From patchwork Tue Oct 18 08:37:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Boeuf, Sebastien" X-Patchwork-Id: 4021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1845304wrs; Tue, 18 Oct 2022 01:48:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7TDrdm61Pav4VXc369JaH/Q6c5HpatL4eaj8T4QR6dUGhSgZPIOwJr+LF4R85FO2dq/hvN X-Received: by 2002:a17:906:d54d:b0:78e:2fbf:ca2a with SMTP id cr13-20020a170906d54d00b0078e2fbfca2amr1550629ejc.488.1666082937840; Tue, 18 Oct 2022 01:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666082937; cv=none; d=google.com; s=arc-20160816; b=OH0ywvMSF4gMbk4o3z7RXiSLlM/Eruz/usim+2vSVaKKOiMcYo2h+qOXktcD0U6hwl iD+Gb4VssxlzLYjXD1v9Ep6AbKsM2umJyG8FXTFhkJJj6PCQ22s5xz3RYQde95PF4zIk UfJU27Y0n+uB4KleePO1llPb99o+8JTXm5ppX92rw8k7eyzuPiKTBA0ME4URICllQdT1 N1XTMTnS9MtYjIqarIyLf/AT/roUbrp3V5N47HHiaxfy/ox40dSHNfr0chhRVDY9fdoL c7ZpEWo1twEyCX+nqth22nu8mG8E2xhKG2yCmDDRsS1NcGVLGFhG4cUwqvVSccYFs1sV oBHw== 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=QXcMFmQdkvGWNbSfz2wW92RpTmPjr1ay3/gajuLNKiM=; b=LWooyO5NxqnWH+eesuRWR1lDKead6OKD7jJK6FJiWeeio5193WJ47ANWEFnzFWt5Bt zwP70uIGBvqXIEcAGcluB6U/cCIeLr0az+Mjvg+eTiAj5gmXs5QjMAVemHAQqQglhmdq 4E1igvwznFlLnLp5Q36xQgspofZZWMf4k0xqGhbR5H9jdZ36VYW3bi0GHdgJu5Vt0ZKN JC0wfySCNTvLhpSRrsm3YCffi2T1qEshpQkcaBfRUZtKZp9EW+HKvIbWy/XXTvqJ7RXZ zZ7b7CyPT16aDsGe9Y+lmuk96xiMpu7kMpBcppqX1msfnnL46rBQ9+EsdpXumYMaAbSl SgYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NqK807Jl; 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 nb17-20020a1709071c9100b0077979f8d3dbsi11226776ejc.838.2022.10.18.01.48.32; Tue, 18 Oct 2022 01:48:57 -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=NqK807Jl; 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 S230175AbiJRIi1 (ORCPT + 99 others); Tue, 18 Oct 2022 04:38:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230137AbiJRIiS (ORCPT ); Tue, 18 Oct 2022 04:38:18 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 059A69F758 for ; Tue, 18 Oct 2022 01:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666082296; x=1697618296; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3EV55upffRiHWnrQrH8wPJ3mud3btZU1zYuiKkySMH4=; b=NqK807Jl1koTGxZZ6e1xouzcUHtBoAq0IRB3USz2a8t7oP8sBOrXc0tx Xw1QrNpUXHJZIVM+xSD0BOJhwWcOUQYprRZh7+3kSBrp9vUUDHAbkQwuy CkNT0KyQO/73P9x14rf2tvpNL/4fWZmwQqf9RJD1T93/sPQX7mvmxne2d VmjSBfTEt+a6Zeg6GtT29v9tWQFBuwz6XUFyfD/xXO1i4VzNpDMORL5v9 rOYsd3nJzX3UQV+dKGGdzzB3wtX5RSSf3gR77zxJhuNgQR7t/Y9WYBdl4 DsCFmEoAe39gUODgzUnuql8uM0XbT/KgYsJuh8ylWeWtOXOH0RIMaQVeb w==; X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="307125543" X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="307125543" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 01:38:04 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="753951077" X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="753951077" 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:02 -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 2/4] vhost-vdpa: Introduce RESUME backend feature bit Date: Tue, 18 Oct 2022 10:37:25 +0200 Message-Id: <2b70c4e3c811d0f769399b0bdc0dae52853ac8c4.1666082013.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.7 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,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?1747014582332982878?= X-GMAIL-MSGID: =?utf-8?q?1747014582332982878?= 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 --- 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; } +static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v) +{ + struct vdpa_device *vdpa = v->vdpa; + const struct vdpa_config_ops *ops = vdpa->config; + + return ops->resume; +} + static long vhost_vdpa_get_features(struct vhost_vdpa *v, u64 __user *featurep) { struct vdpa_device *vdpa = v->vdpa; @@ -602,11 +610,15 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, 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 *filep, features = VHOST_VDPA_BACKEND_FEATURES; if (vhost_vdpa_can_suspend(v)) features |= BIT_ULL(VHOST_BACKEND_F_SUSPEND); + if (vhost_vdpa_can_resume(v)) + features |= BIT_ULL(VHOST_BACKEND_F_RESUME); if (copy_to_user(featurep, &features, sizeof(features))) r = -EFAULT; break; diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_types.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 #endif