KVM/arm updates for 5.3-rc3
Marc Zyngier
maintainerPaolo, Radim,
Here's a handful of patches for 5.3-rc3: Two actual fixes (missing break; in the 32bit register mapping, PMU reset being broken after the chained counter update). The rest is either cosmetic (exception classes in debug/tracing) or silence warnings (the fall-through explosion).
Please pull.
M.
The following changes since commit 5f9e832c137075045d15cd6899ab0505cfb2ca4b:
Linus 5.3-rc1 (2019-07-21 14:05:38 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-fixes-for-5.3
for you to fetch changes up to cdb2d3ee0436d74fa9092f2df46aaa6f9e03c969:
arm64: KVM: hyp: debug-sr: Mark expected switch fall-through (2019-07-29 11:01:37 +0100)
----------------------------------------------------------------
KVM/arm fixes for 5.3
- A bunch of switch/case fall-through annotation, fixing one actual bug
- Fix PMU reset bug
- Add missing exception class debug strings
----------------------------------------------------------------
Anders Roxell (3):
arm64: KVM: regmap: Fix unexpected switch fall-through
KVM: arm: vgic-v3: Mark expected switch fall-through
arm64: KVM: hyp: debug-sr: Mark expected switch fall-through
Zenghui Yu (2):
KVM: arm/arm64: Introduce kvm_pmu_vcpu_init() to setup PMU counter index
KVM: arm64: Update kvm_arm_exception_class and esr_class_str for new EC
arch/arm64/include/asm/kvm_arm.h | 7 ++++--- arch/arm64/kernel/traps.c | 1 + arch/arm64/kvm/hyp/debug-sr.c | 30 ++++++++++++++++++++++++++++++ arch/arm64/kvm/regmap.c | 5 +++++ include/kvm/arm_pmu.h | 2 ++ virt/kvm/arm/arm.c | 2 ++ virt/kvm/arm/hyp/vgic-v3-sr.c | 8 ++++++++ virt/kvm/arm/pmu.c | 18 +++++++++++++++--- 8 files changed, 67 insertions(+), 6 deletions(-)
Marc Zyngier
maintainerPATCH 1/5 KVM: arm/arm64: Introduce kvm_pmu_vcpu_init() to setup PMU counter index
From: Zenghui Yu <[email protected]>
We use "pmc->idx" and the "chained" bitmap to determine if the pmc is chained, in kvm_pmu_pmc_is_chained(). But idx might be uninitialized (and random) when we doing this decision, through a KVM_ARM_VCPU_INIT ioctl -> kvm_pmu_vcpu_reset(). And the test_bit() against this random idx will potentially hit a KASAN BUG [1].
In general, idx is the static property of a PMU counter that is not expected to be modified across resets, as suggested by Julien. It looks more reasonable if we can setup the PMU counter idx for a vcpu in its creation time. Introduce a new function - kvm_pmu_vcpu_init() for this basic setup. Oh, and the KASAN BUG will get fixed this way.
[1] https://www.spinics.net/lists/kvm-arm/msg36700.html
--- include/kvm/arm_pmu.h | 2 ++ virt/kvm/arm/arm.c | 2 ++ virt/kvm/arm/pmu.c | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-)
include/kvm/arm_pmu.h +2 -0
@@ -34,6 +34,7 @@ struct kvm_pmu {u64 kvm_pmu_get_counter_value (struct kvm_vcpu *vcpu,u64 select_idx);void kvm_pmu_set_counter_value (struct kvm_vcpu *vcpu,u64 select_idx,u64 val);u64 kvm_pmu_valid_counter_mask (struct kvm_vcpu *vcpu); +void kvm_pmu_vcpu_init (struct kvm_vcpu *vcpu);void kvm_pmu_vcpu_reset (struct kvm_vcpu *vcpu);void kvm_pmu_vcpu_destroy (struct kvm_vcpu *vcpu);void kvm_pmu_disable_counter_mask (struct kvm_vcpu *vcpu,u64 val);
@@ -71,6 +72,7 @@ static inline u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu) {return 0 ; } +static inline void kvm_pmu_vcpu_init (struct kvm_vcpu *vcpu) {}static inline void kvm_pmu_vcpu_reset (struct kvm_vcpu *vcpu) {}static inline void kvm_pmu_vcpu_destroy (struct kvm_vcpu *vcpu) {}static inline void kvm_pmu_disable_counter_mask (struct kvm_vcpu *vcpu,u64 val) {}
virt/kvm/arm/arm.c +2 -0
@@ -340,6 +340,8 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)/* Set up the timer */ kvm_timer_vcpu_init (vcpu); +kvm_pmu_vcpu_init (vcpu); +kvm_arm_reset_debug_ptr (vcpu);return kvm_vgic_vcpu_init (vcpu);
virt/kvm/arm/pmu.c +15 -3
@@ -214,6 +214,20 @@ static void kvm_pmu_stop_counter(struct kvm_vcpu *vcpu, struct kvm_pmc *pmc)kvm_pmu_release_perf_event (pmc); } +/** +* kvm_pmu_vcpu_init - assign pmu counter idx for cpu +* @vcpu: The vcpu pointer +* +*/ +void kvm_pmu_vcpu_init (struct kvm_vcpu *vcpu) +{ +int i; +struct kvm_pmu *pmu = &vcpu->arch.pmu; + +for (i =0 ; i <ARMV8_PMU_MAX_COUNTERS ; i++) + pmu->pmc[i].idx = i; +} +/** * kvm_pmu_vcpu_reset - reset pmu state for cpu * @vcpu: The vcpu pointer
@@ -224,10 +238,8 @@ void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu)int i;struct kvm_pmu *pmu = &vcpu->arch.pmu; -for (i =0 ; i <ARMV8_PMU_MAX_COUNTERS ; i++) { +for (i =0 ; i <ARMV8_PMU_MAX_COUNTERS ; i++)kvm_pmu_stop_counter (vcpu, &pmu->pmc[i]); - pmu->pmc[i].idx = i; - }bitmap_zero (vcpu->arch.pmu.chained,ARMV8_PMU_MAX_COUNTER_PAIRS ); }
Signature · 1 line
2.20.1
Marc Zyngier
maintainerPATCH 2/5 arm64: KVM: regmap: Fix unexpected switch fall-through
In reply to Marc ZyngierFrom: Anders Roxell <[email protected]>
When fall-through warnings was enabled by default, commit d93512ef0f0e ("Makefile: Globally enable fall-through warning"), the following warnings was starting to show up:
In file included from ../arch/arm64/include/asm/kvm_emulate.h:19,
from ../arch/arm64/kvm/regmap.c:13:
../arch/arm64/kvm/regmap.c: In function ‘vcpu_write_spsr32’:../arch/arm64/include/asm/kvm_hyp.h:31:3: warning: this statement may fall
through [-Wimplicit-fallthrough=]
asm volatile(ALTERNATIVE(__msr_s(r##nvh, "%x0"), \
^~~../arch/arm64/include/asm/kvm_hyp.h:46:31: note: in expansion of macro ‘write_sysreg_elx’
#define write_sysreg_el1(v,r) write_sysreg_elx(v, r, _EL1, _EL12)
^~~~~~~~~~~~~~~~../arch/arm64/kvm/regmap.c:180:3: note: in expansion of macro ‘write_sysreg_el1’
write_sysreg_el1(v, SYS_SPSR);
^~~~~~~~~~~~~~~~../arch/arm64/kvm/regmap.c:181:2: note: here
case KVM_SPSR_ABT:
^~~~
In file included from ../arch/arm64/include/asm/cputype.h:132,
from ../arch/arm64/include/asm/cache.h:8,
from ../include/linux/cache.h:6,
from ../include/linux/printk.h:9,
from ../include/linux/kernel.h:15,
from ../include/asm-generic/bug.h:18,
from ../arch/arm64/include/asm/bug.h:26,
from ../include/linux/bug.h:5,
from ../include/linux/mmdebug.h:5,
from ../include/linux/mm.h:9,
from ../arch/arm64/kvm/regmap.c:11:../arch/arm64/include/asm/sysreg.h:837:2: warning: this statement may fall
through [-Wimplicit-fallthrough=]
asm volatile("msr " __stringify(r) ", %x0" \
^~~../arch/arm64/kvm/regmap.c:182:3: note: in expansion of macro ‘write_sysreg’
write_sysreg(v, spsr_abt);
^~~~~~~~~~~~../arch/arm64/kvm/regmap.c:183:2: note: here
case KVM_SPSR_UND:
^~~~
Rework to add a 'break;' in the swich-case since it didn't have that, leading to an interresting set of bugs.
--- arch/arm64/kvm/regmap.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/kvm/regmap.c +5 -0
@@ -178,13 +178,18 @@ void vcpu_write_spsr32(struct kvm_vcpu *vcpu, unsigned long v)switch (spsr_idx) {case KVM_SPSR_SVC :write_sysreg_el1 (v,SYS_SPSR ); +break ;case KVM_SPSR_ABT :write_sysreg (v, spsr_abt); +break ;case KVM_SPSR_UND :write_sysreg (v, spsr_und); +break ;case KVM_SPSR_IRQ :write_sysreg (v, spsr_irq); +break ;case KVM_SPSR_FIQ :write_sysreg (v, spsr_fiq); +break ; } }
Signature · 1 line
2.20.1
Marc Zyngier
maintainerPATCH 3/5 KVM: arm: vgic-v3: Mark expected switch fall-through
In reply to Marc ZyngierFrom: Anders Roxell <[email protected]>
When fall-through warnings was enabled by default the following warnings was starting to show up:
../virt/kvm/arm/hyp/vgic-v3-sr.c: In function ‘__vgic_v3_save_aprs’:../virt/kvm/arm/hyp/vgic-v3-sr.c:351:24: warning: this statement may fall
through [-Wimplicit-fallthrough=]
cpu_if->vgic_ap0r[2] = __vgic_v3_read_ap0rn(2); ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~../virt/kvm/arm/hyp/vgic-v3-sr.c:352:2: note: here
case 6:
^~~~../virt/kvm/arm/hyp/vgic-v3-sr.c:353:24: warning: this statement may fall
through [-Wimplicit-fallthrough=]
cpu_if->vgic_ap0r[1] = __vgic_v3_read_ap0rn(1); ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~../virt/kvm/arm/hyp/vgic-v3-sr.c:354:2: note: here
default:
^~~~~~~
Rework so that the compiler doesn't warn about fall-through.
--- virt/kvm/arm/hyp/vgic-v3-sr.c | 8 ++++++++ 1 file changed, 8 insertions(+)
virt/kvm/arm/hyp/vgic-v3-sr.c +8 -0
@@ -349,8 +349,10 @@ void __hyp_text __vgic_v3_save_aprs(struct kvm_vcpu *vcpu)case 7 : cpu_if->vgic_ap0r[3 ] =__vgic_v3_read_ap0rn (3 ); cpu_if->vgic_ap0r[2 ] =__vgic_v3_read_ap0rn (2 ); +/* Fall through */ case 6 : cpu_if->vgic_ap0r[1 ] =__vgic_v3_read_ap0rn (1 ); +/* Fall through */ default : cpu_if->vgic_ap0r[0 ] =__vgic_v3_read_ap0rn (0 ); }
@@ -359,8 +361,10 @@ void __hyp_text __vgic_v3_save_aprs(struct kvm_vcpu *vcpu)case 7 : cpu_if->vgic_ap1r[3 ] =__vgic_v3_read_ap1rn (3 ); cpu_if->vgic_ap1r[2 ] =__vgic_v3_read_ap1rn (2 ); +/* Fall through */ case 6 : cpu_if->vgic_ap1r[1 ] =__vgic_v3_read_ap1rn (1 ); +/* Fall through */ default : cpu_if->vgic_ap1r[0 ] =__vgic_v3_read_ap1rn (0 ); }
@@ -382,8 +386,10 @@ void __hyp_text __vgic_v3_restore_aprs(struct kvm_vcpu *vcpu)case 7 :__vgic_v3_write_ap0rn (cpu_if->vgic_ap0r[3 ],3 );__vgic_v3_write_ap0rn (cpu_if->vgic_ap0r[2 ],2 ); +/* Fall through */ case 6 :__vgic_v3_write_ap0rn (cpu_if->vgic_ap0r[1 ],1 ); +/* Fall through */ default :__vgic_v3_write_ap0rn (cpu_if->vgic_ap0r[0 ],0 ); }
@@ -392,8 +398,10 @@ void __hyp_text __vgic_v3_restore_aprs(struct kvm_vcpu *vcpu)case 7 :__vgic_v3_write_ap1rn (cpu_if->vgic_ap1r[3 ],3 );__vgic_v3_write_ap1rn (cpu_if->vgic_ap1r[2 ],2 ); +/* Fall through */ case 6 :__vgic_v3_write_ap1rn (cpu_if->vgic_ap1r[1 ],1 ); +/* Fall through */ default :__vgic_v3_write_ap1rn (cpu_if->vgic_ap1r[0 ],0 ); }
Signature · 1 line
2.20.1
Marc Zyngier
maintainerPATCH 4/5 KVM: arm64: Update kvm_arm_exception_class and esr_class_str for new EC
In reply to Marc ZyngierFrom: Zenghui Yu <[email protected]>
We've added two ESR exception classes for new ARM hardware extensions:ESR_ELx_EC_PAC and ESR_ELx_EC_SVE, but failed to update the strings used in tracing and other debug.
Let's update "kvm_arm_exception_class" for these two EC, which the new EC will be visible to user-space via kvm_exit trace events Also update to "esr_class_str" for ESR_ELx_EC_PAC, by which we can get more readable debug info.
--- arch/arm64/include/asm/kvm_arm.h | 7 ++++--- arch/arm64/kernel/traps.c | 1 + 2 files changed, 5 insertions(+), 3 deletions(-)
arch/arm64/include/asm/kvm_arm.h +4 -3
@@ -316,9 +316,10 @@#define kvm_arm_exception_class \ ECN(UNKNOWN), ECN(WFx), ECN(CP15_32), ECN(CP15_64), ECN(CP14_MR), \ - ECN(CP14_LS), ECN(FP_ASIMD), ECN(CP10_ID), ECN(CP14_64), ECN(SVC64), \ - ECN(HVC64), ECN(SMC64), ECN(SYS64), ECN(IMP_DEF), ECN(IABT_LOW), \ - ECN(IABT_CUR), ECN(PC_ALIGN), ECN(DABT_LOW), ECN(DABT_CUR), \ + ECN(CP14_LS), ECN(FP_ASIMD), ECN(CP10_ID), ECN(PAC), ECN(CP14_64), \ + ECN(SVC64), ECN(HVC64), ECN(SMC64), ECN(SYS64), ECN(SVE), \ + ECN(IMP_DEF), ECN(IABT_LOW), ECN(IABT_CUR), \ + ECN(PC_ALIGN), ECN(DABT_LOW), ECN(DABT_CUR), \ ECN(SP_ALIGN), ECN(FP_EXC32), ECN(FP_EXC64), ECN(SERROR), \ ECN(BREAKPT_LOW), ECN(BREAKPT_CUR), ECN(SOFTSTP_LOW), \ ECN(SOFTSTP_CUR), ECN(WATCHPT_LOW), ECN(WATCHPT_CUR), \
arch/arm64/kernel/traps.c +1 -0
@@ -734,6 +734,7 @@ static const char *esr_class_str[] = { [ESR_ELx_EC_CP14_LS] = "CP14 LDC/STC", [ESR_ELx_EC_FP_ASIMD] = "ASIMD", [ESR_ELx_EC_CP10_ID] = "CP10 MRC/VMRS", + [ESR_ELx_EC_PAC] = "PAC", [ESR_ELx_EC_CP14_64] = "CP14 MCRR/MRRC", [ESR_ELx_EC_ILL] = "PSTATE.IL", [ESR_ELx_EC_SVC32] = "SVC (AArch32)",
Signature · 1 line
2.20.1
Marc Zyngier
maintainerPATCH 5/5 arm64: KVM: hyp: debug-sr: Mark expected switch fall-through
In reply to Marc ZyngierFrom: Anders Roxell <[email protected]>
When fall-through warnings was enabled by default the following warnings was starting to show up:
../arch/arm64/kvm/hyp/debug-sr.c: In function ‘__debug_save_state’:../arch/arm64/kvm/hyp/debug-sr.c:20:19: warning: this statement may fall
through [-Wimplicit-fallthrough=]
case 15: ptr[15] = read_debug(reg, 15); \../arch/arm64/kvm/hyp/debug-sr.c:113:2: note: in expansion of macro ‘save_debug’
save_debug(dbg->dbg_bcr, dbgbcr, brps);
^~~~~~~~~~../arch/arm64/kvm/hyp/debug-sr.c:21:2: note: here
case 14: ptr[14] = read_debug(reg, 14); \
^~~~../arch/arm64/kvm/hyp/debug-sr.c:113:2: note: in expansion of macro ‘save_debug’
save_debug(dbg->dbg_bcr, dbgbcr, brps);
^~~~~~~~~~../arch/arm64/kvm/hyp/debug-sr.c:21:19: warning: this statement may fall
through [-Wimplicit-fallthrough=]
case 14: ptr[14] = read_debug(reg, 14); \../arch/arm64/kvm/hyp/debug-sr.c:113:2: note: in expansion of macro ‘save_debug’
save_debug(dbg->dbg_bcr, dbgbcr, brps);
^~~~~~~~~~../arch/arm64/kvm/hyp/debug-sr.c:22:2: note: here
case 13: ptr[13] = read_debug(reg, 13); \
^~~~../arch/arm64/kvm/hyp/debug-sr.c:113:2: note: in expansion of macro ‘save_debug’
save_debug(dbg->dbg_bcr, dbgbcr, brps);
^~~~~~~~~~
Rework to add a 'Fall through' comment where the compiler warned about fall-through, hence silencing the warning.
--- arch/arm64/kvm/hyp/debug-sr.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
arch/arm64/kvm/hyp/debug-sr.c +30 -0
@@ -18,40 +18,70 @@#define save_debug (ptr,reg,nr) \ switch (nr) { \ case 15: ptr[15] = read_debug(reg, 15); \ +/* Fall through */ \case 14 : ptr[14 ] =read_debug (reg,14 ); \ +/* Fall through */ \case 13 : ptr[13 ] =read_debug (reg,13 ); \ +/* Fall through */ \case 12 : ptr[12 ] =read_debug (reg,12 ); \ +/* Fall through */ \case 11 : ptr[11 ] =read_debug (reg,11 ); \ +/* Fall through */ \case 10 : ptr[10 ] =read_debug (reg,10 ); \ +/* Fall through */ \case 9 : ptr[9 ] =read_debug (reg,9 ); \ +/* Fall through */ \case 8 : ptr[8 ] =read_debug (reg,8 ); \ +/* Fall through */ \case 7 : ptr[7 ] =read_debug (reg,7 ); \ +/* Fall through */ \case 6 : ptr[6 ] =read_debug (reg,6 ); \ +/* Fall through */ \case 5 : ptr[5 ] =read_debug (reg,5 ); \ +/* Fall through */ \case 4 : ptr[4 ] =read_debug (reg,4 ); \ +/* Fall through */ \case 3 : ptr[3 ] =read_debug (reg,3 ); \ +/* Fall through */ \case 2 : ptr[2 ] =read_debug (reg,2 ); \ +/* Fall through */ \case 1 : ptr[1 ] =read_debug (reg,1 ); \ +/* Fall through */ \default : ptr[0 ] =read_debug (reg,0 ); \ }#define restore_debug (ptr,reg,nr) \ switch (nr) { \ case 15: write_debug(ptr[15], reg, 15); \ +/* Fall through */ \case 14 :write_debug (ptr[14 ], reg,14 ); \ +/* Fall through */ \case 13 :write_debug (ptr[13 ], reg,13 ); \ +/* Fall through */ \case 12 :write_debug (ptr[12 ], reg,12 ); \ +/* Fall through */ \case 11 :write_debug (ptr[11 ], reg,11 ); \ +/* Fall through */ \case 10 :write_debug (ptr[10 ], reg,10 ); \ +/* Fall through */ \case 9 :write_debug (ptr[9 ], reg,9 ); \ +/* Fall through */ \case 8 :write_debug (ptr[8 ], reg,8 ); \ +/* Fall through */ \case 7 :write_debug (ptr[7 ], reg,7 ); \ +/* Fall through */ \case 6 :write_debug (ptr[6 ], reg,6 ); \ +/* Fall through */ \case 5 :write_debug (ptr[5 ], reg,5 ); \ +/* Fall through */ \case 4 :write_debug (ptr[4 ], reg,4 ); \ +/* Fall through */ \case 3 :write_debug (ptr[3 ], reg,3 ); \ +/* Fall through */ \case 2 :write_debug (ptr[2 ], reg,2 ); \ +/* Fall through */ \case 1 :write_debug (ptr[1 ], reg,1 ); \ +/* Fall through */ \default :write_debug (ptr[0 ], reg,0 ); \ }
Signature · 1 line
2.20.1