Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1673308 > unrolled thread

[PATCH v2] qla2xxx: Protect access to qpair members with qpair->qp_lock

Started byJohannes Thumshirn <jthumshirn@suse.de>
First post2017-06-23 09:20 +0200
Last post2017-07-01 23:00 +0200
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] qla2xxx: Protect access to qpair members with qpair->qp_lock Johannes Thumshirn <jthumshirn@suse.de> - 2017-06-23 09:20 +0200
    Re: [PATCH v2] qla2xxx: Protect access to qpair members with qpair->qp_lock "Martin K. Petersen" <martin.petersen@oracle.com> - 2017-06-28 03:40 +0200
      Re: [PATCH v2] qla2xxx: Protect access to qpair members with  qpair->qp_lock "Madhani, Himanshu" <Himanshu.Madhani@cavium.com> - 2017-06-28 03:50 +0200
    Re: [PATCH v2] qla2xxx: Protect access to qpair members with  qpair->qp_lock "Madhani, Himanshu" <Himanshu.Madhani@cavium.com> - 2017-06-28 20:00 +0200
    Re: [PATCH v2] qla2xxx: Protect access to qpair members with qpair->qp_lock "Martin K. Petersen" <martin.petersen@oracle.com> - 2017-07-01 23:00 +0200

#1673308 — [PATCH v2] qla2xxx: Protect access to qpair members with qpair->qp_lock

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2017-06-23 09:20 +0200
Subject[PATCH v2] qla2xxx: Protect access to qpair members with qpair->qp_lock
Message-ID<tVr2O-7yl-15@gated-at.bofh.it>
In qla2xx_start_scsi_mq() and qla2xx_dif_start_scsi_mq() we grab the
qpair->qp_lock but do access members of the qpair before having the lock.
Re-order the locking sequence to have all read and write access to qpair
members under the qpair->qp_lock.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/scsi/qla2xxx/qla_iocb.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Changes to v1:
* Use __qla2x00_marker() instead of qla2x00_marker which is fit to be called
  with the qp_lock held (John)
* Don't protect qpair->online and qpair->difdix_supported as it's not
  needed (Hannes)

diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index 8404f17f3c6c..c64036ddd365 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -1770,6 +1770,9 @@ qla2xxx_start_scsi_mq(srb_t *sp)
 	struct qla_hw_data *ha = vha->hw;
 	struct qla_qpair *qpair = sp->qpair;
 
+	/* Acquire qpair specific lock */
+	spin_lock_irqsave(&qpair->qp_lock, flags);
+
 	/* Setup qpair pointers */
 	rsp = qpair->rsp;
 	req = qpair->req;
@@ -1779,15 +1782,14 @@ qla2xxx_start_scsi_mq(srb_t *sp)
 
 	/* Send marker if required */
 	if (vha->marker_needed != 0) {
-		if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
-		    QLA_SUCCESS)
+		if (__qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
+		    QLA_SUCCESS) {
+			spin_unlock_irqrestore(&qpair->qp_lock, flags);
 			return QLA_FUNCTION_FAILED;
+		}
 		vha->marker_needed = 0;
 	}
 
-	/* Acquire qpair specific lock */
-	spin_lock_irqsave(&qpair->qp_lock, flags);
-
 	/* Check for room in outstanding command list. */
 	handle = req->current_outstanding_cmd;
 	for (index = 1; index < req->num_outstanding_cmds; index++) {
@@ -1942,6 +1944,8 @@ qla2xxx_dif_start_scsi_mq(srb_t *sp)
 			return qla2xxx_start_scsi_mq(sp);
 	}
 
+	spin_lock_irqsave(&qpair->qp_lock, flags);
+
 	/* Setup qpair pointers */
 	rsp = qpair->rsp;
 	req = qpair->req;
@@ -1951,15 +1955,14 @@ qla2xxx_dif_start_scsi_mq(srb_t *sp)
 
 	/* Send marker if required */
 	if (vha->marker_needed != 0) {
-		if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
-		    QLA_SUCCESS)
+		if (__qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
+		    QLA_SUCCESS) {
+			spin_unlock_irqrestore(&qpair->qp_lock, flags);
 			return QLA_FUNCTION_FAILED;
+		}
 		vha->marker_needed = 0;
 	}
 
