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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/6/22 11:35 AM, Christian Borntraeger wrote:


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.

Oh, good catch. Per my conversation with Jason in a thread on patch 16, we will end up with a CONFIG_VFIO_PCI_ZDEV_KVM (or something like that) -- this could be used instead of CONFIG_S390 && CONFIG_KVM and would imply both of those anyway



Otherwise this looks sane

Reviewed-by: Christian Borntraeger <borntraeger@xxxxxxxxxxxxx>




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux