From patchwork Wed Mar 21 04:47:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 132183 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1696581ljb; Tue, 20 Mar 2018 21:50:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELtTlZqr2nB06xzanrR6HPgd55U4sNox90p+fBDKoeEFeg30pcWgmM5sbbNQF8mThXxNhucu X-Received: by 10.107.155.148 with SMTP id d142mr18034510ioe.163.1521607820585; Tue, 20 Mar 2018 21:50:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521607820; cv=none; d=google.com; s=arc-20160816; b=vKCu8Bn5+ewVGxpYFDYg/B3JilM9v1s17kAnqQojDOQVc3ss9OTtVV8IiDsCsiiXMW 8rueUS/gG2yRP/Huo5W5P52IjRumPAIYhY1yNd3w48picnA/JaZ8I12Ru0LdPr3lBF4j RDljmUGSKeVFKV+alRcZJR3MktILblWhgsf+QxcBj0yGhKsYjLulQCSS3snrX0gwcDc/ Jy0XaLxEjLXRqgqSkXgB+ugVS/hiXQh2KUzifCakXV57LCZLDF6z+9t+yrtz7vuGgoN0 KpOdm36BgFGv6+StDUWx0Tgf0AZ6+uhlxDhmoGVbi+7QIvDTshZpdvOiGoL3LHUqrBcy lU5w== 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=KnHSVY9Itvyj86XXj4O49elFQeY0lWP9NWoBJ1L5D/0=; b=d1q1RaB/cuuL4ZQV17ymj4idJFFKC4G/ApcomZowX8BlRLjGtNr4rsPOMedLahLCo0 rdMX5p88EkWgzu4o2CP8cMTEK8fOoZ8VSquRUXi0TwZ0kqPOFTt7ATPPRRj+ULr1JPqT 9lvtINA4m6cwch7X7BkzQMyfuxOXut9EzhhTQntfrDfmkAlADsiiy01qFS4zoKIG0i6M yRApf+LIUtrNUzwtqlqqILAnbKkRYmdahN2UqbuW7gi8gudh6lOIvqFHzli3tmK6X29o ZpbeUhcWQ10hfcHgYfn/VqYnXkYy0xKV2zThxCilv2KPmLl3rNozGC4Zr+O3+Q3uKCH9 RZZg== 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 x13-v6si2522700iti.117.2018.03.20.21.50.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Mar 2018 21:50:20 -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 1eyVfg-00073e-4t; Wed, 21 Mar 2018 04:48:20 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1eyVfe-00071u-3k for xen-devel@lists.xen.org; Wed, 21 Mar 2018 04:48:18 +0000 X-Inumbo-ID: 09e7cb67-2cc3-11e8-9728-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 09e7cb67-2cc3-11e8-9728-bc764e045a96; Wed, 21 Mar 2018 05:48:03 +0100 (CET) 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 DE81280D; Tue, 20 Mar 2018 21:48:16 -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 006983F487; Tue, 20 Mar 2018 21:48:15 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 21 Mar 2018 04:47:36 +0000 Message-Id: <20180321044737.20794-16-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180321044737.20794-1-julien.grall@arm.com> References: <20180321044737.20794-1-julien.grall@arm.com> Subject: [Xen-devel] [for-4.11][PATCH v6 15/16] xen/x86: Switch mfn_to_page in x86_64/mm.c to use 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: Andrew Cooper , Julien Grall , Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Other than MFN 0 -> INVALID_MFN, no functional change intended. Signed-off-by: Julien Grall Acked-by: Jan Beulich --- Cc: Jan Beulich Cc: Andrew Cooper Changes in v6: - s/_mfn(0)/MFN 0/ - Fix typo in the commit message Changes in v5: - Use INVALID_MFN instead of _mfn(0) Changes in v4: - Patch added --- xen/arch/x86/x86_64/mm.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index f6dd95aa47..8d1f130abf 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -43,6 +43,8 @@ asm(".file \"" __FILE__ "\""); /* Override macros from asm/page.h to make them work with mfn_t */ #undef page_to_mfn #define page_to_mfn(pg) _mfn(__page_to_mfn(pg)) +#undef mfn_to_page +#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn)) unsigned int __read_mostly m2p_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START; @@ -160,7 +162,8 @@ static int m2p_mapped(unsigned long spfn) static int share_hotadd_m2p_table(struct mem_hotadd_info *info) { - unsigned long i, n, v, m2p_start_mfn = 0; + unsigned long i, n, v; + mfn_t m2p_start_mfn = INVALID_MFN; l3_pgentry_t l3e; l2_pgentry_t l2e; @@ -180,15 +183,16 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info) l2e = l3e_to_l2e(l3e)[l2_table_offset(v)]; if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) ) continue; - m2p_start_mfn = l2e_get_pfn(l2e); + m2p_start_mfn = l2e_get_mfn(l2e); } else continue; for ( i = 0; i < n; i++ ) { - struct page_info *page = mfn_to_page(m2p_start_mfn + i); - if (hotadd_mem_valid(m2p_start_mfn + i, info)) + struct page_info *page = mfn_to_page(mfn_add(m2p_start_mfn, i)); + + if ( hotadd_mem_valid(mfn_x(mfn_add(m2p_start_mfn, i)), info) ) share_xen_page_with_privileged_guests(page, SHARE_ro); } } @@ -204,12 +208,13 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info) l2e = l3e_to_l2e(l3e)[l2_table_offset(v)]; if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) ) continue; - m2p_start_mfn = l2e_get_pfn(l2e); + m2p_start_mfn = l2e_get_mfn(l2e); for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) { - struct page_info *page = mfn_to_page(m2p_start_mfn + i); - if (hotadd_mem_valid(m2p_start_mfn + i, info)) + struct page_info *page = mfn_to_page(mfn_add(m2p_start_mfn, i)); + + if ( hotadd_mem_valid(mfn_x(mfn_add(m2p_start_mfn, i)), info) ) share_xen_page_with_privileged_guests(page, SHARE_ro); } } @@ -720,10 +725,10 @@ static void cleanup_frame_table(struct mem_hotadd_info *info) unsigned long sva, eva; l3_pgentry_t l3e; l2_pgentry_t l2e; - unsigned long spfn, epfn; + mfn_t spfn, epfn; - spfn = info->spfn; - epfn = info->epfn; + spfn = _mfn(info->spfn); + epfn = _mfn(info->epfn); sva = (unsigned long)mfn_to_page(spfn); eva = (unsigned long)mfn_to_page(epfn); @@ -795,16 +800,17 @@ static int setup_frametable_chunk(void *start, void *end, static int extend_frame_table(struct mem_hotadd_info *info) { - unsigned long cidx, nidx, eidx, spfn, epfn; + unsigned long cidx, nidx, eidx; + mfn_t spfn, epfn; - spfn = info->spfn; - epfn = info->epfn; + spfn = _mfn(info->spfn); + epfn = _mfn(info->epfn); - eidx = (pfn_to_pdx(epfn) + PDX_GROUP_COUNT - 1) / PDX_GROUP_COUNT; - nidx = cidx = pfn_to_pdx(spfn)/PDX_GROUP_COUNT; + eidx = (mfn_to_pdx(epfn) + PDX_GROUP_COUNT - 1) / PDX_GROUP_COUNT; + nidx = cidx = mfn_to_pdx(spfn)/PDX_GROUP_COUNT; - ASSERT( pfn_to_pdx(epfn) <= (DIRECTMAP_SIZE >> PAGE_SHIFT) && - pfn_to_pdx(epfn) <= FRAMETABLE_NR ); + ASSERT( mfn_to_pdx(epfn) <= (DIRECTMAP_SIZE >> PAGE_SHIFT) && + mfn_to_pdx(epfn) <= FRAMETABLE_NR ); if ( test_bit(cidx, pdx_group_valid) ) cidx = find_next_zero_bit(pdx_group_valid, eidx, cidx); @@ -866,7 +872,7 @@ void __init subarch_init_memory(void) for ( i = 0; i < n; i++ ) share_xen_page_with_privileged_guests( - mfn_to_page(m2p_start_mfn + i), SHARE_ro); + mfn_to_page(_mfn(m2p_start_mfn + i)), SHARE_ro); } for ( v = RDWR_COMPAT_MPT_VIRT_START; @@ -884,7 +890,7 @@ void __init subarch_init_memory(void) for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) share_xen_page_with_privileged_guests( - mfn_to_page(m2p_start_mfn + i), SHARE_ro); + mfn_to_page(_mfn(m2p_start_mfn + i)), SHARE_ro); } /* Mark all of direct map NX if hardware supports it. */ @@ -1270,7 +1276,7 @@ static int transfer_pages_to_heap(struct mem_hotadd_info *info) */ for (i = info->spfn; i < info->cur; i++) { - pg = mfn_to_page(i); + pg = mfn_to_page(_mfn(i)); pg->count_info = PGC_state_inuse; }