From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0107.outbound.protection.outlook.com [65.55.169.107]) by dpdk.org (Postfix) with ESMTP id A02AD3796 for ; Tue, 7 Apr 2015 19:21:40 +0200 (CEST) Received: from CY1PR0101MB0987.prod.exchangelabs.com (25.160.224.149) by CY1PR0101MB0988.prod.exchangelabs.com (25.160.224.150) with Microsoft SMTP Server (TLS) id 15.1.125.19; Tue, 7 Apr 2015 17:21:38 +0000 Received: from CY1PR0101MB0987.prod.exchangelabs.com ([25.160.224.149]) by CY1PR0101MB0987.prod.exchangelabs.com ([25.160.224.149]) with mapi id 15.01.0130.020; Tue, 7 Apr 2015 17:21:37 +0000 From: Don Provan To: Stephen Hemminger Thread-Topic: [dpdk-dev] [PATCH] eth_dev: make ether dev_ops const Thread-Index: AQHQcJQ2bC6K+z5roU2pUQtP3bjJP51Bx0Ew Date: Tue, 7 Apr 2015 17:21:37 +0000 Message-ID: References: <1428343496-26532-1-git-send-email-stephen@networkplumber.org> In-Reply-To: <1428343496-26532-1-git-send-email-stephen@networkplumber.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [209.234.132.35] authentication-results: networkplumber.org; dkim=none (message not signed) header.d=none; x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0101MB0988; x-forefront-antispam-report: BMV:1; SFV:NSPM; SFS:(10019020)(6009001)(377454003)(13464003)(2656002)(86362001)(66066001)(92566002)(76176999)(74316001)(122556002)(40100003)(50986999)(62966003)(54356999)(77156002)(2900100001)(102836002)(2950100001)(87936001)(110136001)(46102003)(19580395003)(19580405001)(106116001)(33656002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR0101MB0988; H:CY1PR0101MB0987.prod.exchangelabs.com; FPR:; SPF:None; MLV:sfv; LANG:en; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(5002010)(5005006); SRVR:CY1PR0101MB0988; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0101MB0988; x-forefront-prvs: 0539EEBD11 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: bivio.net X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Apr 2015 17:21:37.1387 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8731bc55-0e76-4eb7-ae4b-401e56037945 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0101MB0988 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH] eth_dev: make ether dev_ops const X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Apr 2015 17:21:41 -0000 -----Original Message----- >From: Stephen Hemminger [mailto:stephen@networkplumber.org]=20 >Sent: Monday, April 06, 2015 11:05 AM >To: dev@dpdk.org >Subject: [dpdk-dev] [PATCH] eth_dev: make ether dev_ops const > >Ethernet device function tables should be immutable for correctness and se= curity. Special case for the test code driver. ... >diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c index f163562= ..f579558 100644 >--- a/app/test/virtual_pmd.c >+++ b/app/test/virtual_pmd.c ... >+/* This driver uses private mutable eth_dev_ops for each >+ * instance so it is safe to override const here. >+ */ >+#pragma GCC diagnostic push >+#pragma GCC diagnostic ignored "-Wcast-qual" > void > virtual_ethdev_start_fn_set_success(uint8_t port_id, uint8_t success) { > struct rte_eth_dev *vrtl_eth_dev =3D &rte_eth_devices[port_id]; >+ struct eth_dev_ops *dev_ops >+ =3D (struct eth_dev_ops *) vrtl_eth_dev->dev_ops; ... If this is really safe, then you should be able to accomplish it without disabling a bunch of protection. I suggest adding a pointer that isn't const to the private data block and adjusting the allocated dispatch table through that instead of through the pointer to the immutable dispatch table you've established in struct rte_eth_dev. That reinforces the fact that modifying the dispatch table is a private matter within the driver while showing structurally exactly why it's safe to change it. And it's not nearly so ugly. -don provan dprovan@bivio.net