From mboxrd@z Thu Jan 1 00:00:00 1970 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=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 98EF5C4708F for ; Tue, 1 Jun 2021 12:38:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3306F60FE5 for ; Tue, 1 Jun 2021 12:38:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3306F60FE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A374F6B009E; Tue, 1 Jun 2021 08:38:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C0C76B00B0; Tue, 1 Jun 2021 08:38:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 813896B00B9; Tue, 1 Jun 2021 08:38:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 4DD606B009E for ; Tue, 1 Jun 2021 08:38:22 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E4AC68790 for ; Tue, 1 Jun 2021 12:38:21 +0000 (UTC) X-FDA: 78205108002.03.FE5E8D2 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf18.hostedemail.com (Postfix) with ESMTP id 37F2F20010A2 for ; Tue, 1 Jun 2021 12:38:10 +0000 (UTC) Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A96A661396; Tue, 1 Jun 2021 12:38:20 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1lo3f0-004oZq-Hk; Tue, 01 Jun 2021 13:38:18 +0100 Date: Tue, 01 Jun 2021 13:38:17 +0100 Message-ID: <87pmx52212.wl-maz@kernel.org> From: Marc Zyngier To: Pavel Tatashin Cc: jmorris@namei.org, sashal@kernel.org, ebiederm@xmission.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, corbet@lwn.net, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, vladimir.murzin@arm.com, matthias.bgg@gmail.com, linux-mm@kvack.org, mark.rutland@arm.com, steve.capper@arm.com, rfontana@redhat.com, tglx@linutronix.de, selindag@gmail.com, tyhicks@linux.microsoft.com, kernelfans@gmail.com, akpm@linux-foundation.org, madvenka@linux.microsoft.com Subject: Re: [PATCH 04/18] arm64: kernel: add helper for booted at EL2 and not VHE In-Reply-To: <20210527150526.271941-5-pasha.tatashin@soleen.com> References: <20210527150526.271941-1-pasha.tatashin@soleen.com> <20210527150526.271941-5-pasha.tatashin@soleen.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: pasha.tatashin@soleen.com, jmorris@namei.org, sashal@kernel.org, ebiederm@xmission.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, corbet@lwn.net, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, vladimir.murzin@arm.com, matthias.bgg@gmail.com, linux-mm@kvack.org, mark.rutland@arm.com, steve.capper@arm.com, rfontana@redhat.com, tglx@linutronix.de, selindag@gmail.com, tyhicks@linux.microsoft.com, kernelfans@gmail.com, akpm@linux-foundation.org, madvenka@linux.microsoft.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Rspamd-Queue-Id: 37F2F20010A2 Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of maz@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=maz@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam03 X-Stat-Signature: out776s5678xcuchpy6kez1on5tqdxqr X-HE-Tag: 1622551090-487232 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, 27 May 2021 16:05:12 +0100, Pavel Tatashin wrote: > > Replace places that contain logic like this: > is_hyp_mode_available() && !is_kernel_in_hyp_mode() > > With a dedicated boolean function is_hyp_callable(). This will be needed > later in kexec in order to sooner switch back to EL2. This looks like the very definition of "run in nVHE mode", so I'd rather you call it like this, rather than "callable", which is extremely ambiguous (if running at EL2, I call it any time I want, for free). > > Suggested-by: James Morse > > [Fixed merging issues] > > Signed-off-by: Pavel Tatashin > --- > arch/arm64/include/asm/virt.h | 5 +++++ > arch/arm64/kernel/cpu-reset.h | 3 +-- > arch/arm64/kernel/hibernate.c | 9 +++------ > arch/arm64/kernel/sdei.c | 2 +- > 4 files changed, 10 insertions(+), 9 deletions(-) > > diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h > index 7379f35ae2c6..4216c8623538 100644 > --- a/arch/arm64/include/asm/virt.h > +++ b/arch/arm64/include/asm/virt.h > @@ -128,6 +128,11 @@ static __always_inline bool is_protected_kvm_enabled(void) > return cpus_have_final_cap(ARM64_KVM_PROTECTED_MODE); > } > > +static inline bool is_hyp_callable(void) > +{ > + return is_hyp_mode_available() && !is_kernel_in_hyp_mode(); > +} nit: consider switching the two members of the expression so that you don't have extra memory accesses when running at EL2. > + > #endif /* __ASSEMBLY__ */ > > #endif /* ! __ASM__VIRT_H */ > diff --git a/arch/arm64/kernel/cpu-reset.h b/arch/arm64/kernel/cpu-reset.h > index 9a7b1262ef17..48d0ed48c147 100644 > --- a/arch/arm64/kernel/cpu-reset.h > +++ b/arch/arm64/kernel/cpu-reset.h > @@ -20,8 +20,7 @@ static inline void __noreturn __nocfi cpu_soft_restart(unsigned long entry, > { > typeof(__cpu_soft_restart) *restart; > > - unsigned long el2_switch = !is_kernel_in_hyp_mode() && > - is_hyp_mode_available(); > + unsigned long el2_switch = is_hyp_callable(); > restart = (void *)__pa_symbol(function_nocfi(__cpu_soft_restart)); > > cpu_install_idmap(); > diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c > index b1cef371df2b..c764574a1acb 100644 > --- a/arch/arm64/kernel/hibernate.c > +++ b/arch/arm64/kernel/hibernate.c > @@ -48,9 +48,6 @@ > */ > extern int in_suspend; > > -/* Do we need to reset el2? */ > -#define el2_reset_needed() (is_hyp_mode_available() && !is_kernel_in_hyp_mode()) > - Please keep the macro, as it explains *why* we're doing things (we need to reset EL2), and replacing it with a generic macro drops the documentation aspect. > /* temporary el2 vectors in the __hibernate_exit_text section. */ > extern char hibernate_el2_vectors[]; > > @@ -125,7 +122,7 @@ int arch_hibernation_header_save(void *addr, unsigned int max_size) > hdr->reenter_kernel = _cpu_resume; > > /* We can't use __hyp_get_vectors() because kvm may still be loaded */ > - if (el2_reset_needed()) > + if (is_hyp_callable()) > hdr->__hyp_stub_vectors = __pa_symbol(__hyp_stub_vectors); > else > hdr->__hyp_stub_vectors = 0; > @@ -387,7 +384,7 @@ int swsusp_arch_suspend(void) > dcache_clean_range(__idmap_text_start, __idmap_text_end); > > /* Clean kvm setup code to PoC? */ > - if (el2_reset_needed()) { > + if (is_hyp_callable()) { > dcache_clean_range(__hyp_idmap_text_start, __hyp_idmap_text_end); > dcache_clean_range(__hyp_text_start, __hyp_text_end); > } > @@ -482,7 +479,7 @@ int swsusp_arch_resume(void) > * > * We can skip this step if we booted at EL1, or are running with VHE. > */ > - if (el2_reset_needed()) { > + if (is_hyp_callable()) { > phys_addr_t el2_vectors = (phys_addr_t)hibernate_exit; > el2_vectors += hibernate_el2_vectors - > __hibernate_exit_text_start; /* offset */ > diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c > index 2c7ca449dd51..af0ac2f920cf 100644 > --- a/arch/arm64/kernel/sdei.c > +++ b/arch/arm64/kernel/sdei.c > @@ -200,7 +200,7 @@ unsigned long sdei_arch_get_entry_point(int conduit) > * dropped to EL1 because we don't support VHE, then we can't support > * SDEI. > */ > - if (is_hyp_mode_available() && !is_kernel_in_hyp_mode()) { > + if (is_hyp_callable()) { > pr_err("Not supported on this hardware/boot configuration\n"); > goto out_err; > } > -- > 2.25.1 > > Thanks, M. -- Without deviation from the norm, progress is not possible.