Tue Sep 1 11:24:14 2020 UTC ()
Fix braino in pmap_find_gnt(), really return the gnt entry covering the range
and not one that starts just after.
Fixes a KASSERT in pmap_remove_gnt().


(bouyer)
diff -r1.403 -r1.404 src/sys/arch/x86/x86/pmap.c

cvs diff -r1.403 -r1.404 src/sys/arch/x86/x86/pmap.c (expand / switch to unified diff)

--- src/sys/arch/x86/x86/pmap.c 2020/08/04 06:23:46 1.403
+++ src/sys/arch/x86/x86/pmap.c 2020/09/01 11:24:14 1.404
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.c,v 1.403 2020/08/04 06:23:46 skrll Exp $ */ 1/* $NetBSD: pmap.c,v 1.404 2020/09/01 11:24:14 bouyer Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2010, 2016, 2017, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran, and by Maxime Villard. 8 * by Andrew Doran, and by Maxime Villard.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -120,27 +120,27 @@ @@ -120,27 +120,27 @@
120 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 120 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
121 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 121 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
122 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 122 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
123 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 123 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
124 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 124 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
125 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 125 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
126 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 126 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
127 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 127 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
128 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 128 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
129 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 129 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
130 */ 130 */
131 131
132#include <sys/cdefs.h> 132#include <sys/cdefs.h>
133__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.403 2020/08/04 06:23:46 skrll Exp $"); 133__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.404 2020/09/01 11:24:14 bouyer Exp $");
134 134
135#include "opt_user_ldt.h" 135#include "opt_user_ldt.h"
136#include "opt_lockdebug.h" 136#include "opt_lockdebug.h"
137#include "opt_multiprocessor.h" 137#include "opt_multiprocessor.h"
138#include "opt_xen.h" 138#include "opt_xen.h"
139#include "opt_svs.h" 139#include "opt_svs.h"
140#include "opt_kaslr.h" 140#include "opt_kaslr.h"
141 141
142#define __MUTEX_PRIVATE /* for assertions */ 142#define __MUTEX_PRIVATE /* for assertions */
143 143
144#include <sys/param.h> 144#include <sys/param.h>
145#include <sys/systm.h> 145#include <sys/systm.h>
146#include <sys/proc.h> 146#include <sys/proc.h>
@@ -5072,27 +5072,27 @@ SLIST_HEAD(pmap_data_gnt_head, pmap_data @@ -5072,27 +5072,27 @@ SLIST_HEAD(pmap_data_gnt_head, pmap_data
5072 5072
5073static void pmap_remove_gnt(struct pmap *, vaddr_t, vaddr_t); 5073static void pmap_remove_gnt(struct pmap *, vaddr_t, vaddr_t);
5074 5074
5075static struct pmap_data_gnt * 5075static struct pmap_data_gnt *
5076pmap_find_gnt(struct pmap *pmap, vaddr_t sva, vaddr_t eva) 5076pmap_find_gnt(struct pmap *pmap, vaddr_t sva, vaddr_t eva)
5077{ 5077{
5078 struct pmap_data_gnt_head *headp; 5078 struct pmap_data_gnt_head *headp;
5079 struct pmap_data_gnt *pgnt; 5079 struct pmap_data_gnt *pgnt;
5080 5080
5081 KASSERT(mutex_owned(&pmap->pm_lock)); 5081 KASSERT(mutex_owned(&pmap->pm_lock));
5082 headp = pmap->pm_data; 5082 headp = pmap->pm_data;
5083 KASSERT(headp != NULL); 5083 KASSERT(headp != NULL);
5084 SLIST_FOREACH(pgnt, headp, pd_gnt_list) { 5084 SLIST_FOREACH(pgnt, headp, pd_gnt_list) {
5085 if (pgnt->pd_gnt_sva >= sva && pgnt->pd_gnt_sva <= eva) 5085 if (pgnt->pd_gnt_sva <= sva && eva <= pgnt->pd_gnt_eva)
5086 return pgnt; 5086 return pgnt;
5087 /* check that we're not overlapping part of a region */ 5087 /* check that we're not overlapping part of a region */
5088 KASSERT(pgnt->pd_gnt_sva >= eva || pgnt->pd_gnt_eva <= sva); 5088 KASSERT(pgnt->pd_gnt_sva >= eva || pgnt->pd_gnt_eva <= sva);
5089 } 5089 }
5090 return NULL; 5090 return NULL;
5091} 5091}
5092 5092
5093static void 5093static void
5094pmap_alloc_gnt(struct pmap *pmap, vaddr_t sva, int nentries, 5094pmap_alloc_gnt(struct pmap *pmap, vaddr_t sva, int nentries,
5095 const struct gnttab_map_grant_ref *ops) 5095 const struct gnttab_map_grant_ref *ops)
5096{ 5096{
5097 struct pmap_data_gnt_head *headp; 5097 struct pmap_data_gnt_head *headp;
5098 struct pmap_data_gnt *pgnt; 5098 struct pmap_data_gnt *pgnt;