From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013069.outbound.protection.outlook.com [40.93.196.69]) (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 864B334D921 for ; Wed, 12 Nov 2025 19:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.69 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976122; cv=fail; b=pcjJaxlLtcuQxLFNWAUgJxbfvA020eoE/eV/M3fi8O/o4X4kKDnuxhz4DCinOLk59Vi0p+OSfKKthf+9dE8JSiLhsKTWGGRmG3ByMZt/kEuvCah1hMgcAcxx1p3vkN9kaxyosjhbv1EIGCwMnLQbhEmkk3MaOKKYZ6594qCT8ug= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762976122; c=relaxed/simple; bh=V0Lqs/k6NZJJ8GJ4zKeSlMYCmo3LrRYW3hGmFfyd+GI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SI7moIQTXFS0QThntbEPSvrXBrmMwx9nblZNt7TTr1sTEGloCwceyluzDrMZ5Gu97njfZRA8xq1JsQG9V+gdXFyFBACdH6Ga9wiRQr5R3S5JDRY4u2ZqXFBWjpFMCFekNJFjas5lGNDPEPDpt2ETNNRQfN8Eua08y2BmKTk2EhU= 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=DWkIb/1x; arc=fail smtp.client-ip=40.93.196.69 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="DWkIb/1x" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=falHsJprBvdL9btsenetFlDvVSnn1MhjaoONbZY1dIiLv9n/5P0Jm2QkqWaHTEn4sIVZ2uagqKdCwOwrgt5K+aNLJ7+j+q2053SZIs384Zm4GuexIXnUXPBATo79X3NSDUnJMGaZzl42DcbqJcFhZ1DGcRn6whyrxm5YGTvGTguQqbbJX309FlpKwMAq4Mh4ZZWosL1ZfbhZsczSHLpLqtxeDRZDRtZu3FBeCA/oHB746UIta82ja99mlIrskCf3HL9SrBD34fd7Z++xCODQu8O9t3pIH1Ibm0zTFBpLA4xfBddZ56KPtl9kBpOuUWnBMvPsVJZt/nROJbQqQtidTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=ag1j2V9kAv+lulSGv3LH0sZmswdQK2GWLOdAV+hjO0M=; b=BNfOivzIf/ujVY0lBSaYetJq37OVKGAXHFl4sXKrPB29eucOedY4xhIiOabEBjGUkndYeM8xt7OqUkzOKo0m3ifP9SIEtG5dy3aaQpl/eu4WaWNwaMB3Fo87a9o6/wmS5eXhWNqrj9a59AsEpHHrC0RAqVV0CPazxmhlhjUQ5cFbq5ymqFcdweiLECF/1y1bntOv1luEWM4MWdOKQiAc8VQ2AkCWbe1xUubIDcKxgM8wZ+Flf/EZRm0M8P7LPIh9P7X856aQHPmNeTk5nW3WByBVTu1vi7xViT0G4DK8lpEPKLetr8iT/7I0GwayNYX5HkdEhilQFj/MWdOsF5Tjiw== 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=ag1j2V9kAv+lulSGv3LH0sZmswdQK2GWLOdAV+hjO0M=; b=DWkIb/1xw4DZ98nf9FL44iSs0sW9zJBbggrdHQOP3xWUatcPIf5OYI+xFuWFklzA7AtquzaJtKdSTvh8XiGAw23Ynrp8yQW0Mgj4ewzK9D3goSqXcSN+37aoffIzY0lci2/10vEY8fYoZOLhNePkLYXd2I++QhBeyYaHNpD0RrHD8ab4qhN4EQcvg4CtMNOdhO2gFUIvTW+6S/FcOrf5eTEukScWRHe0q/EqBk4/4yWOSo5QaysIXETh/540C3ioiqcNQoNwOSTJwQyfY1b/E0A3WpRt0ZcSr3ERXJvG1iedEUBGAnoVnE1VW4AChqRvgTvhOriVk7UPdQ5dCzgKQg== Received: from BN9PR03CA0501.namprd03.prod.outlook.com (2603:10b6:408:130::26) by PH8PR12MB6698.namprd12.prod.outlook.com (2603:10b6:510:1cd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.15; Wed, 12 Nov 2025 19:35:13 +0000 Received: from BL02EPF0002992B.namprd02.prod.outlook.com (2603:10b6:408:130:cafe::a8) by BN9PR03CA0501.outlook.office365.com (2603:10b6:408:130::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9298.16 via Frontend Transport; Wed, 12 Nov 2025 19:35:13 +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 BL02EPF0002992B.mail.protection.outlook.com (10.167.249.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.13 via Frontend Transport; Wed, 12 Nov 2025 19:35:12 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) 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.2562.20; Wed, 12 Nov 2025 11:34:58 -0800 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 12 Nov 2025 11:34:57 -0800 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 12 Nov 2025 11:34:56 -0800 From: Daniel Jurgens To: , , , CC: , , , , , , , , , , , , Daniel Jurgens Subject: [PATCH net-next v10 05/12] virtio_net: Query and set flow filter caps Date: Wed, 12 Nov 2025 13:34:28 -0600 Message-ID: <20251112193435.2096-6-danielj@nvidia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251112193435.2096-2-danielj@nvidia.com> References: <20251112193435.2096-2-danielj@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0002992B:EE_|PH8PR12MB6698:EE_ X-MS-Office365-Filtering-Correlation-Id: 63fdc34c-2318-4d70-f321-08de2222995d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?TVGMx8Fw+SIvvQWOBzxSTEr0KkxmK5AohFFgi2MMEEO555y2Zjrb+QOmbxNZ?= =?us-ascii?Q?Uh094aLquF9K7aIgHB5oKr6yMC3HIxZtIXKMGUoG7cteG3CPx18zDgjomH2q?= =?us-ascii?Q?sPQorfu+CTjhz+jLNRP21Isz92Eszu+4xcaRPvSBLzTLAKzKM1vWAnSD2cuG?= =?us-ascii?Q?AY3moqJpmie4R/eMZX6ljnIZO3cGdcqJ23Hg+on1GNheUyGXB1rOjeN8/bZ8?= =?us-ascii?Q?LeLQcpunmSH2d7kvLI4QRlwCYyWyIqiS47woRPzB7VkA/eady6epiWorIS6Y?= =?us-ascii?Q?v1YkUaJE3n4E7KRAtvT2Ya6DFbhsIrkGp29tf3eTIn88O0Bvmtx6so/IhNhb?= =?us-ascii?Q?qkk+hlztvhcwAPSw1pOQW476ZYn+gPCQ+qOPGfKNiEy5YukfUyOOVS+6U1Us?= =?us-ascii?Q?x40QLvJ0Y3diuf7tm5KvUepJ7skqiFdDcsXOReU88KzTjLsNBZSeUBHd14yP?= =?us-ascii?Q?TNTpmSpFVjRiKdkHnrhX/d34jrd6jOnICW+pickLLWR6XZ+8wJoN2w5xr72v?= =?us-ascii?Q?7CLqk1YV/1eRIKG7CDIaNg9xV/HBjGL5Ogj2QnkW/niCH45+P2ARd3xyp+3z?= =?us-ascii?Q?dwpWVMbqc9yV02+1+z70aT5gS+9ANRBu/9K6qIprM2AvuGMvk8zlvcGTDB0z?= =?us-ascii?Q?fpOjDPaaGEnBXWe2c/JL0QmSXQsviGw6XbtXCmN7MukVO5Oo3250x1Ektdr/?= =?us-ascii?Q?I8BIMhtnzkownZbw4cBqZOKJT+gvd6BSFa/4pIDZDnVfD5XGEDnRGyVtppo5?= =?us-ascii?Q?2Xk6vml4bI2ZWWeBg6RErWhkghcG3N/VACaSsC00bQncgdjynfDzmPugjPUg?= =?us-ascii?Q?F0BFAZtg3RDq6XDcYkcye75LpDxR7bEnIDVsu7QRd0RCnOCK6YHjvmHiJZwG?= =?us-ascii?Q?JhWCsgklL/1iw4XQ6zcXZjjvqExq04TXv9SD3bQWYtJSYlsf4LYu3BxjTv+s?= =?us-ascii?Q?KzJiB0CIt/X8N1HVtVEl3ymNfoLXg/ty7FVEw/KUwpfvLAzMabQ3N0Zf+Yf1?= =?us-ascii?Q?iA3tGB34bganQXkoLlUZU/Rpx9MMoWAjd4kbEbuYTjrO4Cop8RmFLHqsndvU?= =?us-ascii?Q?WucbAttEb7gLkB/nCDaQM4XEu6e7Clqngxmcume2lkjbX0ySKE5hohwDZAk/?= =?us-ascii?Q?ChEpDas7FwMeP1tMvEbUbhigJzGZMN7iddQQQF9yv1pDlUzn8bOFsz7EREip?= =?us-ascii?Q?aS6vdLYdCA3cYywze4P1UgrwKMGV9csDZlEmATIYrPyGhJZ3HafDJ9h/PmAn?= =?us-ascii?Q?jfcOuESPOrKctozxcHU3qOMxXaNQz5Mm9fbAw2pnrtFG9x2SkwvX3pxheo1R?= =?us-ascii?Q?EBNVNzfuXUX/nEkg4Ts+KSBM4PbLHd3kCyyMQZJEhlNWJRXpom2j+T3y3VCf?= =?us-ascii?Q?sjAXK2cOEyhdscUJ7Nl3qoovd7gZdG84wXsVOc8HOoNBWu60/iSGMkdqwiaW?= =?us-ascii?Q?O5OKmOC8QATW8XS9zCyKZDgKZ6F9ga0pEWtxoGSWFtKet25EPbM23u1ZuNqc?= =?us-ascii?Q?5ffj+hZRFCdKbhrGSm+c7hMP/I4vensvMWmpQs1lwyO5UKJrQoKf7S7miMBF?= =?us-ascii?Q?z+Ja2boBQpW9M2WudRE=3D?= 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:(13230040)(7416014)(1800799024)(82310400026)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2025 19:35:12.8698 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63fdc34c-2318-4d70-f321-08de2222995d 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: BL02EPF0002992B.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6698 When probing a virtnet device, attempt to read the flow filter capabilities. In order to use the feature the caps must also be set. For now setting what was read is sufficient. Signed-off-by: Daniel Jurgens Reviewed-by: Parav Pandit Reviewed-by: Shahar Shitrit --- v4: - Validate the length in the selector caps - Removed __free usage. - Removed for(int. v5: - Remove unneed () after MAX_SEL_LEN macro (test bot) v6: - Fix sparse warning "array of flexible structures" Jakub K/Simon H - Use new variable and validate ff_mask_size before set_cap. MST v7: - Set ff->ff_{caps, mask, actions} NULL in error path. Paolo Abeni - Return errors from virtnet_ff_init, -ENOTSUPP is not fatal. Xuan v8: - Use real_ff_mask_size when setting the selector caps. Jason Wang v9: - Set err after failed memory allocations. Simon Horman v10: - Return -EOPNOTSUPP in virnet_ff_init if !config->admin_cmd_exec before allocing any memory. Jason/Paolo. --- drivers/net/virtio_net.c | 194 +++++++++++++++++++++++++++++ include/linux/virtio_admin.h | 1 + include/uapi/linux/virtio_net_ff.h | 91 ++++++++++++++ 3 files changed, 286 insertions(+) create mode 100644 include/uapi/linux/virtio_net_ff.h diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 9220eea24875..b4d6e475b0d8 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -26,6 +26,9 @@ #include #include #include +#include +#include +#include static int napi_weight = NAPI_POLL_WEIGHT; module_param(napi_weight, int, 0444); @@ -281,6 +284,14 @@ static const struct virtnet_stat_desc virtnet_stats_tx_speed_desc_qstat[] = { VIRTNET_STATS_DESC_TX_QSTAT(speed, ratelimit_packets, hw_drop_ratelimits), }; +struct virtnet_ff { + struct virtio_device *vdev; + bool ff_supported; + struct virtio_net_ff_cap_data *ff_caps; + struct virtio_net_ff_cap_mask_data *ff_mask; + struct virtio_net_ff_actions *ff_actions; +}; + #define VIRTNET_Q_TYPE_RX 0 #define VIRTNET_Q_TYPE_TX 1 #define VIRTNET_Q_TYPE_CQ 2 @@ -493,6 +504,8 @@ struct virtnet_info { struct failover *failover; u64 device_stats_cap; + + struct virtnet_ff ff; }; struct padded_vnet_hdr { @@ -6768,6 +6781,176 @@ static const struct xdp_metadata_ops virtnet_xdp_metadata_ops = { .xmo_rx_hash = virtnet_xdp_rx_hash, }; +static size_t get_mask_size(u16 type) +{ + switch (type) { + case VIRTIO_NET_FF_MASK_TYPE_ETH: + return sizeof(struct ethhdr); + case VIRTIO_NET_FF_MASK_TYPE_IPV4: + return sizeof(struct iphdr); + case VIRTIO_NET_FF_MASK_TYPE_IPV6: + return sizeof(struct ipv6hdr); + case VIRTIO_NET_FF_MASK_TYPE_TCP: + return sizeof(struct tcphdr); + case VIRTIO_NET_FF_MASK_TYPE_UDP: + return sizeof(struct udphdr); + } + + return 0; +} + +#define MAX_SEL_LEN (sizeof(struct ipv6hdr)) + +static int virtnet_ff_init(struct virtnet_ff *ff, struct virtio_device *vdev) +{ + size_t ff_mask_size = sizeof(struct virtio_net_ff_cap_mask_data) + + sizeof(struct virtio_net_ff_selector) * + VIRTIO_NET_FF_MASK_TYPE_MAX; + struct virtio_admin_cmd_query_cap_id_result *cap_id_list; + struct virtio_net_ff_selector *sel; + size_t real_ff_mask_size; + int err; + int i; + + if (!vdev->config->admin_cmd_exec) + return -EOPNOTSUPP; + + cap_id_list = kzalloc(sizeof(*cap_id_list), GFP_KERNEL); + if (!cap_id_list) + return -ENOMEM; + + err = virtio_admin_cap_id_list_query(vdev, cap_id_list); + if (err) + goto err_cap_list; + + if (!(VIRTIO_CAP_IN_LIST(cap_id_list, + VIRTIO_NET_FF_RESOURCE_CAP) && + VIRTIO_CAP_IN_LIST(cap_id_list, + VIRTIO_NET_FF_SELECTOR_CAP) && + VIRTIO_CAP_IN_LIST(cap_id_list, + VIRTIO_NET_FF_ACTION_CAP))) { + err = -EOPNOTSUPP; + goto err_cap_list; + } + + ff->ff_caps = kzalloc(sizeof(*ff->ff_caps), GFP_KERNEL); + if (!ff->ff_caps) { + err = -ENOMEM; + goto err_cap_list; + } + + err = virtio_admin_cap_get(vdev, + VIRTIO_NET_FF_RESOURCE_CAP, + ff->ff_caps, + sizeof(*ff->ff_caps)); + + if (err) + goto err_ff; + + /* VIRTIO_NET_FF_MASK_TYPE start at 1 */ + for (i = 1; i <= VIRTIO_NET_FF_MASK_TYPE_MAX; i++) + ff_mask_size += get_mask_size(i); + + ff->ff_mask = kzalloc(ff_mask_size, GFP_KERNEL); + if (!ff->ff_mask) { + err = -ENOMEM; + goto err_ff; + } + + err = virtio_admin_cap_get(vdev, + VIRTIO_NET_FF_SELECTOR_CAP, + ff->ff_mask, + ff_mask_size); + + if (err) + goto err_ff_mask; + + ff->ff_actions = kzalloc(sizeof(*ff->ff_actions) + + VIRTIO_NET_FF_ACTION_MAX, + GFP_KERNEL); + if (!ff->ff_actions) { + err = -ENOMEM; + goto err_ff_mask; + } + + err = virtio_admin_cap_get(vdev, + VIRTIO_NET_FF_ACTION_CAP, + ff->ff_actions, + sizeof(*ff->ff_actions) + VIRTIO_NET_FF_ACTION_MAX); + + if (err) + goto err_ff_action; + + err = virtio_admin_cap_set(vdev, + VIRTIO_NET_FF_RESOURCE_CAP, + ff->ff_caps, + sizeof(*ff->ff_caps)); + if (err) + goto err_ff_action; + + real_ff_mask_size = sizeof(struct virtio_net_ff_cap_mask_data); + sel = (void *)&ff->ff_mask->selectors[0]; + + for (i = 0; i < ff->ff_mask->count; i++) { + if (sel->length > MAX_SEL_LEN) { + err = -EINVAL; + goto err_ff_action; + } + real_ff_mask_size += sizeof(struct virtio_net_ff_selector) + sel->length; + sel = (void *)sel + sizeof(*sel) + sel->length; + } + + if (real_ff_mask_size > ff_mask_size) { + err = -EINVAL; + goto err_ff_action; + } + + err = virtio_admin_cap_set(vdev, + VIRTIO_NET_FF_SELECTOR_CAP, + ff->ff_mask, + real_ff_mask_size); + if (err) + goto err_ff_action; + + err = virtio_admin_cap_set(vdev, + VIRTIO_NET_FF_ACTION_CAP, + ff->ff_actions, + sizeof(*ff->ff_actions) + VIRTIO_NET_FF_ACTION_MAX); + if (err) + goto err_ff_action; + + ff->vdev = vdev; + ff->ff_supported = true; + + kfree(cap_id_list); + + return 0; + +err_ff_action: + kfree(ff->ff_actions); + ff->ff_actions = NULL; +err_ff_mask: + kfree(ff->ff_mask); + ff->ff_mask = NULL; +err_ff: + kfree(ff->ff_caps); + ff->ff_caps = NULL; +err_cap_list: + kfree(cap_id_list); + + return err; +} + +static void virtnet_ff_cleanup(struct virtnet_ff *ff) +{ + if (!ff->ff_supported) + return; + + kfree(ff->ff_actions); + kfree(ff->ff_mask); + kfree(ff->ff_caps); +} + static int virtnet_probe(struct virtio_device *vdev) { int i, err = -ENOMEM; @@ -7131,6 +7314,15 @@ static int virtnet_probe(struct virtio_device *vdev) } vi->guest_offloads_capable = vi->guest_offloads; + /* Initialize flow filters. Not supported is an acceptable and common + * return code + */ + err = virtnet_ff_init(&vi->ff, vi->vdev); + if (err && err != -EOPNOTSUPP) { + rtnl_unlock(); + goto free_unregister_netdev; + } + rtnl_unlock(); err = virtnet_cpu_notif_add(vi); @@ -7146,6 +7338,7 @@ static int virtnet_probe(struct virtio_device *vdev) free_unregister_netdev: unregister_netdev(dev); + virtnet_ff_cleanup(&vi->ff); free_failover: net_failover_destroy(vi->failover); free_vqs: @@ -7195,6 +7388,7 @@ static void virtnet_remove(struct virtio_device *vdev) virtnet_free_irq_moder(vi); unregister_netdev(vi->dev); + virtnet_ff_cleanup(&vi->ff); net_failover_destroy(vi->failover); diff --git a/include/linux/virtio_admin.h b/include/linux/virtio_admin.h index 039b996f73ec..db0f42346ca9 100644 --- a/include/linux/virtio_admin.h +++ b/include/linux/virtio_admin.h @@ -3,6 +3,7 @@ * Header file for virtio admin operations */ #include +#include #ifndef _LINUX_VIRTIO_ADMIN_H #define _LINUX_VIRTIO_ADMIN_H diff --git a/include/uapi/linux/virtio_net_ff.h b/include/uapi/linux/virtio_net_ff.h new file mode 100644 index 000000000000..bd7a194a9959 --- /dev/null +++ b/include/uapi/linux/virtio_net_ff.h @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note + * + * Header file for virtio_net flow filters + */ +#ifndef _LINUX_VIRTIO_NET_FF_H +#define _LINUX_VIRTIO_NET_FF_H + +#include +#include + +#define VIRTIO_NET_FF_RESOURCE_CAP 0x800 +#define VIRTIO_NET_FF_SELECTOR_CAP 0x801 +#define VIRTIO_NET_FF_ACTION_CAP 0x802 + +/** + * struct virtio_net_ff_cap_data - Flow filter resource capability limits + * @groups_limit: maximum number of flow filter groups supported by the device + * @classifiers_limit: maximum number of classifiers supported by the device + * @rules_limit: maximum number of rules supported device-wide across all groups + * @rules_per_group_limit: maximum number of rules allowed in a single group + * @last_rule_priority: priority value associated with the lowest-priority rule + * @selectors_per_classifier_limit: maximum selectors allowed in one classifier + * + * The limits are reported by the device and describe resource capacities for + * flow filters. Multi-byte fields are little-endian. + */ +struct virtio_net_ff_cap_data { + __le32 groups_limit; + __le32 classifiers_limit; + __le32 rules_limit; + __le32 rules_per_group_limit; + __u8 last_rule_priority; + __u8 selectors_per_classifier_limit; +}; + +/** + * struct virtio_net_ff_selector - Selector mask descriptor + * @type: selector type, one of VIRTIO_NET_FF_MASK_TYPE_* constants + * @flags: selector flags, see VIRTIO_NET_FF_MASK_F_* constants + * @reserved: must be set to 0 by the driver and ignored by the device + * @length: size in bytes of @mask + * @reserved1: must be set to 0 by the driver and ignored by the device + * @mask: variable-length mask payload for @type, length given by @length + * + * A selector describes a header mask that a classifier can apply. The format + * of @mask depends on @type. + */ +struct virtio_net_ff_selector { + __u8 type; + __u8 flags; + __u8 reserved[2]; + __u8 length; + __u8 reserved1[3]; + __u8 mask[]; +}; + +#define VIRTIO_NET_FF_MASK_TYPE_ETH 1 +#define VIRTIO_NET_FF_MASK_TYPE_IPV4 2 +#define VIRTIO_NET_FF_MASK_TYPE_IPV6 3 +#define VIRTIO_NET_FF_MASK_TYPE_TCP 4 +#define VIRTIO_NET_FF_MASK_TYPE_UDP 5 +#define VIRTIO_NET_FF_MASK_TYPE_MAX VIRTIO_NET_FF_MASK_TYPE_UDP + +/** + * struct virtio_net_ff_cap_mask_data - Supported selector mask formats + * @count: number of entries in @selectors + * @reserved: must be set to 0 by the driver and ignored by the device + * @selectors: array of supported selector descriptors + */ +struct virtio_net_ff_cap_mask_data { + __u8 count; + __u8 reserved[7]; + __u8 selectors[]; +}; +#define VIRTIO_NET_FF_MASK_F_PARTIAL_MASK (1 << 0) + +#define VIRTIO_NET_FF_ACTION_DROP 1 +#define VIRTIO_NET_FF_ACTION_RX_VQ 2 +#define VIRTIO_NET_FF_ACTION_MAX VIRTIO_NET_FF_ACTION_RX_VQ +/** + * struct virtio_net_ff_actions - Supported flow actions + * @count: number of supported actions in @actions + * @reserved: must be set to 0 by the driver and ignored by the device + * @actions: array of action identifiers (VIRTIO_NET_FF_ACTION_*) + */ +struct virtio_net_ff_actions { + __u8 count; + __u8 reserved[7]; + __u8 actions[]; +}; +#endif -- 2.50.1