Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2484546ybi; Thu, 18 Jul 2019 09:07:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqytZyV5U0DmvJholc2bTs3t/9/i8hjZQxoQs15uQ+XgRFPF3rsSdkzNmcBUXsCmGdier5Xj X-Received: by 2002:a17:90a:19c2:: with SMTP id 2mr50071298pjj.13.1563466024874; Thu, 18 Jul 2019 09:07:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563466024; cv=none; d=google.com; s=arc-20160816; b=Pym7qDoUo3QcLoqxe+jEDqHxMBRlvhhpntA4N9QUe7FQKR1C0u4K3tNziylIvxbx0s Ac4c9oPJyJOk9yheCWa7/MQZ13rKNn3Ej1ssm0jSQmVsTFlmmVdpgj8G4JB5uE/4hBT3 h4apMgQXFZcrWMacpc4ELWhSmei4yB2XRttZRocTV8KFQyWf/mLwoopjP17HhZbaE4NU HsHa0+GEaeUa5iDIBDuVfU0F48y+Iwu/rjUfgK1Gink4WB5RyZgwknV3Klqp6MkFya36 BXTKMXnAwGenMtMKTbh8Herx2BvK9sKgFpM2R+AClziqiuW+1G88YjvsKozrAkXDlhuq ADfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CDwEGY8hvSUCeppe1h5aNTwi/2OwtesE3l3LkHtIONs=; b=Z3tjcMApTeylPNy/dnuq5mSx3xb2h0mxxnfdHs+yaEBRrQiniEKAa9tWtJPDfA5mPZ STG/ApwGKHUH+XArAgclwT6nh7gkBVvWIj9HZ80YH6eRDjn1qGqKF+k6xi8BPHgGbPxp Hp/qnYJm5IWb5iCy/0QJcV0gjMAgP3HSm/KUYr/7siKEi3+5c2u7ND8lbKi2NJz23u9O 4rWbIIVOih36nd1QMusJ2vMmzCoXgcDS3tNHRE6X/dAWj+K5z/i2w54nFJR0Bi7Bl7XX dyRHAu0lXMAWS+v8D5O6AS4McjY+FFFWwj04QHBT1XSfgZSdoztEVELkQ4K5bdXz+vDb ztgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=A87ug+yJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si1388296pji.65.2019.07.18.09.06.48; Thu, 18 Jul 2019 09:07:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=A87ug+yJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730256AbfGRQGN (ORCPT + 99 others); Thu, 18 Jul 2019 12:06:13 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:43630 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbfGRQGN (ORCPT ); Thu, 18 Jul 2019 12:06:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=CDwEGY8hvSUCeppe1h5aNTwi/2OwtesE3l3LkHtIONs=; b=A87ug+yJ6JdD5GxZM0VjyV94v D+s34s4VvEiaTkb0MAwDZxmSltvwXYkxINrX0eAdGn0rluGitXOJ/VyqiqPefzttMqN0C4QGd240y A933wTHLOzorZSf1Hlm6GpKKzMJ5ma/wVNMbyjm2HuRNQujyp9ER/+T634O4ags4rUMevh64p5wkC qxIlYf0f9jHrUfFn/PwWCDxXtdlkL/2UXOc6/zc8n2eBDvTHvbyyzP5Syck3bOVd0a52v6XrbIk3w 5NvpG+N5/VpMTznyKbzUguHYF/nO8BgjSeyB4xZPJV3yjf9qpKonYjjdsRNEowgavdZ8UjLIkQy0h jnPWFUS9A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1ho8uy-0001XW-MG; Thu, 18 Jul 2019 16:06:05 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 0679C20B94DC4; Thu, 18 Jul 2019 18:06:02 +0200 (CEST) Date: Thu, 18 Jul 2019 18:06:01 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: luferry , Rik van Riel , Greg Kroah-Hartman , Josh Poimboeuf , linux-kernel@vger.kernel.org Subject: Re: Re: [PATCH v2] smp: avoid generic_exec_single cause system lockup Message-ID: <20190718160601.GP3402@hirez.programming.kicks-ass.net> References: <20190718080308.48381-1-luferry@163.com> <5f5fbd7.1073c.16c0446ea63.Coremail.luferry@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 18, 2019 at 11:58:47AM +0200, Thomas Gleixner wrote: > Subject: smp: Warn on function calls from softirq context > From: Thomas Gleixner > Date: Thu, 18 Jul 2019 11:20:09 +0200 > > It's clearly documented that smp function calls cannot be invoked from > softirq handling context. Unfortunately nothing enforces that or emits a > warning. > > A single function call can be invoked from softirq context only via > smp_call_function_single_async(). > > Reported-by: luferry > Signed-off-by: Thomas Gleixner > --- > kernel/smp.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > --- a/kernel/smp.c > +++ b/kernel/smp.c > @@ -291,6 +291,15 @@ int smp_call_function_single(int cpu, sm > WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled() > && !oops_in_progress); > > + /* > + * Can deadlock when the softirq is executed on return from > + * interrupt and the interrupt hit between llist_add() and > + * arch_send_call_function_single_ipi() because then this > + * invocation sees the list non-empty, skips the IPI send > + * and waits forever. > + */ > + WARN_ON_ONCE(is_serving_softirq() && wait); > + > csd = &csd_stack; > if (!wait) { > csd = this_cpu_ptr(&csd_data); > @@ -416,6 +425,13 @@ void smp_call_function_many(const struct > WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled() > && !oops_in_progress && !early_boot_irqs_disabled); > > + /* > + * Bottom half handlers are not allowed to call this as they might > + * corrupt cfd_data when the interrupt which triggered softirq > + * processing hit this function. > + */ > + WARN_ON_ONCE(is_serving_softirq()); > + > /* Try to fastpath. So, what's a CPU they want? Ignoring this one. */ > cpu = cpumask_first_and(mask, cpu_online_mask); > if (cpu == this_cpu) As we discussed on IRC, it is worse, we can only use these functions from task/process context. We need something like the below. I've build a kernel with this applied and nothing went *splat*. diff --git a/kernel/smp.c b/kernel/smp.c index 616d4d114847..7dbcb402c2fc 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -291,6 +291,14 @@ int smp_call_function_single(int cpu, smp_call_func_t func, void *info, WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled() && !oops_in_progress); + /* + * When @wait we can deadlock when we interrupt between llist_add() and + * arch_send_call_function_ipi*(); when !@wait we can deadlock due to + * csd_lock() on because the interrupt context uses the same csd + * storage. + */ + WARN_ON_ONCE(!in_task()); + csd = &csd_stack; if (!wait) { csd = this_cpu_ptr(&csd_data); @@ -416,6 +424,14 @@ void smp_call_function_many(const struct cpumask *mask, WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled() && !oops_in_progress && !early_boot_irqs_disabled); + /* + * When @wait we can deadlock when we interrupt between llist_add() and + * arch_send_call_function_ipi*(); when !@wait we can deadlock due to + * csd_lock() on because the interrupt context uses the same csd + * storage. + */ + WARN_ON_ONCE(!in_task()); + /* Try to fastpath. So, what's a CPU they want? Ignoring this one. */ cpu = cpumask_first_and(mask, cpu_online_mask); if (cpu == this_cpu)