[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YYRhsclZpZwilkE5@google.com>
Date: Thu, 4 Nov 2021 22:41:53 +0000
From: Sean Christopherson <seanjc@...gle.com>
To: Ben Gardon <bgardon@...gle.com>
Cc: Marc Zyngier <maz@...nel.org>, Huacai Chen <chenhuacai@...nel.org>,
Aleksandar Markovic <aleksandar.qemu.devel@...il.com>,
Paul Mackerras <paulus@...abs.org>,
Anup Patel <anup.patel@....com>,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
Christian Borntraeger <borntraeger@...ibm.com>,
Janosch Frank <frankja@...ux.ibm.com>,
Paolo Bonzini <pbonzini@...hat.com>,
James Morse <james.morse@....com>,
Alexandru Elisei <alexandru.elisei@....com>,
Suzuki K Poulose <suzuki.poulose@....com>,
Atish Patra <atish.patra@....com>,
David Hildenbrand <david@...hat.com>,
Cornelia Huck <cohuck@...hat.com>,
Claudio Imbrenda <imbrenda@...ux.ibm.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>,
linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.cs.columbia.edu,
linux-mips@...r.kernel.org, kvm@...r.kernel.org,
kvm-ppc@...r.kernel.org, kvm-riscv@...ts.infradead.org,
linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org,
"Maciej S . Szmigiero" <maciej.szmigiero@...cle.com>
Subject: Re: [PATCH v5.5 01/30] KVM: Ensure local memslot copies operate on
up-to-date arch-specific data
On Thu, Nov 04, 2021, Ben Gardon wrote:
> > @@ -1597,6 +1596,26 @@ static int kvm_set_memslot(struct kvm *kvm,
> > kvm_copy_memslots(slots, __kvm_memslots(kvm, as_id));
> > }
> >
> > + /*
> > + * Make a full copy of the old memslot, the pointer will become stale
> > + * when the memslots are re-sorted by update_memslots(), and the old
> > + * memslot needs to be referenced after calling update_memslots(), e.g.
> > + * to free its resources and for arch specific behavior. This needs to
> > + * happen *after* (re)acquiring slots_arch_lock.
> > + */
> > + slot = id_to_memslot(slots, new->id);
> > + if (slot) {
> > + old = *slot;
> > + } else {
> > + WARN_ON_ONCE(change != KVM_MR_CREATE);
> > + memset(&old, 0, sizeof(old));
> > + old.id = new->id;
> > + old.as_id = as_id;
> > + }
> > +
> > + /* Copy the arch-specific data, again after (re)acquiring slots_arch_lock. */
> > + memcpy(&new->arch, &old.arch, sizeof(old.arch));
> > +
>
> Is new->arch not initialized before this function is called? Does this
> need to be here, or could it be moved above into the first branch of
> the if statement?
> Oh I see you removed the memset below and replaced it with this. I
> think this is fine, but it might be easier to reason about if we left
> the memset and moved the memcopy into the if.
> No point in doing a memcpy of zeros here.
Hmm, good point. I wrote it like this so that the "arch" part is more identifiable
since that's what needs to be protected by the lock, but I completely agree that
it's odd when viewed without that lens.
Powered by blists - more mailing lists