Index | Thread | Search

From:
Alexandr Nedvedicky <sashan@fastmail.net>
Subject:
Re: net lock kernel lock order
To:
Alexander Bluhm <alexander.bluhm@gmx.net>
Cc:
tech@openbsd.org
Date:
Fri, 5 Jan 2024 15:55:49 +0100

Download raw body.

Thread
Hello,

On Fri, Jan 05, 2024 at 03:24:44PM +0100, Alexander Bluhm wrote:
> On Fri, Jan 05, 2024 at 03:05:44PM +0100, Claudio Jeker wrote:
> > On Fri, Jan 05, 2024 at 01:26:15PM +0100, Alexander Bluhm wrote:
> > > Hi,
> > > 
> > > We have code that takes kernel lock just before net lock.  As net
> > > lock is a rwlock that releases kernel lock while sleeping, there
> > > is never deadlock due to lock ordering.
> > > 
> > > The order kernel lock -> net lock is suboptimal.  If net lock is
> > > held by another thread the following happens:
> > > 
> > > take kernel lock -> try net lock -> release kernel lock -> sleep
> > > -> take net lock -> take kernel lock
> > 
> > this is incorrect. the kernel lock is aquired before the rwlock in a sleep
> > call.
> 
> Yes.  The kernel lock dance is done in mi_switch().  So the correct
> old sequence is:
> 
> take kernel lock -> try net lock -> release kernel lock -> sleep
> -> take kernel lock -> take net lock
> 
> But that does not change my argument that the sequence with my diff
> is cheaper.
> 

    I think the new sequence rather supports your diff. that's
    at least my understanding.

regards
sashan