linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb+git@google.com>
To: linux-arm-kernel@lists.infradead.org
Cc: linux@armlinux.org.uk, Ard Biesheuvel <ardb@kernel.org>,
	 Linus Walleij <linus.walleij@linaro.org>,
	Arnd Bergmann <arnd@arndb.de>,
	walther-it@gmx.de
Subject: [PATCH] ARM: iwmmxt: Handle Thumb2 encodings of coproc loads and stores
Date: Wed, 31 Jan 2024 12:40:29 +0100	[thread overview]
Message-ID: <20240131114028.625373-2-ardb+git@google.com> (raw)

From: Ard Biesheuvel <ardb@kernel.org>

The iWMMXt ISA only exists in a 32-bit encoding, but the generic load
and store instructions operating on coprocessor #1, which iWMMXt
repurposes as WLDR/WSTR instructions, can in fact be emitted as Thumb2
encodings as well.

The register file preserve/restore logic that glibc has as part of its
implementation setjmp/longjmp (among other things) uses the generic
LDC/STC mnemonics, which the assembler happily emits as Thumb2 if that
happens to be how the file is being built.

This means that, even though iWMMXt itself is only defined for ARM mode,
we need to take into account the possibility that we UNDEF in Thumb2
code when attempting to access iWMMXt registers, and trigger the
associated lazy preserve/restore logic as usual.

Given that this only applies to PJ4 and not to Xscale, add this handling
to PJ4 only.

Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Reported-by: walther-it@gmx.de
Fixes: 8bcba70cb5c2204a ("ARM: entry: Disregard Thumb undef exception in coproc dispatch")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm/kernel/pj4-cp0.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/arm/kernel/pj4-cp0.c b/arch/arm/kernel/pj4-cp0.c
index 4bca8098c4ff..2ef4f8a2bce0 100644
--- a/arch/arm/kernel/pj4-cp0.c
+++ b/arch/arm/kernel/pj4-cp0.c
@@ -101,6 +101,19 @@ static int __init pj4_get_iwmmxt_version(void)
 	return -EINVAL;
 }
 
+/*
+ * The iWMMXt ISA is only defined in ARM mode, but the generic coprocessor
+ * load/store instructions (LDC/STC) exist in a Thumb2 encoding as well, and
+ * may be used (e.g., by glibc) to preserve/restore the iWMMXt register file.
+ */
+static struct undef_hook iwmmxt_undef_t2_hook = {
+       .instr_mask     = 0xee000f00,
+       .instr_val      = 0xec000100,
+       .cpsr_mask      = MODE_MASK | PSR_T_BIT,
+       .cpsr_val       = USR_MODE | PSR_T_BIT,
+       .fn             = iwmmxt_undef_handler,
+};
+
 /*
  * Disable CP0/CP1 on boot, and let call_fpe() and the iWMMXt lazy
  * switch code handle iWMMXt context switching.
@@ -127,6 +140,9 @@ static int __init pj4_cp0_init(void)
 	elf_hwcap |= HWCAP_IWMMXT;
 	thread_register_notifier(&iwmmxt_notifier_block);
 	register_iwmmxt_undef_handler();
+
+	if (IS_ENABLED(CONFIG_ARM_THUMB))
+		register_undef_hook(&iwmmxt_undef_t2_hook);
 #endif
 
 	return 0;
-- 
2.43.0.429.g432eaa2c6b-goog


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

                 reply	other threads:[~2024-01-31 11:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240131114028.625373-2-ardb+git@google.com \
    --to=ardb+git@google.com \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=walther-it@gmx.de \
    /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 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).