2021-08-02 17:13:20

by Nicholas Richardson

[permalink] [raw]
Subject: [PATCH v2] pktgen: Fix invalid clone_skb override

From: Nick Richardson <[email protected]>

When the netif_receive xmit_mode is set, a line is supposed to set
clone_skb to a default 0 value. This line is not reached due to a line
that checks if clone_skb is more than zero and returns -ENOTSUPP.

Removes line that defaults clone_skb to zero. -ENOTSUPP is returned
if clone_skb is more than zero. If clone_skb is equal to zero then the
xmit_mode is set to netif_receive as usual and no error is returned.

Signed-off-by: Nick Richardson <[email protected]>
---
net/core/pktgen.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 7e258d255e90..314f97acf39d 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -1190,11 +1190,6 @@ static ssize_t pktgen_if_write(struct file *file,
* pktgen_xmit() is called
*/
pkt_dev->last_ok = 1;
-
- /* override clone_skb if user passed default value
- * at module loading time
- */
- pkt_dev->clone_skb = 0;
} else if (strcmp(f, "queue_xmit") == 0) {
pkt_dev->xmit_mode = M_QUEUE_XMIT;
pkt_dev->last_ok = 1;
--
2.32.0.554.ge1b32706d8-goog



2021-08-02 17:24:47

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH v2] pktgen: Fix invalid clone_skb override

On Mon, 2 Aug 2021 17:12:07 +0000 Nicholas Richardson wrote:
> From: Nick Richardson <[email protected]>
>
> When the netif_receive xmit_mode is set, a line is supposed to set
> clone_skb to a default 0 value. This line is not reached due to a line
> that checks if clone_skb is more than zero and returns -ENOTSUPP.
>
> Removes line that defaults clone_skb to zero.

s/Removes/Remove/
s/defaults/sets/

> -ENOTSUPP is returned
> if clone_skb is more than zero.

That's already mentioned in the previous paragraph.

> If clone_skb is equal to zero then the
> xmit_mode is set to netif_receive as usual and no error is returned.

Please add the explanation why clone_skb can't be negative to the
commit message.

2021-08-02 18:23:57

by Nicholas Richardson

[permalink] [raw]
Subject: [PATCH v3] pktgen: Fix invalid clone_skb override

From: Nick Richardson <[email protected]>

When the netif_receive xmit_mode is set, a line is supposed to set
clone_skb to a default 0 value. This line is made redundant due to a
preceding line that checks if clone_skb is more than zero and returns
-ENOTSUPP.

Only the positive case for clone_skb needs to be checked. It
is impossible for a user to set clone_skb to a negative number.
When a user passes a negative value for clone_skb, the num_arg()
function stops parsing at the first nonnumeric value.

For example: "clone_skb -200" would stop parsing at the
first char ('-') and return zero for the new clone_skb value.

The value read by num_arg() cannot be overflow-ed into the negative
range, since it is an unsigned long.

Remove redundant line that sets clone_skb to zero. If clone_skb is
equal to zero then set xmit_mode to netif_receive as usual and return
no error.

Signed-off-by: Nick Richardson <[email protected]>
---
net/core/pktgen.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 7e258d255e90..314f97acf39d 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -1190,11 +1190,6 @@ static ssize_t pktgen_if_write(struct file *file,
* pktgen_xmit() is called
*/
pkt_dev->last_ok = 1;
-
- /* override clone_skb if user passed default value
- * at module loading time
- */
- pkt_dev->clone_skb = 0;
} else if (strcmp(f, "queue_xmit") == 0) {
pkt_dev->xmit_mode = M_QUEUE_XMIT;
pkt_dev->last_ok = 1;
--
2.32.0.554.ge1b32706d8-goog


2021-08-03 02:19:11

by zhudi (J)

[permalink] [raw]
Subject: 答复: [PATCH v3] pktgen: Fix invalid clone_ skb override

> From: Nick Richardson <[email protected]>
>
> When the netif_receive xmit_mode is set, a line is supposed to set
> clone_skb to a default 0 value. This line is made redundant due to a
> preceding line that checks if clone_skb is more than zero and returns
> -ENOTSUPP.
>
> Only the positive case for clone_skb needs to be checked. It
> is impossible for a user to set clone_skb to a negative number.
> When a user passes a negative value for clone_skb, the num_arg()
> function stops parsing at the first nonnumeric value.
>
> For example: "clone_skb -200" would stop parsing at the
> first char ('-') and return zero for the new clone_skb value.
>
> The value read by num_arg() cannot be overflow-ed into the negative
> range, since it is an unsigned long.
>

module_param(pg_clone_skb_d, int, 0);

This kernel parameter can also set the value of pkt_dev->clone_skb
In pktgen_add_device() and the value can be negative.


> Remove redundant line that sets clone_skb to zero. If clone_skb is
> equal to zero then set xmit_mode to netif_receive as usual and return
> no error.
>
> Signed-off-by: Nick Richardson <[email protected]>
> ---
> net/core/pktgen.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index 7e258d255e90..314f97acf39d 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -1190,11 +1190,6 @@ static ssize_t pktgen_if_write(struct file *file,
> * pktgen_xmit() is called
> */
> pkt_dev->last_ok = 1;
> -
> - /* override clone_skb if user passed default value
> - * at module loading time
> - */
> - pkt_dev->clone_skb = 0;
> } else if (strcmp(f, "queue_xmit") == 0) {
> pkt_dev->xmit_mode = M_QUEUE_XMIT;
> pkt_dev->last_ok = 1;
> --
> 2.32.0.554.ge1b32706d8-goog

2021-08-03 16:32:13

by Nicholas Richardson

[permalink] [raw]
Subject: [PATCH v4] pktgen: Remove redundant clone_skb override

From: Nick Richardson <[email protected]>

When the netif_receive xmit_mode is set, a line is supposed to set
clone_skb to a default 0 value. This line is made redundant due to a
preceding line that checks if clone_skb is more than zero and returns
-ENOTSUPP.

Overriding clone_skb to 0 does not make any difference to the behavior
because if it was positive we return error. So it can be either 0 or
negative, and in both cases the behavior is the same.

Remove redundant line that sets clone_skb to zero.

Signed-off-by: Nick Richardson <[email protected]>
---
net/core/pktgen.c | 5 -----
1 file changed, 5 deletions(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 7e258d255e90..314f97acf39d 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -1190,11 +1190,6 @@ static ssize_t pktgen_if_write(struct file *file,
* pktgen_xmit() is called
*/
pkt_dev->last_ok = 1;
-
- /* override clone_skb if user passed default value
- * at module loading time
- */
- pkt_dev->clone_skb = 0;
} else if (strcmp(f, "queue_xmit") == 0) {
pkt_dev->xmit_mode = M_QUEUE_XMIT;
pkt_dev->last_ok = 1;
--
2.32.0.554.ge1b32706d8-goog


2021-08-04 13:08:45

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH v4] pktgen: Remove redundant clone_skb override

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Tue, 3 Aug 2021 16:27:35 +0000 you wrote:
> From: Nick Richardson <[email protected]>
>
> When the netif_receive xmit_mode is set, a line is supposed to set
> clone_skb to a default 0 value. This line is made redundant due to a
> preceding line that checks if clone_skb is more than zero and returns
> -ENOTSUPP.
>
> [...]

Here is the summary with links:
- [v4] pktgen: Remove redundant clone_skb override
https://git.kernel.org/netdev/net-next/c/c2eecaa193ff

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html