mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	x86/alternative: Merge include files
Merge arch/x86/include/asm/alternative-asm.h into arch/x86/include/asm/alternative.h in order to make it easier to use common definitions later. Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/20210311142319.4723-2-jgross@suse.com
This commit is contained in:
		
							parent
							
								
									db16e07269
								
							
						
					
					
						commit
						5e21a3ecad
					
				
					 14 changed files with 120 additions and 132 deletions
				
			
		| 
						 | 
				
			
			@ -40,7 +40,7 @@
 | 
			
		|||
#include <asm/processor-flags.h>
 | 
			
		||||
#include <asm/irq_vectors.h>
 | 
			
		||||
#include <asm/cpufeatures.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
#include <asm/asm.h>
 | 
			
		||||
#include <asm/smap.h>
 | 
			
		||||
#include <asm/frame.h>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@
 | 
			
		|||
#include <linux/linkage.h>
 | 
			
		||||
#include <asm/dwarf2.h>
 | 
			
		||||
#include <asm/cpufeatures.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
 | 
			
		||||
	.text
 | 
			
		||||
	.globl __kernel_vsyscall
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,114 +0,0 @@
 | 
			
		|||
/* SPDX-License-Identifier: GPL-2.0 */
 | 
			
		||||
#ifndef _ASM_X86_ALTERNATIVE_ASM_H
 | 
			
		||||
#define _ASM_X86_ALTERNATIVE_ASM_H
 | 
			
		||||
 | 
			
		||||
#ifdef __ASSEMBLY__
 | 
			
		||||
 | 
			
		||||
#include <asm/asm.h>
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_SMP
 | 
			
		||||
	.macro LOCK_PREFIX
 | 
			
		||||
672:	lock
 | 
			
		||||
	.pushsection .smp_locks,"a"
 | 
			
		||||
	.balign 4
 | 
			
		||||
	.long 672b - .
 | 
			
		||||
	.popsection
 | 
			
		||||
	.endm
 | 
			
		||||
#else
 | 
			
		||||
	.macro LOCK_PREFIX
 | 
			
		||||
	.endm
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * objtool annotation to ignore the alternatives and only consider the original
 | 
			
		||||
 * instruction(s).
 | 
			
		||||
 */
 | 
			
		||||
.macro ANNOTATE_IGNORE_ALTERNATIVE
 | 
			
		||||
	.Lannotate_\@:
 | 
			
		||||
	.pushsection .discard.ignore_alts
 | 
			
		||||
	.long .Lannotate_\@ - .
 | 
			
		||||
	.popsection
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Issue one struct alt_instr descriptor entry (need to put it into
 | 
			
		||||
 * the section .altinstructions, see below). This entry contains
 | 
			
		||||
 * enough information for the alternatives patching code to patch an
 | 
			
		||||
 * instruction. See apply_alternatives().
 | 
			
		||||
 */
 | 
			
		||||
.macro altinstruction_entry orig alt feature orig_len alt_len pad_len
 | 
			
		||||
	.long \orig - .
 | 
			
		||||
	.long \alt - .
 | 
			
		||||
	.word \feature
 | 
			
		||||
	.byte \orig_len
 | 
			
		||||
	.byte \alt_len
 | 
			
		||||
	.byte \pad_len
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Define an alternative between two instructions. If @feature is
 | 
			
		||||
 * present, early code in apply_alternatives() replaces @oldinstr with
 | 
			
		||||
 * @newinstr. ".skip" directive takes care of proper instruction padding
 | 
			
		||||
 * in case @newinstr is longer than @oldinstr.
 | 
			
		||||
 */
 | 
			
		||||
.macro ALTERNATIVE oldinstr, newinstr, feature
 | 
			
		||||
140:
 | 
			
		||||
	\oldinstr
 | 
			
		||||
141:
 | 
			
		||||
	.skip -(((144f-143f)-(141b-140b)) > 0) * ((144f-143f)-(141b-140b)),0x90
 | 
			
		||||
