* [PATCH net-next v2] net/smc: cap allocation order for SMC-R physically contiguous buffers @ 2026-04-07 12:43 D. Wythe 2026-04-10 15:16 ` Simon Horman 0 siblings, 1 reply; 4+ messages in thread From: D. Wythe @ 2026-04-07 12:43 UTC (permalink / raw) To: David S. Miller, Dust Li, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Sidraya Jayagond, Wenjia Zhang Cc: Mahanta Jambigi, Simon Horman, Tony Lu, Wen Gu, linux-kernel, linux-rdma, linux-s390, netdev, oliver.yang, pasic 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. Signed-off-by: D. Wythe <alibuda@linux.alibaba.com> Reviewed-by: Dust Li <dust.li@linux.alibaba.com> --- Changes v1 -> v2: https://lore.kernel.org/netdev/20260312082154.36971-1-alibuda@linux.alibaba.com/ - 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(+) diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c index e2d083daeb7e..cdd881746e21 100644 --- a/net/smc/smc_core.c +++ b/net/smc/smc_core.c @@ -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) { -- 2.45.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] net/smc: cap allocation order for SMC-R physically contiguous buffers 2026-04-07 12:43 [PATCH net-next v2] net/smc: cap allocation order for SMC-R physically contiguous buffers D. Wythe @ 2026-04-10 15:16 ` Simon Horman 2026-04-14 2:10 ` D. Wythe 0 siblings, 1 reply; 4+ messages in thread From: Simon Horman @ 2026-04-10 15:16 UTC (permalink / raw) To: D. Wythe Cc: David S. Miller, Dust Li, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Sidraya Jayagond, Wenjia Zhang, Mahanta Jambigi, Tony Lu, Wen Gu, linux-kernel, linux-rdma, linux-s390, netdev, oliver.yang, pasic On Tue, Apr 07, 2026 at 08:43:37PM +0800, D. Wythe wrote: > 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. > > Signed-off-by: D. Wythe <alibuda@linux.alibaba.com> > Reviewed-by: Dust Li <dust.li@linux.alibaba.com> > --- > Changes v1 -> v2: > https://lore.kernel.org/netdev/20260312082154.36971-1-alibuda@linux.alibaba.com/ > > - 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 <horms@kernel.org> > --- > net/smc/smc_core.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c > index e2d083daeb7e..cdd881746e21 100644 > --- a/net/smc/smc_core.c > +++ b/net/smc/smc_core.c > @@ -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 > + > for (bufsize_comp = smc_compress_bufsize(bufsize, is_smcd, is_rmb); > bufsize_comp >= 0; bufsize_comp--) { > if (is_rmb) { > -- > 2.45.0 > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] net/smc: cap allocation order for SMC-R physically contiguous buffers 2026-04-10 15:16 ` Simon Horman @ 2026-04-14 2:10 ` D. Wythe 2026-04-14 17:16 ` Simon Horman 0 siblings, 1 reply; 4+ messages in thread From: D. Wythe @ 2026-04-14 2:10 UTC (permalink / raw) To: Simon Horman Cc: D. Wythe, David S. Miller, Dust Li, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Sidraya Jayagond, Wenjia Zhang, Mahanta Jambigi, Tony Lu, Wen Gu, linux-kernel, linux-rdma, linux-s390, netdev, oliver.yang, pasic On Fri, Apr 10, 2026 at 04:16:31PM +0100, Simon Horman wrote: > On Tue, Apr 07, 2026 at 08:43:37PM +0800, D. Wythe wrote: > > 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. > > > > Signed-off-by: D. Wythe <alibuda@linux.alibaba.com> > > Reviewed-by: Dust Li <dust.li@linux.alibaba.com> > > --- > > Changes v1 -> v2: > > https://lore.kernel.org/netdev/20260312082154.36971-1-alibuda@linux.alibaba.com/ > > > > - 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 <horms@kernel.org> > > > --- > > net/smc/smc_core.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c > > index e2d083daeb7e..cdd881746e21 100644 > > --- a/net/smc/smc_core.c > > +++ b/net/smc/smc_core.c > > @@ -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 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 > > > + > > for (bufsize_comp = smc_compress_bufsize(bufsize, is_smcd, is_rmb); > > bufsize_comp >= 0; bufsize_comp--) { > > if (is_rmb) { > > -- > > 2.45.0 > > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] net/smc: cap allocation order for SMC-R physically contiguous buffers 2026-04-14 2:10 ` D. Wythe @ 2026-04-14 17:16 ` Simon Horman 0 siblings, 0 replies; 4+ messages in thread From: Simon Horman @ 2026-04-14 17:16 UTC (permalink / raw) To: D. Wythe Cc: David S. Miller, Dust Li, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Sidraya Jayagond, Wenjia Zhang, Mahanta Jambigi, Tony Lu, Wen Gu, linux-kernel, linux-rdma, linux-s390, netdev, oliver.yang, pasic On Tue, Apr 14, 2026 at 10:10:54AM +0800, D. Wythe wrote: > On Fri, Apr 10, 2026 at 04:16:31PM +0100, Simon Horman wrote: > > On Tue, Apr 07, 2026 at 08:43:37PM +0800, D. Wythe wrote: > > > 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. > > > > > > Signed-off-by: D. Wythe <alibuda@linux.alibaba.com> > > > Reviewed-by: Dust Li <dust.li@linux.alibaba.com> > > > --- > > > Changes v1 -> v2: > > > https://lore.kernel.org/netdev/20260312082154.36971-1-alibuda@linux.alibaba.com/ > > > > > > - 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 <horms@kernel.org> > > > > > --- > > > net/smc/smc_core.c | 4 ++++ > > > 1 file changed, 4 insertions(+) > > > > > > diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c > > > index e2d083daeb7e..cdd881746e21 100644 > > > --- a/net/smc/smc_core.c > > > +++ b/net/smc/smc_core.c > > > @@ -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 > > 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. Ack, thanks for checking. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-14 17:17 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-07 12:43 [PATCH net-next v2] net/smc: cap allocation order for SMC-R physically contiguous buffers D. Wythe 2026-04-10 15:16 ` Simon Horman 2026-04-14 2:10 ` D. Wythe 2026-04-14 17:16 ` Simon Horman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox