* [PATCH v2 7/7] KVM: Convert kvm_for_each_vcpu() to using xa_for_each_range()
From: Marc Zyngier @ 2021-11-16 16:04 UTC (permalink / raw)
To: kvm, linux-mips, kvmarm, linuxppc-dev, Paolo Bonzini
Cc: Juergen Gross, Huacai Chen, Janosch Frank, David Hildenbrand,
Sean Christopherson, Anup Patel, Philippe Mathieu-Daudé,
Nicholas Piggin, Christian Borntraeger, Aleksandar Markovic,
Paul Mackerras, James Morse, kernel-team, Claudio Imbrenda,
Alexandru Elisei, Suzuki K Poulose
In-Reply-To: <20211116160403.4074052-1-maz@kernel.org>
Now that the vcpu array is backed by an xarray, use the optimised
iterator that matches the underlying data structure.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
include/linux/kvm_host.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index dc635fbfd901..d20e33378c63 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -705,11 +705,9 @@ static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
return xa_load(&kvm->vcpu_array, i);
}
-#define kvm_for_each_vcpu(idx, vcpup, kvm) \
- for (idx = 0; \
- idx < atomic_read(&kvm->online_vcpus) && \
- (vcpup = kvm_get_vcpu(kvm, idx)) != NULL; \
- idx++)
+#define kvm_for_each_vcpu(idx, vcpup, kvm) \
+ xa_for_each_range(&kvm->vcpu_array, idx, vcpup, 0, \
+ (atomic_read(&kvm->online_vcpus) - 1))
static inline struct kvm_vcpu *kvm_get_vcpu_by_id(struct kvm *kvm, int id)
{
--
2.30.2
^ permalink raw reply related
* [PATCH v2 6/7] KVM: Use 'unsigned long' as kvm_for_each_vcpu()'s index
From: Marc Zyngier @ 2021-11-16 16:04 UTC (permalink / raw)
To: kvm, linux-mips, kvmarm, linuxppc-dev, Paolo Bonzini
Cc: Juergen Gross, Huacai Chen, Janosch Frank, David Hildenbrand,
Sean Christopherson, Anup Patel, Philippe Mathieu-Daudé,
Nicholas Piggin, Christian Borntraeger, Aleksandar Markovic,
Paul Mackerras, James Morse, kernel-team, Claudio Imbrenda,
Alexandru Elisei, Suzuki K Poulose
In-Reply-To: <20211116160403.4074052-1-maz@kernel.org>
Everywhere we use kvm_for_each_vpcu(), we use an int as the vcpu
index. Unfortunately, we're about to move rework the iterator,
which requires this to be upgrade to an unsigned long.
Let's bite the bullet and repaint all of it in one go.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/kvm/arch_timer.c | 8 ++++----
arch/arm64/kvm/arm.c | 6 +++---
arch/arm64/kvm/pmu-emul.c | 2 +-
arch/arm64/kvm/psci.c | 6 +++---
arch/arm64/kvm/reset.c | 2 +-
arch/arm64/kvm/vgic/vgic-init.c | 10 ++++++----
arch/arm64/kvm/vgic/vgic-kvm-device.c | 2 +-
arch/arm64/kvm/vgic/vgic-mmio-v2.c | 3 +--
arch/arm64/kvm/vgic/vgic-mmio-v3.c | 7 ++++---
arch/arm64/kvm/vgic/vgic-v3.c | 4 ++--
arch/arm64/kvm/vgic/vgic-v4.c | 5 +++--
arch/arm64/kvm/vgic/vgic.c | 2 +-
arch/powerpc/kvm/book3s_32_mmu.c | 2 +-
arch/powerpc/kvm/book3s_64_mmu.c | 2 +-
arch/powerpc/kvm/book3s_hv.c | 8 ++++----
arch/powerpc/kvm/book3s_pr.c | 2 +-
arch/powerpc/kvm/book3s_xics.c | 6 +++---
arch/powerpc/kvm/book3s_xics.h | 2 +-
arch/powerpc/kvm/book3s_xive.c | 15 +++++++++------
arch/powerpc/kvm/book3s_xive.h | 4 ++--
arch/powerpc/kvm/book3s_xive_native.c | 8 ++++----
arch/powerpc/kvm/e500_emulate.c | 2 +-
arch/riscv/kvm/vcpu_sbi.c | 2 +-
arch/riscv/kvm/vmid.c | 2 +-
arch/s390/kvm/interrupt.c | 2 +-
arch/s390/kvm/kvm-s390.c | 21 +++++++++++----------
arch/s390/kvm/kvm-s390.h | 4 ++--
arch/x86/kvm/hyperv.c | 7 ++++---
arch/x86/kvm/i8254.c | 2 +-
arch/x86/kvm/i8259.c | 5 +++--
arch/x86/kvm/ioapic.c | 4 ++--
arch/x86/kvm/irq_comm.c | 7 ++++---
arch/x86/kvm/kvm_onhyperv.c | 3 ++-
arch/x86/kvm/lapic.c | 6 +++---
arch/x86/kvm/svm/avic.c | 2 +-
arch/x86/kvm/svm/sev.c | 3 ++-
arch/x86/kvm/x86.c | 21 +++++++++++----------
include/linux/kvm_host.h | 2 +-
virt/kvm/kvm_main.c | 13 +++++++------
39 files changed, 114 insertions(+), 100 deletions(-)
diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index 3df67c127489..d6f4114f1d11 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -750,7 +750,7 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu)
/* Make the updates of cntvoff for all vtimer contexts atomic */
static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff)
{
- int i;
+ unsigned long i;
struct kvm *kvm = vcpu->kvm;
struct kvm_vcpu *tmp;
@@ -1189,8 +1189,8 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)
static bool timer_irqs_are_valid(struct kvm_vcpu *vcpu)
{
- int vtimer_irq, ptimer_irq;
- int i, ret;
+ int vtimer_irq, ptimer_irq, ret;
+ unsigned long i;
vtimer_irq = vcpu_vtimer(vcpu)->irq.irq;
ret = kvm_vgic_set_owner(vcpu, vtimer_irq, vcpu_vtimer(vcpu));
@@ -1297,7 +1297,7 @@ void kvm_timer_init_vhe(void)
static void set_timer_irqs(struct kvm *kvm, int vtimer_irq, int ptimer_irq)
{
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
kvm_for_each_vcpu(i, vcpu, kvm) {
vcpu_vtimer(vcpu)->irq.irq = vtimer_irq;
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 29942d8c357c..6177b0c882ea 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -624,7 +624,7 @@ bool kvm_arch_intc_initialized(struct kvm *kvm)
void kvm_arm_halt_guest(struct kvm *kvm)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
kvm_for_each_vcpu(i, vcpu, kvm)
@@ -634,7 +634,7 @@ void kvm_arm_halt_guest(struct kvm *kvm)
void kvm_arm_resume_guest(struct kvm *kvm)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
kvm_for_each_vcpu(i, vcpu, kvm) {
@@ -2020,7 +2020,7 @@ static int finalize_hyp_mode(void)
struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr)
{
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
mpidr &= MPIDR_HWID_BITMASK;
kvm_for_each_vcpu(i, vcpu, kvm) {
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index a5e4bbf5e68f..0404357705a8 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -900,7 +900,7 @@ static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)
*/
static bool pmu_irq_is_valid(struct kvm *kvm, int irq)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
kvm_for_each_vcpu(i, vcpu, kvm) {
diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c
index 74c47d420253..ed675fce8fb7 100644
--- a/arch/arm64/kvm/psci.c
+++ b/arch/arm64/kvm/psci.c
@@ -121,8 +121,8 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
{
- int i, matching_cpus = 0;
- unsigned long mpidr;
+ int matching_cpus = 0;
+ unsigned long i, mpidr;
unsigned long target_affinity;
unsigned long target_affinity_mask;
unsigned long lowest_affinity_level;
@@ -164,7 +164,7 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
static void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *tmp;
/*
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index 426bd7fbc3fd..97de30a79770 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -170,7 +170,7 @@ static bool vcpu_allowed_register_width(struct kvm_vcpu *vcpu)
{
struct kvm_vcpu *tmp;
bool is32bit;
- int i;
+ unsigned long i;
is32bit = vcpu_has_feature(vcpu, KVM_ARM_VCPU_EL1_32BIT);
if (!cpus_have_const_cap(ARM64_HAS_32BIT_EL1) && is32bit)
diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c
index 0a06d0648970..a7382bda9676 100644
--- a/arch/arm64/kvm/vgic/vgic-init.c
+++ b/arch/arm64/kvm/vgic/vgic-init.c
@@ -70,8 +70,9 @@ void kvm_vgic_early_init(struct kvm *kvm)
*/
int kvm_vgic_create(struct kvm *kvm, u32 type)
{
- int i, ret;
struct kvm_vcpu *vcpu;
+ unsigned long i;
+ int ret;
if (irqchip_in_kernel(kvm))
return -EEXIST;
@@ -255,7 +256,8 @@ int vgic_init(struct kvm *kvm)
{
struct vgic_dist *dist = &kvm->arch.vgic;
struct kvm_vcpu *vcpu;
- int ret = 0, i, idx;
+ int ret = 0, i;
+ unsigned long idx;
if (vgic_initialized(kvm))
return 0;
@@ -308,7 +310,7 @@ int vgic_init(struct kvm *kvm)
goto out;
}
- kvm_for_each_vcpu(i, vcpu, kvm)
+ kvm_for_each_vcpu(idx, vcpu, kvm)
kvm_vgic_vcpu_enable(vcpu);
ret = kvm_vgic_setup_default_irq_routing(kvm);
@@ -370,7 +372,7 @@ void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
static void __kvm_vgic_destroy(struct kvm *kvm)
{
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
vgic_debug_destroy(kvm);
diff --git a/arch/arm64/kvm/vgic/vgic-kvm-device.c b/arch/arm64/kvm/vgic/vgic-kvm-device.c
index 0d000d2fe8d2..c6d52a1fd9c8 100644
--- a/arch/arm64/kvm/vgic/vgic-kvm-device.c
+++ b/arch/arm64/kvm/vgic/vgic-kvm-device.c
@@ -325,7 +325,7 @@ void unlock_all_vcpus(struct kvm *kvm)
bool lock_all_vcpus(struct kvm *kvm)
{
struct kvm_vcpu *tmp_vcpu;
- int c;
+ unsigned long c;
/*
* Any time a vcpu is run, vcpu_load is called which tries to grab the
diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v2.c b/arch/arm64/kvm/vgic/vgic-mmio-v2.c
index 5f9014ae595b..12e4c223e6b8 100644
--- a/arch/arm64/kvm/vgic/vgic-mmio-v2.c
+++ b/arch/arm64/kvm/vgic/vgic-mmio-v2.c
@@ -113,9 +113,8 @@ static void vgic_mmio_write_sgir(struct kvm_vcpu *source_vcpu,
int intid = val & 0xf;
int targets = (val >> 16) & 0xff;
int mode = (val >> 24) & 0x03;
- int c;
struct kvm_vcpu *vcpu;
- unsigned long flags;
+ unsigned long flags, c;
switch (mode) {
case 0x0: /* as specified by targets */
diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c
index bf7ec4a78497..82906cb3f713 100644
--- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c
+++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c
@@ -754,7 +754,8 @@ static void vgic_unregister_redist_iodev(struct kvm_vcpu *vcpu)
static int vgic_register_all_redist_iodevs(struct kvm *kvm)
{
struct kvm_vcpu *vcpu;
- int c, ret = 0;
+ unsigned long c;
+ int ret = 0;
kvm_for_each_vcpu(c, vcpu, kvm) {
ret = vgic_register_redist_iodev(vcpu);
@@ -995,10 +996,10 @@ void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg, bool allow_group1)
struct kvm_vcpu *c_vcpu;
u16 target_cpus;
u64 mpidr;
- int sgi, c;
+ int sgi;
int vcpu_id = vcpu->vcpu_id;
bool broadcast;
- unsigned long flags;
+ unsigned long c, flags;
sgi = (reg & ICC_SGI1R_SGI_ID_MASK) >> ICC_SGI1R_SGI_ID_SHIFT;
broadcast = reg & BIT_ULL(ICC_SGI1R_IRQ_ROUTING_MODE_BIT);
diff --git a/arch/arm64/kvm/vgic/vgic-v3.c b/arch/arm64/kvm/vgic/vgic-v3.c
index 04f62c4b07fb..5fedaee15e72 100644
--- a/arch/arm64/kvm/vgic/vgic-v3.c
+++ b/arch/arm64/kvm/vgic/vgic-v3.c
@@ -542,13 +542,13 @@ int vgic_v3_map_resources(struct kvm *kvm)
struct vgic_dist *dist = &kvm->arch.vgic;
struct kvm_vcpu *vcpu;
int ret = 0;
- int c;
+ unsigned long c;
kvm_for_each_vcpu(c, vcpu, kvm) {
struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
if (IS_VGIC_ADDR_UNDEF(vgic_cpu->rd_iodev.base_addr)) {
- kvm_debug("vcpu %d redistributor base not set\n", c);
+ kvm_debug("vcpu %ld redistributor base not set\n", c);
return -ENXIO;
}
}
diff --git a/arch/arm64/kvm/vgic/vgic-v4.c b/arch/arm64/kvm/vgic/vgic-v4.c
index 772dd15a22c7..ad06ba6c9b00 100644
--- a/arch/arm64/kvm/vgic/vgic-v4.c
+++ b/arch/arm64/kvm/vgic/vgic-v4.c
@@ -189,7 +189,7 @@ void vgic_v4_configure_vsgis(struct kvm *kvm)
{
struct vgic_dist *dist = &kvm->arch.vgic;
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
kvm_arm_halt_guest(kvm);
@@ -235,7 +235,8 @@ int vgic_v4_init(struct kvm *kvm)
{
struct vgic_dist *dist = &kvm->arch.vgic;
struct kvm_vcpu *vcpu;
- int i, nr_vcpus, ret;
+ int nr_vcpus, ret;
+ unsigned long i;
if (!kvm_vgic_global_state.has_gicv4)
return 0; /* Nothing to see here... move along. */
diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c
index 5dad4996cfb2..9b98876a8a93 100644
--- a/arch/arm64/kvm/vgic/vgic.c
+++ b/arch/arm64/kvm/vgic/vgic.c
@@ -990,7 +990,7 @@ int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu)
void vgic_kick_vcpus(struct kvm *kvm)
{
struct kvm_vcpu *vcpu;
- int c;
+ unsigned long c;
/*
* We've injected an interrupt, time to find out who deserves
diff --git a/arch/powerpc/kvm/book3s_32_mmu.c b/arch/powerpc/kvm/book3s_32_mmu.c
index 3fbd570f9c1e..0215f32932a9 100644
--- a/arch/powerpc/kvm/book3s_32_mmu.c
+++ b/arch/powerpc/kvm/book3s_32_mmu.c
@@ -337,7 +337,7 @@ static void kvmppc_mmu_book3s_32_mtsrin(struct kvm_vcpu *vcpu, u32 srnum,
static void kvmppc_mmu_book3s_32_tlbie(struct kvm_vcpu *vcpu, ulong ea, bool large)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *v;
/* flush this VA on all cpus */
diff --git a/arch/powerpc/kvm/book3s_64_mmu.c b/arch/powerpc/kvm/book3s_64_mmu.c
index feee40cb2ba1..61290282fd9e 100644
--- a/arch/powerpc/kvm/book3s_64_mmu.c
+++ b/arch/powerpc/kvm/book3s_64_mmu.c
@@ -530,7 +530,7 @@ static void kvmppc_mmu_book3s_64_tlbie(struct kvm_vcpu *vcpu, ulong va,
bool large)
{
u64 mask = 0xFFFFFFFFFULL;
- long i;
+ unsigned long i;
struct kvm_vcpu *v;
dprintk("KVM MMU: tlbie(0x%lx)\n", va);
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 7b74fc0a986b..32873c6985f9 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1993,7 +1993,7 @@ static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, u64 new_lpcr,
*/
if ((new_lpcr & LPCR_ILE) != (vc->lpcr & LPCR_ILE)) {
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
kvm_for_each_vcpu(i, vcpu, kvm) {
if (vcpu->arch.vcore != vc)
@@ -4786,8 +4786,8 @@ static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
{
struct kvm_memslots *slots;
struct kvm_memory_slot *memslot;
- int i, r;
- unsigned long n;
+ int r;
+ unsigned long n, i;
unsigned long *buf, *p;
struct kvm_vcpu *vcpu;
@@ -5861,7 +5861,7 @@ static int kvmhv_svm_off(struct kvm *kvm)
int mmu_was_ready;
int srcu_idx;
int ret = 0;
- int i;
+ unsigned long i;
if (!(kvm->arch.secure_guest & KVMPPC_SECURE_INIT_START))
return ret;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 6bc9425acb32..bb0612c49b92 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -428,7 +428,7 @@ static int kvmppc_core_check_requests_pr(struct kvm_vcpu *vcpu)
/************* MMU Notifiers *************/
static bool do_kvm_unmap_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
{
- long i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
kvm_for_each_vcpu(i, vcpu, kvm)
diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index ebd5d920de8c..9cc466006e8b 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -942,8 +942,8 @@ static int xics_debug_show(struct seq_file *m, void *private)
struct kvmppc_xics *xics = m->private;
struct kvm *kvm = xics->kvm;
struct kvm_vcpu *vcpu;
- int icsid, i;
- unsigned long flags;
+ int icsid;
+ unsigned long flags, i;
unsigned long t_rm_kick_vcpu, t_rm_check_resend;
unsigned long t_rm_notify_eoi;
unsigned long t_reject, t_check_resend;
@@ -1340,7 +1340,7 @@ static int xics_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
static void kvmppc_xics_release(struct kvm_device *dev)
{
struct kvmppc_xics *xics = dev->private;
- int i;
+ unsigned long i;
struct kvm *kvm = xics->kvm;
struct kvm_vcpu *vcpu;
diff --git a/arch/powerpc/kvm/book3s_xics.h b/arch/powerpc/kvm/book3s_xics.h
index 6231f76bdd66..8e4c79e2fcd8 100644
--- a/arch/powerpc/kvm/book3s_xics.h
+++ b/arch/powerpc/kvm/book3s_xics.h
@@ -116,7 +116,7 @@ static inline struct kvmppc_icp *kvmppc_xics_find_server(struct kvm *kvm,
u32 nr)
{
struct kvm_vcpu *vcpu = NULL;
- int i;
+ unsigned long i;
kvm_for_each_vcpu(i, vcpu, kvm) {
if (vcpu->arch.icp && nr == vcpu->arch.icp->server_num)
diff --git a/arch/powerpc/kvm/book3s_xive.c b/arch/powerpc/kvm/book3s_xive.c
index 225008882958..e216c068075d 100644
--- a/arch/powerpc/kvm/book3s_xive.c
+++ b/arch/powerpc/kvm/book3s_xive.c
@@ -368,7 +368,8 @@ static int xive_check_provisioning(struct kvm *kvm, u8 prio)
{
struct kvmppc_xive *xive = kvm->arch.xive;
struct kvm_vcpu *vcpu;
- int i, rc;
+ unsigned long i;
+ int rc;
lockdep_assert_held(&xive->lock);
@@ -439,7 +440,8 @@ static int xive_try_pick_queue(struct kvm_vcpu *vcpu, u8 prio)
int kvmppc_xive_select_target(struct kvm *kvm, u32 *server, u8 prio)
{
struct kvm_vcpu *vcpu;
- int i, rc;
+ unsigned long i;
+ int rc;
/* Locate target server */
vcpu = kvmppc_xive_find_server(kvm, *server);
@@ -1519,7 +1521,8 @@ static void xive_pre_save_queue(struct kvmppc_xive *xive, struct xive_q *q)
static void xive_pre_save_scan(struct kvmppc_xive *xive)
{
struct kvm_vcpu *vcpu = NULL;
- int i, j;
+ unsigned long i;
+ int j;
/*
* See comment in xive_get_source() about how this
@@ -1700,7 +1703,7 @@ static bool xive_check_delayed_irq(struct kvmppc_xive *xive, u32 irq)
{
struct kvm *kvm = xive->kvm;
struct kvm_vcpu *vcpu = NULL;
- int i;
+ unsigned long i;
kvm_for_each_vcpu(i, vcpu, kvm) {
struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
@@ -2037,7 +2040,7 @@ static void kvmppc_xive_release(struct kvm_device *dev)
struct kvmppc_xive *xive = dev->private;
struct kvm *kvm = xive->kvm;
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
pr_devel("Releasing xive device\n");
@@ -2291,7 +2294,7 @@ static int xive_debug_show(struct seq_file *m, void *private)
u64 t_vm_h_cppr = 0;
u64 t_vm_h_eoi = 0;
u64 t_vm_h_ipi = 0;
- unsigned int i;
+ unsigned long i;
if (!kvm)
return 0;
diff --git a/arch/powerpc/kvm/book3s_xive.h b/arch/powerpc/kvm/book3s_xive.h
index e6a9651c6f1e..09d0657596c3 100644
--- a/arch/powerpc/kvm/book3s_xive.h
+++ b/arch/powerpc/kvm/book3s_xive.h
@@ -199,7 +199,7 @@ struct kvmppc_xive_vcpu {
static inline struct kvm_vcpu *kvmppc_xive_find_server(struct kvm *kvm, u32 nr)
{
struct kvm_vcpu *vcpu = NULL;
- int i;
+ unsigned long i;
kvm_for_each_vcpu(i, vcpu, kvm) {
if (vcpu->arch.xive_vcpu && nr == vcpu->arch.xive_vcpu->server_num)
@@ -240,7 +240,7 @@ static inline u32 kvmppc_xive_vp(struct kvmppc_xive *xive, u32 server)
static inline bool kvmppc_xive_vp_in_use(struct kvm *kvm, u32 vp_id)
{
struct kvm_vcpu *vcpu = NULL;
- int i;
+ unsigned long i;
kvm_for_each_vcpu(i, vcpu, kvm) {
if (vcpu->arch.xive_vcpu && vp_id == vcpu->arch.xive_vcpu->vp_id)
diff --git a/arch/powerpc/kvm/book3s_xive_native.c b/arch/powerpc/kvm/book3s_xive_native.c
index 99db9ac49901..561a5bfe0468 100644
--- a/arch/powerpc/kvm/book3s_xive_native.c
+++ b/arch/powerpc/kvm/book3s_xive_native.c
@@ -807,7 +807,7 @@ static int kvmppc_xive_reset(struct kvmppc_xive *xive)
{
struct kvm *kvm = xive->kvm;
struct kvm_vcpu *vcpu;
- unsigned int i;
+ unsigned long i;
pr_devel("%s\n", __func__);
@@ -916,7 +916,7 @@ static int kvmppc_xive_native_eq_sync(struct kvmppc_xive *xive)
{
struct kvm *kvm = xive->kvm;
struct kvm_vcpu *vcpu;
- unsigned int i;
+ unsigned long i;
pr_devel("%s\n", __func__);
@@ -1017,7 +1017,7 @@ static void kvmppc_xive_native_release(struct kvm_device *dev)
struct kvmppc_xive *xive = dev->private;
struct kvm *kvm = xive->kvm;
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
pr_devel("Releasing xive native device\n");
@@ -1214,7 +1214,7 @@ static int xive_native_debug_show(struct seq_file *m, void *private)
struct kvmppc_xive *xive = m->private;
struct kvm *kvm = xive->kvm;
struct kvm_vcpu *vcpu;
- unsigned int i;
+ unsigned long i;
if (!kvm)
return 0;
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 64eb833e9f02..051102d50c31 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -65,7 +65,7 @@ static int kvmppc_e500_emul_msgsnd(struct kvm_vcpu *vcpu, int rb)
ulong param = vcpu->arch.regs.gpr[rb];
int prio = dbell2prio(rb);
int pir = param & PPC_DBELL_PIR_MASK;
- int i;
+ unsigned long i;
struct kvm_vcpu *cvcpu;
if (prio < 0)
diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c
index eb3c045edf11..fe65bef4eb90 100644
--- a/arch/riscv/kvm/vcpu_sbi.c
+++ b/arch/riscv/kvm/vcpu_sbi.c
@@ -60,7 +60,7 @@ int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run)
static void kvm_sbi_system_shutdown(struct kvm_vcpu *vcpu,
struct kvm_run *run, u32 type)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *tmp;
kvm_for_each_vcpu(i, tmp, vcpu->kvm)
diff --git a/arch/riscv/kvm/vmid.c b/arch/riscv/kvm/vmid.c
index 2c6253b293bc..807228f8f409 100644
--- a/arch/riscv/kvm/vmid.c
+++ b/arch/riscv/kvm/vmid.c
@@ -65,7 +65,7 @@ bool kvm_riscv_stage2_vmid_ver_changed(struct kvm_vmid *vmid)
void kvm_riscv_stage2_vmid_update(struct kvm_vcpu *vcpu)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *v;
struct cpumask hmask;
struct kvm_vmid *vmid = &vcpu->kvm->arch.vmid;
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index c3bd993fdd0c..1aa094810f6d 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -2659,7 +2659,7 @@ static int flic_ais_mode_set_all(struct kvm *kvm, struct kvm_device_attr *attr)
static int flic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
{
int r = 0;
- unsigned int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
switch (attr->group) {
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 4a0f62b03964..b36a886c0421 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -295,7 +295,7 @@ static int kvm_clock_sync(struct notifier_block *notifier, unsigned long val,
{
struct kvm *kvm;
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
unsigned long long *delta = v;
list_for_each_entry(kvm, &vm_list, vm_list) {
@@ -680,7 +680,7 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
static void icpt_operexc_on_all_vcpus(struct kvm *kvm)
{
- unsigned int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
kvm_for_each_vcpu(i, vcpu, kvm) {
@@ -934,7 +934,7 @@ static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu);
void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm)
{
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
kvm_s390_vcpu_block_all(kvm);
@@ -1019,7 +1019,7 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
static void kvm_s390_sync_request_broadcast(struct kvm *kvm, int req)
{
- int cx;
+ unsigned long cx;
struct kvm_vcpu *vcpu;
kvm_for_each_vcpu(cx, vcpu, kvm)
@@ -2204,7 +2204,7 @@ static int kvm_s390_cpus_from_pv(struct kvm *kvm, u16 *rcp, u16 *rrcp)
struct kvm_vcpu *vcpu;
u16 rc, rrc;
int ret = 0;
- int i;
+ unsigned long i;
/*
* We ignore failures and try to destroy as many CPUs as possible.
@@ -2228,7 +2228,8 @@ static int kvm_s390_cpus_from_pv(struct kvm *kvm, u16 *rcp, u16 *rrcp)
static int kvm_s390_cpus_to_pv(struct kvm *kvm, u16 *rc, u16 *rrc)
{
- int i, r = 0;
+ unsigned long i;
+ int r = 0;
u16 dummy;
struct kvm_vcpu *vcpu;
@@ -2927,7 +2928,7 @@ static int sca_switch_to_extended(struct kvm *kvm)
struct bsca_block *old_sca = kvm->arch.sca;
struct esca_block *new_sca;
struct kvm_vcpu *vcpu;
- unsigned int vcpu_idx;
+ unsigned long vcpu_idx;
u32 scaol, scaoh;
if (kvm->arch.use_esca)
@@ -3409,7 +3410,7 @@ static void kvm_gmap_notifier(struct gmap *gmap, unsigned long start,
struct kvm *kvm = gmap->private;
struct kvm_vcpu *vcpu;
unsigned long prefix;
- int i;
+ unsigned long i;
if (gmap_is_shadow(gmap))
return;
@@ -3902,7 +3903,7 @@ void kvm_s390_set_tod_clock(struct kvm *kvm,
{
struct kvm_vcpu *vcpu;
union tod_clock clk;
- int i;
+ unsigned long i;
mutex_lock(&kvm->lock);
preempt_disable();
@@ -4534,7 +4535,7 @@ static void __disable_ibs_on_vcpu(struct kvm_vcpu *vcpu)
static void __disable_ibs_on_all_vcpus(struct kvm *kvm)
{
- unsigned int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
kvm_for_each_vcpu(i, vcpu, kvm) {
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index c07a050d757d..b887fe7a7064 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -357,7 +357,7 @@ int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
static inline void kvm_s390_vcpu_block_all(struct kvm *kvm)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
WARN_ON(!mutex_is_locked(&kvm->lock));
@@ -367,7 +367,7 @@ static inline void kvm_s390_vcpu_block_all(struct kvm *kvm)
static inline void kvm_s390_vcpu_unblock_all(struct kvm *kvm)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
kvm_for_each_vcpu(i, vcpu, kvm)
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 4a555f32885a..e8c18f25814a 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -164,7 +164,7 @@ static int synic_set_sint(struct kvm_vcpu_hv_synic *synic, int sint,
static struct kvm_vcpu *get_vcpu_by_vpidx(struct kvm *kvm, u32 vpidx)
{
struct kvm_vcpu *vcpu = NULL;
- int i;
+ unsigned long i;
if (vpidx >= KVM_MAX_VCPUS)
return NULL;
@@ -1716,7 +1716,8 @@ static __always_inline unsigned long *sparse_set_to_vcpu_mask(
{
struct kvm_hv *hv = to_kvm_hv(kvm);
struct kvm_vcpu *vcpu;
- int i, bank, sbank = 0;
+ int bank, sbank = 0;
+ unsigned long i;
memset(vp_bitmap, 0,
KVM_HV_MAX_SPARSE_VCPU_SET_BITS * sizeof(*vp_bitmap));
@@ -1863,7 +1864,7 @@ static void kvm_send_ipi_to_many(struct kvm *kvm, u32 vector,
.vector = vector
};
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
kvm_for_each_vcpu(i, vcpu, kvm) {
if (vcpu_bitmap && !test_bit(i, vcpu_bitmap))
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index 5a69cce4d72d..0b65a764ed3a 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -242,7 +242,7 @@ static void pit_do_work(struct kthread_work *work)
struct kvm_pit *pit = container_of(work, struct kvm_pit, expired);
struct kvm *kvm = pit->kvm;
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
struct kvm_kpit_state *ps = &pit->pit_state;
if (atomic_read(&ps->reinject) && !atomic_xchg(&ps->irq_ack, 0))
diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c
index 0b80263d46d8..814064d06016 100644
--- a/arch/x86/kvm/i8259.c
+++ b/arch/x86/kvm/i8259.c
@@ -50,7 +50,7 @@ static void pic_unlock(struct kvm_pic *s)
{
bool wakeup = s->wakeup_needed;
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
s->wakeup_needed = false;
@@ -270,7 +270,8 @@ int kvm_pic_read_irq(struct kvm *kvm)
static void kvm_pic_reset(struct kvm_kpic_state *s)
{
- int irq, i;
+ int irq;
+ unsigned long i;
struct kvm_vcpu *vcpu;
u8 edge_irr = s->irr & ~s->elcr;
bool found = false;
diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
index 816a82515dcd..decfa36b7891 100644
--- a/arch/x86/kvm/ioapic.c
+++ b/arch/x86/kvm/ioapic.c
@@ -149,7 +149,7 @@ void kvm_rtc_eoi_tracking_restore_one(struct kvm_vcpu *vcpu)
static void kvm_rtc_eoi_tracking_restore_all(struct kvm_ioapic *ioapic)
{
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
if (RTC_GSI >= IOAPIC_NUM_PINS)
return;
@@ -184,7 +184,7 @@ static bool rtc_irq_check_coalesced(struct kvm_ioapic *ioapic)
static void ioapic_lazy_update_eoi(struct kvm_ioapic *ioapic, int irq)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];
diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c
index d5b72a08e566..39ad02d6dc63 100644
--- a/arch/x86/kvm/irq_comm.c
+++ b/arch/x86/kvm/irq_comm.c
@@ -45,9 +45,9 @@ static int kvm_set_ioapic_irq(struct kvm_kernel_irq_routing_entry *e,
int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
struct kvm_lapic_irq *irq, struct dest_map *dest_map)
{
- int i, r = -1;
+ int r = -1;
struct kvm_vcpu *vcpu, *lowest = NULL;
- unsigned long dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)];
+ unsigned long i, dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)];
unsigned int dest_vcpus = 0;
if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r, dest_map))
@@ -320,7 +320,8 @@ int kvm_set_routing_entry(struct kvm *kvm,
bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq,
struct kvm_vcpu **dest_vcpu)
{
- int i, r = 0;
+ int r = 0;
+ unsigned long i;
struct kvm_vcpu *vcpu;
if (kvm_intr_is_single_vcpu_fast(kvm, irq, dest_vcpu))
diff --git a/arch/x86/kvm/kvm_onhyperv.c b/arch/x86/kvm/kvm_onhyperv.c
index c7db2df50a7a..b469f45e3fe4 100644
--- a/arch/x86/kvm/kvm_onhyperv.c
+++ b/arch/x86/kvm/kvm_onhyperv.c
@@ -33,7 +33,8 @@ int hv_remote_flush_tlb_with_range(struct kvm *kvm,
{
struct kvm_arch *kvm_arch = &kvm->arch;
struct kvm_vcpu *vcpu;
- int ret = 0, i, nr_unique_valid_roots;
+ int ret = 0, nr_unique_valid_roots;
+ unsigned long i;
hpa_t root;
spin_lock(&kvm_arch->hv_root_tdp_lock);
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 759952dd1222..31fa9b6760ea 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -185,7 +185,7 @@ void kvm_recalculate_apic_map(struct kvm *kvm)
{
struct kvm_apic_map *new, *old = NULL;
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
u32 max_id = 255; /* enough space for any xAPIC ID */
/* Read kvm->arch.apic_map_dirty before kvm->arch.apic_map. */
@@ -1172,8 +1172,8 @@ void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct kvm_lapic_irq *irq,
struct kvm_lapic *src = NULL;
struct kvm_apic_map *map;
struct kvm_vcpu *vcpu;
- unsigned long bitmap;
- int i, vcpu_idx;
+ unsigned long bitmap, i;
+ int vcpu_idx;
bool ret;
rcu_read_lock();
diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
index affc0ea98d30..c6e1f07cca28 100644
--- a/arch/x86/kvm/svm/avic.c
+++ b/arch/x86/kvm/svm/avic.c
@@ -293,7 +293,7 @@ static void avic_kick_target_vcpus(struct kvm *kvm, struct kvm_lapic *source,
u32 icrl, u32 icrh)
{
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
kvm_for_each_vcpu(i, vcpu, kvm) {
bool m = kvm_apic_match_dest(vcpu, source,
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 902c52a8dd0c..dfa8cdafe708 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -637,7 +637,8 @@ static int __sev_launch_update_vmsa(struct kvm *kvm, struct kvm_vcpu *vcpu,
static int sev_launch_update_vmsa(struct kvm *kvm, struct kvm_sev_cmd *argp)
{
struct kvm_vcpu *vcpu;
- int i, ret;
+ unsigned long i;
+ int ret;
if (!sev_es_guest(kvm))
return -ENOTTY;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 259f719014c9..abda63a0e381 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2816,7 +2816,7 @@ static void kvm_end_pvclock_update(struct kvm *kvm)
{
struct kvm_arch *ka = &kvm->arch;
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
write_seqcount_end(&ka->pvclock_sc);
raw_spin_unlock_irq(&ka->tsc_write_lock);
@@ -3065,7 +3065,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
static void kvmclock_update_fn(struct work_struct *work)
{
- int i;
+ unsigned long i;
struct delayed_work *dwork = to_delayed_work(work);
struct kvm_arch *ka = container_of(dwork, struct kvm_arch,
kvmclock_update_work);
@@ -5650,7 +5650,7 @@ void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot)
* VM-Exit.
*/
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
kvm_for_each_vcpu(i, vcpu, kvm)
kvm_vcpu_kick(vcpu);
@@ -5918,7 +5918,8 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, void __user *argp)
static int kvm_arch_suspend_notifier(struct kvm *kvm)
{
struct kvm_vcpu *vcpu;
- int i, ret = 0;
+ unsigned long i;
+ int ret = 0;
mutex_lock(&kvm->lock);
kvm_for_each_vcpu(i, vcpu, kvm) {
@@ -8344,7 +8345,8 @@ static void __kvmclock_cpufreq_notifier(struct cpufreq_freqs *freq, int cpu)
{
struct kvm *kvm;
struct kvm_vcpu *vcpu;
- int i, send_ipi = 0;
+ int send_ipi = 0;
+ unsigned long i;
/*
* We allow guests to temporarily run on slowing clocks,
@@ -8517,9 +8519,8 @@ static struct perf_guest_info_callbacks kvm_guest_cbs = {
static void pvclock_gtod_update_fn(struct work_struct *work)
{
struct kvm *kvm;
-
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
mutex_lock(&kvm_lock);
list_for_each_entry(kvm, &vm_list, vm_list)
@@ -11115,7 +11116,7 @@ int kvm_arch_hardware_enable(void)
{
struct kvm *kvm;
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
int ret;
u64 local_tsc;
u64 max_tsc = 0;
@@ -11368,7 +11369,7 @@ static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
static void kvm_free_vcpus(struct kvm *kvm)
{
- unsigned int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
/*
@@ -11614,7 +11615,7 @@ static int kvm_alloc_memslot_metadata(struct kvm *kvm,
void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen)
{
struct kvm_vcpu *vcpu;
- int i;
+ unsigned long i;
/*
* memslots->generation has been incremented.
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index df1b2b183d94..dc635fbfd901 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -714,7 +714,7 @@ static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
static inline struct kvm_vcpu *kvm_get_vcpu_by_id(struct kvm *kvm, int id)
{
struct kvm_vcpu *vcpu = NULL;
- int i;
+ unsigned long i;
if (id < 0)
return NULL;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 9a7bce944427..b85cd9c916d4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -305,8 +305,9 @@ bool kvm_make_all_cpus_request_except(struct kvm *kvm, unsigned int req,
{
struct kvm_vcpu *vcpu;
struct cpumask *cpus;
+ unsigned long i;
bool called;
- int i, me;
+ int me;
me = get_cpu();
@@ -453,7 +454,7 @@ static void kvm_vcpu_destroy(struct kvm_vcpu *vcpu)
void kvm_destroy_vcpus(struct kvm *kvm)
{
- unsigned int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
kvm_for_each_vcpu(i, vcpu, kvm) {
@@ -3449,10 +3450,10 @@ void kvm_vcpu_on_spin(struct kvm_vcpu *me, bool yield_to_kernel_mode)
struct kvm *kvm = me->kvm;
struct kvm_vcpu *vcpu;
int last_boosted_vcpu = me->kvm->last_boosted_vcpu;
+ unsigned long i;
int yielded = 0;
int try = 3;
int pass;
- int i;
kvm_vcpu_set_in_spin_loop(me, true);
/*
@@ -4261,7 +4262,7 @@ static int kvm_vm_ioctl_enable_dirty_log_ring(struct kvm *kvm, u32 size)
static int kvm_vm_ioctl_reset_dirty_pages(struct kvm *kvm)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
int cleared = 0;
@@ -5180,7 +5181,7 @@ static int kvm_clear_stat_per_vm(struct kvm *kvm, size_t offset)
static int kvm_get_stat_per_vcpu(struct kvm *kvm, size_t offset, u64 *val)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
*val = 0;
@@ -5193,7 +5194,7 @@ static int kvm_get_stat_per_vcpu(struct kvm *kvm, size_t offset, u64 *val)
static int kvm_clear_stat_per_vcpu(struct kvm *kvm, size_t offset)
{
- int i;
+ unsigned long i;
struct kvm_vcpu *vcpu;
kvm_for_each_vcpu(i, vcpu, kvm)
--
2.30.2
^ permalink raw reply related
* [PATCH v2 5/7] KVM: Convert the kvm->vcpus array to a xarray
From: Marc Zyngier @ 2021-11-16 16:04 UTC (permalink / raw)
To: kvm, linux-mips, kvmarm, linuxppc-dev, Paolo Bonzini
Cc: Juergen Gross, Huacai Chen, Janosch Frank, David Hildenbrand,
Sean Christopherson, Anup Patel, Philippe Mathieu-Daudé,
Nicholas Piggin, Christian Borntraeger, Aleksandar Markovic,
Paul Mackerras, James Morse, kernel-team, Claudio Imbrenda,
Alexandru Elisei, Suzuki K Poulose
In-Reply-To: <20211116160403.4074052-1-maz@kernel.org>
At least on arm64 and x86, the vcpus array is pretty huge (up to
1024 entries on x86) and is mostly empty in the majority of the cases
(running 1k vcpu VMs is not that common).
This mean that we end-up with a 4kB block of unused memory in the
middle of the kvm structure.
Instead of wasting away this memory, let's use an xarray instead,
which gives us almost the same flexibility as a normal array, but
with a reduced memory usage with smaller VMs.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
include/linux/kvm_host.h | 5 +++--
virt/kvm/kvm_main.c | 15 +++++++++------
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 9a8c997ff9bc..df1b2b183d94 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -29,6 +29,7 @@
#include <linux/refcount.h>
#include <linux/nospec.h>
#include <linux/notifier.h>
+#include <linux/xarray.h>
#include <asm/signal.h>
#include <linux/kvm.h>
@@ -552,7 +553,7 @@ struct kvm {
struct mutex slots_arch_lock;
struct mm_struct *mm; /* userspace tied to this vm */
struct kvm_memslots __rcu *memslots[KVM_ADDRESS_SPACE_NUM];
- struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
+ struct xarray vcpu_array;
/* Used to wait for completion of MMU notifiers. */
spinlock_t mn_invalidate_lock;
@@ -701,7 +702,7 @@ static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
/* Pairs with smp_wmb() in kvm_vm_ioctl_create_vcpu. */
smp_rmb();
- return kvm->vcpus[i];
+ return xa_load(&kvm->vcpu_array, i);
}
#define kvm_for_each_vcpu(idx, vcpup, kvm) \
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 73811c3829a2..9a7bce944427 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -458,7 +458,7 @@ void kvm_destroy_vcpus(struct kvm *kvm)
kvm_for_each_vcpu(i, vcpu, kvm) {
kvm_vcpu_destroy(vcpu);
- kvm->vcpus[i] = NULL;
+ xa_erase(&kvm->vcpu_array, i);
}
atomic_set(&kvm->online_vcpus, 0);
@@ -1063,6 +1063,7 @@ static struct kvm *kvm_create_vm(unsigned long type)
mutex_init(&kvm->slots_arch_lock);
spin_lock_init(&kvm->mn_invalidate_lock);
rcuwait_init(&kvm->mn_memslots_update_rcuwait);
+ xa_init(&kvm->vcpu_array);
INIT_LIST_HEAD(&kvm->devices);
@@ -3658,7 +3659,10 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
}
vcpu->vcpu_idx = atomic_read(&kvm->online_vcpus);
- BUG_ON(kvm->vcpus[vcpu->vcpu_idx]);
+ r = xa_insert(&kvm->vcpu_array, vcpu->vcpu_idx, vcpu, GFP_KERNEL_ACCOUNT);
+ BUG_ON(r == -EBUSY);
+ if (r)
+ goto unlock_vcpu_destroy;
/* Fill the stats id string for the vcpu */
snprintf(vcpu->stats_id, sizeof(vcpu->stats_id), "kvm-%d/vcpu-%d",
@@ -3668,15 +3672,14 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
kvm_get_kvm(kvm);
r = create_vcpu_fd(vcpu);
if (r < 0) {
+ xa_erase(&kvm->vcpu_array, vcpu->vcpu_idx);
kvm_put_kvm_no_destroy(kvm);
goto unlock_vcpu_destroy;
}
- kvm->vcpus[vcpu->vcpu_idx] = vcpu;
-
/*
- * Pairs with smp_rmb() in kvm_get_vcpu. Write kvm->vcpus
- * before kvm->online_vcpu's incremented value.
+ * Pairs with smp_rmb() in kvm_get_vcpu. Store the vcpu
+ * pointer before kvm->online_vcpu's incremented value.
*/
smp_wmb();
atomic_inc(&kvm->online_vcpus);
--
2.30.2
^ permalink raw reply related
* [PATCH v2 4/7] KVM: x86: Use kvm_get_vcpu() instead of open-coded access
From: Marc Zyngier @ 2021-11-16 16:04 UTC (permalink / raw)
To: kvm, linux-mips, kvmarm, linuxppc-dev, Paolo Bonzini
Cc: Juergen Gross, Huacai Chen, Janosch Frank, David Hildenbrand,
Sean Christopherson, Anup Patel, Philippe Mathieu-Daudé,
Nicholas Piggin, Christian Borntraeger, Aleksandar Markovic,
Paul Mackerras, James Morse, kernel-team, Claudio Imbrenda,
Alexandru Elisei, Suzuki K Poulose
In-Reply-To: <20211116160403.4074052-1-maz@kernel.org>
As we are about to change the way vcpus are allocated, mandate
the use of kvm_get_vcpu() instead of open-coding the access.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/x86/kvm/vmx/posted_intr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c
index 5f81ef092bd4..82a49720727d 100644
--- a/arch/x86/kvm/vmx/posted_intr.c
+++ b/arch/x86/kvm/vmx/posted_intr.c
@@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq,
if (!kvm_arch_has_assigned_device(kvm) ||
!irq_remapping_cap(IRQ_POSTING_CAP) ||
- !kvm_vcpu_apicv_active(kvm->vcpus[0]))
+ !kvm_vcpu_apicv_active(kvm_get_vcpu(kvm, 0)))
return 0;
idx = srcu_read_lock(&kvm->irq_srcu);
--
2.30.2
^ permalink raw reply related
* [PATCH v2 3/7] KVM: s390: Use kvm_get_vcpu() instead of open-coded access
From: Marc Zyngier @ 2021-11-16 16:03 UTC (permalink / raw)
To: kvm, linux-mips, kvmarm, linuxppc-dev, Paolo Bonzini
Cc: Juergen Gross, Huacai Chen, Janosch Frank, David Hildenbrand,
Sean Christopherson, Anup Patel, Philippe Mathieu-Daudé,
Nicholas Piggin, Christian Borntraeger, Aleksandar Markovic,
Paul Mackerras, James Morse, kernel-team, Claudio Imbrenda,
Alexandru Elisei, Suzuki K Poulose
In-Reply-To: <20211116160403.4074052-1-maz@kernel.org>
As we are about to change the way vcpus are allocated, mandate
the use of kvm_get_vcpu() instead of open-coding the access.
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/s390/kvm/kvm-s390.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 7af53b8788fa..4a0f62b03964 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -4572,7 +4572,7 @@ int kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)
}
for (i = 0; i < online_vcpus; i++) {
- if (!is_vcpu_stopped(vcpu->kvm->vcpus[i]))
+ if (!is_vcpu_stopped(kvm_get_vcpu(vcpu->kvm, i)))
started_vcpus++;
}
@@ -4634,9 +4634,11 @@ int kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu)
__disable_ibs_on_vcpu(vcpu);
for (i = 0; i < online_vcpus; i++) {
- if (!is_vcpu_stopped(vcpu->kvm->vcpus[i])) {
+ struct kvm_vcpu *tmp = kvm_get_vcpu(vcpu->kvm, i);
+
+ if (!is_vcpu_stopped(tmp)) {
started_vcpus++;
- started_vcpu = vcpu->kvm->vcpus[i];
+ started_vcpu = tmp;
}
}
--
2.30.2
^ permalink raw reply related
* [PATCH v2 2/7] KVM: mips: Use kvm_get_vcpu() instead of open-coded access
From: Marc Zyngier @ 2021-11-16 16:03 UTC (permalink / raw)
To: kvm, linux-mips, kvmarm, linuxppc-dev, Paolo Bonzini
Cc: Juergen Gross, Huacai Chen, Janosch Frank, David Hildenbrand,
Sean Christopherson, Anup Patel, Philippe Mathieu-Daudé,
Nicholas Piggin, Christian Borntraeger, Aleksandar Markovic,
Paul Mackerras, James Morse, kernel-team, Claudio Imbrenda,
Alexandru Elisei, Suzuki K Poulose
In-Reply-To: <20211116160403.4074052-1-maz@kernel.org>
As we are about to change the way vcpus are allocated, mandate
the use of kvm_get_vcpu() instead of open-coding the access.
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/mips/kvm/loongson_ipi.c | 4 ++--
arch/mips/kvm/mips.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/mips/kvm/loongson_ipi.c b/arch/mips/kvm/loongson_ipi.c
index 3681fc8fba38..5d53f32d837c 100644
--- a/arch/mips/kvm/loongson_ipi.c
+++ b/arch/mips/kvm/loongson_ipi.c
@@ -120,7 +120,7 @@ static int loongson_vipi_write(struct loongson_kvm_ipi *ipi,
s->status |= data;
irq.cpu = id;
irq.irq = 6;
- kvm_vcpu_ioctl_interrupt(kvm->vcpus[id], &irq);
+ kvm_vcpu_ioctl_interrupt(kvm_get_vcpu(kvm, id), &irq);
break;
case CORE0_CLEAR_OFF:
@@ -128,7 +128,7 @@ static int loongson_vipi_write(struct loongson_kvm_ipi *ipi,
if (!s->status) {
irq.cpu = id;
irq.irq = -6;
- kvm_vcpu_ioctl_interrupt(kvm->vcpus[id], &irq);
+ kvm_vcpu_ioctl_interrupt(kvm_get_vcpu(kvm, id), &irq);
}
break;
diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index ceacca74f808..6228bf396d63 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -479,7 +479,7 @@ int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
if (irq->cpu == -1)
dvcpu = vcpu;
else
- dvcpu = vcpu->kvm->vcpus[irq->cpu];
+ dvcpu = kvm_get_vcpu(vcpu->kvm, irq->cpu);
if (intr == 2 || intr == 3 || intr == 4 || intr == 6) {
kvm_mips_callbacks->queue_io_int(dvcpu, irq);
--
2.30.2
^ permalink raw reply related
* [PATCH v2 1/7] KVM: Move wiping of the kvm->vcpus array to common code
From: Marc Zyngier @ 2021-11-16 16:03 UTC (permalink / raw)
To: kvm, linux-mips, kvmarm, linuxppc-dev, Paolo Bonzini
Cc: Juergen Gross, Huacai Chen, Janosch Frank, David Hildenbrand,
Sean Christopherson, Anup Patel, Philippe Mathieu-Daudé,
Nicholas Piggin, Christian Borntraeger, Aleksandar Markovic,
Paul Mackerras, James Morse, kernel-team, Claudio Imbrenda,
Alexandru Elisei, Suzuki K Poulose
In-Reply-To: <20211116160403.4074052-1-maz@kernel.org>
All architectures have similar loops iterating over the vcpus,
freeing one vcpu at a time, and eventually wiping the reference
off the vcpus array. They are also inconsistently taking
the kvm->lock mutex when wiping the references from the array.
Make this code common, which will simplify further changes.
The locking is dropped altogether, as this should only be called
when there is no further references on the kvm structure.
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/kvm/arm.c | 10 +---------
arch/mips/kvm/mips.c | 21 +--------------------
arch/powerpc/kvm/powerpc.c | 10 +---------
arch/riscv/kvm/vm.c | 10 +---------
arch/s390/kvm/kvm-s390.c | 18 +-----------------
arch/x86/kvm/x86.c | 9 +--------
include/linux/kvm_host.h | 2 +-
virt/kvm/kvm_main.c | 17 +++++++++++++++--
8 files changed, 22 insertions(+), 75 deletions(-)
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 2f03cbfefe67..29942d8c357c 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -175,19 +175,11 @@ vm_fault_t kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
*/
void kvm_arch_destroy_vm(struct kvm *kvm)
{
- int i;
-
bitmap_free(kvm->arch.pmu_filter);
kvm_vgic_destroy(kvm);
- for (i = 0; i < KVM_MAX_VCPUS; ++i) {
- if (kvm->vcpus[i]) {
- kvm_vcpu_destroy(kvm->vcpus[i]);
- kvm->vcpus[i] = NULL;
- }
- }
- atomic_set(&kvm->online_vcpus, 0);
+ kvm_destroy_vcpus(kvm);
}
int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index 562aa878b266..ceacca74f808 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -171,25 +171,6 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
return 0;
}
-void kvm_mips_free_vcpus(struct kvm *kvm)
-{
- unsigned int i;
- struct kvm_vcpu *vcpu;
-
- kvm_for_each_vcpu(i, vcpu, kvm) {
- kvm_vcpu_destroy(vcpu);
- }
-
- mutex_lock(&kvm->lock);
-
- for (i = 0; i < atomic_read(&kvm->online_vcpus); i++)
- kvm->vcpus[i] = NULL;
-
- atomic_set(&kvm->online_vcpus, 0);
-
- mutex_unlock(&kvm->lock);
-}
-
static void kvm_mips_free_gpa_pt(struct kvm *kvm)
{
/* It should always be safe to remove after flushing the whole range */
@@ -199,7 +180,7 @@ static void kvm_mips_free_gpa_pt(struct kvm *kvm)
void kvm_arch_destroy_vm(struct kvm *kvm)
{
- kvm_mips_free_vcpus(kvm);
+ kvm_destroy_vcpus(kvm);
kvm_mips_free_gpa_pt(kvm);
}
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 35e9cccdeef9..492e4a4121cb 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -463,9 +463,6 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
void kvm_arch_destroy_vm(struct kvm *kvm)
{
- unsigned int i;
- struct kvm_vcpu *vcpu;
-
#ifdef CONFIG_KVM_XICS
/*
* We call kick_all_cpus_sync() to ensure that all
@@ -476,14 +473,9 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
kick_all_cpus_sync();
#endif
- kvm_for_each_vcpu(i, vcpu, kvm)
- kvm_vcpu_destroy(vcpu);
+ kvm_destroy_vcpus(kvm);
mutex_lock(&kvm->lock);
- for (i = 0; i < atomic_read(&kvm->online_vcpus); i++)
- kvm->vcpus[i] = NULL;
-
- atomic_set(&kvm->online_vcpus, 0);
kvmppc_core_destroy_vm(kvm);
diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c
index 26399df15b63..6af6cde295eb 100644
--- a/arch/riscv/kvm/vm.c
+++ b/arch/riscv/kvm/vm.c
@@ -46,15 +46,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
void kvm_arch_destroy_vm(struct kvm *kvm)
{
- int i;
-
- for (i = 0; i < KVM_MAX_VCPUS; ++i) {
- if (kvm->vcpus[i]) {
- kvm_vcpu_destroy(kvm->vcpus[i]);
- kvm->vcpus[i] = NULL;
- }
- }
- atomic_set(&kvm->online_vcpus, 0);
+ kvm_destroy_vcpus(kvm);
}
int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index c6257f625929..7af53b8788fa 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -2819,27 +2819,11 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
free_page((unsigned long)(vcpu->arch.sie_block));
}
-static void kvm_free_vcpus(struct kvm *kvm)
-{
- unsigned int i;
- struct kvm_vcpu *vcpu;
-
- kvm_for_each_vcpu(i, vcpu, kvm)
- kvm_vcpu_destroy(vcpu);
-
- mutex_lock(&kvm->lock);
- for (i = 0; i < atomic_read(&kvm->online_vcpus); i++)
- kvm->vcpus[i] = NULL;
-
- atomic_set(&kvm->online_vcpus, 0);
- mutex_unlock(&kvm->lock);
-}
-
void kvm_arch_destroy_vm(struct kvm *kvm)
{
u16 rc, rrc;
- kvm_free_vcpus(kvm);
+ kvm_destroy_vcpus(kvm);
sca_dispose(kvm);
kvm_s390_gisa_destroy(kvm);
/*
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index dc7eb5fddfd3..259f719014c9 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11378,15 +11378,8 @@ static void kvm_free_vcpus(struct kvm *kvm)
kvm_clear_async_pf_completion_queue(vcpu);
kvm_unload_vcpu_mmu(vcpu);
}
- kvm_for_each_vcpu(i, vcpu, kvm)
- kvm_vcpu_destroy(vcpu);
-
- mutex_lock(&kvm->lock);
- for (i = 0; i < atomic_read(&kvm->online_vcpus); i++)
- kvm->vcpus[i] = NULL;
- atomic_set(&kvm->online_vcpus, 0);
- mutex_unlock(&kvm->lock);
+ kvm_destroy_vcpus(kvm);
}
void kvm_arch_sync_events(struct kvm *kvm)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 9e0667e3723e..9a8c997ff9bc 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -733,7 +733,7 @@ static inline struct kvm_vcpu *kvm_get_vcpu_by_id(struct kvm *kvm, int id)
if (WARN_ON_ONCE(!memslot->npages)) { \
} else
-void kvm_vcpu_destroy(struct kvm_vcpu *vcpu);
+void kvm_destroy_vcpus(struct kvm *kvm);
void vcpu_load(struct kvm_vcpu *vcpu);
void vcpu_put(struct kvm_vcpu *vcpu);
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index d31724500501..73811c3829a2 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -435,7 +435,7 @@ static void kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id)
vcpu->last_used_slot = 0;
}
-void kvm_vcpu_destroy(struct kvm_vcpu *vcpu)
+static void kvm_vcpu_destroy(struct kvm_vcpu *vcpu)
{
kvm_dirty_ring_free(&vcpu->dirty_ring);
kvm_arch_vcpu_destroy(vcpu);
@@ -450,7 +450,20 @@ void kvm_vcpu_destroy(struct kvm_vcpu *vcpu)
free_page((unsigned long)vcpu->run);
kmem_cache_free(kvm_vcpu_cache, vcpu);
}
-EXPORT_SYMBOL_GPL(kvm_vcpu_destroy);
+
+void kvm_destroy_vcpus(struct kvm *kvm)
+{
+ unsigned int i;
+ struct kvm_vcpu *vcpu;
+
+ kvm_for_each_vcpu(i, vcpu, kvm) {
+ kvm_vcpu_destroy(vcpu);
+ kvm->vcpus[i] = NULL;
+ }
+
+ atomic_set(&kvm->online_vcpus, 0);
+}
+EXPORT_SYMBOL_GPL(kvm_destroy_vcpus);
#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn)
--
2.30.2
^ permalink raw reply related
* [PATCH v2 0/7] KVM: Turn the vcpu array into an xarray
From: Marc Zyngier @ 2021-11-16 16:03 UTC (permalink / raw)
To: kvm, linux-mips, kvmarm, linuxppc-dev, Paolo Bonzini
Cc: Juergen Gross, Huacai Chen, Janosch Frank, David Hildenbrand,
Sean Christopherson, Anup Patel, Philippe Mathieu-Daudé,
Nicholas Piggin, Christian Borntraeger, Aleksandar Markovic,
Paul Mackerras, James Morse, kernel-team, Claudio Imbrenda,
Alexandru Elisei, Suzuki K Poulose
The kvm structure is pretty large. A large portion of it is the vcpu
array, which is 4kB on arm64 with 512 vcpu, double that on x86-64. Of
course, hardly anyone runs VMs this big, so this is often a net waste
of memory and cache locality.
A possible approach is to turn the fixed-size array into an xarray,
which results in a net code deletion after a bit of cleanup.
* From v1:
- Rebased on v5.16-rc1
- Dropped the dubious locking on teardown
- Converted kvm_for_each_vcpu() to xa_for_each_range(), together with
an invasive change converting the index to an unsigned long
Marc Zyngier (7):
KVM: Move wiping of the kvm->vcpus array to common code
KVM: mips: Use kvm_get_vcpu() instead of open-coded access
KVM: s390: Use kvm_get_vcpu() instead of open-coded access
KVM: x86: Use kvm_get_vcpu() instead of open-coded access
KVM: Convert the kvm->vcpus array to a xarray
KVM: Use 'unsigned long' as kvm_for_each_vcpu()'s index
KVM: Convert kvm_for_each_vcpu() to using xa_for_each_range()
arch/arm64/kvm/arch_timer.c | 8 ++---
arch/arm64/kvm/arm.c | 16 +++------
arch/arm64/kvm/pmu-emul.c | 2 +-
arch/arm64/kvm/psci.c | 6 ++--
arch/arm64/kvm/reset.c | 2 +-
arch/arm64/kvm/vgic/vgic-init.c | 10 +++---
arch/arm64/kvm/vgic/vgic-kvm-device.c | 2 +-
arch/arm64/kvm/vgic/vgic-mmio-v2.c | 3 +-
arch/arm64/kvm/vgic/vgic-mmio-v3.c | 7 ++--
arch/arm64/kvm/vgic/vgic-v3.c | 4 +--
arch/arm64/kvm/vgic/vgic-v4.c | 5 +--
arch/arm64/kvm/vgic/vgic.c | 2 +-
arch/mips/kvm/loongson_ipi.c | 4 +--
arch/mips/kvm/mips.c | 23 ++-----------
arch/powerpc/kvm/book3s_32_mmu.c | 2 +-
arch/powerpc/kvm/book3s_64_mmu.c | 2 +-
arch/powerpc/kvm/book3s_hv.c | 8 ++---
arch/powerpc/kvm/book3s_pr.c | 2 +-
arch/powerpc/kvm/book3s_xics.c | 6 ++--
arch/powerpc/kvm/book3s_xics.h | 2 +-
arch/powerpc/kvm/book3s_xive.c | 15 +++++----
arch/powerpc/kvm/book3s_xive.h | 4 +--
arch/powerpc/kvm/book3s_xive_native.c | 8 ++---
arch/powerpc/kvm/e500_emulate.c | 2 +-
arch/powerpc/kvm/powerpc.c | 10 +-----
arch/riscv/kvm/vcpu_sbi.c | 2 +-
arch/riscv/kvm/vm.c | 10 +-----
arch/riscv/kvm/vmid.c | 2 +-
arch/s390/kvm/interrupt.c | 2 +-
arch/s390/kvm/kvm-s390.c | 47 ++++++++++-----------------
arch/s390/kvm/kvm-s390.h | 4 +--
arch/x86/kvm/hyperv.c | 7 ++--
arch/x86/kvm/i8254.c | 2 +-
arch/x86/kvm/i8259.c | 5 +--
arch/x86/kvm/ioapic.c | 4 +--
arch/x86/kvm/irq_comm.c | 7 ++--
arch/x86/kvm/kvm_onhyperv.c | 3 +-
arch/x86/kvm/lapic.c | 6 ++--
arch/x86/kvm/svm/avic.c | 2 +-
arch/x86/kvm/svm/sev.c | 3 +-
arch/x86/kvm/vmx/posted_intr.c | 2 +-
arch/x86/kvm/x86.c | 30 +++++++----------
include/linux/kvm_host.h | 17 +++++-----
virt/kvm/kvm_main.c | 41 ++++++++++++++++-------
44 files changed, 158 insertions(+), 193 deletions(-)
--
2.30.2
^ permalink raw reply
* Re: [PATCH 0/5] KVM: Turn the vcpu array into an xarray
From: Marc Zyngier @ 2021-11-16 15:40 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Juergen Gross, Alexandru Elisei, Anup Patel, Janosch Frank, kvm,
Christian Borntraeger, Sean Christopherson, Huacai Chen,
David Hildenbrand, linux-mips, Nicholas Piggin, Atish Patra,
Aleksandar Markovic, Paul Mackerras, James Morse, kernel-team,
Claudio Imbrenda, linuxppc-dev, kvmarm, Suzuki K Poulose
In-Reply-To: <dd5292e5-7387-9797-2d74-6a3350cbe4f5@redhat.com>
On Tue, 16 Nov 2021 15:03:40 +0000,
Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 11/5/21 20:20, Marc Zyngier wrote:
> > The kvm structure is pretty large. A large portion of it is the vcpu
> > array, which is 4kB on x86_64 and arm64 as they deal with 512 vcpu
> > VMs. Of course, hardly anyone runs VMs this big, so this is often a
> > net waste of memory and cache locality.
> >
> > A possible approach is to turn the fixed-size array into an xarray,
> > which results in a net code deletion after a bit of cleanup.
> >
> > This series is on top of the current linux/master as it touches the
> > RISC-V implementation. Only tested on arm64.
>
> Queued, only locally until I get a review for my replacement of patch
> 4 (see
> https://lore.kernel.org/kvm/20211116142205.719375-1-pbonzini@redhat.com/T/).
In which case, let me send a v2 with the changes that we discussed
with Sean. It will still have my version of patch 4, but that's
nothing you can't fix.
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply
* Re: [PATCH] powerpc: clean vdso32 and vdso64 directories
From: Christophe Leroy @ 2021-11-16 15:37 UTC (permalink / raw)
To: Masahiro Yamada, linux-kernel
Cc: Aneesh Kumar K.V, Nicholas Piggin, Paul Mackerras, linuxppc-dev,
Ard Biesheuvel
In-Reply-To: <20211109185015.615517-1-masahiroy@kernel.org>
Hi Masahiro,
Le 09/11/2021 à 19:50, Masahiro Yamada a écrit :
> Since commit bce74491c300 ("powerpc/vdso: fix unnecessary rebuilds of
> vgettimeofday.o"), "make ARCH=powerpc clean" does not clean up the
> arch/powerpc/kernel/{vdso32,vdso64} directories.
>
> Use the subdir- trick to let "make clean" descend into them.
>
> Fixes: bce74491c300 ("powerpc/vdso: fix unnecessary rebuilds of vgettimeofday.o")
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
>
> arch/powerpc/kernel/Makefile | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
> index 0e3640e14eb1..5fa68c2ef1f8 100644
> --- a/arch/powerpc/kernel/Makefile
> +++ b/arch/powerpc/kernel/Makefile
> @@ -196,3 +196,6 @@ clean-files := vmlinux.lds
> # Force dependency (incbin is bad)
> $(obj)/vdso32_wrapper.o : $(obj)/vdso32/vdso32.so.dbg
> $(obj)/vdso64_wrapper.o : $(obj)/vdso64/vdso64.so.dbg
> +
> +# for cleaning
> +subdir- += vdso32 vdso64
>
This patch make me think about one thing I would have liked to do, but I
don't know Makefiles well enough to be able to do it. You could probably
help me with it.
vdso32 and vdso64 contain a lot of redundant sources. I would like to
merge them into a new single directory, let say 'vdso', and use the
files in that directory to build both vdso32.so and vdso64.so. I have a
feeling that x86 is doing it that way, but I've not been able to figure
out how to build two objects using the same C/S files.
Thanks
Christophe
^ permalink raw reply
* Re: [PATCH v2 12/13] lkdtm: Fix execute_[user]_location()
From: Christophe Leroy @ 2021-11-16 15:07 UTC (permalink / raw)
To: Kees Cook
Cc: linux-arch, linux-ia64, linux-parisc, Arnd Bergmann,
Greg Kroah-Hartman, Helge Deller, linux-kernel,
James E.J. Bottomley, linux-mm, Paul Mackerras, Andrew Morton,
linuxppc-dev
In-Reply-To: <9b4c39d4-1322-89af-585c-679a574576a2@csgroup.eu>
Hi Kees,
Le 16/10/2021 à 08:42, Christophe Leroy a écrit :
>
>
> Le 15/10/2021 à 23:31, Kees Cook a écrit :
>> On Thu, Oct 14, 2021 at 07:50:01AM +0200, Christophe Leroy wrote:
>>> execute_location() and execute_user_location() intent
>>> to copy do_nothing() text and execute it at a new location.
>>> However, at the time being it doesn't copy do_nothing() function
>>> but do_nothing() function descriptor which still points to the
>>> original text. So at the end it still executes do_nothing() at
>>> its original location allthough using a copied function descriptor.
>>>
>>> So, fix that by really copying do_nothing() text and build a new
>>> function descriptor by copying do_nothing() function descriptor and
>>> updating the target address with the new location.
>>>
>>> Also fix the displayed addresses by dereferencing do_nothing()
>>> function descriptor.
>>>
>>> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
>>> ---
>>> drivers/misc/lkdtm/perms.c | 25 +++++++++++++++++++++----
>>> include/asm-generic/sections.h | 5 +++++
>>> 2 files changed, 26 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
>>> index 5266dc28df6e..96b3ebfcb8ed 100644
>>> --- a/drivers/misc/lkdtm/perms.c
>>> +++ b/drivers/misc/lkdtm/perms.c
>>> @@ -44,19 +44,32 @@ static noinline void do_overwritten(void)
>>> return;
>>> }
>>> +static void *setup_function_descriptor(func_desc_t *fdesc, void *dst)
>>> +{
>>> + memcpy(fdesc, do_nothing, sizeof(*fdesc));
>>> + fdesc->addr = (unsigned long)dst;
>>> + barrier();
>>> +
>>> + return fdesc;
>>> +}
>>
>> How about collapsing the "have_function_descriptors()" check into
>> setup_function_descriptor()?
>>
>> static void *setup_function_descriptor(func_desc_t *fdesc, void *dst)
>> {
>> if (__is_defined(HAVE_FUNCTION_DESCRIPTORS)) {
>> memcpy(fdesc, do_nothing, sizeof(*fdesc));
>> fdesc->addr = (unsigned long)dst;
>> barrier();
>> return fdesc;
>> } else {
>> return dst;
>> }
>> }
>
> Ok
>
...
>>
>>> diff --git a/include/asm-generic/sections.h
>>> b/include/asm-generic/sections.h
>>> index 76163883c6ff..d225318538bd 100644
>>> --- a/include/asm-generic/sections.h
>>> +++ b/include/asm-generic/sections.h
>>> @@ -70,6 +70,11 @@ typedef struct {
>>> } func_desc_t;
>>> #endif
>>> +static inline bool have_function_descriptors(void)
>>> +{
>>> + return __is_defined(HAVE_FUNCTION_DESCRIPTORS);
>>> +}
>>> +
>>> /* random extra sections (if any). Override
>>> * in asm/sections.h */
>>> #ifndef arch_is_kernel_text
>>
>> This hunk seems like it should live in a separate patch.
>>
>
> Ok I move it in a previous patch.
Do you have any additional feedback or comment on series v3 ?
What's the way forward, should it go via LKDTM tree or via powerpc tree
or another tree ? I see there are neither Ack-by nor Reviewed-by for the
last 2 patches.
Thanks
Christophe
^ permalink raw reply
* Re: [PATCH 0/5] KVM: Turn the vcpu array into an xarray
From: Paolo Bonzini @ 2021-11-16 15:03 UTC (permalink / raw)
To: Marc Zyngier, kvm, linux-mips, kvmarm, linuxppc-dev
Cc: Juergen Gross, Huacai Chen, Janosch Frank, Christian Borntraeger,
Sean Christopherson, Anup Patel, David Hildenbrand,
Nicholas Piggin, Atish Patra, Aleksandar Markovic, Paul Mackerras,
James Morse, kernel-team, Claudio Imbrenda, Alexandru Elisei,
Suzuki K Poulose
In-Reply-To: <20211105192101.3862492-1-maz@kernel.org>
On 11/5/21 20:20, Marc Zyngier wrote:
> The kvm structure is pretty large. A large portion of it is the vcpu
> array, which is 4kB on x86_64 and arm64 as they deal with 512 vcpu
> VMs. Of course, hardly anyone runs VMs this big, so this is often a
> net waste of memory and cache locality.
>
> A possible approach is to turn the fixed-size array into an xarray,
> which results in a net code deletion after a bit of cleanup.
>
> This series is on top of the current linux/master as it touches the
> RISC-V implementation. Only tested on arm64.
Queued, only locally until I get a review for my replacement of patch 4
(see
https://lore.kernel.org/kvm/20211116142205.719375-1-pbonzini@redhat.com/T/).
Paolo
> Marc Zyngier (5):
> KVM: Move wiping of the kvm->vcpus array to common code
> KVM: mips: Use kvm_get_vcpu() instead of open-coded access
> KVM: s390: Use kvm_get_vcpu() instead of open-coded access
> KVM: x86: Use kvm_get_vcpu() instead of open-coded access
> KVM: Convert the kvm->vcpus array to a xarray
>
> arch/arm64/kvm/arm.c | 10 +---------
> arch/mips/kvm/loongson_ipi.c | 4 ++--
> arch/mips/kvm/mips.c | 23 ++---------------------
> arch/powerpc/kvm/powerpc.c | 10 +---------
> arch/riscv/kvm/vm.c | 10 +---------
> arch/s390/kvm/kvm-s390.c | 26 ++++++--------------------
> arch/x86/kvm/vmx/posted_intr.c | 2 +-
> arch/x86/kvm/x86.c | 9 +--------
> include/linux/kvm_host.h | 7 ++++---
> virt/kvm/kvm_main.c | 33 ++++++++++++++++++++++++++-------
> 10 files changed, 45 insertions(+), 89 deletions(-)
>
^ permalink raw reply
* Re: [RESEND PATCH v5 0/4] Add perf interface to expose nvdimm
From: LEROY Christophe @ 2021-11-16 14:59 UTC (permalink / raw)
To: Kajol Jain, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org,
nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org,
peterz@infradead.org, dan.j.williams@intel.com,
ira.weiny@intel.com, vishal.l.verma@intel.com
Cc: santosh@fossix.org, maddy@linux.ibm.com, rnsastry@linux.ibm.com,
aneesh.kumar@linux.ibm.com, atrajeev@linux.vnet.ibm.com,
vaibhav@linux.ibm.com
In-Reply-To: <20211116044904.48718-1-kjain@linux.ibm.com>
Hi
Le 16/11/2021 à 05:49, Kajol Jain a écrit :
> Patchset adds performance stats reporting support for nvdimm.
> Added interface includes support for pmu register/unregister
> functions. A structure is added called nvdimm_pmu to be used for
> adding arch/platform specific data such as cpumask, nvdimm device
> pointer and pmu event functions like event_init/add/read/del.
> User could use the standard perf tool to access perf events
> exposed via pmu.
>
> Interface also defines supported event list, config fields for the
> event attributes and their corresponding bit values which are exported
> via sysfs. Patch 3 exposes IBM pseries platform nmem* device
> performance stats using this interface.
You resending your v5 series ? Is there any news since your submittion
last month that's awaiting in patchwork here at
https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=264422 ?
Christophe
>
> Result from power9 pseries lpar with 2 nvdimm device:
>
> Ex: List all event by perf list
>
> command:# perf list nmem
>
> nmem0/cache_rh_cnt/ [Kernel PMU event]
> nmem0/cache_wh_cnt/ [Kernel PMU event]
> nmem0/cri_res_util/ [Kernel PMU event]
> nmem0/ctl_res_cnt/ [Kernel PMU event]
> nmem0/ctl_res_tm/ [Kernel PMU event]
> nmem0/fast_w_cnt/ [Kernel PMU event]
> nmem0/host_l_cnt/ [Kernel PMU event]
> nmem0/host_l_dur/ [Kernel PMU event]
> nmem0/host_s_cnt/ [Kernel PMU event]
> nmem0/host_s_dur/ [Kernel PMU event]
> nmem0/med_r_cnt/ [Kernel PMU event]
> nmem0/med_r_dur/ [Kernel PMU event]
> nmem0/med_w_cnt/ [Kernel PMU event]
> nmem0/med_w_dur/ [Kernel PMU event]
> nmem0/mem_life/ [Kernel PMU event]
> nmem0/poweron_secs/ [Kernel PMU event]
> ...
> nmem1/mem_life/ [Kernel PMU event]
> nmem1/poweron_secs/ [Kernel PMU event]
>
> Patch1:
> Introduces the nvdimm_pmu structure
> Patch2:
> Adds common interface to add arch/platform specific data
> includes nvdimm device pointer, pmu data along with
> pmu event functions. It also defines supported event list
> and adds attribute groups for format, events and cpumask.
> It also adds code for cpu hotplug support.
> Patch3:
> Add code in arch/powerpc/platform/pseries/papr_scm.c to expose
> nmem* pmu. It fills in the nvdimm_pmu structure with pmu name,
> capabilities, cpumask and event functions and then registers
> the pmu by adding callbacks to register_nvdimm_pmu.
> Patch4:
> Sysfs documentation patch
>
> Changelog
> ---
> v4 -> v5:
> - Remove multiple variables defined in nvdimm_pmu structure include
> name and pmu functions(event_int/add/del/read) as they are just
> used to copy them again in pmu variable. Now we are directly doing
> this step in arch specific code as suggested by Dan Williams.
>
> - Remove attribute group field from nvdimm pmu structure and
> defined these attribute groups in common interface which
> includes format, event list along with cpumask as suggested by
> Dan Williams.
> Since we added static defination for attrbute groups needed in
> common interface, removes corresponding code from papr.
>
> - Add nvdimm pmu event list with event codes in the common interface.
>
> - Remove Acked-by/Reviewed-by/Tested-by tags as code is refactored
> to handle review comments from Dan.
>
> - Make nvdimm_pmu_free_hotplug_memory function static as reported
> by kernel test robot, also add corresponding Reported-by tag.
>
> - Link to the patchset v4: https://lkml.org/lkml/2021/9/3/45
>
> v3 -> v4
> - Rebase code on top of current papr_scm code without any logical
> changes.
>
> - Added Acked-by tag from Peter Zijlstra and Reviewed by tag
> from Madhavan Srinivasan.
>
> - Link to the patchset v3: https://lkml.org/lkml/2021/6/17/605
>
> v2 -> v3
> - Added Tested-by tag.
>
> - Fix nvdimm mailing list in the ABI Documentation.
>
> - Link to the patchset v2: https://lkml.org/lkml/2021/6/14/25
>
> v1 -> v2
> - Fix hotplug code by adding pmu migration call
> incase current designated cpu got offline. As
> pointed by Peter Zijlstra.
>
> - Removed the retun -1 part from cpu hotplug offline
> function.
>
> - Link to the patchset v1: https://lkml.org/lkml/2021/6/8/500
>
> Kajol Jain (4):
> drivers/nvdimm: Add nvdimm pmu structure
> drivers/nvdimm: Add perf interface to expose nvdimm performance stats
> powerpc/papr_scm: Add perf interface support
> docs: ABI: sysfs-bus-nvdimm: Document sysfs event format entries for
> nvdimm pmu
>
> Documentation/ABI/testing/sysfs-bus-nvdimm | 35 +++
> arch/powerpc/include/asm/device.h | 5 +
> arch/powerpc/platforms/pseries/papr_scm.c | 225 ++++++++++++++
> drivers/nvdimm/Makefile | 1 +
> drivers/nvdimm/nd_perf.c | 328 +++++++++++++++++++++
> include/linux/nd.h | 41 +++
> 6 files changed, 635 insertions(+)
> create mode 100644 drivers/nvdimm/nd_perf.c
>
^ permalink raw reply
* Re: [PATCH] powerpc/xive: Change IRQ domain to a tree domain
From: Cédric Le Goater @ 2021-11-16 14:49 UTC (permalink / raw)
To: Greg Kurz; +Cc: linuxppc-dev, stable, Marc Zyngier
In-Reply-To: <20211116152343.782c687c@bahia>
On 11/16/21 15:23, Greg Kurz wrote:
> On Tue, 16 Nov 2021 14:40:22 +0100
> Cédric Le Goater <clg@kaod.org> wrote:
>
>> Commit 4f86a06e2d6e ("irqdomain: Make normal and nomap irqdomains
>> exclusive") introduced an IRQ_DOMAIN_FLAG_NO_MAP flag to isolate the
>> 'nomap' domains still in use under the powerpc arch. With this new
>> flag, the revmap_tree of the IRQ domain is not used anymore. This
>> change broke the support of shared LSIs [1] in the XIVE driver because
>> it was relying on a lookup in the revmap_tree to query previously
>> mapped interrupts. Linux now creates two distinct IRQ mappings on the
>> same HW IRQ which can lead to unexpected behavior in the drivers.
>>
>> The XIVE IRQ domain is not a direct mapping domain and its HW IRQ
>> interrupt number space is rather large : 1M/socket on POWER9 and
>> POWER10, change the XIVE driver to use a 'tree' domain type instead.
>>
>> [1] For instance, a linux KVM guest with virtio-rng and virtio-balloon
>> devices.
>>
>> Cc: Marc Zyngier <maz@kernel.org>
>> Cc: stable@vger.kernel.org # v5.14+
>> Fixes: 4f86a06e2d6e ("irqdomain: Make normal and nomap irqdomains exclusive")
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>> ---
>>
>
> Tested-by: Greg Kurz <groug@kaod.org>
>
> with a KVM guest + virtio-rng + virtio-balloon on a POWER9 host.
Did you test on a 5.14 backport or mainline ?
I am asking because a large change adding support for MSI domains
to XIVE was merged in 5.15.
Thanks,
C.
>
>> Marc,
>>
>> The Fixes tag is there because the patch in question revealed that
>> something was broken in XIVE. genirq is not in cause. However, I
>> don't know for PS3 and Cell. May be less critical for now.
>>
>> arch/powerpc/sysdev/xive/common.c | 3 +--
>> arch/powerpc/sysdev/xive/Kconfig | 1 -
>> 2 files changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
>> index fed6fd16c8f4..9d0f0fe25598 100644
>> --- a/arch/powerpc/sysdev/xive/common.c
>> +++ b/arch/powerpc/sysdev/xive/common.c
>> @@ -1536,8 +1536,7 @@ static const struct irq_domain_ops xive_irq_domain_ops = {
>>
>> static void __init xive_init_host(struct device_node *np)
>> {
>> - xive_irq_domain = irq_domain_add_nomap(np, XIVE_MAX_IRQ,
>> - &xive_irq_domain_ops, NULL);
>> + xive_irq_domain = irq_domain_add_tree(np, &xive_irq_domain_ops, NULL);
>> if (WARN_ON(xive_irq_domain == NULL))
>> return;
>> irq_set_default_host(xive_irq_domain);
>> diff --git a/arch/powerpc/sysdev/xive/Kconfig b/arch/powerpc/sysdev/xive/Kconfig
>> index 97796c6b63f0..785c292d104b 100644
>> --- a/arch/powerpc/sysdev/xive/Kconfig
>> +++ b/arch/powerpc/sysdev/xive/Kconfig
>> @@ -3,7 +3,6 @@ config PPC_XIVE
>> bool
>> select PPC_SMP_MUXED_IPI
>> select HARDIRQS_SW_RESEND
>> - select IRQ_DOMAIN_NOMAP
>>
>> config PPC_XIVE_NATIVE
>> bool
>
^ permalink raw reply
* Re: [PATCH 0/5] KVM: Turn the vcpu array into an xarray
From: Juergen Gross @ 2021-11-16 14:54 UTC (permalink / raw)
To: Paolo Bonzini, Marc Zyngier, kvm, linux-mips, kvmarm,
linuxppc-dev
Cc: Huacai Chen, Janosch Frank, Christian Borntraeger,
Sean Christopherson, Anup Patel, David Hildenbrand,
Nicholas Piggin, Atish Patra, Aleksandar Markovic, Paul Mackerras,
James Morse, kernel-team, Claudio Imbrenda, Alexandru Elisei,
Suzuki K Poulose
In-Reply-To: <d0f41b9f-9307-3694-59c8-5a009a2f06a2@redhat.com>
[-- Attachment #1.1.1: Type: text/plain, Size: 2147 bytes --]
On 16.11.21 15:21, Paolo Bonzini wrote:
> On 11/16/21 15:13, Juergen Gross wrote:
>> On 05.11.21 20:20, Marc Zyngier wrote:
>>> The kvm structure is pretty large. A large portion of it is the vcpu
>>> array, which is 4kB on x86_64 and arm64 as they deal with 512 vcpu
>>> VMs. Of course, hardly anyone runs VMs this big, so this is often a
>>> net waste of memory and cache locality.
>>>
>>> A possible approach is to turn the fixed-size array into an xarray,
>>> which results in a net code deletion after a bit of cleanup.
>>>
>>> This series is on top of the current linux/master as it touches the
>>> RISC-V implementation. Only tested on arm64.
>>>
>>> Marc Zyngier (5):
>>> KVM: Move wiping of the kvm->vcpus array to common code
>>> KVM: mips: Use kvm_get_vcpu() instead of open-coded access
>>> KVM: s390: Use kvm_get_vcpu() instead of open-coded access
>>> KVM: x86: Use kvm_get_vcpu() instead of open-coded access
>>> KVM: Convert the kvm->vcpus array to a xarray
>>>
>>> arch/arm64/kvm/arm.c | 10 +---------
>>> arch/mips/kvm/loongson_ipi.c | 4 ++--
>>> arch/mips/kvm/mips.c | 23 ++---------------------
>>> arch/powerpc/kvm/powerpc.c | 10 +---------
>>> arch/riscv/kvm/vm.c | 10 +---------
>>> arch/s390/kvm/kvm-s390.c | 26 ++++++--------------------
>>> arch/x86/kvm/vmx/posted_intr.c | 2 +-
>>> arch/x86/kvm/x86.c | 9 +--------
>>> include/linux/kvm_host.h | 7 ++++---
>>> virt/kvm/kvm_main.c | 33 ++++++++++++++++++++++++++-------
>>> 10 files changed, 45 insertions(+), 89 deletions(-)
>>>
>>
>> For x86 you can add my:
>>
>> Tested-by: Juergen Gross <jgross@suse.com>
>
> Heh, unfortunately x86 is the only one that needs a change in patch 4.
> I'll Cc you on my version.
I guess the changes in kvm_main.c are more important for my series. :-)
I've replaced patch 4 with your variant and everything is still working.
Not sure how relevant that is, though.
Juergen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply
* Re: [PATCH] powerpc/xive: Change IRQ domain to a tree domain
From: Greg Kurz @ 2021-11-16 14:50 UTC (permalink / raw)
To: Cédric Le Goater; +Cc: linuxppc-dev, stable, Marc Zyngier
In-Reply-To: <bcc9f90d-1ba1-6814-960c-e9205c9b2c85@kaod.org>
On Tue, 16 Nov 2021 15:49:13 +0100
Cédric Le Goater <clg@kaod.org> wrote:
> On 11/16/21 15:23, Greg Kurz wrote:
> > On Tue, 16 Nov 2021 14:40:22 +0100
> > Cédric Le Goater <clg@kaod.org> wrote:
> >
> >> Commit 4f86a06e2d6e ("irqdomain: Make normal and nomap irqdomains
> >> exclusive") introduced an IRQ_DOMAIN_FLAG_NO_MAP flag to isolate the
> >> 'nomap' domains still in use under the powerpc arch. With this new
> >> flag, the revmap_tree of the IRQ domain is not used anymore. This
> >> change broke the support of shared LSIs [1] in the XIVE driver because
> >> it was relying on a lookup in the revmap_tree to query previously
> >> mapped interrupts. Linux now creates two distinct IRQ mappings on the
> >> same HW IRQ which can lead to unexpected behavior in the drivers.
> >>
> >> The XIVE IRQ domain is not a direct mapping domain and its HW IRQ
> >> interrupt number space is rather large : 1M/socket on POWER9 and
> >> POWER10, change the XIVE driver to use a 'tree' domain type instead.
> >>
> >> [1] For instance, a linux KVM guest with virtio-rng and virtio-balloon
> >> devices.
> >>
> >> Cc: Marc Zyngier <maz@kernel.org>
> >> Cc: stable@vger.kernel.org # v5.14+
> >> Fixes: 4f86a06e2d6e ("irqdomain: Make normal and nomap irqdomains exclusive")
> >> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> >> ---
> >>
> >
> > Tested-by: Greg Kurz <groug@kaod.org>
> >
> > with a KVM guest + virtio-rng + virtio-balloon on a POWER9 host.
>
> Did you test on a 5.14 backport or mainline ?
>
I've tested on a 5.14 backport only.
> I am asking because a large change adding support for MSI domains
> to XIVE was merged in 5.15.
>
> Thanks,
>
> C.
>
>
> >
> >> Marc,
> >>
> >> The Fixes tag is there because the patch in question revealed that
> >> something was broken in XIVE. genirq is not in cause. However, I
> >> don't know for PS3 and Cell. May be less critical for now.
> >>
> >> arch/powerpc/sysdev/xive/common.c | 3 +--
> >> arch/powerpc/sysdev/xive/Kconfig | 1 -
> >> 2 files changed, 1 insertion(+), 3 deletions(-)
> >>
> >> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
> >> index fed6fd16c8f4..9d0f0fe25598 100644
> >> --- a/arch/powerpc/sysdev/xive/common.c
> >> +++ b/arch/powerpc/sysdev/xive/common.c
> >> @@ -1536,8 +1536,7 @@ static const struct irq_domain_ops xive_irq_domain_ops = {
> >>
> >> static void __init xive_init_host(struct device_node *np)
> >> {
> >> - xive_irq_domain = irq_domain_add_nomap(np, XIVE_MAX_IRQ,
> >> - &xive_irq_domain_ops, NULL);
> >> + xive_irq_domain = irq_domain_add_tree(np, &xive_irq_domain_ops, NULL);
> >> if (WARN_ON(xive_irq_domain == NULL))
> >> return;
> >> irq_set_default_host(xive_irq_domain);
> >> diff --git a/arch/powerpc/sysdev/xive/Kconfig b/arch/powerpc/sysdev/xive/Kconfig
> >> index 97796c6b63f0..785c292d104b 100644
> >> --- a/arch/powerpc/sysdev/xive/Kconfig
> >> +++ b/arch/powerpc/sysdev/xive/Kconfig
> >> @@ -3,7 +3,6 @@ config PPC_XIVE
> >> bool
> >> select PPC_SMP_MUXED_IPI
> >> select HARDIRQS_SW_RESEND
> >> - select IRQ_DOMAIN_NOMAP
> >>
> >> config PPC_XIVE_NATIVE
> >> bool
> >
>
^ permalink raw reply
* Re: [PATCH] powerpc/xive: Change IRQ domain to a tree domain
From: Greg Kurz @ 2021-11-16 14:23 UTC (permalink / raw)
To: Cédric Le Goater; +Cc: linuxppc-dev, stable, Marc Zyngier
In-Reply-To: <20211116134022.420412-1-clg@kaod.org>
On Tue, 16 Nov 2021 14:40:22 +0100
Cédric Le Goater <clg@kaod.org> wrote:
> Commit 4f86a06e2d6e ("irqdomain: Make normal and nomap irqdomains
> exclusive") introduced an IRQ_DOMAIN_FLAG_NO_MAP flag to isolate the
> 'nomap' domains still in use under the powerpc arch. With this new
> flag, the revmap_tree of the IRQ domain is not used anymore. This
> change broke the support of shared LSIs [1] in the XIVE driver because
> it was relying on a lookup in the revmap_tree to query previously
> mapped interrupts. Linux now creates two distinct IRQ mappings on the
> same HW IRQ which can lead to unexpected behavior in the drivers.
>
> The XIVE IRQ domain is not a direct mapping domain and its HW IRQ
> interrupt number space is rather large : 1M/socket on POWER9 and
> POWER10, change the XIVE driver to use a 'tree' domain type instead.
>
> [1] For instance, a linux KVM guest with virtio-rng and virtio-balloon
> devices.
>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: stable@vger.kernel.org # v5.14+
> Fixes: 4f86a06e2d6e ("irqdomain: Make normal and nomap irqdomains exclusive")
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---
>
Tested-by: Greg Kurz <groug@kaod.org>
with a KVM guest + virtio-rng + virtio-balloon on a POWER9 host.
> Marc,
>
> The Fixes tag is there because the patch in question revealed that
> something was broken in XIVE. genirq is not in cause. However, I
> don't know for PS3 and Cell. May be less critical for now.
>
> arch/powerpc/sysdev/xive/common.c | 3 +--
> arch/powerpc/sysdev/xive/Kconfig | 1 -
> 2 files changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
> index fed6fd16c8f4..9d0f0fe25598 100644
> --- a/arch/powerpc/sysdev/xive/common.c
> +++ b/arch/powerpc/sysdev/xive/common.c
> @@ -1536,8 +1536,7 @@ static const struct irq_domain_ops xive_irq_domain_ops = {
>
> static void __init xive_init_host(struct device_node *np)
> {
> - xive_irq_domain = irq_domain_add_nomap(np, XIVE_MAX_IRQ,
> - &xive_irq_domain_ops, NULL);
> + xive_irq_domain = irq_domain_add_tree(np, &xive_irq_domain_ops, NULL);
> if (WARN_ON(xive_irq_domain == NULL))
> return;
> irq_set_default_host(xive_irq_domain);
> diff --git a/arch/powerpc/sysdev/xive/Kconfig b/arch/powerpc/sysdev/xive/Kconfig
> index 97796c6b63f0..785c292d104b 100644
> --- a/arch/powerpc/sysdev/xive/Kconfig
> +++ b/arch/powerpc/sysdev/xive/Kconfig
> @@ -3,7 +3,6 @@ config PPC_XIVE
> bool
> select PPC_SMP_MUXED_IPI
> select HARDIRQS_SW_RESEND
> - select IRQ_DOMAIN_NOMAP
>
> config PPC_XIVE_NATIVE
> bool
^ permalink raw reply
* Re: [PATCH 0/5] KVM: Turn the vcpu array into an xarray
From: Paolo Bonzini @ 2021-11-16 14:21 UTC (permalink / raw)
To: Juergen Gross, Marc Zyngier, kvm, linux-mips, kvmarm,
linuxppc-dev
Cc: Huacai Chen, Janosch Frank, Christian Borntraeger,
Sean Christopherson, Anup Patel, David Hildenbrand,
Nicholas Piggin, Atish Patra, Aleksandar Markovic, Paul Mackerras,
James Morse, kernel-team, Claudio Imbrenda, Alexandru Elisei,
Suzuki K Poulose
In-Reply-To: <6232cbcb-b2e2-e79f-a520-43d552f35243@suse.com>
On 11/16/21 15:13, Juergen Gross wrote:
> On 05.11.21 20:20, Marc Zyngier wrote:
>> The kvm structure is pretty large. A large portion of it is the vcpu
>> array, which is 4kB on x86_64 and arm64 as they deal with 512 vcpu
>> VMs. Of course, hardly anyone runs VMs this big, so this is often a
>> net waste of memory and cache locality.
>>
>> A possible approach is to turn the fixed-size array into an xarray,
>> which results in a net code deletion after a bit of cleanup.
>>
>> This series is on top of the current linux/master as it touches the
>> RISC-V implementation. Only tested on arm64.
>>
>> Marc Zyngier (5):
>> KVM: Move wiping of the kvm->vcpus array to common code
>> KVM: mips: Use kvm_get_vcpu() instead of open-coded access
>> KVM: s390: Use kvm_get_vcpu() instead of open-coded access
>> KVM: x86: Use kvm_get_vcpu() instead of open-coded access
>> KVM: Convert the kvm->vcpus array to a xarray
>>
>> arch/arm64/kvm/arm.c | 10 +---------
>> arch/mips/kvm/loongson_ipi.c | 4 ++--
>> arch/mips/kvm/mips.c | 23 ++---------------------
>> arch/powerpc/kvm/powerpc.c | 10 +---------
>> arch/riscv/kvm/vm.c | 10 +---------
>> arch/s390/kvm/kvm-s390.c | 26 ++++++--------------------
>> arch/x86/kvm/vmx/posted_intr.c | 2 +-
>> arch/x86/kvm/x86.c | 9 +--------
>> include/linux/kvm_host.h | 7 ++++---
>> virt/kvm/kvm_main.c | 33 ++++++++++++++++++++++++++-------
>> 10 files changed, 45 insertions(+), 89 deletions(-)
>>
>
> For x86 you can add my:
>
> Tested-by: Juergen Gross <jgross@suse.com>
Heh, unfortunately x86 is the only one that needs a change in patch 4.
I'll Cc you on my version.
Paolo
^ permalink raw reply
* Re: [PATCH 0/5] KVM: Turn the vcpu array into an xarray
From: Juergen Gross @ 2021-11-16 14:13 UTC (permalink / raw)
To: Marc Zyngier, kvm, linux-mips, kvmarm, linuxppc-dev
Cc: Huacai Chen, Janosch Frank, Christian Borntraeger,
Sean Christopherson, Anup Patel, David Hildenbrand,
Nicholas Piggin, Atish Patra, Aleksandar Markovic, Paul Mackerras,
James Morse, Paolo Bonzini, kernel-team, Claudio Imbrenda,
Alexandru Elisei, Suzuki K Poulose
In-Reply-To: <20211105192101.3862492-1-maz@kernel.org>
[-- Attachment #1.1.1: Type: text/plain, Size: 1596 bytes --]
On 05.11.21 20:20, Marc Zyngier wrote:
> The kvm structure is pretty large. A large portion of it is the vcpu
> array, which is 4kB on x86_64 and arm64 as they deal with 512 vcpu
> VMs. Of course, hardly anyone runs VMs this big, so this is often a
> net waste of memory and cache locality.
>
> A possible approach is to turn the fixed-size array into an xarray,
> which results in a net code deletion after a bit of cleanup.
>
> This series is on top of the current linux/master as it touches the
> RISC-V implementation. Only tested on arm64.
>
> Marc Zyngier (5):
> KVM: Move wiping of the kvm->vcpus array to common code
> KVM: mips: Use kvm_get_vcpu() instead of open-coded access
> KVM: s390: Use kvm_get_vcpu() instead of open-coded access
> KVM: x86: Use kvm_get_vcpu() instead of open-coded access
> KVM: Convert the kvm->vcpus array to a xarray
>
> arch/arm64/kvm/arm.c | 10 +---------
> arch/mips/kvm/loongson_ipi.c | 4 ++--
> arch/mips/kvm/mips.c | 23 ++---------------------
> arch/powerpc/kvm/powerpc.c | 10 +---------
> arch/riscv/kvm/vm.c | 10 +---------
> arch/s390/kvm/kvm-s390.c | 26 ++++++--------------------
> arch/x86/kvm/vmx/posted_intr.c | 2 +-
> arch/x86/kvm/x86.c | 9 +--------
> include/linux/kvm_host.h | 7 ++++---
> virt/kvm/kvm_main.c | 33 ++++++++++++++++++++++++++-------
> 10 files changed, 45 insertions(+), 89 deletions(-)
>
For x86 you can add my:
Tested-by: Juergen Gross <jgross@suse.com>
Juergen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply
* Re: [PATCH 4/5] KVM: x86: Use kvm_get_vcpu() instead of open-coded access
From: Paolo Bonzini @ 2021-11-16 14:04 UTC (permalink / raw)
To: Sean Christopherson, Marc Zyngier
Cc: Juergen Gross, Alexandru Elisei, Anup Patel, Janosch Frank, kvm,
Christian Borntraeger, Huacai Chen, David Hildenbrand, linux-mips,
Nicholas Piggin, Atish Patra, Aleksandar Markovic, Paul Mackerras,
James Morse, kernel-team, Claudio Imbrenda, linuxppc-dev, kvmarm,
Suzuki K Poulose
In-Reply-To: <YYWOKTYHhJywwCRk@google.com>
On 11/5/21 21:03, Sean Christopherson wrote:
> But I think even that is flawed, as APICv can be dynamically deactivated and
> re-activated while the VM is running, and I don't see a path that re-updates
> the IRTE when APICv is re-activated. So I think a more conservative check is
> needed, e.g.
>
> diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c
> index 5f81ef092bd4..6cf5b2e86118 100644
> --- a/arch/x86/kvm/vmx/posted_intr.c
> +++ b/arch/x86/kvm/vmx/posted_intr.c
> @@ -272,7 +272,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq,
>
> if (!kvm_arch_has_assigned_device(kvm) ||
> !irq_remapping_cap(IRQ_POSTING_CAP) ||
> - !kvm_vcpu_apicv_active(kvm->vcpus[0]))
> + !irqchip_in_kernel(kvm) || !enable_apicv)
> return 0;
>
> idx = srcu_read_lock(&kvm->irq_srcu);
What happens then if pi_pre_block is called and the IRTE denotes a
posted interrupt?
I might be wrong, but it seems to me that you have to change all of the
occurrences this way. As soon as enable_apicv is set, you need to go
through the POSTED_INTR_WAKEUP_VECTOR just in case.
Paolo
^ permalink raw reply
* Re: [PATCH 1/5] KVM: Move wiping of the kvm->vcpus array to common code
From: Paolo Bonzini @ 2021-11-16 13:49 UTC (permalink / raw)
To: Marc Zyngier, Sean Christopherson
Cc: Juergen Gross, Alexandru Elisei, Anup Patel, Janosch Frank, kvm,
Christian Borntraeger, Huacai Chen, David Hildenbrand, linux-mips,
Nicholas Piggin, Atish Patra, Aleksandar Markovic, Paul Mackerras,
James Morse, kernel-team, Claudio Imbrenda, linuxppc-dev, kvmarm,
Suzuki K Poulose
In-Reply-To: <87o86xednu.wl-maz@kernel.org>
On 11/6/21 12:17, Marc Zyngier wrote:
>
> If you too believe that this is just wrong, I'm happy to drop the
> locking altogether. If that breaks someone's flow, they'll shout soon
> enough.
Yes, it's not necessary. It was added in 2009 (commit 988a2cae6a3c,
"KVM: Use macro to iterate over vcpus.") and it was unnecessary back
then too.
Paolo
^ permalink raw reply
* Re: [PATCH v2 3/5] powerpc: Use preemption model accessors
From: Christophe Leroy @ 2021-11-16 13:41 UTC (permalink / raw)
To: Valentin Schneider, linux-kernel, kasan-dev, linuxppc-dev,
linux-kbuild
Cc: Marco Elver, Michal Marek, Peter Zijlstra, Frederic Weisbecker,
Mike Galbraith, Nick Desaulniers, Steven Rostedt, Ingo Molnar,
Paul Mackerras, Masahiro Yamada, Dmitry Vyukov
In-Reply-To: <20211110202448.4054153-4-valentin.schneider@arm.com>
Le 10/11/2021 à 21:24, Valentin Schneider a écrit :
> Per PREEMPT_DYNAMIC, checking CONFIG_PREEMPT doesn't tell you the actual
> preemption model of the live kernel. Use the newly-introduced accessors
> instead.
Is that change worth it for now ? As far as I can see powerpc doesn't
have DYNAMIC PREEMPT, a lot of work needs to be done before being able
to use it:
- Implement GENERIC_ENTRY
- Implement STATIC_CALLS (already done on PPC32, to be done on PPC64)
>
> sched_init() -> preempt_dynamic_init() happens way before IRQs are set up,
> so this should be fine.
It looks like you are mixing up interrupts and IRQs (also known as
"external interrupts").
ISI (Instruction Storage Interrupt) and DSI (Data Storage Interrupt) for
instance are also interrupts. They happen everytime there is a page
fault so may happen pretty early.
Traps generated by WARN_ON() are also interrupts that may happen at any
time.
>
> Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
> ---
> arch/powerpc/kernel/interrupt.c | 2 +-
> arch/powerpc/kernel/traps.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
> index de10a2697258..c56c10b59be3 100644
> --- a/arch/powerpc/kernel/interrupt.c
> +++ b/arch/powerpc/kernel/interrupt.c
> @@ -552,7 +552,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
> /* Returning to a kernel context with local irqs enabled. */
> WARN_ON_ONCE(!(regs->msr & MSR_EE));
> again:
> - if (IS_ENABLED(CONFIG_PREEMPT)) {
> + if (is_preempt_full()) {
I think the cost of that additionnal test should be analysed. Maybe it's
worth not doing the test at all and check _TIF_NEED_RESCHED everytime,
unless that recurrent test is changed into a jump label as suggested in
patch 2.
> /* Return to preemptible kernel context */
> if (unlikely(current_thread_info()->flags & _TIF_NEED_RESCHED)) {
> if (preempt_count() == 0)
> diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
> index aac8c0412ff9..1cb31bbdc925 100644
> --- a/arch/powerpc/kernel/traps.c
> +++ b/arch/powerpc/kernel/traps.c
> @@ -265,7 +265,7 @@ static int __die(const char *str, struct pt_regs *regs, long err)
> printk("%s PAGE_SIZE=%luK%s%s%s%s%s%s %s\n",
> IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN) ? "LE" : "BE",
> PAGE_SIZE / 1024, get_mmu_str(),
> - IS_ENABLED(CONFIG_PREEMPT) ? " PREEMPT" : "",
> + is_preempt_full() ? " PREEMPT" : "",
> IS_ENABLED(CONFIG_SMP) ? " SMP" : "",
> IS_ENABLED(CONFIG_SMP) ? (" NR_CPUS=" __stringify(NR_CPUS)) : "",
> debug_pagealloc_enabled() ? " DEBUG_PAGEALLOC" : "",
>
Would it be interesting as well to know that we are indeed in a DYNAMIC
PREEMPT context when dying ?
Christophe
^ permalink raw reply
* [PATCH] powerpc/xive: Change IRQ domain to a tree domain
From: Cédric Le Goater @ 2021-11-16 13:40 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Marc Zyngier, Greg Kurz, stable, Cédric Le Goater
Commit 4f86a06e2d6e ("irqdomain: Make normal and nomap irqdomains
exclusive") introduced an IRQ_DOMAIN_FLAG_NO_MAP flag to isolate the
'nomap' domains still in use under the powerpc arch. With this new
flag, the revmap_tree of the IRQ domain is not used anymore. This
change broke the support of shared LSIs [1] in the XIVE driver because
it was relying on a lookup in the revmap_tree to query previously
mapped interrupts. Linux now creates two distinct IRQ mappings on the
same HW IRQ which can lead to unexpected behavior in the drivers.
The XIVE IRQ domain is not a direct mapping domain and its HW IRQ
interrupt number space is rather large : 1M/socket on POWER9 and
POWER10, change the XIVE driver to use a 'tree' domain type instead.
[1] For instance, a linux KVM guest with virtio-rng and virtio-balloon
devices.
Cc: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org # v5.14+
Fixes: 4f86a06e2d6e ("irqdomain: Make normal and nomap irqdomains exclusive")
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
Marc,
The Fixes tag is there because the patch in question revealed that
something was broken in XIVE. genirq is not in cause. However, I
don't know for PS3 and Cell. May be less critical for now.
arch/powerpc/sysdev/xive/common.c | 3 +--
arch/powerpc/sysdev/xive/Kconfig | 1 -
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
index fed6fd16c8f4..9d0f0fe25598 100644
--- a/arch/powerpc/sysdev/xive/common.c
+++ b/arch/powerpc/sysdev/xive/common.c
@@ -1536,8 +1536,7 @@ static const struct irq_domain_ops xive_irq_domain_ops = {
static void __init xive_init_host(struct device_node *np)
{
- xive_irq_domain = irq_domain_add_nomap(np, XIVE_MAX_IRQ,
- &xive_irq_domain_ops, NULL);
+ xive_irq_domain = irq_domain_add_tree(np, &xive_irq_domain_ops, NULL);
if (WARN_ON(xive_irq_domain == NULL))
return;
irq_set_default_host(xive_irq_domain);
diff --git a/arch/powerpc/sysdev/xive/Kconfig b/arch/powerpc/sysdev/xive/Kconfig
index 97796c6b63f0..785c292d104b 100644
--- a/arch/powerpc/sysdev/xive/Kconfig
+++ b/arch/powerpc/sysdev/xive/Kconfig
@@ -3,7 +3,6 @@ config PPC_XIVE
bool
select PPC_SMP_MUXED_IPI
select HARDIRQS_SW_RESEND
- select IRQ_DOMAIN_NOMAP
config PPC_XIVE_NATIVE
bool
--
2.31.1
^ permalink raw reply related
* Re: [PATCH v2 2/5] preempt/dynamic: Introduce preempt mode accessors
From: Christophe Leroy @ 2021-11-16 13:29 UTC (permalink / raw)
To: Valentin Schneider, linux-kernel, kasan-dev, linuxppc-dev,
linux-kbuild
Cc: Marco Elver, Michal Marek, Peter Zijlstra, Frederic Weisbecker,
Mike Galbraith, Nick Desaulniers, Steven Rostedt, Ingo Molnar,
Paul Mackerras, Masahiro Yamada, Dmitry Vyukov
In-Reply-To: <20211110202448.4054153-3-valentin.schneider@arm.com>
Le 10/11/2021 à 21:24, Valentin Schneider a écrit :
> CONFIG_PREEMPT{_NONE, _VOLUNTARY} designate either:
> o The build-time preemption model when !PREEMPT_DYNAMIC
> o The default boot-time preemption model when PREEMPT_DYNAMIC
>
> IOW, using those on PREEMPT_DYNAMIC kernels is meaningless - the actual
> model could have been set to something else by the "preempt=foo" cmdline
> parameter.
>
> Introduce a set of helpers to determine the actual preemption mode used by
> the live kernel.
>
> Suggested-by: Marco Elver <elver@google.com>
> Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
> ---
> include/linux/sched.h | 16 ++++++++++++++++
> kernel/sched/core.c | 11 +++++++++++
> 2 files changed, 27 insertions(+)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 5f8db54226af..0640d5622496 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -2073,6 +2073,22 @@ static inline void cond_resched_rcu(void)
> #endif
> }
>
> +#ifdef CONFIG_PREEMPT_DYNAMIC
> +
> +extern bool is_preempt_none(void);
> +extern bool is_preempt_voluntary(void);
> +extern bool is_preempt_full(void);
Those are trivial tests supposed to be used in fast pathes. They should
be static inlines in order to minimise the overhead.
> +
> +#else
> +
> +#define is_preempt_none() IS_ENABLED(CONFIG_PREEMPT_NONE)
> +#define is_preempt_voluntary() IS_ENABLED(CONFIG_PREEMPT_VOLUNTARY)
> +#define is_preempt_full() IS_ENABLED(CONFIG_PREEMPT)
Would be better to use static inlines here as well instead of macros.
> +
> +#endif
> +
> +#define is_preempt_rt() IS_ENABLED(CONFIG_PREEMPT_RT)
> +
> /*
> * Does a critical section need to be broken due to another
> * task waiting?: (technically does not depend on CONFIG_PREEMPTION,
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 97047aa7b6c2..9db7f77e53c3 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -6638,6 +6638,17 @@ static void __init preempt_dynamic_init(void)
> }
> }
>
> +#define PREEMPT_MODE_ACCESSOR(mode) \
> + bool is_preempt_##mode(void) \
> + { \
> + WARN_ON_ONCE(preempt_dynamic_mode == preempt_dynamic_undefined); \
Not sure using WARN_ON is a good idea here, as it may be called very
early, see comment on powerpc patch.
> + return preempt_dynamic_mode == preempt_dynamic_##mode; \
> + }
I'm not sure that's worth a macro. You only have 3 accessors, 2 lines of
code each. Just define all 3 in plain text.
CONFIG_PREEMPT_DYNAMIC is based on using strategies like static_calls in
order to minimise the overhead. For those accessors you should use the
same kind of approach and use things like jump_labels in order to not
redo the test at each time and minimise overhead as much as possible.
> +
> +PREEMPT_MODE_ACCESSOR(none)
> +PREEMPT_MODE_ACCESSOR(voluntary)
> +PREEMPT_MODE_ACCESSOR(full)
> +
> #else /* !CONFIG_PREEMPT_DYNAMIC */
>
> static inline void preempt_dynamic_init(void) { }
>
^ permalink raw reply
* [PATCH 4/7] KVM: mips: Use Makefile.kvm for common files
From: David Woodhouse @ 2021-11-16 11:50 UTC (permalink / raw)
To: Paolo Bonzini, kvm
Cc: Anup Patel, wanpengli @ tencent . com, Catalin Marinas,
Joao Martins, Will Deacon, kvmarm, linux-s390,
joro @ 8bytes . org, Huacai Chen, Christian Borntraeger,
Aleksandar Markovic, karahmed, Suzuki K Poulose, Boris Ostrovsky,
Alexandru Elisei, linux-arm-kernel, jmattson @ google . com,
seanjc @ google . com, mtosatti @ redhat . com, linux-mips,
James Morse, kvm-riscv, Marc Zyngier, vkuznets @ redhat . com,
linuxppc-dev
In-Reply-To: <20211116115051.119956-1-dwmw2@infradead.org>
From: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
arch/mips/kvm/Makefile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/mips/kvm/Makefile b/arch/mips/kvm/Makefile
index d3710959da55..21ff75bcdbc4 100644
--- a/arch/mips/kvm/Makefile
+++ b/arch/mips/kvm/Makefile
@@ -2,9 +2,10 @@
# Makefile for KVM support for MIPS
#
+include $(srctree)/virt/kvm/Makefile.kvm
+
ccflags-y += -Ivirt/kvm -Iarch/mips/kvm
-kvm-y := $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o eventfd.o binary_stats.o)
kvm-$(CONFIG_CPU_HAS_MSA) += msa.o
kvm-y += mips.o emulate.o entry.o \
--
2.31.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox