From patchwork Mon Jun 3 16:03:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 165663 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4660406ili; Mon, 3 Jun 2019 09:05:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzg8lsFXedCrpq4U4ULcf+oWKG/4MAYY2slozbkQZs3vbgLxgre8Ab2kn11XCNdfIDenQfY X-Received: by 2002:a24:5587:: with SMTP id e129mr11648116itb.72.1559577927557; Mon, 03 Jun 2019 09:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559577927; cv=none; d=google.com; s=arc-20160816; b=wH3BxcM1P5N3CDvlewOUpYWH0cClJXnGQbgGWFo1ktHaX4fWW0iDJYwcfcH4wC/u3O QDxQX8Gs4zKcrf5B5zg39HNWHDyMR2JmhWXxGS0QGf9ndPM+XpnTkntNa4K+4P+xlN6w S+d9jwGtUxchjh2x+mOZCdNyiSPKe7d65LaAj6EGcN/G8hOMR5unlFIeBx96Uu71QlPl wYW1lDrxuCj2LAIiEdIJgI4Mwl14qjSSValXBFJZbVIlgSjI6XNCGwX7tx3on8f3mkQ6 6jYpmYljbmeuZRimEBrVAelg7nYXWlG1fu47HY89wlWIED6Svb77dxehfp377iXlDaFk Ka4Q== 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=I7IwnujisgWYWSOzFmKuY09E9KpX+s5A70so7G62MNY=; b=qdYqrPHMDG+SVTN0ahBcmkIrV0HjgxT/OE5Hd+AIE1GzJHqvHjPBrMeyIAeS05FF2c zNVmjtTq7DwF6I9GIGLPwv6Lb/j9MFO59VOd+D5ebWkuLSQ1b8UgJKrDqvfN10syFg4a ycAlZrLJOR1UElNnRIodZPLwjUk1IllNu/amRM2JDn7K4hPcEFQLzHqRGirZ2UgPVMVF IXF3flL+XuxvyENcVWv9evWg8IsiMCVVbwSG9ZLitYlxhEMxaSjiuR22xoy3jWYPngzj qIyOLINzy2Vr6W1T9hqwv32k9oBj/dbRHjesJqi7PfPXbGZAaGF5a9QUrhaqlAxNmchS A3hQ== 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 b1si2410380iog.90.2019.06.03.09.05.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jun 2019 09:05:27 -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 1hXpRL-0001tO-Kd; Mon, 03 Jun 2019 16:04:03 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRK-0001tE-Cx for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:02 +0000 X-Inumbo-ID: 336ebb00-8619-11e9-8980-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 336ebb00-8619-11e9-8980-bc764e045a96; Mon, 03 Jun 2019 16:04:00 +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 6274715AB; Mon, 3 Jun 2019 09:04:00 -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 DC5D33F246; Mon, 3 Jun 2019 09:03:58 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:37 +0100 Message-Id: <20190603160350.29806-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 01/14] xen/x86: Make mfn_to_gfn typesafe 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: Wei Liu , George Dunlap , Andrew Cooper , Tim Deegan , Julien Grall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" No functional changes intended. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich Acked-by: George Dunlap --- Changes in v3: - Remove gfn_x(...) for gfn used in parameter of __trace_var(...). Changes in v2: - Patch added --- xen/arch/x86/mm/p2m.c | 2 +- xen/arch/x86/mm/shadow/common.c | 31 ++++++++++++++++++------------- xen/arch/x86/mm/shadow/multi.c | 4 ++-- xen/include/asm-x86/p2m.h | 6 +++--- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 4c9954867c..279278715e 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -951,7 +951,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn, } if ( page_get_owner(mfn_to_page(mfn_add(mfn, i))) != d ) continue; - ogfn = _gfn(mfn_to_gfn(d, mfn_add(mfn, i))); + ogfn = mfn_to_gfn(d, mfn_add(mfn, i)); if ( !gfn_eq(ogfn, _gfn(INVALID_M2P_ENTRY)) && !gfn_eq(ogfn, gfn_add(gfn, i)) ) { diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/common.c index 795201dc82..1e67bd072a 100644 --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -474,7 +474,8 @@ static inline void trace_resync(int event, mfn_t gmfn) if ( tb_init_done ) { /* Convert gmfn to gfn */ - unsigned long gfn = mfn_to_gfn(current->domain, gmfn); + gfn_t gfn = mfn_to_gfn(current->domain, gmfn); + __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn); } } @@ -985,7 +986,8 @@ static inline void trace_shadow_prealloc_unpin(struct domain *d, mfn_t smfn) if ( tb_init_done ) { /* Convert smfn to gfn */ - unsigned long gfn; + gfn_t gfn; + ASSERT(mfn_valid(smfn)); gfn = mfn_to_gfn(d, backpointer(mfn_to_page(smfn))); __trace_var(TRC_SHADOW_PREALLOC_UNPIN, 0/*!tsc*/, sizeof(gfn), &gfn); @@ -1861,7 +1863,8 @@ static inline void trace_shadow_wrmap_bf(mfn_t gmfn) if ( tb_init_done ) { /* Convert gmfn to gfn */ - unsigned long gfn = mfn_to_gfn(current->domain, gmfn); + gfn_t gfn = mfn_to_gfn(current->domain, gmfn); + __trace_var(TRC_SHADOW_WRMAP_BF, 0/*!tsc*/, sizeof(gfn), &gfn); } } @@ -1946,7 +1949,7 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn, #if SHADOW_OPTIMIZATIONS & SHOPT_WRITABLE_HEURISTIC if ( curr->domain == d ) { - unsigned long gfn; + gfn_t gfn; /* Heuristic: there is likely to be only one writeable mapping, * and that mapping is likely to be in the current pagetable, * in the guest's linear map (on non-HIGHPTE linux and windows)*/ @@ -1969,8 +1972,9 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn, GUESS(0xC0000000UL + (fault_addr >> 10), 1); /* Linux lowmem: first 896MB is mapped 1-to-1 above 0xC0000000 */ - if ((gfn = mfn_to_gfn(d, gmfn)) < 0x38000 ) - GUESS(0xC0000000UL + (gfn << PAGE_SHIFT), 4); + gfn = mfn_to_gfn(d, gmfn); + if ( gfn_x(gfn) < 0x38000 ) + GUESS(0xC0000000UL + gfn_to_gaddr(gfn), 4); /* FreeBSD: Linear map at 0xBFC00000 */ if ( level == 1 ) @@ -1987,8 +1991,9 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn, } /* Linux lowmem: first 896MB is mapped 1-to-1 above 0xC0000000 */ - if ((gfn = mfn_to_gfn(d, gmfn)) < 0x38000 ) - GUESS(0xC0000000UL + (gfn << PAGE_SHIFT), 4); + gfn = mfn_to_gfn(d, gmfn); + if ( gfn_x(gfn) < 0x38000 ) + GUESS(0xC0000000UL + gfn_to_gaddr(gfn), 4); /* FreeBSD PAE: Linear map at 0xBF800000 */ switch ( level ) @@ -2016,15 +2021,15 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn, * had it at 0xffff810000000000, and older kernels yet had it * at 0x0000010000000000UL */ gfn = mfn_to_gfn(d, gmfn); - GUESS(0xffff880000000000UL + (gfn << PAGE_SHIFT), 4); - GUESS(0xffff810000000000UL + (gfn << PAGE_SHIFT), 4); - GUESS(0x0000010000000000UL + (gfn << PAGE_SHIFT), 4); + GUESS(0xffff880000000000UL + gfn_to_gaddr(gfn), 4); + GUESS(0xffff810000000000UL + gfn_to_gaddr(gfn), 4); + GUESS(0x0000010000000000UL + gfn_to_gaddr(gfn), 4); /* * 64bit Solaris kernel page map at * kpm_vbase; 0xfffffe0000000000UL */ - GUESS(0xfffffe0000000000UL + (gfn << PAGE_SHIFT), 4); + GUESS(0xfffffe0000000000UL + gfn_to_gaddr(gfn), 4); /* FreeBSD 64bit: linear map 0xffff800000000000 */ switch ( level ) @@ -2037,7 +2042,7 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn, + ((fault_addr & VADDR_MASK) >> 27), 6); break; } /* FreeBSD 64bit: direct map at 0xffffff0000000000 */ - GUESS(0xffffff0000000000 + (gfn << PAGE_SHIFT), 6); + GUESS(0xffffff0000000000 + gfn_to_gaddr(gfn), 6); } #undef GUESS diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index 5f8a745de2..74681ba85c 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -1076,7 +1076,7 @@ static inline void shadow_vram_get_l1e(shadow_l1e_t new_sl1e, || !mfn_valid(mfn) ) /* mfn can be invalid in mmio_direct */ return; - gfn = mfn_to_gfn(d, mfn); + gfn = gfn_x(mfn_to_gfn(d, mfn)); /* Page sharing not supported on shadow PTs */ BUG_ON(SHARED_M2P(gfn)); @@ -1107,7 +1107,7 @@ static inline void shadow_vram_put_l1e(shadow_l1e_t old_sl1e, || !mfn_valid(mfn) ) /* mfn can be invalid in mmio_direct */ return; - gfn = mfn_to_gfn(d, mfn); + gfn = gfn_x(mfn_to_gfn(d, mfn)); /* Page sharing not supported on shadow PTs */ BUG_ON(SHARED_M2P(gfn)); diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 09ef7e02fd..1a075547e2 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -506,12 +506,12 @@ static inline struct page_info *get_page_from_gfn( } /* General conversion function from mfn to gfn */ -static inline unsigned long mfn_to_gfn(const struct domain *d, mfn_t mfn) +static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn) { if ( paging_mode_translate(d) ) - return get_gpfn_from_mfn(mfn_x(mfn)); + return _gfn(get_gpfn_from_mfn(mfn_x(mfn))); else - return mfn_x(mfn); + return _gfn(mfn_x(mfn)); } #ifdef CONFIG_HVM