This source file includes following definitions.
- intel_vgpu_find_page_track
- intel_vgpu_register_page_track
- intel_vgpu_unregister_page_track
- intel_vgpu_enable_page_track
- intel_vgpu_disable_page_track
- intel_vgpu_page_track_handler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include "i915_drv.h"
24 #include "gvt.h"
25
26
27
28
29
30
31
32
33
34 struct intel_vgpu_page_track *intel_vgpu_find_page_track(
35 struct intel_vgpu *vgpu, unsigned long gfn)
36 {
37 return radix_tree_lookup(&vgpu->page_track_tree, gfn);
38 }
39
40
41
42
43
44
45
46
47
48
49
50 int intel_vgpu_register_page_track(struct intel_vgpu *vgpu, unsigned long gfn,
51 gvt_page_track_handler_t handler, void *priv)
52 {
53 struct intel_vgpu_page_track *track;
54 int ret;
55
56 track = intel_vgpu_find_page_track(vgpu, gfn);
57 if (track)
58 return -EEXIST;
59
60 track = kzalloc(sizeof(*track), GFP_KERNEL);
61 if (!track)
62 return -ENOMEM;
63
64 track->handler = handler;
65 track->priv_data = priv;
66
67 ret = radix_tree_insert(&vgpu->page_track_tree, gfn, track);
68 if (ret) {
69 kfree(track);
70 return ret;
71 }
72
73 return 0;
74 }
75
76
77
78
79
80
81
82 void intel_vgpu_unregister_page_track(struct intel_vgpu *vgpu,
83 unsigned long gfn)
84 {
85 struct intel_vgpu_page_track *track;
86
87 track = radix_tree_delete(&vgpu->page_track_tree, gfn);
88 if (track) {
89 if (track->tracked)
90 intel_gvt_hypervisor_disable_page_track(vgpu, gfn);
91 kfree(track);
92 }
93 }
94
95
96
97
98
99
100
101
102
103 int intel_vgpu_enable_page_track(struct intel_vgpu *vgpu, unsigned long gfn)
104 {
105 struct intel_vgpu_page_track *track;
106 int ret;
107
108 track = intel_vgpu_find_page_track(vgpu, gfn);
109 if (!track)
110 return -ENXIO;
111
112 if (track->tracked)
113 return 0;
114
115 ret = intel_gvt_hypervisor_enable_page_track(vgpu, gfn);
116 if (ret)
117 return ret;
118 track->tracked = true;
119 return 0;
120 }
121
122
123
124
125
126
127
128
129
130 int intel_vgpu_disable_page_track(struct intel_vgpu *vgpu, unsigned long gfn)
131 {
132 struct intel_vgpu_page_track *track;
133 int ret;
134
135 track = intel_vgpu_find_page_track(vgpu, gfn);
136 if (!track)
137 return -ENXIO;
138
139 if (!track->tracked)
140 return 0;
141
142 ret = intel_gvt_hypervisor_disable_page_track(vgpu, gfn);
143 if (ret)
144 return ret;
145 track->tracked = false;
146 return 0;
147 }
148
149
150
151
152
153
154
155
156
157
158
159 int intel_vgpu_page_track_handler(struct intel_vgpu *vgpu, u64 gpa,
160 void *data, unsigned int bytes)
161 {
162 struct intel_vgpu_page_track *page_track;
163 int ret = 0;
164
165 mutex_lock(&vgpu->vgpu_lock);
166
167 page_track = intel_vgpu_find_page_track(vgpu, gpa >> PAGE_SHIFT);
168 if (!page_track) {
169 ret = -ENXIO;
170 goto out;
171 }
172
173 if (unlikely(vgpu->failsafe)) {
174
175 intel_vgpu_disable_page_track(vgpu, gpa >> PAGE_SHIFT);
176 } else {
177 ret = page_track->handler(page_track, gpa, data, bytes);
178 if (ret)
179 gvt_err("guest page write error, gpa %llx\n", gpa);
180 }
181
182 out:
183 mutex_unlock(&vgpu->vgpu_lock);
184 return ret;
185 }