Skip to content

Commit e89f0e9

Browse files
committed
Merge tag 'kvmarm-fixes-6.19-1' of https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into HEAD
KVM/arm64 fixes for 6.19 - Ensure early return semantics are preserved for pKVM fault handlers - Fix case where the kernel runs with the guest's PAN value when CONFIG_ARM64_PAN is not set - Make stage-1 walks to set the access flag respect the access permission of the underlying stage-2, when enabled - Propagate computed FGT values to the pKVM view of the vCPU at vcpu_load() - Correctly program PXN and UXN privilege bits for hVHE's stage-1 page tables - Check that the VM is actually using VGICv3 before accessing the GICv3 CPU interface - Delete some unused code
2 parents 24d479d + 19cffd1 commit e89f0e9

File tree

17 files changed

+73
-38
lines changed

17 files changed

+73
-38
lines changed

arch/arm64/include/asm/kvm_asm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ void kvm_get_kimage_voffset(struct alt_instr *alt,
300300
__le32 *origptr, __le32 *updptr, int nr_inst);
301301
void kvm_compute_final_ctr_el0(struct alt_instr *alt,
302302
__le32 *origptr, __le32 *updptr, int nr_inst);
303+
void kvm_pan_patch_el2_entry(struct alt_instr *alt,
304+
__le32 *origptr, __le32 *updptr, int nr_inst);
303305
void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr, u64 elr_virt,
304306
u64 elr_phys, u64 par, uintptr_t vcpu, u64 far, u64 hpfar);
305307

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,6 @@ static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu)
119119
return (unsigned long *)&vcpu->arch.hcr_el2;
120120
}
121121

