Pull kvm fixes from Paolo Bonzini: "RISC-V: - Fix compilation without RISCV_ISA_ZICBOM - Fix kvm_riscv_vcpu_timer_pending() for Sstc ARM: - Fix a bug preventing restoring an ITS containing mappings for very large and very sparse device topology - Work around a relocation handling error when compiling the nVHE object with profile optimisation - Fix for stage-2 invalidation holding the VM MMU lock for too long by limiting the walk to the largest block mapping size - Enable stack protection and branch profiling for VHE - Two selftest fixes x86: - add compat implementation for KVM_X86_SET_MSR_FILTER ioctl selftests: - synchronize includes between include/uapi and tools/include/uapi" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: tools: include: sync include/api/linux/kvm.h KVM: x86: Add compat handler for KVM_X86_SET_MSR_FILTER KVM: x86: Copy filter arg outside kvm_vm_ioctl_set_msr_filter() kvm: Add support for arch compat vm ioctls RISC-V: KVM: Fix kvm_riscv_vcpu_timer_pending() for Sstc RISC-V: Fix compilation without RISCV_ISA_ZICBOM KVM: arm64: vgic: Fix exit condition in scan_its_table() KVM: arm64: nvhe: Fix build with profile optimization KVM: selftests: Fix number of pages for memory slot in memslot_modification_stress_test KVM: arm64: selftests: Fix multiple versions of GIC creation KVM: arm64: Enable stack protection and branch profiling for VHE KVM: arm64: Limit stage2_apply_range() batch size to largest block KVM: arm64: Work out supported block level at compile time
Unified · Split
| @@ -13,6 +13,18 @@ · 12 unmodified lines | |||
| 13 | 13 | ||
| 14 | #define KVM_PGTABLE_MAX_LEVELS 4U | 14 | #define KVM_PGTABLE_MAX_LEVELS 4U |
| 15 | 15 | ||
| 16 | /* | ||
| 17 | * The largest supported block sizes for KVM (no 52-bit PA support): | ||
| 18 | * - 4K (level 1): 1GB | ||
| 19 | * - 16K (level 2): 32MB | ||
| 20 | * - 64K (level 2): 512MB | ||
| 21 | */ | ||
| 22 | #ifdef CONFIG_ARM64_4K_PAGES | ||
| 23 | #define KVM_PGTABLE_MIN_BLOCK_LEVEL 1U | ||
| 24 | #else | ||
| 25 | #define KVM_PGTABLE_MIN_BLOCK_LEVEL 2U | ||
| 26 | #endif | ||
| 27 | |||
| 16 | static inline u64 kvm_get_parange(u64 mmfr0) | 28 | static inline u64 kvm_get_parange(u64 mmfr0) |
| 17 | { | 29 | { |
| 18 | u64 parange = cpuid_feature_extract_unsigned_field(mmfr0, | 30 | u64 parange = cpuid_feature_extract_unsigned_field(mmfr0, |
| @@ -58,11 +70,7 @@ static inline u64 kvm_granule_size(u32 level) · 39 unmodified lines | |||
| 58 | 70 | ||
| 59 | static inline bool kvm_level_supports_block_mapping(u32 level) | 71 | static inline bool kvm_level_supports_block_mapping(u32 level) |
| 60 | { | 72 | { |
| 61 | /* | 73 | return level >= KVM_PGTABLE_MIN_BLOCK_LEVEL; |
| 62 | * Reject invalid block mappings and don't bother with 4TB mappings for | ||
| 63 | * 52-bit PAs. | ||
| 64 | */ | ||
| 65 | return !(level == 0 || (PAGE_SIZE != SZ_4K && level == 1)); | ||
| 66 | } | 74 | } |
| 67 | 75 | ||
| 68 | /** | 76 | /** |
| @@ -10,13 +10,6 @@ · 9 unmodified lines | |||
| 10 | 10 | ||
| 11 | #include <linux/pgtable.h> | 11 | #include <linux/pgtable.h> |
| 12 | 12 | ||
| 13 | /* | ||
| 14 | * PGDIR_SHIFT determines the size a top-level page table entry can map | ||
| 15 | * and depends on the number of levels in the page table. Compute the | ||
| 16 | * PGDIR_SHIFT for a given number of levels. | ||
| 17 | */ | ||
| 18 | #define pt_levels_pgdir_shift(lvls) ARM64_HW_PGTABLE_LEVEL_SHIFT(4 - (lvls)) | ||
| 19 | |||
| 20 | /* | 13 | /* |
| 21 | * The hardware supports concatenation of up to 16 tables at stage2 entry | 14 | * The hardware supports concatenation of up to 16 tables at stage2 entry |
| 22 | * level and we use the feature whenever possible, which means we resolve 4 | 15 | * level and we use the feature whenever possible, which means we resolve 4 |
| @@ -30,11 +23,6 @@ · 7 unmodified lines | |||
| 30 | #define stage2_pgtable_levels(ipa) ARM64_HW_PGTABLE_LEVELS((ipa) - 4) | 23 | #define stage2_pgtable_levels(ipa) ARM64_HW_PGTABLE_LEVELS((ipa) - 4) |
| 31 | #define kvm_stage2_levels(kvm) VTCR_EL2_LVLS(kvm->arch.vtcr) | 24 | #define kvm_stage2_levels(kvm) VTCR_EL2_LVLS(kvm->arch.vtcr) |
| 32 | 25 | ||
| 33 | /* stage2_pgdir_shift() is the size mapped by top-level stage2 entry for the VM */ | ||
| 34 | #define stage2_pgdir_shift(kvm) pt_levels_pgdir_shift(kvm_stage2_levels(kvm)) | ||
| 35 | #define stage2_pgdir_size(kvm) (1ULL << stage2_pgdir_shift(kvm)) | ||
| 36 | #define stage2_pgdir_mask(kvm) ~(stage2_pgdir_size(kvm) - 1) | ||
| 37 | |||
| 38 | /* | 26 | /* |
| 39 | * kvm_mmmu_cache_min_pages() is the number of pages required to install | 27 | * kvm_mmmu_cache_min_pages() is the number of pages required to install |
| 40 | * a stage-2 translation. We pre-allocate the entry level page table at | 28 | * a stage-2 translation. We pre-allocate the entry level page table at |
| @@ -42,12 +30,4 @@ · 1 unmodified line | |||
| 42 | */ | 30 | */ |
| 43 | #define kvm_mmu_cache_min_pages(kvm) (kvm_stage2_levels(kvm) - 1) | 31 | #define kvm_mmu_cache_min_pages(kvm) (kvm_stage2_levels(kvm) - 1) |
| 44 | 32 | ||
| 45 | static inline phys_addr_t | ||
| 46 | stage2_pgd_addr_end(struct kvm *kvm, phys_addr_t addr, phys_addr_t end) | ||
| 47 | { | ||
| 48 | phys_addr_t boundary = (addr + stage2_pgdir_size(kvm)) & stage2_pgdir_mask(kvm); | ||
| 49 | |||
| 50 | return (boundary - 1 < end - 1) ? boundary : end; | ||
| 51 | } | ||
| 52 | |||
| 53 | #endif /* __ARM64_S2_PGTABLE_H_ */ | 33 | #endif /* __ARM64_S2_PGTABLE_H_ */ |
| @@ -5,9 +5,6 @@ · 4 unmodified lines | |||
| 5 | 5 | ||
| 6 | incdir := $(srctree)/$(src)/include | 6 | incdir := $(srctree)/$(src)/include |
| 7 | subdir-asflags-y := -I$(incdir) | 7 | subdir-asflags-y := -I$(incdir) |
| 8 | subdir-ccflags-y := -I$(incdir) \ | 8 | subdir-ccflags-y := -I$(incdir) |
| 9 | -fno-stack-protector \ | ||
| 10 | -DDISABLE_BRANCH_PROFILING \ | ||
| 11 | $(DISABLE_STACKLEAK_PLUGIN) | ||
| 12 | 9 | ||
| 13 | obj-$(CONFIG_KVM) += vhe/ nvhe/ pgtable.o | 10 | obj-$(CONFIG_KVM) += vhe/ nvhe/ pgtable.o |
| @@ -10,6 +10,9 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS · 9 unmodified lines | |||
| 10 | # will explode instantly (Words of Marc Zyngier). So introduce a generic flag | 10 | # will explode instantly (Words of Marc Zyngier). So introduce a generic flag |
| 11 | # __DISABLE_TRACE_MMIO__ to disable MMIO tracing for nVHE KVM. | 11 | # __DISABLE_TRACE_MMIO__ to disable MMIO tracing for nVHE KVM. |
| 12 | ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__ | 12 | ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__ |
| 13 | ccflags-y += -fno-stack-protector \ | ||
| 14 | -DDISABLE_BRANCH_PROFILING \ | ||
| 15 | $(DISABLE_STACKLEAK_PLUGIN) | ||
| 13 | 16 | ||
| 14 | hostprogs := gen-hyprel | 17 | hostprogs := gen-hyprel |
| 15 | HOST_EXTRACFLAGS += -I$(objtree)/include | 18 | HOST_EXTRACFLAGS += -I$(objtree)/include |
| @@ -89,6 +92,10 @@ quiet_cmd_hypcopy = HYPCOPY $@ · 73 unmodified lines | |||
| 89 | # Remove ftrace, Shadow Call Stack, and CFI CFLAGS. | 92 | # Remove ftrace, Shadow Call Stack, and CFI CFLAGS. |
| 90 | # This is equivalent to the 'notrace', '__noscs', and '__nocfi' annotations. | 93 | # This is equivalent to the 'notrace', '__noscs', and '__nocfi' annotations. |
| 91 | KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_CFI), $(KBUILD_CFLAGS)) | 94 | KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_CFI), $(KBUILD_CFLAGS)) |
| 95 | # Starting from 13.0.0 llvm emits SHT_REL section '.llvm.call-graph-profile' | ||
| 96 | # when profile optimization is applied. gen-hyprel does not support SHT_REL and | ||
| 97 | # causes a build failure. Remove profile optimization flags. | ||
| 98 | KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%, $(KBUILD_CFLAGS)) | ||
| 92 | 99 | ||
| 93 | # KVM nVHE code is run at a different exception code with a different map, so | 100 | # KVM nVHE code is run at a different exception code with a different map, so |
| 94 | # compiler instrumentation that inserts callbacks or checks into the code may | 101 | # compiler instrumentation that inserts callbacks or checks into the code may |
| @@ -31,6 +31,13 @@ static phys_addr_t hyp_idmap_vector; · 30 unmodified lines | |||
| 31 | 31 | ||
| 32 | static unsigned long io_map_base; | 32 | static unsigned long io_map_base; |
| 33 | 33 | ||
| 34 | static phys_addr_t stage2_range_addr_end(phys_addr_t addr, phys_addr_t end) | ||
| 35 | { | ||
| 36 | phys_addr_t size = kvm_granule_size(KVM_PGTABLE_MIN_BLOCK_LEVEL); | ||
| 37 | phys_addr_t boundary = ALIGN_DOWN(addr + size, size); | ||
| 38 | |||
| 39 | return (boundary - 1 < end - 1) ? boundary : end; | ||
| 40 | } | ||
| 34 | 41 | ||
| 35 | /* | 42 | /* |
| 36 | * Release kvm_mmu_lock periodically if the memory region is large. Otherwise, | 43 | * Release kvm_mmu_lock periodically if the memory region is large. Otherwise, |
| @@ -52,7 +59,7 @@ static int stage2_apply_range(struct kvm *kvm, phys_addr_t addr, · 15 unmodified lines | |||
| 52 | if (!pgt) | 59 | if (!pgt) |
| 53 | return -EINVAL; | 60 | return -EINVAL; |
| 54 | 61 | ||
| 55 | next = stage2_pgd_addr_end(kvm, addr, end); | 62 | next = stage2_range_addr_end(addr, end); |
| 56 | ret = fn(pgt, addr, next - addr); | 63 | ret = fn(pgt, addr, next - addr); |
| 57 | if (ret) | 64 | if (ret) |
| 58 | break; | 65 | break; |
| @@ -2149,7 +2149,7 @@ static int scan_its_table(struct vgic_its *its, gpa_t base, int size, u32 esz, · 2148 unmodified lines | |||
| 2149 | 2149 | ||
| 2150 | memset(entry, 0, esz); | 2150 | memset(entry, 0, esz); |
| 2151 | 2151 | ||
| 2152 | while (len > 0) { | 2152 | while (true) { |
| 2153 | int next_offset; | 2153 | int next_offset; |
| 2154 | size_t byte_offset; | 2154 | size_t byte_offset; |
| 2155 | 2155 | ||
| @@ -2162,6 +2162,9 @@ static int scan_its_table(struct vgic_its *its, gpa_t base, int size, u32 esz, · 6 unmodified lines | |||
| 2162 | return next_offset; | 2162 | return next_offset; |
| 2163 | 2163 | ||
| 2164 | byte_offset = next_offset * esz; | 2164 | byte_offset = next_offset * esz; |
| 2165 | if (byte_offset >= len) | ||
| 2166 | break; | ||
| 2167 | |||
| 2165 | id += next_offset; | 2168 | id += next_offset; |
| 2166 | gpa += byte_offset; | 2169 | gpa += byte_offset; |
| 2167 | len -= byte_offset; | 2170 | len -= byte_offset; |
| @@ -42,16 +42,8 @@ void flush_icache_mm(struct mm_struct *mm, bool local); · 41 unmodified lines | |||
| 42 | 42 | ||
| 43 | #endif /* CONFIG_SMP */ | 43 | #endif /* CONFIG_SMP */ |
| 44 | 44 | ||
| 45 | /* | ||
| 46 | * The T-Head CMO errata internally probe the CBOM block size, but otherwise | ||
| 47 | * don't depend on Zicbom. | ||
| 48 | */ | ||
| 49 | extern unsigned int riscv_cbom_block_size; | 45 | extern unsigned int riscv_cbom_block_size; |
| 50 | #ifdef CONFIG_RISCV_ISA_ZICBOM | ||
| 51 | void riscv_init_cbom_blocksize(void); | 46 | void riscv_init_cbom_blocksize(void); |
| 52 | #else | ||
| 53 | static inline void riscv_init_cbom_blocksize(void) { } | ||
| 54 | #endif | ||
| 55 | 47 | ||
| 56 | #ifdef CONFIG_RISCV_DMA_NONCOHERENT | 48 | #ifdef CONFIG_RISCV_DMA_NONCOHERENT |
| 57 | void riscv_noncoherent_supported(void); | 49 | void riscv_noncoherent_supported(void); |
| @@ -45,6 +45,7 @@ int kvm_riscv_vcpu_timer_deinit(struct kvm_vcpu *vcpu); · 44 unmodified lines | |||
| 45 | int kvm_riscv_vcpu_timer_reset(struct kvm_vcpu *vcpu); | 45 | int kvm_riscv_vcpu_timer_reset(struct kvm_vcpu *vcpu); |
| 46 | void kvm_riscv_vcpu_timer_restore(struct kvm_vcpu *vcpu); | 46 | void kvm_riscv_vcpu_timer_restore(struct kvm_vcpu *vcpu); |
| 47 | void kvm_riscv_guest_timer_init(struct kvm *kvm); | 47 | void kvm_riscv_guest_timer_init(struct kvm *kvm); |
| 48 | void kvm_riscv_vcpu_timer_sync(struct kvm_vcpu *vcpu); | ||
| 48 | void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu); | 49 | void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu); |
| 49 | bool kvm_riscv_vcpu_timer_pending(struct kvm_vcpu *vcpu); | 50 | bool kvm_riscv_vcpu_timer_pending(struct kvm_vcpu *vcpu); |
| 50 | 51 | ||
| @@ -708,6 +708,9 @@ void kvm_riscv_vcpu_sync_interrupts(struct kvm_vcpu *vcpu) · 707 unmodified lines | |||
| 708 | clear_bit(IRQ_VS_SOFT, &v->irqs_pending); | 708 | clear_bit(IRQ_VS_SOFT, &v->irqs_pending); |
| 709 | } | 709 | } |
| 710 | } | 710 | } |
| 711 | |||
| 712 | /* Sync-up timer CSRs */ | ||
| 713 | kvm_riscv_vcpu_timer_sync(vcpu); | ||
| 711 | } | 714 | } |
| 712 | 715 | ||
| 713 | int kvm_riscv_vcpu_set_interrupt(struct kvm_vcpu *vcpu, unsigned int irq) | 716 | int kvm_riscv_vcpu_set_interrupt(struct kvm_vcpu *vcpu, unsigned int irq) |
| @@ -320,20 +320,33 @@ void kvm_riscv_vcpu_timer_restore(struct kvm_vcpu *vcpu) · 319 unmodified lines | |||
| 320 | kvm_riscv_vcpu_timer_unblocking(vcpu); | 320 | kvm_riscv_vcpu_timer_unblocking(vcpu); |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu) | 323 | void kvm_riscv_vcpu_timer_sync(struct kvm_vcpu *vcpu) |
| 324 | { | 324 | { |
| 325 | struct kvm_vcpu_timer *t = &vcpu->arch.timer; | 325 | struct kvm_vcpu_timer *t = &vcpu->arch.timer; |
| 326 | 326 | ||
| 327 | if (!t->sstc_enabled) | 327 | if (!t->sstc_enabled) |
| 328 | return; | 328 | return; |
| 329 | 329 | ||
| 330 | t = &vcpu->arch.timer; | ||
| 331 | #if defined(CONFIG_32BIT) | 330 | #if defined(CONFIG_32BIT) |
| 332 | t->next_cycles = csr_read(CSR_VSTIMECMP); | 331 | t->next_cycles = csr_read(CSR_VSTIMECMP); |
| 333 | t->next_cycles |= (u64)csr_read(CSR_VSTIMECMPH) << 32; | 332 | t->next_cycles |= (u64)csr_read(CSR_VSTIMECMPH) << 32; |
| 334 | #else | 333 | #else |
| 335 | t->next_cycles = csr_read(CSR_VSTIMECMP); | 334 | t->next_cycles = csr_read(CSR_VSTIMECMP); |
| 336 | #endif | 335 | #endif |
| 336 | } | ||
| 337 | |||
| 338 | void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu) | ||
| 339 | { | ||
| 340 | struct kvm_vcpu_timer *t = &vcpu->arch.timer; | ||
| 341 | |||
| 342 | if (!t->sstc_enabled) | ||
| 343 | return; | ||
| 344 | |||
| 345 | /* | ||
| 346 | * The vstimecmp CSRs are saved by kvm_riscv_vcpu_timer_sync() | ||
| 347 | * upon every VM exit so no need to save here. | ||
| 348 | */ | ||
| 349 | |||
| 337 | /* timer should be enabled for the remaining operations */ | 350 | /* timer should be enabled for the remaining operations */ |
| 338 | if (unlikely(!t->init_done)) | 351 | if (unlikely(!t->init_done)) |
| 339 | return; | 352 | return; |
| @@ -3,6 +3,7 @@ · 2 unmodified lines | |||
| 3 | * Copyright (C) 2017 SiFive | 3 | * Copyright (C) 2017 SiFive |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #include <linux/of.h> | ||
| 6 | #include <asm/cacheflush.h> | 7 | #include <asm/cacheflush.h> |
| 7 | 8 | ||
| 8 | #ifdef CONFIG_SMP | 9 | #ifdef CONFIG_SMP |
| @@ -86,3 +87,40 @@ void flush_icache_pte(pte_t pte) · 77 unmodified lines | |||
| 86 | flush_icache_all(); | 87 | flush_icache_all(); |
| 87 | } | 88 | } |
| 88 | #endif /* CONFIG_MMU */ | 89 | #endif /* CONFIG_MMU */ |
| 90 | |||
| 91 | unsigned int riscv_cbom_block_size; | ||
| 92 | EXPORT_SYMBOL_GPL(riscv_cbom_block_size); | ||
| 93 | |||
| 94 | void riscv_init_cbom_blocksize(void) | ||
| 95 | { | ||
| 96 | struct device_node *node; | ||
| 97 | unsigned long cbom_hartid; | ||
| 98 | u32 val, probed_block_size; | ||
| 99 | int ret; | ||
| 100 | |||
| 101 | probed_block_size = 0; | ||
| 102 | for_each_of_cpu_node(node) { | ||
| 103 | unsigned long hartid; | ||
| 104 | |||
| 105 | ret = riscv_of_processor_hartid(node, &hartid); | ||
| 106 | if (ret) | ||
| 107 | continue; | ||
| 108 | |||
| 109 | /* set block-size for cbom extension if available */ | ||
| 110 | ret = of_property_read_u32(node, "riscv,cbom-block-size", &val); | ||
| 111 | if (ret) | ||
| 112 | continue; | ||
| 113 | |||
| 114 | if (!probed_block_size) { | ||
| 115 | probed_block_size = val; | ||
| 116 | cbom_hartid = hartid; | ||
| 117 | } else { | ||
| 118 | if (probed_block_size != val) | ||
| 119 | pr_warn("cbom-block-size mismatched between harts %lu and %lu\n", | ||
| 120 | cbom_hartid, hartid); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | if (probed_block_size) | ||
| 125 | riscv_cbom_block_size = probed_block_size; | ||
| 126 | } | ||
| @@ -8,13 +8,8 @@ · 7 unmodified lines | |||
| 8 | #include <linux/dma-direct.h> | 8 | #include <linux/dma-direct.h> |
| 9 | #include <linux/dma-map-ops.h> | 9 | #include <linux/dma-map-ops.h> |
| 10 | #include <linux/mm.h> | 10 | #include <linux/mm.h> |
| 11 | #include <linux/of.h> | ||
| 12 | #include <linux/of_device.h> | ||
| 13 | #include <asm/cacheflush.h> | 11 | #include <asm/cacheflush.h> |
| 14 | 12 | ||
| 15 | unsigned int riscv_cbom_block_size; | ||
| 16 | EXPORT_SYMBOL_GPL(riscv_cbom_block_size); | ||
| 17 | |||
| 18 | static bool noncoherent_supported; | 13 | static bool noncoherent_supported; |
| 19 | 14 | ||
| 20 | void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, | 15 | void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, |
| @@ -77,42 +72,6 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, · 56 unmodified lines | |||
| 77 | dev->dma_coherent = coherent; | 72 | dev->dma_coherent = coherent; |
| 78 | } | 73 | } |
| 79 | 74 | ||
| 80 | #ifdef CONFIG_RISCV_ISA_ZICBOM | ||
| 81 | void riscv_init_cbom_blocksize(void) | ||
| 82 | { | ||
| 83 | struct device_node *node; | ||
| 84 | unsigned long cbom_hartid; | ||
| 85 | u32 val, probed_block_size; | ||
| 86 | int ret; | ||
| 87 | |||
| 88 | probed_block_size = 0; | ||
| 89 | for_each_of_cpu_node(node) { | ||
| 90 | unsigned long hartid; | ||
| 91 | |||
| 92 | ret = riscv_of_processor_hartid(node, &hartid); | ||
| 93 | if (ret) | ||
| 94 | continue; | ||
| 95 | |||
| 96 | /* set block-size for cbom extension if available */ | ||
| 97 | ret = of_property_read_u32(node, "riscv,cbom-block-size", &val); | ||
| 98 | if (ret) | ||
| 99 | continue; | ||
| 100 | |||
| 101 | if (!probed_block_size) { | ||
| 102 | probed_block_size = val; | ||
| 103 | cbom_hartid = hartid; | ||
| 104 | } else { | ||
| 105 | if (probed_block_size != val) | ||
| 106 | pr_warn("cbom-block-size mismatched between harts %lu and %lu\n", | ||
| 107 | cbom_hartid, hartid); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | if (probed_block_size) | ||
| 112 | riscv_cbom_block_size = probed_block_size; | ||
| 113 | } | ||
| 114 | #endif | ||
| 115 | |||
| 116 | void riscv_noncoherent_supported(void) | 75 | void riscv_noncoherent_supported(void) |
| 117 | { | 76 | { |
| 118 | WARN(!riscv_cbom_block_size, | 77 | WARN(!riscv_cbom_block_size, |
| @@ -6442,26 +6442,22 @@ static int kvm_add_msr_filter(struct kvm_x86_msr_filter *msr_filter, · 6441 unmodified lines | |||
| 6442 | return 0; | 6442 | return 0; |
| 6443 | } | 6443 | } |
| 6444 | 6444 | ||
| 6445 | static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, void __user *argp) | 6445 | static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, |
| 6446 | struct kvm_msr_filter *filter) | ||
| 6446 | { | 6447 | { |
| 6447 | struct kvm_msr_filter __user *user_msr_filter = argp; | ||
| 6448 | struct kvm_x86_msr_filter *new_filter, *old_filter; | 6448 | struct kvm_x86_msr_filter *new_filter, *old_filter; |
| 6449 | struct kvm_msr_filter filter; | ||
| 6450 | bool default_allow; | 6449 | bool default_allow; |
| 6451 | bool empty = true; | 6450 | bool empty = true; |
| 6452 | int r = 0; | 6451 | int r = 0; |
| 6453 | u32 i; | 6452 | u32 i; |
| 6454 | 6453 | ||
| 6455 | if (copy_from_user(&filter, user_msr_filter, sizeof(filter))) | 6454 | if (filter->flags & ~KVM_MSR_FILTER_DEFAULT_DENY) |
| 6456 | return -EFAULT; | ||
| 6457 | |||
| 6458 | if (filter.flags & ~KVM_MSR_FILTER_DEFAULT_DENY) | ||
| 6459 | return -EINVAL; | 6455 | return -EINVAL; |
| 6460 | 6456 | ||
| 6461 | for (i = 0; i < ARRAY_SIZE(filter.ranges); i++) | 6457 | for (i = 0; i < ARRAY_SIZE(filter->ranges); i++) |
| 6462 | empty &= !filter.ranges[i].nmsrs; | 6458 | empty &= !filter->ranges[i].nmsrs; |
| 6463 | 6459 | ||
| 6464 | default_allow = !(filter.flags & KVM_MSR_FILTER_DEFAULT_DENY); | 6460 | default_allow = !(filter->flags & KVM_MSR_FILTER_DEFAULT_DENY); |
| 6465 | if (empty && !default_allow) | 6461 | if (empty && !default_allow) |
| 6466 | return -EINVAL; | 6462 | return -EINVAL; |
| 6467 | 6463 | ||
| @@ -6469,8 +6465,8 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, void __user *argp) · 1 unmodified line | |||
| 6469 | if (!new_filter) | 6465 | if (!new_filter) |
| 6470 | return -ENOMEM; | 6466 | return -ENOMEM; |
| 6471 | 6467 | ||
| 6472 | for (i = 0; i < ARRAY_SIZE(filter.ranges); i++) { | 6468 | for (i = 0; i < ARRAY_SIZE(filter->ranges); i++) { |
| 6473 | r = kvm_add_msr_filter(new_filter, &filter.ranges[i]); | 6469 | r = kvm_add_msr_filter(new_filter, &filter->ranges[i]); |
| 6474 | if (r) { | 6470 | if (r) { |
| 6475 | kvm_free_msr_filter(new_filter); | 6471 | kvm_free_msr_filter(new_filter); |
| 6476 | return r; | 6472 | return r; |
| @@ -6493,6 +6489,62 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, void __user *argp) · 16 unmodified lines | |||
| 6493 | return 0; | 6489 | return 0; |
| 6494 | } | 6490 | } |
| 6495 | 6491 | ||
| 6492 | #ifdef CONFIG_KVM_COMPAT | ||
| 6493 | /* for KVM_X86_SET_MSR_FILTER */ | ||
| 6494 | struct kvm_msr_filter_range_compat { | ||
| 6495 | __u32 flags; | ||
| 6496 | __u32 nmsrs; | ||
| 6497 | __u32 base; | ||
| 6498 | __u32 bitmap; | ||
| 6499 | }; | ||
| 6500 | |||
| 6501 | struct kvm_msr_filter_compat { | ||
| 6502 | __u32 flags; | ||
| 6503 | struct kvm_msr_filter_range_compat ranges[KVM_MSR_FILTER_MAX_RANGES]; | ||
| 6504 | }; | ||
| 6505 | |||
| 6506 | #define KVM_X86_SET_MSR_FILTER_COMPAT _IOW(KVMIO, 0xc6, struct kvm_msr_filter_compat) | ||
| 6507 | |||
| 6508 | long kvm_arch_vm_compat_ioctl(struct file *filp, unsigned int ioctl, | ||
| 6509 | unsigned long arg) | ||
| 6510 | { | ||
| 6511 | void __user *argp = (void __user *)arg; | ||
| 6512 | struct kvm *kvm = filp->private_data; | ||
| 6513 | long r = -ENOTTY; | ||
| 6514 | |||
| 6515 | switch (ioctl) { | ||
| 6516 | case KVM_X86_SET_MSR_FILTER_COMPAT: { | ||
| 6517 | struct kvm_msr_filter __user *user_msr_filter = argp; | ||
| 6518 | struct kvm_msr_filter_compat filter_compat; | ||
| 6519 | struct kvm_msr_filter filter; | ||
| 6520 | int i; | ||
| 6521 | |||
| 6522 | if (copy_from_user(&filter_compat, user_msr_filter, | ||
| 6523 | sizeof(filter_compat))) | ||
| 6524 | return -EFAULT; | ||
| 6525 | |||
| 6526 | filter.flags = filter_compat.flags; | ||
| 6527 | for (i = 0; i < ARRAY_SIZE(filter.ranges); i++) { | ||
| 6528 | struct kvm_msr_filter_range_compat *cr; | ||
| 6529 | |||
| 6530 | cr = &filter_compat.ranges[i]; | ||
| 6531 | filter.ranges[i] = (struct kvm_msr_filter_range) { | ||
| 6532 | .flags = cr->flags, | ||
| 6533 | .nmsrs = cr->nmsrs, | ||
| 6534 | .base = cr->base, | ||
| 6535 | .bitmap = (__u8 *)(ulong)cr->bitmap, | ||
| 6536 | }; | ||
| 6537 | } | ||
| 6538 | |||
| 6539 | r = kvm_vm_ioctl_set_msr_filter(kvm, &filter); | ||
| 6540 | break; | ||
| 6541 | } | ||
| 6542 | } | ||
| 6543 | |||
| 6544 | return r; | ||
| 6545 | } | ||
| 6546 | #endif | ||
| 6547 | |||
| 6496 | #ifdef CONFIG_HAVE_KVM_PM_NOTIFIER | 6548 | #ifdef CONFIG_HAVE_KVM_PM_NOTIFIER |
| 6497 | static int kvm_arch_suspend_notifier(struct kvm *kvm) | 6549 | static int kvm_arch_suspend_notifier(struct kvm *kvm) |
| 6498 | { | 6550 | { |
| @@ -6915,9 +6967,16 @@ set_pit2_out: · 416 unmodified lines | |||
| 6915 | case KVM_SET_PMU_EVENT_FILTER: | 6967 | case KVM_SET_PMU_EVENT_FILTER: |
| 6916 | r = kvm_vm_ioctl_set_pmu_event_filter(kvm, argp); | 6968 | r = kvm_vm_ioctl_set_pmu_event_filter(kvm, argp); |
| 6917 | break; | 6969 | break; |
| 6918 | case KVM_X86_SET_MSR_FILTER: | 6970 | case KVM_X86_SET_MSR_FILTER: { |
| 6919 | r = kvm_vm_ioctl_set_msr_filter(kvm, argp); | 6971 | struct kvm_msr_filter __user *user_msr_filter = argp; |
| 6972 | struct kvm_msr_filter filter; | ||
| 6973 | |||
| 6974 | if (copy_from_user(&filter, user_msr_filter, sizeof(filter))) | ||
| 6975 | return -EFAULT; | ||
| 6976 | |||
| 6977 | r = kvm_vm_ioctl_set_msr_filter(kvm, &filter); | ||
| 6920 | break; | 6978 | break; |
| 6979 | } | ||
| 6921 | default: | 6980 | default: |
| 6922 | r = -ENOTTY; | 6981 | r = -ENOTTY; |
| 6923 | } | 6982 | } |
| @@ -1390,6 +1390,8 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, · 1389 unmodified lines | |||
| 1390 | struct kvm_enable_cap *cap); | 1390 | struct kvm_enable_cap *cap); |
| 1391 | long kvm_arch_vm_ioctl(struct file *filp, | 1391 | long kvm_arch_vm_ioctl(struct file *filp, |
| 1392 | unsigned int ioctl, unsigned long arg); | 1392 | unsigned int ioctl, unsigned long arg); |
| 1393 | long kvm_arch_vm_compat_ioctl(struct file *filp, unsigned int ioctl, | ||
| 1394 | unsigned long arg); | ||
| 1393 | 1395 | ||
| 1394 | int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu); | 1396 | int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu); |
| 1395 | int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu); | 1397 | int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu); |
| @@ -1177,6 +1177,7 @@ struct kvm_ppc_resize_hpt { · 1176 unmodified lines | |||
| 1177 | #define KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 220 | 1177 | #define KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 220 |
| 1178 | #define KVM_CAP_S390_ZPCI_OP 221 | 1178 | #define KVM_CAP_S390_ZPCI_OP 221 |
| 1179 | #define KVM_CAP_S390_CPU_TOPOLOGY 222 | 1179 | #define KVM_CAP_S390_CPU_TOPOLOGY 222 |
| 1180 | #define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223 | ||
| 1180 | 1181 | ||
| 1181 | #ifdef KVM_CAP_IRQ_ROUTING | 1182 | #ifdef KVM_CAP_IRQ_ROUTING |
| 1182 | 1183 | ||
| @@ -662,8 +662,8 @@ int test_kvm_device(uint32_t gic_dev_type) · 661 unmodified lines | |||
| 662 | : KVM_DEV_TYPE_ARM_VGIC_V2; | 662 | : KVM_DEV_TYPE_ARM_VGIC_V2; |
| 663 | 663 | ||
| 664 | if (!__kvm_test_create_device(v.vm, other)) { | 664 | if (!__kvm_test_create_device(v.vm, other)) { |
| 665 | ret = __kvm_test_create_device(v.vm, other); | 665 | ret = __kvm_create_device(v.vm, other); |
| 666 | TEST_ASSERT(ret && (errno == EINVAL || errno == EEXIST), | 666 | TEST_ASSERT(ret < 0 && (errno == EINVAL || errno == EEXIST), |
| 667 | "create GIC device while other version exists"); | 667 | "create GIC device while other version exists"); |
| 668 | } | 668 | } |
| 669 | 669 | ||
| @@ -67,7 +67,7 @@ struct memslot_antagonist_args { · 66 unmodified lines | |||
| 67 | static void add_remove_memslot(struct kvm_vm *vm, useconds_t delay, | 67 | static void add_remove_memslot(struct kvm_vm *vm, useconds_t delay, |
| 68 | uint64_t nr_modifications) | 68 | uint64_t nr_modifications) |
| 69 | { | 69 | { |
| 70 | const uint64_t pages = 1; | 70 | uint64_t pages = max_t(int, vm->page_size, getpagesize()) / vm->page_size; |
| 71 | uint64_t gpa; | 71 | uint64_t gpa; |
| 72 | int i; | 72 | int i; |
| 73 | 73 | ||
| @@ -4839,6 +4839,12 @@ struct compat_kvm_clear_dirty_log { · 4838 unmodified lines | |||
| 4839 | }; | 4839 | }; |
| 4840 | }; | 4840 | }; |
| 4841 | 4841 | ||
| 4842 | long __weak kvm_arch_vm_compat_ioctl(struct file *filp, unsigned int ioctl, | ||
| 4843 | unsigned long arg) | ||
| 4844 | { | ||
| 4845 | return -ENOTTY; | ||
| 4846 | } | ||
| 4847 | |||
| 4842 | static long kvm_vm_compat_ioctl(struct file *filp, | 4848 | static long kvm_vm_compat_ioctl(struct file *filp, |
| 4843 | unsigned int ioctl, unsigned long arg) | 4849 | unsigned int ioctl, unsigned long arg) |
| 4844 | { | 4850 | { |
| @@ -4847,6 +4853,11 @@ static long kvm_vm_compat_ioctl(struct file *filp, · 2 unmodified lines | |||
| 4847 | 4853 | ||
| 4848 | if (kvm->mm != current->mm || kvm->vm_dead) | 4854 | if (kvm->mm != current->mm || kvm->vm_dead) |
| 4849 | return -EIO; | 4855 | return -EIO; |
| 4856 | |||
| 4857 | r = kvm_arch_vm_compat_ioctl(filp, ioctl, arg); | ||
| 4858 | if (r != -ENOTTY) | ||
| 4859 | return r; | ||
| 4860 | |||
| 4850 | switch (ioctl) { | 4861 | switch (ioctl) { |
| 4851 | #ifdef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT | 4862 | #ifdef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT |
| 4852 | case KVM_CLEAR_DIRTY_LOG: { | 4863 | case KVM_CLEAR_DIRTY_LOG: { |