From patchwork Tue May 7 15:14:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 163545 Delivered-To: patch@linaro.org Received: by 2002:ac9:2a84:0:0:0:0:0 with SMTP id p4csp3883300oca; Tue, 7 May 2019 08:16:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbePCBUHJ0uncXrshIwzySoouT2fAzVwbVXKGOIpvnZJmVToMGOaNam9Gp1fiWt+XMmCoV X-Received: by 2002:a24:2855:: with SMTP id h82mr21849102ith.82.1557242217727; Tue, 07 May 2019 08:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557242217; cv=none; d=google.com; s=arc-20160816; b=ToS8YbYKBhjY9Uevy0pUx9jT7Y/ehwAWdQl2QXchbA9vyHyKA0r2e0kN+Ci9D+cY5E /JD5Ga4t3Rj5Ex5r73+SCnEzSTOpS5o1OSt+sVvZyjKCnJ/PEUVSIwt0Njlf9fN4Yc4c RUNZXnyisZldl6XlUj2fzMARfHVABhIrLGgHklcdS4YjV2uZ/uy59KC3ZCriZ8Pcl+2M EIak42jlKxDHTfWPJVcV2k9/ewXi7RlEiGYsOUPEwb0Y5arzVEnd+2dMrsJZzjhrC23X yUoSy/PU5FvQiyiYYxRZwCe7eQzNOw/DYqC7WJbfMGg/aEsefOk46NXheVd3qHt+LncH tDqQ== 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=hbhu0YohWONiIdqNjjwb9jC9809YnzZVx3Mwl7Zxu28=; b=w+IdAF+peSdDljh99AAB+NYo2P2Uy/hggG26M+XT2FiiFuqvPqPBGMDPvfId/jeuYd ela4vB6B2bWmjUTfZmpXk7wIQl0/PoiJd+XG6cIEw1hgs4YroKRnA/VA56/PlHIXpthN GIt1EhuokwSJaf3dUr6RVX3ULTGyts5Bx7Ik2Z1C6A+FrQniOZyjLefhXGyBdtDwl9Es Xi37iqgaTNzlPZTSzVuyxbSG/se2iUfw/Ww2IHisP+MTp887CmAq3vXvAoP0w/EfpdJP RF8zFbOwDuz3SM8EdvIUYqHqLxmmp9CYiVs6u2qB+9hLLdb81Gmv7Lrs1F9WDhz96/nf UWEw== 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 k1si9026564ios.153.2019.05.07.08.16.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 May 2019 08:16:57 -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 1hO1oc-0007Vq-I2; Tue, 07 May 2019 15:15:34 +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 1hO1ob-0007UV-5f for xen-devel@lists.xenproject.org; Tue, 07 May 2019 15:15:33 +0000 X-Inumbo-ID: f4392e90-70da-11e9-82a8-5b2083d4bc8e Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id f4392e90-70da-11e9-82a8-5b2083d4bc8e; Tue, 07 May 2019 15:15:31 +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 35F4F15AD; Tue, 7 May 2019 08:15:31 -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 025F63F5AF; Tue, 7 May 2019 08:15:29 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 7 May 2019 16:14:55 +0100 Message-Id: <20190507151458.29350-12-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190507151458.29350-1-julien.grall@arm.com> References: <20190507151458.29350-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 11/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function 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: Andrew Cooper , Julien Grall , Wei Liu , 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" set_gpfn_from_mfn() is currently implement in a 2 part macros. The second macro is only called within the first macro, so they can be folded together. Furthermore, this is now converted to a static inline making the code more readable and safer. As set_gpfn_from_mfn is now a static inline function, the extern variable dom_cow should be defined earlier on. For convenience, the definition of all dom_* variables are moved earlier on. Signed-off-by: Julien Grall --- Changes in v2: - Patch added --- xen/include/asm-x86/mm.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 717378730b..4721725c60 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -442,6 +442,8 @@ int check_descriptor(const struct domain *d, seg_desc_t *desc); extern paddr_t mem_hotplug; +extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ + /****************************************************************************** * With shadow pagetables, the different kinds of address start * to get get confusing. @@ -483,24 +485,25 @@ extern paddr_t mem_hotplug; #define SHARED_M2P(_e) ((_e) == SHARED_M2P_ENTRY) #define compat_machine_to_phys_mapping ((unsigned int *)RDWR_COMPAT_MPT_VIRT_START) -#define _set_gpfn_from_mfn(mfn, pfn) ({ \ - struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn))); \ - unsigned long entry = (d && (d == dom_cow)) ? \ - SHARED_M2P_ENTRY : (pfn); \ - ((void)((mfn) >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 || \ - (compat_machine_to_phys_mapping[(mfn)] = (unsigned int)(entry))), \ - machine_to_phys_mapping[(mfn)] = (entry)); \ - }) /* * Disable some users of set_gpfn_from_mfn() (e.g., free_heap_pages()) until * the machine_to_phys_mapping is actually set up. */ extern bool machine_to_phys_mapping_valid; -#define set_gpfn_from_mfn(mfn, pfn) do { \ - if ( machine_to_phys_mapping_valid ) \ - _set_gpfn_from_mfn(mfn, pfn); \ -} while (0) + +static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn) +{ + struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn))); + unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn; + + if (!machine_to_phys_mapping_valid) + return; + + if ( mfn >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 ) + compat_machine_to_phys_mapping[mfn] = entry; + machine_to_phys_mapping[mfn] = entry; +} extern struct rangeset *mmio_ro_ranges; @@ -592,8 +595,6 @@ unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits); unsigned long domain_get_maximum_gpfn(struct domain *d); -extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ - /* Definition of an mm lock: spinlock with extra fields for debugging */ typedef struct mm_lock { spinlock_t lock;