From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eric Farman <farman@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PULL 16/41] block: Fix target variable of BLKSECTGET ioctl
Date: Fri, 27 Jan 2017 14:45:24 +0100 [thread overview]
Message-ID: <1485524749-118532-17-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1485524749-118532-1-git-send-email-pbonzini@redhat.com>
From: Eric Farman <farman@linux.vnet.ibm.com>
Commit 6f6071745bd0 ("raw-posix: Fetch max sectors for host block device")
introduced a routine to call the kernel BLKSECTGET ioctl, which stores the
result back to user space. However, the size of the data returned depends
on the routine handling the ioctl. The (compat_)blkdev_ioctl returns a
short, while sg_ioctl returns an int. Thus, on big-endian systems, we can
find ourselves accidentally shifting the result to a much larger value.
(On s390x, a short is 16 bits while an int is 32 bits.)
Also, the two ioctl handlers return values in different scales (block
returns sectors, while sg returns bytes), so some tweaking of the outputs
is required such that hdev_get_max_transfer_length returns a value in a
consistent set of units.
Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com>
Message-Id: <20170120162527.66075-3-farman@linux.vnet.ibm.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
block/file-posix.c | 17 ++++++++++-------
include/block/block.h | 1 +
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 28b47d9..9f83725 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -651,12 +651,15 @@ static void raw_reopen_abort(BDRVReopenState *state)
state->opaque = NULL;
}
-static int hdev_get_max_transfer_length(int fd)
+static int hdev_get_max_transfer_length(BlockDriverState *bs, int fd)
{
#ifdef BLKSECTGET
- int max_sectors = 0;
- if (ioctl(fd, BLKSECTGET, &max_sectors) == 0) {
- return max_sectors;
+ int max_bytes = 0;
+ short max_sectors = 0;
+ if (bs->sg && ioctl(fd, BLKSECTGET, &max_bytes) == 0) {
+ return max_bytes;
+ } else if (!bs->sg && ioctl(fd, BLKSECTGET, &max_sectors) == 0) {
+ return max_sectors << BDRV_SECTOR_BITS;
} else {
return -errno;
}
@@ -672,9 +675,9 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
if (!fstat(s->fd, &st)) {
if (S_ISBLK(st.st_mode)) {
- int ret = hdev_get_max_transfer_length(s->fd);
- if (ret > 0 && ret <= BDRV_REQUEST_MAX_SECTORS) {
- bs->bl.max_transfer = pow2floor(ret << BDRV_SECTOR_BITS);
+ int ret = hdev_get_max_transfer_length(bs, s->fd);
+ if (ret > 0 && ret <= BDRV_REQUEST_MAX_BYTES) {
+ bs->bl.max_transfer = pow2floor(ret);
}
}
}
diff --git a/include/block/block.h b/include/block/block.h
index 8b0dcda..4e81f20 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -116,6 +116,7 @@ typedef struct HDGeometry {
#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \
INT_MAX >> BDRV_SECTOR_BITS)
+#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS)
/*
* Allocation status flags
--
1.8.3.1
next prev parent reply other threads:[~2017-01-27 13:46 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-27 13:45 [Qemu-devel] [PULL 00/41] Misc changes for 2017-01-27 Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 01/41] icount: update instruction counter on apic patching Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 02/41] replay: improve interrupt handling Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 03/41] replay: don't use rtc clock on loadvm phase Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 04/41] savevm: add public save_vmstate function Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 05/41] replay: save/load initial state Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 06/41] replay: exception replay fix Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 07/41] apic: save apic_delivered flag Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 08/41] memory: tune mtree_print_mr() to dump mr type Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 09/41] memory: hmp: add "-f" for "info mtree" Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 10/41] hw/isa/lpc_ich9: add SMI feature negotiation via fw_cfg Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 11/41] hw/isa/lpc_ich9: add broadcast SMI feature Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 12/41] hw/isa/lpc_ich9: negotiate SMI broadcast on pc-q35-2.9+ machine types Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 13/41] block/iscsi: avoid data corruption with cache=writeback Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 14/41] Introduce DEVICE_CATEGORY_CPU for CPU devices Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 15/41] hw/scsi: Fix debug message of cdb structure in scsi-generic Paolo Bonzini
2017-01-27 13:45 ` Paolo Bonzini [this message]
2017-01-27 13:45 ` [Qemu-devel] [PULL 17/41] block: get max_transfer limit for char (scsi-generic) devices Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 18/41] x86-KVM: Supply TSC and APIC clock rates to guest like VMWare Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 19/41] pc: Enable vmware-cpuid-freq CPU option for 2.9+ machine types Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 20/41] block/iscsi: statically link qemu_iscsi_opts Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 21/41] tests: fix linking test-char on win32 Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 22/41] qemu-options: stdio is available " Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 23/41] char: add qemu_chr_fe_add_watch() Returns description Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 24/41] doc: fix spelling Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 25/41] char: use a const CharDriver Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 26/41] char: use a static array for backends Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 27/41] char: move callbacks in CharDriver Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 28/41] char: fold single-user functions in caller Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 29/41] char: introduce generic qemu_chr_get_kind() Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 30/41] char: use a feature bit for replay Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 31/41] char: allocate CharDriverState as a single object Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 32/41] bt: use qemu_chr_alloc() Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 33/41] char: rename CharDriverState Chardev Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 34/41] char: rename TCPChardev and NetChardev Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 35/41] spice-char: improve error reporting Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 36/41] char: use error_report() Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 37/41] gtk: overwrite the console.c char driver Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 38/41] baum: use a common prefix for chr callbacks Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 39/41] vc: " Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 40/41] chardev: qom-ify Paolo Bonzini
2017-01-27 13:45 ` [Qemu-devel] [PULL 41/41] memory: don't sign-extend 32-bit writes Paolo Bonzini
2017-01-27 16:58 ` [Qemu-devel] [PULL 00/41] Misc changes for 2017-01-27 Peter Maydell
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=1485524749-118532-17-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=farman@linux.vnet.ibm.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).