From: Sean Christopherson <seanjc@google.com>
To: Ilias Stamatis <ilstam@amazon.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, pdurrant@amazon.co.uk,
dwmw@amazon.co.uk, nh-open-source@amazon.com,
Paul Durrant <paul@xen.org>
Subject: Re: [PATCH v3 1/6] KVM: Fix coalesced_mmio_has_room()
Date: Fri, 23 Aug 2024 17:04:23 -0700 [thread overview]
Message-ID: <ZskjhzkfQDtJVnDI@google.com> (raw)
In-Reply-To: <20240820133333.1724191-2-ilstam@amazon.com>
On Tue, Aug 20, 2024, Ilias Stamatis wrote:
> The following calculation used in coalesced_mmio_has_room() to check
> whether the ring buffer is full is wrong and only allows half the buffer
> to be used.
>
> avail = (ring->first - last - 1) % KVM_COALESCED_MMIO_MAX;
> if (avail == 0)
> /* full */
>
> The % operator in C is not the modulo operator but the remainder
> operator. Modulo and remainder operators differ with respect to negative
> values. But all values are unsigned in this case anyway.
>
> The above might have worked as expected in python for example:
> >>> (-86) % 170
> 84
>
> However it doesn't work the same way in C.
>
> printf("avail: %d\n", (-86) % 170);
> printf("avail: %u\n", (-86) % 170);
> printf("avail: %u\n", (-86u) % 170u);
>
> Using gcc-11 these print:
>
> avail: -86
> avail: 4294967210
> avail: 0
>
> Fix the calculation and allow all but one entries in the buffer to be
> used as originally intended.
>
> Fixes: 105f8d40a737 ("KVM: Calculate available entries in coalesced mmio ring")
> Signed-off-by: Ilias Stamatis <ilstam@amazon.com>
> Reviewed-by: Paul Durrant <paul@xen.org>
> ---
Doh, I applied v2 instead of v3. Though unless mine eyes deceive me, they're
the same.
next prev parent reply other threads:[~2024-08-24 0:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 13:33 [PATCH v3 0/6] KVM: Improve MMIO Coalescing API Ilias Stamatis
2024-08-20 13:33 ` [PATCH v3 1/6] KVM: Fix coalesced_mmio_has_room() Ilias Stamatis
2024-08-24 0:04 ` Sean Christopherson [this message]
2024-08-20 13:33 ` [PATCH v3 2/6] KVM: Add KVM_CREATE_COALESCED_MMIO_BUFFER ioctl Ilias Stamatis
2024-08-28 14:25 ` Sean Christopherson
2024-08-29 11:20 ` Stamatis, Ilias
2024-08-29 14:55 ` Sean Christopherson
2024-08-29 17:42 ` Stamatis, Ilias
2024-08-20 13:33 ` [PATCH v3 3/6] KVM: Support poll() on coalesced mmio buffer fds Ilias Stamatis
2024-08-20 13:33 ` [PATCH v3 4/6] KVM: Add KVM_(UN)REGISTER_COALESCED_MMIO2 ioctls Ilias Stamatis
2024-08-20 13:33 ` [PATCH v3 5/6] KVM: Documentation: Document v2 of coalesced MMIO API Ilias Stamatis
2024-08-20 13:33 ` [PATCH v3 6/6] KVM: selftests: Add coalesced_mmio_test Ilias Stamatis
2024-08-28 17:20 ` Sean Christopherson
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=ZskjhzkfQDtJVnDI@google.com \
--to=seanjc@google.com \
--cc=dwmw@amazon.co.uk \
--cc=ilstam@amazon.com \
--cc=kvm@vger.kernel.org \
--cc=nh-open-source@amazon.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=pdurrant@amazon.co.uk \
/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