* [dpdk-dev] [PATCH] usertools: check 0-division with hugepage size
@ 2021-02-11 22:05 Thomas Monjalon
2021-02-11 23:18 ` Stephen Hemminger
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Thomas Monjalon @ 2021-02-11 22:05 UTC (permalink / raw)
To: dev; +Cc: sarosh.arif, stephen
The default page size can be None, and the page size from user request
can be 0 kB if lower than 1024. In these cases, a division will fail.
In order to avoid a Python exception, the page size is checked
and an error message "Invalid page size" is printed.
A similar error message is printed in set_hugepages()
if the size is not supported, except at this stage the message can be
completed with "Valid page sizes".
Unfortunately the first check is too early to print such information.
A third error message can be printed in a different place (get_memsize)
in case of a format issue, e.g. a negative size.
The function get_memsize() is also used for total requested size,
so the error message "not a valid page size" was potentially wrong.
This message is replaced with the more general "is not a valid size".
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
usertools/dpdk-hugepages.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
index fb368b6933..c1f2549ec0 100755
--- a/usertools/dpdk-hugepages.py
+++ b/usertools/dpdk-hugepages.py
@@ -29,7 +29,7 @@ def get_memsize(arg):
'''Convert memory size with suffix to kB'''
match = re.match(r'(\d+)([' + BINARY_PREFIX + r']?)$', arg.upper())
if match is None:
- sys.exit('{} is not a valid page size'.format(arg))
+ sys.exit('{} is not a valid size'.format(arg))
num = float(match.group(1))
suffix = match.group(2)
if suffix == "":
@@ -254,6 +254,8 @@ def main():
pagesize_kb = get_memsize(args.pagesize)
else:
pagesize_kb = default_pagesize()
+ if pagesize_kb is None or pagesize_kb == 0:
+ sys.exit("Invalid page size: {}kB".format(pagesize_kb))
if args.clear:
clear_pages()
--
2.30.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH] usertools: check 0-division with hugepage size
2021-02-11 22:05 [dpdk-dev] [PATCH] usertools: check 0-division with hugepage size Thomas Monjalon
@ 2021-02-11 23:18 ` Stephen Hemminger
2021-02-12 11:27 ` Burakov, Anatoly
2021-03-21 9:09 ` [dpdk-dev] [PATCH v2] " Thomas Monjalon
2 siblings, 0 replies; 7+ messages in thread
From: Stephen Hemminger @ 2021-02-11 23:18 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: dev, sarosh.arif
On Thu, 11 Feb 2021 23:05:44 +0100
Thomas Monjalon <thomas@monjalon.net> wrote:
> The default page size can be None, and the page size from user request
> can be 0 kB if lower than 1024. In these cases, a division will fail.
> In order to avoid a Python exception, the page size is checked
> and an error message "Invalid page size" is printed.
>
> A similar error message is printed in set_hugepages()
> if the size is not supported, except at this stage the message can be
> completed with "Valid page sizes".
> Unfortunately the first check is too early to print such information.
>
> A third error message can be printed in a different place (get_memsize)
> in case of a format issue, e.g. a negative size.
> The function get_memsize() is also used for total requested size,
> so the error message "not a valid page size" was potentially wrong.
> This message is replaced with the more general "is not a valid size".
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH] usertools: check 0-division with hugepage size
2021-02-11 22:05 [dpdk-dev] [PATCH] usertools: check 0-division with hugepage size Thomas Monjalon
2021-02-11 23:18 ` Stephen Hemminger
@ 2021-02-12 11:27 ` Burakov, Anatoly
2021-02-12 11:34 ` Thomas Monjalon
2021-03-21 9:09 ` [dpdk-dev] [PATCH v2] " Thomas Monjalon
2 siblings, 1 reply; 7+ messages in thread
From: Burakov, Anatoly @ 2021-02-12 11:27 UTC (permalink / raw)
To: Thomas Monjalon, dev; +Cc: sarosh.arif, stephen
On 11-Feb-21 10:05 PM, Thomas Monjalon wrote:
> The default page size can be None, and the page size from user request
> can be 0 kB if lower than 1024. In these cases, a division will fail.
> In order to avoid a Python exception, the page size is checked
> and an error message "Invalid page size" is printed.
>
> A similar error message is printed in set_hugepages()
> if the size is not supported, except at this stage the message can be
> completed with "Valid page sizes".
> Unfortunately the first check is too early to print such information.
>
> A third error message can be printed in a different place (get_memsize)
> in case of a format issue, e.g. a negative size.
> The function get_memsize() is also used for total requested size,
> so the error message "not a valid page size" was potentially wrong.
> This message is replaced with the more general "is not a valid size".
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
> usertools/dpdk-hugepages.py | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
> index fb368b6933..c1f2549ec0 100755
> --- a/usertools/dpdk-hugepages.py
> +++ b/usertools/dpdk-hugepages.py
> @@ -29,7 +29,7 @@ def get_memsize(arg):
> '''Convert memory size with suffix to kB'''
> match = re.match(r'(\d+)([' + BINARY_PREFIX + r']?)$', arg.upper())
> if match is None:
> - sys.exit('{} is not a valid page size'.format(arg))
> + sys.exit('{} is not a valid size'.format(arg))
> num = float(match.group(1))
> suffix = match.group(2)
> if suffix == "":
> @@ -254,6 +254,8 @@ def main():
> pagesize_kb = get_memsize(args.pagesize)
> else:
> pagesize_kb = default_pagesize()
> + if pagesize_kb is None or pagesize_kb == 0:
> + sys.exit("Invalid page size: {}kB".format(pagesize_kb))
Both None and 0 evaluate to False for boolean comparisons, so you can
replace it with:
if not pagesize_kb:
sys.exit(...)
>
> if args.clear:
> clear_pages()
>
--
Thanks,
Anatoly
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH] usertools: check 0-division with hugepage size
2021-02-12 11:27 ` Burakov, Anatoly
@ 2021-02-12 11:34 ` Thomas Monjalon
0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2021-02-12 11:34 UTC (permalink / raw)
To: Burakov, Anatoly; +Cc: dev, sarosh.arif, stephen
12/02/2021 12:27, Burakov, Anatoly:
> On 11-Feb-21 10:05 PM, Thomas Monjalon wrote:
> > The default page size can be None, and the page size from user request
> > can be 0 kB if lower than 1024. In these cases, a division will fail.
> > In order to avoid a Python exception, the page size is checked
> > and an error message "Invalid page size" is printed.
> >
> > A similar error message is printed in set_hugepages()
> > if the size is not supported, except at this stage the message can be
> > completed with "Valid page sizes".
> > Unfortunately the first check is too early to print such information.
> >
> > A third error message can be printed in a different place (get_memsize)
> > in case of a format issue, e.g. a negative size.
> > The function get_memsize() is also used for total requested size,
> > so the error message "not a valid page size" was potentially wrong.
> > This message is replaced with the more general "is not a valid size".
> >
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > ---
> > @@ -254,6 +254,8 @@ def main():
> > pagesize_kb = get_memsize(args.pagesize)
> > else:
> > pagesize_kb = default_pagesize()
> > + if pagesize_kb is None or pagesize_kb == 0:
> > + sys.exit("Invalid page size: {}kB".format(pagesize_kb))
>
> Both None and 0 evaluate to False for boolean comparisons, so you can
> replace it with:
>
> if not pagesize_kb:
> sys.exit(...)
Oh yes better :)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [dpdk-dev] [PATCH v2] usertools: check 0-division with hugepage size
2021-02-11 22:05 [dpdk-dev] [PATCH] usertools: check 0-division with hugepage size Thomas Monjalon
2021-02-11 23:18 ` Stephen Hemminger
2021-02-12 11:27 ` Burakov, Anatoly
@ 2021-03-21 9:09 ` Thomas Monjalon
2021-03-23 11:30 ` Burakov, Anatoly
2 siblings, 1 reply; 7+ messages in thread
From: Thomas Monjalon @ 2021-03-21 9:09 UTC (permalink / raw)
To: dev; +Cc: sarosh.arif, anatoly.burakov, Stephen Hemminger
The default page size can be None, and the page size from user request
can be 0 kB if lower than 1024. In these cases, a division will fail.
In order to avoid a Python exception, the page size is checked
and an error message "Invalid page size" is printed.
A similar error message is printed in set_hugepages()
if the size is not supported, except at this stage the message can be
completed with "Valid page sizes".
Unfortunately the first check is too early to print such information.
A third error message can be printed in a different place (get_memsize)
in case of a format issue, e.g. a negative size.
The function get_memsize() is also used for total requested size,
so the error message "not a valid page size" was potentially wrong.
This message is replaced with the more general "is not a valid size".
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
v2: use simple "if not" construct for both None and 0
---
usertools/dpdk-hugepages.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
index fb368b6933..db141b3efa 100755
--- a/usertools/dpdk-hugepages.py
+++ b/usertools/dpdk-hugepages.py
@@ -29,7 +29,7 @@ def get_memsize(arg):
'''Convert memory size with suffix to kB'''
match = re.match(r'(\d+)([' + BINARY_PREFIX + r']?)$', arg.upper())
if match is None:
- sys.exit('{} is not a valid page size'.format(arg))
+ sys.exit('{} is not a valid size'.format(arg))
num = float(match.group(1))
suffix = match.group(2)
if suffix == "":
@@ -254,6 +254,8 @@ def main():
pagesize_kb = get_memsize(args.pagesize)
else:
pagesize_kb = default_pagesize()
+ if not pagesize_kb:
+ sys.exit("Invalid page size: {}kB".format(pagesize_kb))
if args.clear:
clear_pages()
--
2.30.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH v2] usertools: check 0-division with hugepage size
2021-03-21 9:09 ` [dpdk-dev] [PATCH v2] " Thomas Monjalon
@ 2021-03-23 11:30 ` Burakov, Anatoly
2021-03-25 17:04 ` Thomas Monjalon
0 siblings, 1 reply; 7+ messages in thread
From: Burakov, Anatoly @ 2021-03-23 11:30 UTC (permalink / raw)
To: Thomas Monjalon, dev; +Cc: sarosh.arif, Stephen Hemminger
On 21-Mar-21 9:09 AM, Thomas Monjalon wrote:
> The default page size can be None, and the page size from user request
> can be 0 kB if lower than 1024. In these cases, a division will fail.
> In order to avoid a Python exception, the page size is checked
> and an error message "Invalid page size" is printed.
>
> A similar error message is printed in set_hugepages()
> if the size is not supported, except at this stage the message can be
> completed with "Valid page sizes".
> Unfortunately the first check is too early to print such information.
>
> A third error message can be printed in a different place (get_memsize)
> in case of a format issue, e.g. a negative size.
> The function get_memsize() is also used for total requested size,
> so the error message "not a valid page size" was potentially wrong.
> This message is replaced with the more general "is not a valid size".
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> v2: use simple "if not" construct for both None and 0
> ---
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
--
Thanks,
Anatoly
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH v2] usertools: check 0-division with hugepage size
2021-03-23 11:30 ` Burakov, Anatoly
@ 2021-03-25 17:04 ` Thomas Monjalon
0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2021-03-25 17:04 UTC (permalink / raw)
To: dev; +Cc: sarosh.arif, Stephen Hemminger, Burakov, Anatoly
23/03/2021 12:30, Burakov, Anatoly:
> On 21-Mar-21 9:09 AM, Thomas Monjalon wrote:
> > The default page size can be None, and the page size from user request
> > can be 0 kB if lower than 1024. In these cases, a division will fail.
> > In order to avoid a Python exception, the page size is checked
> > and an error message "Invalid page size" is printed.
> >
> > A similar error message is printed in set_hugepages()
> > if the size is not supported, except at this stage the message can be
> > completed with "Valid page sizes".
> > Unfortunately the first check is too early to print such information.
> >
> > A third error message can be printed in a different place (get_memsize)
> > in case of a format issue, e.g. a negative size.
> > The function get_memsize() is also used for total requested size,
> > so the error message "not a valid page size" was potentially wrong.
> > This message is replaced with the more general "is not a valid size".
> >
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> > v2: use simple "if not" construct for both None and 0
> > ---
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Applied
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-03-25 17:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-11 22:05 [dpdk-dev] [PATCH] usertools: check 0-division with hugepage size Thomas Monjalon
2021-02-11 23:18 ` Stephen Hemminger
2021-02-12 11:27 ` Burakov, Anatoly
2021-02-12 11:34 ` Thomas Monjalon
2021-03-21 9:09 ` [dpdk-dev] [PATCH v2] " Thomas Monjalon
2021-03-23 11:30 ` Burakov, Anatoly
2021-03-25 17:04 ` Thomas Monjalon
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).