Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp486276pxb; Wed, 6 Oct 2021 09:04:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuGF7RTimsMuJbj4oYQ2C9/Dzr0YK20xDSg04kD/UOoVpBmd+tc8YalGrvUJ1SJb8HH3EI X-Received: by 2002:a17:902:db04:b0:13e:f118:54de with SMTP id m4-20020a170902db0400b0013ef11854demr6059372plx.44.1633536297760; Wed, 06 Oct 2021 09:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633536297; cv=none; d=google.com; s=arc-20160816; b=NYHtLn2Xp0HzD7DfLC7NW3jujjh9J6q9vYbQBQVYqVlUE2aTRWs/l8cBMlxMFzQmR2 ydAnNJM/3WmT4FJVNR1TO1WzqxC5eriRy+Sn9hczWL0uT7f2UDRivi3fiuZQW+WdfhAF 1ZhoPuynjpuhethTbpO2Jcp1TTYml8OCTRt1I7nVQNZMDAGFsdx6oY990weiEVLAT0vO l42A29emezR+b2boI0MwcX3FO5DX1yeNvSaKeo1M3OrJtSSM28XGatKKSu+w4yzBZ3lk XDi2OCcRxXm0GY6P+twZvq+sykIvQYxyR14Lw/aQcAvQfQIMclMryhwXxpHHzYlOvVlm aZrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=OVnvyTGe/3u1cy9bVU8oT0clyJPLfvzHggRvrJMSRu4=; b=yCFPY3ZP52N1sTNdpi4gw0KP0LjjzWh4PfbIsL/2mIgRQuovKMoZ+Y1d8GF/U7X68C OBo0PvEktI3Ig3WWY5JdCKqskTdScDtFvmSza3cGEFCRw13huJzmQ7UfAfxoiTgJSa70 xe5iniHsoBQCtQt8HN9umjoxreCDzGDu2soLM7gYZCK+iq0RFISjQdUbzY5AW4QQgM13 BNCEyqGl4w7eSVByaeAKb/JPznL2f56yRCcV6nuIv+yiyFKRV0/d4qA9gfphKWf4ZXj9 jQORpdTraAX3i7yQIExuPfOGOlHgOBanz+WryoEhdqDeG8MA2BbevM3HbO4XFpZsJfFx OAlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cRq8b+Gk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si26069843pgb.393.2021.10.06.09.04.29; Wed, 06 Oct 2021 09:04:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cRq8b+Gk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239335AbhJFQD1 (ORCPT + 99 others); Wed, 6 Oct 2021 12:03:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:39430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239332AbhJFQD0 (ORCPT ); Wed, 6 Oct 2021 12:03:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2E502610CC for ; Wed, 6 Oct 2021 16:01:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633536094; bh=ZlaiC0n6P5r9j8bdKPC7sgApMtJMYoiumv6YMDwMIYE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=cRq8b+GkF+Z16Yxq4pCkXjHpb0Lt1XIkRzLrmviXQKI457GNdGL32P6BZBGwT2wFx V+Cp3cOEpmbSOOZ7v+bOmFVH2e7O3pVLtvdL7fvlcyGwmzxwJsq9wyZ/WwxcLD5ysa BTfXJrs8lGHwVmbMrmugHv4jrgQb56nTCz58JACf5xYejs7dwfz3JQxcoinR80V1by I1b9uSO4ZqnF/ErYvzn2Q5VImQWROOBe4CD+/iN1IEYzJRxxi6RVqFkxIJGQVMrflM sGaZZNfdi5RifYwlmvvtF4rINu2UMNGMjs1NsIlklSZCGIUBVg+Me/WsHpXjxUFyLA 2EJs8sai5pFBw== Received: by mail-ot1-f52.google.com with SMTP id j11-20020a9d190b000000b00546fac94456so3669943ota.6 for ; Wed, 06 Oct 2021 09:01:34 -0700 (PDT) X-Gm-Message-State: AOAM532Sf3jKVygQ0gtcIcKpNBZtJF+G1LDo8qCu/F8ESxzoEcR7N6ut cg1VTjxvanPmHbPKDx2mlv3Tu03BAb+tMbrlYSI= X-Received: by 2002:a05:6830:3189:: with SMTP id p9mr19970544ots.147.1633536093391; Wed, 06 Oct 2021 09:01:33 -0700 (PDT) MIME-Version: 1.0 References: <20210928154143.2106903-1-arnd@kernel.org> <20210928154143.2106903-7-arnd@kernel.org> In-Reply-To: <20210928154143.2106903-7-arnd@kernel.org> From: Ard Biesheuvel Date: Wed, 6 Oct 2021 18:01:22 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 06/14] ARM: disallow CONFIG_THUMB with ARMv4 To: Arnd Bergmann Cc: Russell King , Linux ARM , Linux Kernel Mailing List , Arnd Bergmann , Linus Walleij , Nathan Chancellor , Nick Desaulniers , llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 28 Sept 2021 at 17:42, Arnd Bergmann wrote: > > From: Arnd Bergmann > > We can currently build a multi-cpu enabled kernel that allows both ARMv4 > and ARMv5 CPUs, and also supports THUMB mode in user space. > > However, returning to user space in this configuration with the usr_ret > macro requires the use of the 'bx' instruction, which is refused by > the assembler: > > arch/arm/kernel/entry-armv.S: Assembler messages: > arch/arm/kernel/entry-armv.S:937: Error: selected processor does not support `bx lr' in ARM mode > arch/arm/kernel/entry-armv.S:960: Error: selected processor does not support `bx lr' in ARM mode > arch/arm/kernel/entry-armv.S:1003: Error: selected processor does not support `bx lr' in ARM mode > :2:2: note: instruction requires: armv4t > bx lr > > While it would be possible to handle this correctly in principle, doing so > seems to not be worth it, if we can simply avoid the problem by enforcing > that a kernel supporting both ARMv4 and a later CPU architecture cannot > run THUMB binaries. > I had a quick look, and it seems that the only way to handle this correctly is to emit the BX instructions, and use code patching to change them into 'mov pc, ' if the runtime detected CPU is not Thumb capable. The usual approach (emitting 'tst , #1; moveq pc, ; bx lr') is not feasible here, since we run out of space in the kuser helper slots. Reviewed-by: Ard Biesheuvel > This turned up while build-testing with clang; for some reason, > gcc never triggered the problem. > > Signed-off-by: Arnd Bergmann > --- > arch/arm/mm/Kconfig | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig > index 82aa990c4180..58afba346729 100644 > --- a/arch/arm/mm/Kconfig > +++ b/arch/arm/mm/Kconfig > @@ -675,7 +675,7 @@ config ARM_PV_FIXUP > > config ARM_THUMB > bool "Support Thumb user binaries" if !CPU_THUMBONLY && EXPERT > - depends on CPU_THUMB_CAPABLE > + depends on CPU_THUMB_CAPABLE && !CPU_32v4 > default y > help > Say Y if you want to include kernel support for running user space > -- > 2.29.2 >