From: "Radim Krčmář" <rkrcmar@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>,
Paolo Bonzini <pbonzini@redhat.com>, KVM <kvm@vger.kernel.org>,
Cornelia Huck <cornelia.huck@de.ibm.com>,
linux-s390 <linux-s390@vger.kernel.org>
Subject: Re: [PATCH] KVM: add kvm_arch_cpu_kick
Date: Mon, 20 Feb 2017 22:45:10 +0100 [thread overview]
Message-ID: <20170220214510.GB3744@potion> (raw)
In-Reply-To: <8c881e51-65f4-100e-fec7-9490b9031d3b@redhat.com>
2017-02-20 12:35+0100, David Hildenbrand:
> Am 20.02.2017 um 12:12 schrieb Christian Borntraeger:
>> On 02/17/2017 06:10 PM, David Hildenbrand wrote:
>>>
>>>>> Yes, it would. There's some parallel with QEMU's qemu_cpu_kick, where
>>>>> the signal would be processed immediately after entering KVM_RUN.
>>>>
>>>> Something like
>>>>
>>>> ---snip-----
>>>> struct kvm_s390_sie_block *scb = READ_ONCE(vcpu->arch.vsie_block);
>>>>
>>>> atomic_or(CPUSTAT_STOP_INT, &vcpu->arch.sie_block->cpuflags);
>>>> if (scb)
>>>> atomic_or(CPUSTAT_STOP_INT, &scb->cpuflags);
>>>> ---snip-----
>>>>
>>>> or
>>>> ---snip-----
>>>> atomic_or(CPUSTAT_STOP_INT, &vcpu->arch.sie_block->cpuflags);
>>>> kvm_s390_vsie_kick(vcpu);
>>>> ---snip-----
>>>
>>> I'd go for the latter one. Keep the vsie stuff isolated. Please note
>>
>> Yes makes sense.
>>
>> Radim, if you go with this patch something like this can be used as the
>> s390 variant of kvm_arch_cpu_kick:
>>
>> ---snip---
>> /*
>> * The stop indication is reset in the interrupt code. As the CPU
>> * loop handles requests after interrupts, we will
>> * a: miss the request handler and enter the guest, but then the
>> * stop request will exit the CPU and handle the request in the next
>> * round or
>> * b: handle the request directly before entering the guest
>> */
>> atomic_or(CPUSTAT_STOP_INT, &vcpu->arch.sie_block->cpuflags);
>> kvm_s390_vsie_kick(vcpu);
>>
>> ---snip---
>> feel free to add that to your patch. I can also send a fixup patch later
>> on if you prefer that.
>
> kvm_arch_vcpu_should_kick() then also has to be changed to return 1 for now.
>
> An interesting thing to note is how vcpu->cpu is used.
>
> Again, as s390x can preempt just before entering the guest, vcpu_kick()
> might see vcpu->cpu = -1. Therefore, kvm_arch_vcpu_should_kick() won't
> even be called. So our cpu might go into guest mode and stay there
> longer than expected (as we won't kick it).
>
> On x86, it is the following way:
>
> If vcpu->cpu is -1, no need to kick the VCPU. It will check for requests
> when preemption is disabled, therefore when rescheduled.
>
> If vcpu->cpu is set, kvm_arch_vcpu_should_kick() remembers if the VCPU
> has already been kicked while in the critical section. It will get
> kicked by smp resched as soon as entering guest mode.
>
> So here, disabled preemption + checks in the section with disabled
> preemption (for requests and EXITING_GUEST_MODE) make sure that the
> guest will leave guest mode and process requests in a timely fashion.
>
> On s390x, this is not 100% true. vcpu->cpu cannot be used as an
> indicator whether a kick is necessary. Either that is ok for now, or the
> vcpu->cpu != -1 check has to be disabled for s390x, e.g. by moving the
> check into kvm_arch_vcpu_should_kick().
Good point.
So s390 doesn't need vcpu->cpu and only sets it because other arches do?
And do I understand it correctly that the s390 SIE block operations have
no side-effect, apart from changed memory, when outside of guest-mode?
(We have cpu->mode mostly because interrupts are expensive. :])
In the end, I'd like to use kvm_vcpu_kick() for kvm_s390_vcpu_wakeup().
s390 sets vcpu->preempted to get a performance boost, which makes
touching it less than desirable ...
On s390, vcpu->preempted is only used in __diag_time_slice_end(), which
seems to be a type of spinning-on-a-taken-lock hypercall -- any reason
why that optimization shouldn't work on other architectures?
Thanks.
next prev parent reply other threads:[~2017-02-20 21:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-17 13:10 [PATCH/RFC 0/2] KVM: s390: enable kvm_vpcu_kick/wake_up Christian Borntraeger
2017-02-17 13:10 ` [PATCH/RFC 1/2] s390/smp: export smp_send_reschedule Christian Borntraeger
2017-02-17 15:12 ` [PATCH] KVM: add kvm_arch_cpu_kick Radim Krčmář
2017-02-17 15:46 ` Christian Borntraeger
2017-02-17 16:23 ` Paolo Bonzini
2017-02-17 16:42 ` Christian Borntraeger
2017-02-17 17:10 ` David Hildenbrand
2017-02-20 11:12 ` Christian Borntraeger
2017-02-20 11:35 ` David Hildenbrand
2017-02-20 21:45 ` Radim Krčmář [this message]
2017-02-21 8:59 ` Christian Borntraeger
2017-02-21 17:15 ` Radim Krčmář
2017-02-21 19:08 ` Christian Borntraeger
2017-02-22 15:29 ` Radim Krčmář
2017-02-20 20:59 ` Radim Krčmář
2017-02-17 17:07 ` David Hildenbrand
2017-02-17 13:10 ` [PATCH/RFC 2/2] KVM: enable kvm_vcpu_kick/wake_up for s390 Christian Borntraeger
2017-02-17 15:23 ` Radim Krčmář
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=20170220214510.GB3744@potion \
--to=rkrcmar@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=david@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=pbonzini@redhat.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