Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3180497ybk; Mon, 18 May 2020 20:43:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYcxjd8q7/Z+DCYl/Ssa+NMDoAI7fublUyFg5a6j7P2Ts3KrHBvoMpFZAWiLElShJYIh61 X-Received: by 2002:a50:e69d:: with SMTP id z29mr12675045edm.307.1589859798194; Mon, 18 May 2020 20:43:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589859798; cv=none; d=google.com; s=arc-20160816; b=WVjRnCtDO0q3tiSps2DSdXoQPwipU99IQ6Knk42zrFgkWSsa8C5cXD+IyVE43+0em5 j2EoRHck2qr4UewDaY7BcliIWT5T49tLraOM1XO0pnDoUc93/tG8fYIWlab3OCUMLPJS 2GiDcnVxg+/12cCQSKfpesT6JG7gCSWWQcTWNrMFBWFl5rE7la2FL+kqG72ijAqtr1AX BcCYQnjF/DbzUjK4o4YURieZLw2meLE2ryeiLu7SVYM7q2mH++/lkGY2nt8xR/no8nxt 1TxHMq2RHP8NNqM7KN1fLcxUiin502w1PlMy+8Tdfsloyver34mL4nO/ZfmXn+RegNVy Mvvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=AmoSinb004QBItlczFEt+9SkY2V///JRTZUjH4ZHNBQ=; b=Lpl0ypzvR5PeaWfeEEHOInAd73nWsenZY6gKvn7wlcDb5WlGhxWXlHP4hxoFosampP dyDOsWL6AJeytfFnOM/iOjYUxSgKq0gfUnTwT3RNxqoRBfn1RaxRPNSWcYyQmMMDIC0H +AKOBVbcA5e3pAPh/UGjKY7hHucRTsWbpZcbYUGah6f4TC71lYKz526iFxnMfDR95k5Y m++OiponoGSt4sF60RZMJ+xGszFmVzxU6ydyeRiZv+C0nJ/IU5iiIeLtptcM6sfedrYr LrhiXNhds99fpl5JR6VmUeX3GNgDBNQWlkFADWisfcbjys6X0cuB2PcQHlWAp0p1SxYi 1hgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hWKuumJ0; 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 y10si7158809edp.3.2020.05.18.20.42.55; Mon, 18 May 2020 20:43:18 -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=hWKuumJ0; 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 S1728142AbgESDis (ORCPT + 99 others); Mon, 18 May 2020 23:38:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726539AbgESDis (ORCPT ); Mon, 18 May 2020 23:38:48 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12D4AC061A0C for ; Mon, 18 May 2020 20:38:47 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id s10so13042449iog.7 for ; Mon, 18 May 2020 20:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AmoSinb004QBItlczFEt+9SkY2V///JRTZUjH4ZHNBQ=; b=hWKuumJ0qsNkKGUydur5dT61kC1W1kJNIPtC3QojiRprZEplH0oMQWn8HqFe8udhHX hw+AUGbiPb8uNxQWmv1UMjCe/suc/nmMdKJjSURkqN2IBUpDGJKMA6xoKm2+Ht8xykC1 LLbZRI+8gTsSxUfnMR2zEjn4l16gAveE6iS3zX1tC5YReGjOhtrMJA1mi1VmlS6nNzTC LMxbxNLqSkw3LkqSHfK4/qIcNN1uenuF9pLQzLFJU3bMN2xlJFjuO5hxIq/YTvoxc/hk IrsE5y57UXbGLj0ByxGHQc4Na2lnYmXDOzOeZkBOSuKxho11O33B36lKSCzrsqEKY0z8 OCXA== 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; bh=AmoSinb004QBItlczFEt+9SkY2V///JRTZUjH4ZHNBQ=; b=g74glZjc3/mshNnXWLo9Hq650lT0ySzB0LOQZCbgCjFy565LU4skziZOqeBWj2E62M TaJJkAmQGf2rU4+0TlDtZHp2O11hSYY5W/zUn/RjfQ1LoKeAbOobaRniffNewrzVqaEF 0/O6Gn+P+YvwuWjQHzffASH/JFOQ3KgkIbS3+ww3xOee89tONy6Fhfpj5uLpfy2cT9Mp CgjMScbug/r7RVzYdDOKei2KCQBphWU5n6wTFlHRhx6hNsPnwg5oqkBBjh3IC9IjBX7h o8ub98i3CY8CNyHcbe3OsTE56PHvkpXw+95o5tkpR5qNGDrf/lQeGU+EBHXAo2r1An2q 5Kjw== X-Gm-Message-State: AOAM531JWAVw+pb85O/O2iiu5ZMZ/RA1fNMO0hYApm85Wy18MPvdKAaS 2XEZGZE3x7GXNE2OxclYJ9mPA373zFTmv5qctA== X-Received: by 2002:a6b:d909:: with SMTP id r9mr17480387ioc.22.1589859525551; Mon, 18 May 2020 20:38:45 -0700 (PDT) MIME-Version: 1.0 References: <20200517152916.3146539-1-brgerst@gmail.com> <20200517152916.3146539-3-brgerst@gmail.com> In-Reply-To: From: Brian Gerst Date: Mon, 18 May 2020 23:38:34 -0400 Message-ID: Subject: Re: [PATCH 2/7] x86/percpu: Clean up percpu_to_op() To: Nick Desaulniers 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 18, 2020 at 5:15 PM Nick Desaulniers wrote: > > 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 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 > > --- > > arch/x86/include/asm/percpu.h | 90 ++++++++++++++--------------------- > > 1 file changed, 35 insertions(+), 55 deletions(-) > > > > diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h > > index 89f918a3e99b..233c7a78d1a6 100644 > > --- a/arch/x86/include/asm/percpu.h > > +++ b/arch/x86/include/asm/percpu.h > > @@ -117,37 +117,17 @@ extern void __bad_percpu_size(void); > > #define __pcpu_reg_imm_4(x) "ri" (x) > > #define __pcpu_reg_imm_8(x) "re" (x) > > > > -#define percpu_to_op(qual, op, var, val) \ > > -do { \ > > - typedef typeof(var) pto_T__; \ > > - if (0) { \ > > - pto_T__ pto_tmp__; \ > > - pto_tmp__ = (val); \ > > - (void)pto_tmp__; \ > > - } \ > > - switch (sizeof(var)) { \ > > - case 1: \ > > - asm qual (op "b %1,"__percpu_arg(0) \ > > - : "+m" (var) \ > > - : "qi" ((pto_T__)(val))); \ > > - break; \ > > - case 2: \ > > - asm qual (op "w %1,"__percpu_arg(0) \ > > - : "+m" (var) \ > > - : "ri" ((pto_T__)(val))); \ > > - break; \ > > - case 4: \ > > - asm qual (op "l %1,"__percpu_arg(0) \ > > - : "+m" (var) \ > > - : "ri" ((pto_T__)(val))); \ > > - break; \ > > - case 8: \ > > - asm qual (op "q %1,"__percpu_arg(0) \ > > - : "+m" (var) \ > > - : "re" ((pto_T__)(val))); \ > > - break; \ > > - default: __bad_percpu_size(); \ > > - } \ > > +#define percpu_to_op(size, qual, op, _var, _val) \ > > +do { \ > > + __pcpu_type_##size pto_val__ = __pcpu_cast_##size(_val); \ > > + if (0) { \ > > + typeof(_var) pto_tmp__; \ > > + pto_tmp__ = (_val); \ > > + (void)pto_tmp__; \ > > + } \ > > Please replace the whole `if (0)` block with: > ```c > __same_type(_var, _val); > ``` > from include/linux/compiler.h. The problem with __builtin_types_compatible_p() is that it considers unsigned long and u64 (aka unsigned long long) as different types even though they are the same width on x86-64. While this may be a good cleanup to look at in the future, it's not a simple drop-in replacement. -- Brian Gerst