android_kernel_xiaomi_sm8450/arch/x86/kvm
Paolo Bonzini e90518d10c KVM: x86/mmu: do compare-and-exchange of gPTE via the user address
commit 2a8859f373b0a86f0ece8ec8312607eacf12485d upstream.

FNAME(cmpxchg_gpte) is an inefficient mess.  It is at least decent if it
can go through get_user_pages_fast(), but if it cannot then it tries to
use memremap(); that is not just terribly slow, it is also wrong because
it assumes that the VM_PFNMAP VMA is contiguous.

The right way to do it would be to do the same thing as
hva_to_pfn_remapped() does since commit add6a0cd1c ("KVM: MMU: try to
fix up page faults before giving up", 2016-07-05), using follow_pte()
and fixup_user_fault() to determine the correct address to use for
memremap().  To do this, one could for example extract hva_to_pfn()
for use outside virt/kvm/kvm_main.c.  But really there is no reason to
do that either, because there is already a perfectly valid address to
do the cmpxchg() on, only it is a userspace address.  That means doing
user_access_begin()/user_access_end() and writing the code in assembly
to handle exceptions correctly.  Worse, the guest PTE can be 8-byte
even on i686 so there is the extra complication of using cmpxchg8b to
account for.  But at least it is an efficient mess.

(Thanks to Linus for suggesting improvement on the inline assembly).

Reported-by: Qiuhao Li <qiuhao@sysec.org>
Reported-by: Gaoning Pan <pgn@zju.edu.cn>
Reported-by: Yongkang Jia <kangel@zju.edu.cn>
Reported-by: syzbot+6cde2282daa792c49ab8@syzkaller.appspotmail.com
Debugged-by: Tadeusz Struk <tadeusz.struk@linaro.org>
Tested-by: Maxim Levitsky <mlevitsk@redhat.com>
Cc: stable@vger.kernel.org
Fixes: bd53cb35a3 ("X86/KVM: Handle PFNs outside of kernel reach when touching GPTEs")
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-04-08 14:40:44 +02:00
..
mmu KVM: x86/mmu: do compare-and-exchange of gPTE via the user address 2022-04-08 14:40:44 +02:00
svm KVM: SVM: fix panic on out-of-bounds guest IRQ 2022-04-08 14:40:39 +02:00
vmx KVM: x86/pmu: Refactoring find_arch_event() to pmc_perf_hw_id() 2022-02-23 12:01:04 +01:00
cpuid.c KVM: x86/pmu: Clear anythread deprecated bit when 0xa leaf is unsupported on the SVM 2021-07-28 14:35:34 +02:00
cpuid.h KVM: x86: reinstate vendor-agnostic check on SPEC_CTRL cpuid bits 2020-12-30 11:54:14 +01:00
debugfs.c KVM: let kvm_destroy_vm_debugfs clean up vCPU debugfs directories 2020-06-04 11:00:54 -04:00
emulate.c KVM: x86/emulator: Defer not-present segment check in __load_segment_descriptor() 2022-04-08 14:40:19 +02:00
hyperv.c KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated 2022-04-08 14:40:38 +02:00
hyperv.h x86/kvm/hyper-v: Add support for synthetic debugger interface 2020-06-01 04:26:11 -04:00
i8254.c kvm: i8254: remove redundant assignment to pointer s 2020-06-11 12:35:18 -04:00
i8254.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
i8259.c KVM: x86: Refactor picdev_write() to prevent Spectre-v1/L1TF attacks 2020-01-27 19:59:37 +01:00
ioapic.c Revert "x86/kvm: fix vcpu-id indexed array sizes" 2021-11-12 14:58:32 +01:00
ioapic.h Revert "x86/kvm: fix vcpu-id indexed array sizes" 2021-11-12 14:58:32 +01:00
irq_comm.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
irq.c KVM: x86: Fix split-irqchip vs interrupt injection window request 2020-11-27 09:27:28 -05:00
irq.h kvm/x86: Remove redundant function implementations 2020-05-27 13:11:10 -04:00
Kconfig x86/kvm: hide KVM options from menuconfig when KVM is not compiled 2020-10-21 17:36:30 -04:00
kvm_cache_regs.h KVM: x86: Let the guest own CR4.FSGSBASE 2020-10-21 17:48:50 -04:00
kvm_emulate.h KVM: x86: Move RDPID emulation intercept to its own enum 2021-05-19 10:13:16 +02:00
lapic.c KVM: x86: Fix emulation in writing cr8 2022-04-08 14:40:19 +02:00
lapic.h KVM: nVMX: Morph notification vector IRQ on nested VM-Enter to pending PI 2020-09-28 07:57:22 -04:00
Makefile kvm: x86/mmu: Init / Uninit the TDP MMU 2020-10-21 18:17:00 -04:00
mmu.h KVM: x86: fix shift out of bounds reported by UBSAN 2021-01-12 20:18:26 +01:00
mtrr.c KVM: x86: Protect MSR-based index computations in fixed_msr_to_seg_unit() from Spectre-v1/L1TF attacks 2020-01-27 19:59:39 +01:00
pmu.c KVM: x86/pmu: Use AMD64_RAW_EVENT_MASK for PERF_TYPE_RAW 2022-02-23 12:01:05 +01:00
pmu.h KVM: x86/pmu: Refactoring find_arch_event() to pmc_perf_hw_id() 2022-02-23 12:01:04 +01:00
trace.h KVM: x86: Ensure liveliness of nested VM-Enter fail tracepoint message 2021-06-16 12:01:46 +02:00
tss.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
x86.c KVM: x86: Forcibly leave nested virt when SMM state is toggled 2022-02-05 12:37:55 +01:00
x86.h KVM: x86: Factor out x86 instruction emulation with decoding 2021-08-26 08:35:34 -04:00