From patchwork Thu Aug 6 08:26:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 11703185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54748722 for ; Thu, 6 Aug 2020 12:19:27 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3C85A22D2C for ; Thu, 6 Aug 2020 12:19:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="h7nG7Uk6"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DsfFnKRU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C85A22D2C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id: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=yVRtuUyHZc84E76fHlI2l1JKxFLL+WJ+zJ4WXIkIU4g=; b=h7nG7Uk603I1VihuWW+7Rn+Orf eDyOIbP+J2cddNAVW+fc7RTcwTqPqpz2IWIu6MMiEWuOKAkJamkm/HFPnCovZldSrNiuhlEiobCJN 2XI6USNv7NvmGhJbfuc3yyvgJq1UO/2Vm1/+pPK+Ii4Z6iqQLSZn06KMGhbGGAfDByIzn9VH9DGoX nu7Q83rXN3tTfk462OnQbK72mr85MJhoRTwqSrmuzmHEXaCJ4bqHItgNFvJRTCBGlya5wAGxw6hDm DWDmS9vvmB1gQgmplRuHrmDIP0RMN+/QeGuHxzmmGz8/vSc+enQhGQ/D1StnkRetdhmMchw/UL6lw LXVIdj8Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3bEa-0001tx-IL; Thu, 06 Aug 2020 08:26:44 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3bEX-0001tD-BD for linux-arm-kernel@lists.infradead.org; Thu, 06 Aug 2020 08:26:42 +0000 Received: by mail-pg1-x542.google.com with SMTP id j21so7566566pgi.9 for ; Thu, 06 Aug 2020 01:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=GGXq1czQBgi3vSjfSlP7TeDNtnDs2EF5G5Swa288KpQ=; b=DsfFnKRUs7w+J9oTfujUmmT7MdglvNGio0VAnUNK0s7jb057CJdSlPj3YPulzLWQ59 pmapbQ2LjjdXpQ4tYzq6mHLWRHOod+LD3qDHmI5FAXiZq3Klgn8hp3BCbKblCbhujUkO OQMQPiLEp+HL7QqlMsSAFNcn4hFshHCczUA/1BCQz3NgIZEbrrtyKMqQEqZemjwKA+Oe baNYHbLkhgFWAXQ3AbhumiPH9Es+q8Zk6dvLQu+QQMA+gSm9kH+de11omXbZwynAD1gm ZicA/DseKLO6yFwOK2sEJC5tQAYY1hRT00nkvugBtCYg9af+Yj3S4hSZLOYv1zFgug6r XX7g== 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=GGXq1czQBgi3vSjfSlP7TeDNtnDs2EF5G5Swa288KpQ=; b=DR7GmCXQIUdsBPlj7VbzrLsLOHVqCm4eUTeit3Z93a0NMRCDcHOmUIBzmxSusZ1F7V QXAWMKhjd+uwqxjUPJViFsUVTf2oVFBTn5Z/xi1A+yJICcNElBcG28VuEmpxUl9HkCtB G5pMaD+bzyNT7syNMEWOil6GC/Pz50Yh9qTpvB0z7UWemchIarfeliXGqKPKlbXcRxNt PDxOKhXrhr/NgbWyl8CL7LJJ90TDAAY6Wjz9vuWtE/Mrc33imdNNRNlPk6NWP2a2pfMV Zb4aKTn1OoSFU7CVUHS/WDytGKGNzk12xrT2OmF3zs1XCp5FMReodpB5XOHoGRsnQxYI 9KCw== X-Gm-Message-State: AOAM531x2QhbfcR/L+AjVA9LoY7II7IH2mfmKykULuVcW2RLzGiWAINw oRl1fS+yqViwg+sYphWkXaoxDrE= X-Google-Smtp-Source: ABdhPJz5JdmpHTCzHXK3bwD7iZu9Ae10Aw8Ik8D6Io4uyTaWqHjtcPbKJlA4+I1+Cf3VB1/TYKKP+g== X-Received: by 2002:aa7:8182:: with SMTP id g2mr6906930pfi.261.1596702398382; Thu, 06 Aug 2020 01:26:38 -0700 (PDT) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y19sm6810986pfn.77.2020.08.06.01.26.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Aug 2020 01:26:36 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm64/relocate_kernel: remove redundant but misleading code Date: Thu, 6 Aug 2020 16:26:18 +0800 Message-Id: <1596702378-29550-1-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200806_042641_402304_CA9ED51D X-CRM114-Status: GOOD ( 12.89 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:542 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [kernelfans[at]gmail.com] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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: Mark Rutland , Kees Cook , Geoff Levand , Catalin Marinas , Pingfan Liu , Mark Brown , Remi Denis-Courmont , Will Deacon , Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The kexec switch sequence looks like the following: SYM_CODE_START(__cpu_soft_restart) ... pre_disable_mmu_workaround msr sctlr_el1, x12 ... br x8 SYM_CODE_START(arm64_relocate_new_kernel) ... pre_disable_mmu_workaround msr sctlr_el2, x0 ... "msr sctlr_el2, x0" is misleading, because "br x8" jump to a physical address, which has no entry in idmap. It implies that MMU has already been fully off after "msr sctlr_el1, x12". And according to "D12.2.101 SCTLR_EL2, System Control Register (EL2)" in "ARM Architecture Reference Manual", actually, EL2&0 host accesses to SCTLR_EL2 when using mnemonic SCTLR_EL1. Hence removing the redundant but misleading code. Signed-off-by: Pingfan Liu Cc: Geoff Levand Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Mark Brown Cc: Kees Cook Cc: Remi Denis-Courmont Cc: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org --- arch/arm64/kernel/cpu-reset.S | 4 ++++ arch/arm64/kernel/relocate_kernel.S | 12 ------------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S index 4a18055..37721eb 100644 --- a/arch/arm64/kernel/cpu-reset.S +++ b/arch/arm64/kernel/cpu-reset.S @@ -35,6 +35,10 @@ SYM_CODE_START(__cpu_soft_restart) mov_q x13, SCTLR_ELx_FLAGS bic x12, x12, x13 pre_disable_mmu_workaround + /* + * either disable EL1&0 translation regime or disable EL2&0 translation + * regime if HCR_EL2.E2H == 1 + */ msr sctlr_el1, x12 isb diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index 542d6ed..84eec95 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -36,18 +36,6 @@ SYM_CODE_START(arm64_relocate_new_kernel) mov x14, xzr /* x14 = entry ptr */ mov x13, xzr /* x13 = copy dest */ - /* Clear the sctlr_el2 flags. */ - mrs x0, CurrentEL - cmp x0, #CurrentEL_EL2 - b.ne 1f - mrs x0, sctlr_el2 - mov_q x1, SCTLR_ELx_FLAGS - bic x0, x0, x1 - pre_disable_mmu_workaround - msr sctlr_el2, x0 - isb -1: - /* Check if the new image needs relocation. */ tbnz x16, IND_DONE_BIT, .Ldone