* [PATCH V2 0/4] Fix some bugs of the vop driver and mpssd user space tool
@ 2020-09-29 9:11 Sherry Sun
2020-09-29 9:11 ` [PATCH V2 1/4] samples: mpssd: fix the build errors when enable DEBUG Sherry Sun
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Sherry Sun @ 2020-09-29 9:11 UTC (permalink / raw)
To: sudeep.dutt, ashutosh.dixit, arnd, gregkh; +Cc: linux-kernel, linux-imx
Changes in V2:
1. Change the way of copy data from ubuf to dbuf in patch4. Reuse the allocated
vvr->buf as the temp buffer and add a loop for multiple copies if there are too
much data.
This patchset fix some bugs about the vop driver and Intel MIC user space tool.
Sherry Sun (4):
samples: mpssd: fix the build errors when enable DEBUG in mpssd.c
misc: vop: build VOP based on CONFIG_VOP
misc: vop: add round_up(x,4) for vring_size to avoid kernel panic
mic: vop: copy data to kernel space then write to io memory
drivers/misc/mic/vop/Makefile | 2 +-
drivers/misc/mic/vop/vop_main.c | 2 +-
drivers/misc/mic/vop/vop_vringh.c | 24 ++++++++++++++++--------
samples/mic/mpssd/mpssd.c | 24 ++++++++++++------------
4 files changed, 30 insertions(+), 22 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH V2 1/4] samples: mpssd: fix the build errors when enable DEBUG
2020-09-29 9:11 [PATCH V2 0/4] Fix some bugs of the vop driver and mpssd user space tool Sherry Sun
@ 2020-09-29 9:11 ` Sherry Sun
2020-09-29 9:11 ` [PATCH V2 2/4] misc: vop: build VOP based on CONFIG_VOP Sherry Sun
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sherry Sun @ 2020-09-29 9:11 UTC (permalink / raw)
To: sudeep.dutt, ashutosh.dixit, arnd, gregkh; +Cc: linux-kernel, linux-imx
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 3410 bytes --]
If enable DEBUG, will meet the following errors when build mpssd, so fix
them here. Only one error is listed here, other errors are similar.
mpssd.c: In function ‘virtio_net’:
mpssd.c:615:21: error: incompatible type for argument 2 of ‘disp_iovec’
disp_iovec(mic, copy, __func__, __LINE__);
^~~~
mpssd.c:361:1: note: expected ‘struct mic_copy_desc *’ but argument is of type ‘struct mic_copy_desc’
disp_iovec(struct mic_info *mic, struct mic_copy_desc *copy,
^~~~~~~~~~
Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
---
samples/mic/mpssd/mpssd.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/samples/mic/mpssd/mpssd.c b/samples/mic/mpssd/mpssd.c
index a11bf6c5b53b..51d03545869e 100644
--- a/samples/mic/mpssd/mpssd.c
+++ b/samples/mic/mpssd/mpssd.c
@@ -612,7 +612,7 @@ virtio_net(void *arg)
copy.out_len, hdr->gso_type);
#endif
#ifdef DEBUG
- disp_iovec(mic, copy, __func__, __LINE__);
+ disp_iovec(mic, ©, __func__, __LINE__);
mpsslog("%s %s %d read from tap 0x%lx\n",
mic->name, __func__, __LINE__,
len);
@@ -632,7 +632,7 @@ virtio_net(void *arg)
if (!err)
verify_out_len(mic, ©);
#ifdef DEBUG
- disp_iovec(mic, copy, __func__, __LINE__);
+ disp_iovec(mic, ©, __func__, __LINE__);
mpsslog("%s %s %d wrote to net 0x%lx\n",
mic->name, __func__, __LINE__,
sum_iovec_len(©));
@@ -681,12 +681,12 @@ virtio_net(void *arg)
sizeof(struct virtio_net_hdr);
verify_out_len(mic, ©);
#ifdef DEBUG
- disp_iovec(mic, copy, __func__,
+ disp_iovec(mic, ©, __func__,
__LINE__);
mpsslog("%s %s %d ",
mic->name, __func__, __LINE__);
mpsslog("read from net 0x%lx\n",
- sum_iovec_len(copy));
+ sum_iovec_len(©));
#endif
len = writev(net_poll[NET_FD_TUN].fd,
copy.iov, copy.iovcnt);
@@ -814,7 +814,7 @@ virtio_console(void *arg)
len = readv(pty_fd, copy.iov, copy.iovcnt);
if (len > 0) {
#ifdef DEBUG
- disp_iovec(mic, copy, __func__, __LINE__);
+ disp_iovec(mic, ©, __func__, __LINE__);
mpsslog("%s %s %d read from tap 0x%lx\n",
mic->name, __func__, __LINE__,
len);
@@ -834,10 +834,10 @@ virtio_console(void *arg)
if (!err)
verify_out_len(mic, ©);
#ifdef DEBUG
- disp_iovec(mic, copy, __func__, __LINE__);
+ disp_iovec(mic, ©, __func__, __LINE__);
mpsslog("%s %s %d wrote to net 0x%lx\n",
mic->name, __func__, __LINE__,
- sum_iovec_len(copy));
+ sum_iovec_len(©));
#endif
/* Reinitialize IOV for next run */
iov0->iov_len = PAGE_SIZE;
@@ -866,12 +866,12 @@ virtio_console(void *arg)
iov1->iov_len = copy.out_len;
verify_out_len(mic, ©);
#ifdef DEBUG
- disp_iovec(mic, copy, __func__,
+ disp_iovec(mic, ©, __func__,
__LINE__);
mpsslog("%s %s %d ",
mic->name, __func__, __LINE__);
mpsslog("read from net 0x%lx\n",
- sum_iovec_len(copy));
+ sum_iovec_len(©));
#endif
len = writev(pty_fd,
copy.iov, copy.iovcnt);
@@ -883,7 +883,7 @@ virtio_console(void *arg)
sum_iovec_len(©));
} else {
#ifdef DEBUG
- disp_iovec(mic, copy, __func__,
+ disp_iovec(mic, ©, __func__,
__LINE__);
mpsslog("%s %s %d ",
mic->name, __func__,
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH V2 2/4] misc: vop: build VOP based on CONFIG_VOP
2020-09-29 9:11 [PATCH V2 0/4] Fix some bugs of the vop driver and mpssd user space tool Sherry Sun
2020-09-29 9:11 ` [PATCH V2 1/4] samples: mpssd: fix the build errors when enable DEBUG Sherry Sun
@ 2020-09-29 9:11 ` Sherry Sun
2020-09-29 9:11 ` [PATCH V2 3/4] misc: vop: add round_up(x,4) for vring_size to avoid kernel panic Sherry Sun
2020-09-29 9:11 ` [PATCH V2 4/4] mic: vop: copy data to kernel space then write to io memory Sherry Sun
3 siblings, 0 replies; 5+ messages in thread
From: Sherry Sun @ 2020-09-29 9:11 UTC (permalink / raw)
To: sudeep.dutt, ashutosh.dixit, arnd, gregkh; +Cc: linux-kernel, linux-imx
Build module or builtin VOP based on CONFIG_VOP macro.
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
---
drivers/misc/mic/vop/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/mic/vop/Makefile b/drivers/misc/mic/vop/Makefile
index 579da3868c8e..51b9b0022786 100644
--- a/drivers/misc/mic/vop/Makefile
+++ b/drivers/misc/mic/vop/Makefile
@@ -3,7 +3,7 @@
# Makefile - Intel MIC Linux driver.
# Copyright(c) 2016, Intel Corporation.
#
-obj-m := vop.o
+obj-$(CONFIG_VOP) := vop.o
vop-objs += vop_main.o
vop-objs += vop_debugfs.o
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH V2 3/4] misc: vop: add round_up(x,4) for vring_size to avoid kernel panic
2020-09-29 9:11 [PATCH V2 0/4] Fix some bugs of the vop driver and mpssd user space tool Sherry Sun
2020-09-29 9:11 ` [PATCH V2 1/4] samples: mpssd: fix the build errors when enable DEBUG Sherry Sun
2020-09-29 9:11 ` [PATCH V2 2/4] misc: vop: build VOP based on CONFIG_VOP Sherry Sun
@ 2020-09-29 9:11 ` Sherry Sun
2020-09-29 9:11 ` [PATCH V2 4/4] mic: vop: copy data to kernel space then write to io memory Sherry Sun
3 siblings, 0 replies; 5+ messages in thread
From: Sherry Sun @ 2020-09-29 9:11 UTC (permalink / raw)
To: sudeep.dutt, ashutosh.dixit, arnd, gregkh; +Cc: linux-kernel, linux-imx
Since struct _mic_vring_info and vring are allocated together and follow
vring, if the vring_size() is not four bytes aligned, which will cause
the start address of struct _mic_vring_info is not four byte aligned.
For example, when vring entries is 128, the vring_size() will be 5126
bytes. The _mic_vring_info struct layout in ddr looks like:
0x90002400: 00000000 00390000 EE010000 0000C0FF
Here 0x39 is the avail_idx member, and 0xC0FFEE01 is the magic member.
When EP use ioread32(magic) to reads the magic in RC's share memory, it
will cause kernel panic on ARM64 platform due to the cross-byte io read.
Here read magic in user space use le32toh(vr0->info->magic) will meet
the same issue.
So add round_up(x,4) for vring_size, then the struct _mic_vring_info
will store in this way:
0x90002400: 00000000 00000000 00000039 C0FFEE01
Which will avoid kernel panic when read magic in struct _mic_vring_info.
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 | 2 +-
drivers/misc/mic/vop/vop_vringh.c | 4 ++--
samples/mic/mpssd/mpssd.c | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/misc/mic/vop/vop_main.c b/drivers/misc/mic/vop/vop_main.c
index 55e7f21e51f4..6722c726b259 100644
--- a/drivers/misc/mic/vop/vop_main.c
+++ b/drivers/misc/mic/vop/vop_main.c
@@ -320,7 +320,7 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev,
/* First assign the vring's allocated in host memory */
vqconfig = _vop_vq_config(vdev->desc) + index;
memcpy_fromio(&config, vqconfig, sizeof(config));
- _vr_size = vring_size(le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN);
+ _vr_size = round_up(vring_size(le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN), 4);
vr_size = PAGE_ALIGN(_vr_size + sizeof(struct _mic_vring_info));
va = vpdev->hw_ops->remap(vpdev, le64_to_cpu(config.address), vr_size);
if (!va)
diff --git a/drivers/misc/mic/vop/vop_vringh.c b/drivers/misc/mic/vop/vop_vringh.c
index 30eac172f017..45fdb394de11 100644
--- a/drivers/misc/mic/vop/vop_vringh.c
+++ b/drivers/misc/mic/vop/vop_vringh.c
@@ -296,7 +296,7 @@ static int vop_virtio_add_device(struct vop_vdev *vdev,
num = le16_to_cpu(vqconfig[i].num);
mutex_init(&vvr->vr_mutex);
- vr_size = PAGE_ALIGN(vring_size(num, MIC_VIRTIO_RING_ALIGN) +
+ 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,
@@ -308,7 +308,7 @@ static int vop_virtio_add_device(struct vop_vdev *vdev,
goto err;
}
vr->len = vr_size;
- vr->info = vr->va + vring_size(num, MIC_VIRTIO_RING_ALIGN);
+ 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);
diff --git a/samples/mic/mpssd/mpssd.c b/samples/mic/mpssd/mpssd.c
index 51d03545869e..c03a05d498f0 100644
--- a/samples/mic/mpssd/mpssd.c
+++ b/samples/mic/mpssd/mpssd.c
@@ -403,9 +403,9 @@ mic_virtio_copy(struct mic_info *mic, int fd,
static inline unsigned _vring_size(unsigned int num, unsigned long align)
{
- return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (3 + num)
+ return _ALIGN_UP(((sizeof(struct vring_desc) * num + sizeof(__u16) * (3 + num)
+ align - 1) & ~(align - 1))
- + sizeof(__u16) * 3 + sizeof(struct vring_used_elem) * num;
+ + sizeof(__u16) * 3 + sizeof(struct vring_used_elem) * num, 4);
}
/*
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH V2 4/4] mic: vop: copy data to kernel space then write to io memory
2020-09-29 9:11 [PATCH V2 0/4] Fix some bugs of the vop driver and mpssd user space tool Sherry Sun
` (2 preceding siblings ...)
2020-09-29 9:11 ` [PATCH V2 3/4] misc: vop: add round_up(x,4) for vring_size to avoid kernel panic Sherry Sun
@ 2020-09-29 9:11 ` Sherry Sun
3 siblings, 0 replies; 5+ messages in thread
From: Sherry Sun @ 2020-09-29 9:11 UTC (permalink / raw)
To: sudeep.dutt, ashutosh.dixit, arnd, gregkh; +Cc: linux-kernel, linux-imx
Read and write io memory should address align on ARCH ARM. Change to use
memcpy_toio to avoid kernel panic caused by the address un-align issue.
Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
drivers/misc/mic/vop/vop_vringh.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/misc/mic/vop/vop_vringh.c b/drivers/misc/mic/vop/vop_vringh.c
index 45fdb394de11..7014ffe88632 100644
--- a/drivers/misc/mic/vop/vop_vringh.c
+++ b/drivers/misc/mic/vop/vop_vringh.c
@@ -602,6 +602,7 @@ static int vop_virtio_copy_from_user(struct vop_vdev *vdev, void __user *ubuf,
size_t partlen;
bool dma = VOP_USE_DMA && vi->dma_ch;
int err = 0;
+ size_t offset = 0;
if (dma) {
dma_alignment = 1 << vi->dma_ch->device->copy_align;
@@ -655,13 +656,20 @@ static int vop_virtio_copy_from_user(struct vop_vdev *vdev, void __user *ubuf,
* We are copying to IO below and should ideally use something
* like copy_from_user_toio(..) if it existed.
*/
- if (copy_from_user((void __force *)dbuf, ubuf, len)) {
- err = -EFAULT;
- dev_err(vop_dev(vdev), "%s %d err %d\n",
- __func__, __LINE__, err);
- goto err;
+ while (len) {
+ partlen = min_t(size_t, len, VOP_INT_DMA_BUF_SIZE);
+
+ if (copy_from_user(vvr->buf, ubuf + offset, partlen)) {
+ err = -EFAULT;
+ dev_err(vop_dev(vdev), "%s %d err %d\n",
+ __func__, __LINE__, err);
+ goto err;
+ }
+ memcpy_toio(dbuf + offset, vvr->buf, partlen);
+ offset += partlen;
+ vdev->out_bytes += partlen;
+ len -= partlen;
}
- vdev->out_bytes += len;
err = 0;
err:
vpdev->hw_ops->unmap(vpdev, dbuf);
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-09-29 9:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-29 9:11 [PATCH V2 0/4] Fix some bugs of the vop driver and mpssd user space tool Sherry Sun
2020-09-29 9:11 ` [PATCH V2 1/4] samples: mpssd: fix the build errors when enable DEBUG Sherry Sun
2020-09-29 9:11 ` [PATCH V2 2/4] misc: vop: build VOP based on CONFIG_VOP Sherry Sun
2020-09-29 9:11 ` [PATCH V2 3/4] misc: vop: add round_up(x,4) for vring_size to avoid kernel panic Sherry Sun
2020-09-29 9:11 ` [PATCH V2 4/4] mic: vop: copy data to kernel space then write to io memory Sherry Sun
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®