[RFC PATCH 24/36] cifs: Add netmem allocation functions
From: David Howells
Date: Tue May 19 2026 - 06:33:30 EST
Add (stub) functions for doing netmem allocations. We want to allocate
memory from the netmem buffering as that does bulk DMA and IOMMU
management.
Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
cc: Steve French <sfrench@xxxxxxxxx>
cc: Paulo Alcantara <pc@xxxxxxxxxxxxx>
cc: Shyam Prasad N <sprasad@xxxxxxxxxxxxx>
cc: Tom Talpey <tom@xxxxxxxxxx>
cc: linux-cifs@xxxxxxxxxxxxxxx
cc: netfs@xxxxxxxxxxxxxxx
cc: linux-fsdevel@xxxxxxxxxxxxxxx
---
fs/smb/client/cifsproto.h | 2 ++
fs/smb/client/transport.c | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h
index 72ee5c5fd8b7..3067056f8ef9 100644
--- a/fs/smb/client/cifsproto.h
+++ b/fs/smb/client/cifsproto.h
@@ -508,5 +508,7 @@ int smb_rxqueue_refill(struct TCP_Server_Info *server, struct netfs_rxqueue *rxq
size_t min_size);
int smb_rxqueue_consume(struct TCP_Server_Info *server, struct netfs_rxqueue *rxq,
size_t amount);
+void *cifs_allocate_tx_buf(struct TCP_Server_Info *server, size_t size);
+void cifs_free_tx_buf(void *p);
#endif /* _CIFSPROTO_H */
diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c
index 68536de2c1a0..1599afb9e5cf 100644
--- a/fs/smb/client/transport.c
+++ b/fs/smb/client/transport.c
@@ -33,6 +33,26 @@
#include "smbdirect.h"
#include "compress.h"
+/*
+ * Allocate transmission buffers for a socket. This memory will be allocated
+ * from the netmem buffers. It comes with a page ref that we need to drop.
+ * The networking layer can pin it by getting its own ref.
+ */
+void *cifs_allocate_tx_buf(struct TCP_Server_Info *server, size_t size)
+{
+ void *p;
+
+ mutex_lock(&server->tx_alloc_lock);
+ p = page_frag_alloc_align(&server->tx_alloc, size, GFP_NOFS, 8);
+ mutex_unlock(&server->tx_alloc_lock);
+ return p;
+}
+
+void cifs_free_tx_buf(void *p)
+{
+ page_frag_free(p);
+}
+
struct smb_message *smb_message_alloc(enum smb_command_trace cmd, gfp_t gfp)
{
static atomic_t debug_ids;