From patchwork Wed Apr 17 17:58:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162413 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp5795932jan; Wed, 17 Apr 2019 10:59:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0apIrLHsES9opnZI6SiZqOGxRWFKZ0tnbO8WLfteEN1qNkMmYGJCTteS51KNcmAH1M7Ki X-Received: by 2002:a81:3b58:: with SMTP id i85mr70817989ywa.357.1555523992797; Wed, 17 Apr 2019 10:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555523992; cv=none; d=google.com; s=arc-20160816; b=bK6GGmjng8vz2olu/9bNxdL20ysWQpS/mj0MkA6ggOj4QxFjXCyWQkJPbVowweSjCr b64OUb3jmJjZxW6siSGDTQXhyCRGm3TQukPhDIMK6kAB96BsaYCePQxsi8jBNWkhFk6O Gjjim+QbrkXqudKybo0Ja6RkPcFPfzGGRaRYX2KnEjQm6TOLFjmeMlUsXXi9InNiMw08 xFi1qgFQnuRNUjQEM4iKG9+J1a1RfCXg5+4xlV18EpRJIM8LGfyfykt/D0bKRCmeqtu/ VOTK6WJZxR1EpZdr1bF6UGCmy8EGK7goD+kaIglhFbJWixhdGMOzUjE6Sv2xNWg1DS3E zabA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=017IOD1/OtFN0JhsdyyD+LpPz/8yc0SLsWHhV5pIG+g=; b=HXLpsKKw7tb/v8pAR5B2gBiaJvIDLlXwl4U31I+4Q5cZ8I3VFBHMN4SdSFLOGvKxHB Vq/sX/vA5RcJm4hPoZqU7OI0QFgIMMN3v6acDm2KrB+8VM61g7pwgrddCh6n47i2uCzF p4wCPI2N0cUg32ufT/ZwdhTZwuDBy4XSV9hdxAEPJb+m8ilNGxzCB05O2v5YdP7w7T3W vb0tJORp9TztVXyxsBO4x4vr9Ul71jL8kdjcNL2rlLhUih3Fkc1PXfp7TGiKdzwObJVc bG6ho5r6Hq9n9pNrkCC6KoZojg1I5eyxaax2mY/eOjxSopxVedkG9BwpzXAO1BE6WPK5 AGUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@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.google.com with ESMTPS id 124si12659308ybo.450.2019.04.17.10.59.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 10:59:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hGopF-00049V-9Y; Wed, 17 Apr 2019 17:58:25 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hGopE-00048n-08 for xen-devel@lists.xenproject.org; Wed, 17 Apr 2019 17:58:24 +0000 X-Inumbo-ID: 645d5ff8-613a-11e9-ad61-234692ca7bf5 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 645d5ff8-613a-11e9-ad61-234692ca7bf5; Wed, 17 Apr 2019 17:58:23 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9A9271688; Wed, 17 Apr 2019 10:58:22 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A4B43F59C; Wed, 17 Apr 2019 10:58:21 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 17 Apr 2019 18:58:09 +0100 Message-Id: <20190417175815.16905-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190417175815.16905-1-julien.grall@arm.com> References: <20190417175815.16905-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 1/7] xen/arm: mm: Consolidate setting SCTLR_EL2.WXN in a single place X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The logic to set SCTLR_EL2.WXN is the same for the boot CPU and non-boot CPU. So introduce a function to set the bit and clear TBLs. This new function will help us to document and update the logic in a single place. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 01ae2cccc0..93ad118183 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -601,6 +601,19 @@ void __init remove_early_mappings(void) flush_xen_data_tlb_range_va(BOOT_FDT_VIRT_START, BOOT_FDT_SLOT_SIZE); } +/* + * After boot, Xen page-tables should not contain mapping that are both + * Writable and eXecutables. + * + * This should be called on each CPU to enforce the policy. + */ +static void xen_pt_enforce_wnx(void) +{ + WRITE_SYSREG32(READ_SYSREG32(SCTLR_EL2) | SCTLR_WXN, SCTLR_EL2); + /* Flush everything after setting WXN bit. */ + flush_xen_text_tlb_local(); +} + extern void switch_ttbr(uint64_t ttbr); /* Clear a translation table and clean & invalidate the cache */ @@ -702,10 +715,7 @@ void __init setup_pagetables(unsigned long boot_phys_offset) clear_table(boot_second); clear_table(boot_third); - /* From now on, no mapping may be both writable and executable. */ - WRITE_SYSREG32(READ_SYSREG32(SCTLR_EL2) | SCTLR_WXN, SCTLR_EL2); - /* Flush everything after setting WXN bit. */ - flush_xen_text_tlb_local(); + xen_pt_enforce_wnx(); #ifdef CONFIG_ARM_32 per_cpu(xen_pgtable, 0) = cpu0_pgtable; @@ -777,9 +787,7 @@ int init_secondary_pagetables(int cpu) /* MMU setup for secondary CPUS (which already have paging enabled) */ void mmu_init_secondary_cpu(void) { - /* From now on, no mapping may be both writable and executable. */ - WRITE_SYSREG32(READ_SYSREG32(SCTLR_EL2) | SCTLR_WXN, SCTLR_EL2); - flush_xen_text_tlb_local(); + xen_pt_enforce_wnx(); } #ifdef CONFIG_ARM_32