From owner-svn-src-all@freebsd.org Thu Oct 29 18:53:36 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8D946A21819 for ; Thu, 29 Oct 2015 18:53:36 +0000 (UTC) (envelope-from alc@rice.edu) Received: from pp1.rice.edu (proofpoint1.mail.rice.edu [128.42.201.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4DB74182E; Thu, 29 Oct 2015 18:53:35 +0000 (UTC) (envelope-from alc@rice.edu) Received: from pps.filterd (pp1.rice.edu [127.0.0.1]) by pp1.rice.edu (8.15.0.59/8.15.0.59) with SMTP id t9TIn5Zu013005; Thu, 29 Oct 2015 13:53:27 -0500 Received: from mh1.mail.rice.edu (mh1.mail.rice.edu [128.42.201.20]) by pp1.rice.edu with ESMTP id 1xuq57045m-1; Thu, 29 Oct 2015 13:53:27 -0500 X-Virus-Scanned: by amavis-2.7.0 at mh1.mail.rice.edu, auth channel Received: from 108-254-203-201.lightspeed.hstntx.sbcglobal.net (108-254-203-201.lightspeed.hstntx.sbcglobal.net [108.254.203.201]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) (Authenticated sender: alc) by mh1.mail.rice.edu (Postfix) with ESMTPSA id 21A0A46026E; Thu, 29 Oct 2015 13:53:26 -0500 (CDT) Subject: Re: svn commit: r290130 - head/sys/dev/ntb/ntb_hw To: John Baldwin , Steven Wahl References: <1968754.iCngWsIWpR@ralph.baldwin.cx> Cc: "svn-src-all@freebsd.org" , "kib@freebsd.org" , "cem@freebsd.org" , Eric Van Gyzen , "?Alan L. Cox" From: Alan Cox Message-ID: <56326B25.8000102@rice.edu> Date: Thu, 29 Oct 2015 13:53:25 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD i386; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <1968754.iCngWsIWpR@ralph.baldwin.cx> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 kscore.is_bulkscore=0 kscore.compositescore=1 compositescore=0.9 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 kscore.is_spamscore=0 rbsscore=0.9 spamscore=0 urlsuspectscore=0.9 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1507310000 definitions=main-1510290318 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Oct 2015 18:53:36 -0000 On 10/29/2015 12:02, John Baldwin wrote: > On Thursday, October 29, 2015 04:42:20 PM Steven Wahl wrote: >> We ran into this exact problem, pmap_change_attr not working right with large bars. I had been working up to seeing if this compiles on the current head, introducing myself to the community, seeing if this would be accepted. >> >> But looks like it's needed sooner, so in case it might save you some time, here's the patch we developed for this problem. >> >> --> Steve Wahl, Dell Compellent, Eden Prairie, MN > Adding alc@, but on first blush this looks correct to me. I agree. Commit it. >> commit 7d112aa8767390cb9dd020325a9f23aaac7fe5a0 >> Author: swahl >> Date: Thu Oct 1 14:36:48 2015 -0500 >> >> CQ00492954: FreeBSD traps on call to pmap_change_attr() with large PLX BAR >> >> If an address passed to pmap_change_attr() refers to a virtual address, >> the function must also change the direct mapping of this same >> region (if any) to match, or intel says the result is undefined. >> >> But the original code did not check if the virtual address actually fell >> within the direct mapped region before attempting to make this change. >> The attempt to look up the direct mapped page entries returned NULL, and >> this was dereferenced causing a panic. >> >> This is fixed by checking whether the address is outside of the direct >> mapped range before trying to change the direct mapped entries. >> >> diff --git a/src/sys/amd64/amd64/pmap.c b/src/sys/amd64/amd64/pmap.c >> index fe09ace..dee22de 100644 >> --- a/src/sys/amd64/amd64/pmap.c >> +++ b/src/sys/amd64/amd64/pmap.c >> @@ -6268,7 +6268,7 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size, int mode) >> */ >> for (tmpva = base; tmpva < base + size; ) { >> pdpe = pmap_pdpe(kernel_pmap, tmpva); >> - if (*pdpe == 0) >> + if (pdpe == NULL || *pdpe == 0) >> return (EINVAL); >> if (*pdpe & PG_PS) { >> /* >> @@ -6341,7 +6341,8 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size, int mode) >> X86_PG_PDE_CACHE); >> changed = TRUE; >> } >> - if (tmpva >= VM_MIN_KERNEL_ADDRESS) { >> + if (tmpva >= VM_MIN_KERNEL_ADDRESS && >> + (*pdpe & PG_PS_FRAME) < dmaplimit) { >> if (pa_start == pa_end) { >> /* Start physical address run. */ >> pa_start = *pdpe & PG_PS_FRAME; >> @@ -6370,7 +6371,8 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size, int mode) >> X86_PG_PDE_CACHE); >> changed = TRUE; >> } >> - if (tmpva >= VM_MIN_KERNEL_ADDRESS) { >> + if (tmpva >= VM_MIN_KERNEL_ADDRESS && >> + (*pde & PG_PS_FRAME) < dmaplimit) { >> if (pa_start == pa_end) { >> /* Start physical address run. */ >> pa_start = *pde & PG_PS_FRAME; >> @@ -6397,7 +6399,8 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size, int mode) >> X86_PG_PTE_CACHE); >> changed = TRUE; >> } >> - if (tmpva >= VM_MIN_KERNEL_ADDRESS) { >> + if (tmpva >= VM_MIN_KERNEL_ADDRESS && >> + (*pte & PG_FRAME) < dmaplimit) { >> if (pa_start == pa_end) { >> /* Start physical address run. */ >> pa_start = *pte & PG_FRAME; >> >