From patchwork Mon Dec 25 13:42:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13504694 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2089.outbound.protection.outlook.com [40.107.244.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE3DA52F65; Mon, 25 Dec 2023 13:42:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="K2jI58W+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k82Th7v9OGKBtC9YoBy0Gz74hbEK7nCz7nniyeFiSEB9b9LeEC799/w6aCegW3dChLAjpYarEYoJTmyCcUr9ctImqoCsn4FU4UNL56mqfdAT2zqFAgNY+3Be06Y+U7hOSSDed4tUudxEcvbhQDE2oUVFMI5rEB850wAYYdjkjkdxIQ3vYitwjvoNYt7HP1zIxEpwMlBDGvHGf4hQP01lgxgQCv0kEo3KYYNI1bZfeEOnfncIvtR8dHE+Xbjyyfrb7PI4ezsAAt7Vor0lm0tVV8qyca6e7DtnwsCqhNN5wXThVIeBbuw8I+Vp5hakznlLMcFbBS6o7lBB7Tifif+K0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dvaJ5qRnej7WGFnOQvn9JQGmb6CfIBXSHf6q8pzSba8=; b=aYQ1ix127thdRPv943CNOw+Q2srKpWWna+bSHCAB+l1jkdYAzr4VBYY5vXl+lEmVyzaLETr2vKAHah/rLcBPt5W6LrUyOtINLUlgojucYJD5BwS1EGKN9LLQUA4/zl7djQ9YKf8OJY9rncTgfucyIA48ZZzYeNV9GQIcBY9aItztRlTLSmmgOXDycMwAuVQigEzOczaDFdCA8Tcoxj9iGkIyB+CJG+WVh64Y802Ppp+3PQ/SGletkqKiT8xg+PU/aUpqEAHtpufY6uoRrjKOdoM/eYI/9cUPAJOkdgp47RwxVqzq5Zu4DxlOWZCyNhHrfxKMsmLZDFqcGdafzT/sTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dvaJ5qRnej7WGFnOQvn9JQGmb6CfIBXSHf6q8pzSba8=; b=K2jI58W+4BgdyM0Y72bZ42vfyLGuI+Q55lgj173ebKxm+nXT39vDKSNgKI5AitFvy0xzF/zmmvmbEm0jdnYa3I8aXP2MSAUK5FoVp2A2xOJCrccfPEilo2/jefUORa7Wiofdw96Y+s4BGThTN1Y1gLky5TKOR0/hZ9VJNXIyxsm/OGAbk6+Yh3htunpRrZbxBgQI2LBNjw7qUiS+ovqjWrHGdm+DF8vP2C/zdA7dtKCRI9wFUA4/o6y0daC6eYgcV+Mbg5htxO7RehXrdvcRx2T4kAq/tSmYOh7+64/Q+M9fDyO4TUZSRVEFzFA61RCT0pxhsy3vjcAHMox6mD22Uw== Received: from BL1P221CA0028.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::18) by MN2PR12MB4423.namprd12.prod.outlook.com (2603:10b6:208:24f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.27; Mon, 25 Dec 2023 13:42:35 +0000 Received: from BL6PEPF0001AB56.namprd02.prod.outlook.com (2603:10b6:208:2c5:cafe::9f) by BL1P221CA0028.outlook.office365.com (2603:10b6:208:2c5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.27 via Frontend Transport; Mon, 25 Dec 2023 13:42:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL6PEPF0001AB56.mail.protection.outlook.com (10.167.241.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.14 via Frontend Transport; Mon, 25 Dec 2023 13:42:35 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 25 Dec 2023 05:42:19 -0800 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 25 Dec 2023 05:42:19 -0800 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Mon, 25 Dec 2023 05:42:16 -0800 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , , "Gal Pressman" CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo Subject: [PATCH 1/2] vdpa: Track device suspended state Date: Mon, 25 Dec 2023 15:42:09 +0200 Message-ID: <20231225134210.151540-2-dtatulea@nvidia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231225134210.151540-1-dtatulea@nvidia.com> References: <20231225134210.151540-1-dtatulea@nvidia.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB56:EE_|MN2PR12MB4423:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c480dc1-4a9b-4518-64ec-08dc054f5a66 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xPx1j6+n9NX8/g/JphRNgo6YMJQwSR6umMTrRBf23x9MR4GlRbV5kV57if/fKNyBKqN7aFCC5EAEoOmtO6fZy0QrlvTWnwXLjoAOsy4Faj1vJ5m44RUO+ywqP7K7Cb2dZ4VDMY5LNpS8XKx/IcSgOJO703B5bx+VOvO31e9nhrWfYKp4K5Gu3IglvXzrTMeDsqn8AqRaMn1rZ1Pyl6ZS7167eh1BXMSybw6yLN8ZyKEPhrxXnqsd2SPrs9IV5c5w1AgXaf2Ug/zLP1H+7wH00x6ap4SS+JQ+NfppxosBPZSUceEFOkPvHcb0m3eH1xm4TOoSoHv2PADVWj+wq4mumjC7S3zW9RVAbBk8iFA6mfoGkfX2A87KZSowRCca7FHwAZffbP8b9T6+1pSEmRe8VXQKZGtQydTSfD7a7SxXPChH7IuhL7mETpXRWKuPwP4GyJs6dSeiaSHZSTDtxjdSBa09V0ZmZGaSlOrs1NV1okRZWytN0qHh2aFMabsNdsSWkVgI2mrvISyu8imSzlW9dNjxKj2u+cZuHGcNJxzIGhUw8G8mzSV0I0agvDR/FmRMVILJJE0+dxUQagvKe0X8MHpMKIkT7KRezAzYXNUMATCYB2+hzjaHZPO2meHTZ5wfm10WembtR8p0FFoIOzFO0nT2omaZn6qsfMeSDUh3MEQe1uXHtCypwlEc08Rzi4+sUwjXWTAypWgGsx9kst/Fbz2amOPDRHoHtq1wAnV/MJ0naiMDonsJBwpj2g6i865u X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(396003)(346002)(39860400002)(136003)(376002)(230922051799003)(186009)(82310400011)(64100799003)(451199024)(1800799012)(46966006)(40470700004)(36840700001)(40480700001)(36756003)(40460700003)(6666004)(6636002)(70586007)(70206006)(86362001)(336012)(66574015)(426003)(1076003)(7636003)(356005)(82740400003)(26005)(83380400001)(2616005)(47076005)(41300700001)(2906002)(15650500001)(5660300002)(8936002)(8676002)(478600001)(36860700001)(54906003)(316002)(4326008)(110136005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Dec 2023 13:42:35.4795 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c480dc1-4a9b-4518-64ec-08dc054f5a66 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB56.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4423 Set vdpa device suspended state on successful suspend. Clear it on successful resume and reset. The state will be locked by the vhost_vdpa mutex. The mutex is taken during suspend, resume and reset in vhost_vdpa_unlocked_ioctl. The exception is vhost_vdpa_open which does a device reset but that should be safe because it can only happen before the other ops. Signed-off-by: Dragos Tatulea Suggested-by: Eugenio Pérez --- drivers/vhost/vdpa.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index da7ec77cdaff..4c422be7d1e7 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -59,6 +59,7 @@ struct vhost_vdpa { int in_batch; struct vdpa_iova_range range; u32 batch_asid; + bool suspended; }; static DEFINE_IDA(vhost_vdpa_ida); @@ -232,6 +233,8 @@ static int _compat_vdpa_reset(struct vhost_vdpa *v) struct vdpa_device *vdpa = v->vdpa; u32 flags = 0; + v->suspended = false; + if (v->vdev.vqs) { flags |= !vhost_backend_has_feature(v->vdev.vqs[0], VHOST_BACKEND_F_IOTLB_PERSIST) ? @@ -590,11 +593,16 @@ static long vhost_vdpa_suspend(struct vhost_vdpa *v) { struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; + int ret; if (!ops->suspend) return -EOPNOTSUPP; - return ops->suspend(vdpa); + ret = ops->suspend(vdpa); + if (!ret) + v->suspended = true; + + return ret; } /* After a successful return of this ioctl the device resumes processing @@ -605,11 +613,16 @@ static long vhost_vdpa_resume(struct vhost_vdpa *v) { struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; + int ret; if (!ops->resume) return -EOPNOTSUPP; - return ops->resume(vdpa); + ret = ops->resume(vdpa); + if (!ret) + v->suspended = false; + + return ret; } static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, From patchwork Mon Dec 25 13:42:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13504695 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2081.outbound.protection.outlook.com [40.107.95.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4020F524A4; Mon, 25 Dec 2023 13:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="tUNwWgwn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ls4cTceGbRUxSswUyDh0mkQm1HQgQ06e+WKkaH4Nm/cTLja4VUeRe+s5GJzYX6S9SCWFguNj1aGASq5XOGRRIe65zmxDSQp9X9RlfjGZft/rdsGnXYFQBALfyOeg8uBQfwKkIGekg0qXy+BDpipMLwMppyKa47SqkG7HwM0sQ5Vs+nmuctBd32kP4mEU3YYktoboE7nB9v6XiK7DDoHLsM8YW8HsQrXKpwArni6XdQV3vw89nUmC2bZ5U8PD+K/3w7IR39NRTLIF/bmAzL8rq/Xek2a+UrwO7o9X9HikAA3+f38sKE9YUMLwPcgQnxyzO8EzQqRPwbrfymlnqP0UnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aBfyYSvTtsV8U/bPOwpFxpHHQ3hgt4hXnhFlHJScCx0=; b=VHcDLUaf2Ewhj8kHyBRzPClgrf5mvJmcVCt+dIPNF4tfSuoGTf+/sbtxB92qZEHn+eRjKMBsvvRaQWZirVYLNO6b0z1GqkLUXg3Fv1Z+EQLZyJj72eEl1o+q+6JB0JS1j0MxFHEKnqUn1OTP4LZe9JpY0dntZNLjfLlG42dn9WVjVrLXEDZaMYwVsMraySNjAbmL6H58BUr99QC2KNVEbOp7Xgpr9X+uJrxLOtHzpG2rJpIVzvWeC23Fqx6iacaq9VmQkR+mOD4r7jW9JZyIDjIHb+jjGOG2H7VmmiXz54X9YTyAyZ+pRvFZ8qXnEiYfjr0fnYefs/MWcZmWVzMOkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aBfyYSvTtsV8U/bPOwpFxpHHQ3hgt4hXnhFlHJScCx0=; b=tUNwWgwntKo7Lmte0gKhvz8Puhz40buvRuA2SKVLiLfZVOEI4rCMELon8x9WtXQiZXO4KT7fXfM4yR3/4Nu+TLB3BzBPf2DhruozbeN8BAefJF8fzTnv5vADDraA8Lrpm9bMeX+y6Zc3cxUTQOTaSXAqNOiWkzeJR1iFUP57cfvRUoKTfcAOSoSCrQmLMokCmE+pDvyyk+mSaOUhEC7xbD+XuHJOYOgkmyWyp3cu8b2TDCBoSRhhCXJPfdKohobwUMftDOE3b0/aiU2NCXx3lDmsS8aKMbZ23KDZM69CeOJC63niSTvjcfwMjKQTsH2lwnerI9VEBs7EIwL0fETq0g== Received: from BL1P223CA0010.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::15) by MN2PR12MB4517.namprd12.prod.outlook.com (2603:10b6:208:267::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.27; Mon, 25 Dec 2023 13:42:50 +0000 Received: from BL6PEPF0001AB55.namprd02.prod.outlook.com (2603:10b6:208:2c4:cafe::32) by BL1P223CA0010.outlook.office365.com (2603:10b6:208:2c4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.26 via Frontend Transport; Mon, 25 Dec 2023 13:42:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL6PEPF0001AB55.mail.protection.outlook.com (10.167.241.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.14 via Frontend Transport; Mon, 25 Dec 2023 13:42:50 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 25 Dec 2023 05:42:38 -0800 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 25 Dec 2023 05:42:38 -0800 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Mon, 25 Dec 2023 05:42:35 -0800 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , , "Gal Pressman" CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo Subject: [PATCH 2/2] vdpa: Block vq property changes in DRIVER_OK Date: Mon, 25 Dec 2023 15:42:10 +0200 Message-ID: <20231225134210.151540-3-dtatulea@nvidia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231225134210.151540-1-dtatulea@nvidia.com> References: <20231225134210.151540-1-dtatulea@nvidia.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB55:EE_|MN2PR12MB4517:EE_ X-MS-Office365-Filtering-Correlation-Id: aeed7c76-c2a4-4168-7e95-08dc054f635f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RwbPnSBdoluD3T4nF7Ew2ofQZc6V8Hpdl+zgworaKrzwoHaAhHC9ElxhLSRJDf1wA8W7p4QEMvFc96gFKuhHAU9exgGAl5ppgTs6qhls48RcqmaETSNEB/glOs5A+yPVQTbA1VOS3hwYP87OgOBOSy9RDMljRFoB/7pSaNoa4bCLQ/n+BkqBGzScxBMzi7rnmWiobYfLKQKhq6BVh7C+MH3yfnua6XApRy0BFSVPu5P/uMiZXOPi1ghKx6QZCk6xAiF/xghiIaZS7n+AJSFp+w4BjyjgTZgjIJ8dy/njdiR8E3OjIiglpRX0BKx1IpAgVCVI1UVkxLnnwIGtroI66UxcjZgMNc6og1QGD7FUGwUJNWyKHVg2TMM2JGB2POwvGRwrLsD1y9YECWnk+K7xV6kBJNC/6rWzgmtBuUMCQfg1sFOniaeZg/Sdsio5qvuInvErNRVjqyae+LEWxrmIU36WgGCFz8IPmGgcMg8tJRfJPxvuM6LK+7d3bnJUS8ebItJtF8lAIQkP2waVavCEWH7DxT6lL+U4c8LS1kFI9/C6spjSiBs8t7Jw5t43XElBInmyNv6p3OTCN81wyHVChJNKJU1B6obKiiQ0ovHb11GWfMlLZTLmo7jQBjiUnfUJTnpbya1iGYxdXgNyjRQ8FwybE4gU98Iw9YWnEVFnap0EO+bPRooQmDpryWOZzoTCBlrbFGqMH7J2ii3XGPBujVe/ZEi/tz6v/RWbSAWWeg79fFijmzpSZtIjjqb3w8Ym X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(346002)(136003)(376002)(396003)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(82310400011)(46966006)(40470700004)(36840700001)(82740400003)(7636003)(356005)(83380400001)(110136005)(6636002)(70206006)(316002)(70586007)(54906003)(47076005)(8936002)(4326008)(8676002)(6666004)(66574015)(478600001)(1076003)(26005)(336012)(426003)(2616005)(41300700001)(36860700001)(5660300002)(2906002)(40480700001)(40460700003)(86362001)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Dec 2023 13:42:50.5494 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aeed7c76-c2a4-4168-7e95-08dc054f635f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB55.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4517 The virtio standard doesn't allow for virtqueue address and state changes when the device is in DRIVER_OK. Return an error in such cases unless the device is suspended. The suspended device exception is needed because some devices support virtqueue changes when the device is suspended. Signed-off-by: Dragos Tatulea Suggested-by: Eugenio Pérez --- drivers/vhost/vdpa.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 4c422be7d1e7..620073383d15 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -703,6 +703,9 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, switch (cmd) { case VHOST_SET_VRING_ADDR: + if ((ops->get_status(vdpa) & VIRTIO_CONFIG_S_DRIVER_OK) && !v->suspended) + return -EINVAL; + if (ops->set_vq_address(vdpa, idx, (u64)(uintptr_t)vq->desc, (u64)(uintptr_t)vq->avail, @@ -711,6 +714,9 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, break; case VHOST_SET_VRING_BASE: + if ((ops->get_status(vdpa) & VIRTIO_CONFIG_S_DRIVER_OK) && !v->suspended) + return -EINVAL; + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) { vq_state.packed.last_avail_idx = vq->last_avail_idx & 0x7fff; vq_state.packed.last_avail_counter = !!(vq->last_avail_idx & 0x8000);