From patchwork Fri Dec 6 15:53:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xia, Hongyan" X-Patchwork-Id: 11276713 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 BBC37138D for ; Fri, 6 Dec 2019 15:54:55 +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 982762173E for ; Fri, 6 Dec 2019 15:54:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="aGAFd90Z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 982762173E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.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 1idFvU-0007fG-F6; Fri, 06 Dec 2019 15:53:52 +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 1idFvT-0007ei-CW for xen-devel@lists.xenproject.org; Fri, 06 Dec 2019 15:53:51 +0000 X-Inumbo-ID: 9863e5de-1840-11ea-8369-12813bfff9fa Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9863e5de-1840-11ea-8369-12813bfff9fa; Fri, 06 Dec 2019 15:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1575647630; x=1607183630; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=GhNaIlIAGdiYLI4LV4f9R5vjcXhLk2rWhfZVDBck0as=; b=aGAFd90ZzYDGDtVnwcp510HRGh2IriSXY/ER9IlwvD476Ow2txcrKj9f PtlVpWJtaqhssMX0KuISm1SxKS7IgUOR4DW3ZgMyoZUmaiCADJEYlp2w9 vWXXnd4VJAoVTNbAmiCjU9MUq9CZFfDu1bpNIe+VOP2mvi7x88TDLhpZL Y=; IronPort-SDR: po6LkYy5UQ5AyCUP/aIxVQLyDc3xkhG69mkhMuS2z+ktShQkHV/zv4n1fiiAGEo12POLkoCjp2 4N48i95xfd1A== X-IronPort-AV: E=Sophos;i="5.69,285,1571702400"; d="scan'208";a="12045173" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-67b371d8.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 06 Dec 2019 15:53:38 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1a-67b371d8.us-east-1.amazon.com (Postfix) with ESMTPS id 2DB8FA1CED; Fri, 6 Dec 2019 15:53:37 +0000 (UTC) Received: from EX13D37EUA004.ant.amazon.com (10.43.165.124) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 6 Dec 2019 15:53:36 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D37EUA004.ant.amazon.com (10.43.165.124) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 6 Dec 2019 15:53:35 +0000 Received: from u60d575063b1f53.ant.amazon.com (10.125.106.64) by mail-relay.amazon.com (10.43.62.226) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 6 Dec 2019 15:53:34 +0000 From: Hongyan Xia To: Date: Fri, 6 Dec 2019 15:53:30 +0000 Message-ID: <95d2bdde025720a4019fa0a913bc7d5395fffe74.1575646580.git.hongyxia@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH 2/2] x86/mm: factor out the code for shattering an l2 PTE X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , jgrall@amazon.com, Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_?= =?utf-8?q?Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" map_pages_to_xen and modify_xen_mappings are performing almost exactly the same operations when shattering an l2 PTE, the only difference being whether we want to flush. Signed-off-by: Hongyan Xia --- xen/arch/x86/mm.c | 81 ++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 42aaaa1083..65f0758a6f 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5151,6 +5151,41 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v) flush_area_local((const void *)v, f) : \ flush_area_all((const void *)v, f)) +/* Shatter an l2 entry and populate l1. If virt is passed in, also do flush. */ +static void shatter_l2e(l2_pgentry_t *pl2e, l1_pgentry_t *l1t, + unsigned long virt, bool locking) +{ + unsigned int i; + l2_pgentry_t ol2e = *pl2e; + + for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) + l1e_write(l1t + i, + l1e_from_pfn(l2e_get_pfn(ol2e) + i, + lNf_to_l1f(l2e_get_flags(ol2e)))); + if ( locking ) + spin_lock(&map_pgdir_lock); + if ( (l2e_get_flags(ol2e) & _PAGE_PRESENT) && + (l2e_get_flags(ol2e) & _PAGE_PSE) ) + { + l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(l1t), + __PAGE_HYPERVISOR)); + l1t = NULL; + } + if ( locking ) + spin_unlock(&map_pgdir_lock); + if ( virt ) + { + unsigned int flush_flags = + FLUSH_TLB | FLUSH_ORDER(PAGETABLE_ORDER); + + if ( l2e_get_flags(ol2e) & _PAGE_GLOBAL ) + flush_flags |= FLUSH_TLB_GLOBAL; + flush_area(virt, flush_flags); + } + if ( l1t ) + free_xen_pagetable(l1t); +} + /* Shatter an l3 entry and populate l2. If virt is passed in, also do flush. */ static void shatter_l3e(l3_pgentry_t *pl3e, l2_pgentry_t *l2t, unsigned long virt, bool locking) @@ -5357,9 +5392,6 @@ int map_pages_to_xen( } else if ( l2e_get_flags(*pl2e) & _PAGE_PSE ) { - unsigned int flush_flags = - FLUSH_TLB | FLUSH_ORDER(PAGETABLE_ORDER); - /* Skip this PTE if there is no change. */ if ( (((l2e_get_pfn(*pl2e) & ~(L1_PAGETABLE_ENTRIES - 1)) + l1_table_offset(virt)) == mfn_x(mfn)) && @@ -5381,29 +5413,8 @@ int map_pages_to_xen( pl1e = alloc_xen_pagetable(); if ( pl1e == NULL ) return -ENOMEM; - - for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) - l1e_write(&pl1e[i], - l1e_from_pfn(l2e_get_pfn(*pl2e) + i, - lNf_to_l1f(l2e_get_flags(*pl2e)))); - - if ( l2e_get_flags(*pl2e) & _PAGE_GLOBAL ) - flush_flags |= FLUSH_TLB_GLOBAL; - - if ( locking ) - spin_lock(&map_pgdir_lock); - if ( (l2e_get_flags(*pl2e) & _PAGE_PRESENT) && - (l2e_get_flags(*pl2e) & _PAGE_PSE) ) - { - l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(pl1e), - __PAGE_HYPERVISOR)); - pl1e = NULL; - } - if ( locking ) - spin_unlock(&map_pgdir_lock); - flush_area(virt, flush_flags); - if ( pl1e ) - free_xen_pagetable(pl1e); + /* Pass virt to indicate we need to flush. */ + shatter_l2e(pl2e, pl1e, virt, locking); } pl1e = l2e_to_l1e(*pl2e) + l1_table_offset(virt); @@ -5631,23 +5642,7 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) pl1e = alloc_xen_pagetable(); if ( !pl1e ) return -ENOMEM; - for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) - l1e_write(&pl1e[i], - l1e_from_pfn(l2e_get_pfn(*pl2e) + i, - l2e_get_flags(*pl2e) & ~_PAGE_PSE)); - if ( locking ) - spin_lock(&map_pgdir_lock); - if ( (l2e_get_flags(*pl2e) & _PAGE_PRESENT) && - (l2e_get_flags(*pl2e) & _PAGE_PSE) ) - { - l2e_write_atomic(pl2e, l2e_from_mfn(virt_to_mfn(pl1e), - __PAGE_HYPERVISOR)); - pl1e = NULL; - } - if ( locking ) - spin_unlock(&map_pgdir_lock); - if ( pl1e ) - free_xen_pagetable(pl1e); + shatter_l2e(pl2e, pl1e, 0, locking); } } else