From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754036AbbIGJP0 (ORCPT ); Mon, 7 Sep 2015 05:15:26 -0400 Received: from www.linutronix.de ([62.245.132.108]:35963 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751676AbbIGJPV (ORCPT ); Mon, 7 Sep 2015 05:15:21 -0400 Date: Mon, 7 Sep 2015 11:14:43 +0200 (CEST) From: Thomas Gleixner To: Steven Rostedt cc: linux-kernel@vger.kernel.org, linux-rt-users , Carsten Emde , Sebastian Andrzej Siewior , John Kacur , Paul Gortmaker , Peter Zijlstra , Clark Williams , Arnaldo Carvalho de Melo , Ingo Molnar Subject: Re: [RFC][PATCH RT 0/3] RT: Fix trylock deadlock without msleep() hack In-Reply-To: <20150905085048.5cefbf5b@gandalf.local.home> Message-ID: References: <20150904011900.730816481@goodmis.org> <20150905081836.2967d80d@gandalf.local.home> <20150905085048.5cefbf5b@gandalf.local.home> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001,URIBL_BLOCKED=0.001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 5 Sep 2015, Steven Rostedt wrote: > On Sat, 5 Sep 2015 08:18:36 -0400 > Steven Rostedt wrote: > > > On Sat, 5 Sep 2015 12:30:59 +0200 (CEST) > > Thomas Gleixner wrote: > > > > > > So instead of doing that proposed magic boost, we can do something > > > more straight forward: > > > > > > retry: > > > lock(B); > > > if (!try_lock(A)) { > > > lock_and_drop(A, B); > > > unlock(A); > > > goto retry; > > > } > > > > > > lock_and_drop() queues the task as a waiter on A, drops B and then > > > does the PI adjustment on A. > > > > That was my original solution, and I believe I added patches to do > > exactly that to the networking code in the past. I remember writing > > that helper function such that on non PREEMPT_RT it was a nop. > > Just to point out again that I misread what you wrote. That's what I > get for responding to email 10 minutes after I get out of bed ;-) > > > You need to be careful about adding the waiter on A. If the owner of A > is blocked on B, the pi inheritance may detect that as a deadlock. That's exactly why I wrote: > > > lock_and_drop() queues the task as a waiter on A, drops B and then > > > does the PI adjustment on A. because the PI adjustment would detect the deadlock. Now the real question is whether we need that complexity at all. We need to analyze the life time rules. If we have something like this: lock(y->lock); x = y->x; ... and x cannot go away under us, then we can simply do lock(y->lock); x = y->x; if (!trylock(x->lock)) { unlock(y->lock); lock(x->lock); unlock(x->lock); goto retry; } Thanks, tglx