net/smc: cap allocation order for SMC-R physically contiguous buffers
Subsystems (5)
D. Wythe
maintainerPATCH v2 1/1 net/smc: cap allocation order for SMC-R physically contiguous buffers
The alloc_pages() cannot satisfy requests exceeding MAX_PAGE_ORDER, and attempting such allocations will lead to guaranteed failures and potential kernel warnings.
For SMCR_PHYS_CONT_BUFS, cap the allocation order to MAX_PAGE_ORDER. This ensures the attempts to allocate the largest possible physically contiguous chunk succeed, instead of failing with an invalid order. This also avoids redundant "try-fail-degrade" cycles in __smc_buf_create().
For SMCR_MIXED_BUFS, no cap is needed: if the order exceeds MAX_PAGE_ORDER, alloc_pages() will silently fail (__GFP_NOWARN) and automatically fall back to virtual memory.
---
Changes v1 -> v2:
https://lore.kernel.org/netdev/[email protected]/
- Move the bufsize cap from smcr_new_buf_create() up to __smc_buf_create(), which is simpler and avoids touching the allocation logic itself.
--- net/smc/smc_core.c | 4 ++++ 1 file changed, 4 insertions(+)
net/smc/smc_core.c +4 -0
@@ -2440,6 +2440,10 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)/* use socket send buffer size (w/o overhead) as start value */ bufsize = smc->sk.sk_sndbuf /2 ; +/* limit bufsize for physically contiguous buffers */ +if (!is_smcd && lgr->buf_type ==SMCR_PHYS_CONT_BUFS ) + bufsize =min_t (int, bufsize, (PAGE_SIZE <<MAX_PAGE_ORDER )); +for (bufsize_comp =smc_compress_bufsize (bufsize, is_smcd, is_rmb); bufsize_comp >=0 ; bufsize_comp--) {if (is_rmb) {
Signature · 1 line
2.45.0
Quoted 16 lines · D. Wythe
The
alloc_pages()cannot satisfy requests exceedingMAX_PAGE_ORDER, and attempting such allocations will lead to guaranteed failures and potential kernel warnings.For
SMCR_PHYS_CONT_BUFS, cap the allocation order toMAX_PAGE_ORDER. This ensures the attempts to allocate the largest possible physically contiguous chunk succeed, instead of failing with an invalid order. This also avoids redundant "try-fail-degrade" cycles in__smc_buf_create().For
SMCR_MIXED_BUFS, no cap is needed: if the order exceedsMAX_PAGE_ORDER,alloc_pages()will silently fail (__GFP_NOWARN) and automatically fall back to virtual memory.Signed-off-by D. Wythe <[email protected]>Reviewed-by Dust Li <[email protected]>
Quoted 7 lines
---
Changes v1 -> v2:
https://lore.kernel.org/netdev/[email protected]/- Move the bufsize cap from
smcr_new_buf_create()up to__smc_buf_create(), which is simpler and avoids touching the allocation logic itself.
The nit below notwithstanding, this looks good to me.
Quoted 9 lines
--- net/smc/smc_core.c | 4 ++++ 1 file changed, 4 insertions(+)net/smc/smc_core.c +0
-0
net/smc/smc_core.c static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb) · line 2445
Quoted 6 lines
net/smc/smc_core.c +3
-0@@ -2440,6 +2440,10 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)/* use socket send buffer size (w/o overhead) as start value */ bufsize = smc->sk.sk_sndbuf /2 ; +/* limit bufsize for physically contiguous buffers */ +if (!is_smcd && lgr->buf_type ==SMCR_PHYS_CONT_BUFS ) + bufsize =min_t (int, bufsize, (PAGE_SIZE <<MAX_PAGE_ORDER ));
nit: I think min() is sufficient here, and the inner parentheses are
unnecessary
Quoted 7 lines
net/smc/smc_core.c +1
-0+for (bufsize_comp =smc_compress_bufsize (bufsize, is_smcd, is_rmb); bufsize_comp >=0 ; bufsize_comp--) {if (is_rmb) {Signature · 1 line
2.45.0
D. Wythe
maintainerQuoted 41 lines · Simon Horman
Quoted 16 lines · D. Wythe
The
alloc_pages()cannot satisfy requests exceedingMAX_PAGE_ORDER, and attempting such allocations will lead to guaranteed failures and potential kernel warnings.For
SMCR_PHYS_CONT_BUFS, cap the allocation order toMAX_PAGE_ORDER. This ensures the attempts to allocate the largest possible physically contiguous chunk succeed, instead of failing with an invalid order. This also avoids redundant "try-fail-degrade" cycles in__smc_buf_create().For
SMCR_MIXED_BUFS, no cap is needed: if the order exceedsMAX_PAGE_ORDER,alloc_pages()will silently fail (__GFP_NOWARN) and automatically fall back to virtual memory.Signed-off-by D. Wythe <[email protected]>Reviewed-by Dust Li <[email protected]>Quoted 7 lines
---
Changes v1 -> v2:
https://lore.kernel.org/netdev/[email protected]/- Move the bufsize cap from
smcr_new_buf_create()up to__smc_buf_create(), which is simpler and avoids touching the allocation logic itself.The nit below notwithstanding, this looks good to me.
Reviewed-by Simon Horman <[email protected]>Quoted 12 lines
--- net/smc/smc_core.c | 4 ++++ 1 file changed, 4 insertions(+)net/smc/smc_core.c +0
-0@@ -2440,6 +2440,10 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)/* use socket send buffer size (w/o overhead) as start value */ bufsize = smc->sk.sk_sndbuf /2 ;
Quoted 6 lines
net/smc/smc_core.c static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb) · line 2445
Quoted 3 lines
net/smc/smc_core.c +3
-0+/* limit bufsize for physically contiguous buffers */ +if (!is_smcd && lgr->buf_type ==SMCR_PHYS_CONT_BUFS ) + bufsize =min_t (int, bufsize, (PAGE_SIZE <<MAX_PAGE_ORDER ));nit: I think
min()is sufficient here, and the inner parentheses are
unnecessary
Hi Simon,
I think min_t is required here because min() triggers a signedness error:
././include/linux/compiler_types.h:706:38: error: call to ‘__compiletime_assert_950’ declared with attribute error: min(bufsize, ((1UL) << 12) << 10) signedness error
The inner parentheses can be removed, though.
D. Wythe
Quoted 8 lines
Quoted 8 lines
net/smc/smc_core.c +1
-0+for (bufsize_comp =smc_compress_bufsize (bufsize, is_smcd, is_rmb); bufsize_comp >=0 ; bufsize_comp--) {if (is_rmb) {Signature · 1 line
2.45.0
Simon Horman
reviewerQuoted 51 lines · D. Wythe
Quoted 41 lines · Simon Horman
Quoted 16 lines · D. Wythe
The
alloc_pages()cannot satisfy requests exceedingMAX_PAGE_ORDER, and attempting such allocations will lead to guaranteed failures and potential kernel warnings.For
SMCR_PHYS_CONT_BUFS, cap the allocation order toMAX_PAGE_ORDER. This ensures the attempts to allocate the largest possible physically contiguous chunk succeed, instead of failing with an invalid order. This also avoids redundant "try-fail-degrade" cycles in__smc_buf_create().For
SMCR_MIXED_BUFS, no cap is needed: if the order exceedsMAX_PAGE_ORDER,alloc_pages()will silently fail (__GFP_NOWARN) and automatically fall back to virtual memory.Signed-off-by D. Wythe <[email protected]>Reviewed-by Dust Li <[email protected]>Quoted 7 lines
---
Changes v1 -> v2:
https://lore.kernel.org/netdev/[email protected]/- Move the bufsize cap from
smcr_new_buf_create()up to__smc_buf_create(), which is simpler and avoids touching the allocation logic itself.The nit below notwithstanding, this looks good to me.
Reviewed-by Simon Horman <[email protected]>Quoted 12 lines
--- net/smc/smc_core.c | 4 ++++ 1 file changed, 4 insertions(+)net/smc/smc_core.c +0
-0@@ -2440,6 +2440,10 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)/* use socket send buffer size (w/o overhead) as start value */ bufsize = smc->sk.sk_sndbuf /2 ;Quoted 6 lines
net/smc/smc_core.c static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb) · line 2445
Quoted 3 lines
net/smc/smc_core.c +3
-0+/* limit bufsize for physically contiguous buffers */ +if (!is_smcd && lgr->buf_type ==SMCR_PHYS_CONT_BUFS ) + bufsize =min_t (int, bufsize, (PAGE_SIZE <<MAX_PAGE_ORDER ));nit: I think
min()is sufficient here, and the inner parentheses are
unnecessaryHi Simon,
Quoted 8 lines
I think
min_tis required here becausemin()triggers a signedness error:
././include/linux/compiler_types.h:706:38: error: call to ‘__compiletime_assert_950’ declared with attribute error:min(bufsize, ((1UL) << 12) << 10)signedness errorThe inner parentheses can be removed, though.
Ack, thanks for checking.
Quoted 32 lines · D. Wythe
The
alloc_pages()cannot satisfy requests exceedingMAX_PAGE_ORDER, and attempting such allocations will lead to guaranteed failures and potential kernel warnings.For
SMCR_PHYS_CONT_BUFS, cap the allocation order toMAX_PAGE_ORDER. This ensures the attempts to allocate the largest possible physically contiguous chunk succeed, instead of failing with an invalid order. This also avoids redundant "try-fail-degrade" cycles in__smc_buf_create().For
SMCR_MIXED_BUFS, no cap is needed: if the order exceedsMAX_PAGE_ORDER,alloc_pages()will silently fail (__GFP_NOWARN) and automatically fall back to virtual memory.Signed-off-by D. Wythe <[email protected]>Reviewed-by Dust Li <[email protected]>---
Changes v1 -> v2:
https://lore.kernel.org/netdev/[email protected]/- Move the bufsize cap from
smcr_new_buf_create()up to__smc_buf_create(), which is simpler and avoids touching the allocation logic itself.--- net/smc/smc_core.c | 4 ++++ 1 file changed, 4 insertions(+)net/smc/smc_core.c +0
-0
net/smc/smc_core.c static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb) · line 2449
Quoted 10 lines
net/smc/smc_core.c +4
-0@@ -2440,6 +2440,10 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)/* use socket send buffer size (w/o overhead) as start value */ bufsize = smc->sk.sk_sndbuf /2 ; +/* limit bufsize for physically contiguous buffers */ +if (!is_smcd && lgr->buf_type ==SMCR_PHYS_CONT_BUFS ) + bufsize =min_t (int, bufsize, (PAGE_SIZE <<MAX_PAGE_ORDER )); +for (bufsize_comp =smc_compress_bufsize (bufsize, is_smcd, is_rmb); bufsize_comp >=0 ; bufsize_comp--) {if (is_rmb) {
Code changes looks good to me.
Thanks