All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mpt3sas: Fix incorrect 4gb boundary check
@ 2022-03-03 14:02 Sreekanth Reddy
  2022-03-03 15:19 ` Laurence Oberman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sreekanth Reddy @ 2022-03-03 14:02 UTC (permalink / raw)
  To: linux-scsi; +Cc: martin.petersen, Sreekanth Reddy

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

Driver has to do a 4gb boundary check using the pool's
dma address instead of using a virtual address.

Fixes: d6adc251dd2f("mpt3sas: Force PCIe scatterlist allocations to be within same 4 GB region")
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index ebb61b47dc2f..a10ceaa8f881 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -5723,14 +5723,13 @@ _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc)
  */
 
 static int
-mpt3sas_check_same_4gb_region(long reply_pool_start_address, u32 pool_sz)
+mpt3sas_check_same_4gb_region(dma_addr_t start_address, u32 pool_sz)
 {
-	long reply_pool_end_address;
+	dma_addr_t end_address;
 
-	reply_pool_end_address = reply_pool_start_address + pool_sz;
+	end_address = start_address + pool_sz - 1;
 
-	if (upper_32_bits(reply_pool_start_address) ==
-		upper_32_bits(reply_pool_end_address))
+	if (upper_32_bits(start_address) == upper_32_bits(end_address))
 		return 1;
 	else
 		return 0;
@@ -5791,7 +5790,7 @@ _base_allocate_pcie_sgl_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz)
 		}
 
 		if (!mpt3sas_check_same_4gb_region(
-		    (long)ioc->pcie_sg_lookup[i].pcie_sgl, sz)) {
+		    ioc->pcie_sg_lookup[i].pcie_sgl_dma, sz)) {
 			ioc_err(ioc, "PCIE SGLs are not in same 4G !! pcie sgl (0x%p) dma = (0x%llx)\n",
 			    ioc->pcie_sg_lookup[i].pcie_sgl,
 			    (unsigned long long)
@@ -5846,8 +5845,8 @@ _base_allocate_chain_dma_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz)
 			    GFP_KERNEL, &ctr->chain_buffer_dma);
 			if (!ctr->chain_buffer)
 				return -EAGAIN;
-			if (!mpt3sas_check_same_4gb_region((long)
-			    ctr->chain_buffer, ioc->chain_segment_sz)) {
+			if (!mpt3sas_check_same_4gb_region(
+			    ctr->chain_buffer_dma, ioc->chain_segment_sz)) {
 				ioc_err(ioc,
 				    "Chain buffers are not in same 4G !!! Chain buff (0x%p) dma = (0x%llx)\n",
 				    ctr->chain_buffer,
@@ -5883,7 +5882,7 @@ _base_allocate_sense_dma_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz)
 	    GFP_KERNEL, &ioc->sense_dma);
 	if (!ioc->sense)
 		return -EAGAIN;
-	if (!mpt3sas_check_same_4gb_region((long)ioc->sense, sz)) {
+	if (!mpt3sas_check_same_4gb_region(ioc->sense_dma, sz)) {
 		dinitprintk(ioc, pr_err(
 		    "Bad Sense Pool! sense (0x%p) sense_dma = (0x%llx)\n",
 		    ioc->sense, (unsigned long long) ioc->sense_dma));
@@ -5916,7 +5915,7 @@ _base_allocate_reply_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz)
 	    &ioc->reply_dma);
 	if (!ioc->reply)
 		return -EAGAIN;
-	if (!mpt3sas_check_same_4gb_region((long)ioc->reply_free, sz)) {
+	if (!mpt3sas_check_same_4gb_region(ioc->reply_dma, sz)) {
 		dinitprintk(ioc, pr_err(
 		    "Bad Reply Pool! Reply (0x%p) Reply dma = (0x%llx)\n",
 		    ioc->reply, (unsigned long long) ioc->reply_dma));
@@ -5951,7 +5950,7 @@ _base_allocate_reply_free_dma_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz)
 	    GFP_KERNEL, &ioc->reply_free_dma);
 	if (!ioc->reply_free)
 		return -EAGAIN;
-	if (!mpt3sas_check_same_4gb_region((long)ioc->reply_free, sz)) {
+	if (!mpt3sas_check_same_4gb_region(ioc->reply_free_dma, sz)) {
 		dinitprintk(ioc,
 		    pr_err("Bad Reply Free Pool! Reply Free (0x%p) Reply Free dma = (0x%llx)\n",
 		    ioc->reply_free, (unsigned long long) ioc->reply_free_dma));
@@ -5990,7 +5989,7 @@ _base_allocate_reply_post_free_array(struct MPT3SAS_ADAPTER *ioc,
 	    GFP_KERNEL, &ioc->reply_post_free_array_dma);
 	if (!ioc->reply_post_free_array)
 		return -EAGAIN;
-	if (!mpt3sas_check_same_4gb_region((long)ioc->reply_post_free_array,
+	if (!mpt3sas_check_same_4gb_region(ioc->reply_post_free_array_dma,
 	    reply_post_free_array_sz)) {
 		dinitprintk(ioc, pr_err(
 		    "Bad Reply Free Pool! Reply Free (0x%p) Reply Free dma = (0x%llx)\n",
@@ -6055,7 +6054,7 @@ base_alloc_rdpq_dma_pool(struct MPT3SAS_ADAPTER *ioc, int sz)
 			 * resources and set DMA mask to 32 and allocate.
 			 */
 			if (!mpt3sas_check_same_4gb_region(
-				(long)ioc->reply_post[i].reply_post_free, sz)) {
+				ioc->reply_post[i].reply_post_free_dma, sz)) {
 				dinitprintk(ioc,
 				    ioc_err(ioc, "bad Replypost free pool(0x%p)"
 				    "reply_post_free_dma = (0x%llx)\n",
-- 
2.27.0


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

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

* Re: [PATCH] mpt3sas: Fix incorrect 4gb boundary check
  2022-03-03 14:02 [PATCH] mpt3sas: Fix incorrect 4gb boundary check Sreekanth Reddy
@ 2022-03-03 15:19 ` Laurence Oberman
  2022-03-09  3:37 ` Martin K. Petersen
  2022-03-15  5:02 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Laurence Oberman @ 2022-03-03 15:19 UTC (permalink / raw)
  To: Sreekanth Reddy, linux-scsi; +Cc: martin.petersen

On Thu, 2022-03-03 at 19:32 +0530, Sreekanth Reddy wrote:
> Driver has to do a 4gb boundary check using the pool's
> dma address instead of using a virtual address.
> 
> Fixes: d6adc251dd2f("mpt3sas: Force PCIe scatterlist allocations to
> be within same 4 GB region")
> Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
> ---
>  drivers/scsi/mpt3sas/mpt3sas_base.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c
> b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index ebb61b47dc2f..a10ceaa8f881 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -5723,14 +5723,13 @@ _base_release_memory_pools(struct
> MPT3SAS_ADAPTER *ioc)
>   */
>  
>  static int
> -mpt3sas_check_same_4gb_region(long reply_pool_start_address, u32
> pool_sz)
> +mpt3sas_check_same_4gb_region(dma_addr_t start_address, u32 pool_sz)
>  {
> -	long reply_pool_end_address;
> +	dma_addr_t end_address;
>  
> -	reply_pool_end_address = reply_pool_start_address + pool_sz;
> +	end_address = start_address + pool_sz - 1;
>  
> -	if (upper_32_bits(reply_pool_start_address) ==
> -		upper_32_bits(reply_pool_end_address))
> +	if (upper_32_bits(start_address) == upper_32_bits(end_address))
>  		return 1;
>  	else
>  		return 0;
> @@ -5791,7 +5790,7 @@ _base_allocate_pcie_sgl_pool(struct
> MPT3SAS_ADAPTER *ioc, u32 sz)
>  		}
>  
>  		if (!mpt3sas_check_same_4gb_region(
> -		    (long)ioc->pcie_sg_lookup[i].pcie_sgl, sz)) {
> +		    ioc->pcie_sg_lookup[i].pcie_sgl_dma, sz)) {
>  			ioc_err(ioc, "PCIE SGLs are not in same 4G !!
> pcie sgl (0x%p) dma = (0x%llx)\n",
>  			    ioc->pcie_sg_lookup[i].pcie_sgl,
>  			    (unsigned long long)
> @@ -5846,8 +5845,8 @@ _base_allocate_chain_dma_pool(struct
> MPT3SAS_ADAPTER *ioc, u32 sz)
>  			    GFP_KERNEL, &ctr->chain_buffer_dma);
>  			if (!ctr->chain_buffer)
>  				return -EAGAIN;
> -			if (!mpt3sas_check_same_4gb_region((long)
> -			    ctr->chain_buffer, ioc->chain_segment_sz))
> {
> +			if (!mpt3sas_check_same_4gb_region(
> +			    ctr->chain_buffer_dma, ioc-
> >chain_segment_sz)) {
>  				ioc_err(ioc,
>  				    "Chain buffers are not in same 4G
> !!! Chain buff (0x%p) dma = (0x%llx)\n",
>  				    ctr->chain_buffer,
> @@ -5883,7 +5882,7 @@ _base_allocate_sense_dma_pool(struct
> MPT3SAS_ADAPTER *ioc, u32 sz)
>  	    GFP_KERNEL, &ioc->sense_dma);
>  	if (!ioc->sense)
>  		return -EAGAIN;
> -	if (!mpt3sas_check_same_4gb_region((long)ioc->sense, sz)) {
> +	if (!mpt3sas_check_same_4gb_region(ioc->sense_dma, sz)) {
>  		dinitprintk(ioc, pr_err(
>  		    "Bad Sense Pool! sense (0x%p) sense_dma =
> (0x%llx)\n",
>  		    ioc->sense, (unsigned long long) ioc->sense_dma));
> @@ -5916,7 +5915,7 @@ _base_allocate_reply_pool(struct
> MPT3SAS_ADAPTER *ioc, u32 sz)
>  	    &ioc->reply_dma);
>  	if (!ioc->reply)
>  		return -EAGAIN;
> -	if (!mpt3sas_check_same_4gb_region((long)ioc->reply_free, sz))
> {
> +	if (!mpt3sas_check_same_4gb_region(ioc->reply_dma, sz)) {
>  		dinitprintk(ioc, pr_err(
>  		    "Bad Reply Pool! Reply (0x%p) Reply dma =
> (0x%llx)\n",
>  		    ioc->reply, (unsigned long long) ioc->reply_dma));
> @@ -5951,7 +5950,7 @@ _base_allocate_reply_free_dma_pool(struct
> MPT3SAS_ADAPTER *ioc, u32 sz)
>  	    GFP_KERNEL, &ioc->reply_free_dma);
>  	if (!ioc->reply_free)
>  		return -EAGAIN;
> -	if (!mpt3sas_check_same_4gb_region((long)ioc->reply_free, sz))
> {
> +	if (!mpt3sas_check_same_4gb_region(ioc->reply_free_dma, sz)) {
>  		dinitprintk(ioc,
>  		    pr_err("Bad Reply Free Pool! Reply Free (0x%p)
> Reply Free dma = (0x%llx)\n",
>  		    ioc->reply_free, (unsigned long long) ioc-
> >reply_free_dma));
> @@ -5990,7 +5989,7 @@ _base_allocate_reply_post_free_array(struct
> MPT3SAS_ADAPTER *ioc,
>  	    GFP_KERNEL, &ioc->reply_post_free_array_dma);
>  	if (!ioc->reply_post_free_array)
>  		return -EAGAIN;
> -	if (!mpt3sas_check_same_4gb_region((long)ioc-
> >reply_post_free_array,
> +	if (!mpt3sas_check_same_4gb_region(ioc-
> >reply_post_free_array_dma,
>  	    reply_post_free_array_sz)) {
>  		dinitprintk(ioc, pr_err(
>  		    "Bad Reply Free Pool! Reply Free (0x%p) Reply Free
> dma = (0x%llx)\n",
> @@ -6055,7 +6054,7 @@ base_alloc_rdpq_dma_pool(struct MPT3SAS_ADAPTER
> *ioc, int sz)
>  			 * resources and set DMA mask to 32 and
> allocate.
>  			 */
>  			if (!mpt3sas_check_same_4gb_region(
> -				(long)ioc-
> >reply_post[i].reply_post_free, sz)) {
> +				ioc->reply_post[i].reply_post_free_dma, 
> sz)) {
>  				dinitprintk(ioc,
>  				    ioc_err(ioc, "bad Replypost free
> pool(0x%p)"
>  				    "reply_post_free_dma = (0x%llx)\n",

Please add
Suggested-by: David Jeffery <djeffery@redhat.com>


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

* Re: [PATCH] mpt3sas: Fix incorrect 4gb boundary check
  2022-03-03 14:02 [PATCH] mpt3sas: Fix incorrect 4gb boundary check Sreekanth Reddy
  2022-03-03 15:19 ` Laurence Oberman
