From patchwork Tue Apr 16 19:30:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Jurgens X-Patchwork-Id: 13632439 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2083.outbound.protection.outlook.com [40.107.94.83]) (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 AC2B513848B for ; Tue, 16 Apr 2024 19:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295877; cv=fail; b=cHadMt/TB4qZAaY9H5YMjZPGe36RZzvqPtHMxhexM8jHogsoACP9BIsmLd6TDl1dp968PAp3Yu/b99ex8e1a+qk9SXVnkCdk8LkVaV4KpLpC0SiKSykvvC8IgeDLFzBoeab/Qch4Rh+zz/fCF6JgjaSIUKvrczZqB7od9tEMm4E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295877; c=relaxed/simple; bh=pnOqH6iHv7NL32V89mNbIm0iyq5N7jureUnXTftRtcU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C/BCiRVRDbcND1psX7EVWr/iBTYXwvDgZ+8r5X6ufWZy4uMErILp8rDcXBsu/ajAatew3IKF2wGR7EXIO84JGkapA1vSQQ5ABvmD21o5Zgn/CvQiqZ60uzwzwIm8Wz8fxI/wsRIvJzml2bvILDhx+PASsp9NTgBaojNpHW/Hbh4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=DIYq2LO8; arc=fail smtp.client-ip=40.107.94.83 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="DIYq2LO8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aJwY9qQewJncrqIjXKn9LVp4zse+ze/G8+Q+kArpLzGBrcR86X/Fm5YQQeVTnbXXFQOFYQ4li2kFbGks2PRHQADkm4QANtPhNFNxY4CEADPIvILVOsORAqVtAJcQnDp7cfJLbFmibDmHq/L/vFAniJkzlROeu3eGIzg4mleD1LgitTFU88rpJN8HCyTCZNr0PQ65B/ayg06MFlQOAUcoMQ1DIoN8v6c0FNsGCx+jguvsTiIcJOA5OpghtXSFaAV09k4PVwB5C0I0bNWwgnGphyh8sojxEx8fiD8L8IeANcIKnWvWp03/bZUxVURSLabyiVohRhXsOpmtBoJ1FLtqPQ== 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=+jw90/y+0sI0GgoIU8LZL8BR5r2COe7SIhzBxhu0Fug=; b=bDlOBanv4YJnqaeRA1b2DHFm+Kx6XO7pvTHyjpm7POGEGjmHclUWuq5mLCfGudpWEU/cwXtHypQDC9c6Aug8pj12I6iCnWNMDEvo91bmYoamJOiQAeTpv5h7/wI9JNV2fDwYQbLKGbFBjYSNw7Lo/95BqxcdFoxEnva5hN+tjssnt3qxwlNjvlpjW733K+m6hIkWujZhmbCYgilgg8v7If4qAzXH7JNLzwHpUWxVyDzgg1qZDVEhbYTdy+MTJ5oE7Udmcco3o8bUIzgaOi6HlgZafd8ww8IuY9G6tMuCFdqGhlL8A8wJ+fT5feY2EIxcZpJL4ZEIXejzK+oBwyyNUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=vger.kernel.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 (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=+jw90/y+0sI0GgoIU8LZL8BR5r2COe7SIhzBxhu0Fug=; b=DIYq2LO8qDwqJoucgS6NLQRkz1Rlbp3DkFSjjM+i6xyRlFm/1XpRXwPXtsLlx5aIl2o/FPWIoAoLB4BvINveChWfUGSsLTguK/o3nTVZffzPizeBv0BEAbfIRFO03ypuKmZzG6xYQwXbZ3mdTtJpvYq4oXGPzQRfC6z1rZn3YOu6cU1xg9jnZBPZbxpAzU49AVunQudGS5AJnFQfwyyJhUuEHONx1m/DePMWFyjnSCWVVB9r9GS8TlG2MhbeXOOCHI855C/CuUIgM9BFJW3KbHzJ7OtcMgHSEA6mi9mISwJR0DtrNCo3JkPMi0iZVq7oTWP7Mux7bbrmVM5GfMgqSg== Received: from BL0PR1501CA0006.namprd15.prod.outlook.com (2603:10b6:207:17::19) by CH3PR12MB8284.namprd12.prod.outlook.com (2603:10b6:610:12e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Tue, 16 Apr 2024 19:31:13 +0000 Received: from BL02EPF0001A103.namprd05.prod.outlook.com (2603:10b6:207:17:cafe::65) by BL0PR1501CA0006.outlook.office365.com (2603:10b6:207:17::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.33 via Frontend Transport; Tue, 16 Apr 2024 19:31:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BL02EPF0001A103.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Tue, 16 Apr 2024 19:31:12 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:48 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:48 -0700 Received: from vdi.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 16 Apr 2024 12:30:47 -0700 From: Daniel Jurgens To: CC: , , , , , , , , , Daniel Jurgens Subject: [PATCH net-next v4 1/6] virtio_net: Store RSS setting in virtnet_info Date: Tue, 16 Apr 2024 22:30:34 +0300 Message-ID: <20240416193039.272997-2-danielj@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240416193039.272997-1-danielj@nvidia.com> References: <20240416193039.272997-1-danielj@nvidia.com> Precedence: bulk X-Mailing-List: netdev@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: BL02EPF0001A103:EE_|CH3PR12MB8284:EE_ X-MS-Office365-Filtering-Correlation-Id: 080dbdeb-54d9-4fa3-91be-08dc5e4bc6b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K53wuxeK+e82G0TTwal3D3eTL4wxTpIujBdCSlAO3KnsOSDwD/cwqX8sec7pzD+pOxU4wy8LiWicEIvHvB2iVPhpNNxPjc685NL2XJLMtQXavE7fVkGWwWcILmWcpvB3/7hOP9qhH1GP/ISOcRKzEukIGO8GX+zF1Ub3olzlYiU2Zhp+hJHg1XulMsSHVAJB8A8x4HnsIiQuj5xv4i4aA4vxYf33Xqw1QJ80Enq1jNUNaqCPxL92EoCXryU7tIJEuBE16qEw0W7KYmo1pglhNdOnG38D0+eIXdJwtuOKOX6rQN4/3hYeCOSQtEBZIDYEKKP7xb2FAol0xofqpBDLG6r6lQEQvosxS+0EEdVtyOxiQnpHrpgsGKrID0pqggW9xhvvmiBIYMmbzQfKNVj8/ixUmW/013LJQoy9klazNtZ43untib856VBV6WKAfADXN9cxBGpAgQArsdzPT0QXLZvYWdbP0NccoruQF8I2K6fqveKp3RfjOYkaaWGa3QIRL/Qc6LfN1q1m0NBIfhGmQnZXaO2MQ3D3BWTN87OJfsVKzGxnxZ+AL/8hxsNIpqoIz44ZtTcP05tGgayD4atJGmn1rZoH67kr9xs4DtU3uwD8t3K96ygwDtwF4C50CR4Hq45dW8XDqUAVLAgeKUz5rmDmwDZXeb6d9rH+cfR3GbAy/JGN+FFK1quWRmmTKUAmBtjdtsjjcjArcGl5d6eXIOy/g8y+lp5u2oPwJ1cMLR+kHRkxKPxzvVB5rU/Kdn5t X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(36860700004)(376005)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2024 19:31:12.7082 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 080dbdeb-54d9-4fa3-91be-08dc5e4bc6b5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A103.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8284 X-Patchwork-Delegate: kuba@kernel.org Stop storing RSS setting in the control buffer. This is prep work for removing RTNL lock protection of the control buffer. Signed-off-by: Daniel Jurgens Reviewed-by: Jiri Pirko --- drivers/net/virtio_net.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 115c3c5414f2..7248dae54e1c 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -245,7 +245,6 @@ struct control_buf { u8 allmulti; __virtio16 vid; __virtio64 offloads; - struct virtio_net_ctrl_rss rss; struct virtio_net_ctrl_coal_tx coal_tx; struct virtio_net_ctrl_coal_rx coal_rx; struct virtio_net_ctrl_coal_vq coal_vq; @@ -287,6 +286,7 @@ struct virtnet_info { u16 rss_indir_table_size; u32 rss_hash_types_supported; u32 rss_hash_types_saved; + struct virtio_net_ctrl_rss rss; /* Has control virtqueue */ bool has_cvq; @@ -3087,17 +3087,17 @@ static bool virtnet_commit_rss_command(struct virtnet_info *vi) sg_init_table(sgs, 4); sg_buf_size = offsetof(struct virtio_net_ctrl_rss, indirection_table); - sg_set_buf(&sgs[0], &vi->ctrl->rss, sg_buf_size); + sg_set_buf(&sgs[0], &vi->rss, sg_buf_size); - sg_buf_size = sizeof(uint16_t) * (vi->ctrl->rss.indirection_table_mask + 1); - sg_set_buf(&sgs[1], vi->ctrl->rss.indirection_table, sg_buf_size); + sg_buf_size = sizeof(uint16_t) * (vi->rss.indirection_table_mask + 1); + sg_set_buf(&sgs[1], vi->rss.indirection_table, sg_buf_size); sg_buf_size = offsetof(struct virtio_net_ctrl_rss, key) - offsetof(struct virtio_net_ctrl_rss, max_tx_vq); - sg_set_buf(&sgs[2], &vi->ctrl->rss.max_tx_vq, sg_buf_size); + sg_set_buf(&sgs[2], &vi->rss.max_tx_vq, sg_buf_size); sg_buf_size = vi->rss_key_size; - sg_set_buf(&sgs[3], vi->ctrl->rss.key, sg_buf_size); + sg_set_buf(&sgs[3], vi->rss.key, sg_buf_size); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ, vi->has_rss ? VIRTIO_NET_CTRL_MQ_RSS_CONFIG @@ -3113,21 +3113,21 @@ static void virtnet_init_default_rss(struct virtnet_info *vi) u32 indir_val = 0; int i = 0; - vi->ctrl->rss.hash_types = vi->rss_hash_types_supported; + vi->rss.hash_types = vi->rss_hash_types_supported; vi->rss_hash_types_saved = vi->rss_hash_types_supported; - vi->ctrl->rss.indirection_table_mask = vi->rss_indir_table_size + vi->rss.indirection_table_mask = vi->rss_indir_table_size ? vi->rss_indir_table_size - 1 : 0; - vi->ctrl->rss.unclassified_queue = 0; + vi->rss.unclassified_queue = 0; for (; i < vi->rss_indir_table_size; ++i) { indir_val = ethtool_rxfh_indir_default(i, vi->curr_queue_pairs); - vi->ctrl->rss.indirection_table[i] = indir_val; + vi->rss.indirection_table[i] = indir_val; } - vi->ctrl->rss.max_tx_vq = vi->has_rss ? vi->curr_queue_pairs : 0; - vi->ctrl->rss.hash_key_length = vi->rss_key_size; + vi->rss.max_tx_vq = vi->has_rss ? vi->curr_queue_pairs : 0; + vi->rss.hash_key_length = vi->rss_key_size; - netdev_rss_key_fill(vi->ctrl->rss.key, vi->rss_key_size); + netdev_rss_key_fill(vi->rss.key, vi->rss_key_size); } static void virtnet_get_hashflow(const struct virtnet_info *vi, struct ethtool_rxnfc *info) @@ -3238,7 +3238,7 @@ static bool virtnet_set_hashflow(struct virtnet_info *vi, struct ethtool_rxnfc * if (new_hashtypes != vi->rss_hash_types_saved) { vi->rss_hash_types_saved = new_hashtypes; - vi->ctrl->rss.hash_types = vi->rss_hash_types_saved; + vi->rss.hash_types = vi->rss_hash_types_saved; if (vi->dev->features & NETIF_F_RXHASH) return virtnet_commit_rss_command(vi); } @@ -3791,11 +3791,11 @@ static int virtnet_get_rxfh(struct net_device *dev, if (rxfh->indir) { for (i = 0; i < vi->rss_indir_table_size; ++i) - rxfh->indir[i] = vi->ctrl->rss.indirection_table[i]; + rxfh->indir[i] = vi->rss.indirection_table[i]; } if (rxfh->key) - memcpy(rxfh->key, vi->ctrl->rss.key, vi->rss_key_size); + memcpy(rxfh->key, vi->rss.key, vi->rss_key_size); rxfh->hfunc = ETH_RSS_HASH_TOP; @@ -3819,7 +3819,7 @@ static int virtnet_set_rxfh(struct net_device *dev, return -EOPNOTSUPP; for (i = 0; i < vi->rss_indir_table_size; ++i) - vi->ctrl->rss.indirection_table[i] = rxfh->indir[i]; + vi->rss.indirection_table[i] = rxfh->indir[i]; update = true; } @@ -3831,7 +3831,7 @@ static int virtnet_set_rxfh(struct net_device *dev, if (!vi->has_rss && !vi->has_rss_hash_report) return -EOPNOTSUPP; - memcpy(vi->ctrl->rss.key, rxfh->key, vi->rss_key_size); + memcpy(vi->rss.key, rxfh->key, vi->rss_key_size); update = true; } @@ -4156,9 +4156,9 @@ static int virtnet_set_features(struct net_device *dev, if ((dev->features ^ features) & NETIF_F_RXHASH) { if (features & NETIF_F_RXHASH) - vi->ctrl->rss.hash_types = vi->rss_hash_types_saved; + vi->rss.hash_types = vi->rss_hash_types_saved; else - vi->ctrl->rss.hash_types = VIRTIO_NET_HASH_REPORT_NONE; + vi->rss.hash_types = VIRTIO_NET_HASH_REPORT_NONE; if (!virtnet_commit_rss_command(vi)) return -EINVAL; From patchwork Tue Apr 16 19:30:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Jurgens X-Patchwork-Id: 13632441 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2083.outbound.protection.outlook.com [40.107.101.83]) (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 07C651384AB for ; Tue, 16 Apr 2024 19:31:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295886; cv=fail; b=BNkpQtvQLwDCdEdFPKbxTPMRZMLCzgY1HPPALPeMhfsvyCingx9lnzN6KLJa4wsLNqDNOuS4Hy4KdgvBF4NatgHinwg+RC83KZ84NaRqzyGOQq99lLX9w0esvZlN/ieYn2fngEoUGvDrhe8yE1EWDmCHf+dZOaZ5nmIr03NijCI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295886; c=relaxed/simple; bh=faPBhRiMloCW3hvR2ZjSMcYeF3YINQvYToCDvrMYfK0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mOmvgxSmAxXLLlDO6kF7pSXgtjpb4WNatx4kDQBh4fgcKDV4so95jrNVNsY8Tx2+rYIqiZAaBHthcxpn+omfU3iXH7VjPm99t+WtzxT2LPfeCGgYsuC6JzmwJwTtRV72j4GlwZ/+BS7KY2/FwEz1/i4jMpiWuw8BZ9j+Qq2gH3U= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=CePgrLr0; arc=fail smtp.client-ip=40.107.101.83 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="CePgrLr0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lH8jVIxeKvuJP7TViPCBMDogckRx+DlOeTflgYcA6Ct+y2LZTtkDB+mmZ0bP64mdAha0DyLlxbsANiNqVtS4qps+cFkz7P9auC/EVQWTB6BGQ2rNig4LcBc9Pre6lCibFyKahvVi4JqDTLzgJjI3zy/YUU9Tn6Hhao374WxK2MlJBGDC828Zb31v/o9kJy4sMkMzConLR7Dgt37ZkZiuMTMsuMjA0KnBwweodFFwooypyKkVT22LZIq9kNRBpn4HlOmz/ojpcbN7/I1m77gC3J9Gn+vLFAnzh1jZ4YRHpDQ3JV1pwmYQYgPgTMhKOV17MuZp8wpsj24o3h89ZbIeGA== 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=JMHqiEPqezP/HQsOKJ08ZsTO9mxHb/ZXdGEU5bUd+Fw=; b=S+u7SKAsZIB2STwVwTTofYjMbb1jm47ac+coEWkHFqTnCpq4njlaMFZ2HQP6jXZLZoLfGLzpBumOogAuzR50e/w8T20xqQ7odDSV201axZeGS90PXAL7SSWjeOaCn637TlLvzhK/5/wwPKQWF5F+vH1v9DEb3K0QxOLQ3NBUhjZhazXJzwpMypWg78Z0xicwOwAC8SP8VcdKq157uxMsqkzLpQE6CzTdKeSd5E5AKox/7PPkCq/6Y7DEqz1WvbI1bxbbf5ZvN/HcISvCkmOhHVAhHgeEEXoDVIBogZhsNUS3byIt4HNGqmIvGrcoHJRHLxELFUupiBp8bzGKmqWJ8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=vger.kernel.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 (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=JMHqiEPqezP/HQsOKJ08ZsTO9mxHb/ZXdGEU5bUd+Fw=; b=CePgrLr0q4HzTZSXqBpUfzHuopFC2gkxZ9B2wOkIcz50vKOj9iA3nAKouwZ1jUdYwcgwM3vbr5KjPwxQbwAAv7ze/Trw+5LmS1mEt1iLj7TUK72loVV6qmZz6QydVB7g7bWdpkSqV/66M+rmiNDx+IPiLCMTqYB8reADt+EMlW7b2GBXfTchIw6v4cI9APiKrUkhE9xk+mN3Zk64W29MCjMLRtePR2Ut7XP3Q33Kg2SO+oDSVhpWsQSkiOogZew2+GX7s328wgEZEJRsT26wjonsDRKZk3rv99eTvPRsf59Q1Ylekl1lv3YxUlL22VOXp+GoIDTzU4IXPmHks48MxQ== Received: from BL6PEPF00016415.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1004:0:d) by SA1PR12MB8918.namprd12.prod.outlook.com (2603:10b6:806:386::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.43; Tue, 16 Apr 2024 19:31:21 +0000 Received: from BL6PEPF0001AB75.namprd02.prod.outlook.com (2a01:111:f403:f903::) by BL6PEPF00016415.outlook.office365.com (2603:1036:903:4::a) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.33 via Frontend Transport; Tue, 16 Apr 2024 19:31:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BL6PEPF0001AB75.mail.protection.outlook.com (10.167.242.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Tue, 16 Apr 2024 19:31:20 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:50 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:49 -0700 Received: from vdi.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 16 Apr 2024 12:30:48 -0700 From: Daniel Jurgens To: CC: , , , , , , , , , Daniel Jurgens Subject: [PATCH net-next v4 2/6] virtio_net: Remove command data from control_buf Date: Tue, 16 Apr 2024 22:30:35 +0300 Message-ID: <20240416193039.272997-3-danielj@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240416193039.272997-1-danielj@nvidia.com> References: <20240416193039.272997-1-danielj@nvidia.com> Precedence: bulk X-Mailing-List: netdev@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: BL6PEPF0001AB75:EE_|SA1PR12MB8918:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a25fabf-6b9e-4ba0-b246-08dc5e4bcb94 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3t7k7SiVtJQKvRJL+b+udBwT+le7HSnM106W/L5jqe1XFc+Z0/zCbvGtIHhVw6AzmAtju1ubsbvtNOiMaYeMsi+ziYKSBnsa69DtT5dGR7iszYYuSzkKFdMNPiEG9mrIKHWSIwbnlXSdIM0gkL1RK3D8rS1vTFdgY6OcSANmukLj+DXx2Sgd2QuZm6DSnHxlfOcs2iti8Jad1xqYsiNl6HwdSUejxMqBZ0Tmi7KXNSQuEQ06/Sw/L3wJRy6fLxFe8Bb2JTa/7bBEdM1jJO8/gGV1nWEdUMMyDiSpin69RAq6tc6eeHuFjWzPPnSuP6tOPp3imEg/QHTPpZ+ysz7eEAIIIyahu3BmXQJEfeONrrRclNn7ZsZLJVrtvUz36a1VhoO1l8Yn2/Q0yilyd2tJDxPGwbEcOqMhIY0t9/3wcxPA9Ya1SIoxOHDrqTyD4oMuPkw9utJ9PHFyfWeXRGdVXvWVX/LB0HbBEATrfwagstRib3EtPL5ovnZhp/YEwZje+jOwhWdPYn8YOhl5C17w8WuNlOScd2NzckIvOuFW2e49r6P1QhXIbA8Jcxk7H3gzPxoJuJmJqNoU1Oin3Io+AnCfhJTHAHU3wwbGDrbxRoACUWxQnPQvyEjd/sYTMEEFqPLjxf0SPLvTIEzAGbVwneuT3N3Agpwo/M+5eh3z8guCX65Z8SsJIql7E/zZha3e6kafCIKo4ip98KjStdeYRYisnvKxSbWegKu6rzh/Jcd1Bc06UfK9NRGg4qxcr9u8 X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230031)(376005)(82310400014)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2024 19:31:20.8970 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a25fabf-6b9e-4ba0-b246-08dc5e4bcb94 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB75.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8918 X-Patchwork-Delegate: kuba@kernel.org Allocate memory for the data when it's used. Ideally the could be on the stack, but we can't DMA stack memory. With this change only the header and status memory are shared between commands, which will allow using a tighter lock than RTNL. Signed-off-by: Daniel Jurgens Reviewed-by: Jiri Pirko --- drivers/net/virtio_net.c | 111 ++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 36 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 7248dae54e1c..0ee192b45e1e 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -240,14 +240,6 @@ struct virtio_net_ctrl_rss { struct control_buf { struct virtio_net_ctrl_hdr hdr; virtio_net_ctrl_ack status; - struct virtio_net_ctrl_mq mq; - u8 promisc; - u8 allmulti; - __virtio16 vid; - __virtio64 offloads; - struct virtio_net_ctrl_coal_tx coal_tx; - struct virtio_net_ctrl_coal_rx coal_rx; - struct virtio_net_ctrl_coal_vq coal_vq; }; struct virtnet_info { @@ -2672,14 +2664,19 @@ static void virtnet_ack_link_announce(struct virtnet_info *vi) static int _virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) { + struct virtio_net_ctrl_mq *mq __free(kfree) = NULL; struct scatterlist sg; struct net_device *dev = vi->dev; if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ)) return 0; - vi->ctrl->mq.virtqueue_pairs = cpu_to_virtio16(vi->vdev, queue_pairs); - sg_init_one(&sg, &vi->ctrl->mq, sizeof(vi->ctrl->mq)); + mq = kzalloc(sizeof(*mq), GFP_KERNEL); + if (!mq) + return -ENOMEM; + + mq->virtqueue_pairs = cpu_to_virtio16(vi->vdev, queue_pairs); + sg_init_one(&sg, mq, sizeof(*mq)); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ, VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET, &sg)) { @@ -2708,6 +2705,7 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) static int virtnet_close(struct net_device *dev) { + u8 *promisc_allmulti __free(kfree) = NULL; struct virtnet_info *vi = netdev_priv(dev); int i; @@ -2732,6 +2730,7 @@ static void virtnet_rx_mode_work(struct work_struct *work) struct scatterlist sg[2]; struct virtio_net_ctrl_mac *mac_data; struct netdev_hw_addr *ha; + u8 *promisc_allmulti; int uc_count; int mc_count; void *buf; @@ -2743,22 +2742,27 @@ static void virtnet_rx_mode_work(struct work_struct *work) rtnl_lock(); - vi->ctrl->promisc = ((dev->flags & IFF_PROMISC) != 0); - vi->ctrl->allmulti = ((dev->flags & IFF_ALLMULTI) != 0); + promisc_allmulti = kzalloc(sizeof(*promisc_allmulti), GFP_ATOMIC); + if (!promisc_allmulti) { + dev_warn(&dev->dev, "Failed to set RX mode, no memory.\n"); + return; + } - sg_init_one(sg, &vi->ctrl->promisc, sizeof(vi->ctrl->promisc)); + *promisc_allmulti = !!(dev->flags & IFF_PROMISC); + sg_init_one(sg, promisc_allmulti, sizeof(*promisc_allmulti)); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX, VIRTIO_NET_CTRL_RX_PROMISC, sg)) dev_warn(&dev->dev, "Failed to %sable promisc mode.\n", - vi->ctrl->promisc ? "en" : "dis"); + *promisc_allmulti ? "en" : "dis"); - sg_init_one(sg, &vi->ctrl->allmulti, sizeof(vi->ctrl->allmulti)); + *promisc_allmulti = !!(dev->flags & IFF_ALLMULTI); + sg_init_one(sg, promisc_allmulti, sizeof(*promisc_allmulti)); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX, VIRTIO_NET_CTRL_RX_ALLMULTI, sg)) dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n", - vi->ctrl->allmulti ? "en" : "dis"); + *promisc_allmulti ? "en" : "dis"); netif_addr_lock_bh(dev); @@ -2819,10 +2823,15 @@ static int virtnet_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid) { struct virtnet_info *vi = netdev_priv(dev); + __virtio16 *_vid __free(kfree) = NULL; struct scatterlist sg; - vi->ctrl->vid = cpu_to_virtio16(vi->vdev, vid); - sg_init_one(&sg, &vi->ctrl->vid, sizeof(vi->ctrl->vid)); + _vid = kzalloc(sizeof(*_vid), GFP_KERNEL); + if (!_vid) + return -ENOMEM; + + *_vid = cpu_to_virtio16(vi->vdev, vid); + sg_init_one(&sg, _vid, sizeof(*_vid)); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN, VIRTIO_NET_CTRL_VLAN_ADD, &sg)) @@ -2834,10 +2843,15 @@ static int virtnet_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid) { struct virtnet_info *vi = netdev_priv(dev); + __virtio16 *_vid __free(kfree) = NULL; struct scatterlist sg; - vi->ctrl->vid = cpu_to_virtio16(vi->vdev, vid); - sg_init_one(&sg, &vi->ctrl->vid, sizeof(vi->ctrl->vid)); + _vid = kzalloc(sizeof(*_vid), GFP_KERNEL); + if (!_vid) + return -ENOMEM; + + *_vid = cpu_to_virtio16(vi->vdev, vid); + sg_init_one(&sg, _vid, sizeof(*_vid)); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN, VIRTIO_NET_CTRL_VLAN_DEL, &sg)) @@ -2950,12 +2964,17 @@ static void virtnet_cpu_notif_remove(struct virtnet_info *vi) static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi, u16 vqn, u32 max_usecs, u32 max_packets) { + struct virtio_net_ctrl_coal_vq *coal_vq __free(kfree) = NULL; struct scatterlist sgs; - vi->ctrl->coal_vq.vqn = cpu_to_le16(vqn); - vi->ctrl->coal_vq.coal.max_usecs = cpu_to_le32(max_usecs); - vi->ctrl->coal_vq.coal.max_packets = cpu_to_le32(max_packets); - sg_init_one(&sgs, &vi->ctrl->coal_vq, sizeof(vi->ctrl->coal_vq)); + coal_vq = kzalloc(sizeof(*coal_vq), GFP_KERNEL); + if (!coal_vq) + return -ENOMEM; + + coal_vq->vqn = cpu_to_le16(vqn); + coal_vq->coal.max_usecs = cpu_to_le32(max_usecs); + coal_vq->coal.max_packets = cpu_to_le32(max_packets); + sg_init_one(&sgs, coal_vq, sizeof(*coal_vq)); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET, @@ -3101,11 +3120,15 @@ static bool virtnet_commit_rss_command(struct virtnet_info *vi) if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ, vi->has_rss ? VIRTIO_NET_CTRL_MQ_RSS_CONFIG - : VIRTIO_NET_CTRL_MQ_HASH_CONFIG, sgs)) { - dev_warn(&dev->dev, "VIRTIONET issue with committing RSS sgs\n"); - return false; - } + : VIRTIO_NET_CTRL_MQ_HASH_CONFIG, sgs)) + goto err; + return true; + +err: + dev_warn(&dev->dev, "VIRTIONET issue with committing RSS sgs\n"); + return false; + } static void virtnet_init_default_rss(struct virtnet_info *vi) @@ -3410,12 +3433,17 @@ static int virtnet_get_link_ksettings(struct net_device *dev, static int virtnet_send_tx_notf_coal_cmds(struct virtnet_info *vi, struct ethtool_coalesce *ec) { + struct virtio_net_ctrl_coal_tx *coal_tx __free(kfree) = NULL; struct scatterlist sgs_tx; int i; - vi->ctrl->coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs); - vi->ctrl->coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames); - sg_init_one(&sgs_tx, &vi->ctrl->coal_tx, sizeof(vi->ctrl->coal_tx)); + coal_tx = kzalloc(sizeof(*coal_tx), GFP_KERNEL); + if (!coal_tx) + return -ENOMEM; + + coal_tx->tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs); + coal_tx->tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames); + sg_init_one(&sgs_tx, coal_tx, sizeof(*coal_tx)); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, VIRTIO_NET_CTRL_NOTF_COAL_TX_SET, @@ -3435,6 +3463,7 @@ static int virtnet_send_tx_notf_coal_cmds(struct virtnet_info *vi, static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi, struct ethtool_coalesce *ec) { + struct virtio_net_ctrl_coal_rx *coal_rx __free(kfree) = NULL; bool rx_ctrl_dim_on = !!ec->use_adaptive_rx_coalesce; struct scatterlist sgs_rx; int i; @@ -3453,6 +3482,10 @@ static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi, return 0; } + coal_rx = kzalloc(sizeof(*coal_rx), GFP_KERNEL); + if (!coal_rx) + return -ENOMEM; + if (!rx_ctrl_dim_on && vi->rx_dim_enabled) { vi->rx_dim_enabled = false; for (i = 0; i < vi->max_queue_pairs; i++) @@ -3463,9 +3496,9 @@ static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi, * we need apply the global new params even if they * are not updated. */ - vi->ctrl->coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs); - vi->ctrl->coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames); - sg_init_one(&sgs_rx, &vi->ctrl->coal_rx, sizeof(vi->ctrl->coal_rx)); + coal_rx->rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs); + coal_rx->rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames); + sg_init_one(&sgs_rx, coal_rx, sizeof(*coal_rx)); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, VIRTIO_NET_CTRL_NOTF_COAL_RX_SET, @@ -3951,10 +3984,16 @@ static int virtnet_restore_up(struct virtio_device *vdev) static int virtnet_set_guest_offloads(struct virtnet_info *vi, u64 offloads) { + __virtio64 *_offloads __free(kfree) = NULL; struct scatterlist sg; - vi->ctrl->offloads = cpu_to_virtio64(vi->vdev, offloads); - sg_init_one(&sg, &vi->ctrl->offloads, sizeof(vi->ctrl->offloads)); + _offloads = kzalloc(sizeof(*_offloads), GFP_KERNEL); + if (!_offloads) + return -ENOMEM; + + *_offloads = cpu_to_virtio64(vi->vdev, offloads); + + sg_init_one(&sg, _offloads, sizeof(*_offloads)); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_GUEST_OFFLOADS, VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET, &sg)) { From patchwork Tue Apr 16 19:30:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Jurgens X-Patchwork-Id: 13632442 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2059.outbound.protection.outlook.com [40.107.93.59]) (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 713111384AD for ; Tue, 16 Apr 2024 19:31:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295886; cv=fail; b=UWryY8XQ8TGVb/dXvNxQE21Zt6tnUh6lBvTRyfrPg9vZZ9mM8Mn0ekDR8BiYF3h6i77t+HolKpRmBt817DFdcrUj9Sa+Zts7RMjlk2Z/XcQv6Z+coSrhizpW/DUqMB0mYDjtY+KXPBcRPLMj9vZnS1prO96xBQEibw9rYiz9awY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295886; c=relaxed/simple; bh=91KjVSUx6x2TymBpbaCxfcryxEjo9MfcJ39qfDsuBKA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BTl6RF2ccwaSvKByaD7sKiQzp/Gp5Y/gqCWT4GQHcOuvpcaU0+M4lz+s6yolN55lVXo5mE1Raak+jcRXowlRTHLBNil4ZsUWsaDKk+ywAsj3BWwLRgDECJJlS1+TN2hwQUzU+gKP6/D9QMuHzSGjz1oyQzp1XjLC/3milnAmZ24= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=iHoOlRBC; arc=fail smtp.client-ip=40.107.93.59 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="iHoOlRBC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LJ/aPv6WvgKUEH3AP4XzaDPaE0+gTazt5B//zU3rsab/Wc14DUgv4+k9mbgRPjUwhyfxdza7Rce1FXk5eCd6x3+gK7bfjbAC+cQKka67KYCqFVO9z7N5A98/+w+gZoqJoVScwXbwMgl997mbqz1qqXb8g8+Pzbn1l2gv8pplXJqiK4iuproQRed07TXGi/BgJaQR5RaYWGqQCBy7/9OlnALOqnWb4Xpr4qRZR7GRJzC228PMEI4vrnjHyrVdqkPNEK3O2AUjaetCRA5c3zKlExsSwpVRCDdQuIPrlWKBffHjY0AmwQixq8pvpm1LMvEHGo15AgX3Pwu7z0JKBIUaxw== 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=3eF2iGZDKA454GaqRNoUz9a3f6MF3kfnlHvM2eef8wA=; b=RrU5WrQTv1tzJtC2edcwkN5Tw0JUFnNAbCb1f5UOZZnZnu6oYAgvdp4OHYesqK9uOP7uaEB/FbQM3Ebq4H/yT6bUx17mf0QPBUrYGOzwSvQbgFp1V5nApMVxM/jdB4nN9WtxWIfYQPuSyncO0LK2n/6zw40QEJ1+DZrvHP5SmEQ6GLv8I0iusBkpVCt4ZmXuw+mJAbtRX53/y0KMmWI+7hetvfhc/jNw9YUNOrFYICfBi5nxPm75N+AiPbMV9zt4XwQGW3wx3dxGIHKFMzb1+AK8aqLI6PsYJvQk+8H3CCxMPBhWM1Zo9bgz3707Fyvj2zbe5vTJQTgiGA9Ug1AQBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=vger.kernel.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 (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=3eF2iGZDKA454GaqRNoUz9a3f6MF3kfnlHvM2eef8wA=; b=iHoOlRBCY0ILGEmM6jm4O2cQqCF2uIEsRQAqVrqrSiah4hEuG7Y69gzvSUoe67Q8v2dvTaLuimJw3dOrkuFfD2r6ziHHDo11fprc0pYkwzzXaNwaag4Q1yQRHpcPxLmF3I5ahb7Ez7iB4GHPL2N3+hNwo/0ktOcHSCyAStQiBzciOLdidP6CiCxv4cqUGTslUT+2lYluBIEkDnm0Mx4ghzKOeLsTRzGaSLZ1G/nCdvEowIeTtJJ1sSyqwCEwSC36RQShoSQ4PFkMGuNgMkqR7KMc2ml1KIQCzY8uLmZsovq+NqEWHW1OjASOXPvGox6xNqQzsXEo/N9ItZytGvi5qw== Received: from BL1P222CA0021.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::26) by DM4PR12MB5820.namprd12.prod.outlook.com (2603:10b6:8:64::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Tue, 16 Apr 2024 19:31:22 +0000 Received: from BL6PEPF0001AB78.namprd02.prod.outlook.com (2603:10b6:208:2c7:cafe::83) by BL1P222CA0021.outlook.office365.com (2603:10b6:208:2c7::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.20 via Frontend Transport; Tue, 16 Apr 2024 19:31:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BL6PEPF0001AB78.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Tue, 16 Apr 2024 19:31:22 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:51 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:50 -0700 Received: from vdi.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 16 Apr 2024 12:30:49 -0700 From: Daniel Jurgens To: CC: , , , , , , , , , Daniel Jurgens Subject: [PATCH net-next v4 3/6] virtio_net: Add a lock for the command VQ. Date: Tue, 16 Apr 2024 22:30:36 +0300 Message-ID: <20240416193039.272997-4-danielj@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240416193039.272997-1-danielj@nvidia.com> References: <20240416193039.272997-1-danielj@nvidia.com> Precedence: bulk X-Mailing-List: netdev@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: BL6PEPF0001AB78:EE_|DM4PR12MB5820:EE_ X-MS-Office365-Filtering-Correlation-Id: ffd67a66-778d-4031-2ef4-08dc5e4bcc87 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a1VxGcIvc1k9UxwvBOdjtzQaBbnkHXDDEzXgiE7Hx2xqAky7+Y7OH7mcQaiBd34QBfaDdJai2mxhGW+Po8xaC3IcbpNfH0ALC1MQpEyQRDIA6OXveXKU9mlh6BWRTUuOESXiTcRGdhSTLr1UKxalaR0KY/ZoqKQjNuJGtxT7aBGaL+csyaz0fxNOFFR4EE77j8nitg8t9uWND3wqAv2RlgxsoH4nlb69yxX0zZWePkL+XVl3tF9R5QFaRQIcE6sIX4hrxMBT3wVa+s/Z4HjPJdL4qQUUYrbMBZlBYElqdPjRncccPBkMPYAH1QDD9HnFdxxvzv6AQxfVdH36IYn673mvaV697K4M+cbbQLaVAfozm101+WapRBWgrd2JUbRTQF15wOIsYrAbRAP+2UlC0NxerGsMiBwtebOpwtuMB1vs7YQTbsd+HYMKm4j+frf6ZQU9xJqmEsUvhgSjeHIBc5Hr6GS6w5uPx0eqONp5UmnEOKY703pPz34oOBifJM6I8Mu6w9qPwE2+cZMeXfWTKVXZmAjnzfcmF1YorqfX/YXo1BGPwfdjJ5argYoCjYT3IZIsuSiYVc9AMhh+yJsCPA64xgA8B7uGos6bneQw+VxOFlxjSmC/Vt6FNjDyG/z+1sNaGoNEA8k9kSNZd/9cMDG8V2VMSYV35rgfh2B8EbYjZ6V16vJXpqdNl38ncxH0BKN/4nweBK5x/vnzDcM5KEWysyIx8NZfv97abdczYLADNypQobP/Wgj8ATkW21sD X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230031)(376005)(82310400014)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2024 19:31:22.4706 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ffd67a66-778d-4031-2ef4-08dc5e4bcc87 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB78.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5820 X-Patchwork-Delegate: kuba@kernel.org The command VQ will no longer be protected by the RTNL lock. Use a spinlock to protect the control buffer header and the VQ. Signed-off-by: Daniel Jurgens Reviewed-by: Jiri Pirko --- drivers/net/virtio_net.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 0ee192b45e1e..d02f83a919a7 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -282,6 +282,7 @@ struct virtnet_info { /* Has control virtqueue */ bool has_cvq; + spinlock_t cvq_lock; /* Host can handle any s/g split between our header and packet data */ bool any_header_sg; @@ -2529,6 +2530,7 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd, /* Caller should know better */ BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)); + guard(spinlock)(&vi->cvq_lock); vi->ctrl->status = ~0; vi->ctrl->hdr.class = class; vi->ctrl->hdr.cmd = cmd; @@ -4818,8 +4820,10 @@ static int virtnet_probe(struct virtio_device *vdev) virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) vi->any_header_sg = true; - if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) + if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) { vi->has_cvq = true; + spin_lock_init(&vi->cvq_lock); + } if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) { mtu = virtio_cread16(vdev, From patchwork Tue Apr 16 19:30:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Jurgens X-Patchwork-Id: 13632443 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2088.outbound.protection.outlook.com [40.107.244.88]) (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 4E4D71384AB for ; Tue, 16 Apr 2024 19:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295889; cv=fail; b=hdLXarEdk6dOSp/OcFkKoiPVX6ytz92ob5KiJu/4hrObAhGxZO2wC4NKhlkNLPeEdpgiogdJE98gATav9bPJ/mAwhwu8GjO3TBqPOyjEUo10PUyqqkVpYQC1qKOxGqFfHTmPB8whz9x1B1fTytYGit9zOHkAPjocgugV03021fY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295889; c=relaxed/simple; bh=Ed+1DP3Dbmc+jR6YuNRT6vp48eezl4GxMp90b8lFe0A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TP7/07FUVGjpQZswsZMSh+/q6EZAwUtEUFJ43gS1euKaVra08wpjeUYWg0Nf/IkHSoYkAl7SVZBaLy9P7IfTSEncH89eQ6tKPB/tCk76EqvGS7cjD8TJEMQwCgAmArB/G1902eB2rIKlHtxbx4ysxiOr9ZVxXOoLDiysRbeNMos= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=NsLARWL+; arc=fail smtp.client-ip=40.107.244.88 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="NsLARWL+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U3Dc4LxoL5gnatoKePAgfegHSeforC9UEhomMxr1kYSb919uuB4RetXPjG6RVPJlDLPu0ZsvoJwxVo1YmaY7CPKaBFNnnbUyYK0qD3lNtQWUhlsmBnQ2Mo4TiZihBwILep30ZmBjrrOUGAMd4stiMCsw7UiWVkxnEdQqXCbltQwRGkyt9Uv0tub5BXOl2CuaVxpRkSyKqn1yLWjKduOdEt4V8z+0l8YBs+6WqtMX7/yRxVdUY+z/sgUKIxvvxyLGDZaMzXd0sgDtWdbO+hU3/ki/WJwAV0SRL6aJSJS66BjfL21q4K2tkDvbKI9tAbwQ052CGKCIMZyYLty0CFVo9g== 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=hzZdQFt0EvVPrkyvl4F8hyflN3RXAGqj8oyCegikMM0=; b=jnVlxZmOitiq8O/WJWbPR3MJ8gy0GnqeF8kVf+luHxvUbNTePg1/5uNbfoI+tFM9Hzpve/hAlSdABwMeTZVGxQMsdq+K4HcOjBqlwK1mNDUb1LnH+XXLsGVwUrQNoZefxSuDUSBeT3Uq8x9tK6+DECbB829eHOGHjKzYsxRADpCZ9gUgod07mBz0pc3UcIjTP06p74le9FKdcueigKb+rubJglXJT9E8ZTda26nr4Rmjwh7P2ixr9aQjntgdGxq0YQb56grYD7Xk8QYPx4dYTc0Aff1ztoyqpL+6PwcbzqAnyXdDIzAjXY9M1lrieN3H4kNzSBeECrdoVZAsnDhEwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=vger.kernel.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 (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=hzZdQFt0EvVPrkyvl4F8hyflN3RXAGqj8oyCegikMM0=; b=NsLARWL+8hlihNLROkzqKSIz4UuXt9FGfg2LBxcb3kgha/NQ6oQoRaaljxPYgU0DoxmgIWycVmFJIJPbVe+usTvgi/3d+zwYSwXkk8vblOLmzcw+tVa0g9Lmyltl5glsHQIPmVRZGwm0oZu8bakmRwcJF7aD+5kMNCOTzI3cNjiHAcLBHGtugzVwak0ETy0xpdRGv6VwEE+IrsiqW06oQ7lCe+MeCqpbqrU8rUneiovUqqMF6FfRWvr2LUb31DtiDSok29N5fed4zXSDSrj7D7Se9iPZwNLyXk4mdycK/Lq//kmsQWJ4S7JpixhN5WciSJzOTHqrg9i7RB9RhNwo5A== Received: from BL1P222CA0005.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::10) by CY8PR12MB7514.namprd12.prod.outlook.com (2603:10b6:930:92::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Tue, 16 Apr 2024 19:31:24 +0000 Received: from BL6PEPF0001AB78.namprd02.prod.outlook.com (2603:10b6:208:2c7:cafe::a4) by BL1P222CA0005.outlook.office365.com (2603:10b6:208:2c7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.34 via Frontend Transport; Tue, 16 Apr 2024 19:31:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BL6PEPF0001AB78.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Tue, 16 Apr 2024 19:31:23 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:51 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:51 -0700 Received: from vdi.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 16 Apr 2024 12:30:50 -0700 From: Daniel Jurgens To: CC: , , , , , , , , , Daniel Jurgens Subject: [PATCH net-next v4 4/6] virtio_net: Do DIM update for specified queue only Date: Tue, 16 Apr 2024 22:30:37 +0300 Message-ID: <20240416193039.272997-5-danielj@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240416193039.272997-1-danielj@nvidia.com> References: <20240416193039.272997-1-danielj@nvidia.com> Precedence: bulk X-Mailing-List: netdev@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: BL6PEPF0001AB78:EE_|CY8PR12MB7514:EE_ X-MS-Office365-Filtering-Correlation-Id: 003a0626-581e-4031-3c07-08dc5e4bcd35 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UW9pVkBxtOa5CSsW+bJsJVtKIxTxlaF5KGwgx5WC0hxDarN1pIpIPnAkoorLaOifATJAuPtX50WTvD/dd2h1x2jtzs3In6YXSv+84n+HQqgdqsF8q0p2yK1Vy28VXuUF35OqDXBUZ1N6VOecu9aX+S2WPDz9iGUYoJ0tLuTHgv8CxvlFJV94RlrwEGgpXQb/lNNFXBybtZjI1mLCJJn5bIeky/AHicQF333QCNEdNz5bHRW3Y1Of7dhgx8a50c8ZX/KsMJImVxnD6tZz9HScyzmRiZ6p90OXj1Qr33ZVA9tkfqq2gLg2ufvVH9N9PO5BJXRdM12U0zqEsnk2mZRJRSOp4LmOlk080yOAsKj17qPfQPaCKQkLxeZ6p/i/WSPzNBUT442KhXWrjFxDoCHDNeKB3rGNzONHyUNYJz99w+xpuMhe4jLN05jDFsgkTvt/FxcZO3A+mWB7butsTbvPnPM84HYG/aw8xzpqmaO8XiVgxdqs0MnYPAPX7Gct+cU/q02vJqZ0GotOLnfhaHqg/e7yAqiWp2I9UoRk61U7equ7T0BZJMlLxIpsWSP6s78ISAa8ARs02DyHDwvMW7bkpf1EeKVYLh919Q4BlqPc4qHH6ragqnty8LWh4V8NOxf7q3IN09ifn0EvWU/m87S1Up3WDbs9Gt8RNcZTDTtk3LyqyK9waHAo8fgbfnuxnTuEIejcdOzgKB/F85SjCSppaHBX7Yt3NlDfiE6XlcrdOEqIL8l2cH8vLvSJ2E+tKXO1 X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230031)(82310400014)(36860700004)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2024 19:31:23.6112 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 003a0626-581e-4031-3c07-08dc5e4bcd35 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB78.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7514 X-Patchwork-Delegate: kuba@kernel.org Since we no longer have to hold the RTNL lock here just do updates for the specified queue. Signed-off-by: Daniel Jurgens --- drivers/net/virtio_net.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index d02f83a919a7..b3aa4d2a15e9 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3596,38 +3596,28 @@ static void virtnet_rx_dim_work(struct work_struct *work) struct virtnet_info *vi = rq->vq->vdev->priv; struct net_device *dev = vi->dev; struct dim_cq_moder update_moder; - int i, qnum, err; + int qnum, err; if (!rtnl_trylock()) return; - /* Each rxq's work is queued by "net_dim()->schedule_work()" - * in response to NAPI traffic changes. Note that dim->profile_ix - * for each rxq is updated prior to the queuing action. - * So we only need to traverse and update profiles for all rxqs - * in the work which is holding rtnl_lock. - */ - for (i = 0; i < vi->curr_queue_pairs; i++) { - rq = &vi->rq[i]; - dim = &rq->dim; - qnum = rq - vi->rq; + qnum = rq - vi->rq; - if (!rq->dim_enabled) - continue; + if (!rq->dim_enabled) + goto out; - update_moder = net_dim_get_rx_moderation(dim->mode, dim->profile_ix); - if (update_moder.usec != rq->intr_coal.max_usecs || - update_moder.pkts != rq->intr_coal.max_packets) { - err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, qnum, - update_moder.usec, - update_moder.pkts); - if (err) - pr_debug("%s: Failed to send dim parameters on rxq%d\n", - dev->name, qnum); - dim->state = DIM_START_MEASURE; - } + update_moder = net_dim_get_rx_moderation(dim->mode, dim->profile_ix); + if (update_moder.usec != rq->intr_coal.max_usecs || + update_moder.pkts != rq->intr_coal.max_packets) { + err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, qnum, + update_moder.usec, + update_moder.pkts); + if (err) + pr_debug("%s: Failed to send dim parameters on rxq%d\n", + dev->name, qnum); + dim->state = DIM_START_MEASURE; } - +out: rtnl_unlock(); } From patchwork Tue Apr 16 19:30:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Jurgens X-Patchwork-Id: 13632440 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2040.outbound.protection.outlook.com [40.107.212.40]) (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 B4D7F13848B for ; Tue, 16 Apr 2024 19:31:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295881; cv=fail; b=ZHMHtXC/poCkpM7koz8FdVamw8Tg6ftIMAbGiWcIQ7lqYLbPFJOKcPCVxQslmtORGIgJkL0s+8BqSV6mbYC8B3Sm0OefmAGUvXSNX7W0ORj12BCNhsnvfNW5t3etgmsaMvOhVYVDXOrSFqyF+1E3GE7sQX9TSuovaTC5xsZgGV8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295881; c=relaxed/simple; bh=ahrnC6BtAqYDjO5AVNBAu4usZHfZ88DdN9Iojsa96Uk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PglnKVoaJ6FtS3pMmx9DqxJ/BsiOKANiIOrAJHaBWNUHUspEx90o5nkD4EDrAnCfHACbc5onkWoM504cTR5UbbVHx6ZeXFR9xyfo6Cyg3yj6ulPlG0R5w3r1QNP02343Y7FFn2E0yo/fseImFXohUHgIDMi6mVVdZ+WtmuQyHF0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=uroo+MCY; arc=fail smtp.client-ip=40.107.212.40 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="uroo+MCY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YWOAYpR0F0hgm3X8upyKHLkTlzRsxTD4vJ+3huU8CSDIFwhnLFkwF19MxLfLKbDsmSL3iYq0JBeZssUMTkd++fZYe/6cEh/wdVmKxXYjRVzI2wNdKsh9uSlsRyMz1Dcnomo5xRYF9srr/pgGfMN2CsuYQXBYfVftm0YkN+WqmsGmNtPj7u3fZUFvpj6gLF3MjgbccmX6j98cMcisVyss3R/7jBrYkRjjZ6pOxV0F//RUGJus+9Rq7APXHOO8vEI3KItIDjHK1gtQU+l87k8eYixynK+CW2/08sOz/BRZzwyB0M+E+LG3Xwgk9Xxpz56lDc2okrqvRo+5sHJ6zAFGxg== 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=Svd8UF4adwvxWLuQBucrz9T5Hl3DZM6wHCJrHrp7axI=; b=Thqa8j/lrCS+wNi33lHk58qa5DDto+lFBaulHSzyDDVgJ+KXGfCFgwq30z+J5WYS7POxOqAK+hg3E+rUvugRz8oMX8oUlEJJ4rH3yJOY1kHGcXhyiHw41dsUGZF64do29IKypu8DFl1aVN0nMJtREly+DqqskJOPyIvVK5cSEWGZlrsDPOBVQAMW8UVzmGgqw6gzQ1/79XrKwZpDzMvoHhcL38/TvEpgxzWIiNNlwRrWcn6PYvdBmNtlziaztGZAWauR1BaKdJvzpiX8Y0qcpS9sOEfCAiYYmb0KP7Q4Bv0a7cdm0vqQojmt7hR9soNFD6zs51FY5gm07UoB3iWOUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=vger.kernel.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 (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=Svd8UF4adwvxWLuQBucrz9T5Hl3DZM6wHCJrHrp7axI=; b=uroo+MCYvWk2Hq/9P5vaww8RTQUa+6guxr9JshqlgRXZJCYKJWwg1Gt5GSM+/7otJDTu6zCV0rUF/H7+TD9xcwzUrMOaLDyiq+m3Rh/wPLeAiMfQzsw6xhFD4IrGvk/B8h4b/H7NF3Rplzs4RIuufI0hQ4AvGXwTyh+VX5r6N+S+A4++uWIbmMVGNGsu342Safe8wow+xaK/uP/dvrqsnbBpDhk/PW3v9wz60bSBU/A6S9bg0U5qfOat3o8DP3SjxIJ5TdvYmQDDPZykiT2ZlHYAyLipft9kusSymmYjB0PVjL1GKXLISMKmYXMg0XuKHuCOiA44Z7B8XKZkGVH7ng== Received: from BL0PR1501CA0035.namprd15.prod.outlook.com (2603:10b6:207:17::48) by MN0PR12MB5977.namprd12.prod.outlook.com (2603:10b6:208:37c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Tue, 16 Apr 2024 19:31:16 +0000 Received: from BL02EPF0001A103.namprd05.prod.outlook.com (2603:10b6:207:17:cafe::58) by BL0PR1501CA0035.outlook.office365.com (2603:10b6:207:17::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.33 via Frontend Transport; Tue, 16 Apr 2024 19:31:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BL02EPF0001A103.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Tue, 16 Apr 2024 19:31:15 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:53 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:52 -0700 Received: from vdi.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 16 Apr 2024 12:30:51 -0700 From: Daniel Jurgens To: CC: , , , , , , , , , Daniel Jurgens Subject: [PATCH net-next v4 5/6] virtio_net: Add a lock for per queue RX coalesce Date: Tue, 16 Apr 2024 22:30:38 +0300 Message-ID: <20240416193039.272997-6-danielj@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240416193039.272997-1-danielj@nvidia.com> References: <20240416193039.272997-1-danielj@nvidia.com> Precedence: bulk X-Mailing-List: netdev@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: BL02EPF0001A103:EE_|MN0PR12MB5977:EE_ X-MS-Office365-Filtering-Correlation-Id: f7fc605c-376b-4fc6-2be3-08dc5e4bc897 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 88t+Xwd9YLTlimVGRQDchR/oOIgaqSyqOMePzVPUKb58BYOryxo6DBLyBNA8T2NQ1wIKwdoHAkoMxoQDmzJbhWnDNdfokecFKABqx19i25Ksizd6wz3ThDIzcyi2abPhY/yfLUJWTMBz0CnQvpYnvggj7tJrRrN1DajEANiZecFeWsZHGPkcW+zJhXR4NWKDDFC4iiG7tVazbiMMkQhMZNZvwB+U4Cv/kB7M1GRaYksWt+NQ+qlWecgqvEwWo+uo0cw6rvP2HjhLFkyUvY9I1/YFVVY0Y2cADFgRZt71fc2VK4dA5H3/Y/I6/uvfx9RoR1qtmnIU2dG9WazoW0l7gWfuSy/zchmc6BOLj3aBlo8LdBHmEnVCBUQj23XubKR7AR8eto7ASdTICKeyhSCmbUeh+w5hRbG2tPr55hwYqpddwmUpsIaSW6BKmkGx9j89wmd7AK4WlNL/JcK64bSgltP7t/2dn0R4tHr3kGUkECj5DlzflsYYJvpHxYLJtIAHPuARAuRBX6jSb05NDvbw6DbWEXqj+7lDCSxcbyw/ON+lUZu6me5PnyNIRTreemDa+qW+luFw5gECLlPnoPnr4vBZIFmI/Tplt9s03/y+PSueS2580wgvOgkXg06l0KsgTZiNAG4Hd/xR15hZScIyNcjToKBAvLIZhVI8bdvPC0rtAlmJFWTtM6+S7C6qJDpJo9VSb/zglzDfLv3uNhs3p4HF0/5GfIdgjGrY1lwkzRBOWlIhKRBew17I1KhGvpwA X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(36860700004)(1800799015)(376005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2024 19:31:15.8645 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f7fc605c-376b-4fc6-2be3-08dc5e4bc897 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A103.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5977 X-Patchwork-Delegate: kuba@kernel.org Once the RTNL locking around the control buffer is removed there can be contention on the per queue RX interrupt coalescing data. Use a spin lock per queue. Signed-off-by: Daniel Jurgens --- drivers/net/virtio_net.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index b3aa4d2a15e9..bae5beafe1a1 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -184,6 +184,9 @@ struct receive_queue { /* Is dynamic interrupt moderation enabled? */ bool dim_enabled; + /* Used to protect dim_enabled and inter_coal */ + spinlock_t dim_lock; + /* Dynamic Interrupt Moderation */ struct dim dim; @@ -2218,6 +2221,10 @@ static int virtnet_poll(struct napi_struct *napi, int budget) /* Out of packets? */ if (received < budget) { napi_complete = virtqueue_napi_complete(napi, rq->vq, received); + /* Intentionally not taking dim_lock here. This could result + * in a net_dim call with dim now disabled. But virtnet_rx_dim_work + * will take the lock not update settings if dim is now disabled. + */ if (napi_complete && rq->dim_enabled) virtnet_rx_dim_update(vi, rq); } @@ -3087,9 +3094,11 @@ static int virtnet_set_ringparam(struct net_device *dev, return err; /* The reason is same as the transmit virtqueue reset */ + spin_lock(&vi->rq[i].dim_lock); err = virtnet_send_rx_ctrl_coal_vq_cmd(vi, i, vi->intr_coal_rx.max_usecs, vi->intr_coal_rx.max_packets); + spin_unlock(&vi->rq[i].dim_lock); if (err) return err; } @@ -3468,6 +3477,7 @@ static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi, struct virtio_net_ctrl_coal_rx *coal_rx __free(kfree) = NULL; bool rx_ctrl_dim_on = !!ec->use_adaptive_rx_coalesce; struct scatterlist sgs_rx; + int ret = 0; int i; if (rx_ctrl_dim_on && !virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) @@ -3477,16 +3487,22 @@ static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi, ec->rx_max_coalesced_frames != vi->intr_coal_rx.max_packets)) return -EINVAL; + /* Acquire all queues dim_locks */ + for (i = 0; i < vi->max_queue_pairs; i++) + spin_lock(&vi->rq[i].dim_lock); + if (rx_ctrl_dim_on && !vi->rx_dim_enabled) { vi->rx_dim_enabled = true; for (i = 0; i < vi->max_queue_pairs; i++) vi->rq[i].dim_enabled = true; - return 0; + goto unlock; } coal_rx = kzalloc(sizeof(*coal_rx), GFP_KERNEL); - if (!coal_rx) - return -ENOMEM; + if (!coal_rx) { + ret = -ENOMEM; + goto unlock; + } if (!rx_ctrl_dim_on && vi->rx_dim_enabled) { vi->rx_dim_enabled = false; @@ -3504,8 +3520,10 @@ static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi, if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, VIRTIO_NET_CTRL_NOTF_COAL_RX_SET, - &sgs_rx)) - return -EINVAL; + &sgs_rx)) { + ret = -EINVAL; + goto unlock; + } vi->intr_coal_rx.max_usecs = ec->rx_coalesce_usecs; vi->intr_coal_rx.max_packets = ec->rx_max_coalesced_frames; @@ -3513,8 +3531,11 @@ static int virtnet_send_rx_notf_coal_cmds(struct virtnet_info *vi, vi->rq[i].intr_coal.max_usecs = ec->rx_coalesce_usecs; vi->rq[i].intr_coal.max_packets = ec->rx_max_coalesced_frames; } +unlock: + for (i = vi->max_queue_pairs - 1; i >= 0; i--) + spin_unlock(&vi->rq[i].dim_lock); - return 0; + return ret; } static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi, @@ -3538,10 +3559,12 @@ static int virtnet_send_rx_notf_coal_vq_cmds(struct virtnet_info *vi, u16 queue) { bool rx_ctrl_dim_on = !!ec->use_adaptive_rx_coalesce; - bool cur_rx_dim = vi->rq[queue].dim_enabled; u32 max_usecs, max_packets; + bool cur_rx_dim; int err; + guard(spinlock)(&vi->rq[queue].dim_lock); + cur_rx_dim = vi->rq[queue].dim_enabled; max_usecs = vi->rq[queue].intr_coal.max_usecs; max_packets = vi->rq[queue].intr_coal.max_packets; @@ -3603,6 +3626,7 @@ static void virtnet_rx_dim_work(struct work_struct *work) qnum = rq - vi->rq; + guard(spinlock)(&rq->dim_lock); if (!rq->dim_enabled) goto out; @@ -3756,6 +3780,7 @@ static int virtnet_get_per_queue_coalesce(struct net_device *dev, return -EINVAL; if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) { + guard(spinlock)(&vi->rq[queue].dim_lock); ec->rx_coalesce_usecs = vi->rq[queue].intr_coal.max_usecs; ec->tx_coalesce_usecs = vi->sq[queue].intr_coal.max_usecs; ec->tx_max_coalesced_frames = vi->sq[queue].intr_coal.max_packets; @@ -4501,6 +4526,7 @@ static int virtnet_alloc_queues(struct virtnet_info *vi) u64_stats_init(&vi->rq[i].stats.syncp); u64_stats_init(&vi->sq[i].stats.syncp); + spin_lock_init(&vi->rq[i].dim_lock); } return 0; From patchwork Tue Apr 16 19:30:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Jurgens X-Patchwork-Id: 13632444 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2079.outbound.protection.outlook.com [40.107.101.79]) (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 D2BE11384BF for ; Tue, 16 Apr 2024 19:31:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295892; cv=fail; b=krrQkYVcfc6B4ezIUroaqWgPuEXPPqlzjztuYwc8JqswyULSVX1uMJs8CeecxLKxKy8nTnCdNgBEF6X1wKqdroghhqOk1seGztyZq1sVMO9Y1DD4cBgxw0w/saKLYR3mtTbap/TDsi4sYHYwqjWnm0A9Myp+GQi4x81cT4CtIc4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713295892; c=relaxed/simple; bh=TX7mPY/ogWWuH+bbw/OFtDzCp1gNVlI7ygZ1Q6nW1Zg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qPWPRvy9xBVzigpFqXP1vxWJAZXpH5yHMekkAXAIh0UE6my/6z0lMX5hDbNlLDJrABIlCkaybvnoFJvoA0mMHdYhm0TkROQGSUWN3hil6xIM8GZmh4bfKnxT9g+EYwHb6gYStJ37/V1hQhSv+9WXDkJK7FL4jPRq61hhvTYht5U= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=umYV7qdR; arc=fail smtp.client-ip=40.107.101.79 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="umYV7qdR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hfWMXsH5SfjwZIEFn/ytbSXBIplztAv9MtRp3MbNn9fVCao/K6oEsEmihVW2JGEcZjI0fm1bUONX6NwdmB8DYkbcj6kaXJpF/9G0ZnAwtFN9bY8SRJfrBKf15dLzq3KCdoKVeVDRZRMSaVSAtWtogaxCuhrZwa6MuWeIzuf3mkli0fgdZHADSm/n3b/7EI0QZVJiMiEffrtX2j6XWx5SK4ZuiWy5mWsT4Zg5OEHkF3FuSEtnCtTjsy3uZnUVV/MOX/DkSur8QgUdlBWwOaqNRD0VnG/q3wrb0o7q7QHn/1hncgYoKLpeMr5y9OMNuMjlCQjGfjtzbPZFcGFi+jZFdA== 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=HPy7j0u1Cl+rc0qtA3mC2mfzUeEXxidOChAAqfJU0tA=; b=EAVdpLpoJM9HmvhMTVKRz5djreANzTbE6oe1oFKa14RmfoGkX7IgsTnNUathguejWMGwjQZPYTDlNe3faqJO9v/IbRwJkMWPOw1UIOPDGhaTYco4ydedI9ftWq2IcnszOXDGAPOSPlDG+o8qVse9xIVilIrmKA1Nud5vQHNkr2+ae7HeCjHXabS78INskpzA/ty2dyAcWS3nUZONWofDF+i9KzuyStwyI7SEF+apofL3ioR0XJK0AtBShzD5vxHTIWkUOJHn6KlM3VeE/+W0zby51e+t6JFcBQ+OQp+LiEYQgCFxpUbdJaj6ZUj1Jp+s17s7nTSps309OCBF2PPVtQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=vger.kernel.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 (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=HPy7j0u1Cl+rc0qtA3mC2mfzUeEXxidOChAAqfJU0tA=; b=umYV7qdR2ewYAIb+wMPPf/ulW9261/w6q1D6Y/HxxyZbCSl33JvhYCbqj1x4YEv4/zfQ4Fo7zwvm1tUr0O11JTr216gEhBFc+0+ahqE7GK1mQvvJFjHlfdowVTay6PKYBvPA4RBA2RNHdGsXT//QTQ43kAePb34VYkuJ2i7q0KLscrA6Ndm6HrhLwi7vYWUQSMknQeFdLVnYAI3an6WlUvqfj3VGiul8IT3CLsG1w2isx3rok6LWMwfqtpumJy75tQpOjfV6HyiRwDT1RwThZYZWUPnj2Md0P9e5iDOzT9GrQPvVXylKSFXB09oPO0zUSbK9KwQpq48RGk2sGp0kYQ== Received: from BL1P222CA0012.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::17) by DS7PR12MB8084.namprd12.prod.outlook.com (2603:10b6:8:ef::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Tue, 16 Apr 2024 19:31:26 +0000 Received: from BL6PEPF0001AB78.namprd02.prod.outlook.com (2603:10b6:208:2c7:cafe::2) by BL1P222CA0012.outlook.office365.com (2603:10b6:208:2c7::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.20 via Frontend Transport; Tue, 16 Apr 2024 19:31:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BL6PEPF0001AB78.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Tue, 16 Apr 2024 19:31:25 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:54 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 16 Apr 2024 12:30:53 -0700 Received: from vdi.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 16 Apr 2024 12:30:53 -0700 From: Daniel Jurgens To: CC: , , , , , , , , , Daniel Jurgens Subject: [PATCH net-next v4 6/6] virtio_net: Remove rtnl lock protection of command buffers Date: Tue, 16 Apr 2024 22:30:39 +0300 Message-ID: <20240416193039.272997-7-danielj@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240416193039.272997-1-danielj@nvidia.com> References: <20240416193039.272997-1-danielj@nvidia.com> Precedence: bulk X-Mailing-List: netdev@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: BL6PEPF0001AB78:EE_|DS7PR12MB8084:EE_ X-MS-Office365-Filtering-Correlation-Id: 5efadc3b-0824-4416-f365-08dc5e4bce8e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hlrc++24fJC3L3p11pn0EGL0MftyqrhtBL1K4vOrdXAlug8G4X5BZdKmOu90FEz1ajXWo3CVIya5bO6CUM8FeVVTm4/ajZhhR5OT1/2BivGBuBD3Vgo95e6kvuWbxTZZQv9sZ990S/dQ4Faa9h31iyvMpLeUSi4h1uEmdfVw11/brQl3OvkOQcc6P0mDDSGWO1er/+E0gWhEeQ4cX47JMmhMMw4axTgKGjQD9v9faYy4vKXAIXb8HJG76fCjUm3KYKjA8CwgjHUysftQQLm+L1uZFKDI50M1rGHoqTH4eqRoaqiXy8hZCHYmDMS8Sg4Qz00RkoCpwIkRpJO3o8wwDmMlnQD0MG+CKMoin2EFZ/qCgnBbJK8mdChAXZY5XmQuz7I8yRguc9YHhLP4Pvj3L3P8llcgAK/TsAP47B7hQPqHUmRfgcc8wapz61ZFvgcLQRjRmib128Mzn22tHOWsSGzD5Ar31/2M56rcQbbxwaAmd3xlvLsfukU4X7cTF2RKHXwrij1BmcgR4F3/Hkvq60tRc+LVLpvMVaDz9wb856O0TYX5LK328I3494FTNy0txArON3R9bJ7CTjjQM6h8W53xDgLYko2tOyHgk3/EHVRuvdsXz+EoR/3IwQY+eC+bHxLOwZQjRbPMB2z3Qp0hQUrFsgmn6UkHAF2coC4U7q61j5vdeWntl32va5HbuVmqHXHwrw5uJEFViI8nlLTXM05rpKVCNQ7G18Tw9pz2xuimd2BRHOFgJMx2zifbH3jK X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230031)(36860700004)(376005)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2024 19:31:25.8925 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5efadc3b-0824-4416-f365-08dc5e4bce8e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB78.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8084 X-Patchwork-Delegate: kuba@kernel.org The rtnl lock is no longer needed to protect the control buffer and command VQ. Signed-off-by: Daniel Jurgens Reviewed-by: Jiri Pirko --- drivers/net/virtio_net.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index bae5beafe1a1..5825775af8f8 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2664,14 +2664,12 @@ static void virtnet_stats(struct net_device *dev, static void virtnet_ack_link_announce(struct virtnet_info *vi) { - rtnl_lock(); if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_ANNOUNCE, VIRTIO_NET_CTRL_ANNOUNCE_ACK, NULL)) dev_warn(&vi->dev->dev, "Failed to ack link announce.\n"); - rtnl_unlock(); } -static int _virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) +static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) { struct virtio_net_ctrl_mq *mq __free(kfree) = NULL; struct scatterlist sg; @@ -2702,16 +2700,6 @@ static int _virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) return 0; } -static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) -{ - int err; - - rtnl_lock(); - err = _virtnet_set_queues(vi, queue_pairs); - rtnl_unlock(); - return err; -} - static int virtnet_close(struct net_device *dev) { u8 *promisc_allmulti __free(kfree) = NULL; @@ -3317,7 +3305,7 @@ static int virtnet_set_channels(struct net_device *dev, return -EINVAL; cpus_read_lock(); - err = _virtnet_set_queues(vi, queue_pairs); + err = virtnet_set_queues(vi, queue_pairs); if (err) { cpus_read_unlock(); goto err; @@ -3621,14 +3609,11 @@ static void virtnet_rx_dim_work(struct work_struct *work) struct dim_cq_moder update_moder; int qnum, err; - if (!rtnl_trylock()) - return; - qnum = rq - vi->rq; guard(spinlock)(&rq->dim_lock); if (!rq->dim_enabled) - goto out; + return; update_moder = net_dim_get_rx_moderation(dim->mode, dim->profile_ix); if (update_moder.usec != rq->intr_coal.max_usecs || @@ -3641,8 +3626,6 @@ static void virtnet_rx_dim_work(struct work_struct *work) dev->name, qnum); dim->state = DIM_START_MEASURE; } -out: - rtnl_unlock(); } static int virtnet_coal_params_supported(struct ethtool_coalesce *ec) @@ -4110,7 +4093,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog, synchronize_net(); } - err = _virtnet_set_queues(vi, curr_qp + xdp_qp); + err = virtnet_set_queues(vi, curr_qp + xdp_qp); if (err) goto err; netif_set_real_num_rx_queues(dev, curr_qp + xdp_qp); @@ -4932,7 +4915,7 @@ static int virtnet_probe(struct virtio_device *vdev) virtio_device_ready(vdev); - _virtnet_set_queues(vi, vi->curr_queue_pairs); + virtnet_set_queues(vi, vi->curr_queue_pairs); /* a random MAC address has been assigned, notify the device. * We don't fail probe if VIRTIO_NET_F_CTRL_MAC_ADDR is not there