From: Matthew Rosato <mjrosato@linux.ibm.com>
To: Niklas Schnelle <schnelle@linux.ibm.com>, linux-s390@vger.kernel.org
Cc: alifm@linux.ibm.com, farman@linux.ibm.com,
borntraeger@linux.ibm.com, frankja@linux.ibm.com,
imbrenda@linux.ibm.com, david@kernel.org, hca@linux.ibm.com,
gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: s390: pci: Fix aisb calculation
Date: Fri, 24 Apr 2026 16:09:52 -0400 [thread overview]
Message-ID: <1acdd73d-2b30-4d92-af83-1d5d1ec34c7d@linux.ibm.com> (raw)
In-Reply-To: <d0765cdf0f3832c3fd92af53d2a4060d2d018439.camel@linux.ibm.com>
On 4/24/26 3:55 PM, Niklas Schnelle wrote:
> On Fri, 2026-04-24 at 15:39 -0400, Matthew Rosato wrote:
>> The current implementation of aisb calculation will erroneously index
>> via an unsigned long * as well as multiply by 8B for every 64-bits in
>> the offset; only one or the other is required. This throws off aisb
>> calculations once the number of devices exceeds 64, and can result
>> in out-of-bounds access as well as failure to indicate summary bits
>> associated with those devices in guests.
>>
>> Fix this by converting to a physical address before applying the
>> offset, as is already done in arch/s390/pci/pci_irq.c.
>>
>> Fixes: 3c5a1b6f0a18 ("KVM: s390: pci: provide routines for enabling/disabling interrupt forwarding")
>> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
>> ---
>> arch/s390/kvm/pci.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
>> index 86d93e8dddae..338171f9371b 100644
>> --- a/arch/s390/kvm/pci.c
>> +++ b/arch/s390/kvm/pci.c
>> @@ -166,7 +166,7 @@ static int kvm_zpci_set_airq(struct zpci_dev *zdev)
>> fib.fmt0.noi = airq_iv_end(zdev->aibv);
>> fib.fmt0.aibv = virt_to_phys(zdev->aibv->vector);
>> fib.fmt0.aibvo = 0;
>> - fib.fmt0.aisb = virt_to_phys(aift->sbv->vector + (zdev->aisb / 64) * 8);
>> + fib.fmt0.aisb = virt_to_phys(aift->sbv->vector) + (zdev->aisb / 64) * 8;
>
> As you state, one or the other would work, wouldn't it be easy to read
> like below:
>
> fib.fmt0.aisb = virt_to_phys(aift->sbv->vector + (zdev->aisb / 64));
My rationale was to match exactly what zpci_set_airq() in
arch/s390/pci/pci_irq.c is doing (I tested that code at the same time to
ensure it produced the expected result as a comparison to the code
changed by this patch).
I'd rather all 3 places stay the same unless you have a strong opinion
on it. I think the reason they ended up different in the first place is
because this code and the pci_irq.c code were updated independently for
V!=R.
>
>> fib.fmt0.aisbo = zdev->aisb & 63;
>> fib.gd = zdev->gisa;
>>
>> @@ -309,7 +309,7 @@ static int kvm_s390_pci_aif_enable(struct zpci_dev *zdev, struct zpci_fib *fib,
>>
>> /* Update guest FIB for re-issue */
>> fib->fmt0.aisbo = zdev->aisb & 63;
>> - fib->fmt0.aisb = virt_to_phys(aift->sbv->vector + (zdev->aisb / 64) * 8);
>> + fib->fmt0.aisb = virt_to_phys(aift->sbv->vector) + (zdev->aisb / 64) * 8;
>
> Same argument as above.
>
>> fib->fmt0.isc = gisc;
>>
>> /* Save some guest fib values in the host for later use */
>
> Ouch, good catch! Was this kind of a follow up to the issue someone
> found upstream with a wrong calculation in the gait? Or did you just
> notice things break with more than 64 devices?
A follow-up of sorts. Sashiko gave various outputs to that gait patch
that were unrelated to it; I'm looking into those things and it led me
to at least this issue which I did verify is a real bug.
Thanks,
Matt
next prev parent reply other threads:[~2026-04-24 20:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 19:39 [PATCH] KVM: s390: pci: Fix aisb calculation Matthew Rosato
2026-04-24 19:55 ` Niklas Schnelle
2026-04-24 20:09 ` Matthew Rosato [this message]
2026-04-24 20:15 ` Niklas Schnelle
2026-04-27 9:11 ` Christian Borntraeger
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=1acdd73d-2b30-4d92-af83-1d5d1ec34c7d@linux.ibm.com \
--to=mjrosato@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=alifm@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=david@kernel.org \
--cc=farman@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=schnelle@linux.ibm.com \
--cc=svens@linux.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