From: Peter Xu <peterx@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
QEMU Developers <qemu-devel@nongnu.org>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 4/8] usb: fix unbounded stack for xhci_dma_write_u32s
Date: Wed, 9 Mar 2016 13:12:21 +0800 [thread overview]
Message-ID: <20160309051221.GL2377@pxdev.xzpeter.org> (raw)
In-Reply-To: <CAFEAcA_gMgxQWinBJCac+4C5LBQuM6G7jOkEVCrYnnc-taTngw@mail.gmail.com>
On Tue, Mar 08, 2016 at 02:26:36PM +0700, Peter Maydell wrote:
> On 8 March 2016 at 14:00, Peter Xu <peterx@redhat.com> wrote:
> > First of all, this function cannot be inlined even with always_inline,
> > so removing inline.
>
> Please don't mix two different changes in one patch.
Sorry. Will follow this.
>
> > After that, make its stack bounded.
> >
> > Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> > CC: Gerd Hoffmann <kraxel@redhat.com>
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> > hw/usb/hcd-xhci.c | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
> > index 44b6f8c..3dd5a02 100644
> > --- a/hw/usb/hcd-xhci.c
> > +++ b/hw/usb/hcd-xhci.c
> > @@ -694,18 +694,22 @@ static inline void xhci_dma_read_u32s(XHCIState *xhci, dma_addr_t addr,
> > }
> > }
> >
> > -static inline void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr,
> > - uint32_t *buf, size_t len)
> > +static void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr,
> > + uint32_t *buf, size_t len)
> > {
> > int i;
> > - uint32_t tmp[len / sizeof(uint32_t)];
> > + uint32_t n = len / sizeof(uint32_t);
> > +#define __BUF_SIZE (12)
> > + uint32_t tmp[__BUF_SIZE];
> >
> > + assert(__BUF_SIZE >= n);
> > assert((len % sizeof(uint32_t)) == 0);
> >
> > - for (i = 0; i < (len / sizeof(uint32_t)); i++) {
> > + for (i = 0; i < n; i++) {
> > tmp[i] = cpu_to_le32(buf[i]);
> > }
> > pci_dma_write(PCI_DEVICE(xhci), addr, tmp, len);
> > +#undef __BUF_SIZE
>
> All the patches in this series seem to be following the
> same pattern of #defining an arbitrary fixed length for
> the array. This does not at all seem to me to be an
> improvement. We should be avoiding unbounded stack
> allocations, but we need to do this by either changing
> the code to work correctly without an unbounded allocation
> or by using a heap allocation instead of a stack allocation.
>
> In some cases, like this one, the original code isn't even
> unbounded -- we always call this function with a length
> parameter which is a small compile time constant, so the
> stack usage is definitely bounded. So this change is making
> the code uglier and less flexible for no benefit that I
> can see.
I was trying to avoid the "stack unlimited" warning. There will be a
warning generated before applying this patch. The patch solved
this. Though I'd say this patch might not be good enough. :(
Then, will drop this one too if I have no further better
idea.
Thanks for review.
Peter
next prev parent reply other threads:[~2016-03-09 5:12 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-08 7:00 [Qemu-devel] [PATCH 0/8] Fix several unbounded stack usage Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 1/8] qdict: fix unbounded stack for qdict_array_entries Peter Xu
2016-03-08 8:22 ` Markus Armbruster
2016-03-08 10:19 ` Kevin Wolf
2016-03-08 16:21 ` Eric Blake
2016-03-08 16:30 ` Kevin Wolf
2016-03-08 16:50 ` Daniel P. Berrange
2016-03-09 2:57 ` Peter Xu
2016-03-09 3:04 ` Eric Blake
2016-03-09 3:27 ` Peter Xu
2016-03-09 9:48 ` Kevin Wolf
2016-03-09 13:23 ` Markus Armbruster
2016-03-09 13:57 ` Kevin Wolf
2016-03-09 21:03 ` Markus Armbruster
2016-03-10 1:30 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 2/8] block: fix unbounded stack for dump_qdict Peter Xu
2016-03-08 8:12 ` Markus Armbruster
2016-03-08 8:53 ` Fam Zheng
2016-03-08 13:47 ` Markus Armbruster
2016-03-09 3:00 ` Peter Xu
2016-03-08 9:31 ` Peter Xu
2016-03-08 13:50 ` Markus Armbruster
2016-03-08 12:17 ` Paolo Bonzini
2016-03-09 3:18 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 3/8] usb: fix unbounded stack for ohci_td_pkt Peter Xu
2016-03-08 12:20 ` Paolo Bonzini
2016-03-09 4:59 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 4/8] usb: fix unbounded stack for xhci_dma_write_u32s Peter Xu
2016-03-08 7:26 ` Peter Maydell
2016-03-09 5:12 ` Peter Xu [this message]
2016-03-08 12:21 ` Paolo Bonzini
2016-03-09 5:08 ` Peter Xu
2016-03-09 7:53 ` Paolo Bonzini
2016-03-09 8:07 ` Peter Xu
2016-03-09 8:34 ` Markus Armbruster
2016-03-09 9:19 ` Peter Xu
2016-03-09 12:52 ` Markus Armbruster
2016-03-09 12:59 ` Paolo Bonzini
2016-03-10 2:07 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 5/8] usb: fix unbounded stack for inotify_watchfn Peter Xu
2016-03-08 7:20 ` Peter Maydell
2016-03-08 12:22 ` Paolo Bonzini
2016-03-09 5:22 ` Peter Xu
2016-03-08 12:22 ` Paolo Bonzini
2016-03-09 5:23 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 6/8] usb: fix unbounded stack for usb_mtp_add_str Peter Xu
2016-03-08 8:10 ` Gerd Hoffmann
2016-03-09 5:29 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 7/8] migration: fix unbounded stack for source_return_path_thread Peter Xu
2016-03-08 9:48 ` Juan Quintela
2016-03-08 12:27 ` Paolo Bonzini
2016-03-08 12:26 ` Paolo Bonzini
2016-03-09 5:27 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 8/8] hw/i386: fix unbounded stack for load_multiboot Peter Xu
2016-03-08 7:17 ` Peter Maydell
2016-03-08 12:29 ` Paolo Bonzini
2016-03-09 5:39 ` Peter Xu
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=20160309051221.GL2377@pxdev.xzpeter.org \
--to=peterx@redhat.com \
--cc=kraxel@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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).