From: Andrew Morton <akpm@linux-foundation.org>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH -mm 3/5] fault-inject: make fail-nth read/write interface symmetric
Date: Wed, 12 Jul 2017 13:49:38 -0700 [thread overview]
Message-ID: <20170712134938.7c954021c6ebe90e609d02a1@linux-foundation.org> (raw)
In-Reply-To: <CACT4Y+YhP+FhfWebRSh4W+3inif7VFrgWf4xZY+F6r8805UQfQ@mail.gmail.com>
On Fri, 7 Apr 2017 22:37:01 +0200 Dmitry Vyukov <dvyukov@google.com> wrote:
> On Thu, Apr 6, 2017 at 4:55 PM, Akinobu Mita <akinobu.mita@gmail.com> wrote:
> > The read interface for fail-nth looks a bit odd. Read from this file
> > returns "NYYYY..." or "YYYYY..." (this makes me surprise when cat this
> > file). Because there is no EOF condition. The first character indicates
> > current->fail_nth is zero or not, and then current->fail_nth is reset
> > to zero.
> >
> > Just returning task->fail_nth value is more natural to understand.
> >
> > Cc: Dmitry Vyukov <dvyukov@google.com>
> > Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> > ---
> > Documentation/fault-injection/fault-injection.txt | 13 +++++++------
> > fs/proc/base.c | 14 ++++++--------
> > 2 files changed, 13 insertions(+), 14 deletions(-)
> >
> > diff --git a/Documentation/fault-injection/fault-injection.txt b/Documentation/fault-injection/fault-injection.txt
> > index a321905..370ddcb 100644
> > --- a/Documentation/fault-injection/fault-injection.txt
> > +++ b/Documentation/fault-injection/fault-injection.txt
> > @@ -139,9 +139,9 @@ o proc entries
> > - /proc/self/task/<current-tid>/fail-nth:
> >
> > Write to this file of integer N makes N-th call in the task fail.
> > - Read from this file returns a single char 'Y' or 'N'
> > - that says if the fault setup with a previous write to this file was
> > - injected or not, and disables the fault if it wasn't yet injected.
> > + Read from this file returns a integer value. A value of '0' indicates
> > + that the fault setup with a previous write to this file was injected.
> > + A positive integer N indicates that the fault wasn't yet injected.
> > Note that this file enables all types of faults (slab, futex, etc).
> > This setting takes precedence over all other generic debugfs settings
> > like probability, interval, times, etc. But per-capability settings
> > @@ -325,13 +325,14 @@ int main()
> > write(fail_nth, buf, strlen(buf));
> > res = socketpair(AF_LOCAL, SOCK_STREAM, 0, fds);
> > err = errno;
> > - read(fail_nth, buf, 1);
> > + pread(fail_nth, buf, sizeof(buf), 0);
> > if (res == 0) {
> > close(fds[0]);
> > close(fds[1]);
> > }
> > - printf("%d-th fault %c: res=%d/%d\n", i, buf[0], res, err);
> > - if (buf[0] != 'Y')
> > + printf("%d-th fault %c: res=%d/%d\n", i, atoi(buf) ? 'N' : 'Y',
> > + res, err);
> > + if (atoi(buf))
> > break;
> > }
> > return 0;
> > diff --git a/fs/proc/base.c b/fs/proc/base.c
> > index 42c52e2..9d14215 100644
> > --- a/fs/proc/base.c
> > +++ b/fs/proc/base.c
> > @@ -1383,7 +1383,8 @@ static ssize_t proc_fail_nth_read(struct file *file, char __user *buf,
> > size_t count, loff_t *ppos)
> > {
> > struct task_struct *task;
> > - int err;
> > + char numbuf[PROC_NUMBUF];
> > + ssize_t len;
> >
> > task = get_proc_task(file_inode(file));
> > if (!task)
> > @@ -1391,13 +1392,10 @@ static ssize_t proc_fail_nth_read(struct file *file, char __user *buf,
> > put_task_struct(task);
> > if (task != current)
> > return -EPERM;
> > - if (count < 1)
> > - return -EINVAL;
> > - err = put_user((char)(current->fail_nth ? 'N' : 'Y'), buf);
> > - if (err)
> > - return err;
> > - current->fail_nth = 0;
> > - return 1;
> > + len = snprintf(numbuf, sizeof(numbuf), "%u\n", task->fail_nth);
>
> If we allow setting this for non current task, then we need to prevent
> data races as the task uses task->fail_nth concurrently. Reads then
> should use READ_ONCE and writes in fault-inject.c should use
> WRITE_ONCE.
This remains unresolved?
next prev parent reply other threads:[~2017-07-12 20:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-06 14:55 [PATCH -mm 0/5] fault-inject: improve fail-nth interface Akinobu Mita
2017-04-06 14:55 ` [PATCH -mm 1/5] fault-inject: automatically detect the number base for fail-nth write interface Akinobu Mita
2017-04-06 14:55 ` [PATCH -mm 2/5] fault-inject: parse as natural 1-based value " Akinobu Mita
2017-04-06 14:55 ` [PATCH -mm 3/5] fault-inject: make fail-nth read/write interface symmetric Akinobu Mita
2017-04-07 20:37 ` Dmitry Vyukov
2017-07-12 20:49 ` Andrew Morton [this message]
2017-07-13 16:17 ` Akinobu Mita
2017-04-06 14:56 ` [PATCH -mm 4/5] fault-inject: simplify access check for fail-nth Akinobu Mita
2017-04-07 20:23 ` Dmitry Vyukov
2017-04-07 20:45 ` Dmitry Vyukov
2017-04-08 8:25 ` Akinobu Mita
2017-04-08 17:35 ` Dmitry Vyukov
2017-04-06 14:56 ` [PATCH -mm 5/5] fault-inject: add /proc/<pid>/fail-nth Akinobu Mita
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=20170712134938.7c954021c6ebe90e609d02a1@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=akinobu.mita@gmail.com \
--cc=dvyukov@google.com \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®