From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 2A3E542BA1;
	Thu, 25 May 2023 22:39:47 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 06C9040DF8;
	Thu, 25 May 2023 22:39:47 +0200 (CEST)
Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com
 [209.85.214.176])
 by mails.dpdk.org (Postfix) with ESMTP id 8C78440DDB
 for <dev@dpdk.org>; Thu, 25 May 2023 22:39:46 +0200 (CEST)
Received: by mail-pl1-f176.google.com with SMTP id
 d9443c01a7336-1ae79528d4dso132895ad.2
 for <dev@dpdk.org>; Thu, 25 May 2023 13:39:46 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1685047185;
 x=1687639185; 
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=H45x7lI0EETxWzacAs6MVMJW0KmfqQJZMwP/QniiOwY=;
 b=o4rLu6+38iuUhgCJuQhjt1l3ZE0ya9xhBiG1HhYUtdfQejd8FePh13/UY1vLukBc+Y
 bUWcPvstmNiBJNIRXw3hMGO9ukcBLNIWH0ITySMBP6VQDMc9cpNGDfu38j0r3mRj8hHA
 VZIS1hVBM0WZ6yggB3K2EB5o0bixM04eU1PbSVf2tvhtJTKQRRIu7ypiB2VQ2I7aP0H/
 of/zxpmB1TJJMzeByEls0sJ3fAIKjXmNpQ4VPpc1kOaMZosFjDBe4rgGcp/Z77g9c3ia
 d65j/eH+5AABFOktRBDiXVSxDzsPQeIca2M9pZyk/9BFBWD1uuHlZRitbVG69L8xdmmg
 GkLQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20221208; t=1685047185; x=1687639185;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=H45x7lI0EETxWzacAs6MVMJW0KmfqQJZMwP/QniiOwY=;
 b=O4seNpfvUUpbj8jdXBovcCB/+ltbTfaW68qm7qnx93D9ESB3+L36gL2Hbc3Enw0Ci6
 FY0AeDXPFAO5HCcCgrRMWDXwKXFp52+sfaVx4zrzcpClq41kMqAJ6x0DeWotNCpafbS+
 yB8QZmctGHTfZMaDnotG3ObbZYxbrWti4xY9NJZU+cK7vzeHXU+aHJUr6fO5cKWeAWyi
 rsTR5DbRua3ea74yO0m4o9aMSHRnCfqUuUf80QSqb1D3cUlaYHsK5/HIir8MYwYrkMfG
 0vKB16v8crkuDM0mAwROYnF9n7TMZXdbqvT5crfNkepekuhpZhAPWNQUuK4xlY+u+RC9
 P4Zw==
X-Gm-Message-State: AC+VfDxxhkHX9CGwhbxoOmBUk4n3D9iChVR5gNiLNrv807xzbqEHrhmk
 K5imPh5lBdkjv1AXP6mr2y2bd3EgLU28cvweu5z1fQ==
X-Google-Smtp-Source: ACHHUZ6ouhA4Ao2S0EvHvybIYLs/379hoJ4G3L4fXbRQ53nBw0furPxT5JeYhfhx+JjHDZvQQMRm4Q==
X-Received: by 2002:a17:902:f690:b0:1a6:9d1b:e18f with SMTP id
 l16-20020a170902f69000b001a69d1be18fmr3366533plg.45.1685047185327; 
 Thu, 25 May 2023 13:39:45 -0700 (PDT)
Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218])
 by smtp.gmail.com with ESMTPSA id
 w14-20020a1709029a8e00b0019719f752c5sm1810729plp.59.2023.05.25.13.39.44
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Thu, 25 May 2023 13:39:44 -0700 (PDT)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>, thomas@monjalon.net,
 Ferruh Yigit <ferruh.yigit@amd.com>,
 Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Subject: [PATCH] ethdev: validate reserved fields
Date: Thu, 25 May 2023 13:39:42 -0700
Message-Id: <20230525203942.129413-1-stephen@networkplumber.org>
X-Mailer: git-send-email 2.39.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

The various reserved fields added to ethdev could not be
safely used for future extensions because they were never
checked on input. Therefore ABI would be broken if these
fields were added in a future DPDK release.

Fixes: 436b3a6b6e62 ("ethdev: reserve space in main structs for extension")
Cc: thomas@monjalon.net
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/ethdev/rte_ethdev.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 4d0325568322..4f937a1914c9 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -1228,6 +1228,25 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 	/* Backup mtu for rollback */
 	old_mtu = dev->data->mtu;
 
+	/* fields must be zero to reserve them for future ABI changes */
+	if (dev_conf->rxmode.reserved_64s[0] != 0 ||
+	    dev_conf->rxmode.reserved_64s[1] != 0 ||
+	    dev_conf->rxmode.reserved_ptrs[0] != NULL ||
+	    dev_conf->rxmode.reserved_ptrs[1] != NULL) {
+		RTE_ETHDEV_LOG(ERR, "Rxmode reserved fields not zero\n");
+		ret = -EINVAL;
+		goto rollback;
+	}
+
+	if (dev_conf->txmode.reserved_64s[0] != 0 ||
+	    dev_conf->txmode.reserved_64s[1] != 0 ||
+	    dev_conf->txmode.reserved_ptrs[0] != NULL ||
+	    dev_conf->txmode.reserved_ptrs[1] != NULL) {
+		RTE_ETHDEV_LOG(ERR, "txmode reserved fields not zero\n");
+		ret = -EINVAL;
+		goto rollback;
+	}
+
 	ret = rte_eth_dev_info_get(port_id, &dev_info);
 	if (ret != 0)
 		goto rollback;
@@ -2003,6 +2022,14 @@ rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
 	if (*dev->dev_ops->rx_queue_setup == NULL)
 		return -ENOTSUP;
 
+	if (rx_conf->reserved_64s[0] != 0 ||
+	    rx_conf->reserved_64s[1] != 0 ||
+	    rx_conf->reserved_ptrs[0] != NULL ||
+	    rx_conf->reserved_ptrs[1] != NULL) {
+		RTE_ETHDEV_LOG(ERR, "Rx conf reserved fields not zero\n");
+		return -EINVAL;
+	}
+
 	ret = rte_eth_dev_info_get(port_id, &dev_info);
 	if (ret != 0)
 		return ret;
@@ -2206,6 +2233,12 @@ rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
 		return -EINVAL;
 	}
 
+	if (conf->reserved != 0) {
+		RTE_ETHDEV_LOG(ERR,
+			       "Rx hairpin reserved field not zero\n");
+		return -EINVAL;
+	}
+
 	ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
 	if (ret != 0)
 		return ret;
@@ -2301,6 +2334,14 @@ rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
 	if (*dev->dev_ops->tx_queue_setup == NULL)
 		return -ENOTSUP;
 
+	if (tx_conf->reserved_64s[0] != 0 ||
+	    tx_conf->reserved_64s[1] != 0 ||
+	    tx_conf->reserved_ptrs[0] != NULL ||
+	    tx_conf->reserved_ptrs[1] != NULL) {
+		RTE_ETHDEV_LOG(ERR, "Tx conf reserved fields not zero\n");
+		return -EINVAL;
+	}
+
 	ret = rte_eth_dev_info_get(port_id, &dev_info);
 	if (ret != 0)
 		return ret;
-- 
2.39.2