Re: [PATCH 7/7] KVM: selftests: Add "delete" testcase to set_memory_region_test
From: Sean Christopherson
Date: Mon Mar 23 2020 - 17:43:20 EST
On Mon, Mar 23, 2020 at 03:06:36PM -0400, Peter Xu wrote:
> On Fri, Mar 20, 2020 at 01:55:46PM -0700, Sean Christopherson wrote:
> > + /*
> > + * Spin until the memory region is moved to a misaligned address. This
> > + * may or may not trigger MMIO, as the window where the memslot is
> > + * invalid is quite small.
> > + */
> > + val = guest_spin_on_val(0);
> > + GUEST_ASSERT(val == 1 || val == MMIO_VAL);
> > +
> > + /* Spin until the memory region is realigned. */
> > + GUEST_ASSERT(guest_spin_on_val(MMIO_VAL) == 1);
>
> IIUC ideally we should do GUEST_SYNC() after each GUEST_ASSERT() to
> make sure the two threads are in sync. Otherwise e.g. there's no
> guarantee that the main thread won't run too fast to quickly remove
> the memslot and re-add it back before the guest_spin_on_val() starts
> above, then the assert could trigger when it reads the value as zero.
Hrm, I was thinking ucall wasn't available across pthreads, but it's just
dumped into a global variable. I'll rework this to replace the udelay()
hacks with proper synchronization.