linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Add sign extension with kernel MMIO read emulation
@ 2025-08-19 12:17 Bibo Mao
  2025-08-19 12:17 ` [PATCH 1/2] LoongArch: KVM: " Bibo Mao
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bibo Mao @ 2025-08-19 12:17 UTC (permalink / raw)
  To: Huacai Chen, Xianglai Li; +Cc: kvm, loongarch, linux-kernel

This patch is to add sign extension with kernel MMIO/IOCSR read
emulation, it is similar with user space MMIO/IOCSR read completion
handling.

Bibo Mao (2):
  LoongArch: KVM: Add sign extension with kernel MMIO read emulation
  LoongArch: KVM: Add sign extension with kernel IOCSR read emulation

 arch/loongarch/kvm/exit.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)


base-commit: be48bcf004f9d0c9207ff21d0edb3b42f253829e
-- 
2.39.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] LoongArch: KVM: Add sign extension with kernel MMIO read emulation
  2025-08-19 12:17 [PATCH 0/2] Add sign extension with kernel MMIO read emulation Bibo Mao
@ 2025-08-19 12:17 ` Bibo Mao
  2025-08-19 12:17 ` [PATCH 2/2] LoongArch: KVM: Add sign extension with kernel IOCSR " Bibo Mao
  2025-08-29 10:10 ` [PATCH 0/2] Add sign extension with kernel MMIO " Huacai Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Bibo Mao @ 2025-08-19 12:17 UTC (permalink / raw)
  To: Huacai Chen, Xianglai Li; +Cc: kvm, loongarch, linux-kernel

Function kvm_complete_mmio_read() is to add sign extension with MMIO
read emulation, it is used in user space MMIO read return now. Also
it can be used in kernel MMIO read emulation.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 arch/loongarch/kvm/exit.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
index 2ce41f93b2a4..6fee1b8c35eb 100644
--- a/arch/loongarch/kvm/exit.c
+++ b/arch/loongarch/kvm/exit.c
@@ -468,6 +468,9 @@ int kvm_emu_mmio_read(struct kvm_vcpu *vcpu, larch_inst inst)
 	if (ret == EMULATE_DO_MMIO) {
 		trace_kvm_mmio(KVM_TRACE_MMIO_READ, run->mmio.len, run->mmio.phys_addr, NULL);
 
+		/* Set for kvm_complete_mmio_read() use */
+		vcpu->arch.io_gpr = rd;
+
 		/*
 		 * If mmio device such as PCH-PIC is emulated in KVM,
 		 * it need not return to user space to handle the mmio
@@ -475,16 +478,15 @@ int kvm_emu_mmio_read(struct kvm_vcpu *vcpu, larch_inst inst)
 		 */
 		idx = srcu_read_lock(&vcpu->kvm->srcu);
 		ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, vcpu->arch.badv,
-				      run->mmio.len, &vcpu->arch.gprs[rd]);
+				      run->mmio.len, run->mmio.data);
 		srcu_read_unlock(&vcpu->kvm->srcu, idx);
 		if (!ret) {
+			kvm_complete_mmio_read(vcpu, run);
 			update_pc(&vcpu->arch);
 			vcpu->mmio_needed = 0;
 			return EMULATE_DONE;
 		}
 
