Remove BKL from default_llseek() and other issues (v2)
Subsystems (13)
cover Remove BKL from default_llseek() and other issues (v2)
Alan,
I worked on the list of driver that need fixing and found some other issue that I think are worth fixing. I post them in one big series because they are all related to llseek in some way even it they are not directly related to the removal of the big kernel lock from default_llseek():
- the osst driver does not really support seeking but wants to work around broken userspace and therefore needs a succeeding llseek
- use of f_pos in frv due to incomplete patch when removing file argument from proc_handler
- filesystems that use BKL in readdir and don't have llseek set shouldn't fall back to default_llseek() but use generic_file_llseek() instead
I hope that the patches address your feedback well.
Comments?
Cheers,
Jan
Jan Blunck (15):
Introduce noop_llseek()
osst: Use noop_llseek() instead of default_llseek()
osst: Update ppos instead of using file->f_pos
s390: tape_char should update ppos instead of using file->f_pos flash_read should update ppos instead of file->f_pos eeprom_read()/eeprom_write() should update ppos instead of
file->f_pos
sched_feat_write: Update ppos instead of file->f_pos
airo: Use ppos instead of file->f_pos
frv: remove "struct file *" argument from sysctl ->proc_handler
mISDN: Remove unnecessary test on f_pos
zcrypt: Use nonseekable_open()
rtc-m41t80: Use nonseekable_open()
Do not fallback to default_llseek() when readdir() uses BKL
BKL: Remove BKL from default_llseek()
BKL: Update documentation on llseek()
Documentation/filesystems/Locking | 5 +++-- arch/cris/arch-v10/drivers/eeprom.c | 34 +++++++++++++--------------------- arch/frv/kernel/sysctl.c | 18 ++++++++++-------- drivers/isdn/mISDN/timerdev.c | 2 -- drivers/net/wireless/airo.c | 2 +- drivers/rtc/rtc-m41t80.c | 6 +----- drivers/s390/char/tape_char.c | 4 ++-- drivers/s390/crypto/zcrypt_api.c | 2 +- drivers/sbus/char/flash.c | 6 +++--- drivers/scsi/osst.c | 9 +++++---- fs/autofs/root.c | 1 + fs/freevxfs/vxfs_lookup.c | 2 ++ fs/isofs/dir.c | 1 + fs/ncpfs/dir.c | 1 + fs/qnx4/dir.c | 1 + fs/read_write.c | 8 ++++++-- fs/reiserfs/dir.c | 1 + fs/smbfs/dir.c | 1 + fs/udf/dir.c | 1 + include/linux/fs.h | 1 + kernel/sched.c | 2 +- 21 files changed, 56 insertions(+), 52 deletions(-)
PATCH 1/15 Introduce noop_llseek()
The noop_llseek() is a llseek() operation that filesystems can use that don't want to support seeking (leave the file->f_pos untouched) but still want to let the syscall itself to succeed.
--- fs/read_write.c | 6 ++++++ include/linux/fs.h | 1 + 2 files changed, 7 insertions(+), 0 deletions(-)
fs/read_write.c +6 -0
@@ -97,6 +97,12 @@ loff_t generic_file_llseek(struct file *file, loff_t offset, int origin) }EXPORT_SYMBOL (generic_file_llseek); +loff_t noop_llseek (struct file *file,loff_t offset,int origin) +{ +return file->f_pos; +} +EXPORT_SYMBOL (noop_llseek); +loff_t no_llseek (struct file *file,loff_t offset,int origin) {return -ESPIPE ;
include/linux/fs.h +1 -0
@@ -2237,6 +2237,7 @@ extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,extern void file_ra_state_init (struct file_ra_state *ra,struct address_space *mapping); +extern loff_t noop_llseek (struct file *file,loff_t offset,int origin);extern loff_t no_llseek (struct file *file,loff_t offset,int origin);extern loff_t generic_file_llseek (struct file *file,loff_t offset,int origin); extern loff_t generic_file_llseek_unlocked(struct file *file, loff_t offset,
Signature · 1 line
1.6.4.2
Re: [PATCH 01/15] Introduce noop_llseek()
Quoted 3 lines · Jan Blunck
The
noop_llseek()is allseek()operation that filesystems can use that don't want to support seeking (leave thefile->f_posuntouched) but still want to let the syscall itself to succeed.
This is weird behaviour: if you want to allow llseek() to succeed but don't really support seeking, why does the device even care about the value of file->f_pos?
-- Jamie
Re: [PATCH 01/15] Introduce noop_llseek()
Quoted 8 lines · Jamie Lokier
Quoted 3 lines · Jan Blunck
The
noop_llseek()is allseek()operation that filesystems can use that don't want to support seeking (leave thefile->f_posuntouched) but still want to let the syscall itself to succeed.This is weird behaviour: if you want to allow
llseek()to succeed but don't really support seeking, why does the device even care about the value offile->f_pos?
The device itself does not care about it but it is userspace that is expecting the seek to succeed. There is a comment in osst that at least there seems to be a borken version of tar that wants to seek on the device even it that does not have any effect.
Regards,
Jan
Signature · 1 line
Jan Blunck <[email protected]>
Re: [PATCH 01/15] Introduce noop_llseek()
Quoted 7 lines · Jan Blunck
Quoted 5 lines · Jamie Lokier
Quoted 3 lines · Jan Blunck
The
noop_llseek()is allseek()operation that filesystems can use that don't want to support seeking (leave thefile->f_posuntouched) but still want to let the syscall itself to succeed.
Quoted 8 lines
Quoted 3 lines
This is weird behaviour: if you want to allow
llseek()to succeed but don't really support seeking, why does the device even care about the value offile->f_pos?The device itself does not care about it but it is userspace that is expecting the seek to succeed. There is a comment in osst that at least there seems to be a borken version of tar that wants to seek on the device even it that does not have any effect.
Looking at the question from the other side -- if the device and the user don't care about file->f_pos, what's wrong with calling generic_file_llseek instead of noop_llseek?
Arnd <><
PATCH 2/15 osst: Use noop_llseek() instead of default_llseek()
In reply to Jan Blunck__os_scsi_tape_open() suggests that llseek() doesn't work:
"We really want to do nonseekable_open(inode, filp); here, but some
versions of tar incorrectly call lseek on tapes and bail out if that fails. So we disallow pread() and pwrite(), but permit lseeks."
Instead of using the fallback default_llseek() the driver should use noop_llseek() which leaves the file->f_pos untouched but succeeds.
--- drivers/scsi/osst.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/scsi/osst.c +1 -0
@@ -5619,6 +5619,7 @@ static const struct file_operations osst_fops = { .open = os_scsi_tape_open, .flush = os_scsi_tape_flush, .release = os_scsi_tape_close, + .llseek = noop_llseek, };static int osst_supports (struct scsi_device * SDp)
Signature · 1 line
1.6.4.2
Re: [PATCH 02/15] osst: Use noop_llseek() instead of default_llseek()
Quoted 7 lines · Jan Blunck
__os_scsi_tape_open()suggests thatllseek()doesn't work:
"We really want to dononseekable_open(inode, filp); here, but some
versions of tar incorrectly call lseek on tapes and bail out if that fails. So we disallowpread()andpwrite(), but permit lseeks."Instead of using the fallback
default_llseek()the driver should usenoop_llseek()which leaves thefile->f_posuntouched but succeeds.
st.c has the same comment, but I didn't see a patch for st.c in the series.
-- Jamie
Re: [PATCH 02/15] osst: Use noop_llseek() instead of default_llseek()
Quoted 11 lines · Jamie Lokier
Quoted 7 lines · Jan Blunck
__os_scsi_tape_open()suggests thatllseek()doesn't work:
"We really want to dononseekable_open(inode, filp); here, but some
versions of tar incorrectly call lseek on tapes and bail out if that fails. So we disallowpread()andpwrite(), but permit lseeks."Instead of using the fallback
default_llseek()the driver should usenoop_llseek()which leaves thefile->f_posuntouched but succeeds.
st.chas the same comment, but I didn't see a patch forst.cin the series.
Right, that would make sense.
I wonder if anyone has this weird tar and could test if it actually works.
Signature · 12 lines
st: Use noop_llseek() instead of default_llseek() st_open() suggests that llseek() doesn't work: "We really want to do nonseekable_open(inode, filp); here, but some versions of tar incorrectly call lseek on tapes and bail out if that fails. So we disallow pread() and pwrite(), but permit lseeks." Instead of using the fallback default_llseek() the driver should use noop_llseek() which leaves the file->f_pos untouched but succeeds. Signed-off-by: Jan Blunck <[email protected]> ---
drivers/scsi/st.c +1 -0
@@ -3958,6 +3958,7 @@ static const struct file_operations st_fops = .open = st_open, .flush = st_flush, .release = st_release, + .llseek = noop_llseek, };static int st_probe (struct device *dev)
PATCH 3/15 osst: Update ppos instead of using file->f_pos
In reply to Jan Blunckosst_read()/osst_write() modify file->f_pos directly instead of the ppos given to them. The VFS later updates the file->f_pos and overwrites it with the value of ppos.
--- drivers/scsi/osst.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/osst.c +4 -4
@@ -3586,7 +3586,7 @@ if (SRpnt) printk(KERN_ERR "%s:A: Not supposed to have SRpnt at line %d\n", nameif (i == (-ENOSPC )) { transfer = STp->buffer->writing;/* FIXME -- check this logic */ if (transfer <= do_count) { - filp->f_pos += do_count - transfer; + *ppos += do_count - transfer; count -= do_count - transfer;if (STps->drv_block >=0 ) { STps->drv_block += (do_count - transfer) / STp->block_size;
@@ -3624,7 +3624,7 @@ if (SRpnt) printk(KERN_ERR "%s:A: Not supposed to have SRpnt at line %d\n", name goto out; } - filp->f_pos += do_count; + *ppos += do_count; b_point += do_count; count -= do_count;if (STps->drv_block >=0 ) {
@@ -3646,7 +3646,7 @@ if (SRpnt) printk(KERN_ERR "%s:A: Not supposed to have SRpnt at line %d\n", nameif (STps->drv_block >=0 ) { STps->drv_block += blks; } - filp->f_pos += count; + *ppos += count; count =0 ; }
@@ -3822,7 +3822,7 @@ static ssize_t osst_read(struct file * filp, char __user * buf, size_t count, lo } STp->logical_blk_num += transfer / STp->block_size; STps->drv_block += transfer / STp->block_size; - filp->f_pos += transfer; + *ppos += transfer; buf += transfer; total += transfer; }
Signature · 1 line
1.6.4.2
Re: [PATCH 03/15] osst: Update ppos instead of using file->f_pos
Quoted 3 lines · Jan Blunck
osst_read()/osst_write() modify
file->f_posdirectly instead of the ppos given to them. The VFS later updates thefile->f_posand overwrites it with the value of ppos.
I notice st.c doesn't use or update file->f_pos (or *ppos), so userspace probably won't be caring about f_pos from osst.c (they're both SCSI tape drivers). And osst.c doesn't use the value, it just increases it with each transfer. It doesn't even reset the value to zero when rewinding the tape, so it's not that meaningful.
So how about just removing those modifications to file->f_pos from osst.c?
-- Jamie
Re: [PATCH 03/15] osst: Update ppos instead of using file->f_pos
Quoted 5 lines · Jamie Lokier
Quoted 3 lines · Jan Blunck
osst_read()/osst_write() modify
file->f_posdirectly instead of the ppos given to them. The VFS later updates thefile->f_posand overwrites it with the value of ppos.
Quoted 7 lines
I notice
st.cdoesn't use or updatefile->f_pos(or *ppos), so userspace probably won't be caring aboutf_posfromosst.c(they're both SCSI tape drivers). Andosst.cdoesn't use the value, it just increases it with each transfer. It doesn't even reset the value to zero when rewinding the tape, so it's not that meaningful.So how about just removing those modifications to
file->f_posfromosst.c?
Or alternatively, perhaps they are missing from st.c. I don't know, but userspace can't have been all that dependent on the value :-)
-- Jamie
PATCH 4/15 s390: tape_char should update ppos instead of using file->f_pos
In reply to Jan Bluncktapechar_read()/tapechar_write() modify file->f_pos directly instead of the ppos given to them. The VFS later updates the file->f_pos and overwrites it with the unchanged value of ppos.
--- drivers/s390/char/tape_char.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/s390/char/tape_char.c +2 -2
@@ -170,7 +170,7 @@ tapechar_read(struct file *filp, char __user *data, size_t count, loff_t *ppos)if (rc ==0 ) { rc = block_size - request->rescnt;DBF_EVENT (6 ,"TCHAR:rbytes: %x\n" , rc); - filp->f_pos += rc; + *ppos += rc;/* Copy data from idal buffer to user space. */ if (idal_buffer_to_user (device->char_data.idal_buf, data, rc) !=0 )
@@ -238,7 +238,7 @@ tapechar_write(struct file *filp, const char __user *data, size_t count, loff_tbreak ;DBF_EVENT (6 ,"TCHAR:wbytes: %lx\n" , block_size - request->rescnt); - filp->f_pos += block_size - request->rescnt; + *ppos += block_size - request->rescnt; written += block_size - request->rescnt;if (request->rescnt !=0 )break ;
Signature · 1 line
1.6.4.2
PATCH 5/15 flash_read should update ppos instead of file->f_pos
In reply to Jan Blunckflash_read() updates file->f_pos directly instead of the ppos given. The VFS later updates the file->f_pos and overwrites it with the unchanged value of ppos.
--- drivers/sbus/char/flash.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/sbus/char/flash.c +3 -3
@@ -106,9 +106,9 @@ static ssize_t flash_read(struct file * file, char __user * buf, size_t count, loff_t *ppos) { - unsigned long p = file->f_pos; + loff_t p = *ppos;int i; - +if (count > flash.read_size - p) count = flash.read_size - p;
@@ -119,7 +119,7 @@ flash_read(struct file * file, char __user * buf, buf++; } - file->f_pos += count; + *ppos += count;return count; }
Signature · 1 line
1.6.4.2
PATCH 6/15 eeprom_read()/eeprom_write() should update ppos instead of file->f_pos
In reply to Jan Blunckeeprom_read()/eeprom_write() modify file->f_pos directly instead of the ppos given. The VFS later updates the file->f_pos and overwrites it with the unchanged value of ppos. Since nothing touches the struct file in eeprom_read()/eeprom_write() now, the on stack allocated struct file in eeprom_read_buf()/eeprom_write_buf() can be removed as well.
--- arch/cris/arch-v10/drivers/eeprom.c | 34 +++++++++++++--------------------- 1 files changed, 13 insertions(+), 21 deletions(-)
arch/cris/arch-v10/drivers/eeprom.c +13 -21
@@ -439,20 +439,18 @@ static loff_t eeprom_lseek(struct file * file, loff_t offset, int orig)static int eeprom_read_buf (loff_t addr,char * buf,int count) { -struct file f; - - f.f_pos = addr; -return eeprom_read (&f, buf, count, &addr); +return eeprom_read (NULL , buf, count, &addr); }/* Reads data from eeprom. */ -static ssize_t eeprom_read (struct file * file,char * buf,size_t count,loff_t *off) +static ssize_t eeprom_read (struct file * file,char * buf,size_t count, +loff_t *ppos) {int read=0 ; -unsigned long p = file->f_pos; +loff_t p = *ppos;unsigned char page;
@@ -498,11 +496,9 @@ static ssize_t eeprom_read(struct file * file, char * buf, size_t count, loff_t/* go on with the actual read */ read =read_from_eeprom ( buf, count); - +if (read >0 ) - { - file->f_pos += read; - } + *ppos += read; eeprom.busy--;wake_up_interruptible (&eeprom.wait_q);
@@ -513,18 +509,14 @@ static ssize_t eeprom_read(struct file * file, char * buf, size_t count, loff_tstatic int eeprom_write_buf (loff_t addr,const char * buf,int count) { -struct file f; - - f.f_pos = addr; - -return eeprom_write (&f, buf, count, &addr); +return eeprom_write (NULL , buf, count, &addr); }/* Writes data to eeprom. */ static ssize_t eeprom_write (struct file * file,const char * buf,size_t count, -loff_t *off) +loff_t *ppos) {int i, written, restart=1 ;unsigned long p;
@@ -543,9 +535,9 @@ static ssize_t eeprom_write(struct file * file, const char * buf, size_t count, { restart =0 ; written =0 ; - p = file->f_pos; - - + p = *ppos; + +while ( (written < count) && (p < eeprom.size)) {/* address the eeprom */
@@ -671,10 +663,10 @@ static ssize_t eeprom_write(struct file * file, const char * buf, size_t count, eeprom.busy--;wake_up_interruptible (&eeprom.wait_q); -if (written ==0 && file->f_pos >= eeprom.size){ +if (written ==0 && *ppos >= eeprom.size){return -ENOSPC ; } - file->f_pos += written; + *ppos += written;return written; }
Signature · 1 line
1.6.4.2
PATCH 7/15 sched_feat_write: Update ppos instead of file->f_pos
In reply to Jan Bluncksched_feat_write() should update ppos instead of file->f_pos.
--- kernel/sched.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sched.c +1 -1
@@ -772,7 +772,7 @@ sched_feat_write(struct file *filp, const char __user *ubuf,if (!sched_feat_names[i])return -EINVAL ; - filp->f_pos += cnt; + *ppos += cnt;return cnt; }
Signature · 1 line
1.6.4.2
[tip:sched/core] sched_feat_write(): Update ppos instead of file->f_pos
Commit-ID: 429947248f814e90f416ab4f68a871ab628000c3 Gitweb: http://git.kernel.org/tip/429947248f814e90f416ab4f68a871ab628000c3 Author: Jan Blunck <[email protected]> AuthorDate: Fri, 20 Nov 2009 17:40:37 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 23 Nov 2009 19:38:03 +0100
sched_feat_write(): Update ppos instead of file->f_pos
sched_feat_write() should update ppos instead of file->f_pos.
(This reduces some BKL dependencies of this code.)
LKML-Reference: <[email protected]>
--- kernel/sched.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sched.c +1 -1
@@ -771,7 +771,7 @@ sched_feat_write(struct file *filp, const char __user *ubuf,if (!sched_feat_names[i])return -EINVAL ; - filp->f_pos += cnt; + *ppos += cnt;return cnt; }
PATCH 8/15 airo: Use ppos instead of file->f_pos
In reply to Jan BlunckWhen updating the priv->writelen value the ppos given to proc_write() should be used instead of file->f_pos. This might lead to a wrong writelen value when pwrite() is used.
--- drivers/net/wireless/airo.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/wireless/airo.c +1 -1
@@ -4659,7 +4659,7 @@ static ssize_t proc_write( struct file *file,if (copy_from_user (priv->wbuffer + pos, buffer, len))return -EFAULT ;if ( pos + len > priv->writelen ) - priv->writelen = len + file->f_pos; + priv->writelen = pos + len; *offset = pos + len;return len; }
Signature · 1 line
1.6.4.2
PATCH 9/15 frv: remove "struct file *" argument from sysctl ->proc_handler
In reply to Jan BlunckSeems that Alexey Dobriyan missed this usage of the file argument when removing it from ->proc_handler in commit 8d65af789f3e2cf4cfbdbf71a0f7a61ebcd41d38.
--- arch/frv/kernel/sysctl.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
arch/frv/kernel/sysctl.c +10 -8
@@ -47,8 +47,9 @@ static void frv_change_dcache_mode(unsigned long newmode)/* * handle requests to dynamically switch the write caching mode delivered by /proc */ -static int procctl_frv_cachemode (ctl_table *table,int write,struct file *filp, -void __user *buffer,size_t *lenp,loff_t *ppos) +static int procctl_frv_cachemode (ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos) {unsigned long hsr0;char buff[8 ];
@@ -85,7 +86,7 @@ static int procctl_frv_cachemode(ctl_table *table, int write, struct file *filp, }/* read the state */ -if (filp->f_pos >0 ) { +if (*ppos >0 ) { *lenp =0 ;return 0 ; }
@@ -111,7 +112,7 @@ static int procctl_frv_cachemode(ctl_table *table, int write, struct file *filp,return -EFAULT ; *lenp = len; - filp->f_pos = len; + *ppos = len;return 0 ; }/* end procctl_frv_cachemode() */
@@ -121,8 +122,9 @@ static int procctl_frv_cachemode(ctl_table *table, int write, struct file *filp,* permit the mm_struct the nominated process is using have its MMU context ID pinned */ #ifdef CONFIG_MMU -static int procctl_frv_pin_cxnr (ctl_table *table,int write,struct file *filp, -void __user *buffer,size_t *lenp,loff_t *ppos) +static int procctl_frv_pin_cxnr (ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos) {pid_t pid;char buff[16 ], *p;
@@ -151,7 +153,7 @@ static int procctl_frv_pin_cxnr(ctl_table *table, int write, struct file *filp, }/* read the currently pinned CXN */ -if (filp->f_pos >0 ) { +if (*ppos >0 ) { *lenp =0 ;return 0 ; }
@@ -164,7 +166,7 @@ static int procctl_frv_pin_cxnr(ctl_table *table, int write, struct file *filp,return -EFAULT ; *lenp = len; - filp->f_pos = len; + *ppos = len;return 0 ; }/* end procctl_frv_pin_cxnr() */
Signature · 1 line
1.6.4.2
PATCH 10/15 mISDN: Remove unnecessary test on f_pos
In reply to Jan BlunckThis test is not doing anything since it is always false if the mISDN_read() is called from vfs_read(). Besides that the driver uses nonseekable_open() and is not using off or file->f_pos anywhere.
--- drivers/isdn/mISDN/timerdev.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/isdn/mISDN/timerdev.c +0 -2
@@ -96,8 +96,6 @@ mISDN_read(struct file *filep, char __user *buf, size_t count, loff_t *off)if (*debug &DEBUG_TIMER )printk (KERN_DEBUG "%s(%p, %p, %d, %p)\n" , __func__, filep, buf, (int )count, off); -if (*off != filep->f_pos) -return -ESPIPE ;if (list_empty (&dev->expired) && (dev->work ==0 )) {if (filep->f_flags &O_NONBLOCK )
Signature · 1 line
1.6.4.2
PATCH 11/15 zcrypt: Use nonseekable_open()
In reply to Jan Blunckzcrypt doesn't even allow to read/write the files it opens. So seeking on it shouldn't fall back to defaults either but should be disallowed as well.
--- drivers/s390/crypto/zcrypt_api.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/s390/crypto/zcrypt_api.c +1 -1
@@ -302,7 +302,7 @@ static int zcrypt_open(struct inode *inode, struct file *filp)lock_kernel ();atomic_inc (&zcrypt_open_count);unlock_kernel (); -return 0 ; +return nonseekable_open (inode, filp); }/**
Signature · 1 line
1.6.4.2
PATCH 12/15 rtc-m41t80: Use nonseekable_open()
In reply to Jan BlunckUse nonseekable_open() for this since seeking is not supported anyway.
--- drivers/rtc/rtc-m41t80.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-)
drivers/rtc/rtc-m41t80.c +1 -5
@@ -595,10 +595,6 @@ static void wdt_disable(void)static ssize_t wdt_write (struct file *file,const char __user *buf,size_t count,loff_t *ppos) { -/* Can't seek (pwrite) on this device -if (ppos != &file->f_pos) -return -ESPIPE; -*/ if (count) {wdt_ping ();return 1 ;
@@ -695,7 +691,7 @@ static int wdt_open(struct inode *inode, struct file *file)*/ wdt_is_open =1 ;unlock_kernel (); -return 0 ; +return nonseekable_open (inode, file); }return -ENODEV ; }
Signature · 1 line
1.6.4.2
PATCH 13/15 Do not fallback to default_llseek() when readdir() uses BKL
In reply to Jan BlunckDo not use the fallback default_llseek() if the readdir operation of the filesystem still uses the big kernel lock. Since llseek() modifies file->f_pos of the directory directly it may need locking to not confuse readdir which usually uses file->f_pos directly as well. Since the special characteristics of the BKL (unlocked on schedule) are not necessary in this case, the inode mutex can be used for locking as provided by generic_file_llseek(). This is only possible since all filesystems, except reiserfs, either use a directory as a flat file or with disk address offsets. Reiserfs on the other hand uses a 32bit hash off the filename as the offset so generic_file_llseek() can get used as well since the hash is always smaller than sb->s_maxbytes (= (512 << 32) - blocksize).
--- fs/autofs/root.c | 1 + fs/freevxfs/vxfs_lookup.c | 2 ++ fs/isofs/dir.c | 1 + fs/ncpfs/dir.c | 1 + fs/qnx4/dir.c | 1 + fs/reiserfs/dir.c | 1 + fs/smbfs/dir.c | 1 + fs/udf/dir.c | 1 + 8 files changed, 9 insertions(+), 0 deletions(-)
fs/autofs/root.c +1 -0
@@ -30,6 +30,7 @@ const struct file_operations autofs_root_operations = { .read = generic_read_dir, .readdir = autofs_root_readdir, .ioctl = autofs_root_ioctl, + .llseek = generic_file_llseek, };const struct inode_operations autofs_root_inode_operations = {
fs/freevxfs/vxfs_lookup.c +2 -0
@@ -57,6 +57,8 @@ const struct inode_operations vxfs_dir_inode_ops = { };const struct file_operations vxfs_dir_operations = { + .llseek = generic_file_llseek, + .read = generic_read_dir, .readdir = vxfs_readdir, };
fs/isofs/dir.c +1 -0
@@ -271,6 +271,7 @@ static int isofs_readdir(struct file *filp,const struct file_operations isofs_dir_operations = { + .llseek = generic_file_llseek, .read = generic_read_dir, .readdir = isofs_readdir, };
fs/ncpfs/dir.c +1 -0
@@ -50,6 +50,7 @@ extern int ncp_symlink(struct inode *, struct dentry *, const char *);const struct file_operations ncp_dir_operations = { + .llseek = generic_file_llseek, .read = generic_read_dir, .readdir = ncp_readdir, .ioctl = ncp_ioctl,
fs/qnx4/dir.c +1 -0
@@ -77,6 +77,7 @@ out:const struct file_operations qnx4_dir_operations = { + .llseek = generic_file_llseek, .read = generic_read_dir, .readdir = qnx4_readdir, .fsync = simple_fsync,
fs/reiserfs/dir.c +1 -0
@@ -17,6 +17,7 @@ static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry, int datasync);const struct file_operations reiserfs_dir_operations = { + .llseek = generic_file_llseek, .read = generic_read_dir, .readdir = reiserfs_readdir, .fsync = reiserfs_dir_fsync,
fs/smbfs/dir.c +1 -0
@@ -37,6 +37,7 @@ static int smb_link(struct dentry *, struct inode *, struct dentry *);const struct file_operations smb_dir_operations = { + .llseek = generic_file_llseek, .read = generic_read_dir, .readdir = smb_readdir, .ioctl = smb_ioctl,
fs/udf/dir.c +1 -0
@@ -207,6 +207,7 @@ static int udf_readdir(struct file *filp, void *dirent, filldir_t filldir)/* readdir and lookup functions */ const struct file_operations udf_dir_operations = { + .llseek = generic_file_llseek, .read = generic_read_dir, .readdir = udf_readdir, .ioctl = udf_ioctl,
Signature · 1 line
1.6.4.2
Re: [PATCH 13/15] Do not fallback to default_llseek() when readdir() uses BKL
Quoted 12 lines · Jan Blunck
Do not use the fallback
default_llseek()if the readdir operation of the filesystem still uses the big kernel lock. Sincellseek()modifiesfile->f_posof the directory directly it may need locking to not confuse readdir which usually usesfile->f_posdirectly as well. Since the special characteristics of the BKL (unlocked on schedule) are not necessary in this case, the inode mutex can be used for locking as provided bygeneric_file_llseek(). This is only possible since all filesystems, except reiserfs, either use a directory as a flat file or with disk address offsets. Reiserfs on the other hand uses a 32bit hash off the filename as the offset sogeneric_file_llseek()can get used as well since the hash is always smaller thansb->s_maxbytes(= (512 << 32) - blocksize).
Quoted 3 lines
Signed-off-by Jan Blunck <[email protected]>--- fs/udf/dir.c | 1 +
For the UDF part:
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 13/15] Do not fallback to default_llseek() when readdir() uses BKL
In reply to Jan BlunckQuoted 12 lines · Jan Blunck
Do not use the fallback
default_llseek()if the readdir operation of the filesystem still uses the big kernel lock. Sincellseek()modifiesfile->f_posof the directory directly it may need locking to not confuse readdir which usually usesfile->f_posdirectly as well. Since the special characteristics of the BKL (unlocked on schedule) are not necessary in this case, the inode mutex can be used for locking as provided bygeneric_file_llseek(). This is only possible since all filesystems, except reiserfs, either use a directory as a flat file or with disk address offsets. Reiserfs on the other hand uses a 32bit hash off the filename as the offset sogeneric_file_llseek()can get used as well since the hash is always smaller thansb->s_maxbytes(= (512 << 32) - blocksize).
Quoted 2 lines
Signed-off-by Jan Blunck <[email protected]>---
wrt fs/qnx4:
PATCH 14/15 BKL: Remove BKL from default_llseek()
In reply to Jan BlunckUsing the BKL in llseek() does not protect the inode's i_size from modification since the i_size is protected by a seqlock nowadays. Since default_llseek() is already using the i_size_read() wrapper it is not the BKL which is serializing the access here.
The access to file->f_pos is not protected by the BKL either since its access in vfs_write()/vfs_read() is not protected by any lock. If the BKL is not protecting anything here it can clearly get removed.
--- fs/read_write.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
fs/read_write.c +0 -2
@@ -113,7 +113,6 @@ loff_t default_llseek(struct file *file, loff_t offset, int origin) {loff_t retval; -lock_kernel ();switch (origin) {case SEEK_END : offset +=i_size_read (file->f_path.dentry->d_inode);
@@ -134,7 +133,6 @@ loff_t default_llseek(struct file *file, loff_t offset, int origin) retval = offset; } out: -unlock_kernel ();return retval; }EXPORT_SYMBOL (default_llseek);
Signature · 1 line
1.6.4.2
PATCH 15/15 BKL: Update documentation on llseek( )
In reply to Jan BlunckThe inode's i_size is not protected by the big kernel lock. Therefore it does not make sense to recommend taking the BKL in filesystems llseek operations. Instead it should use the inode's mutex or use just use i_size_read() instead. Add a note that this is not protecting file->f_pos.
--- Documentation/filesystems/Locking | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
Documentation/filesystems/Locking +3 -2
@@ -429,8 +429,9 @@ check_flags: no implementations. If your fs is not using generic_file_llseek, you need to acquire and release the appropriate locks in your ->llseek(). For many filesystems, it is probably safe to acquire the inode -semaphore. Note some filesystems (i.e. remote ones) provide no -protection for i_size so you will need to use the BKL. +mutex or just to use i_size_read() instead. +Note: this does not protect the file->f_pos against concurrent modifications +since this is something the userspace has to take care about. Note: ext2_release() was *the* source of contention on fs-intensive loads and dropping BKL on ->release() helps to get rid of that (we still
Signature · 1 line
1.6.4.2
Re: [PATCH 15/15] BKL: Update documentation on llseek()
Quoted 4 lines · On Fri, 20 Nov 2009 17:40:45 +0100 Jan Blunck <[email protected]> wrote:
The inode's
i_sizeis not protected by the big kernel lock. Therefore it does not make sense to recommend taking the BKL in filesystems llseek operations. Instead it should use the inode's mutex or use just usei_size_read()instead. Add a note that this is not protectingfile->f_pos.
Looks good to me reading through it.
Alan