From patchwork Wed Mar 9 05:08:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 8542081 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8E9A3C0553 for ; Wed, 9 Mar 2016 05:09:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ABCEC20220 for ; Wed, 9 Mar 2016 05:09:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 922F4200DF for ; Wed, 9 Mar 2016 05:09:45 +0000 (UTC) Received: from localhost ([::1]:39101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adWNU-0003Lc-IS for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 Mar 2016 00:09:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adWML-0001sK-Jy for qemu-devel@nongnu.org; Wed, 09 Mar 2016 00:08:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adWMI-0007tz-A3 for qemu-devel@nongnu.org; Wed, 09 Mar 2016 00:08:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42180) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adWMI-0007tv-4N for qemu-devel@nongnu.org; Wed, 09 Mar 2016 00:08:30 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id A35E93D1E9 for ; Wed, 9 Mar 2016 05:08:29 +0000 (UTC) Received: from pxdev.xzpeter.org (dhcp-14-238.nay.redhat.com [10.66.14.238]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2958JhR009994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 9 Mar 2016 00:08:25 -0500 Date: Wed, 9 Mar 2016 13:08:12 +0800 From: Peter Xu To: Paolo Bonzini Message-ID: <20160309050812.GK2377@pxdev.xzpeter.org> References: <1457420446-25276-1-git-send-email-peterx@redhat.com> <1457420446-25276-5-git-send-email-peterx@redhat.com> <56DEC3E0.1010404@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <56DEC3E0.1010404@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, Gerd Hoffmann Subject: Re: [Qemu-devel] [PATCH 4/8] usb: fix unbounded stack for xhci_dma_write_u32s X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Mar 08, 2016 at 01:21:52PM +0100, Paolo Bonzini wrote: > > > On 08/03/2016 08:00, Peter Xu wrote: > > First of all, this function cannot be inlined even with always_inline, > > so removing inline. > > Why? always_inline fixes the error for me. I tried this patch: ----------------- ----------------- What I got is: /root/git/qemu/hw/usb/hcd-xhci.c:699:1: warning: ‘artificial’ attribute ignored [-Wattributes] { ^ /root/git/qemu/hw/usb/hcd-xhci.c:697:56: warning: always_inline function might not be inlinable [-Wattributes] static QEMU_ARTIFICIAL void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr, ^ GCC version: pxdev:bin# gcc -v Using built-in specs. COLLECT_GCC=/bin/gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) Do you know why "might not be inlinable"? Failed to figure it out myself as mentioned in cover letter.. > > > 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); > > Instead of a #define, you can use ARRAY_SIZE(tmp). Will do when needed. Thanks! Peter diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 44b6f8c..961fd78 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -694,7 +694,7 @@ 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, +static QEMU_ARTIFICIAL void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr, uint32_t *buf, size_t len) { int i;