-	/* Acquire ring specific lock */
-	spin_lock_irqsave(&qpair->qp_lock, flags);
-
 	/* Check for room in outstanding command list. */
 	handle = req->current_outstanding_cmd;
 	for (index = 1; index < req->num_outstanding_cmds; index++) {
-- 
2.12.3

[toc] | [next] | [standalone]


#1676309

From"Martin K. Petersen" <martin.petersen@oracle.com>
Date2017-06-28 03:40 +0200
Message-ID<tXa7w-eJ-9@gated-at.bofh.it>
In reply to#1673308
> In qla2xx_start_scsi_mq() and qla2xx_dif_start_scsi_mq() we grab the
> qpair->qp_lock but do access members of the qpair before having the lock.
> Re-order the locking sequence to have all read and write access to qpair
> members under the qpair->qp_lock.

Cavium folks, please review!

-- 
Martin K. Petersen	Oracle Linux Engineering

[toc] | [prev] | [next] | [standalone]


#1676311 — Re: [PATCH v2] qla2xxx: Protect access to qpair members with qpair->qp_lock

From"Madhani, Himanshu" <Himanshu.Madhani@cavium.com>
Date2017-06-28 03:50 +0200
SubjectRe: [PATCH v2] qla2xxx: Protect access to qpair members with qpair->qp_lock
Message-ID<tXahb-i0-7@gated-at.bofh.it>
In reply to#1676309
Hi Martin,

On 6/27/17, 6:32 PM, "Martin K. Petersen" <martin.petersen@oracle.com> wrote:

    
    > In qla2xx_start_scsi_mq() and qla2xx_dif_start_scsi_mq() we grab the
    > qpair->qp_lock but do access members of the qpair before having the lock.
    > Re-order the locking sequence to have all read and write access to qpair
    > members under the qpair->qp_lock.
    
    Cavium folks, please review!

I am testing it internally, will update by tomorrow. 
    
    -- 
    Martin K. Petersen	Oracle Linux Engineering
    
Thanks,
Himanshu


[toc] | [prev] | [next] | [standalone]


#1676993 — Re: [PATCH v2] qla2xxx: Protect access to qpair members with qpair->qp_lock

From"Madhani, Himanshu" <Himanshu.Madhani@cavium.com>
Date2017-06-28 20:00 +0200
SubjectRe: [PATCH v2] qla2xxx: Protect access to qpair members with qpair->qp_lock
Message-ID<tXpq5-t5-221@gated-at.bofh.it>
In reply to#1673308
> On Jun 23, 2017, at 12:10 AM, Johannes Thumshirn <jthumshirn@suse.de> wrote:
> 
> In qla2xx_start_scsi_mq() and qla2xx_dif_start_scsi_mq() we grab the
> qpair->qp_lock but do access members of the qpair before having the lock.
> Re-order the locking sequence to have all read and write access to qpair
> members under the qpair->qp_lock.
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> ---
> drivers/scsi/qla2xxx/qla_iocb.c | 23 +++++++++++++----------
> 1 file changed, 13 insertions(+), 10 deletions(-)
> 
> Changes to v1:
> * Use __qla2x00_marker() instead of qla2x00_marker which is fit to be called
>  with the qp_lock held (John)
> * Don't protect qpair->online and qpair->difdix_supported as it's not
>  needed (Hannes)
> 
> diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
> index 8404f17f3c6c..c64036ddd365 100644
> --- a/drivers/scsi/qla2xxx/qla_iocb.c
> +++ b/drivers/scsi/qla2xxx/qla_iocb.c
> @@ -1770,6 +1770,9 @@ qla2xxx_start_scsi_mq(srb_t *sp)
> 	struct qla_hw_data *ha = vha->hw;
> 	struct qla_qpair *qpair = sp->qpair;
> 
> +	/* Acquire qpair specific lock */
> +	spin_lock_irqsave(&qpair->qp_lock, flags);
> +
> 	/* Setup qpair pointers */
> 	rsp = qpair->rsp;
> 	req = qpair->req;
> @@ -1779,15 +1782,14 @@ qla2xxx_start_scsi_mq(srb_t *sp)
> 
> 	/* Send marker if required */
> 	if (vha->marker_needed != 0) {
> -		if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
> -		    QLA_SUCCESS)
> +		if (__qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
> +		    QLA_SUCCESS) {
> +			spin_unlock_irqrestore(&qpair->qp_lock, flags);
> 			return QLA_FUNCTION_FAILED;
> +		}
> 		vha->marker_needed = 0;
> 	}
> 
> -	/* Acquire qpair specific lock */
> -	spin_lock_irqsave(&qpair->qp_lock, flags);
> -
> 	/* Check for room in outstanding command list. */
> 	handle = req->current_outstanding_cmd;
> 	for (index = 1; index < req->num_outstanding_cmds; index++) {
> @@ -1942,6 +1944,8 @@ qla2xxx_dif_start_scsi_mq(srb_t *sp)
> 			return qla2xxx_start_scsi_mq(sp);
> 	}
> 
> +	spin_lock_irqsave(&qpair->qp_lock, flags);
> +
> 	/* Setup qpair pointers */
> 	rsp = qpair->rsp;
> 	req = qpair->req;
> @@ -1951,15 +1955,14 @@ qla2xxx_dif_start_scsi_mq(srb_t *sp)
> 
> 	/* Send marker if required */
> 	if (vha->marker_needed != 0) {
> -		if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
> -		    QLA_SUCCESS)
> +		if (__qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
> +		    QLA_SUCCESS) {
> +			spin_unlock_irqrestore(&qpair->qp_lock, flags);
> 			return QLA_FUNCTION_FAILED;
> +		}
> 		vha->marker_needed = 0;
> 	}
> 
> -	/* Acquire ring specific lock */
> -	spin_lock_irqsave(&qpair->qp_lock, flags);
> -
> 	/* Check for room in outstanding command list. */
> 	handle = req->current_outstanding_cmd;
> 	for (index = 1; index < req->num_outstanding_cmds; index++) {
> -- 
> 2.12.3
> 

Looks Good. 

Acked-By: Himanshu Madhani <himanshu.madhani@cavium.com>

[toc] | [prev] | [next] | [standalone]


#1679399

From"Martin K. Petersen" <martin.petersen@oracle.com>
Date2017-07-01 23:00 +0200
Message-ID<tYxEK-8et-7@gated-at.bofh.it>
In reply to#1673308
Johannes,

> In qla2xx_start_scsi_mq() and qla2xx_dif_start_scsi_mq() we grab the
> qpair->qp_lock but do access members of the qpair before having the lock.
> Re-order the locking sequence to have all read and write access to qpair
> members under the qpair->qp_lock.

Applied to 4.13/scsi-queue.

-- 
Martin K. Petersen	Oracle Linux Engineering

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web