linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Tyrel Datwyler <tyreld@linux.ibm.com>
To: Cai Huoqing <caihuoqing@baidu.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	linux-kernel@vger.kernel.org, Paul Mackerras <paulus@samba.org>,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v2] scsi: ibmvscsi: Use dma_alloc_noncoherent() instead of get_zeroed_page/dma_map_single()
Date: Thu, 14 Oct 2021 15:07:55 -0700	[thread overview]
Message-ID: <0a2ef145-b84f-129a-c915-50f32aeeaa1d@linux.ibm.com> (raw)
In-Reply-To: <20211012032317.2360-1-caihuoqing@baidu.com>

On 10/11/21 8:23 PM, Cai Huoqing wrote:
> Replacing get_zeroed_page/free_page/dma_map_single/dma_unmap_single()
> with dma_alloc_noncoherent/dma_free_noncoherent() helps to reduce
> code size, and simplify the code, and the hardware can keeep DMA
> coherent itsel
Not sure why the switch from coherent in v1 to noncoherent in v2. I think that
was unnecessary and I believe requires explicit synchronization via
dma_sync_single_{for_device|for_cpu} calls.

Further, as both kernel-bot and Nathan have already pointed out this doesn't
even compile.

-Tyrel

> 
> Signed-off-by: Cai Huoqing <caihuoqing@baidu.com>
> ---
> v1->v2:
> 	*Change to dma_alloc/free_noncoherent from dma_alloc/free_coherent.
> 	*Update changelog.
> 
>  drivers/scsi/ibmvscsi/ibmvfc.c   | 16 ++++------------
>  drivers/scsi/ibmvscsi/ibmvscsi.c | 29 +++++++++--------------------
>  2 files changed, 13 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
> index 1f1586ad48fe..6e95fd02fd25 100644
> --- a/drivers/scsi/ibmvscsi/ibmvfc.c
> +++ b/drivers/scsi/ibmvscsi/ibmvfc.c
> @@ -869,8 +869,8 @@ static void ibmvfc_free_queue(struct ibmvfc_host *vhost,
>  {
>  	struct device *dev = vhost->dev;
>  
> -	dma_unmap_single(dev, queue->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
> -	free_page((unsigned long)queue->msgs.handle);
> +	dma_free_noncoherent(dev, PAGE_SIZE, queue->msgs.handle,
> +			     queue->msg_token, DMA_BIDIRECTIONAL);
>  	queue->msgs.handle = NULL;
>  
>  	ibmvfc_free_event_pool(vhost, queue);
> @@ -5663,19 +5663,11 @@ static int ibmvfc_alloc_queue(struct ibmvfc_host *vhost,
>  		return -ENOMEM;
>  	}
>  
> -	queue->msgs.handle = (void *)get_zeroed_page(GFP_KERNEL);
> +	queue->msgs.handle = dma_alloc_noncoherent(dev, PAGE_SIZE, &queue->msg_token,
> +						   DMA_BIDIRECTIONAL, GFP_KERNEL);
>  	if (!queue->msgs.handle)
>  		return -ENOMEM;
>  
> -	queue->msg_token = dma_map_single(dev, queue->msgs.handle, PAGE_SIZE,
> -					  DMA_BIDIRECTIONAL);
> -
> -	if (dma_mapping_error(dev, queue->msg_token)) {
> -		free_page((unsigned long)queue->msgs.handle);
> -		queue->msgs.handle = NULL;
> -		return -ENOMEM;
> -	}
> -
>  	queue->cur = 0;
>  	queue->fmt = fmt;
>  	queue->size = PAGE_SIZE / fmt_size;
> diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
> index ea8e01f49cba..68409c298c74 100644
> --- a/drivers/scsi/ibmvscsi/ibmvscsi.c
> +++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
> @@ -151,10 +151,8 @@ static void ibmvscsi_release_crq_queue(struct crq_queue *queue,
>  			msleep(100);
>  		rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
>  	} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
> -	dma_unmap_single(hostdata->dev,
> -			 queue->msg_token,
> -			 queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL);
> -	free_page((unsigned long)queue->msgs);
> +	dma_free_noncoherent(hostdata->dev, PAGE_SIZE,
> +			     queue->msgs, queue->msg_token, DMA_BIDIRECTIONAL);
>  }
>  
>  /**
> @@ -331,18 +329,12 @@ static int ibmvscsi_init_crq_queue(struct crq_queue *queue,
>  	int retrc;
>  	struct vio_dev *vdev = to_vio_dev(hostdata->dev);
>  
> -	queue->msgs = (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL);
> -
> -	if (!queue->msgs)
> -		goto malloc_failed;
>  	queue->size = PAGE_SIZE / sizeof(*queue->msgs);
> -
> -	queue->msg_token = dma_map_single(hostdata->dev, queue->msgs,
> -					  queue->size * sizeof(*queue->msgs),
> -					  DMA_BIDIRECTIONAL);
> -
> -	if (dma_mapping_error(hostdata->dev, queue->msg_token))
> -		goto map_failed;
> +	queue->msgs = dma_alloc_noncoherent(hostdata->dev,
> +					    PAGE_SIZE, &queue->msg_token,
> +					    DMA_BIDIRECTIONAL, GFP_KERNEL);
> +	if (!queue->msg)
> +		goto malloc_failed;
>  
>  	gather_partition_info();
>  	set_adapter_info(hostdata);
> @@ -395,11 +387,8 @@ static int ibmvscsi_init_crq_queue(struct crq_queue *queue,
>  		rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
>  	} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
>        reg_crq_failed:
> -	dma_unmap_single(hostdata->dev,
> -			 queue->msg_token,
> -			 queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL);
> -      map_failed:
> -	free_page((unsigned long)queue->msgs);
> +	dma_free_noncoherent(hostdata->dev, PAGE_SIZE, queue->msg,
> +			     queue->msg_token, DMA_BIDIRECTIONAL);
>        malloc_failed:
>  	return -1;
>  }
> 


  parent reply	other threads:[~2021-10-14 22:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-12  3:23 [PATCH v2] scsi: ibmvscsi: Use dma_alloc_noncoherent() instead of get_zeroed_page/dma_map_single() Cai Huoqing
2021-10-14 19:25 ` Nathan Lynch
2021-10-14 22:07 ` Tyrel Datwyler [this message]
2021-11-08 14:49 ` kernel test robot

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=0a2ef145-b84f-129a-c915-50f32aeeaa1d@linux.ibm.com \
    --to=tyreld@linux.ibm.com \
    --cc=caihuoqing@baidu.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=martin.petersen@oracle.com \
    --cc=paulus@samba.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;
as well as URLs for NNTP newsgroup(s).