Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1625124ybm; Sat, 30 May 2020 15:14:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvaodsI7rafAfshg0xbAGNYFtbc+bxkx8c8I9xTVr6vZ6y2TIJrruFiGxBoYEZdBQtLDFt X-Received: by 2002:aa7:d312:: with SMTP id p18mr14841085edq.88.1590876877047; Sat, 30 May 2020 15:14:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590876877; cv=none; d=google.com; s=arc-20160816; b=pdYCNSQDlIrYr38pN47S/Tmf4G/EW7hOZ4hfVIEvjWQ8fFvuKEbrucQPIfjO25+SUW V7is0+ttXvmWKHg+0zNvVHLFXexe7dhWF2R8VeRp/rbRR020xcC7Gl3Qbd22tcxMSxxU Ew5n/XzPDJ7VzoCm3iLVr601tNcVjyKmfb9mT5kE+weV3cc6h+33xjbbHr1HEpgZIELA 90Me6FZVN6VPbvS87fLvBoyXhFd8v5V9JoaakCN6eBvo4gDYhrW9Tk5QS1i8dFo52Z/P TesxK6pZkDq9dZ8VuSb207LIdofGeYIfGMo3fWDUy5Wl8bpih6qdBP2ECLc22T/jzYXW dp3w== 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=e0WjK0e7hgwQHYo1aWVTXJ/dHNIzXbzevTz/cIfmq1Q=; b=R7XU8NHEajj0C8b4oolccx5HhCC5wUwhBCYG7g9pMdFiZ9oAPgAQKmzTNJ8PVtAhUx rjM6hBpXgIamkO4yiRKDpBAGb22pacjptzmtLIJw4LOHJPDM43tgvRtHPXZmOgbxMVzH QP2Ih5rpTECYoBZsUv7/OzUkevYKeQISQ7rXPYM2ygyPbOt97pL6YGFNja3ETpoth1ME VjAERMFMX7mqqpwWWI9AkjfVbC8ZA0Rmrt1WgWprhl/z/GpbhzJrgSol+DQqJQSoPD3e D5p7j3pJhr9GE5ER39a02j5Wyqc6Isj+jrBzLsiQWZGOmPX9iKX+ljC/9n0sLHbasuBa A24w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oRLIZZ3J; 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 cm1si2063348edb.235.2020.05.30.15.14.14; Sat, 30 May 2020 15:14:37 -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=oRLIZZ3J; 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 S1729497AbgE3WMF (ORCPT + 99 others); Sat, 30 May 2020 18:12:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729449AbgE3WLt (ORCPT ); Sat, 30 May 2020 18:11:49 -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 A6D4EC08C5D1 for ; Sat, 30 May 2020 15:11:47 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id c8so3137069iob.6 for ; Sat, 30 May 2020 15:11:47 -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=e0WjK0e7hgwQHYo1aWVTXJ/dHNIzXbzevTz/cIfmq1Q=; b=oRLIZZ3JgdJu6h0ApjQ6OOQULR7BshXrLbWNBX/sz1mmhKQHtB25gwDONRXbjUuwCT Iv5rjAtWs1uFn2hS7d0WbuwZuq4HT0oyT7MPvHvl71KctAbWQk4ab25SdhuxGmdrXhMS JwKLaaRvQIClxnnwHZxX8ISTGHcM0QaAnzbU5uIv+h8UEPNLCmI/xEpd2duvTzm+uYQ6 E9Eu/jIrwr3BjzjiJifxNuJhI1LXVoflE22YBU/r1dCMTR2bSmNpkUCkCx5B1MlfFa9d +G4OoInp21slCylewNUKnszobro/AVTV7dyX5s7XBH5Mx1ln+OMEdzg4/5Y81ifZKFE9 JznQ== 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=e0WjK0e7hgwQHYo1aWVTXJ/dHNIzXbzevTz/cIfmq1Q=; b=efRn7bm/RnsurJgddV+4410uGwP8k9+wFIQDP36xcxhzL3aaj5ipmIxRzxy5OBXzR2 91KuV2XSajhwZCrl6rRX92U5ymbM7BQKCkGn/TDH9i8F1N+98+PlT0r1YGfIWwYdlfKu +LEtmprx/Dj24ETX+L2j5yM9EE8dLK1WPiRVuWhHpqa1DbqtJ+j/bOT9Y5JVrBauNKVe B4DmYqcz5uWT6R2/gU1pFEw6kvt+YF/Q+FssCryfz/0Fz1nljqhayRe/mpl/vh/64W0Q qzbi1pghit3lUukz2pMHZnlwCFkB1KJylJ3elX2TX2RDmC2MKc3CI/aijPbP1gdQmYye 2l7g== X-Gm-Message-State: AOAM532tkeHl6fAVGIU8Di/SFVHoO+t75lQhHRjxjfaGyqOjWfBBy0JM VtPfRp72ZrOdPvGrupmiCGtOiHrfBA== X-Received: by 2002:a02:cc49:: with SMTP id i9mr6212076jaq.52.1590876706813; Sat, 30 May 2020 15:11:46 -0700 (PDT) Received: from localhost.localdomain (174-084-153-250.res.spectrum.com. [174.84.153.250]) by smtp.gmail.com with ESMTPSA id w78sm2735698ilk.14.2020.05.30.15.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 15:11:46 -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 v2 07/10] x86/percpu: Clean up percpu_xchg_op() Date: Sat, 30 May 2020 18:11:24 -0400 Message-Id: <20200530221127.459704-8-brgerst@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200530221127.459704-1-brgerst@gmail.com> References: <20200530221127.459704-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 Reviewed-by: Nick Desaulniers --- 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 0776a11e7e11..ac6d7e76c0d4 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