From patchwork Tue Oct 18 08:37:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Boeuf, Sebastien" X-Patchwork-Id: 4024 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1849016wrs; Tue, 18 Oct 2022 02:02:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Jh1iAJ8gcieMJE7PnvxbpbbwjexJySHH2rTdkPqYcovy4L4UX0nvjCWVOO5KsT5FM+mwD X-Received: by 2002:aa7:c58a:0:b0:459:1511:6cff with SMTP id g10-20020aa7c58a000000b0045915116cffmr1688543edq.27.1666083752952; Tue, 18 Oct 2022 02:02:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666083752; cv=none; d=google.com; s=arc-20160816; b=fF+BOIZxYA2Irig9RnWH7WxOomdgIPi5YfUauPal3iZeyDXPSl0TMDCAKbCgGhVsRP 8/LefGUXiUPnldC0sZhflrPwGOICyWf16dmOd07KhfqF7iiuZZ3iFOYP9T780iBfRYVr kU9qYBIZ0E+DtCgsaZKlgyJAQsdtnLLIA33uVvylOxTV5kCMceL30no/B9zRBRPbd9+4 rip6L3B7OYRAlCWlhAhB6nrzENWrdn41l7I0tJr+3YSqnwypYWWwhxRmp8Ska3pBvwpn UnQWYwNE6prsh7o+uUNrnFl+NQbw/aWXfjJuFpSkItZMymrQ20VesGCvNaPyWIKdzaTA vnPg== 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=AUVP2+SgMoX6uSMIW8WCe0Ab6DkC+OJVRJ/BD9SWdCjqmhWrpApXd69swB74J9eYnh aOXpWmU0zLdzw3/i+IVvw57HGR8PvsaQtyVn2MO9Wn9C6GtPAPHjqAjDgjC5yaN4Hcn2 m9dVgswWCfR7QJkGuJv34+/i6GlRsm/wJ7oUNkTsl0qEb2rj4v+cwz+ORR5CIhoE4Fl2 oJCkAQdsHLhBKkfBi+mru0rekLhrmJ/YcJAetEvHzZslvj3yOSB0gX2om6G5Sg8lV2x3 n5Lev4TSSMTpAHUy4klhCY7Hx9IDkyfEeqzk3+VSfzQakW/cPP0ldGJTeyEZgl9LN3P1 6+Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=byZvNa7K; 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 e27-20020a50d4db000000b004594ac619b4si9867518edj.245.2022.10.18.02.02.07; Tue, 18 Oct 2022 02:02:32 -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=byZvNa7K; 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 S229978AbiJRIiN (ORCPT + 99 others); Tue, 18 Oct 2022 04:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbiJRIiL (ORCPT ); Tue, 18 Oct 2022 04:38:11 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE4C19C7DF for ; Tue, 18 Oct 2022 01:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666082290; x=1697618290; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d4xVHWCp3WQNIGyJXoYLjNrxvXCMfEsO8t0kmydFxrI=; b=byZvNa7KdJhllvF8/L55vnOYBX6/4JsCqAkxnvMqApbMYNEhPM2u9wMX lktM6JtuT0eRl1nfH7vxElgtxAuGl8DUAFHgcaeephq55k8IUk+l2InMA sFW89bsXUaUzd+7ZcV3Z9Z1sHjSPCZwf+Y3sFFmX4/8m9/+56mZjK394w xOCXRYargdS3Hdw0gS1y9w+RG7HyRJRPArMWfDrbuZZSBK3tzN4W+vddE D0LLJ7rOoUCNx9aZ9qdASCHvIsDewKyUjInzu+se5XFYbrbzoy8U9xnOh Z3bUj2ApzQydpbpKoWdDFzEIe7421LMWwwAGfWAMgUqIAfmne0FAmQ9ak g==; X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="332580434" X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="332580434" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 01:38:10 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="753951118" X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="753951118" Received: from aboyhan-mobl1.ger.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.26.192]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 01:38:08 -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 v4 3/4] vhost-vdpa: uAPI to resume the device Date: Tue, 18 Oct 2022 10:37:26 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-7.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_HI,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, 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?1747015437119671517?= X-GMAIL-MSGID: =?utf-8?q?1747015437119671517?= 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