* kernel bug 2.6.31-rc6 (2)
@ 2009-08-19 12:48 Christoph Thielecke
2009-08-19 13:47 ` Eric Paris
2009-08-19 22:26 ` Eric Paris
0 siblings, 2 replies; 5+ messages in thread
From: Christoph Thielecke @ 2009-08-19 12:48 UTC (permalink / raw)
To: Linux Kernel Mailing List, Eric Paris
[-- Attachment #1: Type: text/plain, Size: 6335 bytes --]
Hello list,
another freeze comes here (still using xephr):
Aug 19 14:04:22 develop kernel: plasma[30850]: segfault at 4 ip b6acef4d sp
bfe72230 error 4 in libQtGui.so.4.5.1[b6993000+81a000]
Aug 19 14:05:03 develop kernel: idr_remove called for id=1024 which is not
allocated.
Aug 19 14:05:03 develop kernel: Pid: 11958, comm: kded4 Tainted: P W
2.6.31-rc6 #2
Aug 19 14:05:03 develop kernel: Call Trace:
Aug 19 14:05:03 develop kernel: [<c133a0b0>] ? printk+0x18/0x20
Aug 19 14:05:03 develop kernel: [<c11d00c0>] idr_remove+0x79/0x1ad
Aug 19 14:05:03 develop kernel: [<c10db9d1>] ?
fsnotify_add_notify_event+0x105/0x205
Aug 19 14:05:03 develop kernel: [<c10ddce3>] inotify_remove_from_idr+0x21/0x34
Aug 19 14:05:03 develop kernel: [<c10de1ae>]
inotify_ignored_and_remove_idr+0x85/0xb7
Aug 19 14:05:03 develop kernel: [<c10dd753>] inotify_freeing_mark+0x8/0xa
Aug 19 14:05:03 develop kernel: [<c10dc3ab>]
fsnotify_destroy_mark_by_entry+0xf3/0x132
Aug 19 14:05:03 develop kernel: [<c10dc532>]
fsnotify_clear_marks_by_group+0x9b/0xc9
Aug 19 14:05:03 develop kernel: [<c10dd8e5>] inotify_release+0x12/0x26
Aug 19 14:05:03 develop kernel: [<c10b3dfa>] __fput+0xd3/0x1ba
Aug 19 14:05:03 develop kernel: [<c10b3efc>] fput+0x1b/0x20
Aug 19 14:05:03 develop kernel: [<c10b108e>] filp_close+0x41/0x5f
Aug 19 14:05:03 develop kernel: [<c10342d5>] put_files_struct+0x68/0xa6
Aug 19 14:05:03 develop kernel: [<c103434a>] exit_files+0x37/0x3c
Aug 19 14:05:03 develop kernel: [<c1035777>] do_exit+0x146/0x6c6
Aug 19 14:05:03 develop kernel: [<c1035d27>] do_group_exit+0x30/0x85
Aug 19 14:05:03 develop kernel: [<c1035d8f>] sys_exit_group+0x13/0x17
Aug 19 14:05:03 develop kernel: [<c1003610>] sysenter_do_call+0x12/0x2c
Aug 19 14:05:03 develop kernel: ------------[ cut here ]------------
Aug 19 14:05:03 develop kernel: kernel BUG at
fs/notify/inotify/inotify_fsnotify.c:109!
Aug 19 14:05:03 develop kernel: invalid opcode: 0000 [#1] PREEMPT SMP
Aug 19 14:05:03 develop kernel: last sysfs
file: /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-7/1-7.2/product
Aug 19 14:05:03 develop kernel: Modules linked in: xt_TCPMSS xt_tcpudp
iptable_filter ip_tables x_tables ppp_async crc_ccitt ppp_mppe nvidia(P)
binfmt_misc ppdev parport_pc lp parport rfcomm l2cap tun vboxnetadp
vboxnetflt vboxdrv pppol2tp pppox ppp_generic slhc ipv6 capifs acpi_cpufreq
cpufreq_ondemand cpufreq_powersave cpufreq_stats freq_table cpufreq_userspace
cpufreq_conservative nfsd nfs lockd fscache nfs_acl auth_rpcgss sunrpc
deflate zlib_deflate ctr twofish twofish_common camellia serpent blowfish
cast5 des_generic cbc aes_i586 aes_generic xcbc rmd160 sha256_generic
sha1_generic crypto_null af_key nls_iso8859_1 nls_cp437 vfat fat fuse
dm_snapshot dm_mirror dm_region_hash dm_log dm_mod coretemp loop asix dm9601
pl2303 usbnet usbserial usbhid hid btusb bluetooth snd_hda_codec_idt
snd_hda_intel snd_hda_codec snd_hwdep snd_pcm_oss snd_mixer_oss arc4
usb_storage snd_pcm ecb snd_seq_dummy snd_seq_oss firewire_ohci snd_seq_midi
snd_rawmidi iwl3945 firewire_core joydev snd_seq_midi_event iwlcore crc_itu_t
b44 iTCO_wdt snd_seq ssb iTCO_vendor_support snd_timer snd_seq_device
sdhci_pci sdhci mac80211 ohci1394 pcmcia pcmcia_core rtc_cmos rtc_core snd
mmc_core i2c_i801 intel_agp uhci_hcd ehci_hcd ricoh_mmc ieee1394 mii psmouse
video rtc_lib soundcore snd_page_alloc led_class i2c_core agpgart cfg80211
usbcore battery ac button processor serio_raw output wmi dell_laptop thermal
rfkill sg sr_mod cdrom evdev
Aug 19 14:05:03 develop kernel:
Aug 19 14:05:03 develop kernel: Pid: 11958, comm: kded4 Tainted: P W
(2.6.31-rc6 #2) MP061
Aug 19 14:05:03 develop kernel: EIP: 0060:[<c10dd747>] EFLAGS: 00210282 CPU: 0
Aug 19 14:05:03 develop kernel: EIP is at idr_callback+0x3/0x7
Aug 19 14:05:03 develop kernel: EAX: 00000000 EBX: 00000000 ECX: 00000000 EDX:
eea26cd0
Aug 19 14:05:03 develop kernel: ESI: f13c9e80 EDI: 00000000 EBP: f13c9e5c ESP:
f13c9e5c
Aug 19 14:05:03 develop kernel: DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Aug 19 14:05:03 develop kernel: Process kded4 (pid: 11958, ti=f13c8000
task=ee942450 task.ti=f13c8000)
Aug 19 14:05:03 develop kernel: Stack:
Aug 19 14:05:03 develop kernel: f13c9ea0 c11cf6fe 00000000 c10dd744 00000400
eea26cd0 00000000 efe90c14
Aug 19 14:05:03 develop kernel: <0> eede5a58 f13c9e8c c10dbb0a f2470858
f13c9eac c10dbba6 ef806fa0 f6927a40
Aug 19 14:05:03 develop kernel: <0> f6c4a9e8 f13c9eac c10dd76c ef806f40
f13c9eb8 c10dbc0f ef806f40 f13c9ec4
Aug 19 14:05:03 develop kernel: Call Trace:
Aug 19 14:05:03 develop kernel: [<c11cf6fe>] ? idr_for_each+0x62/0xb0
Aug 19 14:05:03 develop kernel: [<c10dd744>] ? idr_callback+0x0/0x7
Aug 19 14:05:03 develop kernel: [<c10dbb0a>] ? fsnotify_put_event+0x39/0x4a
Aug 19 14:05:03 develop kernel: [<c10dbba6>] ? fsnotify_flush_notify+0x8b/0x95
Aug 19 14:05:03 develop kernel: [<c10dd76c>] ?
inotify_free_group_priv+0x17/0x28
Aug 19 14:05:03 develop kernel: [<c10dbc0f>] ?
fsnotify_final_destroy_group+0x19/0x23
Aug 19 14:05:03 develop kernel: [<c10dbcd5>] ? fsnotify_put_group+0x70/0x77
Aug 19 14:05:03 develop kernel: [<c10dd8ec>] ? inotify_release+0x19/0x26
Aug 19 14:05:03 develop kernel: [<c10b3dfa>] ? __fput+0xd3/0x1ba
Aug 19 14:05:03 develop kernel: [<c10b3efc>] ? fput+0x1b/0x20
Aug 19 14:05:03 develop kernel: [<c10b108e>] ? filp_close+0x41/0x5f
Aug 19 14:05:03 develop kernel: [<c10342d5>] ? put_files_struct+0x68/0xa6
Aug 19 14:05:03 develop kernel: [<c103434a>] ? exit_files+0x37/0x3c
Aug 19 14:05:03 develop kernel: [<c1035777>] ? do_exit+0x146/0x6c6
Aug 19 14:05:03 develop kernel: [<c1035d27>] ? do_group_exit+0x30/0x85
Aug 19 14:05:03 develop kernel: [<c1035d8f>] ? sys_exit_group+0x13/0x17
Aug 19 14:05:03 develop kernel: [<c1003610>] ? sysenter_do_call+0x12/0x2c
Aug 19 14:05:03 develop kernel: Code: 89 04 24 8b 4d e8 8b 55 ec 89 f8 e8 5f
f9 ff ff 89 d8 e8 5d 4b fe ff eb 97 89 f0 e8 7d ee 25 00 8d 74 26 00 eb 8a 90
90 55 89 e5 <0f> 0b eb fe 55 89 e5 e8 d6 09 00 00 5d c3 55 89 e5 53 89 c3 83
Aug 19 14:05:03 develop kernel: EIP: [<c10dd747>] idr_callback+0x3/0x7 SS:ESP
0068:f13c9e5c
Aug 19 14:05:03 develop kernel: ---[ end trace 0dbb2fea4568c322 ]---
--
Linux User Group Wernigerode
http://www.lug-wr.de/
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kernel bug 2.6.31-rc6 (2)
2009-08-19 12:48 kernel bug 2.6.31-rc6 (2) Christoph Thielecke
@ 2009-08-19 13:47 ` Eric Paris
2009-08-19 22:26 ` Eric Paris
1 sibling, 0 replies; 5+ messages in thread
From: Eric Paris @ 2009-08-19 13:47 UTC (permalink / raw)
To: christoph.thielecke; +Cc: Linux Kernel Mailing List, Eric Paris
On Wed, Aug 19, 2009 at 8:48 AM, Christoph
Thielecke<christoph.thielecke@gmx.de> wrote:
> Hello list,
>
> another freeze comes here (still using xephr):
>
> Aug 19 14:04:22 develop kernel: plasma[30850]: segfault at 4 ip b6acef4d sp
> bfe72230 error 4 in libQtGui.so.4.5.1[b6993000+81a000]
> Aug 19 14:05:03 develop kernel: idr_remove called for id=1024 which is not
> allocated.
> Aug 19 14:05:03 develop kernel: Pid: 11958, comm: kded4 Tainted: P W
> 2.6.31-rc6 #2
> Aug 19 14:05:03 develop kernel: Call Trace:
> Aug 19 14:05:03 develop kernel: [<c133a0b0>] ? printk+0x18/0x20
> Aug 19 14:05:03 develop kernel: [<c11d00c0>] idr_remove+0x79/0x1ad
> Aug 19 14:05:03 develop kernel: [<c10db9d1>] ?
> fsnotify_add_notify_event+0x105/0x205
> Aug 19 14:05:03 develop kernel: [<c10ddce3>] inotify_remove_from_idr+0x21/0x34
> Aug 19 14:05:03 develop kernel: [<c10de1ae>]
> inotify_ignored_and_remove_idr+0x85/0xb7
> Aug 19 14:05:03 develop kernel: [<c10dd753>] inotify_freeing_mark+0x8/0xa
> Aug 19 14:05:03 develop kernel: [<c10dc3ab>]
> fsnotify_destroy_mark_by_entry+0xf3/0x132
> Aug 19 14:05:03 develop kernel: [<c10dc532>]
> fsnotify_clear_marks_by_group+0x9b/0xc9
> Aug 19 14:05:03 develop kernel: [<c10dd8e5>] inotify_release+0x12/0x26
> Aug 19 14:05:03 develop kernel: [<c10b3dfa>] __fput+0xd3/0x1ba
> Aug 19 14:05:03 develop kernel: [<c10b3efc>] fput+0x1b/0x20
> Aug 19 14:05:03 develop kernel: [<c10b108e>] filp_close+0x41/0x5f
> Aug 19 14:05:03 develop kernel: [<c10342d5>] put_files_struct+0x68/0xa6
> Aug 19 14:05:03 develop kernel: [<c103434a>] exit_files+0x37/0x3c
> Aug 19 14:05:03 develop kernel: [<c1035777>] do_exit+0x146/0x6c6
> Aug 19 14:05:03 develop kernel: [<c1035d27>] do_group_exit+0x30/0x85
> Aug 19 14:05:03 develop kernel: [<c1035d8f>] sys_exit_group+0x13/0x17
> Aug 19 14:05:03 develop kernel: [<c1003610>] sysenter_do_call+0x12/0x2c
> Aug 19 14:05:03 develop kernel: ------------[ cut here ]------------
Hmmm, this one could possibly be a race between adding a new watch
while destroying the group, maybe? I'm going to go over the add a new
watch function with a fine tooth comb. The wd looks 'ok,' 1024
surprises me but it's sorta reasonable that we could have jut happened
to have 1023 other watches.
The second panic is because of the above problem (we left something in
the idr).
It might be the same as the other report in that it could be something
is overwriting entry->wd after it is in memory. But that isn't
supposed to happen!
-Eric
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kernel bug 2.6.31-rc6 (2)
2009-08-19 12:48 kernel bug 2.6.31-rc6 (2) Christoph Thielecke
2009-08-19 13:47 ` Eric Paris
@ 2009-08-19 22:26 ` Eric Paris
2009-08-20 5:48 ` Christoph Thielecke
1 sibling, 1 reply; 5+ messages in thread
From: Eric Paris @ 2009-08-19 22:26 UTC (permalink / raw)
To: christoph.thielecke; +Cc: Linux Kernel Mailing List
On Wed, 2009-08-19 at 14:48 +0200, Christoph Thielecke wrote:
> Aug 19 14:05:03 develop kernel: kernel BUG at
> fs/notify/inotify/inotify_fsnotify.c:109!
Can you apply the following patch? It cleans up some logic, which I
didn't see a problem with, but it makes it very easy for me to know it's
right now. It also should prevent the BUG() you hit from bringing down
the box.
-Eric
commit da9d447e409fdca12001378650f020982093e91e
Author: Eric Paris <eparis@redhat.com>
Date: Wed Aug 19 17:01:12 2009 -0400
inotify: the inotify add watch code is horrible clean it up
Just reworking the inotify watch add code to be readable, clean, and full
of a lot less gotos.
Signed-off-by: Eric Paris <eparis@redhat.com>
diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
index d11ac71..1df198b 100644
--- a/fs/notify/inotify/inotify_fsnotify.c
+++ b/fs/notify/inotify/inotify_fsnotify.c
@@ -179,14 +179,25 @@ static bool inotify_should_send_event(struct fsnotify_group *group, struct inode
static int idr_callback(int id, void *p, void *data)
{
- BUG();
+ struct fsnotify_mark_entry *entry;
+ struct inotify_inode_mark_entry *ientry;
+
+ entry = p;
+ ientry = container_of(entry, struct inotify_inode_mark_entry, fsn_entry);
+
+ WARN(1, "inotify closing but id=%d still in idr. Probably leaking memory\n", id);
+
+ printk(KERN_WARNING "group=%p entry->group=%p inode=%p wd=%d\n",
+ data, entry->group, entry->inode, ientry->wd);
+
return 0;
}
static void inotify_free_group_priv(struct fsnotify_group *group)
{
- /* ideally the idr is empty and we won't hit the BUG in teh callback */
- idr_for_each(&group->inotify_data.idr, idr_callback, NULL);
+ /* the idr is supposed to be empty. The idr callback should never trigger
+ * and idr_remove_all() should basically be a noop. */
+ idr_for_each(&group->inotify_data.idr, idr_callback, group);
idr_remove_all(&group->inotify_data.idr);
idr_destroy(&group->inotify_data.idr);
}
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index ac0b739..24c2171 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -431,80 +431,29 @@ static void inotify_free_mark(struct fsnotify_mark_entry *entry)
kmem_cache_free(inotify_inode_mark_cachep, ientry);
}
-static int inotify_update_watch(struct fsnotify_group *group, struct inode *inode, u32 arg)
+static int inotify_update_existing_watch(struct fsnotify_group *group,
+ struct inode *inode,
+ u32 arg)
{
- struct fsnotify_mark_entry *entry = NULL;
+ struct fsnotify_mark_entry *entry;
struct inotify_inode_mark_entry *ientry;
- struct inotify_inode_mark_entry *tmp_ientry;
- int ret = 0;
- int add = (arg & IN_MASK_ADD);
- __u32 mask;
__u32 old_mask, new_mask;
+ __u32 mask;
+ int add = (arg & IN_MASK_ADD);
+ int ret;
/* don't allow invalid bits: we don't want flags set */
mask = inotify_arg_to_mask(arg);
if (unlikely(!mask))
return -EINVAL;
- tmp_ientry = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL);
- if (unlikely(!tmp_ientry))
- return -ENOMEM;
- /* we set the mask at the end after attaching it */
- fsnotify_init_mark(&tmp_ientry->fsn_entry, inotify_free_mark);
- tmp_ientry->wd = -1;
-
-find_entry:
spin_lock(&inode->i_lock);
entry = fsnotify_find_mark_entry(group, inode);
spin_unlock(&inode->i_lock);
- if (entry) {
- ientry = container_of(entry, struct inotify_inode_mark_entry, fsn_entry);
- } else {
- ret = -ENOSPC;
- if (atomic_read(&group->inotify_data.user->inotify_watches) >= inotify_max_user_watches)
- goto out_err;
-retry:
- ret = -ENOMEM;
- if (unlikely(!idr_pre_get(&group->inotify_data.idr, GFP_KERNEL)))
- goto out_err;
-
- spin_lock(&group->inotify_data.idr_lock);
- ret = idr_get_new_above(&group->inotify_data.idr, &tmp_ientry->fsn_entry,
- group->inotify_data.last_wd,
- &tmp_ientry->wd);
- spin_unlock(&group->inotify_data.idr_lock);
- if (ret) {
- if (ret == -EAGAIN)
- goto retry;
- goto out_err;
- }
+ if (!entry)
+ return -ENOENT;
- ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode, 0);
- if (ret) {
- inotify_remove_from_idr(group, tmp_ientry);
- if (ret == -EEXIST)
- goto find_entry;
- goto out_err;
- }
-
- /* tmp_ientry has been added to the inode, so we are all set up.
- * now we just need to make sure tmp_ientry doesn't get freed and
- * we need to set up entry and ientry so the generic code can
- * do its thing. */
- ientry = tmp_ientry;
- entry = &ientry->fsn_entry;
- tmp_ientry = NULL;
-
- atomic_inc(&group->inotify_data.user->inotify_watches);
-
- /* update the idr hint */
- group->inotify_data.last_wd = ientry->wd;
-
- /* we put the mark on the idr, take a reference */
- fsnotify_get_mark(entry);
- }
-
- ret = ientry->wd;
+ ientry = container_of(entry, struct inotify_inode_mark_entry, fsn_entry);
spin_lock(&entry->lock);
@@ -536,18 +485,103 @@ retry:
fsnotify_recalc_group_mask(group);
}
- /* this either matches fsnotify_find_mark_entry, or init_mark_entry
- * depending on which path we took... */
+ /* return the wd */
+ ret = ientry->wd;
+
+ /* match the get from fsnotify_find_mark_entry() */
fsnotify_put_mark(entry);
+ return ret;
+}
+
+static int inotify_new_watch(struct fsnotify_group *group,
+ struct inode *inode,
+ u32 arg)
+{
+ struct inotify_inode_mark_entry *tmp_ientry;
+ __u32 mask;
+ int ret;
+
+ /* don't allow invalid bits: we don't want flags set */
+ mask = inotify_arg_to_mask(arg);
+ if (unlikely(!mask))
+ return -EINVAL;
+
+ tmp_ientry = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL);
+ if (unlikely(!tmp_ientry))
+ return -ENOMEM;
+
+ fsnotify_init_mark(&tmp_ientry->fsn_entry, inotify_free_mark);
+ tmp_ientry->fsn_entry.mask = mask;
+ tmp_ientry->wd = -1;
+
+ ret = -ENOSPC;
+ if (atomic_read(&group->inotify_data.user->inotify_watches) >= inotify_max_user_watches)
+ goto out_err;
+retry:
+ ret = -ENOMEM;
+ if (unlikely(!idr_pre_get(&group->inotify_data.idr, GFP_KERNEL)))
+ goto out_err;
+
+ spin_lock(&group->inotify_data.idr_lock);
+ ret = idr_get_new_above(&group->inotify_data.idr, &tmp_ientry->fsn_entry,
+ group->inotify_data.last_wd,
+ &tmp_ientry->wd);
+ spin_unlock(&group->inotify_data.idr_lock);
+ if (ret) {
+ /* idr was out of memory allocate and try again */
+ if (ret == -EAGAIN)
+ goto retry;
+ goto out_err;
+ }
+
+ /* we are on the idr, now get on the inode */
+ ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode, 0);
+ if (ret) {
+ /* we failed to get on the inode, get off the idr */
+ inotify_remove_from_idr(group, tmp_ientry);
+ goto out_err;
+ }
+
+ /* we put the mark on the idr, take a reference */
+ fsnotify_get_mark(&tmp_ientry->fsn_entry);
+
+ /* update the idr hint, who cares about races, it's just a hint */
+ group->inotify_data.last_wd = tmp_ientry->wd;
+
+ /* increment the number of watches the user has */
+ atomic_inc(&group->inotify_data.user->inotify_watches);
+
+ /* return the watch descriptor for this new entry */
+ ret = tmp_ientry->wd;
+
+ /* match the ref from fsnotify_init_markentry() */
+ fsnotify_put_mark(&tmp_ientry->fsn_entry);
+
out_err:
- /* could be an error, could be that we found an existing mark */
- if (tmp_ientry) {
- /* on the idr but didn't make it on the inode */
- if (tmp_ientry->wd != -1)
- inotify_remove_from_idr(group, tmp_ientry);
+ if (ret < 0)
kmem_cache_free(inotify_inode_mark_cachep, tmp_ientry);
- }
+
+ return ret;
+}
+
+static int inotify_update_watch(struct fsnotify_group *group, struct inode *inode, u32 arg)
+{
+ int ret = 0;
+
+retry:
+ /* try to update and existing watch with the new arg */
+ ret = inotify_update_existing_watch(group, inode, arg);
+ /* no mark present, try to add a new one */
+ if (ret == -ENOENT)
+ ret = inotify_new_watch(group, inode, arg);
+ /*
+ * inotify_new_watch could race with another thread which did an
+ * inotify_new_watch between the update_existing and the add watch
+ * here, go back and try to update an existing mark again.
+ */
+ if (ret == -EEXIST)
+ goto retry;
return ret;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kernel bug 2.6.31-rc6 (2)
2009-08-19 22:26 ` Eric Paris
@ 2009-08-20 5:48 ` Christoph Thielecke
2009-08-20 14:24 ` Eric Paris
0 siblings, 1 reply; 5+ messages in thread
From: Christoph Thielecke @ 2009-08-20 5:48 UTC (permalink / raw)
To: Eric Paris; +Cc: Linux Kernel Mailing List
[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]
Hello Eric,
> On Wed, 2009-08-19 at 14:48 +0200, Christoph Thielecke wrote:
> > Aug 19 14:05:03 develop kernel: kernel BUG at
> > fs/notify/inotify/inotify_fsnotify.c:109!
>
> Can you apply the following patch? It cleans up some logic, which I
> didn't see a problem with, but it makes it very easy for me to know it's
> right now. It also should prevent the BUG() you hit from bringing down
> the box.
> commit da9d447e409fdca12001378650f020982093e91e
> Author: Eric Paris <eparis@redhat.com>
> Date: Wed Aug 19 17:01:12 2009 -0400
>
> inotify: the inotify add watch code is horrible clean it up
>
> Just reworking the inotify watch add code to be readable, clean, and
> full of a lot less gotos.
>
> Signed-off-by: Eric Paris <eparis@redhat.com>
>
> diff --git a/fs/notify/inotify/inotify_fsnotify.c
> b/fs/notify/inotify/inotify_fsnotify.c index d11ac71..1df198b 100644
The patch does not apply clean:
develop:/usr/src/linux-2.6.git.linus# patch -p1
< /home/crissi/download2/inotify_fsnotify_test.patch
patching file fs/notify/inotify/inotify_fsnotify.c
Hunk #1 succeeded at 107 (offset -72 lines).
patching file fs/notify/inotify/inotify_user.c
Hunk #1 FAILED at 431.
Is it against 2.6.31-rc6 or current git? I have 2.6.31-rc6-00195-gc124891.
I did an update to latest from linus and try to apply your patch but it fails
there too (no changes in the files after update from git).
Best regards
Christoph
--
Linux User Group Wernigerode
http://www.lug-wr.de/
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kernel bug 2.6.31-rc6 (2)
2009-08-20 5:48 ` Christoph Thielecke
@ 2009-08-20 14:24 ` Eric Paris
0 siblings, 0 replies; 5+ messages in thread
From: Eric Paris @ 2009-08-20 14:24 UTC (permalink / raw)
To: christoph.thielecke; +Cc: Linux Kernel Mailing List
On Thu, 2009-08-20 at 07:48 +0200, Christoph Thielecke wrote:
> Hello Eric,
>
>
> The patch does not apply clean:
That's because I gave you a bad patch (it was against linux-next not
against Linus, sorry :()
-Eric
---
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index dc32ed8..d8f73c2 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -431,80 +431,29 @@ static void inotify_free_mark(struct fsnotify_mark_entry *entry)
kmem_cache_free(inotify_inode_mark_cachep, ientry);
}
-static int inotify_update_watch(struct fsnotify_group *group, struct inode *inode, u32 arg)
+static int inotify_update_existing_watch(struct fsnotify_group *group,
+ struct inode *inode,
+ u32 arg)
{
- struct fsnotify_mark_entry *entry = NULL;
+ struct fsnotify_mark_entry *entry;
struct inotify_inode_mark_entry *ientry;
- struct inotify_inode_mark_entry *tmp_ientry;
- int ret = 0;
- int add = (arg & IN_MASK_ADD);
- __u32 mask;
__u32 old_mask, new_mask;
+ __u32 mask;
+ int add = (arg & IN_MASK_ADD);
+ int ret;
/* don't allow invalid bits: we don't want flags set */
mask = inotify_arg_to_mask(arg);
if (unlikely(!mask))
return -EINVAL;
- tmp_ientry = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL);
- if (unlikely(!tmp_ientry))
- return -ENOMEM;
- /* we set the mask at the end after attaching it */
- fsnotify_init_mark(&tmp_ientry->fsn_entry, inotify_free_mark);
- tmp_ientry->wd = -1;
-
-find_entry:
spin_lock(&inode->i_lock);
entry = fsnotify_find_mark_entry(group, inode);
spin_unlock(&inode->i_lock);
- if (entry) {
- ientry = container_of(entry, struct inotify_inode_mark_entry, fsn_entry);
- } else {
- ret = -ENOSPC;
- if (atomic_read(&group->inotify_data.user->inotify_watches) >= inotify_max_user_watches)
- goto out_err;
-retry:
- ret = -ENOMEM;
- if (unlikely(!idr_pre_get(&group->inotify_data.idr, GFP_KERNEL)))
- goto out_err;
-
- spin_lock(&group->inotify_data.idr_lock);
- ret = idr_get_new_above(&group->inotify_data.idr, &tmp_ientry->fsn_entry,
- group->inotify_data.last_wd,
- &tmp_ientry->wd);
- spin_unlock(&group->inotify_data.idr_lock);
- if (ret) {
- if (ret == -EAGAIN)
- goto retry;
- goto out_err;
- }
+ if (!entry)
+ return -ENOENT;
- ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode);
- if (ret) {
- inotify_remove_from_idr(group, tmp_ientry);
- if (ret == -EEXIST)
- goto find_entry;
- goto out_err;
- }
-
- /* tmp_ientry has been added to the inode, so we are all set up.
- * now we just need to make sure tmp_ientry doesn't get freed and
- * we need to set up entry and ientry so the generic code can
- * do its thing. */
- ientry = tmp_ientry;
- entry = &ientry->fsn_entry;
- tmp_ientry = NULL;
-
- atomic_inc(&group->inotify_data.user->inotify_watches);
-
- /* update the idr hint */
- group->inotify_data.last_wd = ientry->wd;
-
- /* we put the mark on the idr, take a reference */
- fsnotify_get_mark(entry);
- }
-
- ret = ientry->wd;
+ ientry = container_of(entry, struct inotify_inode_mark_entry, fsn_entry);
spin_lock(&entry->lock);
@@ -536,18 +485,103 @@ retry:
fsnotify_recalc_group_mask(group);
}
- /* this either matches fsnotify_find_mark_entry, or init_mark_entry
- * depending on which path we took... */
+ /* return the wd */
+ ret = ientry->wd;
+
+ /* match the get from fsnotify_find_mark_entry() */
fsnotify_put_mark(entry);
+ return ret;
+}
+
+static int inotify_new_watch(struct fsnotify_group *group,
+ struct inode *inode,
+ u32 arg)
+{
+ struct inotify_inode_mark_entry *tmp_ientry;
+ __u32 mask;
+ int ret;
+
+ /* don't allow invalid bits: we don't want flags set */
+ mask = inotify_arg_to_mask(arg);
+ if (unlikely(!mask))
+ return -EINVAL;
+
+ tmp_ientry = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL);
+ if (unlikely(!tmp_ientry))
+ return -ENOMEM;
+
+ fsnotify_init_mark(&tmp_ientry->fsn_entry, inotify_free_mark);
+ tmp_ientry->fsn_entry.mask = mask;
+ tmp_ientry->wd = -1;
+
+ ret = -ENOSPC;
+ if (atomic_read(&group->inotify_data.user->inotify_watches) >= inotify_max_user_watches)
+ goto out_err;
+retry:
+ ret = -ENOMEM;
+ if (unlikely(!idr_pre_get(&group->inotify_data.idr, GFP_KERNEL)))
+ goto out_err;
+
+ spin_lock(&group->inotify_data.idr_lock);
+ ret = idr_get_new_above(&group->inotify_data.idr, &tmp_ientry->fsn_entry,
+ group->inotify_data.last_wd,
+ &tmp_ientry->wd);
+ spin_unlock(&group->inotify_data.idr_lock);
+ if (ret) {
+ /* idr was out of memory allocate and try again */
+ if (ret == -EAGAIN)
+ goto retry;
+ goto out_err;
+ }
+
+ /* we are on the idr, now get on the inode */
+ ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode);
+ if (ret) {
+ /* we failed to get on the inode, get off the idr */
+ inotify_remove_from_idr(group, tmp_ientry);
+ goto out_err;
+ }
+
+ /* we put the mark on the idr, take a reference */
+ fsnotify_get_mark(&tmp_ientry->fsn_entry);
+
+ /* update the idr hint, who cares about races, it's just a hint */
+ group->inotify_data.last_wd = tmp_ientry->wd;
+
+ /* increment the number of watches the user has */
+ atomic_inc(&group->inotify_data.user->inotify_watches);
+
+ /* return the watch descriptor for this new entry */
+ ret = tmp_ientry->wd;
+
+ /* match the ref from fsnotify_init_markentry() */
+ fsnotify_put_mark(&tmp_ientry->fsn_entry);
+
out_err:
- /* could be an error, could be that we found an existing mark */
- if (tmp_ientry) {
- /* on the idr but didn't make it on the inode */
- if (tmp_ientry->wd != -1)
- inotify_remove_from_idr(group, tmp_ientry);
+ if (ret < 0)
kmem_cache_free(inotify_inode_mark_cachep, tmp_ientry);
- }
+
+ return ret;
+}
+
+static int inotify_update_watch(struct fsnotify_group *group, struct inode *inode, u32 arg)
+{
+ int ret = 0;
+
+retry:
+ /* try to update and existing watch with the new arg */
+ ret = inotify_update_existing_watch(group, inode, arg);
+ /* no mark present, try to add a new one */
+ if (ret == -ENOENT)
+ ret = inotify_new_watch(group, inode, arg);
+ /*
+ * inotify_new_watch could race with another thread which did an
+ * inotify_new_watch between the update_existing and the add watch
+ * here, go back and try to update an existing mark again.
+ */
+ if (ret == -EEXIST)
+ goto retry;
return ret;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-08-20 14:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-19 12:48 kernel bug 2.6.31-rc6 (2) Christoph Thielecke
2009-08-19 13:47 ` Eric Paris
2009-08-19 22:26 ` Eric Paris
2009-08-20 5:48 ` Christoph Thielecke
2009-08-20 14:24 ` Eric Paris
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®