]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.4-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 23 Apr 2024 13:16:58 +0000 (06:16 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 23 Apr 2024 13:16:58 +0000 (06:16 -0700)
added patches:
kvm-async_pf-cleanup-kvm_setup_async_pf.patch
nilfs2-fix-oob-in-nilfs_set_de_type.patch
nouveau-fix-instmem-race-condition-around-ptr-stores.patch

queue-5.4/kvm-async_pf-cleanup-kvm_setup_async_pf.patch [new file with mode: 0644]
queue-5.4/nilfs2-fix-oob-in-nilfs_set_de_type.patch [new file with mode: 0644]
queue-5.4/nouveau-fix-instmem-race-condition-around-ptr-stores.patch [new file with mode: 0644]
queue-5.4/series

diff --git a/queue-5.4/kvm-async_pf-cleanup-kvm_setup_async_pf.patch b/queue-5.4/kvm-async_pf-cleanup-kvm_setup_async_pf.patch
new file mode 100644 (file)
index 0000000..d5b85de
--- /dev/null
@@ -0,0 +1,70 @@
+From 7863e346e1089b40cac1c7d9098314c405e2e1e3 Mon Sep 17 00:00:00 2001
+From: Vitaly Kuznetsov <vkuznets@redhat.com>
+Date: Wed, 10 Jun 2020 19:55:31 +0200
+Subject: KVM: async_pf: Cleanup kvm_setup_async_pf()
+
+From: Vitaly Kuznetsov <vkuznets@redhat.com>
+
+commit 7863e346e1089b40cac1c7d9098314c405e2e1e3 upstream.
+
+schedule_work() returns 'false' only when the work is already on the queue
+and this can't happen as kvm_setup_async_pf() always allocates a new one.
+Also, to avoid potential race, it makes sense to to schedule_work() at the
+very end after we've added it to the queue.
+
+While on it, do some minor cleanup. gfn_to_pfn_async() mentioned in a
+comment does not currently exist and, moreover, we can check
+kvm_is_error_hva() at the very beginning, before we try to allocate work so
+'retry_sync' label can go away completely.
+
+Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
+Message-Id: <20200610175532.779793-1-vkuznets@redhat.com>
+Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>
+Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
+Cc: Guenter Roeck <linux@roeck-us.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ virt/kvm/async_pf.c |   19 ++++++-------------
+ 1 file changed, 6 insertions(+), 13 deletions(-)
+
+--- a/virt/kvm/async_pf.c
++++ b/virt/kvm/async_pf.c
+@@ -195,7 +195,9 @@ int kvm_setup_async_pf(struct kvm_vcpu *
+       if (vcpu->async_pf.queued >= ASYNC_PF_PER_VCPU)
+               return 0;
+-      /* setup delayed work */
++      /* Arch specific code should not do async PF in this case */
++      if (unlikely(kvm_is_error_hva(hva)))
++              return 0;
+       /*
+        * do alloc nowait since if we are going to sleep anyway we
+@@ -213,24 +215,15 @@ int kvm_setup_async_pf(struct kvm_vcpu *
+       work->mm = current->mm;
+       mmget(work->mm);
+-      /* this can't really happen otherwise gfn_to_pfn_async
+-         would succeed */
+-      if (unlikely(kvm_is_error_hva(work->addr)))
+-              goto retry_sync;
+-
+       INIT_WORK(&work->work, async_pf_execute);
+-      if (!schedule_work(&work->work))
+-              goto retry_sync;
+       list_add_tail(&work->queue, &vcpu->async_pf.queue);
+       vcpu->async_pf.queued++;
+       kvm_arch_async_page_not_present(vcpu, work);
++
++      schedule_work(&work->work);
++
+       return 1;
+-retry_sync:
+-      kvm_put_kvm(work->vcpu->kvm);
+-      mmput(work->mm);
+-      kmem_cache_free(async_pf_cache, work);
+-      return 0;
+ }
+ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu)
diff --git a/queue-5.4/nilfs2-fix-oob-in-nilfs_set_de_type.patch b/queue-5.4/nilfs2-fix-oob-in-nilfs_set_de_type.patch
new file mode 100644 (file)
index 0000000..f463678
--- /dev/null
@@ -0,0 +1,53 @@
+From c4a7dc9523b59b3e73fd522c73e95e072f876b16 Mon Sep 17 00:00:00 2001
+From: Jeongjun Park <aha310510@gmail.com>
+Date: Tue, 16 Apr 2024 03:20:48 +0900
+Subject: nilfs2: fix OOB in nilfs_set_de_type
+
+From: Jeongjun Park <aha310510@gmail.com>
+
+commit c4a7dc9523b59b3e73fd522c73e95e072f876b16 upstream.
+
+The size of the nilfs_type_by_mode array in the fs/nilfs2/dir.c file is
+defined as "S_IFMT >> S_SHIFT", but the nilfs_set_de_type() function,
+which uses this array, specifies the index to read from the array in the
+same way as "(mode & S_IFMT) >> S_SHIFT".
+
+static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode
+ *inode)
+{
+       umode_t mode = inode->i_mode;
+
+       de->file_type = nilfs_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; // oob
+}
+
+However, when the index is determined this way, an out-of-bounds (OOB)
+error occurs by referring to an index that is 1 larger than the array size
+when the condition "mode & S_IFMT == S_IFMT" is satisfied.  Therefore, a
+patch to resize the nilfs_type_by_mode array should be applied to prevent
+OOB errors.
+
+Link: https://lkml.kernel.org/r/20240415182048.7144-1-konishi.ryusuke@gmail.com
+Reported-by: syzbot+2e22057de05b9f3b30d8@syzkaller.appspotmail.com
+Closes: https://syzkaller.appspot.com/bug?extid=2e22057de05b9f3b30d8
+Fixes: 2ba466d74ed7 ("nilfs2: directory entry operations")
+Signed-off-by: Jeongjun Park <aha310510@gmail.com>
+Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
+Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
+Cc: <stable@vger.kernel.org>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ fs/nilfs2/dir.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/fs/nilfs2/dir.c
++++ b/fs/nilfs2/dir.c
+@@ -243,7 +243,7 @@ nilfs_filetype_table[NILFS_FT_MAX] = {
+ #define S_SHIFT 12
+ static unsigned char
+-nilfs_type_by_mode[S_IFMT >> S_SHIFT] = {
++nilfs_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = {
+       [S_IFREG >> S_SHIFT]    = NILFS_FT_REG_FILE,
+       [S_IFDIR >> S_SHIFT]    = NILFS_FT_DIR,
+       [S_IFCHR >> S_SHIFT]    = NILFS_FT_CHRDEV,
diff --git a/queue-5.4/nouveau-fix-instmem-race-condition-around-ptr-stores.patch b/queue-5.4/nouveau-fix-instmem-race-condition-around-ptr-stores.patch
new file mode 100644 (file)
index 0000000..7760cb3
--- /dev/null
@@ -0,0 +1,96 @@
+From fff1386cc889d8fb4089d285f883f8cba62d82ce Mon Sep 17 00:00:00 2001
+From: Dave Airlie <airlied@redhat.com>
+Date: Thu, 11 Apr 2024 11:15:09 +1000
+Subject: nouveau: fix instmem race condition around ptr stores
+
+From: Dave Airlie <airlied@redhat.com>
+
+commit fff1386cc889d8fb4089d285f883f8cba62d82ce upstream.
+
+Running a lot of VK CTS in parallel against nouveau, once every
+few hours you might see something like this crash.
+
+BUG: kernel NULL pointer dereference, address: 0000000000000008
+PGD 8000000114e6e067 P4D 8000000114e6e067 PUD 109046067 PMD 0
+Oops: 0000 [#1] PREEMPT SMP PTI
+CPU: 7 PID: 53891 Comm: deqp-vk Not tainted 6.8.0-rc6+ #27
+Hardware name: Gigabyte Technology Co., Ltd. Z390 I AORUS PRO WIFI/Z390 I AORUS PRO WIFI-CF, BIOS F8 11/05/2021
+RIP: 0010:gp100_vmm_pgt_mem+0xe3/0x180 [nouveau]
+Code: c7 48 01 c8 49 89 45 58 85 d2 0f 84 95 00 00 00 41 0f b7 46 12 49 8b 7e 08 89 da 42 8d 2c f8 48 8b 47 08 41 83 c7 01 48 89 ee <48> 8b 40 08 ff d0 0f 1f 00 49 8b 7e 08 48 89 d9 48 8d 75 04 48 c1
+RSP: 0000:ffffac20c5857838 EFLAGS: 00010202
+RAX: 0000000000000000 RBX: 00000000004d8001 RCX: 0000000000000001
+RDX: 00000000004d8001 RSI: 00000000000006d8 RDI: ffffa07afe332180
+RBP: 00000000000006d8 R08: ffffac20c5857ad0 R09: 0000000000ffff10
+R10: 0000000000000001 R11: ffffa07af27e2de0 R12: 000000000000001c
+R13: ffffac20c5857ad0 R14: ffffa07a96fe9040 R15: 000000000000001c
+FS:  00007fe395eed7c0(0000) GS:ffffa07e2c980000(0000) knlGS:0000000000000000
+CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
+CR2: 0000000000000008 CR3: 000000011febe001 CR4: 00000000003706f0
+DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
+DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
+Call Trace:
+
+...
+
+ ? gp100_vmm_pgt_mem+0xe3/0x180 [nouveau]
+ ? gp100_vmm_pgt_mem+0x37/0x180 [nouveau]
+ nvkm_vmm_iter+0x351/0xa20 [nouveau]
+ ? __pfx_nvkm_vmm_ref_ptes+0x10/0x10 [nouveau]
+ ? __pfx_gp100_vmm_pgt_mem+0x10/0x10 [nouveau]
+ ? __pfx_gp100_vmm_pgt_mem+0x10/0x10 [nouveau]
+ ? __lock_acquire+0x3ed/0x2170
+ ? __pfx_gp100_vmm_pgt_mem+0x10/0x10 [nouveau]
+ nvkm_vmm_ptes_get_map+0xc2/0x100 [nouveau]
+ ? __pfx_nvkm_vmm_ref_ptes+0x10/0x10 [nouveau]
+ ? __pfx_gp100_vmm_pgt_mem+0x10/0x10 [nouveau]
+ nvkm_vmm_map_locked+0x224/0x3a0 [nouveau]
+
+Adding any sort of useful debug usually makes it go away, so I hand
+wrote the function in a line, and debugged the asm.
+
+Every so often pt->memory->ptrs is NULL. This ptrs ptr is set in
+the nv50_instobj_acquire called from nvkm_kmap.
+
+If Thread A and Thread B both get to nv50_instobj_acquire around
+the same time, and Thread A hits the refcount_set line, and in
+lockstep thread B succeeds at refcount_inc_not_zero, there is a
+chance the ptrs value won't have been stored since refcount_set
+is unordered. Force a memory barrier here, I picked smp_mb, since
+we want it on all CPUs and it's write followed by a read.
+
+v2: use paired smp_rmb/smp_wmb.
+
+Cc: <stable@vger.kernel.org>
+Fixes: be55287aa5ba ("drm/nouveau/imem/nv50: embed nvkm_instobj directly into nv04_instobj")
+Signed-off-by: Dave Airlie <airlied@redhat.com>
+Signed-off-by: Danilo Krummrich <dakr@redhat.com>
+Link: https://patchwork.freedesktop.org/patch/msgid/20240411011510.2546857-1-airlied@gmail.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/gpu/drm/nouveau/nvkm/subdev/instmem/nv50.c |    7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+--- a/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/nv50.c
++++ b/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/nv50.c
+@@ -221,8 +221,11 @@ nv50_instobj_acquire(struct nvkm_memory
+       void __iomem *map = NULL;
+       /* Already mapped? */
+-      if (refcount_inc_not_zero(&iobj->maps))
++      if (refcount_inc_not_zero(&iobj->maps)) {
++              /* read barrier match the wmb on refcount set */
++              smp_rmb();
+               return iobj->map;
++      }
+       /* Take the lock, and re-check that another thread hasn't
+        * already mapped the object in the meantime.
+@@ -249,6 +252,8 @@ nv50_instobj_acquire(struct nvkm_memory
+                       iobj->base.memory.ptrs = &nv50_instobj_fast;
+               else
+                       iobj->base.memory.ptrs = &nv50_instobj_slow;
++              /* barrier to ensure the ptrs are written before refcount is set */
++              smp_wmb();
+               refcount_set(&iobj->maps, 1);
+       }
index 812cb08cf167f011886e73e98e8656ad71a38cea..f72e0825896aa12b53d66abc87e1663547f3d750 100644 (file)
@@ -47,3 +47,6 @@ usb-dwc2-host-fix-dereference-issue-in-ddma-completion-flow.patch
 usb-disable-usb3-lpm-at-shutdown.patch
 speakup-avoid-crash-on-very-long-word.patch
 fs-sysfs-fix-reference-leak-in-sysfs_break_active_protection.patch
+nouveau-fix-instmem-race-condition-around-ptr-stores.patch
+nilfs2-fix-oob-in-nilfs_set_de_type.patch
+kvm-async_pf-cleanup-kvm_setup_async_pf.patch