122-
static inline void vcpu_clear_wfx_traps(struct kvm_vcpu *vcpu)
123-
{
124-
vcpu->arch.hcr_el2 &= ~HCR_TWE;
125-
if (atomic_read(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count) ||
126-
vcpu->kvm->arch.vgic.nassgireq)
127-
vcpu->arch.hcr_el2 &= ~HCR_TWI;
128-
else
129-
vcpu->arch.hcr_el2 |= HCR_TWI;
130-
}
131-
132-
static inline void vcpu_set_wfx_traps(struct kvm_vcpu *vcpu)
133-
{
134-
vcpu->arch.hcr_el2 |= HCR_TWE;
135-
vcpu->arch.hcr_el2 |= HCR_TWI;
136-
}
137-
138122
static inline unsigned long vcpu_get_vsesr(struct kvm_vcpu *vcpu)
139123
{
140124
return vcpu->arch.vsesr_el2;

arch/arm64/include/asm/kvm_pgtable.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,15 @@ typedef u64 kvm_pte_t;
8787

8888
#define KVM_PTE_LEAF_ATTR_HI_SW GENMASK(58, 55)
8989

90-
#define KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54)
90+
#define __KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54)
91+
#define __KVM_PTE_LEAF_ATTR_HI_S1_UXN BIT(54)
92+
#define __KVM_PTE_LEAF_ATTR_HI_S1_PXN BIT(53)
93+
94+
#define KVM_PTE_LEAF_ATTR_HI_S1_XN \
95+
({ cpus_have_final_cap(ARM64_KVM_HVHE) ? \
96+
(__KVM_PTE_LEAF_ATTR_HI_S1_UXN | \
97+
__KVM_PTE_LEAF_ATTR_HI_S1_PXN) : \
98+
__KVM_PTE_LEAF_ATTR_HI_S1_XN; })
9199

92100
#define KVM_PTE_LEAF_ATTR_HI_S2_XN GENMASK(54, 53)
93101

@@ -293,8 +301,8 @@ typedef bool (*kvm_pgtable_force_pte_cb_t)(u64 addr, u64 end,
293301
* children.
294302
* @KVM_PGTABLE_WALK_SHARED: Indicates the page-tables may be shared
295303
* with other software walkers.
296-
* @KVM_PGTABLE_WALK_HANDLE_FAULT: Indicates the page-table walk was
297-
* invoked from a fault handler.
304+
* @KVM_PGTABLE_WALK_IGNORE_EAGAIN: Don't terminate the walk early if
305+
* the walker returns -EAGAIN.
298306
* @KVM_PGTABLE_WALK_SKIP_BBM_TLBI: Visit and update table entries
299307
* without Break-before-make's
300308
* TLB invalidation.
@@ -307,7 +315,7 @@ enum kvm_pgtable_walk_flags {
307315
KVM_PGTABLE_WALK_TABLE_PRE = BIT(1),
308316
KVM_PGTABLE_WALK_TABLE_POST = BIT(2),
309317
KVM_PGTABLE_WALK_SHARED = BIT(3),
310-
KVM_PGTABLE_WALK_HANDLE_FAULT = BIT(4),
318+
KVM_PGTABLE_WALK_IGNORE_EAGAIN = BIT(4),
311319
KVM_PGTABLE_WALK_SKIP_BBM_TLBI = BIT(5),
312320
KVM_PGTABLE_WALK_SKIP_CMO = BIT(6),
313321
};

arch/arm64/include/asm/sysreg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
*/
9292
#define pstate_field(op1, op2) ((op1) << Op1_shift | (op2) << Op2_shift)
9393
#define PSTATE_Imm_shift CRm_shift
94-
#define SET_PSTATE(x, r) __emit_inst(0xd500401f | PSTATE_ ## r | ((!!x) << PSTATE_Imm_shift))
94+
#define ENCODE_PSTATE(x, r) (0xd500401f | PSTATE_ ## r | ((!!x) << PSTATE_Imm_shift))
95+
#define SET_PSTATE(x, r) __emit_inst(ENCODE_PSTATE(x, r))
9596

9697
#define PSTATE_PAN pstate_field(0, 4)
9798
#define PSTATE_UAO pstate_field(0, 3)

arch/arm64/kernel/image-vars.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ KVM_NVHE_ALIAS(kvm_patch_vector_branch);
8686
KVM_NVHE_ALIAS(kvm_update_va_mask);
8787
KVM_NVHE_ALIAS(kvm_get_kimage_voffset);
8888
KVM_NVHE_ALIAS(kvm_compute_final_ctr_el0);
89+
KVM_NVHE_ALIAS(kvm_pan_patch_el2_entry);
8990
KVM_NVHE_ALIAS(spectre_bhb_patch_loop_iter);
9091
KVM_NVHE_ALIAS(spectre_bhb_patch_loop_mitigation_enable);
9192
KVM_NVHE_ALIAS(spectre_bhb_patch_wa3);

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ static bool kvm_vcpu_should_clear_twi(struct kvm_vcpu *vcpu)
569569
return kvm_wfi_trap_policy == KVM_WFX_NOTRAP;
570570

571571
return single_task_running() &&
572+
vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3 &&
572573
(atomic_read(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count) ||
573574
vcpu->kvm->arch.vgic.nassgireq);
574575
}

arch/arm64/kvm/at.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ static int walk_s1(struct kvm_vcpu *vcpu, struct s1_walk_info *wi,
403403
struct s1_walk_result *wr, u64 va)
404404
{
405405
u64 va_top, va_bottom, baddr, desc, new_desc, ipa;
406+
struct kvm_s2_trans s2_trans = {};
406407
int level, stride, ret;
407408

408409
level = wi->sl;
@@ -420,8 +421,6 @@ static int walk_s1(struct kvm_vcpu *vcpu, struct s1_walk_info *wi,
420421
ipa = baddr | index;
421422

422423
if (wi->s2) {
423-
struct kvm_s2_trans s2_trans = {};
424-
425424
ret = kvm_walk_nested_s2(vcpu, ipa, &s2_trans);
426425
if (ret) {
427426
fail_s1_walk(wr,
@@ -515,6 +514,11 @@ static int walk_s1(struct kvm_vcpu *vcpu, struct s1_walk_info *wi,
515514
new_desc |= PTE_AF;
516515

517516
if (new_desc != desc) {
517+
if (wi->s2 && !kvm_s2_trans_writable(&s2_trans)) {
518+
fail_s1_walk(wr, ESR_ELx_FSC_PERM_L(level), true);
519+
return -EPERM;
520+
}
521+
518522
ret = kvm_swap_s1_desc(vcpu, ipa, desc, new_desc, wi);
519523
if (ret)
520524
return ret;

arch/arm64/kvm/hyp/entry.S

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ SYM_INNER_LABEL(__guest_exit, SYM_L_GLOBAL)
126126

127127
add x1, x1, #VCPU_CONTEXT
128128

129-
ALTERNATIVE(nop, SET_PSTATE_PAN(1), ARM64_HAS_PAN, CONFIG_ARM64_PAN)
129+
alternative_cb ARM64_ALWAYS_SYSTEM, kvm_pan_patch_el2_entry
130+
nop
131+
alternative_cb_end
130132

131133
// Store the guest regs x2 and x3
132134
stp x2, x3, [x1, #CPU_XREG_OFFSET(2)]

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ static inline bool kvm_hyp_handle_exit(struct kvm_vcpu *vcpu, u64 *exit_code,
854854
return false;
855855
}
856856

857-
static inline void synchronize_vcpu_pstate(struct kvm_vcpu *vcpu, u64 *exit_code)
857+
static inline void synchronize_vcpu_pstate(struct kvm_vcpu *vcpu)
858858
{
859859
/*
860860
* Check for the conditions of Cortex-A510's #2077057. When these occur

arch/arm64/kvm/hyp/nvhe/hyp-main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ static void handle___pkvm_vcpu_load(struct kvm_cpu_context *host_ctxt)
180180
/* Propagate WFx trapping flags */
181181
hyp_vcpu->vcpu.arch.hcr_el2 &= ~(HCR_TWE | HCR_TWI);
182182
hyp_vcpu->vcpu.arch.hcr_el2 |= hcr_el2 & (HCR_TWE | HCR_TWI);
183+
} else {
184+
memcpy(&hyp_vcpu->vcpu.arch.fgt, hyp_vcpu->host_vcpu->arch.fgt,
185+
sizeof(hyp_vcpu->vcpu.arch.fgt));
183186
}
184187
}
185188

0 commit comments

Comments
 (0)