From patchwork Wed Feb 21 14:02:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 129069 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp662561ljc; Wed, 21 Feb 2018 06:05:59 -0800 (PST) X-Google-Smtp-Source: AH8x227kZQaB8KqZbobPZHkNISer3ez4QhX16lbEqF7tMHDddXwJjM4oH2fn7ni+lm+l4EZXmnDj X-Received: by 2002:a25:c651:: with SMTP id k78-v6mr2255971ybf.132.1519221959064; Wed, 21 Feb 2018 06:05:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519221959; cv=none; d=google.com; s=arc-20160816; b=UgZ9YHGc7BZ9uRWV4oouRUwLsk+Hg8pTKjJ3sbml2BL2cQWxZILLHhfXSQeZUQ1AVo KOXj2xS2wy7/H5OjwNwlvf/owJ2PhDFM47HCy9osFwDe5UM5wEv5NsAI9vssvE0VTB8F 8a8M/glY9818Sw/ELN9NC9f5vitK+Ig7NLp2N1IQJdfIGH1uB0JUstI+GqIpjpGTG9nJ KtCSxBaV9Vs61YopemxokluRUIPDQ6/DTwtPOrFlIRoVjDDqVEr2h981ErQUt9Zy7x5g p98K0AdaRy57UtnDlWbuNUZYhI6b1h/aAPm9BgrGgHatgWuw53P5BZj1jictUfnHolNT BkBg== 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=MymjMSfrKNZxYbHABT6Q6W3XpevcfFgKAayh9dUCAlQ=; b=IhEsa2AIxVMt6YejpQeZ5Gkov4kddnAy7FZIG7D7K5WxVCU+/0SPpe+nLEj6BSqwf5 DOPOSXTMunpfJas4v+4D/x7UWZcD80ncNitWwxJedGQHDJ1al4Z1oLiv7m8lBBSm0VWc 2PFXlT2ud/oo6hlQ3dc7yr0pOUb7HdJavIRkSeaiPnfYsyvwHX8DxNycIZ96aFoGv8qd iYgVtFQj6DPULHBfiPjtTlZrr7pCD5PFQRWmoP2KywoKOXIUF5aLWozKug3Mro758aMW uBV7Wml2kweRmq1qLOvfVLwdbr+5IBBXAjdh1KA8elENqx4qINm/dNbEBvjL7JW2Kaq5 q8NA== 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 r1si2112860qkk.368.2018.02.21.06.05.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 06:05:59 -0800 (PST) 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 1eoUzn-0004is-Mp; Wed, 21 Feb 2018 14:03:43 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eoUzm-0004bZ-S5 for xen-devel@lists.xen.org; Wed, 21 Feb 2018 14:03:42 +0000 X-Inumbo-ID: 3c3ffbd6-1710-11e8-b9b1-635ca7ef6cff Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 3c3ffbd6-1710-11e8-b9b1-635ca7ef6cff; Wed, 21 Feb 2018 14:05:13 +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 BE85E1596; Wed, 21 Feb 2018 06:03:36 -0800 (PST) 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 D2C753F318; Wed, 21 Feb 2018 06:03:35 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 21 Feb 2018 14:02:58 +0000 Message-Id: <20180221140259.29360-16-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180221140259.29360-1-julien.grall@arm.com> References: <20180221140259.29360-1-julien.grall@arm.com> Cc: Andrew Cooper , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v4 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" No functional change intendend. Signed-off-by: Julien Grall Acked-by: Jan Beulich --- Cc: Jan Beulich Cc: Andrew Cooper 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 cfbc8ecf16..6b679882d6 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 = _mfn(0); 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; }