netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2-next] tc: mqprio: reject queues count/offset pair count higher than num_tc
@ 2020-05-13 19:47 Maciej Fijalkowski
  2020-05-14  0:47 ` Stephen Hemminger
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Maciej Fijalkowski @ 2020-05-13 19:47 UTC (permalink / raw)
  To: dsahern, stephen; +Cc: netdev, kiran.patil, Maciej Fijalkowski

Provide a sanity check that will make sure whether queues count/offset
pair count will not exceed the actual number of TCs being created.

Example command that is invalid because there are 4 count/offset pairs
whereas num_tc is only 2.

 # tc qdisc add dev enp96s0f0 root mqprio num_tc 2 map 0 0 0 0 1 1 1 1
queues 4@0 4@4 4@8 4@12 hw 1 mode channel

Store the parsed count/offset pair count onto a dedicated variable that
will be compared against opt.num_tc after all of the command line
arguments were parsed. Bail out if this count is higher than opt.num_tc
and let user know about it.

Drivers were swallowing such commands as they were iterating over
count/offset pairs where num_tc was used as a delimiter, so this is not
a big deal, but better catch such misconfiguration at the command line
argument parsing level.

Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
 tc/q_mqprio.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tc/q_mqprio.c b/tc/q_mqprio.c
index 0eb41308..f26ba8d7 100644
--- a/tc/q_mqprio.c
+++ b/tc/q_mqprio.c
@@ -48,6 +48,7 @@ static int mqprio_parse_opt(struct qdisc_util *qu, int argc,
 	__u64 max_rate64[TC_QOPT_MAX_QUEUE] = {0};
 	__u16 shaper = TC_MQPRIO_SHAPER_DCB;
 	__u16 mode = TC_MQPRIO_MODE_DCB;
+	int cnt_off_pairs = 0;
 	struct rtattr *tail;
 	__u32 flags = 0;
 
@@ -94,6 +95,7 @@ static int mqprio_parse_opt(struct qdisc_util *qu, int argc,
 				}
 				free(tmp);
 				idx++;
+				cnt_off_pairs++;
 			}
 		} else if (strcmp(*argv, "hw") == 0) {
 			NEXT_ARG();
@@ -173,6 +175,12 @@ static int mqprio_parse_opt(struct qdisc_util *qu, int argc,
 		argc--; argv++;
 	}
 
+	if (cnt_off_pairs > opt.num_tc) {
+		fprintf(stderr, "queues count/offset pair count %d can not be higher than given num_tc %d\n",
+			cnt_off_pairs, opt.num_tc);
+		return -1;
+	}
+
 	tail = NLMSG_TAIL(n);
 	addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2-next] tc: mqprio: reject queues count/offset pair count higher than num_tc
  2020-05-13 19:47 [PATCH iproute2-next] tc: mqprio: reject queues count/offset pair count higher than num_tc Maciej Fijalkowski
@ 2020-05-14  0:47 ` Stephen Hemminger
  2020-05-18 14:59 ` David Ahern
  2020-05-18 15:08 ` Stephen Hemminger
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2020-05-14  0:47 UTC (permalink / raw)
  To: Maciej Fijalkowski; +Cc: dsahern, netdev, kiran.patil

On Wed, 13 May 2020 21:47:17 +0200
Maciej Fijalkowski <maciej.fijalkowski@intel.com> wrote:

> Provide a sanity check that will make sure whether queues count/offset
> pair count will not exceed the actual number of TCs being created.
> 
> Example command that is invalid because there are 4 count/offset pairs
> whereas num_tc is only 2.
> 
>  # tc qdisc add dev enp96s0f0 root mqprio num_tc 2 map 0 0 0 0 1 1 1 1
> queues 4@0 4@4 4@8 4@12 hw 1 mode channel
> 
> Store the parsed count/offset pair count onto a dedicated variable that
> will be compared against opt.num_tc after all of the command line
> arguments were parsed. Bail out if this count is higher than opt.num_tc
> and let user know about it.
> 
> Drivers were swallowing such commands as they were iterating over
> count/offset pairs where num_tc was used as a delimiter, so this is not
> a big deal, but better catch such misconfiguration at the command line
> argument parsing level.
> 
> Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>

