From patchwork Tue Apr 9 16:42:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 161986 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp5162684jan; Tue, 9 Apr 2019 09:42:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0OzDv0VSX8Q/qWw9uhFvT6blBsHkR+1r9FeW1mOQNaGQ64F7R5zgNEKpgZ0WnzWBN7OV5 X-Received: by 2002:a65:480c:: with SMTP id h12mr35534499pgs.266.1554828145813; Tue, 09 Apr 2019 09:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554828145; cv=none; d=google.com; s=arc-20160816; b=vZ13eS37yM3xr43CaVNvJAZG36YC8ZpSXv4twZPP3VVOF7apyObPNfgM1T6wOP6s+9 yVp1T03ovKetfYaAIfmUyOlTmqobP2t0PHIstByEJ4IjKhLIym706D4Oi7CcQKxWrxch YZaRotG39Oj1e2izAMHoxMDnOfU8mT5eLtV/diVUcjmXZyuA+vDjhebMPMRjnLxDVrwf zddcAdUYrPm26Xs16b8hWlIEgkwmZ2nQs31Givk9JziwdKee5gZ/RfqhMyFupWHg9m85 HKXiMfblbkieg+uP9cdNYK1fat3Zu552T/H2mDFxeeGad7TAfuBHctQrgGn0oEWuk3XT OEtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Lwv0DS81R3UDGsDpa6oEEiS09+Iy8UYSWPxuCX54ix4=; b=XFAAiD642gUkMW1mHonhbD4g043jNldJz3ulcDuh4AovxRzJJMkl8dhUE5n3kM85Lw saSqnRKyKMKBtoNhRhFVXyW+NGsuC7rtFSafp02T1yRcUmyoul4BiqkkJcVpP7DabV6M 3N7f5PZ7TLvSF7z2iK01BOP4yswcWhxh6vDRAaTlnPoOnGpUhkMQAL+JavGop/iNtcHZ 5fyIEOTbgA8kB85OQBp92tZ2/Kh530d26DUkmqA4wyFczjEO2dPf4BOUzb129AZIR55L JcjF01ROB3o6nQ5HffL2Qa6ZC3Jo456iMc/0HWeZixrKleIUf9R2+r3osVmve4mjyWh2 8ZcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oY1oyE6j; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f14si4067784pgf.519.2019.04.09.09.42.25; Tue, 09 Apr 2019 09:42:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=@linaro.org header.s=google header.b=oY1oyE6j; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726431AbfDIQmZ (ORCPT + 3 others); Tue, 9 Apr 2019 12:42:25 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34454 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726383AbfDIQmZ (ORCPT ); Tue, 9 Apr 2019 12:42:25 -0400 Received: by mail-pl1-f195.google.com with SMTP id y6so9735694plt.1 for ; Tue, 09 Apr 2019 09:42:24 -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; bh=Lwv0DS81R3UDGsDpa6oEEiS09+Iy8UYSWPxuCX54ix4=; b=oY1oyE6jnRUWo5pShSwWr7HP2ZhWyMHmiyWwAujmXbYCDdLS+56Wmifj0wJ7X0isGD EvPajv/pIrjMS90xl3OiqJ7aB7aCzvgdS7M1aXDw62dS+CwaPaWuYv9W9VHmdUYl/Fam /SMONECHNcN65aj75YzaioGlgntom1ER8Ena7QjF12zwrn5gw8ZVVd0EstDH3zC6j9bm hTSXRzhlN12UGFPbRuaDvGkZbyBXiEjQaUEDaLad4B5etDAc0XDwqcT4hKBLNjy98Iq1 BySE6fOUNso9tKGTInHAtv76iEqTEIGwJnkEOi/imUIHurKkEQuzGzC/xZTPokM6KRL1 gFDg== 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; bh=Lwv0DS81R3UDGsDpa6oEEiS09+Iy8UYSWPxuCX54ix4=; b=M/nIzxIRQhmtz9+Vc0PLK2B45qUuM+VuEXfogilA9jHr7RraqhFAWz9AR351F30xhu 3wln5m72Lzie2nHH1iseAFwCyjuRLC1Qf2NCW11OEZteAgGd2oaT59lHJPVGy5+w/jJB jCWVTh5gpjbKd1popOqhtdnF0DmRSsVkmvxF9Ubxq5KpCVEVF9tSrI8AnvPXDR/DM58z C+chWyeYmSaCpVdP0SaRECz1N/AkTt5eBE47dYGXWxKdN2IeAPJIs/5TrKLnLXsQTX7L Nk8Jg/OJJ33Zzhii4EcMcsprr22jgZNslevb+8pjYU2CtT+Tri9KUcLP+9H9T6nTjTYs ZzeQ== X-Gm-Message-State: APjAAAW51dY/Dl5LToDZ7T+FUjEaaqZ14fNuMzMhSTXyzJxMp18C/7C6 ZA3RMVuQiwDiPdthNSsfM968KQ== X-Received: by 2002:a17:902:441:: with SMTP id 59mr8471761ple.242.1554828144068; Tue, 09 Apr 2019 09:42:24 -0700 (PDT) Received: from localhost.localdomain (50-205-23-12-static.hfc.comcastbusiness.net. [50.205.23.12]) by smtp.gmail.com with ESMTPSA id j16sm44455524pfi.58.2019.04.09.09.42.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Apr 2019 09:42:22 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org, linux@armlinux.org.uk, vladimir.murzin@arm.com, marc.zyngier@arm.com, Ard Biesheuvel Subject: [PATCH v2] efi/arm: enable CP15 DMB instructions before cleaning the cache Date: Tue, 9 Apr 2019 09:42:20 -0700 Message-Id: <20190409164220.5993-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The EFI stub is entered with the caches and MMU enabled by the firmware, and once the stub is ready to hand over to the decompressor, we clean and disable the caches. The cache clean routines use CP15 barrier instructions, which can be disabled via SCTLR. Normally, when using the provided cache handling routines to enable the caches and MMU, this bit is enabled as well. However, but since we entered the stub with the caches already enabled, this routine is not executed before we call the cache clean routines, resulting in undefined instruction exceptions if the firmware never enabled this bit. So set the bit explicitly in the EFI entry code, but do so in a way that guarantees that the resulting code can still run on v6 cores as well (which are guaranteed to have CP15 barriers enabled) Acked-by: Marc Zyngier Signed-off-by: Ard Biesheuvel --- arch/arm/boot/compressed/head.S | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index 6c7ccb428c07..c174098acdf1 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -1438,7 +1438,21 @@ ENTRY(efi_stub_entry) @ Preserve return value of efi_entry() in r4 mov r4, r0 - bl cache_clean_flush + + @ our cache maintenance code relies on CP15 barrier instructions + @ but since we arrived here with the MMU and caches configured + @ by UEFI, we must check that the CP15BEN bit is set in SCTLR. + @ Note that this bit is RAO/WI on v6 and earlier, so the ISB in + @ the enable path will be executed on v7+ only. + mrc p15, 0, r1, c1, c0, 0 @ read SCTLR + tst r1, #(1 << 5) @ CP15BEN bit set? + bne 0f + orr r1, r1, #(1 << 5) @ CP15 barrier instructions + mcr p15, 0, r1, c1, c0, 0 @ write SCTLR + ARM( .inst 0xf57ff06f @ isb ) + THUMB( isb ) + +0: bl cache_clean_flush bl cache_off @ Set parameters for booting zImage according to boot protocol