From patchwork Fri Jun 14 17:51:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 166871 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2351281ilk; Fri, 14 Jun 2019 10:53:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqwinMj7cRkJSdN72l2aj8RfTwR8nMYW9hhouRivdTO8mzicr8j6JaKyyHuTB1iVHuDYHZnA X-Received: by 2002:a6b:621a:: with SMTP id f26mr3180828iog.127.1560534813101; Fri, 14 Jun 2019 10:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534813; cv=none; d=google.com; s=arc-20160816; b=dJViIlOd7eYlC/SMcoHwVS6arLKp30P+qSWFURc6jmcfaMFcgwM9YfZDe3mhVipCzV R1sWVWwTrcMdYxJtVZYG69uJmldWuKyGRci3LGgVW8LJmgBEm92lVH2pkdoqD5CC4dLK 6qILdbitBKL9HkQNdvD1t+ftd+5AeL8r82ao2fshNS/EKcY8XamJ59sBnfo/qVpp1665 tCs86jU3FzG8KsEFInqN4pH+3VbWBbIJaEDbhB0/iInPef3y4kGNR1lEGIKLVAC8cCbe r3d0bthvoEvrmIYruJAEA/L8gc6lDctkH4x3jnyGv09xImAzsSNlWTsC0VNjb045ynTV /5eQ== 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=0Oaluw5j5Q6sORl18a5YpVe/ACZm6T5I0vplJWuO8TE=; b=S2Urofp3E9oBbc40WqNSL+rEyh16IjaU7eLFgVfkBPn+hRGZkwX15O99oCzdRAW0Qk Nd1n78oKmJDFMXyCLO1ZHHv9CsOKGBJfLDflgbSX0v7HrHvD2TtCriDkVQEVH6/Oz260 lwacXVWdjF8S8VOM93OKNpHH8+sy6pRe8Y4WIohkDNkVmRSZ/2K3hYQVrKudlcKM+NtY 6gC10Lqj9xu772+zWEACPVD/l4pXYeWKaDLrje5mObLX/CiIVKlX3DiICm5ZYuxKq97B svM2p2ShmlyQZoEwKg8Hd0bpNPkc8OXkg0LOGCFpgEu6HKVGK95FghqWOZde5Leo8nIQ 8wuw== 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 y24si4244748ioc.1.2019.06.14.10.53.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2019 10:53:33 -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 1hbqMw-0001ul-R7; Fri, 14 Jun 2019 17:52:06 +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 1hbqMv-0001tw-Fv for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 17:52:05 +0000 X-Inumbo-ID: 1d6a061c-8ecd-11e9-afa5-8b6a9b7e3b28 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 1d6a061c-8ecd-11e9-afa5-8b6a9b7e3b28; Fri, 14 Jun 2019 17:52:02 +0000 (UTC) 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 2FD21346; Fri, 14 Jun 2019 10:52:02 -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 458A83F718; Fri, 14 Jun 2019 10:52:01 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Jun 2019 18:51:44 +0100 Message-Id: <20190614175144.20046-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614175144.20046-1-julien.grall@arm.com> References: <20190614175144.20046-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v3 9/9] xen/arm: mm: Remove set_pte_flags_on_range() 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" set_pte_flags_on_range() is yet another function that will open-code update to a specific range in the Xen page-tables. It can be completely dropped by using either modify_xen_mappings() or destroy_xen_mappings(). Note that modify_xen_mappings() will keep the field 'pxn' cleared for the all the cases. This is because the field is RES0 for the stage-1 hypervisor as only a single VA range is supported (see D5.4.5 in DDI0487D.b). Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v3: - Update commit message to explain why the field 'pxn' is now cleared. Changes in v2: - Add missing newline in panic - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 58 ++++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 46bc3d8075..35dc1f7e71 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1255,52 +1255,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags) return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags); } -enum mg { mg_clear, mg_ro, mg_rw, mg_rx }; -static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg mg) -{ - lpae_t pte; - int i; - - ASSERT(is_kernel(p) && is_kernel(p + l)); - - /* Can only guard in page granularity */ - ASSERT(!((unsigned long) p & ~PAGE_MASK)); - ASSERT(!(l & ~PAGE_MASK)); - - for ( i = (p - _start) / PAGE_SIZE; - i < (p + l - _start) / PAGE_SIZE; - i++ ) - { - pte = xen_xenmap[i]; - switch ( mg ) - { - case mg_clear: - pte.pt.valid = 0; - break; - case mg_ro: - pte.pt.valid = 1; - pte.pt.pxn = 1; - pte.pt.xn = 1; - pte.pt.ro = 1; - break; - case mg_rw: - pte.pt.valid = 1; - pte.pt.pxn = 1; - pte.pt.xn = 1; - pte.pt.ro = 0; - break; - case mg_rx: - pte.pt.valid = 1; - pte.pt.pxn = 0; - pte.pt.xn = 0; - pte.pt.ro = 1; - break; - } - write_pte(xen_xenmap + i, pte); - } - flush_xen_tlb_local(); -} - /* Release all __init and __initdata ranges to be reused */ void free_init_memory(void) { @@ -1309,8 +1263,12 @@ void free_init_memory(void) uint32_t insn; unsigned int i, nr = len / sizeof(insn); uint32_t *p; + int rc; - set_pte_flags_on_range(__init_begin, len, mg_rw); + rc = modify_xen_mappings((unsigned long)__init_begin, + (unsigned long)__init_end, PAGE_HYPERVISOR_RW); + if ( rc ) + panic("Unable to map RW the init section (rc = %d)\n", rc); /* * From now on, init will not be used for execution anymore, @@ -1328,7 +1286,11 @@ void free_init_memory(void) for ( i = 0; i < nr; i++ ) *(p + i) = insn; - set_pte_flags_on_range(__init_begin, len, mg_clear); + rc = destroy_xen_mappings((unsigned long)__init_begin, + (unsigned long)__init_end); + if ( rc ) + panic("Unable to remove the init section (rc = %d)\n", rc); + init_domheap_pages(pa, pa + len); printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10); }