13 Jun, 2020

1 commit

  • Pull more KVM updates from Paolo Bonzini:
    "The guest side of the asynchronous page fault work has been delayed to
    5.9 in order to sync with Thomas's interrupt entry rework, but here's
    the rest of the KVM updates for this merge window.

    MIPS:
    - Loongson port

    PPC:
    - Fixes

    ARM:
    - Fixes

    x86:
    - KVM_SET_USER_MEMORY_REGION optimizations
    - Fixes
    - Selftest fixes"

    * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (62 commits)
    KVM: x86: do not pass poisoned hva to __kvm_set_memory_region
    KVM: selftests: fix sync_with_host() in smm_test
    KVM: async_pf: Inject 'page ready' event only if 'page not present' was previously injected
    KVM: async_pf: Cleanup kvm_setup_async_pf()
    kvm: i8254: remove redundant assignment to pointer s
    KVM: x86: respect singlestep when emulating instruction
    KVM: selftests: Don't probe KVM_CAP_HYPERV_ENLIGHTENED_VMCS when nested VMX is unsupported
    KVM: selftests: do not substitute SVM/VMX check with KVM_CAP_NESTED_STATE check
    KVM: nVMX: Consult only the "basic" exit reason when routing nested exit
    KVM: arm64: Move hyp_symbol_addr() to kvm_asm.h
    KVM: arm64: Synchronize sysreg state on injecting an AArch32 exception
    KVM: arm64: Make vcpu_cp1x() work on Big Endian hosts
    KVM: arm64: Remove host_cpu_context member from vcpu structure
    KVM: arm64: Stop sparse from moaning at __hyp_this_cpu_ptr
    KVM: arm64: Handle PtrAuth traps early
    KVM: x86: Unexport x86_fpu_cache and make it static
    KVM: selftests: Ignore KVM 5-level paging support for VM_MODE_PXXV48_4K
    KVM: arm64: Save the host's PtrAuth keys in non-preemptible context
    KVM: arm64: Stop save/restoring ACTLR_EL1
    KVM: arm64: Add emulation for 32bit guests accessing ACTLR2
    ...

    Linus Torvalds
     

12 Jun, 2020

2 commits

  • 'Page not present' event may or may not get injected depending on
    guest's state. If the event wasn't injected, there is no need to
    inject the corresponding 'page ready' event as the guest may get
    confused. E.g. Linux thinks that the corresponding 'page not present'
    event wasn't delivered *yet* and allocates a 'dummy entry' for it.
    This entry is never freed.

    Note, 'wakeup all' events have no corresponding 'page not present'
    event and always get injected.

    s390 seems to always be able to inject 'page not present', the
    change is effectively a nop.

    Suggested-by: Vivek Goyal
    Signed-off-by: Vitaly Kuznetsov
    Message-Id:
    Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=208081
    Signed-off-by: Paolo Bonzini

    Vitaly Kuznetsov
     
  • schedule_work() returns 'false' only when the work is already on the queue
    and this can't happen as kvm_setup_async_pf() always allocates a new one.
    Also, to avoid potential race, it makes sense to to schedule_work() at the
    very end after we've added it to the queue.

    While on it, do some minor cleanup. gfn_to_pfn_async() mentioned in a
    comment does not currently exist and, moreover, we can check
    kvm_is_error_hva() at the very beginning, before we try to allocate work so
    'retry_sync' label can go away completely.

    Signed-off-by: Vitaly Kuznetsov
    Message-Id:
    Reviewed-by: Sean Christopherson
    Signed-off-by: Paolo Bonzini

    Vitaly Kuznetsov
     

10 Jun, 2020

2 commits

  • This change converts the existing mmap_sem rwsem calls to use the new mmap
    locking API instead.

    The change is generated using coccinelle with the following rule:

    // spatch --sp-file mmap_lock_api.cocci --in-place --include-headers --dir .

    @@
    expression mm;
    @@
    (
    -init_rwsem
    +mmap_init_lock
    |
    -down_write
    +mmap_write_lock
    |
    -down_write_killable
    +mmap_write_lock_killable
    |
    -down_write_trylock
    +mmap_write_trylock
    |
    -up_write
    +mmap_write_unlock
    |
    -downgrade_write
    +mmap_write_downgrade
    |
    -down_read
    +mmap_read_lock
    |
    -down_read_killable
    +mmap_read_lock_killable
    |
    -down_read_trylock
    +mmap_read_trylock
    |
    -up_read
    +mmap_read_unlock
    )
    -(&mm->mmap_sem)
    +(mm)

    Signed-off-by: Michel Lespinasse
    Signed-off-by: Andrew Morton
    Reviewed-by: Daniel Jordan
    Reviewed-by: Laurent Dufour
    Reviewed-by: Vlastimil Babka
    Cc: Davidlohr Bueso
    Cc: David Rientjes
    Cc: Hugh Dickins
    Cc: Jason Gunthorpe
    Cc: Jerome Glisse
    Cc: John Hubbard
    Cc: Liam Howlett
    Cc: Matthew Wilcox
    Cc: Peter Zijlstra
    Cc: Ying Han
    Link: http://lkml.kernel.org/r/20200520052908.204642-5-walken@google.com
    Signed-off-by: Linus Torvalds

    Michel Lespinasse
     
  • Patch series "mm: consolidate definitions of page table accessors", v2.

    The low level page table accessors (pXY_index(), pXY_offset()) are
    duplicated across all architectures and sometimes more than once. For
    instance, we have 31 definition of pgd_offset() for 25 supported
    architectures.

    Most of these definitions are actually identical and typically it boils
    down to, e.g.

    static inline unsigned long pmd_index(unsigned long address)
    {
    return (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
    }

    static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
    {
    return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(address);
    }

    These definitions can be shared among 90% of the arches provided
    XYZ_SHIFT, PTRS_PER_XYZ and xyz_page_vaddr() are defined.

    For architectures that really need a custom version there is always
    possibility to override the generic version with the usual ifdefs magic.

    These patches introduce include/linux/pgtable.h that replaces
    include/asm-generic/pgtable.h and add the definitions of the page table
    accessors to the new header.

    This patch (of 12):

    The linux/mm.h header includes to allow inlining of the
    functions involving page table manipulations, e.g. pte_alloc() and
    pmd_alloc(). So, there is no point to explicitly include
    in the files that include .

    The include statements in such cases are remove with a simple loop:

    for f in $(git grep -l "include ") ; do
    sed -i -e '/include / d' $f
    done

    Signed-off-by: Mike Rapoport
    Signed-off-by: Andrew Morton
    Cc: Arnd Bergmann
    Cc: Borislav Petkov
    Cc: Brian Cain
    Cc: Catalin Marinas
    Cc: Chris Zankel
    Cc: "David S. Miller"
    Cc: Geert Uytterhoeven
    Cc: Greentime Hu
    Cc: Greg Ungerer
    Cc: Guan Xuetao
    Cc: Guo Ren
    Cc: Heiko Carstens
    Cc: Helge Deller
    Cc: Ingo Molnar
    Cc: Ley Foon Tan
    Cc: Mark Salter
    Cc: Matthew Wilcox
    Cc: Matt Turner
    Cc: Max Filippov
    Cc: Michael Ellerman
    Cc: Michal Simek
    Cc: Mike Rapoport
    Cc: Nick Hu
    Cc: Paul Walmsley
    Cc: Richard Weinberger
    Cc: Rich Felker
    Cc: Russell King
    Cc: Stafford Horne
    Cc: Thomas Bogendoerfer
    Cc: Thomas Gleixner
    Cc: Tony Luck
    Cc: Vincent Chen
    Cc: Vineet Gupta
    Cc: Will Deacon
    Cc: Yoshinori Sato
    Link: http://lkml.kernel.org/r/20200514170327.31389-1-rppt@kernel.org
    Link: http://lkml.kernel.org/r/20200514170327.31389-2-rppt@kernel.org
    Signed-off-by: Linus Torvalds

    Mike Rapoport
     

09 Jun, 2020

1 commit

  • API __get_user_pages_fast() renamed to get_user_pages_fast_only() to
    align with pin_user_pages_fast_only().

    As part of this we will get rid of write parameter. Instead caller will
    pass FOLL_WRITE to get_user_pages_fast_only(). This will not change any
    existing functionality of the API.

    All the callers are changed to pass FOLL_WRITE.

    Also introduce get_user_page_fast_only(), and use it in a few places
    that hard-code nr_pages to 1.

    Updated the documentation of the API.

    Signed-off-by: Souptick Joarder
    Signed-off-by: Andrew Morton
    Reviewed-by: John Hubbard
    Reviewed-by: Paul Mackerras [arch/powerpc/kvm]
    Cc: Matthew Wilcox
    Cc: Michael Ellerman
    Cc: Benjamin Herrenschmidt
    Cc: Peter Zijlstra
    Cc: Ingo Molnar
    Cc: Mark Rutland
    Cc: Alexander Shishkin
    Cc: Jiri Olsa
    Cc: Namhyung Kim
    Cc: Paolo Bonzini
    Cc: Stephen Rothwell
    Cc: Mike Rapoport
    Cc: Aneesh Kumar K.V
    Cc: Michal Suchanek
    Link: http://lkml.kernel.org/r/1590396812-31277-1-git-send-email-jrdr.linux@gmail.com
    Signed-off-by: Linus Torvalds

    Souptick Joarder
     

08 Jun, 2020

1 commit

  • Commit b1394e745b94 ("KVM: x86: fix APIC page invalidation") tried
    to fix inappropriate APIC page invalidation by re-introducing arch
    specific kvm_arch_mmu_notifier_invalidate_range() and calling it from
    kvm_mmu_notifier_invalidate_range_start. However, the patch left a
    possible race where the VMCS APIC address cache is updated *before*
    it is unmapped:

    (Invalidator) kvm_mmu_notifier_invalidate_range_start()
    (Invalidator) kvm_make_all_cpus_request(kvm, KVM_REQ_APIC_PAGE_RELOAD)
    (KVM VCPU) vcpu_enter_guest()
    (KVM VCPU) kvm_vcpu_reload_apic_access_page()
    (Invalidator) actually unmap page

    Because of the above race, there can be a mismatch between the
    host physical address stored in the APIC_ACCESS_PAGE VMCS field and
    the host physical address stored in the EPT entry for the APIC GPA
    (0xfee0000). When this happens, the processor will not trap APIC
    accesses, and will instead show the raw contents of the APIC-access page.
    Because Windows OS periodically checks for unexpected modifications to
    the LAPIC register, this will show up as a BSOD crash with BugCheck
    CRITICAL_STRUCTURE_CORRUPTION (109) we are currently seeing in
    https://bugzilla.redhat.com/show_bug.cgi?id=1751017.

    The root cause of the issue is that kvm_arch_mmu_notifier_invalidate_range()
    cannot guarantee that no additional references are taken to the pages in
    the range before kvm_mmu_notifier_invalidate_range_end(). Fortunately,
    this case is supported by the MMU notifier API, as documented in
    include/linux/mmu_notifier.h:

    * If the subsystem
    * can't guarantee that no additional references are taken to
    * the pages in the range, it has to implement the
    * invalidate_range() notifier to remove any references taken
    * after invalidate_range_start().

    The fix therefore is to reload the APIC-access page field in the VMCS
    from kvm_mmu_notifier_invalidate_range() instead of ..._range_start().

    Cc: stable@vger.kernel.org
    Fixes: b1394e745b94 ("KVM: x86: fix APIC page invalidation")
    Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=197951
    Signed-off-by: Eiichi Tsukata
    Message-Id:
    Signed-off-by: Paolo Bonzini

    Eiichi Tsukata
     

05 Jun, 2020

1 commit


04 Jun, 2020

1 commit

  • After commit 63d0434 ("KVM: x86: move kvm_create_vcpu_debugfs after
    last failure point") we are creating the pre-vCPU debugfs files
    after the creation of the vCPU file descriptor. This makes it
    possible for userspace to reach kvm_vcpu_release before
    kvm_create_vcpu_debugfs has finished. The vcpu->debugfs_dentry
    then does not have any associated inode anymore, and this causes
    a NULL-pointer dereference in debugfs_create_file.

    The solution is simply to avoid removing the files; they are
    cleaned up when the VM file descriptor is closed (and that must be
    after KVM_CREATE_VCPU returns). We can stop storing the dentry
    in struct kvm_vcpu too, because it is not needed anywhere after
    kvm_create_vcpu_debugfs returns.

    Reported-by: syzbot+705f4401d5a93a59b87d@syzkaller.appspotmail.com
    Fixes: 63d04348371b ("KVM: x86: move kvm_create_vcpu_debugfs after last failure point")
    Signed-off-by: Paolo Bonzini

    Paolo Bonzini
     

01 Jun, 2020

6 commits

  • KVM/arm64 updates for Linux 5.8:

    - Move the arch-specific code into arch/arm64/kvm
    - Start the post-32bit cleanup
    - Cherry-pick a few non-invasive pre-NV patches

    Paolo Bonzini
     
  • The userspace_addr alignment and range checks are not performed for private
    memory slots that are prepared by KVM itself. This is unnecessary and makes
    it questionable to use __*_user functions to access memory later on. We also
    rely on the userspace address being aligned since we have an entire family
    of functions to map gfn to pfn.

    Fortunately skipping the check is completely unnecessary. Only x86 uses
    private memslots and their userspace_addr is obtained from vm_mmap,
    therefore it must be below PAGE_OFFSET. In fact, any attempt to pass
    an address above PAGE_OFFSET would have failed because such an address
    would return true for kvm_is_error_hva.

    Reported-by: Linus Torvalds
    Signed-off-by: Paolo Bonzini

    Paolo Bonzini
     
  • If two page ready notifications happen back to back the second one is not
    delivered and the only mechanism we currently have is
    kvm_check_async_pf_completion() check in vcpu_run() loop. The check will
    only be performed with the next vmexit when it happens and in some cases
    it may take a while. With interrupt based page ready notification delivery
    the situation is even worse: unlike exceptions, interrupts are not handled
    immediately so we must check if the slot is empty. This is slow and
    unnecessary. Introduce dedicated MSR_KVM_ASYNC_PF_ACK MSR to communicate
    the fact that the slot is free and host should check its notification
    queue. Mandate using it for interrupt based 'page ready' APF event
    delivery.

    As kvm_check_async_pf_completion() is going away from vcpu_run() we need
    a way to communicate the fact that vcpu->async_pf.done queue has
    transitioned from empty to non-empty state. Introduce
    kvm_arch_async_page_present_queued() and KVM_REQ_APF_READY to do the job.

    Signed-off-by: Vitaly Kuznetsov
    Message-Id:
    Signed-off-by: Paolo Bonzini

    Vitaly Kuznetsov
     
  • We already have kvm_write_guest_offset_cached(), introduce read analogue.

    Signed-off-by: Vitaly Kuznetsov
    Message-Id:
    Signed-off-by: Paolo Bonzini

    Vitaly Kuznetsov
     
  • An innocent reader of the following x86 KVM code:

    bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu)
    {
    if (!(vcpu->arch.apf.msr_val & KVM_ASYNC_PF_ENABLED))
    return true;
    ...

    may get very confused: if APF mechanism is not enabled, why do we report
    that we 'can inject async page present'? In reality, upon injection
    kvm_arch_async_page_present() will check the same condition again and,
    in case APF is disabled, will just drop the item. This is fine as the
    guest which deliberately disabled APF doesn't expect to get any APF
    notifications.

    Rename kvm_arch_can_inject_async_page_present() to
    kvm_arch_can_dequeue_async_page_present() to make it clear what we are
    checking: if the item can be dequeued (meaning either injected or just
    dropped).

    On s390 kvm_arch_can_inject_async_page_present() always returns 'true' so
    the rename doesn't matter much.

    Signed-off-by: Vitaly Kuznetsov
    Message-Id:
    Signed-off-by: Paolo Bonzini

    Vitaly Kuznetsov
     
  • This reverts commit 5b494aea13fe9ec67365510c0d75835428cbb303.
    If unlocked==true then the vma pointer could be invalidated, so the 2nd
    follow_pfn() is potentially racy: we do need to get out and redo
    find_vma_intersection().

    Signed-off-by: Peter Xu
    Signed-off-by: Paolo Bonzini

    Paolo Bonzini
     

16 May, 2020

5 commits

  • Fix spelling and typos (e.g., repeated words) in comments.

    Signed-off-by: Fuad Tabba
    Signed-off-by: Marc Zyngier
    Link: https://lore.kernel.org/r/20200401140310.29701-1-tabba@google.com

    Fuad Tabba
     
  • Now that the 32bit KVM/arm host is a distant memory, let's move the
    whole of the KVM/arm64 code into the arm64 tree.

    As they said in the song: Welcome Home (Sanitarium).

    Signed-off-by: Marc Zyngier
    Acked-by: Will Deacon
    Link: https://lore.kernel.org/r/20200513104034.74741-1-maz@kernel.org

    Marc Zyngier
     
  • Two new stats for exposing halt-polling cpu usage:
    halt_poll_success_ns
    halt_poll_fail_ns

    Thus sum of these 2 stats is the total cpu time spent polling. "success"
    means the VCPU polled until a virtual interrupt was delivered. "fail"
    means the VCPU had to schedule out (either because the maximum poll time
    was reached or it needed to yield the CPU).

    To avoid touching every arch's kvm_vcpu_stat struct, only update and
    export halt-polling cpu usage stats if we're on x86.

    Exporting cpu usage as a u64 and in nanoseconds means we will overflow at
    ~500 years, which seems reasonably large.

    Signed-off-by: David Matlack
    Signed-off-by: Jon Cargille
    Reviewed-by: Jim Mattson

    Message-Id:
    Signed-off-by: Paolo Bonzini

    David Matlack
     
  • While optimizing posted-interrupt delivery especially for the timer
    fastpath scenario, I measured kvm_x86_ops.deliver_posted_interrupt()
    to introduce substantial latency because the processor has to perform
    all vmentry tasks, ack the posted interrupt notification vector,
    read the posted-interrupt descriptor etc.

    This is not only slow, it is also unnecessary when delivering an
    interrupt to the current CPU (as is the case for the LAPIC timer) because
    PIR->IRR and IRR->RVI synchronization is already performed on vmentry
    Therefore skip kvm_vcpu_trigger_posted_interrupt in this case, and
    instead do vmx_sync_pir_to_irr() on the EXIT_FASTPATH_REENTER_GUEST
    fastpath as well.

    Tested-by: Haiwei Li
    Cc: Haiwei Li
    Suggested-by: Paolo Bonzini
    Signed-off-by: Wanpeng Li
    Message-Id:
    Signed-off-by: Paolo Bonzini

    Wanpeng Li
     
  • hva_to_pfn_remapped() calls fixup_user_fault(), which has already
    handled the retry gracefully. Even if "unlocked" is set to true, it
    means that we've got a VM_FAULT_RETRY inside fixup_user_fault(),
    however the page fault has already retried and we should have the pfn
    set correctly. No need to do that again.

    Signed-off-by: Peter Xu
    Message-Id:
    Signed-off-by: Paolo Bonzini

    Peter Xu
     

14 May, 2020

3 commits

  • The '==' expression itself is bool, no need to convert it to bool again.
    This fixes the following coccicheck warning:

    virt/kvm/eventfd.c:724:38-43: WARNING: conversion to bool not needed
    here

    Signed-off-by: Jason Yan
    Message-Id:
    Reviewed-by: Peter Xu
    Signed-off-by: Paolo Bonzini

    Jason Yan
     
  • The use of any sort of waitqueue (simple or regular) for
    wait/waking vcpus has always been an overkill and semantically
    wrong. Because this is per-vcpu (which is blocked) there is
    only ever a single waiting vcpu, thus no need for any sort of
    queue.

    As such, make use of the rcuwait primitive, with the following
    considerations:

    - rcuwait already provides the proper barriers that serialize
    concurrent waiter and waker.

    - Task wakeup is done in rcu read critical region, with a
    stable task pointer.

    - Because there is no concurrency among waiters, we need
    not worry about rcuwait_wait_event() calls corrupting
    the wait->task. As a consequence, this saves the locking
    done in swait when modifying the queue. This also applies
    to per-vcore wait for powerpc kvm-hv.

    The x86 tscdeadline_latency test mentioned in 8577370fb0cb
    ("KVM: Use simple waitqueue for vcpu->wq") shows that, on avg,
    latency is reduced by around 15-20% with this change.

    Cc: Paul Mackerras
    Cc: kvmarm@lists.cs.columbia.edu
    Cc: linux-mips@vger.kernel.org
    Reviewed-by: Marc Zyngier
    Signed-off-by: Davidlohr Bueso
    Message-Id:
    [Avoid extra logic changes. - Paolo]
    Signed-off-by: Paolo Bonzini

    Davidlohr Bueso
     
  • Paolo Bonzini
     

08 May, 2020

1 commit


01 May, 2020

1 commit

  • In the unlikely event that a 32bit vcpu traps into the hypervisor
    on an instruction that is located right at the end of the 32bit
    range, the emulation of that instruction is going to increment
    PC past the 32bit range. This isn't great, as userspace can then
    observe this value and get a bit confused.

    Conversly, userspace can do things like (in the context of a 64bit
    guest that is capable of 32bit EL0) setting PSTATE to AArch64-EL0,
    set PC to a 64bit value, change PSTATE to AArch32-USR, and observe
    that PC hasn't been truncated. More confusion.

    Fix both by:
    - truncating PC increments for 32bit guests
    - sanitizing all 32bit regs every time a core reg is changed by
    userspace, and that PSTATE indicates a 32bit mode.

    Cc: stable@vger.kernel.org
    Acked-by: Will Deacon
    Signed-off-by: Marc Zyngier

    Marc Zyngier
     

30 Apr, 2020

1 commit

  • KVM now expects to be able to use HW-accelerated delivery of vSGIs
    as soon as the guest has enabled thm. Unfortunately, we only
    initialize the GICv4 context if we have a virtual ITS exposed to
    the guest.

    Fix it by always initializing the GICv4.1 context if it is
    available on the host.

    Fixes: 2291ff2f2a56 ("KVM: arm64: GICv4.1: Plumb SGI implementation selection in the distributor")
    Reviewed-by: Zenghui Yu
    Signed-off-by: Marc Zyngier

    Marc Zyngier
     

25 Apr, 2020

1 commit

  • KVM_CAP_HALT_POLL is a per-VM capability that lets userspace
    control the halt-polling time, allowing halt-polling to be tuned or
    disabled on particular VMs.

    With dynamic halt-polling, a VM's VCPUs can poll from anywhere from
    [0, halt_poll_ns] on each halt. KVM_CAP_HALT_POLL sets the
    upper limit on the poll time.

    Signed-off-by: David Matlack
    Signed-off-by: Jon Cargille
    Reviewed-by: Jim Mattson
    Message-Id:
    Signed-off-by: Paolo Bonzini

    David Matlack
     

23 Apr, 2020

6 commits

  • Marc Zyngier
     
  • If we're going to fail out the vgic_add_lpi(), let's make sure the
    allocated vgic_irq memory is also freed. Though it seems that both
    cases are unlikely to fail.

    Signed-off-by: Zenghui Yu
    Signed-off-by: Marc Zyngier
    Link: https://lore.kernel.org/r/20200414030349.625-3-yuzenghui@huawei.com

    Zenghui Yu
     
  • It's likely that the vcpu fails to handle all virtual interrupts if
    userspace decides to destroy it, leaving the pending ones stay in the
    ap_list. If the un-handled one is a LPI, its vgic_irq structure will
    be eventually leaked because of an extra refcount increment in
    vgic_queue_irq_unlock().

    This was detected by kmemleak on almost every guest destroy, the
    backtrace is as follows:

    unreferenced object 0xffff80725aed5500 (size 128):
    comm "CPU 5/KVM", pid 40711, jiffies 4298024754 (age 166366.512s)
    hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 08 01 a9 73 6d 80 ff ff ...........sm...
    c8 61 ee a9 00 20 ff ff 28 1e 55 81 6c 80 ff ff .a... ..(.U.l...
    backtrace:
    [] kmem_cache_alloc_trace+0x2dc/0x418
    [] vgic_add_lpi+0x88/0x418
    [] vgic_its_cmd_handle_mapi+0x4dc/0x588
    [] vgic_its_process_commands.part.5+0x484/0x1198
    [] vgic_its_process_commands+0x50/0x80
    [] vgic_mmio_write_its_cwriter+0xac/0x108
    [] dispatch_mmio_write+0xd0/0x188
    [] __kvm_io_bus_write+0x134/0x240
    [] kvm_io_bus_write+0xe0/0x150
    [] io_mem_abort+0x484/0x7b8
    [] kvm_handle_guest_abort+0x4cc/0xa58
    [] handle_exit+0x24c/0x770
    [] kvm_arch_vcpu_ioctl_run+0x460/0x1988
    [] kvm_vcpu_ioctl+0x4f8/0xee0
    [] do_vfs_ioctl+0x160/0xcd8
    [] ksys_ioctl+0x98/0xd8

    Fix it by retiring all pending LPIs in the ap_list on the destroy path.

    p.s. I can also reproduce it on a normal guest shutdown. It is because
    userspace still send LPIs to vcpu (through KVM_SIGNAL_MSI ioctl) while
    the guest is being shutdown and unable to handle it. A little strange
    though and haven't dig further...

    Reviewed-by: James Morse
    Signed-off-by: Zenghui Yu
    [maz: moved the distributor deallocation down to avoid an UAF splat]
    Signed-off-by: Marc Zyngier
    Link: https://lore.kernel.org/r/20200414030349.625-2-yuzenghui@huawei.com

    Zenghui Yu
     
  • There is no point in accessing the HW when writing to any of the
    ISPENDR/ICPENDR registers from userspace, as only the guest should
    be allowed to change the HW state.

    Introduce new userspace-specific accessors that deal solely with
    the virtual state. Note that the API differs from that of GICv3,
    where userspace exclusively uses ISPENDR to set the state. Too
    bad we can't reuse it.

    Fixes: 82e40f558de56 ("KVM: arm/arm64: vgic-v2: Handle SGI bits in GICD_I{S,C}PENDR0 as WI")
    Reviewed-by: James Morse
    Signed-off-by: Marc Zyngier

    Marc Zyngier
     
  • There is no point in accessing the HW when writing to any of the
    ISENABLER/ICENABLER registers from userspace, as only the guest
    should be allowed to change the HW state.

    Introduce new userspace-specific accessors that deal solely with
    the virtual state.

    Reported-by: James Morse
    Tested-by: James Morse
    Reviewed-by: James Morse
    Signed-off-by: Marc Zyngier

    Marc Zyngier
     
  • When a guest tries to read the active state of its interrupts,
    we currently just return whatever state we have in memory. This
    means that if such an interrupt lives in a List Register on another
    CPU, we fail to obsertve the latest active state for this interrupt.

    In order to remedy this, stop all the other vcpus so that they exit
    and we can observe the most recent value for the state. This is
    similar to what we are doing for the write side of the same
    registers, and results in new MMIO handlers for userspace (which
    do not need to stop the guest, as it is supposed to be stopped
    already).

    Reported-by: Julien Grall
    Reviewed-by: Andre Przywara
    Signed-off-by: Marc Zyngier

    Marc Zyngier
     

21 Apr, 2020

4 commits

  • When a nested page fault is taken from an address that does not have
    a memslot associated to it, kvm_mmu_do_page_fault returns RET_PF_EMULATE
    (via mmu_set_spte) and kvm_mmu_page_fault then invokes svm_need_emulation_on_page_fault.

    The default answer there is to return false, but in this case this just
    causes the page fault to be retried ad libitum. Since this is not a
    fast path, and the only other case where it is taken is an erratum,
    just stick a kvm_vcpu_gfn_to_memslot check in there to detect the
    common case where the erratum is not happening.

    This fixes an infinite loop in the new set_memory_region_test.

    Signed-off-by: Paolo Bonzini

    Paolo Bonzini
     
  • In earlier versions of kvm, 'kvm_run' was an independent structure
    and was not included in the vcpu structure. At present, 'kvm_run'
    is already included in the vcpu structure, so the parameter
    'kvm_run' is redundant.

    This patch simplifies the function definition, removes the extra
    'kvm_run' parameter, and extracts it from the 'kvm_vcpu' structure
    if necessary.

    Signed-off-by: Tianjia Zhang
    Message-Id:
    Signed-off-by: Paolo Bonzini

    Tianjia Zhang
     
  • Create a new function kvm_is_visible_memslot() and use it from
    kvm_is_visible_gfn(); use the new function in try_async_pf() too,
    to avoid an extra memslot lookup.

    Opportunistically squish a multi-line comment into a single-line comment.

    Note, the end result, KVM_PFN_NOSLOT, is unchanged.

    Cc: Jim Mattson
    Cc: Rick Edgecombe
    Suggested-by: Sean Christopherson
    Signed-off-by: Paolo Bonzini

    Paolo Bonzini
     
  • The placement of kvm_create_vcpu_debugfs is more or less irrelevant, since
    it cannot fail and userspace should not care about the debugfs entries until
    it knows the vcpu has been created. Moving it after the last failure
    point removes the need to remove the directory when unwinding the creation.

    Reviewed-by: Emanuele Giuseppe Esposito
    Message-Id:
    Signed-off-by: Paolo Bonzini

    Paolo Bonzini
     

17 Apr, 2020

2 commits

  • Implementing (and even advertising) 64bit PSCI functions to 32bit
    guests is at least a bit odd, if not altogether violating the
    spec which says ("5.2.1 Register usage in arguments and return values"):

    "Adherence to the SMC Calling Conventions implies that any AArch32
    caller of an SMC64 function will get a return code of 0xFFFFFFFF(int32).
    This matches the NOT_SUPPORTED error code used in PSCI"

    Tighten the implementation by pretending these functions are not
    there for 32bit guests.

    Reviewed-by: Christoffer Dall
    Reviewed-by: Alexandru Elisei
    Signed-off-by: Marc Zyngier

    Marc Zyngier
     
  • When a guest delibarately uses an SMC32 function number (which is allowed),
    we should make sure we drop the top 32bits from the input arguments, as they
    could legitimately be junk.

    Reported-by: Christoffer Dall
    Reviewed-by: Christoffer Dall
    Reviewed-by: Alexandru Elisei
    Signed-off-by: Marc Zyngier

    Marc Zyngier
     

16 Apr, 2020

1 commit