From: Thomas Monjalon <thomas@monjalon.net>
To: "Morten Brørup" <mb@smartsharesystems.com>,
"Stephen Hemminger" <stephen@networkplumber.org>
Cc: Tyler Retzlaff <roretzla@linux.microsoft.com>,
Anatoly Burakov <anatoly.burakov@intel.com>,
Bruce Richardson <bruce.richardson@intel.com>,
Maxime Coquelin <maxime.coquelin@redhat.com>,
Chenbo Xia <chenbox@nvidia.com>,
Tomasz Duszynski <tduszynski@marvell.com>,
dev@dpdk.org
Subject: Re: [PATCH v3 2/3] eal: handle sysconf(_SC_PAGESIZE) negative return value
Date: Sun, 29 Jun 2025 14:10:55 +0200 [thread overview]
Message-ID: <4900019.7x91mkYCy2@thomas> (raw)
In-Reply-To: <20250628154927.6161b011@hermes.local>
29/06/2025 00:49, Stephen Hemminger:
> On Sat, 28 Jun 2025 18:45:44 +0200
> Morten Brørup <mb@smartsharesystems.com> wrote:
>
> > > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > > Sent: Friday, 27 June 2025 20.30
> > >
> > > 27/06/2025 19:49, Morten Brørup:
> > > > > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > > > > Sent: Friday, 27 June 2025 19.35
> > > > >
> > > > > 27/06/2025 18:38, Morten Brørup:
> > > > > > > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > > > > > > Sent: Friday, 27 June 2025 17.58
> > > > > > >
> > > > > > > 24/06/2025 10:03, Morten Brørup:
> > > > > > > > + if ((ssize_t)page_size < 0)
> > > > > > > > + rte_panic("sysconf(_SC_PAGESIZE) failed: %s",
> > > > > > > > + errno == 0 ? "Indeterminate" :
> > > > > > > strerror(errno));
> > > > > > >
> > > > > > > We don't want more rte_panic().
> > > > > > > You could log the problem and return 0 here.
> > > > > > > It will be a problem later, but it may allow the application to
> > > > > cleanup
> > > > > > > instead of abrupting crashing.
> > > > > >
> > > > > > Disagree.
> > > > > > That would be likely to cause crash with division by zero later.
> > > > > > Better to fail early.
> > > > >
> > > > > Which division by zero?
> > > >
> > > > Functions dividing by page size. E.g.:
> > > >
> > > https://elixir.bootlin.com/dpdk/v25.03/source/lib/eal/common/eal_common_
> > > memory.c#L313
> > > >
> > > > >
> > > > > I don't think a library should take this decision on behalf of the
> > > app.
> > > >
> > > > I expect lots of things to break if sysconf(_SC_PAGESIZE) fails, so
> > > the purpose of this patch is to centralize error handling here, and only
> > > continue/return with non-failing values.
> > > >
> > > > Otherwise, everywhere using rte_mem_page_size() or
> > > sysconf(_SC_PAGESIZE) should implement error handling (or ignore
> > > errors).
> > > > That's a lot of places, so I'm not going to provide a patch doing
> > > that.
> > >
> > > I understand.
> > >
> > > The problem is that we don't have an exception mechanism in this
> > > language.
> >
> > Yep.
> > And everyone assumes sysconf(_SC_PAGESIZE) never fails, which is probably correct, so nobody implemented error handling for it. Not even in rte_mem_page_size().
> > Coverity detected the missing error handling, and warns: "Although rte_mem_page_size() is declared to return unsigned int, it may actually return a negative value." This defect applies to all functions calling rte_mem_page_size().
> > This patch adds error handling to ensure that rte_mem_page_size() only returns non-negative values, or doesn’t return at all - i.e. fails with rte_panic() - so Coverity is satisfied with callers not implementing error handling for it.
> >
> > It would be borderline waste of time fixing all the callers, so I fixed the root cause to satisfy Coverity.
> >
> > From an higher level perspective:
> > This is a low level EAL function to determine the page size. I would consider it reasonable for such a low level EAL function to never fail.
> > If some O/S decides to not have a "system page size", and fail with "Indeterminate", e.g. to support multiple page sizes, we would need to handle that somehow. But let's ignore that until it actually happens, if ever.
> >
> > If you are skeptical about this patch 2/3 in the series, we can escalate the discussion to the tech board. If you really hate this patch 2/3, I will honor a NAK from you. The patch is not important for me; I'm just trying to clean up.
> >
>
> In such cases, I look at glibc source and see if handles it or not.
> Looks like only used a couple of places there, the result of sysconf(_SC_PAGE_SIZE) is checked
> in one of the tests; but is not checked in the loading of locale's. It expects a valid power of 2
> value there.
>
> Ok to just die if value isn't valid.
Yes I'm convinced too.
next prev parent reply other threads:[~2025-06-29 12:11 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 13:13 [PATCH] eal: handle sysconf() negative return value Morten Brørup
2025-06-12 14:06 ` [PATCH v2] eal: handle sysconf(_SC_PAGESIZE) " Morten Brørup
2025-06-13 9:55 ` Burakov, Anatoly
2025-06-24 8:03 ` [PATCH v3 0/3] " Morten Brørup
2025-06-24 8:03 ` [PATCH v3 1/3] eal/unix: fix log message for madvise() failure Morten Brørup
2025-06-27 15:56 ` Thomas Monjalon
2025-06-27 16:47 ` Morten Brørup
2025-06-27 17:34 ` Thomas Monjalon
2025-06-27 17:51 ` Morten Brørup
2025-06-28 10:11 ` Morten Brørup
2025-06-24 8:03 ` [PATCH v3 2/3] eal: handle sysconf(_SC_PAGESIZE) negative return value Morten Brørup
2025-06-27 15:58 ` Thomas Monjalon
2025-06-27 16:38 ` Morten Brørup
2025-06-27 17:35 ` Thomas Monjalon
2025-06-27 17:49 ` Morten Brørup
2025-06-27 18:30 ` Thomas Monjalon
2025-06-28 16:45 ` Morten Brørup
2025-06-28 22:49 ` Stephen Hemminger
2025-06-29 12:10 ` Thomas Monjalon [this message]
2025-06-24 8:03 ` [PATCH v3 3/3] pmu: " Morten Brørup
2025-06-29 19:52 ` [PATCH v3 0/3] " 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=4900019.7x91mkYCy2@thomas \
--to=thomas@monjalon.net \
--cc=anatoly.burakov@intel.com \
--cc=bruce.richardson@intel.com \
--cc=chenbox@nvidia.com \
--cc=dev@dpdk.org \
--cc=maxime.coquelin@redhat.com \
--cc=mb@smartsharesystems.com \
--cc=roretzla@linux.microsoft.com \
--cc=stephen@networkplumber.org \
--cc=tduszynski@marvell.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.