From nobody Tue Sep 16 12:32:14 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0F7EC46467 for ; Tue, 3 Jan 2023 10:52:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237376AbjACKwF (ORCPT ); Tue, 3 Jan 2023 05:52:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237108AbjACKvc (ORCPT ); Tue, 3 Jan 2023 05:51:32 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05AD0DF3 for ; Tue, 3 Jan 2023 02:51:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672743092; x=1704279092; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zukvlO7ayucX1PyDrSkH1p1yDhKXLf7pZ9ViBv268Sg=; b=Zfx7MmkXB6gpkVmIK0PPGoas+8IDi5c5KLumkTL15In6DhDp1zjNISWW w2CTV/CbL5mjgMnlgEHDoSxCQita9fcfuLDoZDLJ5X1g8r/8TtB7Mx/Km 9yKwiuiAccEYcBXW4L8KSo5IjHlegswPC/xAM1B361wRuy323i/1gMDHX mwlGjaGSnBAqxj5/w5ImVRmYybvUOvy0b6RPod3dTHpDsGGVlNY8RjKUH j+muTGxsEmm26BZiLFF7H+L+dMEEouenc/Ch2PncspqeW5hRcN0Qf+U84 g/6iajpHY0xdZ3cFv5xoEDRdIW32mmFodu97PrdI8oWF3ZSMOl4gNCkMn A==; X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="301318433" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="301318433" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 02:51:31 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="604772656" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="604772656" Received: from isobansk-mobl1.ger.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.24.246]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 02:51:29 -0800 From: sebastien.boeuf@intel.com To: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: mst@redhat.com, jasowang@redhat.com, eperezma@redhat.com, sebastien.boeuf@intel.com Subject: [PATCH v6 1/4] vdpa: Add resume operation Date: Tue, 3 Jan 2023 11:51:05 +0100 Message-Id: <6e05c4b31b47f3e29cb2bd7ebd56c81f84b8f48a.1672742878.git.sebastien.boeuf@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sebastien Boeuf Add a new operation to allow a vDPA device to be resumed after it has been suspended. Trying to resume a device that wasn't suspended will result in a no-op. This operation is optional. If it's not implemented, the associated backend feature bit will not be exposed. And if the feature bit is not exposed, invoking this operation will return an error. Acked-by: Jason Wang Signed-off-by: Sebastien Boeuf Reviewed-by: Stefano Garzarella --- include/linux/vdpa.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 6d0f5e4e82c2..96d308cbf97b 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -219,7 +219,10 @@ struct vdpa_map_file { * @reset: Reset device * @vdev: vdpa device * Returns integer: success (0) or error (< 0) - * @suspend: Suspend or resume the device (optional) + * @suspend: Suspend the device (optional) + * @vdev: vdpa device + * Returns integer: success (0) or error (< 0) + * @resume: Resume the device (optional) * @vdev: vdpa device * Returns integer: success (0) or error (< 0) * @get_config_size: Get the size of the configuration space includes @@ -324,6 +327,7 @@ struct vdpa_config_ops { void (*set_status)(struct vdpa_device *vdev, u8 status); int (*reset)(struct vdpa_device *vdev); int (*suspend)(struct vdpa_device *vdev); + int (*resume)(struct vdpa_device *vdev); size_t (*get_config_size)(struct vdpa_device *vdev); void (*get_config)(struct vdpa_device *vdev, unsigned int offset, void *buf, unsigned int len); --=20 2.37.2 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris,=20 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 5 208 026.16 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. From nobody Tue Sep 16 12:32:14 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BB93C54EBD for ; Tue, 3 Jan 2023 10:52:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237432AbjACKwK (ORCPT ); Tue, 3 Jan 2023 05:52:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237193AbjACKvi (ORCPT ); Tue, 3 Jan 2023 05:51:38 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 765602FA for ; Tue, 3 Jan 2023 02:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672743097; x=1704279097; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wwAlVm/7I8ndsWi60dF17HSTriSq8epoPrbPLSohnLw=; b=PpLoTiiAXvPV6Y0VKIgd581nm9AxugWU/N8sDhTYFo0TI/aIuE2wbShk ORfQmkUbA7DKmB/cFQYW9tvBGQi4AoPo11ezZAyzzEZrpxSHrJStaWjJx qKtD9zHglvyKLCFrlElVLMvLiWuHDQlPOMY/cmADgpT/43Wjh6VUrrIS1 dDzYe1CbDVmttZApxjr1njzECMyoeM/gxCSbe2YIyyf5cZEEG/YnFlnMe ecSDYTUNqHvkWOCxEieiuUwDLXCv97W/0IAPeSE9qAuF/cYDngEYzZw1Y OwMRNepXuZF0OlYhHhQNGTuUiDVb4up5vf/i0y7jLVznumuwWhv6Sg4MQ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="301318451" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="301318451" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 02:51:37 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="604772689" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="604772689" Received: from isobansk-mobl1.ger.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.24.246]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 02:51:35 -0800 From: sebastien.boeuf@intel.com To: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: mst@redhat.com, jasowang@redhat.com, eperezma@redhat.com, sebastien.boeuf@intel.com Subject: [PATCH v6 2/4] vhost-vdpa: Introduce RESUME backend feature bit Date: Tue, 3 Jan 2023 11:51:06 +0100 Message-Id: X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sebastien Boeuf Userspace knows if the device can be resumed or not by checking this feature bit. It's only exposed if the vdpa driver backend implements the resume() operation callback. Userspace trying to negotiate this feature when it hasn't been exposed will result in an error. Acked-by: Jason Wang Signed-off-by: Sebastien Boeuf Reviewed-by: Stefano Garzarella --- drivers/vhost/vdpa.c | 16 +++++++++++++++- include/uapi/linux/vhost_types.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 166044642fd5..833617d00ef6 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -355,6 +355,14 @@ static bool vhost_vdpa_can_suspend(const struct vhost_= vdpa *v) return ops->suspend; } =20 +static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v) +{ + struct vdpa_device *vdpa =3D v->vdpa; + const struct vdpa_config_ops *ops =3D vdpa->config; + + return ops->resume; +} + static long vhost_vdpa_get_features(struct vhost_vdpa *v, u64 __user *feat= urep) { struct vdpa_device *vdpa =3D v->vdpa; @@ -602,11 +610,15 @@ static long vhost_vdpa_unlocked_ioctl(struct file *fi= lep, if (copy_from_user(&features, featurep, sizeof(features))) return -EFAULT; if (features & ~(VHOST_VDPA_BACKEND_FEATURES | - BIT_ULL(VHOST_BACKEND_F_SUSPEND))) + BIT_ULL(VHOST_BACKEND_F_SUSPEND) | + BIT_ULL(VHOST_BACKEND_F_RESUME))) return -EOPNOTSUPP; if ((features & BIT_ULL(VHOST_BACKEND_F_SUSPEND)) && !vhost_vdpa_can_suspend(v)) return -EOPNOTSUPP; + if ((features & BIT_ULL(VHOST_BACKEND_F_RESUME)) && + !vhost_vdpa_can_resume(v)) + return -EOPNOTSUPP; vhost_set_backend_features(&v->vdev, features); return 0; } @@ -658,6 +670,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *file= p, features =3D VHOST_VDPA_BACKEND_FEATURES; if (vhost_vdpa_can_suspend(v)) features |=3D BIT_ULL(VHOST_BACKEND_F_SUSPEND); + if (vhost_vdpa_can_resume(v)) + features |=3D BIT_ULL(VHOST_BACKEND_F_RESUME); if (copy_to_user(featurep, &features, sizeof(features))) r =3D -EFAULT; break; diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_ty= pes.h index 53601ce2c20a..c5690a8992d8 100644 --- a/include/uapi/linux/vhost_types.h +++ b/include/uapi/linux/vhost_types.h @@ -163,5 +163,7 @@ struct vhost_vdpa_iova_range { #define VHOST_BACKEND_F_IOTLB_ASID 0x3 /* Device can be suspended */ #define VHOST_BACKEND_F_SUSPEND 0x4 +/* Device can be resumed */ +#define VHOST_BACKEND_F_RESUME 0x5 =20 #endif --=20 2.37.2 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris,=20 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 5 208 026.16 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. From nobody Tue Sep 16 12:32:14 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CDB7C53210 for ; Tue, 3 Jan 2023 10:52:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237445AbjACKwN (ORCPT ); Tue, 3 Jan 2023 05:52:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237304AbjACKvm (ORCPT ); Tue, 3 Jan 2023 05:51:42 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 784FB2AE1 for ; Tue, 3 Jan 2023 02:51:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672743101; x=1704279101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Wpp2BiRmPtCrq2dRBOAMounsOwKlI+2jikZIpNAzISg=; b=P9+4tBXnraxk6gOQE34Ei6+MCf4EUe6dmRVgVf0LcBe8DiWMvMeD0qlx zUxxTF0e5sZsLB3Jd139wpn0Gic6Zf+ObMqIeSHPpB8tOOrm7lYOvXPfD KfvqYliwPrD+awOebQwWYFkL3kXfNEDej+ybREW3a8H0mBVVKurq+UA5r qxvUh5WFJPdqXdTnJyOmJ20OKv8wkigFMiKBFE7bBWP8ZqUZ7e1JvxuNn lA0gYI2xhUvSFNUgHkdgbjwcE8FNxPOr/adHAhBjpM7Bdrx0yAZJ1zdvX 772Um0xuvbJqDbEXfgD7ZHj7tT4b105v2cfkOKJwpWFo7Bxbd2giy6+WB A==; X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="301318463" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="301318463" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 02:51:41 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="604772706" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="604772706" Received: from isobansk-mobl1.ger.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.24.246]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 02:51:39 -0800 From: sebastien.boeuf@intel.com To: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: mst@redhat.com, jasowang@redhat.com, eperezma@redhat.com, sebastien.boeuf@intel.com Subject: [PATCH v6 3/4] vhost-vdpa: uAPI to resume the device Date: Tue, 3 Jan 2023 11:51:07 +0100 Message-Id: <73b75fb87d25cff59768b4955a81fe7ffe5b4770.1672742878.git.sebastien.boeuf@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sebastien Boeuf This new ioctl adds support for resuming the device from userspace. This is required when trying to restore the device in a functioning state after it's been suspended. It is already possible to reset a suspended device, but that means the device must be reconfigured and all the IOMMU/IOTLB mappings must be recreated. This new operation allows the device to be resumed without going through a full reset. This is particularly useful when trying to perform offline migration of a virtual machine (also known as snapshot/restore) as it allows the VMM to resume the virtual machine back to a running state after the snapshot is performed. Acked-by: Jason Wang Signed-off-by: Sebastien Boeuf Reviewed-by: Stefano Garzarella --- drivers/vhost/vdpa.c | 18 ++++++++++++++++++ include/uapi/linux/vhost.h | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 833617d00ef6..1db7bd39fb63 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -502,6 +502,21 @@ static long vhost_vdpa_suspend(struct vhost_vdpa *v) return ops->suspend(vdpa); } =20 +/* After a successful return of this ioctl the device resumes processing + * virtqueue descriptors. The device becomes fully operational the same wa= y it + * was before it was suspended. + */ +static long vhost_vdpa_resume(struct vhost_vdpa *v) +{ + struct vdpa_device *vdpa =3D v->vdpa; + const struct vdpa_config_ops *ops =3D vdpa->config; + + if (!ops->resume) + return -EOPNOTSUPP; + + return ops->resume(vdpa); +} + static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, void __user *argp) { @@ -687,6 +702,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *file= p, case VHOST_VDPA_SUSPEND: r =3D vhost_vdpa_suspend(v); break; + case VHOST_VDPA_RESUME: + r =3D vhost_vdpa_resume(v); + break; default: r =3D vhost_dev_ioctl(&v->vdev, cmd, argp); if (r =3D=3D -ENOIOCTLCMD) diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index f9f115a7c75b..92e1b700b51c 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -180,4 +180,12 @@ */ #define VHOST_VDPA_SUSPEND _IO(VHOST_VIRTIO, 0x7D) =20 +/* Resume a device so it can resume processing virtqueue requests + * + * After the return of this ioctl the device will have restored all the + * necessary states and it is fully operational to continue processing the + * virtqueue descriptors. + */ +#define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E) + #endif --=20 2.37.2 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris,=20 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 5 208 026.16 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. From nobody Tue Sep 16 12:32:14 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E6A3C54EBF for ; Tue, 3 Jan 2023 10:52:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237458AbjACKwP (ORCPT ); Tue, 3 Jan 2023 05:52:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237350AbjACKvq (ORCPT ); Tue, 3 Jan 2023 05:51:46 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C67B5FFC for ; Tue, 3 Jan 2023 02:51:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672743105; x=1704279105; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lmnHqI3tKK38BSUrN2DgjBvLt72f0TuIKDBVQU/rvhw=; b=ddfmerVjrE7+0suayq7UkX2tHTfDp5ezOWMIB5e1Rye1oVg2/Q7+Uv1M k/Ja6KmucxqmJd1UheCeOHBnDGeG1Al4jXcUBxgZnbmBh2qK8DrpMOzJt YC5hm3WbPhIHXGfQd9lTK2/9Zt69CXnAvIvCzxOqk1ClEzIo6NILmdkbG Y3oNjACCZQKRGFYWIzOavOG90Vl04T0FhHSOo9F3d+/RapiWkA4AxiPa0 nftFlUt6R3ei3B3VSOW1YrqgtdFuzPaa8Z4QA1dE8r/+cPYQRjaoNM3eh +pmFdPXyu07VUMy+Q84pucO2g2bnjVrxdO7ux26102vAsLQnQYh+HnHUX A==; X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="301318478" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="301318478" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 02:51:45 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="604772731" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="604772731" Received: from isobansk-mobl1.ger.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.24.246]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 02:51:43 -0800 From: sebastien.boeuf@intel.com To: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: mst@redhat.com, jasowang@redhat.com, eperezma@redhat.com, sebastien.boeuf@intel.com Subject: [PATCH v6 4/4] vdpa_sim: Implement resume vdpa op Date: Tue, 3 Jan 2023 11:51:08 +0100 Message-Id: <15a4566826033c5dd9a2167e5cfb0ef4d90cea49.1672742878.git.sebastien.boeuf@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sebastien Boeuf Implement resume operation for vdpa_sim devices, so vhost-vdpa will offer that backend feature and userspace can effectively resume the device. Signed-off-by: Sebastien Boeuf Acked-by: Jason Wang --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 29 +++++++++++++++++++++++++++++ drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 + 2 files changed, 30 insertions(+) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index b071f0d842fb..756a5db0109c 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -357,6 +357,12 @@ static void vdpasim_kick_vq(struct vdpa_device *vdpa, = u16 idx) struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); struct vdpasim_virtqueue *vq =3D &vdpasim->vqs[idx]; =20 + if (!vdpasim->running && + (vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK)) { + vdpasim->pending_kick =3D true; + return; + } + if (vq->ready) schedule_work(&vdpasim->work); } @@ -527,6 +533,27 @@ static int vdpasim_suspend(struct vdpa_device *vdpa) return 0; } =20 +static int vdpasim_resume(struct vdpa_device *vdpa) +{ + struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); + int i; + + spin_lock(&vdpasim->lock); + vdpasim->running =3D true; + + if (vdpasim->pending_kick) { + /* Process pending descriptors */ + for (i =3D 0; i < vdpasim->dev_attr.nvqs; ++i) + vdpasim_kick_vq(vdpa, i); + + vdpasim->pending_kick =3D false; + } + + spin_unlock(&vdpasim->lock); + + return 0; +} + static size_t vdpasim_get_config_size(struct vdpa_device *vdpa) { struct vdpasim *vdpasim =3D vdpa_to_sim(vdpa); @@ -717,6 +744,7 @@ static const struct vdpa_config_ops vdpasim_config_ops = =3D { .set_status =3D vdpasim_set_status, .reset =3D vdpasim_reset, .suspend =3D vdpasim_suspend, + .resume =3D vdpasim_resume, .get_config_size =3D vdpasim_get_config_size, .get_config =3D vdpasim_get_config, .set_config =3D vdpasim_set_config, @@ -750,6 +778,7 @@ static const struct vdpa_config_ops vdpasim_batch_confi= g_ops =3D { .set_status =3D vdpasim_set_status, .reset =3D vdpasim_reset, .suspend =3D vdpasim_suspend, + .resume =3D vdpasim_resume, .get_config_size =3D vdpasim_get_config_size, .get_config =3D vdpasim_get_config, .set_config =3D vdpasim_set_config, diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_= sim.h index 0e78737dcc16..a745605589e2 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -67,6 +67,7 @@ struct vdpasim { u64 features; u32 groups; bool running; + bool pending_kick; /* spinlock to synchronize iommu table */ spinlock_t iommu_lock; }; --=20 2.37.2 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris,=20 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 5 208 026.16 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.