Skip to content

Commit 4f712ee

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm updates from Paolo Bonzini: "S390: - Changes to FPU handling came in via the main s390 pull request - Only deliver to the guest the SCLP events that userspace has requested - More virtual vs physical address fixes (only a cleanup since virtual and physical address spaces are currently the same) - Fix selftests undefined behavior x86: - Fix a restriction that the guest can't program a PMU event whose encoding matches an architectural event that isn't included in the guest CPUID. The enumeration of an architectural event only says that if a CPU supports an architectural event, then the event can be programmed *using the architectural encoding*. The enumeration does NOT say anything about the encoding when the CPU doesn't report support the event *in general*. It might support it, and it might support it using the same encoding that made it into the architectural PMU spec - Fix a variety of bugs in KVM's emulation of RDPMC (more details on individual commits) and add a selftest to verify KVM correctly emulates RDMPC, counter availability, and a variety of other PMC-related behaviors that depend on guest CPUID and therefore are easier to validate with selftests than with custom guests (aka kvm-unit-tests) - Zero out PMU state on AMD if the virtual PMU is disabled, it does not cause any bug but it wastes time in various cases where KVM would check if a PMC event needs to be synthesized - Optimize triggering of emulated events, with a nice ~10% performance improvement in VM-Exit microbenchmarks when a vPMU is exposed to the guest - Tighten the check for "PMI in guest" to reduce false positives if an NMI arrives in the host while KVM is handling an IRQ VM-Exit - Fix a bug where KVM would report stale/bogus exit qualification information when exiting to userspace with an internal error exit code - Add a VMX flag in /proc/cpuinfo to report 5-level EPT support - Rework TDP MMU root unload, free, and alloc to run with mmu_lock held for read, e.g. to avoid serializing vCPUs when userspace deletes a memslot - Tear down TDP MMU page tables at 4KiB granularity (used to be 1GiB). KVM doesn't support yielding in the middle of processing a zap, and 1GiB granularity resulted in multi-millisecond lags that are quite impolite for CONFIG_PREEMPT kernels - Allocate write-tracking metadata on-demand to avoid the memory overhead when a kernel is built with i915 virtualization support but the workloads use neither shadow paging nor i915 virtualization - Explicitly initialize a variety of on-stack variables in the emulator that triggered KMSAN false positives - Fix the debugregs ABI for 32-bit KVM - Rework the "force immediate exit" code so that vendor code ultimately decides how and when to force the exit, which allowed some optimization for both Intel and AMD - Fix a long-standing bug where kvm_has_noapic_vcpu could be left elevated if vCPU creation ultimately failed, causing extra unnecessary work - Cleanup the logic for checking if the currently loaded vCPU is in-kernel - Harden against underflowing the active mmu_notifier invalidation count, so that "bad" invalidations (usually due to bugs elsehwere in the kernel) are detected earlier and are less likely to hang the kernel x86 Xen emulation: - Overlay pages can now be cached based on host virtual address, instead of guest physical addresses. This removes the need to reconfigure and invalidate the cache if the guest changes the gpa but the underlying host virtual address remains the same - When possible, use a single host TSC value when computing the deadline for Xen timers in order to improve the accuracy of the timer emulation - Inject pending upcall events when the vCPU software-enables its APIC to fix a bug where an upcall can be lost (and to follow Xen's behavior) - Fall back to the slow path instead of warning if "fast" IRQ delivery of Xen events fails, e.g. if the guest has aliased xAPIC IDs RISC-V: - Support exception and interrupt handling in selftests - New self test for RISC-V architectural timer (Sstc extension) - New extension support (Ztso, Zacas) - Support userspace emulation of random number seed CSRs ARM: - Infrastructure for building KVM's trap configuration based on the architectural features (or lack thereof) advertised in the VM's ID registers - Support for mapping vfio-pci BARs as Normal-NC (vaguely similar to x86's WC) at stage-2, improving the performance of interacting with assigned devices that can tolerate it - Conversion of KVM's representation of LPIs to an xarray, utilized to address serialization some of the serialization on the LPI injection path - Support for _architectural_ VHE-only systems, advertised through the absence of FEAT_E2H0 in the CPU's ID register - Miscellaneous cleanups, fixes, and spelling corrections to KVM and selftests LoongArch: - Set reserved bits as zero in CPUCFG - Start SW timer only when vcpu is blocking - Do not restart SW timer when it is expired - Remove unnecessary CSR register saving during enter guest - Misc cleanups and fixes as usual Generic: - Clean up Kconfig by removing CONFIG_HAVE_KVM, which was basically always true on all architectures except MIPS (where Kconfig determines the available depending on CPU capabilities). It is replaced either by an architecture-dependent symbol for MIPS, and IS_ENABLED(CONFIG_KVM) everywhere else - Factor common "select" statements in common code instead of requiring each architecture to specify it - Remove thoroughly obsolete APIs from the uapi headers - Move architecture-dependent stuff to uapi/asm/kvm.h - Always flush the async page fault workqueue when a work item is being removed, especially during vCPU destruction, to ensure that there are no workers running in KVM code when all references to KVM-the-module are gone, i.e. to prevent a very unlikely use-after-free if kvm.ko is unloaded - Grab a reference to the VM's mm_struct in the async #PF worker itself instead of gifting the worker a reference, so that there's no need to remember to *conditionally* clean up after the worker Selftests: - Reduce boilerplate especially when utilize selftest TAP infrastructure - Add basic smoke tests for SEV and SEV-ES, along with a pile of library support for handling private/encrypted/protected memory - Fix benign bugs where tests neglect to close() guest_memfd files" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (246 commits) selftests: kvm: remove meaningless assignments in Makefiles KVM: riscv: selftests: Add Zacas extension to get-reg-list test RISC-V: KVM: Allow Zacas extension for Guest/VM KVM: riscv: selftests: Add Ztso extension to get-reg-list test RISC-V: KVM: Allow Ztso extension for Guest/VM RISC-V: KVM: Forward SEED CSR access to user space KVM: riscv: selftests: Add sstc timer test KVM: riscv: selftests: Change vcpu_has_ext to a common function KVM: riscv: selftests: Add guest helper to get vcpu id KVM: riscv: selftests: Add exception handling support LoongArch: KVM: Remove unnecessary CSR register saving during enter guest LoongArch: KVM: Do not restart SW timer when it is expired LoongArch: KVM: Start SW timer only when vcpu is blocking LoongArch: KVM: Set reserved bits as zero in CPUCFG KVM: selftests: Explicitly close guest_memfd files in some gmem tests KVM: x86/xen: fix recursive deadlock in timer injection KVM: pfncache: simplify locking and make more self-contained KVM: x86/xen: remove WARN_ON_ONCE() with false positives in evtchn delivery KVM: x86/xen: inject vCPU upcall vector when local APIC is enabled KVM: x86/xen: improve accuracy of Xen timers ...
2 parents 8a2fbff + 4781179 commit 4f712ee

File tree

179 files changed

+6663
-2718
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+6663
-2718
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ The bits in the dirty bitmap are cleared before the ioctl returns, unless
372372
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is enabled. For more information,
373373
see the description of the capability.
374374

375-
Note that the Xen shared info page, if configured, shall always be assumed
375+
Note that the Xen shared_info page, if configured, shall always be assumed
376376
to be dirty. KVM will not explicitly mark it such.
377377

378378

@@ -5487,8 +5487,9 @@ KVM_PV_ASYNC_CLEANUP_PERFORM
54875487
__u8 long_mode;
54885488
__u8 vector;
54895489
__u8 runstate_update_flag;
5490-
struct {
5490+
union {
54915491
__u64 gfn;
5492+
__u64 hva;
54925493
} shared_info;
54935494
struct {
54945495
__u32 send_port;
@@ -5516,19 +5517,20 @@ type values:
55165517

55175518
KVM_XEN_ATTR_TYPE_LONG_MODE
55185519
Sets the ABI mode of the VM to 32-bit or 64-bit (long mode). This
5519-
determines the layout of the shared info pages exposed to the VM.
5520+
determines the layout of the shared_info page exposed to the VM.
55205521

55215522
KVM_XEN_ATTR_TYPE_SHARED_INFO
5522-
Sets the guest physical frame number at which the Xen "shared info"
5523+
Sets the guest physical frame number at which the Xen shared_info
55235524
page resides. Note that although Xen places vcpu_info for the first
55245525
32 vCPUs in the shared_info page, KVM does not automatically do so
5525-
and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used
5526-
explicitly even when the vcpu_info for a given vCPU resides at the
5527-
"default" location in the shared_info page. This is because KVM may
5528-
not be aware of the Xen CPU id which is used as the index into the
5529-
vcpu_info[] array, so may know the correct default location.
5530-
5531-
Note that the shared info page may be constantly written to by KVM;
5526+
and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO or
5527+
KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO_HVA be used explicitly even when
5528+
the vcpu_info for a given vCPU resides at the "default" location
5529+
in the shared_info page. This is because KVM may not be aware of
5530+
the Xen CPU id which is used as the index into the vcpu_info[]
5531+
array, so may know the correct default location.
5532+
5533+
Note that the shared_info page may be constantly written to by KVM;
55325534
it contains the event channel bitmap used to deliver interrupts to
55335535
a Xen guest, amongst other things. It is exempt from dirty tracking
55345536
mechanisms — KVM will not explicitly mark the page as dirty each
@@ -5537,9 +5539,21 @@ KVM_XEN_ATTR_TYPE_SHARED_INFO
55375539
any vCPU has been running or any event channel interrupts can be
55385540
routed to the guest.
55395541

5540-
Setting the gfn to KVM_XEN_INVALID_GFN will disable the shared info
5542+
Setting the gfn to KVM_XEN_INVALID_GFN will disable the shared_info
55415543
page.
55425544

5545+
KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA
5546+
If the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA flag is also set in the
5547+
Xen capabilities, then this attribute may be used to set the
5548+
userspace address at which the shared_info page resides, which
5549+
will always be fixed in the VMM regardless of where it is mapped
5550+
in guest physical address space. This attribute should be used in
5551+
preference to KVM_XEN_ATTR_TYPE_SHARED_INFO as it avoids
5552+
unnecessary invalidation of an internal cache when the page is
5553+
re-mapped in guest physcial address space.
5554+
5555+
Setting the hva to zero will disable the shared_info page.
5556+
55435557
KVM_XEN_ATTR_TYPE_UPCALL_VECTOR
55445558
Sets the exception vector used to deliver Xen event channel upcalls.
55455559
This is the HVM-wide vector injected directly by the hypervisor
@@ -5636,6 +5650,21 @@ KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO
56365650
on dirty logging. Setting the gpa to KVM_XEN_INVALID_GPA will disable
56375651
the vcpu_info.
56385652

5653+
KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO_HVA
5654+
If the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA flag is also set in the
5655+
Xen capabilities, then this attribute may be used to set the
5656+
userspace address of the vcpu_info for a given vCPU. It should
5657+
only be used when the vcpu_info resides at the "default" location
5658+
in the shared_info page. In this case it is safe to assume the
5659+
userspace address will not change, because the shared_info page is
5660+
an overlay on guest memory and remains at a fixed host address
5661+
regardless of where it is mapped in guest physical address space
5662+
and hence unnecessary invalidation of an internal cache may be
5663+
avoided if the guest memory layout is modified.
5664+
If the vcpu_info does not reside at the "default" location then
5665+
it is not guaranteed to remain at the same host address and
5666+
hence the aforementioned cache invalidation is required.
5667+
56395668
KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO
56405669
Sets the guest physical address of an additional pvclock structure
56415670
for a given vCPU. This is typically used for guest vsyscall support.

arch/arm64/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ config ARM64
216216
select HAVE_HW_BREAKPOINT if PERF_EVENTS
217217
select HAVE_IOREMAP_PROT
218218
select HAVE_IRQ_TIME_ACCOUNTING
219-
select HAVE_KVM
220219
select HAVE_MOD_ARCH_SPECIFIC
221220
select HAVE_NMI
222221
select HAVE_PERF_EVENTS

arch/arm64/include/asm/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct cpuinfo_arm64 {
5757
u64 reg_id_aa64mmfr1;
5858
u64 reg_id_aa64mmfr2;
5959
u64 reg_id_aa64mmfr3;
60+
u64 reg_id_aa64mmfr4;
6061
u64 reg_id_aa64pfr0;
6162
u64 reg_id_aa64pfr1;
6263
u64 reg_id_aa64pfr2;

arch/arm64/include/asm/cpufeature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ struct arm64_cpu_capabilities {
364364
u8 field_pos;
365365
u8 field_width;
366366
u8 min_field_value;
367+
u8 max_field_value;
367368
u8 hwcap_type;
368369
bool sign;
369370
unsigned long hwcap;

arch/arm64/include/asm/kvm_arm.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@
102102
#define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC)
103103
#define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H)
104104

105-
#define HCRX_GUEST_FLAGS \
106-
(HCRX_EL2_SMPME | HCRX_EL2_TCR2En | \
107-
(cpus_have_final_cap(ARM64_HAS_MOPS) ? (HCRX_EL2_MSCEn | HCRX_EL2_MCE2) : 0))
105+
#define HCRX_GUEST_FLAGS (HCRX_EL2_SMPME | HCRX_EL2_TCR2En)
108106
#define HCRX_HOST_FLAGS (HCRX_EL2_MSCEn | HCRX_EL2_TCR2En | HCRX_EL2_EnFPM)
109107

110108
/* TCR_EL2 Registers bits */

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ static inline bool vcpu_is_el2(const struct kvm_vcpu *vcpu)
209209

210210
static inline bool __vcpu_el2_e2h_is_set(const struct kvm_cpu_context *ctxt)
211211
{
212-
return ctxt_sys_reg(ctxt, HCR_EL2) & HCR_E2H;
212+
return (!cpus_have_final_cap(ARM64_HAS_HCR_NV1) ||
213+
(ctxt_sys_reg(ctxt, HCR_EL2) & HCR_E2H));
213214
}
214215

215216
static inline bool vcpu_el2_e2h_is_set(const struct kvm_vcpu *vcpu)

arch/arm64/include/asm/kvm_host.h

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,32 @@ static inline u16 kvm_mpidr_index(struct kvm_mpidr_data *data, u64 mpidr)
238238
return index;
239239
}
240240

241+
struct kvm_sysreg_masks;
242+
243+
enum fgt_group_id {
244+
__NO_FGT_GROUP__,
245+
HFGxTR_GROUP,
246+
HDFGRTR_GROUP,
247+
HDFGWTR_GROUP = HDFGRTR_GROUP,
248+
HFGITR_GROUP,
249+
HAFGRTR_GROUP,
250+
251+
/* Must be last */
252+
__NR_FGT_GROUP_IDS__
253+
};
254+
241255
struct kvm_arch {
242256
struct kvm_s2_mmu mmu;
243257

258+
/*
259+
* Fine-Grained UNDEF, mimicking the FGT layout defined by the
260+
* architecture. We track them globally, as we present the
261+
* same feature-set to all vcpus.
262+
*
263+
* Index 0 is currently spare.
264+
*/
265+
u64 fgu[__NR_FGT_GROUP_IDS__];
266+
244267
/* Interrupt controller */
245268
struct vgic_dist vgic;
246269

@@ -274,6 +297,8 @@ struct kvm_arch {
274297
#define KVM_ARCH_FLAG_TIMER_PPIS_IMMUTABLE 6
275298
/* Initial ID reg values loaded */
276299
#define KVM_ARCH_FLAG_ID_REGS_INITIALIZED 7
300+
/* Fine-Grained UNDEF initialised */
301+
#define KVM_ARCH_FLAG_FGU_INITIALIZED 8
277302
unsigned long flags;
278303

279304
/* VM-wide vCPU feature set */
@@ -294,6 +319,9 @@ struct kvm_arch {
294319
/* PMCR_EL0.N value for the guest */
295320
u8 pmcr_n;
296321

322+
/* Iterator for idreg debugfs */
323+
u8 idreg_debugfs_iter;
324+
297325
/* Hypercall features firmware registers' descriptor */
298326
struct kvm_smccc_features smccc_feat;
299327
struct maple_tree smccc_filter;
@@ -312,6 +340,9 @@ struct kvm_arch {
312340
#define KVM_ARM_ID_REG_NUM (IDREG_IDX(sys_reg(3, 0, 0, 7, 7)) + 1)
313341
u64 id_regs[KVM_ARM_ID_REG_NUM];
314342

343+
/* Masks for VNCR-baked sysregs */
344+
struct kvm_sysreg_masks *sysreg_masks;
345+
315346
/*
316347
* For an untrusted host VM, 'pkvm.handle' is used to lookup
317348
* the associated pKVM instance in the hypervisor.
@@ -474,6 +505,13 @@ enum vcpu_sysreg {
474505
NR_SYS_REGS /* Nothing after this line! */
475506
};
476507

508+
struct kvm_sysreg_masks {
509+
struct {
510+
u64 res0;
511+
u64 res1;
512+
} mask[NR_SYS_REGS - __VNCR_START__];
513+
};
514+
477515
struct kvm_cpu_context {
478516
struct user_pt_regs regs; /* sp = sp_el0 */
479517

@@ -550,6 +588,7 @@ struct kvm_vcpu_arch {
550588

551589
/* Values of trap registers for the guest. */
552590
u64 hcr_el2;
591+
u64 hcrx_el2;
553592
u64 mdcr_el2;
554593
u64 cptr_el2;
555594

@@ -869,7 +908,15 @@ static inline u64 *__ctxt_sys_reg(const struct kvm_cpu_context *ctxt, int r)
869908

870909
#define ctxt_sys_reg(c,r) (*__ctxt_sys_reg(c,r))
871910

872-
#define __vcpu_sys_reg(v,r) (ctxt_sys_reg(&(v)->arch.ctxt, (r)))
911+
u64 kvm_vcpu_sanitise_vncr_reg(const struct kvm_vcpu *, enum vcpu_sysreg);
912+
#define __vcpu_sys_reg(v,r) \
913+
(*({ \
914+
const struct kvm_cpu_context *ctxt = &(v)->arch.ctxt; \
915+
u64 *__r = __ctxt_sys_reg(ctxt, (r)); \
916+
if (vcpu_has_nv((v)) && (r) >= __VNCR_START__) \
917+
*__r = kvm_vcpu_sanitise_vncr_reg((v), (r)); \
918+
__r; \
919+
}))
873920

874921
u64 vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg);
875922
void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg);
@@ -1056,14 +1103,20 @@ int kvm_handle_cp15_64(struct kvm_vcpu *vcpu);
10561103
int kvm_handle_sys_reg(struct kvm_vcpu *vcpu);
10571104
int kvm_handle_cp10_id(struct kvm_vcpu *vcpu);
10581105

1106+
void kvm_sys_regs_create_debugfs(struct kvm *kvm);
10591107
void kvm_reset_sys_regs(struct kvm_vcpu *vcpu);
10601108

10611109
int __init kvm_sys_reg_table_init(void);
1110+
struct sys_reg_desc;
1111+
int __init populate_sysreg_config(const struct sys_reg_desc *sr,
1112+
unsigned int idx);
10621113
int __init populate_nv_trap_config(void);
10631114

10641115
bool lock_all_vcpus(struct kvm *kvm);
10651116
void unlock_all_vcpus(struct kvm *kvm);
10661117

1118+
void kvm_init_sysreg(struct kvm_vcpu *);
1119+
10671120
/* MMIO helpers */
10681121
void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data);
10691122
unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);
@@ -1234,4 +1287,48 @@ static inline void kvm_hyp_reserve(void) { }
12341287
void kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu);
12351288
bool kvm_arm_vcpu_stopped(struct kvm_vcpu *vcpu);
12361289

1290+
#define __expand_field_sign_unsigned(id, fld, val) \
1291+
((u64)SYS_FIELD_VALUE(id, fld, val))
1292+
1293+
#define __expand_field_sign_signed(id, fld, val) \
1294+
({ \
1295+
u64 __val = SYS_FIELD_VALUE(id, fld, val); \
1296+
sign_extend64(__val, id##_##fld##_WIDTH - 1); \
1297+
})
1298+
1299+
#define expand_field_sign(id, fld, val) \
1300+
(id##_##fld##_SIGNED ? \
1301+
__expand_field_sign_signed(id, fld, val) : \
1302+
__expand_field_sign_unsigned(id, fld, val))
1303+
1304+
#define get_idreg_field_unsigned(kvm, id, fld) \
1305+
({ \
1306+
u64 __val = IDREG((kvm), SYS_##id); \
1307+
FIELD_GET(id##_##fld##_MASK, __val); \
1308+
})
1309+
1310+
#define get_idreg_field_signed(kvm, id, fld) \
1311+
({ \
1312+
u64 __val = get_idreg_field_unsigned(kvm, id, fld); \
1313+
sign_extend64(__val, id##_##fld##_WIDTH - 1); \
1314+
})
1315+
1316+
#define get_idreg_field_enum(kvm, id, fld) \
1317+
get_idreg_field_unsigned(kvm, id, fld)
1318+
1319+
#define get_idreg_field(kvm, id, fld) \
1320+
(id##_##fld##_SIGNED ? \
1321+
get_idreg_field_signed(kvm, id, fld) : \
1322+
get_idreg_field_unsigned(kvm, id, fld))
1323+
1324+
#define kvm_has_feat(kvm, id, fld, limit) \
1325+
(get_idreg_field((kvm), id, fld) >= expand_field_sign(id, fld, limit))
1326+
1327+
#define kvm_has_feat_enum(kvm, id, fld, val) \
1328+
(get_idreg_field_unsigned((kvm), id, fld) == __expand_field_sign_unsigned(id, fld, val))
1329+
1330+
#define kvm_has_feat_range(kvm, id, fld, min, max) \
1331+
(get_idreg_field((kvm), id, fld) >= expand_field_sign(id, fld, min) && \
1332+
get_idreg_field((kvm), id, fld) <= expand_field_sign(id, fld, max))
1333+
12371334
#endif /* __ARM64_KVM_HOST_H__ */

arch/arm64/include/asm/kvm_hyp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ DECLARE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params);
7070
/*
7171
* Without an __arch_swab32(), we fall back to ___constant_swab32(), but the
7272
* static inline can allow the compiler to out-of-line this. KVM always wants
73-
* the macro version as its always inlined.
73+
* the macro version as it's always inlined.
7474
*/
7575
#define __kvm_swab32(x) ___constant_swab32(x)
7676

arch/arm64/include/asm/kvm_mmu.h

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,6 @@
5353

5454
#include <asm/alternative.h>
5555

56-
/*
57-
* Convert a kernel VA into a HYP VA.
58-
* reg: VA to be converted.
59-
*
60-
* The actual code generation takes place in kvm_update_va_mask, and
61-
* the instructions below are only there to reserve the space and
62-
* perform the register allocation (kvm_update_va_mask uses the
63-
* specific registers encoded in the instructions).
64-
*/
65-
.macro kern_hyp_va reg
66-
#ifndef __KVM_VHE_HYPERVISOR__
67-
alternative_cb ARM64_ALWAYS_SYSTEM, kvm_update_va_mask
68-
and \reg, \reg, #1 /* mask with va_mask */
69-
ror \reg, \reg, #1 /* rotate to the first tag bit */
70-
add \reg, \reg, #0 /* insert the low 12 bits of the tag */
71-
add \reg, \reg, #0, lsl 12 /* insert the top 12 bits of the tag */
72-
ror \reg, \reg, #63 /* rotate back */
73-
alternative_cb_end
74-
#endif
75-
.endm
76-
7756
/*
7857
* Convert a hypervisor VA to a PA
7958
* reg: hypervisor address to be converted in place
@@ -127,14 +106,29 @@ void kvm_apply_hyp_relocations(void);
127106

128107
#define __hyp_pa(x) (((phys_addr_t)(x)) + hyp_physvirt_offset)
129108

109+
/*
110+
* Convert a kernel VA into a HYP VA.
111+
*
112+
* Can be called from hyp or non-hyp context.
113+
*
114+
* The actual code generation takes place in kvm_update_va_mask(), and
115+
* the instructions below are only there to reserve the space and
116+
* perform the register allocation (kvm_update_va_mask() uses the
117+
* specific registers encoded in the instructions).
118+
*/
130119
static __always_inline unsigned long __kern_hyp_va(unsigned long v)
131120
{
121+
/*
122+
* This #ifndef is an optimisation for when this is called from VHE hyp
123+
* context. When called from a VHE non-hyp context, kvm_update_va_mask() will
124+
* replace the instructions with `nop`s.
125+
*/
132126
#ifndef __KVM_VHE_HYPERVISOR__
133-
asm volatile(ALTERNATIVE_CB("and %0, %0, #1\n"
134-
"ror %0, %0, #1\n"
135-
"add %0, %0, #0\n"
136-
"add %0, %0, #0, lsl 12\n"
137-
"ror %0, %0, #63\n",
127+
asm volatile(ALTERNATIVE_CB("and %0, %0, #1\n" /* mask with va_mask */
128+
"ror %0, %0, #1\n" /* rotate to the first tag bit */
129+
"add %0, %0, #0\n" /* insert the low 12 bits of the tag */
130+
"add %0, %0, #0, lsl 12\n" /* insert the top 12 bits of the tag */
131+
"ror %0, %0, #63\n", /* rotate back */
138132
ARM64_ALWAYS_SYSTEM,
139133
kvm_update_va_mask)
140134
: "+r" (v));

arch/arm64/include/asm/kvm_nested.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ static inline u64 translate_ttbr0_el2_to_ttbr0_el1(u64 ttbr0)
6060
return ttbr0 & ~GENMASK_ULL(63, 48);
6161
}
6262

63-
extern bool __check_nv_sr_forward(struct kvm_vcpu *vcpu);
6463

6564
int kvm_init_nv_sysregs(struct kvm *kvm);
6665

0 commit comments

Comments
 (0)