Skip to content

Commit 086aca1

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini: "s390: - vsie: Fix races with partial gmap invalidations x86: - Use __DECLARE_FLEX_ARRAY() for UAPI structures with VLAs" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: s390: vsie: Fix races with partial gmap invalidations KVM: x86: Use __DECLARE_FLEX_ARRAY() for UAPI structures with VLAs
2 parents 558b920 + 1fe7294 commit 086aca1

5 files changed

Lines changed: 21 additions & 15 deletions

File tree

arch/s390/kvm/gaccess.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ static int _do_shadow_pte(struct gmap *sg, gpa_t raddr, union pte *ptep_h, union
14491449
pgste_set_unlock(ptep_h, pgste);
14501450
if (rc)
14511451
return rc;
1452-
if (!sg->parent)
1452+
if (sg->invalidated)
14531453
return -EAGAIN;
14541454

14551455
newpte = _pte(f->pfn, 0, !p, 0);
@@ -1479,7 +1479,7 @@ static int _do_shadow_crste(struct gmap *sg, gpa_t raddr, union crste *host, uni
14791479

14801480
do {
14811481
/* _gmap_crstep_xchg_atomic() could have unshadowed this shadow gmap */
1482-
if (!sg->parent)
1482+
if (sg->invalidated)
14831483
return -EAGAIN;
14841484
oldcrste = READ_ONCE(*host);
14851485
newcrste = _crste_fc1(f->pfn, oldcrste.h.tt, f->writable, !p);
@@ -1492,7 +1492,7 @@ static int _do_shadow_crste(struct gmap *sg, gpa_t raddr, union crste *host, uni
14921492
if (!newcrste.h.p && !f->writable)
14931493
return -EOPNOTSUPP;
14941494
} while (!_gmap_crstep_xchg_atomic(sg->parent, host, oldcrste, newcrste, f->gfn, false));
1495-
if (!sg->parent)
1495+
if (sg->invalidated)
14961496
return -EAGAIN;
14971497

14981498
newcrste = _crste_fc1(f->pfn, oldcrste.h.tt, 0, !p);
@@ -1545,7 +1545,7 @@ static int _gaccess_do_shadow(struct kvm_s390_mmu_cache *mc, struct gmap *sg,
15451545
entries[i].pfn, i + 1, entries[i].writable);
15461546
if (rc)
15471547
return rc;
1548-
if (!sg->parent)
1548+
if (sg->invalidated)
15491549
return -EAGAIN;
15501550
}
15511551

@@ -1601,6 +1601,7 @@ static inline int _gaccess_shadow_fault(struct kvm_vcpu *vcpu, struct gmap *sg,
16011601
scoped_guard(spinlock, &parent->children_lock) {
16021602
if (READ_ONCE(sg->parent) != parent)
16031603
return -EAGAIN;
1604+
sg->invalidated = false;
16041605
rc = _gaccess_do_shadow(vcpu->arch.mc, sg, saddr, walk);
16051606
}
16061607
if (rc == -ENOMEM)

arch/s390/kvm/gmap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ void gmap_remove_child(struct gmap *child)
181181

182182
list_del(&child->list);
183183
child->parent = NULL;
184+
child->invalidated = true;
184185
}
185186

186187
/**
@@ -1069,6 +1070,7 @@ static void gmap_unshadow_level(struct gmap *sg, gfn_t r_gfn, int level)
10691070
if (level > TABLE_TYPE_PAGE_TABLE)
10701071
align = 1UL << (11 * level + _SEGMENT_SHIFT);
10711072
kvm_s390_vsie_gmap_notifier(sg, ALIGN_DOWN(gaddr, align), ALIGN(gaddr + 1, align));
1073+
sg->invalidated = true;
10721074
if (dat_entry_walk(NULL, r_gfn, sg->asce, 0, level, &crstep, &ptep))
10731075
return;
10741076
if (ptep) {
@@ -1174,6 +1176,7 @@ static inline int __gmap_protect_asce_top_level(struct kvm_s390_mmu_cache *mc, s
11741176
scoped_guard(spinlock, &parent->children_lock) {
11751177
if (READ_ONCE(sg->parent) != parent)
11761178
return -EAGAIN;
1179+
sg->invalidated = false;
11771180
for (i = 0; i < CRST_TABLE_PAGES; i++) {
11781181
if (!context->f[i].valid)
11791182
continue;

arch/s390/kvm/gmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum gmap_flags {
6060
struct gmap {
6161
unsigned long flags;
6262
unsigned char edat_level;
63+
bool invalidated;
6364
struct kvm *kvm;
6465
union asce asce;
6566
struct list_head list;

arch/x86/include/uapi/asm/kvm.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ struct kvm_msrs {
197197
__u32 nmsrs; /* number of msrs in entries */
198198
__u32 pad;
199199

200-
struct kvm_msr_entry entries[];
200+
__DECLARE_FLEX_ARRAY(struct kvm_msr_entry, entries);
201201
};
202202

203203
/* for KVM_GET_MSR_INDEX_LIST */
204204
struct kvm_msr_list {
205205
__u32 nmsrs; /* number of msrs in entries */
206-
__u32 indices[];
206+
__DECLARE_FLEX_ARRAY(__u32, indices);
207207
};
208208

209209
/* Maximum size of any access bitmap in bytes */
@@ -245,7 +245,7 @@ struct kvm_cpuid_entry {
245245
struct kvm_cpuid {
246246
__u32 nent;
247247
__u32 padding;
248-
struct kvm_cpuid_entry entries[];
248+
__DECLARE_FLEX_ARRAY(struct kvm_cpuid_entry, entries);
249249
};
250250

251251
struct kvm_cpuid_entry2 {
@@ -267,7 +267,7 @@ struct kvm_cpuid_entry2 {
267267
struct kvm_cpuid2 {
268268
__u32 nent;
269269
__u32 padding;
270-
struct kvm_cpuid_entry2 entries[];
270+
__DECLARE_FLEX_ARRAY(struct kvm_cpuid_entry2, entries);
271271
};
272272

273273
/* for KVM_GET_PIT and KVM_SET_PIT */
@@ -398,7 +398,7 @@ struct kvm_xsave {
398398
* the contents of CPUID leaf 0xD on the host.
399399
*/
400400
__u32 region[1024];
401-
__u32 extra[];
401+
__DECLARE_FLEX_ARRAY(__u32, extra);
402402
};
403403

404404
#define KVM_MAX_XCRS 16
@@ -566,7 +566,7 @@ struct kvm_pmu_event_filter {
566566
__u32 fixed_counter_bitmap;
567567
__u32 flags;
568568
__u32 pad[4];
569-
__u64 events[];
569+
__DECLARE_FLEX_ARRAY(__u64, events);
570570
};
571571

572572
#define KVM_PMU_EVENT_ALLOW 0

include/uapi/linux/kvm.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/const.h>
1212
#include <linux/types.h>
1313
#include <linux/compiler.h>
14+
#include <linux/stddef.h>
1415
#include <linux/ioctl.h>
1516
#include <asm/kvm.h>
1617

@@ -542,7 +543,7 @@ struct kvm_coalesced_mmio {
542543

543544
struct kvm_coalesced_mmio_ring {
544545
__u32 first, last;
545-
struct kvm_coalesced_mmio coalesced_mmio[];
546+
__DECLARE_FLEX_ARRAY(struct kvm_coalesced_mmio, coalesced_mmio);
546547
};
547548

548549
#define KVM_COALESCED_MMIO_MAX \
@@ -592,7 +593,7 @@ struct kvm_clear_dirty_log {
592593
/* for KVM_SET_SIGNAL_MASK */
593594
struct kvm_signal_mask {
594595
__u32 len;
595-
__u8 sigset[];
596+
__DECLARE_FLEX_ARRAY(__u8, sigset);
596597
};
597598

598599
/* for KVM_TPR_ACCESS_REPORTING */
@@ -1051,7 +1052,7 @@ struct kvm_irq_routing_entry {
10511052
struct kvm_irq_routing {
10521053
__u32 nr;
10531054
__u32 flags;
1054-
struct kvm_irq_routing_entry entries[];
1055+
__DECLARE_FLEX_ARRAY(struct kvm_irq_routing_entry, entries);
10551056
};
10561057

10571058
#define KVM_IRQFD_FLAG_DEASSIGN (1 << 0)
@@ -1142,7 +1143,7 @@ struct kvm_dirty_tlb {
11421143

11431144
struct kvm_reg_list {
11441145
__u64 n; /* number of regs */
1145-
__u64 reg[];
1146+
__DECLARE_FLEX_ARRAY(__u64, reg);
11461147
};
11471148

11481149
struct kvm_one_reg {
@@ -1608,7 +1609,7 @@ struct kvm_stats_desc {
16081609
#ifdef __KERNEL__
16091610
char name[KVM_STATS_NAME_SIZE];
16101611
#else
1611-
char name[];
1612+
__DECLARE_FLEX_ARRAY(char, name);
16121613
#endif
16131614
};
16141615

0 commit comments

Comments
 (0)