From patchwork Thu Oct 25 14:13:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 149532 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1395815ljp; Thu, 25 Oct 2018 07:15:24 -0700 (PDT) X-Google-Smtp-Source: AJdET5eyNT3TFbA7qJLDI+35aYRm3mh2QUNNwx6sLi05h4/T9Wvj8QMPurccxNNCG1+Eig10Jy6O X-Received: by 2002:a17:902:765:: with SMTP id 92-v6mr1686985pli.263.1540476924480; Thu, 25 Oct 2018 07:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540476924; cv=none; d=google.com; s=arc-20160816; b=lGsZO4bKtUvt64cAsFerV/nGaLwm1RJCuC5ec9EOW5Q77CCljQ8Ew4gjIY6ZeyFTjd H8rPjnsIMqsyRA/V6dIWTwxI8pP2/YT6HfZ3yB2C5RKtWObH6cueKGP9q2VnPEC4Fr7R 1W6zpS3jjPmXoX7H3Ny5YXHIUx2zn0wyfiiHecLGZd4jKyyyqeWpPCWLsaWZE+Aw1LQL cTVx+Bt7WnHJC9+XrNZfSxTwoXx1pgi1NdrpG4V9nfZJPlu3K0yh+u90t6iNss4JSXHm Zc8EqHCy/WealyC45N4Oxa4iy8tU27xD0IqnaOteI01asUtn5PkKYIXHRceXiVZje/cu ULRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=fO7IaPWY7KjqFO0GNszcqLmwkiEVdsei56o7k0xnWhI=; b=hqm8AYD9QR9zt6lzVAjgwe3LSC2Ntu/hmRwX41Y1U+xD66rRijrZ0eLYU7eFiCrMyq PvDAUP2ZNQaolj41x22dGhuX9YlG+xXaR0cU+qQ1zmVCbLseX5agsM9DNOyMSdADBDb5 bGT7720YqTSnLXF+U+6Oq+EMaWIe+g5dXlZj2KXb4yV2nPuSqhm7D3T4V/vdfhODr+Y4 6E6eaMqZlrvUoySjM83Hci53npMMxrJB61ChxE3HKPH15gzAEqnJrE1lLurVdbCKLFEm 0g4umehiPoHLXtGSNPkTO8XhF1pNY68Isr2PadkK8h5GmAlrVncqQL3tQdQv/vlbRC/Z /58w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=es0ZK75X; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id p79-v6si8270497pfj.244.2018.10.25.07.15.23; Thu, 25 Oct 2018 07:15:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=es0ZK75X; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728918AbeJYWsS (ORCPT + 32 others); Thu, 25 Oct 2018 18:48:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:56832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728907AbeJYWsQ (ORCPT ); Thu, 25 Oct 2018 18:48:16 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D43032085A; Thu, 25 Oct 2018 14:15:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540476919; bh=CIBOZAugqCEte1nJc7quNpkpOjQXgdyjfJLJNtl9xhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=es0ZK75X5ZwMvu+aG+fdYUfwxS3pXa4rMa4PawUBPFxihp/3V2JYSDJ5c+I69YdWz Fdk3tpXdJ5nDp8ci1MSOA0BhnZG9SE9IOay5CQhTI0/oOTL99vm8ZQ1UYKqRl5umxR BjC1MpXCTubHhDpgjeeGdy0AAEfdbVFdK0PCs8B8= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Russell King , Sasha Levin Subject: [PATCH AUTOSEL 4.9 37/98] ARM: 8677/1: boot/compressed: fix decompressor header layout for v7-M Date: Thu, 25 Oct 2018 10:13:22 -0400 Message-Id: <20181025141423.213774-37-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141423.213774-1-sashal@kernel.org> References: <20181025141423.213774-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel [ Upstream commit 06a4b6d009a1b74a6ec46c5418b46cc53a79fcb8 ] As reported by Patrice, the header layout of the decompressor is incorrect when building for v7-M. In this case, the __nop macro resolves to 'mov r0, r0', which is emitted as a narrow encoding, resulting in the header data fields to end up at lower offsets than required. Given the variety of targets we need to support with the same code, the startup sequence is a bit of a jumble, and uses instructions and macros whose encoding widths cannot be specified (badr), or only exist in a narrow encoding (bx) So force the use of a wide encoding in __nop, and replace the start sequence with a simple jump to the label marking the start of code, preceded by a Thumb2 mode switch if required (using explicit wide encodings where appropriate). The label itself can be moved to the start of code [where it belongs] due to the larger range of branch instructions as compared to adr instructions. Reported-by: Patrice CHOTARD Acked-by: Nicolas Pitre Signed-off-by: Ard Biesheuvel Signed-off-by: Russell King Signed-off-by: Sasha Levin --- arch/arm/boot/compressed/efi-header.S | 4 +--- arch/arm/boot/compressed/head.S | 17 ++++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) -- 2.17.1 diff --git a/arch/arm/boot/compressed/efi-header.S b/arch/arm/boot/compressed/efi-header.S index 9d5dc4fda3c1..3f7d1b74c5e0 100644 --- a/arch/arm/boot/compressed/efi-header.S +++ b/arch/arm/boot/compressed/efi-header.S @@ -17,14 +17,12 @@ @ there. .inst 'M' | ('Z' << 8) | (0x1310 << 16) @ tstne r0, #0x4d000 #else - mov r0, r0 + W(mov) r0, r0 #endif .endm .macro __EFI_HEADER #ifdef CONFIG_EFI_STUB - b __efi_start - .set start_offset, __efi_start - start .org start + 0x3c @ diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index fc6d541549a2..2d7f2bb0d66a 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -130,19 +130,22 @@ start: .rept 7 __nop .endr - ARM( mov r0, r0 ) - ARM( b 1f ) - THUMB( badr r12, 1f ) - THUMB( bx r12 ) +#ifndef CONFIG_THUMB2_KERNEL + mov r0, r0 +#else + AR_CLASS( sub pc, pc, #3 ) @ A/R: switch to Thumb2 mode + M_CLASS( nop.w ) @ M: already in Thumb2 mode + .thumb +#endif + W(b) 1f .word _magic_sig @ Magic numbers to help the loader .word _magic_start @ absolute load/run zImage address .word _magic_end @ zImage end address .word 0x04030201 @ endianness flag - THUMB( .thumb ) -1: __EFI_HEADER - + __EFI_HEADER +1: ARM_BE8( setend be ) @ go BE8 if compiled for BE8 AR_CLASS( mrs r9, cpsr ) #ifdef CONFIG_ARM_VIRT_EXT