Skip to content

Commit 004443b

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: add support for smb2 max credit parameter
Add smb2 max credits parameter to adjust maximum credits value to limit number of outstanding requests. Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent cb097b3 commit 004443b

8 files changed

Lines changed: 22 additions & 10 deletions

File tree

fs/ksmbd/connection.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ struct ksmbd_conn {
6262
/* References which are made for this Server object*/
6363
atomic_t r_count;
6464
unsigned short total_credits;
65-
unsigned short max_credits;
6665
spinlock_t credits_lock;
6766
wait_queue_head_t req_running_q;
6867
/* Lock to protect requests list*/

fs/ksmbd/ksmbd_netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct ksmbd_startup_request {
103103
* we set the SPARSE_FILES bit (0x40).
104104
*/
105105
__u32 sub_auth[3]; /* Subauth value for Security ID */
106+
__u32 smb2_max_credits; /* MAX credits */
106107
__u32 ifc_list_sz; /* interfaces list size */
107108
__s8 ____payload[];
108109
};

fs/ksmbd/smb2misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn,
326326
ksmbd_debug(SMB, "Insufficient credit charge, given: %d, needed: %d\n",
327327
credit_charge, calc_credit_num);
328328
return 1;
329-
} else if (credit_charge > conn->max_credits) {
329+
} else if (credit_charge > conn->vals->max_credits) {
330330
ksmbd_debug(SMB, "Too large credit charge: %d\n", credit_charge);
331331
return 1;
332332
}

