From nobody Fri May 3 14:36:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1643212788; cv=none; d=zohomail.com; s=zohoarc; b=SwrKeHIVmBlfO/pP1YgB2AsMJg7SshpT/KKkAwQ+hUStr/WPfYEf+3U/eGASzMKLY5es2zNpiAVIsIeEZvO0nHZ/E9MiL+FbMqjNufXCr0XuC4lAWfiN27/OWgfDUQwnxDJE+1eMoUYeZSv2dib51fqiWnpbNIdwvwbfPOHenes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643212788; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=eBX7D1PxumbG6dEKxGfJrObnb724MkaIC0aw1q7qAAA=; b=KBjEEbdiUYyQhYNDxRtK9D3NMywCOHFoFUN8ujkjQG9+tIXPxHdo8TwWPfmQZdfgGFb0Sw7XJWPSSGnmrttw9hGwcrZezNqfkqeRJIwMy6PHrakW47GSZUXgVtkh6B1pruiOH0Q0QI9JjOaPB9yyzSdg5UVUVJrGEZvupP8YNvw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1643212788579763.2867166028818; Wed, 26 Jan 2022 07:59:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.260996.451428 (Exim 4.92) (envelope-from ) id 1nCkhj-00077R-SP; Wed, 26 Jan 2022 15:59:27 +0000 Received: by outflank-mailman (output) from mailman id 260996.451428; Wed, 26 Jan 2022 15:59:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nCkhj-00077K-P8; Wed, 26 Jan 2022 15:59:27 +0000 Received: by outflank-mailman (input) for mailman id 260996; Wed, 26 Jan 2022 15:59:26 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nCkhi-00077D-Tr for xen-devel@lists.xenproject.org; Wed, 26 Jan 2022 15:59:26 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nCkhh-0005gv-Fh; Wed, 26 Jan 2022 15:59:25 +0000 Received: from 54-240-197-224.amazon.com ([54.240.197.224] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nCkhh-0004wO-6t; Wed, 26 Jan 2022 15:59:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From; bh=eBX7D1PxumbG6dEKxGfJrObnb724MkaIC0aw1q7qAAA=; b=Z1lqUu AliszOIcbnQ0/8hqxh4xIUMZ+CAy/rSy2faCYqaiPIOPojibOf0SnCDL8fjSDkR5BOo3H7uPs7UXV gexj0xPc6sf3VnkSp5RkeVmeCraPKUw7o/LCxEOoUOjfUTuNErNtVSI8YCa6MVWhAZpZ9A/rXOyAr fVTpsumwdlg=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Volodymyr Babchuk , Bertrand Marquis , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v2] xen: Replace arch_mfn_in_directmap() with arch_mfns_in_directmap() Date: Wed, 26 Jan 2022 15:59:19 +0000 Message-Id: <20220126155919.36706-1-julien@xen.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1643212790595100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall The name of arch_mfn_in_directmap() suggests that it will check against that the passed MFN should be in the directmap. However, the current callers are passing the next MFN and the implementation will return true for up to one MFN past the directmap. It would be more meaningful to test the exact MFN rather than the next one. That said, the current expectation is the memory will be direct-mapped from 0 up to a given MFN. This may not be a valid assumption on all the architectures. For instance, on Arm32 only the xenheap that will be direct-mapped. This may not be allocated a the beginning of the RAM. So take the opportunity to rework the parameters and pass the number of pages we want to check. This also requires to rename the helper to better match the implementation. Note that the implementation of the helper on arm32 is left as-is for now. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini Reviewed-by: Jan Beulich ---- Changes in v2: - Pass a region instead the last MFN. - Rename the helper to arch_mfns_in_directmap() - This was https://lore.kernel.org/xen-devel/20211216152220.3317-1-juli= en@xen.org/ Looking at the history, it looks like the check in init_node_heap() was <=3D and it was simply moved to a new helper without any adjustment as part of c6fdc9696a "boot allocator: use arch helper for virt_to_mfn on DIRECTMAP_VIRT region". --- xen/arch/arm/include/asm/arm32/mm.h | 2 +- xen/arch/arm/include/asm/arm64/mm.h | 2 +- xen/arch/x86/include/asm/mm.h | 6 +++--- xen/common/page_alloc.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/include/asm/arm32/mm.h b/xen/arch/arm/include/asm= /arm32/mm.h index 68612499bf6c..6b039d9ceaa2 100644 --- a/xen/arch/arm/include/asm/arm32/mm.h +++ b/xen/arch/arm/include/asm/arm32/mm.h @@ -5,7 +5,7 @@ * Only a limited amount of RAM, called xenheap, is always mapped on ARM32. * For convenience always return false. */ -static inline bool arch_mfn_in_directmap(unsigned long mfn) +static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long= nr) { return false; } diff --git a/xen/arch/arm/include/asm/arm64/mm.h b/xen/arch/arm/include/asm= /arm64/mm.h index d0a3be7e15a4..aa2adac63189 100644 --- a/xen/arch/arm/include/asm/arm64/mm.h +++ b/xen/arch/arm/include/asm/arm64/mm.h @@ -5,7 +5,7 @@ * On ARM64, all the RAM is currently direct mapped in Xen. * Hence return always true. */ -static inline bool arch_mfn_in_directmap(unsigned long mfn) +static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long= nr) { return true; } diff --git a/xen/arch/x86/include/asm/mm.h b/xen/arch/x86/include/asm/mm.h index 5dbcee869624..9b9de4c6bef7 100644 --- a/xen/arch/x86/include/asm/mm.h +++ b/xen/arch/x86/include/asm/mm.h @@ -635,13 +635,13 @@ void write_32bit_pse_identmap(uint32_t *l2); =20 /* * x86 maps part of physical memory via the directmap region. - * Return whether the input MFN falls in that range. + * Return whether the range of MFN falls in the directmap region. */ -static inline bool arch_mfn_in_directmap(unsigned long mfn) +static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long= nr) { unsigned long eva =3D min(DIRECTMAP_VIRT_END, HYPERVISOR_VIRT_END); =20 - return mfn <=3D (virt_to_mfn(eva - 1) + 1); + return (mfn + nr) <=3D (virt_to_mfn(eva - 1) + 1); } =20 #endif /* __ASM_X86_MM_H__ */ diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 38eea879c04a..f8749b0787a6 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -588,7 +588,7 @@ static unsigned long init_node_heap(int node, unsigned = long mfn, needed =3D 0; } else if ( *use_tail && nr >=3D needed && - arch_mfn_in_directmap(mfn + nr) && + arch_mfns_in_directmap(mfn + nr - needed, needed) && (!xenheap_bits || !((mfn + nr - 1) >> (xenheap_bits - PAGE_SHIFT))) ) { @@ -597,7 +597,7 @@ static unsigned long init_node_heap(int node, unsigned = long mfn, PAGE_SIZE - sizeof(**avail) * NR_ZONES; } else if ( nr >=3D needed && - arch_mfn_in_directmap(mfn + needed) && + arch_mfns_in_directmap(mfn, needed) && (!xenheap_bits || !((mfn + needed - 1) >> (xenheap_bits - PAGE_SHIFT))) ) { --=20 2.32.0