2023-11-16 08:57:54

by Binbin Wu

[permalink] [raw]
Subject: Re: [PATCH v6 04/16] KVM: TDX: Pass size to tdx_measure_page()



On 11/7/2023 11:00 PM, [email protected] wrote:
> From: Xiaoyao Li <[email protected]>
>
> Extend tdx_measure_page() to pass size info so that it can measure
> large page as well.
>
> Signed-off-by: Xiaoyao Li <[email protected]>
> Signed-off-by: Isaku Yamahata <[email protected]>
> ---
> arch/x86/kvm/vmx/tdx.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> index 2d5c86e06c5f..a728175c4a6d 100644
> --- a/arch/x86/kvm/vmx/tdx.c
> +++ b/arch/x86/kvm/vmx/tdx.c
> @@ -1434,13 +1434,15 @@ void tdx_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa, int pgd_level)
> td_vmcs_write64(to_tdx(vcpu), SHARED_EPT_POINTER, root_hpa & PAGE_MASK);
> }
>
> -static void tdx_measure_page(struct kvm_tdx *kvm_tdx, hpa_t gpa)
> +static void tdx_measure_page(struct kvm_tdx *kvm_tdx, hpa_t gpa, int size)
IMHO, it's better to pass kvm page level instead of size here to align with
other APIs.

> {
> struct tdx_module_args out;
> u64 err;
> int i;
>
> - for (i = 0; i < PAGE_SIZE; i += TDX_EXTENDMR_CHUNKSIZE) {
> + WARN_ON_ONCE(size % TDX_EXTENDMR_CHUNKSIZE);

If passed level instead of size, then no need to check KVM_HPAGE_SIZE(level)
against TDX_EXTENDMR_CHUNKSIZE

But same qeustion, tdx_measure_page() is only for tdh_mem_page_add(), is
this
change necessary?

> +
> + for (i = 0; i < size; i += TDX_EXTENDMR_CHUNKSIZE) {
> err = tdh_mr_extend(kvm_tdx->tdr_pa, gpa + i, &out);
> if (KVM_BUG_ON(err, &kvm_tdx->kvm)) {
> pr_tdx_error(TDH_MR_EXTEND, err, &out);
> @@ -1544,7 +1546,7 @@ static int tdx_sept_page_add(struct kvm *kvm, gfn_t gfn,
> tdx_unpin(kvm, pfn);
> return -EIO;
> } else if (measure)
> - tdx_measure_page(kvm_tdx, gpa);
> + tdx_measure_page(kvm_tdx, gpa, KVM_HPAGE_SIZE(level));
>
> return 0;
>


2023-11-17 00:37:13

by Isaku Yamahata

[permalink] [raw]
Subject: Re: [PATCH v6 04/16] KVM: TDX: Pass size to tdx_measure_page()

On Thu, Nov 16, 2023 at 04:57:26PM +0800,
Binbin Wu <[email protected]> wrote:

>
>
> On 11/7/2023 11:00 PM, [email protected] wrote:
> > From: Xiaoyao Li <[email protected]>
> >
> > Extend tdx_measure_page() to pass size info so that it can measure
> > large page as well.
> >
> > Signed-off-by: Xiaoyao Li <[email protected]>
> > Signed-off-by: Isaku Yamahata <[email protected]>
> > ---
> > arch/x86/kvm/vmx/tdx.c | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> > index 2d5c86e06c5f..a728175c4a6d 100644
> > --- a/arch/x86/kvm/vmx/tdx.c
> > +++ b/arch/x86/kvm/vmx/tdx.c
> > @@ -1434,13 +1434,15 @@ void tdx_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa, int pgd_level)
> > td_vmcs_write64(to_tdx(vcpu), SHARED_EPT_POINTER, root_hpa & PAGE_MASK);
> > }
> > -static void tdx_measure_page(struct kvm_tdx *kvm_tdx, hpa_t gpa)
> > +static void tdx_measure_page(struct kvm_tdx *kvm_tdx, hpa_t gpa, int size)
> IMHO, it's better to pass kvm page level instead of size here to align with
> other APIs.
>
> > {
> > struct tdx_module_args out;
> > u64 err;
> > int i;
> > - for (i = 0; i < PAGE_SIZE; i += TDX_EXTENDMR_CHUNKSIZE) {
> > + WARN_ON_ONCE(size % TDX_EXTENDMR_CHUNKSIZE);
>
> If passed level instead of size, then no need to check KVM_HPAGE_SIZE(level)
> against TDX_EXTENDMR_CHUNKSIZE
>
> But same qeustion, tdx_measure_page() is only for tdh_mem_page_add(), is
> this
> change necessary?

You're right. As tdx_mem_page_add() is the only caller of tdx_measure_page(),
open-code it into tdx_mem_page_add() and drop this patch.
--
Isaku Yamahata <[email protected]>