Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2047269ybk; Sun, 17 May 2020 08:33:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyMjuV+baeVVX9i6a+1EPbnvHGrIEsFUNsxc7SX334TxQ3gIkIOKgHJ9i00bmzV2wWMQqC X-Received: by 2002:a05:6402:2c3:: with SMTP id b3mr10842946edx.66.1589729604938; Sun, 17 May 2020 08:33:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589729604; cv=none; d=google.com; s=arc-20160816; b=tLkLYEAOL9ptEFGz5LRwUW1L9Z3hUS1VLS09K6cyJSNxhemur1gSJaIxF9mF02kz38 opgIINW9mewCdUjnqkKjMUYgZbFHIHp9mGpKF03gogaVkTQwZnApBEhFZwGoYLP+lFHQ LG7ezuBQy9LLcn265vnNGYVT5Ute2ApAfgykqRcDcLiU5MP1IdXpKArelyjBL8nyDvVU nxSiS6EXnXQC0iuysKMWU/AWzJEJ9lmmK2kSHB6G41hU/5SlwWMFunmlVU8n+WNApnvm OXqRiV+BJDjsIjyabLRqrTgCPV4HPxdI0dotD/rVDP9r12IaY2HAUZkyFyWag6dCyTwP sL7Q== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GY4Jy7rnTiJ0kXrs7xMxihBrYL9Ask63QEduHqOBnn8=; b=DRiGT81mY82P/Y0+P9D1ETxgaxVSOYUSH0VjNx7jPkgUvOwdZ5XXn0R9U20iP2L/c5 StfCcxsCCehEoQ2zZXEyIDywTHwUmUaQhVtZ7vkd0XvrTNpx7Iua6IJZk/gQnBOnL1l0 F7pCAyuT2EkoEh9RMekBdsyaONp/v8AJr/IKng47qJTL7pDvEHJKhLSSdw6MrKZXRVYF V/gMIRFh+tE8HTQ30nr+pfWVHSWO4Zd97dJ6nUMHQPbr3q2XN2GuYxOLzTaA06Xf4yWl LyH4oeOIQwSuOmJ3PmwYY/eZNffns8qeqORScspLpxdEzaxvZOkLsnoGk8o+Z94NgGZE 8EPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ZP75/YwZ"; 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 u8si4692635edl.504.2020.05.17.08.33.02; Sun, 17 May 2020 08:33:24 -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="ZP75/YwZ"; 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 S1728180AbgEQP3n (ORCPT + 99 others); Sun, 17 May 2020 11:29:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728117AbgEQP3f (ORCPT ); Sun, 17 May 2020 11:29:35 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF478C05BD09 for ; Sun, 17 May 2020 08:29:33 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id o19so6082315qtr.10 for ; Sun, 17 May 2020 08:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GY4Jy7rnTiJ0kXrs7xMxihBrYL9Ask63QEduHqOBnn8=; b=ZP75/YwZhW0QWF2UjInjZ6pQyLz2V+sOWihhnYexKABHM1W77hBR/j4NLCl9Qzdrrf /Hm2fXN4dgplvbDFTcY+9EzXMwZhcfxx0q93v0fWMXRp5rzW8Gm3s/fmp1KHQxC5DP1K 58ZH5cbqeWOWQKD/fRLLGfRDsH+GR9w0h2ULm5KAadmzXTAar74804VkhCkkqwXmipvo k+OaJMfDs++p5F/S5AMnF5bo1w0QaaWyR9NB+9QfcMgDt8Zh2uXV4LlhNjvAtdj070kX E8ZxOXWjx4J8pZl/x0Cq/gjnUCT8B8gcbA2uRZe28t0cJNac0NlWKNxVj+8zCVQoQWcb ORfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GY4Jy7rnTiJ0kXrs7xMxihBrYL9Ask63QEduHqOBnn8=; b=k00FVG/wvkVvhRjPjM1FB6Hky06wEe4qgKO5wEJbRMvM4SLgnAvqX7QrJl8YX8m+2s zJM5Qpnw3y3MlPaOPh+c5UX9X9hfjPAP8ZTc7D6mz82sRzMKZEJVJgnIVy7rMCenwNJv Et1feJvjEUPFyMC5daZ49jSG/9pmEc7e/fKC+h0HVsX3/l9Q5WBQKds7PVtXgSc5ibKO M+dRsIOgg/3Bam/FtvoeTuwFeJCVwqwdXL3vat0jcxo7hVhJMMqfE+EP4STR2nsnvoMO CyPQgW8e3LBoU8K3n69xA964aZXWg0WPaZ3pI61n9p9m8WdsEyR/YS7/u2DCLfA2rpZv /1PA== X-Gm-Message-State: AOAM532rw6ajHyytuvHm0RtWS/z+PICu7iCZY5v4F/GpQqlbbF4aVnSi o+QDJFxGW8BOczTxupkjKy7w2qCJ6w== X-Received: by 2002:aed:3ff7:: with SMTP id w52mr12579261qth.148.1589729372645; Sun, 17 May 2020 08:29:32 -0700 (PDT) Received: from localhost.localdomain (174-084-153-250.res.spectrum.com. [174.84.153.250]) by smtp.gmail.com with ESMTPSA id 63sm6234335qkh.120.2020.05.17.08.29.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2020 08:29:32 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Nick Desaulniers , Brian Gerst Subject: [PATCH 6/7] x86/percpu: Clean up percpu_xchg_op() Date: Sun, 17 May 2020 11:29:15 -0400 Message-Id: <20200517152916.3146539-7-brgerst@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200517152916.3146539-1-brgerst@gmail.com> References: <20200517152916.3146539-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 61 +++++++++++------------------------ 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index ac8c391a190e..3c95ab3c99cd 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -215,46 +215,21 @@ do { \ * expensive due to the implied lock prefix. The processor cannot prefetch * cachelines if xchg is used. */ -#define percpu_xchg_op(qual, var, nval) \ +#define percpu_xchg_op(size, qual, _var, _nval) \ ({ \ - typeof(var) pxo_ret__; \ - typeof(var) pxo_new__ = (nval); \ - switch (sizeof(var)) { \ - case 1: \ - asm qual ("\n\tmov "__percpu_arg(1)",%%al" \ - "\n1:\tcmpxchgb %2, "__percpu_arg(1) \ - "\n\tjnz 1b" \ - : "=&a" (pxo_ret__), "+m" (var) \ - : "q" (pxo_new__) \ - : "memory"); \ - break; \ - case 2: \ - asm qual ("\n\tmov "__percpu_arg(1)",%%ax" \ - "\n1:\tcmpxchgw %2, "__percpu_arg(1) \ - "\n\tjnz 1b" \ - : "=&a" (pxo_ret__), "+m" (var) \ - : "r" (pxo_new__) \ - : "memory"); \ - break; \ - case 4: \ - asm qual ("\n\tmov "__percpu_arg(1)",%%eax" \ - "\n1:\tcmpxchgl %2, "__percpu_arg(1) \ - "\n\tjnz 1b" \ - : "=&a" (pxo_ret__), "+m" (var) \ - : "r" (pxo_new__) \ - : "memory"); \ - break; \ - case 8: \ - asm qual ("\n\tmov "__percpu_arg(1)",%%rax" \ - "\n1:\tcmpxchgq %2, "__percpu_arg(1) \ - "\n\tjnz 1b" \ - : "=&a" (pxo_ret__), "+m" (var) \ - : "r" (pxo_new__) \ - : "memory"); \ - break; \ - default: __bad_percpu_size(); \ - } \ - pxo_ret__; \ + __pcpu_type_##size pxo_old__; \ + __pcpu_type_##size pxo_new__ = __pcpu_cast_##size(_nval); \ + asm qual (__pcpu_op2_##size("mov", __percpu_arg([var]), \ + "%[oval]") \ + "\n1:\t" \ + __pcpu_op2_##size("cmpxchg", "%[nval]", \ + __percpu_arg([var])) \ + "\n\tjnz 1b" \ + : [oval] "=&a" (pxo_old__), \ + [var] "+m" (_var) \ + : [nval] __pcpu_reg_##size(, pxo_new__) \ + : "memory"); \ + (typeof(_var))(unsigned long) pxo_old__; \ }) /* @@ -354,9 +329,9 @@ do { \ #define this_cpu_or_1(pcp, val) percpu_to_op(1, volatile, "or", (pcp), val) #define this_cpu_or_2(pcp, val) percpu_to_op(2, volatile, "or", (pcp), val) #define this_cpu_or_4(pcp, val) percpu_to_op(4, volatile, "or", (pcp), val) -#define this_cpu_xchg_1(pcp, nval) percpu_xchg_op(volatile, pcp, nval) -#define this_cpu_xchg_2(pcp, nval) percpu_xchg_op(volatile, pcp, nval) -#define this_cpu_xchg_4(pcp, nval) percpu_xchg_op(volatile, pcp, nval) +#define this_cpu_xchg_1(pcp, nval) percpu_xchg_op(1, volatile, pcp, nval) +#define this_cpu_xchg_2(pcp, nval) percpu_xchg_op(2, volatile, pcp, nval) +#define this_cpu_xchg_4(pcp, nval) percpu_xchg_op(4, volatile, pcp, nval) #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) @@ -409,7 +384,7 @@ do { \ #define this_cpu_and_8(pcp, val) percpu_to_op(8, volatile, "and", (pcp), val) #define this_cpu_or_8(pcp, val) percpu_to_op(8, volatile, "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(volatile, pcp, nval) +#define this_cpu_xchg_8(pcp, nval) percpu_xchg_op(8, volatile, pcp, nval) #define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(volatile, pcp, oval, nval) /* -- 2.25.4