Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1671567lqg; Sun, 3 Mar 2024 23:08:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVnlFxSFKYHOkkkMuKr/Jw1SZiuuWN/joufk/ZZi3jsq72xXMHINXiFe+MlFDsW6p/5ocIgWf+OVkvbX9SuZVBb+2B3PedE4k44aW1DPw== X-Google-Smtp-Source: AGHT+IEsFu91sgVt7Qy2ehOro3NcQSCilZDBo2rgRnKoO+7Y1rqfqtc6UijdcmCY0Oha5oK+aUVk X-Received: by 2002:a05:6a00:1490:b0:6e5:f675:2827 with SMTP id v16-20020a056a00149000b006e5f6752827mr4670757pfu.11.1709536104737; Sun, 03 Mar 2024 23:08:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709536104; cv=pass; d=google.com; s=arc-20160816; b=gDRwOj0EXyGGL4hBwF1i0d63jr1uOo+Ddzm/pfNVA8o23yPGHY5m/BcwPtfEE8DaQH 8Tz0AQM7GZtU1UoSkb4fuNHZsWnGz8KphOK1hiQsa010SIyS6j+wRc3R4jdWVUXR+eKb C/irEudheZJuUAMvugrNpI+xlXAfJrLJXt5GUUHRyCqY8G45ylicAq9w/aYSJJSDvWuh 7oWZgIMzlYMiLcgymNXX8aQT9IyHekfIQXRrMOU9aE4qnBtUUXHyEZ4qlH7UmjihAbS5 JG1Tkk2mD/uB0G+k5KQu7HN1gswG3x2qMf87vAxrT6Ty51jI/PaxkRvoreXNa8Q1SvVw /WHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature:dkim-filter; bh=9pO23Pg5PwijYFQsb1h5+UWzqjRYkZ7j/df8N5fJN/8=; fh=VYedHhzxLYmoFEUkGXdP/u3X3/QphQfDyl7pAJXcTC0=; b=csulsFpYOXJiCtykqtfwAlgDpnEcFopHhrJ3+3WYX3Sy9pYwpJuAgSMa7+tsP5unJd +5EYoVtMIkxmxsK7Ay/bo5qtsiHhD5jDfOteKMWtZjlFKo2X+YomXvJxEJ3ppM9uXCFH DvmzzQjsouMVx7llmnhQFqlRh0ecpgtAIhMF50LP46lUygk8risQKJpM6VS8cmPHthW5 ZFz2qKkH8t6fcQi1W1TAMfqni+0AmyHLlmvyWSk78JUjD9b4rkAeBEHWL0wyIkfbgABg BYU5grR9oQyBn08A9HtBh62v2sX830kujupg1NiwG8G4d35FXjz5W4pEvlXxE6aOLV3B QqXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=OsJW4yDh; 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-90111-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90111-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m11-20020a62f20b000000b006e48bbb9073si7771507pfh.309.2024.03.03.23.08.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 23:08:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90111-linux.lists.archive=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=OsJW4yDh; 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-90111-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90111-linux.lists.archive=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 1537828175D for ; Mon, 4 Mar 2024 07:08:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9D65134AE; Mon, 4 Mar 2024 07:08:19 +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="OsJW4yDh" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95C3712E4F; Mon, 4 Mar 2024 07:08:17 +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=1709536099; cv=none; b=IDNywbP02tf81LtZc/zWX9rPqvisMFZT5SualRn+Chv94trFuzX/TFJ7P1rdeZkuXLMZqio1UJCXNobk6N+9D1N0tsOtasZ/Sjtsbf6NsJJT6tcO0X0WCXFayem3YUfumIUuBzTv2aNvaXxEwiV6qMpYXJXYJyE1fnBaooSGxv0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709536099; c=relaxed/simple; bh=85CjglgMm8FIeWTxu2nlk+0mIr4+9dhpjr8AGjXgTj0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fPB/xAE3aK+JyNHFRdM+g5gKgd4bI/1bCNDJkZiyFJc/a0hm1NZ92derlHQa/ZWxztVQeNMvLymD2S1+BeJSkNaFmTPmnjxiAku8pnDv9LM9vF1/znh6E4xgzLOJiepoVWRPvd4DfE/BSJUt6FjUjPX0+2TYaEWDx80s3N82LgQ= 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=OsJW4yDh; 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: by linux.microsoft.com (Postfix, from userid 1127) id 1CE1220B74C0; Sun, 3 Mar 2024 23:08:17 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1CE1220B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1709536097; bh=9pO23Pg5PwijYFQsb1h5+UWzqjRYkZ7j/df8N5fJN/8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OsJW4yDhbvbHNx7GnAKnTRfP/quYg8LO2oJxJ6v2+b6xuatqvDXie56KHJvZk3+1t Lq73c11RhfqbKt0QvQm9LmaqP1ryVkY5cELKAC/VZAe8c+PKMl7ENghGyuumM/52kO NmTJYGeZ9LcrU5piFiJK6ctqKmHVenAUsFAOHo1s= Date: Sun, 3 Mar 2024 23:08:17 -0800 From: Saurabh Singh Sengar To: Wei Liu Cc: kys@microsoft.com, haiyangz@microsoft.com, 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, ssengar@microsoft.com, mhklinux@outlook.com Subject: Re: [PATCH v3] x86/hyperv: Use per cpu initial stack for vtl context Message-ID: <20240304070817.GA501@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1709452896-13342-1-git-send-email-ssengar@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) On Mon, Mar 04, 2024 at 06:24:27AM +0000, Wei Liu wrote: > On Sun, Mar 03, 2024 at 12:01:36AM -0800, Saurabh Sengar wrote: > > Currently, the secondary CPUs 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") > > I don't think this patch is buggy. Instead, it exposes an assumption in > the VTL code. So this either should be dropped or point to the patch > which introduces the assumption. > > Let me know what you would prefer. The VTL code will crash if this fix is not present post above mentioned patch: 18415f33e2ac ("cpu/hotplug: Allow "parallel" bringup up to CPUHP_BP_KICK_AP_STATE"). So I would prefer a fixes which added the assumption in VTL: Fixes: 3be1bc2fe9d2 ("x86/hyperv: VTL support for Hyper-V") Please let me know if you need V4 for it. > > Thanks, > Wei. > > > Signed-off-by: Saurabh Sengar > > Reviewed-by: Michael Kelley > > --- > > [V3] > > - Added the VTL code dependency on SMP to fix kernel build error > > when SMP is disabled. > > > > arch/x86/hyperv/hv_vtl.c | 19 +++++++++++++++---- > > drivers/hv/Kconfig | 1 + > > 2 files changed, 16 insertions(+), 4 deletions(-) > > > > diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c > > index 804b629ea49d..b4e233954d0f 100644 > > --- a/arch/x86/hyperv/hv_vtl.c > > +++ b/arch/x86/hyperv/hv_vtl.c > > @@ -12,6 +12,7 @@ > > #include > > #include > > #include > > +#include <../kernel/smpboot.h> > > > > extern struct boot_params boot_params; > > static struct real_mode_header hv_vtl_real_mode_header; > > @@ -58,7 +59,7 @@ static void hv_vtl_ap_entry(void) > > ((secondary_startup_64_fn)secondary_startup_64)(&boot_params, &boot_params); > > } > > > > -static int hv_vtl_bringup_vcpu(u32 target_vp_index, u64 eip_ignored) > > +static int hv_vtl_bringup_vcpu(u32 target_vp_index, int cpu, u64 eip_ignored) > > { > > u64 status; > > int ret = 0; > > @@ -72,7 +73,9 @@ 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(cpu); > > + u64 rsp = (unsigned long)idle->thread.sp; > > + > > u64 rip = (u64)&hv_vtl_ap_entry; > > > > native_store_gdt(&gdt_ptr); > > @@ -199,7 +202,15 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id) > > > > static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip) > > { > > - int vp_id; > > + int vp_id, cpu; > > + > > + /* Find the logical CPU for the APIC ID */ > > + for_each_present_cpu(cpu) { > > + if (arch_match_cpu_phys_id(cpu, apicid)) > > + break; > > + } > > + if (cpu >= nr_cpu_ids) > > + return -EINVAL; > > > > pr_debug("Bringing up CPU with APIC ID %d in VTL2...\n", apicid); > > vp_id = hv_vtl_apicid_to_vp_id(apicid); > > @@ -213,7 +224,7 @@ static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip) > > return -EINVAL; > > } > > > > - return hv_vtl_bringup_vcpu(vp_id, start_eip); > > + return hv_vtl_bringup_vcpu(vp_id, cpu, start_eip); > > } > > > > int __init hv_vtl_early_init(void) > > diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig > > index 00242107d62e..862c47b191af 100644 > > --- a/drivers/hv/Kconfig > > +++ b/drivers/hv/Kconfig > > @@ -16,6 +16,7 @@ config HYPERV > > config HYPERV_VTL_MODE > > bool "Enable Linux to boot in VTL context" > > depends on X86_64 && HYPERV > > + depends on SMP > > default n > > help > > Virtual Secure Mode (VSM) is a set of hypervisor capabilities and > > -- > > 2.34.1 > >