From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, avi@redhat.com, borntraeger@de.ibm.com,
cotte@de.ibm.com, heiko.carstens@de.ibm.com,
schwidefsky@de.ibm.com
Subject: Re: [PATCH 3/3] kvm-s390: streamline memslot handling - rebased
Date: Mon, 08 Jun 2009 12:51:26 +0200 [thread overview]
Message-ID: <4A2CED2E.6030904@linux.vnet.ibm.com> (raw)
In-Reply-To: <20090605205312.GA13471@amt.cnet>
Marcelo Tosatti wrote:
> On Tue, Jun 02, 2009 at 04:26:11PM +0200, ehrhardt@linux.vnet.ibm.com wrote:
>
>> From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
>>
[...]
>> @@ -706,13 +713,19 @@ int kvm_arch_set_memory_region(struct kv
>>
>> /* request update of sie control block for all available vcpus */
>> for (i = 0; i < KVM_MAX_VCPUS; ++i) {
>> - if (kvm->vcpus[i]) {
>> - if (test_and_set_bit(KVM_REQ_MMU_RELOAD,
>> - &kvm->vcpus[i]->requests))
>> - continue;
>> - kvm_s390_inject_sigp_stop(kvm->vcpus[i],
>> - ACTION_VCPUREQUEST_ON_STOP);
>> - }
>> + vcpu = kvm->vcpus[i];
>> + if (!vcpu)
>> + continue;
>> +
>> + if (!test_and_set_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests))
>> + continue;
>> +
>> + if (vcpu->cpu == -1)
>> + continue;
>>
>
> What happens if the check for cpu == -1 races with kvm_arch_vcpu_put?
> This context will wait until the vcpu_put context is scheduled back in
> to clear the bit? Is that OK?
>
It either comes back to clear the bit or it is consumed on deletion of
the vcpu. Both ways are ok. The question we have to answer is if it
might stall the mem update ioctl for too long.
Because eventually the check for vcpu->cpu == -1 is just an optimization
if we would completely ignore remove it we would have the same problem
-> could it stall the set mem operation too much. That means the "race"
is not an issue it might just be sub-optimal, but the chance for a long
stall could become an issue. Unfortunately I have no better approach to
that (yet), until then this I like this implementation more than what we
would have without all the corner case fixes in that patch series.
>> +
>> + kvm_s390_inject_sigp_stop(vcpu, ACTION_VCPUREQUEST_ON_STOP);
>> + wait_on_bit(&vcpu->requests, KVM_REQ_MMU_RELOAD,
>> + wait_bit_schedule, TASK_UNINTERRUPTIBLE);
>> }
>>
>
> void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
> {
> + vcpu->cpu = -1;
> save_fp_regs(&vcpu->arch.guest_fpregs);
>
[...]
>> +++ kvm/arch/s390/kvm/kvm-s390.h
>> @@ -92,6 +92,13 @@ static inline unsigned long kvm_s390_han
>> if (!vcpu->requests)
>> return 0;
>>
>> + /* requests that can be handled at all levels */
>> + if (test_and_clear_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests)) {
>> + smp_mb__after_clear_bit();
>>
>
> Really need that smp_mb__after_clear_bit ? AFAIK test_and_clear_bit
> implies a barrier?
>
Well I agree that practically test_and_clear_bit has a barrier on s390,
but as far as I read Documentation/atomic_ops.txt at line 339-360 I
think the interface does not imply it so I wanted to add it explicitly.
I would be happy if someone really knows the in depth details here and
corrects me :-)
>> + wake_up_bit(&vcpu->requests, KVM_REQ_MMU_RELOAD);
>> + kvm_s390_vcpu_set_mem(vcpu);
>> + }
>> +
>> return vcpu->requests;
>> }
>>
>> Index: kvm/virt/kvm/kvm_main.c
>> ===================================================================
>> --- kvm.orig/virt/kvm/kvm_main.c
>> +++ kvm/virt/kvm/kvm_main.c
>> @@ -1682,6 +1682,10 @@ static int kvm_vcpu_release(struct inode
>> {
>> struct kvm_vcpu *vcpu = filp->private_data;
>>
>> + clear_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests);
>> + smp_mb__after_clear_bit();
>> + wake_up_bit(&vcpu->requests, KVM_REQ_MMU_RELOAD);
>> +
>>
>
> And this should be generic? Say if other architectures want to make use
> of a similar wait infrastructure. Talk is cheap.
>
Clear bit and wake up on release doesn't hurt any architecture, but it
is at a good place fine for those using the mechanism to ensure cleaning
up outstanding things when closing a vcpu fd.
I thought its not worth to add kvm_ARCH_vcpu_release for it while I
could do so if we want it separated.
(continued below)
> Anyway, yeah, the set request / wait mechanism you implement here is
> quite similar to the idea mentioned earlier that could be used for x86.
>
> Just get rid of this explicit KVM_REQ_MMU_RELOAD knowledge in
> arch-independent code please (if you want to see this merged).
>
I agree to lift the wait part to other archs later if needed, but as
mentioned above I could move this to arch code to the cost of one arch
hook more. But as also mentioned it doesn't really hurt. I agree that it
does not need to be KVM_REQ_MMU_RELOAD specific, we could just
walk/clear/wake all bits on that vcpu->requests variable.
Would that be generic enough in your opinion ?
> Later it can all be lifted off to arch independent code.
>
True for the wait part which can evolve in our arch code until it is
ripe to get cross arch merged.
--
Grüsse / regards, Christian Ehrhardt
IBM Linux Technology Center, Open Virtualization
next prev parent reply other threads:[~2009-06-08 10:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-02 14:26 [PATCH 0/3] kvm-s390: revised version of kvm-s390 guest memory handling - rebased ehrhardt
2009-06-02 14:26 ` [PATCH 1/3] kvm-s390: infrastructure to kick vcpus out of guest state " ehrhardt
2009-06-02 14:26 ` [PATCH 2/3] kvm-s390: update vcpu->cpu " ehrhardt
2009-06-02 14:26 ` [PATCH 3/3] kvm-s390: streamline memslot handling " ehrhardt
2009-06-05 20:53 ` Marcelo Tosatti
2009-06-08 10:51 ` Christian Ehrhardt [this message]
2009-06-08 11:10 ` Avi Kivity
2009-06-08 12:05 ` Christian Ehrhardt
2009-06-08 12:09 ` Avi Kivity
2009-06-09 0:56 ` Marcelo Tosatti
2009-06-14 12:04 ` Avi Kivity
2009-06-15 13:47 ` Christian Ehrhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A2CED2E.6030904@linux.vnet.ibm.com \
--to=ehrhardt@linux.vnet.ibm.com \
--cc=avi@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cotte@de.ibm.com \
--cc=heiko.carstens@de.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=schwidefsky@de.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox