Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/817561/?format=api
{ "id": 817561, "url": "http://patchwork.ozlabs.org/api/patches/817561/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/1506092407-26985-4-git-send-email-peter.maydell@linaro.org/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<1506092407-26985-4-git-send-email-peter.maydell@linaro.org>", "list_archive_url": null, "date": "2017-09-22T14:59:50", "name": "[03/20] target/arm: Prepare for CONTROL.SPSEL being nonzero in Handler mode", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "7f126425f769cac51b3f77e60ed1fab0421a47b1", "submitter": { "id": 5111, "url": "http://patchwork.ozlabs.org/api/people/5111/?format=api", "name": "Peter Maydell", "email": "peter.maydell@linaro.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/1506092407-26985-4-git-send-email-peter.maydell@linaro.org/mbox/", "series": [ { "id": 4650, "url": "http://patchwork.ozlabs.org/api/series/4650/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=4650", "date": "2017-09-22T14:59:47", "name": "ARM v8M: exception entry, exit and security", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/4650/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/817561/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/817561/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)", "Received": [ "from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xzGvP5gLWz9sPm\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat, 23 Sep 2017 01:03:29 +1000 (AEST)", "from localhost ([::1]:59326 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dvPUF-0002AV-Rs\n\tfor incoming@patchwork.ozlabs.org; Fri, 22 Sep 2017 11:03:27 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:46992)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pm215@archaic.org.uk>) id 1dvPQZ-0007x4-34\n\tfor qemu-devel@nongnu.org; Fri, 22 Sep 2017 10:59:40 -0400", "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pm215@archaic.org.uk>) id 1dvPQX-00045M-O3\n\tfor qemu-devel@nongnu.org; Fri, 22 Sep 2017 10:59:39 -0400", "from orth.archaic.org.uk ([2001:8b0:1d0::2]:37534)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <pm215@archaic.org.uk>)\n\tid 1dvPQU-0003yz-3t; Fri, 22 Sep 2017 10:59:34 -0400", "from pm215 by orth.archaic.org.uk with local (Exim 4.89)\n\t(envelope-from <pm215@archaic.org.uk>)\n\tid 1dvPQR-00078T-S7; Fri, 22 Sep 2017 15:59:31 +0100" ], "From": "Peter Maydell <peter.maydell@linaro.org>", "To": "qemu-arm@nongnu.org,\n\tqemu-devel@nongnu.org", "Date": "Fri, 22 Sep 2017 15:59:50 +0100", "Message-Id": "<1506092407-26985-4-git-send-email-peter.maydell@linaro.org>", "X-Mailer": "git-send-email 2.7.4", "In-Reply-To": "<1506092407-26985-1-git-send-email-peter.maydell@linaro.org>", "References": "<1506092407-26985-1-git-send-email-peter.maydell@linaro.org>", "X-detected-operating-system": "by eggs.gnu.org: Genre and OS details not\n\trecognized.", "X-Received-From": "2001:8b0:1d0::2", "Subject": "[Qemu-devel] [PATCH 03/20] target/arm: Prepare for CONTROL.SPSEL\n\tbeing nonzero in Handler mode", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.21", "Precedence": "list", "List-Id": "<qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<http://lists.nongnu.org/archive/html/qemu-devel/>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Cc": "patches@linaro.org", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>" }, "content": "In the v7M architecture, there is an invariant that if the CPU is\nin Handler mode then the CONTROL.SPSEL bit cannot be nonzero.\nThis in turn means that the current stack pointer is always\nindicated by CONTROL.SPSEL, even though Handler mode always uses\nthe Main stack pointer.\n\nIn v8M, this invariant is removed, and CONTROL.SPSEL may now\nbe nonzero in Handler mode (though Handler mode still always\nuses the Main stack pointer). In preparation for this change,\nchange how we handle this bit: rename switch_v7m_sp() to\nthe now more accurate write_v7m_control_spsel(), and make it\ncheck both the handler mode state and the SPSEL bit.\n\nNote that this implicitly changes the point at which we switch\nactive SP on exception exit from before we pop the exception\nframe to after it.\n\nSigned-off-by: Peter Maydell <peter.maydell@linaro.org>\n---\n target/arm/cpu.h | 8 ++++++-\n hw/intc/armv7m_nvic.c | 2 +-\n target/arm/helper.c | 65 ++++++++++++++++++++++++++++++++++-----------------\n 3 files changed, 51 insertions(+), 24 deletions(-)", "diff": "diff --git a/target/arm/cpu.h b/target/arm/cpu.h\nindex 8afceca..ad6eff4 100644\n--- a/target/arm/cpu.h\n+++ b/target/arm/cpu.h\n@@ -991,6 +991,11 @@ void pmccntr_sync(CPUARMState *env);\n #define PSTATE_MODE_EL1t 4\n #define PSTATE_MODE_EL0t 0\n \n+/* Write a new value to v7m.exception, thus transitioning into or out\n+ * of Handler mode; this may result in a change of active stack pointer.\n+ */\n+void write_v7m_exception(CPUARMState *env, uint32_t new_exc);\n+\n /* Map EL and handler into a PSTATE_MODE. */\n static inline unsigned int aarch64_pstate_mode(unsigned int el, bool handler)\n {\n@@ -1071,7 +1076,8 @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)\n env->condexec_bits |= (val >> 8) & 0xfc;\n }\n if (mask & XPSR_EXCP) {\n- env->v7m.exception = val & XPSR_EXCP;\n+ /* Note that this only happens on exception exit */\n+ write_v7m_exception(env, val & XPSR_EXCP);\n }\n }\n \ndiff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c\nindex bc7b66d..a1041c2 100644\n--- a/hw/intc/armv7m_nvic.c\n+++ b/hw/intc/armv7m_nvic.c\n@@ -616,7 +616,7 @@ bool armv7m_nvic_acknowledge_irq(void *opaque)\n vec->active = 1;\n vec->pending = 0;\n \n- env->v7m.exception = s->vectpending;\n+ write_v7m_exception(env, s->vectpending);\n \n nvic_irq_update(s);\n \ndiff --git a/target/arm/helper.c b/target/arm/helper.c\nindex f13b99d..509a1aa 100644\n--- a/target/arm/helper.c\n+++ b/target/arm/helper.c\n@@ -6052,21 +6052,44 @@ static bool v7m_using_psp(CPUARMState *env)\n env->v7m.control[env->v7m.secure] & R_V7M_CONTROL_SPSEL_MASK;\n }\n \n-/* Switch to V7M main or process stack pointer. */\n-static void switch_v7m_sp(CPUARMState *env, bool new_spsel)\n+/* Write to v7M CONTROL.SPSEL bit. This may change the current\n+ * stack pointer between Main and Process stack pointers.\n+ */\n+static void write_v7m_control_spsel(CPUARMState *env, bool new_spsel)\n {\n uint32_t tmp;\n- uint32_t old_control = env->v7m.control[env->v7m.secure];\n- bool old_spsel = old_control & R_V7M_CONTROL_SPSEL_MASK;\n+ bool new_is_psp, old_is_psp = v7m_using_psp(env);\n+\n+ env->v7m.control[env->v7m.secure] =\n+ deposit32(env->v7m.control[env->v7m.secure],\n+ R_V7M_CONTROL_SPSEL_SHIFT,\n+ R_V7M_CONTROL_SPSEL_LENGTH, new_spsel);\n+\n+ new_is_psp = v7m_using_psp(env);\n \n- if (old_spsel != new_spsel) {\n+ if (old_is_psp != new_is_psp) {\n tmp = env->v7m.other_sp;\n env->v7m.other_sp = env->regs[13];\n env->regs[13] = tmp;\n+ }\n+}\n+\n+void write_v7m_exception(CPUARMState *env, uint32_t new_exc)\n+{\n+ /* Write a new value to v7m.exception, thus transitioning into or out\n+ * of Handler mode; this may result in a change of active stack pointer.\n+ */\n+ bool new_is_psp, old_is_psp = v7m_using_psp(env);\n+ uint32_t tmp;\n \n- env->v7m.control[env->v7m.secure] = deposit32(old_control,\n- R_V7M_CONTROL_SPSEL_SHIFT,\n- R_V7M_CONTROL_SPSEL_LENGTH, new_spsel);\n+ env->v7m.exception = new_exc;\n+\n+ new_is_psp = v7m_using_psp(env);\n+\n+ if (old_is_psp != new_is_psp) {\n+ tmp = env->v7m.other_sp;\n+ env->v7m.other_sp = env->regs[13];\n+ env->regs[13] = tmp;\n }\n }\n \n@@ -6149,13 +6172,11 @@ static uint32_t *get_v7m_sp_ptr(CPUARMState *env, bool secure, bool threadmode,\n bool want_psp = threadmode && spsel;\n \n if (secure == env->v7m.secure) {\n- /* Currently switch_v7m_sp switches SP as it updates SPSEL,\n- * so the SP we want is always in regs[13].\n- * When we decouple SPSEL from the actually selected SP\n- * we need to check want_psp against v7m_using_psp()\n- * to see whether we need regs[13] or v7m.other_sp.\n- */\n- return &env->regs[13];\n+ if (want_psp == v7m_using_psp(env)) {\n+ return &env->regs[13];\n+ } else {\n+ return &env->v7m.other_sp;\n+ }\n } else {\n if (want_psp) {\n return &env->v7m.other_ss_psp;\n@@ -6198,7 +6219,7 @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr)\n uint32_t addr;\n \n armv7m_nvic_acknowledge_irq(env->nvic);\n- switch_v7m_sp(env, 0);\n+ write_v7m_control_spsel(env, 0);\n arm_clear_exclusive(env);\n /* Clear IT bits */\n env->condexec_bits = 0;\n@@ -6344,11 +6365,11 @@ static void do_v7m_exception_exit(ARMCPU *cpu)\n return;\n }\n \n- /* Set CONTROL.SPSEL from excret.SPSEL. For QEMU this currently\n- * causes us to switch the active SP, but we will change this\n- * later to not do that so we can support v8M.\n+ /* Set CONTROL.SPSEL from excret.SPSEL. Since we're still in\n+ * Handler mode (and will be until we write the new XPSR.Interrupt\n+ * field) this does not switch around the current stack pointer.\n */\n- switch_v7m_sp(env, return_to_sp_process);\n+ write_v7m_control_spsel(env, return_to_sp_process);\n \n {\n /* The stack pointer we should be reading the exception frame from\n@@ -9163,11 +9184,11 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)\n case 20: /* CONTROL */\n /* Writing to the SPSEL bit only has an effect if we are in\n * thread mode; other bits can be updated by any privileged code.\n- * switch_v7m_sp() deals with updating the SPSEL bit in\n+ * write_v7m_control_spsel() deals with updating the SPSEL bit in\n * env->v7m.control, so we only need update the others.\n */\n if (!arm_v7m_is_handler_mode(env)) {\n- switch_v7m_sp(env, (val & R_V7M_CONTROL_SPSEL_MASK) != 0);\n+ write_v7m_control_spsel(env, (val & R_V7M_CONTROL_SPSEL_MASK) != 0);\n }\n env->v7m.control[env->v7m.secure] &= ~R_V7M_CONTROL_NPRIV_MASK;\n env->v7m.control[env->v7m.secure] |= val & R_V7M_CONTROL_NPRIV_MASK;\n", "prefixes": [ "03/20" ] }