142:
 | 
			
		||||
 | 
			
		||||
	.pushsection .altinstructions,"a"
 | 
			
		||||
	altinstruction_entry 140b,143f,\feature,142b-140b,144f-143f,142b-141b
 | 
			
		||||
	.popsection
 | 
			
		||||
 | 
			
		||||
	.pushsection .altinstr_replacement,"ax"
 | 
			
		||||
143:
 | 
			
		||||
	\newinstr
 | 
			
		||||
144:
 | 
			
		||||
	.popsection
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
#define old_len			141b-140b
 | 
			
		||||
#define new_len1		144f-143f
 | 
			
		||||
#define new_len2		145f-144f
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * gas compatible max based on the idea from:
 | 
			
		||||
 * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
 | 
			
		||||
 *
 | 
			
		||||
 * The additional "-" is needed because gas uses a "true" value of -1.
 | 
			
		||||
 */
 | 
			
		||||
#define alt_max_short(a, b)	((a) ^ (((a) ^ (b)) & -(-((a) < (b)))))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Same as ALTERNATIVE macro above but for two alternatives. If CPU
 | 
			
		||||
 * has @feature1, it replaces @oldinstr with @newinstr1. If CPU has
 | 
			
		||||
 * @feature2, it replaces @oldinstr with @feature2.
 | 
			
		||||
 */
 | 
			
		||||
.macro ALTERNATIVE_2 oldinstr, newinstr1, feature1, newinstr2, feature2
 | 
			
		||||
140:
 | 
			
		||||
	\oldinstr
 | 
			
		||||
141:
 | 
			
		||||
	.skip -((alt_max_short(new_len1, new_len2) - (old_len)) > 0) * \
 | 
			
		||||
		(alt_max_short(new_len1, new_len2) - (old_len)),0x90
 | 
			
		||||
142:
 | 
			
		||||
 | 
			
		||||
	.pushsection .altinstructions,"a"
 | 
			
		||||
	altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f,142b-141b
 | 
			
		||||
	altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f,142b-141b
 | 
			
		||||
	.popsection
 | 
			
		||||
 | 
			
		||||
	.pushsection .altinstr_replacement,"ax"
 | 
			
		||||
143:
 | 
			
		||||
	\newinstr1
 | 
			
		||||
144:
 | 
			
		||||
	\newinstr2
 | 
			
		||||
145:
 | 
			
		||||
	.popsection
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
#endif  /*  __ASSEMBLY__  */
 | 
			
		||||
 | 
			
		||||
#endif /* _ASM_X86_ALTERNATIVE_ASM_H */
 | 
			
		||||
| 
						 | 
				
			
			@ -2,13 +2,14 @@
 | 
			
		|||
#ifndef _ASM_X86_ALTERNATIVE_H
 | 
			
		||||
#define _ASM_X86_ALTERNATIVE_H
 | 
			
		||||
 | 
			
		||||
#ifndef __ASSEMBLY__
 | 
			
		||||
 | 
			
		||||
#include <linux/types.h>
 | 
			
		||||
#include <linux/stddef.h>
 | 
			
		||||
#include <linux/stringify.h>
 | 
			
		||||
#include <asm/asm.h>
 | 
			
		||||
 | 
			
		||||
#ifndef __ASSEMBLY__
 | 
			
		||||
 | 
			
		||||
#include <linux/stddef.h>
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Alternative inline assembly for SMP.
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -271,6 +272,111 @@ static inline int alternatives_text_reserved(void *start, void *end)
 | 
			
		|||
 */
 | 
			
		||||
#define ASM_NO_INPUT_CLOBBER(clbr...) "i" (0) : clbr
 | 
			
		||||
 | 
			
		||||
#else /* __ASSEMBLY__ */
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_SMP
 | 
			
		||||
	.macro LOCK_PREFIX
 | 
			
		||||
672:	lock
 | 
			
		||||
	.pushsection .smp_locks,"a"
 | 
			
		||||
	.balign 4
 | 
			
		||||
	.long 672b - .
 | 
			
		||||
	.popsection
 | 
			
		||||
	.endm
 | 
			
		||||
#else
 | 
			
		||||
	.macro LOCK_PREFIX
 | 
			
		||||
	.endm
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * objtool annotation to ignore the alternatives and only consider the original
 | 
			
		||||
 * instruction(s).
 | 
			
		||||
 */
 | 
			
		||||
.macro ANNOTATE_IGNORE_ALTERNATIVE
 | 
			
		||||
	.Lannotate_\@:
 | 
			
		||||
	.pushsection .discard.ignore_alts
 | 
			
		||||
	.long .Lannotate_\@ - .
 | 
			
		||||
	.popsection
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Issue one struct alt_instr descriptor entry (need to put it into
 | 
			
		||||
 * the section .altinstructions, see below). This entry contains
 | 
			
		||||
 * enough information for the alternatives patching code to patch an
 | 
			
		||||
 * instruction. See apply_alternatives().
 | 
			
		||||
 */
 | 
			
		||||
.macro altinstruction_entry orig alt feature orig_len alt_len pad_len
 | 
			
		||||
	.long \orig - .
 | 
			
		||||
	.long \alt - .
 | 
			
		||||
	.word \feature
 | 
			
		||||
	.byte \orig_len
 | 
			
		||||
	.byte \alt_len
 | 
			
		||||
	.byte \pad_len
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Define an alternative between two instructions. If @feature is
 | 
			
		||||
 * present, early code in apply_alternatives() replaces @oldinstr with
 | 
			
		||||
 * @newinstr. ".skip" directive takes care of proper instruction padding
 | 
			
		||||
 * in case @newinstr is longer than @oldinstr.
 | 
			
		||||
 */
 | 
			
		||||
.macro ALTERNATIVE oldinstr, newinstr, feature
 | 
			
		||||
140:
 | 
			
		||||
	\oldinstr
 | 
			
		||||
141:
 | 
			
		||||
	.skip -(((144f-143f)-(141b-140b)) > 0) * ((144f-143f)-(141b-140b)),0x90
 | 
			
		||||
142:
 | 
			
		||||
 | 
			
		||||
	.pushsection .altinstructions,"a"
 | 
			
		||||
	altinstruction_entry 140b,143f,\feature,142b-140b,144f-143f,142b-141b
 | 
			
		||||
	.popsection
 | 
			
		||||
 | 
			
		||||
	.pushsection .altinstr_replacement,"ax"
 | 
			
		||||
143:
 | 
			
		||||
	\newinstr
 | 
			
		||||
144:
 | 
			
		||||
	.popsection
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
#define old_len			141b-140b
 | 
			
		||||
#define new_len1		144f-143f
 | 
			
		||||
#define new_len2		145f-144f
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * gas compatible max based on the idea from:
 | 
			
		||||
 * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
 | 
			
		||||
 *
 | 
			
		||||
 * The additional "-" is needed because gas uses a "true" value of -1.
 | 
			
		||||
 */
 | 
			
		||||
#define alt_max_short(a, b)	((a) ^ (((a) ^ (b)) & -(-((a) < (b)))))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Same as ALTERNATIVE macro above but for two alternatives. If CPU
 | 
			
		||||
 * has @feature1, it replaces @oldinstr with @newinstr1. If CPU has
 | 
			
		||||
 * @feature2, it replaces @oldinstr with @feature2.
 | 
			
		||||
 */
 | 
			
		||||
.macro ALTERNATIVE_2 oldinstr, newinstr1, feature1, newinstr2, feature2
 | 
			
		||||
140:
 | 
			
		||||
	\oldinstr
 | 
			
		||||
141:
 | 
			
		||||
	.skip -((alt_max_short(new_len1, new_len2) - (old_len)) > 0) * \
 | 
			
		||||
		(alt_max_short(new_len1, new_len2) - (old_len)),0x90
 | 
			
		||||
142:
 | 
			
		||||
 | 
			
		||||
	.pushsection .altinstructions,"a"
 | 
			
		||||
	altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f,142b-141b
 | 
			
		||||
	altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f,142b-141b
 | 
			
		||||
	.popsection
 | 
			
		||||
 | 
			
		||||
	.pushsection .altinstr_replacement,"ax"
 | 
			
		||||
