[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200323215844.GS127076@xz-x1>
Date: Mon, 23 Mar 2020 17:58:44 -0400
From: Peter Xu <peterx@...hat.com>
To: Sean Christopherson <sean.j.christopherson@...el.com>
Cc: Christian Borntraeger <borntraeger@...ibm.com>,
Janosch Frank <frankja@...ux.ibm.com>,
Paolo Bonzini <pbonzini@...hat.com>,
David Hildenbrand <david@...hat.com>,
Cornelia Huck <cohuck@...hat.com>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, Qian Cai <cai@....pw>
Subject: Re: [PATCH 7/7] KVM: selftests: Add "delete" testcase to
set_memory_region_test
On Mon, Mar 23, 2020 at 02:43:18PM -0700, Sean Christopherson wrote:
> 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.
I think ucall should work for pthread (shared address space of either
kvm_run or guest memories), however my thought was even simpler than
that, something like:
- in guest code: do GUEST_SYNC after each GUEST_ASSERT
- introduce a global_sem
- in vcpu thread: when receive GUEST_SYNC, do "sem_post(&global_sem)"
- in main thread: replace all usleep() with "sem_wait(&global_sem)"
--
Peter Xu
Powered by blists - more mailing lists