Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1874850yba; Fri, 10 May 2019 02:30:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqRABGW26LG3uG85IJKraX6WtjgD490uYJpWXOFRJztRGyr7XZajWAXMy8ZZxQf/9mkV3l X-Received: by 2002:a65:51c8:: with SMTP id i8mr12085223pgq.175.1557480644413; Fri, 10 May 2019 02:30:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557480644; cv=none; d=google.com; s=arc-20160816; b=s+rWcrzLAfscAf99iAuCeV7b2CErzkl1TK46EGkL2fSjM55ivO/8/NWW34la3UUDpF VEygKysFVpUdSto0Stcnr/o4tvy+fa5/By0ifkGgUMXTdNZjVuLHANh4xUAQ1UPzCGan tF+I6Bq9qUqww0SmvqT5Rusco7zkU4kjrWbCBnWAOAAY8R0xHIq5LDigq/PnamD2lf54 zPcEICAAEDEefXtAMyotOSSQO9P0GxLBPT6Mjd2trdhunyI3nXRzQwQBFirqwlKiZR/q cEbNN3UsWVFq+BMwAH/NPEUvsJFDBvbI43LtHaEQdkAONUluXZL+i70ozyOCcABTz+n+ TpEA== 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; bh=Lui1alnv18SUCxMyygNjcwu7GHQXyNNTI/z6IF+HQz0=; b=TJTBfQIkEXYx2cSJPkb3dQ3B+7J1bj3LU7vJ3IU8Z30DJi8mX9EemOqQOdmG3wrJkB l8OIRrK/fBsKnI2epYWdwoBlTl9+q9egxmNL1dbgWOZK0QOqU2P69hUyDEixdfCP4Q/E /57qk2xyCwDc0oBY28wb9/G4L5a9Gz3/6yOwi86J0miWVv/TdjoCQqfPeIp3mTXgb+aF RPiPhY0ZnHsYop7a3clq7bxkPBjqviYtwKEvjNcteU+IYg0AI4glG64QvgjTqPqh95aV GAv6qbZeiH0uHUYI+PzcDpzSq+kBC+ssIioCyPav8maxfqkqkTbThtm1Tqj1meB/bqWR Fs1A== ARC-Authentication-Results: i=1; mx.google.com; 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 187si7491287pfe.116.2019.05.10.02.30.28; Fri, 10 May 2019 02:30:44 -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; 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 S1727160AbfEJJ2V (ORCPT + 99 others); Fri, 10 May 2019 05:28:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:56372 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726992AbfEJJ2U (ORCPT ); Fri, 10 May 2019 05:28:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AEE65AD9D; Fri, 10 May 2019 09:28:19 +0000 (UTC) Date: Fri, 10 May 2019 11:28:19 +0200 From: Petr Mladek To: Daniel Vetter Cc: Intel Graphics Development , DRI Development , Daniel Vetter , Peter Zijlstra , Ingo Molnar , Will Deacon , Sergey Senozhatsky , Steven Rostedt , John Ogness , Chris Wilson , linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernel/locking/semaphore: use wake_q in up() Message-ID: <20190510092819.elu4b7fcojzcek2q@pathway.suse.cz> References: <20190509120903.28939-1-daniel.vetter@ffwll.ch> <20190509200633.19678-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190509200633.19678-1-daniel.vetter@ffwll.ch> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2019-05-09 22:06:33, Daniel Vetter wrote: > console_trylock, called from within printk, can be called from pretty > much anywhere. Including try_to_wake_up. Note that this isn't common, > usually the box is in pretty bad shape at that point already. But it > really doesn't help when then lockdep jumps in and spams the logs, > potentially obscuring the real backtrace we're really interested in. > One case I've seen (slightly simplified backtrace): > > Fix this specific locking recursion by moving the wake_up_process out > from under the semaphore.lock spinlock, using wake_q as recommended by > Peter Zijlstra. It might make sense to mention also the optimization effect mentioned by Peter. > diff --git a/kernel/locking/semaphore.c b/kernel/locking/semaphore.c > index 561acdd39960..7a6f33715688 100644 > --- a/kernel/locking/semaphore.c > +++ b/kernel/locking/semaphore.c > @@ -169,6 +169,14 @@ int down_timeout(struct semaphore *sem, long timeout) > } > EXPORT_SYMBOL(down_timeout); > > +/* Functions for the contended case */ > + > +struct semaphore_waiter { > + struct list_head list; > + struct task_struct *task; > + bool up; > +}; > + > /** > * up - release the semaphore > * @sem: the semaphore to release > @@ -179,24 +187,25 @@ EXPORT_SYMBOL(down_timeout); > void up(struct semaphore *sem) > { > unsigned long flags; > + struct semaphore_waiter *waiter; > + DEFINE_WAKE_Q(wake_q); We need to call wake_q_init(&wake_q) to make sure that it is empty. Best Regards, Petr > raw_spin_lock_irqsave(&sem->lock, flags); > - if (likely(list_empty(&sem->wait_list))) > + if (likely(list_empty(&sem->wait_list))) { > sem->count++; > - else > - __up(sem); > + } else { > + waiter = list_first_entry(&sem->wait_list, > + struct semaphore_waiter, list); > + list_del(&waiter->list); > + waiter->up = true; > + wake_q_add(&wake_q, waiter->task); > + } > raw_spin_unlock_irqrestore(&sem->lock, flags); > + > + wake_up_q(&wake_q); > } > EXPORT_SYMBOL(up); > > -/* Functions for the contended case */ > - > -struct semaphore_waiter { > - struct list_head list; > - struct task_struct *task; > - bool up; > -}; > - > /* > * Because this function is inlined, the 'state' parameter will be > * constant, and thus optimised away by the compiler. Likewise the