From patchwork Wed Mar 14 18:20:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 131714 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp157120ljb; Wed, 14 Mar 2018 11:22:41 -0700 (PDT) X-Google-Smtp-Source: AG47ELtfnvlJZiOb/NQmYBLDNmZ3IrrweoGiorJiGPm62cqkaGSD3BBXDHtm70kzxjVlK6qXLMlr X-Received: by 2002:a24:dbd6:: with SMTP id c205-v6mr3237207itg.63.1521051760845; Wed, 14 Mar 2018 11:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521051760; cv=none; d=google.com; s=arc-20160816; b=WmaeCi5+F+GCRa8YAiMuoFfc+Gf/R3xWEleKjxxlzG7p479IpbpGQdKD93j/AZkYuc skvlxztbDQ/dMN+ZFuZ2iua9rMFXkfpFN2zeBz3J+SDwVZ3QAPJY+dEuO+sq1XGkjmPJ 2l4zhtegR4Snm0+jSH9OG6YoBrGNNyY9CwTgPMHoC3tqTuQ+oK6NVWr6XXr0QpEUKMmr xB4SSSk47Ay7UjepLfN1t3e7sED6BJHSftSL1n1oMX6uCMDBKm5Zz0642KivR+Tnx9N6 Q37S0K1C3brUzCdVDY2emA9DX/otxmBd58WvO0GZuB3mAzIOZ2wZi9n2mBgWgtJTUFYD oRcA== 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 :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:arc-authentication-results; bh=zzeq0Nz32ZMVHWUlsOzmdPp07SN/KxPXa0xyrvgyv0k=; b=k8weDyOxMFCkj8JYfQZSc4GkPIht2yRa1n8/YycA28Ijun4QL32lkYpxyeKPEY1GoJ hfUTnxXiwCLBh/4I5vOQgtorcVfYUGaUF69d8VlmkT4io/Lw1xD2K4STarHEK/GNuv4k zsj0DY+/FRAMkyEJdJG4OAHOwyUM8ZvomKCh61NwDXnekrATkYgur5VTI2sG8i9eBQv5 BDYFlkYvdVfRuYDhW4BwZRg5KOzZjzuwq4FfS/GYEO4srZJ2Tny8mizd/wIsQPXYAXmC yr+2cSBSnbBbhnPXU3PzaYKBr4zx+NDKgJ1Ir/Vy1MtAn3yDbN/RAbZITp3dDeApSEqt qZ9g== 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 z6si2027644iod.214.2018.03.14.11.22.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 11:22:40 -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.84_2) (envelope-from ) id 1ewB12-0007AH-Sk; Wed, 14 Mar 2018 18:20:44 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ewB11-00077f-Hr for xen-devel@lists.xen.org; Wed, 14 Mar 2018 18:20:43 +0000 X-Inumbo-ID: 6526feb1-27b4-11e8-9728-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6526feb1-27b4-11e8-9728-bc764e045a96; Wed, 14 Mar 2018 19:20:38 +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 9650C15BE; Wed, 14 Mar 2018 11:20:41 -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 AB5373F53D; Wed, 14 Mar 2018 11:20:40 -0700 (PDT) From: julien.grall@arm.com To: xen-devel@lists.xen.org Date: Wed, 14 Mar 2018 18:20:08 +0000 Message-Id: <20180314182009.14274-16-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180314182009.14274-1-julien.grall@arm.com> References: <20180314182009.14274-1-julien.grall@arm.com> Cc: Andrew Cooper , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v5 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.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Julien Grall Other than _mfn(0) -> INVALID_MFN, no functional change intendend. Signed-off-by: Julien Grall Acked-by: Jan Beulich --- Cc: Jan Beulich Cc: Andrew Cooper 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 e03250bcdd..a54e2c9be4 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, XENSHARE_readonly); } } @@ -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, XENSHARE_readonly); } } @@ -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++ ) { - struct page_info *page = mfn_to_page(m2p_start_mfn + i); + struct page_info *page = mfn_to_page(_mfn(m2p_start_mfn + i)); share_xen_page_with_privileged_guests(page, XENSHARE_readonly); } } @@ -886,7 +892,7 @@ void __init subarch_init_memory(void) for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) { - struct page_info *page = mfn_to_page(m2p_start_mfn + i); + struct page_info *page = mfn_to_page(_mfn(m2p_start_mfn + i)); share_xen_page_with_privileged_guests(page, XENSHARE_readonly); } } @@ -1274,7 +1280,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; }