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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D631C77B73 for ; Tue, 30 May 2023 19:55:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230433AbjE3Ty7 (ORCPT ); Tue, 30 May 2023 15:54:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbjE3Ty6 (ORCPT ); Tue, 30 May 2023 15:54:58 -0400 Received: from out-8.mta0.migadu.com (out-8.mta0.migadu.com [IPv6:2001:41d0:1004:224b::8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 283EEB2 for ; Tue, 30 May 2023 12:54:57 -0700 (PDT) Date: Tue, 30 May 2023 19:54:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1685476495; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=htwngbgIM6ZN3m6ZvTP5t2aYi4SJcXt18PpdVgVHy80=; b=Nwl2017bgJ899tFHJGB9HffKOzY3lgGKfnWiGeFSxr5rZCDIHtgQL/uvnQ9zbnW80mmi7w 4Ls9VxkU7VgpAQ3DwWx8PgiwSRxnWknxVEk4+ZOg13JRGX94IrtSeYqxTTtdJN3FMqThqX q4QsyL705SyPIvgUeorNLzAnkXgbXBo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Marc Zyngier Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Zenghui Yu , Quentin Perret , Will Deacon , Fuad Tabba Subject: Re: [PATCH v2 02/17] arm64: Prevent the use of is_kernel_in_hyp_mode() in hypervisor code Message-ID: References: <20230526143348.4072074-1-maz@kernel.org> <20230526143348.4072074-3-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230526143348.4072074-3-maz@kernel.org> X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi Marc, On Fri, May 26, 2023 at 03:33:33PM +0100, Marc Zyngier wrote: > Using is_kernel_in_hyp_mode() in hypervisor code is a pretty bad > mistake. This helper only checks for CurrentEL being EL2, which > is always true. > > Make the link fail if using the helper in hypervisor context > by referencing a non-existent function. Whilst we're at it, > flag the helper as __always_inline, which it really should be. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/include/asm/virt.h | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h > index 4eb601e7de50..91029709d133 100644 > --- a/arch/arm64/include/asm/virt.h > +++ b/arch/arm64/include/asm/virt.h > @@ -110,8 +110,13 @@ static inline bool is_hyp_mode_mismatched(void) > return __boot_cpu_mode[0] != __boot_cpu_mode[1]; > } > > -static inline bool is_kernel_in_hyp_mode(void) > +extern void gotcha_is_kernel_in_hyp_mode(void); > + > +static __always_inline bool is_kernel_in_hyp_mode(void) > { > +#if defined(__KVM_NVHE_HYPERVISOR__) || defined(__KVM_VHE_HYPERVISOR__) > + gotcha_is_kernel_in_hyp_mode(); > +#endif > return read_sysreg(CurrentEL) == CurrentEL_EL2; > } Would BUILD_BUG() work in this context, or have I missed something? -- Thanks, Oliver