Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'kvmarm-5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into HEAD

KVM/arm64 updates for Linux 5.11

- PSCI relay at EL2 when "protected KVM" is enabled
- New exception injection code
- Simplification of AArch32 system register handling
- Fix PMU accesses when no PMU is enabled
- Expose CSV3 on non-Meltdown hosts
- Cache hierarchy discovery fixes
- PV steal-time cleanups
- Allow function pointers at EL2
- Various host EL2 entry cleanups
- Simplification of the EL2 vector allocation

+4341 -3274
+4 -1
.mailmap
··· 82 82 Dengcheng Zhu <dzhu@wavecomp.com> <dengcheng.zhu@imgtec.com> 83 83 Dengcheng Zhu <dzhu@wavecomp.com> <dengcheng.zhu@mips.com> 84 84 <dev.kurt@vandijck-laurijssen.be> <kurt.van.dijck@eia.be> 85 - Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 85 + Dmitry Baryshkov <dbaryshkov@gmail.com> 86 + Dmitry Baryshkov <dbaryshkov@gmail.com> <[dbaryshkov@gmail.com]> 87 + Dmitry Baryshkov <dbaryshkov@gmail.com> <dmitry_baryshkov@mentor.com> 88 + Dmitry Baryshkov <dbaryshkov@gmail.com> <dmitry_eremin@mentor.com> 86 89 Dmitry Safonov <0x7f454c46@gmail.com> <dima@arista.com> 87 90 Dmitry Safonov <0x7f454c46@gmail.com> <d.safonov@partner.samsung.com> 88 91 Dmitry Safonov <0x7f454c46@gmail.com> <dsafonov@virtuozzo.com>
+10
Documentation/admin-guide/kernel-parameters.txt
··· 2259 2259 for all guests. 2260 2260 Default is 1 (enabled) if in 64-bit or 32-bit PAE mode. 2261 2261 2262 + kvm-arm.mode= 2263 + [KVM,ARM] Select one of KVM/arm64's modes of operation. 2264 + 2265 + protected: nVHE-based mode with support for guests whose 2266 + state is kept private from the host. 2267 + Not valid if the kernel is running in EL2. 2268 + 2269 + Defaults to VHE/nVHE based on hardware support and 2270 + the value of CONFIG_ARM64_VHE. 2271 + 2262 2272 kvm-arm.vgic_v3_group0_trap= 2263 2273 [KVM,ARM] Trap guest accesses to GICv3 group-0 2264 2274 system registers
+1 -1
Documentation/arm64/memory.rst
··· 100 100 random) offset from the linear mapping. See the kern_hyp_va macro and 101 101 kvm_update_va_mask function for more details. MMIO devices such as 102 102 GICv2 gets mapped next to the HYP idmap page, as do vectors when 103 - ARM64_HARDEN_EL2_VECTORS is selected for particular CPUs. 103 + ARM64_SPECTRE_V3A is enabled for particular CPUs. 104 104 105 105 When using KVM with the Virtualization Host Extensions, no additional 106 106 mappings are created, since the host kernel runs directly in EL2.
+1 -1
Documentation/devicetree/bindings/clock/imx5-clock.yaml
··· 57 57 }; 58 58 59 59 can@53fc8000 { 60 - compatible = "fsl,imx53-flexcan", "fsl,p1010-flexcan"; 60 + compatible = "fsl,imx53-flexcan", "fsl,imx25-flexcan"; 61 61 reg = <0x53fc8000 0x4000>; 62 62 interrupts = <82>; 63 63 clocks = <&clks IMX5_CLK_CAN1_IPG_GATE>, <&clks IMX5_CLK_CAN1_SERIAL_GATE>;
+11 -7
Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
··· 20 20 - fsl,imx8qm-flexcan 21 21 - fsl,imx8mp-flexcan 22 22 - fsl,imx6q-flexcan 23 - - fsl,imx53-flexcan 24 - - fsl,imx35-flexcan 25 23 - fsl,imx28-flexcan 26 24 - fsl,imx25-flexcan 27 25 - fsl,p1010-flexcan 28 26 - fsl,vf610-flexcan 29 27 - fsl,ls1021ar2-flexcan 30 28 - fsl,lx2160ar1-flexcan 29 + - items: 30 + - enum: 31 + - fsl,imx53-flexcan 32 + - fsl,imx35-flexcan 33 + - const: fsl,imx25-flexcan 31 34 - items: 32 35 - enum: 33 36 - fsl,imx7d-flexcan ··· 84 81 req_bit is the bit offset of CAN stop request. 85 82 $ref: /schemas/types.yaml#/definitions/phandle-array 86 83 items: 87 - - description: The 'gpr' is the phandle to general purpose register node. 88 - - description: The 'req_gpr' is the gpr register offset of CAN stop request. 89 - maximum: 0xff 90 - - description: The 'req_bit' is the bit offset of CAN stop request. 91 - maximum: 0x1f 84 + items: 85 + - description: The 'gpr' is the phandle to general purpose register node. 86 + - description: The 'req_gpr' is the gpr register offset of CAN stop request. 87 + maximum: 0xff 88 + - description: The 'req_bit' is the bit offset of CAN stop request. 89 + maximum: 0x1f 92 90 93 91 fsl,clk-source: 94 92 description: |
+2 -2
Documentation/virt/kvm/arm/pvtime.rst
··· 19 19 20 20 These are only available in the SMC64/HVC64 calling convention as 21 21 paravirtualized time is not available to 32 bit Arm guests. The existence of 22 - the PV_FEATURES hypercall should be probed using the SMCCC 1.1 ARCH_FEATURES 23 - mechanism before calling it. 22 + the PV_TIME_FEATURES hypercall should be probed using the SMCCC 1.1 23 + ARCH_FEATURES mechanism before calling it. 24 24 25 25 PV_TIME_FEATURES 26 26 ============= ======== ==========
+8
MAINTAINERS
··· 18173 18173 S: Supported 18174 18174 F: drivers/usb/class/usblp.c 18175 18175 18176 + USB RAW GADGET DRIVER 18177 + R: Andrey Konovalov <andreyknvl@gmail.com> 18178 + L: linux-usb@vger.kernel.org 18179 + S: Maintained 18180 + F: Documentation/usb/raw-gadget.rst 18181 + F: drivers/usb/gadget/legacy/raw_gadget.c 18182 + F: include/uapi/linux/usb/raw_gadget.h 18183 + 18176 18184 USB QMI WWAN NETWORK DRIVER 18177 18185 M: Bjørn Mork <bjorn@mork.no> 18178 18186 L: netdev@vger.kernel.org
+1 -1
Makefile
··· 2 2 VERSION = 5 3 3 PATCHLEVEL = 10 4 4 SUBLEVEL = 0 5 - EXTRAVERSION = -rc3 5 + EXTRAVERSION = -rc4 6 6 NAME = Kleptomaniac Octopus 7 7 8 8 # *DOCUMENTATION*
+11 -11
arch/arm/include/asm/kprobes.h
··· 44 44 unsigned long val, void *data); 45 45 46 46 /* optinsn template addresses */ 47 - extern __visible kprobe_opcode_t optprobe_template_entry; 48 - extern __visible kprobe_opcode_t optprobe_template_val; 49 - extern __visible kprobe_opcode_t optprobe_template_call; 50 - extern __visible kprobe_opcode_t optprobe_template_end; 51 - extern __visible kprobe_opcode_t optprobe_template_sub_sp; 52 - extern __visible kprobe_opcode_t optprobe_template_add_sp; 53 - extern __visible kprobe_opcode_t optprobe_template_restore_begin; 54 - extern __visible kprobe_opcode_t optprobe_template_restore_orig_insn; 55 - extern __visible kprobe_opcode_t optprobe_template_restore_end; 47 + extern __visible kprobe_opcode_t optprobe_template_entry[]; 48 + extern __visible kprobe_opcode_t optprobe_template_val[]; 49 + extern __visible kprobe_opcode_t optprobe_template_call[]; 50 + extern __visible kprobe_opcode_t optprobe_template_end[]; 51 + extern __visible kprobe_opcode_t optprobe_template_sub_sp[]; 52 + extern __visible kprobe_opcode_t optprobe_template_add_sp[]; 53 + extern __visible kprobe_opcode_t optprobe_template_restore_begin[]; 54 + extern __visible kprobe_opcode_t optprobe_template_restore_orig_insn[]; 55 + extern __visible kprobe_opcode_t optprobe_template_restore_end[]; 56 56 57 57 #define MAX_OPTIMIZED_LENGTH 4 58 58 #define MAX_OPTINSN_SIZE \ 59 - ((unsigned long)&optprobe_template_end - \ 60 - (unsigned long)&optprobe_template_entry) 59 + ((unsigned long)optprobe_template_end - \ 60 + (unsigned long)optprobe_template_entry) 61 61 #define RELATIVEJUMP_SIZE 4 62 62 63 63 struct arch_optimized_insn {
+1 -2
arch/arm/kernel/perf_regs.c
··· 32 32 } 33 33 34 34 void perf_get_regs_user(struct perf_regs *regs_user, 35 - struct pt_regs *regs, 36 - struct pt_regs *regs_user_copy) 35 + struct pt_regs *regs) 37 36 { 38 37 regs_user->regs = task_pt_regs(current); 39 38 regs_user->abi = perf_reg_abi(current);
+9 -9
arch/arm/probes/kprobes/opt-arm.c
··· 85 85 "optprobe_template_end:\n"); 86 86 87 87 #define TMPL_VAL_IDX \ 88 - ((unsigned long *)&optprobe_template_val - (unsigned long *)&optprobe_template_entry) 88 + ((unsigned long *)optprobe_template_val - (unsigned long *)optprobe_template_entry) 89 89 #define TMPL_CALL_IDX \ 90 - ((unsigned long *)&optprobe_template_call - (unsigned long *)&optprobe_template_entry) 90 + ((unsigned long *)optprobe_template_call - (unsigned long *)optprobe_template_entry) 91 91 #define TMPL_END_IDX \ 92 - ((unsigned long *)&optprobe_template_end - (unsigned long *)&optprobe_template_entry) 92 + ((unsigned long *)optprobe_template_end - (unsigned long *)optprobe_template_entry) 93 93 #define TMPL_ADD_SP \ 94 - ((unsigned long *)&optprobe_template_add_sp - (unsigned long *)&optprobe_template_entry) 94 + ((unsigned long *)optprobe_template_add_sp - (unsigned long *)optprobe_template_entry) 95 95 #define TMPL_SUB_SP \ 96 - ((unsigned long *)&optprobe_template_sub_sp - (unsigned long *)&optprobe_template_entry) 96 + ((unsigned long *)optprobe_template_sub_sp - (unsigned long *)optprobe_template_entry) 97 97 #define TMPL_RESTORE_BEGIN \ 98 - ((unsigned long *)&optprobe_template_restore_begin - (unsigned long *)&optprobe_template_entry) 98 + ((unsigned long *)optprobe_template_restore_begin - (unsigned long *)optprobe_template_entry) 99 99 #define TMPL_RESTORE_ORIGN_INSN \ 100 - ((unsigned long *)&optprobe_template_restore_orig_insn - (unsigned long *)&optprobe_template_entry) 100 + ((unsigned long *)optprobe_template_restore_orig_insn - (unsigned long *)optprobe_template_entry) 101 101 #define TMPL_RESTORE_END \ 102 - ((unsigned long *)&optprobe_template_restore_end - (unsigned long *)&optprobe_template_entry) 102 + ((unsigned long *)optprobe_template_restore_end - (unsigned long *)optprobe_template_entry) 103 103 104 104 /* 105 105 * ARM can always optimize an instruction when using ARM ISA, except ··· 234 234 } 235 235 236 236 /* Copy arch-dep-instance from template. */ 237 - memcpy(code, (unsigned long *)&optprobe_template_entry, 237 + memcpy(code, (unsigned long *)optprobe_template_entry, 238 238 TMPL_END_IDX * sizeof(kprobe_opcode_t)); 239 239 240 240 /* Adjust buffer according to instruction. */
+3 -22
arch/arm64/Kconfig
··· 195 195 select PCI_SYSCALL if PCI 196 196 select POWER_RESET 197 197 select POWER_SUPPLY 198 - select SET_FS 199 198 select SPARSE_IRQ 200 199 select SWIOTLB 201 200 select SYSCTL_EXCEPTION_TRACE ··· 1387 1388 The feature is detected at runtime, and will remain as a 'nop' 1388 1389 instruction if the cpu does not implement the feature. 1389 1390 1391 + config AS_HAS_LDAPR 1392 + def_bool $(as-instr,.arch_extension rcpc) 1393 + 1390 1394 config ARM64_LSE_ATOMICS 1391 1395 bool 1392 1396 default ARM64_USE_LSE_ATOMICS ··· 1426 1424 endmenu 1427 1425 1428 1426 menu "ARMv8.2 architectural features" 1429 - 1430 - config ARM64_UAO 1431 - bool "Enable support for User Access Override (UAO)" 1432 - default y 1433 - help 1434 - User Access Override (UAO; part of the ARMv8.2 Extensions) 1435 - causes the 'unprivileged' variant of the load/store instructions to 1436 - be overridden to be privileged. 1437 - 1438 - This option changes get_user() and friends to use the 'unprivileged' 1439 - variant of the load/store instructions. This ensures that user-space 1440 - really did have access to the supplied memory. When addr_limit is 1441 - set to kernel memory the UAO bit will be set, allowing privileged 1442 - access to kernel memory. 1443 - 1444 - Choosing this option will cause copy_to_user() et al to use user-space 1445 - memory permissions. 1446 - 1447 - The feature is detected at runtime, the kernel will use the 1448 - regular load/store instructions if the cpu does not implement the 1449 - feature. 1450 1427 1451 1428 config ARM64_PMEM 1452 1429 bool "Enable support for persistent memory"
+217
arch/arm64/include/asm/alternative-macros.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __ASM_ALTERNATIVE_MACROS_H 3 + #define __ASM_ALTERNATIVE_MACROS_H 4 + 5 + #include <asm/cpucaps.h> 6 + 7 + #define ARM64_CB_PATCH ARM64_NCAPS 8 + 9 + /* A64 instructions are always 32 bits. */ 10 + #define AARCH64_INSN_SIZE 4 11 + 12 + #ifndef __ASSEMBLY__ 13 + 14 + #include <linux/stringify.h> 15 + 16 + #define ALTINSTR_ENTRY(feature) \ 17 + " .word 661b - .\n" /* label */ \ 18 + " .word 663f - .\n" /* new instruction */ \ 19 + " .hword " __stringify(feature) "\n" /* feature bit */ \ 20 + " .byte 662b-661b\n" /* source len */ \ 21 + " .byte 664f-663f\n" /* replacement len */ 22 + 23 + #define ALTINSTR_ENTRY_CB(feature, cb) \ 24 + " .word 661b - .\n" /* label */ \ 25 + " .word " __stringify(cb) "- .\n" /* callback */ \ 26 + " .hword " __stringify(feature) "\n" /* feature bit */ \ 27 + " .byte 662b-661b\n" /* source len */ \ 28 + " .byte 664f-663f\n" /* replacement len */ 29 + 30 + /* 31 + * alternative assembly primitive: 32 + * 33 + * If any of these .org directive fail, it means that insn1 and insn2 34 + * don't have the same length. This used to be written as 35 + * 36 + * .if ((664b-663b) != (662b-661b)) 37 + * .error "Alternatives instruction length mismatch" 38 + * .endif 39 + * 40 + * but most assemblers die if insn1 or insn2 have a .inst. This should 41 + * be fixed in a binutils release posterior to 2.25.51.0.2 (anything 42 + * containing commit 4e4d08cf7399b606 or c1baaddf8861). 43 + * 44 + * Alternatives with callbacks do not generate replacement instructions. 45 + */ 46 + #define __ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg_enabled) \ 47 + ".if "__stringify(cfg_enabled)" == 1\n" \ 48 + "661:\n\t" \ 49 + oldinstr "\n" \ 50 + "662:\n" \ 51 + ".pushsection .altinstructions,\"a\"\n" \ 52 + ALTINSTR_ENTRY(feature) \ 53 + ".popsection\n" \ 54 + ".subsection 1\n" \ 55 + "663:\n\t" \ 56 + newinstr "\n" \ 57 + "664:\n\t" \ 58 + ".org . - (664b-663b) + (662b-661b)\n\t" \ 59 + ".org . - (662b-661b) + (664b-663b)\n\t" \ 60 + ".previous\n" \ 61 + ".endif\n" 62 + 63 + #define __ALTERNATIVE_CFG_CB(oldinstr, feature, cfg_enabled, cb) \ 64 + ".if "__stringify(cfg_enabled)" == 1\n" \ 65 + "661:\n\t" \ 66 + oldinstr "\n" \ 67 + "662:\n" \ 68 + ".pushsection .altinstructions,\"a\"\n" \ 69 + ALTINSTR_ENTRY_CB(feature, cb) \ 70 + ".popsection\n" \ 71 + "663:\n\t" \ 72 + "664:\n\t" \ 73 + ".endif\n" 74 + 75 + #define _ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg, ...) \ 76 + __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg)) 77 + 78 + #define ALTERNATIVE_CB(oldinstr, cb) \ 79 + __ALTERNATIVE_CFG_CB(oldinstr, ARM64_CB_PATCH, 1, cb) 80 + #else 81 + 82 + #include <asm/assembler.h> 83 + 84 + .macro altinstruction_entry orig_offset alt_offset feature orig_len alt_len 85 + .word \orig_offset - . 86 + .word \alt_offset - . 87 + .hword \feature 88 + .byte \orig_len 89 + .byte \alt_len 90 + .endm 91 + 92 + .macro alternative_insn insn1, insn2, cap, enable = 1 93 + .if \enable 94 + 661: \insn1 95 + 662: .pushsection .altinstructions, "a" 96 + altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f 97 + .popsection 98 + .subsection 1 99 + 663: \insn2 100 + 664: .previous 101 + .org . - (664b-663b) + (662b-661b) 102 + .org . - (662b-661b) + (664b-663b) 103 + .endif 104 + .endm 105 + 106 + /* 107 + * Alternative sequences 108 + * 109 + * The code for the case where the capability is not present will be 110 + * assembled and linked as normal. There are no restrictions on this 111 + * code. 112 + * 113 + * The code for the case where the capability is present will be 114 + * assembled into a special section to be used for dynamic patching. 115 + * Code for that case must: 116 + * 117 + * 1. Be exactly the same length (in bytes) as the default code 118 + * sequence. 119 + * 120 + * 2. Not contain a branch target that is used outside of the 121 + * alternative sequence it is defined in (branches into an 122 + * alternative sequence are not fixed up). 123 + */ 124 + 125 + /* 126 + * Begin an alternative code sequence. 127 + */ 128 + .macro alternative_if_not cap 129 + .set .Lasm_alt_mode, 0 130 + .pushsection .altinstructions, "a" 131 + altinstruction_entry 661f, 663f, \cap, 662f-661f, 664f-663f 132 + .popsection 133 + 661: 134 + .endm 135 + 136 + .macro alternative_if cap 137 + .set .Lasm_alt_mode, 1 138 + .pushsection .altinstructions, "a" 139 + altinstruction_entry 663f, 661f, \cap, 664f-663f, 662f-661f 140 + .popsection 141 + .subsection 1 142 + .align 2 /* So GAS knows label 661 is suitably aligned */ 143 + 661: 144 + .endm 145 + 146 + .macro alternative_cb cb 147 + .set .Lasm_alt_mode, 0 148 + .pushsection .altinstructions, "a" 149 + altinstruction_entry 661f, \cb, ARM64_CB_PATCH, 662f-661f, 0 150 + .popsection 151 + 661: 152 + .endm 153 + 154 + /* 155 + * Provide the other half of the alternative code sequence. 156 + */ 157 + .macro alternative_else 158 + 662: 159 + .if .Lasm_alt_mode==0 160 + .subsection 1 161 + .else 162 + .previous 163 + .endif 164 + 663: 165 + .endm 166 + 167 + /* 168 + * Complete an alternative code sequence. 169 + */ 170 + .macro alternative_endif 171 + 664: 172 + .if .Lasm_alt_mode==0 173 + .previous 174 + .endif 175 + .org . - (664b-663b) + (662b-661b) 176 + .org . - (662b-661b) + (664b-663b) 177 + .endm 178 + 179 + /* 180 + * Callback-based alternative epilogue 181 + */ 182 + .macro alternative_cb_end 183 + 662: 184 + .endm 185 + 186 + /* 187 + * Provides a trivial alternative or default sequence consisting solely 188 + * of NOPs. The number of NOPs is chosen automatically to match the 189 + * previous case. 190 + */ 191 + .macro alternative_else_nop_endif 192 + alternative_else 193 + nops (662b-661b) / AARCH64_INSN_SIZE 194 + alternative_endif 195 + .endm 196 + 197 + #define _ALTERNATIVE_CFG(insn1, insn2, cap, cfg, ...) \ 198 + alternative_insn insn1, insn2, cap, IS_ENABLED(cfg) 199 + 200 + .macro user_alt, label, oldinstr, newinstr, cond 201 + 9999: alternative_insn "\oldinstr", "\newinstr", \cond 202 + _asm_extable 9999b, \label 203 + .endm 204 + 205 + #endif /* __ASSEMBLY__ */ 206 + 207 + /* 208 + * Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature)); 209 + * 210 + * Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature, CONFIG_FOO)); 211 + * N.B. If CONFIG_FOO is specified, but not selected, the whole block 212 + * will be omitted, including oldinstr. 213 + */ 214 + #define ALTERNATIVE(oldinstr, newinstr, ...) \ 215 + _ALTERNATIVE_CFG(oldinstr, newinstr, __VA_ARGS__, 1) 216 + 217 + #endif /* __ASM_ALTERNATIVE_MACROS_H */
+2 -265
arch/arm64/include/asm/alternative.h
··· 2 2 #ifndef __ASM_ALTERNATIVE_H 3 3 #define __ASM_ALTERNATIVE_H 4 4 5 - #include <asm/cpucaps.h> 6 - #include <asm/insn.h> 7 - 8 - #define ARM64_CB_PATCH ARM64_NCAPS 5 + #include <asm/alternative-macros.h> 9 6 10 7 #ifndef __ASSEMBLY__ 11 8 12 9 #include <linux/init.h> 13 10 #include <linux/types.h> 14 11 #include <linux/stddef.h> 15 - #include <linux/stringify.h> 16 12 17 13 struct alt_instr { 18 14 s32 orig_offset; /* offset to original instruction */ ··· 31 35 static inline void apply_alternatives_module(void *start, size_t length) { } 32 36 #endif 33 37 34 - #define ALTINSTR_ENTRY(feature) \ 35 - " .word 661b - .\n" /* label */ \ 36 - " .word 663f - .\n" /* new instruction */ \ 37 - " .hword " __stringify(feature) "\n" /* feature bit */ \ 38 - " .byte 662b-661b\n" /* source len */ \ 39 - " .byte 664f-663f\n" /* replacement len */ 40 - 41 - #define ALTINSTR_ENTRY_CB(feature, cb) \ 42 - " .word 661b - .\n" /* label */ \ 43 - " .word " __stringify(cb) "- .\n" /* callback */ \ 44 - " .hword " __stringify(feature) "\n" /* feature bit */ \ 45 - " .byte 662b-661b\n" /* source len */ \ 46 - " .byte 664f-663f\n" /* replacement len */ 47 - 48 - /* 49 - * alternative assembly primitive: 50 - * 51 - * If any of these .org directive fail, it means that insn1 and insn2 52 - * don't have the same length. This used to be written as 53 - * 54 - * .if ((664b-663b) != (662b-661b)) 55 - * .error "Alternatives instruction length mismatch" 56 - * .endif 57 - * 58 - * but most assemblers die if insn1 or insn2 have a .inst. This should 59 - * be fixed in a binutils release posterior to 2.25.51.0.2 (anything 60 - * containing commit 4e4d08cf7399b606 or c1baaddf8861). 61 - * 62 - * Alternatives with callbacks do not generate replacement instructions. 63 - */ 64 - #define __ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg_enabled) \ 65 - ".if "__stringify(cfg_enabled)" == 1\n" \ 66 - "661:\n\t" \ 67 - oldinstr "\n" \ 68 - "662:\n" \ 69 - ".pushsection .altinstructions,\"a\"\n" \ 70 - ALTINSTR_ENTRY(feature) \ 71 - ".popsection\n" \ 72 - ".subsection 1\n" \ 73 - "663:\n\t" \ 74 - newinstr "\n" \ 75 - "664:\n\t" \ 76 - ".org . - (664b-663b) + (662b-661b)\n\t" \ 77 - ".org . - (662b-661b) + (664b-663b)\n\t" \ 78 - ".previous\n" \ 79 - ".endif\n" 80 - 81 - #define __ALTERNATIVE_CFG_CB(oldinstr, feature, cfg_enabled, cb) \ 82 - ".if "__stringify(cfg_enabled)" == 1\n" \ 83 - "661:\n\t" \ 84 - oldinstr "\n" \ 85 - "662:\n" \ 86 - ".pushsection .altinstructions,\"a\"\n" \ 87 - ALTINSTR_ENTRY_CB(feature, cb) \ 88 - ".popsection\n" \ 89 - "663:\n\t" \ 90 - "664:\n\t" \ 91 - ".endif\n" 92 - 93 - #define _ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg, ...) \ 94 - __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg)) 95 - 96 - #define ALTERNATIVE_CB(oldinstr, cb) \ 97 - __ALTERNATIVE_CFG_CB(oldinstr, ARM64_CB_PATCH, 1, cb) 98 - #else 99 - 100 - #include <asm/assembler.h> 101 - 102 - .macro altinstruction_entry orig_offset alt_offset feature orig_len alt_len 103 - .word \orig_offset - . 104 - .word \alt_offset - . 105 - .hword \feature 106 - .byte \orig_len 107 - .byte \alt_len 108 - .endm 109 - 110 - .macro alternative_insn insn1, insn2, cap, enable = 1 111 - .if \enable 112 - 661: \insn1 113 - 662: .pushsection .altinstructions, "a" 114 - altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f 115 - .popsection 116 - .subsection 1 117 - 663: \insn2 118 - 664: .previous 119 - .org . - (664b-663b) + (662b-661b) 120 - .org . - (662b-661b) + (664b-663b) 121 - .endif 122 - .endm 123 - 124 - /* 125 - * Alternative sequences 126 - * 127 - * The code for the case where the capability is not present will be 128 - * assembled and linked as normal. There are no restrictions on this 129 - * code. 130 - * 131 - * The code for the case where the capability is present will be 132 - * assembled into a special section to be used for dynamic patching. 133 - * Code for that case must: 134 - * 135 - * 1. Be exactly the same length (in bytes) as the default code 136 - * sequence. 137 - * 138 - * 2. Not contain a branch target that is used outside of the 139 - * alternative sequence it is defined in (branches into an 140 - * alternative sequence are not fixed up). 141 - */ 142 - 143 - /* 144 - * Begin an alternative code sequence. 145 - */ 146 - .macro alternative_if_not cap 147 - .set .Lasm_alt_mode, 0 148 - .pushsection .altinstructions, "a" 149 - altinstruction_entry 661f, 663f, \cap, 662f-661f, 664f-663f 150 - .popsection 151 - 661: 152 - .endm 153 - 154 - .macro alternative_if cap 155 - .set .Lasm_alt_mode, 1 156 - .pushsection .altinstructions, "a" 157 - altinstruction_entry 663f, 661f, \cap, 664f-663f, 662f-661f 158 - .popsection 159 - .subsection 1 160 - .align 2 /* So GAS knows label 661 is suitably aligned */ 161 - 661: 162 - .endm 163 - 164 - .macro alternative_cb cb 165 - .set .Lasm_alt_mode, 0 166 - .pushsection .altinstructions, "a" 167 - altinstruction_entry 661f, \cb, ARM64_CB_PATCH, 662f-661f, 0 168 - .popsection 169 - 661: 170 - .endm 171 - 172 - /* 173 - * Provide the other half of the alternative code sequence. 174 - */ 175 - .macro alternative_else 176 - 662: 177 - .if .Lasm_alt_mode==0 178 - .subsection 1 179 - .else 180 - .previous 181 - .endif 182 - 663: 183 - .endm 184 - 185 - /* 186 - * Complete an alternative code sequence. 187 - */ 188 - .macro alternative_endif 189 - 664: 190 - .if .Lasm_alt_mode==0 191 - .previous 192 - .endif 193 - .org . - (664b-663b) + (662b-661b) 194 - .org . - (662b-661b) + (664b-663b) 195 - .endm 196 - 197 - /* 198 - * Callback-based alternative epilogue 199 - */ 200 - .macro alternative_cb_end 201 - 662: 202 - .endm 203 - 204 - /* 205 - * Provides a trivial alternative or default sequence consisting solely 206 - * of NOPs. The number of NOPs is chosen automatically to match the 207 - * previous case. 208 - */ 209 - .macro alternative_else_nop_endif 210 - alternative_else 211 - nops (662b-661b) / AARCH64_INSN_SIZE 212 - alternative_endif 213 - .endm 214 - 215 - #define _ALTERNATIVE_CFG(insn1, insn2, cap, cfg, ...) \ 216 - alternative_insn insn1, insn2, cap, IS_ENABLED(cfg) 217 - 218 - .macro user_alt, label, oldinstr, newinstr, cond 219 - 9999: alternative_insn "\oldinstr", "\newinstr", \cond 220 - _asm_extable 9999b, \label 221 - .endm 222 - 223 - /* 224 - * Generate the assembly for UAO alternatives with exception table entries. 225 - * This is complicated as there is no post-increment or pair versions of the 226 - * unprivileged instructions, and USER() only works for single instructions. 227 - */ 228 - #ifdef CONFIG_ARM64_UAO 229 - .macro uao_ldp l, reg1, reg2, addr, post_inc 230 - alternative_if_not ARM64_HAS_UAO 231 - 8888: ldp \reg1, \reg2, [\addr], \post_inc; 232 - 8889: nop; 233 - nop; 234 - alternative_else 235 - ldtr \reg1, [\addr]; 236 - ldtr \reg2, [\addr, #8]; 237 - add \addr, \addr, \post_inc; 238 - alternative_endif 239 - 240 - _asm_extable 8888b,\l; 241 - _asm_extable 8889b,\l; 242 - .endm 243 - 244 - .macro uao_stp l, reg1, reg2, addr, post_inc 245 - alternative_if_not ARM64_HAS_UAO 246 - 8888: stp \reg1, \reg2, [\addr], \post_inc; 247 - 8889: nop; 248 - nop; 249 - alternative_else 250 - sttr \reg1, [\addr]; 251 - sttr \reg2, [\addr, #8]; 252 - add \addr, \addr, \post_inc; 253 - alternative_endif 254 - 255 - _asm_extable 8888b,\l; 256 - _asm_extable 8889b,\l; 257 - .endm 258 - 259 - .macro uao_user_alternative l, inst, alt_inst, reg, addr, post_inc 260 - alternative_if_not ARM64_HAS_UAO 261 - 8888: \inst \reg, [\addr], \post_inc; 262 - nop; 263 - alternative_else 264 - \alt_inst \reg, [\addr]; 265 - add \addr, \addr, \post_inc; 266 - alternative_endif 267 - 268 - _asm_extable 8888b,\l; 269 - .endm 270 - #else 271 - .macro uao_ldp l, reg1, reg2, addr, post_inc 272 - USER(\l, ldp \reg1, \reg2, [\addr], \post_inc) 273 - .endm 274 - .macro uao_stp l, reg1, reg2, addr, post_inc 275 - USER(\l, stp \reg1, \reg2, [\addr], \post_inc) 276 - .endm 277 - .macro uao_user_alternative l, inst, alt_inst, reg, addr, post_inc 278 - USER(\l, \inst \reg, [\addr], \post_inc) 279 - .endm 280 - #endif 281 - 282 - #endif /* __ASSEMBLY__ */ 283 - 284 - /* 285 - * Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature)); 286 - * 287 - * Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature, CONFIG_FOO)); 288 - * N.B. If CONFIG_FOO is specified, but not selected, the whole block 289 - * will be omitted, including oldinstr. 290 - */ 291 - #define ALTERNATIVE(oldinstr, newinstr, ...) \ 292 - _ALTERNATIVE_CFG(oldinstr, newinstr, __VA_ARGS__, 1) 293 - 38 + #endif /* __ASSEMBLY__ */ 294 39 #endif /* __ASM_ALTERNATIVE_H */
+30 -1
arch/arm64/include/asm/asm-uaccess.h
··· 2 2 #ifndef __ASM_ASM_UACCESS_H 3 3 #define __ASM_ASM_UACCESS_H 4 4 5 - #include <asm/alternative.h> 5 + #include <asm/alternative-macros.h> 6 6 #include <asm/kernel-pgtable.h> 7 7 #include <asm/mmu.h> 8 8 #include <asm/sysreg.h> ··· 58 58 .endm 59 59 #endif 60 60 61 + /* 62 + * Generate the assembly for LDTR/STTR with exception table entries. 63 + * This is complicated as there is no post-increment or pair versions of the 64 + * unprivileged instructions, and USER() only works for single instructions. 65 + */ 66 + .macro user_ldp l, reg1, reg2, addr, post_inc 67 + 8888: ldtr \reg1, [\addr]; 68 + 8889: ldtr \reg2, [\addr, #8]; 69 + add \addr, \addr, \post_inc; 70 + 71 + _asm_extable 8888b,\l; 72 + _asm_extable 8889b,\l; 73 + .endm 74 + 75 + .macro user_stp l, reg1, reg2, addr, post_inc 76 + 8888: sttr \reg1, [\addr]; 77 + 8889: sttr \reg2, [\addr, #8]; 78 + add \addr, \addr, \post_inc; 79 + 80 + _asm_extable 8888b,\l; 81 + _asm_extable 8889b,\l; 82 + .endm 83 + 84 + .macro user_ldst l, inst, reg, addr, post_inc 85 + 8888: \inst \reg, [\addr]; 86 + add \addr, \addr, \post_inc; 87 + 88 + _asm_extable 8888b,\l; 89 + .endm 61 90 #endif
+4 -4
arch/arm64/include/asm/cpucaps.h
··· 16 16 #define ARM64_WORKAROUND_CAVIUM_23154 6 17 17 #define ARM64_WORKAROUND_834220 7 18 18 #define ARM64_HAS_NO_HW_PREFETCH 8 19 - #define ARM64_HAS_UAO 9 20 - #define ARM64_ALT_PAN_NOT_UAO 10 21 19 #define ARM64_HAS_VIRT_HOST_EXTN 11 22 20 #define ARM64_WORKAROUND_CAVIUM_27456 12 23 21 #define ARM64_HAS_32BIT_EL0 13 24 - #define ARM64_HARDEN_EL2_VECTORS 14 22 + #define ARM64_SPECTRE_V3A 14 25 23 #define ARM64_HAS_CNP 15 26 24 #define ARM64_HAS_NO_FPSIMD 16 27 25 #define ARM64_WORKAROUND_REPEAT_TLBI 17 ··· 64 66 #define ARM64_HAS_TLB_RANGE 56 65 67 #define ARM64_MTE 57 66 68 #define ARM64_WORKAROUND_1508412 58 69 + #define ARM64_HAS_LDAPR 59 70 + #define ARM64_KVM_PROTECTED_MODE 60 67 71 68 - #define ARM64_NCAPS 59 72 + #define ARM64_NCAPS 61 69 73 70 74 #endif /* __ASM_CPUCAPS_H */
+21 -1
arch/arm64/include/asm/cpufeature.h
··· 268 268 /* 269 269 * CPU feature detected at boot time based on feature of one or more CPUs. 270 270 * All possible conflicts for a late CPU are ignored. 271 + * NOTE: this means that a late CPU with the feature will *not* cause the 272 + * capability to be advertised by cpus_have_*cap()! 271 273 */ 272 274 #define ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE \ 273 275 (ARM64_CPUCAP_SCOPE_LOCAL_CPU | \ ··· 669 667 return !cpus_have_const_cap(ARM64_HAS_NO_FPSIMD); 670 668 } 671 669 670 + static inline bool system_uses_hw_pan(void) 671 + { 672 + return IS_ENABLED(CONFIG_ARM64_PAN) && 673 + cpus_have_const_cap(ARM64_HAS_PAN); 674 + } 675 + 672 676 static inline bool system_uses_ttbr0_pan(void) 673 677 { 674 678 return IS_ENABLED(CONFIG_ARM64_SW_TTBR0_PAN) && 675 - !cpus_have_const_cap(ARM64_HAS_PAN); 679 + !system_uses_hw_pan(); 676 680 } 677 681 678 682 static __always_inline bool system_supports_sve(void) ··· 703 695 { 704 696 return IS_ENABLED(CONFIG_ARM64_PTR_AUTH) && 705 697 cpus_have_const_cap(ARM64_HAS_GENERIC_AUTH); 698 + } 699 + 700 + static inline bool system_has_full_ptr_auth(void) 701 + { 702 + return system_supports_address_auth() && system_supports_generic_auth(); 706 703 } 707 704 708 705 static __always_inline bool system_uses_irq_prio_masking(void) ··· 773 760 mmfr1 = read_cpuid(ID_AA64MMFR1_EL1); 774 761 return cpuid_feature_extract_unsigned_field(mmfr1, 775 762 ID_AA64MMFR1_HADBS_SHIFT); 763 + } 764 + 765 + static inline bool cpu_has_pan(void) 766 + { 767 + u64 mmfr1 = read_cpuid(ID_AA64MMFR1_EL1); 768 + return cpuid_feature_extract_unsigned_field(mmfr1, 769 + ID_AA64MMFR1_PAN_SHIFT); 776 770 } 777 771 778 772 #ifdef CONFIG_ARM64_AMU_EXTN
+4
arch/arm64/include/asm/cputype.h
··· 86 86 #define QCOM_CPU_PART_FALKOR_V1 0x800 87 87 #define QCOM_CPU_PART_FALKOR 0xC00 88 88 #define QCOM_CPU_PART_KRYO 0x200 89 + #define QCOM_CPU_PART_KRYO_2XX_GOLD 0x800 90 + #define QCOM_CPU_PART_KRYO_2XX_SILVER 0x801 89 91 #define QCOM_CPU_PART_KRYO_3XX_SILVER 0x803 90 92 #define QCOM_CPU_PART_KRYO_4XX_GOLD 0x804 91 93 #define QCOM_CPU_PART_KRYO_4XX_SILVER 0x805 ··· 118 116 #define MIDR_QCOM_FALKOR_V1 MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR_V1) 119 117 #define MIDR_QCOM_FALKOR MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR) 120 118 #define MIDR_QCOM_KRYO MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO) 119 + #define MIDR_QCOM_KRYO_2XX_GOLD MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_2XX_GOLD) 120 + #define MIDR_QCOM_KRYO_2XX_SILVER MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_2XX_SILVER) 121 121 #define MIDR_QCOM_KRYO_3XX_SILVER MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_3XX_SILVER) 122 122 #define MIDR_QCOM_KRYO_4XX_GOLD MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_4XX_GOLD) 123 123 #define MIDR_QCOM_KRYO_4XX_SILVER MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_4XX_SILVER)
+181
arch/arm64/include/asm/el2_setup.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (C) 2012,2013 - ARM Ltd 4 + * Author: Marc Zyngier <marc.zyngier@arm.com> 5 + */ 6 + 7 + #ifndef __ARM_KVM_INIT_H__ 8 + #define __ARM_KVM_INIT_H__ 9 + 10 + #ifndef __ASSEMBLY__ 11 + #error Assembly-only header 12 + #endif 13 + 14 + #include <asm/kvm_arm.h> 15 + #include <asm/ptrace.h> 16 + #include <asm/sysreg.h> 17 + #include <linux/irqchip/arm-gic-v3.h> 18 + 19 + .macro __init_el2_sctlr 20 + mov_q x0, INIT_SCTLR_EL2_MMU_OFF 21 + msr sctlr_el2, x0 22 + isb 23 + .endm 24 + 25 + /* 26 + * Allow Non-secure EL1 and EL0 to access physical timer and counter. 27 + * This is not necessary for VHE, since the host kernel runs in EL2, 28 + * and EL0 accesses are configured in the later stage of boot process. 29 + * Note that when HCR_EL2.E2H == 1, CNTHCTL_EL2 has the same bit layout 30 + * as CNTKCTL_EL1, and CNTKCTL_EL1 accessing instructions are redefined 31 + * to access CNTHCTL_EL2. This allows the kernel designed to run at EL1 32 + * to transparently mess with the EL0 bits via CNTKCTL_EL1 access in 33 + * EL2. 34 + */ 35 + .macro __init_el2_timers mode 36 + .ifeqs "\mode", "nvhe" 37 + mrs x0, cnthctl_el2 38 + orr x0, x0, #3 // Enable EL1 physical timers 39 + msr cnthctl_el2, x0 40 + .endif 41 + msr cntvoff_el2, xzr // Clear virtual offset 42 + .endm 43 + 44 + .macro __init_el2_debug mode 45 + mrs x1, id_aa64dfr0_el1 46 + sbfx x0, x1, #ID_AA64DFR0_PMUVER_SHIFT, #4 47 + cmp x0, #1 48 + b.lt 1f // Skip if no PMU present 49 + mrs x0, pmcr_el0 // Disable debug access traps 50 + ubfx x0, x0, #11, #5 // to EL2 and allow access to 51 + 1: 52 + csel x2, xzr, x0, lt // all PMU counters from EL1 53 + 54 + /* Statistical profiling */ 55 + ubfx x0, x1, #ID_AA64DFR0_PMSVER_SHIFT, #4 56 + cbz x0, 3f // Skip if SPE not present 57 + 58 + .ifeqs "\mode", "nvhe" 59 + mrs_s x0, SYS_PMBIDR_EL1 // If SPE available at EL2, 60 + and x0, x0, #(1 << SYS_PMBIDR_EL1_P_SHIFT) 61 + cbnz x0, 2f // then permit sampling of physical 62 + mov x0, #(1 << SYS_PMSCR_EL2_PCT_SHIFT | \ 63 + 1 << SYS_PMSCR_EL2_PA_SHIFT) 64 + msr_s SYS_PMSCR_EL2, x0 // addresses and physical counter 65 + 2: 66 + mov x0, #(MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT) 67 + orr x2, x2, x0 // If we don't have VHE, then 68 + // use EL1&0 translation. 69 + .else 70 + orr x2, x2, #MDCR_EL2_TPMS // For VHE, use EL2 translation 71 + // and disable access from EL1 72 + .endif 73 + 74 + 3: 75 + msr mdcr_el2, x2 // Configure debug traps 76 + .endm 77 + 78 + /* LORegions */ 79 + .macro __init_el2_lor 80 + mrs x1, id_aa64mmfr1_el1 81 + ubfx x0, x1, #ID_AA64MMFR1_LOR_SHIFT, 4 82 + cbz x0, 1f 83 + msr_s SYS_LORC_EL1, xzr 84 + 1: 85 + .endm 86 + 87 + /* Stage-2 translation */ 88 + .macro __init_el2_stage2 89 + msr vttbr_el2, xzr 90 + .endm 91 + 92 + /* GICv3 system register access */ 93 + .macro __init_el2_gicv3 94 + mrs x0, id_aa64pfr0_el1 95 + ubfx x0, x0, #ID_AA64PFR0_GIC_SHIFT, #4 96 + cbz x0, 1f 97 + 98 + mrs_s x0, SYS_ICC_SRE_EL2 99 + orr x0, x0, #ICC_SRE_EL2_SRE // Set ICC_SRE_EL2.SRE==1 100 + orr x0, x0, #ICC_SRE_EL2_ENABLE // Set ICC_SRE_EL2.Enable==1 101 + msr_s SYS_ICC_SRE_EL2, x0 102 + isb // Make sure SRE is now set 103 + mrs_s x0, SYS_ICC_SRE_EL2 // Read SRE back, 104 + tbz x0, #0, 1f // and check that it sticks 105 + msr_s SYS_ICH_HCR_EL2, xzr // Reset ICC_HCR_EL2 to defaults 106 + 1: 107 + .endm 108 + 109 + .macro __init_el2_hstr 110 + msr hstr_el2, xzr // Disable CP15 traps to EL2 111 + .endm 112 + 113 + /* Virtual CPU ID registers */ 114 + .macro __init_el2_nvhe_idregs 115 + mrs x0, midr_el1 116 + mrs x1, mpidr_el1 117 + msr vpidr_el2, x0 118 + msr vmpidr_el2, x1 119 + .endm 120 + 121 + /* Coprocessor traps */ 122 + .macro __init_el2_nvhe_cptr 123 + mov x0, #0x33ff 124 + msr cptr_el2, x0 // Disable copro. traps to EL2 125 + .endm 126 + 127 + /* SVE register access */ 128 + .macro __init_el2_nvhe_sve 129 + mrs x1, id_aa64pfr0_el1 130 + ubfx x1, x1, #ID_AA64PFR0_SVE_SHIFT, #4 131 + cbz x1, 1f 132 + 133 + bic x0, x0, #CPTR_EL2_TZ // Also disable SVE traps 134 + msr cptr_el2, x0 // Disable copro. traps to EL2 135 + isb 136 + mov x1, #ZCR_ELx_LEN_MASK // SVE: Enable full vector 137 + msr_s SYS_ZCR_EL2, x1 // length for EL1. 138 + 1: 139 + .endm 140 + 141 + .macro __init_el2_nvhe_prepare_eret 142 + mov x0, #INIT_PSTATE_EL1 143 + msr spsr_el2, x0 144 + .endm 145 + 146 + /** 147 + * Initialize EL2 registers to sane values. This should be called early on all 148 + * cores that were booted in EL2. 149 + * 150 + * Regs: x0, x1 and x2 are clobbered. 151 + */ 152 + .macro init_el2_state mode 153 + .ifnes "\mode", "vhe" 154 + .ifnes "\mode", "nvhe" 155 + .error "Invalid 'mode' argument" 156 + .endif 157 + .endif 158 + 159 + __init_el2_sctlr 160 + __init_el2_timers \mode 161 + __init_el2_debug \mode 162 + __init_el2_lor 163 + __init_el2_stage2 164 + __init_el2_gicv3 165 + __init_el2_hstr 166 + 167 + /* 168 + * When VHE is not in use, early init of EL2 needs to be done here. 169 + * When VHE _is_ in use, EL1 will not be used in the host and 170 + * requires no configuration, and all non-hyp-specific EL2 setup 171 + * will be done via the _EL1 system register aliases in __cpu_setup. 172 + */ 173 + .ifeqs "\mode", "nvhe" 174 + __init_el2_nvhe_idregs 175 + __init_el2_nvhe_cptr 176 + __init_el2_nvhe_sve 177 + __init_el2_nvhe_prepare_eret 178 + .endif 179 + .endm 180 + 181 + #endif /* __ARM_KVM_INIT_H__ */
-1
arch/arm64/include/asm/exec.h
··· 10 10 #include <linux/sched.h> 11 11 12 12 extern unsigned long arch_align_stack(unsigned long sp); 13 - void uao_thread_switch(struct task_struct *next); 14 13 15 14 #endif /* __ASM_EXEC_H */
+4 -4
arch/arm64/include/asm/futex.h
··· 16 16 do { \ 17 17 unsigned int loops = FUTEX_MAX_LOOPS; \ 18 18 \ 19 - uaccess_enable(); \ 19 + uaccess_enable_privileged(); \ 20 20 asm volatile( \ 21 21 " prfm pstl1strm, %2\n" \ 22 22 "1: ldxr %w1, %2\n" \ ··· 39 39 "+r" (loops) \ 40 40 : "r" (oparg), "Ir" (-EFAULT), "Ir" (-EAGAIN) \ 41 41 : "memory"); \ 42 - uaccess_disable(); \ 42 + uaccess_disable_privileged(); \ 43 43 } while (0) 44 44 45 45 static inline int ··· 95 95 return -EFAULT; 96 96 97 97 uaddr = __uaccess_mask_ptr(_uaddr); 98 - uaccess_enable(); 98 + uaccess_enable_privileged(); 99 99 asm volatile("// futex_atomic_cmpxchg_inatomic\n" 100 100 " prfm pstl1strm, %2\n" 101 101 "1: ldxr %w1, %2\n" ··· 118 118 : "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp), "+r" (loops) 119 119 : "r" (oldval), "r" (newval), "Ir" (-EFAULT), "Ir" (-EAGAIN) 120 120 : "memory"); 121 - uaccess_disable(); 121 + uaccess_disable_privileged(); 122 122 123 123 if (!ret) 124 124 *uval = val;
+1 -2
arch/arm64/include/asm/insn.h
··· 10 10 #include <linux/build_bug.h> 11 11 #include <linux/types.h> 12 12 13 - /* A64 instructions are always 32 bits. */ 14 - #define AARCH64_INSN_SIZE 4 13 + #include <asm/alternative.h> 15 14 16 15 #ifndef __ASSEMBLY__ 17 16 /*
+1
arch/arm64/include/asm/kvm_arm.h
··· 80 80 HCR_FMO | HCR_IMO | HCR_PTW ) 81 81 #define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF) 82 82 #define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK | HCR_ATA) 83 + #define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC) 83 84 #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) 84 85 85 86 /* TCR_EL2 Registers bits */
+8 -9
arch/arm64/include/asm/kvm_asm.h
··· 34 34 */ 35 35 #define KVM_VECTOR_PREAMBLE (2 * AARCH64_INSN_SIZE) 36 36 37 - #define __SMCCC_WORKAROUND_1_SMC_SZ 36 38 - 39 37 #define KVM_HOST_SMCCC_ID(id) \ 40 38 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ 41 39 ARM_SMCCC_SMC_64, \ ··· 148 150 149 151 #endif 150 152 153 + struct kvm_nvhe_init_params { 154 + unsigned long mair_el2; 155 + unsigned long tcr_el2; 156 + unsigned long tpidr_el2; 157 + unsigned long stack_hyp_va; 158 + phys_addr_t pgd_pa; 159 + }; 160 + 151 161 /* Translate a kernel address @ptr into its equivalent linear mapping */ 152 162 #define kvm_ksym_ref(ptr) \ 153 163 ({ \ ··· 171 165 struct kvm_s2_mmu; 172 166 173 167 DECLARE_KVM_NVHE_SYM(__kvm_hyp_init); 174 - DECLARE_KVM_NVHE_SYM(__kvm_hyp_host_vector); 175 168 DECLARE_KVM_HYP_SYM(__kvm_hyp_vector); 176 169 #define __kvm_hyp_init CHOOSE_NVHE_SYM(__kvm_hyp_init) 177 - #define __kvm_hyp_host_vector CHOOSE_NVHE_SYM(__kvm_hyp_host_vector) 178 170 #define __kvm_hyp_vector CHOOSE_HYP_SYM(__kvm_hyp_vector) 179 171 180 172 extern unsigned long kvm_arm_hyp_percpu_base[NR_CPUS]; 181 173 DECLARE_KVM_NVHE_SYM(__per_cpu_start); 182 174 DECLARE_KVM_NVHE_SYM(__per_cpu_end); 183 175 184 - extern atomic_t arm64_el2_vector_last_slot; 185 176 DECLARE_KVM_HYP_SYM(__bp_harden_hyp_vecs); 186 177 #define __bp_harden_hyp_vecs CHOOSE_HYP_SYM(__bp_harden_hyp_vecs) 187 178 ··· 192 189 193 190 extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu); 194 191 195 - extern void __kvm_enable_ssbs(void); 196 - 197 192 extern u64 __vgic_v3_get_ich_vtr_el2(void); 198 193 extern u64 __vgic_v3_read_vmcr(void); 199 194 extern void __vgic_v3_write_vmcr(u32 vmcr); 200 195 extern void __vgic_v3_init_lrs(void); 201 196 202 197 extern u32 __kvm_get_mdcr_el2(void); 203 - 204 - extern char __smccc_workaround_1_smc[__SMCCC_WORKAROUND_1_SMC_SZ]; 205 198 206 199 /* 207 200 * Obtain the PC-relative address of a kernel symbol
-38
arch/arm64/include/asm/kvm_coproc.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012,2013 - ARM Ltd 4 - * Author: Marc Zyngier <marc.zyngier@arm.com> 5 - * 6 - * Derived from arch/arm/include/asm/kvm_coproc.h 7 - * Copyright (C) 2012 Rusty Russell IBM Corporation 8 - */ 9 - 10 - #ifndef __ARM64_KVM_COPROC_H__ 11 - #define __ARM64_KVM_COPROC_H__ 12 - 13 - #include <linux/kvm_host.h> 14 - 15 - void kvm_reset_sys_regs(struct kvm_vcpu *vcpu); 16 - 17 - struct kvm_sys_reg_table { 18 - const struct sys_reg_desc *table; 19 - size_t num; 20 - }; 21 - 22 - int kvm_handle_cp14_load_store(struct kvm_vcpu *vcpu); 23 - int kvm_handle_cp14_32(struct kvm_vcpu *vcpu); 24 - int kvm_handle_cp14_64(struct kvm_vcpu *vcpu); 25 - int kvm_handle_cp15_32(struct kvm_vcpu *vcpu); 26 - int kvm_handle_cp15_64(struct kvm_vcpu *vcpu); 27 - int kvm_handle_sys_reg(struct kvm_vcpu *vcpu); 28 - 29 - #define kvm_coproc_table_init kvm_sys_reg_table_init 30 - void kvm_sys_reg_table_init(void); 31 - 32 - struct kvm_one_reg; 33 - int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices); 34 - int kvm_arm_sys_reg_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *); 35 - int kvm_arm_sys_reg_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *); 36 - unsigned long kvm_arm_num_sys_reg_descs(struct kvm_vcpu *vcpu); 37 - 38 - #endif /* __ARM64_KVM_COPROC_H__ */
+14 -56
arch/arm64/include/asm/kvm_emulate.h
··· 21 21 #include <asm/cputype.h> 22 22 #include <asm/virt.h> 23 23 24 - unsigned long *vcpu_reg32(const struct kvm_vcpu *vcpu, u8 reg_num); 25 - unsigned long vcpu_read_spsr32(const struct kvm_vcpu *vcpu); 26 - void vcpu_write_spsr32(struct kvm_vcpu *vcpu, unsigned long v); 24 + #define CURRENT_EL_SP_EL0_VECTOR 0x0 25 + #define CURRENT_EL_SP_ELx_VECTOR 0x200 26 + #define LOWER_EL_AArch64_VECTOR 0x400 27 + #define LOWER_EL_AArch32_VECTOR 0x600 28 + 29 + enum exception_type { 30 + except_type_sync = 0, 31 + except_type_irq = 0x80, 32 + except_type_fiq = 0x100, 33 + except_type_serror = 0x180, 34 + }; 27 35 28 36 bool kvm_condition_valid32(const struct kvm_vcpu *vcpu); 29 - void kvm_skip_instr32(struct kvm_vcpu *vcpu, bool is_wide_instr); 37 + void kvm_skip_instr32(struct kvm_vcpu *vcpu); 30 38 31 39 void kvm_inject_undefined(struct kvm_vcpu *vcpu); 32 40 void kvm_inject_vabt(struct kvm_vcpu *vcpu); 33 41 void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr); 34 42 void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr); 35 - void kvm_inject_undef32(struct kvm_vcpu *vcpu); 36 - void kvm_inject_dabt32(struct kvm_vcpu *vcpu, unsigned long addr); 37 - void kvm_inject_pabt32(struct kvm_vcpu *vcpu, unsigned long addr); 38 43 39 44 static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu) 40 45 { ··· 171 166 { 172 167 if (reg_num != 31) 173 168 vcpu_gp_regs(vcpu)->regs[reg_num] = val; 174 - } 175 - 176 - static inline unsigned long vcpu_read_spsr(const struct kvm_vcpu *vcpu) 177 - { 178 - if (vcpu_mode_is_32bit(vcpu)) 179 - return vcpu_read_spsr32(vcpu); 180 - 181 - if (vcpu->arch.sysregs_loaded_on_cpu) 182 - return read_sysreg_el1(SYS_SPSR); 183 - else 184 - return __vcpu_sys_reg(vcpu, SPSR_EL1); 185 - } 186 - 187 - static inline void vcpu_write_spsr(struct kvm_vcpu *vcpu, unsigned long v) 188 - { 189 - if (vcpu_mode_is_32bit(vcpu)) { 190 - vcpu_write_spsr32(vcpu, v); 191 - return; 192 - } 193 - 194 - if (vcpu->arch.sysregs_loaded_on_cpu) 195 - write_sysreg_el1(v, SYS_SPSR); 196 - else 197 - __vcpu_sys_reg(vcpu, SPSR_EL1) = v; 198 169 } 199 170 200 171 /* ··· 453 472 return data; /* Leave LE untouched */ 454 473 } 455 474 456 - static __always_inline void kvm_skip_instr(struct kvm_vcpu *vcpu, bool is_wide_instr) 475 + static __always_inline void kvm_incr_pc(struct kvm_vcpu *vcpu) 457 476 { 458 - if (vcpu_mode_is_32bit(vcpu)) { 459 - kvm_skip_instr32(vcpu, is_wide_instr); 460 - } else { 461 - *vcpu_pc(vcpu) += 4; 462 - *vcpu_cpsr(vcpu) &= ~PSR_BTYPE_MASK; 463 - } 464 - 465 - /* advance the singlestep state machine */ 466 - *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; 467 - } 468 - 469 - /* 470 - * Skip an instruction which has been emulated at hyp while most guest sysregs 471 - * are live. 472 - */ 473 - static __always_inline void __kvm_skip_instr(struct kvm_vcpu *vcpu) 474 - { 475 - *vcpu_pc(vcpu) = read_sysreg_el2(SYS_ELR); 476 - vcpu_gp_regs(vcpu)->pstate = read_sysreg_el2(SYS_SPSR); 477 - 478 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 479 - 480 - write_sysreg_el2(vcpu_gp_regs(vcpu)->pstate, SYS_SPSR); 481 - write_sysreg_el2(*vcpu_pc(vcpu), SYS_ELR); 477 + vcpu->arch.flags |= KVM_ARM64_INCREMENT_PC; 482 478 } 483 479 484 480 #endif /* __ARM64_KVM_EMULATE_H__ */
+150 -56
arch/arm64/include/asm/kvm_host.h
··· 50 50 #define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \ 51 51 KVM_DIRTY_LOG_INITIALLY_SET) 52 52 53 + /* 54 + * Mode of operation configurable with kvm-arm.mode early param. 55 + * See Documentation/admin-guide/kernel-parameters.txt for more information. 56 + */ 57 + enum kvm_mode { 58 + KVM_MODE_DEFAULT, 59 + KVM_MODE_PROTECTED, 60 + }; 61 + enum kvm_mode kvm_get_mode(void); 62 + 53 63 DECLARE_STATIC_KEY_FALSE(userspace_irqchip_in_use); 54 64 55 65 extern unsigned int kvm_sve_max_vl; ··· 68 58 int __attribute_const__ kvm_target_cpu(void); 69 59 int kvm_reset_vcpu(struct kvm_vcpu *vcpu); 70 60 void kvm_arm_vcpu_destroy(struct kvm_vcpu *vcpu); 71 - int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext); 72 - void __extended_idmap_trampoline(phys_addr_t boot_pgd, phys_addr_t idmap_start); 73 61 74 62 struct kvm_vmid { 75 63 /* The VMID generation used for the virt. memory system */ ··· 95 87 int __percpu *last_vcpu_ran; 96 88 97 89 struct kvm *kvm; 90 + }; 91 + 92 + struct kvm_arch_memory_slot { 98 93 }; 99 94 100 95 struct kvm_arch { ··· 131 120 unsigned int pmuver; 132 121 133 122 u8 pfr0_csv2; 123 + u8 pfr0_csv3; 134 124 }; 135 125 136 126 struct kvm_vcpu_fault_info { ··· 215 203 NR_SYS_REGS /* Nothing after this line! */ 216 204 }; 217 205 218 - /* 32bit mapping */ 219 - #define c0_MPIDR (MPIDR_EL1 * 2) /* MultiProcessor ID Register */ 220 - #define c0_CSSELR (CSSELR_EL1 * 2)/* Cache Size Selection Register */ 221 - #define c1_SCTLR (SCTLR_EL1 * 2) /* System Control Register */ 222 - #define c1_ACTLR (ACTLR_EL1 * 2) /* Auxiliary Control Register */ 223 - #define c1_CPACR (CPACR_EL1 * 2) /* Coprocessor Access Control */ 224 - #define c2_TTBR0 (TTBR0_EL1 * 2) /* Translation Table Base Register 0 */ 225 - #define c2_TTBR0_high (c2_TTBR0 + 1) /* TTBR0 top 32 bits */ 226 - #define c2_TTBR1 (TTBR1_EL1 * 2) /* Translation Table Base Register 1 */ 227 - #define c2_TTBR1_high (c2_TTBR1 + 1) /* TTBR1 top 32 bits */ 228 - #define c2_TTBCR (TCR_EL1 * 2) /* Translation Table Base Control R. */ 229 - #define c3_DACR (DACR32_EL2 * 2)/* Domain Access Control Register */ 230 - #define c5_DFSR (ESR_EL1 * 2) /* Data Fault Status Register */ 231 - #define c5_IFSR (IFSR32_EL2 * 2)/* Instruction Fault Status Register */ 232 - #define c5_ADFSR (AFSR0_EL1 * 2) /* Auxiliary Data Fault Status R */ 233 - #define c5_AIFSR (AFSR1_EL1 * 2) /* Auxiliary Instr Fault Status R */ 234 - #define c6_DFAR (FAR_EL1 * 2) /* Data Fault Address Register */ 235 - #define c6_IFAR (c6_DFAR + 1) /* Instruction Fault Address Register */ 236 - #define c7_PAR (PAR_EL1 * 2) /* Physical Address Register */ 237 - #define c7_PAR_high (c7_PAR + 1) /* PAR top 32 bits */ 238 - #define c10_PRRR (MAIR_EL1 * 2) /* Primary Region Remap Register */ 239 - #define c10_NMRR (c10_PRRR + 1) /* Normal Memory Remap Register */ 240 - #define c12_VBAR (VBAR_EL1 * 2) /* Vector Base Address Register */ 241 - #define c13_CID (CONTEXTIDR_EL1 * 2) /* Context ID Register */ 242 - #define c13_TID_URW (TPIDR_EL0 * 2) /* Thread ID, User R/W */ 243 - #define c13_TID_URO (TPIDRRO_EL0 * 2)/* Thread ID, User R/O */ 244 - #define c13_TID_PRIV (TPIDR_EL1 * 2) /* Thread ID, Privileged */ 245 - #define c10_AMAIR0 (AMAIR_EL1 * 2) /* Aux Memory Attr Indirection Reg */ 246 - #define c10_AMAIR1 (c10_AMAIR0 + 1)/* Aux Memory Attr Indirection Reg */ 247 - #define c14_CNTKCTL (CNTKCTL_EL1 * 2) /* Timer Control Register (PL1) */ 248 - 249 - #define cp14_DBGDSCRext (MDSCR_EL1 * 2) 250 - #define cp14_DBGBCR0 (DBGBCR0_EL1 * 2) 251 - #define cp14_DBGBVR0 (DBGBVR0_EL1 * 2) 252 - #define cp14_DBGBXVR0 (cp14_DBGBVR0 + 1) 253 - #define cp14_DBGWCR0 (DBGWCR0_EL1 * 2) 254 - #define cp14_DBGWVR0 (DBGWVR0_EL1 * 2) 255 - #define cp14_DBGDCCINT (MDCCINT_EL1 * 2) 256 - #define cp14_DBGVCR (DBGVCR32_EL2 * 2) 257 - 258 - #define NR_COPRO_REGS (NR_SYS_REGS * 2) 259 - 260 206 struct kvm_cpu_context { 261 207 struct user_pt_regs regs; /* sp = sp_el0 */ 262 208 ··· 225 255 226 256 struct user_fpsimd_state fp_regs; 227 257 228 - union { 229 - u64 sys_regs[NR_SYS_REGS]; 230 - u32 copro[NR_COPRO_REGS]; 231 - }; 258 + u64 sys_regs[NR_SYS_REGS]; 232 259 233 260 struct kvm_vcpu *__hyp_running_vcpu; 234 261 }; ··· 376 409 #define KVM_ARM64_GUEST_HAS_SVE (1 << 5) /* SVE exposed to guest */ 377 410 #define KVM_ARM64_VCPU_SVE_FINALIZED (1 << 6) /* SVE config completed */ 378 411 #define KVM_ARM64_GUEST_HAS_PTRAUTH (1 << 7) /* PTRAUTH exposed to guest */ 412 + #define KVM_ARM64_PENDING_EXCEPTION (1 << 8) /* Exception pending */ 413 + #define KVM_ARM64_EXCEPT_MASK (7 << 9) /* Target EL/MODE */ 379 414 380 - #define vcpu_has_sve(vcpu) (system_supports_sve() && \ 415 + /* 416 + * When KVM_ARM64_PENDING_EXCEPTION is set, KVM_ARM64_EXCEPT_MASK can 417 + * take the following values: 418 + * 419 + * For AArch32 EL1: 420 + */ 421 + #define KVM_ARM64_EXCEPT_AA32_UND (0 << 9) 422 + #define KVM_ARM64_EXCEPT_AA32_IABT (1 << 9) 423 + #define KVM_ARM64_EXCEPT_AA32_DABT (2 << 9) 424 + /* For AArch64: */ 425 + #define KVM_ARM64_EXCEPT_AA64_ELx_SYNC (0 << 9) 426 + #define KVM_ARM64_EXCEPT_AA64_ELx_IRQ (1 << 9) 427 + #define KVM_ARM64_EXCEPT_AA64_ELx_FIQ (2 << 9) 428 + #define KVM_ARM64_EXCEPT_AA64_ELx_SERR (3 << 9) 429 + #define KVM_ARM64_EXCEPT_AA64_EL1 (0 << 11) 430 + #define KVM_ARM64_EXCEPT_AA64_EL2 (1 << 11) 431 + 432 + /* 433 + * Overlaps with KVM_ARM64_EXCEPT_MASK on purpose so that it can't be 434 + * set together with an exception... 435 + */ 436 + #define KVM_ARM64_INCREMENT_PC (1 << 9) /* Increment PC */ 437 + 438 + #define vcpu_has_sve(vcpu) (system_supports_sve() && \ 381 439 ((vcpu)->arch.flags & KVM_ARM64_GUEST_HAS_SVE)) 382 440 383 441 #ifdef CONFIG_ARM64_PTR_AUTH ··· 432 440 u64 vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg); 433 441 void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg); 434 442 435 - /* 436 - * CP14 and CP15 live in the same array, as they are backed by the 437 - * same system registers. 438 - */ 439 - #define CPx_BIAS IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) 443 + static inline bool __vcpu_read_sys_reg_from_cpu(int reg, u64 *val) 444 + { 445 + /* 446 + * *** VHE ONLY *** 447 + * 448 + * System registers listed in the switch are not saved on every 449 + * exit from the guest but are only saved on vcpu_put. 450 + * 451 + * Note that MPIDR_EL1 for the guest is set by KVM via VMPIDR_EL2 but 452 + * should never be listed below, because the guest cannot modify its 453 + * own MPIDR_EL1 and MPIDR_EL1 is accessed for VCPU A from VCPU B's 454 + * thread when emulating cross-VCPU communication. 455 + */ 456 + if (!has_vhe()) 457 + return false; 440 458 441 - #define vcpu_cp14(v,r) ((v)->arch.ctxt.copro[(r) ^ CPx_BIAS]) 442 - #define vcpu_cp15(v,r) ((v)->arch.ctxt.copro[(r) ^ CPx_BIAS]) 459 + switch (reg) { 460 + case CSSELR_EL1: *val = read_sysreg_s(SYS_CSSELR_EL1); break; 461 + case SCTLR_EL1: *val = read_sysreg_s(SYS_SCTLR_EL12); break; 462 + case CPACR_EL1: *val = read_sysreg_s(SYS_CPACR_EL12); break; 463 + case TTBR0_EL1: *val = read_sysreg_s(SYS_TTBR0_EL12); break; 464 + case TTBR1_EL1: *val = read_sysreg_s(SYS_TTBR1_EL12); break; 465 + case TCR_EL1: *val = read_sysreg_s(SYS_TCR_EL12); break; 466 + case ESR_EL1: *val = read_sysreg_s(SYS_ESR_EL12); break; 467 + case AFSR0_EL1: *val = read_sysreg_s(SYS_AFSR0_EL12); break; 468 + case AFSR1_EL1: *val = read_sysreg_s(SYS_AFSR1_EL12); break; 469 + case FAR_EL1: *val = read_sysreg_s(SYS_FAR_EL12); break; 470 + case MAIR_EL1: *val = read_sysreg_s(SYS_MAIR_EL12); break; 471 + case VBAR_EL1: *val = read_sysreg_s(SYS_VBAR_EL12); break; 472 + case CONTEXTIDR_EL1: *val = read_sysreg_s(SYS_CONTEXTIDR_EL12);break; 473 + case TPIDR_EL0: *val = read_sysreg_s(SYS_TPIDR_EL0); break; 474 + case TPIDRRO_EL0: *val = read_sysreg_s(SYS_TPIDRRO_EL0); break; 475 + case TPIDR_EL1: *val = read_sysreg_s(SYS_TPIDR_EL1); break; 476 + case AMAIR_EL1: *val = read_sysreg_s(SYS_AMAIR_EL12); break; 477 + case CNTKCTL_EL1: *val = read_sysreg_s(SYS_CNTKCTL_EL12); break; 478 + case ELR_EL1: *val = read_sysreg_s(SYS_ELR_EL12); break; 479 + case PAR_EL1: *val = read_sysreg_par(); break; 480 + case DACR32_EL2: *val = read_sysreg_s(SYS_DACR32_EL2); break; 481 + case IFSR32_EL2: *val = read_sysreg_s(SYS_IFSR32_EL2); break; 482 + case DBGVCR32_EL2: *val = read_sysreg_s(SYS_DBGVCR32_EL2); break; 483 + default: return false; 484 + } 485 + 486 + return true; 487 + } 488 + 489 + static inline bool __vcpu_write_sys_reg_to_cpu(u64 val, int reg) 490 + { 491 + /* 492 + * *** VHE ONLY *** 493 + * 494 + * System registers listed in the switch are not restored on every 495 + * entry to the guest but are only restored on vcpu_load. 496 + * 497 + * Note that MPIDR_EL1 for the guest is set by KVM via VMPIDR_EL2 but 498 + * should never be listed below, because the MPIDR should only be set 499 + * once, before running the VCPU, and never changed later. 500 + */ 501 + if (!has_vhe()) 502 + return false; 503 + 504 + switch (reg) { 505 + case CSSELR_EL1: write_sysreg_s(val, SYS_CSSELR_EL1); break; 506 + case SCTLR_EL1: write_sysreg_s(val, SYS_SCTLR_EL12); break; 507 + case CPACR_EL1: write_sysreg_s(val, SYS_CPACR_EL12); break; 508 + case TTBR0_EL1: write_sysreg_s(val, SYS_TTBR0_EL12); break; 509 + case TTBR1_EL1: write_sysreg_s(val, SYS_TTBR1_EL12); break; 510 + case TCR_EL1: write_sysreg_s(val, SYS_TCR_EL12); break; 511 + case ESR_EL1: write_sysreg_s(val, SYS_ESR_EL12); break; 512 + case AFSR0_EL1: write_sysreg_s(val, SYS_AFSR0_EL12); break; 513 + case AFSR1_EL1: write_sysreg_s(val, SYS_AFSR1_EL12); break; 514 + case FAR_EL1: write_sysreg_s(val, SYS_FAR_EL12); break; 515 + case MAIR_EL1: write_sysreg_s(val, SYS_MAIR_EL12); break; 516 + case VBAR_EL1: write_sysreg_s(val, SYS_VBAR_EL12); break; 517 + case CONTEXTIDR_EL1: write_sysreg_s(val, SYS_CONTEXTIDR_EL12);break; 518 + case TPIDR_EL0: write_sysreg_s(val, SYS_TPIDR_EL0); break; 519 + case TPIDRRO_EL0: write_sysreg_s(val, SYS_TPIDRRO_EL0); break; 520 + case TPIDR_EL1: write_sysreg_s(val, SYS_TPIDR_EL1); break; 521 + case AMAIR_EL1: write_sysreg_s(val, SYS_AMAIR_EL12); break; 522 + case CNTKCTL_EL1: write_sysreg_s(val, SYS_CNTKCTL_EL12); break; 523 + case ELR_EL1: write_sysreg_s(val, SYS_ELR_EL12); break; 524 + case PAR_EL1: write_sysreg_s(val, SYS_PAR_EL1); break; 525 + case DACR32_EL2: write_sysreg_s(val, SYS_DACR32_EL2); break; 526 + case IFSR32_EL2: write_sysreg_s(val, SYS_IFSR32_EL2); break; 527 + case DBGVCR32_EL2: write_sysreg_s(val, SYS_DBGVCR32_EL2); break; 528 + default: return false; 529 + } 530 + 531 + return true; 532 + } 443 533 444 534 struct kvm_vm_stat { 445 535 ulong remote_tlb_flush; ··· 547 473 int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices); 548 474 int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); 549 475 int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); 476 + 477 + unsigned long kvm_arm_num_sys_reg_descs(struct kvm_vcpu *vcpu); 478 + int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices); 479 + int kvm_arm_sys_reg_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *); 480 + int kvm_arm_sys_reg_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *); 481 + 550 482 int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu, 551 483 struct kvm_vcpu_events *events); 552 484 ··· 614 534 615 535 int handle_exit(struct kvm_vcpu *vcpu, int exception_index); 616 536 void handle_exit_early(struct kvm_vcpu *vcpu, int exception_index); 537 + 538 + int kvm_handle_cp14_load_store(struct kvm_vcpu *vcpu); 539 + int kvm_handle_cp14_32(struct kvm_vcpu *vcpu); 540 + int kvm_handle_cp14_64(struct kvm_vcpu *vcpu); 541 + int kvm_handle_cp15_32(struct kvm_vcpu *vcpu); 542 + int kvm_handle_cp15_64(struct kvm_vcpu *vcpu); 543 + int kvm_handle_sys_reg(struct kvm_vcpu *vcpu); 544 + 545 + void kvm_reset_sys_regs(struct kvm_vcpu *vcpu); 546 + 547 + void kvm_sys_reg_table_init(void); 617 548 618 549 /* MMIO helpers */ 619 550 void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data); ··· 744 653 745 654 #define kvm_arm_vcpu_sve_finalized(vcpu) \ 746 655 ((vcpu)->arch.flags & KVM_ARM64_VCPU_SVE_FINALIZED) 656 + 657 + #define kvm_vcpu_has_pmu(vcpu) \ 658 + (test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features)) 747 659 748 660 #endif /* __ARM64_KVM_HOST_H__ */
+3 -1
arch/arm64/include/asm/kvm_hyp.h
··· 14 14 15 15 DECLARE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt); 16 16 DECLARE_PER_CPU(unsigned long, kvm_hyp_vector); 17 + DECLARE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params); 17 18 18 19 #define read_sysreg_elx(r,nvh,vh) \ 19 20 ({ \ ··· 93 92 94 93 u64 __guest_enter(struct kvm_vcpu *vcpu); 95 94 95 + bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt); 96 + 96 97 void __noreturn hyp_panic(void); 97 98 #ifdef __KVM_NVHE_HYPERVISOR__ 98 99 void __noreturn __hyp_do_panic(bool restore_host, u64 spsr, u64 elr, u64 par); 99 100 #endif 100 101 101 102 #endif /* __ARM64_KVM_HYP_H__ */ 102 -
+64 -46
arch/arm64/include/asm/kvm_mmu.h
··· 72 72 alternative_cb_end 73 73 .endm 74 74 75 + /* 76 + * Convert a kernel image address to a PA 77 + * reg: kernel address to be converted in place 78 + * tmp: temporary register 79 + * 80 + * The actual code generation takes place in kvm_get_kimage_voffset, and 81 + * the instructions below are only there to reserve the space and 82 + * perform the register allocation (kvm_get_kimage_voffset uses the 83 + * specific registers encoded in the instructions). 84 + */ 85 + .macro kimg_pa reg, tmp 86 + alternative_cb kvm_get_kimage_voffset 87 + movz \tmp, #0 88 + movk \tmp, #0, lsl #16 89 + movk \tmp, #0, lsl #32 90 + movk \tmp, #0, lsl #48 91 + alternative_cb_end 92 + 93 + /* reg = __pa(reg) */ 94 + sub \reg, \reg, \tmp 95 + .endm 96 + 97 + /* 98 + * Convert a kernel image address to a hyp VA 99 + * reg: kernel address to be converted in place 100 + * tmp: temporary register 101 + * 102 + * The actual code generation takes place in kvm_get_kimage_voffset, and 103 + * the instructions below are only there to reserve the space and 104 + * perform the register allocation (kvm_update_kimg_phys_offset uses the 105 + * specific registers encoded in the instructions). 106 + */ 107 + .macro kimg_hyp_va reg, tmp 108 + alternative_cb kvm_update_kimg_phys_offset 109 + movz \tmp, #0 110 + movk \tmp, #0, lsl #16 111 + movk \tmp, #0, lsl #32 112 + movk \tmp, #0, lsl #48 113 + alternative_cb_end 114 + 115 + sub \reg, \reg, \tmp 116 + mov_q \tmp, PAGE_OFFSET 117 + orr \reg, \reg, \tmp 118 + kern_hyp_va \reg 119 + .endm 120 + 75 121 #else 76 122 77 123 #include <linux/pgtable.h> ··· 143 97 } 144 98 145 99 #define kern_hyp_va(v) ((typeof(v))(__kern_hyp_va((unsigned long)(v)))) 100 + 101 + static __always_inline unsigned long __kimg_hyp_va(unsigned long v) 102 + { 103 + unsigned long offset; 104 + 105 + asm volatile(ALTERNATIVE_CB("movz %0, #0\n" 106 + "movk %0, #0, lsl #16\n" 107 + "movk %0, #0, lsl #32\n" 108 + "movk %0, #0, lsl #48\n", 109 + kvm_update_kimg_phys_offset) 110 + : "=r" (offset)); 111 + 112 + return __kern_hyp_va((v - offset) | PAGE_OFFSET); 113 + } 114 + 115 + #define kimg_fn_hyp_va(v) ((typeof(*v))(__kimg_hyp_va((unsigned long)(v)))) 116 + 117 + #define kimg_fn_ptr(x) (typeof(x) **)(x) 146 118 147 119 /* 148 120 * We currently support using a VM-specified IPA size. For backward ··· 270 206 srcu_read_unlock(&kvm->srcu, srcu_idx); 271 207 272 208 return ret; 273 - } 274 - 275 - /* 276 - * EL2 vectors can be mapped and rerouted in a number of ways, 277 - * depending on the kernel configuration and CPU present: 278 - * 279 - * - If the CPU is affected by Spectre-v2, the hardening sequence is 280 - * placed in one of the vector slots, which is executed before jumping 281 - * to the real vectors. 282 - * 283 - * - If the CPU also has the ARM64_HARDEN_EL2_VECTORS cap, the slot 284 - * containing the hardening sequence is mapped next to the idmap page, 285 - * and executed before jumping to the real vectors. 286 - * 287 - * - If the CPU only has the ARM64_HARDEN_EL2_VECTORS cap, then an 288 - * empty slot is selected, mapped next to the idmap page, and 289 - * executed before jumping to the real vectors. 290 - * 291 - * Note that ARM64_HARDEN_EL2_VECTORS is somewhat incompatible with 292 - * VHE, as we don't have hypervisor-specific mappings. If the system 293 - * is VHE and yet selects this capability, it will be ignored. 294 - */ 295 - extern void *__kvm_bp_vect_base; 296 - extern int __kvm_harden_el2_vector_slot; 297 - 298 - static inline void *kvm_get_hyp_vector(void) 299 - { 300 - struct bp_hardening_data *data = arm64_get_bp_hardening_data(); 301 - void *vect = kern_hyp_va(kvm_ksym_ref(__kvm_hyp_vector)); 302 - int slot = -1; 303 - 304 - if (cpus_have_const_cap(ARM64_SPECTRE_V2) && data->fn) { 305 - vect = kern_hyp_va(kvm_ksym_ref(__bp_harden_hyp_vecs)); 306 - slot = data->hyp_vectors_slot; 307 - } 308 - 309 - if (this_cpu_has_cap(ARM64_HARDEN_EL2_VECTORS) && !has_vhe()) { 310 - vect = __kvm_bp_vect_base; 311 - if (slot == -1) 312 - slot = __kvm_harden_el2_vector_slot; 313 - } 314 - 315 - if (slot != -1) 316 - vect += slot * SZ_2K; 317 - 318 - return vect; 319 209 } 320 210 321 211 #define kvm_phys_to_vttbr(addr) phys_to_ttbr(addr)
-29
arch/arm64/include/asm/mmu.h
··· 12 12 #define USER_ASID_FLAG (UL(1) << USER_ASID_BIT) 13 13 #define TTBR_ASID_MASK (UL(0xffff) << 48) 14 14 15 - #define BP_HARDEN_EL2_SLOTS 4 16 - #define __BP_HARDEN_HYP_VECS_SZ (BP_HARDEN_EL2_SLOTS * SZ_2K) 17 - 18 15 #ifndef __ASSEMBLY__ 19 16 20 17 #include <linux/refcount.h> ··· 36 39 static inline bool arm64_kernel_unmapped_at_el0(void) 37 40 { 38 41 return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0); 39 - } 40 - 41 - typedef void (*bp_hardening_cb_t)(void); 42 - 43 - struct bp_hardening_data { 44 - int hyp_vectors_slot; 45 - bp_hardening_cb_t fn; 46 - }; 47 - 48 - DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); 49 - 50 - static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void) 51 - { 52 - return this_cpu_ptr(&bp_hardening_data); 53 - } 54 - 55 - static inline void arm64_apply_bp_hardening(void) 56 - { 57 - struct bp_hardening_data *d; 58 - 59 - if (!cpus_have_const_cap(ARM64_SPECTRE_V2)) 60 - return; 61 - 62 - d = arm64_get_bp_hardening_data(); 63 - if (d->fn) 64 - d->fn(); 65 42 } 66 43 67 44 extern void arm64_memblock_init(void);
+6
arch/arm64/include/asm/percpu.h
··· 239 239 #define this_cpu_cmpxchg_8(pcp, o, n) \ 240 240 _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) 241 241 242 + #ifdef __KVM_NVHE_HYPERVISOR__ 243 + extern unsigned long __hyp_per_cpu_offset(unsigned int cpu); 244 + #define __per_cpu_offset 245 + #define per_cpu_offset(cpu) __hyp_per_cpu_offset((cpu)) 246 + #endif 247 + 242 248 #include <asm-generic/percpu.h> 243 249 244 250 /* Redefine macros for nVHE hyp under DEBUG_PREEMPT to avoid its dependencies. */
+1 -3
arch/arm64/include/asm/processor.h
··· 8 8 #ifndef __ASM_PROCESSOR_H 9 9 #define __ASM_PROCESSOR_H 10 10 11 - #define KERNEL_DS UL(-1) 12 - #define USER_DS ((UL(1) << VA_BITS) - 1) 13 - 14 11 /* 15 12 * On arm64 systems, unaligned accesses by the CPU are cheap, and so there is 16 13 * no point in shifting all network buffers by 2 bytes just to make some IP ··· 45 48 46 49 #define DEFAULT_MAP_WINDOW_64 (UL(1) << VA_BITS_MIN) 47 50 #define TASK_SIZE_64 (UL(1) << vabits_actual) 51 + #define TASK_SIZE_MAX (UL(1) << VA_BITS) 48 52 49 53 #ifdef CONFIG_COMPAT 50 54 #if defined(CONFIG_ARM64_64K_PAGES) && defined(CONFIG_KUSER_HELPERS)
+6 -2
arch/arm64/include/asm/ptrace.h
··· 16 16 #define CurrentEL_EL1 (1 << 2) 17 17 #define CurrentEL_EL2 (2 << 2) 18 18 19 + #define INIT_PSTATE_EL1 \ 20 + (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | PSR_MODE_EL1h) 21 + #define INIT_PSTATE_EL2 \ 22 + (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | PSR_MODE_EL2h) 23 + 19 24 /* 20 25 * PMR values used to mask/unmask interrupts. 21 26 * ··· 193 188 s32 syscallno; 194 189 u32 unused2; 195 190 #endif 196 - 197 - u64 orig_addr_limit; 191 + u64 sdei_ttbr1; 198 192 /* Only valid when ARM64_HAS_IRQ_PRIO_MASKING is enabled. */ 199 193 u64 pmr_save; 200 194 u64 stackframe[2];
+73
arch/arm64/include/asm/rwonce.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright (C) 2020 Google LLC. 4 + */ 5 + #ifndef __ASM_RWONCE_H 6 + #define __ASM_RWONCE_H 7 + 8 + #ifdef CONFIG_LTO 9 + 10 + #include <linux/compiler_types.h> 11 + #include <asm/alternative-macros.h> 12 + 13 + #ifndef BUILD_VDSO 14 + 15 + #ifdef CONFIG_AS_HAS_LDAPR 16 + #define __LOAD_RCPC(sfx, regs...) \ 17 + ALTERNATIVE( \ 18 + "ldar" #sfx "\t" #regs, \ 19 + ".arch_extension rcpc\n" \ 20 + "ldapr" #sfx "\t" #regs, \ 21 + ARM64_HAS_LDAPR) 22 + #else 23 + #define __LOAD_RCPC(sfx, regs...) "ldar" #sfx "\t" #regs 24 + #endif /* CONFIG_AS_HAS_LDAPR */ 25 + 26 + /* 27 + * When building with LTO, there is an increased risk of the compiler 28 + * converting an address dependency headed by a READ_ONCE() invocation 29 + * into a control dependency and consequently allowing for harmful 30 + * reordering by the CPU. 31 + * 32 + * Ensure that such transformations are harmless by overriding the generic 33 + * READ_ONCE() definition with one that provides RCpc acquire semantics 34 + * when building with LTO. 35 + */ 36 + #define __READ_ONCE(x) \ 37 + ({ \ 38 + typeof(&(x)) __x = &(x); \ 39 + int atomic = 1; \ 40 + union { __unqual_scalar_typeof(*__x) __val; char __c[1]; } __u; \ 41 + switch (sizeof(x)) { \ 42 + case 1: \ 43 + asm volatile(__LOAD_RCPC(b, %w0, %1) \ 44 + : "=r" (*(__u8 *)__u.__c) \ 45 + : "Q" (*__x) : "memory"); \ 46 + break; \ 47 + case 2: \ 48 + asm volatile(__LOAD_RCPC(h, %w0, %1) \ 49 + : "=r" (*(__u16 *)__u.__c) \ 50 + : "Q" (*__x) : "memory"); \ 51 + break; \ 52 + case 4: \ 53 + asm volatile(__LOAD_RCPC(, %w0, %1) \ 54 + : "=r" (*(__u32 *)__u.__c) \ 55 + : "Q" (*__x) : "memory"); \ 56 + break; \ 57 + case 8: \ 58 + asm volatile(__LOAD_RCPC(, %0, %1) \ 59 + : "=r" (*(__u64 *)__u.__c) \ 60 + : "Q" (*__x) : "memory"); \ 61 + break; \ 62 + default: \ 63 + atomic = 0; \ 64 + } \ 65 + atomic ? (typeof(*__x))__u.__val : (*(volatile typeof(__x))__x);\ 66 + }) 67 + 68 + #endif /* !BUILD_VDSO */ 69 + #endif /* CONFIG_LTO */ 70 + 71 + #include <asm-generic/rwonce.h> 72 + 73 + #endif /* __ASM_RWONCE_H */
+1
arch/arm64/include/asm/sections.h
··· 11 11 extern char __hibernate_exit_text_start[], __hibernate_exit_text_end[]; 12 12 extern char __hyp_idmap_text_start[], __hyp_idmap_text_end[]; 13 13 extern char __hyp_text_start[], __hyp_text_end[]; 14 + extern char __hyp_data_ro_after_init_start[], __hyp_data_ro_after_init_end[]; 14 15 extern char __idmap_text_start[], __idmap_text_end[]; 15 16 extern char __initdata_begin[], __initdata_end[]; 16 17 extern char __inittext_begin[], __inittext_end[];
+2 -2
arch/arm64/include/asm/smp.h
··· 46 46 * Logical CPU mapping. 47 47 */ 48 48 extern u64 __cpu_logical_map[NR_CPUS]; 49 - extern u64 cpu_logical_map(int cpu); 49 + extern u64 cpu_logical_map(unsigned int cpu); 50 50 51 - static inline void set_cpu_logical_map(int cpu, u64 hwid) 51 + static inline void set_cpu_logical_map(unsigned int cpu, u64 hwid) 52 52 { 53 53 __cpu_logical_map[cpu] = hwid; 54 54 }
+65
arch/arm64/include/asm/spectre.h
··· 9 9 #ifndef __ASM_SPECTRE_H 10 10 #define __ASM_SPECTRE_H 11 11 12 + #define BP_HARDEN_EL2_SLOTS 4 13 + #define __BP_HARDEN_HYP_VECS_SZ ((BP_HARDEN_EL2_SLOTS - 1) * SZ_2K) 14 + 15 + #ifndef __ASSEMBLY__ 16 + 17 + #include <linux/percpu.h> 18 + 12 19 #include <asm/cpufeature.h> 20 + #include <asm/virt.h> 13 21 14 22 /* Watch out, ordering is important here. */ 15 23 enum mitigation_state { ··· 28 20 29 21 struct task_struct; 30 22 23 + /* 24 + * Note: the order of this enum corresponds to __bp_harden_hyp_vecs and 25 + * we rely on having the direct vectors first. 26 + */ 27 + enum arm64_hyp_spectre_vector { 28 + /* 29 + * Take exceptions directly to __kvm_hyp_vector. This must be 30 + * 0 so that it used by default when mitigations are not needed. 31 + */ 32 + HYP_VECTOR_DIRECT, 33 + 34 + /* 35 + * Bounce via a slot in the hypervisor text mapping of 36 + * __bp_harden_hyp_vecs, which contains an SMC call. 37 + */ 38 + HYP_VECTOR_SPECTRE_DIRECT, 39 + 40 + /* 41 + * Bounce via a slot in a special mapping of __bp_harden_hyp_vecs 42 + * next to the idmap page. 43 + */ 44 + HYP_VECTOR_INDIRECT, 45 + 46 + /* 47 + * Bounce via a slot in a special mapping of __bp_harden_hyp_vecs 48 + * next to the idmap page, which contains an SMC call. 49 + */ 50 + HYP_VECTOR_SPECTRE_INDIRECT, 51 + }; 52 + 53 + typedef void (*bp_hardening_cb_t)(void); 54 + 55 + struct bp_hardening_data { 56 + enum arm64_hyp_spectre_vector slot; 57 + bp_hardening_cb_t fn; 58 + }; 59 + 60 + DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); 61 + 62 + static inline void arm64_apply_bp_hardening(void) 63 + { 64 + struct bp_hardening_data *d; 65 + 66 + if (!cpus_have_const_cap(ARM64_SPECTRE_V2)) 67 + return; 68 + 69 + d = this_cpu_ptr(&bp_hardening_data); 70 + if (d->fn) 71 + d->fn(); 72 + } 73 + 31 74 enum mitigation_state arm64_get_spectre_v2_state(void); 32 75 bool has_spectre_v2(const struct arm64_cpu_capabilities *cap, int scope); 33 76 void spectre_v2_enable_mitigation(const struct arm64_cpu_capabilities *__unused); 77 + 78 + bool has_spectre_v3a(const struct arm64_cpu_capabilities *cap, int scope); 79 + void spectre_v3a_enable_mitigation(const struct arm64_cpu_capabilities *__unused); 34 80 35 81 enum mitigation_state arm64_get_spectre_v4_state(void); 36 82 bool has_spectre_v4(const struct arm64_cpu_capabilities *cap, int scope); 37 83 void spectre_v4_enable_mitigation(const struct arm64_cpu_capabilities *__unused); 38 84 void spectre_v4_enable_task_mitigation(struct task_struct *tsk); 39 85 86 + enum mitigation_state arm64_get_meltdown_state(void); 87 + 88 + #endif /* __ASSEMBLY__ */ 40 89 #endif /* __ASM_SPECTRE_H */
+17 -6
arch/arm64/include/asm/sysreg.h
··· 98 98 #define SET_PSTATE_SSBS(x) __emit_inst(0xd500401f | PSTATE_SSBS | ((!!x) << PSTATE_Imm_shift)) 99 99 #define SET_PSTATE_TCO(x) __emit_inst(0xd500401f | PSTATE_TCO | ((!!x) << PSTATE_Imm_shift)) 100 100 101 + #define set_pstate_pan(x) asm volatile(SET_PSTATE_PAN(x)) 102 + #define set_pstate_uao(x) asm volatile(SET_PSTATE_UAO(x)) 103 + #define set_pstate_ssbs(x) asm volatile(SET_PSTATE_SSBS(x)) 104 + 101 105 #define __SYS_BARRIER_INSN(CRm, op2, Rt) \ 102 106 __emit_inst(0xd5000000 | sys_insn(0, 3, 3, (CRm), (op2)) | ((Rt) & 0x1f)) 103 107 ··· 469 465 470 466 #define SYS_PMCCFILTR_EL0 sys_reg(3, 3, 14, 15, 7) 471 467 468 + #define SYS_SCTLR_EL2 sys_reg(3, 4, 1, 0, 0) 472 469 #define SYS_ZCR_EL2 sys_reg(3, 4, 1, 2, 0) 473 470 #define SYS_DACR32_EL2 sys_reg(3, 4, 3, 0, 0) 474 471 #define SYS_SPSR_EL2 sys_reg(3, 4, 4, 0, 0) ··· 587 582 #define ENDIAN_SET_EL2 0 588 583 #endif 589 584 585 + #define INIT_SCTLR_EL2_MMU_OFF \ 586 + (SCTLR_EL2_RES1 | ENDIAN_SET_EL2) 587 + 590 588 /* SCTLR_EL1 specific flags. */ 591 589 #define SCTLR_EL1_ATA0 (BIT(42)) 592 590 ··· 623 615 #define ENDIAN_SET_EL1 0 624 616 #endif 625 617 626 - #define SCTLR_EL1_SET (SCTLR_ELx_M | SCTLR_ELx_C | SCTLR_ELx_SA |\ 627 - SCTLR_EL1_SA0 | SCTLR_EL1_SED | SCTLR_ELx_I |\ 628 - SCTLR_EL1_DZE | SCTLR_EL1_UCT |\ 629 - SCTLR_EL1_NTWE | SCTLR_ELx_IESB | SCTLR_EL1_SPAN |\ 630 - SCTLR_ELx_ITFSB| SCTLR_ELx_ATA | SCTLR_EL1_ATA0 |\ 631 - ENDIAN_SET_EL1 | SCTLR_EL1_UCI | SCTLR_EL1_RES1) 618 + #define INIT_SCTLR_EL1_MMU_OFF \ 619 + (ENDIAN_SET_EL1 | SCTLR_EL1_RES1) 620 + 621 + #define INIT_SCTLR_EL1_MMU_ON \ 622 + (SCTLR_ELx_M | SCTLR_ELx_C | SCTLR_ELx_SA | SCTLR_EL1_SA0 | \ 623 + SCTLR_EL1_SED | SCTLR_ELx_I | SCTLR_EL1_DZE | SCTLR_EL1_UCT | \ 624 + SCTLR_EL1_NTWE | SCTLR_ELx_IESB | SCTLR_EL1_SPAN | SCTLR_ELx_ITFSB | \ 625 + SCTLR_ELx_ATA | SCTLR_EL1_ATA0 | ENDIAN_SET_EL1 | SCTLR_EL1_UCI | \ 626 + SCTLR_EL1_RES1) 632 627 633 628 /* MAIR_ELx memory attributes (used by Linux) */ 634 629 #define MAIR_ATTR_DEVICE_nGnRnE UL(0x00)
+2 -8
arch/arm64/include/asm/thread_info.h
··· 18 18 #include <asm/stack_pointer.h> 19 19 #include <asm/types.h> 20 20 21 - typedef unsigned long mm_segment_t; 22 - 23 21 /* 24 22 * low level task data that entry.S needs immediate access to. 25 23 */ 26 24 struct thread_info { 27 25 unsigned long flags; /* low level flags */ 28 - mm_segment_t addr_limit; /* address limit */ 29 26 #ifdef CONFIG_ARM64_SW_TTBR0_PAN 30 27 u64 ttbr0; /* saved TTBR0_EL1 */ 31 28 #endif ··· 63 66 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */ 64 67 #define TIF_FOREIGN_FPSTATE 3 /* CPU's FP state is not current's */ 65 68 #define TIF_UPROBE 4 /* uprobe breakpoint or singlestep */ 66 - #define TIF_FSCHECK 5 /* Check FS is USER_DS on return */ 67 - #define TIF_MTE_ASYNC_FAULT 6 /* MTE Asynchronous Tag Check Fault */ 69 + #define TIF_MTE_ASYNC_FAULT 5 /* MTE Asynchronous Tag Check Fault */ 68 70 #define TIF_SYSCALL_TRACE 8 /* syscall trace active */ 69 71 #define TIF_SYSCALL_AUDIT 9 /* syscall auditing */ 70 72 #define TIF_SYSCALL_TRACEPOINT 10 /* syscall tracepoint for ftrace */ ··· 89 93 #define _TIF_SECCOMP (1 << TIF_SECCOMP) 90 94 #define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU) 91 95 #define _TIF_UPROBE (1 << TIF_UPROBE) 92 - #define _TIF_FSCHECK (1 << TIF_FSCHECK) 93 96 #define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP) 94 97 #define _TIF_32BIT (1 << TIF_32BIT) 95 98 #define _TIF_SVE (1 << TIF_SVE) ··· 96 101 97 102 #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \ 98 103 _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \ 99 - _TIF_UPROBE | _TIF_FSCHECK | _TIF_MTE_ASYNC_FAULT) 104 + _TIF_UPROBE | _TIF_MTE_ASYNC_FAULT) 100 105 101 106 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ 102 107 _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ ··· 114 119 { \ 115 120 .flags = _TIF_FOREIGN_FPSTATE, \ 116 121 .preempt_count = INIT_PREEMPT_COUNT, \ 117 - .addr_limit = KERNEL_DS, \ 118 122 INIT_SCS \ 119 123 } 120 124
+75 -103
arch/arm64/include/asm/uaccess.h
··· 24 24 #include <asm/memory.h> 25 25 #include <asm/extable.h> 26 26 27 - #define get_fs() (current_thread_info()->addr_limit) 28 - 29 - static inline void set_fs(mm_segment_t fs) 30 - { 31 - current_thread_info()->addr_limit = fs; 32 - 33 - /* 34 - * Prevent a mispredicted conditional call to set_fs from forwarding 35 - * the wrong address limit to access_ok under speculation. 36 - */ 37 - spec_bar(); 38 - 39 - /* On user-mode return, check fs is correct */ 40 - set_thread_flag(TIF_FSCHECK); 41 - 42 - /* 43 - * Enable/disable UAO so that copy_to_user() etc can access 44 - * kernel memory with the unprivileged instructions. 45 - */ 46 - if (IS_ENABLED(CONFIG_ARM64_UAO) && fs == KERNEL_DS) 47 - asm(ALTERNATIVE("nop", SET_PSTATE_UAO(1), ARM64_HAS_UAO)); 48 - else 49 - asm(ALTERNATIVE("nop", SET_PSTATE_UAO(0), ARM64_HAS_UAO, 50 - CONFIG_ARM64_UAO)); 51 - } 52 - 53 - #define uaccess_kernel() (get_fs() == KERNEL_DS) 27 + #define HAVE_GET_KERNEL_NOFAULT 54 28 55 29 /* 56 30 * Test whether a block of memory is a valid user space address. 57 31 * Returns 1 if the range is valid, 0 otherwise. 58 32 * 59 33 * This is equivalent to the following test: 60 - * (u65)addr + (u65)size <= (u65)current->addr_limit + 1 34 + * (u65)addr + (u65)size <= (u65)TASK_SIZE_MAX 61 35 */ 62 36 static inline unsigned long __range_ok(const void __user *addr, unsigned long size) 63 37 { 64 - unsigned long ret, limit = current_thread_info()->addr_limit; 38 + unsigned long ret, limit = TASK_SIZE_MAX - 1; 65 39 66 40 /* 67 41 * Asynchronous I/O running in a kernel thread does not have the ··· 68 94 } 69 95 70 96 #define access_ok(addr, size) __range_ok(addr, size) 71 - #define user_addr_max get_fs 72 97 73 98 #define _ASM_EXTABLE(from, to) \ 74 99 " .pushsection __ex_table, \"a\"\n" \ ··· 159 186 CONFIG_ARM64_PAN)); 160 187 } 161 188 162 - #define __uaccess_disable(alt) \ 163 - do { \ 164 - if (!uaccess_ttbr0_disable()) \ 165 - asm(ALTERNATIVE("nop", SET_PSTATE_PAN(1), alt, \ 166 - CONFIG_ARM64_PAN)); \ 167 - } while (0) 168 - 169 - #define __uaccess_enable(alt) \ 170 - do { \ 171 - if (!uaccess_ttbr0_enable()) \ 172 - asm(ALTERNATIVE("nop", SET_PSTATE_PAN(0), alt, \ 173 - CONFIG_ARM64_PAN)); \ 174 - } while (0) 175 - 176 - static inline void uaccess_disable(void) 189 + static inline void uaccess_disable_privileged(void) 177 190 { 178 - __uaccess_disable(ARM64_HAS_PAN); 191 + if (uaccess_ttbr0_disable()) 192 + return; 193 + 194 + __uaccess_enable_hw_pan(); 179 195 } 180 196 181 - static inline void uaccess_enable(void) 197 + static inline void uaccess_enable_privileged(void) 182 198 { 183 - __uaccess_enable(ARM64_HAS_PAN); 199 + if (uaccess_ttbr0_enable()) 200 + return; 201 + 202 + __uaccess_disable_hw_pan(); 184 203 } 185 204 186 205 /* 187 - * These functions are no-ops when UAO is present. 188 - */ 189 - static inline void uaccess_disable_not_uao(void) 190 - { 191 - __uaccess_disable(ARM64_ALT_PAN_NOT_UAO); 192 - } 193 - 194 - static inline void uaccess_enable_not_uao(void) 195 - { 196 - __uaccess_enable(ARM64_ALT_PAN_NOT_UAO); 197 - } 198 - 199 - /* 200 - * Sanitise a uaccess pointer such that it becomes NULL if above the 201 - * current addr_limit. In case the pointer is tagged (has the top byte set), 202 - * untag the pointer before checking. 206 + * Sanitise a uaccess pointer such that it becomes NULL if above the maximum 207 + * user address. In case the pointer is tagged (has the top byte set), untag 208 + * the pointer before checking. 203 209 */ 204 210 #define uaccess_mask_ptr(ptr) (__typeof__(ptr))__uaccess_mask_ptr(ptr) 205 211 static inline void __user *__uaccess_mask_ptr(const void __user *ptr) ··· 189 237 " bics xzr, %3, %2\n" 190 238 " csel %0, %1, xzr, eq\n" 191 239 : "=&r" (safe_ptr) 192 - : "r" (ptr), "r" (current_thread_info()->addr_limit), 240 + : "r" (ptr), "r" (TASK_SIZE_MAX - 1), 193 241 "r" (untagged_addr(ptr)) 194 242 : "cc"); 195 243 ··· 205 253 * The "__xxx_error" versions set the third argument to -EFAULT if an error 206 254 * occurs, and leave it unchanged on success. 207 255 */ 208 - #define __get_user_asm(instr, alt_instr, reg, x, addr, err, feature) \ 256 + #define __get_mem_asm(load, reg, x, addr, err) \ 209 257 asm volatile( \ 210 - "1:"ALTERNATIVE(instr " " reg "1, [%2]\n", \ 211 - alt_instr " " reg "1, [%2]\n", feature) \ 258 + "1: " load " " reg "1, [%2]\n" \ 212 259 "2:\n" \ 213 260 " .section .fixup, \"ax\"\n" \ 214 261 " .align 2\n" \ ··· 219 268 : "+r" (err), "=&r" (x) \ 220 269 : "r" (addr), "i" (-EFAULT)) 221 270 222 - #define __raw_get_user(x, ptr, err) \ 271 + #define __raw_get_mem(ldr, x, ptr, err) \ 223 272 do { \ 224 273 unsigned long __gu_val; \ 225 - __chk_user_ptr(ptr); \ 226 - uaccess_enable_not_uao(); \ 227 274 switch (sizeof(*(ptr))) { \ 228 275 case 1: \ 229 - __get_user_asm("ldrb", "ldtrb", "%w", __gu_val, (ptr), \ 230 - (err), ARM64_HAS_UAO); \ 276 + __get_mem_asm(ldr "b", "%w", __gu_val, (ptr), (err)); \ 231 277 break; \ 232 278 case 2: \ 233 - __get_user_asm("ldrh", "ldtrh", "%w", __gu_val, (ptr), \ 234 - (err), ARM64_HAS_UAO); \ 279 + __get_mem_asm(ldr "h", "%w", __gu_val, (ptr), (err)); \ 235 280 break; \ 236 281 case 4: \ 237 - __get_user_asm("ldr", "ldtr", "%w", __gu_val, (ptr), \ 238 - (err), ARM64_HAS_UAO); \ 282 + __get_mem_asm(ldr, "%w", __gu_val, (ptr), (err)); \ 239 283 break; \ 240 284 case 8: \ 241 - __get_user_asm("ldr", "ldtr", "%x", __gu_val, (ptr), \ 242 - (err), ARM64_HAS_UAO); \ 285 + __get_mem_asm(ldr, "%x", __gu_val, (ptr), (err)); \ 243 286 break; \ 244 287 default: \ 245 288 BUILD_BUG(); \ 246 289 } \ 247 - uaccess_disable_not_uao(); \ 248 290 (x) = (__force __typeof__(*(ptr)))__gu_val; \ 291 + } while (0) 292 + 293 + #define __raw_get_user(x, ptr, err) \ 294 + do { \ 295 + __chk_user_ptr(ptr); \ 296 + uaccess_ttbr0_enable(); \ 297 + __raw_get_mem("ldtr", x, ptr, err); \ 298 + uaccess_ttbr0_disable(); \ 249 299 } while (0) 250 300 251 301 #define __get_user_error(x, ptr, err) \ ··· 270 318 271 319 #define get_user __get_user 272 320 273 - #define __put_user_asm(instr, alt_instr, reg, x, addr, err, feature) \ 321 + #define __get_kernel_nofault(dst, src, type, err_label) \ 322 + do { \ 323 + int __gkn_err = 0; \ 324 + \ 325 + __raw_get_mem("ldr", *((type *)(dst)), \ 326 + (__force type *)(src), __gkn_err); \ 327 + if (unlikely(__gkn_err)) \ 328 + goto err_label; \ 329 + } while (0) 330 + 331 + #define __put_mem_asm(store, reg, x, addr, err) \ 274 332 asm volatile( \ 275 - "1:"ALTERNATIVE(instr " " reg "1, [%2]\n", \ 276 - alt_instr " " reg "1, [%2]\n", feature) \ 333 + "1: " store " " reg "1, [%2]\n" \ 277 334 "2:\n" \ 278 335 " .section .fixup,\"ax\"\n" \ 279 336 " .align 2\n" \ ··· 293 332 : "+r" (err) \ 294 333 : "r" (x), "r" (addr), "i" (-EFAULT)) 295 334 296 - #define __raw_put_user(x, ptr, err) \ 335 + #define __raw_put_mem(str, x, ptr, err) \ 297 336 do { \ 298 337 __typeof__(*(ptr)) __pu_val = (x); \ 299 - __chk_user_ptr(ptr); \ 300 - uaccess_enable_not_uao(); \ 301 338 switch (sizeof(*(ptr))) { \ 302 339 case 1: \ 303 - __put_user_asm("strb", "sttrb", "%w", __pu_val, (ptr), \ 304 - (err), ARM64_HAS_UAO); \ 340 + __put_mem_asm(str "b", "%w", __pu_val, (ptr), (err)); \ 305 341 break; \ 306 342 case 2: \ 307 - __put_user_asm("strh", "sttrh", "%w", __pu_val, (ptr), \ 308 - (err), ARM64_HAS_UAO); \ 343 + __put_mem_asm(str "h", "%w", __pu_val, (ptr), (err)); \ 309 344 break; \ 310 345 case 4: \ 311 - __put_user_asm("str", "sttr", "%w", __pu_val, (ptr), \ 312 - (err), ARM64_HAS_UAO); \ 346 + __put_mem_asm(str, "%w", __pu_val, (ptr), (err)); \ 313 347 break; \ 314 348 case 8: \ 315 - __put_user_asm("str", "sttr", "%x", __pu_val, (ptr), \ 316 - (err), ARM64_HAS_UAO); \ 349 + __put_mem_asm(str, "%x", __pu_val, (ptr), (err)); \ 317 350 break; \ 318 351 default: \ 319 352 BUILD_BUG(); \ 320 353 } \ 321 - uaccess_disable_not_uao(); \ 354 + } while (0) 355 + 356 + #define __raw_put_user(x, ptr, err) \ 357 + do { \ 358 + __chk_user_ptr(ptr); \ 359 + uaccess_ttbr0_enable(); \ 360 + __raw_put_mem("sttr", x, ptr, err); \ 361 + uaccess_ttbr0_disable(); \ 322 362 } while (0) 323 363 324 364 #define __put_user_error(x, ptr, err) \ ··· 343 381 344 382 #define put_user __put_user 345 383 384 + #define __put_kernel_nofault(dst, src, type, err_label) \ 385 + do { \ 386 + int __pkn_err = 0; \ 387 + \ 388 + __raw_put_mem("str", *((type *)(src)), \ 389 + (__force type *)(dst), __pkn_err); \ 390 + if (unlikely(__pkn_err)) \ 391 + goto err_label; \ 392 + } while(0) 393 + 346 394 extern unsigned long __must_check __arch_copy_from_user(void *to, const void __user *from, unsigned long n); 347 395 #define raw_copy_from_user(to, from, n) \ 348 396 ({ \ 349 397 unsigned long __acfu_ret; \ 350 - uaccess_enable_not_uao(); \ 398 + uaccess_ttbr0_enable(); \ 351 399 __acfu_ret = __arch_copy_from_user((to), \ 352 400 __uaccess_mask_ptr(from), (n)); \ 353 - uaccess_disable_not_uao(); \ 401 + uaccess_ttbr0_disable(); \ 354 402 __acfu_ret; \ 355 403 }) 356 404 ··· 368 396 #define raw_copy_to_user(to, from, n) \ 369 397 ({ \ 370 398 unsigned long __actu_ret; \ 371 - uaccess_enable_not_uao(); \ 399 + uaccess_ttbr0_enable(); \ 372 400 __actu_ret = __arch_copy_to_user(__uaccess_mask_ptr(to), \ 373 401 (from), (n)); \ 374 - uaccess_disable_not_uao(); \ 402 + uaccess_ttbr0_disable(); \ 375 403 __actu_ret; \ 376 404 }) 377 405 ··· 379 407 #define raw_copy_in_user(to, from, n) \ 380 408 ({ \ 381 409 unsigned long __aciu_ret; \ 382 - uaccess_enable_not_uao(); \ 410 + uaccess_ttbr0_enable(); \ 383 411 __aciu_ret = __arch_copy_in_user(__uaccess_mask_ptr(to), \ 384 412 __uaccess_mask_ptr(from), (n)); \ 385 - uaccess_disable_not_uao(); \ 413 + uaccess_ttbr0_disable(); \ 386 414 __aciu_ret; \ 387 415 }) 388 416 ··· 393 421 static inline unsigned long __must_check __clear_user(void __user *to, unsigned long n) 394 422 { 395 423 if (access_ok(to, n)) { 396 - uaccess_enable_not_uao(); 424 + uaccess_ttbr0_enable(); 397 425 n = __arch_clear_user(__uaccess_mask_ptr(to), n); 398 - uaccess_disable_not_uao(); 426 + uaccess_ttbr0_disable(); 399 427 } 400 428 return n; 401 429 }
+26
arch/arm64/include/asm/virt.h
··· 65 65 void __hyp_set_vectors(phys_addr_t phys_vector_base); 66 66 void __hyp_reset_vectors(void); 67 67 68 + DECLARE_STATIC_KEY_FALSE(kvm_protected_mode_initialized); 69 + 68 70 /* Reports the availability of HYP mode */ 69 71 static inline bool is_hyp_mode_available(void) 70 72 { 73 + /* 74 + * If KVM protected mode is initialized, all CPUs must have been booted 75 + * in EL2. Avoid checking __boot_cpu_mode as CPUs now come up in EL1. 76 + */ 77 + if (IS_ENABLED(CONFIG_KVM) && 78 + static_branch_likely(&kvm_protected_mode_initialized)) 79 + return true; 80 + 71 81 return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 && 72 82 __boot_cpu_mode[1] == BOOT_CPU_MODE_EL2); 73 83 } ··· 85 75 /* Check if the bootloader has booted CPUs in different modes */ 86 76 static inline bool is_hyp_mode_mismatched(void) 87 77 { 78 + /* 79 + * If KVM protected mode is initialized, all CPUs must have been booted 80 + * in EL2. Avoid checking __boot_cpu_mode as CPUs now come up in EL1. 81 + */ 82 + if (IS_ENABLED(CONFIG_KVM) && 83 + static_branch_likely(&kvm_protected_mode_initialized)) 84 + return false; 85 + 88 86 return __boot_cpu_mode[0] != __boot_cpu_mode[1]; 89 87 } 90 88 ··· 113 95 return false; 114 96 else 115 97 return cpus_have_final_cap(ARM64_HAS_VIRT_HOST_EXTN); 98 + } 99 + 100 + static __always_inline bool is_protected_kvm_enabled(void) 101 + { 102 + if (is_vhe_hyp_code()) 103 + return false; 104 + else 105 + return cpus_have_final_cap(ARM64_KVM_PROTECTED_MODE); 116 106 } 117 107 118 108 #endif /* __ASSEMBLY__ */
-3
arch/arm64/include/uapi/asm/kvm.h
··· 156 156 __u64 device_irq_level; 157 157 }; 158 158 159 - struct kvm_arch_memory_slot { 160 - }; 161 - 162 159 /* 163 160 * PMU filter structure. Describe a range of events with a particular 164 161 * action. To be used with KVM_ARM_VCPU_PMU_V3_FILTER.
+4 -3
arch/arm64/kernel/alternative.c
··· 21 21 #define ALT_ORIG_PTR(a) __ALT_PTR(a, orig_offset) 22 22 #define ALT_REPL_PTR(a) __ALT_PTR(a, alt_offset) 23 23 24 - static int all_alternatives_applied; 24 + /* Volatile, as we may be patching the guts of READ_ONCE() */ 25 + static volatile int all_alternatives_applied; 25 26 26 27 static DECLARE_BITMAP(applied_alternatives, ARM64_NCAPS); 27 28 ··· 206 205 207 206 /* We always have a CPU 0 at this point (__init) */ 208 207 if (smp_processor_id()) { 209 - while (!READ_ONCE(all_alternatives_applied)) 208 + while (!all_alternatives_applied) 210 209 cpu_relax(); 211 210 isb(); 212 211 } else { ··· 218 217 BUG_ON(all_alternatives_applied); 219 218 __apply_alternatives(&region, false, remaining_capabilities); 220 219 /* Barriers provided by the cache flushing */ 221 - WRITE_ONCE(all_alternatives_applied, 1); 220 + all_alternatives_applied = 1; 222 221 } 223 222 224 223 return 0;
+2 -2
arch/arm64/kernel/armv8_deprecated.c
··· 277 277 278 278 #define __user_swpX_asm(data, addr, res, temp, temp2, B) \ 279 279 do { \ 280 - uaccess_enable(); \ 280 + uaccess_enable_privileged(); \ 281 281 __asm__ __volatile__( \ 282 282 " mov %w3, %w7\n" \ 283 283 "0: ldxr"B" %w2, [%4]\n" \ ··· 302 302 "i" (-EFAULT), \ 303 303 "i" (__SWP_LL_SC_LOOPS) \ 304 304 : "memory"); \ 305 - uaccess_disable(); \ 305 + uaccess_disable_privileged(); \ 306 306 } while (0) 307 307 308 308 #define __user_swp_asm(data, addr, res, temp, temp2) \
+6 -2
arch/arm64/kernel/asm-offsets.c
··· 30 30 BLANK(); 31 31 DEFINE(TSK_TI_FLAGS, offsetof(struct task_struct, thread_info.flags)); 32 32 DEFINE(TSK_TI_PREEMPT, offsetof(struct task_struct, thread_info.preempt_count)); 33 - DEFINE(TSK_TI_ADDR_LIMIT, offsetof(struct task_struct, thread_info.addr_limit)); 34 33 #ifdef CONFIG_ARM64_SW_TTBR0_PAN 35 34 DEFINE(TSK_TI_TTBR0, offsetof(struct task_struct, thread_info.ttbr0)); 36 35 #endif ··· 69 70 DEFINE(S_PSTATE, offsetof(struct pt_regs, pstate)); 70 71 DEFINE(S_PC, offsetof(struct pt_regs, pc)); 71 72 DEFINE(S_SYSCALLNO, offsetof(struct pt_regs, syscallno)); 72 - DEFINE(S_ORIG_ADDR_LIMIT, offsetof(struct pt_regs, orig_addr_limit)); 73 + DEFINE(S_SDEI_TTBR1, offsetof(struct pt_regs, sdei_ttbr1)); 73 74 DEFINE(S_PMR_SAVE, offsetof(struct pt_regs, pmr_save)); 74 75 DEFINE(S_STACKFRAME, offsetof(struct pt_regs, stackframe)); 75 76 DEFINE(S_FRAME_SIZE, sizeof(struct pt_regs)); ··· 109 110 DEFINE(CPU_APGAKEYLO_EL1, offsetof(struct kvm_cpu_context, sys_regs[APGAKEYLO_EL1])); 110 111 DEFINE(HOST_CONTEXT_VCPU, offsetof(struct kvm_cpu_context, __hyp_running_vcpu)); 111 112 DEFINE(HOST_DATA_CONTEXT, offsetof(struct kvm_host_data, host_ctxt)); 113 + DEFINE(NVHE_INIT_MAIR_EL2, offsetof(struct kvm_nvhe_init_params, mair_el2)); 114 + DEFINE(NVHE_INIT_TCR_EL2, offsetof(struct kvm_nvhe_init_params, tcr_el2)); 115 + DEFINE(NVHE_INIT_TPIDR_EL2, offsetof(struct kvm_nvhe_init_params, tpidr_el2)); 116 + DEFINE(NVHE_INIT_STACK_HYP_VA, offsetof(struct kvm_nvhe_init_params, stack_hyp_va)); 117 + DEFINE(NVHE_INIT_PGD_PA, offsetof(struct kvm_nvhe_init_params, pgd_pa)); 112 118 #endif 113 119 #ifdef CONFIG_CPU_PM 114 120 DEFINE(CPU_CTX_SP, offsetof(struct cpu_suspend_ctx, sp));
+8 -13
arch/arm64/kernel/cpu_errata.c
··· 196 196 return is_midr_in_range(midr, &range) && has_dic; 197 197 } 198 198 199 - #ifdef CONFIG_RANDOMIZE_BASE 200 - 201 - static const struct midr_range ca57_a72[] = { 202 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), 203 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), 204 - {}, 205 - }; 206 - 207 - #endif 208 - 209 199 #ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI 210 200 static const struct arm64_cpu_capabilities arm64_repeat_tlbi_list[] = { 211 201 #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009 ··· 289 299 MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4), 290 300 /* Brahma-B53 r0p[0] */ 291 301 MIDR_REV(MIDR_BRAHMA_B53, 0, 0), 302 + /* Kryo2XX Silver rAp4 */ 303 + MIDR_REV(MIDR_QCOM_KRYO_2XX_SILVER, 0xa, 0x4), 292 304 {}, 293 305 }; 294 306 #endif ··· 451 459 }, 452 460 #ifdef CONFIG_RANDOMIZE_BASE 453 461 { 454 - .desc = "EL2 vector hardening", 455 - .capability = ARM64_HARDEN_EL2_VECTORS, 456 - ERRATA_MIDR_RANGE_LIST(ca57_a72), 462 + /* Must come after the Spectre-v2 entry */ 463 + .desc = "Spectre-v3a", 464 + .capability = ARM64_SPECTRE_V3A, 465 + .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, 466 + .matches = has_spectre_v3a, 467 + .cpu_enable = spectre_v3a_enable_mitigation, 457 468 }, 458 469 #endif 459 470 {
+53 -37
arch/arm64/kernel/cpufeature.c
··· 74 74 #include <asm/cpufeature.h> 75 75 #include <asm/cpu_ops.h> 76 76 #include <asm/fpsimd.h> 77 + #include <asm/kvm_host.h> 77 78 #include <asm/mmu_context.h> 78 79 #include <asm/mte.h> 79 80 #include <asm/processor.h> ··· 153 152 { \ 154 153 .width = 0, \ 155 154 } 156 - 157 - /* meta feature for alternatives */ 158 - static bool __maybe_unused 159 - cpufeature_pan_not_uao(const struct arm64_cpu_capabilities *entry, int __unused); 160 155 161 156 static void cpu_enable_cnp(struct arm64_cpu_capabilities const *cap); 162 157 ··· 1334 1337 MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), 1335 1338 MIDR_ALL_VERSIONS(MIDR_HISI_TSV110), 1336 1339 MIDR_ALL_VERSIONS(MIDR_NVIDIA_CARMEL), 1340 + MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_2XX_GOLD), 1341 + MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_2XX_SILVER), 1337 1342 MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_3XX_SILVER), 1338 1343 MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_4XX_SILVER), 1339 1344 { /* sentinel */ } ··· 1597 1598 WARN_ON_ONCE(in_interrupt()); 1598 1599 1599 1600 sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPAN, 0); 1600 - asm(SET_PSTATE_PAN(1)); 1601 + set_pstate_pan(1); 1601 1602 } 1602 1603 #endif /* CONFIG_ARM64_PAN */ 1603 1604 ··· 1706 1707 } 1707 1708 #endif /* CONFIG_ARM64_MTE */ 1708 1709 1710 + #ifdef CONFIG_KVM 1711 + static bool is_kvm_protected_mode(const struct arm64_cpu_capabilities *entry, int __unused) 1712 + { 1713 + if (kvm_get_mode() != KVM_MODE_PROTECTED) 1714 + return false; 1715 + 1716 + if (is_kernel_in_hyp_mode()) { 1717 + pr_warn("Protected KVM not available with VHE\n"); 1718 + return false; 1719 + } 1720 + 1721 + return true; 1722 + } 1723 + #endif /* CONFIG_KVM */ 1724 + 1709 1725 /* Internal helper functions to match cpu capability type */ 1710 1726 static bool 1711 1727 cpucap_late_cpu_optional(const struct arm64_cpu_capabilities *cap) ··· 1782 1768 .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE, 1783 1769 .matches = has_no_hw_prefetch, 1784 1770 }, 1785 - #ifdef CONFIG_ARM64_UAO 1786 - { 1787 - .desc = "User Access Override", 1788 - .capability = ARM64_HAS_UAO, 1789 - .type = ARM64_CPUCAP_SYSTEM_FEATURE, 1790 - .matches = has_cpuid_feature, 1791 - .sys_reg = SYS_ID_AA64MMFR2_EL1, 1792 - .field_pos = ID_AA64MMFR2_UAO_SHIFT, 1793 - .min_field_value = 1, 1794 - /* 1795 - * We rely on stop_machine() calling uao_thread_switch() to set 1796 - * UAO immediately after patching. 1797 - */ 1798 - }, 1799 - #endif /* CONFIG_ARM64_UAO */ 1800 - #ifdef CONFIG_ARM64_PAN 1801 - { 1802 - .capability = ARM64_ALT_PAN_NOT_UAO, 1803 - .type = ARM64_CPUCAP_SYSTEM_FEATURE, 1804 - .matches = cpufeature_pan_not_uao, 1805 - }, 1806 - #endif /* CONFIG_ARM64_PAN */ 1807 1771 #ifdef CONFIG_ARM64_VHE 1808 1772 { 1809 1773 .desc = "Virtualization Host Extensions", ··· 1811 1819 .sign = FTR_UNSIGNED, 1812 1820 .field_pos = ID_AA64PFR0_EL1_SHIFT, 1813 1821 .min_field_value = ID_AA64PFR0_EL1_32BIT_64BIT, 1822 + }, 1823 + { 1824 + .desc = "Protected KVM", 1825 + .capability = ARM64_KVM_PROTECTED_MODE, 1826 + .type = ARM64_CPUCAP_SYSTEM_FEATURE, 1827 + .matches = is_kvm_protected_mode, 1814 1828 }, 1815 1829 #endif 1816 1830 { ··· 2134 2136 .cpu_enable = cpu_enable_mte, 2135 2137 }, 2136 2138 #endif /* CONFIG_ARM64_MTE */ 2139 + { 2140 + .desc = "RCpc load-acquire (LDAPR)", 2141 + .capability = ARM64_HAS_LDAPR, 2142 + .type = ARM64_CPUCAP_SYSTEM_FEATURE, 2143 + .sys_reg = SYS_ID_AA64ISAR1_EL1, 2144 + .sign = FTR_UNSIGNED, 2145 + .field_pos = ID_AA64ISAR1_LRCPC_SHIFT, 2146 + .matches = has_cpuid_feature, 2147 + .min_field_value = 1, 2148 + }, 2137 2149 {}, 2138 2150 }; 2139 2151 ··· 2658 2650 * - The SYSTEM_FEATURE cpu_hwcaps may not have been set. 2659 2651 * In all other cases cpus_have_{const_}cap() should be used. 2660 2652 */ 2661 - static bool __system_matches_cap(unsigned int n) 2653 + static bool __maybe_unused __system_matches_cap(unsigned int n) 2662 2654 { 2663 2655 if (n < ARM64_NCAPS) { 2664 2656 const struct arm64_cpu_capabilities *cap = cpu_hwcaps_ptrs[n]; ··· 2736 2728 if (!cwg) 2737 2729 pr_warn("No Cache Writeback Granule information, assuming %d\n", 2738 2730 ARCH_DMA_MINALIGN); 2739 - } 2740 - 2741 - static bool __maybe_unused 2742 - cpufeature_pan_not_uao(const struct arm64_cpu_capabilities *entry, int __unused) 2743 - { 2744 - return (__system_matches_cap(ARM64_HAS_PAN) && !__system_matches_cap(ARM64_HAS_UAO)); 2745 2731 } 2746 2732 2747 2733 static void __maybe_unused cpu_enable_cnp(struct arm64_cpu_capabilities const *cap) ··· 2846 2844 2847 2845 core_initcall(enable_mrs_emulation); 2848 2846 2847 + enum mitigation_state arm64_get_meltdown_state(void) 2848 + { 2849 + if (__meltdown_safe) 2850 + return SPECTRE_UNAFFECTED; 2851 + 2852 + if (arm64_kernel_unmapped_at_el0()) 2853 + return SPECTRE_MITIGATED; 2854 + 2855 + return SPECTRE_VULNERABLE; 2856 + } 2857 + 2849 2858 ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, 2850 2859 char *buf) 2851 2860 { 2852 - if (__meltdown_safe) 2861 + switch (arm64_get_meltdown_state()) { 2862 + case SPECTRE_UNAFFECTED: 2853 2863 return sprintf(buf, "Not affected\n"); 2854 2864 2855 - if (arm64_kernel_unmapped_at_el0()) 2865 + case SPECTRE_MITIGATED: 2856 2866 return sprintf(buf, "Mitigation: PTI\n"); 2857 2867 2858 - return sprintf(buf, "Vulnerable\n"); 2868 + default: 2869 + return sprintf(buf, "Vulnerable\n"); 2870 + } 2859 2871 }
+3 -16
arch/arm64/kernel/entry.S
··· 216 216 .else 217 217 add x21, sp, #S_FRAME_SIZE 218 218 get_current_task tsk 219 - /* Save the task's original addr_limit and set USER_DS */ 220 - ldr x20, [tsk, #TSK_TI_ADDR_LIMIT] 221 - str x20, [sp, #S_ORIG_ADDR_LIMIT] 222 - mov x20, #USER_DS 223 - str x20, [tsk, #TSK_TI_ADDR_LIMIT] 224 - /* No need to reset PSTATE.UAO, hardware's already set it to 0 for us */ 225 219 .endif /* \el == 0 */ 226 220 mrs x22, elr_el1 227 221 mrs x23, spsr_el1 ··· 273 279 .macro kernel_exit, el 274 280 .if \el != 0 275 281 disable_daif 276 - 277 - /* Restore the task's original addr_limit. */ 278 - ldr x20, [sp, #S_ORIG_ADDR_LIMIT] 279 - str x20, [tsk, #TSK_TI_ADDR_LIMIT] 280 - 281 - /* No need to restore UAO, it will be restored from SPSR_EL1 */ 282 282 .endif 283 283 284 284 /* Restore pmr */ ··· 987 999 mov x4, xzr 988 1000 989 1001 /* 990 - * Use reg->interrupted_regs.addr_limit to remember whether to unmap 991 - * the kernel on exit. 1002 + * Remember whether to unmap the kernel on exit. 992 1003 */ 993 - 1: str x4, [x1, #(SDEI_EVENT_INTREGS + S_ORIG_ADDR_LIMIT)] 1004 + 1: str x4, [x1, #(SDEI_EVENT_INTREGS + S_SDEI_TTBR1)] 994 1005 995 1006 #ifdef CONFIG_RANDOMIZE_BASE 996 1007 adr x4, tramp_vectors + PAGE_SIZE ··· 1010 1023 * x4: struct sdei_registered_event argument from registration time. 1011 1024 */ 1012 1025 SYM_CODE_START(__sdei_asm_exit_trampoline) 1013 - ldr x4, [x4, #(SDEI_EVENT_INTREGS + S_ORIG_ADDR_LIMIT)] 1026 + ldr x4, [x4, #(SDEI_EVENT_INTREGS + S_SDEI_TTBR1)] 1014 1027 cbnz x4, 1f 1015 1028 1016 1029 tramp_unmap_kernel tmp=x4
+55 -143
arch/arm64/kernel/head.S
··· 11 11 12 12 #include <linux/linkage.h> 13 13 #include <linux/init.h> 14 - #include <linux/irqchip/arm-gic-v3.h> 15 14 #include <linux/pgtable.h> 16 15 17 16 #include <asm/asm_pointer_auth.h> ··· 20 21 #include <asm/asm-offsets.h> 21 22 #include <asm/cache.h> 22 23 #include <asm/cputype.h> 24 + #include <asm/el2_setup.h> 23 25 #include <asm/elf.h> 24 26 #include <asm/image.h> 25 27 #include <asm/kernel-pgtable.h> ··· 104 104 */ 105 105 SYM_CODE_START(primary_entry) 106 106 bl preserve_boot_args 107 - bl el2_setup // Drop to EL1, w0=cpu_boot_mode 107 + bl init_kernel_el // w0=cpu_boot_mode 108 108 adrp x23, __PHYS_OFFSET 109 109 and x23, x23, MIN_KIMG_ALIGN - 1 // KASLR offset, defaults to 0 110 110 bl set_cpu_boot_mode_flag ··· 482 482 .section ".idmap.text","awx" 483 483 484 484 /* 485 - * If we're fortunate enough to boot at EL2, ensure that the world is 486 - * sane before dropping to EL1. 485 + * Starting from EL2 or EL1, configure the CPU to execute at the highest 486 + * reachable EL supported by the kernel in a chosen default state. If dropping 487 + * from EL2 to EL1, configure EL2 before configuring EL1. 488 + * 489 + * Since we cannot always rely on ERET synchronizing writes to sysregs (e.g. if 490 + * SCTLR_ELx.EOS is clear), we place an ISB prior to ERET. 487 491 * 488 492 * Returns either BOOT_CPU_MODE_EL1 or BOOT_CPU_MODE_EL2 in w0 if 489 493 * booted in EL1 or EL2 respectively. 490 494 */ 491 - SYM_FUNC_START(el2_setup) 492 - msr SPsel, #1 // We want to use SP_EL{1,2} 495 + SYM_FUNC_START(init_kernel_el) 493 496 mrs x0, CurrentEL 494 497 cmp x0, #CurrentEL_EL2 495 - b.eq 1f 496 - mov_q x0, (SCTLR_EL1_RES1 | ENDIAN_SET_EL1) 498 + b.eq init_el2 499 + 500 + SYM_INNER_LABEL(init_el1, SYM_L_LOCAL) 501 + mov_q x0, INIT_SCTLR_EL1_MMU_OFF 497 502 msr sctlr_el1, x0 498 - mov w0, #BOOT_CPU_MODE_EL1 // This cpu booted in EL1 499 503 isb 500 - ret 504 + mov_q x0, INIT_PSTATE_EL1 505 + msr spsr_el1, x0 506 + msr elr_el1, lr 507 + mov w0, #BOOT_CPU_MODE_EL1 508 + eret 501 509 502 - 1: mov_q x0, (SCTLR_EL2_RES1 | ENDIAN_SET_EL2) 503 - msr sctlr_el2, x0 504 - 510 + SYM_INNER_LABEL(init_el2, SYM_L_LOCAL) 505 511 #ifdef CONFIG_ARM64_VHE 506 512 /* 507 - * Check for VHE being present. For the rest of the EL2 setup, 508 - * x2 being non-zero indicates that we do have VHE, and that the 509 - * kernel is intended to run at EL2. 513 + * Check for VHE being present. x2 being non-zero indicates that we 514 + * do have VHE, and that the kernel is intended to run at EL2. 510 515 */ 511 516 mrs x2, id_aa64mmfr1_el1 512 517 ubfx x2, x2, #ID_AA64MMFR1_VHE_SHIFT, #4 513 518 #else 514 519 mov x2, xzr 515 520 #endif 516 - 517 - /* Hyp configuration. */ 518 - mov_q x0, HCR_HOST_NVHE_FLAGS 519 - cbz x2, set_hcr 520 - mov_q x0, HCR_HOST_VHE_FLAGS 521 - set_hcr: 522 - msr hcr_el2, x0 523 - isb 521 + cbz x2, init_el2_nvhe 524 522 525 523 /* 526 - * Allow Non-secure EL1 and EL0 to access physical timer and counter. 527 - * This is not necessary for VHE, since the host kernel runs in EL2, 528 - * and EL0 accesses are configured in the later stage of boot process. 529 - * Note that when HCR_EL2.E2H == 1, CNTHCTL_EL2 has the same bit layout 530 - * as CNTKCTL_EL1, and CNTKCTL_EL1 accessing instructions are redefined 531 - * to access CNTHCTL_EL2. This allows the kernel designed to run at EL1 532 - * to transparently mess with the EL0 bits via CNTKCTL_EL1 access in 533 - * EL2. 534 - */ 535 - cbnz x2, 1f 536 - mrs x0, cnthctl_el2 537 - orr x0, x0, #3 // Enable EL1 physical timers 538 - msr cnthctl_el2, x0 539 - 1: 540 - msr cntvoff_el2, xzr // Clear virtual offset 541 - 542 - #ifdef CONFIG_ARM_GIC_V3 543 - /* GICv3 system register access */ 544 - mrs x0, id_aa64pfr0_el1 545 - ubfx x0, x0, #ID_AA64PFR0_GIC_SHIFT, #4 546 - cbz x0, 3f 547 - 548 - mrs_s x0, SYS_ICC_SRE_EL2 549 - orr x0, x0, #ICC_SRE_EL2_SRE // Set ICC_SRE_EL2.SRE==1 550 - orr x0, x0, #ICC_SRE_EL2_ENABLE // Set ICC_SRE_EL2.Enable==1 551 - msr_s SYS_ICC_SRE_EL2, x0 552 - isb // Make sure SRE is now set 553 - mrs_s x0, SYS_ICC_SRE_EL2 // Read SRE back, 554 - tbz x0, #0, 3f // and check that it sticks 555 - msr_s SYS_ICH_HCR_EL2, xzr // Reset ICC_HCR_EL2 to defaults 556 - 557 - 3: 558 - #endif 559 - 560 - /* Populate ID registers. */ 561 - mrs x0, midr_el1 562 - mrs x1, mpidr_el1 563 - msr vpidr_el2, x0 564 - msr vmpidr_el2, x1 565 - 566 - #ifdef CONFIG_COMPAT 567 - msr hstr_el2, xzr // Disable CP15 traps to EL2 568 - #endif 569 - 570 - /* EL2 debug */ 571 - mrs x1, id_aa64dfr0_el1 572 - sbfx x0, x1, #ID_AA64DFR0_PMUVER_SHIFT, #4 573 - cmp x0, #1 574 - b.lt 4f // Skip if no PMU present 575 - mrs x0, pmcr_el0 // Disable debug access traps 576 - ubfx x0, x0, #11, #5 // to EL2 and allow access to 577 - 4: 578 - csel x3, xzr, x0, lt // all PMU counters from EL1 579 - 580 - /* Statistical profiling */ 581 - ubfx x0, x1, #ID_AA64DFR0_PMSVER_SHIFT, #4 582 - cbz x0, 7f // Skip if SPE not present 583 - cbnz x2, 6f // VHE? 584 - mrs_s x4, SYS_PMBIDR_EL1 // If SPE available at EL2, 585 - and x4, x4, #(1 << SYS_PMBIDR_EL1_P_SHIFT) 586 - cbnz x4, 5f // then permit sampling of physical 587 - mov x4, #(1 << SYS_PMSCR_EL2_PCT_SHIFT | \ 588 - 1 << SYS_PMSCR_EL2_PA_SHIFT) 589 - msr_s SYS_PMSCR_EL2, x4 // addresses and physical counter 590 - 5: 591 - mov x1, #(MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT) 592 - orr x3, x3, x1 // If we don't have VHE, then 593 - b 7f // use EL1&0 translation. 594 - 6: // For VHE, use EL2 translation 595 - orr x3, x3, #MDCR_EL2_TPMS // and disable access from EL1 596 - 7: 597 - msr mdcr_el2, x3 // Configure debug traps 598 - 599 - /* LORegions */ 600 - mrs x1, id_aa64mmfr1_el1 601 - ubfx x0, x1, #ID_AA64MMFR1_LOR_SHIFT, 4 602 - cbz x0, 1f 603 - msr_s SYS_LORC_EL1, xzr 604 - 1: 605 - 606 - /* Stage-2 translation */ 607 - msr vttbr_el2, xzr 608 - 609 - cbz x2, install_el2_stub 610 - 611 - mov w0, #BOOT_CPU_MODE_EL2 // This CPU booted in EL2 612 - isb 613 - ret 614 - 615 - SYM_INNER_LABEL(install_el2_stub, SYM_L_LOCAL) 616 - /* 617 - * When VHE is not in use, early init of EL2 and EL1 needs to be 618 - * done here. 619 524 * When VHE _is_ in use, EL1 will not be used in the host and 620 525 * requires no configuration, and all non-hyp-specific EL2 setup 621 526 * will be done via the _EL1 system register aliases in __cpu_setup. 622 527 */ 623 - mov_q x0, (SCTLR_EL1_RES1 | ENDIAN_SET_EL1) 624 - msr sctlr_el1, x0 625 - 626 - /* Coprocessor traps. */ 627 - mov x0, #0x33ff 628 - msr cptr_el2, x0 // Disable copro. traps to EL2 629 - 630 - /* SVE register access */ 631 - mrs x1, id_aa64pfr0_el1 632 - ubfx x1, x1, #ID_AA64PFR0_SVE_SHIFT, #4 633 - cbz x1, 7f 634 - 635 - bic x0, x0, #CPTR_EL2_TZ // Also disable SVE traps 636 - msr cptr_el2, x0 // Disable copro. traps to EL2 528 + mov_q x0, HCR_HOST_VHE_FLAGS 529 + msr hcr_el2, x0 637 530 isb 638 - mov x1, #ZCR_ELx_LEN_MASK // SVE: Enable full vector 639 - msr_s SYS_ZCR_EL2, x1 // length for EL1. 640 531 641 - /* Hypervisor stub */ 642 - 7: adr_l x0, __hyp_stub_vectors 643 - msr vbar_el2, x0 532 + init_el2_state vhe 644 533 645 - /* spsr */ 646 - mov x0, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\ 647 - PSR_MODE_EL1h) 534 + isb 535 + 536 + mov_q x0, INIT_PSTATE_EL2 648 537 msr spsr_el2, x0 649 538 msr elr_el2, lr 650 - mov w0, #BOOT_CPU_MODE_EL2 // This CPU booted in EL2 539 + mov w0, #BOOT_CPU_MODE_EL2 651 540 eret 652 - SYM_FUNC_END(el2_setup) 541 + 542 + SYM_INNER_LABEL(init_el2_nvhe, SYM_L_LOCAL) 543 + /* 544 + * When VHE is not in use, early init of EL2 and EL1 needs to be 545 + * done here. 546 + */ 547 + mov_q x0, INIT_SCTLR_EL1_MMU_OFF 548 + msr sctlr_el1, x0 549 + 550 + mov_q x0, HCR_HOST_NVHE_FLAGS 551 + msr hcr_el2, x0 552 + isb 553 + 554 + init_el2_state nvhe 555 + 556 + /* Hypervisor stub */ 557 + adr_l x0, __hyp_stub_vectors 558 + msr vbar_el2, x0 559 + isb 560 + 561 + msr elr_el2, lr 562 + mov w0, #BOOT_CPU_MODE_EL2 563 + eret 564 + SYM_FUNC_END(init_kernel_el) 653 565 654 566 /* 655 567 * Sets the __boot_cpu_mode flag depending on the CPU boot mode passed ··· 611 699 * cores are held until we're ready for them to initialise. 612 700 */ 613 701 SYM_FUNC_START(secondary_holding_pen) 614 - bl el2_setup // Drop to EL1, w0=cpu_boot_mode 702 + bl init_kernel_el // w0=cpu_boot_mode 615 703 bl set_cpu_boot_mode_flag 616 704 mrs x0, mpidr_el1 617 705 mov_q x1, MPIDR_HWID_BITMASK ··· 629 717 * be used where CPUs are brought online dynamically by the kernel. 630 718 */ 631 719 SYM_FUNC_START(secondary_entry) 632 - bl el2_setup // Drop to EL1 720 + bl init_kernel_el // w0=cpu_boot_mode 633 721 bl set_cpu_boot_mode_flag 634 722 b secondary_startup 635 723 SYM_FUNC_END(secondary_entry)
+5 -6
arch/arm64/kernel/image-vars.h
··· 64 64 /* Alternative callbacks for init-time patching of nVHE hyp code. */ 65 65 KVM_NVHE_ALIAS(kvm_patch_vector_branch); 66 66 KVM_NVHE_ALIAS(kvm_update_va_mask); 67 + KVM_NVHE_ALIAS(kvm_update_kimg_phys_offset); 68 + KVM_NVHE_ALIAS(kvm_get_kimage_voffset); 67 69 68 70 /* Global kernel state accessed by nVHE hyp code. */ 69 71 KVM_NVHE_ALIAS(kvm_vgic_global_state); 70 - 71 - /* Kernel constant needed to compute idmap addresses. */ 72 - KVM_NVHE_ALIAS(kimage_voffset); 73 72 74 73 /* Kernel symbols used to call panic() from nVHE hyp code (via ERET). */ 75 74 KVM_NVHE_ALIAS(__hyp_panic_string); ··· 76 77 77 78 /* Vectors installed by hyp-init on reset HVC. */ 78 79 KVM_NVHE_ALIAS(__hyp_stub_vectors); 79 - 80 - /* IDMAP TCR_EL1.T0SZ as computed by the EL1 init code */ 81 - KVM_NVHE_ALIAS(idmap_t0sz); 82 80 83 81 /* Kernel symbol used by icache_is_vpipt(). */ 84 82 KVM_NVHE_ALIAS(__icache_flags); ··· 98 102 /* EL2 exception handling */ 99 103 KVM_NVHE_ALIAS(__start___kvm_ex_table); 100 104 KVM_NVHE_ALIAS(__stop___kvm_ex_table); 105 + 106 + /* Array containing bases of nVHE per-CPU memory regions. */ 107 + KVM_NVHE_ALIAS(kvm_arm_hyp_percpu_base); 101 108 102 109 #endif /* CONFIG_KVM */ 103 110
+1 -1
arch/arm64/kernel/kexec_image.c
··· 127 127 kernel_segment->mem, kbuf.bufsz, 128 128 kernel_segment->memsz); 129 129 130 - return 0; 130 + return NULL; 131 131 } 132 132 133 133 #ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG
+1 -2
arch/arm64/kernel/perf_regs.c
··· 73 73 } 74 74 75 75 void perf_get_regs_user(struct perf_regs *regs_user, 76 - struct pt_regs *regs, 77 - struct pt_regs *regs_user_copy) 76 + struct pt_regs *regs) 78 77 { 79 78 regs_user->regs = task_pt_regs(current); 80 79 regs_user->abi = perf_reg_abi(current);
+10 -24
arch/arm64/kernel/process.c
··· 422 422 if (clone_flags & CLONE_SETTLS) 423 423 p->thread.uw.tp_value = tls; 424 424 } else { 425 + /* 426 + * A kthread has no context to ERET to, so ensure any buggy 427 + * ERET is treated as an illegal exception return. 428 + * 429 + * When a user task is created from a kthread, childregs will 430 + * be initialized by start_thread() or start_compat_thread(). 431 + */ 425 432 memset(childregs, 0, sizeof(struct pt_regs)); 426 - childregs->pstate = PSR_MODE_EL1h; 427 - if (IS_ENABLED(CONFIG_ARM64_UAO) && 428 - cpus_have_const_cap(ARM64_HAS_UAO)) 429 - childregs->pstate |= PSR_UAO_BIT; 430 - 431 - spectre_v4_enable_task_mitigation(p); 432 - 433 - if (system_uses_irq_prio_masking()) 434 - childregs->pmr_save = GIC_PRIO_IRQON; 433 + childregs->pstate = PSR_MODE_EL1h | PSR_IL_BIT; 435 434 436 435 p->thread.cpu_context.x19 = stack_start; 437 436 p->thread.cpu_context.x20 = stk_sz; ··· 458 459 write_sysreg(0, tpidrro_el0); 459 460 460 461 write_sysreg(*task_user_tls(next), tpidr_el0); 461 - } 462 - 463 - /* Restore the UAO state depending on next's addr_limit */ 464 - void uao_thread_switch(struct task_struct *next) 465 - { 466 - if (IS_ENABLED(CONFIG_ARM64_UAO)) { 467 - if (task_thread_info(next)->addr_limit == KERNEL_DS) 468 - asm(ALTERNATIVE("nop", SET_PSTATE_UAO(1), ARM64_HAS_UAO)); 469 - else 470 - asm(ALTERNATIVE("nop", SET_PSTATE_UAO(0), ARM64_HAS_UAO)); 471 - } 472 462 } 473 463 474 464 /* ··· 510 522 bool prev32, next32; 511 523 u64 val; 512 524 513 - if (!(IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040) && 514 - cpus_have_const_cap(ARM64_WORKAROUND_1418040))) 525 + if (!IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040)) 515 526 return; 516 527 517 528 prev32 = is_compat_thread(task_thread_info(prev)); 518 529 next32 = is_compat_thread(task_thread_info(next)); 519 530 520 - if (prev32 == next32) 531 + if (prev32 == next32 || !this_cpu_has_cap(ARM64_WORKAROUND_1418040)) 521 532 return; 522 533 523 534 val = read_sysreg(cntkctl_el1); ··· 542 555 hw_breakpoint_thread_switch(next); 543 556 contextidr_thread_switch(next); 544 557 entry_task_switch(next); 545 - uao_thread_switch(next); 546 558 ssbs_thread_switch(next); 547 559 erratum_1418040_thread_switch(prev, next); 548 560
+37 -53
arch/arm64/kernel/proton-pack.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* 3 - * Handle detection, reporting and mitigation of Spectre v1, v2 and v4, as 3 + * Handle detection, reporting and mitigation of Spectre v1, v2, v3a and v4, as 4 4 * detailed at: 5 5 * 6 6 * https://developer.arm.com/support/arm-security-updates/speculative-processor-vulnerability ··· 24 24 #include <linux/prctl.h> 25 25 #include <linux/sched/task_stack.h> 26 26 27 + #include <asm/insn.h> 27 28 #include <asm/spectre.h> 28 29 #include <asm/traps.h> 30 + #include <asm/virt.h> 29 31 30 32 /* 31 33 * We try to ensure that the mitigation state can never change as the result of ··· 120 118 MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), 121 119 MIDR_ALL_VERSIONS(MIDR_BRAHMA_B53), 122 120 MIDR_ALL_VERSIONS(MIDR_HISI_TSV110), 121 + MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_2XX_SILVER), 123 122 MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_3XX_SILVER), 124 123 MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_4XX_SILVER), 125 124 { /* sentinel */ } ··· 172 169 return true; 173 170 } 174 171 175 - DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); 176 - 177 172 enum mitigation_state arm64_get_spectre_v2_state(void) 178 173 { 179 174 return spectre_v2_state; 180 175 } 181 176 182 - #ifdef CONFIG_KVM 183 - #include <asm/cacheflush.h> 184 - #include <asm/kvm_asm.h> 185 - 186 - atomic_t arm64_el2_vector_last_slot = ATOMIC_INIT(-1); 187 - 188 - static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start, 189 - const char *hyp_vecs_end) 190 - { 191 - void *dst = lm_alias(__bp_harden_hyp_vecs + slot * SZ_2K); 192 - int i; 193 - 194 - for (i = 0; i < SZ_2K; i += 0x80) 195 - memcpy(dst + i, hyp_vecs_start, hyp_vecs_end - hyp_vecs_start); 196 - 197 - __flush_icache_range((uintptr_t)dst, (uintptr_t)dst + SZ_2K); 198 - } 177 + DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); 199 178 200 179 static void install_bp_hardening_cb(bp_hardening_cb_t fn) 201 180 { 202 - static DEFINE_RAW_SPINLOCK(bp_lock); 203 - int cpu, slot = -1; 204 - const char *hyp_vecs_start = __smccc_workaround_1_smc; 205 - const char *hyp_vecs_end = __smccc_workaround_1_smc + 206 - __SMCCC_WORKAROUND_1_SMC_SZ; 181 + __this_cpu_write(bp_hardening_data.fn, fn); 207 182 208 183 /* 209 184 * Vinz Clortho takes the hyp_vecs start/end "keys" at 210 185 * the door when we're a guest. Skip the hyp-vectors work. 211 186 */ 212 - if (!is_hyp_mode_available()) { 213 - __this_cpu_write(bp_hardening_data.fn, fn); 187 + if (!is_hyp_mode_available()) 214 188 return; 215 - } 216 189 217 - raw_spin_lock(&bp_lock); 218 - for_each_possible_cpu(cpu) { 219 - if (per_cpu(bp_hardening_data.fn, cpu) == fn) { 220 - slot = per_cpu(bp_hardening_data.hyp_vectors_slot, cpu); 221 - break; 222 - } 223 - } 224 - 225 - if (slot == -1) { 226 - slot = atomic_inc_return(&arm64_el2_vector_last_slot); 227 - BUG_ON(slot >= BP_HARDEN_EL2_SLOTS); 228 - __copy_hyp_vect_bpi(slot, hyp_vecs_start, hyp_vecs_end); 229 - } 230 - 231 - __this_cpu_write(bp_hardening_data.hyp_vectors_slot, slot); 232 - __this_cpu_write(bp_hardening_data.fn, fn); 233 - raw_spin_unlock(&bp_lock); 190 + __this_cpu_write(bp_hardening_data.slot, HYP_VECTOR_SPECTRE_DIRECT); 234 191 } 235 - #else 236 - static void install_bp_hardening_cb(bp_hardening_cb_t fn) 237 - { 238 - __this_cpu_write(bp_hardening_data.fn, fn); 239 - } 240 - #endif /* CONFIG_KVM */ 241 192 242 193 static void call_smc_arch_workaround_1(void) 243 194 { ··· 270 313 state = spectre_v2_enable_fw_mitigation(); 271 314 272 315 update_mitigation_state(&spectre_v2_state, state); 316 + } 317 + 318 + /* 319 + * Spectre-v3a. 320 + * 321 + * Phew, there's not an awful lot to do here! We just instruct EL2 to use 322 + * an indirect trampoline for the hyp vectors so that guests can't read 323 + * VBAR_EL2 to defeat randomisation of the hypervisor VA layout. 324 + */ 325 + bool has_spectre_v3a(const struct arm64_cpu_capabilities *entry, int scope) 326 + { 327 + static const struct midr_range spectre_v3a_unsafe_list[] = { 328 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), 329 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), 330 + {}, 331 + }; 332 + 333 + WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); 334 + return is_midr_in_range_list(read_cpuid_id(), spectre_v3a_unsafe_list); 335 + } 336 + 337 + void spectre_v3a_enable_mitigation(const struct arm64_cpu_capabilities *__unused) 338 + { 339 + struct bp_hardening_data *data = this_cpu_ptr(&bp_hardening_data); 340 + 341 + if (this_cpu_has_cap(ARM64_SPECTRE_V3A)) 342 + data->slot += HYP_VECTOR_INDIRECT; 273 343 } 274 344 275 345 /* ··· 521 537 522 538 if (spectre_v4_mitigations_off()) { 523 539 sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_DSSBS); 524 - asm volatile(SET_PSTATE_SSBS(1)); 540 + set_pstate_ssbs(1); 525 541 return SPECTRE_VULNERABLE; 526 542 } 527 543 528 544 /* SCTLR_EL1.DSSBS was initialised to 0 during boot */ 529 - asm volatile(SET_PSTATE_SSBS(0)); 545 + set_pstate_ssbs(0); 530 546 return SPECTRE_MITIGATED; 531 547 } 532 548
+1 -4
arch/arm64/kernel/psci.c
··· 66 66 67 67 static void cpu_psci_cpu_die(unsigned int cpu) 68 68 { 69 - int ret; 70 69 /* 71 70 * There are no known implementations of PSCI actually using the 72 71 * power state field, pass a sensible default for now. ··· 73 74 u32 state = PSCI_POWER_STATE_TYPE_POWER_DOWN << 74 75 PSCI_0_2_POWER_STATE_TYPE_SHIFT; 75 76 76 - ret = psci_ops.cpu_off(state); 77 - 78 - pr_crit("unable to power off CPU%u (%d)\n", cpu, ret); 77 + psci_ops.cpu_off(state); 79 78 } 80 79 81 80 static int cpu_psci_cpu_kill(unsigned int cpu)
+27 -6
arch/arm64/kernel/sdei.c
··· 178 178 sdei_api_event_context(i, &regs->regs[i]); 179 179 } 180 180 181 - /* 182 - * We didn't take an exception to get here, set PAN. UAO will be cleared 183 - * by sdei_event_handler()s force_uaccess_begin() call. 184 - */ 185 - __uaccess_enable_hw_pan(); 186 - 187 181 err = sdei_event_handler(regs, arg); 188 182 if (err) 189 183 return SDEI_EV_FAILED; ··· 216 222 return vbar + 0x480; 217 223 } 218 224 225 + static void __kprobes notrace __sdei_pstate_entry(void) 226 + { 227 + /* 228 + * The original SDEI spec (ARM DEN 0054A) can be read ambiguously as to 229 + * whether PSTATE bits are inherited unchanged or generated from 230 + * scratch, and the TF-A implementation always clears PAN and always 231 + * clears UAO. There are no other known implementations. 232 + * 233 + * Subsequent revisions (ARM DEN 0054B) follow the usual rules for how 234 + * PSTATE is modified upon architectural exceptions, and so PAN is 235 + * either inherited or set per SCTLR_ELx.SPAN, and UAO is always 236 + * cleared. 237 + * 238 + * We must explicitly reset PAN to the expected state, including 239 + * clearing it when the host isn't using it, in case a VM had it set. 240 + */ 241 + if (system_uses_hw_pan()) 242 + set_pstate_pan(1); 243 + else if (cpu_has_pan()) 244 + set_pstate_pan(0); 245 + } 219 246 220 247 asmlinkage __kprobes notrace unsigned long 221 248 __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg) 222 249 { 223 250 unsigned long ret; 251 + 252 + /* 253 + * We didn't take an exception to get here, so the HW hasn't 254 + * set/cleared bits in PSTATE that we may rely on. Initialize PAN. 255 + */ 256 + __sdei_pstate_entry(); 224 257 225 258 nmi_enter(); 226 259
+1 -1
arch/arm64/kernel/setup.c
··· 276 276 277 277 u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID }; 278 278 279 - u64 cpu_logical_map(int cpu) 279 + u64 cpu_logical_map(unsigned int cpu) 280 280 { 281 281 return __cpu_logical_map[cpu]; 282 282 }
-3
arch/arm64/kernel/signal.c
··· 922 922 trace_hardirqs_off(); 923 923 924 924 do { 925 - /* Check valid user FS if needed */ 926 - addr_limit_user_check(); 927 - 928 925 if (thread_flags & _TIF_NEED_RESCHED) { 929 926 /* Unmask Debug and SError for the next task */ 930 927 local_daif_restore(DAIF_PROCCTX_NOIRQ);
+1 -1
arch/arm64/kernel/sleep.S
··· 99 99 100 100 .pushsection ".idmap.text", "awx" 101 101 SYM_CODE_START(cpu_resume) 102 - bl el2_setup // if in EL2 drop to EL1 cleanly 102 + bl init_kernel_el 103 103 bl __cpu_setup 104 104 /* enable the MMU early - so we can access sleep_save_stash by va */ 105 105 adrp x1, swapper_pg_dir
+1
arch/arm64/kernel/smp.c
··· 413 413 414 414 /* Mark this CPU absent */ 415 415 set_cpu_present(cpu, 0); 416 + rcu_report_dead(cpu); 416 417 417 418 if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) { 418 419 update_cpu_boot_status(CPU_KILL_ME);
-1
arch/arm64/kernel/suspend.c
··· 58 58 * features that might not have been set correctly. 59 59 */ 60 60 __uaccess_enable_hw_pan(); 61 - uao_thread_switch(current); 62 61 63 62 /* 64 63 * Restore HW breakpoint registers to sane values
+1 -1
arch/arm64/kernel/vdso/Makefile
··· 28 28 $(btildflags-y) -T 29 29 30 30 ccflags-y := -fno-common -fno-builtin -fno-stack-protector -ffixed-x18 31 - ccflags-y += -DDISABLE_BRANCH_PROFILING 31 + ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO 32 32 33 33 CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) $(GCC_PLUGINS_CFLAGS) 34 34 KASAN_SANITIZE := n
+1 -1
arch/arm64/kernel/vdso32/Makefile
··· 48 48 # As a result we set our own flags here. 49 49 50 50 # KBUILD_CPPFLAGS and NOSTDINC_FLAGS from top-level Makefile 51 - VDSO_CPPFLAGS := -D__KERNEL__ -nostdinc -isystem $(shell $(CC_COMPAT) -print-file-name=include) 51 + VDSO_CPPFLAGS := -DBUILD_VDSO -D__KERNEL__ -nostdinc -isystem $(shell $(CC_COMPAT) -print-file-name=include) 52 52 VDSO_CPPFLAGS += $(LINUXINCLUDE) 53 53 54 54 # Common C and assembly flags
+11 -1
arch/arm64/kernel/vmlinux.lds.S
··· 30 30 *(__kvm_ex_table) \ 31 31 __stop___kvm_ex_table = .; 32 32 33 + #define HYPERVISOR_DATA_SECTIONS \ 34 + HYP_SECTION_NAME(.data..ro_after_init) : { \ 35 + __hyp_data_ro_after_init_start = .; \ 36 + *(HYP_SECTION_NAME(.data..ro_after_init)) \ 37 + __hyp_data_ro_after_init_end = .; \ 38 + } 39 + 33 40 #define HYPERVISOR_PERCPU_SECTION \ 34 41 . = ALIGN(PAGE_SIZE); \ 35 42 HYP_SECTION_NAME(.data..percpu) : { \ ··· 44 37 } 45 38 #else /* CONFIG_KVM */ 46 39 #define HYPERVISOR_EXTABLE 40 + #define HYPERVISOR_DATA_SECTIONS 47 41 #define HYPERVISOR_PERCPU_SECTION 48 42 #endif 49 43 ··· 209 201 INIT_CALLS 210 202 CON_INITCALL 211 203 INIT_RAM_FS 212 - *(.init.rodata.* .init.bss) /* from the EFI stub */ 204 + *(.init.altinstructions .init.rodata.* .init.bss) /* from the EFI stub */ 213 205 } 214 206 .exit.data : { 215 207 EXIT_DATA ··· 241 233 _data = .; 242 234 _sdata = .; 243 235 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 236 + 237 + HYPERVISOR_DATA_SECTIONS 244 238 245 239 /* 246 240 * Data written with the MMU off but read with the MMU on requires
+2 -2
arch/arm64/kvm/Makefile
··· 13 13 kvm-y := $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o \ 14 14 $(KVM)/vfio.o $(KVM)/irqchip.o \ 15 15 arm.o mmu.o mmio.o psci.o perf.o hypercalls.o pvtime.o \ 16 - inject_fault.o regmap.o va_layout.o handle_exit.o \ 16 + inject_fault.o va_layout.o handle_exit.o \ 17 17 guest.o debug.o reset.o sys_regs.o \ 18 18 vgic-sys-reg-v3.o fpsimd.o pmu.o \ 19 - aarch32.o arch_timer.o \ 19 + arch_timer.o \ 20 20 vgic/vgic.o vgic/vgic-init.o \ 21 21 vgic/vgic-irqfd.o vgic/vgic-v2.o \ 22 22 vgic/vgic-v3.o vgic/vgic-v4.o \
-232
arch/arm64/kvm/aarch32.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * (not much of an) Emulation layer for 32bit guests. 4 - * 5 - * Copyright (C) 2012,2013 - ARM Ltd 6 - * Author: Marc Zyngier <marc.zyngier@arm.com> 7 - * 8 - * based on arch/arm/kvm/emulate.c 9 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 10 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 11 - */ 12 - 13 - #include <linux/bits.h> 14 - #include <linux/kvm_host.h> 15 - #include <asm/kvm_emulate.h> 16 - #include <asm/kvm_hyp.h> 17 - 18 - #define DFSR_FSC_EXTABT_LPAE 0x10 19 - #define DFSR_FSC_EXTABT_nLPAE 0x08 20 - #define DFSR_LPAE BIT(9) 21 - 22 - /* 23 - * Table taken from ARMv8 ARM DDI0487B-B, table G1-10. 24 - */ 25 - static const u8 return_offsets[8][2] = { 26 - [0] = { 0, 0 }, /* Reset, unused */ 27 - [1] = { 4, 2 }, /* Undefined */ 28 - [2] = { 0, 0 }, /* SVC, unused */ 29 - [3] = { 4, 4 }, /* Prefetch abort */ 30 - [4] = { 8, 8 }, /* Data abort */ 31 - [5] = { 0, 0 }, /* HVC, unused */ 32 - [6] = { 4, 4 }, /* IRQ, unused */ 33 - [7] = { 4, 4 }, /* FIQ, unused */ 34 - }; 35 - 36 - static bool pre_fault_synchronize(struct kvm_vcpu *vcpu) 37 - { 38 - preempt_disable(); 39 - if (vcpu->arch.sysregs_loaded_on_cpu) { 40 - kvm_arch_vcpu_put(vcpu); 41 - return true; 42 - } 43 - 44 - preempt_enable(); 45 - return false; 46 - } 47 - 48 - static void post_fault_synchronize(struct kvm_vcpu *vcpu, bool loaded) 49 - { 50 - if (loaded) { 51 - kvm_arch_vcpu_load(vcpu, smp_processor_id()); 52 - preempt_enable(); 53 - } 54 - } 55 - 56 - /* 57 - * When an exception is taken, most CPSR fields are left unchanged in the 58 - * handler. However, some are explicitly overridden (e.g. M[4:0]). 59 - * 60 - * The SPSR/SPSR_ELx layouts differ, and the below is intended to work with 61 - * either format. Note: SPSR.J bit doesn't exist in SPSR_ELx, but this bit was 62 - * obsoleted by the ARMv7 virtualization extensions and is RES0. 63 - * 64 - * For the SPSR layout seen from AArch32, see: 65 - * - ARM DDI 0406C.d, page B1-1148 66 - * - ARM DDI 0487E.a, page G8-6264 67 - * 68 - * For the SPSR_ELx layout for AArch32 seen from AArch64, see: 69 - * - ARM DDI 0487E.a, page C5-426 70 - * 71 - * Here we manipulate the fields in order of the AArch32 SPSR_ELx layout, from 72 - * MSB to LSB. 73 - */ 74 - static unsigned long get_except32_cpsr(struct kvm_vcpu *vcpu, u32 mode) 75 - { 76 - u32 sctlr = vcpu_cp15(vcpu, c1_SCTLR); 77 - unsigned long old, new; 78 - 79 - old = *vcpu_cpsr(vcpu); 80 - new = 0; 81 - 82 - new |= (old & PSR_AA32_N_BIT); 83 - new |= (old & PSR_AA32_Z_BIT); 84 - new |= (old & PSR_AA32_C_BIT); 85 - new |= (old & PSR_AA32_V_BIT); 86 - new |= (old & PSR_AA32_Q_BIT); 87 - 88 - // CPSR.IT[7:0] are set to zero upon any exception 89 - // See ARM DDI 0487E.a, section G1.12.3 90 - // See ARM DDI 0406C.d, section B1.8.3 91 - 92 - new |= (old & PSR_AA32_DIT_BIT); 93 - 94 - // CPSR.SSBS is set to SCTLR.DSSBS upon any exception 95 - // See ARM DDI 0487E.a, page G8-6244 96 - if (sctlr & BIT(31)) 97 - new |= PSR_AA32_SSBS_BIT; 98 - 99 - // CPSR.PAN is unchanged unless SCTLR.SPAN == 0b0 100 - // SCTLR.SPAN is RES1 when ARMv8.1-PAN is not implemented 101 - // See ARM DDI 0487E.a, page G8-6246 102 - new |= (old & PSR_AA32_PAN_BIT); 103 - if (!(sctlr & BIT(23))) 104 - new |= PSR_AA32_PAN_BIT; 105 - 106 - // SS does not exist in AArch32, so ignore 107 - 108 - // CPSR.IL is set to zero upon any exception 109 - // See ARM DDI 0487E.a, page G1-5527 110 - 111 - new |= (old & PSR_AA32_GE_MASK); 112 - 113 - // CPSR.IT[7:0] are set to zero upon any exception 114 - // See prior comment above 115 - 116 - // CPSR.E is set to SCTLR.EE upon any exception 117 - // See ARM DDI 0487E.a, page G8-6245 118 - // See ARM DDI 0406C.d, page B4-1701 119 - if (sctlr & BIT(25)) 120 - new |= PSR_AA32_E_BIT; 121 - 122 - // CPSR.A is unchanged upon an exception to Undefined, Supervisor 123 - // CPSR.A is set upon an exception to other modes 124 - // See ARM DDI 0487E.a, pages G1-5515 to G1-5516 125 - // See ARM DDI 0406C.d, page B1-1182 126 - new |= (old & PSR_AA32_A_BIT); 127 - if (mode != PSR_AA32_MODE_UND && mode != PSR_AA32_MODE_SVC) 128 - new |= PSR_AA32_A_BIT; 129 - 130 - // CPSR.I is set upon any exception 131 - // See ARM DDI 0487E.a, pages G1-5515 to G1-5516 132 - // See ARM DDI 0406C.d, page B1-1182 133 - new |= PSR_AA32_I_BIT; 134 - 135 - // CPSR.F is set upon an exception to FIQ 136 - // CPSR.F is unchanged upon an exception to other modes 137 - // See ARM DDI 0487E.a, pages G1-5515 to G1-5516 138 - // See ARM DDI 0406C.d, page B1-1182 139 - new |= (old & PSR_AA32_F_BIT); 140 - if (mode == PSR_AA32_MODE_FIQ) 141 - new |= PSR_AA32_F_BIT; 142 - 143 - // CPSR.T is set to SCTLR.TE upon any exception 144 - // See ARM DDI 0487E.a, page G8-5514 145 - // See ARM DDI 0406C.d, page B1-1181 146 - if (sctlr & BIT(30)) 147 - new |= PSR_AA32_T_BIT; 148 - 149 - new |= mode; 150 - 151 - return new; 152 - } 153 - 154 - static void prepare_fault32(struct kvm_vcpu *vcpu, u32 mode, u32 vect_offset) 155 - { 156 - unsigned long spsr = *vcpu_cpsr(vcpu); 157 - bool is_thumb = (spsr & PSR_AA32_T_BIT); 158 - u32 return_offset = return_offsets[vect_offset >> 2][is_thumb]; 159 - u32 sctlr = vcpu_cp15(vcpu, c1_SCTLR); 160 - 161 - *vcpu_cpsr(vcpu) = get_except32_cpsr(vcpu, mode); 162 - 163 - /* Note: These now point to the banked copies */ 164 - vcpu_write_spsr(vcpu, host_spsr_to_spsr32(spsr)); 165 - *vcpu_reg32(vcpu, 14) = *vcpu_pc(vcpu) + return_offset; 166 - 167 - /* Branch to exception vector */ 168 - if (sctlr & (1 << 13)) 169 - vect_offset += 0xffff0000; 170 - else /* always have security exceptions */ 171 - vect_offset += vcpu_cp15(vcpu, c12_VBAR); 172 - 173 - *vcpu_pc(vcpu) = vect_offset; 174 - } 175 - 176 - void kvm_inject_undef32(struct kvm_vcpu *vcpu) 177 - { 178 - bool loaded = pre_fault_synchronize(vcpu); 179 - 180 - prepare_fault32(vcpu, PSR_AA32_MODE_UND, 4); 181 - post_fault_synchronize(vcpu, loaded); 182 - } 183 - 184 - /* 185 - * Modelled after TakeDataAbortException() and TakePrefetchAbortException 186 - * pseudocode. 187 - */ 188 - static void inject_abt32(struct kvm_vcpu *vcpu, bool is_pabt, 189 - unsigned long addr) 190 - { 191 - u32 vect_offset; 192 - u32 *far, *fsr; 193 - bool is_lpae; 194 - bool loaded; 195 - 196 - loaded = pre_fault_synchronize(vcpu); 197 - 198 - if (is_pabt) { 199 - vect_offset = 12; 200 - far = &vcpu_cp15(vcpu, c6_IFAR); 201 - fsr = &vcpu_cp15(vcpu, c5_IFSR); 202 - } else { /* !iabt */ 203 - vect_offset = 16; 204 - far = &vcpu_cp15(vcpu, c6_DFAR); 205 - fsr = &vcpu_cp15(vcpu, c5_DFSR); 206 - } 207 - 208 - prepare_fault32(vcpu, PSR_AA32_MODE_ABT, vect_offset); 209 - 210 - *far = addr; 211 - 212 - /* Give the guest an IMPLEMENTATION DEFINED exception */ 213 - is_lpae = (vcpu_cp15(vcpu, c2_TTBCR) >> 31); 214 - if (is_lpae) { 215 - *fsr = DFSR_LPAE | DFSR_FSC_EXTABT_LPAE; 216 - } else { 217 - /* no need to shuffle FS[4] into DFSR[10] as its 0 */ 218 - *fsr = DFSR_FSC_EXTABT_nLPAE; 219 - } 220 - 221 - post_fault_synchronize(vcpu, loaded); 222 - } 223 - 224 - void kvm_inject_dabt32(struct kvm_vcpu *vcpu, unsigned long addr) 225 - { 226 - inject_abt32(vcpu, false, addr); 227 - } 228 - 229 - void kvm_inject_pabt32(struct kvm_vcpu *vcpu, unsigned long addr) 230 - { 231 - inject_abt32(vcpu, true, addr); 232 - }
+225 -60
arch/arm64/kvm/arm.c
··· 19 19 #include <linux/kvm_irqfd.h> 20 20 #include <linux/irqbypass.h> 21 21 #include <linux/sched/stat.h> 22 + #include <linux/psci.h> 22 23 #include <trace/events/kvm.h> 23 24 24 25 #define CREATE_TRACE_POINTS ··· 36 35 #include <asm/kvm_asm.h> 37 36 #include <asm/kvm_mmu.h> 38 37 #include <asm/kvm_emulate.h> 39 - #include <asm/kvm_coproc.h> 40 38 #include <asm/sections.h> 41 39 42 40 #include <kvm/arm_hypercalls.h> ··· 46 46 __asm__(".arch_extension virt"); 47 47 #endif 48 48 49 + static enum kvm_mode kvm_mode = KVM_MODE_DEFAULT; 50 + DEFINE_STATIC_KEY_FALSE(kvm_protected_mode_initialized); 51 + 49 52 DECLARE_KVM_HYP_PER_CPU(unsigned long, kvm_hyp_vector); 50 53 51 54 static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page); 52 55 unsigned long kvm_arm_hyp_percpu_base[NR_CPUS]; 56 + DECLARE_KVM_NVHE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params); 53 57 54 58 /* The VMID used in the VTTBR */ 55 59 static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1); ··· 64 60 65 61 static DEFINE_PER_CPU(unsigned char, kvm_arm_hardware_enabled); 66 62 DEFINE_STATIC_KEY_FALSE(userspace_irqchip_in_use); 63 + 64 + extern u64 kvm_nvhe_sym(__cpu_logical_map)[NR_CPUS]; 65 + extern u32 kvm_nvhe_sym(kvm_host_psci_version); 66 + extern struct psci_0_1_function_ids kvm_nvhe_sym(kvm_host_psci_0_1_function_ids); 67 67 68 68 int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) 69 69 { ··· 110 102 return vgic_present ? kvm_vgic_get_max_vcpus() : KVM_MAX_VCPUS; 111 103 } 112 104 113 - static void set_default_csv2(struct kvm *kvm) 105 + static void set_default_spectre(struct kvm *kvm) 114 106 { 115 107 /* 116 108 * The default is to expose CSV2 == 1 if the HW isn't affected. ··· 122 114 */ 123 115 if (arm64_get_spectre_v2_state() == SPECTRE_UNAFFECTED) 124 116 kvm->arch.pfr0_csv2 = 1; 117 + if (arm64_get_meltdown_state() == SPECTRE_UNAFFECTED) 118 + kvm->arch.pfr0_csv3 = 1; 125 119 } 126 120 127 121 /** ··· 151 141 /* The maximum number of VCPUs is limited by the host's GIC model */ 152 142 kvm->arch.max_vcpus = kvm_arm_default_max_vcpus(); 153 143 154 - set_default_csv2(kvm); 144 + set_default_spectre(kvm); 155 145 156 146 return ret; 157 147 out_free_stage2_pgd: ··· 208 198 case KVM_CAP_ARM_IRQ_LINE_LAYOUT_2: 209 199 case KVM_CAP_ARM_NISV_TO_USER: 210 200 case KVM_CAP_ARM_INJECT_EXT_DABT: 201 + case KVM_CAP_SET_GUEST_DEBUG: 202 + case KVM_CAP_VCPU_ATTRIBUTES: 211 203 r = 1; 212 204 break; 213 205 case KVM_CAP_ARM_SET_DEVICE_ADDR: ··· 241 229 case KVM_CAP_STEAL_TIME: 242 230 r = kvm_arm_pvtime_supported(); 243 231 break; 244 - default: 245 - r = kvm_arch_vm_ioctl_check_extension(kvm, ext); 232 + case KVM_CAP_ARM_EL1_32BIT: 233 + r = cpus_have_const_cap(ARM64_HAS_32BIT_EL1); 246 234 break; 235 + case KVM_CAP_GUEST_DEBUG_HW_BPS: 236 + r = get_num_brps(); 237 + break; 238 + case KVM_CAP_GUEST_DEBUG_HW_WPS: 239 + r = get_num_wrps(); 240 + break; 241 + case KVM_CAP_ARM_PMU_V3: 242 + r = kvm_arm_support_pmu_v3(); 243 + break; 244 + case KVM_CAP_ARM_INJECT_SERROR_ESR: 245 + r = cpus_have_const_cap(ARM64_HAS_RAS_EXTN); 246 + break; 247 + case KVM_CAP_ARM_VM_IPA_SIZE: 248 + r = get_kvm_ipa_limit(); 249 + break; 250 + case KVM_CAP_ARM_SVE: 251 + r = system_supports_sve(); 252 + break; 253 + case KVM_CAP_ARM_PTRAUTH_ADDRESS: 254 + case KVM_CAP_ARM_PTRAUTH_GENERIC: 255 + r = system_has_full_ptr_auth(); 256 + break; 257 + default: 258 + r = 0; 247 259 } 260 + 248 261 return r; 249 262 } 250 263 ··· 1348 1311 return size ? get_order(size) : 0; 1349 1312 } 1350 1313 1351 - static int kvm_map_vectors(void) 1314 + /* A lookup table holding the hypervisor VA for each vector slot */ 1315 + static void *hyp_spectre_vector_selector[BP_HARDEN_EL2_SLOTS]; 1316 + 1317 + static int __kvm_vector_slot2idx(enum arm64_hyp_spectre_vector slot) 1352 1318 { 1353 - /* 1354 - * SV2 = ARM64_SPECTRE_V2 1355 - * HEL2 = ARM64_HARDEN_EL2_VECTORS 1356 - * 1357 - * !SV2 + !HEL2 -> use direct vectors 1358 - * SV2 + !HEL2 -> use hardened vectors in place 1359 - * !SV2 + HEL2 -> allocate one vector slot and use exec mapping 1360 - * SV2 + HEL2 -> use hardened vectors and use exec mapping 1361 - */ 1362 - if (cpus_have_const_cap(ARM64_SPECTRE_V2)) { 1363 - __kvm_bp_vect_base = kvm_ksym_ref(__bp_harden_hyp_vecs); 1364 - __kvm_bp_vect_base = kern_hyp_va(__kvm_bp_vect_base); 1319 + return slot - (slot != HYP_VECTOR_DIRECT); 1320 + } 1321 + 1322 + static void kvm_init_vector_slot(void *base, enum arm64_hyp_spectre_vector slot) 1323 + { 1324 + int idx = __kvm_vector_slot2idx(slot); 1325 + 1326 + hyp_spectre_vector_selector[slot] = base + (idx * SZ_2K); 1327 + } 1328 + 1329 + static int kvm_init_vector_slots(void) 1330 + { 1331 + int err; 1332 + void *base; 1333 + 1334 + base = kern_hyp_va(kvm_ksym_ref(__kvm_hyp_vector)); 1335 + kvm_init_vector_slot(base, HYP_VECTOR_DIRECT); 1336 + 1337 + base = kern_hyp_va(kvm_ksym_ref(__bp_harden_hyp_vecs)); 1338 + kvm_init_vector_slot(base, HYP_VECTOR_SPECTRE_DIRECT); 1339 + 1340 + if (!cpus_have_const_cap(ARM64_SPECTRE_V3A)) 1341 + return 0; 1342 + 1343 + if (!has_vhe()) { 1344 + err = create_hyp_exec_mappings(__pa_symbol(__bp_harden_hyp_vecs), 1345 + __BP_HARDEN_HYP_VECS_SZ, &base); 1346 + if (err) 1347 + return err; 1365 1348 } 1366 1349 1367 - if (cpus_have_const_cap(ARM64_HARDEN_EL2_VECTORS)) { 1368 - phys_addr_t vect_pa = __pa_symbol(__bp_harden_hyp_vecs); 1369 - unsigned long size = __BP_HARDEN_HYP_VECS_SZ; 1370 - 1371 - /* 1372 - * Always allocate a spare vector slot, as we don't 1373 - * know yet which CPUs have a BP hardening slot that 1374 - * we can reuse. 1375 - */ 1376 - __kvm_harden_el2_vector_slot = atomic_inc_return(&arm64_el2_vector_last_slot); 1377 - BUG_ON(__kvm_harden_el2_vector_slot >= BP_HARDEN_EL2_SLOTS); 1378 - return create_hyp_exec_mappings(vect_pa, size, 1379 - &__kvm_bp_vect_base); 1380 - } 1381 - 1350 + kvm_init_vector_slot(base, HYP_VECTOR_INDIRECT); 1351 + kvm_init_vector_slot(base, HYP_VECTOR_SPECTRE_INDIRECT); 1382 1352 return 0; 1383 1353 } 1384 1354 1385 1355 static void cpu_init_hyp_mode(void) 1386 1356 { 1387 - phys_addr_t pgd_ptr; 1388 - unsigned long hyp_stack_ptr; 1389 - unsigned long vector_ptr; 1390 - unsigned long tpidr_el2; 1357 + struct kvm_nvhe_init_params *params = this_cpu_ptr_nvhe_sym(kvm_init_params); 1391 1358 struct arm_smccc_res res; 1359 + unsigned long tcr; 1392 1360 1393 1361 /* Switch from the HYP stub to our own HYP init vector */ 1394 1362 __hyp_set_vectors(kvm_get_idmap_vector()); ··· 1403 1361 * kernel's mapping to the linear mapping, and store it in tpidr_el2 1404 1362 * so that we can use adr_l to access per-cpu variables in EL2. 1405 1363 */ 1406 - tpidr_el2 = (unsigned long)this_cpu_ptr_nvhe_sym(__per_cpu_start) - 1407 - (unsigned long)kvm_ksym_ref(CHOOSE_NVHE_SYM(__per_cpu_start)); 1364 + params->tpidr_el2 = (unsigned long)this_cpu_ptr_nvhe_sym(__per_cpu_start) - 1365 + (unsigned long)kvm_ksym_ref(CHOOSE_NVHE_SYM(__per_cpu_start)); 1408 1366 1409 - pgd_ptr = kvm_mmu_get_httbr(); 1410 - hyp_stack_ptr = __this_cpu_read(kvm_arm_hyp_stack_page) + PAGE_SIZE; 1411 - hyp_stack_ptr = kern_hyp_va(hyp_stack_ptr); 1412 - vector_ptr = (unsigned long)kern_hyp_va(kvm_ksym_ref(__kvm_hyp_host_vector)); 1367 + params->mair_el2 = read_sysreg(mair_el1); 1368 + 1369 + /* 1370 + * The ID map may be configured to use an extended virtual address 1371 + * range. This is only the case if system RAM is out of range for the 1372 + * currently configured page size and VA_BITS, in which case we will 1373 + * also need the extended virtual range for the HYP ID map, or we won't 1374 + * be able to enable the EL2 MMU. 1375 + * 1376 + * However, at EL2, there is only one TTBR register, and we can't switch 1377 + * between translation tables *and* update TCR_EL2.T0SZ at the same 1378 + * time. Bottom line: we need to use the extended range with *both* our 1379 + * translation tables. 1380 + * 1381 + * So use the same T0SZ value we use for the ID map. 1382 + */ 1383 + tcr = (read_sysreg(tcr_el1) & TCR_EL2_MASK) | TCR_EL2_RES1; 1384 + tcr &= ~TCR_T0SZ_MASK; 1385 + tcr |= (idmap_t0sz & GENMASK(TCR_TxSZ_WIDTH - 1, 0)) << TCR_T0SZ_OFFSET; 1386 + params->tcr_el2 = tcr; 1387 + 1388 + params->stack_hyp_va = kern_hyp_va(__this_cpu_read(kvm_arm_hyp_stack_page) + PAGE_SIZE); 1389 + params->pgd_pa = kvm_mmu_get_httbr(); 1390 + 1391 + /* 1392 + * Flush the init params from the data cache because the struct will 1393 + * be read while the MMU is off. 1394 + */ 1395 + kvm_flush_dcache_to_poc(params, sizeof(*params)); 1413 1396 1414 1397 /* 1415 1398 * Call initialization code, and switch to the full blown HYP code. ··· 1443 1376 * cpus_have_const_cap() wrapper. 1444 1377 */ 1445 1378 BUG_ON(!system_capabilities_finalized()); 1446 - arm_smccc_1_1_hvc(KVM_HOST_SMCCC_FUNC(__kvm_hyp_init), 1447 - pgd_ptr, tpidr_el2, hyp_stack_ptr, vector_ptr, &res); 1379 + arm_smccc_1_1_hvc(KVM_HOST_SMCCC_FUNC(__kvm_hyp_init), virt_to_phys(params), &res); 1448 1380 WARN_ON(res.a0 != SMCCC_RET_SUCCESS); 1449 1381 1450 1382 /* ··· 1462 1396 __hyp_reset_vectors(); 1463 1397 } 1464 1398 1399 + /* 1400 + * EL2 vectors can be mapped and rerouted in a number of ways, 1401 + * depending on the kernel configuration and CPU present: 1402 + * 1403 + * - If the CPU is affected by Spectre-v2, the hardening sequence is 1404 + * placed in one of the vector slots, which is executed before jumping 1405 + * to the real vectors. 1406 + * 1407 + * - If the CPU also has the ARM64_SPECTRE_V3A cap, the slot 1408 + * containing the hardening sequence is mapped next to the idmap page, 1409 + * and executed before jumping to the real vectors. 1410 + * 1411 + * - If the CPU only has the ARM64_SPECTRE_V3A cap, then an 1412 + * empty slot is selected, mapped next to the idmap page, and 1413 + * executed before jumping to the real vectors. 1414 + * 1415 + * Note that ARM64_SPECTRE_V3A is somewhat incompatible with 1416 + * VHE, as we don't have hypervisor-specific mappings. If the system 1417 + * is VHE and yet selects this capability, it will be ignored. 1418 + */ 1419 + static void cpu_set_hyp_vector(void) 1420 + { 1421 + struct bp_hardening_data *data = this_cpu_ptr(&bp_hardening_data); 1422 + void *vector = hyp_spectre_vector_selector[data->slot]; 1423 + 1424 + *this_cpu_ptr_hyp_sym(kvm_hyp_vector) = (unsigned long)vector; 1425 + } 1426 + 1465 1427 static void cpu_hyp_reinit(void) 1466 1428 { 1467 1429 kvm_init_host_cpu_context(&this_cpu_ptr_hyp_sym(kvm_host_data)->host_ctxt); 1468 1430 1469 1431 cpu_hyp_reset(); 1470 - 1471 - *this_cpu_ptr_hyp_sym(kvm_hyp_vector) = (unsigned long)kvm_get_hyp_vector(); 1432 + cpu_set_hyp_vector(); 1472 1433 1473 1434 if (is_kernel_in_hyp_mode()) 1474 1435 kvm_timer_init_vhe(); ··· 1532 1439 1533 1440 void kvm_arch_hardware_disable(void) 1534 1441 { 1535 - _kvm_arch_hardware_disable(NULL); 1442 + if (!is_protected_kvm_enabled()) 1443 + _kvm_arch_hardware_disable(NULL); 1536 1444 } 1537 1445 1538 1446 #ifdef CONFIG_CPU_PM ··· 1576 1482 1577 1483 static void __init hyp_cpu_pm_init(void) 1578 1484 { 1579 - cpu_pm_register_notifier(&hyp_init_cpu_pm_nb); 1485 + if (!is_protected_kvm_enabled()) 1486 + cpu_pm_register_notifier(&hyp_init_cpu_pm_nb); 1580 1487 } 1581 1488 static void __init hyp_cpu_pm_exit(void) 1582 1489 { 1583 - cpu_pm_unregister_notifier(&hyp_init_cpu_pm_nb); 1490 + if (!is_protected_kvm_enabled()) 1491 + cpu_pm_unregister_notifier(&hyp_init_cpu_pm_nb); 1584 1492 } 1585 1493 #else 1586 1494 static inline void hyp_cpu_pm_init(void) ··· 1592 1496 { 1593 1497 } 1594 1498 #endif 1499 + 1500 + static void init_cpu_logical_map(void) 1501 + { 1502 + unsigned int cpu; 1503 + 1504 + /* 1505 + * Copy the MPIDR <-> logical CPU ID mapping to hyp. 1506 + * Only copy the set of online CPUs whose features have been chacked 1507 + * against the finalized system capabilities. The hypervisor will not 1508 + * allow any other CPUs from the `possible` set to boot. 1509 + */ 1510 + for_each_online_cpu(cpu) 1511 + kvm_nvhe_sym(__cpu_logical_map)[cpu] = cpu_logical_map(cpu); 1512 + } 1513 + 1514 + static bool init_psci_relay(void) 1515 + { 1516 + /* 1517 + * If PSCI has not been initialized, protected KVM cannot install 1518 + * itself on newly booted CPUs. 1519 + */ 1520 + if (!psci_ops.get_version) { 1521 + kvm_err("Cannot initialize protected mode without PSCI\n"); 1522 + return false; 1523 + } 1524 + 1525 + kvm_nvhe_sym(kvm_host_psci_version) = psci_ops.get_version(); 1526 + kvm_nvhe_sym(kvm_host_psci_0_1_function_ids) = get_psci_0_1_function_ids(); 1527 + return true; 1528 + } 1595 1529 1596 1530 static int init_common_resources(void) 1597 1531 { ··· 1667 1541 goto out; 1668 1542 1669 1543 kvm_perf_init(); 1670 - kvm_coproc_table_init(); 1544 + kvm_sys_reg_table_init(); 1671 1545 1672 1546 out: 1673 - on_each_cpu(_kvm_arch_hardware_disable, NULL, 1); 1547 + if (err || !is_protected_kvm_enabled()) 1548 + on_each_cpu(_kvm_arch_hardware_disable, NULL, 1); 1674 1549 1675 1550 return err; 1676 1551 } ··· 1745 1618 goto out_err; 1746 1619 } 1747 1620 1621 + err = create_hyp_mappings(kvm_ksym_ref(__hyp_data_ro_after_init_start), 1622 + kvm_ksym_ref(__hyp_data_ro_after_init_end), 1623 + PAGE_HYP_RO); 1624 + if (err) { 1625 + kvm_err("Cannot map .hyp.data..ro_after_init section\n"); 1626 + goto out_err; 1627 + } 1628 + 1748 1629 err = create_hyp_mappings(kvm_ksym_ref(__start_rodata), 1749 1630 kvm_ksym_ref(__end_rodata), PAGE_HYP_RO); 1750 1631 if (err) { ··· 1764 1629 kvm_ksym_ref(__bss_stop), PAGE_HYP_RO); 1765 1630 if (err) { 1766 1631 kvm_err("Cannot map bss section\n"); 1767 - goto out_err; 1768 - } 1769 - 1770 - err = kvm_map_vectors(); 1771 - if (err) { 1772 - kvm_err("Cannot map vectors\n"); 1773 1632 goto out_err; 1774 1633 } 1775 1634 ··· 1794 1665 kvm_err("Cannot map hyp percpu region\n"); 1795 1666 goto out_err; 1796 1667 } 1668 + } 1669 + 1670 + if (is_protected_kvm_enabled()) { 1671 + init_cpu_logical_map(); 1672 + 1673 + if (!init_psci_relay()) 1674 + goto out_err; 1797 1675 } 1798 1676 1799 1677 return 0; ··· 1917 1781 goto out_err; 1918 1782 } 1919 1783 1784 + err = kvm_init_vector_slots(); 1785 + if (err) { 1786 + kvm_err("Cannot initialise vector slots\n"); 1787 + goto out_err; 1788 + } 1789 + 1920 1790 err = init_subsystems(); 1921 1791 if (err) 1922 1792 goto out_hyp; 1923 1793 1924 - if (in_hyp_mode) 1794 + if (is_protected_kvm_enabled()) { 1795 + static_branch_enable(&kvm_protected_mode_initialized); 1796 + kvm_info("Protected nVHE mode initialized successfully\n"); 1797 + } else if (in_hyp_mode) { 1925 1798 kvm_info("VHE mode initialized successfully\n"); 1926 - else 1799 + } else { 1927 1800 kvm_info("Hyp mode initialized successfully\n"); 1801 + } 1928 1802 1929 1803 return 0; 1930 1804 ··· 1950 1804 void kvm_arch_exit(void) 1951 1805 { 1952 1806 kvm_perf_teardown(); 1807 + } 1808 + 1809 + static int __init early_kvm_mode_cfg(char *arg) 1810 + { 1811 + if (!arg) 1812 + return -EINVAL; 1813 + 1814 + if (strcmp(arg, "protected") == 0) { 1815 + kvm_mode = KVM_MODE_PROTECTED; 1816 + return 0; 1817 + } 1818 + 1819 + return -EINVAL; 1820 + } 1821 + early_param("kvm-arm.mode", early_kvm_mode_cfg); 1822 + 1823 + enum kvm_mode kvm_get_mode(void) 1824 + { 1825 + return kvm_mode; 1953 1826 } 1954 1827 1955 1828 static int arm_init(void)
+25 -4
arch/arm64/kvm/guest.c
··· 24 24 #include <asm/fpsimd.h> 25 25 #include <asm/kvm.h> 26 26 #include <asm/kvm_emulate.h> 27 - #include <asm/kvm_coproc.h> 28 27 #include <asm/sigcontext.h> 29 28 30 29 #include "trace.h" ··· 251 252 memcpy(addr, valp, KVM_REG_SIZE(reg->id)); 252 253 253 254 if (*vcpu_cpsr(vcpu) & PSR_MODE32_BIT) { 254 - int i; 255 + int i, nr_reg; 255 256 256 - for (i = 0; i < 16; i++) 257 - *vcpu_reg32(vcpu, i) = (u32)*vcpu_reg32(vcpu, i); 257 + switch (*vcpu_cpsr(vcpu)) { 258 + /* 259 + * Either we are dealing with user mode, and only the 260 + * first 15 registers (+ PC) must be narrowed to 32bit. 261 + * AArch32 r0-r14 conveniently map to AArch64 x0-x14. 262 + */ 263 + case PSR_AA32_MODE_USR: 264 + case PSR_AA32_MODE_SYS: 265 + nr_reg = 15; 266 + break; 267 + 268 + /* 269 + * Otherwide, this is a priviledged mode, and *all* the 270 + * registers must be narrowed to 32bit. 271 + */ 272 + default: 273 + nr_reg = 31; 274 + break; 275 + } 276 + 277 + for (i = 0; i < nr_reg; i++) 278 + vcpu_set_reg(vcpu, i, (u32)vcpu_get_reg(vcpu, i)); 279 + 280 + *vcpu_pc(vcpu) = (u32)*vcpu_pc(vcpu); 258 281 } 259 282 out: 260 283 return err;
+3 -21
arch/arm64/kvm/handle_exit.c
··· 14 14 #include <asm/esr.h> 15 15 #include <asm/exception.h> 16 16 #include <asm/kvm_asm.h> 17 - #include <asm/kvm_coproc.h> 18 17 #include <asm/kvm_emulate.h> 19 18 #include <asm/kvm_mmu.h> 20 19 #include <asm/debug-monitors.h> ··· 60 61 * otherwise return to the same address... 61 62 */ 62 63 vcpu_set_reg(vcpu, 0, ~0UL); 63 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 64 + kvm_incr_pc(vcpu); 64 65 return 1; 65 66 } 66 67 ··· 99 100 kvm_clear_request(KVM_REQ_UNHALT, vcpu); 100 101 } 101 102 102 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 103 + kvm_incr_pc(vcpu); 103 104 104 105 return 1; 105 106 } ··· 220 221 * that fail their condition code check" 221 222 */ 222 223 if (!kvm_condition_valid(vcpu)) { 223 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 224 + kvm_incr_pc(vcpu); 224 225 handled = 1; 225 226 } else { 226 227 exit_handle_fn exit_handler; ··· 239 240 int handle_exit(struct kvm_vcpu *vcpu, int exception_index) 240 241 { 241 242 struct kvm_run *run = vcpu->run; 242 - 243 - if (ARM_SERROR_PENDING(exception_index)) { 244 - u8 esr_ec = ESR_ELx_EC(kvm_vcpu_get_esr(vcpu)); 245 - 246 - /* 247 - * HVC/SMC already have an adjusted PC, which we need 248 - * to correct in order to return to after having 249 - * injected the SError. 250 - */ 251 - if (esr_ec == ESR_ELx_EC_HVC32 || esr_ec == ESR_ELx_EC_HVC64 || 252 - esr_ec == ESR_ELx_EC_SMC32 || esr_ec == ESR_ELx_EC_SMC64) { 253 - u32 adj = kvm_vcpu_trap_il_is32bit(vcpu) ? 4 : 2; 254 - *vcpu_pc(vcpu) -= adj; 255 - } 256 - 257 - return 1; 258 - } 259 243 260 244 exception_index = ARM_EXCEPTION_CODE(exception_index); 261 245
+1 -1
arch/arm64/kvm/hyp/Makefile
··· 10 10 -DDISABLE_BRANCH_PROFILING \ 11 11 $(DISABLE_STACKLEAK_PLUGIN) 12 12 13 - obj-$(CONFIG_KVM) += vhe/ nvhe/ pgtable.o smccc_wa.o 13 + obj-$(CONFIG_KVM) += vhe/ nvhe/ pgtable.o
+2 -2
arch/arm64/kvm/hyp/aarch32.c
··· 123 123 * kvm_skip_instr - skip a trapped instruction and proceed to the next 124 124 * @vcpu: The vcpu pointer 125 125 */ 126 - void kvm_skip_instr32(struct kvm_vcpu *vcpu, bool is_wide_instr) 126 + void kvm_skip_instr32(struct kvm_vcpu *vcpu) 127 127 { 128 128 u32 pc = *vcpu_pc(vcpu); 129 129 bool is_thumb; 130 130 131 131 is_thumb = !!(*vcpu_cpsr(vcpu) & PSR_AA32_T_BIT); 132 - if (is_thumb && !is_wide_instr) 132 + if (is_thumb && !kvm_vcpu_trap_il_is32bit(vcpu)) 133 133 pc += 2; 134 134 else 135 135 pc += 4;
+331
arch/arm64/kvm/hyp/exception.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Fault injection for both 32 and 64bit guests. 4 + * 5 + * Copyright (C) 2012,2013 - ARM Ltd 6 + * Author: Marc Zyngier <marc.zyngier@arm.com> 7 + * 8 + * Based on arch/arm/kvm/emulate.c 9 + * Copyright (C) 2012 - Virtual Open Systems and Columbia University 10 + * Author: Christoffer Dall <c.dall@virtualopensystems.com> 11 + */ 12 + 13 + #include <hyp/adjust_pc.h> 14 + #include <linux/kvm_host.h> 15 + #include <asm/kvm_emulate.h> 16 + 17 + #if !defined (__KVM_NVHE_HYPERVISOR__) && !defined (__KVM_VHE_HYPERVISOR__) 18 + #error Hypervisor code only! 19 + #endif 20 + 21 + static inline u64 __vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg) 22 + { 23 + u64 val; 24 + 25 + if (__vcpu_read_sys_reg_from_cpu(reg, &val)) 26 + return val; 27 + 28 + return __vcpu_sys_reg(vcpu, reg); 29 + } 30 + 31 + static inline void __vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg) 32 + { 33 + if (__vcpu_write_sys_reg_to_cpu(val, reg)) 34 + return; 35 + 36 + __vcpu_sys_reg(vcpu, reg) = val; 37 + } 38 + 39 + static void __vcpu_write_spsr(struct kvm_vcpu *vcpu, u64 val) 40 + { 41 + write_sysreg_el1(val, SYS_SPSR); 42 + } 43 + 44 + static void __vcpu_write_spsr_abt(struct kvm_vcpu *vcpu, u64 val) 45 + { 46 + if (has_vhe()) 47 + write_sysreg(val, spsr_abt); 48 + else 49 + vcpu->arch.ctxt.spsr_abt = val; 50 + } 51 + 52 + static void __vcpu_write_spsr_und(struct kvm_vcpu *vcpu, u64 val) 53 + { 54 + if (has_vhe()) 55 + write_sysreg(val, spsr_und); 56 + else 57 + vcpu->arch.ctxt.spsr_und = val; 58 + } 59 + 60 + /* 61 + * This performs the exception entry at a given EL (@target_mode), stashing PC 62 + * and PSTATE into ELR and SPSR respectively, and compute the new PC/PSTATE. 63 + * The EL passed to this function *must* be a non-secure, privileged mode with 64 + * bit 0 being set (PSTATE.SP == 1). 65 + * 66 + * When an exception is taken, most PSTATE fields are left unchanged in the 67 + * handler. However, some are explicitly overridden (e.g. M[4:0]). Luckily all 68 + * of the inherited bits have the same position in the AArch64/AArch32 SPSR_ELx 69 + * layouts, so we don't need to shuffle these for exceptions from AArch32 EL0. 70 + * 71 + * For the SPSR_ELx layout for AArch64, see ARM DDI 0487E.a page C5-429. 72 + * For the SPSR_ELx layout for AArch32, see ARM DDI 0487E.a page C5-426. 73 + * 74 + * Here we manipulate the fields in order of the AArch64 SPSR_ELx layout, from 75 + * MSB to LSB. 76 + */ 77 + static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode, 78 + enum exception_type type) 79 + { 80 + unsigned long sctlr, vbar, old, new, mode; 81 + u64 exc_offset; 82 + 83 + mode = *vcpu_cpsr(vcpu) & (PSR_MODE_MASK | PSR_MODE32_BIT); 84 + 85 + if (mode == target_mode) 86 + exc_offset = CURRENT_EL_SP_ELx_VECTOR; 87 + else if ((mode | PSR_MODE_THREAD_BIT) == target_mode) 88 + exc_offset = CURRENT_EL_SP_EL0_VECTOR; 89 + else if (!(mode & PSR_MODE32_BIT)) 90 + exc_offset = LOWER_EL_AArch64_VECTOR; 91 + else 92 + exc_offset = LOWER_EL_AArch32_VECTOR; 93 + 94 + switch (target_mode) { 95 + case PSR_MODE_EL1h: 96 + vbar = __vcpu_read_sys_reg(vcpu, VBAR_EL1); 97 + sctlr = __vcpu_read_sys_reg(vcpu, SCTLR_EL1); 98 + __vcpu_write_sys_reg(vcpu, *vcpu_pc(vcpu), ELR_EL1); 99 + break; 100 + default: 101 + /* Don't do that */ 102 + BUG(); 103 + } 104 + 105 + *vcpu_pc(vcpu) = vbar + exc_offset + type; 106 + 107 + old = *vcpu_cpsr(vcpu); 108 + new = 0; 109 + 110 + new |= (old & PSR_N_BIT); 111 + new |= (old & PSR_Z_BIT); 112 + new |= (old & PSR_C_BIT); 113 + new |= (old & PSR_V_BIT); 114 + 115 + // TODO: TCO (if/when ARMv8.5-MemTag is exposed to guests) 116 + 117 + new |= (old & PSR_DIT_BIT); 118 + 119 + // PSTATE.UAO is set to zero upon any exception to AArch64 120 + // See ARM DDI 0487E.a, page D5-2579. 121 + 122 + // PSTATE.PAN is unchanged unless SCTLR_ELx.SPAN == 0b0 123 + // SCTLR_ELx.SPAN is RES1 when ARMv8.1-PAN is not implemented 124 + // See ARM DDI 0487E.a, page D5-2578. 125 + new |= (old & PSR_PAN_BIT); 126 + if (!(sctlr & SCTLR_EL1_SPAN)) 127 + new |= PSR_PAN_BIT; 128 + 129 + // PSTATE.SS is set to zero upon any exception to AArch64 130 + // See ARM DDI 0487E.a, page D2-2452. 131 + 132 + // PSTATE.IL is set to zero upon any exception to AArch64 133 + // See ARM DDI 0487E.a, page D1-2306. 134 + 135 + // PSTATE.SSBS is set to SCTLR_ELx.DSSBS upon any exception to AArch64 136 + // See ARM DDI 0487E.a, page D13-3258 137 + if (sctlr & SCTLR_ELx_DSSBS) 138 + new |= PSR_SSBS_BIT; 139 + 140 + // PSTATE.BTYPE is set to zero upon any exception to AArch64 141 + // See ARM DDI 0487E.a, pages D1-2293 to D1-2294. 142 + 143 + new |= PSR_D_BIT; 144 + new |= PSR_A_BIT; 145 + new |= PSR_I_BIT; 146 + new |= PSR_F_BIT; 147 + 148 + new |= target_mode; 149 + 150 + *vcpu_cpsr(vcpu) = new; 151 + __vcpu_write_spsr(vcpu, old); 152 + } 153 + 154 + /* 155 + * When an exception is taken, most CPSR fields are left unchanged in the 156 + * handler. However, some are explicitly overridden (e.g. M[4:0]). 157 + * 158 + * The SPSR/SPSR_ELx layouts differ, and the below is intended to work with 159 + * either format. Note: SPSR.J bit doesn't exist in SPSR_ELx, but this bit was 160 + * obsoleted by the ARMv7 virtualization extensions and is RES0. 161 + * 162 + * For the SPSR layout seen from AArch32, see: 163 + * - ARM DDI 0406C.d, page B1-1148 164 + * - ARM DDI 0487E.a, page G8-6264 165 + * 166 + * For the SPSR_ELx layout for AArch32 seen from AArch64, see: 167 + * - ARM DDI 0487E.a, page C5-426 168 + * 169 + * Here we manipulate the fields in order of the AArch32 SPSR_ELx layout, from 170 + * MSB to LSB. 171 + */ 172 + static unsigned long get_except32_cpsr(struct kvm_vcpu *vcpu, u32 mode) 173 + { 174 + u32 sctlr = __vcpu_read_sys_reg(vcpu, SCTLR_EL1); 175 + unsigned long old, new; 176 + 177 + old = *vcpu_cpsr(vcpu); 178 + new = 0; 179 + 180 + new |= (old & PSR_AA32_N_BIT); 181 + new |= (old & PSR_AA32_Z_BIT); 182 + new |= (old & PSR_AA32_C_BIT); 183 + new |= (old & PSR_AA32_V_BIT); 184 + new |= (old & PSR_AA32_Q_BIT); 185 + 186 + // CPSR.IT[7:0] are set to zero upon any exception 187 + // See ARM DDI 0487E.a, section G1.12.3 188 + // See ARM DDI 0406C.d, section B1.8.3 189 + 190 + new |= (old & PSR_AA32_DIT_BIT); 191 + 192 + // CPSR.SSBS is set to SCTLR.DSSBS upon any exception 193 + // See ARM DDI 0487E.a, page G8-6244 194 + if (sctlr & BIT(31)) 195 + new |= PSR_AA32_SSBS_BIT; 196 + 197 + // CPSR.PAN is unchanged unless SCTLR.SPAN == 0b0 198 + // SCTLR.SPAN is RES1 when ARMv8.1-PAN is not implemented 199 + // See ARM DDI 0487E.a, page G8-6246 200 + new |= (old & PSR_AA32_PAN_BIT); 201 + if (!(sctlr & BIT(23))) 202 + new |= PSR_AA32_PAN_BIT; 203 + 204 + // SS does not exist in AArch32, so ignore 205 + 206 + // CPSR.IL is set to zero upon any exception 207 + // See ARM DDI 0487E.a, page G1-5527 208 + 209 + new |= (old & PSR_AA32_GE_MASK); 210 + 211 + // CPSR.IT[7:0] are set to zero upon any exception 212 + // See prior comment above 213 + 214 + // CPSR.E is set to SCTLR.EE upon any exception 215 + // See ARM DDI 0487E.a, page G8-6245 216 + // See ARM DDI 0406C.d, page B4-1701 217 + if (sctlr & BIT(25)) 218 + new |= PSR_AA32_E_BIT; 219 + 220 + // CPSR.A is unchanged upon an exception to Undefined, Supervisor 221 + // CPSR.A is set upon an exception to other modes 222 + // See ARM DDI 0487E.a, pages G1-5515 to G1-5516 223 + // See ARM DDI 0406C.d, page B1-1182 224 + new |= (old & PSR_AA32_A_BIT); 225 + if (mode != PSR_AA32_MODE_UND && mode != PSR_AA32_MODE_SVC) 226 + new |= PSR_AA32_A_BIT; 227 + 228 + // CPSR.I is set upon any exception 229 + // See ARM DDI 0487E.a, pages G1-5515 to G1-5516 230 + // See ARM DDI 0406C.d, page B1-1182 231 + new |= PSR_AA32_I_BIT; 232 + 233 + // CPSR.F is set upon an exception to FIQ 234 + // CPSR.F is unchanged upon an exception to other modes 235 + // See ARM DDI 0487E.a, pages G1-5515 to G1-5516 236 + // See ARM DDI 0406C.d, page B1-1182 237 + new |= (old & PSR_AA32_F_BIT); 238 + if (mode == PSR_AA32_MODE_FIQ) 239 + new |= PSR_AA32_F_BIT; 240 + 241 + // CPSR.T is set to SCTLR.TE upon any exception 242 + // See ARM DDI 0487E.a, page G8-5514 243 + // See ARM DDI 0406C.d, page B1-1181 244 + if (sctlr & BIT(30)) 245 + new |= PSR_AA32_T_BIT; 246 + 247 + new |= mode; 248 + 249 + return new; 250 + } 251 + 252 + /* 253 + * Table taken from ARMv8 ARM DDI0487B-B, table G1-10. 254 + */ 255 + static const u8 return_offsets[8][2] = { 256 + [0] = { 0, 0 }, /* Reset, unused */ 257 + [1] = { 4, 2 }, /* Undefined */ 258 + [2] = { 0, 0 }, /* SVC, unused */ 259 + [3] = { 4, 4 }, /* Prefetch abort */ 260 + [4] = { 8, 8 }, /* Data abort */ 261 + [5] = { 0, 0 }, /* HVC, unused */ 262 + [6] = { 4, 4 }, /* IRQ, unused */ 263 + [7] = { 4, 4 }, /* FIQ, unused */ 264 + }; 265 + 266 + static void enter_exception32(struct kvm_vcpu *vcpu, u32 mode, u32 vect_offset) 267 + { 268 + unsigned long spsr = *vcpu_cpsr(vcpu); 269 + bool is_thumb = (spsr & PSR_AA32_T_BIT); 270 + u32 sctlr = __vcpu_read_sys_reg(vcpu, SCTLR_EL1); 271 + u32 return_address; 272 + 273 + *vcpu_cpsr(vcpu) = get_except32_cpsr(vcpu, mode); 274 + return_address = *vcpu_pc(vcpu); 275 + return_address += return_offsets[vect_offset >> 2][is_thumb]; 276 + 277 + /* KVM only enters the ABT and UND modes, so only deal with those */ 278 + switch(mode) { 279 + case PSR_AA32_MODE_ABT: 280 + __vcpu_write_spsr_abt(vcpu, host_spsr_to_spsr32(spsr)); 281 + vcpu_gp_regs(vcpu)->compat_lr_abt = return_address; 282 + break; 283 + 284 + case PSR_AA32_MODE_UND: 285 + __vcpu_write_spsr_und(vcpu, host_spsr_to_spsr32(spsr)); 286 + vcpu_gp_regs(vcpu)->compat_lr_und = return_address; 287 + break; 288 + } 289 + 290 + /* Branch to exception vector */ 291 + if (sctlr & (1 << 13)) 292 + vect_offset += 0xffff0000; 293 + else /* always have security exceptions */ 294 + vect_offset += __vcpu_read_sys_reg(vcpu, VBAR_EL1); 295 + 296 + *vcpu_pc(vcpu) = vect_offset; 297 + } 298 + 299 + void kvm_inject_exception(struct kvm_vcpu *vcpu) 300 + { 301 + if (vcpu_el1_is_32bit(vcpu)) { 302 + switch (vcpu->arch.flags & KVM_ARM64_EXCEPT_MASK) { 303 + case KVM_ARM64_EXCEPT_AA32_UND: 304 + enter_exception32(vcpu, PSR_AA32_MODE_UND, 4); 305 + break; 306 + case KVM_ARM64_EXCEPT_AA32_IABT: 307 + enter_exception32(vcpu, PSR_AA32_MODE_ABT, 12); 308 + break; 309 + case KVM_ARM64_EXCEPT_AA32_DABT: 310 + enter_exception32(vcpu, PSR_AA32_MODE_ABT, 16); 311 + break; 312 + default: 313 + /* Err... */ 314 + break; 315 + } 316 + } else { 317 + switch (vcpu->arch.flags & KVM_ARM64_EXCEPT_MASK) { 318 + case (KVM_ARM64_EXCEPT_AA64_ELx_SYNC | 319 + KVM_ARM64_EXCEPT_AA64_EL1): 320 + enter_exception64(vcpu, PSR_MODE_EL1h, except_type_sync); 321 + break; 322 + default: 323 + /* 324 + * Only EL1_SYNC makes sense so far, EL2_{SYNC,IRQ} 325 + * will be implemented at some point. Everything 326 + * else gets silently ignored. 327 + */ 328 + break; 329 + } 330 + } 331 + }
+45 -36
arch/arm64/kvm/hyp/hyp-entry.S
··· 13 13 #include <asm/kvm_arm.h> 14 14 #include <asm/kvm_asm.h> 15 15 #include <asm/mmu.h> 16 + #include <asm/spectre.h> 16 17 17 18 .macro save_caller_saved_regs_vect 18 19 /* x0 and x1 were saved in the vector entry */ ··· 188 187 valid_vect el1_error // Error 32-bit EL1 189 188 SYM_CODE_END(__kvm_hyp_vector) 190 189 191 - .macro hyp_ventry 192 - .align 7 193 - 1: esb 194 - .rept 26 195 - nop 196 - .endr 197 - /* 198 - * The default sequence is to directly branch to the KVM vectors, 199 - * using the computed offset. This applies for VHE as well as 200 - * !ARM64_HARDEN_EL2_VECTORS. The first vector must always run the preamble. 201 - * 202 - * For ARM64_HARDEN_EL2_VECTORS configurations, this gets replaced 203 - * with: 204 - * 205 - * stp x0, x1, [sp, #-16]! 206 - * movz x0, #(addr & 0xffff) 207 - * movk x0, #((addr >> 16) & 0xffff), lsl #16 208 - * movk x0, #((addr >> 32) & 0xffff), lsl #32 209 - * br x0 210 - * 211 - * Where: 212 - * addr = kern_hyp_va(__kvm_hyp_vector) + vector-offset + KVM_VECTOR_PREAMBLE. 213 - * See kvm_patch_vector_branch for details. 214 - */ 215 - alternative_cb kvm_patch_vector_branch 216 - stp x0, x1, [sp, #-16]! 217 - b __kvm_hyp_vector + (1b - 0b + KVM_VECTOR_PREAMBLE) 218 - nop 219 - nop 220 - nop 221 - alternative_cb_end 190 + .macro spectrev2_smccc_wa1_smc 191 + sub sp, sp, #(8 * 4) 192 + stp x2, x3, [sp, #(8 * 0)] 193 + stp x0, x1, [sp, #(8 * 2)] 194 + mov w0, #ARM_SMCCC_ARCH_WORKAROUND_1 195 + smc #0 196 + ldp x2, x3, [sp, #(8 * 0)] 197 + add sp, sp, #(8 * 2) 222 198 .endm 223 199 224 - .macro generate_vectors 200 + .macro hyp_ventry indirect, spectrev2 201 + .align 7 202 + 1: esb 203 + .if \spectrev2 != 0 204 + spectrev2_smccc_wa1_smc 205 + .else 206 + stp x0, x1, [sp, #-16]! 207 + .endif 208 + .if \indirect != 0 209 + alternative_cb kvm_patch_vector_branch 210 + /* 211 + * For ARM64_SPECTRE_V3A configurations, these NOPs get replaced with: 212 + * 213 + * movz x0, #(addr & 0xffff) 214 + * movk x0, #((addr >> 16) & 0xffff), lsl #16 215 + * movk x0, #((addr >> 32) & 0xffff), lsl #32 216 + * br x0 217 + * 218 + * Where: 219 + * addr = kern_hyp_va(__kvm_hyp_vector) + vector-offset + KVM_VECTOR_PREAMBLE. 220 + * See kvm_patch_vector_branch for details. 221 + */ 222 + nop 223 + nop 224 + nop 225 + nop 226 + alternative_cb_end 227 + .endif 228 + b __kvm_hyp_vector + (1b - 0b + KVM_VECTOR_PREAMBLE) 229 + .endm 230 + 231 + .macro generate_vectors indirect, spectrev2 225 232 0: 226 233 .rept 16 227 - hyp_ventry 234 + hyp_ventry \indirect, \spectrev2 228 235 .endr 229 236 .org 0b + SZ_2K // Safety measure 230 237 .endm 231 238 232 239 .align 11 233 240 SYM_CODE_START(__bp_harden_hyp_vecs) 234 - .rept BP_HARDEN_EL2_SLOTS 235 - generate_vectors 236 - .endr 241 + generate_vectors indirect = 0, spectrev2 = 1 // HYP_VECTOR_SPECTRE_DIRECT 242 + generate_vectors indirect = 1, spectrev2 = 0 // HYP_VECTOR_INDIRECT 243 + generate_vectors indirect = 1, spectrev2 = 1 // HYP_VECTOR_SPECTRE_INDIRECT 237 244 1: .org __bp_harden_hyp_vecs + __BP_HARDEN_HYP_VECS_SZ 238 245 .org 1b 239 246 SYM_CODE_END(__bp_harden_hyp_vecs)
+62
arch/arm64/kvm/hyp/include/hyp/adjust_pc.h
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Guest PC manipulation helpers 4 + * 5 + * Copyright (C) 2012,2013 - ARM Ltd 6 + * Copyright (C) 2020 - Google LLC 7 + * Author: Marc Zyngier <maz@kernel.org> 8 + */ 9 + 10 + #ifndef __ARM64_KVM_HYP_ADJUST_PC_H__ 11 + #define __ARM64_KVM_HYP_ADJUST_PC_H__ 12 + 13 + #include <asm/kvm_emulate.h> 14 + #include <asm/kvm_host.h> 15 + 16 + void kvm_inject_exception(struct kvm_vcpu *vcpu); 17 + 18 + static inline void kvm_skip_instr(struct kvm_vcpu *vcpu) 19 + { 20 + if (vcpu_mode_is_32bit(vcpu)) { 21 + kvm_skip_instr32(vcpu); 22 + } else { 23 + *vcpu_pc(vcpu) += 4; 24 + *vcpu_cpsr(vcpu) &= ~PSR_BTYPE_MASK; 25 + } 26 + 27 + /* advance the singlestep state machine */ 28 + *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; 29 + } 30 + 31 + /* 32 + * Skip an instruction which has been emulated at hyp while most guest sysregs 33 + * are live. 34 + */ 35 + static inline void __kvm_skip_instr(struct kvm_vcpu *vcpu) 36 + { 37 + *vcpu_pc(vcpu) = read_sysreg_el2(SYS_ELR); 38 + vcpu_gp_regs(vcpu)->pstate = read_sysreg_el2(SYS_SPSR); 39 + 40 + kvm_skip_instr(vcpu); 41 + 42 + write_sysreg_el2(vcpu_gp_regs(vcpu)->pstate, SYS_SPSR); 43 + write_sysreg_el2(*vcpu_pc(vcpu), SYS_ELR); 44 + } 45 + 46 + /* 47 + * Adjust the guest PC on entry, depending on flags provided by EL1 48 + * for the purpose of emulation (MMIO, sysreg) or exception injection. 49 + */ 50 + static inline void __adjust_pc(struct kvm_vcpu *vcpu) 51 + { 52 + if (vcpu->arch.flags & KVM_ARM64_PENDING_EXCEPTION) { 53 + kvm_inject_exception(vcpu); 54 + vcpu->arch.flags &= ~(KVM_ARM64_PENDING_EXCEPTION | 55 + KVM_ARM64_EXCEPT_MASK); 56 + } else if (vcpu->arch.flags & KVM_ARM64_INCREMENT_PC) { 57 + kvm_skip_instr(vcpu); 58 + vcpu->arch.flags &= ~KVM_ARM64_INCREMENT_PC; 59 + } 60 + } 61 + 62 + #endif
+17
arch/arm64/kvm/hyp/include/hyp/switch.h
··· 7 7 #ifndef __ARM64_KVM_HYP_SWITCH_H__ 8 8 #define __ARM64_KVM_HYP_SWITCH_H__ 9 9 10 + #include <hyp/adjust_pc.h> 11 + 10 12 #include <linux/arm-smccc.h> 11 13 #include <linux/kvm_host.h> 12 14 #include <linux/types.h> ··· 410 408 { 411 409 if (ARM_EXCEPTION_CODE(*exit_code) != ARM_EXCEPTION_IRQ) 412 410 vcpu->arch.fault.esr_el2 = read_sysreg_el2(SYS_ESR); 411 + 412 + if (ARM_SERROR_PENDING(*exit_code)) { 413 + u8 esr_ec = kvm_vcpu_trap_get_class(vcpu); 414 + 415 + /* 416 + * HVC already have an adjusted PC, which we need to 417 + * correct in order to return to after having injected 418 + * the SError. 419 + * 420 + * SMC, on the other hand, is *trapped*, meaning its 421 + * preferred return address is the SMC itself. 422 + */ 423 + if (esr_ec == ESR_ELx_EC_HVC32 || esr_ec == ESR_ELx_EC_HVC64) 424 + write_sysreg_el2(read_sysreg_el2(SYS_ELR) - 4, SYS_ELR); 425 + } 413 426 414 427 /* 415 428 * We're using the raw exception code in order to only process
+18
arch/arm64/kvm/hyp/include/nvhe/trap_handler.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Trap handler helpers. 4 + * 5 + * Copyright (C) 2020 - Google LLC 6 + * Author: Marc Zyngier <maz@kernel.org> 7 + */ 8 + 9 + #ifndef __ARM64_KVM_NVHE_TRAP_HANDLER_H__ 10 + #define __ARM64_KVM_NVHE_TRAP_HANDLER_H__ 11 + 12 + #include <asm/kvm_host.h> 13 + 14 + #define cpu_reg(ctxt, r) (ctxt)->regs.regs[r] 15 + #define DECLARE_REG(type, name, ctxt, reg) \ 16 + type name = (type)cpu_reg(ctxt, (reg)) 17 + 18 + #endif /* __ARM64_KVM_NVHE_TRAP_HANDLER_H__ */
+3 -2
arch/arm64/kvm/hyp/nvhe/Makefile
··· 6 6 asflags-y := -D__KVM_NVHE_HYPERVISOR__ 7 7 ccflags-y := -D__KVM_NVHE_HYPERVISOR__ 8 8 9 - obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o hyp-main.o 9 + obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ 10 + hyp-main.o hyp-smp.o psci-relay.o 10 11 obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ 11 - ../fpsimd.o ../hyp-entry.o 12 + ../fpsimd.o ../hyp-entry.o ../exception.o 12 13 13 14 ## 14 15 ## Build rules for compiling nVHE hyp code
+51 -7
arch/arm64/kvm/hyp/nvhe/host.S
··· 13 13 .text 14 14 15 15 SYM_FUNC_START(__host_exit) 16 - stp x0, x1, [sp, #-16]! 17 - 18 16 get_host_ctxt x0, x1 19 17 20 18 /* Store the host regs x2 and x3 */ ··· 39 41 bl handle_trap 40 42 41 43 /* Restore host regs x0-x17 */ 44 + __host_enter_restore_full: 42 45 ldp x0, x1, [x29, #CPU_XREG_OFFSET(0)] 43 46 ldp x2, x3, [x29, #CPU_XREG_OFFSET(2)] 44 47 ldp x4, x5, [x29, #CPU_XREG_OFFSET(4)] ··· 61 62 eret 62 63 sb 63 64 SYM_FUNC_END(__host_exit) 65 + 66 + /* 67 + * void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt); 68 + */ 69 + SYM_FUNC_START(__host_enter) 70 + mov x29, x0 71 + b __host_enter_restore_full 72 + SYM_FUNC_END(__host_enter) 64 73 65 74 /* 66 75 * void __noreturn __hyp_do_panic(bool restore_host, u64 spsr, u64 elr, u64 par); ··· 106 99 mrs x0, esr_el2 107 100 lsr x0, x0, #ESR_ELx_EC_SHIFT 108 101 cmp x0, #ESR_ELx_EC_HVC64 109 - ldp x0, x1, [sp], #16 110 102 b.ne __host_exit 103 + 104 + ldp x0, x1, [sp] // Don't fixup the stack yet 111 105 112 106 /* Check for a stub HVC call */ 113 107 cmp x0, #HVC_STUB_HCALL_NR 114 108 b.hs __host_exit 115 109 110 + add sp, sp, #16 116 111 /* 117 112 * Compute the idmap address of __kvm_handle_stub_hvc and 118 113 * jump there. Since we use kimage_voffset, do not use the ··· 124 115 * Preserve x0-x4, which may contain stub parameters. 125 116 */ 126 117 ldr x5, =__kvm_handle_stub_hvc 127 - ldr_l x6, kimage_voffset 128 - 129 - /* x5 = __pa(x5) */ 130 - sub x5, x5, x6 118 + kimg_pa x5, x6 131 119 br x5 132 120 .L__vect_end\@: 133 121 .if ((.L__vect_end\@ - .L__vect_start\@) > 0x80) ··· 189 183 invalid_host_el1_vect // FIQ 32-bit EL1 190 184 invalid_host_el1_vect // Error 32-bit EL1 191 185 SYM_CODE_END(__kvm_hyp_host_vector) 186 + 187 + /* 188 + * Forward SMC with arguments in struct kvm_cpu_context, and 189 + * store the result into the same struct. Assumes SMCCC 1.2 or older. 190 + * 191 + * x0: struct kvm_cpu_context* 192 + */ 193 + SYM_CODE_START(__kvm_hyp_host_forward_smc) 194 + /* 195 + * Use x18 to keep the pointer to the host context because 196 + * x18 is callee-saved in SMCCC but not in AAPCS64. 197 + */ 198 + mov x18, x0 199 + 200 + ldp x0, x1, [x18, #CPU_XREG_OFFSET(0)] 201 + ldp x2, x3, [x18, #CPU_XREG_OFFSET(2)] 202 + ldp x4, x5, [x18, #CPU_XREG_OFFSET(4)] 203 + ldp x6, x7, [x18, #CPU_XREG_OFFSET(6)] 204 + ldp x8, x9, [x18, #CPU_XREG_OFFSET(8)] 205 + ldp x10, x11, [x18, #CPU_XREG_OFFSET(10)] 206 + ldp x12, x13, [x18, #CPU_XREG_OFFSET(12)] 207 + ldp x14, x15, [x18, #CPU_XREG_OFFSET(14)] 208 + ldp x16, x17, [x18, #CPU_XREG_OFFSET(16)] 209 + 210 + smc #0 211 + 212 + stp x0, x1, [x18, #CPU_XREG_OFFSET(0)] 213 + stp x2, x3, [x18, #CPU_XREG_OFFSET(2)] 214 + stp x4, x5, [x18, #CPU_XREG_OFFSET(4)] 215 + stp x6, x7, [x18, #CPU_XREG_OFFSET(6)] 216 + stp x8, x9, [x18, #CPU_XREG_OFFSET(8)] 217 + stp x10, x11, [x18, #CPU_XREG_OFFSET(10)] 218 + stp x12, x13, [x18, #CPU_XREG_OFFSET(12)] 219 + stp x14, x15, [x18, #CPU_XREG_OFFSET(14)] 220 + stp x16, x17, [x18, #CPU_XREG_OFFSET(16)] 221 + 222 + ret 223 + SYM_CODE_END(__kvm_hyp_host_forward_smc)
+108 -44
arch/arm64/kvm/hyp/nvhe/hyp-init.S
··· 9 9 10 10 #include <asm/alternative.h> 11 11 #include <asm/assembler.h> 12 + #include <asm/el2_setup.h> 12 13 #include <asm/kvm_arm.h> 13 14 #include <asm/kvm_asm.h> 14 15 #include <asm/kvm_mmu.h> ··· 48 47 49 48 /* 50 49 * x0: SMCCC function ID 51 - * x1: HYP pgd 52 - * x2: per-CPU offset 53 - * x3: HYP stack 54 - * x4: HYP vectors 50 + * x1: struct kvm_nvhe_init_params PA 55 51 */ 56 52 __do_hyp_init: 57 53 /* Check for a stub HVC call */ ··· 69 71 mov x0, #SMCCC_RET_NOT_SUPPORTED 70 72 eret 71 73 72 - 1: 73 - /* Set tpidr_el2 for use by HYP to free a register */ 74 - msr tpidr_el2, x2 74 + 1: mov x0, x1 75 + mov x4, lr 76 + bl ___kvm_hyp_init 77 + mov lr, x4 75 78 76 - phys_to_ttbr x0, x1 77 - alternative_if ARM64_HAS_CNP 78 - orr x0, x0, #TTBR_CNP_BIT 79 + /* Hello, World! */ 80 + mov x0, #SMCCC_RET_SUCCESS 81 + eret 82 + SYM_CODE_END(__kvm_hyp_init) 83 + 84 + /* 85 + * Initialize the hypervisor in EL2. 86 + * 87 + * Only uses x0..x3 so as to not clobber callee-saved SMCCC registers 88 + * and leave x4 for the caller. 89 + * 90 + * x0: struct kvm_nvhe_init_params PA 91 + */ 92 + SYM_CODE_START_LOCAL(___kvm_hyp_init) 93 + alternative_if ARM64_KVM_PROTECTED_MODE 94 + mov_q x1, HCR_HOST_NVHE_PROTECTED_FLAGS 95 + msr hcr_el2, x1 79 96 alternative_else_nop_endif 80 - msr ttbr0_el2, x0 81 97 82 - mrs x0, tcr_el1 83 - mov_q x1, TCR_EL2_MASK 84 - and x0, x0, x1 85 - mov x1, #TCR_EL2_RES1 86 - orr x0, x0, x1 98 + ldr x1, [x0, #NVHE_INIT_TPIDR_EL2] 99 + msr tpidr_el2, x1 87 100 88 - /* 89 - * The ID map may be configured to use an extended virtual address 90 - * range. This is only the case if system RAM is out of range for the 91 - * currently configured page size and VA_BITS, in which case we will 92 - * also need the extended virtual range for the HYP ID map, or we won't 93 - * be able to enable the EL2 MMU. 94 - * 95 - * However, at EL2, there is only one TTBR register, and we can't switch 96 - * between translation tables *and* update TCR_EL2.T0SZ at the same 97 - * time. Bottom line: we need to use the extended range with *both* our 98 - * translation tables. 99 - * 100 - * So use the same T0SZ value we use for the ID map. 101 - */ 102 - ldr_l x1, idmap_t0sz 103 - bfi x0, x1, TCR_T0SZ_OFFSET, TCR_TxSZ_WIDTH 101 + ldr x1, [x0, #NVHE_INIT_STACK_HYP_VA] 102 + mov sp, x1 103 + 104 + ldr x1, [x0, #NVHE_INIT_MAIR_EL2] 105 + msr mair_el2, x1 106 + 107 + ldr x1, [x0, #NVHE_INIT_PGD_PA] 108 + phys_to_ttbr x2, x1 109 + alternative_if ARM64_HAS_CNP 110 + orr x2, x2, #TTBR_CNP_BIT 111 + alternative_else_nop_endif 112 + msr ttbr0_el2, x2 104 113 105 114 /* 106 115 * Set the PS bits in TCR_EL2. 107 116 */ 108 - tcr_compute_pa_size x0, #TCR_EL2_PS_SHIFT, x1, x2 117 + ldr x1, [x0, #NVHE_INIT_TCR_EL2] 118 + tcr_compute_pa_size x1, #TCR_EL2_PS_SHIFT, x2, x3 119 + msr tcr_el2, x1 109 120 110 - msr tcr_el2, x0 111 - 112 - mrs x0, mair_el1 113 - msr mair_el2, x0 114 121 isb 115 122 116 123 /* Invalidate the stale TLBs from Bootloader */ ··· 137 134 msr sctlr_el2, x0 138 135 isb 139 136 140 - /* Set the stack and new vectors */ 141 - mov sp, x3 142 - msr vbar_el2, x4 137 + /* Set the host vector */ 138 + ldr x0, =__kvm_hyp_host_vector 139 + kimg_hyp_va x0, x1 140 + msr vbar_el2, x0 143 141 144 - /* Hello, World! */ 145 - mov x0, #SMCCC_RET_SUCCESS 146 - eret 147 - SYM_CODE_END(__kvm_hyp_init) 142 + ret 143 + SYM_CODE_END(___kvm_hyp_init) 144 + 145 + /* 146 + * PSCI CPU_ON entry point 147 + * 148 + * x0: struct kvm_nvhe_init_params PA 149 + */ 150 + SYM_CODE_START(kvm_hyp_cpu_entry) 151 + mov x1, #1 // is_cpu_on = true 152 + b __kvm_hyp_init_cpu 153 + SYM_CODE_END(kvm_hyp_cpu_entry) 154 + 155 + /* 156 + * PSCI CPU_SUSPEND / SYSTEM_SUSPEND entry point 157 + * 158 + * x0: struct kvm_nvhe_init_params PA 159 + */ 160 + SYM_CODE_START(kvm_hyp_cpu_resume) 161 + mov x1, #0 // is_cpu_on = false 162 + b __kvm_hyp_init_cpu 163 + SYM_CODE_END(kvm_hyp_cpu_resume) 164 + 165 + /* 166 + * Common code for CPU entry points. Initializes EL2 state and 167 + * installs the hypervisor before handing over to a C handler. 168 + * 169 + * x0: struct kvm_nvhe_init_params PA 170 + * x1: bool is_cpu_on 171 + */ 172 + SYM_CODE_START_LOCAL(__kvm_hyp_init_cpu) 173 + mov x28, x0 // Stash arguments 174 + mov x29, x1 175 + 176 + /* Check that the core was booted in EL2. */ 177 + mrs x0, CurrentEL 178 + cmp x0, #CurrentEL_EL2 179 + b.eq 2f 180 + 181 + /* The core booted in EL1. KVM cannot be initialized on it. */ 182 + 1: wfe 183 + wfi 184 + b 1b 185 + 186 + 2: msr SPsel, #1 // We want to use SP_EL{1,2} 187 + 188 + /* Initialize EL2 CPU state to sane values. */ 189 + init_el2_state nvhe // Clobbers x0..x2 190 + 191 + /* Enable MMU, set vectors and stack. */ 192 + mov x0, x28 193 + bl ___kvm_hyp_init // Clobbers x0..x3 194 + 195 + /* Leave idmap. */ 196 + mov x0, x29 197 + ldr x1, =kvm_host_psci_cpu_entry 198 + kimg_hyp_va x1, x2 199 + br x1 200 + SYM_CODE_END(__kvm_hyp_init_cpu) 148 201 149 202 SYM_CODE_START(__kvm_handle_stub_hvc) 150 203 cmp x0, #HVC_SOFT_RESTART ··· 234 175 pre_disable_mmu_workaround 235 176 msr sctlr_el2, x5 236 177 isb 178 + 179 + alternative_if ARM64_KVM_PROTECTED_MODE 180 + mov_q x5, HCR_HOST_NVHE_FLAGS 181 + msr hcr_el2, x5 182 + alternative_else_nop_endif 237 183 238 184 /* Install stub vectors */ 239 185 adr_l x5, __hyp_stub_vectors
+160 -83
arch/arm64/kvm/hyp/nvhe/hyp-main.c
··· 12 12 #include <asm/kvm_hyp.h> 13 13 #include <asm/kvm_mmu.h> 14 14 15 - #include <kvm/arm_hypercalls.h> 15 + #include <nvhe/trap_handler.h> 16 16 17 - static void handle_host_hcall(unsigned long func_id, 18 - struct kvm_cpu_context *host_ctxt) 17 + DEFINE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params); 18 + 19 + void __kvm_hyp_host_forward_smc(struct kvm_cpu_context *host_ctxt); 20 + 21 + static void handle___kvm_vcpu_run(struct kvm_cpu_context *host_ctxt) 19 22 { 20 - unsigned long ret = 0; 23 + DECLARE_REG(struct kvm_vcpu *, vcpu, host_ctxt, 1); 21 24 22 - switch (func_id) { 23 - case KVM_HOST_SMCCC_FUNC(__kvm_vcpu_run): { 24 - unsigned long r1 = host_ctxt->regs.regs[1]; 25 - struct kvm_vcpu *vcpu = (struct kvm_vcpu *)r1; 25 + cpu_reg(host_ctxt, 1) = __kvm_vcpu_run(kern_hyp_va(vcpu)); 26 + } 26 27 27 - ret = __kvm_vcpu_run(kern_hyp_va(vcpu)); 28 - break; 29 - } 30 - case KVM_HOST_SMCCC_FUNC(__kvm_flush_vm_context): 31 - __kvm_flush_vm_context(); 32 - break; 33 - case KVM_HOST_SMCCC_FUNC(__kvm_tlb_flush_vmid_ipa): { 34 - unsigned long r1 = host_ctxt->regs.regs[1]; 35 - struct kvm_s2_mmu *mmu = (struct kvm_s2_mmu *)r1; 36 - phys_addr_t ipa = host_ctxt->regs.regs[2]; 37 - int level = host_ctxt->regs.regs[3]; 28 + static void handle___kvm_flush_vm_context(struct kvm_cpu_context *host_ctxt) 29 + { 30 + __kvm_flush_vm_context(); 31 + } 38 32 39 - __kvm_tlb_flush_vmid_ipa(kern_hyp_va(mmu), ipa, level); 40 - break; 41 - } 42 - case KVM_HOST_SMCCC_FUNC(__kvm_tlb_flush_vmid): { 43 - unsigned long r1 = host_ctxt->regs.regs[1]; 44 - struct kvm_s2_mmu *mmu = (struct kvm_s2_mmu *)r1; 33 + static void handle___kvm_tlb_flush_vmid_ipa(struct kvm_cpu_context *host_ctxt) 34 + { 35 + DECLARE_REG(struct kvm_s2_mmu *, mmu, host_ctxt, 1); 36 + DECLARE_REG(phys_addr_t, ipa, host_ctxt, 2); 37 + DECLARE_REG(int, level, host_ctxt, 3); 45 38 46 - __kvm_tlb_flush_vmid(kern_hyp_va(mmu)); 47 - break; 48 - } 49 - case KVM_HOST_SMCCC_FUNC(__kvm_tlb_flush_local_vmid): { 50 - unsigned long r1 = host_ctxt->regs.regs[1]; 51 - struct kvm_s2_mmu *mmu = (struct kvm_s2_mmu *)r1; 39 + __kvm_tlb_flush_vmid_ipa(kern_hyp_va(mmu), ipa, level); 40 + } 52 41 53 - __kvm_tlb_flush_local_vmid(kern_hyp_va(mmu)); 54 - break; 55 - } 56 - case KVM_HOST_SMCCC_FUNC(__kvm_timer_set_cntvoff): { 57 - u64 cntvoff = host_ctxt->regs.regs[1]; 42 + static void handle___kvm_tlb_flush_vmid(struct kvm_cpu_context *host_ctxt) 43 + { 44 + DECLARE_REG(struct kvm_s2_mmu *, mmu, host_ctxt, 1); 58 45 59 - __kvm_timer_set_cntvoff(cntvoff); 60 - break; 61 - } 62 - case KVM_HOST_SMCCC_FUNC(__kvm_enable_ssbs): 63 - __kvm_enable_ssbs(); 64 - break; 65 - case KVM_HOST_SMCCC_FUNC(__vgic_v3_get_ich_vtr_el2): 66 - ret = __vgic_v3_get_ich_vtr_el2(); 67 - break; 68 - case KVM_HOST_SMCCC_FUNC(__vgic_v3_read_vmcr): 69 - ret = __vgic_v3_read_vmcr(); 70 - break; 71 - case KVM_HOST_SMCCC_FUNC(__vgic_v3_write_vmcr): { 72 - u32 vmcr = host_ctxt->regs.regs[1]; 46 + __kvm_tlb_flush_vmid(kern_hyp_va(mmu)); 47 + } 73 48 74 - __vgic_v3_write_vmcr(vmcr); 75 - break; 76 - } 77 - case KVM_HOST_SMCCC_FUNC(__vgic_v3_init_lrs): 78 - __vgic_v3_init_lrs(); 79 - break; 80 - case KVM_HOST_SMCCC_FUNC(__kvm_get_mdcr_el2): 81 - ret = __kvm_get_mdcr_el2(); 82 - break; 83 - case KVM_HOST_SMCCC_FUNC(__vgic_v3_save_aprs): { 84 - unsigned long r1 = host_ctxt->regs.regs[1]; 85 - struct vgic_v3_cpu_if *cpu_if = (struct vgic_v3_cpu_if *)r1; 49 + static void handle___kvm_tlb_flush_local_vmid(struct kvm_cpu_context *host_ctxt) 50 + { 51 + DECLARE_REG(struct kvm_s2_mmu *, mmu, host_ctxt, 1); 86 52 87 - __vgic_v3_save_aprs(kern_hyp_va(cpu_if)); 88 - break; 89 - } 90 - case KVM_HOST_SMCCC_FUNC(__vgic_v3_restore_aprs): { 91 - unsigned long r1 = host_ctxt->regs.regs[1]; 92 - struct vgic_v3_cpu_if *cpu_if = (struct vgic_v3_cpu_if *)r1; 53 + __kvm_tlb_flush_local_vmid(kern_hyp_va(mmu)); 54 + } 93 55 94 - __vgic_v3_restore_aprs(kern_hyp_va(cpu_if)); 95 - break; 96 - } 97 - default: 98 - /* Invalid host HVC. */ 99 - host_ctxt->regs.regs[0] = SMCCC_RET_NOT_SUPPORTED; 100 - return; 101 - } 56 + static void handle___kvm_timer_set_cntvoff(struct kvm_cpu_context *host_ctxt) 57 + { 58 + __kvm_timer_set_cntvoff(cpu_reg(host_ctxt, 1)); 59 + } 102 60 103 - host_ctxt->regs.regs[0] = SMCCC_RET_SUCCESS; 104 - host_ctxt->regs.regs[1] = ret; 61 + static void handle___kvm_enable_ssbs(struct kvm_cpu_context *host_ctxt) 62 + { 63 + u64 tmp; 64 + 65 + tmp = read_sysreg_el2(SYS_SCTLR); 66 + tmp |= SCTLR_ELx_DSSBS; 67 + write_sysreg_el2(tmp, SYS_SCTLR); 68 + } 69 + 70 + static void handle___vgic_v3_get_ich_vtr_el2(struct kvm_cpu_context *host_ctxt) 71 + { 72 + cpu_reg(host_ctxt, 1) = __vgic_v3_get_ich_vtr_el2(); 73 + } 74 + 75 + static void handle___vgic_v3_read_vmcr(struct kvm_cpu_context *host_ctxt) 76 + { 77 + cpu_reg(host_ctxt, 1) = __vgic_v3_read_vmcr(); 78 + } 79 + 80 + static void handle___vgic_v3_write_vmcr(struct kvm_cpu_context *host_ctxt) 81 + { 82 + __vgic_v3_write_vmcr(cpu_reg(host_ctxt, 1)); 83 + } 84 + 85 + static void handle___vgic_v3_init_lrs(struct kvm_cpu_context *host_ctxt) 86 + { 87 + __vgic_v3_init_lrs(); 88 + } 89 + 90 + static void handle___kvm_get_mdcr_el2(struct kvm_cpu_context *host_ctxt) 91 + { 92 + cpu_reg(host_ctxt, 1) = __kvm_get_mdcr_el2(); 93 + } 94 + 95 + static void handle___vgic_v3_save_aprs(struct kvm_cpu_context *host_ctxt) 96 + { 97 + DECLARE_REG(struct vgic_v3_cpu_if *, cpu_if, host_ctxt, 1); 98 + 99 + __vgic_v3_save_aprs(kern_hyp_va(cpu_if)); 100 + } 101 + 102 + static void handle___vgic_v3_restore_aprs(struct kvm_cpu_context *host_ctxt) 103 + { 104 + DECLARE_REG(struct vgic_v3_cpu_if *, cpu_if, host_ctxt, 1); 105 + 106 + __vgic_v3_restore_aprs(kern_hyp_va(cpu_if)); 107 + } 108 + 109 + typedef void (*hcall_t)(struct kvm_cpu_context *); 110 + 111 + #define HANDLE_FUNC(x) [__KVM_HOST_SMCCC_FUNC_##x] = kimg_fn_ptr(handle_##x) 112 + 113 + static const hcall_t *host_hcall[] = { 114 + HANDLE_FUNC(__kvm_vcpu_run), 115 + HANDLE_FUNC(__kvm_flush_vm_context), 116 + HANDLE_FUNC(__kvm_tlb_flush_vmid_ipa), 117 + HANDLE_FUNC(__kvm_tlb_flush_vmid), 118 + HANDLE_FUNC(__kvm_tlb_flush_local_vmid), 119 + HANDLE_FUNC(__kvm_timer_set_cntvoff), 120 + HANDLE_FUNC(__kvm_enable_ssbs), 121 + HANDLE_FUNC(__vgic_v3_get_ich_vtr_el2), 122 + HANDLE_FUNC(__vgic_v3_read_vmcr), 123 + HANDLE_FUNC(__vgic_v3_write_vmcr), 124 + HANDLE_FUNC(__vgic_v3_init_lrs), 125 + HANDLE_FUNC(__kvm_get_mdcr_el2), 126 + HANDLE_FUNC(__vgic_v3_save_aprs), 127 + HANDLE_FUNC(__vgic_v3_restore_aprs), 128 + }; 129 + 130 + static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) 131 + { 132 + DECLARE_REG(unsigned long, id, host_ctxt, 0); 133 + const hcall_t *kfn; 134 + hcall_t hfn; 135 + 136 + id -= KVM_HOST_SMCCC_ID(0); 137 + 138 + if (unlikely(id >= ARRAY_SIZE(host_hcall))) 139 + goto inval; 140 + 141 + kfn = host_hcall[id]; 142 + if (unlikely(!kfn)) 143 + goto inval; 144 + 145 + cpu_reg(host_ctxt, 0) = SMCCC_RET_SUCCESS; 146 + 147 + hfn = kimg_fn_hyp_va(kfn); 148 + hfn(host_ctxt); 149 + 150 + return; 151 + inval: 152 + cpu_reg(host_ctxt, 0) = SMCCC_RET_NOT_SUPPORTED; 153 + } 154 + 155 + static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt) 156 + { 157 + __kvm_hyp_host_forward_smc(host_ctxt); 158 + } 159 + 160 + static void skip_host_instruction(void) 161 + { 162 + write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR); 163 + } 164 + 165 + static void handle_host_smc(struct kvm_cpu_context *host_ctxt) 166 + { 167 + bool handled; 168 + 169 + handled = kvm_host_psci_handler(host_ctxt); 170 + if (!handled) 171 + default_host_smc_handler(host_ctxt); 172 + 173 + /* 174 + * Unlike HVC, the return address of an SMC is the instruction's PC. 175 + * Move the return address past the instruction. 176 + */ 177 + skip_host_instruction(); 105 178 } 106 179 107 180 void handle_trap(struct kvm_cpu_context *host_ctxt) 108 181 { 109 182 u64 esr = read_sysreg_el2(SYS_ESR); 110 - unsigned long func_id; 111 183 112 - if (ESR_ELx_EC(esr) != ESR_ELx_EC_HVC64) 184 + switch (ESR_ELx_EC(esr)) { 185 + case ESR_ELx_EC_HVC64: 186 + handle_host_hcall(host_ctxt); 187 + break; 188 + case ESR_ELx_EC_SMC64: 189 + handle_host_smc(host_ctxt); 190 + break; 191 + default: 113 192 hyp_panic(); 114 - 115 - func_id = host_ctxt->regs.regs[0]; 116 - handle_host_hcall(func_id, host_ctxt); 193 + } 117 194 }
+40
arch/arm64/kvm/hyp/nvhe/hyp-smp.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2020 - Google LLC 4 + * Author: David Brazdil <dbrazdil@google.com> 5 + */ 6 + 7 + #include <asm/kvm_asm.h> 8 + #include <asm/kvm_hyp.h> 9 + #include <asm/kvm_mmu.h> 10 + 11 + /* 12 + * nVHE copy of data structures tracking available CPU cores. 13 + * Only entries for CPUs that were online at KVM init are populated. 14 + * Other CPUs should not be allowed to boot because their features were 15 + * not checked against the finalized system capabilities. 16 + */ 17 + u64 __ro_after_init __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID }; 18 + 19 + u64 cpu_logical_map(unsigned int cpu) 20 + { 21 + if (cpu >= ARRAY_SIZE(__cpu_logical_map)) 22 + hyp_panic(); 23 + 24 + return __cpu_logical_map[cpu]; 25 + } 26 + 27 + unsigned long __hyp_per_cpu_offset(unsigned int cpu) 28 + { 29 + unsigned long *cpu_base_array; 30 + unsigned long this_cpu_base; 31 + unsigned long elf_base; 32 + 33 + if (cpu >= ARRAY_SIZE(kvm_arm_hyp_percpu_base)) 34 + hyp_panic(); 35 + 36 + cpu_base_array = (unsigned long *)hyp_symbol_addr(kvm_arm_hyp_percpu_base); 37 + this_cpu_base = kern_hyp_va(cpu_base_array[cpu]); 38 + elf_base = (unsigned long)hyp_symbol_addr(__per_cpu_start); 39 + return this_cpu_base - elf_base; 40 + }
+1
arch/arm64/kvm/hyp/nvhe/hyp.lds.S
··· 16 16 HYP_SECTION_NAME(.data..percpu) : { 17 17 PERCPU_INPUT(L1_CACHE_BYTES) 18 18 } 19 + HYP_SECTION(.data..ro_after_init) 19 20 }
+324
arch/arm64/kvm/hyp/nvhe/psci-relay.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2020 - Google LLC 4 + * Author: David Brazdil <dbrazdil@google.com> 5 + */ 6 + 7 + #include <asm/kvm_asm.h> 8 + #include <asm/kvm_hyp.h> 9 + #include <asm/kvm_mmu.h> 10 + #include <kvm/arm_hypercalls.h> 11 + #include <linux/arm-smccc.h> 12 + #include <linux/kvm_host.h> 13 + #include <linux/psci.h> 14 + #include <kvm/arm_psci.h> 15 + #include <uapi/linux/psci.h> 16 + 17 + #include <nvhe/trap_handler.h> 18 + 19 + void kvm_hyp_cpu_entry(unsigned long r0); 20 + void kvm_hyp_cpu_resume(unsigned long r0); 21 + 22 + void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt); 23 + 24 + /* Config options set by the host. */ 25 + __ro_after_init u32 kvm_host_psci_version; 26 + __ro_after_init struct psci_0_1_function_ids kvm_host_psci_0_1_function_ids; 27 + __ro_after_init s64 hyp_physvirt_offset; 28 + 29 + #define __hyp_pa(x) ((phys_addr_t)((x)) + hyp_physvirt_offset) 30 + 31 + #define INVALID_CPU_ID UINT_MAX 32 + 33 + struct psci_boot_args { 34 + atomic_t lock; 35 + unsigned long pc; 36 + unsigned long r0; 37 + }; 38 + 39 + #define PSCI_BOOT_ARGS_UNLOCKED 0 40 + #define PSCI_BOOT_ARGS_LOCKED 1 41 + 42 + #define PSCI_BOOT_ARGS_INIT \ 43 + ((struct psci_boot_args){ \ 44 + .lock = ATOMIC_INIT(PSCI_BOOT_ARGS_UNLOCKED), \ 45 + }) 46 + 47 + static DEFINE_PER_CPU(struct psci_boot_args, cpu_on_args) = PSCI_BOOT_ARGS_INIT; 48 + static DEFINE_PER_CPU(struct psci_boot_args, suspend_args) = PSCI_BOOT_ARGS_INIT; 49 + 50 + static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt) 51 + { 52 + DECLARE_REG(u64, func_id, host_ctxt, 0); 53 + 54 + return func_id; 55 + } 56 + 57 + static bool is_psci_0_1_call(u64 func_id) 58 + { 59 + return (func_id == kvm_host_psci_0_1_function_ids.cpu_suspend) || 60 + (func_id == kvm_host_psci_0_1_function_ids.cpu_on) || 61 + (func_id == kvm_host_psci_0_1_function_ids.cpu_off) || 62 + (func_id == kvm_host_psci_0_1_function_ids.migrate); 63 + } 64 + 65 + static bool is_psci_0_2_call(u64 func_id) 66 + { 67 + /* SMCCC reserves IDs 0x00-1F with the given 32/64-bit base for PSCI. */ 68 + return (PSCI_0_2_FN(0) <= func_id && func_id <= PSCI_0_2_FN(31)) || 69 + (PSCI_0_2_FN64(0) <= func_id && func_id <= PSCI_0_2_FN64(31)); 70 + } 71 + 72 + static bool is_psci_call(u64 func_id) 73 + { 74 + switch (kvm_host_psci_version) { 75 + case PSCI_VERSION(0, 1): 76 + return is_psci_0_1_call(func_id); 77 + default: 78 + return is_psci_0_2_call(func_id); 79 + } 80 + } 81 + 82 + static unsigned long psci_call(unsigned long fn, unsigned long arg0, 83 + unsigned long arg1, unsigned long arg2) 84 + { 85 + struct arm_smccc_res res; 86 + 87 + arm_smccc_1_1_smc(fn, arg0, arg1, arg2, &res); 88 + return res.a0; 89 + } 90 + 91 + static unsigned long psci_forward(struct kvm_cpu_context *host_ctxt) 92 + { 93 + return psci_call(cpu_reg(host_ctxt, 0), cpu_reg(host_ctxt, 1), 94 + cpu_reg(host_ctxt, 2), cpu_reg(host_ctxt, 3)); 95 + } 96 + 97 + static __noreturn unsigned long psci_forward_noreturn(struct kvm_cpu_context *host_ctxt) 98 + { 99 + psci_forward(host_ctxt); 100 + hyp_panic(); /* unreachable */ 101 + } 102 + 103 + static unsigned int find_cpu_id(u64 mpidr) 104 + { 105 + unsigned int i; 106 + 107 + /* Reject invalid MPIDRs */ 108 + if (mpidr & ~MPIDR_HWID_BITMASK) 109 + return INVALID_CPU_ID; 110 + 111 + for (i = 0; i < NR_CPUS; i++) { 112 + if (cpu_logical_map(i) == mpidr) 113 + return i; 114 + } 115 + 116 + return INVALID_CPU_ID; 117 + } 118 + 119 + static __always_inline bool try_acquire_boot_args(struct psci_boot_args *args) 120 + { 121 + return atomic_cmpxchg_acquire(&args->lock, 122 + PSCI_BOOT_ARGS_UNLOCKED, 123 + PSCI_BOOT_ARGS_LOCKED) == 124 + PSCI_BOOT_ARGS_UNLOCKED; 125 + } 126 + 127 + static __always_inline void release_boot_args(struct psci_boot_args *args) 128 + { 129 + atomic_set_release(&args->lock, PSCI_BOOT_ARGS_UNLOCKED); 130 + } 131 + 132 + static int psci_cpu_on(u64 func_id, struct kvm_cpu_context *host_ctxt) 133 + { 134 + DECLARE_REG(u64, mpidr, host_ctxt, 1); 135 + DECLARE_REG(unsigned long, pc, host_ctxt, 2); 136 + DECLARE_REG(unsigned long, r0, host_ctxt, 3); 137 + 138 + unsigned int cpu_id; 139 + struct psci_boot_args *boot_args; 140 + struct kvm_nvhe_init_params *init_params; 141 + int ret; 142 + 143 + /* 144 + * Find the logical CPU ID for the given MPIDR. The search set is 145 + * the set of CPUs that were online at the point of KVM initialization. 146 + * Booting other CPUs is rejected because their cpufeatures were not 147 + * checked against the finalized capabilities. This could be relaxed 148 + * by doing the feature checks in hyp. 149 + */ 150 + cpu_id = find_cpu_id(mpidr); 151 + if (cpu_id == INVALID_CPU_ID) 152 + return PSCI_RET_INVALID_PARAMS; 153 + 154 + boot_args = per_cpu_ptr(hyp_symbol_addr(cpu_on_args), cpu_id); 155 + init_params = per_cpu_ptr(hyp_symbol_addr(kvm_init_params), cpu_id); 156 + 157 + /* Check if the target CPU is already being booted. */ 158 + if (!try_acquire_boot_args(boot_args)) 159 + return PSCI_RET_ALREADY_ON; 160 + 161 + boot_args->pc = pc; 162 + boot_args->r0 = r0; 163 + wmb(); 164 + 165 + ret = psci_call(func_id, mpidr, 166 + __hyp_pa(hyp_symbol_addr(kvm_hyp_cpu_entry)), 167 + __hyp_pa(init_params)); 168 + 169 + /* If successful, the lock will be released by the target CPU. */ 170 + if (ret != PSCI_RET_SUCCESS) 171 + release_boot_args(boot_args); 172 + 173 + return ret; 174 + } 175 + 176 + static int psci_cpu_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt) 177 + { 178 + DECLARE_REG(u64, power_state, host_ctxt, 1); 179 + DECLARE_REG(unsigned long, pc, host_ctxt, 2); 180 + DECLARE_REG(unsigned long, r0, host_ctxt, 3); 181 + 182 + struct psci_boot_args *boot_args; 183 + struct kvm_nvhe_init_params *init_params; 184 + 185 + boot_args = this_cpu_ptr(hyp_symbol_addr(suspend_args)); 186 + init_params = this_cpu_ptr(hyp_symbol_addr(kvm_init_params)); 187 + 188 + /* 189 + * No need to acquire a lock before writing to boot_args because a core 190 + * can only suspend itself. Racy CPU_ON calls use a separate struct. 191 + */ 192 + boot_args->pc = pc; 193 + boot_args->r0 = r0; 194 + 195 + /* 196 + * Will either return if shallow sleep state, or wake up into the entry 197 + * point if it is a deep sleep state. 198 + */ 199 + return psci_call(func_id, power_state, 200 + __hyp_pa(hyp_symbol_addr(kvm_hyp_cpu_resume)), 201 + __hyp_pa(init_params)); 202 + } 203 + 204 + static int psci_system_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt) 205 + { 206 + DECLARE_REG(unsigned long, pc, host_ctxt, 1); 207 + DECLARE_REG(unsigned long, r0, host_ctxt, 2); 208 + 209 + struct psci_boot_args *boot_args; 210 + struct kvm_nvhe_init_params *init_params; 211 + 212 + boot_args = this_cpu_ptr(hyp_symbol_addr(suspend_args)); 213 + init_params = this_cpu_ptr(hyp_symbol_addr(kvm_init_params)); 214 + 215 + /* 216 + * No need to acquire a lock before writing to boot_args because a core 217 + * can only suspend itself. Racy CPU_ON calls use a separate struct. 218 + */ 219 + boot_args->pc = pc; 220 + boot_args->r0 = r0; 221 + 222 + /* Will only return on error. */ 223 + return psci_call(func_id, 224 + __hyp_pa(hyp_symbol_addr(kvm_hyp_cpu_resume)), 225 + __hyp_pa(init_params), 0); 226 + } 227 + 228 + asmlinkage void __noreturn kvm_host_psci_cpu_entry(bool is_cpu_on) 229 + { 230 + struct psci_boot_args *boot_args; 231 + struct kvm_cpu_context *host_ctxt; 232 + 233 + host_ctxt = &this_cpu_ptr(hyp_symbol_addr(kvm_host_data))->host_ctxt; 234 + 235 + if (is_cpu_on) 236 + boot_args = this_cpu_ptr(hyp_symbol_addr(cpu_on_args)); 237 + else 238 + boot_args = this_cpu_ptr(hyp_symbol_addr(suspend_args)); 239 + 240 + cpu_reg(host_ctxt, 0) = boot_args->r0; 241 + write_sysreg_el2(boot_args->pc, SYS_ELR); 242 + 243 + if (is_cpu_on) 244 + release_boot_args(boot_args); 245 + 246 + __host_enter(host_ctxt); 247 + } 248 + 249 + static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) 250 + { 251 + if ((func_id == kvm_host_psci_0_1_function_ids.cpu_off) || 252 + (func_id == kvm_host_psci_0_1_function_ids.migrate)) 253 + return psci_forward(host_ctxt); 254 + else if (func_id == kvm_host_psci_0_1_function_ids.cpu_on) 255 + return psci_cpu_on(func_id, host_ctxt); 256 + else if (func_id == kvm_host_psci_0_1_function_ids.cpu_suspend) 257 + return psci_cpu_suspend(func_id, host_ctxt); 258 + else 259 + return PSCI_RET_NOT_SUPPORTED; 260 + } 261 + 262 + static unsigned long psci_0_2_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) 263 + { 264 + switch (func_id) { 265 + case PSCI_0_2_FN_PSCI_VERSION: 266 + case PSCI_0_2_FN_CPU_OFF: 267 + case PSCI_0_2_FN64_AFFINITY_INFO: 268 + case PSCI_0_2_FN64_MIGRATE: 269 + case PSCI_0_2_FN_MIGRATE_INFO_TYPE: 270 + case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU: 271 + return psci_forward(host_ctxt); 272 + case PSCI_0_2_FN_SYSTEM_OFF: 273 + case PSCI_0_2_FN_SYSTEM_RESET: 274 + psci_forward_noreturn(host_ctxt); 275 + unreachable(); 276 + case PSCI_0_2_FN64_CPU_SUSPEND: 277 + return psci_cpu_suspend(func_id, host_ctxt); 278 + case PSCI_0_2_FN64_CPU_ON: 279 + return psci_cpu_on(func_id, host_ctxt); 280 + default: 281 + return PSCI_RET_NOT_SUPPORTED; 282 + } 283 + } 284 + 285 + static unsigned long psci_1_0_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) 286 + { 287 + switch (func_id) { 288 + case PSCI_1_0_FN_PSCI_FEATURES: 289 + case PSCI_1_0_FN_SET_SUSPEND_MODE: 290 + case PSCI_1_1_FN64_SYSTEM_RESET2: 291 + return psci_forward(host_ctxt); 292 + case PSCI_1_0_FN64_SYSTEM_SUSPEND: 293 + return psci_system_suspend(func_id, host_ctxt); 294 + default: 295 + return psci_0_2_handler(func_id, host_ctxt); 296 + } 297 + } 298 + 299 + bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt) 300 + { 301 + u64 func_id = get_psci_func_id(host_ctxt); 302 + unsigned long ret; 303 + 304 + if (!is_psci_call(func_id)) 305 + return false; 306 + 307 + switch (kvm_host_psci_version) { 308 + case PSCI_VERSION(0, 1): 309 + ret = psci_0_1_handler(func_id, host_ctxt); 310 + break; 311 + case PSCI_VERSION(0, 2): 312 + ret = psci_0_2_handler(func_id, host_ctxt); 313 + break; 314 + default: 315 + ret = psci_1_0_handler(func_id, host_ctxt); 316 + break; 317 + } 318 + 319 + cpu_reg(host_ctxt, 0) = ret; 320 + cpu_reg(host_ctxt, 1) = 0; 321 + cpu_reg(host_ctxt, 2) = 0; 322 + cpu_reg(host_ctxt, 3) = 0; 323 + return true; 324 + }
+7 -1
arch/arm64/kvm/hyp/nvhe/switch.c
··· 4 4 * Author: Marc Zyngier <marc.zyngier@arm.com> 5 5 */ 6 6 7 + #include <hyp/adjust_pc.h> 7 8 #include <hyp/switch.h> 8 9 #include <hyp/sysreg-sr.h> 9 10 ··· 97 96 mdcr_el2 |= MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT; 98 97 99 98 write_sysreg(mdcr_el2, mdcr_el2); 100 - write_sysreg(HCR_HOST_NVHE_FLAGS, hcr_el2); 99 + if (is_protected_kvm_enabled()) 100 + write_sysreg(HCR_HOST_NVHE_PROTECTED_FLAGS, hcr_el2); 101 + else 102 + write_sysreg(HCR_HOST_NVHE_FLAGS, hcr_el2); 101 103 write_sysreg(CPTR_EL2_DEFAULT, cptr_el2); 102 104 write_sysreg(__kvm_hyp_host_vector, vbar_el2); 103 105 } ··· 192 188 pmu_switch_needed = __pmu_switch_to_guest(host_ctxt); 193 189 194 190 __sysreg_save_state_nvhe(host_ctxt); 191 + 192 + __adjust_pc(vcpu); 195 193 196 194 /* 197 195 * We must restore the 32-bit state before the sysregs, thanks
-11
arch/arm64/kvm/hyp/nvhe/sysreg-sr.c
··· 33 33 __sysreg_restore_user_state(ctxt); 34 34 __sysreg_restore_el2_return_state(ctxt); 35 35 } 36 - 37 - void __kvm_enable_ssbs(void) 38 - { 39 - u64 tmp; 40 - 41 - asm volatile( 42 - "mrs %0, sctlr_el2\n" 43 - "orr %0, %0, %1\n" 44 - "msr sctlr_el2, %0" 45 - : "=&r" (tmp) : "L" (SCTLR_ELx_DSSBS)); 46 - }
-32
arch/arm64/kvm/hyp/smccc_wa.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2015-2018 - ARM Ltd 4 - * Author: Marc Zyngier <marc.zyngier@arm.com> 5 - */ 6 - 7 - #include <linux/arm-smccc.h> 8 - #include <linux/linkage.h> 9 - 10 - #include <asm/kvm_asm.h> 11 - #include <asm/kvm_mmu.h> 12 - 13 - /* 14 - * This is not executed directly and is instead copied into the vectors 15 - * by install_bp_hardening_cb(). 16 - */ 17 - .data 18 - .pushsection .rodata 19 - .global __smccc_workaround_1_smc 20 - SYM_DATA_START(__smccc_workaround_1_smc) 21 - esb 22 - sub sp, sp, #(8 * 4) 23 - stp x2, x3, [sp, #(8 * 0)] 24 - stp x0, x1, [sp, #(8 * 2)] 25 - mov w0, #ARM_SMCCC_ARCH_WORKAROUND_1 26 - smc #0 27 - ldp x2, x3, [sp, #(8 * 0)] 28 - ldp x0, x1, [sp, #(8 * 2)] 29 - add sp, sp, #(8 * 4) 30 - 1: .org __smccc_workaround_1_smc + __SMCCC_WORKAROUND_1_SMC_SZ 31 - .org 1b 32 - SYM_DATA_END(__smccc_workaround_1_smc)
+2
arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c
··· 4 4 * Author: Marc Zyngier <marc.zyngier@arm.com> 5 5 */ 6 6 7 + #include <hyp/adjust_pc.h> 8 + 7 9 #include <linux/compiler.h> 8 10 #include <linux/irqchip/arm-gic.h> 9 11 #include <linux/kvm_host.h>
+2
arch/arm64/kvm/hyp/vgic-v3-sr.c
··· 4 4 * Author: Marc Zyngier <marc.zyngier@arm.com> 5 5 */ 6 6 7 + #include <hyp/adjust_pc.h> 8 + 7 9 #include <linux/compiler.h> 8 10 #include <linux/irqchip/arm-gic-v3.h> 9 11 #include <linux/kvm_host.h>
+1 -1
arch/arm64/kvm/hyp/vhe/Makefile
··· 8 8 9 9 obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o 10 10 obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ 11 - ../fpsimd.o ../hyp-entry.o 11 + ../fpsimd.o ../hyp-entry.o ../exception.o
+3
arch/arm64/kvm/hyp/vhe/switch.c
··· 4 4 * Author: Marc Zyngier <marc.zyngier@arm.com> 5 5 */ 6 6 7 + #include <hyp/adjust_pc.h> 7 8 #include <hyp/switch.h> 8 9 9 10 #include <linux/arm-smccc.h> ··· 133 132 */ 134 133 __load_guest_stage2(vcpu->arch.hw_mmu); 135 134 __activate_traps(vcpu); 135 + 136 + __adjust_pc(vcpu); 136 137 137 138 sysreg_restore_guest_state_vhe(guest_ctxt); 138 139 __debug_switch_to_guest(vcpu);
+56 -111
arch/arm64/kvm/inject_fault.c
··· 14 14 #include <asm/kvm_emulate.h> 15 15 #include <asm/esr.h> 16 16 17 - #define CURRENT_EL_SP_EL0_VECTOR 0x0 18 - #define CURRENT_EL_SP_ELx_VECTOR 0x200 19 - #define LOWER_EL_AArch64_VECTOR 0x400 20 - #define LOWER_EL_AArch32_VECTOR 0x600 21 - 22 - enum exception_type { 23 - except_type_sync = 0, 24 - except_type_irq = 0x80, 25 - except_type_fiq = 0x100, 26 - except_type_serror = 0x180, 27 - }; 28 - 29 - /* 30 - * This performs the exception entry at a given EL (@target_mode), stashing PC 31 - * and PSTATE into ELR and SPSR respectively, and compute the new PC/PSTATE. 32 - * The EL passed to this function *must* be a non-secure, privileged mode with 33 - * bit 0 being set (PSTATE.SP == 1). 34 - * 35 - * When an exception is taken, most PSTATE fields are left unchanged in the 36 - * handler. However, some are explicitly overridden (e.g. M[4:0]). Luckily all 37 - * of the inherited bits have the same position in the AArch64/AArch32 SPSR_ELx 38 - * layouts, so we don't need to shuffle these for exceptions from AArch32 EL0. 39 - * 40 - * For the SPSR_ELx layout for AArch64, see ARM DDI 0487E.a page C5-429. 41 - * For the SPSR_ELx layout for AArch32, see ARM DDI 0487E.a page C5-426. 42 - * 43 - * Here we manipulate the fields in order of the AArch64 SPSR_ELx layout, from 44 - * MSB to LSB. 45 - */ 46 - static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode, 47 - enum exception_type type) 48 - { 49 - unsigned long sctlr, vbar, old, new, mode; 50 - u64 exc_offset; 51 - 52 - mode = *vcpu_cpsr(vcpu) & (PSR_MODE_MASK | PSR_MODE32_BIT); 53 - 54 - if (mode == target_mode) 55 - exc_offset = CURRENT_EL_SP_ELx_VECTOR; 56 - else if ((mode | PSR_MODE_THREAD_BIT) == target_mode) 57 - exc_offset = CURRENT_EL_SP_EL0_VECTOR; 58 - else if (!(mode & PSR_MODE32_BIT)) 59 - exc_offset = LOWER_EL_AArch64_VECTOR; 60 - else 61 - exc_offset = LOWER_EL_AArch32_VECTOR; 62 - 63 - switch (target_mode) { 64 - case PSR_MODE_EL1h: 65 - vbar = vcpu_read_sys_reg(vcpu, VBAR_EL1); 66 - sctlr = vcpu_read_sys_reg(vcpu, SCTLR_EL1); 67 - vcpu_write_sys_reg(vcpu, *vcpu_pc(vcpu), ELR_EL1); 68 - break; 69 - default: 70 - /* Don't do that */ 71 - BUG(); 72 - } 73 - 74 - *vcpu_pc(vcpu) = vbar + exc_offset + type; 75 - 76 - old = *vcpu_cpsr(vcpu); 77 - new = 0; 78 - 79 - new |= (old & PSR_N_BIT); 80 - new |= (old & PSR_Z_BIT); 81 - new |= (old & PSR_C_BIT); 82 - new |= (old & PSR_V_BIT); 83 - 84 - // TODO: TCO (if/when ARMv8.5-MemTag is exposed to guests) 85 - 86 - new |= (old & PSR_DIT_BIT); 87 - 88 - // PSTATE.UAO is set to zero upon any exception to AArch64 89 - // See ARM DDI 0487E.a, page D5-2579. 90 - 91 - // PSTATE.PAN is unchanged unless SCTLR_ELx.SPAN == 0b0 92 - // SCTLR_ELx.SPAN is RES1 when ARMv8.1-PAN is not implemented 93 - // See ARM DDI 0487E.a, page D5-2578. 94 - new |= (old & PSR_PAN_BIT); 95 - if (!(sctlr & SCTLR_EL1_SPAN)) 96 - new |= PSR_PAN_BIT; 97 - 98 - // PSTATE.SS is set to zero upon any exception to AArch64 99 - // See ARM DDI 0487E.a, page D2-2452. 100 - 101 - // PSTATE.IL is set to zero upon any exception to AArch64 102 - // See ARM DDI 0487E.a, page D1-2306. 103 - 104 - // PSTATE.SSBS is set to SCTLR_ELx.DSSBS upon any exception to AArch64 105 - // See ARM DDI 0487E.a, page D13-3258 106 - if (sctlr & SCTLR_ELx_DSSBS) 107 - new |= PSR_SSBS_BIT; 108 - 109 - // PSTATE.BTYPE is set to zero upon any exception to AArch64 110 - // See ARM DDI 0487E.a, pages D1-2293 to D1-2294. 111 - 112 - new |= PSR_D_BIT; 113 - new |= PSR_A_BIT; 114 - new |= PSR_I_BIT; 115 - new |= PSR_F_BIT; 116 - 117 - new |= target_mode; 118 - 119 - *vcpu_cpsr(vcpu) = new; 120 - vcpu_write_spsr(vcpu, old); 121 - } 122 - 123 17 static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr) 124 18 { 125 19 unsigned long cpsr = *vcpu_cpsr(vcpu); 126 20 bool is_aarch32 = vcpu_mode_is_32bit(vcpu); 127 21 u32 esr = 0; 128 22 129 - enter_exception64(vcpu, PSR_MODE_EL1h, except_type_sync); 23 + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 | 24 + KVM_ARM64_EXCEPT_AA64_ELx_SYNC | 25 + KVM_ARM64_PENDING_EXCEPTION); 130 26 131 27 vcpu_write_sys_reg(vcpu, addr, FAR_EL1); 132 28 ··· 52 156 { 53 157 u32 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT); 54 158 55 - enter_exception64(vcpu, PSR_MODE_EL1h, except_type_sync); 159 + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 | 160 + KVM_ARM64_EXCEPT_AA64_ELx_SYNC | 161 + KVM_ARM64_PENDING_EXCEPTION); 56 162 57 163 /* 58 164 * Build an unknown exception, depending on the instruction ··· 64 166 esr |= ESR_ELx_IL; 65 167 66 168 vcpu_write_sys_reg(vcpu, esr, ESR_EL1); 169 + } 170 + 171 + #define DFSR_FSC_EXTABT_LPAE 0x10 172 + #define DFSR_FSC_EXTABT_nLPAE 0x08 173 + #define DFSR_LPAE BIT(9) 174 + #define TTBCR_EAE BIT(31) 175 + 176 + static void inject_undef32(struct kvm_vcpu *vcpu) 177 + { 178 + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_UND | 179 + KVM_ARM64_PENDING_EXCEPTION); 180 + } 181 + 182 + /* 183 + * Modelled after TakeDataAbortException() and TakePrefetchAbortException 184 + * pseudocode. 185 + */ 186 + static void inject_abt32(struct kvm_vcpu *vcpu, bool is_pabt, u32 addr) 187 + { 188 + u64 far; 189 + u32 fsr; 190 + 191 + /* Give the guest an IMPLEMENTATION DEFINED exception */ 192 + if (vcpu_read_sys_reg(vcpu, TCR_EL1) & TTBCR_EAE) { 193 + fsr = DFSR_LPAE | DFSR_FSC_EXTABT_LPAE; 194 + } else { 195 + /* no need to shuffle FS[4] into DFSR[10] as its 0 */ 196 + fsr = DFSR_FSC_EXTABT_nLPAE; 197 + } 198 + 199 + far = vcpu_read_sys_reg(vcpu, FAR_EL1); 200 + 201 + if (is_pabt) { 202 + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_IABT | 203 + KVM_ARM64_PENDING_EXCEPTION); 204 + far &= GENMASK(31, 0); 205 + far |= (u64)addr << 32; 206 + vcpu_write_sys_reg(vcpu, fsr, IFSR32_EL2); 207 + } else { /* !iabt */ 208 + vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_DABT | 209 + KVM_ARM64_PENDING_EXCEPTION); 210 + far &= GENMASK(63, 32); 211 + far |= addr; 212 + vcpu_write_sys_reg(vcpu, fsr, ESR_EL1); 213 + } 214 + 215 + vcpu_write_sys_reg(vcpu, far, FAR_EL1); 67 216 } 68 217 69 218 /** ··· 124 179 void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr) 125 180 { 126 181 if (vcpu_el1_is_32bit(vcpu)) 127 - kvm_inject_dabt32(vcpu, addr); 182 + inject_abt32(vcpu, false, addr); 128 183 else 129 184 inject_abt64(vcpu, false, addr); 130 185 } ··· 140 195 void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr) 141 196 { 142 197 if (vcpu_el1_is_32bit(vcpu)) 143 - kvm_inject_pabt32(vcpu, addr); 198 + inject_abt32(vcpu, true, addr); 144 199 else 145 200 inject_abt64(vcpu, true, addr); 146 201 } ··· 155 210 void kvm_inject_undefined(struct kvm_vcpu *vcpu) 156 211 { 157 212 if (vcpu_el1_is_32bit(vcpu)) 158 - kvm_inject_undef32(vcpu); 213 + inject_undef32(vcpu); 159 214 else 160 215 inject_undef64(vcpu); 161 216 }
+1 -1
arch/arm64/kvm/mmio.c
··· 115 115 * The MMIO instruction is emulated and should not be re-executed 116 116 * in the guest. 117 117 */ 118 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 118 + kvm_incr_pc(vcpu); 119 119 120 120 return 0; 121 121 }
+1 -1
arch/arm64/kvm/mmu.c
··· 1016 1016 * cautious, and skip the instruction. 1017 1017 */ 1018 1018 if (kvm_is_error_hva(hva) && kvm_vcpu_dabt_is_cm(vcpu)) { 1019 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 1019 + kvm_incr_pc(vcpu); 1020 1020 ret = 1; 1021 1021 goto out_unlock; 1022 1022 }
+8 -11
arch/arm64/kvm/pmu-emul.c
··· 384 384 struct kvm_pmu *pmu = &vcpu->arch.pmu; 385 385 bool overflow; 386 386 387 - if (!kvm_arm_pmu_v3_ready(vcpu)) 387 + if (!kvm_vcpu_has_pmu(vcpu)) 388 388 return; 389 389 390 390 overflow = !!kvm_pmu_overflow_status(vcpu); ··· 825 825 826 826 int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu) 827 827 { 828 - if (!vcpu->arch.pmu.created) 828 + if (!kvm_vcpu_has_pmu(vcpu)) 829 829 return 0; 830 + 831 + if (!vcpu->arch.pmu.created) 832 + return -EINVAL; 830 833 831 834 /* 832 835 * A valid interrupt configuration for the PMU is either to have a ··· 838 835 */ 839 836 if (irqchip_in_kernel(vcpu->kvm)) { 840 837 int irq = vcpu->arch.pmu.irq_num; 841 - if (!kvm_arm_pmu_irq_initialized(vcpu)) 842 - return -EINVAL; 843 - 844 838 /* 845 839 * If we are using an in-kernel vgic, at this point we know 846 840 * the vgic will be initialized, so we can check the PMU irq ··· 851 851 } 852 852 853 853 kvm_pmu_vcpu_reset(vcpu); 854 - vcpu->arch.pmu.ready = true; 855 854 856 855 return 0; 857 856 } ··· 912 913 913 914 int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) 914 915 { 915 - if (!kvm_arm_support_pmu_v3() || 916 - !test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features)) 916 + if (!kvm_vcpu_has_pmu(vcpu)) 917 917 return -ENODEV; 918 918 919 919 if (vcpu->arch.pmu.created) ··· 1013 1015 if (!irqchip_in_kernel(vcpu->kvm)) 1014 1016 return -EINVAL; 1015 1017 1016 - if (!test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features)) 1018 + if (!kvm_vcpu_has_pmu(vcpu)) 1017 1019 return -ENODEV; 1018 1020 1019 1021 if (!kvm_arm_pmu_irq_initialized(vcpu)) ··· 1033 1035 case KVM_ARM_VCPU_PMU_V3_IRQ: 1034 1036 case KVM_ARM_VCPU_PMU_V3_INIT: 1035 1037 case KVM_ARM_VCPU_PMU_V3_FILTER: 1036 - if (kvm_arm_support_pmu_v3() && 1037 - test_bit(KVM_ARM_VCPU_PMU_V3, vcpu->arch.features)) 1038 + if (kvm_vcpu_has_pmu(vcpu)) 1038 1039 return 0; 1039 1040 } 1040 1041
+1 -5
arch/arm64/kvm/pvtime.c
··· 53 53 struct pvclock_vcpu_stolen_time init_values = {}; 54 54 struct kvm *kvm = vcpu->kvm; 55 55 u64 base = vcpu->arch.steal.base; 56 - int idx; 57 56 58 57 if (base == GPA_INVALID) 59 58 return base; ··· 62 63 * the feature enabled. 63 64 */ 64 65 vcpu->arch.steal.last_steal = current->sched_info.run_delay; 65 - 66 - idx = srcu_read_lock(&kvm->srcu); 67 - kvm_write_guest(kvm, base, &init_values, sizeof(init_values)); 68 - srcu_read_unlock(&kvm->srcu, idx); 66 + kvm_write_guest_lock(kvm, base, &init_values, sizeof(init_values)); 69 67 70 68 return base; 71 69 }
-224
arch/arm64/kvm/regmap.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) 2012,2013 - ARM Ltd 4 - * Author: Marc Zyngier <marc.zyngier@arm.com> 5 - * 6 - * Derived from arch/arm/kvm/emulate.c: 7 - * Copyright (C) 2012 - Virtual Open Systems and Columbia University 8 - * Author: Christoffer Dall <c.dall@virtualopensystems.com> 9 - */ 10 - 11 - #include <linux/mm.h> 12 - #include <linux/kvm_host.h> 13 - #include <asm/kvm_emulate.h> 14 - #include <asm/ptrace.h> 15 - 16 - #define VCPU_NR_MODES 6 17 - #define REG_OFFSET(_reg) \ 18 - (offsetof(struct user_pt_regs, _reg) / sizeof(unsigned long)) 19 - 20 - #define USR_REG_OFFSET(R) REG_OFFSET(compat_usr(R)) 21 - 22 - static const unsigned long vcpu_reg_offsets[VCPU_NR_MODES][16] = { 23 - /* USR Registers */ 24 - { 25 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 26 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 27 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), USR_REG_OFFSET(8), 28 - USR_REG_OFFSET(9), USR_REG_OFFSET(10), USR_REG_OFFSET(11), 29 - USR_REG_OFFSET(12), USR_REG_OFFSET(13), USR_REG_OFFSET(14), 30 - REG_OFFSET(pc) 31 - }, 32 - 33 - /* FIQ Registers */ 34 - { 35 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 36 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 37 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), 38 - REG_OFFSET(compat_r8_fiq), /* r8 */ 39 - REG_OFFSET(compat_r9_fiq), /* r9 */ 40 - REG_OFFSET(compat_r10_fiq), /* r10 */ 41 - REG_OFFSET(compat_r11_fiq), /* r11 */ 42 - REG_OFFSET(compat_r12_fiq), /* r12 */ 43 - REG_OFFSET(compat_sp_fiq), /* r13 */ 44 - REG_OFFSET(compat_lr_fiq), /* r14 */ 45 - REG_OFFSET(pc) 46 - }, 47 - 48 - /* IRQ Registers */ 49 - { 50 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 51 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 52 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), USR_REG_OFFSET(8), 53 - USR_REG_OFFSET(9), USR_REG_OFFSET(10), USR_REG_OFFSET(11), 54 - USR_REG_OFFSET(12), 55 - REG_OFFSET(compat_sp_irq), /* r13 */ 56 - REG_OFFSET(compat_lr_irq), /* r14 */ 57 - REG_OFFSET(pc) 58 - }, 59 - 60 - /* SVC Registers */ 61 - { 62 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 63 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 64 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), USR_REG_OFFSET(8), 65 - USR_REG_OFFSET(9), USR_REG_OFFSET(10), USR_REG_OFFSET(11), 66 - USR_REG_OFFSET(12), 67 - REG_OFFSET(compat_sp_svc), /* r13 */ 68 - REG_OFFSET(compat_lr_svc), /* r14 */ 69 - REG_OFFSET(pc) 70 - }, 71 - 72 - /* ABT Registers */ 73 - { 74 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 75 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 76 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), USR_REG_OFFSET(8), 77 - USR_REG_OFFSET(9), USR_REG_OFFSET(10), USR_REG_OFFSET(11), 78 - USR_REG_OFFSET(12), 79 - REG_OFFSET(compat_sp_abt), /* r13 */ 80 - REG_OFFSET(compat_lr_abt), /* r14 */ 81 - REG_OFFSET(pc) 82 - }, 83 - 84 - /* UND Registers */ 85 - { 86 - USR_REG_OFFSET(0), USR_REG_OFFSET(1), USR_REG_OFFSET(2), 87 - USR_REG_OFFSET(3), USR_REG_OFFSET(4), USR_REG_OFFSET(5), 88 - USR_REG_OFFSET(6), USR_REG_OFFSET(7), USR_REG_OFFSET(8), 89 - USR_REG_OFFSET(9), USR_REG_OFFSET(10), USR_REG_OFFSET(11), 90 - USR_REG_OFFSET(12), 91 - REG_OFFSET(compat_sp_und), /* r13 */ 92 - REG_OFFSET(compat_lr_und), /* r14 */ 93 - REG_OFFSET(pc) 94 - }, 95 - }; 96 - 97 - /* 98 - * Return a pointer to the register number valid in the current mode of 99 - * the virtual CPU. 100 - */ 101 - unsigned long *vcpu_reg32(const struct kvm_vcpu *vcpu, u8 reg_num) 102 - { 103 - unsigned long *reg_array = (unsigned long *)&vcpu->arch.ctxt.regs; 104 - unsigned long mode = *vcpu_cpsr(vcpu) & PSR_AA32_MODE_MASK; 105 - 106 - switch (mode) { 107 - case PSR_AA32_MODE_USR ... PSR_AA32_MODE_SVC: 108 - mode &= ~PSR_MODE32_BIT; /* 0 ... 3 */ 109 - break; 110 - 111 - case PSR_AA32_MODE_ABT: 112 - mode = 4; 113 - break; 114 - 115 - case PSR_AA32_MODE_UND: 116 - mode = 5; 117 - break; 118 - 119 - case PSR_AA32_MODE_SYS: 120 - mode = 0; /* SYS maps to USR */ 121 - break; 122 - 123 - default: 124 - BUG(); 125 - } 126 - 127 - return reg_array + vcpu_reg_offsets[mode][reg_num]; 128 - } 129 - 130 - /* 131 - * Return the SPSR for the current mode of the virtual CPU. 132 - */ 133 - static int vcpu_spsr32_mode(const struct kvm_vcpu *vcpu) 134 - { 135 - unsigned long mode = *vcpu_cpsr(vcpu) & PSR_AA32_MODE_MASK; 136 - switch (mode) { 137 - case PSR_AA32_MODE_SVC: return KVM_SPSR_SVC; 138 - case PSR_AA32_MODE_ABT: return KVM_SPSR_ABT; 139 - case PSR_AA32_MODE_UND: return KVM_SPSR_UND; 140 - case PSR_AA32_MODE_IRQ: return KVM_SPSR_IRQ; 141 - case PSR_AA32_MODE_FIQ: return KVM_SPSR_FIQ; 142 - default: BUG(); 143 - } 144 - } 145 - 146 - unsigned long vcpu_read_spsr32(const struct kvm_vcpu *vcpu) 147 - { 148 - int spsr_idx = vcpu_spsr32_mode(vcpu); 149 - 150 - if (!vcpu->arch.sysregs_loaded_on_cpu) { 151 - switch (spsr_idx) { 152 - case KVM_SPSR_SVC: 153 - return __vcpu_sys_reg(vcpu, SPSR_EL1); 154 - case KVM_SPSR_ABT: 155 - return vcpu->arch.ctxt.spsr_abt; 156 - case KVM_SPSR_UND: 157 - return vcpu->arch.ctxt.spsr_und; 158 - case KVM_SPSR_IRQ: 159 - return vcpu->arch.ctxt.spsr_irq; 160 - case KVM_SPSR_FIQ: 161 - return vcpu->arch.ctxt.spsr_fiq; 162 - } 163 - } 164 - 165 - switch (spsr_idx) { 166 - case KVM_SPSR_SVC: 167 - return read_sysreg_el1(SYS_SPSR); 168 - case KVM_SPSR_ABT: 169 - return read_sysreg(spsr_abt); 170 - case KVM_SPSR_UND: 171 - return read_sysreg(spsr_und); 172 - case KVM_SPSR_IRQ: 173 - return read_sysreg(spsr_irq); 174 - case KVM_SPSR_FIQ: 175 - return read_sysreg(spsr_fiq); 176 - default: 177 - BUG(); 178 - } 179 - } 180 - 181 - void vcpu_write_spsr32(struct kvm_vcpu *vcpu, unsigned long v) 182 - { 183 - int spsr_idx = vcpu_spsr32_mode(vcpu); 184 - 185 - if (!vcpu->arch.sysregs_loaded_on_cpu) { 186 - switch (spsr_idx) { 187 - case KVM_SPSR_SVC: 188 - __vcpu_sys_reg(vcpu, SPSR_EL1) = v; 189 - break; 190 - case KVM_SPSR_ABT: 191 - vcpu->arch.ctxt.spsr_abt = v; 192 - break; 193 - case KVM_SPSR_UND: 194 - vcpu->arch.ctxt.spsr_und = v; 195 - break; 196 - case KVM_SPSR_IRQ: 197 - vcpu->arch.ctxt.spsr_irq = v; 198 - break; 199 - case KVM_SPSR_FIQ: 200 - vcpu->arch.ctxt.spsr_fiq = v; 201 - break; 202 - } 203 - 204 - return; 205 - } 206 - 207 - switch (spsr_idx) { 208 - case KVM_SPSR_SVC: 209 - write_sysreg_el1(v, SYS_SPSR); 210 - break; 211 - case KVM_SPSR_ABT: 212 - write_sysreg(v, spsr_abt); 213 - break; 214 - case KVM_SPSR_UND: 215 - write_sysreg(v, spsr_und); 216 - break; 217 - case KVM_SPSR_IRQ: 218 - write_sysreg(v, spsr_irq); 219 - break; 220 - case KVM_SPSR_FIQ: 221 - write_sysreg(v, spsr_fiq); 222 - break; 223 - } 224 - }
+4 -53
arch/arm64/kvm/reset.c
··· 25 25 #include <asm/ptrace.h> 26 26 #include <asm/kvm_arm.h> 27 27 #include <asm/kvm_asm.h> 28 - #include <asm/kvm_coproc.h> 29 28 #include <asm/kvm_emulate.h> 30 29 #include <asm/kvm_mmu.h> 31 30 #include <asm/virt.h> ··· 40 41 41 42 #define VCPU_RESET_PSTATE_SVC (PSR_AA32_MODE_SVC | PSR_AA32_A_BIT | \ 42 43 PSR_AA32_I_BIT | PSR_AA32_F_BIT) 43 - 44 - static bool system_has_full_ptr_auth(void) 45 - { 46 - return system_supports_address_auth() && system_supports_generic_auth(); 47 - } 48 - 49 - /** 50 - * kvm_arch_vm_ioctl_check_extension 51 - * 52 - * We currently assume that the number of HW registers is uniform 53 - * across all CPUs (see cpuinfo_sanity_check). 54 - */ 55 - int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext) 56 - { 57 - int r; 58 - 59 - switch (ext) { 60 - case KVM_CAP_ARM_EL1_32BIT: 61 - r = cpus_have_const_cap(ARM64_HAS_32BIT_EL1); 62 - break; 63 - case KVM_CAP_GUEST_DEBUG_HW_BPS: 64 - r = get_num_brps(); 65 - break; 66 - case KVM_CAP_GUEST_DEBUG_HW_WPS: 67 - r = get_num_wrps(); 68 - break; 69 - case KVM_CAP_ARM_PMU_V3: 70 - r = kvm_arm_support_pmu_v3(); 71 - break; 72 - case KVM_CAP_ARM_INJECT_SERROR_ESR: 73 - r = cpus_have_const_cap(ARM64_HAS_RAS_EXTN); 74 - break; 75 - case KVM_CAP_SET_GUEST_DEBUG: 76 - case KVM_CAP_VCPU_ATTRIBUTES: 77 - r = 1; 78 - break; 79 - case KVM_CAP_ARM_VM_IPA_SIZE: 80 - r = kvm_ipa_limit; 81 - break; 82 - case KVM_CAP_ARM_SVE: 83 - r = system_supports_sve(); 84 - break; 85 - case KVM_CAP_ARM_PTRAUTH_ADDRESS: 86 - case KVM_CAP_ARM_PTRAUTH_GENERIC: 87 - r = system_has_full_ptr_auth(); 88 - break; 89 - default: 90 - r = 0; 91 - } 92 - 93 - return r; 94 - } 95 44 96 45 unsigned int kvm_sve_max_vl; 97 46 ··· 233 286 pstate = VCPU_RESET_PSTATE_EL1; 234 287 } 235 288 289 + if (kvm_vcpu_has_pmu(vcpu) && !kvm_arm_support_pmu_v3()) { 290 + ret = -EINVAL; 291 + goto out; 292 + } 236 293 break; 237 294 } 238 295
+137 -253
arch/arm64/kvm/sys_regs.c
··· 20 20 #include <asm/debug-monitors.h> 21 21 #include <asm/esr.h> 22 22 #include <asm/kvm_arm.h> 23 - #include <asm/kvm_coproc.h> 24 23 #include <asm/kvm_emulate.h> 25 24 #include <asm/kvm_hyp.h> 26 25 #include <asm/kvm_mmu.h> ··· 63 64 return false; 64 65 } 65 66 66 - static bool __vcpu_read_sys_reg_from_cpu(int reg, u64 *val) 67 - { 68 - /* 69 - * System registers listed in the switch are not saved on every 70 - * exit from the guest but are only saved on vcpu_put. 71 - * 72 - * Note that MPIDR_EL1 for the guest is set by KVM via VMPIDR_EL2 but 73 - * should never be listed below, because the guest cannot modify its 74 - * own MPIDR_EL1 and MPIDR_EL1 is accessed for VCPU A from VCPU B's 75 - * thread when emulating cross-VCPU communication. 76 - */ 77 - switch (reg) { 78 - case CSSELR_EL1: *val = read_sysreg_s(SYS_CSSELR_EL1); break; 79 - case SCTLR_EL1: *val = read_sysreg_s(SYS_SCTLR_EL12); break; 80 - case CPACR_EL1: *val = read_sysreg_s(SYS_CPACR_EL12); break; 81 - case TTBR0_EL1: *val = read_sysreg_s(SYS_TTBR0_EL12); break; 82 - case TTBR1_EL1: *val = read_sysreg_s(SYS_TTBR1_EL12); break; 83 - case TCR_EL1: *val = read_sysreg_s(SYS_TCR_EL12); break; 84 - case ESR_EL1: *val = read_sysreg_s(SYS_ESR_EL12); break; 85 - case AFSR0_EL1: *val = read_sysreg_s(SYS_AFSR0_EL12); break; 86 - case AFSR1_EL1: *val = read_sysreg_s(SYS_AFSR1_EL12); break; 87 - case FAR_EL1: *val = read_sysreg_s(SYS_FAR_EL12); break; 88 - case MAIR_EL1: *val = read_sysreg_s(SYS_MAIR_EL12); break; 89 - case VBAR_EL1: *val = read_sysreg_s(SYS_VBAR_EL12); break; 90 - case CONTEXTIDR_EL1: *val = read_sysreg_s(SYS_CONTEXTIDR_EL12);break; 91 - case TPIDR_EL0: *val = read_sysreg_s(SYS_TPIDR_EL0); break; 92 - case TPIDRRO_EL0: *val = read_sysreg_s(SYS_TPIDRRO_EL0); break; 93 - case TPIDR_EL1: *val = read_sysreg_s(SYS_TPIDR_EL1); break; 94 - case AMAIR_EL1: *val = read_sysreg_s(SYS_AMAIR_EL12); break; 95 - case CNTKCTL_EL1: *val = read_sysreg_s(SYS_CNTKCTL_EL12); break; 96 - case ELR_EL1: *val = read_sysreg_s(SYS_ELR_EL12); break; 97 - case PAR_EL1: *val = read_sysreg_par(); break; 98 - case DACR32_EL2: *val = read_sysreg_s(SYS_DACR32_EL2); break; 99 - case IFSR32_EL2: *val = read_sysreg_s(SYS_IFSR32_EL2); break; 100 - case DBGVCR32_EL2: *val = read_sysreg_s(SYS_DBGVCR32_EL2); break; 101 - default: return false; 102 - } 103 - 104 - return true; 105 - } 106 - 107 - static bool __vcpu_write_sys_reg_to_cpu(u64 val, int reg) 108 - { 109 - /* 110 - * System registers listed in the switch are not restored on every 111 - * entry to the guest but are only restored on vcpu_load. 112 - * 113 - * Note that MPIDR_EL1 for the guest is set by KVM via VMPIDR_EL2 but 114 - * should never be listed below, because the MPIDR should only be set 115 - * once, before running the VCPU, and never changed later. 116 - */ 117 - switch (reg) { 118 - case CSSELR_EL1: write_sysreg_s(val, SYS_CSSELR_EL1); break; 119 - case SCTLR_EL1: write_sysreg_s(val, SYS_SCTLR_EL12); break; 120 - case CPACR_EL1: write_sysreg_s(val, SYS_CPACR_EL12); break; 121 - case TTBR0_EL1: write_sysreg_s(val, SYS_TTBR0_EL12); break; 122 - case TTBR1_EL1: write_sysreg_s(val, SYS_TTBR1_EL12); break; 123 - case TCR_EL1: write_sysreg_s(val, SYS_TCR_EL12); break; 124 - case ESR_EL1: write_sysreg_s(val, SYS_ESR_EL12); break; 125 - case AFSR0_EL1: write_sysreg_s(val, SYS_AFSR0_EL12); break; 126 - case AFSR1_EL1: write_sysreg_s(val, SYS_AFSR1_EL12); break; 127 - case FAR_EL1: write_sysreg_s(val, SYS_FAR_EL12); break; 128 - case MAIR_EL1: write_sysreg_s(val, SYS_MAIR_EL12); break; 129 - case VBAR_EL1: write_sysreg_s(val, SYS_VBAR_EL12); break; 130 - case CONTEXTIDR_EL1: write_sysreg_s(val, SYS_CONTEXTIDR_EL12);break; 131 - case TPIDR_EL0: write_sysreg_s(val, SYS_TPIDR_EL0); break; 132 - case TPIDRRO_EL0: write_sysreg_s(val, SYS_TPIDRRO_EL0); break; 133 - case TPIDR_EL1: write_sysreg_s(val, SYS_TPIDR_EL1); break; 134 - case AMAIR_EL1: write_sysreg_s(val, SYS_AMAIR_EL12); break; 135 - case CNTKCTL_EL1: write_sysreg_s(val, SYS_CNTKCTL_EL12); break; 136 - case ELR_EL1: write_sysreg_s(val, SYS_ELR_EL12); break; 137 - case PAR_EL1: write_sysreg_s(val, SYS_PAR_EL1); break; 138 - case DACR32_EL2: write_sysreg_s(val, SYS_DACR32_EL2); break; 139 - case IFSR32_EL2: write_sysreg_s(val, SYS_IFSR32_EL2); break; 140 - case DBGVCR32_EL2: write_sysreg_s(val, SYS_DBGVCR32_EL2); break; 141 - default: return false; 142 - } 143 - 144 - return true; 145 - } 146 - 147 67 u64 vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg) 148 68 { 149 69 u64 val = 0x8badf00d8badf00d; ··· 87 169 static u32 cache_levels; 88 170 89 171 /* CSSELR values; used to index KVM_REG_ARM_DEMUX_ID_CCSIDR */ 90 - #define CSSELR_MAX 12 172 + #define CSSELR_MAX 14 91 173 92 174 /* Which cache CCSIDR represents depends on CSSELR value. */ 93 175 static u32 get_ccsidr(u32 csselr) ··· 127 209 return true; 128 210 } 129 211 212 + static void get_access_mask(const struct sys_reg_desc *r, u64 *mask, u64 *shift) 213 + { 214 + switch (r->aarch32_map) { 215 + case AA32_LO: 216 + *mask = GENMASK_ULL(31, 0); 217 + *shift = 0; 218 + break; 219 + case AA32_HI: 220 + *mask = GENMASK_ULL(63, 32); 221 + *shift = 32; 222 + break; 223 + default: 224 + *mask = GENMASK_ULL(63, 0); 225 + *shift = 0; 226 + break; 227 + } 228 + } 229 + 130 230 /* 131 231 * Generic accessor for VM registers. Only called as long as HCR_TVM 132 232 * is set. If the guest enables the MMU, we stop trapping the VM ··· 155 219 const struct sys_reg_desc *r) 156 220 { 157 221 bool was_enabled = vcpu_has_cache_enabled(vcpu); 158 - u64 val; 159 - int reg = r->reg; 222 + u64 val, mask, shift; 160 223 161 224 BUG_ON(!p->is_write); 162 225 163 - /* See the 32bit mapping in kvm_host.h */ 164 - if (p->is_aarch32) 165 - reg = r->reg / 2; 226 + get_access_mask(r, &mask, &shift); 166 227 167 - if (!p->is_aarch32 || !p->is_32bit) { 168 - val = p->regval; 228 + if (~mask) { 229 + val = vcpu_read_sys_reg(vcpu, r->reg); 230 + val &= ~mask; 169 231 } else { 170 - val = vcpu_read_sys_reg(vcpu, reg); 171 - if (r->reg % 2) 172 - val = (p->regval << 32) | (u64)lower_32_bits(val); 173 - else 174 - val = ((u64)upper_32_bits(val) << 32) | 175 - lower_32_bits(p->regval); 232 + val = 0; 176 233 } 177 - vcpu_write_sys_reg(vcpu, val, reg); 234 + 235 + val |= (p->regval & (mask >> shift)) << shift; 236 + vcpu_write_sys_reg(vcpu, val, r->reg); 178 237 179 238 kvm_toggle_cache(vcpu, was_enabled); 180 239 return true; ··· 179 248 struct sys_reg_params *p, 180 249 const struct sys_reg_desc *r) 181 250 { 251 + u64 mask, shift; 252 + 182 253 if (p->is_write) 183 254 return ignore_write(vcpu, p); 184 255 185 - p->regval = vcpu_read_sys_reg(vcpu, ACTLR_EL1); 186 - 187 - if (p->is_aarch32) { 188 - if (r->Op2 & 2) 189 - p->regval = upper_32_bits(p->regval); 190 - else 191 - p->regval = lower_32_bits(p->regval); 192 - } 256 + get_access_mask(r, &mask, &shift); 257 + p->regval = (vcpu_read_sys_reg(vcpu, r->reg) & mask) >> shift; 193 258 194 259 return true; 195 260 } ··· 212 285 * equivalent to ICC_SGI0R_EL1, as there is no "alternative" secure 213 286 * group. 214 287 */ 215 - if (p->is_aarch32) { 288 + if (p->Op0 == 0) { /* AArch32 */ 216 289 switch (p->Op1) { 217 290 default: /* Keep GCC quiet */ 218 291 case 0: /* ICC_SGI1R */ ··· 223 296 g1 = false; 224 297 break; 225 298 } 226 - } else { 299 + } else { /* AArch64 */ 227 300 switch (p->Op2) { 228 301 default: /* Keep GCC quiet */ 229 302 case 5: /* ICC_SGI1R_EL1 */ ··· 365 438 */ 366 439 static void reg_to_dbg(struct kvm_vcpu *vcpu, 367 440 struct sys_reg_params *p, 441 + const struct sys_reg_desc *rd, 368 442 u64 *dbg_reg) 369 443 { 370 - u64 val = p->regval; 444 + u64 mask, shift, val; 371 445 372 - if (p->is_32bit) { 373 - val &= 0xffffffffUL; 374 - val |= ((*dbg_reg >> 32) << 32); 375 - } 446 + get_access_mask(rd, &mask, &shift); 376 447 448 + val = *dbg_reg; 449 + val &= ~mask; 450 + val |= (p->regval & (mask >> shift)) << shift; 377 451 *dbg_reg = val; 452 + 378 453 vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY; 379 454 } 380 455 381 456 static void dbg_to_reg(struct kvm_vcpu *vcpu, 382 457 struct sys_reg_params *p, 458 + const struct sys_reg_desc *rd, 383 459 u64 *dbg_reg) 384 460 { 385 - p->regval = *dbg_reg; 386 - if (p->is_32bit) 387 - p->regval &= 0xffffffffUL; 461 + u64 mask, shift; 462 + 463 + get_access_mask(rd, &mask, &shift); 464 + p->regval = (*dbg_reg & mask) >> shift; 388 465 } 389 466 390 467 static bool trap_bvr(struct kvm_vcpu *vcpu, ··· 398 467 u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg]; 399 468 400 469 if (p->is_write) 401 - reg_to_dbg(vcpu, p, dbg_reg); 470 + reg_to_dbg(vcpu, p, rd, dbg_reg); 402 471 else 403 - dbg_to_reg(vcpu, p, dbg_reg); 472 + dbg_to_reg(vcpu, p, rd, dbg_reg); 404 473 405 474 trace_trap_reg(__func__, rd->reg, p->is_write, *dbg_reg); 406 475 ··· 440 509 u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_bcr[rd->reg]; 441 510 442 511 if (p->is_write) 443 - reg_to_dbg(vcpu, p, dbg_reg); 512 + reg_to_dbg(vcpu, p, rd, dbg_reg); 444 513 else 445 - dbg_to_reg(vcpu, p, dbg_reg); 514 + dbg_to_reg(vcpu, p, rd, dbg_reg); 446 515 447 516 trace_trap_reg(__func__, rd->reg, p->is_write, *dbg_reg); 448 517 ··· 483 552 u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg]; 484 553 485 554 if (p->is_write) 486 - reg_to_dbg(vcpu, p, dbg_reg); 555 + reg_to_dbg(vcpu, p, rd, dbg_reg); 487 556 else 488 - dbg_to_reg(vcpu, p, dbg_reg); 557 + dbg_to_reg(vcpu, p, rd, dbg_reg); 489 558 490 559 trace_trap_reg(__func__, rd->reg, p->is_write, 491 560 vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg]); ··· 526 595 u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_wcr[rd->reg]; 527 596 528 597 if (p->is_write) 529 - reg_to_dbg(vcpu, p, dbg_reg); 598 + reg_to_dbg(vcpu, p, rd, dbg_reg); 530 599 else 531 - dbg_to_reg(vcpu, p, dbg_reg); 600 + dbg_to_reg(vcpu, p, rd, dbg_reg); 532 601 533 602 trace_trap_reg(__func__, rd->reg, p->is_write, *dbg_reg); 534 603 ··· 609 678 static bool check_pmu_access_disabled(struct kvm_vcpu *vcpu, u64 flags) 610 679 { 611 680 u64 reg = __vcpu_sys_reg(vcpu, PMUSERENR_EL0); 612 - bool enabled = (reg & flags) || vcpu_mode_priv(vcpu); 681 + bool enabled = kvm_vcpu_has_pmu(vcpu); 613 682 683 + enabled &= (reg & flags) || vcpu_mode_priv(vcpu); 614 684 if (!enabled) 615 685 kvm_inject_undefined(vcpu); 616 686 ··· 643 711 { 644 712 u64 val; 645 713 646 - if (!kvm_arm_pmu_v3_ready(vcpu)) 647 - return trap_raz_wi(vcpu, p, r); 648 - 649 714 if (pmu_access_el0_disabled(vcpu)) 650 715 return false; 651 716 ··· 669 740 static bool access_pmselr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, 670 741 const struct sys_reg_desc *r) 671 742 { 672 - if (!kvm_arm_pmu_v3_ready(vcpu)) 673 - return trap_raz_wi(vcpu, p, r); 674 - 675 743 if (pmu_access_event_counter_el0_disabled(vcpu)) 676 744 return false; 677 745 ··· 686 760 const struct sys_reg_desc *r) 687 761 { 688 762 u64 pmceid; 689 - 690 - if (!kvm_arm_pmu_v3_ready(vcpu)) 691 - return trap_raz_wi(vcpu, p, r); 692 763 693 764 BUG_ON(p->is_write); 694 765 ··· 717 794 struct sys_reg_params *p, 718 795 const struct sys_reg_desc *r) 719 796 { 720 - u64 idx; 721 - 722 - if (!kvm_arm_pmu_v3_ready(vcpu)) 723 - return trap_raz_wi(vcpu, p, r); 797 + u64 idx = ~0UL; 724 798 725 799 if (r->CRn == 9 && r->CRm == 13) { 726 800 if (r->Op2 == 2) { ··· 733 813 return false; 734 814 735 815 idx = ARMV8_PMU_CYCLE_IDX; 736 - } else { 737 - return false; 738 816 } 739 817 } else if (r->CRn == 0 && r->CRm == 9) { 740 818 /* PMCCNTR */ ··· 746 828 return false; 747 829 748 830 idx = ((r->CRm & 3) << 3) | (r->Op2 & 7); 749 - } else { 750 - return false; 751 831 } 832 + 833 + /* Catch any decoding mistake */ 834 + WARN_ON(idx == ~0UL); 752 835 753 836 if (!pmu_counter_idx_valid(vcpu, idx)) 754 837 return false; ··· 770 851 const struct sys_reg_desc *r) 771 852 { 772 853 u64 idx, reg; 773 - 774 - if (!kvm_arm_pmu_v3_ready(vcpu)) 775 - return trap_raz_wi(vcpu, p, r); 776 854 777 855 if (pmu_access_el0_disabled(vcpu)) 778 856 return false; ··· 808 892 { 809 893 u64 val, mask; 810 894 811 - if (!kvm_arm_pmu_v3_ready(vcpu)) 812 - return trap_raz_wi(vcpu, p, r); 813 - 814 895 if (pmu_access_el0_disabled(vcpu)) 815 896 return false; 816 897 ··· 836 923 { 837 924 u64 mask = kvm_pmu_valid_counter_mask(vcpu); 838 925 839 - if (!kvm_arm_pmu_v3_ready(vcpu)) 840 - return trap_raz_wi(vcpu, p, r); 841 - 842 - if (!vcpu_mode_priv(vcpu)) { 843 - kvm_inject_undefined(vcpu); 926 + if (check_pmu_access_disabled(vcpu, 0)) 844 927 return false; 845 - } 846 928 847 929 if (p->is_write) { 848 930 u64 val = p->regval & mask; ··· 859 951 const struct sys_reg_desc *r) 860 952 { 861 953 u64 mask = kvm_pmu_valid_counter_mask(vcpu); 862 - 863 - if (!kvm_arm_pmu_v3_ready(vcpu)) 864 - return trap_raz_wi(vcpu, p, r); 865 954 866 955 if (pmu_access_el0_disabled(vcpu)) 867 956 return false; ··· 882 977 { 883 978 u64 mask; 884 979 885 - if (!kvm_arm_pmu_v3_ready(vcpu)) 886 - return trap_raz_wi(vcpu, p, r); 887 - 888 980 if (!p->is_write) 889 981 return read_from_write_only(vcpu, p, r); 890 982 ··· 896 994 static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, 897 995 const struct sys_reg_desc *r) 898 996 { 899 - if (!kvm_arm_pmu_v3_ready(vcpu)) 900 - return trap_raz_wi(vcpu, p, r); 997 + if (!kvm_vcpu_has_pmu(vcpu)) { 998 + kvm_inject_undefined(vcpu); 999 + return false; 1000 + } 901 1001 902 1002 if (p->is_write) { 903 1003 if (!vcpu_mode_priv(vcpu)) { ··· 1026 1122 val &= ~(0xfUL << ID_AA64PFR0_AMU_SHIFT); 1027 1123 val &= ~(0xfUL << ID_AA64PFR0_CSV2_SHIFT); 1028 1124 val |= ((u64)vcpu->kvm->arch.pfr0_csv2 << ID_AA64PFR0_CSV2_SHIFT); 1125 + val &= ~(0xfUL << ID_AA64PFR0_CSV3_SHIFT); 1126 + val |= ((u64)vcpu->kvm->arch.pfr0_csv3 << ID_AA64PFR0_CSV3_SHIFT); 1029 1127 } else if (id == SYS_ID_AA64PFR1_EL1) { 1030 1128 val &= ~(0xfUL << ID_AA64PFR1_MTE_SHIFT); 1031 1129 } else if (id == SYS_ID_AA64ISAR1_EL1 && !vcpu_has_ptrauth(vcpu)) { ··· 1036 1130 (0xfUL << ID_AA64ISAR1_GPA_SHIFT) | 1037 1131 (0xfUL << ID_AA64ISAR1_GPI_SHIFT)); 1038 1132 } else if (id == SYS_ID_AA64DFR0_EL1) { 1133 + u64 cap = 0; 1134 + 1039 1135 /* Limit guests to PMUv3 for ARMv8.1 */ 1136 + if (kvm_vcpu_has_pmu(vcpu)) 1137 + cap = ID_AA64DFR0_PMUVER_8_1; 1138 + 1040 1139 val = cpuid_feature_cap_perfmon_field(val, 1041 1140 ID_AA64DFR0_PMUVER_SHIFT, 1042 - ID_AA64DFR0_PMUVER_8_1); 1141 + cap); 1043 1142 } else if (id == SYS_ID_DFR0_EL1) { 1044 1143 /* Limit guests to PMUv3 for ARMv8.1 */ 1045 1144 val = cpuid_feature_cap_perfmon_field(val, ··· 1120 1209 const struct kvm_one_reg *reg, void __user *uaddr) 1121 1210 { 1122 1211 const u64 id = sys_reg_to_index(rd); 1212 + u8 csv2, csv3; 1123 1213 int err; 1124 1214 u64 val; 1125 - u8 csv2; 1126 1215 1127 1216 err = reg_from_user(&val, uaddr, id); 1128 1217 if (err) ··· 1138 1227 (csv2 && arm64_get_spectre_v2_state() != SPECTRE_UNAFFECTED)) 1139 1228 return -EINVAL; 1140 1229 1141 - /* We can only differ with CSV2, and anything else is an error */ 1230 + /* Same thing for CSV3 */ 1231 + csv3 = cpuid_feature_extract_unsigned_field(val, ID_AA64PFR0_CSV3_SHIFT); 1232 + if (csv3 > 1 || 1233 + (csv3 && arm64_get_meltdown_state() != SPECTRE_UNAFFECTED)) 1234 + return -EINVAL; 1235 + 1236 + /* We can only differ with CSV[23], and anything else is an error */ 1142 1237 val ^= read_id_reg(vcpu, rd, false); 1143 - val &= ~(0xFUL << ID_AA64PFR0_CSV2_SHIFT); 1238 + val &= ~((0xFUL << ID_AA64PFR0_CSV2_SHIFT) | 1239 + (0xFUL << ID_AA64PFR0_CSV3_SHIFT)); 1144 1240 if (val) 1145 1241 return -EINVAL; 1146 1242 1147 1243 vcpu->kvm->arch.pfr0_csv2 = csv2; 1244 + vcpu->kvm->arch.pfr0_csv3 = csv3 ; 1148 1245 1149 1246 return 0; 1150 1247 } ··· 1245 1326 const struct sys_reg_desc *r) 1246 1327 { 1247 1328 int reg = r->reg; 1248 - 1249 - /* See the 32bit mapping in kvm_host.h */ 1250 - if (p->is_aarch32) 1251 - reg = r->reg / 2; 1252 1329 1253 1330 if (p->is_write) 1254 1331 vcpu_write_sys_reg(vcpu, p->regval, reg); ··· 1716 1801 } 1717 1802 } 1718 1803 1719 - static bool trap_debug32(struct kvm_vcpu *vcpu, 1720 - struct sys_reg_params *p, 1721 - const struct sys_reg_desc *r) 1722 - { 1723 - if (p->is_write) { 1724 - vcpu_cp14(vcpu, r->reg) = p->regval; 1725 - vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY; 1726 - } else { 1727 - p->regval = vcpu_cp14(vcpu, r->reg); 1728 - } 1729 - 1730 - return true; 1731 - } 1732 - 1733 - /* AArch32 debug register mappings 1804 + /* 1805 + * AArch32 debug register mappings 1734 1806 * 1735 1807 * AArch32 DBGBVRn is mapped to DBGBVRn_EL1[31:0] 1736 1808 * AArch32 DBGBXVRn is mapped to DBGBVRn_EL1[63:32] 1737 1809 * 1738 - * All control registers and watchpoint value registers are mapped to 1739 - * the lower 32 bits of their AArch64 equivalents. We share the trap 1740 - * handlers with the above AArch64 code which checks what mode the 1741 - * system is in. 1810 + * None of the other registers share their location, so treat them as 1811 + * if they were 64bit. 1742 1812 */ 1743 - 1744 - static bool trap_xvr(struct kvm_vcpu *vcpu, 1745 - struct sys_reg_params *p, 1746 - const struct sys_reg_desc *rd) 1747 - { 1748 - u64 *dbg_reg = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg]; 1749 - 1750 - if (p->is_write) { 1751 - u64 val = *dbg_reg; 1752 - 1753 - val &= 0xffffffffUL; 1754 - val |= p->regval << 32; 1755 - *dbg_reg = val; 1756 - 1757 - vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY; 1758 - } else { 1759 - p->regval = *dbg_reg >> 32; 1760 - } 1761 - 1762 - trace_trap_reg(__func__, rd->reg, p->is_write, *dbg_reg); 1763 - 1764 - return true; 1765 - } 1766 - 1767 - #define DBG_BCR_BVR_WCR_WVR(n) \ 1768 - /* DBGBVRn */ \ 1769 - { Op1( 0), CRn( 0), CRm((n)), Op2( 4), trap_bvr, NULL, n }, \ 1770 - /* DBGBCRn */ \ 1771 - { Op1( 0), CRn( 0), CRm((n)), Op2( 5), trap_bcr, NULL, n }, \ 1772 - /* DBGWVRn */ \ 1773 - { Op1( 0), CRn( 0), CRm((n)), Op2( 6), trap_wvr, NULL, n }, \ 1774 - /* DBGWCRn */ \ 1813 + #define DBG_BCR_BVR_WCR_WVR(n) \ 1814 + /* DBGBVRn */ \ 1815 + { AA32(LO), Op1( 0), CRn( 0), CRm((n)), Op2( 4), trap_bvr, NULL, n }, \ 1816 + /* DBGBCRn */ \ 1817 + { Op1( 0), CRn( 0), CRm((n)), Op2( 5), trap_bcr, NULL, n }, \ 1818 + /* DBGWVRn */ \ 1819 + { Op1( 0), CRn( 0), CRm((n)), Op2( 6), trap_wvr, NULL, n }, \ 1820 + /* DBGWCRn */ \ 1775 1821 { Op1( 0), CRn( 0), CRm((n)), Op2( 7), trap_wcr, NULL, n } 1776 1822 1777 - #define DBGBXVR(n) \ 1778 - { Op1( 0), CRn( 1), CRm((n)), Op2( 1), trap_xvr, NULL, n } 1823 + #define DBGBXVR(n) \ 1824 + { AA32(HI), Op1( 0), CRn( 1), CRm((n)), Op2( 1), trap_bvr, NULL, n } 1779 1825 1780 1826 /* 1781 1827 * Trapped cp14 registers. We generally ignore most of the external ··· 1754 1878 { Op1( 0), CRn( 0), CRm( 1), Op2( 0), trap_raz_wi }, 1755 1879 DBG_BCR_BVR_WCR_WVR(1), 1756 1880 /* DBGDCCINT */ 1757 - { Op1( 0), CRn( 0), CRm( 2), Op2( 0), trap_debug32, NULL, cp14_DBGDCCINT }, 1881 + { Op1( 0), CRn( 0), CRm( 2), Op2( 0), trap_debug_regs, NULL, MDCCINT_EL1 }, 1758 1882 /* DBGDSCRext */ 1759 - { Op1( 0), CRn( 0), CRm( 2), Op2( 2), trap_debug32, NULL, cp14_DBGDSCRext }, 1883 + { Op1( 0), CRn( 0), CRm( 2), Op2( 2), trap_debug_regs, NULL, MDSCR_EL1 }, 1760 1884 DBG_BCR_BVR_WCR_WVR(2), 1761 1885 /* DBGDTR[RT]Xint */ 1762 1886 { Op1( 0), CRn( 0), CRm( 3), Op2( 0), trap_raz_wi }, ··· 1771 1895 { Op1( 0), CRn( 0), CRm( 6), Op2( 2), trap_raz_wi }, 1772 1896 DBG_BCR_BVR_WCR_WVR(6), 1773 1897 /* DBGVCR */ 1774 - { Op1( 0), CRn( 0), CRm( 7), Op2( 0), trap_debug32, NULL, cp14_DBGVCR }, 1898 + { Op1( 0), CRn( 0), CRm( 7), Op2( 0), trap_debug_regs, NULL, DBGVCR32_EL2 }, 1775 1899 DBG_BCR_BVR_WCR_WVR(7), 1776 1900 DBG_BCR_BVR_WCR_WVR(8), 1777 1901 DBG_BCR_BVR_WCR_WVR(9), ··· 1857 1981 */ 1858 1982 static const struct sys_reg_desc cp15_regs[] = { 1859 1983 { Op1( 0), CRn( 0), CRm( 0), Op2( 1), access_ctr }, 1860 - { Op1( 0), CRn( 1), CRm( 0), Op2( 0), access_vm_reg, NULL, c1_SCTLR }, 1861 - { Op1( 0), CRn( 1), CRm( 0), Op2( 1), access_actlr }, 1862 - { Op1( 0), CRn( 1), CRm( 0), Op2( 3), access_actlr }, 1863 - { Op1( 0), CRn( 2), CRm( 0), Op2( 0), access_vm_reg, NULL, c2_TTBR0 }, 1864 - { Op1( 0), CRn( 2), CRm( 0), Op2( 1), access_vm_reg, NULL, c2_TTBR1 }, 1865 - { Op1( 0), CRn( 2), CRm( 0), Op2( 2), access_vm_reg, NULL, c2_TTBCR }, 1866 - { Op1( 0), CRn( 3), CRm( 0), Op2( 0), access_vm_reg, NULL, c3_DACR }, 1867 - { Op1( 0), CRn( 5), CRm( 0), Op2( 0), access_vm_reg, NULL, c5_DFSR }, 1868 - { Op1( 0), CRn( 5), CRm( 0), Op2( 1), access_vm_reg, NULL, c5_IFSR }, 1869 - { Op1( 0), CRn( 5), CRm( 1), Op2( 0), access_vm_reg, NULL, c5_ADFSR }, 1870 - { Op1( 0), CRn( 5), CRm( 1), Op2( 1), access_vm_reg, NULL, c5_AIFSR }, 1871 - { Op1( 0), CRn( 6), CRm( 0), Op2( 0), access_vm_reg, NULL, c6_DFAR }, 1872 - { Op1( 0), CRn( 6), CRm( 0), Op2( 2), access_vm_reg, NULL, c6_IFAR }, 1984 + { Op1( 0), CRn( 1), CRm( 0), Op2( 0), access_vm_reg, NULL, SCTLR_EL1 }, 1985 + /* ACTLR */ 1986 + { AA32(LO), Op1( 0), CRn( 1), CRm( 0), Op2( 1), access_actlr, NULL, ACTLR_EL1 }, 1987 + /* ACTLR2 */ 1988 + { AA32(HI), Op1( 0), CRn( 1), CRm( 0), Op2( 3), access_actlr, NULL, ACTLR_EL1 }, 1989 + { Op1( 0), CRn( 2), CRm( 0), Op2( 0), access_vm_reg, NULL, TTBR0_EL1 }, 1990 + { Op1( 0), CRn( 2), CRm( 0), Op2( 1), access_vm_reg, NULL, TTBR1_EL1 }, 1991 + /* TTBCR */ 1992 + { AA32(LO), Op1( 0), CRn( 2), CRm( 0), Op2( 2), access_vm_reg, NULL, TCR_EL1 }, 1993 + /* TTBCR2 */ 1994 + { AA32(HI), Op1( 0), CRn( 2), CRm( 0), Op2( 3), access_vm_reg, NULL, TCR_EL1 }, 1995 + { Op1( 0), CRn( 3), CRm( 0), Op2( 0), access_vm_reg, NULL, DACR32_EL2 }, 1996 + /* DFSR */ 1997 + { Op1( 0), CRn( 5), CRm( 0), Op2( 0), access_vm_reg, NULL, ESR_EL1 }, 1998 + { Op1( 0), CRn( 5), CRm( 0), Op2( 1), access_vm_reg, NULL, IFSR32_EL2 }, 1999 + /* ADFSR */ 2000 + { Op1( 0), CRn( 5), CRm( 1), Op2( 0), access_vm_reg, NULL, AFSR0_EL1 }, 2001 + /* AIFSR */ 2002 + { Op1( 0), CRn( 5), CRm( 1), Op2( 1), access_vm_reg, NULL, AFSR1_EL1 }, 2003 + /* DFAR */ 2004 + { AA32(LO), Op1( 0), CRn( 6), CRm( 0), Op2( 0), access_vm_reg, NULL, FAR_EL1 }, 2005 + /* IFAR */ 2006 + { AA32(HI), Op1( 0), CRn( 6), CRm( 0), Op2( 2), access_vm_reg, NULL, FAR_EL1 }, 1873 2007 1874 2008 /* 1875 2009 * DC{C,I,CI}SW operations: ··· 1905 2019 { Op1( 0), CRn( 9), CRm(14), Op2( 2), access_pminten }, 1906 2020 { Op1( 0), CRn( 9), CRm(14), Op2( 3), access_pmovs }, 1907 2021 1908 - { Op1( 0), CRn(10), CRm( 2), Op2( 0), access_vm_reg, NULL, c10_PRRR }, 1909 - { Op1( 0), CRn(10), CRm( 2), Op2( 1), access_vm_reg, NULL, c10_NMRR }, 1910 - { Op1( 0), CRn(10), CRm( 3), Op2( 0), access_vm_reg, NULL, c10_AMAIR0 }, 1911 - { Op1( 0), CRn(10), CRm( 3), Op2( 1), access_vm_reg, NULL, c10_AMAIR1 }, 2022 + /* PRRR/MAIR0 */ 2023 + { AA32(LO), Op1( 0), CRn(10), CRm( 2), Op2( 0), access_vm_reg, NULL, MAIR_EL1 }, 2024 + /* NMRR/MAIR1 */ 2025 + { AA32(HI), Op1( 0), CRn(10), CRm( 2), Op2( 1), access_vm_reg, NULL, MAIR_EL1 }, 2026 + /* AMAIR0 */ 2027 + { AA32(LO), Op1( 0), CRn(10), CRm( 3), Op2( 0), access_vm_reg, NULL, AMAIR_EL1 }, 2028 + /* AMAIR1 */ 2029 + { AA32(HI), Op1( 0), CRn(10), CRm( 3), Op2( 1), access_vm_reg, NULL, AMAIR_EL1 }, 1912 2030 1913 2031 /* ICC_SRE */ 1914 2032 { Op1( 0), CRn(12), CRm(12), Op2( 5), access_gic_sre }, 1915 2033 1916 - { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, c13_CID }, 2034 + { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, CONTEXTIDR_EL1 }, 1917 2035 1918 2036 /* Arch Tmers */ 1919 2037 { SYS_DESC(SYS_AARCH32_CNTP_TVAL), access_arch_timer }, ··· 1992 2102 1993 2103 { Op1(1), CRn( 0), CRm( 0), Op2(0), access_ccsidr }, 1994 2104 { Op1(1), CRn( 0), CRm( 0), Op2(1), access_clidr }, 1995 - { Op1(2), CRn( 0), CRm( 0), Op2(0), access_csselr, NULL, c0_CSSELR }, 2105 + { Op1(2), CRn( 0), CRm( 0), Op2(0), access_csselr, NULL, CSSELR_EL1 }, 1996 2106 }; 1997 2107 1998 2108 static const struct sys_reg_desc cp15_64_regs[] = { 1999 - { Op1( 0), CRn( 0), CRm( 2), Op2( 0), access_vm_reg, NULL, c2_TTBR0 }, 2109 + { Op1( 0), CRn( 0), CRm( 2), Op2( 0), access_vm_reg, NULL, TTBR0_EL1 }, 2000 2110 { Op1( 0), CRn( 0), CRm( 9), Op2( 0), access_pmu_evcntr }, 2001 2111 { Op1( 0), CRn( 0), CRm(12), Op2( 0), access_gic_sgi }, /* ICC_SGI1R */ 2002 - { Op1( 1), CRn( 0), CRm( 2), Op2( 0), access_vm_reg, NULL, c2_TTBR1 }, 2112 + { Op1( 1), CRn( 0), CRm( 2), Op2( 0), access_vm_reg, NULL, TTBR1_EL1 }, 2003 2113 { Op1( 1), CRn( 0), CRm(12), Op2( 0), access_gic_sgi }, /* ICC_ASGI1R */ 2004 2114 { Op1( 2), CRn( 0), CRm(12), Op2( 0), access_gic_sgi }, /* ICC_SGI0R */ 2005 2115 { SYS_DESC(SYS_AARCH32_CNTP_CVAL), access_arch_timer }, ··· 2070 2180 2071 2181 /* Skip instruction if instructed so */ 2072 2182 if (likely(r->access(vcpu, params, r))) 2073 - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); 2183 + kvm_incr_pc(vcpu); 2074 2184 } 2075 2185 2076 2186 /* ··· 2143 2253 int Rt = kvm_vcpu_sys_get_rt(vcpu); 2144 2254 int Rt2 = (esr >> 10) & 0x1f; 2145 2255 2146 - params.is_aarch32 = true; 2147 - params.is_32bit = false; 2148 2256 params.CRm = (esr >> 1) & 0xf; 2149 2257 params.is_write = ((esr & 1) == 0); 2150 2258 ··· 2192 2304 u32 esr = kvm_vcpu_get_esr(vcpu); 2193 2305 int Rt = kvm_vcpu_sys_get_rt(vcpu); 2194 2306 2195 - params.is_aarch32 = true; 2196 - params.is_32bit = true; 2197 2307 params.CRm = (esr >> 1) & 0xf; 2198 2308 params.regval = vcpu_get_reg(vcpu, Rt); 2199 2309 params.is_write = ((esr & 1) == 0); ··· 2285 2399 2286 2400 trace_kvm_handle_sys_reg(esr); 2287 2401 2288 - params.is_aarch32 = false; 2289 - params.is_32bit = false; 2290 2402 params.Op0 = (esr >> 20) & 3; 2291 2403 params.Op1 = (esr >> 14) & 0x7; 2292 2404 params.CRn = (esr >> 10) & 0xf;
+7 -2
arch/arm64/kvm/sys_regs.h
··· 19 19 u8 Op2; 20 20 u64 regval; 21 21 bool is_write; 22 - bool is_aarch32; 23 - bool is_32bit; /* Only valid if is_aarch32 is true */ 24 22 }; 25 23 26 24 struct sys_reg_desc { 27 25 /* Sysreg string for debug */ 28 26 const char *name; 27 + 28 + enum { 29 + AA32_ZEROHIGH, 30 + AA32_LO, 31 + AA32_HI, 32 + } aarch32_map; 29 33 30 34 /* MRS/MSR instruction which accesses it. */ 31 35 u8 Op0; ··· 157 153 const struct sys_reg_desc table[], 158 154 unsigned int num); 159 155 156 + #define AA32(_x) .aarch32_map = AA32_##_x 160 157 #define Op0(_x) .Op0 = _x 161 158 #define Op1(_x) .Op1 = _x 162 159 #define CRn(_x) .CRn = _x
+85 -19
arch/arm64/kvm/va_layout.c
··· 11 11 #include <asm/debug-monitors.h> 12 12 #include <asm/insn.h> 13 13 #include <asm/kvm_mmu.h> 14 + #include <asm/memory.h> 14 15 15 16 /* 16 17 * The LSB of the HYP VA tag ··· 22 21 */ 23 22 static u64 tag_val; 24 23 static u64 va_mask; 24 + 25 + /* 26 + * Compute HYP VA by using the same computation as kern_hyp_va(). 27 + */ 28 + static u64 __early_kern_hyp_va(u64 addr) 29 + { 30 + addr &= va_mask; 31 + addr |= tag_val << tag_lsb; 32 + return addr; 33 + } 34 + 35 + /* 36 + * Store a hyp VA <-> PA offset into a hyp-owned variable. 37 + */ 38 + static void init_hyp_physvirt_offset(void) 39 + { 40 + extern s64 kvm_nvhe_sym(hyp_physvirt_offset); 41 + u64 kern_va, hyp_va; 42 + 43 + /* Compute the offset from the hyp VA and PA of a random symbol. */ 44 + kern_va = (u64)kvm_ksym_ref(__hyp_text_start); 45 + hyp_va = __early_kern_hyp_va(kern_va); 46 + CHOOSE_NVHE_SYM(hyp_physvirt_offset) = (s64)__pa(kern_va) - (s64)hyp_va; 47 + } 25 48 26 49 /* 27 50 * We want to generate a hyp VA with the following format (with V == ··· 78 53 tag_val |= get_random_long() & GENMASK_ULL(vabits_actual - 2, tag_lsb); 79 54 } 80 55 tag_val >>= tag_lsb; 56 + 57 + init_hyp_physvirt_offset(); 81 58 } 82 59 83 60 static u32 compute_instruction(int n, u32 rd, u32 rn) ··· 158 131 } 159 132 } 160 133 161 - void *__kvm_bp_vect_base; 162 - int __kvm_harden_el2_vector_slot; 163 - 164 134 void kvm_patch_vector_branch(struct alt_instr *alt, 165 135 __le32 *origptr, __le32 *updptr, int nr_inst) 166 136 { 167 137 u64 addr; 168 138 u32 insn; 169 139 170 - BUG_ON(nr_inst != 5); 140 + BUG_ON(nr_inst != 4); 171 141 172 - if (has_vhe() || !cpus_have_const_cap(ARM64_HARDEN_EL2_VECTORS)) { 173 - WARN_ON_ONCE(cpus_have_const_cap(ARM64_HARDEN_EL2_VECTORS)); 142 + if (!cpus_have_const_cap(ARM64_SPECTRE_V3A) || WARN_ON_ONCE(has_vhe())) 174 143 return; 175 - } 176 144 177 145 /* 178 146 * Compute HYP VA by using the same computation as kern_hyp_va() 179 147 */ 180 - addr = (uintptr_t)kvm_ksym_ref(__kvm_hyp_vector); 181 - addr &= va_mask; 182 - addr |= tag_val << tag_lsb; 148 + addr = __early_kern_hyp_va((u64)kvm_ksym_ref(__kvm_hyp_vector)); 183 149 184 150 /* Use PC[10:7] to branch to the same vector in KVM */ 185 151 addr |= ((u64)origptr & GENMASK_ULL(10, 7)); ··· 182 162 * the stack (which we already perform in the hardening vectors). 183 163 */ 184 164 addr += KVM_VECTOR_PREAMBLE; 185 - 186 - /* stp x0, x1, [sp, #-16]! */ 187 - insn = aarch64_insn_gen_load_store_pair(AARCH64_INSN_REG_0, 188 - AARCH64_INSN_REG_1, 189 - AARCH64_INSN_REG_SP, 190 - -16, 191 - AARCH64_INSN_VARIANT_64BIT, 192 - AARCH64_INSN_LDST_STORE_PAIR_PRE_INDEX); 193 - *updptr++ = cpu_to_le32(insn); 194 165 195 166 /* movz x0, #(addr & 0xffff) */ 196 167 insn = aarch64_insn_gen_movewide(AARCH64_INSN_REG_0, ··· 211 200 insn = aarch64_insn_gen_branch_reg(AARCH64_INSN_REG_0, 212 201 AARCH64_INSN_BRANCH_NOLINK); 213 202 *updptr++ = cpu_to_le32(insn); 203 + } 204 + 205 + static void generate_mov_q(u64 val, __le32 *origptr, __le32 *updptr, int nr_inst) 206 + { 207 + u32 insn, oinsn, rd; 208 + 209 + BUG_ON(nr_inst != 4); 210 + 211 + /* Compute target register */ 212 + oinsn = le32_to_cpu(*origptr); 213 + rd = aarch64_insn_decode_register(AARCH64_INSN_REGTYPE_RD, oinsn); 214 + 215 + /* movz rd, #(val & 0xffff) */ 216 + insn = aarch64_insn_gen_movewide(rd, 217 + (u16)val, 218 + 0, 219 + AARCH64_INSN_VARIANT_64BIT, 220 + AARCH64_INSN_MOVEWIDE_ZERO); 221 + *updptr++ = cpu_to_le32(insn); 222 + 223 + /* movk rd, #((val >> 16) & 0xffff), lsl #16 */ 224 + insn = aarch64_insn_gen_movewide(rd, 225 + (u16)(val >> 16), 226 + 16, 227 + AARCH64_INSN_VARIANT_64BIT, 228 + AARCH64_INSN_MOVEWIDE_KEEP); 229 + *updptr++ = cpu_to_le32(insn); 230 + 231 + /* movk rd, #((val >> 32) & 0xffff), lsl #32 */ 232 + insn = aarch64_insn_gen_movewide(rd, 233 + (u16)(val >> 32), 234 + 32, 235 + AARCH64_INSN_VARIANT_64BIT, 236 + AARCH64_INSN_MOVEWIDE_KEEP); 237 + *updptr++ = cpu_to_le32(insn); 238 + 239 + /* movk rd, #((val >> 48) & 0xffff), lsl #48 */ 240 + insn = aarch64_insn_gen_movewide(rd, 241 + (u16)(val >> 48), 242 + 48, 243 + AARCH64_INSN_VARIANT_64BIT, 244 + AARCH64_INSN_MOVEWIDE_KEEP); 245 + *updptr++ = cpu_to_le32(insn); 246 + } 247 + 248 + void kvm_update_kimg_phys_offset(struct alt_instr *alt, 249 + __le32 *origptr, __le32 *updptr, int nr_inst) 250 + { 251 + generate_mov_q(kimage_voffset + PHYS_OFFSET, origptr, updptr, nr_inst); 252 + } 253 + 254 + void kvm_get_kimage_voffset(struct alt_instr *alt, 255 + __le32 *origptr, __le32 *updptr, int nr_inst) 256 + { 257 + generate_mov_q(kimage_voffset, origptr, updptr, nr_inst); 214 258 }
-4
arch/arm64/kvm/vgic-sys-reg-v3.c
··· 268 268 269 269 params.regval = *reg; 270 270 params.is_write = is_write; 271 - params.is_aarch32 = false; 272 - params.is_32bit = false; 273 271 274 272 if (find_reg_by_id(sysreg, &params, gic_v3_icc_reg_descs, 275 273 ARRAY_SIZE(gic_v3_icc_reg_descs))) ··· 286 288 if (is_write) 287 289 params.regval = *reg; 288 290 params.is_write = is_write; 289 - params.is_aarch32 = false; 290 - params.is_32bit = false; 291 291 292 292 r = find_reg_by_id(sysreg, &params, gic_v3_icc_reg_descs, 293 293 ARRAY_SIZE(gic_v3_icc_reg_descs));
+12
arch/arm64/kvm/vgic/vgic-v4.c
··· 353 353 return err; 354 354 } 355 355 356 + void vgic_v4_commit(struct kvm_vcpu *vcpu) 357 + { 358 + struct its_vpe *vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe; 359 + 360 + /* 361 + * No need to wait for the vPE to be ready across a shallow guest 362 + * exit, as only a vcpu_put will invalidate it. 363 + */ 364 + if (!vpe->ready) 365 + its_commit_vpe(vpe); 366 + } 367 + 356 368 static struct vgic_its *vgic_get_its(struct kvm *kvm, 357 369 struct kvm_kernel_irq_routing_entry *irq_entry) 358 370 {
+3
arch/arm64/kvm/vgic/vgic.c
··· 915 915 916 916 if (can_access_vgic_from_kernel()) 917 917 vgic_restore_state(vcpu); 918 + 919 + if (vgic_supports_direct_msis(vcpu->kvm)) 920 + vgic_v4_commit(vcpu); 918 921 } 919 922 920 923 void kvm_vgic_load(struct kvm_vcpu *vcpu)
+4 -4
arch/arm64/lib/clear_user.S
··· 24 24 subs x1, x1, #8 25 25 b.mi 2f 26 26 1: 27 - uao_user_alternative 9f, str, sttr, xzr, x0, 8 27 + user_ldst 9f, sttr, xzr, x0, 8 28 28 subs x1, x1, #8 29 29 b.pl 1b 30 30 2: adds x1, x1, #4 31 31 b.mi 3f 32 - uao_user_alternative 9f, str, sttr, wzr, x0, 4 32 + user_ldst 9f, sttr, wzr, x0, 4 33 33 sub x1, x1, #4 34 34 3: adds x1, x1, #2 35 35 b.mi 4f 36 - uao_user_alternative 9f, strh, sttrh, wzr, x0, 2 36 + user_ldst 9f, sttrh, wzr, x0, 2 37 37 sub x1, x1, #2 38 38 4: adds x1, x1, #1 39 39 b.mi 5f 40 - uao_user_alternative 9f, strb, sttrb, wzr, x0, 0 40 + user_ldst 9f, sttrb, wzr, x0, 0 41 41 5: mov x0, #0 42 42 ret 43 43 SYM_FUNC_END(__arch_clear_user)
+4 -4
arch/arm64/lib/copy_from_user.S
··· 21 21 */ 22 22 23 23 .macro ldrb1 reg, ptr, val 24 - uao_user_alternative 9998f, ldrb, ldtrb, \reg, \ptr, \val 24 + user_ldst 9998f, ldtrb, \reg, \ptr, \val 25 25 .endm 26 26 27 27 .macro strb1 reg, ptr, val ··· 29 29 .endm 30 30 31 31 .macro ldrh1 reg, ptr, val 32 - uao_user_alternative 9998f, ldrh, ldtrh, \reg, \ptr, \val 32 + user_ldst 9998f, ldtrh, \reg, \ptr, \val 33 33 .endm 34 34 35 35 .macro strh1 reg, ptr, val ··· 37 37 .endm 38 38 39 39 .macro ldr1 reg, ptr, val 40 - uao_user_alternative 9998f, ldr, ldtr, \reg, \ptr, \val 40 + user_ldst 9998f, ldtr, \reg, \ptr, \val 41 41 .endm 42 42 43 43 .macro str1 reg, ptr, val ··· 45 45 .endm 46 46 47 47 .macro ldp1 reg1, reg2, ptr, val 48 - uao_ldp 9998f, \reg1, \reg2, \ptr, \val 48 + user_ldp 9998f, \reg1, \reg2, \ptr, \val 49 49 .endm 50 50 51 51 .macro stp1 reg1, reg2, ptr, val
+8 -8
arch/arm64/lib/copy_in_user.S
··· 22 22 * x0 - bytes not copied 23 23 */ 24 24 .macro ldrb1 reg, ptr, val 25 - uao_user_alternative 9998f, ldrb, ldtrb, \reg, \ptr, \val 25 + user_ldst 9998f, ldtrb, \reg, \ptr, \val 26 26 .endm 27 27 28 28 .macro strb1 reg, ptr, val 29 - uao_user_alternative 9998f, strb, sttrb, \reg, \ptr, \val 29 + user_ldst 9998f, sttrb, \reg, \ptr, \val 30 30 .endm 31 31 32 32 .macro ldrh1 reg, ptr, val 33 - uao_user_alternative 9998f, ldrh, ldtrh, \reg, \ptr, \val 33 + user_ldst 9998f, ldtrh, \reg, \ptr, \val 34 34 .endm 35 35 36 36 .macro strh1 reg, ptr, val 37 - uao_user_alternative 9998f, strh, sttrh, \reg, \ptr, \val 37 + user_ldst 9998f, sttrh, \reg, \ptr, \val 38 38 .endm 39 39 40 40 .macro ldr1 reg, ptr, val 41 - uao_user_alternative 9998f, ldr, ldtr, \reg, \ptr, \val 41 + user_ldst 9998f, ldtr, \reg, \ptr, \val 42 42 .endm 43 43 44 44 .macro str1 reg, ptr, val 45 - uao_user_alternative 9998f, str, sttr, \reg, \ptr, \val 45 + user_ldst 9998f, sttr, \reg, \ptr, \val 46 46 .endm 47 47 48 48 .macro ldp1 reg1, reg2, ptr, val 49 - uao_ldp 9998f, \reg1, \reg2, \ptr, \val 49 + user_ldp 9998f, \reg1, \reg2, \ptr, \val 50 50 .endm 51 51 52 52 .macro stp1 reg1, reg2, ptr, val 53 - uao_stp 9998f, \reg1, \reg2, \ptr, \val 53 + user_stp 9998f, \reg1, \reg2, \ptr, \val 54 54 .endm 55 55 56 56 end .req x5
+4 -4
arch/arm64/lib/copy_to_user.S
··· 24 24 .endm 25 25 26 26 .macro strb1 reg, ptr, val 27 - uao_user_alternative 9998f, strb, sttrb, \reg, \ptr, \val 27 + user_ldst 9998f, sttrb, \reg, \ptr, \val 28 28 .endm 29 29 30 30 .macro ldrh1 reg, ptr, val ··· 32 32 .endm 33 33 34 34 .macro strh1 reg, ptr, val 35 - uao_user_alternative 9998f, strh, sttrh, \reg, \ptr, \val 35 + user_ldst 9998f, sttrh, \reg, \ptr, \val 36 36 .endm 37 37 38 38 .macro ldr1 reg, ptr, val ··· 40 40 .endm 41 41 42 42 .macro str1 reg, ptr, val 43 - uao_user_alternative 9998f, str, sttr, \reg, \ptr, \val 43 + user_ldst 9998f, sttr, \reg, \ptr, \val 44 44 .endm 45 45 46 46 .macro ldp1 reg1, reg2, ptr, val ··· 48 48 .endm 49 49 50 50 .macro stp1 reg1, reg2, ptr, val 51 - uao_stp 9998f, \reg1, \reg2, \ptr, \val 51 + user_stp 9998f, \reg1, \reg2, \ptr, \val 52 52 .endm 53 53 54 54 end .req x5
+3 -3
arch/arm64/lib/mte.S
··· 4 4 */ 5 5 #include <linux/linkage.h> 6 6 7 - #include <asm/alternative.h> 7 + #include <asm/asm-uaccess.h> 8 8 #include <asm/assembler.h> 9 9 #include <asm/mte.h> 10 10 #include <asm/page.h> ··· 67 67 mov x3, x1 68 68 cbz x2, 2f 69 69 1: 70 - uao_user_alternative 2f, ldrb, ldtrb, w4, x1, 0 70 + user_ldst 2f, ldtrb, w4, x1, 0 71 71 lsl x4, x4, #MTE_TAG_SHIFT 72 72 stg x4, [x0], #MTE_GRANULE_SIZE 73 73 add x1, x1, #1 ··· 94 94 1: 95 95 ldg x4, [x1] 96 96 ubfx x4, x4, #MTE_TAG_SHIFT, #MTE_TAG_SIZE 97 - uao_user_alternative 2f, strb, sttrb, w4, x0, 0 97 + user_ldst 2f, sttrb, w4, x0, 0 98 98 add x0, x0, #1 99 99 add x1, x1, #MTE_GRANULE_SIZE 100 100 subs x2, x2, #1
+1 -3
arch/arm64/lib/uaccess_flushcache.c
··· 30 30 { 31 31 unsigned long rc; 32 32 33 - uaccess_enable_not_uao(); 34 - rc = __arch_copy_from_user(to, from, n); 35 - uaccess_disable_not_uao(); 33 + rc = raw_copy_from_user(to, from, n); 36 34 37 35 /* See above */ 38 36 __clean_dcache_area_pop(to, n - rc);
-5
arch/arm64/mm/fault.c
··· 479 479 } 480 480 481 481 if (is_ttbr0_addr(addr) && is_el1_permission_fault(addr, esr, regs)) { 482 - /* regs->orig_addr_limit may be 0 if we entered from EL0 */ 483 - if (regs->orig_addr_limit == KERNEL_DS) 484 - die_kernel_fault("access to user memory with fs=KERNEL_DS", 485 - addr, esr, regs); 486 - 487 482 if (is_el1_instruction_abort(esr)) 488 483 die_kernel_fault("execution of user memory", 489 484 addr, esr, regs);
+17
arch/arm64/mm/mmu.c
··· 1444 1444 free_empty_tables(start, end, PAGE_OFFSET, PAGE_END); 1445 1445 } 1446 1446 1447 + static bool inside_linear_region(u64 start, u64 size) 1448 + { 1449 + /* 1450 + * Linear mapping region is the range [PAGE_OFFSET..(PAGE_END - 1)] 1451 + * accommodating both its ends but excluding PAGE_END. Max physical 1452 + * range which can be mapped inside this linear mapping range, must 1453 + * also be derived from its end points. 1454 + */ 1455 + return start >= __pa(_PAGE_OFFSET(vabits_actual)) && 1456 + (start + size - 1) <= __pa(PAGE_END - 1); 1457 + } 1458 + 1447 1459 int arch_add_memory(int nid, u64 start, u64 size, 1448 1460 struct mhp_params *params) 1449 1461 { 1450 1462 int ret, flags = 0; 1463 + 1464 + if (!inside_linear_region(start, size)) { 1465 + pr_err("[%llx %llx] is outside linear mapping region\n", start, start + size); 1466 + return -EINVAL; 1467 + } 1451 1468 1452 1469 if (rodata_full || debug_pagealloc_enabled()) 1453 1470 flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
+1 -1
arch/arm64/mm/proc.S
··· 489 489 /* 490 490 * Prepare SCTLR 491 491 */ 492 - mov_q x0, SCTLR_EL1_SET 492 + mov_q x0, INIT_SCTLR_EL1_MMU_ON 493 493 ret // return to head.S 494 494 SYM_FUNC_END(__cpu_setup)
+1 -2
arch/csky/kernel/perf_regs.c
··· 32 32 } 33 33 34 34 void perf_get_regs_user(struct perf_regs *regs_user, 35 - struct pt_regs *regs, 36 - struct pt_regs *regs_user_copy) 35 + struct pt_regs *regs) 37 36 { 38 37 regs_user->regs = task_pt_regs(current); 39 38 regs_user->abi = perf_reg_abi(current);
+1 -1
arch/powerpc/perf/imc-pmu.c
··· 1336 1336 /* If this is a valid record, create the sample */ 1337 1337 struct perf_output_handle handle; 1338 1338 1339 - if (perf_output_begin(&handle, event, header.size)) 1339 + if (perf_output_begin(&handle, &data, event, header.size)) 1340 1340 return; 1341 1341 1342 1342 perf_output_sample(&handle, &header, &data, event);
+1 -2
arch/powerpc/perf/perf_regs.c
··· 144 144 } 145 145 146 146 void perf_get_regs_user(struct perf_regs *regs_user, 147 - struct pt_regs *regs, 148 - struct pt_regs *regs_user_copy) 147 + struct pt_regs *regs) 149 148 { 150 149 regs_user->regs = task_pt_regs(current); 151 150 regs_user->abi = (regs_user->regs) ? perf_reg_abi(current) :
+1 -2
arch/riscv/kernel/perf_regs.c
··· 36 36 } 37 37 38 38 void perf_get_regs_user(struct perf_regs *regs_user, 39 - struct pt_regs *regs, 40 - struct pt_regs *regs_user_copy) 39 + struct pt_regs *regs) 41 40 { 42 41 regs_user->regs = task_pt_regs(current); 43 42 regs_user->abi = perf_reg_abi(current);
+1 -1
arch/s390/kernel/perf_cpum_sf.c
··· 672 672 rcu_read_lock(); 673 673 674 674 perf_prepare_sample(&header, data, event, regs); 675 - if (perf_output_begin(&handle, event, header.size)) 675 + if (perf_output_begin(&handle, data, event, header.size)) 676 676 goto out; 677 677 678 678 /* Update the process ID (see also kernel/events/core.c) */
+1 -2
arch/s390/kernel/perf_regs.c
··· 53 53 } 54 54 55 55 void perf_get_regs_user(struct perf_regs *regs_user, 56 - struct pt_regs *regs, 57 - struct pt_regs *regs_user_copy) 56 + struct pt_regs *regs) 58 57 { 59 58 /* 60 59 * Use the regs from the first interruption and let
+7 -1
arch/um/include/asm/pgalloc.h
··· 33 33 } while (0) 34 34 35 35 #ifdef CONFIG_3_LEVEL_PGTABLES 36 - #define __pmd_free_tlb(tlb,x, address) tlb_remove_page((tlb),virt_to_page(x)) 36 + 37 + #define __pmd_free_tlb(tlb, pmd, address) \ 38 + do { \ 39 + pgtable_pmd_page_dtor(virt_to_page(pmd)); \ 40 + tlb_remove_page((tlb),virt_to_page(pmd)); \ 41 + } while (0) \ 42 + 37 43 #endif 38 44 39 45 #endif
+11 -1
arch/x86/events/intel/core.c
··· 2630 2630 u64 pebs_enabled = cpuc->pebs_enabled; 2631 2631 2632 2632 handled++; 2633 - x86_pmu.drain_pebs(regs); 2633 + x86_pmu.drain_pebs(regs, &data); 2634 2634 status &= x86_pmu.intel_ctrl | GLOBAL_STATUS_TRACE_TOPAPMI; 2635 2635 2636 2636 /* ··· 4987 4987 4988 4988 x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */ 4989 4989 4990 + if (version >= 5) { 4991 + x86_pmu.intel_cap.anythread_deprecated = edx.split.anythread_deprecated; 4992 + if (x86_pmu.intel_cap.anythread_deprecated) 4993 + pr_cont(" AnyThread deprecated, "); 4994 + } 4995 + 4990 4996 /* 4991 4997 * Install the hw-cache-events table: 4992 4998 */ ··· 5517 5511 5518 5512 x86_pmu.intel_ctrl |= 5519 5513 ((1LL << x86_pmu.num_counters_fixed)-1) << INTEL_PMC_IDX_FIXED; 5514 + 5515 + /* AnyThread may be deprecated on arch perfmon v5 or later */ 5516 + if (x86_pmu.intel_cap.anythread_deprecated) 5517 + x86_pmu.format_attrs = intel_arch_formats_attr; 5520 5518 5521 5519 if (x86_pmu.event_constraints) { 5522 5520 /*
+28 -25
arch/x86/events/intel/ds.c
··· 642 642 rcu_read_lock(); 643 643 perf_prepare_sample(&header, &data, event, &regs); 644 644 645 - if (perf_output_begin(&handle, event, header.size * 646 - (top - base - skip))) 645 + if (perf_output_begin(&handle, &data, event, 646 + header.size * (top - base - skip))) 647 647 goto unlock; 648 648 649 649 for (at = base; at < top; at++) { ··· 670 670 671 671 static inline void intel_pmu_drain_pebs_buffer(void) 672 672 { 673 - x86_pmu.drain_pebs(NULL); 673 + struct perf_sample_data data; 674 + 675 + x86_pmu.drain_pebs(NULL, &data); 674 676 } 675 677 676 678 /* ··· 1721 1719 return 0; 1722 1720 } 1723 1721 1724 - static void __intel_pmu_pebs_event(struct perf_event *event, 1725 - struct pt_regs *iregs, 1726 - void *base, void *top, 1727 - int bit, int count, 1728 - void (*setup_sample)(struct perf_event *, 1729 - struct pt_regs *, 1730 - void *, 1731 - struct perf_sample_data *, 1732 - struct pt_regs *)) 1722 + static __always_inline void 1723 + __intel_pmu_pebs_event(struct perf_event *event, 1724 + struct pt_regs *iregs, 1725 + struct perf_sample_data *data, 1726 + void *base, void *top, 1727 + int bit, int count, 1728 + void (*setup_sample)(struct perf_event *, 1729 + struct pt_regs *, 1730 + void *, 1731 + struct perf_sample_data *, 1732 + struct pt_regs *)) 1733 1733 { 1734 1734 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); 1735 1735 struct hw_perf_event *hwc = &event->hw; 1736 - struct perf_sample_data data; 1737 1736 struct x86_perf_regs perf_regs; 1738 1737 struct pt_regs *regs = &perf_regs.regs; 1739 1738 void *at = get_next_pebs_record_by_bit(base, top, bit); 1740 - struct pt_regs dummy_iregs; 1739 + static struct pt_regs dummy_iregs; 1741 1740 1742 1741 if (hwc->flags & PERF_X86_EVENT_AUTO_RELOAD) { 1743 1742 /* ··· 1755 1752 iregs = &dummy_iregs; 1756 1753 1757 1754 while (count > 1) { 1758 - setup_sample(event, iregs, at, &data, regs); 1759 - perf_event_output(event, &data, regs); 1755 + setup_sample(event, iregs, at, data, regs); 1756 + perf_event_output(event, data, regs); 1760 1757 at += cpuc->pebs_record_size; 1761 1758 at = get_next_pebs_record_by_bit(at, top, bit); 1762 1759 count--; 1763 1760 } 1764 1761 1765 - setup_sample(event, iregs, at, &data, regs); 1762 + setup_sample(event, iregs, at, data, regs); 1766 1763 if (iregs == &dummy_iregs) { 1767 1764 /* 1768 1765 * The PEBS records may be drained in the non-overflow context, ··· 1770 1767 * last record the same as other PEBS records, and doesn't 1771 1768 * invoke the generic overflow handler. 1772 1769 */ 1773 - perf_event_output(event, &data, regs); 1770 + perf_event_output(event, data, regs); 1774 1771 } else { 1775 1772 /* 1776 1773 * All but the last records are processed. 1777 1774 * The last one is left to be able to call the overflow handler. 1778 1775 */ 1779 - if (perf_event_overflow(event, &data, regs)) 1776 + if (perf_event_overflow(event, data, regs)) 1780 1777 x86_pmu_stop(event, 0); 1781 1778 } 1782 1779 } 1783 1780 1784 - static void intel_pmu_drain_pebs_core(struct pt_regs *iregs) 1781 + static void intel_pmu_drain_pebs_core(struct pt_regs *iregs, struct perf_sample_data *data) 1785 1782 { 1786 1783 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); 1787 1784 struct debug_store *ds = cpuc->ds; ··· 1815 1812 return; 1816 1813 } 1817 1814 1818 - __intel_pmu_pebs_event(event, iregs, at, top, 0, n, 1815 + __intel_pmu_pebs_event(event, iregs, data, at, top, 0, n, 1819 1816 setup_pebs_fixed_sample_data); 1820 1817 } 1821 1818 ··· 1838 1835 } 1839 1836 } 1840 1837 1841 - static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs) 1838 + static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_data *data) 1842 1839 { 1843 1840 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); 1844 1841 struct debug_store *ds = cpuc->ds; ··· 1945 1942 } 1946 1943 1947 1944 if (counts[bit]) { 1948 - __intel_pmu_pebs_event(event, iregs, base, 1945 + __intel_pmu_pebs_event(event, iregs, data, base, 1949 1946 top, bit, counts[bit], 1950 1947 setup_pebs_fixed_sample_data); 1951 1948 } 1952 1949 } 1953 1950 } 1954 1951 1955 - static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs) 1952 + static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs, struct perf_sample_data *data) 1956 1953 { 1957 1954 short counts[INTEL_PMC_IDX_FIXED + MAX_FIXED_PEBS_EVENTS] = {}; 1958 1955 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); ··· 2000 1997 if (WARN_ON_ONCE(!event->attr.precise_ip)) 2001 1998 continue; 2002 1999 2003 - __intel_pmu_pebs_event(event, iregs, base, 2000 + __intel_pmu_pebs_event(event, iregs, data, base, 2004 2001 top, bit, counts[bit], 2005 2002 setup_pebs_adaptive_sample_data); 2006 2003 }
+1 -1
arch/x86/events/intel/uncore_snb.c
··· 475 475 static struct freerunning_counters snb_uncore_imc_freerunning[] = { 476 476 [SNB_PCI_UNCORE_IMC_DATA_READS] = { SNB_UNCORE_PCI_IMC_DATA_READS_BASE, 477 477 0x0, 0x0, 1, 32 }, 478 - [SNB_PCI_UNCORE_IMC_DATA_READS] = { SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE, 478 + [SNB_PCI_UNCORE_IMC_DATA_WRITES] = { SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE, 479 479 0x0, 0x0, 1, 32 }, 480 480 [SNB_PCI_UNCORE_IMC_GT_REQUESTS] = { SNB_UNCORE_PCI_IMC_GT_REQUESTS_BASE, 481 481 0x0, 0x0, 1, 32 },
+2 -1
arch/x86/events/perf_event.h
··· 585 585 u64 pebs_baseline:1; 586 586 u64 perf_metrics:1; 587 587 u64 pebs_output_pt_available:1; 588 + u64 anythread_deprecated:1; 588 589 }; 589 590 u64 capabilities; 590 591 }; ··· 728 727 int pebs_record_size; 729 728 int pebs_buffer_size; 730 729 int max_pebs_events; 731 - void (*drain_pebs)(struct pt_regs *regs); 730 + void (*drain_pebs)(struct pt_regs *regs, struct perf_sample_data *data); 732 731 struct event_constraint *pebs_constraints; 733 732 void (*pebs_aliases)(struct perf_event *event); 734 733 unsigned long large_pebs_flags;
+3 -1
arch/x86/include/asm/perf_event.h
··· 137 137 struct { 138 138 unsigned int num_counters_fixed:5; 139 139 unsigned int bit_width_fixed:8; 140 - unsigned int reserved:19; 140 + unsigned int reserved1:2; 141 + unsigned int anythread_deprecated:1; 142 + unsigned int reserved2:16; 141 143 } split; 142 144 unsigned int full; 143 145 };
-10
arch/x86/include/asm/uv/uv.h
··· 2 2 #ifndef _ASM_X86_UV_UV_H 3 3 #define _ASM_X86_UV_UV_H 4 4 5 - #include <asm/tlbflush.h> 6 - 7 5 enum uv_system_type {UV_NONE, UV_LEGACY_APIC, UV_X2APIC}; 8 - 9 - struct cpumask; 10 - struct mm_struct; 11 - struct flush_tlb_info; 12 6 13 7 #ifdef CONFIG_X86_UV 14 8 #include <linux/efi.h> ··· 38 44 static inline int is_uv_hubbed(int uv) { return 0; } 39 45 static inline void uv_cpu_init(void) { } 40 46 static inline void uv_system_init(void) { } 41 - static inline const struct cpumask * 42 - uv_flush_tlb_others(const struct cpumask *cpumask, 43 - const struct flush_tlb_info *info) 44 - { return cpumask; } 45 47 46 48 #endif /* X86_UV */ 47 49
+3 -3
arch/x86/kernel/apic/x2apic_uv_x.c
··· 33 33 static int uv_node_id; 34 34 35 35 /* Unpack AT/OEM/TABLE ID's to be NULL terminated strings */ 36 - static u8 uv_archtype[UV_AT_SIZE]; 36 + static u8 uv_archtype[UV_AT_SIZE + 1]; 37 37 static u8 oem_id[ACPI_OEM_ID_SIZE + 1]; 38 38 static u8 oem_table_id[ACPI_OEM_TABLE_ID_SIZE + 1]; 39 39 ··· 320 320 321 321 if (n > 0 && n < sizeof(uv_ate->archtype)) { 322 322 pr_info("UV: UVarchtype received from BIOS\n"); 323 - uv_stringify(UV_AT_SIZE, uv_archtype, uv_ate->archtype); 323 + uv_stringify(sizeof(uv_archtype), uv_archtype, uv_ate->archtype); 324 324 return 1; 325 325 } 326 326 return 0; ··· 378 378 if (!early_get_arch_type()) 379 379 380 380 /* If not use OEM ID for UVarchtype */ 381 - uv_stringify(UV_AT_SIZE, uv_archtype, _oem_id); 381 + uv_stringify(sizeof(uv_archtype), uv_archtype, oem_id); 382 382 383 383 /* Check if not hubbed */ 384 384 if (strncmp(uv_archtype, "SGI", 3) != 0) {
+11 -4
arch/x86/kernel/perf_regs.c
··· 101 101 } 102 102 103 103 void perf_get_regs_user(struct perf_regs *regs_user, 104 - struct pt_regs *regs, 105 - struct pt_regs *regs_user_copy) 104 + struct pt_regs *regs) 106 105 { 107 106 regs_user->regs = task_pt_regs(current); 108 107 regs_user->abi = perf_reg_abi(current); ··· 128 129 return PERF_SAMPLE_REGS_ABI_64; 129 130 } 130 131 132 + static DEFINE_PER_CPU(struct pt_regs, nmi_user_regs); 133 + 131 134 void perf_get_regs_user(struct perf_regs *regs_user, 132 - struct pt_regs *regs, 133 - struct pt_regs *regs_user_copy) 135 + struct pt_regs *regs) 134 136 { 137 + struct pt_regs *regs_user_copy = this_cpu_ptr(&nmi_user_regs); 135 138 struct pt_regs *user_regs = task_pt_regs(current); 139 + 140 + if (!in_nmi()) { 141 + regs_user->regs = user_regs; 142 + regs_user->abi = perf_reg_abi(current); 143 + return; 144 + } 136 145 137 146 /* 138 147 * If we're in an NMI that interrupted task_pt_regs setup, then
+3 -1
arch/x86/kvm/cpuid.c
··· 684 684 685 685 edx.split.num_counters_fixed = min(cap.num_counters_fixed, MAX_FIXED_COUNTERS); 686 686 edx.split.bit_width_fixed = cap.bit_width_fixed; 687 - edx.split.reserved = 0; 687 + edx.split.anythread_deprecated = 1; 688 + edx.split.reserved1 = 0; 689 + edx.split.reserved2 = 0; 688 690 689 691 entry->eax = eax.full; 690 692 entry->ebx = cap.events_mask;
+4 -1
block/genhd.c
··· 49 49 * Set disk capacity and notify if the size is not currently 50 50 * zero and will not be set to zero 51 51 */ 52 - void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size, 52 + bool set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size, 53 53 bool update_bdev) 54 54 { 55 55 sector_t capacity = get_capacity(disk); ··· 62 62 char *envp[] = { "RESIZE=1", NULL }; 63 63 64 64 kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp); 65 + return true; 65 66 } 67 + 68 + return false; 66 69 } 67 70 68 71 EXPORT_SYMBOL_GPL(set_capacity_revalidate_and_notify);
-1
drivers/accessibility/speakup/main.c
··· 357 357 mark_cut_flag = 0; 358 358 synth_printf("%s\n", spk_msg_get(MSG_CUT)); 359 359 360 - speakup_clear_selection(); 361 360 ret = speakup_set_selection(tty); 362 361 363 362 switch (ret) {
+4 -7
drivers/accessibility/speakup/selection.c
··· 22 22 struct tty_struct *tty; 23 23 }; 24 24 25 - void speakup_clear_selection(void) 26 - { 27 - console_lock(); 28 - clear_selection(); 29 - console_unlock(); 30 - } 31 - 32 25 static void __speakup_set_selection(struct work_struct *work) 33 26 { 34 27 struct speakup_selection_work *ssw = ··· 43 50 pr_warn("Selection: mark console not the same as cut\n"); 44 51 goto unref; 45 52 } 53 + 54 + console_lock(); 55 + clear_selection(); 56 + console_unlock(); 46 57 47 58 set_selection_kernel(&sel, tty); 48 59
-1
drivers/accessibility/speakup/speakup.h
··· 70 70 void speakup_start_ttys(void); 71 71 void synth_buffer_add(u16 ch); 72 72 void synth_buffer_clear(void); 73 - void speakup_clear_selection(void); 74 73 int speakup_set_selection(struct tty_struct *tty); 75 74 void speakup_cancel_selection(void); 76 75 int speakup_paste_selection(struct tty_struct *tty);
+6 -4
drivers/accessibility/speakup/spk_ttyio.c
··· 298 298 struct spk_ldisc_data *ldisc_data = speakup_tty->disc_data; 299 299 char rv; 300 300 301 - if (wait_for_completion_timeout(&ldisc_data->completion, 301 + if (!timeout) { 302 + if (!try_wait_for_completion(&ldisc_data->completion)) 303 + return 0xff; 304 + } else if (wait_for_completion_timeout(&ldisc_data->completion, 302 305 usecs_to_jiffies(timeout)) == 0) { 303 - if (timeout) 304 - pr_warn("spk_ttyio: timeout (%d) while waiting for input\n", 305 - timeout); 306 + pr_warn("spk_ttyio: timeout (%d) while waiting for input\n", 307 + timeout); 306 308 return 0xff; 307 309 } 308 310
+6 -2
drivers/accessibility/speakup/spk_types.h
··· 32 32 E_NEW_DEFAULT, 33 33 }; 34 34 35 + /* 36 + * Note: add new members at the end, speakupmap.h depends on the values of the 37 + * enum starting from SPELL_DELAY (see inc_dec_var) 38 + */ 35 39 enum var_id_t { 36 40 VERSION = 0, SYNTH, SILENT, SYNTH_DIRECT, 37 41 KEYMAP, CHARS, ··· 46 42 SAY_CONTROL, SAY_WORD_CTL, NO_INTERRUPT, KEY_ECHO, 47 43 SPELL_DELAY, PUNC_LEVEL, READING_PUNC, 48 44 ATTRIB_BLEEP, BLEEPS, 49 - RATE, PITCH, INFLECTION, VOL, TONE, PUNCT, VOICE, FREQUENCY, LANG, 45 + RATE, PITCH, VOL, TONE, PUNCT, VOICE, FREQUENCY, LANG, 50 46 DIRECT, PAUSE, 51 - CAPS_START, CAPS_STOP, CHARTAB, 47 + CAPS_START, CAPS_STOP, CHARTAB, INFLECTION, 52 48 MAXVARS 53 49 }; 54 50
+2 -1
drivers/block/loop.c
··· 255 255 256 256 bd_set_nr_sectors(bdev, size); 257 257 258 - set_capacity_revalidate_and_notify(lo->lo_disk, size, false); 258 + if (!set_capacity_revalidate_and_notify(lo->lo_disk, size, false)) 259 + kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); 259 260 } 260 261 261 262 static inline int
+1
drivers/block/nbd.c
··· 1518 1518 if (test_bit(NBD_RT_DISCONNECT_ON_CLOSE, &nbd->config->runtime_flags) && 1519 1519 bdev->bd_openers == 0) 1520 1520 nbd_disconnect_and_put(nbd); 1521 + bdput(bdev); 1521 1522 1522 1523 nbd_config_put(nbd); 1523 1524 nbd_put(nbd);
+4 -4
drivers/char/virtio_console.c
··· 435 435 /* 436 436 * Allocate DMA memory from ancestor. When a virtio 437 437 * device is created by remoteproc, the DMA memory is 438 - * associated with the grandparent device: 439 - * vdev => rproc => platform-dev. 438 + * associated with the parent device: 439 + * virtioY => remoteprocX#vdevYbuffer. 440 440 */ 441 - if (!vdev->dev.parent || !vdev->dev.parent->parent) 441 + buf->dev = vdev->dev.parent; 442 + if (!buf->dev) 442 443 goto free_buf; 443 - buf->dev = vdev->dev.parent->parent; 444 444 445 445 /* Increase device refcnt to avoid freeing it */ 446 446 get_device(buf->dev);
+5 -5
drivers/clk/imx/clk-imx8mm.c
··· 443 443 hws[IMX8MM_CLK_A53_CORE] = imx_clk_hw_mux2("arm_a53_core", base + 0x9880, 24, 1, imx8mm_a53_core_sels, ARRAY_SIZE(imx8mm_a53_core_sels)); 444 444 445 445 /* BUS */ 446 - hws[IMX8MM_CLK_MAIN_AXI] = imx8m_clk_hw_composite_critical("main_axi", imx8mm_main_axi_sels, base + 0x8800); 446 + hws[IMX8MM_CLK_MAIN_AXI] = imx8m_clk_hw_composite_bus_critical("main_axi", imx8mm_main_axi_sels, base + 0x8800); 447 447 hws[IMX8MM_CLK_ENET_AXI] = imx8m_clk_hw_composite_bus("enet_axi", imx8mm_enet_axi_sels, base + 0x8880); 448 - hws[IMX8MM_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_critical("nand_usdhc_bus", imx8mm_nand_usdhc_sels, base + 0x8900); 448 + hws[IMX8MM_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_bus_critical("nand_usdhc_bus", imx8mm_nand_usdhc_sels, base + 0x8900); 449 449 hws[IMX8MM_CLK_VPU_BUS] = imx8m_clk_hw_composite_bus("vpu_bus", imx8mm_vpu_bus_sels, base + 0x8980); 450 450 hws[IMX8MM_CLK_DISP_AXI] = imx8m_clk_hw_composite_bus("disp_axi", imx8mm_disp_axi_sels, base + 0x8a00); 451 451 hws[IMX8MM_CLK_DISP_APB] = imx8m_clk_hw_composite_bus("disp_apb", imx8mm_disp_apb_sels, base + 0x8a80); ··· 453 453 hws[IMX8MM_CLK_USB_BUS] = imx8m_clk_hw_composite_bus("usb_bus", imx8mm_usb_bus_sels, base + 0x8b80); 454 454 hws[IMX8MM_CLK_GPU_AXI] = imx8m_clk_hw_composite_bus("gpu_axi", imx8mm_gpu_axi_sels, base + 0x8c00); 455 455 hws[IMX8MM_CLK_GPU_AHB] = imx8m_clk_hw_composite_bus("gpu_ahb", imx8mm_gpu_ahb_sels, base + 0x8c80); 456 - hws[IMX8MM_CLK_NOC] = imx8m_clk_hw_composite_critical("noc", imx8mm_noc_sels, base + 0x8d00); 457 - hws[IMX8MM_CLK_NOC_APB] = imx8m_clk_hw_composite_critical("noc_apb", imx8mm_noc_apb_sels, base + 0x8d80); 456 + hws[IMX8MM_CLK_NOC] = imx8m_clk_hw_composite_bus_critical("noc", imx8mm_noc_sels, base + 0x8d00); 457 + hws[IMX8MM_CLK_NOC_APB] = imx8m_clk_hw_composite_bus_critical("noc_apb", imx8mm_noc_apb_sels, base + 0x8d80); 458 458 459 459 /* AHB */ 460 - hws[IMX8MM_CLK_AHB] = imx8m_clk_hw_composite_critical("ahb", imx8mm_ahb_sels, base + 0x9000); 460 + hws[IMX8MM_CLK_AHB] = imx8m_clk_hw_composite_bus_critical("ahb", imx8mm_ahb_sels, base + 0x9000); 461 461 hws[IMX8MM_CLK_AUDIO_AHB] = imx8m_clk_hw_composite_bus("audio_ahb", imx8mm_audio_ahb_sels, base + 0x9100); 462 462 463 463 /* IPG */
+3 -3
drivers/clk/imx/clk-imx8mn.c
··· 431 431 hws[IMX8MN_CLK_A53_CORE] = imx_clk_hw_mux2("arm_a53_core", base + 0x9880, 24, 1, imx8mn_a53_core_sels, ARRAY_SIZE(imx8mn_a53_core_sels)); 432 432 433 433 /* BUS */ 434 - hws[IMX8MN_CLK_MAIN_AXI] = imx8m_clk_hw_composite_critical("main_axi", imx8mn_main_axi_sels, base + 0x8800); 434 + hws[IMX8MN_CLK_MAIN_AXI] = imx8m_clk_hw_composite_bus_critical("main_axi", imx8mn_main_axi_sels, base + 0x8800); 435 435 hws[IMX8MN_CLK_ENET_AXI] = imx8m_clk_hw_composite_bus("enet_axi", imx8mn_enet_axi_sels, base + 0x8880); 436 436 hws[IMX8MN_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_bus("nand_usdhc_bus", imx8mn_nand_usdhc_sels, base + 0x8900); 437 437 hws[IMX8MN_CLK_DISP_AXI] = imx8m_clk_hw_composite_bus("disp_axi", imx8mn_disp_axi_sels, base + 0x8a00); ··· 439 439 hws[IMX8MN_CLK_USB_BUS] = imx8m_clk_hw_composite_bus("usb_bus", imx8mn_usb_bus_sels, base + 0x8b80); 440 440 hws[IMX8MN_CLK_GPU_AXI] = imx8m_clk_hw_composite_bus("gpu_axi", imx8mn_gpu_axi_sels, base + 0x8c00); 441 441 hws[IMX8MN_CLK_GPU_AHB] = imx8m_clk_hw_composite_bus("gpu_ahb", imx8mn_gpu_ahb_sels, base + 0x8c80); 442 - hws[IMX8MN_CLK_NOC] = imx8m_clk_hw_composite_critical("noc", imx8mn_noc_sels, base + 0x8d00); 442 + hws[IMX8MN_CLK_NOC] = imx8m_clk_hw_composite_bus_critical("noc", imx8mn_noc_sels, base + 0x8d00); 443 443 444 - hws[IMX8MN_CLK_AHB] = imx8m_clk_hw_composite_critical("ahb", imx8mn_ahb_sels, base + 0x9000); 444 + hws[IMX8MN_CLK_AHB] = imx8m_clk_hw_composite_bus_critical("ahb", imx8mn_ahb_sels, base + 0x9000); 445 445 hws[IMX8MN_CLK_AUDIO_AHB] = imx8m_clk_hw_composite_bus("audio_ahb", imx8mn_audio_ahb_sels, base + 0x9100); 446 446 hws[IMX8MN_CLK_IPG_ROOT] = imx_clk_hw_divider2("ipg_root", "ahb", base + 0x9080, 0, 1); 447 447 hws[IMX8MN_CLK_IPG_AUDIO_ROOT] = imx_clk_hw_divider2("ipg_audio_root", "audio_ahb", base + 0x9180, 0, 1);
+5 -5
drivers/clk/imx/clk-imx8mp.c
··· 557 557 /* CORE SEL */ 558 558 hws[IMX8MP_CLK_A53_CORE] = imx_clk_hw_mux2("arm_a53_core", ccm_base + 0x9880, 24, 1, imx8mp_a53_core_sels, ARRAY_SIZE(imx8mp_a53_core_sels)); 559 559 560 - hws[IMX8MP_CLK_MAIN_AXI] = imx8m_clk_hw_composite_critical("main_axi", imx8mp_main_axi_sels, ccm_base + 0x8800); 560 + hws[IMX8MP_CLK_MAIN_AXI] = imx8m_clk_hw_composite_bus_critical("main_axi", imx8mp_main_axi_sels, ccm_base + 0x8800); 561 561 hws[IMX8MP_CLK_ENET_AXI] = imx8m_clk_hw_composite_bus("enet_axi", imx8mp_enet_axi_sels, ccm_base + 0x8880); 562 - hws[IMX8MP_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_critical("nand_usdhc_bus", imx8mp_nand_usdhc_sels, ccm_base + 0x8900); 562 + hws[IMX8MP_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_bus_critical("nand_usdhc_bus", imx8mp_nand_usdhc_sels, ccm_base + 0x8900); 563 563 hws[IMX8MP_CLK_VPU_BUS] = imx8m_clk_hw_composite_bus("vpu_bus", imx8mp_vpu_bus_sels, ccm_base + 0x8980); 564 564 hws[IMX8MP_CLK_MEDIA_AXI] = imx8m_clk_hw_composite_bus("media_axi", imx8mp_media_axi_sels, ccm_base + 0x8a00); 565 565 hws[IMX8MP_CLK_MEDIA_APB] = imx8m_clk_hw_composite_bus("media_apb", imx8mp_media_apb_sels, ccm_base + 0x8a80); ··· 567 567 hws[IMX8MP_CLK_HDMI_AXI] = imx8m_clk_hw_composite_bus("hdmi_axi", imx8mp_media_axi_sels, ccm_base + 0x8b80); 568 568 hws[IMX8MP_CLK_GPU_AXI] = imx8m_clk_hw_composite_bus("gpu_axi", imx8mp_gpu_axi_sels, ccm_base + 0x8c00); 569 569 hws[IMX8MP_CLK_GPU_AHB] = imx8m_clk_hw_composite_bus("gpu_ahb", imx8mp_gpu_ahb_sels, ccm_base + 0x8c80); 570 - hws[IMX8MP_CLK_NOC] = imx8m_clk_hw_composite_critical("noc", imx8mp_noc_sels, ccm_base + 0x8d00); 571 - hws[IMX8MP_CLK_NOC_IO] = imx8m_clk_hw_composite_critical("noc_io", imx8mp_noc_io_sels, ccm_base + 0x8d80); 570 + hws[IMX8MP_CLK_NOC] = imx8m_clk_hw_composite_bus_critical("noc", imx8mp_noc_sels, ccm_base + 0x8d00); 571 + hws[IMX8MP_CLK_NOC_IO] = imx8m_clk_hw_composite_bus_critical("noc_io", imx8mp_noc_io_sels, ccm_base + 0x8d80); 572 572 hws[IMX8MP_CLK_ML_AXI] = imx8m_clk_hw_composite_bus("ml_axi", imx8mp_ml_axi_sels, ccm_base + 0x8e00); 573 573 hws[IMX8MP_CLK_ML_AHB] = imx8m_clk_hw_composite_bus("ml_ahb", imx8mp_ml_ahb_sels, ccm_base + 0x8e80); 574 574 575 - hws[IMX8MP_CLK_AHB] = imx8m_clk_hw_composite_critical("ahb_root", imx8mp_ahb_sels, ccm_base + 0x9000); 575 + hws[IMX8MP_CLK_AHB] = imx8m_clk_hw_composite_bus_critical("ahb_root", imx8mp_ahb_sels, ccm_base + 0x9000); 576 576 hws[IMX8MP_CLK_AUDIO_AHB] = imx8m_clk_hw_composite_bus("audio_ahb", imx8mp_audio_ahb_sels, ccm_base + 0x9100); 577 577 hws[IMX8MP_CLK_MIPI_DSI_ESC_RX] = imx8m_clk_hw_composite_bus("mipi_dsi_esc_rx", imx8mp_mipi_dsi_esc_rx_sels, ccm_base + 0x9200); 578 578
+4 -4
drivers/clk/imx/clk-imx8mq.c
··· 431 431 hws[IMX8MQ_CLK_A53_CORE] = imx_clk_hw_mux2("arm_a53_core", base + 0x9880, 24, 1, imx8mq_a53_core_sels, ARRAY_SIZE(imx8mq_a53_core_sels)); 432 432 433 433 /* BUS */ 434 - hws[IMX8MQ_CLK_MAIN_AXI] = imx8m_clk_hw_composite_critical("main_axi", imx8mq_main_axi_sels, base + 0x8800); 434 + hws[IMX8MQ_CLK_MAIN_AXI] = imx8m_clk_hw_composite_bus_critical("main_axi", imx8mq_main_axi_sels, base + 0x8800); 435 435 hws[IMX8MQ_CLK_ENET_AXI] = imx8m_clk_hw_composite_bus("enet_axi", imx8mq_enet_axi_sels, base + 0x8880); 436 436 hws[IMX8MQ_CLK_NAND_USDHC_BUS] = imx8m_clk_hw_composite_bus("nand_usdhc_bus", imx8mq_nand_usdhc_sels, base + 0x8900); 437 437 hws[IMX8MQ_CLK_VPU_BUS] = imx8m_clk_hw_composite_bus("vpu_bus", imx8mq_vpu_bus_sels, base + 0x8980); ··· 441 441 hws[IMX8MQ_CLK_USB_BUS] = imx8m_clk_hw_composite_bus("usb_bus", imx8mq_usb_bus_sels, base + 0x8b80); 442 442 hws[IMX8MQ_CLK_GPU_AXI] = imx8m_clk_hw_composite_bus("gpu_axi", imx8mq_gpu_axi_sels, base + 0x8c00); 443 443 hws[IMX8MQ_CLK_GPU_AHB] = imx8m_clk_hw_composite_bus("gpu_ahb", imx8mq_gpu_ahb_sels, base + 0x8c80); 444 - hws[IMX8MQ_CLK_NOC] = imx8m_clk_hw_composite_critical("noc", imx8mq_noc_sels, base + 0x8d00); 445 - hws[IMX8MQ_CLK_NOC_APB] = imx8m_clk_hw_composite_critical("noc_apb", imx8mq_noc_apb_sels, base + 0x8d80); 444 + hws[IMX8MQ_CLK_NOC] = imx8m_clk_hw_composite_bus_critical("noc", imx8mq_noc_sels, base + 0x8d00); 445 + hws[IMX8MQ_CLK_NOC_APB] = imx8m_clk_hw_composite_bus_critical("noc_apb", imx8mq_noc_apb_sels, base + 0x8d80); 446 446 447 447 /* AHB */ 448 448 /* AHB clock is used by the AHB bus therefore marked as critical */ 449 - hws[IMX8MQ_CLK_AHB] = imx8m_clk_hw_composite_critical("ahb", imx8mq_ahb_sels, base + 0x9000); 449 + hws[IMX8MQ_CLK_AHB] = imx8m_clk_hw_composite_bus_critical("ahb", imx8mq_ahb_sels, base + 0x9000); 450 450 hws[IMX8MQ_CLK_AUDIO_AHB] = imx8m_clk_hw_composite_bus("audio_ahb", imx8mq_audio_ahb_sels, base + 0x9100); 451 451 452 452 /* IPG */
+5
drivers/clk/imx/clk.h
··· 549 549 IMX_COMPOSITE_BUS, \ 550 550 CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE) 551 551 552 + #define imx8m_clk_hw_composite_bus_critical(name, parent_names, reg) \ 553 + imx8m_clk_hw_composite_flags(name, parent_names, ARRAY_SIZE(parent_names), reg, \ 554 + IMX_COMPOSITE_BUS, \ 555 + CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE | CLK_IS_CRITICAL) 556 + 552 557 #define imx8m_clk_hw_composite_core(name, parent_names, reg) \ 553 558 imx8m_clk_hw_composite_flags(name, parent_names, \ 554 559 ARRAY_SIZE(parent_names), reg, \
+4 -1
drivers/clk/meson/clk-regmap.h
··· 26 26 void *data; 27 27 }; 28 28 29 - #define to_clk_regmap(_hw) container_of(_hw, struct clk_regmap, hw) 29 + static inline struct clk_regmap *to_clk_regmap(struct clk_hw *hw) 30 + { 31 + return container_of(hw, struct clk_regmap, hw); 32 + } 30 33 31 34 /** 32 35 * struct clk_regmap_gate_data - regmap backed gate specific data
+5 -1
drivers/clk/qcom/clk-regmap.h
··· 24 24 unsigned int enable_mask; 25 25 bool enable_is_inverted; 26 26 }; 27 - #define to_clk_regmap(_hw) container_of(_hw, struct clk_regmap, hw) 27 + 28 + static inline struct clk_regmap *to_clk_regmap(struct clk_hw *hw) 29 + { 30 + return container_of(hw, struct clk_regmap, hw); 31 + } 28 32 29 33 int clk_is_enabled_regmap(struct clk_hw *hw); 30 34 int clk_enable_regmap(struct clk_hw *hw);
-14
drivers/firmware/arm_sdei.c
··· 31 31 #include <linux/slab.h> 32 32 #include <linux/smp.h> 33 33 #include <linux/spinlock.h> 34 - #include <linux/uaccess.h> 35 34 36 35 /* 37 36 * The call to use to reach the firmware. ··· 1091 1092 struct sdei_registered_event *arg) 1092 1093 { 1093 1094 int err; 1094 - mm_segment_t orig_addr_limit; 1095 1095 u32 event_num = arg->event_num; 1096 - 1097 - /* 1098 - * Save restore 'fs'. 1099 - * The architecture's entry code save/restores 'fs' when taking an 1100 - * exception from the kernel. This ensures addr_limit isn't inherited 1101 - * if you interrupted something that allowed the uaccess routines to 1102 - * access kernel memory. 1103 - * Do the same here because this doesn't come via the same entry code. 1104 - */ 1105 - orig_addr_limit = force_uaccess_begin(); 1106 1096 1107 1097 err = arg->callback(event_num, regs, arg->callback_arg); 1108 1098 if (err) 1109 1099 pr_err_ratelimited("event %u on CPU %u failed with error: %d\n", 1110 1100 event_num, smp_processor_id(), err); 1111 - 1112 - force_uaccess_end(orig_addr_limit); 1113 1101 1114 1102 return err; 1115 1103 }
+78 -48
drivers/firmware/psci/psci.c
··· 58 58 unsigned long, unsigned long); 59 59 static psci_fn *invoke_psci_fn; 60 60 61 - enum psci_function { 62 - PSCI_FN_CPU_SUSPEND, 63 - PSCI_FN_CPU_ON, 64 - PSCI_FN_CPU_OFF, 65 - PSCI_FN_MIGRATE, 66 - PSCI_FN_MAX, 67 - }; 61 + static struct psci_0_1_function_ids psci_0_1_function_ids; 68 62 69 - static u32 psci_function_id[PSCI_FN_MAX]; 63 + struct psci_0_1_function_ids get_psci_0_1_function_ids(void) 64 + { 65 + return psci_0_1_function_ids; 66 + } 70 67 71 68 #define PSCI_0_2_POWER_STATE_MASK \ 72 69 (PSCI_0_2_POWER_STATE_ID_MASK | \ ··· 143 146 return -EINVAL; 144 147 } 145 148 146 - static u32 psci_get_version(void) 149 + static u32 psci_0_1_get_version(void) 150 + { 151 + return PSCI_VERSION(0, 1); 152 + } 153 + 154 + static u32 psci_0_2_get_version(void) 147 155 { 148 156 return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0); 149 157 } ··· 165 163 return psci_to_linux_errno(err); 166 164 } 167 165 168 - static int psci_cpu_suspend(u32 state, unsigned long entry_point) 166 + static int __psci_cpu_suspend(u32 fn, u32 state, unsigned long entry_point) 169 167 { 170 168 int err; 171 - u32 fn; 172 169 173 - fn = psci_function_id[PSCI_FN_CPU_SUSPEND]; 174 170 err = invoke_psci_fn(fn, state, entry_point, 0); 175 171 return psci_to_linux_errno(err); 176 172 } 177 173 178 - static int psci_cpu_off(u32 state) 174 + static int psci_0_1_cpu_suspend(u32 state, unsigned long entry_point) 175 + { 176 + return __psci_cpu_suspend(psci_0_1_function_ids.cpu_suspend, 177 + state, entry_point); 178 + } 179 + 180 + static int psci_0_2_cpu_suspend(u32 state, unsigned long entry_point) 181 + { 182 + return __psci_cpu_suspend(PSCI_FN_NATIVE(0_2, CPU_SUSPEND), 183 + state, entry_point); 184 + } 185 + 186 + static int __psci_cpu_off(u32 fn, u32 state) 179 187 { 180 188 int err; 181 - u32 fn; 182 189 183 - fn = psci_function_id[PSCI_FN_CPU_OFF]; 184 190 err = invoke_psci_fn(fn, state, 0, 0); 185 191 return psci_to_linux_errno(err); 186 192 } 187 193 188 - static int psci_cpu_on(unsigned long cpuid, unsigned long entry_point) 194 + static int psci_0_1_cpu_off(u32 state) 195 + { 196 + return __psci_cpu_off(psci_0_1_function_ids.cpu_off, state); 197 + } 198 + 199 + static int psci_0_2_cpu_off(u32 state) 200 + { 201 + return __psci_cpu_off(PSCI_0_2_FN_CPU_OFF, state); 202 + } 203 + 204 + static int __psci_cpu_on(u32 fn, unsigned long cpuid, unsigned long entry_point) 189 205 { 190 206 int err; 191 - u32 fn; 192 207 193 - fn = psci_function_id[PSCI_FN_CPU_ON]; 194 208 err = invoke_psci_fn(fn, cpuid, entry_point, 0); 195 209 return psci_to_linux_errno(err); 196 210 } 197 211 198 - static int psci_migrate(unsigned long cpuid) 212 + static int psci_0_1_cpu_on(unsigned long cpuid, unsigned long entry_point) 213 + { 214 + return __psci_cpu_on(psci_0_1_function_ids.cpu_on, cpuid, entry_point); 215 + } 216 + 217 + static int psci_0_2_cpu_on(unsigned long cpuid, unsigned long entry_point) 218 + { 219 + return __psci_cpu_on(PSCI_FN_NATIVE(0_2, CPU_ON), cpuid, entry_point); 220 + } 221 + 222 + static int __psci_migrate(u32 fn, unsigned long cpuid) 199 223 { 200 224 int err; 201 - u32 fn; 202 225 203 - fn = psci_function_id[PSCI_FN_MIGRATE]; 204 226 err = invoke_psci_fn(fn, cpuid, 0, 0); 205 227 return psci_to_linux_errno(err); 228 + } 229 + 230 + static int psci_0_1_migrate(unsigned long cpuid) 231 + { 232 + return __psci_migrate(psci_0_1_function_ids.migrate, cpuid); 233 + } 234 + 235 + static int psci_0_2_migrate(unsigned long cpuid) 236 + { 237 + return __psci_migrate(PSCI_FN_NATIVE(0_2, MIGRATE), cpuid); 206 238 } 207 239 208 240 static int psci_affinity_info(unsigned long target_affinity, ··· 383 347 384 348 static void __init psci_init_cpu_suspend(void) 385 349 { 386 - int feature = psci_features(psci_function_id[PSCI_FN_CPU_SUSPEND]); 350 + int feature = psci_features(PSCI_FN_NATIVE(0_2, CPU_SUSPEND)); 387 351 388 352 if (feature != PSCI_RET_NOT_SUPPORTED) 389 353 psci_cpu_suspend_feature = feature; ··· 457 421 static void __init psci_0_2_set_functions(void) 458 422 { 459 423 pr_info("Using standard PSCI v0.2 function IDs\n"); 460 - psci_ops.get_version = psci_get_version; 461 424 462 - psci_function_id[PSCI_FN_CPU_SUSPEND] = 463 - PSCI_FN_NATIVE(0_2, CPU_SUSPEND); 464 - psci_ops.cpu_suspend = psci_cpu_suspend; 465 - 466 - psci_function_id[PSCI_FN_CPU_OFF] = PSCI_0_2_FN_CPU_OFF; 467 - psci_ops.cpu_off = psci_cpu_off; 468 - 469 - psci_function_id[PSCI_FN_CPU_ON] = PSCI_FN_NATIVE(0_2, CPU_ON); 470 - psci_ops.cpu_on = psci_cpu_on; 471 - 472 - psci_function_id[PSCI_FN_MIGRATE] = PSCI_FN_NATIVE(0_2, MIGRATE); 473 - psci_ops.migrate = psci_migrate; 474 - 475 - psci_ops.affinity_info = psci_affinity_info; 476 - 477 - psci_ops.migrate_info_type = psci_migrate_info_type; 425 + psci_ops = (struct psci_operations){ 426 + .get_version = psci_0_2_get_version, 427 + .cpu_suspend = psci_0_2_cpu_suspend, 428 + .cpu_off = psci_0_2_cpu_off, 429 + .cpu_on = psci_0_2_cpu_on, 430 + .migrate = psci_0_2_migrate, 431 + .affinity_info = psci_affinity_info, 432 + .migrate_info_type = psci_migrate_info_type, 433 + }; 478 434 479 435 arm_pm_restart = psci_sys_reset; 480 436 ··· 478 450 */ 479 451 static int __init psci_probe(void) 480 452 { 481 - u32 ver = psci_get_version(); 453 + u32 ver = psci_0_2_get_version(); 482 454 483 455 pr_info("PSCIv%d.%d detected in firmware.\n", 484 456 PSCI_VERSION_MAJOR(ver), ··· 542 514 543 515 pr_info("Using PSCI v0.1 Function IDs from DT\n"); 544 516 517 + psci_ops.get_version = psci_0_1_get_version; 518 + 545 519 if (!of_property_read_u32(np, "cpu_suspend", &id)) { 546 - psci_function_id[PSCI_FN_CPU_SUSPEND] = id; 547 - psci_ops.cpu_suspend = psci_cpu_suspend; 520 + psci_0_1_function_ids.cpu_suspend = id; 521 + psci_ops.cpu_suspend = psci_0_1_cpu_suspend; 548 522 } 549 523 550 524 if (!of_property_read_u32(np, "cpu_off", &id)) { 551 - psci_function_id[PSCI_FN_CPU_OFF] = id; 552 - psci_ops.cpu_off = psci_cpu_off; 525 + psci_0_1_function_ids.cpu_off = id; 526 + psci_ops.cpu_off = psci_0_1_cpu_off; 553 527 } 554 528 555 529 if (!of_property_read_u32(np, "cpu_on", &id)) { 556 - psci_function_id[PSCI_FN_CPU_ON] = id; 557 - psci_ops.cpu_on = psci_cpu_on; 530 + psci_0_1_function_ids.cpu_on = id; 531 + psci_ops.cpu_on = psci_0_1_cpu_on; 558 532 } 559 533 560 534 if (!of_property_read_u32(np, "migrate", &id)) { 561 - psci_function_id[PSCI_FN_MIGRATE] = id; 562 - psci_ops.migrate = psci_migrate; 535 + psci_0_1_function_ids.migrate = id; 536 + psci_ops.migrate = psci_0_1_migrate; 563 537 } 564 538 565 539 return 0;
+3
drivers/firmware/xilinx/zynqmp.c
··· 147 147 return 0; 148 148 149 149 /* Return value if feature is already checked */ 150 + if (api_id > ARRAY_SIZE(zynqmp_pm_features)) 151 + return PM_FEATURE_INVALID; 152 + 150 153 if (zynqmp_pm_features[api_id] != PM_FEATURE_UNCHECKED) 151 154 return zynqmp_pm_features[api_id]; 152 155
+1
drivers/gpio/gpio-aspeed.c
··· 1114 1114 1115 1115 static const struct aspeed_bank_props ast2600_bank_props[] = { 1116 1116 /* input output */ 1117 + {4, 0xffffffff, 0x00ffffff}, /* Q/R/S/T */ 1117 1118 {5, 0xffffffff, 0xffffff00}, /* U/V/W/X */ 1118 1119 {6, 0x0000ffff, 0x0000ffff}, /* Y/Z */ 1119 1120 { },
+2 -2
drivers/gpio/gpio-dwapb.c
··· 343 343 #ifdef CONFIG_PM_SLEEP 344 344 static int dwapb_irq_set_wake(struct irq_data *d, unsigned int enable) 345 345 { 346 - struct irq_chip_generic *igc = irq_data_get_irq_chip_data(d); 347 - struct dwapb_gpio *gpio = igc->private; 346 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 347 + struct dwapb_gpio *gpio = to_dwapb_gpio(gc); 348 348 struct dwapb_context *ctx = gpio->ports[0].ctx; 349 349 irq_hw_number_t bit = irqd_to_hwirq(d); 350 350
+11 -1
drivers/gpio/gpio-omap.c
··· 1114 1114 { 1115 1115 struct device *dev = bank->chip.parent; 1116 1116 void __iomem *base = bank->base; 1117 - u32 nowake; 1117 + u32 mask, nowake; 1118 1118 1119 1119 bank->saved_datain = readl_relaxed(base + bank->regs->datain); 1120 1120 1121 1121 if (!bank->enabled_non_wakeup_gpios) 1122 1122 goto update_gpio_context_count; 1123 + 1124 + /* Check for pending EDGE_FALLING, ignore EDGE_BOTH */ 1125 + mask = bank->enabled_non_wakeup_gpios & bank->context.fallingdetect; 1126 + mask &= ~bank->context.risingdetect; 1127 + bank->saved_datain |= mask; 1128 + 1129 + /* Check for pending EDGE_RISING, ignore EDGE_BOTH */ 1130 + mask = bank->enabled_non_wakeup_gpios & bank->context.risingdetect; 1131 + mask &= ~bank->context.fallingdetect; 1132 + bank->saved_datain &= ~mask; 1123 1133 1124 1134 if (!may_lose_context) 1125 1135 goto update_gpio_context_count;
+56 -6
drivers/gpio/gpio-pcie-idio-24.c
··· 28 28 #include <linux/spinlock.h> 29 29 #include <linux/types.h> 30 30 31 + /* 32 + * PLX PEX8311 PCI LCS_INTCSR Interrupt Control/Status 33 + * 34 + * Bit: Description 35 + * 0: Enable Interrupt Sources (Bit 0) 36 + * 1: Enable Interrupt Sources (Bit 1) 37 + * 2: Generate Internal PCI Bus Internal SERR# Interrupt 38 + * 3: Mailbox Interrupt Enable 39 + * 4: Power Management Interrupt Enable 40 + * 5: Power Management Interrupt 41 + * 6: Slave Read Local Data Parity Check Error Enable 42 + * 7: Slave Read Local Data Parity Check Error Status 43 + * 8: Internal PCI Wire Interrupt Enable 44 + * 9: PCI Express Doorbell Interrupt Enable 45 + * 10: PCI Abort Interrupt Enable 46 + * 11: Local Interrupt Input Enable 47 + * 12: Retry Abort Enable 48 + * 13: PCI Express Doorbell Interrupt Active 49 + * 14: PCI Abort Interrupt Active 50 + * 15: Local Interrupt Input Active 51 + * 16: Local Interrupt Output Enable 52 + * 17: Local Doorbell Interrupt Enable 53 + * 18: DMA Channel 0 Interrupt Enable 54 + * 19: DMA Channel 1 Interrupt Enable 55 + * 20: Local Doorbell Interrupt Active 56 + * 21: DMA Channel 0 Interrupt Active 57 + * 22: DMA Channel 1 Interrupt Active 58 + * 23: Built-In Self-Test (BIST) Interrupt Active 59 + * 24: Direct Master was the Bus Master during a Master or Target Abort 60 + * 25: DMA Channel 0 was the Bus Master during a Master or Target Abort 61 + * 26: DMA Channel 1 was the Bus Master during a Master or Target Abort 62 + * 27: Target Abort after internal 256 consecutive Master Retrys 63 + * 28: PCI Bus wrote data to LCS_MBOX0 64 + * 29: PCI Bus wrote data to LCS_MBOX1 65 + * 30: PCI Bus wrote data to LCS_MBOX2 66 + * 31: PCI Bus wrote data to LCS_MBOX3 67 + */ 68 + #define PLX_PEX8311_PCI_LCS_INTCSR 0x68 69 + #define INTCSR_INTERNAL_PCI_WIRE BIT(8) 70 + #define INTCSR_LOCAL_INPUT BIT(11) 71 + 31 72 /** 32 73 * struct idio_24_gpio_reg - GPIO device registers structure 33 74 * @out0_7: Read: FET Outputs 0-7 ··· 133 92 struct idio_24_gpio { 134 93 struct gpio_chip chip; 135 94 raw_spinlock_t lock; 95 + __u8 __iomem *plx; 136 96 struct idio_24_gpio_reg __iomem *reg; 137 97 unsigned long irq_mask; 138 98 }; ··· 376 334 unsigned long flags; 377 335 const unsigned long bit_offset = irqd_to_hwirq(data) - 24; 378 336 unsigned char new_irq_mask; 379 - const unsigned long bank_offset = bit_offset/8 * 8; 337 + const unsigned long bank_offset = bit_offset / 8; 380 338 unsigned char cos_enable_state; 381 339 382 340 raw_spin_lock_irqsave(&idio24gpio->lock, flags); 383 341 384 - idio24gpio->irq_mask &= BIT(bit_offset); 385 - new_irq_mask = idio24gpio->irq_mask >> bank_offset; 342 + idio24gpio->irq_mask &= ~BIT(bit_offset); 343 + new_irq_mask = idio24gpio->irq_mask >> bank_offset * 8; 386 344 387 345 if (!new_irq_mask) { 388 346 cos_enable_state = ioread8(&idio24gpio->reg->cos_enable); ··· 405 363 unsigned long flags; 406 364 unsigned char prev_irq_mask; 407 365 const unsigned long bit_offset = irqd_to_hwirq(data) - 24; 408 - const unsigned long bank_offset = bit_offset/8 * 8; 366 + const unsigned long bank_offset = bit_offset / 8; 409 367 unsigned char cos_enable_state; 410 368 411 369 raw_spin_lock_irqsave(&idio24gpio->lock, flags); 412 370 413 - prev_irq_mask = idio24gpio->irq_mask >> bank_offset; 371 + prev_irq_mask = idio24gpio->irq_mask >> bank_offset * 8; 414 372 idio24gpio->irq_mask |= BIT(bit_offset); 415 373 416 374 if (!prev_irq_mask) { ··· 497 455 struct device *const dev = &pdev->dev; 498 456 struct idio_24_gpio *idio24gpio; 499 457 int err; 458 + const size_t pci_plx_bar_index = 1; 500 459 const size_t pci_bar_index = 2; 501 460 const char *const name = pci_name(pdev); 502 461 struct gpio_irq_chip *girq; ··· 512 469 return err; 513 470 } 514 471 515 - err = pcim_iomap_regions(pdev, BIT(pci_bar_index), name); 472 + err = pcim_iomap_regions(pdev, BIT(pci_plx_bar_index) | BIT(pci_bar_index), name); 516 473 if (err) { 517 474 dev_err(dev, "Unable to map PCI I/O addresses (%d)\n", err); 518 475 return err; 519 476 } 520 477 478 + idio24gpio->plx = pcim_iomap_table(pdev)[pci_plx_bar_index]; 521 479 idio24gpio->reg = pcim_iomap_table(pdev)[pci_bar_index]; 522 480 523 481 idio24gpio->chip.label = name; ··· 548 504 549 505 /* Software board reset */ 550 506 iowrite8(0, &idio24gpio->reg->soft_reset); 507 + /* 508 + * enable PLX PEX8311 internal PCI wire interrupt and local interrupt 509 + * input 510 + */ 511 + iowrite8((INTCSR_INTERNAL_PCI_WIRE | INTCSR_LOCAL_INPUT) >> 8, 512 + idio24gpio->plx + PLX_PEX8311_PCI_LCS_INTCSR + 1); 551 513 552 514 err = devm_gpiochip_add_data(dev, &idio24gpio->chip, idio24gpio); 553 515 if (err) {
+1 -1
drivers/gpio/gpio-sifive.c
··· 183 183 return PTR_ERR(chip->regs); 184 184 185 185 ngpio = of_irq_count(node); 186 - if (ngpio >= SIFIVE_GPIO_MAX) { 186 + if (ngpio > SIFIVE_GPIO_MAX) { 187 187 dev_err(dev, "Too many GPIO interrupts (max=%d)\n", 188 188 SIFIVE_GPIO_MAX); 189 189 return -ENXIO;
-15
drivers/gpio/gpiolib-cdev.h
··· 7 7 8 8 struct gpio_device; 9 9 10 - #ifdef CONFIG_GPIO_CDEV 11 - 12 10 int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt); 13 11 void gpiolib_cdev_unregister(struct gpio_device *gdev); 14 - 15 - #else 16 - 17 - static inline int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt) 18 - { 19 - return 0; 20 - } 21 - 22 - static inline void gpiolib_cdev_unregister(struct gpio_device *gdev) 23 - { 24 - } 25 - 26 - #endif /* CONFIG_GPIO_CDEV */ 27 12 28 13 #endif /* GPIOLIB_CDEV_H */
+15 -3
drivers/gpio/gpiolib.c
··· 480 480 kfree(gdev); 481 481 } 482 482 483 + #ifdef CONFIG_GPIO_CDEV 484 + #define gcdev_register(gdev, devt) gpiolib_cdev_register((gdev), (devt)) 485 + #define gcdev_unregister(gdev) gpiolib_cdev_unregister((gdev)) 486 + #else 487 + /* 488 + * gpiolib_cdev_register() indirectly calls device_add(), which is still 489 + * required even when cdev is not selected. 490 + */ 491 + #define gcdev_register(gdev, devt) device_add(&(gdev)->dev) 492 + #define gcdev_unregister(gdev) device_del(&(gdev)->dev) 493 + #endif 494 + 483 495 static int gpiochip_setup_dev(struct gpio_device *gdev) 484 496 { 485 497 int ret; 486 498 487 - ret = gpiolib_cdev_register(gdev, gpio_devt); 499 + ret = gcdev_register(gdev, gpio_devt); 488 500 if (ret) 489 501 return ret; 490 502 ··· 512 500 return 0; 513 501 514 502 err_remove_device: 515 - gpiolib_cdev_unregister(gdev); 503 + gcdev_unregister(gdev); 516 504 return ret; 517 505 } 518 506 ··· 837 825 * be removed, else it will be dangling until the last user is 838 826 * gone. 839 827 */ 840 - gpiolib_cdev_unregister(gdev); 828 + gcdev_unregister(gdev); 841 829 put_device(&gdev->dev); 842 830 } 843 831 EXPORT_SYMBOL_GPL(gpiochip_remove);
+1 -2
drivers/gpu/drm/amd/amdgpu/nv.c
··· 492 492 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) 493 493 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block); 494 494 #if defined(CONFIG_DRM_AMD_DC) 495 - else if (amdgpu_device_has_dc_support(adev) && 496 - !nv_is_headless_sku(adev->pdev)) 495 + else if (amdgpu_device_has_dc_support(adev)) 497 496 amdgpu_device_ip_block_add(adev, &dm_ip_block); 498 497 #endif 499 498 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
+1
drivers/gpu/drm/amd/amdgpu/psp_v12_0.c
··· 40 40 MODULE_FIRMWARE("amdgpu/renoir_asd.bin"); 41 41 MODULE_FIRMWARE("amdgpu/renoir_ta.bin"); 42 42 MODULE_FIRMWARE("amdgpu/green_sardine_asd.bin"); 43 + MODULE_FIRMWARE("amdgpu/green_sardine_ta.bin"); 43 44 44 45 /* address block */ 45 46 #define smnMP1_FIRMWARE_FLAGS 0x3010024
+2 -2
drivers/gpu/drm/amd/display/dc/irq/dcn30/irq_service_dcn30.c
··· 306 306 pflip_int_entry(1), 307 307 pflip_int_entry(2), 308 308 pflip_int_entry(3), 309 - [DC_IRQ_SOURCE_PFLIP5] = dummy_irq_entry(), 310 - [DC_IRQ_SOURCE_PFLIP6] = dummy_irq_entry(), 309 + pflip_int_entry(4), 310 + pflip_int_entry(5), 311 311 [DC_IRQ_SOURCE_PFLIP_UNDERLAY0] = dummy_irq_entry(), 312 312 gpio_pad_int_entry(0), 313 313 gpio_pad_int_entry(1),
+1 -1
drivers/gpu/drm/bridge/cadence/Kconfig
··· 13 13 if DRM_CDNS_MHDP8546 14 14 15 15 config DRM_CDNS_MHDP8546_J721E 16 - depends on ARCH_K3_J721E_SOC || COMPILE_TEST 16 + depends on ARCH_K3 || COMPILE_TEST 17 17 bool "J721E Cadence DPI/DP wrapper support" 18 18 default y 19 19 help
+12 -22
drivers/gpu/drm/gma500/psb_irq.c
··· 347 347 { 348 348 struct drm_psb_private *dev_priv = dev->dev_private; 349 349 unsigned long irqflags; 350 + unsigned int i; 350 351 351 352 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); 352 353 ··· 360 359 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); 361 360 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); 362 361 363 - if (dev->vblank[0].enabled) 364 - psb_enable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE); 365 - else 366 - psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE); 367 - 368 - if (dev->vblank[1].enabled) 369 - psb_enable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE); 370 - else 371 - psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE); 372 - 373 - if (dev->vblank[2].enabled) 374 - psb_enable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE); 375 - else 376 - psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE); 362 + for (i = 0; i < dev->num_crtcs; ++i) { 363 + if (dev->vblank[i].enabled) 364 + psb_enable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE); 365 + else 366 + psb_disable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE); 367 + } 377 368 378 369 if (dev_priv->ops->hotplug_enable) 379 370 dev_priv->ops->hotplug_enable(dev, true); ··· 378 385 { 379 386 struct drm_psb_private *dev_priv = dev->dev_private; 380 387 unsigned long irqflags; 388 + unsigned int i; 381 389 382 390 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); 383 391 ··· 387 393 388 394 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); 389 395 390 - if (dev->vblank[0].enabled) 391 - psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE); 392 - 393 - if (dev->vblank[1].enabled) 394 - psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE); 395 - 396 - if (dev->vblank[2].enabled) 397 - psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE); 396 + for (i = 0; i < dev->num_crtcs; ++i) { 397 + if (dev->vblank[i].enabled) 398 + psb_disable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE); 399 + } 398 400 399 401 dev_priv->vdc_irq_mask &= _PSB_IRQ_SGX_FLAG | 400 402 _PSB_IRQ_MSVDX_FLAG |
+2
drivers/gpu/drm/i915/gem/i915_gem_object_types.h
··· 56 56 void (*truncate)(struct drm_i915_gem_object *obj); 57 57 void (*writeback)(struct drm_i915_gem_object *obj); 58 58 59 + int (*pread)(struct drm_i915_gem_object *obj, 60 + const struct drm_i915_gem_pread *arg); 59 61 int (*pwrite)(struct drm_i915_gem_object *obj, 60 62 const struct drm_i915_gem_pwrite *arg); 61 63
+55
drivers/gpu/drm/i915/gem/i915_gem_phys.c
··· 134 134 vaddr, dma); 135 135 } 136 136 137 + static int 138 + phys_pwrite(struct drm_i915_gem_object *obj, 139 + const struct drm_i915_gem_pwrite *args) 140 + { 141 + void *vaddr = sg_page(obj->mm.pages->sgl) + args->offset; 142 + char __user *user_data = u64_to_user_ptr(args->data_ptr); 143 + int err; 144 + 145 + err = i915_gem_object_wait(obj, 146 + I915_WAIT_INTERRUPTIBLE | 147 + I915_WAIT_ALL, 148 + MAX_SCHEDULE_TIMEOUT); 149 + if (err) 150 + return err; 151 + 152 + /* 153 + * We manually control the domain here and pretend that it 154 + * remains coherent i.e. in the GTT domain, like shmem_pwrite. 155 + */ 156 + i915_gem_object_invalidate_frontbuffer(obj, ORIGIN_CPU); 157 + 158 + if (copy_from_user(vaddr, user_data, args->size)) 159 + return -EFAULT; 160 + 161 + drm_clflush_virt_range(vaddr, args->size); 162 + intel_gt_chipset_flush(&to_i915(obj->base.dev)->gt); 163 + 164 + i915_gem_object_flush_frontbuffer(obj, ORIGIN_CPU); 165 + return 0; 166 + } 167 + 168 + static int 169 + phys_pread(struct drm_i915_gem_object *obj, 170 + const struct drm_i915_gem_pread *args) 171 + { 172 + void *vaddr = sg_page(obj->mm.pages->sgl) + args->offset; 173 + char __user *user_data = u64_to_user_ptr(args->data_ptr); 174 + int err; 175 + 176 + err = i915_gem_object_wait(obj, 177 + I915_WAIT_INTERRUPTIBLE, 178 + MAX_SCHEDULE_TIMEOUT); 179 + if (err) 180 + return err; 181 + 182 + drm_clflush_virt_range(vaddr, args->size); 183 + if (copy_to_user(user_data, vaddr, args->size)) 184 + return -EFAULT; 185 + 186 + return 0; 187 + } 188 + 137 189 static void phys_release(struct drm_i915_gem_object *obj) 138 190 { 139 191 fput(obj->base.filp); ··· 195 143 .name = "i915_gem_object_phys", 196 144 .get_pages = i915_gem_object_get_pages_phys, 197 145 .put_pages = i915_gem_object_put_pages_phys, 146 + 147 + .pread = phys_pread, 148 + .pwrite = phys_pwrite, 198 149 199 150 .release = phys_release, 200 151 };
+2 -1
drivers/gpu/drm/i915/gt/intel_engine_cs.c
··· 371 371 * instances. 372 372 */ 373 373 if ((INTEL_GEN(i915) >= 11 && 374 - engine->gt->info.vdbox_sfc_access & engine->mask) || 374 + (engine->gt->info.vdbox_sfc_access & 375 + BIT(engine->instance))) || 375 376 (INTEL_GEN(i915) >= 9 && engine->instance == 0)) 376 377 engine->uabi_capabilities |= 377 378 I915_VIDEO_AND_ENHANCE_CLASS_CAPABILITY_SFC;
+6 -26
drivers/gpu/drm/i915/i915_gem.c
··· 180 180 } 181 181 182 182 static int 183 - i915_gem_phys_pwrite(struct drm_i915_gem_object *obj, 184 - struct drm_i915_gem_pwrite *args, 185 - struct drm_file *file) 186 - { 187 - void *vaddr = sg_page(obj->mm.pages->sgl) + args->offset; 188 - char __user *user_data = u64_to_user_ptr(args->data_ptr); 189 - 190 - /* 191 - * We manually control the domain here and pretend that it 192 - * remains coherent i.e. in the GTT domain, like shmem_pwrite. 193 - */ 194 - i915_gem_object_invalidate_frontbuffer(obj, ORIGIN_CPU); 195 - 196 - if (copy_from_user(vaddr, user_data, args->size)) 197 - return -EFAULT; 198 - 199 - drm_clflush_virt_range(vaddr, args->size); 200 - intel_gt_chipset_flush(&to_i915(obj->base.dev)->gt); 201 - 202 - i915_gem_object_flush_frontbuffer(obj, ORIGIN_CPU); 203 - return 0; 204 - } 205 - 206 - static int 207 183 i915_gem_create(struct drm_file *file, 208 184 struct intel_memory_region *mr, 209 185 u64 *size_p, ··· 502 526 } 503 527 504 528 trace_i915_gem_object_pread(obj, args->offset, args->size); 529 + 530 + ret = -ENODEV; 531 + if (obj->ops->pread) 532 + ret = obj->ops->pread(obj, args); 533 + if (ret != -ENODEV) 534 + goto out; 505 535 506 536 ret = i915_gem_object_wait(obj, 507 537 I915_WAIT_INTERRUPTIBLE, ··· 848 866 if (ret == -EFAULT || ret == -ENOSPC) { 849 867 if (i915_gem_object_has_struct_page(obj)) 850 868 ret = i915_gem_shmem_pwrite(obj, args); 851 - else 852 - ret = i915_gem_phys_pwrite(obj, args, file); 853 869 } 854 870 855 871 i915_gem_object_unpin_pages(obj);
+7 -1
drivers/gpu/drm/mcde/mcde_drv.c
··· 413 413 match); 414 414 if (ret) { 415 415 dev_err(dev, "failed to add component master\n"); 416 - goto clk_disable; 416 + /* 417 + * The EPOD regulator is already disabled at this point so some 418 + * special errorpath code is needed 419 + */ 420 + clk_disable_unprepare(mcde->mcde_clk); 421 + regulator_disable(mcde->vana); 422 + return ret; 417 423 } 418 424 419 425 return 0;
+14 -15
drivers/gpu/drm/nouveau/dispnv50/disp.c
··· 455 455 * DAC 456 456 *****************************************************************************/ 457 457 static void 458 - nv50_dac_disable(struct drm_encoder *encoder) 458 + nv50_dac_disable(struct drm_encoder *encoder, struct drm_atomic_state *state) 459 459 { 460 460 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 461 461 struct nv50_core *core = nv50_disp(encoder->dev)->core; ··· 467 467 } 468 468 469 469 static void 470 - nv50_dac_enable(struct drm_encoder *encoder) 470 + nv50_dac_enable(struct drm_encoder *encoder, struct drm_atomic_state *state) 471 471 { 472 472 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 473 473 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); ··· 525 525 static const struct drm_encoder_helper_funcs 526 526 nv50_dac_help = { 527 527 .atomic_check = nv50_outp_atomic_check, 528 - .enable = nv50_dac_enable, 529 - .disable = nv50_dac_disable, 528 + .atomic_enable = nv50_dac_enable, 529 + .atomic_disable = nv50_dac_disable, 530 530 .detect = nv50_dac_detect 531 531 }; 532 532 ··· 1055 1055 } 1056 1056 1057 1057 static void 1058 - nv50_msto_enable(struct drm_encoder *encoder) 1058 + nv50_msto_enable(struct drm_encoder *encoder, struct drm_atomic_state *state) 1059 1059 { 1060 1060 struct nv50_head *head = nv50_head(encoder->crtc); 1061 1061 struct nv50_head_atom *armh = nv50_head_atom(head->base.base.state); ··· 1101 1101 } 1102 1102 1103 1103 static void 1104 - nv50_msto_disable(struct drm_encoder *encoder) 1104 + nv50_msto_disable(struct drm_encoder *encoder, struct drm_atomic_state *state) 1105 1105 { 1106 1106 struct nv50_msto *msto = nv50_msto(encoder); 1107 1107 struct nv50_mstc *mstc = msto->mstc; ··· 1118 1118 1119 1119 static const struct drm_encoder_helper_funcs 1120 1120 nv50_msto_help = { 1121 - .disable = nv50_msto_disable, 1122 - .enable = nv50_msto_enable, 1121 + .atomic_disable = nv50_msto_disable, 1122 + .atomic_enable = nv50_msto_enable, 1123 1123 .atomic_check = nv50_msto_atomic_check, 1124 1124 }; 1125 1125 ··· 1645 1645 } 1646 1646 1647 1647 static void 1648 - nv50_sor_enable(struct drm_encoder *encoder, 1649 - struct drm_atomic_state *state) 1648 + nv50_sor_enable(struct drm_encoder *encoder, struct drm_atomic_state *state) 1650 1649 { 1651 1650 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 1652 1651 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); ··· 1872 1873 } 1873 1874 1874 1875 static void 1875 - nv50_pior_disable(struct drm_encoder *encoder) 1876 + nv50_pior_disable(struct drm_encoder *encoder, struct drm_atomic_state *state) 1876 1877 { 1877 1878 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 1878 1879 struct nv50_core *core = nv50_disp(encoder->dev)->core; ··· 1884 1885 } 1885 1886 1886 1887 static void 1887 - nv50_pior_enable(struct drm_encoder *encoder) 1888 + nv50_pior_enable(struct drm_encoder *encoder, struct drm_atomic_state *state) 1888 1889 { 1889 1890 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 1890 1891 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); ··· 1920 1921 } 1921 1922 1922 1923 core->func->pior->ctrl(core, nv_encoder->or, ctrl, asyh); 1923 - nv_encoder->crtc = encoder->crtc; 1924 + nv_encoder->crtc = &nv_crtc->base; 1924 1925 } 1925 1926 1926 1927 static const struct drm_encoder_helper_funcs 1927 1928 nv50_pior_help = { 1928 1929 .atomic_check = nv50_pior_atomic_check, 1929 - .enable = nv50_pior_enable, 1930 - .disable = nv50_pior_disable, 1930 + .atomic_enable = nv50_pior_enable, 1931 + .atomic_disable = nv50_pior_disable, 1931 1932 }; 1932 1933 1933 1934 static void
+1 -2
drivers/gpu/drm/nouveau/nouveau_bo.c
··· 350 350 351 351 if (domain & NOUVEAU_GEM_DOMAIN_VRAM) { 352 352 struct nvif_mmu *mmu = &drm->client.mmu; 353 - const u8 type = mmu->type[drm->ttm.type_vram].type; 354 353 355 354 pl[*n].mem_type = TTM_PL_VRAM; 356 355 pl[*n].flags = flags & ~TTM_PL_FLAG_CACHED; 357 356 358 357 /* Some BARs do not support being ioremapped WC */ 359 358 if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA && 360 - type & NVIF_MEM_UNCACHED) 359 + mmu->type[drm->ttm.type_vram].type & NVIF_MEM_UNCACHED) 361 360 pl[*n].flags &= ~TTM_PL_FLAG_WC; 362 361 363 362 (*n)++;
+9 -5
drivers/gpu/drm/nouveau/nouveau_connector.c
··· 532 532 nouveau_connector_set_edid(struct nouveau_connector *nv_connector, 533 533 struct edid *edid) 534 534 { 535 - struct edid *old_edid = nv_connector->edid; 535 + if (nv_connector->edid != edid) { 536 + struct edid *old_edid = nv_connector->edid; 536 537 537 - drm_connector_update_edid_property(&nv_connector->base, edid); 538 - kfree(old_edid); 539 - nv_connector->edid = edid; 538 + drm_connector_update_edid_property(&nv_connector->base, edid); 539 + kfree(old_edid); 540 + nv_connector->edid = edid; 541 + } 540 542 } 541 543 542 544 static enum drm_connector_status ··· 671 669 /* Try retrieving EDID via DDC */ 672 670 if (!drm->vbios.fp_no_ddc) { 673 671 status = nouveau_connector_detect(connector, force); 674 - if (status == connector_status_connected) 672 + if (status == connector_status_connected) { 673 + edid = nv_connector->edid; 675 674 goto out; 675 + } 676 676 } 677 677 678 678 /* On some laptops (Sony, i'm looking at you) there appears to
+1 -1
drivers/hwmon/amd_energy.c
··· 171 171 enum hwmon_sensor_types type, 172 172 u32 attr, int channel) 173 173 { 174 - return 0444; 174 + return 0440; 175 175 } 176 176 177 177 static int energy_accumulator(void *p)
+82 -48
drivers/hwmon/applesmc.c
··· 32 32 #include <linux/hwmon.h> 33 33 #include <linux/workqueue.h> 34 34 #include <linux/err.h> 35 + #include <linux/bits.h> 35 36 36 37 /* data port used by Apple SMC */ 37 38 #define APPLESMC_DATA_PORT 0x300 ··· 43 42 44 43 #define APPLESMC_MAX_DATA_LENGTH 32 45 44 46 - /* wait up to 128 ms for a status change. */ 47 - #define APPLESMC_MIN_WAIT 0x0010 48 - #define APPLESMC_RETRY_WAIT 0x0100 49 - #define APPLESMC_MAX_WAIT 0x20000 45 + /* Apple SMC status bits */ 46 + #define SMC_STATUS_AWAITING_DATA BIT(0) /* SMC has data waiting to be read */ 47 + #define SMC_STATUS_IB_CLOSED BIT(1) /* Will ignore any input */ 48 + #define SMC_STATUS_BUSY BIT(2) /* Command in progress */ 49 + 50 + /* Initial wait is 8us */ 51 + #define APPLESMC_MIN_WAIT 0x0008 50 52 51 53 #define APPLESMC_READ_CMD 0x10 52 54 #define APPLESMC_WRITE_CMD 0x11 ··· 155 151 static struct workqueue_struct *applesmc_led_wq; 156 152 157 153 /* 158 - * wait_read - Wait for a byte to appear on SMC port. Callers must 159 - * hold applesmc_lock. 154 + * Wait for specific status bits with a mask on the SMC. 155 + * Used before all transactions. 156 + * This does 10 fast loops of 8us then exponentially backs off for a 157 + * minimum total wait of 262ms. Depending on usleep_range this could 158 + * run out past 500ms. 160 159 */ 161 - static int wait_read(void) 160 + 161 + static int wait_status(u8 val, u8 mask) 162 162 { 163 - unsigned long end = jiffies + (APPLESMC_MAX_WAIT * HZ) / USEC_PER_SEC; 164 163 u8 status; 165 164 int us; 165 + int i; 166 166 167 - for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) { 168 - usleep_range(us, us * 16); 167 + us = APPLESMC_MIN_WAIT; 168 + for (i = 0; i < 24 ; i++) { 169 169 status = inb(APPLESMC_CMD_PORT); 170 - /* read: wait for smc to settle */ 171 - if (status & 0x01) 170 + if ((status & mask) == val) 172 171 return 0; 173 - /* timeout: give up */ 174 - if (time_after(jiffies, end)) 175 - break; 172 + usleep_range(us, us * 2); 173 + if (i > 9) 174 + us <<= 1; 176 175 } 177 - 178 - pr_warn("wait_read() fail: 0x%02x\n", status); 179 176 return -EIO; 180 177 } 181 178 182 - /* 183 - * send_byte - Write to SMC port, retrying when necessary. Callers 184 - * must hold applesmc_lock. 185 - */ 179 + /* send_byte - Write to SMC data port. Callers must hold applesmc_lock. */ 180 + 186 181 static int send_byte(u8 cmd, u16 port) 187 182 { 188 - u8 status; 189 - int us; 190 - unsigned long end = jiffies + (APPLESMC_MAX_WAIT * HZ) / USEC_PER_SEC; 183 + int status; 184 + 185 + status = wait_status(0, SMC_STATUS_IB_CLOSED); 186 + if (status) 187 + return status; 188 + /* 189 + * This needs to be a separate read looking for bit 0x04 190 + * after bit 0x02 falls. If consolidated with the wait above 191 + * this extra read may not happen if status returns both 192 + * simultaneously and this would appear to be required. 193 + */ 194 + status = wait_status(SMC_STATUS_BUSY, SMC_STATUS_BUSY); 195 + if (status) 196 + return status; 191 197 192 198 outb(cmd, port); 193 - for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) { 194 - usleep_range(us, us * 16); 195 - status = inb(APPLESMC_CMD_PORT); 196 - /* write: wait for smc to settle */ 197 - if (status & 0x02) 198 - continue; 199 - /* ready: cmd accepted, return */ 200 - if (status & 0x04) 201 - return 0; 202 - /* timeout: give up */ 203 - if (time_after(jiffies, end)) 204 - break; 205 - /* busy: long wait and resend */ 206 - udelay(APPLESMC_RETRY_WAIT); 207 - outb(cmd, port); 208 - } 209 - 210 - pr_warn("send_byte(0x%02x, 0x%04x) fail: 0x%02x\n", cmd, port, status); 211 - return -EIO; 199 + return 0; 212 200 } 201 + 202 + /* send_command - Write a command to the SMC. Callers must hold applesmc_lock. */ 213 203 214 204 static int send_command(u8 cmd) 215 205 { 216 - return send_byte(cmd, APPLESMC_CMD_PORT); 206 + int ret; 207 + 208 + ret = wait_status(0, SMC_STATUS_IB_CLOSED); 209 + if (ret) 210 + return ret; 211 + outb(cmd, APPLESMC_CMD_PORT); 212 + return 0; 213 + } 214 + 215 + /* 216 + * Based on logic from the Apple driver. This is issued before any interaction 217 + * If busy is stuck high, issue a read command to reset the SMC state machine. 218 + * If busy is stuck high after the command then the SMC is jammed. 219 + */ 220 + 221 + static int smc_sane(void) 222 + { 223 + int ret; 224 + 225 + ret = wait_status(0, SMC_STATUS_BUSY); 226 + if (!ret) 227 + return ret; 228 + ret = send_command(APPLESMC_READ_CMD); 229 + if (ret) 230 + return ret; 231 + return wait_status(0, SMC_STATUS_BUSY); 217 232 } 218 233 219 234 static int send_argument(const char *key) ··· 249 226 { 250 227 u8 status, data = 0; 251 228 int i; 229 + int ret; 230 + 231 + ret = smc_sane(); 232 + if (ret) 233 + return ret; 252 234 253 235 if (send_command(cmd) || send_argument(key)) { 254 236 pr_warn("%.4s: read arg fail\n", key); ··· 267 239 } 268 240 269 241 for (i = 0; i < len; i++) { 270 - if (wait_read()) { 242 + if (wait_status(SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY, 243 + SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY)) { 271 244 pr_warn("%.4s: read data[%d] fail\n", key, i); 272 245 return -EIO; 273 246 } ··· 279 250 for (i = 0; i < 16; i++) { 280 251 udelay(APPLESMC_MIN_WAIT); 281 252 status = inb(APPLESMC_CMD_PORT); 282 - if (!(status & 0x01)) 253 + if (!(status & SMC_STATUS_AWAITING_DATA)) 283 254 break; 284 255 data = inb(APPLESMC_DATA_PORT); 285 256 } 286 257 if (i) 287 258 pr_warn("flushed %d bytes, last value is: %d\n", i, data); 288 259 289 - return 0; 260 + return wait_status(0, SMC_STATUS_BUSY); 290 261 } 291 262 292 263 static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len) 293 264 { 294 265 int i; 266 + int ret; 267 + 268 + ret = smc_sane(); 269 + if (ret) 270 + return ret; 295 271 296 272 if (send_command(cmd) || send_argument(key)) { 297 273 pr_warn("%s: write arg fail\n", key); ··· 315 281 } 316 282 } 317 283 318 - return 0; 284 + return wait_status(0, SMC_STATUS_BUSY); 319 285 } 320 286 321 287 static int read_register_count(unsigned int *count)
+13 -13
drivers/hwmon/pmbus/max20730.c
··· 122 122 switch (idx) { 123 123 case MAX20730_DEBUGFS_VOUT_MIN: 124 124 ret = VOLT_FROM_REG(data->mfr_voutmin * 10000); 125 - len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d.%d\n", 126 - ret / 10000, ret % 10000); 125 + len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d.%d\n", 126 + ret / 10000, ret % 10000); 127 127 break; 128 128 case MAX20730_DEBUGFS_FREQUENCY: 129 129 val = (data->mfr_devset1 & MAX20730_MFR_DEVSET1_FSW_MASK) ··· 141 141 ret = 800; 142 142 else 143 143 ret = 900; 144 - len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 144 + len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 145 145 break; 146 146 case MAX20730_DEBUGFS_PG_DELAY: 147 147 val = (data->mfr_devset1 & MAX20730_MFR_DEVSET1_TSTAT_MASK) ··· 223 223 case MAX20730_DEBUGFS_OC_PROTECT_MODE: 224 224 ret = (data->mfr_devset2 & MAX20730_MFR_DEVSET2_OCPM_MASK) 225 225 >> MAX20730_MFR_DEVSET2_OCPM_BIT_POS; 226 - len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 226 + len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 227 227 break; 228 228 case MAX20730_DEBUGFS_SS_TIMING: 229 229 val = (data->mfr_devset2 & MAX20730_MFR_DEVSET2_SS_MASK) ··· 241 241 case MAX20730_DEBUGFS_IMAX: 242 242 ret = (data->mfr_devset2 & MAX20730_MFR_DEVSET2_IMAX_MASK) 243 243 >> MAX20730_MFR_DEVSET2_IMAX_BIT_POS; 244 - len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 244 + len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 245 245 break; 246 246 case MAX20730_DEBUGFS_OPERATION: 247 247 ret = i2c_smbus_read_byte_data(psu->client, PMBUS_OPERATION); 248 248 if (ret < 0) 249 249 return ret; 250 - len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 250 + len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 251 251 break; 252 252 case MAX20730_DEBUGFS_ON_OFF_CONFIG: 253 253 ret = i2c_smbus_read_byte_data(psu->client, PMBUS_ON_OFF_CONFIG); 254 254 if (ret < 0) 255 255 return ret; 256 - len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 256 + len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 257 257 break; 258 258 case MAX20730_DEBUGFS_SMBALERT_MASK: 259 259 ret = i2c_smbus_read_word_data(psu->client, 260 260 PMBUS_SMB_ALERT_MASK); 261 261 if (ret < 0) 262 262 return ret; 263 - len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 263 + len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 264 264 break; 265 265 case MAX20730_DEBUGFS_VOUT_MODE: 266 266 ret = i2c_smbus_read_byte_data(psu->client, PMBUS_VOUT_MODE); 267 267 if (ret < 0) 268 268 return ret; 269 - len = snprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 269 + len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, "%d\n", ret); 270 270 break; 271 271 case MAX20730_DEBUGFS_VOUT_COMMAND: 272 272 ret = i2c_smbus_read_word_data(psu->client, PMBUS_VOUT_COMMAND); ··· 274 274 return ret; 275 275 276 276 ret = VOLT_FROM_REG(ret * 10000); 277 - len = snprintf(tbuf, DEBUG_FS_DATA_MAX, 278 - "%d.%d\n", ret / 10000, ret % 10000); 277 + len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, 278 + "%d.%d\n", ret / 10000, ret % 10000); 279 279 break; 280 280 case MAX20730_DEBUGFS_VOUT_MAX: 281 281 ret = i2c_smbus_read_word_data(psu->client, PMBUS_VOUT_MAX); ··· 283 283 return ret; 284 284 285 285 ret = VOLT_FROM_REG(ret * 10000); 286 - len = snprintf(tbuf, DEBUG_FS_DATA_MAX, 287 - "%d.%d\n", ret / 10000, ret % 10000); 286 + len = scnprintf(tbuf, DEBUG_FS_DATA_MAX, 287 + "%d.%d\n", ret / 10000, ret % 10000); 288 288 break; 289 289 default: 290 290 len = strlcpy(tbuf, "Invalid\n", DEBUG_FS_DATA_MAX);
+10 -3
drivers/hwmon/pmbus/pmbus_core.c
··· 941 941 struct i2c_client *client = to_i2c_client(dev->parent); 942 942 struct pmbus_sensor *sensor = to_pmbus_sensor(devattr); 943 943 struct pmbus_data *data = i2c_get_clientdata(client); 944 + ssize_t ret; 944 945 946 + mutex_lock(&data->update_lock); 945 947 pmbus_update_sensor_data(client, sensor); 946 948 if (sensor->data < 0) 947 - return sensor->data; 948 - 949 - return snprintf(buf, PAGE_SIZE, "%lld\n", pmbus_reg2data(data, sensor)); 949 + ret = sensor->data; 950 + else 951 + ret = snprintf(buf, PAGE_SIZE, "%lld\n", pmbus_reg2data(data, sensor)); 952 + mutex_unlock(&data->update_lock); 953 + return ret; 950 954 } 951 955 952 956 static ssize_t pmbus_set_sensor(struct device *dev, ··· 2016 2012 int val; 2017 2013 struct i2c_client *client = to_i2c_client(dev->parent); 2018 2014 struct pmbus_samples_reg *reg = to_samples_reg(devattr); 2015 + struct pmbus_data *data = i2c_get_clientdata(client); 2019 2016 2017 + mutex_lock(&data->update_lock); 2020 2018 val = _pmbus_read_word_data(client, reg->page, 0xff, reg->attr->reg); 2019 + mutex_unlock(&data->update_lock); 2021 2020 if (val < 0) 2022 2021 return val; 2023 2022
+9 -7
drivers/hwmon/pwm-fan.c
··· 54 54 static void sample_timer(struct timer_list *t) 55 55 { 56 56 struct pwm_fan_ctx *ctx = from_timer(ctx, t, rpm_timer); 57 + unsigned int delta = ktime_ms_delta(ktime_get(), ctx->sample_start); 57 58 int pulses; 58 - u64 tmp; 59 59 60 - pulses = atomic_read(&ctx->pulses); 61 - atomic_sub(pulses, &ctx->pulses); 62 - tmp = (u64)pulses * ktime_ms_delta(ktime_get(), ctx->sample_start) * 60; 63 - do_div(tmp, ctx->pulses_per_revolution * 1000); 64 - ctx->rpm = tmp; 60 + if (delta) { 61 + pulses = atomic_read(&ctx->pulses); 62 + atomic_sub(pulses, &ctx->pulses); 63 + ctx->rpm = (unsigned int)(pulses * 1000 * 60) / 64 + (ctx->pulses_per_revolution * delta); 65 65 66 - ctx->sample_start = ktime_get(); 66 + ctx->sample_start = ktime_get(); 67 + } 68 + 67 69 mod_timer(&ctx->rpm_timer, jiffies + HZ); 68 70 } 69 71
+18 -1
drivers/iommu/intel/dmar.c
··· 333 333 dmar_iommu_notify_scope_dev(info); 334 334 } 335 335 336 + static inline void vf_inherit_msi_domain(struct pci_dev *pdev) 337 + { 338 + dev_set_msi_domain(&pdev->dev, dev_get_msi_domain(&pdev->physfn->dev)); 339 + } 340 + 336 341 static int dmar_pci_bus_notifier(struct notifier_block *nb, 337 342 unsigned long action, void *data) 338 343 { ··· 347 342 /* Only care about add/remove events for physical functions. 348 343 * For VFs we actually do the lookup based on the corresponding 349 344 * PF in device_to_iommu() anyway. */ 350 - if (pdev->is_virtfn) 345 + if (pdev->is_virtfn) { 346 + /* 347 + * Ensure that the VF device inherits the irq domain of the 348 + * PF device. Ideally the device would inherit the domain 349 + * from the bus, but DMAR can have multiple units per bus 350 + * which makes this impossible. The VF 'bus' could inherit 351 + * from the PF device, but that's yet another x86'sism to 352 + * inflict on everybody else. 353 + */ 354 + if (action == BUS_NOTIFY_ADD_DEVICE) 355 + vf_inherit_msi_domain(pdev); 351 356 return NOTIFY_DONE; 357 + } 358 + 352 359 if (action != BUS_NOTIFY_ADD_DEVICE && 353 360 action != BUS_NOTIFY_REMOVED_DEVICE) 354 361 return NOTIFY_DONE;
+8 -4
drivers/irqchip/irq-gic-v3-its.c
··· 3842 3842 val |= vpe->idai ? GICR_VPENDBASER_IDAI : 0; 3843 3843 val |= GICR_VPENDBASER_Valid; 3844 3844 gicr_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); 3845 - 3846 - its_wait_vpt_parse_complete(); 3847 3845 } 3848 3846 3849 3847 static void its_vpe_deschedule(struct its_vpe *vpe) ··· 3887 3889 3888 3890 case DESCHEDULE_VPE: 3889 3891 its_vpe_deschedule(vpe); 3892 + return 0; 3893 + 3894 + case COMMIT_VPE: 3895 + its_wait_vpt_parse_complete(); 3890 3896 return 0; 3891 3897 3892 3898 case INVALL_VPE: ··· 4054 4052 val |= FIELD_PREP(GICR_VPENDBASER_4_1_VPEID, vpe->vpe_id); 4055 4053 4056 4054 gicr_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER); 4057 - 4058 - its_wait_vpt_parse_complete(); 4059 4055 } 4060 4056 4061 4057 static void its_vpe_4_1_deschedule(struct its_vpe *vpe, ··· 4126 4126 4127 4127 case DESCHEDULE_VPE: 4128 4128 its_vpe_4_1_deschedule(vpe, info); 4129 + return 0; 4130 + 4131 + case COMMIT_VPE: 4132 + its_wait_vpt_parse_complete(); 4129 4133 return 0; 4130 4134 4131 4135 case INVALL_VPE:
+19
drivers/irqchip/irq-gic-v4.c
··· 232 232 if (!ret) 233 233 vpe->resident = false; 234 234 235 + vpe->ready = false; 236 + 235 237 return ret; 236 238 } 237 239 ··· 259 257 260 258 return ret; 261 259 } 260 + 261 + int its_commit_vpe(struct its_vpe *vpe) 262 + { 263 + struct its_cmd_info info = { 264 + .cmd_type = COMMIT_VPE, 265 + }; 266 + int ret; 267 + 268 + WARN_ON(preemptible()); 269 + 270 + ret = its_send_vpe_cmd(vpe, &info); 271 + if (!ret) 272 + vpe->ready = true; 273 + 274 + return ret; 275 + } 276 + 262 277 263 278 int its_invall_vpe(struct its_vpe *vpe) 264 279 {
+4 -5
drivers/misc/habanalabs/common/command_buffer.c
··· 142 142 { 143 143 if (cb->is_internal) 144 144 gen_pool_free(hdev->internal_cb_pool, 145 - cb->kernel_address, cb->size); 145 + (uintptr_t)cb->kernel_address, cb->size); 146 146 else 147 147 hdev->asic_funcs->asic_dma_free_coherent(hdev, cb->size, 148 - (void *) (uintptr_t) cb->kernel_address, 149 - cb->bus_address); 148 + cb->kernel_address, cb->bus_address); 150 149 151 150 kfree(cb); 152 151 } ··· 229 230 return NULL; 230 231 } 231 232 232 - cb->kernel_address = (u64) (uintptr_t) p; 233 + cb->kernel_address = p; 233 234 cb->size = cb_size; 234 235 235 236 return cb; ··· 508 509 509 510 vma->vm_private_data = cb; 510 511 511 - rc = hdev->asic_funcs->cb_mmap(hdev, vma, (void *) cb->kernel_address, 512 + rc = hdev->asic_funcs->cb_mmap(hdev, vma, cb->kernel_address, 512 513 cb->bus_address, cb->size); 513 514 if (rc) { 514 515 spin_lock(&cb->lock);
+7 -7
drivers/misc/habanalabs/common/habanalabs.h
··· 452 452 struct list_head pool_list; 453 453 struct list_head va_block_list; 454 454 u64 id; 455 - u64 kernel_address; 455 + void *kernel_address; 456 456 dma_addr_t bus_address; 457 457 u32 mmap_size; 458 458 u32 size; ··· 515 515 struct hl_hw_sob hw_sob[HL_RSVD_SOBS]; 516 516 struct hl_cs_job **shadow_queue; 517 517 enum hl_queue_type queue_type; 518 - u64 kernel_address; 518 + void *kernel_address; 519 519 dma_addr_t bus_address; 520 520 u32 pi; 521 521 atomic_t ci; ··· 544 544 */ 545 545 struct hl_cq { 546 546 struct hl_device *hdev; 547 - u64 kernel_address; 547 + void *kernel_address; 548 548 dma_addr_t bus_address; 549 549 u32 cq_idx; 550 550 u32 hw_queue_id; ··· 562 562 */ 563 563 struct hl_eq { 564 564 struct hl_device *hdev; 565 - u64 kernel_address; 565 + void *kernel_address; 566 566 dma_addr_t bus_address; 567 567 u32 ci; 568 568 }; ··· 757 757 u32 (*get_dma_desc_list_size)(struct hl_device *hdev, 758 758 struct sg_table *sgt); 759 759 void (*add_end_of_cb_packets)(struct hl_device *hdev, 760 - u64 kernel_address, u32 len, 760 + void *kernel_address, u32 len, 761 761 u64 cq_addr, u32 cq_val, u32 msix_num, 762 762 bool eb); 763 763 void (*update_eq_ci)(struct hl_device *hdev, u32 val); ··· 1382 1382 for (;;) { \ 1383 1383 /* Verify we read updates done by other cores or by device */ \ 1384 1384 mb(); \ 1385 - (val) = *((u32 *) (uintptr_t) (addr)); \ 1385 + (val) = *((u32 *)(addr)); \ 1386 1386 if (mem_written_by_device) \ 1387 1387 (val) = le32_to_cpu(*(__le32 *) &(val)); \ 1388 1388 if (cond) \ 1389 1389 break; \ 1390 1390 if (timeout_us && ktime_compare(ktime_get(), __timeout) > 0) { \ 1391 - (val) = *((u32 *) (uintptr_t) (addr)); \ 1391 + (val) = *((u32 *)(addr)); \ 1392 1392 if (mem_written_by_device) \ 1393 1393 (val) = le32_to_cpu(*(__le32 *) &(val)); \ 1394 1394 break; \
+9 -10
drivers/misc/habanalabs/common/hw_queue.c
··· 75 75 { 76 76 struct hl_bd *bd; 77 77 78 - bd = (struct hl_bd *) (uintptr_t) q->kernel_address; 78 + bd = q->kernel_address; 79 79 bd += hl_pi_2_offset(q->pi); 80 80 bd->ctl = cpu_to_le32(ctl); 81 81 bd->len = cpu_to_le32(len); ··· 335 335 bd.len = cpu_to_le32(job->job_cb_size); 336 336 bd.ptr = cpu_to_le64((u64) (uintptr_t) job->user_cb); 337 337 338 - pi = (__le64 *) (uintptr_t) (q->kernel_address + 339 - ((q->pi & (q->int_queue_len - 1)) * sizeof(bd))); 338 + pi = q->kernel_address + (q->pi & (q->int_queue_len - 1)) * sizeof(bd); 340 339 341 340 q->pi++; 342 341 q->pi &= ((q->int_queue_len << 1) - 1); ··· 629 630 if (!p) 630 631 return -ENOMEM; 631 632 632 - q->kernel_address = (u64) (uintptr_t) p; 633 + q->kernel_address = p; 633 634 634 635 q->shadow_queue = kmalloc_array(HL_QUEUE_LENGTH, 635 636 sizeof(*q->shadow_queue), ··· 652 653 if (is_cpu_queue) 653 654 hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev, 654 655 HL_QUEUE_SIZE_IN_BYTES, 655 - (void *) (uintptr_t) q->kernel_address); 656 + q->kernel_address); 656 657 else 657 658 hdev->asic_funcs->asic_dma_free_coherent(hdev, 658 659 HL_QUEUE_SIZE_IN_BYTES, 659 - (void *) (uintptr_t) q->kernel_address, 660 + q->kernel_address, 660 661 q->bus_address); 661 662 662 663 return rc; ··· 675 676 return -EFAULT; 676 677 } 677 678 678 - q->kernel_address = (u64) (uintptr_t) p; 679 + q->kernel_address = p; 679 680 q->pi = 0; 680 681 atomic_set(&q->ci, 0); 681 682 ··· 703 704 if (!p) 704 705 return -ENOMEM; 705 706 706 - q->kernel_address = (u64) (uintptr_t) p; 707 + q->kernel_address = p; 707 708 708 709 /* Make sure read/write pointers are initialized to start of queue */ 709 710 atomic_set(&q->ci, 0); ··· 838 839 if (q->queue_type == QUEUE_TYPE_CPU) 839 840 hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev, 840 841 HL_QUEUE_SIZE_IN_BYTES, 841 - (void *) (uintptr_t) q->kernel_address); 842 + q->kernel_address); 842 843 else 843 844 hdev->asic_funcs->asic_dma_free_coherent(hdev, 844 845 HL_QUEUE_SIZE_IN_BYTES, 845 - (void *) (uintptr_t) q->kernel_address, 846 + q->kernel_address, 846 847 q->bus_address); 847 848 } 848 849
+9 -8
drivers/misc/habanalabs/common/irq.c
··· 90 90 return IRQ_HANDLED; 91 91 } 92 92 93 - cq_base = (struct hl_cq_entry *) (uintptr_t) cq->kernel_address; 93 + cq_base = cq->kernel_address; 94 94 95 95 while (1) { 96 96 bool entry_ready = ((le32_to_cpu(cq_base[cq->ci].data) & ··· 152 152 struct hl_eq_entry *eq_base; 153 153 struct hl_eqe_work *handle_eqe_work; 154 154 155 - eq_base = (struct hl_eq_entry *) (uintptr_t) eq->kernel_address; 155 + eq_base = eq->kernel_address; 156 156 157 157 while (1) { 158 158 bool entry_ready = ··· 221 221 return -ENOMEM; 222 222 223 223 q->hdev = hdev; 224 - q->kernel_address = (u64) (uintptr_t) p; 224 + q->kernel_address = p; 225 225 q->hw_queue_id = hw_queue_id; 226 226 q->ci = 0; 227 227 q->pi = 0; ··· 242 242 void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q) 243 243 { 244 244 hdev->asic_funcs->asic_dma_free_coherent(hdev, HL_CQ_SIZE_IN_BYTES, 245 - (void *) (uintptr_t) q->kernel_address, q->bus_address); 245 + q->kernel_address, 246 + q->bus_address); 246 247 } 247 248 248 249 void hl_cq_reset(struct hl_device *hdev, struct hl_cq *q) ··· 260 259 * when the device is operational again 261 260 */ 262 261 263 - memset((void *) (uintptr_t) q->kernel_address, 0, HL_CQ_SIZE_IN_BYTES); 262 + memset(q->kernel_address, 0, HL_CQ_SIZE_IN_BYTES); 264 263 } 265 264 266 265 /** ··· 283 282 return -ENOMEM; 284 283 285 284 q->hdev = hdev; 286 - q->kernel_address = (u64) (uintptr_t) p; 285 + q->kernel_address = p; 287 286 q->ci = 0; 288 287 289 288 return 0; ··· 303 302 304 303 hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev, 305 304 HL_EQ_SIZE_IN_BYTES, 306 - (void *) (uintptr_t) q->kernel_address); 305 + q->kernel_address); 307 306 } 308 307 309 308 void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q) ··· 317 316 * when the device is operational again 318 317 */ 319 318 320 - memset((void *) (uintptr_t) q->kernel_address, 0, HL_EQ_SIZE_IN_BYTES); 319 + memset(q->kernel_address, 0, HL_EQ_SIZE_IN_BYTES); 321 320 }
+15 -23
drivers/misc/habanalabs/gaudi/gaudi.c
··· 680 680 if (!cb) 681 681 return -EFAULT; 682 682 683 - init_tpc_mem_pkt = (struct packet_lin_dma *) (uintptr_t) 684 - cb->kernel_address; 683 + init_tpc_mem_pkt = cb->kernel_address; 685 684 cb_size = sizeof(*init_tpc_mem_pkt); 686 685 memset(init_tpc_mem_pkt, 0, cb_size); 687 686 ··· 3810 3811 u16 pkt_size; 3811 3812 struct gaudi_packet *user_pkt; 3812 3813 3813 - user_pkt = (struct gaudi_packet *) (uintptr_t) 3814 - (parser->user_cb->kernel_address + cb_parsed_length); 3814 + user_pkt = parser->user_cb->kernel_address + cb_parsed_length; 3815 3815 3816 3816 pkt_id = (enum packet_id) ( 3817 3817 (le64_to_cpu(user_pkt->header) & ··· 4033 4035 u32 new_pkt_size = 0; 4034 4036 struct gaudi_packet *user_pkt, *kernel_pkt; 4035 4037 4036 - user_pkt = (struct gaudi_packet *) (uintptr_t) 4037 - (parser->user_cb->kernel_address + cb_parsed_length); 4038 - kernel_pkt = (struct gaudi_packet *) (uintptr_t) 4039 - (parser->patched_cb->kernel_address + 4040 - cb_patched_cur_length); 4038 + user_pkt = parser->user_cb->kernel_address + cb_parsed_length; 4039 + kernel_pkt = parser->patched_cb->kernel_address + 4040 + cb_patched_cur_length; 4041 4041 4042 4042 pkt_id = (enum packet_id) ( 4043 4043 (le64_to_cpu(user_pkt->header) & ··· 4151 4155 * The check that parser->user_cb_size <= parser->user_cb->size was done 4152 4156 * in validate_queue_index(). 4153 4157 */ 4154 - memcpy((void *) (uintptr_t) parser->patched_cb->kernel_address, 4155 - (void *) (uintptr_t) parser->user_cb->kernel_address, 4158 + memcpy(parser->patched_cb->kernel_address, 4159 + parser->user_cb->kernel_address, 4156 4160 parser->user_cb_size); 4157 4161 4158 4162 patched_cb_size = parser->patched_cb_size; ··· 4286 4290 } 4287 4291 4288 4292 static void gaudi_add_end_of_cb_packets(struct hl_device *hdev, 4289 - u64 kernel_address, u32 len, 4293 + void *kernel_address, u32 len, 4290 4294 u64 cq_addr, u32 cq_val, u32 msi_vec, 4291 4295 bool eb) 4292 4296 { ··· 4294 4298 struct packet_msg_prot *cq_pkt; 4295 4299 u32 tmp; 4296 4300 4297 - cq_pkt = (struct packet_msg_prot *) (uintptr_t) 4298 - (kernel_address + len - (sizeof(struct packet_msg_prot) * 2)); 4301 + cq_pkt = kernel_address + len - (sizeof(struct packet_msg_prot) * 2); 4299 4302 4300 4303 tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT); 4301 4304 tmp |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1); ··· 4337 4342 if (!cb) 4338 4343 return -EFAULT; 4339 4344 4340 - lin_dma_pkt = (struct packet_lin_dma *) (uintptr_t) cb->kernel_address; 4345 + lin_dma_pkt = cb->kernel_address; 4341 4346 memset(lin_dma_pkt, 0, sizeof(*lin_dma_pkt)); 4342 4347 cb_size = sizeof(*lin_dma_pkt); 4343 4348 ··· 4742 4747 (addr - gaudi->hbm_bar_cur_addr)); 4743 4748 } 4744 4749 4745 - static void gaudi_mmu_prepare_reg(struct hl_device *hdev, u64 reg, u32 asid) 4750 + void gaudi_mmu_prepare_reg(struct hl_device *hdev, u64 reg, u32 asid) 4746 4751 { 4747 4752 /* mask to zero the MMBP and ASID bits */ 4748 4753 WREG32_AND(reg, ~0x7FF); ··· 4910 4915 gaudi_mmu_prepare_reg(hdev, mmMME2_ACC_WBC, asid); 4911 4916 gaudi_mmu_prepare_reg(hdev, mmMME3_ACC_WBC, asid); 4912 4917 4913 - gaudi_mmu_prepare_reg(hdev, mmPSOC_GLOBAL_CONF_TRACE_ARUSER, asid); 4914 - gaudi_mmu_prepare_reg(hdev, mmPSOC_GLOBAL_CONF_TRACE_AWUSER, asid); 4915 - 4916 4918 hdev->asic_funcs->set_clock_gating(hdev); 4917 4919 4918 4920 mutex_unlock(&gaudi->clk_gate_mutex); ··· 4946 4954 4947 4955 cb = job->patched_cb; 4948 4956 4949 - fence_pkt = (struct packet_msg_prot *) (uintptr_t) (cb->kernel_address + 4950 - job->job_cb_size - sizeof(struct packet_msg_prot)); 4957 + fence_pkt = cb->kernel_address + 4958 + job->job_cb_size - sizeof(struct packet_msg_prot); 4951 4959 4952 4960 tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT); 4953 4961 tmp |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 1); ··· 6378 6386 struct packet_msg_short *pkt; 6379 6387 u32 value, ctl; 6380 6388 6381 - pkt = (struct packet_msg_short *) (uintptr_t) cb->kernel_address; 6389 + pkt = cb->kernel_address; 6382 6390 memset(pkt, 0, sizeof(*pkt)); 6383 6391 6384 6392 /* Inc by 1, Mode ADD */ ··· 6470 6478 u16 sob_val, u16 mon_id, u32 q_idx) 6471 6479 { 6472 6480 struct hl_cb *cb = (struct hl_cb *) data; 6473 - void *buf = (void *) (uintptr_t) cb->kernel_address; 6481 + void *buf = cb->kernel_address; 6474 6482 u64 monitor_base, fence_addr = 0; 6475 6483 u32 size = 0; 6476 6484 u16 msg_addr_offset;
+1
drivers/misc/habanalabs/gaudi/gaudiP.h
··· 271 271 int gaudi_debug_coresight(struct hl_device *hdev, void *data); 272 272 void gaudi_halt_coresight(struct hl_device *hdev); 273 273 int gaudi_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk); 274 + void gaudi_mmu_prepare_reg(struct hl_device *hdev, u64 reg, u32 asid); 274 275 275 276 #endif /* GAUDIP_H_ */
+5
drivers/misc/habanalabs/gaudi/gaudi_coresight.c
··· 623 623 return -EINVAL; 624 624 } 625 625 626 + gaudi_mmu_prepare_reg(hdev, mmPSOC_GLOBAL_CONF_TRACE_ARUSER, 627 + hdev->compute_ctx->asid); 628 + gaudi_mmu_prepare_reg(hdev, mmPSOC_GLOBAL_CONF_TRACE_AWUSER, 629 + hdev->compute_ctx->asid); 630 + 626 631 msb = upper_32_bits(input->buffer_address) >> 8; 627 632 msb &= PSOC_GLOBAL_CONF_TRACE_ADDR_MSB_MASK; 628 633 WREG32(mmPSOC_GLOBAL_CONF_TRACE_ADDR, msb);
+11 -15
drivers/misc/habanalabs/goya/goya.c
··· 2882 2882 2883 2883 cb = job->patched_cb; 2884 2884 2885 - fence_pkt = (struct packet_msg_prot *) (uintptr_t) (cb->kernel_address + 2886 - job->job_cb_size - sizeof(struct packet_msg_prot)); 2885 + fence_pkt = cb->kernel_address + 2886 + job->job_cb_size - sizeof(struct packet_msg_prot); 2887 2887 2888 2888 tmp = (PACKET_MSG_PROT << GOYA_PKT_CTL_OPCODE_SHIFT) | 2889 2889 (1 << GOYA_PKT_CTL_EB_SHIFT) | ··· 3475 3475 u16 pkt_size; 3476 3476 struct goya_packet *user_pkt; 3477 3477 3478 - user_pkt = (struct goya_packet *) (uintptr_t) 3479 - (parser->user_cb->kernel_address + cb_parsed_length); 3478 + user_pkt = parser->user_cb->kernel_address + cb_parsed_length; 3480 3479 3481 3480 pkt_id = (enum packet_id) ( 3482 3481 (le64_to_cpu(user_pkt->header) & ··· 3712 3713 u32 new_pkt_size = 0; 3713 3714 struct goya_packet *user_pkt, *kernel_pkt; 3714 3715 3715 - user_pkt = (struct goya_packet *) (uintptr_t) 3716 - (parser->user_cb->kernel_address + cb_parsed_length); 3717 - kernel_pkt = (struct goya_packet *) (uintptr_t) 3718 - (parser->patched_cb->kernel_address + 3719 - cb_patched_cur_length); 3716 + user_pkt = parser->user_cb->kernel_address + cb_parsed_length; 3717 + kernel_pkt = parser->patched_cb->kernel_address + 3718 + cb_patched_cur_length; 3720 3719 3721 3720 pkt_id = (enum packet_id) ( 3722 3721 (le64_to_cpu(user_pkt->header) & ··· 3838 3841 * The check that parser->user_cb_size <= parser->user_cb->size was done 3839 3842 * in validate_queue_index(). 3840 3843 */ 3841 - memcpy((void *) (uintptr_t) parser->patched_cb->kernel_address, 3842 - (void *) (uintptr_t) parser->user_cb->kernel_address, 3844 + memcpy(parser->patched_cb->kernel_address, 3845 + parser->user_cb->kernel_address, 3843 3846 parser->user_cb_size); 3844 3847 3845 3848 patched_cb_size = parser->patched_cb_size; ··· 3971 3974 return goya_parse_cb_no_mmu(hdev, parser); 3972 3975 } 3973 3976 3974 - void goya_add_end_of_cb_packets(struct hl_device *hdev, u64 kernel_address, 3977 + void goya_add_end_of_cb_packets(struct hl_device *hdev, void *kernel_address, 3975 3978 u32 len, u64 cq_addr, u32 cq_val, u32 msix_vec, 3976 3979 bool eb) 3977 3980 { 3978 3981 struct packet_msg_prot *cq_pkt; 3979 3982 u32 tmp; 3980 3983 3981 - cq_pkt = (struct packet_msg_prot *) (uintptr_t) 3982 - (kernel_address + len - (sizeof(struct packet_msg_prot) * 2)); 3984 + cq_pkt = kernel_address + len - (sizeof(struct packet_msg_prot) * 2); 3983 3985 3984 3986 tmp = (PACKET_MSG_PROT << GOYA_PKT_CTL_OPCODE_SHIFT) | 3985 3987 (1 << GOYA_PKT_CTL_EB_SHIFT) | ··· 4742 4746 if (!cb) 4743 4747 return -ENOMEM; 4744 4748 4745 - lin_dma_pkt = (struct packet_lin_dma *) (uintptr_t) cb->kernel_address; 4749 + lin_dma_pkt = cb->kernel_address; 4746 4750 4747 4751 do { 4748 4752 memset(lin_dma_pkt, 0, sizeof(*lin_dma_pkt));
+1 -1
drivers/misc/habanalabs/goya/goyaP.h
··· 217 217 void goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry); 218 218 void *goya_get_events_stat(struct hl_device *hdev, bool aggregate, u32 *size); 219 219 220 - void goya_add_end_of_cb_packets(struct hl_device *hdev, u64 kernel_address, 220 + void goya_add_end_of_cb_packets(struct hl_device *hdev, void *kernel_address, 221 221 u32 len, u64 cq_addr, u32 cq_val, u32 msix_vec, 222 222 bool eb); 223 223 int goya_cs_parser(struct hl_device *hdev, struct hl_cs_parser *parser);
-1
drivers/misc/habanalabs/include/gaudi/gaudi_masks.h
··· 421 421 422 422 #define QM_ARB_ERR_MSG_EN_MASK (\ 423 423 QM_ARB_ERR_MSG_EN_CHOISE_OVF_MASK |\ 424 - QM_ARB_ERR_MSG_EN_CHOISE_WDT_MASK |\ 425 424 QM_ARB_ERR_MSG_EN_AXI_LBW_ERR_MASK) 426 425 427 426 #define PCIE_AUX_FLR_CTRL_HW_CTRL_MASK 0x1
+2 -2
drivers/misc/mei/client.h
··· 182 182 * 183 183 * @cl: host client 184 184 * 185 - * Return: mtu 185 + * Return: mtu or 0 if client is not connected 186 186 */ 187 187 static inline size_t mei_cl_mtu(const struct mei_cl *cl) 188 188 { 189 - return cl->me_cl->props.max_msg_length; 189 + return cl->me_cl ? cl->me_cl->props.max_msg_length : 0; 190 190 } 191 191 192 192 /**
+1 -13
drivers/mmc/host/renesas_sdhi_core.c
··· 572 572 TMIO_MASK_INIT_RCAR2); 573 573 } 574 574 575 - /* 576 - * This is a temporary workaround! This driver used 'hw_reset' wrongly and the 577 - * fix for that showed a regression. So, we mimic the old behaviour until the 578 - * proper solution is found. 579 - */ 580 - static void renesas_sdhi_hw_reset(struct mmc_host *mmc) 581 - { 582 - struct tmio_mmc_host *host = mmc_priv(mmc); 583 - renesas_sdhi_reset(host); 584 - } 585 - 586 575 #define SH_MOBILE_SDHI_MIN_TAP_ROW 3 587 576 588 577 static int renesas_sdhi_select_tuning(struct tmio_mmc_host *host) ··· 1009 1020 if (of_data && of_data->scc_offset) { 1010 1021 priv->scc_ctl = host->ctl + of_data->scc_offset; 1011 1022 host->reset = renesas_sdhi_reset; 1012 - host->ops.hw_reset = renesas_sdhi_hw_reset; 1013 - host->mmc->caps |= MMC_CAP_HW_RESET; 1014 1023 } 1015 1024 } 1016 1025 ··· 1147 1160 1148 1161 tmio_mmc_host_remove(host); 1149 1162 renesas_sdhi_clk_disable(host); 1163 + tmio_mmc_host_free(host); 1150 1164 1151 1165 return 0; 1152 1166 }
+2
drivers/mmc/host/sdhci-of-esdhc.c
··· 1324 1324 1325 1325 static struct soc_device_attribute soc_unreliable_pulse_detection[] = { 1326 1326 { .family = "QorIQ LX2160A", .revision = "1.0", }, 1327 + { .family = "QorIQ LX2160A", .revision = "2.0", }, 1328 + { .family = "QorIQ LS1028A", .revision = "1.0", }, 1327 1329 { }, 1328 1330 }; 1329 1331
+5 -2
drivers/mmc/host/tmio_mmc_core.c
··· 175 175 if (host->reset) 176 176 host->reset(host); 177 177 178 + tmio_mmc_abort_dma(host); 179 + 178 180 if (host->pdata->flags & TMIO_MMC_SDIO_IRQ) { 179 181 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask); 180 182 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001); ··· 225 223 226 224 /* Ready for new calls */ 227 225 host->mrq = NULL; 228 - 229 - tmio_mmc_abort_dma(host); 230 226 mmc_request_done(host->mmc, mrq); 231 227 } 232 228 ··· 927 927 switch (ios->power_mode) { 928 928 case MMC_POWER_OFF: 929 929 tmio_mmc_power_off(host); 930 + /* Downgrade ensures a sane state for tuning HW (e.g. SCC) */ 931 + if (host->mmc->ops->hs400_downgrade) 932 + host->mmc->ops->hs400_downgrade(host->mmc); 930 933 host->set_clock(host, 0); 931 934 break; 932 935 case MMC_POWER_UP:
-2
drivers/nvme/host/core.c
··· 2060 2060 2061 2061 if (id->nsattr & NVME_NS_ATTR_RO) 2062 2062 set_disk_ro(disk, true); 2063 - else 2064 - set_disk_ro(disk, false); 2065 2063 } 2066 2064 2067 2065 static inline bool nvme_first_scan(struct gendisk *disk)
+3 -1
drivers/of/address.c
··· 1034 1034 */ 1035 1035 bool of_dma_is_coherent(struct device_node *np) 1036 1036 { 1037 - struct device_node *node = of_node_get(np); 1037 + struct device_node *node; 1038 1038 1039 1039 if (IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT)) 1040 1040 return true; 1041 + 1042 + node = of_node_get(np); 1041 1043 1042 1044 while (node) { 1043 1045 if (of_property_read_bool(node, "dma-coherent")) {
+4 -3
drivers/pinctrl/aspeed/pinctrl-aspeed.c
··· 286 286 static bool aspeed_expr_is_gpio(const struct aspeed_sig_expr *expr) 287 287 { 288 288 /* 289 - * The signal type is GPIO if the signal name has "GPIO" as a prefix. 289 + * The signal type is GPIO if the signal name has "GPI" as a prefix. 290 290 * strncmp (rather than strcmp) is used to implement the prefix 291 291 * requirement. 292 292 * 293 - * expr->signal might look like "GPIOT3" in the GPIO case. 293 + * expr->signal might look like "GPIOB1" in the GPIO case. 294 + * expr->signal might look like "GPIT0" in the GPI case. 294 295 */ 295 - return strncmp(expr->signal, "GPIO", 4) == 0; 296 + return strncmp(expr->signal, "GPI", 3) == 0; 296 297 } 297 298 298 299 static bool aspeed_gpio_in_exprs(const struct aspeed_sig_expr **exprs)
+30 -10
drivers/pinctrl/intel/pinctrl-intel.c
··· 62 62 #define PADCFG1_TERM_UP BIT(13) 63 63 #define PADCFG1_TERM_SHIFT 10 64 64 #define PADCFG1_TERM_MASK GENMASK(12, 10) 65 - #define PADCFG1_TERM_20K 4 66 - #define PADCFG1_TERM_2K 3 67 - #define PADCFG1_TERM_5K 2 68 - #define PADCFG1_TERM_1K 1 65 + #define PADCFG1_TERM_20K BIT(2) 66 + #define PADCFG1_TERM_5K BIT(1) 67 + #define PADCFG1_TERM_1K BIT(0) 68 + #define PADCFG1_TERM_833 (BIT(1) | BIT(0)) 69 69 70 70 #define PADCFG2 0x008 71 71 #define PADCFG2_DEBEN BIT(0) ··· 549 549 return -EINVAL; 550 550 551 551 switch (term) { 552 + case PADCFG1_TERM_833: 553 + *arg = 833; 554 + break; 552 555 case PADCFG1_TERM_1K: 553 556 *arg = 1000; 554 - break; 555 - case PADCFG1_TERM_2K: 556 - *arg = 2000; 557 557 break; 558 558 case PADCFG1_TERM_5K: 559 559 *arg = 5000; ··· 570 570 return -EINVAL; 571 571 572 572 switch (term) { 573 + case PADCFG1_TERM_833: 574 + if (!(community->features & PINCTRL_FEATURE_1K_PD)) 575 + return -EINVAL; 576 + *arg = 833; 577 + break; 573 578 case PADCFG1_TERM_1K: 574 579 if (!(community->features & PINCTRL_FEATURE_1K_PD)) 575 580 return -EINVAL; ··· 683 678 684 679 value |= PADCFG1_TERM_UP; 685 680 681 + /* Set default strength value in case none is given */ 682 + if (arg == 1) 683 + arg = 5000; 684 + 686 685 switch (arg) { 687 686 case 20000: 688 687 value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT; ··· 694 685 case 5000: 695 686 value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT; 696 687 break; 697 - case 2000: 698 - value |= PADCFG1_TERM_2K << PADCFG1_TERM_SHIFT; 699 - break; 700 688 case 1000: 701 689 value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT; 690 + break; 691 + case 833: 692 + value |= PADCFG1_TERM_833 << PADCFG1_TERM_SHIFT; 702 693 break; 703 694 default: 704 695 ret = -EINVAL; ··· 708 699 709 700 case PIN_CONFIG_BIAS_PULL_DOWN: 710 701 value &= ~(PADCFG1_TERM_UP | PADCFG1_TERM_MASK); 702 + 703 + /* Set default strength value in case none is given */ 704 + if (arg == 1) 705 + arg = 5000; 711 706 712 707 switch (arg) { 713 708 case 20000: ··· 726 713 break; 727 714 } 728 715 value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT; 716 + break; 717 + case 833: 718 + if (!(community->features & PINCTRL_FEATURE_1K_PD)) { 719 + ret = -EINVAL; 720 + break; 721 + } 722 + value |= PADCFG1_TERM_833 << PADCFG1_TERM_SHIFT; 729 723 break; 730 724 default: 731 725 ret = -EINVAL;
+3 -3
drivers/pinctrl/pinctrl-amd.c
··· 156 156 pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF); 157 157 pin_reg &= ~BIT(DB_TMR_LARGE_OFF); 158 158 } else if (debounce < 250000) { 159 - time = debounce / 15600; 159 + time = debounce / 15625; 160 160 pin_reg |= time & DB_TMR_OUT_MASK; 161 161 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF); 162 162 pin_reg |= BIT(DB_TMR_LARGE_OFF); ··· 166 166 pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF); 167 167 pin_reg |= BIT(DB_TMR_LARGE_OFF); 168 168 } else { 169 - pin_reg &= ~DB_CNTRl_MASK; 169 + pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF); 170 170 ret = -EINVAL; 171 171 } 172 172 } else { 173 173 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF); 174 174 pin_reg &= ~BIT(DB_TMR_LARGE_OFF); 175 175 pin_reg &= ~DB_TMR_OUT_MASK; 176 - pin_reg &= ~DB_CNTRl_MASK; 176 + pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF); 177 177 } 178 178 writel(pin_reg, gpio_dev->base + offset * 4); 179 179 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
+36 -36
drivers/pinctrl/pinctrl-ingenic.c
··· 635 635 static int jz4770_uart3_hwflow_pins[] = { 0x88, 0x89, }; 636 636 static int jz4770_ssi0_dt_a_pins[] = { 0x15, }; 637 637 static int jz4770_ssi0_dt_b_pins[] = { 0x35, }; 638 - static int jz4770_ssi0_dt_d_pins[] = { 0x55, }; 639 - static int jz4770_ssi0_dt_e_pins[] = { 0x71, }; 638 + static int jz4770_ssi0_dt_d_pins[] = { 0x75, }; 639 + static int jz4770_ssi0_dt_e_pins[] = { 0x91, }; 640 640 static int jz4770_ssi0_dr_a_pins[] = { 0x14, }; 641 641 static int jz4770_ssi0_dr_b_pins[] = { 0x34, }; 642 - static int jz4770_ssi0_dr_d_pins[] = { 0x54, }; 643 - static int jz4770_ssi0_dr_e_pins[] = { 0x6e, }; 642 + static int jz4770_ssi0_dr_d_pins[] = { 0x74, }; 643 + static int jz4770_ssi0_dr_e_pins[] = { 0x8e, }; 644 644 static int jz4770_ssi0_clk_a_pins[] = { 0x12, }; 645 645 static int jz4770_ssi0_clk_b_pins[] = { 0x3c, }; 646 - static int jz4770_ssi0_clk_d_pins[] = { 0x58, }; 647 - static int jz4770_ssi0_clk_e_pins[] = { 0x6f, }; 646 + static int jz4770_ssi0_clk_d_pins[] = { 0x78, }; 647 + static int jz4770_ssi0_clk_e_pins[] = { 0x8f, }; 648 648 static int jz4770_ssi0_gpc_b_pins[] = { 0x3e, }; 649 - static int jz4770_ssi0_gpc_d_pins[] = { 0x56, }; 650 - static int jz4770_ssi0_gpc_e_pins[] = { 0x73, }; 649 + static int jz4770_ssi0_gpc_d_pins[] = { 0x76, }; 650 + static int jz4770_ssi0_gpc_e_pins[] = { 0x93, }; 651 651 static int jz4770_ssi0_ce0_a_pins[] = { 0x13, }; 652 652 static int jz4770_ssi0_ce0_b_pins[] = { 0x3d, }; 653 - static int jz4770_ssi0_ce0_d_pins[] = { 0x59, }; 654 - static int jz4770_ssi0_ce0_e_pins[] = { 0x70, }; 653 + static int jz4770_ssi0_ce0_d_pins[] = { 0x79, }; 654 + static int jz4770_ssi0_ce0_e_pins[] = { 0x90, }; 655 655 static int jz4770_ssi0_ce1_b_pins[] = { 0x3f, }; 656 - static int jz4770_ssi0_ce1_d_pins[] = { 0x57, }; 657 - static int jz4770_ssi0_ce1_e_pins[] = { 0x72, }; 656 + static int jz4770_ssi0_ce1_d_pins[] = { 0x77, }; 657 + static int jz4770_ssi0_ce1_e_pins[] = { 0x92, }; 658 658 static int jz4770_ssi1_dt_b_pins[] = { 0x35, }; 659 - static int jz4770_ssi1_dt_d_pins[] = { 0x55, }; 660 - static int jz4770_ssi1_dt_e_pins[] = { 0x71, }; 659 + static int jz4770_ssi1_dt_d_pins[] = { 0x75, }; 660 + static int jz4770_ssi1_dt_e_pins[] = { 0x91, }; 661 661 static int jz4770_ssi1_dr_b_pins[] = { 0x34, }; 662 - static int jz4770_ssi1_dr_d_pins[] = { 0x54, }; 663 - static int jz4770_ssi1_dr_e_pins[] = { 0x6e, }; 662 + static int jz4770_ssi1_dr_d_pins[] = { 0x74, }; 663 + static int jz4770_ssi1_dr_e_pins[] = { 0x8e, }; 664 664 static int jz4770_ssi1_clk_b_pins[] = { 0x3c, }; 665 - static int jz4770_ssi1_clk_d_pins[] = { 0x58, }; 666 - static int jz4770_ssi1_clk_e_pins[] = { 0x6f, }; 665 + static int jz4770_ssi1_clk_d_pins[] = { 0x78, }; 666 + static int jz4770_ssi1_clk_e_pins[] = { 0x8f, }; 667 667 static int jz4770_ssi1_gpc_b_pins[] = { 0x3e, }; 668 - static int jz4770_ssi1_gpc_d_pins[] = { 0x56, }; 669 - static int jz4770_ssi1_gpc_e_pins[] = { 0x73, }; 668 + static int jz4770_ssi1_gpc_d_pins[] = { 0x76, }; 669 + static int jz4770_ssi1_gpc_e_pins[] = { 0x93, }; 670 670 static int jz4770_ssi1_ce0_b_pins[] = { 0x3d, }; 671 - static int jz4770_ssi1_ce0_d_pins[] = { 0x59, }; 672 - static int jz4770_ssi1_ce0_e_pins[] = { 0x70, }; 671 + static int jz4770_ssi1_ce0_d_pins[] = { 0x79, }; 672 + static int jz4770_ssi1_ce0_e_pins[] = { 0x90, }; 673 673 static int jz4770_ssi1_ce1_b_pins[] = { 0x3f, }; 674 - static int jz4770_ssi1_ce1_d_pins[] = { 0x57, }; 675 - static int jz4770_ssi1_ce1_e_pins[] = { 0x72, }; 674 + static int jz4770_ssi1_ce1_d_pins[] = { 0x77, }; 675 + static int jz4770_ssi1_ce1_e_pins[] = { 0x92, }; 676 676 static int jz4770_mmc0_1bit_a_pins[] = { 0x12, 0x13, 0x14, }; 677 677 static int jz4770_mmc0_4bit_a_pins[] = { 0x15, 0x16, 0x17, }; 678 678 static int jz4770_mmc0_1bit_e_pins[] = { 0x9c, 0x9d, 0x94, }; ··· 1050 1050 static int jz4780_ssi0_dt_a_21_pins[] = { 0x15, }; 1051 1051 static int jz4780_ssi0_dt_a_28_pins[] = { 0x1c, }; 1052 1052 static int jz4780_ssi0_dt_b_pins[] = { 0x3d, }; 1053 - static int jz4780_ssi0_dt_d_pins[] = { 0x59, }; 1053 + static int jz4780_ssi0_dt_d_pins[] = { 0x79, }; 1054 1054 static int jz4780_ssi0_dr_a_20_pins[] = { 0x14, }; 1055 1055 static int jz4780_ssi0_dr_a_27_pins[] = { 0x1b, }; 1056 1056 static int jz4780_ssi0_dr_b_pins[] = { 0x34, }; 1057 - static int jz4780_ssi0_dr_d_pins[] = { 0x54, }; 1057 + static int jz4780_ssi0_dr_d_pins[] = { 0x74, }; 1058 1058 static int jz4780_ssi0_clk_a_pins[] = { 0x12, }; 1059 1059 static int jz4780_ssi0_clk_b_5_pins[] = { 0x25, }; 1060 1060 static int jz4780_ssi0_clk_b_28_pins[] = { 0x3c, }; 1061 - static int jz4780_ssi0_clk_d_pins[] = { 0x58, }; 1061 + static int jz4780_ssi0_clk_d_pins[] = { 0x78, }; 1062 1062 static int jz4780_ssi0_gpc_b_pins[] = { 0x3e, }; 1063 - static int jz4780_ssi0_gpc_d_pins[] = { 0x56, }; 1063 + static int jz4780_ssi0_gpc_d_pins[] = { 0x76, }; 1064 1064 static int jz4780_ssi0_ce0_a_23_pins[] = { 0x17, }; 1065 1065 static int jz4780_ssi0_ce0_a_25_pins[] = { 0x19, }; 1066 1066 static int jz4780_ssi0_ce0_b_pins[] = { 0x3f, }; 1067 - static int jz4780_ssi0_ce0_d_pins[] = { 0x57, }; 1067 + static int jz4780_ssi0_ce0_d_pins[] = { 0x77, }; 1068 1068 static int jz4780_ssi0_ce1_b_pins[] = { 0x35, }; 1069 - static int jz4780_ssi0_ce1_d_pins[] = { 0x55, }; 1069 + static int jz4780_ssi0_ce1_d_pins[] = { 0x75, }; 1070 1070 static int jz4780_ssi1_dt_b_pins[] = { 0x3d, }; 1071 - static int jz4780_ssi1_dt_d_pins[] = { 0x59, }; 1071 + static int jz4780_ssi1_dt_d_pins[] = { 0x79, }; 1072 1072 static int jz4780_ssi1_dr_b_pins[] = { 0x34, }; 1073 - static int jz4780_ssi1_dr_d_pins[] = { 0x54, }; 1073 + static int jz4780_ssi1_dr_d_pins[] = { 0x74, }; 1074 1074 static int jz4780_ssi1_clk_b_pins[] = { 0x3c, }; 1075 - static int jz4780_ssi1_clk_d_pins[] = { 0x58, }; 1075 + static int jz4780_ssi1_clk_d_pins[] = { 0x78, }; 1076 1076 static int jz4780_ssi1_gpc_b_pins[] = { 0x3e, }; 1077 - static int jz4780_ssi1_gpc_d_pins[] = { 0x56, }; 1077 + static int jz4780_ssi1_gpc_d_pins[] = { 0x76, }; 1078 1078 static int jz4780_ssi1_ce0_b_pins[] = { 0x3f, }; 1079 - static int jz4780_ssi1_ce0_d_pins[] = { 0x57, }; 1079 + static int jz4780_ssi1_ce0_d_pins[] = { 0x77, }; 1080 1080 static int jz4780_ssi1_ce1_b_pins[] = { 0x35, }; 1081 - static int jz4780_ssi1_ce1_d_pins[] = { 0x55, }; 1081 + static int jz4780_ssi1_ce1_d_pins[] = { 0x75, }; 1082 1082 static int jz4780_mmc0_8bit_a_pins[] = { 0x04, 0x05, 0x06, 0x07, 0x18, }; 1083 1083 static int jz4780_i2c3_pins[] = { 0x6a, 0x6b, }; 1084 1084 static int jz4780_i2c4_e_pins[] = { 0x8c, 0x8d, };
+3 -1
drivers/pinctrl/pinctrl-mcp23s08_spi.c
··· 119 119 return -EINVAL; 120 120 } 121 121 122 - copy = devm_kmemdup(dev, &config, sizeof(config), GFP_KERNEL); 122 + copy = devm_kmemdup(dev, config, sizeof(*config), GFP_KERNEL); 123 123 if (!copy) 124 124 return -ENOMEM; 125 125 126 126 copy->name = name; 127 127 128 128 mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp, copy); 129 + if (IS_ERR(mcp->regmap)) 130 + dev_err(dev, "regmap init failed for %s\n", mcp->chip.label); 129 131 return PTR_ERR_OR_ZERO(mcp->regmap); 130 132 } 131 133
+14 -16
drivers/pinctrl/pinctrl-rockchip.c
··· 3155 3155 if (!bank->domain) 3156 3156 return -ENXIO; 3157 3157 3158 + clk_enable(bank->clk); 3158 3159 virq = irq_create_mapping(bank->domain, offset); 3160 + clk_disable(bank->clk); 3159 3161 3160 3162 return (virq) ? : -ENXIO; 3161 3163 } ··· 3196 3194 3197 3195 irq = __ffs(pend); 3198 3196 pend &= ~BIT(irq); 3199 - virq = irq_linear_revmap(bank->domain, irq); 3197 + virq = irq_find_mapping(bank->domain, irq); 3200 3198 3201 3199 if (!virq) { 3202 3200 dev_err(bank->drvdata->dev, "unmapped irq %d\n", irq); ··· 3375 3373 unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN; 3376 3374 struct irq_chip_generic *gc; 3377 3375 int ret; 3378 - int i, j; 3376 + int i; 3379 3377 3380 3378 for (i = 0; i < ctrl->nr_banks; ++i, ++bank) { 3381 3379 if (!bank->valid) { ··· 3402 3400 3403 3401 ret = irq_alloc_domain_generic_chips(bank->domain, 32, 1, 3404 3402 "rockchip_gpio_irq", handle_level_irq, 3405 - clr, 0, IRQ_GC_INIT_MASK_CACHE); 3403 + clr, 0, 0); 3406 3404 if (ret) { 3407 3405 dev_err(&pdev->dev, "could not alloc generic chips for bank %s\n", 3408 3406 bank->name); ··· 3410 3408 clk_disable(bank->clk); 3411 3409 continue; 3412 3410 } 3413 - 3414 - /* 3415 - * Linux assumes that all interrupts start out disabled/masked. 3416 - * Our driver only uses the concept of masked and always keeps 3417 - * things enabled, so for us that's all masked and all enabled. 3418 - */ 3419 - writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTMASK); 3420 - writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTEN); 3421 3411 3422 3412 gc = irq_get_domain_generic_chip(bank->domain, 0); 3423 3413 gc->reg_base = bank->reg_base; ··· 3427 3433 gc->chip_types[0].chip.irq_set_type = rockchip_irq_set_type; 3428 3434 gc->wake_enabled = IRQ_MSK(bank->nr_pins); 3429 3435 3436 + /* 3437 + * Linux assumes that all interrupts start out disabled/masked. 3438 + * Our driver only uses the concept of masked and always keeps 3439 + * things enabled, so for us that's all masked and all enabled. 3440 + */ 3441 + writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTMASK); 3442 + writel_relaxed(0xffffffff, bank->reg_base + GPIO_INTEN); 3443 + gc->mask_cache = 0xffffffff; 3444 + 3430 3445 irq_set_chained_handler_and_data(bank->irq, 3431 3446 rockchip_irq_demux, bank); 3432 - 3433 - /* map the gpio irqs here, when the clock is still running */ 3434 - for (j = 0 ; j < 32 ; j++) 3435 - irq_create_mapping(bank->domain, j); 3436 - 3437 3447 clk_disable(bank->clk); 3438 3448 } 3439 3449
+20 -14
drivers/pinctrl/qcom/pinctrl-msm.c
··· 815 815 816 816 static void msm_gpio_irq_enable(struct irq_data *d) 817 817 { 818 - /* 819 - * Clear the interrupt that may be pending before we enable 820 - * the line. 821 - * This is especially a problem with the GPIOs routed to the 822 - * PDC. These GPIOs are direct-connect interrupts to the GIC. 823 - * Disabling the interrupt line at the PDC does not prevent 824 - * the interrupt from being latched at the GIC. The state at 825 - * GIC needs to be cleared before enabling. 826 - */ 827 - if (d->parent_data) { 828 - irq_chip_set_parent_state(d, IRQCHIP_STATE_PENDING, 0); 829 - irq_chip_enable_parent(d); 830 - } 818 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 819 + struct msm_pinctrl *pctrl = gpiochip_get_data(gc); 831 820 832 - msm_gpio_irq_clear_unmask(d, true); 821 + if (d->parent_data) 822 + irq_chip_enable_parent(d); 823 + 824 + if (!test_bit(d->hwirq, pctrl->skip_wake_irqs)) 825 + msm_gpio_irq_clear_unmask(d, true); 833 826 } 834 827 835 828 static void msm_gpio_irq_disable(struct irq_data *d) ··· 1097 1104 ret = -EINVAL; 1098 1105 goto out; 1099 1106 } 1107 + 1108 + /* 1109 + * Clear the interrupt that may be pending before we enable 1110 + * the line. 1111 + * This is especially a problem with the GPIOs routed to the 1112 + * PDC. These GPIOs are direct-connect interrupts to the GIC. 1113 + * Disabling the interrupt line at the PDC does not prevent 1114 + * the interrupt from being latched at the GIC. The state at 1115 + * GIC needs to be cleared before enabling. 1116 + */ 1117 + if (d->parent_data && test_bit(d->hwirq, pctrl->skip_wake_irqs)) 1118 + irq_chip_set_parent_state(d, IRQCHIP_STATE_PENDING, 0); 1119 + 1100 1120 return 0; 1101 1121 out: 1102 1122 module_put(gc->owner);
+18
drivers/pinctrl/qcom/pinctrl-sm8250.c
··· 1313 1313 [183] = SDC_PINGROUP(sdc2_data, 0xb7000, 9, 0), 1314 1314 }; 1315 1315 1316 + static const struct msm_gpio_wakeirq_map sm8250_pdc_map[] = { 1317 + { 0, 79 }, { 1, 84 }, { 2, 80 }, { 3, 82 }, { 4, 107 }, { 7, 43 }, 1318 + { 11, 42 }, { 14, 44 }, { 15, 52 }, { 19, 67 }, { 23, 68 }, { 24, 105 }, 1319 + { 27, 92 }, { 28, 106 }, { 31, 69 }, { 35, 70 }, { 39, 37 }, 1320 + { 40, 108 }, { 43, 71 }, { 45, 72 }, { 47, 83 }, { 51, 74 }, { 55, 77 }, 1321 + { 59, 78 }, { 63, 75 }, { 64, 81 }, { 65, 87 }, { 66, 88 }, { 67, 89 }, 1322 + { 68, 54 }, { 70, 85 }, { 77, 46 }, { 80, 90 }, { 81, 91 }, { 83, 97 }, 1323 + { 84, 98 }, { 86, 99 }, { 87, 100 }, { 88, 101 }, { 89, 102 }, 1324 + { 92, 103 }, { 93, 104 }, { 100, 53 }, { 103, 47 }, { 104, 48 }, 1325 + { 108, 49 }, { 109, 94 }, { 110, 95 }, { 111, 96 }, { 112, 55 }, 1326 + { 113, 56 }, { 118, 50 }, { 121, 51 }, { 122, 57 }, { 123, 58 }, 1327 + { 124, 45 }, { 126, 59 }, { 128, 76 }, { 129, 86 }, { 132, 93 }, 1328 + { 133, 65 }, { 134, 66 }, { 136, 62 }, { 137, 63 }, { 138, 64 }, 1329 + { 142, 60 }, { 143, 61 } 1330 + }; 1331 + 1316 1332 static const struct msm_pinctrl_soc_data sm8250_pinctrl = { 1317 1333 .pins = sm8250_pins, 1318 1334 .npins = ARRAY_SIZE(sm8250_pins), ··· 1339 1323 .ngpios = 181, 1340 1324 .tiles = sm8250_tiles, 1341 1325 .ntiles = ARRAY_SIZE(sm8250_tiles), 1326 + .wakeirq_map = sm8250_pdc_map, 1327 + .nwakeirq_map = ARRAY_SIZE(sm8250_pdc_map), 1342 1328 }; 1343 1329 1344 1330 static int sm8250_pinctrl_probe(struct platform_device *pdev)
+29 -5
drivers/scsi/ufs/ufshcd.c
··· 1627 1627 */ 1628 1628 fallthrough; 1629 1629 case CLKS_OFF: 1630 - ufshcd_scsi_block_requests(hba); 1631 1630 hba->clk_gating.state = REQ_CLKS_ON; 1632 1631 trace_ufshcd_clk_gating(dev_name(hba->dev), 1633 1632 hba->clk_gating.state); 1634 - queue_work(hba->clk_gating.clk_gating_workq, 1635 - &hba->clk_gating.ungate_work); 1633 + if (queue_work(hba->clk_gating.clk_gating_workq, 1634 + &hba->clk_gating.ungate_work)) 1635 + ufshcd_scsi_block_requests(hba); 1636 1636 /* 1637 1637 * fall through to check if we should wait for this 1638 1638 * work to be done or not. ··· 2115 2115 unsigned long flags; 2116 2116 2117 2117 if (wait_for_completion_timeout(&uic_cmd->done, 2118 - msecs_to_jiffies(UIC_CMD_TIMEOUT))) 2118 + msecs_to_jiffies(UIC_CMD_TIMEOUT))) { 2119 2119 ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT; 2120 - else 2120 + } else { 2121 2121 ret = -ETIMEDOUT; 2122 + dev_err(hba->dev, 2123 + "uic cmd 0x%x with arg3 0x%x completion timeout\n", 2124 + uic_cmd->command, uic_cmd->argument3); 2125 + 2126 + if (!uic_cmd->cmd_active) { 2127 + dev_err(hba->dev, "%s: UIC cmd has been completed, return the result\n", 2128 + __func__); 2129 + ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT; 2130 + } 2131 + } 2122 2132 2123 2133 spin_lock_irqsave(hba->host->host_lock, flags); 2124 2134 hba->active_uic_cmd = NULL; ··· 2160 2150 if (completion) 2161 2151 init_completion(&uic_cmd->done); 2162 2152 2153 + uic_cmd->cmd_active = 1; 2163 2154 ufshcd_dispatch_uic_cmd(hba, uic_cmd); 2164 2155 2165 2156 return 0; ··· 3818 3807 dev_err(hba->dev, 3819 3808 "pwr ctrl cmd 0x%x with mode 0x%x completion timeout\n", 3820 3809 cmd->command, cmd->argument3); 3810 + 3811 + if (!cmd->cmd_active) { 3812 + dev_err(hba->dev, "%s: Power Mode Change operation has been completed, go check UPMCRS\n", 3813 + __func__); 3814 + goto check_upmcrs; 3815 + } 3816 + 3821 3817 ret = -ETIMEDOUT; 3822 3818 goto out; 3823 3819 } 3824 3820 3821 + check_upmcrs: 3825 3822 status = ufshcd_get_upmcrs(hba); 3826 3823 if (status != PWR_LOCAL) { 3827 3824 dev_err(hba->dev, ··· 4921 4902 ufshcd_get_uic_cmd_result(hba); 4922 4903 hba->active_uic_cmd->argument3 = 4923 4904 ufshcd_get_dme_attr_val(hba); 4905 + if (!hba->uic_async_done) 4906 + hba->active_uic_cmd->cmd_active = 0; 4924 4907 complete(&hba->active_uic_cmd->done); 4925 4908 retval = IRQ_HANDLED; 4926 4909 } 4927 4910 4928 4911 if ((intr_status & UFSHCD_UIC_PWR_MASK) && hba->uic_async_done) { 4912 + hba->active_uic_cmd->cmd_active = 0; 4929 4913 complete(hba->uic_async_done); 4930 4914 retval = IRQ_HANDLED; 4931 4915 } ··· 8928 8906 blk_mq_free_tag_set(&hba->tmf_tag_set); 8929 8907 blk_cleanup_queue(hba->cmd_queue); 8930 8908 scsi_remove_host(hba->host); 8909 + destroy_workqueue(hba->eh_wq); 8931 8910 /* disable interrupts */ 8932 8911 ufshcd_disable_intr(hba, hba->intr_mask); 8933 8912 ufshcd_hba_stop(hba); ··· 9229 9206 exit_gating: 9230 9207 ufshcd_exit_clk_scaling(hba); 9231 9208 ufshcd_exit_clk_gating(hba); 9209 + destroy_workqueue(hba->eh_wq); 9232 9210 out_disable: 9233 9211 hba->is_irq_enabled = false; 9234 9212 ufshcd_hba_exit(hba);
+2
drivers/scsi/ufs/ufshcd.h
··· 64 64 * @argument1: UIC command argument 1 65 65 * @argument2: UIC command argument 2 66 66 * @argument3: UIC command argument 3 67 + * @cmd_active: Indicate if UIC command is outstanding 67 68 * @done: UIC command completion 68 69 */ 69 70 struct uic_command { ··· 72 71 u32 argument1; 73 72 u32 argument2; 74 73 u32 argument3; 74 + int cmd_active; 75 75 struct completion done; 76 76 }; 77 77
+1
drivers/thunderbolt/debugfs.c
··· 9 9 10 10 #include <linux/debugfs.h> 11 11 #include <linux/pm_runtime.h> 12 + #include <linux/uaccess.h> 12 13 13 14 #include "tb.h" 14 15
+2
drivers/thunderbolt/icm.c
··· 2284 2284 2285 2285 case PCI_DEVICE_ID_INTEL_TGL_NHI0: 2286 2286 case PCI_DEVICE_ID_INTEL_TGL_NHI1: 2287 + case PCI_DEVICE_ID_INTEL_TGL_H_NHI0: 2288 + case PCI_DEVICE_ID_INTEL_TGL_H_NHI1: 2287 2289 icm->is_supported = icm_tgl_is_supported; 2288 2290 icm->driver_ready = icm_icl_driver_ready; 2289 2291 icm->set_uuid = icm_icl_set_uuid;
+19 -4
drivers/thunderbolt/nhi.c
··· 406 406 407 407 ring->vector = ret; 408 408 409 - ring->irq = pci_irq_vector(ring->nhi->pdev, ring->vector); 410 - if (ring->irq < 0) 411 - return ring->irq; 409 + ret = pci_irq_vector(ring->nhi->pdev, ring->vector); 410 + if (ret < 0) 411 + goto err_ida_remove; 412 + 413 + ring->irq = ret; 412 414 413 415 irqflags = no_suspend ? IRQF_NO_SUSPEND : 0; 414 - return request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring); 416 + ret = request_irq(ring->irq, ring_msix, irqflags, "thunderbolt", ring); 417 + if (ret) 418 + goto err_ida_remove; 419 + 420 + return 0; 421 + 422 + err_ida_remove: 423 + ida_simple_remove(&nhi->msix_ida, ring->vector); 424 + 425 + return ret; 415 426 } 416 427 417 428 static void ring_release_msix(struct tb_ring *ring) ··· 1344 1333 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGL_NHI0), 1345 1334 .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1346 1335 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGL_NHI1), 1336 + .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1337 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGL_H_NHI0), 1338 + .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1339 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGL_H_NHI1), 1347 1340 .driver_data = (kernel_ulong_t)&icl_nhi_ops }, 1348 1341 1349 1342 /* Any USB4 compliant host */
+2
drivers/thunderbolt/nhi.h
··· 75 75 #define PCI_DEVICE_ID_INTEL_ICL_NHI0 0x8a17 76 76 #define PCI_DEVICE_ID_INTEL_TGL_NHI0 0x9a1b 77 77 #define PCI_DEVICE_ID_INTEL_TGL_NHI1 0x9a1d 78 + #define PCI_DEVICE_ID_INTEL_TGL_H_NHI0 0x9a1f 79 + #define PCI_DEVICE_ID_INTEL_TGL_H_NHI1 0x9a21 78 80 79 81 #define PCI_CLASS_SERIAL_USB_USB4 0x0c0340 80 82
+2
drivers/thunderbolt/tb.h
··· 784 784 switch (sw->config.device_id) { 785 785 case PCI_DEVICE_ID_INTEL_TGL_NHI0: 786 786 case PCI_DEVICE_ID_INTEL_TGL_NHI1: 787 + case PCI_DEVICE_ID_INTEL_TGL_H_NHI0: 788 + case PCI_DEVICE_ID_INTEL_TGL_H_NHI1: 787 789 return true; 788 790 } 789 791 }
+4
drivers/thunderbolt/usb4.c
··· 421 421 * upstream USB4 port. 422 422 */ 423 423 tb_switch_for_each_port(sw, port) { 424 + if (!tb_port_is_null(port)) 425 + continue; 424 426 if (!route && tb_is_upstream_port(port)) 427 + continue; 428 + if (!port->cap_usb4) 425 429 continue; 426 430 427 431 ret = tb_port_read(port, &val, TB_CFG_PORT,
+1
drivers/thunderbolt/xdomain.c
··· 881 881 882 882 id = ida_simple_get(&xd->service_ids, 0, 0, GFP_KERNEL); 883 883 if (id < 0) { 884 + kfree(svc->key); 884 885 kfree(svc); 885 886 break; 886 887 }
+6 -4
drivers/uio/uio.c
··· 413 413 return retval; 414 414 } 415 415 416 - static void uio_free_minor(struct uio_device *idev) 416 + static void uio_free_minor(unsigned long minor) 417 417 { 418 418 mutex_lock(&minor_lock); 419 - idr_remove(&uio_idr, idev->minor); 419 + idr_remove(&uio_idr, minor); 420 420 mutex_unlock(&minor_lock); 421 421 } 422 422 ··· 990 990 err_uio_dev_add_attributes: 991 991 device_del(&idev->dev); 992 992 err_device_create: 993 - uio_free_minor(idev); 993 + uio_free_minor(idev->minor); 994 994 put_device(&idev->dev); 995 995 return ret; 996 996 } ··· 1042 1042 void uio_unregister_device(struct uio_info *info) 1043 1043 { 1044 1044 struct uio_device *idev; 1045 + unsigned long minor; 1045 1046 1046 1047 if (!info || !info->uio_dev) 1047 1048 return; 1048 1049 1049 1050 idev = info->uio_dev; 1051 + minor = idev->minor; 1050 1052 1051 1053 mutex_lock(&idev->info_lock); 1052 1054 uio_dev_del_attributes(idev); ··· 1064 1062 1065 1063 device_unregister(&idev->dev); 1066 1064 1067 - uio_free_minor(idev); 1065 + uio_free_minor(minor); 1068 1066 1069 1067 return; 1070 1068 }
+9
drivers/usb/class/cdc-acm.c
··· 1693 1693 { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */ 1694 1694 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ 1695 1695 }, 1696 + { USB_DEVICE(0x045b, 0x023c), /* Renesas USB Download mode */ 1697 + .driver_info = DISABLE_ECHO, /* Don't echo banner */ 1698 + }, 1699 + { USB_DEVICE(0x045b, 0x0248), /* Renesas USB Download mode */ 1700 + .driver_info = DISABLE_ECHO, /* Don't echo banner */ 1701 + }, 1702 + { USB_DEVICE(0x045b, 0x024D), /* Renesas USB Download mode */ 1703 + .driver_info = DISABLE_ECHO, /* Don't echo banner */ 1704 + }, 1696 1705 { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */ 1697 1706 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ 1698 1707 },
+1 -1
drivers/usb/host/xhci-histb.c
··· 240 240 /* Initialize dma_mask and coherent_dma_mask to 32-bits */ 241 241 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); 242 242 if (ret) 243 - return ret; 243 + goto disable_pm; 244 244 245 245 hcd = usb_create_hcd(driver, dev, dev_name(dev)); 246 246 if (!hcd) {
+3 -1
drivers/usb/musb/musb_dsps.c
··· 429 429 struct platform_device *parent = to_platform_device(dev->parent); 430 430 const struct dsps_musb_wrapper *wrp = glue->wrp; 431 431 void __iomem *reg_base; 432 + struct resource *r; 432 433 u32 rev, val; 433 434 int ret; 434 435 435 - reg_base = devm_platform_ioremap_resource_byname(parent, "control"); 436 + r = platform_get_resource_byname(parent, IORESOURCE_MEM, "control"); 437 + reg_base = devm_ioremap_resource(dev, r); 436 438 if (IS_ERR(reg_base)) 437 439 return PTR_ERR(reg_base); 438 440 musb->ctrl_base = reg_base;
+9
drivers/usb/typec/ucsi/psy.c
··· 238 238 return; 239 239 240 240 power_supply_unregister(con->psy); 241 + con->psy = NULL; 242 + } 243 + 244 + void ucsi_port_psy_changed(struct ucsi_connector *con) 245 + { 246 + if (IS_ERR_OR_NULL(con->psy)) 247 + return; 248 + 249 + power_supply_changed(con->psy); 241 250 }
+6 -1
drivers/usb/typec/ucsi/ucsi.c
··· 643 643 role = !!(con->status.flags & UCSI_CONSTAT_PWR_DIR); 644 644 645 645 if (con->status.change & UCSI_CONSTAT_POWER_OPMODE_CHANGE || 646 - con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE) 646 + con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE) { 647 647 ucsi_pwr_opmode_change(con); 648 + ucsi_port_psy_changed(con); 649 + } 648 650 649 651 if (con->status.change & UCSI_CONSTAT_POWER_DIR_CHANGE) { 650 652 typec_set_pwr_role(con->port, role); ··· 676 674 ucsi_register_partner(con); 677 675 else 678 676 ucsi_unregister_partner(con); 677 + 678 + ucsi_port_psy_changed(con); 679 679 } 680 680 681 681 if (con->status.change & UCSI_CONSTAT_CAM_CHANGE) { ··· 998 994 !!(con->status.flags & UCSI_CONSTAT_PWR_DIR)); 999 995 ucsi_pwr_opmode_change(con); 1000 996 ucsi_register_partner(con); 997 + ucsi_port_psy_changed(con); 1001 998 } 1002 999 1003 1000 if (con->partner) {
+2
drivers/usb/typec/ucsi/ucsi.h
··· 340 340 #if IS_ENABLED(CONFIG_POWER_SUPPLY) 341 341 int ucsi_register_port_psy(struct ucsi_connector *con); 342 342 void ucsi_unregister_port_psy(struct ucsi_connector *con); 343 + void ucsi_port_psy_changed(struct ucsi_connector *con); 343 344 #else 344 345 static inline int ucsi_register_port_psy(struct ucsi_connector *con) { return 0; } 345 346 static inline void ucsi_unregister_port_psy(struct ucsi_connector *con) { } 347 + static inline void ucsi_port_psy_changed(struct ucsi_connector *con) { } 346 348 #endif /* CONFIG_POWER_SUPPLY */ 347 349 348 350 #if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE)
+1
drivers/video/fbdev/hyperv_fb.c
··· 47 47 48 48 #include <linux/module.h> 49 49 #include <linux/kernel.h> 50 + #include <linux/vmalloc.h> 50 51 #include <linux/init.h> 51 52 #include <linux/completion.h> 52 53 #include <linux/fb.h>
+2 -4
drivers/virt/nitro_enclaves/ne_misc_dev.c
··· 1505 1505 1506 1506 poll_wait(file, &ne_enclave->eventq, wait); 1507 1507 1508 - if (!ne_enclave->has_event) 1509 - return mask; 1510 - 1511 - mask = POLLHUP; 1508 + if (ne_enclave->has_event) 1509 + mask |= EPOLLHUP; 1512 1510 1513 1511 return mask; 1514 1512 }
+4 -1
fs/afs/write.c
··· 169 169 unsigned int f, from = pos & (PAGE_SIZE - 1); 170 170 unsigned int t, to = from + copied; 171 171 loff_t i_size, maybe_i_size; 172 - int ret; 172 + int ret = 0; 173 173 174 174 _enter("{%llx:%llu},{%lx}", 175 175 vnode->fid.vid, vnode->fid.vnode, page->index); 176 + 177 + if (copied == 0) 178 + goto out; 176 179 177 180 maybe_i_size = pos + copied; 178 181
+1 -1
fs/aio.c
··· 1572 1572 * we return to userspace. 1573 1573 */ 1574 1574 if (S_ISREG(file_inode(file)->i_mode)) { 1575 - __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true); 1575 + sb_start_write(file_inode(file)->i_sb); 1576 1576 __sb_writers_release(file_inode(file)->i_sb, SB_FREEZE_WRITE); 1577 1577 } 1578 1578 req->ki_flags |= IOCB_WRITE;
+3 -3
fs/ext4/ext4.h
··· 1231 1231 blocks */ 1232 1232 #define EXT4_MOUNT2_HURD_COMPAT 0x00000004 /* Support HURD-castrated 1233 1233 file systems */ 1234 - #define EXT4_MOUNT2_DAX_NEVER 0x00000008 /* Do not allow Direct Access */ 1235 - #define EXT4_MOUNT2_DAX_INODE 0x00000010 /* For printing options only */ 1236 - 1237 1234 #define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM 0x00000008 /* User explicitly 1238 1235 specified journal checksum */ 1239 1236 1240 1237 #define EXT4_MOUNT2_JOURNAL_FAST_COMMIT 0x00000010 /* Journal fast commit */ 1238 + #define EXT4_MOUNT2_DAX_NEVER 0x00000020 /* Do not allow Direct Access */ 1239 + #define EXT4_MOUNT2_DAX_INODE 0x00000040 /* For printing options only */ 1240 + 1241 1241 1242 1242 #define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \ 1243 1243 ~EXT4_MOUNT_##opt
-11
fs/ext4/super.c
··· 289 289 if (!ext4_has_metadata_csum(sb)) 290 290 return; 291 291 292 - /* 293 - * Locking the superblock prevents the scenario 294 - * where: 295 - * 1) a first thread pauses during checksum calculation. 296 - * 2) a second thread updates the superblock, recalculates 297 - * the checksum, and updates s_checksum 298 - * 3) the first thread resumes and finishes its checksum calculation 299 - * and updates s_checksum with a potentially stale or torn value. 300 - */ 301 - lock_buffer(EXT4_SB(sb)->s_sbh); 302 292 es->s_checksum = ext4_superblock_csum(sb, es); 303 - unlock_buffer(EXT4_SB(sb)->s_sbh); 304 293 } 305 294 306 295 ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
+2 -3
fs/io_uring.c
··· 3547 3547 * we return to userspace. 3548 3548 */ 3549 3549 if (req->flags & REQ_F_ISREG) { 3550 - __sb_start_write(file_inode(req->file)->i_sb, 3551 - SB_FREEZE_WRITE, true); 3550 + sb_start_write(file_inode(req->file)->i_sb); 3552 3551 __sb_writers_release(file_inode(req->file)->i_sb, 3553 3552 SB_FREEZE_WRITE); 3554 3553 } ··· 9225 9226 * to a power-of-two, if it isn't already. We do NOT impose 9226 9227 * any cq vs sq ring sizing. 9227 9228 */ 9229 + p->cq_entries = roundup_pow_of_two(p->cq_entries); 9228 9230 if (p->cq_entries < p->sq_entries) 9229 9231 return -EINVAL; 9230 9232 if (p->cq_entries > IORING_MAX_CQ_ENTRIES) { ··· 9233 9233 return -EINVAL; 9234 9234 p->cq_entries = IORING_MAX_CQ_ENTRIES; 9235 9235 } 9236 - p->cq_entries = roundup_pow_of_two(p->cq_entries); 9237 9236 } else { 9238 9237 p->cq_entries = 2 * p->sq_entries; 9239 9238 }
+1
fs/ocfs2/super.c
··· 1713 1713 1714 1714 oi->ip_blkno = 0ULL; 1715 1715 oi->ip_clusters = 0; 1716 + oi->ip_next_orphan = NULL; 1716 1717 1717 1718 ocfs2_resv_init_once(&oi->ip_la_data_resv); 1718 1719
-49
fs/super.c
··· 1631 1631 } 1632 1632 EXPORT_SYMBOL(super_setup_bdi); 1633 1633 1634 - /* 1635 - * This is an internal function, please use sb_end_{write,pagefault,intwrite} 1636 - * instead. 1637 - */ 1638 - void __sb_end_write(struct super_block *sb, int level) 1639 - { 1640 - percpu_up_read(sb->s_writers.rw_sem + level-1); 1641 - } 1642 - EXPORT_SYMBOL(__sb_end_write); 1643 - 1644 - /* 1645 - * This is an internal function, please use sb_start_{write,pagefault,intwrite} 1646 - * instead. 1647 - */ 1648 - int __sb_start_write(struct super_block *sb, int level, bool wait) 1649 - { 1650 - bool force_trylock = false; 1651 - int ret = 1; 1652 - 1653 - #ifdef CONFIG_LOCKDEP 1654 - /* 1655 - * We want lockdep to tell us about possible deadlocks with freezing 1656 - * but it's it bit tricky to properly instrument it. Getting a freeze 1657 - * protection works as getting a read lock but there are subtle 1658 - * problems. XFS for example gets freeze protection on internal level 1659 - * twice in some cases, which is OK only because we already hold a 1660 - * freeze protection also on higher level. Due to these cases we have 1661 - * to use wait == F (trylock mode) which must not fail. 1662 - */ 1663 - if (wait) { 1664 - int i; 1665 - 1666 - for (i = 0; i < level - 1; i++) 1667 - if (percpu_rwsem_is_held(sb->s_writers.rw_sem + i)) { 1668 - force_trylock = true; 1669 - break; 1670 - } 1671 - } 1672 - #endif 1673 - if (wait && !force_trylock) 1674 - percpu_down_read(sb->s_writers.rw_sem + level-1); 1675 - else 1676 - ret = percpu_down_read_trylock(sb->s_writers.rw_sem + level-1); 1677 - 1678 - WARN_ON(force_trylock && !ret); 1679 - return ret; 1680 - } 1681 - EXPORT_SYMBOL(__sb_start_write); 1682 - 1683 1634 /** 1684 1635 * sb_wait_write - wait until all writers to given file system finish 1685 1636 * @sb: the super for which we wait
+1 -1
fs/xfs/libxfs/xfs_rmap.c
··· 1514 1514 * record for our insertion point. This will also give us the record for 1515 1515 * start block contiguity tests. 1516 1516 */ 1517 - error = xfs_rmap_lookup_le_range(cur, bno, owner, offset, flags, 1517 + error = xfs_rmap_lookup_le_range(cur, bno, owner, offset, oldext, 1518 1518 &PREV, &i); 1519 1519 if (error) 1520 1520 goto done;
+8 -8
fs/xfs/libxfs/xfs_rmap_btree.c
··· 243 243 else if (y > x) 244 244 return -1; 245 245 246 - x = XFS_RMAP_OFF(be64_to_cpu(kp->rm_offset)); 247 - y = rec->rm_offset; 246 + x = be64_to_cpu(kp->rm_offset); 247 + y = xfs_rmap_irec_offset_pack(rec); 248 248 if (x > y) 249 249 return 1; 250 250 else if (y > x) ··· 275 275 else if (y > x) 276 276 return -1; 277 277 278 - x = XFS_RMAP_OFF(be64_to_cpu(kp1->rm_offset)); 279 - y = XFS_RMAP_OFF(be64_to_cpu(kp2->rm_offset)); 278 + x = be64_to_cpu(kp1->rm_offset); 279 + y = be64_to_cpu(kp2->rm_offset); 280 280 if (x > y) 281 281 return 1; 282 282 else if (y > x) ··· 390 390 return 1; 391 391 else if (a > b) 392 392 return 0; 393 - a = XFS_RMAP_OFF(be64_to_cpu(k1->rmap.rm_offset)); 394 - b = XFS_RMAP_OFF(be64_to_cpu(k2->rmap.rm_offset)); 393 + a = be64_to_cpu(k1->rmap.rm_offset); 394 + b = be64_to_cpu(k2->rmap.rm_offset); 395 395 if (a <= b) 396 396 return 1; 397 397 return 0; ··· 420 420 return 1; 421 421 else if (a > b) 422 422 return 0; 423 - a = XFS_RMAP_OFF(be64_to_cpu(r1->rmap.rm_offset)); 424 - b = XFS_RMAP_OFF(be64_to_cpu(r2->rmap.rm_offset)); 423 + a = be64_to_cpu(r1->rmap.rm_offset); 424 + b = be64_to_cpu(r2->rmap.rm_offset); 425 425 if (a <= b) 426 426 return 1; 427 427 return 0;
+2
fs/xfs/scrub/bmap.c
··· 113 113 114 114 if (info->whichfork == XFS_ATTR_FORK) 115 115 rflags |= XFS_RMAP_ATTR_FORK; 116 + if (irec->br_state == XFS_EXT_UNWRITTEN) 117 + rflags |= XFS_RMAP_UNWRITTEN; 116 118 117 119 /* 118 120 * CoW staging extents are owned (on disk) by the refcountbt, so
+3 -5
fs/xfs/scrub/refcount.c
··· 170 170 */ 171 171 INIT_LIST_HEAD(&worklist); 172 172 rbno = NULLAGBLOCK; 173 - nr = 1; 174 173 175 174 /* Make sure the fragments actually /are/ in agbno order. */ 176 175 bno = 0; ··· 183 184 * Find all the rmaps that start at or before the refc extent, 184 185 * and put them on the worklist. 185 186 */ 187 + nr = 0; 186 188 list_for_each_entry_safe(frag, n, &refchk->fragments, list) { 187 - if (frag->rm.rm_startblock > refchk->bno) 188 - goto done; 189 + if (frag->rm.rm_startblock > refchk->bno || nr > target_nr) 190 + break; 189 191 bno = frag->rm.rm_startblock + frag->rm.rm_blockcount; 190 192 if (bno < rbno) 191 193 rbno = bno; 192 194 list_move_tail(&frag->list, &worklist); 193 - if (nr == target_nr) 194 - break; 195 195 nr++; 196 196 } 197 197
+1 -1
fs/xfs/xfs_pnfs.c
··· 134 134 goto out_unlock; 135 135 error = invalidate_inode_pages2(inode->i_mapping); 136 136 if (WARN_ON_ONCE(error)) 137 - return error; 137 + goto out_unlock; 138 138 139 139 end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + length); 140 140 offset_fsb = XFS_B_TO_FSBT(mp, offset);
+1
include/asm-generic/barrier.h
··· 13 13 14 14 #ifndef __ASSEMBLY__ 15 15 16 + #include <linux/compiler.h> 16 17 #include <asm/rwonce.h> 17 18 18 19 #ifndef nop
+9 -9
include/asm-generic/percpu.h
··· 114 114 115 115 #define __this_cpu_generic_read_nopreempt(pcp) \ 116 116 ({ \ 117 - typeof(pcp) __ret; \ 117 + typeof(pcp) ___ret; \ 118 118 preempt_disable_notrace(); \ 119 - __ret = READ_ONCE(*raw_cpu_ptr(&(pcp))); \ 119 + ___ret = READ_ONCE(*raw_cpu_ptr(&(pcp))); \ 120 120 preempt_enable_notrace(); \ 121 - __ret; \ 121 + ___ret; \ 122 122 }) 123 123 124 124 #define __this_cpu_generic_read_noirq(pcp) \ 125 125 ({ \ 126 - typeof(pcp) __ret; \ 127 - unsigned long __flags; \ 128 - raw_local_irq_save(__flags); \ 129 - __ret = raw_cpu_generic_read(pcp); \ 130 - raw_local_irq_restore(__flags); \ 131 - __ret; \ 126 + typeof(pcp) ___ret; \ 127 + unsigned long ___flags; \ 128 + raw_local_irq_save(___flags); \ 129 + ___ret = raw_cpu_generic_read(pcp); \ 130 + raw_local_irq_restore(___flags); \ 131 + ___ret; \ 132 132 }) 133 133 134 134 #define this_cpu_generic_read(pcp) \
-3
include/kvm/arm_pmu.h
··· 24 24 int irq_num; 25 25 struct kvm_pmc pmc[ARMV8_PMU_MAX_COUNTERS]; 26 26 DECLARE_BITMAP(chained, ARMV8_PMU_MAX_COUNTER_PAIRS); 27 - bool ready; 28 27 bool created; 29 28 bool irq_level; 30 29 struct irq_work overflow_work; 31 30 }; 32 31 33 - #define kvm_arm_pmu_v3_ready(v) ((v)->arch.pmu.ready) 34 32 #define kvm_arm_pmu_irq_initialized(v) ((v)->arch.pmu.irq_num >= VGIC_NR_SGIS) 35 33 u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, u64 select_idx); 36 34 void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu, u64 select_idx, u64 val); ··· 59 61 struct kvm_pmu { 60 62 }; 61 63 62 - #define kvm_arm_pmu_v3_ready(v) (false) 63 64 #define kvm_arm_pmu_irq_initialized(v) (false) 64 65 static inline u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, 65 66 u64 select_idx)
+1
include/kvm/arm_vgic.h
··· 402 402 struct kvm_kernel_irq_routing_entry *irq_entry); 403 403 404 404 int vgic_v4_load(struct kvm_vcpu *vcpu); 405 + void vgic_v4_commit(struct kvm_vcpu *vcpu); 405 406 int vgic_v4_put(struct kvm_vcpu *vcpu, bool need_db); 406 407 407 408 #endif /* __KVM_ARM_VGIC_H */
-6
include/linux/compiler-clang.h
··· 60 60 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 61 61 #endif 62 62 63 - /* The following are for compatibility with GCC, from compiler-gcc.h, 64 - * and may be redefined here because they should not be shared with other 65 - * compilers, like ICC. 66 - */ 67 - #define barrier() __asm__ __volatile__("" : : : "memory") 68 - 69 63 #if __has_feature(shadow_call_stack) 70 64 # define __noscs __attribute__((__no_sanitize__("shadow-call-stack"))) 71 65 #endif
-19
include/linux/compiler-gcc.h
··· 15 15 # error Sorry, your version of GCC is too old - please use 4.9 or newer. 16 16 #endif 17 17 18 - /* Optimization barrier */ 19 - 20 - /* The "volatile" is due to gcc bugs */ 21 - #define barrier() __asm__ __volatile__("": : :"memory") 22 - /* 23 - * This version is i.e. to prevent dead stores elimination on @ptr 24 - * where gcc and llvm may behave differently when otherwise using 25 - * normal barrier(): while gcc behavior gets along with a normal 26 - * barrier(), llvm needs an explicit input variable to be assumed 27 - * clobbered. The issue is as follows: while the inline asm might 28 - * access any memory it wants, the compiler could have fit all of 29 - * @ptr into memory registers instead, and since @ptr never escaped 30 - * from that, it proved that the inline asm wasn't touching any of 31 - * it. This version works well with both compilers, i.e. we're telling 32 - * the compiler that the inline asm absolutely may see the contents 33 - * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495 34 - */ 35 - #define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory") 36 - 37 18 /* 38 19 * This macro obfuscates arithmetic on a variable address so that gcc 39 20 * shouldn't recognize the original var, and make assumptions about it.
+16 -2
include/linux/compiler.h
··· 80 80 81 81 /* Optimization barrier */ 82 82 #ifndef barrier 83 - # define barrier() __memory_barrier() 83 + /* The "volatile" is due to gcc bugs */ 84 + # define barrier() __asm__ __volatile__("": : :"memory") 84 85 #endif 85 86 86 87 #ifndef barrier_data 87 - # define barrier_data(ptr) barrier() 88 + /* 89 + * This version is i.e. to prevent dead stores elimination on @ptr 90 + * where gcc and llvm may behave differently when otherwise using 91 + * normal barrier(): while gcc behavior gets along with a normal 92 + * barrier(), llvm needs an explicit input variable to be assumed 93 + * clobbered. The issue is as follows: while the inline asm might 94 + * access any memory it wants, the compiler could have fit all of 95 + * @ptr into memory registers instead, and since @ptr never escaped 96 + * from that, it proved that the inline asm wasn't touching any of 97 + * it. This version works well with both compilers, i.e. we're telling 98 + * the compiler that the inline asm absolutely may see the contents 99 + * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495 100 + */ 101 + # define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory") 88 102 #endif 89 103 90 104 /* workaround for GCC PR82365 if needed */
+27 -11
include/linux/fs.h
··· 1580 1580 * Snapshotting support. 1581 1581 */ 1582 1582 1583 - void __sb_end_write(struct super_block *sb, int level); 1584 - int __sb_start_write(struct super_block *sb, int level, bool wait); 1583 + /* 1584 + * These are internal functions, please use sb_start_{write,pagefault,intwrite} 1585 + * instead. 1586 + */ 1587 + static inline void __sb_end_write(struct super_block *sb, int level) 1588 + { 1589 + percpu_up_read(sb->s_writers.rw_sem + level-1); 1590 + } 1591 + 1592 + static inline void __sb_start_write(struct super_block *sb, int level) 1593 + { 1594 + percpu_down_read(sb->s_writers.rw_sem + level - 1); 1595 + } 1596 + 1597 + static inline bool __sb_start_write_trylock(struct super_block *sb, int level) 1598 + { 1599 + return percpu_down_read_trylock(sb->s_writers.rw_sem + level - 1); 1600 + } 1585 1601 1586 1602 #define __sb_writers_acquired(sb, lev) \ 1587 1603 percpu_rwsem_acquire(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_) ··· 1661 1645 */ 1662 1646 static inline void sb_start_write(struct super_block *sb) 1663 1647 { 1664 - __sb_start_write(sb, SB_FREEZE_WRITE, true); 1648 + __sb_start_write(sb, SB_FREEZE_WRITE); 1665 1649 } 1666 1650 1667 - static inline int sb_start_write_trylock(struct super_block *sb) 1651 + static inline bool sb_start_write_trylock(struct super_block *sb) 1668 1652 { 1669 - return __sb_start_write(sb, SB_FREEZE_WRITE, false); 1653 + return __sb_start_write_trylock(sb, SB_FREEZE_WRITE); 1670 1654 } 1671 1655 1672 1656 /** ··· 1690 1674 */ 1691 1675 static inline void sb_start_pagefault(struct super_block *sb) 1692 1676 { 1693 - __sb_start_write(sb, SB_FREEZE_PAGEFAULT, true); 1677 + __sb_start_write(sb, SB_FREEZE_PAGEFAULT); 1694 1678 } 1695 1679 1696 1680 /* ··· 1708 1692 */ 1709 1693 static inline void sb_start_intwrite(struct super_block *sb) 1710 1694 { 1711 - __sb_start_write(sb, SB_FREEZE_FS, true); 1695 + __sb_start_write(sb, SB_FREEZE_FS); 1712 1696 } 1713 1697 1714 - static inline int sb_start_intwrite_trylock(struct super_block *sb) 1698 + static inline bool sb_start_intwrite_trylock(struct super_block *sb) 1715 1699 { 1716 - return __sb_start_write(sb, SB_FREEZE_FS, false); 1700 + return __sb_start_write_trylock(sb, SB_FREEZE_FS); 1717 1701 } 1718 1702 1719 1703 ··· 2772 2756 { 2773 2757 if (!S_ISREG(file_inode(file)->i_mode)) 2774 2758 return; 2775 - __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true); 2759 + sb_start_write(file_inode(file)->i_sb); 2776 2760 } 2777 2761 2778 2762 static inline bool file_start_write_trylock(struct file *file) 2779 2763 { 2780 2764 if (!S_ISREG(file_inode(file)->i_mode)) 2781 2765 return true; 2782 - return __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, false); 2766 + return sb_start_write_trylock(file_inode(file)->i_sb); 2783 2767 } 2784 2768 2785 2769 static inline void file_end_write(struct file *file)
+1 -1
include/linux/genhd.h
··· 315 315 extern void disk_block_events(struct gendisk *disk); 316 316 extern void disk_unblock_events(struct gendisk *disk); 317 317 extern void disk_flush_events(struct gendisk *disk, unsigned int mask); 318 - void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size, 318 + bool set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size, 319 319 bool update_bdev); 320 320 321 321 /* drivers/char/random.c */
+4
include/linux/irqchip/arm-gic-v4.h
··· 39 39 irq_hw_number_t vpe_db_lpi; 40 40 /* VPE resident */ 41 41 bool resident; 42 + /* VPT parse complete */ 43 + bool ready; 42 44 union { 43 45 /* GICv4.0 implementations */ 44 46 struct { ··· 106 104 PROP_UPDATE_AND_INV_VLPI, 107 105 SCHEDULE_VPE, 108 106 DESCHEDULE_VPE, 107 + COMMIT_VPE, 109 108 INVALL_VPE, 110 109 PROP_UPDATE_VSGI, 111 110 }; ··· 132 129 void its_free_vcpu_irqs(struct its_vm *vm); 133 130 int its_make_vpe_resident(struct its_vpe *vpe, bool g0en, bool g1en); 134 131 int its_make_vpe_non_resident(struct its_vpe *vpe, bool db); 132 + int its_commit_vpe(struct its_vpe *vpe); 135 133 int its_invall_vpe(struct its_vpe *vpe); 136 134 int its_map_vlpi(int irq, struct its_vlpi_map *map); 137 135 int its_get_vlpi(int irq, struct its_vlpi_map *map);
+9 -2
include/linux/memcontrol.h
··· 900 900 static inline void memcg_memory_event(struct mem_cgroup *memcg, 901 901 enum memcg_memory_event event) 902 902 { 903 + bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX || 904 + event == MEMCG_SWAP_FAIL; 905 + 903 906 atomic_long_inc(&memcg->memory_events_local[event]); 904 - cgroup_file_notify(&memcg->events_local_file); 907 + if (!swap_event) 908 + cgroup_file_notify(&memcg->events_local_file); 905 909 906 910 do { 907 911 atomic_long_inc(&memcg->memory_events[event]); 908 - cgroup_file_notify(&memcg->events_file); 912 + if (swap_event) 913 + cgroup_file_notify(&memcg->swap_events_file); 914 + else 915 + cgroup_file_notify(&memcg->events_file); 909 916 910 917 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) 911 918 break;
+5 -8
include/linux/perf_event.h
··· 1022 1022 struct perf_callchain_entry *callchain; 1023 1023 u64 aux_size; 1024 1024 1025 - /* 1026 - * regs_user may point to task_pt_regs or to regs_user_copy, depending 1027 - * on arch details. 1028 - */ 1029 1025 struct perf_regs regs_user; 1030 - struct pt_regs regs_user_copy; 1031 - 1032 1026 struct perf_regs regs_intr; 1033 1027 u64 stack_user_size; 1034 1028 ··· 1394 1400 extern void perf_event_addr_filters_sync(struct perf_event *event); 1395 1401 1396 1402 extern int perf_output_begin(struct perf_output_handle *handle, 1403 + struct perf_sample_data *data, 1397 1404 struct perf_event *event, unsigned int size); 1398 1405 extern int perf_output_begin_forward(struct perf_output_handle *handle, 1399 - struct perf_event *event, 1400 - unsigned int size); 1406 + struct perf_sample_data *data, 1407 + struct perf_event *event, 1408 + unsigned int size); 1401 1409 extern int perf_output_begin_backward(struct perf_output_handle *handle, 1410 + struct perf_sample_data *data, 1402 1411 struct perf_event *event, 1403 1412 unsigned int size); 1404 1413
+2 -4
include/linux/perf_regs.h
··· 20 20 int perf_reg_validate(u64 mask); 21 21 u64 perf_reg_abi(struct task_struct *task); 22 22 void perf_get_regs_user(struct perf_regs *regs_user, 23 - struct pt_regs *regs, 24 - struct pt_regs *regs_user_copy); 23 + struct pt_regs *regs); 25 24 #else 26 25 27 26 #define PERF_REG_EXTENDED_MASK 0 ··· 41 42 } 42 43 43 44 static inline void perf_get_regs_user(struct perf_regs *regs_user, 44 - struct pt_regs *regs, 45 - struct pt_regs *regs_user_copy) 45 + struct pt_regs *regs) 46 46 { 47 47 regs_user->regs = task_pt_regs(current); 48 48 regs_user->abi = perf_reg_abi(current);
+9
include/linux/psci.h
··· 34 34 35 35 extern struct psci_operations psci_ops; 36 36 37 + struct psci_0_1_function_ids { 38 + u32 cpu_suspend; 39 + u32 cpu_on; 40 + u32 cpu_off; 41 + u32 migrate; 42 + }; 43 + 44 + struct psci_0_1_function_ids get_psci_0_1_function_ids(void); 45 + 37 46 #if defined(CONFIG_ARM_PSCI_FW) 38 47 int __init psci_dt_init(void); 39 48 #else
+54 -52
include/uapi/linux/gpio.h
··· 26 26 * struct gpiochip_info - Information about a certain GPIO chip 27 27 * @name: the Linux kernel name of this GPIO chip 28 28 * @label: a functional name for this GPIO chip, such as a product 29 - * number, may be empty 29 + * number, may be empty (i.e. label[0] == '\0') 30 30 * @lines: number of GPIO lines on this chip 31 31 */ 32 32 struct gpiochip_info { ··· 98 98 * identifying which field of the attribute union is in use. 99 99 * @GPIO_V2_LINE_ATTR_ID_FLAGS: flags field is in use 100 100 * @GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES: values field is in use 101 - * @GPIO_V2_LINE_ATTR_ID_DEBOUNCE: debounce_period_us is in use 101 + * @GPIO_V2_LINE_ATTR_ID_DEBOUNCE: debounce_period_us field is in use 102 102 */ 103 103 enum gpio_v2_line_attr_id { 104 104 GPIO_V2_LINE_ATTR_ID_FLAGS = 1, ··· 110 110 * struct gpio_v2_line_attribute - a configurable attribute of a line 111 111 * @id: attribute identifier with value from &enum gpio_v2_line_attr_id 112 112 * @padding: reserved for future use and must be zero filled 113 - * @flags: if id is GPIO_V2_LINE_ATTR_ID_FLAGS, the flags for the GPIO 114 - * line, with values from enum gpio_v2_line_flag, such as 115 - * GPIO_V2_LINE_FLAG_ACTIVE_LOW, GPIO_V2_LINE_FLAG_OUTPUT etc, OR:ed 113 + * @flags: if id is %GPIO_V2_LINE_ATTR_ID_FLAGS, the flags for the GPIO 114 + * line, with values from &enum gpio_v2_line_flag, such as 115 + * %GPIO_V2_LINE_FLAG_ACTIVE_LOW, %GPIO_V2_LINE_FLAG_OUTPUT etc, added 116 116 * together. This overrides the default flags contained in the &struct 117 117 * gpio_v2_line_config for the associated line. 118 - * @values: if id is GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES, a bitmap 118 + * @values: if id is %GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES, a bitmap 119 119 * containing the values to which the lines will be set, with each bit 120 120 * number corresponding to the index into &struct 121 121 * gpio_v2_line_request.offsets. 122 - * @debounce_period_us: if id is GPIO_V2_LINE_ATTR_ID_DEBOUNCE, the desired 123 - * debounce period, in microseconds 122 + * @debounce_period_us: if id is %GPIO_V2_LINE_ATTR_ID_DEBOUNCE, the 123 + * desired debounce period, in microseconds 124 124 */ 125 125 struct gpio_v2_line_attribute { 126 126 __u32 id; ··· 147 147 148 148 /** 149 149 * struct gpio_v2_line_config - Configuration for GPIO lines 150 - * @flags: flags for the GPIO lines, with values from enum 151 - * gpio_v2_line_flag, such as GPIO_V2_LINE_FLAG_ACTIVE_LOW, 152 - * GPIO_V2_LINE_FLAG_OUTPUT etc, OR:ed together. This is the default for 150 + * @flags: flags for the GPIO lines, with values from &enum 151 + * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW, 152 + * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together. This is the default for 153 153 * all requested lines but may be overridden for particular lines using 154 - * attrs. 155 - * @num_attrs: the number of attributes in attrs 154 + * @attrs. 155 + * @num_attrs: the number of attributes in @attrs 156 156 * @padding: reserved for future use and must be zero filled 157 157 * @attrs: the configuration attributes associated with the requested 158 158 * lines. Any attribute should only be associated with a particular line ··· 175 175 * "my-bitbanged-relay" 176 176 * @config: requested configuration for the lines. 177 177 * @num_lines: number of lines requested in this request, i.e. the number 178 - * of valid fields in the GPIO_V2_LINES_MAX sized arrays, set to 1 to 178 + * of valid fields in the %GPIO_V2_LINES_MAX sized arrays, set to 1 to 179 179 * request a single line 180 180 * @event_buffer_size: a suggested minimum number of line events that the 181 181 * kernel should buffer. This is only relevant if edge detection is 182 182 * enabled in the configuration. Note that this is only a suggested value 183 183 * and the kernel may allocate a larger buffer or cap the size of the 184 184 * buffer. If this field is zero then the buffer size defaults to a minimum 185 - * of num_lines*16. 185 + * of @num_lines * 16. 186 186 * @padding: reserved for future use and must be zero filled 187 187 * @fd: if successful this field will contain a valid anonymous file handle 188 - * after a GPIO_GET_LINE_IOCTL operation, zero or negative value means 188 + * after a %GPIO_GET_LINE_IOCTL operation, zero or negative value means 189 189 * error 190 190 */ 191 191 struct gpio_v2_line_request { ··· 203 203 * struct gpio_v2_line_info - Information about a certain GPIO line 204 204 * @name: the name of this GPIO line, such as the output pin of the line on 205 205 * the chip, a rail or a pin header name on a board, as specified by the 206 - * GPIO chip, may be empty 206 + * GPIO chip, may be empty (i.e. name[0] == '\0') 207 207 * @consumer: a functional name for the consumer of this GPIO line as set 208 208 * by whatever is using it, will be empty if there is no current user but 209 209 * may also be empty if the consumer doesn't set this up 210 - * @flags: flags for the GPIO line, such as GPIO_V2_LINE_FLAG_ACTIVE_LOW, 211 - * GPIO_V2_LINE_FLAG_OUTPUT etc, OR:ed together 212 210 * @offset: the local offset on this GPIO chip, fill this in when 213 211 * requesting the line information from the kernel 214 - * @num_attrs: the number of attributes in attrs 212 + * @num_attrs: the number of attributes in @attrs 213 + * @flags: flags for the GPIO lines, with values from &enum 214 + * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW, 215 + * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together. 215 216 * @attrs: the configuration attributes associated with the line 216 217 * @padding: reserved for future use 217 218 */ ··· 245 244 * of a GPIO line 246 245 * @info: updated line information 247 246 * @timestamp_ns: estimate of time of status change occurrence, in nanoseconds 248 - * @event_type: the type of change with a value from enum 247 + * @event_type: the type of change with a value from &enum 249 248 * gpio_v2_line_changed_type 250 249 * @padding: reserved for future use 251 250 */ ··· 270 269 /** 271 270 * struct gpio_v2_line_event - The actual event being pushed to userspace 272 271 * @timestamp_ns: best estimate of time of event occurrence, in nanoseconds. 273 - * The timestamp_ns is read from CLOCK_MONOTONIC and is intended to allow the 274 - * accurate measurement of the time between events. It does not provide 272 + * The @timestamp_ns is read from %CLOCK_MONOTONIC and is intended to allow 273 + * the accurate measurement of the time between events. It does not provide 275 274 * the wall-clock time. 276 - * @id: event identifier with value from enum gpio_v2_line_event_id 275 + * @id: event identifier with value from &enum gpio_v2_line_event_id 277 276 * @offset: the offset of the line that triggered the event 278 277 * @seqno: the sequence number for this event in the sequence of events for 279 278 * all the lines in this line request ··· 292 291 }; 293 292 294 293 /* 295 - * ABI v1 294 + * ABI v1 296 295 * 297 296 * This version of the ABI is deprecated. 298 297 * Use the latest version of the ABI, defined above, instead. ··· 315 314 * @flags: various flags for this line 316 315 * @name: the name of this GPIO line, such as the output pin of the line on the 317 316 * chip, a rail or a pin header name on a board, as specified by the gpio 318 - * chip, may be empty 317 + * chip, may be empty (i.e. name[0] == '\0') 319 318 * @consumer: a functional name for the consumer of this GPIO line as set by 320 319 * whatever is using it, will be empty if there is no current user but may 321 320 * also be empty if the consumer doesn't set this up 322 321 * 323 - * This struct is part of ABI v1 and is deprecated. 324 - * Use struct gpio_v2_line_info instead. 322 + * Note: This struct is part of ABI v1 and is deprecated. 323 + * Use &struct gpio_v2_line_info instead. 325 324 */ 326 325 struct gpioline_info { 327 326 __u32 line_offset; ··· 345 344 * of a GPIO line 346 345 * @info: updated line information 347 346 * @timestamp: estimate of time of status change occurrence, in nanoseconds 348 - * @event_type: one of GPIOLINE_CHANGED_REQUESTED, GPIOLINE_CHANGED_RELEASED 349 - * and GPIOLINE_CHANGED_CONFIG 347 + * @event_type: one of %GPIOLINE_CHANGED_REQUESTED, 348 + * %GPIOLINE_CHANGED_RELEASED and %GPIOLINE_CHANGED_CONFIG 349 + * @padding: reserved for future use 350 350 * 351 - * Note: struct gpioline_info embedded here has 32-bit alignment on its own, 351 + * The &struct gpioline_info embedded here has 32-bit alignment on its own, 352 352 * but it works fine with 64-bit alignment too. With its 72 byte size, we can 353 353 * guarantee there are no implicit holes between it and subsequent members. 354 354 * The 20-byte padding at the end makes sure we don't add any implicit padding 355 355 * at the end of the structure on 64-bit architectures. 356 356 * 357 - * This struct is part of ABI v1 and is deprecated. 358 - * Use struct gpio_v2_line_info_changed instead. 357 + * Note: This struct is part of ABI v1 and is deprecated. 358 + * Use &struct gpio_v2_line_info_changed instead. 359 359 */ 360 360 struct gpioline_info_changed { 361 361 struct gpioline_info info; ··· 380 378 * @lineoffsets: an array of desired lines, specified by offset index for the 381 379 * associated GPIO device 382 380 * @flags: desired flags for the desired GPIO lines, such as 383 - * GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed 381 + * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, added 384 382 * together. Note that even if multiple lines are requested, the same flags 385 383 * must be applicable to all of them, if you want lines with individual 386 384 * flags set, request them one by one. It is possible to select 387 385 * a batch of input or output lines, but they must all have the same 388 386 * characteristics, i.e. all inputs or all outputs, all active low etc 389 - * @default_values: if the GPIOHANDLE_REQUEST_OUTPUT is set for a requested 387 + * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is set for a requested 390 388 * line, this specifies the default output value, should be 0 (low) or 391 389 * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high) 392 390 * @consumer_label: a desired consumer label for the selected GPIO line(s) ··· 394 392 * @lines: number of lines requested in this request, i.e. the number of 395 393 * valid fields in the above arrays, set to 1 to request a single line 396 394 * @fd: if successful this field will contain a valid anonymous file handle 397 - * after a GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value 395 + * after a %GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value 398 396 * means error 399 397 * 400 - * This struct is part of ABI v1 and is deprecated. 401 - * Use struct gpio_v2_line_request instead. 398 + * Note: This struct is part of ABI v1 and is deprecated. 399 + * Use &struct gpio_v2_line_request instead. 402 400 */ 403 401 struct gpiohandle_request { 404 402 __u32 lineoffsets[GPIOHANDLES_MAX]; ··· 412 410 /** 413 411 * struct gpiohandle_config - Configuration for a GPIO handle request 414 412 * @flags: updated flags for the requested GPIO lines, such as 415 - * GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed 413 + * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, added 416 414 * together 417 - * @default_values: if the GPIOHANDLE_REQUEST_OUTPUT is set in flags, 415 + * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is set in flags, 418 416 * this specifies the default output value, should be 0 (low) or 419 417 * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high) 420 418 * @padding: reserved for future use and should be zero filled 421 419 * 422 - * This struct is part of ABI v1 and is deprecated. 423 - * Use struct gpio_v2_line_config instead. 420 + * Note: This struct is part of ABI v1 and is deprecated. 421 + * Use &struct gpio_v2_line_config instead. 424 422 */ 425 423 struct gpiohandle_config { 426 424 __u32 flags; ··· 434 432 * state of a line, when setting the state of lines these should contain 435 433 * the desired target state 436 434 * 437 - * This struct is part of ABI v1 and is deprecated. 438 - * Use struct gpio_v2_line_values instead. 435 + * Note: This struct is part of ABI v1 and is deprecated. 436 + * Use &struct gpio_v2_line_values instead. 439 437 */ 440 438 struct gpiohandle_data { 441 439 __u8 values[GPIOHANDLES_MAX]; ··· 451 449 * @lineoffset: the desired line to subscribe to events from, specified by 452 450 * offset index for the associated GPIO device 453 451 * @handleflags: desired handle flags for the desired GPIO line, such as 454 - * GPIOHANDLE_REQUEST_ACTIVE_LOW or GPIOHANDLE_REQUEST_OPEN_DRAIN 452 + * %GPIOHANDLE_REQUEST_ACTIVE_LOW or %GPIOHANDLE_REQUEST_OPEN_DRAIN 455 453 * @eventflags: desired flags for the desired GPIO event line, such as 456 - * GPIOEVENT_REQUEST_RISING_EDGE or GPIOEVENT_REQUEST_FALLING_EDGE 454 + * %GPIOEVENT_REQUEST_RISING_EDGE or %GPIOEVENT_REQUEST_FALLING_EDGE 457 455 * @consumer_label: a desired consumer label for the selected GPIO line(s) 458 456 * such as "my-listener" 459 457 * @fd: if successful this field will contain a valid anonymous file handle 460 - * after a GPIO_GET_LINEEVENT_IOCTL operation, zero or negative value 458 + * after a %GPIO_GET_LINEEVENT_IOCTL operation, zero or negative value 461 459 * means error 462 460 * 463 - * This struct is part of ABI v1 and is deprecated. 464 - * Use struct gpio_v2_line_request instead. 461 + * Note: This struct is part of ABI v1 and is deprecated. 462 + * Use &struct gpio_v2_line_request instead. 465 463 */ 466 464 struct gpioevent_request { 467 465 __u32 lineoffset; ··· 471 469 int fd; 472 470 }; 473 471 474 - /** 472 + /* 475 473 * GPIO event types 476 474 */ 477 475 #define GPIOEVENT_EVENT_RISING_EDGE 0x01 ··· 482 480 * @timestamp: best estimate of time of event occurrence, in nanoseconds 483 481 * @id: event identifier 484 482 * 485 - * This struct is part of ABI v1 and is deprecated. 486 - * Use struct gpio_v2_line_event instead. 483 + * Note: This struct is part of ABI v1 and is deprecated. 484 + * Use &struct gpio_v2_line_event instead. 487 485 */ 488 486 struct gpioevent_data { 489 487 __u64 timestamp;
+12 -2
init/main.c
··· 269 269 u32 size, csum; 270 270 char *data; 271 271 u32 *hdr; 272 + int i; 272 273 273 274 if (!initrd_end) 274 275 return NULL; 275 276 276 277 data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN; 277 - if (memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN)) 278 - return NULL; 278 + /* 279 + * Since Grub may align the size of initrd to 4, we must 280 + * check the preceding 3 bytes as well. 281 + */ 282 + for (i = 0; i < 4; i++) { 283 + if (!memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN)) 284 + goto found; 285 + data--; 286 + } 287 + return NULL; 279 288 289 + found: 280 290 hdr = (u32 *)(data - 8); 281 291 size = hdr[0]; 282 292 csum = hdr[1];
+25 -32
kernel/events/core.c
··· 2312 2312 event_sched_out(event, cpuctx, ctx); 2313 2313 2314 2314 perf_pmu_enable(ctx->pmu); 2315 - 2316 - if (group_event->attr.exclusive) 2317 - cpuctx->exclusive = 0; 2318 2315 } 2319 2316 2320 2317 #define DETACH_GROUP 0x01UL ··· 2580 2583 2581 2584 pmu->start_txn(pmu, PERF_PMU_TXN_ADD); 2582 2585 2583 - if (event_sched_in(group_event, cpuctx, ctx)) { 2584 - pmu->cancel_txn(pmu); 2585 - perf_mux_hrtimer_restart(cpuctx); 2586 - return -EAGAIN; 2587 - } 2586 + if (event_sched_in(group_event, cpuctx, ctx)) 2587 + goto error; 2588 2588 2589 2589 /* 2590 2590 * Schedule in siblings as one group (if any): ··· 2610 2616 } 2611 2617 event_sched_out(group_event, cpuctx, ctx); 2612 2618 2619 + error: 2613 2620 pmu->cancel_txn(pmu); 2614 - 2615 - perf_mux_hrtimer_restart(cpuctx); 2616 - 2617 2621 return -EAGAIN; 2618 2622 } 2619 2623 ··· 2637 2645 * If this group is exclusive and there are already 2638 2646 * events on the CPU, it can't go on. 2639 2647 */ 2640 - if (event->attr.exclusive && cpuctx->active_oncpu) 2648 + if (event->attr.exclusive && !list_empty(get_event_list(event))) 2641 2649 return 0; 2642 2650 /* 2643 2651 * Otherwise, try to add it if all previous groups were able ··· 3671 3679 3672 3680 *can_add_hw = 0; 3673 3681 ctx->rotate_necessary = 1; 3682 + perf_mux_hrtimer_restart(cpuctx); 3674 3683 } 3675 3684 3676 3685 return 0; ··· 6367 6374 } 6368 6375 6369 6376 static void perf_sample_regs_user(struct perf_regs *regs_user, 6370 - struct pt_regs *regs, 6371 - struct pt_regs *regs_user_copy) 6377 + struct pt_regs *regs) 6372 6378 { 6373 6379 if (user_mode(regs)) { 6374 6380 regs_user->abi = perf_reg_abi(current); 6375 6381 regs_user->regs = regs; 6376 6382 } else if (!(current->flags & PF_KTHREAD)) { 6377 - perf_get_regs_user(regs_user, regs, regs_user_copy); 6383 + perf_get_regs_user(regs_user, regs); 6378 6384 } else { 6379 6385 regs_user->abi = PERF_SAMPLE_REGS_ABI_NONE; 6380 6386 regs_user->regs = NULL; ··· 7075 7083 } 7076 7084 7077 7085 if (sample_type & (PERF_SAMPLE_REGS_USER | PERF_SAMPLE_STACK_USER)) 7078 - perf_sample_regs_user(&data->regs_user, regs, 7079 - &data->regs_user_copy); 7086 + perf_sample_regs_user(&data->regs_user, regs); 7080 7087 7081 7088 if (sample_type & PERF_SAMPLE_REGS_USER) { 7082 7089 /* regs dump ABI info */ ··· 7177 7186 struct perf_sample_data *data, 7178 7187 struct pt_regs *regs, 7179 7188 int (*output_begin)(struct perf_output_handle *, 7189 + struct perf_sample_data *, 7180 7190 struct perf_event *, 7181 7191 unsigned int)) 7182 7192 { ··· 7190 7198 7191 7199 perf_prepare_sample(&header, data, event, regs); 7192 7200 7193 - err = output_begin(&handle, event, header.size); 7201 + err = output_begin(&handle, data, event, header.size); 7194 7202 if (err) 7195 7203 goto exit; 7196 7204 ··· 7256 7264 int ret; 7257 7265 7258 7266 perf_event_header__init_id(&read_event.header, &sample, event); 7259 - ret = perf_output_begin(&handle, event, read_event.header.size); 7267 + ret = perf_output_begin(&handle, &sample, event, read_event.header.size); 7260 7268 if (ret) 7261 7269 return; 7262 7270 ··· 7525 7533 7526 7534 perf_event_header__init_id(&task_event->event_id.header, &sample, event); 7527 7535 7528 - ret = perf_output_begin(&handle, event, 7536 + ret = perf_output_begin(&handle, &sample, event, 7529 7537 task_event->event_id.header.size); 7530 7538 if (ret) 7531 7539 goto out; ··· 7628 7636 return; 7629 7637 7630 7638 perf_event_header__init_id(&comm_event->event_id.header, &sample, event); 7631 - ret = perf_output_begin(&handle, event, 7639 + ret = perf_output_begin(&handle, &sample, event, 7632 7640 comm_event->event_id.header.size); 7633 7641 7634 7642 if (ret) ··· 7728 7736 7729 7737 perf_event_header__init_id(&namespaces_event->event_id.header, 7730 7738 &sample, event); 7731 - ret = perf_output_begin(&handle, event, 7739 + ret = perf_output_begin(&handle, &sample, event, 7732 7740 namespaces_event->event_id.header.size); 7733 7741 if (ret) 7734 7742 goto out; ··· 7855 7863 7856 7864 perf_event_header__init_id(&cgroup_event->event_id.header, 7857 7865 &sample, event); 7858 - ret = perf_output_begin(&handle, event, 7866 + ret = perf_output_begin(&handle, &sample, event, 7859 7867 cgroup_event->event_id.header.size); 7860 7868 if (ret) 7861 7869 goto out; ··· 7981 7989 } 7982 7990 7983 7991 perf_event_header__init_id(&mmap_event->event_id.header, &sample, event); 7984 - ret = perf_output_begin(&handle, event, 7992 + ret = perf_output_begin(&handle, &sample, event, 7985 7993 mmap_event->event_id.header.size); 7986 7994 if (ret) 7987 7995 goto out; ··· 8291 8299 int ret; 8292 8300 8293 8301 perf_event_header__init_id(&rec.header, &sample, event); 8294 - ret = perf_output_begin(&handle, event, rec.header.size); 8302 + ret = perf_output_begin(&handle, &sample, event, rec.header.size); 8295 8303 8296 8304 if (ret) 8297 8305 return; ··· 8325 8333 8326 8334 perf_event_header__init_id(&lost_samples_event.header, &sample, event); 8327 8335 8328 - ret = perf_output_begin(&handle, event, 8336 + ret = perf_output_begin(&handle, &sample, event, 8329 8337 lost_samples_event.header.size); 8330 8338 if (ret) 8331 8339 return; ··· 8380 8388 8381 8389 perf_event_header__init_id(&se->event_id.header, &sample, event); 8382 8390 8383 - ret = perf_output_begin(&handle, event, se->event_id.header.size); 8391 + ret = perf_output_begin(&handle, &sample, event, se->event_id.header.size); 8384 8392 if (ret) 8385 8393 return; 8386 8394 ··· 8455 8463 8456 8464 perf_event_header__init_id(&throttle_event.header, &sample, event); 8457 8465 8458 - ret = perf_output_begin(&handle, event, 8466 + ret = perf_output_begin(&handle, &sample, event, 8459 8467 throttle_event.header.size); 8460 8468 if (ret) 8461 8469 return; ··· 8498 8506 8499 8507 perf_event_header__init_id(&ksymbol_event->event_id.header, 8500 8508 &sample, event); 8501 - ret = perf_output_begin(&handle, event, 8509 + ret = perf_output_begin(&handle, &sample, event, 8502 8510 ksymbol_event->event_id.header.size); 8503 8511 if (ret) 8504 8512 return; ··· 8588 8596 8589 8597 perf_event_header__init_id(&bpf_event->event_id.header, 8590 8598 &sample, event); 8591 - ret = perf_output_begin(&handle, event, 8599 + ret = perf_output_begin(&handle, data, event, 8592 8600 bpf_event->event_id.header.size); 8593 8601 if (ret) 8594 8602 return; ··· 8697 8705 8698 8706 perf_event_header__init_id(&text_poke_event->event_id.header, &sample, event); 8699 8707 8700 - ret = perf_output_begin(&handle, event, text_poke_event->event_id.header.size); 8708 + ret = perf_output_begin(&handle, &sample, event, 8709 + text_poke_event->event_id.header.size); 8701 8710 if (ret) 8702 8711 return; 8703 8712 ··· 8779 8786 rec.tid = perf_event_tid(event, current); 8780 8787 8781 8788 perf_event_header__init_id(&rec.header, &sample, event); 8782 - ret = perf_output_begin(&handle, event, rec.header.size); 8789 + ret = perf_output_begin(&handle, &sample, event, rec.header.size); 8783 8790 8784 8791 if (ret) 8785 8792 return;
+5 -9
kernel/events/internal.h
··· 205 205 206 206 static inline int get_recursion_context(int *recursion) 207 207 { 208 - int rctx; 208 + unsigned int pc = preempt_count(); 209 + unsigned char rctx = 0; 209 210 210 - if (unlikely(in_nmi())) 211 - rctx = 3; 212 - else if (in_irq()) 213 - rctx = 2; 214 - else if (in_softirq()) 215 - rctx = 1; 216 - else 217 - rctx = 0; 211 + rctx += !!(pc & (NMI_MASK)); 212 + rctx += !!(pc & (NMI_MASK | HARDIRQ_MASK)); 213 + rctx += !!(pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)); 218 214 219 215 if (recursion[rctx]) 220 216 return -1;
+11 -9
kernel/events/ring_buffer.c
··· 147 147 148 148 static __always_inline int 149 149 __perf_output_begin(struct perf_output_handle *handle, 150 + struct perf_sample_data *data, 150 151 struct perf_event *event, unsigned int size, 151 152 bool backward) 152 153 { ··· 238 237 handle->size = (1UL << page_shift) - offset; 239 238 240 239 if (unlikely(have_lost)) { 241 - struct perf_sample_data sample_data; 242 - 243 240 lost_event.header.size = sizeof(lost_event); 244 241 lost_event.header.type = PERF_RECORD_LOST; 245 242 lost_event.header.misc = 0; 246 243 lost_event.id = event->id; 247 244 lost_event.lost = local_xchg(&rb->lost, 0); 248 245 249 - perf_event_header__init_id(&lost_event.header, 250 - &sample_data, event); 246 + /* XXX mostly redundant; @data is already fully initializes */ 247 + perf_event_header__init_id(&lost_event.header, data, event); 251 248 perf_output_put(handle, lost_event); 252 - perf_event__output_id_sample(event, handle, &sample_data); 249 + perf_event__output_id_sample(event, handle, data); 253 250 } 254 251 255 252 return 0; ··· 262 263 } 263 264 264 265 int perf_output_begin_forward(struct perf_output_handle *handle, 265 - struct perf_event *event, unsigned int size) 266 + struct perf_sample_data *data, 267 + struct perf_event *event, unsigned int size) 266 268 { 267 - return __perf_output_begin(handle, event, size, false); 269 + return __perf_output_begin(handle, data, event, size, false); 268 270 } 269 271 270 272 int perf_output_begin_backward(struct perf_output_handle *handle, 273 + struct perf_sample_data *data, 271 274 struct perf_event *event, unsigned int size) 272 275 { 273 - return __perf_output_begin(handle, event, size, true); 276 + return __perf_output_begin(handle, data, event, size, true); 274 277 } 275 278 276 279 int perf_output_begin(struct perf_output_handle *handle, 280 + struct perf_sample_data *data, 277 281 struct perf_event *event, unsigned int size) 278 282 { 279 283 280 - return __perf_output_begin(handle, event, size, 284 + return __perf_output_begin(handle, data, event, size, 281 285 unlikely(is_write_backward(event))); 282 286 } 283 287
+3 -2
kernel/futex.c
··· 788 788 */ 789 789 if (pi_state->owner) { 790 790 struct task_struct *owner; 791 + unsigned long flags; 791 792 792 - raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock); 793 + raw_spin_lock_irqsave(&pi_state->pi_mutex.wait_lock, flags); 793 794 owner = pi_state->owner; 794 795 if (owner) { 795 796 raw_spin_lock(&owner->pi_lock); ··· 798 797 raw_spin_unlock(&owner->pi_lock); 799 798 } 800 799 rt_mutex_proxy_unlock(&pi_state->pi_mutex, owner); 801 - raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); 800 + raw_spin_unlock_irqrestore(&pi_state->pi_mutex.wait_lock, flags); 802 801 } 803 802 804 803 if (current->pi_state_cache) {
+9 -10
kernel/locking/lockdep.c
··· 2765 2765 * (Note that this has to be done separately, because the graph cannot 2766 2766 * detect such classes of deadlocks.) 2767 2767 * 2768 - * Returns: 0 on deadlock detected, 1 on OK, 2 on recursive read 2768 + * Returns: 0 on deadlock detected, 1 on OK, 2 if another lock with the same 2769 + * lock class is held but nest_lock is also held, i.e. we rely on the 2770 + * nest_lock to avoid the deadlock. 2769 2771 */ 2770 2772 static int 2771 2773 check_deadlock(struct task_struct *curr, struct held_lock *next) ··· 2790 2788 * lock class (i.e. read_lock(lock)+read_lock(lock)): 2791 2789 */ 2792 2790 if ((next->read == 2) && prev->read) 2793 - return 2; 2791 + continue; 2794 2792 2795 2793 /* 2796 2794 * We're holding the nest_lock, which serializes this lock's ··· 3595 3593 if (!ret) 3596 3594 return 0; 3597 3595 /* 3598 - * Mark recursive read, as we jump over it when 3599 - * building dependencies (just like we jump over 3600 - * trylock entries): 3601 - */ 3602 - if (ret == 2) 3603 - hlock->read = 2; 3604 - /* 3605 3596 * Add dependency only if this lock is not the head 3606 - * of the chain, and if it's not a secondary read-lock: 3597 + * of the chain, and if the new lock introduces no more 3598 + * lock dependency (because we already hold a lock with the 3599 + * same lock class) nor deadlock (because the nest_lock 3600 + * serializes nesting locks), see the comments for 3601 + * check_deadlock(). 3607 3602 */ 3608 3603 if (!chain_head && ret != 2) { 3609 3604 if (!check_prevs_add(curr, hlock))
+2 -1
kernel/panic.c
··· 605 605 panic("panic_on_warn set ...\n"); 606 606 } 607 607 608 - dump_stack(); 608 + if (!regs) 609 + dump_stack(); 609 610 610 611 print_irqtrace_events(current); 611 612
+1 -1
kernel/rcu/tree.c
··· 4077 4077 smp_mb(); /* Ensure RCU read-side usage follows above initialization. */ 4078 4078 } 4079 4079 4080 - #ifdef CONFIG_HOTPLUG_CPU 4081 4080 /* 4082 4081 * The outgoing function has no further need of RCU, so remove it from 4083 4082 * the rcu_node tree's ->qsmaskinitnext bit masks. ··· 4116 4117 rdp->cpu_started = false; 4117 4118 } 4118 4119 4120 + #ifdef CONFIG_HOTPLUG_CPU 4119 4121 /* 4120 4122 * The outgoing CPU has just passed through the dying-idle state, and we 4121 4123 * are being invoked from the CPU that was IPIed to continue the offline
+14 -14
kernel/reboot.c
··· 551 551 break; 552 552 553 553 case 's': 554 - { 555 - int rc; 556 - 557 - if (isdigit(*(str+1))) { 558 - rc = kstrtoint(str+1, 0, &reboot_cpu); 559 - if (rc) 560 - return rc; 561 - } else if (str[1] == 'm' && str[2] == 'p' && 562 - isdigit(*(str+3))) { 563 - rc = kstrtoint(str+3, 0, &reboot_cpu); 564 - if (rc) 565 - return rc; 566 - } else 554 + if (isdigit(*(str+1))) 555 + reboot_cpu = simple_strtoul(str+1, NULL, 0); 556 + else if (str[1] == 'm' && str[2] == 'p' && 557 + isdigit(*(str+3))) 558 + reboot_cpu = simple_strtoul(str+3, NULL, 0); 559 + else 567 560 *mode = REBOOT_SOFT; 561 + if (reboot_cpu >= num_possible_cpus()) { 562 + pr_err("Ignoring the CPU number in reboot= option. " 563 + "CPU %d exceeds possible cpu number %d\n", 564 + reboot_cpu, num_possible_cpus()); 565 + reboot_cpu = 0; 566 + break; 567 + } 568 568 break; 569 - } 569 + 570 570 case 'g': 571 571 *mode = REBOOT_GPIO; 572 572 break;
+6 -6
kernel/sched/debug.c
··· 251 251 unsigned long flags = *(unsigned long *)table->data; 252 252 size_t data_size = 0; 253 253 size_t len = 0; 254 - char *tmp; 254 + char *tmp, *buf; 255 255 int idx; 256 256 257 257 if (write) ··· 269 269 return 0; 270 270 } 271 271 272 - tmp = kcalloc(data_size + 1, sizeof(*tmp), GFP_KERNEL); 273 - if (!tmp) 272 + buf = kcalloc(data_size + 1, sizeof(*buf), GFP_KERNEL); 273 + if (!buf) 274 274 return -ENOMEM; 275 275 276 276 for_each_set_bit(idx, &flags, __SD_FLAG_CNT) { 277 277 char *name = sd_flag_debug[idx].name; 278 278 279 - len += snprintf(tmp + len, strlen(name) + 2, "%s ", name); 279 + len += snprintf(buf + len, strlen(name) + 2, "%s ", name); 280 280 } 281 281 282 - tmp += *ppos; 282 + tmp = buf + *ppos; 283 283 len -= *ppos; 284 284 285 285 if (len > *lenp) ··· 294 294 *lenp = len; 295 295 *ppos += len; 296 296 297 - kfree(tmp); 297 + kfree(buf); 298 298 299 299 return 0; 300 300 }
+45 -25
kernel/sched/fair.c
··· 6172 6172 static int 6173 6173 select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target) 6174 6174 { 6175 - unsigned long best_cap = 0; 6175 + unsigned long task_util, best_cap = 0; 6176 6176 int cpu, best_cpu = -1; 6177 6177 struct cpumask *cpus; 6178 6178 6179 - sync_entity_load_avg(&p->se); 6180 - 6181 6179 cpus = this_cpu_cpumask_var_ptr(select_idle_mask); 6182 6180 cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr); 6181 + 6182 + task_util = uclamp_task_util(p); 6183 6183 6184 6184 for_each_cpu_wrap(cpu, cpus, target) { 6185 6185 unsigned long cpu_cap = capacity_of(cpu); 6186 6186 6187 6187 if (!available_idle_cpu(cpu) && !sched_idle_cpu(cpu)) 6188 6188 continue; 6189 - if (task_fits_capacity(p, cpu_cap)) 6189 + if (fits_capacity(task_util, cpu_cap)) 6190 6190 return cpu; 6191 6191 6192 6192 if (cpu_cap > best_cap) { ··· 6198 6198 return best_cpu; 6199 6199 } 6200 6200 6201 + static inline bool asym_fits_capacity(int task_util, int cpu) 6202 + { 6203 + if (static_branch_unlikely(&sched_asym_cpucapacity)) 6204 + return fits_capacity(task_util, capacity_of(cpu)); 6205 + 6206 + return true; 6207 + } 6208 + 6201 6209 /* 6202 6210 * Try and locate an idle core/thread in the LLC cache domain. 6203 6211 */ 6204 6212 static int select_idle_sibling(struct task_struct *p, int prev, int target) 6205 6213 { 6206 6214 struct sched_domain *sd; 6215 + unsigned long task_util; 6207 6216 int i, recent_used_cpu; 6208 6217 6209 6218 /* 6210 - * For asymmetric CPU capacity systems, our domain of interest is 6211 - * sd_asym_cpucapacity rather than sd_llc. 6219 + * On asymmetric system, update task utilization because we will check 6220 + * that the task fits with cpu's capacity. 6212 6221 */ 6213 6222 if (static_branch_unlikely(&sched_asym_cpucapacity)) { 6214 - sd = rcu_dereference(per_cpu(sd_asym_cpucapacity, target)); 6215 - /* 6216 - * On an asymmetric CPU capacity system where an exclusive 6217 - * cpuset defines a symmetric island (i.e. one unique 6218 - * capacity_orig value through the cpuset), the key will be set 6219 - * but the CPUs within that cpuset will not have a domain with 6220 - * SD_ASYM_CPUCAPACITY. These should follow the usual symmetric 6221 - * capacity path. 6222 - */ 6223 - if (!sd) 6224 - goto symmetric; 6225 - 6226 - i = select_idle_capacity(p, sd, target); 6227 - return ((unsigned)i < nr_cpumask_bits) ? i : target; 6223 + sync_entity_load_avg(&p->se); 6224 + task_util = uclamp_task_util(p); 6228 6225 } 6229 6226 6230 - symmetric: 6231 - if (available_idle_cpu(target) || sched_idle_cpu(target)) 6227 + if ((available_idle_cpu(target) || sched_idle_cpu(target)) && 6228 + asym_fits_capacity(task_util, target)) 6232 6229 return target; 6233 6230 6234 6231 /* 6235 6232 * If the previous CPU is cache affine and idle, don't be stupid: 6236 6233 */ 6237 6234 if (prev != target && cpus_share_cache(prev, target) && 6238 - (available_idle_cpu(prev) || sched_idle_cpu(prev))) 6235 + (available_idle_cpu(prev) || sched_idle_cpu(prev)) && 6236 + asym_fits_capacity(task_util, prev)) 6239 6237 return prev; 6240 6238 6241 6239 /* ··· 6256 6258 recent_used_cpu != target && 6257 6259 cpus_share_cache(recent_used_cpu, target) && 6258 6260 (available_idle_cpu(recent_used_cpu) || sched_idle_cpu(recent_used_cpu)) && 6259 - cpumask_test_cpu(p->recent_used_cpu, p->cpus_ptr)) { 6261 + cpumask_test_cpu(p->recent_used_cpu, p->cpus_ptr) && 6262 + asym_fits_capacity(task_util, recent_used_cpu)) { 6260 6263 /* 6261 6264 * Replace recent_used_cpu with prev as it is a potential 6262 6265 * candidate for the next wake: 6263 6266 */ 6264 6267 p->recent_used_cpu = prev; 6265 6268 return recent_used_cpu; 6269 + } 6270 + 6271 + /* 6272 + * For asymmetric CPU capacity systems, our domain of interest is 6273 + * sd_asym_cpucapacity rather than sd_llc. 6274 + */ 6275 + if (static_branch_unlikely(&sched_asym_cpucapacity)) { 6276 + sd = rcu_dereference(per_cpu(sd_asym_cpucapacity, target)); 6277 + /* 6278 + * On an asymmetric CPU capacity system where an exclusive 6279 + * cpuset defines a symmetric island (i.e. one unique 6280 + * capacity_orig value through the cpuset), the key will be set 6281 + * but the CPUs within that cpuset will not have a domain with 6282 + * SD_ASYM_CPUCAPACITY. These should follow the usual symmetric 6283 + * capacity path. 6284 + */ 6285 + if (sd) { 6286 + i = select_idle_capacity(p, sd, target); 6287 + return ((unsigned)i < nr_cpumask_bits) ? i : target; 6288 + } 6266 6289 } 6267 6290 6268 6291 sd = rcu_dereference(per_cpu(sd_llc, target)); ··· 9050 9031 * emptying busiest. 9051 9032 */ 9052 9033 if (local->group_type == group_has_spare) { 9053 - if (busiest->group_type > group_fully_busy) { 9034 + if ((busiest->group_type > group_fully_busy) && 9035 + !(env->sd->flags & SD_SHARE_PKG_RESOURCES)) { 9054 9036 /* 9055 9037 * If busiest is overloaded, try to fill spare 9056 9038 * capacity. This might end up creating spare capacity
+2 -2
kernel/watchdog.c
··· 44 44 int __read_mostly watchdog_thresh = 10; 45 45 static int __read_mostly nmi_watchdog_available; 46 46 47 - static struct cpumask watchdog_allowed_mask __read_mostly; 48 - 49 47 struct cpumask watchdog_cpumask __read_mostly; 50 48 unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask); 51 49 ··· 159 161 #ifdef CONFIG_SMP 160 162 int __read_mostly sysctl_softlockup_all_cpu_backtrace; 161 163 #endif 164 + 165 + static struct cpumask watchdog_allowed_mask __read_mostly; 162 166 163 167 /* Global variables, exported for sysctl */ 164 168 unsigned int __read_mostly softlockup_panic =
+8 -4
mm/compaction.c
··· 817 817 * delay for some time until fewer pages are isolated 818 818 */ 819 819 while (unlikely(too_many_isolated(pgdat))) { 820 + /* stop isolation if there are still pages not migrated */ 821 + if (cc->nr_migratepages) 822 + return 0; 823 + 820 824 /* async migration should just abort */ 821 825 if (cc->mode == MIGRATE_ASYNC) 822 826 return 0; ··· 1016 1012 1017 1013 isolate_success: 1018 1014 list_add(&page->lru, &cc->migratepages); 1019 - cc->nr_migratepages++; 1020 - nr_isolated++; 1015 + cc->nr_migratepages += compound_nr(page); 1016 + nr_isolated += compound_nr(page); 1021 1017 1022 1018 /* 1023 1019 * Avoid isolating too much unless this block is being ··· 1025 1021 * or a lock is contended. For contention, isolate quickly to 1026 1022 * potentially remove one source of contention. 1027 1023 */ 1028 - if (cc->nr_migratepages == COMPACT_CLUSTER_MAX && 1024 + if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX && 1029 1025 !cc->rescan && !cc->contended) { 1030 1026 ++low_pfn; 1031 1027 break; ··· 1136 1132 if (!pfn) 1137 1133 break; 1138 1134 1139 - if (cc->nr_migratepages == COMPACT_CLUSTER_MAX) 1135 + if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX) 1140 1136 break; 1141 1137 } 1142 1138
+10 -4
mm/gup.c
··· 1647 1647 /* 1648 1648 * drop the above get_user_pages reference. 1649 1649 */ 1650 - for (i = 0; i < nr_pages; i++) 1651 - put_page(pages[i]); 1650 + if (gup_flags & FOLL_PIN) 1651 + unpin_user_pages(pages, nr_pages); 1652 + else 1653 + for (i = 0; i < nr_pages; i++) 1654 + put_page(pages[i]); 1652 1655 1653 1656 if (migrate_pages(&cma_page_list, alloc_migration_target, NULL, 1654 1657 (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE)) { ··· 1731 1728 goto out; 1732 1729 1733 1730 if (check_dax_vmas(vmas_tmp, rc)) { 1734 - for (i = 0; i < rc; i++) 1735 - put_page(pages[i]); 1731 + if (gup_flags & FOLL_PIN) 1732 + unpin_user_pages(pages, rc); 1733 + else 1734 + for (i = 0; i < rc; i++) 1735 + put_page(pages[i]); 1736 1736 rc = -EOPNOTSUPP; 1737 1737 goto out; 1738 1738 }
+5 -85
mm/hugetlb.c
··· 1568 1568 } 1569 1569 1570 1570 /* 1571 - * Find address_space associated with hugetlbfs page. 1572 - * Upon entry page is locked and page 'was' mapped although mapped state 1573 - * could change. If necessary, use anon_vma to find vma and associated 1574 - * address space. The returned mapping may be stale, but it can not be 1575 - * invalid as page lock (which is held) is required to destroy mapping. 1576 - */ 1577 - static struct address_space *_get_hugetlb_page_mapping(struct page *hpage) 1578 - { 1579 - struct anon_vma *anon_vma; 1580 - pgoff_t pgoff_start, pgoff_end; 1581 - struct anon_vma_chain *avc; 1582 - struct address_space *mapping = page_mapping(hpage); 1583 - 1584 - /* Simple file based mapping */ 1585 - if (mapping) 1586 - return mapping; 1587 - 1588 - /* 1589 - * Even anonymous hugetlbfs mappings are associated with an 1590 - * underlying hugetlbfs file (see hugetlb_file_setup in mmap 1591 - * code). Find a vma associated with the anonymous vma, and 1592 - * use the file pointer to get address_space. 1593 - */ 1594 - anon_vma = page_lock_anon_vma_read(hpage); 1595 - if (!anon_vma) 1596 - return mapping; /* NULL */ 1597 - 1598 - /* Use first found vma */ 1599 - pgoff_start = page_to_pgoff(hpage); 1600 - pgoff_end = pgoff_start + pages_per_huge_page(page_hstate(hpage)) - 1; 1601 - anon_vma_interval_tree_foreach(avc, &anon_vma->rb_root, 1602 - pgoff_start, pgoff_end) { 1603 - struct vm_area_struct *vma = avc->vma; 1604 - 1605 - mapping = vma->vm_file->f_mapping; 1606 - break; 1607 - } 1608 - 1609 - anon_vma_unlock_read(anon_vma); 1610 - return mapping; 1611 - } 1612 - 1613 - /* 1614 1571 * Find and lock address space (mapping) in write mode. 1615 1572 * 1616 - * Upon entry, the page is locked which allows us to find the mapping 1617 - * even in the case of an anon page. However, locking order dictates 1618 - * the i_mmap_rwsem be acquired BEFORE the page lock. This is hugetlbfs 1619 - * specific. So, we first try to lock the sema while still holding the 1620 - * page lock. If this works, great! If not, then we need to drop the 1621 - * page lock and then acquire i_mmap_rwsem and reacquire page lock. Of 1622 - * course, need to revalidate state along the way. 1573 + * Upon entry, the page is locked which means that page_mapping() is 1574 + * stable. Due to locking order, we can only trylock_write. If we can 1575 + * not get the lock, simply return NULL to caller. 1623 1576 */ 1624 1577 struct address_space *hugetlb_page_mapping_lock_write(struct page *hpage) 1625 1578 { 1626 - struct address_space *mapping, *mapping2; 1579 + struct address_space *mapping = page_mapping(hpage); 1627 1580 1628 - mapping = _get_hugetlb_page_mapping(hpage); 1629 - retry: 1630 1581 if (!mapping) 1631 1582 return mapping; 1632 1583 1633 - /* 1634 - * If no contention, take lock and return 1635 - */ 1636 1584 if (i_mmap_trylock_write(mapping)) 1637 1585 return mapping; 1638 1586 1639 - /* 1640 - * Must drop page lock and wait on mapping sema. 1641 - * Note: Once page lock is dropped, mapping could become invalid. 1642 - * As a hack, increase map count until we lock page again. 1643 - */ 1644 - atomic_inc(&hpage->_mapcount); 1645 - unlock_page(hpage); 1646 - i_mmap_lock_write(mapping); 1647 - lock_page(hpage); 1648 - atomic_add_negative(-1, &hpage->_mapcount); 1649 - 1650 - /* verify page is still mapped */ 1651 - if (!page_mapped(hpage)) { 1652 - i_mmap_unlock_write(mapping); 1653 - return NULL; 1654 - } 1655 - 1656 - /* 1657 - * Get address space again and verify it is the same one 1658 - * we locked. If not, drop lock and retry. 1659 - */ 1660 - mapping2 = _get_hugetlb_page_mapping(hpage); 1661 - if (mapping2 != mapping) { 1662 - i_mmap_unlock_write(mapping); 1663 - mapping = mapping2; 1664 - goto retry; 1665 - } 1666 - 1667 - return mapping; 1587 + return NULL; 1668 1588 } 1669 1589 1670 1590 pgoff_t __basepage_index(struct page *page)
+17 -19
mm/memory-failure.c
··· 1057 1057 if (!PageHuge(hpage)) { 1058 1058 unmap_success = try_to_unmap(hpage, ttu); 1059 1059 } else { 1060 - /* 1061 - * For hugetlb pages, try_to_unmap could potentially call 1062 - * huge_pmd_unshare. Because of this, take semaphore in 1063 - * write mode here and set TTU_RMAP_LOCKED to indicate we 1064 - * have taken the lock at this higer level. 1065 - * 1066 - * Note that the call to hugetlb_page_mapping_lock_write 1067 - * is necessary even if mapping is already set. It handles 1068 - * ugliness of potentially having to drop page lock to obtain 1069 - * i_mmap_rwsem. 1070 - */ 1071 - mapping = hugetlb_page_mapping_lock_write(hpage); 1072 - 1073 - if (mapping) { 1074 - unmap_success = try_to_unmap(hpage, 1060 + if (!PageAnon(hpage)) { 1061 + /* 1062 + * For hugetlb pages in shared mappings, try_to_unmap 1063 + * could potentially call huge_pmd_unshare. Because of 1064 + * this, take semaphore in write mode here and set 1065 + * TTU_RMAP_LOCKED to indicate we have taken the lock 1066 + * at this higer level. 1067 + */ 1068 + mapping = hugetlb_page_mapping_lock_write(hpage); 1069 + if (mapping) { 1070 + unmap_success = try_to_unmap(hpage, 1075 1071 ttu|TTU_RMAP_LOCKED); 1076 - i_mmap_unlock_write(mapping); 1072 + i_mmap_unlock_write(mapping); 1073 + } else { 1074 + pr_info("Memory failure: %#lx: could not lock mapping for mapped huge page\n", pfn); 1075 + unmap_success = false; 1076 + } 1077 1077 } else { 1078 - pr_info("Memory failure: %#lx: could not find mapping for mapped huge page\n", 1079 - pfn); 1080 - unmap_success = false; 1078 + unmap_success = try_to_unmap(hpage, ttu); 1081 1079 } 1082 1080 } 1083 1081 if (!unmap_success)
+24 -20
mm/migrate.c
··· 1328 1328 goto put_anon; 1329 1329 1330 1330 if (page_mapped(hpage)) { 1331 - /* 1332 - * try_to_unmap could potentially call huge_pmd_unshare. 1333 - * Because of this, take semaphore in write mode here and 1334 - * set TTU_RMAP_LOCKED to let lower levels know we have 1335 - * taken the lock. 1336 - */ 1337 - mapping = hugetlb_page_mapping_lock_write(hpage); 1338 - if (unlikely(!mapping)) 1339 - goto unlock_put_anon; 1331 + bool mapping_locked = false; 1332 + enum ttu_flags ttu = TTU_MIGRATION|TTU_IGNORE_MLOCK| 1333 + TTU_IGNORE_ACCESS; 1340 1334 1341 - try_to_unmap(hpage, 1342 - TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS| 1343 - TTU_RMAP_LOCKED); 1335 + if (!PageAnon(hpage)) { 1336 + /* 1337 + * In shared mappings, try_to_unmap could potentially 1338 + * call huge_pmd_unshare. Because of this, take 1339 + * semaphore in write mode here and set TTU_RMAP_LOCKED 1340 + * to let lower levels know we have taken the lock. 1341 + */ 1342 + mapping = hugetlb_page_mapping_lock_write(hpage); 1343 + if (unlikely(!mapping)) 1344 + goto unlock_put_anon; 1345 + 1346 + mapping_locked = true; 1347 + ttu |= TTU_RMAP_LOCKED; 1348 + } 1349 + 1350 + try_to_unmap(hpage, ttu); 1344 1351 page_was_mapped = 1; 1345 - /* 1346 - * Leave mapping locked until after subsequent call to 1347 - * remove_migration_ptes() 1348 - */ 1352 + 1353 + if (mapping_locked) 1354 + i_mmap_unlock_write(mapping); 1349 1355 } 1350 1356 1351 1357 if (!page_mapped(hpage)) 1352 1358 rc = move_to_new_page(new_hpage, hpage, mode); 1353 1359 1354 - if (page_was_mapped) { 1360 + if (page_was_mapped) 1355 1361 remove_migration_ptes(hpage, 1356 - rc == MIGRATEPAGE_SUCCESS ? new_hpage : hpage, true); 1357 - i_mmap_unlock_write(mapping); 1358 - } 1362 + rc == MIGRATEPAGE_SUCCESS ? new_hpage : hpage, false); 1359 1363 1360 1364 unlock_put_anon: 1361 1365 unlock_page(new_hpage);
+4 -4
mm/percpu.c
··· 1315 1315 region_size = ALIGN(start_offset + map_size, lcm_align); 1316 1316 1317 1317 /* allocate chunk */ 1318 - alloc_size = sizeof(struct pcpu_chunk) + 1319 - BITS_TO_LONGS(region_size >> PAGE_SHIFT) * sizeof(unsigned long); 1318 + alloc_size = struct_size(chunk, populated, 1319 + BITS_TO_LONGS(region_size >> PAGE_SHIFT)); 1320 1320 chunk = memblock_alloc(alloc_size, SMP_CACHE_BYTES); 1321 1321 if (!chunk) 1322 1322 panic("%s: Failed to allocate %zu bytes\n", __func__, ··· 2521 2521 pcpu_unit_pages = ai->unit_size >> PAGE_SHIFT; 2522 2522 pcpu_unit_size = pcpu_unit_pages << PAGE_SHIFT; 2523 2523 pcpu_atom_size = ai->atom_size; 2524 - pcpu_chunk_struct_size = sizeof(struct pcpu_chunk) + 2525 - BITS_TO_LONGS(pcpu_unit_pages) * sizeof(unsigned long); 2524 + pcpu_chunk_struct_size = struct_size(chunk, populated, 2525 + BITS_TO_LONGS(pcpu_unit_pages)); 2526 2526 2527 2527 pcpu_stats_save_ai(ai); 2528 2528
+1 -4
mm/rmap.c
··· 1413 1413 /* 1414 1414 * If sharing is possible, start and end will be adjusted 1415 1415 * accordingly. 1416 - * 1417 - * If called for a huge page, caller must hold i_mmap_rwsem 1418 - * in write mode as it is possible to call huge_pmd_unshare. 1419 1416 */ 1420 1417 adjust_range_if_pmd_sharing_possible(vma, &range.start, 1421 1418 &range.end); ··· 1459 1462 subpage = page - page_to_pfn(page) + pte_pfn(*pvmw.pte); 1460 1463 address = pvmw.address; 1461 1464 1462 - if (PageHuge(page)) { 1465 + if (PageHuge(page) && !PageAnon(page)) { 1463 1466 /* 1464 1467 * To call huge_pmd_unshare, i_mmap_rwsem must be 1465 1468 * held in write mode. Caller needs to explicitly
+1 -1
mm/slub.c
··· 2852 2852 2853 2853 object = c->freelist; 2854 2854 page = c->page; 2855 - if (unlikely(!object || !node_match(page, node))) { 2855 + if (unlikely(!object || !page || !node_match(page, node))) { 2856 2856 object = __slab_alloc(s, gfpflags, node, addr, c); 2857 2857 } else { 2858 2858 void *next_object = get_freepointer_safe(s, object);
+3 -2
mm/vmscan.c
··· 1516 1516 nr_reclaimed = shrink_page_list(&clean_pages, zone->zone_pgdat, &sc, 1517 1517 TTU_IGNORE_ACCESS, &stat, true); 1518 1518 list_splice(&clean_pages, page_list); 1519 - mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, -nr_reclaimed); 1519 + mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, 1520 + -(long)nr_reclaimed); 1520 1521 /* 1521 1522 * Since lazyfree pages are isolated from file LRU from the beginning, 1522 1523 * they will rotate back to anonymous LRU in the end if it failed to ··· 1527 1526 mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_ANON, 1528 1527 stat.nr_lazyfree_fail); 1529 1528 mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, 1530 - -stat.nr_lazyfree_fail); 1529 + -(long)stat.nr_lazyfree_fail); 1531 1530 return nr_reclaimed; 1532 1531 } 1533 1532
+3 -1
security/selinux/ibpkey.c
··· 151 151 * is valid, it just won't be added to the cache. 152 152 */ 153 153 new = kzalloc(sizeof(*new), GFP_ATOMIC); 154 - if (!new) 154 + if (!new) { 155 + ret = -ENOMEM; 155 156 goto out; 157 + } 156 158 157 159 new->psec.subnet_prefix = subnet_prefix; 158 160 new->psec.pkey = pkey_num;
+30 -9
tools/testing/selftests/kvm/aarch64/get-reg-list.c
··· 42 42 #define for_each_reg(i) \ 43 43 for ((i) = 0; (i) < reg_list->n; ++(i)) 44 44 45 + #define for_each_reg_filtered(i) \ 46 + for_each_reg(i) \ 47 + if (!filter_reg(reg_list->reg[i])) 48 + 45 49 #define for_each_missing_reg(i) \ 46 50 for ((i) = 0; (i) < blessed_n; ++(i)) \ 47 51 if (!find_reg(reg_list->reg, reg_list->n, blessed_reg[i])) 48 52 49 53 #define for_each_new_reg(i) \ 50 - for ((i) = 0; (i) < reg_list->n; ++(i)) \ 54 + for_each_reg_filtered(i) \ 51 55 if (!find_reg(blessed_reg, blessed_n, reg_list->reg[i])) 52 56 53 57 ··· 60 56 static __u64 base_regs[], vregs[], sve_regs[], rejects_set[]; 61 57 static __u64 base_regs_n, vregs_n, sve_regs_n, rejects_set_n; 62 58 static __u64 *blessed_reg, blessed_n; 59 + 60 + static bool filter_reg(__u64 reg) 61 + { 62 + /* 63 + * DEMUX register presence depends on the host's CLIDR_EL1. 64 + * This means there's no set of them that we can bless. 65 + */ 66 + if ((reg & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_DEMUX) 67 + return true; 68 + 69 + return false; 70 + } 63 71 64 72 static bool find_reg(__u64 regs[], __u64 nr_regs, __u64 reg) 65 73 { ··· 341 325 struct kvm_vcpu_init init = { .target = -1, }; 342 326 int new_regs = 0, missing_regs = 0, i; 343 327 int failed_get = 0, failed_set = 0, failed_reject = 0; 344 - bool print_list = false, fixup_core_regs = false; 328 + bool print_list = false, print_filtered = false, fixup_core_regs = false; 345 329 struct kvm_vm *vm; 346 330 __u64 *vec_regs; 347 331 ··· 352 336 fixup_core_regs = true; 353 337 else if (strcmp(av[i], "--list") == 0) 354 338 print_list = true; 339 + else if (strcmp(av[i], "--list-filtered") == 0) 340 + print_filtered = true; 355 341 else 356 - fprintf(stderr, "Ignoring unknown option: %s\n", av[i]); 342 + TEST_FAIL("Unknown option: %s\n", av[i]); 357 343 } 358 344 359 345 vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR); ··· 368 350 if (fixup_core_regs) 369 351 core_reg_fixup(); 370 352 371 - if (print_list) { 353 + if (print_list || print_filtered) { 372 354 putchar('\n'); 373 - for_each_reg(i) 374 - print_reg(reg_list->reg[i]); 355 + for_each_reg(i) { 356 + __u64 id = reg_list->reg[i]; 357 + if ((print_list && !filter_reg(id)) || 358 + (print_filtered && filter_reg(id))) 359 + print_reg(id); 360 + } 375 361 putchar('\n'); 376 362 return 0; 377 363 } ··· 480 458 /* 481 459 * The current blessed list was primed with the output of kernel version 482 460 * v4.15 with --core-reg-fixup and then later updated with new registers. 461 + * 462 + * The blessed list is up to date with kernel version v5.10-rc5 483 463 */ 484 464 static __u64 base_regs[] = { 485 465 KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(regs.regs[0]), ··· 760 736 ARM64_SYS_REG(3, 4, 3, 0, 0), /* DACR32_EL2 */ 761 737 ARM64_SYS_REG(3, 4, 5, 0, 1), /* IFSR32_EL2 */ 762 738 ARM64_SYS_REG(3, 4, 5, 3, 0), /* FPEXC32_EL2 */ 763 - KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_DEMUX | KVM_REG_ARM_DEMUX_ID_CCSIDR | 0, 764 - KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_DEMUX | KVM_REG_ARM_DEMUX_ID_CCSIDR | 1, 765 - KVM_REG_ARM64 | KVM_REG_SIZE_U32 | KVM_REG_ARM_DEMUX | KVM_REG_ARM_DEMUX_ID_CCSIDR | 2, 766 739 }; 767 740 static __u64 base_regs_n = ARRAY_SIZE(base_regs); 768 741