From patchwork Mon Oct 8 18:33:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 148426 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp3982071lji; Mon, 8 Oct 2018 11:36:16 -0700 (PDT) X-Google-Smtp-Source: ACcGV63XHX4lZnDuQDojv/1yq8ea/DkTn/D3V8bU82P3II73zesIP9idTGjoCmnbgG+9flLI2XUj X-Received: by 2002:a6b:c085:: with SMTP id q127-v6mr15992379iof.255.1539023776378; Mon, 08 Oct 2018 11:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539023776; cv=none; d=google.com; s=arc-20160816; b=JiPuEvPrQO84NLBUSOCHQ55PzN4SSWgyuq41Yi7VBGcvQ6oeSZvRYZp8pBm05Q4S7F +E7Sr7Y8iQ48OdfHffR4ij1+wCTDRGywUq69/TFucI2igzBckb50JsUPbQRKMdvfrUvR MhHzvOfJcYdaTZnanC26JruUsZYTH1kC6oYy/iIF+RsIopkEnbzSLG9pG0JK35CA0REv DoFhpqS9XrgbOu5z7U9MEjduL/L1CS3Km5J+hU3FHk5EGEwYlnDpceIH8jGNVWno8pBa Qxmtjkyg9ctMOpbZ/vn5c63o0OLfBhVNnn+6y9MqES5mA3KF24o5iGi2du3aIOfzhg3U 8sdw== 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=0JFENIUQeQwMjFdJPynNiFis7jZN8IA6Ps5BA1mQ+JU=; b=JG6/WvyGIaahy+sGzYWYcAbNeGQ3hiEtqTBMkrV+2ziPGiUdBJIibtHMBOV4RWe6G0 Oned0S2PdHctMppt3XQpjr4vaHfo5GbsGRJ8XkwBkxA6I4WcuLK4uejrXcO/tq2QLmMi 2yhhZTo4BuFeT7oG9+Mu+G+b22sEBugWAtioSihbZvhO6mfWJaEk+H2zsWWP89B25yyz z/80lpfeDAcvuWdBGpBDUa0D1QVg/iC5jtRbxZU8qfkcMQDI8nD82rJ+7pvK5QMtB8OA X/JSyUfCCK77Ig88+7e9SqWuTdLQJoi6dHUxy45gJfNGILcsYIuPgEHF1rpiGufEPfn7 e4kA== 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 g10-v6si11820236ioa.38.2018.10.08.11.36.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Oct 2018 11:36:16 -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 1g9aM9-0005hj-8V; Mon, 08 Oct 2018 18:34:13 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1g9aM7-0005fi-9U for xen-devel@lists.xen.org; Mon, 08 Oct 2018 18:34:11 +0000 X-Inumbo-ID: ed1f928e-cb28-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id ed1f928e-cb28-11e8-a6a9-d7ebe60f679a; Mon, 08 Oct 2018 18:35:27 +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 55FE91596; Mon, 8 Oct 2018 11:34:10 -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 6C04C3F5B3; Mon, 8 Oct 2018 11:34:09 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 8 Oct 2018 19:33:44 +0100 Message-Id: <20181008183352.16291-9-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 08/16] xen/arm: p2m: Handle translation fault in get_page_from_gva 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" A follow-up patch will re-purpose the valid bit of LPAE entries to generate fault even on entry containing valid information. This means that when translation a guest VA to guest PA (e.g IPA) will fail if the Stage-2 entries used have the valid bit unset. Because of that, we need to fallback to walk the page-table in software to check whether the fault was expected. This patch adds the software page-table walk on all the translation fault. It would be possible in the future to avoid pointless walk when the fault in PAR_EL1 is not a translation fault. Signed-off-by: Julien Grall --- There are a couple of TODO in the code. They are clean-up and performance improvement (e.g when the fault cannot be handled) that could be delayed after the series has been merged. --- xen/arch/arm/p2m.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 2a1e7e9be2..ec956bc151 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -1438,6 +1439,8 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, struct page_info *page = NULL; paddr_t maddr = 0; uint64_t par; + mfn_t mfn; + p2m_type_t t; /* * XXX: To support a different vCPU, we would need to load the @@ -1454,8 +1457,30 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, par = gvirt_to_maddr(va, &maddr, flags); p2m_read_unlock(p2m); + /* + * gvirt_to_maddr may fail if the entry does not have the valid bit + * set. Fallback + * to the second method: + * 1) Translate the VA to IPA using software lookup -> Stage-1 page-table + * may not be accessible because the stage-2 entries may have valid + * bit unset. + * 2) Software lookup of the MFN + * + * Note that when memaccess is enabled, we instead all directly + * p2m_mem_access_check_and_get_page(...). Because the function is a + * a variant of the methods described above, it will be able to + * handle entry with valid bit unset. + * + * TODO: Integrate more nicely memaccess with the rest of the + * function. + * TODO: Use the fault error in PAR_EL1 to avoid pointless + * translation. + */ if ( par ) { + paddr_t ipa; + unsigned int perms; + /* * When memaccess is enabled, the translation GVA to MADDR may * have failed because of a permission fault. @@ -1463,20 +1488,46 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, if ( p2m->mem_access_enabled ) return p2m_mem_access_check_and_get_page(va, flags, v); - dprintk(XENLOG_G_DEBUG, - "%pv: gvirt_to_maddr failed va=%#"PRIvaddr" flags=0x%lx par=%#"PRIx64"\n", - v, va, flags, par); - return NULL; + /* + * The software stage-1 table walk can still fail, e.g, if the + * GVA is not mapped. + */ + if ( !guest_walk_tables(v, va, &ipa, &perms) ) + { + dprintk(XENLOG_G_DEBUG, "%pv: Failed to walk page-table va %#"PRIvaddr"\n", v, va); + return NULL; + } + + /* + * Check permission that are assumed by the caller. For instance + * in case of guestcopy, the caller assumes that the translated + * page can be accessed with the requested permissions. If this + * is not the case, we should fail. + * + * Please note that we do not check for the GV2M_EXEC + * permission. This is fine because the hardware-based translation + * instruction does not test for execute permissions. + */ + if ( (flags & GV2M_WRITE) && !(perms & GV2M_WRITE) ) + return NULL; + + mfn = p2m_lookup(d, gaddr_to_gfn(ipa), &t); + if ( mfn_eq(INVALID_MFN, mfn) ) + return NULL; + + /* We consider that RAM is always mapped read-write */ } + else + mfn = maddr_to_mfn(maddr); - if ( !mfn_valid(maddr_to_mfn(maddr)) ) + if ( !mfn_valid(mfn) ) { dprintk(XENLOG_G_DEBUG, "%pv: Invalid MFN %#"PRI_mfn"\n", - v, mfn_x(maddr_to_mfn(maddr))); + v, mfn_x(mfn)); return NULL; } - page = mfn_to_page(maddr_to_mfn(maddr)); + page = mfn_to_page(mfn); ASSERT(page); if ( unlikely(!get_page(page, d)) )