From nobody Tue Dec 16 07:06:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520981585761409.8679684145908; Tue, 13 Mar 2018 15:53:05 -0700 (PDT) Received: from localhost ([::1]:43298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evsmm-0000zb-Mn for importer@patchew.org; Tue, 13 Mar 2018 18:52:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evshc-0005M0-Hn for qemu-devel@nongnu.org; Tue, 13 Mar 2018 18:47:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evshb-0002iL-HZ for qemu-devel@nongnu.org; Tue, 13 Mar 2018 18:47:28 -0400 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]:34287) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evshb-0002ha-BZ for qemu-devel@nongnu.org; Tue, 13 Mar 2018 18:47:27 -0400 Received: by mail-wr0-x22a.google.com with SMTP id o8so2597588wra.1 for ; Tue, 13 Mar 2018 15:47:27 -0700 (PDT) Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it. [94.36.191.219]) by smtp.gmail.com with ESMTPSA id x107sm1557951wrb.97.2018.03.13.15.47.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Mar 2018 15:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=F+xEpHrU6Z+I42OD0RSwChBmw4eawrXdlAv7SajXprs=; b=S6A7ncepD+RevD37ujM1bNAbUO+p/Ax2vvzkZbtVztBcxX3WpJ3RxrAQQSn0yanxZh BCKRwwQYHF/+MNGQC1lwiNllLBgvaclqW475Orzs0D7eiFPWH8RYdZ9Xc/GLgsoq07v0 iggwSqV3kHxlF7W0oElzDO1itEsG6+FC40n0QN5PxsFyrWaRfDsV43n/dukXaIwGrNHI IRWLSd5duWNACXllKRoqEj5DLPFZzGNRbAzlhUlAoju6LgWP2SkQfbhI7CEesKDnRglP N0/TgbnA9DOWxIa3k9ojyd4NRj77tbhHk3Vrz5csgAY8t16D3tJR+OENzWlHvV84Pq2Y SSQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=F+xEpHrU6Z+I42OD0RSwChBmw4eawrXdlAv7SajXprs=; b=sC48GF2YXwHoSdiltJNAzjWxswm5ZHSrgMTqXI6lonUpaHcT4LmlppAShKeQr2upVR ALyWGJiS9tur9qaz1GU2snGvfe8IIuxS6213wtxEg+9kYO1HpYSKDR+Th/uki2RNIXVx Dh5j8tAfvK/zBPMNcw9Lu9++DbLMzx8IETle85sisSHPuWDAoyPStHP73tS8cFoxMuzW QMCGimETVW5AHewrDvmGJHIPsak7irDZYVZcparWsOAo6mdbGQuEoYLXmnujlFv1H4nL jqtInjl/gPbF5U6vDN78C0REE245pVKxWuHFR8Qf/Iku+z6mF3T8efWbSkbF9+76uWD3 bZCg== X-Gm-Message-State: AElRT7F76wtuYv5bv/Eiy92Ig18TQvqE7UYIXOUMrnGK4E9exDGaLLBb CAwdYerz9vOyQYNwRcdXVq3f98Rg X-Google-Smtp-Source: AG47ELvwrRcdXqYdalMM3uM+y/DBJveOpOktSVnwyApaxI1rVl/N59cLPYLI4pO/jGoflhYMr47L2A== X-Received: by 10.223.164.138 with SMTP id g10mr1826743wrb.74.1520981245916; Tue, 13 Mar 2018 15:47:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 23:46:14 +0100 Message-Id: <20180313224719.4954-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313224719.4954-1-pbonzini@redhat.com> References: <20180313224719.4954-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22a Subject: [Qemu-devel] [PULL 04/69] scsi-disk.c: consider bl->max_transfer in INQUIRY emulation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza The calculation of the max_transfer atribute of BlockDriverState makes considerations such as max_segments and transfer_length via the BLKSECTGET ioctl (if available). However, bl->max_transfer isn't considered when emulating the INQUIRY 'Block Limit' response to the scsi-hd devices. This leads to situations where the declared max_sectors from the INQUIRY response is inconsistent with the block limits, which isn't ideal. It can also be misleading to the user that sets /sys/block//queue/max_sectors_kb to a certain value, then finds a different value in the guest OS for the same disk. Following the same logic scsi_read_complete from scsi-generic.c does when patching the response of the Block Limits VPD back to the guest, change the max_io_sectors value of the emulated Block Limits VPD response by considering the blk_get_max_transfer of the related BlockDriverState. Use MIN_NOT_ZERO to be sure that the minimal value is chosen. Given that we're changing max_io_sectors, consider that min_io_sectors and opt_io_sectors can't be greater than the new calculated value. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Fam Zheng Message-Id: <20180306154411.18462-1-danielhb@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-disk.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 49d2559d93..c65c1ce56d 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -704,6 +704,21 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req,= uint8_t *outbuf) page_code); return -1; } + if (s->qdev.type =3D=3D TYPE_DISK) { + int max_transfer_blk =3D blk_get_max_transfer(s->qdev.conf= .blk); + int max_io_sectors_blk =3D + max_transfer_blk / s->qdev.blocksize; + + max_io_sectors =3D + MIN_NON_ZERO(max_io_sectors_blk, max_io_sectors); + + /* min_io_size and opt_io_size can't be greater than + * max_io_sectors */ + min_io_size =3D + MIN_NON_ZERO(min_io_size, max_io_sectors); + opt_io_size =3D + MIN_NON_ZERO(opt_io_size, max_io_sectors); + } /* required VPD size with unmap support */ buflen =3D 0x40; memset(outbuf + 4, 0, buflen - 4); --=20 2.14.3