* [PATCH] uevent: send events in correct order according to seqnum
[not found] <CAPXgP10GRZ6Y3+dtNSw5zQMaM9FnSBBfLrCJmQ948gA3tALtfw@mail.gmail.com>
@ 2012-03-06 20:06 ` Andrew Vagin
2012-03-06 21:03 ` Kay Sievers
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Vagin @ 2012-03-06 20:06 UTC (permalink / raw)
To: Greg Kroah-Hartman, Kay Sievers; +Cc: avagin, linux-hotplug, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 493 bytes --]
The queue handling in the udev daemon assumes that the events are
ordered.
Before this patch uevent_seqnum is incremented under sequence_lock,
than an event is send uner uevent_sock_mutex. I want to say that code
contained a window between incrementing seqnum and sending an event.
This patch locks uevent_sock_mutex before incrementing uevent_seqnum.
Signed-off-by: Andrew Vagin <avagin@openvz.org>
---
lib/kobject_uevent.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-uevent-send-events-in-correct-order-according-to-seq.patch --]
[-- Type: text/x-patch; name="0001-uevent-send-events-in-correct-order-according-to-seq.patch", Size: 798 bytes --]
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index e66e9b6..596c40d 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -243,6 +243,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
else if (action == KOBJ_REMOVE)
kobj->state_remove_uevent_sent = 1;
+#if defined(CONFIG_NET)
+ mutex_lock(&uevent_sock_mutex);
+#endif
/* we will send an event, so request a new sequence number */
spin_lock(&sequence_lock);
seq = ++uevent_seqnum;
@@ -253,7 +256,6 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
#if defined(CONFIG_NET)
/* send netlink message */
- mutex_lock(&uevent_sock_mutex);
list_for_each_entry(ue_sk, &uevent_sock_list, list) {
struct sock *uevent_sock = ue_sk->sk;
struct sk_buff *skb;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] uevent: send events in correct order according to seqnum
2012-03-06 20:06 ` [PATCH] uevent: send events in correct order according to seqnum Andrew Vagin
@ 2012-03-06 21:03 ` Kay Sievers
2012-03-06 21:14 ` avagin
0 siblings, 1 reply; 4+ messages in thread
From: Kay Sievers @ 2012-03-06 21:03 UTC (permalink / raw)
To: Andrew Vagin; +Cc: Greg Kroah-Hartman, linux-hotplug, linux-kernel
On Tue, Mar 6, 2012 at 21:06, Andrew Vagin <avagin@openvz.org> wrote:
>
> The queue handling in the udev daemon assumes that the events are
> ordered.
>
> Before this patch uevent_seqnum is incremented under sequence_lock,
> than an event is send uner uevent_sock_mutex. I want to say that code
> contained a window between incrementing seqnum and sending an event.
>
> This patch locks uevent_sock_mutex before incrementing uevent_seqnum.
I think we can remove the spin_lock(&sequence_lock); entirely now, right?
Also the section with:
seq = ++uevent_seqnum;
can just be:
add_uevent_var(env, "SEQNUM=%llu", (unsigned long long) ++uevent_seqnum);
right?
And the:
mutex_lock(&uevent_sock_mutex);
can just move outside of the _NET ifdef and we always use the mutex
instead of the spinlock?
That could look much simpler than the current code, I think.
Thanks,
Kay
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] uevent: send events in correct order according to seqnum
2012-03-06 21:03 ` Kay Sievers
@ 2012-03-06 21:14 ` avagin
2012-03-07 5:52 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: avagin @ 2012-03-06 21:14 UTC (permalink / raw)
To: Kay Sievers; +Cc: Andrew Vagin, Greg Kroah-Hartman, linux-hotplug, linux-kernel
On 03/07/2012 01:03 AM, Kay Sievers wrote:
> On Tue, Mar 6, 2012 at 21:06, Andrew Vagin<avagin@openvz.org> wrote:
>>
>> The queue handling in the udev daemon assumes that the events are
>> ordered.
>>
>> Before this patch uevent_seqnum is incremented under sequence_lock,
>> than an event is send uner uevent_sock_mutex. I want to say that code
>> contained a window between incrementing seqnum and sending an event.
>>
>> This patch locks uevent_sock_mutex before incrementing uevent_seqnum.
>
> I think we can remove the spin_lock(&sequence_lock); entirely now, right?
I thought about that too. sequence_lock is used when CONFIG_NET isn't
defined. I've looked on this code one more time and we may leave only
uevent_sock_mutex and use it even when CONFIG_NET isn't defined.
Thanks for the comment.
Greg, do you have other objections about this patch?
>
> Also the section with:
> seq = ++uevent_seqnum;
> can just be:
> add_uevent_var(env, "SEQNUM=%llu", (unsigned long long) ++uevent_seqnum);
> right?
>
> And the:
> mutex_lock(&uevent_sock_mutex);
> can just move outside of the _NET ifdef and we always use the mutex
> instead of the spinlock?
>
> That could look much simpler than the current code, I think.
>
> Thanks,
> Kay
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] uevent: send events in correct order according to seqnum
2012-03-06 21:14 ` avagin
@ 2012-03-07 5:52 ` Greg Kroah-Hartman
0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2012-03-07 5:52 UTC (permalink / raw)
To: avagin@gmail.com; +Cc: Kay Sievers, Andrew Vagin, linux-hotplug, linux-kernel
On Wed, Mar 07, 2012 at 01:14:04AM +0400, avagin@gmail.com wrote:
> On 03/07/2012 01:03 AM, Kay Sievers wrote:
> >On Tue, Mar 6, 2012 at 21:06, Andrew Vagin<avagin@openvz.org> wrote:
> >>
> >>The queue handling in the udev daemon assumes that the events are
> >>ordered.
> >>
> >>Before this patch uevent_seqnum is incremented under sequence_lock,
> >>than an event is send uner uevent_sock_mutex. I want to say that code
> >>contained a window between incrementing seqnum and sending an event.
> >>
> >>This patch locks uevent_sock_mutex before incrementing uevent_seqnum.
> >
> >I think we can remove the spin_lock(&sequence_lock); entirely now, right?
>
> I thought about that too. sequence_lock is used when CONFIG_NET
> isn't defined. I've looked on this code one more time and we may
> leave only uevent_sock_mutex and use it even when CONFIG_NET isn't
> defined.
> Thanks for the comment.
>
> Greg, do you have other objections about this patch?
Let's see the one based on Kay's comments first please.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-07 5:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CAPXgP10GRZ6Y3+dtNSw5zQMaM9FnSBBfLrCJmQ948gA3tALtfw@mail.gmail.com>
2012-03-06 20:06 ` [PATCH] uevent: send events in correct order according to seqnum Andrew Vagin
2012-03-06 21:03 ` Kay Sievers
2012-03-06 21:14 ` avagin
2012-03-07 5:52 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox