Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: Marco Elver <elver@google.com>
Cc: Bart Van Assche <bvanassche@acm.org>,
	linux-ide@vger.kernel.org, Damien Le Moal <dlemoal@kernel.org>,
	Mikael Pettersson <mikpelinux@gmail.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Magnus Damm <magnus.damm@gmail.com>
Subject: Re: [PATCH v2 9/9] ata: Annotate the code that uses the host lock
Date: Wed, 27 May 2026 15:42:37 +0200	[thread overview]
Message-ID: <ahb0zRlRGMI0_WwT@ryzen> (raw)
In-Reply-To: <CANpmjNMU4nwg==7pn0UAXY9Z5s-4dZFgPwxEHHhwvhiynSi_cA@mail.gmail.com>

On Wed, May 27, 2026 at 12:40:24AM +0200, Marco Elver wrote:
> On Tue, 26 May 2026 at 23:33, Bart Van Assche <bvanassche@acm.org> wrote:
> 
> Then the assumption is checked at runtime when running with lockdep.
> This is by design, because it goes both ways: every time you now add
> __assume_ctx_lock(), someone just has to move that code around and
> suddenly the assumption no longer holds and you have a bug. If you
> were using lockdep_assert_held() you're at least ensuring that someone
> running with lockdep (e.g. syzkaller) will catch the bad assumption.

My biggest worry/issue with this series is all the __assume_ctx_lock()
annotations it adds. Because __assume_ctx_lock() seems to tell the compiler:
"trust me, I have taken this lock". It seems quite fragile, and if someone
refactors the code, the annotation might no longer be valid.

I suggested something similar to what Bart suggested, a:
__objects_are_equal(dev->link->ap->lock, ap->lock) annotation.
But as Bart said, that would probably require additions to Clang.

But here Marco says that pointer-equality is unsound, since it can't be
verified statically and would have to be verified at rutime...


> 
> > Whether lockdep_assert_held() or __assume_ctx_lock() is used to help the
> > compiler alias analysis, there is a risk that these annotations are
> > incorrect. My preferred solution is that a new macro would be added that
> > supports expressing pointer equality in a direct way to the compiler
> > alias analysis engine and also that evaluates pointer equality at
> > runtime. However, I'm afraid this requires compiler changes and changing
> > Clang is out-of-scope for me.
> 
> Telling the compiler about pointer-equality is also unsound, because
> there's no way to verify our assumption statically. The only way to
> recover soundness is to again introduce runtime checks of some sort.
> 
> > I chose __assume_ctx_lock() because it is evaluated only at compile time
> > and a compile time annotation is sufficient in this context.
> 
> There's a real risk that your assumption may become stale, and if it
> were my codebase, I'd prefer lockdep_assert_held() just to make sure
> we check our assumption at runtime. This is not my subsystem -- just
> my 2c.

Right now, I think my ideal solution would be to, to the furthest extent
possible, try to avoid adding __assume_ctx_lock().
Sure, a few special cases might be acceptable, if there are no reasonable
way to avoid it.

And if there is no reasonable way to avoid it, at least with the current
behavior in linux-next/master, I would prefer a lockdep_assert_held() over
a __assume_ctx_lock().


Kind regards,
Niklas

  reply	other threads:[~2026-05-27 13:42 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 17:33 [PATCH v2 0/9] ata: libata-core: Enable context analysis Bart Van Assche
2026-05-21 17:33 ` [PATCH v2 1/9] ata: libata: Fix ata_exec_internal() Bart Van Assche
2026-05-26 13:43   ` Niklas Cassel
2026-05-26 15:56     ` Bart Van Assche
2026-05-27  9:17       ` Niklas Cassel
2026-05-27 18:31   ` Damien Le Moal
2026-05-28  6:10   ` Hannes Reinecke
2026-05-21 17:33 ` [PATCH v2 2/9] ata: libata: Pass the ATA port argument directly to __ata_scsi_queuecmd() Bart Van Assche
2026-05-26 15:07   ` Niklas Cassel
2026-05-26 21:46     ` Bart Van Assche
2026-05-27 10:44       ` Niklas Cassel
2026-05-27 18:43   ` Damien Le Moal
2026-05-27 18:55     ` Bart Van Assche
2026-05-27 19:32       ` Damien Le Moal
2026-05-28  6:11   ` Hannes Reinecke
2026-05-21 17:33 ` [PATCH v2 3/9] ata: libata: Pass the ATA port argument directly to ata_qc_schedule_eh() Bart Van Assche
2026-05-21 17:33 ` [PATCH v2 4/9] ata: libata: Pass the ATA port argument directly to ata_qc_complete() Bart Van Assche
2026-05-21 18:40   ` sashiko-bot
2026-05-21 20:30     ` Bart Van Assche
2026-05-26 13:23       ` Niklas Cassel
2026-05-21 17:33 ` [PATCH v2 5/9] ata: libata: Pass the ATA port argument directly to ata_qc_issue() Bart Van Assche
2026-05-21 18:56   ` sashiko-bot
2026-05-21 17:33 ` [PATCH v2 6/9] ata: libata: Pass the ATA port argument directly to __ata_qc_complete() Bart Van Assche
2026-05-21 17:33 ` [PATCH v2 7/9] ata: libata: Pass the ATA port argument directly to ata_link_abort() Bart Van Assche
2026-05-21 19:14   ` sashiko-bot
2026-05-21 17:33 ` [PATCH v2 8/9] ata: libata: Enable context analysis Bart Van Assche
2026-05-21 20:17   ` sashiko-bot
2026-05-21 20:31     ` Bart Van Assche
2026-05-27 10:48   ` Niklas Cassel
2026-05-21 17:33 ` [PATCH v2 9/9] ata: Annotate the code that uses the host lock Bart Van Assche
2026-05-21 20:38   ` sashiko-bot
2026-05-26 15:16   ` Niklas Cassel
2026-05-26 21:33     ` Bart Van Assche
2026-05-26 22:37       ` Damien Le Moal
2026-05-26 22:40       ` Marco Elver
2026-05-27 13:42         ` Niklas Cassel [this message]
2026-05-27 10:57   ` Niklas Cassel
2026-05-27 18:51   ` Damien Le Moal
2026-05-27 18:54     ` Bart Van Assche
2026-05-27 19:34       ` Damien Le Moal
2026-05-27  9:20 ` (subset) [PATCH v2 0/9] ata: libata-core: Enable context analysis Niklas Cassel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ahb0zRlRGMI0_WwT@ryzen \
    --to=cassel@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=dlemoal@kernel.org \
    --cc=elver@google.com \
    --cc=geert+renesas@glider.be \
    --cc=linux-ide@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=mikpelinux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox