| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Supervisor Mode Access Prevention support |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2012 Intel Corporation |
|---|
| 5 | 6 | * Author: H. Peter Anvin <hpa@linux.intel.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or |
|---|
| 8 | | - * modify it under the terms of the GNU General Public License |
|---|
| 9 | | - * as published by the Free Software Foundation; version 2 |
|---|
| 10 | | - * of the License. |
|---|
| 11 | 7 | */ |
|---|
| 12 | 8 | |
|---|
| 13 | 9 | #ifndef _ASM_X86_SMAP_H |
|---|
| 14 | 10 | #define _ASM_X86_SMAP_H |
|---|
| 15 | 11 | |
|---|
| 16 | | -#include <linux/stringify.h> |
|---|
| 17 | 12 | #include <asm/nops.h> |
|---|
| 18 | 13 | #include <asm/cpufeatures.h> |
|---|
| 14 | +#include <asm/alternative.h> |
|---|
| 19 | 15 | |
|---|
| 20 | 16 | /* "Raw" instruction opcodes */ |
|---|
| 21 | | -#define __ASM_CLAC .byte 0x0f,0x01,0xca |
|---|
| 22 | | -#define __ASM_STAC .byte 0x0f,0x01,0xcb |
|---|
| 17 | +#define __ASM_CLAC ".byte 0x0f,0x01,0xca" |
|---|
| 18 | +#define __ASM_STAC ".byte 0x0f,0x01,0xcb" |
|---|
| 23 | 19 | |
|---|
| 24 | 20 | #ifdef __ASSEMBLY__ |
|---|
| 25 | | - |
|---|
| 26 | | -#include <asm/alternative-asm.h> |
|---|
| 27 | 21 | |
|---|
| 28 | 22 | #ifdef CONFIG_X86_SMAP |
|---|
| 29 | 23 | |
|---|
| 30 | 24 | #define ASM_CLAC \ |
|---|
| 31 | | - ALTERNATIVE "", __stringify(__ASM_CLAC), X86_FEATURE_SMAP |
|---|
| 25 | + ALTERNATIVE "", __ASM_CLAC, X86_FEATURE_SMAP |
|---|
| 32 | 26 | |
|---|
| 33 | 27 | #define ASM_STAC \ |
|---|
| 34 | | - ALTERNATIVE "", __stringify(__ASM_STAC), X86_FEATURE_SMAP |
|---|
| 28 | + ALTERNATIVE "", __ASM_STAC, X86_FEATURE_SMAP |
|---|
| 35 | 29 | |
|---|
| 36 | 30 | #else /* CONFIG_X86_SMAP */ |
|---|
| 37 | 31 | |
|---|
| .. | .. |
|---|
| 42 | 36 | |
|---|
| 43 | 37 | #else /* __ASSEMBLY__ */ |
|---|
| 44 | 38 | |
|---|
| 45 | | -#include <asm/alternative.h> |
|---|
| 46 | | - |
|---|
| 47 | 39 | #ifdef CONFIG_X86_SMAP |
|---|
| 48 | 40 | |
|---|
| 49 | 41 | static __always_inline void clac(void) |
|---|
| 50 | 42 | { |
|---|
| 51 | 43 | /* Note: a barrier is implicit in alternative() */ |
|---|
| 52 | | - alternative("", __stringify(__ASM_CLAC), X86_FEATURE_SMAP); |
|---|
| 44 | + alternative("", __ASM_CLAC, X86_FEATURE_SMAP); |
|---|
| 53 | 45 | } |
|---|
| 54 | 46 | |
|---|
| 55 | 47 | static __always_inline void stac(void) |
|---|
| 56 | 48 | { |
|---|
| 57 | 49 | /* Note: a barrier is implicit in alternative() */ |
|---|
| 58 | | - alternative("", __stringify(__ASM_STAC), X86_FEATURE_SMAP); |
|---|
| 50 | + alternative("", __ASM_STAC, X86_FEATURE_SMAP); |
|---|
| 59 | 51 | } |
|---|
| 60 | 52 | |
|---|
| 61 | 53 | static __always_inline unsigned long smap_save(void) |
|---|
| 62 | 54 | { |
|---|
| 63 | 55 | unsigned long flags; |
|---|
| 64 | 56 | |
|---|
| 65 | | - asm volatile (ALTERNATIVE("", "pushf; pop %0; " __stringify(__ASM_CLAC), |
|---|
| 66 | | - X86_FEATURE_SMAP) |
|---|
| 57 | + asm volatile ("# smap_save\n\t" |
|---|
| 58 | + ALTERNATIVE("jmp 1f", "", X86_FEATURE_SMAP) |
|---|
| 59 | + "pushf; pop %0; " __ASM_CLAC "\n\t" |
|---|
| 60 | + "1:" |
|---|
| 67 | 61 | : "=rm" (flags) : : "memory", "cc"); |
|---|
| 68 | 62 | |
|---|
| 69 | 63 | return flags; |
|---|
| .. | .. |
|---|
| 71 | 65 | |
|---|
| 72 | 66 | static __always_inline void smap_restore(unsigned long flags) |
|---|
| 73 | 67 | { |
|---|
| 74 | | - asm volatile (ALTERNATIVE("", "push %0; popf", X86_FEATURE_SMAP) |
|---|
| 68 | + asm volatile ("# smap_restore\n\t" |
|---|
| 69 | + ALTERNATIVE("jmp 1f", "", X86_FEATURE_SMAP) |
|---|
| 70 | + "push %0; popf\n\t" |
|---|
| 71 | + "1:" |
|---|
| 75 | 72 | : : "g" (flags) : "memory", "cc"); |
|---|
| 76 | 73 | } |
|---|
| 77 | 74 | |
|---|
| 78 | 75 | /* These macros can be used in asm() statements */ |
|---|
| 79 | 76 | #define ASM_CLAC \ |
|---|
| 80 | | - ALTERNATIVE("", __stringify(__ASM_CLAC), X86_FEATURE_SMAP) |
|---|
| 77 | + ALTERNATIVE("", __ASM_CLAC, X86_FEATURE_SMAP) |
|---|
| 81 | 78 | #define ASM_STAC \ |
|---|
| 82 | | - ALTERNATIVE("", __stringify(__ASM_STAC), X86_FEATURE_SMAP) |
|---|
| 79 | + ALTERNATIVE("", __ASM_STAC, X86_FEATURE_SMAP) |
|---|
| 83 | 80 | |
|---|
| 84 | 81 | #else /* CONFIG_X86_SMAP */ |
|---|
| 85 | 82 | |
|---|