Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp729432ybk; Wed, 20 May 2020 10:28:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydyebEOsGY9jDUyWq6UcAMo+X1g0nbrDoYKoaw5Ip1zzoBfVCv1+Z864kIUz4hFGhFXchy X-Received: by 2002:a17:906:82d9:: with SMTP id a25mr119866ejy.43.1589995688626; Wed, 20 May 2020 10:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589995688; cv=none; d=google.com; s=arc-20160816; b=eji5JM4Eq37Ld+u90ARp+nO4AmYIlRfDKFgUcYY7eKC3YzFDzhfHbVUt+vCZkqVXKP 51ak/2mhp5iQr4wWTRGVLobCHgo+p6F8EmGYClO6vIab2J7qbymXyBbFrVSqahcGQLCX BicN1SyGVokyzzStDrx3e0PHqzUseOyeXx7s7rbVmDLj8vA3ZC4AcjeLMFgqhH90omVX j92yT3L6cndutG6tFrbjHxUG/boXkMFljy/xaMKK/pwowfXW4f6uDaZijXqJzpMvYnA2 oXN6zlsHfGa0+qnjS0yVAQ8Ms/f5GECfhMPTOgcCb9HJW2F+oDDtmDHgk9Sc8/MSIcQc 5Yhg== 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=I4uDtSN00g/PyrhXYZzL0F8/NB4Tyo630ZwvvT8OLZg=; b=ENtTb2yokK0q1cmKDe7ij9eiV++DQN6kYQv0wWl/jjpZZ+vTsmUROHw9uwEmj1rI9Z 9qcz8gdg6fe0Ym9QbA8Z9Ddmbaf4aYZDy2L0zTd6iUNz/IFKsbfE8PQQ3NS13fXhCOCE gOKHJekZ6pOqvaJ2N5AJXtIr+o1baCw9BkH0km6JdNtHeQohKuH1yeV/O4ga04JsfoZP f9H84ZVOdFdKajJ83iSMpVgTVU6LQTLDvxOhh1aDoRvzuqq6C02B52ZB6cCrOhNtLEOB B4wePwRoY/j0iF06nBA0HE4fwWCO3oEOAsbXrziwhsuBnnUmyZA1P7IsSMdxoIQAJTNs Decg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=V9JKluzt; 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 a3si1808068eds.355.2020.05.20.10.27.45; Wed, 20 May 2020 10:28:08 -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=V9JKluzt; 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 S1726805AbgETR02 (ORCPT + 99 others); Wed, 20 May 2020 13:26:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726439AbgETR00 (ORCPT ); Wed, 20 May 2020 13:26:26 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15384C061A0E for ; Wed, 20 May 2020 10:26:26 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id t16so1611584plo.7 for ; Wed, 20 May 2020 10:26:26 -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; bh=I4uDtSN00g/PyrhXYZzL0F8/NB4Tyo630ZwvvT8OLZg=; b=V9JKluztz6B+qth05Gg1jopFe/1IeJITinsjf/1HTM6jdqb+1xHzToPxVZXAPhpxQZ DGs/SHNa439w8dTEvwZGhheTRW64oya84qk1ve0BiKb60L+9f28maQdEN/dlHbMViSW3 O8F9N3wXHpvC+N7cvSso2O+lJxKD6Np9VGJbs3Wi6o8usvYzr63LMm68/mM23PFrfA6/ 8R4pYKFxL4dKhIzLxTvIGRADMakVzJz86njTycSI3I3yAX/Zb7HTbDcVW3hkXSam5FiQ 2aFoiV1O0c2sBsMeXxW7Imf2zGSsSG2MreMBdfzVmWNJCPqR44NctbfyurV1wlJC1Utg gtiQ== 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=I4uDtSN00g/PyrhXYZzL0F8/NB4Tyo630ZwvvT8OLZg=; b=fOUYkxGiTZaHtA92ZbqtZFyGZEgAzHFpaxGYdwYO2vx6gGLom1WXD3/gq2EUb4IcQD sniZXrIxojkxUEF719x6HJv+rTGjFgqU2cctXea1302JXKnjDi7LWBEYYZFZSceWDY+3 EV2nV39JdHjHHcctNDnJwdEB/vkAy9vQ0hIgcA8DZg8Q2n9semLIt7B0BFz0V3wfbmQs OqVF9poPkvAQifMyTqsjslzgukpqcXVX5XY/d/0HKMZZ+mHmLSl2xYaH5eTvqgRlUw0R Y5/qYi9rJLJVtwgnOk3GykkY/Bcd80Zmd8WG7/LmicmYGDb4GDAMSm0WVP7mPGJzIYoL is+A== X-Gm-Message-State: AOAM532Ksx7B9d3I5vnPg4zlJcScNhthtQSCDp+lJdEg9jglG9pxwm6e Pcghv6lgL4JyX7kKABwb+SKgQkA3VzsuKZqOHSt19A== X-Received: by 2002:a17:902:82c9:: with SMTP id u9mr5505686plz.179.1589995585260; Wed, 20 May 2020 10:26:25 -0700 (PDT) MIME-Version: 1.0 References: <20200517152916.3146539-1-brgerst@gmail.com> <20200517152916.3146539-3-brgerst@gmail.com> In-Reply-To: From: Nick Desaulniers Date: Wed, 20 May 2020 10:26:13 -0700 Message-ID: Subject: Re: [PATCH 2/7] x86/percpu: Clean up percpu_to_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" 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 8:38 PM Brian Gerst wrote: > > 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. Does it trigger errors in this case? It's interesting to know how this trick differs from __builtin_types_compatible_p(). Might even be helpful to wrap this pattern in a macro with a comment with the pros/cons of this approach vs __same_type. On the other hand, the use of `long` seems tricky in x86 code as x86 (32b) is ILP32 but x86_64 (64b) is LP64. So the use of `long` is ambiguous in the sense that it's a different size depending on the target ABI. Wouldn't it potentially be a bug for x86 kernel code to use `long` percpu variables (or rather mix `long` and `long long` in the same operation) in that case, since the sizes of the two would be different for i386? -- Thanks, ~Nick Desaulniers