Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync kvm patch for loongarch #635

Open
wants to merge 67 commits into
base: linux-6.6.y
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
26cb64e
anolis: LoongArch: KVM: Add PMU support
gaosong-loongson Jun 13, 2024
78a4fcc
anolis: LoongArch: KVM: Add iocsr and mmio bus simulation in kernel
lixianglai Jun 3, 2024
68060d2
anolis: LoongArch: KVM: Add IPI device support
lixianglai Jun 3, 2024
d6e485a
anolis: LoongArch: KVM: Add IPI read and write function
lixianglai Jun 15, 2024
fa63b13
anolis: LoongArch: KVM: Add IPI user mode read and write function
lixianglai Jun 15, 2024
a612ff5
anolis: LoongArch: KVM: Add EXTIOI device support
lixianglai Jun 3, 2024
303ff2b
anolis: LoongArch: KVM: Add EXTIOI read and write functions
lixianglai Jun 15, 2024
0710322
anolis: LoongArch: KVM: Add EXTIOI user mode read and write functions
lixianglai Jun 15, 2024
b499bce
anolis: LoongArch: KVM: Add PCHPIC device support
lixianglai Jun 3, 2024
9d92d8a
anolis: LoongArch: KVM: Add PCHPIC read and write functions
lixianglai Jun 15, 2024
f0ca787
anolis: LoongArch: KVM: Add PCHPIC user mode read and write functions
lixianglai Jun 15, 2024
4aa1697
anolis: LoongArch: KVM: Add irqfd support
lixianglai Jun 3, 2024
9f26f59
anolis: LoongArch: KVM: Fix pmu build error
gaosong-loongson Jun 13, 2024
cfb5b57
LoongArch: KVM: Add PV IPI support on host side
bibo-mao May 6, 2024
0998dc2
LoongArch: KVM: Add PV IPI support on guest side
bibo-mao May 6, 2024
1e0de7e
LoongArch: KVM: Add software breakpoint support
bibo-mao May 6, 2024
d4627fa
LoongArch: KVM: Add mmio trace events support
bibo-mao May 6, 2024
43c9fd3
LoongArch: KVM: Sync pending interrupt when getting ESTAT from user mode
bibo-mao Jul 9, 2024
2641198
LoongArch: KVM: Delay secondary mmu tlb flush until guest entry
bibo-mao Jul 9, 2024
8247fdb
LoongArch: KVM: Select huge page only if secondary mmu supports it
bibo-mao Jul 9, 2024
5e075e3
LoongArch: KVM: Discard dirty page tracking on readonly memslot
bibo-mao Jul 9, 2024
447426a
LoongArch: KVM: Add memory barrier before update pmd entry
bibo-mao Jul 9, 2024
ffe9bde
LoongArch: KVM: Add dirty bitmap initially all set support
bibo-mao Jul 9, 2024
0315bc3
LoongArch: KVM: Mark page accessed and dirty with page ref added
bibo-mao Jul 9, 2024
6c3427b
LoongArch: KVM: always make pte young in page map's fast path
Jul 9, 2024
dc5cdbf
LoongArch: KVM: Add PV steal time support in host side
bibo-mao Jul 9, 2024
cb400d8
LoongArch: KVM: Add PV steal time support in guest side
bibo-mao Jul 9, 2024
e7d2088
perf kvm: Add kvm-stat for loongarch64
bibo-mao Jul 10, 2024
ebff70a
KVM: Discard zero mask with function kvm_dirty_ring_reset
bibo-mao Jun 13, 2024
d7db865
LoongArch: KVM: Invalidate guest steal time address on vCPU reset
bibo-mao Aug 26, 2024
e14f888
LoongArch: Revert qspinlock to test-and-set simple lock on VM
bibo-mao Sep 11, 2024
076346a
LoongArch: KVM: Add VM feature detection function
bibo-mao Sep 11, 2024
a65036e
LoongArch: KVM: Add Binary Translation extension support
bibo-mao Sep 11, 2024
f1b7ffd
LoongArch: KVM: Add vm migration support for LBT registers
bibo-mao Sep 11, 2024
9225ae2
LoongArch: KVM: Add PMU support for guest
gaosong-loongson Sep 12, 2024
f90bf7f
LoongArch: KVM: Enable paravirt feature control from VMM
bibo-mao Sep 12, 2024
1dd2c49
LoongArch: KVM: Implement function kvm_para_has_feature()
bibo-mao Sep 12, 2024
dece713
LoongArch: KVM: Add cpucfg area for kvm hypervisor
bibo-mao May 6, 2024
d504e8a
KVM: Introduce vcpu->wants_to_run
dmatlack May 3, 2024
f622042
KVM: Delete the now unused kvm_arch_sched_in()
sean-jc May 22, 2024
f6ad22a
KVM: Convert KVM_ARCH_WANT_MMU_NOTIFIER to CONFIG_KVM_GENERIC_MMU_NOT…
sean-jc Oct 27, 2023
908c2db
KVM: define __KVM_HAVE_GUEST_DEBUG unconditionally
bonzini Jan 11, 2024
9e4b44c
LoongArch: KVM: Add vcpu mapping from physical cpuid
bibo-mao May 6, 2024
9cf47ab
KVM: delete .change_pte MMU notifier callback
bonzini Apr 5, 2024
552e299
LoongArch: KVM: Remove undefined a6 argument comment for kvm_hypercall()
Aug 7, 2024
6213ed3
kvm: replace __KVM_HAVE_READONLY_MEM with Kconfig symbol
bonzini Jan 11, 2024
8bf1ec3
LoongArch: KVM: Remove unnecessary CSR register saving during enter g…
bibo-mao Mar 6, 2024
56a336e
fix the compile error
lixianglai Sep 27, 2024
46ad88e
LoongArch:Improve hardware page walk & Set pte with default GLOBAL
zhangtianyang-zty Oct 30, 2024
9abc805
revert "kvm: replace __KVM_HAVE_READONLY_MEM with Kconfig symbol"
lixianglai Oct 26, 2024
0c27adf
revert "KVM: delete .change_pte MMU notifier callback"
lixianglai Oct 26, 2024
b0f457e
revert "KVM: define __KVM_HAVE_GUEST_DEBUG unconditionally"
lixianglai Oct 26, 2024
d31365c
revert "KVM: Convert KVM_ARCH_WANT_MMU_NOTIFIER to CONFIG_KVM_GENERIC…
lixianglai Oct 26, 2024
a844e58
revert "KVM: Delete the now unused kvm_arch_sched_in()"
lixianglai Oct 26, 2024
104bf6c
revert "KVM: Introduce vcpu->wants_to_run"
lixianglai Oct 26, 2024
0901edd
LoongArch: Fix cpu hotplug issue
bibo-mao Oct 21, 2024
b57994a
loongarch/kvm: fix pch pic spinlock dead lock
lixianglai Nov 4, 2024
dfe63cd
drivers/iommu: add iommu support
lixianglai Aug 8, 2024
4f8db7a
arch/loongarch/kvm: Fix extioi restart issue
lixianglai Dec 18, 2024
61f4537
driver/iommu: Fixed multiple vfio devices not working properly
lixianglai Dec 27, 2024
19f1aea
LoongArch:LSVZ: Clear LLBCTL if secondary mmu mapping is changed
bibo-mao Jan 2, 2025
a4fa0b3
LoongArch: KVM: enable ptw for kvm
lixianglai Jan 9, 2025
9686161
LoongArch: fix compile error when enable CONFIG_PARAVIRT
lixianglai Jan 10, 2025
f234b07
LoongArch: KVM: Add reset function for irqchip
lixianglai Feb 5, 2025
4202825
drivers/iommu: Fixed the VFIO physical machine crash problem
lixianglai Feb 7, 2025
b9c7894
LoongArch: KVM: Fixed VM migration failure after ptw was enabled
lixianglai Feb 14, 2025
d8f7ae1
LoongArch: KVM: add virt extioi cpu encode support
lixianglai Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Documentation/admin-guide/kernel-parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3939,9 +3939,10 @@
vulnerability. System may allow data leaks with this
option.

