Skip to content

Commit a8ebfcd

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM fixes from Paolo Bonzini: "RISC-V: - Fix missing PAGE_PFN_MASK - Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests() x86: - Fix for nested virtualization when TSC scaling is active - Estimate the size of fastcc subroutines conservatively, avoiding disastrous underestimation when return thunks are enabled - Avoid possible use of uninitialized fields of 'struct kvm_lapic_irq' Generic: - Mark as such the boolean values available from the statistics file descriptors - Clarify statistics documentation" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: emulate: do not adjust size of fastop and setcc subroutines KVM: x86: Fully initialize 'struct kvm_lapic_irq' in kvm_pv_kick_cpu_op() Documentation: kvm: clarify histogram units kvm: stats: tell userspace which values are boolean x86/kvm: fix FASTOP_SIZE when return thunks are enabled KVM: nVMX: Always enable TSC scaling for L2 when it was enabled for L1 RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests() riscv: Fix missing PAGE_PFN_MASK
2 parents 1ce9d79 + 7962918 commit a8ebfcd

File tree

10 files changed

+54
-33
lines changed

10 files changed

+54
-33
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5657,6 +5657,7 @@ by a string of size ``name_size``.
56575657
#define KVM_STATS_UNIT_BYTES (0x1 << KVM_STATS_UNIT_SHIFT)
56585658
#define KVM_STATS_UNIT_SECONDS (0x2 << KVM_STATS_UNIT_SHIFT)
56595659
#define KVM_STATS_UNIT_CYCLES (0x3 << KVM_STATS_UNIT_SHIFT)
5660+
#define KVM_STATS_UNIT_BOOLEAN (0x4 << KVM_STATS_UNIT_SHIFT)
56605661
#define KVM_STATS_UNIT_MAX KVM_STATS_UNIT_CYCLES
56615662

56625663
#define KVM_STATS_BASE_SHIFT 8
@@ -5702,14 +5703,13 @@ Bits 0-3 of ``flags`` encode the type:
57025703
by the ``hist_param`` field. The range of the Nth bucket (1 <= N < ``size``)
57035704
is [``hist_param``*(N-1), ``hist_param``*N), while the range of the last
57045705
bucket is [``hist_param``*(``size``-1), +INF). (+INF means positive infinity
5705-
value.) The bucket value indicates how many samples fell in the bucket's range.
5706+
value.)
57065707
* ``KVM_STATS_TYPE_LOG_HIST``
57075708
The statistic is reported as a logarithmic histogram. The number of
57085709
buckets is specified by the ``size`` field. The range of the first bucket is
57095710
[0, 1), while the range of the last bucket is [pow(2, ``size``-2), +INF).
57105711
Otherwise, The Nth bucket (1 < N < ``size``) covers
5711-
[pow(2, N-2), pow(2, N-1)). The bucket value indicates how many samples fell
5712-
in the bucket's range.
5712+
[pow(2, N-2), pow(2, N-1)).
57135713

57145714
Bits 4-7 of ``flags`` encode the unit:
57155715

@@ -5724,6 +5724,15 @@ Bits 4-7 of ``flags`` encode the unit:
57245724
It indicates that the statistics data is used to measure time or latency.
57255725
* ``KVM_STATS_UNIT_CYCLES``
57265726
It indicates that the statistics data is used to measure CPU clock cycles.
5727+
* ``KVM_STATS_UNIT_BOOLEAN``
5728+
It indicates that the statistic will always be either 0 or 1. Boolean
5729+
statistics of "peak" type will never go back from 1 to 0. Boolean
5730+
statistics can be linear histograms (with two buckets) but not logarithmic
5731+
histograms.
5732+
5733+
Note that, in the case of histograms, the unit applies to the bucket
5734+
ranges, while the bucket value indicates how many samples fell in the
5735+
bucket's range.
57275736

57285737
Bits 8-11 of ``flags``, together with ``exponent``, encode the scale of the
57295738
unit:
@@ -5746,7 +5755,7 @@ the corresponding statistics data.
57465755

57475756
The ``bucket_size`` field is used as a parameter for histogram statistics data.
57485757
It is only used by linear histogram statistics data, specifying the size of a
5749-
bucket.
5758+
bucket in the unit expressed by bits 4-11 of ``flags`` together with ``exponent``.
57505759

