From patchwork Wed Nov 15 07:14:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoyao Li X-Patchwork-Id: 13456240 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1912E4419 for ; Wed, 15 Nov 2023 07:16:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="eCFwZV1b" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF15C8E for ; Tue, 14 Nov 2023 23:16:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700032587; x=1731568587; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I+Zt4PPlUf4SBKG5BHDSP7VkS1LcDTzb79bbPWPOk4I=; b=eCFwZV1b115ZrbvOKse6sGsqsx7ukliOepntjmZHKUsXqMC2KaXkenK0 iPLpmCfUqlpyE5Ej9Yzki6V9TPOkixTyc0S7+pUS/85/BfatYHR/GEVD8 5A5MCEeKk2gze+Jyf6oZUBLIgY+16CTHVoQq8XtPuHYIi2ODdwFTMA4sA VqxEuEU4v4KhMQCp3lYATNFAeRf7BnHeqjN6URozyfqb7xjVRNh1fGOHN SespzWOMsLQAZRrZ0jgVz/I5UFEkHFPyjYM8etJ68X24LctBDxJLtuDIy xHiwnslvxBDy1A4SeD1Qubx2l2tcLOZzSly4AFn2+TFizKauCwY8d381a A==; X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="390622188" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="390622188" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2023 23:16:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="714797046" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="714797046" Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by orsmga003.jf.intel.com with ESMTP; 14 Nov 2023 23:16:16 -0800 From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S . Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Cornelia Huck , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , Sean Christopherson , Claudio Fontana , Gerd Hoffmann , Isaku Yamahata , Chenyi Qiang Subject: [PATCH v3 07/70] physmem: Relax the alignment check of host_startaddr in ram_block_discard_range() Date: Wed, 15 Nov 2023 02:14:16 -0500 Message-Id: <20231115071519.2864957-8-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231115071519.2864957-1-xiaoyao.li@intel.com> References: <20231115071519.2864957-1-xiaoyao.li@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Commit d3a5038c461 ("exec: ram_block_discard_range") introduced ram_block_discard_range() which grabs some code from ram_discard_range(). However, during code movement, it changed alignment check of host_startaddr from qemu_host_page_size to rb->page_size. When ramblock is back'ed by hugepage, it requires the startaddr to be huge page size aligned, which is a overkill. e.g., TDX's private-shared page conversion is done at 4KB granularity. Shared page is discarded when it gets converts to private and when shared page back'ed by hugepage it is going to fail on this check. So change to alignment check back to qemu_host_page_size. Signed-off-by: Xiaoyao Li --- Changes in v3: - Newly added in v3; --- system/physmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/physmem.c b/system/physmem.c index c56b17e44df6..8a4e42c7cf60 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3532,7 +3532,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) uint8_t *host_startaddr = rb->host + start; - if (!QEMU_PTR_IS_ALIGNED(host_startaddr, rb->page_size)) { + if (!QEMU_PTR_IS_ALIGNED(host_startaddr, qemu_host_page_size)) { error_report("ram_block_discard_range: Unaligned start address: %p", host_startaddr); goto err;