This doesn't have to wait for iproute2-next.
Can pick it up on the master side (after review).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2-next] tc: mqprio: reject queues count/offset pair count higher than num_tc
  2020-05-13 19:47 [PATCH iproute2-next] tc: mqprio: reject queues count/offset pair count higher than num_tc Maciej Fijalkowski
  2020-05-14  0:47 ` Stephen Hemminger
@ 2020-05-18 14:59 ` David Ahern
  2020-05-18 15:08 ` Stephen Hemminger
  2 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2020-05-18 14:59 UTC (permalink / raw)
  To: Maciej Fijalkowski, stephen; +Cc: netdev, kiran.patil

On 5/13/20 1:47 PM, Maciej Fijalkowski wrote:
> Provide a sanity check that will make sure whether queues count/offset
> pair count will not exceed the actual number of TCs being created.
> 
> Example command that is invalid because there are 4 count/offset pairs
> whereas num_tc is only 2.
> 
>  # tc qdisc add dev enp96s0f0 root mqprio num_tc 2 map 0 0 0 0 1 1 1 1
> queues 4@0 4@4 4@8 4@12 hw 1 mode channel
> 
> Store the parsed count/offset pair count onto a dedicated variable that
> will be compared against opt.num_tc after all of the command line
> arguments were parsed. Bail out if this count is higher than opt.num_tc
> and let user know about it.
> 
> Drivers were swallowing such commands as they were iterating over
> count/offset pairs where num_tc was used as a delimiter, so this is not
> a big deal, but better catch such misconfiguration at the command line
> argument parsing level.
> 
> Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> ---
>  tc/q_mqprio.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
\

applied to iproute2-next. Thanks,


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2-next] tc: mqprio: reject queues count/offset pair count higher than num_tc
  2020-05-13 19:47 [PATCH iproute2-next] tc: mqprio: reject queues count/offset pair count higher than num_tc Maciej Fijalkowski
  2020-05-14  0:47 ` Stephen Hemminger
  2020-05-18 14:59 ` David Ahern
@ 2020-05-18 15:08 ` Stephen Hemminger
  2020-05-18 15:12   ` David Ahern
  2 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2020-05-18 15:08 UTC (permalink / raw)
  To: Maciej Fijalkowski; +Cc: dsahern, netdev, kiran.patil

On Wed, 13 May 2020 21:47:17 +0200
Maciej Fijalkowski <maciej.fijalkowski@intel.com> wrote:

> Provide a sanity check that will make sure whether queues count/offset
> pair count will not exceed the actual number of TCs being created.
> 
> Example command that is invalid because there are 4 count/offset pairs
> whereas num_tc is only 2.
> 
>  # tc qdisc add dev enp96s0f0 root mqprio num_tc 2 map 0 0 0 0 1 1 1 1
> queues 4@0 4@4 4@8 4@12 hw 1 mode channel
> 
> Store the parsed count/offset pair count onto a dedicated variable that
> will be compared against opt.num_tc after all of the command line
> arguments were parsed. Bail out if this count is higher than opt.num_tc
> and let user know about it.
> 
> Drivers were swallowing such commands as they were iterating over
> count/offset pairs where num_tc was used as a delimiter, so this is not
> a big deal, but better catch such misconfiguration at the command line
> argument parsing level.
> 
> Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> ---
>  tc/q_mqprio.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/tc/q_mqprio.c b/tc/q_mqprio.c
> index 0eb41308..f26ba8d7 100644
> --- a/tc/q_mqprio.c
> +++ b/tc/q_mqprio.c
> @@ -48,6 +48,7 @@ static int mqprio_parse_opt(struct qdisc_util *qu, int argc,
>  	__u64 max_rate64[TC_QOPT_MAX_QUEUE] = {0};
>  	__u16 shaper = TC_MQPRIO_SHAPER_DCB;
>  	__u16 mode = TC_MQPRIO_MODE_DCB;
> +	int cnt_off_pairs = 0;

Since opt.num_tc is u8, shouldn't this be u8 as well?
Note: maximum number of queue is TC_QOPT_MAX_QUEUE (16).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2-next] tc: mqprio: reject queues count/offset pair count higher than num_tc
  2020-05-18 15:08 ` Stephen Hemminger
@ 2020-05-18 15:12   ` David Ahern
  0 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2020-05-18 15:12 UTC (permalink / raw)
  To: Stephen Hemminger, Maciej Fijalkowski; +Cc: netdev, kiran.patil

On 5/18/20 9:08 AM, Stephen Hemminger wrote:
> On Wed, 13 May 2020 21:47:17 +0200
> Maciej Fijalkowski <maciej.fijalkowski@intel.com> wrote:
> 
>> Provide a sanity check that will make sure whether queues count/offset
>> pair count will not exceed the actual number of TCs being created.
>>
>> Example command that is invalid because there are 4 count/offset pairs
>> whereas num_tc is only 2.
>>
>>  # tc qdisc add dev enp96s0f0 root mqprio num_tc 2 map 0 0 0 0 1 1 1 1
>> queues 4@0 4@4 4@8 4@12 hw 1 mode channel
>>
>> Store the parsed count/offset pair count onto a dedicated variable that
>> will be compared against opt.num_tc after all of the command line
>> arguments were parsed. Bail out if this count is higher than opt.num_tc
>> and let user know about it.
>>
>> Drivers were swallowing such commands as they were iterating over
>> count/offset pairs where num_tc was used as a delimiter, so this is not
>> a big deal, but better catch such misconfiguration at the command line
>> argument parsing level.
>>
>> Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
>> ---
>>  tc/q_mqprio.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/tc/q_mqprio.c b/tc/q_mqprio.c
>> index 0eb41308..f26ba8d7 100644
>> --- a/tc/q_mqprio.c
>> +++ b/tc/q_mqprio.c
>> @@ -48,6 +48,7 @@ static int mqprio_parse_opt(struct qdisc_util *qu, int argc,
>>  	__u64 max_rate64[TC_QOPT_MAX_QUEUE] = {0};
>>  	__u16 shaper = TC_MQPRIO_SHAPER_DCB;
>>  	__u16 mode = TC_MQPRIO_MODE_DCB;
>> +	int cnt_off_pairs = 0;
> 
> Since opt.num_tc is u8, shouldn't this be u8 as well?
> Note: maximum number of queue is TC_QOPT_MAX_QUEUE (16).
> 

I was looking that as having cnt_off_pairs as an int makes for simpler
code - not having to detect rollover. But if there is a limit, I guess
that takes precedence.

And if there is a limit, perhaps that should be checked on num_tc parsing.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-18 15:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13 19:47 [PATCH iproute2-next] tc: mqprio: reject queues count/offset pair count higher than num_tc Maciej Fijalkowski
2020-05-14  0:47 ` Stephen Hemminger
2020-05-18 14:59 ` David Ahern
2020-05-18 15:08 ` Stephen Hemminger
2020-05-18 15:12   ` David Ahern

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).