All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] megaraid_sas: Driver version update to 07.719.03.00-rc1
@ 2021-09-29 12:40 Sumit Saxena
  2021-09-29 12:40 ` [PATCH 1/3] megaraid_sas: fix concurrent access to ISR between IRQ polling and real interrupt Sumit Saxena
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Sumit Saxena @ 2021-09-29 12:40 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, jejb
  Cc: chandrakanth.patil, kashyap.desai, Sumit Saxena

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

This patchset has a critical fix and added helper functions
to improve code readbility in ISR.

Sumit Saxena (3):
  megaraid_sas: fix concurrent access to ISR between IRQ polling and
    real interrupt
  megaraid_sas: Add helper functions- {access/release}_irq_context
  megaraid_sas: Driver version update to 07.719.03.00-rc1

 drivers/scsi/megaraid/megaraid_sas.h        |  4 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 50 ++++++++++++++++++---
 2 files changed, 45 insertions(+), 9 deletions(-)

-- 
2.18.1


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] megaraid_sas: fix concurrent access to ISR between IRQ polling and real interrupt
  2021-09-29 12:40 [PATCH 0/3] megaraid_sas: Driver version update to 07.719.03.00-rc1 Sumit Saxena
@ 2021-09-29 12:40 ` Sumit Saxena
  2021-09-29 12:40 ` [PATCH 2/3] megaraid_sas: Add helper functions- {access/release}_irq_context Sumit Saxena
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sumit Saxena @ 2021-09-29 12:40 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, jejb
  Cc: chandrakanth.patil, kashyap.desai, Sumit Saxena

[-- Attachment #1: Type: text/plain, Size: 2212 bytes --]

IRQ polling thread calls ISR after enable_irq() to handle any missed IO
completion. atomic flag "in_used" was added to have the synchronization
between the IRQ polling thread and the interrupt context.
There is a bug around it leading to a race condition.

Below is the sequence:
-IRQ polling thread accesses ISR, fetches the reply descriptor.
-Real interrupt arrives and pre-empts polling thread(see enable_irq()
 is already called).
-Interrupt context picks the same reply descriptor as fetched by polling
 thread, processes it, and exits.
-Polling thread resumes and processes the descriptor which is already
 processed by interrupt thread leads to kernel crash.

Setting the "in_used" flag before fetching the reply descriptor ensures
synchronized access to ISR.

Link: https://www.spinics.net/lists/linux-scsi/msg159440.html
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Fixes: 9bedd36e9146 (scsi: megaraid_sas: Handle missing interrupts while re-enabling IRQs)
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 26d0cf9353dd..eb5ceb75a15e 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3530,6 +3530,9 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex,
 	if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR)
 		return IRQ_HANDLED;
 
+	if (irq_context && !atomic_add_unless(&irq_context->in_used, 1, 1))
+		return 0;
+
 	desc = fusion->reply_frames_desc[MSIxIndex] +
 				fusion->last_reply_idx[MSIxIndex];
 
@@ -3540,11 +3543,11 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex,
 	reply_descript_type = reply_desc->ReplyFlags &
 		MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
 
-	if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
+	if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) {
+		if (irq_context)
+			atomic_dec(&irq_context->in_used);
 		return IRQ_NONE;
-
-	if (irq_context && !atomic_add_unless(&irq_context->in_used, 1, 1))
-		return 0;
+	}
 
 	num_completed = 0;
 
-- 
2.18.1


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] megaraid_sas: Add helper functions- {access/release}_irq_context
  2021-09-29 12:40 [PATCH 0/3] megaraid_sas: Driver version update to 07.719.03.00-rc1 Sumit Saxena
  2021-09-29 12:40 ` [PATCH 1/3] megaraid_sas: fix concurrent access to ISR between IRQ polling and real interrupt Sumit Saxena
@ 2021-09-29 12:40 ` Sumit Saxena
  2021-09-29 12:40 ` [PATCH 3/3] megaraid_sas: Driver version update to 07.719.03.00-rc1 Sumit Saxena
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sumit Saxena @ 2021-09-29 12:40 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, jejb
  Cc: chandrakanth.patil, kashyap.desai, Sumit Saxena

[-- Attachment #1: Type: text/plain, Size: 2671 bytes --]

Adding helper functions for ISR access and release to improve
the readability.

Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 45 ++++++++++++++++++---
 1 file changed, 39 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index eb5ceb75a15e..109782e3ec44 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -3497,6 +3497,41 @@ megasas_complete_r1_command(struct megasas_instance *instance,
 	}
 }
 
+/**
+ * access_irq_context:		Access to reply processing
+ * @irq_context:		IRQ context
+ *
+ * Synchronize access to reply processing.
+ *
+ * Return:  true on success, false on failure.
+ */
+static inline
+bool access_irq_context(struct megasas_irq_context  *irq_context)
+{
+	if (!irq_context)
+		return true;
+
+	if (atomic_add_unless(&irq_context->in_used, 1, 1))
+		return true;
+
+	return false;
+}
+
+/**
+ * release_irq_context:		Release reply processing
+ * @irq_context:		IRQ context
+ *
+ * Release access of reply processing.
+ *
+ * Return: Nothing.
+ */
+static inline
+void release_irq_context(struct megasas_irq_context  *irq_context)
+{
+	if (irq_context)
+		atomic_dec(&irq_context->in_used);
+}
+
 /**
  * complete_cmd_fusion -	Completes command
  * @instance:			Adapter soft state
@@ -3530,7 +3565,7 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex,
 	if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR)
 		return IRQ_HANDLED;
 
-	if (irq_context && !atomic_add_unless(&irq_context->in_used, 1, 1))
+	if (!access_irq_context(irq_context))
 		return 0;
 
 	desc = fusion->reply_frames_desc[MSIxIndex] +
@@ -3544,8 +3579,7 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex,
 		MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
 
 	if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) {
-		if (irq_context)
-			atomic_dec(&irq_context->in_used);
+		release_irq_context(irq_context);
 		return IRQ_NONE;
 	}
 
@@ -3663,7 +3697,7 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex,
 					irq_context->irq_line_enable = true;
 					irq_poll_sched(&irq_context->irqpoll);
 				}
-				atomic_dec(&irq_context->in_used);
+				release_irq_context(irq_context);
 				return num_completed;
 			}
 		}
@@ -3682,8 +3716,7 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex,
 		megasas_check_and_restore_queue_depth(instance);
 	}
 
-	if (irq_context)
-		atomic_dec(&irq_context->in_used);
+	release_irq_context(irq_context);
 
 	return num_completed;
 }
-- 
2.18.1


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] megaraid_sas: Driver version update to 07.719.03.00-rc1
  2021-09-29 12:40 [PATCH 0/3] megaraid_sas: Driver version update to 07.719.03.00-rc1 Sumit Saxena
  2021-09-29 12:40 ` [PATCH 1/3] megaraid_sas: fix concurrent access to ISR between IRQ polling and real interrupt Sumit Saxena
  2021-09-29 12:40 ` [PATCH 2/3] megaraid_sas: Add helper functions- {access/release}_irq_context Sumit Saxena
@ 2021-09-29 12:40 ` Sumit Saxena
  2021-10-05  3:20 ` [PATCH 0/3] " Martin K. Petersen
  2021-10-12 20:35 ` Martin K. Petersen
  4 siblings, 0 replies; 6+ messages in thread
From: Sumit Saxena @ 2021-09-29 12:40 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, jejb
  Cc: chandrakanth.patil, kashyap.desai, Sumit Saxena

[-- Attachment #1: Type: text/plain, Size: 665 bytes --]

Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
---
 drivers/scsi/megaraid/megaraid_sas.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 7af2c23652b0..2c9d1b796475 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -21,8 +21,8 @@
 /*
  * MegaRAID SAS Driver meta data
  */
