From patchwork Sun Apr 25 20:13:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B179C433B4 for ; Sun, 25 Apr 2021 20:13:38 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 39E0261350 for ; Sun, 25 Apr 2021 20:13:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39E0261350 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117301.223106 (Exim 4.92) (envelope-from ) id 1lal89-0001RV-Rr; Sun, 25 Apr 2021 20:13:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117301.223106; Sun, 25 Apr 2021 20:13: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 1lal89-0001RO-OP; Sun, 25 Apr 2021 20:13:25 +0000 Received: by outflank-mailman (input) for mailman id 117301; Sun, 25 Apr 2021 20:13:24 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal88-0001QK-8J for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:13:24 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal87-0000o0-R7; Sun, 25 Apr 2021 20:13:23 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal87-0005m7-Gv; Sun, 25 Apr 2021 20:13:23 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=aeGTdR45KQ3asOXLFfCMyppOP+nTbqurYRYNJDh+L6k=; b=iMNjfTueq2jlaMv+RGtfn2lyn u750jZZVVvNq5BUM8wRsDBVg3PJlrmq3C5kCCB69a1gNwAiwBtlClrn73J6zujzywaGAM53jADEFx 41AGctMqHBV7mQ5CO/IRrpuYlpXglS/SK/AyuYPoXgFAn+30fTzbt/iSmRzj/xHcBu8Aw=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH RFCv2 01/15] xen/arm: lpae: Rename LPAE_ENTRIES_MASK_GS to LPAE_ENTRY_MASK_GS Date: Sun, 25 Apr 2021 21:13:04 +0100 Message-Id: <20210425201318.15447-2-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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 Acked-by: Stefano Stabellini --- Changes in v2: - New patch --- xen/include/asm-arm/lpae.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index e94de2e7d8e8..4fb9a40a4ca9 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -180,7 +180,7 @@ static inline bool lpae_is_superpage(lpae_t pte, unsigned 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) #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, unsigned int level) /* 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)) /* Generate an array @var containing the offset for each level from @addr */ #define DECLARE_OFFSETS(var, addr) \ From patchwork Sun Apr 25 20:13:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3551C43461 for ; Sun, 25 Apr 2021 20:13:40 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 86E5E611ED for ; Sun, 25 Apr 2021 20:13:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86E5E611ED Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117302.223114 (Exim 4.92) (envelope-from ) id 1lal8A-0001S6-8J; Sun, 25 Apr 2021 20:13:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117302.223114; Sun, 25 Apr 2021 20:13: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 1lal8A-0001Rp-23; Sun, 25 Apr 2021 20:13:26 +0000 Received: by outflank-mailman (input) for mailman id 117302; Sun, 25 Apr 2021 20:13:25 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal89-0001RJ-KT for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:13:25 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal89-0000o9-9c; Sun, 25 Apr 2021 20:13:25 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal89-0005m7-0v; Sun, 25 Apr 2021 20:13:25 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=LKWf7A+MF6uxi0Yzj4E+EHypbxoopwZaOMfIEc68W2U=; b=1SDMm0QKKs7ZTmqP/oyO5AZh9 0OPJ6JkxMteNKRWqu9oagsX/IqwziRYQxxOGM+zopceh8gifGisQ16kLw7DSM1BBWXXCHBqUL/WzF PG9/sViCrlB0jH55Aa9+Sr5Vu6QiedEczvB96Tb6NYy7xL2yVOyb9zzQBanYC1wVznCQ4=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH RFCv2 02/15] xen/arm: lpae: Use the generic helpers to defined the Xen PT helpers Date: Sun, 25 Apr 2021 21:13:05 +0100 Message-Id: <20210425201318.15447-3-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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. 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 --- Changes in v2: - New patch --- xen/include/asm-arm/lpae.h | 71 +++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index 4fb9a40a4ca9..310f5225e056 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -159,6 +159,17 @@ static inline bool lpae_is_superpage(lpae_t pte, unsigned int level) #define lpae_get_mfn(pte) (_mfn((pte).walk.base)) #define lpae_set_mfn(pte, mfn) ((pte).walk.base = mfn_x(mfn)) +/* Generate an array @var containing the offset for each level from @addr */ +#define DECLARE_OFFSETS(var, addr) \ + const unsigned int var[4] = { \ + 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, unsigned int level) #define LPAE_TABLE_INDEX_GS(gs, lvl, addr) \ (((addr) >> LEVEL_SHIFT_GS(gs, lvl)) & LPAE_ENTRY_MASK_GS(gs)) -/* Generate an array @var containing the offset for each level from @addr */ -#define DECLARE_OFFSETS(var, addr) \ - const unsigned int var[4] = { \ - 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, unsigned int level) * therefore 39-bits are sufficient. */ -#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 LPAE_SHIFT LPAE_SHIFT_GS(PAGE_SHIFT) +#define LPAE_ENTRIES LPAE_ENTRIES_GS(PAGE_SHIFT) +#define LPAE_ENTRY_MASK LPAE_ENTRY_MASK_GS(PAGE_SHIFT) + +#define LEVEL_SHIFT(lvl) LEVEL_SHIFT_GS(PAGE_SHIFT, lvl) +#define LEVEL_ORDER(lvl) LEVEL_ORDER_GS(PAGE_SHIFT, lvl) +#define LEVEL_SIZE(lvl) LEVEL_SIZE_GS(PAGE_SHIFT, lvl) +#define LEVEL_MASK(lvl) (~(LEVEL_SIZE(lvl) - 1)) + +/* Convenience aliases */ +#define THIRD_SHIFT LEVEL_SHIFT(3) +#define THIRD_ORDER LEVEL_ORDER(3) +#define THIRD_SIZE LEVEL_SIZE(3) +#define THIRD_MASK LEVEL_MASK(3) + +#define SECOND_SHIFT LEVEL_SHIFT(2) +#define SECOND_ORDER LEVEL_ORDER(2) +#define SECOND_SIZE LEVEL_SIZE(2) +#define SECOND_MASK LEVEL_MASK(2) + +#define FIRST_SHIFT LEVEL_SHIFT(1) +#define FIRST_ORDER LEVEL_ORDER(1) +#define FIRST_SIZE LEVEL_SIZE(1) +#define FIRST_MASK LEVEL_MASK(1) + +#define ZEROETH_SHIFT LEVEL_SHIFT(0) +#define ZEROETH_ORDER LEVEL_ORDER(0) +#define ZEROETH_SIZE LEVEL_SIZE(0) +#define ZEROETH_MASK LEVEL_MASK(0) /* Calculate the offsets into the pagetables for a given VA */ #define zeroeth_linear_offset(va) ((va) >> ZEROETH_SHIFT) From patchwork Sun Apr 25 20:13:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223547 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CD55C43460 for ; Sun, 25 Apr 2021 20:13:38 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 39D6261288 for ; Sun, 25 Apr 2021 20:13:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39D6261288 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117303.223130 (Exim 4.92) (envelope-from ) id 1lal8C-0001Uw-G0; Sun, 25 Apr 2021 20:13:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117303.223130; Sun, 25 Apr 2021 20:13:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8C-0001Uo-Cj; Sun, 25 Apr 2021 20:13:28 +0000 Received: by outflank-mailman (input) for mailman id 117303; Sun, 25 Apr 2021 20:13:27 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8B-0001Tv-5i for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:13:27 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8A-0000oJ-Pf; Sun, 25 Apr 2021 20:13:26 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8A-0005m7-HE; Sun, 25 Apr 2021 20:13:26 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=jWWczyhwx5+vonIhKTnyI8FTuC3mdInSZ1tXL3+0cBg=; b=Ib3Ub05fstFLx8pqFUj2tpx+l trTAMuc4XOpZ5Ge3426W5ETmcqn+9nMYRWdSyFl1hqYnuX24sOs/5xujbt/yU6hFC4Lf/3TBv1XyX O/RHbp+NCSWqVgNXGMv5ufJ5fIS+JQAYXDDVPXNLyDD3J+BCASCvzJ22oiGOXTiS813jc=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH RFCv2 03/15] xen/arm: p2m: Replace level_{orders, masks} arrays with LEVEL_{ORDER, MASK} Date: Sun, 25 Apr 2021 21:13:06 +0100 Message-Id: <20210425201318.15447-4-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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 Acked-by: Stefano Stabellini --- Changes in v2: - New patch --- xen/arch/arm/p2m.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index ac5031262061..1b04c3534439 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -36,12 +36,6 @@ static unsigned int __read_mostly max_vmid = MAX_VMID_8_BIT; */ unsigned int __read_mostly p2m_ipa_bits = 64; -/* Helpers to lookup the properties of each level */ -static const paddr_t level_masks[] = - { ZEROETH_MASK, FIRST_MASK, SECOND_MASK, THIRD_MASK }; -static const uint8_t level_orders[] = - { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER }; - static mfn_t __read_mostly empty_root_mfn; static uint64_t generate_vttbr(uint16_t vmid, mfn_t root_mfn) @@ -232,7 +226,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 = gfn_x(gfn) >> (level_orders[P2M_ROOT_LEVEL] + LPAE_SHIFT); + root_table = gfn_x(gfn) >> (LEVEL_ORDER(P2M_ROOT_LEVEL) + LPAE_SHIFT); if ( root_table >= P2M_ROOT_PAGES ) return NULL; @@ -378,7 +372,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 = P2M_ROOT_LEVEL; level < 3; level++ ) - if ( (gfn_x(gfn) & (level_masks[level] >> PAGE_SHIFT)) > + if ( (gfn_x(gfn) & (LEVEL_MASK(level) >> PAGE_SHIFT)) > gfn_x(p2m->max_mapped_gfn) ) break; @@ -421,7 +415,7 @@ 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 = mfn_add(mfn, gfn_x(gfn) & ((1UL << level_orders[level]) - 1)); + mfn = mfn_add(mfn, gfn_x(gfn) & ((1UL << LEVEL_ORDER(level)) - 1)); if ( valid ) *valid = lpae_is_valid(entry); @@ -432,7 +426,7 @@ out_unmap: out: if ( page_order ) - *page_order = level_orders[level]; + *page_order = LEVEL_ORDER(level); return mfn; } @@ -806,7 +800,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m, lpae_t *entry, /* Convenience aliases */ mfn_t mfn = lpae_get_mfn(*entry); unsigned int next_level = level + 1; - unsigned int level_order = level_orders[next_level]; + unsigned int level_order = LEVEL_ORDER(next_level); /* * This should only be called with target != level and the entry is From patchwork Sun Apr 25 20:13:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A204C43462 for ; Sun, 25 Apr 2021 20:13:40 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 355CC611ED for ; Sun, 25 Apr 2021 20:13:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 355CC611ED Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117304.223143 (Exim 4.92) (envelope-from ) id 1lal8E-0001Yc-Qk; Sun, 25 Apr 2021 20:13:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117304.223143; Sun, 25 Apr 2021 20:13: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 1lal8E-0001YT-NH; Sun, 25 Apr 2021 20:13:30 +0000 Received: by outflank-mailman (input) for mailman id 117304; Sun, 25 Apr 2021 20:13:29 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8C-0001W7-Vu for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:13:28 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8C-0000oV-Hb; Sun, 25 Apr 2021 20:13:28 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8C-0005m7-4y; Sun, 25 Apr 2021 20:13:28 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=lBfQueqmN8lGEfYvmwCQNPeVCuWNGXAaHJKI8fcyO7c=; b=ypvOlVCA4WHF0pL5/WG6c5HOo k9ybUduQYf91ZwDEarIKEk6z1uwks64TuJ3Pz1cGWgW0O7vUTP0IEMsP/dogcLhRB9E0IFu1b4haA zkhTQFFg3irUF+JPz9h+sbZIMexFdageCS/DsCX39slv4XPCAm6ZwLTdcihHAmB8BuvjQ=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Julien Grall Subject: [PATCH RFCv2 04/15] xen/arm: mm: Allow other mapping size in xen_pt_update_entry() Date: Sun, 25 Apr 2021 21:13:07 +0100 Message-Id: <20210425201318.15447-5-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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/modify 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 mean 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 Reviewed-by: Stefano Stabellini --- 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/mm.c | 93 ++++++++++++++++++++++++++++++-------- xen/include/asm-arm/page.h | 4 ++ 2 files changed, 79 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 59f8a3f15fd1..8ebb36899314 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1060,9 +1060,10 @@ static int xen_pt_next_level(bool read_only, unsigned int level, } /* 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. */ @@ -1072,6 +1073,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) return false; } + /* 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 != PAGE_AI_MASK(flags) ) { @@ -1087,7 +1095,7 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, 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. */ @@ -1096,18 +1104,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 (%#"PRI_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)) == 0 ) { /* We should be here with an invalid MFN. */ ASSERT(mfn_eq(mfn, INVALID_MFN)); - /* 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 allowed.\n"); @@ -1125,13 +1143,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) return true; } +/* 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 = 3; lpae_t *table; /* * The intermediate page tables are read-only when the MFN is not valid @@ -1186,7 +1204,7 @@ static int xen_pt_update_entry(mfn_t root, unsigned long virt, entry = table + offsets[level]; rc = -EINVAL; - if ( !xen_pt_check_entry(*entry, mfn, flags) ) + if ( !xen_pt_check_entry(*entry, mfn, level, flags) ) goto out; /* If we are only populating page-table, then we are done. */ @@ -1204,8 +1222,11 @@ static int xen_pt_update_entry(mfn_t root, unsigned long virt, { pte = mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); - /* Third level entries set pte.pt.table = 1 */ - pte.pt.table = 1; + /* + * First and second level pages set pte.pt.table = 0, but + * third level entries set pte.pt.table = 1. + */ + pte.pt.table = (level == 3); } else /* We are updating the permission => Copy the current pte. */ pte = *entry; @@ -1229,11 +1250,12 @@ static DEFINE_SPINLOCK(xen_pt_lock); 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 = 0; - unsigned long addr = virt, addr_end = addr + nr_mfns * PAGE_SIZE; + unsigned long vfn = virt >> PAGE_SHIFT; + unsigned long left = nr_mfns; /* * For arm32, page-tables are different on each CPUs. Yet, they share @@ -1265,14 +1287,49 @@ static int xen_pt_update(unsigned long virt, spin_lock(&xen_pt_lock); - for ( ; addr < addr_end; addr += PAGE_SIZE ) + while ( left ) { - rc = xen_pt_update_entry(root, addr, mfn, flags); + unsigned int order, level; + unsigned long mask; + + /* + * Don't take into account the MFN when removing mapping (i.e + * MFN_INVALID) to calculate the correct target order. + * + * This loop relies on mfn, vfn, and nr_mfn to be all superpage + * aligned (mfn and vfn have to be architecturally), and it uses + * `mask` to check for that. + * + * XXX: Support superpage mappings if nr is not aligned to a + * superpage size. + */ + mask = !mfn_eq(mfn, INVALID_MFN) ? mfn_x(mfn) : 0; + mask |= vfn | left; + + /* + * Always use level 3 mapping unless the caller request block + * mapping. + */ + if ( likely(!(flags & _PAGE_BLOCK)) ) + level = 3; + else if ( !(mask & (BIT(FIRST_ORDER, UL) - 1)) ) + level = 1; + else if ( !(mask & (BIT(SECOND_ORDER, UL) - 1)) ) + level = 2; + else + level = 3; + + order = LEVEL_ORDER(level); + + rc = xen_pt_update_entry(root, pfn_to_paddr(vfn), mfn, level, flags); if ( rc ) break; + vfn += 1U << order; if ( !mfn_eq(mfn, INVALID_MFN) ) - mfn = mfn_add(mfn, 1); + mfn = mfn_add(mfn, 1U << order); + + left -= (1U << order); } /* diff --git a/xen/include/asm-arm/page.h b/xen/include/asm-arm/page.h index 131507a51712..7052a87ec0fe 100644 --- a/xen/include/asm-arm/page.h +++ b/xen/include/asm-arm/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) @@ -82,6 +83,9 @@ #define _PAGE_PRESENT (1U << 5) #define _PAGE_POPULATE (1U << 6) +#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. From patchwork Sun Apr 25 20:13:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DECCAC433ED for ; Sun, 25 Apr 2021 20:13:39 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9C68561285 for ; Sun, 25 Apr 2021 20:13:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C68561285 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117305.223152 (Exim 4.92) (envelope-from ) id 1lal8F-0001aF-IZ; Sun, 25 Apr 2021 20:13:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117305.223152; Sun, 25 Apr 2021 20:13:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8F-0001Zz-8n; Sun, 25 Apr 2021 20:13:31 +0000 Received: by outflank-mailman (input) for mailman id 117305; Sun, 25 Apr 2021 20:13:30 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8E-0001Y5-Am for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:13:30 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8E-0000od-1A; Sun, 25 Apr 2021 20:13:30 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8D-0005m7-Ow; Sun, 25 Apr 2021 20:13:30 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=qdn1le94TFR9RGBuVbMK3tl4UOk0qVZcjP09VJjmTGA=; b=kSyw3dlhX1A7P2j0w/l4hybr8 Ud7zQLDGt7Mn8i2uLPIulsJTxh+GPmAfBOJ+yF7305IdEUH38vps72MRsC2vx5R8CCCdDVKY8IHQD 9hFVBq73P0B1YneXKbnrgn/waWH4v8dVnu9t/ZXBysrReYhDJFh8i2DS0ckzPd97eWLYM=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH RFCv2 05/15] xen/arm: mm: Avoid flushing the TLBs when mapping are inserted Date: Sun, 25 Apr 2021 21:13:08 +0100 Message-Id: <20210425201318.15447-6-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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 Reviewed-by: Stefano Stabellini --- 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 8ebb36899314..1fe52b3af722 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1101,7 +1101,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int level, /* We should be here with a valid MFN. */ ASSERT(!mfn_eq(mfn, INVALID_MFN)); - /* 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) ) @@ -1333,11 +1339,16 @@ static int xen_pt_update(unsigned long virt, } /* - * 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 are 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); spin_unlock(&xen_pt_lock); From patchwork Sun Apr 25 20:13:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D0ABC43461 for ; Sun, 25 Apr 2021 20:13:44 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 13E4F611ED for ; Sun, 25 Apr 2021 20:13:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 13E4F611ED Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117306.223167 (Exim 4.92) (envelope-from ) id 1lal8H-0001ex-S2; Sun, 25 Apr 2021 20:13:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117306.223167; Sun, 25 Apr 2021 20:13: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 1lal8H-0001el-NM; Sun, 25 Apr 2021 20:13:33 +0000 Received: by outflank-mailman (input) for mailman id 117306; Sun, 25 Apr 2021 20:13:32 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8G-0001ci-6i for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:13:32 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8F-0000om-LM; Sun, 25 Apr 2021 20:13:31 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8F-0005m7-Cs; Sun, 25 Apr 2021 20:13:31 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=siVUWwfApP96aB3lihKwJZ2TVvy/coY05i6ribyQkaQ=; b=TFO4q8j8JOAgGjBBHSZTLC9+u iMlWqMTBkWFPT36hYWWc45g8Fn5uSG78rEvAy+6H21I/Zi1kc+RNJ+JDddxtmVz/WrZPfWXlehK++ RbjszRSe7SLY8uM6Tn4Vd5WPAUN7qbDigjXmUG8LihxVjqOpSclHnKLMMocAWn9vFeTmM=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Julien Grall Subject: [PATCH RFCv2 06/15] xen/arm: mm: Don't open-code Xen PT update in remove_early_mappings() Date: Sun, 25 Apr 2021 21:13:09 +0100 Message-Id: <20210425201318.15447-7-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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 Acked-by: Stefano Stabellini --- 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 1fe52b3af722..2cbfbe25240e 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -598,11 +598,11 @@ void * __init early_fdt_map(paddr_t fdt_paddr) void __init remove_early_mappings(void) { - lpae_t pte = {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 = modify_xen_mappings(BOOT_FDT_VIRT_START, BOOT_FDT_VIRT_END, + _PAGE_BLOCK); + BUG_ON(rc); } /* From patchwork Sun Apr 25 20:13:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AB9DC433ED for ; Sun, 25 Apr 2021 20:13:43 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C6DB6124B for ; Sun, 25 Apr 2021 20:13:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C6DB6124B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117307.223179 (Exim 4.92) (envelope-from ) id 1lal8J-0001iY-Cr; Sun, 25 Apr 2021 20:13:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117307.223179; Sun, 25 Apr 2021 20:13:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8J-0001iD-4n; Sun, 25 Apr 2021 20:13:35 +0000 Received: by outflank-mailman (input) for mailman id 117307; Sun, 25 Apr 2021 20:13:33 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8H-0001eY-IA for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:13:33 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8H-0000ow-92; Sun, 25 Apr 2021 20:13:33 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8H-0005m7-0N; Sun, 25 Apr 2021 20:13:33 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=BjS7PbV9YIvothNxojvfyxpwJGXVh+HIjQYc5MW8oEY=; b=5HLK2dyh1X7dCPn8EtxAG9MCg Bsj2Nv2kLQNEpk6BmPmNgnoREbSJ8Ey6254znwK/FVhZvMRRVfzwomElROXT24J4u34Avbssq+C0b NIrGT3Cae/S5MRKrG9thBQjGB4MOjLU4O0CUmtuFf5eWGgBQMki4bjoQEFLQw+9MHNe/c=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Julien Grall Subject: [PATCH RFCv2 07/15] xen/arm: mm: Re-implement early_fdt_map() using map_pages_to_xen() Date: Sun, 25 Apr 2021 21:13:10 +0100 Message-Id: <20210425201318.15447-8-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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: Stefano Stabellini --- 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 2cbfbe25240e..8fac24d80086 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -558,6 +558,7 @@ void * __init early_fdt_map(paddr_t fdt_paddr) paddr_t offset; void *fdt_virt; uint32_t size; + int rc; /* * Check whether the physical FDT address is set and meets the minimum @@ -573,8 +574,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); - create_mappings(xen_second, BOOT_FDT_VIRT_START, paddr_to_pfn(base_paddr), - SZ_2M >> PAGE_SHIFT, SZ_2M); + rc = 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"); + offset = fdt_paddr % SECOND_SIZE; fdt_virt = (void *)BOOT_FDT_VIRT_START + offset; @@ -588,9 +593,12 @@ void * __init early_fdt_map(paddr_t fdt_paddr) 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 = 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"); } return fdt_virt; From patchwork Sun Apr 25 20:13:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C013C43462 for ; Sun, 25 Apr 2021 20:13:44 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 62C38611ED for ; Sun, 25 Apr 2021 20:13:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62C38611ED Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117308.223187 (Exim 4.92) (envelope-from ) id 1lal8K-0001kE-7t; Sun, 25 Apr 2021 20:13:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117308.223187; Sun, 25 Apr 2021 20:13:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8J-0001ji-Ln; Sun, 25 Apr 2021 20:13:35 +0000 Received: by outflank-mailman (input) for mailman id 117308; Sun, 25 Apr 2021 20:13:35 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8J-0001i6-0m for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:13:35 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8I-0000p4-Ou; Sun, 25 Apr 2021 20:13:34 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8I-0005m7-GR; Sun, 25 Apr 2021 20:13:34 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=NkFXrdGqH4EPmzou9mWkeqYkQCSaITClqSn4Be5r/zI=; b=F12nHvd4PDHg3Ann1gEV5mT4c Uyt5mKxNT0Cx4WZY9me+oL5J3D/WXAT5LwiE0CtuebDNHBPCDkY/xwx5/hvekdxLkyxdp96WPtOYW ShK7euMpoS4UkgoRNayfziVBZWzNdioOmRY1Zq5PGedJHx43r8QbptSw+5TBrdshL7AiM=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH RFCv2 08/15] xen/arm32: mm: Check if the virtual address is shared before updating it Date: Sun, 25 Apr 2021 21:13:11 +0100 Message-Id: <20210425201318.15447-9-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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 is 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 ened 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 Reviewed-by: Stefano Stabellini --- Changes in v2: - New patch --- xen/arch/arm/mm.c | 11 +++++++++-- xen/include/asm-arm/config.h | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 8fac24d80086..5c17cafff847 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1275,11 +1275,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 = virt_to_mfn(THIS_CPU_PGTABLE); +#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. diff --git a/xen/include/asm-arm/config.h b/xen/include/asm-arm/config.h index c7b77912013e..85d4a510ce8a 100644 --- a/xen/include/asm-arm/config.h +++ b/xen/include/asm-arm/config.h @@ -137,6 +137,10 @@ #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) From patchwork Sun Apr 25 20:13:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30028C433B4 for ; Sun, 25 Apr 2021 20:13:51 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EE6A6611ED for ; Sun, 25 Apr 2021 20:13:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE6A6611ED Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117309.223203 (Exim 4.92) (envelope-from ) id 1lal8M-0001rN-MS; Sun, 25 Apr 2021 20:13:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117309.223203; Sun, 25 Apr 2021 20:13:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8M-0001r4-Ep; Sun, 25 Apr 2021 20:13:38 +0000 Received: by outflank-mailman (input) for mailman id 117309; Sun, 25 Apr 2021 20:13:36 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8K-0001mW-IE for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:13:36 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lal8K-0000pC-8v; Sun, 25 Apr 2021 20:13:36 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8K-0005m7-0R; Sun, 25 Apr 2021 20:13:36 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Moqxyc1ZPjrdBFjtAzt9LgU5Lw+fiLu9r1elfDAEKcE=; b=yM5oyAyjNFkRoriEbAu8nWkgg UlBONVmOVRgQO+sDd02/RWxitSO8BTbZai7UE596NzmhmJKm7Nt9Ga0ZR0gKc7Fy7I76MQp4D/2eJ e8q1+blNljXuHofnGkUdwe60An/1k1cLI+uGyXeIIuczJV16/QlepsBcue5JTfx0B6QOU=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH RFCv2 09/15] xen/arm32: mm: Re-implement setup_xenheap_mappings() using map_pages_to_xen() Date: Sun, 25 Apr 2021 21:13:12 +0100 Message-Id: <20210425201318.15447-10-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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 --- 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 5c17cafff847..19ecf73542ce 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -806,7 +806,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 = map_pages_to_xen(XENHEAP_VIRT_START, base_mfn, nr_mfns, + PAGE_HYPERVISOR_RW | _PAGE_BLOCK); + if ( rc ) + panic("Unable to setup the xenheap mappings.\n"); /* Record where the xenheap is, for translation routines. */ xenheap_virt_end = XENHEAP_VIRT_START + nr_mfns * PAGE_SIZE; From patchwork Sun Apr 25 20:13:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAD37C433ED for ; Sun, 25 Apr 2021 20:32:33 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6F45961260 for ; Sun, 25 Apr 2021 20:32:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F45961260 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117357.223226 (Exim 4.92) (envelope-from ) id 1lalQN-0004Re-Lk; Sun, 25 Apr 2021 20:32:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117357.223226; Sun, 25 Apr 2021 20:32:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQN-0004RX-Iq; Sun, 25 Apr 2021 20:32:15 +0000 Received: by outflank-mailman (input) for mailman id 117357; Sun, 25 Apr 2021 20:32:13 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-0004R3-KB for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:32:13 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-00019r-2B; Sun, 25 Apr 2021 20:32:13 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8L-0005m7-GV; Sun, 25 Apr 2021 20:13:37 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=MTKf2MkfWHAQW1rNB3O16F5z9jItgd6Wm5yHl60rcz0=; b=G4cjzDdnao/cYiBL47XbuXs7H jcxnQhIHE7VNkYj+iwSl9M8ppJlJlms/56Y8BuWXUNIKuS4swrS8gfymRWyh7URLqVBIPPRmOKRrq 3kvfWWmum3NoGMd6aslV38Tmoj7VYoOOAnEaAlzcTsOPbL/KQJSqIVINt6GZUrLEgE7qE=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH RFCv2 10/15] xen/arm: mm: Allocate xen page tables in domheap rather than xenheap Date: Sun, 25 Apr 2021 21:13:13 +0100 Message-Id: <20210425201318.15447-11-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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 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 19ecf73542ce..ae5a07ea956b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -969,21 +969,6 @@ void *ioremap(paddr_t pa, size_t len) return ioremap_attr(pa, len, PAGE_HYPERVISOR_NOCACHE); } -static int create_xen_table(lpae_t *entry) -{ - void *p; - lpae_t pte; - - p = alloc_xenheap_page(); - if ( p == NULL ) - return -ENOMEM; - clear_page(p); - pte = mfn_to_xen_entry(virt_to_mfn(p), MT_NORMAL); - pte.pt.table = 1; - write_pte(entry, pte); - return 0; -} - static lpae_t *xen_map_table(mfn_t mfn) { /* @@ -1024,6 +1009,27 @@ static void xen_unmap_table(const lpae_t *table) unmap_domain_page(table); } +static int create_xen_table(lpae_t *entry) +{ + struct page_info *pg; + void *p; + lpae_t pte; + + pg = alloc_domheap_page(NULL, 0); + if ( pg == NULL ) + return -ENOMEM; + + p = xen_map_table(page_to_mfn(pg)); + clear_page(p); + xen_unmap_table(p); + + pte = mfn_to_xen_entry(page_to_mfn(pg), MT_NORMAL); + pte.pt.table = 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 From patchwork Sun Apr 25 20:13:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 533B8C433B4 for ; Sun, 25 Apr 2021 20:32:28 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1A64E61285 for ; Sun, 25 Apr 2021 20:32:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A64E61285 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117359.223243 (Exim 4.92) (envelope-from ) id 1lalQO-0004So-BC; Sun, 25 Apr 2021 20:32:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117359.223243; Sun, 25 Apr 2021 20:32:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQO-0004ST-4L; Sun, 25 Apr 2021 20:32:16 +0000 Received: by outflank-mailman (input) for mailman id 117359; Sun, 25 Apr 2021 20:32:13 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-0004RD-NI for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:32:13 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-00019v-8G; Sun, 25 Apr 2021 20:32:13 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8N-0005m7-4G; Sun, 25 Apr 2021 20:13:39 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=kyXJNvfLj/1Qpk3hX2ctxX4bb1KB1kLqdFkNoEVhegI=; b=DMPjMKHaz0psSHPwnrQmyg1DL 5KZAnETEyRoMzMfgNqCyiOVcqcKu1W0hkOR3+LKUZ+oLcbcewEYQEtAqwwO50IMuRjtPur0d88H8y NL+elfsaML0BFMmROqtyeTC1Lp8vamrPgfUlhv+xqULeHNNcCEWErnA/oq7g15AaS6YZM=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Julien Grall Subject: [PATCH RFCv2 11/15] xen/arm: mm: Allow page-table allocation from the boot allocator Date: Sun, 25 Apr 2021 21:13:14 +0100 Message-Id: <20210425201318.15447-12-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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 ae5a07ea956b..d090fdfd5994 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1011,19 +1011,27 @@ static void xen_unmap_table(const lpae_t *table) static int create_xen_table(lpae_t *entry) { - struct page_info *pg; + mfn_t mfn; void *p; lpae_t pte; - pg = alloc_domheap_page(NULL, 0); - if ( pg == NULL ) - return -ENOMEM; + if ( system_state != SYS_STATE_early_boot ) + { + struct page_info *pg = alloc_domheap_page(NULL, 0); + + if ( pg == NULL ) + return -ENOMEM; + + mfn = page_to_mfn(pg); + } + else + mfn = alloc_boot_pages(1, 1); - p = xen_map_table(page_to_mfn(pg)); + p = xen_map_table(mfn); clear_page(p); xen_unmap_table(p); - pte = mfn_to_xen_entry(page_to_mfn(pg), MT_NORMAL); + pte = mfn_to_xen_entry(mfn, MT_NORMAL); pte.pt.table = 1; write_pte(entry, pte); From patchwork Sun Apr 25 20:13:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34A61C433ED for ; Sun, 25 Apr 2021 20:32:28 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DF20361260 for ; Sun, 25 Apr 2021 20:32:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF20361260 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117362.223272 (Exim 4.92) (envelope-from ) id 1lalQP-0004VN-K7; Sun, 25 Apr 2021 20:32:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117362.223272; Sun, 25 Apr 2021 20:32:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQP-0004Us-5d; Sun, 25 Apr 2021 20:32:17 +0000 Received: by outflank-mailman (input) for mailman id 117362; Sun, 25 Apr 2021 20:32:13 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-0004RP-Tj for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:32:13 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-00019x-B1; Sun, 25 Apr 2021 20:32:13 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8P-0005m7-E0; Sun, 25 Apr 2021 20:13:41 +0000 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=d6/VERpOpmisc9IqH4nSo3nCT42W307X8jAJ7pAR9wY=; b=QsI0i3rJK15J/0NratxUSYmB11 vqx01X+WXK6ipXuw4wnzdoVpmp4I6SyXrpjlZ3uWaXiFaxzBYJ7MROjAr/udNlVZ+j6HoMLC89me/ U2gp72yg8I8k7DB5XhtWB8QDPNffTJgN7DfyV3HYm8MATdClvH0+Ka/Pd4dTJNRR7cBU=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Hongyan Xia , Julien Grall , Jan Beulich , Wei Liu , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Hongian Xia Subject: [PATCH RFCv2 12/15] xen/arm: add Persistent Map (PMAP) infrastructure Date: Sun, 25 Apr 2021 21:13:15 +0100 Message-Id: <20210425201318.15447-13-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> MIME-Version: 1.0 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. Take the opportunity to switch 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 v2: - New patch Cc: Jan Beulich Cc: Wei Liu Cc: Andrew Cooper Cc: Roger Pau Monné Cc: Hongian Xia This is mostly a copy of the PMAP infrastructure currently discussed on x86. The only difference is how the page-tables are updated. I think we want to consider to provide a common infrastructure. But I haven't done it yet to gather feedback on the overall series first. --- xen/arch/arm/Makefile | 1 + xen/arch/arm/mm.c | 7 +-- xen/arch/arm/pmap.c | 101 +++++++++++++++++++++++++++++++++++ xen/include/asm-arm/config.h | 2 + xen/include/asm-arm/lpae.h | 8 +++ xen/include/asm-arm/pmap.h | 10 ++++ 6 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 xen/arch/arm/pmap.c create mode 100644 xen/include/asm-arm/pmap.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index ca75f1040dcc..2196ada24941 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -40,6 +40,7 @@ obj-y += percpu.o obj-y += platform.o obj-y += platform_hypercall.o obj-y += physdev.o +obj-y += pmap.init.o obj-y += processor.o obj-y += psci.o obj-y += setup.o diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index d090fdfd5994..5e713b599611 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -288,12 +288,7 @@ void dump_hyp_walk(vaddr_t addr) dump_pt_walk(ttbr, addr, HYP_PT_ROOT_LEVEL, 1); } -/* - * 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 = (lpae_t) { .pt = { diff --git a/xen/arch/arm/pmap.c b/xen/arch/arm/pmap.c new file mode 100644 index 000000000000..702b1bde982d --- /dev/null +++ b/xen/arch/arm/pmap.c @@ -0,0 +1,101 @@ +#include +#include + +#include +#include +#include + +/* + * To be able to use FIXMAP_PMAP_BEGIN. + * XXX: move fixmap definition in a separate header + */ +#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 after + * smp bring-up. + */ + +/* Bitmap to track which slot is used */ +static unsigned long __initdata inuse; + +/* XXX: Find an header to declare it */ +extern lpae_t xen_fixmap[LPAE_ENTRIES]; + +void *__init pmap_map(mfn_t mfn) +{ + unsigned long flags; + unsigned int idx; + vaddr_t linear; + unsigned int slot; + lpae_t *entry, pte; + + BUILD_BUG_ON(sizeof(inuse) * BITS_PER_LONG < NUM_FIX_PMAP); + + ASSERT(system_state < SYS_STATE_smp_boot); + + local_irq_save(flags); + + idx = find_first_zero_bit(&inuse, NUM_FIX_PMAP); + if ( idx == NUM_FIX_PMAP ) + panic("Out of PMAP slots\n"); + + __set_bit(idx, &inuse); + + slot = idx + FIXMAP_PMAP_BEGIN; + ASSERT(slot >= FIXMAP_PMAP_BEGIN && slot <= FIXMAP_PMAP_END); + + linear = FIXMAP_ADDR(slot); + /* + * We cannot use set_fixmap() here. We use PMAP when there is no direct 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(). + */ + entry = &xen_fixmap[third_table_offset(linear)]; + + ASSERT(!lpae_is_valid(*entry)); + + pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); + pte.pt.table = 1; + write_pte(entry, pte); + + local_irq_restore(flags); + + return (void *)linear; +} + +void __init pmap_unmap(const void *p) +{ + unsigned long flags; + unsigned int idx; + lpae_t *entry; + lpae_t pte = { 0 }; + unsigned int slot = third_table_offset((vaddr_t)p); + + ASSERT(system_state < SYS_STATE_smp_boot); + ASSERT(slot >= FIXMAP_PMAP_BEGIN && slot <= FIXMAP_PMAP_END); + + idx = slot - FIXMAP_PMAP_BEGIN; + local_irq_save(flags); + + __clear_bit(idx, &inuse); + entry = &xen_fixmap[third_table_offset((vaddr_t)p)]; + write_pte(entry, pte); + flush_xen_tlb_range_va_local((vaddr_t)p, PAGE_SIZE); + + 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/asm-arm/config.h b/xen/include/asm-arm/config.h index 85d4a510ce8a..35050855b6e1 100644 --- a/xen/include/asm-arm/config.h +++ b/xen/include/asm-arm/config.h @@ -180,6 +180,8 @@ #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) +#define FIXMAP_PMAP_END (FIXMAP_PMAP_BEGIN + NUM_FIX_PMAP - 1) #define NR_hypercalls 64 diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index 310f5225e056..81fd482ab2ce 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -4,6 +4,7 @@ #ifndef __ASSEMBLY__ #include +#include /* * WARNING! Unlike the x86 pagetable code, where l1 is the lowest level and @@ -168,6 +169,13 @@ static inline bool lpae_is_superpage(lpae_t pte, unsigned int level) third_table_offset(addr) \ } +/* + * 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__ */ /* diff --git a/xen/include/asm-arm/pmap.h b/xen/include/asm-arm/pmap.h new file mode 100644 index 000000000000..8e1dce93f8e4 --- /dev/null +++ b/xen/include/asm-arm/pmap.h @@ -0,0 +1,10 @@ +#ifndef __ASM_PMAP_H__ +#define __ARM_PMAP_H__ + +/* Large enough for mapping 5 levels of page tables with some headroom */ +#define NUM_FIX_PMAP 8 + +void *pmap_map(mfn_t mfn); +void pmap_unmap(const void *p); + +#endif /* __ASM_PMAP_H__ */ From patchwork Sun Apr 25 20:13:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9C73C43460 for ; Sun, 25 Apr 2021 20:32:28 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A9366610C8 for ; Sun, 25 Apr 2021 20:32:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9366610C8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117360.223251 (Exim 4.92) (envelope-from ) id 1lalQO-0004Ti-M1; Sun, 25 Apr 2021 20:32:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117360.223251; Sun, 25 Apr 2021 20:32:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQO-0004TE-EG; Sun, 25 Apr 2021 20:32:16 +0000 Received: by outflank-mailman (input) for mailman id 117360; Sun, 25 Apr 2021 20:32:13 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-0004RI-Nv for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:32:13 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-00019z-Ce; Sun, 25 Apr 2021 20:32:13 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8Q-0005m7-UI; Sun, 25 Apr 2021 20:13:43 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ifKF5vlWlY6l4PDeK/yzMglzvzJIHrIdX0+DxnqU6gM=; b=aDVnd/t+JJAmjS00rJXk2q4jN NB5fjWXRYRB+MKeBuWXa+51DmJcKGs1okA0zWazHweIwAGmQuQ690dWiAfxlOETAZcE/HXrdIpYiR 9ITanj2BNk+LUga8ozVtM/xy09nsQjKU+H7TSQvg2ECM433eSsnRQ4dJR1QbD5ssqU8Gw=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH RFCv2 13/15] xen/arm: mm: Use the PMAP helpers in xen_{,un}map_table() Date: Sun, 25 Apr 2021 21:13:16 +0100 Message-Id: <20210425201318.15447-14-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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 5e713b599611..f5768f2d4a81 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -41,6 +41,7 @@ #include #include +#include #include /* Override macros from asm/page.h to make them work with mfn_t */ @@ -967,27 +968,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 == 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 = mfn_to_maddr(mfn) - virt_to_maddr(&_start); - - return (lpae_t *)(XEN_VIRT_START + offset); - } - } + return pmap_map(mfn); return map_domain_page(mfn); } @@ -996,12 +981,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 == SYS_STATE_early_boot && is_kernel(table) ) - return; - - unmap_domain_page(table); + if ( system_state == SYS_STATE_early_boot ) + pmap_unmap(table); + else + unmap_domain_page(table); } static int create_xen_table(lpae_t *entry) From patchwork Sun Apr 25 20:13:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA05EC43462 for ; Sun, 25 Apr 2021 20:32:29 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 96ED1610C8 for ; Sun, 25 Apr 2021 20:32:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96ED1610C8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117361.223265 (Exim 4.92) (envelope-from ) id 1lalQP-0004UO-9Q; Sun, 25 Apr 2021 20:32:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117361.223265; Sun, 25 Apr 2021 20:32:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQO-0004U0-PL; Sun, 25 Apr 2021 20:32:16 +0000 Received: by outflank-mailman (input) for mailman id 117361; Sun, 25 Apr 2021 20:32:13 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-0004RN-TQ for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:32:13 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-0001A1-FU; Sun, 25 Apr 2021 20:32:13 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8S-0005m7-I0; Sun, 25 Apr 2021 20:13:44 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=kWwF6/XiImdq/NMXQrU9YONcKwipFpia2KSsKJxknoU=; b=fuqgFWg/KYT7rBgGpcjFUhEDq wF64yv2LQnpsv33Z7VtoKGU67NQb+prKwQkNbVylwDYBIAChrckdb3+aPe9pjsdONt7cI9jsj3m5/ +KpYjEY0MTcKXzpJf2BI1nEDzCn0NunKJphZQU5WK/1shoDKv3v20HUzbRhtzhXKpJy7I=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Julien Grall Subject: [PATCH RFCv2 14/15] xen/arm: mm: Rework setup_xenheap_mappings() Date: Sun, 25 Apr 2021 21:13:17 +0100 Message-Id: <20210425201318.15447-15-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> From: Julien Grall A few issues have been reported with setup_xenheap_mappings() over the last couple of years. The main ones are: - It will break on platform supporting more than 512GB of RAM because the memory allocated by the boot allocator is not yet mapped. - Aligning all the regions to 1GB may lead to unexpected result because we may alias non-cacheable region (such as device or reserved regions). map_pages_to_xen() was recently reworked to allow superpage mappings and deal with the use of page-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(). This also require to re-order the steps setup_mm() so the regions are given to the boot allocator first and then we setup the xenheap mappings. Note that the 1GB alignment is not yet removed. Signed-off-by: Julien Grall Signed-off-by: Julien Grall --- Changes in v2: - New patch TODO: - Remove the 1GB alignment - Add support for setting the contiguous bit --- xen/arch/arm/mm.c | 60 ++++---------------------------------------- xen/arch/arm/setup.c | 10 ++++++-- 2 files changed, 13 insertions(+), 57 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index f5768f2d4a81..c49403b687f5 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -143,17 +143,6 @@ static DEFINE_PAGE_TABLE(cpu0_pgtable); static DEFINE_PAGE_TABLES(cpu0_dommap, DOMHEAP_SECOND_PAGES); #endif -#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 = -1; -#endif - /* Common pagetable leaves */ /* Second level page tables. * @@ -818,9 +807,9 @@ 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; + int rc; /* Align to previous 1GB boundary */ mfn = base_mfn & ~((FIRST_SIZE>>PAGE_SHIFT)-1); @@ -846,49 +835,10 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, */ vaddr = (vaddr_t)__mfn_to_virt(base_mfn) & FIRST_MASK; - while ( mfn < end_mfn ) - { - int slot = zeroeth_table_offset(vaddr); - lpae_t *p = &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 = slot == xenheap_first_first_slot ? - xenheap_first_first : mfn_to_virt(lpae_get_mfn(*p)); - } - else if ( xenheap_first_first_slot == -1) - { - /* Use xenheap_first_first to bootstrap the mappings */ - first = xenheap_first_first; - - pte = pte_of_xenaddr((vaddr_t)xenheap_first_first); - pte.pt.table = 1; - write_pte(p, pte); - - xenheap_first_first_slot = slot; - } - else - { - mfn_t first_mfn = alloc_boot_pages(1, 1); - - clear_page(mfn_to_virt(first_mfn)); - pte = mfn_to_xen_entry(first_mfn, MT_NORMAL); - pte.pt.table = 1; - write_pte(p, pte); - first = mfn_to_virt(first_mfn); - } - - pte = mfn_to_xen_entry(_mfn(mfn), MT_NORMAL); - /* TODO: Set pte.pt.contig when appropriate. */ - write_pte(&first[first_table_offset(vaddr)], pte); - - mfn += FIRST_SIZE>>PAGE_SHIFT; - vaddr += FIRST_SIZE; - } - - flush_xen_tlb_local(); + rc = map_pages_to_xen(vaddr, _mfn(mfn), end_mfn - mfn, + PAGE_HYPERVISOR_RW | _PAGE_BLOCK); + if ( rc ) + panic("Unable to setup the xenheap mappings.\n"); } #endif diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 00aad1c194b9..0993a4bb52d4 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -761,8 +761,11 @@ static void __init setup_mm(void) ram_start = min(ram_start,bank_start); ram_end = max(ram_end,bank_end); - setup_xenheap_mappings(bank_start>>PAGE_SHIFT, bank_size>>PAGE_SHIFT); - + /* + * Add the region to the boot allocator first, so we can use + * some to allocate page-tables for setting up the xenheap + * mappings. + */ s = bank_start; while ( s < bank_end ) { @@ -781,6 +784,9 @@ static void __init setup_mm(void) fw_unreserved_regions(s, e, init_boot_pages, 0); s = n; } + + setup_xenheap_mappings(bank_start >> PAGE_SHIFT, + bank_size >> PAGE_SHIFT); } total_pages += ram_size >> PAGE_SHIFT; From patchwork Sun Apr 25 20:13:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12223573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6375AC433B4 for ; Sun, 25 Apr 2021 20:32:31 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B0F6610C8 for ; Sun, 25 Apr 2021 20:32:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B0F6610C8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.117358.223233 (Exim 4.92) (envelope-from ) id 1lalQO-0004S8-08; Sun, 25 Apr 2021 20:32:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 117358.223233; Sun, 25 Apr 2021 20:32:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQN-0004Ry-RZ; Sun, 25 Apr 2021 20:32:15 +0000 Received: by outflank-mailman (input) for mailman id 117358; Sun, 25 Apr 2021 20:32:13 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-0004R4-K9 for xen-devel@lists.xenproject.org; Sun, 25 Apr 2021 20:32:13 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lalQL-00019t-6O; Sun, 25 Apr 2021 20:32:13 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lal8U-0005m7-5k; Sun, 25 Apr 2021 20:13:46 +0000 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=PFAiZzvNdX0XtM/ZLCXS9tRAO1+3c66q0ERBXXoUxuU=; b=18GiCLTtl3bnQ66urZwClAPR7 yLQ1IBqgCGqcFBm7zM/2dUEJM6KCFcBJxZ5R+qhBaRdb2XfUMOyVd/cIof87Zs21TbEYVmZloReOc q7H2sLamLiNK7pd4N/BIdavxN+YJKF4rOTO+A7foq6rQcSlD9vCTv3ysK1+YTVYdpQ/kA=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Wei.Chen@arm.com, Henry.Wang@arm.com, Penny.Zheng@arm.com, Bertrand.Marquis@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Julien Grall Subject: [PATCH RFCv2 15/15] xen/arm: mm: Re-implement setup_frame_table_mappings() with map_pages_to_xen() Date: Sun, 25 Apr 2021 21:13:18 +0100 Message-Id: <20210425201318.15447-16-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210425201318.15447-1-julien@xen.org> References: <20210425201318.15447-1-julien@xen.org> 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 different 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 --- Changes in v2: - New patch TODO: - Add support for setting the contiguous bit --- xen/arch/arm/mm.c | 64 +++++------------------------------------------ 1 file changed, 6 insertions(+), 58 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index c49403b687f5..5f8ae029dd6d 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -359,40 +359,6 @@ void clear_fixmap(unsigned map) BUG_ON(res != 0); } -/* 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 = mapping_size >> PAGE_SHIFT; - lpae_t pte, *p; - - ASSERT((mapping_size == MB(2)) || (mapping_size == MB(32))); - ASSERT(!((virt_offset >> PAGE_SHIFT) % granularity)); - ASSERT(!(base_mfn % granularity)); - ASSERT(!(nr_mfns % granularity)); - - count = nr_mfns / LPAE_ENTRIES; - p = second + second_linear_offset(virt_offset); - pte = mfn_to_xen_entry(_mfn(base_mfn), MT_NORMAL); - if ( granularity == 16 * LPAE_ENTRIES ) - pte.pt.contig = 1; /* These maps are in 16-entry contiguous chunks. */ - for ( i = 0; i < count; i++ ) - { - write_pte(p + i, pte); - pte.pt.base += 1 << LPAE_SHIFT; - } - flush_xen_tlb_local(); -} - #ifdef CONFIG_DOMAIN_PAGE void *map_domain_page_global(mfn_t mfn) { @@ -850,36 +816,18 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) unsigned long frametable_size = nr_pdxs * sizeof(struct page_info); mfn_t base_mfn; const unsigned long mapping_size = 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; frametable_base_pdx = mfn_to_pdx(maddr_to_mfn(ps)); /* Round up to 2M or 32M boundary, as appropriate. */ frametable_size = ROUNDUP(frametable_size, mapping_size); base_mfn = alloc_boot_pages(frametable_size >> PAGE_SHIFT, 32<<(20-12)); -#ifdef CONFIG_ARM_64 - /* Compute the number of second level pages. */ - nr_second = ROUNDUP(frametable_size, FIRST_SIZE) >> FIRST_SHIFT; - second_base = alloc_boot_pages(nr_second, 1); - second = mfn_to_virt(second_base); - for ( i = 0; i < nr_second; i++ ) - { - clear_page(mfn_to_virt(mfn_add(second_base, i))); - pte = mfn_to_xen_entry(mfn_add(second_base, i), MT_NORMAL); - pte.pt.table = 1; - write_pte(&xen_first[first_table_offset(FRAMETABLE_VIRT_START)+i], pte); - } - create_mappings(second, 0, mfn_x(base_mfn), frametable_size >> PAGE_SHIFT, - mapping_size); -#else - create_mappings(xen_second, FRAMETABLE_VIRT_START, mfn_x(base_mfn), - frametable_size >> PAGE_SHIFT, mapping_size); -#endif + /* XXX: Handle contiguous bit */ + rc = map_pages_to_xen(FRAMETABLE_VIRT_START, base_mfn, + frametable_size >> PAGE_SHIFT, PAGE_HYPERVISOR_RW); + if ( rc ) + panic("Unable to setup the frametable mappings.\n"); memset(&frame_table[0], 0, nr_pdxs * sizeof(struct page_info)); memset(&frame_table[nr_pdxs], -1,