From nobody Tue May 14 10:08:56 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=1645438971; cv=none; d=zohomail.com; s=zohoarc; b=mYfiMxMTXMUJc/eoLmvfoF6t3xmHLIFL/UlFfMQ/ekshDua2hobOQAa17iPaRzwXzyeLuhBFlqeS2Ka1e5bmbpRAdD/tYqFaHjCm/7yxquBEfcMMMXp/G2hYyehkpNopXjGccraf+w4zaPlXgaNexDBkLoAeRNIaAiRTcGj2fQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645438971; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ACRkY4KhzmsVNHMcOkXHEpsxlBF8BKtVgEaQlfg0BNc=; b=iiYjY3D/AZFdbIgS4LcaHEjGsB7ikx+2UhlmVOpCAAS42qKXOcbNKg2ItbUpB8lnPqk0TkS0yh+EZ1BsuXs4dMS8jPYNBd09CPuwwsBbMBQNXsZuTD7f/mMg3Kg1tP3qHL28ekIa4QyJzSH3q5m+RF8lGoOQxESlj4VPY2PsPRI= 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 1645438971960635.3722667089066; Mon, 21 Feb 2022 02:22:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.275987.472004 (Exim 4.92) (envelope-from ) id 1nM5pp-0004Hi-Jg; Mon, 21 Feb 2022 10:22:25 +0000 Received: by outflank-mailman (output) from mailman id 275987.472004; Mon, 21 Feb 2022 10:22:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pp-0004HM-Bt; Mon, 21 Feb 2022 10:22:25 +0000 Received: by outflank-mailman (input) for mailman id 275987; Mon, 21 Feb 2022 10:22:24 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5po-0004FP-7v for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:22:24 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pn-0002AY-Ua; Mon, 21 Feb 2022 10:22:23 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5pn-00070b-MY; Mon, 21 Feb 2022 10:22:23 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ACRkY4KhzmsVNHMcOkXHEpsxlBF8BKtVgEaQlfg0BNc=; b=55WepRFLg0bmiSYJclRhlTge7D MgBe3sFdk4LNDN/N9g7c556hnZI3Swp9dkMRo3B6xkB/Emt9NTSaqapqaom6QGkTgsUZkTHJbFzK2 0x82I94h1yvGUi5rZBoFHXrQhllYxh0iLFsPkuLsl+fNvtPJo7InySh5mOOiucG0vl+U=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 01/19] xen/arm: lpae: Rename LPAE_ENTRIES_MASK_GS to LPAE_ENTRY_MASK_GS Date: Mon, 21 Feb 2022 10:22:00 +0000 Message-Id: <20220221102218.33785-2-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645438974322100011 Content-Type: text/plain; charset="utf-8" From: Julien Grall Commit 05031fa87357 "xen/arm: guest_walk: Only generate necessary offsets/masks" introduced LPAE_ENTRIES_MASK_GS. In a follow-up patch, we will use it for to define LPAE_ENTRY_MASK. This will lead to inconsistent naming. As LPAE_ENTRY_MASK is used in many places, it is better to rename LPAE_ENTRIES_MASK_GS and avoid some churn. So rename LPAE_ENTRIES_MASK_GS to LPAE_ENTRY_MASK_GS. Signed-off-by: Julien Grall Reviewed-by: Bertrand Marquis --- Changes in v2: - New patch --- xen/arch/arm/include/asm/lpae.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/include/asm/lpae.h b/xen/arch/arm/include/asm/lpa= e.h index e94de2e7d8e8..4fb9a40a4ca9 100644 --- a/xen/arch/arm/include/asm/lpae.h +++ b/xen/arch/arm/include/asm/lpae.h @@ -180,7 +180,7 @@ static inline bool lpae_is_superpage(lpae_t pte, unsign= ed int level) */ #define LPAE_SHIFT_GS(gs) ((gs) - 3) #define LPAE_ENTRIES_GS(gs) (_AC(1, U) << LPAE_SHIFT_GS(gs)) -#define LPAE_ENTRIES_MASK_GS(gs) (LPAE_ENTRIES_GS(gs) - 1) +#define LPAE_ENTRY_MASK_GS(gs) (LPAE_ENTRIES_GS(gs) - 1) =20 #define LEVEL_ORDER_GS(gs, lvl) ((3 - (lvl)) * LPAE_SHIFT_GS(gs)) #define LEVEL_SHIFT_GS(gs, lvl) (LEVEL_ORDER_GS(gs, lvl) + (gs)) @@ -188,7 +188,7 @@ static inline bool lpae_is_superpage(lpae_t pte, unsign= ed int level) =20 /* Offset in the table at level 'lvl' */ #define LPAE_TABLE_INDEX_GS(gs, lvl, addr) \ - (((addr) >> LEVEL_SHIFT_GS(gs, lvl)) & LPAE_ENTRIES_MASK_GS(gs)) + (((addr) >> LEVEL_SHIFT_GS(gs, lvl)) & LPAE_ENTRY_MASK_GS(gs)) =20 /* Generate an array @var containing the offset for each level from @addr = */ #define DECLARE_OFFSETS(var, addr) \ --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645438969; cv=none; d=zohomail.com; s=zohoarc; b=KLLG6wA+pTth06YaFKci00TI6uk1XnuzwOIwwOwaSfo9y3rXKfU2v5db7ryeUzBYlapgbwXdzpbaf2G653cmpadNpDSiWqB4OyGGlXCMIM6F09xw5y0R1tiBYdKzLQM0jXizyOrH3sbMpWN0Ule31S9F62Thh49j7KQh/7AuDU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645438969; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kU4hAjZM1wdm5Xqt+UCg0gYAV4Ows97+OkKeN1riEcM=; b=ZMeSRgaUaruaOuZFaIZqxcLWa1S/OgOwXTTxdHHO/PpqPqSg+4i1FlsdQsUVjSMXLUkH+b6beGK+76qhxlY568FErmh5C0g0aaOgZTxrzOTvSBfiH7y3fFiKw1ScJsSLyAzZ1+pS2EZ/HcsbD27ypBKhUjyHGfRAVc6FJAKXAek= 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 16454389691311004.4299049380288; Mon, 21 Feb 2022 02:22:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.275988.472020 (Exim 4.92) (envelope-from ) id 1nM5pq-0004lW-V3; Mon, 21 Feb 2022 10:22:26 +0000 Received: by outflank-mailman (output) from mailman id 275988.472020; Mon, 21 Feb 2022 10:22:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pq-0004lL-QY; Mon, 21 Feb 2022 10:22:26 +0000 Received: by outflank-mailman (input) for mailman id 275988; Mon, 21 Feb 2022 10:22:25 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pp-0004Fz-7X for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:22:25 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pp-0002Am-04; Mon, 21 Feb 2022 10:22:25 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5po-00070b-La; Mon, 21 Feb 2022 10:22:24 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=kU4hAjZM1wdm5Xqt+UCg0gYAV4Ows97+OkKeN1riEcM=; b=ZRQT9wpIvJ8XngTAuCy2o98Zv9 F1wRj4oruAZrLEbM/0UUOrDYR2UciO8hAf54JexWiiOk8mOWYwh3cZ7of4mIsgdTqpfOz+c9RfLi2 arvH2hCu7ArcQQIOflrogwsYwsLDpv66HiawyWafsqv8lIbFtPNXaFE4D1SCU/655ewc=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 02/19] xen/arm: lpae: Use the generic helpers to defined the Xen PT helpers Date: Mon, 21 Feb 2022 10:22:01 +0000 Message-Id: <20220221102218.33785-3-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645438970552100002 Content-Type: text/plain; charset="utf-8" From: Julien Grall Currently, Xen PT helpers are only working with 4KB page granularity and open-code the generic helpers. To allow more flexibility, we can re-use the generic helpers and pass Xen's page granularity (PAGE_SHIFT). As Xen PT helpers are used in both C and assembly, we need to move the generic helpers definition outside of the !__ASSEMBLY__ section. Take the opportunity to prefix LPAE_ENTRIES, LPAE_ENTRIES and LPAE_ENTRIES_MASK with XEN_PT_. Note the aliases for each level are still kept for the time being so we can avoid a massive patch to change all the callers. Signed-off-by: Julien Grall Reviewed-by: Bertrand Marquis Reviewed-by: Michal Orzel --- Changes in v3: - Prefix the new define with XEN_PT_ Changes in v2: - New patch --- xen/arch/arm/arm32/head.S | 14 +++---- xen/arch/arm/arm64/head.S | 14 +++---- xen/arch/arm/include/asm/lpae.h | 73 ++++++++++++++++++--------------- xen/arch/arm/mm.c | 33 ++++++++------- xen/arch/arm/p2m.c | 13 +++--- 5 files changed, 80 insertions(+), 67 deletions(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index b5912d381b98..b1d209ea2842 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -375,7 +375,7 @@ ENDPROC(cpu_init) */ .macro create_table_entry, ptbl, tbl, virt, shift, mmu=3D0 lsr r1, \virt, #\shift - mov_w r2, LPAE_ENTRY_MASK + mov_w r2, XEN_PT_LPAE_ENTRY_MASK and r1, r1, r2 /* r1 :=3D slot in \tlb */ lsl r1, r1, #3 /* r1 :=3D slot offset in \tlb */ =20 @@ -410,7 +410,7 @@ ENDPROC(cpu_init) * and be distinct. */ .macro create_mapping_entry, ptbl, virt, phys, type=3DPT_MEM_L3, mmu=3D0 - mov_w r2, LPAE_ENTRY_MASK + mov_w r2, XEN_PT_LPAE_ENTRY_MASK lsr r1, \virt, #THIRD_SHIFT and r1, r1, r2 /* r1 :=3D slot in \tlb */ lsl r1, r1, #3 /* r1 :=3D slot offset in \tlb */ @@ -465,7 +465,7 @@ create_page_tables: 1: strd r2, r3, [r4, r1] /* Map vaddr(start) */ add r2, r2, #PAGE_SIZE /* Next page */ add r1, r1, #8 /* Next slot */ - cmp r1, #(LPAE_ENTRIES<<3) /* 512*8-byte entries per page */ + cmp r1, #(XEN_PT_LPAE_ENTRIES<<3) /* 512*8-byte entries per page= */ blo 1b =20 /* @@ -487,7 +487,7 @@ create_page_tables: * the second level. */ lsr r1, r9, #FIRST_SHIFT - mov_w r0, LPAE_ENTRY_MASK + mov_w r0, XEN_PT_LPAE_ENTRY_MASK and r1, r1, r0 /* r1 :=3D first slot */ cmp r1, #XEN_FIRST_SLOT beq 1f @@ -502,7 +502,7 @@ create_page_tables: * it. */ lsr r1, r9, #SECOND_SHIFT - mov_w r0, LPAE_ENTRY_MASK + mov_w r0, XEN_PT_LPAE_ENTRY_MASK and r1, r1, r0 /* r1 :=3D second slot */ cmp r1, #XEN_SECOND_SLOT beq virtphys_clash @@ -573,7 +573,7 @@ remove_identity_mapping: * table if the slot is not XEN_FIRST_SLOT. */ lsr r1, r9, #FIRST_SHIFT - mov_w r0, LPAE_ENTRY_MASK + mov_w r0, XEN_PT_LPAE_ENTRY_MASK and r1, r1, r0 /* r1 :=3D first slot */ cmp r1, #XEN_FIRST_SLOT beq 1f @@ -589,7 +589,7 @@ remove_identity_mapping: * table if the slot is not XEN_SECOND_SLOT. */ lsr r1, r9, #SECOND_SHIFT - mov_w r0, LPAE_ENTRY_MASK + mov_w r0, XEN_PT_LPAE_ENTRY_MASK and r1, r1, r0 /* r1 :=3D second slot */ cmp r1, #XEN_SECOND_SLOT beq identity_mapping_removed diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 51b00ab0bea6..314b800b3f8e 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -509,7 +509,7 @@ ENDPROC(cpu_init) */ .macro create_table_entry, ptbl, tbl, virt, shift, tmp1, tmp2, tmp3 lsr \tmp1, \virt, #\shift - and \tmp1, \tmp1, #LPAE_ENTRY_MASK/* \tmp1 :=3D slot in \tlb */ + and \tmp1, \tmp1, #XEN_PT_LPAE_ENTRY_MASK/* \tmp1 :=3D slot in \= tlb */ =20 load_paddr \tmp2, \tbl mov \tmp3, #PT_PT /* \tmp3 :=3D right for linear= PT */ @@ -541,7 +541,7 @@ ENDPROC(cpu_init) and \tmp3, \phys, #THIRD_MASK /* \tmp3 :=3D PAGE_ALIGNED(phy= s) */ =20 lsr \tmp1, \virt, #THIRD_SHIFT - and \tmp1, \tmp1, #LPAE_ENTRY_MASK/* \tmp1 :=3D slot in \tlb */ + and \tmp1, \tmp1, #XEN_PT_LPAE_ENTRY_MASK/* \tmp1 :=3D slot in \= tlb */ =20 mov \tmp2, #\type /* \tmp2 :=3D right for sectio= n PT */ orr \tmp2, \tmp2, \tmp3 /* + PAGE_ALIGNED(phy= s) */ @@ -586,7 +586,7 @@ create_page_tables: 1: str x2, [x4, x1] /* Map vaddr(start) */ add x2, x2, #PAGE_SIZE /* Next page */ add x1, x1, #8 /* Next slot */ - cmp x1, #(LPAE_ENTRIES<<3) /* 512 entries per page */ + cmp x1, #(XEN_PT_LPAE_ENTRIES<<3) /* 512 entries per page */ b.lt 1b =20 /* @@ -621,7 +621,7 @@ create_page_tables: * the second level. */ lsr x0, x19, #FIRST_SHIFT - and x0, x0, #LPAE_ENTRY_MASK /* x0 :=3D first slot */ + and x0, x0, #XEN_PT_LPAE_ENTRY_MASK /* x0 :=3D first slot */ cmp x0, #XEN_FIRST_SLOT beq 1f create_table_entry boot_first, boot_second_id, x19, FIRST_SHIFT, x= 0, x1, x2 @@ -635,7 +635,7 @@ create_page_tables: * it. */ lsr x0, x19, #SECOND_SHIFT - and x0, x0, #LPAE_ENTRY_MASK /* x0 :=3D first slot */ + and x0, x0, #XEN_PT_LPAE_ENTRY_MASK /* x0 :=3D first slot */ cmp x0, #XEN_SECOND_SLOT beq virtphys_clash create_table_entry boot_second, boot_third_id, x19, SECOND_SHIFT, = x0, x1, x2 @@ -715,7 +715,7 @@ remove_identity_mapping: * table if the slot is not XEN_FIRST_SLOT. */ lsr x1, x19, #FIRST_SHIFT - and x1, x1, #LPAE_ENTRY_MASK /* x1 :=3D first slot */ + and x1, x1, #XEN_PT_LPAE_ENTRY_MASK /* x1 :=3D first slot */ cmp x1, #XEN_FIRST_SLOT beq 1f /* It is not in slot XEN_FIRST_SLOT, remove the entry. */ @@ -729,7 +729,7 @@ remove_identity_mapping: * table if the slot is not XEN_SECOND_SLOT. */ lsr x1, x19, #SECOND_SHIFT - and x1, x1, #LPAE_ENTRY_MASK /* x1 :=3D first slot */ + and x1, x1, #XEN_PT_LPAE_ENTRY_MASK /* x1 :=3D first slot */ cmp x1, #XEN_SECOND_SLOT beq identity_mapping_removed /* It is not in slot 1, remove the entry */ diff --git a/xen/arch/arm/include/asm/lpae.h b/xen/arch/arm/include/asm/lpa= e.h index 4fb9a40a4ca9..8cf932b5c947 100644 --- a/xen/arch/arm/include/asm/lpae.h +++ b/xen/arch/arm/include/asm/lpae.h @@ -159,6 +159,17 @@ static inline bool lpae_is_superpage(lpae_t pte, unsig= ned int level) #define lpae_get_mfn(pte) (_mfn((pte).walk.base)) #define lpae_set_mfn(pte, mfn) ((pte).walk.base =3D mfn_x(mfn)) =20 +/* Generate an array @var containing the offset for each level from @addr = */ +#define DECLARE_OFFSETS(var, addr) \ + const unsigned int var[4] =3D { \ + zeroeth_table_offset(addr), \ + first_table_offset(addr), \ + second_table_offset(addr), \ + third_table_offset(addr) \ + } + +#endif /* __ASSEMBLY__ */ + /* * AArch64 supports pages with different sizes (4K, 16K, and 64K). * Provide a set of generic helpers that will compute various @@ -190,17 +201,6 @@ static inline bool lpae_is_superpage(lpae_t pte, unsig= ned int level) #define LPAE_TABLE_INDEX_GS(gs, lvl, addr) \ (((addr) >> LEVEL_SHIFT_GS(gs, lvl)) & LPAE_ENTRY_MASK_GS(gs)) =20 -/* Generate an array @var containing the offset for each level from @addr = */ -#define DECLARE_OFFSETS(var, addr) \ - const unsigned int var[4] =3D { \ - zeroeth_table_offset(addr), \ - first_table_offset(addr), \ - second_table_offset(addr), \ - third_table_offset(addr) \ - } - -#endif /* __ASSEMBLY__ */ - /* * These numbers add up to a 48-bit input address space. * @@ -211,26 +211,35 @@ static inline bool lpae_is_superpage(lpae_t pte, unsi= gned int level) * therefore 39-bits are sufficient. */ =20 -#define LPAE_SHIFT 9 -#define LPAE_ENTRIES (_AC(1,U) << LPAE_SHIFT) -#define LPAE_ENTRY_MASK (LPAE_ENTRIES - 1) - -#define THIRD_SHIFT (PAGE_SHIFT) -#define THIRD_ORDER (THIRD_SHIFT - PAGE_SHIFT) -#define THIRD_SIZE (_AT(paddr_t, 1) << THIRD_SHIFT) -#define THIRD_MASK (~(THIRD_SIZE - 1)) -#define SECOND_SHIFT (THIRD_SHIFT + LPAE_SHIFT) -#define SECOND_ORDER (SECOND_SHIFT - PAGE_SHIFT) -#define SECOND_SIZE (_AT(paddr_t, 1) << SECOND_SHIFT) -#define SECOND_MASK (~(SECOND_SIZE - 1)) -#define FIRST_SHIFT (SECOND_SHIFT + LPAE_SHIFT) -#define FIRST_ORDER (FIRST_SHIFT - PAGE_SHIFT) -#define FIRST_SIZE (_AT(paddr_t, 1) << FIRST_SHIFT) -#define FIRST_MASK (~(FIRST_SIZE - 1)) -#define ZEROETH_SHIFT (FIRST_SHIFT + LPAE_SHIFT) -#define ZEROETH_ORDER (ZEROETH_SHIFT - PAGE_SHIFT) -#define ZEROETH_SIZE (_AT(paddr_t, 1) << ZEROETH_SHIFT) -#define ZEROETH_MASK (~(ZEROETH_SIZE - 1)) +#define XEN_PT_LPAE_SHIFT LPAE_SHIFT_GS(PAGE_SHIFT) +#define XEN_PT_LPAE_ENTRIES LPAE_ENTRIES_GS(PAGE_SHIFT) +#define XEN_PT_LPAE_ENTRY_MASK LPAE_ENTRY_MASK_GS(PAGE_SHIFT) + +#define XEN_PT_LEVEL_SHIFT(lvl) LEVEL_SHIFT_GS(PAGE_SHIFT, lvl) +#define XEN_PT_LEVEL_ORDER(lvl) LEVEL_ORDER_GS(PAGE_SHIFT, lvl) +#define XEN_PT_LEVEL_SIZE(lvl) LEVEL_SIZE_GS(PAGE_SHIFT, lvl) +#define XEN_PT_LEVEL_MASK(lvl) (~(XEN_PT_LEVEL_SIZE(lvl) - 1)) + +/* Convenience aliases */ +#define THIRD_SHIFT XEN_PT_LEVEL_SHIFT(3) +#define THIRD_ORDER XEN_PT_LEVEL_ORDER(3) +#define THIRD_SIZE XEN_PT_LEVEL_SIZE(3) +#define THIRD_MASK XEN_PT_LEVEL_MASK(3) + +#define SECOND_SHIFT XEN_PT_LEVEL_SHIFT(2) +#define SECOND_ORDER XEN_PT_LEVEL_ORDER(2) +#define SECOND_SIZE XEN_PT_LEVEL_SIZE(2) +#define SECOND_MASK XEN_PT_LEVEL_MASK(2) + +#define FIRST_SHIFT XEN_PT_LEVEL_SHIFT(1) +#define FIRST_ORDER XEN_PT_LEVEL_ORDER(1) +#define FIRST_SIZE XEN_PT_LEVEL_SIZE(1) +#define FIRST_MASK XEN_PT_LEVEL_MASK(1) + +#define ZEROETH_SHIFT XEN_PT_LEVEL_SHIFT(0) +#define ZEROETH_ORDER XEN_PT_LEVEL_ORDER(0) +#define ZEROETH_SIZE XEN_PT_LEVEL_SIZE(0) +#define ZEROETH_MASK XEN_PT_LEVEL_MASK(0) =20 /* Calculate the offsets into the pagetables for a given VA */ #define zeroeth_linear_offset(va) ((va) >> ZEROETH_SHIFT) @@ -238,7 +247,7 @@ static inline bool lpae_is_superpage(lpae_t pte, unsign= ed int level) #define second_linear_offset(va) ((va) >> SECOND_SHIFT) #define third_linear_offset(va) ((va) >> THIRD_SHIFT) =20 -#define TABLE_OFFSET(offs) (_AT(unsigned int, offs) & LPAE_ENTRY_MASK) +#define TABLE_OFFSET(offs) (_AT(unsigned int, offs) & XEN_PT_LPAE_ENTRY_MA= SK) #define first_table_offset(va) TABLE_OFFSET(first_linear_offset(va)) #define second_table_offset(va) TABLE_OFFSET(second_linear_offset(va)) #define third_table_offset(va) TABLE_OFFSET(third_linear_offset(va)) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b1eae767c27c..515d0906f85b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -71,10 +71,11 @@ mm_printk(const char *fmt, ...) {} * in C). */ #define DEFINE_BOOT_PAGE_TABLE(name) = \ -lpae_t __aligned(PAGE_SIZE) __section(".data.page_aligned") name[LPAE_ENTR= IES] +lpae_t __aligned(PAGE_SIZE) __section(".data.page_aligned") = \ + name[XEN_PT_LPAE_ENTRIES] =20 #define DEFINE_PAGE_TABLES(name, nr) \ -lpae_t __aligned(PAGE_SIZE) name[LPAE_ENTRIES * (nr)] +lpae_t __aligned(PAGE_SIZE) name[XEN_PT_LPAE_ENTRIES * (nr)] =20 #define DEFINE_PAGE_TABLE(name) DEFINE_PAGE_TABLES(name, 1) =20 @@ -207,7 +208,7 @@ static void __init __maybe_unused build_assertions(void) BUILD_BUG_ON(zeroeth_table_offset(XEN_VIRT_START)); #endif BUILD_BUG_ON(first_table_offset(XEN_VIRT_START)); - BUILD_BUG_ON(second_linear_offset(XEN_VIRT_START) >=3D LPAE_ENTRIES); + BUILD_BUG_ON(second_linear_offset(XEN_VIRT_START) >=3D XEN_PT_LPAE_ENT= RIES); #ifdef CONFIG_DOMAIN_PAGE BUILD_BUG_ON(DOMHEAP_VIRT_START & ~FIRST_MASK); #endif @@ -256,7 +257,7 @@ void dump_pt_walk(paddr_t ttbr, paddr_t addr, =20 for ( level =3D root_level; ; level++ ) { - if ( offsets[level] > LPAE_ENTRIES ) + if ( offsets[level] > XEN_PT_LPAE_ENTRIES ) break; =20 pte =3D mapping[offsets[level]]; @@ -395,15 +396,15 @@ static void __init create_mappings(lpae_t *second, ASSERT(!(base_mfn % granularity)); ASSERT(!(nr_mfns % granularity)); =20 - count =3D nr_mfns / LPAE_ENTRIES; + count =3D nr_mfns / XEN_PT_LPAE_ENTRIES; p =3D second + second_linear_offset(virt_offset); pte =3D mfn_to_xen_entry(_mfn(base_mfn), MT_NORMAL); - if ( granularity =3D=3D 16 * LPAE_ENTRIES ) + if ( granularity =3D=3D 16 * XEN_PT_LPAE_ENTRIES ) pte.pt.contig =3D 1; /* These maps are in 16-entry contiguous chu= nks. */ for ( i =3D 0; i < count; i++ ) { write_pte(p + i, pte); - pte.pt.base +=3D 1 << LPAE_SHIFT; + pte.pt.base +=3D 1 << XEN_PT_LPAE_SHIFT; } flush_xen_tlb_local(); } @@ -424,7 +425,7 @@ void *map_domain_page(mfn_t mfn) { unsigned long flags; lpae_t *map =3D this_cpu(xen_dommap); - unsigned long slot_mfn =3D mfn_x(mfn) & ~LPAE_ENTRY_MASK; + unsigned long slot_mfn =3D mfn_x(mfn) & ~XEN_PT_LPAE_ENTRY_MASK; vaddr_t va; lpae_t pte; int i, slot; @@ -435,7 +436,7 @@ void *map_domain_page(mfn_t mfn) * entry is a 2MB superpage pte. We use the available bits of each * PTE as a reference count; when the refcount is zero the slot can * be reused. */ - for ( slot =3D (slot_mfn >> LPAE_SHIFT) % DOMHEAP_ENTRIES, i =3D 0; + for ( slot =3D (slot_mfn >> XEN_PT_LPAE_SHIFT) % DOMHEAP_ENTRIES, i = =3D 0; i < DOMHEAP_ENTRIES; slot =3D (slot + 1) % DOMHEAP_ENTRIES, i++ ) { @@ -477,7 +478,7 @@ void *map_domain_page(mfn_t mfn) =20 va =3D (DOMHEAP_VIRT_START + (slot << SECOND_SHIFT) - + ((mfn_x(mfn) & LPAE_ENTRY_MASK) << THIRD_SHIFT)); + + ((mfn_x(mfn) & XEN_PT_LPAE_ENTRY_MASK) << THIRD_SHIFT)); =20 /* * We may not have flushed this specific subpage at map time, @@ -513,7 +514,7 @@ mfn_t domain_page_map_to_mfn(const void *ptr) unsigned long va =3D (unsigned long)ptr; lpae_t *map =3D this_cpu(xen_dommap); int slot =3D (va - DOMHEAP_VIRT_START) >> SECOND_SHIFT; - unsigned long offset =3D (va>>THIRD_SHIFT) & LPAE_ENTRY_MASK; + unsigned long offset =3D (va>>THIRD_SHIFT) & XEN_PT_LPAE_ENTRY_MASK; =20 if ( va >=3D VMAP_VIRT_START && va < VMAP_VIRT_END ) return virt_to_mfn(va); @@ -654,7 +655,8 @@ void __init setup_pagetables(unsigned long boot_phys_of= fset) /* Initialise first level entries, to point to second level entries */ for ( i =3D 0; i < 2; i++) { - p[i] =3D pte_of_xenaddr((uintptr_t)(xen_second+i*LPAE_ENTRIES)); + p[i] =3D pte_of_xenaddr((uintptr_t)(xen_second + + i * XEN_PT_LPAE_ENTRIES)); p[i].pt.table =3D 1; p[i].pt.xn =3D 0; } @@ -663,13 +665,14 @@ void __init setup_pagetables(unsigned long boot_phys_= offset) for ( i =3D 0; i < DOMHEAP_SECOND_PAGES; i++ ) { p[first_table_offset(DOMHEAP_VIRT_START+i*FIRST_SIZE)] - =3D pte_of_xenaddr((uintptr_t)(cpu0_dommap+i*LPAE_ENTRIES)); + =3D pte_of_xenaddr((uintptr_t)(cpu0_dommap + + i * XEN_PT_LPAE_ENTRIES)); p[first_table_offset(DOMHEAP_VIRT_START+i*FIRST_SIZE)].pt.table = =3D 1; } #endif =20 /* Break up the Xen mapping into 4k pages and protect them separately.= */ - for ( i =3D 0; i < LPAE_ENTRIES; i++ ) + for ( i =3D 0; i < XEN_PT_LPAE_ENTRIES; i++ ) { vaddr_t va =3D XEN_VIRT_START + (i << PAGE_SHIFT); =20 @@ -768,7 +771,7 @@ int init_secondary_pagetables(int cpu) * domheap mapping pages. */ for ( i =3D 0; i < DOMHEAP_SECOND_PAGES; i++ ) { - pte =3D mfn_to_xen_entry(virt_to_mfn(domheap+i*LPAE_ENTRIES), + pte =3D mfn_to_xen_entry(virt_to_mfn(domheap + i * XEN_PT_LPAE_ENT= RIES), MT_NORMAL); pte.pt.table =3D 1; write_pte(&first[first_table_offset(DOMHEAP_VIRT_START+i*FIRST_SIZ= E)], pte); diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 02cf852d4cf1..493a1e25879a 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -233,7 +233,8 @@ static lpae_t *p2m_get_root_pointer(struct p2m_domain *= p2m, * we can't use (P2M_ROOT_LEVEL - 1) because the root level might be * 0. Yet we still want to check if all the unused bits are zeroed. */ - root_table =3D gfn_x(gfn) >> (level_orders[P2M_ROOT_LEVEL] + LPAE_SHIF= T); + root_table =3D gfn_x(gfn) >> (level_orders[P2M_ROOT_LEVEL] + + XEN_PT_LPAE_SHIFT); if ( root_table >=3D P2M_ROOT_PAGES ) return NULL; =20 @@ -773,7 +774,7 @@ static void p2m_free_entry(struct p2m_domain *p2m, } =20 table =3D map_domain_page(lpae_get_mfn(entry)); - for ( i =3D 0; i < LPAE_ENTRIES; i++ ) + for ( i =3D 0; i < XEN_PT_LPAE_ENTRIES; i++ ) p2m_free_entry(p2m, *(table + i), level + 1); =20 unmap_domain_page(table); @@ -827,7 +828,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m,= lpae_t *entry, * We are either splitting a first level 1G page into 512 second level * 2M pages, or a second level 2M page into 512 third level 4K pages. */ - for ( i =3D 0; i < LPAE_ENTRIES; i++ ) + for ( i =3D 0; i < XEN_PT_LPAE_ENTRIES; i++ ) { lpae_t *new_entry =3D table + i; =20 @@ -850,7 +851,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m,= lpae_t *entry, /* Update stats */ p2m->stats.shattered[level]++; p2m->stats.mappings[level]--; - p2m->stats.mappings[next_level] +=3D LPAE_ENTRIES; + p2m->stats.mappings[next_level] +=3D XEN_PT_LPAE_ENTRIES; =20 /* * Shatter superpage in the page to the level we want to make the @@ -888,7 +889,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, p2m_access_t a) { unsigned int level =3D 0; - unsigned int target =3D 3 - (page_order / LPAE_SHIFT); + unsigned int target =3D 3 - (page_order / XEN_PT_LPAE_SHIFT); lpae_t *entry, *table, orig_pte; int rc; /* A mapping is removed if the MFN is invalid. */ @@ -1142,7 +1143,7 @@ static void p2m_invalidate_table(struct p2m_domain *p= 2m, mfn_t mfn) =20 table =3D map_domain_page(mfn); =20 - for ( i =3D 0; i < LPAE_ENTRIES; i++ ) + for ( i =3D 0; i < XEN_PT_LPAE_ENTRIES; i++ ) { lpae_t pte =3D table[i]; =20 --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645438970; cv=none; d=zohomail.com; s=zohoarc; b=lrql5vbBxuyxg2nFGTymp0K1/593ndFKlsVRYkv/NwEJW666QA50O1C1ylHLV6aMbal9ydVnHoAoDB70jIchc6envRSrIXs5yC94bzgvilQ9uPE3kHIik0MyhjmWJgUT3dwd5J2FOPp9SymdzHPfMwnaoQCFJFlmaL4c5T9x1wI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645438970; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MXWuUJ4Gmt9SmtDQvOOz1c2o08azUVVOAJUW5p8Yymw=; b=A92AwWz1aL1H3wpA1/0/iOgeOVJ1kCxKfIbCrwe8zA2qJo8r1qS6gMzyP5XIOTJ8T89vpEj7l526GG/j83Uq2Ph/tZBfjd1iFbkqBMD5Am/+gNeHNqVteMUWhGDh1UfRxfmxqXqCIq0EaTwspyM3sLYOAjOfj63b1PjfR9M6gi4= 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 1645438969773808.6300429215946; Mon, 21 Feb 2022 02:22:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.275989.472025 (Exim 4.92) (envelope-from ) id 1nM5pr-0004ny-Az; Mon, 21 Feb 2022 10:22:27 +0000 Received: by outflank-mailman (output) from mailman id 275989.472025; Mon, 21 Feb 2022 10:22: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 1nM5pr-0004nL-2Z; Mon, 21 Feb 2022 10:22:27 +0000 Received: by outflank-mailman (input) for mailman id 275989; Mon, 21 Feb 2022 10:22:26 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pq-0004cB-3l for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:22:26 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pp-0002Ay-VE; Mon, 21 Feb 2022 10:22:25 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5pp-00070b-Nh; Mon, 21 Feb 2022 10:22: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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=MXWuUJ4Gmt9SmtDQvOOz1c2o08azUVVOAJUW5p8Yymw=; b=QLO96n1xIu6/SHSb3SXM+I+P6F 52Xx7khHqRnfeSkjkrvlruIRBxcGXkytgs7C0p+wVNyfG/mrykGKosZ780IoW9alQzdE2HJvn+77M e6Yd/5r9n2qbGkVTn32WCx+h3ojkIJ9ePXoZkNj9gefcCGHqDu2BfI/oIoItnyCICyIE=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 03/19] xen/arm: p2m: Replace level_{orders, masks} arrays with XEN_PT_LEVEL_{ORDER, MASK} Date: Mon, 21 Feb 2022 10:22:02 +0000 Message-Id: <20220221102218.33785-4-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645438972279100006 Content-Type: text/plain; charset="utf-8" From: Julien Grall The array level_orders and level_masks can be replaced with the recently introduced macros LEVEL_ORDER and LEVEL_MASK. Signed-off-by: Julien Grall Reviewed-by: Bertrand Marquis --- Changes in v3: - Fix clashes after prefixing the PT macros with XEN_PT_ Changes in v2: - New patch The goal is to remove completely the static arrays so they don't need to be global (or duplicated) when adding superpage support for Xen PT. This also has the added benefits to replace a couple of loads with only a few instructions working on immediate. --- xen/arch/arm/p2m.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 493a1e25879a..1d1059f7d2bd 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -37,12 +37,6 @@ static unsigned int __read_mostly max_vmid =3D MAX_VMID_= 8_BIT; */ unsigned int __read_mostly p2m_ipa_bits =3D 64; =20 -/* Helpers to lookup the properties of each level */ -static const paddr_t level_masks[] =3D - { ZEROETH_MASK, FIRST_MASK, SECOND_MASK, THIRD_MASK }; -static const uint8_t level_orders[] =3D - { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER }; - static mfn_t __read_mostly empty_root_mfn; =20 static uint64_t generate_vttbr(uint16_t vmid, mfn_t root_mfn) @@ -233,7 +227,7 @@ static lpae_t *p2m_get_root_pointer(struct p2m_domain *= p2m, * we can't use (P2M_ROOT_LEVEL - 1) because the root level might be * 0. Yet we still want to check if all the unused bits are zeroed. */ - root_table =3D gfn_x(gfn) >> (level_orders[P2M_ROOT_LEVEL] + + root_table =3D gfn_x(gfn) >> (XEN_PT_LEVEL_ORDER(P2M_ROOT_LEVEL) + XEN_PT_LPAE_SHIFT); if ( root_table >=3D P2M_ROOT_PAGES ) return NULL; @@ -380,7 +374,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, if ( gfn_x(gfn) > gfn_x(p2m->max_mapped_gfn) ) { for ( level =3D P2M_ROOT_LEVEL; level < 3; level++ ) - if ( (gfn_x(gfn) & (level_masks[level] >> PAGE_SHIFT)) > + if ( (gfn_x(gfn) & (XEN_PT_LEVEL_MASK(level) >> PAGE_SHIFT)) > gfn_x(p2m->max_mapped_gfn) ) break; =20 @@ -423,7 +417,8 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, * The entry may point to a superpage. Find the MFN associated * to the GFN. */ - mfn =3D mfn_add(mfn, gfn_x(gfn) & ((1UL << level_orders[level]) - = 1)); + mfn =3D mfn_add(mfn, + gfn_x(gfn) & ((1UL << XEN_PT_LEVEL_ORDER(level)) - 1= )); =20 if ( valid ) *valid =3D lpae_is_valid(entry); @@ -434,7 +429,7 @@ out_unmap: =20 out: if ( page_order ) - *page_order =3D level_orders[level]; + *page_order =3D XEN_PT_LEVEL_ORDER(level); =20 return mfn; } @@ -808,7 +803,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m,= lpae_t *entry, /* Convenience aliases */ mfn_t mfn =3D lpae_get_mfn(*entry); unsigned int next_level =3D level + 1; - unsigned int level_order =3D level_orders[next_level]; + unsigned int level_order =3D XEN_PT_LEVEL_ORDER(next_level); =20 /* * This should only be called with target !=3D level and the entry is --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645438974; cv=none; d=zohomail.com; s=zohoarc; b=gZkgnMarAjXF/W99QoxyYR2YidIKEmjfoF+dw42L19awCZpKRtDqft4ADFtr3DC+ZTZe/aPSxreDIPNvc6HcLJgAxQrwdBMvloy2vYqko6TF9Km1jWmoCqGznKBnl2jUfThqEE9sawmVuhbRqA3QuggeOQNG8wuE5tKzurmjRwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645438974; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vdk2f2XtwtCP7lnk+xz6BHSsXzbsgK1tvinW1UcZ8Xk=; b=UqdiAwa8RHmAQr1GM134ewWUExqD1cyco/8DpmxCsZaOVJf+95WWJnwVHl5rFOtrDbDcfz5qoyayGXn6k81l6A4bR4YduqUl4KdUUqd0XIm1hmfT+9OUGX90yyNRznG0qDQ0BJ3eALUmf/bO7CXRufEDYORPowrChv5+RK4ANvQ= 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 1645438974148689.2691824530216; Mon, 21 Feb 2022 02:22:54 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.275990.472042 (Exim 4.92) (envelope-from ) id 1nM5pt-0005Kq-I8; Mon, 21 Feb 2022 10:22:29 +0000 Received: by outflank-mailman (output) from mailman id 275990.472042; Mon, 21 Feb 2022 10:22:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pt-0005Kb-Dd; Mon, 21 Feb 2022 10:22:29 +0000 Received: by outflank-mailman (input) for mailman id 275990; Mon, 21 Feb 2022 10:22:27 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pr-0004rs-Bw for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:22:27 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pr-0002BA-0w; Mon, 21 Feb 2022 10:22:27 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5pq-00070b-Po; Mon, 21 Feb 2022 10:22:26 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=vdk2f2XtwtCP7lnk+xz6BHSsXzbsgK1tvinW1UcZ8Xk=; b=kTPb7leRM9W9uI0SYo3zFhRB0e gnsx/mIbEeV/OzvpYoziEfEMN3JIi6icJkolvf5BDgq9JZKzaA9+XdC73c6L/v5Wqvz/Rd+KNXYzl i1R+wWU9eySsU9kaTqxrJTPud6L7wgWnARfWjlpvvKJdbcUSTrgimeW21uqbsHliqny8=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall Subject: [PATCH v3 04/19] xen/arm: mm: Allow other mapping size in xen_pt_update_entry() Date: Mon, 21 Feb 2022 10:22:03 +0000 Message-Id: <20220221102218.33785-5-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645438976318100017 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment, xen_pt_update_entry() only supports mapping at level 3 (i.e 4KB mapping). While this is fine for most of the runtime helper, the boot code will require to use superpage mapping. We don't want to allow superpage mapping by default as some of the callers may expect small mappings (i.e populate_pt_range()) or even expect to unmap only a part of a superpage. To keep the code simple, a new flag _PAGE_BLOCK is introduced to allow the caller to enable superpage mapping. As the code doesn't support all the combinations, xen_pt_check_entry() is extended to take into account the cases we don't support when using block mapping: - Replacing a table with a mapping. This may happen if region was first mapped with 4KB mapping and then later on replaced with a 2MB (or 1GB mapping). - Removing/modifying a table. This may happen if a caller try to remove a region with _PAGE_BLOCK set when it was created without it. Note that the current restriction means that the caller must ensure that _PAGE_BLOCK is consistently set/cleared across all the updates on a given virtual region. This ought to be fine with the expected use-cases. More rework will be necessary if we wanted to remove the restrictions. Note that nr_mfns is now marked const as it is used for flushing the TLBs and we don't want it to be modified. Signed-off-by: Julien Grall Signed-off-by: Julien Grall --- Changes in v3: - Fix clash after prefixing the PT macros with XEN_PT_ - Fix typoes in the commit message - Support superpage mappings even if nr is not suitably aligned - Move the logic to find the level in a separate function Changes in v2: - Pass the target level rather than the order to xen_pt_update_entry() - Update some comments - Open-code paddr_to_pfn() - Add my AWS signed-off-by --- xen/arch/arm/include/asm/page.h | 4 ++ xen/arch/arm/mm.c | 108 ++++++++++++++++++++++++++------ 2 files changed, 94 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/include/asm/page.h b/xen/arch/arm/include/asm/pag= e.h index c6f9fb0d4e0c..07998df47bac 100644 --- a/xen/arch/arm/include/asm/page.h +++ b/xen/arch/arm/include/asm/page.h @@ -69,6 +69,7 @@ * [3:4] Permission flags * [5] Page present * [6] Only populate page tables + * [7] Superpage mappings is allowed */ #define PAGE_AI_MASK(x) ((x) & 0x7U) =20 @@ -82,6 +83,9 @@ #define _PAGE_PRESENT (1U << 5) #define _PAGE_POPULATE (1U << 6) =20 +#define _PAGE_BLOCK_BIT 7 +#define _PAGE_BLOCK (1U << _PAGE_BLOCK_BIT) + /* * _PAGE_DEVICE and _PAGE_NORMAL are convenience defines. They are not * meant to be used outside of this header. diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 515d0906f85b..3af69b396bd1 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1063,9 +1063,10 @@ static int xen_pt_next_level(bool read_only, unsigne= d int level, } =20 /* Sanity check of the entry */ -static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) +static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int level, + unsigned int flags) { - /* Sanity check when modifying a page. */ + /* Sanity check when modifying an entry. */ if ( (flags & _PAGE_PRESENT) && mfn_eq(mfn, INVALID_MFN) ) { /* We don't allow modifying an invalid entry. */ @@ -1075,6 +1076,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t m= fn, unsigned int flags) return false; } =20 + /* We don't allow modifying a table entry */ + if ( !lpae_is_mapping(entry, level) ) + { + mm_printk("Modifying a table entry is not allowed.\n"); + return false; + } + /* We don't allow changing memory attributes. */ if ( entry.pt.ai !=3D PAGE_AI_MASK(flags) ) { @@ -1090,7 +1098,7 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mf= n, unsigned int flags) return false; } } - /* Sanity check when inserting a page */ + /* Sanity check when inserting a mapping */ else if ( flags & _PAGE_PRESENT ) { /* We should be here with a valid MFN. */ @@ -1099,18 +1107,28 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t = mfn, unsigned int flags) /* We don't allow replacing any valid entry. */ if ( lpae_is_valid(entry) ) { - mm_printk("Changing MFN for a valid entry is not allowed (%#"P= RI_mfn" -> %#"PRI_mfn").\n", - mfn_x(lpae_get_mfn(entry)), mfn_x(mfn)); + if ( lpae_is_mapping(entry, level) ) + mm_printk("Changing MFN for a valid entry is not allowed (= %#"PRI_mfn" -> %#"PRI_mfn").\n", + mfn_x(lpae_get_mfn(entry)), mfn_x(mfn)); + else + mm_printk("Trying to replace a table with a mapping.\n"); return false; } } - /* Sanity check when removing a page. */ + /* Sanity check when removing a mapping. */ else if ( (flags & (_PAGE_PRESENT|_PAGE_POPULATE)) =3D=3D 0 ) { /* We should be here with an invalid MFN. */ ASSERT(mfn_eq(mfn, INVALID_MFN)); =20 - /* We don't allow removing page with contiguous bit set. */ + /* We don't allow removing a table */ + if ( lpae_is_table(entry, level) ) + { + mm_printk("Removing a table is not allowed.\n"); + return false; + } + + /* We don't allow removing a mapping with contiguous bit set. */ if ( entry.pt.contig ) { mm_printk("Removing entry with contiguous bit set is not allow= ed.\n"); @@ -1128,13 +1146,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t = mfn, unsigned int flags) return true; } =20 +/* Update an entry at the level @target. */ static int xen_pt_update_entry(mfn_t root, unsigned long virt, - mfn_t mfn, unsigned int flags) + mfn_t mfn, unsigned int target, + unsigned int flags) { int rc; unsigned int level; - /* We only support 4KB mapping (i.e level 3) for now */ - unsigned int target =3D 3; lpae_t *table; /* * The intermediate page tables are read-only when the MFN is not valid @@ -1189,7 +1207,7 @@ static int xen_pt_update_entry(mfn_t root, unsigned l= ong virt, entry =3D table + offsets[level]; =20 rc =3D -EINVAL; - if ( !xen_pt_check_entry(*entry, mfn, flags) ) + if ( !xen_pt_check_entry(*entry, mfn, level, flags) ) goto out; =20 /* If we are only populating page-table, then we are done. */ @@ -1207,8 +1225,11 @@ static int xen_pt_update_entry(mfn_t root, unsigned = long virt, { pte =3D mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); =20 - /* Third level entries set pte.pt.table =3D 1 */ - pte.pt.table =3D 1; + /* + * First and second level pages set pte.pt.table =3D 0, but + * third level entries set pte.pt.table =3D 1. + */ + pte.pt.table =3D (level =3D=3D 3); } else /* We are updating the permission =3D> Copy the current pte. = */ pte =3D *entry; @@ -1228,15 +1249,56 @@ out: return rc; } =20 +/* Return the level where mapping should be done */ +static int xen_pt_mapping_level(unsigned long vfn, mfn_t mfn, unsigned lon= g nr, + unsigned int flags) +{ + unsigned int level; + unsigned long mask; + + /* + * Don't take into account the MFN when removing mapping (i.e + * MFN_INVALID) to calculate the correct target order. + * + * Per the Arm Arm, `vfn` and `mfn` must be both superpage aligned. + * They are or-ed together and then checked against the size of + * each level. + * + * `left` is not included and checked separately to allow + * superpage mapping even if it is not properly aligned (the + * user may have asked to map 2MB + 4k). + */ + mask =3D !mfn_eq(mfn, INVALID_MFN) ? mfn_x(mfn) : 0; + mask |=3D vfn; + + /* + * Always use level 3 mapping unless the caller request block + * mapping. + */ + if ( likely(!(flags & _PAGE_BLOCK)) ) + level =3D 3; + else if ( !(mask & (BIT(FIRST_ORDER, UL) - 1)) && + (nr >=3D BIT(FIRST_ORDER, UL)) ) + level =3D 1; + else if ( !(mask & (BIT(SECOND_ORDER, UL) - 1)) && + (nr >=3D BIT(SECOND_ORDER, UL)) ) + level =3D 2; + else + level =3D 3; + + return level; +} + static DEFINE_SPINLOCK(xen_pt_lock); =20 static int xen_pt_update(unsigned long virt, mfn_t mfn, - unsigned long nr_mfns, + const unsigned long nr_mfns, unsigned int flags) { int rc =3D 0; - unsigned long addr =3D virt, addr_end =3D addr + nr_mfns * PAGE_SIZE; + unsigned long vfn =3D virt >> PAGE_SHIFT; + unsigned long left =3D nr_mfns; =20 /* * For arm32, page-tables are different on each CPUs. Yet, they share @@ -1268,14 +1330,24 @@ static int xen_pt_update(unsigned long virt, =20 spin_lock(&xen_pt_lock); =20 - for ( ; addr < addr_end; addr +=3D PAGE_SIZE ) + while ( left ) { - rc =3D xen_pt_update_entry(root, addr, mfn, flags); + unsigned int order, level; + + level =3D xen_pt_mapping_level(vfn, mfn, left, flags); + order =3D XEN_PT_LEVEL_ORDER(level); + + ASSERT(left >=3D BIT(order, UL)); + + rc =3D xen_pt_update_entry(root, pfn_to_paddr(vfn), mfn, level, fl= ags); if ( rc ) break; =20 + vfn +=3D 1U << order; if ( !mfn_eq(mfn, INVALID_MFN) ) - mfn =3D mfn_add(mfn, 1); + mfn =3D mfn_add(mfn, 1U << order); + + left -=3D (1U << order); } =20 /* --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645438970; cv=none; d=zohomail.com; s=zohoarc; b=DOWSFKoGaVeKSXgSIYT4cYZZy7fXLvQEWPPKK7vFplHlTIfVWdb+8VXbJj1T8oT15y4sOGxC7JUViGFobwZUpocRhUSUpAjXh3r45Og0X2eD9X58DbiRLbsCWKIjB/s1PXH9UGUWq+oKyn9JCeYLN87jTJc7ZptkDXGjxVhxBCA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645438970; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sFYaVlLq15N1H/anRoXOtrE4yZfgYVYOPXSH6aKnS1c=; b=ltgE1d+md9q/dfXuGC1/OHT8Jvd55gfv/1N8w9JUwzfkKFhxX22xMkImN+csiCHq7SC3eD/4n89DKSaEa6GRzGrwRNMXCbY7tEHIt5wIAVlcf2/12e/2PC8JDjWQ6UUinjcmyWzpsKcSMHgyQgAlnPxgHzYg5PosG+cvAMhCOIo= 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 1645438970859614.3655356959625; Mon, 21 Feb 2022 02:22:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.275991.472047 (Exim 4.92) (envelope-from ) id 1nM5pt-0005OH-Ug; Mon, 21 Feb 2022 10:22:29 +0000 Received: by outflank-mailman (output) from mailman id 275991.472047; Mon, 21 Feb 2022 10:22:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pt-0005NJ-Nz; Mon, 21 Feb 2022 10:22:29 +0000 Received: by outflank-mailman (input) for mailman id 275991; Mon, 21 Feb 2022 10:22:28 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5ps-0005Ck-8L for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:22:28 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pr-0002BM-W9; Mon, 21 Feb 2022 10:22:27 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5pr-00070b-Oo; Mon, 21 Feb 2022 10:22:27 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=sFYaVlLq15N1H/anRoXOtrE4yZfgYVYOPXSH6aKnS1c=; b=JwDq/w/csOKozdfgbxUMXi5DOG qsRCDVP8kNgM0ZZY1v42hOsAJxCK80gkaDYUgzlchR7Rc/WvhTL1k2Jdx7nr0560Xgq77Y0m07bpk 92KNHKUdvP9o5WBxr+I/Cm8y5ltfFvdcHHiPgG5ekHlD+0wtfmEZ9JgIeiuAKqyaO+lU=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 05/19] xen/arm: mm: Add support for the contiguous bit Date: Mon, 21 Feb 2022 10:22:04 +0000 Message-Id: <20220221102218.33785-6-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645438972278100005 Content-Type: text/plain; charset="utf-8" From: Julien Grall In follow-up patches, we will use xen_pt_update() (or its callers) to handle large mappings (e.g. frametable, xenheap). They are also not going to be modified once created. The page-table entries have an hint to indicate that whether an entry is contiguous to another 16 entries (assuming 4KB). When the processor support the hint, one TLB entry will be created per contiguous region. For now this is tied to _PAGE_BLOCK. We can untie it in the future if there are use-cases where we may want to use _PAGE_BLOCK without setting the contiguous (couldn't think of any yet). Note that to avoid extra complexity, mappings with the contiguous bit set cannot be removed. Given the expected use, this restriction ought to be fine. Signed-off-by: Julien Grall Reviewed-by: Hongda Deng Reviewed-by: Stefano Stabellini --- Changes in v3: - New patch --- xen/arch/arm/include/asm/page.h | 4 ++ xen/arch/arm/mm.c | 80 ++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/include/asm/page.h b/xen/arch/arm/include/asm/pag= e.h index 07998df47bac..e7cd62190c7f 100644 --- a/xen/arch/arm/include/asm/page.h +++ b/xen/arch/arm/include/asm/page.h @@ -70,6 +70,7 @@ * [5] Page present * [6] Only populate page tables * [7] Superpage mappings is allowed + * [8] Set contiguous bit (internal flag) */ #define PAGE_AI_MASK(x) ((x) & 0x7U) =20 @@ -86,6 +87,9 @@ #define _PAGE_BLOCK_BIT 7 #define _PAGE_BLOCK (1U << _PAGE_BLOCK_BIT) =20 +#define _PAGE_CONTIG_BIT 8 +#define _PAGE_CONTIG (1U << _PAGE_CONTIG_BIT) + /* * _PAGE_DEVICE and _PAGE_NORMAL are convenience defines. They are not * meant to be used outside of this header. diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 3af69b396bd1..fd16c1541ce2 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1237,6 +1237,8 @@ static int xen_pt_update_entry(mfn_t root, unsigned l= ong virt, /* Set permission */ pte.pt.ro =3D PAGE_RO_MASK(flags); pte.pt.xn =3D PAGE_XN_MASK(flags); + /* Set contiguous bit */ + pte.pt.contig =3D !!(flags & _PAGE_CONTIG); } =20 write_pte(entry, pte); @@ -1289,6 +1291,51 @@ static int xen_pt_mapping_level(unsigned long vfn, m= fn_t mfn, unsigned long nr, return level; } =20 +#define XEN_PT_4K_NR_CONTIG 16 + +/* + * Check whether the contiguous bit can be set. Return the number of + * contiguous entry allowed. If not allowed, return 1. + */ +static unsigned int xen_pt_check_contig(unsigned long vfn, mfn_t mfn, + unsigned int level, unsigned long = left, + unsigned int flags) +{ + unsigned long nr_contig; + + /* + * Allow the contiguous bit to set when the caller requests block + * mapping. + */ + if ( !(flags & _PAGE_BLOCK) ) + return 1; + + /* + * We don't allow to remove mapping with the contiguous bit set. + * So shortcut the logic and directly return 1. + */ + if ( mfn_eq(mfn, INVALID_MFN) ) + return 1; + + /* + * The number of contiguous entries varies depending on the page + * granularity used. The logic below assumes 4KB. + */ + BUILD_BUG_ON(PAGE_SIZE !=3D SZ_4K); + + /* + * In order to enable the contiguous bit, we should have enough entries + * to map left and both the virtual and physical address should be + * aligned to the size of 16 translation tables entries. + */ + nr_contig =3D BIT(XEN_PT_LEVEL_ORDER(level), UL) * XEN_PT_4K_NR_CONTIG; + + if ( (left < nr_contig) || ((mfn_x(mfn) | vfn) & (nr_contig - 1)) ) + return 1; + + return XEN_PT_4K_NR_CONTIG; +} + static DEFINE_SPINLOCK(xen_pt_lock); =20 static int xen_pt_update(unsigned long virt, @@ -1322,6 +1369,12 @@ static int xen_pt_update(unsigned long virt, return -EINVAL; } =20 + if ( flags & _PAGE_CONTIG ) + { + mm_printk("_PAGE_CONTIG is an internal only flag.\n"); + return -EINVAL; + } + if ( !IS_ALIGNED(virt, PAGE_SIZE) ) { mm_printk("The virtual address is not aligned to the page-size.\n"= ); @@ -1333,21 +1386,34 @@ static int xen_pt_update(unsigned long virt, while ( left ) { unsigned int order, level; + unsigned int nr_contig; + unsigned int new_flags; =20 level =3D xen_pt_mapping_level(vfn, mfn, left, flags); order =3D XEN_PT_LEVEL_ORDER(level); =20 ASSERT(left >=3D BIT(order, UL)); =20 - rc =3D xen_pt_update_entry(root, pfn_to_paddr(vfn), mfn, level, fl= ags); - if ( rc ) - break; + /* + * Check if we can set the contiguous mapping and update the + * flags accordingly. + */ + nr_contig =3D xen_pt_check_contig(vfn, mfn, level, left, flags); + new_flags =3D flags | ((nr_contig > 1) ? _PAGE_CONTIG : 0); =20 - vfn +=3D 1U << order; - if ( !mfn_eq(mfn, INVALID_MFN) ) - mfn =3D mfn_add(mfn, 1U << order); + for ( ; nr_contig > 0; nr_contig-- ) + { + rc =3D xen_pt_update_entry(root, pfn_to_paddr(vfn), mfn, level, + new_flags); + if ( rc ) + break; =20 - left -=3D (1U << order); + vfn +=3D 1U << order; + if ( !mfn_eq(mfn, INVALID_MFN) ) + mfn =3D mfn_add(mfn, 1U << order); + + left -=3D (1U << order); + } } =20 /* --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645438969; cv=none; d=zohomail.com; s=zohoarc; b=ICctFe5JXdDGSg+ferCp+Qn6lJJCKIBPLHd3VlF29KyV3q0esVqExHHO+Xx1rRIawahv6yIgrjVS+k1wmj+QkkpxDNSqt31JteAlFOB7pd9gra8xvXKo4Abq4gwE3pdE8GelkUxkaMnTeEJ/cTk+U4NtbHNEPJ5ituSMo+KAycc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645438969; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0n6etsYqo9bTpW5hKB66bUfArotdLsp5P4nlJNvCktk=; b=a6UqPEgEL+FJHjos8b/mC8oBhwXnBhiHxTnhWQUX70ex76HSAtZPW/pIrSKoI/FbKQ8DEdG5he6MkIBIWvzRJ2h8xDmhoEy357JccCjabFpPU+HnW6gFQrD+Io/uja8U8u6NbIGHipa75xvBsLj46mmFNYX2Al7if+w6wTcxv2I= 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 1645438969082342.8411151973705; Mon, 21 Feb 2022 02:22:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.275992.472053 (Exim 4.92) (envelope-from ) id 1nM5pu-0005Wb-Vb; Mon, 21 Feb 2022 10:22:30 +0000 Received: by outflank-mailman (output) from mailman id 275992.472053; Mon, 21 Feb 2022 10:22:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pu-0005UD-C0; Mon, 21 Feb 2022 10:22:30 +0000 Received: by outflank-mailman (input) for mailman id 275992; Mon, 21 Feb 2022 10:22:29 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pt-0005K5-3e for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:22:29 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5ps-0002Bb-VA; Mon, 21 Feb 2022 10:22:28 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5ps-00070b-Nq; Mon, 21 Feb 2022 10:22:28 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=0n6etsYqo9bTpW5hKB66bUfArotdLsp5P4nlJNvCktk=; b=hpgsGAWjKmB3nCSgB72nz6fMpj r5/GlFDET7YiB2drOVybCDihBpbWM3SlDyrUqXpruffX2XpjwkPE6cv4hWqvOVQCUIxsTt7LGN+38 362aFG77G5lHwua6lUDhpNwJ3AxG30RyARIlXYyQuB4XK18ZGjEAJ6805oSnkYXwQdY8=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 06/19] xen/arm: mm: Avoid flushing the TLBs when mapping are inserted Date: Mon, 21 Feb 2022 10:22:05 +0000 Message-Id: <20220221102218.33785-7-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645438970524100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall Currently, the function xen_pt_update() will flush the TLBs even when the mappings are inserted. This is a bit wasteful because we don't allow mapping replacement. Even if we were, the flush would need to happen earlier because mapping replacement should use Break-Before-Make when updating the entry. A single call to xen_pt_update() can perform a single action. IOW, it is not possible to, for instance, mix inserting and removing mappings. Therefore, we can use `flags` to determine what action is performed. This change will be particularly help to limit the impact of switching boot time mapping to use xen_pt_update(). Signed-off-by: Julien Grall --- Changes in v2: - New patch --- xen/arch/arm/mm.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index fd16c1541ce2..7b4b9de8693e 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1104,7 +1104,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t m= fn, unsigned int level, /* We should be here with a valid MFN. */ ASSERT(!mfn_eq(mfn, INVALID_MFN)); =20 - /* We don't allow replacing any valid entry. */ + /* + * We don't allow replacing any valid entry. + * + * Note that the function xen_pt_update() relies on this + * assumption and will skip the TLB flush. The function will need + * to be updated if the check is relaxed. + */ if ( lpae_is_valid(entry) ) { if ( lpae_is_mapping(entry, level) ) @@ -1417,11 +1423,16 @@ static int xen_pt_update(unsigned long virt, } =20 /* - * Flush the TLBs even in case of failure because we may have + * The TLBs flush can be safely skipped when a mapping is inserted + * as we don't allow mapping replacement (see xen_pt_check_entry()). + * + * For all the other cases, the TLBs will be flushed unconditionally + * even if the mapping has failed. This is because we may have * partially modified the PT. This will prevent any unexpected * behavior afterwards. */ - flush_xen_tlb_range_va(virt, PAGE_SIZE * nr_mfns); + if ( !(flags & _PAGE_PRESENT) || mfn_eq(mfn, INVALID_MFN) ) + flush_xen_tlb_range_va(virt, PAGE_SIZE * nr_mfns); =20 spin_unlock(&xen_pt_lock); =20 --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645438969; cv=none; d=zohomail.com; s=zohoarc; b=TVm4P6RtYPhiLbhSJyOiuuyxUQwY5hmmbxUcMtYMX6NfAlZ7SX9lqXUF9z9x3dDIRrLTZz6gycGwjjIyrM7D76qGy9zx1SyVPVMdqGWgGcj4b5VfA0x/Bb5Q9E+Rv4DBawqwtKa8kIrV9DVKnEnUOZsoIHfNa0sXGIcv6MLh3as= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645438969; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gj6Tx1Ts6XYE8jhOQFSpNUB23rP/9Mj+pm8BtVXwdgI=; b=UTdujFhCG6G5AmgvkGmueIVpkOcvNyQEz/EU927hIVzZEl0aTKY0OXk/rvkA3f79Ls6JArhn70jrWbG0SclK88iOQBEyp59Mx2BWhlJzGkaivCtBmnO7nfTT3vIFTNsmaTWBQFEOobF73THWAML2ZtdapEzZ1hPzjDA2QbfmrzY= 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 1645438969523487.9758771647058; Mon, 21 Feb 2022 02:22:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.275993.472074 (Exim 4.92) (envelope-from ) id 1nM5px-0006C9-0p; Mon, 21 Feb 2022 10:22:33 +0000 Received: by outflank-mailman (output) from mailman id 275993.472074; Mon, 21 Feb 2022 10:22:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pw-00069E-M3; Mon, 21 Feb 2022 10:22:32 +0000 Received: by outflank-mailman (input) for mailman id 275993; Mon, 21 Feb 2022 10:22:30 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pu-0005TR-6s for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:22:30 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pu-0002Bn-0t; Mon, 21 Feb 2022 10:22:30 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5pt-00070b-Pv; Mon, 21 Feb 2022 10:22:29 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=gj6Tx1Ts6XYE8jhOQFSpNUB23rP/9Mj+pm8BtVXwdgI=; b=uVjIeenzjjYRsw54H1HNYmxQfw 3v2o/47jmnPmphrWNR5brpLJwHw36oVfIHhVYQH/HTvGFTztGzzBTXDPQ4l4FHFzZkV0lnJXXR4g9 on+BkY3BJRTt+4hUBLh0xl947Qr63WSRovux0mdJsfwxG8NGpG/GuF77r2jda4RwhMI4=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall Subject: [PATCH v3 07/19] xen/arm: mm: Don't open-code Xen PT update in remove_early_mappings() Date: Mon, 21 Feb 2022 10:22:06 +0000 Message-Id: <20220221102218.33785-8-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645438996005100004 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that xen_pt_update_entry() is able to deal with different mapping size, we can replace the open-coding of the page-tables update by a call to modify_xen_mappings(). As the function is not meant to fail, a BUG_ON() is added to check the return. Signed-off-by: Julien Grall Signed-off-by: Julien Grall --- Changes in v2: - Stay consistent with how function name are used in the commit message - Add my AWS signed-off-by --- xen/arch/arm/mm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7b4b9de8693e..f088a4b2de96 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -599,11 +599,11 @@ void * __init early_fdt_map(paddr_t fdt_paddr) =20 void __init remove_early_mappings(void) { - lpae_t pte =3D {0}; - write_pte(xen_second + second_table_offset(BOOT_FDT_VIRT_START), pte); - write_pte(xen_second + second_table_offset(BOOT_FDT_VIRT_START + SZ_2M= ), - pte); - flush_xen_tlb_range_va(BOOT_FDT_VIRT_START, BOOT_FDT_SLOT_SIZE); + int rc; + + rc =3D modify_xen_mappings(BOOT_FDT_VIRT_START, BOOT_FDT_VIRT_END, + _PAGE_BLOCK); + BUG_ON(rc); } =20 /* --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645438971; cv=none; d=zohomail.com; s=zohoarc; b=WC8bQtICumrinYL0q1gYZSdhMdZTCbtzP1uVl+rG1o0K40hjNAEWmZXyEA40MWqXgHPV54Ox36CwV/Ep64sBVnvfDBeVgudstPJNniwwP6k10SV/ulFTVNtGl/1iw81uBDkc1+0s0UuOHx7ubh+qJwAJVN+0/c6hOBAQ6fjKNwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645438971; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=m0aLEbK54kAkQt7srRGP8ZDAT2HpX86Y4s8RUrJJBLI=; b=ZwMJv+ZJoIp6hrOC2MBNKiwtqUZ+sCnL7haVEpKiwrQYFpdhKAeD75lhEMKjLfdGfDSHNPiAiVPNC6I7SyAaSEYx+12ZkqQ83LlnC4xCialxilFV7+BXk3RKwwbWBNOuxkmbpTxzYe38daWMuUgDEgxzsUDu47nkc53WoddqCmI= 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 1645438971290580.0385466743701; Mon, 21 Feb 2022 02:22:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.275994.472080 (Exim 4.92) (envelope-from ) id 1nM5px-0006IG-Hp; Mon, 21 Feb 2022 10:22:33 +0000 Received: by outflank-mailman (output) from mailman id 275994.472080; Mon, 21 Feb 2022 10:22:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5px-0006HB-7k; Mon, 21 Feb 2022 10:22:33 +0000 Received: by outflank-mailman (input) for mailman id 275994; Mon, 21 Feb 2022 10:22:31 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pv-0005iU-7R for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:22:31 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pv-0002C8-37; Mon, 21 Feb 2022 10:22:31 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5pu-00070b-S1; Mon, 21 Feb 2022 10:22:31 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=m0aLEbK54kAkQt7srRGP8ZDAT2HpX86Y4s8RUrJJBLI=; b=z3x1rDlnxMesdj9WXzr3h3/heK Dlu/SsDx31w1y3YKAWXT4NuufWw+g6cm5+XJ0yg4LlcZz9s7rslvsZ11GlZ+CLEj6zsSzm1sagUg8 54huy996LvdrKXYXtDPp9Ouvc7TEzOy8rCyt+hSJVxKGKhBmI9Qoi4t60d2r6Cfm2Vrs=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall Subject: [PATCH v3 08/19] xen/arm: mm: Re-implement early_fdt_map() using map_pages_to_xen() Date: Mon, 21 Feb 2022 10:22:07 +0000 Message-Id: <20220221102218.33785-9-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645438974329100013 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that map_pages_to_xen() has been extended to support 2MB mappings, we can replace the create_mappings() calls by map_pages_to_xen() calls. The mapping can also be marked read-only has Xen as no business to modify the host Device Tree. Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: Hongda Deng --- Changes in v2: - Add my AWS signed-off-by - Fix typo in the commit message --- xen/arch/arm/mm.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index f088a4b2de96..24de8dcb9042 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -559,6 +559,7 @@ void * __init early_fdt_map(paddr_t fdt_paddr) paddr_t offset; void *fdt_virt; uint32_t size; + int rc; =20 /* * Check whether the physical FDT address is set and meets the minimum @@ -574,8 +575,12 @@ void * __init early_fdt_map(paddr_t fdt_paddr) /* The FDT is mapped using 2MB superpage */ BUILD_BUG_ON(BOOT_FDT_VIRT_START % SZ_2M); =20 - create_mappings(xen_second, BOOT_FDT_VIRT_START, paddr_to_pfn(base_pad= dr), - SZ_2M >> PAGE_SHIFT, SZ_2M); + rc =3D map_pages_to_xen(BOOT_FDT_VIRT_START, maddr_to_mfn(base_paddr), + SZ_2M >> PAGE_SHIFT, + PAGE_HYPERVISOR_RO | _PAGE_BLOCK); + if ( rc ) + panic("Unable to map the device-tree.\n"); + =20 offset =3D fdt_paddr % SECOND_SIZE; fdt_virt =3D (void *)BOOT_FDT_VIRT_START + offset; @@ -589,9 +594,12 @@ void * __init early_fdt_map(paddr_t fdt_paddr) =20 if ( (offset + size) > SZ_2M ) { - create_mappings(xen_second, BOOT_FDT_VIRT_START + SZ_2M, - paddr_to_pfn(base_paddr + SZ_2M), - SZ_2M >> PAGE_SHIFT, SZ_2M); + rc =3D map_pages_to_xen(BOOT_FDT_VIRT_START + SZ_2M, + maddr_to_mfn(base_paddr + SZ_2M), + SZ_2M >> PAGE_SHIFT, + PAGE_HYPERVISOR_RO | _PAGE_BLOCK); + if ( rc ) + panic("Unable to map the device-tree\n"); } =20 return fdt_virt; --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645438972; cv=none; d=zohomail.com; s=zohoarc; b=j0iM2DWlG2u76gfraAKJaRZ+EJ1KTp3qQvz1SrDtQJlxKjHxAXqtP62yI+BZIuQw+vg5nutIS6eSN2Tj3Gjz2aAFTpK1C5irjlVtrmltzjQ3xh1yxT/6UkLe+ifc+StmcWvvOgsL9b9gzFe3HwRUKWVE+hgXc8tSS6/uHI2qn+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645438972; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f5eydWA/xrVr2E4ET4uKtIXdg9zT+/rA87h+Dp/T1XQ=; b=nbvnSLZ6YyHJcXgovji2usKAkjeAmdbNaa0LYJ7V/jsss1VMNjt4W2E2kRULkwPd65Grz0of1E7PctitxPw06xap/tGGbS1oxoKhzqfQSKm6/OsESG8cjV6OtJr/1Babxbdi6xO029or8fSawt34T/eBV0I8qROtB5RB2UY64Ss= 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 1645438972692798.4185337550989; Mon, 21 Feb 2022 02:22:52 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.275995.472085 (Exim 4.92) (envelope-from ) id 1nM5py-0006Pq-CR; Mon, 21 Feb 2022 10:22:34 +0000 Received: by outflank-mailman (output) from mailman id 275995.472085; Mon, 21 Feb 2022 10:22:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5px-0006O3-Og; Mon, 21 Feb 2022 10:22:33 +0000 Received: by outflank-mailman (input) for mailman id 275995; Mon, 21 Feb 2022 10:22:32 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pw-00062Y-9Z for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:22:32 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM5pw-0002CP-22; Mon, 21 Feb 2022 10:22:32 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5pv-00070b-R2; Mon, 21 Feb 2022 10:22:32 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=f5eydWA/xrVr2E4ET4uKtIXdg9zT+/rA87h+Dp/T1XQ=; b=kGZXEvUvAbBP8RABHqRfsx1pWV Ri+mN6arLvsf1/9WTidhs68lId5bZsdZ5BKsSTGfV/LtrsypqKt8+0I5eaj3ZgJ4Puhwknk+wugJb qEw7W6bp4sIPOni6pCivbopojiCa7mIIg7d8ZQveDVkm9muFF7wEKgBMvy7udwNT/8Jc=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 09/19] xen/arm32: mm: Check if the virtual address is shared before updating it Date: Mon, 21 Feb 2022 10:22:08 +0000 Message-Id: <20220221102218.33785-10-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645438974324100012 Content-Type: text/plain; charset="utf-8" From: Julien Grall Only the first 2GB of the virtual address space is shared between all the page-tables on Arm32. There is a long outstanding TODO in xen_pt_update() stating that the function can only work with shared mapping. Nobody has ever called the function with private mapping, however as we add more callers there is a risk to mess things up. Introduce a new define to mark the end of the shared mappings and use it in xen_pt_update() to verify if the address is correct. Note that on Arm64, all the mappings are shared. Some compiler may complain about an always true check, so the new define is not introduced for arm64 and the code is protected with an #ifdef. Signed-off-by: Julien Grall --- Changes in v2: - New patch --- xen/arch/arm/include/asm/config.h | 4 ++++ xen/arch/arm/mm.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/include/asm/config.h b/xen/arch/arm/include/asm/c= onfig.h index c7b77912013e..85d4a510ce8a 100644 --- a/xen/arch/arm/include/asm/config.h +++ b/xen/arch/arm/include/asm/config.h @@ -137,6 +137,10 @@ =20 #define XENHEAP_VIRT_START _AT(vaddr_t,0x40000000) #define XENHEAP_VIRT_END _AT(vaddr_t,0x7fffffff) + +/* The first 2GB is always shared between all the page-tables. */ +#define SHARED_VIRT_END _AT(vaddr_t, 0x7fffffff) + #define DOMHEAP_VIRT_START _AT(vaddr_t,0x80000000) #define DOMHEAP_VIRT_END _AT(vaddr_t,0xffffffff) =20 diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 24de8dcb9042..f18f65745595 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1365,11 +1365,18 @@ static int xen_pt_update(unsigned long virt, * For arm32, page-tables are different on each CPUs. Yet, they share * some common mappings. It is assumed that only common mappings * will be modified with this function. - * - * XXX: Add a check. */ const mfn_t root =3D virt_to_mfn(THIS_CPU_PGTABLE); =20 +#ifdef SHARED_VIRT_END + if ( virt > SHARED_VIRT_END || + (SHARED_VIRT_END - virt) < nr_mfns ) + { + mm_printk("Trying to map outside of the shared area.\n"); + return -EINVAL; + } +#endif + /* * The hardware was configured to forbid mapping both writeable and * executable. --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645440676; cv=none; d=zohomail.com; s=zohoarc; b=McksPCZByicssvaif3ZxdD4+BSoJKropOxOOLxrH+MMR7luTwPw5d410eXx1V5OITMJxD1QssvUHsxcih1bQ0H/7DB8VnyyIFW6ZO5hNL8zE10zDHj1sDR6RpzCYogGXdcL4VF5+RBGLDAXaAWJNPxKnYdP7gcZFeu68tK2lQEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645440676; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zEuypYbMOVU+QCEpQRIrLKSHSHuGJNjHPBiDujcG7MU=; b=JiRS/BuneigYQFRdX0oB6KIVb5r0pTaz+JnRvNn82/1WcYCz0bN9UViL8rrb5ayIP3YLjV+vub6DvBK9rwf2eCLgS/TkfQkID7tkAXzHX00jPBP+M4grjvxSFKtvcIDI4ICDFi5VJUs2ayAXpvMAq7uDSjnfkzCZQhviWReB33Y= 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 164544067615840.20015786305464; Mon, 21 Feb 2022 02:51:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.276090.472144 (Exim 4.92) (envelope-from ) id 1nM6HS-0006QQ-GM; Mon, 21 Feb 2022 10:50:58 +0000 Received: by outflank-mailman (output) from mailman id 276090.472144; Mon, 21 Feb 2022 10:50:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HS-0006QH-Az; Mon, 21 Feb 2022 10:50:58 +0000 Received: by outflank-mailman (input) for mailman id 276090; Mon, 21 Feb 2022 10:50:57 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0006Pn-I8 for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:50:57 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0002lS-6D; Mon, 21 Feb 2022 10:50:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5pw-00070b-Q2; Mon, 21 Feb 2022 10:22:33 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=zEuypYbMOVU+QCEpQRIrLKSHSHuGJNjHPBiDujcG7MU=; b=oD4C8Xy85gKcZSzamwua69gzJh vwmWHW3VGsBHpotI4HnvBmxqIi3fJRGT/PtfWcILV3mCMobBjoTKgwF+P8BkoX4Z+NMHHFrMbh05t l82nYJCrb5EbAVvUVtuPLZVSqH4FEwWBlOgZJykIVF/kxIFvVb5hzb8a5B2LzLPYzL/Y=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 10/19] xen/arm32: mm: Re-implement setup_xenheap_mappings() using map_pages_to_xen() Date: Mon, 21 Feb 2022 10:22:09 +0000 Message-Id: <20220221102218.33785-11-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645440684154100009 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that map_pages_to_xen() has been extended to support 2MB mappings, we can replace the create_mappings() call by map_pages_to_xen() call. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Fix build when CONFIG_DEBUG=3Dy Changes in v2: - New patch TODOs: - add support for contiguous mapping --- xen/arch/arm/mm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index f18f65745595..1e5c2c45dcf9 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -809,7 +809,12 @@ void mmu_init_secondary_cpu(void) void __init setup_xenheap_mappings(unsigned long base_mfn, unsigned long nr_mfns) { - create_mappings(xen_second, XENHEAP_VIRT_START, base_mfn, nr_mfns, MB(= 32)); + int rc; + + rc =3D map_pages_to_xen(XENHEAP_VIRT_START, _mfn(base_mfn), nr_mfns, + PAGE_HYPERVISOR_RW | _PAGE_BLOCK); + if ( rc ) + panic("Unable to setup the xenheap mappings.\n"); =20 /* Record where the xenheap is, for translation routines. */ xenheap_virt_end =3D XENHEAP_VIRT_START + nr_mfns * PAGE_SIZE; --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645440681; cv=none; d=zohomail.com; s=zohoarc; b=iSx/RPuT2AUk7kr6iAzHa4UxW8omFXhTdzIZVxK+SULawsDT94Fk6FmywF2WO+P4C0y2errbTXVpwyziCu0U2dDEwJ2pRDr/U5NUAKCX0QTdVK21oawxzPk0mfbx228S1wwKVPxdNaoQVm9arN1PvRn5Y1ouLQOf9TpT+xdikDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645440681; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hWjfevoUxZaDKcehRUZH+C4jM8zdEI8w51IWDQgtbOY=; b=ESu6TZyv6BqflAl22sqARZriwU6Tkk5soOMeYmD4U1BOP6m9UnZuF2JkStu3OCTToAWSKYnoKmBHZdMczLSl31Vekb0O4vAMMtDunJwpFlaSi9lViwrCo352yOxZCzDzE7PoD/e5xJiobGtr34dkxekthwf/BcMqtqeHATb2d8c= 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 1645440681547344.20547774137117; Mon, 21 Feb 2022 02:51:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.276095.472182 (Exim 4.92) (envelope-from ) id 1nM6HV-00077Z-5j; Mon, 21 Feb 2022 10:51:01 +0000 Received: by outflank-mailman (output) from mailman id 276095.472182; Mon, 21 Feb 2022 10:51:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HU-00073Q-OT; Mon, 21 Feb 2022 10:51:00 +0000 Received: by outflank-mailman (input) for mailman id 276095; Mon, 21 Feb 2022 10:50:58 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HS-0006QN-CA for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:50:58 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0002lY-C0; Mon, 21 Feb 2022 10:50:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5px-00070b-P2; Mon, 21 Feb 2022 10:22:33 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=hWjfevoUxZaDKcehRUZH+C4jM8zdEI8w51IWDQgtbOY=; b=RuUM164HznDXh6/dLShCUL7Lum EgpxRX1vKp5TmYi/aA/2lysuQY0Qdha+xIARUS7HqNl8nQjr9/2Nf1+AV/5IB7+NQMaTd0ueMU/Sj NV1g+ENGfjBa69WssNjj2ehEeY9/yty7yDBH+2WREYgwIIcfvU7MxEf4gKZMBEiLDmGo=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 11/19] xen/arm: mm: Allocate xen page tables in domheap rather than xenheap Date: Mon, 21 Feb 2022 10:22:10 +0000 Message-Id: <20220221102218.33785-12-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645440683005100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall xen_{un,}map_table() already uses the helper to map/unmap pages on-demand (note this is currently a NOP on arm64). So switching to domheap don't have any disavantage. But this as the benefit: - to keep the page tables unmapped if an arch decided to do so - reduce xenheap use on arm32 which can be pretty small Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - New patch --- xen/arch/arm/mm.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 1e5c2c45dcf9..58364bb6c820 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -972,21 +972,6 @@ void *ioremap(paddr_t pa, size_t len) return ioremap_attr(pa, len, PAGE_HYPERVISOR_NOCACHE); } =20 -static int create_xen_table(lpae_t *entry) -{ - void *p; - lpae_t pte; - - p =3D alloc_xenheap_page(); - if ( p =3D=3D NULL ) - return -ENOMEM; - clear_page(p); - pte =3D mfn_to_xen_entry(virt_to_mfn(p), MT_NORMAL); - pte.pt.table =3D 1; - write_pte(entry, pte); - return 0; -} - static lpae_t *xen_map_table(mfn_t mfn) { /* @@ -1027,6 +1012,27 @@ static void xen_unmap_table(const lpae_t *table) unmap_domain_page(table); } =20 +static int create_xen_table(lpae_t *entry) +{ + struct page_info *pg; + void *p; + lpae_t pte; + + pg =3D alloc_domheap_page(NULL, 0); + if ( pg =3D=3D NULL ) + return -ENOMEM; + + p =3D xen_map_table(page_to_mfn(pg)); + clear_page(p); + xen_unmap_table(p); + + pte =3D mfn_to_xen_entry(page_to_mfn(pg), MT_NORMAL); + pte.pt.table =3D 1; + write_pte(entry, pte); + + return 0; +} + #define XEN_TABLE_MAP_FAILED 0 #define XEN_TABLE_SUPER_PAGE 1 #define XEN_TABLE_NORMAL_PAGE 2 --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645440679; cv=none; d=zohomail.com; s=zohoarc; b=WMHOReJ+x3CUEKVsvRu7ovf6lHn4o7ycXZC63VXBu77W7myYMxJNXtyeCXgrJxvKcz6T7bFrvoJgD/fvvy5dF5MJB3mzvpQ6BNDsJxmG6i1awrYykHC/vQlWSZjQVVsoFwMwLwwsq77b4zsXL6lDNFkUJaCb/MMkiSplAsjudYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645440679; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f03/3Vf/UCt5JQLkCjdrbloKJVprsUR48KaiuBmSgTo=; b=DEYUDTnJNd/Htd0Cglh3h5xRQ9SBmU39MT5yW2ZqcAQdHGVkv3TcDsZMsy9WAfHPky8aTI4Zqph4Ycj/RQbOAX6aFd0oMHLzbxD0TytEIwvkPwqGZtFy8aI6kbxQLKCZ0HrAG74ICXtLvtL5gqT+EVb1T/Q3f9LHlpRPcb5zU4g= 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 1645440679929270.2682145934383; Mon, 21 Feb 2022 02:51:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.276091.472149 (Exim 4.92) (envelope-from ) id 1nM6HS-0006Su-Rv; Mon, 21 Feb 2022 10:50:58 +0000 Received: by outflank-mailman (output) from mailman id 276091.472149; Mon, 21 Feb 2022 10:50:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HS-0006RM-Jb; Mon, 21 Feb 2022 10:50:58 +0000 Received: by outflank-mailman (input) for mailman id 276091; Mon, 21 Feb 2022 10:50:57 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0006Po-Hh for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:50:57 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0002lU-8Y; Mon, 21 Feb 2022 10:50:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5py-00070b-R6; Mon, 21 Feb 2022 10:22:35 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=f03/3Vf/UCt5JQLkCjdrbloKJVprsUR48KaiuBmSgTo=; b=hiMhKzUPL64NsMAqmJd0Lk1PkD DJSjYDBI5vU5yLcg4P1nWPCTuyPHBADK9kZ/irp1z9TFfuVQgpyvmiU9PsIxJkOpo9UcAkQPeWN90 rr7vUIZAReVu/w4TKR92qz3FYyhvV8vcFgR1Q+m6BeyNaEEiM8b53E2fx65jka4DY1dQ=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall Subject: [PATCH v3 12/19] xen/arm: mm: Allow page-table allocation from the boot allocator Date: Mon, 21 Feb 2022 10:22:11 +0000 Message-Id: <20220221102218.33785-13-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645440680802100006 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment, page-table can only be allocated from domheap. This means it is not possible to create mapping in the page-tables via map_pages_to_xen() if page-table needs to be allocated. In order to avoid open-coding page-tables update in early boot, we need to be able to allocate page-tables much earlier. Thankfully, we have the boot allocator for those cases. create_xen_table() is updated to cater early boot allocation by using alloc_boot_pages(). Note, this is not sufficient to bootstrap the page-tables (i.e mapping before any memory is actually mapped). This will be addressed separately. Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - New patch --- xen/arch/arm/mm.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 58364bb6c820..f70b8cc7ce87 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1014,19 +1014,27 @@ static void xen_unmap_table(const lpae_t *table) =20 static int create_xen_table(lpae_t *entry) { - struct page_info *pg; + mfn_t mfn; void *p; lpae_t pte; =20 - pg =3D alloc_domheap_page(NULL, 0); - if ( pg =3D=3D NULL ) - return -ENOMEM; + if ( system_state !=3D SYS_STATE_early_boot ) + { + struct page_info *pg =3D alloc_domheap_page(NULL, 0); + + if ( pg =3D=3D NULL ) + return -ENOMEM; + + mfn =3D page_to_mfn(pg); + } + else + mfn =3D alloc_boot_pages(1, 1); =20 - p =3D xen_map_table(page_to_mfn(pg)); + p =3D xen_map_table(mfn); clear_page(p); xen_unmap_table(p); =20 - pte =3D mfn_to_xen_entry(page_to_mfn(pg), MT_NORMAL); + pte =3D mfn_to_xen_entry(mfn, MT_NORMAL); pte.pt.table =3D 1; write_pte(entry, pte); =20 --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645440678; cv=none; d=zohomail.com; s=zohoarc; b=nb+oCekJcd0dnyVv7O/PgQpRf9OjwC3oeIe9Q7Xarv12FPIQABoCsD1BRUo6JN660W90M/ZQUMi9RRIKrp7vlUNiUpL/t8UfZVuARj5fdvAv3+xyuw90fOtHnfibFPDhvRRFcOPJDGQtDH6hJshBjJjxMF4NlgWzNYaM0V0boHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645440678; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0MbMCc6Fc4nKPqui2STMDRF8WroiVRuB9EZOJsrT/c4=; b=L2VXq6BOiciUG7uqzOQJE8Ot2+qGb5OP/xXZBqNzCmvIdoIQ4j+Fde25rZ1u9VPlSpY2GaSeOApvD5D2znsrY0i1j20P95C13H+0b3une9OuF+satzoSwCcmJNJwHZ1B2wPgbIrT95zbKfLOFiYwcXJvqJa7NID0VIN9V0rv6O0= 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 1645440678077826.6867657052388; Mon, 21 Feb 2022 02:51:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.276094.472169 (Exim 4.92) (envelope-from ) id 1nM6HU-0006oX-9a; Mon, 21 Feb 2022 10:51:00 +0000 Received: by outflank-mailman (output) from mailman id 276094.472169; Mon, 21 Feb 2022 10:51:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HT-0006mE-Sl; Mon, 21 Feb 2022 10:50:59 +0000 Received: by outflank-mailman (input) for mailman id 276094; Mon, 21 Feb 2022 10:50:58 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HS-0006QB-15 for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:50:58 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0002la-Dw; Mon, 21 Feb 2022 10:50:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5q0-00070b-6H; Mon, 21 Feb 2022 10:22:36 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=0MbMCc6Fc4nKPqui2STMDRF8WroiVRuB9EZOJsrT/c4=; b=oS0peln7Lspnp759qq8L0fNVa4 8OeCfzCZhy2QJPHOQNYj48rY1uyWerg7d1ijkcAI8nRzwhY9YCCbEhK2m9L43ZGHsBmTa6cz9ZKrb Oky5hwhDLv793A14iRsks2Eh/CkzQM/6l1Gk3wDJgJ/Ko1kwiVT2j80bxMS3wjWYBgpY=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [PATCH v3 13/19] xen/arm: Move fixmap definitions in a separate header Date: Mon, 21 Feb 2022 10:22:12 +0000 Message-Id: <20220221102218.33785-14-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645440679146100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall To use properly the fixmap definitions, their user would need also new to include . This is not very great when the user itself is not meant to directly use ACPI definitions. Including in is not option because the latter header is included by everyone. So move out the fixmap entries definition in a new header. Take the opportunity to also move {set, clear}_fixmap() prototypes in the new header. Note that most of the definitions in now need to be surrounded with #ifndef __ASSEMBLY__ because will be used in assembly (see EARLY_UART_VIRTUAL_ADDRESS). The split will become more helpful in a follow-up patch where new fixmap entries will be defined. Signed-off-by: Julien Grall Acked-by: Jan Beulich --- Changes in v3: - Patch added --- xen/arch/arm/acpi/lib.c | 2 ++ xen/arch/arm/include/asm/config.h | 6 ------ xen/arch/arm/include/asm/early_printk.h | 1 + xen/arch/arm/include/asm/fixmap.h | 24 ++++++++++++++++++++++++ xen/arch/arm/include/asm/mm.h | 4 ---- xen/arch/arm/kernel.c | 1 + xen/arch/arm/mm.c | 1 + xen/include/xen/acpi.h | 18 +++++++++++------- 8 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 xen/arch/arm/include/asm/fixmap.h diff --git a/xen/arch/arm/acpi/lib.c b/xen/arch/arm/acpi/lib.c index a59cc4074cfb..41d521f720ac 100644 --- a/xen/arch/arm/acpi/lib.c +++ b/xen/arch/arm/acpi/lib.c @@ -25,6 +25,8 @@ #include #include =20 +#include + static bool fixmap_inuse; =20 char *__acpi_map_table(paddr_t phys, unsigned long size) diff --git a/xen/arch/arm/include/asm/config.h b/xen/arch/arm/include/asm/c= onfig.h index 85d4a510ce8a..51908bf9422c 100644 --- a/xen/arch/arm/include/asm/config.h +++ b/xen/arch/arm/include/asm/config.h @@ -175,12 +175,6 @@ =20 #endif =20 -/* Fixmap slots */ -#define FIXMAP_CONSOLE 0 /* The primary UART */ -#define FIXMAP_MISC 1 /* Ephemeral mappings of hardware */ -#define FIXMAP_ACPI_BEGIN 2 /* Start mappings of ACPI tables */ -#define FIXMAP_ACPI_END (FIXMAP_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1)= /* End mappings of ACPI tables */ - #define NR_hypercalls 64 =20 #define STACK_ORDER 3 diff --git a/xen/arch/arm/include/asm/early_printk.h b/xen/arch/arm/include= /asm/early_printk.h index 8dc911cf48a3..c5149b2976da 100644 --- a/xen/arch/arm/include/asm/early_printk.h +++ b/xen/arch/arm/include/asm/early_printk.h @@ -11,6 +11,7 @@ #define __ARM_EARLY_PRINTK_H__ =20 #include +#include =20 #ifdef CONFIG_EARLY_PRINTK =20 diff --git a/xen/arch/arm/include/asm/fixmap.h b/xen/arch/arm/include/asm/f= ixmap.h new file mode 100644 index 000000000000..1cee51e52ab9 --- /dev/null +++ b/xen/arch/arm/include/asm/fixmap.h @@ -0,0 +1,24 @@ +/* + * fixmap.h: compile-time virtual memory allocation + */ +#ifndef __ASM_FIXMAP_H +#define __ASM_FIXMAP_H + +#include + +/* Fixmap slots */ +#define FIXMAP_CONSOLE 0 /* The primary UART */ +#define FIXMAP_MISC 1 /* Ephemeral mappings of hardware */ +#define FIXMAP_ACPI_BEGIN 2 /* Start mappings of ACPI tables */ +#define FIXMAP_ACPI_END (FIXMAP_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1)= /* End mappings of ACPI tables */ + +#ifndef __ASSEMBLY__ + +/* Map a page in a fixmap entry */ +extern void set_fixmap(unsigned map, mfn_t mfn, unsigned attributes); +/* Remove a mapping from a fixmap entry */ +extern void clear_fixmap(unsigned map); + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_FIXMAP_H */ diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 424aaf28230b..045a8ba4bb63 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -191,10 +191,6 @@ extern void mmu_init_secondary_cpu(void); extern void setup_xenheap_mappings(unsigned long base_mfn, unsigned long n= r_mfns); /* Map a frame table to cover physical addresses ps through pe */ extern void setup_frametable_mappings(paddr_t ps, paddr_t pe); -/* Map a 4k page in a fixmap entry */ -extern void set_fixmap(unsigned map, mfn_t mfn, unsigned attributes); -/* Remove a mapping from a fixmap entry */ -extern void clear_fixmap(unsigned map); /* map a physical range in virtual memory */ void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned attributes); =20 diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 8f43caa1866d..25ded1c056d9 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -15,6 +15,7 @@ #include =20 #include +#include #include #include =20 diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index f70b8cc7ce87..d6a4b9407c43 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -41,6 +41,7 @@ #include #include =20 +#include #include =20 /* Override macros from asm/page.h to make them work with mfn_t */ diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h index 08834f140266..500aaa538551 100644 --- a/xen/include/xen/acpi.h +++ b/xen/include/xen/acpi.h @@ -28,6 +28,15 @@ #define _LINUX #endif =20 +/* + * Fixmap pages to reserve for ACPI boot-time tables (see + * arch/x86/include/asm/fixmap.h or arch/arm/include/asm/fixmap.h), + * 64 pages(256KB) is large enough for most cases.) + */ +#define NUM_FIXMAP_ACPI_PAGES 64 + +#ifndef __ASSEMBLY__ + #include =20 #include @@ -39,13 +48,6 @@ #define ACPI_MADT_GET_POLARITY(inti) ACPI_MADT_GET_(POLARITY, inti) #define ACPI_MADT_GET_TRIGGER(inti) ACPI_MADT_GET_(TRIGGER, inti) =20 -/* - * Fixmap pages to reserve for ACPI boot-time tables (see - * arch/x86/include/asm/fixmap.h or arch/arm/include/asm/config.h, - * 64 pages(256KB) is large enough for most cases.) - */ -#define NUM_FIXMAP_ACPI_PAGES 64 - #define BAD_MADT_ENTRY(entry, end) ( = \ (!(entry)) || (unsigned long)(entry) + sizeof(*(entry)) > = (end) || \ (entry)->header.length < sizeof(*(entry))) @@ -207,4 +209,6 @@ void acpi_reboot(void); void acpi_dmar_zap(void); void acpi_dmar_reinstate(void); =20 +#endif /* __ASSEMBLY__ */ + #endif /*_LINUX_ACPI_H*/ --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645440678; cv=none; d=zohomail.com; s=zohoarc; b=Nlr6ocI6Fajx20LkLzvWXjI0PIs5Yd4FJG8XaGgbzxwOEy5G/XHlXHjWhop7aDJjz3raCZbIqD0Fo3FBhGJPN0eY3SCthzf6DyflZgosYMPOjOVmlfSbtijXrPCPI9QKatbGoX2njQpUElGPsM6wH9rDHUm4+44GDstkUnfU+dE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645440678; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vpQruBgrefHFrUQ/LCTSC1M9bnsWKZKjMmpBwte2ato=; b=nCBppMCcX8YsIkJ5MO062AxklxAEV7E6YocDlOV7dlquO9zJ+FMnVKjLsmGziGUQ//MgWdv5Mbiqo/PpvhDnWlV5BkA6n8vr91NqpTrXlEeDqcn+I0gA9zXOrK7dQ7ndQtgbUWqw5ZRYAAG/BnhDNyPBkU2QVtDMHLCClvh9l1U= 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 1645440678442347.4149245813861; Mon, 21 Feb 2022 02:51:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.276097.472192 (Exim 4.92) (envelope-from ) id 1nM6HV-0007HO-RO; Mon, 21 Feb 2022 10:51:01 +0000 Received: by outflank-mailman (output) from mailman id 276097.472192; Mon, 21 Feb 2022 10:51:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HV-0007DS-7t; Mon, 21 Feb 2022 10:51:01 +0000 Received: by outflank-mailman (input) for mailman id 276097; Mon, 21 Feb 2022 10:50:58 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HS-0006Sg-MD for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:50:58 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0002lr-Js; Mon, 21 Feb 2022 10:50:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5q1-00070b-R0; Mon, 21 Feb 2022 10:22:38 +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:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=vpQruBgrefHFrUQ/LCTSC1M9bnsWKZKjMmpBwte2ato=; b=jplxBhar50D+va8ChkMHyh1sg3 +pfFUZKJIZ18i6/RxtGgSiUeLxNQWnPhIfBadRviVnTBhWKv2bsC0S1V1E79X4vRV9RqMAVHIAOIy 0uGSPN1IdDUlJ4qiy8vaStWjEDHd8KOfkMJwJ46/7Dj35BCMNAHcJFucd9FZl4oFqWkw=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Wei Liu , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , George Dunlap , Hongyan Xia , Julien Grall , Jan Beulich , Wei Liu , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v3 14/19] xen/arm: add Persistent Map (PMAP) infrastructure Date: Mon, 21 Feb 2022 10:22:13 +0000 Message-Id: <20220221102218.33785-15-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645440679158100002 From: Wei Liu The basic idea is like Persistent Kernel Map (PKMAP) in Linux. We pre-populate all the relevant page tables before the system is fully set up. We will need it on Arm in order to rework the arm64 version of xenheap_setup_mappings() as we may need to use pages allocated from the boot allocator before they are effectively mapped. This infrastructure is not lock-protected therefore can only be used before smpboot. After smpboot, map_domain_page() has to be used. This is based on the x86 version [1] that was originally implemented by Wei Liu. The PMAP infrastructure is implemented in common code with some arch helpers to set/clear the page-table entries and convertion between a fixmap slot to a virtual address... As mfn_to_xen_entry() now needs to be exported, take the opportunity to swich the parameter attr from unsigned to unsigned int. [1] Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia [julien: Adapted for Arm] Signed-off-by: Julien Grall --- Changes in v3: - s/BITS_PER_LONG/BITS_PER_BYTE/ - Move pmap to common code Changes in v2: - New patch Cc: Jan Beulich Cc: Wei Liu Cc: Andrew Cooper Cc: Roger Pau Monn=C3=A9 --- xen/arch/arm/Kconfig | 1 + xen/arch/arm/include/asm/fixmap.h | 17 +++++++ xen/arch/arm/include/asm/lpae.h | 8 ++++ xen/arch/arm/include/asm/pmap.h | 33 +++++++++++++ xen/arch/arm/mm.c | 7 +-- xen/common/Kconfig | 3 ++ xen/common/Makefile | 1 + xen/common/pmap.c | 79 +++++++++++++++++++++++++++++++ xen/include/xen/pmap.h | 16 +++++++ 9 files changed, 159 insertions(+), 6 deletions(-) create mode 100644 xen/arch/arm/include/asm/pmap.h create mode 100644 xen/common/pmap.c create mode 100644 xen/include/xen/pmap.h diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index ecfa6822e4d3..a89a67802aa9 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -14,6 +14,7 @@ config ARM select HAS_DEVICE_TREE select HAS_PASSTHROUGH select HAS_PDX + select HAS_PMAP select IOMMU_FORCE_PT_SHARE =20 config ARCH_DEFCONFIG diff --git a/xen/arch/arm/include/asm/fixmap.h b/xen/arch/arm/include/asm/f= ixmap.h index 1cee51e52ab9..c46a15e59de4 100644 --- a/xen/arch/arm/include/asm/fixmap.h +++ b/xen/arch/arm/include/asm/fixmap.h @@ -5,12 +5,20 @@ #define __ASM_FIXMAP_H =20 #include +#include =20 /* Fixmap slots */ #define FIXMAP_CONSOLE 0 /* The primary UART */ #define FIXMAP_MISC 1 /* Ephemeral mappings of hardware */ #define FIXMAP_ACPI_BEGIN 2 /* Start mappings of ACPI tables */ #define FIXMAP_ACPI_END (FIXMAP_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1)= /* End mappings of ACPI tables */ +#define FIXMAP_PMAP_BEGIN (FIXMAP_ACPI_END + 1) /* Start of PMAP */ +#define FIXMAP_PMAP_END (FIXMAP_PMAP_BEGIN + NUM_FIX_PMAP - 1) /* End of P= MAP */ + +#define FIXMAP_LAST FIXMAP_PMAP_END + +#define FIXADDR_START FIXMAP_ADDR(0) +#define FIXADDR_TOP FIXMAP_ADDR(FIXMAP_LAST) =20 #ifndef __ASSEMBLY__ =20 @@ -19,6 +27,15 @@ extern void set_fixmap(unsigned map, mfn_t mfn, unsigned= attributes); /* Remove a mapping from a fixmap entry */ extern void clear_fixmap(unsigned map); =20 +#define fix_to_virt(slot) ((void *)FIXMAP_ADDR(slot)) + +static inline unsigned int virt_to_fix(vaddr_t vaddr) +{ + BUG_ON(vaddr >=3D FIXADDR_TOP || vaddr < FIXADDR_START); + + return ((vaddr - FIXADDR_START) >> PAGE_SHIFT); +} + #endif /* __ASSEMBLY__ */ =20 #endif /* __ASM_FIXMAP_H */ diff --git a/xen/arch/arm/include/asm/lpae.h b/xen/arch/arm/include/asm/lpa= e.h index 8cf932b5c947..6099037da1c0 100644 --- a/xen/arch/arm/include/asm/lpae.h +++ b/xen/arch/arm/include/asm/lpae.h @@ -4,6 +4,7 @@ #ifndef __ASSEMBLY__ =20 #include +#include =20 /* * WARNING! Unlike the x86 pagetable code, where l1 is the lowest level a= nd @@ -168,6 +169,13 @@ static inline bool lpae_is_superpage(lpae_t pte, unsig= ned int level) third_table_offset(addr) \ } =20 +/* + * Standard entry type that we'll use to build Xen's own pagetables. + * We put the same permissions at every level, because they're ignored + * by the walker in non-leaf entries. + */ +lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr); + #endif /* __ASSEMBLY__ */ =20 /* diff --git a/xen/arch/arm/include/asm/pmap.h b/xen/arch/arm/include/asm/pma= p.h new file mode 100644 index 000000000000..70eafe2891d7 --- /dev/null +++ b/xen/arch/arm/include/asm/pmap.h @@ -0,0 +1,33 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include + +/* XXX: Find an header to declare it */ +extern lpae_t xen_fixmap[XEN_PT_LPAE_ENTRIES]; + +static inline void arch_pmap_map(unsigned int slot, mfn_t mfn) +{ + lpae_t *entry =3D &xen_fixmap[slot]; + lpae_t pte; + + ASSERT(!lpae_is_valid(*entry)); + + pte =3D mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); + pte.pt.table =3D 1; + write_pte(entry, pte); +} + +static inline void arch_pmap_unmap(unsigned int slot) +{ + lpae_t pte =3D {}; + + write_pte(&xen_fixmap[slot], pte); + + flush_xen_tlb_range_va_local(FIXMAP_ADDR(slot), PAGE_SIZE); +} + +void arch_pmap_map_slot(unsigned int slot, mfn_t mfn); +void arch_pmap_clear_slot(void *ptr); + +#endif /* __ASM_PMAP_H__ */ diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index d6a4b9407c43..b7942464d4de 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -290,12 +290,7 @@ void dump_hyp_walk(vaddr_t addr) dump_pt_walk(ttbr, addr, HYP_PT_ROOT_LEVEL, 1); } =20 -/* - * Standard entry type that we'll use to build Xen's own pagetables. - * We put the same permissions at every level, because they're ignored - * by the walker in non-leaf entries. - */ -static inline lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned attr) +lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr) { lpae_t e =3D (lpae_t) { .pt =3D { diff --git a/xen/common/Kconfig b/xen/common/Kconfig index db687b1785e7..b6c55af2eb03 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -49,6 +49,9 @@ config HAS_KEXEC config HAS_PDX bool =20 +config HAS_PMAP + bool + config HAS_SCHED_GRANULARITY bool =20 diff --git a/xen/common/Makefile b/xen/common/Makefile index ca839118e4d1..8b42b0828134 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -28,6 +28,7 @@ obj-y +=3D multicall.o obj-y +=3D notifier.o obj-y +=3D page_alloc.o obj-$(CONFIG_HAS_PDX) +=3D pdx.o +obj-bin-$(CONFIG_HAS_PMAP) +=3D pmap.init.o obj-$(CONFIG_PERF_COUNTERS) +=3D perfc.o obj-y +=3D preempt.o obj-y +=3D random.o diff --git a/xen/common/pmap.c b/xen/common/pmap.c new file mode 100644 index 000000000000..cea730ead545 --- /dev/null +++ b/xen/common/pmap.c @@ -0,0 +1,79 @@ +#include +#include +#include + +#include +#include + +/* + * Simple mapping infrastructure to map / unmap pages in fixed map. + * This is used to set up the page table for mapcache, which is used + * by map domain page infrastructure. + * + * This structure is not protected by any locks, so it must not be used af= ter + * smp bring-up. + */ + +/* Bitmap to track which slot is used */ +static unsigned long __initdata inuse; + +void *__init pmap_map(mfn_t mfn) +{ + unsigned long flags; + unsigned int idx; + unsigned int slot; + + BUILD_BUG_ON(sizeof(inuse) * BITS_PER_BYTE < NUM_FIX_PMAP); + + ASSERT(system_state < SYS_STATE_smp_boot); + + local_irq_save(flags); + + idx =3D find_first_zero_bit(&inuse, NUM_FIX_PMAP); + if ( idx =3D=3D NUM_FIX_PMAP ) + panic("Out of PMAP slots\n"); + + __set_bit(idx, &inuse); + + slot =3D idx + FIXMAP_PMAP_BEGIN; + ASSERT(slot >=3D FIXMAP_PMAP_BEGIN && slot <=3D FIXMAP_PMAP_END); + + /* + * We cannot use set_fixmap() here. We use PMAP when there is no direc= t map, + * so map_pages_to_xen() called by set_fixmap() needs to map pages on + * demand, which then calls pmap() again, resulting in a loop. Modify = the + * PTEs directly instead. The same is true for pmap_unmap(). + */ + arch_pmap_map(slot, mfn); + + local_irq_restore(flags); + + return fix_to_virt(slot); +} + +void __init pmap_unmap(const void *p) +{ + unsigned long flags; + unsigned int idx; + unsigned int slot =3D virt_to_fix((unsigned long)p); + + ASSERT(system_state < SYS_STATE_smp_boot); + ASSERT(slot >=3D FIXMAP_PMAP_BEGIN && slot <=3D FIXMAP_PMAP_END); + + idx =3D slot - FIXMAP_PMAP_BEGIN; + local_irq_save(flags); + + __clear_bit(idx, &inuse); + arch_pmap_unmap(slot); + + local_irq_restore(flags); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/pmap.h b/xen/include/xen/pmap.h new file mode 100644 index 000000000000..93e61b10870e --- /dev/null +++ b/xen/include/xen/pmap.h @@ -0,0 +1,16 @@ +#ifndef __XEN_PMAP_H__ +#define __XEN_PMAP_H__ + +/* Large enough for mapping 5 levels of page tables with some headroom */ +#define NUM_FIX_PMAP 8 + +#ifndef __ASSEMBLY__ + +#include + +void *pmap_map(mfn_t mfn); +void pmap_unmap(const void *p); + +#endif /* __ASSEMBLY__ */ + +#endif /* __XEN_PMAP_H__ */ --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645440679; cv=none; d=zohomail.com; s=zohoarc; b=PTzEz7PkyGCMb7vnkVTsPNgTkSsc0cb1aWXw/yUhEJSydD1emRnpMcXnEPZ87TYIx3UE8f0hw21+rauMZYT+CmZ+AVHiesEOYcMffWgmpkYqUDxvrN6vmEYbOEg2IgOf/shiucj5gx9rpH6+HQorI6BjxuGwI3AyU3lCvp9bh34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645440679; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ircv52tCd8GVVO1Y1H28ZgnoiMPLWO4TwQBUEqK5CEg=; b=DcO8EBzAfKdHpkABKii7qCb0nwVczvdGdA0Xdx1HmO+MpZUJJxKZs93Mh3HTq2e1AHiNXh1o/Hp+x+UL/yxjfsNPQP8EqfGL+Ciq1+fAyRYtLGF+WRqu772xf2xIRQH1RT9QaFC4PSfHCz3tNDV8LZPy/Lts8o0DJzd/6vewr/Y= 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 1645440679254948.6980745471112; Mon, 21 Feb 2022 02:51:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.276093.472161 (Exim 4.92) (envelope-from ) id 1nM6HT-0006et-Nf; Mon, 21 Feb 2022 10:50:59 +0000 Received: by outflank-mailman (output) from mailman id 276093.472161; Mon, 21 Feb 2022 10:50:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HT-0006bz-D3; Mon, 21 Feb 2022 10:50:59 +0000 Received: by outflank-mailman (input) for mailman id 276093; Mon, 21 Feb 2022 10:50:57 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0006Q5-Q7 for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:50:57 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0002lf-Ff; Mon, 21 Feb 2022 10:50:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5q2-00070b-Px; Mon, 21 Feb 2022 10:22:38 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ircv52tCd8GVVO1Y1H28ZgnoiMPLWO4TwQBUEqK5CEg=; b=Xv0S9neTaH+451IW1pwoDwNDfa vaXPqblQTGO6fwUSpEJkWaTW/1YQZQVLJ2+3ikbeIk7ouhtWqwWeJxYf4LuNS4Du2IMoSeoLdT6N6 /yImBSUG0m8yuK9WMQfefLasIre8tUCoTAGpanTQ723A9yZMFN+UNsfPdowMrvnlV7cI=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 15/19] xen/arm: mm: Clean-up the includes and order them Date: Mon, 21 Feb 2022 10:22:14 +0000 Message-Id: <20220221102218.33785-16-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645440680792100005 Content-Type: text/plain; charset="utf-8" From: Julien Grall The numbers of includes in mm.c has been growing quite a lot. However some of them (e.g. xen/device_tree.h, xen/softirq.h) doesn't look to be directly used by the file or other will be included by larger headers (e.g asm/flushtlb.h will be included by xen/mm.h). So trim down the number of includes. Take the opportunity to order them with the xen headers first, then asm headers and last public headers. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v3: - Patch added --- xen/arch/arm/mm.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b7942464d4de..659bdf25e0ff 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -17,33 +17,26 @@ * GNU General Public License for more details. */ =20 -#include -#include -#include -#include -#include -#include +#include #include #include -#include -#include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include +#include +#include #include + #include -#include -#include -#include =20 #include #include =20 +#include + /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn #define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645440679; cv=none; d=zohomail.com; s=zohoarc; b=nvpIbXjrA6g42RwIfncRJOuPoDXBoF9Qpa6Plj96WLwjLutSgidy8ltH2l0STzo1ssilcQ25IyqkLeGEZ7pAZxpHSoBgFAEkTVkrH3TUXER0xe7VXmAWXCCCa2BAyPRpCXHRmIgG+5/FqgArSwHu7KjIzTC8s96qzbCMubGd2xE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645440679; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WOeJ/LVD52L5YzIcVNL+IXQBycQP2W2GDSj+IqdQKo0=; b=RM05lapohNo/XaIb/P4Go8uBA+KR5YlsAxHHuc5+qgZXMxipBgCm8RINP1DnuHcM5XeqfxACA1Si7qJbh2LlfL3a6VjuPFXUqcbaXnXNluDips9ufpiLvGojo77ZH3I0pOevN9Tz+rVl64tkUrpS39FtX4Yjj2Av5T9uNoz6Uzo= 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 1645440679851661.4517128392415; Mon, 21 Feb 2022 02:51:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.276092.472155 (Exim 4.92) (envelope-from ) id 1nM6HT-0006XX-9s; Mon, 21 Feb 2022 10:50:59 +0000 Received: by outflank-mailman (output) from mailman id 276092.472155; Mon, 21 Feb 2022 10:50:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HS-0006VG-Vk; Mon, 21 Feb 2022 10:50:58 +0000 Received: by outflank-mailman (input) for mailman id 276092; Mon, 21 Feb 2022 10:50:57 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0006Pp-JL for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:50:57 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0002lW-AS; Mon, 21 Feb 2022 10:50:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5q3-00070b-Ox; Mon, 21 Feb 2022 10:22:39 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=WOeJ/LVD52L5YzIcVNL+IXQBycQP2W2GDSj+IqdQKo0=; b=x+HtDP7Wbuvk3vQTsEi+QK12Li yB+qv9oUO2OZ/C4B90il6KJSWmgKDLSYR6JqRakY7/h4RIZebuwkJiU+P9LtaJdF0feLie1xCPF5D /eoMlp7ZPl9eqyXZBaRfbtlGAruV/du5M6f2hjQyoe3xZ8hFu4/fk8yVutc4na/H1AzI=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 16/19] xen/arm: mm: Use the PMAP helpers in xen_{,un}map_table() Date: Mon, 21 Feb 2022 10:22:15 +0000 Message-Id: <20220221102218.33785-17-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645440680809100007 Content-Type: text/plain; charset="utf-8" From: Julien Grall During early boot, it is not possible to use xen_{,un}map_table() if the page tables are not residing the Xen binary. This is a blocker to switch some of the helpers to use xen_pt_update() as we may need to allocate extra page tables and access them before the domheap has been initialized (see setup_xenheap_mappings()). xen_{,un}map_table() are now updated to use the PMAP helpers for early boot map/unmap. Note that the special case for page-tables residing in Xen binary has been dropped because it is "complex" and was only added as a workaround in 8d4f1b8878e0 ("xen/arm: mm: Allow generic xen page-tables helpers to be called early"). Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - New patch --- xen/arch/arm/mm.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 659bdf25e0ff..11b6b60a2bc1 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -964,27 +965,11 @@ void *ioremap(paddr_t pa, size_t len) static lpae_t *xen_map_table(mfn_t mfn) { /* - * We may require to map the page table before map_domain_page() is - * useable. The requirements here is it must be useable as soon as - * page-tables are allocated dynamically via alloc_boot_pages(). - * - * We need to do the check on physical address rather than virtual - * address to avoid truncation on Arm32. Therefore is_kernel() cannot - * be used. + * During early boot, map_domain_page() may be unusable. Use the + * PMAP to map temporarily a page-table. */ if ( system_state =3D=3D SYS_STATE_early_boot ) - { - if ( is_xen_fixed_mfn(mfn) ) - { - /* - * It is fine to demote the type because the size of Xen - * will always fit in vaddr_t. - */ - vaddr_t offset =3D mfn_to_maddr(mfn) - virt_to_maddr(&_start); - - return (lpae_t *)(XEN_VIRT_START + offset); - } - } + return pmap_map(mfn); =20 return map_domain_page(mfn); } @@ -993,12 +978,12 @@ static void xen_unmap_table(const lpae_t *table) { /* * During early boot, xen_map_table() will not use map_domain_page() - * for page-tables residing in Xen binary. So skip the unmap part. + * but the PMAP. */ - if ( system_state =3D=3D SYS_STATE_early_boot && is_kernel(table) ) - return; - - unmap_domain_page(table); + if ( system_state =3D=3D SYS_STATE_early_boot ) + pmap_unmap(table); + else + unmap_domain_page(table); } =20 static int create_xen_table(lpae_t *entry) --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645440680; cv=none; d=zohomail.com; s=zohoarc; b=A7cvx1NtlBTKwuFQDxeaWlcM9LAnd3QvKg8JxS0alrI3WPcq/utG8T4d1n0wCJKNf4tzC3iozM+YwgCcy6+PG1t/j5PMD3MRQskLXvAt699ISHcF/LwcUoS48pxHh2gVE49wnLNjD2xpBrWwUGe3BTsH3GfTwkJsCkQ3vAGIK5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645440680; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KXQhE4JwQVSql4G63vu+dVWvMWK9F9ZJUhgjQV+fnpo=; b=WcsJI2723Uh/45E4z0icTt7uYZqzMTFT+m4OVnfzTi+N2f/OLO0K5lZhIqh4ii+sfmt5yfBKfsMC7D0Z4e/i5xVSMjm96JC8XWfu0ZX9CyJEw5C+wHzXjE5HzPghf+O/dPEkfDunm04x1bTQw/YcBXzvqo/6TUVaI6F4KBzTk0Q= 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 1645440680880929.914470796004; Mon, 21 Feb 2022 02:51:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.276096.472206 (Exim 4.92) (envelope-from ) id 1nM6HX-0007c7-Am; Mon, 21 Feb 2022 10:51:03 +0000 Received: by outflank-mailman (output) from mailman id 276096.472206; Mon, 21 Feb 2022 10:51:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HW-0007Xe-Ej; Mon, 21 Feb 2022 10:51:02 +0000 Received: by outflank-mailman (input) for mailman id 276096; Mon, 21 Feb 2022 10:50:58 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HS-0006Ri-Iv for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:50:58 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0002lj-HW; Mon, 21 Feb 2022 10:50:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5q4-00070b-Nt; Mon, 21 Feb 2022 10:22:40 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=KXQhE4JwQVSql4G63vu+dVWvMWK9F9ZJUhgjQV+fnpo=; b=kiUDonnWYV5KI6PTUUqj8ctYcz yYikeIAMlHznE+6xc4wdf0yKc0TZbzy6bNEGTfh5589ds+XgSxqAtBAJr4wSgfAHvvBqAU/MQVsF6 +sxKmRbotqkUxiJTby08Z8odVirrLOxreHSVhkGJejjb6rzwln9QUJJmmgIRz236QGrY=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v3 17/19] xen/arm64: mm: Add memory to the boot allocator first Date: Mon, 21 Feb 2022 10:22:16 +0000 Message-Id: <20220221102218.33785-18-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645440683018100003 Content-Type: text/plain; charset="utf-8" From: Julien Grall Currently, memory is added to the boot allocator after the xenheap mappings are done. This will break if the first mapping is more than 512GB of RAM. In addition to that, a follow-up patch will rework setup_xenheap_mappings() to use smaller mappings (e.g. 2MB, 4KB). So it will be necessary to have memory in the boot allocator earlier. Only free memory (e.g. not reserved or modules) can be added to the boot allocator. It might be possible that some regions (including the first one) will have no free memory. So we need to add all the free memory to the boot allocator first and then add do the mappings. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Patch added --- xen/arch/arm/setup.c | 63 +++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index d5d0792ed48a..777cf96639f5 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -767,30 +767,18 @@ static void __init setup_mm(void) init_staticmem_pages(); } #else /* CONFIG_ARM_64 */ -static void __init setup_mm(void) +static void __init populate_boot_allocator(void) { - paddr_t ram_start =3D ~0; - paddr_t ram_end =3D 0; - paddr_t ram_size =3D 0; - int bank; - - init_pdx(); + unsigned int i; + const struct meminfo *banks =3D &bootinfo.mem; =20 - total_pages =3D 0; - for ( bank =3D 0 ; bank < bootinfo.mem.nr_banks; bank++ ) + for ( i =3D 0; i < banks->nr_banks; i++ ) { - paddr_t bank_start =3D bootinfo.mem.bank[bank].start; - paddr_t bank_size =3D bootinfo.mem.bank[bank].size; - paddr_t bank_end =3D bank_start + bank_size; + const struct membank *bank =3D &banks->bank[i]; + paddr_t bank_end =3D bank->start + bank->size; paddr_t s, e; =20 - ram_size =3D ram_size + bank_size; - ram_start =3D min(ram_start,bank_start); - ram_end =3D max(ram_end,bank_end); - - setup_xenheap_mappings(bank_start>>PAGE_SHIFT, bank_size>>PAGE_SHI= FT); - - s =3D bank_start; + s =3D bank->start; while ( s < bank_end ) { paddr_t n =3D bank_end; @@ -798,9 +786,7 @@ static void __init setup_mm(void) e =3D next_module(s, &n); =20 if ( e =3D=3D ~(paddr_t)0 ) - { e =3D n =3D bank_end; - } =20 if ( e > bank_end ) e =3D bank_end; @@ -809,6 +795,41 @@ static void __init setup_mm(void) s =3D n; } } +} + +static void __init setup_mm(void) +{ + const struct meminfo *banks =3D &bootinfo.mem; + paddr_t ram_start =3D ~0; + paddr_t ram_end =3D 0; + paddr_t ram_size =3D 0; + unsigned int i; + + init_pdx(); + + /* + * We need some memory to allocate the page-tables used for the xenheap + * mappings. But some regions may contain memory already allocated + * for other uses (e.g. modules, reserved-memory...). + * + * For simplify add all the free regions in the boot allocator. + */ + populate_boot_allocator(); + + total_pages =3D 0; + + for ( i =3D 0; i < banks->nr_banks; i++ ) + { + const struct membank *bank =3D &banks->bank[i]; + paddr_t bank_end =3D bank->start + bank->size; + + ram_size =3D ram_size + bank->size; + ram_start =3D min(ram_start, bank->start); + ram_end =3D max(ram_end, bank_end); + + setup_xenheap_mappings(PFN_DOWN(bank->start), + PFN_DOWN(bank->size)); + } =20 total_pages +=3D ram_size >> PAGE_SHIFT; =20 --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645440682; cv=none; d=zohomail.com; s=zohoarc; b=LH52E52fFF7VKwHcM3UfzQL/uJ0Wrdj+BHBHbhWTrJ6351tIO/C3320evSRG/Ib6XZyZmQZCV8irrBfbffDnkjGKDdrQnYUVQkwbowwyqK5/BGyNn3oCEdTBipZvCfIfIOoj2goAsJbOf1fd/d35jaXHmc1fC1wZ29nhJV5mEOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645440682; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=D3nC49pPPlSt0jCvDVIcUQr1XjPlKjaXYX88znegfds=; b=luNSVBgjwd5uDv1fXSr6frkHSTeRe+z5S9YgYP+4466BeUNk00wHMCWlUED02rEpF5gLhwCL2orBuF9tMA3/CLZN4D+7RNUdyjC7aDybkT98bZcTIvZ/R1M6LFScoG6IrrCAUArDqpW6UOcm+kAaiSwjvQO+VNEo81rNc+UA0SU= 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 16454406822474.329737838773212; Mon, 21 Feb 2022 02:51:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.276099.472211 (Exim 4.92) (envelope-from ) id 1nM6HX-0007md-PD; Mon, 21 Feb 2022 10:51:03 +0000 Received: by outflank-mailman (output) from mailman id 276099.472211; Mon, 21 Feb 2022 10:51:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HX-0007jC-5q; Mon, 21 Feb 2022 10:51:03 +0000 Received: by outflank-mailman (input) for mailman id 276099; Mon, 21 Feb 2022 10:50:58 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HS-0006SR-Lr for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:50:58 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0002lx-NZ; Mon, 21 Feb 2022 10:50:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5q5-00070b-Py; Mon, 21 Feb 2022 10:22:41 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=D3nC49pPPlSt0jCvDVIcUQr1XjPlKjaXYX88znegfds=; b=L37qETmWZoIP8V+g5+NzwQbK8d +ku44VagmufwFIBsvMEhS6wCAM9s4Nd3ikoetMhu+1IbJ5C0XlMbBqyUzCXP+My7zgovNBNQG2ipB smt5znX4iM4F9lacP5KlWY1by0xFmKkRqnV6WaC4+ZRis5le88/xMhqN9HidHJVkRBPU=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall Subject: [PATCH v3 18/19] xen/arm: mm: Rework setup_xenheap_mappings() Date: Mon, 21 Feb 2022 10:22:17 +0000 Message-Id: <20220221102218.33785-19-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645440683022100004 Content-Type: text/plain; charset="utf-8" From: Julien Grall The current implementation of setup_xenheap_mappings() is using 1GB mappings. This can lead to unexpected result because the mapping may alias a non-cachable region (such as device or reserved regions). For more details see B2.8 in ARM DDI 0487H.a. map_pages_to_xen() was recently reworked to allow superpage mappings, support contiguous mapping and deal with the use of pagge-tables before they are mapped. Most of the code in setup_xenheap_mappings() is now replaced with a single call to map_pages_to_xen(). Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v3: - Don't use 1GB mapping - Re-order code in setup_mm() in a separate patch Changes in v2: - New patch --- xen/arch/arm/mm.c | 87 ++++++++++------------------------------------- 1 file changed, 18 insertions(+), 69 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 11b6b60a2bc1..4af59375d998 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -138,17 +138,6 @@ static DEFINE_PAGE_TABLE(cpu0_pgtable); static DEFINE_PAGE_TABLES(cpu0_dommap, DOMHEAP_SECOND_PAGES); #endif =20 -#ifdef CONFIG_ARM_64 -/* The first page of the first level mapping of the xenheap. The - * subsequent xenheap first level pages are dynamically allocated, but - * we need this one to bootstrap ourselves. */ -static DEFINE_PAGE_TABLE(xenheap_first_first); -/* The zeroeth level slot which uses xenheap_first_first. Used because - * setup_xenheap_mappings otherwise relies on mfn_to_virt which isn't - * valid for a non-xenheap mapping. */ -static __initdata int xenheap_first_first_slot =3D -1; -#endif - /* Common pagetable leaves */ /* Second level page tables. * @@ -815,77 +804,37 @@ void __init setup_xenheap_mappings(unsigned long base= _mfn, void __init setup_xenheap_mappings(unsigned long base_mfn, unsigned long nr_mfns) { - lpae_t *first, pte; - unsigned long mfn, end_mfn; - vaddr_t vaddr; - - /* Align to previous 1GB boundary */ - mfn =3D base_mfn & ~((FIRST_SIZE>>PAGE_SHIFT)-1); + int rc; =20 /* First call sets the xenheap physical and virtual offset. */ if ( mfn_eq(xenheap_mfn_start, INVALID_MFN) ) { + unsigned long mfn_gb =3D base_mfn & ~((FIRST_SIZE >> PAGE_SHIFT) -= 1); + xenheap_mfn_start =3D _mfn(base_mfn); xenheap_base_pdx =3D mfn_to_pdx(_mfn(base_mfn)); + /* + * The base address may not be aligned to the first level + * size (e.g. 1GB when using 4KB pages). This would prevent + * superpage mappings for all the regions because the virtual + * address and machine address should both be suitably aligned. + * + * Prevent that by offsetting the start of the xenheap virtual + * address. + */ xenheap_virt_start =3D DIRECTMAP_VIRT_START + - (base_mfn - mfn) * PAGE_SIZE; + (base_mfn - mfn_gb) * PAGE_SIZE; } =20 if ( base_mfn < mfn_x(xenheap_mfn_start) ) panic("cannot add xenheap mapping at %lx below heap start %lx\n", base_mfn, mfn_x(xenheap_mfn_start)); =20 - end_mfn =3D base_mfn + nr_mfns; - - /* - * Virtual address aligned to previous 1GB to match physical - * address alignment done above. - */ - vaddr =3D (vaddr_t)__mfn_to_virt(base_mfn) & FIRST_MASK; - - while ( mfn < end_mfn ) - { - int slot =3D zeroeth_table_offset(vaddr); - lpae_t *p =3D &xen_pgtable[slot]; - - if ( p->pt.valid ) - { - /* mfn_to_virt is not valid on the 1st 1st mfn, since it - * is not within the xenheap. */ - first =3D slot =3D=3D xenheap_first_first_slot ? - xenheap_first_first : mfn_to_virt(lpae_get_mfn(*p)); - } - else if ( xenheap_first_first_slot =3D=3D -1) - { - /* Use xenheap_first_first to bootstrap the mappings */ - first =3D xenheap_first_first; - - pte =3D pte_of_xenaddr((vaddr_t)xenheap_first_first); - pte.pt.table =3D 1; - write_pte(p, pte); - - xenheap_first_first_slot =3D slot; - } - else - { - mfn_t first_mfn =3D alloc_boot_pages(1, 1); - - clear_page(mfn_to_virt(first_mfn)); - pte =3D mfn_to_xen_entry(first_mfn, MT_NORMAL); - pte.pt.table =3D 1; - write_pte(p, pte); - first =3D mfn_to_virt(first_mfn); - } - - pte =3D mfn_to_xen_entry(_mfn(mfn), MT_NORMAL); - /* TODO: Set pte.pt.contig when appropriate. */ - write_pte(&first[first_table_offset(vaddr)], pte); - - mfn +=3D FIRST_SIZE>>PAGE_SHIFT; - vaddr +=3D FIRST_SIZE; - } - - flush_xen_tlb_local(); + rc =3D map_pages_to_xen((vaddr_t)__mfn_to_virt(base_mfn), + _mfn(base_mfn), nr_mfns, + PAGE_HYPERVISOR_RW | _PAGE_BLOCK); + if ( rc ) + panic("Unable to setup the xenheap mappings.\n"); } #endif =20 --=20 2.32.0 From nobody Tue May 14 10:08:56 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=1645440681; cv=none; d=zohomail.com; s=zohoarc; b=kSr9i3As7cfqDO8V+5w+0Kp/shrSjF4I1qJjc9gkX5aS0mp7WG56ZLZjYtBGia9TnbGmjl1CHup5+9+GPoR1fI/5mmk+6RUwYg4mDKV51FqqPEo9yAX0F9+N1OACfMVzCsPxOi6SmseJojNjt7a/qjYn4IGLuZ79KITmBoZmDrw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645440681; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9KLsMofNLy3j5de3pHJ2lPBADdkm64K7Ef3aTBPoXCg=; b=YLmxCqhwEWIvr4On4jcC6vcd5NVJyfRPKw28T7k5YHlkKsNaNJonjse4mtJNjBYmuhwiNpjyOO0um3nhHqWqV7Vjy+Roj/rwlQ+Zafu3SbCfGbAxXumo/QTydjmkuLqWhltM+FCORjqQb5z7mOBXX3tqfCqdS4q3bYudaC+K19k= 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 1645440681388300.90785783674517; Mon, 21 Feb 2022 02:51:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.276098.472197 (Exim 4.92) (envelope-from ) id 1nM6HW-0007Sc-CH; Mon, 21 Feb 2022 10:51:02 +0000 Received: by outflank-mailman (output) from mailman id 276098.472197; Mon, 21 Feb 2022 10:51:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HV-0007OX-UA; Mon, 21 Feb 2022 10:51:01 +0000 Received: by outflank-mailman (input) for mailman id 276098; Mon, 21 Feb 2022 10:50:58 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HS-0006TD-Nq for xen-devel@lists.xenproject.org; Mon, 21 Feb 2022 10:50:58 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nM6HR-0002lv-Lv; Mon, 21 Feb 2022 10:50:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] 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 1nM5q6-00070b-S4; Mon, 21 Feb 2022 10:22:43 +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:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=9KLsMofNLy3j5de3pHJ2lPBADdkm64K7Ef3aTBPoXCg=; b=EjhcJAJOyC8rFVXQZJre5dJ2cS aBLNvlIDzKRFWDtl4HIrCxCQTl/vj3qIfuMKuwaZS5Zmy1QlE4m/ssrIA0gGmIHre40zkc2DYsiJU xPeoJ3octnCgPeYm83iM77GKyhZAIihkiqUTJLd/gO2W0jsEDkprdezTgf6Z22cIHuhA=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall Subject: [PATCH v3 19/19] xen/arm: mm: Re-implement setup_frame_table_mappings() with map_pages_to_xen() Date: Mon, 21 Feb 2022 10:22:18 +0000 Message-Id: <20220221102218.33785-20-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221102218.33785-1-julien@xen.org> References: <20220221102218.33785-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1645440683015100002 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that map_pages_to_xen() has been extended to support 2MB mappings, we can replace the create_mappings() call by map_pages_to_xen() call. This has the advantage to remove the differences between 32-bit and 64-bit code. Lastly remove create_mappings() as there is no more callers. Signed-off-by: Julien Grall Signed-off-by: Julien Grall Tested-by: Hongda Deng --- Changes in v3: - Fix typo in the commit message - Remove the TODO regarding contiguous bit Changes in v2: - New patch --- xen/arch/arm/mm.c | 63 ++++------------------------------------------- 1 file changed, 5 insertions(+), 58 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 4af59375d998..d73f49d5b6fc 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -354,40 +354,6 @@ void clear_fixmap(unsigned map) BUG_ON(res !=3D 0); } =20 -/* Create Xen's mappings of memory. - * Mapping_size must be either 2MB or 32MB. - * Base and virt must be mapping_size aligned. - * Size must be a multiple of mapping_size. - * second must be a contiguous set of second level page tables - * covering the region starting at virt_offset. */ -static void __init create_mappings(lpae_t *second, - unsigned long virt_offset, - unsigned long base_mfn, - unsigned long nr_mfns, - unsigned int mapping_size) -{ - unsigned long i, count; - const unsigned long granularity =3D mapping_size >> PAGE_SHIFT; - lpae_t pte, *p; - - ASSERT((mapping_size =3D=3D MB(2)) || (mapping_size =3D=3D MB(32))); - ASSERT(!((virt_offset >> PAGE_SHIFT) % granularity)); - ASSERT(!(base_mfn % granularity)); - ASSERT(!(nr_mfns % granularity)); - - count =3D nr_mfns / XEN_PT_LPAE_ENTRIES; - p =3D second + second_linear_offset(virt_offset); - pte =3D mfn_to_xen_entry(_mfn(base_mfn), MT_NORMAL); - if ( granularity =3D=3D 16 * XEN_PT_LPAE_ENTRIES ) - pte.pt.contig =3D 1; /* These maps are in 16-entry contiguous chu= nks. */ - for ( i =3D 0; i < count; i++ ) - { - write_pte(p + i, pte); - pte.pt.base +=3D 1 << XEN_PT_LPAE_SHIFT; - } - flush_xen_tlb_local(); -} - #ifdef CONFIG_DOMAIN_PAGE void *map_domain_page_global(mfn_t mfn) { @@ -846,36 +812,17 @@ void __init setup_frametable_mappings(paddr_t ps, pad= dr_t pe) unsigned long frametable_size =3D nr_pdxs * sizeof(struct page_info); mfn_t base_mfn; const unsigned long mapping_size =3D frametable_size < MB(32) ? MB(2) = : MB(32); -#ifdef CONFIG_ARM_64 - lpae_t *second, pte; - unsigned long nr_second; - mfn_t second_base; - int i; -#endif + int rc; =20 frametable_base_pdx =3D mfn_to_pdx(maddr_to_mfn(ps)); /* Round up to 2M or 32M boundary, as appropriate. */ frametable_size =3D ROUNDUP(frametable_size, mapping_size); base_mfn =3D alloc_boot_pages(frametable_size >> PAGE_SHIFT, 32<<(20-1= 2)); =20 -#ifdef CONFIG_ARM_64 - /* Compute the number of second level pages. */ - nr_second =3D ROUNDUP(frametable_size, FIRST_SIZE) >> FIRST_SHIFT; - second_base =3D alloc_boot_pages(nr_second, 1); - second =3D mfn_to_virt(second_base); - for ( i =3D 0; i < nr_second; i++ ) - { - clear_page(mfn_to_virt(mfn_add(second_base, i))); - pte =3D mfn_to_xen_entry(mfn_add(second_base, i), MT_NORMAL); - pte.pt.table =3D 1; - write_pte(&xen_first[first_table_offset(FRAMETABLE_VIRT_START)+i],= pte); - } - create_mappings(second, 0, mfn_x(base_mfn), frametable_size >> PAGE_SH= IFT, - mapping_size); -#else - create_mappings(xen_second, FRAMETABLE_VIRT_START, mfn_x(base_mfn), - frametable_size >> PAGE_SHIFT, mapping_size); -#endif + rc =3D map_pages_to_xen(FRAMETABLE_VIRT_START, base_mfn, + frametable_size >> PAGE_SHIFT, PAGE_HYPERVISOR_R= W); + if ( rc ) + panic("Unable to setup the frametable mappings.\n"); =20 memset(&frame_table[0], 0, nr_pdxs * sizeof(struct page_info)); memset(&frame_table[nr_pdxs], -1, --=20 2.32.0