From: Adrian Hunter <adrian.hunter@intel.com>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: "James E . J . Bottomley" <jejb@linux.ibm.com>,
Bean Huo <huobean@gmail.com>, Avri Altman <avri.altman@wdc.com>,
Alim Akhtar <alim.akhtar@samsung.com>,
Can Guo <cang@codeaurora.org>,
Asutosh Das <asutoshd@codeaurora.org>,
Bart Van Assche <bvanassche@acm.org>,
linux-scsi@vger.kernel.org
Subject: [PATCH RFC 3/6] scsi: ufs: Let ufshcd_[down/up]_read be nested within ufshcd_[down/up]_write
Date: Mon, 4 Oct 2021 15:06:47 +0300 [thread overview]
Message-ID: <20211004120650.153218-4-adrian.hunter@intel.com> (raw)
In-Reply-To: <20211004120650.153218-1-adrian.hunter@intel.com>
In preparation to hold ufshcd_down_write() lock for the entire error
handler duration.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
drivers/scsi/ufs/ufshcd.h | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 495e1c0afae3..74891947bb34 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -898,6 +898,7 @@ struct ufs_hba {
bool is_urgent_bkops_lvl_checked;
struct rw_semaphore host_rw_sem;
+ struct task_struct *excl_task;
unsigned char desc_size[QUERY_DESC_IDN_MAX];
atomic_t scsi_block_reqs_cnt;
@@ -1420,31 +1421,45 @@ static inline int ufshcd_rpmb_rpm_put(struct ufs_hba *hba)
static inline void ufshcd_down_read(struct ufs_hba *hba)
{
- down_read(&hba->host_rw_sem);
+ if (hba->excl_task != current)
+ down_read(&hba->host_rw_sem);
}
static inline void ufshcd_up_read(struct ufs_hba *hba)
{
- up_read(&hba->host_rw_sem);
+ if (hba->excl_task != current)
+ up_read(&hba->host_rw_sem);
}
static inline int ufshcd_down_read_trylock(struct ufs_hba *hba)
{
+ if (hba->excl_task == current)
+ return 1;
+
return down_read_trylock(&hba->host_rw_sem);
}
static inline void ufshcd_down_write(struct ufs_hba *hba)
{
down_write(&hba->host_rw_sem);
+ /*
+ * Assign exclusive access to this task, which enables bypassing
+ * down_read/up_read, refer ufshcd_down_read() and ufshcd_up_read().
+ * Note, if the same task will not be doing up_write(), it must set
+ * hba->excl_task to NULL itself.
+ */
+ hba->excl_task = current;
}
static inline void ufshcd_up_write(struct ufs_hba *hba)
{
+ hba->excl_task = NULL;
up_write(&hba->host_rw_sem);
}
static inline void ufshcd_downgrade_write(struct ufs_hba *hba)
{
+ hba->excl_task = NULL;
downgrade_write(&hba->host_rw_sem);
}
--
2.25.1
next prev parent reply other threads:[~2021-10-04 12:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-04 12:06 [PATCH RFC 0/6] scsi: ufs: Start to make driver synchronization easier to understand Adrian Hunter
2021-10-04 12:06 ` [PATCH RFC 1/6] scsi: ufs: Encapsulate clk_scaling_lock by inline functions Adrian Hunter
2021-10-04 12:06 ` [PATCH RFC 2/6] scsi: ufs: Rename clk_scaling_lock to host_rw_sem Adrian Hunter
2021-10-04 16:52 ` Bart Van Assche
2021-10-05 5:06 ` Adrian Hunter
2021-10-05 19:06 ` Bart Van Assche
2021-10-04 12:06 ` Adrian Hunter [this message]
2021-10-04 12:06 ` [PATCH RFC 4/6] scsi: ufs: Fix a possible dead lock in clock scaling Adrian Hunter
2021-10-04 12:06 ` [PATCH RFC 5/6] scsi: ufs: Reorder dev_cmd locking Adrian Hunter
2021-10-04 12:06 ` [PATCH RFC 6/6] scsi: ufs: Hold ufshcd_down_write() lock for entire error handler duration Adrian Hunter
2021-10-04 12:42 ` [PATCH RFC 0/6] scsi: ufs: Start to make driver synchronization easier to understand Avri Altman
2021-10-04 13:27 ` Adrian Hunter
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=20211004120650.153218-4-adrian.hunter@intel.com \
--to=adrian.hunter@intel.com \
--cc=alim.akhtar@samsung.com \
--cc=asutoshd@codeaurora.org \
--cc=avri.altman@wdc.com \
--cc=bvanassche@acm.org \
--cc=cang@codeaurora.org \
--cc=huobean@gmail.com \
--cc=jejb@linux.ibm.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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