public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Chenyi Qiang <chenyi.qiang@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	<linux-kernel@vger.kernel.org>, <kvm@vger.kernel.org>
Cc: <seanjc@google.com>, Yan Zhao <yan.y.zhao@intel.com>,
	Rick Edgecombe <rick.p.edgecombe@intel.com>,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	Isaku Yamahata <isaku.yamahata@intel.com>,
	Kai Huang <kai.huang@intel.com>,
	Binbin Wu <binbin.wu@linux.intel.com>,
	"Yuan Yao" <yuan.yao@intel.com>,
	Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [PATCH 07/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX page cache management
Date: Mon, 3 Mar 2025 08:22:29 +0800	[thread overview]
Message-ID: <8a86c242-1761-4d2b-b2f2-4a009c2ba766@intel.com> (raw)
In-Reply-To: <20250226181453.2311849-8-pbonzini@redhat.com>



On 2/27/2025 2:14 AM, Paolo Bonzini wrote:
> From: Rick Edgecombe <rick.p.edgecombe@intel.com>
> 
> Intel TDX protects guest VMs from malicious host and certain physical
> attacks. The TDX module uses pages provided by the host for both control
> structures and for TD guest pages. These pages are encrypted using the
> MK-TME encryption engine, with its special requirements around cache
> invalidation. For its own security, the TDX module ensures pages are
> flushed properly and track which usage they are currently assigned. For
> creating and tearing down TD VMs and vCPUs KVM will need to use the
> TDH.PHYMEM.PAGE.RECLAIM, TDH.PHYMEM.CACHE.WB, and TDH.PHYMEM.PAGE.WBINVD
> SEAMCALLs.
> 
> Add tdh_phymem_page_reclaim() to enable KVM to call
> TDH.PHYMEM.PAGE.RECLAIM to reclaim the page for use by the host kernel.
> This effectively resets its state in the TDX module's page tracking
> (PAMT), if the page is available to be reclaimed. This will be used by KVM
> to reclaim the various types of pages owned by the TDX module. It will
> have a small wrapper in KVM that retries in the case of a relevant error
> code. Don't implement this wrapper in arch/x86 because KVM's solution
> around retrying SEAMCALLs will be better located in a single place.
> 
> Add tdh_phymem_cache_wb() to enable KVM to call TDH.PHYMEM.CACHE.WB to do
> a cache write back in a way that the TDX module can verify, before it
> allows a KeyID to be freed. The KVM code will use this to have a small
> wrapper that handles retries. Since the TDH.PHYMEM.CACHE.WB operation is
> interruptible, have tdh_phymem_cache_wb() take a resume argument to pass
> this info to the TDX module for restarts. It is worth noting that this
> SEAMCALL uses a SEAM specific MSR to do the write back in sections. In
> this way it does export some new functionality that affects CPU state.
> 
> Add tdh_phymem_page_wbinvd_tdr() to enable KVM to call
> TDH.PHYMEM.PAGE.WBINVD to do a cache write back and invalidate of a TDR,
> using the global KeyID. The underlying TDH.PHYMEM.PAGE.WBINVD SEAMCALL
> requires the related KeyID to be encoded into the SEAMCALL args. Since the
> global KeyID is not exposed to KVM, a dedicated wrapper is needed for TDR
> focused TDH.PHYMEM.PAGE.WBINVD operations.
> 
> Co-developed-by: Sean Christopherson <sean.j.christopherson@intel.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
> Signed-off-by: Kai Huang <kai.huang@intel.com>
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
> Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
> Reviewed-by: Yuan Yao <yuan.yao@intel.com>
> Message-ID: <20241203010317.827803-5-rick.p.edgecombe@intel.com>
> Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/include/asm/tdx.h  | 17 +++++++++++++++
>  arch/x86/virt/vmx/tdx/tdx.c | 42 +++++++++++++++++++++++++++++++++++++
>  arch/x86/virt/vmx/tdx/tdx.h |  3 +++
>  3 files changed, 62 insertions(+)
> 
> diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
> index f783d5f1a0e1..ea26d79ec9d9 100644
> --- a/arch/x86/include/asm/tdx.h
> +++ b/arch/x86/include/asm/tdx.h
> @@ -33,6 +33,7 @@
>  #ifndef __ASSEMBLY__
>  
>  #include <uapi/asm/mce.h>
> +#include <linux/pgtable.h>
>  
>  /*
>   * Used by the #VE exception handler to gather the #VE exception
> @@ -140,6 +141,19 @@ struct tdx_vp {
>  	struct page **tdcx_pages;
>  };
>  
> +
> +static inline u64 mk_keyed_paddr(u16 hkid, struct page *page)
> +{
> +	u64 ret;
> +
> +	ret = page_to_phys(page);

We did "make allyesconfig" build test, and see the build error:

./arch/x86/include/asm/tdx.h: In function ‘mk_keyed_paddr’:
    ./include/asm-generic/memory_model.h:72:23: error: implicit
declaration of function ‘pfn_valid’ [-Werror=implicit-function-declaration]
       72 |         WARN_ON_ONCE(!pfn_valid(__pfn));
           \
          |                       ^~~~~~~~~
    ./include/asm-generic/bug.h:111:32: note: in definition of macro
‘WARN_ON_ONCE’
      111 |         int __ret_warn_on = !!(condition);
   \
          |                                ^~~~~~~~~
    ./arch/x86/include/asm/tdx.h:155:15: note: in expansion of macro
‘page_to_phys’
      155 |         ret = page_to_phys(page);
          |               ^~~~~~~~~~~~

Maybe add the fix:

diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
index 847252f520df..428243384696 100644
--- a/arch/x86/include/asm/tdx.h
+++ b/arch/x86/include/asm/tdx.h
@@ -5,6 +5,7 @@

 #include <linux/init.h>
 #include <linux/bits.h>
+#include <linux/mmzone.h>

 #include <asm/errno.h>
 #include <asm/ptrace.h>


> +	/* KeyID bits are just above the physical address bits: */
> +	ret |= (u64)hkid << boot_cpu_data.x86_phys_bits;
> +
> +	return ret;
> +
> +}



  reply	other threads:[~2025-03-03  0:22 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-26 18:14 [PATCH v4 00/33] TDX initialization + vCPU/VM creation Paolo Bonzini
2025-02-26 18:14 ` [PATCH 01/33] KVM: x86: Free vCPUs before freeing VM state Paolo Bonzini
2025-02-26 18:14 ` [PATCH 02/33] KVM: x86: move vm_destroy callback at end of kvm_arch_destroy_vm Paolo Bonzini
2025-02-26 18:14 ` [PATCH 03/33] KVM: x86: Don't load/put vCPU when unloading its MMU during teardown Paolo Bonzini
2025-02-26 18:14 ` [PATCH 04/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX KeyID management Paolo Bonzini
2025-02-26 18:14 ` [PATCH 05/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX TD creation Paolo Bonzini
2025-02-26 18:14 ` [PATCH 06/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX vCPU creation Paolo Bonzini
2025-02-26 18:14 ` [PATCH 07/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX page cache management Paolo Bonzini
2025-03-03  0:22   ` Chenyi Qiang [this message]
2025-02-26 18:14 ` [PATCH 08/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX VM/vCPU field access Paolo Bonzini
2025-02-26 18:14 ` [PATCH 09/33] x86/virt/tdx: Add SEAMCALL wrappers for TDX flush operations Paolo Bonzini
2025-02-26 18:14 ` [PATCH 10/33] x86/virt/tdx: allocate tdx_sys_info in static memory Paolo Bonzini
2025-02-26 18:14 ` [PATCH 11/33] x86/virt/tdx: Read essential global metadata for KVM Paolo Bonzini
2025-02-26 18:14 ` [PATCH 12/33] x86/virt/tdx: Add tdx_guest_keyid_alloc/free() to alloc and free TDX guest KeyID Paolo Bonzini
2025-02-26 18:14 ` [PATCH 13/33] KVM: Export hardware virtualization enabling/disabling functions Paolo Bonzini
2025-02-26 18:14 ` [PATCH 14/33] KVM: VMX: Refactor VMX module init/exit functions Paolo Bonzini
2025-02-26 18:14 ` [PATCH 15/33] KVM: VMX: Initialize TDX during KVM module load Paolo Bonzini
2025-02-26 18:14 ` [PATCH 16/33] KVM: TDX: Get TDX global information Paolo Bonzini
2025-02-26 18:14 ` [PATCH 17/33] KVM: TDX: Add placeholders for TDX VM/vCPU structures Paolo Bonzini
2025-02-26 18:14 ` [PATCH 18/33] KVM: TDX: Define TDX architectural definitions Paolo Bonzini
2025-02-26 18:14 ` [PATCH 19/33] KVM: TDX: Add TDX "architectural" error codes Paolo Bonzini
2025-02-26 18:14 ` [PATCH 20/33] KVM: TDX: Add helper functions to print TDX SEAMCALL error Paolo Bonzini
2025-02-26 18:14 ` [PATCH 21/33] KVM: TDX: Add place holder for TDX VM specific mem_enc_op ioctl Paolo Bonzini
2025-02-26 18:14 ` [PATCH 22/33] KVM: TDX: Get system-wide info about TDX module on initialization Paolo Bonzini
2025-02-26 18:14 ` [PATCH 23/33] KVM: TDX: create/destroy VM structure Paolo Bonzini
2025-06-25 15:46   ` Dave Hansen
2025-06-25 16:12     ` Sean Christopherson
2025-02-26 18:14 ` [PATCH 24/33] KVM: TDX: Support per-VM KVM_CAP_MAX_VCPUS extension check Paolo Bonzini
2025-02-26 18:14 ` [PATCH 25/33] KVM: x86: expose cpuid_entry2_find for TDX Paolo Bonzini
2025-02-26 22:03   ` Huang, Kai
2025-02-26 18:14 ` [PATCH 26/33] KVM: TDX: add ioctl to initialize VM with TDX specific parameters Paolo Bonzini
2025-02-26 18:14 ` [PATCH 27/33] KVM: TDX: Make pmu_intel.c ignore guest TD case Paolo Bonzini
2025-02-26 18:14 ` [PATCH 28/33] KVM: TDX: Don't offline the last cpu of one package when there's TDX guest Paolo Bonzini
2025-02-26 18:14 ` [PATCH 29/33] KVM: TDX: create/free TDX vcpu structure Paolo Bonzini
2025-02-26 18:14 ` [PATCH 30/33] KVM: TDX: Do TDX specific vcpu initialization Paolo Bonzini
2025-02-26 18:14 ` [PATCH 31/33] KVM: x86: Introduce KVM_TDX_GET_CPUID Paolo Bonzini
2025-02-26 18:14 ` [PATCH 32/33] KVM: x86/mmu: Taking guest pa into consideration when calculate tdp level Paolo Bonzini
2025-02-26 18:14 ` [PATCH 33/33] KVM: TDX: Register TDX host key IDs to cgroup misc controller Paolo Bonzini
2025-02-28  1:56   ` Chenyi Qiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8a86c242-1761-4d2b-b2f2-4a009c2ba766@intel.com \
    --to=chenyi.qiang@intel.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=seanjc@google.com \
    --cc=yan.y.zhao@intel.com \
    --cc=yuan.yao@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox