From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619381628; cv=none; d=zohomail.com; s=zohoarc; b=HhrcNKcf7iAQlcKYo9zbNbpO4jROWB262PbRx40LW2nzkWje4v8JPd5HDAUizQOMzaSWu+JzFN3OTLC/BHfTWf3UgdNc57Q+Qp/B7uNdBnL94svj3YBNnyGVJF+9w8f6w/XzBDON6r7Kenm7lUPauGTVZThBRIej+2QzjFMnbzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619381628; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=aeGTdR45KQ3asOXLFfCMyppOP+nTbqurYRYNJDh+L6k=; b=hSxtetOthaP1TYUK6ezc4np41cnD75Wo39/iNo4G/2XqmPBcE8lYnOpy4sNBIEPQ+6C5kGjC3FIzy1OUOMqDplBBCnI6nqs1hQC93fKQOqHA1sSmw3+w5mxqH/7HsMdCzbQy4Gp9OoHDfpR3DHvwI6ANLNutHjmTUQaVv4LkXTc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619381628773827.4718894933907; Sun, 25 Apr 2021 13:13:48 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall Commit 05031fa87357 "xen/arm: guest_walk: Only generate necessary offsets/masks" introduced LPAE_ENTRIES_MASK_GS. In a follow-up patch, we will use it for to define LPAE_ENTRY_MASK. This will lead to inconsistent naming. As LPAE_ENTRY_MASK is used in many places, it is better to rename LPAE_ENTRIES_MASK_GS and avoid some churn. So rename LPAE_ENTRIES_MASK_GS to LPAE_ENTRY_MASK_GS. Signed-off-by: Julien Grall 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, unsign= ed int level) */ #define LPAE_SHIFT_GS(gs) ((gs) - 3) #define LPAE_ENTRIES_GS(gs) (_AC(1, U) << LPAE_SHIFT_GS(gs)) -#define LPAE_ENTRIES_MASK_GS(gs) (LPAE_ENTRIES_GS(gs) - 1) +#define LPAE_ENTRY_MASK_GS(gs) (LPAE_ENTRIES_GS(gs) - 1) =20 #define LEVEL_ORDER_GS(gs, lvl) ((3 - (lvl)) * LPAE_SHIFT_GS(gs)) #define LEVEL_SHIFT_GS(gs, lvl) (LEVEL_ORDER_GS(gs, lvl) + (gs)) @@ -188,7 +188,7 @@ static inline bool lpae_is_superpage(lpae_t pte, unsign= ed int level) =20 /* Offset in the table at level 'lvl' */ #define LPAE_TABLE_INDEX_GS(gs, lvl, addr) \ - (((addr) >> LEVEL_SHIFT_GS(gs, lvl)) & LPAE_ENTRIES_MASK_GS(gs)) + (((addr) >> LEVEL_SHIFT_GS(gs, lvl)) & LPAE_ENTRY_MASK_GS(gs)) =20 /* Generate an array @var containing the offset for each level from @addr = */ #define DECLARE_OFFSETS(var, addr) \ --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619381628; cv=none; d=zohomail.com; s=zohoarc; b=H9ojzjEKPia28pO1yfClzCSWgbn10ljhOLu8Nd7cKWltVaI1AOHHogzEhhZt5mflRCcZFuA9JeH9eLXZ6SoQiroKGWwHAW3u1QyKn88s+LXq3uAdjDv60s4AZIS/dWTcEWGysjNGJSrU2L2MAd4xAuiuabhbslOml69hsFJ1xe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619381628; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=LKWf7A+MF6uxi0Yzj4E+EHypbxoopwZaOMfIEc68W2U=; b=fgbTKxjCXeWimvNFrbYd3Xti1UBgbccsm/0HS5bkJwsBjz8q+xFA39pU+11p2PO2MLCG51tqlcMbkNwkj/N2XLCz+QCrNPOvBJag3vzY0qI0Ir+bYpUfLBSHqbkGijkx35RWUjo3+S5NVwv9sjJKXNT/0D8ZgpvGIGx6RlMfAic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619381628109588.5313211752217; Sun, 25 Apr 2021 13:13:48 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall Currently, Xen PT helpers are only working with 4KB page granularity and open-code the generic helpers. To allow more flexibility, we can re-use the generic helpers and pass Xen's page granularity (PAGE_SHIFT). As Xen PT helpers are used in both C and assembly, we need to move the generic helpers definition outside of the !__ASSEMBLY__ section. 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, unsig= ned int level) #define lpae_get_mfn(pte) (_mfn((pte).walk.base)) #define lpae_set_mfn(pte, mfn) ((pte).walk.base =3D mfn_x(mfn)) =20 +/* Generate an array @var containing the offset for each level from @addr = */ +#define DECLARE_OFFSETS(var, addr) \ + const unsigned int var[4] =3D { \ + zeroeth_table_offset(addr), \ + first_table_offset(addr), \ + second_table_offset(addr), \ + third_table_offset(addr) \ + } + +#endif /* __ASSEMBLY__ */ + /* * AArch64 supports pages with different sizes (4K, 16K, and 64K). * Provide a set of generic helpers that will compute various @@ -190,17 +201,6 @@ static inline bool lpae_is_superpage(lpae_t pte, unsig= ned int level) #define LPAE_TABLE_INDEX_GS(gs, lvl, addr) \ (((addr) >> LEVEL_SHIFT_GS(gs, lvl)) & LPAE_ENTRY_MASK_GS(gs)) =20 -/* Generate an array @var containing the offset for each level from @addr = */ -#define DECLARE_OFFSETS(var, addr) \ - const unsigned int var[4] =3D { \ - zeroeth_table_offset(addr), \ - first_table_offset(addr), \ - second_table_offset(addr), \ - third_table_offset(addr) \ - } - -#endif /* __ASSEMBLY__ */ - /* * These numbers add up to a 48-bit input address space. * @@ -211,26 +211,35 @@ static inline bool lpae_is_superpage(lpae_t pte, unsi= gned int level) * therefore 39-bits are sufficient. */ =20 -#define LPAE_SHIFT 9 -#define LPAE_ENTRIES (_AC(1,U) << LPAE_SHIFT) -#define LPAE_ENTRY_MASK (LPAE_ENTRIES - 1) - -#define THIRD_SHIFT (PAGE_SHIFT) -#define THIRD_ORDER (THIRD_SHIFT - PAGE_SHIFT) -#define THIRD_SIZE (_AT(paddr_t, 1) << THIRD_SHIFT) -#define THIRD_MASK (~(THIRD_SIZE - 1)) -#define SECOND_SHIFT (THIRD_SHIFT + LPAE_SHIFT) -#define SECOND_ORDER (SECOND_SHIFT - PAGE_SHIFT) -#define SECOND_SIZE (_AT(paddr_t, 1) << SECOND_SHIFT) -#define SECOND_MASK (~(SECOND_SIZE - 1)) -#define FIRST_SHIFT (SECOND_SHIFT + LPAE_SHIFT) -#define FIRST_ORDER (FIRST_SHIFT - PAGE_SHIFT) -#define FIRST_SIZE (_AT(paddr_t, 1) << FIRST_SHIFT) -#define FIRST_MASK (~(FIRST_SIZE - 1)) -#define ZEROETH_SHIFT (FIRST_SHIFT + LPAE_SHIFT) -#define ZEROETH_ORDER (ZEROETH_SHIFT - PAGE_SHIFT) -#define ZEROETH_SIZE (_AT(paddr_t, 1) << ZEROETH_SHIFT) -#define ZEROETH_MASK (~(ZEROETH_SIZE - 1)) +#define 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) =20 /* Calculate the offsets into the pagetables for a given VA */ #define zeroeth_linear_offset(va) ((va) >> ZEROETH_SHIFT) --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619381628; cv=none; d=zohomail.com; s=zohoarc; b=CopdSx2Bd9u0IOCDdjrk+Oin72A3iltrvOoZ5t2nkyRmYOOXQ9oYHssh3EBBGVm5ngxZXQ4sjavypn3dvuZIuRBP++meH5unjH+EuSW2MImSJoeIkBWJuoXClnTnMs1j015WV17GhRxMQUz3n4eI9u+DGVW2lrLlOyovCMvVnJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619381628; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=jWWczyhwx5+vonIhKTnyI8FTuC3mdInSZ1tXL3+0cBg=; b=cbaL3NXhoLXi/VI02oiUvuJXvmDZt5BM9t+Y5U0l8qwgF5vUPkF/qSLcsZcfEvWKpvcg8w4YKzaPH4cFkYK/wWuFjihD/o57u8XQWH6NGimXkJI2koSvt9ZSlgCsULzG/3CA6GBW58JMgW00mfV27WPvHMx5kyD9bbMGxeHADrE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619381628786705.8596795099302; Sun, 25 Apr 2021 13:13:48 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall The array level_orders and level_masks can be replaced with the recently introduced macros LEVEL_ORDER and LEVEL_MASK. Signed-off-by: Julien Grall 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 =3D MAX_VMID_= 8_BIT; */ unsigned int __read_mostly p2m_ipa_bits =3D 64; =20 -/* Helpers to lookup the properties of each level */ -static const paddr_t level_masks[] =3D - { ZEROETH_MASK, FIRST_MASK, SECOND_MASK, THIRD_MASK }; -static const uint8_t level_orders[] =3D - { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER }; - static mfn_t __read_mostly empty_root_mfn; =20 static uint64_t generate_vttbr(uint16_t vmid, mfn_t root_mfn) @@ -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 =3D gfn_x(gfn) >> (level_orders[P2M_ROOT_LEVEL] + LPAE_SHIF= T); + root_table =3D gfn_x(gfn) >> (LEVEL_ORDER(P2M_ROOT_LEVEL) + LPAE_SHIFT= ); if ( root_table >=3D P2M_ROOT_PAGES ) return NULL; =20 @@ -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 =3D 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; =20 @@ -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 =3D mfn_add(mfn, gfn_x(gfn) & ((1UL << level_orders[level]) - = 1)); + mfn =3D mfn_add(mfn, gfn_x(gfn) & ((1UL << LEVEL_ORDER(level)) - 1= )); =20 if ( valid ) *valid =3D lpae_is_valid(entry); @@ -432,7 +426,7 @@ out_unmap: =20 out: if ( page_order ) - *page_order =3D level_orders[level]; + *page_order =3D LEVEL_ORDER(level); =20 return mfn; } @@ -806,7 +800,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m,= lpae_t *entry, /* Convenience aliases */ mfn_t mfn =3D lpae_get_mfn(*entry); unsigned int next_level =3D level + 1; - unsigned int level_order =3D level_orders[next_level]; + unsigned int level_order =3D LEVEL_ORDER(next_level); =20 /* * This should only be called with target !=3D level and the entry is --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619381628; cv=none; d=zohomail.com; s=zohoarc; b=SHOq4WiD58yZZW/Zz0KXY8q3y6tvyIGij/EHh60oyG9rsLzNH+Ux53Sx9X/LZiE7jJWNtFRm7bmCNth1lPeNyfZvBpkxcsKAZrFQULJXMqadGXod1sTjL6zXqJ1lO8ZYoT8djBzciNkgCcJzzzlVP8vKfRZkX5BWs1ip5xQYN0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619381628; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=lBfQueqmN8lGEfYvmwCQNPeVCuWNGXAaHJKI8fcyO7c=; b=fi8r0U7lcbB9pFRmrHH25lDnm48FL3sgirFy0+NzGPQZElLhy03X6gqGFCEy2MvpQNsiqEsre4dCfRnQ3FMOzXEESMW3p48WqCFsogYzDt2BAu90DXNzdZpTlHEJcDInudCVDL1wC2X2YUrH+bGgt0pkQ47VIRQiZGRoj0HbcrM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619381628744407.5396436067359; Sun, 25 Apr 2021 13:13:48 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment, xen_pt_update_entry() only supports mapping at level 3 (i.e 4KB mapping). While this is fine for most of the runtime helper, the boot code will require to use superpage mapping. We don't want to allow superpage mapping by default as some of the callers may expect small mappings (i.e populate_pt_range()) or even expect to unmap only a part of a superpage. To keep the code simple, a new flag _PAGE_BLOCK is introduced to allow the caller to enable superpage mapping. As the code doesn't support all the combinations, xen_pt_check_entry() is extended to take into account the cases we don't support when using block mapping: - Replacing a table with a mapping. This may happen if region was first mapped with 4KB mapping and then later on replaced with a 2MB (or 1GB mapping) - Removing/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, unsigne= d int level, } =20 /* Sanity check of the entry */ -static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) +static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int level, + unsigned int flags) { - /* Sanity check when modifying a page. */ + /* Sanity check when modifying an entry. */ if ( (flags & _PAGE_PRESENT) && mfn_eq(mfn, INVALID_MFN) ) { /* We don't allow modifying an invalid entry. */ @@ -1072,6 +1073,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t m= fn, unsigned int flags) return false; } =20 + /* We don't allow modifying a table entry */ + if ( !lpae_is_mapping(entry, level) ) + { + mm_printk("Modifying a table entry is not allowed.\n"); + return false; + } + /* We don't allow changing memory attributes. */ if ( entry.pt.ai !=3D PAGE_AI_MASK(flags) ) { @@ -1087,7 +1095,7 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mf= n, unsigned int flags) return false; } } - /* Sanity check when inserting a page */ + /* Sanity check when inserting a mapping */ else if ( flags & _PAGE_PRESENT ) { /* We should be here with a valid MFN. */ @@ -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 (%#"P= RI_mfn" -> %#"PRI_mfn").\n", - mfn_x(lpae_get_mfn(entry)), mfn_x(mfn)); + if ( lpae_is_mapping(entry, level) ) + mm_printk("Changing MFN for a valid entry is not allowed (= %#"PRI_mfn" -> %#"PRI_mfn").\n", + mfn_x(lpae_get_mfn(entry)), mfn_x(mfn)); + else + mm_printk("Trying to replace a table with a mapping.\n"); return false; } } - /* Sanity check when removing a page. */ + /* Sanity check when removing a mapping. */ else if ( (flags & (_PAGE_PRESENT|_PAGE_POPULATE)) =3D=3D 0 ) { /* We should be here with an invalid MFN. */ ASSERT(mfn_eq(mfn, INVALID_MFN)); =20 - /* We don't allow removing page with contiguous bit set. */ + /* We don't allow removing a table */ + if ( lpae_is_table(entry, level) ) + { + mm_printk("Removing a table is not allowed.\n"); + return false; + } + + /* We don't allow removing a mapping with contiguous bit set. */ if ( entry.pt.contig ) { mm_printk("Removing entry with contiguous bit set is not allow= ed.\n"); @@ -1125,13 +1143,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t = mfn, unsigned int flags) return true; } =20 +/* Update an entry at the level @target. */ static int xen_pt_update_entry(mfn_t root, unsigned long virt, - mfn_t mfn, unsigned int flags) + mfn_t mfn, unsigned int target, + unsigned int flags) { int rc; unsigned int level; - /* We only support 4KB mapping (i.e level 3) for now */ - unsigned int target =3D 3; lpae_t *table; /* * The intermediate page tables are read-only when the MFN is not valid @@ -1186,7 +1204,7 @@ static int xen_pt_update_entry(mfn_t root, unsigned l= ong virt, entry =3D table + offsets[level]; =20 rc =3D -EINVAL; - if ( !xen_pt_check_entry(*entry, mfn, flags) ) + if ( !xen_pt_check_entry(*entry, mfn, level, flags) ) goto out; =20 /* If we are only populating page-table, then we are done. */ @@ -1204,8 +1222,11 @@ static int xen_pt_update_entry(mfn_t root, unsigned = long virt, { pte =3D mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); =20 - /* Third level entries set pte.pt.table =3D 1 */ - pte.pt.table =3D 1; + /* + * First and second level pages set pte.pt.table =3D 0, but + * third level entries set pte.pt.table =3D 1. + */ + pte.pt.table =3D (level =3D=3D 3); } else /* We are updating the permission =3D> Copy the current pte. = */ pte =3D *entry; @@ -1229,11 +1250,12 @@ static DEFINE_SPINLOCK(xen_pt_lock); =20 static int xen_pt_update(unsigned long virt, mfn_t mfn, - unsigned long nr_mfns, + const unsigned long nr_mfns, unsigned int flags) { int rc =3D 0; - unsigned long addr =3D virt, addr_end =3D addr + nr_mfns * PAGE_SIZE; + unsigned long vfn =3D virt >> PAGE_SHIFT; + unsigned long left =3D nr_mfns; =20 /* * For arm32, page-tables are different on each CPUs. Yet, they share @@ -1265,14 +1287,49 @@ static int xen_pt_update(unsigned long virt, =20 spin_lock(&xen_pt_lock); =20 - for ( ; addr < addr_end; addr +=3D PAGE_SIZE ) + while ( left ) { - rc =3D xen_pt_update_entry(root, addr, mfn, flags); + unsigned int order, level; + 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 =3D !mfn_eq(mfn, INVALID_MFN) ? mfn_x(mfn) : 0; + mask |=3D vfn | left; + + /* + * Always use level 3 mapping unless the caller request block + * mapping. + */ + if ( likely(!(flags & _PAGE_BLOCK)) ) + level =3D 3; + else if ( !(mask & (BIT(FIRST_ORDER, UL) - 1)) ) + level =3D 1; + else if ( !(mask & (BIT(SECOND_ORDER, UL) - 1)) ) + level =3D 2; + else + level =3D 3; + + order =3D LEVEL_ORDER(level); + + rc =3D xen_pt_update_entry(root, pfn_to_paddr(vfn), mfn, level, fl= ags); if ( rc ) break; =20 + vfn +=3D 1U << order; if ( !mfn_eq(mfn, INVALID_MFN) ) - mfn =3D mfn_add(mfn, 1); + mfn =3D mfn_add(mfn, 1U << order); + + left -=3D (1U << order); } =20 /* 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) =20 @@ -82,6 +83,9 @@ #define _PAGE_PRESENT (1U << 5) #define _PAGE_POPULATE (1U << 6) =20 +#define _PAGE_BLOCK_BIT 7 +#define _PAGE_BLOCK (1U << _PAGE_BLOCK_BIT) + /* * _PAGE_DEVICE and _PAGE_NORMAL are convenience defines. They are not * meant to be used outside of this header. --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619381628; cv=none; d=zohomail.com; s=zohoarc; b=UKHtl4+hkkgwHB13yG0AoxmSyk2vKm7hTYi9vwI9OXhdOVpK5ShWJwUHKnFuU4ETrGiAGJV5k2b1e+EGujchJLl0qAvXWjLSQw70cDOqUUwFnJS3F0dLrdNojtfkWNyKfrfIPnshFq2nlIdCTJNJERr5pt8A60zqXvqqNqDwrks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619381628; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=qdn1le94TFR9RGBuVbMK3tl4UOk0qVZcjP09VJjmTGA=; b=ISy95jE6g6Is9iyBMa5IZuFRv6RaOPsJV7xClA3w01r7Bk2wlILEG+YREZi7DWd/3K/3QRuXovI1iZ9W3ApB2zRsWaHMSNZp1XyUVYyN3xBgteCcXpGEqCNTNx8ownk0AWllK9YJXR44BFZhtYuyl17+tpMBDFUrsMpaN/uWUX8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619381628490733.8305719913482; Sun, 25 Apr 2021 13:13:48 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall Currently, the function xen_pt_update() will flush the TLBs even when the mappings are inserted. This is a bit wasteful because we don't allow mapping replacement. Even if we were, the flush would need to happen earlier because mapping replacement should use Break-Before-Make when updating the entry. A single call to xen_pt_update() can perform a single action. IOW, it is not possible to, for instance, mix inserting and removing mappings. Therefore, we can use `flags` to determine what action is performed. This change will be particularly help to limit the impact of switching boot time mapping to use xen_pt_update(). Signed-off-by: Julien Grall 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 m= fn, unsigned int level, /* We should be here with a valid MFN. */ ASSERT(!mfn_eq(mfn, INVALID_MFN)); =20 - /* We don't allow replacing any valid entry. */ + /* + * We don't allow replacing any valid entry. + * + * Note that the function xen_pt_update() relies on this + * assumption and will skip the TLB flush. The function will need + * to be updated if the check is relaxed. + */ if ( lpae_is_valid(entry) ) { if ( lpae_is_mapping(entry, level) ) @@ -1333,11 +1339,16 @@ static int xen_pt_update(unsigned long virt, } =20 /* - * Flush the TLBs even in case of failure because we may have + * The TLBs flush can be safely skipped when a mapping is inserted + * as we don't allow mapping replacement (see xen_pt_check_entry()). + * + * For all the other cases, the TLBs will be flushed unconditionally + * even if the mapping 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); =20 spin_unlock(&xen_pt_lock); =20 --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619381629; cv=none; d=zohomail.com; s=zohoarc; b=j/SHQ7VPocAghL+XmvvkDPTTCiyAc5wwXCjlYA55NQNBrN5Oh/o3oKfJ/NKhoSFrOWGZmAkCZpUwbWXDkM8ZITSWAYF2aCEkk8/wsKGMNNxv8fGzAUsoTGxeTYnlks5UaUoZcof/dRLs0JHPhgk0IrYdT/YF/I6kMS9YYABBkVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619381629; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=siVUWwfApP96aB3lihKwJZ2TVvy/coY05i6ribyQkaQ=; b=AofR8VcWDWGCPzBAXMz2KiP16HGezw0zEu1eefV9N8MX0eu7mvk5tpYSerjWuBv+98eiZp2q7P9007Hak/vXb4lynM6JcOGIv4prbujW3O8bT1x94babFQH537w4Tg/pBh+XzUoW5jMnKOTRAOwJ2+PKTzvDTDtzOYZCQFQTMzI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161938162998331.32617664809709; Sun, 25 Apr 2021 13:13:49 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that xen_pt_update_entry() is able to deal with different mapping size, we can replace the open-coding of the page-tables update by a call to modify_xen_mappings(). As the function is not meant to fail, a BUG_ON() is added to check the return. Signed-off-by: Julien Grall Signed-off-by: Julien Grall 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) =20 void __init remove_early_mappings(void) { - lpae_t pte =3D {0}; - write_pte(xen_second + second_table_offset(BOOT_FDT_VIRT_START), pte); - write_pte(xen_second + second_table_offset(BOOT_FDT_VIRT_START + SZ_2M= ), - pte); - flush_xen_tlb_range_va(BOOT_FDT_VIRT_START, BOOT_FDT_SLOT_SIZE); + int rc; + + rc =3D modify_xen_mappings(BOOT_FDT_VIRT_START, BOOT_FDT_VIRT_END, + _PAGE_BLOCK); + BUG_ON(rc); } =20 /* --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619381629; cv=none; d=zohomail.com; s=zohoarc; b=WoX0NEEOaWggzvK3hp/iRMF/O6pdUAQybvWw8jYv8c/Wqa67c5UqDdZq1gqidv9m+DqhBIDGS0sm0kY5eKGSHkSZwJLC5AgZsMp4zAiW/ZkCbkp7+e03Cf47ilgxiapOGvRRj/erOXCuFoUErUrw1fNX8vbQKdVcRdVuvOZNlSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619381629; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=BjS7PbV9YIvothNxojvfyxpwJGXVh+HIjQYc5MW8oEY=; b=KNKlMhepFhbattgkqCgAT/c4IB6ZChLfSdtMSfXweo6gprCRgyZJPoUu1fa/jYe+qyBVdE6tEoDKdX84h/F4WfWA8786CixJLDtJDaY4K8NmcuoFs7FS7k6lRIaK0DY0F35ImCSIOVODsVaj3UBJwD2TFvN901jDB6VeRmNz5sc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161938162966013.076126511063649; Sun, 25 Apr 2021 13:13:49 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that map_pages_to_xen() has been extended to support 2MB mappings, we can replace the create_mappings() calls by map_pages_to_xen() calls. The mapping can also be marked read-only has Xen as no business to modify the host Device Tree. Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: 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; =20 /* * 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); =20 - create_mappings(xen_second, BOOT_FDT_VIRT_START, paddr_to_pfn(base_pad= dr), - SZ_2M >> PAGE_SHIFT, SZ_2M); + rc =3D map_pages_to_xen(BOOT_FDT_VIRT_START, maddr_to_mfn(base_paddr), + SZ_2M >> PAGE_SHIFT, + PAGE_HYPERVISOR_RO | _PAGE_BLOCK); + if ( rc ) + panic("Unable to map the device-tree.\n"); + =20 offset =3D fdt_paddr % SECOND_SIZE; fdt_virt =3D (void *)BOOT_FDT_VIRT_START + offset; @@ -588,9 +593,12 @@ void * __init early_fdt_map(paddr_t fdt_paddr) =20 if ( (offset + size) > SZ_2M ) { - create_mappings(xen_second, BOOT_FDT_VIRT_START + SZ_2M, - paddr_to_pfn(base_paddr + SZ_2M), - SZ_2M >> PAGE_SHIFT, SZ_2M); + rc =3D map_pages_to_xen(BOOT_FDT_VIRT_START + SZ_2M, + maddr_to_mfn(base_paddr + SZ_2M), + SZ_2M >> PAGE_SHIFT, + PAGE_HYPERVISOR_RO | _PAGE_BLOCK); + if ( rc ) + panic("Unable to map the device-tree\n"); } =20 return fdt_virt; --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619381629; cv=none; d=zohomail.com; s=zohoarc; b=XQ7ahstp27UUtfOp1uVZnD8DLw/5OccENCSwizJTO2YEkFeGrxRnUka60AOlXbnUPcEP71igtcNBzg4IApjJ3c3S+57+BpOiIRVLpnD0d4S4miHI0CUGQ6U80TG/9GzA5DMlCbl44aRwl9d7CjaxCj4Vkl4A8+13c5QKdntpY+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619381629; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=NkFXrdGqH4EPmzou9mWkeqYkQCSaITClqSn4Be5r/zI=; b=eIJP8pjKXnVFoesdK7qow8nfbF3SiAO57hLOdBxOcBlvKY+lAjP8cgcyWb4kWhzPfFBKcGNHyNCW8u0PPP/7p/0m53s151kibS4E+tiqSCa4RLNJu+rWaIWs0prKBzGX0h6/5zyN+NRterur1Deuz5MqVS8Ue/WAglblgZxP0p4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619381629797193.5750536293708; Sun, 25 Apr 2021 13:13:49 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall Only the first 2GB of the virtual address space is shared between all the page-tables on Arm32. There is a long outstanding TODO in xen_pt_update() stating that the function 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 =3D virt_to_mfn(THIS_CPU_PGTABLE); =20 +#ifdef SHARED_VIRT_END + if ( virt > SHARED_VIRT_END || + (SHARED_VIRT_END - virt) < nr_mfns ) + { + mm_printk("Trying to map outside of the shared area.\n"); + return -EINVAL; + } +#endif + /* * The hardware was configured to forbid mapping both writeable and * executable. 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 @@ =20 #define XENHEAP_VIRT_START _AT(vaddr_t,0x40000000) #define XENHEAP_VIRT_END _AT(vaddr_t,0x7fffffff) + +/* The first 2GB is always shared between all the page-tables. */ +#define SHARED_VIRT_END _AT(vaddr_t, 0x7fffffff) + #define DOMHEAP_VIRT_START _AT(vaddr_t,0x80000000) #define DOMHEAP_VIRT_END _AT(vaddr_t,0xffffffff) =20 --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619381636; cv=none; d=zohomail.com; s=zohoarc; b=Qpua048bKvkeT4sjsbWTNO2TLWBfg8QyIeq87z6GPuTR1G2WANMvRUkRK3jFnC7TALhYX1vXnh9KCUtTQZZELjTkETMp+uhOTccuG+bUK3Lk6AeRzvEixmpWl2EI8kNgqt1PBY/O9s7SNoyQ8busmFitjXUoSInuOBFaekHMOf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619381636; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Moqxyc1ZPjrdBFjtAzt9LgU5Lw+fiLu9r1elfDAEKcE=; b=kG2nbMMVHkboIoUyVLoWOBWmBPaVBO2rhg4EpRMz+QTBHYDk6fSsU8P9zd09ryX3/bS4/g2d94pJsj0Wb9fyKg+519h8+dRxDcbQpLOjmysfzVsxYxaXZw4aQpqrXLfueeO2TZ8pQZcWdryil2prC9nwpIgJHfK2yY5jXcZB5zM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619381636362867.1184823742097; Sun, 25 Apr 2021 13:13:56 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that map_pages_to_xen() has been extended to support 2MB mappings, we can replace the create_mappings() call by map_pages_to_xen() call. Signed-off-by: Julien Grall --- 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 =3D 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"); =20 /* Record where the xenheap is, for translation routines. */ xenheap_virt_end =3D XENHEAP_VIRT_START + nr_mfns * PAGE_SIZE; --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619382759; cv=none; d=zohomail.com; s=zohoarc; b=WUFzigp4k/0l0hpXV5zYQlkF30oKCw+VBhOn91WCtyH5qhY7RuiruQWE/3KmTlHUqYrJG5joYYBY6V06U7rLjhHVdyqKglGYphZXWKgS9flGdvoY7dUpt6KCXAfbFcr27JwPCAS99NJqxZQdqpgqt5Ja1BB8tuEsTA7CVzzVqHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619382759; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=MTKf2MkfWHAQW1rNB3O16F5z9jItgd6Wm5yHl60rcz0=; b=L9lNaSvhs4V+o3m4Up8BaFzfgsnKiQG/kKhSMC9jmuHaW/lfVWOvQl3jrFXDFcFLKZB4caw+vGRZuFBPOlZ3G08RT1z3HxPDtkVatR6LWnuZZRYT4aDRBtZh3MtTJ/KNQSfAXJY7Romo1ASCatvAkNMZtvkys9p9yOezRRhmMP4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619382759439247.90530059536104; Sun, 25 Apr 2021 13:32:39 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall xen_{un,}map_table() already uses the helper to map/unmap pages on-demand (note this is currently a NOP on arm64). So switching to domheap don't have any disavantage. But this as the benefit: - to keep the page tables unmapped if an arch decided to do so - reduce xenheap use on arm32 which can be pretty small Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in 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); } =20 -static int create_xen_table(lpae_t *entry) -{ - void *p; - lpae_t pte; - - p =3D alloc_xenheap_page(); - if ( p =3D=3D NULL ) - return -ENOMEM; - clear_page(p); - pte =3D mfn_to_xen_entry(virt_to_mfn(p), MT_NORMAL); - pte.pt.table =3D 1; - write_pte(entry, pte); - return 0; -} - static lpae_t *xen_map_table(mfn_t mfn) { /* @@ -1024,6 +1009,27 @@ static void xen_unmap_table(const lpae_t *table) unmap_domain_page(table); } =20 +static int create_xen_table(lpae_t *entry) +{ + struct page_info *pg; + void *p; + lpae_t pte; + + pg =3D alloc_domheap_page(NULL, 0); + if ( pg =3D=3D NULL ) + return -ENOMEM; + + p =3D xen_map_table(page_to_mfn(pg)); + clear_page(p); + xen_unmap_table(p); + + pte =3D mfn_to_xen_entry(page_to_mfn(pg), MT_NORMAL); + pte.pt.table =3D 1; + write_pte(entry, pte); + + return 0; +} + #define XEN_TABLE_MAP_FAILED 0 #define XEN_TABLE_SUPER_PAGE 1 #define XEN_TABLE_NORMAL_PAGE 2 --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619382754; cv=none; d=zohomail.com; s=zohoarc; b=WON2PO/NKSRIC1I/0OySrdI4FiHllBhp5t/3KytY8kcxIpMEgRrKaZffFDPzATE47TXh925YG6Jvn2CGlX0Ru915BCKqTR44vAXTGJoHimUcTQA9lP9SjlryixM8dxEYW1JgLF4spZPbfxOjBiZX3OKc2kOJ50imYT/KgVotf5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619382754; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=kyXJNvfLj/1Qpk3hX2ctxX4bb1KB1kLqdFkNoEVhegI=; b=cH6KVRiuRhCxYyv4x5NF6HnR5+aCToRywGjbRVaiVWoCLwaUo+1RmNR1EpRUUsNEn7tWEtesIRdQ1LdSAAdYI4PZKdk139Zp9pESY6a0hrw4jFGEN4xlzGgDZ5MMaIulYBVLmcEgBUNfKhAXCCZ5ZU5CH/0Em2QNjoIok7eIbOk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619382754397736.3195089426832; Sun, 25 Apr 2021 13:32:34 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment, page-table can only be allocated from domheap. This means it is not possible to create mapping in the page-tables via map_pages_to_xen() if page-table needs to be allocated. In order to avoid open-coding page-tables update in early boot, we need to be able to allocate page-tables much earlier. Thankfully, we have the boot allocator for those cases. create_xen_table() is updated to cater early boot allocation by using alloc_boot_pages(). Note, this is not sufficient to bootstrap the page-tables (i.e mapping before any memory is actually mapped). This will be addressed separately. Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - New patch --- xen/arch/arm/mm.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 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) =20 static int create_xen_table(lpae_t *entry) { - struct page_info *pg; + mfn_t mfn; void *p; lpae_t pte; =20 - pg =3D alloc_domheap_page(NULL, 0); - if ( pg =3D=3D NULL ) - return -ENOMEM; + if ( system_state !=3D SYS_STATE_early_boot ) + { + struct page_info *pg =3D alloc_domheap_page(NULL, 0); + + if ( pg =3D=3D NULL ) + return -ENOMEM; + + mfn =3D page_to_mfn(pg); + } + else + mfn =3D alloc_boot_pages(1, 1); =20 - p =3D xen_map_table(page_to_mfn(pg)); + p =3D xen_map_table(mfn); clear_page(p); xen_unmap_table(p); =20 - pte =3D mfn_to_xen_entry(page_to_mfn(pg), MT_NORMAL); + pte =3D mfn_to_xen_entry(mfn, MT_NORMAL); pte.pt.table =3D 1; write_pte(entry, pte); =20 --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619382754; cv=none; d=zohomail.com; s=zohoarc; b=Es7sdjgJyA5+ciIV2h+ukmFgJMXaBm4Mr+FvmkFeRXY/riXqELLefAulShr4l0e/TwIfNV9e4UvcX30EePCYkb6QhUCimedWZZwjv3ZoH9DRkHUoWDs28DAUPbcgQzI+/Ivb3ZuGQjRnLX4g5J1z5dpZBOYk76k8f34wYG/iOv8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619382754; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=d6/VERpOpmisc9IqH4nSo3nCT42W307X8jAJ7pAR9wY=; b=KURyKEcB5laDPVo5LMY7GzkDRcdNBsZDEzd+ljb/zlyOKFuXyZ5XsqAlAcuqka0h8I75B0rSxcW6nxj2T+HymP/lSVqojQyNhobVRsKoTZM5gzmo/lr07dsPtqYI3vYXUEDGBXwMkw2mYI/qgPE1Y+wbptEsbuHOBs3R1MCrmqw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619382754287245.78250236702524; Sun, 25 Apr 2021 13:32:34 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=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=20Pau=20Monn=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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) 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=C3=A9 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 +=3D percpu.o obj-y +=3D platform.o obj-y +=3D platform_hypercall.o obj-y +=3D physdev.o +obj-y +=3D pmap.init.o obj-y +=3D processor.o obj-y +=3D psci.o obj-y +=3D 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); } =20 -/* - * Standard entry type that we'll use to build Xen's own pagetables. - * We put the same permissions at every level, because they're ignored - * by the walker in non-leaf entries. - */ -static inline lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned attr) +lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr) { lpae_t e =3D (lpae_t) { .pt =3D { diff --git a/xen/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 af= ter + * 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 =3D find_first_zero_bit(&inuse, NUM_FIX_PMAP); + if ( idx =3D=3D NUM_FIX_PMAP ) + panic("Out of PMAP slots\n"); + + __set_bit(idx, &inuse); + + slot =3D idx + FIXMAP_PMAP_BEGIN; + ASSERT(slot >=3D FIXMAP_PMAP_BEGIN && slot <=3D FIXMAP_PMAP_END); + + linear =3D FIXMAP_ADDR(slot); + /* + * We cannot use set_fixmap() here. We use PMAP when there is no direc= t map, + * so map_pages_to_xen() called by set_fixmap() needs to map pages on + * demand, which then calls pmap() again, resulting in a loop. Modify = the + * PTEs directly instead. The same is true for pmap_unmap(). + */ + entry =3D &xen_fixmap[third_table_offset(linear)]; + + ASSERT(!lpae_is_valid(*entry)); + + pte =3D mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); + pte.pt.table =3D 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 =3D { 0 }; + unsigned int slot =3D third_table_offset((vaddr_t)p); + + ASSERT(system_state < SYS_STATE_smp_boot); + ASSERT(slot >=3D FIXMAP_PMAP_BEGIN && slot <=3D FIXMAP_PMAP_END); + + idx =3D slot - FIXMAP_PMAP_BEGIN; + local_irq_save(flags); + + __clear_bit(idx, &inuse); + entry =3D &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) =20 #define NR_hypercalls 64 =20 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__ =20 #include +#include =20 /* * WARNING! Unlike the x86 pagetable code, where l1 is the lowest level a= nd @@ -168,6 +169,13 @@ static inline bool lpae_is_superpage(lpae_t pte, unsig= ned int level) third_table_offset(addr) \ } =20 +/* + * Standard entry type that we'll use to build Xen's own pagetables. + * We put the same permissions at every level, because they're ignored + * by the walker in non-leaf entries. + */ +lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr); + #endif /* __ASSEMBLY__ */ =20 /* diff --git a/xen/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__ */ --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619382754; cv=none; d=zohomail.com; s=zohoarc; b=N0760PEdcp+cSMJNUBziC7WvVvRckPUGVx53kLclqaFo0lAROyk2/B3+MOs+qFx7LEV2Ab77YzQlkgJ4/JUxPfciMpVAr/DNSXS1JczeqPW3R8B1hPL42Eug/aCNR/bDpbkfzx1Ur8EmR9z65XXjBV/jeXGRpKrLiluEGy3ZD+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619382754; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ifKF5vlWlY6l4PDeK/yzMglzvzJIHrIdX0+DxnqU6gM=; b=BvdJsdIdPdxsdq/ikVowTudPKMT/A5vxk5CF6+PhGn3u82jg0OaWjmjCVznmm6a+CtB+xi3tMkT1sLGaUNmQDaY30CQSQ/MTKsJitM6c+iHEgez0n+cr2EjMRCl9sFvnJp1OA3twgUEfXsaa0H7R3d78/IdSeT+ij7lpJW6fTMs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619382754333420.6515840704609; Sun, 25 Apr 2021 13:32:34 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall During early boot, it is not possible to use xen_{,un}map_table() if the page tables are not residing the Xen binary. This is a blocker to switch some of the helpers to use xen_pt_update() as we may need to allocate extra page tables and access them before the domheap has been initialized (see setup_xenheap_mappings()). xen_{,un}map_table() are now updated to use the PMAP helpers for early boot map/unmap. Note that the special case for page-tables residing in Xen binary has been dropped because it is "complex" and was only added as a workaround in 8d4f1b8878e0 ("xen/arm: mm: Allow generic xen page-tables helpers to be called early"). Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - New patch --- xen/arch/arm/mm.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 5e713b599611..f5768f2d4a81 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -41,6 +41,7 @@ #include #include =20 +#include #include =20 /* Override macros from asm/page.h to make them work with mfn_t */ @@ -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 =3D=3D SYS_STATE_early_boot ) - { - if ( is_xen_fixed_mfn(mfn) ) - { - /* - * It is fine to demote the type because the size of Xen - * will always fit in vaddr_t. - */ - vaddr_t offset =3D mfn_to_maddr(mfn) - virt_to_maddr(&_start); - - return (lpae_t *)(XEN_VIRT_START + offset); - } - } + return pmap_map(mfn); =20 return map_domain_page(mfn); } @@ -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 =3D=3D SYS_STATE_early_boot && is_kernel(table) ) - return; - - unmap_domain_page(table); + if ( system_state =3D=3D SYS_STATE_early_boot ) + pmap_unmap(table); + else + unmap_domain_page(table); } =20 static int create_xen_table(lpae_t *entry) --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619382755; cv=none; d=zohomail.com; s=zohoarc; b=X1fiTFOyzrJ5MG8Ul3ce7qEsasm4FB3xJDKEcbh6Hp4fojPyjkk/E3N5zdpHW+UcD4pxqhLtaa+tXX9QKBjk/mncydV8yG8+PVu5rwEOMDXMK6lPNz3sNH422d82pzZcceZsqjn5v+DdME9wGlnJHHDWNsFd00d6YNx8L9BjQfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619382755; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=kWwF6/XiImdq/NMXQrU9YONcKwipFpia2KSsKJxknoU=; b=iYRZ//0956WY5+NkFppahAb+kl+8isIV4V8am6s+JNoCkBpu2YvWumdUvd0WxIlOE88k2K3E7zDGAcq9XwCCjCIltpcPWgOQ+tXfNzjm1tLDL54IvAkCvkrxkDVQJ71NJBSD0IGN+eM627SBW/CAyXnOuAqIm52j6iwvO5pu8V0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619382755638602.9992112144419; Sun, 25 Apr 2021 13:32:35 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =20 -#ifdef CONFIG_ARM_64 -/* The first page of the first level mapping of the xenheap. The - * subsequent xenheap first level pages are dynamically allocated, but - * we need this one to bootstrap ourselves. */ -static DEFINE_PAGE_TABLE(xenheap_first_first); -/* The zeroeth level slot which uses xenheap_first_first. Used because - * setup_xenheap_mappings otherwise relies on mfn_to_virt which isn't - * valid for a non-xenheap mapping. */ -static __initdata int xenheap_first_first_slot =3D -1; -#endif - /* Common pagetable leaves */ /* Second level page tables. * @@ -818,9 +807,9 @@ void __init setup_xenheap_mappings(unsigned long base_m= fn, 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; =20 /* Align to previous 1GB boundary */ mfn =3D base_mfn & ~((FIRST_SIZE>>PAGE_SHIFT)-1); @@ -846,49 +835,10 @@ void __init setup_xenheap_mappings(unsigned long base= _mfn, */ vaddr =3D (vaddr_t)__mfn_to_virt(base_mfn) & FIRST_MASK; =20 - while ( mfn < end_mfn ) - { - int slot =3D zeroeth_table_offset(vaddr); - lpae_t *p =3D &xen_pgtable[slot]; - - if ( p->pt.valid ) - { - /* mfn_to_virt is not valid on the 1st 1st mfn, since it - * is not within the xenheap. */ - first =3D slot =3D=3D xenheap_first_first_slot ? - xenheap_first_first : mfn_to_virt(lpae_get_mfn(*p)); - } - else if ( xenheap_first_first_slot =3D=3D -1) - { - /* Use xenheap_first_first to bootstrap the mappings */ - first =3D xenheap_first_first; - - pte =3D pte_of_xenaddr((vaddr_t)xenheap_first_first); - pte.pt.table =3D 1; - write_pte(p, pte); - - xenheap_first_first_slot =3D slot; - } - else - { - mfn_t first_mfn =3D alloc_boot_pages(1, 1); - - clear_page(mfn_to_virt(first_mfn)); - pte =3D mfn_to_xen_entry(first_mfn, MT_NORMAL); - pte.pt.table =3D 1; - write_pte(p, pte); - first =3D mfn_to_virt(first_mfn); - } - - pte =3D mfn_to_xen_entry(_mfn(mfn), MT_NORMAL); - /* TODO: Set pte.pt.contig when appropriate. */ - write_pte(&first[first_table_offset(vaddr)], pte); - - mfn +=3D FIRST_SIZE>>PAGE_SHIFT; - vaddr +=3D FIRST_SIZE; - } - - flush_xen_tlb_local(); + rc =3D map_pages_to_xen(vaddr, _mfn(mfn), end_mfn - mfn, + PAGE_HYPERVISOR_RW | _PAGE_BLOCK); + if ( rc ) + panic("Unable to setup the xenheap mappings.\n"); } #endif =20 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 =3D min(ram_start,bank_start); ram_end =3D max(ram_end,bank_end); =20 - setup_xenheap_mappings(bank_start>>PAGE_SHIFT, bank_size>>PAGE_SHI= FT); - + /* + * Add the region to the boot allocator first, so we can use + * some to allocate page-tables for setting up the xenheap + * mappings. + */ s =3D 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 =3D n; } + + setup_xenheap_mappings(bank_start >> PAGE_SHIFT, + bank_size >> PAGE_SHIFT); } =20 total_pages +=3D ram_size >> PAGE_SHIFT; --=20 2.17.1 From nobody Fri Mar 29 04:38:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1619382755; cv=none; d=zohomail.com; s=zohoarc; b=T3T7ll0P77gH+v0Jo2E1WuYRUUk19Vm+rKJ3q1DXEcPvx2MhfLuqcurGv4zOxbkR5CjXswCSUSBtJslhqmxeyAecFSBixc4AMRlOExvtuvoAeNOcjeoEMI4fOoCqT4OHnqp5wuRqnc6UlTJaivIe8K8cPL5DH0OHMJTlLkMcHhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619382755; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=PFAiZzvNdX0XtM/ZLCXS9tRAO1+3c66q0ERBXXoUxuU=; b=f9sDmlw/c+4CA+dGqxzuD90zTt0ywIYHQ7hBoBAj5pulDb289aWnu2SS0gxnpY0wDNSbW8X4S25osSAMWBL++XNCvgBZ6I38TTaUFbR/44dVSxbxUyRcko2wsfbBzlXGYsDTFqMznP0Vn4CFw6uchx7ZtM9kyBDoJzdSVZUKgOo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619382755870152.15067211351004; Sun, 25 Apr 2021 13:32:35 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=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> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that map_pages_to_xen() has been extended to support 2MB mappings, we can replace the create_mappings() call by map_pages_to_xen() call. This has the advantage to remove the 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 !=3D 0); } =20 -/* Create Xen's mappings of memory. - * Mapping_size must be either 2MB or 32MB. - * Base and virt must be mapping_size aligned. - * Size must be a multiple of mapping_size. - * second must be a contiguous set of second level page tables - * covering the region starting at virt_offset. */ -static void __init create_mappings(lpae_t *second, - unsigned long virt_offset, - unsigned long base_mfn, - unsigned long nr_mfns, - unsigned int mapping_size) -{ - unsigned long i, count; - const unsigned long granularity =3D mapping_size >> PAGE_SHIFT; - lpae_t pte, *p; - - ASSERT((mapping_size =3D=3D MB(2)) || (mapping_size =3D=3D MB(32))); - ASSERT(!((virt_offset >> PAGE_SHIFT) % granularity)); - ASSERT(!(base_mfn % granularity)); - ASSERT(!(nr_mfns % granularity)); - - count =3D nr_mfns / LPAE_ENTRIES; - p =3D second + second_linear_offset(virt_offset); - pte =3D mfn_to_xen_entry(_mfn(base_mfn), MT_NORMAL); - if ( granularity =3D=3D 16 * LPAE_ENTRIES ) - pte.pt.contig =3D 1; /* These maps are in 16-entry contiguous chu= nks. */ - for ( i =3D 0; i < count; i++ ) - { - write_pte(p + i, pte); - pte.pt.base +=3D 1 << LPAE_SHIFT; - } - 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, pad= dr_t pe) unsigned long frametable_size =3D nr_pdxs * sizeof(struct page_info); mfn_t base_mfn; const unsigned long mapping_size =3D frametable_size < MB(32) ? MB(2) = : MB(32); -#ifdef CONFIG_ARM_64 - lpae_t *second, pte; - unsigned long nr_second; - mfn_t second_base; - int i; -#endif + int rc; =20 frametable_base_pdx =3D mfn_to_pdx(maddr_to_mfn(ps)); /* Round up to 2M or 32M boundary, as appropriate. */ frametable_size =3D ROUNDUP(frametable_size, mapping_size); base_mfn =3D alloc_boot_pages(frametable_size >> PAGE_SHIFT, 32<<(20-1= 2)); =20 -#ifdef CONFIG_ARM_64 - /* Compute the number of second level pages. */ - nr_second =3D ROUNDUP(frametable_size, FIRST_SIZE) >> FIRST_SHIFT; - second_base =3D alloc_boot_pages(nr_second, 1); - second =3D mfn_to_virt(second_base); - for ( i =3D 0; i < nr_second; i++ ) - { - clear_page(mfn_to_virt(mfn_add(second_base, i))); - pte =3D mfn_to_xen_entry(mfn_add(second_base, i), MT_NORMAL); - pte.pt.table =3D 1; - write_pte(&xen_first[first_table_offset(FRAMETABLE_VIRT_START)+i],= pte); - } - create_mappings(second, 0, mfn_x(base_mfn), frametable_size >> PAGE_SH= IFT, - mapping_size); -#else - create_mappings(xen_second, FRAMETABLE_VIRT_START, mfn_x(base_mfn), - frametable_size >> PAGE_SHIFT, mapping_size); -#endif + /* XXX: Handle contiguous bit */ + rc =3D map_pages_to_xen(FRAMETABLE_VIRT_START, base_mfn, + frametable_size >> PAGE_SHIFT, PAGE_HYPERVISOR_R= W); + if ( rc ) + panic("Unable to setup the frametable mappings.\n"); =20 memset(&frame_table[0], 0, nr_pdxs * sizeof(struct page_info)); memset(&frame_table[nr_pdxs], -1, --=20 2.17.1