linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Paolo Valente <paolo.valente@linaro.org>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	ulf.hansson@linaro.org, linus.walleij@linaro.org,
	broonie@kernel.org
Subject: Re: [PATCH BUGFIX] block, bfq: access and cache blkg data only when safe
Date: Fri, 19 May 2017 10:54:42 -0400	[thread overview]
Message-ID: <20170519145442.GA7174@wtj.duckdns.org> (raw)
In-Reply-To: <20170519083908.2588-1-paolo.valente@linaro.org>

Hello, Paolo.

On Fri, May 19, 2017 at 10:39:08AM +0200, Paolo Valente wrote:
> Operations on blkg objects in blk-cgroup are protected with the
> request_queue lock, which is no more the lock that protects
> I/O-scheduler operations in blk-mq. The latter are now protected with
> finer-grained per-scheduler-instance locks. As a consequence, if blkg
> and blkg-related objects are accessed in a blk-mq I/O scheduler, it is
> possible to have races, unless proper care is taken for these
> accesses. BFQ does access these objects, and does incur these races.
> 
> This commit addresses this issue without introducing further locks, by
> exploiting the following facts.  Destroy operations on a blkg invoke,
> as a first step, hooks of the scheduler associated with the blkg. And
> these hooks are executed with bfqd->lock held for BFQ. As a
> consequence, for any blkg associated with the request queue an
> instance of BFQ is attached to, we are guaranteed that such a blkg is
> not destroyed and that all the pointers it contains are consistent,
> (only) while that instance is holding its bfqd->lock. A blkg_lookup
> performed with bfqd->lock held then returns a fully consistent blkg,
> which remains consistent until this lock is held.
> 
> In view of these facts, this commit caches any needed blkg data (only)
> when it (safely) detects a parent-blkg change for an internal entity,
> and, to cache these data safely, it gets the new blkg, through a
> blkg_lookup, and copies data while keeping the bfqd->lock held. As of
> now, BFQ needs to cache only the path of the blkg, which is used in
> the bfq_log_* functions.
> 
> This commit also removes or updates some stale comments on locking
> issues related to blk-cgroup operations.

For a quick fix, this is fine but I think it'd be much better to
update blkcg core so that we protect lookups with rcu and refcnt the
blkg with percpu refs so that we can use blkcg correctly for all
purposes with blk-mq.  There's no reason to hold up the immediate fix
for that but it'd be nice to at least note what we should be doing in
the longer term in a comment.

Thanks.

-- 
tejun

  parent reply	other threads:[~2017-05-19 14:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-19  8:39 [PATCH BUGFIX] block, bfq: access and cache blkg data only when safe Paolo Valente
2017-05-19 14:37 ` Jens Axboe
2017-05-22 20:20   ` Paolo Valente
2017-05-19 14:54 ` Tejun Heo [this message]
2017-05-20  7:27   ` Paolo Valente
2017-05-23 20:42     ` Tejun Heo
2017-05-24 11:53       ` Paolo Valente
2017-05-24 14:24         ` Paolo Valente
2017-05-24 14:50         ` Tejun Heo
2017-05-24 16:43           ` Paolo Valente
2017-05-24 16:47             ` Tejun Heo
2017-05-25  7:10               ` Paolo Valente
2017-05-25 14:37                 ` Tejun Heo
  -- strict thread matches above, loose matches on Subject: below --
2017-06-05  8:11 Paolo Valente
2017-06-08 15:30 ` Paolo Valente
2017-06-08 15:52   ` Jens Axboe

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=20170519145442.GA7174@wtj.duckdns.org \
    --to=tj@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=broonie@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paolo.valente@linaro.org \
    --cc=ulf.hansson@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).