diff options
author | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2012-02-18 13:54:45 -0500 |
---|---|---|
committer | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2012-02-22 16:36:01 -0500 |
commit | 90963f1cdb3baffc68321e7c98073bf9e99d2ec7 (patch) | |
tree | f05b75602a799b48d38f751de20b879d87bd6c4a /drivers/firewire/core-transaction.c | |
parent | 280f64d4f108b7ac707d6208d50a59627b984dc5 (diff) |
firewire: core: fix race at address_handler unregistration
Fix the following unlikely but possible race:
CPU 1 CPU 2
------------------------------------------------------------------------
AR-request tasklet
lookup handler
unregister handler
free handler->callback_data or handler
call handler->callback
The application which registered the handler has no way to stop nodes
sending new requests to their address range, hence cannot prevent this
race.
Fix it simply by extending the address_handler_lock-protected region
from only around the lookup to around both lookup and call. We only
need to do so in the exclusive region handler; the FCP region handler
already holds the lock around the handler->callback call.
Alas this removes the current ability to execute the callback in
parallel on different CPUs if it was called for different FireWire cards
at the same time. (For a single card, the handler is already
serialized.) If this loss of a rather obscure feature is not tolerable,
a more complex fix would be required: Add a handler reference counter;
wait in fw_core_remove_address_handler() for this conter to become zero.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers/firewire/core-transaction.c')
-rw-r--r-- | drivers/firewire/core-transaction.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c index 89e310ba03ba..190bf61533a2 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c | |||
@@ -602,6 +602,9 @@ EXPORT_SYMBOL(fw_core_add_address_handler); | |||
602 | 602 | ||
603 | /** | 603 | /** |
604 | * fw_core_remove_address_handler() - unregister an address handler | 604 | * fw_core_remove_address_handler() - unregister an address handler |
605 | * | ||
606 | * When fw_core_remove_address_handler() returns, @handler->callback() is | ||
607 | * guaranteed to not run on any CPU anymore. | ||
605 | */ | 608 | */ |
606 | void fw_core_remove_address_handler(struct fw_address_handler *handler) | 609 | void fw_core_remove_address_handler(struct fw_address_handler *handler) |
607 | { | 610 | { |
@@ -838,16 +841,16 @@ static void handle_exclusive_region_request(struct fw_card *card, | |||
838 | spin_lock_irqsave(&address_handler_lock, flags); | 841 | spin_lock_irqsave(&address_handler_lock, flags); |
839 | handler = lookup_enclosing_address_handler(&address_handler_list, | 842 | handler = lookup_enclosing_address_handler(&address_handler_list, |
840 | offset, request->length); | 843 | offset, request->length); |
841 | spin_unlock_irqrestore(&address_handler_lock, flags); | 844 | if (handler) |
842 | |||
843 | if (handler == NULL) | ||
844 | fw_send_response(card, request, RCODE_ADDRESS_ERROR); | ||
845 | else | ||
846 | handler->address_callback(card, request, | 845 | handler->address_callback(card, request, |
847 | tcode, destination, source, | 846 | tcode, destination, source, |
848 | p->generation, offset, | 847 | p->generation, offset, |
849 | request->data, request->length, | 848 | request->data, request->length, |
850 | handler->callback_data); | 849 | handler->callback_data); |
850 | spin_unlock_irqrestore(&address_handler_lock, flags); | ||
851 | |||
852 | if (!handler) | ||
853 | fw_send_response(card, request, RCODE_ADDRESS_ERROR); | ||
851 | } | 854 | } |
852 | 855 | ||
853 | static void handle_fcp_region_request(struct fw_card *card, | 856 | static void handle_fcp_region_request(struct fw_card *card, |