Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2566100lqp; Mon, 25 Mar 2024 02:50:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX8FWiCq8BMmhgxSi9YjPjxwJT4e4sbUO4Eh2xZ0OkmkesP3bnSw8JyxiQqq+5JHDuT5eZYCQwlLnMxtom2k8UpyfRwfW2Ya4qyInP7vw== X-Google-Smtp-Source: AGHT+IHfNOY4SkzgyY3Jpgk5qJcaHc8OkA7ltoT5TKwZRbBVpp9aqilFCCRjHP4c3JT6Yr2t5sit X-Received: by 2002:a05:6a20:3952:b0:1a3:53ae:80c7 with SMTP id r18-20020a056a20395200b001a353ae80c7mr9079125pzg.7.1711360226730; Mon, 25 Mar 2024 02:50:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711360226; cv=pass; d=google.com; s=arc-20160816; b=CScbNo46S0e2RGmR6iXw4E1VpxoYxpLAfW40PGR5Qq7LSMjj2GL5bu7XLOJFI32zQZ 3IEYSrKYlFFhwAXJCgzBF5UUa9MNZapTjPL55VFRPYhIklg3GqD7BxCbrP5AQdJHAG9s d+oDIFV84Ey2BFUU1DUEFMGqpS+EnEL+Q1JiC1eM8Fbb4rHGhzJmRHYj7OTaIHdrRF38 K6FxF8hNzBCKbOFcrzUENj6fidhmd4wFwZchnVLg1n4Iucwf2FRY/JsYhoJrb0PqcALk MxPmnv8g+0PDn8z0hKvHOo3lRj1SMW5xs8ye1m2WZ9ZqyTi0a7L9MqiAoVBlnmUp99NK vclQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ihm7h5RXymNi151DgxkOK4EEAu19lzrXHPC+cxs9e98=; fh=F4+0HI6D+Zw1MPCTfED+SaQho8sePYWXOsxPTtEWFf0=; b=pwJ1zRei7fk+L/J0lad0KqWGEE/ENARIPo6e1nZlNbUPwiuHWAqoPVtIduYcJez5HK zO++WtO0Li/uM3z76raYvatmqa/qPmXhEM3w0jZRqbv3F0kKcDRVXddJQ3CD6IQTnxw0 jRxdfObot70JozqnWDNqqlvyTjLvD1rk1Z3k/EZKt/vOdvI0UQhBhUjLz0tVwH95uNrl 85k/2h0eHTvFdCd2spqNsOGp1YDVFtNE5LC9ccBbcNmUk3+ktEq9rzhWHXi7bfCsyGxX xeYfIuiCvDp+t63l4kLqX5SW8mfwR0UbkX9TXePMFy6PpmK9RJ48OZy1BWqIApWpKKIJ 7shg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="F1Jlk/f7"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115737-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115737-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h1-20020aa786c1000000b006e656ef20f6si4811523pfo.206.2024.03.25.02.50.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 02:50:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115737-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="F1Jlk/f7"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115737-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115737-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 19D44B33FD6 for ; Mon, 25 Mar 2024 09:14:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC15C21AFE2; Mon, 25 Mar 2024 02:57:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F1Jlk/f7" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C89B21C99F; Sun, 24 Mar 2024 23:10:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321846; cv=none; b=CZ9OZhkPIW1vxwKfDLqimXUlMnkPthiAuK8HxythX3KuwdjyhQIrwQdVjZ61DAs5zkHltsUghwPuP2riMOFpgukOwTRYz4Fq69ELs2OuXnX/HBnjy+On+YK2ehaJvePhEhH+lwINwX6lViCyuR+HohUjSO/LzsGLQLayYUFVub4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321846; c=relaxed/simple; bh=ZsGdZoB7ileVKJyMqzxesuFEMdBK59pTpB+KyAjD88E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aOETV5ElouZeo4o3MLM0VLWmm5q3c6VGcf5+/sPjEPsYrJwJQvRGVbQI/sSRM94m9qWM4TV7Rc4Zshkp46C0n+YL9t0IvOG1AzaK7lFt4Cv5XdRcSohT2S9L3+OSMhvgppyi4byGyYV4zOshllCo0M/JednVePFaPV8Iem1/j/U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F1Jlk/f7; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47733C43390; Sun, 24 Mar 2024 23:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711321845; bh=ZsGdZoB7ileVKJyMqzxesuFEMdBK59pTpB+KyAjD88E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F1Jlk/f72QG5LSn0zUPHO79G8RBepC3HrYE2EZcYjA8ctw0JxXuPXYjuUMDiREJM3 hgJrwyfjlu3nNtMWdiKm2qEOBtPEI1P0Fq85h6cuV+m0YSo5ipaOhtICxlW0Ybfasf tnY1QbMk6ylZ6Kpd/4WVn/gfP1ofjAB9XG9J+AevD5+o1FJLaWLfMYqvjcIR8vXfjn +MgeIyL0uKV11D8OVs9hFLUUTrvSYH7wT0WoEWaZT+z7ZxNY3+Dqm5Ul5xHWb6p76w WJrpTxejr+fLBb5xcWPs7Adv6BwxY6i5r7zT/Q47t5RQLmIpdYmDj1TEIQRvJmorcG TvgMfyiR0Sygg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Saurabh Sengar , Michael Kelley , Wei Liu , Sasha Levin Subject: [PATCH 6.6 573/638] x86/hyperv: Use per cpu initial stack for vtl context Date: Sun, 24 Mar 2024 19:00:10 -0400 Message-ID: <20240324230116.1348576-574-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324230116.1348576-1-sashal@kernel.org> References: <20240324230116.1348576-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Saurabh Sengar [ Upstream commit 2b4b90e053a29057fb05ba81acce26bddce8d404 ] 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: 3be1bc2fe9d2 ("x86/hyperv: VTL support for Hyper-V") Signed-off-by: Saurabh Sengar Reviewed-by: Michael Kelley Link: https://lore.kernel.org/r/1709452896-13342-1-git-send-email-ssengar@linux.microsoft.com Signed-off-by: Wei Liu Message-ID: <1709452896-13342-1-git-send-email-ssengar@linux.microsoft.com> Signed-off-by: Sasha Levin --- 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 53b309d41b3b9..c2f78fabc865b 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; @@ -64,7 +65,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; @@ -78,7 +79,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); @@ -205,7 +208,15 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id) static int hv_vtl_wakeup_secondary_cpu(int 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); @@ -219,7 +230,7 @@ static int hv_vtl_wakeup_secondary_cpu(int 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 00242107d62e0..862c47b191afe 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.43.0