* [PATCH 0/2] LoongArch: KVM: Do not flush tlb if HW PTW supported
@ 2025-04-24 6:46 Bibo Mao
2025-04-24 6:46 ` [PATCH 1/2] LoongArch: KVM: Add parameter exception code with exception handler Bibo Mao
2025-04-24 6:46 ` [PATCH 2/2] LoongArch: KVM: Do not flush tlb if HW PTW supported Bibo Mao
0 siblings, 2 replies; 4+ messages in thread
From: Bibo Mao @ 2025-04-24 6:46 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen; +Cc: WANG Xuerui, kvm, loongarch, linux-kernel
With HW PTW supported, stale TLB is not added if page fault happens. With
EXCCODE_TLBM exception, stale TLB may exist because last read access, tlb
flush operation is necessary with EXCCODE_TLBM exception, and not necessary
with other memory page fault exceptions.
With SW PTW supported, invalid TLB is added in TLB refill exception.
TLB flush operation is necessary with all page fault exceptions.
Bibo Mao (2):
LoongArch: KVM: Add parameter exception code with exception handler
LoongArch: KVM: Do not flush tlb if HW PTW supported
arch/loongarch/include/asm/kvm_host.h | 2 +-
arch/loongarch/include/asm/kvm_vcpu.h | 2 +-
arch/loongarch/kvm/exit.c | 34 +++++++++++++--------------
arch/loongarch/kvm/mmu.c | 17 ++++++++++----
4 files changed, 31 insertions(+), 24 deletions(-)
base-commit: 9d7a0577c9db35c4cc52db90bc415ea248446472
--
2.39.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] LoongArch: KVM: Add parameter exception code with exception handler
2025-04-24 6:46 [PATCH 0/2] LoongArch: KVM: Do not flush tlb if HW PTW supported Bibo Mao
@ 2025-04-24 6:46 ` Bibo Mao
2025-04-25 7:05 ` kernel test robot
2025-04-24 6:46 ` [PATCH 2/2] LoongArch: KVM: Do not flush tlb if HW PTW supported Bibo Mao
1 sibling, 1 reply; 4+ messages in thread
From: Bibo Mao @ 2025-04-24 6:46 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen; +Cc: WANG Xuerui, kvm, loongarch, linux-kernel
With some KVM exception types, they share the same exception function
handler. To show the difference, exception code is added as new
parameter in exception handler.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/include/asm/kvm_vcpu.h | 2 +-
arch/loongarch/kvm/exit.c | 26 ++++++++++++--------------
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/arch/loongarch/include/asm/kvm_vcpu.h b/arch/loongarch/include/asm/kvm_vcpu.h
index 2c349f961bfb..b0a6cac07ed8 100644
--- a/arch/loongarch/include/asm/kvm_vcpu.h
+++ b/arch/loongarch/include/asm/kvm_vcpu.h
@@ -37,7 +37,7 @@
#define KVM_LOONGSON_IRQ_NUM_MASK 0xffff
typedef union loongarch_instruction larch_inst;
-typedef int (*exit_handle_fn)(struct kvm_vcpu *);
+typedef int (*exit_handle_fn)(struct kvm_vcpu *, int ecode);
int kvm_emu_mmio_read(struct kvm_vcpu *vcpu, larch_inst inst);
int kvm_emu_mmio_write(struct kvm_vcpu *vcpu, larch_inst inst);
diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
index ea321403644a..31b9d5f67e8f 100644
--- a/arch/loongarch/kvm/exit.c
+++ b/arch/loongarch/kvm/exit.c
@@ -341,7 +341,7 @@ static int kvm_trap_handle_gspr(struct kvm_vcpu *vcpu)
* 2) Execute CACOP/IDLE instructions;
* 3) Access to unimplemented CSRs/IOCSRs.
*/
-static int kvm_handle_gspr(struct kvm_vcpu *vcpu)
+static int kvm_handle_gspr(struct kvm_vcpu *vcpu, int ecode)
{
int ret = RESUME_GUEST;
enum emulation_result er = EMULATE_DONE;
@@ -705,12 +705,12 @@ static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write)
return ret;
}
-static int kvm_handle_read_fault(struct kvm_vcpu *vcpu)
+static int kvm_handle_read_fault(struct kvm_vcpu *vcpu, int ecode)
{
return kvm_handle_rdwr_fault(vcpu, false);
}
-static int kvm_handle_write_fault(struct kvm_vcpu *vcpu)
+static int kvm_handle_write_fault(struct kvm_vcpu *vcpu, int ecode)
{
return kvm_handle_rdwr_fault(vcpu, true);
}
@@ -730,7 +730,7 @@ int kvm_complete_user_service(struct kvm_vcpu *vcpu, struct kvm_run *run)
* Handle when the guest attempts to use fpu which hasn't been allowed
* by the root context.
*/
-static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu)
+static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu, int ecode)
{
struct kvm_run *run = vcpu->run;
@@ -787,7 +787,7 @@ static long kvm_save_notify(struct kvm_vcpu *vcpu)
* Handle when the guest attempts to use LSX when it is disabled in the root
* context.
*/
-static int kvm_handle_lsx_disabled(struct kvm_vcpu *vcpu)
+static int kvm_handle_lsx_disabled(struct kvm_vcpu *vcpu, int ecode)
{
if (kvm_own_lsx(vcpu))
kvm_queue_exception(vcpu, EXCCODE_INE, 0);
@@ -802,7 +802,7 @@ static int kvm_handle_lsx_disabled(struct kvm_vcpu *vcpu)
* Handle when the guest attempts to use LASX when it is disabled in the root
* context.
*/
-static int kvm_handle_lasx_disabled(struct kvm_vcpu *vcpu)
+static int kvm_handle_lasx_disabled(struct kvm_vcpu *vcpu, int ecode)
{
if (kvm_own_lasx(vcpu))
kvm_queue_exception(vcpu, EXCCODE_INE, 0);
@@ -810,7 +810,7 @@ static int kvm_handle_lasx_disabled(struct kvm_vcpu *vcpu)
return RESUME_GUEST;
}
-static int kvm_handle_lbt_disabled(struct kvm_vcpu *vcpu)
+static int kvm_handle_lbt_disabled(struct kvm_vcpu *vcpu, int ecode)
{
if (kvm_own_lbt(vcpu))
kvm_queue_exception(vcpu, EXCCODE_INE, 0);
@@ -872,7 +872,7 @@ static void kvm_handle_service(struct kvm_vcpu *vcpu)
kvm_write_reg(vcpu, LOONGARCH_GPR_A0, ret);
}
-static int kvm_handle_hypercall(struct kvm_vcpu *vcpu)
+static int kvm_handle_hypercall(struct kvm_vcpu *vcpu, int ecode)
{
int ret;
larch_inst inst;
@@ -932,16 +932,14 @@ static int kvm_handle_hypercall(struct kvm_vcpu *vcpu)
/*
* LoongArch KVM callback handling for unimplemented guest exiting
*/
-static int kvm_fault_ni(struct kvm_vcpu *vcpu)
+static int kvm_fault_ni(struct kvm_vcpu *vcpu, int ecode)
{
- unsigned int ecode, inst;
- unsigned long estat, badv;
+ unsigned int inst;
+ unsigned long badv;
/* Fetch the instruction */
inst = vcpu->arch.badi;
badv = vcpu->arch.badv;
- estat = vcpu->arch.host_estat;
- ecode = (estat & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT;
kvm_err("ECode: %d PC=%#lx Inst=0x%08x BadVaddr=%#lx ESTAT=%#lx\n",
ecode, vcpu->arch.pc, inst, badv, read_gcsr_estat());
kvm_arch_vcpu_dump_regs(vcpu);
@@ -966,5 +964,5 @@ static exit_handle_fn kvm_fault_tables[EXCCODE_INT_START] = {
int kvm_handle_fault(struct kvm_vcpu *vcpu, int fault)
{
- return kvm_fault_tables[fault](vcpu);
+ return kvm_fault_tables[fault](vcpu, fault);
}
--
2.39.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] LoongArch: KVM: Do not flush tlb if HW PTW supported
2025-04-24 6:46 [PATCH 0/2] LoongArch: KVM: Do not flush tlb if HW PTW supported Bibo Mao
2025-04-24 6:46 ` [PATCH 1/2] LoongArch: KVM: Add parameter exception code with exception handler Bibo Mao
@ 2025-04-24 6:46 ` Bibo Mao
1 sibling, 0 replies; 4+ messages in thread
From: Bibo Mao @ 2025-04-24 6:46 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen; +Cc: WANG Xuerui, kvm, loongarch, linux-kernel
With HW PTW supported, TLB is not added if page fault happens. With
EXCCODE_TLBM exception, TLB may exist because last read access, tlb
flush operation is necessary with EXCCODE_TLBM exception, and not
necessary with other memory page fault exception.
With SW PTW supported, invalid TLB is added in TLB refill exception.
tlb flush operation is necessary with all page fault exceptions.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/include/asm/kvm_host.h | 2 +-
arch/loongarch/kvm/exit.c | 8 ++++----
arch/loongarch/kvm/mmu.c | 17 +++++++++++++----
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/arch/loongarch/include/asm/kvm_host.h b/arch/loongarch/include/asm/kvm_host.h
index f457c2662e2f..a3c4cc46c892 100644
--- a/arch/loongarch/include/asm/kvm_host.h
+++ b/arch/loongarch/include/asm/kvm_host.h
@@ -301,7 +301,7 @@ int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu);
/* MMU handling */
void kvm_flush_tlb_all(void);
void kvm_flush_tlb_gpa(struct kvm_vcpu *vcpu, unsigned long gpa);
-int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long badv, bool write);
+int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long badv, bool write, int ecode);
int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end, bool blockable);
int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
index 31b9d5f67e8f..e6ad251debb1 100644
--- a/arch/loongarch/kvm/exit.c
+++ b/arch/loongarch/kvm/exit.c
@@ -661,7 +661,7 @@ int kvm_emu_mmio_write(struct kvm_vcpu *vcpu, larch_inst inst)
return ret;
}
-static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write)
+static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write, int ecode)
{
int ret;
larch_inst inst;
@@ -675,7 +675,7 @@ static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write)
return RESUME_GUEST;
}
- ret = kvm_handle_mm_fault(vcpu, badv, write);
+ ret = kvm_handle_mm_fault(vcpu, badv, write, ecode);
if (ret) {
/* Treat as MMIO */
inst.word = vcpu->arch.badi;
@@ -707,12 +707,12 @@ static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write)
static int kvm_handle_read_fault(struct kvm_vcpu *vcpu, int ecode)
{
- return kvm_handle_rdwr_fault(vcpu, false);
+ return kvm_handle_rdwr_fault(vcpu, false, ecode);
}
static int kvm_handle_write_fault(struct kvm_vcpu *vcpu, int ecode)
{
- return kvm_handle_rdwr_fault(vcpu, true);
+ return kvm_handle_rdwr_fault(vcpu, true, ecode);
}
int kvm_complete_user_service(struct kvm_vcpu *vcpu, struct kvm_run *run)
diff --git a/arch/loongarch/kvm/mmu.c b/arch/loongarch/kvm/mmu.c
index 4d203294767c..0f0d4be9cba2 100644
--- a/arch/loongarch/kvm/mmu.c
+++ b/arch/loongarch/kvm/mmu.c
@@ -912,7 +912,7 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool write)
return err;
}
-int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long gpa, bool write)
+int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long gpa, bool write, int ecode)
{
int ret;
@@ -920,9 +920,18 @@ int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long gpa, bool write)
if (ret)
return ret;
- /* Invalidate this entry in the TLB */
- vcpu->arch.flush_gpa = gpa;
- kvm_make_request(KVM_REQ_TLB_FLUSH_GPA, vcpu);
+ if (!cpu_has_ptw || (ecode == EXCCODE_TLBM)) {
+ /*
+ * With HW ptw supported, TLB will not update for any page fault
+ * For EXCCODE_TLBM exception, TLB may exist because last read access
+ *
+ * With SW ptw, invalid TLB is added in TLB refill exception
+ *
+ * Invalidate this entry in the TLB
+ */
+ vcpu->arch.flush_gpa = gpa;
+ kvm_make_request(KVM_REQ_TLB_FLUSH_GPA, vcpu);
+ }
return 0;
}
--
2.39.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] LoongArch: KVM: Add parameter exception code with exception handler
2025-04-24 6:46 ` [PATCH 1/2] LoongArch: KVM: Add parameter exception code with exception handler Bibo Mao
@ 2025-04-25 7:05 ` kernel test robot
0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-04-25 7:05 UTC (permalink / raw)
To: Bibo Mao, Tianrui Zhao, Huacai Chen
Cc: oe-kbuild-all, WANG Xuerui, kvm, loongarch, linux-kernel
Hi Bibo,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 9d7a0577c9db35c4cc52db90bc415ea248446472]
url: https://github.com/intel-lab-lkp/linux/commits/Bibo-Mao/LoongArch-KVM-Add-parameter-exception-code-with-exception-handler/20250424-144905
base: 9d7a0577c9db35c4cc52db90bc415ea248446472
patch link: https://lore.kernel.org/r/20250424064625.3928278-2-maobibo%40loongson.cn
patch subject: [PATCH 1/2] LoongArch: KVM: Add parameter exception code with exception handler
config: loongarch-randconfig-001-20250425 (https://download.01.org/0day-ci/archive/20250425/202504251458.EJKsZMLH-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250425/202504251458.EJKsZMLH-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504251458.EJKsZMLH-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> arch/loongarch/kvm/exit.c:734: warning: Function parameter or struct member 'ecode' not described in 'kvm_handle_fpu_disabled'
vim +734 arch/loongarch/kvm/exit.c
2737dee1067c2f Bibo Mao 2025-01-13 725
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 726 /**
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 727 * kvm_handle_fpu_disabled() - Guest used fpu however it is disabled at host
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 728 * @vcpu: Virtual CPU context.
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 729 *
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 730 * Handle when the guest attempts to use fpu which hasn't been allowed
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 731 * by the root context.
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 732 */
74303fac8d0580 Bibo Mao 2025-04-24 733 static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu, int ecode)
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 @734 {
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 735 struct kvm_run *run = vcpu->run;
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 736
db1ecca22edf27 Tianrui Zhao 2023-12-19 737 if (!kvm_guest_has_fpu(&vcpu->arch)) {
db1ecca22edf27 Tianrui Zhao 2023-12-19 738 kvm_queue_exception(vcpu, EXCCODE_INE, 0);
db1ecca22edf27 Tianrui Zhao 2023-12-19 739 return RESUME_GUEST;
db1ecca22edf27 Tianrui Zhao 2023-12-19 740 }
db1ecca22edf27 Tianrui Zhao 2023-12-19 741
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 742 /*
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 743 * If guest FPU not present, the FPU operation should have been
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 744 * treated as a reserved instruction!
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 745 * If FPU already in use, we shouldn't get this at all.
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 746 */
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 747 if (WARN_ON(vcpu->arch.aux_inuse & KVM_LARCH_FPU)) {
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 748 kvm_err("%s internal error\n", __func__);
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 749 run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 750 return RESUME_HOST;
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 751 }
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 752
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 753 kvm_own_fpu(vcpu);
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 754
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 755 return RESUME_GUEST;
37cdfc6dbf0416 Tianrui Zhao 2023-10-02 756 }
71f4fb845874c3 Tianrui Zhao 2023-10-02 757
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-25 7:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-24 6:46 [PATCH 0/2] LoongArch: KVM: Do not flush tlb if HW PTW supported Bibo Mao
2025-04-24 6:46 ` [PATCH 1/2] LoongArch: KVM: Add parameter exception code with exception handler Bibo Mao
2025-04-25 7:05 ` kernel test robot
2025-04-24 6:46 ` [PATCH 2/2] LoongArch: KVM: Do not flush tlb if HW PTW supported Bibo Mao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox