| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: xengnt.c,v 1.37 2020/04/25 15:26:18 bouyer Exp $ */ | | 1 | /* $NetBSD: xengnt.c,v 1.38 2020/05/13 16:13:14 jdolecek Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2006 Manuel Bouyer. | | 4 | * Copyright (c) 2006 Manuel Bouyer. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * | | 14 | * |
| @@ -16,27 +16,27 @@ | | | @@ -16,27 +16,27 @@ |
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | * | | 25 | * |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/cdefs.h> | | 28 | #include <sys/cdefs.h> |
29 | __KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.37 2020/04/25 15:26:18 bouyer Exp $"); | | 29 | __KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.38 2020/05/13 16:13:14 jdolecek Exp $"); |
30 | | | 30 | |
31 | #include <sys/types.h> | | 31 | #include <sys/types.h> |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/systm.h> | | 33 | #include <sys/systm.h> |
34 | #include <sys/kmem.h> | | 34 | #include <sys/kmem.h> |
35 | #include <sys/queue.h> | | 35 | #include <sys/queue.h> |
36 | #include <sys/extent.h> | | 36 | #include <sys/extent.h> |
37 | #include <sys/kernel.h> | | 37 | #include <sys/kernel.h> |
38 | #include <sys/mutex.h> | | 38 | #include <sys/mutex.h> |
39 | #include <uvm/uvm.h> | | 39 | #include <uvm/uvm.h> |
40 | | | 40 | |
41 | #include <xen/hypervisor.h> | | 41 | #include <xen/hypervisor.h> |
42 | #include <xen/xen.h> | | 42 | #include <xen/xen.h> |
| @@ -92,67 +92,66 @@ xengnt_init(void) | | | @@ -92,67 +92,66 @@ xengnt_init(void) |
92 | | | 92 | |
93 | query.dom = DOMID_SELF; | | 93 | query.dom = DOMID_SELF; |
94 | rc = HYPERVISOR_grant_table_op(GNTTABOP_query_size, &query, 1); | | 94 | rc = HYPERVISOR_grant_table_op(GNTTABOP_query_size, &query, 1); |
95 | if ((rc < 0) || (query.status != GNTST_okay)) | | 95 | if ((rc < 0) || (query.status != GNTST_okay)) |
96 | gnt_max_grant_frames = 4; /* Legacy max number of frames */ | | 96 | gnt_max_grant_frames = 4; /* Legacy max number of frames */ |
97 | else | | 97 | else |
98 | gnt_max_grant_frames = query.max_nr_frames; | | 98 | gnt_max_grant_frames = query.max_nr_frames; |
99 | | | 99 | |
100 | /* | | 100 | /* |
101 | * Always allocate max number of grant frames, never expand in runtime | | 101 | * Always allocate max number of grant frames, never expand in runtime |
102 | */ | | 102 | */ |
103 | gnt_nr_grant_frames = gnt_max_grant_frames; | | 103 | gnt_nr_grant_frames = gnt_max_grant_frames; |
104 | | | 104 | |
105 | | | | |
106 | struct gnttab_set_version gntversion; | | | |
107 | gntversion.version = 2; | | | |
108 | rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, &gntversion, 1); | | | |
109 | if (rc < 0 || gntversion.version != 2) | | | |
110 | panic("GNTTABOP_set_version 2 failed %d", rc); | | | |
111 | | | | |
112 | nr_grant_entries = | | 105 | nr_grant_entries = |
113 | gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE; | | 106 | gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE; |
114 | | | 107 | |
115 | grant_table = (void *)uvm_km_alloc(kernel_map, | | 108 | grant_table = (void *)uvm_km_alloc(kernel_map, |
116 | gnt_max_grant_frames * PAGE_SIZE, 0, UVM_KMF_VAONLY); | | 109 | gnt_max_grant_frames * PAGE_SIZE, 0, UVM_KMF_VAONLY); |
117 | if (grant_table == NULL) | | 110 | if (grant_table == NULL) |
118 | panic("xengnt_init() table no VM space"); | | 111 | panic("xengnt_init() table no VM space"); |
119 | | | 112 | |
120 | gnt_entries = kmem_alloc((nr_grant_entries + 1) * sizeof(grant_ref_t), | | 113 | gnt_entries = kmem_alloc((nr_grant_entries + 1) * sizeof(grant_ref_t), |
121 | KM_SLEEP); | | 114 | KM_SLEEP); |
122 | for (i = 0; i <= nr_grant_entries; i++) | | 115 | for (i = 0; i <= nr_grant_entries; i++) |
123 | gnt_entries[i] = XENGNT_NO_ENTRY; | | 116 | gnt_entries[i] = XENGNT_NO_ENTRY; |
124 | | | 117 | |
125 | gnt_status_frames = | | 118 | gnt_status_frames = |
126 | round_page(nr_grant_entries * sizeof(grant_status_t)) / PAGE_SIZE; | | 119 | round_page(nr_grant_entries * sizeof(grant_status_t)) / PAGE_SIZE; |
127 | grant_status = (void *)uvm_km_alloc(kernel_map, | | 120 | grant_status = (void *)uvm_km_alloc(kernel_map, |
128 | gnt_status_frames * PAGE_SIZE, 0, UVM_KMF_VAONLY); | | 121 | gnt_status_frames * PAGE_SIZE, 0, UVM_KMF_VAONLY); |
129 | if (grant_status == NULL) | | 122 | if (grant_status == NULL) |
130 | panic("xengnt_init() status no VM space"); | | 123 | panic("xengnt_init() status no VM space"); |
131 | | | 124 | |
132 | mutex_init(&grant_lock, MUTEX_DEFAULT, IPL_VM); | | 125 | mutex_init(&grant_lock, MUTEX_DEFAULT, IPL_VM); |
133 | | | 126 | |
134 | xengnt_resume(); | | 127 | xengnt_resume(); |
135 | | | | |
136 | } | | 128 | } |
137 | | | 129 | |
138 | /* | | 130 | /* |
139 | * Resume grant table state | | 131 | * Resume grant table state |
140 | */ | | 132 | */ |
141 | bool | | 133 | bool |
142 | xengnt_resume(void) | | 134 | xengnt_resume(void) |
143 | { | | 135 | { |
| | | 136 | int rc; |
144 | int previous_nr_grant_frames = gnt_nr_grant_frames; | | 137 | int previous_nr_grant_frames = gnt_nr_grant_frames; |
145 | | | 138 | |
| | | 139 | struct gnttab_set_version gntversion; |
| | | 140 | gntversion.version = 2; |
| | | 141 | rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, &gntversion, 1); |
| | | 142 | if (rc < 0 || gntversion.version != 2) |
| | | 143 | panic("GNTTABOP_set_version 2 failed %d", rc); |
| | | 144 | |
146 | last_gnt_entry = 0; | | 145 | last_gnt_entry = 0; |
147 | gnt_nr_grant_frames = 0; | | 146 | gnt_nr_grant_frames = 0; |
148 | | | 147 | |
149 | mutex_enter(&grant_lock); | | 148 | mutex_enter(&grant_lock); |
150 | while (gnt_nr_grant_frames < previous_nr_grant_frames) { | | 149 | while (gnt_nr_grant_frames < previous_nr_grant_frames) { |
151 | if (xengnt_more_entries() != 0) | | 150 | if (xengnt_more_entries() != 0) |
152 | panic("xengnt_resume: can't restore grant frames"); | | 151 | panic("xengnt_resume: can't restore grant frames"); |
153 | } | | 152 | } |
154 | xengnt_map_status(); | | 153 | xengnt_map_status(); |
155 | mutex_exit(&grant_lock); | | 154 | mutex_exit(&grant_lock); |
156 | return true; | | 155 | return true; |
157 | } | | 156 | } |
158 | | | 157 | |