From patchwork Tue May 14 12:11:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 164136 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2540608ili; Tue, 14 May 2019 05:13:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqw38o2A2oQqzc2wYc0P7KAFFQAz4Kbe47HFmwu0YPpKdeQne7xekQswNHRLYb46D5QQDQvP X-Received: by 2002:a6b:6304:: with SMTP id p4mr3938240iog.211.1557835981304; Tue, 14 May 2019 05:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557835981; cv=none; d=google.com; s=arc-20160816; b=xGeIX8UruDIeb9wtvtsjn3a3iwlZ4XjFyK/fbpyhR7WeKH2JPnFqMTIHHzICV9qx/g LqJC5B7i6lC1Rev/FcVVh6Ye//PDVf1NDdimPruJjtsEYwOY06QyWnHwe3vfK564fp5D 3nbMELYqoUM2YnUCbWuNrCoF/uCqwWyAMoxO96jUPa7B8SJ3vKXIE9gX2nt2pCcm0PvG 8bf+RbMSb/911A+ABDmDxpWfeP4jPnGKfyn9nZpTE94omxw4QyJvat8bpBIOGqI2XVAh 1EFBfTy3YsSeUpOrDOS/IV1YpvjCVMAMMyuyVS7Nz4x1lgEhuyPfzDqv/X1yufGUeGd1 C7ow== 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=BhTZ+0klaTehJOtVb+DOx1H9QOZvkNN7IXM574DSmRw=; b=e0NyZLtedawAOiLhLGDFiuZEQmJMRjhVs7rfGrdstoddqt4Bj/iFZZcln1DNEg1A4K 0a+2f/3Sd7x+A/DYuErUFTRvjqwOIj6SBV5ZjBY8abiCSrGgObumASV4HlBMF+L/atKW X9sFE2BLGmyYu7ajGZ8Lql3FmTPj3FHyo6emqLt0hEZhpJz5yRPZrCHxkD6Mo80PlUJD SF/Z92WZZAzUypHgLl1Jb1GCfxEersk+iP80xKriF0+2uz6O57Rjcq7MEh+ZlXMZ8jdG HTcxwrCcZBvGQb01Z6QvYT8oHJjtxczuoBLzhrNCciQRU8xRPR4ON++uC5vr5qbqy9Kd 0Sqg== 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 w188si1469105itg.45.2019.05.14.05.13.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 05:13:01 -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 1hQWHZ-0006Ey-3a; Tue, 14 May 2019 12:11:45 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWHY-0006EZ-6Q for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:11:44 +0000 X-Inumbo-ID: 6f4ff7aa-7641-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6f4ff7aa-7641-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:11:42 +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 1EA4C15AD; Tue, 14 May 2019 05:11:42 -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 DF6C83F71E; Tue, 14 May 2019 05:11:40 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:11:26 +0100 Message-Id: <20190514121132.26732-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514121132.26732-1-julien.grall@arm.com> References: <20190514121132.26732-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART1 v3 2/8] 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 , Stefano Stabellini , Andrii Anisov 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 TLBs. 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 Reviewed-by: Stefano Stabellini --- Changes in v3: - Add Stefano's reviewed-by Changes in v2: - Fix typo in the commit message - Add Andrii's reviewed-by --- 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