From: sashiko-bot@kernel.org
To: "Farhan Ali" <alifm@linux.ibm.com>
Cc: linux-s390@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
kvm@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v2 1/4] KVM: s390: pci: Fix memory accounting for pinned/unpinned pages
Date: Thu, 16 Jul 2026 18:08:19 +0000 [thread overview]
Message-ID: <20260716180819.7BD461F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716175241.1039-2-alifm@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Sequential calls to the KVM_S390_ZPCIOP_REG_AEN ioctl on the same device overwrite kzdev->user_account and kzdev->mm_account without dropping previous references, causing a permanent leak of mm_struct references and pinned pages.
--
--- Patch [1]: [PATCH v2 1/4] KVM: s390: pci: Fix memory accounting for pinned/unpinned pages ---
commit cbbebe9ad7b7a6af2ee4a68dd67b2e520770bd20
Author: Farhan Ali <alifm@linux.ibm.com>
KVM: s390: pci: Fix memory accounting for pinned/unpinned pages
This patch addresses a bug where unaccount_mem() could be called from a
different process context than the one that initially pinned the pages. It
resolves this by storing the pinning process's user_struct and mm_struct
when accounting for pinned pages, so they can be properly freed later.
> diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
> index 720bb58cabe2e..dd17f8a7b4734 100644
> --- a/arch/s390/kvm/pci.c
> +++ b/arch/s390/kvm/pci.c
[ ... ]
> @@ -206,17 +220,24 @@ static inline int account_mem(struct kvm_zdev *kzdev, unsigned long nr_pages)
> do {
> new_pages = cur_pages + nr_pages;
> - if (new_pages > page_limit)
> - return -ENOMEM;
> + if (new_pages > page_limit) {
> + rc = -ENOMEM;
> + goto out;
> + }
> } while (!atomic_long_try_cmpxchg(&user->locked_vm, &cur_pages, new_pages));
>
> + mmgrab(current->mm);
> atomic64_add(nr_pages, ¤t->mm->pinned_vm);
> + kzdev->user_account = user;
> + kzdev->mm_account = current->mm;
[Severity: High]
If kvm_s390_pci_aif_enable() is called multiple times for the same device,
will this overwrite kzdev->user_account and kzdev->mm_account and leak
the previously acquired references?
It looks like kvm_s390_pci_aif_enable() doesn't check if the device is
already enabled before proceeding. If a userspace process calls the
KVM_S390_ZPCIOP_REG_AEN ioctl twice on the same device, the first call
will successfully populate these pointers.
The second call would then overwrite them here, leaking the original
mm_struct reference and permanently stranding the initially pinned pages.
If that second call subsequently fails, unaccount_mem() drops the new
reference and sets the pointers to NULL, leaving the original references
permanently orphaned.
Should there be a check in kvm_s390_pci_aif_enable() to bail out if it
is already enabled, or a check here to ensure we aren't overwriting an
existing reference?
>
> return 0;
> +
> +out:
> + free_uid(user);
> + return rc;
> }
>
> static int kvm_s390_pci_aif_enable(struct zpci_dev *zdev, struct zpci_fib *fib,
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260716175241.1039-1-alifm@linux.ibm.com?part=1
next prev parent reply other threads:[~2026-07-16 18:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 17:52 [PATCH v2 0/4] KVM s390x PCI fixes Farhan Ali
2026-07-16 17:52 ` [PATCH v2 1/4] KVM: s390: pci: Fix memory accounting for pinned/unpinned pages Farhan Ali
2026-07-16 18:08 ` sashiko-bot [this message]
2026-07-16 17:52 ` [PATCH v2 2/4] KVM: s390: pci: Fix missing error codes and memory unaccounting Farhan Ali
2026-07-16 18:06 ` sashiko-bot
2026-07-16 17:52 ` [PATCH v2 3/4] KVM: s390: pci: Fix NULL dereference on AIBV allocation failure Farhan Ali
2026-07-16 18:06 ` sashiko-bot
2026-07-16 17:52 ` [PATCH v2 4/4] KVM: s390: pci: Fix resource leak on IRQ registration failure Farhan Ali
2026-07-16 18:05 ` sashiko-bot
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=20260716180819.7BD461F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=alifm@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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