mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dongli Zhang <dongli.zhang@oracle.com>
To: Jason Wang <jasowang@redhat.com>
Cc: virtualization@lists.linux.dev, kvm@vger.kernel.org,
	netdev@vger.kernel.org, mst@redhat.com,
	michael.christie@oracle.com, pbonzini@redhat.com,
	stefanha@redhat.com, eperezma@redhat.com,
	joao.m.martins@oracle.com, joe.jin@oracle.com,
	si-wei.liu@oracle.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 04/10] vhost: modify vhost_log_write() for broader users
Date: Wed, 19 Mar 2025 09:38:17 -0700	[thread overview]
Message-ID: <93797957-b23c-4861-a755-28bfc506051f@oracle.com> (raw)
In-Reply-To: <CACGkMEtOsQg68O+Nqo9ycLSq7sN4AMZ92ZvLLMEF7xYDCA5Ycw@mail.gmail.com>

Hi Jason,

On 3/17/25 6:12 PM, Jason Wang wrote:
> On Tue, Mar 18, 2025 at 7:51 AM Dongli Zhang <dongli.zhang@oracle.com> wrote:
>>
>> Currently, the only user of vhost_log_write() is vhost-net. The 'len'
>> argument prevents logging of pages that are not tainted by the RX path.
>>
>> Adjustments are needed since more drivers (i.e. vhost-scsi) begin using
>> vhost_log_write(). So far vhost-net RX path may only partially use pages
>> shared by the last vring descriptor. Unlike vhost-net, vhost-scsi always
>> logs all pages shared via vring descriptors. To accommodate this, a new
>> argument 'partial' is introduced. This argument works alongside 'len' to
>> indicate whether the driver should log all pages of a vring descriptor, or
>> only pages that are tainted by the driver.
>>
>> In addition, removes BUG().
>>
>> Suggested-by: Joao Martins <joao.m.martins@oracle.com>
>> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
>> ---
>>  drivers/vhost/net.c   |  2 +-
>>  drivers/vhost/vhost.c | 28 +++++++++++++++++-----------
>>  drivers/vhost/vhost.h |  2 +-
>>  3 files changed, 19 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
>> index b9b9e9d40951..0e5d82bfde76 100644
>> --- a/drivers/vhost/net.c
>> +++ b/drivers/vhost/net.c
>> @@ -1219,7 +1219,7 @@ static void handle_rx(struct vhost_net *net)
>>                 if (nvq->done_idx > VHOST_NET_BATCH)
>>                         vhost_net_signal_used(nvq);
>>                 if (unlikely(vq_log))
>> -                       vhost_log_write(vq, vq_log, log, vhost_len,
>> +                       vhost_log_write(vq, vq_log, log, vhost_len, true,
>>                                         vq->iov, in);
>>                 total_len += vhost_len;
>>         } while (likely(!vhost_exceeds_weight(vq, ++recv_pkts, total_len)));
>> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
>> index 9ac25d08f473..db3b30aba940 100644
>> --- a/drivers/vhost/vhost.c
>> +++ b/drivers/vhost/vhost.c
>> @@ -2304,8 +2304,14 @@ static int log_used(struct vhost_virtqueue *vq, u64 used_offset, u64 len)
>>         return 0;
>>  }
>>
>> -int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
>> -                   unsigned int log_num, u64 len, struct iovec *iov, int count)
>> +/*
>> + * 'len' is used only when 'partial' is true, to indicate whether the
>> + * entire length of each descriptor is logged.
>> + */
> 
> While at it, let's document all the parameters here.

Sure.

