From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0060.outbound.protection.outlook.com [104.47.0.60]) by dpdk.org (Postfix) with ESMTP id 8B3871B330 for ; Thu, 18 Jan 2018 16:00:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=JajZ8O3jh5MZb5tMLxmKcsdQlOyyyoLduHBshNeQmag=; b=FSRryM7M4EjW3FMhLe/ooOQtxPO5n3iZJ/SPwOb0aPa+P0iaOBA5s5u7NiH3f1YteR4eW/xSnxG/j0PWglN6cvxteJVf0OJ7On8J3qa0XLcj7Rt7p1DHW8XbHH5G2XrUq8TSwQefU7SzNjC9LHxLwqitl/dz0yBMplGDfKhl3nc= Received: from AM6PR0502MB3797.eurprd05.prod.outlook.com (52.133.21.26) by AM6PR0502MB3941.eurprd05.prod.outlook.com (52.133.30.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Thu, 18 Jan 2018 15:00:13 +0000 Received: from AM6PR0502MB3797.eurprd05.prod.outlook.com ([fe80::6c28:c6b3:de94:a733]) by AM6PR0502MB3797.eurprd05.prod.outlook.com ([fe80::6c28:c6b3:de94:a733%13]) with mapi id 15.20.0428.014; Thu, 18 Jan 2018 15:00:13 +0000 From: Matan Azrad To: "Ananyev, Konstantin" , Thomas Monjalon , Gaetan Rivet , "Wu, Jingjing" CC: "dev@dpdk.org" , Neil Horman , "Richardson, Bruce" Thread-Topic: [PATCH v2 2/6] ethdev: add port ownership Thread-Index: AQHTihf/M9xg8LYorUSRFqZtTc27hqNtNdVQgAFomACAAAOCwIAAuwQAgABvY+CABQwJgIAAEk3ggABinoCAANUIAIAAxQGAgAAGCnCAAQnKAIAAAmNwgAAXCYCAAABqkIAAQhEAgAASagCAACqV0IABKccAgAABeuCAAAVxgIAAAFvAgAACfQCAAAFdcA== Date: Thu, 18 Jan 2018 15:00:13 +0000 Message-ID: References: <1511870281-15282-1-git-send-email-matan@mellanox.com> <1515318351-4756-1-git-send-email-matan@mellanox.com> <1515318351-4756-3-git-send-email-matan@mellanox.com> <2601191342CEEE43887BDE71AB97725880E3B9D6@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772588627B12A@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772588627CCB0@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772588627DC25@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772588627DE30@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772588627E954@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772588627EE60@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772588627EEDA@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772588627F076@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772588628029A@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB9772588628032A@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB97725886280357@irsmsx105.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB97725886280357@irsmsx105.ger.corp.intel.com> Accept-Language: en-US, he-IL Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM6PR0502MB3941; 7:vO1PIi2MsMmdjdEko4d2nMZHeJkAm6TVJbIzHUsWWDDp9hBdxWGJIlkb0zBFQStUTxQ0k09Bxq1gvQSAYy4KuVfI/1tTh5Dl/kUXJaZLTxBBIhh/O+gRrxFQ6SrgBNcqX9L8a6LakXuB+DqdDCvFiT+mKjPzySgdBpao6aljm+JHV7dg2LxxdlDxiYKFXZ+arzKE2kIcy4x1+H0k0FT+P9AT3QPkNerkl7X7ykHr9+sJ1H0+zPuSMz2HDKE7mnc1 x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 1333070d-9195-430f-36fc-08d55e842dbf x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(48565401081)(2017052603307)(7153060)(7193020); SRVR:AM6PR0502MB3941; x-ms-traffictypediagnostic: AM6PR0502MB3941: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(60795455431006)(228905959029699)(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231023)(2400063)(944501161)(6055026)(6041268)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:AM6PR0502MB3941; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:AM6PR0502MB3941; x-forefront-prvs: 05568D1FF7 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(39860400002)(346002)(376002)(39380400002)(366004)(52314003)(199004)(189003)(13464003)(25786009)(2900100001)(5660300001)(68736007)(6246003)(4326008)(8936002)(229853002)(81156014)(8676002)(53936002)(81166006)(97736004)(86362001)(6506007)(2906002)(76176011)(53546011)(99286004)(6436002)(102836004)(59450400001)(106356001)(3660700001)(110136005)(33656002)(316002)(54906003)(3846002)(6116002)(66066001)(7696005)(26005)(93886005)(7736002)(5250100002)(5890100001)(478600001)(305945005)(74316002)(3280700002)(14454004)(55016002)(105586002)(9686003)(2950100002)(21314002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR0502MB3941; H:AM6PR0502MB3797.eurprd05.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: FmhZrLmzz0p5WcDT2wt1ETgFFmkCsZpkeXP5HgcpyAfLdgsJ03OtZ4zszk8vYVCITECn6YQozSxuI8fajZOxdg== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1333070d-9195-430f-36fc-08d55e842dbf X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2018 15:00:13.8055 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0502MB3941 Subject: Re: [dpdk-dev] [PATCH v2 2/6] ethdev: add port ownership X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jan 2018 15:00:15 -0000 From: Ananyev, Konstantin, Thursday, January 18, 2018 4:52 PM >=20 > > -----Original Message----- > > From: Matan Azrad [mailto:matan@mellanox.com] > > Sent: Thursday, January 18, 2018 2:45 PM > > To: Ananyev, Konstantin ; Thomas > > Monjalon ; Gaetan Rivet > ; > > Wu, Jingjing > > Cc: dev@dpdk.org; Neil Horman ; Richardson, > > Bruce > > Subject: RE: [PATCH v2 2/6] ethdev: add port ownership > > > > HI > > > > From: Ananyev, Konstantin, Thursday, January 18, 2018 4:42 PM > > > > Hi Konstantine > > > > > > > > > Hi Matan, > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Another thing - you'll > > > > > > > > > > > > > > > > > > > > > > > > probably need to > > > > > > > > > > grab/release > > > > > > > > > > > > > > > > > > > > > > > > a lock inside > > > > > > > > > > > > > > > > > > > > > > > > rte_eth_dev_allocated() too= . > > > > > > > > > > > > > > > > > > > > > > > > It is a public function > > > > > > > > > > > > > > > > > > > > > > > > used by drivers, so need > > > > > > > > > > > > > > > > > > > > > > > > to be protected > > > > > > > > > > > > > > > > too. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Yes, I thought about it, but > > > > > > > > > > > > > > > > > > > > > > > decided not to use lock in > > > > > > > > > > > > next: > > > > > > > > > > > > > > > > > > > > > > > rte_eth_dev_allocated > > > > > > > > > > > > > > > > > > > > > > > rte_eth_dev_count > > > > > > > > > > > > > > > > > > > > > > > rte_eth_dev_get_name_by_port > > > > > > > > > > > > > > > > rte_eth_dev_get_port_by_name > > > > > > > > > > > > > > > > > > > > > > > maybe more... > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > As I can see in patch #3 you > > > > > > > > > > > > > > > > > > > > > > protect by lock access to > > > > > > > > > > > > > > > > > > > > > > rte_eth_dev_data[].name (which > > > > > > > > > > > > > > > > > > > > > > seems like a good > > > > > > > > > > > > thing). > > > > > > > > > > > > > > > > > > > > > > So I think any other public > > > > > > > > > > > > > > > > > > > > > > function that access > > > > > > > > > > > > > > > > > > > > > > rte_eth_dev_data[].name should > > > > > > > > > > > > > > > > > > > > > > be protected by the > > > > > > > > > > > > same > > > > > > > > > > > > > > lock. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I don't think so, I can > > > > > > > > > > > > > > > > > > > > > understand to use the ownership > > > > > > > > > > > > > > > > > > > > > lock here(as in port > > > > > > > > > > > > > > > > > > > > creation) but I don't think it is n= ecessary > too. > > > > > > > > > > > > > > > > > > > > > What are we exactly protecting he= re? > > > > > > > > > > > > > > > > > > > > > Don't you think it is just > > > > > > > > > > > > > > > > > > > > > timing?(ask in the next moment > > > > > > > > > > > > > > > > > > > > > and you may get another > > > > > > > > > > > > > > > > > > > > > answer) I don't see optional > > > > > > > > > > crash. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Not sure what you mean here by timi= ng... > > > > > > > > > > > > > > > > > > > > As I understand > > > > > > > > > > > > > > > > > > > > rte_eth_dev_data[].name unique > > > > > > > > > > identifies > > > > > > > > > > > > > > > > > > > > device and is used by port > > > > > > > > > > > > > > > > > > > > allocation/release/find > > > > > > > > > > functions. > > > > > > > > > > > > > > > > > > > > As you stated above: > > > > > > > > > > > > > > > > > > > > "1. The port allocation and port > > > > > > > > > > > > > > > > > > > > release synchronization will be > > > > > > > > > > > > > > > > > > > > managed by > > > ethdev." > > > > > > > > > > > > > > > > > > > > To me it means that ethdev layer > > > > > > > > > > > > > > > > > > > > has to make sure that all accesses > > > > > > > > > > > > > > > > > > > > to rte_eth_dev_data[].name are > > > > > > > > atomic. > > > > > > > > > > > > > > > > > > > > Otherwise what would prevent the > > > > > > > > > > > > > > > > > > > > situation when one > > > > > > > > > > > > process > > > > > > > > > > > > > > > > > > > > does > > > > > > > > > > > > > > > > > > > > rte_eth_dev_allocate()- > > > > > > > > > > >snprintf(rte_eth_dev_data[x].name, > > > > > > > > > > > > > > > > > > > > ...) while second one does > > > > > > > > > > > > > > > > > > rte_eth_dev_allocated(rte_eth_dev_data[= x]. > > > > > > > > > > > > > > > > > > name, > > > > > ...) ? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > The second will get True or False and= that is > it. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Under race condition - in the worst > > > > > > > > > > > > > > > > > > case it might crash, though for that > > > > > > > > > > > > > > > > > > you'll have to be really > > > > > unlucky. > > > > > > > > > > > > > > > > > > Though in most cases as you said it > > > > > > > > > > > > > > > > > > would just not operate > > > > > > > > > > > > correctly. > > > > > > > > > > > > > > > > > > I think if we start to protect > > > > > > > > > > > > > > > > > > dev->name by lock we need to do it for > > > > > > > > > > > > > > > > > > all instances (both read and > > > > > write). > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Since under the ownership rules, the > > > > > > > > > > > > > > > > > user must take ownership > > > > > > > > > > of a > > > > > > > > > > > > > > > > > port > > > > > > > > > > > > > > > > before using it, I still don't see a proble= m here. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I am not talking about owner id or name her= e. > > > > > > > > > > > > > > > > I am talking about dev->name. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > So? The user still should take ownership of > > > > > > > > > > > > > > > a device before using it > > > > > > > > > > (by > > > > > > > > > > > > > > name or by port id). > > > > > > > > > > > > > > > It can just read it without owning it, but no > managing it. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Please, Can you describe specific crash > > > > > > > > > > > > > > > > > scenario and explain how could the > > > > > > > > > > > > > > > > locking fix it? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Let say thread 0 doing > > > > > > > > > > > > > > > > rte_eth_dev_allocate()- > > > > > > > > > > > > > > > > >snprintf(rte_eth_dev_data[x].name, ...), > > > > > > > > > > > > > > > > >thread 1 doing > > > > > > > > > > > > > > > > rte_pmd_ring_remove()->rte_eth_dev_allocat > > > > > > > > > > > > > > > > ed() > > > > > > > > > > > > > > > > - > > > > > > > > >strcmp(). > > > > > > > > > > > > > > > > And because of race condition - > > > > > > > > > > > > > > > > rte_eth_dev_allocated() will > > > > > > > > > > return > > > > > > > > > > > > > > > > rte_eth_dev * for the wrong device. > > > > > > > > > > > > > > > Which wrong device do you mean? I guess it > > > > > > > > > > > > > > > is the device which > > > > > > > > > > > > currently is > > > > > > > > > > > > > > being created by thread 0. > > > > > > > > > > > > > > > > Then rte_pmd_ring_remove() will call > > > > > > > > > > > > > > > > rte_free() for related resources, while It > > > > > > > > > > > > > > > > can still be in use by someone > > > > > > > else. > > > > > > > > > > > > > > > The rte_pmd_ring_remove caller(some DPDK > > > > > > > > > > > > > > > entity) must take > > > > > > > > > > > > ownership > > > > > > > > > > > > > > > (or validate that he is the owner) of a port > > > > > > > > > > > > > > > before doing it(free, > > > > > > > > > > > > release), so > > > > > > > > > > > > > > no issue here. > > > > > > > > > > > > > > > > > > > > > > > > > > > > Forget about ownership for a second. > > > > > > > > > > > > > > Suppose we have a process it created ring port > > > > > > > > > > > > > > for itself (without > > > > > > > > > > setting > > > > > > > > > > > > any > > > > > > > > > > > > > > ownership) and used it for some time. > > > > > > > > > > > > > > Then it decided to remove it, so it calls > > > > > > > > > > > > > > rte_pmd_ring_remove() > > > > > > > > for it. > > > > > > > > > > > > > > At the same time second process decides to > > > > > > > > > > > > > > call > > > > > > > > > > rte_eth_dev_allocate() > > > > > > > > > > > > (let > > > > > > > > > > > > > > say for anither ring port). > > > > > > > > > > > > > > They could collide trying to read (process 0) > > > > > > > > > > > > > > and modify (process 1) > > > > > > > > > > same > > > > > > > > > > > > > > string rte_eth_dev_data[].name. > > > > > > > > > > > > > > > > > > > > > > > > > > > Do you mean that process 0 will compare > > > > > > > > > > > > > successfully the process 1 > > > > > > > > > > new > > > > > > > > > > > > port name? > > > > > > > > > > > > > > > > > > > > > > > > Yes. > > > > > > > > > > > > > > > > > > > > > > > > > The state are in local process memory - so > > > > > > > > > > > > > process 0 will not compare > > > > > > > > > > the > > > > > > > > > > > > process 1 port, from its point of view this port > > > > > > > > > > > > is in UNUSED > > > > > > > > > > > > > state. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Ok, and why it can't be in attached state in proces= s 0 too? > > > > > > > > > > > > > > > > > > > > > > Someone in process 0 should attach it using > > > > > > > > > > > protected attach_secondary > > > > > > > > > > somewhere in your scenario. > > > > > > > > > > > > > > > > > > > > Yes, process 0 can have this port attached too, why not= ? > > > > > > > > > See the function with inline comments: > > > > > > > > > > > > > > > > > > struct rte_eth_dev * > > > > > > > > > rte_eth_dev_allocated(const char *name) { > > > > > > > > > unsigned i; > > > > > > > > > > > > > > > > > > for (i =3D 0; i < RTE_MAX_ETHPORTS; i++) { > > > > > > > > > > > > > > > > > > The below state are in local process memory, > > > > > > > > > So, if here process 1 will allocate a new port (the > > > > > > > > > current i), > > > > > > > > update its local state to ATTACHED and write the name, > > > > > > > > > the state is not visible by process 0 until someone in > > > > > > > > > process > > > > > > > > 0 will attach it by rte_eth_dev_attach_secondary. > > > > > > > > > So, to use rte_eth_dev_attach_secondary process 0 > > > must > > > > > > > > take the lock > > > > > > > > > and it can't, because it is currently locked by process 1= . > > > > > > > > > > > > > > > > Ok I see. > > > > > > > > Thanks for your patience. > > > > > > > > BTW, that means that if let say process 0 will call > > > > > > > > rte_eth_dev_allocate("xxx") and process 1 will call > > > > > > > > rte_eth_dev_allocate("yyy") we can endup with same port_id > > > > > > > > be used for different devices and 2 processes will > > > > > > > > overwrite the same > > > > > > > rte_eth_dev_data[port_id]? > > > > > > > > > > > > > > No, contrary to the state, the lock itself is in shared > > > > > > > memory, so 2 processes cannot allocate port in the same > > > > > > > time.(you can see it in the next patch of this series). > > > > > > > > > > I am not talking about racing here. > > > > > Let say process 0 calls rte_pmd_ring_probe()->....- > > > > > >rte_eth_dev_allocate("xxx") > > > > > rte_eth_dev_allocate() finds that port N is 'free', i.e. > > > > > local rte_eth_devices[N].state =3D=3D RTE_ETH_DEV_UNUSED so it > > > > > assigns new dev ("xxx") to port N. > > > > > Then after some time process 1 calls rte_pmd_ring_probe()->....- > > > > > >rte_eth_dev_allocate("yyy"). > > > > > From its perspective port N is still free: > > > > > rte_eth_devices[N].state =3D=3D RTE_ETH_DEV_UNUSED, so it will > > > > > assign new dev ("yyy") to the same > > > port. > > > > > > > > > > > > > Yes you right, this is a problem(not related actually to port > > > > ownership) > > > > > > Yep that's true - it was there before your patches. > > > > > > > but look: > > > > As I understand the secondary processes are not allowed to create > > > > a ports and they must to use attach_secondary API, but there is > > > > not > > > hardcoded check which prevent them to do it. > > > > > > Secondary processes ae the ability to allocate their own vdevs and > > > probably it should stay like that. > > > I just thought it is a good opportunity to fix it while you are on > > > these changes anyway, but ok we can leave it for now. > > > > > Looks like the fix should break ABI(moving the state to the shared > > memory), let's try to fix it in the next version :) >=20 > Not necessarily - I think we can just add a check inside > te_eth_dev_find_free_port() that rte_eth_dev_data[port_id].name is an > empty string. Good idea, I will add it (actually the first patch in this series allows it= ). Thanks. > Konstantin >=20 >=20 > > > > > Konstantin