From patchwork Mon Nov 7 04:08:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Wu X-Patchwork-Id: 13033784 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8D354C433FE for ; Mon, 7 Nov 2022 04:10:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ortRV-0008PU-88; Sun, 06 Nov 2022 23:09:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ortRU-0008PK-4C for qemu-devel@nongnu.org; Sun, 06 Nov 2022 23:09:00 -0500 Received: from mail-bn7nam10on2078.outbound.protection.outlook.com ([40.107.92.78] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ortRP-0002Zx-Ku for qemu-devel@nongnu.org; Sun, 06 Nov 2022 23:08:59 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jVRxks9WdYsCLsHtCRoeyBtS+2Xzv529sULXqZh5p8P3ZR+68AyrfTq16yMNrrjcFvoQ7XVKEYOwQSiTYkM7+qeuQ+21KlH0cPtRbkGC3oympxAKPi1V2VlIfV1ZUDsANVJAnqIMcAK4Pmsx0VuZKWsafzCLtU4TiPUfEW9H6DGSCs4B5XP7InJGmt8FSZErYf8L8C7l0OIZLg2h5RHLr0M3OuFMhII1P/14HU5lJV+akYHuKcP7xTJp+Qpee2ZpWqQORT0EIi5Z0sYc5UD4sSKRR0G3tRlVwYtHRdJWEvKvS+aHzp5EyxWyuk1ryw3y3tixU6HK4saxdwbXv3/2xg== 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=RpOYEJpKQK9ijfjqnUAxvkZTuvtnmdix9wqdO6A93wM=; b=Y2ihqT0bHtn6Km0bjsalAj/iu2pMBLMMMoZcrCGfJdUrTL1UWbv+GCjqHsxm2GNVisaYWUpPF78KkOtBLIWy0s7styeHRzWIg5C07zPcdwG6f+6k/pduw8v+0j0RhrJPHuMzp/r73F9kupFVY7ibYaZdvjvyD2wqdmlyX4WzlW4a0GCWq4w9Ik0yrUVtWrAHHZBbak+jiMUEbB8eTqUEOTLe75yUi56mY015SGJ/vWK1QI2qms1vUST3L0v1B25czTAR3q5SlA61XzjB8WjfhHFVMN/taaiQgPt2YWHJwsicuXPCL7QyneuweRRBZgRkJ6uSKOOrbOPisdPkxL+WZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=nongnu.org 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 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=RpOYEJpKQK9ijfjqnUAxvkZTuvtnmdix9wqdO6A93wM=; b=RwnmZQkj1Fzf6FBbzmh2ska3kSFFdoum7wpFiZfs6zO9H/5ZfVZouXs5kAZNKClQ9zLbPa/iSPJYWQ+ypsn/3OieQVK6ak3IOBI+irqnEd8/i3cvd4GSAMuOmHKlJ1omRxKQfpbr2bh7v724nyETJjcSm9PCvmqmqHZKDsZechRL50EZt2Vqbd1jhqnEG2IhI9bGwCvvC6WNkKDUcG/8vhj43Ccx0gzEzgpZaMW99DhnEiLT/oiC3q7MqXiT3WGNLg7u0Yy9dvslB5DImXJDoC8GTRw51QQqEgpeAd9lYngxYopqZlcdNrkjkkpFjrUY8wbfRrMRZmZQXiR51nBSJA== Received: from DM6PR04CA0019.namprd04.prod.outlook.com (2603:10b6:5:334::24) by DM4PR12MB5867.namprd12.prod.outlook.com (2603:10b6:8:66::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.25; Mon, 7 Nov 2022 04:08:52 +0000 Received: from DM6NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:5:334:cafe::a8) by DM6PR04CA0019.outlook.office365.com (2603:10b6:5:334::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.25 via Frontend Transport; Mon, 7 Nov 2022 04:08:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DM6NAM11FT034.mail.protection.outlook.com (10.13.173.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.20 via Frontend Transport; Mon, 7 Nov 2022 04:08:52 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Sun, 6 Nov 2022 20:08:44 -0800 Received: from nvidia.com (10.126.230.35) 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.29; Sun, 6 Nov 2022 20:08:42 -0800 From: Yajun Wu To: , , , Subject: [PATCH v4 2/2] vhost-user: Support vhost_dev_start Date: Mon, 7 Nov 2022 12:08:18 +0800 Message-ID: <20221107040818.619072-3-yajunw@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20221107040818.619072-1-yajunw@nvidia.com> References: <20220629022517.2600911-1-yajunw@nvidia.com> <20221107040818.619072-1-yajunw@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT034:EE_|DM4PR12MB5867:EE_ X-MS-Office365-Filtering-Correlation-Id: 5e8b9805-28a3-4634-7611-08dac075c7dd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WOoGpU4Eo2O1tWgcQ5EcrO0X4qOXARPSZbsbcDVR0Tmdp328Kc9l7b3s2Rhi5GdaC+Qhll0g4Vyis1HDbxDsz8RCmiJASBpZ4WuejlfEs9/BD9q5e0eZxNxv9BSwc8BDNlqM48wvYTYyhJF1Ilu1r2HF1SKwhYXtfMU/HD1xkgQgKTURzjOKeJ8POcHiFg7jfvbNz0bVELPZ/SRw5uojSaT3SK0RQpybw1Uv1GECGqdpTWBRWYVMWLK0oeqoju/91yBl1X/Sig0LuFqj47ajAq0iM4bhvltm1Az++B59fphOYuoxe6LhhQmSldf9YPTK06ZTkYrl56gbM8Q1vBr9wjdVkFajrW7jSjbZA1Y5Oe1kJbAhLg+71bKAo4FxEgkpCoVNvrj9fNZFLC9ovn3Msz33Cj2a2IyEEMUquLXhP0MncQc+MFrW62M0X6xrezer1Ci8Sa1rdo8HNAGAyMJoQN6YvB+0MBJpjKLhyg0m8j2ZSrsiMLDBvc0EoQCKoIOkourxWiJNBUT+4QPay29oW3QbP0S6pfG0gDcn9v66qbs0X6DrS91LCwk1dKDdebPYM1AOUa7SXTW7WRPcl9GHW4KSbgVGsxcPL77f/7hmP1QR5w/twTYjaLdS/dyMHyPIhRndKSaFZqfP8JcAnV4mxXdPdIfWN7A0dpmPaHhTFUKdcOiK5/8boCCGHm9p8ukEtEh53gAuYzWXGfaPsdiJ6K3rv2ubsLiAiNPUIQ0O39DPAeYR2vqEk/JmPeXwm7af+0d6wLbKVnSGT8V7x6O4wg== X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230022)(4636009)(39860400002)(346002)(376002)(396003)(136003)(451199015)(40470700004)(36840700001)(46966006)(966005)(478600001)(8936002)(5660300002)(36860700001)(7696005)(86362001)(8676002)(26005)(82310400005)(55016003)(41300700001)(2616005)(36756003)(6286002)(6636002)(110136005)(6666004)(82740400003)(7636003)(16526019)(1076003)(426003)(40460700003)(356005)(186003)(70586007)(70206006)(83380400001)(2906002)(47076005)(336012)(316002)(40480700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2022 04:08:52.1826 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e8b9805-28a3-4634-7611-08dac075c7dd 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.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5867 Received-SPF: softfail client-ip=40.107.92.78; envelope-from=yajunw@nvidia.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The motivation of adding vhost-user vhost_dev_start support is to improve backend configuration speed and reduce live migration VM downtime. Today VQ configuration is issued one by one. For virtio net with multi-queue support, backend needs to update RSS (Receive side scaling) on every rx queue enable. Updating RSS is time-consuming (typical time like 7ms). Implement already defined vhost status and message in the vhost specification [1]. (a) VHOST_USER_PROTOCOL_F_STATUS (b) VHOST_USER_SET_STATUS (c) VHOST_USER_GET_STATUS Send message VHOST_USER_SET_STATUS with VIRTIO_CONFIG_S_DRIVER_OK for device start and reset(0) for device stop. On reception of the DRIVER_OK message, backend can apply the needed setting only once (instead of incremental) and also utilize parallelism on enabling queues. This improves QEMU's live migration downtime with vhost user backend implementation by great margin, specially for the large number of VQs of 64 from 800 msec to 250 msec. [1] https://qemu-project.gitlab.io/qemu/interop/vhost-user.html Signed-off-by: Yajun Wu Acked-by: Parav Pandit --- hw/virtio/vhost-user.c | 74 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 03415b6c95..bb5164b753 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -81,6 +81,7 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13, /* Feature 14 reserved for VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS. */ VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS = 15, + VHOST_USER_PROTOCOL_F_STATUS = 16, VHOST_USER_PROTOCOL_F_MAX }; @@ -126,6 +127,8 @@ typedef enum VhostUserRequest { VHOST_USER_GET_MAX_MEM_SLOTS = 36, VHOST_USER_ADD_MEM_REG = 37, VHOST_USER_REM_MEM_REG = 38, + VHOST_USER_SET_STATUS = 39, + VHOST_USER_GET_STATUS = 40, VHOST_USER_MAX } VhostUserRequest; @@ -1452,6 +1455,43 @@ static int vhost_user_set_u64(struct vhost_dev *dev, int request, uint64_t u64, return 0; } +static int vhost_user_set_status(struct vhost_dev *dev, uint8_t status) +{ + return vhost_user_set_u64(dev, VHOST_USER_SET_STATUS, status, false); +} + +static int vhost_user_get_status(struct vhost_dev *dev, uint8_t *status) +{ + uint64_t value; + int ret; + + ret = vhost_user_get_u64(dev, VHOST_USER_GET_STATUS, &value); + if (ret < 0) { + return ret; + } + *status = value; + + return 0; +} + +static int vhost_user_add_status(struct vhost_dev *dev, uint8_t status) +{ + uint8_t s; + int ret; + + ret = vhost_user_get_status(dev, &s); + if (ret < 0) { + return ret; + } + + if ((s & status) == status) { + return 0; + } + s |= status; + + return vhost_user_set_status(dev, s); +} + static int vhost_user_set_features(struct vhost_dev *dev, uint64_t features) { @@ -1460,6 +1500,7 @@ static int vhost_user_set_features(struct vhost_dev *dev, * backend is actually logging changes */ bool log_enabled = features & (0x1ULL << VHOST_F_LOG_ALL); + int ret; /* * We need to include any extra backend only feature bits that @@ -1467,9 +1508,18 @@ static int vhost_user_set_features(struct vhost_dev *dev, * VHOST_USER_F_PROTOCOL_FEATURES bit for enabling protocol * features. */ - return vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, + ret = vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, features | dev->backend_features, log_enabled); + + if (virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_STATUS)) { + if (!ret) { + return vhost_user_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); + } + } + + return ret; } static int vhost_user_set_protocol_features(struct vhost_dev *dev, @@ -2615,6 +2665,27 @@ void vhost_user_cleanup(VhostUserState *user) user->chr = NULL; } +static int vhost_user_dev_start(struct vhost_dev *dev, bool started) +{ + if (!virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_STATUS)) { + return 0; + } + + /* Set device status only for last queue pair */ + if (dev->vq_index + dev->nvqs != dev->vq_index_end) { + return 0; + } + + if (started) { + return vhost_user_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER | + VIRTIO_CONFIG_S_DRIVER_OK); + } else { + return vhost_user_set_status(dev, 0); + } +} + const VhostOps user_ops = { .backend_type = VHOST_BACKEND_TYPE_USER, .vhost_backend_init = vhost_user_backend_init, @@ -2649,4 +2720,5 @@ const VhostOps user_ops = { .vhost_backend_mem_section_filter = vhost_user_mem_section_filter, .vhost_get_inflight_fd = vhost_user_get_inflight_fd, .vhost_set_inflight_fd = vhost_user_set_inflight_fd, + .vhost_dev_start = vhost_user_dev_start, };