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: 12500479 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 C5FD3C433F5 for ; Thu, 16 Sep 2021 23:15:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 9263D611EE for ; Thu, 16 Sep 2021 23:15:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9263D611EE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aRIJWFBPXom/IUO0SnbXCaole1RPALtsTqkwZR9mI+4=; b=V1ATpmlvq/Hioa MzVWY6GNFJFdG7R01lymIPNSALie7T7jJOBtGDB6uqDh1/rHwE52vSKnpCCp2QciWR9rsX43jtrJ1 h0cYNnkkms3+hGfTRF977fqwsqf9GcXX1CBupm85opIjmtacG+IRy0fEk8AYoMM/Cm71vJiEC9Ill sPs/QXmZ+eXkaufo0YoSI9CX5m06ofBB5zY3FljL7iITnD3l7JpPe4jcSGc/6n7oXFhbXrQ/zywvG ieEU50xsCCZ3QplgtkUZvb41x++9yv3CXIQzs/Q2oqlz0CbCL8qsKISjcw2H8oEq75E5ThOwBog8U zgTIMGpuhgVfCEpZqOJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mR0Zm-00CaJs-Vo; Thu, 16 Sep 2021 23:13:55 +0000 Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mR0ZQ-00Ca3r-L3 for linux-arm-kernel@lists.infradead.org; Thu, 16 Sep 2021 23:13:34 +0000 Received: by mail-qv1-xf2f.google.com with SMTP id cf2so5289029qvb.10 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=dRtTo5uWEdkCQZOAj1tOspDy/BPJ7J8scfc8IfIBEnMPfmSnaDQSS+6TZfmwxBKCl3 H9DolyivU1X6ZEwNRZE1OquPYZi7TryG4UnI7MDqwPb+0uSkUPAVEZjTbUy29Lms+VSB JRRiR6lUj68bvaBHq042ZoIs4on70O0+iqxOP3p81RRaYZiE0pGgrd5lK6lm8rHYt4jA z7T4NjzjByR39p4htgCT0XJqrkCTKL2qjMfQI0RS/WJZv6oLyOKeXyXG72/pT0Zuw2KT +Xxpwu8b0KjT5Iks+3Lx2hk2WwHCFe3iAaWr+v9PdyvA9pECb7u5EYkoVWor5MVeTrlW MkAQ== X-Gm-Message-State: AOAM533vOZByYzdvDx3KN1RgqiwQuQLFcEbrZBYOz92F03+2WKESo1aB J4EZh+RjejiGd+GJEP8QewwXBg== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210916_161332_737856_798C8D26 X-CRM114-Status: GOOD ( 15.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; }