Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66E2CC433E1 for ; Tue, 25 Aug 2020 17:57:34 +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 3937C20782 for ; Tue, 25 Aug 2020 17:57:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uzmJpilw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3937C20782 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.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:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8jyVDxVHJMOSx0jydTICGgn65jOeXJ1M1qEoA9iYivc=; b=uzmJpilwA2of78ShIZljZ471Y /R5+UXIO9y8sdD5OoK/a/5DQGgvd/Hq7IQpFI89ez/XPZu2p3zK+vkf+h501F81wlSRJEJERlc55C iq+dnJoivjj+zcnV/JBfSmgA7Y7A6+lWALMNx7JafOhPsnKl6PJjCvNfVHupcJiZsVmzte7n6W3jF 5WMcU6HQv0bP09UzfSgowCnP8YFLKL505nN0YwPU6WlUDmONwDs1eqguPVc45L3g3K/OKbRJUgFEv a+q3l9v1CzVVBKEXuc1PlfBvttWtG7N+O0f943/REZI+eQqAHvs8H/cOKqIJ6YWq1LlP4YqZ9yCkL eLjONFcVQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAdBB-00044e-9q; Tue, 25 Aug 2020 17:56:17 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAdB8-00043u-Gf for linux-arm-kernel@lists.infradead.org; Tue, 25 Aug 2020 17:56:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 36D86101E; Tue, 25 Aug 2020 10:56:13 -0700 (PDT) Received: from [172.16.1.113] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BC4083F66B; Tue, 25 Aug 2020 10:56:11 -0700 (PDT) Subject: Re: [PATCH] arm64/relocate_kernel: remove redundant but misleading code To: Pingfan Liu References: <1596702378-29550-1-git-send-email-kernelfans@gmail.com> <9b0da257-785b-90ba-de3c-b9ee9ccdeeba@arm.com> From: James Morse Message-ID: <8c17568d-3182-4cd4-1395-d8026ea63e54@arm.com> Date: Tue, 25 Aug 2020 18:56:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200825_135614_694626_F3896BA8 X-CRM114-Status: GOOD ( 25.56 ) 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 , Mark Brown , Remi Denis-Courmont , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Pingfan, On 12/08/2020 15:21, Pingfan Liu wrote: > I have read the arm64/kvm code, and been more clear about it now. > > What do you think about the following commit log (just describe the fact) > > arm64/relocate_kernel: remove redundant code > > The kexec switch sequence looks like the following: > SYM_CODE_START(__cpu_soft_restart) > /* Clear sctlr_el1 flags. */ > mrs x12, sctlr_el1 > mov_q x13, SCTLR_ELx_FLAGS > bic x12, x12, x13 > pre_disable_mmu_workaround > msr sctlr_el1, x12 > isb > > cbz x0, 1f // el2_switch? > mov x0, #HVC_SOFT_RESTART > hvc #0 // no return > > 1: mov x8, x1 // entry > mov x0, x2 // arg0 > mov x1, x3 // arg1 > mov x2, x4 // arg2 > br x8 > SYM_CODE_END(__cpu_soft_restart) I think this is far to much to put in the commit message! It should be a summary. We can always checkout the whole tree at the point the commit was made to look at functions like this, we don't need to preserve them in the commit log. > SYM_CODE_START(arm64_relocate_new_kernel) > ... > pre_disable_mmu_workaround > msr sctlr_el2, x0 > ... > > As for the shutdown of MMU and clearing of I+C bits, three cases should be > considered: > -1. Guest I don't think host/guest matter here. This one is really 'booted at EL1'. > "msr sctlr_el1, x12" is enough to turn off EL1&0 translation regime and > clear I+C bits. > -2. EL2&0 host (Booted at EL2, using VHE) > 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. > So "msr sctlr_el1, x12" is enough to turn off MMU and clear I+C bits. > -3. EL1&0 host, (Booted at EL2, not using VHE) > "msr sctlr_el1, x12" turns off EL1&0 translation regime. > As for EL2 regime, el2_setup doesn't turn on EL2 regime A regime isn't something you turn on, I think this should just be 'The hyp-stub doesn't enable the MMU, see el2_setup.' digression { If you think about the EL1&0 regime when stage2 is enabled, is the regime only 'on' when the stage1 MMU is enabled? Not really, when the stage1 MMU is disabled it outputs VA==IPA, and the stage2 MMU translates this to PA. The whole thing belongs to the translation EL1&0 regime. } > and set those bits , and KVM clears > them when it's unloaded, or has a HVC_SOFT_RESTART call. > > As a conclusion, the shutdown of MMU and clearing I+C bits in > SYM_CODE_START(arm64_relocate_new_kernel) is redundant. This certainly covers all the cases. As kexec is now depending on this behaviour of KVM, how do you feel about updating the document at Documentation/virt/kvm/arm/hyp-abi.rst ? I think all it needs is a "Clear the I+C bits (arm64 only)" under HVC_SOFT_RESTART. Thanks, James _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel