From patchwork Sun Mar 22 16:14:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 11451901 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 82F9C17D4 for ; Sun, 22 Mar 2020 16:16:25 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6986320724 for ; Sun, 22 Mar 2020 16:16:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6986320724 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass 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 1jG3FY-0004pn-Ae; Sun, 22 Mar 2020 16:14:56 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jG3FX-0004oq-Fx for xen-devel@lists.xenproject.org; Sun, 22 Mar 2020 16:14:55 +0000 X-Inumbo-ID: 3b2d69e6-6c58-11ea-b34e-bc764e2007e4 Received: from mail-ed1-f65.google.com (unknown [209.85.208.65]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3b2d69e6-6c58-11ea-b34e-bc764e2007e4; Sun, 22 Mar 2020 16:14:39 +0000 (UTC) Received: by mail-ed1-f65.google.com with SMTP id z65so13537431ede.0 for ; Sun, 22 Mar 2020 09:14:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=klK9FdE2K1lUNI+mLYUEqRnbc1iAOenHTFOoesGJIXc=; b=bnY3Mp3NCu8lRY4LGX0L31v31DBOnTr+m4DsfJxqr2bKryyG57nZ43jLaiclNSGM90 gXhtKja6NQF/6F6694TpEfIISOjLTcWUVRuxul/JWUCTmaeATVxczQggEHlH5Of6+Fsv fQOXdvecnD0DQwNvoOa7CW75IMcxgQeh/zOy4UYKYCkt2GI6WHyqQjPk77n9b7SAeDcU B8U5NPI/3YwCTH8n1AjdzXXZqcfQs4qvgnTj0bothvE+7wIqhf74ev/4u2HACiCoFMet Bi2Am0Egfn4rI5JpRVcer2vwaObRQOZOj87KMxpt3+o00kuAJDzmXJeSuyjbK/wnSlV8 kDsg== X-Gm-Message-State: ANhLgQ2EYWwNrtr7F3E6uXw0PFawSxli7BdLjg0kr/wV+awyoUynZg4B c8sCtvkKZlNIkIKnDfcKNu93cEprCzhebA== X-Google-Smtp-Source: ADFU+vuUpOX1gSnROav2FUOZMUb+kId6Pc0sBLXjVopEjrCPInAdWcNh/jQ+8rbjIHyOA9qDj3UleA== X-Received: by 2002:a17:906:32d8:: with SMTP id k24mr92782ejk.2.1584893678743; Sun, 22 Mar 2020 09:14:38 -0700 (PDT) Received: from ufe34d9ed68d054.ant.amazon.com (54-240-197-235.amazon.com. [54.240.197.235]) by smtp.gmail.com with ESMTPSA id v13sm106693edj.62.2020.03.22.09.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2020 09:14:38 -0700 (PDT) From: julien@xen.org To: xen-devel@lists.xenproject.org Date: Sun, 22 Mar 2020 16:14:15 +0000 Message-Id: <20200322161418.31606-15-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200322161418.31606-1-julien@xen.org> References: <20200322161418.31606-1-julien@xen.org> Subject: [Xen-devel] [PATCH 14/17] 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: julien@xen.org, Wei Liu , Andrew Cooper , 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" From: Julien Grall 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. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich --- This was originally sent as part of "xen/arm: Properly disable M2P on Arm" [1]. Changes since the original version: - Remove the paragraph in the comment about dom_* as we don't need to move them anymore. - Constify 'd' as it is never modified within the function [1] <20190603160350.29806-1-julien.grall@arm.com> --- xen/include/asm-x86/mm.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 83058fb8d1..53f2ed7c7d 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -493,24 +493,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) +{ + const 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;