linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blktrace: re-write setting q->blk_trace
@ 2015-10-27  3:05 Davidlohr Bueso
  2015-10-27  3:14 ` [PATCH v2] " Davidlohr Bueso
  0 siblings, 1 reply; 10+ messages in thread
From: Davidlohr Bueso @ 2015-10-27  3:05 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Steven Rostedt, Ingo Molnar, linux-kernel, dave

This is really about simplifying the double xchg patterns into
a single cmpxchg, with the same logic. Other than the immediate
cleanup, there are some subtleties this change deals with:

(i) While the load of the old bt is fully ordered wrt everything,
ie:

       old_bt = xchg(&q->blk_trace, bt);             [barrier]
       if (old_bt)
	     (void) xchg(&q->blk_trace, old_bt);    [barrier]

blk_trace could still be changed between the xchg and the old_bt
load. Note that this description is merely theoretical and afaict
very small, but doing everything in a single context with cmpxchg
closes this potential race.

(ii) Ordering guarantees are obviously kept with cmpxchg.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
  kernel/trace/blktrace.c | 15 ++++-----------
  1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 90e72a0..4a30229 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -437,7 +437,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
		       struct block_device *bdev,
		       struct blk_user_trace_setup *buts)
  {
-	struct blk_trace *old_bt, *bt = NULL;
+	struct blk_trace *bt = NULL;
	struct dentry *dir = NULL;
	int ret;

@@ -519,11 +519,8 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
	bt->trace_state = Blktrace_setup;

	ret = -EBUSY;
-	old_bt = xchg(&q->blk_trace, bt);
-	if (old_bt) {
-		(void) xchg(&q->blk_trace, old_bt);
+	if (cmpxchg(&q->blk_trace, NULL, bt))
		goto err;
-	}

	if (atomic_inc_return(&blk_probes_ref) == 1)
		blk_register_tracepoints();
@@ -1481,7 +1478,7 @@ static int blk_trace_remove_queue(struct request_queue *q)
  static int blk_trace_setup_queue(struct request_queue *q,
				 struct block_device *bdev)
  {
-	struct blk_trace *old_bt, *bt = NULL;
+	struct blk_trace *bt = NULL;
	int ret = -ENOMEM;

	bt = kzalloc(sizeof(*bt), GFP_KERNEL);
@@ -1497,12 +1494,8 @@ static int blk_trace_setup_queue(struct request_queue *q,

	blk_trace_setup_lba(bt, bdev);

-	old_bt = xchg(&q->blk_trace, bt);
-	if (old_bt != NULL) {
-		(void)xchg(&q->blk_trace, old_bt);
-		ret = -EBUSY;
+	if (cmpxchg(&q->blk_trace, NULL, bt))
		goto free_bt;
-	}

	if (atomic_inc_return(&blk_probes_ref) == 1)
		blk_register_tracepoints();
--
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-10-29 21:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-27  3:05 [PATCH] blktrace: re-write setting q->blk_trace Davidlohr Bueso
2015-10-27  3:14 ` [PATCH v2] " Davidlohr Bueso
2015-10-28 21:37   ` Jeff Moyer
2015-10-29 19:19     ` Davidlohr Bueso
2015-10-29 19:35       ` Jeff Moyer
2015-10-29 20:28       ` Jens Axboe
2015-10-29 20:46         ` Jeff Moyer
2015-10-29 20:48           ` Jens Axboe
2015-10-29 20:52             ` Jeff Moyer
2015-10-29 21:05         ` Davidlohr Bueso

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).