All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tao Cui <cui.tao@linux.dev>
To: Nathan Chancellor <nathan@kernel.org>, Tejun Heo <tj@kernel.org>,
	Josef Bacik <josef@toxicpanda.com>, Jens Axboe <axboe@kernel.dk>
Cc: cui.tao@linux.dev, cgroups@vger.kernel.org,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev, stable@vger.kernel.org
Subject: Re: [PATCH v2] blk-throttle: Avoid unsequenced accesses to jiffies in throtl_schedule_pending_timer()
Date: Mon, 16 Nov 2026 20:44:06 +0800	[thread overview]
Message-ID: <01f0b173-dbd2-484e-8e53-f4a001af9acb@linux.dev> (raw)
In-Reply-To: <20261115-blk-throttle-wunsequenced-v2-1-1d297c891b82@kernel.org>



在 2026/11/16 11:37, Nathan Chancellor 写道:
> After a recent improvement in clang to warn on unsequenced accesses to
> volatile variables [1], two instances appear in
> throtl_schedule_pending_timer(), which can break the build with
> CONFIG_WERROR=y / W=e:
> 
>   block/blk-throttle.c:469:25: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced]
>     469 |                    expires - jiffies, jiffies);
>         |                              ~~~~~~~  ^
>   block/blk-throttle.c:469:25: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced]
>     469 |                    expires - jiffies, jiffies);
>         |                              ~~~~~~~  ^
> 
> Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11
> 6.5.2, unsequenced side effects on the same scalar object are undefined
> behavior. Per C11 6.5.2.2.10/12, the evaluation of arguments in a
> function call is indeterminately sequenced, meaning any side effects in
> the arguments are unsequenced.
> 
> Add a local variable to hold the value of jiffies before the function
> call so that there are no unsequenced side effects, clearing up the
> warning.
> 
> Cc: stable@vger.kernel.org
> Fixes: 69df0ab030c9 ("blk-throttle: separate out throtl_service_queue->pending_timer from throtl_data->dispatch_work")
> Closes: https://github.com/ClangBuiltLinux/linux/issues/2191
> Link: https://github.com/llvm/llvm-project/commit/955715460eaf9188c241c74750637fc82dfcc423 [1]
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Reviewed-by: Tao Cui <cuitao@kylinos.cn>
> ---
> Changes in v2:
> - Reuse value of jiffies in max_expire to avoid
>   -Wunused-but-set-variable for j when CONFIG_BLK_DEV_IO_TRACE is
>   disabled (Sashiko)
> - Link to v1: https://patch.msgid.link/20261114-blk-throttle-wunsequenced-v1-1-d28ed5553ff3@kernel.org
> ---
>  block/blk-throttle.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/block/blk-throttle.c b/block/blk-throttle.c
> index c5e26551956a..8e58e50bce4d 100644
> --- a/block/blk-throttle.c
> +++ b/block/blk-throttle.c
> @@ -453,7 +453,8 @@ static void throtl_dequeue_tg(struct throtl_grp *tg)
>  static void throtl_schedule_pending_timer(struct throtl_service_queue *sq,
>  					  unsigned long expires)
>  {
> -	unsigned long max_expire = jiffies + 8 * DFL_THROTL_SLICE;
> +	unsigned long j = jiffies;
> +	unsigned long max_expire = j + 8 * DFL_THROTL_SLICE;
>  
>  	/*
>  	 * Since we are adjusting the throttle limit dynamically, the sleep
> @@ -466,7 +467,7 @@ static void throtl_schedule_pending_timer(struct throtl_service_queue *sq,
>  		expires = max_expire;
>  	mod_timer(&sq->pending_timer, expires);
>  	throtl_log(sq, "schedule timer. delay=%lu jiffies=%lu",
> -		   expires - jiffies, jiffies);
> +		   expires - j, j);
>  }
>  
>  /**
> 
> ---
> base-commit: ab43ec385580b8f8abf72d70fa3acbf4e4f098a5
> change-id: 20261114-blk-throttle-wunsequenced-ccf308a23c1b
> 
> Best regards,
> --  
> Cheers,
> Nathan


      reply	other threads:[~2026-11-16 12:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  3:37 [PATCH v2] blk-throttle: Avoid unsequenced accesses to jiffies in throtl_schedule_pending_timer() Nathan Chancellor
2026-11-16 12:44 ` Tao Cui [this message]

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=01f0b173-dbd2-484e-8e53-f4a001af9acb@linux.dev \
    --to=cui.tao@linux.dev \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.