lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABgObfbzjLtzFX9wC_FU2GKGF_Wq8og+O=pSnG_yD8j1Dn3jAg@mail.gmail.com>
Date: Fri, 7 Jun 2024 10:46:15 +0200
From: Paolo Bonzini <pbonzini@...hat.com>
To: Rick Edgecombe <rick.p.edgecombe@...el.com>
Cc: seanjc@...gle.com, kvm@...r.kernel.org, kai.huang@...el.com, 
	dmatlack@...gle.com, erdemaktas@...gle.com, isaku.yamahata@...il.com, 
	linux-kernel@...r.kernel.org, sagis@...gle.com, yan.y.zhao@...el.com, 
	Isaku Yamahata <isaku.yamahata@...el.com>
Subject: Re: [PATCH v2 09/15] KVM: x86/tdp_mmu: Support mirror root for TDP MMU

On Thu, May 30, 2024 at 11:07 PM Rick Edgecombe
<rick.p.edgecombe@...el.com> wrote:
> +static inline bool kvm_on_mirror(const struct kvm *kvm, enum kvm_process process)
> +{
> +       if (!kvm_has_mirrored_tdp(kvm))
> +               return false;
> +
> +       return process & KVM_PROCESS_PRIVATE;
> +}
> +
> +static inline bool kvm_on_direct(const struct kvm *kvm, enum kvm_process process)
> +{
> +       if (!kvm_has_mirrored_tdp(kvm))
> +               return true;
> +
> +       return process & KVM_PROCESS_SHARED;
> +}

These helpers don't add much, it's easier to just write
kvm_process_to_root_types() as

if (process & KVM_PROCESS_SHARED)
  ret |= KVM_DIRECT_ROOTS;
if (process & KVM_PROCESS_PRIVATE)
  ret |= kvm_has_mirror_tdp(kvm) ? KVM_MIRROR_ROOTS : KVM_DIRECT_ROOTS;

WARN_ON_ONCE(!ret);
return ret;

(Here I chose to rename kvm_has_mirrored_tdp to kvm_has_mirror_tdp;
but if you prefer to call it kvm_has_external_tdp, it's just as
readable. Whatever floats your boat).

>         struct kvm *kvm = vcpu->kvm;
> -       struct kvm_mmu_page *root = root_to_sp(vcpu->arch.mmu->root.hpa);
> +       enum kvm_tdp_mmu_root_types root_type = tdp_mmu_get_fault_root_type(kvm, fault);
> +       struct kvm_mmu_page *root = tdp_mmu_get_root(vcpu, root_type);

Please make this

  struct kvm_mmu_page *root = tdp_mmu_get_root_for_fault(vcpu, fault);

Most other uses of tdp_mmu_get_root() don't really need a root_type,
I'll get to them in the reviews for the rest of the series.

>  enum kvm_tdp_mmu_root_types {
>         KVM_VALID_ROOTS = BIT(0),
> +       KVM_DIRECT_ROOTS = BIT(1),
> +       KVM_MIRROR_ROOTS = BIT(2),
>
> -       KVM_ANY_ROOTS = 0,
> -       KVM_ANY_VALID_ROOTS = KVM_VALID_ROOTS,
> +       KVM_ANY_ROOTS = KVM_DIRECT_ROOTS | KVM_MIRROR_ROOTS,
> +       KVM_ANY_VALID_ROOTS = KVM_DIRECT_ROOTS | KVM_MIRROR_ROOTS | KVM_VALID_ROOTS,

See previous review.

> +static inline enum kvm_tdp_mmu_root_types tdp_mmu_get_fault_root_type(struct kvm *kvm,
> +                                                                     struct kvm_page_fault *fault)
> +{
> +       if (fault->is_private)
> +               return kvm_process_to_root_types(kvm, KVM_PROCESS_PRIVATE);
> +       return KVM_DIRECT_ROOTS;
> +}
> +
> +static inline struct kvm_mmu_page *tdp_mmu_get_root(struct kvm_vcpu *vcpu, enum kvm_tdp_mmu_root_types type)
> +{
> +       if (type == KVM_MIRROR_ROOTS)
> +               return root_to_sp(vcpu->arch.mmu->mirror_root_hpa);
> +       return root_to_sp(vcpu->arch.mmu->root.hpa);
> +}

static inline struct kvm_mmu_page *
tdp_mmu_get_root_for_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
{
  hpa_t root_hpa;
  if (unlikely(fault->is_private && kvm_has_mirror_tdp(kvm)))
    root_hpa = vcpu->arch.mmu->mirror_root_hpa;
  else
    root_hpa = vcpu->arch.mmu->root.hpa;
  return root_to_sp(root_hpa);
}

Paolo


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