Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1155883rdb; Wed, 20 Sep 2023 00:47:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvaIT88/st2v2k7G/RlVYrx2Ed06iCZyrJ3h3v3SYi2jMYzWBDhX2thc5os3k4pfYy6ZlV X-Received: by 2002:a05:6a20:7352:b0:15a:f4e:620d with SMTP id v18-20020a056a20735200b0015a0f4e620dmr2120060pzc.4.1695196070180; Wed, 20 Sep 2023 00:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695196070; cv=none; d=google.com; s=arc-20160816; b=OrhRzRJjg/Ue0QrLv4GypeakhasU/GqbakyM6ecurF2fCt/OpnuqVYvjftYRN8WjCF DSKaFjzwaOL4VCREZzzTwoJ4BrtgAqDUl8Z4WIUot1e20MlgCOeYhPVDH3j7K090x0pq Ojquaza4ppqy6PrWKgmj5hvv3L3XAsxXIMSjjSMkTUBE52CSoCa6e7L0Jo7XmDuPLl0V S8G3iooHCsaR92REGfQRlykECLx1WeQXnOxmqMng7BhapKgTqZHrA7U1p2ge9X0dRFDW W5nqr9Rb51vmvAUPt47p3Mjt5rHjVTOLD8zBMJroxtAZXrtjKr2kQgpeyPQsCP66EeEr ormA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=mLN2bn4JjfkyYmq8OaE11aXc6Fms0dmnNK2B2velDMo=; fh=X76b0S9MjgH4l53FcWzDKTpXTkHyZ97zz1+LlFXz+Fk=; b=Ff8jWaiihNDY8KfJweLCmhtm+oxfxCGGkviupRYZvtAmq2T5+lNpiBQ0wyezuo6J6y +deQlFIrzLYc0vrdx4i0PAmy//wtTAn3D30bSruq0ZQheSWlu4RCoKbO89H4+PV4VHaI NcsBAPGMT92BzuL2WXblZxMmPwlonX7TJk6GVkAYQGOutsfYDsRiQcG7jzAU/BAIQ341 /aVPelsgp8MRcT3ejiSNwdHrOPWA886QPLTAtvjgFWHLTS1T5jPQgqJZHP5SfkVDwjvw Fd/mOP9zRAgHSi0606xbIYCyfVGdkxJoD7ByRzevy/jZrO9JIbdQwhubslKIM408UWUK 12oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=PtNVtm3z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id h12-20020a170902f54c00b001b9ea0f0e8esi11811432plf.650.2023.09.20.00.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 00:47:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=PtNVtm3z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7B10D822CB01; Tue, 19 Sep 2023 21:05:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232542AbjITEFG (ORCPT + 99 others); Wed, 20 Sep 2023 00:05:06 -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 X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 19 Sep 2023 21:05:18 -0700 (PDT) When Linux runs in a non-default VTL (CONFIG_HYPERV_VTL_MODE=y), 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=n) 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); } +#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE) static u8 __init get_vtl(void) { u64 control = 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 = 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 = 0; + pr_err("Failed to get VTL(error: %lld) exiting...\n", ret); + BUG(); } local_irq_restore(flags); return ret; } +#else +static inline u8 get_vtl(void) { return 0; } +#endif /* * 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); /* Find the VTL */ - if (!ms_hyperv.paravisor_present && hv_isolation_type_snp()) - ms_hyperv.vtl = get_vtl(); + ms_hyperv.vtl = get_vtl(); return; -- 2.34.1