Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp184788ybh; Mon, 20 Jul 2020 13:50:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2J6NNmTDA516Enh8KFjfG4z/jjnr8cM+6vW9AL2nxldm0yCRksbXTBJ0eAq8fxn7jR+KQ X-Received: by 2002:aa7:dc46:: with SMTP id g6mr22499654edu.194.1595278253675; Mon, 20 Jul 2020 13:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595278253; cv=none; d=google.com; s=arc-20160816; b=alb5Bksg17NLO9+pbi8E55o6H2HyJ7GYIjXpmlSTMt2jxVYsihkliafWZb/lusMUHJ yWOM3YG52cVXm80syBUd1jFNCdh3Hg4q3fDcHKX22T9fPSAVgLX329zh5Jd8BM+o+z11 YX+VO6+IVpMXqacIAFJkvOddsSCh4Lc1VYKgR/3c9usS2L6A2YpVbOtlYr1ly/Ym3/TS 2/gBowHIpTSa7DrRSl9uyHHBEDzpzG+iYcXbJtn1K82n8uo/zbvd8U7gcRv3eJXh2IdJ IuBGKwzQDMT7gcmjV72Ld9BQffjtGdAYfkX5Iq0xromuO78qMhYEAwS2Im5Br7F1iGob 8Viw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=moMBrUya8+f11J0lfoG20VXlS54zFWp92IgRf7/2Gwk=; b=mzsO6qeLIon1NdF3reBE+Dra6iUX1KNLAp0edZylIDnmRX4ZKcpD2NYmr512T2hz4k TMDazVTRqMr2FFX4J145AjAuhkpxtQ2XTM1nRZ5Qqm4SA2OG7z5FamDqUVIaemLpn01Z mkRHR4NquYfD2Hqm2NMBPixobl/qPM86ZxZT1Kp3XnrrwFQ2MZHdPlNNgpu7DqOnIN7I rAJSopeYw3lxbPGeVWiE0uEQYDK5oeC7CLHsk/SHZk18yk9g+p/q2AIkdZ+UmNc7zmtB yNw+9JHf7RUVUW19FrUJuEtpALIxC7/SH9mkRD0BUO1YZFUyoZqmcV6bOZ8d5DEhkGwJ 2VaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PynqyNO2; 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 u30si561084edc.466.2020.07.20.13.50.30; Mon, 20 Jul 2020 13:50:53 -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=PynqyNO2; 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 S1729374AbgGTUuD (ORCPT + 99 others); Mon, 20 Jul 2020 16:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726648AbgGTUuC (ORCPT ); Mon, 20 Jul 2020 16:50:02 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38AC0C061794 for ; Mon, 20 Jul 2020 13:50:02 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id w35so23158227ybi.16 for ; Mon, 20 Jul 2020 13:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=moMBrUya8+f11J0lfoG20VXlS54zFWp92IgRf7/2Gwk=; b=PynqyNO2eV4KSO1NON0YdMlKrn3ICVzTrzjmZ/5xUPrqbtBhxeuNs+QS4b9Iz0NTEs RMOZAfxvHjgCgi4Tcx0DqQzO0A9w2T5afQbxYCH2JpjsdRap7jDlyubgkb2iNSetIXCs gjafUu4gxrFMBnrI/MJRqt03KcIee2VzoOv4GPx6TG2msQoNzlNShlbi+lti8rigo+E1 lNocxqrxSXrPNfsWPvnP6/KyORTbOYDw7OYvJK0xhJEwpbWUIjjh6BpXiVBhcipB0vl2 ARZWxZmSJD9twHzaBbuzmX3jD/0w0wPgfKGZ96CO7pFO27kdkPo579Fe2ODlPRvWfHLO gpFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=moMBrUya8+f11J0lfoG20VXlS54zFWp92IgRf7/2Gwk=; b=jGmIZtgFnpTuY1ryuRarCYU4Lyd72z5+Z/0gwLVdp3hhe1QXPQSz50PQ+jwUI1GjZn b8pc9dTg13G+Tm+y9dN+Rw17UqXDsIOTUVXJviAkwKaTbrf71Qo7o+BAMTCFclDuD6iv Onjd1cytKNqcZZhRvmR3a+oMZKRG3OnilnZJqoNG6W5VP36I7YBn8p74uoPcfYYaD2l/ dVHS1CHv+GMJe/upnBltrOY+bRg9ZcDqHQKot36lFrQFRzN+/OK47KjVS4+T4Ll2jLIP 3xQ/z+r/HBfS069IzmxIYD7UCYJmqTd6vMrl0YlcAegFP/cO/GKKNQGt1/AipZ42G5wp MHPA== X-Gm-Message-State: AOAM532sqWcgYC6OwSTo0sYLWs1ac0dvNRZfQNt/DP9baVHO2R95IJMR qTFltzpUXYxkCb4Yo0TEgOdPxrDFiMBrK1Wg5qc= X-Received: by 2002:a25:138a:: with SMTP id 132mr36725992ybt.334.1595278201430; Mon, 20 Jul 2020 13:50:01 -0700 (PDT) Date: Mon, 20 Jul 2020 13:49:17 -0700 In-Reply-To: <20200720204925.3654302-1-ndesaulniers@google.com> Message-Id: <20200720204925.3654302-4-ndesaulniers@google.com> Mime-Version: 1.0 References: <20200720204925.3654302-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH v3 03/11] x86/percpu: Clean up percpu_from_op() From: Nick Desaulniers To: Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Dennis Zhou , Tejun Heo , Christoph Lameter , x86@kernel.org, "H. Peter Anvin" , Al Viro , Andrew Morton , Peter Zijlstra , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Brian Gerst , Nick Desaulniers , Linus Torvalds 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 From: Brian Gerst 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. Tested-by: Nick Desaulniers Reviewed-by: Nick Desaulniers Acked-by: Linus Torvalds Acked-by: Peter Zijlstra (Intel) Signed-off-by: Brian Gerst Signed-off-by: Nick Desaulniers --- arch/x86/include/asm/percpu.h | 50 +++++++++++------------------------ 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index fb280fba94c5..a40d2e055f58 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -190,33 +190,13 @@ do { \ } \ } while (0) -#define percpu_from_op(qual, op, var) \ -({ \ - typeof(var) pfo_ret__; \ - switch (sizeof(var)) { \ - case 1: \ - asm qual (op "b "__percpu_arg(1)",%0" \ - : "=q" (pfo_ret__) \ - : "m" (var)); \ - break; \ - case 2: \ - asm qual (op "w "__percpu_arg(1)",%0" \ - : "=r" (pfo_ret__) \ - : "m" (var)); \ - break; \ - case 4: \ - asm qual (op "l "__percpu_arg(1)",%0" \ - : "=r" (pfo_ret__) \ - : "m" (var)); \ - break; \ - case 8: \ - asm qual (op "q "__percpu_arg(1)",%0" \ - : "=r" (pfo_ret__) \ - : "m" (var)); \ - break; \ - default: __bad_percpu_size(); \ - } \ - pfo_ret__; \ +#define percpu_from_op(size, qual, op, _var) \ +({ \ + __pcpu_type_##size pfo_val__; \ + asm qual (__pcpu_op2_##size(op, __percpu_arg([var]), "%[val]") \ + : [val] __pcpu_reg_##size("=", pfo_val__) \ + : [var] "m" (_var)); \ + (typeof(_var))(unsigned long) pfo_val__; \ }) #define percpu_stable_op(op, var) \ @@ -401,9 +381,9 @@ do { \ */ #define this_cpu_read_stable(var) percpu_stable_op("mov", var) -#define raw_cpu_read_1(pcp) percpu_from_op(, "mov", pcp) -#define raw_cpu_read_2(pcp) percpu_from_op(, "mov", pcp) -#define raw_cpu_read_4(pcp) percpu_from_op(, "mov", 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) +#define raw_cpu_read_4(pcp) percpu_from_op(4, , "mov", pcp) #define raw_cpu_write_1(pcp, val) percpu_to_op(1, , "mov", (pcp), val) #define raw_cpu_write_2(pcp, val) percpu_to_op(2, , "mov", (pcp), val) @@ -433,9 +413,9 @@ do { \ #define raw_cpu_xchg_2(pcp, val) raw_percpu_xchg_op(pcp, val) #define raw_cpu_xchg_4(pcp, val) raw_percpu_xchg_op(pcp, val) -#define this_cpu_read_1(pcp) percpu_from_op(volatile, "mov", pcp) -#define this_cpu_read_2(pcp) percpu_from_op(volatile, "mov", pcp) -#define this_cpu_read_4(pcp) percpu_from_op(volatile, "mov", pcp) +#define this_cpu_read_1(pcp) percpu_from_op(1, volatile, "mov", pcp) +#define this_cpu_read_2(pcp) percpu_from_op(2, volatile, "mov", pcp) +#define this_cpu_read_4(pcp) percpu_from_op(4, volatile, "mov", pcp) #define this_cpu_write_1(pcp, val) percpu_to_op(1, volatile, "mov", (pcp), val) #define this_cpu_write_2(pcp, val) percpu_to_op(2, volatile, "mov", (pcp), val) #define this_cpu_write_4(pcp, val) percpu_to_op(4, volatile, "mov", (pcp), val) @@ -488,7 +468,7 @@ do { \ * 32 bit must fall back to generic operations. */ #ifdef CONFIG_X86_64 -#define raw_cpu_read_8(pcp) percpu_from_op(, "mov", pcp) +#define raw_cpu_read_8(pcp) percpu_from_op(8, , "mov", pcp) #define raw_cpu_write_8(pcp, val) percpu_to_op(8, , "mov", (pcp), val) #define raw_cpu_add_8(pcp, val) percpu_add_op(, (pcp), val) #define raw_cpu_and_8(pcp, val) percpu_to_op(8, , "and", (pcp), val) @@ -497,7 +477,7 @@ do { \ #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 this_cpu_read_8(pcp) percpu_from_op(volatile, "mov", pcp) +#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) #define this_cpu_add_8(pcp, val) percpu_add_op(volatile, (pcp), val) #define this_cpu_and_8(pcp, val) percpu_to_op(8, volatile, "and", (pcp), val) -- 2.28.0.rc0.105.gf9edc3c819-goog