public inbox for linux-next@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Metzmacher <metze@samba.org>
To: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org
Cc: metze@samba.org, Steve French <smfrench@gmail.com>,
	Tom Talpey <tom@talpey.com>, Long Li <longli@microsoft.com>,
	Namjae Jeon <linkinjeon@kernel.org>,
	David Howells <dhowells@redhat.com>,
	Henrique Carvalho <henrique.carvalho@suse.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Willem de Bruijn <willemb@google.com>,
	netdev@vger.kernel.org, Xin Long <lucien.xin@gmail.com>,
	quic@lists.linux.dev, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org, Mark Brown <broonie@kernel.org>,
	linux-next@vger.kernel.org
Subject: [PATCH 0/8] smb: add kernel internal IPPROTO_SMBDIRECT
Date: Tue,  7 Apr 2026 16:46:26 +0200	[thread overview]
Message-ID: <cover.1775571957.git.metze@samba.org> (raw)

Hi,

as the work to unify the smbdirect code
between cifs.ko and ksmbd.ko into an smbdirect.ko
is in linux-next for a while this is the next
step to also share the code with userspace
e.g. Samba as client and server.

The SMBDIRECT protocol, defined in [MS-SMBD] by Microsoft.
It is used as wrapper around RDMA in order to provide a transport for SMB3,
but Microsoft also uses it as transport for other protocols.

SMBDIRECT works over Infiniband, RoCE and iWarp.  RoCEv2 is based on IP/UDP
and iWarp is based on IP/TCP, so these use IP addresses natively.
Infiniband and RoCEv1 require IPOIB in order to be used for SMBDIRECT.

So instead of adding a PF_SMBDIRECT, which would only use AF_INET[6],
we use IPPROTO_SMBDIRECT instead, this uses a number not
allocated from IANA, as it would not appear in an IP header.

This is similar to IPPROTO_SMC, IPPROTO_MPTCP and IPPROTO_QUIC,
which are linux specific values for the socket() syscall.

  socket(AF_INET, SOCK_STREAM, IPPROTO_SMBDIRECT);
  socket(AF_INET6, SOCK_STREAM, IPPROTO_SMBDIRECT);

This will allow the existing smbdirect code used by
cifs.ko and ksmbd.ko to be moved behind the socket layer [1],
so that there's less special handling. Only sock_sendmsg()
sock_recvmsg() are used, so that the main stream handling
is done all the same for tcp, smbdirect and later also quic.

The special RDMA read/write handling will be via direct
function calls as they are currently done for the in kernel
consumers.

As a start __sock_create(kern=0)/sk->sk_kern_sock == 0 will
still cause a -EPROTONOSUPPORT. So only in kernel consumers
will be supported for now.

For now the core smbdirect code still supports both
modes, direct calls in indirect via the socket layer.
The core code uses if (sc->sk.sk_family) as indication
for the new socket mode. Once cifs.ko and ksmbd.ko
are converted we can remove the old mode slowly,
but I'll deferr that to a future patchset.

There's still a way to go in order to make this
as generic as tcp and quic e.g. adding MSG_SPLICE_PAGES support or
splice_read/read_sock/read_skb.

But it's a good start, which will make changes much easier.

This patchset is based on top of the smbdirect.ko patches
in ksmbd-for-next and it's also based on netdev-next
because it needs this commit from there:
8341c989ac77d712c7d6e2bce29e8a4bcb2eeae4
"net: remove addr_len argument of recvmsg() handlers"

Patches 1-4 are some preparation fixes for the
existing smbdirect.ko patchset. We may
squash them into the existing patches before
sending them to Linus. But for now I kept
them separately. I also don't cc the network and rdma
people on these...

Patch 5 defines IPPROTO_SMBDIRECT and SOL_SMBDIRECT
constants (and also reserve the number 288 for SOL_QUIC
as applications are already using that and we don't
want to conflict)

Patch 6 adds basic IPPROTO_SMBDIRECT layering
on top of the existing smbdirect code.
This is just enough in order to let cifs.ko
and ksmbd.ko use it in the following commits,
so userspace still sees -EPROTONOSUPPORT.

Patch 7 converts cifs.ko to use IPPROTO_SMBDIRECT
as much as currently possible.
Using sock_sendmsg is not yet possible, because of the
tcp_sock_set_cork usage, but that will change in future.

Patch 8 converts ksmbd.ko to use IPPROTO_SMBDIRECT.

Because of the need for netdev-next commit
8341c989ac77d712c7d6e2bce29e8a4bcb2eeae4
"net: remove addr_len argument of recvmsg() handlers"
it's a bit tricky to prepare something that would not
cause problems in linux-next.

We could merge in netdev-next completely,
but I saw commit 00f03539e3d97af925abf42992d8c46167d54243
in next-20260406, indicates some resolved conflicts
with (at least) the rdma tree, which comes
just before netdev-next, while ksmbd-for-next is merged
before all of them. So merging netdev-next into
ksmbd-for-next changes the order of netdev-next vs. rdma.

Or we add a new branch smbdirect-for-next that's
merged into linux-next after netdev-next.

Or a bit hacky but likely easier, ksmbd-for-next
just cherry-picks 8341c989ac77d712c7d6e2bce29e8a4bcb2eeae4
"net: remove addr_len argument of recvmsg() handlers"
and that cherry picked commit is reverted as
last commit in ksmbd-for-next, or only in linux-next
right before netdev-next is merged.

For now I have the patches in a branch with a
cherry picked version of the needed commit only, see
for-7.1/ipproto-smbdirect-20260407-v1 at commit:
e1972e6f1fda9842c5724b7daf4a2aa7779901a5
git fetch https://git.samba.org/metze/linux/wip.git for-7.1/ipproto-smbdirect-20260407-v1
https://git.samba.org/?p=metze/linux/wip.git;a=shortlog;h=refs/heads/for-7.1/ipproto-smbdirect-20260407-v1

It would be great to get this somehow into linux-next soon :-)

Stefan Metzmacher (8):
  smb: smbdirect: change
    smbdirect_socket_parameters.{initiator_depth,responder_resources} to
    __u16
  smb: smbdirect: fix copyright header of smbdirect.h
  smb: smbdirect: fix the logic in smbdirect_socket_destroy_sync()
    without an error
  smb: smbdirect: let smbdirect_connection_deregister_mr_io unlock while
    waiting
  net: define IPPROTO_SMBDIRECT and SOL_SMBDIRECT constants
  smb: smbdirect: add in kernel only support for IPPROTO_SMBDIRECT
  smb: client: make use of IPPROTO_SMBDIRECT sockets
  smb: server: make use of IPPROTO_SMBDIRECT sockets

 fs/smb/client/cifs_debug.c                    |    2 +-
 fs/smb/client/cifsfs.c                        |    2 +-
 fs/smb/client/cifsglob.h                      |    7 +-
 fs/smb/client/connect.c                       |  123 +-
 fs/smb/client/file.c                          |    8 +-
 fs/smb/client/sess.c                          |    4 +-
 fs/smb/client/smb2ops.c                       |    8 +-
 fs/smb/client/smb2pdu.c                       |   10 +-
 fs/smb/client/smbdirect.c                     |  275 +--
 fs/smb/client/smbdirect.h                     |   27 +-
 fs/smb/client/transport.c                     |    2 +-
 fs/smb/common/smbdirect/Makefile              |    1 +
 fs/smb/common/smbdirect/smbdirect.h           |   69 +-
 fs/smb/common/smbdirect/smbdirect_accept.c    |   14 +-
 .../common/smbdirect/smbdirect_connection.c   |   58 +
 fs/smb/common/smbdirect/smbdirect_devices.c   |    2 +-
 fs/smb/common/smbdirect/smbdirect_internal.h  |   59 +-
 fs/smb/common/smbdirect/smbdirect_listen.c    |   49 +-
 fs/smb/common/smbdirect/smbdirect_main.c      |   45 +
 fs/smb/common/smbdirect/smbdirect_mr.c        |   18 +
 fs/smb/common/smbdirect/smbdirect_proto.c     | 1549 +++++++++++++++++
 fs/smb/common/smbdirect/smbdirect_public.h    |    3 +
 fs/smb/common/smbdirect/smbdirect_rw.c        |   29 +-
 fs/smb/common/smbdirect/smbdirect_socket.c    |  180 +-
 fs/smb/common/smbdirect/smbdirect_socket.h    |   26 +-
 fs/smb/server/transport_rdma.c                |  119 +-
 include/linux/socket.h                        |    2 +
 include/uapi/linux/in.h                       |    2 +
 28 files changed, 2320 insertions(+), 373 deletions(-)
 create mode 100644 fs/smb/common/smbdirect/smbdirect_proto.c

-- 
2.43.0


             reply	other threads:[~2026-04-07 15:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-07 14:46 Stefan Metzmacher [this message]
2026-04-07 21:18 ` [PATCH 0/8] smb: add kernel internal IPPROTO_SMBDIRECT Steve French

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1775571957.git.metze@samba.org \
    --to=metze@samba.org \
    --cc=broonie@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=edumazet@google.com \
    --cc=henrique.carvalho@suse.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=longli@microsoft.com \
    --cc=lucien.xin@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=quic@lists.linux.dev \
    --cc=samba-technical@lists.samba.org \
    --cc=smfrench@gmail.com \
    --cc=tom@talpey.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox