From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH] target-mips: Ignore unassigned accesses with KVM Date: Tue, 29 Jul 2014 10:55:29 +0200 Message-ID: <53D76181.3050806@redhat.com> References: <1406547470-22766-1-git-send-email-james.hogan@imgtec.com> <20140728213628.GA24554@ohm.rr44.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Cc: qemu-devel@nongnu.org, Peter Maydell , kvm@vger.kernel.org, Gleb Natapov , Christoffer Dall , Sanjay Lal To: Aurelien Jarno , James Hogan Return-path: Received: from mx1.redhat.com ([209.132.183.28]:16192 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750746AbaG2I4N (ORCPT ); Tue, 29 Jul 2014 04:56:13 -0400 In-Reply-To: <20140728213628.GA24554@ohm.rr44.fr> Sender: kvm-owner@vger.kernel.org List-ID: Il 28/07/2014 23:36, Aurelien Jarno ha scritto: > On Mon, Jul 28, 2014 at 12:37:50PM +0100, James Hogan wrote: >> MIPS registers an unassigned access handler which raises a guest bus >> error exception. However this causes QEMU to crash when KVM is enabled >> as it isn't called from the main execution loop so longjmp() gets called >> without a corresponding setjmp(). >> >> Until the KVM API can be updated to trigger a guest exception in >> response to an MMIO exit, prevent the bus error exception being raised >> from mips_cpu_unassigned_access() if KVM is enabled. >> >> The check is at run time since the do_unassigned_access callback is >> initialised before it is known whether KVM will be enabled. >> >> The problem can be triggered with Malta emulation by making the guest >> write to the reset region at physical address 0x1bf00000, since it is >> marked read-only which is treated as unassigned for writes. >> >> Signed-off-by: James Hogan >> Cc: Aurelien Jarno >> Cc: Peter Maydell >> Cc: Paolo Bonzini >> Cc: Gleb Natapov >> Cc: Christoffer Dall >> Cc: Sanjay Lal >> --- >> target-mips/op_helper.c | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c >> index 27651a4a00c1..df97b35f8701 100644 >> --- a/target-mips/op_helper.c >> +++ b/target-mips/op_helper.c >> @@ -21,6 +21,7 @@ >> #include "qemu/host-utils.h" >> #include "exec/helper-proto.h" >> #include "exec/cpu_ldst.h" >> +#include "sysemu/kvm.h" >> >> #ifndef CONFIG_USER_ONLY >> static inline void cpu_mips_tlb_flush (CPUMIPSState *env, int flush_global); >> @@ -2168,6 +2169,16 @@ void mips_cpu_unassigned_access(CPUState *cs, hwaddr addr, >> MIPSCPU *cpu = MIPS_CPU(cs); >> CPUMIPSState *env = &cpu->env; >> >> + /* >> + * Raising an exception with KVM enabled will crash because it won't be from >> + * the main execution loop so the longjmp won't have a matching setjmp. >> + * Until we can trigger a bus error exception through KVM lets just ignore >> + * the access. >> + */ >> + if (kvm_enabled()) { >> + return; >> + } >> + >> if (is_exec) { >> helper_raise_exception(env, EXCP_IBE); >> } else { > > Reviewed-by: Aurelien Jarno > > Note that even if the test is added for each exception, it is light > enough compared to triggering and handling an exception so that it has > no impact on performance. > > Paolo, do you want to take this patch in your kvm tree? Sure, I'll include it for 2.2. Paolo From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XC3Cj-0002FN-CE for qemu-devel@nongnu.org; Tue, 29 Jul 2014 04:56:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XC3Cf-00088Q-Eg for qemu-devel@nongnu.org; Tue, 29 Jul 2014 04:56:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XC3Cf-00088J-6f for qemu-devel@nongnu.org; Tue, 29 Jul 2014 04:56:13 -0400 Message-ID: <53D76181.3050806@redhat.com> Date: Tue, 29 Jul 2014 10:55:29 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1406547470-22766-1-git-send-email-james.hogan@imgtec.com> <20140728213628.GA24554@ohm.rr44.fr> In-Reply-To: <20140728213628.GA24554@ohm.rr44.fr> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] target-mips: Ignore unassigned accesses with KVM List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Aurelien Jarno , James Hogan Cc: Peter Maydell , kvm@vger.kernel.org, Gleb Natapov , qemu-devel@nongnu.org, Sanjay Lal , Christoffer Dall Il 28/07/2014 23:36, Aurelien Jarno ha scritto: > On Mon, Jul 28, 2014 at 12:37:50PM +0100, James Hogan wrote: >> MIPS registers an unassigned access handler which raises a guest bus >> error exception. However this causes QEMU to crash when KVM is enabled >> as it isn't called from the main execution loop so longjmp() gets called >> without a corresponding setjmp(). >> >> Until the KVM API can be updated to trigger a guest exception in >> response to an MMIO exit, prevent the bus error exception being raised >> from mips_cpu_unassigned_access() if KVM is enabled. >> >> The check is at run time since the do_unassigned_access callback is >> initialised before it is known whether KVM will be enabled. >> >> The problem can be triggered with Malta emulation by making the guest >> write to the reset region at physical address 0x1bf00000, since it is >> marked read-only which is treated as unassigned for writes. >> >> Signed-off-by: James Hogan >> Cc: Aurelien Jarno >> Cc: Peter Maydell >> Cc: Paolo Bonzini >> Cc: Gleb Natapov >> Cc: Christoffer Dall >> Cc: Sanjay Lal >> --- >> target-mips/op_helper.c | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c >> index 27651a4a00c1..df97b35f8701 100644 >> --- a/target-mips/op_helper.c >> +++ b/target-mips/op_helper.c >> @@ -21,6 +21,7 @@ >> #include "qemu/host-utils.h" >> #include "exec/helper-proto.h" >> #include "exec/cpu_ldst.h" >> +#include "sysemu/kvm.h" >> >> #ifndef CONFIG_USER_ONLY >> static inline void cpu_mips_tlb_flush (CPUMIPSState *env, int flush_global); >> @@ -2168,6 +2169,16 @@ void mips_cpu_unassigned_access(CPUState *cs, hwaddr addr, >> MIPSCPU *cpu = MIPS_CPU(cs); >> CPUMIPSState *env = &cpu->env; >> >> + /* >> + * Raising an exception with KVM enabled will crash because it won't be from >> + * the main execution loop so the longjmp won't have a matching setjmp. >> + * Until we can trigger a bus error exception through KVM lets just ignore >> + * the access. >> + */ >> + if (kvm_enabled()) { >> + return; >> + } >> + >> if (is_exec) { >> helper_raise_exception(env, EXCP_IBE); >> } else { > > Reviewed-by: Aurelien Jarno > > Note that even if the test is added for each exception, it is light > enough compared to triggering and handling an exception so that it has > no impact on performance. > > Paolo, do you want to take this patch in your kvm tree? Sure, I'll include it for 2.2. Paolo