From patchwork Tue Apr 3 15:32:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 132758 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp3954109ljb; Tue, 3 Apr 2018 08:35:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx49fogRhKShLV56kaOmGbo4J+rmBQEI9MvQILb86ff3LMRV20Z+SmdnlPoedTpZ/xjhilm6Z X-Received: by 10.107.167.21 with SMTP id q21mr13211703ioe.36.1522769716104; Tue, 03 Apr 2018 08:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522769716; cv=none; d=google.com; s=arc-20160816; b=qHnW5SYGU/2mPZWJAuso+VZTyoJ6wn2B2MSr5vNjoYMg/++EjrcCyAIJHxqyes0HMv l6tPtTcRbhdmf4gQcOQaRc9FdlypZwX0U4f8ElfywikrOSvODwMDWo5x+xdf8NRPvWFt ViDz558d8Y7qc4iWS6mrFplQq1pBy+fuoHSccqNfbAfwx4mN+/MZbDtLvj4O1wsi3gU2 C1FzvzPrwafi+WbL7Z8IHNXEj27Lvnjcp0qRj6flhY6KMZh8mo7I3VBYiPO/x+ndfR0v QInQSbwe6vaEfF0SaG1CmO/jZfWaGeMuvNReQ28oqtok6bprPqunYeSUT8hECARiQSMT VSzQ== 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 :arc-authentication-results; bh=XyJ5XtPZjscWrydLlzsXArzETWtyuFv8OZtQkSKP9TU=; b=cB3RwUKvZ4o6MzhX16fhg/oOGY0Hzk0oeaATSRhtRJ1E+JohcJ8ZgYf/QpvnhrEJKN kxL5C2AzSCkn6lRbVlnmTuV5g8k6KjvnCRZfx97BAxkbebppyvzaG8c3LF0knG4P0hSd JplIXOgMw1Vab6vxafp1B5V3tkbt6jDx+zUJIObYsLMXj/NPJ/IOswbr9vi14ajbMg0s GQZUgujbCggG3JXka4tF8ZxFJnNwsYfiJeNTMdUpJQvk2ii3TH7UjLsVWQ1+Jo7z/96B LPag53r6cl4h1QdFGAC6SxdDWxA4Is7R5RLM+4aut1qUkN6zbnrqGELj7OBU+Q8R1Cbu p9Yg== 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 z62si1997397iod.199.2018.04.03.08.35.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Apr 2018 08:35: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 1f3Nw6-00086w-EL; Tue, 03 Apr 2018 15:33:26 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1f3Nw5-00085N-6s for xen-devel@lists.xen.org; Tue, 03 Apr 2018 15:33:25 +0000 X-Inumbo-ID: 43855142-3754-11e8-9728-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 43855142-3754-11e8-9728-bc764e045a96; Tue, 03 Apr 2018 17:32:48 +0200 (CEST) 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 991D21435; Tue, 3 Apr 2018 08:33:23 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CF09F3F24A; Tue, 3 Apr 2018 08:33:21 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 3 Apr 2018 16:32:48 +0100 Message-Id: <20180403153251.19595-14-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180403153251.19595-1-julien.grall@arm.com> References: <20180403153251.19595-1-julien.grall@arm.com> Subject: [Xen-devel] [for-4.11][PATCH v7 13/16] xen/grant: Switch {create, replace}_grant_p2m_mapping to typesafe MFN 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: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The current prototype is slightly confusing because it takes a guest physical address and a machine physical frame (not address!). Switching to MFN will improve safety and reduce the chance to mistakenly invert the 2 parameters. Signed-off-by: Julien grall Reviewed-by: Wei Liu Reviewed-by: Jan Beulich Acked-by: Stefano Stabellini --- Cc: Stefano Stabellini Cc: Julien Grall Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Konrad Rzeszutek Wilk Cc: Tim Deegan Cc: Wei Liu Changes in v5: - Add Wei's and Jan's reviewed-by Changes in v4: - Patch added --- xen/arch/arm/mm.c | 10 +++++----- xen/arch/x86/hvm/grant_table.c | 14 +++++++------- xen/arch/x86/pv/grant_table.c | 10 +++++----- xen/common/grant_table.c | 8 ++++---- xen/include/asm-arm/grant_table.h | 9 ++++----- xen/include/asm-x86/grant_table.h | 4 ++-- xen/include/asm-x86/hvm/grant_table.h | 8 ++++---- xen/include/asm-x86/pv/grant_table.h | 8 ++++---- 8 files changed, 35 insertions(+), 36 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7af6baa3d6..49080ca0ac 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1418,7 +1418,7 @@ void gnttab_mark_dirty(struct domain *d, unsigned long l) } } -int create_grant_host_mapping(unsigned long addr, unsigned long frame, +int create_grant_host_mapping(unsigned long addr, mfn_t frame, unsigned int flags, unsigned int cache_flags) { int rc; @@ -1431,7 +1431,7 @@ int create_grant_host_mapping(unsigned long addr, unsigned long frame, t = p2m_grant_map_ro; rc = guest_physmap_add_entry(current->domain, gaddr_to_gfn(addr), - _mfn(frame), 0, t); + frame, 0, t); if ( rc ) return GNTST_general_error; @@ -1439,8 +1439,8 @@ int create_grant_host_mapping(unsigned long addr, unsigned long frame, return GNTST_okay; } -int replace_grant_host_mapping(unsigned long addr, unsigned long mfn, - unsigned long new_addr, unsigned int flags) +int replace_grant_host_mapping(unsigned long addr, mfn_t mfn, + unsigned long new_addr, unsigned int flags) { gfn_t gfn = gaddr_to_gfn(addr); struct domain *d = current->domain; @@ -1449,7 +1449,7 @@ int replace_grant_host_mapping(unsigned long addr, unsigned long mfn, if ( new_addr != 0 || (flags & GNTMAP_contains_pte) ) return GNTST_general_error; - rc = guest_physmap_remove_page(d, gfn, _mfn(mfn), 0); + rc = guest_physmap_remove_page(d, gfn, mfn, 0); return rc ? GNTST_general_error : GNTST_okay; } diff --git a/xen/arch/x86/hvm/grant_table.c b/xen/arch/x86/hvm/grant_table.c index 9ca9fe0425..ecd7d078ab 100644 --- a/xen/arch/x86/hvm/grant_table.c +++ b/xen/arch/x86/hvm/grant_table.c @@ -25,7 +25,7 @@ #include -int create_grant_p2m_mapping(uint64_t addr, unsigned long frame, +int create_grant_p2m_mapping(uint64_t addr, mfn_t frame, unsigned int flags, unsigned int cache_flags) { @@ -41,14 +41,14 @@ int create_grant_p2m_mapping(uint64_t addr, unsigned long frame, p2mt = p2m_grant_map_rw; rc = guest_physmap_add_entry(current->domain, _gfn(addr >> PAGE_SHIFT), - _mfn(frame), PAGE_ORDER_4K, p2mt); + frame, PAGE_ORDER_4K, p2mt); if ( rc ) return GNTST_general_error; else return GNTST_okay; } -int replace_grant_p2m_mapping(uint64_t addr, unsigned long frame, +int replace_grant_p2m_mapping(uint64_t addr, mfn_t frame, uint64_t new_addr, unsigned int flags) { unsigned long gfn = (unsigned long)(addr >> PAGE_SHIFT); @@ -60,15 +60,15 @@ int replace_grant_p2m_mapping(uint64_t addr, unsigned long frame, return GNTST_general_error; old_mfn = get_gfn(d, gfn, &type); - if ( !p2m_is_grant(type) || mfn_x(old_mfn) != frame ) + if ( !p2m_is_grant(type) || !mfn_eq(old_mfn, frame) ) { put_gfn(d, gfn); gdprintk(XENLOG_WARNING, - "old mapping invalid (type %d, mfn %" PRI_mfn ", frame %lx)\n", - type, mfn_x(old_mfn), frame); + "old mapping invalid (type %d, mfn %" PRI_mfn ", frame %"PRI_mfn")\n", + type, mfn_x(old_mfn), mfn_x(frame)); return GNTST_general_error; } - if ( guest_physmap_remove_page(d, _gfn(gfn), _mfn(frame), PAGE_ORDER_4K) ) + if ( guest_physmap_remove_page(d, _gfn(gfn), frame, PAGE_ORDER_4K) ) { put_gfn(d, gfn); return GNTST_general_error; diff --git a/xen/arch/x86/pv/grant_table.c b/xen/arch/x86/pv/grant_table.c index 4dbc550366..458085e1b6 100644 --- a/xen/arch/x86/pv/grant_table.c +++ b/xen/arch/x86/pv/grant_table.c @@ -50,7 +50,7 @@ static unsigned int grant_to_pte_flags(unsigned int grant_flags, return pte_flags; } -int create_grant_pv_mapping(uint64_t addr, unsigned long frame, +int create_grant_pv_mapping(uint64_t addr, mfn_t frame, unsigned int flags, unsigned int cache_flags) { struct vcpu *curr = current; @@ -60,7 +60,7 @@ int create_grant_pv_mapping(uint64_t addr, unsigned long frame, mfn_t gl1mfn; int rc = GNTST_general_error; - nl1e = l1e_from_pfn(frame, grant_to_pte_flags(flags, cache_flags)); + nl1e = l1e_from_mfn(frame, grant_to_pte_flags(flags, cache_flags)); nl1e = adjust_guest_l1e(nl1e, currd); /* @@ -192,7 +192,7 @@ static bool steal_linear_address(unsigned long linear, l1_pgentry_t *out) * new_addr has only ever been available via GNTABOP_unmap_and_replace, and * only when !(flags & GNTMAP_contains_pte). */ -int replace_grant_pv_mapping(uint64_t addr, unsigned long frame, +int replace_grant_pv_mapping(uint64_t addr, mfn_t frame, uint64_t new_addr, unsigned int flags) { struct vcpu *curr = current; @@ -282,14 +282,14 @@ int replace_grant_pv_mapping(uint64_t addr, unsigned long frame, * Check that the address supplied is actually mapped to frame (with * appropriate permissions). */ - if ( unlikely(l1e_get_pfn(ol1e) != frame) || + if ( unlikely(!mfn_eq(l1e_get_mfn(ol1e), frame)) || unlikely((l1e_get_flags(ol1e) ^ grant_pte_flags) & (_PAGE_PRESENT | _PAGE_RW)) ) { gdprintk(XENLOG_ERR, "PTE %"PRIpte" for %"PRIx64" doesn't match grant (%"PRIpte")\n", l1e_get_intpte(ol1e), addr, - l1e_get_intpte(l1e_from_pfn(frame, grant_pte_flags))); + l1e_get_intpte(l1e_from_mfn(frame, grant_pte_flags))); goto out_unlock; } diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 18201912e4..f9e3d1bb95 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1071,7 +1071,7 @@ map_grant_ref( if ( op->flags & GNTMAP_host_map ) { - rc = create_grant_host_mapping(op->host_addr, frame, op->flags, + rc = create_grant_host_mapping(op->host_addr, _mfn(frame), op->flags, cache_flags); if ( rc != GNTST_okay ) goto undo_out; @@ -1111,7 +1111,7 @@ map_grant_ref( typecnt++; } - rc = create_grant_host_mapping(op->host_addr, frame, op->flags, 0); + rc = create_grant_host_mapping(op->host_addr, _mfn(frame), op->flags, 0); if ( rc != GNTST_okay ) goto undo_out; @@ -1188,7 +1188,7 @@ map_grant_ref( undo_out: if ( host_map_created ) { - replace_grant_host_mapping(op->host_addr, frame, 0, op->flags); + replace_grant_host_mapping(op->host_addr, _mfn(frame), 0, op->flags); gnttab_flush_tlb(ld); } @@ -1374,7 +1374,7 @@ unmap_common( if ( op->host_addr && (flags & GNTMAP_host_map) ) { if ( (rc = replace_grant_host_mapping(op->host_addr, - op->frame, op->new_addr, + _mfn(op->frame), op->new_addr, flags)) < 0 ) goto act_release_out; diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h index d2027d26b2..24644084a1 100644 --- a/xen/include/asm-arm/grant_table.h +++ b/xen/include/asm-arm/grant_table.h @@ -14,12 +14,11 @@ struct grant_table_arch { }; void gnttab_clear_flag(unsigned long nr, uint16_t *addr); -int create_grant_host_mapping(unsigned long gpaddr, - unsigned long mfn, unsigned int flags, unsigned int - cache_flags); +int create_grant_host_mapping(unsigned long gpaddr, mfn_t mfn, + unsigned int flags, unsigned int cache_flags); #define gnttab_host_mapping_get_page_type(ro, ld, rd) (0) -int replace_grant_host_mapping(unsigned long gpaddr, unsigned long mfn, - unsigned long new_gpaddr, unsigned int flags); +int replace_grant_host_mapping(unsigned long gpaddr, mfn_t mfn, + unsigned long new_gpaddr, unsigned int flags); void gnttab_mark_dirty(struct domain *d, unsigned long l); #define gnttab_create_status_page(d, t, i) do {} while (0) #define gnttab_release_host_mappings(domain) 1 diff --git a/xen/include/asm-x86/grant_table.h b/xen/include/asm-x86/grant_table.h index 4ac0b9b4c7..fc07291ff2 100644 --- a/xen/include/asm-x86/grant_table.h +++ b/xen/include/asm-x86/grant_table.h @@ -21,7 +21,7 @@ struct grant_table_arch { * Caller must own caller's BIGLOCK, is responsible for flushing the TLB, and * must hold a reference to the page. */ -static inline int create_grant_host_mapping(uint64_t addr, unsigned long frame, +static inline int create_grant_host_mapping(uint64_t addr, mfn_t frame, unsigned int flags, unsigned int cache_flags) { @@ -30,7 +30,7 @@ static inline int create_grant_host_mapping(uint64_t addr, unsigned long frame, return create_grant_pv_mapping(addr, frame, flags, cache_flags); } -static inline int replace_grant_host_mapping(uint64_t addr, unsigned long frame, +static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame, uint64_t new_addr, unsigned int flags) { diff --git a/xen/include/asm-x86/hvm/grant_table.h b/xen/include/asm-x86/hvm/grant_table.h index 711ce9b560..a5612585b3 100644 --- a/xen/include/asm-x86/hvm/grant_table.h +++ b/xen/include/asm-x86/hvm/grant_table.h @@ -23,24 +23,24 @@ #ifdef CONFIG_HVM -int create_grant_p2m_mapping(uint64_t addr, unsigned long frame, +int create_grant_p2m_mapping(uint64_t addr, mfn_t frame, unsigned int flags, unsigned int cache_flags); -int replace_grant_p2m_mapping(uint64_t addr, unsigned long frame, +int replace_grant_p2m_mapping(uint64_t addr, mfn_t frame, uint64_t new_addr, unsigned int flags); #else #include -static inline int create_grant_p2m_mapping(uint64_t addr, unsigned long frame, +static inline int create_grant_p2m_mapping(uint64_t addr, mfn_t frame, unsigned int flags, unsigned int cache_flags) { return GNTST_general_error; } -static inline int replace_grant_p2m_mapping(uint64_t addr, unsigned long frame, +static inline int replace_grant_p2m_mapping(uint64_t addr, mfn_t frame, uint64_t new_addr, unsigned int flags) { return GNTST_general_error; diff --git a/xen/include/asm-x86/pv/grant_table.h b/xen/include/asm-x86/pv/grant_table.h index 556e68f0eb..85442b6074 100644 --- a/xen/include/asm-x86/pv/grant_table.h +++ b/xen/include/asm-x86/pv/grant_table.h @@ -23,23 +23,23 @@ #ifdef CONFIG_PV -int create_grant_pv_mapping(uint64_t addr, unsigned long frame, +int create_grant_pv_mapping(uint64_t addr, mfn_t frame, unsigned int flags, unsigned int cache_flags); -int replace_grant_pv_mapping(uint64_t addr, unsigned long frame, +int replace_grant_pv_mapping(uint64_t addr, mfn_t frame, uint64_t new_addr, unsigned int flags); #else #include -static inline int create_grant_pv_mapping(uint64_t addr, unsigned long frame, +static inline int create_grant_pv_mapping(uint64_t addr, mfn_t frame, unsigned int flags, unsigned int cache_flags) { return GNTST_general_error; } -static inline int replace_grant_pv_mapping(uint64_t addr, unsigned long frame, +static inline int replace_grant_pv_mapping(uint64_t addr, mfn_t frame, uint64_t new_addr, unsigned int flags) { return GNTST_general_error;