• Mark Rutland's avatar
    rcu: Correctly handle sparse possible cpus · bc75e999
    Mark Rutland authored
    In many cases in the RCU tree code, we iterate over the set of cpus for
    a leaf node described by rcu_node::grplo and rcu_node::grphi, checking
    per-cpu data for each cpu in this range. However, if the set of possible
    cpus is sparse, some cpus described in this range are not possible, and
    thus no per-cpu region will have been allocated (or initialised) for
    them by the generic percpu code.
    
    Erroneous accesses to a per-cpu area for these !possible cpus may fault
    or may hit other data depending on the addressed generated when the
    erroneous per cpu offset is applied. In practice, both cases have been
    observed on arm64 hardware (the former being silent, but detectable with
    additional patches).
    
    To avoid issues resulting from this, we must iterate over the set of
    *possible* cpus for a given leaf node. This patch add a new helper,
    for_each_leaf_node_possible_cpu, to enable this. As iteration is often
    intertwined with rcu_node local bitmask manipulation, a new
    leaf_node_cpu_bit helper is added to make this simpler and more
    consistent. The RCU tree code is made to use both of these where
    appropriate.
    
    Without this patch, running reboot at a shell can result in an oops
    like:
    
    [ 3369.075979] Unable to handle kernel paging request at virtual address ffffff8008b21b4c
    [ 3369.083881] pgd = ffffffc3ecdda000
    [ 3369.087270] [ffffff8008b21b4c] *pgd=00000083eca48003, *pud=00000083eca48003, *pmd=0000000000000000
    [ 3369.096222] Internal error: Oops: 96000007 [#1] PREEMPT SMP
    [ 3369.101781] Modules linked in:
    [ 3369.104825] CPU: 2 PID: 1817 Comm: NetworkManager Tainted: G        W       4.6.0+ #3
    [ 3369.121239] task: ffffffc0fa13e000 ti: ffffffc3eb940000 task.ti: ffffffc3eb940000
    [ 3369.128708] PC is at sync_rcu_exp_select_cpus+0x188/0x510
    [ 3369.134094] LR is at sync_rcu_exp_select_cpus+0x104/0x510
    [ 3369.139479] pc : [<ffffff80081109a8>] lr : [<ffffff8008110924>] pstate: 200001c5
    [ 3369.146860] sp : ffffffc3eb9435a0
    [ 3369.150162] x29: ffffffc3eb9435a0 x28: ffffff8008be4f88
    [ 3369.155465] x27: ffffff8008b66c80 x26: ffffffc3eceb2600
    [ 3369.160767] x25: 0000000000000001 x24: ffffff8008be4f88
    [ 3369.166070] x23: ffffff8008b51c3c x22: ffffff8008b66c80
    [ 3369.171371] x21: 0000000000000001 x20: ffffff8008b21b40
    [ 3369.176673] x19: ffffff8008b66c80 x18: 0000000000000000
    [ 3369.181975] x17: 0000007fa951a010 x16: ffffff80086a30f0
    [ 3369.187278] x15: 0000007fa9505590 x14: 0000000000000000
    [ 3369.192580] x13: ffffff8008b51000 x12: ffffffc3eb940000
    [ 3369.197882] x11: 0000000000000006 x10: ffffff8008b51b78
    [ 3369.203184] x9 : 0000000000000001 x8 : ffffff8008be4000
    [ 3369.208486] x7 : ffffff8008b21b40 x6 : 0000000000001003
    [ 3369.213788] x5 : 0000000000000000 x4 : ffffff8008b27280
    [ 3369.219090] x3 : ffffff8008b21b4c x2 : 0000000000000001
    [ 3369.224406] x1 : 0000000000000001 x0 : 0000000000000140
    ...
    [ 3369.972257] [<ffffff80081109a8>] sync_rcu_exp_select_cpus+0x188/0x510
    [ 3369.978685] [<ffffff80081128b4>] synchronize_rcu_expedited+0x64/0xa8
    [ 3369.985026] [<ffffff80086b987c>] synchronize_net+0x24/0x30
    [ 3369.990499] [<ffffff80086ddb54>] dev_deactivate_many+0x28c/0x298
    [ 3369.996493] [<ffffff80086b6bb8>] __dev_close_many+0x60/0xd0
    [ 3370.002052] [<ffffff80086b6d48>] __dev_close+0x28/0x40
    [ 3370.007178] [<ffffff80086bf62c>] __dev_change_flags+0x8c/0x158
    [ 3370.012999] [<ffffff80086bf718>] dev_change_flags+0x20/0x60
    [ 3370.018558] [<ffffff80086cf7f0>] do_setlink+0x288/0x918
    [ 3370.023771] [<ffffff80086d0798>] rtnl_newlink+0x398/0x6a8
    [ 3370.029158] [<ffffff80086cee84>] rtnetlink_rcv_msg+0xe4/0x220
    [ 3370.034891] [<ffffff80086e274c>] netlink_rcv_skb+0xc4/0xf8
    [ 3370.040364] [<ffffff80086ced8c>] rtnetlink_rcv+0x2c/0x40
    [ 3370.045663] [<ffffff80086e1fe8>] netlink_unicast+0x160/0x238
    [ 3370.051309] [<ffffff80086e24b8>] netlink_sendmsg+0x2f0/0x358
    [ 3370.056956] [<ffffff80086a0070>] sock_sendmsg+0x18/0x30
    [ 3370.062168] [<ffffff80086a21cc>] ___sys_sendmsg+0x26c/0x280
    [ 3370.067728] [<ffffff80086a30ac>] __sys_sendmsg+0x44/0x88
    [ 3370.073027] [<ffffff80086a3100>] SyS_sendmsg+0x10/0x20
    [ 3370.078153] [<ffffff8008085e70>] el0_svc_naked+0x24/0x28
    Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
    Reported-by: default avatarDennis Chen <dennis.chen@arm.com>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: Josh Triplett <josh@joshtriplett.org>
    Cc: Lai Jiangshan <jiangshanlai@gmail.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Steve Capper <steve.capper@arm.com>
    Cc: Steven Rostedt <rostedt@goodmis.org>
    Cc: Will Deacon <will.deacon@arm.com>
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
    bc75e999
tree.c 130 KB