From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932389AbdJJQ43 (ORCPT ); Tue, 10 Oct 2017 12:56:29 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:44656 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932075AbdJJQ41 (ORCPT ); Tue, 10 Oct 2017 12:56:27 -0400 X-Google-Smtp-Source: AOwi7QBt+bfjVRewTyj2f2EzdJ/tT9g5gMRiPI1feP1bPvBAULkBD6hspxijTZ1K1C51kmulb9Gg1RSAito0Ycx8f2g= MIME-Version: 1.0 In-Reply-To: References: <20171003140634.r2jzujgl62ox4uzh@wfg-t540p.sh.intel.com> <20171010054801.GD3323@X58A-UD3R> From: Linus Torvalds Date: Tue, 10 Oct 2017 09:56:26 -0700 X-Google-Sender-Auth: HuT7oIWDvHeLBnbdc3n06ierHLI Message-ID: Subject: Re: [lockdep] b09be676e0 BUG: unable to handle kernel NULL pointer dereference at 000001f2 To: Byungchul Park Cc: Fengguang Wu , Ingo Molnar , "Peter Zijlstra (Intel)" , Linux Kernel Mailing List , LKP , Josh Poimboeuf , kernel-team@lge.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 10, 2017 at 9:22 AM, Linus Torvalds wrote: > > I really would like to see the sites that do cross-thread lock/unlock > pairs themselves be annotated. > > So when you lock in one thread, and then unlock in another, I'd > actually prefer to see something like > > - T1: > lock_mutex_cross(); > > - T2: > unlock_mutex_cross(); > > to make it very explicit that *these* particular lock/unlock > operations are the fancy ones. Actually, let's make it even *more* obvious, and even easier for lockdep (and for humans) to see what's going on. So I think the best model would be something like this: - T1: mutex_lock(&lock) ... mutex_transfer(&lock) - T2: mutex_receive(&lock); ... mutex_unlock(&lock); where the "mutex_transfer() -> mutex_receive()" thing really makes it obvious that "now thread 1 is transferring the lock to thread 2". And for lockdep, those transfer points will be easy to check: verify that the "mutex_transfer()" is done with the lock held, and maybe clear the lock ownership at that point (or set it to "in flight" or whatever). And then "mutex_receive()" can verify that (a) the ownership was that "in tranfer" thing and that it's still held, before it then sets the ownership to thread 2. Wouldn't that be easier for lockdep? And I think it would be much more obvious to users too, and really document those places where we do something odd and transfer ownership of a lock from one thread to another? Linus From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============0825724156147588933==" MIME-Version: 1.0 From: Linus Torvalds To: lkp@lists.01.org Subject: Re: [lockdep] b09be676e0 BUG: unable to handle kernel NULL pointer dereference at 000001f2 Date: Tue, 10 Oct 2017 09:56:26 -0700 Message-ID: In-Reply-To: List-Id: --===============0825724156147588933== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On Tue, Oct 10, 2017 at 9:22 AM, Linus Torvalds wrote: > > I really would like to see the sites that do cross-thread lock/unlock > pairs themselves be annotated. > > So when you lock in one thread, and then unlock in another, I'd > actually prefer to see something like > > - T1: > lock_mutex_cross(); > > - T2: > unlock_mutex_cross(); > > to make it very explicit that *these* particular lock/unlock > operations are the fancy ones. Actually, let's make it even *more* obvious, and even easier for lockdep (and for humans) to see what's going on. So I think the best model would be something like this: - T1: mutex_lock(&lock) ... mutex_transfer(&lock) - T2: mutex_receive(&lock); ... mutex_unlock(&lock); where the "mutex_transfer() -> mutex_receive()" thing really makes it obvious that "now thread 1 is transferring the lock to thread 2". And for lockdep, those transfer points will be easy to check: verify that the "mutex_transfer()" is done with the lock held, and maybe clear the lock ownership at that point (or set it to "in flight" or whatever). And then "mutex_receive()" can verify that (a) the ownership was that "in tranfer" thing and that it's still held, before it then sets the ownership to thread 2. Wouldn't that be easier for lockdep? And I think it would be much more obvious to users too, and really document those places where we do something odd and transfer ownership of a lock from one thread to another? Linus --===============0825724156147588933==--