Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1160959 > unrolled thread
| Started by | Calvin Owens <calvinowens@fb.com> |
|---|---|
| First post | 2015-06-09 06:00 +0200 |
| Last post | 2015-06-09 06:00 +0200 |
| Articles | 4 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[RESEND][PATCH 0/6] Fixes for memory corruption in mpt2sas Calvin Owens <calvinowens@fb.com> - 2015-06-09 06:00 +0200
[PATCH 6/6] Fix unsafe fw_event_list usage Calvin Owens <calvinowens@fb.com> - 2015-06-09 06:00 +0200
[PATCH 4/6] Add refcount to fw_event_work struct Calvin Owens <calvinowens@fb.com> - 2015-06-09 06:00 +0200
[PATCH 1/6] Add refcount to sas_device struct Calvin Owens <calvinowens@fb.com> - 2015-06-09 06:00 +0200
| From | Calvin Owens <calvinowens@fb.com> |
|---|---|
| Date | 2015-06-09 06:00 +0200 |
| Subject | [RESEND][PATCH 0/6] Fixes for memory corruption in mpt2sas |
| Message-ID | <pziRH-34C-3@gated-at.bofh.it> |
Hello all, This patchset attempts to address problems we've been having with panics due to memory corruption from the mpt2sas driver. I will provide a similar set of fixes for mpt3sas, since we see similar issues there as well. "Porting" this to mpt3sas will be trivial since the part of the driver I'm touching is nearly identical between the two, so I thought it would be simpler to review a patch against mpt2sas alone at first. I've tested this on a handful of large storage boxes over the past few weeks, so far it seems to have completely eliminated the memory corruption panics. Thanks, Calvin Total diffstat: drivers/scsi/mpt2sas/mpt2sas_base.h | 20 +- drivers/scsi/mpt2sas/mpt2sas_scsih.c | 482 +++++++++++++++++++++---------- drivers/scsi/mpt2sas/mpt2sas_transport.c | 12 +- 3 files changed, 359 insertions(+), 155 deletions(-) Patches: * [PATCH 1/6] Add refcount to sas_device struct * [PATCH 2/6] Refactor code to use new sas_device refcount * [PATCH 3/6] Fix unsafe sas_device_list usage * [PATCH 4/6] Add refcount to fw_event_work struct * [PATCH 5/6] Refactor code to use new fw_event refcount * [PATCH 6/6] Fix unsafe fw_event_list usage -- 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/
[toc] | [next] | [standalone]
| From | Calvin Owens <calvinowens@fb.com> |
|---|---|
| Date | 2015-06-09 06:00 +0200 |
| Subject | [PATCH 6/6] Fix unsafe fw_event_list usage |
| Message-ID | <pziRI-34C-13@gated-at.bofh.it> |
| In reply to | #1160959 |
Since the fw_event deletes itself from the list, cleanup_queue() can
walk onto garbage pointers or walk off into freed memory.
This refactors the code in _scsih_fw_event_cleanup_queue() to not
iterate over the fw_event_list without a lock.
Signed-off-by: Calvin Owens <calvinowens@fb.com>
---
drivers/scsi/mpt2sas/mpt2sas_scsih.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
index 8d8c814..f504e28 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
@@ -2939,6 +2939,23 @@ mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
fw_event_work_put(fw_event);
}
+static struct fw_event_work *dequeue_next_fw_event(struct MPT2SAS_ADAPTER *ioc)
+{
+ unsigned long flags;
+ struct fw_event_work *fw_event = NULL;
+
+ spin_lock_irqsave(&ioc->fw_event_lock, flags);
+ if (!list_empty(&ioc->fw_event_list)) {
+ fw_event = list_first_entry(&ioc->fw_event_list,
+ struct fw_event_work, list);
+ list_del_init(&fw_event->list);
+ fw_event_work_get(fw_event);
+ }
+ spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
+
+ return fw_event;
+}
+
/**
* _scsih_fw_event_cleanup_queue - cleanup event queue
* @ioc: per adapter object
@@ -2951,17 +2968,18 @@ mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
static void
_scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
{
- struct fw_event_work *fw_event, *next;
+ struct fw_event_work *fw_event;
if (list_empty(&ioc->fw_event_list) ||
!ioc->firmware_event_thread || in_interrupt())
return;
- list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
+ while ((fw_event = dequeue_next_fw_event(ioc))) {
if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
_scsih_fw_event_free(ioc, fw_event);
continue;
}
+ fw_event_work_put(fw_event);
}
}
--
1.8.1
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Calvin Owens <calvinowens@fb.com> |
|---|---|
| Date | 2015-06-09 06:00 +0200 |
| Subject | [PATCH 4/6] Add refcount to fw_event_work struct |
| Message-ID | <pziRI-34C-21@gated-at.bofh.it> |
| In reply to | #1160959 |
The fw_event_work struct is concurrently referenced at shutdown, so
add a refcount to protect it.
Signed-off-by: Calvin Owens <calvinowens@fb.com>
---
drivers/scsi/mpt2sas/mpt2sas_scsih.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
index 9645055..611b34d 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
@@ -176,9 +176,37 @@ struct fw_event_work {
u8 VP_ID;
u8 ignore;
u16 event;
+ struct kref refcount;
char event_data[0] __aligned(4);
};
+static void fw_event_work_free(struct kref *r)
+{
+ kfree(container_of(r, struct fw_event_work, refcount));
+}
+
+static void fw_event_work_get(struct fw_event_work *fw_work)
+{
+ kref_get(&fw_work->refcount);
+}
+
+static void fw_event_work_put(struct fw_event_work *fw_work)
+{
+ kref_put(&fw_work->refcount, fw_event_work_free);
+}
+
+static struct fw_event_work *alloc_fw_event_work(int len)
+{
+ struct fw_event_work *fw_event;
+
+ fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
+ if (!fw_event)
+ return NULL;
+
+ kref_init(&fw_event->refcount);
+ return fw_event;
+}
+
/* raid transport support */
static struct raid_template *mpt2sas_raid_template;
--
1.8.1
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Calvin Owens <calvinowens@fb.com> |
|---|---|
| Date | 2015-06-09 06:00 +0200 |
| Subject | [PATCH 1/6] Add refcount to sas_device struct |
| Message-ID | <pziRJ-34C-29@gated-at.bofh.it> |
| In reply to | #1160959 |
These objects can be referenced concurrently throughout the driver, we
need a way to make sure threads can't delete them out from under each
other.
Signed-off-by: Calvin Owens <calvinowens@fb.com>
---
drivers/scsi/mpt2sas/mpt2sas_base.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.h b/drivers/scsi/mpt2sas/mpt2sas_base.h
index caff8d1..2e7dc33 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.h
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.h
@@ -376,8 +376,24 @@ struct _sas_device {
u8 phy;
u8 responding;
u8 pfa_led_on;
+ struct kref refcount;
};
+static inline void sas_device_get(struct _sas_device *s)
+{
+ kref_get(&s->refcount);
+}
+
+static inline void sas_device_free(struct kref *r)
+{
+ kfree(container_of(r, struct _sas_device, refcount));
+}
+
+static inline void sas_device_put(struct _sas_device *s)
+{
+ kref_put(&s->refcount, sas_device_free);
+}
+
/**
* struct _raid_device - raid volume link list
* @list: sas device list
--
1.8.1
--
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/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web