Annotation of /trunk/kernel26-xen/patches-2.6.25-r1/1013-2.6.25-xen-Add-proc-xen-privcmd.patch
Parent Directory | Revision Log
Revision 606 -
(hide annotations)
(download)
Thu May 22 23:13:13 2008 UTC (16 years, 4 months ago) by niro
File size: 9168 byte(s)
Thu May 22 23:13:13 2008 UTC (16 years, 4 months ago) by niro
File size: 9168 byte(s)
-ver bump to 2.6.25-magellan-r1: - linux-2.6.25.4 - fbcondecor-0.9.4 - squashfs-3.3 - unionfs-2.3.3 - tuxonice-3.0-rc7 - linux-phc-0.3.0 - acpi-dstd-0.9a - reiser4 - xen-3.2.0 . ipw3945-1.2.2
1 | niro | 606 | From e217efac809f98813a03237ebd1ba25c2033c2d9 Mon Sep 17 00:00:00 2001 |
2 | From: Mark McLoughlin <markmc@redhat.com> | ||
3 | Date: Mon, 4 Feb 2008 08:24:57 +0000 | ||
4 | Subject: [PATCH] xen: Add /proc/xen/privcmd | ||
5 | |||
6 | /proc/xen/privcmd is an ioctl() interface which allows | ||
7 | userspace apps to invoke hypercalls. | ||
8 | |||
9 | There should also be an ioctl (IOCTL_PRIVCMD_MMAP) | ||
10 | which is used to map foreign pages into a processes | ||
11 | address space, but we leave this unimplemented for | ||
12 | now pending further work on foreign page support. | ||
13 | |||
14 | Signed-off-by: Mark McLoughlin <markmc@redhat.com> | ||
15 | --- | ||
16 | drivers/xen/xenctrl/Makefile | 1 + | ||
17 | drivers/xen/xenctrl/main.c | 6 +++ | ||
18 | drivers/xen/xenctrl/privcmd.c | 81 +++++++++++++++++++++++++++++++++++++++ | ||
19 | drivers/xen/xenctrl/xenctrl.h | 6 +++ | ||
20 | include/asm-x86/xen/hypercall.h | 28 +++++++++++++ | ||
21 | include/xen/sys/privcmd.h | 79 ++++++++++++++++++++++++++++++++++++++ | ||
22 | 6 files changed, 201 insertions(+), 0 deletions(-) | ||
23 | create mode 100644 drivers/xen/xenctrl/privcmd.c | ||
24 | create mode 100644 include/xen/sys/privcmd.h | ||
25 | |||
26 | diff --git a/drivers/xen/xenctrl/Makefile b/drivers/xen/xenctrl/Makefile | ||
27 | index 631f535..8a706cb 100644 | ||
28 | --- a/drivers/xen/xenctrl/Makefile | ||
29 | +++ b/drivers/xen/xenctrl/Makefile | ||
30 | @@ -3,3 +3,4 @@ obj-$(CONFIG_XENCTRL) += xenctrl.o | ||
31 | xenctrl-objs = | ||
32 | xenctrl-objs += main.o | ||
33 | xenctrl-objs += capabilities.o | ||
34 | +xenctrl-objs += privcmd.o | ||
35 | diff --git a/drivers/xen/xenctrl/main.c b/drivers/xen/xenctrl/main.c | ||
36 | index 0e42f7e..d1fe6ef 100644 | ||
37 | --- a/drivers/xen/xenctrl/main.c | ||
38 | +++ b/drivers/xen/xenctrl/main.c | ||
39 | @@ -55,14 +55,20 @@ static int __init xenctrl_init(void) | ||
40 | if (ret) | ||
41 | goto fail1; | ||
42 | |||
43 | + ret = privcmd_create_proc_entry(); | ||
44 | + if (ret) | ||
45 | + goto fail2; | ||
46 | + | ||
47 | return 0; | ||
48 | |||
49 | + fail2: capabilities_remove_proc_entry(); | ||
50 | fail1: remove_proc_entry("xen", NULL); | ||
51 | return ret; | ||
52 | } | ||
53 | |||
54 | static void __exit xenctrl_exit(void) | ||
55 | { | ||
56 | + privcmd_remove_proc_entry(); | ||
57 | capabilities_remove_proc_entry(); | ||
58 | remove_proc_entry("xen", NULL); | ||
59 | } | ||
60 | diff --git a/drivers/xen/xenctrl/privcmd.c b/drivers/xen/xenctrl/privcmd.c | ||
61 | new file mode 100644 | ||
62 | index 0000000..58c4b83 | ||
63 | --- /dev/null | ||
64 | +++ b/drivers/xen/xenctrl/privcmd.c | ||
65 | @@ -0,0 +1,81 @@ | ||
66 | +/****************************************************************************** | ||
67 | + * privcmd.c | ||
68 | + * | ||
69 | + * Interface to privileged domain-0 commands. | ||
70 | + * | ||
71 | + * Copyright (c) 2002-2004, K A Fraser, B Dragovic | ||
72 | + * | ||
73 | + * This program is free software; you can redistribute it and/or | ||
74 | + * modify it under the terms of the GNU General Public License version 2 | ||
75 | + * as published by the Free Software Foundation; or, when distributed | ||
76 | + * separately from the Linux kernel or incorporated into other | ||
77 | + * software packages, subject to the following license: | ||
78 | + * | ||
79 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
80 | + * of this source file (the "Software"), to deal in the Software without | ||
81 | + * restriction, including without limitation the rights to use, copy, modify, | ||
82 | + * merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
83 | + * and to permit persons to whom the Software is furnished to do so, subject to | ||
84 | + * the following conditions: | ||
85 | + * | ||
86 | + * The above copyright notice and this permission notice shall be included in | ||
87 | + * all copies or substantial portions of the Software. | ||
88 | + * | ||
89 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
90 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
91 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
92 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
93 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
94 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
95 | + * IN THE SOFTWARE. | ||
96 | + */ | ||
97 | + | ||
98 | +#include <linux/proc_fs.h> | ||
99 | +#include <linux/module.h> | ||
100 | +#include <linux/uaccess.h> | ||
101 | +#include <asm/xen/hypervisor.h> | ||
102 | +#include <xen/sys/privcmd.h> | ||
103 | + | ||
104 | +static long privcmd_ioctl(struct file *file, unsigned int cmd, | ||
105 | + unsigned long arg) | ||
106 | +{ | ||
107 | + switch (cmd) { | ||
108 | + case IOCTL_PRIVCMD_HYPERCALL: { | ||
109 | + privcmd_hypercall_t cmd; | ||
110 | + | ||
111 | + if (copy_from_user(&cmd, (void __user *)arg, sizeof(cmd))) | ||
112 | + return -EFAULT; | ||
113 | + | ||
114 | + return privcmd_hypercall(&cmd); | ||
115 | + } | ||
116 | + | ||
117 | + case IOCTL_PRIVCMD_MMAP: | ||
118 | + case IOCTL_PRIVCMD_MMAPBATCH: | ||
119 | + printk(KERN_WARNING "IOCTL_PRIVCMD_MMAP ioctl not yet implemented\n"); | ||
120 | + default: | ||
121 | + return -EINVAL; | ||
122 | + } | ||
123 | +} | ||
124 | + | ||
125 | +static const struct file_operations privcmd_file_ops = { | ||
126 | + .unlocked_ioctl = privcmd_ioctl, | ||
127 | +}; | ||
128 | + | ||
129 | +int __init privcmd_create_proc_entry(void) | ||
130 | +{ | ||
131 | + static struct proc_dir_entry *entry; | ||
132 | + | ||
133 | + entry = create_proc_entry("xen/privcmd", 0400, NULL); | ||
134 | + if (!entry) | ||
135 | + return -ENOMEM; | ||
136 | + | ||
137 | + entry->owner = THIS_MODULE; | ||
138 | + entry->proc_fops = &privcmd_file_ops; | ||
139 | + | ||
140 | + return 0; | ||
141 | +} | ||
142 | + | ||
143 | +void __exit privcmd_remove_proc_entry(void) | ||
144 | +{ | ||
145 | + remove_proc_entry("xen/privcmd", NULL); | ||
146 | +} | ||
147 | diff --git a/drivers/xen/xenctrl/xenctrl.h b/drivers/xen/xenctrl/xenctrl.h | ||
148 | index 7378dde..a35209a 100644 | ||
149 | --- a/drivers/xen/xenctrl/xenctrl.h | ||
150 | +++ b/drivers/xen/xenctrl/xenctrl.h | ||
151 | @@ -37,3 +37,9 @@ | ||
152 | */ | ||
153 | int capabilities_create_proc_entry(void) __init; | ||
154 | void capabilities_remove_proc_entry(void) __exit; | ||
155 | + | ||
156 | +/* | ||
157 | + * privcmd.c | ||
158 | + */ | ||
159 | +int privcmd_create_proc_entry(void) __init; | ||
160 | +void privcmd_remove_proc_entry(void) __exit; | ||
161 | diff --git a/include/asm-x86/xen/hypercall.h b/include/asm-x86/xen/hypercall.h | ||
162 | index bc0ee7d..cd554ca 100644 | ||
163 | --- a/include/asm-x86/xen/hypercall.h | ||
164 | +++ b/include/asm-x86/xen/hypercall.h | ||
165 | @@ -410,4 +410,32 @@ MULTI_stack_switch(struct multicall_entry *mcl, | ||
166 | mcl->args[1] = esp; | ||
167 | } | ||
168 | |||
169 | +#include <xen/sys/privcmd.h> | ||
170 | + | ||
171 | +static inline int privcmd_hypercall(privcmd_hypercall_t *hypercall) | ||
172 | +{ | ||
173 | + int ret; | ||
174 | + | ||
175 | + if (hypercall->op >= (PAGE_SIZE >> 5)) | ||
176 | + return -EINVAL; | ||
177 | + | ||
178 | + __asm__ __volatile__ ( | ||
179 | + "pushl %%ebx; pushl %%ecx; pushl %%edx; " | ||
180 | + "pushl %%esi; pushl %%edi; " | ||
181 | + "movl 8(%%eax),%%ebx ;" | ||
182 | + "movl 16(%%eax),%%ecx ;" | ||
183 | + "movl 24(%%eax),%%edx ;" | ||
184 | + "movl 32(%%eax),%%esi ;" | ||
185 | + "movl 40(%%eax),%%edi ;" | ||
186 | + "movl (%%eax),%%eax ;" | ||
187 | + "shll $5,%%eax ;" | ||
188 | + "addl $hypercall_page,%%eax ;" | ||
189 | + "call *%%eax ;" | ||
190 | + "popl %%edi; popl %%esi; popl %%edx; " | ||
191 | + "popl %%ecx; popl %%ebx" | ||
192 | + : "=a" (ret) : "0" (hypercall) : "memory" ); | ||
193 | + | ||
194 | + return ret; | ||
195 | +} | ||
196 | + | ||
197 | #endif /* __HYPERCALL_H__ */ | ||
198 | diff --git a/include/xen/sys/privcmd.h b/include/xen/sys/privcmd.h | ||
199 | new file mode 100644 | ||
200 | index 0000000..9cfa9d7 | ||
201 | --- /dev/null | ||
202 | +++ b/include/xen/sys/privcmd.h | ||
203 | @@ -0,0 +1,79 @@ | ||
204 | +/****************************************************************************** | ||
205 | + * privcmd.h | ||
206 | + * | ||
207 | + * Interface to /proc/xen/privcmd. | ||
208 | + * | ||
209 | + * Copyright (c) 2003-2005, K A Fraser | ||
210 | + * | ||
211 | + * This program is free software; you can redistribute it and/or | ||
212 | + * modify it under the terms of the GNU General Public License version 2 | ||
213 | + * as published by the Free Software Foundation; or, when distributed | ||
214 | + * separately from the Linux kernel or incorporated into other | ||
215 | + * software packages, subject to the following license: | ||
216 | + * | ||
217 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
218 | + * of this source file (the "Software"), to deal in the Software without | ||
219 | + * restriction, including without limitation the rights to use, copy, modify, | ||
220 | + * merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
221 | + * and to permit persons to whom the Software is furnished to do so, subject to | ||
222 | + * the following conditions: | ||
223 | + * | ||
224 | + * The above copyright notice and this permission notice shall be included in | ||
225 | + * all copies or substantial portions of the Software. | ||
226 | + * | ||
227 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
228 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
229 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
230 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
231 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
232 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
233 | + * IN THE SOFTWARE. | ||
234 | + */ | ||
235 | + | ||
236 | +#ifndef __LINUX_PUBLIC_PRIVCMD_H__ | ||
237 | +#define __LINUX_PUBLIC_PRIVCMD_H__ | ||
238 | + | ||
239 | +#include <linux/types.h> | ||
240 | + | ||
241 | +#ifndef __user | ||
242 | +#define __user | ||
243 | +#endif | ||
244 | + | ||
245 | +typedef struct privcmd_hypercall | ||
246 | +{ | ||
247 | + __u64 op; | ||
248 | + __u64 arg[5]; | ||
249 | +} privcmd_hypercall_t; | ||
250 | + | ||
251 | +typedef struct privcmd_mmap_entry { | ||
252 | + __u64 va; | ||
253 | + __u64 mfn; | ||
254 | + __u64 npages; | ||
255 | +} privcmd_mmap_entry_t; | ||
256 | + | ||
257 | +typedef struct privcmd_mmap { | ||
258 | + int num; | ||
259 | + domid_t dom; /* target domain */ | ||
260 | + privcmd_mmap_entry_t __user *entry; | ||
261 | +} privcmd_mmap_t; | ||
262 | + | ||
263 | +typedef struct privcmd_mmapbatch { | ||
264 | + int num; /* number of pages to populate */ | ||
265 | + domid_t dom; /* target domain */ | ||
266 | + __u64 addr; /* virtual address */ | ||
267 | + ulong __user *arr; /* array of mfns - top nibble set on err */ | ||
268 | +} privcmd_mmapbatch_t; | ||
269 | + | ||
270 | +/* | ||
271 | + * @cmd: IOCTL_PRIVCMD_HYPERCALL | ||
272 | + * @arg: &privcmd_hypercall_t | ||
273 | + * Return: Value returned from execution of the specified hypercall. | ||
274 | + */ | ||
275 | +#define IOCTL_PRIVCMD_HYPERCALL \ | ||
276 | + _IOC(_IOC_NONE, 'P', 0, sizeof(privcmd_hypercall_t)) | ||
277 | +#define IOCTL_PRIVCMD_MMAP \ | ||
278 | + _IOC(_IOC_NONE, 'P', 2, sizeof(privcmd_mmap_t)) | ||
279 | +#define IOCTL_PRIVCMD_MMAPBATCH \ | ||
280 | + _IOC(_IOC_NONE, 'P', 3, sizeof(privcmd_mmapbatch_t)) | ||
281 | + | ||
282 | +#endif /* __LINUX_PUBLIC_PRIVCMD_H__ */ | ||
283 | -- | ||
284 | 1.5.4.1 | ||
285 |