Message ID | 1706811931-3579-1-git-send-email-ssengar@linux.microsoft.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-48695-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp364786dyb; Thu, 1 Feb 2024 10:35:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgcY6a3Kw1YGh5ORcFAuZAXS4LvEfwFPTWf0pr7CME9rojEMyeCOgtjC9DttdbGqVgxYR7 X-Received: by 2002:a05:6a00:2295:b0:6db:ca49:9ce3 with SMTP id f21-20020a056a00229500b006dbca499ce3mr3635172pfe.6.1706812544743; Thu, 01 Feb 2024 10:35:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706812544; cv=pass; d=google.com; s=arc-20160816; b=WyZ3SMGdFteInAHwrY0n6KnugcNxY2re0u0miLCInHbJ4RTU56P+n7Jvaw5hRx8tfT zmEmILTbds7Bbf041DiYOn92DGxQU74fncGmJFgcoI/mhw2bj5Z6n1heY/i91rtu+miy VEFg6NoTnekXUMM6af9UWdzuHiT0BrKUnrm1EINh+7/2rNwYI4SWOqBsG3QK2oiNE/MU pWwK9gu8it8HEDrmsNmT/nKww2l05JHlV9TQGJlQdI95INbvJaQGzjv9Z+oPYCZtl2hP NPR0lFOIy+ZCYPkGge9GKnuj1WZbQjE0KRUUkPFRlgHbJWMJLZf4S3VOyusf59yj2Jzo uULw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=EHQDwjjVzZ88bNsS20/UDC5Vi19PhVaSrJVWsd14ed0=; fh=K+MYYQ20R6ByPLLsyDGaMytISzwQAigW2OtSMx0XuRE=; b=hfg8xHpdpReKSP61ZsW9T6pMiMTY/3D85zxra6GqqzIGUaNWsLQViQAQ36dbyL7bKh 6LpGbZssW+DbvhswypicxqSa3kV6aY9z0L+yu+jIynO8aCHZSWCAOR7P/K98nKVxHyUu X4yT+EUVgeGNve171XgjahXAtLnjY9VJKCvG9GpMc9EE0rcLyL3NAVY5vsyV3RW+wJvr 8iH/BSOH6zUnAOA7mSq1qfqL0H+KObaGuUy7a0lRtwZSnQtPUwKI/PxxuqGk4NBvfMHP KBaY2y8KkQGGQZZ3e9cXvxTh0FMP2RCIDtr/GqdUwwAzPRNb5dOUEg8RLYq6j1EPfIwZ Jgjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="Q/31eGNM"; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-48695-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48695-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com X-Forwarded-Encrypted: i=1; AJvYcCUF9RvPkO1D3kHrl4STuM77ZZ0oF/3ua5QaSPEC+4VoItsG2sMEF3DAy1u92C3lL2vl/aww8brUeOZDKOfLv6MDT935Lg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h11-20020a056a00170b00b006dfeed741c7si93744pfc.4.2024.02.01.10.35.44 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 10:35:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48695-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="Q/31eGNM"; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-48695-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48695-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A282529B361 for <ouuuleilei@gmail.com>; Thu, 1 Feb 2024 18:26:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A19F84FDD; Thu, 1 Feb 2024 18:25:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Q/31eGNM" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77A0512FB2A; Thu, 1 Feb 2024 18:25:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706811939; cv=none; b=ZPRUdU66nbtjJyF+Jn35QDx3Ypn8z3tYd5l5B+Io8HpoTGaeevy2BHvUyVV3bCdDz5y3CtNy2dtMyt6dObUixrGnM4LeafNb83oqJacyQeNvbgtsRrzaXpl3cW4mV4qX4+Z1H5drvXc0HA3TW3/lOSLEeQ2NoXgXzSMCtlUu1Sw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706811939; c=relaxed/simple; bh=LQBEIMnLecAl+vJ+XotE8XRfN49u42wwrviAFW3qf+I=; h=From:To:Cc:Subject:Date:Message-Id; b=IAoX0sxNYEE0o0CS1YmiVEcTOClwXzzpwY6V3fsEF8pPXPUvS5rwH4RmPuRG3v65C4bvYrIlnErrdRTtOWw/6mLFXrrZXyDfw0xjYv9jq0CRhDerpl/Bep1FoZac1FTeeXfjwigQMry/5yIH4nADi63FXlWns19jPduWU1+Y0WY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=Q/31eGNM; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id E8D6220B2000; Thu, 1 Feb 2024 10:25:37 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E8D6220B2000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1706811938; bh=EHQDwjjVzZ88bNsS20/UDC5Vi19PhVaSrJVWsd14ed0=; h=From:To:Cc:Subject:Date:From; b=Q/31eGNMWcBfOQ+KNtygSmngPJY2nL7GC2U1wgdEVpRBsGTsLOLEMndTnqv5WHaTT pSP/ltvKviNqhbMWLQExnA183YHM0RcThya3eQqnUTjwjgsnX6jd5FcsvCXjZTIR75 hkzQVXf2ufxwWrYCsgsToeO7pP66Je/TVA+ELMAQ= From: Saurabh Sengar <ssengar@linux.microsoft.com> 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, dwmw@amazon.co.uk, peterz@infradead.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ssengar@microsoft.com Subject: [PATCH] x86/hyperv: Use per cpu initial stack for vtl context Date: Thu, 1 Feb 2024 10:25:31 -0800 Message-Id: <1706811931-3579-1-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789722670711387480 X-GMAIL-MSGID: 1789722670711387480 |
Series |
x86/hyperv: Use per cpu initial stack for vtl context
|
|
Commit Message
Saurabh Singh Sengar
Feb. 1, 2024, 6:25 p.m. UTC
Currently, the secondary vCPUs in Hyper-V VTL context lack support for
parallel startup. Therefore, relying on the single initial_stack fetched
from the current task structure suffices for all vCPUs.
However, common initial_stack risks stack corruption when parallel startup
is enabled. In order to facilitate parallel startup, use the initial_stack
from the per CPU idle thread instead of the current task.
Fixes: 18415f33e2ac ("cpu/hotplug: Allow "parallel" bringup up to CPUHP_BP_KICK_AP_STATE")
Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
---
arch/x86/hyperv/hv_vtl.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Comments
On Thu, Feb 01, 2024 at 07:53:59PM +0000, Michael Kelley wrote: > From: Saurabh Sengar <ssengar@linux.microsoft.com> Sent: Thursday, February 1, 2024 10:26 AM > > > > Currently, the secondary vCPUs in Hyper-V VTL context lack support for > > parallel startup. Therefore, relying on the single initial_stack fetched > > from the current task structure suffices for all vCPUs. > > > > However, common initial_stack risks stack corruption when parallel startup > > is enabled. In order to facilitate parallel startup, use the initial_stack > > from the per CPU idle thread instead of the current task. > > > > Fixes: 18415f33e2ac ("cpu/hotplug: Allow "parallel" bringup up to CPUHP_BP_KICK_AP_STATE") > > Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com> > > --- > > arch/x86/hyperv/hv_vtl.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c > > index 96e6c51515f5..a54b46b673de 100644 > > --- a/arch/x86/hyperv/hv_vtl.c > > +++ b/arch/x86/hyperv/hv_vtl.c > > @@ -12,6 +12,7 @@ > > #include <asm/i8259.h> > > #include <asm/mshyperv.h> > > #include <asm/realmode.h> > > +#include <../kernel/smpboot.h> > > > > extern struct boot_params boot_params; > > static struct real_mode_header hv_vtl_real_mode_header; > > @@ -71,7 +72,8 @@ static int hv_vtl_bringup_vcpu(u32 target_vp_index, u64 eip_ignored) > > struct ldttss_desc *ldt; > > struct desc_struct *gdt; > > > > - u64 rsp = current->thread.sp; > > + struct task_struct *idle = idle_thread_get(target_vp_index); > > The "VP index" of a vCPU is a Hyper-V concept, and may not match > the Linux concept of a CPU number. In most cases, they *do* match, > so your testing of this patch probably worked. But there's no guarantee > that they match. The Hyper-V TLFS does not even guarantee that VP > indices are dense or that they start with 0 (even though they do in > current versions of Hyper-V). > > As a different kind of example, in a kdump kernel, Linux labels the > booting CPU as CPU 0, but it may not be the 0th CPU in the guest > VM, and hence may not have VP index of 0. Of course, in a kdump > kernel nr_cpus is typically 1, so you aren't bringing up secondary > CPUs. But sometimes kdump kernels boot with nr_cpus=2 or greater, > in which case the mismatch would occur. > > This conceptual difference in VP index and Linux CPU numbers is why > the hv_vp_index array exists -- to map from a Linux CPU number to a > Hyper-V VP index, and thereby avoid assuming they are equal. > > So before hv_vtl_wakeup_secondary_cpu() calls this function, it needs > to separately map the apicid to a Linux CPU number, which can then > be passed to idle_thread_get(). > > Michael Thanks for the review. I will fix this in V2. > > > + u64 rsp = (unsigned long)idle->thread.sp; > > u64 rip = (u64)&hv_vtl_ap_entry; > > > > native_store_gdt(&gdt_ptr); > > -- > > 2.34.1 > > >
diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c index 96e6c51515f5..a54b46b673de 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -12,6 +12,7 @@ #include <asm/i8259.h> #include <asm/mshyperv.h> #include <asm/realmode.h> +#include <../kernel/smpboot.h> extern struct boot_params boot_params; static struct real_mode_header hv_vtl_real_mode_header; @@ -71,7 +72,8 @@ static int hv_vtl_bringup_vcpu(u32 target_vp_index, u64 eip_ignored) struct ldttss_desc *ldt; struct desc_struct *gdt; - u64 rsp = current->thread.sp; + struct task_struct *idle = idle_thread_get(target_vp_index); + u64 rsp = (unsigned long)idle->thread.sp; u64 rip = (u64)&hv_vtl_ap_entry; native_store_gdt(&gdt_ptr);