Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1309622ybk; Thu, 21 May 2020 03:51:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwq8maw4aFKcYloJd3PpSgFDSTaLk4DEnoxgRw1bvEB+degwTEXksSpIfQEPG11Km+4Jsy0 X-Received: by 2002:aa7:dd12:: with SMTP id i18mr7436363edv.133.1590058318152; Thu, 21 May 2020 03:51:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590058318; cv=none; d=google.com; s=arc-20160816; b=mhWmDwwhFh9dSn3cPTiDzuqe6yIylG80NWuruNVQZahNvwLvwGY5URs6BHOcU9nuJ/ foCcM1vIgy2RSGtxHeIK9PSYgznNvx/mDGy7fE4ehWdJINZB99P4BtZqs9fjNucN8R57 pGqv9id8NBhZ9tyxAPze4SqRDWVwokl3hLABO1ooak6GMmVyk2akQqdNSuMYZILJvOuH DHyTt9w7us5uPAaPbcZvJZ1HOMvXN0kXp8b+hCsBifWX8bK9EuJ2nssiNWYn353vkt0S qyTOaoIzKLp7Mf0pOiA/BLPtdZqBeSjKtfv34g9oHwzawCeWjpg0fRAJdKz/YYkb7hFT HhBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=UWvnfa19r1FQDwx/9W5RgRGXvBWnFUWUYn6L5ClPmLM=; b=lx8PIfTs1Bag3KIKF+SSrwaLq81BnBKHm+X9iKqD2PylCnHL2tEPxknOc/kjfZUzV/ hQdB3Ydip4LGT1dqYpX5Sg6LsHNotI9j5lTdwjOan/YWMenZlw5wQuujn7a/a9wa0bLd zG8Oam/cIhtSi7raxM7izcA4sSpLaXYG1zzEObFFDLC/BCPwOJOmXkIoNVS0w3RdD4rM be7PYMf2GTeIh9Px57qA5HFFFnFhV3+Z6w4QCDed21DddIdP8PQTUE8MT7L6lVPqk7X9 fYDVvdwwBrbMvtJ3jm7L64wEkglQQXkyfL6TiU++wkx+DvOCWvG9zZXsfk+OZrKFH/FZ +Hew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=p73WvaiB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si2865012edx.113.2020.05.21.03.51.34; Thu, 21 May 2020 03:51:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=p73WvaiB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727912AbgEUKuM (ORCPT + 99 others); Thu, 21 May 2020 06:50:12 -0400 Received: from merlin.infradead.org ([205.233.59.134]:38268 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727013AbgEUKuL (ORCPT ); Thu, 21 May 2020 06:50:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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; bh=UWvnfa19r1FQDwx/9W5RgRGXvBWnFUWUYn6L5ClPmLM=; b=p73WvaiBjYOVphK2nrGUC/aXVZ Q85YumDlcbbViLt6y3IZwuXRg4//ElM6aRGlb+WK2Q0yK8+3WafTz8mN2H4eUS5Nqnm/wLUTp+42f zInP0dgKxLmHIBrL+jlJrNAlOIYv35lDJ4kfKYayjpwep9MzwWVos5dnubWQdnIlbpUlNSV0V6wtU Tb1APna4unoZtH0Ac1e1Mn5VE6pA74HMmhUkmcRaK82mq10YtOvUfHIkb+7mAuvg4LIrcKNZQWthT L1mySfRV/O9AJ1T7/Z5kczHIlI88UQq65qNPwXONwDzdhgQZCQ7IMnC48GeXSFD3dOsPH951VUgsw X1cDOCZw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jbill-0002XT-MC; Thu, 21 May 2020 10:49:45 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 317103011E8; Thu, 21 May 2020 12:49:38 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id DF997286B5F33; Thu, 21 May 2020 12:49:37 +0200 (CEST) Date: Thu, 21 May 2020 12:49:37 +0200 From: Peter Zijlstra To: Frederic Weisbecker Cc: Qian Cai , "Paul E. McKenney" , Linux Kernel Mailing List , Thomas Gleixner , Michael Ellerman , linuxppc-dev , Borislav Petkov Subject: Re: Endless soft-lockups for compiling workload since next-20200519 Message-ID: <20200521104937.GB325303@hirez.programming.kicks-ass.net> References: <20200520125056.GC325280@hirez.programming.kicks-ass.net> <20200521004035.GA15455@lenoir> <20200521093938.GG325280@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200521093938.GG325280@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 21, 2020 at 11:39:39AM +0200, Peter Zijlstra wrote: > On Thu, May 21, 2020 at 02:40:36AM +0200, Frederic Weisbecker wrote: > This: > > > smp_call_function_single_async() { smp_call_function_single_async() { > > // verified csd->flags != CSD_LOCK // verified csd->flags != CSD_LOCK > > csd->flags = CSD_LOCK csd->flags = CSD_LOCK > > concurrent smp_call_function_single_async() using the same csd is what > I'm looking at as well. So something like this ought to cure the fundamental problem and make smp_call_function_single_async() more user friendly, but also more expensive. The problem is that while the ILB case is easy to fix, I can't seem to find an equally nice solution for the ttwu_remote_queue() case; that would basically require sticking the wake_csd in task_struct, I'll also post that. So it's either this: --- kernel/smp.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/kernel/smp.c b/kernel/smp.c index 84303197caf9..d1ca2a2d1cc7 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -109,6 +109,12 @@ static __always_inline void csd_lock_wait(call_single_data_t *csd) smp_cond_load_acquire(&csd->flags, !(VAL & CSD_FLAG_LOCK)); } +/* + * csd_lock() can use non-atomic operations to set CSD_FLAG_LOCK because it's + * users are careful to only use CPU-local data. IOW, there is no cross-cpu + * lock usage. Also, you're not allowed to use smp_call_function*() from IRQs, + * and must be extra careful from SoftIRQ. + */ static __always_inline void csd_lock(call_single_data_t *csd) { csd_lock_wait(csd); @@ -318,7 +324,7 @@ EXPORT_SYMBOL(smp_call_function_single); /** * smp_call_function_single_async(): Run an asynchronous function on a - * specific CPU. + * specific CPU. * @cpu: The CPU to run on. * @csd: Pre-allocated and setup data structure * @@ -339,18 +345,23 @@ EXPORT_SYMBOL(smp_call_function_single); */ int smp_call_function_single_async(int cpu, call_single_data_t *csd) { + unsigned int csd_flags; int err = 0; preempt_disable(); - if (csd->flags & CSD_FLAG_LOCK) { + /* + * Unlike the regular smp_call_function*() APIs, this one is actually + * usable from IRQ context, also the -EBUSY return value suggests + * it is safe to share csd's. + */ + csd_flags = READ_ONCE(csd->flags); + if (csd_flags & CSD_FLAG_LOCK || + cmpxchg(&csd->flags, csd_flags, csd_flags | CSD_FLAG_LOCK) != csd_flags) { err = -EBUSY; goto out; } - csd->flags = CSD_FLAG_LOCK; - smp_wmb(); - err = generic_exec_single(cpu, csd, csd->func, csd->info); out: