From: Sherry Sun <sherry.sun@nxp.com>
To: sudeep.dutt@intel.com, ashutosh.dixit@intel.com, arnd@arndb.de,
gregkh@linuxfoundation.org, wang.yi59@zte.com.cn,
huang.zijiang@zte.com.cn, rikard.falkeborn@gmail.com,
lee.jones@linaro.org, mst@redhat.com
Cc: linux-kernel@vger.kernel.org, linux-imx@nxp.com
Subject: [PATCH 2/5] misc: vop: change the way of allocating used ring
Date: Fri, 25 Sep 2020 15:26:27 +0800 [thread overview]
Message-ID: <20200925072630.8157-3-sherry.sun@nxp.com> (raw)
In-Reply-To: <20200925072630.8157-1-sherry.sun@nxp.com>
For noncoherent platform, we shouldn't allocate and reassign the used
ring. Since RC has allocated the entire vring, including the used ring.
simply add the corresponding offset can get the used ring address.
If follow the orginal way to reassign the used ring, will encounter a
problem. When host finished with descriptor, it will update the used
ring with putused_kern function, if reassign used ring at EP side, used
ring will be io device memory for RC, use memcpy in putused_kern will
cause kernel panic.
Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
drivers/misc/mic/vop/vop_main.c | 48 ++++++++++++++++++++++-----------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c
index 6722c726b259..d3645122c983 100644
--- a/drivers/misc/mic/vop/vop_main.c
+++ b/drivers/misc/mic/vop/vop_main.c
@@ -18,6 +18,7 @@
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/dma-mapping.h>
+#include <linux/dma-noncoherent.h>
#include <linux/io-64-nonatomic-lo-hi.h>
#include "vop_main.h"
@@ -249,10 +250,13 @@ static void vop_del_vq(struct virtqueue *vq, int n)
struct _vop_vdev *vdev = to_vopvdev(vq->vdev);
struct vop_device *vpdev = vdev->vpdev;
- dma_unmap_single(&vpdev->dev, vdev->used[n],
- vdev->used_size[n], DMA_BIDIRECTIONAL);
- free_pages((unsigned long)vdev->used_virt[n],
- get_order(vdev->used_size[n]));
+ if (dev_is_dma_coherent(_vop_dev(vdev))) {
+ dma_unmap_single(&vpdev->dev, vdev->used[n],
+ vdev->used_size[n], DMA_BIDIRECTIONAL);
+ free_pages((unsigned long)vdev->used_virt[n],
+ get_order(vdev->used_size[n]));
+ }
+
vring_del_virtqueue(vq);
vpdev->hw_ops->unmap(vpdev, vdev->vr[n]);
vdev->vr[n] = NULL;
@@ -339,8 +343,13 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev,
vdev->used_size[index] = PAGE_ALIGN(sizeof(__u16) * 3 +
sizeof(struct vring_used_elem) *
le16_to_cpu(config.num));
- used = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
- get_order(vdev->used_size[index]));
+ if (!dev_is_dma_coherent(_vop_dev(vdev)))
+ used = va + PAGE_ALIGN(sizeof(struct vring_desc) * le16_to_cpu(config.num) +
+ sizeof(__u16) * (3 + le16_to_cpu(config.num)));
+ else
+ used = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+ get_order(vdev->used_size[index]));
+
vdev->used_virt[index] = used;
if (!used) {
err = -ENOMEM;
@@ -357,14 +366,20 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev,
goto free_used;
}
- vdev->used[index] = dma_map_single(&vpdev->dev, used,
- vdev->used_size[index],
- DMA_BIDIRECTIONAL);
- if (dma_mapping_error(&vpdev->dev, vdev->used[index])) {
- err = -ENOMEM;
- dev_err(_vop_dev(vdev), "%s %d err %d\n",
- __func__, __LINE__, err);
- goto del_vq;
+ if (!dev_is_dma_coherent(_vop_dev(vdev)))
+ vdev->used[index] = config.address +
+ PAGE_ALIGN(sizeof(struct vring_desc) * le16_to_cpu(config.num) +
+ sizeof(__u16) * (3 + le16_to_cpu(config.num)));
+ else {
+ vdev->used[index] = dma_map_single(&vpdev->dev, used,
+ vdev->used_size[index],
+ DMA_BIDIRECTIONAL);
+ if (dma_mapping_error(&vpdev->dev, vdev->used[index])) {
+ err = -ENOMEM;
+ dev_err(_vop_dev(vdev), "%s %d err %d\n",
+ __func__, __LINE__, err);
+ goto del_vq;
+ }
}
writeq(vdev->used[index], &vqconfig->used_address);
@@ -373,8 +388,9 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev,
del_vq:
vring_del_virtqueue(vq);
free_used:
- free_pages((unsigned long)used,
- get_order(vdev->used_size[index]));
+ if (dev_is_dma_coherent(_vop_dev(vdev)))
+ free_pages((unsigned long)used,
+ get_order(vdev->used_size[index]));
unmap:
vpdev->hw_ops->unmap(vpdev, vdev->vr[index]);
return ERR_PTR(err);
--
2.17.1
next prev parent reply other threads:[~2020-09-25 7:27 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
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 ` Sherry Sun [this message]
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=20200925072630.8157-3-sherry.sun@nxp.com \
--to=sherry.sun@nxp.com \
--cc=arnd@arndb.de \
--cc=ashutosh.dixit@intel.com \
--cc=gregkh@linuxfoundation.org \
--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=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®