From nobody Fri Oct 31 11:33:44 2025 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; 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; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 175041305780086.03161069224518; Fri, 20 Jun 2025 02:50:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1020734.1396865 (Exim 4.92) (envelope-from ) id 1uSYOU-0007LR-RD; Fri, 20 Jun 2025 09:50:46 +0000 Received: by outflank-mailman (output) from mailman id 1020734.1396865; Fri, 20 Jun 2025 09:50:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uSYOU-0007LI-OD; Fri, 20 Jun 2025 09:50:46 +0000 Received: by outflank-mailman (input) for mailman id 1020734; Fri, 20 Jun 2025 09:50:45 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uSYOT-0004kQ-AR for xen-devel@lists.xenproject.org; Fri, 20 Jun 2025 09:50:45 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 0823130f-4dbc-11f0-b894-0df219b8e170; Fri, 20 Jun 2025 11:50:43 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 78CB1176A; Fri, 20 Jun 2025 02:50:23 -0700 (PDT) Received: from PWQ0QT7DJ1.arm.com (unknown [10.57.67.38]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E96063F673; Fri, 20 Jun 2025 02:50:41 -0700 (PDT) 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" X-Inumbo-ID: 0823130f-4dbc-11f0-b894-0df219b8e170 From: Hari Limaye To: xen-devel@lists.xenproject.org Cc: luca.fancellu@arm.com, Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH 2/6] xen/arm: Introduce flags_has_rwx helper Date: Fri, 20 Jun 2025 10:49:20 +0100 Message-ID: X-Mailer: git-send-email 2.42.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1750413058510116600 Content-Type: text/plain; charset="utf-8" From: Luca Fancellu Introduce flags_has_rwx() function that will check if a mapping is both writable and executable when modifying or update the mapping. This check was already present in pt.c but since it will be used also for MPU system, it's wrapped into a function now. Signed-off-by: Luca Fancellu Reviewed-by: Ayan Kumar Halder Reviewed-by: Michal Orzel --- xen/arch/arm/include/asm/mm.h | 2 ++ xen/arch/arm/mm.c | 15 +++++++++++++++ xen/arch/arm/mmu/pt.c | 9 +-------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 011bc1fd30..9daaa96d93 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -192,6 +192,8 @@ extern unsigned long frametable_base_pdx; =20 /* Boot-time pagetable setup */ extern void setup_pagetables(void); +/* Check that the mapping flag has no W and X together */ +extern bool flags_has_rwx(unsigned int flags); /* Map FDT in boot pagetable */ extern void *early_fdt_map(paddr_t fdt_paddr); /* Remove early mappings */ diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 0613c19169..c2da1e3a05 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -24,6 +24,21 @@ =20 unsigned long frametable_base_pdx __read_mostly; =20 +bool flags_has_rwx(unsigned int flags) +{ + /* + * The hardware was configured to forbid mapping both writeable and + * executable. + * When modifying/creating mapping (i.e _PAGE_PRESENT is set), + * prevent any update if this happen. + */ + if ( (flags & _PAGE_PRESENT) && !PAGE_RO_MASK(flags) && + !PAGE_XN_MASK(flags) ) + return true; + else + return false; +} + void flush_page_to_ram(unsigned long mfn, bool sync_icache) { void *v =3D map_domain_page(_mfn(mfn)); diff --git a/xen/arch/arm/mmu/pt.c b/xen/arch/arm/mmu/pt.c index 4726e713ef..621b47dbf5 100644 --- a/xen/arch/arm/mmu/pt.c +++ b/xen/arch/arm/mmu/pt.c @@ -610,14 +610,7 @@ static int xen_pt_update(unsigned long virt, */ const mfn_t root =3D maddr_to_mfn(READ_SYSREG64(TTBR0_EL2)); =20 - /* - * The hardware was configured to forbid mapping both writeable and - * executable. - * When modifying/creating mapping (i.e _PAGE_PRESENT is set), - * prevent any update if this happen. - */ - if ( (flags & _PAGE_PRESENT) && !PAGE_RO_MASK(flags) && - !PAGE_XN_MASK(flags) ) + if ( flags_has_rwx(flags) ) { mm_printk("Mappings should not be both Writeable and Executable.\n= "); return -EINVAL; --=20 2.34.1