From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5107EC282DD for ; Fri, 10 Jan 2020 18:03:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1CE372072E for ; Fri, 10 Jan 2020 18:03:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CE372072E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dornerworks.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipych-0008Q4-7G for qemu-devel@archiver.kernel.org; Fri, 10 Jan 2020 13:03:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51194) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipyc3-0007lz-BD for qemu-devel@nongnu.org; Fri, 10 Jan 2020 13:02:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipyc2-00062W-8A for qemu-devel@nongnu.org; Fri, 10 Jan 2020 13:02:23 -0500 Received: from mail.dornerworks.com ([12.207.209.150]:34882 helo=webmail.dornerworks.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ipybz-0005iE-Q1; Fri, 10 Jan 2020 13:02:19 -0500 From: Jeff Kubascik To: Peter Maydell , , Subject: [PATCH] target/arm: adjust program counter for wfi exception in AArch32 Date: Fri, 10 Jan 2020 13:02:11 -0500 Message-ID: <20200110180211.29025-1-jeff.kubascik@dornerworks.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.27.13.179] X-ClientProxiedBy: Mcbain.dw.local (172.27.1.45) To Mcbain.dw.local (172.27.1.45) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 12.207.209.150 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stewart Hildebrand , Jarvis Roach Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The wfi instruction can be configured to be trapped by a higher exception level, such as the EL2 hypervisor. When the instruction is trapped, the program counter should contain the address of the wfi instruction that caused the exception. The program counter is adjusted for this in the wfi op helper function. However, this correction is done to env->pc, which only applies to AArch64 mode. For AArch32, the program counter is stored in env->regs[15]. This adds an if-else statement to modify the correct program counter location based on the the current CPU mode. Signed-off-by: Jeff Kubascik --- Hello, I am using the ARMv8 version of QEMU to run the Xen hypervisor with a guest virtual machine compiled for AArch32/Thumb code. I have noticed that when the AArch32 guest VM executes the wfi instruction, the hypervisor trap of the wfi instruction sees the program counter contain the address of the instruction following the wfi. This does not occur for an AARch64 guest VM; in this case, the program counter contains the address of the wfi instruction. I am confident the correct behavior in both cases is for the program counter to contain the address of the wfi instruction, as this works on actual hardware (Xilinx Zynq UltraScale+ MPSoC). I have tested the above patch and it works for Xen with both an AArch64 guest (Linux) and an AArch32 guest (RTEMS). I'm still getting accustomed to the QEMU code base, so it may not be correct. Any feedback would be greatly appreciated. Sincerely, Jeff Kubascik --- target/arm/op_helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c index e5a346cb87..7295645854 100644 --- a/target/arm/op_helper.c +++ b/target/arm/op_helper.c @@ -295,7 +295,11 @@ void HELPER(wfi)(CPUARMState *env, uint32_t insn_len) } if (target_el) { - env->pc -= insn_len; + if (env->aarch64) + env->pc -= insn_len; + else + env->regs[15] -= insn_len; + raise_exception(env, EXCP_UDEF, syn_wfx(1, 0xe, 0, insn_len == 2), target_el); } -- 2.17.1