Skip to contentSkip to conversation

cifs: Fix TCP_Server_Info::credits to be signed

PATCH In review David Howells 4 participants 6 messages Oct 20, 2025 – Oct 24, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: Fix TCP_Server_Info::credits to be signed

Fix TCP_Server_Info::credits to be signed, just as echo_credits and oplock_credits are. This also fixes what ought to get at least a compilation warning if not an outright error in *get_credits_field() as a pointer to the unsigned server->credits field is passed back as a pointer to a signed int.

---
 fs/smb/client/cifsglob.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cifsglob.h +1 -1
index 8f6f567d7474..b91397dbb6aa 100644
@@ -740,7 +740,7 @@ struct TCP_Server_Info {
 	bool nosharesock;
 	bool tcp_nodelay;
 	bool terminate;
-	unsigned int credits;  /* send no more requests at once */
+	int credits;  /* send no more requests at once */
 	unsigned int max_credits; /* can override large 32000 default at mnt */
 	unsigned int in_flight;  /* number of requests on the wire to server */
 	unsigned int max_in_flight; /* max number of requests that were on wire */
#1 lore raw

Hi David,

Quoted 5 lines · David Howells

Fix TCP_Server_Info::credits to be signed, just as echo_credits and oplock_credits are. This also fixes what ought to get at least a compilation warning if not an outright error in *get_credits_field() as a pointer to the unsigned server->credits field is passed back as a pointer to a signed int.

Both semantically and technically, credits shouldn't go negative. Shouldn't those other fields/functions become unsigned instead?

Cheers,

Enzo

Quoted 23 lines

---
fs/smb/client/cifsglob.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cifsglob.h +1 -1
index 8f6f567d7474..b91397dbb6aa 100644
@@ -740,7 +740,7 @@ struct TCP_Server_Info {
 	bool nosharesock;
 	bool tcp_nodelay;
 	bool terminate;
-	unsigned int credits;  /* send no more requests at once */
+	int credits;  /* send no more requests at once */
 	unsigned int max_credits; /* can override large 32000 default at mnt */
 	unsigned int in_flight;  /* number of requests on the wire to server */
 	unsigned int max_in_flight; /* max number of requests that were on wire */
#2 lore raw
Quoted 2 lines · Enzo Matsumiya

Both semantically and technically, credits shouldn't go negative. Shouldn't those other fields/functions become unsigned instead?

That's really a question for Steve, but it makes it easier to handle underflow, and I'm guessing that the maximum credits isn't likely to exceed 2G.

David

#3 lore raw
Quoted 7 lines · David Howells
Quoted 2 lines · Enzo Matsumiya

Both semantically and technically, credits shouldn't go negative. Shouldn't those other fields/functions become unsigned instead?

That's really a question for Steve, but it makes it easier to handle underflow

But if there's an overflow somewhere the math should be checked instead (I never seen it happen though).

Quoted 2 lines

and I'm guessing that the maximum credits isn't likely to exceed 2G.

Yes, it's capped at 60-65k (depends on the function...) So yes, an unsigned short would be fine.

Cheers,

Enzo

#4 lore raw
In reply to David Howells
Quoted 11 lines · David Howells
Quoted 2 lines · Enzo Matsumiya

Both semantically and technically, credits shouldn't go negative. Shouldn't those other fields/functions become unsigned instead?

That's really a question for Steve, but it makes it easier to handle underflow, and I'm guessing that the maximum credits isn't likely to exceed 2G.

David

Interesting question - I do like the idea of keeping signed if it makes it easier to check
for underflows but IIRC that hasn't been a problem in a long time (adding Pavel and Ronnie in case they remember) but more important than the signed vs. unsigned
in my opinion is at least keeping the field consistent.

I have seen a few stress related xfstests that often generate reconnects, so we may want
to run with the tracepoint enabled (smb3_reconnect_with_invalid_credits) to see if that is actually happening (the underflow of credits)

I also was thinking that we should doublecheck that lease break acks will never run out credits
(since that can deadlock servers for more than 30 seconds as they wait for timeouts), even if
"lease break storms" are rare. Maybe we should allow e.g. lease
break acks to borrow echo
credits e.g. as minor improvement?

Signature · 3 lines
Thanks,

Steve
#5 lore raw
Quoted 35 lines · Steve French
Quoted 11 lines · David Howells
Quoted 2 lines · Enzo Matsumiya

Both semantically and technically, credits shouldn't go negative. Shouldn't those other fields/functions become unsigned instead?

That's really a question for Steve, but it makes it easier to handle underflow, and I'm guessing that the maximum credits isn't likely to exceed 2G.

David

Interesting question - I do like the idea of keeping signed if it makes it easier to check
for underflows but IIRC that hasn't been a problem in a long time (adding Pavel and Ronnie in case they remember) but more important than the signed vs. unsigned
in my opinion is at least keeping the field consistent.

I have seen a few stress related xfstests that often generate reconnects, so we may want
to run with the tracepoint enabled (smb3_reconnect_with_invalid_credits) to see if that is actually happening (the underflow of credits)

I also was thinking that we should doublecheck that lease break acks will never run out credits
(since that can deadlock servers for more than 30 seconds as they wait for timeouts), even if
"lease break storms" are rare. Maybe we should allow e.g. lease
break acks to borrow echo
credits e.g. as minor improvement?

Quoted 4 lines

--
Thanks,

Steve

I agree with Steve.
I don't mind credits being a signed int. If credits go negative, it's a clear indication of a bug and jumps out at you more than a large integer would.

Signature · 2 lines
Regards,
Shyam