From patchwork Wed Jan 31 11:40:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13539346 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6AA93C47258 for ; Wed, 31 Jan 2024 11:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=7tKvCR8/dXHDaULH/VZH5/Dl+cIVOEWtixIZ3tMf0lg=; b=bJY GUVi5zOiv6aFnTwGzimS3sSiAjv2hpmrfnj4ITLGH9OAklCoHTq3pymNPZUoW8RwjRcnGT06B40Rg iAte8s56zwgOapTxnpfB5HdT88QzadllBLfF7HnjeBD5aDOsQJyInvMX688On8UnXODTUE5xM13/1 3sCHgh2MXuPYwN4WsUbtxCQzTJFI0UMtXo2QGHSobCeBqsujj9y9NOrlZWomnB8nVvCwuD6vzLST+ HKHQBLergg8KOIyBxg9k8y4jmKbqfB8LdONcKV08ibJqwUL8qjicc/2H86/UIsL8YVCXj5I59al0D Qokf6IbkLFnm9zcDxzQAsR5GdddK8SA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rV8xR-00000003Awz-0FQf; Wed, 31 Jan 2024 11:40:45 +0000 Received: from mail-ej1-x64a.google.com ([2a00:1450:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rV8xO-00000003Auy-1RCO for linux-arm-kernel@lists.infradead.org; Wed, 31 Jan 2024 11:40:43 +0000 Received: by mail-ej1-x64a.google.com with SMTP id a640c23a62f3a-a365b809240so55685166b.0 for ; Wed, 31 Jan 2024 03:40:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706701239; x=1707306039; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=upDms1LBnFk0KUo+Gu46Lso71MLBIiyoNGek8lMVPUs=; b=VcuXEkj8wiFnQ5R1Dr8h4vVJg1W/p+NXTgS4oOJMILBQWGK2SKbX9nEMHh9aIGgJCm 0LFeb/Vg8feVURnSHrmFvyMgfA5StL3SK80T0PcN/dZR2syNknTQ/5o2zLJ3Uc4IRxfr KObZNfnrrD/XGp2BI+l9ivtR75b7Jqh24wGgjM5/as6xbAgMFk7yROeWb14If4D7S3DT mWXuehMshI8XgQvxN/5sDzjlKHutWMEnL0X4iIzRbI1hE2J/MeGQcEkWMkzz6R3YEQsx 1ISitIGyQ7rn0kZkqtILQdFJ/F1XdBhUAFsVQ9t/moRaFO+BGMo7iI14diiuoxNnamzC ioyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706701239; x=1707306039; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=upDms1LBnFk0KUo+Gu46Lso71MLBIiyoNGek8lMVPUs=; b=UFeAmT3PJxL3T0+xjuXyMN/XpBDevM6UNTtmtUBWJt3w3+eUN7hN9TUfrQabJjN5RP FZHaeQwxOzkBGPFg9N0dlihIIuFqM2aRBYKGZSnSS4eWUVjztQ+kkvsJw7/82x5efwek Jrb62n0e6Czs6lhnt3P2DPANaie+6zDC7GTRcI0Uv5U6KVO4Ue1tXZUWnL4zYJk68uYn 9Pz2YKXUdAQFIxZfsD25qKTURPcb9vGxcGz13wYAT77wC0MJHOGwgW1LCrNBvo+h9lHy s2Y5HpzaUr3z+ri0EFRC8p6Dlpzd8SQYOikxp+hOu4PguVTcBT8MTC1lpMFGYNYdKXim 1ZGQ== X-Gm-Message-State: AOJu0YzS+7m8ZT9Kv121dDiNWyLF0Cj/j62R+LWGNeYdxFvzc/t1hZ4t Kpd4cpMf3qDj5+ja5qq6XXS2+H9mivovs9bUohdGkixOpi9opVAfOUn4/sVO48sfar8wrFU5yOU WLVYynWQ76j9Uqre2x69gwhCc//FO+0PDWah6SoRSSVDOZ8FL6ZzUzr6T9hCssEOzwSok08yGRa lznzh+RgslIbtn5CydbhBOy8JCTET9CQUN4+yy0jgR X-Google-Smtp-Source: AGHT+IHEDY98AylW1KaKHQkW0/bLwe3N8W8eKA62Epd540mFkKmvl2Fh0KHpPbxo8gEWrV91tlPjhfaV X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a17:906:a855:b0:a36:266c:8b9c with SMTP id dx21-20020a170906a85500b00a36266c8b9cmr2328ejb.8.1706701238887; Wed, 31 Jan 2024 03:40:38 -0800 (PST) Date: Wed, 31 Jan 2024 12:40:29 +0100 Mime-Version: 1.0 X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2439; i=ardb@kernel.org; h=from:subject; bh=4UwhiiAlGGzcJM3YEyOKH3VTKQxkgxw/twFh0qtM4Kc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXWX4dpN0crPdOzaP7ZF+h/jLrpm8JRPat0Kz/spl/TeS ptEtAZ2lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIlM/MnwT3fO+6dPjnp0hJUz GxfER/v0q58TyxGW5Ht7dkI0S/JpNob/ob0X1n7tWfT+7wu/B/cXznmxoTpl5rEXHxeF308O/RL sxwkA X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240131114028.625373-2-ardb+git@google.com> Subject: [PATCH] ARM: iwmmxt: Handle Thumb2 encodings of coproc loads and stores From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux@armlinux.org.uk, Ard Biesheuvel , Linus Walleij , Arnd Bergmann , walther-it@gmx.de X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_034042_432698_8812E62E X-CRM114-Status: GOOD ( 16.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ard Biesheuvel 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 Cc: Arnd Bergmann Reported-by: walther-it@gmx.de Fixes: 8bcba70cb5c2204a ("ARM: entry: Disregard Thumb undef exception in coproc dispatch") Signed-off-by: Ard Biesheuvel --- 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;