From: Borislav Petkov <bp@alien8.de> To: Jeremy Cline <jcline@redhat.com>, Tony Luck <tony.luck@intel.com> Cc: Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>, x86@kernel.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, Laura Abbott <labbott@redhat.com> Subject: Re: x86/mce: suspicious RCU usage in 4.13.4 Date: Tue, 10 Oct 2017 21:44:26 +0200 [thread overview] Message-ID: <20171010194426.s7keveirclglx6vh@pd.tnic> (raw) In-Reply-To: <9840bf0d-6756-75eb-1a2d-d3aace235244@redhat.com> On Tue, Oct 10, 2017 at 03:00:09PM -0400, Jeremy Cline wrote: > Hello, > > A Fedora user has reported an issue about suspicious RCU usage in > dev-mcelog. It looks like perhaps the notifier call chain is not > acquiring the mce_chrdev_read_mutex? The traceback is > > [36915.633804] ============================= > [36915.633805] WARNING: suspicious RCU usage > [36915.633808] 4.13.4-301.fc27.x86_64+debug #1 Not tainted > [36915.633809] ----------------------------- > [36915.633811] arch/x86/kernel/cpu/mcheck/dev-mcelog.c:60 suspicious > mce_log_get_idx_check() usage! > [36915.633812] > other info that might help us debug this: > > [36915.633813] > rcu_scheduler_active = 2, debug_locks = 1 > [36915.633815] 3 locks held by kworker/1:2/14637: > [36915.633816] #0: ("events"){.+.+.+}, at: [<ffffffffaa0d2ac0>] > process_one_work+0x1d0/0x6a0 > [36915.633827] #1: ((&mce_work)){+.+...}, at: [<ffffffffaa0d2ac0>] > process_one_work+0x1d0/0x6a0 > [36915.633833] #2: ((x86_mce_decoder_chain).rwsem){++++..}, at: > [<ffffffffaa0dc92f>] blocking_notifier_call_chain+0x2f/0x70 > [36915.633840] > stack backtrace: > [36915.633843] CPU: 1 PID: 14637 Comm: kworker/1:2 Not tainted > 4.13.4-301.fc27.x86_64+debug #1 > [36915.633844] Hardware name: Gigabyte Technology Co., Ltd. > Z87M-D3H/Z87M-D3H, BIOS F11 08/12/2014 > [36915.633847] Workqueue: events mce_gen_pool_process > [36915.633849] Call Trace: > [36915.633854] dump_stack+0x8e/0xd6 > [36915.633858] lockdep_rcu_suspicious+0xc5/0x100 > [36915.633862] dev_mce_log+0xf6/0x1e0 > [36915.633865] notifier_call_chain+0x39/0x90 > [36915.633869] blocking_notifier_call_chain+0x49/0x70 > [36915.633873] mce_gen_pool_process+0x41/0x70 Right, so dev_mce_log() is called in process context now and thus can be greatly simplified by removing all those memory barriers and cmpxchg() fun which was for atomic context back then. And simply grab the mutex instead. IOW, something like this totally untested hunk. Tony? --- diff --git a/arch/x86/kernel/cpu/mcheck/dev-mcelog.c b/arch/x86/kernel/cpu/mcheck/dev-mcelog.c index 10cec43aac38..1dacebb6a23b 100644 --- a/arch/x86/kernel/cpu/mcheck/dev-mcelog.c +++ b/arch/x86/kernel/cpu/mcheck/dev-mcelog.c @@ -53,9 +53,10 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val, void *data) { struct mce *mce = (struct mce *)data; - unsigned int next, entry; + unsigned int entry; + + mutex_lock(&mce_chrdev_read_mutex); - wmb(); for (;;) { entry = mce_log_get_idx_check(mcelog.next); for (;;) { @@ -66,10 +67,10 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val, * interesting ones: */ if (entry >= MCE_LOG_LEN) { - set_bit(MCE_OVERFLOW, - (unsigned long *)&mcelog.flags); + set_bit(MCE_OVERFLOW, (unsigned long *)&mcelog.flags); return NOTIFY_OK; } + /* Old left over entry. Skip: */ if (mcelog.entry[entry].finished) { entry++; @@ -77,15 +78,13 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val, } break; } - smp_rmb(); - next = entry + 1; - if (cmpxchg(&mcelog.next, entry, next) == entry) - break; + mcelog.next = entry + 1; } + memcpy(mcelog.entry + entry, mce, sizeof(struct mce)); - wmb(); mcelog.entry[entry].finished = 1; - wmb(); + + mutex_unlock(&mce_chrdev_read_mutex); /* wake processes polling /dev/mcelog */ wake_up_interruptible(&mce_chrdev_wait); -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
WARNING: multiple messages have this Message-ID (diff)
From: Borislav Petkov <bp@alien8.de> To: Jeremy Cline <jcline@redhat.com>, Tony Luck <tony.luck@intel.com> Cc: Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>, x86@kernel.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, Laura Abbott <labbott@redhat.com> Subject: x86/mce: suspicious RCU usage in 4.13.4 Date: Tue, 10 Oct 2017 21:44:26 +0200 [thread overview] Message-ID: <20171010194426.s7keveirclglx6vh@pd.tnic> (raw) On Tue, Oct 10, 2017 at 03:00:09PM -0400, Jeremy Cline wrote: > Hello, > > A Fedora user has reported an issue about suspicious RCU usage in > dev-mcelog. It looks like perhaps the notifier call chain is not > acquiring the mce_chrdev_read_mutex? The traceback is > > [36915.633804] ============================= > [36915.633805] WARNING: suspicious RCU usage > [36915.633808] 4.13.4-301.fc27.x86_64+debug #1 Not tainted > [36915.633809] ----------------------------- > [36915.633811] arch/x86/kernel/cpu/mcheck/dev-mcelog.c:60 suspicious > mce_log_get_idx_check() usage! > [36915.633812] > other info that might help us debug this: > > [36915.633813] > rcu_scheduler_active = 2, debug_locks = 1 > [36915.633815] 3 locks held by kworker/1:2/14637: > [36915.633816] #0: ("events"){.+.+.+}, at: [<ffffffffaa0d2ac0>] > process_one_work+0x1d0/0x6a0 > [36915.633827] #1: ((&mce_work)){+.+...}, at: [<ffffffffaa0d2ac0>] > process_one_work+0x1d0/0x6a0 > [36915.633833] #2: ((x86_mce_decoder_chain).rwsem){++++..}, at: > [<ffffffffaa0dc92f>] blocking_notifier_call_chain+0x2f/0x70 > [36915.633840] > stack backtrace: > [36915.633843] CPU: 1 PID: 14637 Comm: kworker/1:2 Not tainted > 4.13.4-301.fc27.x86_64+debug #1 > [36915.633844] Hardware name: Gigabyte Technology Co., Ltd. > Z87M-D3H/Z87M-D3H, BIOS F11 08/12/2014 > [36915.633847] Workqueue: events mce_gen_pool_process > [36915.633849] Call Trace: > [36915.633854] dump_stack+0x8e/0xd6 > [36915.633858] lockdep_rcu_suspicious+0xc5/0x100 > [36915.633862] dev_mce_log+0xf6/0x1e0 > [36915.633865] notifier_call_chain+0x39/0x90 > [36915.633869] blocking_notifier_call_chain+0x49/0x70 > [36915.633873] mce_gen_pool_process+0x41/0x70 Right, so dev_mce_log() is called in process context now and thus can be greatly simplified by removing all those memory barriers and cmpxchg() fun which was for atomic context back then. And simply grab the mutex instead. IOW, something like this totally untested hunk. Tony? diff --git a/arch/x86/kernel/cpu/mcheck/dev-mcelog.c b/arch/x86/kernel/cpu/mcheck/dev-mcelog.c index 10cec43aac38..1dacebb6a23b 100644 --- a/arch/x86/kernel/cpu/mcheck/dev-mcelog.c +++ b/arch/x86/kernel/cpu/mcheck/dev-mcelog.c @@ -53,9 +53,10 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val, void *data) { struct mce *mce = (struct mce *)data; - unsigned int next, entry; + unsigned int entry; + + mutex_lock(&mce_chrdev_read_mutex); - wmb(); for (;;) { entry = mce_log_get_idx_check(mcelog.next); for (;;) { @@ -66,10 +67,10 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val, * interesting ones: */ if (entry >= MCE_LOG_LEN) { - set_bit(MCE_OVERFLOW, - (unsigned long *)&mcelog.flags); + set_bit(MCE_OVERFLOW, (unsigned long *)&mcelog.flags); return NOTIFY_OK; } + /* Old left over entry. Skip: */ if (mcelog.entry[entry].finished) { entry++; @@ -77,15 +78,13 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val, } break; } - smp_rmb(); - next = entry + 1; - if (cmpxchg(&mcelog.next, entry, next) == entry) - break; + mcelog.next = entry + 1; } + memcpy(mcelog.entry + entry, mce, sizeof(struct mce)); - wmb(); mcelog.entry[entry].finished = 1; - wmb(); + + mutex_unlock(&mce_chrdev_read_mutex); /* wake processes polling /dev/mcelog */ wake_up_interruptible(&mce_chrdev_wait);
next prev parent reply other threads:[~2017-10-10 19:44 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-10-10 19:00 x86/mce: suspicious RCU usage in 4.13.4 Jeremy Cline 2017-10-10 19:44 ` Borislav Petkov [this message] 2017-10-10 19:44 ` Borislav Petkov 2017-10-10 20:08 ` Luck, Tony 2017-10-10 20:08 ` Luck, Tony 2017-10-10 20:13 ` Andi Kleen 2017-10-10 20:13 ` Andi Kleen 2017-10-11 11:50 ` Borislav Petkov 2017-10-11 11:50 ` Borislav Petkov 2017-10-11 21:34 ` Luck, Tony 2017-10-11 21:34 ` Luck, Tony 2017-10-15 9:40 ` Borislav Petkov 2017-10-15 9:40 ` Borislav Petkov 2017-10-16 18:28 ` Luck, Tony 2017-10-16 18:28 ` Luck, Tony 2017-11-01 14:56 ` Laura Abbott 2017-11-01 14:56 ` Laura Abbott 2017-11-01 16:47 ` Borislav Petkov 2017-11-01 16:47 ` Borislav Petkov 2017-11-01 20:07 ` Luck, Tony 2017-11-01 20:07 ` Luck, Tony 2017-11-01 20:28 ` [tip:ras/urgent] x86/mcelog: Get rid of RCU remnants tip-bot for Borislav Petkov 2017-10-11 23:11 ` x86/mce: suspicious RCU usage in 4.13.4 Andi Kleen 2017-10-11 23:11 ` Andi Kleen 2017-10-12 9:02 ` Borislav Petkov 2017-10-12 9:02 ` Borislav Petkov 2017-10-12 22:13 ` Andi Kleen 2017-10-12 22:13 ` Andi Kleen
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20171010194426.s7keveirclglx6vh@pd.tnic \ --to=bp@alien8.de \ --cc=hpa@zytor.com \ --cc=jcline@redhat.com \ --cc=labbott@redhat.com \ --cc=linux-edac@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=mingo@redhat.com \ --cc=tglx@linutronix.de \ --cc=tony.luck@intel.com \ --cc=x86@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.