mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Sherry Sun <sherry.sun@nxp.com>
Cc: sudeep.dutt@intel.com, ashutosh.dixit@intel.com, arnd@arndb.de,
	wang.yi59@zte.com.cn, huang.zijiang@zte.com.cn,
	rikard.falkeborn@gmail.com, lee.jones@linaro.org, mst@redhat.com,
	linux-kernel@vger.kernel.org, linux-imx@nxp.com
Subject: Re: [PATCH 1/5] misc: vop: change the way of allocating vring for noncoherent platform
Date: Fri, 25 Sep 2020 14:16:00 +0200	[thread overview]
Message-ID: <20200925121600.GA2680110@kroah.com> (raw)
In-Reply-To: <20200925072630.8157-2-sherry.sun@nxp.com>

On Fri, Sep 25, 2020 at 03:26:26PM +0800, Sherry Sun wrote:
> For noncoherent platform, we should allocate vring through
> dma_alloc_coherent api to ensure timely synchronization of vring.
> The orginal way which used __get_free_pages and dma_map_single only
> apply to coherent platforms.
> 
> Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
> Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
> ---
>  drivers/misc/mic/vop/vop_vringh.c | 101 ++++++++++++++++++++----------
>  1 file changed, 67 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/misc/mic/vop/vop_vringh.c b/drivers/misc/mic/vop/vop_vringh.c
> index f344209ac386..fc8d8ff9ded3 100644
> --- a/drivers/misc/mic/vop/vop_vringh.c
> +++ b/drivers/misc/mic/vop/vop_vringh.c
> @@ -9,6 +9,7 @@
>  #include <linux/sched.h>
>  #include <linux/poll.h>
>  #include <linux/dma-mapping.h>
> +#include <linux/dma-noncoherent.h>
>  
>  #include <linux/mic_common.h>
>  #include "../common/mic_dev.h"
> @@ -67,11 +68,12 @@ static void vop_virtio_init_post(struct vop_vdev *vdev)
>  			dev_warn(vop_dev(vdev), "used_address zero??\n");
>  			continue;
>  		}
> -		vdev->vvr[i].vrh.vring.used =
> -			(void __force *)vpdev->hw_ops->remap(
> -			vpdev,
> -			le64_to_cpu(vqconfig[i].used_address),
> -			used_size);
> +		if (dev_is_dma_coherent(vop_dev(vdev)))
> +			vdev->vvr[i].vrh.vring.used =
> +				(void __force *)vpdev->hw_ops->remap(
> +				vpdev,
> +				le64_to_cpu(vqconfig[i].used_address),
> +				used_size);

That's really hard to read, don't you agree?  We can go longer than 80
columns now, and why the __force?



>  	}
>  
>  	vdev->dc->used_address_updated = 0;
> @@ -298,9 +300,14 @@ static int vop_virtio_add_device(struct vop_vdev *vdev,
>  		mutex_init(&vvr->vr_mutex);
>  		vr_size = PAGE_ALIGN(round_up(vring_size(num, MIC_VIRTIO_RING_ALIGN), 4) +
>  			sizeof(struct _mic_vring_info));
> -		vr->va = (void *)
> -			__get_free_pages(GFP_KERNEL | __GFP_ZERO,
> -					 get_order(vr_size));
> +
> +		if (!dev_is_dma_coherent(vop_dev(vdev)))
> +			vr->va = dma_alloc_coherent(vop_dev(vdev), vr_size,
> +						    &vr_addr, GFP_KERNEL);

Are you sure this is correct?  If dev_is_dma_coherent is NOT true, then
you call dma_alloc_coherent()?


> +		else
> +			vr->va = (void *)
> +				__get_free_pages(GFP_KERNEL | __GFP_ZERO,
> +						 get_order(vr_size));
>  		if (!vr->va) {
>  			ret = -ENOMEM;
>  			dev_err(vop_dev(vdev), "%s %d err %d\n",
> @@ -310,14 +317,17 @@ static int vop_virtio_add_device(struct vop_vdev *vdev,
>  		vr->len = vr_size;
>  		vr->info = vr->va + round_up(vring_size(num, MIC_VIRTIO_RING_ALIGN), 4);
>  		vr->info->magic = cpu_to_le32(MIC_MAGIC + vdev->virtio_id + i);
> -		vr_addr = dma_map_single(&vpdev->dev, vr->va, vr_size,
> -					 DMA_BIDIRECTIONAL);
> -		if (dma_mapping_error(&vpdev->dev, vr_addr)) {
> -			free_pages((unsigned long)vr->va, get_order(vr_size));
> -			ret = -ENOMEM;
> -			dev_err(vop_dev(vdev), "%s %d err %d\n",
> -				__func__, __LINE__, ret);
> -			goto err;
> +
> +		if (dev_is_dma_coherent(vop_dev(vdev))) {
> +			vr_addr = dma_map_single(&vpdev->dev, vr->va, vr_size,
> +						 DMA_BIDIRECTIONAL);
> +			if (dma_mapping_error(&vpdev->dev, vr_addr)) {
> +				free_pages((unsigned long)vr->va, get_order(vr_size));
> +				ret = -ENOMEM;
> +				dev_err(vop_dev(vdev), "%s %d err %d\n",
> +						__func__, __LINE__, ret);
> +				goto err;
> +			}

What about if this is not true?

Same for other places in this patch.

thanks,

greg k-h

  reply	other threads:[~2020-09-25 12:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-25  7:26 [PATCH 0/5] Add noncoherent platform support for vop driver Sherry Sun
2020-09-25  7:26 ` [PATCH 1/5] misc: vop: change the way of allocating vring for noncoherent platform Sherry Sun
2020-09-25 12:16   ` Greg KH [this message]
2020-09-27  7:06     ` Sherry Sun
2020-09-26  7:50   ` Christoph Hellwig
2020-09-27  7:58     ` Sherry Sun
2020-09-28  6:09       ` Christoph Hellwig
2020-09-28 10:10         ` Sherry Sun
2020-09-25  7:26 ` [PATCH 2/5] misc: vop: change the way of allocating used ring Sherry Sun
2020-09-25  7:26 ` [PATCH 3/5] misc: vop: simply return the saved dma address instead of virt_to_phys Sherry Sun
2020-09-25 12:17   ` Greg KH
2020-09-27  7:23     ` Sherry Sun
2020-09-25  7:26 ` [PATCH 4/5] misc: vop: set VIRTIO_F_ACCESS_PLATFORM for nocoherent platform Sherry Sun
2020-09-25 12:16   ` Greg KH
2020-09-27  7:20     ` Sherry Sun
2020-09-26  7:51   ` Christoph Hellwig
2020-09-27  8:05     ` Sherry Sun
2020-09-28  6:09       ` Christoph Hellwig
2020-09-28  9:57         ` Sherry Sun
2020-09-25  7:26 ` [PATCH 5/5] misc: vop: mapping kernel memory to user space as noncached Sherry Sun
2020-09-25 11:25 ` [PATCH 0/5] Add noncoherent platform support for vop driver Arnd Bergmann
2020-09-27  5:07   ` Sherry Sun

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=20200925121600.GA2680110@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=arnd@arndb.de \
    --cc=ashutosh.dixit@intel.com \
    --cc=huang.zijiang@zte.com.cn \
    --cc=lee.jones@linaro.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=rikard.falkeborn@gmail.com \
    --cc=sherry.sun@nxp.com \
    --cc=sudeep.dutt@intel.com \
    --cc=wang.yi59@zte.com.cn \
    /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

all inboxes | Powered by JetHome®