KVM: s390: pci: Fix memory accounting for pinned/unpinned pages
authorFarhan Ali <alifm@linux.ibm.com>
Thu, 23 Jul 2026 22:14:05 +0000 (15:14 -0700)
committerChristian Borntraeger <borntraeger@linux.ibm.com>
Fri, 24 Jul 2026 09:26:53 +0000 (11:26 +0200)
commit36f6999ecde3976731a8bfc0b8e667da6f593069
tree7c58b47c0cec7d2d3ceb3ef8a0d419e06c3a9298
parent8fa01be5a6149404adb82c0979a78f6347edd3ef
KVM: s390: pci: Fix memory accounting for pinned/unpinned pages

The account_mem() and unaccount_mem() functions call get_uid() which
increments the reference count of struct user_struct on every invocation.
But we don't decrement the count by calling free_uid(). It also
accounted/unaccounted the pages against the current->mm. But its possible
the unaccount_mem() can be called from a different process context than the
one that originally pinned the pages.

Let's fix this by storing the pinning process user_struct and mm_struct
when accounting for pinned pages, and subsequently free these resources
when the pages are unpinned.

Fixes: 3c5a1b6f0a18 ("KVM: s390: pci: provide routines for enabling/disabling interrupt forwarding")
Cc: stable@vger.kernel.org
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Farhan Ali <alifm@linux.ibm.com>
Tested-by: Matthew Rosato <mjrosato@linux.ibm.com>
[borntraeger@linux.ibm.com: Fixed whitespace]
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
arch/s390/kvm/pci.c
arch/s390/kvm/pci.h