From: Greg Kroah-Hartman Date: Mon, 28 Feb 2022 11:12:13 +0000 (+0100) Subject: 4.14-stable patches X-Git-Tag: v4.9.304~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=46252cddb0d842ea64d93522d16922cf24397352;p=thirdparty%2Fkernel%2Fstable-queue.git 4.14-stable patches added patches: fget-clarify-and-improve-__fget_files-implementation.patch memblock-use-kfree-to-release-kmalloced-memblock-regions.patch revert-drm-nouveau-pmu-gm200-avoid-touching-pmu-outside-of-devinit-preos-acr.patch --- diff --git a/queue-4.14/fget-clarify-and-improve-__fget_files-implementation.patch b/queue-4.14/fget-clarify-and-improve-__fget_files-implementation.patch new file mode 100644 index 00000000000..07e6654cb4e --- /dev/null +++ b/queue-4.14/fget-clarify-and-improve-__fget_files-implementation.patch @@ -0,0 +1,141 @@ +From foo@baz Mon Feb 28 12:05:24 PM CET 2022 +From: Baokun Li +Date: Sat, 26 Feb 2022 14:32:56 +0800 +Subject: fget: clarify and improve __fget_files() implementation +To: +Cc: , , , , , , , , +Message-ID: <20220226063256.168114-1-libaokun1@huawei.com> + +From: Linus Torvalds + +commit e386dfc56f837da66d00a078e5314bc8382fab83 upstream. + +Commit 054aa8d439b9 ("fget: check that the fd still exists after getting +a ref to it") fixed a race with getting a reference to a file just as it +was being closed. It was a fairly minimal patch, and I didn't think +re-checking the file pointer lookup would be a measurable overhead, +since it was all right there and cached. + +But I was wrong, as pointed out by the kernel test robot. + +The 'poll2' case of the will-it-scale.per_thread_ops benchmark regressed +quite noticeably. Admittedly it seems to be a very artificial test: +doing "poll()" system calls on regular files in a very tight loop in +multiple threads. + +That means that basically all the time is spent just looking up file +descriptors without ever doing anything useful with them (not that doing +'poll()' on a regular file is useful to begin with). And as a result it +shows the extra "re-check fd" cost as a sore thumb. + +Happily, the regression is fixable by just writing the code to loook up +the fd to be better and clearer. There's still a cost to verify the +file pointer, but now it's basically in the noise even for that +benchmark that does nothing else - and the code is more understandable +and has better comments too. + +[ Side note: this patch is also a classic case of one that looks very + messy with the default greedy Myers diff - it's much more legible with + either the patience of histogram diff algorithm ] + +Link: https://lore.kernel.org/lkml/20211210053743.GA36420@xsang-OptiPlex-9020/ +Link: https://lore.kernel.org/lkml/20211213083154.GA20853@linux.intel.com/ +Reported-by: kernel test robot +Tested-by: Carel Si +Cc: Jann Horn +Cc: Miklos Szeredi +Signed-off-by: Linus Torvalds +Signed-off-by: Baokun Li +Signed-off-by: Greg Kroah-Hartman +--- + fs/file.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++-------------- + 1 file changed, 57 insertions(+), 16 deletions(-) + +--- a/fs/file.c ++++ b/fs/file.c +@@ -679,28 +679,69 @@ void do_close_on_exec(struct files_struc + spin_unlock(&files->file_lock); + } + +-static struct file *__fget(unsigned int fd, fmode_t mask, unsigned int refs) ++static inline struct file *__fget_files_rcu(struct files_struct *files, ++ unsigned int fd, fmode_t mask, unsigned int refs) + { +- struct files_struct *files = current->files; +- struct file *file; ++ for (;;) { ++ struct file *file; ++ struct fdtable *fdt = rcu_dereference_raw(files->fdt); ++ struct file __rcu **fdentry; + +- rcu_read_lock(); +-loop: +- file = fcheck_files(files, fd); +- if (file) { +- /* File object ref couldn't be taken. +- * dup2() atomicity guarantee is the reason +- * we loop to catch the new file (or NULL pointer) ++ if (unlikely(fd >= fdt->max_fds)) ++ return NULL; ++ ++ fdentry = fdt->fd + array_index_nospec(fd, fdt->max_fds); ++ file = rcu_dereference_raw(*fdentry); ++ if (unlikely(!file)) ++ return NULL; ++ ++ if (unlikely(file->f_mode & mask)) ++ return NULL; ++ ++ /* ++ * Ok, we have a file pointer. However, because we do ++ * this all locklessly under RCU, we may be racing with ++ * that file being closed. ++ * ++ * Such a race can take two forms: ++ * ++ * (a) the file ref already went down to zero, ++ * and get_file_rcu_many() fails. Just try ++ * again: + */ +- if (file->f_mode & mask) +- file = NULL; +- else if (!get_file_rcu_many(file, refs)) +- goto loop; +- else if (__fcheck_files(files, fd) != file) { ++ if (unlikely(!get_file_rcu_many(file, refs))) ++ continue; ++ ++ /* ++ * (b) the file table entry has changed under us. ++ * Note that we don't need to re-check the 'fdt->fd' ++ * pointer having changed, because it always goes ++ * hand-in-hand with 'fdt'. ++ * ++ * If so, we need to put our refs and try again. ++ */ ++ if (unlikely(rcu_dereference_raw(files->fdt) != fdt) || ++ unlikely(rcu_dereference_raw(*fdentry) != file)) { + fput_many(file, refs); +- goto loop; ++ continue; + } ++ ++ /* ++ * Ok, we have a ref to the file, and checked that it ++ * still exists. ++ */ ++ return file; + } ++} ++ ++ ++static struct file *__fget(unsigned int fd, fmode_t mask, unsigned int refs) ++{ ++ struct files_struct *files = current->files; ++ struct file *file; ++ ++ rcu_read_lock(); ++ file = __fget_files_rcu(files, fd, mask, refs); + rcu_read_unlock(); + + return file; diff --git a/queue-4.14/memblock-use-kfree-to-release-kmalloced-memblock-regions.patch b/queue-4.14/memblock-use-kfree-to-release-kmalloced-memblock-regions.patch new file mode 100644 index 00000000000..4017f2476b0 --- /dev/null +++ b/queue-4.14/memblock-use-kfree-to-release-kmalloced-memblock-regions.patch @@ -0,0 +1,46 @@ +From c94afc46cae7ad41b2ad6a99368147879f4b0e56 Mon Sep 17 00:00:00 2001 +From: Miaohe Lin +Date: Thu, 17 Feb 2022 22:53:27 +0800 +Subject: memblock: use kfree() to release kmalloced memblock regions + +From: Miaohe Lin + +commit c94afc46cae7ad41b2ad6a99368147879f4b0e56 upstream. + +memblock.{reserved,memory}.regions may be allocated using kmalloc() in +memblock_double_array(). Use kfree() to release these kmalloced regions +indicated by memblock_{reserved,memory}_in_slab. + +Signed-off-by: Miaohe Lin +Fixes: 3010f876500f ("mm: discard memblock data later") +Signed-off-by: Mike Rapoport +Signed-off-by: Greg Kroah-Hartman +--- + mm/memblock.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +--- a/mm/memblock.c ++++ b/mm/memblock.c +@@ -260,14 +260,20 @@ void __init memblock_discard(void) + addr = __pa(memblock.reserved.regions); + size = PAGE_ALIGN(sizeof(struct memblock_region) * + memblock.reserved.max); +- __memblock_free_late(addr, size); ++ if (memblock_reserved_in_slab) ++ kfree(memblock.reserved.regions); ++ else ++ __memblock_free_late(addr, size); + } + + if (memblock.memory.regions != memblock_memory_init_regions) { + addr = __pa(memblock.memory.regions); + size = PAGE_ALIGN(sizeof(struct memblock_region) * + memblock.memory.max); +- __memblock_free_late(addr, size); ++ if (memblock_memory_in_slab) ++ kfree(memblock.memory.regions); ++ else ++ __memblock_free_late(addr, size); + } + } + #endif diff --git a/queue-4.14/revert-drm-nouveau-pmu-gm200-avoid-touching-pmu-outside-of-devinit-preos-acr.patch b/queue-4.14/revert-drm-nouveau-pmu-gm200-avoid-touching-pmu-outside-of-devinit-preos-acr.patch new file mode 100644 index 00000000000..a66cdcee0bc --- /dev/null +++ b/queue-4.14/revert-drm-nouveau-pmu-gm200-avoid-touching-pmu-outside-of-devinit-preos-acr.patch @@ -0,0 +1,99 @@ +From kherbst@redhat.com Mon Feb 28 11:53:27 2022 +From: Karol Herbst +Date: Mon, 28 Feb 2022 10:12:59 +0100 +Subject: Revert "drm/nouveau/pmu/gm200-: avoid touching PMU outside of DEVINIT/PREOS/ACR" +To: stable@vger.kernel.org +Cc: Karol Herbst , Ben Skeggs , Lyude Paul +Message-ID: <20220228091259.996188-1-kherbst@redhat.com> + +From: Karol Herbst + +This reverts commit c9ec3d85c0eef7c71cdc68db758e0f0e378132c0. + +This commit causes a regression if 4cdd2450bf739bada353e82d27b00db9af8c3001 +is not applied as well. This was fixed for 5.16, 5.15 and 5.10. + +On older stable branches backporting this commit is complicated as relevant +code changed quite a bit. Furthermore most of the affected hardware barely +works on those and users would want to use the newer kernels anyway. + +Cc: stable@vger.kernel.org # 5.4 4.19 and 4.14 +Cc: Ben Skeggs +Cc: Lyude Paul +Link: https://gitlab.freedesktop.org/drm/nouveau/-/issues/149 +Signed-off-by: Karol Herbst +Signed-off-by: Greg Kroah-Hartman +--- + drivers/gpu/drm/nouveau/nvkm/subdev/pmu/base.c | 37 ++++++++++--------------- + 1 file changed, 16 insertions(+), 21 deletions(-) + +--- a/drivers/gpu/drm/nouveau/nvkm/subdev/pmu/base.c ++++ b/drivers/gpu/drm/nouveau/nvkm/subdev/pmu/base.c +@@ -70,13 +70,20 @@ nvkm_pmu_fini(struct nvkm_subdev *subdev + return 0; + } + +-static void ++static int + nvkm_pmu_reset(struct nvkm_pmu *pmu) + { + struct nvkm_device *device = pmu->subdev.device; + + if (!pmu->func->enabled(pmu)) +- return; ++ return 0; ++ ++ /* Inhibit interrupts, and wait for idle. */ ++ nvkm_wr32(device, 0x10a014, 0x0000ffff); ++ nvkm_msec(device, 2000, ++ if (!nvkm_rd32(device, 0x10a04c)) ++ break; ++ ); + + /* Reset. */ + if (pmu->func->reset) +@@ -87,37 +94,25 @@ nvkm_pmu_reset(struct nvkm_pmu *pmu) + if (!(nvkm_rd32(device, 0x10a10c) & 0x00000006)) + break; + ); ++ ++ return 0; + } + + static int + nvkm_pmu_preinit(struct nvkm_subdev *subdev) + { + struct nvkm_pmu *pmu = nvkm_pmu(subdev); +- nvkm_pmu_reset(pmu); +- return 0; ++ return nvkm_pmu_reset(pmu); + } + + static int + nvkm_pmu_init(struct nvkm_subdev *subdev) + { + struct nvkm_pmu *pmu = nvkm_pmu(subdev); +- struct nvkm_device *device = pmu->subdev.device; +- +- if (!pmu->func->init) +- return 0; +- +- if (pmu->func->enabled(pmu)) { +- /* Inhibit interrupts, and wait for idle. */ +- nvkm_wr32(device, 0x10a014, 0x0000ffff); +- nvkm_msec(device, 2000, +- if (!nvkm_rd32(device, 0x10a04c)) +- break; +- ); +- +- nvkm_pmu_reset(pmu); +- } +- +- return pmu->func->init(pmu); ++ int ret = nvkm_pmu_reset(pmu); ++ if (ret == 0 && pmu->func->init) ++ ret = pmu->func->init(pmu); ++ return ret; + } + + static int diff --git a/queue-4.14/series b/queue-4.14/series index 3307ae004e2..b0e2326fac2 100644 --- a/queue-4.14/series +++ b/queue-4.14/series @@ -26,3 +26,6 @@ xhci-re-initialize-the-hc-during-resume-if-hce-was-set.patch xhci-prevent-futile-urb-re-submissions-due-to-incorrect-return-value.patch tty-n_gsm-fix-encoding-of-control-signal-octet-bit-dv.patch tty-n_gsm-fix-proper-link-termination-after-failed-open.patch +revert-drm-nouveau-pmu-gm200-avoid-touching-pmu-outside-of-devinit-preos-acr.patch +memblock-use-kfree-to-release-kmalloced-memblock-regions.patch +fget-clarify-and-improve-__fget_files-implementation.patch