From owner-svn-src-head@FreeBSD.ORG Tue Jul 15 15:38:08 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 593A6BD7; Tue, 15 Jul 2014 15:38:07 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B072722E4; Tue, 15 Jul 2014 15:38:07 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id AE423B91E; Tue, 15 Jul 2014 11:38:06 -0400 (EDT) From: John Baldwin To: Ian Lepore Subject: Re: svn commit: r268660 - head/sys/amd64/amd64 Date: Tue, 15 Jul 2014 10:03:19 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20140415; KDE/4.5.5; amd64; ; ) References: <201407150930.s6F9Uhgi052394@svn.freebsd.org> <1405432340.1312.26.camel@revolution.hippie.lan> In-Reply-To: <1405432340.1312.26.camel@revolution.hippie.lan> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201407151003.19335.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 15 Jul 2014 11:38:06 -0400 (EDT) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Konstantin Belousov X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jul 2014 15:38:08 -0000 On Tuesday, July 15, 2014 9:52:20 am Ian Lepore wrote: > On Tue, 2014-07-15 at 09:30 +0000, Konstantin Belousov wrote: > > Author: kib > > Date: Tue Jul 15 09:30:43 2014 > > New Revision: 268660 > > URL: http://svnweb.freebsd.org/changeset/base/268660 > > > > Log: > > Make amd64 pmap_copy_pages() functional for pages not mapped by DMAP. > > > > Requested and reviewed by: royger > > Tested by: pho, royger > > Sponsored by: The FreeBSD Foundation > > MFC after: 1 week > > > > Modified: > > head/sys/amd64/amd64/pmap.c > > > > Modified: head/sys/amd64/amd64/pmap.c > > ============================================================================== > > --- head/sys/amd64/amd64/pmap.c Tue Jul 15 05:45:50 2014 (r268659) > > +++ head/sys/amd64/amd64/pmap.c Tue Jul 15 09:30:43 2014 (r268660) > > @@ -390,6 +390,11 @@ SYSCTL_PROC(_vm_pmap, OID_AUTO, pcid_sav > > CTLFLAG_MPSAFE, NULL, 0, pmap_pcid_save_cnt_proc, "QU", > > "Count of saved TLB context on switch"); > > > > +/* pmap_copy_pages() over non-DMAP */ > > +static struct mtx cpage_lock; > > +static vm_offset_t cpage_a; > > +static vm_offset_t cpage_b; > > + > > /* > > * Crashdump maps. > > */ > > @@ -1055,6 +1060,10 @@ pmap_init(void) > > M_WAITOK | M_ZERO); > > for (i = 0; i < pv_npg; i++) > > TAILQ_INIT(&pv_table[i].pv_list); > > + > > + mtx_init(&cpage_lock, "cpage", NULL, MTX_DEF); > > + cpage_a = kva_alloc(PAGE_SIZE); > > + cpage_b = kva_alloc(PAGE_SIZE); > > } > > > > static SYSCTL_NODE(_vm_pmap, OID_AUTO, pde, CTLFLAG_RD, 0, > > @@ -5064,19 +5073,58 @@ pmap_copy_pages(vm_page_t ma[], vm_offse > > vm_offset_t b_offset, int xfersize) > > { > > void *a_cp, *b_cp; > > + vm_page_t m_a, m_b; > > + vm_paddr_t p_a, p_b; > > + pt_entry_t *pte; > > vm_offset_t a_pg_offset, b_pg_offset; > > int cnt; > > + boolean_t pinned; > > > > + pinned = FALSE; > > while (xfersize > 0) { > > a_pg_offset = a_offset & PAGE_MASK; > > - cnt = min(xfersize, PAGE_SIZE - a_pg_offset); > > - a_cp = (char *)PHYS_TO_DMAP(ma[a_offset >> PAGE_SHIFT]-> > > - phys_addr) + a_pg_offset; > > + m_a = ma[a_offset >> PAGE_SHIFT]; > > + p_a = m_a->phys_addr; > > b_pg_offset = b_offset & PAGE_MASK; > > + m_b = mb[b_offset >> PAGE_SHIFT]; > > + p_b = m_b->phys_addr; > > + cnt = min(xfersize, PAGE_SIZE - a_pg_offset); > > cnt = min(cnt, PAGE_SIZE - b_pg_offset); > > - b_cp = (char *)PHYS_TO_DMAP(mb[b_offset >> PAGE_SHIFT]-> > > - phys_addr) + b_pg_offset; > > + if (__predict_false(p_a < DMAP_MIN_ADDRESS || > > + p_a > DMAP_MIN_ADDRESS + dmaplimit)) { > > + mtx_lock(&cpage_lock); > > + sched_pin(); > > + pinned = TRUE; > > + pte = vtopte(cpage_a); > > + *pte = p_a | X86_PG_A | X86_PG_V | > > + pmap_cache_bits(kernel_pmap, m_a->md.pat_mode, 0); > > + invlpg(cpage_a); > > + a_cp = (char *)cpage_a + a_pg_offset; > > + } else { > > + a_cp = (char *)PHYS_TO_DMAP(p_a) + a_pg_offset; > > + } > > + if (__predict_false(p_b < DMAP_MIN_ADDRESS || > > + p_b > DMAP_MIN_ADDRESS + dmaplimit)) { > > + if (!pinned) { > > + mtx_lock(&cpage_lock); > > + sched_pin(); > > + pinned = TRUE; > > + } > > + pte = vtopte(cpage_b); > > + *pte = p_b | X86_PG_A | X86_PG_M | X86_PG_RW | > > + X86_PG_V | pmap_cache_bits(kernel_pmap, > > + m_b->md.pat_mode, 0); > > + invlpg(cpage_b); > > + b_cp = (char *)cpage_b + b_pg_offset; > > + } else { > > + b_cp = (char *)PHYS_TO_DMAP(p_b) + b_pg_offset; > > + } > > bcopy(a_cp, b_cp, cnt); > > + if (__predict_false(pinned)) { > > + sched_unpin(); > > + mtx_unlock(&cpage_lock); > > + pinned = FALSE; > > Should this pinned = FALSE be done under the cpage_lock to avoid a race? It's a local variable, how would it race? (No other thread/CPU should be able to "get" to it to either read or write to it, only curthread, so it shouldn't need any locking.) -- John Baldwin