From patchwork Wed Apr 24 16:59:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162788 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895677jan; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEWkwIDV3qi66Ycn1zVn7upXomfvIotUFPR2Ee6be430hDdyK4IPNRecxkH+oE72hKmbJY X-Received: by 2002:a25:d6cc:: with SMTP id n195mr27504041ybg.516.1556125313420; Wed, 24 Apr 2019 10:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125313; cv=none; d=google.com; s=arc-20160816; b=Dn0gnxvQtfIenQULvzFgCUqTUhvLVr/hJRLQCDdwIQZDJWXshGlCw1NQVl5BIgPwUQ 5F8uAckGcWwHWVGhSrPRefD1e5z4b23ICYMywXi2eP2BZlVYcEGI9eLqOBIwhnrOuWEG vchXEAzf5VUSrwBhnWEYABWcvmIEkb6fA0FuVCrMk2U7lgxjX+H6pELXfdaZ1YOGgWh4 axoIsM02J0QQB7H/Cq6W7A9p8hSRAeT5lsPbaTTdK+rxSh7r31RlM8MxW7a35hYmU8UI q5lmN8DyYqpZ+kbzrtLeY1CuYCQS72stzDVyIP8whuZQV75wENGjh24UcfO5Iyf2IGV5 zNVQ== 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=NlbK9HPyMEbbgtBdlomy8/Y3Jhvfacl6cJjNdD5yKCw=; b=PGhYEBGhUITh6B3V+bAthvu/aLbGs0jl09CNHAoSN5nFC72grfqrsyRDWzmX2Y/SIb OHHHorRIgFkpL93iXKP82w+l5F+29R59d/zrSvhRu9KFyUBra5SzmYURoy0yQLpRoo5F hhDlF+H2wdzkmlo4bE6MAp2kGw2XpLJIr4gtgA/FMh7ZnsC4DXB9wcgPoMZ2nosBAyoS IEztHRWrdvsP4Q+zNkSOdbw7x1X9oEzZiGTREMbPSbRtoh0+cdsv614RrB5D118iH/qN iq4gSHUT7MoNIepZTi1Nd7KNfOAmib9fuFNILVcbGy8m2YwcbP5Ch9NbjG7Px8si9RW7 V7rQ== 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 126si5894942yby.399.2019.04.24.10.01.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:53 -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 1hJLFu-0007qw-Ma; Wed, 24 Apr 2019 17:00:22 +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 1hJLFu-0007qV-22 for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:22 +0000 X-Inumbo-ID: 71db77c8-66b2-11e9-9fa8-dfc6e70f8e3d Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 71db77c8-66b2-11e9-9fa8-dfc6e70f8e3d; Wed, 24 Apr 2019 17:00:21 +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 F1477374; Wed, 24 Apr 2019 10:00:20 -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 D6D073F557; Wed, 24 Apr 2019 10:00:19 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:55 +0100 Message-Id: <20190424165955.23718-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 12/12] 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 , sstabellini@kernel.org, Andrii_Anisov@epam.com 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(). Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- 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 7e6df9f877..5810d569ee 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1272,52 +1272,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) { @@ -1326,8 +1280,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)", rc); /* * From now on, init will not be used for execution anymore, @@ -1345,7 +1303,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)", rc); + init_domheap_pages(pa, pa + len); printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10); }