From patchwork Wed Oct 26 15:08:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Boeuf, Sebastien" X-Patchwork-Id: 11301 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp328729wru; Wed, 26 Oct 2022 08:18:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7U7kaP5PF9KEmEZvVh0ZYCCmnqSOYGG2KmecjODLw6m9sFav4Etj5PlewtI007KXSw48u3 X-Received: by 2002:a17:906:6a17:b0:794:f0e8:1918 with SMTP id qw23-20020a1709066a1700b00794f0e81918mr32654484ejc.474.1666797535318; Wed, 26 Oct 2022 08:18:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666797535; cv=none; d=google.com; s=arc-20160816; b=gGX37wIpI0tPt64m7OFzddQsaOgy/mXJ1st7jiJSO4PFDyPQYaXco1b4HRf6obNVtZ CHe8xPiR0iyI+4xcabhlhN7smIeQ6WF06YZasD9rdwO8Kyr7c1V/MpN7fVGBJbvoVoq4 xQp6ti2manIjWEkogA5s7Fnv3ZZzFe2HfPcWNN4LmaxIYNkXdk1kscI7IQX5TgbqK7i/ oLLnCYT4jz0dst2m2FLKCGP0IJwlkSLxD5h4gM4/zhJzZWQLNEg0OWMGGDy1zhjqdczq z/ViVfnH9XWgeiyp5YoOXVcugh4REOWoCpSGhBwebzM1K9rgBF96YvPYg2Y8p/E2I9aJ RDSA== 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=q3ckY7eRWys3SiIByjebXdptkdLc6+MrCvy88LbHelb4QD1J24dMK0SzOP4oqucTYx yIlLceiJlZv5rDLjGAA+lKvfEhLzGJdg/V3uCW94R7czKa5PGjKsoUT6y5Tm28MbrYDz S3E14t87ptMuaOEdLNeWm0HwOkFtjbcKpTQoBCe3pmUCvQpEH8j1+j/FSwLf0xzMMFbw m5pOXXP1g7R8gU1WN2mXZr5vdrkwytUdvFsHuaOFvBimwTog66VB4TUQI07kgxeWkvs6 wpFHipn5SXkSkYfVzAtnp7aXJJLilS6DN3AE3e55d4yak4z+CxMuXmSJOwNsyrC3QO9g BFvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PD4M2O9M; 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 he41-20020a1709073da900b0077cfdda438csi1856793ejc.35.2022.10.26.08.18.30; Wed, 26 Oct 2022 08:18:55 -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=PD4M2O9M; 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 S234161AbiJZPJ3 (ORCPT + 99 others); Wed, 26 Oct 2022 11:09:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234509AbiJZPJV (ORCPT ); Wed, 26 Oct 2022 11:09:21 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7D81285DA for ; Wed, 26 Oct 2022 08:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666796960; x=1698332960; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3EV55upffRiHWnrQrH8wPJ3mud3btZU1zYuiKkySMH4=; b=PD4M2O9MM8eLHQ3R6TBD6j2P5fr1ErBOLT/9zfXaqvjMQHzXE0xU5VJ6 ZCLb5O+ogX9zC50GD5bwPSlIAVHRQuxXpJ5y6ziRCzjwms/2EHH8i07Yt P9BWFgzI4+LazK8A6ZwCaBXhOiaBAmcohTIKGP9GKXEmzwSh/vm1bLPyW w61RHyZs8pozJaqSSOZcD0WAKJvepjBTzFUqttUTJFSZNQCb6WyF512gR D2v/D8iiF3iSxv8aeZidHysZcCA3FF21BejBycnz6nhCCuxOczAC9zGp7 dVV4+6kYA223Ke7Y07uShVPlrQJXHK0U6MS2CpfZZk09MWEa5kJOeZn8r w==; X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="372178672" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="372178672" 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:08:57 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="961252449" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="961252449" 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:55 -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 2/4] vhost-vdpa: Introduce RESUME backend feature bit Date: Wed, 26 Oct 2022 17:08:36 +0200 Message-Id: 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?1747763892609620969?= X-GMAIL-MSGID: =?utf-8?q?1747763892609620969?= 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