All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Fontana <cfontana@suse.de>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Wenchao Wang" <wenchao.wang@intel.com>,
	"Roman Bolshakov" <r.bolshakov@yadro.com>,
	"Sunil Muthuswamy" <sunilmut@microsoft.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: "Laurent Vivier" <lvivier@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Paul Durrant" <paul@xen.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Jason Wang" <jasowang@redhat.com>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	qemu-devel@nongnu.org, "Peter Xu" <peterx@redhat.com>,
	"Dario Faggioli" <dfaggioli@suse.com>,
	"Cameron Esfahani" <dirty@apple.com>,
	haxm-team@intel.com, "Claudio Fontana" <cfontana@suse.de>,
	"Anthony Perard" <anthony.perard@citrix.com>,
	"Bruce Rogers" <brogers@suse.com>,
	"Olaf Hering" <ohering@suse.de>,
	"Emilio G . Cota" <cota@braap.org>,
	"Colin Xu" <colin.xu@intel.com>
Subject: [PATCH v12 20/23] target/arm: do not use cc->do_interrupt for KVM directly
Date: Sat, 12 Dec 2020 16:55:27 +0100	[thread overview]
Message-ID: <20201212155530.23098-21-cfontana@suse.de> (raw)
In-Reply-To: <20201212155530.23098-1-cfontana@suse.de>

cc->do_interrupt is in theory a TCG callback used in accel/tcg only,
to prepare the emulated architecture to take an interrupt as defined
in the hardware specifications,

but in reality the _do_interrupt style of functions in targets are
also occasionally reused by KVM to prepare the architecture state in a
similar way where userspace code has identified that it needs to
deliver an exception to the guest.

In the case of ARM, that includes:

1) the vcpu thread got a SIGBUS indicating a memory error,
   and we need to deliver a Synchronous External Abort to the guest to
   let it know about the error.
2) the kernel told us about a debug exception (breakpoint, watchpoint)
   but it is not for one of QEMU's own gdbstub breakpoints/watchpoints
   so it must be a breakpoint the guest itself has set up, therefore
   we need to deliver it to the guest.

So in order to reuse code, the same arm_do_interrupt function is used.
This is all fine, but we need to avoid calling it using the callback
registered in CPUClass, since that one is now TCG-only.

Fortunately this is easily solved by replacing calls to
CPUClass::do_interrupt() with explicit calls to arm_do_interrupt().

Signed-off-by: Claudio Fontana <cfontana@suse.de>
Cc: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/helper.c | 4 ++++
 target/arm/kvm64.c  | 6 ++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/target/arm/helper.c b/target/arm/helper.c
index 7b8bcd6903..fcef942eb8 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -9895,6 +9895,10 @@ static void handle_semihosting(CPUState *cs)
  * Do any appropriate logging, handle PSCI calls, and then hand off
  * to the AArch64-entry or AArch32-entry function depending on the
  * target exception level's register width.
+ *
+ * Note: this is used for both TCG (as the do_interrupt tcg op),
+ *       and KVM to re-inject guest debug exceptions, and to
+ *       inject a Synchronous-External-Abort.
  */
 void arm_cpu_do_interrupt(CPUState *cs)
 {
diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
index f74bac2457..3728b3a336 100644
--- a/target/arm/kvm64.c
+++ b/target/arm/kvm64.c
@@ -944,7 +944,6 @@ static void kvm_inject_arm_sea(CPUState *c)
 {
     ARMCPU *cpu = ARM_CPU(c);
     CPUARMState *env = &cpu->env;
-    CPUClass *cc = CPU_GET_CLASS(c);
     uint32_t esr;
     bool same_el;
 
@@ -960,7 +959,7 @@ static void kvm_inject_arm_sea(CPUState *c)
 
     env->exception.syndrome = esr;
 
-    cc->do_interrupt(c);
+    arm_cpu_do_interrupt(c);
 }
 
 #define AARCH64_CORE_REG(x)   (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
@@ -1491,7 +1490,6 @@ bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit)
 {
     int hsr_ec = syn_get_ec(debug_exit->hsr);
     ARMCPU *cpu = ARM_CPU(cs);
-    CPUClass *cc = CPU_GET_CLASS(cs);
     CPUARMState *env = &cpu->env;
 
     /* Ensure PC is synchronised */
@@ -1545,7 +1543,7 @@ bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit)
     env->exception.vaddress = debug_exit->far;
     env->exception.target_el = 1;
     qemu_mutex_lock_iothread();
