Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1264768
| From | Chris Bainbridge <chris.bainbridge@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] Preserve task state in reentrant calls to ___wait_event |
| Date | 2015-11-07 09:40 +0100 |
| Message-ID | <qs7ct-8kw-11@gated-at.bofh.it> (permalink) |
| References | <qrW7p-YG-27@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Fri, Nov 06, 2015 at 08:44:08PM +0000, Chris Bainbridge wrote:
> -#define ___wait_event(wq, condition, state, exclusive, ret, cmd) \
> +#define ___wait_event(wq, condition, nstate, exclusive, ret, cmd) \
> ({ \
> __label__ __out; \
> wait_queue_t __wait; \
> long __ret = ret; /* explicit shadow */ \
> + long ostate = current->state; \
XXX
> \
> INIT_LIST_HEAD(&__wait.task_list); \
> if (exclusive) \
> @@ -222,16 +223,16 @@ wait_queue_head_t *bit_waitqueue(void *, int);
> __wait.flags = 0; \
> \
> for (;;) { \
> - long __int = prepare_to_wait_event(&wq, &__wait, state);\
> + long __int = prepare_to_wait_event(&wq, &__wait, nstate);\
> \
> if (condition) \
> break; \
> \
> - if (___wait_is_interruptible(state) && __int) { \
> + if (___wait_is_interruptible(nstate) && __int) { \
> __ret = __int; \
> if (exclusive) { \
> abort_exclusive_wait(&wq, &__wait, \
> - state, NULL); \
> + nstate, NULL); \
> goto __out; \
> } \
> break; \
> @@ -240,6 +241,7 @@ wait_queue_head_t *bit_waitqueue(void *, int);
> cmd; \
> } \
> finish_wait(&wq, &__wait); \
> + set_current_state(ostate); \
I'm not convinced that this particular code is (or can be) race free in
the general reentrant case. The outer call to ___wait_event will miss
any wake_up received in the inner call between XXX above (store of
current->state) and this point of restoring the previous state. So if
the inner condition evaluation or some interrupt handler happens to
trigger a wake_up meant for the outer call then it will be lost.
> __out: __ret; \
> })
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] Preserve task state in reentrant calls to ___wait_event Chris Bainbridge <chris.bainbridge@gmail.com> - 2015-11-06 21:50 +0100
Re: [PATCH] Preserve task state in reentrant calls to ___wait_event "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2015-11-06 23:40 +0100
[PATCH] ACPI / SMBus: Fix boot stalls / high CPU caused by reentrant code Chris Bainbridge <chris.bainbridge@gmail.com> - 2015-11-12 19:10 +0100
[PATCH] Revert "ACPI / SBS: Add 5 us delay to fix SBS hangs on MacBook" Chris Bainbridge <chris.bainbridge@gmail.com> - 2015-11-12 20:30 +0100
Re: [PATCH] Preserve task state in reentrant calls to ___wait_event Chris Bainbridge <chris.bainbridge@gmail.com> - 2015-11-07 09:40 +0100
Re: [PATCH] Preserve task state in reentrant calls to ___wait_event Peter Zijlstra <peterz@infradead.org> - 2015-11-07 10:30 +0100
csiph-web