From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 7B50929D2 for ; Fri, 1 Apr 2016 13:31:00 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 01 Apr 2016 04:30:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,427,1455004800"; d="scan'208";a="936197059" Received: from irsmsx104.ger.corp.intel.com ([163.33.3.159]) by fmsmga001.fm.intel.com with ESMTP; 01 Apr 2016 04:30:55 -0700 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.174]) by IRSMSX104.ger.corp.intel.com ([169.254.5.87]) with mapi id 14.03.0248.002; Fri, 1 Apr 2016 12:30:55 +0100 From: "Burakov, Anatoly" To: Mauricio Vasquez B CC: "dev@dpdk.org" Thread-Topic: [PATCH v2] ivshmem: fix race condition Thread-Index: AQHRjAjfCiCHs9uIr0Owsd/sxEQZ7Z90+zbA Date: Fri, 1 Apr 2016 11:30:55 +0000 Message-ID: References: <1459498608-10789-1-git-send-email-mauricio.vasquezbernal@studenti.polito.it> <1459509732-22664-1-git-send-email-mauricio.vasquezbernal@studenti.polito.it> In-Reply-To: <1459509732-22664-1-git-send-email-mauricio.vasquezbernal@studenti.polito.it> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNWE1NDMyMDUtNGZmYy00M2QyLThhM2QtNzcwZjIzMDRmNTQ1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IjBvXC9LNHpnZUhWTjgyc2dGaitldXdMeXlrQXpZUmtWMThIRzZ3RGxRWDdzPSJ9 x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2] ivshmem: fix race condition 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: Fri, 01 Apr 2016 11:31:00 -0000 > The memory zone could be freed just after adding it to the metadata > file and just before marking it as not freeable. > This patch changes the locking logic in order to prevent it. >=20 > Fixes: cd10c42eb5bc ("mem: fix ivshmem freeing") >=20 > Signed-off-by: Mauricio Vasquez B > > --- > lib/librte_ivshmem/rte_ivshmem.c | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) >=20 > diff --git a/lib/librte_ivshmem/rte_ivshmem.c > b/lib/librte_ivshmem/rte_ivshmem.c > index 8fc4b57..013c3eb 100644 > --- a/lib/librte_ivshmem/rte_ivshmem.c > +++ b/lib/librte_ivshmem/rte_ivshmem.c > @@ -471,10 +471,21 @@ add_memzone_to_metadata(const struct > rte_memzone * mz, > struct ivshmem_config * config) > { > struct rte_ivshmem_metadata_entry * entry; > - unsigned i; > + unsigned i, idx; > + struct rte_mem_config *mcfg; > + > + if(mz->len =3D=3D 0) { > + RTE_LOG(ERR, EAL, "Trying to add an empty memzone\n"); > + return -1; > + } >=20 > rte_spinlock_lock(&config->sl); >=20 > + mcfg =3D rte_eal_get_configuration()->mem_config; > + > + /* it prevents the memzone being freed while we add it to the > metadata */ > + rte_rwlock_write_lock(&mcfg->mlock); > + > /* find free slot in this config */ > for (i =3D 0; i < RTE_DIM(config->metadata->entry); i++) { > entry =3D &config->metadata->entry[i]; > @@ -504,13 +515,6 @@ add_memzone_to_metadata(const struct > rte_memzone * mz, > config->metadata->name); > goto fail; > } > -#ifdef RTE_LIBRTE_IVSHMEM > - struct rte_mem_config *mcfg; > - unsigned int idx; > - > - mcfg =3D rte_eal_get_configuration()->mem_config; > - > - rte_rwlock_write_lock(&mcfg->mlock); >=20 > idx =3D ((uintptr_t)mz - (uintptr_t)mcfg->memzone); > idx =3D idx / sizeof(struct rte_memzone); > @@ -519,10 +523,10 @@ add_memzone_to_metadata(const struct > rte_memzone * mz, > mcfg->memzone[idx].ioremap_addr =3D mz->phys_addr; >=20 > rte_rwlock_write_unlock(&mcfg->mlock); > -#endif > rte_spinlock_unlock(&config->sl); > return 0; > fail: > + rte_rwlock_write_unlock(&mcfg->mlock); > rte_spinlock_unlock(&config->sl); > return -1; > } > -- > 1.9.1 Acked-by: Anatoly Burakov