no-steal-acc [X86,PV_OPS,ARM64,PPC/PSERIES] Disable paravirtualized
steal time accounting. steal time is computed, but
won't influence scheduler behaviour
no-steal-acc [X86,PV_OPS,ARM64,PPC/PSERIES,RISCV,LOONGARCH,EARLY]
Disable paravirtualized steal time accounting. steal time
is computed, but won't influence scheduler behaviour


nosync [HW,M68K] Disables sync negotiation for all devices.

Expand Down
31 changes: 31 additions & 0 deletions arch/loongarch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,26 @@ config RANDOMIZE_BASE_MAX_OFFSET

This is limited by the size of the lower address memory, 256MB.

config PARAVIRT
bool "Enable paravirtualization code"
depends on AS_HAS_LVZ_EXTENSION
help
This changes the kernel so it can modify itself when it is run
under a hypervisor, potentially improving performance significantly
over full virtualization. However, when run without a hypervisor
the kernel is theoretically slower and slightly larger.

config PARAVIRT_TIME_ACCOUNTING
bool "Paravirtual steal time accounting"
depends on PARAVIRT
help
Select this option to enable fine granularity task steal time
accounting. Time spent executing other tasks in parallel with
the current vCPU is discounted from the vCPU power. To account for
that, there can be a small performance impact.