-    cc->do_interrupt(cs);
+    arm_cpu_do_interrupt(cs);
     qemu_mutex_unlock_iothread();
 
     return false;
-- 
2.26.2



  parent reply	other threads:[~2020-12-12 18:25 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-12 15:55 [PATCH v12 00/23] i386 cleanup PART 1 Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 01/23] i386: move kvm accel files into kvm/ Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 02/23] i386: move whpx accel files into whpx/ Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 03/23] i386: move hax accel files into hax/ Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 04/23] i386: hvf: remove stale MAINTAINERS entry for old hvf stubs Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 05/23] i386: move TCG accel files into tcg/ Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 06/23] i386: move cpu dump out of helper.c into cpu-dump.c Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 07/23] i386: move TCG cpu class initialization to tcg/ Claudio Fontana
2020-12-15 22:08   ` Richard Henderson
2020-12-12 15:55 ` [PATCH v12 08/23] i386: tcg: remove inline from cpu_load_eflags Claudio Fontana
2020-12-15 22:09   ` Richard Henderson
2020-12-12 15:55 ` [PATCH v12 09/23] tcg: cpu_exec_{enter,exit} helpers Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 10/23] tcg: make CPUClass.cpu_exec_* optional Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 11/23] tcg: Make CPUClass.debug_excp_handler optional Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 12/23] cpu: Remove unnecessary noop methods Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 13/23] cpu: Introduce TCGCpuOperations struct Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 14/23] target/riscv: remove CONFIG_TCG, as it is always TCG Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 15/23] accel/tcg: split TCG-only code from cpu_exec_realizefn Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 16/23] cpu: Move synchronize_from_tb() to tcg_ops Claudio Fontana
2020-12-14 19:10   ` Eduardo Habkost
2020-12-14 21:56     ` Philippe Mathieu-Daudé
2020-12-14 22:23       ` Eduardo Habkost
2020-12-16 20:09         ` Eduardo Habkost
2020-12-16  8:44       ` Claudio Fontana
2020-12-16 19:18         ` Richard Henderson
2020-12-12 15:55 ` [PATCH v12 17/23] cpu: Move cpu_exec_* " Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 18/23] cpu: Move tlb_fill " Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 19/23] cpu: Move debug_excp_handler " Claudio Fontana
2020-12-12 15:55 ` Claudio Fontana [this message]
2020-12-12 15:55 ` [PATCH v12 21/23] cpu: move cc->do_interrupt " Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 22/23] cpu: move cc->transaction_failed " Claudio Fontana
2020-12-12 15:55 ` [PATCH v12 23/23] cpu: move do_unaligned_access " Claudio Fontana
2020-12-12 18:51 ` [PATCH v12 00/23] i386 cleanup PART 1 no-reply
2020-12-14 21:08 ` Eduardo Habkost
2020-12-16 20:11 ` Eduardo Habkost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201212155530.23098-21-cfontana@suse.de \
    --to=cfontana@suse.de \
    --cc=alex.bennee@linaro.org \
    --cc=anthony.perard@citrix.com \
    --cc=brogers@suse.com \
    --cc=colin.xu@intel.com \
    --cc=cota@braap.org \
    --cc=dfaggioli@suse.com \
    --cc=dirty@apple.com \
    --cc=ehabkost@redhat.com \
    --cc=haxm-team@intel.com \
    --cc=jasowang@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=ohering@suse.de \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=r.bolshakov@yadro.com \
    --cc=richard.henderson@linaro.org \
    --cc=sstabellini@kernel.org \
    --cc=sunilmut@microsoft.com \
    --cc=thuth@redhat.com \
    --cc=wenchao.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.