Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2224369rdb; Wed, 21 Feb 2024 00:25:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXyr0IspouCNX1WpxR4MBPVOo7E3MQiO/J2AZ6gdb6zqs31iYns8oihIN9HSFJEd7hjH1abOWJOXt6US/xwBYVfoWifELdjBepgXsvNhQ== X-Google-Smtp-Source: AGHT+IFfIfbX6vaCc+WctV93/E2uUcJCtVC3AwnlYgzYMUcN9Rcc4yGBCwD7WFQdfOpdo/ClHL8U X-Received: by 2002:a05:6808:2388:b0:3c0:4129:9467 with SMTP id bp8-20020a056808238800b003c041299467mr22344843oib.0.1708503909973; Wed, 21 Feb 2024 00:25:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708503909; cv=pass; d=google.com; s=arc-20160816; b=Z2cAFGVI206yjRLPfhV1fG2F5InkX3R/+2HSOG2u1a6qrC2fmuRx22OZWG7IBTYRim CT3af/RLJeC6K0YyVPkSMU9eyJYwffQuZOW/7AvBVXSNh2aXAzQa9vqskmMhQs4tVwkv NrmS6gterec9kTMv8DUUvp8+xxPliENpgIMIOLB8664fHQZ1+5wueNxc/CrNFZkKFg3K 8Jr0NxRhSRWNtUtKiPzWKYR2SxubOTtRW0nn4p5fmglPfWORi/7GtWVZqcWRBDS4sS6y xB+9anrJKr3UXpMulndJeIGjH3gGvwQpz8JGBwUI2RpVSLJ8UXc2i4PxeRvQmLwfFuo1 K9qA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=oVLD2bU2eId6hnwGLZd21GxQPk7a0tfGVCylfbMollo=; fh=WuQvpk6wLzB4Rn153D+AqNBnRt6WYYeEM3NCy46Pb90=; b=GboNo10UzFJ3pUCWPLLwgb2Dq554pck6Sh5kKnCVT7vjnV+ZrcVzkWkD6K2Gge9R/J cuDPdZGbkF1a+JdVkCkgNqBnB31buKavXsmWME2C/11HvojHF6CKyZacF2XQzqdI1lP7 Xges89rZf+pen54W4kiDqhaukg0bzGnvxTLUqBdIiAOJ9nv7EK350u88DUT7tu/IXWCP yMMzcw9lVRcp+ucUiaVDBu5u0fmO3FiP0jrVgVGxCTpMSaFsC12Oa17POHEKRZXsU81q vnLq2BGH185K0Mar7urT0FOGYBsg3uJIFl5ZSrtu0yA7XLAHyj6ZOC1uty5BG/vGGzX9 RpIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ICs169in; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-73956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i12-20020a056a00004c00b006e0eff486f4si7029404pfk.61.2024.02.21.00.25.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 00:25:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ICs169in; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-73956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 2361B285AD8 for ; Wed, 21 Feb 2024 02:29:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DDF410942; Wed, 21 Feb 2024 02:29:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ICs169in" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 476023C29; Wed, 21 Feb 2024 02:29:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708482564; cv=none; b=t7BN7WfQNgcp2eY2zMvxv8bQJeeQGx1itHQ+ciWtsQCIj50PypzysQULidshPaiVBYJdPMvTUF862xde80UPvdKz3UdGCOSDfGKmyhodMkEVX3c69M1LzQMD8Cl4hKsmJqYb+AugUINuHb/pdJkgNTKzClsE10j5JTXAmanDVzA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708482564; c=relaxed/simple; bh=gPPbnQYj1+eq6sPOlu7HUtlfxwyArBDBxuXKAwgAUJw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=u2eVS4gX5hpvJTj1bu6pJQwDI4zMSaYgUEC73nZs/BgsMRAle+jpK9U+VHn1qFa75Iu5D8EBJGBh6FLopq7wUhBLntnz5WNn932DiFeJoroHDPkLd0jz2v6S9vB9omQVSOxU1hHJGHTH14wTTgFDpz2nSseObmh0fuoQDlNcCm8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ICs169in; arc=none smtp.client-ip=198.175.65.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708482563; x=1740018563; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=gPPbnQYj1+eq6sPOlu7HUtlfxwyArBDBxuXKAwgAUJw=; b=ICs169inoE63OF7XBCBD2/T9gUaF+t89+Y9PtwtKycRLMs/mmNcD1qpB Z7e4gh3lFwwTbGGr8bWmAnb7WWKYhZDsz7KpPGx/OytNT6UTZwLFDGPYW zrMTTaVhBypqJnBNMzXFjotm08WfBxWgOzAU7+WaPZGvoAcEj9vNCkTcN 4IrPcjnHYG6Glrq66HoXflIR+pgn1KsSNTKpEJBb6ZgKk/8rBcfNtVkN3 n+U4uexGlvP1Ntxu7cYlZBnlKAhTArNrtNUFN2VRbTEi54c7zct74zFhB 3zbRWweL/9A8tEAed/0sFp/puacde5RxtmiS5URk0tU6oW2hKhYJ/4mu4 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10990"; a="2533262" X-IronPort-AV: E=Sophos;i="6.06,174,1705392000"; d="scan'208";a="2533262" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 18:29:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,174,1705392000"; d="scan'208";a="5333435" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.93.18.46]) ([10.93.18.46]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 18:29:18 -0800 Message-ID: Date: Wed, 21 Feb 2024 10:29:15 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v5 03/29] KVM: selftests: Store initial stack address in struct kvm_vcpu To: Sagi Shahar Cc: linux-kselftest@vger.kernel.org, Ackerley Tng , Ryan Afranji , Erdem Aktas , Isaku Yamahata , Sean Christopherson , Paolo Bonzini , Shuah Khan , Peter Gonda , Haibo Xu , Chao Peng , Vishal Annapurve , Roger Wang , Vipin Sharma , jmattson@google.com, dmatlack@google.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org References: <20231212204647.2170650-1-sagis@google.com> <20231212204647.2170650-4-sagis@google.com> From: Binbin Wu In-Reply-To: <20231212204647.2170650-4-sagis@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/13/2023 4:46 AM, Sagi Shahar wrote: > From: Ackerley Tng > > TDX guests' registers cannot be initialized directly using > vcpu_regs_set(), hence the stack pointer needs to be initialized by > the guest itself, running boot code beginning at the reset vector. > > We store the stack address as part of struct kvm_vcpu so that it can > be accessible later to be passed to the boot code for rsp > initialization. > > Signed-off-by: Ackerley Tng > Signed-off-by: Ryan Afranji > Signed-off-by: Sagi Shahar > --- > tools/testing/selftests/kvm/include/kvm_util_base.h | 1 + > tools/testing/selftests/kvm/lib/x86_64/processor.c | 4 +++- > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h > index c2e5c5f25dfc..b353617fcdd1 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util_base.h > +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h > @@ -68,6 +68,7 @@ struct kvm_vcpu { > int fd; > struct kvm_vm *vm; > struct kvm_run *run; > + vm_vaddr_t initial_stack_addr; > #ifdef __x86_64__ > struct kvm_cpuid2 *cpuid; > #endif > diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c > index f130f78a4974..b6b9438e0a33 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c > @@ -621,10 +621,12 @@ struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id, > vcpu_init_cpuid(vcpu, kvm_get_supported_cpuid()); > vcpu_setup(vm, vcpu); > > + vcpu->initial_stack_addr = stack_vaddr; > + > /* Setup guest general purpose registers */ > vcpu_regs_get(vcpu, ®s); > regs.rflags = regs.rflags | 0x2; > - regs.rsp = stack_vaddr; > + regs.rsp = vcpu->initial_stack_addr; Nit: No need to do this change. Reviewed-by: Binbin Wu > regs.rip = (unsigned long) guest_code; > vcpu_regs_set(vcpu, ®s); >