Re: [PATCH v2 1/8] cleanup: Introduce ACQUIRE() and ACQUIRE_ERR() for conditional locks
From: Dan Williams
Date: Thu Jun 19 2025 - 17:18:49 EST
Dan Williams wrote:
> From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
>
> scoped_cond_guard(), automatic cleanup for conditional locks, has a couple
> pain points:
>
> * It causes existing straight-line code to be re-indented into a new
> bracketed scope. While this can be mitigated by a new helper function
> to contain the scope, that is not always a comfortable conversion.
>
> * The return code from the conditional lock is tossed in favor of a scheme
> to pass a 'return err;' statement to the macro.
>
> Other attempts to clean this up, to behave more like guard() [1], got hung
> up trying to both establish and evaluate the conditional lock in one
> statement.
>
> ACQUIRE() solves this by reflecting the result of the condition in the
> automatic variable established by the lock CLASS(). The result is
> separately retrieved with the ACQUIRE_ERR() helper, effectively a PTR_ERR()
> operation.
>
> Link: http://lore.kernel.org/all/Z1LBnX9TpZLR5Dkf@xxxxxxxxx [1]
> Link: http://patch.msgid.link/20250512105026.GP4439@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Link: http://patch.msgid.link/20250512185817.GA1808@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> Cc: David Lechner <dlechner@xxxxxxxxxxxx>
> Cc: Fabio M. De Francesco <fabio.m.de.francesco@xxxxxxxxxxxxxxx>
> Not-yet-signed-off-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> [djbw: wrap Peter's proposal with changelog and comments]
> Co-developed-by: Dan Williams <dan.j.williams@xxxxxxxxx>
> Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx>
With Peter's sign-off, pushed to for-6.17/cleanup-acquire as a stable
commit that others can reference:
https://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl.git/log/?h=for-6.17/cleanup-acquire