From patchwork Wed Mar 11 17:20:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 184410 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp872443ile; Wed, 11 Mar 2020 10:24:12 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvQr+7HZpJskw0eOWohqVRD+jg5sTucjUrTzo1yE0u17x8iI7bw5zDP1dUIDQZyq++deX6q X-Received: by 2002:a05:6214:946:: with SMTP id dn6mr3663431qvb.154.1583947451918; Wed, 11 Mar 2020 10:24:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583947451; cv=none; d=google.com; s=arc-20160816; b=aY7rK90NVnUqkVUdMAYP37UjSKxCrBw73/IvLYVyKoFoUlvTXF5YP7Z0f3ObyBfpQj RysCp7MIITFjJJDuBtvZQqrHnJKeOBGLaZE+aNQkle2AXlvkFnlomC6GZeB+g2i37FIB 0/0ZlIwQob3XKrxCqF9ie4i7oqJOsAOYTs9nQYLPpaUia+UR8YJyrcGDWlGo3iquHTHS nGav1EFrB7+JnROwF88jgoz2kbtKKqy47TbGEXBp8R0qv/mbwmn3+rVUBUTbCYWg5gw8 9W7SiyngAowb5U07+ecP9g/0mMcyrusw7ajzWssd52ym1pL1r4GHnN+pN3zO635nO0oP 9I2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:references :in-reply-to:message-id:date:subject:to:from; bh=9c4IQBvzRkufAwdC9dSxucGO0wye5J6f1toNwDioFWU=; b=WMtUwqt1WTV02huDSVWpAES4TPvuqcr4oG8XmHpKBpQfg3DQkn0vVhUPw19qqTnnbc zAQgtVkqtBjTCatTZgtjME6wrB7/AmL5Zchp/x/iyN/B+aouwx4B6n9824WzxMgFGHUN 2hwdI7GeUW8CsKhWghtxKyqVq1njdd0d9mZcFi3xbCSmLn5JbZHGYidDsnsGCENw6KFU Rl3CjFy/kY+cNDmqVd18qipZis19AJ9Re/xyMtFj0OpAdMdn2Dgmv+krWyFV8++QJDfd YMo5wuK6pYVec1PU+nAY1m2hCtGACdi7hL47nNnm8LV6je455fbApzndu6J60zuVIakt 8eyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bt4si1247000qvb.101.2020.03.11.10.24.11 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 10:24:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:56220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC55X-0002eE-FK for patch@linaro.org; Wed, 11 Mar 2020 13:24:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58063) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC555-0001wh-2G for qemu-devel@nongnu.org; Wed, 11 Mar 2020 13:23:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC553-0003mz-S8 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 13:23:42 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3277 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jC550-0003Zv-CB; Wed, 11 Mar 2020 13:23:38 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id B1DB18F36637FA53CF75; Thu, 12 Mar 2020 01:23:34 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Thu, 12 Mar 2020 01:23:24 +0800 From: Shameer Kolothum To: , , , Subject: [PATCH v3 03/10] exec: Fix for qemu_ram_resize() callback Date: Wed, 11 Mar 2020 17:20:07 +0000 Message-ID: <20200311172014.33052-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20200311172014.33052-1-shameerali.kolothum.thodi@huawei.com> References: <20200311172014.33052-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 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: peter.maydell@linaro.org, xiaoguangrong.eric@gmail.com, david@redhat.com, mst@redhat.com, linuxarm@huawei.com, xuwei5@hisilicon.com, shannon.zhaosl@gmail.com, lersek@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Summarizing the issue: 1. Memory regions contain ram blocks with a different size, if the size is not properly aligned. While memory regions can have an unaligned size, ram blocks can't. This is true when creating resizable memory region with an unaligned size. 2. When resizing a ram block/memory region, the size of the memory region is set to the aligned size. The callback is called with the aligned size. The unaligned piece is lost. Because of the above, if ACPI blob length modifications happens after the initial virt_acpi_build() call, and the changed blob length is within the PAGE size boundary, then the revised size is not seen by the firmware on Guest reboot. Hence make sure callback is called if memory region size is changed, irrespective of aligned or not. Signed-off-by: David Hildenbrand [Shameer: added commit log] Signed-off-by: Shameer Kolothum --- Please find the discussion here, https://patchwork.kernel.org/patch/11339591/ --- exec.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) -- 2.17.1 Reviewed-by: Igor Mammedov diff --git a/exec.c b/exec.c index 0cc500d53a..f8974cd303 100644 --- a/exec.c +++ b/exec.c @@ -2073,11 +2073,21 @@ static int memory_try_enable_merging(void *addr, size_t len) */ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp) { + const ram_addr_t unaligned_size = newsize; + assert(block); newsize = HOST_PAGE_ALIGN(newsize); if (block->used_length == newsize) { + /* + * We don't have to resize the ram block (which only knows aligned + * sizes), however, we have to notify if the unaligned size changed. + */ + if (block->resized && unaligned_size != memory_region_size(block->mr)) { + block->resized(block->idstr, unaligned_size, block->host); + memory_region_set_size(block->mr, unaligned_size); + } return 0; } @@ -2101,9 +2111,9 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp) block->used_length = newsize; cpu_physical_memory_set_dirty_range(block->offset, block->used_length, DIRTY_CLIENTS_ALL); - memory_region_set_size(block->mr, newsize); + memory_region_set_size(block->mr, unaligned_size); if (block->resized) { - block->resized(block->idstr, newsize, block->host); + block->resized(block->idstr, unaligned_size, block->host); } return 0; }