From patchwork Thu Jul 18 11:57:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 169200 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2304843ilk; Thu, 18 Jul 2019 04:59:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQxKu67P3FEWOB56JeJLuv/SoFgUhwOnfdMZ1G8CKpKgJX35bSwID3vZP9j54Z+jgT+buW X-Received: by 2002:a05:6602:1d2:: with SMTP id w18mr27345785iot.157.1563451143144; Thu, 18 Jul 2019 04:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563451143; cv=none; d=google.com; s=arc-20160816; b=A5jmoYMMaNNqkxHJTebA0E+zV+6Ch99AvPd4dxrJ5+mDwk7UGirvcKgIbfve5zJ7oy Fgr8M+NElUaaKtpb5Tk3pixwO9Pp1lRoxFET4j/TQajxQ3wVJCBjnKvCsVSOnfRVyVYP gDwUGwAdjv4We0r7sFxZSiTq/NcNYrvGkH8TgKiFhG7vqgzSECNYd848FcGrPo2JdsYO zvW6xZtcdFR3ppuscp3HCwADyKZtj1tNuQSpvHMS+U1HvFOkBB2p/EWr3sI5TMie26eF Zt2+NVHbHJPyhFfIEmDeZB2JWxrkJbw7pVK+eKj4nix6OxyJ6jj+htpzeTAJ9n6N5aGb 6OrA== 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:message-id:date:to:from; bh=C6EKNzkyZzuZUz7Hm+7ZZzL4WMo9aDhMDNYWduQWayg=; b=iNDEuziiwyzYUCgROm2afdwGRZml27Fkbm/N9QlVsm25++ZC/YlFrCnwEl47D5dGaJ iPqW0dIT36YEjY/7++vb3ZKlVkVG660gXXQV746a6eEQ0wWfTXS2CDTfXl799FZQdiJE +CtUsZHHaGlKJrpQoFDh7hr6Zm8RkyctdjQWohjUGcahmc9Wr2o9xMeuLo7BIDqrKFvj hfrU+5hU4GU9KWhw+Eg5b70skULRJ+ybNZuxKIBXS/98vQ9Y4KPowf3bNwkx3MCFmeXA oRM24yfqLY5PuScf8OxJPxQHqQi5C3OmgUP6ymb2d3guWbBur+BEbmVUP+ZPOsim/ZHP h2Wg== 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 p7si37574510iob.149.2019.07.18.04.59.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Jul 2019 04:59:03 -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 1ho52K-0000sw-Ir; Thu, 18 Jul 2019 11:57:24 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ho52I-0000sr-U9 for xen-devel@lists.xenproject.org; Thu, 18 Jul 2019 11:57:22 +0000 X-Inumbo-ID: 32af65e9-a953-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 32af65e9-a953-11e9-8980-bc764e045a96; Thu, 18 Jul 2019 11:57:20 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B133C2B; Thu, 18 Jul 2019 04:57: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 09A6B3F71A; Thu, 18 Jul 2019 04:57:19 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 18 Jul 2019 12:57:14 +0100 Message-Id: <20190718115714.634-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Subject: [Xen-devel] [PATCH] xen/arm64: Correctly compute the virtual address in maddr_to_virt() 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 , Stefano Stabellini , Volodymyr Babchuk MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The helper maddr_to_virt() is used to translate a machine address to a virtual address. To save some valuable address space, some part of the machine address may be compressed. In theory the PDX code is free to compress any bits so there are no guarantee the machine index computed will be always greater than xenheap_mfn_start. This would result to return a virtual address that is not part of the direct map and trigger a crash at least on debug-build later on because of the check in virt_to_page(). A recently reverted patch (see 1191156361 "xen/arm: fix mask calculation in pdx_init_mask") allows the PDX to compress more bits and triggered a crash on AMD Seattle Platform. Avoid the crash by keeping track of the base PDX for the xenheap and use it for computing the virtual address. Note that virt_to_maddr() does not need to have similar modification as it is using the hardware to translate the virtual address to a machine address. Take the opportunity to fix the ASSERT() as the direct map base address correspond to the start of the RAM (this is not always 0). Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- With that, the patch 1191156361 "xen/arm: fix mask calculation in pdx_init_mask" could be re-instated. --- xen/arch/arm/mm.c | 2 ++ xen/include/asm-arm/mm.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 44258ad89c..e1cdeaaf2f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -165,6 +165,7 @@ mfn_t xenheap_mfn_end __read_mostly; vaddr_t xenheap_virt_end __read_mostly; #ifdef CONFIG_ARM_64 vaddr_t xenheap_virt_start __read_mostly; +unsigned long xenheap_base_pdx __read_mostly; #endif unsigned long frametable_base_pdx __read_mostly; @@ -796,6 +797,7 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, if ( mfn_eq(xenheap_mfn_start, INVALID_MFN) ) { xenheap_mfn_start = _mfn(base_mfn); + xenheap_base_pdx = mfn_to_pdx(_mfn(base_mfn)); xenheap_virt_start = DIRECTMAP_VIRT_START + (base_mfn - mfn) * PAGE_SIZE; } diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 3dbc8a6469..d6b5544015 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -135,6 +135,7 @@ extern mfn_t xenheap_mfn_start, xenheap_mfn_end; extern vaddr_t xenheap_virt_end; #ifdef CONFIG_ARM_64 extern vaddr_t xenheap_virt_start; +extern unsigned long xenheap_base_pdx; #endif #ifdef CONFIG_ARM_32 @@ -253,9 +254,10 @@ static inline void *maddr_to_virt(paddr_t ma) #else static inline void *maddr_to_virt(paddr_t ma) { - ASSERT(mfn_to_pdx(maddr_to_mfn(ma)) < (DIRECTMAP_SIZE >> PAGE_SHIFT)); + ASSERT((mfn_to_pdx(maddr_to_mfn(ma)) - xenheap_base_pdx) < + (DIRECTMAP_SIZE >> PAGE_SHIFT)); return (void *)(XENHEAP_VIRT_START - - mfn_to_maddr(xenheap_mfn_start) + + (xenheap_base_pdx << PAGE_SHIFT) + ((ma & ma_va_bottom_mask) | ((ma & ma_top_mask) >> pfn_pdx_hole_shift))); }