Re: [PATCH 2/6] KVM: use kvm_{test,clear}_request instead of {test,clear}_bit

From: Christian Borntraeger
Date: Fri Apr 07 2017 - 06:55:37 EST


On 04/06/2017 10:20 PM, Radim KrÄmÃÅ wrote:
> Users were expected to use kvm_check_request() for testing and clearing,
> but request have expanded their use since then and some users want to
> only test or do a faster clear.
>
> Make sure that requests are not directly accessed with bit operations, because
> we'll be clearing them later.
>
> Signed-off-by: Radim KrÄmÃÅ <rkrcmar@xxxxxxxxxx>

Patch itself looks sane
Reviewed-by: Christian Borntraeger <borntraeger@xxxxxxxxxx>


one question:
> static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu)
> {
> - if (test_bit(req, &vcpu->requests)) {
> - clear_bit(req, &vcpu->requests);
> + if (kvm_test_request(req, vcpu)) {
> + kvm_clear_request(req, vcpu);

This looks fine. I am just asking myself why we do not use
test_and_clear_bit? Do we expect gcc to merge all test bits as
a fast path? This does not seem to work as far as I can tell and
almost everybody does a fast path like in



arch/s390/kvm/kvm-s390.c:
if (!vcpu->requests)
return 0;

arch/x86/kvm/x86.c:
if (vcpu->requests) {

>
> /*
> * Ensure the rest of the request is visible to kvm_check_request's
>