Skip to content
Snippets Groups Projects
  1. Oct 06, 2024
    • Paolo Bonzini's avatar
      x86/reboot: emergency callbacks are now registered by common KVM code · 2a5fe5a0
      Paolo Bonzini authored
      
      Guard them with CONFIG_KVM_X86_COMMON rather than the two vendor modules.
      In practice this has no functional change, because CONFIG_KVM_X86_COMMON
      is set if and only if at least one vendor-specific module is being built.
      However, it is cleaner to specify CONFIG_KVM_X86_COMMON for functions that
      are used in kvm.ko.
      
      Reported-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Fixes: 590b09b1 ("KVM: x86: Register "emergency disable" callbacks when virt is enabled")
      Fixes: 6d55a942 ("x86/reboot: Unconditionally define cpu_emergency_virt_cb typedef")
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      2a5fe5a0
    • Paolo Bonzini's avatar
      KVM: x86: leave kvm.ko out of the build if no vendor module is requested · ea4290d7
      Paolo Bonzini authored
      
      kvm.ko is nothing but library code shared by kvm-intel.ko and kvm-amd.ko.
      It provides no functionality on its own and it is unnecessary unless one
      of the vendor-specific module is compiled.  In particular, /dev/kvm is
      not created until one of kvm-intel.ko or kvm-amd.ko is loaded.
      
      Use CONFIG_KVM to decide if it is built-in or a module, but use the
      vendor-specific modules for the actual decision on whether to build it.
      
      This also fixes a build failure when CONFIG_KVM_INTEL and CONFIG_KVM_AMD
      are both disabled.  The cpu_emergency_register_virt_callback() function
      is called from kvm.ko, but it is only defined if at least one of
      CONFIG_KVM_INTEL and CONFIG_KVM_AMD is provided.
      
      Fixes: 590b09b1 ("KVM: x86: Register "emergency disable" callbacks when virt is enabled")
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      ea4290d7
  2. Oct 04, 2024
  3. Oct 03, 2024
  4. Oct 02, 2024
    • Al Viro's avatar
      move asm/unaligned.h to linux/unaligned.h · 5f60d5f6
      Al Viro authored
      asm/unaligned.h is always an include of asm-generic/unaligned.h;
      might as well move that thing to linux/unaligned.h and include
      that - there's nothing arch-specific in that header.
      
      auto-generated by the following:
      
      for i in `git grep -l -w asm/unaligned.h`; do
      	sed -i -e "s/asm\/unaligned.h/linux\/unaligned.h/" $i
      done
      for i in `git grep -l -w asm-generic/unaligned.h`; do
      	sed -i -e "s/asm-generic\/unaligned.h/linux\/unaligned.h/" $i
      done
      git mv include/asm-generic/unaligned.h include/linux/unaligned.h
      git mv tools/include/asm-generic/unaligned.h tools/include/linux/unaligned.h
      sed -i -e "/unaligned.h/d" include/asm-generic/Kbuild
      sed -i -e "s/__ASM_GENERIC/__LINUX/" include/linux/unaligned.h tools/include/linux/unaligned.h
      5f60d5f6
    • Al Viro's avatar
      arc: get rid of private asm/unaligned.h · 00429083
      Al Viro authored
      
      Declarations local to arch/*/kernel/*.c are better off *not* in a public
      header - arch/arc/kernel/unaligned.h is just fine for those
      bits.
      
      Unlike the parisc case, here we have an extra twist - asm/mmu.h
      has an implicit dependency on struct pt_regs, and in some users
      that used to be satisfied by include of asm/ptrace.h from
      asm/unaligned.h (note that asm/mmu.h itself did _not_ pull asm/unaligned.h
      - it relied upon the users having pulled asm/unaligned.h before asm/mmu.h
      got there).
      
      Seeing that asm/mmu.h only wants struct pt_regs * arguments in
      an extern, just pre-declare it there - less brittle that way.
      
      With that done _all_ asm/unaligned.h instances are reduced to include
      of asm-generic/unaligned.h and can be removed - unaligned.h is in
      mandatory-y in include/asm-generic/Kbuild.
      
      What's more, we can move asm-generic/unaligned.h to linux/unaligned.h
      and switch includes of <asm/unaligned.h> to <linux/unaligned.h>; that's
      better off as an auto-generated commit, though, to be done by Linus
      at -rc1 time next cycle.
      
      Acked-by: default avatarVineet Gupta <vgupta@kernel.org>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      00429083
    • Al Viro's avatar
      parisc: get rid of private asm/unaligned.h · 134d9882
      Al Viro authored
      
      Declarations local to arch/*/kernel/*.c are better off *not* in a public
      header - arch/parisc/kernel/unaligned.h is just fine for those
      bits.
      
      With that done parisc asm/unaligned.h is reduced to include
      of asm-generic/unaligned.h and can be removed - unaligned.h is in
      mandatory-y in include/asm-generic/Kbuild.
      
      Acked-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      134d9882
  5. Oct 01, 2024
  6. Sep 30, 2024
  7. Sep 29, 2024
    • Linus Torvalds's avatar
      x86: kvm: fix build error · 3f749bef
      Linus Torvalds authored
      
      The cpu_emergency_register_virt_callback() function is used
      unconditionally by the x86 kvm code, but it is declared (and defined)
      conditionally:
      
        #if IS_ENABLED(CONFIG_KVM_INTEL) || IS_ENABLED(CONFIG_KVM_AMD)
        void cpu_emergency_register_virt_callback(cpu_emergency_virt_cb *callback);
        ...
      
      leading to a build error when neither KVM_INTEL nor KVM_AMD support is
      enabled:
      
        arch/x86/kvm/x86.c: In function ‘kvm_arch_enable_virtualization’:
        arch/x86/kvm/x86.c:12517:9: error: implicit declaration of function ‘cpu_emergency_register_virt_callback’ [-Wimplicit-function-declaration]
        12517 |         cpu_emergency_register_virt_callback(kvm_x86_ops.emergency_disable_virtualization_cpu);
              |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        arch/x86/kvm/x86.c: In function ‘kvm_arch_disable_virtualization’:
        arch/x86/kvm/x86.c:12522:9: error: implicit declaration of function ‘cpu_emergency_unregister_virt_callback’ [-Wimplicit-function-declaration]
        12522 |         cpu_emergency_unregister_virt_callback(kvm_x86_ops.emergency_disable_virtualization_cpu);
              |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      Fix the build by defining empty helper functions the same way the old
      cpu_emergency_disable_virtualization() function was dealt with for the
      same situation.
      
      Maybe we could instead have made the call sites conditional, since the
      callers (kvm_arch_{en,dis}able_virtualization()) have an empty weak
      fallback.  I'll leave that to the kvm people to argue about, this at
      least gets the build going for that particular config.
      
      Fixes: 590b09b1 ("KVM: x86: Register "emergency disable" callbacks when virt is enabled")
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Kai Huang <kai.huang@intel.com>
      Cc: Chao Gao <chao.gao@intel.com>
      Cc: Farrah Chen <farrah.chen@intel.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      3f749bef
  8. Sep 27, 2024
    • Al Viro's avatar
      [tree-wide] finally take no_llseek out · cb787f4a
      Al Viro authored
      
      no_llseek had been defined to NULL two years ago, in commit 868941b1
      ("fs: remove no_llseek")
      
      To quote that commit,
      
        At -rc1 we'll need do a mechanical removal of no_llseek -
      
        git grep -l -w no_llseek | grep -v porting.rst | while read i; do
      	sed -i '/\<no_llseek\>/d' $i
        done
      
        would do it.
      
      Unfortunately, that hadn't been done.  Linus, could you do that now, so
      that we could finally put that thing to rest? All instances are of the
      form
      	.llseek = no_llseek,
      so it's obviously safe.
      
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      cb787f4a
  9. Sep 26, 2024
  10. Sep 25, 2024
    • Jason Andryuk's avatar
      x86/pvh: Add 64bit relocation page tables · 47ffe057
      Jason Andryuk authored
      
      The PVH entry point is 32bit.  For a 64bit kernel, the entry point must
      switch to 64bit mode, which requires a set of page tables.  In the past,
      PVH used init_top_pgt.
      
      This works fine when the kernel is loaded at LOAD_PHYSICAL_ADDR, as the
      page tables are prebuilt for this address.  If the kernel is loaded at a
      different address, they need to be adjusted.
      
      __startup_64() adjusts the prebuilt page tables for the physical load
      address, but it is 64bit code.  The 32bit PVH entry code can't call it
      to adjust the page tables, so it can't readily be re-used.
      
      64bit PVH entry needs page tables set up for identity map, the kernel
      high map and the direct map.  pvh_start_xen() enters identity mapped.
      Inside xen_prepare_pvh(), it jumps through a pv_ops function pointer
      into the highmap.  The direct map is used for __va() on the initramfs
      and other guest physical addresses.
      
      Add a dedicated set of prebuild page tables for PVH entry.  They are
      adjusted in assembly before loading.
      
      Add XEN_ELFNOTE_PHYS32_RELOC to indicate support for relocation
      along with the kernel's loading constraints.  The maximum load address,
      KERNEL_IMAGE_SIZE - 1, is determined by a single pvh_level2_ident_pgt
      page.  It could be larger with more pages.
      
      Signed-off-by: default avatarJason Andryuk <jason.andryuk@amd.com>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Message-ID: <20240823193630.2583107-6-jason.andryuk@amd.com>
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      47ffe057
    • Jason Andryuk's avatar
      x86/kernel: Move page table macros to header · e3e8cd90
      Jason Andryuk authored
      
      The PVH entry point will need an additional set of prebuild page tables.
      Move the macros and defines to pgtable_64.h, so they can be re-used.
      
      Signed-off-by: default avatarJason Andryuk <jason.andryuk@amd.com>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Acked-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
      Message-ID: <20240823193630.2583107-5-jason.andryuk@amd.com>
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      e3e8cd90
    • Jason Andryuk's avatar
      x86/pvh: Set phys_base when calling xen_prepare_pvh() · b464b461
      Jason Andryuk authored
      
      phys_base needs to be set for __pa() to work in xen_pvh_init() when
      finding the hypercall page.  Set it before calling into
      xen_prepare_pvh(), which calls xen_pvh_init().  Clear it afterward to
      avoid __startup_64() adding to it and creating an incorrect value.
      
      Signed-off-by: default avatarJason Andryuk <jason.andryuk@amd.com>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Message-ID: <20240823193630.2583107-4-jason.andryuk@amd.com>
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      b464b461
    • Jason Andryuk's avatar
      x86/pvh: Make PVH entrypoint PIC for x86-64 · 1db29f99
      Jason Andryuk authored
      
      The PVH entrypoint is 32bit non-PIC code running the uncompressed
      vmlinux at its load address CONFIG_PHYSICAL_START - default 0x1000000
      (16MB).  The kernel is loaded at that physical address inside the VM by
      the VMM software (Xen/QEMU).
      
      When running a Xen PVH Dom0, the host reserved addresses are mapped 1-1
      into the PVH container.  There exist system firmwares (Coreboot/EDK2)
      with reserved memory at 16MB.  This creates a conflict where the PVH
      kernel cannot be loaded at that address.
      
      Modify the PVH entrypoint to be position-indepedent to allow flexibility
      in load address.  Only the 64bit entry path is converted.  A 32bit
      kernel is not PIC, so calling into other parts of the kernel, like
      xen_prepare_pvh() and mk_pgtable_32(), don't work properly when
      relocated.
      
      This makes the code PIC, but the page tables need to be updated as well
      to handle running from the kernel high map.
      
      The UNWIND_HINT_END_OF_STACK is to silence:
      vmlinux.o: warning: objtool: pvh_start_xen+0x7f: unreachable instruction
      after the lret into 64bit code.
      
      Signed-off-by: default avatarJason Andryuk <jason.andryuk@amd.com>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Message-ID: <20240823193630.2583107-3-jason.andryuk@amd.com>
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      1db29f99
    • Jiqian Chen's avatar
      xen/pvh: Setup gsi for passthrough device · b166b8ab
      Jiqian Chen authored
      
      In PVH dom0, the gsis don't get registered, but the gsi of
      a passthrough device must be configured for it to be able to be
      mapped into a domU.
      
      When assigning a device to passthrough, proactively setup the gsi
      of the device during that process.
      
      Signed-off-by: default avatarJiqian Chen <Jiqian.Chen@amd.com>
      Signed-off-by: default avatarHuang Rui <ray.huang@amd.com>
      Signed-off-by: default avatarJiqian Chen <Jiqian.Chen@amd.com>
      Reviewed-by: default avatarStefano Stabellini <sstabellini@kernel.org>
      Message-ID: <20240924061437.2636766-3-Jiqian.Chen@amd.com>
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      b166b8ab
  11. Sep 24, 2024
    • Xi Ruoyao's avatar
      LoongArch: vDSO: Tune chacha implementation · 9805f39d
      Xi Ruoyao authored and Jason A. Donenfeld's avatar Jason A. Donenfeld committed
      
      As Christophe pointed out, tuning the chacha implementation by
      scheduling the instructions like what GCC does can improve the
      performance.
      
      The tuning does not introduce too much complexity (basically it's just
      reordering some instructions). And the tuning does not hurt readibility
      too much: actually the tuned code looks even more similar to a
      textbook-style implementation based on 128-bit vectors.  So overall it's
      a good deal to me.
      
      Tested with vdso_test_getchacha and benched with vdso_test_getrandom.
      On a LA664 the speedup is 5%, and I expect a larger speedup on LA[2-4]64
      with a lower issue rate.
      
      Suggested-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Link: https://lore.kernel.org/all/77655d9e-fc05-4300-8f0d-7b2ad840d091@csgroup.eu/
      
      
      Signed-off-by: default avatarXi Ruoyao <xry111@xry111.site>
      Reviewed-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      9805f39d
    • Xi Ruoyao's avatar
      LoongArch: Remove posix_types.h include from sigcontext.h · 64c35d6c
      Xi Ruoyao authored
      Nothing in sigcontext.h seems to require anything from
      linux/posix_types.h.  This include seems a MIPS relic originated from
      an error in Linux 2.6.11-rc2 (in 2005).
      
      The unneeded include was found debugging some vDSO self test build
      failure (it's not the root cause though).
      
      Link: https://lore.kernel.org/linux-mips/20240828030413.143930-2-xry111@xry111.site/
      Link: https://lore.kernel.org/loongarch/0b540679ec8cfccec75aeb3463810924f6ff71e6.camel@xry111.site/
      
      
      Signed-off-by: default avatarXi Ruoyao <xry111@xry111.site>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      64c35d6c
    • Wentao Guan's avatar
      LoongArch: Fix memleak in pci_acpi_scan_root() · 5016c3a3
      Wentao Guan authored
      
      Add kfree(root_ops) in this case to avoid memleak of root_ops,
      leaks when pci_find_bus() != 0.
      
      Signed-off-by: default avatarYuli Wang <wangyuli@uniontech.com>
      Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      5016c3a3
    • Uroš Bizjak's avatar
      LoongArch: Simplify _percpu_read() and _percpu_write() · d4f31acf
      Uroš Bizjak authored
      Now _percpu_read() and _percpu_write() macros call __percpu_read()
      and __percpu_write() static inline functions that result in a single
      assembly instruction. However, percpu infrastructure expects its leaf
      definitions to encode the size of their percpu variable, so the patch
      merges all the asm clauses from the static inline function into the
      corresponding leaf macros.
      
      The secondary effect of this change is to avoid explicit __percpu
      annotations for function arguments. Currently, __percpu macro is defined
      in include/linux/compiler_types.h, but with proposed patch [1], __percpu
      definition will need macros from include/asm-generic/percpu.h, creating
      forward dependency loop.
      
      The proposed solution is the same as x86 architecture uses.
      
      [1] https://lore.kernel.org/lkml/20240812115945.484051-4-ubizjak@gmail.com/
      
      
      
      Tested-by: default avatarXi Ruoyao <xry111@xry111.site>
      Signed-off-by: default avatarUros Bizjak <ubizjak@gmail.com>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      d4f31acf
    • Huacai Chen's avatar
      LoongArch: Improve hardware page table walker · f93f67d0
      Huacai Chen authored
      
      LoongArch has similar problems explained in commit 7f0b1bf0
      ("arm64: Fix barriers used for page table modifications"), when hardware
      page table walker (PTW) enabled, speculative accesses may cause spurious
      page fault in kernel space. Theoretically, in order to completely avoid
      spurious page fault we need a "dbar + ibar" pair between the page table
      modifications and the subsequent memory accesses using the corresponding
      virtual address. But "ibar" is too heavy for performace, so we only use
      a "dbar 0b11000" in set_pte(). And let spurious_fault() filter the rest
      rare spurious page faults which should be avoided by "ibar".
      
      Besides, we replace the llsc loop with amo in set_pte() which has better
      performace, and refactor mmu_context.h to 1) avoid any load/store/branch
      instructions between the writing of CSR.ASID & CSR.PGDL, 2) ensure flush
      tlb operation is after updating ASID.
      
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      f93f67d0
    • Huacai Chen's avatar
      LoongArch: Add ARCH_HAS_SET_DIRECT_MAP support · f04de6d8
      Huacai Chen authored
      
      Add set_direct_map_*() functions for setting the direct map alias for
      the page to its default permissions and to an invalid state that cannot
      be cached in a TLB. (See d253ca0c ("x86/mm/cpa: Add set_direct_map_*()
      functions")) Add a similar implementation for LoongArch.
      
      This fixes the KFENCE warnings during hibernation:
      
       ==================================================================
       BUG: KFENCE: invalid read in swsusp_save+0x368/0x4d8
      
       Invalid read at 0x00000000f7b89a3c:
        swsusp_save+0x368/0x4d8
        hibernation_snapshot+0x3f0/0x4e0
        hibernate+0x20c/0x440
        state_store+0x128/0x140
        kernfs_fop_write_iter+0x160/0x260
        vfs_write+0x2c0/0x520
        ksys_write+0x74/0x160
        do_syscall+0xb0/0x160
      
       CPU: 0 UID: 0 PID: 812 Comm: bash Tainted: G    B              6.11.0-rc1+ #1566
       Tainted: [B]=BAD_PAGE
       Hardware name: Loongson-LS3A5000-7A1000-1w-CRB, BIOS vUDK2018-LoongArch-V2.0.0 10/21/2022
       ==================================================================
      
      Note: We can only set permissions for KVRANGE/XKVRANGE kernel addresses.
      
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      f04de6d8
    • Huacai Chen's avatar
      LoongArch: Add ARCH_HAS_SET_MEMORY support · e86935f7
      Huacai Chen authored
      
      Add set_memory_ro/rw/x/nx architecture hooks to change the page
      attribution.
      
      Use own set_memory.h rather than generic set_memory.h (i.e.
      include/asm-generic/set_memory.h), because we want to add other function
      prototypes here.
      
      Note: We can only set attributes for KVRANGE/XKVRANGE kernel addresses.
      
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      e86935f7
    • Jiaxun Yang's avatar
      LoongArch: Rework CPU feature probe from CPUCFG/IOCSR · 34e3c450
      Jiaxun Yang authored
      
      Probe ISA level, TLB, IOCSR information from CPUCFG to improve kernel
      resilience to different core implementations.
      
      BTW, IOCSR register definition appears to be a platform-specific spec
      instead of an architecture spec, even for the Loongson CPUs there is no
      guarantee that IOCSR will always present.
      
      Thus it's dangerous to perform IOCSR probing without checking CPU type
      and instruction availability.
      
      Signed-off-by: default avatarJiaxun Yang <jiaxun.yang@flygoat.com>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      34e3c450
    • Bibo Mao's avatar
      LoongArch: Enable ACPI BGRT handling · d0bb0b60
      Bibo Mao authored
      
      Add ACPI BGRT support on LoongArch so it can display image provied by
      acpi table at boot stage and switch to graphical UI smoothly.
      
      Signed-off-by: default avatarBibo Mao <maobibo@loongson.cn>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      d0bb0b60
    • Tiezhu Yang's avatar
      LoongArch: Enable generic CPU vulnerabilites support · e8dd556c
      Tiezhu Yang authored
      Currently, many architectures support generic CPU vulnerabilites, such
      as x86, arm64 and riscv:
      
       commit 61dc0f55 ("x86/cpu: Implement CPU vulnerabilites sysfs functions")
       commit 61ae1321 ("arm64: enable generic CPU vulnerabilites support")
       commit 0e3f3649 ("riscv: Enable generic CPU vulnerabilites support")
      
      All LoongArch CPUs (since Loongson-3A5000) implement a special mechanism
      in the processor core to prevent "Meltdown" and "Spectre" attacks, so it
      can enable generic CPU vulnerabilites support for LoongArch too.
      
      Without this patch, there are no user interfaces of vulnerabilities to
      check on LoongArch. The output of those files reflects the state of the
      CPUs in the system, the output value "Not affected" means "CPU is not
      affected by the vulnerability".
      
      Before:
      
       # cat /sys/devices/system/cpu/vulnerabilities/spec_rstack_overflow
       cat: /sys/devices/system/cpu/vulnerabilities/spec_rstack_overflow: No such file or directory
       # cat /sys/devices/system/cpu/vulnerabilities/spec_store_bypass
       cat: /sys/devices/system/cpu/vulnerabilities/spec_store_bypass: No such file or directory
       # cat /sys/devices/system/cpu/vulnerabilities/meltdown
       cat: /sys/devices/system/cpu/vulnerabilities/meltdown: No such file or directory
      
      After:
      
       # cat /sys/devices/system/cpu/vulnerabilities/spec_rstack_overflow
       Not affected
       # cat /sys/devices/system/cpu/vulnerabilities/spec_store_bypass
       Not affected
       # cat /sys/devices/system/cpu/vulnerabilities/meltdown
       Not affected
      
      Link: https://www.loongson.cn/EN/news/show?id=633
      
      
      Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      e8dd556c
  12. Sep 23, 2024
Loading