If in doubt, say N here.

endmenu

config ARCH_SELECT_MEMORY_MODEL
Expand Down Expand Up @@ -680,6 +700,17 @@ source "drivers/cpufreq/Kconfig"
source "kernel/power/Kconfig"
source "drivers/acpi/Kconfig"

config PARAVIRT_TIME_ACCOUNTING
bool "Paravirtual steal time accounting"
depends on PARAVIRT
help
Select this option to enable fine granularity task steal time
accounting. Time spent executing other tasks in parallel with
the current vCPU is discounted from the vCPU power. To account for
that, there can be a small performance impact.

If in doubt, say N here.

endmenu

source "arch/loongarch/kvm/Kconfig"
3 changes: 3 additions & 0 deletions arch/loongarch/configs/loongson3_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2204,3 +2204,6 @@ CONFIG_RCU_CPU_STALL_TIMEOUT=60
# CONFIG_STRICT_DEVMEM is not set
# CONFIG_RUNTIME_TESTING_MENU is not set
CONFIG_UNWINDER_ORC=y
CONFIG_CMDLINE_EXTEND=y
CONFIG_LOONGARCH_IOMMU=m
CONFIG_CMDLINE="vfio_iommu_type1.allow_unsafe_interrupts=1 nokaslr"
1 change: 0 additions & 1 deletion arch/loongarch/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ generic-y += mcs_spinlock.h
generic-y += parport.h
generic-y += early_ioremap.h
generic-y += qrwlock.h
generic-y += qspinlock.h
generic-y += rwsem.h
generic-y += segment.h
generic-y += user.h
Expand Down
36 changes: 36 additions & 0 deletions arch/loongarch/include/asm/device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Arch specific extensions to struct device
*
* This file is released under the GPLv2
* Copyright (C) 2020 Loongson Technology Corporation Limited
*/
#ifndef _ASM_LOONGARCH_DEVICE_H
#define _ASM_LOONGARCH_DEVICE_H

struct dev_archdata {
/* hook for IOMMU specific extension */
void *iommu;
struct bus_dma_region *dma_range_map;
/*
* On some old 7A chipset, dma address is different from physical
* address, the main difference is that node id. For dma address
* node id starts from bit 36, physical node id starts from
* bit 44. The remaining address below node id is the same.
*/
unsigned long dma_node_mask;
unsigned int dma_node_off;
};

