From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Renata Saiakhova <renata.saiakhova@ekinops.com>,
"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH 1/2] librte_ethdev: Introduce a function to release HW rings
Date: Tue, 5 May 2020 14:36:01 +0100 [thread overview]
Message-ID: <6c68ac6d-b669-eb94-0347-36940eb32d43@intel.com> (raw)
In-Reply-To: <MRXP264MB0325B273A6185AAF5E64B59292A70@MRXP264MB0325.FRAP264.PROD.OUTLOOK.COM>
On 05-May-20 1:49 PM, Renata Saiakhova wrote:
> Hi Anatoly,
>
> thanks! The fact that memzone is found and matched only based on the
> name, could it create potential problem like the one I described besides
> HW rings?
Technically, yes, it could. However, at this point, we can't really do
anything. Memzones having names is both an advantage (less code to find
memory areas you're looking for) and a disadvantage (lots of ways to
shoot yourself in the foot *if* you have a habit of naming different
memzones with identical names... which our drivers apparently do!).
IMO, trying to fix it will lead us down the rabbit hole of, 1) check if
memzone exists, 2) check if it matches the requirements, and 3) handle
all possible conditions related to 1) and 2) (do the requirements match?
do they have to match *exactly*, or "this or bigger" will do? do we
throw an error if we detect mismatch? do we deallocate old memzone?). So
from our perspective, it is better to leave it up to the user, and just
ensure that our drivers do mostly sane things.
>
> Kind regards,
> Renata
> ------------------------------------------------------------------------
> *From:* Burakov, Anatoly <anatoly.burakov@intel.com>
> *Sent:* Tuesday, May 5, 2020 12:45 PM
> *To:* Renata Saiakhova <renata.saiakhova@ekinops.com>; dev@dpdk.org
> <dev@dpdk.org>
> *Subject:* Re: [dpdk-dev] [PATCH 1/2] librte_ethdev: Introduce a
> function to release HW rings
> On 05-May-20 11:25 AM, Burakov, Anatoly wrote:
>> On 03-May-20 5:26 PM, Renata Saiakhova wrote:
>>> Free previously allocated memzone for HW rings
>>>
>>> Signed-off-by: Renata Saiakhova <Renata.Saiakhova@ekinops.com>
>>> ---
>>> lib/librte_ethdev/rte_ethdev.c | 23 +++++++++++++++++++++++
>>> lib/librte_ethdev/rte_ethdev_driver.h | 14 ++++++++++++++
>>> lib/librte_ethdev/rte_ethdev_version.map | 1 +
>>> 3 files changed, 38 insertions(+)
>>>
>>> diff --git a/lib/librte_ethdev/rte_ethdev.c
>>> b/lib/librte_ethdev/rte_ethdev.c
>>> index 72aed59a5..c6d27e1aa 100644
>>> --- a/lib/librte_ethdev/rte_ethdev.c
>>> +++ b/lib/librte_ethdev/rte_ethdev.c
>>> @@ -4206,6 +4206,29 @@ rte_eth_dma_zone_reserve(const struct
>>> rte_eth_dev *dev, const char *ring_name,
>>> RTE_MEMZONE_IOVA_CONTIG, align);
>>> }
>>> +int
>>> +rte_eth_dma_zone_free(const struct rte_eth_dev *dev, const char
>>> *ring_name,
>>> + uint16_t queue_id)
>>> +{
>>> + char z_name[RTE_MEMZONE_NAMESIZE];
>>> + const struct rte_memzone *mz;
>>> + int rc = 0;
>>> +
>>> + snprintf(z_name, sizeof(z_name), "eth_p%d_q%d_%s",
>>> + dev->data->port_id, queue_id, ring_name);
>>> + if (rc >= RTE_MEMZONE_NAMESIZE) {
>>> + RTE_ETHDEV_LOG(ERR, "ring name too long\n");
>>> + rte_errno = ENAMETOOLONG;
>>> + return NULL;
>>> + }
>>> +
>>> + mz = rte_memzone_lookup(z_name);
>>> + if (mz)
>>> + rc = rte_memzone_free(mz);
>>
>> This is racy. Please just use rte_memzone_free() unconditionally. It'll
>> return 0 if memzone existed, or will set rte_errno to EINVAL if it
>> didn't. (this is suboptimal, it should be ENOENT, but changing this
>> would be an API break... I'll submit a patch for future release to fix
>> this)
>>
>
> My apologies, just using rte_memzone_free will not solve the problem
> because you don't have memzone pointer. Now that i think of it, the
> rte_eth_dma_zone_reserve() suffers from this issue too, and the problem
> is lack of atomic "find or create" memzone API.
>
> This patch is OK for now, as it follows similar code in
> rte_eth_dma_zone_reserve(), but ideally, this should be fixed at the
> memzone API level. I'll see if i can cobble together a quick patchset
> adding atomic "find or reserve" and "find and free" operations.
>
> --
> Thanks,
> Anatoly
--
Thanks,
Anatoly
next prev parent reply other threads:[~2020-05-05 13:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-03 16:26 [dpdk-dev] [PATCH 0/2] Memory corruption due to HW rings allocation Renata Saiakhova
2020-05-03 16:26 ` [dpdk-dev] [PATCH 1/2] librte_ethdev: Introduce a function to release HW rings Renata Saiakhova
2020-05-05 10:25 ` Burakov, Anatoly
2020-05-05 10:45 ` Burakov, Anatoly
2020-05-05 12:49 ` Renata Saiakhova
2020-05-05 13:36 ` Burakov, Anatoly [this message]
2020-05-05 15:47 ` Lukasz Wojciechowski
2020-05-05 17:25 ` Renata Saiakhova
2020-05-05 17:31 ` Lukasz Wojciechowski
2020-05-06 10:14 ` Burakov, Anatoly
2020-05-03 16:26 ` [dpdk-dev] [PATCH 2/2] drivers/net: Fix in e1000 and ixgbe HW rings memory overlap Renata Saiakhova
2020-05-05 10:28 ` Burakov, Anatoly
2020-05-05 10:59 ` Thomas Monjalon
2020-05-05 11:36 ` Burakov, Anatoly
2020-05-05 11:01 ` [dpdk-dev] [PATCH 0/2] Memory corruption due to HW rings allocation Thomas Monjalon
2020-05-05 11:19 ` Renata Saiakhova
2020-05-05 12:35 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6c68ac6d-b669-eb94-0347-36940eb32d43@intel.com \
--to=anatoly.burakov@intel.com \
--cc=dev@dpdk.org \
--cc=renata.saiakhova@ekinops.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).