From patchwork Fri Dec 13 17:37:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11291161 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 7E5FC14E3 for ; Fri, 13 Dec 2019 21:01:10 +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 43BB32465E for ; Fri, 13 Dec 2019 21:01:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="VIQKAklq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43BB32465E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none 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 1ifot6-0000MY-Hl; Fri, 13 Dec 2019 17:38:00 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ifot5-0000MA-86 for xen-devel@lists.xenproject.org; Fri, 13 Dec 2019 17:37:59 +0000 X-Inumbo-ID: 48621ff8-1dcf-11ea-8fa7-12813bfff9fa Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 48621ff8-1dcf-11ea-8fa7-12813bfff9fa; Fri, 13 Dec 2019 17:37:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1576258669; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b+2YaW9uII8XvjvL0l+RbCqi/7Wcsm6fBxQB/SrIG0E=; b=VIQKAklqTxETxzaGQXItju+Be9vC+JgCxgsnGWjWboKrNkgG/9dddycl UpvWt465UxKd/1Hrhkg5hzYHt684G/h0RJbNGQn6VsaDfInS4fDr9KKQ4 5AafAU+CmX/Tru/x+P7mxXY0Ih/b1IIzIy6YlROfwulQbYPKIeeJdX6KH 4=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: YidhDiZyocLeLfKGZ82VuujyDdpAiInxGSD+/SfgXEMsu2iiCse1F506h+KWj4FhwYrR6ySKrC eg1pioNsrjUQBn9uZvnTTPyhc4hGRXT/1Z0GFx5RlWGICoNQnTP+97fgcjB29YU/GrNzhvWh6V zKDQwkMR2S/9+tbPf+pg+VShaGCaoizY6IIgatD8+t8rZxK04C7IvYngK/hjqeUHYhZnnIyA4S UfcRnBOJnwvFAtBJj6vaZ+djtfCP2Pw24E+Ealmrj+GuZP/a69IGEwWHifZX21Oj8/LCN8Oxav jKI= X-SBRS: 2.7 X-MesageID: 10226691 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,309,1571716800"; d="scan'208";a="10226691" From: George Dunlap To: Date: Fri, 13 Dec 2019 17:37:42 +0000 Message-ID: <20191213173742.1960441-4-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191213173742.1960441-1-george.dunlap@citrix.com> References: <20191213173742.1960441-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 3/3] x86/mm: More discriptive names for page de/validation functions 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 , George Dunlap , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The functions alloc_page_type(), alloc_lN_table(), free_page_type() and free_lN_table() are confusingly named: nothing is being allocated or freed. Rather, the page being passed in is being either validated or devalidated for use as the specific type; in the specific case of pagetables, these may be promoted or demoted (i.e., grab appropriate references for PTEs). Rename alloc_page_type() and free_page_type() to validate_page() and devalidate_page(). Also rename alloc_segdesc_page() to validate_segdesc_page(), since this is what it's doing. Rename alloc_lN_table() and free_lN_table() to promote_lN_table() and demote_lN_table(), respectively. After this change: - get / put type consistenly refer to increasing or decreasing the count - validate / devalidate consistently refers to actions done when a type count goes 0 -> 1 or 1 -> 0 - promote / demote consistenly refers to acquiring or freeing resources (in the form of type refs and general references) in order to allow a page to be used as a pagetable. No functional change. Signed-off-by: George Dunlap Acked-by: Jan Beulich --- v2: - Rebase onto staging - Also rename alloc_segdesc_page - Drop superfluous '_type' from validate_page / devalidate_page - Use promote / demote for _lN_table CC: Andrew Cooper CC: Jan Beulich --- xen/arch/x86/domain.c | 2 +- xen/arch/x86/mm.c | 66 ++++++++++++++++++++-------------------- xen/include/asm-x86/mm.h | 4 +-- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index bed19fc4dc..7cb7fd31dd 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -2032,7 +2032,7 @@ static int relinquish_memory( if ( likely(y == x) ) { /* No need for atomic update of type_info here: noone else updates it. */ - switch ( ret = free_page_type(page, x, 1) ) + switch ( ret = devalidate_page(page, x, 1) ) { case 0: break; diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 55f9a581b4..a711e8c78d 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -587,7 +587,7 @@ const char __section(".bss.page_aligned.const") __aligned(PAGE_SIZE) #ifdef CONFIG_PV -static int alloc_segdesc_page(struct page_info *page) +static int validate_segdesc_page(struct page_info *page) { const struct domain *owner = page_get_owner(page); seg_desc_t *descs = __map_domain_page(page); @@ -1363,7 +1363,7 @@ static int put_page_from_l4e(l4_pgentry_t l4e, mfn_t l4mfn, unsigned int flags) return put_pt_page(l4e_get_page(l4e), mfn_to_page(l4mfn), flags); } -static int alloc_l1_table(struct page_info *page) +static int promote_l1_table(struct page_info *page) { struct domain *d = page_get_owner(page); l1_pgentry_t *pl1e; @@ -1405,7 +1405,7 @@ static int alloc_l1_table(struct page_info *page) fail: gdprintk(XENLOG_WARNING, - "Failure %d in alloc_l1_table: slot %#x\n", ret, i); + "Failure %d in promote_l1_table: slot %#x\n", ret, i); out: while ( i-- > 0 ) put_page_from_l1e(pl1e[i], d); @@ -1438,7 +1438,7 @@ static int create_pae_xen_mappings(struct domain *d, l3_pgentry_t *pl3e) * 1. Cannot appear in slots != 3 because get_page_type() checks the * PGT_pae_xen_l2 flag, which is asserted iff the L2 appears in slot 3 * 2. Cannot appear in another page table's L3: - * a. alloc_l3_table() calls this function and this check will fail + * a. promote_l3_table() calls this function and this check will fail * b. mod_l3_entry() disallows updates to slot 3 in an existing table */ page = l3e_get_page(l3e3); @@ -1454,7 +1454,7 @@ static int create_pae_xen_mappings(struct domain *d, l3_pgentry_t *pl3e) return 1; } -static int alloc_l2_table(struct page_info *page, unsigned long type) +static int promote_l2_table(struct page_info *page, unsigned long type) { struct domain *d = page_get_owner(page); mfn_t l2mfn = page_to_mfn(page); @@ -1466,8 +1466,8 @@ static int alloc_l2_table(struct page_info *page, unsigned long type) pl2e = map_domain_page(l2mfn); /* - * NB that alloc_l2_table will never set partial_pte on an l2; but - * free_l2_table might if a linear_pagetable entry is interrupted + * NB that promote_l2_table will never set partial_pte on an l2; but + * demote_l2_table might if a linear_pagetable entry is interrupted * partway through de-validation. In that circumstance, * get_page_from_l2e() will always return -EINVAL; and we must * retain the type ref by doing the normal partial_flags tracking. @@ -1494,7 +1494,7 @@ static int alloc_l2_table(struct page_info *page, unsigned long type) /* * It shouldn't be possible for get_page_from_l2e to return * -ERESTART, since we never call this with PTF_preemptible. - * (alloc_l1_table may return -EINTR on an L1TF-vulnerable + * (promote_l1_table may return -EINTR on an L1TF-vulnerable * entry.) * * NB that while on a "clean" promotion, we can never get @@ -1515,12 +1515,12 @@ static int alloc_l2_table(struct page_info *page, unsigned long type) else if ( rc < 0 && rc != -EINTR ) { gdprintk(XENLOG_WARNING, - "Failure %d in alloc_l2_table: slot %#x\n", rc, i); + "Failure %d in promote_l2_table: slot %#x\n", rc, i); ASSERT(current->arch.old_guest_table == NULL); if ( i ) { /* - * alloc_l1_table() doesn't set old_guest_table; it does + * promote_l1_table() doesn't set old_guest_table; it does * its own tear-down immediately on failure. If it * did we'd need to check it and set partial_flags as we * do in alloc_l[34]_table(). @@ -1553,7 +1553,7 @@ static int alloc_l2_table(struct page_info *page, unsigned long type) return rc; } -static int alloc_l3_table(struct page_info *page) +static int promote_l3_table(struct page_info *page) { struct domain *d = page_get_owner(page); mfn_t l3mfn = page_to_mfn(page); @@ -1626,7 +1626,7 @@ static int alloc_l3_table(struct page_info *page) if ( rc < 0 && rc != -ERESTART && rc != -EINTR ) { gdprintk(XENLOG_WARNING, - "Failure %d in alloc_l3_table: slot %#x\n", rc, i); + "Failure %d in promote_l3_table: slot %#x\n", rc, i); if ( i ) { page->nr_validated_ptes = i; @@ -1677,7 +1677,7 @@ void init_xen_pae_l2_slots(l2_pgentry_t *l2t, const struct domain *d) * Fill an L4 with Xen entries. * * This function must write all ROOT_PAGETABLE_PV_XEN_SLOTS, to clobber any - * values a guest may have left there from alloc_l4_table(). + * values a guest may have left there from promote_l4_table(). * * l4t and l4mfn are mandatory, but l4mfn doesn't need to be the mfn under * *l4t. All other parameters are optional and will either fill or zero the @@ -1780,7 +1780,7 @@ void zap_ro_mpt(mfn_t mfn) } #ifdef CONFIG_PV -static int alloc_l4_table(struct page_info *page) +static int promote_l4_table(struct page_info *page) { struct domain *d = page_get_owner(page); mfn_t l4mfn = page_to_mfn(page); @@ -1819,7 +1819,7 @@ static int alloc_l4_table(struct page_info *page) { if ( rc != -EINTR ) gdprintk(XENLOG_WARNING, - "Failure %d in alloc_l4_table: slot %#x\n", rc, i); + "Failure %d in promote_l4_table: slot %#x\n", rc, i); if ( i ) { page->nr_validated_ptes = i; @@ -1875,7 +1875,7 @@ static int alloc_l4_table(struct page_info *page) return rc; } -static void free_l1_table(struct page_info *page) +static void demote_l1_table(struct page_info *page) { struct domain *d = page_get_owner(page); l1_pgentry_t *pl1e; @@ -1890,7 +1890,7 @@ static void free_l1_table(struct page_info *page) } -static int free_l2_table(struct page_info *page) +static int demote_l2_table(struct page_info *page) { struct domain *d = page_get_owner(page); mfn_t l2mfn = page_to_mfn(page); @@ -1942,7 +1942,7 @@ static int free_l2_table(struct page_info *page) return rc; } -static int free_l3_table(struct page_info *page) +static int demote_l3_table(struct page_info *page) { struct domain *d = page_get_owner(page); mfn_t l3mfn = page_to_mfn(page); @@ -1989,7 +1989,7 @@ static int free_l3_table(struct page_info *page) return rc > 0 ? 0 : rc; } -static int free_l4_table(struct page_info *page) +static int demote_l4_table(struct page_info *page) { struct domain *d = page_get_owner(page); mfn_t l4mfn = page_to_mfn(page); @@ -2589,7 +2589,7 @@ static void get_page_light(struct page_info *page) while ( unlikely(y != x) ); } -static int alloc_page_type(struct page_info *page, unsigned long type, +static int validate_page(struct page_info *page, unsigned long type, int preemptible) { #ifdef CONFIG_PV @@ -2603,25 +2603,25 @@ static int alloc_page_type(struct page_info *page, unsigned long type, switch ( type & PGT_type_mask ) { case PGT_l1_page_table: - rc = alloc_l1_table(page); + rc = promote_l1_table(page); break; case PGT_l2_page_table: ASSERT(preemptible); - rc = alloc_l2_table(page, type); + rc = promote_l2_table(page, type); break; case PGT_l3_page_table: ASSERT(preemptible); - rc = alloc_l3_table(page); + rc = promote_l3_table(page); break; case PGT_l4_page_table: ASSERT(preemptible); - rc = alloc_l4_table(page); + rc = promote_l4_table(page); break; case PGT_seg_desc_page: - rc = alloc_segdesc_page(page); + rc = validate_segdesc_page(page); break; default: - printk("Bad type in alloc_page_type %lx t=%" PRtype_info " c=%lx\n", + printk("Bad type in validate_page %lx t=%" PRtype_info " c=%lx\n", type, page->u.inuse.type_info, page->count_info); rc = -EINVAL; @@ -2669,7 +2669,7 @@ static int alloc_page_type(struct page_info *page, unsigned long type, } -int free_page_type(struct page_info *page, unsigned long type, +int devalidate_page(struct page_info *page, unsigned long type, int preemptible) { #ifdef CONFIG_PV @@ -2697,20 +2697,20 @@ int free_page_type(struct page_info *page, unsigned long type, switch ( type & PGT_type_mask ) { case PGT_l1_page_table: - free_l1_table(page); + demote_l1_table(page); rc = 0; break; case PGT_l2_page_table: ASSERT(preemptible); - rc = free_l2_table(page); + rc = demote_l2_table(page); break; case PGT_l3_page_table: ASSERT(preemptible); - rc = free_l3_table(page); + rc = demote_l3_table(page); break; case PGT_l4_page_table: ASSERT(preemptible); - rc = free_l4_table(page); + rc = demote_l4_table(page); break; default: gdprintk(XENLOG_WARNING, "type %" PRtype_info " mfn %" PRI_mfn "\n", @@ -2730,7 +2730,7 @@ int free_page_type(struct page_info *page, unsigned long type, static int _put_final_page_type(struct page_info *page, unsigned long type, bool preemptible, struct page_info *ptpg) { - int rc = free_page_type(page, type, preemptible); + int rc = devalidate_page(page, type, preemptible); if ( ptpg && PGT_type_equal(type, ptpg->u.inuse.type_info) && (type & PGT_validated) && rc != -EINTR ) @@ -3013,7 +3013,7 @@ static int _get_page_type(struct page_info *page, unsigned long type, page->partial_flags = 0; page->linear_pt_count = 0; } - rc = alloc_page_type(page, type, preemptible); + rc = validate_page(page, type, preemptible); } out: diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 320c6cd196..1479ba6703 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -355,8 +355,8 @@ static inline void *__page_to_virt(const struct page_info *pg) (PAGE_SIZE / (sizeof(*pg) & -sizeof(*pg)))); } -int free_page_type(struct page_info *page, unsigned long type, - int preemptible); +int devalidate_page(struct page_info *page, unsigned long type, + int preemptible); void init_xen_pae_l2_slots(l2_pgentry_t *l2t, const struct domain *d); void init_xen_l4_slots(l4_pgentry_t *l4t, mfn_t l4mfn,