.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 OR MIT |
---|
1 | 2 | /****************************************************************************** |
---|
2 | 3 | * grant_table.c |
---|
3 | 4 | * x86 specific part |
---|
.. | .. |
---|
8 | 9 | * Copyright (c) 2004-2005, K A Fraser |
---|
9 | 10 | * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp> |
---|
10 | 11 | * VA Linux Systems Japan. Split out x86 specific part. |
---|
11 | | - * |
---|
12 | | - * This program is free software; you can redistribute it and/or |
---|
13 | | - * modify it under the terms of the GNU General Public License version 2 |
---|
14 | | - * as published by the Free Software Foundation; or, when distributed |
---|
15 | | - * separately from the Linux kernel or incorporated into other |
---|
16 | | - * software packages, subject to the following license: |
---|
17 | | - * |
---|
18 | | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
19 | | - * of this source file (the "Software"), to deal in the Software without |
---|
20 | | - * restriction, including without limitation the rights to use, copy, modify, |
---|
21 | | - * merge, publish, distribute, sublicense, and/or sell copies of the Software, |
---|
22 | | - * and to permit persons to whom the Software is furnished to do so, subject to |
---|
23 | | - * the following conditions: |
---|
24 | | - * |
---|
25 | | - * The above copyright notice and this permission notice shall be included in |
---|
26 | | - * all copies or substantial portions of the Software. |
---|
27 | | - * |
---|
28 | | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
29 | | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
30 | | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
31 | | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
32 | | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
33 | | - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
---|
34 | | - * IN THE SOFTWARE. |
---|
35 | 12 | */ |
---|
36 | 13 | |
---|
37 | 14 | #include <linux/sched.h> |
---|
.. | .. |
---|
44 | 21 | #include <xen/grant_table.h> |
---|
45 | 22 | #include <xen/xen.h> |
---|
46 | 23 | |
---|
47 | | -#include <asm/pgtable.h> |
---|
48 | 24 | |
---|
49 | 25 | static struct gnttab_vm_area { |
---|
50 | 26 | struct vm_struct *area; |
---|
51 | 27 | pte_t **ptes; |
---|
| 28 | + int idx; |
---|
52 | 29 | } gnttab_shared_vm_area, gnttab_status_vm_area; |
---|
53 | 30 | |
---|
54 | 31 | int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes, |
---|
.. | .. |
---|
114 | 91 | } |
---|
115 | 92 | } |
---|
116 | 93 | |
---|
| 94 | +static int gnttab_apply(pte_t *pte, unsigned long addr, void *data) |
---|
| 95 | +{ |
---|
| 96 | + struct gnttab_vm_area *area = data; |
---|
| 97 | + |
---|
| 98 | + area->ptes[area->idx++] = pte; |
---|
| 99 | + return 0; |
---|
| 100 | +} |
---|
| 101 | + |
---|
117 | 102 | static int arch_gnttab_valloc(struct gnttab_vm_area *area, unsigned nr_frames) |
---|
118 | 103 | { |
---|
119 | 104 | area->ptes = kmalloc_array(nr_frames, sizeof(*area->ptes), GFP_KERNEL); |
---|
120 | 105 | if (area->ptes == NULL) |
---|
121 | 106 | return -ENOMEM; |
---|
122 | | - |
---|
123 | | - area->area = alloc_vm_area(PAGE_SIZE * nr_frames, area->ptes); |
---|
124 | | - if (area->area == NULL) { |
---|
125 | | - kfree(area->ptes); |
---|
126 | | - return -ENOMEM; |
---|
127 | | - } |
---|
128 | | - |
---|
| 107 | + area->area = get_vm_area(PAGE_SIZE * nr_frames, VM_IOREMAP); |
---|
| 108 | + if (!area->area) |
---|
| 109 | + goto out_free_ptes; |
---|
| 110 | + if (apply_to_page_range(&init_mm, (unsigned long)area->area->addr, |
---|
| 111 | + PAGE_SIZE * nr_frames, gnttab_apply, area)) |
---|
| 112 | + goto out_free_vm_area; |
---|
129 | 113 | return 0; |
---|
| 114 | +out_free_vm_area: |
---|
| 115 | + free_vm_area(area->area); |
---|
| 116 | +out_free_ptes: |
---|
| 117 | + kfree(area->ptes); |
---|
| 118 | + return -ENOMEM; |
---|
130 | 119 | } |
---|
131 | 120 | |
---|
132 | 121 | static void arch_gnttab_vfree(struct gnttab_vm_area *area) |
---|