From: Jens Axboe <jens.axboe@oracle.com>
To: linux-btrace@vger.kernel.org
Subject: Re: [RFC PATCH] block: disable IRQs until data is written to relay channel
Date: Fri, 30 May 2008 11:44:02 +0000 [thread overview]
Message-ID: <20080530114401.GY25504@kernel.dk> (raw)
In-Reply-To: <20080530110429.GA23157@ping.uio.no>
On Fri, May 30 2008, Carl Henrik Lunde wrote:
> Hi,
>
> Can you review this patch? I'm new to locking in the Linux kernel
> so I may be misssing something.
>
> I think we must disable IRQs between relay_reserve and initializing
> the data; consider the following scenario where task 1 and task 2
> runs on the same CPU:
>
> task 1: trace_note_message task 2: interrupt userspace (blktrace)
> -------------------------- ----------------- --------------------
> __trace_note_message read(relay)
> relay_reserve <blocks ...>
> <interrupted: I/O completion>
>
> __blk_add_trace
> relay_reserve
> <buffers switched,
> wake user>
> <reads uninitialized
> trace_note_message>
> <done>
> <runs again>
> memcpy() - too late
>
> --
> Carl Henrik
> From 30fce97a2d7c02ba265eceed59592dbdc9c34f26 Mon Sep 17 00:00:00 2001
> From: Carl Henrik Lunde <chlunde@ping.uio.no>
> Date: Fri, 30 May 2008 12:57:47 +0200
> Subject: [PATCH] block: disable IRQs until data is written to relay channel
>
> As we may run relay_reserve from interrupt context we must always disable
> IRQs. This is because a call to relay_reserve may expose previously written
> data to use space.
>
> Updated new message code and an old but related comment.
>
> Signed-off-by: Carl Henrik Lunde <chlunde@ping.uio.no>
> ---
> block/blktrace.c | 10 ++++------
> 1 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/block/blktrace.c b/block/blktrace.c
> index 7ae87cc..8d3a277 100644
> --- a/block/blktrace.c
> +++ b/block/blktrace.c
> @@ -79,16 +79,17 @@ void __trace_note_message(struct blk_trace *bt, const char *fmt, ...)
> {
> int n;
> va_list args;
> + unsigned long flags;
> char *buf;
>
> - preempt_disable();
> + local_irq_save(flags);
> buf = per_cpu_ptr(bt->msg_data, smp_processor_id());
> va_start(args, fmt);
> n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
> va_end(args);
>
> trace_note(bt, 0, BLK_TN_MESSAGE, buf, n);
> - preempt_enable();
> + local_irq_restore(flags);
Good spotting, applied! Thanks.
--
Jens Axboe
next prev parent reply other threads:[~2008-05-30 11:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-30 11:04 [RFC PATCH] block: disable IRQs until data is written to relay Carl Henrik Lunde
2008-05-30 11:44 ` Jens Axboe [this message]
2008-06-11 12:32 ` [RFC PATCH] block: disable IRQs until data is written to relay channel Carl Henrik Lunde
2008-06-11 13:06 ` 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=20080530114401.GY25504@kernel.dk \
--to=jens.axboe@oracle.com \
--cc=linux-btrace@vger.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 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).