struct pdev_archdata {
};

struct dma_domain {
struct list_head node;
const struct dma_map_ops *dma_ops;
int domain_nr;
};
void add_dma_domain(struct dma_domain *domain);
void del_dma_domain(struct dma_domain *domain);

#endif /* _ASM_LOONGARCH_DEVICE_H*/
9 changes: 5 additions & 4 deletions arch/loongarch/include/asm/kvm_csr.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
: [val] "+r" (__v) \
: [reg] "i" (csr) \
: "memory"); \
__v; \
})

#define gcsr_xchg(v, m, csr) \
Expand Down Expand Up @@ -181,6 +182,8 @@ __BUILD_GCSR_OP(tlbidx)
#define kvm_save_hw_gcsr(csr, gid) (csr->csrs[gid] = gcsr_read(gid))
#define kvm_restore_hw_gcsr(csr, gid) (gcsr_write(csr->csrs[gid], gid))

#define kvm_read_clear_hw_gcsr(csr, gid) (csr->csrs[gid] = gcsr_write(0, gid))

int kvm_emu_iocsr(larch_inst inst, struct kvm_run *run, struct kvm_vcpu *vcpu);

static __always_inline unsigned long kvm_read_sw_gcsr(struct loongarch_csrs *csr, int gid)
Expand Down Expand Up @@ -208,9 +211,7 @@ static __always_inline void kvm_change_sw_gcsr(struct loongarch_csrs *csr,
csr->csrs[gid] |= val & _mask;
}

#define KVM_PMU_PLV_ENABLE (CSR_PERFCTRL_PLV0 | \
CSR_PERFCTRL_PLV1 | \
CSR_PERFCTRL_PLV2 | \
CSR_PERFCTRL_PLV3)
#define KVM_PMU_EVENT_ENABLED (CSR_PERFCTRL_PLV0 | CSR_PERFCTRL_PLV1 | \
CSR_PERFCTRL_PLV2 | CSR_PERFCTRL_PLV3)

#endif /* __ASM_LOONGARCH_KVM_CSR_H__ */
118 changes: 118 additions & 0 deletions arch/loongarch/include/asm/kvm_extioi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2024 Loongson Technology Corporation Limited
*/

#ifndef LOONGARCH_EXTIOI_H
#define LOONGARCH_EXTIOI_H

#include <kvm/iodev.h>

#define EXTIOI_IRQS 256
#define EXTIOI_ROUTE_MAX_VCPUS 256
#define EXTIOI_IRQS_U8_NUMS (EXTIOI_IRQS / 8)
#define EXTIOI_IRQS_U32_NUMS (EXTIOI_IRQS_U8_NUMS / 4)
#define EXTIOI_IRQS_U64_NUMS (EXTIOI_IRQS_U32_NUMS / 2)
/* map to ipnum per 32 irqs */
#define EXTIOI_IRQS_NODETYPE_COUNT 16

#define EXTIOI_BASE 0x1400
#define EXTIOI_SIZE 0x900

#define EXTIOI_NODETYPE_START 0xa0
#define EXTIOI_NODETYPE_END 0xbf
#define EXTIOI_IPMAP_START 0xc0
#define EXTIOI_IPMAP_END 0xc7
#define EXTIOI_ENABLE_START 0x200
#define EXTIOI_ENABLE_END 0x21f
#define EXTIOI_BOUNCE_START 0x280
#define EXTIOI_BOUNCE_END 0x29f
#define EXTIOI_ISR_START 0x300
#define EXTIOI_ISR_END 0x31f
#define EXTIOI_COREISR_START 0x400
#define EXTIOI_COREISR_END 0x71f
#define EXTIOI_COREMAP_START 0x800
#define EXTIOI_COREMAP_END 0x8ff

#define EIOINTC_VIRT_BASE (0x40000000)
#define EIOINTC_VIRT_SIZE (0x1000)

