From: Zhu Yanjun <yanjun.zhu@linux.dev>
To: Arnd Bergmann <arnd@kernel.org>,
Bernard Metzler <bmt@zurich.ibm.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
Nathan Chancellor <nathan@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Potnuri Bharat Teja <bharat@chelsio.com>,
Showrya M N <showrya@chelsio.com>,
Eric Biggers <ebiggers@google.com>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH] RDMA/siw: work around clang stack size warning
Date: Fri, 20 Jun 2025 21:12:40 -0700 [thread overview]
Message-ID: <2d04fee6-5d95-4c50-b2b1-ee67f42932e2@linux.dev> (raw)
In-Reply-To: <20250620114332.4072051-1-arnd@kernel.org>
在 2025/6/20 4:43, Arnd Bergmann 写道:
> From: Arnd Bergmann <arnd@arndb.de>
>
> clang inlines a lot of functions into siw_qp_sq_process(), with the
> aggregate stack frame blowing the warning limit in some configurations:
>
> drivers/infiniband/sw/siw/siw_qp_tx.c:1014:5: error: stack frame size (1544) exceeds limit (1280) in 'siw_qp_sq_process' [-Werror,-Wframe-larger-than]
>
> The real problem here is the array of kvec structures in siw_tx_hdt that
> makes up the majority of the consumed stack space.
Because the array of kvec structures in siw_tx_hdt consumes the majority
of the stack space, would it be possible to use kmalloc or a similar
dynamic memory allocation function instead of allocating this memory on
the stack?
Would using kmalloc (or an equivalent) also effectively resolve the
stack usage issue?
Please note that I’m not questioning the value of this commit—I’m simply
curious whether there might be an alternative solution to the problem.
Thanks,
Yanjun.Zhu
>
> Ideally there would be a way to avoid allocating the array on the
> stack, but that would require a larger rework. Add a noinline_for_stack
> annotation to avoid the warning for now, and make clang behave the same
> way as gcc here. The combined stack usage is still similar, but is spread
> over multiple functions now.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/infiniband/sw/siw/siw_qp_tx.c | 22 ++++++++++++++++------
> 1 file changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/infiniband/sw/siw/siw_qp_tx.c b/drivers/infiniband/sw/siw/siw_qp_tx.c
> index 6432bce7d083..3a08f57d2211 100644
> --- a/drivers/infiniband/sw/siw/siw_qp_tx.c
> +++ b/drivers/infiniband/sw/siw/siw_qp_tx.c
> @@ -277,6 +277,15 @@ static int siw_qp_prepare_tx(struct siw_iwarp_tx *c_tx)
> return PKT_FRAGMENTED;
> }
>
> +static noinline_for_stack int
> +siw_sendmsg(struct socket *sock, unsigned int msg_flags,
> + struct kvec *vec, size_t num, size_t len)
> +{
> + struct msghdr msg = { .msg_flags = msg_flags };
> +
> + return kernel_sendmsg(sock, &msg, vec, num, len);
> +}
> +
> /*
> * Send out one complete control type FPDU, or header of FPDU carrying
> * data. Used for fixed sized packets like Read.Requests or zero length
> @@ -285,12 +294,11 @@ static int siw_qp_prepare_tx(struct siw_iwarp_tx *c_tx)
> static int siw_tx_ctrl(struct siw_iwarp_tx *c_tx, struct socket *s,
> int flags)
> {
> - struct msghdr msg = { .msg_flags = flags };
> struct kvec iov = { .iov_base =
> (char *)&c_tx->pkt.ctrl + c_tx->ctrl_sent,
> .iov_len = c_tx->ctrl_len - c_tx->ctrl_sent };
>
> - int rv = kernel_sendmsg(s, &msg, &iov, 1, iov.iov_len);
> + int rv = siw_sendmsg(s, flags, &iov, 1, iov.iov_len);
>
> if (rv >= 0) {
> c_tx->ctrl_sent += rv;
> @@ -427,13 +435,13 @@ static void siw_unmap_pages(struct kvec *iov, unsigned long kmap_mask, int len)
> * Write out iov referencing hdr, data and trailer of current FPDU.
> * Update transmit state dependent on write return status
> */
> -static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s)
> +static noinline_for_stack int siw_tx_hdt(struct siw_iwarp_tx *c_tx,
> + struct socket *s)
> {
> struct siw_wqe *wqe = &c_tx->wqe_active;
> struct siw_sge *sge = &wqe->sqe.sge[c_tx->sge_idx];
> struct kvec iov[MAX_ARRAY];
> struct page *page_array[MAX_ARRAY];
> - struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_EOR };
>
> int seg = 0, do_crc = c_tx->do_crc, is_kva = 0, rv;
> unsigned int data_len = c_tx->bytes_unsent, hdr_len = 0, trl_len = 0,
> @@ -586,14 +594,16 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s)
> rv = siw_0copy_tx(s, page_array, &wqe->sqe.sge[c_tx->sge_idx],
> c_tx->sge_off, data_len);
> if (rv == data_len) {
> - rv = kernel_sendmsg(s, &msg, &iov[seg], 1, trl_len);
> +
> + rv = siw_sendmsg(s, MSG_DONTWAIT | MSG_EOR, &iov[seg],
> + 1, trl_len);
> if (rv > 0)
> rv += data_len;
> else
> rv = data_len;
> }
> } else {
> - rv = kernel_sendmsg(s, &msg, iov, seg + 1,
> + rv = siw_sendmsg(s, MSG_DONTWAIT | MSG_EOR, iov, seg + 1,
> hdr_len + data_len + trl_len);
> siw_unmap_pages(iov, kmap_mask, seg);
> }
next prev parent reply other threads:[~2025-06-21 4:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-20 11:43 [PATCH] RDMA/siw: work around clang stack size warning Arnd Bergmann
2025-06-21 4:12 ` Zhu Yanjun [this message]
2025-06-21 8:43 ` Arnd Bergmann
2025-06-21 16:09 ` Zhu Yanjun
2025-06-22 13:29 ` Bernard Metzler
2025-06-24 10:47 ` Bernard Metzler
2025-06-25 11:14 ` Leon Romanovsky
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=2d04fee6-5d95-4c50-b2b1-ee67f42932e2@linux.dev \
--to=yanjun.zhu@linux.dev \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=bharat@chelsio.com \
--cc=bmt@zurich.ibm.com \
--cc=ebiggers@google.com \
--cc=jgg@ziepe.ca \
--cc=justinstitt@google.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=showrya@chelsio.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