From nobody Sat Feb 7 17:38:08 2026 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 62D48CE79AD for ; Wed, 20 Sep 2023 04:05:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232547AbjITEFH (ORCPT ); Wed, 20 Sep 2023 00:05:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232569AbjITEEt (ORCPT ); Wed, 20 Sep 2023 00:04:49 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7FAAAC; Tue, 19 Sep 2023 21:04:43 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id E28B2212C4AC; Tue, 19 Sep 2023 21:04:42 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E28B2212C4AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1695182682; bh=mLN2bn4JjfkyYmq8OaE11aXc6Fms0dmnNK2B2velDMo=; h=From:To:Cc:Subject:Date:From; b=PtNVtm3zZx27iw5h//0Uhikal2u4g7eMDbVVkP01fUkuTLzWMKwg5mlyNYqk8ZiXg KIHJzaiCc8lhaI72rsyZCFdQsheJFWzZFKmv4rjQ34TibIQDv4rNv4wBIq8yjGgA6l Xt2NorulcN6BJJNrpndToxJLYOKolxlIKTq7jdrs= From: Saurabh Sengar To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, mikelley@microsoft.com, vkuznets@redhat.com Cc: ssengar@microsoft.com Subject: [PATCH v3] x86/hyperv: Restrict get_vtl to only VTL platforms Date: Tue, 19 Sep 2023 21:04:35 -0700 Message-Id: <1695182675-13405-1-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When Linux runs in a non-default VTL (CONFIG_HYPERV_VTL_MODE=3Dy), get_vtl() must never fail as its return value is used in negotiations with the host. In the more generic case, (CONFIG_HYPERV_VTL_MODE=3Dn) the VTL is always zero so there's no need to do the hypercall. Make get_vtl() BUG() in case of failure and put the implementation under "if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)" to avoid the call altogether in the most generic use case. Signed-off-by: Saurabh Sengar Reviewed-by: Vitaly Kuznetsov --- [V3] - Modified commit message - Added reviewed-by [V2] - Put the if else at function definition rather then at the caller arch/x86/hyperv/hv_init.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 783ed339f341..f0128fd4031d 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -394,6 +394,7 @@ static void __init hv_get_partition_id(void) local_irq_restore(flags); } =20 +#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE) static u8 __init get_vtl(void) { u64 control =3D HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS; @@ -416,13 +417,16 @@ static u8 __init get_vtl(void) if (hv_result_success(ret)) { ret =3D output->as64.low & HV_X64_VTL_MASK; } else { - pr_err("Failed to get VTL(%lld) and set VTL to zero by default.\n", ret); - ret =3D 0; + pr_err("Failed to get VTL(error: %lld) exiting...\n", ret); + BUG(); } =20 local_irq_restore(flags); return ret; } +#else +static inline u8 get_vtl(void) { return 0; } +#endif =20 /* * This function is to be invoked early in the boot sequence after the @@ -604,8 +608,7 @@ void __init hyperv_init(void) hv_query_ext_cap(0); =20 /* Find the VTL */ - if (!ms_hyperv.paravisor_present && hv_isolation_type_snp()) - ms_hyperv.vtl =3D get_vtl(); + ms_hyperv.vtl =3D get_vtl(); =20 return; =20 --=20 2.34.1