Ver código fonte

[linux] Add uaccess

Add user access API for linux.

On linux userspace virtual == user == phys addresses.  Physical
addresses also being the same is wrong, but there is no general way of
converting userspace addresses to physical as what appears to be
contiguous in userspace is physically fragmented.  Currently only the
DMA memory is special-cased, but its conversion to bus addresses is
done in phys_to_bus.  This is known to break virtio as it is passing
phys addresses to the virtual device.

Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Piotr Jaroszyński 14 anos atrás
pai
commit
a320085750

+ 1
- 0
src/config/defaults/linux.h Ver arquivo

@@ -9,6 +9,7 @@
9 9
 
10 10
 #define CONSOLE_LINUX
11 11
 #define TIMER_LINUX
12
+#define UACCESS_LINUX
12 13
 
13 14
 #define IMAGE_SCRIPT
14 15
 

+ 104
- 0
src/include/ipxe/linux/linux_uaccess.h Ver arquivo

@@ -0,0 +1,104 @@
1
+/*
2
+ * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
+ */
18
+
19
+#ifndef _IPXE_LINUX_UACCESS_H
20
+#define _IPXE_LINUX_UACCESS_H
21
+
22
+FILE_LICENCE(GPL2_OR_LATER);
23
+
24
+/** @file
25
+ *
26
+ * iPXE user access API for linux
27
+ *
28
+ * In linux userspace virtual == user == phys addresses.
29
+ * Physical addresses also being the same is wrong, but there is no general way
30
+ * of converting userspace addresses to physical as what appears to be
31
+ * contiguous in userspace is physically fragmented.
32
+ * Currently only the DMA memory is special-cased, but its conversion to bus
33
+ * addresses is done in phys_to_bus.
34
+ * This is known to break virtio as it is passing phys addresses to the virtual
35
+ * device.
36
+ */
37
+
38
+#ifdef UACCESS_LINUX
39
+#define UACCESS_PREFIX_linux
40
+#else
41
+#define UACCESS_PREFIX_linux __linux_
42
+#endif
43
+
44
+static inline __always_inline userptr_t
45
+UACCESS_INLINE(linux, phys_to_user)(unsigned long phys_addr)
46
+{
47
+	return phys_addr;
48
+}
49
+
50
+static inline __always_inline unsigned long
51
+UACCESS_INLINE(linux, user_to_phys)(userptr_t userptr, off_t offset)
52
+{
53
+	return userptr + offset;
54
+}
55
+
56
+static inline __always_inline userptr_t
57
+UACCESS_INLINE(linux, virt_to_user)(volatile const void *addr)
58
+{
59
+	return trivial_virt_to_user(addr);
60
+}
61
+
62
+static inline __always_inline void *
63
+UACCESS_INLINE(linux, user_to_virt)(userptr_t userptr, off_t offset)
64
+{
65
+	return trivial_user_to_virt(userptr, offset);
66
+}
67
+
68
+static inline __always_inline userptr_t
69
+UACCESS_INLINE(linux, userptr_add)(userptr_t userptr, off_t offset)
70
+{
71
+	return trivial_userptr_add(userptr, offset);
72
+}
73
+
74
+static inline __always_inline void
75
+UACCESS_INLINE(linux, memcpy_user)(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
76
+{
77
+	trivial_memcpy_user(dest, dest_off, src, src_off, len);
78
+}
79
+
80
+static inline __always_inline void
81
+UACCESS_INLINE(linux, memmove_user)(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
82
+{
83
+	trivial_memmove_user(dest, dest_off, src, src_off, len);
84
+}
85
+
86
+static inline __always_inline void
87
+UACCESS_INLINE(linux, memset_user)(userptr_t buffer, off_t offset, int c, size_t len)
88
+{
89
+	trivial_memset_user(buffer, offset, c, len);
90
+}
91
+
92
+static inline __always_inline size_t
93
+UACCESS_INLINE(linux, strlen_user)(userptr_t buffer, off_t offset)
94
+{
95
+	return trivial_strlen_user(buffer, offset);
96
+}
97
+
98
+static inline __always_inline off_t
99
+UACCESS_INLINE(linux, memchr_user)(userptr_t buffer, off_t offset, int c, size_t len)
100
+{
101
+	return trivial_memchr_user(buffer, offset, c, len);
102
+}
103
+
104
+#endif /* _IPXE_LINUX_UACCESS_H */

+ 1
- 0
src/include/ipxe/uaccess.h Ver arquivo

@@ -189,6 +189,7 @@ trivial_memchr_user ( userptr_t buffer, off_t offset, int c, size_t len ) {
189 189
 
190 190
 /* Include all architecture-independent user access API headers */
191 191
 #include <ipxe/efi/efi_uaccess.h>
192
+#include <ipxe/linux/linux_uaccess.h>
192 193
 
193 194
 /* Include all architecture-dependent user access API headers */
194 195
 #include <bits/uaccess.h>

+ 38
- 0
src/interface/linux/linux_uaccess.c Ver arquivo

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+FILE_LICENCE(GPL2_OR_LATER);
20
+
21
+#include <ipxe/uaccess.h>
22
+
23
+/** @file
24
+ *
25
+ * iPXE user access API for linux
26
+ *
27
+ */
28
+
29
+PROVIDE_UACCESS_INLINE(linux, phys_to_user);
30
+PROVIDE_UACCESS_INLINE(linux, user_to_phys);
31
+PROVIDE_UACCESS_INLINE(linux, virt_to_user);
32
+PROVIDE_UACCESS_INLINE(linux, user_to_virt);
33
+PROVIDE_UACCESS_INLINE(linux, userptr_add);
34
+PROVIDE_UACCESS_INLINE(linux, memcpy_user);
35
+PROVIDE_UACCESS_INLINE(linux, memmove_user);
36
+PROVIDE_UACCESS_INLINE(linux, memset_user);
37
+PROVIDE_UACCESS_INLINE(linux, strlen_user);
38
+PROVIDE_UACCESS_INLINE(linux, memchr_user);

Carregando…
Cancelar
Salvar