From patchwork Wed Oct 26 15:08:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Boeuf, Sebastien" X-Patchwork-Id: 11300 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp328652wru; Wed, 26 Oct 2022 08:18:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7YAc+64V4Jt2iPM8YiRkjXQ+c55OF7U2u4S/UwHvzX/OOh44U/pEHu4HfoctA+iOg31e9Q X-Received: by 2002:a17:907:2bcf:b0:79d:e8e6:d579 with SMTP id gv15-20020a1709072bcf00b0079de8e6d579mr22784607ejc.563.1666797528520; Wed, 26 Oct 2022 08:18:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666797528; cv=none; d=google.com; s=arc-20160816; b=s/Xfqpcf0l/Ti0HSYWitHx6YsEfvTiB+JfmhLOlQckXzDwTrWWYZ8uM8idb8bTjBUY sCNwTNLJCkfekFHvSEFyN7Dj+XGCfqEuBD+VwzYWPjRBIjVKgwDMr7gTjRbIuzCJhIBE /FyQbBq0LVAx6qwPlvQr84xmXq6M0TkdxYFHW0zSFTU2mMz81xX3vIwMlPqN/7XQuu0W cRSh7sj6YfEahf2/h58Zey/5bPPS1ULRhATvPOEHm5W8vTX7Ouo/ymgr17s2vX0HUDeS EtwrIbDdGmewcJh0kAoGGZMpuO2YnIO5pdpvvCDByq1kM2iIhIH7LvBAfOBbo0OcIXLR pndA== 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=CmutJhSnCo7GzUEgjGUiWPoZ4PIgkK24LIqJ3waWfKs=; b=Y0B8zBWf9zKZ0xRcGpLnswJSw5iCIWFUeIHwAsiGyUluUhoV07PeV64PoApBpRXK3s coOvVbGJwkiWudpPTgmzGLk9JcNw10L2bfNeBRDfX8aThWHYr+WIxBIsCbo4Sz2RI36h Gm/MSiWzgITzoFURFD/aiyEBDlTt/2FW3zFGSS2tP4jsrzojcYk9w7kf2Hrur2WxV4xG BiSVSvYMewii8Een0VKX57WGOXIqUO0SRcS2bo+9giGbufzeHGuA7QGa0FXXx3IB1FiX 26khf8y4SB3TDA9tNtNDR6xBV9j21gzuP0um//WwVjP8htrAV0wH03whGCcUN2x2lQ1+ 9P5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C6s9+Nji; 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 l21-20020a170906795500b0073db353cb25si6497246ejo.869.2022.10.26.08.18.22; Wed, 26 Oct 2022 08:18:48 -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=C6s9+Nji; 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 S234470AbiJZPI7 (ORCPT + 99 others); Wed, 26 Oct 2022 11:08:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234280AbiJZPIw (ORCPT ); Wed, 26 Oct 2022 11:08:52 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5931912347E for ; Wed, 26 Oct 2022 08:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666796932; x=1698332932; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w/VJ/zZxV+j4zvTylkKvQJvW+/QH7d4xZGt7+Trkcoo=; b=C6s9+Njiw4Iseaahok1QTFaCimIdHyeutV3JInD/G+kpqG1OxX77hQ46 E1TBU2+XkEjjf6R9mpfPuS1StS7E/w21yMf5Bym5y+Dz3vFIp7H4BOS+N yexsGMeaIyE08HyxRyPcBiV+7kq1NfiK4iOqCFVuxqqNH7qwCS5+sgDqr n6NAgioDy9asP6c7qZLYrz4NbKsoaOsHOC7QcOnuVMlhZRUMN6gOw8gq9 b6i59F4YSwqEN9zHvuiuBaJjUoQLP/axWs4Gj+lwLUNXfftty7zHPzQIl EcJ7Wl5ln9o0ql3RPbgy3BArRKp+XweDIWll7CDNoxSLPW0+hwIj8GKVD w==; X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="370035946" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="370035946" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2022 08:08:51 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="961252435" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="961252435" 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:49 -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 1/4] vdpa: Add resume operation Date: Wed, 26 Oct 2022 17:08:35 +0200 Message-Id: <2c10a3b3a52081fc467868e6f2c2b4bdc12584f1.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?1747763885046716674?= X-GMAIL-MSGID: =?utf-8?q?1747763885046716674?= From: Sebastien Boeuf Add a new operation to allow a vDPA device to be resumed after it has been suspended. Trying to resume a device that wasn't suspended will result in a no-op. This operation is optional. If it's not implemented, the associated backend feature bit will not be exposed. And if the feature bit is not exposed, invoking this operation will return an error. Acked-by: Jason Wang Signed-off-by: Sebastien Boeuf --- include/linux/vdpa.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index 6d0f5e4e82c2..96d308cbf97b 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -219,7 +219,10 @@ struct vdpa_map_file { * @reset: Reset device * @vdev: vdpa device * Returns integer: success (0) or error (< 0) - * @suspend: Suspend or resume the device (optional) + * @suspend: Suspend the device (optional) + * @vdev: vdpa device + * Returns integer: success (0) or error (< 0) + * @resume: Resume the device (optional) * @vdev: vdpa device * Returns integer: success (0) or error (< 0) * @get_config_size: Get the size of the configuration space includes @@ -324,6 +327,7 @@ struct vdpa_config_ops { void (*set_status)(struct vdpa_device *vdev, u8 status); int (*reset)(struct vdpa_device *vdev); int (*suspend)(struct vdpa_device *vdev); + int (*resume)(struct vdpa_device *vdev); size_t (*get_config_size)(struct vdpa_device *vdev); void (*get_config)(struct vdpa_device *vdev, unsigned int offset, void *buf, unsigned int len); 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 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 From patchwork Wed Oct 26 15:08:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Boeuf, Sebastien" X-Patchwork-Id: 11303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp329103wru; Wed, 26 Oct 2022 08:19:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Y+sWGD0u0veRMCrm/T1ZbQv3533EeS6YbPKh5U63SHMuWGTgYb3wCISK49IA+2sxKco6I X-Received: by 2002:a17:907:78a:b0:78d:9ac7:b697 with SMTP id xd10-20020a170907078a00b0078d9ac7b697mr37618105ejb.457.1666797580857; Wed, 26 Oct 2022 08:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666797580; cv=none; d=google.com; s=arc-20160816; b=epCSa3qs3umrwgTg6u8SXCnunTf56E9QCRrG09L0kcQotou70siylqWVXnfw7+U0aN /DTk0ncdsbkXpjeu7OUEt7dDFZLQ5HVmbKUpKnl3quueBCmPNfN6o3ogM5cNj24CpYlW 37Ficc/3th7Ixtlrsq/dCmgffAnluUY2Dl45bW5tO+P/ESGW9pjzkCoe/bJsD2T07l+Y qCbHpVJmrOSjsUVXrYp0WrOG9c7dWQ8OAT8hNwYqJCIqcyJ6eM+5bN53r3EaYFEu9SIw AyeznW/tE27313KJ1nd2WJCCIH0T+ixEmM3yC3f7b4XlHygMHhzy03K2d30RrJrpJnk9 NBdw== 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=DRAyu2nedGUpRmjgEhLho0Isyrm6euj16kwLoUe3GIE=; b=sybnlr2EQwnbkom6BbrnKo8sMaXvvF/EMjq90VImc8ctXNryqOxhYjGc9EIn6RvJBy 5rQ1KoPtxoWYpI0s4vUPJL0f/QeZiuzdkFmM4Wrr2caS4DmUDjN71cGD//D3b/y2iTFF LDW1PcMRGjOulLrEzHlWd3SRWTrDWHHY2jWolGGfv5RVa1dQMwUCqDeiZ146CDaRwMvW XWtb3szxJwo/B0I2l6yjJJReqAeXxnSpA/gEeORM+T/vP/MukhVaXysp2J3D4W6MiaPt xQ21OAyQ4K81CFo0zdowmG+qF7s71huIaY11IteA8ITNAO2mOQH1jvA2/mQirBjBMCj6 0pjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QmeLlV4M; 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 e17-20020a056402191100b0046159da6233si7660129edz.145.2022.10.26.08.19.16; Wed, 26 Oct 2022 08:19:40 -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=QmeLlV4M; 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 S233689AbiJZPJr (ORCPT + 99 others); Wed, 26 Oct 2022 11:09:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234484AbiJZPJ1 (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 0F6B2200 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=1666796964; x=1698332964; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xRbBHi5E+N2qU/Z+c5NfZHEpwCKk1QOB5B18pjThjKE=; b=QmeLlV4MhkNOzGy6Uj26VA187RwSJHPE0qEAZHjWlwpkDFgeFTph0DCJ JV9YB6QEyKzLdNY814xoavjc4li/j+TlnhuVk5WJboG46PmU64dpWCXHo c9g8SHKrUCIUiCza6ueBpraA9KqNjcpOhRY0idhtjNCZTu4CAQXPKyLqX zbS52c9EaOGojFW5u8uvpkkd9HxLBM/kOsfjaFOW0L6EeHsuL7ri6D7uo 6A200kvsSIGkSvivYsraqEA5NkJx9UmHwljxVD2RNyvrWxd5GNpbj+DWE YSQcXqwrsayMLVSiKRnwDgnjH29bRLJOt6RinO9Zga+ouBlXQPkT7d4Ql g==; X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="372178709" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="372178709" 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:03 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="961252466" X-IronPort-AV: E=Sophos;i="5.95,215,1661842800"; d="scan'208";a="961252466" 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:09:01 -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 4/4] vdpa_sim: Implement resume vdpa op Date: Wed, 26 Oct 2022 17:08:38 +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?1747763940098527682?= X-GMAIL-MSGID: =?utf-8?q?1747763940098527682?= From: Sebastien Boeuf Implement resume operation for vdpa_sim devices, so vhost-vdpa will offer that backend feature and userspace can effectively resume the device. Signed-off-by: Sebastien Boeuf --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 28 ++++++++++++++++++++++++++++ drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 + 2 files changed, 29 insertions(+) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index b071f0d842fb..84fee8bb2929 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -357,6 +357,11 @@ static void vdpasim_kick_vq(struct vdpa_device *vdpa, u16 idx) struct vdpasim *vdpasim = vdpa_to_sim(vdpa); struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx]; + if (!vdpasim->running) { + vdpasim->pending_kick = true; + return; + } + if (vq->ready) schedule_work(&vdpasim->work); } @@ -527,6 +532,27 @@ static int vdpasim_suspend(struct vdpa_device *vdpa) return 0; } +static int vdpasim_resume(struct vdpa_device *vdpa) +{ + struct vdpasim *vdpasim = vdpa_to_sim(vdpa); + int i; + + spin_lock(&vdpasim->lock); + vdpasim->running = true; + + if (vdpasim->pending_kick) { + /* Process pending descriptors */ + for (i = 0; i < vdpasim->dev_attr.nvqs; ++i) + vdpasim_kick_vq(vdpa, i); + + vdpasim->pending_kick = false; + } + + spin_unlock(&vdpasim->lock); + + return 0; +} + static size_t vdpasim_get_config_size(struct vdpa_device *vdpa) { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); @@ -717,6 +743,7 @@ static const struct vdpa_config_ops vdpasim_config_ops = { .set_status = vdpasim_set_status, .reset = vdpasim_reset, .suspend = vdpasim_suspend, + .resume = vdpasim_resume, .get_config_size = vdpasim_get_config_size, .get_config = vdpasim_get_config, .set_config = vdpasim_set_config, @@ -750,6 +777,7 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { .set_status = vdpasim_set_status, .reset = vdpasim_reset, .suspend = vdpasim_suspend, + .resume = vdpasim_resume, .get_config_size = vdpasim_get_config_size, .get_config = vdpasim_get_config, .set_config = vdpasim_set_config, diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h index 0e78737dcc16..a745605589e2 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -67,6 +67,7 @@ struct vdpasim { u64 features; u32 groups; bool running; + bool pending_kick; /* spinlock to synchronize iommu table */ spinlock_t iommu_lock; };