> 
>> +int vhost_log_write(struct vhost_virtqueue *vq,
>> +                   struct vhost_log *log, unsigned int log_num,
>> +                   u64 len, bool partial,
>> +                   struct iovec *iov, int count)
>>  {
>>         int i, r;
>>
>> @@ -2323,19 +2329,19 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
>>         }
>>
>>         for (i = 0; i < log_num; ++i) {
>> -               u64 l = min(log[i].len, len);
>> +               u64 l = partial ? min(log[i].len, len) : log[i].len;
>> +
>>                 r = log_write(vq->log_base, log[i].addr, l);
>>                 if (r < 0)
>>                         return r;
>> -               len -= l;
>> -               if (!len) {
>> -                       if (vq->log_ctx)
>> -                               eventfd_signal(vq->log_ctx);
>> -                       return 0;
>> -               }
>> +
>> +               if (partial)
>> +                       len -= l;
> 
> I wonder if it's simpler to just tweak the caller to call with the
> correct len (or probably U64_MAX) in this case?

To "tweak the caller to call with the correct len" may need to sum the length
of all log[i].

Regarding U64_MAX, would you like something below? That is, only use 'len'
when it isn't U64_MAX.

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 9ac25d08f473..5b49de05e752 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2327,15 +2327,14 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
 		r = log_write(vq->log_base, log[i].addr, l);
 		if (r < 0)
 			return r;
-		len -= l;
-		if (!len) {
-			if (vq->log_ctx)
-				eventfd_signal(vq->log_ctx);
-			return 0;
-		}
+
+		if (len != U64_MAX) ---> It is impossible to have len = U64_MAX from vhost-net
+			len -= l;        How about keeping those two lines?
 	}
-	/* Length written exceeds what we have stored. This is a bug. */
-	BUG();
+
+	if (vq->log_ctx)
+		eventfd_signal(vq->log_ctx);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(vhost_log_write);


Thank you very much!

Dongli Zhang


  reply	other threads:[~2025-03-19 16:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-17 23:55 [PATCH v2 00/10] vhost-scsi: log write descriptors for live migration (and three bugfix) Dongli Zhang
2025-03-17 23:55 ` [PATCH v2 01/10] vhost-scsi: protect vq->log_used with vq->mutex Dongli Zhang
2025-03-18  0:47   ` Jason Wang
2025-03-26 22:22   ` Mike Christie
2025-03-17 23:55 ` [PATCH v2 02/10] vhost-scsi: Fix vhost_scsi_send_bad_target() Dongli Zhang
2025-03-18  0:48   ` Jason Wang
2025-03-26 22:25   ` Mike Christie
2025-03-17 23:55 ` [PATCH v2 03/10] vhost-scsi: Fix vhost_scsi_send_status() Dongli Zhang
2025-03-18  0:48   ` Jason Wang
2025-03-19 17:54     ` Dongli Zhang
2025-03-20  1:42       ` Jason Wang
2025-03-26 22:27   ` Mike Christie
2025-03-17 23:55 ` [PATCH v2 04/10] vhost: modify vhost_log_write() for broader users Dongli Zhang
2025-03-18  1:12   ` Jason Wang
2025-03-19 16:38     ` Dongli Zhang [this message]
2025-03-20  1:41       ` Jason Wang
2025-03-17 23:55 ` [PATCH v2 05/10] vhost-scsi: adjust vhost_scsi_get_desc() to log vring descriptors Dongli Zhang
2025-03-26 23:21   ` Mike Christie
2025-03-17 23:55 ` [PATCH v2 06/10] vhost-scsi: cache log buffer in I/O queue vhost_scsi_cmd Dongli Zhang
2025-03-18  0:04   ` Dongli Zhang
2025-03-26 23:37     ` Mike Christie
2025-03-27 20:27       ` Dongli Zhang
2025-03-17 23:55 ` [PATCH v2 07/10] vhost-scsi: log I/O queue write descriptors Dongli Zhang
2025-03-17 23:55 ` [PATCH v2 08/10] vhost-scsi: log control " Dongli Zhang
2025-03-17 23:55 ` [PATCH v2 09/10] vhost-scsi: log event " Dongli Zhang
2025-03-26 23:50   ` Mike Christie
2025-03-26 23:51   ` Mike Christie
2025-03-17 23:55 ` [PATCH v2 10/10] vhost: add WARNING if log_num is more than limit Dongli Zhang

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=93797957-b23c-4861-a755-28bfc506051f@oracle.com \
    --to=dongli.zhang@oracle.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=joao.m.martins@oracle.com \
    --cc=joe.jin@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.christie@oracle.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=si-wei.liu@oracle.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    /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®