From owner-freebsd-stable@FreeBSD.ORG Fri Oct 3 21:58:38 2014 Return-Path: Delivered-To: stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DAEF712C; Fri, 3 Oct 2014 21:58:37 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7E7F4C96; Fri, 3 Oct 2014 21:58:37 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id s93LwWNb086896 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 4 Oct 2014 00:58:32 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua s93LwWNb086896 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id s93LwU14086895; Sat, 4 Oct 2014 00:58:30 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 4 Oct 2014 00:58:30 +0300 From: Konstantin Belousov To: Kohji Okuno Subject: Re: About pmap_mapdev() & pmap_unmapdev() Message-ID: <20141003215830.GK26076@kib.kiev.ua> References: <20141003.172533.863334695746935674.okuno.kohji@jp.panasonic.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20141003.172533.863334695746935674.okuno.kohji@jp.panasonic.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: stable@freebsd.org, freebsd-current@freebsd.org X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Oct 2014 21:58:38 -0000 On Fri, Oct 03, 2014 at 05:25:33PM +0900, Kohji Okuno wrote: > Hi, > > At least in i386 && 9-stable, when we call pmap_mapdev() and > pmap_unmapdev(), kernel_pmap.pm_stats.resident_count is decreased > incorrectly. > > pmap_mapdev_attr()->pmap_kenter_attr(): > In this path, kernel_pmap.pm_stats.resident_count is not increlmented. > > pmap_unmapdev()->kmem_free(kernel_map)->vm_map_remove()->pmap_remove(): > But, in this path, kernel_pmap.pm_stats.resident_count is decreased in > pmap_remove_pte(). > > While I called pmap_mapdev() and pmap_unmapdev() repeatedly and > kernel_pmap.pm_stats.resident_count became `0', since pmap_remove() > returned without removing ptes, I encountered various kernel panics. I think you are right. The problem seems to be fixed in HEAD and 10, since mapdev was switched to use kva_alloc/kva_free. I added stable@ to Cc:. > > And, when I enabled INVARIANTS, I looked the following panic message. > panic: vm_page_free_toq: freeing mapped page 0xXXXXXXXX. Do you mean that this panic is related to missed pmap_remove() ? I doubt it, since pmap_mapdev() does not establish managed mappings. > > I think, I should change the following. > What do you think about this? > > > diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c > index 2adc6f8..a0998e8 100644 > --- a/sys/i386/i386/pmap.c > +++ b/sys/i386/i386/pmap.c > @@ -5061,6 +5061,7 @@ pmap_mapdev_attr(vm_paddr_t pa, vm_size_t size, int mode) > { > vm_offset_t va, offset; > vm_size_t tmpsize; > + int kmem_allocated = 0; > > offset = pa & PAGE_MASK; > size = roundup(offset + size, PAGE_SIZE); > @@ -5068,13 +5069,18 @@ pmap_mapdev_attr(vm_paddr_t pa, vm_size_t size, int mode) > > if (pa < KERNLOAD && pa + size <= KERNLOAD) > va = KERNBASE + pa; > - else > + else { > va = kmem_alloc_nofault(kernel_map, size); > + kmem_allocated = 1; You could just do PMAP_LOCK(kernel_pmap); kernel_pmap.pm_stats.resident_count += OFF_TO_IDX(size); PMAP_UNLOCK(kernel_pmap); there. And, the same fix is needed for amd64. > + } > if (!va) > panic("pmap_mapdev: Couldn't alloc kernel virtual memory"); > > - for (tmpsize = 0; tmpsize < size; tmpsize += PAGE_SIZE) > + for (tmpsize = 0; tmpsize < size; tmpsize += PAGE_SIZE) { > pmap_kenter_attr(va + tmpsize, pa + tmpsize, mode); > + if (kmem_allocated) > + kernel_pmap.pm_stats.resident_count++; > + } > pmap_invalidate_range(kernel_pmap, va, va + tmpsize); > pmap_invalidate_cache_range(va, va + size); > return ((void *)(va + offset)); > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"