Commit 004443b3 authored by Namjae Jeon's avatar Namjae Jeon Committed by Steve French

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: default avatarNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent cb097b3d
...@@ -62,7 +62,6 @@ struct ksmbd_conn { ...@@ -62,7 +62,6 @@ struct ksmbd_conn {
/* References which are made for this Server object*/ /* References which are made for this Server object*/
atomic_t r_count; atomic_t r_count;
unsigned short total_credits; unsigned short total_credits;
unsigned short max_credits;
spinlock_t credits_lock; spinlock_t credits_lock;
wait_queue_head_t req_running_q; wait_queue_head_t req_running_q;
/* Lock to protect requests list*/ /* Lock to protect requests list*/
......
...@@ -103,6 +103,7 @@ struct ksmbd_startup_request { ...@@ -103,6 +103,7 @@ struct ksmbd_startup_request {
* we set the SPARSE_FILES bit (0x40). * we set the SPARSE_FILES bit (0x40).
*/ */
__u32 sub_auth[3]; /* Subauth value for Security ID */ __u32 sub_auth[3]; /* Subauth value for Security ID */
__u32 smb2_max_credits; /* MAX credits */
__u32 ifc_list_sz; /* interfaces list size */ __u32 ifc_list_sz; /* interfaces list size */
__s8 ____payload[]; __s8 ____payload[];
}; };
......
...@@ -326,7 +326,7 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn, ...@@ -326,7 +326,7 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn,
ksmbd_debug(SMB, "Insufficient credit charge, given: %d, needed: %d\n", ksmbd_debug(SMB, "Insufficient credit charge, given: %d, needed: %d\n",
credit_charge, calc_credit_num); credit_charge, calc_credit_num);
return 1; return 1;
} else if (credit_charge > conn->max_credits) { } else if (credit_charge > conn->vals->max_credits) {
ksmbd_debug(SMB, "Too large credit charge: %d\n", credit_charge); ksmbd_debug(SMB, "Too large credit charge: %d\n", credit_charge);
return 1; return 1;
} }
......
...@@ -19,6 +19,7 @@ static struct smb_version_values smb21_server_values = { ...@@ -19,6 +19,7 @@ static struct smb_version_values smb21_server_values = {
.max_read_size = SMB21_DEFAULT_IOSIZE, .max_read_size = SMB21_DEFAULT_IOSIZE,
.max_write_size = SMB21_DEFAULT_IOSIZE, .max_write_size = SMB21_DEFAULT_IOSIZE,
.max_trans_size = SMB21_DEFAULT_IOSIZE, .max_trans_size = SMB21_DEFAULT_IOSIZE,
.max_credits = SMB2_MAX_CREDITS,
.large_lock_type = 0, .large_lock_type = 0,
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
.shared_lock_type = SMB2_LOCKFLAG_SHARED, .shared_lock_type = SMB2_LOCKFLAG_SHARED,
...@@ -44,6 +45,7 @@ static struct smb_version_values smb30_server_values = { ...@@ -44,6 +45,7 @@ static struct smb_version_values smb30_server_values = {
.max_read_size = SMB3_DEFAULT_IOSIZE, .max_read_size = SMB3_DEFAULT_IOSIZE,
.max_write_size = SMB3_DEFAULT_IOSIZE, .max_write_size = SMB3_DEFAULT_IOSIZE,
.max_trans_size = SMB3_DEFAULT_TRANS_SIZE, .max_trans_size = SMB3_DEFAULT_TRANS_SIZE,
.max_credits = SMB2_MAX_CREDITS,
.large_lock_type = 0, .large_lock_type = 0,
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
.shared_lock_type = SMB2_LOCKFLAG_SHARED, .shared_lock_type = SMB2_LOCKFLAG_SHARED,
...@@ -70,6 +72,7 @@ static struct smb_version_values smb302_server_values = { ...@@ -70,6 +72,7 @@ static struct smb_version_values smb302_server_values = {
.max_read_size = SMB3_DEFAULT_IOSIZE, .max_read_size = SMB3_DEFAULT_IOSIZE,
.max_write_size = SMB3_DEFAULT_IOSIZE, .max_write_size = SMB3_DEFAULT_IOSIZE,
.max_trans_size = SMB3_DEFAULT_TRANS_SIZE, .max_trans_size = SMB3_DEFAULT_TRANS_SIZE,
.max_credits = SMB2_MAX_CREDITS,
.large_lock_type = 0, .large_lock_type = 0,
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
.shared_lock_type = SMB2_LOCKFLAG_SHARED, .shared_lock_type = SMB2_LOCKFLAG_SHARED,
...@@ -96,6 +99,7 @@ static struct smb_version_values smb311_server_values = { ...@@ -96,6 +99,7 @@ static struct smb_version_values smb311_server_values = {
.max_read_size = SMB3_DEFAULT_IOSIZE, .max_read_size = SMB3_DEFAULT_IOSIZE,
.max_write_size = SMB3_DEFAULT_IOSIZE, .max_write_size = SMB3_DEFAULT_IOSIZE,
.max_trans_size = SMB3_DEFAULT_TRANS_SIZE, .max_trans_size = SMB3_DEFAULT_TRANS_SIZE,
.max_credits = SMB2_MAX_CREDITS,
.large_lock_type = 0, .large_lock_type = 0,
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
.shared_lock_type = SMB2_LOCKFLAG_SHARED, .shared_lock_type = SMB2_LOCKFLAG_SHARED,
...@@ -197,7 +201,6 @@ void init_smb2_1_server(struct ksmbd_conn *conn) ...@@ -197,7 +201,6 @@ void init_smb2_1_server(struct ksmbd_conn *conn)
conn->ops = &smb2_0_server_ops; conn->ops = &smb2_0_server_ops;
conn->cmds = smb2_0_server_cmds; conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds); conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
conn->max_credits = SMB2_MAX_CREDITS;
conn->signing_algorithm = SIGNING_ALG_HMAC_SHA256_LE; conn->signing_algorithm = SIGNING_ALG_HMAC_SHA256_LE;
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES) if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
...@@ -215,7 +218,6 @@ void init_smb3_0_server(struct ksmbd_conn *conn) ...@@ -215,7 +218,6 @@ void init_smb3_0_server(struct ksmbd_conn *conn)
conn->ops = &smb3_0_server_ops; conn->ops = &smb3_0_server_ops;
conn->cmds = smb2_0_server_cmds; conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds); conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
conn->max_credits = SMB2_MAX_CREDITS;
conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE; conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE;
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES) if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
...@@ -240,7 +242,6 @@ void init_smb3_02_server(struct ksmbd_conn *conn) ...@@ -240,7 +242,6 @@ void init_smb3_02_server(struct ksmbd_conn *conn)
conn->ops = &smb3_0_server_ops; conn->ops = &smb3_0_server_ops;
conn->cmds = smb2_0_server_cmds; conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds); conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
conn->max_credits = SMB2_MAX_CREDITS;
conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE; conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE;
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES) if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
...@@ -265,7 +266,6 @@ int init_smb3_11_server(struct ksmbd_conn *conn) ...@@ -265,7 +266,6 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
conn->ops = &smb3_11_server_ops; conn->ops = &smb3_11_server_ops;
conn->cmds = smb2_0_server_cmds; conn->cmds = smb2_0_server_cmds;
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds); conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
conn->max_credits = SMB2_MAX_CREDITS;
conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE; conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE;
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES) if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
...@@ -304,3 +304,11 @@ void init_smb2_max_trans_size(unsigned int sz) ...@@ -304,3 +304,11 @@ void init_smb2_max_trans_size(unsigned int sz)
smb302_server_values.max_trans_size = sz; smb302_server_values.max_trans_size = sz;
smb311_server_values.max_trans_size = sz; smb311_server_values.max_trans_size = sz;
} }
void init_smb2_max_credits(unsigned int sz)
{
smb21_server_values.max_credits = sz;
smb30_server_values.max_credits = sz;
smb302_server_values.max_credits = sz;
smb311_server_values.max_credits = sz;
}
...@@ -308,7 +308,7 @@ int smb2_set_rsp_credits(struct ksmbd_work *work) ...@@ -308,7 +308,7 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
hdr->CreditCharge = req_hdr->CreditCharge; hdr->CreditCharge = req_hdr->CreditCharge;
if (conn->total_credits > conn->max_credits) { if (conn->total_credits > conn->vals->max_credits) {
hdr->CreditRequest = 0; hdr->CreditRequest = 0;
pr_err("Total credits overflow: %d\n", conn->total_credits); pr_err("Total credits overflow: %d\n", conn->total_credits);
return -EINVAL; return -EINVAL;
...@@ -329,12 +329,12 @@ int smb2_set_rsp_credits(struct ksmbd_work *work) ...@@ -329,12 +329,12 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
if (hdr->Command == SMB2_NEGOTIATE) if (hdr->Command == SMB2_NEGOTIATE)
aux_max = 0; aux_max = 0;
else else
aux_max = conn->max_credits - credit_charge; aux_max = conn->vals->max_credits - credit_charge;
aux_credits = min_t(unsigned short, aux_credits, aux_max); aux_credits = min_t(unsigned short, aux_credits, aux_max);
credits_granted = credit_charge + aux_credits; credits_granted = credit_charge + aux_credits;
if (conn->max_credits - conn->total_credits < credits_granted) if (conn->vals->max_credits - conn->total_credits < credits_granted)
credits_granted = conn->max_credits - credits_granted = conn->vals->max_credits -
conn->total_credits; conn->total_credits;
conn->total_credits += credits_granted; conn->total_credits += credits_granted;
......
...@@ -980,6 +980,7 @@ int init_smb3_11_server(struct ksmbd_conn *conn); ...@@ -980,6 +980,7 @@ int init_smb3_11_server(struct ksmbd_conn *conn);
void init_smb2_max_read_size(unsigned int sz); void init_smb2_max_read_size(unsigned int sz);
void init_smb2_max_write_size(unsigned int sz); void init_smb2_max_write_size(unsigned int sz);
void init_smb2_max_trans_size(unsigned int sz); void init_smb2_max_trans_size(unsigned int sz);
void init_smb2_max_credits(unsigned int sz);
bool is_smb2_neg_cmd(struct ksmbd_work *work); bool is_smb2_neg_cmd(struct ksmbd_work *work);
bool is_smb2_rsp(struct ksmbd_work *work); bool is_smb2_rsp(struct ksmbd_work *work);
......
...@@ -365,6 +365,7 @@ struct smb_version_values { ...@@ -365,6 +365,7 @@ struct smb_version_values {
__u32 max_read_size; __u32 max_read_size;
__u32 max_write_size; __u32 max_write_size;
__u32 max_trans_size; __u32 max_trans_size;
__u32 max_credits;
__u32 large_lock_type; __u32 large_lock_type;
__u32 exclusive_lock_type; __u32 exclusive_lock_type;
__u32 shared_lock_type; __u32 shared_lock_type;
......
...@@ -301,6 +301,8 @@ static int ipc_server_config_on_startup(struct ksmbd_startup_request *req) ...@@ -301,6 +301,8 @@ static int ipc_server_config_on_startup(struct ksmbd_startup_request *req)
init_smb2_max_write_size(req->smb2_max_write); init_smb2_max_write_size(req->smb2_max_write);
if (req->smb2_max_trans) if (req->smb2_max_trans)
init_smb2_max_trans_size(req->smb2_max_trans); init_smb2_max_trans_size(req->smb2_max_trans);
if (req->smb2_max_credits)
init_smb2_max_credits(req->smb2_max_credits);
ret = ksmbd_set_netbios_name(req->netbios_name); ret = ksmbd_set_netbios_name(req->netbios_name);
ret |= ksmbd_set_server_string(req->server_string); ret |= ksmbd_set_server_string(req->server_string);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment