All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 4.19 001/244] gfs2: Fix lru_count going negative
@ 2019-05-22 19:22 ` Sasha Levin
  0 siblings, 0 replies; 97+ messages in thread
From: Sasha Levin @ 2019-05-22 19:22 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Ross Lagerwall, Andreas Gruenbacher, Sasha Levin, cluster-devel

From: Ross Lagerwall <ross.lagerwall@citrix.com>

[ Upstream commit 7881ef3f33bb80f459ea6020d1e021fc524a6348 ]

Under certain conditions, lru_count may drop below zero resulting in
a large amount of log spam like this:

vmscan: shrink_slab: gfs2_dump_glock+0x3b0/0x630 [gfs2] \
    negative objects to delete nr=-1

This happens as follows:
1) A glock is moved from lru_list to the dispose list and lru_count is
   decremented.
2) The dispose function calls cond_resched() and drops the lru lock.
3) Another thread takes the lru lock and tries to add the same glock to
   lru_list, checking if the glock is on an lru list.
4) It is on a list (actually the dispose list) and so it avoids
   incrementing lru_count.
5) The glock is moved to lru_list.
5) The original thread doesn't dispose it because it has been re-added
   to the lru list but the lru_count has still decreased by one.

Fix by checking if the LRU flag is set on the glock rather than checking
if the glock is on some list and rearrange the code so that the LRU flag
is added/removed precisely when the glock is added/removed from lru_list.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/gfs2/glock.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 9d566e62684c2..775256141e9fb 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -183,15 +183,19 @@ static int demote_ok(const struct gfs2_glock *gl)
 
 void gfs2_glock_add_to_lru(struct gfs2_glock *gl)
 {
+	if (!(gl->gl_ops->go_flags & GLOF_LRU))
+		return;
+
 	spin_lock(&lru_lock);
 
-	if (!list_empty(&gl->gl_lru))
-		list_del_init(&gl->gl_lru);
-	else
+	list_del(&gl->gl_lru);
+	list_add_tail(&gl->gl_lru, &lru_list);
+
+	if (!test_bit(GLF_LRU, &gl->gl_flags)) {
+		set_bit(GLF_LRU, &gl->gl_flags);
 		atomic_inc(&lru_count);
+	}
 
-	list_add_tail(&gl->gl_lru, &lru_list);
-	set_bit(GLF_LRU, &gl->gl_flags);
 	spin_unlock(&lru_lock);
 }
 
@@ -201,7 +205,7 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
 		return;
 
 	spin_lock(&lru_lock);
-	if (!list_empty(&gl->gl_lru)) {
+	if (test_bit(GLF_LRU, &gl->gl_flags)) {
 		list_del_init(&gl->gl_lru);
 		atomic_dec(&lru_count);
 		clear_bit(GLF_LRU, &gl->gl_flags);
@@ -1158,8 +1162,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
 		    !test_bit(GLF_DEMOTE, &gl->gl_flags))
 			fast_path = 1;
 	}
-	if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl) &&
-	    (glops->go_flags & GLOF_LRU))
+	if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl))
 		gfs2_glock_add_to_lru(gl);
 
 	trace_gfs2_glock_queue(gh, 0);
@@ -1455,6 +1458,7 @@ __acquires(&lru_lock)
 		if (!spin_trylock(&gl->gl_lockref.lock)) {
 add_back_to_lru:
 			list_add(&gl->gl_lru, &lru_list);
+			set_bit(GLF_LRU, &gl->gl_flags);
 			atomic_inc(&lru_count);
 			continue;
 		}
@@ -1462,7 +1466,6 @@ __acquires(&lru_lock)
 			spin_unlock(&gl->gl_lockref.lock);
 			goto add_back_to_lru;
 		}
-		clear_bit(GLF_LRU, &gl->gl_flags);
 		gl->gl_lockref.count++;
 		if (demote_ok(gl))
 			handle_callback(gl, LM_ST_UNLOCKED, 0, false);
@@ -1497,6 +1500,7 @@ static long gfs2_scan_glock_lru(int nr)
 		if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
 			list_move(&gl->gl_lru, &dispose);
 			atomic_dec(&lru_count);
+			clear_bit(GLF_LRU, &gl->gl_flags);
 			freed++;
 			continue;
 		}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 97+ messages in thread

end of thread, other threads:[~2019-05-22 19:54 UTC | newest]

Thread overview: 97+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 19:22 [PATCH AUTOSEL 4.19 001/244] gfs2: Fix lru_count going negative Sasha Levin
2019-05-22 19:22 ` [Cluster-devel] " Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 002/244] cxgb4: Fix error path in cxgb4_init_module Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 003/244] NFS: make nfs_match_client killable Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 004/244] IB/hfi1: Fix WQ_MEM_RECLAIM warning Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 005/244] gfs2: Fix occasional glock use-after-free Sasha Levin
2019-05-22 19:22   ` [Cluster-devel] " Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 006/244] mmc: core: Verify SD bus width Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 007/244] batman-adv: mcast: fix multicast tt/tvlv worker locking Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 008/244] tools/bpf: fix perf build error with uClibc (seen on ARC) Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 009/244] selftests/bpf: set RLIMIT_MEMLOCK properly for test_libbpf_open.c Sasha Levin
2019-05-22 19:22   ` Sasha Levin
2019-05-22 19:22   ` sashal
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 010/244] bpftool: exclude bash-completion/bpftool from .gitignore pattern Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 011/244] dmaengine: tegra210-dma: free dma controller in remove() Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 012/244] net: ena: gcc 8: fix compilation warning Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 013/244] hv_netvsc: fix race that may miss tx queue wakeup Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 014/244] orangefs: truncate before updating size Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 015/244] Bluetooth: Ignore CC events not matching the last HCI command Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 016/244] pinctrl: zte: fix leaked of_node references Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 017/244] ASoC: Intel: kbl_da7219_max98357a: Map BTN_0 to KEY_PLAYPAUSE Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 018/244] usb: dwc2: gadget: Increase descriptors count for ISOC's Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 019/244] usb: dwc3: move synchronize_irq() out of the spinlock protected block Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 020/244] ASoC: hdmi-codec: unlock the device on startup errors Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 021/244] leds: avoid races with workqueue Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 022/244] powerpc/perf: Return accordingly on invalid chip-id in Sasha Levin
2019-05-22 19:22   ` Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 023/244] powerpc/boot: Fix missing check of lseek() return value Sasha Levin
2019-05-22 19:22   ` Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 024/244] powerpc/perf: Fix loop exit condition in nest_imc_event_init Sasha Levin
2019-05-22 19:22   ` Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 025/244] ASoC: imx: fix fiq dependencies Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 026/244] spi: pxa2xx: fix SCR (divisor) calculation Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 027/244] brcm80211: potential NULL dereference in brcmf_cfg80211_vndr_cmds_dcmd_handler() Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 028/244] ACPI / property: fix handling of data_nodes in acpi_get_next_subnode() Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 029/244] drm/nouveau/bar/nv50: ensure BAR is mapped Sasha Levin
2019-05-22 19:22   ` Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 030/244] media: stm32-dcmi: return appropriate error codes during probe Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 031/244] ARM: vdso: Remove dependency with the arch_timer driver internals Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 032/244] arm64: Fix compiler warning from pte_unmap() with -Wunused-but-set-variable Sasha Levin
2019-05-22 19:22 ` [PATCH AUTOSEL 4.19 033/244] powerpc/watchdog: Use hrtimers for per-CPU heartbeat Sasha Levin
2019-05-22 19:22   ` Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 034/244] sched/cpufreq: Fix kobject memleak Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 035/244] scsi: qla2xxx: Fix a qla24xx_enable_msix() error path Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 036/244] scsi: qla2xxx: Fix abort handling in tcm_qla2xxx_write_pending() Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 037/244] scsi: qla2xxx: Avoid that lockdep complains about unsafe locking in tcm_qla2xxx_close_session() Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 038/244] scsi: qla2xxx: Fix hardirq-unsafe locking Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 039/244] x86/modules: Avoid breaking W^X while loading modules Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 040/244] Btrfs: fix data bytes_may_use underflow with fallocate due to failed quota reserve Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 041/244] btrfs: fix panic during relocation after ENOSPC before writeback happens Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 042/244] btrfs: Don't panic when we can't find a root key Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 043/244] iwlwifi: pcie: don't crash on invalid RX interrupt Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 044/244] rtc: 88pm860x: prevent use-after-free on device remove Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 045/244] rtc: stm32: manage the get_irq probe defer case Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 046/244] scsi: qedi: Abort ep termination if offload not scheduled Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 047/244] s390/kexec_file: Fix detection of text segment in ELF loader Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 048/244] sched/nohz: Run NOHZ idle load balancer on HK_FLAG_MISC CPUs Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 049/244] w1: fix the resume command API Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 050/244] s390: qeth: address type mismatch warning Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 051/244] dmaengine: pl330: _stop: clear interrupt status Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 052/244] mac80211/cfg80211: update bss channel on channel switch Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 053/244] USB: serial: fix initial-termios handling Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 054/244] libbpf: fix samples/bpf build failure due to undefined UINT32_MAX Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 055/244] slimbus: fix a potential NULL pointer dereference in of_qcom_slim_ngd_register Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 056/244] driver core: platform: Fix the usage of platform device name(pdev->name) Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 057/244] ASoC: fsl_sai: Update is_slave_mode with correct value Sasha Levin
2019-05-22 19:23   ` Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 058/244] mwifiex: prevent an array overflow Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 059/244] rsi: Fix NULL pointer dereference in kmalloc Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 060/244] net: cw1200: fix a NULL pointer dereference Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 061/244] at76c50x-usb: Don't register led_trigger if usb_register_driver failed Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 062/244] nvme: set 0 capacity if namespace block size exceeds PAGE_SIZE Sasha Levin
2019-05-22 19:23   ` Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 063/244] nvme-rdma: fix a NULL deref when an admin connect times out Sasha Levin
2019-05-22 19:23   ` Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 064/244] ssb: Fix possible NULL pointer dereference in ssb_host_pcmcia_exit Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 065/244] crypto: sun4i-ss - Fix invalid calculation of hash end Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 066/244] bcache: avoid potential memleak of list of journal_replay(s) in the CACHE_SYNC branch of run_cache_set Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 067/244] bcache: return error immediately in bch_journal_replay() Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 068/244] bcache: fix failure in journal relplay Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 069/244] bcache: add failure check to run_cache_set() for journal replay Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 070/244] bcache: avoid clang -Wunintialized warning Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 071/244] RDMA/cma: Consider scope_id while binding to ipv6 ll address Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 072/244] vfio-ccw: Do not call flush_workqueue while holding the spinlock Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 073/244] vfio-ccw: Release any channel program when releasing/removing vfio-ccw mdev Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 074/244] x86/build: Move _etext to actual end of .text Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 075/244] smpboot: Place the __percpu annotation correctly Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 076/244] x86/mm: Remove in_nmi() warning from 64-bit implementation of vmalloc_fault() Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 077/244] mlxsw: spectrum_router: Prevent ipv6 gateway with v4 route via replace and append Sasha Levin
2019-05-22 19:29   ` David Ahern
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 078/244] mm/uaccess: Use 'unsigned long' to placate UBSAN warnings on older GCC versions Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 079/244] Bluetooth: hci_qca: Give enough time to ROME controller to bootup Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 080/244] HID: logitech-hidpp: use RAP instead of FAP to get the protocol version Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 081/244] pinctrl: pistachio: fix leaked of_node references Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 082/244] pinctrl: samsung: " Sasha Levin
2019-05-22 19:23 ` [PATCH AUTOSEL 4.19 083/244] clk: rockchip: undo several noc and special clocks as critical on rk3288 Sasha Levin
2019-05-22 19:23   ` Sasha Levin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.