From patchwork Tue Jul 9 13:03:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11037011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 957B913B1 for ; Tue, 9 Jul 2019 13:03:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84F2E28755 for ; Tue, 9 Jul 2019 13:03:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EFF828757; Tue, 9 Jul 2019 13:03:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1103A2874E for ; Tue, 9 Jul 2019 13:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From: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=55uPlcx8605BME+yn6xAT8NQStN3fNNQfhXuDS2GGsU=; b=ZbW2+lCSPFudOA JpSIf61AD7KQ9Afk1ccInNImDCgGtqfE86XsvhygoSTHFtILkNprRxiB9z6mnGj7Vx39xFLiqEtQA woA1G63Sct6RqH0FtpZ9RqBs5DYKBW+nYtZuKV1q2ikugLNz52e8MCSaYg81O+cef+5Cs4hmitzq7 kSY9HhWoNKasPetsdkqgy7VC5oOAhEiA1SedzQa/N/w1GEgt7v93K/QA24aWKsR9G2V3LiNUBC2sO PZbTsE06IQDyNxzci3YCEZh3Yn9gCua1yVgwGG/Q9ECkTwjHDMs/ROrJOvx1b4nUN+6jN+Lq0faXp kEJ9o5CMgB1+zUsaM+kA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hkpm7-0007N2-JX; Tue, 09 Jul 2019 13:03:15 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hkpm5-0007Mg-9y for linux-arm-kernel@lists.infradead.org; Tue, 09 Jul 2019 13:03:14 +0000 Received: by mail-lj1-x241.google.com with SMTP id h10so19482020ljg.0 for ; Tue, 09 Jul 2019 06:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Yxx9emx1/I2cEY2sTHL1IF3iO56b8GLZ1Lsk/UYEGCM=; b=DdVE+VMTyZI5jxU+RJT+91H8y47HtVGyRN9sSB7J8DUPG/kIL7A+K0Ahr57yNI0wi7 2rrdAnUbs97lhT4R/jtQGXFegji5UEtO30kB6qVCuJ3JpH2Kw1d4jCEk1VfJ3w5aAj8x cPN1x3DQZxJN6U/4f0EDnW8iUGk49BsJd/1FexYIxGvaBtM38wzLJU0AqAikHVobiu2P 4/Q3WOKjyPfCF0dyvXURmuJwCXDeNrKAuuiTJPkLk5F9TEK5F7bwKjgx/4tBnITQh+HQ I0JdajHA0qkFu33QNhF/3BuxUi2FGvyLRm6eLb4/lA3k6ImBmbDaNXFrhJtA3qfsFxlT 7LvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Yxx9emx1/I2cEY2sTHL1IF3iO56b8GLZ1Lsk/UYEGCM=; b=SuTYNPphJRvXw/g6+1oVfxs6SGb9wFnh/j/qW0SmvSCKG8i9k4zJ6+OOIcP+XTOfU1 pTVP1ondhnt/dvKY2R9/YlhhOHaKrhsVgDCaE2spa6+RmW8L14oXivyvyhEeM6kuurc5 SWyk9ruVX5QDubWAJIB+WPqKXaaJizERFu1AH4LpFrDOY8LQZh64d+sRPjdP/+2Nd/P9 iRm/tgxpJSnT8bFEj5dIN4jyxUQGXBaSOsCRV4OP9vk14tbADPV2vrd0lcVFKswgyP8d rjfMmq1EkzrYOAe+CPrYM1r/40jkbkYN/Pp/ajXaYSqsCKiWYyJvZE40EzkK39Iolldj q26A== X-Gm-Message-State: APjAAAW3h+luIvlETEVewkp1rsUTgJwXNTa7JisJgBJhOkdc3TSo0KAJ nWBcDxXe7nODwkLla8cN4XDalQ== X-Google-Smtp-Source: APXvYqw1tpvgLeJdGjawJCw+wH/DIYEsyMJn6+k0aZ4w+nCpibb+lNHPNfv83fJbgG5gKHzwbm/q4w== X-Received: by 2002:a2e:5dc6:: with SMTP id v67mr10528306lje.240.1562677391403; Tue, 09 Jul 2019 06:03:11 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id q4sm4808037lje.99.2019.07.09.06.03.10 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 09 Jul 2019 06:03:10 -0700 (PDT) From: Linus Walleij To: Russell King Subject: [PATCH 1/2] ARM: boot: Explain the 8 nops Date: Tue, 9 Jul 2019 15:03:00 +0200 Message-Id: <20190709130301.1916-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190709_060313_346917_F8C7FA29 X-CRM114-Status: GOOD ( 10.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Linus Walleij , Roy Franz , linux-arm-kernel@lists.infradead.org, Nicolas Pitre Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This was unclear to me until Russell explained the obvious that 8 nops are added to offset an a.out image. Reading git history reveals that thumb kernels first removed the nops and then kept 7 of them (the last instruction being a switch to thumb mode) as it turns out that some boot loaders were using this as a "patch area". Also the magic numbers after the initial nops and the jump of course need to stay in the same offset for kernel file detection. Make the code easier to understand with a comment. Cc: Nicolas Pitre Cc: Roy Franz Cc: Ard Biesheuvel Signed-off-by: Linus Walleij --- arch/arm/boot/compressed/head.S | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index e59d14679fb0..544450c90673 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -153,6 +153,18 @@ AR_CLASS( .arm ) start: .type start,#function + /* + * These 7 nops along with the 1 nop immediately below for + * !THUMB2 form 8 nops that make the compressed kernel bootable + * on legacy ARM systems that were assuming the kernel in a.out + * binary format. The boot loaders on these systems would + * jump 32 bytes into the image to skip the a.out header. + * with these 8 nops filling exactly 32 bytes, things still + * work as expected on these legacy systems. Thumb2 mode keeps + * 7 of the nops as it turns out that some boot loaders + * were patching the initial instructions of the kernel, i.e + * had started to exploit this "patch area". + */ .rept 7 __nop .endr From patchwork Tue Jul 9 13:03:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11037013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABFF513B1 for ; Tue, 9 Jul 2019 13:03:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9886728759 for ; Tue, 9 Jul 2019 13:03:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CCAF28754; Tue, 9 Jul 2019 13:03:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3412B28754 for ; Tue, 9 Jul 2019 13:03:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HtvGSow80JBaHMrSJnYZt+J0mnBCKiavtI09znLgfwA=; b=oU7yJxyQQKbcMu 9Pshvh21ECHFzVyZ48/UuuDgWWtlTPv8b/7b+wRo+HVZX839bwXbZYk6tpkRYhl9b46ehVAweng5V OGtFZum+B7HAC4yCDnN25/hI87DiS6faH2D1yQZ4dKNhlYr/+pTmQakw2OhITLBqEiDD/NzWJNbH7 0Ygbz95KUiL3hFKvXEjjBn9tZpxfZL7/RWrEP3VY6M0aoUO771VecySAKOyHwjii02Aep1Q7oMdWR uV0RAJgxWrtDbHUlF0BDZtcKaHYaHjBuMmEp9n8JZFQaqHcB8tsnEBHynuVyUmw+apjoRolrXVjfX svL0B7ah7uU3fpo+OKYg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hkpmH-0007Ve-5L; Tue, 09 Jul 2019 13:03:25 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hkpm7-0007Mu-Mg for linux-arm-kernel@lists.infradead.org; Tue, 09 Jul 2019 13:03:17 +0000 Received: by mail-lf1-x143.google.com with SMTP id s19so12645566lfb.9 for ; Tue, 09 Jul 2019 06:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M3gNxZoQxGFJAS9PytMqlpu7JPyqZG60fnpoWp9WuE8=; b=AqxVgb++cOjQxuDrT3KDN2MxNa+9d4e0zFD7PqIVgSXYh3EM2vf2Zld1R/3kVrgUWd PR9CmxS6xx9LiiBBR5dOH79cRO59Zx58elymnasOktb8pMAZQCbZ6huMF++rAWCH9wPD ENytw9DX4+YKNXzfLQHwfIgVTqnAUFl2XgumCWB0Y+zrMIpGsj70EA6kLOUv+hE5fiKz F+llHLkpVROnMchRgdmlrVPIiMwPODFd47SThU9ol0ddzKP/LSvC5qwrIkYd1vAZykzJ JznszOjGngSko3xcbjzPhfQfvRzR85fwEVG7khFPHLFNztbCfBV356Cq8UY9ttYC+qlJ j+VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M3gNxZoQxGFJAS9PytMqlpu7JPyqZG60fnpoWp9WuE8=; b=Lg2OTxXD3TREez9eQp6ZlGg85q/igxGZsLQ2fNTr/UDvkvS1NMvrS8Q0lDMugrTfFq +s/p5aOAPDvTfZZ8vHECtwWzl9+2pIamOZqJOHeUlL/sLXdCcUbtcLKuG5wLQsIG+Uuq 0xOkflXxONvPzb/3m0M4PBmr4w19OF8VQxUCgfp6itFE0Lc8GhCwVD+qSKyhsx5AYFrl 2FyekSO2YXjBFWxx0jPPrbms8apd7FGew9nXiCGb6+OeSeTq7M3RZkaKVny6BD2NFkJU gp2a2XeqA4+vDIZQNz5pgDRhRRbPz7HUiDb+RYFVftKZRqzfjPmKhNeHwtyvARO3bY7S HuPg== X-Gm-Message-State: APjAAAWlb6rKfy81IkRZJQLna/W0SJpn6qTuwK7qCs64Xh0IWyg2985T 4ROElCXZEdo70lJik+vw0N6ltA== X-Google-Smtp-Source: APXvYqybjmDtzYSZFPPqdCHd6Gn2HeqDSYSy4UiakMcT+/IpOjyWMdXuqTiHvPeHD/pjs24yFWab0Q== X-Received: by 2002:ac2:5212:: with SMTP id a18mr11515725lfl.50.1562677393890; Tue, 09 Jul 2019 06:03:13 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id q4sm4808037lje.99.2019.07.09.06.03.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 09 Jul 2019 06:03:12 -0700 (PDT) From: Linus Walleij To: Russell King Subject: [PATCH 2/2] ARM: boot: Replace open-coded nop with macro Date: Tue, 9 Jul 2019 15:03:01 +0200 Message-Id: <20190709130301.1916-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709130301.1916-1-linus.walleij@linaro.org> References: <20190709130301.1916-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190709_060315_767047_758C11CE X-CRM114-Status: GOOD ( 13.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Linus Walleij , Roy Franz , linux-arm-kernel@lists.infradead.org, Nicolas Pitre Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This open-coded nop as mov r0, r0 is a development history artifact. First commit b11fe38883d1 ("ARM: 6663/1: make Thumb2 kernel entry point more similar to the ARM one") moved the code around so that the nops would come before the conditional thumb instructions, as it turned out that some boot loaders were patching the initial nop instructions in the kernel. At this point it is clear that all mov r0,r0 are open-coded nops. Then commit 81a0bc39ea19 ("ARM: add UEFI stub support") moved things around and defined __nop for EFI support and missed this open-coded nop. commit 06a4b6d009a1 ("ARM: 8677/1: boot/compressed: fix decompressor header layout for v7-M") makes all invocations of __nop be wide, but that is fine, because this is what we want: the mov r0,r0 is inside ifndef CONFIG_THUMB2_KERNEL. Cc: Nicolas Pitre Cc: Roy Franz Cc: Ard Biesheuvel Signed-off-by: Linus Walleij Acked-by: Nicolas Pitre Acked-by: Roy Franz --- arch/arm/boot/compressed/head.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index 544450c90673..93dffed0ac6e 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -169,7 +169,7 @@ start: __nop .endr #ifndef CONFIG_THUMB2_KERNEL - mov r0, r0 + __nop #else AR_CLASS( sub pc, pc, #3 ) @ A/R: switch to Thumb2 mode M_CLASS( nop.w ) @ M: already in Thumb2 mode