@ 2022-03-09  3:37 ` Martin K. Petersen
  2022-03-15  5:02 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-03-09  3:37 UTC (permalink / raw)
  To: Sreekanth Reddy; +Cc: linux-scsi, martin.petersen


Sreekanth,

> Driver has to do a 4gb boundary check using the pool's dma address
> instead of using a virtual address.

Applied to 5.18/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH] mpt3sas: Fix incorrect 4gb boundary check
  2022-03-03 14:02 [PATCH] mpt3sas: Fix incorrect 4gb boundary check Sreekanth Reddy
  2022-03-03 15:19 ` Laurence Oberman
  2022-03-09  3:37 ` Martin K. Petersen
@ 2022-03-15  5:02 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-03-15  5:02 UTC (permalink / raw)
  To: Sreekanth Reddy, linux-scsi; +Cc: Martin K . Petersen

On Thu, 3 Mar 2022 19:32:30 +0530, Sreekanth Reddy wrote:

> Driver has to do a 4gb boundary check using the pool's
> dma address instead of using a virtual address.
> 
> 

Applied to 5.18/scsi-queue, thanks!

[1/1] mpt3sas: Fix incorrect 4gb boundary check
      https://git.kernel.org/mkp/scsi/c/208cc9fe6f21

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2022-03-15  5:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-03 14:02 [PATCH] mpt3sas: Fix incorrect 4gb boundary check Sreekanth Reddy
2022-03-03 15:19 ` Laurence Oberman
2022-03-09  3:37 ` Martin K. Petersen
2022-03-15  5:02 ` 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.