From patchwork Mon Oct 8 18:33:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 148436 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp3982244lji; Mon, 8 Oct 2018 11:36:26 -0700 (PDT) X-Google-Smtp-Source: ACcGV61KACZI5lk+ESKfCkuGs4EZdiavq/t9cRaB7yCT6vOE9e5hNCfw+Xk0hBr1saB4GD+yCXDT X-Received: by 2002:a24:22d0:: with SMTP id o199-v6mr16153433ito.67.1539023785901; Mon, 08 Oct 2018 11:36:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539023785; cv=none; d=google.com; s=arc-20160816; b=dWdQycJJEZp1anLowxYSxbI0XZPn3+bYK7ZRBzK6ibxvmEgi/C45hl1MOa+46thY0M klrjdsy7wl/v5txS/Th9mqcHhqI4imaYx0WrHpIfKVMvemKC1PDu4bLkT1Py+Qg/Oy6y lwqcGRaWzIeWD+/4YBGZYVLiXvigJ4GP+QfqlwVS1JjZpBpJMZIkgDOdoArjYcjjmqv4 VsaHKOa3z16A3oFaQg4tNs8oNytMaqrRg4KFfpKGhfWojBtSF8MqQ6mtgVQI+7PI7qEb xbuqAWwZvDgTtSQpv2vZtBE6tg62xv6nBpavoxqdQR8G3fiUce4Z4Bk8XVXwingaAjWq CuYw== 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=+5xVqlSM0pSrKqei5YQtScR4D5yGyKdTs+Y7d+AbWpo=; b=eOkT38yylXe11Jp9fhhXfV0gCw47FJCTS+OeLO045i1tTd6GjMUQig59H3NUcv9srX pyuvWiPLlDsalOxciLFSGts3p+5UpJGQQTNnySOHts+Zfyy1LGKl8gxwk7DY0o/OcU/K JTZ230zDlFIOw8ng3AhpvnoCoy6xdh9IreW8axkR4vA6HjqU/8b4EVRd9+K+E2ia/wYH P0W9cydSbqc74iN4Kr4vaZGacJkkwDK8VfnfS42DcwlKcqJGv/V5g2Zi9GOWklMt3MzW yAyRcUj6NX4QLvrEyGSBTJMKLcR10oJS/yPmTwgrJgrWU4e6SjSxffN1aCLhdy/wh/A0 HLvQ== 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 q74-v6si8229489itb.97.2018.10.08.11.36.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Oct 2018 11:36:25 -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 1g9aMF-0005pT-Ns; Mon, 08 Oct 2018 18:34:19 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1g9aME-0005nI-1w for xen-devel@lists.xen.org; Mon, 08 Oct 2018 18:34:18 +0000 X-Inumbo-ID: f14b8f75-cb28-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id f14b8f75-cb28-11e8-a6a9-d7ebe60f679a; Mon, 08 Oct 2018 18:35:34 +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 55363ED1; Mon, 8 Oct 2018 11:34:17 -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 6B1F83F5B3; Mon, 8 Oct 2018 11:34:16 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 8 Oct 2018 19:33:50 +0100 Message-Id: <20181008183352.16291-15-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181008183352.16291-1-julien.grall@arm.com> References: <20181008183352.16291-1-julien.grall@arm.com> Subject: [Xen-devel] [RFC 14/16] xen/arm: p2m: Extend p2m_get_entry to return the value of bit[0] (valid bit) 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: Julien Grall , sstabellini@kernel.org, andre.przywara@linaro.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" With the recent changes, a P2M entry may be populated but may as not valid. In some situation, it would be useful to know whether the entry has been marked available to guest in order to perform a specific action. So extend p2m_get_entry to return the value of bit[0] (valid bit). Signed-off-by: Julien Grall --- xen/arch/arm/mem_access.c | 6 +++--- xen/arch/arm/p2m.c | 20 ++++++++++++++++---- xen/include/asm-arm/p2m.h | 3 ++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/mem_access.c b/xen/arch/arm/mem_access.c index 9239bdf323..f434510b2a 100644 --- a/xen/arch/arm/mem_access.c +++ b/xen/arch/arm/mem_access.c @@ -70,7 +70,7 @@ static int __p2m_get_mem_access(struct domain *d, gfn_t gfn, * No setting was found in the Radix tree. Check if the * entry exists in the page-tables. */ - mfn_t mfn = p2m_get_entry(p2m, gfn, NULL, NULL, NULL); + mfn_t mfn = p2m_get_entry(p2m, gfn, NULL, NULL, NULL, NULL); if ( mfn_eq(mfn, INVALID_MFN) ) return -ESRCH; @@ -199,7 +199,7 @@ p2m_mem_access_check_and_get_page(vaddr_t gva, unsigned long flag, * We had a mem_access permission limiting the access, but the page type * could also be limiting, so we need to check that as well. */ - mfn = p2m_get_entry(p2m, gfn, &t, NULL, NULL); + mfn = p2m_get_entry(p2m, gfn, &t, NULL, NULL, NULL); if ( mfn_eq(mfn, INVALID_MFN) ) goto err; @@ -405,7 +405,7 @@ long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr, gfn = gfn_next_boundary(gfn, order) ) { p2m_type_t t; - mfn_t mfn = p2m_get_entry(p2m, gfn, &t, NULL, &order); + mfn_t mfn = p2m_get_entry(p2m, gfn, &t, NULL, &order, NULL); if ( !mfn_eq(mfn, INVALID_MFN) ) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 12b459924b..df6b48d73b 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -306,10 +306,14 @@ static int p2m_next_level(struct p2m_domain *p2m, bool read_only, * * If the entry is not present, INVALID_MFN will be returned and the * page_order will be set according to the order of the invalid range. + * + * valid will contain the value of bit[0] (e.g valid bit) of the + * entry. */ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, p2m_type_t *t, p2m_access_t *a, - unsigned int *page_order) + unsigned int *page_order, + bool *valid) { paddr_t addr = gfn_to_gaddr(gfn); unsigned int level = 0; @@ -317,6 +321,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, int rc; mfn_t mfn = INVALID_MFN; p2m_type_t _t; + bool _valid; /* Convenience aliases */ const unsigned int offsets[4] = { @@ -334,6 +339,10 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, *t = p2m_invalid; + /* Allow valid to be NULL */ + valid = valid?: &_valid; + *valid = false; + /* XXX: Check if the mapping is lower than the mapped gfn */ /* This gfn is higher than the highest the p2m map currently holds */ @@ -379,6 +388,9 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, * to the GFN. */ mfn = mfn_add(mfn, gfn_x(gfn) & ((1UL << level_orders[level]) - 1)); + + if ( valid ) + *valid = lpae_is_valid(entry); } out_unmap: @@ -397,7 +409,7 @@ mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t) struct p2m_domain *p2m = p2m_get_hostp2m(d); p2m_read_lock(p2m); - mfn = p2m_get_entry(p2m, gfn, t, NULL, NULL); + mfn = p2m_get_entry(p2m, gfn, t, NULL, NULL, NULL); p2m_read_unlock(p2m); return mfn; @@ -1464,7 +1476,7 @@ int relinquish_p2m_mapping(struct domain *d) for ( ; gfn_x(start) < gfn_x(end); start = gfn_next_boundary(start, order) ) { - mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order); + mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order, NULL); count++; /* @@ -1527,7 +1539,7 @@ int p2m_cache_flush_range(struct domain *d, gfn_t start, gfn_t end) for ( ; gfn_x(start) < gfn_x(end); start = next_gfn ) { - mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order); + mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order, NULL); next_gfn = gfn_next_boundary(start, order); diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index d7afa2bbe8..92213dd1ab 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -211,7 +211,8 @@ mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t); */ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, p2m_type_t *t, p2m_access_t *a, - unsigned int *page_order); + unsigned int *page_order, + bool *valid); /* * Direct set a p2m entry: only for use by the P2M code.