From nobody Sun Feb 8 21:12:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1578597616; cv=none; d=zohomail.com; s=zohoarc; b=gH4R0lOYN6ouzzVXdU23LukzmN7emIHy+cSvVgTUxXMlkR0yUW8ZNqamHLMH38dStoNnPF7s7pHPOt9gM8vSz9RdPJJayDgrjgEf0UjrcsuFQLpkjtD762mG49bSBPlSWLJ6gG6n+XQrhDRaOskFxLSuPAXtXx+M0CblA0dRTk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578597616; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6r67467UjiAqot9W1R09uwC8mdguy5+C3Pq/7SaJD5A=; b=Yei0or2QJm3RKkGtnfnE9i9meRBbag+j/oBDNaq/7tc6bZTkrBV280iLe7So0r1dZV+x1zf8tLHlhXtJCTqR7Z+MCv43gzmwNWKSPJTFAYAaQEBcIjvwiuOpycljimCyLbhNHWn4yJ5O9QXkRyaH37IsYosq7ULyezMTxKynH3E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578597616696575.0985733091346; Thu, 9 Jan 2020 11:20:16 -0800 (PST) Received: from localhost ([::1]:36578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipdLr-0001AV-DQ for importer@patchew.org; Thu, 09 Jan 2020 14:20:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39313) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipdGC-0003WU-Sz for qemu-devel@nongnu.org; Thu, 09 Jan 2020 14:14:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipdGB-0007J7-ER for qemu-devel@nongnu.org; Thu, 09 Jan 2020 14:14:24 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:58341) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ipdG9-0006BD-G9; Thu, 09 Jan 2020 14:14:22 -0500 Received: from [213.99.255.143] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ipdFp-0006Mj-Pd; Thu, 09 Jan 2020 20:14:02 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1ipdF0-0005R2-ME; Thu, 09 Jan 2020 20:13:10 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=6r67467UjiAqot9W1R09uwC8mdguy5+C3Pq/7SaJD5A=; b=nGk0aEq+VtVTAwrWgDvpNupvGIQdop027e0P6jHZ7gAxxaWVagjKttPu44swwgqBgpIhcyGxkSvpC8fQxTtsjUdekl+tZuL7KKFwL16Dq+n8rzxyrSuFPvjcwsMRYTgUwKOOJJVWImHkKy/2w8r4O1EHpQ/9D2WQJjl03nRRmmpI9fojwtdu0pdf1CTCjviJb3A5unoQ8f4GSTipy2+LrxEEIn7rdLIsNCoFjdFSF8Pc1hliyALr3x6lM0LAuJQxbkskH8dKBYe9V6bXAmGV8qz1wVyVt/0czLR9GDWeGxsIywC6NHLsxapfNjHMo7VXb8ZzKvyBTobTTvbDwJDRmA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v2 2/4] qcow2: Don't round the L1 table allocation up to the sector size Date: Thu, 9 Jan 2020 20:13:00 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Nir Soffer Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The L1 table is read from disk using the byte-based bdrv_pread() and is never accessed beyond its last element, so there's no need to allocate more memory than that. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 5 ++--- block/qcow2-refcount.c | 2 +- block/qcow2-snapshot.c | 3 +-- block/qcow2.c | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 8982b7b762..932fc48919 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -124,12 +124,11 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_= t min_size, #endif =20 new_l1_size2 =3D sizeof(uint64_t) * new_l1_size; - new_l1_table =3D qemu_try_blockalign(bs->file->bs, - ROUND_UP(new_l1_size2, 512)); + new_l1_table =3D qemu_try_blockalign(bs->file->bs, new_l1_size2); if (new_l1_table =3D=3D NULL) { return -ENOMEM; } - memset(new_l1_table, 0, ROUND_UP(new_l1_size2, 512)); + memset(new_l1_table, 0, new_l1_size2); =20 if (s->l1_size) { memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t)); diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index f67ac6b2d8..c963bc8de1 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1262,7 +1262,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, * l1_table_offset when it is the current s->l1_table_offset! Be caref= ul * when changing this! */ if (l1_table_offset !=3D s->l1_table_offset) { - l1_table =3D g_try_malloc0(ROUND_UP(l1_size2, 512)); + l1_table =3D g_try_malloc0(l1_size2); if (l1_size2 && l1_table =3D=3D NULL) { ret =3D -ENOMEM; goto fail; diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 5ab64da1ec..82c32d4c9b 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -1024,8 +1024,7 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, return ret; } new_l1_bytes =3D sn->l1_size * sizeof(uint64_t); - new_l1_table =3D qemu_try_blockalign(bs->file->bs, - ROUND_UP(new_l1_bytes, 512)); + new_l1_table =3D qemu_try_blockalign(bs->file->bs, new_l1_bytes); if (new_l1_table =3D=3D NULL) { return -ENOMEM; } diff --git a/block/qcow2.c b/block/qcow2.c index 87ca2832f0..848a6c5182 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1499,7 +1499,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, =20 if (s->l1_size > 0) { s->l1_table =3D qemu_try_blockalign(bs->file->bs, - ROUND_UP(s->l1_size * sizeof(uint64_t), 512)); + s->l1_size * sizeof(uint64_t)); if (s->l1_table =3D=3D NULL) { error_setg(errp, "Could not allocate L1 table"); ret =3D -ENOMEM; --=20 2.20.1