From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH 3/9] pvscsi: check validity of DMA addresses in advance
Date: Mon, 6 Jun 2011 18:26:54 +0200 [thread overview]
Message-ID: <1307377620-7538-4-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1307377620-7538-1-git-send-email-pbonzini@redhat.com>
This also depends on the cpu_physical_memory_map_fast series, so I'm
keeping it separated.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/vmw_pvscsi.c | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/hw/vmw_pvscsi.c b/hw/vmw_pvscsi.c
index 6f0b0b9..84bcfe6 100644
--- a/hw/vmw_pvscsi.c
+++ b/hw/vmw_pvscsi.c
@@ -383,6 +383,35 @@ static void pvscsi_transfer_data_with_sg_list(PVSCSIRequest *p, bool to_host,
}
}
+static bool pvscsi_check_sg_list_addresses(PVSCSIRequest *p)
+{
+ uint64_t len = p->req.dataLen;
+ uint64_t n;
+ PVSCSISGState sg = { .elemAddr = p->req.dataAddr };
+ while (len) {
+ while (!sg.resid) {
+ pvscsi_get_next_sg_elem(&sg);
+ }
+ n = MIN(len, sg.resid);
+ if (!cpu_physical_memory_map_check(sg.dataAddr, n)) {
+ return false;
+ }
+
+ len -= n;
+ sg.resid -= n;
+ }
+ return true;
+}
+
+static bool pvscsi_check_addresses(PVSCSIRequest *p)
+{
+ if (p->req.flags & PVSCSI_FLAG_CMD_WITH_SG_LIST) {
+ return pvscsi_check_sg_list_addresses(p);
+ } else {
+ return cpu_physical_memory_map_check(p->req.dataAddr, p->req.dataLen);
+ }
+}
+
/* Callback to indicate that the SCSI layer has completed a transfer. */
static void pvscsi_transfer_data(SCSIRequest *req, uint32_t len)
{
@@ -487,6 +516,12 @@ static void pvscsi_process_req(PVSCSIState *s, struct PVSCSIRingReqDesc *r)
return;
}
+ if (!pvscsi_check_addresses(p)) {
+ p->cmp.hostStatus = BTSTAT_DATARUN;
+ pvscsi_complete_req(s, p);
+ return;
+ }
+
if (r->flags & PVSCSI_FLAG_CMD_WITH_SG_LIST) {
p->sg.elemAddr = r->dataAddr;
}
--
1.7.4.4
next prev parent reply other threads:[~2011-06-06 16:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-06 16:26 [Qemu-devel] [RFC PATCH 0/9] scsi: support s/g operation without a bounce buffer Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 1/9] make qbus_reset_all public Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 2/9] pvscsi: first commit Paolo Bonzini
2011-06-06 16:26 ` Paolo Bonzini [this message]
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 4/9] scsi: always use get_sense Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 5/9] scsi-disk: lazily allocate bounce buffer Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 6/9] allow switching a qiov between internal and external storage Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 7/9] scsi: push qiov to SCSIRequest Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 8/9] scsi: add get_iovec/unmap_iovec to SCSIBusOps Paolo Bonzini
2011-06-06 16:27 ` [Qemu-devel] [RFC PATCH 9/9] pvscsi: implement s/g operation without a bounce buffer Paolo Bonzini
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=1307377620-7538-4-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).