From patchwork Mon Jun 3 16:03:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 165671 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4660782ili; Mon, 3 Jun 2019 09:05:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGzvg88YqJqXqZnetY+SEZ3By140YD7IarnlYkDNaOyNJkcoaxz0RfRaQpTzY/TtmGsELR X-Received: by 2002:a05:660c:602:: with SMTP id i2mr18276430itk.25.1559577939628; Mon, 03 Jun 2019 09:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559577939; cv=none; d=google.com; s=arc-20160816; b=frx6fPOBmOAPYexNEU5YMwpClejCYQZF4pfK43C1J5Cxev9etKtpSVQunrOinkrGnr QksAaxszHOZfl1/1z3yFWOR2/ne3yRNKjRphsDKP2os5tDASRy/pGBXq3GdbCFMpMFUg +c1UZQ/dzE58veCpVeZZuCMKe/4OaXHsKj8JEB3VjW68C8n2pRlzgxzZzcLL2TbVykOy 6JSM14ICnUE3Es3GR8RtxIpaddig6uH5Bnjj1rc4wNAYXr8VIIW/dR+CecdPAZiS5G8T Pkkf4kxyoOxgbefcdycI6aAGzqzcFiqFxFhuB2ZL0W7v082JvHk10PiDUovMLd1/5hIM IVFg== 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=x66YXEVOIcYvY2UITycn9C0LDz/k+UOiu+j3wTMr+jY=; b=ioE+k2bh/h/WSGDlbzUKRQ0Z/ubYCeHL6UcUnHBB7U/aWUgwK0qpCx1o0P+IssD2OV zk9QGdT/kadmWPaLRWOh3ViwbvcOLjxOM6TmhUzSvaEFE6vJYG44oFAHDB1qtgLINde7 9smj4P5//6qpJRVKHt2qoGA5xm+JuhWBE7ctMXjjpUIZs36kF5pQ73DkW+0v7a6CJBR6 Rw4/VTiMJb+Cpb10BCvqK2fuqvuFh+RLiJPKtwDmt8TSxmkyvOGQFKeiBm9HuG5Sdvob mOLoZTV86T4vgXfBGSWWOI9e8bpC/d525w1dQDhqFuwZB3DcMeR0ZxHq3kbquUyTefH1 Fvog== 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 y26si10291687jak.4.2019.06.03.09.05.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jun 2019 09:05:39 -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 1hXpRb-00025f-SM; Mon, 03 Jun 2019 16:04:19 +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 1hXpRa-00023a-6c for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:18 +0000 X-Inumbo-ID: 3d3ae388-8619-11e9-8d3d-37e54aa2a50d Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3d3ae388-8619-11e9-8d3d-37e54aa2a50d; Mon, 03 Jun 2019 16:04:17 +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 E47A015AB; Mon, 3 Jun 2019 09:04:16 -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 B187C3F246; Mon, 3 Jun 2019 09:04:15 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:45 +0100 Message-Id: <20190603160350.29806-10-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 09/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 Reviewed-by: Jan Beulich --- Changes in v3: - Add missing blank - Fix condition 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 bf90916077..dcae558764 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; @@ -590,8 +593,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;