Commit 9f8eeea1 authored by Yunsheng Lin's avatar Yunsheng Lin Committed by Jakub Kicinski

rxrpc: Fix using alignmask being zero for __page_frag_alloc_align()

rxrpc_alloc_data_txbuf() may be called with data_align being
zero in none_alloc_txbuf() and rxkad_alloc_txbuf(), data_align
is supposed to be an order-based alignment value, but zero is
not a valid order-based alignment value, and '~(data_align - 1)'
doesn't result in a valid mask-based alignment value for
__page_frag_alloc_align().

Fix it by passing a valid order-based alignment value in
none_alloc_txbuf() and rxkad_alloc_txbuf().

Also use page_frag_alloc_align() expecting an order-based
alignment value in rxrpc_alloc_data_txbuf() to avoid doing the
alignment converting operation and to catch possible invalid
alignment value in the future. Remove the 'if (data_align)'
checking too, as it is always true for a valid order-based
alignment value.

Fixes: 6b253646 ("rxrpc: Fix use of changed alignment param to page_frag_alloc_align()")
Fixes: 49489bb0 ("rxrpc: Do zerocopy using MSG_SPLICE_PAGES and page frags")
CC: Alexander Duyck <alexander.duyck@gmail.com>
Signed-off-by: default avatarYunsheng Lin <linyunsheng@huawei.com>
Acked-by: default avatarDavid Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/r/20240428111640.27306-1-linyunsheng@huawei.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent ba1cb99b
...@@ -19,7 +19,7 @@ static int none_init_connection_security(struct rxrpc_connection *conn, ...@@ -19,7 +19,7 @@ static int none_init_connection_security(struct rxrpc_connection *conn,
*/ */
static struct rxrpc_txbuf *none_alloc_txbuf(struct rxrpc_call *call, size_t remain, gfp_t gfp) static struct rxrpc_txbuf *none_alloc_txbuf(struct rxrpc_call *call, size_t remain, gfp_t gfp)
{ {
return rxrpc_alloc_data_txbuf(call, min_t(size_t, remain, RXRPC_JUMBO_DATALEN), 0, gfp); return rxrpc_alloc_data_txbuf(call, min_t(size_t, remain, RXRPC_JUMBO_DATALEN), 1, gfp);
} }
static int none_secure_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb) static int none_secure_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
......
...@@ -155,7 +155,7 @@ static struct rxrpc_txbuf *rxkad_alloc_txbuf(struct rxrpc_call *call, size_t rem ...@@ -155,7 +155,7 @@ static struct rxrpc_txbuf *rxkad_alloc_txbuf(struct rxrpc_call *call, size_t rem
switch (call->conn->security_level) { switch (call->conn->security_level) {
default: default:
space = min_t(size_t, remain, RXRPC_JUMBO_DATALEN); space = min_t(size_t, remain, RXRPC_JUMBO_DATALEN);
return rxrpc_alloc_data_txbuf(call, space, 0, gfp); return rxrpc_alloc_data_txbuf(call, space, 1, gfp);
case RXRPC_SECURITY_AUTH: case RXRPC_SECURITY_AUTH:
shdr = sizeof(struct rxkad_level1_hdr); shdr = sizeof(struct rxkad_level1_hdr);
break; break;
......
...@@ -21,20 +21,20 @@ struct rxrpc_txbuf *rxrpc_alloc_data_txbuf(struct rxrpc_call *call, size_t data_ ...@@ -21,20 +21,20 @@ struct rxrpc_txbuf *rxrpc_alloc_data_txbuf(struct rxrpc_call *call, size_t data_
{ {
struct rxrpc_wire_header *whdr; struct rxrpc_wire_header *whdr;
struct rxrpc_txbuf *txb; struct rxrpc_txbuf *txb;
size_t total, hoff = 0; size_t total, hoff;
void *buf; void *buf;
txb = kmalloc(sizeof(*txb), gfp); txb = kmalloc(sizeof(*txb), gfp);
if (!txb) if (!txb)
return NULL; return NULL;
if (data_align)
hoff = round_up(sizeof(*whdr), data_align) - sizeof(*whdr); hoff = round_up(sizeof(*whdr), data_align) - sizeof(*whdr);
total = hoff + sizeof(*whdr) + data_size; total = hoff + sizeof(*whdr) + data_size;
data_align = umax(data_align, L1_CACHE_BYTES);
mutex_lock(&call->conn->tx_data_alloc_lock); mutex_lock(&call->conn->tx_data_alloc_lock);
buf = __page_frag_alloc_align(&call->conn->tx_data_alloc, total, gfp, buf = page_frag_alloc_align(&call->conn->tx_data_alloc, total, gfp,
~(data_align - 1) & ~(L1_CACHE_BYTES - 1)); data_align);
mutex_unlock(&call->conn->tx_data_alloc_lock); mutex_unlock(&call->conn->tx_data_alloc_lock);
if (!buf) { if (!buf) {
kfree(txb); kfree(txb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment