From patchwork Thu Sep 16 23:13:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12500455 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 06D4AC4332F for ; Thu, 16 Sep 2021 23:13:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8021960F58 for ; Thu, 16 Sep 2021 23:13:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8021960F58 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 244CF6B0071; Thu, 16 Sep 2021 19:13:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1313A940007; Thu, 16 Sep 2021 19:13:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC6CB6B0073; Thu, 16 Sep 2021 19:13:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id DA2546B0071 for ; Thu, 16 Sep 2021 19:13:30 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9B39C348B3 for ; Thu, 16 Sep 2021 23:13:30 +0000 (UTC) X-FDA: 78594990180.32.A6771FE Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by imf12.hostedemail.com (Postfix) with ESMTP id 5667A10000B4 for ; Thu, 16 Sep 2021 23:13:30 +0000 (UTC) Received: by mail-qv1-f49.google.com with SMTP id a13so5289881qvo.9 for ; Thu, 16 Sep 2021 16:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=izAVFpEvWmgGrg5dDdCTfojtmVMYt432wfvBnpESnjE=; b=GAeeTsTiMWgZ/mrEbLarF+Ykm+dqSe+pmGVZ0WDN8xE7kyy69Iebgu6cvmgXJVOXLm OGd58KGOD9rxyk1SsSDQJgtTAkcl6mqQQwubDE/olaD+l/gSVM2Wnvx6NobhbR5cGsCl CUv0H3cFXUKMbB3hSV4cpYfzViaySxUwAJhOlc61BhZYlJgBhcEqcGJ7KUf2Eq20YCH7 ui60w/IyJvPR7AEBxxUAqRAzMaJ5cTHKnGzHeP37FdyFBv9Q21yICC48ly/GiELsytCC jRkHtnnUDubxibZXVu3V6xMFzbfqa/xPs4N0smZdPjhJcrI83zk4WG7Kfskl7omyw6/M FJIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=izAVFpEvWmgGrg5dDdCTfojtmVMYt432wfvBnpESnjE=; b=AZukQ6QByASJxzsDfZDHvuqz9HmCwfLIrvNvG5w560tUl3A/C+bnCyyvqwSr4nl+l+ qBsP3S9LszPQvLUcpiHujIrY4Oz27hb6+2payVi5qvuXqySdaxsKO/hbIo6GaC9IZdP4 SXyYcUSVYFUtHiLW57JgAwNceBWM0VuAPmkpb8n8LxNGje8vQX3TSlfy3jGY7KANyPn9 a9UMPGnqCT/20076CVIko/pnAEX7QungO/4nHwkFS9ddaKkm3JRqdNHOKnchaSLDMcby B0Tc4K3Y9TWIkyPP/oezCpJgFFxAj5LPFIQv9ZobA5kM+UKrY8q6bFaidP3hAe1uHFyk h64A== X-Gm-Message-State: AOAM530vncAghkHdQKCt/Vyv8HRavwwFMRdUuRibGxMW1IWvFuBlQK1s oGxkJfpFV2WfqSWheq6bj2VizA== X-Google-Smtp-Source: ABdhPJxDA+gY3OZD9CV/MvCWYphxLHZFgApqCPwPjnAgRNs7iMjwV+PWgCoWyHRjGBLVUarVMeiG2A== X-Received: by 2002:ad4:466a:: with SMTP id z10mr8048091qvv.7.1631834009592; Thu, 16 Sep 2021 16:13:29 -0700 (PDT) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id az6sm3312891qkb.70.2021.09.16.16.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 16:13:29 -0700 (PDT) From: Pasha Tatashin 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, maz@kernel.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: [PATCH v17 01/15] arm64: kernel: add helper for booted at EL2 and not VHE Date: Thu, 16 Sep 2021 19:13:11 -0400 Message-Id: <20210916231325.125533-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210916231325.125533-1-pasha.tatashin@soleen.com> References: <20210916231325.125533-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=GAeeTsTi; spf=pass (imf12.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.49 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5667A10000B4 X-Stat-Signature: m81q7d3qb715a5c4g47zy5i3r5mmjg3m X-HE-Tag: 1631834010-531844 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: Replace places that contain logic like this: is_hyp_mode_available() && !is_kernel_in_hyp_mode() With a dedicated boolean function is_hyp_nvhe(). This will be needed later in kexec in order to sooner switch back to EL2. Suggested-by: James Morse Signed-off-by: Pasha Tatashin --- arch/arm64/include/asm/virt.h | 5 +++++ arch/arm64/kernel/cpu-reset.h | 3 +-- arch/arm64/kernel/hibernate.c | 2 +- arch/arm64/kernel/sdei.c | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index 7379f35ae2c6..a9457e96203c 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_nvhe(void) +{ + return is_hyp_mode_available() && !is_kernel_in_hyp_mode(); +} + #endif /* __ASSEMBLY__ */ #endif /* ! __ASM__VIRT_H */ diff --git a/arch/arm64/kernel/cpu-reset.h b/arch/arm64/kernel/cpu-reset.h index 9a7b1262ef17..81b3d0fe7a63 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_nvhe(); 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 46a0b4d6e251..4c9533f4c0c4 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -49,7 +49,7 @@ extern int in_suspend; /* Do we need to reset el2? */ -#define el2_reset_needed() (is_hyp_mode_available() && !is_kernel_in_hyp_mode()) +#define el2_reset_needed() (is_hyp_nvhe()) /* temporary el2 vectors in the __hibernate_exit_text section. */ extern char hibernate_el2_vectors[]; diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 47f77d1234cb..d20620a1c51a 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -202,7 +202,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_nvhe()) { pr_err("Not supported on this hardware/boot configuration\n"); goto out_err; }