Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp759739ybg; Mon, 1 Jun 2020 13:46:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOtdzLk10orqQ/4tyK2ijIy7yWe41UQSS14zwEYw0P6fafiA7GxJh+e+eh76H+uNYD0JsX X-Received: by 2002:a17:906:4554:: with SMTP id s20mr15136522ejq.241.1591044360590; Mon, 01 Jun 2020 13:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591044360; cv=none; d=google.com; s=arc-20160816; b=cOcLJ2KluRSXhzLY+bGHupspsSCeJA3heEtUw418IxSlFOazhfRSSPuNoGULp8CVHN 1tU2QWGtRUuNWq3SqgcwZ5ObpxHQQoo7rYWsMSyjsbCW7eL37ZMrvYNefClJAOOIud/C vaBgA6AtthdvPioIAIi+f9gLRA6aSSPrQKtnuKB7N/TtU3RPkL/EiA+W0jZ2xhfCDvSH NgdUdvk6sbt4AC2mC92zOOGlYPWsBUbRnL8uq5NwcLmw6800VGpyTH3MMYD6C2qZQ7Vr pqLiQ8q6se6yZf0d13ozO7EgwK2jl4eZRSy4vVpdzTFXdLjH+dScyuTmLvnxolF8PxYA Rkiw== 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=53PobnMXXIvJkI0Sukcip3xX+z8MPjzfSKWsAjYxgRo=; b=AX6ZUOu31A8NzJ3ZWQY5+5AnPMAfoCzyD9IEz+MNbGVVzCIJB3eUR/Bm1K3wkUo0u4 +i1tGUMIllcP7RtuLHqg0kyqteaXxEprXtb9KaqKGUFp7dH34MLgOnpGTXql5OgE5v2O YTEi99RCC9Y/QGvtdSDqzCXBDzMebCgdnEJBotzUdl0wxDXfIXIRG1uke6SvISteEdoE qz3+QdXz6noauwaz34WYLI1521LLv4atiTEGioWHfmEzMcQSYPSzJnsR/3g0kF0Kqt5x uJBy5QlCg1ZhFqOSRZp6pR6SSBHCB05oqlYmjUy8Xk5+Lcwd5R0/lSdtUf9Q8pKIUUzX LVzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gTN0KPcZ; 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 s3si331058ejq.532.2020.06.01.13.45.37; Mon, 01 Jun 2020 13:46:00 -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=gTN0KPcZ; 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 S1728097AbgFAUnb (ORCPT + 99 others); Mon, 1 Jun 2020 16:43:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgFAUna (ORCPT ); Mon, 1 Jun 2020 16:43:30 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4E07C061A0E for ; Mon, 1 Jun 2020 13:43:30 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id s10so4034902pgm.0 for ; Mon, 01 Jun 2020 13:43:30 -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=53PobnMXXIvJkI0Sukcip3xX+z8MPjzfSKWsAjYxgRo=; b=gTN0KPcZ7NiBzgz5Pa+hOtBXiZyAStDGftJk/BLjsW7K1QMrgbGaT10BnoJJBUwlRy Kyk/sCwuZ9SfcOCU9SRa8t3/vEl+ubG5fwEVZGOG2OycGICdGVXvHgbYGi4+uFnd4NWQ 5rq74RrzVMO8QHZsuToq784rIV38PLuI/he0TAkXy7vFkMmo5YuH+Z5K5bqAkNOGiiGH 9m7w6SjQvd1TrcJTtnSdMBTvSbsy/Mov4RRRasNdhN0ehMr/6G6wGk8nV+fQWKYO8TB+ PwUjk2h7PwLfsUTUoQL86shHHHEN9GKCdby2JNu2GyDLUiGn1r9lYUxLxCBgOTOj1WFN OhfA== 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=53PobnMXXIvJkI0Sukcip3xX+z8MPjzfSKWsAjYxgRo=; b=VN3tZ2ngTGc5apjfriM0gQyc8n15ZZ561Vxvw+UOvKoek45KZT37UrxL+n9dz9blMZ r6wDQnG10v84gK6qoY8hIAPifiUpovGW8xmIKDgCfRMI2O9bLtxpbUS91b/kEKF9nGI8 OQyXdYTF1UNmG3KISyh1tcPWN0fbmtu3Dbc/6duHFOpPU6AN8pmJ3s2bGdcyxwySFnZf QhtVx1m+Fm0k/SxClKi76rQF0ezI6WOimaSwvKpROknY/rZ6Ue3jsAjKj7sdxy+WtT3u 3DwbQNC83UfWXAL6sGnZfTsK4FIN0MvD+w3pCZTlm+HMTV98BTxVWwpAG4GJIWZzfL1I MlFQ== X-Gm-Message-State: AOAM532jS9yxaPwcnCB/J4poqNsk1WXTHIbnnIxSOsA9CzBCxo39Mgby lJlKPCOrWi23yYQFp6+Gl6e8pkOEmyiEsOP44Ismoil/zAo= X-Received: by 2002:a63:4f09:: with SMTP id d9mr20208805pgb.10.1591044209841; Mon, 01 Jun 2020 13:43:29 -0700 (PDT) MIME-Version: 1.0 References: <20200530221127.459704-1-brgerst@gmail.com> <20200530221127.459704-10-brgerst@gmail.com> In-Reply-To: <20200530221127.459704-10-brgerst@gmail.com> From: Nick Desaulniers Date: Mon, 1 Jun 2020 13:43:18 -0700 Message-ID: Subject: Re: [PATCH v2 09/10] x86/percpu: Clean up percpu_stable_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 Sat, May 30, 2020 at 3:11 PM Brian Gerst wrote: > > Use __pcpu_size_call_return() to simplify this_cpu_read_stable(). Clever! As in this_cpu_read() in include/linux/percpu-defs.h. Could be its own patch before this, but it's fine. Reviewed-by: Nick Desaulniers > Also remove __bad_percpu_size() which is now unused. > > Signed-off-by: Brian Gerst > --- > arch/x86/include/asm/percpu.h | 41 ++++++++++------------------------- > 1 file changed, 12 insertions(+), 29 deletions(-) > > diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h > index 7efc0b5c4ff0..cf2b9c2a241e 100644 > --- a/arch/x86/include/asm/percpu.h > +++ b/arch/x86/include/asm/percpu.h > @@ -85,7 +85,6 @@ > > /* For arch-specific code, we can use direct single-insn ops (they > * don't give an lvalue though). */ > -extern void __bad_percpu_size(void); > > #define __pcpu_type_1 u8 > #define __pcpu_type_2 u16 > @@ -167,33 +166,13 @@ do { \ > (typeof(_var))(unsigned long) pfo_val__; \ > }) > > -#define percpu_stable_op(op, var) \ > -({ \ > - typeof(var) pfo_ret__; \ > - switch (sizeof(var)) { \ > - case 1: \ > - asm(op "b "__percpu_arg(P1)",%0" \ What does the `P` do here? https://gcc.gnu.org/onlinedocs/gcc/Simple-Constraints.html#Simple-Constraints says can be machine dependent integral literal in a certain range. https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html#Machine-Constraints doesn't document `P` for x86 though... > - : "=q" (pfo_ret__) \ > - : "p" (&(var))); \ > - break; \ > - case 2: \ > - asm(op "w "__percpu_arg(P1)",%0" \ > - : "=r" (pfo_ret__) \ > - : "p" (&(var))); \ > - break; \ > - case 4: \ > - asm(op "l "__percpu_arg(P1)",%0" \ > - : "=r" (pfo_ret__) \ > - : "p" (&(var))); \ > - break; \ > - case 8: \ > - asm(op "q "__percpu_arg(P1)",%0" \ > - : "=r" (pfo_ret__) \ > - : "p" (&(var))); \ > - break; \ > - default: __bad_percpu_size(); \ > - } \ > - pfo_ret__; \ > +#define percpu_stable_op(size, op, _var) \ > +({ \ > + __pcpu_type_##size pfo_val__; \ > + asm(__pcpu_op2_##size(op, __percpu_arg(P[var]), "%[val]") \ > + : [val] __pcpu_reg_##size("=", pfo_val__) \ > + : [var] "p" (&(_var))); \ > + (typeof(_var))(unsigned long) pfo_val__; \ > }) > > /* > @@ -258,7 +237,11 @@ do { \ > * per-thread variables implemented as per-cpu variables and thus > * stable for the duration of the respective task. > */ > -#define this_cpu_read_stable(var) percpu_stable_op("mov", var) > +#define this_cpu_read_stable_1(pcp) percpu_stable_op(1, "mov", pcp) > +#define this_cpu_read_stable_2(pcp) percpu_stable_op(2, "mov", pcp) > +#define this_cpu_read_stable_4(pcp) percpu_stable_op(4, "mov", pcp) > +#define this_cpu_read_stable_8(pcp) percpu_stable_op(8, "mov", pcp) > +#define this_cpu_read_stable(pcp) __pcpu_size_call_return(this_cpu_read_stable_, pcp) > > #define raw_cpu_read_1(pcp) percpu_from_op(1, , "mov", pcp) > #define raw_cpu_read_2(pcp) percpu_from_op(2, , "mov", pcp) > -- > 2.25.4 > -- Thanks, ~Nick Desaulniers