From patchwork Fri Sep 22 04:58:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saurabh Singh Sengar X-Patchwork-Id: 143455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5599350vqi; Fri, 22 Sep 2023 07:03:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtE3myreqpEKO8NCj+rtJJpwFFeydLYFPMdFqv5lHy1Ot14Qka6+JcMzLoV+agvQa1X2tN X-Received: by 2002:a17:903:244d:b0:1bc:3908:14d with SMTP id l13-20020a170903244d00b001bc3908014dmr4601706pls.2.1695391421125; Fri, 22 Sep 2023 07:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695391421; cv=none; d=google.com; s=arc-20160816; b=rzYIYGtjMjXl3eIJe1YsjkjLZM3NaCx98r5924iBPMwakMsXH5Ezjs3HDPHzUQAo0j EEZy3AufgDdItmS+4nX4EUAwL6+vu8JtxaXMkIDQT8nVoutBA19f36YtKJYSBjw3GZqZ BQOWmWfYALJjt2WlkmeHy5oQ8pNaD2etgQIj8CKxo7tVgOQenJtDPTIwSLnmZCXxH1TC 9bQANQp+8suI+jIscRyxNOtWkU7NzkNVNu2sgHP8Whcv6vP9FonmKCXF4wLnoExDHLUj DewpiKvu5O2mWkW5npre2ABbR6KCBtuGi31DjFQzoDaKMBX5tqP9em0CYIQu3C7C8uaQ alww== 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=+yXMZYNsMsvn2jwwDbQl1ZwR5DmyfHWdhUieAsjjntE=; fh=diQcnjKTNudP6DVBv2JRvKLhENNPY70FwDnSY9GqiaM=; b=OEkqJBQGrmphBBxqDvFi2MTolDRAYa5JpElFozYCor0evXUhPyNTlo01fyzMJbhGYS tHwYqRQYafG8KG4aGuGIMd521gzpuLcvHRAU7aR/52IGkhYRYjacDdllhOhkTb8IHu7T 9fdGWq87LplglcnZBwvfmcEHf3AG/A5sEeNCH4l/1T7iVU23TB4VoILTxDoKUQoI044I ZKubTM9Tv83j4M7MNLwj9DC51PWHfL/k5dMpxy8I3bJpd27b01oypR3VU487S4DtI3Ac R5uNyTDWJvD+ipf3hzx1469/wYhiHF7UiZiVb+aKEouHublzpuLr66uLMCwjSKmyNFdy r8zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ZV8FpA5r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id d10-20020a170902654a00b001b8af83d939si3758221pln.537.2023.09.22.07.03.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 07:03:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ZV8FpA5r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 6923B836D618; Thu, 21 Sep 2023 21:59:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230157AbjIVE6w (ORCPT + 30 others); Fri, 22 Sep 2023 00:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjIVE6v (ORCPT ); Fri, 22 Sep 2023 00:58:51 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6629B192; Thu, 21 Sep 2023 21:58:45 -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 A1BED212C5B7; Thu, 21 Sep 2023 21:58:44 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A1BED212C5B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1695358724; bh=+yXMZYNsMsvn2jwwDbQl1ZwR5DmyfHWdhUieAsjjntE=; h=From:To:Cc:Subject:Date:From; b=ZV8FpA5rQIGeeqhPqT4DBWcgP+m3qnVc4ZFfXauyHrMtr98EOzQ1wYPpgAl/NxFTM cM2GWtz3RpyVULVnoqz0MAQ0g/yv/US4sVIPpE0Zc4+te1K+nhtiCi+dzHqQt/xz8d +QyjT7tMhmkicZfXAlaVkFiDXVJBwFShF4dWdjOM= 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 Cc: minipli@grsecurity.net, ssengar@microsoft.com Subject: [PATCH v2] x86/hyperv: Remove hv_vtl_early_init initcall Date: Thu, 21 Sep 2023 21:58:40 -0700 Message-Id: <1695358720-27681-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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 21:59:08 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777535733423808332 X-GMAIL-MSGID: 1777746754961242352 There has been cases reported where HYPERV_VTL_MODE is enabled by mistake, on a non Hyper-V platforms. This causes the hv_vtl_early_init function to be called in an non Hyper-V/VTL platforms which results the memory corruption. Remove the early_initcall for hv_vtl_early_init and call it at the end of hyperv_init to make sure it is never called in a non Hyper-V platform by mistake. Reported-by: Mathias Krause Closes: https://lore.kernel.org/lkml/40467722-f4ab-19a5-4989-308225b1f9f0@grsecurity.net/ Signed-off-by: Saurabh Sengar Acked-by: Mathias Krause --- This patch is dependent on : https://lore.kernel.org/lkml/1695182675-13405-1-git-send-email-ssengar@linux.microsoft.com/ [V2] - Fix HYPERV_VTL_MODE=n compilation flow - Updated commit s/vhv_vtl_early_init/hv_vtl_early_init arch/x86/hyperv/hv_init.c | 3 +++ arch/x86/hyperv/hv_vtl.c | 3 +-- arch/x86/include/asm/mshyperv.h | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index f0128fd4031d..608f4fe41fb7 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -610,6 +610,9 @@ void __init hyperv_init(void) /* Find the VTL */ ms_hyperv.vtl = get_vtl(); + if (ms_hyperv.vtl > 0) /* non default VTL */ + hv_vtl_early_init(); + return; clean_guest_os_id: diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c index 36a562218010..999f5ac82fe9 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -215,7 +215,7 @@ static int hv_vtl_wakeup_secondary_cpu(int apicid, unsigned long start_eip) return hv_vtl_bringup_vcpu(vp_id, start_eip); } -static int __init hv_vtl_early_init(void) +int __init hv_vtl_early_init(void) { /* * `boot_cpu_has` returns the runtime feature support, @@ -230,4 +230,3 @@ static int __init hv_vtl_early_init(void) return 0; } -early_initcall(hv_vtl_early_init); diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 033b53f993c6..896445edc6a8 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -340,8 +340,10 @@ static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; } #ifdef CONFIG_HYPERV_VTL_MODE void __init hv_vtl_init_platform(void); +int __init hv_vtl_early_init(void); #else static inline void __init hv_vtl_init_platform(void) {} +static inline int __init hv_vtl_early_init(void) { return 0; } #endif #include