From patchwork Fri Aug 28 13:39:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 11742847 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 91F2B739 for ; Fri, 28 Aug 2020 13:42:16 +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 6B60D207DF for ; Fri, 28 Aug 2020 13:42:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WjCj7rM3"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c6+iYFm3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B60D207DF 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=X+cPLF/LiIfXKmTwKyPqLf2YCHxEm1JDpgTDzMoYcLA=; b=WjCj7rM3AhKBeWpjwTdy3oTi36 s4BS5zqY0YwnFt+BBFK38gO282j5wUWW/WKAR7yql72jNffcqZKC3XA3VFi+McvHnnjh5bjRinz65 lu26FOJivIw6Wl2LWbyyC9wkJfEH+4YlyMYLY+T42rtKkoMGeufVVUZ1sFDCFUqQ4G9FcG9mPgsPq mxzwxBuw1Duw5eH/tJaI6kXoguHa1mn/KdDK/qjgnKr0cBe8/Vk1GMXNGGBem+mpCG6NGCPCz17PE Hk3O069++fPR4RUigKyC1lvaBX4OBdubNPwlt9C9ZADK2gYyfQsrBjameJesf/F6e/+MEJhpQ4vbK Yz+UL6Dg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBec9-0000EJ-Un; Fri, 28 Aug 2020 13:40:21 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBec7-0000DZ-9j for linux-arm-kernel@lists.infradead.org; Fri, 28 Aug 2020 13:40:20 +0000 Received: by mail-pf1-x443.google.com with SMTP id o68so693311pfg.2 for ; Fri, 28 Aug 2020 06:40:18 -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=mgrYv7djjcwPKBcwSuPRa9gDCJlsOXVcLbni56sIc20=; b=c6+iYFm39iM5ehnXHgohQOtvPP4Actfi+8FwijsEJLKpNxIw+zaMTTRVW5QuiVMSyK +uHvjVMeImm8j1nkGFFvBhdeq+mW57UR0mDt+TMCi9o1VA33Bazp32lsPKVyzGtFRgvU obaOn8bzO3sK6syphhgOp58IARzEs3BuHEOFKzvUJAiqUP1hzu9/W/LVB3XtKuVQRAmj SiSzWpgz0qVL4WxIFzNdUcaHUpYVzd5lp54gbDLZYbhovS7Bw9bEMWgT7xuWksJGMlTZ Om/ECbEvIuuQT/FFgjmIprCoeVjXm42xu3A44N/doEYtETaYrh66S2KBE98cOd48GXJu Dbtg== 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=mgrYv7djjcwPKBcwSuPRa9gDCJlsOXVcLbni56sIc20=; b=Lun1+BfSp197p+2WjJUbgM3x7fjYJ7b4Y986DHq7H0VkPHl8YcpiaoIh9vDhRGD9GX Cn0IUQ9CExolcCiH25uPm5TcroHvjvByr8VCwHcSSa6dFq1jR+NMcJ2O23fwqxsg1q8R Qn2qg5K/hZMXh4JUx/7FsWcuSwxOpYxNzrbpG9fuduaKSrc+FcXjoBbNULOrL4Q4pj1H JUvUVi/fZPujkIHFaER1DvfmWSiXCviO226YE5SzHUw7X3VfsFcdWaaMCnHJVjai3qn9 K2aZ0r18rNNnDcyyWaq4wQoXP7yiNZ9Sr7xKBh79/x8m9CcS4gB3rcdyfFyBnh3ACT4c H83A== X-Gm-Message-State: AOAM530eNiMgyQVY+YcV0WwGUYb2Rtlg4WUJR/fYsEaZ0mWMnjfbxRAE 6x6tlYxCrLqsDhTH4MYALPblK9ervw== X-Google-Smtp-Source: ABdhPJwZ8ssnw7ayyRREkP1u9OCgsSNGyNfGZJQAc104tTnsMqU4PSmyX9pjBVp3Bj3pBJbEhvD1Kg== X-Received: by 2002:a63:1d07:: with SMTP id d7mr1349038pgd.106.1598622016873; Fri, 28 Aug 2020 06:40:16 -0700 (PDT) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k1sm1806559pfp.86.2020.08.28.06.40.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Aug 2020 06:40:16 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Subject: [PATCHv2 1/2] arm64/relocate_kernel: remove redundant code Date: Fri, 28 Aug 2020 21:39:57 +0800 Message-Id: <1598621998-20563-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-20200828_094019_354520_37901934 X-CRM114-Status: GOOD ( 14.82 ) 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:443 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [kernelfans[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 , Remi Denis-Courmont , Pingfan Liu , kvmarm@lists.cs.columbia.edu, Mark Brown , James Morse , Marc Zyngier , 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 Kernel startup entry point requires disabling MMU and D-cache. As for kexec-reboot, taking a close look at "msr sctlr_el1, x12" in __cpu_soft_restart as the following: -1. booted at EL1 The instruction is enough to disable MMU and I/D cache for EL1 regime. -2. booted at EL2, using VHE Access to SCTLR_EL1 is redirected to SCTLR_EL2 in EL2. So the instruction is enough to disable MMU and clear I+C bits for EL2 regime. -3. booted at EL2, not using VHE The instruction itself can not affect EL2 regime. But The hyp-stub doesn't enable the MMU and I/D cache for EL2 regime. And KVM also disable them for EL2 regime when its unloaded, or execute a HVC_SOFT_RESTART call. So when kexec-reboot, the code in KVM has prepare the requirement. As a conclusion, disabling MMU and clearing I+C bits in SYM_CODE_START(arm64_relocate_new_kernel) is redundant, and can be removed Signed-off-by: Pingfan Liu Cc: James Morse Cc: Geoff Levand Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Marc Zyngier Cc: Mark Brown Cc: Kees Cook Cc: Remi Denis-Courmont Cc: Ard Biesheuvel Cc: kvmarm@lists.cs.columbia.edu 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