Skip to contentSkip to conversation

devlink: fix return value after hitting end in region read

PATCH In review Jakub Kicinski 3 participants 3 messages Apr 29, 2020

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 devlink: fix return value after hitting end in region read

Commit d5b90e99e1d5 ("devlink: report 0 after hitting end in region read") fixed region dump, but region read still returns a spurious error:

$ devlink region read netdevsim/netdevsim1/dummy snapshot 0 addr 0 len 128
0000000000000000 a6 f4 c4 1c 21 35 95 a6 9d 34 c3 5b 87 5b 35 79
0000000000000010 f3 a0 d7 ee 4f 2f 82 7f c6 dd c4 f6 a5 c3 1b ae
0000000000000020 a4 fd c8 62 07 59 48 03 70 3b c7 09 86 88 7f 68
0000000000000030 6f 45 5d 6d 7d 0e 16 38 a9 d0 7a 4b 1e 1e 2e a6
0000000000000040 e6 1d ae 06 d6 18 00 85 ca 62 e8 7e 11 7e f6 0f
0000000000000050 79 7e f7 0f f3 94 68 bd e6 40 22 85 b6 be 6f b1
0000000000000060 af db ef 5e 34 f0 98 4b 62 9a e3 1b 8b 93 fc 17
devlink answers: Invalid argument
0000000000000070 61 e8 11 11 66 10 a5 f7 b1 ea 8d 40 60 53 ed 12

This is a minimal fix, I'll follow up with a restructuring so we don't have two checks for the same condition.

Fixes fdd41ec21e15 ("devlink: Return right error code in case of errors for region read")
---
 net/core/devlink.c | 5 +++++
 1 file changed, 5 insertions(+)
net/core/devlink.c +5 -0
index 80f97722f31f..1ec2e9fd8898 100644
@@ -4283,6 +4283,11 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
 		end_offset = nla_get_u64(attrs[DEVLINK_ATTR_REGION_CHUNK_ADDR]);
 		end_offset += nla_get_u64(attrs[DEVLINK_ATTR_REGION_CHUNK_LEN]);
 		dump = false;
+
+		if (start_offset == end_offset) {
+			err = 0;
+			goto nla_put_failure;
+		}
 	}
 
 	err = devlink_nl_region_read_snapshot_fill(skb, devlink,
Signature · 1 line
2.25.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines

-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Tuesday, April 28, 2020 7:02 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; Jakub Kicinski <[email protected]>
Subject: [PATCH net] devlink: fix return value after hitting end in region read

Commit d5b90e99e1d5 ("devlink: report 0 after hitting end in region read") fixed region dump, but region read still returns a spurious error:

$ devlink region read netdevsim/netdevsim1/dummy snapshot 0 addr 0 len 128
0000000000000000 a6 f4 c4 1c 21 35 95 a6 9d 34 c3 5b 87 5b 35 79
0000000000000010 f3 a0 d7 ee 4f 2f 82 7f c6 dd c4 f6 a5 c3 1b ae
0000000000000020 a4 fd c8 62 07 59 48 03 70 3b c7 09 86 88 7f 68
0000000000000030 6f 45 5d 6d 7d 0e 16 38 a9 d0 7a 4b 1e 1e 2e a6
0000000000000040 e6 1d ae 06 d6 18 00 85 ca 62 e8 7e 11 7e f6 0f
0000000000000050 79 7e f7 0f f3 94 68 bd e6 40 22 85 b6 be 6f b1
0000000000000060 af db ef 5e 34 f0 98 4b 62 9a e3 1b 8b 93 fc 17
devlink answers: Invalid argument
0000000000000070 61 e8 11 11 66 10 a5 f7 b1 ea 8d 40 60 53 ed 12
Quoted 3 lines

This is a minimal fix, I'll follow up with a restructuring so we don't have two checks for the same condition.

Makes sense.

Quoted 28 lines
Fixes fdd41ec21e15 ("devlink: Return right error code in case of errors for region

read")

---
 net/core/devlink.c | 5 +++++
 1 file changed, 5 insertions(+)
net/core/devlink.c +5 -0
index 80f97722f31f..1ec2e9fd8898 100644
@@ -4283,6 +4283,11 @@ static int devlink_nl_cmd_region_read_dumpit(struct
 sk_buff *skb,
 		end_offset =
 nla_get_u64(attrs[DEVLINK_ATTR_REGION_CHUNK_ADDR]);
 		end_offset +=
 nla_get_u64(attrs[DEVLINK_ATTR_REGION_CHUNK_LEN]);
 		dump = false;
+
+		if (start_offset == end_offset) {
+			err = 0;
+			goto nla_put_failure;
+		}
net/core/devlink.c +0 -1
 	}
 
 	err = devlink_nl_region_read_snapshot_fill(skb, devlink,
--

2.25.4

Reviewed-by on v1 1/1
#2 lore raw
In reply to Jakub Kicinski
Quoted 14 lines · Wed, Apr 29, 2020 at 04:01:58AM CEST, [email protected] wrote:

Commit d5b90e99e1d5 ("devlink: report 0 after hitting end in region read") fixed region dump, but region read still returns a spurious error:

$ devlink region read netdevsim/netdevsim1/dummy snapshot 0 addr 0 len 128
0000000000000000 a6 f4 c4 1c 21 35 95 a6 9d 34 c3 5b 87 5b 35 79
0000000000000010 f3 a0 d7 ee 4f 2f 82 7f c6 dd c4 f6 a5 c3 1b ae
0000000000000020 a4 fd c8 62 07 59 48 03 70 3b c7 09 86 88 7f 68
0000000000000030 6f 45 5d 6d 7d 0e 16 38 a9 d0 7a 4b 1e 1e 2e a6
0000000000000040 e6 1d ae 06 d6 18 00 85 ca 62 e8 7e 11 7e f6 0f
0000000000000050 79 7e f7 0f f3 94 68 bd e6 40 22 85 b6 be 6f b1
0000000000000060 af db ef 5e 34 f0 98 4b 62 9a e3 1b 8b 93 fc 17
devlink answers: Invalid argument
0000000000000070 61 e8 11 11 66 10 a5 f7 b1 ea 8d 40 60 53 ed 12
Quoted 5 lines

This is a minimal fix, I'll follow up with a restructuring so we don't have two checks for the same condition.

Fixes fdd41ec21e15 ("devlink: Return right error code in case of errors for region read")