Re: [PATCH v6 14/21] KVM: s390: pci: provide routines for enabling/disabling interrupt forwarding

Christian Borntraeger
2022-05-06T15:35:53Z

Am 26.04.22 um 22:08 schrieb Matthew Rosato:
[...]
> +static inline void unaccount_mem(unsigned long nr_pages)
> +{
> + struct user_struct *user = get_uid(current_user());
> +
> + if (user)
> + atomic_long_sub(nr_pages, &user->locked_vm);
> + if (current->mm)
> + atomic64_sub(nr_pages, &current->mm->pinned_vm);
> +}
> +
> +static inline int account_mem(unsigned long nr_pages)
> +{
> + struct user_struct *user = get_uid(current_user());
> + unsigned long page_limit, cur_pages, new_pages;
> +
> + page_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> +
> + do {
> + cur_pages = atomic_long_read(&user->locked_vm);
> + new_pages = cur_pages + nr_pages;
> + if (new_pages > page_limit)
> + return -ENOMEM;
> + } while (atomic_long_cmpxchg(&user->locked_vm, cur_pages,
> + new_pages) != cur_pages);
> +
> + atomic64_add(nr_pages, &current->mm->pinned_vm);
> +
> + return 0;

user->locked_vm is not available unconditionally. Shall we add

CONFIG_S390 && CONFIG_KVM here?

include/linux/sched/user.h
#if defined(CONFIG_PERF_EVENTS) || defined(CONFIG_BPF_SYSCALL) || \
defined(CONFIG_NET) || defined(CONFIG_IO_URING)
atomic_long_t locked_vm;
#endif
Or we could get rid of the user memlock checking for now until this is more ubiquitous.

Otherwise this looks sane

Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>