143:
 | 
			
		||||
	\newinstr1
 | 
			
		||||
144:
 | 
			
		||||
	\newinstr2
 | 
			
		||||
145:
 | 
			
		||||
	.popsection
 | 
			
		||||
.endm
 | 
			
		||||
 | 
			
		||||
#endif /* __ASSEMBLY__ */
 | 
			
		||||
 | 
			
		||||
#endif /* _ASM_X86_ALTERNATIVE_H */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,6 @@
 | 
			
		|||
#include <linux/objtool.h>
 | 
			
		||||
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/cpufeatures.h>
 | 
			
		||||
#include <asm/msr-index.h>
 | 
			
		||||
#include <asm/unwind_hints.h>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,6 +11,7 @@
 | 
			
		|||
 | 
			
		||||
#include <asm/nops.h>
 | 
			
		||||
#include <asm/cpufeatures.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
 | 
			
		||||
/* "Raw" instruction opcodes */
 | 
			
		||||
#define __ASM_CLAC	".byte 0x0f,0x01,0xca"
 | 
			
		||||
| 
						 | 
				
			
			@ -18,8 +19,6 @@
 | 
			
		|||
 | 
			
		||||
#ifdef __ASSEMBLY__
 | 
			
		||||
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_X86_SMAP
 | 
			
		||||
 | 
			
		||||
#define ASM_CLAC \
 | 
			
		||||
| 
						 | 
				
			
			@ -37,8 +36,6 @@
 | 
			
		|||
 | 
			
		||||
#else /* __ASSEMBLY__ */
 | 
			
		||||
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_X86_SMAP
 | 
			
		||||
 | 
			
		||||
static __always_inline void clac(void)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@
 | 
			
		|||
 */
 | 
			
		||||
 | 
			
		||||
#include <linux/linkage.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
 | 
			
		||||
/* if you want SMP support, implement these with real spinlocks */
 | 
			
		||||
.macro LOCK reg
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@
 | 
			
		|||
 */
 | 
			
		||||
 | 
			
		||||
#include <linux/linkage.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
 | 
			
		||||
.macro read64 reg
 | 
			
		||||
	movl %ebx, %eax
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
 | 
			
		||||
#include <linux/linkage.h>
 | 
			
		||||
#include <asm/cpufeatures.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
#include <asm/export.h>
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,7 @@
 | 
			
		|||
#include <asm/asm-offsets.h>
 | 
			
		||||
#include <asm/thread_info.h>
 | 
			
		||||
#include <asm/cpufeatures.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
#include <asm/asm.h>
 | 
			
		||||
#include <asm/smap.h>
 | 
			
		||||
#include <asm/export.h>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,7 @@
 | 
			
		|||
#include <linux/linkage.h>
 | 
			
		||||
#include <asm/errno.h>
 | 
			
		||||
#include <asm/cpufeatures.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
#include <asm/export.h>
 | 
			
		||||
 | 
			
		||||
.pushsection .noinstr.text, "ax"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@
 | 
			
		|||
 */
 | 
			
		||||
#include <linux/linkage.h>
 | 
			
		||||
#include <asm/cpufeatures.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
#include <asm/export.h>
 | 
			
		||||
 | 
			
		||||
#undef memmove
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
 | 
			
		||||
#include <linux/linkage.h>
 | 
			
		||||
#include <asm/cpufeatures.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
#include <asm/export.h>
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,7 @@
 | 
			
		|||
#include <linux/linkage.h>
 | 
			
		||||
#include <asm/dwarf2.h>
 | 
			
		||||
#include <asm/cpufeatures.h>
 | 
			
		||||
#include <asm/alternative-asm.h>
 | 
			
		||||
#include <asm/alternative.h>
 | 
			
		||||
#include <asm/export.h>
 | 
			
		||||
#include <asm/nospec-branch.h>
 | 
			
		||||
#include <asm/unwind_hints.h>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue