From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: Jarod Wilson <jwilson@redhat.com>
Cc: "Kristian Høgsberg" <krh@redhat.com>,
"Nick Piggin" <nickpiggin@yahoo.com.au>,
linux1394-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] firewire: enforce access order between generation and node ID
Date: Fri, 25 Jan 2008 18:57:41 +0100 (CET) [thread overview]
Message-ID: <tkrat.7cfb2c72baf87206@s5r6.in-berlin.de> (raw)
In-Reply-To: <479A0FD7.5050003@s5r6.in-berlin.de>
Stefan Richter wrote:
> I'm going to commit it with a whitespace adjustment and a comment typo
> fixed.
Also forgot to #include <asm/system.h> in some of the files. Here is
the final product, for the record.
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
Subject: firewire: enforce access order between generation and node ID, fix "giving up on config rom"
fw_device.node_id and fw_device.generation are accessed without mutexes.
We have to ensure that all readers will get to see node_id updates
before generation updates.
Fixes an inability to recognize devices after "giving up on config rom",
https://bugzilla.redhat.com/show_bug.cgi?id=429950
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Reviewed by Nick Piggin <nickpiggin@yahoo.com.au>.
Verified to fix 'giving up on config rom' issues on multiple system and
drive combinations that were previously affected.
Signed-off-by: Jarod Wilson <jwilson@redhat.com>
---
drivers/firewire/fw-cdev.c | 1 +
drivers/firewire/fw-device.c | 15 +++++++++++++--
drivers/firewire/fw-device.h | 12 ++++++++++++
drivers/firewire/fw-sbp2.c | 3 +++
drivers/firewire/fw-topology.c | 6 ++++++
5 files changed, 35 insertions(+), 2 deletions(-)
Index: linux/drivers/firewire/fw-device.c
===================================================================
--- linux.orig/drivers/firewire/fw-device.c
+++ linux/drivers/firewire/fw-device.c
@@ -27,6 +27,7 @@
#include <linux/idr.h>
#include <linux/rwsem.h>
#include <asm/semaphore.h>
+#include <asm/system.h>
#include <linux/ctype.h>
#include "fw-transaction.h"
#include "fw-topology.h"
@@ -182,9 +183,14 @@ static void fw_device_release(struct dev
int fw_device_enable_phys_dma(struct fw_device *device)
{
+ int generation = device->generation;
+
+ /* device->node_id, accessed below, must not be older than generation */
+ smp_rmb();
+
return device->card->driver->enable_phys_dma(device->card,
device->node_id,
- device->generation);
+ generation);
}
EXPORT_SYMBOL(fw_device_enable_phys_dma);
@@ -389,12 +395,16 @@ static int read_rom(struct fw_device *de
struct read_quadlet_callback_data callback_data;
struct fw_transaction t;
u64 offset;
+ int generation = device->generation;
+
+ /* device->node_id, accessed below, must not be older than generation */
+ smp_rmb();
init_completion(&callback_data.done);
offset = 0xfffff0000400ULL + index * 4;
fw_send_request(device->card, &t, TCODE_READ_QUADLET_REQUEST,
- device->node_id, device->generation, device->max_speed,
+ device->node_id, generation, device->max_speed,
offset, NULL, 4, complete_transaction, &callback_data);
wait_for_completion(&callback_data.done);
@@ -801,6 +811,7 @@ void fw_node_event(struct fw_card *card,
device = node->data;
device->node_id = node->node_id;
+ smp_wmb(); /* update node_id before generation */
device->generation = card->generation;
if (atomic_read(&device->state) == FW_DEVICE_RUNNING) {
PREPARE_DELAYED_WORK(&device->work, fw_device_update);
Index: linux/drivers/firewire/fw-topology.c
===================================================================
--- linux.orig/drivers/firewire/fw-topology.c
+++ linux/drivers/firewire/fw-topology.c
@@ -21,6 +21,7 @@
#include <linux/module.h>
#include <linux/wait.h>
#include <linux/errno.h>
+#include <asm/system.h>
#include "fw-transaction.h"
#include "fw-topology.h"
@@ -518,6 +519,11 @@ fw_core_handle_bus_reset(struct fw_card
card->bm_retries = 0;
card->node_id = node_id;
+ /*
+ * Update node_id before generation to prevent anybody from using
+ * a stale node_id together with a current generation.
+ */
+ smp_wmb();
card->generation = generation;
card->reset_jiffies = jiffies;
schedule_delayed_work(&card->work, 0);
Index: linux/drivers/firewire/fw-sbp2.c
===================================================================
--- linux.orig/drivers/firewire/fw-sbp2.c
+++ linux/drivers/firewire/fw-sbp2.c
@@ -40,6 +40,7 @@
#include <linux/stringify.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
+#include <asm/system.h>
#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
@@ -662,6 +663,7 @@ static void sbp2_login(struct work_struc
int generation, node_id, local_node_id;
generation = device->generation;
+ smp_rmb(); /* node_id must not be older than generation */
node_id = device->node_id;
local_node_id = device->card->node_id;
@@ -912,6 +914,7 @@ static void sbp2_reconnect(struct work_s
int generation, node_id, local_node_id;
generation = device->generation;
+ smp_rmb(); /* node_id must not be older than generation */
node_id = device->node_id;
local_node_id = device->card->node_id;
Index: linux/drivers/firewire/fw-device.h
===================================================================
--- linux.orig/drivers/firewire/fw-device.h
+++ linux/drivers/firewire/fw-device.h
@@ -35,6 +35,18 @@ struct fw_attribute_group {
struct attribute *attrs[11];
};
+/*
+ * Note, fw_device.generation always has to be read before fw_device.node_id.
+ * Use SMP memory barriers to ensure this. Otherwise requests will be sent
+ * to an outdated node_id if the generation was updated in the meantime due
+ * to a bus reset.
+ *
+ * Likewise, fw-core will take care to update .node_id before .generation so
+ * that whenever fw_device.generation is current WRT the actual bus generation,
+ * fw_device.node_id is guaranteed to be current too.
+ *
+ * The same applies to fw_device.card->node_id vs. fw_device.generation.
+ */
struct fw_device {
atomic_t state;
struct fw_node *node;
Index: linux/drivers/firewire/fw-cdev.c
===================================================================
--- linux.orig/drivers/firewire/fw-cdev.c
+++ linux/drivers/firewire/fw-cdev.c
@@ -207,6 +207,7 @@ fill_bus_reset_event(struct fw_cdev_even
event->closure = client->bus_reset_closure;
event->type = FW_CDEV_EVENT_BUS_RESET;
event->generation = client->device->generation;
+ smp_rmb(); /* node_id must not be older than generation */
event->node_id = client->device->node_id;
event->local_node_id = card->local_node->node_id;
event->bm_node_id = 0; /* FIXME: We don't track the BM. */
--
Stefan Richter
-=====-==--- ---= ==--=
http://arcgraph.de/sr/
next prev parent reply other threads:[~2008-01-25 17:58 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-01 1:49 [PATCH] firewire: fw-core: enforce write order when updating fw_device.generation Stefan Richter
2007-11-01 1:50 ` [PATCH] firewire: fw-core: react on bus resets while the config ROM is being fetched Stefan Richter
2007-11-01 1:51 ` [PATCH] firewire: fw-sbp2: enforce read order of device generation and node ID Stefan Richter
2007-11-01 3:53 ` [PATCH] firewire: fw-core: enforce write order when updating fw_device.generation Nick Piggin
2007-11-01 9:51 ` dealing with barriers (was Re: [PATCH] firewire: fw-core: enforce write order when updating fw_device.generation) Stefan Richter
2007-11-01 11:32 ` Nick Piggin
2008-01-24 0:52 ` [PATCH 0/4] firewire: order of memory accesses (bus generation vs. node ID) Stefan Richter
2008-01-24 0:53 ` [PATCH 1/4] firewire: fw-sbp2: use device generation, not card generation Stefan Richter
2008-01-24 16:04 ` Jarod Wilson
2008-01-24 0:53 ` [PATCH 2/4] firewire: fw-cdev: " Stefan Richter
2008-01-24 16:05 ` Jarod Wilson
2008-01-24 0:54 ` [PATCH 3/4] firewire: enforce access order between generation and node ID Stefan Richter
2008-01-24 4:55 ` Nick Piggin
2008-01-24 16:06 ` Jarod Wilson
2008-01-25 16:35 ` Stefan Richter
2008-01-25 17:57 ` Stefan Richter [this message]
[not found] ` <59ad55d30801251024j6ff43953tb86aaa52fdea5ec9@mail.gmail.com>
2008-01-25 22:25 ` Stefan Richter
2008-01-24 0:55 ` [PATCH 4/4] firewire: fw-core: react on bus resets while the config ROM is being fetched Stefan Richter
2008-01-24 16:11 ` Jarod Wilson
2008-01-24 19:26 ` Jarod Wilson
2008-01-25 16:53 ` [PATCH 4/4 update] " Stefan Richter
2008-01-25 17:16 ` Jarod Wilson
2008-01-25 17:21 ` Stefan Richter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tkrat.7cfb2c72baf87206@s5r6.in-berlin.de \
--to=stefanr@s5r6.in-berlin.de \
--cc=jwilson@redhat.com \
--cc=krh@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux1394-devel@lists.sourceforge.net \
--cc=nickpiggin@yahoo.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome