Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1624982ybm; Sat, 30 May 2020 15:14:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzduCCxyD+DVOzjWRNwWv3D/7mlkS83a387EQUyIiBMH05muwJ9HSSA7r4qmguwC3JemtKQ X-Received: by 2002:a50:b961:: with SMTP id m88mr14931624ede.4.1590876859354; Sat, 30 May 2020 15:14:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590876859; cv=none; d=google.com; s=arc-20160816; b=k4Fhe9SLk5Jg6WBNdLf6wAmFF1a/teyTPGGQrp6M9Zzi0jLR1J4gAcR9/xVhXYe4EG +tLa8hlQ5k8Xy2GRTz9sCYXOMNBh8OcofyaUwR1/EnzSlI0zjq3LrP317ORbo6u+HAZQ 1ZrKX1pHwWHFCJPcceVNoyPoXZX65O/O5pi7RzfEWCZEcjodWcYefFHGk0SFqiD46/22 r1xPXIudTuKh8e/R8vBUd29g1aDyesMqOLDMfajmLtRM/Jd+amMp+6GET8EUs5x3s7Dy gxxQmhA8sDfVi24IwVx1pnUAtKzPrZIfE9WGMaLyLHl0FTwV8JJ5ibXZwTft3RU47MOD MTgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d+eiMzeZbmcuIhhC0c40VxnM3edyG90lx+BihnOt8/E=; b=QDv7wq9lH3qXlcuUOTDmyqAPMDdpsYszyGZ2dCq041JvhcgqK89ahMwFMkqp9djh8l 6gXTFTkhWiKJbkZcmtdh1HO1Gkx4ZIf2HASW3Trb4abdd8FPfb8b+/lITl5DfOMy1AM5 dOF05Bkp0eJXGYkXGjx5731QHQm68zs9fWPBjHqp3RfAr+1ohCmA75ib8UACijBngk/g VZzPww78TTauQp7d6fb0AWzHb2A5l7PNAtui4MOH0w6VkXw62w9ald4takGeUSaMiNhZ Un912arJBa+Lcv1aopLOKHf1CxSEoqr0KdLhR0ypPQ7Vh3UIj/HNM5Js/JfAsSR0I7o8 k8ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q8Xk7NaT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r13si7935081edt.263.2020.05.30.15.13.56; Sat, 30 May 2020 15:14:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q8Xk7NaT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729489AbgE3WMD (ORCPT + 99 others); Sat, 30 May 2020 18:12:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729416AbgE3WLu (ORCPT ); Sat, 30 May 2020 18:11:50 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8804EC0A88B4 for ; Sat, 30 May 2020 15:11:48 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id v11so5973849ilh.1 for ; Sat, 30 May 2020 15:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=d+eiMzeZbmcuIhhC0c40VxnM3edyG90lx+BihnOt8/E=; b=q8Xk7NaT5x/vweCOXdg3lZZX10qCE7U1xuPrdj/I0BAGsKyYghPKT4pT6jJr50mMXx 64bpAzlA9ywDxKqjQmglL+ZwkwKAyg5XFMgXTJnFQwKxip2I8j8Kv/guR9lG2nK6Yv09 y0ygSSQpKmNUqR8AiBXHWEeXxhqqn32Eu9aSS7QEP7AyYENXWdp7c3+XJD2/uWtjcvYw R2D2XXTfThvtxfos1Bm/khOTh89DAOsXkb936VEFYDTc6LVOmD7SyQZ/fc6/o4Chkjtg XFyw0q3d1mpVNWjtpaAH930/HZ4heV2CcLofYO0WHBP8YX7182LvyQeYCrViiU9vOH5q 5f0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d+eiMzeZbmcuIhhC0c40VxnM3edyG90lx+BihnOt8/E=; b=W9Qk+jABq0TyPuZLXdwZX2wbPJtP+YKA7ORMEgUm+KMh8O8UrwGkFL3As6SQYt+Cr6 VSIijYeZGLpy+TSPBHZ6LbFaRmNgq5qWuV/s0p1aJci8pD+plgWk+As7I/iz9QbBD6Qy DO7SRWp30VGsOPH+AzIY72FrBJCs9Zzya5MzZ6fKvpZP9YhGboVHCqKp4hOZx9jK7rVL wnayeTYkpdkNM6ci7wWTaCciLYH3dEiYLXGDtwxFsftxQhjZdKu+YN8wYfqWNLSBnuCq 1K6iLn7hV6zboIyE8hZBvVaR7OZ3nvJXgbuXmiZ2Pg4xA0byiy/6vIknr3ag5b2v0yr7 DZog== X-Gm-Message-State: AOAM533SmKJ/76c17hoAIq+PXMlGjFayVTTO4dcxqQxw9gsGoSAOSzuK HCJvYn2PcHvpMx2e8m10ThAxQTS3mA== X-Received: by 2002:a92:b0d:: with SMTP id b13mr14212519ilf.225.1590876707680; Sat, 30 May 2020 15:11:47 -0700 (PDT) Received: from localhost.localdomain (174-084-153-250.res.spectrum.com. [174.84.153.250]) by smtp.gmail.com with ESMTPSA id w78sm2735698ilk.14.2020.05.30.15.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 15:11:47 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Nick Desaulniers , Brian Gerst Subject: [PATCH v2 08/10] x86/percpu: Clean up percpu_cmpxchg_op() Date: Sat, 30 May 2020 18:11:25 -0400 Message-Id: <20200530221127.459704-9-brgerst@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200530221127.459704-1-brgerst@gmail.com> References: <20200530221127.459704-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The core percpu macros already have a switch on the data size, so the switch in the x86 code is redundant and produces more dead code. Also use appropriate types for the width of the instructions. This avoids errors when compiling with Clang. Signed-off-by: Brian Gerst Reviewed-by: Nick Desaulniers --- arch/x86/include/asm/percpu.h | 58 +++++++++++------------------------ 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index ac6d7e76c0d4..7efc0b5c4ff0 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -236,39 +236,17 @@ do { \ * cmpxchg has no such implied lock semantics as a result it is much * more efficient for cpu local operations. */ -#define percpu_cmpxchg_op(qual, var, oval, nval) \ +#define percpu_cmpxchg_op(size, qual, _var, _oval, _nval) \ ({ \ - typeof(var) pco_ret__; \ - typeof(var) pco_old__ = (oval); \ - typeof(var) pco_new__ = (nval); \ - switch (sizeof(var)) { \ - case 1: \ - asm qual ("cmpxchgb %2, "__percpu_arg(1) \ - : "=a" (pco_ret__), "+m" (var) \ - : "q" (pco_new__), "0" (pco_old__) \ - : "memory"); \ - break; \ - case 2: \ - asm qual ("cmpxchgw %2, "__percpu_arg(1) \ - : "=a" (pco_ret__), "+m" (var) \ - : "r" (pco_new__), "0" (pco_old__) \ - : "memory"); \ - break; \ - case 4: \ - asm qual ("cmpxchgl %2, "__percpu_arg(1) \ - : "=a" (pco_ret__), "+m" (var) \ - : "r" (pco_new__), "0" (pco_old__) \ - : "memory"); \ - break; \ - case 8: \ - asm qual ("cmpxchgq %2, "__percpu_arg(1) \ - : "=a" (pco_ret__), "+m" (var) \ - : "r" (pco_new__), "0" (pco_old__) \ - : "memory"); \ - break; \ - default: __bad_percpu_size(); \ - } \ - pco_ret__; \ + __pcpu_type_##size pco_old__ = __pcpu_cast_##size(_oval); \ + __pcpu_type_##size pco_new__ = __pcpu_cast_##size(_nval); \ + asm qual (__pcpu_op2_##size("cmpxchg", "%[nval]", \ + __percpu_arg([var])) \ + : [oval] "+a" (pco_old__), \ + [var] "+m" (_var) \ + : [nval] __pcpu_reg_##size(, pco_new__) \ + : "memory"); \ + (typeof(_var))(unsigned long) pco_old__; \ }) /* @@ -336,16 +314,16 @@ do { \ #define raw_cpu_add_return_1(pcp, val) percpu_add_return_op(1, , pcp, val) #define raw_cpu_add_return_2(pcp, val) percpu_add_return_op(2, , pcp, val) #define raw_cpu_add_return_4(pcp, val) percpu_add_return_op(4, , pcp, val) -#define raw_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, nval) -#define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, nval) -#define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, nval) +#define raw_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(1, , pcp, oval, nval) +#define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, , pcp, oval, nval) +#define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, , pcp, oval, nval) #define this_cpu_add_return_1(pcp, val) percpu_add_return_op(1, volatile, pcp, val) #define this_cpu_add_return_2(pcp, val) percpu_add_return_op(2, volatile, pcp, val) #define this_cpu_add_return_4(pcp, val) percpu_add_return_op(4, volatile, pcp, val) -#define this_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(volatile, pcp, oval, nval) -#define this_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(volatile, pcp, oval, nval) -#define this_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(volatile, pcp, oval, nval) +#define this_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(1, volatile, pcp, oval, nval) +#define this_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, volatile, pcp, oval, nval) +#define this_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, volatile, pcp, oval, nval) #ifdef CONFIG_X86_CMPXCHG64 #define percpu_cmpxchg8b_double(pcp1, pcp2, o1, o2, n1, n2) \ @@ -376,7 +354,7 @@ do { \ #define raw_cpu_or_8(pcp, val) percpu_to_op(8, , "or", (pcp), val) #define raw_cpu_add_return_8(pcp, val) percpu_add_return_op(8, , pcp, val) #define raw_cpu_xchg_8(pcp, nval) raw_percpu_xchg_op(pcp, nval) -#define raw_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(, pcp, oval, nval) +#define raw_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, , pcp, oval, nval) #define this_cpu_read_8(pcp) percpu_from_op(8, volatile, "mov", pcp) #define this_cpu_write_8(pcp, val) percpu_to_op(8, volatile, "mov", (pcp), val) @@ -385,7 +363,7 @@ do { \ #define this_cpu_or_8(pcp, val) percpu_to_op(8, volatile, "or", (pcp), val) #define this_cpu_add_return_8(pcp, val) percpu_add_return_op(8, volatile, pcp, val) #define this_cpu_xchg_8(pcp, nval) percpu_xchg_op(8, volatile, pcp, nval) -#define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(volatile, pcp, oval, nval) +#define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, volatile, pcp, oval, nval) /* * Pretty complex macro to generate cmpxchg16 instruction. The instruction -- 2.25.4