From patchwork Wed Apr 24 16:59:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 162785 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp895601jan; Wed, 24 Apr 2019 10:01:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6QVSbc1yCr2AClMgjhgCdgQiLL1p5+uIv5XXAe1SLHQtI16IModnFyBrhN/GVDX+V/im8 X-Received: by 2002:a25:cbd3:: with SMTP id b202mr5943858ybg.247.1556125310282; Wed, 24 Apr 2019 10:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556125310; cv=none; d=google.com; s=arc-20160816; b=eZishnSjk8RmviCuo2PZgIrlQzmz9+sxMxrC7BTUWCvVKOPI2nYHRZa/C6lCB0FIsL lgsYwgv6hcE39jIDSNU4N2hYqgUNeo5WdmgCOhq+4c3wy54BX1IIAKyL/zQOgbZ6r2wv Zq3EmT8IqgrJRvDvJfakeMUbH3CzgJZD92a7UBk89njWndfu2PhcktrDpa1kKpVAfWZc +QzRXKUeEYrgndtmZdLY0ymRrhMszeKx3OWiL+OA2HgZm/WzHP4BdlBt2igtga5yfXlr I3r9AaF45aWy/feCBzfdcK6VppWcrhQBA0MQZ4WlgvqoQJevTnWyP78SChcvtS6fjlbh b4lg== 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=ZNputk6QUdrZiTQcmoyAXdm73PJc4QX+zMHIMfURwWk=; b=BIFmsfiuuQGi6W+4GYq2i38TPE6RJTsRa4QfSXja7cEo9YRqcr+NexSEKehAYqF2P9 UrwLNbPgKeHCbPgNowJOYLzIZv62mOkfZT7cPyTXwK9G2CODSOdFFbFTaE+k4tY7zKeE 5vYasXhQ2kqx5wAgmC9UWCd57jqBbrD0InkqpZoNu0OLtrJXaf0Wzp6p3lgVDAkEk3co s/l8EVM1fhwS0Soj7a0nXc9HIMLeZrisIyGqcJUpOHptk72aPU3+Espg4s41rnQes5/r opqxaur961OsQrMJGbKGXhVPJz1cEV7MQS3c0gmFK6jqrHZ4bblOaf+JSf0FNdnhhXIY SXtA== 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 134si13819849ywp.77.2019.04.24.10.01.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 10:01:50 -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 1hJLFj-0007nH-LL; Wed, 24 Apr 2019 17:00:11 +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 1hJLFi-0007n1-BB for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:10 +0000 X-Inumbo-ID: 6a7fddf2-66b2-11e9-8188-4bb1fa585020 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 6a7fddf2-66b2-11e9-8188-4bb1fa585020; Wed, 24 Apr 2019 17:00:09 +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 97A45374; Wed, 24 Apr 2019 10:00:08 -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 7B2593F557; Wed, 24 Apr 2019 10:00:07 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:46 +0100 Message-Id: <20190424165955.23718-4-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 03/12] xen/arm: mm: Move out of xen_pt_update() the logic to update an entry 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" In preparation of rework of the Xen PT, the logic to update an entry in moved out in a separate function. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 140 +++++++++++++++++++++++++++++------------------------- 1 file changed, 74 insertions(+), 66 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index df2ec3a36b..6b1d41cfba 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -963,6 +963,76 @@ enum xenmap_operation { RESERVE }; +static int xen_pt_update_entry(enum xenmap_operation op, unsigned long addr, + mfn_t mfn, unsigned int flags) +{ + lpae_t pte, *entry; + lpae_t *third = NULL; + + entry = &xen_second[second_linear_offset(addr)]; + if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) + { + int rc = create_xen_table(entry); + if ( rc < 0 ) { + printk("%s: L2 failed\n", __func__); + return rc; + } + } + + BUG_ON(!lpae_is_valid(*entry)); + + third = mfn_to_virt(lpae_get_mfn(*entry)); + entry = &third[third_table_offset(addr)]; + + switch ( op ) { + case INSERT: + case RESERVE: + if ( lpae_is_valid(*entry) ) + { + printk("%s: trying to replace an existing mapping addr=%lx mfn=%"PRI_mfn"\n", + __func__, addr, mfn_x(mfn)); + return -EINVAL; + } + if ( op == RESERVE ) + break; + pte = mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); + pte.pt.ro = PAGE_RO_MASK(flags); + pte.pt.xn = PAGE_XN_MASK(flags); + BUG_ON(!pte.pt.ro && !pte.pt.xn); + pte.pt.table = 1; + write_pte(entry, pte); + break; + case MODIFY: + case REMOVE: + if ( !lpae_is_valid(*entry) ) + { + printk("%s: trying to %s a non-existing mapping addr=%lx\n", + __func__, op == REMOVE ? "remove" : "modify", addr); + return -EINVAL; + } + if ( op == REMOVE ) + pte.bits = 0; + else + { + pte = *entry; + pte.pt.ro = PAGE_RO_MASK(flags); + pte.pt.xn = PAGE_XN_MASK(flags); + if ( !pte.pt.ro && !pte.pt.xn ) + { + printk("%s: Incorrect combination for addr=%lx\n", + __func__, addr); + return -EINVAL; + } + } + write_pte(entry, pte); + break; + default: + BUG(); + } + + return 0; +} + static DEFINE_SPINLOCK(xen_pt_lock); static int xen_pt_update(enum xenmap_operation op, @@ -973,78 +1043,16 @@ static int xen_pt_update(enum xenmap_operation op, { int rc = 0; unsigned long addr = virt, addr_end = addr + nr_mfns * PAGE_SIZE; - lpae_t pte, *entry; - lpae_t *third = NULL; spin_lock(&xen_pt_lock); for(; addr < addr_end; addr += PAGE_SIZE, mfn = mfn_add(mfn, 1)) { - entry = &xen_second[second_linear_offset(addr)]; - if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) - { - rc = create_xen_table(entry); - if ( rc < 0 ) { - printk("%s: L2 failed\n", __func__); - goto out; - } - } - - BUG_ON(!lpae_is_valid(*entry)); - - third = mfn_to_virt(lpae_get_mfn(*entry)); - entry = &third[third_table_offset(addr)]; - - switch ( op ) { - case INSERT: - case RESERVE: - if ( lpae_is_valid(*entry) ) - { - printk("%s: trying to replace an existing mapping addr=%lx mfn=%"PRI_mfn"\n", - __func__, addr, mfn_x(mfn)); - rc = -EINVAL; - goto out; - } - if ( op == RESERVE ) - break; - pte = mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); - pte.pt.ro = PAGE_RO_MASK(flags); - pte.pt.xn = PAGE_XN_MASK(flags); - BUG_ON(!pte.pt.ro && !pte.pt.xn); - pte.pt.table = 1; - write_pte(entry, pte); - break; - case MODIFY: - case REMOVE: - if ( !lpae_is_valid(*entry) ) - { - printk("%s: trying to %s a non-existing mapping addr=%lx\n", - __func__, op == REMOVE ? "remove" : "modify", addr); - rc = -EINVAL; - goto out; - } - if ( op == REMOVE ) - pte.bits = 0; - else - { - pte = *entry; - pte.pt.ro = PAGE_RO_MASK(flags); - pte.pt.xn = PAGE_XN_MASK(flags); - if ( !pte.pt.ro && !pte.pt.xn ) - { - printk("%s: Incorrect combination for addr=%lx\n", - __func__, addr); - rc = -EINVAL; - goto out; - } - } - write_pte(entry, pte); - break; - default: - BUG(); - } + rc = xen_pt_update_entry(op, addr, mfn, flags); + if ( rc ) + break; } -out: + /* * Flush the TLBs even in case of failure because we may have * partially modified the PT. This will prevent any unexpected