57515760
The ``name`` field is the name string of the statistics data. The name string
57525761
starts at the end of ``struct kvm_stats_desc``. The maximum length including

arch/riscv/include/asm/pgtable-64.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static inline pud_t pfn_pud(unsigned long pfn, pgprot_t prot)
175175

176176
static inline unsigned long _pud_pfn(pud_t pud)
177177
{
178-
return pud_val(pud) >> _PAGE_PFN_SHIFT;
178+
return __page_val_to_pfn(pud_val(pud));
179179
}
180180

181181
static inline pmd_t *pud_pgtable(pud_t pud)
@@ -278,21 +278,21 @@ static inline p4d_t pfn_p4d(unsigned long pfn, pgprot_t prot)
278278

279279
static inline unsigned long _p4d_pfn(p4d_t p4d)
280280
{
281-
return p4d_val(p4d) >> _PAGE_PFN_SHIFT;
281+
return __page_val_to_pfn(p4d_val(p4d));
282282
}
283283

284284
static inline pud_t *p4d_pgtable(p4d_t p4d)
285285
{
286286
if (pgtable_l4_enabled)
287-
return (pud_t *)pfn_to_virt(p4d_val(p4d) >> _PAGE_PFN_SHIFT);
287+
return (pud_t *)pfn_to_virt(__page_val_to_pfn(p4d_val(p4d)));
288288

289289
return (pud_t *)pud_pgtable((pud_t) { p4d_val(p4d) });
290290
}
291291
#define p4d_page_vaddr(p4d) ((unsigned long)p4d_pgtable(p4d))
292292

293293
static inline struct page *p4d_page(p4d_t p4d)
294294
{
295-
return pfn_to_page(p4d_val(p4d) >> _PAGE_PFN_SHIFT);
295+
return pfn_to_page(__page_val_to_pfn(p4d_val(p4d)));
296296
}
297297

298298
#define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
@@ -347,15 +347,15 @@ static inline void pgd_clear(pgd_t *pgd)
347347
static inline p4d_t *pgd_pgtable(pgd_t pgd)
348348
{
349349
if (pgtable_l5_enabled)
350-
return (p4d_t *)pfn_to_virt(pgd_val(pgd) >> _PAGE_PFN_SHIFT);
350+
return (p4d_t *)pfn_to_virt(__page_val_to_pfn(pgd_val(pgd)));
351351

352352
return (p4d_t *)p4d_pgtable((p4d_t) { pgd_val(pgd) });
353353
}
354354
#define pgd_page_vaddr(pgd) ((unsigned long)pgd_pgtable(pgd))
355355

356356
static inline struct page *pgd_page(pgd_t pgd)
357357
{
358-
return pfn_to_page(pgd_val(pgd) >> _PAGE_PFN_SHIFT);
358+
return pfn_to_page(__page_val_to_pfn(pgd_val(pgd)));
359359
}
360360
#define pgd_page(pgd) pgd_page(pgd)
361361

arch/riscv/include/asm/pgtable.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static inline pgd_t pfn_pgd(unsigned long pfn, pgprot_t prot)
261261

262262
static inline unsigned long _pgd_pfn(pgd_t pgd)
263263
{
264-
return pgd_val(pgd) >> _PAGE_PFN_SHIFT;
264+
return __page_val_to_pfn(pgd_val(pgd));
265265
}
266266

267267
static inline struct page *pmd_page(pmd_t pmd)
@@ -590,14 +590,14 @@ static inline pmd_t pmd_mkinvalid(pmd_t pmd)
590590
return __pmd(pmd_val(pmd) & ~(_PAGE_PRESENT|_PAGE_PROT_NONE));
591591
}
592592

593-
#define __pmd_to_phys(pmd) (pmd_val(pmd) >> _PAGE_PFN_SHIFT << PAGE_SHIFT)
593+
#define __pmd_to_phys(pmd) (__page_val_to_pfn(pmd_val(pmd)) << PAGE_SHIFT)
594594

595595
static inline unsigned long pmd_pfn(pmd_t pmd)
596596
{
597597
return ((__pmd_to_phys(pmd) & PMD_MASK) >> PAGE_SHIFT);
598598
}
599599

