Subject: [linux-next][DLPAR] kernel BUG at arch/powerpc/lib/locks.c:34!

From: Abdul Haleem <[email-masked]>
Date: Fri, 29 Sep 2017 11:43:20 +0530

Hi,

Memory hot-unplug operation on linux-next kernel (4K pagesize) results
in BUG_ON() at arch/powerpc/lib/locks.c

/*
 * Waiting for a read lock or a write lock on a rwlock...
 * This turns out to be the same for read and write locks, since
 * we only know the holder if it is write-locked.
 */
void __rw_yield(arch_rwlock_t *rw)
{
    int lock_value;
    unsigned int holder_cpu, yield_count;

    lock_value = rw->lock;
    if (lock_value >= 0)
        return;     /* no write lock at present */
    holder_cpu = lock_value & 0xffff;
>>  BUG_ON(holder_cpu >= NR_CPUS);
    yield_count = be32_to_cpu(lppaca_of(holder_cpu).yield_count);
    if ((yield_count & 1) == 0)
        return;     /* virtual cpu is currently running */
    rmb();

Machine Type: Power 8 PowerVM LPAR
kernel : 4.14.0-rc2-next-20170928
gcc: version 6.3.1
Test : DLPAR Memory
config:
CONFIG_PPC_4K_PAGES=y
# CONFIG_PPC_64K_PAGES is not set

logs:
----
Offlined Pages 65536
Offlined Pages 65536
Offlined Pages 65536
Offlined Pages 65536
------------[ cut here ]------------
kernel BUG at arch/powerpc/lib/locks.c:34!
Oops: Exception in kernel mode, sig: 5 [#1]
LE SMP NR_CPUS=2048 NUMA pSeries
Dumping ftrace buffer: 
   (ftrace buffer empty)
Modules linked in: rpadlpar_io rpaphp bridge stp llc xt_tcpudp ipt_REJECT nf_reject_ipv4 xt_conntrack nfnetlink iptable_mangle iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_filter vmx_crypto pseries_rng rng_core binfmt_misc nfsd ip_tables x_tables autofs4
CPU: 0 PID: 12030 Comm: touch Not tainted 4.14.0-rc2-next-20170928-autotest #1
task: c000000271aecc00 task.stack: c00000026c24c000
NIP:  c0000000016a50d0 LR: c0000000017ff2c4 CTR: c000000001af4270
REGS: c00000026c24f860 TRAP: 0700   Not tainted  (4.14.0-rc2-next-20170928-autotest)
MSR:  8000000000029033 <SF,EE,ME,IR,DR,RI,LE>  CR: 42008884  XER: 00000000  
CFAR: c0000000017ff2c0 SOFTE: 1 
GPR00: c0000000017ff2c4 c00000026c24fae0 c000000003572500 c00000026b7f37f0 
GPR04: 0000000000000002 c000000270179b10 c000000003622500 0000000000103265 
GPR08: 0000000000000001 000000000000a1e0 000000000323a1e0 c000000270060420 
GPR12: 0000000082008288 c00000000fdc0000 0000000000000000 0000000000000000 
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 
GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000002 
GPR24: c000000002b252f0 c00000026b7f37f0 fffffffffffffffd c000000271aecc00 
GPR28: c000000270008000 c00000026b7f37e8 c00000026b7f37f0 c00000000361ff50 
NIP [c0000000016a50d0] __spin_yield+0x60/0x130
LR [c0000000017ff2c4] do_raw_spin_lock+0x2d4/0x2e0
Call Trace:
[c00000026c24fae0] [c00000026c24fb30] 0xc00000026c24fb30 (unreliable)
[c00000026c24fb50] [c0000000017ff2c4] do_raw_spin_lock+0x2d4/0x2e0
[c00000026c24fb80] [c0000000027ca540] _raw_spin_lock+0x40/0x70
[c00000026c24fba0] [c0000000027bfbf0] __mutex_lock.isra.0+0x1a0/0x11f0
[c00000026c24fca0] [c0000000027c0f24] __mutex_lock_slowpath+0x44/0x70
[c00000026c24fcc0] [c0000000027c0ff4] mutex_lock+0xa4/0xd0
[c00000026c24fce0] [c000000001af42b8] pipe_release+0x48/0x1e0
[c00000026c24fd20] [c000000001ae0efc] __fput+0x12c/0x4f0
[c00000026c24fd80] [c000000001ae12ec] ____fput+0x2c/0x50
[c00000026c24fda0] [c00000000178eb3c] task_work_run+0x17c/0x200
[c00000026c24fe00] [c00000000160adb8] do_notify_resume+0x1f8/0x220
[c00000026c24fe30] [c0000000015ebec4] ret_from_except_lite+0x70/0x74
Instruction dump:
2faa0000 39290001 f926da50 419e0078 3ce2000b e8e7da60 5549043e 3cc2000b 
210907ff 79080fe0 38e70001 f8e6da60 <0b080000> 3ce20007 38e7ea78 1d290480 
---[ end trace 1343a8353f7a1a73 ]---

Kernel panic - not syncing: Fatal exception
Dumping ftrace buffer: 
   (ftrace buffer empty)
Rebooting in 10 seconds..

Test script to recreate :
https://github.com/avocado-framework-tests/avocado-misc-tests/blob/master/memory/memhotplug.py

$ avocado run memhotplug.py --show-job-log

-- 
Regard's

Abdul Haleem
IBM Linux Technology Centre