From: Ulf Hansson <ulf.hansson@linaro.org>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Jernej Skrabec <jernej.skrabec@gmail.com>,
pizza@shaftnet.org, Kalle Valo <kvalo@codeaurora.org>,
David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
linux-wireless <linux-wireless@vger.kernel.org>,
Networking <netdev@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH] cw1200: use kmalloc() allocation instead of stack
Date: Wed, 30 Jun 2021 11:55:45 +0200 [thread overview]
Message-ID: <CAPDyKFqFTCzXFMar88CYdZKc=eMjKszsOCS1LwLmnF0uNQyPAw@mail.gmail.com> (raw)
In-Reply-To: <CAK8P3a1mvRTTFHtxqREmcbgJS+e94BHajCtAU_fzBhNNKjJBcg@mail.gmail.com>
On Tue, 22 Jun 2021 at 22:33, Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Tue, Jun 22, 2021 at 10:24 PM Jernej Skrabec
> <jernej.skrabec@gmail.com> wrote:
> >
> > It turns out that if CONFIG_VMAP_STACK is enabled and src or dst is
> > memory allocated on stack, SDIO operations fail due to invalid memory
> > address conversion:
>
> Thank you for sending this!
>
> It's worth pointing out that even without CONFIG_VMAP_STACK, using
> dma_map_sg() on a stack variable is broken, though it will appear to
> work most of the time but rarely cause a stack data corruption when
> the cache management goes wrong.
>
> This clearly needs to be fixed somewhere, if not with your patch, then
> a similar one.
>
> > diff --git a/drivers/net/wireless/st/cw1200/hwio.c b/drivers/net/wireless/st/cw1200/hwio.c
> > index 3ba462de8e91..5521cb7f2233 100644
> > --- a/drivers/net/wireless/st/cw1200/hwio.c
> > +++ b/drivers/net/wireless/st/cw1200/hwio.c
> > @@ -66,33 +66,65 @@ static int __cw1200_reg_write(struct cw1200_common *priv, u16 addr,
> > static inline int __cw1200_reg_read_32(struct cw1200_common *priv,
> > u16 addr, u32 *val)
> > {
> > - __le32 tmp;
> > - int i = __cw1200_reg_read(priv, addr, &tmp, sizeof(tmp), 0);
> > - *val = le32_to_cpu(tmp);
> > + __le32 *tmp;
> > + int i;
> > +
> > + tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
> > + if (!tmp)
> > + return -ENOMEM;
> > +
> > + i = __cw1200_reg_read(priv, addr, tmp, sizeof(*tmp), 0);
> > + *val = le32_to_cpu(*tmp);
> > + kfree(tmp);
> > return i;
> > }
>
> There is a possible problem here when the function gets called from
> atomic context, so it might need to use GFP_ATOMIC instead of
> GFP_KERNEL. If it's never called from atomic context, then this patch
> looks correct to me.
I would be surprised if this is called from atomic context (when IRQs
are turned off), because in most cases, to complete the read/write
request the mmc controller driver relies on IRQs being delivered.
>
> The alternative would be to add a bounce buffer check based on
> is_vmalloc_or_module_addr() in sdio_io_rw_ext_helper(), which would
> add a small bit of complexity there but solve the problem for
> all drivers at once. In this case, it would probably have to use
> GFP_ATOMIC regardless of whether __cw1200_reg_read_32()
> is allowed to sleep, since other callers might not.
I like the idea, but...
I don't think we should see this as an alternative, but rather as a
complement which would have performance issues. A warning should be
printed, if the buffer isn't properly allocated.
Additionally, I don't think GFT_ATOMIC should be needed.
Kind regards
Uffe
next prev parent reply other threads:[~2021-06-30 9:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-22 20:23 [RFC PATCH] cw1200: use kmalloc() allocation instead of stack Jernej Skrabec
2021-06-22 20:30 ` Arnd Bergmann
2021-06-30 9:55 ` Ulf Hansson [this message]
2021-06-30 11:30 ` Arnd Bergmann
2021-06-30 12:03 ` Ulf Hansson
2021-06-30 12:21 ` Arnd Bergmann
2021-06-30 10:03 ` Ulf Hansson
2021-06-30 10:09 ` Jernej Škrabec
2021-06-30 12:00 ` Ulf Hansson
2021-06-30 16:08 ` David Laight
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='CAPDyKFqFTCzXFMar88CYdZKc=eMjKszsOCS1LwLmnF0uNQyPAw@mail.gmail.com' \
--to=ulf.hansson@linaro.org \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=jernej.skrabec@gmail.com \
--cc=kuba@kernel.org \
--cc=kvalo@codeaurora.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pizza@shaftnet.org \
/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;
as well as URLs for NNTP newsgroup(s).