#include #include #include "8250.h" /* * Freescale 16550 UART "driver", Copyright (C) 2011 Paul Gortmaker. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This isn't a full driver; it just provides an alternate IRQ * handler to deal with an errata. Everything else is just * using the bog standard 8250 support. * * We follow code flow of serial8250_default_handle_irq() but add * a check for a break and insert a dummy read on the Rx for the * immediately following IRQ event. * * We re-use the already existing "bug handling" lsr_saved_flags * field to carry the "what we just did" information from the one * IRQ event to the next one. */ int fsl8250_handle_irq(struct uart_port *port) { unsigned char lsr, orig_lsr; unsigned long flags; unsigned int iir; struct uart_8250_port *up = up_to_u8250p(port); spin_lock_irqsave(&up->port.lock, flags); iir = port->serial_in(port, UART_IIR); if (iir & UART_IIR_NO_INT) { spin_unlock_irqrestore(&up->port.lock, flags); return 0; } /* This is the WAR; if last event was BRK, then read and return */ if (unlikely(up->lsr_saved_flags & UART_LSR_BI)) { up->lsr_saved_flags &= ~UART_LSR_BI; port->serial_in(port, UART_RX); spin_unlock_irqrestore(&up->port.lock, flags); return 1; } lsr = orig_lsr = up->port.serial_in(&up->port, UART_LSR); if (lsr & (UART_LSR_DR | UART_LSR_BI)) lsr = serial8250_rx_chars(up, lsr); serial8250_modem_status(up); if (lsr & UART_LSR_THRE) serial8250_tx_chars(up); up->lsr_saved_flags = orig_lsr; spin_unlock_irqrestore(&up->port.lock, flags); return 1; } EXPORT_SYMBOL_GPL(fsl8250_handle_irq); ?id=2939e1a86f758b55cdba73e29397dd3d94df13bc'>treecommitdiff
diff options
context:
space:
mode:
authorMaxim Patlasov <mpatlasov@virtuozzo.com>2016-12-12 14:32:44 -0800
committerChris Mason <clm@fb.com>2016-12-13 11:01:30 -0800
commit2939e1a86f758b55cdba73e29397dd3d94df13bc (patch)
tree6024381b6fe04ed125c7bb6b613d3c3d3bf2b983 /net/mac80211/wpa.c
parent5f52a2c512a55500349aa261e469d099ede0f256 (diff)
btrfs: limit async_work allocation and worker func duration
Problem statement: unprivileged user who has read-write access to more than one btrfs subvolume may easily consume all kernel memory (eventually triggering oom-killer). Reproducer (./mkrmdir below essentially loops over mkdir/rmdir): [root@kteam1 ~]# cat prep.sh DEV=/dev/sdb mkfs.btrfs -f $DEV mount $DEV /mnt for i in `seq 1 16` do mkdir /mnt/$i btrfs subvolume create /mnt/SV_$i ID=`btrfs subvolume list /mnt |grep "SV_$i$" |cut -d ' ' -f 2` mount -t btrfs -o subvolid=$ID $DEV /mnt/$i chmod a+rwx /mnt/$i done [root@kteam1 ~]# sh prep.sh [maxim@kteam1 ~]$ for i in `seq 1 16`; do ./mkrmdir /mnt/$i 2000 2000 & done [root@kteam1 ~]# for i in `seq 1 4`; do grep "kmalloc-128" /proc/slabinfo | grep -v dma; sleep 60; done kmalloc-128 10144 10144 128 32 1 : tunables 0 0 0 : slabdata 317 317 0 kmalloc-128 9992352 9992352 128 32 1 : tunables 0 0 0 : slabdata 312261 312261 0 kmalloc-128 24226752 24226752 128 32 1 : tunables 0 0 0 : slabdata 757086 757086 0 kmalloc-128 42754240 42754240 128 32 1 : tunables 0 0 0 : slabdata 1336070 1336070 0 The huge numbers above come from insane number of async_work-s allocated and queued by btrfs_wq_run_delayed_node. The problem is caused by btrfs_wq_run_delayed_node() queuing more and more works if the number of delayed items is above BTRFS_DELAYED_BACKGROUND. The worker func (btrfs_async_run_delayed_root) processes at least BTRFS_DELAYED_BATCH items (if they are present in the list). So, the machinery works as expected while the list is almost empty. As soon as it is getting bigger, worker func starts to process more than one item at a time, it takes longer, and the chances to have async_works queued more than needed is getting higher. The problem above is worsened by another flaw of delayed-inode implementation: if async_work was queued in a throttling branch (number of items >= BTRFS_DELAYED_WRITEBACK), corresponding worker func won't quit until the number of items < BTRFS_DELAYED_BACKGROUND / 2. So, it is possible that the func occupies CPU infinitely (up to 30sec in my experiments): while the func is trying to drain the list, the user activity may add more and more items to the list. The patch fixes both problems in straightforward way: refuse queuing too many works in btrfs_wq_run_delayed_node and bail out of worker func if at least BTRFS_DELAYED_WRITEBACK items are processed. Changed in v2: remove support of thresh == NO_THRESHOLD. Signed-off-by: Maxim Patlasov <mpatlasov@virtuozzo.com> Signed-off-by: Chris Mason <clm@fb.com> Cc: stable@vger.kernel.org # v3.15+
Diffstat (limited to 'net/mac80211/wpa.c')