diff options
5 files changed, 833 insertions, 0 deletions
diff --git a/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest.bb b/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest.bb new file mode 100644 index 0000000000..27d98a3049 --- /dev/null +++ b/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest.bb | |||
@@ -0,0 +1,104 @@ | |||
1 | SUMMARY = "Kernel selftest for Linux" | ||
2 | DESCRIPTION = "Kernel selftest for Linux" | ||
3 | LICENSE = "GPLv2" | ||
4 | |||
5 | LIC_FILES_CHKSUM = "file://COPYING;md5=d7810fab7487fb0aad327b76f1be7cd7 \ | ||
6 | " | ||
7 | |||
8 | # for musl libc | ||
9 | SRC_URI_libc-musl += "file://userfaultfd.patch \ | ||
10 | file://0001-bpf-test_progs.c-add-support-for-musllibc.patch \ | ||
11 | " | ||
12 | |||
13 | PACKAGECONFIG ??= "bpf vm" | ||
14 | |||
15 | PACKAGECONFIG[bpf] = ",,elfutils libcap libcap-ng rsync-native," | ||
16 | PACKAGECONFIG[vm] = ",,,libgcc bash" | ||
17 | |||
18 | do_patch[depends] += "virtual/kernel:do_shared_workdir" | ||
19 | |||
20 | inherit linux-kernel-base kernel-arch | ||
21 | |||
22 | do_populate_lic[depends] += "virtual/kernel:do_patch" | ||
23 | |||
24 | S = "${WORKDIR}/${BP}" | ||
25 | |||
26 | # now we just test bpf and vm | ||
27 | # we will append other kernel selftest in the future | ||
28 | TEST_LIST = "bpf \ | ||
29 | vm \ | ||
30 | " | ||
31 | |||
32 | EXTRA_OEMAKE = '\ | ||
33 | CROSS_COMPILE=${TARGET_PREFIX} \ | ||
34 | ARCH=${ARCH} \ | ||
35 | CC="${CC}" \ | ||
36 | AR="${AR}" \ | ||
37 | LD="${LD}" \ | ||
38 | ' | ||
39 | |||
40 | EXTRA_OEMAKE += "\ | ||
41 | 'DESTDIR=${D}' \ | ||
42 | " | ||
43 | |||
44 | KERNEL_SELFTEST_SRC ?= "Makefile \ | ||
45 | include \ | ||
46 | tools \ | ||
47 | scripts \ | ||
48 | arch \ | ||
49 | COPYING \ | ||
50 | " | ||
51 | |||
52 | python __anonymous () { | ||
53 | import re | ||
54 | |||
55 | var = d.getVar('TARGET_CC_ARCH') | ||
56 | pattern = '_FORTIFY_SOURCE=[^0]' | ||
57 | |||
58 | if re.search(pattern, var): | ||
59 | d.appendVar('TARGET_CC_ARCH', " -O") | ||
60 | } | ||
61 | |||
62 | do_compile() { | ||
63 | for i in ${TEST_LIST} | ||
64 | do | ||
65 | oe_runmake -C ${S}/tools/testing/selftests/${i} | ||
66 | done | ||
67 | } | ||
68 | |||
69 | do_install() { | ||
70 | for i in ${TEST_LIST} | ||
71 | do | ||
72 | oe_runmake -C ${S}/tools/testing/selftests/${i} INSTALL_PATH=${D}/usr/kernel-selftest/${i} install | ||
73 | done | ||
74 | |||
75 | chown root:root -R ${D}/usr/kernel-selftest | ||
76 | } | ||
77 | |||
78 | do_configure() { | ||
79 | : | ||
80 | } | ||
81 | |||
82 | do_patch[prefuncs] += "copy_kselftest_source_from_kernel remove_clang_related" | ||
83 | python copy_kselftest_source_from_kernel() { | ||
84 | sources = (d.getVar("KERNEL_SELFTEST_SRC") or "").split() | ||
85 | src_dir = d.getVar("STAGING_KERNEL_DIR") | ||
86 | dest_dir = d.getVar("S") | ||
87 | bb.utils.mkdirhier(dest_dir) | ||
88 | for s in sources: | ||
89 | src = oe.path.join(src_dir, s) | ||
90 | dest = oe.path.join(dest_dir, s) | ||
91 | if os.path.isdir(src): | ||
92 | oe.path.copytree(src, dest) | ||
93 | else: | ||
94 | bb.utils.copyfile(src, dest) | ||
95 | } | ||
96 | |||
97 | remove_clang_related() { | ||
98 | sed -i -e '/test_pkt_access/d' -e '/test_pkt_md_access/d' ${S}/tools/testing/selftests/bpf/Makefile | ||
99 | } | ||
100 | |||
101 | PACKAGE_ARCH = "${MACHINE_ARCH}" | ||
102 | |||
103 | INHIBIT_PACKAGE_DEBUG_SPLIT="1" | ||
104 | FILES_${PN} += "/usr/kernel-selftest" | ||
diff --git a/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/0001-bpf-test_progs.c-add-support-for-musllibc.patch b/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/0001-bpf-test_progs.c-add-support-for-musllibc.patch new file mode 100644 index 0000000000..5f25426811 --- /dev/null +++ b/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/0001-bpf-test_progs.c-add-support-for-musllibc.patch | |||
@@ -0,0 +1,25 @@ | |||
1 | From a2e6b8fde28b743b69990a4e16c296e099631ed4 Mon Sep 17 00:00:00 2001 | ||
2 | From: "Hongzhi.Song" <hongzhi.song@windriver.com> | ||
3 | Date: Mon, 23 Jul 2018 00:56:19 -0700 | ||
4 | Subject: [PATCH] bpf: test_progs.c add support for musllibc | ||
5 | |||
6 | Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com> | ||
7 | --- | ||
8 | tools/testing/selftests/bpf/test_progs.c | 1 + | ||
9 | 1 file changed, 1 insertion(+) | ||
10 | |||
11 | diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c | ||
12 | index 11ee25c..21b27b7 100644 | ||
13 | --- a/tools/testing/selftests/bpf/test_progs.c | ||
14 | +++ b/tools/testing/selftests/bpf/test_progs.c | ||
15 | @@ -4,6 +4,7 @@ | ||
16 | * modify it under the terms of version 2 of the GNU General Public | ||
17 | * License as published by the Free Software Foundation. | ||
18 | */ | ||
19 | +#define __always_inline __inline __attribute__ ((__always_inline__)) | ||
20 | #include <stdio.h> | ||
21 | #include <unistd.h> | ||
22 | #include <errno.h> | ||
23 | -- | ||
24 | 2.11.0 | ||
25 | |||
diff --git a/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/0001-swap.h-micro-define-to-support-musl-libc.patch b/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/0001-swap.h-micro-define-to-support-musl-libc.patch new file mode 100644 index 0000000000..e2245fc4c2 --- /dev/null +++ b/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/0001-swap.h-micro-define-to-support-musl-libc.patch | |||
@@ -0,0 +1,26 @@ | |||
1 | From c21dfb0dfdfec281479e267ad7fe9a8d4ba15a70 Mon Sep 17 00:00:00 2001 | ||
2 | From: "Hongzhi.Song" <hongzhi.song@windriver.com> | ||
3 | Date: Tue, 17 Jul 2018 23:47:48 -0700 | ||
4 | Subject: [PATCH] add micro define to support musl libc | ||
5 | |||
6 | Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com> | ||
7 | --- | ||
8 | recipe-sysroot/usr/include/linux/swab.h | 2 ++ | ||
9 | 1 file changed, 2 insertions(+) | ||
10 | |||
11 | diff --git a/recipe-sysroot/usr/include/linux/swab.h b/recipe-sysroot/usr/include/linux/swab.h | ||
12 | index afb7eb7..33efa10 100644 | ||
13 | --- a/recipe-sysroot/usr/include/linux/swab.h | ||
14 | +++ b/recipe-sysroot/usr/include/linux/swab.h | ||
15 | @@ -6,6 +6,8 @@ | ||
16 | |||
17 | #include <asm/swab.h> | ||
18 | |||
19 | +#define __always_inline __inline __attribute__ ((__always_inline__)) | ||
20 | + | ||
21 | /* | ||
22 | * casts are necessary for constants, because we never know how for sure | ||
23 | * how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way. | ||
24 | -- | ||
25 | 2.11.0 | ||
26 | |||
diff --git a/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/COPYING b/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/COPYING new file mode 100644 index 0000000000..ca442d313d --- /dev/null +++ b/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/COPYING | |||
@@ -0,0 +1,356 @@ | |||
1 | |||
2 | NOTE! This copyright does *not* cover user programs that use kernel | ||
3 | services by normal system calls - this is merely considered normal use | ||
4 | of the kernel, and does *not* fall under the heading of "derived work". | ||
5 | Also note that the GPL below is copyrighted by the Free Software | ||
6 | Foundation, but the instance of code that it refers to (the Linux | ||
7 | kernel) is copyrighted by me and others who actually wrote it. | ||
8 | |||
9 | Also note that the only valid version of the GPL as far as the kernel | ||
10 | is concerned is _this_ particular version of the license (ie v2, not | ||
11 | v2.2 or v3.x or whatever), unless explicitly otherwise stated. | ||
12 | |||
13 | Linus Torvalds | ||
14 | |||
15 | ---------------------------------------- | ||
16 | |||
17 | GNU GENERAL PUBLIC LICENSE | ||
18 | Version 2, June 1991 | ||
19 | |||
20 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. | ||
21 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | Everyone is permitted to copy and distribute verbatim copies | ||
23 | of this license document, but changing it is not allowed. | ||
24 | |||
25 | Preamble | ||
26 | |||
27 | The licenses for most software are designed to take away your | ||
28 | freedom to share and change it. By contrast, the GNU General Public | ||
29 | License is intended to guarantee your freedom to share and change free | ||
30 | software--to make sure the software is free for all its users. This | ||
31 | General Public License applies to most of the Free Software | ||
32 | Foundation's software and to any other program whose authors commit to | ||
33 | using it. (Some other Free Software Foundation software is covered by | ||
34 | the GNU Library General Public License instead.) You can apply it to | ||
35 | your programs, too. | ||
36 | |||
37 | When we speak of free software, we are referring to freedom, not | ||
38 | price. Our General Public Licenses are designed to make sure that you | ||
39 | have the freedom to distribute copies of free software (and charge for | ||
40 | this service if you wish), that you receive source code or can get it | ||
41 | if you want it, that you can change the software or use pieces of it | ||
42 | in new free programs; and that you know you can do these things. | ||
43 | |||
44 | To protect your rights, we need to make restrictions that forbid | ||
45 | anyone to deny you these rights or to ask you to surrender the rights. | ||
46 | These restrictions translate to certain responsibilities for you if you | ||
47 | distribute copies of the software, or if you modify it. | ||
48 | |||
49 | For example, if you distribute copies of such a program, whether | ||
50 | gratis or for a fee, you must give the recipients all the rights that | ||
51 | you have. You must make sure that they, too, receive or can get the | ||
52 | source code. And you must show them these terms so they know their | ||
53 | rights. | ||
54 | |||
55 | We protect your rights with two steps: (1) copyright the software, and | ||
56 | (2) offer you this license which gives you legal permission to copy, | ||
57 | distribute and/or modify the software. | ||
58 | |||
59 | Also, for each author's protection and ours, we want to make certain | ||
60 | that everyone understands that there is no warranty for this free | ||
61 | software. If the software is modified by someone else and passed on, we | ||
62 | want its recipients to know that what they have is not the original, so | ||
63 | that any problems introduced by others will not reflect on the original | ||
64 | authors' reputations. | ||
65 | |||
66 | Finally, any free program is threatened constantly by software | ||
67 | patents. We wish to avoid the danger that redistributors of a free | ||
68 | program will individually obtain patent licenses, in effect making the | ||
69 | program proprietary. To prevent this, we have made it clear that any | ||
70 | patent must be licensed for everyone's free use or not licensed at all. | ||
71 | |||
72 | The precise terms and conditions for copying, distribution and | ||
73 | modification follow. | ||
74 | |||
75 | GNU GENERAL PUBLIC LICENSE | ||
76 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
77 | |||
78 | 0. This License applies to any program or other work which contains | ||
79 | a notice placed by the copyright holder saying it may be distributed | ||
80 | under the terms of this General Public License. The "Program", below, | ||
81 | refers to any such program or work, and a "work based on the Program" | ||
82 | means either the Program or any derivative work under copyright law: | ||
83 | that is to say, a work containing the Program or a portion of it, | ||
84 | either verbatim or with modifications and/or translated into another | ||
85 | language. (Hereinafter, translation is included without limitation in | ||
86 | the term "modification".) Each licensee is addressed as "you". | ||
87 | |||
88 | Activities other than copying, distribution and modification are not | ||
89 | covered by this License; they are outside its scope. The act of | ||
90 | running the Program is not restricted, and the output from the Program | ||
91 | is covered only if its contents constitute a work based on the | ||
92 | Program (independent of having been made by running the Program). | ||
93 | Whether that is true depends on what the Program does. | ||
94 | |||
95 | 1. You may copy and distribute verbatim copies of the Program's | ||
96 | source code as you receive it, in any medium, provided that you | ||
97 | conspicuously and appropriately publish on each copy an appropriate | ||
98 | copyright notice and disclaimer of warranty; keep intact all the | ||
99 | notices that refer to this License and to the absence of any warranty; | ||
100 | and give any other recipients of the Program a copy of this License | ||
101 | along with the Program. | ||
102 | |||
103 | You may charge a fee for the physical act of transferring a copy, and | ||
104 | you may at your option offer warranty protection in exchange for a fee. | ||
105 | |||
106 | 2. You may modify your copy or copies of the Program or any portion | ||
107 | of it, thus forming a work based on the Program, and copy and | ||
108 | distribute such modifications or work under the terms of Section 1 | ||
109 | above, provided that you also meet all of these conditions: | ||
110 | |||
111 | a) You must cause the modified files to carry prominent notices | ||
112 | stating that you changed the files and the date of any change. | ||
113 | |||
114 | b) You must cause any work that you distribute or publish, that in | ||
115 | whole or in part contains or is derived from the Program or any | ||
116 | part thereof, to be licensed as a whole at no charge to all third | ||
117 | parties under the terms of this License. | ||
118 | |||
119 | c) If the modified program normally reads commands interactively | ||
120 | when run, you must cause it, when started running for such | ||
121 | interactive use in the most ordinary way, to print or display an | ||
122 | announcement including an appropriate copyright notice and a | ||
123 | notice that there is no warranty (or else, saying that you provide | ||
124 | a warranty) and that users may redistribute the program under | ||
125 | these conditions, and telling the user how to view a copy of this | ||
126 | License. (Exception: if the Program itself is interactive but | ||
127 | does not normally print such an announcement, your work based on | ||
128 | the Program is not required to print an announcement.) | ||
129 | |||
130 | These requirements apply to the modified work as a whole. If | ||
131 | identifiable sections of that work are not derived from the Program, | ||
132 | and can be reasonably considered independent and separate works in | ||
133 | themselves, then this License, and its terms, do not apply to those | ||
134 | sections when you distribute them as separate works. But when you | ||
135 | distribute the same sections as part of a whole which is a work based | ||
136 | on the Program, the distribution of the whole must be on the terms of | ||
137 | this License, whose permissions for other licensees extend to the | ||
138 | entire whole, and thus to each and every part regardless of who wrote it. | ||
139 | |||
140 | Thus, it is not the intent of this section to claim rights or contest | ||
141 | your rights to work written entirely by you; rather, the intent is to | ||
142 | exercise the right to control the distribution of derivative or | ||
143 | collective works based on the Program. | ||
144 | |||
145 | In addition, mere aggregation of another work not based on the Program | ||
146 | with the Program (or with a work based on the Program) on a volume of | ||
147 | a storage or distribution medium does not bring the other work under | ||
148 | the scope of this License. | ||
149 | |||
150 | 3. You may copy and distribute the Program (or a work based on it, | ||
151 | under Section 2) in object code or executable form under the terms of | ||
152 | Sections 1 and 2 above provided that you also do one of the following: | ||
153 | |||
154 | a) Accompany it with the complete corresponding machine-readable | ||
155 | source code, which must be distributed under the terms of Sections | ||
156 | 1 and 2 above on a medium customarily used for software interchange; or, | ||
157 | |||
158 | b) Accompany it with a written offer, valid for at least three | ||
159 | years, to give any third party, for a charge no more than your | ||
160 | cost of physically performing source distribution, a complete | ||
161 | machine-readable copy of the corresponding source code, to be | ||
162 | distributed under the terms of Sections 1 and 2 above on a medium | ||
163 | customarily used for software interchange; or, | ||
164 | |||
165 | c) Accompany it with the information you received as to the offer | ||
166 | to distribute corresponding source code. (This alternative is | ||
167 | allowed only for noncommercial distribution and only if you | ||
168 | received the program in object code or executable form with such | ||
169 | an offer, in accord with Subsection b above.) | ||
170 | |||
171 | The source code for a work means the preferred form of the work for | ||
172 | making modifications to it. For an executable work, complete source | ||
173 | code means all the source code for all modules it contains, plus any | ||
174 | associated interface definition files, plus the scripts used to | ||
175 | control compilation and installation of the executable. However, as a | ||
176 | special exception, the source code distributed need not include | ||
177 | anything that is normally distributed (in either source or binary | ||
178 | form) with the major components (compiler, kernel, and so on) of the | ||
179 | operating system on which the executable runs, unless that component | ||
180 | itself accompanies the executable. | ||
181 | |||
182 | If distribution of executable or object code is made by offering | ||
183 | access to copy from a designated place, then offering equivalent | ||
184 | access to copy the source code from the same place counts as | ||
185 | distribution of the source code, even though third parties are not | ||
186 | compelled to copy the source along with the object code. | ||
187 | |||
188 | 4. You may not copy, modify, sublicense, or distribute the Program | ||
189 | except as expressly provided under this License. Any attempt | ||
190 | otherwise to copy, modify, sublicense or distribute the Program is | ||
191 | void, and will automatically terminate your rights under this License. | ||
192 | However, parties who have received copies, or rights, from you under | ||
193 | this License will not have their licenses terminated so long as such | ||
194 | parties remain in full compliance. | ||
195 | |||
196 | 5. You are not required to accept this License, since you have not | ||
197 | signed it. However, nothing else grants you permission to modify or | ||
198 | distribute the Program or its derivative works. These actions are | ||
199 | prohibited by law if you do not accept this License. Therefore, by | ||
200 | modifying or distributing the Program (or any work based on the | ||
201 | Program), you indicate your acceptance of this License to do so, and | ||
202 | all its terms and conditions for copying, distributing or modifying | ||
203 | the Program or works based on it. | ||
204 | |||
205 | 6. Each time you redistribute the Program (or any work based on the | ||
206 | Program), the recipient automatically receives a license from the | ||
207 | original licensor to copy, distribute or modify the Program subject to | ||
208 | these terms and conditions. You may not impose any further | ||
209 | restrictions on the recipients' exercise of the rights granted herein. | ||
210 | You are not responsible for enforcing compliance by third parties to | ||
211 | this License. | ||
212 | |||
213 | 7. If, as a consequence of a court judgment or allegation of patent | ||
214 | infringement or for any other reason (not limited to patent issues), | ||
215 | conditions are imposed on you (whether by court order, agreement or | ||
216 | otherwise) that contradict the conditions of this License, they do not | ||
217 | excuse you from the conditions of this License. If you cannot | ||
218 | distribute so as to satisfy simultaneously your obligations under this | ||
219 | License and any other pertinent obligations, then as a consequence you | ||
220 | may not distribute the Program at all. For example, if a patent | ||
221 | license would not permit royalty-free redistribution of the Program by | ||
222 | all those who receive copies directly or indirectly through you, then | ||
223 | the only way you could satisfy both it and this License would be to | ||
224 | refrain entirely from distribution of the Program. | ||
225 | |||
226 | If any portion of this section is held invalid or unenforceable under | ||
227 | any particular circumstance, the balance of the section is intended to | ||
228 | apply and the section as a whole is intended to apply in other | ||
229 | circumstances. | ||
230 | |||
231 | It is not the purpose of this section to induce you to infringe any | ||
232 | patents or other property right claims or to contest validity of any | ||
233 | such claims; this section has the sole purpose of protecting the | ||
234 | integrity of the free software distribution system, which is | ||
235 | implemented by public license practices. Many people have made | ||
236 | generous contributions to the wide range of software distributed | ||
237 | through that system in reliance on consistent application of that | ||
238 | system; it is up to the author/donor to decide if he or she is willing | ||
239 | to distribute software through any other system and a licensee cannot | ||
240 | impose that choice. | ||
241 | |||
242 | This section is intended to make thoroughly clear what is believed to | ||
243 | be a consequence of the rest of this License. | ||
244 | |||
245 | 8. If the distribution and/or use of the Program is restricted in | ||
246 | certain countries either by patents or by copyrighted interfaces, the | ||
247 | original copyright holder who places the Program under this License | ||
248 | may add an explicit geographical distribution limitation excluding | ||
249 | those countries, so that distribution is permitted only in or among | ||
250 | countries not thus excluded. In such case, this License incorporates | ||
251 | the limitation as if written in the body of this License. | ||
252 | |||
253 | 9. The Free Software Foundation may publish revised and/or new versions | ||
254 | of the General Public License from time to time. Such new versions will | ||
255 | be similar in spirit to the present version, but may differ in detail to | ||
256 | address new problems or concerns. | ||
257 | |||
258 | Each version is given a distinguishing version number. If the Program | ||
259 | specifies a version number of this License which applies to it and "any | ||
260 | later version", you have the option of following the terms and conditions | ||
261 | either of that version or of any later version published by the Free | ||
262 | Software Foundation. If the Program does not specify a version number of | ||
263 | this License, you may choose any version ever published by the Free Software | ||
264 | Foundation. | ||
265 | |||
266 | 10. If you wish to incorporate parts of the Program into other free | ||
267 | programs whose distribution conditions are different, write to the author | ||
268 | to ask for permission. For software which is copyrighted by the Free | ||
269 | Software Foundation, write to the Free Software Foundation; we sometimes | ||
270 | make exceptions for this. Our decision will be guided by the two goals | ||
271 | of preserving the free status of all derivatives of our free software and | ||
272 | of promoting the sharing and reuse of software generally. | ||
273 | |||
274 | NO WARRANTY | ||
275 | |||
276 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | ||
277 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | ||
278 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | ||
279 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | ||
280 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
281 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | ||
282 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | ||
283 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | ||
284 | REPAIR OR CORRECTION. | ||
285 | |||
286 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||
287 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | ||
288 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, | ||
289 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING | ||
290 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | ||
291 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | ||
292 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | ||
293 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | ||
294 | POSSIBILITY OF SUCH DAMAGES. | ||
295 | |||
296 | END OF TERMS AND CONDITIONS | ||
297 | |||
298 | How to Apply These Terms to Your New Programs | ||
299 | |||
300 | If you develop a new program, and you want it to be of the greatest | ||
301 | possible use to the public, the best way to achieve this is to make it | ||
302 | free software which everyone can redistribute and change under these terms. | ||
303 | |||
304 | To do so, attach the following notices to the program. It is safest | ||
305 | to attach them to the start of each source file to most effectively | ||
306 | convey the exclusion of warranty; and each file should have at least | ||
307 | the "copyright" line and a pointer to where the full notice is found. | ||
308 | |||
309 | <one line to give the program's name and a brief idea of what it does.> | ||
310 | Copyright (C) <year> <name of author> | ||
311 | |||
312 | This program is free software; you can redistribute it and/or modify | ||
313 | it under the terms of the GNU General Public License as published by | ||
314 | the Free Software Foundation; either version 2 of the License, or | ||
315 | (at your option) any later version. | ||
316 | |||
317 | This program is distributed in the hope that it will be useful, | ||
318 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
319 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
320 | GNU General Public License for more details. | ||
321 | |||
322 | You should have received a copy of the GNU General Public License | ||
323 | along with this program; if not, write to the Free Software | ||
324 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
325 | |||
326 | |||
327 | Also add information on how to contact you by electronic and paper mail. | ||
328 | |||
329 | If the program is interactive, make it output a short notice like this | ||
330 | when it starts in an interactive mode: | ||
331 | |||
332 | Gnomovision version 69, Copyright (C) year name of author | ||
333 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | ||
334 | This is free software, and you are welcome to redistribute it | ||
335 | under certain conditions; type `show c' for details. | ||
336 | |||
337 | The hypothetical commands `show w' and `show c' should show the appropriate | ||
338 | parts of the General Public License. Of course, the commands you use may | ||
339 | be called something other than `show w' and `show c'; they could even be | ||
340 | mouse-clicks or menu items--whatever suits your program. | ||
341 | |||
342 | You should also get your employer (if you work as a programmer) or your | ||
343 | school, if any, to sign a "copyright disclaimer" for the program, if | ||
344 | necessary. Here is a sample; alter the names: | ||
345 | |||
346 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program | ||
347 | `Gnomovision' (which makes passes at compilers) written by James Hacker. | ||
348 | |||
349 | <signature of Ty Coon>, 1 April 1989 | ||
350 | Ty Coon, President of Vice | ||
351 | |||
352 | This General Public License does not permit incorporating your program into | ||
353 | proprietary programs. If your program is a subroutine library, you may | ||
354 | consider it more useful to permit linking proprietary applications with the | ||
355 | library. If this is what you want to do, use the GNU Library General | ||
356 | Public License instead of this License. | ||
diff --git a/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/userfaultfd.patch b/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/userfaultfd.patch new file mode 100644 index 0000000000..bed20510e8 --- /dev/null +++ b/meta-oe/recipes-kernel/kernel-selftest/kernel-selftest/userfaultfd.patch | |||
@@ -0,0 +1,322 @@ | |||
1 | From c7b375747cffb627d02543d946b28525455d7d46 Mon Sep 17 00:00:00 2001 | ||
2 | From: "Hongzhi.Song" <hongzhi.song@windriver.com> | ||
3 | Date: Fri, 13 Jul 2018 06:06:19 -0700 | ||
4 | Subject: [PATCH] vm: add some funtions to support musl libc | ||
5 | |||
6 | Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com> | ||
7 | --- | ||
8 | tools/testing/selftests/vm/userfaultfd.c | 298 +++++++++++++++++++++++++++++++ | ||
9 | 1 file changed, 298 insertions(+) | ||
10 | |||
11 | diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c | ||
12 | index de2f9ec..dc73021 100644 | ||
13 | --- a/tools/testing/selftests/vm/userfaultfd.c | ||
14 | +++ b/tools/testing/selftests/vm/userfaultfd.c | ||
15 | @@ -71,6 +71,304 @@ | ||
16 | |||
17 | #ifdef __NR_userfaultfd | ||
18 | |||
19 | +/* Linear congruential. */ | ||
20 | +#define TYPE_0 0 | ||
21 | +#define BREAK_0 8 | ||
22 | +#define DEG_0 0 | ||
23 | +#define SEP_0 0 | ||
24 | + | ||
25 | +/* x**7 + x**3 + 1. */ | ||
26 | +#define TYPE_1 1 | ||
27 | +#define BREAK_1 32 | ||
28 | +#define DEG_1 7 | ||
29 | +#define SEP_1 3 | ||
30 | + | ||
31 | +/* x**15 + x + 1. */ | ||
32 | +#define TYPE_2 2 | ||
33 | +#define BREAK_2 64 | ||
34 | +#define DEG_2 15 | ||
35 | +#define SEP_2 1 | ||
36 | + | ||
37 | +/* x**31 + x**3 + 1. */ | ||
38 | +#define TYPE_3 3 | ||
39 | +#define BREAK_3 128 | ||
40 | +#define DEG_3 31 | ||
41 | +#define SEP_3 3 | ||
42 | + | ||
43 | +/* x**63 + x + 1. */ | ||
44 | +#define TYPE_4 4 | ||
45 | +#define BREAK_4 256 | ||
46 | +#define DEG_4 63 | ||
47 | +#define SEP_4 1 | ||
48 | + | ||
49 | +/* Array versions of the above information to make code run faster. | ||
50 | + Relies on fact that TYPE_i == i. */ | ||
51 | + | ||
52 | +#define MAX_TYPES 5 /* Max number of types above. */ | ||
53 | + | ||
54 | +#define __set_errno(val) (errno = (val)) | ||
55 | + | ||
56 | +struct random_data | ||
57 | + { | ||
58 | + int32_t *fptr; /* Front pointer. */ | ||
59 | + int32_t *rptr; /* Rear pointer. */ | ||
60 | + int32_t *state; /* Array of state values. */ | ||
61 | + int rand_type; /* Type of random number generator. */ | ||
62 | + int rand_deg; /* Degree of random number generator. */ | ||
63 | + int rand_sep; /* Distance between front and rear. */ | ||
64 | + int32_t *end_ptr; /* Pointer behind state table. */ | ||
65 | + }; | ||
66 | + | ||
67 | +struct random_poly_info | ||
68 | +{ | ||
69 | + int seps[MAX_TYPES]; | ||
70 | + int degrees[MAX_TYPES]; | ||
71 | +}; | ||
72 | + | ||
73 | +static const struct random_poly_info random_poly_info = | ||
74 | +{ | ||
75 | + { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }, | ||
76 | + { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 } | ||
77 | +}; | ||
78 | + | ||
79 | +/* If we are using the trivial TYPE_0 R.N.G., just do the old linear | ||
80 | + congruential bit. Otherwise, we do our fancy trinomial stuff, which is the | ||
81 | + same in all the other cases due to all the global variables that have been | ||
82 | + set up. The basic operation is to add the number at the rear pointer into | ||
83 | + the one at the front pointer. Then both pointers are advanced to the next | ||
84 | + location cyclically in the table. The value returned is the sum generated, | ||
85 | + reduced to 31 bits by throwing away the "least random" low bit. | ||
86 | + Note: The code takes advantage of the fact that both the front and | ||
87 | + rear pointers can't wrap on the same call by not testing the rear | ||
88 | + pointer if the front one has wrapped. Returns a 31-bit random number. */ | ||
89 | + | ||
90 | +int random_r (struct random_data *buf, int32_t *result) | ||
91 | +{ | ||
92 | + int32_t *state; | ||
93 | + | ||
94 | + if (buf == NULL || result == NULL) | ||
95 | + goto fail; | ||
96 | + | ||
97 | + state = buf->state; | ||
98 | + | ||
99 | + if (buf->rand_type == TYPE_0) | ||
100 | + { | ||
101 | + int32_t val = ((state[0] * 1103515245U) + 12345U) & 0x7fffffff; | ||
102 | + state[0] = val; | ||
103 | + *result = val; | ||
104 | + } | ||
105 | + else | ||
106 | + { | ||
107 | + int32_t *fptr = buf->fptr; | ||
108 | + int32_t *rptr = buf->rptr; | ||
109 | + int32_t *end_ptr = buf->end_ptr; | ||
110 | + uint32_t val; | ||
111 | + | ||
112 | + val = *fptr += (uint32_t) *rptr; | ||
113 | + /* Chucking least random bit. */ | ||
114 | + *result = val >> 1; | ||
115 | + ++fptr; | ||
116 | + if (fptr >= end_ptr) | ||
117 | + { | ||
118 | + fptr = state; | ||
119 | + ++rptr; | ||
120 | + } | ||
121 | + else | ||
122 | + { | ||
123 | + ++rptr; | ||
124 | + if (rptr >= end_ptr) | ||
125 | + rptr = state; | ||
126 | + } | ||
127 | + buf->fptr = fptr; | ||
128 | + buf->rptr = rptr; | ||
129 | + } | ||
130 | + return 0; | ||
131 | + | ||
132 | + fail: | ||
133 | + __set_errno (EINVAL); | ||
134 | + return -1; | ||
135 | +} | ||
136 | + | ||
137 | +/* Initialize the random number generator based on the given seed. If the | ||
138 | + type is the trivial no-state-information type, just remember the seed. | ||
139 | + Otherwise, initializes state[] based on the given "seed" via a linear | ||
140 | + congruential generator. Then, the pointers are set to known locations | ||
141 | + that are exactly rand_sep places apart. Lastly, it cycles the state | ||
142 | + information a given number of times to get rid of any initial dependencies | ||
143 | + introduced by the L.C.R.N.G. Note that the initialization of randtbl[] | ||
144 | + for default usage relies on values produced by this routine. */ | ||
145 | +int srandom_r (unsigned int seed, struct random_data *buf) | ||
146 | +{ | ||
147 | + int type; | ||
148 | + int32_t *state; | ||
149 | + long int i; | ||
150 | + int32_t word; | ||
151 | + int32_t *dst; | ||
152 | + int kc; | ||
153 | + | ||
154 | + if (buf == NULL) | ||
155 | + goto fail; | ||
156 | + type = buf->rand_type; | ||
157 | + if ((unsigned int) type >= MAX_TYPES) | ||
158 | + goto fail; | ||
159 | + | ||
160 | + state = buf->state; | ||
161 | + /* We must make sure the seed is not 0. Take arbitrarily 1 in this case. */ | ||
162 | + if (seed == 0) | ||
163 | + seed = 1; | ||
164 | + state[0] = seed; | ||
165 | + if (type == TYPE_0) | ||
166 | + goto done; | ||
167 | + | ||
168 | + dst = state; | ||
169 | + word = seed; | ||
170 | + kc = buf->rand_deg; | ||
171 | + for (i = 1; i < kc; ++i) | ||
172 | + { | ||
173 | + /* This does: | ||
174 | + state[i] = (16807 * state[i - 1]) % 2147483647; | ||
175 | + but avoids overflowing 31 bits. */ | ||
176 | + long int hi = word / 127773; | ||
177 | + long int lo = word % 127773; | ||
178 | + word = 16807 * lo - 2836 * hi; | ||
179 | + if (word < 0) | ||
180 | + word += 2147483647; | ||
181 | + *++dst = word; | ||
182 | + } | ||
183 | + | ||
184 | + buf->fptr = &state[buf->rand_sep]; | ||
185 | + buf->rptr = &state[0]; | ||
186 | + kc *= 10; | ||
187 | + while (--kc >= 0) | ||
188 | + { | ||
189 | + int32_t discard; | ||
190 | + (void) random_r (buf, &discard); | ||
191 | + } | ||
192 | + | ||
193 | + done: | ||
194 | + return 0; | ||
195 | + | ||
196 | + fail: | ||
197 | + return -1; | ||
198 | +} | ||
199 | + | ||
200 | +/* Initialize the state information in the given array of N bytes for | ||
201 | + future random number generation. Based on the number of bytes we | ||
202 | + are given, and the break values for the different R.N.G.'s, we choose | ||
203 | + the best (largest) one we can and set things up for it. srandom is | ||
204 | + then called to initialize the state information. Note that on return | ||
205 | + from srandom, we set state[-1] to be the type multiplexed with the current | ||
206 | + value of the rear pointer; this is so successive calls to initstate won't | ||
207 | + lose this information and will be able to restart with setstate. | ||
208 | + Note: The first thing we do is save the current state, if any, just like | ||
209 | + setstate so that it doesn't matter when initstate is called. | ||
210 | + Returns 0 on success, non-zero on failure. */ | ||
211 | +int initstate_r (unsigned int seed, char *arg_state, size_t n, | ||
212 | + struct random_data *buf) | ||
213 | +{ | ||
214 | + if (buf == NULL) | ||
215 | + goto fail; | ||
216 | + | ||
217 | + int32_t *old_state = buf->state; | ||
218 | + if (old_state != NULL) | ||
219 | + { | ||
220 | + int old_type = buf->rand_type; | ||
221 | + if (old_type == TYPE_0) | ||
222 | + old_state[-1] = TYPE_0; | ||
223 | + else | ||
224 | + old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type; | ||
225 | + } | ||
226 | + | ||
227 | + int type; | ||
228 | + if (n >= BREAK_3) | ||
229 | + type = n < BREAK_4 ? TYPE_3 : TYPE_4; | ||
230 | + else if (n < BREAK_1) | ||
231 | + { | ||
232 | + if (n < BREAK_0) | ||
233 | + goto fail; | ||
234 | + | ||
235 | + type = TYPE_0; | ||
236 | + } | ||
237 | + else | ||
238 | + type = n < BREAK_2 ? TYPE_1 : TYPE_2; | ||
239 | + | ||
240 | + int degree = random_poly_info.degrees[type]; | ||
241 | + int separation = random_poly_info.seps[type]; | ||
242 | + | ||
243 | + buf->rand_type = type; | ||
244 | + buf->rand_sep = separation; | ||
245 | + buf->rand_deg = degree; | ||
246 | + int32_t *state = &((int32_t *) arg_state)[1]; /* First location. */ | ||
247 | + /* Must set END_PTR before srandom. */ | ||
248 | + buf->end_ptr = &state[degree]; | ||
249 | + | ||
250 | + buf->state = state; | ||
251 | + | ||
252 | + srandom_r (seed, buf); | ||
253 | + | ||
254 | + state[-1] = TYPE_0; | ||
255 | + if (type != TYPE_0) | ||
256 | + state[-1] = (buf->rptr - state) * MAX_TYPES + type; | ||
257 | + | ||
258 | + return 0; | ||
259 | + | ||
260 | + fail: | ||
261 | + __set_errno (EINVAL); | ||
262 | + return -1; | ||
263 | +} | ||
264 | + | ||
265 | +/* Restore the state from the given state array. | ||
266 | + Note: It is important that we also remember the locations of the pointers | ||
267 | + in the current state information, and restore the locations of the pointers | ||
268 | + from the old state information. This is done by multiplexing the pointer | ||
269 | + location into the zeroth word of the state information. Note that due | ||
270 | + to the order in which things are done, it is OK to call setstate with the | ||
271 | + same state as the current state | ||
272 | + Returns 0 on success, non-zero on failure. */ | ||
273 | +int setstate_r (char *arg_state, struct random_data *buf) | ||
274 | +{ | ||
275 | + int32_t *new_state = 1 + (int32_t *) arg_state; | ||
276 | + int type; | ||
277 | + int old_type; | ||
278 | + int32_t *old_state; | ||
279 | + int degree; | ||
280 | + int separation; | ||
281 | + | ||
282 | + if (arg_state == NULL || buf == NULL) | ||
283 | + goto fail; | ||
284 | + | ||
285 | + old_type = buf->rand_type; | ||
286 | + old_state = buf->state; | ||
287 | + if (old_type == TYPE_0) | ||
288 | + old_state[-1] = TYPE_0; | ||
289 | + else | ||
290 | + old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type; | ||
291 | + | ||
292 | + type = new_state[-1] % MAX_TYPES; | ||
293 | + if (type < TYPE_0 || type > TYPE_4) | ||
294 | + goto fail; | ||
295 | + | ||
296 | + buf->rand_deg = degree = random_poly_info.degrees[type]; | ||
297 | + buf->rand_sep = separation = random_poly_info.seps[type]; | ||
298 | + buf->rand_type = type; | ||
299 | + | ||
300 | + if (type != TYPE_0) | ||
301 | + { | ||
302 | + int rear = new_state[-1] / MAX_TYPES; | ||
303 | + buf->rptr = &new_state[rear]; | ||
304 | + buf->fptr = &new_state[(rear + separation) % degree]; | ||
305 | + } | ||
306 | + buf->state = new_state; | ||
307 | + /* Set end_ptr too. */ | ||
308 | + buf->end_ptr = &new_state[degree]; | ||
309 | + | ||
310 | + return 0; | ||
311 | + | ||
312 | + fail: | ||
313 | + __set_errno (EINVAL); | ||
314 | + return -1; | ||
315 | +} | ||
316 | + | ||
317 | static unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; | ||
318 | |||
319 | #define BOUNCE_RANDOM (1<<0) | ||
320 | -- | ||
321 | 2.11.0 | ||
322 | |||