From: Dongli Zhang <dongli.zhang@oracle.com>
To: virtualization@lists.linux.dev, netdev@vger.kernel.org,
kvm@vger.kernel.org
Cc: mst@redhat.com, jasowang@redhat.com, eperezma@redhat.com,
michael.christie@oracle.com, pbonzini@redhat.com,
stefanha@redhat.com, joao.m.martins@oracle.com,
joe.jin@oracle.com, si-wei.liu@oracle.com,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/9] vhost-scsi: cache log buffer in I/O queue vhost_scsi_cmd
Date: Fri, 7 Feb 2025 10:41:47 -0800 [thread overview]
Message-ID: <20250207184212.20831-4-dongli.zhang@oracle.com> (raw)
In-Reply-To: <20250207184212.20831-1-dongli.zhang@oracle.com>
The vhost-scsi I/O queue uses vhost_scsi_cmd. Pre-allocate the log buffer
during vhost_scsi_cmd allocation, and free it when vhost_scsi_cmd is
reclaimed.
The cached log buffer will be uses in upcoming patches to log write
descriptors for the I/O queue. The core idea is to cache the log in the
per-command log buffer in the submission path, and use them to log write
descriptors in the completion path.
Suggested-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
drivers/vhost/scsi.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index ee2310555740..5e6221cbbe9e 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -98,6 +98,11 @@ struct vhost_scsi_cmd {
unsigned char tvc_cdb[VHOST_SCSI_MAX_CDB_SIZE];
/* Sense buffer that will be mapped into outgoing status */
unsigned char tvc_sense_buf[TRANSPORT_SENSE_BUFFER];
+ /*
+ * Dirty write descriptors of this command.
+ */
+ struct vhost_log *tvc_log;
+ unsigned int tvc_log_num;
/* Completed commands list, serviced from vhost worker thread */
struct llist_node tvc_completion_list;
/* Used to track inflight cmd */
@@ -619,6 +624,7 @@ vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
struct vhost_scsi_nexus *tv_nexus;
struct scatterlist *sg, *prot_sg;
struct iovec *tvc_resp_iov;
+ struct vhost_log *log;
struct page **pages;
int tag;
@@ -639,6 +645,7 @@ vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
prot_sg = cmd->tvc_prot_sgl;
pages = cmd->tvc_upages;
tvc_resp_iov = cmd->tvc_resp_iov;
+ log = cmd->tvc_log;
memset(cmd, 0, sizeof(*cmd));
cmd->tvc_sgl = sg;
cmd->tvc_prot_sgl = prot_sg;
@@ -652,6 +659,7 @@ vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
cmd->tvc_nexus = tv_nexus;
cmd->inflight = vhost_scsi_get_inflight(vq);
cmd->tvc_resp_iov = tvc_resp_iov;
+ cmd->tvc_log = log;
memcpy(cmd->tvc_cdb, cdb, VHOST_SCSI_MAX_CDB_SIZE);
@@ -1604,6 +1612,7 @@ static void vhost_scsi_destroy_vq_cmds(struct vhost_virtqueue *vq)
kfree(tv_cmd->tvc_prot_sgl);
kfree(tv_cmd->tvc_upages);
kfree(tv_cmd->tvc_resp_iov);
+ kfree(tv_cmd->tvc_log);
}
sbitmap_free(&svq->scsi_tags);
@@ -1666,6 +1675,18 @@ static int vhost_scsi_setup_vq_cmds(struct vhost_virtqueue *vq, int max_cmds)
pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n");
goto out;
}
+
+ /*
+ * tv_cmd->tvc_log and vq->log need to have the same max
+ * length.
+ */
+ tv_cmd->tvc_log = kcalloc(vq->dev->iov_limit,
+ sizeof(struct vhost_log),
+ GFP_KERNEL);
+ if (!tv_cmd->tvc_log) {
+ pr_err("Unable to allocate tv_cmd->tvc_log\n");
+ goto out;
+ }
}
return 0;
out:
--
2.39.3
next prev parent reply other threads:[~2025-02-07 18:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 18:41 [PATCH 0/9] vhost-scsi: log write descriptors for live migration (and two bugfix) Dongli Zhang
2025-02-07 18:41 ` [PATCH 1/9] vhost: modify vhost_log_write() for broader users Dongli Zhang
2025-02-07 18:41 ` [PATCH 2/9] vhost-scsi: adjust vhost_scsi_get_desc() to log vring descriptors Dongli Zhang
2025-02-07 18:41 ` Dongli Zhang [this message]
2025-02-10 20:11 ` [PATCH 3/9] vhost-scsi: cache log buffer in I/O queue vhost_scsi_cmd Mike Christie
2025-02-07 18:41 ` [PATCH 4/9] vhost-scsi: log I/O queue write descriptors Dongli Zhang
2025-02-07 18:41 ` [PATCH 5/9] vhost-scsi: log control " Dongli Zhang
2025-02-12 1:08 ` Mike Christie
2025-02-07 18:41 ` [PATCH 6/9] vhost-scsi: log event " Dongli Zhang
2025-02-07 18:41 ` [PATCH 7/9] vhost: add WARNING if log_num is more than limit Dongli Zhang
2025-02-07 18:41 ` [PATCH 8/9] vhost-scsi: protect vq->log_used with vq->mutex Dongli Zhang
2025-02-07 18:41 ` [PATCH 9/9] vhost-scsi: Fix vhost_scsi_send_bad_target() Dongli Zhang
2025-02-21 18:03 ` [PATCH 0/9] vhost-scsi: log write descriptors for live migration (and two bugfix) 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=20250207184212.20831-4-dongli.zhang@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