From patchwork Thu Mar 16 13:05:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9628109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B6378604AA for ; Thu, 16 Mar 2017 13:08:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADBAB28236 for ; Thu, 16 Mar 2017 13:08:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EBC928644; Thu, 16 Mar 2017 13:08:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 87BCF28236 for ; Thu, 16 Mar 2017 13:08:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coV62-0003U2-Jh; Thu, 16 Mar 2017 13:05:38 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coV60-0003Tw-Py for xen-devel@lists.xenproject.org; Thu, 16 Mar 2017 13:05:36 +0000 Received: from [85.158.139.211] by server-15.bemta-5.messagelabs.com id 57/BC-01896-0AD8AC85; Thu, 16 Mar 2017 13:05:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHIsWRWlGSWpSXmKPExsXS6fjDS3d+76k Ig7fNYhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bje//YCi5IVFxYtZexgfG4UBcjB4eQQJ7E 16aQLkZODl4BO4mLWw6yg9gSAoYST99fZwOxWQRUJX7vbAez2QTUJdqebWcFaRURMJA4dzQJx GQW0JfYto4FpEJYwFiice8EZhBbCGji1LOLwKp5BQQl/u4QBgkzA4UndN5mnMDIPQshMwtJBs LWknj46xYLhK0tsWzha+ZZYLukJZb/44AIW0tsOP+bHVUJiO0msWD5GpYFjByrGNWLU4vKUot 0zfWSijLTM0pyEzNzdA0NTPVyU4uLE9NTcxKTivWS83M3MQLDkQEIdjAem+x8iFGSg0lJlLf8 x4kIIb6k/JTKjMTijPii0pzU4kOMMhwcShK8MoYnI4QEi1LTUyvSMnOAkQGTluDgURLh5TEAS vMWFyTmFmemQ6ROMSpKifPeAUkIgCQySvPg2mDReIlRVkqYlxHoECGegtSi3MwSVPlXjOIcjE rCvGdBpvBk5pXATX8FtJgJaPHbDydAFpckIqSkGhgVV/QL8cQxbCrQrF5UFyfHEikvuzw3XCy hIFI/Sjhx27QtUU/Xi6971f13Z/xsXY72qzP3381xXbFtgqa0+gL3zddslea/9kz4K8R1f1F7 zv23q/MfCO71EJNpe+Xp0DvZ4d3tb/kTVyabfAo/omR2Wf1PJh/DqU8+VloyjMcEbLSefTaJf 6PEUpyRaKjFXFScCAAcU02mwQIAAA== X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1489669533!86932371!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 39654 invoked from network); 16 Mar 2017 13:05:34 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-7.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 16 Mar 2017 13:05:34 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Thu, 16 Mar 2017 07:05:32 -0600 Message-Id: <58CA9BAB0200007800143CE4@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.1 Date: Thu, 16 Mar 2017 07:05:31 -0600 From: "Jan Beulich" To: "xen-devel" References: <58CA9BAB0200007800143CE4@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH] x86emul: correct DECLARE_ALIGNED() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Stop creating an excessively large array on the stack, by properly taking into account the array element size when establishing its element count (and of course also when calculating the pointer to be actually used to access the memory). Signed-off-by: Jan Beulich x86emul: correct DECLARE_ALIGNED() Stop creating an excessively large array on the stack, by properly taking into account the array element size when establishing its element count (and of course also when calculating the pointer to be actually used to access the memory). Signed-off-by: Jan Beulich --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -553,10 +553,10 @@ typedef union { * the compiler for automatic variables. Use this helper to instantiate a * suitably aligned variable, producing a pointer to access it. */ -#define DECLARE_ALIGNED(type, var) \ - long __##var[sizeof(type) + __alignof(type) - __alignof(long)]; \ - type *const var##p = \ - (void *)((long)(__##var + __alignof(type) - __alignof(long)) \ +#define DECLARE_ALIGNED(type, var) \ + long __##var[(sizeof(type) + __alignof(type)) / __alignof(long) - 1]; \ + type *const var##p = \ + (void *)(((long)__##var + __alignof(type) - __alignof(__##var)) \ & -__alignof(type)) #ifdef __GCC_ASM_FLAG_OUTPUTS__ Reviewed-by: Andrew Cooper --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -553,10 +553,10 @@ typedef union { * the compiler for automatic variables. Use this helper to instantiate a * suitably aligned variable, producing a pointer to access it. */ -#define DECLARE_ALIGNED(type, var) \ - long __##var[sizeof(type) + __alignof(type) - __alignof(long)]; \ - type *const var##p = \ - (void *)((long)(__##var + __alignof(type) - __alignof(long)) \ +#define DECLARE_ALIGNED(type, var) \ + long __##var[(sizeof(type) + __alignof(type)) / __alignof(long) - 1]; \ + type *const var##p = \ + (void *)(((long)__##var + __alignof(type) - __alignof(__##var)) \ & -__alignof(type)) #ifdef __GCC_ASM_FLAG_OUTPUTS__