From patchwork Tue Jan 3 10:51:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Boeuf, Sebastien" X-Patchwork-Id: 38374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4548497wrt; Tue, 3 Jan 2023 02:53:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXu29tu05tGOy40HiZ55bP98tSYVS4q3w0al3V0Y5X78I8IdvLF/RGVJt4H9vC7OaeXyUbN0 X-Received: by 2002:a62:1642:0:b0:580:c548:9910 with SMTP id 63-20020a621642000000b00580c5489910mr33004597pfw.7.1672743227695; Tue, 03 Jan 2023 02:53:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672743227; cv=none; d=google.com; s=arc-20160816; b=zzKWAm5sw3yyh+7eAO+AAYInqi5gmpTo2lo+P96s+aKF1Tvo622lZYAOBOxlNIAqRD lQRnbz1BFN2UFwxo0xfVPUXtOr1Xu3j5ZsBkZ+OtnNUGQz41piLlNqEzL24yCP47QfSp pPK6C1mM83s5+Yz2uTmYcNCYPpkTRF4Ba9r6lKRzGQj5yI5yrUZu4D/ujea3uj5CE4Mg J9AWcrsJNqlX3lj1jQKW3ZmzYMsNxx+fl/O5iyh6Cisu8YrRvS81KEJl0WLkkf2Lyyu9 LcNmKhN3XbjUAgZK9xxQ+65yNe57uvWrIedGJCs3XhbvsANx6vtMlq9LxsWH/9OxOFa6 cf9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=l4fCEsiLzm45J7O+K4Y88a/Guop8UyNFm/AVdJja+oc=; b=NasenVg6F8qoXCNWtNGnFYTDERayrTt+KxXT0LGkxPvo/cSVztvJgiGW6kgpoXCTQr cezQF9EwyvClZyJvP+QosjpApoV4VWyVk/gF4OZAxk7g729r1etYad5dtqi0GniSxwBS Ro9FiEeYFdNZ71rkj/Rxp7lcI1UX1l6QKJyN3oWIj7zI/34pF3yPgp9blGTTdPXfkhLh 6ClSCBJHZg/GiF7hjOA+mVlAm0sRLzs55WOSGKzPjNLtCDuban4jZp0TXn/Ns/tI0FMg gHHrR0inXrmNa+z3VE9jqCLlq2UwHnZhlKAsFgD49Mqh8XBwLml/tP9zS3EDuuaKBcvM kjig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P9+4tBXn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a62e90e000000b005775394c99fsi31004735pfh.52.2023.01.03.02.53.34; Tue, 03 Jan 2023 02:53:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P9+4tBXn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237440AbjACKwM (ORCPT + 99 others); Tue, 3 Jan 2023 05:52:12 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,LOTS_OF_MONEY, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753998402830005203?= X-GMAIL-MSGID: =?utf-8?q?1753998402830005203?= 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); } +/* After a successful return of this ioctl the device resumes processing + * virtqueue descriptors. The device becomes fully operational the same way it + * was before it was suspended. + */ +static long vhost_vdpa_resume(struct vhost_vdpa *v) +{ + struct vdpa_device *vdpa = v->vdpa; + const struct vdpa_config_ops *ops = 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 *filep, case VHOST_VDPA_SUSPEND: r = vhost_vdpa_suspend(v); break; + case VHOST_VDPA_RESUME: + r = vhost_vdpa_resume(v); + break; default: r = vhost_dev_ioctl(&v->vdev, cmd, argp); if (r == -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) +/* 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