From patchwork Mon Dec 17 16:03:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 154016 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2640580ljp; Mon, 17 Dec 2018 08:11:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/WWlr7AqVQeVuUaUS6jo+IkEaqWUG32dtzMx1VygPaig6lSAHd0uLdN+kZymErfNIRVT3dl X-Received: by 2002:a63:f658:: with SMTP id u24mr12700490pgj.267.1545063087926; Mon, 17 Dec 2018 08:11:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545063087; cv=none; d=google.com; s=arc-20160816; b=ZGM4bmU3Qvv37orjGbTl7XCnOp6sxHRd50UQPVN67mGcL966cRzVnDBhzX9X9adGY3 57HhaIJ4eHgibHWEG0z0D/nI18SdBxKUSSBlL8iCIsuExv1JO9nXYcXYy/+xr8bGeBKi uhqImpart/rXSyxzuiIJmN8lRWJga6NVGNqszZYJUdWMtWaCPbY+2jayKzrFeB/h43Ex LnvhBKIF63BGHYxMWqtdzukqBvhQjRMcit/1C+7ynbOL3f0myxSvj+S0+/fY0/K76UUb JrLgVy01ifRnwPot0ggCGVpRKg10izAvRy0DToI06nPP6oOKS8Yxsd7IB8sLGEdE3W5W 67oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=9DcjqEmtpr1b4GO1cESJaDoe5JvvAOWZuwQM0QNgknw=; b=ij/rQd/SaDk9aiFx1F4p+3hYdYDD5hQXhb6dE4feSu/kwwpkKdFcVoKdXe6UbjaCnN J2cOFQG77WdItH8+Y2nGo62VBIRHuiPMj8+oBtJw6b1rSAuzt/Gj27HkumEwndN2ReGX asV59NM4QgQm9wlFO68ikvbPxXZm+hwXvKtl3Q0Kni7pSiLGL9v5J8nXMd2xLZk+K+Jy +UVUJonAVzm/BLzNwBE+gvfAA0CmSp2W/p69cNCAVo/1xSQD08TphN4hZBGWJRwcJDGH PCpiYCuSis8Iu74f8IF8eIsXtiWn6iBuS2asRT7hodNSh0YGPc5V0okVd6bQBwDPU+zx VW1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=UvhPspAD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j132si7406217pfc.84.2018.12.17.08.11.27; Mon, 17 Dec 2018 08:11:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=UvhPspAD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388248AbeLQQLQ (ORCPT + 31 others); Mon, 17 Dec 2018 11:11:16 -0500 Received: from conuserg-07.nifty.com ([210.131.2.74]:65246 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726548AbeLQQLP (ORCPT ); Mon, 17 Dec 2018 11:11:15 -0500 Received: from grover.tkatk1.zaq.ne.jp (zaqdadce369.zaq.ne.jp [218.220.227.105]) (authenticated) by conuserg-07.nifty.com with ESMTP id wBHG3bRo008119; Tue, 18 Dec 2018 01:03:55 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com wBHG3bRo008119 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1545062636; bh=9DcjqEmtpr1b4GO1cESJaDoe5JvvAOWZuwQM0QNgknw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UvhPspADlIzQrlh8fdDk3sHogE5Obsyfz5Xbk6iOPgw/3syRRNOCSUp+v19VRTYbF yv/kVKF3IUHFyNSDOJ2xSs0KWaU86eCCvr9CUYCBIvSyZzcF07hd1ucJYyYC398Cl1 1M9DVQPruecUvJvSJIn8udJzLRdtGxg8EG0fIBE+Ky5ycLNf6RZjzyjnk3Ffiih7B4 q3o8TRd+iEt8z8ioUyvkYjcykB12cGBUmCm/rVQQOHu9aUZzjJ2QeFJd524UPuUpCK LGSOU7Ya1VNHFcC0MRO5ecxjDetrFNH28Hkz3ZqrNXeJNrttOAPKI65WljADIlgOc0 7QehQi0VxnvoQ== X-Nifty-SrcIP: [218.220.227.105] From: Masahiro Yamada To: x86@kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" Cc: Richard Biener , Segher Boessenkool , Peter Zijlstra , Juergen Gross , Josh Poimboeuf , Kees Cook , Linus Torvalds , Masahiro Yamada , David Woodhouse , linux-kernel@vger.kernel.org, Alexey Dobriyan , Nadav Amit Subject: [PATCH v3 11/12] x86/alternatives: consolidate LOCK_PREFIX macro Date: Tue, 18 Dec 2018 01:03:26 +0900 Message-Id: <1545062607-8599-12-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545062607-8599-1-git-send-email-yamada.masahiro@socionext.com> References: <1545062607-8599-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The LOCK_PREFIX is mostly used in inline asm, but also used by atomic64_cx8_32.S Let's unify the definition by using ASM() macro. This was previously cleaned up by 77f48ec28e4c ("x86/alternatives: Macrofy lock prefixes to work around GCC inlining bugs"). Now, I am refactoring the code without using the macros approach. The new header contains macros that can be used by C and assembly. Signed-off-by: Masahiro Yamada --- arch/x86/include/asm/alternative-asm.h | 14 +-------- arch/x86/include/asm/alternative-common.h | 47 +++++++++++++++++++++++++++++++ arch/x86/include/asm/alternative.h | 37 +----------------------- 3 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 arch/x86/include/asm/alternative-common.h -- 2.7.4 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h index 31b627b..7425514 100644 --- a/arch/x86/include/asm/alternative-asm.h +++ b/arch/x86/include/asm/alternative-asm.h @@ -4,21 +4,9 @@ #ifdef __ASSEMBLY__ +#include #include -#ifdef CONFIG_SMP - .macro LOCK_PREFIX -672: lock - .pushsection .smp_locks,"a" - .balign 4 - .long 672b - . - .popsection - .endm -#else - .macro LOCK_PREFIX - .endm -#endif - /* * Issue one struct alt_instr descriptor entry (need to put it into * the section .altinstructions, see below). This entry contains diff --git a/arch/x86/include/asm/alternative-common.h b/arch/x86/include/asm/alternative-common.h new file mode 100644 index 0000000..ae0b58f --- /dev/null +++ b/arch/x86/include/asm/alternative-common.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_ALTERNATIVE_COMMON_H +#define _ASM_X86_ALTERNATIVE_COMMON_H + +#include + +/* + * Alternative inline assembly for SMP. + * + * The LOCK_PREFIX macro defined here replaces the LOCK and + * LOCK_PREFIX macros used everywhere in the source tree. + * + * SMP alternatives use the same data structures as the other + * alternatives and the X86_FEATURE_UP flag to indicate the case of a + * UP system running a SMP kernel. The existing apply_alternatives() + * works fine for patching a SMP kernel for UP. + * + * The SMP alternative tables can be kept after boot and contain both + * UP and SMP versions of the instructions to allow switching back to + * SMP at runtime, when hotplugging in a new CPU, which is especially + * useful in virtualized environments. + * + * The very common lock prefix is handled as special case in a + * separate table which is a pure address list without replacement ptr + * and size information. That keeps the table sizes small. + */ + +#include +#include + +#ifdef CONFIG_SMP + +#define LOCK_PREFIX_HERE \ +ASM( .pushsection .smp_locks,"a" )\ +ASM( .balign 4 )\ +ASM( .long 671f - . )\ +ASM( .popsection )\ +ASM( 671: ) + +#define LOCK_PREFIX LOCK_PREFIX_HERE ASM(lock) + +#else /* ! CONFIG_SMP */ +#define LOCK_PREFIX_HERE ASM() +#define LOCK_PREFIX ASM() +#endif + +#endif /* _ASM_X86_ALTERNATIVE_COMMON_H */ diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h index 4cd6a3b..157967c 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -7,44 +7,9 @@ #include #include #include +#include #include -/* - * Alternative inline assembly for SMP. - * - * The LOCK_PREFIX macro defined here replaces the LOCK and - * LOCK_PREFIX macros used everywhere in the source tree. - * - * SMP alternatives use the same data structures as the other - * alternatives and the X86_FEATURE_UP flag to indicate the case of a - * UP system running a SMP kernel. The existing apply_alternatives() - * works fine for patching a SMP kernel for UP. - * - * The SMP alternative tables can be kept after boot and contain both - * UP and SMP versions of the instructions to allow switching back to - * SMP at runtime, when hotplugging in a new CPU, which is especially - * useful in virtualized environments. - * - * The very common lock prefix is handled as special case in a - * separate table which is a pure address list without replacement ptr - * and size information. That keeps the table sizes small. - */ - -#ifdef CONFIG_SMP -#define LOCK_PREFIX_HERE \ - ".pushsection .smp_locks,\"a\"\n" \ - ".balign 4\n" \ - ".long 671f - .\n" /* offset */ \ - ".popsection\n" \ - "671:" - -#define LOCK_PREFIX LOCK_PREFIX_HERE "\n\tlock; " - -#else /* ! CONFIG_SMP */ -#define LOCK_PREFIX_HERE "" -#define LOCK_PREFIX "" -#endif - struct alt_instr { s32 instr_offset; /* original instruction */ s32 repl_offset; /* offset to replacement instruction */