From: John Garry <john.garry@huawei.com>
To: <jejb@linux.vnet.ibm.com>, <martin.petersen@oracle.com>
Cc: <linuxarm@huawei.com>, <linux-scsi@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <zhangfei.gao@linaro.org>,
Xiaofei Tan <tanxiaofei@huawei.com>,
John Garry <john.garry@huawei.com>
Subject: [PATCH 08/19] scsi: hisi_sas: fix the risk of freeing slot twice
Date: Tue, 24 Oct 2017 23:51:38 +0800 [thread overview]
Message-ID: <1508860309-212397-9-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1508860309-212397-1-git-send-email-john.garry@huawei.com>
From: Xiaofei Tan <tanxiaofei@huawei.com>
The function hisi_sas_slot_task_free() is used to free
the slot and do tidy-up of LLDD resources. The LLDD
generally should know the state of a slot and decide when
to free it, and it should only be done once.
For some scenarios, we really don't know the state, like
when TMF timeout. In this case, we check task->lldd_task
before calling hisi_sas_slot_task_free().
However, we may miss some scenarios when we should also
check task->lldd_task, and it is not SMP safe to check
task->lldd_task as we don't protect it within spin lock.
This patch is to fix this risk of freeing slot twice, as
follows:
1. Check task->lldd_task in the hisi_sas_slot_task_free(),
and give up freeing of this time if task->lldd_task is NULL.
2. Set slot->buf to NULL after it is freed.
Signed-off-by: Xiaofei Tan <tanxiaofei@huawei.com>
Signed-off-by: John Garry <john.garry@huawei.com>
---
drivers/scsi/hisi_sas/hisi_sas_main.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 2a209e1..6b4dabde 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -185,13 +185,16 @@ void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task,
struct domain_device *device = task->dev;
struct hisi_sas_device *sas_dev = device->lldd_dev;
+ if (!task->lldd_task)
+ return;
+
+ task->lldd_task = NULL;
+
if (!sas_protocol_ata(task->task_proto))
if (slot->n_elem)
dma_unmap_sg(dev, task->scatter, slot->n_elem,
task->data_dir);
- task->lldd_task = NULL;
-
if (sas_dev)
atomic64_dec(&sas_dev->running_req);
}
@@ -199,8 +202,8 @@ void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task,
if (slot->buf)
dma_pool_free(hisi_hba->buffer_pool, slot->buf, slot->buf_dma);
-
list_del_init(&slot->entry);
+ slot->buf = NULL;
slot->task = NULL;
slot->port = NULL;
hisi_sas_slot_index_free(hisi_hba, slot->idx);
--
1.9.1
next prev parent reply other threads:[~2017-10-24 15:07 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-24 15:51 [PATCH 00/19] hisi_sas: misc fixes, improvements, and new features John Garry
2017-10-24 15:51 ` [PATCH 01/19] scsi: hisi_sas: delete get_ncq_tag_v3_hw() John Garry
2017-10-24 15:51 ` [PATCH 02/19] scsi: hisi_sas: fix internal abort slot timeout bug John Garry
2017-10-24 15:51 ` [PATCH 03/19] scsi: hisi_sas: use spin_lock_irqsave() for hisi_hba.lock John Garry
2017-10-24 15:51 ` [PATCH 04/19] scsi: hisi_sas: grab hisi_hba.lock when processing slots John Garry
2017-10-24 15:51 ` [PATCH 05/19] scsi: hisi_sas: fix SATA breakpoint memory size John Garry
2017-10-24 15:51 ` [PATCH 06/19] scsi: hisi_sas: us start_phy in PHY_FUNC_LINK_RESET John Garry
2017-10-24 15:51 ` [PATCH 07/19] scsi: hisi_sas: fix NULL check in SMP abort task path John Garry
2017-10-24 15:51 ` John Garry [this message]
2017-10-24 15:51 ` [PATCH 09/19] scsi: hisi_sas: use array for v2 hw AXI errors John Garry
2017-10-24 15:51 ` [PATCH 10/19] scsi: hisi_sas: report ECC errors in v2 hw to userspace John Garry
2017-10-24 15:51 ` [PATCH 11/19] scsi: hisi_sas: report v2 hw AXI errors " John Garry
2017-10-24 15:51 ` [PATCH 12/19] scsi: hisi_sas: check PHY state in get_wideport_bitmap_v3_hw() John Garry
2017-10-24 15:51 ` [PATCH 13/19] scsi: hisi_sas: init connect cfg register for v3 hw John Garry
2017-10-24 15:51 ` [PATCH 14/19] scsi: hisi_sas: add v3 hw DFX feature John Garry
2017-10-24 15:51 ` [PATCH 15/19] scsi: hisi_sas: add hisi_hba.rst_work init for v3 hw John Garry
2017-10-24 15:51 ` [PATCH 16/19] scsi: hisi_sas: fix a bug when free device " John Garry
2017-10-24 15:51 ` [PATCH 17/19] scsi: hisi_sas: complete all tasklets prior to host reset John Garry
2017-10-24 15:51 ` [PATCH 18/19] scsi: hisi_sas: add v3 hw support for AXI fatal error John Garry
2017-10-24 15:51 ` [PATCH 19/19] scsi: hisi_sas: add v3 hw port AXI error handling John Garry
2017-10-25 12:29 ` [PATCH 00/19] hisi_sas: misc fixes, improvements, and new features Martin K. Petersen
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=1508860309-212397-9-git-send-email-john.garry@huawei.com \
--to=john.garry@huawei.com \
--cc=jejb@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=martin.petersen@oracle.com \
--cc=tanxiaofei@huawei.com \
--cc=zhangfei.gao@linaro.org \
/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
all inboxes | Powered by JetHome®