Re: [PATCH 04/16] KVM: arm64: Add MMIO checking infrastructure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 30 Jul 2021 13:26:59 +0100,
Will Deacon <will@xxxxxxxxxx> wrote:
> 
> On Wed, Jul 28, 2021 at 10:57:30AM +0100, Marc Zyngier wrote:
> > On Tue, 27 Jul 2021 19:11:08 +0100,
> > Will Deacon <will@xxxxxxxxxx> wrote:
> > > On Thu, Jul 15, 2021 at 05:31:47PM +0100, Marc Zyngier wrote:
> > > > +bool kvm_install_ioguard_page(struct kvm_vcpu *vcpu, gpa_t ipa)
> > > > +{
> > > > +	struct kvm_mmu_memory_cache *memcache;
> > > > +	struct kvm_memory_slot *memslot;
> > > > +	int ret, idx;
> > > > +
> > > > +	if (!test_bit(KVM_ARCH_FLAG_MMIO_GUARD, &vcpu->kvm->arch.flags))
> > > > +		return false;
> > > > +
> > > > +	/* Must be page-aligned */
> > > > +	if (ipa & ~PAGE_MASK)
> > > > +		return false;
> > > > +
> > > > +	/*
> > > > +	 * The page cannot be in a memslot. At some point, this will
> > > > +	 * have to deal with device mappings though.
> > > > +	 */
> > > > +	idx = srcu_read_lock(&vcpu->kvm->srcu);
> > > > +	memslot = gfn_to_memslot(vcpu->kvm, ipa >> PAGE_SHIFT);
> > > > +	srcu_read_unlock(&vcpu->kvm->srcu, idx);
> > > 
> > > What does this memslot check achieve? A new memslot could be added after
> > > you've checked, no?
> > 
> > If you start allowing S2 annotations to coexist with potential memory
> > mappings, you're in for trouble. The faulting logic will happily
> > overwrite the annotation, and that's probably not what you want.
> 
> I don't disagree, but the check above appears to be racy.

Yup, the srcu_read_unlock() should be moved at the end of this
function. It's rather silly as it is currently written...

> 
> > As for new (or moving) memslots, I guess they should be checked
> > against existing annotations.
> 
> Something like that, but the devil is in the details as it will need to
> synchronize with this check somehow.

The SRCU read lock should protect us against memslots being removed
whilst we're accessing it. In a way, this is no different from taking
a page fault.

For new memslots, it is a lot less clear. There are multiple levels of
locking, more or less documented... It feels like slots_arch_lock is
the right tool for this job, but I need to page all that stuff in...

	M.

-- 
Without deviation from the norm, progress is not possible.



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux