13 Jan, 2016
40 commits
-
checkpatch.pl wants arrays of strings declared as follows:
static const char * const names[] = { "vq-1", "vq-2", "vq-3" };
Currently the find_vqs() function takes a const char *names[] argument
so passing checkpatch.pl's const char * const names[] results in a
compiler error due to losing the second const.This patch adjusts the find_vqs() prototype and updates all virtio
transports. This makes it possible for virtio_balloon.c, virtio_input.c,
virtgpu_kms.c, and virtio_rpmsg_bus.c to use the checkpatch.pl-friendly
type.Signed-off-by: Stefan Hajnoczi
Signed-off-by: Michael S. Tsirkin
Acked-by: Bjorn Andersson -
In balloon_page_dequeue, pages_lock should cover the loop
(ie, list_for_each_entry_safe). Otherwise, the cursor page could
be isolated by compaction and then list_del by isolation could
poison the page->lru.{prev,next} so the loop finally could
access wrong address like this. This patch fixes the bug.general protection fault: 0000 [#1] SMP
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in:
CPU: 2 PID: 82 Comm: vballoon Not tainted 4.4.0-rc5-mm1-access_bit+ #1906
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
task: ffff8800a7ff0000 ti: ffff8800a7fec000 task.ti: ffff8800a7fec000
RIP: 0010:[] [] balloon_page_dequeue+0x54/0x130
RSP: 0018:ffff8800a7fefdc0 EFLAGS: 00010246
RAX: ffff88013fff9a70 RBX: ffffea000056fe00 RCX: 0000000000002b7d
RDX: ffff88013fff9a70 RSI: ffffea000056fe00 RDI: ffff88013fff9a68
RBP: ffff8800a7fefde8 R08: ffffea000056fda0 R09: 0000000000000000
R10: ffff8800a7fefd90 R11: 0000000000000001 R12: dead0000000000e0
R13: ffffea000056fe20 R14: ffff880138809070 R15: ffff880138809060
FS: 0000000000000000(0000) GS:ffff88013fc40000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 00007f229c10e000 CR3: 00000000b8b53000 CR4: 00000000000006a0
Stack:
0000000000000100 ffff880138809088 ffff880138809000 ffff880138809060
0000000000000046 ffff8800a7fefe28 ffffffff812c86d3 ffff880138809020
ffff880138809000 fffffffffff91900 0000000000000100 ffff880138809060
Call Trace:
[] leak_balloon+0x93/0x1a0
[] balloon+0x217/0x2a0
[] ? __schedule+0x31e/0x8b0
[] ? abort_exclusive_wait+0xb0/0xb0
[] ? update_balloon_stats+0xf0/0xf0
[] kthread+0xc9/0xe0
[] ? kthread_park+0x60/0x60
[] ret_from_fork+0x3f/0x70
[] ? kthread_park+0x60/0x60
Code: 8d 60 e0 0f 84 af 00 00 00 48 8b 43 20 a8 01 75 3b 48 89 d8 f0 0f ba 28 00 72 10 48 8b 03 f6 c4 08 75 2f 48 89 df e8 8c 83 f9 ff 8b 44 24 20 4d 8d 6c 24 20 48 83 e8 20 4d 39 f5 74 7a 4c 89
RIP [] balloon_page_dequeue+0x54/0x130
RSP
---[ end trace 43cf28060d708d5f ]---
Kernel panic - not syncing: Fatal exception
Dumping ftrace buffer:
(ftrace buffer empty)
Kernel Offset: disabledCc:
Signed-off-by: Minchan Kim
Signed-off-by: Michael S. Tsirkin
Acked-by: Rafael Aquini -
During my compaction-related stuff, I encountered a bug
with ballooning.With repeated inflating and deflating cycle, guest memory(
ie, cat /proc/meminfo | grep MemTotal) is decreased and
couldn't be recovered.The reason is balloon_lock doesn't cover release_pages_balloon
so struct virtio_balloon fields could be overwritten by race
of fill_balloon(e,g, vb->*pfns could be critical).This patch fixes it in my test.
Cc:
Signed-off-by: Minchan Kim
Signed-off-by: Michael S. Tsirkin -
As per: lkml.kernel.org/r/20150921112252.3c2937e1@mschwide
atomics imply a barrier on s390, so s390 should change
smp_mb__before_atomic and smp_mb__after_atomic to barrier() instead of
smp_mb() and hence should not use the generic versions.Suggested-by: Peter Zijlstra
Suggested-by: Martin Schwidefsky
Signed-off-by: Michael S. Tsirkin
Acked-by: Martin Schwidefsky
Acked-by: Peter Zijlstra (Intel) -
The s390 kernel is SMP to 99.99%, we just didn't bother with a
non-smp variant for the memory-barriers. If the generic header
is used we'd get the non-smp version for free. It will save a
small amount of text space for CONFIG_SMP=n.Suggested-by: Martin Schwidefsky
Signed-off-by: Michael S. Tsirkin
Acked-by: Peter Zijlstra (Intel) -
drivers/xen/events/events_fifo.c uses rmb() to communicate with the
other side.For guests compiled with CONFIG_SMP, smp_rmb would be sufficient, so
rmb() here is only needed if a non-SMP guest runs on an SMP host.Switch to the virt_rmb barrier which serves this exact purpose.
Pull in asm/barrier.h here to make sure the file is self-contained.
Suggested-by: David Vrabel
Signed-off-by: Michael S. Tsirkin
Acked-by: David Vrabel
Acked-by: Peter Zijlstra (Intel) -
include/xen/interface/io/ring.h uses
full memory barriers to communicate with the other side.For guests compiled with CONFIG_SMP, smp_wmb and smp_mb
would be sufficient, so mb() and wmb() here are only needed if
a non-SMP guest runs on an SMP host.Switch to virt_xxx barriers which serve this exact purpose.
Signed-off-by: Michael S. Tsirkin
Acked-by: David Vrabel
Acked-by: Peter Zijlstra (Intel) -
drivers/xen/xenbus/xenbus_comms.c uses
full memory barriers to communicate with the other side.For guests compiled with CONFIG_SMP, smp_wmb and smp_mb
would be sufficient, so mb() and wmb() here are only needed if
a non-SMP guest runs on an SMP host.Switch to virt_xxx barriers which serve this exact purpose.
Signed-off-by: Michael S. Tsirkin
Acked-by: David Vrabel
Acked-by: Peter Zijlstra (Intel) -
We need a full barrier after writing out event index, using
virt_store_mb there seems better than open-coding. As usual, we need a
wrapper to account for strong barriers.It's tempting to use this in vhost as well, for that, we'll
need a variant of smp_store_mb that works on __user pointers.Signed-off-by: Michael S. Tsirkin
Acked-by: Peter Zijlstra (Intel) -
Looks like future sh variants will support a 4-byte cas which will be
used to implement 1 and 2 byte xchg.This is exactly what we do for llsc now, move the portable part of the
code into a separate header so it's easy to reuse.Suggested-by: Rich Felker
Signed-off-by: Michael S. Tsirkin
Acked-by: Peter Zijlstra (Intel) -
This completes the xchg implementation for sh architecture. Note: The
llsc variant is tricky since this only supports 4 byte atomics, the
existing implementation of 1 byte xchg is wrong: we need to do a 4 byte
cmpxchg and retry if any bytes changed meanwhile.Write this in C for clarity.
Suggested-by: Rich Felker
Signed-off-by: Michael S. Tsirkin
Acked-by: Peter Zijlstra (Intel) -
virtio ring uses smp_wmb on SMP and wmb on !SMP,
the reason for the later being that it might be
talking to another kernel on the same SMP machine.This is exactly what virt_xxx barriers do,
so switch to these instead of homegrown ifdef hacks.Cc: Peter Zijlstra
Cc: Alexander Duyck
Signed-off-by: Michael S. Tsirkin
Acked-by: Peter Zijlstra (Intel) -
This reverts commit 9e1a27ea42691429e31f158cce6fc61bc79bb2e9.
While that commit optimizes !CONFIG_SMP, it mixes
up DMA and SMP concepts, making the code hard
to figure out.A better way to optimize this is with the new __smp_XXX
barriers.As a first step, go back to full rmb/wmb barriers
for !SMP.
We switch to __smp_XXX barriers in the next patch.Cc: Peter Zijlstra
Cc: Alexander Duyck
Signed-off-by: Michael S. Tsirkin
Acked-by: Peter Zijlstra (Intel) -
Guests running within virtual machines might be affected by SMP effects even if
the guest itself is compiled without SMP support. This is an artifact of
interfacing with an SMP host while running an UP kernel. Using mandatory
barriers for this use-case would be possible but is often suboptimal.In particular, virtio uses a bunch of confusing ifdefs to work around
this, while xen just uses the mandatory barriers.To better handle this case, low-level virt_mb() etc macros are made available.
These are implemented trivially using the low-level __smp_xxx macros,
the purpose of these wrappers is to annotate those specific cases.These have the same effect as smp_mb() etc when SMP is enabled, but generate
identical code for SMP and non-SMP systems. For example, virtual machine guests
should use virt_mb() rather than smp_mb() when synchronizing against a
(possibly SMP) host.Suggested-by: David Miller
Signed-off-by: Michael S. Tsirkin
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for x86,
for use by virtualization.smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hSigned-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel)
Reviewed-by: Thomas Gleixner -
This defines __smp_xxx barriers for xtensa,
for use by virtualization.smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hSigned-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for tile,
for use by virtualization.Some smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hNote: for 32 bit, keep smp_mb__after_atomic around since it's faster
than the generic implementation.Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for sparc,
for use by virtualization.smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hSigned-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: David S. Miller
Acked-by: Peter Zijlstra (Intel) -
sh variant of smp_store_mb() calls xchg() on !SMP which is stronger than
implied by both the name and the documentation.define __smp_store_mb instead: code in asm-generic/barrier.h
will then define smp_store_mb correctly depending on
CONFIG_SMP.Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for s390,
for use by virtualization.Some smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hNote: smp_mb, smp_rmb and smp_wmb are defined as full barriers
unconditionally on this architecture.Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Martin Schwidefsky
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for mips,
for use by virtualization.smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hNote: the only exception is smp_mb__before_llsc which is mips-specific.
We define both the __smp_mb__before_llsc variant (for use in
asm/barriers.h) and smp_mb__before_llsc (for use elsewhere on this
architecture).Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for metag,
for use by virtualization.smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hNote: as __smp_XX macros should not depend on CONFIG_SMP, they can not
use the existing fence() macro since that is defined differently between
SMP and !SMP. For this reason, this patch introduces a wrapper
metag_fence() that doesn't depend on CONFIG_SMP.
fence() is then defined using that, depending on CONFIG_SMP.Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: James Hogan
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for ia64,
for use by virtualization.smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hThis reduces the amount of arch-specific boiler-plate code.
Signed-off-by: Michael S. Tsirkin
Acked-by: Tony Luck
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for blackfin,
for use by virtualization.smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hSigned-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for arm,
for use by virtualization.smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hThis reduces the amount of arch-specific boiler-plate code.
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Russell King
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for arm64,
for use by virtualization.smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hNote: arm64 does not support !SMP config,
so smp_xxx and __smp_xxx are always equivalent.Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
This defines __smp_xxx barriers for powerpc
for use by virtualization.smp_xxx barriers are removed as they are
defined correctly by asm-generic/barriers.hThis reduces the amount of arch-specific boiler-plate code.
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Boqun Feng
Acked-by: Peter Zijlstra (Intel) -
On !SMP, most architectures define their
barriers as compiler barriers.
On SMP, most need an actual barrier.Make it possible to remove the code duplication for
!SMP by defining low-level __smp_xxx barriers
which do not depend on the value of SMP, then
use them from asm-generic conditionally.Besides reducing code duplication, these low level APIs will also be
useful for virtualization, where a barrier is sometimes needed even if
!SMP since we might be talking to another kernel on the same SMP system.Both virtio and Xen drivers will benefit.
The smp_xxx variants should use __smp_XXX ones or barrier() depending on
SMP, identically for all architectures.We keep ifndef guards around them for now - once/if all
architectures are converted to use the generic
code, we'll be able to remove these.Suggested-by: Peter Zijlstra
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
As on most architectures, on x86 read_barrier_depends and
smp_read_barrier_depends are empty. Drop the local definitions and pull
the generic ones from asm-generic/barrier.h instead: they are identical.This is in preparation to refactoring this code area.
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel)
Reviewed-by: Thomas Gleixner -
On x86/um CONFIG_SMP is never defined. As a result, several macros
match the asm-generic variant exactly. Drop the local definitions and
pull in asm-generic/barrier.h instead.This is in preparation to refactoring this code area.
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Richard Weinberger
Acked-by: Peter Zijlstra (Intel) -
On mips dma_rmb, dma_wmb, smp_store_mb, read_barrier_depends,
smp_read_barrier_depends, smp_store_release and smp_load_acquire match
the asm-generic variants exactly. Drop the local definitions and pull in
asm-generic/barrier.h instead.This is in preparation to refactoring this code area.
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
On metag dma_rmb, dma_wmb, smp_store_mb, read_barrier_depends,
smp_read_barrier_depends, smp_store_release and smp_load_acquire match
the asm-generic variants exactly. Drop the local definitions and pull in
asm-generic/barrier.h instead.This is in preparation to refactoring this code area.
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: James Hogan
Acked-by: Peter Zijlstra (Intel) -
On arm64 nop, read_barrier_depends, smp_read_barrier_depends
smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the
asm-generic variants exactly. Drop the local definitions and pull in
asm-generic/barrier.h instead.This is in preparation to refactoring this code area.
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
On arm smp_store_mb, read_barrier_depends, smp_read_barrier_depends,
smp_store_release, smp_load_acquire, smp_mb__before_atomic and
smp_mb__after_atomic match the asm-generic variants exactly. Drop the
local definitions and pull in asm-generic/barrier.h instead.This is in preparation to refactoring this code area.
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Russell King
Acked-by: Peter Zijlstra (Intel) -
On sparc 64 bit dma_rmb, dma_wmb, smp_store_mb, smp_mb, smp_rmb,
smp_wmb, read_barrier_depends and smp_read_barrier_depends match the
asm-generic variants exactly. Drop the local definitions and pull in
asm-generic/barrier.h instead.nop uses __asm__ __volatile but is otherwise identical to
the generic version, drop that as well.This is in preparation to refactoring this code area.
Note: nop() was in processor.h and not in barrier.h as on other
architectures. Nothing seems to depend on it being there though.Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: David S. Miller
Acked-by: Peter Zijlstra (Intel) -
On s390 read_barrier_depends, smp_read_barrier_depends
smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the
asm-generic variants exactly. Drop the local definitions and pull in
asm-generic/barrier.h instead.This is in preparation to refactoring this code area.
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
On powerpc read_barrier_depends, smp_read_barrier_depends
smp_store_mb(), smp_mb__before_atomic and smp_mb__after_atomic match the
asm-generic variants exactly. Drop the local definitions and pull in
asm-generic/barrier.h instead.This is in preparation to refactoring this code area.
Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel)
Reviewed-by: Paul E. McKenney -
On ia64 smp_rmb, smp_wmb, read_barrier_depends, smp_read_barrier_depends
and smp_store_mb() match the asm-generic variants exactly. Drop the
local definitions and pull in asm-generic/barrier.h instead.This is in preparation to refactoring this code area.
Signed-off-by: Michael S. Tsirkin
Acked-by: Tony Luck
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
asm-generic/barrier.h defines a nop() macro.
To be able to use this header on ia64, we shouldn't
call local functions/variables nop().There's one instance where this breaks on ia64:
rename the function to iosapic_nop to avoid the conflict.Signed-off-by: Michael S. Tsirkin
Acked-by: Tony Luck
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel) -
Allow architectures to override smp_store_release
and smp_load_acquire by guarding the defines
in asm-generic/barrier.h with ifndef directives.This is in preparation to reusing asm-generic/barrier.h
on architectures which have their own definition
of these macros.Signed-off-by: Michael S. Tsirkin
Acked-by: Arnd Bergmann
Acked-by: Peter Zijlstra (Intel)