smb: server: fix IRD/ORD negotiation with the client
Subsystems (3)
Stefan Metzmacher
reviewerPATCH v2 1/1 smb: server: fix IRD/ORD negotiation with the client
Already do real negotiation in smb_direct_handle_connect_request() where we see the requested initiator_depth and responder_resources from the client.
We should should detect legacy iwarp clients using MPA v1 with the custom IRD/ORD negotiation.
We need to send the custom IRD/ORD in big endian, but we need to try to let clients with broken requests using little endian (older cifs.ko) to work.
--- fs/smb/server/transport_rdma.c | 101 ++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 14 deletions(-)
fs/smb/server/transport_rdma.c +87 -14
@@ -153,6 +153,10 @@ struct smb_direct_transport {struct work_struct disconnect_work;bool negotiation_requested; + +bool legacy_iwarp; +u8 initiator_depth; +u8 responder_resources; };#define KSMBD_TRANS (t) ((struct ksmbd_transport *)&((t)->transport))
@@ -347,6 +351,9 @@ static struct smb_direct_transport *alloc_transport(struct rdma_cm_id *cm_id) t->cm_id = cm_id; cm_id->context = t; + t->initiator_depth =SMB_DIRECT_CM_INITIATOR_DEPTH ; + t->responder_resources =1 ; + t->status =SMB_DIRECT_CS_NEW ;init_waitqueue_head (&t->wait_status);
@@ -1616,21 +1623,21 @@ static int smb_direct_send_negotiate_response(struct smb_direct_transport *t,static int smb_direct_accept_client (struct smb_direct_transport *t) {struct rdma_conn_param conn_param; -struct ib_port_immutable port_immutable; -u32 ird_ord_hdr[2 ]; +__be32 ird_ord_hdr[2 ];int ret; +/* +* smb_direct_handle_connect_request() +* already negotiated t->initiator_depth +* and t->responder_resources +*/ memset (&conn_param,0 ,sizeof (conn_param)); - conn_param.initiator_depth =min_t (u8, t->cm_id->device->attrs.max_qp_rd_atom, -SMB_DIRECT_CM_INITIATOR_DEPTH ); - conn_param.responder_resources =0 ; - - t->cm_id->device->ops.get_port_immutable (t->cm_id->device, - t->cm_id->port_num, - &port_immutable); -if (port_immutable.core_cap_flags &RDMA_CORE_PORT_IWARP ) { - ird_ord_hdr[0 ] = conn_param.responder_resources; - ird_ord_hdr[1 ] =1 ; + conn_param.initiator_depth = t->initiator_depth; + conn_param.responder_resources = t->responder_resources; + +if (t->legacy_iwarp) { + ird_ord_hdr[0 ] =cpu_to_be32 (conn_param.responder_resources); + ird_ord_hdr[1 ] =cpu_to_be32 (conn_param.initiator_depth); conn_param.private_data = ird_ord_hdr; conn_param.private_data_len =sizeof (ird_ord_hdr); }else {
@@ -2016,10 +2023,13 @@ static bool rdma_frwr_is_supported(struct ib_device_attr *attrs)return true; } -static int smb_direct_handle_connect_request (struct rdma_cm_id *new_cm_id) +static int smb_direct_handle_connect_request (struct rdma_cm_id *new_cm_id, +struct rdma_cm_event *event) {struct smb_direct_transport *t;struct task_struct *handler; +u8 peer_initiator_depth; +u8 peer_responder_resources;int ret;if (!rdma_frwr_is_supported (&new_cm_id->device->attrs)) {
@@ -2033,6 +2043,69 @@ static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id)if (!t)return -ENOMEM ; + peer_initiator_depth = event->param.conn.initiator_depth; + peer_responder_resources = event->param.conn.responder_resources; +if (rdma_protocol_iwarp (new_cm_id->device, new_cm_id->port_num) && + event->param.conn.private_data_len ==8 ) + { +/* +* Legacy clients with only iWarp MPA v1 support +* need a private blob in order to negotiate +* the IRD/ORD values. +*/ +const __be32 *ird_ord_hdr = event->param.conn.private_data; +u32 ird32 =be32_to_cpu (ird_ord_hdr[0 ]); +u32 ord32 =be32_to_cpu (ird_ord_hdr[1 ]); + +/* +* cifs.ko sends the legacy IRD/ORD negotiation +* event if iWarp MPA v2 was used. +* +* Here we check that the values match and only +* mark the client as legacy if they don't match. +*/ +if ((u32 )peer_initiator_depth != ird32 || + (u32 )peer_responder_resources != ord32) + { +/* +* There are broken clients (old cifs.ko) +* using little endian and also +* struct rdma_conn_param only uses u8 +* for initiator_depth and responder_resources, +* so we truncate the value to U8_MAX. +* +* smb_direct_accept_client() will then +* do the real negotiation in order to +* select the minimum between client and +* server. +*/ + ird32 =min_t (u32, ird32,U8_MAX ); + ord32 =min_t (u32, ord32,U8_MAX ); + + t->legacy_iwarp = true; + peer_initiator_depth = (u8 )ird32; + peer_responder_resources = (u8 )ord32; + } + } + +/* +* First set what the we as server are able to support +*/ + t->initiator_depth =min_t (u8, t->initiator_depth, + new_cm_id->device->attrs.max_qp_rd_atom); + +/* +* negotiate the value by using the minimum +* between client and server if the client provided +* non 0 values. +*/ +if (peer_initiator_depth !=0 ) + t->initiator_depth =min_t (u8, t->initiator_depth, + peer_initiator_depth); +if (peer_responder_resources !=0 ) + t->responder_resources =min_t (u8, t->responder_resources, + peer_responder_resources); + ret =smb_direct_connect (t);if (ret) goto out_err;
@@ -2057,7 +2130,7 @@ static int smb_direct_listen_handler(struct rdma_cm_id *cm_id, {switch (event->event) {case RDMA_CM_EVENT_CONNECT_REQUEST : { -int ret =smb_direct_handle_connect_request (cm_id); +int ret =smb_direct_handle_connect_request (cm_id, event);if (ret) {pr_err ("Can't create transport: %d\n" , ret);
Signature · 1 line
2.43.0
Tom Talpey
reviewerQuoted 27 lines · Stefan Metzmacher
Already do real negotiation in
smb_direct_handle_connect_request()where we see the requestedinitiator_depthandresponder_resourcesfrom the client.We should should detect legacy iwarp clients using MPA v1 with the custom IRD/ORD negotiation.
We need to send the custom IRD/ORD in big endian, but we need to try to let clients with broken requests using little endian (older cifs.ko) to work.
Cc Namjae Jeon <[email protected]>Cc Steve French <[email protected]>Cc Tom Talpey <[email protected]>Fixes 0626e6641f6b ("cifsd: add server handler for central processing and tranport layers")Signed-off-by Stefan Metzmacher <[email protected]>--- fs/smb/server/transport_rdma.c | 101 ++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 14 deletions(-)fs/smb/server/transport_rdma.c +0
-0
fs/smb/server/transport_rdma.c struct smb_direct_transport { · line 159
Quoted 7 lines
fs/smb/server/transport_rdma.c +4
-0@@ -153,6 +153,10 @@ struct smb_direct_transport {struct work_struct disconnect_work;bool negotiation_requested; + +bool legacy_iwarp; +u8 initiator_depth; +u8 responder_resources;
Why are these limited to 255? I could foresee peers requesting large numbers, or over (very) high latency links. Also, the MPA protocol extension allows up to 2^14.
Quoted 34 lines
fs/smb/server/transport_rdma.c +9
-8};#define KSMBD_TRANS (t) ((struct ksmbd_transport *)&((t)->transport))@@ -347,6 +351,9 @@ static struct smb_direct_transport *alloc_transport(struct rdma_cm_id *cm_id) t->cm_id = cm_id; cm_id->context = t; + t->initiator_depth =SMB_DIRECT_CM_INITIATOR_DEPTH ; + t->responder_resources =1 ; + t->status =SMB_DIRECT_CS_NEW ;init_waitqueue_head (&t->wait_status);@@ -1616,21 +1623,21 @@ static int smb_direct_send_negotiate_response(struct smb_direct_transport *t,static int smb_direct_accept_client (struct smb_direct_transport *t) {struct rdma_conn_param conn_param; -struct ib_port_immutable port_immutable; -u32 ird_ord_hdr[2 ]; +__be32 ird_ord_hdr[2 ];int ret; +/* +* smb_direct_handle_connect_request() +* already negotiated t->initiator_depth +* and t->responder_resources +*/ memset (&conn_param,0 ,sizeof (conn_param)); - conn_param.initiator_depth =min_t (u8, t->cm_id->device->attrs.max_qp_rd_atom, -SMB_DIRECT_CM_INITIATOR_DEPTH ); - conn_param.responder_resources =0 ; - - t->cm_id->device->ops.get_port_immutable(t->cm_id->device, - t->cm_id->port_num,
fs/smb/server/transport_rdma.c static int smb_direct_send_negotiate_response(struct smb_direct_transport *t, · line 1640
Quoted 10 lines
fs/smb/server/transport_rdma.c +6
-4- &port_immutable); -if (port_immutable.core_cap_flags &RDMA_CORE_PORT_IWARP ) { - ird_ord_hdr[0 ] = conn_param.responder_resources; - ird_ord_hdr[1 ] =1 ; + conn_param.initiator_depth = t->initiator_depth; + conn_param.responder_resources = t->responder_resources; + +if (t->legacy_iwarp) { + ird_ord_hdr[0 ] =cpu_to_be32 (conn_param.responder_resources); + ird_ord_hdr[1 ] =cpu_to_be32 (conn_param.initiator_depth);
Ditto previous comment.
Quoted 5 lines
fs/smb/server/transport_rdma.c +0
-0conn_param.private_data = ird_ord_hdr; conn_param.private_data_len =sizeof (ird_ord_hdr); }else {@@ -2016,10 +2023,13 @@ static bool rdma_frwr_is_supported(struct ib_device_attr *attrs)return true;
fs/smb/server/transport_rdma.c static bool rdma_frwr_is_supported(struct ib_device_attr *attrs) · line 2032
Quoted 10 lines
fs/smb/server/transport_rdma.c +4
-1} -static int smb_direct_handle_connect_request (struct rdma_cm_id *new_cm_id) +static int smb_direct_handle_connect_request (struct rdma_cm_id *new_cm_id, +struct rdma_cm_event *event) {struct smb_direct_transport *t;struct task_struct *handler; +u8 peer_initiator_depth; +u8 peer_responder_resources;
Ditto previous comment.
Quoted 14 lines
fs/smb/server/transport_rdma.c +7
-0int ret;if (!rdma_frwr_is_supported (&new_cm_id->device->attrs)) {@@ -2033,6 +2043,69 @@ static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id)if (!t)return -ENOMEM ; + peer_initiator_depth = event->param.conn.initiator_depth; + peer_responder_resources = event->param.conn.responder_resources; +if (rdma_protocol_iwarp (new_cm_id->device, new_cm_id->port_num) && + event->param.conn.private_data_len ==8 ) + { +/* +* Legacy clients with only iWarp MPA v1 support
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2062
Quoted 10 lines
fs/smb/server/transport_rdma.c +10
-0+* need a private blob in order to negotiate +* the IRD/ORD values. +*/ +const __be32 *ird_ord_hdr = event->param.conn.private_data; +u32 ird32 =be32_to_cpu (ird_ord_hdr[0 ]); +u32 ord32 =be32_to_cpu (ird_ord_hdr[1 ]); + +/* +* cifs.ko sends the legacy IRD/ORD negotiation +* event if iWarp MPA v2 was used.
This is very confusing - what "legacy IRD/ORD negotiation"? And, did you really mean MPA _V2_?
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2065
Quoted 3 lines
fs/smb/server/transport_rdma.c +3
-0+* +* Here we check that the values match and only +* mark the client as legacy if they don't match.
I am troubled by this - if the peer is violating the protocol, we should not perpetuate it. And if the peer truly meant what it said, then we've overridden it.
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2075
Quoted 10 lines
fs/smb/server/transport_rdma.c +10
-0+*/ +if ((u32 )peer_initiator_depth != ird32 || + (u32 )peer_responder_resources != ord32) + { +/* +* There are broken clients (old cifs.ko) +* using little endian and also +* struct rdma_conn_param only uses u8 +* for initiator_depth and responder_resources, +* so we truncate the value to U8_MAX.
We should not do this. I presume any such peer worked previously. Why violate the protocol now???
Tom.
Quoted 45 lines
fs/smb/server/transport_rdma.c +34
-1+* +* smb_direct_accept_client() will then +* do the real negotiation in order to +* select the minimum between client and +* server. +*/ + ird32 =min_t (u32, ird32,U8_MAX ); + ord32 =min_t (u32, ord32,U8_MAX ); + + t->legacy_iwarp = true; + peer_initiator_depth = (u8 )ird32; + peer_responder_resources = (u8 )ord32; + } + } + +/* +* First set what the we as server are able to support +*/ + t->initiator_depth =min_t (u8, t->initiator_depth, + new_cm_id->device->attrs.max_qp_rd_atom); + +/* +* negotiate the value by using the minimum +* between client and server if the client provided +* non 0 values. +*/ +if (peer_initiator_depth !=0 ) + t->initiator_depth =min_t (u8, t->initiator_depth, + peer_initiator_depth); +if (peer_responder_resources !=0 ) + t->responder_resources =min_t (u8, t->responder_resources, + peer_responder_resources); + ret =smb_direct_connect (t);if (ret) goto out_err;@@ -2057,7 +2130,7 @@ static int smb_direct_listen_handler(struct rdma_cm_id *cm_id, {switch (event->event) {case RDMA_CM_EVENT_CONNECT_REQUEST : { -int ret =smb_direct_handle_connect_request (cm_id); +int ret =smb_direct_handle_connect_request (cm_id, event);if (ret) {pr_err ("Can't create transport: %d\n" , ret);
Stefan Metzmacher
reviewerHi Tom,
thanks for the review!
Quoted 23 lines · Stefan Metzmacher
Quoted 22 lines
Already do real negotiation in
smb_direct_handle_connect_request()where we see the requestedinitiator_depthandresponder_resourcesfrom the client.We should should detect legacy iwarp clients using MPA v1 with the custom IRD/ORD negotiation.
We need to send the custom IRD/ORD in big endian, but we need to try to let clients with broken requests using little endian (older cifs.ko) to work.
Cc Namjae Jeon <[email protected]>Cc Steve French <[email protected]>Cc Tom Talpey <[email protected]>Fixes 0626e6641f6b ("cifsd: add server handler for central processing and tranport layers")Signed-off-by Stefan Metzmacher <[email protected]>---
fs/smb/server/transport_rdma.c| 101 ++++++++++++++++++++++++++++-----1 file changed, 87 insertions(+), 14 deletions(-)
Quoted 15 lines
fs/smb/server/transport_rdma.c struct smb_direct_transport { · line 158
Quoted 11 lines
fs/smb/server/transport_rdma.c +4
-0@@ -153,6 +153,10 @@ struct smb_direct_transport { struct work_struct disconnect_work; bool negotiation_requested; + + bool legacy_iwarp; + u8 initiator_depth; + u8 responder_resources;Why are these limited to 255? I could foresee peers requesting large numbers, or over (very) high latency links. Also, the MPA protocol extension allows up to 2^14.
This is because the rdma core also only supports u8, it's strange but that's what we have in include/rdma/rdma_cm.h:
struct rdma_conn_param {
const void *private_data;
u8 private_data_len;
u8 responder_resources;
u8 initiator_depth;
u8 flow_control;
u8 retry_count; /* ignored when accepting */
u8 rnr_retry_count;
/* Fields below ignored if a QP is created on the rdma_cm_id. */
u8 srq;
u32 qp_num;
u32 qkey;
};I'll send a mail to [email protected] to ask why that's the case.
Quoted 35 lines
Quoted 35 lines
fs/smb/server/transport_rdma.c +9
-12}; #define KSMBD_TRANS(t) ((struct ksmbd_transport *)&((t)->transport))@@ -347,6 +351,9 @@ static struct smb_direct_transport *alloc_transport(struct rdma_cm_id *cm_id) t->cm_id = cm_id; cm_id->context = t; + t->initiator_depth = SMB_DIRECT_CM_INITIATOR_DEPTH; + t->responder_resources = 1; + t->status = SMB_DIRECT_CS_NEW; init_waitqueue_head(&t->wait_status);@@ -1616,21 +1623,21 @@ static int smb_direct_send_negotiate_response(struct smb_direct_transport *t, static int smb_direct_accept_client(struct smb_direct_transport *t) { struct rdma_conn_param conn_param; - struct ib_port_immutable port_immutable; - u32 ird_ord_hdr[2]; + __be32 ird_ord_hdr[2]; int ret; + /* + * smb_direct_handle_connect_request() + * already negotiated t->initiator_depth + * and t->responder_resources + */ memset(&conn_param, 0, sizeof(conn_param)); - conn_param.initiator_depth = min_t(u8, t->cm_id->device->attrs.max_qp_rd_atom, - SMB_DIRECT_CM_INITIATOR_DEPTH); - conn_param.responder_resources = 0; - - t->cm_id->device->ops.get_port_immutable(t->cm_id->device, - t->cm_id->port_num, - &port_immutable); - if (port_immutable.core_cap_flags & RDMA_CORE_PORT_IWARP) { - ird_ord_hdr[0] = conn_param.responder_resources; - ird_ord_hdr[1] = 1;
Quoted 8 lines
fs/smb/server/transport_rdma.c static int smb_direct_send_negotiate_response(struct smb_direct_transport *t, · line 1640
Quoted 6 lines
fs/smb/server/transport_rdma.c +6
-0+ conn_param.initiator_depth = t->initiator_depth; + conn_param.responder_resources = t->responder_resources; + + if (t->legacy_iwarp) { + ird_ord_hdr[0] = cpu_to_be32(conn_param.responder_resources); + ird_ord_hdr[1] = cpu_to_be32(conn_param.initiator_depth);Ditto previous comment.
I don't understand this comment there's nothing with u8 here. We just change to big endian instead of using host byte order (most likely little endian).
Quoted 34 lines
Quoted 4 lines
fs/smb/server/transport_rdma.c +0
-0conn_param.private_data = ird_ord_hdr; conn_param.private_data_len = sizeof(ird_ord_hdr); } else {fs/smb/server/transport_rdma.c static bool rdma_frwr_is_supported(struct ib_device_attr *attrs) · line 2031
Quoted 10 lines
fs/smb/server/transport_rdma.c +4
-1@@ -2016,10 +2023,13 @@ static bool rdma_frwr_is_supported(struct ib_device_attr *attrs) return true; } -static int smb_direct_handle_connect_request (struct rdma_cm_id *new_cm_id) +static int smb_direct_handle_connect_request (struct rdma_cm_id *new_cm_id, + struct rdma_cm_event *event) { struct smb_direct_transport *t; struct task_struct *handler; + u8 peer_initiator_depth; + u8 peer_responder_resources;Ditto previous comment.
Quoted 17 lines
fs/smb/server/transport_rdma.c +12
-0int ret; if (!rdma_frwr_is_supported(&new_cm_id->device->attrs)) {@@ -2033,6 +2043,69 @@ static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) if (!t) return -ENOMEM; + peer_initiator_depth = event->param.conn.initiator_depth; + peer_responder_resources = event->param.conn.responder_resources; + if (rdma_protocol_iwarp(new_cm_id->device, new_cm_id->port_num) && + event->param.conn.private_data_len == 8) + { + /* + * Legacy clients with only iWarp MPA v1 support + * need a private blob in order to negotiate + * the IRD/ORD values. + */ + const __be32 *ird_ord_hdr = event->param.conn.private_data; + u32 ird32 = be32_to_cpu(ird_ord_hdr[0]);
Quoted 8 lines
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2062
Quoted 5 lines
fs/smb/server/transport_rdma.c +5
-0+ u32 ord32 = be32_to_cpu(ird_ord_hdr[1]); + + /* +* cifs.ko sends the legacy IRD/ORD negotiation +* event if iWarp MPA v2 was used. This is very confusing - what "legacy IRD/ORD negotiation"? And, did you really mean MPA _V2_?
No v1 with [MS-SMBD] 6 Appendix A: RDMA Provider IRD/ORD Negotiation
Quoted 8 lines
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2065
Quoted 3 lines
fs/smb/server/transport_rdma.c +3
-0+ * + * Here we check that the values match and only + * mark the client as legacy if they don't match.I am troubled by this - if the peer is violating the protocol, we should not perpetuate it. And if the peer truly meant what it said, then we've overridden it.
There's nobody violating something.
These values are negotiated and the server should use the minimum of the peers and it's own value.
So if an old cifs.ko sent private data of
0x20 0x00 0x00 0x00 0x01 0x00 0x00 0x00
Then we have IRD = 536870912 (0x20000000)
and ORD = 16777216 (0x1000000).
While a fixed cifs.ko would send
0x00 0x00 0x00 0x20 0x00 0x00 0x00 0x01
IRD = 32 (0x20) ORD = 1.
So we better truncate the huge values with min_t
instead of (ird & 0xff) (or without the rdma core u8 limitation & 0x3fff) as using & or a cast to u8 would mean we would result in thinking the peer would have send 0.
Quoted 4 lines
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2068
Quoted 4 lines
fs/smb/server/transport_rdma.c +3
-0+*/ + if ((u32)peer_initiator_depth != ird32 || + (u32)peer_responder_resources != ord32)
These checks are there in order to handle the case where the rdma core iwarp MPA v1 negotiation left rdma_conn_param.{initiator_depth,responder_resources} at their local default values.
It lets us detect that MPA v2 was not used.
Windows servers do not add a
[MS-SMBD] 6 Appendix A: RDMA Provider IRD/ORD Negotiation private data blob even if the client sent it together with an MPA v2 exchange.
And we try to do the same here if we detect the values we got via rdma_conn_param and the extra private IRD/ORD Negotiation are the same, then we don't set t->legacy_iwarp = true and won't use conn_param.private_data when calling rdma_accept().
We also just use u8 for the negotiation because we need to fill the u8 values in conn_param for the rdma_accept() call.
Quoted 10 lines
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2075
Quoted 7 lines
fs/smb/server/transport_rdma.c +7
-0+ { + /* +* There are broken clients (old cifs.ko) +* using little endian and also +* struct rdma_conn_param only uses u8 +* for initiator_depth and responder_resources, +* so we truncate the value to U8_MAX. We should not do this. I presume any such peer worked previously. Why violate the protocol now???
It is a limitation in rdma core.
metze
Stefan Metzmacher
reviewerHi Tom,
based on the u8 limitation in the core rdma code are there any real problems with this?
I created wireshark fixes in order to look at it in detail in captures.
And I tested with Windows 2016 using MPA v1, old and new ksmbd with MPA v1 and v2, Windows 2025 with MPA v2 as servers. And old and new cifs.ko with MPA v1 and v2.
My smbdirect refactoring is based on these patches, so it would be great if we could move forward with this.
Thanks!
metze
Quoted 224 lines
Quoted 23 lines · Stefan Metzmacher
Quoted 22 lines
Already do real negotiation in
smb_direct_handle_connect_request()where we see the requestedinitiator_depthandresponder_resourcesfrom the client.We should should detect legacy iwarp clients using MPA v1 with the custom IRD/ORD negotiation.
We need to send the custom IRD/ORD in big endian, but we need to try to let clients with broken requests using little endian (older cifs.ko) to work.
Cc Namjae Jeon <[email protected]>Cc Steve French <[email protected]>Cc Tom Talpey <[email protected]>Fixes 0626e6641f6b ("cifsd: add server handler for central processing and tranport layers")Signed-off-by Stefan Metzmacher <[email protected]>---
fs/smb/server/transport_rdma.c| 101 ++++++++++++++++++++++++++++-----1 file changed, 87 insertions(+), 14 deletions(-)Quoted 15 lines
fs/smb/server/transport_rdma.c struct smb_direct_transport { · line 158
Quoted 11 lines
fs/smb/server/transport_rdma.c +4
-0@@ -153,6 +153,10 @@ struct smb_direct_transport { struct work_struct disconnect_work; bool negotiation_requested; + + bool legacy_iwarp; + u8 initiator_depth; + u8 responder_resources;Why are these limited to 255? I could foresee peers requesting large numbers, or over (very) high latency links. Also, the MPA protocol extension allows up to 2^14.
This is because the rdma core also only supports u8, it's strange but that's what we have in
include/rdma/rdma_cm.h:struct
rdma_conn_param{
const void*private_data;
u8private_data_len;
u8responder_resources;
u8initiator_depth;
u8flow_control;
u8 retry_count; /* ignored when accepting */ u8rnr_retry_count;
/* Fields below ignored if a QP is created on therdma_cm_id. */ u8 srq;
u32qp_num;
u32 qkey;
};I'll send a mail to [email protected] to ask why that's the case.
Quoted 35 lines
Quoted 35 lines
fs/smb/server/transport_rdma.c +9
-12}; #define KSMBD_TRANS(t) ((struct ksmbd_transport *)&((t)->transport))@@ -347,6 +351,9 @@ static struct smb_direct_transport *alloc_transport(struct rdma_cm_id *cm_id) t->cm_id = cm_id; cm_id->context = t; + t->initiator_depth = SMB_DIRECT_CM_INITIATOR_DEPTH; + t->responder_resources = 1; + t->status = SMB_DIRECT_CS_NEW; init_waitqueue_head(&t->wait_status);@@ -1616,21 +1623,21 @@ static int smb_direct_send_negotiate_response(struct smb_direct_transport *t, static int smb_direct_accept_client(struct smb_direct_transport *t) { struct rdma_conn_param conn_param; - struct ib_port_immutable port_immutable; - u32 ird_ord_hdr[2]; + __be32 ird_ord_hdr[2]; int ret; + /* + * smb_direct_handle_connect_request() + * already negotiated t->initiator_depth + * and t->responder_resources + */ memset(&conn_param, 0, sizeof(conn_param)); - conn_param.initiator_depth = min_t(u8, t->cm_id->device->attrs.max_qp_rd_atom, - SMB_DIRECT_CM_INITIATOR_DEPTH); - conn_param.responder_resources = 0; - - t->cm_id->device->ops.get_port_immutable(t->cm_id->device, - t->cm_id->port_num, - &port_immutable); - if (port_immutable.core_cap_flags & RDMA_CORE_PORT_IWARP) { - ird_ord_hdr[0] = conn_param.responder_resources; - ird_ord_hdr[1] = 1;Quoted 8 lines
fs/smb/server/transport_rdma.c static int smb_direct_send_negotiate_response(struct smb_direct_transport *t, · line 1640
Quoted 6 lines
fs/smb/server/transport_rdma.c +6
-0+ conn_param.initiator_depth = t->initiator_depth; + conn_param.responder_resources = t->responder_resources; + + if (t->legacy_iwarp) { + ird_ord_hdr[0] = cpu_to_be32(conn_param.responder_resources); + ird_ord_hdr[1] = cpu_to_be32(conn_param.initiator_depth);Ditto previous comment.
I don't understand this comment there's nothing with u8 here. We just change to big endian instead of using host byte order (most likely little endian).
Quoted 34 lines
Quoted 4 lines
fs/smb/server/transport_rdma.c +0
-0conn_param.private_data = ird_ord_hdr; conn_param.private_data_len = sizeof(ird_ord_hdr); } else {fs/smb/server/transport_rdma.c static bool rdma_frwr_is_supported(struct ib_device_attr *attrs) · line 2031
Quoted 10 lines
fs/smb/server/transport_rdma.c +4
-1@@ -2016,10 +2023,13 @@ static bool rdma_frwr_is_supported(struct ib_device_attr *attrs) return true; } -static int smb_direct_handle_connect_request (struct rdma_cm_id *new_cm_id) +static int smb_direct_handle_connect_request (struct rdma_cm_id *new_cm_id, + struct rdma_cm_event *event) { struct smb_direct_transport *t; struct task_struct *handler; + u8 peer_initiator_depth; + u8 peer_responder_resources;Ditto previous comment.
Quoted 17 lines
fs/smb/server/transport_rdma.c +12
-0int ret; if (!rdma_frwr_is_supported(&new_cm_id->device->attrs)) {@@ -2033,6 +2043,69 @@ static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) if (!t) return -ENOMEM; + peer_initiator_depth = event->param.conn.initiator_depth; + peer_responder_resources = event->param.conn.responder_resources; + if (rdma_protocol_iwarp(new_cm_id->device, new_cm_id->port_num) && + event->param.conn.private_data_len == 8) + { + /* + * Legacy clients with only iWarp MPA v1 support + * need a private blob in order to negotiate + * the IRD/ORD values. + */ + const __be32 *ird_ord_hdr = event->param.conn.private_data; + u32 ird32 = be32_to_cpu(ird_ord_hdr[0]);Quoted 8 lines
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2062
Quoted 5 lines
fs/smb/server/transport_rdma.c +5
-0+ u32 ord32 = be32_to_cpu(ird_ord_hdr[1]); + + /* +* cifs.ko sends the legacy IRD/ORD negotiation +* event if iWarp MPA v2 was used. This is very confusing - what "legacy IRD/ORD negotiation"? And, did you really mean MPA _V2_?
No v1 with [MS-SMBD] 6 Appendix A: RDMA Provider IRD/ORD Negotiation
Quoted 8 lines
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2065
Quoted 3 lines
fs/smb/server/transport_rdma.c +3
-0+ * + * Here we check that the values match and only + * mark the client as legacy if they don't match.I am troubled by this - if the peer is violating the protocol, we should not perpetuate it. And if the peer truly meant what it said, then we've overridden it.
There's nobody violating something.
These values are negotiated and the server should use the minimum of the peers and it's own value.
So if an old cifs.ko sent private data of
0x200x000x000x000x010x000x000x00Then we have IRD = 536870912 (
0x20000000)
and ORD = 16777216 (0x1000000).While a fixed cifs.ko would send
0x000x000x000x200x000x000x000x01
IRD = 32 (0x20) ORD = 1.So we better truncate the huge values with
min_t
instead of (ird &0xff) (or without the rdma core u8 limitation &0x3fff) as using & or a cast to u8 would mean we would result in thinking the peer would have send 0.Quoted 4 lines
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2068
Quoted 4 lines
fs/smb/server/transport_rdma.c +3
-0+*/ + if ((u32)peer_initiator_depth != ird32 || + (u32)peer_responder_resources != ord32)These checks are there in order to handle the case where the rdma core iwarp MPA v1 negotiation left rdma_conn_param.{initiator_depth,responder_resources} at their local default values.
It lets us detect that MPA v2 was not used.
Windows servers do not add a
[MS-SMBD] 6 Appendix A: RDMA Provider IRD/ORD Negotiation private data blob even if the client sent it together with an MPA v2 exchange.And we try to do the same here if we detect the values we got via
rdma_conn_paramand the extra private IRD/ORD Negotiation are the same, then we don't sett->legacy_iwarp= true and won't use conn_param.private_data when callingrdma_accept().We also just use u8 for the negotiation because we need to fill the u8 values in
conn_paramfor therdma_accept()call.Quoted 10 lines
fs/smb/server/transport_rdma.c static int smb_direct_handle_connect_request(struct rdma_cm_id *new_cm_id) · line 2075
Quoted 7 lines
fs/smb/server/transport_rdma.c +7
-0+ { + /* +* There are broken clients (old cifs.ko) +* using little endian and also +* struct rdma_conn_param only uses u8 +* for initiator_depth and responder_resources, +* so we truncate the value to U8_MAX. We should not do this. I presume any such peer worked previously. Why violate the protocol now???
It is a limitation in rdma core.
metze