From nobody Mon Feb 9 07:55:32 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582303543; cv=none; d=zohomail.com; s=zohoarc; b=KFUi7q3c6WkSDZWZfrHDVCz9TBqybZCFpE87vZ5he/g+a4IDhEVO2X3FeUEO7wjtyL9zMxJdvfoIdx73XH4Zabjqmb1dcB/J47Hyivd0c8bR0g+V/fj6QLG8CX2KDLJX5h/Y91OMBybCrQmbJYjNV3aPmKB8J3Xs9m7n0T9mBY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582303543; h=Content-Type: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=EJq972UhjpkmcHCdnxALNgVTNAc8KQY0NgduEwRuRMw=; b=AQDmgjOg8h56J2NNL5GssUMTcSK9T8CizoGPnE4GQnku0TA/qV4EsN1rKf1S4Ylv7gME3fLRoy1YVg3v0HTTRTTeGqXB5z7u3mch782M7El520dyUDPnt53h/J7DBQT7uDGQ8PyyQPAzQsI95J1d9F7HRtopEq6ndyWJ+m3qijQ= 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582303543130302.33171640753767; Fri, 21 Feb 2020 08:45:43 -0800 (PST) Received: from localhost ([::1]:33122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5BQr-0003su-TT for importer@patchew.org; Fri, 21 Feb 2020 11:45:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52765) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5BOc-0008LF-GJ for qemu-devel@nongnu.org; Fri, 21 Feb 2020 11:43:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5BOb-0006wl-JA for qemu-devel@nongnu.org; Fri, 21 Feb 2020 11:43:22 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:22151 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j5BOb-0006wH-Fb for qemu-devel@nongnu.org; Fri, 21 Feb 2020 11:43:21 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-5-yv3BARUZPWKVHwrPkxlv-w-1; Fri, 21 Feb 2020 11:43:19 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72924800D4E; Fri, 21 Feb 2020 16:43:18 +0000 (UTC) Received: from t480s.redhat.com (ovpn-117-197.ams2.redhat.com [10.36.117.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B3055C105; Fri, 21 Feb 2020 16:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582303401; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EJq972UhjpkmcHCdnxALNgVTNAc8KQY0NgduEwRuRMw=; b=TMte7PXMRgeBvjjqGpkijBcwBVNomDC4irfCe/ZZvKj7ddEM2kb4MUBPlUiLyVepAZMURl XUXxDYf6gaiYsAu5BNl2H9W7hEEH6Z3PR3OKWZkA4HTqr7QExubEq58/CIQUAtTKGoIVB1 /AA/uLKrOFkBdwvIXdVv84g2oKd6Yd8= X-MC-Unique: yv3BARUZPWKVHwrPkxlv-w-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 06/13] exec: Relax range check in ram_block_discard_range() Date: Fri, 21 Feb 2020 17:41:57 +0100 Message-Id: <20200221164204.105570-7-david@redhat.com> In-Reply-To: <20200221164204.105570-1-david@redhat.com> References: <20200221164204.105570-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Eduardo Habkost , Juan Quintela , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , Richard Henderson 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" We want to make use of ram_block_discard_range() in the RAM block resize callback when growing a RAM block, *before* used_length is changed. Let's relax the check. We always have a reserved mapping for the whole max_length, so we cannot corrupt unrelated data. Cc: Richard Henderson Cc: Paolo Bonzini Cc: Eduardo Habkost Cc: Peter Xu Signed-off-by: David Hildenbrand Reviewed-by: Peter Xu --- exec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 8b015821d6..8737acedab 100644 --- a/exec.c +++ b/exec.c @@ -3915,7 +3915,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t st= art, size_t length) goto err; } =20 - if ((start + length) <=3D rb->used_length) { + if ((start + length) <=3D rb->max_length) { bool need_madvise, need_fallocate; if (!QEMU_IS_ALIGNED(length, rb->page_size)) { error_report("ram_block_discard_range: Unaligned length: %zx", @@ -3982,7 +3982,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t st= art, size_t length) } else { error_report("ram_block_discard_range: Overrun block '%s' (%" PRIu= 64 "/%zx/" RAM_ADDR_FMT")", - rb->idstr, start, length, rb->used_length); + rb->idstr, start, length, rb->max_length); } =20 err: --=20 2.24.1