Re: [PATCH v10 049/108] KVM: x86/tdp_mmu: Support TDX private mapping for TDP MMU

Isaku Yamahata
2022-11-17T19:27:01Z

On Wed, Nov 16, 2022 at 09:40:38AM +0800,
Chenyi Qiang <chenyi.qiang@intel.com> wrote:

> > +static int __must_check handle_changed_private_spte(struct kvm *kvm, gfn_t gfn,
> > + u64 old_spte, u64 new_spte,
> > + int level)
> > +{
> > + bool was_present = is_shadow_present_pte(old_spte);
> > + bool is_present = is_shadow_present_pte(new_spte);
> > + bool was_leaf = was_present && is_last_spte(old_spte, level);
> > + bool is_leaf = is_present && is_last_spte(new_spte, level);
> > + kvm_pfn_t old_pfn = spte_to_pfn(old_spte);
> > + kvm_pfn_t new_pfn = spte_to_pfn(new_spte);
> > + int ret;
>
> int ret = 0;
>
> > +
> > + lockdep_assert_held(&kvm->mmu_lock);
> > + if (is_present) {
> > + /* TDP MMU doesn't change present -> present */
> > + KVM_BUG_ON(was_present, kvm);
> > +
> > + /*
> > + * Use different call to either set up middle level
> > + * private page table, or leaf.
> > + */
> > + if (is_leaf)
> > + ret = static_call(kvm_x86_set_private_spte)(kvm, gfn, level, new_pfn);
> > + else {
> > + void *private_spt = get_private_spt(gfn, new_spte, level);
> > +
> > + KVM_BUG_ON(!private_spt, kvm);
> > + ret = static_call(kvm_x86_link_private_spt)(kvm, gfn, level, private_spt);
> > + }
> > + } else if (was_leaf) {
> > + /* non-present -> non-present doesn't make sense. */
> > + KVM_BUG_ON(!was_present, kvm);
> > + /*
> > + * Zap private leaf SPTE. Zapping private table is done
> > + * below in handle_removed_tdp_mmu_page().
> > + */
> > + lockdep_assert_held_write(&kvm->mmu_lock);
> > + ret = static_call(kvm_x86_zap_private_spte)(kvm, gfn, level);
> > + if (!ret) {
> > + ret = static_call(kvm_x86_remove_private_spte)(kvm, gfn, level, old_pfn);
> > + WARN_ON_ONCE(ret);
> > + }
> > + }
>
> Otherwise, "ret" may be returned without initialization. Then it will
> trigger the WARN_ON_ONCE(ret) after handle_changed_spte() in patch 48.

Thanks for catching it. Compiler didn't complain it. Maybe W=1 is needed.
--
Isaku Yamahata <isaku.yamahata@gmail.com>