600-
#define __pud_to_phys(pud) (pud_val(pud) >> _PAGE_PFN_SHIFT << PAGE_SHIFT)
600+
#define __pud_to_phys(pud) (__page_val_to_pfn(pud_val(pud)) << PAGE_SHIFT)
601601

602602
static inline unsigned long pud_pfn(pud_t pud)
603603
{

arch/riscv/kvm/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static inline unsigned long gstage_pte_index(gpa_t addr, u32 level)
5454

5555
static inline unsigned long gstage_pte_page_vaddr(pte_t pte)
5656
{
57-
return (unsigned long)pfn_to_virt(pte_val(pte) >> _PAGE_PFN_SHIFT);
57+
return (unsigned long)pfn_to_virt(__page_val_to_pfn(pte_val(pte)));
5858
}
5959

6060
static int gstage_page_size_to_level(unsigned long page_size, u32 *out_level)

arch/riscv/kvm/vcpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,11 @@ static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)
781781

782782
if (kvm_request_pending(vcpu)) {
783783
if (kvm_check_request(KVM_REQ_SLEEP, vcpu)) {
784+
kvm_vcpu_srcu_read_unlock(vcpu);
784785
rcuwait_wait_event(wait,
785786
(!vcpu->arch.power_off) && (!vcpu->arch.pause),
786787
TASK_INTERRUPTIBLE);
788+
kvm_vcpu_srcu_read_lock(vcpu);
787789

788790
if (vcpu->arch.power_off || vcpu->arch.pause) {
789791
/*

arch/x86/kvm/emulate.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@
189189
#define X8(x...) X4(x), X4(x)
190190
#define X16(x...) X8(x), X8(x)
191191

192-
#define NR_FASTOP (ilog2(sizeof(ulong)) + 1)
193-
#define FASTOP_SIZE (8 * (1 + HAS_KERNEL_IBT))
194-
195192
struct opcode {
196193
u64 flags;
197194
u8 intercept;
@@ -306,9 +303,15 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
306303
* Moreover, they are all exactly FASTOP_SIZE bytes long, so functions for
307304
* different operand sizes can be reached by calculation, rather than a jump
308305
* table (which would be bigger than the code).
306+
*
307+
* The 16 byte alignment, considering 5 bytes for the RET thunk, 3 for ENDBR
308+
* and 1 for the straight line speculation INT3, leaves 7 bytes for the
309+
* body of the function. Currently none is larger than 4.
309310
*/
310311
static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
311312

313+
#define FASTOP_SIZE 16
314+
312315
#define __FOP_FUNC(name) \
313316
".align " __stringify(FASTOP_SIZE) " \n\t" \
314317
".type " name ", @function \n\t" \
@@ -442,11 +445,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
442445
* RET | JMP __x86_return_thunk [1,5 bytes; CONFIG_RETHUNK]
443446
* INT3 [1 byte; CONFIG_SLS]
444447
*/
445-
#define RET_LENGTH (1 + (4 * IS_ENABLED(CONFIG_RETHUNK)) + \
446-
IS_ENABLED(CONFIG_SLS))
447-
#define SETCC_LENGTH (ENDBR_INSN_SIZE + 3 + RET_LENGTH)
448-
#define SETCC_ALIGN (4 << ((SETCC_LENGTH > 4) & 1) << ((SETCC_LENGTH > 8) & 1))
449-
static_assert(SETCC_LENGTH <= SETCC_ALIGN);
448+
#define SETCC_ALIGN 16
450449

451450
#define FOP_SETCC(op) \
452451
".align " __stringify(SETCC_ALIGN) " \n\t" \

arch/x86/kvm/vmx/nested.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,6 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct loaded_vmcs *vmcs0
22782278
SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY |
22792279
SECONDARY_EXEC_APIC_REGISTER_VIRT |
22802280
SECONDARY_EXEC_ENABLE_VMFUNC |
2281-
SECONDARY_EXEC_TSC_SCALING |
22822281
SECONDARY_EXEC_DESC);
22832282

22842283
if (nested_cpu_has(vmcs12,

arch/x86/kvm/x86.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
298298
STATS_DESC_COUNTER(VCPU, directed_yield_successful),
299299
STATS_DESC_COUNTER(VCPU, preemption_reported),
300300
STATS_DESC_COUNTER(VCPU, preemption_other),
301-
STATS_DESC_ICOUNTER(VCPU, guest_mode)
301+
STATS_DESC_IBOOLEAN(VCPU, guest_mode)
302302
};
303303

304304
const struct kvm_stats_header kvm_vcpu_stats_header = {
@@ -9143,15 +9143,17 @@ static int kvm_pv_clock_pairing(struct kvm_vcpu *vcpu, gpa_t paddr,
91439143
*/
91449144
static void kvm_pv_kick_cpu_op(struct kvm *kvm, int apicid)
91459145
{
9146-
struct kvm_lapic_irq lapic_irq;
9147-
9148-
lapic_irq.shorthand = APIC_DEST_NOSHORT;
9149-
lapic_irq.dest_mode = APIC_DEST_PHYSICAL;
9150-
lapic_irq.level = 0;
9151-
lapic_irq.dest_id = apicid;
9152-
lapic_irq.msi_redir_hint = false;
9146+
/*
9147+
* All other fields are unused for APIC_DM_REMRD, but may be consumed by
9148+
* common code, e.g. for tracing. Defer initialization to the compiler.
9149+
*/
9150+
struct kvm_lapic_irq lapic_irq = {
9151+
.delivery_mode = APIC_DM_REMRD,
9152+
.dest_mode = APIC_DEST_PHYSICAL,
9153+
.shorthand = APIC_DEST_NOSHORT,
9154+
.dest_id = apicid,
9155+
};
91539156

9154-
lapic_irq.delivery_mode = APIC_DM_REMRD;
91559157
kvm_irq_delivery_to_apic(kvm, NULL, &lapic_irq, NULL);
91569158
}
91579159

include/linux/kvm_host.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,15 @@ struct _kvm_stats_desc {
18221822
STATS_DESC_PEAK(SCOPE, name, KVM_STATS_UNIT_NONE, \
18231823
KVM_STATS_BASE_POW10, 0)
18241824

1825+
/* Instantaneous boolean value, read only */
1826+
#define STATS_DESC_IBOOLEAN(SCOPE, name) \
1827+
STATS_DESC_INSTANT(SCOPE, name, KVM_STATS_UNIT_BOOLEAN, \
1828+
KVM_STATS_BASE_POW10, 0)
1829+
/* Peak (sticky) boolean value, read/write */
1830+
#define STATS_DESC_PBOOLEAN(SCOPE, name) \
1831+
STATS_DESC_PEAK(SCOPE, name, KVM_STATS_UNIT_BOOLEAN, \
1832+
KVM_STATS_BASE_POW10, 0)
1833+
18251834
/* Cumulative time in nanosecond */
18261835
#define STATS_DESC_TIME_NSEC(SCOPE, name) \
18271836
STATS_DESC_CUMULATIVE(SCOPE, name, KVM_STATS_UNIT_SECONDS, \
@@ -1853,7 +1862,7 @@ struct _kvm_stats_desc {
18531862
HALT_POLL_HIST_COUNT), \
18541863
STATS_DESC_LOGHIST_TIME_NSEC(VCPU_GENERIC, halt_wait_hist, \
18551864
HALT_POLL_HIST_COUNT), \
1856-
STATS_DESC_ICOUNTER(VCPU_GENERIC, blocking)
1865+
STATS_DESC_IBOOLEAN(VCPU_GENERIC, blocking)
18571866

18581867
extern struct dentry *kvm_debugfs_dir;
18591868

include/uapi/linux/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,7 @@ struct kvm_stats_header {
20832083
#define KVM_STATS_UNIT_BYTES (0x1 << KVM_STATS_UNIT_SHIFT)
20842084
#define KVM_STATS_UNIT_SECONDS (0x2 << KVM_STATS_UNIT_SHIFT)
20852085
#define KVM_STATS_UNIT_CYCLES (0x3 << KVM_STATS_UNIT_SHIFT)
2086+
#define KVM_STATS_UNIT_BOOLEAN (0x4 << KVM_STATS_UNIT_SHIFT)
20862087
#define KVM_STATS_UNIT_MAX KVM_STATS_UNIT_CYCLES
20872088

20882089
#define KVM_STATS_BASE_SHIFT 8

0 commit comments

Comments
 (0)