fs/ksmbd/smb2ops.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static struct smb_version_values smb21_server_values = {
1919
.max_read_size = SMB21_DEFAULT_IOSIZE,
2020
.max_write_size = SMB21_DEFAULT_IOSIZE,
2121
.max_trans_size = SMB21_DEFAULT_IOSIZE,
22+
.max_credits = SMB2_MAX_CREDITS,
2223
.large_lock_type = 0,
2324
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
2425
.shared_lock_type = SMB2_LOCKFLAG_SHARED,
@@ -44,6 +45,7 @@ static struct smb_version_values smb30_server_values = {
4445
.max_read_size = SMB3_DEFAULT_IOSIZE,
4546
.max_write_size = SMB3_DEFAULT_IOSIZE,
4647
.max_trans_size = SMB3_DEFAULT_TRANS_SIZE,
48+
.max_credits = SMB2_MAX_CREDITS,
4749
.large_lock_type = 0,
4850
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
4951
.shared_lock_type = SMB2_LOCKFLAG_SHARED,
@@ -70,6 +72,7 @@ static struct smb_version_values smb302_server_values = {
7072
.max_read_size = SMB3_DEFAULT_IOSIZE,
7173
.max_write_size = SMB3_DEFAULT_IOSIZE,
7274
.max_trans_size = SMB3_DEFAULT_TRANS_SIZE,
75+
.max_credits = SMB2_MAX_CREDITS,
7376
.large_lock_type = 0,
7477
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
7578
.shared_lock_type = SMB2_LOCKFLAG_SHARED,
@@ -96,6 +99,7 @@ static struct smb_version_values smb311_server_values = {
9699
.max_read_size = SMB3_DEFAULT_IOSIZE,
97100
.max_write_size = SMB3_DEFAULT_IOSIZE,
98101
.max_trans_size = SMB3_DEFAULT_TRANS_SIZE,
102+
.max_credits = SMB2_MAX_CREDITS,
99103
.large_lock_type = 0,
100104
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
101105
.shared_lock_type = SMB2_LOCKFLAG_SHARED,
@@ -197,7 +201,6 @@ void init_smb2_1_server(struct ksmbd_conn *conn)
197201
conn->ops = &smb2_0_server_ops;
198202
conn->cmds = smb2_0_server_cmds;
199203
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
200-
conn->max_credits = SMB2_MAX_CREDITS;
201204
conn->signing_algorithm = SIGNING_ALG_HMAC_SHA256_LE;
202205

203206
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
@@ -215,7 +218,6 @@ void init_smb3_0_server(struct ksmbd_conn *conn)
215218
conn->ops = &smb3_0_server_ops;
216219
conn->cmds = smb2_0_server_cmds;
217220
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
218-
conn->max_credits = SMB2_MAX_CREDITS;
219221
conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE;
220222

221223
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
@@ -240,7 +242,6 @@ void init_smb3_02_server(struct ksmbd_conn *conn)
240242
conn->ops = &smb3_0_server_ops;
241243
conn->cmds = smb2_0_server_cmds;
242244
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
243-
conn->max_credits = SMB2_MAX_CREDITS;
244245
conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE;
245246

246247
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
@@ -265,7 +266,6 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
265266
conn->ops = &smb3_11_server_ops;
266267
conn->cmds = smb2_0_server_cmds;
267268
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
268-
conn->max_credits = SMB2_MAX_CREDITS;
269269
conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE;
270270

271271
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
@@ -304,3 +304,11 @@ void init_smb2_max_trans_size(unsigned int sz)
304304
smb302_server_values.max_trans_size = sz;
305305
smb311_server_values.max_trans_size = sz;
306306
}
307+
308+
void init_smb2_max_credits(unsigned int sz)
309+
{
310+
smb21_server_values.max_credits = sz;
311+
smb30_server_values.max_credits = sz;
312+
smb302_server_values.max_credits = sz;
313+
smb311_server_values.max_credits = sz;
314+
}

fs/ksmbd/smb2pdu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
308308

309309
hdr->CreditCharge = req_hdr->CreditCharge;
310310

311-
if (conn->total_credits > conn->max_credits) {
311+
if (conn->total_credits > conn->vals->max_credits) {
312312
hdr->CreditRequest = 0;
313313
pr_err("Total credits overflow: %d\n", conn->total_credits);
314314
return -EINVAL;
@@ -329,12 +329,12 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
329329
if (hdr->Command == SMB2_NEGOTIATE)
330330
aux_max = 0;
331331
else
332-
aux_max = conn->max_credits - credit_charge;
332+
aux_max = conn->vals->max_credits - credit_charge;
333333
aux_credits = min_t(unsigned short, aux_credits, aux_max);
334334
credits_granted = credit_charge + aux_credits;
335335

336-
if (conn->max_credits - conn->total_credits < credits_granted)
337-
credits_granted = conn->max_credits -
336+
if (conn->vals->max_credits - conn->total_credits < credits_granted)
337+
credits_granted = conn->vals->max_credits -
338338
conn->total_credits;
339339

340340
conn->total_credits += credits_granted;

fs/ksmbd/smb2pdu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ int init_smb3_11_server(struct ksmbd_conn *conn);
980980
void init_smb2_max_read_size(unsigned int sz);
981981
void init_smb2_max_write_size(unsigned int sz);
982982
void init_smb2_max_trans_size(unsigned int sz);
983+
void init_smb2_max_credits(unsigned int sz);
983984

984985
bool is_smb2_neg_cmd(struct ksmbd_work *work);
985986
bool is_smb2_rsp(struct ksmbd_work *work);

fs/ksmbd/smb_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ struct smb_version_values {
365365
__u32 max_read_size;
366366
__u32 max_write_size;
367367
__u32 max_trans_size;
368+
__u32 max_credits;
368369
__u32 large_lock_type;
369370
__u32 exclusive_lock_type;
370371
__u32 shared_lock_type;

fs/ksmbd/transport_ipc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ static int ipc_server_config_on_startup(struct ksmbd_startup_request *req)
301301
init_smb2_max_write_size(req->smb2_max_write);
302302
if (req->smb2_max_trans)
303303
init_smb2_max_trans_size(req->smb2_max_trans);
304+
if (req->smb2_max_credits)
305+
init_smb2_max_credits(req->smb2_max_credits);
304306

305307
ret = ksmbd_set_netbios_name(req->netbios_name);
306308
ret |= ksmbd_set_server_string(req->server_string);

0 commit comments

Comments
 (0)