From patchwork Fri Dec 20 14:19:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11305573 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 9C15B13B6 for ; Fri, 20 Dec 2019 14:19:51 +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 81E382053B for ; Fri, 20 Dec 2019 14:19:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81E382053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.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 1iiJ7F-0003iJ-6B; Fri, 20 Dec 2019 14:18:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iiJ7E-0003iD-7X for xen-devel@lists.xenproject.org; Fri, 20 Dec 2019 14:18:52 +0000 X-Inumbo-ID: a06b8888-2333-11ea-a1e1-bc764e2007e4 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a06b8888-2333-11ea-a1e1-bc764e2007e4; Fri, 20 Dec 2019 14:18:43 +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 9F810B2CF; Fri, 20 Dec 2019 14:18:42 +0000 (UTC) From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: Message-ID: <8be5ebf6-c710-e1de-12af-f87137b69c44@suse.com> Date: Fri, 20 Dec 2019 15:19:11 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Subject: [Xen-devel] [PATCH 1/4] x86/mm: mod_l_entry() have no need to use __copy_from_user() 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: George Dunlap , Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" mod_l1_entry()'s need to do so went away with commit 2d0557c5cb ("x86: Fold page_info lock into type_info"), and the other three never had such a need, at least going back as far as 3.2.0. Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2124,13 +2124,10 @@ static int mod_l1_entry(l1_pgentry_t *pl struct vcpu *pt_vcpu, struct domain *pg_dom) { bool preserve_ad = (cmd == MMU_PT_UPDATE_PRESERVE_AD); - l1_pgentry_t ol1e; + l1_pgentry_t ol1e = *pl1e; struct domain *pt_dom = pt_vcpu->domain; int rc = 0; - if ( unlikely(__copy_from_user(&ol1e, pl1e, sizeof(ol1e)) != 0) ) - return -EFAULT; - ASSERT(!paging_mode_refcounts(pt_dom)); if ( l1e_get_flags(nl1e) & _PAGE_PRESENT ) @@ -2248,8 +2245,7 @@ static int mod_l2_entry(l2_pgentry_t *pl return -EPERM; } - if ( unlikely(__copy_from_user(&ol2e, pl2e, sizeof(ol2e)) != 0) ) - return -EFAULT; + ol2e = *pl2e; if ( l2e_get_flags(nl2e) & _PAGE_PRESENT ) { @@ -2311,8 +2307,7 @@ static int mod_l3_entry(l3_pgentry_t *pl if ( is_pv_32bit_domain(d) && (pgentry_ptr_to_slot(pl3e) >= 3) ) return -EINVAL; - if ( unlikely(__copy_from_user(&ol3e, pl3e, sizeof(ol3e)) != 0) ) - return -EFAULT; + ol3e = *pl3e; if ( l3e_get_flags(nl3e) & _PAGE_PRESENT ) { @@ -2378,8 +2373,7 @@ static int mod_l4_entry(l4_pgentry_t *pl return -EINVAL; } - if ( unlikely(__copy_from_user(&ol4e, pl4e, sizeof(ol4e)) != 0) ) - return -EFAULT; + ol4e = *pl4e; if ( l4e_get_flags(nl4e) & _PAGE_PRESENT ) { From patchwork Fri Dec 20 14:19:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11305577 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 95F7214F6 for ; Fri, 20 Dec 2019 14:20:06 +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 7730621655 for ; Fri, 20 Dec 2019 14:20:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7730621655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.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 1iiJ7b-0003ki-Fw; Fri, 20 Dec 2019 14:19:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iiJ7a-0003kY-L5 for xen-devel@lists.xenproject.org; Fri, 20 Dec 2019 14:19:14 +0000 X-Inumbo-ID: adbf2d96-2333-11ea-88e7-bc764e2007e4 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id adbf2d96-2333-11ea-88e7-bc764e2007e4; Fri, 20 Dec 2019 14:19:05 +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 1A61CACA3; Fri, 20 Dec 2019 14:19:05 +0000 (UTC) From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: Message-ID: <455ab356-3354-1661-51d0-7f67caa9ecfb@suse.com> Date: Fri, 20 Dec 2019 15:19:34 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Subject: [Xen-devel] [PATCH 2/4] x86/mm: rename and tidy create_pae_xen_mappings() 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: George Dunlap , Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" After dad74b0f9e ("i386: fix handling of Xen entries in final L2 page table") and the removal of 32-bit support the function doesn't modify state anymore, and hence its name has been misleading. Change its name, constify parameters and a local variable, and make it return bool. Also drop the call to it from mod_l3_entry(): The function explicitly disallows 32-bit domains to modify slot 3. Furthermore, re-checking of slot 3 when other slots change has needlessly disallowed doing this together with making some L2 table recursively link back to an L2 used in some L3's 3rd slot (because of the checking of the type ref count to be 1). (Note that allowing dynamic changes of L3 entries in the way we do is bogus anyway, as that's not how L3s behave in the native case: They get re-evaluated only upon CR3 reloads.) As a result of this we no longer need to play games to get at the start of the L3 table. Leave an ASSERT() though, just in case. Further move a BUG_ON() such that in the common case its condition wouldn't need evaluating. Finally, since we're at it, move init_xen_pae_l2_slots() next to the renamed function, as they really belong together (in fact init_xen_pae_l2_slots() was [indirectly] broken out of this function). Signed-off-by: Jan Beulich --- We could go further here and delete the function altogether: There are no linear mappings in a PGT_pae_xen_l2 table anymore (this was on 32-bit only). The corresponding conditional in mod_l3_entry() could then go away as well (or, more precisely, would need to be replaced by correct handling of 3rd slot updates). This would mean that a 32-bit guest functioning on new Xen may fail to work on older (possibly 32-bit) Xen. --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -1414,22 +1414,23 @@ static int promote_l1_table(struct page_ return ret; } -static int create_pae_xen_mappings(struct domain *d, l3_pgentry_t *pl3e) +static bool pae_xen_mappings_check(const struct domain *d, + const l3_pgentry_t *pl3e) { - struct page_info *page; - l3_pgentry_t l3e3; + const struct page_info *page; + l3_pgentry_t l3e3; if ( !is_pv_32bit_domain(d) ) - return 1; + return true; - pl3e = (l3_pgentry_t *)((unsigned long)pl3e & PAGE_MASK); + ASSERT(!((unsigned long)pl3e & ~PAGE_MASK)); /* 3rd L3 slot contains L2 with Xen-private mappings. It *must* exist. */ l3e3 = pl3e[3]; if ( !(l3e_get_flags(l3e3) & _PAGE_PRESENT) ) { gdprintk(XENLOG_WARNING, "PAE L3 3rd slot is empty\n"); - return 0; + return false; } /* @@ -1443,15 +1444,23 @@ static int create_pae_xen_mappings(struc */ page = l3e_get_page(l3e3); BUG_ON(page->u.inuse.type_info & PGT_pinned); - BUG_ON((page->u.inuse.type_info & PGT_count_mask) == 0); BUG_ON(!(page->u.inuse.type_info & PGT_pae_xen_l2)); if ( (page->u.inuse.type_info & PGT_count_mask) != 1 ) { + BUG_ON(!(page->u.inuse.type_info & PGT_count_mask)); gdprintk(XENLOG_WARNING, "PAE L3 3rd slot is shared\n"); - return 0; + return false; } - return 1; + return true; +} + +void init_xen_pae_l2_slots(l2_pgentry_t *l2t, const struct domain *d) +{ + memcpy(&l2t[COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(d)], + &compat_idle_pg_table_l2[ + l2_table_offset(HIRO_COMPAT_MPT_VIRT_START)], + COMPAT_L2_PAGETABLE_XEN_SLOTS(d) * sizeof(*l2t)); } static int promote_l2_table(struct page_info *page, unsigned long type) @@ -1621,7 +1630,7 @@ static int promote_l3_table(struct page_ pl3e[i] = adjust_guest_l3e(l3e, d); } - if ( !rc && !create_pae_xen_mappings(d, pl3e) ) + if ( !rc && !pae_xen_mappings_check(d, pl3e) ) rc = -EINVAL; if ( rc < 0 && rc != -ERESTART && rc != -EINTR ) { @@ -1663,14 +1672,6 @@ static int promote_l3_table(struct page_ unmap_domain_page(pl3e); return rc; } - -void init_xen_pae_l2_slots(l2_pgentry_t *l2t, const struct domain *d) -{ - memcpy(&l2t[COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(d)], - &compat_idle_pg_table_l2[ - l2_table_offset(HIRO_COMPAT_MPT_VIRT_START)], - COMPAT_L2_PAGETABLE_XEN_SLOTS(d) * sizeof(*l2t)); -} #endif /* CONFIG_PV */ /* @@ -2349,10 +2350,6 @@ static int mod_l3_entry(l3_pgentry_t *pl return -EFAULT; } - if ( likely(rc == 0) ) - if ( !create_pae_xen_mappings(d, pl3e) ) - BUG(); - put_page_from_l3e(ol3e, mfn, PTF_defer); return rc; } From patchwork Fri Dec 20 14:19:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11305581 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 5366E13B6 for ; Fri, 20 Dec 2019 14:20:34 +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 3970321655 for ; Fri, 20 Dec 2019 14:20:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3970321655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.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 1iiJ7x-0003of-QF; Fri, 20 Dec 2019 14:19:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iiJ7w-0003oW-H3 for xen-devel@lists.xenproject.org; Fri, 20 Dec 2019 14:19:36 +0000 X-Inumbo-ID: bada06c2-2333-11ea-b6f1-bc764e2007e4 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id bada06c2-2333-11ea-b6f1-bc764e2007e4; Fri, 20 Dec 2019 14:19:27 +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 1887AB23D; Fri, 20 Dec 2019 14:19:27 +0000 (UTC) From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: Message-ID: Date: Fri, 20 Dec 2019 15:19:56 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Subject: [Xen-devel] [PATCH 3/4] x86/mm: avoid IOMMU operations in more cases in _get_page_type() 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: George Dunlap , Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" All that really matters is whether writability of a page changes; in paticular e.g. page table -> page table (but different levels) transitions do not require unmapping the page from the IOMMU again. Note that the XSA-288 fix did arrange for PGT_none pages not needing special consideration here. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2968,17 +2968,19 @@ static int _get_page_type(struct page_in return -EINTR; } - if ( unlikely((x & PGT_type_mask) != type) ) + if ( unlikely(((x & PGT_type_mask) == PGT_writable_page) != + (type == PGT_writable_page)) ) { /* Special pages should not be accessible from devices. */ struct domain *d = page_get_owner(page); + if ( d && is_pv_domain(d) && unlikely(need_iommu_pt_sync(d)) ) { mfn_t mfn = page_to_mfn(page); if ( (x & PGT_type_mask) == PGT_writable_page ) rc = iommu_legacy_unmap(d, _dfn(mfn_x(mfn)), PAGE_ORDER_4K); - else if ( type == PGT_writable_page ) + else rc = iommu_legacy_map(d, _dfn(mfn_x(mfn)), mfn, PAGE_ORDER_4K, IOMMUF_readable | IOMMUF_writable); From patchwork Fri Dec 20 14:20:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11305583 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 6D86A14F6 for ; Fri, 20 Dec 2019 14:20:42 +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 52E2521655 for ; Fri, 20 Dec 2019 14:20:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52E2521655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.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 1iiJ89-0003ri-6u; Fri, 20 Dec 2019 14:19:49 +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 1iiJ87-0003rA-IN for xen-devel@lists.xenproject.org; Fri, 20 Dec 2019 14:19:47 +0000 X-Inumbo-ID: c5d67eb6-2333-11ea-9367-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c5d67eb6-2333-11ea-9367-12813bfff9fa; Fri, 20 Dec 2019 14:19:46 +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 83B2FB23D; Fri, 20 Dec 2019 14:19:45 +0000 (UTC) From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: Message-ID: <272862bd-0b05-9a66-c79e-76502b89dd38@suse.com> Date: Fri, 20 Dec 2019 15:20:14 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Subject: [Xen-devel] [PATCH 4/4] x86/mm: drop redundant smp_wmb() from _put_final_page_type() 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: George Dunlap , Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" get_page_light()'s use of cmpxchg() is a full barrier already anyway. Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2746,7 +2746,7 @@ static int _put_final_page_type(struct p else { BUG_ON(rc != -ERESTART); - smp_wmb(); + /* get_page_light() includes a full barrier. */ get_page_light(page); page->u.inuse.type_info |= PGT_partial; }