From patchwork Wed Oct 26 15:08:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Boeuf, Sebastien" X-Patchwork-Id: 11302 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp328860wru; Wed, 26 Oct 2022 08:19:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Kqc28dWsys+RET3cGaQuJZMLeEQS5gh3z9StDQ++cBi9px53I7vyoz0yVejSwlfUdVuqn X-Received: by 2002:a05:6402:5107:b0:462:3014:3d73 with SMTP id m7-20020a056402510700b0046230143d73mr7165530edd.177.1666797552858; Wed, 26 Oct 2022 08:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666797552; cv=none; d=google.com; s=arc-20160816; b=upSNxyrPF/wVwvQyyzbSYncCCkV1j6Jy0Y7i8Cc6SjyhADi/LOjTK9ZmoRcR7MnOOy 1NcyQUn3NGFbmVgzSEDRWkLIj6YVWMs2uYfzkvIqVQZuhDi3xY4rDDAOcvxasRJkPOSt svh6+9Nx6Fitin+zTt9EpCPw0ZFjkLhTUc3YP4G0mZnT4RH/6QsQYtWWoIseX/iB5saD cLiriZfEvo89l4higSGWMCt9vvTrJD7PszdSwYb+nWbO8aadm3whGz9QRxVoOjVkrBXC PZoIw7aoHzMBEezpObrgO3icfy1j8QtyUpvEJcEAq+8tYzBSzRF0ZF6OEm9we7NIFwpO Ln+w== 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=1InPzRD+gAzrYUOfP2l2RJaVXLWLM+f9BHUts4Ginfc=; b=d6CtxF1fsOG8D1aOA0qRZ2mP/Am5CFEttvzFfViN9aUm9zbY26hMdYxWCOAGNaYI3f 9rsxD6Y8ttb0TBOGJRLzOmhrNeRM9/rJdYzTT8tS+WsXwcYEgcixKCDkH8zM9h1SQISh b5AOrgfQJzj/BZu7E4JCV+JF1BDauBv9s/Prgt3UvZSKUA7uRtguvyYe38gmhPVWLtK6 s4JrZqTNz+XJh1V1r5hku9kFIBtNfrJCRSqZSkrXyVeFJYNxG1dW8Wxb+bzrc5kt1E3t Db21c5O91Lz0fv3zBB0b+vjlKu2RYpvj8c8YghlAh6ysityN31jexSOfE2DNlCAuvczs WI6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=T7gyYrFN; 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 qb16-20020a1709077e9000b0078debc9d30fsi6342836ejc.45.2022.10.26.08.18.49; Wed, 26 Oct 2022 08:19:12 -0700 (PDT) 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=T7gyYrFN; 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 S234513AbiJZPJf (ORCPT + 99 others); Wed, 26 Oct 2022 11:09:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234467AbiJZPJ1 (ORCPT ); Wed, 26 Oct 2022 11:09:27 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1D8E129761 for ; Wed, 26 Oct 2022 08:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666796963; x=1698332963; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d4xVHWCp3WQNIGyJXoYLjNrxvXCMfEsO8t0kmydFxrI=; b=T7gyYrFNkj644s/ZoJJgxc++UJSq6KMkIKn5kk5zGpUgMwmq9XutKagr v/P/UgZo5jkEPb+TklZAAqGqS8sivX18exqkMuI8L16U3tibjGProoBMG 5owA7z3ybY3c8/JTz8+e1KXK6on7Y6FrbPE0FK+vjcpgGC0Y1YAHlX2wr h2g4FDC8JygktU71MmSQZHspGJay2FH6pOE2HUbwx7N9p6rOU0DFe18xB XniKquteVTbKcep7FCyI0XQ9bXSNY7BEJyH7RWFpYhrvhk1djktrOboIs BDoLd0dc1fCh3FeynkfJNOiDycA95/M/munCRDov08edUY1cqc1bYImcN w==; X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="372178694" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="372178694" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2022 08:09:00 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="961252456" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="961252456" Received: from briansim-mobl.ger.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.29.107]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2022 08:08:58 -0700 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 v5 3/4] vhost-vdpa: uAPI to resume the device Date: Wed, 26 Oct 2022 17:08:37 +0200 Message-Id: <5f2665bac768c29aad2f75e875708f593f966f0a.1666796792.git.sebastien.boeuf@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-4.9 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_NONE,SPF_NONE,URIBL_BLOCKED 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?1747763910972993148?= X-GMAIL-MSGID: =?utf-8?q?1747763910972993148?= 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 --- 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