qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Temir Zharaspayev <masscry@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Xie Yongji <xieyongji@bytedance.com>,
	Temir Zharaspayev <masscry@gmail.com>
Subject: [PATCH 1/2] libvhost-user: Fix pointer arithmetic in indirect read
Date: Sat, 13 Jan 2024 04:27:40 +0300	[thread overview]
Message-ID: <20240113012741.54664-2-masscry@gmail.com> (raw)
In-Reply-To: <20240113012741.54664-1-masscry@gmail.com>

When zero-copy usage of indirect descriptors buffer table isn't
possible, library gather scattered memory chunks in a local copy.
This commit fixes the issue with pointer arithmetic for the local copy
buffer.

Signed-off-by: Temir Zharaspayev <masscry@gmail.com>
---
 subprojects/libvhost-user/libvhost-user.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
index 6684057370..e952c098a3 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -2307,7 +2307,7 @@ static int
 virtqueue_read_indirect_desc(VuDev *dev, struct vring_desc *desc,
                              uint64_t addr, size_t len)
 {
-    struct vring_desc *ori_desc;
+    uint8_t *src_cursor, *dst_cursor;
     uint64_t read_len;
 
     if (len > (VIRTQUEUE_MAX_SIZE * sizeof(struct vring_desc))) {
@@ -2318,17 +2318,18 @@ virtqueue_read_indirect_desc(VuDev *dev, struct vring_desc *desc,
         return -1;
     }
 
+    dst_cursor = (uint8_t *) desc;
     while (len) {
         read_len = len;
-        ori_desc = vu_gpa_to_va(dev, &read_len, addr);
-        if (!ori_desc) {
+        src_cursor = vu_gpa_to_va(dev, &read_len, addr);
+        if (!src_cursor) {
             return -1;
         }
 
-        memcpy(desc, ori_desc, read_len);
+        memcpy(dst_cursor, src_cursor, read_len);
         len -= read_len;
         addr += read_len;
-        desc += read_len;
+        dst_cursor += read_len;
     }
 
     return 0;
-- 
2.34.1



  reply	other threads:[~2024-01-13  1:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-13  1:27 [PATCH 0/2] Fix pointer arithmetic in indirect read for libvhost-user and libvduse Temir Zharaspayev
2024-01-13  1:27 ` Temir Zharaspayev [this message]
2024-04-18 13:55   ` [PATCH 1/2] libvhost-user: Fix pointer arithmetic in indirect read Daniel P. Berrangé
2024-04-18 23:12     ` Raphael Norwitz
2024-01-13  1:27 ` [PATCH 2/2] libvduse: " Temir Zharaspayev
2024-02-04  9:41 ` [PATCH 0/2] Fix pointer arithmetic in indirect read for libvhost-user and libvduse Тимур
2024-04-18 12:19   ` Peter Maydell
2024-04-18 13:57   ` Daniel P. Berrangé

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=20240113012741.54664-2-masscry@gmail.com \
    --to=masscry@gmail.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xieyongji@bytedance.com \
    /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).