forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/arch/x86/xen/grant-table.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0 OR MIT
12 /******************************************************************************
23 * grant_table.c
34 * x86 specific part
....@@ -8,30 +9,6 @@
89 * Copyright (c) 2004-2005, K A Fraser
910 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
1011 * 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.
3512 */
3613
3714 #include <linux/sched.h>
....@@ -44,11 +21,11 @@
4421 #include <xen/grant_table.h>
4522 #include <xen/xen.h>
4623
47
-#include <asm/pgtable.h>
4824
4925 static struct gnttab_vm_area {
5026 struct vm_struct *area;
5127 pte_t **ptes;
28
+ int idx;
5229 } gnttab_shared_vm_area, gnttab_status_vm_area;
5330
5431 int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
....@@ -114,19 +91,31 @@
11491 }
11592 }
11693
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
+
117102 static int arch_gnttab_valloc(struct gnttab_vm_area *area, unsigned nr_frames)
118103 {
119104 area->ptes = kmalloc_array(nr_frames, sizeof(*area->ptes), GFP_KERNEL);
120105 if (area->ptes == NULL)
121106 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;
129113 return 0;
114
+out_free_vm_area:
115
+ free_vm_area(area->area);
116
+out_free_ptes:
117
+ kfree(area->ptes);
118
+ return -ENOMEM;
130119 }
131120
132121 static void arch_gnttab_vfree(struct gnttab_vm_area *area)