Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F225CC433E0 for ; Wed, 20 May 2020 09:54:38 +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 C1FB22070A for ; Wed, 20 May 2020 09:54:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1FB22070A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com 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.92) (envelope-from ) id 1jbLQe-0007ry-CL; Wed, 20 May 2020 09:54:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jbLQd-0007rt-HR for xen-devel@lists.xenproject.org; Wed, 20 May 2020 09:54:23 +0000 X-Inumbo-ID: e18e8e64-9a7f-11ea-9887-bc764e2007e4 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e18e8e64-9a7f-11ea-9887-bc764e2007e4; Wed, 20 May 2020 09:54:22 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7F383AC49; Wed, 20 May 2020 09:54:24 +0000 (UTC) Subject: Re: [PATCH v6 08/15] x86_64/mm: switch to new APIs in setup_m2p_table To: Hongyan Xia References: From: Jan Beulich Message-ID: Date: Wed, 20 May 2020 11:54:21 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: xen-devel@lists.xenproject.org, =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , julien@xen.org, Wei Liu , Andrew Cooper Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 24.04.2020 16:08, Hongyan Xia wrote: > --- a/xen/arch/x86/x86_64/mm.c > +++ b/xen/arch/x86/x86_64/mm.c > @@ -379,13 +379,13 @@ static int setup_m2p_table(struct mem_hotadd_info *info) > { > unsigned long i, va, smap, emap; > unsigned int n; > - l2_pgentry_t *l2_ro_mpt = NULL; > l3_pgentry_t *l3_ro_mpt = NULL; > int ret = 0; > > ASSERT(l4e_get_flags(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]) > & _PAGE_PRESENT); > - l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]); > + l3_ro_mpt = map_l3t_from_l4e( > + idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]); > > smap = (info->spfn & (~((1UL << (L2_PAGETABLE_SHIFT - 3)) -1))); > emap = ((info->epfn + ((1UL << (L2_PAGETABLE_SHIFT - 3)) - 1 )) & > @@ -424,6 +424,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info) > break; > if ( n < CNT ) > { > + l2_pgentry_t *l2_ro_mpt; > mfn_t mfn = alloc_hotadd_mfn(info); > > ret = map_pages_to_xen( > @@ -440,30 +441,30 @@ static int setup_m2p_table(struct mem_hotadd_info *info) > _PAGE_PSE)); > if ( l3e_get_flags(l3_ro_mpt[l3_table_offset(va)]) & > _PAGE_PRESENT ) > - l2_ro_mpt = l3e_to_l2e(l3_ro_mpt[l3_table_offset(va)]) + > - l2_table_offset(va); > + l2_ro_mpt = map_l2t_from_l3e(l3_ro_mpt[l3_table_offset(va)]); > else > { > - l2_ro_mpt = alloc_xen_pagetable(); > - if ( !l2_ro_mpt ) > + mfn_t l2_ro_mpt_mfn = alloc_xen_pagetable_new(); > + > + if ( mfn_eq(l2_ro_mpt_mfn, INVALID_MFN) ) > { > ret = -ENOMEM; > goto error; > } > > + l2_ro_mpt = map_domain_page(l2_ro_mpt_mfn); > clear_page(l2_ro_mpt); > l3e_write(&l3_ro_mpt[l3_table_offset(va)], > - l3e_from_paddr(__pa(l2_ro_mpt), > - __PAGE_HYPERVISOR_RO | _PAGE_USER)); > - l2_ro_mpt += l2_table_offset(va); > + l3e_from_mfn(l2_ro_mpt_mfn, > + __PAGE_HYPERVISOR_RO | _PAGE_USER)); > } > + l2_ro_mpt += l2_table_offset(va); > > /* NB. Cannot be GLOBAL: guest user mode should not see it. */ > l2e_write(l2_ro_mpt, l2e_from_mfn(mfn, > /*_PAGE_GLOBAL|*/_PAGE_PSE|_PAGE_USER|_PAGE_PRESENT)); > + unmap_domain_page(l2_ro_mpt); > } > - if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) ) > - l2_ro_mpt = NULL; I think you want to consider retaining these two lines and the wider scope of l2_ro_mpt, to leverage it to avoid mapping and unmapping the same L2 page over and over on each loop iteration. Jan