* Re: [PATCH] vfs: added better file aio_read aio_write operations presence check [not found] ` <bcGBv-4eJ-1@gated-at.bofh.it> @ 2008-09-16 15:36 ` Bodo Eggert 2008-09-16 15:41 ` Matthew Wilcox 0 siblings, 1 reply; 7+ messages in thread From: Bodo Eggert @ 2008-09-16 15:36 UTC (permalink / raw) To: Manish Katiyar, Marco Stornelli, viro, linux-fsdevel, linux-kernel Manish Katiyar <mkatiyar@gmail.com> wrote: > On Tue, Sep 16, 2008 at 2:59 PM, Marco Stornelli >> From: Marco Stornelli <marco.stornelli@gmail.com> >> If a filesystem in the file operations specifies for read and write >> operations only do_sync_read and do_sync_write without init aio_read and >> aio_write, there will be a kernel oops, because the vfs code check the >> presence of (to read for example) read OR aio_read method, then it calls read >> if it's pointer is not null. It's not sufficient because if the read function >> is actually a do_sync_read, it calls aio_read but without checking the >> presence. I think a BUG_ON check can be more useful. > > Instead of doing a BUG_ON() why can't we simply fall back to the > generic_aio functions since most of the fs tend to do so as below. > --- a/fs/read_write.c > - ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); > + if (filp->f_op->aio_read) > + ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); > + else > + ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos); Why can't the file system registration code set filp->f_op->aio_read to generic_file_aio_read? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] vfs: added better file aio_read aio_write operations presence check 2008-09-16 15:36 ` [PATCH] vfs: added better file aio_read aio_write operations presence check Bodo Eggert @ 2008-09-16 15:41 ` Matthew Wilcox 0 siblings, 0 replies; 7+ messages in thread From: Matthew Wilcox @ 2008-09-16 15:41 UTC (permalink / raw) To: Bodo Eggert Cc: Manish Katiyar, Marco Stornelli, viro, linux-fsdevel, linux-kernel On Tue, Sep 16, 2008 at 05:36:09PM +0200, Bodo Eggert wrote: > Why can't the file system registration code set filp->f_op->aio_read to > generic_file_aio_read? const struct file_operations *f_op; Having said that, BUILD_BUG_ON(!f_op->aio_read) is fine by me ... make the filesystem writer put it in without slowing down anyone at runtime. -- Matthew Wilcox Intel Open Source Technology Centre "Bill, look, we understand that you're interested in selling us this operating system, but compare it to ours. We can't possibly take such a retrograde step." ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] vfs: added better file aio_read aio_write operations presence check
@ 2008-09-16 9:29 Marco Stornelli
2008-09-16 11:03 ` Manish Katiyar
2008-09-16 16:36 ` Christoph Hellwig
0 siblings, 2 replies; 7+ messages in thread
From: Marco Stornelli @ 2008-09-16 9:29 UTC (permalink / raw)
To: viro, linux-fsdevel; +Cc: linux-kernel
From: Marco Stornelli <marco.stornelli@gmail.com>
If a filesystem in the file operations specifies for read and write operations only do_sync_read and do_sync_write without
init aio_read and aio_write, there will be a kernel oops, because the vfs code check the presence of (to read for example)
read OR aio_read method, then it calls read if it's pointer is not null. It's not sufficient because if the read function is
actually a do_sync_read, it calls aio_read but without checking the presence. I think a BUG_ON check can be more useful.
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
---
--- linux-2.6.26.5/fs/read_write.c.orig 2008-08-20 20:11:37.000000000 +0200
+++ linux-2.6.26.5/fs/read_write.c 2008-09-16 11:01:13.000000000 +0200
@@ -240,6 +240,7 @@ ssize_t do_sync_read(struct file *filp,
kiocb.ki_pos = *ppos;
kiocb.ki_left = len;
+ BUG_ON(!filp->f_op->aio_read);
for (;;) {
ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
@@ -295,6 +296,7 @@ ssize_t do_sync_write(struct file *filp,
kiocb.ki_pos = *ppos;
kiocb.ki_left = len;
+ BUG_ON(!filp->f_op->aio_write);
for (;;) {
ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] vfs: added better file aio_read aio_write operations presence check 2008-09-16 9:29 Marco Stornelli @ 2008-09-16 11:03 ` Manish Katiyar 2008-09-16 11:13 ` Marco Stornelli 2008-09-16 16:36 ` Christoph Hellwig 1 sibling, 1 reply; 7+ messages in thread From: Manish Katiyar @ 2008-09-16 11:03 UTC (permalink / raw) To: Marco Stornelli; +Cc: viro, linux-fsdevel, linux-kernel On Tue, Sep 16, 2008 at 2:59 PM, Marco Stornelli <marco.stornelli@coritel.it> wrote: > From: Marco Stornelli <marco.stornelli@gmail.com> > > If a filesystem in the file operations specifies for read and write operations only do_sync_read and do_sync_write without > init aio_read and aio_write, there will be a kernel oops, because the vfs code check the presence of (to read for example) > read OR aio_read method, then it calls read if it's pointer is not null. It's not sufficient because if the read function is > actually a do_sync_read, it calls aio_read but without checking the presence. I think a BUG_ON check can be more useful. Instead of doing a BUG_ON() why can't we simply fall back to the generic_aio functions since most of the fs tend to do so as below. Signed-off-by: Manish Katiyar <mkatiyar@gmail.com> --- fs/read_write.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 9ba495d..5439bc4 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -225,7 +225,11 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *pp kiocb.ki_left = len; for (;;) { - ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); + if (filp->f_op->aio_read) + ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); + else + ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos); if (ret != -EIOCBRETRY) break; wait_on_retry_sync_kiocb(&kiocb); @@ -280,7 +284,10 @@ ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, lof kiocb.ki_left = len; for (;;) { - ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos); + if (filp->f_op->aio_write) + ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos); + else + ret = generic_file_aio_write(&kiocb, &iov, 1, kiocb.ki_pos); if (ret != -EIOCBRETRY) break; wait_on_retry_sync_kiocb(&kiocb); -- 1.5.4.3 Thanks - Manish > Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com> > --- > > --- linux-2.6.26.5/fs/read_write.c.orig 2008-08-20 20:11:37.000000000 +0200 > +++ linux-2.6.26.5/fs/read_write.c 2008-09-16 11:01:13.000000000 +0200 > @@ -240,6 +240,7 @@ ssize_t do_sync_read(struct file *filp, > kiocb.ki_pos = *ppos; > kiocb.ki_left = len; > > + BUG_ON(!filp->f_op->aio_read); > for (;;) { > ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); > if (ret != -EIOCBRETRY) > @@ -295,6 +296,7 @@ ssize_t do_sync_write(struct file *filp, > kiocb.ki_pos = *ppos; > kiocb.ki_left = len; > > + BUG_ON(!filp->f_op->aio_write); > for (;;) { > ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos); > if (ret != -EIOCBRETRY) > > -- > To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] vfs: added better file aio_read aio_write operations presence check 2008-09-16 11:03 ` Manish Katiyar @ 2008-09-16 11:13 ` Marco Stornelli 2008-09-16 11:31 ` Manish Katiyar 0 siblings, 1 reply; 7+ messages in thread From: Marco Stornelli @ 2008-09-16 11:13 UTC (permalink / raw) To: Manish Katiyar; +Cc: viro, linux-fsdevel, linux-kernel BUG_ON it was a way to say: "hey you've used the do_sync_read/write as read/write operation but you don't specified an aio_read/write", but your solutions it's good too. Manish Katiyar ha scritto: > On Tue, Sep 16, 2008 at 2:59 PM, Marco Stornelli > <marco.stornelli@coritel.it> wrote: >> From: Marco Stornelli <marco.stornelli@gmail.com> >> >> If a filesystem in the file operations specifies for read and write operations only do_sync_read and do_sync_write without >> init aio_read and aio_write, there will be a kernel oops, because the vfs code check the presence of (to read for example) >> read OR aio_read method, then it calls read if it's pointer is not null. It's not sufficient because if the read function is >> actually a do_sync_read, it calls aio_read but without checking the presence. I think a BUG_ON check can be more useful. > > Instead of doing a BUG_ON() why can't we simply fall back to the > generic_aio functions since most of the fs tend to do so as below. > > > Signed-off-by: Manish Katiyar <mkatiyar@gmail.com> > > --- > fs/read_write.c | 10 ++++++++-- > 1 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/fs/read_write.c b/fs/read_write.c > index 9ba495d..5439bc4 100644 > --- a/fs/read_write.c > +++ b/fs/read_write.c > @@ -225,7 +225,11 @@ ssize_t do_sync_read(struct file *filp, char > __user *buf, size_t len, loff_t *pp > kiocb.ki_left = len; > > for (;;) { > - ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); > + if (filp->f_op->aio_read) > + ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); > + else > + ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos); > if (ret != -EIOCBRETRY) > break; > wait_on_retry_sync_kiocb(&kiocb); > @@ -280,7 +284,10 @@ ssize_t do_sync_write(struct file *filp, const > char __user *buf, size_t len, lof > kiocb.ki_left = len; > > for (;;) { > - ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos); > + if (filp->f_op->aio_write) > + ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos); > + else > + ret = generic_file_aio_write(&kiocb, &iov, 1, kiocb.ki_pos); > if (ret != -EIOCBRETRY) > break; > wait_on_retry_sync_kiocb(&kiocb); ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] vfs: added better file aio_read aio_write operations presence check 2008-09-16 11:13 ` Marco Stornelli @ 2008-09-16 11:31 ` Manish Katiyar 0 siblings, 0 replies; 7+ messages in thread From: Manish Katiyar @ 2008-09-16 11:31 UTC (permalink / raw) To: Marco Stornelli; +Cc: viro, linux-fsdevel, linux-kernel On Tue, Sep 16, 2008 at 4:43 PM, Marco Stornelli <marco.stornelli@coritel.it> wrote: > BUG_ON it was a way to say: "hey you've used the do_sync_read/write as > read/write operation but you don't specified an aio_read/write", but > your solutions it's good too. Looks like I made some copy paste error while sending the patch. Below is the updated one. Signed-off-by: Manish Katiyar <mkatiyar@gmail.com> --- fs/read_write.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 9ba495d..b89b707 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -225,7 +225,10 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *pp kiocb.ki_left = len; for (;;) { - ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); + if (filp->f_op->aio_read) + ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); + else + ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos); if (ret != -EIOCBRETRY) break; wait_on_retry_sync_kiocb(&kiocb); @@ -280,7 +283,10 @@ ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, lof kiocb.ki_left = len; for (;;) { - ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos); + if (filp->f_op->aio_write) + ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos); + else + ret = generic_file_aio_write(&kiocb, &iov, 1, kiocb.ki_pos); if (ret != -EIOCBRETRY) break; wait_on_retry_sync_kiocb(&kiocb); -- 1.5.4.3 Thanks - Manish > > Manish Katiyar ha scritto: >> On Tue, Sep 16, 2008 at 2:59 PM, Marco Stornelli >> <marco.stornelli@coritel.it> wrote: >>> From: Marco Stornelli <marco.stornelli@gmail.com> >>> >>> If a filesystem in the file operations specifies for read and write operations only do_sync_read and do_sync_write without >>> init aio_read and aio_write, there will be a kernel oops, because the vfs code check the presence of (to read for example) >>> read OR aio_read method, then it calls read if it's pointer is not null. It's not sufficient because if the read function is >>> actually a do_sync_read, it calls aio_read but without checking the presence. I think a BUG_ON check can be more useful. >> >> Instead of doing a BUG_ON() why can't we simply fall back to the >> generic_aio functions since most of the fs tend to do so as below. >> >> >> Signed-off-by: Manish Katiyar <mkatiyar@gmail.com> >> >> --- >> fs/read_write.c | 10 ++++++++-- >> 1 files changed, 8 insertions(+), 2 deletions(-) >> >> diff --git a/fs/read_write.c b/fs/read_write.c >> index 9ba495d..5439bc4 100644 >> --- a/fs/read_write.c >> +++ b/fs/read_write.c >> @@ -225,7 +225,11 @@ ssize_t do_sync_read(struct file *filp, char >> __user *buf, size_t len, loff_t *pp >> kiocb.ki_left = len; >> >> for (;;) { >> - ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); >> + if (filp->f_op->aio_read) >> + ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos); >> + else >> + ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos); >> if (ret != -EIOCBRETRY) >> break; >> wait_on_retry_sync_kiocb(&kiocb); >> @@ -280,7 +284,10 @@ ssize_t do_sync_write(struct file *filp, const >> char __user *buf, size_t len, lof >> kiocb.ki_left = len; >> >> for (;;) { >> - ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos); >> + if (filp->f_op->aio_write) >> + ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos); >> + else >> + ret = generic_file_aio_write(&kiocb, &iov, 1, kiocb.ki_pos); >> if (ret != -EIOCBRETRY) >> break; >> wait_on_retry_sync_kiocb(&kiocb); > > ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] vfs: added better file aio_read aio_write operations presence check 2008-09-16 9:29 Marco Stornelli 2008-09-16 11:03 ` Manish Katiyar @ 2008-09-16 16:36 ` Christoph Hellwig 1 sibling, 0 replies; 7+ messages in thread From: Christoph Hellwig @ 2008-09-16 16:36 UTC (permalink / raw) To: Marco Stornelli; +Cc: viro, linux-fsdevel, linux-kernel On Tue, Sep 16, 2008 at 11:29:41AM +0200, Marco Stornelli wrote: > From: Marco Stornelli <marco.stornelli@gmail.com> > > If a filesystem in the file operations specifies for read and write operations only do_sync_read and do_sync_write without > init aio_read and aio_write, there will be a kernel oops, because the vfs code check the presence of (to read for example) > read OR aio_read method, then it calls read if it's pointer is not null. It's not sufficient because if the read function is > actually a do_sync_read, it calls aio_read but without checking the presence. I think a BUG_ON check can be more useful. A NULL pointer derference is just as clear as the bug.. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-09-16 16:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <bcF2N-29W-1@gated-at.bofh.it>
[not found] ` <bcGBv-4eJ-1@gated-at.bofh.it>
2008-09-16 15:36 ` [PATCH] vfs: added better file aio_read aio_write operations presence check Bodo Eggert
2008-09-16 15:41 ` Matthew Wilcox
2008-09-16 9:29 Marco Stornelli
2008-09-16 11:03 ` Manish Katiyar
2008-09-16 11:13 ` Marco Stornelli
2008-09-16 11:31 ` Manish Katiyar
2008-09-16 16:36 ` Christoph Hellwig
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox