From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46E87C433DF for ; Thu, 28 May 2020 18:31:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A6F8206A1 for ; Thu, 28 May 2020 18:31:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405798AbgE1Sby (ORCPT ); Thu, 28 May 2020 14:31:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:52988 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405775AbgE1Sbx (ORCPT ); Thu, 28 May 2020 14:31:53 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2F24AAD1A; Thu, 28 May 2020 18:31:52 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 66B781E1289; Thu, 28 May 2020 20:31:52 +0200 (CEST) Date: Thu, 28 May 2020 20:31:52 +0200 From: Jan Kara To: Bart Van Assche Cc: Jan Kara , Jens Axboe , linux-block@vger.kernel.org, Luis Chamberlain Subject: Re: [PATCH] blktrace: Avoid sparse warnings when assigning q->blk_trace Message-ID: <20200528183152.GH14550@quack2.suse.cz> References: <20200528092910.11118-1-jack@suse.cz> <298af02a-3b58-932a-8769-72dcc52750ad@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <298af02a-3b58-932a-8769-72dcc52750ad@acm.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On Thu 28-05-20 07:44:38, Bart Van Assche wrote: > (+Luis) > > On 2020-05-28 02:29, Jan Kara wrote: > > Mostly for historical reasons, q->blk_trace is assigned through xchg() > > and cmpxchg() atomic operations. Although this is correct, sparse > > complains about this because it violates rcu annotations. Furthermore > > there's no real need for atomic operations anymore since all changes to > > q->blk_trace happen under q->blk_trace_mutex. So let's just replace > > xchg() with rcu_replace_pointer() and cmpxchg() with explicit check and > > rcu_assign_pointer(). This makes the code more efficient and sparse > > happy. > > > > Reported-by: kbuild test robot > > Signed-off-by: Jan Kara > > How about adding a reference to commit c780e86dd48e ("blktrace: Protect > q->blk_trace with RCU") in the description of this patch? Yes, that's probably a good idea. > > @@ -1669,10 +1672,7 @@ static int blk_trace_setup_queue(struct request_queue *q, > > > > blk_trace_setup_lba(bt, bdev); > > > > - ret = -EBUSY; > > - if (cmpxchg(&q->blk_trace, NULL, bt)) > > - goto free_bt; > > - > > + rcu_assign_pointer(q->blk_trace, bt); > > get_probe_ref(); > > return 0; > > This changes a conditional assignment of q->blk_trace into an > unconditional assignment. Shouldn't q->blk_trace only be assigned if > q->blk_trace == NULL? Yes but both callers of blk_trace_setup_queue() actually check that q->blk_trace is NULL before calling blk_trace_setup_queue() and since we hold blk_trace_mutex all the time, the value of q->blk_trace cannot change. So the conditional assignment was just bogus. Honza -- Jan Kara SUSE Labs, CR