From patchwork Tue Dec 4 20:26:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 152849 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp8503297ljp; Tue, 4 Dec 2018 12:29:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/XCxH9bjG6lG4E+MCV6WFcjWilTUmWlDfpnPXMqezoN5np7K/Nzrh9zdRRS/F+hUGYUAXg8 X-Received: by 2002:a0d:d945:: with SMTP id b66mr21072967ywe.318.1543955359015; Tue, 04 Dec 2018 12:29:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543955359; cv=none; d=google.com; s=arc-20160816; b=0V+80hdP+d+d0Yn6eXbKUDwjdboJotsvC/M+bQg9BN3OSuvl9hOy1BKMSlEz8zjJyX G1260KFa5yg7PhE0qw1p0a3pkxUhMK1mFdeoe2gh/6fsrUKRKZHspicl+wJTqcrkzh4s pD252mvFkQUmePAPBBw4wQMURStGp3uKaMsjiwbOVtLul2JvICrz7y6zIzABN78pTvKT rMCI5PsN3/1RD+LXONFNZY9ua15OfYpNv2crgTZOpo+PS4c9W2foBkV1bOumhjcfZZnw xx5lxZHGbNcaV4S4e5oRn50NOxiAfV/canYGM03oHC2Hd7LtJnxtoYudc//DYwC5M3Wi Y7SQ== 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=Yl8guLWQt1dCwSLq8HwpGeA7Di1FT0mm7WXsPuIm8j0=; b=Rn5saS5nWWc3SY1VFN0EOJWzsjI243TsVl9m3f60RACxJBxVLukbPws1iOjw43oE3c yoM4vUSrr4bze/l4aHkhcvjgW+2r6Pvy+PBwrFXx2rlICayPQw+W28gkDeZxpA8yV4YP ypvRkz1b2a7xyGewNHuaxkp/lJSoCsowhtNzZghNrEnFF4whMFW/ox1mbNA4t6LCcwqH wpV164m2xQGPo8dYtUP6EgJewgfLUYqeplZkC4QD1da48d5tpb0Oxdhundvd2HZAbmpK JOIhYsgkQOw0RCIGECrjr20TDA4twmXZpQgVOXQk68l4c176c1ySNG8BfrMUp6ACZMj+ GRVA== 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 140si10249921ywk.118.2018.12.04.12.29.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 12:29:19 -0800 (PST) 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 1gUHI4-00089t-00; Tue, 04 Dec 2018 20:27:31 +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 1gUHI2-00089P-Ql for xen-devel@lists.xenproject.org; Tue, 04 Dec 2018 20:27:30 +0000 X-Inumbo-ID: 057c8202-f803-11e8-88cd-4fc698895070 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 057c8202-f803-11e8-88cd-4fc698895070; Tue, 04 Dec 2018 20:27:29 +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 5A90B15BE; Tue, 4 Dec 2018 12:27:29 -0800 (PST) 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 4B4C53F614; Tue, 4 Dec 2018 12:27:28 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 4 Dec 2018 20:26:45 +0000 Message-Id: <20181204202651.8836-12-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181204202651.8836-1-julien.grall@arm.com> References: <20181204202651.8836-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 11/17] 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, Tamas K Lengyel , Razvan Cojocaru 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 Acked-by: Razvan Cojocaru Reviewed-by: Stefano Stabellini --- Changes in v2: - Don't use _valid --- xen/arch/arm/mem_access.c | 6 +++--- xen/arch/arm/p2m.c | 18 ++++++++++++++---- xen/include/asm-arm/p2m.h | 3 ++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/mem_access.c b/xen/arch/arm/mem_access.c index f911937ccf..db49372a2c 100644 --- a/xen/arch/arm/mem_access.c +++ b/xen/arch/arm/mem_access.c @@ -71,7 +71,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; @@ -200,7 +200,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; @@ -406,7 +406,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 4e0ddbf70b..c713226561 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -298,10 +298,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; @@ -326,6 +330,9 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, *t = p2m_invalid; + if ( 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 */ @@ -371,6 +378,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: @@ -389,7 +399,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; @@ -1471,7 +1481,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++; /* @@ -1534,7 +1544,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 5858f97e9c..7c1d930b1d 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -213,7 +213,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.