* [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1)
@ 2025-05-28 16:01 Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions Stefan Metzmacher
` (13 more replies)
0 siblings, 14 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
Hi,
in preparation of a having a common smb_direct layer I started
to move things into common header files and added the first
step in using shared structues like struct smbdirect_socket.
Currently only simple things are shared and there is no
intended behaviour change (even if I found some things
I'd like to change, but I'll defer them in order to
make the review easier).
I'll work on this the next few months in order to
unify the in kernel client and server layers
and expose the result to userspace too.
So that Samba can also use it.
v2:
- change smb_direct into smbdirect
- make usage of header files just as needed
- also introduce struct smbdirect_socket[_parameters]
as shared structures
Stefan Metzmacher (12):
smb: smbdirect: add smbdirect_pdu.h with protocol definitions
smb: client: make use of common smbdirect_pdu.h
smb: server: make use of common smbdirect_pdu.h
smb: smbdirect: add smbdirect.h with public structures
smb: client: make use of common smbdirect.h
smb: server: make use of common smbdirect.h
smb: smbdirect: add smbdirect_socket.h
smb: client: make use of common smbdirect_socket
smb: server: make use of common smbdirect_socket
smb: smbdirect: introduce smbdirect_socket_parameters
smb: client: make use of common smbdirect_socket_parameters
smb: server: make use of common smbdirect_socket_parameters
fs/smb/client/cifs_debug.c | 23 +-
fs/smb/client/smb2ops.c | 14 +-
fs/smb/client/smb2pdu.c | 17 +-
fs/smb/client/smbdirect.c | 389 +++++++++++----------
fs/smb/client/smbdirect.h | 71 +---
fs/smb/common/smbdirect/smbdirect.h | 37 ++
fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++
fs/smb/common/smbdirect/smbdirect_socket.h | 43 +++
fs/smb/server/connection.c | 4 +-
fs/smb/server/connection.h | 10 +-
fs/smb/server/smb2pdu.c | 11 +-
fs/smb/server/smb2pdu.h | 6 -
fs/smb/server/transport_rdma.c | 385 +++++++++++---------
fs/smb/server/transport_rdma.h | 41 ---
14 files changed, 613 insertions(+), 493 deletions(-)
create mode 100644 fs/smb/common/smbdirect/smbdirect.h
create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
create mode 100644 fs/smb/common/smbdirect/smbdirect_socket.h
--
2.34.1
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 23:28 ` Namjae Jeon
2025-05-28 16:01 ` [PATCH v2 02/12] smb: client: make use of common smbdirect_pdu.h Stefan Metzmacher
` (12 subsequent siblings)
13 siblings, 1 reply; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
This is just a start moving into a common smbdirect layer.
It will be used in the next commits...
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
diff --git a/fs/smb/common/smbdirect/smbdirect_pdu.h b/fs/smb/common/smbdirect/smbdirect_pdu.h
new file mode 100644
index 000000000000..ae9fdb05ce23
--- /dev/null
+++ b/fs/smb/common/smbdirect/smbdirect_pdu.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2017 Stefan Metzmacher
+ */
+
+#ifndef __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_PDU_H__
+#define __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_PDU_H__
+
+#define SMBDIRECT_V1 0x0100
+
+/* SMBD negotiation request packet [MS-SMBD] 2.2.1 */
+struct smbdirect_negotiate_req {
+ __le16 min_version;
+ __le16 max_version;
+ __le16 reserved;
+ __le16 credits_requested;
+ __le32 preferred_send_size;
+ __le32 max_receive_size;
+ __le32 max_fragmented_size;
+} __packed;
+
+/* SMBD negotiation response packet [MS-SMBD] 2.2.2 */
+struct smbdirect_negotiate_resp {
+ __le16 min_version;
+ __le16 max_version;
+ __le16 negotiated_version;
+ __le16 reserved;
+ __le16 credits_requested;
+ __le16 credits_granted;
+ __le32 status;
+ __le32 max_readwrite_size;
+ __le32 preferred_send_size;
+ __le32 max_receive_size;
+ __le32 max_fragmented_size;
+} __packed;
+
+#define SMBDIRECT_DATA_MIN_HDR_SIZE 0x14
+#define SMBDIRECT_DATA_OFFSET 0x18
+
+#define SMBDIRECT_FLAG_RESPONSE_REQUESTED 0x0001
+
+/* SMBD data transfer packet with payload [MS-SMBD] 2.2.3 */
+struct smbdirect_data_transfer {
+ __le16 credits_requested;
+ __le16 credits_granted;
+ __le16 flags;
+ __le16 reserved;
+ __le32 remaining_data_length;
+ __le32 data_offset;
+ __le32 data_length;
+ __le32 padding;
+ __u8 buffer[];
+} __packed;
+
+#endif /* __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_PDU_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 02/12] smb: client: make use of common smbdirect_pdu.h
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 03/12] smb: server: " Stefan Metzmacher
` (11 subsequent siblings)
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/client/smbdirect.c | 40 ++++++++++++++++++--------------------
fs/smb/client/smbdirect.h | 41 ---------------------------------------
2 files changed, 19 insertions(+), 62 deletions(-)
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index b0b7254661e9..0b08169e885d 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -7,6 +7,7 @@
#include <linux/module.h>
#include <linux/highmem.h>
#include <linux/folio_queue.h>
+#include "../common/smbdirect/smbdirect_pdu.h"
#include "smbdirect.h"
#include "cifs_debug.h"
#include "cifsproto.h"
@@ -50,9 +51,6 @@ struct smb_extract_to_rdma {
static ssize_t smb_extract_iter_to_rdma(struct iov_iter *iter, size_t len,
struct smb_extract_to_rdma *rdma);
-/* SMBD version number */
-#define SMBD_V1 0x0100
-
/* Port numbers for SMBD transport */
#define SMB_PORT 445
#define SMBD_PORT 5445
@@ -299,7 +297,7 @@ static void send_done(struct ib_cq *cq, struct ib_wc *wc)
mempool_free(request, request->info->request_mempool);
}
-static void dump_smbd_negotiate_resp(struct smbd_negotiate_resp *resp)
+static void dump_smbdirect_negotiate_resp(struct smbdirect_negotiate_resp *resp)
{
log_rdma_event(INFO, "resp message min_version %u max_version %u negotiated_version %u credits_requested %u credits_granted %u status %u max_readwrite_size %u preferred_send_size %u max_receive_size %u max_fragmented_size %u\n",
resp->min_version, resp->max_version,
@@ -318,15 +316,15 @@ static bool process_negotiation_response(
struct smbd_response *response, int packet_length)
{
struct smbd_connection *info = response->info;
- struct smbd_negotiate_resp *packet = smbd_response_payload(response);
+ struct smbdirect_negotiate_resp *packet = smbd_response_payload(response);
- if (packet_length < sizeof(struct smbd_negotiate_resp)) {
+ if (packet_length < sizeof(struct smbdirect_negotiate_resp)) {
log_rdma_event(ERR,
"error: packet_length=%d\n", packet_length);
return false;
}
- if (le16_to_cpu(packet->negotiated_version) != SMBD_V1) {
+ if (le16_to_cpu(packet->negotiated_version) != SMBDIRECT_V1) {
log_rdma_event(ERR, "error: negotiated_version=%x\n",
le16_to_cpu(packet->negotiated_version));
return false;
@@ -448,7 +446,7 @@ static void smbd_post_send_credits(struct work_struct *work)
/* Called from softirq, when recv is done */
static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
{
- struct smbd_data_transfer *data_transfer;
+ struct smbdirect_data_transfer *data_transfer;
struct smbd_response *response =
container_of(wc->wr_cqe, struct smbd_response, cqe);
struct smbd_connection *info = response->info;
@@ -474,7 +472,7 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
switch (response->type) {
/* SMBD negotiation response */
case SMBD_NEGOTIATE_RESP:
- dump_smbd_negotiate_resp(smbd_response_payload(response));
+ dump_smbdirect_negotiate_resp(smbd_response_payload(response));
info->full_packet_received = true;
info->negotiate_done =
process_negotiation_response(response, wc->byte_len);
@@ -531,7 +529,7 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
/* Send a KEEP_ALIVE response right away if requested */
info->keep_alive_requested = KEEP_ALIVE_NONE;
if (le16_to_cpu(data_transfer->flags) &
- SMB_DIRECT_RESPONSE_REQUESTED) {
+ SMBDIRECT_FLAG_RESPONSE_REQUESTED) {
info->keep_alive_requested = KEEP_ALIVE_PENDING;
}
@@ -686,7 +684,7 @@ static int smbd_post_send_negotiate_req(struct smbd_connection *info)
struct ib_send_wr send_wr;
int rc = -ENOMEM;
struct smbd_request *request;
- struct smbd_negotiate_req *packet;
+ struct smbdirect_negotiate_req *packet;
request = mempool_alloc(info->request_mempool, GFP_KERNEL);
if (!request)
@@ -695,8 +693,8 @@ static int smbd_post_send_negotiate_req(struct smbd_connection *info)
request->info = info;
packet = smbd_request_payload(request);
- packet->min_version = cpu_to_le16(SMBD_V1);
- packet->max_version = cpu_to_le16(SMBD_V1);
+ packet->min_version = cpu_to_le16(SMBDIRECT_V1);
+ packet->max_version = cpu_to_le16(SMBDIRECT_V1);
packet->reserved = 0;
packet->credits_requested = cpu_to_le16(info->send_credit_target);
packet->preferred_send_size = cpu_to_le32(info->max_send_size);
@@ -774,10 +772,10 @@ static int manage_credits_prior_sending(struct smbd_connection *info)
/*
* Check if we need to send a KEEP_ALIVE message
* The idle connection timer triggers a KEEP_ALIVE message when expires
- * SMB_DIRECT_RESPONSE_REQUESTED is set in the message flag to have peer send
+ * SMBDIRECT_FLAG_RESPONSE_REQUESTED is set in the message flag to have peer send
* back a response.
* return value:
- * 1 if SMB_DIRECT_RESPONSE_REQUESTED needs to be set
+ * 1 if SMBDIRECT_FLAG_RESPONSE_REQUESTED needs to be set
* 0: otherwise
*/
static int manage_keep_alive_before_sending(struct smbd_connection *info)
@@ -837,7 +835,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
int header_length;
int data_length;
struct smbd_request *request;
- struct smbd_data_transfer *packet;
+ struct smbdirect_data_transfer *packet;
int new_credits = 0;
wait_credit:
@@ -919,7 +917,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
packet->flags = 0;
if (manage_keep_alive_before_sending(info))
- packet->flags |= cpu_to_le16(SMB_DIRECT_RESPONSE_REQUESTED);
+ packet->flags |= cpu_to_le16(SMBDIRECT_FLAG_RESPONSE_REQUESTED);
packet->reserved = 0;
if (!data_length)
@@ -938,10 +936,10 @@ static int smbd_post_send_iter(struct smbd_connection *info,
le32_to_cpu(packet->remaining_data_length));
/* Map the packet to DMA */
- header_length = sizeof(struct smbd_data_transfer);
+ header_length = sizeof(struct smbdirect_data_transfer);
/* If this is a packet without payload, don't send padding */
if (!data_length)
- header_length = offsetof(struct smbd_data_transfer, padding);
+ header_length = offsetof(struct smbdirect_data_transfer, padding);
request->sge[0].addr = ib_dma_map_single(info->id->device,
(void *)packet,
@@ -1432,7 +1430,7 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
kmem_cache_create(
name,
sizeof(struct smbd_request) +
- sizeof(struct smbd_data_transfer),
+ sizeof(struct smbdirect_data_transfer),
0, SLAB_HWCACHE_ALIGN, NULL);
if (!info->request_cache)
return -ENOMEM;
@@ -1735,7 +1733,7 @@ static int smbd_recv_buf(struct smbd_connection *info, char *buf,
unsigned int size)
{
struct smbd_response *response;
- struct smbd_data_transfer *data_transfer;
+ struct smbdirect_data_transfer *data_transfer;
int to_copy, to_read, data_read, offset;
u32 data_length, remaining_data_length, data_offset;
int rc;
diff --git a/fs/smb/client/smbdirect.h b/fs/smb/client/smbdirect.h
index c08e3665150d..4da0974ce730 100644
--- a/fs/smb/client/smbdirect.h
+++ b/fs/smb/client/smbdirect.h
@@ -177,47 +177,6 @@ enum smbd_message_type {
SMBD_TRANSFER_DATA,
};
-#define SMB_DIRECT_RESPONSE_REQUESTED 0x0001
-
-/* SMBD negotiation request packet [MS-SMBD] 2.2.1 */
-struct smbd_negotiate_req {
- __le16 min_version;
- __le16 max_version;
- __le16 reserved;
- __le16 credits_requested;
- __le32 preferred_send_size;
- __le32 max_receive_size;
- __le32 max_fragmented_size;
-} __packed;
-
-/* SMBD negotiation response packet [MS-SMBD] 2.2.2 */
-struct smbd_negotiate_resp {
- __le16 min_version;
- __le16 max_version;
- __le16 negotiated_version;
- __le16 reserved;
- __le16 credits_requested;
- __le16 credits_granted;
- __le32 status;
- __le32 max_readwrite_size;
- __le32 preferred_send_size;
- __le32 max_receive_size;
- __le32 max_fragmented_size;
-} __packed;
-
-/* SMBD data transfer packet with payload [MS-SMBD] 2.2.3 */
-struct smbd_data_transfer {
- __le16 credits_requested;
- __le16 credits_granted;
- __le16 flags;
- __le16 reserved;
- __le32 remaining_data_length;
- __le32 data_offset;
- __le32 data_length;
- __le32 padding;
- __u8 buffer[];
-} __packed;
-
/* The packet fields for a registered RDMA buffer */
struct smbd_buffer_descriptor_v1 {
__le64 offset;
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 03/12] smb: server: make use of common smbdirect_pdu.h
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 02/12] smb: client: make use of common smbdirect_pdu.h Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 04/12] smb: smbdirect: add smbdirect.h with public structures Stefan Metzmacher
` (10 subsequent siblings)
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/server/transport_rdma.c | 49 +++++++++++++++++-----------------
fs/smb/server/transport_rdma.h | 41 ----------------------------
2 files changed, 25 insertions(+), 65 deletions(-)
diff --git a/fs/smb/server/transport_rdma.c b/fs/smb/server/transport_rdma.c
index 4998df04ab95..55fda2585583 100644
--- a/fs/smb/server/transport_rdma.c
+++ b/fs/smb/server/transport_rdma.c
@@ -23,12 +23,13 @@
#include "connection.h"
#include "smb_common.h"
#include "../common/smb2status.h"
+#include "../common/smbdirect/smbdirect_pdu.h"
#include "transport_rdma.h"
#define SMB_DIRECT_PORT_IWARP 5445
#define SMB_DIRECT_PORT_INFINIBAND 445
-#define SMB_DIRECT_VERSION_LE cpu_to_le16(0x0100)
+#define SMB_DIRECT_VERSION_LE cpu_to_le16(SMBDIRECT_V1)
/* SMB_DIRECT negotiation timeout in seconds */
#define SMB_DIRECT_NEGOTIATE_TIMEOUT 120
@@ -493,8 +494,8 @@ static int smb_direct_check_recvmsg(struct smb_direct_recvmsg *recvmsg)
{
switch (recvmsg->type) {
case SMB_DIRECT_MSG_DATA_TRANSFER: {
- struct smb_direct_data_transfer *req =
- (struct smb_direct_data_transfer *)recvmsg->packet;
+ struct smbdirect_data_transfer *req =
+ (struct smbdirect_data_transfer *)recvmsg->packet;
struct smb2_hdr *hdr = (struct smb2_hdr *)(recvmsg->packet
+ le32_to_cpu(req->data_offset));
ksmbd_debug(RDMA,
@@ -506,8 +507,8 @@ static int smb_direct_check_recvmsg(struct smb_direct_recvmsg *recvmsg)
break;
}
case SMB_DIRECT_MSG_NEGOTIATE_REQ: {
- struct smb_direct_negotiate_req *req =
- (struct smb_direct_negotiate_req *)recvmsg->packet;
+ struct smbdirect_negotiate_req *req =
+ (struct smbdirect_negotiate_req *)recvmsg->packet;
ksmbd_debug(RDMA,
"MinVersion: %u, MaxVersion: %u, CreditRequested: %u, MaxSendSize: %u, MaxRecvSize: %u, MaxFragmentedSize: %u\n",
le16_to_cpu(req->min_version),
@@ -561,7 +562,7 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
switch (recvmsg->type) {
case SMB_DIRECT_MSG_NEGOTIATE_REQ:
- if (wc->byte_len < sizeof(struct smb_direct_negotiate_req)) {
+ if (wc->byte_len < sizeof(struct smbdirect_negotiate_req)) {
put_empty_recvmsg(t, recvmsg);
return;
}
@@ -572,20 +573,20 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
wake_up_interruptible(&t->wait_status);
break;
case SMB_DIRECT_MSG_DATA_TRANSFER: {
- struct smb_direct_data_transfer *data_transfer =
- (struct smb_direct_data_transfer *)recvmsg->packet;
+ struct smbdirect_data_transfer *data_transfer =
+ (struct smbdirect_data_transfer *)recvmsg->packet;
unsigned int data_length;
int avail_recvmsg_count, receive_credits;
if (wc->byte_len <
- offsetof(struct smb_direct_data_transfer, padding)) {
+ offsetof(struct smbdirect_data_transfer, padding)) {
put_empty_recvmsg(t, recvmsg);
return;
}
data_length = le32_to_cpu(data_transfer->data_length);
if (data_length) {
- if (wc->byte_len < sizeof(struct smb_direct_data_transfer) +
+ if (wc->byte_len < sizeof(struct smbdirect_data_transfer) +
(u64)data_length) {
put_empty_recvmsg(t, recvmsg);
return;
@@ -621,7 +622,7 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
&t->send_credits);
if (le16_to_cpu(data_transfer->flags) &
- SMB_DIRECT_RESPONSE_REQUESTED)
+ SMBDIRECT_FLAG_RESPONSE_REQUESTED)
queue_work(smb_direct_wq, &t->send_immediate_work);
if (atomic_read(&t->send_credits) > 0)
@@ -674,7 +675,7 @@ static int smb_direct_read(struct ksmbd_transport *t, char *buf,
unsigned int size, int unused)
{
struct smb_direct_recvmsg *recvmsg;
- struct smb_direct_data_transfer *data_transfer;
+ struct smbdirect_data_transfer *data_transfer;
int to_copy, to_read, data_read, offset;
u32 data_length, remaining_data_length, data_offset;
int rc;
@@ -1021,7 +1022,7 @@ static int smb_direct_create_header(struct smb_direct_transport *t,
struct smb_direct_sendmsg **sendmsg_out)
{
struct smb_direct_sendmsg *sendmsg;
- struct smb_direct_data_transfer *packet;
+ struct smbdirect_data_transfer *packet;
int header_length;
int ret;
@@ -1030,7 +1031,7 @@ static int smb_direct_create_header(struct smb_direct_transport *t,
return PTR_ERR(sendmsg);
/* Fill in the packet header */
- packet = (struct smb_direct_data_transfer *)sendmsg->packet;
+ packet = (struct smbdirect_data_transfer *)sendmsg->packet;
packet->credits_requested = cpu_to_le16(t->send_credit_target);
packet->credits_granted = cpu_to_le16(manage_credits_prior_sending(t));
@@ -1053,11 +1054,11 @@ static int smb_direct_create_header(struct smb_direct_transport *t,
le32_to_cpu(packet->remaining_data_length));
/* Map the packet to DMA */
- header_length = sizeof(struct smb_direct_data_transfer);
+ header_length = sizeof(struct smbdirect_data_transfer);
/* If this is a packet without payload, don't send padding */
if (!size)
header_length =
- offsetof(struct smb_direct_data_transfer, padding);
+ offsetof(struct smbdirect_data_transfer, padding);
sendmsg->sge[0].addr = ib_dma_map_single(t->cm_id->device,
(void *)packet,
@@ -1232,7 +1233,7 @@ static int smb_direct_writev(struct ksmbd_transport *t,
int remaining_data_length;
int start, i, j;
int max_iov_size = st->max_send_size -
- sizeof(struct smb_direct_data_transfer);
+ sizeof(struct smbdirect_data_transfer);
int ret;
struct kvec vec;
struct smb_direct_send_ctx send_ctx;
@@ -1580,18 +1581,18 @@ static int smb_direct_send_negotiate_response(struct smb_direct_transport *t,
int failed)
{
struct smb_direct_sendmsg *sendmsg;
- struct smb_direct_negotiate_resp *resp;
+ struct smbdirect_negotiate_resp *resp;
int ret;
sendmsg = smb_direct_alloc_sendmsg(t);
if (IS_ERR(sendmsg))
return -ENOMEM;
- resp = (struct smb_direct_negotiate_resp *)sendmsg->packet;
+ resp = (struct smbdirect_negotiate_resp *)sendmsg->packet;
if (failed) {
memset(resp, 0, sizeof(*resp));
- resp->min_version = cpu_to_le16(0x0100);
- resp->max_version = cpu_to_le16(0x0100);
+ resp->min_version = SMB_DIRECT_VERSION_LE;
+ resp->max_version = SMB_DIRECT_VERSION_LE;
resp->status = STATUS_NOT_SUPPORTED;
} else {
resp->status = STATUS_SUCCESS;
@@ -1825,7 +1826,7 @@ static int smb_direct_create_pools(struct smb_direct_transport *t)
snprintf(name, sizeof(name), "smb_direct_rqst_pool_%p", t);
t->sendmsg_cache = kmem_cache_create(name,
sizeof(struct smb_direct_sendmsg) +
- sizeof(struct smb_direct_negotiate_resp),
+ sizeof(struct smbdirect_negotiate_resp),
0, SLAB_HWCACHE_ALIGN, NULL);
if (!t->sendmsg_cache)
return -ENOMEM;
@@ -1957,7 +1958,7 @@ static int smb_direct_prepare(struct ksmbd_transport *t)
{
struct smb_direct_transport *st = smb_trans_direct_transfort(t);
struct smb_direct_recvmsg *recvmsg;
- struct smb_direct_negotiate_req *req;
+ struct smbdirect_negotiate_req *req;
int ret;
ksmbd_debug(RDMA, "Waiting for SMB_DIRECT negotiate request\n");
@@ -1976,7 +1977,7 @@ static int smb_direct_prepare(struct ksmbd_transport *t)
if (ret == -ECONNABORTED)
goto out;
- req = (struct smb_direct_negotiate_req *)recvmsg->packet;
+ req = (struct smbdirect_negotiate_req *)recvmsg->packet;
st->max_recv_size = min_t(int, st->max_recv_size,
le32_to_cpu(req->preferred_send_size));
st->max_send_size = min_t(int, st->max_send_size,
diff --git a/fs/smb/server/transport_rdma.h b/fs/smb/server/transport_rdma.h
index 77aee4e5c9dc..0fb692c40e21 100644
--- a/fs/smb/server/transport_rdma.h
+++ b/fs/smb/server/transport_rdma.h
@@ -11,47 +11,6 @@
#define SMBD_MIN_IOSIZE (512 * 1024)
#define SMBD_MAX_IOSIZE (16 * 1024 * 1024)
-/* SMB DIRECT negotiation request packet [MS-SMBD] 2.2.1 */
-struct smb_direct_negotiate_req {
- __le16 min_version;
- __le16 max_version;
- __le16 reserved;
- __le16 credits_requested;
- __le32 preferred_send_size;
- __le32 max_receive_size;
- __le32 max_fragmented_size;
-} __packed;
-
-/* SMB DIRECT negotiation response packet [MS-SMBD] 2.2.2 */
-struct smb_direct_negotiate_resp {
- __le16 min_version;
- __le16 max_version;
- __le16 negotiated_version;
- __le16 reserved;
- __le16 credits_requested;
- __le16 credits_granted;
- __le32 status;
- __le32 max_readwrite_size;
- __le32 preferred_send_size;
- __le32 max_receive_size;
- __le32 max_fragmented_size;
-} __packed;
-
-#define SMB_DIRECT_RESPONSE_REQUESTED 0x0001
-
-/* SMB DIRECT data transfer packet with payload [MS-SMBD] 2.2.3 */
-struct smb_direct_data_transfer {
- __le16 credits_requested;
- __le16 credits_granted;
- __le16 flags;
- __le16 reserved;
- __le32 remaining_data_length;
- __le32 data_offset;
- __le32 data_length;
- __le32 padding;
- __u8 buffer[];
-} __packed;
-
#ifdef CONFIG_SMB_SERVER_SMBDIRECT
int ksmbd_rdma_init(void);
void ksmbd_rdma_destroy(void);
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 04/12] smb: smbdirect: add smbdirect.h with public structures
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (2 preceding siblings ...)
2025-05-28 16:01 ` [PATCH v2 03/12] smb: server: " Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 05/12] smb: client: make use of common smbdirect.h Stefan Metzmacher
` (9 subsequent siblings)
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
Will be used in client and server in the next commits.
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
CC: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/common/smbdirect/smbdirect.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
create mode 100644 fs/smb/common/smbdirect/smbdirect.h
diff --git a/fs/smb/common/smbdirect/smbdirect.h b/fs/smb/common/smbdirect/smbdirect.h
new file mode 100644
index 000000000000..eedbdf0d0433
--- /dev/null
+++ b/fs/smb/common/smbdirect/smbdirect.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2017, Microsoft Corporation.
+ * Copyright (C) 2018, LG Electronics.
+ */
+
+#ifndef __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_H__
+#define __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_H__
+
+/* SMB-DIRECT buffer descriptor V1 structure [MS-SMBD] 2.2.3.1 */
+struct smbdirect_buffer_descriptor_v1 {
+ __le64 offset;
+ __le32 token;
+ __le32 length;
+} __packed;
+
+#endif /* __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 05/12] smb: client: make use of common smbdirect.h
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (3 preceding siblings ...)
2025-05-28 16:01 ` [PATCH v2 04/12] smb: smbdirect: add smbdirect.h with public structures Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 06/12] smb: server: " Stefan Metzmacher
` (8 subsequent siblings)
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/client/smb2pdu.c | 17 +++++++++--------
fs/smb/client/smbdirect.h | 7 -------
2 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index 701a138b82c8..3529b829cda7 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -36,6 +36,7 @@
#include "smb2glob.h"
#include "cifspdu.h"
#include "cifs_spnego.h"
+#include "../common/smbdirect/smbdirect.h"
#include "smbdirect.h"
#include "trace.h"
#ifdef CONFIG_CIFS_DFS_UPCALL
@@ -4442,10 +4443,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len,
#ifdef CONFIG_CIFS_SMB_DIRECT
/*
* If we want to do a RDMA write, fill in and append
- * smbd_buffer_descriptor_v1 to the end of read request
+ * smbdirect_buffer_descriptor_v1 to the end of read request
*/
if (rdata && smb3_use_rdma_offload(io_parms)) {
- struct smbd_buffer_descriptor_v1 *v1;
+ struct smbdirect_buffer_descriptor_v1 *v1;
bool need_invalidate = server->dialect == SMB30_PROT_ID;
rdata->mr = smbd_register_mr(server->smbd_conn, &rdata->subreq.io_iter,
@@ -4459,8 +4460,8 @@ smb2_new_read_req(void **buf, unsigned int *total_len,
req->ReadChannelInfoOffset =
cpu_to_le16(offsetof(struct smb2_read_req, Buffer));
req->ReadChannelInfoLength =
- cpu_to_le16(sizeof(struct smbd_buffer_descriptor_v1));
- v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0];
+ cpu_to_le16(sizeof(struct smbdirect_buffer_descriptor_v1));
+ v1 = (struct smbdirect_buffer_descriptor_v1 *) &req->Buffer[0];
v1->offset = cpu_to_le64(rdata->mr->mr->iova);
v1->token = cpu_to_le32(rdata->mr->mr->rkey);
v1->length = cpu_to_le32(rdata->mr->mr->length);
@@ -4968,10 +4969,10 @@ smb2_async_writev(struct cifs_io_subrequest *wdata)
#ifdef CONFIG_CIFS_SMB_DIRECT
/*
* If we want to do a server RDMA read, fill in and append
- * smbd_buffer_descriptor_v1 to the end of write request
+ * smbdirect_buffer_descriptor_v1 to the end of write request
*/
if (smb3_use_rdma_offload(io_parms)) {
- struct smbd_buffer_descriptor_v1 *v1;
+ struct smbdirect_buffer_descriptor_v1 *v1;
bool need_invalidate = server->dialect == SMB30_PROT_ID;
wdata->mr = smbd_register_mr(server->smbd_conn, &wdata->subreq.io_iter,
@@ -4990,8 +4991,8 @@ smb2_async_writev(struct cifs_io_subrequest *wdata)
req->WriteChannelInfoOffset =
cpu_to_le16(offsetof(struct smb2_write_req, Buffer));
req->WriteChannelInfoLength =
- cpu_to_le16(sizeof(struct smbd_buffer_descriptor_v1));
- v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0];
+ cpu_to_le16(sizeof(struct smbdirect_buffer_descriptor_v1));
+ v1 = (struct smbdirect_buffer_descriptor_v1 *) &req->Buffer[0];
v1->offset = cpu_to_le64(wdata->mr->mr->iova);
v1->token = cpu_to_le32(wdata->mr->mr->rkey);
v1->length = cpu_to_le32(wdata->mr->mr->length);
diff --git a/fs/smb/client/smbdirect.h b/fs/smb/client/smbdirect.h
index 4da0974ce730..8561e19a23a3 100644
--- a/fs/smb/client/smbdirect.h
+++ b/fs/smb/client/smbdirect.h
@@ -177,13 +177,6 @@ enum smbd_message_type {
SMBD_TRANSFER_DATA,
};
-/* The packet fields for a registered RDMA buffer */
-struct smbd_buffer_descriptor_v1 {
- __le64 offset;
- __le32 token;
- __le32 length;
-} __packed;
-
/* Maximum number of SGEs used by smbdirect.c in any send work request */
#define SMBDIRECT_MAX_SEND_SGE 6
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 06/12] smb: server: make use of common smbdirect.h
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (4 preceding siblings ...)
2025-05-28 16:01 ` [PATCH v2 05/12] smb: client: make use of common smbdirect.h Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 07/12] smb: smbdirect: add smbdirect_socket.h Stefan Metzmacher
` (7 subsequent siblings)
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/server/connection.c | 4 ++--
fs/smb/server/connection.h | 10 ++++++----
fs/smb/server/smb2pdu.c | 11 ++++++-----
fs/smb/server/smb2pdu.h | 6 ------
fs/smb/server/transport_rdma.c | 7 ++++---
5 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/fs/smb/server/connection.c b/fs/smb/server/connection.c
index 83764c230e9d..2e7515e57117 100644
--- a/fs/smb/server/connection.c
+++ b/fs/smb/server/connection.c
@@ -243,7 +243,7 @@ int ksmbd_conn_write(struct ksmbd_work *work)
int ksmbd_conn_rdma_read(struct ksmbd_conn *conn,
void *buf, unsigned int buflen,
- struct smb2_buffer_desc_v1 *desc,
+ struct smbdirect_buffer_descriptor_v1 *desc,
unsigned int desc_len)
{
int ret = -EINVAL;
@@ -257,7 +257,7 @@ int ksmbd_conn_rdma_read(struct ksmbd_conn *conn,
int ksmbd_conn_rdma_write(struct ksmbd_conn *conn,
void *buf, unsigned int buflen,
- struct smb2_buffer_desc_v1 *desc,
+ struct smbdirect_buffer_descriptor_v1 *desc,
unsigned int desc_len)
{
int ret = -EINVAL;
diff --git a/fs/smb/server/connection.h b/fs/smb/server/connection.h
index 14620e147dda..3821f0f53d3d 100644
--- a/fs/smb/server/connection.h
+++ b/fs/smb/server/connection.h
@@ -19,6 +19,8 @@
#include "smb_common.h"
#include "ksmbd_work.h"
+struct smbdirect_buffer_descriptor_v1;
+
#define KSMBD_SOCKET_BACKLOG 16
enum {
@@ -126,11 +128,11 @@ struct ksmbd_transport_ops {
unsigned int remote_key);
int (*rdma_read)(struct ksmbd_transport *t,
void *buf, unsigned int len,
- struct smb2_buffer_desc_v1 *desc,
+ struct smbdirect_buffer_descriptor_v1 *desc,
unsigned int desc_len);
int (*rdma_write)(struct ksmbd_transport *t,
void *buf, unsigned int len,
- struct smb2_buffer_desc_v1 *desc,
+ struct smbdirect_buffer_descriptor_v1 *desc,
unsigned int desc_len);
};
@@ -155,11 +157,11 @@ bool ksmbd_conn_lookup_dialect(struct ksmbd_conn *c);
int ksmbd_conn_write(struct ksmbd_work *work);
int ksmbd_conn_rdma_read(struct ksmbd_conn *conn,
void *buf, unsigned int buflen,
- struct smb2_buffer_desc_v1 *desc,
+ struct smbdirect_buffer_descriptor_v1 *desc,
unsigned int desc_len);
int ksmbd_conn_rdma_write(struct ksmbd_conn *conn,
void *buf, unsigned int buflen,
- struct smb2_buffer_desc_v1 *desc,
+ struct smbdirect_buffer_descriptor_v1 *desc,
unsigned int desc_len);
void ksmbd_conn_enqueue_request(struct ksmbd_work *work);
void ksmbd_conn_try_dequeue_request(struct ksmbd_work *work);
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 8d414239b3fe..7ddc69fe6320 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -23,6 +23,7 @@
#include "asn1.h"
#include "connection.h"
#include "transport_ipc.h"
+#include "../common/smbdirect/smbdirect.h"
#include "transport_rdma.h"
#include "vfs.h"
#include "vfs_cache.h"
@@ -6617,7 +6618,7 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work)
}
static int smb2_set_remote_key_for_rdma(struct ksmbd_work *work,
- struct smb2_buffer_desc_v1 *desc,
+ struct smbdirect_buffer_descriptor_v1 *desc,
__le32 Channel,
__le16 ChannelInfoLength)
{
@@ -6653,7 +6654,7 @@ static ssize_t smb2_read_rdma_channel(struct ksmbd_work *work,
int err;
err = ksmbd_conn_rdma_write(work->conn, data_buf, length,
- (struct smb2_buffer_desc_v1 *)
+ (struct smbdirect_buffer_descriptor_v1 *)
((char *)req + le16_to_cpu(req->ReadChannelInfoOffset)),
le16_to_cpu(req->ReadChannelInfoLength));
if (err)
@@ -6724,7 +6725,7 @@ int smb2_read(struct ksmbd_work *work)
goto out;
}
err = smb2_set_remote_key_for_rdma(work,
- (struct smb2_buffer_desc_v1 *)
+ (struct smbdirect_buffer_descriptor_v1 *)
((char *)req + ch_offset),
req->Channel,
req->ReadChannelInfoLength);
@@ -6919,7 +6920,7 @@ static ssize_t smb2_write_rdma_channel(struct ksmbd_work *work,
return -ENOMEM;
ret = ksmbd_conn_rdma_read(work->conn, data_buf, length,
- (struct smb2_buffer_desc_v1 *)
+ (struct smbdirect_buffer_descriptor_v1 *)
((char *)req + le16_to_cpu(req->WriteChannelInfoOffset)),
le16_to_cpu(req->WriteChannelInfoLength));
if (ret < 0) {
@@ -6984,7 +6985,7 @@ int smb2_write(struct ksmbd_work *work)
goto out;
}
err = smb2_set_remote_key_for_rdma(work,
- (struct smb2_buffer_desc_v1 *)
+ (struct smbdirect_buffer_descriptor_v1 *)
((char *)req + ch_offset),
req->Channel,
req->WriteChannelInfoLength);
diff --git a/fs/smb/server/smb2pdu.h b/fs/smb/server/smb2pdu.h
index 17a0b18a8406..1b940cedb22f 100644
--- a/fs/smb/server/smb2pdu.h
+++ b/fs/smb/server/smb2pdu.h
@@ -133,12 +133,6 @@ struct create_posix_rsp {
u8 SidBuffer[44];
} __packed;
-struct smb2_buffer_desc_v1 {
- __le64 offset;
- __le32 token;
- __le32 length;
-} __packed;
-
#define SMB2_0_IOCTL_IS_FSCTL 0x00000001
struct smb_sockaddr_in {
diff --git a/fs/smb/server/transport_rdma.c b/fs/smb/server/transport_rdma.c
index 55fda2585583..99ceef3d83ba 100644
--- a/fs/smb/server/transport_rdma.c
+++ b/fs/smb/server/transport_rdma.c
@@ -23,6 +23,7 @@
#include "connection.h"
#include "smb_common.h"
#include "../common/smb2status.h"
+#include "../common/smbdirect/smbdirect.h"
#include "../common/smbdirect/smbdirect_pdu.h"
#include "transport_rdma.h"
@@ -1355,7 +1356,7 @@ static void write_done(struct ib_cq *cq, struct ib_wc *wc)
static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
void *buf, int buf_len,
- struct smb2_buffer_desc_v1 *desc,
+ struct smbdirect_buffer_descriptor_v1 *desc,
unsigned int desc_len,
bool is_read)
{
@@ -1485,7 +1486,7 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
static int smb_direct_rdma_write(struct ksmbd_transport *t,
void *buf, unsigned int buflen,
- struct smb2_buffer_desc_v1 *desc,
+ struct smbdirect_buffer_descriptor_v1 *desc,
unsigned int desc_len)
{
return smb_direct_rdma_xmit(smb_trans_direct_transfort(t), buf, buflen,
@@ -1494,7 +1495,7 @@ static int smb_direct_rdma_write(struct ksmbd_transport *t,
static int smb_direct_rdma_read(struct ksmbd_transport *t,
void *buf, unsigned int buflen,
- struct smb2_buffer_desc_v1 *desc,
+ struct smbdirect_buffer_descriptor_v1 *desc,
unsigned int desc_len)
{
return smb_direct_rdma_xmit(smb_trans_direct_transfort(t), buf, buflen,
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 07/12] smb: smbdirect: add smbdirect_socket.h
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (5 preceding siblings ...)
2025-05-28 16:01 ` [PATCH v2 06/12] smb: server: " Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 08/12] smb: client: make use of common smbdirect_socket Stefan Metzmacher
` (6 subsequent siblings)
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
This abstracts the common smbdirect layer.
Currently with just a few things in it,
but that will change over time until everything is
in common.
Will be used in client and server in the next commits
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/common/smbdirect/smbdirect_socket.h | 41 ++++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 fs/smb/common/smbdirect/smbdirect_socket.h
diff --git a/fs/smb/common/smbdirect/smbdirect_socket.h b/fs/smb/common/smbdirect/smbdirect_socket.h
new file mode 100644
index 000000000000..69a55561f91a
--- /dev/null
+++ b/fs/smb/common/smbdirect/smbdirect_socket.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2025 Stefan Metzmacher
+ */
+
+#ifndef __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_SOCKET_H__
+#define __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_SOCKET_H__
+
+enum smbdirect_socket_status {
+ SMBDIRECT_SOCKET_CREATED,
+ SMBDIRECT_SOCKET_CONNECTING,
+ SMBDIRECT_SOCKET_CONNECTED,
+ SMBDIRECT_SOCKET_NEGOTIATE_FAILED,
+ SMBDIRECT_SOCKET_DISCONNECTING,
+ SMBDIRECT_SOCKET_DISCONNECTED,
+ SMBDIRECT_SOCKET_DESTROYED
+};
+
+struct smbdirect_socket {
+ enum smbdirect_socket_status status;
+
+ /* RDMA related */
+ struct {
+ struct rdma_cm_id *cm_id;
+ } rdma;
+
+ /* IB verbs related */
+ struct {
+ struct ib_pd *pd;
+ struct ib_cq *send_cq;
+ struct ib_cq *recv_cq;
+
+ /*
+ * shortcuts for rdma.cm_id->{qp,device};
+ */
+ struct ib_qp *qp;
+ struct ib_device *dev;
+ } ib;
+};
+
+#endif /* __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_SOCKET_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 08/12] smb: client: make use of common smbdirect_socket
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (6 preceding siblings ...)
2025-05-28 16:01 ` [PATCH v2 07/12] smb: smbdirect: add smbdirect_socket.h Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 09/12] smb: server: " Stefan Metzmacher
` (5 subsequent siblings)
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
This is the next step in the direction of a common smbdirect layer.
Currently only structures are shared, but that will change
over time until everything is shared.
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/client/cifs_debug.c | 2 +-
fs/smb/client/smbdirect.c | 258 ++++++++++++++++++++-----------------
fs/smb/client/smbdirect.h | 12 +-
3 files changed, 146 insertions(+), 126 deletions(-)
diff --git a/fs/smb/client/cifs_debug.c b/fs/smb/client/cifs_debug.c
index e03c890de0a0..56b0b5c82dd1 100644
--- a/fs/smb/client/cifs_debug.c
+++ b/fs/smb/client/cifs_debug.c
@@ -387,7 +387,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
"transport status: %x",
server->smbd_conn->protocol,
- server->smbd_conn->transport_status);
+ server->smbd_conn->socket.status);
seq_printf(m, "\nConn receive_credit_max: %x "
"send_credit_target: %x max_send_size: %x",
server->smbd_conn->receive_credit_max,
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index 0b08169e885d..608ecd2149ed 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -163,10 +163,11 @@ static void smbd_disconnect_rdma_work(struct work_struct *work)
{
struct smbd_connection *info =
container_of(work, struct smbd_connection, disconnect_work);
+ struct smbdirect_socket *sc = &info->socket;
- if (info->transport_status == SMBD_CONNECTED) {
- info->transport_status = SMBD_DISCONNECTING;
- rdma_disconnect(info->id);
+ if (sc->status == SMBDIRECT_SOCKET_CONNECTED) {
+ sc->status = SMBDIRECT_SOCKET_DISCONNECTING;
+ rdma_disconnect(sc->rdma.cm_id);
}
}
@@ -180,6 +181,7 @@ static int smbd_conn_upcall(
struct rdma_cm_id *id, struct rdma_cm_event *event)
{
struct smbd_connection *info = id->context;
+ struct smbdirect_socket *sc = &info->socket;
log_rdma_event(INFO, "event=%d status=%d\n",
event->event, event->status);
@@ -203,7 +205,7 @@ static int smbd_conn_upcall(
case RDMA_CM_EVENT_ESTABLISHED:
log_rdma_event(INFO, "connected event=%d\n", event->event);
- info->transport_status = SMBD_CONNECTED;
+ sc->status = SMBDIRECT_SOCKET_CONNECTED;
wake_up_interruptible(&info->conn_wait);
break;
@@ -211,20 +213,20 @@ static int smbd_conn_upcall(
case RDMA_CM_EVENT_UNREACHABLE:
case RDMA_CM_EVENT_REJECTED:
log_rdma_event(INFO, "connecting failed event=%d\n", event->event);
- info->transport_status = SMBD_DISCONNECTED;
+ sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
wake_up_interruptible(&info->conn_wait);
break;
case RDMA_CM_EVENT_DEVICE_REMOVAL:
case RDMA_CM_EVENT_DISCONNECTED:
/* This happens when we fail the negotiation */
- if (info->transport_status == SMBD_NEGOTIATE_FAILED) {
- info->transport_status = SMBD_DISCONNECTED;
+ if (sc->status == SMBDIRECT_SOCKET_NEGOTIATE_FAILED) {
+ sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
wake_up(&info->conn_wait);
break;
}
- info->transport_status = SMBD_DISCONNECTED;
+ sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
wake_up_interruptible(&info->disconn_wait);
wake_up_interruptible(&info->wait_reassembly_queue);
wake_up_interruptible_all(&info->wait_send_queue);
@@ -273,6 +275,8 @@ static void send_done(struct ib_cq *cq, struct ib_wc *wc)
int i;
struct smbd_request *request =
container_of(wc->wr_cqe, struct smbd_request, cqe);
+ struct smbd_connection *info = request->info;
+ struct smbdirect_socket *sc = &info->socket;
log_rdma_send(INFO, "smbd_request 0x%p completed wc->status=%d\n",
request, wc->status);
@@ -284,7 +288,7 @@ static void send_done(struct ib_cq *cq, struct ib_wc *wc)
}
for (i = 0; i < request->num_sge; i++)
- ib_dma_unmap_single(request->info->id->device,
+ ib_dma_unmap_single(sc->ib.dev,
request->sge[i].addr,
request->sge[i].length,
DMA_TO_DEVICE);
@@ -391,8 +395,9 @@ static void smbd_post_send_credits(struct work_struct *work)
struct smbd_connection *info =
container_of(work, struct smbd_connection,
post_send_credits_work);
+ struct smbdirect_socket *sc = &info->socket;
- if (info->transport_status != SMBD_CONNECTED) {
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
wake_up(&info->wait_receive_queues);
return;
}
@@ -633,32 +638,34 @@ static int smbd_ia_open(
struct smbd_connection *info,
struct sockaddr *dstaddr, int port)
{
+ struct smbdirect_socket *sc = &info->socket;
int rc;
- info->id = smbd_create_id(info, dstaddr, port);
- if (IS_ERR(info->id)) {
- rc = PTR_ERR(info->id);
+ sc->rdma.cm_id = smbd_create_id(info, dstaddr, port);
+ if (IS_ERR(sc->rdma.cm_id)) {
+ rc = PTR_ERR(sc->rdma.cm_id);
goto out1;
}
+ sc->ib.dev = sc->rdma.cm_id->device;
- if (!frwr_is_supported(&info->id->device->attrs)) {
+ if (!frwr_is_supported(&sc->ib.dev->attrs)) {
log_rdma_event(ERR, "Fast Registration Work Requests (FRWR) is not supported\n");
log_rdma_event(ERR, "Device capability flags = %llx max_fast_reg_page_list_len = %u\n",
- info->id->device->attrs.device_cap_flags,
- info->id->device->attrs.max_fast_reg_page_list_len);
+ sc->ib.dev->attrs.device_cap_flags,
+ sc->ib.dev->attrs.max_fast_reg_page_list_len);
rc = -EPROTONOSUPPORT;
goto out2;
}
info->max_frmr_depth = min_t(int,
smbd_max_frmr_depth,
- info->id->device->attrs.max_fast_reg_page_list_len);
+ sc->ib.dev->attrs.max_fast_reg_page_list_len);
info->mr_type = IB_MR_TYPE_MEM_REG;
- if (info->id->device->attrs.kernel_cap_flags & IBK_SG_GAPS_REG)
+ if (sc->ib.dev->attrs.kernel_cap_flags & IBK_SG_GAPS_REG)
info->mr_type = IB_MR_TYPE_SG_GAPS;
- info->pd = ib_alloc_pd(info->id->device, 0);
- if (IS_ERR(info->pd)) {
- rc = PTR_ERR(info->pd);
+ sc->ib.pd = ib_alloc_pd(sc->ib.dev, 0);
+ if (IS_ERR(sc->ib.pd)) {
+ rc = PTR_ERR(sc->ib.pd);
log_rdma_event(ERR, "ib_alloc_pd() returned %d\n", rc);
goto out2;
}
@@ -666,8 +673,8 @@ static int smbd_ia_open(
return 0;
out2:
- rdma_destroy_id(info->id);
- info->id = NULL;
+ rdma_destroy_id(sc->rdma.cm_id);
+ sc->rdma.cm_id = NULL;
out1:
return rc;
@@ -681,6 +688,7 @@ static int smbd_ia_open(
*/
static int smbd_post_send_negotiate_req(struct smbd_connection *info)
{
+ struct smbdirect_socket *sc = &info->socket;
struct ib_send_wr send_wr;
int rc = -ENOMEM;
struct smbd_request *request;
@@ -704,18 +712,18 @@ static int smbd_post_send_negotiate_req(struct smbd_connection *info)
request->num_sge = 1;
request->sge[0].addr = ib_dma_map_single(
- info->id->device, (void *)packet,
+ sc->ib.dev, (void *)packet,
sizeof(*packet), DMA_TO_DEVICE);
- if (ib_dma_mapping_error(info->id->device, request->sge[0].addr)) {
+ if (ib_dma_mapping_error(sc->ib.dev, request->sge[0].addr)) {
rc = -EIO;
goto dma_mapping_failed;
}
request->sge[0].length = sizeof(*packet);
- request->sge[0].lkey = info->pd->local_dma_lkey;
+ request->sge[0].lkey = sc->ib.pd->local_dma_lkey;
ib_dma_sync_single_for_device(
- info->id->device, request->sge[0].addr,
+ sc->ib.dev, request->sge[0].addr,
request->sge[0].length, DMA_TO_DEVICE);
request->cqe.done = send_done;
@@ -732,14 +740,14 @@ static int smbd_post_send_negotiate_req(struct smbd_connection *info)
request->sge[0].length, request->sge[0].lkey);
atomic_inc(&info->send_pending);
- rc = ib_post_send(info->id->qp, &send_wr, NULL);
+ rc = ib_post_send(sc->ib.qp, &send_wr, NULL);
if (!rc)
return 0;
/* if we reach here, post send failed */
log_rdma_send(ERR, "ib_post_send failed rc=%d\n", rc);
atomic_dec(&info->send_pending);
- ib_dma_unmap_single(info->id->device, request->sge[0].addr,
+ ib_dma_unmap_single(sc->ib.dev, request->sge[0].addr,
request->sge[0].length, DMA_TO_DEVICE);
smbd_disconnect_rdma_connection(info);
@@ -791,6 +799,7 @@ static int manage_keep_alive_before_sending(struct smbd_connection *info)
static int smbd_post_send(struct smbd_connection *info,
struct smbd_request *request)
{
+ struct smbdirect_socket *sc = &info->socket;
struct ib_send_wr send_wr;
int rc, i;
@@ -799,7 +808,7 @@ static int smbd_post_send(struct smbd_connection *info,
"rdma_request sge[%d] addr=0x%llx length=%u\n",
i, request->sge[i].addr, request->sge[i].length);
ib_dma_sync_single_for_device(
- info->id->device,
+ sc->ib.dev,
request->sge[i].addr,
request->sge[i].length,
DMA_TO_DEVICE);
@@ -814,7 +823,7 @@ static int smbd_post_send(struct smbd_connection *info,
send_wr.opcode = IB_WR_SEND;
send_wr.send_flags = IB_SEND_SIGNALED;
- rc = ib_post_send(info->id->qp, &send_wr, NULL);
+ rc = ib_post_send(sc->ib.qp, &send_wr, NULL);
if (rc) {
log_rdma_send(ERR, "ib_post_send failed rc=%d\n", rc);
smbd_disconnect_rdma_connection(info);
@@ -831,6 +840,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
struct iov_iter *iter,
int *_remaining_data_length)
{
+ struct smbdirect_socket *sc = &info->socket;
int i, rc;
int header_length;
int data_length;
@@ -842,11 +852,11 @@ static int smbd_post_send_iter(struct smbd_connection *info,
/* Wait for send credits. A SMBD packet needs one credit */
rc = wait_event_interruptible(info->wait_send_queue,
atomic_read(&info->send_credits) > 0 ||
- info->transport_status != SMBD_CONNECTED);
+ sc->status != SMBDIRECT_SOCKET_CONNECTED);
if (rc)
goto err_wait_credit;
- if (info->transport_status != SMBD_CONNECTED) {
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
log_outgoing(ERR, "disconnected not sending on wait_credit\n");
rc = -EAGAIN;
goto err_wait_credit;
@@ -859,9 +869,9 @@ static int smbd_post_send_iter(struct smbd_connection *info,
wait_send_queue:
wait_event(info->wait_post_send,
atomic_read(&info->send_pending) < info->send_credit_target ||
- info->transport_status != SMBD_CONNECTED);
+ sc->status != SMBDIRECT_SOCKET_CONNECTED);
- if (info->transport_status != SMBD_CONNECTED) {
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
log_outgoing(ERR, "disconnected not sending on wait_send_queue\n");
rc = -EAGAIN;
goto err_wait_send_queue;
@@ -888,8 +898,8 @@ static int smbd_post_send_iter(struct smbd_connection *info,
.nr_sge = 1,
.max_sge = SMBDIRECT_MAX_SEND_SGE,
.sge = request->sge,
- .device = info->id->device,
- .local_dma_lkey = info->pd->local_dma_lkey,
+ .device = sc->ib.dev,
+ .local_dma_lkey = sc->ib.pd->local_dma_lkey,
.direction = DMA_TO_DEVICE,
};
@@ -941,18 +951,18 @@ static int smbd_post_send_iter(struct smbd_connection *info,
if (!data_length)
header_length = offsetof(struct smbdirect_data_transfer, padding);
- request->sge[0].addr = ib_dma_map_single(info->id->device,
+ request->sge[0].addr = ib_dma_map_single(sc->ib.dev,
(void *)packet,
header_length,
DMA_TO_DEVICE);
- if (ib_dma_mapping_error(info->id->device, request->sge[0].addr)) {
+ if (ib_dma_mapping_error(sc->ib.dev, request->sge[0].addr)) {
rc = -EIO;
request->sge[0].addr = 0;
goto err_dma;
}
request->sge[0].length = header_length;
- request->sge[0].lkey = info->pd->local_dma_lkey;
+ request->sge[0].lkey = sc->ib.pd->local_dma_lkey;
rc = smbd_post_send(info, request);
if (!rc)
@@ -961,7 +971,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
err_dma:
for (i = 0; i < request->num_sge; i++)
if (request->sge[i].addr)
- ib_dma_unmap_single(info->id->device,
+ ib_dma_unmap_single(sc->ib.dev,
request->sge[i].addr,
request->sge[i].length,
DMA_TO_DEVICE);
@@ -1006,17 +1016,18 @@ static int smbd_post_send_empty(struct smbd_connection *info)
static int smbd_post_recv(
struct smbd_connection *info, struct smbd_response *response)
{
+ struct smbdirect_socket *sc = &info->socket;
struct ib_recv_wr recv_wr;
int rc = -EIO;
response->sge.addr = ib_dma_map_single(
- info->id->device, response->packet,
+ sc->ib.dev, response->packet,
info->max_receive_size, DMA_FROM_DEVICE);
- if (ib_dma_mapping_error(info->id->device, response->sge.addr))
+ if (ib_dma_mapping_error(sc->ib.dev, response->sge.addr))
return rc;
response->sge.length = info->max_receive_size;
- response->sge.lkey = info->pd->local_dma_lkey;
+ response->sge.lkey = sc->ib.pd->local_dma_lkey;
response->cqe.done = recv_done;
@@ -1025,9 +1036,9 @@ static int smbd_post_recv(
recv_wr.sg_list = &response->sge;
recv_wr.num_sge = 1;
- rc = ib_post_recv(info->id->qp, &recv_wr, NULL);
+ rc = ib_post_recv(sc->ib.qp, &recv_wr, NULL);
if (rc) {
- ib_dma_unmap_single(info->id->device, response->sge.addr,
+ ib_dma_unmap_single(sc->ib.dev, response->sge.addr,
response->sge.length, DMA_FROM_DEVICE);
smbd_disconnect_rdma_connection(info);
log_rdma_recv(ERR, "ib_post_recv failed rc=%d\n", rc);
@@ -1185,9 +1196,10 @@ static struct smbd_response *get_receive_buffer(struct smbd_connection *info)
static void put_receive_buffer(
struct smbd_connection *info, struct smbd_response *response)
{
+ struct smbdirect_socket *sc = &info->socket;
unsigned long flags;
- ib_dma_unmap_single(info->id->device, response->sge.addr,
+ ib_dma_unmap_single(sc->ib.dev, response->sge.addr,
response->sge.length, DMA_FROM_DEVICE);
spin_lock_irqsave(&info->receive_queue_lock, flags);
@@ -1287,6 +1299,7 @@ static void idle_connection_timer(struct work_struct *work)
void smbd_destroy(struct TCP_Server_Info *server)
{
struct smbd_connection *info = server->smbd_conn;
+ struct smbdirect_socket *sc;
struct smbd_response *response;
unsigned long flags;
@@ -1294,19 +1307,21 @@ void smbd_destroy(struct TCP_Server_Info *server)
log_rdma_event(INFO, "rdma session already destroyed\n");
return;
}
+ sc = &info->socket;
log_rdma_event(INFO, "destroying rdma session\n");
- if (info->transport_status != SMBD_DISCONNECTED) {
- rdma_disconnect(server->smbd_conn->id);
+ if (sc->status != SMBDIRECT_SOCKET_DISCONNECTED) {
+ rdma_disconnect(sc->rdma.cm_id);
log_rdma_event(INFO, "wait for transport being disconnected\n");
wait_event_interruptible(
info->disconn_wait,
- info->transport_status == SMBD_DISCONNECTED);
+ sc->status == SMBDIRECT_SOCKET_DISCONNECTED);
}
log_rdma_event(INFO, "destroying qp\n");
- ib_drain_qp(info->id->qp);
- rdma_destroy_qp(info->id);
+ ib_drain_qp(sc->ib.qp);
+ rdma_destroy_qp(sc->rdma.cm_id);
+ sc->ib.qp = NULL;
log_rdma_event(INFO, "cancelling idle timer\n");
cancel_delayed_work_sync(&info->idle_timer_work);
@@ -1353,10 +1368,10 @@ void smbd_destroy(struct TCP_Server_Info *server)
}
destroy_mr_list(info);
- ib_free_cq(info->send_cq);
- ib_free_cq(info->recv_cq);
- ib_dealloc_pd(info->pd);
- rdma_destroy_id(info->id);
+ ib_free_cq(sc->ib.send_cq);
+ ib_free_cq(sc->ib.recv_cq);
+ ib_dealloc_pd(sc->ib.pd);
+ rdma_destroy_id(sc->rdma.cm_id);
/* free mempools */
mempool_destroy(info->request_mempool);
@@ -1365,7 +1380,7 @@ void smbd_destroy(struct TCP_Server_Info *server)
mempool_destroy(info->response_mempool);
kmem_cache_destroy(info->response_cache);
- info->transport_status = SMBD_DESTROYED;
+ sc->status = SMBDIRECT_SOCKET_DESTROYED;
destroy_workqueue(info->workqueue);
log_rdma_event(INFO, "rdma session destroyed\n");
@@ -1390,7 +1405,7 @@ int smbd_reconnect(struct TCP_Server_Info *server)
* This is possible if transport is disconnected and we haven't received
* notification from RDMA, but upper layer has detected timeout
*/
- if (server->smbd_conn->transport_status == SMBD_CONNECTED) {
+ if (server->smbd_conn->socket.status == SMBDIRECT_SOCKET_CONNECTED) {
log_rdma_event(INFO, "disconnecting transport\n");
smbd_destroy(server);
}
@@ -1489,6 +1504,7 @@ static struct smbd_connection *_smbd_get_connection(
{
int rc;
struct smbd_connection *info;
+ struct smbdirect_socket *sc;
struct rdma_conn_param conn_param;
struct ib_qp_init_attr qp_attr;
struct sockaddr_in *addr_in = (struct sockaddr_in *) dstaddr;
@@ -1498,29 +1514,30 @@ static struct smbd_connection *_smbd_get_connection(
info = kzalloc(sizeof(struct smbd_connection), GFP_KERNEL);
if (!info)
return NULL;
+ sc = &info->socket;
- info->transport_status = SMBD_CONNECTING;
+ sc->status = SMBDIRECT_SOCKET_CONNECTING;
rc = smbd_ia_open(info, dstaddr, port);
if (rc) {
log_rdma_event(INFO, "smbd_ia_open rc=%d\n", rc);
goto create_id_failed;
}
- if (smbd_send_credit_target > info->id->device->attrs.max_cqe ||
- smbd_send_credit_target > info->id->device->attrs.max_qp_wr) {
+ if (smbd_send_credit_target > sc->ib.dev->attrs.max_cqe ||
+ smbd_send_credit_target > sc->ib.dev->attrs.max_qp_wr) {
log_rdma_event(ERR, "consider lowering send_credit_target = %d. Possible CQE overrun, device reporting max_cqe %d max_qp_wr %d\n",
smbd_send_credit_target,
- info->id->device->attrs.max_cqe,
- info->id->device->attrs.max_qp_wr);
+ sc->ib.dev->attrs.max_cqe,
+ sc->ib.dev->attrs.max_qp_wr);
goto config_failed;
}
- if (smbd_receive_credit_max > info->id->device->attrs.max_cqe ||
- smbd_receive_credit_max > info->id->device->attrs.max_qp_wr) {
+ if (smbd_receive_credit_max > sc->ib.dev->attrs.max_cqe ||
+ smbd_receive_credit_max > sc->ib.dev->attrs.max_qp_wr) {
log_rdma_event(ERR, "consider lowering receive_credit_max = %d. Possible CQE overrun, device reporting max_cqe %d max_qp_wr %d\n",
smbd_receive_credit_max,
- info->id->device->attrs.max_cqe,
- info->id->device->attrs.max_qp_wr);
+ sc->ib.dev->attrs.max_cqe,
+ sc->ib.dev->attrs.max_qp_wr);
goto config_failed;
}
@@ -1531,32 +1548,30 @@ static struct smbd_connection *_smbd_get_connection(
info->max_receive_size = smbd_max_receive_size;
info->keep_alive_interval = smbd_keep_alive_interval;
- if (info->id->device->attrs.max_send_sge < SMBDIRECT_MAX_SEND_SGE ||
- info->id->device->attrs.max_recv_sge < SMBDIRECT_MAX_RECV_SGE) {
+ if (sc->ib.dev->attrs.max_send_sge < SMBDIRECT_MAX_SEND_SGE ||
+ sc->ib.dev->attrs.max_recv_sge < SMBDIRECT_MAX_RECV_SGE) {
log_rdma_event(ERR,
"device %.*s max_send_sge/max_recv_sge = %d/%d too small\n",
IB_DEVICE_NAME_MAX,
- info->id->device->name,
- info->id->device->attrs.max_send_sge,
- info->id->device->attrs.max_recv_sge);
+ sc->ib.dev->name,
+ sc->ib.dev->attrs.max_send_sge,
+ sc->ib.dev->attrs.max_recv_sge);
goto config_failed;
}
- info->send_cq = NULL;
- info->recv_cq = NULL;
- info->send_cq =
- ib_alloc_cq_any(info->id->device, info,
+ sc->ib.send_cq =
+ ib_alloc_cq_any(sc->ib.dev, info,
info->send_credit_target, IB_POLL_SOFTIRQ);
- if (IS_ERR(info->send_cq)) {
- info->send_cq = NULL;
+ if (IS_ERR(sc->ib.send_cq)) {
+ sc->ib.send_cq = NULL;
goto alloc_cq_failed;
}
- info->recv_cq =
- ib_alloc_cq_any(info->id->device, info,
+ sc->ib.recv_cq =
+ ib_alloc_cq_any(sc->ib.dev, info,
info->receive_credit_max, IB_POLL_SOFTIRQ);
- if (IS_ERR(info->recv_cq)) {
- info->recv_cq = NULL;
+ if (IS_ERR(sc->ib.recv_cq)) {
+ sc->ib.recv_cq = NULL;
goto alloc_cq_failed;
}
@@ -1570,29 +1585,30 @@ static struct smbd_connection *_smbd_get_connection(
qp_attr.cap.max_inline_data = 0;
qp_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
qp_attr.qp_type = IB_QPT_RC;
- qp_attr.send_cq = info->send_cq;
- qp_attr.recv_cq = info->recv_cq;
+ qp_attr.send_cq = sc->ib.send_cq;
+ qp_attr.recv_cq = sc->ib.recv_cq;
qp_attr.port_num = ~0;
- rc = rdma_create_qp(info->id, info->pd, &qp_attr);
+ rc = rdma_create_qp(sc->rdma.cm_id, sc->ib.pd, &qp_attr);
if (rc) {
log_rdma_event(ERR, "rdma_create_qp failed %i\n", rc);
goto create_qp_failed;
}
+ sc->ib.qp = sc->rdma.cm_id->qp;
memset(&conn_param, 0, sizeof(conn_param));
conn_param.initiator_depth = 0;
conn_param.responder_resources =
- min(info->id->device->attrs.max_qp_rd_atom,
+ min(sc->ib.dev->attrs.max_qp_rd_atom,
SMBD_CM_RESPONDER_RESOURCES);
info->responder_resources = conn_param.responder_resources;
log_rdma_mr(INFO, "responder_resources=%d\n",
info->responder_resources);
/* Need to send IRD/ORD in private data for iWARP */
- info->id->device->ops.get_port_immutable(
- info->id->device, info->id->port_num, &port_immutable);
+ sc->ib.dev->ops.get_port_immutable(
+ sc->ib.dev, sc->rdma.cm_id->port_num, &port_immutable);
if (port_immutable.core_cap_flags & RDMA_CORE_PORT_IWARP) {
ird_ord_hdr[0] = info->responder_resources;
ird_ord_hdr[1] = 1;
@@ -1613,16 +1629,16 @@ static struct smbd_connection *_smbd_get_connection(
init_waitqueue_head(&info->conn_wait);
init_waitqueue_head(&info->disconn_wait);
init_waitqueue_head(&info->wait_reassembly_queue);
- rc = rdma_connect(info->id, &conn_param);
+ rc = rdma_connect(sc->rdma.cm_id, &conn_param);
if (rc) {
log_rdma_event(ERR, "rdma_connect() failed with %i\n", rc);
goto rdma_connect_failed;
}
wait_event_interruptible(
- info->conn_wait, info->transport_status != SMBD_CONNECTING);
+ info->conn_wait, sc->status != SMBDIRECT_SOCKET_CONNECTING);
- if (info->transport_status != SMBD_CONNECTED) {
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
log_rdma_event(ERR, "rdma_connect failed port=%d\n", port);
goto rdma_connect_failed;
}
@@ -1673,26 +1689,26 @@ static struct smbd_connection *_smbd_get_connection(
negotiation_failed:
cancel_delayed_work_sync(&info->idle_timer_work);
destroy_caches_and_workqueue(info);
- info->transport_status = SMBD_NEGOTIATE_FAILED;
+ sc->status = SMBDIRECT_SOCKET_NEGOTIATE_FAILED;
init_waitqueue_head(&info->conn_wait);
- rdma_disconnect(info->id);
+ rdma_disconnect(sc->rdma.cm_id);
wait_event(info->conn_wait,
- info->transport_status == SMBD_DISCONNECTED);
+ sc->status == SMBDIRECT_SOCKET_DISCONNECTED);
allocate_cache_failed:
rdma_connect_failed:
- rdma_destroy_qp(info->id);
+ rdma_destroy_qp(sc->rdma.cm_id);
create_qp_failed:
alloc_cq_failed:
- if (info->send_cq)
- ib_free_cq(info->send_cq);
- if (info->recv_cq)
- ib_free_cq(info->recv_cq);
+ if (sc->ib.send_cq)
+ ib_free_cq(sc->ib.send_cq);
+ if (sc->ib.recv_cq)
+ ib_free_cq(sc->ib.recv_cq);
config_failed:
- ib_dealloc_pd(info->pd);
- rdma_destroy_id(info->id);
+ ib_dealloc_pd(sc->ib.pd);
+ rdma_destroy_id(sc->rdma.cm_id);
create_id_failed:
kfree(info);
@@ -1732,6 +1748,7 @@ struct smbd_connection *smbd_get_connection(
static int smbd_recv_buf(struct smbd_connection *info, char *buf,
unsigned int size)
{
+ struct smbdirect_socket *sc = &info->socket;
struct smbd_response *response;
struct smbdirect_data_transfer *data_transfer;
int to_copy, to_read, data_read, offset;
@@ -1846,12 +1863,12 @@ static int smbd_recv_buf(struct smbd_connection *info, char *buf,
rc = wait_event_interruptible(
info->wait_reassembly_queue,
info->reassembly_data_length >= size ||
- info->transport_status != SMBD_CONNECTED);
+ sc->status != SMBDIRECT_SOCKET_CONNECTED);
/* Don't return any data if interrupted */
if (rc)
return rc;
- if (info->transport_status != SMBD_CONNECTED) {
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
log_read(ERR, "disconnected\n");
return -ECONNABORTED;
}
@@ -1869,6 +1886,7 @@ static int smbd_recv_page(struct smbd_connection *info,
struct page *page, unsigned int page_offset,
unsigned int to_read)
{
+ struct smbdirect_socket *sc = &info->socket;
int ret;
char *to_address;
void *page_address;
@@ -1877,7 +1895,7 @@ static int smbd_recv_page(struct smbd_connection *info,
ret = wait_event_interruptible(
info->wait_reassembly_queue,
info->reassembly_data_length >= to_read ||
- info->transport_status != SMBD_CONNECTED);
+ sc->status != SMBDIRECT_SOCKET_CONNECTED);
if (ret)
return ret;
@@ -1952,12 +1970,13 @@ int smbd_send(struct TCP_Server_Info *server,
int num_rqst, struct smb_rqst *rqst_array)
{
struct smbd_connection *info = server->smbd_conn;
+ struct smbdirect_socket *sc = &info->socket;
struct smb_rqst *rqst;
struct iov_iter iter;
unsigned int remaining_data_length, klen;
int rc, i, rqst_idx;
- if (info->transport_status != SMBD_CONNECTED)
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED)
return -EAGAIN;
/*
@@ -2051,6 +2070,7 @@ static void smbd_mr_recovery_work(struct work_struct *work)
{
struct smbd_connection *info =
container_of(work, struct smbd_connection, mr_recovery_work);
+ struct smbdirect_socket *sc = &info->socket;
struct smbd_mr *smbdirect_mr;
int rc;
@@ -2068,7 +2088,7 @@ static void smbd_mr_recovery_work(struct work_struct *work)
}
smbdirect_mr->mr = ib_alloc_mr(
- info->pd, info->mr_type,
+ sc->ib.pd, info->mr_type,
info->max_frmr_depth);
if (IS_ERR(smbdirect_mr->mr)) {
log_rdma_mr(ERR, "ib_alloc_mr failed mr_type=%x max_frmr_depth=%x\n",
@@ -2097,12 +2117,13 @@ static void smbd_mr_recovery_work(struct work_struct *work)
static void destroy_mr_list(struct smbd_connection *info)
{
+ struct smbdirect_socket *sc = &info->socket;
struct smbd_mr *mr, *tmp;
cancel_work_sync(&info->mr_recovery_work);
list_for_each_entry_safe(mr, tmp, &info->mr_list, list) {
if (mr->state == MR_INVALIDATED)
- ib_dma_unmap_sg(info->id->device, mr->sgt.sgl,
+ ib_dma_unmap_sg(sc->ib.dev, mr->sgt.sgl,
mr->sgt.nents, mr->dir);
ib_dereg_mr(mr->mr);
kfree(mr->sgt.sgl);
@@ -2119,6 +2140,7 @@ static void destroy_mr_list(struct smbd_connection *info)
*/
static int allocate_mr_list(struct smbd_connection *info)
{
+ struct smbdirect_socket *sc = &info->socket;
int i;
struct smbd_mr *smbdirect_mr, *tmp;
@@ -2134,7 +2156,7 @@ static int allocate_mr_list(struct smbd_connection *info)
smbdirect_mr = kzalloc(sizeof(*smbdirect_mr), GFP_KERNEL);
if (!smbdirect_mr)
goto cleanup_entries;
- smbdirect_mr->mr = ib_alloc_mr(info->pd, info->mr_type,
+ smbdirect_mr->mr = ib_alloc_mr(sc->ib.pd, info->mr_type,
info->max_frmr_depth);
if (IS_ERR(smbdirect_mr->mr)) {
log_rdma_mr(ERR, "ib_alloc_mr failed mr_type=%x max_frmr_depth=%x\n",
@@ -2179,20 +2201,20 @@ static int allocate_mr_list(struct smbd_connection *info)
*/
static struct smbd_mr *get_mr(struct smbd_connection *info)
{
+ struct smbdirect_socket *sc = &info->socket;
struct smbd_mr *ret;
int rc;
again:
rc = wait_event_interruptible(info->wait_mr,
atomic_read(&info->mr_ready_count) ||
- info->transport_status != SMBD_CONNECTED);
+ sc->status != SMBDIRECT_SOCKET_CONNECTED);
if (rc) {
log_rdma_mr(ERR, "wait_event_interruptible rc=%x\n", rc);
return NULL;
}
- if (info->transport_status != SMBD_CONNECTED) {
- log_rdma_mr(ERR, "info->transport_status=%x\n",
- info->transport_status);
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
+ log_rdma_mr(ERR, "sc->status=%x\n", sc->status);
return NULL;
}
@@ -2245,6 +2267,7 @@ struct smbd_mr *smbd_register_mr(struct smbd_connection *info,
struct iov_iter *iter,
bool writing, bool need_invalidate)
{
+ struct smbdirect_socket *sc = &info->socket;
struct smbd_mr *smbdirect_mr;
int rc, num_pages;
enum dma_data_direction dir;
@@ -2274,7 +2297,7 @@ struct smbd_mr *smbd_register_mr(struct smbd_connection *info,
num_pages, iov_iter_count(iter), info->max_frmr_depth);
smbd_iter_to_mr(info, iter, &smbdirect_mr->sgt, info->max_frmr_depth);
- rc = ib_dma_map_sg(info->id->device, smbdirect_mr->sgt.sgl,
+ rc = ib_dma_map_sg(sc->ib.dev, smbdirect_mr->sgt.sgl,
smbdirect_mr->sgt.nents, dir);
if (!rc) {
log_rdma_mr(ERR, "ib_dma_map_sg num_pages=%x dir=%x rc=%x\n",
@@ -2310,7 +2333,7 @@ struct smbd_mr *smbd_register_mr(struct smbd_connection *info,
* on IB_WR_REG_MR. Hardware enforces a barrier and order of execution
* on the next ib_post_send when we actually send I/O to remote peer
*/
- rc = ib_post_send(info->id->qp, ®_wr->wr, NULL);
+ rc = ib_post_send(sc->ib.qp, ®_wr->wr, NULL);
if (!rc)
return smbdirect_mr;
@@ -2319,7 +2342,7 @@ struct smbd_mr *smbd_register_mr(struct smbd_connection *info,
/* If all failed, attempt to recover this MR by setting it MR_ERROR*/
map_mr_error:
- ib_dma_unmap_sg(info->id->device, smbdirect_mr->sgt.sgl,
+ ib_dma_unmap_sg(sc->ib.dev, smbdirect_mr->sgt.sgl,
smbdirect_mr->sgt.nents, smbdirect_mr->dir);
dma_map_error:
@@ -2357,6 +2380,7 @@ int smbd_deregister_mr(struct smbd_mr *smbdirect_mr)
{
struct ib_send_wr *wr;
struct smbd_connection *info = smbdirect_mr->conn;
+ struct smbdirect_socket *sc = &info->socket;
int rc = 0;
if (smbdirect_mr->need_invalidate) {
@@ -2370,7 +2394,7 @@ int smbd_deregister_mr(struct smbd_mr *smbdirect_mr)
wr->send_flags = IB_SEND_SIGNALED;
init_completion(&smbdirect_mr->invalidate_done);
- rc = ib_post_send(info->id->qp, wr, NULL);
+ rc = ib_post_send(sc->ib.qp, wr, NULL);
if (rc) {
log_rdma_mr(ERR, "ib_post_send failed rc=%x\n", rc);
smbd_disconnect_rdma_connection(info);
@@ -2387,7 +2411,7 @@ int smbd_deregister_mr(struct smbd_mr *smbdirect_mr)
if (smbdirect_mr->state == MR_INVALIDATED) {
ib_dma_unmap_sg(
- info->id->device, smbdirect_mr->sgt.sgl,
+ sc->ib.dev, smbdirect_mr->sgt.sgl,
smbdirect_mr->sgt.nents,
smbdirect_mr->dir);
smbdirect_mr->state = MR_READY;
diff --git a/fs/smb/client/smbdirect.h b/fs/smb/client/smbdirect.h
index 8561e19a23a3..904c4e5b9e5c 100644
--- a/fs/smb/client/smbdirect.h
+++ b/fs/smb/client/smbdirect.h
@@ -15,6 +15,8 @@
#include <rdma/rdma_cm.h>
#include <linux/mempool.h>
+#include "../common/smbdirect/smbdirect_socket.h"
+
extern int rdma_readwrite_threshold;
extern int smbd_max_frmr_depth;
extern int smbd_keep_alive_interval;
@@ -50,14 +52,8 @@ enum smbd_connection_status {
* 5. mempools for allocating packets
*/
struct smbd_connection {
- enum smbd_connection_status transport_status;
-
- /* RDMA related */
- struct rdma_cm_id *id;
- struct ib_qp_init_attr qp_attr;
- struct ib_pd *pd;
- struct ib_cq *send_cq, *recv_cq;
- struct ib_device_attr dev_attr;
+ struct smbdirect_socket socket;
+
int ri_rc;
struct completion ri_done;
wait_queue_head_t conn_wait;
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 09/12] smb: server: make use of common smbdirect_socket
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (7 preceding siblings ...)
2025-05-28 16:01 ` [PATCH v2 08/12] smb: client: make use of common smbdirect_socket Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 10/12] smb: smbdirect: introduce smbdirect_socket_parameters Stefan Metzmacher
` (4 subsequent siblings)
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
This is the next step in the direction of a common smbdirect layer.
Currently only structures are shared, but that will change
over time until everything is shared.
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/server/transport_rdma.c | 244 +++++++++++++++++++--------------
1 file changed, 139 insertions(+), 105 deletions(-)
diff --git a/fs/smb/server/transport_rdma.c b/fs/smb/server/transport_rdma.c
index 99ceef3d83ba..16044d473c34 100644
--- a/fs/smb/server/transport_rdma.c
+++ b/fs/smb/server/transport_rdma.c
@@ -25,6 +25,7 @@
#include "../common/smb2status.h"
#include "../common/smbdirect/smbdirect.h"
#include "../common/smbdirect/smbdirect_pdu.h"
+#include "../common/smbdirect/smbdirect_socket.h"
#include "transport_rdma.h"
#define SMB_DIRECT_PORT_IWARP 5445
@@ -99,16 +100,11 @@ enum smb_direct_status {
struct smb_direct_transport {
struct ksmbd_transport transport;
- enum smb_direct_status status;
+ struct smbdirect_socket socket;
+
bool full_packet_received;
wait_queue_head_t wait_status;
- struct rdma_cm_id *cm_id;
- struct ib_cq *send_cq;
- struct ib_cq *recv_cq;
- struct ib_pd *pd;
- struct ib_qp *qp;
-
int max_send_size;
int max_recv_size;
int max_fragmented_send_size;
@@ -269,7 +265,9 @@ smb_direct_recvmsg *get_free_recvmsg(struct smb_direct_transport *t)
static void put_recvmsg(struct smb_direct_transport *t,
struct smb_direct_recvmsg *recvmsg)
{
- ib_dma_unmap_single(t->cm_id->device, recvmsg->sge.addr,
+ struct smbdirect_socket *sc = &t->socket;
+
+ ib_dma_unmap_single(sc->ib.dev, recvmsg->sge.addr,
recvmsg->sge.length, DMA_FROM_DEVICE);
spin_lock(&t->recvmsg_queue_lock);
@@ -295,7 +293,9 @@ smb_direct_recvmsg *get_empty_recvmsg(struct smb_direct_transport *t)
static void put_empty_recvmsg(struct smb_direct_transport *t,
struct smb_direct_recvmsg *recvmsg)
{
- ib_dma_unmap_single(t->cm_id->device, recvmsg->sge.addr,
+ struct smbdirect_socket *sc = &t->socket;
+
+ ib_dma_unmap_single(sc->ib.dev, recvmsg->sge.addr,
recvmsg->sge.length, DMA_FROM_DEVICE);
spin_lock(&t->empty_recvmsg_queue_lock);
@@ -335,17 +335,20 @@ static void smb_direct_disconnect_rdma_work(struct work_struct *work)
struct smb_direct_transport *t =
container_of(work, struct smb_direct_transport,
disconnect_work);
+ struct smbdirect_socket *sc = &t->socket;
- if (t->status == SMB_DIRECT_CS_CONNECTED) {
- t->status = SMB_DIRECT_CS_DISCONNECTING;
- rdma_disconnect(t->cm_id);
+ if (sc->status == SMBDIRECT_SOCKET_CONNECTED) {
+ sc->status = SMBDIRECT_SOCKET_DISCONNECTING;
+ rdma_disconnect(sc->rdma.cm_id);
}
}
static void
smb_direct_disconnect_rdma_connection(struct smb_direct_transport *t)
{
- if (t->status == SMB_DIRECT_CS_CONNECTED)
+ struct smbdirect_socket *sc = &t->socket;
+
+ if (sc->status == SMBDIRECT_SOCKET_CONNECTED)
queue_work(smb_direct_wq, &t->disconnect_work);
}
@@ -353,8 +356,9 @@ static void smb_direct_send_immediate_work(struct work_struct *work)
{
struct smb_direct_transport *t = container_of(work,
struct smb_direct_transport, send_immediate_work);
+ struct smbdirect_socket *sc = &t->socket;
- if (t->status != SMB_DIRECT_CS_CONNECTED)
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED)
return;
smb_direct_post_send_data(t, NULL, NULL, 0, 0);
@@ -363,16 +367,20 @@ static void smb_direct_send_immediate_work(struct work_struct *work)
static struct smb_direct_transport *alloc_transport(struct rdma_cm_id *cm_id)
{
struct smb_direct_transport *t;
+ struct smbdirect_socket *sc;
struct ksmbd_conn *conn;
t = kzalloc(sizeof(*t), KSMBD_DEFAULT_GFP);
if (!t)
return NULL;
+ sc = &t->socket;
- t->cm_id = cm_id;
+ sc->rdma.cm_id = cm_id;
cm_id->context = t;
- t->status = SMB_DIRECT_CS_NEW;
+ sc->ib.dev = sc->rdma.cm_id->device;
+
+ sc->status = SMBDIRECT_SOCKET_CREATED;
init_waitqueue_head(&t->wait_status);
spin_lock_init(&t->reassembly_queue_lock);
@@ -414,6 +422,7 @@ static struct smb_direct_transport *alloc_transport(struct rdma_cm_id *cm_id)
static void free_transport(struct smb_direct_transport *t)
{
+ struct smbdirect_socket *sc = &t->socket;
struct smb_direct_recvmsg *recvmsg;
wake_up_interruptible(&t->wait_send_credits);
@@ -426,10 +435,10 @@ static void free_transport(struct smb_direct_transport *t)
cancel_delayed_work_sync(&t->post_recv_credits_work);
cancel_work_sync(&t->send_immediate_work);
- if (t->qp) {
- ib_drain_qp(t->qp);
- ib_mr_pool_destroy(t->qp, &t->qp->rdma_mrs);
- ib_destroy_qp(t->qp);
+ if (sc->ib.qp) {
+ ib_drain_qp(sc->ib.qp);
+ ib_mr_pool_destroy(sc->ib.qp, &sc->ib.qp->rdma_mrs);
+ ib_destroy_qp(sc->ib.qp);
}
ksmbd_debug(RDMA, "drain the reassembly queue\n");
@@ -446,14 +455,14 @@ static void free_transport(struct smb_direct_transport *t)
} while (recvmsg);
t->reassembly_data_length = 0;
- if (t->send_cq)
- ib_free_cq(t->send_cq);
- if (t->recv_cq)
- ib_free_cq(t->recv_cq);
- if (t->pd)
- ib_dealloc_pd(t->pd);
- if (t->cm_id)
- rdma_destroy_id(t->cm_id);
+ if (sc->ib.send_cq)
+ ib_free_cq(sc->ib.send_cq);
+ if (sc->ib.recv_cq)
+ ib_free_cq(sc->ib.recv_cq);
+ if (sc->ib.pd)
+ ib_dealloc_pd(sc->ib.pd);
+ if (sc->rdma.cm_id)
+ rdma_destroy_id(sc->rdma.cm_id);
smb_direct_destroy_pools(t);
ksmbd_conn_free(KSMBD_TRANS(t)->conn);
@@ -477,14 +486,15 @@ static struct smb_direct_sendmsg
static void smb_direct_free_sendmsg(struct smb_direct_transport *t,
struct smb_direct_sendmsg *msg)
{
+ struct smbdirect_socket *sc = &t->socket;
int i;
if (msg->num_sge > 0) {
- ib_dma_unmap_single(t->cm_id->device,
+ ib_dma_unmap_single(sc->ib.dev,
msg->sge[0].addr, msg->sge[0].length,
DMA_TO_DEVICE);
for (i = 1; i < msg->num_sge; i++)
- ib_dma_unmap_page(t->cm_id->device,
+ ib_dma_unmap_page(sc->ib.dev,
msg->sge[i].addr, msg->sge[i].length,
DMA_TO_DEVICE);
}
@@ -539,9 +549,11 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
{
struct smb_direct_recvmsg *recvmsg;
struct smb_direct_transport *t;
+ struct smbdirect_socket *sc;
recvmsg = container_of(wc->wr_cqe, struct smb_direct_recvmsg, cqe);
t = recvmsg->transport;
+ sc = &t->socket;
if (wc->status != IB_WC_SUCCESS || wc->opcode != IB_WC_RECV) {
if (wc->status != IB_WC_WR_FLUSH_ERR) {
@@ -569,7 +581,7 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
}
t->negotiation_requested = true;
t->full_packet_received = true;
- t->status = SMB_DIRECT_CS_CONNECTED;
+ sc->status = SMBDIRECT_SOCKET_CONNECTED;
enqueue_reassembly(t, recvmsg, 0);
wake_up_interruptible(&t->wait_status);
break;
@@ -642,17 +654,18 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
static int smb_direct_post_recv(struct smb_direct_transport *t,
struct smb_direct_recvmsg *recvmsg)
{
+ struct smbdirect_socket *sc = &t->socket;
struct ib_recv_wr wr;
int ret;
- recvmsg->sge.addr = ib_dma_map_single(t->cm_id->device,
+ recvmsg->sge.addr = ib_dma_map_single(sc->ib.dev,
recvmsg->packet, t->max_recv_size,
DMA_FROM_DEVICE);
- ret = ib_dma_mapping_error(t->cm_id->device, recvmsg->sge.addr);
+ ret = ib_dma_mapping_error(sc->ib.dev, recvmsg->sge.addr);
if (ret)
return ret;
recvmsg->sge.length = t->max_recv_size;
- recvmsg->sge.lkey = t->pd->local_dma_lkey;
+ recvmsg->sge.lkey = sc->ib.pd->local_dma_lkey;
recvmsg->cqe.done = recv_done;
wr.wr_cqe = &recvmsg->cqe;
@@ -660,10 +673,10 @@ static int smb_direct_post_recv(struct smb_direct_transport *t,
wr.sg_list = &recvmsg->sge;
wr.num_sge = 1;
- ret = ib_post_recv(t->qp, &wr, NULL);
+ ret = ib_post_recv(sc->ib.qp, &wr, NULL);
if (ret) {
pr_err("Can't post recv: %d\n", ret);
- ib_dma_unmap_single(t->cm_id->device,
+ ib_dma_unmap_single(sc->ib.dev,
recvmsg->sge.addr, recvmsg->sge.length,
DMA_FROM_DEVICE);
smb_direct_disconnect_rdma_connection(t);
@@ -681,9 +694,10 @@ static int smb_direct_read(struct ksmbd_transport *t, char *buf,
u32 data_length, remaining_data_length, data_offset;
int rc;
struct smb_direct_transport *st = smb_trans_direct_transfort(t);
+ struct smbdirect_socket *sc = &st->socket;
again:
- if (st->status != SMB_DIRECT_CS_CONNECTED) {
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
pr_err("disconnected\n");
return -ENOTCONN;
}
@@ -793,7 +807,7 @@ static int smb_direct_read(struct ksmbd_transport *t, char *buf,
ksmbd_debug(RDMA, "wait_event on more data\n");
rc = wait_event_interruptible(st->wait_reassembly_queue,
st->reassembly_data_length >= size ||
- st->status != SMB_DIRECT_CS_CONNECTED);
+ sc->status != SMBDIRECT_SOCKET_CONNECTED);
if (rc)
return -EINTR;
@@ -905,10 +919,11 @@ static int manage_credits_prior_sending(struct smb_direct_transport *t)
static int smb_direct_post_send(struct smb_direct_transport *t,
struct ib_send_wr *wr)
{
+ struct smbdirect_socket *sc = &t->socket;
int ret;
atomic_inc(&t->send_pending);
- ret = ib_post_send(t->qp, wr, NULL);
+ ret = ib_post_send(sc->ib.qp, wr, NULL);
if (ret) {
pr_err("failed to post send: %d\n", ret);
if (atomic_dec_and_test(&t->send_pending))
@@ -973,6 +988,7 @@ static int wait_for_credits(struct smb_direct_transport *t,
wait_queue_head_t *waitq, atomic_t *total_credits,
int needed)
{
+ struct smbdirect_socket *sc = &t->socket;
int ret;
do {
@@ -982,9 +998,9 @@ static int wait_for_credits(struct smb_direct_transport *t,
atomic_add(needed, total_credits);
ret = wait_event_interruptible(*waitq,
atomic_read(total_credits) >= needed ||
- t->status != SMB_DIRECT_CS_CONNECTED);
+ sc->status != SMBDIRECT_SOCKET_CONNECTED);
- if (t->status != SMB_DIRECT_CS_CONNECTED)
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED)
return -ENOTCONN;
else if (ret < 0)
return ret;
@@ -1022,6 +1038,7 @@ static int smb_direct_create_header(struct smb_direct_transport *t,
int size, int remaining_data_length,
struct smb_direct_sendmsg **sendmsg_out)
{
+ struct smbdirect_socket *sc = &t->socket;
struct smb_direct_sendmsg *sendmsg;
struct smbdirect_data_transfer *packet;
int header_length;
@@ -1061,11 +1078,11 @@ static int smb_direct_create_header(struct smb_direct_transport *t,
header_length =
offsetof(struct smbdirect_data_transfer, padding);
- sendmsg->sge[0].addr = ib_dma_map_single(t->cm_id->device,
+ sendmsg->sge[0].addr = ib_dma_map_single(sc->ib.dev,
(void *)packet,
header_length,
DMA_TO_DEVICE);
- ret = ib_dma_mapping_error(t->cm_id->device, sendmsg->sge[0].addr);
+ ret = ib_dma_mapping_error(sc->ib.dev, sendmsg->sge[0].addr);
if (ret) {
smb_direct_free_sendmsg(t, sendmsg);
return ret;
@@ -1073,7 +1090,7 @@ static int smb_direct_create_header(struct smb_direct_transport *t,
sendmsg->num_sge = 1;
sendmsg->sge[0].length = header_length;
- sendmsg->sge[0].lkey = t->pd->local_dma_lkey;
+ sendmsg->sge[0].lkey = sc->ib.pd->local_dma_lkey;
*sendmsg_out = sendmsg;
return 0;
@@ -1127,10 +1144,11 @@ static int post_sendmsg(struct smb_direct_transport *t,
struct smb_direct_send_ctx *send_ctx,
struct smb_direct_sendmsg *msg)
{
+ struct smbdirect_socket *sc = &t->socket;
int i;
for (i = 0; i < msg->num_sge; i++)
- ib_dma_sync_single_for_device(t->cm_id->device,
+ ib_dma_sync_single_for_device(sc->ib.dev,
msg->sge[i].addr, msg->sge[i].length,
DMA_TO_DEVICE);
@@ -1166,6 +1184,7 @@ static int smb_direct_post_send_data(struct smb_direct_transport *t,
struct kvec *iov, int niov,
int remaining_data_length)
{
+ struct smbdirect_socket *sc = &t->socket;
int i, j, ret;
struct smb_direct_sendmsg *msg;
int data_length;
@@ -1191,7 +1210,7 @@ static int smb_direct_post_send_data(struct smb_direct_transport *t,
int sg_cnt;
sg_init_table(sg, SMB_DIRECT_MAX_SEND_SGES - 1);
- sg_cnt = get_mapped_sg_list(t->cm_id->device,
+ sg_cnt = get_mapped_sg_list(sc->ib.dev,
iov[i].iov_base, iov[i].iov_len,
sg, SMB_DIRECT_MAX_SEND_SGES - 1,
DMA_TO_DEVICE);
@@ -1202,7 +1221,7 @@ static int smb_direct_post_send_data(struct smb_direct_transport *t,
} else if (sg_cnt + msg->num_sge > SMB_DIRECT_MAX_SEND_SGES) {
pr_err("buffer not fitted into sges\n");
ret = -E2BIG;
- ib_dma_unmap_sg(t->cm_id->device, sg, sg_cnt,
+ ib_dma_unmap_sg(sc->ib.dev, sg, sg_cnt,
DMA_TO_DEVICE);
goto err;
}
@@ -1211,7 +1230,7 @@ static int smb_direct_post_send_data(struct smb_direct_transport *t,
sge = &msg->sge[msg->num_sge];
sge->addr = sg_dma_address(&sg[j]);
sge->length = sg_dma_len(&sg[j]);
- sge->lkey = t->pd->local_dma_lkey;
+ sge->lkey = sc->ib.pd->local_dma_lkey;
msg->num_sge++;
}
}
@@ -1231,6 +1250,7 @@ static int smb_direct_writev(struct ksmbd_transport *t,
bool need_invalidate, unsigned int remote_key)
{
struct smb_direct_transport *st = smb_trans_direct_transfort(t);
+ struct smbdirect_socket *sc = &st->socket;
int remaining_data_length;
int start, i, j;
int max_iov_size = st->max_send_size -
@@ -1239,7 +1259,7 @@ static int smb_direct_writev(struct ksmbd_transport *t,
struct kvec vec;
struct smb_direct_send_ctx send_ctx;
- if (st->status != SMB_DIRECT_CS_CONNECTED)
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED)
return -ENOTCONN;
//FIXME: skip RFC1002 header..
@@ -1320,7 +1340,9 @@ static void smb_direct_free_rdma_rw_msg(struct smb_direct_transport *t,
struct smb_direct_rdma_rw_msg *msg,
enum dma_data_direction dir)
{
- rdma_rw_ctx_destroy(&msg->rw_ctx, t->qp, t->qp->port,
+ struct smbdirect_socket *sc = &t->socket;
+
+ rdma_rw_ctx_destroy(&msg->rw_ctx, sc->ib.qp, sc->ib.qp->port,
msg->sgt.sgl, msg->sgt.nents, dir);
sg_free_table_chained(&msg->sgt, SG_CHUNK_SIZE);
kfree(msg);
@@ -1360,6 +1382,7 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
unsigned int desc_len,
bool is_read)
{
+ struct smbdirect_socket *sc = &t->socket;
struct smb_direct_rdma_rw_msg *msg, *next_msg;
int i, ret;
DECLARE_COMPLETION_ONSTACK(completion);
@@ -1369,7 +1392,7 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
int credits_needed;
unsigned int desc_buf_len, desc_num = 0;
- if (t->status != SMB_DIRECT_CS_CONNECTED)
+ if (sc->status != SMBDIRECT_SOCKET_CONNECTED)
return -ENOTCONN;
if (buf_len > t->max_rdma_rw_size)
@@ -1439,7 +1462,7 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
goto out;
}
- ret = rdma_rw_ctx_init(&msg->rw_ctx, t->qp, t->qp->port,
+ ret = rdma_rw_ctx_init(&msg->rw_ctx, sc->ib.qp, sc->ib.qp->port,
msg->sgt.sgl,
get_buf_page_count(desc_buf, desc_buf_len),
0,
@@ -1460,11 +1483,11 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
/* concatenate work requests of rdma_rw_ctxs */
first_wr = NULL;
list_for_each_entry_reverse(msg, &msg_list, list) {
- first_wr = rdma_rw_ctx_wrs(&msg->rw_ctx, t->qp, t->qp->port,
+ first_wr = rdma_rw_ctx_wrs(&msg->rw_ctx, sc->ib.qp, sc->ib.qp->port,
&msg->cqe, first_wr);
}
- ret = ib_post_send(t->qp, first_wr, NULL);
+ ret = ib_post_send(sc->ib.qp, first_wr, NULL);
if (ret) {
pr_err("failed to post send wr for RDMA R/W: %d\n", ret);
goto out;
@@ -1505,20 +1528,22 @@ static int smb_direct_rdma_read(struct ksmbd_transport *t,
static void smb_direct_disconnect(struct ksmbd_transport *t)
{
struct smb_direct_transport *st = smb_trans_direct_transfort(t);
+ struct smbdirect_socket *sc = &st->socket;
- ksmbd_debug(RDMA, "Disconnecting cm_id=%p\n", st->cm_id);
+ ksmbd_debug(RDMA, "Disconnecting cm_id=%p\n", sc->rdma.cm_id);
smb_direct_disconnect_rdma_work(&st->disconnect_work);
wait_event_interruptible(st->wait_status,
- st->status == SMB_DIRECT_CS_DISCONNECTED);
+ sc->status == SMBDIRECT_SOCKET_DISCONNECTED);
free_transport(st);
}
static void smb_direct_shutdown(struct ksmbd_transport *t)
{
struct smb_direct_transport *st = smb_trans_direct_transfort(t);
+ struct smbdirect_socket *sc = &st->socket;
- ksmbd_debug(RDMA, "smb-direct shutdown cm_id=%p\n", st->cm_id);
+ ksmbd_debug(RDMA, "smb-direct shutdown cm_id=%p\n", sc->rdma.cm_id);
smb_direct_disconnect_rdma_work(&st->disconnect_work);
}
@@ -1527,28 +1552,29 @@ static int smb_direct_cm_handler(struct rdma_cm_id *cm_id,
struct rdma_cm_event *event)
{
struct smb_direct_transport *t = cm_id->context;
+ struct smbdirect_socket *sc = &t->socket;
ksmbd_debug(RDMA, "RDMA CM event. cm_id=%p event=%s (%d)\n",
cm_id, rdma_event_msg(event->event), event->event);
switch (event->event) {
case RDMA_CM_EVENT_ESTABLISHED: {
- t->status = SMB_DIRECT_CS_CONNECTED;
+ sc->status = SMBDIRECT_SOCKET_CONNECTED;
wake_up_interruptible(&t->wait_status);
break;
}
case RDMA_CM_EVENT_DEVICE_REMOVAL:
case RDMA_CM_EVENT_DISCONNECTED: {
- ib_drain_qp(t->qp);
+ ib_drain_qp(sc->ib.qp);
- t->status = SMB_DIRECT_CS_DISCONNECTED;
+ sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
wake_up_interruptible(&t->wait_status);
wake_up_interruptible(&t->wait_reassembly_queue);
wake_up(&t->wait_send_credits);
break;
}
case RDMA_CM_EVENT_CONNECT_ERROR: {
- t->status = SMB_DIRECT_CS_DISCONNECTED;
+ sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
wake_up_interruptible(&t->wait_status);
break;
}
@@ -1564,9 +1590,10 @@ static int smb_direct_cm_handler(struct rdma_cm_id *cm_id,
static void smb_direct_qpair_handler(struct ib_event *event, void *context)
{
struct smb_direct_transport *t = context;
+ struct smbdirect_socket *sc = &t->socket;
ksmbd_debug(RDMA, "Received QP event. cm_id=%p, event=%s (%d)\n",
- t->cm_id, ib_event_msg(event->event), event->event);
+ sc->rdma.cm_id, ib_event_msg(event->event), event->event);
switch (event->event) {
case IB_EVENT_CQ_ERR:
@@ -1581,6 +1608,7 @@ static void smb_direct_qpair_handler(struct ib_event *event, void *context)
static int smb_direct_send_negotiate_response(struct smb_direct_transport *t,
int failed)
{
+ struct smbdirect_socket *sc = &t->socket;
struct smb_direct_sendmsg *sendmsg;
struct smbdirect_negotiate_resp *resp;
int ret;
@@ -1611,10 +1639,10 @@ static int smb_direct_send_negotiate_response(struct smb_direct_transport *t,
cpu_to_le32(t->max_fragmented_recv_size);
}
- sendmsg->sge[0].addr = ib_dma_map_single(t->cm_id->device,
+ sendmsg->sge[0].addr = ib_dma_map_single(sc->ib.dev,
(void *)resp, sizeof(*resp),
DMA_TO_DEVICE);
- ret = ib_dma_mapping_error(t->cm_id->device, sendmsg->sge[0].addr);
+ ret = ib_dma_mapping_error(sc->ib.dev, sendmsg->sge[0].addr);
if (ret) {
smb_direct_free_sendmsg(t, sendmsg);
return ret;
@@ -1622,7 +1650,7 @@ static int smb_direct_send_negotiate_response(struct smb_direct_transport *t,
sendmsg->num_sge = 1;
sendmsg->sge[0].length = sizeof(*resp);
- sendmsg->sge[0].lkey = t->pd->local_dma_lkey;
+ sendmsg->sge[0].lkey = sc->ib.pd->local_dma_lkey;
ret = post_sendmsg(t, NULL, sendmsg);
if (ret) {
@@ -1637,19 +1665,20 @@ static int smb_direct_send_negotiate_response(struct smb_direct_transport *t,
static int smb_direct_accept_client(struct smb_direct_transport *t)
{
+ struct smbdirect_socket *sc = &t->socket;
struct rdma_conn_param conn_param;
struct ib_port_immutable port_immutable;
u32 ird_ord_hdr[2];
int ret;
memset(&conn_param, 0, sizeof(conn_param));
- conn_param.initiator_depth = min_t(u8, t->cm_id->device->attrs.max_qp_rd_atom,
+ conn_param.initiator_depth = min_t(u8, sc->ib.dev->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);
+ sc->ib.dev->ops.get_port_immutable(sc->ib.dev,
+ sc->rdma.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;
@@ -1663,7 +1692,7 @@ static int smb_direct_accept_client(struct smb_direct_transport *t)
conn_param.rnr_retry_count = SMB_DIRECT_CM_RNR_RETRY;
conn_param.flow_control = 0;
- ret = rdma_accept(t->cm_id, &conn_param);
+ ret = rdma_accept(sc->rdma.cm_id, &conn_param);
if (ret) {
pr_err("error at rdma_accept: %d\n", ret);
return ret;
@@ -1703,15 +1732,18 @@ static int smb_direct_prepare_negotiation(struct smb_direct_transport *t)
static unsigned int smb_direct_get_max_fr_pages(struct smb_direct_transport *t)
{
+ struct smbdirect_socket *sc = &t->socket;
+
return min_t(unsigned int,
- t->cm_id->device->attrs.max_fast_reg_page_list_len,
+ sc->ib.dev->attrs.max_fast_reg_page_list_len,
256);
}
static int smb_direct_init_params(struct smb_direct_transport *t,
struct ib_qp_cap *cap)
{
- struct ib_device *device = t->cm_id->device;
+ struct smbdirect_socket *sc = &t->socket;
+ struct ib_device *device = sc->ib.dev;
int max_send_sges, max_rw_wrs, max_send_wrs;
unsigned int max_sge_per_wr, wrs_per_credit;
@@ -1872,34 +1904,35 @@ static int smb_direct_create_pools(struct smb_direct_transport *t)
static int smb_direct_create_qpair(struct smb_direct_transport *t,
struct ib_qp_cap *cap)
{
+ struct smbdirect_socket *sc = &t->socket;
int ret;
struct ib_qp_init_attr qp_attr;
int pages_per_rw;
- t->pd = ib_alloc_pd(t->cm_id->device, 0);
- if (IS_ERR(t->pd)) {
+ sc->ib.pd = ib_alloc_pd(sc->ib.dev, 0);
+ if (IS_ERR(sc->ib.pd)) {
pr_err("Can't create RDMA PD\n");
- ret = PTR_ERR(t->pd);
- t->pd = NULL;
+ ret = PTR_ERR(sc->ib.pd);
+ sc->ib.pd = NULL;
return ret;
}
- t->send_cq = ib_alloc_cq(t->cm_id->device, t,
+ sc->ib.send_cq = ib_alloc_cq(sc->ib.dev, t,
smb_direct_send_credit_target + cap->max_rdma_ctxs,
0, IB_POLL_WORKQUEUE);
- if (IS_ERR(t->send_cq)) {
+ if (IS_ERR(sc->ib.send_cq)) {
pr_err("Can't create RDMA send CQ\n");
- ret = PTR_ERR(t->send_cq);
- t->send_cq = NULL;
+ ret = PTR_ERR(sc->ib.send_cq);
+ sc->ib.send_cq = NULL;
goto err;
}
- t->recv_cq = ib_alloc_cq(t->cm_id->device, t,
+ sc->ib.recv_cq = ib_alloc_cq(sc->ib.dev, t,
t->recv_credit_max, 0, IB_POLL_WORKQUEUE);
- if (IS_ERR(t->recv_cq)) {
+ if (IS_ERR(sc->ib.recv_cq)) {
pr_err("Can't create RDMA recv CQ\n");
- ret = PTR_ERR(t->recv_cq);
- t->recv_cq = NULL;
+ ret = PTR_ERR(sc->ib.recv_cq);
+ sc->ib.recv_cq = NULL;
goto err;
}
@@ -1909,22 +1942,22 @@ static int smb_direct_create_qpair(struct smb_direct_transport *t,
qp_attr.cap = *cap;
qp_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
qp_attr.qp_type = IB_QPT_RC;
- qp_attr.send_cq = t->send_cq;
- qp_attr.recv_cq = t->recv_cq;
+ qp_attr.send_cq = sc->ib.send_cq;
+ qp_attr.recv_cq = sc->ib.recv_cq;
qp_attr.port_num = ~0;
- ret = rdma_create_qp(t->cm_id, t->pd, &qp_attr);
+ ret = rdma_create_qp(sc->rdma.cm_id, sc->ib.pd, &qp_attr);
if (ret) {
pr_err("Can't create RDMA QP: %d\n", ret);
goto err;
}
- t->qp = t->cm_id->qp;
- t->cm_id->event_handler = smb_direct_cm_handler;
+ sc->ib.qp = sc->rdma.cm_id->qp;
+ sc->rdma.cm_id->event_handler = smb_direct_cm_handler;
pages_per_rw = DIV_ROUND_UP(t->max_rdma_rw_size, PAGE_SIZE) + 1;
- if (pages_per_rw > t->cm_id->device->attrs.max_sgl_rd) {
- ret = ib_mr_pool_init(t->qp, &t->qp->rdma_mrs,
+ if (pages_per_rw > sc->ib.dev->attrs.max_sgl_rd) {
+ ret = ib_mr_pool_init(sc->ib.qp, &sc->ib.qp->rdma_mrs,
t->max_rw_credits, IB_MR_TYPE_MEM_REG,
t->pages_per_rw_credit, 0);
if (ret) {
@@ -1936,21 +1969,21 @@ static int smb_direct_create_qpair(struct smb_direct_transport *t,
return 0;
err:
- if (t->qp) {
- ib_destroy_qp(t->qp);
- t->qp = NULL;
+ if (sc->ib.qp) {
+ ib_destroy_qp(sc->ib.qp);
+ sc->ib.qp = NULL;
}
- if (t->recv_cq) {
- ib_destroy_cq(t->recv_cq);
- t->recv_cq = NULL;
+ if (sc->ib.recv_cq) {
+ ib_destroy_cq(sc->ib.recv_cq);
+ sc->ib.recv_cq = NULL;
}
- if (t->send_cq) {
- ib_destroy_cq(t->send_cq);
- t->send_cq = NULL;
+ if (sc->ib.send_cq) {
+ ib_destroy_cq(sc->ib.send_cq);
+ sc->ib.send_cq = NULL;
}
- if (t->pd) {
- ib_dealloc_pd(t->pd);
- t->pd = NULL;
+ if (sc->ib.pd) {
+ ib_dealloc_pd(sc->ib.pd);
+ sc->ib.pd = NULL;
}
return ret;
}
@@ -1958,6 +1991,7 @@ static int smb_direct_create_qpair(struct smb_direct_transport *t,
static int smb_direct_prepare(struct ksmbd_transport *t)
{
struct smb_direct_transport *st = smb_trans_direct_transfort(t);
+ struct smbdirect_socket *sc = &st->socket;
struct smb_direct_recvmsg *recvmsg;
struct smbdirect_negotiate_req *req;
int ret;
@@ -1965,9 +1999,9 @@ static int smb_direct_prepare(struct ksmbd_transport *t)
ksmbd_debug(RDMA, "Waiting for SMB_DIRECT negotiate request\n");
ret = wait_event_interruptible_timeout(st->wait_status,
st->negotiation_requested ||
- st->status == SMB_DIRECT_CS_DISCONNECTED,
+ sc->status == SMBDIRECT_SOCKET_DISCONNECTED,
SMB_DIRECT_NEGOTIATE_TIMEOUT * HZ);
- if (ret <= 0 || st->status == SMB_DIRECT_CS_DISCONNECTED)
+ if (ret <= 0 || sc->status == SMBDIRECT_SOCKET_DISCONNECTED)
return ret < 0 ? ret : -ETIMEDOUT;
recvmsg = get_first_reassembly(st);
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 10/12] smb: smbdirect: introduce smbdirect_socket_parameters
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (8 preceding siblings ...)
2025-05-28 16:01 ` [PATCH v2 09/12] smb: server: " Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 11/12] smb: client: make use of common smbdirect_socket_parameters Stefan Metzmacher
` (3 subsequent siblings)
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
This is the next step in the direction of a common smbdirect layer.
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/client/smbdirect.h | 1 +
fs/smb/common/smbdirect/smbdirect.h | 20 ++++++++++++++++++++
fs/smb/common/smbdirect/smbdirect_socket.h | 2 ++
3 files changed, 23 insertions(+)
diff --git a/fs/smb/client/smbdirect.h b/fs/smb/client/smbdirect.h
index 904c4e5b9e5c..3d325d73364a 100644
--- a/fs/smb/client/smbdirect.h
+++ b/fs/smb/client/smbdirect.h
@@ -15,6 +15,7 @@
#include <rdma/rdma_cm.h>
#include <linux/mempool.h>
+#include "../common/smbdirect/smbdirect.h"
#include "../common/smbdirect/smbdirect_socket.h"
extern int rdma_readwrite_threshold;
diff --git a/fs/smb/common/smbdirect/smbdirect.h b/fs/smb/common/smbdirect/smbdirect.h
index eedbdf0d0433..b9a385344ff3 100644
--- a/fs/smb/common/smbdirect/smbdirect.h
+++ b/fs/smb/common/smbdirect/smbdirect.h
@@ -14,4 +14,24 @@ struct smbdirect_buffer_descriptor_v1 {
__le32 length;
} __packed;
+/*
+ * Connection parameters mostly from [MS-SMBD] 3.1.1.1
+ *
+ * These are setup and negotiated at the beginning of a
+ * connection and remain constant unless explicitly changed.
+ *
+ * Some values are important for the upper layer.
+ */
+struct smbdirect_socket_parameters {
+ __u16 recv_credit_max;
+ __u16 send_credit_target;
+ __u32 max_send_size;
+ __u32 max_fragmented_send_size;
+ __u32 max_recv_size;
+ __u32 max_fragmented_recv_size;
+ __u32 max_read_write_size;
+ __u32 keepalive_interval_msec;
+ __u32 keepalive_timeout_msec;
+} __packed;
+
#endif /* __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_H__ */
diff --git a/fs/smb/common/smbdirect/smbdirect_socket.h b/fs/smb/common/smbdirect/smbdirect_socket.h
index 69a55561f91a..e5b15cc44a7b 100644
--- a/fs/smb/common/smbdirect/smbdirect_socket.h
+++ b/fs/smb/common/smbdirect/smbdirect_socket.h
@@ -36,6 +36,8 @@ struct smbdirect_socket {
struct ib_qp *qp;
struct ib_device *dev;
} ib;
+
+ struct smbdirect_socket_parameters parameters;
};
#endif /* __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_SOCKET_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 11/12] smb: client: make use of common smbdirect_socket_parameters
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (9 preceding siblings ...)
2025-05-28 16:01 ` [PATCH v2 10/12] smb: smbdirect: introduce smbdirect_socket_parameters Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 12/12] smb: server: " Stefan Metzmacher
` (2 subsequent siblings)
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/client/cifs_debug.c | 21 +++++----
fs/smb/client/smb2ops.c | 14 ++++--
fs/smb/client/smbdirect.c | 91 ++++++++++++++++++++++----------------
fs/smb/client/smbdirect.h | 10 +----
4 files changed, 77 insertions(+), 59 deletions(-)
diff --git a/fs/smb/client/cifs_debug.c b/fs/smb/client/cifs_debug.c
index 56b0b5c82dd1..c0196be0e65f 100644
--- a/fs/smb/client/cifs_debug.c
+++ b/fs/smb/client/cifs_debug.c
@@ -362,6 +362,10 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
c = 0;
spin_lock(&cifs_tcp_ses_lock);
list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
+#ifdef CONFIG_CIFS_SMB_DIRECT
+ struct smbdirect_socket_parameters *sp;
+#endif
+
/* channel info will be printed as a part of sessions below */
if (SERVER_IS_CHAN(server))
continue;
@@ -383,6 +387,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
seq_printf(m, "\nSMBDirect transport not available");
goto skip_rdma;
}
+ sp = &server->smbd_conn->socket.parameters;
seq_printf(m, "\nSMBDirect (in hex) protocol version: %x "
"transport status: %x",
@@ -390,18 +395,18 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
server->smbd_conn->socket.status);
seq_printf(m, "\nConn receive_credit_max: %x "
"send_credit_target: %x max_send_size: %x",
- server->smbd_conn->receive_credit_max,
- server->smbd_conn->send_credit_target,
- server->smbd_conn->max_send_size);
+ sp->recv_credit_max,
+ sp->send_credit_target,
+ sp->max_send_size);
seq_printf(m, "\nConn max_fragmented_recv_size: %x "
"max_fragmented_send_size: %x max_receive_size:%x",
- server->smbd_conn->max_fragmented_recv_size,
- server->smbd_conn->max_fragmented_send_size,
- server->smbd_conn->max_receive_size);
+ sp->max_fragmented_recv_size,
+ sp->max_fragmented_send_size,
+ sp->max_recv_size);
seq_printf(m, "\nConn keep_alive_interval: %x "
"max_readwrite_size: %x rdma_readwrite_threshold: %x",
- server->smbd_conn->keep_alive_interval,
- server->smbd_conn->max_readwrite_size,
+ sp->keepalive_interval_msec * 1000,
+ sp->max_read_write_size,
server->smbd_conn->rdma_readwrite_threshold);
seq_printf(m, "\nDebug count_get_receive_buffer: %x "
"count_put_receive_buffer: %x count_send_empty: %x",
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 2fe8eeb98535..8ee7b3dde12f 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -504,6 +504,9 @@ smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
wsize = min_t(unsigned int, wsize, server->max_write);
#ifdef CONFIG_CIFS_SMB_DIRECT
if (server->rdma) {
+ struct smbdirect_socket_parameters *sp =
+ &server->smbd_conn->socket.parameters;
+
if (server->sign)
/*
* Account for SMB2 data transfer packet header and
@@ -511,12 +514,12 @@ smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
*/
wsize = min_t(unsigned int,
wsize,
- server->smbd_conn->max_fragmented_send_size -
+ sp->max_fragmented_send_size -
SMB2_READWRITE_PDU_HEADER_SIZE -
sizeof(struct smb2_transform_hdr));
else
wsize = min_t(unsigned int,
- wsize, server->smbd_conn->max_readwrite_size);
+ wsize, sp->max_read_write_size);
}
#endif
if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
@@ -552,6 +555,9 @@ smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
rsize = min_t(unsigned int, rsize, server->max_read);
#ifdef CONFIG_CIFS_SMB_DIRECT
if (server->rdma) {
+ struct smbdirect_socket_parameters *sp =
+ &server->smbd_conn->socket.parameters;
+
if (server->sign)
/*
* Account for SMB2 data transfer packet header and
@@ -559,12 +565,12 @@ smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
*/
rsize = min_t(unsigned int,
rsize,
- server->smbd_conn->max_fragmented_recv_size -
+ sp->max_fragmented_recv_size -
SMB2_READWRITE_PDU_HEADER_SIZE -
sizeof(struct smb2_transform_hdr));
else
rsize = min_t(unsigned int,
- rsize, server->smbd_conn->max_readwrite_size);
+ rsize, sp->max_read_write_size);
}
#endif
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index 608ecd2149ed..5ae847919da5 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -320,6 +320,8 @@ static bool process_negotiation_response(
struct smbd_response *response, int packet_length)
{
struct smbd_connection *info = response->info;
+ struct smbdirect_socket *sc = &info->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct smbdirect_negotiate_resp *packet = smbd_response_payload(response);
if (packet_length < sizeof(struct smbdirect_negotiate_resp)) {
@@ -349,20 +351,20 @@ static bool process_negotiation_response(
atomic_set(&info->receive_credits, 0);
- if (le32_to_cpu(packet->preferred_send_size) > info->max_receive_size) {
+ if (le32_to_cpu(packet->preferred_send_size) > sp->max_recv_size) {
log_rdma_event(ERR, "error: preferred_send_size=%d\n",
le32_to_cpu(packet->preferred_send_size));
return false;
}
- info->max_receive_size = le32_to_cpu(packet->preferred_send_size);
+ sp->max_recv_size = le32_to_cpu(packet->preferred_send_size);
if (le32_to_cpu(packet->max_receive_size) < SMBD_MIN_RECEIVE_SIZE) {
log_rdma_event(ERR, "error: max_receive_size=%d\n",
le32_to_cpu(packet->max_receive_size));
return false;
}
- info->max_send_size = min_t(int, info->max_send_size,
- le32_to_cpu(packet->max_receive_size));
+ sp->max_send_size = min_t(u32, sp->max_send_size,
+ le32_to_cpu(packet->max_receive_size));
if (le32_to_cpu(packet->max_fragmented_size) <
SMBD_MIN_FRAGMENTED_SIZE) {
@@ -370,18 +372,18 @@ static bool process_negotiation_response(
le32_to_cpu(packet->max_fragmented_size));
return false;
}
- info->max_fragmented_send_size =
+ sp->max_fragmented_send_size =
le32_to_cpu(packet->max_fragmented_size);
info->rdma_readwrite_threshold =
- rdma_readwrite_threshold > info->max_fragmented_send_size ?
- info->max_fragmented_send_size :
+ rdma_readwrite_threshold > sp->max_fragmented_send_size ?
+ sp->max_fragmented_send_size :
rdma_readwrite_threshold;
- info->max_readwrite_size = min_t(u32,
+ sp->max_read_write_size = min_t(u32,
le32_to_cpu(packet->max_readwrite_size),
info->max_frmr_depth * PAGE_SIZE);
- info->max_frmr_depth = info->max_readwrite_size / PAGE_SIZE;
+ info->max_frmr_depth = sp->max_read_write_size / PAGE_SIZE;
return true;
}
@@ -689,6 +691,7 @@ static int smbd_ia_open(
static int smbd_post_send_negotiate_req(struct smbd_connection *info)
{
struct smbdirect_socket *sc = &info->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct ib_send_wr send_wr;
int rc = -ENOMEM;
struct smbd_request *request;
@@ -704,11 +707,11 @@ static int smbd_post_send_negotiate_req(struct smbd_connection *info)
packet->min_version = cpu_to_le16(SMBDIRECT_V1);
packet->max_version = cpu_to_le16(SMBDIRECT_V1);
packet->reserved = 0;
- packet->credits_requested = cpu_to_le16(info->send_credit_target);
- packet->preferred_send_size = cpu_to_le32(info->max_send_size);
- packet->max_receive_size = cpu_to_le32(info->max_receive_size);
+ packet->credits_requested = cpu_to_le16(sp->send_credit_target);
+ packet->preferred_send_size = cpu_to_le32(sp->max_send_size);
+ packet->max_receive_size = cpu_to_le32(sp->max_recv_size);
packet->max_fragmented_size =
- cpu_to_le32(info->max_fragmented_recv_size);
+ cpu_to_le32(sp->max_fragmented_recv_size);
request->num_sge = 1;
request->sge[0].addr = ib_dma_map_single(
@@ -800,6 +803,7 @@ static int smbd_post_send(struct smbd_connection *info,
struct smbd_request *request)
{
struct smbdirect_socket *sc = &info->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct ib_send_wr send_wr;
int rc, i;
@@ -831,7 +835,7 @@ static int smbd_post_send(struct smbd_connection *info,
} else
/* Reset timer for idle connection after packet is sent */
mod_delayed_work(info->workqueue, &info->idle_timer_work,
- info->keep_alive_interval*HZ);
+ msecs_to_jiffies(sp->keepalive_interval_msec));
return rc;
}
@@ -841,6 +845,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
int *_remaining_data_length)
{
struct smbdirect_socket *sc = &info->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
int i, rc;
int header_length;
int data_length;
@@ -868,7 +873,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
wait_send_queue:
wait_event(info->wait_post_send,
- atomic_read(&info->send_pending) < info->send_credit_target ||
+ atomic_read(&info->send_pending) < sp->send_credit_target ||
sc->status != SMBDIRECT_SOCKET_CONNECTED);
if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
@@ -878,7 +883,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
}
if (unlikely(atomic_inc_return(&info->send_pending) >
- info->send_credit_target)) {
+ sp->send_credit_target)) {
atomic_dec(&info->send_pending);
goto wait_send_queue;
}
@@ -917,7 +922,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
/* Fill in the packet header */
packet = smbd_request_payload(request);
- packet->credits_requested = cpu_to_le16(info->send_credit_target);
+ packet->credits_requested = cpu_to_le16(sp->send_credit_target);
new_credits = manage_credits_prior_sending(info);
atomic_add(new_credits, &info->receive_credits);
@@ -1017,16 +1022,17 @@ static int smbd_post_recv(
struct smbd_connection *info, struct smbd_response *response)
{
struct smbdirect_socket *sc = &info->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct ib_recv_wr recv_wr;
int rc = -EIO;
response->sge.addr = ib_dma_map_single(
sc->ib.dev, response->packet,
- info->max_receive_size, DMA_FROM_DEVICE);
+ sp->max_recv_size, DMA_FROM_DEVICE);
if (ib_dma_mapping_error(sc->ib.dev, response->sge.addr))
return rc;
- response->sge.length = info->max_receive_size;
+ response->sge.length = sp->max_recv_size;
response->sge.lkey = sc->ib.pd->local_dma_lkey;
response->cqe.done = recv_done;
@@ -1274,6 +1280,8 @@ static void idle_connection_timer(struct work_struct *work)
struct smbd_connection *info = container_of(
work, struct smbd_connection,
idle_timer_work.work);
+ struct smbdirect_socket *sc = &info->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
if (info->keep_alive_requested != KEEP_ALIVE_NONE) {
log_keep_alive(ERR,
@@ -1288,7 +1296,7 @@ static void idle_connection_timer(struct work_struct *work)
/* Setup the next idle timeout work */
queue_delayed_work(info->workqueue, &info->idle_timer_work,
- info->keep_alive_interval*HZ);
+ msecs_to_jiffies(sp->keepalive_interval_msec));
}
/*
@@ -1300,6 +1308,7 @@ void smbd_destroy(struct TCP_Server_Info *server)
{
struct smbd_connection *info = server->smbd_conn;
struct smbdirect_socket *sc;
+ struct smbdirect_socket_parameters *sp;
struct smbd_response *response;
unsigned long flags;
@@ -1308,6 +1317,7 @@ void smbd_destroy(struct TCP_Server_Info *server)
return;
}
sc = &info->socket;
+ sp = &sc->parameters;
log_rdma_event(INFO, "destroying rdma session\n");
if (sc->status != SMBDIRECT_SOCKET_DISCONNECTED) {
@@ -1349,7 +1359,7 @@ void smbd_destroy(struct TCP_Server_Info *server)
log_rdma_event(INFO, "free receive buffers\n");
wait_event(info->wait_receive_queues,
info->count_receive_queue + info->count_empty_packet_queue
- == info->receive_credit_max);
+ == sp->recv_credit_max);
destroy_receive_buffers(info);
/*
@@ -1437,6 +1447,8 @@ static void destroy_caches_and_workqueue(struct smbd_connection *info)
#define MAX_NAME_LEN 80
static int allocate_caches_and_workqueue(struct smbd_connection *info)
{
+ struct smbdirect_socket *sc = &info->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
char name[MAX_NAME_LEN];
int rc;
@@ -1451,7 +1463,7 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
return -ENOMEM;
info->request_mempool =
- mempool_create(info->send_credit_target, mempool_alloc_slab,
+ mempool_create(sp->send_credit_target, mempool_alloc_slab,
mempool_free_slab, info->request_cache);
if (!info->request_mempool)
goto out1;
@@ -1461,13 +1473,13 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
kmem_cache_create(
name,
sizeof(struct smbd_response) +
- info->max_receive_size,
+ sp->max_recv_size,
0, SLAB_HWCACHE_ALIGN, NULL);
if (!info->response_cache)
goto out2;
info->response_mempool =
- mempool_create(info->receive_credit_max, mempool_alloc_slab,
+ mempool_create(sp->recv_credit_max, mempool_alloc_slab,
mempool_free_slab, info->response_cache);
if (!info->response_mempool)
goto out3;
@@ -1477,7 +1489,7 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
if (!info->workqueue)
goto out4;
- rc = allocate_receive_buffers(info, info->receive_credit_max);
+ rc = allocate_receive_buffers(info, sp->recv_credit_max);
if (rc) {
log_rdma_event(ERR, "failed to allocate receive buffers\n");
goto out5;
@@ -1505,6 +1517,7 @@ static struct smbd_connection *_smbd_get_connection(
int rc;
struct smbd_connection *info;
struct smbdirect_socket *sc;
+ struct smbdirect_socket_parameters *sp;
struct rdma_conn_param conn_param;
struct ib_qp_init_attr qp_attr;
struct sockaddr_in *addr_in = (struct sockaddr_in *) dstaddr;
@@ -1515,6 +1528,7 @@ static struct smbd_connection *_smbd_get_connection(
if (!info)
return NULL;
sc = &info->socket;
+ sp = &sc->parameters;
sc->status = SMBDIRECT_SOCKET_CONNECTING;
rc = smbd_ia_open(info, dstaddr, port);
@@ -1541,12 +1555,12 @@ static struct smbd_connection *_smbd_get_connection(
goto config_failed;
}
- info->receive_credit_max = smbd_receive_credit_max;
- info->send_credit_target = smbd_send_credit_target;
- info->max_send_size = smbd_max_send_size;
- info->max_fragmented_recv_size = smbd_max_fragmented_recv_size;
- info->max_receive_size = smbd_max_receive_size;
- info->keep_alive_interval = smbd_keep_alive_interval;
+ sp->recv_credit_max = smbd_receive_credit_max;
+ sp->send_credit_target = smbd_send_credit_target;
+ sp->max_send_size = smbd_max_send_size;
+ sp->max_fragmented_recv_size = smbd_max_fragmented_recv_size;
+ sp->max_recv_size = smbd_max_receive_size;
+ sp->keepalive_interval_msec = smbd_keep_alive_interval * 1000;
if (sc->ib.dev->attrs.max_send_sge < SMBDIRECT_MAX_SEND_SGE ||
sc->ib.dev->attrs.max_recv_sge < SMBDIRECT_MAX_RECV_SGE) {
@@ -1561,7 +1575,7 @@ static struct smbd_connection *_smbd_get_connection(
sc->ib.send_cq =
ib_alloc_cq_any(sc->ib.dev, info,
- info->send_credit_target, IB_POLL_SOFTIRQ);
+ sp->send_credit_target, IB_POLL_SOFTIRQ);
if (IS_ERR(sc->ib.send_cq)) {
sc->ib.send_cq = NULL;
goto alloc_cq_failed;
@@ -1569,7 +1583,7 @@ static struct smbd_connection *_smbd_get_connection(
sc->ib.recv_cq =
ib_alloc_cq_any(sc->ib.dev, info,
- info->receive_credit_max, IB_POLL_SOFTIRQ);
+ sp->recv_credit_max, IB_POLL_SOFTIRQ);
if (IS_ERR(sc->ib.recv_cq)) {
sc->ib.recv_cq = NULL;
goto alloc_cq_failed;
@@ -1578,8 +1592,8 @@ static struct smbd_connection *_smbd_get_connection(
memset(&qp_attr, 0, sizeof(qp_attr));
qp_attr.event_handler = smbd_qp_async_error_upcall;
qp_attr.qp_context = info;
- qp_attr.cap.max_send_wr = info->send_credit_target;
- qp_attr.cap.max_recv_wr = info->receive_credit_max;
+ qp_attr.cap.max_send_wr = sp->send_credit_target;
+ qp_attr.cap.max_recv_wr = sp->recv_credit_max;
qp_attr.cap.max_send_sge = SMBDIRECT_MAX_SEND_SGE;
qp_attr.cap.max_recv_sge = SMBDIRECT_MAX_RECV_SGE;
qp_attr.cap.max_inline_data = 0;
@@ -1654,7 +1668,7 @@ static struct smbd_connection *_smbd_get_connection(
init_waitqueue_head(&info->wait_send_queue);
INIT_DELAYED_WORK(&info->idle_timer_work, idle_connection_timer);
queue_delayed_work(info->workqueue, &info->idle_timer_work,
- info->keep_alive_interval*HZ);
+ msecs_to_jiffies(sp->keepalive_interval_msec));
init_waitqueue_head(&info->wait_send_pending);
atomic_set(&info->send_pending, 0);
@@ -1971,6 +1985,7 @@ int smbd_send(struct TCP_Server_Info *server,
{
struct smbd_connection *info = server->smbd_conn;
struct smbdirect_socket *sc = &info->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct smb_rqst *rqst;
struct iov_iter iter;
unsigned int remaining_data_length, klen;
@@ -1988,10 +2003,10 @@ int smbd_send(struct TCP_Server_Info *server,
for (i = 0; i < num_rqst; i++)
remaining_data_length += smb_rqst_len(server, &rqst_array[i]);
- if (unlikely(remaining_data_length > info->max_fragmented_send_size)) {
+ if (unlikely(remaining_data_length > sp->max_fragmented_send_size)) {
/* assertion: payload never exceeds negotiated maximum */
log_write(ERR, "payload size %d > max size %d\n",
- remaining_data_length, info->max_fragmented_send_size);
+ remaining_data_length, sp->max_fragmented_send_size);
return -EINVAL;
}
diff --git a/fs/smb/client/smbdirect.h b/fs/smb/client/smbdirect.h
index 3d325d73364a..75b3f491c3ad 100644
--- a/fs/smb/client/smbdirect.h
+++ b/fs/smb/client/smbdirect.h
@@ -69,15 +69,7 @@ struct smbd_connection {
spinlock_t lock_new_credits_offered;
int new_credits_offered;
- /* Connection parameters defined in [MS-SMBD] 3.1.1.1 */
- int receive_credit_max;
- int send_credit_target;
- int max_send_size;
- int max_fragmented_recv_size;
- int max_fragmented_send_size;
- int max_receive_size;
- int keep_alive_interval;
- int max_readwrite_size;
+ /* dynamic connection parameters defined in [MS-SMBD] 3.1.1.1 */
enum keep_alive_status keep_alive_requested;
int protocol;
atomic_t send_credits;
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 12/12] smb: server: make use of common smbdirect_socket_parameters
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (10 preceding siblings ...)
2025-05-28 16:01 ` [PATCH v2 11/12] smb: client: make use of common smbdirect_socket_parameters Stefan Metzmacher
@ 2025-05-28 16:01 ` Stefan Metzmacher
2025-05-29 3:33 ` [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Steve French
2025-05-30 16:51 ` Steve French
13 siblings, 0 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-28 16:01 UTC (permalink / raw)
To: linux-cifs
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Hyunchul Lee, Meetakshi Setiya, samba-technical
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/server/transport_rdma.c | 85 ++++++++++++++++++----------------
1 file changed, 44 insertions(+), 41 deletions(-)
diff --git a/fs/smb/server/transport_rdma.c b/fs/smb/server/transport_rdma.c
index 16044d473c34..ceedf4e45c60 100644
--- a/fs/smb/server/transport_rdma.c
+++ b/fs/smb/server/transport_rdma.c
@@ -105,12 +105,6 @@ struct smb_direct_transport {
bool full_packet_received;
wait_queue_head_t wait_status;
- int max_send_size;
- int max_recv_size;
- int max_fragmented_send_size;
- int max_fragmented_recv_size;
- int max_rdma_rw_size;
-
spinlock_t reassembly_queue_lock;
struct list_head reassembly_queue;
int reassembly_data_length;
@@ -121,7 +115,6 @@ struct smb_direct_transport {
spinlock_t receive_credit_lock;
int recv_credits;
int count_avail_recvmsg;
- int recv_credit_max;
int recv_credit_target;
spinlock_t recvmsg_queue_lock;
@@ -130,7 +123,6 @@ struct smb_direct_transport {
spinlock_t empty_recvmsg_queue_lock;
struct list_head empty_recvmsg_queue;
- int send_credit_target;
atomic_t send_credits;
spinlock_t lock_new_recv_credits;
int new_recv_credits;
@@ -655,16 +647,18 @@ static int smb_direct_post_recv(struct smb_direct_transport *t,
struct smb_direct_recvmsg *recvmsg)
{
struct smbdirect_socket *sc = &t->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct ib_recv_wr wr;
int ret;
recvmsg->sge.addr = ib_dma_map_single(sc->ib.dev,
- recvmsg->packet, t->max_recv_size,
+ recvmsg->packet,
+ sp->max_recv_size,
DMA_FROM_DEVICE);
ret = ib_dma_mapping_error(sc->ib.dev, recvmsg->sge.addr);
if (ret)
return ret;
- recvmsg->sge.length = t->max_recv_size;
+ recvmsg->sge.length = sp->max_recv_size;
recvmsg->sge.lkey = sc->ib.pd->local_dma_lkey;
recvmsg->cqe.done = recv_done;
@@ -1039,6 +1033,7 @@ static int smb_direct_create_header(struct smb_direct_transport *t,
struct smb_direct_sendmsg **sendmsg_out)
{
struct smbdirect_socket *sc = &t->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct smb_direct_sendmsg *sendmsg;
struct smbdirect_data_transfer *packet;
int header_length;
@@ -1050,7 +1045,7 @@ static int smb_direct_create_header(struct smb_direct_transport *t,
/* Fill in the packet header */
packet = (struct smbdirect_data_transfer *)sendmsg->packet;
- packet->credits_requested = cpu_to_le16(t->send_credit_target);
+ packet->credits_requested = cpu_to_le16(sp->send_credit_target);
packet->credits_granted = cpu_to_le16(manage_credits_prior_sending(t));
packet->flags = 0;
@@ -1251,9 +1246,10 @@ static int smb_direct_writev(struct ksmbd_transport *t,
{
struct smb_direct_transport *st = smb_trans_direct_transfort(t);
struct smbdirect_socket *sc = &st->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
int remaining_data_length;
int start, i, j;
- int max_iov_size = st->max_send_size -
+ int max_iov_size = sp->max_send_size -
sizeof(struct smbdirect_data_transfer);
int ret;
struct kvec vec;
@@ -1383,6 +1379,7 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
bool is_read)
{
struct smbdirect_socket *sc = &t->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct smb_direct_rdma_rw_msg *msg, *next_msg;
int i, ret;
DECLARE_COMPLETION_ONSTACK(completion);
@@ -1395,7 +1392,7 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t,
if (sc->status != SMBDIRECT_SOCKET_CONNECTED)
return -ENOTCONN;
- if (buf_len > t->max_rdma_rw_size)
+ if (buf_len > sp->max_read_write_size)
return -EINVAL;
/* calculate needed credits */
@@ -1609,6 +1606,7 @@ static int smb_direct_send_negotiate_response(struct smb_direct_transport *t,
int failed)
{
struct smbdirect_socket *sc = &t->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct smb_direct_sendmsg *sendmsg;
struct smbdirect_negotiate_resp *resp;
int ret;
@@ -1630,13 +1628,13 @@ static int smb_direct_send_negotiate_response(struct smb_direct_transport *t,
resp->negotiated_version = SMB_DIRECT_VERSION_LE;
resp->reserved = 0;
resp->credits_requested =
- cpu_to_le16(t->send_credit_target);
+ cpu_to_le16(sp->send_credit_target);
resp->credits_granted = cpu_to_le16(manage_credits_prior_sending(t));
- resp->max_readwrite_size = cpu_to_le32(t->max_rdma_rw_size);
- resp->preferred_send_size = cpu_to_le32(t->max_send_size);
- resp->max_receive_size = cpu_to_le32(t->max_recv_size);
+ resp->max_readwrite_size = cpu_to_le32(sp->max_read_write_size);
+ resp->preferred_send_size = cpu_to_le32(sp->max_send_size);
+ resp->max_receive_size = cpu_to_le32(sp->max_recv_size);
resp->max_fragmented_size =
- cpu_to_le32(t->max_fragmented_recv_size);
+ cpu_to_le32(sp->max_fragmented_recv_size);
}
sendmsg->sge[0].addr = ib_dma_map_single(sc->ib.dev,
@@ -1743,6 +1741,7 @@ static int smb_direct_init_params(struct smb_direct_transport *t,
struct ib_qp_cap *cap)
{
struct smbdirect_socket *sc = &t->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct ib_device *device = sc->ib.dev;
int max_send_sges, max_rw_wrs, max_send_wrs;
unsigned int max_sge_per_wr, wrs_per_credit;
@@ -1750,10 +1749,10 @@ static int smb_direct_init_params(struct smb_direct_transport *t,
/* need 3 more sge. because a SMB_DIRECT header, SMB2 header,
* SMB2 response could be mapped.
*/
- t->max_send_size = smb_direct_max_send_size;
- max_send_sges = DIV_ROUND_UP(t->max_send_size, PAGE_SIZE) + 3;
+ sp->max_send_size = smb_direct_max_send_size;
+ max_send_sges = DIV_ROUND_UP(sp->max_send_size, PAGE_SIZE) + 3;
if (max_send_sges > SMB_DIRECT_MAX_SEND_SGES) {
- pr_err("max_send_size %d is too large\n", t->max_send_size);
+ pr_err("max_send_size %d is too large\n", sp->max_send_size);
return -EINVAL;
}
@@ -1764,9 +1763,9 @@ static int smb_direct_init_params(struct smb_direct_transport *t,
* are needed for MR registration, RDMA R/W, local & remote
* MR invalidation.
*/
- t->max_rdma_rw_size = smb_direct_max_read_write_size;
+ sp->max_read_write_size = smb_direct_max_read_write_size;
t->pages_per_rw_credit = smb_direct_get_max_fr_pages(t);
- t->max_rw_credits = DIV_ROUND_UP(t->max_rdma_rw_size,
+ t->max_rw_credits = DIV_ROUND_UP(sp->max_read_write_size,
(t->pages_per_rw_credit - 1) *
PAGE_SIZE);
@@ -1807,20 +1806,20 @@ static int smb_direct_init_params(struct smb_direct_transport *t,
t->recv_credits = 0;
t->count_avail_recvmsg = 0;
- t->recv_credit_max = smb_direct_receive_credit_max;
+ sp->recv_credit_max = smb_direct_receive_credit_max;
t->recv_credit_target = 10;
t->new_recv_credits = 0;
- t->send_credit_target = smb_direct_send_credit_target;
+ sp->send_credit_target = smb_direct_send_credit_target;
atomic_set(&t->send_credits, 0);
atomic_set(&t->rw_credits, t->max_rw_credits);
- t->max_send_size = smb_direct_max_send_size;
- t->max_recv_size = smb_direct_max_receive_size;
- t->max_fragmented_recv_size = smb_direct_max_fragmented_recv_size;
+ sp->max_send_size = smb_direct_max_send_size;
+ sp->max_recv_size = smb_direct_max_receive_size;
+ sp->max_fragmented_recv_size = smb_direct_max_fragmented_recv_size;
cap->max_send_wr = max_send_wrs;
- cap->max_recv_wr = t->recv_credit_max;
+ cap->max_recv_wr = sp->recv_credit_max;
cap->max_send_sge = max_sge_per_wr;
cap->max_recv_sge = SMB_DIRECT_MAX_RECV_SGES;
cap->max_inline_data = 0;
@@ -1852,6 +1851,8 @@ static void smb_direct_destroy_pools(struct smb_direct_transport *t)
static int smb_direct_create_pools(struct smb_direct_transport *t)
{
+ struct smbdirect_socket *sc = &t->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
char name[80];
int i;
struct smb_direct_recvmsg *recvmsg;
@@ -1864,7 +1865,7 @@ static int smb_direct_create_pools(struct smb_direct_transport *t)
if (!t->sendmsg_cache)
return -ENOMEM;
- t->sendmsg_mempool = mempool_create(t->send_credit_target,
+ t->sendmsg_mempool = mempool_create(sp->send_credit_target,
mempool_alloc_slab, mempool_free_slab,
t->sendmsg_cache);
if (!t->sendmsg_mempool)
@@ -1873,27 +1874,27 @@ static int smb_direct_create_pools(struct smb_direct_transport *t)
snprintf(name, sizeof(name), "smb_direct_resp_%p", t);
t->recvmsg_cache = kmem_cache_create(name,
sizeof(struct smb_direct_recvmsg) +
- t->max_recv_size,
+ sp->max_recv_size,
0, SLAB_HWCACHE_ALIGN, NULL);
if (!t->recvmsg_cache)
goto err;
t->recvmsg_mempool =
- mempool_create(t->recv_credit_max, mempool_alloc_slab,
+ mempool_create(sp->recv_credit_max, mempool_alloc_slab,
mempool_free_slab, t->recvmsg_cache);
if (!t->recvmsg_mempool)
goto err;
INIT_LIST_HEAD(&t->recvmsg_queue);
- for (i = 0; i < t->recv_credit_max; i++) {
+ for (i = 0; i < sp->recv_credit_max; i++) {
recvmsg = mempool_alloc(t->recvmsg_mempool, KSMBD_DEFAULT_GFP);
if (!recvmsg)
goto err;
recvmsg->transport = t;
list_add(&recvmsg->list, &t->recvmsg_queue);
}
- t->count_avail_recvmsg = t->recv_credit_max;
+ t->count_avail_recvmsg = sp->recv_credit_max;
return 0;
err:
@@ -1905,6 +1906,7 @@ static int smb_direct_create_qpair(struct smb_direct_transport *t,
struct ib_qp_cap *cap)
{
struct smbdirect_socket *sc = &t->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
int ret;
struct ib_qp_init_attr qp_attr;
int pages_per_rw;
@@ -1928,7 +1930,7 @@ static int smb_direct_create_qpair(struct smb_direct_transport *t,
}
sc->ib.recv_cq = ib_alloc_cq(sc->ib.dev, t,
- t->recv_credit_max, 0, IB_POLL_WORKQUEUE);
+ sp->recv_credit_max, 0, IB_POLL_WORKQUEUE);
if (IS_ERR(sc->ib.recv_cq)) {
pr_err("Can't create RDMA recv CQ\n");
ret = PTR_ERR(sc->ib.recv_cq);
@@ -1955,7 +1957,7 @@ static int smb_direct_create_qpair(struct smb_direct_transport *t,
sc->ib.qp = sc->rdma.cm_id->qp;
sc->rdma.cm_id->event_handler = smb_direct_cm_handler;
- pages_per_rw = DIV_ROUND_UP(t->max_rdma_rw_size, PAGE_SIZE) + 1;
+ pages_per_rw = DIV_ROUND_UP(sp->max_read_write_size, PAGE_SIZE) + 1;
if (pages_per_rw > sc->ib.dev->attrs.max_sgl_rd) {
ret = ib_mr_pool_init(sc->ib.qp, &sc->ib.qp->rdma_mrs,
t->max_rw_credits, IB_MR_TYPE_MEM_REG,
@@ -1992,6 +1994,7 @@ static int smb_direct_prepare(struct ksmbd_transport *t)
{
struct smb_direct_transport *st = smb_trans_direct_transfort(t);
struct smbdirect_socket *sc = &st->socket;
+ struct smbdirect_socket_parameters *sp = &sc->parameters;
struct smb_direct_recvmsg *recvmsg;
struct smbdirect_negotiate_req *req;
int ret;
@@ -2013,14 +2016,14 @@ static int smb_direct_prepare(struct ksmbd_transport *t)
goto out;
req = (struct smbdirect_negotiate_req *)recvmsg->packet;
- st->max_recv_size = min_t(int, st->max_recv_size,
+ sp->max_recv_size = min_t(int, sp->max_recv_size,
le32_to_cpu(req->preferred_send_size));
- st->max_send_size = min_t(int, st->max_send_size,
+ sp->max_send_size = min_t(int, sp->max_send_size,
le32_to_cpu(req->max_receive_size));
- st->max_fragmented_send_size =
+ sp->max_fragmented_send_size =
le32_to_cpu(req->max_fragmented_size);
- st->max_fragmented_recv_size =
- (st->recv_credit_max * st->max_recv_size) / 2;
+ sp->max_fragmented_recv_size =
+ (sp->recv_credit_max * sp->max_recv_size) / 2;
ret = smb_direct_send_negotiate_response(st, ret);
out:
--
2.34.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-05-28 16:01 ` [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions Stefan Metzmacher
@ 2025-05-28 23:28 ` Namjae Jeon
2025-05-30 19:03 ` Stefan Metzmacher
0 siblings, 1 reply; 27+ messages in thread
From: Namjae Jeon @ 2025-05-28 23:28 UTC (permalink / raw)
To: Stefan Metzmacher
Cc: linux-cifs, Steve French, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
On Thu, May 29, 2025 at 1:02 AM Stefan Metzmacher <metze@samba.org> wrote:
>
> This is just a start moving into a common smbdirect layer.
>
> It will be used in the next commits...
>
> Cc: Steve French <smfrench@gmail.com>
> Cc: Tom Talpey <tom@talpey.com>
> Cc: Long Li <longli@microsoft.com>
> Cc: Namjae Jeon <linkinjeon@kernel.org>
> Cc: Hyunchul Lee <hyc.lee@gmail.com>
> Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
> Cc: linux-cifs@vger.kernel.org
> Cc: samba-technical@lists.samba.org
> Signed-off-by: Stefan Metzmacher <metze@samba.org>
> ---
> fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++++++++++++++++++++++++
> 1 file changed, 55 insertions(+)
> create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
>
> diff --git a/fs/smb/common/smbdirect/smbdirect_pdu.h b/fs/smb/common/smbdirect/smbdirect_pdu.h
> new file mode 100644
> index 000000000000..ae9fdb05ce23
> --- /dev/null
> +++ b/fs/smb/common/smbdirect/smbdirect_pdu.h
> @@ -0,0 +1,55 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (c) 2017 Stefan Metzmacher
Isn't it 2025? It looks like a typo.
And why do you split the existing one into multiple header
files(smbdirect_pdu.h, smbdirect_socket.h, smbdirect.h)?
> + */
> +
> +#ifndef __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_PDU_H__
> +#define __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_PDU_H__
> +
> +#define SMBDIRECT_V1 0x0100
> +
> +/* SMBD negotiation request packet [MS-SMBD] 2.2.1 */
> +struct smbdirect_negotiate_req {
> + __le16 min_version;
> + __le16 max_version;
> + __le16 reserved;
> + __le16 credits_requested;
> + __le32 preferred_send_size;
> + __le32 max_receive_size;
> + __le32 max_fragmented_size;
> +} __packed;
> +
> +/* SMBD negotiation response packet [MS-SMBD] 2.2.2 */
> +struct smbdirect_negotiate_resp {
> + __le16 min_version;
> + __le16 max_version;
> + __le16 negotiated_version;
> + __le16 reserved;
> + __le16 credits_requested;
> + __le16 credits_granted;
> + __le32 status;
> + __le32 max_readwrite_size;
> + __le32 preferred_send_size;
> + __le32 max_receive_size;
> + __le32 max_fragmented_size;
> +} __packed;
> +
> +#define SMBDIRECT_DATA_MIN_HDR_SIZE 0x14
> +#define SMBDIRECT_DATA_OFFSET 0x18
> +
> +#define SMBDIRECT_FLAG_RESPONSE_REQUESTED 0x0001
> +
> +/* SMBD data transfer packet with payload [MS-SMBD] 2.2.3 */
> +struct smbdirect_data_transfer {
> + __le16 credits_requested;
> + __le16 credits_granted;
> + __le16 flags;
> + __le16 reserved;
> + __le32 remaining_data_length;
> + __le32 data_offset;
> + __le32 data_length;
> + __le32 padding;
> + __u8 buffer[];
> +} __packed;
> +
> +#endif /* __FS_SMB_COMMON_SMBDIRECT_SMBDIRECT_PDU_H__ */
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1)
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (11 preceding siblings ...)
2025-05-28 16:01 ` [PATCH v2 12/12] smb: server: " Stefan Metzmacher
@ 2025-05-29 3:33 ` Steve French
2025-05-30 16:51 ` Steve French
13 siblings, 0 replies; 27+ messages in thread
From: Steve French @ 2025-05-29 3:33 UTC (permalink / raw)
To: Stefan Metzmacher
Cc: linux-cifs, Tom Talpey, Long Li, Namjae Jeon, Hyunchul Lee,
Meetakshi Setiya, samba-technical
So far not seeing any issues testing (non-smbdirect tests) with this
patch series, but would love feedback on any smbdirect testing with
the series
On Wed, May 28, 2025 at 11:01 AM Stefan Metzmacher <metze@samba.org> wrote:
>
> Hi,
>
> in preparation of a having a common smb_direct layer I started
> to move things into common header files and added the first
> step in using shared structues like struct smbdirect_socket.
>
> Currently only simple things are shared and there is no
> intended behaviour change (even if I found some things
> I'd like to change, but I'll defer them in order to
> make the review easier).
>
> I'll work on this the next few months in order to
> unify the in kernel client and server layers
> and expose the result to userspace too.
> So that Samba can also use it.
>
> v2:
> - change smb_direct into smbdirect
> - make usage of header files just as needed
> - also introduce struct smbdirect_socket[_parameters]
> as shared structures
>
> Stefan Metzmacher (12):
> smb: smbdirect: add smbdirect_pdu.h with protocol definitions
> smb: client: make use of common smbdirect_pdu.h
> smb: server: make use of common smbdirect_pdu.h
> smb: smbdirect: add smbdirect.h with public structures
> smb: client: make use of common smbdirect.h
> smb: server: make use of common smbdirect.h
> smb: smbdirect: add smbdirect_socket.h
> smb: client: make use of common smbdirect_socket
> smb: server: make use of common smbdirect_socket
> smb: smbdirect: introduce smbdirect_socket_parameters
> smb: client: make use of common smbdirect_socket_parameters
> smb: server: make use of common smbdirect_socket_parameters
>
> fs/smb/client/cifs_debug.c | 23 +-
> fs/smb/client/smb2ops.c | 14 +-
> fs/smb/client/smb2pdu.c | 17 +-
> fs/smb/client/smbdirect.c | 389 +++++++++++----------
> fs/smb/client/smbdirect.h | 71 +---
> fs/smb/common/smbdirect/smbdirect.h | 37 ++
> fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++
> fs/smb/common/smbdirect/smbdirect_socket.h | 43 +++
> fs/smb/server/connection.c | 4 +-
> fs/smb/server/connection.h | 10 +-
> fs/smb/server/smb2pdu.c | 11 +-
> fs/smb/server/smb2pdu.h | 6 -
> fs/smb/server/transport_rdma.c | 385 +++++++++++---------
> fs/smb/server/transport_rdma.h | 41 ---
> 14 files changed, 613 insertions(+), 493 deletions(-)
> create mode 100644 fs/smb/common/smbdirect/smbdirect.h
> create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
> create mode 100644 fs/smb/common/smbdirect/smbdirect_socket.h
>
> --
> 2.34.1
>
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1)
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
` (12 preceding siblings ...)
2025-05-29 3:33 ` [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Steve French
@ 2025-05-30 16:51 ` Steve French
13 siblings, 0 replies; 27+ messages in thread
From: Steve French @ 2025-05-30 16:51 UTC (permalink / raw)
To: Stefan Metzmacher
Cc: linux-cifs, Tom Talpey, Long Li, Namjae Jeon, Hyunchul Lee,
Meetakshi Setiya, samba-technical
I have temporarily removed that patches which touch the server, ie
updated for-next with only the client and common patches, pending
answer to one of Namjae's questions about the ksmbd changes.
4e89b3b35e98 (HEAD -> for-next, origin/for-next) smb: client: make use
of common smbdirect_socket_parameters
34399d47fa28 smb: smbdirect: introduce smbdirect_socket_parameters
39bfc4a85f60 smb: client: make use of common smbdirect_socket
8ed057da2a21 smb: smbdirect: add smbdirect_socket.h
3173f315fa92 smb: client: make use of common smbdirect.h
c54ba448cb35 smb: smbdirect: add smbdirect.h with public structures
2119e7ed45d1 smb: client: make use of common smbdirect_pdu.h
0aad6cf27293 smb: smbdirect: add smbdirect_pdu.h with protocol definitions
bc01b00a6ca2 smb: client: use ParentLeaseKey in cifs_do_create
0e441841edfa smb: client: use ParentLeaseKey in open_cached_dir
5015217979ad smb: client: add ParentLeaseKey support
55423e9c534d smb: client: Remove an unused function and variable
0ff41df1cb26 (tag: v6.15) Linux 6.15
On Wed, May 28, 2025 at 11:01 AM Stefan Metzmacher <metze@samba.org> wrote:
>
> Hi,
>
> in preparation of a having a common smb_direct layer I started
> to move things into common header files and added the first
> step in using shared structues like struct smbdirect_socket.
>
> Currently only simple things are shared and there is no
> intended behaviour change (even if I found some things
> I'd like to change, but I'll defer them in order to
> make the review easier).
>
> I'll work on this the next few months in order to
> unify the in kernel client and server layers
> and expose the result to userspace too.
> So that Samba can also use it.
>
> v2:
> - change smb_direct into smbdirect
> - make usage of header files just as needed
> - also introduce struct smbdirect_socket[_parameters]
> as shared structures
>
> Stefan Metzmacher (12):
> smb: smbdirect: add smbdirect_pdu.h with protocol definitions
> smb: client: make use of common smbdirect_pdu.h
> smb: server: make use of common smbdirect_pdu.h
> smb: smbdirect: add smbdirect.h with public structures
> smb: client: make use of common smbdirect.h
> smb: server: make use of common smbdirect.h
> smb: smbdirect: add smbdirect_socket.h
> smb: client: make use of common smbdirect_socket
> smb: server: make use of common smbdirect_socket
> smb: smbdirect: introduce smbdirect_socket_parameters
> smb: client: make use of common smbdirect_socket_parameters
> smb: server: make use of common smbdirect_socket_parameters
>
> fs/smb/client/cifs_debug.c | 23 +-
> fs/smb/client/smb2ops.c | 14 +-
> fs/smb/client/smb2pdu.c | 17 +-
> fs/smb/client/smbdirect.c | 389 +++++++++++----------
> fs/smb/client/smbdirect.h | 71 +---
> fs/smb/common/smbdirect/smbdirect.h | 37 ++
> fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++
> fs/smb/common/smbdirect/smbdirect_socket.h | 43 +++
> fs/smb/server/connection.c | 4 +-
> fs/smb/server/connection.h | 10 +-
> fs/smb/server/smb2pdu.c | 11 +-
> fs/smb/server/smb2pdu.h | 6 -
> fs/smb/server/transport_rdma.c | 385 +++++++++++---------
> fs/smb/server/transport_rdma.h | 41 ---
> 14 files changed, 613 insertions(+), 493 deletions(-)
> create mode 100644 fs/smb/common/smbdirect/smbdirect.h
> create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
> create mode 100644 fs/smb/common/smbdirect/smbdirect_socket.h
>
> --
> 2.34.1
>
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-05-28 23:28 ` Namjae Jeon
@ 2025-05-30 19:03 ` Stefan Metzmacher
2025-05-30 19:27 ` Steve French
2025-05-30 22:29 ` Namjae Jeon
0 siblings, 2 replies; 27+ messages in thread
From: Stefan Metzmacher @ 2025-05-30 19:03 UTC (permalink / raw)
To: Namjae Jeon
Cc: linux-cifs, Steve French, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
Am 29.05.25 um 01:28 schrieb Namjae Jeon:
> On Thu, May 29, 2025 at 1:02 AM Stefan Metzmacher <metze@samba.org> wrote:
>>
>> This is just a start moving into a common smbdirect layer.
>>
>> It will be used in the next commits...
>>
>> Cc: Steve French <smfrench@gmail.com>
>> Cc: Tom Talpey <tom@talpey.com>
>> Cc: Long Li <longli@microsoft.com>
>> Cc: Namjae Jeon <linkinjeon@kernel.org>
>> Cc: Hyunchul Lee <hyc.lee@gmail.com>
>> Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
>> Cc: linux-cifs@vger.kernel.org
>> Cc: samba-technical@lists.samba.org
>> Signed-off-by: Stefan Metzmacher <metze@samba.org>
>> ---
>> fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++++++++++++++++++++++++
>> 1 file changed, 55 insertions(+)
>> create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
>>
>> diff --git a/fs/smb/common/smbdirect/smbdirect_pdu.h b/fs/smb/common/smbdirect/smbdirect_pdu.h
>> new file mode 100644
>> index 000000000000..ae9fdb05ce23
>> --- /dev/null
>> +++ b/fs/smb/common/smbdirect/smbdirect_pdu.h
>> @@ -0,0 +1,55 @@
>> +/* SPDX-License-Identifier: GPL-2.0-or-later */
>> +/*
>> + * Copyright (c) 2017 Stefan Metzmacher
> Isn't it 2025? It looks like a typo.
I took it from here:
https://git.samba.org/?p=metze/linux/smbdirect.git;a=blob;f=smbdirect_private.h;hb=284ad8ea768c06e3cc70d6f2754929a6abbd2719
> And why do you split the existing one into multiple header
> files(smbdirect_pdu.h, smbdirect_socket.h, smbdirect.h)?
In the end smbdirect.h will be the only header used outside
of fs/smb/common/smbdirect, it will be the public api, to be used
by the smb layer.
smbdirect_pdu.h holds protocol definitions, while smbdirect_socket.h
will be some kind of internal header that holds structures shared between multiple .c files.
But we'll see I think this is a start in the correct direction.
I try to focus on doing tiny steps avoiding doing to much at the same time
or even try to avoid thinking about the next step already...
metze
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-05-30 19:03 ` Stefan Metzmacher
@ 2025-05-30 19:27 ` Steve French
2025-05-30 22:29 ` Namjae Jeon
1 sibling, 0 replies; 27+ messages in thread
From: Steve French @ 2025-05-30 19:27 UTC (permalink / raw)
To: Stefan Metzmacher
Cc: Namjae Jeon, linux-cifs, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
On Fri, May 30, 2025 at 2:03 PM Stefan Metzmacher <metze@samba.org> wrote:
>
> Am 29.05.25 um 01:28 schrieb Namjae Jeon:
> > On Thu, May 29, 2025 at 1:02 AM Stefan Metzmacher <metze@samba.org> wrote:
> >>
> >> This is just a start moving into a common smbdirect layer.
> >>
> >> It will be used in the next commits...
> >>
> >> Cc: Steve French <smfrench@gmail.com>
> >> Cc: Tom Talpey <tom@talpey.com>
> >> Cc: Long Li <longli@microsoft.com>
> >> Cc: Namjae Jeon <linkinjeon@kernel.org>
> >> Cc: Hyunchul Lee <hyc.lee@gmail.com>
> >> Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
> >> Cc: linux-cifs@vger.kernel.org
> >> Cc: samba-technical@lists.samba.org
> >> Signed-off-by: Stefan Metzmacher <metze@samba.org>
> >> ---
> >> fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++++++++++++++++++++++++
> >> 1 file changed, 55 insertions(+)
> >> create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
> >>
> >> diff --git a/fs/smb/common/smbdirect/smbdirect_pdu.h b/fs/smb/common/smbdirect/smbdirect_pdu.h
> >> new file mode 100644
> >> index 000000000000..ae9fdb05ce23
> >> --- /dev/null
> >> +++ b/fs/smb/common/smbdirect/smbdirect_pdu.h
> >> @@ -0,0 +1,55 @@
> >> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> >> +/*
> >> + * Copyright (c) 2017 Stefan Metzmacher
> > Isn't it 2025? It looks like a typo.
>
> I took it from here:
> https://git.samba.org/?p=metze/linux/smbdirect.git;a=blob;f=smbdirect_private.h;hb=284ad8ea768c06e3cc70d6f2754929a6abbd2719
>
> > And why do you split the existing one into multiple header
> > files(smbdirect_pdu.h, smbdirect_socket.h, smbdirect.h)?
>
> In the end smbdirect.h will be the only header used outside
> of fs/smb/common/smbdirect, it will be the public api, to be used
> by the smb layer.
>
> smbdirect_pdu.h holds protocol definitions, while smbdirect_socket.h
> will be some kind of internal header that holds structures shared between multiple .c files.
>
> But we'll see I think this is a start in the correct direction.
>
> I try to focus on doing tiny steps avoiding doing to much at the same time
> or even try to avoid thinking about the next step already...
Makes sense to me. Seems like a very good plan
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-05-30 19:03 ` Stefan Metzmacher
2025-05-30 19:27 ` Steve French
@ 2025-05-30 22:29 ` Namjae Jeon
[not found] ` <CAH2r5mvQbL_R9wrFRHF9_3XwM3e-=2vK=i1uaSCk37-FZmJq9g@mail.gmail.com>
1 sibling, 1 reply; 27+ messages in thread
From: Namjae Jeon @ 2025-05-30 22:29 UTC (permalink / raw)
To: Stefan Metzmacher
Cc: linux-cifs, Steve French, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
On Sat, May 31, 2025 at 4:03 AM Stefan Metzmacher <metze@samba.org> wrote:
>
> Am 29.05.25 um 01:28 schrieb Namjae Jeon:
> > On Thu, May 29, 2025 at 1:02 AM Stefan Metzmacher <metze@samba.org> wrote:
> >>
> >> This is just a start moving into a common smbdirect layer.
> >>
> >> It will be used in the next commits...
> >>
> >> Cc: Steve French <smfrench@gmail.com>
> >> Cc: Tom Talpey <tom@talpey.com>
> >> Cc: Long Li <longli@microsoft.com>
> >> Cc: Namjae Jeon <linkinjeon@kernel.org>
> >> Cc: Hyunchul Lee <hyc.lee@gmail.com>
> >> Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
> >> Cc: linux-cifs@vger.kernel.org
> >> Cc: samba-technical@lists.samba.org
> >> Signed-off-by: Stefan Metzmacher <metze@samba.org>
> >> ---
> >> fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++++++++++++++++++++++++
> >> 1 file changed, 55 insertions(+)
> >> create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
> >>
> >> diff --git a/fs/smb/common/smbdirect/smbdirect_pdu.h b/fs/smb/common/smbdirect/smbdirect_pdu.h
> >> new file mode 100644
> >> index 000000000000..ae9fdb05ce23
> >> --- /dev/null
> >> +++ b/fs/smb/common/smbdirect/smbdirect_pdu.h
> >> @@ -0,0 +1,55 @@
> >> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> >> +/*
> >> + * Copyright (c) 2017 Stefan Metzmacher
> > Isn't it 2025? It looks like a typo.
>
> I took it from here:
> https://git.samba.org/?p=metze/linux/smbdirect.git;a=blob;f=smbdirect_private.h;hb=284ad8ea768c06e3cc70d6f2754929a6abbd2719
>
> > And why do you split the existing one into multiple header
> > files(smbdirect_pdu.h, smbdirect_socket.h, smbdirect.h)?
>
> In the end smbdirect.h will be the only header used outside
> of fs/smb/common/smbdirect, it will be the public api, to be used
> by the smb layer.
>
> smbdirect_pdu.h holds protocol definitions, while smbdirect_socket.h
> will be some kind of internal header that holds structures shared between multiple .c files.
>
> But we'll see I think this is a start in the correct direction.
When will you send the patches for multiple .c files?
I'm not sure if this is the right direction when I check only this patch-set.
I don't prefer to change the headers like this in advance without a body.
When you're ready, how about sending the patches including the body all at once?
>
> I try to focus on doing tiny steps avoiding doing to much at the same time
> or even try to avoid thinking about the next step already...
>
> metze
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
[not found] ` <CAH2r5mvQbL_R9wrFRHF9_3XwM3e-=2vK=i1uaSCk37-FZmJq9g@mail.gmail.com>
@ 2025-06-01 0:01 ` Namjae Jeon
[not found] ` <CAH2r5mso54sXPcoJWDSU4E--XMH44wFY-cdww6_6yx5CxrFtdg@mail.gmail.com>
0 siblings, 1 reply; 27+ messages in thread
From: Namjae Jeon @ 2025-06-01 0:01 UTC (permalink / raw)
To: Steve French
Cc: Stefan Metzmacher, CIFS, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
On Sun, Jun 1, 2025 at 8:23 AM Steve French <smfrench@gmail.com> wrote:
>
> I do like the small, relatively safe steps he is doing these in.
Small is okay, but I wonder when he will send the rest.
What if he just separates it like this and doesn't send the rest of
patches later?
I've never seen a case where the headers are separated first,
And send the main if it's implemented later. This is not a personal repository.
Thanks.
>
> Thanks,
>
> Steve
>
> On Fri, May 30, 2025, 5:29 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
>>
>> On Sat, May 31, 2025 at 4:03 AM Stefan Metzmacher <metze@samba.org> wrote:
>> >
>> > Am 29.05.25 um 01:28 schrieb Namjae Jeon:
>> > > On Thu, May 29, 2025 at 1:02 AM Stefan Metzmacher <metze@samba.org> wrote:
>> > >>
>> > >> This is just a start moving into a common smbdirect layer.
>> > >>
>> > >> It will be used in the next commits...
>> > >>
>> > >> Cc: Steve French <smfrench@gmail.com>
>> > >> Cc: Tom Talpey <tom@talpey.com>
>> > >> Cc: Long Li <longli@microsoft.com>
>> > >> Cc: Namjae Jeon <linkinjeon@kernel.org>
>> > >> Cc: Hyunchul Lee <hyc.lee@gmail.com>
>> > >> Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
>> > >> Cc: linux-cifs@vger.kernel.org
>> > >> Cc: samba-technical@lists.samba.org
>> > >> Signed-off-by: Stefan Metzmacher <metze@samba.org>
>> > >> ---
>> > >> fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++++++++++++++++++++++++
>> > >> 1 file changed, 55 insertions(+)
>> > >> create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
>> > >>
>> > >> diff --git a/fs/smb/common/smbdirect/smbdirect_pdu.h b/fs/smb/common/smbdirect/smbdirect_pdu.h
>> > >> new file mode 100644
>> > >> index 000000000000..ae9fdb05ce23
>> > >> --- /dev/null
>> > >> +++ b/fs/smb/common/smbdirect/smbdirect_pdu.h
>> > >> @@ -0,0 +1,55 @@
>> > >> +/* SPDX-License-Identifier: GPL-2.0-or-later */
>> > >> +/*
>> > >> + * Copyright (c) 2017 Stefan Metzmacher
>> > > Isn't it 2025? It looks like a typo.
>> >
>> > I took it from here:
>> > https://git.samba.org/?p=metze/linux/smbdirect.git;a=blob;f=smbdirect_private.h;hb=284ad8ea768c06e3cc70d6f2754929a6abbd2719
>> >
>> > > And why do you split the existing one into multiple header
>> > > files(smbdirect_pdu.h, smbdirect_socket.h, smbdirect.h)?
>> >
>> > In the end smbdirect.h will be the only header used outside
>> > of fs/smb/common/smbdirect, it will be the public api, to be used
>> > by the smb layer.
>> >
>> > smbdirect_pdu.h holds protocol definitions, while smbdirect_socket.h
>> > will be some kind of internal header that holds structures shared between multiple .c files.
>> >
>> > But we'll see I think this is a start in the correct direction.
>> When will you send the patches for multiple .c files?
>> I'm not sure if this is the right direction when I check only this patch-set.
>> I don't prefer to change the headers like this in advance without a body.
>> When you're ready, how about sending the patches including the body all at once?
>> >
>> > I try to focus on doing tiny steps avoiding doing to much at the same time
>> > or even try to avoid thinking about the next step already...
>> >
>> > metze
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
[not found] ` <CAH2r5mso54sXPcoJWDSU4E--XMH44wFY-cdww6_6yx5CxrFtdg@mail.gmail.com>
@ 2025-06-01 4:59 ` Namjae Jeon
2025-06-02 1:56 ` Steve French
0 siblings, 1 reply; 27+ messages in thread
From: Namjae Jeon @ 2025-06-01 4:59 UTC (permalink / raw)
To: Steve French
Cc: Stefan Metzmacher, CIFS, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
On Sun, Jun 1, 2025 at 12:49 PM Steve French <smfrench@gmail.com> wrote:
>
> Moving to use common headers is something I did multiple times with ksmbd and cifs.ko already, not a bad first step
This is not simply moved to the common header. He splits the header
into smaller pieces for some unknown reason.
Can you explain why he has split it into smbdirect_socket.h?
We doesn't need to do it now if he's thinking of creating a
smbdirect_socket.c file later.
>
> Thanks,
>
> Steve
>
> On Sat, May 31, 2025, 7:01 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
>>
>> On Sun, Jun 1, 2025 at 8:23 AM Steve French <smfrench@gmail.com> wrote:
>> >
>> > I do like the small, relatively safe steps he is doing these in.
>> Small is okay, but I wonder when he will send the rest.
>> What if he just separates it like this and doesn't send the rest of
>> patches later?
>> I've never seen a case where the headers are separated first,
>> And send the main if it's implemented later. This is not a personal repository.
>>
>> Thanks.
>> >
>> > Thanks,
>> >
>> > Steve
>> >
>> > On Fri, May 30, 2025, 5:29 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
>> >>
>> >> On Sat, May 31, 2025 at 4:03 AM Stefan Metzmacher <metze@samba.org> wrote:
>> >> >
>> >> > Am 29.05.25 um 01:28 schrieb Namjae Jeon:
>> >> > > On Thu, May 29, 2025 at 1:02 AM Stefan Metzmacher <metze@samba.org> wrote:
>> >> > >>
>> >> > >> This is just a start moving into a common smbdirect layer.
>> >> > >>
>> >> > >> It will be used in the next commits...
>> >> > >>
>> >> > >> Cc: Steve French <smfrench@gmail.com>
>> >> > >> Cc: Tom Talpey <tom@talpey.com>
>> >> > >> Cc: Long Li <longli@microsoft.com>
>> >> > >> Cc: Namjae Jeon <linkinjeon@kernel.org>
>> >> > >> Cc: Hyunchul Lee <hyc.lee@gmail.com>
>> >> > >> Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
>> >> > >> Cc: linux-cifs@vger.kernel.org
>> >> > >> Cc: samba-technical@lists.samba.org
>> >> > >> Signed-off-by: Stefan Metzmacher <metze@samba.org>
>> >> > >> ---
>> >> > >> fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++++++++++++++++++++++++
>> >> > >> 1 file changed, 55 insertions(+)
>> >> > >> create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
>> >> > >>
>> >> > >> diff --git a/fs/smb/common/smbdirect/smbdirect_pdu.h b/fs/smb/common/smbdirect/smbdirect_pdu.h
>> >> > >> new file mode 100644
>> >> > >> index 000000000000..ae9fdb05ce23
>> >> > >> --- /dev/null
>> >> > >> +++ b/fs/smb/common/smbdirect/smbdirect_pdu.h
>> >> > >> @@ -0,0 +1,55 @@
>> >> > >> +/* SPDX-License-Identifier: GPL-2.0-or-later */
>> >> > >> +/*
>> >> > >> + * Copyright (c) 2017 Stefan Metzmacher
>> >> > > Isn't it 2025? It looks like a typo.
>> >> >
>> >> > I took it from here:
>> >> > https://git.samba.org/?p=metze/linux/smbdirect.git;a=blob;f=smbdirect_private.h;hb=284ad8ea768c06e3cc70d6f2754929a6abbd2719
>> >> >
>> >> > > And why do you split the existing one into multiple header
>> >> > > files(smbdirect_pdu.h, smbdirect_socket.h, smbdirect.h)?
>> >> >
>> >> > In the end smbdirect.h will be the only header used outside
>> >> > of fs/smb/common/smbdirect, it will be the public api, to be used
>> >> > by the smb layer.
>> >> >
>> >> > smbdirect_pdu.h holds protocol definitions, while smbdirect_socket.h
>> >> > will be some kind of internal header that holds structures shared between multiple .c files.
>> >> >
>> >> > But we'll see I think this is a start in the correct direction.
>> >> When will you send the patches for multiple .c files?
>> >> I'm not sure if this is the right direction when I check only this patch-set.
>> >> I don't prefer to change the headers like this in advance without a body.
>> >> When you're ready, how about sending the patches including the body all at once?
>> >> >
>> >> > I try to focus on doing tiny steps avoiding doing to much at the same time
>> >> > or even try to avoid thinking about the next step already...
>> >> >
>> >> > metze
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-06-01 4:59 ` Namjae Jeon
@ 2025-06-02 1:56 ` Steve French
2025-06-02 2:19 ` Namjae Jeon
0 siblings, 1 reply; 27+ messages in thread
From: Steve French @ 2025-06-02 1:56 UTC (permalink / raw)
To: Namjae Jeon
Cc: Stefan Metzmacher, CIFS, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
> Can you explain why he has split it into smbdirect_socket.h?
The three header names seem plausible, but would be useful to have
Metze's clarification/explanation:
- the "protocol" related header info for smbdirect goes in
smb/common/smbdirect/smbdirect_pdu.h (we use similar name smb2pdu.h
for the smb2/smb3 protocol related wire definitions)
- smbdirect.h for internal smbdirect structure definitions
- smbdirect_socket.h for things related to exporting it as a socket
(since one of the goals is to make smbdirect useable by Samba
userspace tools)
On Sun, Jun 1, 2025 at 12:00 AM Namjae Jeon <linkinjeon@kernel.org> wrote:
>
> On Sun, Jun 1, 2025 at 12:49 PM Steve French <smfrench@gmail.com> wrote:
> >
> > Moving to use common headers is something I did multiple times with ksmbd and cifs.ko already, not a bad first step
> This is not simply moved to the common header. He splits the header
> into smaller pieces for some unknown reason.
> Can you explain why he has split it into smbdirect_socket.h?
> We doesn't need to do it now if he's thinking of creating a
> smbdirect_socket.c file later.
> >
> > Thanks,
> >
> > Steve
> >
> > On Sat, May 31, 2025, 7:01 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
> >>
> >> On Sun, Jun 1, 2025 at 8:23 AM Steve French <smfrench@gmail.com> wrote:
> >> >
> >> > I do like the small, relatively safe steps he is doing these in.
> >> Small is okay, but I wonder when he will send the rest.
> >> What if he just separates it like this and doesn't send the rest of
> >> patches later?
> >> I've never seen a case where the headers are separated first,
> >> And send the main if it's implemented later. This is not a personal repository.
> >>
> >> Thanks.
> >> >
> >> > Thanks,
> >> >
> >> > Steve
> >> >
> >> > On Fri, May 30, 2025, 5:29 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
> >> >>
> >> >> On Sat, May 31, 2025 at 4:03 AM Stefan Metzmacher <metze@samba.org> wrote:
> >> >> >
> >> >> > Am 29.05.25 um 01:28 schrieb Namjae Jeon:
> >> >> > > On Thu, May 29, 2025 at 1:02 AM Stefan Metzmacher <metze@samba.org> wrote:
> >> >> > >>
> >> >> > >> This is just a start moving into a common smbdirect layer.
> >> >> > >>
> >> >> > >> It will be used in the next commits...
> >> >> > >>
> >> >> > >> Cc: Steve French <smfrench@gmail.com>
> >> >> > >> Cc: Tom Talpey <tom@talpey.com>
> >> >> > >> Cc: Long Li <longli@microsoft.com>
> >> >> > >> Cc: Namjae Jeon <linkinjeon@kernel.org>
> >> >> > >> Cc: Hyunchul Lee <hyc.lee@gmail.com>
> >> >> > >> Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
> >> >> > >> Cc: linux-cifs@vger.kernel.org
> >> >> > >> Cc: samba-technical@lists.samba.org
> >> >> > >> Signed-off-by: Stefan Metzmacher <metze@samba.org>
> >> >> > >> ---
> >> >> > >> fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++++++++++++++++++++++++
> >> >> > >> 1 file changed, 55 insertions(+)
> >> >> > >> create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
> >> >> > >>
> >> >> > >> diff --git a/fs/smb/common/smbdirect/smbdirect_pdu.h b/fs/smb/common/smbdirect/smbdirect_pdu.h
> >> >> > >> new file mode 100644
> >> >> > >> index 000000000000..ae9fdb05ce23
> >> >> > >> --- /dev/null
> >> >> > >> +++ b/fs/smb/common/smbdirect/smbdirect_pdu.h
> >> >> > >> @@ -0,0 +1,55 @@
> >> >> > >> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> >> >> > >> +/*
> >> >> > >> + * Copyright (c) 2017 Stefan Metzmacher
> >> >> > > Isn't it 2025? It looks like a typo.
> >> >> >
> >> >> > I took it from here:
> >> >> > https://git.samba.org/?p=metze/linux/smbdirect.git;a=blob;f=smbdirect_private.h;hb=284ad8ea768c06e3cc70d6f2754929a6abbd2719
> >> >> >
> >> >> > > And why do you split the existing one into multiple header
> >> >> > > files(smbdirect_pdu.h, smbdirect_socket.h, smbdirect.h)?
> >> >> >
> >> >> > In the end smbdirect.h will be the only header used outside
> >> >> > of fs/smb/common/smbdirect, it will be the public api, to be used
> >> >> > by the smb layer.
> >> >> >
> >> >> > smbdirect_pdu.h holds protocol definitions, while smbdirect_socket.h
> >> >> > will be some kind of internal header that holds structures shared between multiple .c files.
> >> >> >
> >> >> > But we'll see I think this is a start in the correct direction.
> >> >> When will you send the patches for multiple .c files?
> >> >> I'm not sure if this is the right direction when I check only this patch-set.
> >> >> I don't prefer to change the headers like this in advance without a body.
> >> >> When you're ready, how about sending the patches including the body all at once?
> >> >> >
> >> >> > I try to focus on doing tiny steps avoiding doing to much at the same time
> >> >> > or even try to avoid thinking about the next step already...
> >> >> >
> >> >> > metze
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-06-02 1:56 ` Steve French
@ 2025-06-02 2:19 ` Namjae Jeon
2025-06-02 22:02 ` Stefan Metzmacher
0 siblings, 1 reply; 27+ messages in thread
From: Namjae Jeon @ 2025-06-02 2:19 UTC (permalink / raw)
To: Steve French
Cc: Stefan Metzmacher, CIFS, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
On Mon, Jun 2, 2025 at 10:57 AM Steve French <smfrench@gmail.com> wrote:
>
> > Can you explain why he has split it into smbdirect_socket.h?
>
> The three header names seem plausible, but would be useful to have
> Metze's clarification/explanation:
> - the "protocol" related header info for smbdirect goes in
> smb/common/smbdirect/smbdirect_pdu.h (we use similar name smb2pdu.h
> for the smb2/smb3 protocol related wire definitions)
> - smbdirect.h for internal smbdirect structure definitions
> - smbdirect_socket.h for things related to exporting it as a socket
> (since one of the goals is to make smbdirect useable by Samba
> userspace tools)
There is no need to do things in advance that are not yet concrete and
may change later.
He can just put these changes in his own queue and work on them.
I am pointing out why he is trying to put unfinished things in the public queue.
If You want to apply it, Please do it only on cifs.ko. When it is
properly implemented, I want to apply it to ksmbd.
>
> On Sun, Jun 1, 2025 at 12:00 AM Namjae Jeon <linkinjeon@kernel.org> wrote:
> >
> > On Sun, Jun 1, 2025 at 12:49 PM Steve French <smfrench@gmail.com> wrote:
> > >
> > > Moving to use common headers is something I did multiple times with ksmbd and cifs.ko already, not a bad first step
> > This is not simply moved to the common header. He splits the header
> > into smaller pieces for some unknown reason.
> > Can you explain why he has split it into smbdirect_socket.h?
> > We doesn't need to do it now if he's thinking of creating a
> > smbdirect_socket.c file later.
> > >
> > > Thanks,
> > >
> > > Steve
> > >
> > > On Sat, May 31, 2025, 7:01 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
> > >>
> > >> On Sun, Jun 1, 2025 at 8:23 AM Steve French <smfrench@gmail.com> wrote:
> > >> >
> > >> > I do like the small, relatively safe steps he is doing these in.
> > >> Small is okay, but I wonder when he will send the rest.
> > >> What if he just separates it like this and doesn't send the rest of
> > >> patches later?
> > >> I've never seen a case where the headers are separated first,
> > >> And send the main if it's implemented later. This is not a personal repository.
> > >>
> > >> Thanks.
> > >> >
> > >> > Thanks,
> > >> >
> > >> > Steve
> > >> >
> > >> > On Fri, May 30, 2025, 5:29 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
> > >> >>
> > >> >> On Sat, May 31, 2025 at 4:03 AM Stefan Metzmacher <metze@samba.org> wrote:
> > >> >> >
> > >> >> > Am 29.05.25 um 01:28 schrieb Namjae Jeon:
> > >> >> > > On Thu, May 29, 2025 at 1:02 AM Stefan Metzmacher <metze@samba.org> wrote:
> > >> >> > >>
> > >> >> > >> This is just a start moving into a common smbdirect layer.
> > >> >> > >>
> > >> >> > >> It will be used in the next commits...
> > >> >> > >>
> > >> >> > >> Cc: Steve French <smfrench@gmail.com>
> > >> >> > >> Cc: Tom Talpey <tom@talpey.com>
> > >> >> > >> Cc: Long Li <longli@microsoft.com>
> > >> >> > >> Cc: Namjae Jeon <linkinjeon@kernel.org>
> > >> >> > >> Cc: Hyunchul Lee <hyc.lee@gmail.com>
> > >> >> > >> Cc: Meetakshi Setiya <meetakshisetiyaoss@gmail.com>
> > >> >> > >> Cc: linux-cifs@vger.kernel.org
> > >> >> > >> Cc: samba-technical@lists.samba.org
> > >> >> > >> Signed-off-by: Stefan Metzmacher <metze@samba.org>
> > >> >> > >> ---
> > >> >> > >> fs/smb/common/smbdirect/smbdirect_pdu.h | 55 +++++++++++++++++++++++++
> > >> >> > >> 1 file changed, 55 insertions(+)
> > >> >> > >> create mode 100644 fs/smb/common/smbdirect/smbdirect_pdu.h
> > >> >> > >>
> > >> >> > >> diff --git a/fs/smb/common/smbdirect/smbdirect_pdu.h b/fs/smb/common/smbdirect/smbdirect_pdu.h
> > >> >> > >> new file mode 100644
> > >> >> > >> index 000000000000..ae9fdb05ce23
> > >> >> > >> --- /dev/null
> > >> >> > >> +++ b/fs/smb/common/smbdirect/smbdirect_pdu.h
> > >> >> > >> @@ -0,0 +1,55 @@
> > >> >> > >> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> > >> >> > >> +/*
> > >> >> > >> + * Copyright (c) 2017 Stefan Metzmacher
> > >> >> > > Isn't it 2025? It looks like a typo.
> > >> >> >
> > >> >> > I took it from here:
> > >> >> > https://git.samba.org/?p=metze/linux/smbdirect.git;a=blob;f=smbdirect_private.h;hb=284ad8ea768c06e3cc70d6f2754929a6abbd2719
> > >> >> >
> > >> >> > > And why do you split the existing one into multiple header
> > >> >> > > files(smbdirect_pdu.h, smbdirect_socket.h, smbdirect.h)?
> > >> >> >
> > >> >> > In the end smbdirect.h will be the only header used outside
> > >> >> > of fs/smb/common/smbdirect, it will be the public api, to be used
> > >> >> > by the smb layer.
> > >> >> >
> > >> >> > smbdirect_pdu.h holds protocol definitions, while smbdirect_socket.h
> > >> >> > will be some kind of internal header that holds structures shared between multiple .c files.
> > >> >> >
> > >> >> > But we'll see I think this is a start in the correct direction.
> > >> >> When will you send the patches for multiple .c files?
> > >> >> I'm not sure if this is the right direction when I check only this patch-set.
> > >> >> I don't prefer to change the headers like this in advance without a body.
> > >> >> When you're ready, how about sending the patches including the body all at once?
> > >> >> >
> > >> >> > I try to focus on doing tiny steps avoiding doing to much at the same time
> > >> >> > or even try to avoid thinking about the next step already...
> > >> >> >
> > >> >> > metze
>
>
>
> --
> Thanks,
>
> Steve
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-06-02 2:19 ` Namjae Jeon
@ 2025-06-02 22:02 ` Stefan Metzmacher
2025-06-03 6:20 ` Namjae Jeon
0 siblings, 1 reply; 27+ messages in thread
From: Stefan Metzmacher @ 2025-06-02 22:02 UTC (permalink / raw)
To: Namjae Jeon, Steve French
Cc: CIFS, Tom Talpey, Long Li, Hyunchul Lee, Meetakshi Setiya,
samba-technical
Am 02.06.25 um 04:19 schrieb Namjae Jeon:
> On Mon, Jun 2, 2025 at 10:57 AM Steve French <smfrench@gmail.com> wrote:
>>
>>> Can you explain why he has split it into smbdirect_socket.h?
>>
>> The three header names seem plausible, but would be useful to have
>> Metze's clarification/explanation:
>> - the "protocol" related header info for smbdirect goes in
>> smb/common/smbdirect/smbdirect_pdu.h (we use similar name smb2pdu.h
>> for the smb2/smb3 protocol related wire definitions)
>> - smbdirect.h for internal smbdirect structure definitions
>> - smbdirect_socket.h for things related to exporting it as a socket
>> (since one of the goals is to make smbdirect useable by Samba
>> userspace tools)
> There is no need to do things in advance that are not yet concrete and
> may change later.
The current idea is to merge transport_tcp and transport_rdma into
transport_sock, see
https://git.samba.org/?p=metze/linux/wip.git;a=blob;f=fs/smb/server/transport_sock.c;hb=66714b6c0fc1eacbeb5b85d07524caa722fc19cf
Which uses this interface:
https://git.samba.org/?p=metze/linux/wip.git;a=blob;f=fs/smb/common/smbdirect/smbdirect.h;hb=66714b6c0fc1eacbeb5b85d07524caa722fc19cf
But note that is just the direction were it goes, that current code has a lot of resolved merge conflicts,
which may not work at all currently.
Instead of putting my current code I try to take the existing client and server
code and merge it, so that we don't have a flag day commit that switches to
completely new code. Instead I try to do tiny steps in that direction
and may end with an interface that is similar but might be a bit different in
some parts.
> He can just put these changes in his own queue and work on them.
> I am pointing out why he is trying to put unfinished things in the public queue.
Because I want to base the next steps on something that is already accepted.
I really don't want to work on it for weeks and then some review will void
that work completely and I can start again.
> If You want to apply it, Please do it only on cifs.ko. When it is
> properly implemented, I want to apply it to ksmbd.
I can keep the ksmbd patches rebased on top and send them again
each time to get more feedback.
Would that work for you?
The key for me is discuss patches first and have them reviewed early
so that the following work rely on. Any the tiny steps should
make it possible to do easy review and make it possible to test each
tiny step.
metze
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-06-02 22:02 ` Stefan Metzmacher
@ 2025-06-03 6:20 ` Namjae Jeon
2025-06-03 9:06 ` Stefan Metzmacher
0 siblings, 1 reply; 27+ messages in thread
From: Namjae Jeon @ 2025-06-03 6:20 UTC (permalink / raw)
To: Stefan Metzmacher
Cc: Steve French, CIFS, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
On Tue, Jun 3, 2025 at 7:03 AM Stefan Metzmacher <metze@samba.org> wrote:
>
> Am 02.06.25 um 04:19 schrieb Namjae Jeon:
> > On Mon, Jun 2, 2025 at 10:57 AM Steve French <smfrench@gmail.com> wrote:
> >>
> >>> Can you explain why he has split it into smbdirect_socket.h?
> >>
> >> The three header names seem plausible, but would be useful to have
> >> Metze's clarification/explanation:
> >> - the "protocol" related header info for smbdirect goes in
> >> smb/common/smbdirect/smbdirect_pdu.h (we use similar name smb2pdu.h
> >> for the smb2/smb3 protocol related wire definitions)
> >> - smbdirect.h for internal smbdirect structure definitions
> >> - smbdirect_socket.h for things related to exporting it as a socket
> >> (since one of the goals is to make smbdirect useable by Samba
> >> userspace tools)
> > There is no need to do things in advance that are not yet concrete and
> > may change later.
>
> The current idea is to merge transport_tcp and transport_rdma into
> transport_sock, see
> https://git.samba.org/?p=metze/linux/wip.git;a=blob;f=fs/smb/server/transport_sock.c;hb=66714b6c0fc1eacbeb5b85d07524caa722fc19cf
>
> Which uses this interface:
> https://git.samba.org/?p=metze/linux/wip.git;a=blob;f=fs/smb/common/smbdirect/smbdirect.h;hb=66714b6c0fc1eacbeb5b85d07524caa722fc19cf
Hm.. I can not access these links.. Is it just me?
>
> But note that is just the direction were it goes, that current code has a lot of resolved merge conflicts,
> which may not work at all currently.
>
> Instead of putting my current code I try to take the existing client and server
> code and merge it, so that we don't have a flag day commit that switches to
> completely new code. Instead I try to do tiny steps in that direction
> and may end with an interface that is similar but might be a bit different in
> some parts.
Okay.
>
> > He can just put these changes in his own queue and work on them.
> > I am pointing out why he is trying to put unfinished things in the public queue.
>
> Because I want to base the next steps on something that is already accepted.
>
> I really don't want to work on it for weeks and then some review will void
> that work completely and I can start again.
It was too tiny a step and unclear.
i.e. the patch description should not have comments like "It will be
used in the next commits..."
>
> > If You want to apply it, Please do it only on cifs.ko. When it is
> > properly implemented, I want to apply it to ksmbd.
>
> I can keep the ksmbd patches rebased on top and send them again
> each time to get more feedback.
>
> Would that work for you?
Okay, Please re-include the ksmbd patches in the next patch-set and I
will check them.
>
> The key for me is discuss patches first and have them reviewed early
> so that the following work rely on. Any the tiny steps should
> make it possible to do easy review and make it possible to test each
> tiny step.
Okay. I agreed. But It should not be too tiny.
As I said above, please don't send it in pieces that I can understand
by looking at the next commits.
Thanks.
>
> metze
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-06-03 6:20 ` Namjae Jeon
@ 2025-06-03 9:06 ` Stefan Metzmacher
2025-06-03 10:55 ` Namjae Jeon
0 siblings, 1 reply; 27+ messages in thread
From: Stefan Metzmacher @ 2025-06-03 9:06 UTC (permalink / raw)
To: Namjae Jeon
Cc: Steve French, CIFS, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
[-- Attachment #1: Type: text/plain, Size: 8637 bytes --]
Am 03.06.25 um 08:20 schrieb Namjae Jeon:
> On Tue, Jun 3, 2025 at 7:03 AM Stefan Metzmacher <metze@samba.org> wrote:
>>
>> Am 02.06.25 um 04:19 schrieb Namjae Jeon:
>>> On Mon, Jun 2, 2025 at 10:57 AM Steve French <smfrench@gmail.com> wrote:
>>>>
>>>>> Can you explain why he has split it into smbdirect_socket.h?
>>>>
>>>> The three header names seem plausible, but would be useful to have
>>>> Metze's clarification/explanation:
>>>> - the "protocol" related header info for smbdirect goes in
>>>> smb/common/smbdirect/smbdirect_pdu.h (we use similar name smb2pdu.h
>>>> for the smb2/smb3 protocol related wire definitions)
>>>> - smbdirect.h for internal smbdirect structure definitions
>>>> - smbdirect_socket.h for things related to exporting it as a socket
>>>> (since one of the goals is to make smbdirect useable by Samba
>>>> userspace tools)
>>> There is no need to do things in advance that are not yet concrete and
>>> may change later.
>>
>> The current idea is to merge transport_tcp and transport_rdma into
>> transport_sock, see
>> https://git.samba.org/?p=metze/linux/wip.git;a=blob;f=fs/smb/server/transport_sock.c;hb=66714b6c0fc1eacbeb5b85d07524caa722fc19cf
I've attached to this mail, but remember this is just a demo I need to redo that
based on the current transport_tcp.c and transport_rdma.c
>> Which uses this interface:
>> https://git.samba.org/?p=metze/linux/wip.git;a=blob;f=fs/smb/common/smbdirect/smbdirect.h;hb=66714b6c0fc1eacbeb5b85d07524caa722fc19cf
> Hm.. I can not access these links.. Is it just me?
Here's a trimmed down version with only the in kernel related stuff of smbdirect.h:
/*
* userspace:
*
* int socket(int family, int type, int protocol);
*
* kernel:
*
* int sock_create_kern(struct net *net,
* int family, int type, int protocol,
* struct socket **res);
*
* family: PF_SMBDIRECT
* type: SOCK_STREAM, together with SOCK_CLOEXEC SOCK_NONBLOCK
* protocol: address family + protocol flavor
*
* address family: AF_INET or AF_INET6
* protocol flavor: SMBDIRECT_FLAVOR_AUTO
*/
/*
* AF_INET, AF_INET6 and AF_IB are below 0xff
*/
#define SMBDIRECT_FAMILY_MASK 0x000000ff
/*
* For now just auto use iWarp and ROCE
*/
#define SMBDIRECT_FLAVOR_MASK 0x0000f000
#define SMBDIRECT_FLAVOR_AUTO 0x00000000
/*
* Additional hints/flags
*/
#define SMBDIRECT_FLAGS_MASK 0x7fff0000
#define SMBDIRECT_FLAGS_VALID ( \
0)
#define SMBDIRECT_PROTOCOL_INVALID_MASK ~((unsigned)( \
SMBDIRECT_FAMILY_MASK | \
SMBDIRECT_FLAVOR_MASK | \
SMBDIRECT_FLAGS_MASK | \
0))
enum {
__SMBDIRECT_CONNECTION_PARAMETERS = 100,
__SMBDIRECT_BUFFER_UNREGISTER = 200,
__SMBDIRECT_BUFFER_REGISTER_READ = 201,
__SMBDIRECT_BUFFER_REGISTER_WRITE = 202,
__SMBDIRECT_BUFFER_REMOTE_INVALIDATE = 300,
__SMBDIRECT_BUFFER_REMOTE_READ = 301,
__SMBDIRECT_BUFFER_REMOTE_WRITE = 302,
};
struct smbdirect_connection_parameters {
__u16 recv_credit_max;
__u16 send_credit_target;
__u32 max_send_size;
__u32 max_fragmented_send_size;
__u32 max_recv_size;
__u32 max_fragmented_recv_size;
__u32 max_read_write_size;
__u32 keepalive_interval;
} __packed;
int smbdirect_kern_connection_get_parameters(struct socket *sock,
struct smbdirect_connection_parameters *params);
struct smbdirect_buffer_descriptor_v1 {
__le64 offset;
__le32 token;
__le32 length;
} __packed;
struct smbdirect_buffer_descriptors_v1 {
#define SMBDIRECT_BUFFER_ALLOW_READ 0x00000001
#define SMBDIRECT_BUFFER_ALLOW_WRITE 0x00000002
#define SMBDIRECT_BUFFER_INVALIDATE 0x00000004
#define SMBDIRECT_BUFFER_REMOTE 0x00000008
#define SMBDIRECT_BUFFER_DEFINED_FLAGS ( \
SMBDIRECT_BUFFER_ALLOW_READ | \
SMBDIRECT_BUFFER_ALLOW_WRITE | \
SMBDIRECT_BUFFER_INVALIDATE | \
SMBDIRECT_BUFFER_REMOTE | \
0)
__u32 flags;
/* (UINT16_MAX / sizeof(smbdirect_buffer_descriptor_v1)) = 4096 */
#define _SMBDIRECT_BUFFER_COUNT_MAX 4096
__u16 max_count;
__u16 count;
struct smbdirect_buffer_descriptor_v1 array[];
} __packed;
struct smbdirect_buffer_descriptors_v1_fast {
struct smbdirect_buffer_descriptors_v1 hdr;
#ifndef SMBDIRECT_BUFFER_COUNT_FAST
#define SMBDIRECT_BUFFER_COUNT_FAST 32
#endif
struct smbdirect_buffer_descriptor_v1 __fast_array[SMBDIRECT_BUFFER_COUNT_FAST];
} __packed;
#define SMBDIRECT_BUFFER_DESCRIPTORS_V1_FAST_INIT { \
.hdr = { \
.max_count = SMBDIRECT_BUFFER_COUNT_FAST, \
}, \
}
#define SMBDIRECT_BUFFER_DESCRIPTORS_V1_SIZE(count) \
(sizeof(struct smbdirect_buffer_descriptors_v1) + \
sizeof(struct smbdirect_buffer_descriptor_v1)*count)
struct smbdirect_cmsg_buffer {
uint8_t msg_control[CMSG_SPACE(24)];
};
static inline void __smbdirect_cmsg_prepare(struct msghdr *msg,
struct smbdirect_cmsg_buffer *cbuffer,
int cmsg_type,
const void *payload,
size_t payloadlen)
{
size_t cmsg_space = CMSG_SPACE(payloadlen);
size_t cmsg_len = CMSG_LEN(payloadlen);
struct cmsghdr *cmsg = NULL;
void *dataptr = NULL;
BUILD_BUG_ON(cmsg_space > sizeof(cbuffer->msg_control));
BUG_ON(cmsg_space > sizeof(cbuffer->msg_control));
memset(cbuffer, 0, sizeof(*cbuffer));
msg->msg_control = cbuffer->msg_control;
msg->msg_controllen = cmsg_space;
cmsg = CMSG_FIRSTHDR(msg);
cmsg->cmsg_level = SOL_SMBDIRECT;
cmsg->cmsg_type = cmsg_type;
cmsg->cmsg_len = cmsg_len;
dataptr = CMSG_DATA(cmsg);
memcpy(dataptr, payload, payloadlen);
msg->msg_controllen = cmsg->cmsg_len;
}
struct smbdirect_buffer_remote_invalidate_args {
struct smbdirect_buffer_descriptor_v1 first_desc;
} __packed;
#define SMBDIRECT_BUFFER_REMOTE_INVALIDATE_CMSG_TYPE \
_IOW('S', __SMBDIRECT_BUFFER_REMOTE_INVALIDATE, \
struct smbdirect_buffer_remote_invalidate_args)
static inline void smbdirect_buffer_remote_invalidate_cmsg_prepare(struct msghdr *msg,
struct smbdirect_cmsg_buffer *cbuffer,
const struct smbdirect_buffer_descriptor_v1 *desc)
{
struct smbdirect_buffer_remote_invalidate_args args = {
.first_desc = *desc,
};
__smbdirect_cmsg_prepare(msg, cbuffer,
SMBDIRECT_BUFFER_REMOTE_INVALIDATE_CMSG_TYPE,
&args, sizeof(args));
}
ssize_t smbdirect_kern_rdma_v1_writev(struct socket *sock,
const struct smbdirect_buffer_descriptors_v1 *remote,
size_t size,
struct iov_iter *iter);
ssize_t smbdirect_kern_rdma_v1_readv(struct socket *sock,
const struct smbdirect_buffer_descriptors_v1 *remote,
size_t size,
struct iov_iter *iter);
>> But note that is just the direction were it goes, that current code has a lot of resolved merge conflicts,
>> which may not work at all currently.
>>
>> Instead of putting my current code I try to take the existing client and server
>> code and merge it, so that we don't have a flag day commit that switches to
>> completely new code. Instead I try to do tiny steps in that direction
>> and may end with an interface that is similar but might be a bit different in
>> some parts.
> Okay.
>
>>
>>> He can just put these changes in his own queue and work on them.
>>> I am pointing out why he is trying to put unfinished things in the public queue.
>>
>> Because I want to base the next steps on something that is already accepted.
>>
>> I really don't want to work on it for weeks and then some review will void
>> that work completely and I can start again.
> It was too tiny a step and unclear.
> i.e. the patch description should not have comments like "It will be
> used in the next commits..."
What should it say if something is introduced but not yet used?
I mean I could explain in more detail how it will be used in
the next commits?
>>> If You want to apply it, Please do it only on cifs.ko. When it is
>>> properly implemented, I want to apply it to ksmbd.
>>
>> I can keep the ksmbd patches rebased on top and send them again
>> each time to get more feedback.
>>
>> Would that work for you?
> Okay, Please re-include the ksmbd patches in the next patch-set and I
> will check them.
>>
>> The key for me is discuss patches first and have them reviewed early
>> so that the following work rely on. Any the tiny steps should
>> make it possible to do easy review and make it possible to test each
>> tiny step.
> Okay. I agreed. But It should not be too tiny.
> As I said above, please don't send it in pieces that I can understand
> by looking at the next commits.
I'll try to keep them tiny they can always be squashed later,
but splitting them again would be a pain.
You can apply them and do a diff over multiple patches
and tell me which commits I should squash.
Thanks!
metze
[-- Attachment #2: transport_sock.c --]
[-- Type: text/x-csrc, Size: 20708 bytes --]
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
* Copyright (C) 2018 Samsung Electronics Co., Ltd.
* Copyright (C) 2021 Stefan Metzmacher <metze@samba.org>
*/
#include <linux/freezer.h>
#include "smb_common.h"
#include "server.h"
#include "auth.h"
#include "connection.h"
#include "transport_sock.h"
#ifdef CONFIG_SMB_SERVER_SMBDIRECT
#include <rdma/ib_verbs.h>
#include <rdma/rdma_cm.h>
#include <rdma/rw.h>
#include "../common/smbdirect/smbdirect.h"
#endif /* CONFIG_SMB_SERVER_SMBDIRECT */
#define IFACE_STATE_DOWN BIT(0)
#define IFACE_STATE_CONFIGURED BIT(1)
static atomic_t active_num_conn;
struct ksmbd_sock_interface {
struct task_struct *ksmbd_kthread;
struct socket *ksmbd_socket;
struct list_head entry;
char *name;
struct mutex sock_release_lock;
int state;
const char *type;
const struct ksmbd_transport_ops *ops;
};
static LIST_HEAD(iface_list);
static int bind_additional_ifaces;
struct ksmbd_sock_transport {
struct ksmbd_transport transport;
struct socket *sock;
struct kvec *iov;
unsigned int nr_iov;
};
static const struct ksmbd_transport_ops ksmbd_tcp_transport_ops;
#ifdef CONFIG_SMB_SERVER_SMBDIRECT
static const struct ksmbd_transport_ops ksmbd_smbdirect_transport_ops;
static int create_smbdirect_socket(struct ksmbd_sock_interface *iface);
#endif /* CONFIG_SMB_SERVER_SMBDIRECT */
static void ksmbd_sock_stop_kthread(struct task_struct *kthread);
static struct ksmbd_sock_interface *ksmbd_alloc_iface(const char *ifname,
const struct ksmbd_transport_ops *ops);
#define KSMBD_TRANS(t) (&(t)->transport)
#define KSMBD_SOCK_TRANS(t) ((struct ksmbd_sock_transport *)container_of(t, \
struct ksmbd_sock_transport, transport))
static inline void ksmbd_tcp_nodelay(struct socket *sock)
{
tcp_sock_set_nodelay(sock->sk);
}
static inline void ksmbd_tcp_reuseaddr(struct socket *sock)
{
sock_set_reuseaddr(sock->sk);
}
static inline void ksmbd_tcp_rcv_timeout(struct socket *sock, s64 secs)
{
lock_sock(sock->sk);
if (secs && secs < MAX_SCHEDULE_TIMEOUT / HZ - 1)
sock->sk->sk_rcvtimeo = secs * HZ;
else
sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
release_sock(sock->sk);
}
static inline void ksmbd_tcp_snd_timeout(struct socket *sock, s64 secs)
{
sock_set_sndtimeo(sock->sk, secs);
}
static struct ksmbd_sock_transport *ksmbd_sock_transport_alloc(struct socket *client_sk,
struct ksmbd_sock_interface *iface)
{
struct ksmbd_sock_transport *t;
struct ksmbd_conn *conn;
t = kzalloc(sizeof(*t), GFP_KERNEL);
if (!t)
return NULL;
t->sock = client_sk;
conn = ksmbd_conn_alloc();
if (!conn) {
kfree(t);
return NULL;
}
conn->transport = KSMBD_TRANS(t);
KSMBD_TRANS(t)->conn = conn;
KSMBD_TRANS(t)->ops = iface->ops;
return t;
}
void ksmbd_free_transport(struct ksmbd_transport *kt)
{
struct ksmbd_sock_transport *t = KSMBD_SOCK_TRANS(kt);
sock_release(t->sock);
kfree(t->iov);
kfree(t);
}
static void ksmbd_sock_transport_free(struct ksmbd_sock_transport *t)
{
kernel_sock_shutdown(t->sock, SHUT_RDWR);
ksmbd_conn_free(KSMBD_TRANS(t)->conn);
}
/**
* kvec_array_init() - initialize a IO vector segment
* @new: IO vector to be initialized
* @iov: base IO vector
* @nr_segs: number of segments in base iov
* @bytes: total iovec length so far for read
*
* Return: Number of IO segments
*/
static unsigned int kvec_array_init(struct kvec *new, struct kvec *iov,
unsigned int nr_segs, size_t bytes)
{
size_t base = 0;
while (bytes || !iov->iov_len) {
int copy = min(bytes, iov->iov_len);
bytes -= copy;
base += copy;
if (iov->iov_len == base) {
iov++;
nr_segs--;
base = 0;
}
}
memcpy(new, iov, sizeof(*iov) * nr_segs);
new->iov_base += base;
new->iov_len -= base;
return nr_segs;
}
/**
* get_conn_iovec() - get connection iovec for reading from socket
* @t: SOCK transport instance
* @nr_segs: number of segments in iov
*
* Return: return existing or newly allocate iovec
*/
static struct kvec *get_conn_iovec(struct ksmbd_sock_transport *t, unsigned int nr_segs)
{
struct kvec *new_iov;
if (t->iov && nr_segs <= t->nr_iov)
return t->iov;
/* not big enough -- allocate a new one and release the old */
new_iov = kmalloc_array(nr_segs, sizeof(*new_iov), GFP_KERNEL);
if (new_iov) {
kfree(t->iov);
t->iov = new_iov;
t->nr_iov = nr_segs;
}
return new_iov;
}
static unsigned short ksmbd_tcp_get_port(const struct sockaddr *sa)
{
switch (sa->sa_family) {
case AF_INET:
return ntohs(((struct sockaddr_in *)sa)->sin_port);
case AF_INET6:
return ntohs(((struct sockaddr_in6 *)sa)->sin6_port);
}
return 0;
}
/**
* ksmbd_sock_new_connection() - create a new sock session on mount
* @client_sk: socket associated with new connection
* @iface: ksmbd_sock_interface of the listening socket
*
* whenever a new connection is requested, create a conn thread
* (session thread) to handle new incoming smb requests from the connection
*
* Return: 0 on success, otherwise error
*/
static int ksmbd_sock_new_connection(struct socket *client_sk,
struct ksmbd_sock_interface *iface)
{
struct sockaddr *csin;
int rc = 0;
struct ksmbd_sock_transport *t;
struct task_struct *handler;
client_sk->sk->sk_rcvtimeo = KSMBD_SOCK_RECV_TIMEOUT;
client_sk->sk->sk_sndtimeo = KSMBD_SOCK_SEND_TIMEOUT;
t = ksmbd_sock_transport_alloc(client_sk, iface);
if (!t)
return -ENOMEM;
csin = KSMBD_SOCK_PEER_SOCKADDR(KSMBD_TRANS(t)->conn);
if (kernel_getpeername(client_sk, csin) < 0) {
pr_err("client ip resolution failed\n");
rc = -EINVAL;
goto out_error;
}
handler = kthread_run(ksmbd_conn_handler_loop,
KSMBD_TRANS(t)->conn,
"ksmbd:%u",
ksmbd_tcp_get_port(csin));
if (IS_ERR(handler)) {
pr_err("cannot start conn thread\n");
rc = PTR_ERR(handler);
ksmbd_sock_transport_free(t);
}
return rc;
out_error:
ksmbd_sock_transport_free(t);
return rc;
}
/**
* ksmbd_kthread_fn() - listen to new SMB connections and callback server
* @p: arguments to forker thread
*
* Return: 0 on success, error number otherwise
*/
static int ksmbd_kthread_fn(void *p)
{
struct socket *client_sk = NULL;
struct ksmbd_sock_interface *iface = (struct ksmbd_sock_interface *)p;
int ret;
while (!kthread_should_stop()) {
mutex_lock(&iface->sock_release_lock);
if (!iface->ksmbd_socket) {
mutex_unlock(&iface->sock_release_lock);
break;
}
ret = kernel_accept(iface->ksmbd_socket, &client_sk,
SOCK_NONBLOCK);
mutex_unlock(&iface->sock_release_lock);
if (ret) {
if (ret == -EAGAIN)
/* check for new connections every 100 msecs */
schedule_timeout_interruptible(HZ / 10);
continue;
}
if (server_conf.max_connections &&
atomic_inc_return(&active_num_conn) >= server_conf.max_connections) {
pr_info_ratelimited("Limit the maximum number of connections(%u)\n",
atomic_read(&active_num_conn));
atomic_dec(&active_num_conn);
sock_release(client_sk);
continue;
}
ksmbd_debug(CONN, "connect success: accepted new connection\n");
ksmbd_sock_new_connection(client_sk, iface);
}
ksmbd_debug(CONN, "releasing socket\n");
return 0;
}
/**
* ksmbd_tcp_run_kthread() - start forker thread
* @iface: pointer to struct ksmbd_sock_interface
*
* start forker thread(ksmbd/0) at module init time to listen
* on port 445 for new SMB connection requests. It creates per connection
* server threads(ksmbd/x)
*
* Return: 0 on success or error number
*/
static int ksmbd_sock_run_kthread(struct ksmbd_sock_interface *iface)
{
int rc;
struct task_struct *kthread;
kthread = kthread_run(ksmbd_kthread_fn, (void *)iface, "ksmbd-%s-%s",
iface->type, iface->name);
if (IS_ERR(kthread)) {
rc = PTR_ERR(kthread);
return rc;
}
iface->ksmbd_kthread = kthread;
return 0;
}
/**
* ksmbd_sock_readv() - read data from socket in given iovec
* @t: SOCK transport instance
* @iov_orig: base IO vector
* @nr_segs: number of segments in base iov
* @to_read: number of bytes to read from socket
* @max_retries: maximum retry count
*
* Return: on success return number of bytes read from socket,
* otherwise return error number
*/
static int ksmbd_sock_readv(struct ksmbd_sock_transport *t, struct kvec *iov_orig,
unsigned int nr_segs, unsigned int to_read,
int max_retries)
{
int length = 0;
int total_read;
unsigned int segs;
struct msghdr ksmbd_msg;
struct kvec *iov;
struct ksmbd_conn *conn = KSMBD_TRANS(t)->conn;
iov = get_conn_iovec(t, nr_segs);
if (!iov)
return -ENOMEM;
ksmbd_msg.msg_control = NULL;
ksmbd_msg.msg_controllen = 0;
for (total_read = 0; to_read; total_read += length, to_read -= length) {
try_to_freeze();
if (!ksmbd_conn_alive(conn)) {
total_read = -ESHUTDOWN;
break;
}
segs = kvec_array_init(iov, iov_orig, nr_segs, total_read);
length = kernel_recvmsg(t->sock, &ksmbd_msg,
iov, segs, to_read, 0);
if (length == -EINTR) {
total_read = -ESHUTDOWN;
break;
} else if (conn->status == KSMBD_SESS_NEED_RECONNECT) {
total_read = -EAGAIN;
break;
} else if (length == -ERESTARTSYS || length == -EAGAIN) {
/*
* If max_retries is negative, Allow unlimited
* retries to keep connection with inactive sessions.
*/
if (max_retries == 0) {
total_read = length;
break;
} else if (max_retries > 0) {
max_retries--;
}
usleep_range(1000, 2000);
length = 0;
continue;
} else if (length <= 0) {
total_read = length;
break;
}
}
return total_read;
}
/**
* ksmbd_tcp_read() - read data from socket in given buffer
* @t: SOCK transport instance
* @buf: buffer to store read data from socket
* @to_read: number of bytes to read from socket
* @max_retries: number of retries if reading from socket fails
*
* Return: on success return number of bytes read from socket,
* otherwise return error number
*/
static int ksmbd_sock_read(struct ksmbd_transport *t, char *buf,
unsigned int to_read, int max_retries)
{
struct kvec iov;
iov.iov_base = buf;
iov.iov_len = to_read;
return ksmbd_sock_readv(KSMBD_SOCK_TRANS(t), &iov, 1, to_read, max_retries);
}
static int ksmbd_sock_writev(struct ksmbd_transport *t, struct kvec *iov,
int nvecs, int size, bool need_invalidate,
unsigned int remote_key)
{
struct msghdr smb_msg = {.msg_flags = MSG_NOSIGNAL};
#ifdef CONFIG_SMB_SERVER_SMBDIRECT
struct smbdirect_cmsg_buffer cbuffer;
if (need_invalidate) {
struct smbdirect_buffer_descriptor_v1 desc = { .token = remote_key, };
smbdirect_buffer_remote_invalidate_cmsg_prepare(&smb_msg, &cbuffer, &desc);
}
#endif /* CONFIG_SMB_SERVER_SMBDIRECT */
return kernel_sendmsg(KSMBD_SOCK_TRANS(t)->sock, &smb_msg, iov, nvecs, size);
}
static void ksmbd_sock_disconnect(struct ksmbd_transport *t)
{
ksmbd_sock_transport_free(KSMBD_SOCK_TRANS(t));
if (server_conf.max_connections)
atomic_dec(&active_num_conn);
}
static void ksmbd_destroy_socket(struct socket *ksmbd_socket)
{
int ret;
if (!ksmbd_socket)
return;
/* set zero to timeout */
ksmbd_tcp_rcv_timeout(ksmbd_socket, 0);
ksmbd_tcp_snd_timeout(ksmbd_socket, 0);
ret = kernel_sock_shutdown(ksmbd_socket, SHUT_RDWR);
if (ret)
pr_err("Failed to shutdown socket: %d\n", ret);
sock_release(ksmbd_socket);
}
/**
* create_socket - create socket for ksmbd/0
* @iface: interface to bind the created socket to
*
* Return: 0 on success, error number otherwise
*/
static int create_socket(struct ksmbd_sock_interface *iface)
{
int ret;
struct sockaddr_in6 sin6;
struct sockaddr_in sin;
struct socket *ksmbd_socket;
bool ipv4 = false;
ret = sock_create(PF_INET6, SOCK_STREAM, IPPROTO_TCP, &ksmbd_socket);
if (ret) {
if (ret != -EAFNOSUPPORT)
pr_err("Can't create socket for ipv6, fallback to ipv4: %d\n", ret);
ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP,
&ksmbd_socket);
if (ret) {
pr_err("Can't create socket for ipv4: %d\n", ret);
goto out_clear;
}
sin.sin_family = PF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(server_conf.tcp_port);
ipv4 = true;
} else {
sin6.sin6_family = PF_INET6;
sin6.sin6_addr = in6addr_any;
sin6.sin6_port = htons(server_conf.tcp_port);
lock_sock(ksmbd_socket->sk);
ksmbd_socket->sk->sk_ipv6only = false;
release_sock(ksmbd_socket->sk);
}
ksmbd_tcp_nodelay(ksmbd_socket);
ksmbd_tcp_reuseaddr(ksmbd_socket);
ret = sock_setsockopt(ksmbd_socket,
SOL_SOCKET,
SO_BINDTODEVICE,
KERNEL_SOCKPTR(iface->name),
strlen(iface->name));
if (ret != -ENODEV && ret < 0) {
pr_err("Failed to set SO_BINDTODEVICE: %d\n", ret);
goto out_error;
}
if (ipv4)
ret = kernel_bind(ksmbd_socket, (struct sockaddr *)&sin,
sizeof(sin));
else
ret = kernel_bind(ksmbd_socket, (struct sockaddr *)&sin6,
sizeof(sin6));
if (ret) {
pr_err("Failed to bind socket: %d\n", ret);
goto out_error;
}
ksmbd_socket->sk->sk_rcvtimeo = KSMBD_SOCK_RECV_TIMEOUT;
ksmbd_socket->sk->sk_sndtimeo = KSMBD_SOCK_SEND_TIMEOUT;
ret = kernel_listen(ksmbd_socket, KSMBD_SOCKET_BACKLOG);
if (ret) {
pr_err("Port listen() error: %d\n", ret);
goto out_error;
}
iface->ksmbd_socket = ksmbd_socket;
ret = ksmbd_sock_run_kthread(iface);
if (ret) {
pr_err("Can't start ksmbd main kthread: %d\n", ret);
goto out_error;
}
iface->state = IFACE_STATE_CONFIGURED;
return 0;
out_error:
ksmbd_destroy_socket(ksmbd_socket);
out_clear:
iface->ksmbd_socket = NULL;
return ret;
}
static int ksmbd_netdev_event(struct notifier_block *nb, unsigned long event,
void *ptr)
{
struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
struct ksmbd_sock_interface *iface;
int ret, found = 0;
switch (event) {
case NETDEV_UP:
if (netif_is_bridge_port(netdev))
return NOTIFY_OK;
list_for_each_entry(iface, &iface_list, entry) {
if (!strcmp(iface->name, netdev->name)) {
found = 1;
if (iface->state != IFACE_STATE_DOWN)
break;
ret = create_socket(iface);
if (ret)
return NOTIFY_OK;
break;
}
}
if (!found && bind_additional_ifaces) {
iface = ksmbd_alloc_iface(netdev->name,
&ksmbd_tcp_transport_ops);
if (!iface)
return NOTIFY_OK;
ret = create_socket(iface);
if (ret)
break;
}
break;
case NETDEV_DOWN:
list_for_each_entry(iface, &iface_list, entry) {
if (!strcmp(iface->name, netdev->name) &&
iface->state == IFACE_STATE_CONFIGURED) {
ksmbd_sock_stop_kthread(iface->ksmbd_kthread);
iface->ksmbd_kthread = NULL;
mutex_lock(&iface->sock_release_lock);
ksmbd_destroy_socket(iface->ksmbd_socket);
iface->ksmbd_socket = NULL;
mutex_unlock(&iface->sock_release_lock);
iface->state = IFACE_STATE_DOWN;
break;
}
}
break;
}
return NOTIFY_DONE;
}
static struct notifier_block ksmbd_netdev_notifier = {
.notifier_call = ksmbd_netdev_event,
};
int ksmbd_sock_init(void)
{
register_netdevice_notifier(&ksmbd_netdev_notifier);
return 0;
}
static void ksmbd_sock_stop_kthread(struct task_struct *kthread)
{
int ret;
if (!kthread)
return;
ret = kthread_stop(kthread);
if (ret)
pr_err("failed to stop forker thread\n");
}
void ksmbd_sock_destroy(void)
{
struct ksmbd_sock_interface *iface, *tmp;
unregister_netdevice_notifier(&ksmbd_netdev_notifier);
list_for_each_entry_safe(iface, tmp, &iface_list, entry) {
list_del(&iface->entry);
kfree(iface->name);
kfree(iface);
}
}
static struct ksmbd_sock_interface *ksmbd_alloc_iface(const char *ifname,
const struct ksmbd_transport_ops *ops)
{
struct ksmbd_sock_interface *iface;
iface = kzalloc(sizeof(struct ksmbd_sock_interface), GFP_KERNEL);
if (!iface) {
return NULL;
}
if (ops == &ksmbd_tcp_transport_ops) {
iface->type = "tcp";
#ifdef CONFIG_SMB_SERVER_SMBDIRECT
} else if (ops == &ksmbd_smbdirect_transport_ops) {
iface->type = "smbdirect";
#endif /* CONFIG_SMB_SERVER_SMBDIRECT */
} else {
WARN_ON_ONCE(1);
kfree(iface);
return NULL;
}
iface->ops = ops;
iface->name = kstrdup(ifname, GFP_KERNEL);
if (!iface->name) {
kfree(iface);
return NULL;
}
iface->state = IFACE_STATE_DOWN;
list_add(&iface->entry, &iface_list);
mutex_init(&iface->sock_release_lock);
return iface;
}
int ksmbd_sock_set_interfaces(char *ifc_list, int ifc_list_sz)
{
int sz = 0;
#ifdef CONFIG_SMB_SERVER_SMBDIRECT
{
struct ksmbd_sock_interface *iface;
iface = ksmbd_alloc_iface("smbdirect-sock",
&ksmbd_smbdirect_transport_ops);
if (iface != NULL) {
int ret;
ret = create_smbdirect_socket(iface);
if (ret)
pr_err("create_smbdirect_socket() failed: %d\n", ret);
}
}
#endif /* CONFIG_SMB_SERVER_SMBDIRECT */
if (!ifc_list_sz) {
struct net_device *netdev;
rtnl_lock();
for_each_netdev(&init_net, netdev) {
struct ksmbd_sock_interface *iface;
if (netif_is_bridge_port(netdev))
continue;
iface = ksmbd_alloc_iface(netdev->name,
&ksmbd_tcp_transport_ops);
if (!iface) {
rtnl_unlock();
return -ENOMEM;
}
}
rtnl_unlock();
bind_additional_ifaces = 1;
return 0;
}
while (ifc_list_sz > 0) {
struct ksmbd_sock_interface *iface;
iface = ksmbd_alloc_iface(ifc_list,
&ksmbd_tcp_transport_ops);
if (!iface)
return -ENOMEM;
sz = strlen(ifc_list);
if (!sz)
break;
ifc_list += sz + 1;
ifc_list_sz -= (sz + 1);
}
bind_additional_ifaces = 0;
return 0;
}
static const struct ksmbd_transport_ops ksmbd_tcp_transport_ops = {
.read = ksmbd_sock_read,
.writev = ksmbd_sock_writev,
.disconnect = ksmbd_sock_disconnect,
};
#ifdef CONFIG_SMB_SERVER_SMBDIRECT
static bool rdma_frwr_is_supported(struct ib_device_attr *attrs)
{
if (!(attrs->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS))
return false;
if (attrs->max_fast_reg_page_list_len == 0)
return false;
return true;
}
bool ksmbd_netdev_rdma_capable(struct net_device *netdev)
{
struct ib_device *ibdev;
bool rdma_capable = false;
ibdev = ib_device_get_by_netdev(netdev, RDMA_DRIVER_UNKNOWN);
if (ibdev) {
if (rdma_frwr_is_supported(&ibdev->attrs))
rdma_capable = true;
ib_device_put(ibdev);
}
return rdma_capable;
}
static int create_smbdirect_socket(struct ksmbd_sock_interface *iface)
{
struct sockaddr_in sin = {
.sin_family = AF_INET,
.sin_addr.s_addr= htonl(INADDR_ANY),
.sin_port = htons(5445),
};
struct socket *ksmbd_socket;
int ret;
ret = sock_create(PF_SMBDIRECT, SOCK_STREAM, AF_INET, &ksmbd_socket);
if (ret) {
pr_err("Can't create smbdirect socket for ipv4: %d\n", ret);
goto out_error;
}
ret = kernel_bind(ksmbd_socket, (struct sockaddr *)&sin,
sizeof(sin));
if (ret) {
pr_err("Failed to bind socket: %d\n", ret);
goto out_error;
}
ksmbd_socket->sk->sk_rcvtimeo = KSMBD_SOCK_RECV_TIMEOUT;
ksmbd_socket->sk->sk_sndtimeo = KSMBD_SOCK_SEND_TIMEOUT;
ret = kernel_listen(ksmbd_socket, KSMBD_SOCKET_BACKLOG);
if (ret) {
pr_err("Port listen() error: %d\n", ret);
goto out_error;
}
iface->ksmbd_socket = ksmbd_socket;
ret = ksmbd_sock_run_kthread(iface);
if (ret) {
pr_err("Can't start ksmbd main kthread: %d\n", ret);
goto out_error;
}
iface->state = IFACE_STATE_CONFIGURED;
return 0;
out_error:
ksmbd_destroy_socket(ksmbd_socket);
iface->ksmbd_socket = NULL;
return ret;
}
static int ksmbd_sock_rdma_write(struct ksmbd_transport *t,
void *buf, unsigned int buflen,
const struct smbdirect_buffer_descriptors_v1 *remote)
{
struct bio_vec biov = {
.bv_page = is_vmalloc_addr(buf) ? vmalloc_to_page(buf) : kmap_to_page(buf),
.bv_offset = offset_in_page(buf),
.bv_len = buflen,
};
struct iov_iter iter;
ssize_t ret;
iov_iter_bvec(&iter, WRITE, &biov, 1, buflen);
ret = smbdirect_kern_rdma_v1_writev(KSMBD_SOCK_TRANS(t)->sock,
remote,
buflen,
&iter);
if (ret < 0) {
return ret;
}
return 0;
}
static int ksmbd_sock_rdma_read(struct ksmbd_transport *t,
void *buf, unsigned int buflen,
const struct smbdirect_buffer_descriptors_v1 *remote)
{
struct bio_vec biov = {
.bv_page = is_vmalloc_addr(buf) ? vmalloc_to_page(buf) : kmap_to_page(buf),
.bv_offset = offset_in_page(buf),
.bv_len = buflen,
};
struct iov_iter iter;
ssize_t ret;
iov_iter_bvec(&iter, READ, &biov, 1, buflen);
ret = smbdirect_kern_rdma_v1_readv(KSMBD_SOCK_TRANS(t)->sock,
remote,
buflen,
&iter);
if (ret < 0) {
return ret;
}
return 0;
}
static const struct ksmbd_transport_ops ksmbd_smbdirect_transport_ops = {
.read = ksmbd_sock_read,
.writev = ksmbd_sock_writev,
.disconnect = ksmbd_sock_disconnect,
.rdma_read = ksmbd_sock_rdma_read,
.rdma_write = ksmbd_sock_rdma_write,
};
#endif /* CONFIG_SMB_SERVER_SMBDIRECT */
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions
2025-06-03 9:06 ` Stefan Metzmacher
@ 2025-06-03 10:55 ` Namjae Jeon
0 siblings, 0 replies; 27+ messages in thread
From: Namjae Jeon @ 2025-06-03 10:55 UTC (permalink / raw)
To: Stefan Metzmacher
Cc: Steve French, CIFS, Tom Talpey, Long Li, Hyunchul Lee,
Meetakshi Setiya, samba-technical
[snip]
> >>> He can just put these changes in his own queue and work on them.
> >>> I am pointing out why he is trying to put unfinished things in the public queue.
> >>
> >> Because I want to base the next steps on something that is already accepted.
> >>
> >> I really don't want to work on it for weeks and then some review will void
> >> that work completely and I can start again.
> > It was too tiny a step and unclear.
> > i.e. the patch description should not have comments like "It will be
> > used in the next commits..."
>
> What should it say if something is introduced but not yet used?
>
> I mean I could explain in more detail how it will be used in
> the next commits?
It should be added when it is used. If it is not used, it does not
need to be added now.
>
> >>> If You want to apply it, Please do it only on cifs.ko. When it is
> >>> properly implemented, I want to apply it to ksmbd.
> >>
> >> I can keep the ksmbd patches rebased on top and send them again
> >> each time to get more feedback.
> >>
> >> Would that work for you?
> > Okay, Please re-include the ksmbd patches in the next patch-set and I
> > will check them.
> >>
> >> The key for me is discuss patches first and have them reviewed early
> >> so that the following work rely on. Any the tiny steps should
> >> make it possible to do easy review and make it possible to test each
> >> tiny step.
> > Okay. I agreed. But It should not be too tiny.
> > As I said above, please don't send it in pieces that I can understand
> > by looking at the next commits.
>
> I'll try to keep them tiny they can always be squashed later,
> but splitting them again would be a pain.
I am sorry, there was a misunderstanding.
What I mean is not that each patch is too tiny, but that the entire
patch-set is small.
So It is not clearly concluded in the patch-set and I have to wait for
the next commits to understand it.
>
> You can apply them and do a diff over multiple patches
> and tell me which commits I should squash.
Okay. Let me check them on the next patch-set.
Thanks!
>
> Thanks!
> metze
^ permalink raw reply [flat|nested] 27+ messages in thread
end of thread, other threads:[~2025-06-03 10:55 UTC | newest]
Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-28 16:01 [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 01/12] smb: smbdirect: add smbdirect_pdu.h with protocol definitions Stefan Metzmacher
2025-05-28 23:28 ` Namjae Jeon
2025-05-30 19:03 ` Stefan Metzmacher
2025-05-30 19:27 ` Steve French
2025-05-30 22:29 ` Namjae Jeon
[not found] ` <CAH2r5mvQbL_R9wrFRHF9_3XwM3e-=2vK=i1uaSCk37-FZmJq9g@mail.gmail.com>
2025-06-01 0:01 ` Namjae Jeon
[not found] ` <CAH2r5mso54sXPcoJWDSU4E--XMH44wFY-cdww6_6yx5CxrFtdg@mail.gmail.com>
2025-06-01 4:59 ` Namjae Jeon
2025-06-02 1:56 ` Steve French
2025-06-02 2:19 ` Namjae Jeon
2025-06-02 22:02 ` Stefan Metzmacher
2025-06-03 6:20 ` Namjae Jeon
2025-06-03 9:06 ` Stefan Metzmacher
2025-06-03 10:55 ` Namjae Jeon
2025-05-28 16:01 ` [PATCH v2 02/12] smb: client: make use of common smbdirect_pdu.h Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 03/12] smb: server: " Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 04/12] smb: smbdirect: add smbdirect.h with public structures Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 05/12] smb: client: make use of common smbdirect.h Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 06/12] smb: server: " Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 07/12] smb: smbdirect: add smbdirect_socket.h Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 08/12] smb: client: make use of common smbdirect_socket Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 09/12] smb: server: " Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 10/12] smb: smbdirect: introduce smbdirect_socket_parameters Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 11/12] smb: client: make use of common smbdirect_socket_parameters Stefan Metzmacher
2025-05-28 16:01 ` [PATCH v2 12/12] smb: server: " Stefan Metzmacher
2025-05-29 3:33 ` [PATCH v2 00/12] smb:common: introduce and use common smbdirect headers/structures (step1) Steve French
2025-05-30 16:51 ` Steve French
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox