ptr_ring: fix race conditions when resizing
Michael S. Tsirkin authored

Resizing currently drops consumer lock.  This can cause entries to be
reordered, which isn't good in itself.  More importantly, consumer can
detect a false ring empty condition and block forever.

Further, nesting of consumer within producer lock is problematic for
tun, since it produces entries in a BH, which causes a lock order
reversal:

       CPU0                    CPU1
       ----                    ----
  consume:
  lock(&(&r->consumer_lock)->rlock);
                               resize:
                               local_irq_disable();
                               lock(&(&r->producer_lock)->rlock);
                               lock(&(&r->consumer_lock)->rlock);
  <Interrupt>
  produce:
  lock(&(&r->producer_lock)->rlock);

To fix, nest producer lock within consumer lock during resize,
and keep consumer lock during the whole swap operation.
Reported-by: default avatarDmitry Vyukov <dvyukov@google.com>
Cc: stable@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
e7169530
Name Last commit Last update
Documentation GTP: Add some basic documentation about drivers/net/gtp.c
arch Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
block cfq-iosched: don't call wbt_disable_default() with IRQs disabled
certs certs: Add a secondary system keyring that can be added to dynamically
crypto crypto: algif_aead - Fix kernel panic on list_del
drivers net: qlogic: qla3xxx: use new api ethtool_{get|set}_link_ksettings
firmware WHENCE: use https://linuxtv.org for LinuxTV URLs
fs gfs2: Use rhashtable walk interface in glock_hash_walk
include ptr_ring: fix race conditions when resizing
init kbuild: modversions: add infrastructure for emitting relative CRCs
ipc ipc/sem.c: fix incorrect sem_lock pairing
kernel Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
lib rhashtable: Add nested tables
mm mm/slub.c: fix random_seq offset destruction
net sctp: add support for MSG_MORE
samples Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
scripts kbuild: modversions: add infrastructure for emitting relative CRCs
security Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
sound ALSA: hda - adding a new NV HDMI/DP codec ID in the driver
tools Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
usr kbuild: initramfs cleanup, set target from Kconfig
virt Merge tag 'kvm-arm-for-4.10-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm
.cocciconfig scripts: add Linux .cocciconfig for coccinelle
.get_maintainer.ignore Add hch to .get_maintainer.ignore
.gitattributes .gitattributes: set git diff driver for C source code files
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Linux kernel
============

This file was moved to Documentation/admin-guide/README.rst

Please notice that there are several guides for kernel developers and users.
These guides can be rendered in a number of formats, like HTML and PDF.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.
See Documentation/00-INDEX for a list of what is contained in each file.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.