-		/* Set for kvm_complete_mmio_read() use */
-		vcpu->arch.io_gpr = rd;
 		run->mmio.is_write = 0;
 		vcpu->mmio_is_write = 0;
 		return EMULATE_DO_MMIO;
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] LoongArch: KVM: Add sign extension with kernel IOCSR read emulation
  2025-08-19 12:17 [PATCH 0/2] Add sign extension with kernel MMIO read emulation Bibo Mao
  2025-08-19 12:17 ` [PATCH 1/2] LoongArch: KVM: " Bibo Mao
@ 2025-08-19 12:17 ` Bibo Mao
  2025-08-29 10:10 ` [PATCH 0/2] Add sign extension with kernel MMIO " Huacai Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Bibo Mao @ 2025-08-19 12:17 UTC (permalink / raw)
  To: Huacai Chen, Xianglai Li; +Cc: kvm, loongarch, linux-kernel

Function kvm_complete_iocsr_read() is to add sign extension with IOCSR
read emulation, it is used in user space IOCSR read return now. Also
it can be used in kernel IOCSR read emulation.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 arch/loongarch/kvm/exit.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
index 6fee1b8c35eb..e4ad2d4acdf1 100644
--- a/arch/loongarch/kvm/exit.c
+++ b/arch/loongarch/kvm/exit.c
@@ -218,16 +218,17 @@ int kvm_emu_iocsr(larch_inst inst, struct kvm_run *run, struct kvm_vcpu *vcpu)
 		}
 		trace_kvm_iocsr(KVM_TRACE_IOCSR_WRITE, run->iocsr_io.len, addr, val);
 	} else {
+		/* Save register id for iocsr read completion */
+		vcpu->arch.io_gpr = rd;
 		idx = srcu_read_lock(&vcpu->kvm->srcu);
-		ret = kvm_io_bus_read(vcpu, KVM_IOCSR_BUS, addr, run->iocsr_io.len, val);
+		ret = kvm_io_bus_read(vcpu, KVM_IOCSR_BUS, addr, run->iocsr_io.len,
+					run->iocsr_io.data);
 		srcu_read_unlock(&vcpu->kvm->srcu, idx);
-		if (ret == 0)
+		if (ret == 0) {
+			kvm_complete_iocsr_read(vcpu, run);
 			ret = EMULATE_DONE;
-		else {
+		} else
 			ret = EMULATE_DO_IOCSR;
-			/* Save register id for iocsr read completion */
-			vcpu->arch.io_gpr = rd;
-		}
 		trace_kvm_iocsr(KVM_TRACE_IOCSR_READ, run->iocsr_io.len, addr, NULL);
 	}
 
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Add sign extension with kernel MMIO read emulation
  2025-08-19 12:17 [PATCH 0/2] Add sign extension with kernel MMIO read emulation Bibo Mao
  2025-08-19 12:17 ` [PATCH 1/2] LoongArch: KVM: " Bibo Mao
  2025-08-19 12:17 ` [PATCH 2/2] LoongArch: KVM: Add sign extension with kernel IOCSR " Bibo Mao
@ 2025-08-29 10:10 ` Huacai Chen
  2 siblings, 0 replies; 4+ messages in thread
From: Huacai Chen @ 2025-08-29 10:10 UTC (permalink / raw)
  To: Bibo Mao; +Cc: Xianglai Li, kvm, loongarch, linux-kernel

Applied, thanks.


Huacai

On Tue, Aug 19, 2025 at 8:17 PM Bibo Mao <maobibo@loongson.cn> wrote:
>
> This patch is to add sign extension with kernel MMIO/IOCSR read
> emulation, it is similar with user space MMIO/IOCSR read completion
> handling.
>
> Bibo Mao (2):
>   LoongArch: KVM: Add sign extension with kernel MMIO read emulation
>   LoongArch: KVM: Add sign extension with kernel IOCSR read emulation
>
>  arch/loongarch/kvm/exit.c | 21 ++++++++++++---------
>  1 file changed, 12 insertions(+), 9 deletions(-)
>
>
> base-commit: be48bcf004f9d0c9207ff21d0edb3b42f253829e
> --
> 2.39.3
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-29 10:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-19 12:17 [PATCH 0/2] Add sign extension with kernel MMIO read emulation Bibo Mao
2025-08-19 12:17 ` [PATCH 1/2] LoongArch: KVM: " Bibo Mao
2025-08-19 12:17 ` [PATCH 2/2] LoongArch: KVM: Add sign extension with kernel IOCSR " Bibo Mao
2025-08-29 10:10 ` [PATCH 0/2] Add sign extension with kernel MMIO " Huacai Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).