Received: by 2002:a17:90a:bc8d:0:0:0:0 with SMTP id x13csp1527194pjr; Mon, 18 May 2020 15:31:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz0Iu9ruAJpv9UvhXYBZU6uXCt9nzNuA6GW5L/Wh13XnYZepCNmIQZVXrwBcNXvQaKQXAC X-Received: by 2002:a05:6402:3185:: with SMTP id di5mr15493531edb.330.1589841090934; Mon, 18 May 2020 15:31:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589841090; cv=none; d=google.com; s=arc-20160816; b=o0YnfuQtoPYCdI4x1nncH6nWHEETws4xbtYxqBPDUHDt4tr09Ts01qnYiHmBhK+xU1 rcHlE3HARuZz13IWLW2oGJfx9SHuy27K86X1+I+jpUOTj/mjP1qiXbFwxWJNaH406dHT Id2IIqhYXITAAKnewJaXojjBR3+KyNx06gTNUNp7c4jFKVYLLjx6q/JfY4RkFpbjMFli YR7HNYI/afLrzyCrKRm4XkQvLB8fqOEEkYFIPsm+DYymtTurTYhBxy/ciWiQm9mFLw/R 7GYkl88fJ97e3s9oFzAFPXEqkKbPi5SR+hwXXt7SfcS1o/EE9GPzNT/pLinJZdMN0w8L 7f9g== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=J9orov8nDrybWoUV5nL1VoYUgfhGVvl5noZ7L+X0xw4=; b=LiAfPgc44hfWc0gMlfJG0gpZoExpqXchcd61YsB6IQjvwoBCDm7m/ithO23B1tDJ8W V9g3rzeBxLQ4pZBBF5HU5Ba5RSRdmOwYB7WzL5LBmdNdrqXJdDWE/CxnSkNDmZwzg2Ls zg3pMK3XMsNQHhGCqDtu4dAqYK5lpxm0kFd3Sh3EjBP1mK3aum9BrjnFnPqX9wgKnaYY eUT78sK75msEPX2nAMDGA5KrMb9GwuWfAdTsXZrIafkmcJI7SjiQWSWbnGaUOw+E8YGy 1xTt6ef1uL+rc+ptzEGnM+WFkKu4Nk4OBpoviI9LOx5gFVVFcOcGX4jGMtwWmXXeKumw q4Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sPSdew+B; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 4si7861502edh.424.2020.05.18.15.31.08; Mon, 18 May 2020 15:31:30 -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=@google.com header.s=20161025 header.b=sPSdew+B; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728511AbgERW3F (ORCPT + 99 others); Mon, 18 May 2020 18:29:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727900AbgERW3E (ORCPT ); Mon, 18 May 2020 18:29:04 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE5C4C061A0C for ; Mon, 18 May 2020 15:29:04 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id ci23so478516pjb.5 for ; Mon, 18 May 2020 15:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=J9orov8nDrybWoUV5nL1VoYUgfhGVvl5noZ7L+X0xw4=; b=sPSdew+BSi8gsLPO+OmURXsRdlHwNF2qdMQLxF8q6OJF+NgOc2TNfz6cpVqYavpLgA 8kmJnLPSs0tUAWhqUPzRX/+AxgCeu/tMF0bwwiQKjEIxaAfJMP5o5kTbKGlg8wTTuax6 4DIAxTc7GMG31XBgcBgfRcsAZ289e38fAwcIb4smB3SRzk+yTfAJoj3qfRMUHMv3OBnE M059OraCsjn9OlL0s6pzOpxQZ/TwE945RgBXUMb4juU3vzbfrfIw4YWTPTZiXgE2p8l6 2PIZmnfDPoXMTbp8IszB3u582laVkYgUDxDVN7hblhrHGGRzkt0Wg6minPST6b/Qd+oK 5aWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=J9orov8nDrybWoUV5nL1VoYUgfhGVvl5noZ7L+X0xw4=; b=DYrOn9VEEsa7x7T77eEF9aibAzVfTylVah8lzy2u0iPfekx8F03imuZvANlMK1FNvi a0A8URD5/jnNQDulHfNFmexf9Xol2gDsTjdyGj3z6M/AnVKtpMKI+du+awfjU/G1wgNC DYQAW4ZiGMcry0j4SSNmYgxUT3ZxnGgyQ0l/5n1vOro1w9231poReEZyKg21vAkWILVV n80Fl3HIStDwddqYdKIFXszW3wNHuI/KJD/IIEDU1OtWqSZW+agIW62N4J4bE2zzPlVs SAmi9m7uomH8D40DYqPzA9TdpSolor5+5z+ZN7dWH0YDPlF0WPdaSUoQgN2tvjSzHY/C yGoA== X-Gm-Message-State: AOAM533wpavTnFew+4c2lqyqIpd1ZJvJMps5sifclw94Xxx72VrJBCGy ujxy14eCx17w/TuFPsu+HcEI82sjsvRk+Q+L0xZpdg== X-Received: by 2002:a17:90b:4c47:: with SMTP id np7mr1722287pjb.101.1589840943985; Mon, 18 May 2020 15:29:03 -0700 (PDT) MIME-Version: 1.0 References: <20200517152916.3146539-1-brgerst@gmail.com> <20200517152916.3146539-8-brgerst@gmail.com> In-Reply-To: <20200517152916.3146539-8-brgerst@gmail.com> From: Nick Desaulniers Date: Mon, 18 May 2020 15:28:50 -0700 Message-ID: Subject: Re: [PATCH 7/7] x86/percpu: Clean up percpu_cmpxchg_op() To: Brian Gerst Cc: LKML , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 17, 2020 at 8:29 AM Brian Gerst wrote: > > The core percpu macros already have a switch on the data size, so the swi= tch > in the x86 code is redundant and produces more dead code. > > Also use appropriate types for the width of the instructions. This avoid= s > errors when compiling with Clang. > > Signed-off-by: Brian Gerst > --- > 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 3c95ab3c99cd..b61d4fc5568e 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__ =3D (oval); = \ > - typeof(var) pco_new__ =3D (nval); = \ > - switch (sizeof(var)) { \ > - case 1: \ > - asm qual ("cmpxchgb %2, "__percpu_arg(1) \ > - : "=3Da" (pco_ret__), "+m" (var) = \ > - : "q" (pco_new__), "0" (pco_old__) \ > - : "memory"); \ > - break; \ > - case 2: \ > - asm qual ("cmpxchgw %2, "__percpu_arg(1) \ > - : "=3Da" (pco_ret__), "+m" (var) = \ > - : "r" (pco_new__), "0" (pco_old__) \ > - : "memory"); \ > - break; \ > - case 4: \ > - asm qual ("cmpxchgl %2, "__percpu_arg(1) \ > - : "=3Da" (pco_ret__), "+m" (var) = \ > - : "r" (pco_new__), "0" (pco_old__) \ > - : "memory"); \ > - break; \ > - case 8: \ > - asm qual ("cmpxchgq %2, "__percpu_arg(1) \ > - : "=3Da" (pco_ret__), "+m" (var) = \ > - : "r" (pco_new__), "0" (pco_old__) \ > - : "memory"); \ > - break; \ > - default: __bad_percpu_size(); \ > - } \ > - pco_ret__; \ > + __pcpu_type_##size pco_old__ =3D __pcpu_cast_##size(_oval); = \ > + __pcpu_type_##size pco_new__ =3D __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__) \ Looks like we're no longer using "=3Da" and "0" constraints. Looking these up for reference for other reviewers: "0" [0]: Input constraints can also be digits (for example, "0"). This indicates that the specified input must be in the same place as the output constraint at the (zero-based) index in the output constraint list. When using asmSymbolicName syntax for the output operands, you may use these names (enclosed in brackets =E2=80=98[]=E2=80=99) instead of = digits. [0] https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Extended-Asm "+" [1]: Means that this operand is both read and written by the instruction. [1] https://gcc.gnu.org/onlinedocs/gcc/Modifiers.html#Modifiers "=3D" [1]: Means that this operand is written to by this instruction: the previous value is discarded and replaced by new data. So this looks like a nice simplification. Reviewed-by: Nick Desaulniers > + : "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, , pc= p, oval, nval) > +#define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, , pc= p, oval, nval) > +#define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, , pc= p, 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(volatil= e, pcp, oval, nval) > -#define this_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(volatil= e, pcp, oval, nval) > -#define this_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(volatil= e, pcp, oval, nval) > +#define this_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(1, vola= tile, pcp, oval, nval) > +#define this_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, vola= tile, pcp, oval, nval) > +#define this_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, vola= tile, 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, n= val) > -#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, , pc= p, oval, nval) > > #define this_cpu_read_8(pcp) percpu_from_op(8, volatil= e, "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, v= olatile, "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, volatil= e, pcp, nval) > -#define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(volatil= e, pcp, oval, nval) > +#define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, vola= tile, pcp, oval, nval) > > /* > * Pretty complex macro to generate cmpxchg16 instruction. The instruct= ion > -- > 2.25.4 > --=20 Thanks, ~Nick Desaulniers