#define EIOINTC_VIRT_FEATURES (0x0)
#define EIOINTC_HAS_VIRT_EXTENSION (0)
#define EIOINTC_HAS_ENABLE_OPTION (1)
#define EIOINTC_HAS_INT_ENCODE (2)
#define EIOINTC_HAS_CPU_ENCODE (3)
#define EIOINTC_VIRT_HAS_FEATURES ((1U << EIOINTC_HAS_VIRT_EXTENSION) \
| (1U << EIOINTC_HAS_ENABLE_OPTION) \
| (1U << EIOINTC_HAS_INT_ENCODE) \
| (1U << EIOINTC_HAS_CPU_ENCODE))
#define EIOINTC_VIRT_CONFIG (0x4)
#define EIOINTC_ENABLE (1)
#define EIOINTC_ENABLE_INT_ENCODE (2)
#define EIOINTC_ENABLE_CPU_ENCODE (3)

#define LS3A_INTC_IP 8

#define EXTIOI_SW_COREMAP_FLAG (1 << 0)

struct loongarch_extioi {
spinlock_t lock;
struct kvm *kvm;
struct kvm_io_device device;
struct kvm_io_device device_vext;
uint32_t num_cpu;
uint32_t features;
uint32_t status;

/* hardware state */
union nodetype {
u64 reg_u64[EXTIOI_IRQS_NODETYPE_COUNT / 4];
u32 reg_u32[EXTIOI_IRQS_NODETYPE_COUNT / 2];
uint16_t reg_u16[EXTIOI_IRQS_NODETYPE_COUNT];
u8 reg_u8[EXTIOI_IRQS_NODETYPE_COUNT * 2];
} nodetype;

/* one bit shows the state of one irq */
union bounce {
u64 reg_u64[EXTIOI_IRQS_U64_NUMS];
u32 reg_u32[EXTIOI_IRQS_U32_NUMS];
u8 reg_u8[EXTIOI_IRQS_U8_NUMS];
} bounce;

union isr {
u64 reg_u64[EXTIOI_IRQS_U64_NUMS];
u32 reg_u32[EXTIOI_IRQS_U32_NUMS];
u8 reg_u8[EXTIOI_IRQS_U8_NUMS];
} isr;
union coreisr {
u64 reg_u64[EXTIOI_ROUTE_MAX_VCPUS][EXTIOI_IRQS_U64_NUMS];
u32 reg_u32[EXTIOI_ROUTE_MAX_VCPUS][EXTIOI_IRQS_U32_NUMS];
u8 reg_u8[EXTIOI_ROUTE_MAX_VCPUS][EXTIOI_IRQS_U8_NUMS];
} coreisr;
union enable {
u64 reg_u64[EXTIOI_IRQS_U64_NUMS];
u32 reg_u32[EXTIOI_IRQS_U32_NUMS];
u8 reg_u8[EXTIOI_IRQS_U8_NUMS];
} enable;

/* use one byte to config ipmap for 32 irqs at once */
union ipmap {
u64 reg_u64;
u32 reg_u32[EXTIOI_IRQS_U32_NUMS / 4];
u8 reg_u8[EXTIOI_IRQS_U8_NUMS / 4];
} ipmap;
/* use one byte to config coremap for one irq */
union coremap {
u64 reg_u64[EXTIOI_IRQS / 8];
u32 reg_u32[EXTIOI_IRQS / 4];
u8 reg_u8[EXTIOI_IRQS];
} coremap;

DECLARE_BITMAP(sw_coreisr[EXTIOI_ROUTE_MAX_VCPUS][LS3A_INTC_IP], EXTIOI_IRQS);
uint8_t sw_coremap[EXTIOI_IRQS];
};

void extioi_set_irq(struct loongarch_extioi *s, int irq, int level);
int kvm_loongarch_register_extioi_device(void);
int kvm_loongarch_reset_extioi(struct kvm *kvm);
#endif /* LOONGARCH_EXTIOI_H */
Loading
Loading