From patchwork Mon Apr 10 13:34:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9672745 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 9D53D60244 for ; Mon, 10 Apr 2017 14:15:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94E2728450 for ; Mon, 10 Apr 2017 14:15:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88CA92846C; Mon, 10 Apr 2017 14:15:13 +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 0FFEA28450 for ; Mon, 10 Apr 2017 14:15:13 +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 1cxa48-0004yC-Pi; Mon, 10 Apr 2017 14:13:12 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxa47-0004xz-N8 for xen-devel@lists.xenproject.org; Mon, 10 Apr 2017 14:13:11 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id C6/87-03642-7F29BE85; Mon, 10 Apr 2017 14:13:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNIsWRWlGSWpSXmKPExsXitHRDpO63Sa8 jDL4161p83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBk/zv1lKvgoUdF0r5m1gfGkYBcjJ4eEgL9E a8MxdhCbTUBH4uLcnWxdjBwcIgIqErf3GoCYzALlEjNuxINUCAtYS5ydtokJxGYRUJXYufEbI 4jNK2ApsfvBBCaIiXoSbye+AItzClhJnLnUAxYXAqq5vwliE6+AoMTJmU9YQGxmAU2J1u2/2S FseYnmrbOZIeoVJfrnPWCbwMg3C0nLLCQts5C0LGBkXsWoUZxaVJZapGtoqpdUlJmeUZKbmJm ja2hgppebWlycmJ6ak5hUrJecn7uJERhoDECwg/HbsoBDjJIcTEqivOmWryOE+JLyUyozEosz 4otKc1KLDzHKcHAoSfBKTwTKCRalpqdWpGXmAEMeJi3BwaMkwqsDkuYtLkjMLc5Mh0idYlSUE uedCJIQAElklObBtcHi7BKjrJQwLyPQIUI8BalFuZklqPKvGMU5GJWEeU+BTOHJzCuBm/4KaD ET0OIzu16CLC5JREhJNTDaBr2TEjuxcY7KOh8T9W3y/y/IXVW5dtNGh2WHyILm5U9zHsQ9WcS 9kl1cLeOnDCdXwxMZXxN7xdDGtafMUr5Z757r+Faq9OyDGV8cD/F+5qtMDzQ62HzbWMS6I+Fg kMf8x+Gu35fkLNj0MzqZ69v7mY5RSTd1TVySPtV78jbpvVmvM//qmUYlluKMREMt5qLiRAAob zrArgIAAA== X-Env-Sender: prvs=266d97a94=roger.pau@citrix.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1491833588!96784356!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 11198 invoked from network); 10 Apr 2017 14:13:10 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 10 Apr 2017 14:13:10 -0000 X-IronPort-AV: E=Sophos;i="5.37,182,1488844800"; d="scan'208";a="418329935" From: Roger Pau Monne To: Date: Mon, 10 Apr 2017 14:34:34 +0100 Message-ID: <20170410133435.51728-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.11.0 (Apple Git-81) In-Reply-To: <20170410133435.51728-1-roger.pau@citrix.com> References: <20170410133435.51728-1-roger.pau@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Jan Beulich , Roger Pau Monne Subject: [Xen-devel] [PATCH for-4.9 v3 2/3] x86/atomic: fix clang build 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 The current code in dm_op breaks clang build with: dm.c:411:21: error: 'break' is bound to loop, GCC binds it to switch [-Werror,-Wgcc-compat] while ( read_atomic(&p2m->ioreq.entry_count) && ^ xen/include/asm/atomic.h:53:43: note: expanded from macro 'read_atomic' default: x_ = 0; __bad_atomic_size(); break; \ ^ Introduce a readatomic static inline helper function in order to solve this. Signed-off-by: Roger Pau Monné --- Cc: Jan Beulich Cc: Andrew Cooper --- Changes since v2: - Introduce a readatomic static inline helper in order to prevent moving the read_atomic check. Changes since v1: - New in this version. --- xen/include/asm-x86/atomic.h | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h index 2fbe705518..ae87a0dcf5 100644 --- a/xen/include/asm-x86/atomic.h +++ b/xen/include/asm-x86/atomic.h @@ -41,20 +41,42 @@ build_add_sized(add_u64_sized, "q", uint64_t, "ri") #undef build_write_atomic #undef build_add_sized -void __bad_atomic_size(void); +/* + * NB: read_atomic needs to be a static inline function because clang doesn't + * like breaks inside of expressions, even when there's an inner switch where + * those breaks should apply, and complains with "'break' is bound to loop, GCC + * binds it to switch", so the following code: + * + * while ( read_atomic(&foo) ) { ... } + * + * Doesn't work if read_atomic is a macro with an inner switch. + */ +static inline unsigned long readatomic(const void *p, size_t s) +{ + switch ( s ) + { + case 1: + return read_u8_atomic((uint8_t *)p); + case 2: + return read_u16_atomic((uint16_t *)p); + case 4: + return read_u32_atomic((uint32_t *)p); + case 8: + return read_u64_atomic((uint64_t *)p); + default: + ASSERT_UNREACHABLE(); + return 0; + } +} -#define read_atomic(p) ({ \ - unsigned long x_; \ - switch ( sizeof(*(p)) ) { \ - case 1: x_ = read_u8_atomic((uint8_t *)(p)); break; \ - case 2: x_ = read_u16_atomic((uint16_t *)(p)); break; \ - case 4: x_ = read_u32_atomic((uint32_t *)(p)); break; \ - case 8: x_ = read_u64_atomic((uint64_t *)(p)); break; \ - default: x_ = 0; __bad_atomic_size(); break; \ - } \ - (typeof(*(p)))x_; \ +#define read_atomic(p) ({ \ + BUILD_BUG_ON(sizeof(*(p)) != 1 && sizeof(*(p)) != 2 && \ + sizeof(*(p)) != 4 && sizeof(*(p)) != 8); \ + (typeof(*(p)))readatomic(p, sizeof(*(p))); \ }) +void __bad_atomic_size(void); + #define write_atomic(p, x) ({ \ typeof(*(p)) __x = (x); \ unsigned long x_ = (unsigned long)__x; \