Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1507993rbb; Mon, 26 Feb 2024 11:27:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXk5QSVCjG1Gz82SfzJ9PffdZLs6QUonzG2MVPgCZnEeAppCp2ozSmdly1ixtVZsC161pIusj9/36h5x8rgcbFiFqKozdS0G8BQOBe9Hw== X-Google-Smtp-Source: AGHT+IE0FZjgym57Do9GGU51x0D5whw2o79H2QauG8bXKgsqm175H2WzhpOJBgmOYaW/JnvhzZdt X-Received: by 2002:a05:6a20:9c8f:b0:1a0:ecaa:e41e with SMTP id mj15-20020a056a209c8f00b001a0ecaae41emr123812pzb.17.1708975620793; Mon, 26 Feb 2024 11:27:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708975620; cv=pass; d=google.com; s=arc-20160816; b=cVGQTG+ffx315o0anTG5SDTkkCobQxynyDlYH6s1/L5EzcFoGRi2Vrlw9cYoYodRGO I6PfFvwS8F+Ce8ynakiUrei1x24JCO7BTyMlxLZqtbAwyXtBxJ39At+C6sZCgiT6NMs/ 6HMf463tAkfp1DnjxUHbkrpdVcZQ9t8G0OxEwGOCL5rwidwLV8Nx8tyHqdFhAVVPBbJL hLD4nVyfM+61sFt/1HPb/yuFQm2RlS9NUxPRfjzSXt72i2ouspkHAtEhiS/55dfrF6JW d6zhpmwLyO1ElCkTb6ivDxoijgwvjRgzHtthVassWpu9X1qwvkMf1RMxw7H1duGedxER QJqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3yN6bvb1VhFseLvKlC9gKKZ7z48Lyv4e1eWVzeoZO28=; fh=P2lTV/JBlyEW5lSM0t29UzW8wYPfOBFoUnCPKcC2ITo=; b=M6vSJURfEI7OycVO9ktPtkEnnu7lRn61gi2SBGFSo1Cghc1tR4g4Xll+xALRpaYQ2Y 2f2uN7xLRe9+iNNG6N5SOSyLzoGT3zWdfbbiDBe2Th6EaTDO+daMppMgG1OVsmnUqw/l Lzj4keb/M7vZxIWGkFk7sOz65H7sQ4JI5S+/NWfeVTsaK/qc4GJOzXlSx7jS8WJs6t6H S+6BQhqWPpm1oYZjgqTMh64yb5RnWnRA32djffEzFvBaflVvY+ERnRVdBTi/PDt361QK 6VYgkAu7AvzdHJhnRA1Hd+SZ6OBgFLsgALzEzjEGOiHwfApZ1SCrmVuBT0Yo150ceAOp C1QA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MYcOGbK9; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-82172-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82172-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y15-20020a056a00190f00b006e085b3c0e8si4187518pfi.236.2024.02.26.11.27.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 11:27:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82172-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MYcOGbK9; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-82172-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82172-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 22C93B2876D for ; Mon, 26 Feb 2024 18:57:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40D8B12FF7D; Mon, 26 Feb 2024 18:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MYcOGbK9" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 4939F12E1F0; Mon, 26 Feb 2024 18:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708973844; cv=none; b=atd/pWxk92SjifchLYzBZv5EKWhuBrejPOj2inmPqWvw7xXArTS0iIOcBZRI/sd84EiZHy1K0H5A2jRvueD4Q40gBIhCElXXnE4AqSEApx67YQP55+QKGCPL0PSnvUkLlNYo/u/HdPyHRmZ4UGtPLUC7WReoL48ou6X3bFE3NrA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708973844; c=relaxed/simple; bh=nJFSrLqJiwp8ithW3MjfceFdjdGmcRw4CXHZqvKmUPI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Xbs40pbK+T6hDFOch1V/eHKQxU0AbSHSIKERFqR6PfmB7H3KfRlzzNLRZMfPHa/lMgeyRiYjZBLdqHF5JvoiWVQeCuGjdr1UWlUsDQeDnW4FfMccvkD2aietctKqWaXdicbP3t8yDRNv2CeG8C8CIkCwbioPpqGUh4qTBDwmKTA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=MYcOGbK9; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708973842; x=1740509842; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=nJFSrLqJiwp8ithW3MjfceFdjdGmcRw4CXHZqvKmUPI=; b=MYcOGbK9YqBhGXmsRJWhkL3jfAoDx8HWo3zItdv4V2YLHyrVPIkHI6hN 9arFmG6e2ID10vC/3xKaxNMr3V+4ClFRd92V9lXB7fx1H9I5EEqvC3VxL IhtulB8UNdMjAycjQLdkPQIqBQgFlEnuzf8T56N0GGJp9NTks7WqXyc0+ It9tAKhi/E6m8DIQAj1en8Aeh4bvGauBIBIGYhMQsZxMOeH9nPiMXRRFv OACgzrSx8d4OQoKjIpyIJv0NnDHC67QYuKzuvXnT/4xkjpTxRB1Qr8Bgk HbkYLCMq6MkIriJBf6JqbXJg7ROtr2OglEA2DjJwntIZcG4qIE+XxNYeH w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="7107236" X-IronPort-AV: E=Sophos;i="6.06,186,1705392000"; d="scan'208";a="7107236" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 10:57:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,186,1705392000"; d="scan'208";a="6977793" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 10:57:21 -0800 Date: Mon, 26 Feb 2024 10:57:20 -0800 From: Isaku Yamahata To: Binbin Wu Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Xiaoyao Li , isaku.yamahata@linux.intel.com Subject: Re: [PATCH v18 025/121] KVM: TDX: initialize VM with TDX specific parameters Message-ID: <20240226185720.GK177224@ls.amr.corp.intel.com> References: <6e517d2e-45ae-46ec-8067-c3e7eb1b2afa@linux.intel.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=utf-8 Content-Disposition: inline In-Reply-To: <6e517d2e-45ae-46ec-8067-c3e7eb1b2afa@linux.intel.com> On Thu, Jan 25, 2024 at 10:19:30AM +0800, Binbin Wu wrote: > > > On 1/23/2024 7:53 AM, isaku.yamahata@intel.com wrote: > > From: Isaku Yamahata > > > > TDX requires additional parameters for TDX VM for confidential execution to > > protect the confidentiality of its memory contents and CPU state from any > > other software, including VMM. When creating a guest TD VM before creating > > vcpu, the number of vcpu, TSC frequency (the values are the same among > > vcpus, and it can't change.) CPUIDs which the TDX module emulates. Guest > > TDs can trust those CPUIDs and sha384 values for measurement. > > > > Add a new subcommand, KVM_TDX_INIT_VM, to pass parameters for the TDX > > guest. It assigns an encryption key to the TDX guest for memory > > encryption. TDX encrypts memory per guest basis. The device model, say > > qemu, passes per-VM parameters for the TDX guest. The maximum number of > > vcpus, TSC frequency (TDX guest has fixed VM-wide TSC frequency, not per > > vcpu. The TDX guest can not change it.), attributes (production or debug), > > available extended features (which configure guest XCR0, IA32_XSS MSR), > > CPUIDs, sha384 measurements, etc. > > > > Call this subcommand before creating vcpu and KVM_SET_CPUID2, i.e. CPUID > > configurations aren't available yet. So CPUIDs configuration values need > > to be passed in struct kvm_tdx_init_vm. The device model's responsibility > > to make this CPUID config for KVM_TDX_INIT_VM and KVM_SET_CPUID2. > > > > Signed-off-by: Xiaoyao Li > > Signed-off-by: Isaku Yamahata > > > > --- > > v18: > > - remove the change of tools/arch/x86/include/uapi/asm/kvm.h > > - typo in comment. sha348 => sha384 > > - updated comment in setup_tdparams_xfam() > > - fix setup_tdparams_xfam() to use init_vm instead of td_params > > > > v15 -> v16: > > - Removed AMX check as the KVM upstream supports AMX. > > - Added CET flag to guest supported xss > > > > v14 -> v15: > > - add check if the reserved area of init_vm is zero > > --- > > arch/x86/include/uapi/asm/kvm.h | 27 ++++ > > arch/x86/kvm/cpuid.c | 7 + > > arch/x86/kvm/cpuid.h | 2 + > > arch/x86/kvm/vmx/tdx.c | 261 ++++++++++++++++++++++++++++++-- > > arch/x86/kvm/vmx/tdx.h | 18 +++ > > arch/x86/kvm/vmx/tdx_arch.h | 6 + > > 6 files changed, 311 insertions(+), 10 deletions(-) > > > [...] > > + > > +static int setup_tdparams_xfam(struct kvm_cpuid2 *cpuid, struct td_params *td_params) > > +{ > > + const struct kvm_cpuid_entry2 *entry; > > + u64 guest_supported_xcr0; > > + u64 guest_supported_xss; > > + > > + /* Setup td_params.xfam */ > > + entry = kvm_find_cpuid_entry2(cpuid->entries, cpuid->nent, 0xd, 0); > > + if (entry) > > + guest_supported_xcr0 = (entry->eax | ((u64)entry->edx << 32)); > > + else > > + guest_supported_xcr0 = 0; > > + guest_supported_xcr0 &= kvm_caps.supported_xcr0; > > + > > + entry = kvm_find_cpuid_entry2(cpuid->entries, cpuid->nent, 0xd, 1); > > + if (entry) > > + guest_supported_xss = (entry->ecx | ((u64)entry->edx << 32)); > > + else > > + guest_supported_xss = 0; > > + > > + /* > > + * PT can be exposed to TD guest regardless of KVM's XSS and CET > > + * support. > > + */ > According to the code below, it seems that both PT and CET can be exposed to > TD > guest regardless of KVM's XSS support? Yes, updated the comment. > > + guest_supported_xss &= > > + (kvm_caps.supported_xss | XFEATURE_MASK_PT | TDX_TD_XFAM_CET); > > + > > + td_params->xfam = guest_supported_xcr0 | guest_supported_xss; > > + if (td_params->xfam & XFEATURE_MASK_LBR) { > > + /* > > + * TODO: once KVM supports LBR(save/restore LBR related > > + * registers around TDENTER), remove this guard. > > + */ > > +#define MSG_LBR "TD doesn't support LBR yet. KVM needs to save/restore IA32_LBR_DEPTH properly.\n" > > + pr_warn(MSG_LBR); > > + return -EOPNOTSUPP; > > + } > > + > > + return 0; > > +} > > + > > +static int setup_tdparams(struct kvm *kvm, struct td_params *td_params, > > + struct kvm_tdx_init_vm *init_vm) > > +{ > > + struct kvm_cpuid2 *cpuid = &init_vm->cpuid; > > + int ret; > > + > > + if (kvm->created_vcpus) > > + return -EBUSY; > > + > > + if (init_vm->attributes & TDX_TD_ATTRIBUTE_PERFMON) { > > + /* > > + * TODO: save/restore PMU related registers around TDENTER. > > + * Once it's done, remove this guard. > > + */ > > +#define MSG_PERFMON "TD doesn't support perfmon yet. KVM needs to save/restore host perf registers properly.\n" > > + pr_warn(MSG_PERFMON); > > + return -EOPNOTSUPP; > > + } > > + > > + td_params->max_vcpus = kvm->max_vcpus; > Can the max vcpu number be passed by KVM_TDX_INIT_VM? > So that no need to add KVM_CAP_MAX_VCPUS in patch 23/121. Please see the comment there. -- Isaku Yamahata