Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp600382ybd; Wed, 26 Jun 2019 03:36:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHmwY5rlJ8aXWjIoDggr1GjkmruM0IA3z9fhLWFjontvUGZypkloWFyTleouoNe7xxf+l7 X-Received: by 2002:a63:dc50:: with SMTP id f16mr2279574pgj.447.1561545415710; Wed, 26 Jun 2019 03:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561545415; cv=none; d=google.com; s=arc-20160816; b=q7b5lm+GEejfLPSyWOfQAQoyJtDnarS1rzG09Q1TIG9nsDgNtr4rCVu5xGB2mcqIe7 nmI4Tvj25kEUhjnv4lZln0plQK6Bmi056uyZtmii18w+ErXyCtk7gOFVHzl1LMBbQ6U0 08fsk2tj2OjgefKmj58iGot6YEE1DaEs3s2PgRRL4M6l501gvjZKjZCGgO2Kb/CROreq URphs+MGw4P1oIR+2YdFpUxY//0iQ3TJErv9NQQMgOEoFKskVo37t4U6c92rbgpXipsG y8wypj1dCLjE//2YQtGrzGCbDt6zfwvHpeAaJijSBkSahTk9z9ECDHKu2gJ7Vx0w575L VLdg== 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=Z59P3DCESmzNCcibG3WuNOZ7nMH3x4w5SM4UGQx+3GM=; b=LtNlKFAnr/mRwEOjoV9Hz26CNboNFbVcQcRlZCD/WxNvwh/co5crp0osQa8Pu5VtUt Xob09r5FJS4zoQ5v9XslyR74YDfjO0ulKoYsMUrCOHb6T6uvS9ix1t3j3Rj/k/5EHATx eX+EFbJChwNBdLKauSRSL7QlrGIoxqdytH5qtzDkD89rbmeG79hLLgF1qlP46Dnv54WL RMyrewtwwu341cZi6EE8QpmSZVEHF9dhLuvl3p46+u2L1h6tvvhT54zODVrKhUzCUthp 4K2mdyR66IND68pftW/l9e9KOccOfebZ0ah2T0AJgCQMAFDv8CPIj/LeNKpuYHeHJJ4A Cxhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=pBMW6Cf1; 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 h11si1832396pju.90.2019.06.26.03.36.38; Wed, 26 Jun 2019 03:36:55 -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=pBMW6Cf1; 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 S1726628AbfFZKgK (ORCPT + 99 others); Wed, 26 Jun 2019 06:36:10 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:54506 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbfFZKgJ (ORCPT ); Wed, 26 Jun 2019 06:36:09 -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=Z59P3DCESmzNCcibG3WuNOZ7nMH3x4w5SM4UGQx+3GM=; b=pBMW6Cf1ltUNRA+WHq8nTd1Ta FhAzvEn03lZYSKkrEkpKW1RV8ZTINiw7UXlApumZIfN8GSm24gQ8x2GtThDHqFfNr4+jqxmUsmLBZ w9u9SPam+mFPOo1EC86eCdaJkFD1srGZINVOn36d6XrZYypmoXLhKqwCPC8U/mklN76IekBqz+/jE ChJfqxCIYvAYzXroETavkB13DKBcOzydl0+vOiALmURIMag3a0avBciBa0RxFXn8EljokQoSPbyD5 CLSmyiAzM5SjioYIvpEiX+jiytugntz68Mu0RZmyhWGrj5ygb4RxdwVzG6fr21HHkL6oiBPGqxwJg FPJjJlOvA==; 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 1hg5HU-0001Ni-KT; Wed, 26 Jun 2019 10:36:00 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 41D43209C957B; Wed, 26 Jun 2019 12:35:58 +0200 (CEST) Date: Wed, 26 Jun 2019 12:35:58 +0200 From: Peter Zijlstra To: Sebastian Andrzej Siewior Cc: minyard@acm.org, linux-rt-users@vger.kernel.org, Corey Minyard , linux-kernel@vger.kernel.org, tglx@linutronix.de, Steven Rostedt Subject: Re: [PATCH RT v2] Fix a lockup in wait_for_completion() and friends Message-ID: <20190626103558.GL3419@hirez.programming.kicks-ass.net> References: <20190508205728.25557-1-minyard@acm.org> <20190509161925.kul66w54wpjcinuc@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190509161925.kul66w54wpjcinuc@linutronix.de> 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, May 09, 2019 at 06:19:25PM +0200, Sebastian Andrzej Siewior wrote: > One question for the upstream completion implementation: > completion_done() returns true if there are no waiters. It acquires the > wait.lock to ensure that complete()/complete_all() is done. However, > once complete releases the lock it is guaranteed that the wake_up() (for > the waiter) occurred. The waiter task still needs to be remove itself > from the wait-queue before the completion can be removed. > Do I miss something? So you mean: init_completion(&done); wait_for_copmletion(&done) spin_lock() __add_wait_queue() spin_unlock() schedule() complete() completion_done() spin_lock() __remove_wait_queue() spin_unlock() Right? I think that boils down to that whenever you have multiple waiters, someone needs to be in charge of @done's lifetime. The case that matters is: DECLARE_COMPLETION_ONSTACK(done) while (!completion_done(&done)) cpu_relax(); Where there is but a single waiter, and that waiter is completion_done(). In that case it must not return early. Now, I've also seen a ton of code do: if (!completion_done(done)) complete(done); And that makes me itch... but I've not bothered to look into it hard enough.