-#define MEGASAS_VERSION				"07.717.02.00-rc1"
-#define MEGASAS_RELDATE				"May 19, 2021"
+#define MEGASAS_VERSION				"07.719.03.00-rc1"
+#define MEGASAS_RELDATE				"Sep 29, 2021"
 
 #define MEGASAS_MSIX_NAME_LEN			32
 
-- 
2.18.1


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] megaraid_sas: Driver version update to 07.719.03.00-rc1
  2021-09-29 12:40 [PATCH 0/3] megaraid_sas: Driver version update to 07.719.03.00-rc1 Sumit Saxena
                   ` (2 preceding siblings ...)
  2021-09-29 12:40 ` [PATCH 3/3] megaraid_sas: Driver version update to 07.719.03.00-rc1 Sumit Saxena
@ 2021-10-05  3:20 ` Martin K. Petersen
  2021-10-12 20:35 ` Martin K. Petersen
  4 siblings, 0 replies; 6+ messages in thread
From: Martin K. Petersen @ 2021-10-05  3:20 UTC (permalink / raw)
  To: Sumit Saxena
  Cc: linux-scsi, martin.petersen, jejb, chandrakanth.patil, kashyap.desai


Sumit,

> This patchset has a critical fix and added helper functions
> to improve code readbility in ISR.

Applied to 5.16/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] megaraid_sas: Driver version update to 07.719.03.00-rc1
  2021-09-29 12:40 [PATCH 0/3] megaraid_sas: Driver version update to 07.719.03.00-rc1 Sumit Saxena
                   ` (3 preceding siblings ...)
  2021-10-05  3:20 ` [PATCH 0/3] " Martin K. Petersen
@ 2021-10-12 20:35 ` Martin K. Petersen
  4 siblings, 0 replies; 6+ messages in thread
From: Martin K. Petersen @ 2021-10-12 20:35 UTC (permalink / raw)
  To: Sumit Saxena, jejb, linux-scsi
  Cc: Martin K . Petersen, chandrakanth.patil, kashyap.desai

On Wed, 29 Sep 2021 18:10:19 +0530, Sumit Saxena wrote:

> This patchset has a critical fix and added helper functions
> to improve code readbility in ISR.
> 
> Sumit Saxena (3):
>   megaraid_sas: fix concurrent access to ISR between IRQ polling and
>     real interrupt
>   megaraid_sas: Add helper functions- {access/release}_irq_context
>   megaraid_sas: Driver version update to 07.719.03.00-rc1
> 
> [...]

Applied to 5.16/scsi-queue, thanks!

[1/3] megaraid_sas: fix concurrent access to ISR between IRQ polling and real interrupt
      https://git.kernel.org/mkp/scsi/c/e7dcc514a49e
[2/3] megaraid_sas: Add helper functions- {access/release}_irq_context
      https://git.kernel.org/mkp/scsi/c/4c32edc350e4
[3/3] megaraid_sas: Driver version update to 07.719.03.00-rc1
      https://git.kernel.org/mkp/scsi/c/cdf7f6a10d48

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-12 20:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 12:40 [PATCH 0/3] megaraid_sas: Driver version update to 07.719.03.00-rc1 Sumit Saxena
2021-09-29 12:40 ` [PATCH 1/3] megaraid_sas: fix concurrent access to ISR between IRQ polling and real interrupt Sumit Saxena
2021-09-29 12:40 ` [PATCH 2/3] megaraid_sas: Add helper functions- {access/release}_irq_context Sumit Saxena
2021-09-29 12:40 ` [PATCH 3/3] megaraid_sas: Driver version update to 07.719.03.00-rc1 Sumit Saxena
2021-10-05  3:20 ` [PATCH 0/3] " Martin K. Petersen
2021-10-12 20:35 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.