diff options
Diffstat (limited to 'Documentation')
43 files changed, 4213 insertions, 178 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index a667eb1fc26e..7f1730f1a1ae 100644 --- a/Documentation/CodingStyle +++ b/Documentation/CodingStyle | |||
@@ -633,12 +633,27 @@ covers RTL which is used frequently with assembly language in the kernel. | |||
633 | 633 | ||
634 | Kernel developers like to be seen as literate. Do mind the spelling | 634 | Kernel developers like to be seen as literate. Do mind the spelling |
635 | of kernel messages to make a good impression. Do not use crippled | 635 | of kernel messages to make a good impression. Do not use crippled |
636 | words like "dont" and use "do not" or "don't" instead. | 636 | words like "dont"; use "do not" or "don't" instead. Make the messages |
637 | concise, clear, and unambiguous. | ||
637 | 638 | ||
638 | Kernel messages do not have to be terminated with a period. | 639 | Kernel messages do not have to be terminated with a period. |
639 | 640 | ||
640 | Printing numbers in parentheses (%d) adds no value and should be avoided. | 641 | Printing numbers in parentheses (%d) adds no value and should be avoided. |
641 | 642 | ||
643 | There are a number of driver model diagnostic macros in <linux/device.h> | ||
644 | which you should use to make sure messages are matched to the right device | ||
645 | and driver, and are tagged with the right level: dev_err(), dev_warn(), | ||
646 | dev_info(), and so forth. For messages that aren't associated with a | ||
647 | particular device, <linux/kernel.h> defines pr_debug() and pr_info(). | ||
648 | |||
649 | Coming up with good debugging messages can be quite a challenge; and once | ||
650 | you have them, they can be a huge help for remote troubleshooting. Such | ||
651 | messages should be compiled out when the DEBUG symbol is not defined (that | ||
652 | is, by default they are not included). When you use dev_dbg() or pr_debug(), | ||
653 | that's automatic. Many subsystems have Kconfig options to turn on -DDEBUG. | ||
654 | A related convention uses VERBOSE_DEBUG to add dev_vdbg() messages to the | ||
655 | ones already enabled by DEBUG. | ||
656 | |||
642 | 657 | ||
643 | Chapter 14: Allocating memory | 658 | Chapter 14: Allocating memory |
644 | 659 | ||
@@ -790,4 +805,5 @@ Kernel CodingStyle, by greg@kroah.com at OLS 2002: | |||
790 | http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/ | 805 | http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/ |
791 | 806 | ||
792 | -- | 807 | -- |
793 | Last updated on 2006-December-06. | 808 | Last updated on 2007-July-13. |
809 | |||
diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile index 6fd1646d3204..08687e45e19d 100644 --- a/Documentation/DocBook/Makefile +++ b/Documentation/DocBook/Makefile | |||
@@ -15,11 +15,11 @@ DOCBOOKS := wanbook.xml z8530book.xml mcabook.xml videobook.xml \ | |||
15 | 15 | ||
16 | ### | 16 | ### |
17 | # The build process is as follows (targets): | 17 | # The build process is as follows (targets): |
18 | # (xmldocs) | 18 | # (xmldocs) [by docproc] |
19 | # file.tmpl --> file.xml +--> file.ps (psdocs) | 19 | # file.tmpl --> file.xml +--> file.ps (psdocs) [by db2ps or xmlto] |
20 | # +--> file.pdf (pdfdocs) | 20 | # +--> file.pdf (pdfdocs) [by db2pdf or xmlto] |
21 | # +--> DIR=file (htmldocs) | 21 | # +--> DIR=file (htmldocs) [by xmlto] |
22 | # +--> man/ (mandocs) | 22 | # +--> man/ (mandocs) [by xmlto] |
23 | 23 | ||
24 | 24 | ||
25 | # for PDF and PS output you can choose between xmlto and docbook-utils tools | 25 | # for PDF and PS output you can choose between xmlto and docbook-utils tools |
diff --git a/Documentation/DocBook/kernel-api.tmpl b/Documentation/DocBook/kernel-api.tmpl index 46bcff2849bd..eb42bf9847cb 100644 --- a/Documentation/DocBook/kernel-api.tmpl +++ b/Documentation/DocBook/kernel-api.tmpl | |||
@@ -139,8 +139,10 @@ X!Ilib/string.c | |||
139 | !Elib/cmdline.c | 139 | !Elib/cmdline.c |
140 | </sect1> | 140 | </sect1> |
141 | 141 | ||
142 | <sect1><title>CRC Functions</title> | 142 | <sect1 id="crc"><title>CRC Functions</title> |
143 | !Elib/crc7.c | ||
143 | !Elib/crc16.c | 144 | !Elib/crc16.c |
145 | !Elib/crc-itu-t.c | ||
144 | !Elib/crc32.c | 146 | !Elib/crc32.c |
145 | !Elib/crc-ccitt.c | 147 | !Elib/crc-ccitt.c |
146 | </sect1> | 148 | </sect1> |
@@ -157,7 +159,6 @@ X!Ilib/string.c | |||
157 | !Earch/i386/lib/usercopy.c | 159 | !Earch/i386/lib/usercopy.c |
158 | </sect1> | 160 | </sect1> |
159 | <sect1><title>More Memory Management Functions</title> | 161 | <sect1><title>More Memory Management Functions</title> |
160 | !Iinclude/linux/rmap.h | ||
161 | !Emm/readahead.c | 162 | !Emm/readahead.c |
162 | !Emm/filemap.c | 163 | !Emm/filemap.c |
163 | !Emm/memory.c | 164 | !Emm/memory.c |
@@ -406,6 +407,10 @@ X!Edrivers/pnp/system.c | |||
406 | !Edrivers/pnp/manager.c | 407 | !Edrivers/pnp/manager.c |
407 | !Edrivers/pnp/support.c | 408 | !Edrivers/pnp/support.c |
408 | </sect1> | 409 | </sect1> |
410 | <sect1><title>Userspace IO devices</title> | ||
411 | !Edrivers/uio/uio.c | ||
412 | !Iinclude/linux/uio_driver.h | ||
413 | </sect1> | ||
409 | </chapter> | 414 | </chapter> |
410 | 415 | ||
411 | <chapter id="blkdev"> | 416 | <chapter id="blkdev"> |
diff --git a/Documentation/DocBook/uio-howto.tmpl b/Documentation/DocBook/uio-howto.tmpl new file mode 100644 index 000000000000..e3bb29a8d8dd --- /dev/null +++ b/Documentation/DocBook/uio-howto.tmpl | |||
@@ -0,0 +1,611 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" | ||
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" []> | ||
4 | |||
5 | <book id="index"> | ||
6 | <bookinfo> | ||
7 | <title>The Userspace I/O HOWTO</title> | ||
8 | |||
9 | <author> | ||
10 | <firstname>Hans-Jürgen</firstname> | ||
11 | <surname>Koch</surname> | ||
12 | <authorblurb><para>Linux developer, Linutronix</para></authorblurb> | ||
13 | <affiliation> | ||
14 | <orgname> | ||
15 | <ulink url="http://www.linutronix.de">Linutronix</ulink> | ||
16 | </orgname> | ||
17 | |||
18 | <address> | ||
19 | <email>hjk@linutronix.de</email> | ||
20 | </address> | ||
21 | </affiliation> | ||
22 | </author> | ||
23 | |||
24 | <pubdate>2006-12-11</pubdate> | ||
25 | |||
26 | <abstract> | ||
27 | <para>This HOWTO describes concept and usage of Linux kernel's | ||
28 | Userspace I/O system.</para> | ||
29 | </abstract> | ||
30 | |||
31 | <revhistory> | ||
32 | <revision> | ||
33 | <revnumber>0.3</revnumber> | ||
34 | <date>2007-04-29</date> | ||
35 | <authorinitials>hjk</authorinitials> | ||
36 | <revremark>Added section about userspace drivers.</revremark> | ||
37 | </revision> | ||
38 | <revision> | ||
39 | <revnumber>0.2</revnumber> | ||
40 | <date>2007-02-13</date> | ||
41 | <authorinitials>hjk</authorinitials> | ||
42 | <revremark>Update after multiple mappings were added.</revremark> | ||
43 | </revision> | ||
44 | <revision> | ||
45 | <revnumber>0.1</revnumber> | ||
46 | <date>2006-12-11</date> | ||
47 | <authorinitials>hjk</authorinitials> | ||
48 | <revremark>First draft.</revremark> | ||
49 | </revision> | ||
50 | </revhistory> | ||
51 | </bookinfo> | ||
52 | |||
53 | <chapter id="aboutthisdoc"> | ||
54 | <?dbhtml filename="about.html"?> | ||
55 | <title>About this document</title> | ||
56 | |||
57 | <sect1 id="copyright"> | ||
58 | <?dbhtml filename="copyright.html"?> | ||
59 | <title>Copyright and License</title> | ||
60 | <para> | ||
61 | Copyright (c) 2006 by Hans-Jürgen Koch.</para> | ||
62 | <para> | ||
63 | This documentation is Free Software licensed under the terms of the | ||
64 | GPL version 2. | ||
65 | </para> | ||
66 | </sect1> | ||
67 | |||
68 | <sect1 id="translations"> | ||
69 | <?dbhtml filename="translations.html"?> | ||
70 | <title>Translations</title> | ||
71 | |||
72 | <para>If you know of any translations for this document, or you are | ||
73 | interested in translating it, please email me | ||
74 | <email>hjk@linutronix.de</email>. | ||
75 | </para> | ||
76 | </sect1> | ||
77 | |||
78 | <sect1 id="preface"> | ||
79 | <title>Preface</title> | ||
80 | <para> | ||
81 | For many types of devices, creating a Linux kernel driver is | ||
82 | overkill. All that is really needed is some way to handle an | ||
83 | interrupt and provide access to the memory space of the | ||
84 | device. The logic of controlling the device does not | ||
85 | necessarily have to be within the kernel, as the device does | ||
86 | not need to take advantage of any of other resources that the | ||
87 | kernel provides. One such common class of devices that are | ||
88 | like this are for industrial I/O cards. | ||
89 | </para> | ||
90 | <para> | ||
91 | To address this situation, the userspace I/O system (UIO) was | ||
92 | designed. For typical industrial I/O cards, only a very small | ||
93 | kernel module is needed. The main part of the driver will run in | ||
94 | user space. This simplifies development and reduces the risk of | ||
95 | serious bugs within a kernel module. | ||
96 | </para> | ||
97 | </sect1> | ||
98 | |||
99 | <sect1 id="thanks"> | ||
100 | <title>Acknowledgments</title> | ||
101 | <para>I'd like to thank Thomas Gleixner and Benedikt Spranger of | ||
102 | Linutronix, who have not only written most of the UIO code, but also | ||
103 | helped greatly writing this HOWTO by giving me all kinds of background | ||
104 | information.</para> | ||
105 | </sect1> | ||
106 | |||
107 | <sect1 id="feedback"> | ||
108 | <title>Feedback</title> | ||
109 | <para>Find something wrong with this document? (Or perhaps something | ||
110 | right?) I would love to hear from you. Please email me at | ||
111 | <email>hjk@linutronix.de</email>.</para> | ||
112 | </sect1> | ||
113 | </chapter> | ||
114 | |||
115 | <chapter id="about"> | ||
116 | <?dbhtml filename="about.html"?> | ||
117 | <title>About UIO</title> | ||
118 | |||
119 | <para>If you use UIO for your card's driver, here's what you get:</para> | ||
120 | |||
121 | <itemizedlist> | ||
122 | <listitem> | ||
123 | <para>only one small kernel module to write and maintain.</para> | ||
124 | </listitem> | ||
125 | <listitem> | ||
126 | <para>develop the main part of your driver in user space, | ||
127 | with all the tools and libraries you're used to.</para> | ||
128 | </listitem> | ||
129 | <listitem> | ||
130 | <para>bugs in your driver won't crash the kernel.</para> | ||
131 | </listitem> | ||
132 | <listitem> | ||
133 | <para>updates of your driver can take place without recompiling | ||
134 | the kernel.</para> | ||
135 | </listitem> | ||
136 | <listitem> | ||
137 | <para>if you need to keep some parts of your driver closed source, | ||
138 | you can do so without violating the GPL license on the kernel.</para> | ||
139 | </listitem> | ||
140 | </itemizedlist> | ||
141 | |||
142 | <sect1 id="how_uio_works"> | ||
143 | <title>How UIO works</title> | ||
144 | <para> | ||
145 | Each UIO device is accessed through a device file and several | ||
146 | sysfs attribute files. The device file will be called | ||
147 | <filename>/dev/uio0</filename> for the first device, and | ||
148 | <filename>/dev/uio1</filename>, <filename>/dev/uio2</filename> | ||
149 | and so on for subsequent devices. | ||
150 | </para> | ||
151 | |||
152 | <para><filename>/dev/uioX</filename> is used to access the | ||
153 | address space of the card. Just use | ||
154 | <function>mmap()</function> to access registers or RAM | ||
155 | locations of your card. | ||
156 | </para> | ||
157 | |||
158 | <para> | ||
159 | Interrupts are handled by reading from | ||
160 | <filename>/dev/uioX</filename>. A blocking | ||
161 | <function>read()</function> from | ||
162 | <filename>/dev/uioX</filename> will return as soon as an | ||
163 | interrupt occurs. You can also use | ||
164 | <function>select()</function> on | ||
165 | <filename>/dev/uioX</filename> to wait for an interrupt. The | ||
166 | integer value read from <filename>/dev/uioX</filename> | ||
167 | represents the total interrupt count. You can use this number | ||
168 | to figure out if you missed some interrupts. | ||
169 | </para> | ||
170 | |||
171 | <para> | ||
172 | To handle interrupts properly, your custom kernel module can | ||
173 | provide its own interrupt handler. It will automatically be | ||
174 | called by the built-in handler. | ||
175 | </para> | ||
176 | |||
177 | <para> | ||
178 | For cards that don't generate interrupts but need to be | ||
179 | polled, there is the possibility to set up a timer that | ||
180 | triggers the interrupt handler at configurable time intervals. | ||
181 | See <filename>drivers/uio/uio_dummy.c</filename> for an | ||
182 | example of this technique. | ||
183 | </para> | ||
184 | |||
185 | <para> | ||
186 | Each driver provides attributes that are used to read or write | ||
187 | variables. These attributes are accessible through sysfs | ||
188 | files. A custom kernel driver module can add its own | ||
189 | attributes to the device owned by the uio driver, but not added | ||
190 | to the UIO device itself at this time. This might change in the | ||
191 | future if it would be found to be useful. | ||
192 | </para> | ||
193 | |||
194 | <para> | ||
195 | The following standard attributes are provided by the UIO | ||
196 | framework: | ||
197 | </para> | ||
198 | <itemizedlist> | ||
199 | <listitem> | ||
200 | <para> | ||
201 | <filename>name</filename>: The name of your device. It is | ||
202 | recommended to use the name of your kernel module for this. | ||
203 | </para> | ||
204 | </listitem> | ||
205 | <listitem> | ||
206 | <para> | ||
207 | <filename>version</filename>: A version string defined by your | ||
208 | driver. This allows the user space part of your driver to deal | ||
209 | with different versions of the kernel module. | ||
210 | </para> | ||
211 | </listitem> | ||
212 | <listitem> | ||
213 | <para> | ||
214 | <filename>event</filename>: The total number of interrupts | ||
215 | handled by the driver since the last time the device node was | ||
216 | read. | ||
217 | </para> | ||
218 | </listitem> | ||
219 | </itemizedlist> | ||
220 | <para> | ||
221 | These attributes appear under the | ||
222 | <filename>/sys/class/uio/uioX</filename> directory. Please | ||
223 | note that this directory might be a symlink, and not a real | ||
224 | directory. Any userspace code that accesses it must be able | ||
225 | to handle this. | ||
226 | </para> | ||
227 | <para> | ||
228 | Each UIO device can make one or more memory regions available for | ||
229 | memory mapping. This is necessary because some industrial I/O cards | ||
230 | require access to more than one PCI memory region in a driver. | ||
231 | </para> | ||
232 | <para> | ||
233 | Each mapping has its own directory in sysfs, the first mapping | ||
234 | appears as <filename>/sys/class/uio/uioX/maps/map0/</filename>. | ||
235 | Subsequent mappings create directories <filename>map1/</filename>, | ||
236 | <filename>map2/</filename>, and so on. These directories will only | ||
237 | appear if the size of the mapping is not 0. | ||
238 | </para> | ||
239 | <para> | ||
240 | Each <filename>mapX/</filename> directory contains two read-only files | ||
241 | that show start address and size of the memory: | ||
242 | </para> | ||
243 | <itemizedlist> | ||
244 | <listitem> | ||
245 | <para> | ||
246 | <filename>addr</filename>: The address of memory that can be mapped. | ||
247 | </para> | ||
248 | </listitem> | ||
249 | <listitem> | ||
250 | <para> | ||
251 | <filename>size</filename>: The size, in bytes, of the memory | ||
252 | pointed to by addr. | ||
253 | </para> | ||
254 | </listitem> | ||
255 | </itemizedlist> | ||
256 | |||
257 | <para> | ||
258 | From userspace, the different mappings are distinguished by adjusting | ||
259 | the <varname>offset</varname> parameter of the | ||
260 | <function>mmap()</function> call. To map the memory of mapping N, you | ||
261 | have to use N times the page size as your offset: | ||
262 | </para> | ||
263 | <programlisting format="linespecific"> | ||
264 | offset = N * getpagesize(); | ||
265 | </programlisting> | ||
266 | |||
267 | </sect1> | ||
268 | </chapter> | ||
269 | |||
270 | <chapter id="using-uio_dummy" xreflabel="Using uio_dummy"> | ||
271 | <?dbhtml filename="using-uio_dummy.html"?> | ||
272 | <title>Using uio_dummy</title> | ||
273 | <para> | ||
274 | Well, there is no real use for uio_dummy. Its only purpose is | ||
275 | to test most parts of the UIO system (everything except | ||
276 | hardware interrupts), and to serve as an example for the | ||
277 | kernel module that you will have to write yourself. | ||
278 | </para> | ||
279 | |||
280 | <sect1 id="what_uio_dummy_does"> | ||
281 | <title>What uio_dummy does</title> | ||
282 | <para> | ||
283 | The kernel module <filename>uio_dummy.ko</filename> creates a | ||
284 | device that uses a timer to generate periodic interrupts. The | ||
285 | interrupt handler does nothing but increment a counter. The | ||
286 | driver adds two custom attributes, <varname>count</varname> | ||
287 | and <varname>freq</varname>, that appear under | ||
288 | <filename>/sys/devices/platform/uio_dummy/</filename>. | ||
289 | </para> | ||
290 | |||
291 | <para> | ||
292 | The attribute <varname>count</varname> can be read and | ||
293 | written. The associated file | ||
294 | <filename>/sys/devices/platform/uio_dummy/count</filename> | ||
295 | appears as a normal text file and contains the total number of | ||
296 | timer interrupts. If you look at it (e.g. using | ||
297 | <function>cat</function>), you'll notice it is slowly counting | ||
298 | up. | ||
299 | </para> | ||
300 | |||
301 | <para> | ||
302 | The attribute <varname>freq</varname> can be read and written. | ||
303 | The content of | ||
304 | <filename>/sys/devices/platform/uio_dummy/freq</filename> | ||
305 | represents the number of system timer ticks between two timer | ||
306 | interrupts. The default value of <varname>freq</varname> is | ||
307 | the value of the kernel variable <varname>HZ</varname>, which | ||
308 | gives you an interval of one second. Lower values will | ||
309 | increase the frequency. Try the following: | ||
310 | </para> | ||
311 | <programlisting format="linespecific"> | ||
312 | cd /sys/devices/platform/uio_dummy/ | ||
313 | echo 100 > freq | ||
314 | </programlisting> | ||
315 | <para> | ||
316 | Use <function>cat count</function> to see how the interrupt | ||
317 | frequency changes. | ||
318 | </para> | ||
319 | </sect1> | ||
320 | </chapter> | ||
321 | |||
322 | <chapter id="custom_kernel_module" xreflabel="Writing your own kernel module"> | ||
323 | <?dbhtml filename="custom_kernel_module.html"?> | ||
324 | <title>Writing your own kernel module</title> | ||
325 | <para> | ||
326 | Please have a look at <filename>uio_dummy.c</filename> as an | ||
327 | example. The following paragraphs explain the different | ||
328 | sections of this file. | ||
329 | </para> | ||
330 | |||
331 | <sect1 id="uio_info"> | ||
332 | <title>struct uio_info</title> | ||
333 | <para> | ||
334 | This structure tells the framework the details of your driver, | ||
335 | Some of the members are required, others are optional. | ||
336 | </para> | ||
337 | |||
338 | <itemizedlist> | ||
339 | <listitem><para> | ||
340 | <varname>char *name</varname>: Required. The name of your driver as | ||
341 | it will appear in sysfs. I recommend using the name of your module for this. | ||
342 | </para></listitem> | ||
343 | |||
344 | <listitem><para> | ||
345 | <varname>char *version</varname>: Required. This string appears in | ||
346 | <filename>/sys/class/uio/uioX/version</filename>. | ||
347 | </para></listitem> | ||
348 | |||
349 | <listitem><para> | ||
350 | <varname>struct uio_mem mem[ MAX_UIO_MAPS ]</varname>: Required if you | ||
351 | have memory that can be mapped with <function>mmap()</function>. For each | ||
352 | mapping you need to fill one of the <varname>uio_mem</varname> structures. | ||
353 | See the description below for details. | ||
354 | </para></listitem> | ||
355 | |||
356 | <listitem><para> | ||
357 | <varname>long irq</varname>: Required. If your hardware generates an | ||
358 | interrupt, it's your modules task to determine the irq number during | ||
359 | initialization. If you don't have a hardware generated interrupt but | ||
360 | want to trigger the interrupt handler in some other way, set | ||
361 | <varname>irq</varname> to <varname>UIO_IRQ_CUSTOM</varname>. The | ||
362 | uio_dummy module does this as it triggers the event mechanism in a timer | ||
363 | routine. If you had no interrupt at all, you could set | ||
364 | <varname>irq</varname> to <varname>UIO_IRQ_NONE</varname>, though this | ||
365 | rarely makes sense. | ||
366 | </para></listitem> | ||
367 | |||
368 | <listitem><para> | ||
369 | <varname>unsigned long irq_flags</varname>: Required if you've set | ||
370 | <varname>irq</varname> to a hardware interrupt number. The flags given | ||
371 | here will be used in the call to <function>request_irq()</function>. | ||
372 | </para></listitem> | ||
373 | |||
374 | <listitem><para> | ||
375 | <varname>int (*mmap)(struct uio_info *info, struct vm_area_struct | ||
376 | *vma)</varname>: Optional. If you need a special | ||
377 | <function>mmap()</function> function, you can set it here. If this | ||
378 | pointer is not NULL, your <function>mmap()</function> will be called | ||
379 | instead of the built-in one. | ||
380 | </para></listitem> | ||
381 | |||
382 | <listitem><para> | ||
383 | <varname>int (*open)(struct uio_info *info, struct inode *inode) | ||
384 | </varname>: Optional. You might want to have your own | ||
385 | <function>open()</function>, e.g. to enable interrupts only when your | ||
386 | device is actually used. | ||
387 | </para></listitem> | ||
388 | |||
389 | <listitem><para> | ||
390 | <varname>int (*release)(struct uio_info *info, struct inode *inode) | ||
391 | </varname>: Optional. If you define your own | ||
392 | <function>open()</function>, you will probably also want a custom | ||
393 | <function>release()</function> function. | ||
394 | </para></listitem> | ||
395 | </itemizedlist> | ||
396 | |||
397 | <para> | ||
398 | Usually, your device will have one or more memory regions that can be mapped | ||
399 | to user space. For each region, you have to set up a | ||
400 | <varname>struct uio_mem</varname> in the <varname>mem[]</varname> array. | ||
401 | Here's a description of the fields of <varname>struct uio_mem</varname>: | ||
402 | </para> | ||
403 | |||
404 | <itemizedlist> | ||
405 | <listitem><para> | ||
406 | <varname>int memtype</varname>: Required if the mapping is used. Set this to | ||
407 | <varname>UIO_MEM_PHYS</varname> if you you have physical memory on your | ||
408 | card to be mapped. Use <varname>UIO_MEM_LOGICAL</varname> for logical | ||
409 | memory (e.g. allocated with <function>kmalloc()</function>). There's also | ||
410 | <varname>UIO_MEM_VIRTUAL</varname> for virtual memory. | ||
411 | </para></listitem> | ||
412 | |||
413 | <listitem><para> | ||
414 | <varname>unsigned long addr</varname>: Required if the mapping is used. | ||
415 | Fill in the address of your memory block. This address is the one that | ||
416 | appears in sysfs. | ||
417 | </para></listitem> | ||
418 | |||
419 | <listitem><para> | ||
420 | <varname>unsigned long size</varname>: Fill in the size of the | ||
421 | memory block that <varname>addr</varname> points to. If <varname>size</varname> | ||
422 | is zero, the mapping is considered unused. Note that you | ||
423 | <emphasis>must</emphasis> initialize <varname>size</varname> with zero for | ||
424 | all unused mappings. | ||
425 | </para></listitem> | ||
426 | |||
427 | <listitem><para> | ||
428 | <varname>void *internal_addr</varname>: If you have to access this memory | ||
429 | region from within your kernel module, you will want to map it internally by | ||
430 | using something like <function>ioremap()</function>. Addresses | ||
431 | returned by this function cannot be mapped to user space, so you must not | ||
432 | store it in <varname>addr</varname>. Use <varname>internal_addr</varname> | ||
433 | instead to remember such an address. | ||
434 | </para></listitem> | ||
435 | </itemizedlist> | ||
436 | |||
437 | <para> | ||
438 | Please do not touch the <varname>kobj</varname> element of | ||
439 | <varname>struct uio_mem</varname>! It is used by the UIO framework | ||
440 | to set up sysfs files for this mapping. Simply leave it alone. | ||
441 | </para> | ||
442 | </sect1> | ||
443 | |||
444 | <sect1 id="adding_irq_handler"> | ||
445 | <title>Adding an interrupt handler</title> | ||
446 | <para> | ||
447 | What you need to do in your interrupt handler depends on your | ||
448 | hardware and on how you want to handle it. You should try to | ||
449 | keep the amount of code in your kernel interrupt handler low. | ||
450 | If your hardware requires no action that you | ||
451 | <emphasis>have</emphasis> to perform after each interrupt, | ||
452 | then your handler can be empty.</para> <para>If, on the other | ||
453 | hand, your hardware <emphasis>needs</emphasis> some action to | ||
454 | be performed after each interrupt, then you | ||
455 | <emphasis>must</emphasis> do it in your kernel module. Note | ||
456 | that you cannot rely on the userspace part of your driver. Your | ||
457 | userspace program can terminate at any time, possibly leaving | ||
458 | your hardware in a state where proper interrupt handling is | ||
459 | still required. | ||
460 | </para> | ||
461 | |||
462 | <para> | ||
463 | There might also be applications where you want to read data | ||
464 | from your hardware at each interrupt and buffer it in a piece | ||
465 | of kernel memory you've allocated for that purpose. With this | ||
466 | technique you could avoid loss of data if your userspace | ||
467 | program misses an interrupt. | ||
468 | </para> | ||
469 | |||
470 | <para> | ||
471 | A note on shared interrupts: Your driver should support | ||
472 | interrupt sharing whenever this is possible. It is possible if | ||
473 | and only if your driver can detect whether your hardware has | ||
474 | triggered the interrupt or not. This is usually done by looking | ||
475 | at an interrupt status register. If your driver sees that the | ||
476 | IRQ bit is actually set, it will perform its actions, and the | ||
477 | handler returns IRQ_HANDLED. If the driver detects that it was | ||
478 | not your hardware that caused the interrupt, it will do nothing | ||
479 | and return IRQ_NONE, allowing the kernel to call the next | ||
480 | possible interrupt handler. | ||
481 | </para> | ||
482 | |||
483 | <para> | ||
484 | If you decide not to support shared interrupts, your card | ||
485 | won't work in computers with no free interrupts. As this | ||
486 | frequently happens on the PC platform, you can save yourself a | ||
487 | lot of trouble by supporting interrupt sharing. | ||
488 | </para> | ||
489 | </sect1> | ||
490 | |||
491 | </chapter> | ||
492 | |||
493 | <chapter id="userspace_driver" xreflabel="Writing a driver in user space"> | ||
494 | <?dbhtml filename="userspace_driver.html"?> | ||
495 | <title>Writing a driver in userspace</title> | ||
496 | <para> | ||
497 | Once you have a working kernel module for your hardware, you can | ||
498 | write the userspace part of your driver. You don't need any special | ||
499 | libraries, your driver can be written in any reasonable language, | ||
500 | you can use floating point numbers and so on. In short, you can | ||
501 | use all the tools and libraries you'd normally use for writing a | ||
502 | userspace application. | ||
503 | </para> | ||
504 | |||
505 | <sect1 id="getting_uio_information"> | ||
506 | <title>Getting information about your UIO device</title> | ||
507 | <para> | ||
508 | Information about all UIO devices is available in sysfs. The | ||
509 | first thing you should do in your driver is check | ||
510 | <varname>name</varname> and <varname>version</varname> to | ||
511 | make sure your talking to the right device and that its kernel | ||
512 | driver has the version you expect. | ||
513 | </para> | ||
514 | <para> | ||
515 | You should also make sure that the memory mapping you need | ||
516 | exists and has the size you expect. | ||
517 | </para> | ||
518 | <para> | ||
519 | There is a tool called <varname>lsuio</varname> that lists | ||
520 | UIO devices and their attributes. It is available here: | ||
521 | </para> | ||
522 | <para> | ||
523 | <ulink url="http://www.osadl.org/projects/downloads/UIO/user/"> | ||
524 | http://www.osadl.org/projects/downloads/UIO/user/</ulink> | ||
525 | </para> | ||
526 | <para> | ||
527 | With <varname>lsuio</varname> you can quickly check if your | ||
528 | kernel module is loaded and which attributes it exports. | ||
529 | Have a look at the manpage for details. | ||
530 | </para> | ||
531 | <para> | ||
532 | The source code of <varname>lsuio</varname> can serve as an | ||
533 | example for getting information about an UIO device. | ||
534 | The file <filename>uio_helper.c</filename> contains a lot of | ||
535 | functions you could use in your userspace driver code. | ||
536 | </para> | ||
537 | </sect1> | ||
538 | |||
539 | <sect1 id="mmap_device_memory"> | ||
540 | <title>mmap() device memory</title> | ||
541 | <para> | ||
542 | After you made sure you've got the right device with the | ||
543 | memory mappings you need, all you have to do is to call | ||
544 | <function>mmap()</function> to map the device's memory | ||
545 | to userspace. | ||
546 | </para> | ||
547 | <para> | ||
548 | The parameter <varname>offset</varname> of the | ||
549 | <function>mmap()</function> call has a special meaning | ||
550 | for UIO devices: It is used to select which mapping of | ||
551 | your device you want to map. To map the memory of | ||
552 | mapping N, you have to use N times the page size as | ||
553 | your offset: | ||
554 | </para> | ||
555 | <programlisting format="linespecific"> | ||
556 | offset = N * getpagesize(); | ||
557 | </programlisting> | ||
558 | <para> | ||
559 | N starts from zero, so if you've got only one memory | ||
560 | range to map, set <varname>offset = 0</varname>. | ||
561 | A drawback of this technique is that memory is always | ||
562 | mapped beginning with its start address. | ||
563 | </para> | ||
564 | </sect1> | ||
565 | |||
566 | <sect1 id="wait_for_interrupts"> | ||
567 | <title>Waiting for interrupts</title> | ||
568 | <para> | ||
569 | After you successfully mapped your devices memory, you | ||
570 | can access it like an ordinary array. Usually, you will | ||
571 | perform some initialization. After that, your hardware | ||
572 | starts working and will generate an interrupt as soon | ||
573 | as it's finished, has some data available, or needs your | ||
574 | attention because an error occured. | ||
575 | </para> | ||
576 | <para> | ||
577 | <filename>/dev/uioX</filename> is a read-only file. A | ||
578 | <function>read()</function> will always block until an | ||
579 | interrupt occurs. There is only one legal value for the | ||
580 | <varname>count</varname> parameter of | ||
581 | <function>read()</function>, and that is the size of a | ||
582 | signed 32 bit integer (4). Any other value for | ||
583 | <varname>count</varname> causes <function>read()</function> | ||
584 | to fail. The signed 32 bit integer read is the interrupt | ||
585 | count of your device. If the value is one more than the value | ||
586 | you read the last time, everything is OK. If the difference | ||
587 | is greater than one, you missed interrupts. | ||
588 | </para> | ||
589 | <para> | ||
590 | You can also use <function>select()</function> on | ||
591 | <filename>/dev/uioX</filename>. | ||
592 | </para> | ||
593 | </sect1> | ||
594 | |||
595 | </chapter> | ||
596 | |||
597 | <appendix id="app1"> | ||
598 | <title>Further information</title> | ||
599 | <itemizedlist> | ||
600 | <listitem><para> | ||
601 | <ulink url="http://www.osadl.org"> | ||
602 | OSADL homepage.</ulink> | ||
603 | </para></listitem> | ||
604 | <listitem><para> | ||
605 | <ulink url="http://www.linutronix.de"> | ||
606 | Linutronix homepage.</ulink> | ||
607 | </para></listitem> | ||
608 | </itemizedlist> | ||
609 | </appendix> | ||
610 | |||
611 | </book> | ||
diff --git a/Documentation/HOWTO b/Documentation/HOWTO index 98e2701c746f..f8cc3f8ed152 100644 --- a/Documentation/HOWTO +++ b/Documentation/HOWTO | |||
@@ -249,6 +249,9 @@ process is as follows: | |||
249 | release a new -rc kernel every week. | 249 | release a new -rc kernel every week. |
250 | - Process continues until the kernel is considered "ready", the | 250 | - Process continues until the kernel is considered "ready", the |
251 | process should last around 6 weeks. | 251 | process should last around 6 weeks. |
252 | - A list of known regressions present in each -rc release is | ||
253 | tracked at the following URI: | ||
254 | http://kernelnewbies.org/known_regressions | ||
252 | 255 | ||
253 | It is worth mentioning what Andrew Morton wrote on the linux-kernel | 256 | It is worth mentioning what Andrew Morton wrote on the linux-kernel |
254 | mailing list about kernel releases: | 257 | mailing list about kernel releases: |
diff --git a/Documentation/connector/cn_test.c b/Documentation/connector/cn_test.c index 3e73231695b3..be7af146dd30 100644 --- a/Documentation/connector/cn_test.c +++ b/Documentation/connector/cn_test.c | |||
@@ -124,9 +124,8 @@ static void cn_test_timer_func(unsigned long __data) | |||
124 | struct cn_msg *m; | 124 | struct cn_msg *m; |
125 | char data[32]; | 125 | char data[32]; |
126 | 126 | ||
127 | m = kmalloc(sizeof(*m) + sizeof(data), GFP_ATOMIC); | 127 | m = kzalloc(sizeof(*m) + sizeof(data), GFP_ATOMIC); |
128 | if (m) { | 128 | if (m) { |
129 | memset(m, 0, sizeof(*m) + sizeof(data)); | ||
130 | 129 | ||
131 | memcpy(&m->id, &cn_test_id, sizeof(m->id)); | 130 | memcpy(&m->id, &cn_test_id, sizeof(m->id)); |
132 | m->seq = cn_test_timer_counter; | 131 | m->seq = cn_test_timer_counter; |
diff --git a/Documentation/console/console.txt b/Documentation/console/console.txt index d3e17447321c..877a1b26cc3d 100644 --- a/Documentation/console/console.txt +++ b/Documentation/console/console.txt | |||
@@ -29,7 +29,7 @@ In newer kernels, the following are also available: | |||
29 | 29 | ||
30 | If sysfs is enabled, the contents of /sys/class/vtconsole can be | 30 | If sysfs is enabled, the contents of /sys/class/vtconsole can be |
31 | examined. This shows the console backends currently registered by the | 31 | examined. This shows the console backends currently registered by the |
32 | system which are named vtcon<n> where <n> is an integer fro 0 to 15. Thus: | 32 | system which are named vtcon<n> where <n> is an integer from 0 to 15. Thus: |
33 | 33 | ||
34 | ls /sys/class/vtconsole | 34 | ls /sys/class/vtconsole |
35 | . .. vtcon0 vtcon1 | 35 | . .. vtcon0 vtcon1 |
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 6c8d8f27db34..8569072fa387 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt | |||
@@ -207,7 +207,7 @@ responsibility. This is usually non-issue because bus ops and | |||
207 | resource allocations already do the job. | 207 | resource allocations already do the job. |
208 | 208 | ||
209 | For an example of single-instance devres type, read pcim_iomap_table() | 209 | For an example of single-instance devres type, read pcim_iomap_table() |
210 | in lib/iomap.c. | 210 | in lib/devres.c. |
211 | 211 | ||
212 | All devres interface functions can be called without context if the | 212 | All devres interface functions can be called without context if the |
213 | right gfp mask is given. | 213 | right gfp mask is given. |
diff --git a/Documentation/drivers/edac/edac.txt b/Documentation/drivers/edac/edac.txt index 3c5a9e4297b4..a5c36842ecef 100644 --- a/Documentation/drivers/edac/edac.txt +++ b/Documentation/drivers/edac/edac.txt | |||
@@ -2,22 +2,42 @@ | |||
2 | 2 | ||
3 | EDAC - Error Detection And Correction | 3 | EDAC - Error Detection And Correction |
4 | 4 | ||
5 | Written by Doug Thompson <norsk5@xmission.com> | 5 | Written by Doug Thompson <dougthompson@xmission.com> |
6 | 7 Dec 2005 | 6 | 7 Dec 2005 |
7 | 17 Jul 2007 Updated | ||
7 | 8 | ||
8 | 9 | ||
9 | EDAC was written by: | 10 | EDAC is maintained and written by: |
10 | Thayne Harbaugh, | ||
11 | modified by Dave Peterson, Doug Thompson, et al, | ||
12 | from the bluesmoke.sourceforge.net project. | ||
13 | 11 | ||
12 | Doug Thompson, Dave Jiang, Dave Peterson et al, | ||
13 | original author: Thayne Harbaugh, | ||
14 | |||
15 | Contact: | ||
16 | website: bluesmoke.sourceforge.net | ||
17 | mailing list: bluesmoke-devel@lists.sourceforge.net | ||
18 | |||
19 | "bluesmoke" was the name for this device driver when it was "out-of-tree" | ||
20 | and maintained at sourceforge.net. When it was pushed into 2.6.16 for the | ||
21 | first time, it was renamed to 'EDAC'. | ||
22 | |||
23 | The bluesmoke project at sourceforge.net is now utilized as a 'staging area' | ||
24 | for EDAC development, before it is sent upstream to kernel.org | ||
25 | |||
26 | At the bluesmoke/EDAC project site, is a series of quilt patches against | ||
27 | recent kernels, stored in a SVN respository. For easier downloading, there | ||
28 | is also a tarball snapshot available. | ||
14 | 29 | ||
15 | ============================================================================ | 30 | ============================================================================ |
16 | EDAC PURPOSE | 31 | EDAC PURPOSE |
17 | 32 | ||
18 | The 'edac' kernel module goal is to detect and report errors that occur | 33 | The 'edac' kernel module goal is to detect and report errors that occur |
19 | within the computer system. In the initial release, memory Correctable Errors | 34 | within the computer system running under linux. |
20 | (CE) and Uncorrectable Errors (UE) are the primary errors being harvested. | 35 | |
36 | MEMORY | ||
37 | |||
38 | In the initial release, memory Correctable Errors (CE) and Uncorrectable | ||
39 | Errors (UE) are the primary errors being harvested. These types of errors | ||
40 | are harvested by the 'edac_mc' class of device. | ||
21 | 41 | ||
22 | Detecting CE events, then harvesting those events and reporting them, | 42 | Detecting CE events, then harvesting those events and reporting them, |
23 | CAN be a predictor of future UE events. With CE events, the system can | 43 | CAN be a predictor of future UE events. With CE events, the system can |
@@ -25,9 +45,27 @@ continue to operate, but with less safety. Preventive maintenance and | |||
25 | proactive part replacement of memory DIMMs exhibiting CEs can reduce | 45 | proactive part replacement of memory DIMMs exhibiting CEs can reduce |
26 | the likelihood of the dreaded UE events and system 'panics'. | 46 | the likelihood of the dreaded UE events and system 'panics'. |
27 | 47 | ||
48 | NON-MEMORY | ||
49 | |||
50 | A new feature for EDAC, the edac_device class of device, was added in | ||
51 | the 2.6.23 version of the kernel. | ||
52 | |||
53 | This new device type allows for non-memory type of ECC hardware detectors | ||
54 | to have their states harvested and presented to userspace via the sysfs | ||
55 | interface. | ||
56 | |||
57 | Some architectures have ECC detectors for L1, L2 and L3 caches, along with DMA | ||
58 | engines, fabric switches, main data path switches, interconnections, | ||
59 | and various other hardware data paths. If the hardware reports it, then | ||
60 | a edac_device device probably can be constructed to harvest and present | ||
61 | that to userspace. | ||
62 | |||
63 | |||
64 | PCI BUS SCANNING | ||
28 | 65 | ||
29 | In addition, PCI Bus Parity and SERR Errors are scanned for on PCI devices | 66 | In addition, PCI Bus Parity and SERR Errors are scanned for on PCI devices |
30 | in order to determine if errors are occurring on data transfers. | 67 | in order to determine if errors are occurring on data transfers. |
68 | |||
31 | The presence of PCI Parity errors must be examined with a grain of salt. | 69 | The presence of PCI Parity errors must be examined with a grain of salt. |
32 | There are several add-in adapters that do NOT follow the PCI specification | 70 | There are several add-in adapters that do NOT follow the PCI specification |
33 | with regards to Parity generation and reporting. The specification says | 71 | with regards to Parity generation and reporting. The specification says |
@@ -35,11 +73,17 @@ the vendor should tie the parity status bits to 0 if they do not intend | |||
35 | to generate parity. Some vendors do not do this, and thus the parity bit | 73 | to generate parity. Some vendors do not do this, and thus the parity bit |
36 | can "float" giving false positives. | 74 | can "float" giving false positives. |
37 | 75 | ||
38 | [There are patches in the kernel queue which will allow for storage of | 76 | In the kernel there is a pci device attribute located in sysfs that is |
39 | quirks of PCI devices reporting false parity positives. The 2.6.18 | 77 | checked by the EDAC PCI scanning code. If that attribute is set, |
40 | kernel should have those patches included. When that becomes available, | 78 | PCI parity/error scannining is skipped for that device. The attribute |
41 | then EDAC will be patched to utilize that information to "skip" such | 79 | is: |
42 | devices.] | 80 | |
81 | broken_parity_status | ||
82 | |||
83 | as is located in /sys/devices/pci<XXX>/0000:XX:YY.Z directorys for | ||
84 | PCI devices. | ||
85 | |||
86 | FUTURE HARDWARE SCANNING | ||
43 | 87 | ||
44 | EDAC will have future error detectors that will be integrated with | 88 | EDAC will have future error detectors that will be integrated with |
45 | EDAC or added to it, in the following list: | 89 | EDAC or added to it, in the following list: |
@@ -57,13 +101,14 @@ and the like. | |||
57 | ============================================================================ | 101 | ============================================================================ |
58 | EDAC VERSIONING | 102 | EDAC VERSIONING |
59 | 103 | ||
60 | EDAC is composed of a "core" module (edac_mc.ko) and several Memory | 104 | EDAC is composed of a "core" module (edac_core.ko) and several Memory |
61 | Controller (MC) driver modules. On a given system, the CORE | 105 | Controller (MC) driver modules. On a given system, the CORE |
62 | is loaded and one MC driver will be loaded. Both the CORE and | 106 | is loaded and one MC driver will be loaded. Both the CORE and |
63 | the MC driver have individual versions that reflect current release | 107 | the MC driver (or edac_device driver) have individual versions that reflect |
64 | level of their respective modules. Thus, to "report" on what version | 108 | current release level of their respective modules. |
65 | a system is running, one must report both the CORE's and the | 109 | |
66 | MC driver's versions. | 110 | Thus, to "report" on what version a system is running, one must report both |
111 | the CORE's and the MC driver's versions. | ||
67 | 112 | ||
68 | 113 | ||
69 | LOADING | 114 | LOADING |
@@ -88,8 +133,9 @@ EDAC sysfs INTERFACE | |||
88 | EDAC presents a 'sysfs' interface for control, reporting and attribute | 133 | EDAC presents a 'sysfs' interface for control, reporting and attribute |
89 | reporting purposes. | 134 | reporting purposes. |
90 | 135 | ||
91 | EDAC lives in the /sys/devices/system/edac directory. Within this directory | 136 | EDAC lives in the /sys/devices/system/edac directory. |
92 | there currently reside 2 'edac' components: | 137 | |
138 | Within this directory there currently reside 2 'edac' components: | ||
93 | 139 | ||
94 | mc memory controller(s) system | 140 | mc memory controller(s) system |
95 | pci PCI control and status system | 141 | pci PCI control and status system |
@@ -188,7 +234,7 @@ In directory 'mc' are EDAC system overall control and attribute files: | |||
188 | 234 | ||
189 | Panic on UE control file: | 235 | Panic on UE control file: |
190 | 236 | ||
191 | 'panic_on_ue' | 237 | 'edac_mc_panic_on_ue' |
192 | 238 | ||
193 | An uncorrectable error will cause a machine panic. This is usually | 239 | An uncorrectable error will cause a machine panic. This is usually |
194 | desirable. It is a bad idea to continue when an uncorrectable error | 240 | desirable. It is a bad idea to continue when an uncorrectable error |
@@ -199,12 +245,12 @@ Panic on UE control file: | |||
199 | 245 | ||
200 | LOAD TIME: module/kernel parameter: panic_on_ue=[0|1] | 246 | LOAD TIME: module/kernel parameter: panic_on_ue=[0|1] |
201 | 247 | ||
202 | RUN TIME: echo "1" >/sys/devices/system/edac/mc/panic_on_ue | 248 | RUN TIME: echo "1" >/sys/devices/system/edac/mc/edac_mc_panic_on_ue |
203 | 249 | ||
204 | 250 | ||
205 | Log UE control file: | 251 | Log UE control file: |
206 | 252 | ||
207 | 'log_ue' | 253 | 'edac_mc_log_ue' |
208 | 254 | ||
209 | Generate kernel messages describing uncorrectable errors. These errors | 255 | Generate kernel messages describing uncorrectable errors. These errors |
210 | are reported through the system message log system. UE statistics | 256 | are reported through the system message log system. UE statistics |
@@ -212,12 +258,12 @@ Log UE control file: | |||
212 | 258 | ||
213 | LOAD TIME: module/kernel parameter: log_ue=[0|1] | 259 | LOAD TIME: module/kernel parameter: log_ue=[0|1] |
214 | 260 | ||
215 | RUN TIME: echo "1" >/sys/devices/system/edac/mc/log_ue | 261 | RUN TIME: echo "1" >/sys/devices/system/edac/mc/edac_mc_log_ue |
216 | 262 | ||
217 | 263 | ||
218 | Log CE control file: | 264 | Log CE control file: |
219 | 265 | ||
220 | 'log_ce' | 266 | 'edac_mc_log_ce' |
221 | 267 | ||
222 | Generate kernel messages describing correctable errors. These | 268 | Generate kernel messages describing correctable errors. These |
223 | errors are reported through the system message log system. | 269 | errors are reported through the system message log system. |
@@ -225,12 +271,12 @@ Log CE control file: | |||
225 | 271 | ||
226 | LOAD TIME: module/kernel parameter: log_ce=[0|1] | 272 | LOAD TIME: module/kernel parameter: log_ce=[0|1] |
227 | 273 | ||
228 | RUN TIME: echo "1" >/sys/devices/system/edac/mc/log_ce | 274 | RUN TIME: echo "1" >/sys/devices/system/edac/mc/edac_mc_log_ce |
229 | 275 | ||
230 | 276 | ||
231 | Polling period control file: | 277 | Polling period control file: |
232 | 278 | ||
233 | 'poll_msec' | 279 | 'edac_mc_poll_msec' |
234 | 280 | ||
235 | The time period, in milliseconds, for polling for error information. | 281 | The time period, in milliseconds, for polling for error information. |
236 | Too small a value wastes resources. Too large a value might delay | 282 | Too small a value wastes resources. Too large a value might delay |
@@ -241,7 +287,7 @@ Polling period control file: | |||
241 | 287 | ||
242 | LOAD TIME: module/kernel parameter: poll_msec=[0|1] | 288 | LOAD TIME: module/kernel parameter: poll_msec=[0|1] |
243 | 289 | ||
244 | RUN TIME: echo "1000" >/sys/devices/system/edac/mc/poll_msec | 290 | RUN TIME: echo "1000" >/sys/devices/system/edac/mc/edac_mc_poll_msec |
245 | 291 | ||
246 | 292 | ||
247 | ============================================================================ | 293 | ============================================================================ |
@@ -587,3 +633,95 @@ Parity Count: | |||
587 | 633 | ||
588 | 634 | ||
589 | ======================================================================= | 635 | ======================================================================= |
636 | |||
637 | |||
638 | EDAC_DEVICE type of device | ||
639 | |||
640 | In the header file, edac_core.h, there is a series of edac_device structures | ||
641 | and APIs for the EDAC_DEVICE. | ||
642 | |||
643 | User space access to an edac_device is through the sysfs interface. | ||
644 | |||
645 | At the location /sys/devices/system/edac (sysfs) new edac_device devices will | ||
646 | appear. | ||
647 | |||
648 | There is a three level tree beneath the above 'edac' directory. For example, | ||
649 | the 'test_device_edac' device (found at the bluesmoke.sourceforget.net website) | ||
650 | installs itself as: | ||
651 | |||
652 | /sys/devices/systm/edac/test-instance | ||
653 | |||
654 | in this directory are various controls, a symlink and one or more 'instance' | ||
655 | directorys. | ||
656 | |||
657 | The standard default controls are: | ||
658 | |||
659 | log_ce boolean to log CE events | ||
660 | log_ue boolean to log UE events | ||
661 | panic_on_ue boolean to 'panic' the system if an UE is encountered | ||
662 | (default off, can be set true via startup script) | ||
663 | poll_msec time period between POLL cycles for events | ||
664 | |||
665 | The test_device_edac device adds at least one of its own custom control: | ||
666 | |||
667 | test_bits which in the current test driver does nothing but | ||
668 | show how it is installed. A ported driver can | ||
669 | add one or more such controls and/or attributes | ||
670 | for specific uses. | ||
671 | One out-of-tree driver uses controls here to allow | ||
672 | for ERROR INJECTION operations to hardware | ||
673 | injection registers | ||
674 | |||
675 | The symlink points to the 'struct dev' that is registered for this edac_device. | ||
676 | |||
677 | INSTANCES | ||
678 | |||
679 | One or more instance directories are present. For the 'test_device_edac' case: | ||
680 | |||
681 | test-instance0 | ||
682 | |||
683 | |||
684 | In this directory there are two default counter attributes, which are totals of | ||
685 | counter in deeper subdirectories. | ||
686 | |||
687 | ce_count total of CE events of subdirectories | ||
688 | ue_count total of UE events of subdirectories | ||
689 | |||
690 | BLOCKS | ||
691 | |||
692 | At the lowest directory level is the 'block' directory. There can be 0, 1 | ||
693 | or more blocks specified in each instance. | ||
694 | |||
695 | test-block0 | ||
696 | |||
697 | |||
698 | In this directory the default attributes are: | ||
699 | |||
700 | ce_count which is counter of CE events for this 'block' | ||
701 | of hardware being monitored | ||
702 | ue_count which is counter of UE events for this 'block' | ||
703 | of hardware being monitored | ||
704 | |||
705 | |||
706 | The 'test_device_edac' device adds 4 attributes and 1 control: | ||
707 | |||
708 | test-block-bits-0 for every POLL cycle this counter | ||
709 | is incremented | ||
710 | test-block-bits-1 every 10 cycles, this counter is bumped once, | ||
711 | and test-block-bits-0 is set to 0 | ||
712 | test-block-bits-2 every 100 cycles, this counter is bumped once, | ||
713 | and test-block-bits-1 is set to 0 | ||
714 | test-block-bits-3 every 1000 cycles, this counter is bumped once, | ||
715 | and test-block-bits-2 is set to 0 | ||
716 | |||
717 | |||
718 | reset-counters writing ANY thing to this control will | ||
719 | reset all the above counters. | ||
720 | |||
721 | |||
722 | Use of the 'test_device_edac' driver should any others to create their own | ||
723 | unique drivers for their hardware systems. | ||
724 | |||
725 | The 'test_device_edac' sample driver is located at the | ||
726 | bluesmoke.sourceforge.net project site for EDAC. | ||
727 | |||
diff --git a/Documentation/dvb/bt8xx.txt b/Documentation/dvb/bt8xx.txt index 4e7614e606c5..ecb47adda063 100644 --- a/Documentation/dvb/bt8xx.txt +++ b/Documentation/dvb/bt8xx.txt | |||
@@ -9,19 +9,29 @@ for accessing the i2c bus and the gpio pins of the bt8xx chipset. | |||
9 | Please see Documentation/dvb/cards.txt => o Cards based on the Conexant Bt8xx PCI bridge: | 9 | Please see Documentation/dvb/cards.txt => o Cards based on the Conexant Bt8xx PCI bridge: |
10 | 10 | ||
11 | Compiling kernel please enable: | 11 | Compiling kernel please enable: |
12 | a.)"Device drivers" => "Multimedia devices" => "Video For Linux" => "BT848 Video For Linux" | 12 | a.)"Device drivers" => "Multimedia devices" => "Video For Linux" => "Enable Video for Linux API 1 (DEPRECATED)" |
13 | b.)"Device drivers" => "Multimedia devices" => "Digital Video Broadcasting Devices" | 13 | b.)"Device drivers" => "Multimedia devices" => "Video For Linux" => "Video Capture Adapters" => "BT848 Video For Linux" |
14 | => "DVB for Linux" "DVB Core Support" "Bt8xx based PCI Cards" | 14 | c.)"Device drivers" => "Multimedia devices" => "Digital Video Broadcasting Devices" => "DVB for Linux" "DVB Core Support" "Bt8xx based PCI Cards" |
15 | 15 | ||
16 | 2) Loading Modules | 16 | Please use the following options with care as deselection of drivers which are in fact necessary |
17 | ================== | 17 | may result in DVB devices that cannot be tuned due to lack of driver support: |
18 | You can save RAM by deselecting every frontend module that your DVB card does not need. | ||
19 | |||
20 | First please remove the static dependency of DVB card drivers on all frontend modules for all possible card variants by enabling: | ||
21 | d.) "Device drivers" => "Multimedia devices" => "Digital Video Broadcasting Devices" | ||
22 | => "DVB for Linux" "DVB Core Support" "Load and attach frontend modules as needed" | ||
18 | 23 | ||
19 | In default cases bttv is loaded automatically. | 24 | If you know the frontend driver that your card needs please enable: |
20 | To load the backend either place dvb-bt8xx in etc/modules, or apply manually: | 25 | e.)"Device drivers" => "Multimedia devices" => "Digital Video Broadcasting Devices" |
26 | => "DVB for Linux" "DVB Core Support" "Customise DVB Frontends" => "Customise the frontend modules to build" | ||
27 | Then please select your card-specific frontend module. | ||
21 | 28 | ||
22 | $ modprobe dvb-bt8xx | 29 | 2) Loading Modules |
30 | ================== | ||
23 | 31 | ||
24 | All frontends will be loaded automatically. | 32 | Regular case: If the bttv driver detects a bt8xx-based DVB card, all frontend and backend modules will be loaded automatically. |
33 | Exceptions are: | ||
34 | - Old TwinHan DST cards or clones with or without CA slot and not containing an Eeprom. | ||
25 | People running udev please see Documentation/dvb/udev.txt. | 35 | People running udev please see Documentation/dvb/udev.txt. |
26 | 36 | ||
27 | In the following cases overriding the PCI type detection for dvb-bt8xx might be necessary: | 37 | In the following cases overriding the PCI type detection for dvb-bt8xx might be necessary: |
@@ -30,7 +40,6 @@ In the following cases overriding the PCI type detection for dvb-bt8xx might be | |||
30 | ------------------------------ | 40 | ------------------------------ |
31 | 41 | ||
32 | $ modprobe bttv card=113 | 42 | $ modprobe bttv card=113 |
33 | $ modprobe dvb-bt8xx | ||
34 | $ modprobe dst | 43 | $ modprobe dst |
35 | 44 | ||
36 | Useful parameters for verbosity level and debugging the dst module: | 45 | Useful parameters for verbosity level and debugging the dst module: |
@@ -65,10 +74,9 @@ DViCO FusionHDTV 5 Lite: 135 | |||
65 | Notice: The order of the card ID should be uprising: | 74 | Notice: The order of the card ID should be uprising: |
66 | Example: | 75 | Example: |
67 | $ modprobe bttv card=113 card=135 | 76 | $ modprobe bttv card=113 card=135 |
68 | $ modprobe dvb-bt8xx | ||
69 | 77 | ||
70 | For a full list of card ID's please see Documentation/video4linux/CARDLIST.bttv. | 78 | For a full list of card ID's please see Documentation/video4linux/CARDLIST.bttv. |
71 | In case of further problems send questions to the mailing list: www.linuxdvb.org. | 79 | In case of further problems please subscribe and send questions to the mailing list: linux-dvb@linuxtv.org. |
72 | 80 | ||
73 | Authors: Richard Walker, | 81 | Authors: Richard Walker, |
74 | Jamie Honan, | 82 | Jamie Honan, |
diff --git a/Documentation/dvb/get_dvb_firmware b/Documentation/dvb/get_dvb_firmware index 4820366b6ae8..b4d306ae9234 100644 --- a/Documentation/dvb/get_dvb_firmware +++ b/Documentation/dvb/get_dvb_firmware | |||
@@ -24,7 +24,8 @@ use IO::Handle; | |||
24 | @components = ( "sp8870", "sp887x", "tda10045", "tda10046", | 24 | @components = ( "sp8870", "sp887x", "tda10045", "tda10046", |
25 | "tda10046lifeview", "av7110", "dec2000t", "dec2540t", | 25 | "tda10046lifeview", "av7110", "dec2000t", "dec2540t", |
26 | "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004", | 26 | "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004", |
27 | "or51211", "or51132_qam", "or51132_vsb", "bluebird"); | 27 | "or51211", "or51132_qam", "or51132_vsb", "bluebird", |
28 | "opera1"); | ||
28 | 29 | ||
29 | # Check args | 30 | # Check args |
30 | syntax() if (scalar(@ARGV) != 1); | 31 | syntax() if (scalar(@ARGV) != 1); |
@@ -56,7 +57,7 @@ syntax(); | |||
56 | 57 | ||
57 | sub sp8870 { | 58 | sub sp8870 { |
58 | my $sourcefile = "tt_Premium_217g.zip"; | 59 | my $sourcefile = "tt_Premium_217g.zip"; |
59 | my $url = "http://www.technotrend.de/new/217g/$sourcefile"; | 60 | my $url = "http://www.softwarepatch.pl/9999ccd06a4813cb827dbb0005071c71/$sourcefile"; |
60 | my $hash = "53970ec17a538945a6d8cb608a7b3899"; | 61 | my $hash = "53970ec17a538945a6d8cb608a7b3899"; |
61 | my $outfile = "dvb-fe-sp8870.fw"; | 62 | my $outfile = "dvb-fe-sp8870.fw"; |
62 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 63 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); |
@@ -210,6 +211,45 @@ sub dec3000s { | |||
210 | 211 | ||
211 | $outfile; | 212 | $outfile; |
212 | } | 213 | } |
214 | sub opera1{ | ||
215 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0); | ||
216 | |||
217 | checkstandard(); | ||
218 | my $fwfile1="dvb-usb-opera1-fpga-01.fw"; | ||
219 | my $fwfile2="dvb-usb-opera-01.fw"; | ||
220 | extract("2830SCap2.sys", 0x62e8, 55024, "$tmpdir/opera1-fpga.fw"); | ||
221 | extract("2830SLoad2.sys",0x3178,0x3685-0x3178,"$tmpdir/fw1part1"); | ||
222 | extract("2830SLoad2.sys",0x0980,0x3150-0x0980,"$tmpdir/fw1part2"); | ||
223 | delzero("$tmpdir/fw1part1","$tmpdir/fw1part1-1"); | ||
224 | delzero("$tmpdir/fw1part2","$tmpdir/fw1part2-1"); | ||
225 | verify("$tmpdir/fw1part1-1","5e0909858fdf0b5b09ad48b9fe622e70"); | ||
226 | verify("$tmpdir/fw1part2-1","d6e146f321427e931df2c6fcadac37a1"); | ||
227 | verify("$tmpdir/opera1-fpga.fw","0f8133f5e9051f5f3c1928f7e5a1b07d"); | ||
228 | |||
229 | my $RES1="\x01\x92\x7f\x00\x01\x00"; | ||
230 | my $RES0="\x01\x92\x7f\x00\x00\x00"; | ||
231 | my $DAT1="\x01\x00\xe6\x00\x01\x00"; | ||
232 | my $DAT0="\x01\x00\xe6\x00\x00\x00"; | ||
233 | open FW,">$tmpdir/opera.fw"; | ||
234 | print FW "$RES1"; | ||
235 | print FW "$DAT1"; | ||
236 | print FW "$RES1"; | ||
237 | print FW "$DAT1"; | ||
238 | appendfile(FW,"$tmpdir/fw1part1-1"); | ||
239 | print FW "$RES0"; | ||
240 | print FW "$DAT0"; | ||
241 | print FW "$RES1"; | ||
242 | print FW "$DAT1"; | ||
243 | appendfile(FW,"$tmpdir/fw1part2-1"); | ||
244 | print FW "$RES1"; | ||
245 | print FW "$DAT1"; | ||
246 | print FW "$RES0"; | ||
247 | print FW "$DAT0"; | ||
248 | copy ("$tmpdir/opera1-fpga.fw",$fwfile1); | ||
249 | copy ("$tmpdir/opera.fw",$fwfile2); | ||
250 | |||
251 | $fwfile1.",".$fwfile2; | ||
252 | } | ||
213 | 253 | ||
214 | sub vp7041 { | 254 | sub vp7041 { |
215 | my $sourcefile = "2.422.zip"; | 255 | my $sourcefile = "2.422.zip"; |
@@ -440,6 +480,25 @@ sub appendfile { | |||
440 | close(INFILE); | 480 | close(INFILE); |
441 | } | 481 | } |
442 | 482 | ||
483 | sub delzero{ | ||
484 | my ($infile,$outfile) =@_; | ||
485 | |||
486 | open INFILE,"<$infile"; | ||
487 | open OUTFILE,">$outfile"; | ||
488 | while (1){ | ||
489 | $rcount=sysread(INFILE,$buf,22); | ||
490 | $len=ord(substr($buf,0,1)); | ||
491 | print OUTFILE substr($buf,0,1); | ||
492 | print OUTFILE substr($buf,2,$len+3); | ||
493 | last if ($rcount<1); | ||
494 | printf OUTFILE "%c",0; | ||
495 | #print $len." ".length($buf)."\n"; | ||
496 | |||
497 | } | ||
498 | close(INFILE); | ||
499 | close(OUTFILE); | ||
500 | } | ||
501 | |||
443 | sub syntax() { | 502 | sub syntax() { |
444 | print STDERR "syntax: get_dvb_firmware <component>\n"; | 503 | print STDERR "syntax: get_dvb_firmware <component>\n"; |
445 | print STDERR "Supported components:\n"; | 504 | print STDERR "Supported components:\n"; |
diff --git a/Documentation/dvb/opera-firmware.txt b/Documentation/dvb/opera-firmware.txt new file mode 100644 index 000000000000..93e784c2607b --- /dev/null +++ b/Documentation/dvb/opera-firmware.txt | |||
@@ -0,0 +1,27 @@ | |||
1 | To extract the firmware for the Opera DVB-S1 USB-Box | ||
2 | you need to copy the files: | ||
3 | |||
4 | 2830SCap2.sys | ||
5 | 2830SLoad2.sys | ||
6 | |||
7 | from the windriver disk into this directory. | ||
8 | |||
9 | Then run | ||
10 | |||
11 | ./get_dvb_firware opera1 | ||
12 | |||
13 | and after that you have 2 files: | ||
14 | |||
15 | dvb-usb-opera-01.fw | ||
16 | dvb-usb-opera1-fpga-01.fw | ||
17 | |||
18 | in here. | ||
19 | |||
20 | Copy them into /lib/firmware/ . | ||
21 | |||
22 | After that the driver can load the firmware | ||
23 | (if you have enabled firmware loading | ||
24 | in kernel config and have hotplug running). | ||
25 | |||
26 | |||
27 | Marco Gittler <g.marco@freenet.de> \ No newline at end of file | ||
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt index d05e6243b4df..a9941544ed8e 100644 --- a/Documentation/feature-removal-schedule.txt +++ b/Documentation/feature-removal-schedule.txt | |||
@@ -26,9 +26,7 @@ Who: Hans Verkuil <hverkuil@xs4all.nl> and | |||
26 | 26 | ||
27 | --------------------------- | 27 | --------------------------- |
28 | 28 | ||
29 | What: /sys/devices/.../power/state | 29 | What: dev->power.power_state |
30 | dev->power.power_state | ||
31 | dpm_runtime_{suspend,resume)() | ||
32 | When: July 2007 | 30 | When: July 2007 |
33 | Why: Broken design for runtime control over driver power states, confusing | 31 | Why: Broken design for runtime control over driver power states, confusing |
34 | driver-internal runtime power management with: mechanisms to support | 32 | driver-internal runtime power management with: mechanisms to support |
@@ -53,6 +51,7 @@ Who: David Miller <davem@davemloft.net> | |||
53 | What: Video4Linux API 1 ioctls and video_decoder.h from Video devices. | 51 | What: Video4Linux API 1 ioctls and video_decoder.h from Video devices. |
54 | When: December 2006 | 52 | When: December 2006 |
55 | Files: include/linux/video_decoder.h | 53 | Files: include/linux/video_decoder.h |
54 | Check: include/linux/video_decoder.h | ||
56 | Why: V4L1 AP1 was replaced by V4L2 API. during migration from 2.4 to 2.6 | 55 | Why: V4L1 AP1 was replaced by V4L2 API. during migration from 2.4 to 2.6 |
57 | series. The old API have lots of drawbacks and don't provide enough | 56 | series. The old API have lots of drawbacks and don't provide enough |
58 | means to work with all video and audio standards. The newer API is | 57 | means to work with all video and audio standards. The newer API is |
@@ -86,7 +85,7 @@ Who: Dominik Brodowski <linux@brodo.de> | |||
86 | What: remove EXPORT_SYMBOL(kernel_thread) | 85 | What: remove EXPORT_SYMBOL(kernel_thread) |
87 | When: August 2006 | 86 | When: August 2006 |
88 | Files: arch/*/kernel/*_ksyms.c | 87 | Files: arch/*/kernel/*_ksyms.c |
89 | Funcs: kernel_thread | 88 | Check: kernel_thread |
90 | Why: kernel_thread is a low-level implementation detail. Drivers should | 89 | Why: kernel_thread is a low-level implementation detail. Drivers should |
91 | use the <linux/kthread.h> API instead which shields them from | 90 | use the <linux/kthread.h> API instead which shields them from |
92 | implementation details and provides a higherlevel interface that | 91 | implementation details and provides a higherlevel interface that |
@@ -137,6 +136,15 @@ Who: Greg Kroah-Hartman <gregkh@suse.de> | |||
137 | 136 | ||
138 | --------------------------- | 137 | --------------------------- |
139 | 138 | ||
139 | What: vm_ops.nopage | ||
140 | When: Soon, provided in-kernel callers have been converted | ||
141 | Why: This interface is replaced by vm_ops.fault, but it has been around | ||
142 | forever, is used by a lot of drivers, and doesn't cost much to | ||
143 | maintain. | ||
144 | Who: Nick Piggin <npiggin@suse.de> | ||
145 | |||
146 | --------------------------- | ||
147 | |||
140 | What: Interrupt only SA_* flags | 148 | What: Interrupt only SA_* flags |
141 | When: September 2007 | 149 | When: September 2007 |
142 | Why: The interrupt related SA_* flags are replaced by IRQF_* to move them | 150 | Why: The interrupt related SA_* flags are replaced by IRQF_* to move them |
@@ -310,3 +318,13 @@ Why: The arch/powerpc tree is the merged architecture for ppc32 and ppc64 | |||
310 | Who: linuxppc-dev@ozlabs.org | 318 | Who: linuxppc-dev@ozlabs.org |
311 | 319 | ||
312 | --------------------------- | 320 | --------------------------- |
321 | |||
322 | What: mthca driver's MSI support | ||
323 | When: January 2008 | ||
324 | Files: drivers/infiniband/hw/mthca/*.[ch] | ||
325 | Why: All mthca hardware also supports MSI-X, which provides | ||
326 | strictly more functionality than MSI. So there is no point in | ||
327 | having both MSI-X and MSI support in the driver. | ||
328 | Who: Roland Dreier <rolandd@cisco.com> | ||
329 | |||
330 | --------------------------- | ||
diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index d866551be037..f0f825808ca4 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking | |||
@@ -510,13 +510,24 @@ More details about quota locking can be found in fs/dquot.c. | |||
510 | prototypes: | 510 | prototypes: |
511 | void (*open)(struct vm_area_struct*); | 511 | void (*open)(struct vm_area_struct*); |
512 | void (*close)(struct vm_area_struct*); | 512 | void (*close)(struct vm_area_struct*); |
513 | int (*fault)(struct vm_area_struct*, struct vm_fault *); | ||
513 | struct page *(*nopage)(struct vm_area_struct*, unsigned long, int *); | 514 | struct page *(*nopage)(struct vm_area_struct*, unsigned long, int *); |
515 | int (*page_mkwrite)(struct vm_area_struct *, struct page *); | ||
514 | 516 | ||
515 | locking rules: | 517 | locking rules: |
516 | BKL mmap_sem | 518 | BKL mmap_sem PageLocked(page) |
517 | open: no yes | 519 | open: no yes |
518 | close: no yes | 520 | close: no yes |
521 | fault: no yes | ||
519 | nopage: no yes | 522 | nopage: no yes |
523 | page_mkwrite: no yes no | ||
524 | |||
525 | ->page_mkwrite() is called when a previously read-only page is | ||
526 | about to become writeable. The file system is responsible for | ||
527 | protecting against truncate races. Once appropriate action has been | ||
528 | taking to lock out truncate, the page range should be verified to be | ||
529 | within i_size. The page mapping should also be checked that it is not | ||
530 | NULL. | ||
520 | 531 | ||
521 | ================================================================================ | 532 | ================================================================================ |
522 | Dubious stuff | 533 | Dubious stuff |
diff --git a/Documentation/filesystems/configfs/configfs_example.c b/Documentation/filesystems/configfs/configfs_example.c index e56d49264b39..25151fd5c2c6 100644 --- a/Documentation/filesystems/configfs/configfs_example.c +++ b/Documentation/filesystems/configfs/configfs_example.c | |||
@@ -277,11 +277,10 @@ static struct config_item *simple_children_make_item(struct config_group *group, | |||
277 | { | 277 | { |
278 | struct simple_child *simple_child; | 278 | struct simple_child *simple_child; |
279 | 279 | ||
280 | simple_child = kmalloc(sizeof(struct simple_child), GFP_KERNEL); | 280 | simple_child = kzalloc(sizeof(struct simple_child), GFP_KERNEL); |
281 | if (!simple_child) | 281 | if (!simple_child) |
282 | return NULL; | 282 | return NULL; |
283 | 283 | ||
284 | memset(simple_child, 0, sizeof(struct simple_child)); | ||
285 | 284 | ||
286 | config_item_init_type_name(&simple_child->item, name, | 285 | config_item_init_type_name(&simple_child->item, name, |
287 | &simple_child_type); | 286 | &simple_child_type); |
@@ -364,12 +363,11 @@ static struct config_group *group_children_make_group(struct config_group *group | |||
364 | { | 363 | { |
365 | struct simple_children *simple_children; | 364 | struct simple_children *simple_children; |
366 | 365 | ||
367 | simple_children = kmalloc(sizeof(struct simple_children), | 366 | simple_children = kzalloc(sizeof(struct simple_children), |
368 | GFP_KERNEL); | 367 | GFP_KERNEL); |
369 | if (!simple_children) | 368 | if (!simple_children) |
370 | return NULL; | 369 | return NULL; |
371 | 370 | ||
372 | memset(simple_children, 0, sizeof(struct simple_children)); | ||
373 | 371 | ||
374 | config_group_init_type_name(&simple_children->group, name, | 372 | config_group_init_type_name(&simple_children->group, name, |
375 | &simple_children_type); | 373 | &simple_children_type); |
diff --git a/Documentation/ecryptfs.txt b/Documentation/filesystems/ecryptfs.txt index 01d8a08351ac..01d8a08351ac 100644 --- a/Documentation/ecryptfs.txt +++ b/Documentation/filesystems/ecryptfs.txt | |||
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt index 460b892d089e..4a37e25e694c 100644 --- a/Documentation/filesystems/proc.txt +++ b/Documentation/filesystems/proc.txt | |||
@@ -42,6 +42,7 @@ Table of Contents | |||
42 | 2.12 /proc/<pid>/oom_adj - Adjust the oom-killer score | 42 | 2.12 /proc/<pid>/oom_adj - Adjust the oom-killer score |
43 | 2.13 /proc/<pid>/oom_score - Display current oom-killer score | 43 | 2.13 /proc/<pid>/oom_score - Display current oom-killer score |
44 | 2.14 /proc/<pid>/io - Display the IO accounting fields | 44 | 2.14 /proc/<pid>/io - Display the IO accounting fields |
45 | 2.15 /proc/<pid>/coredump_filter - Core dump filtering settings | ||
45 | 46 | ||
46 | ------------------------------------------------------------------------------ | 47 | ------------------------------------------------------------------------------ |
47 | Preface | 48 | Preface |
@@ -1065,6 +1066,13 @@ check the amount of free space (value is in seconds). Default settings are: 4, | |||
1065 | resume it if we have a value of 3 or more percent; consider information about | 1066 | resume it if we have a value of 3 or more percent; consider information about |
1066 | the amount of free space valid for 30 seconds | 1067 | the amount of free space valid for 30 seconds |
1067 | 1068 | ||
1069 | audit_argv_kb | ||
1070 | ------------- | ||
1071 | |||
1072 | The file contains a single value denoting the limit on the argv array size | ||
1073 | for execve (in KiB). This limit is only applied when system call auditing for | ||
1074 | execve is enabled, otherwise the value is ignored. | ||
1075 | |||
1068 | ctrl-alt-del | 1076 | ctrl-alt-del |
1069 | ------------ | 1077 | ------------ |
1070 | 1078 | ||
@@ -1348,6 +1356,21 @@ nr_hugepages configures number of hugetlb page reserved for the system. | |||
1348 | hugetlb_shm_group contains group id that is allowed to create SysV shared | 1356 | hugetlb_shm_group contains group id that is allowed to create SysV shared |
1349 | memory segment using hugetlb page. | 1357 | memory segment using hugetlb page. |
1350 | 1358 | ||
1359 | hugepages_treat_as_movable | ||
1360 | -------------------------- | ||
1361 | |||
1362 | This parameter is only useful when kernelcore= is specified at boot time to | ||
1363 | create ZONE_MOVABLE for pages that may be reclaimed or migrated. Huge pages | ||
1364 | are not movable so are not normally allocated from ZONE_MOVABLE. A non-zero | ||
1365 | value written to hugepages_treat_as_movable allows huge pages to be allocated | ||
1366 | from ZONE_MOVABLE. | ||
1367 | |||
1368 | Once enabled, the ZONE_MOVABLE is treated as an area of memory the huge | ||
1369 | pages pool can easily grow or shrink within. Assuming that applications are | ||
1370 | not running that mlock() a lot of memory, it is likely the huge pages pool | ||
1371 | can grow to the size of ZONE_MOVABLE by repeatedly entering the desired value | ||
1372 | into nr_hugepages and triggering page reclaim. | ||
1373 | |||
1351 | laptop_mode | 1374 | laptop_mode |
1352 | ----------- | 1375 | ----------- |
1353 | 1376 | ||
@@ -2162,4 +2185,41 @@ those 64-bit counters, process A could see an intermediate result. | |||
2162 | More information about this can be found within the taskstats documentation in | 2185 | More information about this can be found within the taskstats documentation in |
2163 | Documentation/accounting. | 2186 | Documentation/accounting. |
2164 | 2187 | ||
2188 | 2.15 /proc/<pid>/coredump_filter - Core dump filtering settings | ||
2189 | --------------------------------------------------------------- | ||
2190 | When a process is dumped, all anonymous memory is written to a core file as | ||
2191 | long as the size of the core file isn't limited. But sometimes we don't want | ||
2192 | to dump some memory segments, for example, huge shared memory. Conversely, | ||
2193 | sometimes we want to save file-backed memory segments into a core file, not | ||
2194 | only the individual files. | ||
2195 | |||
2196 | /proc/<pid>/coredump_filter allows you to customize which memory segments | ||
2197 | will be dumped when the <pid> process is dumped. coredump_filter is a bitmask | ||
2198 | of memory types. If a bit of the bitmask is set, memory segments of the | ||
2199 | corresponding memory type are dumped, otherwise they are not dumped. | ||
2200 | |||
2201 | The following 4 memory types are supported: | ||
2202 | - (bit 0) anonymous private memory | ||
2203 | - (bit 1) anonymous shared memory | ||
2204 | - (bit 2) file-backed private memory | ||
2205 | - (bit 3) file-backed shared memory | ||
2206 | |||
2207 | Note that MMIO pages such as frame buffer are never dumped and vDSO pages | ||
2208 | are always dumped regardless of the bitmask status. | ||
2209 | |||
2210 | Default value of coredump_filter is 0x3; this means all anonymous memory | ||
2211 | segments are dumped. | ||
2212 | |||
2213 | If you don't want to dump all shared memory segments attached to pid 1234, | ||
2214 | write 1 to the process's proc file. | ||
2215 | |||
2216 | $ echo 0x1 > /proc/1234/coredump_filter | ||
2217 | |||
2218 | When a new process is created, the process inherits the bitmask status from its | ||
2219 | parent. It is useful to set up coredump_filter before the program runs. | ||
2220 | For example: | ||
2221 | |||
2222 | $ echo 0x7 > /proc/self/coredump_filter | ||
2223 | $ ./some_program | ||
2224 | |||
2165 | ------------------------------------------------------------------------------ | 2225 | ------------------------------------------------------------------------------ |
diff --git a/Documentation/gpio.txt b/Documentation/gpio.txt index 36af58eba136..218a8650f48d 100644 --- a/Documentation/gpio.txt +++ b/Documentation/gpio.txt | |||
@@ -75,6 +75,9 @@ using the include file: | |||
75 | If you stick to this convention then it'll be easier for other developers to | 75 | If you stick to this convention then it'll be easier for other developers to |
76 | see what your code is doing, and help maintain it. | 76 | see what your code is doing, and help maintain it. |
77 | 77 | ||
78 | Note that these operations include I/O barriers on platforms which need to | ||
79 | use them; drivers don't need to add them explicitly. | ||
80 | |||
78 | 81 | ||
79 | Identifying GPIOs | 82 | Identifying GPIOs |
80 | ----------------- | 83 | ----------------- |
diff --git a/Documentation/ja_JP/HOWTO b/Documentation/ja_JP/HOWTO new file mode 100644 index 000000000000..b2446a090870 --- /dev/null +++ b/Documentation/ja_JP/HOWTO | |||
@@ -0,0 +1,650 @@ | |||
1 | NOTE: | ||
2 | This is Japanese translated version of "Documentation/HOWTO". | ||
3 | This one is maintained by Tsugikazu Shibata <tshibata@ab.jp.nec.com> | ||
4 | and JF Project team <www.linux.or.jp/JF>. | ||
5 | If you find difference with original file or problem in translation, | ||
6 | please contact maintainer of this file or JF project. | ||
7 | |||
8 | Please also note that purpose of this file is easier to read for non | ||
9 | English natives and not to be intended to fork. So, if you have any | ||
10 | comments or updates of this file, please try to update Original(English) | ||
11 | file at first. | ||
12 | |||
13 | Last Updated: 2007/06/04 | ||
14 | ================================== | ||
15 | これは、 | ||
16 | linux-2.6.21/Documentation/HOWTO | ||
17 | の和訳です。 | ||
18 | |||
19 | 翻訳団体: JF プロジェクト < http://www.linux.or.jp/JF/ > | ||
20 | 翻訳日: 2007/06/04 | ||
21 | 翻訳者: Tsugikazu Shibata <tshibata at ab dot jp dot nec dot com> | ||
22 | 校正者: 松倉さん <nbh--mats at nifty dot com> | ||
23 | 小林 雅典さん (Masanori Kobayasi) <zap03216 at nifty dot ne dot jp> | ||
24 | 武井伸光さん、<takei at webmasters dot gr dot jp> | ||
25 | かねこさん (Seiji Kaneko) <skaneko at a2 dot mbn dot or dot jp> | ||
26 | 野口さん (Kenji Noguchi) <tokyo246 at gmail dot com> | ||
27 | 河内さん (Takayoshi Kochi) <t-kochi at bq dot jp dot nec dot com> | ||
28 | 岩本さん (iwamoto) <iwamoto.kn at ncos dot nec dot co dot jp> | ||
29 | ================================== | ||
30 | |||
31 | Linux カーネル開発のやり方 | ||
32 | ------------------------------- | ||
33 | |||
34 | これは上のトピック( Linux カーネル開発のやり方)の重要な事柄を網羅した | ||
35 | ドキュメントです。ここには Linux カーネル開発者になるための方法と | ||
36 | Linux カーネル開発コミュニティと共に活動するやり方を学ぶ方法が含まれて | ||
37 | います。カーネルプログラミングに関する技術的な項目に関することは何も含 | ||
38 | めないようにしていますが、カーネル開発者となるための正しい方向に向かう | ||
39 | 手助けになります。 | ||
40 | |||
41 | もし、このドキュメントのどこかが古くなっていた場合には、このドキュメン | ||
42 | トの最後にリストしたメンテナーにパッチを送ってください。 | ||
43 | |||
44 | はじめに | ||
45 | --------- | ||
46 | |||
47 | あなたは Linux カーネルの開発者になる方法を学びたいのでしょうか? そ | ||
48 | れともあなたは上司から「このデバイスの Linux ドライバを書くように」と | ||
49 | 言われているのでしょうか? | ||
50 | この文書の目的は、あなたが踏むべき手順と、コミュニティと一緒にうまく働 | ||
51 | くヒントを書き下すことで、あなたが知るべき全てのことを教えることです。 | ||
52 | また、このコミュニティがなぜ今うまくまわっているのかという理由の一部も | ||
53 | 説明しようと試みています。 | ||
54 | |||
55 | カーネルは 少量のアーキテクチャ依存部分がアセンブリ言語で書かれている | ||
56 | 以外は大部分は C 言語で書かれています。C言語をよく理解していることはカー | ||
57 | ネル開発者には必要です。アーキテクチャ向けの低レベル部分の開発をするの | ||
58 | でなければ、(どんなアーキテクチャでも)アセンブリ(訳注: 言語)は必要あり | ||
59 | ません。以下の本は、C 言語の十分な知識や何年もの経験に取って代わるもの | ||
60 | ではありませんが、少なくともリファレンスとしてはいい本です。 | ||
61 | - "The C Programming Language" by Kernighan and Ritchie [Prentice Hall] | ||
62 | -『プログラミング言語C第2版』(B.W. カーニハン/D.M. リッチー著 石田晴久訳) [共立出版] | ||
63 | - "Practical C Programming" by Steve Oualline [O'Reilly] | ||
64 | - 『C実践プログラミング第3版』(Steve Oualline著 望月康司監訳 谷口功訳) [オライリージャパン] | ||
65 | - "C: A Reference Manual" by Harbison and Steele [Prentice Hall] | ||
66 | - 『新・詳説 C 言語 H&S リファレンス』 | ||
67 | (サミュエル P ハービソン/ガイ L スティール共著 斉藤 信男監訳)[ソフトバンク] | ||
68 | |||
69 | カーネルは GNU C と GNU ツールチェインを使って書かれています。カーネル | ||
70 | は ISO C89 仕様に準拠して書く一方で、標準には無い言語拡張を多く使って | ||
71 | います。カーネルは標準 C ライブラリとは関係がないといった、C 言語フリー | ||
72 | スタンディング環境です。そのため、C の標準で使えないものもあります。任 | ||
73 | 意の long long の除算や浮動小数点は使えません。 | ||
74 | ときどき、カーネルがツールチェインや C 言語拡張に置いている前提がどう | ||
75 | なっているのかわかりにくいことがあり、また、残念なことに決定的なリファ | ||
76 | レンスは存在しません。情報を得るには、gcc の info ページ( info gcc )を | ||
77 | みてください。 | ||
78 | |||
79 | あなたは既存の開発コミュニティと一緒に作業する方法を学ぼうとしているこ | ||
80 | とに留意してください。そのコミュニティは、コーディング、スタイル、 | ||
81 | 開発手順について高度な標準を持つ、多様な人の集まりです。 | ||
82 | 地理的に分散した大規模なチームに対してもっともうまくいくとわかったこと | ||
83 | をベースにしながら、これらの標準は長い時間をかけて築かれてきました。 | ||
84 | これらはきちんと文書化されていますから、事前にこれらの標準についてでき | ||
85 | るだけたくさん学んでください。また皆があなたやあなたの会社のやり方に合わ | ||
86 | せてくれると思わないでください。 | ||
87 | |||
88 | 法的問題 | ||
89 | ------------ | ||
90 | |||
91 | Linux カーネルのソースコードは GPL ライセンスの下でリリースされていま | ||
92 | す。ライセンスの詳細については、ソースツリーのメインディレクトリに存在 | ||
93 | する、COPYING のファイルをみてください。もしライセンスについてさらに質 | ||
94 | 問があれば、Linux Kernel メーリングリストに質問するのではなく、どうぞ | ||
95 | 法律家に相談してください。メーリングリストの人達は法律家ではなく、法的 | ||
96 | 問題については彼らの声明はあてにするべきではありません。 | ||
97 | |||
98 | GPL に関する共通の質問や回答については、以下を参照してください。 | ||
99 | http://www.gnu.org/licenses/gpl-faq.html | ||
100 | |||
101 | ドキュメント | ||
102 | ------------ | ||
103 | |||
104 | Linux カーネルソースツリーは幅広い範囲のドキュメントを含んでおり、それ | ||
105 | らはカーネルコミュニティと会話する方法を学ぶのに非常に貴重なものです。 | ||
106 | 新しい機能がカーネルに追加される場合、その機能の使い方について説明した | ||
107 | 新しいドキュメントファイルも追加することを勧めます。 | ||
108 | カーネルの変更が、カーネルがユーザ空間に公開しているインターフェイスの | ||
109 | 変更を引き起こす場合、その変更を説明するマニュアルページのパッチや情報 | ||
110 | をマニュアルページのメンテナ mtk-manpages@gmx.net に送ることを勧めます。 | ||
111 | |||
112 | 以下はカーネルソースツリーに含まれている読んでおくべきファイルの一覧で | ||
113 | す- | ||
114 | |||
115 | README | ||
116 | このファイルは Linuxカーネルの簡単な背景とカーネルを設定(訳注 | ||
117 | configure )し、生成(訳注 build )するために必要なことは何かが書かれ | ||
118 | ています。カーネルに関して初めての人はここからスタートするとよいで | ||
119 | しょう。 | ||
120 | |||
121 | Documentation/Changes | ||
122 | このファイルはカーネルをうまく生成(訳注 build )し、走らせるのに最 | ||
123 | 小限のレベルで必要な数々のソフトウェアパッケージの一覧を示してい | ||
124 | ます。 | ||
125 | |||
126 | Documentation/CodingStyle | ||
127 | これは Linux カーネルのコーディングスタイルと背景にある理由を記述 | ||
128 | しています。全ての新しいコードはこのドキュメントにあるガイドライン | ||
129 | に従っていることを期待されています。大部分のメンテナーはこれらのルー | ||
130 | ルに従っているものだけを受け付け、多くの人は正しいスタイルのコード | ||
131 | だけをレビューします。 | ||
132 | |||
133 | Documentation/SubmittingPatches | ||
134 | Documentation/SubmittingDrivers | ||
135 | これらのファイルには、どうやってうまくパッチを作って投稿するかに | ||
136 | ついて非常に詳しく書かれており、以下を含みます(これだけに限らない | ||
137 | けれども) | ||
138 | - Email に含むこと | ||
139 | - Email の形式 | ||
140 | - だれに送るか | ||
141 | これらのルールに従えばうまくいくことを保証することではありません | ||
142 | が (すべてのパッチは内容とスタイルについて精査を受けるので)、 | ||
143 | ルールに従わなければ間違いなくうまくいかないでしょう。 | ||
144 | この他にパッチを作る方法についてのよくできた記述は- | ||
145 | |||
146 | "The Perfect Patch" | ||
147 | http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt | ||
148 | "Linux kernel patch submission format" | ||
149 | http://linux.yyz.us/patch-format.html | ||
150 | |||
151 | Documentation/stable_api_nonsense.txt | ||
152 | このファイルはカーネルの中に不変のAPIを持たないことにした意識的な | ||
153 | 決断の背景にある理由について書かれています。以下のようなことを含 | ||
154 | んでいます- | ||
155 | - サブシステムとの間に層を作ること(コンパチビリティのため?) | ||
156 | - オペレーティングシステム間のドライバの移植性 | ||
157 | - カーネルソースツリーの素早い変更を遅らせる(もしくは素早い変更 | ||
158 | を妨げる) | ||
159 | このドキュメントは Linux 開発の思想を理解するのに非常に重要です。 | ||
160 | そして、他のOSでの開発者が Linux に移る時にとても重要です。 | ||
161 | |||
162 | Documentation/SecurityBugs | ||
163 | もし Linux カーネルでセキュリティ問題を発見したように思ったら、こ | ||
164 | のドキュメントのステップに従ってカーネル開発者に連絡し、問題解決を | ||
165 | 支援してください。 | ||
166 | |||
167 | Documentation/ManagementStyle | ||
168 | このドキュメントは Linux カーネルのメンテナー達がどう行動するか、 | ||
169 | 彼らの手法の背景にある共有されている精神について記述しています。こ | ||
170 | れはカーネル開発の初心者なら(もしくは、単に興味があるだけの人でも) | ||
171 | 重要です。なぜならこのドキュメントは、カーネルメンテナー達の独特な | ||
172 | 行動についての多くの誤解や混乱を解消するからです。 | ||
173 | |||
174 | Documentation/stable_kernel_rules.txt | ||
175 | このファイルはどのように stable カーネルのリリースが行われるかのルー | ||
176 | ルが記述されています。そしてこれらのリリースの中のどこかで変更を取 | ||
177 | り入れてもらいたい場合に何をすればいいかが示されています。 | ||
178 | |||
179 | Documentation/kernel-docs.txt | ||
180 | カーネル開発に付随する外部ドキュメントのリストです。もしあなたが | ||
181 | 探しているものがカーネル内のドキュメントでみつからなかった場合、 | ||
182 | このリストをあたってみてください。 | ||
183 | |||
184 | Documentation/applying-patches.txt | ||
185 | パッチとはなにか、パッチをどうやって様々なカーネルの開発ブランチに | ||
186 | 適用するのかについて正確に記述した良い入門書です。 | ||
187 | |||
188 | カーネルはソースコードから自動的に生成可能な多数のドキュメントを自分自 | ||
189 | 身でもっています。これにはカーネル内 API のすべての記述や、どう正しく | ||
190 | ロックをかけるかの規則が含まれます。このドキュメントは | ||
191 | Documentation/DocBook/ ディレクトリに作られ、以下のように | ||
192 | make pdfdocs | ||
193 | make psdocs | ||
194 | make htmldocs | ||
195 | make mandocs | ||
196 | コマンドを実行するとメインカーネルのソースディレクトリから | ||
197 | それぞれ、PDF, Postscript, HTML, man page の形式で生成されます。 | ||
198 | |||
199 | カーネル開発者になるには | ||
200 | --------------------------- | ||
201 | |||
202 | もしあなたが、Linux カーネル開発について何も知らないならば、 | ||
203 | KernelNewbies プロジェクトを見るべきです | ||
204 | http://kernelnewbies.org | ||
205 | |||
206 | このサイトには役に立つメーリングリストがあり、基本的なカーネル開発に関 | ||
207 | するほとんどどんな種類の質問もできます (既に回答されているようなことを | ||
208 | 聞く前にまずはアーカイブを調べてください)。 | ||
209 | またここには、リアルタイムで質問を聞くことができる IRC チャネルや、Linux | ||
210 | カーネルの開発に関して学ぶのに便利なたくさんの役に立つドキュメントがあ | ||
211 | ります。 | ||
212 | |||
213 | web サイトには、コードの構成、サブシステム、現在存在するプロジェクト(ツ | ||
214 | リーにあるもの無いものの両方)の基本的な管理情報があります。 | ||
215 | ここには、また、カーネルのコンパイルのやり方やパッチの当て方などの間接 | ||
216 | 的な基本情報も記述されています。 | ||
217 | |||
218 | あなたがどこからスタートしてよいかわからないが、Linux カーネル開発コミュ | ||
219 | ニティに参加して何かすることをさがしている場合には、Linux kernel | ||
220 | Janitor's プロジェクトにいけばよいでしょう - | ||
221 | http://janitor.kernelnewbies.org/ | ||
222 | ここはそのようなスタートをするのにうってつけの場所です。ここには、 | ||
223 | Linux カーネルソースツリーの中に含まれる、きれいにし、修正しなければな | ||
224 | らない、単純な問題のリストが記述されています。このプロジェクトに関わる | ||
225 | 開発者と一緒に作業することで、あなたのパッチを Linuxカーネルツリーに入 | ||
226 | れるための基礎を学ぶことができ、そしてもしあなたがまだアイディアを持っ | ||
227 | ていない場合には、次にやる仕事の方向性が見えてくるかもしれません。 | ||
228 | |||
229 | もしあなたが、すでにひとまとまりコードを書いていて、カーネルツリーに入 | ||
230 | れたいと思っていたり、それに関する適切な支援を求めたい場合、カーネル | ||
231 | メンターズプロジェクトはそのような皆さんを助けるためにできました。 | ||
232 | ここにはメーリングリストがあり、以下から参照できます | ||
233 | http://selenic.com/mailman/listinfo/kernel-mentors | ||
234 | |||
235 | 実際に Linux カーネルのコードについて修正を加える前に、どうやってその | ||
236 | コードが動作するのかを理解することが必要です。そのためには、特別なツー | ||
237 | ルの助けを借りてでも、それを直接よく読むことが最良の方法です(ほとんど | ||
238 | のトリッキーな部分は十分にコメントしてありますから)。そういうツールで | ||
239 | 特におすすめなのは、Linux クロスリファレンスプロジェクトです。これは、 | ||
240 | 自己参照方式で、索引がついた web 形式で、ソースコードを参照することが | ||
241 | できます。この最新の素晴しいカーネルコードのリポジトリは以下で見つかり | ||
242 | ます- | ||
243 | http://sosdg.org/~coywolf/lxr/ | ||
244 | |||
245 | 開発プロセス | ||
246 | ----------------------- | ||
247 | |||
248 | Linux カーネルの開発プロセスは現在幾つかの異なるメインカーネル「ブラン | ||
249 | チ」と多数のサブシステム毎のカーネルブランチから構成されます。 | ||
250 | これらのブランチとは- | ||
251 | - メインの 2.6.x カーネルツリー | ||
252 | - 2.6.x.y -stable カーネルツリー | ||
253 | - 2.6.x -git カーネルパッチ | ||
254 | - 2.6.x -mm カーネルパッチ | ||
255 | - サブシステム毎のカーネルツリーとパッチ | ||
256 | |||
257 | 2.6.x カーネルツリー | ||
258 | ----------------- | ||
259 | |||
260 | 2.6.x カーネルは Linus Torvalds によってメンテナンスされ、kernel.org | ||
261 | の pub/linux/kernel/v2.6/ ディレクトリに存在します。この開発プロセスは | ||
262 | 以下のとおり- | ||
263 | |||
264 | - 新しいカーネルがリリースされた直後に、2週間の特別期間が設けられ、 | ||
265 | この期間中に、メンテナー達は Linus に大きな差分を送ることができま | ||
266 | す。このような差分は通常 -mm カーネルに数週間含まれてきたパッチで | ||
267 | す。 大きな変更は git(カーネルのソース管理ツール、詳細は | ||
268 | http://git.or.cz/ 参照) を使って送るのが好ましいやり方ですが、パッ | ||
269 | チファイルの形式のまま送るのでも十分です。 | ||
270 | |||
271 | - 2週間後、-rc1 カーネルがリリースされ、この後にはカーネル全体の安定 | ||
272 | 性に影響をあたえるような新機能は含まない類のパッチしか取り込むこと | ||
273 | はできません。新しいドライバ(もしくはファイルシステム)のパッチは | ||
274 | -rc1 の後で受け付けられることもあることを覚えておいてください。な | ||
275 | ぜなら、変更が独立していて、追加されたコードの外の領域に影響を与え | ||
276 | ない限り、退行のリスクは無いからです。-rc1 がリリースされた後、 | ||
277 | Linus へパッチを送付するのに git を使うこともできますが、パッチは | ||
278 | レビューのために、パブリックなメーリングリストへも同時に送る必要が | ||
279 | あります。 | ||
280 | |||
281 | - 新しい -rc は Linus が、最新の git ツリーがテスト目的であれば十分 | ||
282 | に安定した状態にあると判断したときにリリースされます。目標は毎週新 | ||
283 | しい -rc カーネルをリリースすることです。 | ||
284 | |||
285 | - このプロセスはカーネルが 「準備ができた」と考えられるまで継続しま | ||
286 | す。このプロセスはだいたい 6週間継続します。 | ||
287 | |||
288 | Andrew Morton が Linux-kernel メーリングリストにカーネルリリースについ | ||
289 | て書いたことをここで言っておくことは価値があります- | ||
290 | 「カーネルがいつリリースされるかは誰も知りません。なぜなら、これは現 | ||
291 | 実に認識されたバグの状況によりリリースされるのであり、前もって決めら | ||
292 | れた計画によってリリースされるものではないからです。」 | ||
293 | |||
294 | 2.6.x.y -stable カーネルツリー | ||
295 | --------------------------- | ||
296 | |||
297 | バージョンに4つ目の数字がついたカーネルは -stable カーネルです。これに | ||
298 | は、2.6.x カーネルで見つかったセキュリティ問題や重大な後戻りに対する比 | ||
299 | 較的小さい重要な修正が含まれます。 | ||
300 | |||
301 | これは、開発/実験的バージョンのテストに協力することに興味が無く、 | ||
302 | 最新の安定したカーネルを使いたいユーザに推奨するブランチです。 | ||
303 | |||
304 | もし、2.6.x.y カーネルが存在しない場合には、番号が一番大きい 2.6.x | ||
305 | が最新の安定版カーネルです。 | ||
306 | |||
307 | 2.6.x.y は "stable" チーム <stable@kernel.org> でメンテされており、だ | ||
308 | いたい隔週でリリースされています。 | ||
309 | |||
310 | カーネルツリーに入っている、Documentation/stable_kernel_rules.txt ファ | ||
311 | イルにはどのような種類の変更が -stable ツリーに受け入れ可能か、またリ | ||
312 | リースプロセスがどう動くかが記述されています。 | ||
313 | |||
314 | 2.6.x -git パッチ | ||
315 | ------------------ | ||
316 | |||
317 | git リポジトリで管理されているLinus のカーネルツリーの毎日のスナップ | ||
318 | ショットがあります。(だから -git という名前がついています)。これらのパッ | ||
319 | チはおおむね毎日リリースされており、Linus のツリーの現状を表します。こ | ||
320 | れは -rc カーネルと比べて、パッチが大丈夫かどうかも確認しないで自動的 | ||
321 | に生成されるので、より実験的です。 | ||
322 | |||
323 | 2.6.x -mm カーネルパッチ | ||
324 | ------------------------ | ||
325 | |||
326 | Andrew Morton によってリリースされる実験的なカーネルパッチ群です。 | ||
327 | Andrew は個別のサブシステムカーネルツリーとパッチを全て集めてきて | ||
328 | linux-kernel メーリングリストで収集された多数のパッチと同時に一つにま | ||
329 | とめます。 | ||
330 | このツリーは新機能とパッチが検証される場となります。ある期間の間パッチ | ||
331 | が -mm に入って価値を証明されたら、Andrew やサブシステムメンテナが、メ | ||
332 | インラインへ入れるように Linus にプッシュします。 | ||
333 | |||
334 | メインカーネルツリーに含めるために Linus に送る前に、すべての新しいパッ | ||
335 | チが -mm ツリーでテストされることが強く推奨されます。 | ||
336 | |||
337 | これらのカーネルは安定して動作すべきシステムとして使うのには適切ではあ | ||
338 | りませんし、カーネルブランチの中でももっとも動作にリスクが高いものです。 | ||
339 | |||
340 | もしあなたが、カーネル開発プロセスの支援をしたいと思っているのであれば、 | ||
341 | どうぞこれらのカーネルリリースをテストに使ってみて、そしてもし問題があ | ||
342 | れば、またもし全てが正しく動作したとしても、linux-kernel メーリングリ | ||
343 | ストにフィードバックを提供してください。 | ||
344 | |||
345 | すべての他の実験的パッチに加えて、これらのカーネルは通常リリース時点で | ||
346 | メインラインの -git カーネルに含まれる全ての変更も含んでいます。 | ||
347 | |||
348 | -mm カーネルは決まったスケジュールではリリースされません、しかし通常幾 | ||
349 | つかの -mm カーネル (1 から 3 が普通)が各-rc カーネルの間にリリースさ | ||
350 | れます。 | ||
351 | |||
352 | サブシステム毎のカーネルツリーとパッチ | ||
353 | ------------------------------------------- | ||
354 | |||
355 | カーネルの様々な領域で何が起きているかを見られるようにするため、多くの | ||
356 | カーネルサブシステム開発者は彼らの開発ツリーを公開しています。これらの | ||
357 | ツリーは説明したように -mm カーネルリリースに入れ込まれます。 | ||
358 | |||
359 | 以下はさまざまなカーネルツリーの中のいくつかのリスト- | ||
360 | |||
361 | git ツリー- | ||
362 | - Kbuild の開発ツリー、Sam Ravnborg <sam@ravnborg.org> | ||
363 | kernel.org:/pub/scm/linux/kernel/git/sam/kbuild.git | ||
364 | |||
365 | - ACPI の開発ツリー、 Len Brown <len.brown@intel.com> | ||
366 | kernel.org:/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6.git | ||
367 | |||
368 | - Block の開発ツリー、Jens Axboe <axboe@suse.de> | ||
369 | kernel.org:/pub/scm/linux/kernel/git/axboe/linux-2.6-block.git | ||
370 | |||
371 | - DRM の開発ツリー、Dave Airlie <airlied@linux.ie> | ||
372 | kernel.org:/pub/scm/linux/kernel/git/airlied/drm-2.6.git | ||
373 | |||
374 | - ia64 の開発ツリー、Tony Luck <tony.luck@intel.com> | ||
375 | kernel.org:/pub/scm/linux/kernel/git/aegl/linux-2.6.git | ||
376 | |||
377 | - ieee1394 の開発ツリー、Jody McIntyre <scjody@modernduck.com> | ||
378 | kernel.org:/pub/scm/linux/kernel/git/scjody/ieee1394.git | ||
379 | |||
380 | - infiniband, Roland Dreier <rolandd@cisco.com> | ||
381 | kernel.org:/pub/scm/linux/kernel/git/roland/infiniband.git | ||
382 | |||
383 | - libata, Jeff Garzik <jgarzik@pobox.com> | ||
384 | kernel.org:/pub/scm/linux/kernel/git/jgarzik/libata-dev.git | ||
385 | |||
386 | - ネットワークドライバ, Jeff Garzik <jgarzik@pobox.com> | ||
387 | kernel.org:/pub/scm/linux/kernel/git/jgarzik/netdev-2.6.git | ||
388 | |||
389 | - pcmcia, Dominik Brodowski <linux@dominikbrodowski.net> | ||
390 | kernel.org:/pub/scm/linux/kernel/git/brodo/pcmcia-2.6.git | ||
391 | |||
392 | - SCSI, James Bottomley <James.Bottomley@SteelEye.com> | ||
393 | kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git | ||
394 | |||
395 | その他の git カーネルツリーは http://kernel.org/git に一覧表がありま | ||
396 | す。 | ||
397 | |||
398 | quilt ツリー- | ||
399 | - USB, PCI ドライバコアと I2C, Greg Kroah-Hartman <gregkh@suse.de> | ||
400 | kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/ | ||
401 | |||
402 | バグレポート | ||
403 | ------------- | ||
404 | |||
405 | bugzilla.kernel.org は Linux カーネル開発者がカーネルのバグを追跡する | ||
406 | 場所です。ユーザは見つけたバグの全てをこのツールで報告すべきです。 | ||
407 | どう kernel bugzilla を使うかの詳細は、以下を参照してください- | ||
408 | http://test.kernel.org/bugzilla/faq.html | ||
409 | |||
410 | メインカーネルソースディレクトリにあるファイル REPORTING-BUGS はカーネ | ||
411 | ルバグらしいものについてどうレポートするかの良いテンプレートであり、問 | ||
412 | 題の追跡を助けるためにカーネル開発者にとってどんな情報が必要なのかの詳 | ||
413 | 細が書かれています。 | ||
414 | |||
415 | メーリングリスト | ||
416 | ------------- | ||
417 | |||
418 | 上のいくつかのドキュメントで述べていますが、コアカーネル開発者の大部分 | ||
419 | は Linux kernel メーリングリストに参加しています。このリストの登録/脱 | ||
420 | 退の方法については以下を参照してください- | ||
421 | http://vger.kernel.org/vger-lists.html#linux-kernel | ||
422 | |||
423 | このメーリングリストのアーカイブは web 上の多数の場所に存在します。こ | ||
424 | れらのアーカイブを探すにはサーチエンジンを使いましょう。例えば- | ||
425 | http://dir.gmane.org/gmane.linux.kernel | ||
426 | |||
427 | リストに投稿する前にすでにその話題がアーカイブに存在するかどうかを検索 | ||
428 | することを是非やってください。多数の事がすでに詳細に渡って議論されて | ||
429 | おり、アーカイブにのみ記録されています。 | ||
430 | |||
431 | 大部分のカーネルサブシステムも自分の個別の開発を実施するメーリングリス | ||
432 | トを持っています。個々のグループがどんなリストを持っているかは、 | ||
433 | MAINTAINERS ファイルにリストがありますので参照してください。 | ||
434 | |||
435 | 多くのリストは kernel.org でホストされています。これらの情報は以下にあ | ||
436 | ります- | ||
437 | http://vger.kernel.org/vger-lists.html | ||
438 | |||
439 | メーリングリストを使う場合、良い行動習慣に従うようにしましょう。 | ||
440 | 少し安っぽいが、以下の URL は上のリスト(や他のリスト)で会話する場合の | ||
441 | シンプルなガイドラインを示しています- | ||
442 | http://www.albion.com/netiquette/ | ||
443 | |||
444 | もし複数の人があなたのメールに返事をした場合、CC: で受ける人のリストは | ||
445 | だいぶ多くなるでしょう。良い理由がない場合、CC: リストから誰かを削除を | ||
446 | しないように、また、メーリングリストのアドレスだけにリプライすることの | ||
447 | ないようにしましょう。1つは送信者から、もう1つはリストからのように、メー | ||
448 | ルを2回受けることになってもそれに慣れ、しゃれたメールヘッダーを追加し | ||
449 | てこの状態を変えようとしないように。人々はそのようなことは好みません。 | ||
450 | |||
451 | 今までのメールでのやりとりとその間のあなたの発言はそのまま残し、 | ||
452 | "John Kernlehacker wrote ...:" の行をあなたのリプライの先頭行にして、 | ||
453 | メールの先頭でなく、各引用行の間にあなたの言いたいことを追加するべきで | ||
454 | す。 | ||
455 | |||
456 | もしパッチをメールに付ける場合は、Documentaion/SubmittingPatches に提 | ||
457 | 示されているように、それは プレーンな可読テキストにすることを忘れない | ||
458 | ようにしましょう。カーネル開発者は 添付や圧縮したパッチを扱いたがりま | ||
459 | せん- | ||
460 | 彼らはあなたのパッチの行毎にコメントを入れたいので、そのためにはそうす | ||
461 | るしかありません。あなたのメールプログラムが空白やタブを圧縮しないよう | ||
462 | に確認した方がいいです。最初の良いテストとしては、自分にメールを送って | ||
463 | みて、そのパッチを自分で当ててみることです。もしそれがうまく行かないな | ||
464 | ら、あなたのメールプログラムを直してもらうか、正しく動くように変えるべ | ||
465 | きです。 | ||
466 | |||
467 | とりわけ、他の登録者に対する尊敬を表すようにすることを覚えておいてくだ | ||
468 | さい。 | ||
469 | |||
470 | コミュニティと共に働くこと | ||
471 | -------------------------- | ||
472 | |||
473 | カーネルコミュニティのゴールは可能なかぎり最高のカーネルを提供すること | ||
474 | です。あなたがパッチを受け入れてもらうために投稿した場合、それは、技術 | ||
475 | 的メリットだけがレビューされます。その際、あなたは何を予想すべきでしょ | ||
476 | うか? | ||
477 | - 批判 | ||
478 | - コメント | ||
479 | - 変更の要求 | ||
480 | - パッチの正当性の証明要求 | ||
481 | - 沈黙 | ||
482 | |||
483 | 思い出してください、ここはあなたのパッチをカーネルに入れる話です。あ | ||
484 | なたは、あなたのパッチに対する批判とコメントを受け入れるべきで、それら | ||
485 | を技術的レベルで評価して、パッチを再作成するか、なぜそれらの変更をすべ | ||
486 | きでないかを明確で簡潔な理由の説明を提供してください。 | ||
487 | もし、あなたのパッチに何も反応がない場合、たまにはメールの山に埋もれて | ||
488 | 見逃され、あなたの投稿が忘れられてしまうこともあるので、数日待って再度 | ||
489 | 投稿してください。 | ||
490 | |||
491 | あなたがやるべきでないものは? | ||
492 | - 質問なしにあなたのパッチが受け入れられると想像すること | ||
493 | - 守りに入ること | ||
494 | - コメントを無視すること | ||
495 | - 要求された変更を何もしないでパッチを出し直すこと | ||
496 | |||
497 | 可能な限り最高の技術的解決を求めているコミュニティでは、パッチがどのく | ||
498 | らい有益なのかについては常に異なる意見があります。あなたは協調的である | ||
499 | べきですし、また、あなたのアイディアをカーネルに対してうまく合わせるよ | ||
500 | うにすることが望まれています。もしくは、最低限あなたのアイディアがそれ | ||
501 | だけの価値があるとすすんで証明するようにしなければなりません。 | ||
502 | 正しい解決に向かって進もうという意志がある限り、間違うことがあっても許 | ||
503 | 容されることを忘れないでください。 | ||
504 | |||
505 | あなたの最初のパッチに単に 1ダースもの修正を求めるリストの返答になるこ | ||
506 | とも普通のことです。これはあなたのパッチが受け入れられないということで | ||
507 | は *ありません*、そしてあなた自身に反対することを意味するのでも *ありま | ||
508 | せん*。単に自分のパッチに対して指摘された問題を全て修正して再送すれば | ||
509 | いいのです。 | ||
510 | |||
511 | カーネルコミュニティと企業組織のちがい | ||
512 | ----------------------------------------------------------------- | ||
513 | |||
514 | カーネルコミュニティは大部分の伝統的な会社の開発環境とは異ったやり方で | ||
515 | 動いています。以下は問題を避けるためにできるとよいことののリストです- | ||
516 | |||
517 | あなたの提案する変更について言うときのうまい言い方: | ||
518 | |||
519 | - "これは複数の問題を解決します" | ||
520 | - "これは2000行のコードを削除します" | ||
521 | - "以下のパッチは、私が言おうとしていることを説明するものです" | ||
522 | - "私はこれを5つの異なるアーキテクチャでテストしたのですが..." | ||
523 | - "以下は一連の小さなパッチ群ですが..." | ||
524 | - "これは典型的なマシンでの性能を向上させます.." | ||
525 | |||
526 | やめた方がいい悪い言い方: | ||
527 | |||
528 | - このやり方で AIX/ptx/Solaris ではできたので、できるはずだ | ||
529 | - 私はこれを20年もの間やってきた、だから | ||
530 | - これは、私の会社が金儲けをするために必要だ | ||
531 | - これは我々のエンタープライズ向け商品ラインのためである | ||
532 | - これは 私が自分のアイディアを記述した、1000ページの設計資料である | ||
533 | - 私はこれについて、6ケ月作業している。 | ||
534 | - 以下は ... に関する5000行のパッチです | ||
535 | - 私は現在のぐちゃぐちゃを全部書き直した、それが以下です... | ||
536 | - 私は〆切がある、そのためこのパッチは今すぐ適用される必要がある | ||
537 | |||
538 | カーネルコミュニティが大部分の伝統的なソフトウェアエンジニアリングの労 | ||
539 | 働環境と異なるもう一つの点は、やりとりに顔を合わせないということです。 | ||
540 | email と irc を第一のコミュニケーションの形とする一つの利点は、性別や | ||
541 | 民族の差別がないことです。Linux カーネルの職場環境は女性や少数民族を受 | ||
542 | 容します。なぜなら、email アドレスによってのみあなたが認識されるからで | ||
543 | す。 | ||
544 | 国際的な側面からも活動領域を均等にするようにします。なぜならば、あなた | ||
545 | は人の名前で性別を想像できないからです。ある男性が アンドレアという名 | ||
546 | 前で、女性の名前は パット かもしれません (訳注 Andrea は米国では女性、 | ||
547 | それ以外(欧州など)では男性名として使われることが多い。同様に、Pat は | ||
548 | Patricia (主に女性名)や Patrick (主に男性名)の略称)。 | ||
549 | Linux カーネルの活動をして、意見を表明したことがある大部分の女性は、前 | ||
550 | 向きな経験をもっています。 | ||
551 | |||
552 | 言葉の壁は英語が得意でない一部の人には問題になります。 | ||
553 | メーリングリストの中できちんとアイディアを交換するには、相当うまく英語 | ||
554 | を操れる必要があることもあります。そのため、あなたは自分のメール | ||
555 | を送る前に英語で意味が通じているかをチェックすることをお薦めします。 | ||
556 | |||
557 | 変更を分割する | ||
558 | --------------------- | ||
559 | |||
560 | Linux カーネルコミュニティは、一度に大量のコードの塊を喜んで受容するこ | ||
561 | とはありません。変更は正確に説明される必要があり、議論され、小さい、個 | ||
562 | 別の部分に分割する必要があります。これはこれまで多くの会社がやり慣れて | ||
563 | きたことと全く正反対のことです。あなたのプロポーザルは、開発プロセスのと | ||
564 | ても早い段階から紹介されるべきです。そうすれば あなたは自分のやってい | ||
565 | ることにフィードバックを得られます。これは、コミュニティからみれば、あ | ||
566 | なたが彼らと一緒にやっているように感じられ、単にあなたの提案する機能の | ||
567 | ゴミ捨て場として使っているのではない、と感じられるでしょう。 | ||
568 | しかし、一度に 50 もの email をメーリングリストに送りつけるようなことは | ||
569 | やってはいけません、あなたのパッチ群はいつもどんな時でもそれよりは小さ | ||
570 | くなければなりません。 | ||
571 | |||
572 | パッチを分割する理由は以下です- | ||
573 | |||
574 | 1) 小さいパッチはあなたのパッチが適用される見込みを大きくします、カー | ||
575 | ネルの人達はパッチが正しいかどうかを確認する時間や労力をかけないか | ||
576 | らです。5行のパッチはメンテナがたった1秒見るだけで適用できます。し | ||
577 | かし、500行のパッチは、正しいことをレビューするのに数時間かかるかも | ||
578 | しれません(時間はパッチのサイズなどにより指数関数に比例してかかりま | ||
579 | す) | ||
580 | 小さいパッチは何かあったときにデバッグもとても簡単になります。パッ | ||
581 | チを1個1個取り除くのは、とても大きなパッチを当てた後に(かつ、何かお | ||
582 | かしくなった後で)解剖するのに比べればとても簡単です。 | ||
583 | |||
584 | 2) 小さいパッチを送るだけでなく、送るまえに、書き直して、シンプルにす | ||
585 | る(もしくは、単に順番を変えるだけでも)ことも、とても重要です。 | ||
586 | |||
587 | 以下はカーネル開発者の Al Viro のたとえ話しです: | ||
588 | |||
589 | "生徒の数学の宿題を採点する先生のことを考えてみてください、先 | ||
590 | 生は生徒が解に到達するまでの試行錯誤をみたいとは思わないでしょ | ||
591 | う。先生は簡潔な最高の解をみたいのです。良い生徒はこれを知って | ||
592 | おり、そして最終解の前の中間作業を提出することは決してないので | ||
593 | す" | ||
594 | カーネル開発でもこれは同じです。メンテナー達とレビューア達は、 | ||
595 | 問題を解決する解の背後になる思考プロセスをみたいとは思いません。 | ||
596 | 彼らは単純であざやかな解決方法をみたいのです。 | ||
597 | |||
598 | あざやかな解を説明するのと、コミュニティと共に仕事をし、未解決の仕事を | ||
599 | 議論することのバランスをキープするのは難しいかもしれません。 | ||
600 | ですから、開発プロセスの早期段階で改善のためのフィードバックをもらうよ | ||
601 | うにするのもいいですが、変更点を小さい部分に分割して全体ではまだ完成し | ||
602 | ていない仕事を(部分的に)取り込んでもらえるようにすることもいいことです。 | ||
603 | |||
604 | また、でき上がっていないものや、"将来直す" ようなパッチを、本流に含め | ||
605 | てもらうように送っても、それは受け付けられないことを理解してください。 | ||
606 | |||
607 | あなたの変更を正当化する | ||
608 | ------------------- | ||
609 | |||
610 | あなたのパッチを分割するのと同時に、なぜその変更を追加しなければならな | ||
611 | いかを Linux コミュニティに知らせることはとても重要です。新機能は必要 | ||
612 | 性と有用性で正当化されなければなりません。 | ||
613 | |||
614 | あなたの変更の説明 | ||
615 | -------------------- | ||
616 | |||
617 | あなたのパッチを送付する場合には、メールの中のテキストで何を言うかにつ | ||
618 | いて、特別に注意を払ってください。この情報はパッチの ChangeLog に使わ | ||
619 | れ、いつも皆がみられるように保管されます。これは次のような項目を含め、 | ||
620 | パッチを完全に記述するべきです- | ||
621 | |||
622 | - なぜ変更が必要か | ||
623 | - パッチ全体の設計アプローチ | ||
624 | - 実装の詳細 | ||
625 | - テスト結果 | ||
626 | |||
627 | これについて全てがどのようにあるべきかについての詳細は、以下のドキュメ | ||
628 | ントの ChangeLog セクションをみてください- | ||
629 | "The Perfect Patch" | ||
630 | http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt | ||
631 | |||
632 | これらのどれもが、時にはとても困難です。これらの慣例を完璧に実施するに | ||
633 | は数年かかるかもしれません。これは継続的な改善のプロセスであり、そのた | ||
634 | めには多数の忍耐と決意を必要とするものです。でも、諦めないで、これは可 | ||
635 | 能なことです。多数の人がすでにできていますし、彼らも皆最初はあなたと同 | ||
636 | じところからスタートしたのですから。 | ||
637 | |||
638 | Paolo Ciarrocchi に感謝、彼は彼の書いた "Development Process" | ||
639 | (http://linux.tar.bz/articles/2.6-development_process)セクショ | ||
640 | ンをこのテキストの原型にすることを許可してくれました。 | ||
641 | Rundy Dunlap と Gerrit Huizenga はメーリングリストでやるべきこととやっ | ||
642 | てはいけないことのリストを提供してくれました。 | ||
643 | 以下の人々のレビュー、コメント、貢献に感謝。 | ||
644 | Pat Mochel, Hanna Linder, Randy Dunlap, Kay Sievers, | ||
645 | Vojtech Pavlik, Jan Kara, Josh Boyer, Kees Cook, Andrew Morton, Andi | ||
646 | Kleen, Vadim Lobanov, Jesper Juhl, Adrian Bunk, Keri Harris, Frans Pop, | ||
647 | David A. Wheeler, Junio Hamano, Michael Kerrisk, と Alex Shepard | ||
648 | 彼らの支援なしでは、このドキュメントはできなかったでしょう。 | ||
649 | |||
650 | Maintainer: Greg Kroah-Hartman <greg@kroah.com> | ||
diff --git a/Documentation/ja_JP/stable_api_nonsense.txt b/Documentation/ja_JP/stable_api_nonsense.txt new file mode 100644 index 000000000000..b3f2b27f0881 --- /dev/null +++ b/Documentation/ja_JP/stable_api_nonsense.txt | |||
@@ -0,0 +1,263 @@ | |||
1 | NOTE: | ||
2 | This is a Japanese translated version of | ||
3 | "Documentation/stable_api_nonsense.txt". | ||
4 | This one is maintained by | ||
5 | IKEDA, Munehiro <m-ikeda@ds.jp.nec.com> | ||
6 | and JF Project team <http://www.linux.or.jp/JF/>. | ||
7 | If you find difference with original file or problem in translation, | ||
8 | please contact the maintainer of this file or JF project. | ||
9 | |||
10 | Please also note that purpose of this file is easier to read for non | ||
11 | English natives and not to be intended to fork. So, if you have any | ||
12 | comments or updates of this file, please try to update | ||
13 | Original(English) file at first. | ||
14 | |||
15 | ================================== | ||
16 | これは、 | ||
17 | linux-2.6.22-rc4/Documentation/stable_api_nonsense.txt の和訳 | ||
18 | です。 | ||
19 | 翻訳団体: JF プロジェクト < http://www.linux.or.jp/JF/ > | ||
20 | 翻訳日 : 2007/06/11 | ||
21 | 原著作者: Greg Kroah-Hartman < greg at kroah dot com > | ||
22 | 翻訳者 : 池田 宗広 < m-ikeda at ds dot jp dot nec dot com > | ||
23 | 校正者 : Masanori Kobayashi さん < zap03216 at nifty dot ne dot jp > | ||
24 | Seiji Kaneko さん < skaneko at a2 dot mbn dot or dot jp > | ||
25 | ================================== | ||
26 | |||
27 | |||
28 | |||
29 | Linux カーネルのドライバインターフェース | ||
30 | (あなたの質問すべてに対する回答とその他諸々) | ||
31 | |||
32 | Greg Kroah-Hartman <greg at kroah dot com> | ||
33 | |||
34 | |||
35 | この文書は、なぜ Linux ではバイナリカーネルインターフェースが定義 | ||
36 | されていないのか、またはなぜ不変のカーネルインターフェースを持たな | ||
37 | いのか、ということを説明するために書かれた。ここでの話題は「カーネ | ||
38 | ル内部の」インターフェースについてであり、ユーザー空間とのインター | ||
39 | フェースではないことを理解してほしい。カーネルとユーザー空間とのイ | ||
40 | ンターフェースとはアプリケーションプログラムが使用するものであり、 | ||
41 | つまりシステムコールのインターフェースがこれに当たる。これは今まで | ||
42 | 長きに渡り、かつ今後も「まさしく」不変である。私は確か 0.9 か何か | ||
43 | より前のカーネルを使ってビルドした古いプログラムを持っているが、そ | ||
44 | れは最新の 2.6 カーネルでもきちんと動作する。ユーザー空間とのイン | ||
45 | ターフェースは、ユーザーとアプリケーションプログラマが不変性を信頼 | ||
46 | してよいものの一つである。 | ||
47 | |||
48 | |||
49 | 要旨 | ||
50 | ---- | ||
51 | |||
52 | あなたは不変のカーネルインターフェースが必要だと考えているかもしれ | ||
53 | ないが、実際のところはそうではない。あなたは必要としているものが分 | ||
54 | かっていない。あなたが必要としているものは安定して動作するドライバ | ||
55 | であり、それはドライバがメインのカーネルツリーに含まれる場合のみ得 | ||
56 | ることができる。ドライバがメインのカーネルツリーに含まれていると、 | ||
57 | 他にも多くの良いことがある。それは、Linux をより強固で、安定な、成 | ||
58 | 熟したオペレーティングシステムにすることができるということだ。これ | ||
59 | こそ、そもそもあなたが Linux を使う理由のはずだ。 | ||
60 | |||
61 | |||
62 | はじめに | ||
63 | -------- | ||
64 | |||
65 | カーネル内部のインターフェース変更を心配しなければならないドライバ | ||
66 | を書きたいなどというのは、変わり者だけだ。この世界のほとんどの人は、 | ||
67 | そのようなドライバがどんなインターフェースを使っているかなど知らな | ||
68 | いし、そんなドライバのことなど全く気にもかけていない。 | ||
69 | |||
70 | |||
71 | まず初めに、クローズソースとか、ソースコードの隠蔽とか、バイナリの | ||
72 | みが配布される使い物にならない代物[訳注(1)]とか、実体はバイナリ | ||
73 | コードでそれを読み込むためのラッパー部分のみソースコードが公開され | ||
74 | ているとか、その他用語は何であれ GPL の下にソースコードがリリース | ||
75 | されていないカーネルドライバに関する法的な問題について、私は「いか | ||
76 | なる議論も」行うつもりがない。法的な疑問があるのならば、プログラマ | ||
77 | である私ではなく、弁護士に相談して欲しい。ここでは単に、技術的な問 | ||
78 | 題について述べることにする。(法的な問題を軽視しているわけではない。 | ||
79 | それらは実際に存在するし、あなたはそれをいつも気にかけておく必要が | ||
80 | ある) | ||
81 | |||
82 | 訳注(1) | ||
83 | 「使い物にならない代物」の原文は "blob" | ||
84 | |||
85 | |||
86 | さてここでは、バイナリカーネルインターフェースについてと、ソースレ | ||
87 | ベルでのインターフェースの不変性について、という二つの話題を取り上 | ||
88 | げる。この二つは互いに依存する関係にあるが、まずはバイナリインター | ||
89 | フェースについて議論を行いやっつけてしまおう。 | ||
90 | |||
91 | |||
92 | バイナリカーネルインターフェース | ||
93 | -------------------------------- | ||
94 | |||
95 | もしソースレベルでのインターフェースが不変ならば、バイナリインター | ||
96 | フェースも当然のように不変である、というのは正しいだろうか?正しく | ||
97 | ない。Linux カーネルに関する以下の事実を考えてみてほしい。 | ||
98 | - あなたが使用するCコンパイラのバージョンによって、カーネル内部 | ||
99 | の構造体の配置構造は異なったものになる。また、関数は異なった方 | ||
100 | 法でカーネルに含まれることになるかもしれない(例えばインライン | ||
101 | 関数として扱われたり、扱われなかったりする)。個々の関数がどの | ||
102 | ようにコンパイルされるかはそれほど重要ではないが、構造体のパデ | ||
103 | ィングが異なるというのは非常に重要である。 | ||
104 | - あなたがカーネルのビルドオプションをどのように設定するかによっ | ||
105 | て、カーネルには広い範囲で異なった事態が起こり得る。 | ||
106 | - データ構造は異なるデータフィールドを持つかもしれない | ||
107 | - いくつかの関数は全く実装されていない状態になり得る | ||
108 | (例:SMP向けではないビルドでは、いくつかのロックは中身が | ||
109 | カラにコンパイルされる) | ||
110 | - カーネル内のメモリは、異なった方法で配置され得る。これはビ | ||
111 | ルドオプションに依存している。 | ||
112 | - Linux は様々な異なるプロセッサアーキテクチャ上で動作する。 | ||
113 | あるアーキテクチャ用のバイナリドライバを、他のアーキテクチャで | ||
114 | 正常に動作させる方法はない。 | ||
115 | |||
116 | |||
117 | ある特定のカーネル設定を使用し、カーネルをビルドしたのと正確に同じ | ||
118 | Cコンパイラを使用して単にカーネルモジュールをコンパイルするだけで | ||
119 | も、あなたはこれらいくつもの問題に直面することになる。ある特定の | ||
120 | Linux ディストリビューションの、ある特定のリリースバージョン用にモ | ||
121 | ジュールを提供しようと思っただけでも、これらの問題を引き起こすには | ||
122 | 十分である。にも関わらず Linux ディストリビューションの数と、サ | ||
123 | ポートするディストリビューションのリリース数を掛け算し、それら一つ | ||
124 | 一つについてビルドを行ったとしたら、今度はリリースごとのビルドオプ | ||
125 | ションの違いという悪夢にすぐさま悩まされることになる。また、ディス | ||
126 | トリビューションの各リリースバージョンには、異なるハードウェア(プ | ||
127 | ロセッサタイプや種々のオプション)に対応するため、何種類かのカーネ | ||
128 | ルが含まれているということも理解して欲しい。従って、ある一つのリ | ||
129 | リースバージョンだけのためにモジュールを作成する場合でも、あなたは | ||
130 | 何バージョンものモジュールを用意しなければならない。 | ||
131 | |||
132 | |||
133 | 信じて欲しい。このような方法でサポートを続けようとするなら、あなた | ||
134 | はいずれ正気を失うだろう。遠い昔、私はそれがいかに困難なことか、身 | ||
135 | をもって学んだのだ・・・ | ||
136 | |||
137 | |||
138 | 不変のカーネルソースレベルインターフェース | ||
139 | ------------------------------------------ | ||
140 | |||
141 | メインカーネルツリーに含まれていない Linux カーネルドライバを継続 | ||
142 | してサポートしていこうとしている人たちとの議論においては、これは極 | ||
143 | めて「引火性の高い」話題である。[訳注(2)] | ||
144 | |||
145 | 訳注(2) | ||
146 | 「引火性の高い」の原文は "volatile"。 | ||
147 | volatile には「揮発性の」「爆発しやすい」という意味の他、「変わり | ||
148 | やすい」「移り気な」という意味がある。 | ||
149 | 「(この話題は)爆発的に激しい論争を巻き起こしかねない」ということ | ||
150 | を、「(カーネルのソースレベルインターフェースは)移ろい行くもので | ||
151 | ある」ということを連想させる "volatile" という単語で表現している。 | ||
152 | |||
153 | |||
154 | Linux カーネルの開発は継続的に速いペースで行われ、決して歩みを緩め | ||
155 | ることがない。その中でカーネル開発者達は、現状のインターフェースに | ||
156 | あるバグを見つけ、より良い方法を考え出す。彼らはやがて、現状のイン | ||
157 | ターフェースがより正しく動作するように修正を行う。その過程で関数の | ||
158 | 名前は変更されるかもしれず、構造体は大きく、または小さくなるかもし | ||
159 | れず、関数の引数は検討しなおされるかもしれない。そのような場合、引 | ||
160 | き続き全てが正常に動作するよう、カーネル内でこれらのインターフェー | ||
161 | スを使用している個所も全て同時に修正される。 | ||
162 | |||
163 | |||
164 | 具体的な例として、カーネル内の USB インターフェースを挙げる。USB | ||
165 | サブシステムはこれまでに少なくとも3回の書き直しが行われ、その結果 | ||
166 | インターフェースが変更された。これらの書き直しはいくつかの異なった | ||
167 | 問題を修正するために行われた。 | ||
168 | - 同期的データストリームが非同期に変更された。これにより多数のド | ||
169 | ライバを単純化でき、全てのドライバのスループットが向上した。今 | ||
170 | やほとんど全ての USB デバイスは、考えられる最高の速度で動作し | ||
171 | ている。 | ||
172 | - USB ドライバが USB サブシステムのコアから行う、データパケット | ||
173 | 用のメモリ確保方法が変更された。これに伴い、いくつもの文書化さ | ||
174 | れたデッドロック条件を回避するため、全ての USB ドライバはより | ||
175 | 多くの情報を USB コアに提供しなければならないようになっている。 | ||
176 | |||
177 | |||
178 | このできごとは、数多く存在するクローズソースのオペレーティングシス | ||
179 | テムとは全く対照的だ。それらは長期に渡り古い USB インターフェース | ||
180 | をメンテナンスしなければならない。古いインターフェースが残ることで、 | ||
181 | 新たな開発者が偶然古いインターフェースを使い、正しくない方法で開発 | ||
182 | を行ってしまう可能性が生じる。これによりシステムの安定性は危険にさ | ||
183 | らされることになる。 | ||
184 | |||
185 | |||
186 | 上に挙げたどちらの例においても、開発者達はその変更が重要かつ必要で | ||
187 | あることに合意し、比較的楽にそれを実行した。もし Linux がソースレ | ||
188 | ベルでインターフェースの不変性を保証しなければならないとしたら、新 | ||
189 | しいインターフェースを作ると同時に、古い、問題のある方を今後ともメ | ||
190 | ンテナンスするという余計な仕事を USB の開発者にさせなければならな | ||
191 | い。Linux の USB 開発者は、自分の時間を使って仕事をしている。よっ | ||
192 | て、価値のない余計な仕事を報酬もなしに実行しろと言うことはできない。 | ||
193 | |||
194 | |||
195 | セキュリティ問題も、Linux にとっては非常に重要である。ひとたびセキ | ||
196 | ュリティに関する問題が発見されれば、それは極めて短期間のうちに修正 | ||
197 | される。セキュリティ問題の発生を防ぐための修正は、カーネルの内部イ | ||
198 | ンターフェースの変更を何度も引き起こしてきた。その際同時に、変更さ | ||
199 | れたインターフェースを使用する全てのドライバもまた変更された。これ | ||
200 | により問題が解消し、将来偶然に問題が再発してしまわないことが保証さ | ||
201 | れる。もし内部インターフェースの変更が許されないとしたら、このよう | ||
202 | にセキュリティ問題を修正し、将来再発しないことを保証することなど不 | ||
203 | 可能なのだ。 | ||
204 | |||
205 | |||
206 | カーネルのインターフェースは時が経つにつれクリーンナップを受ける。 | ||
207 | 誰も使っていないインターフェースは削除される。これにより、可能な限 | ||
208 | りカーネルが小さく保たれ、現役の全てのインターフェースが可能な限り | ||
209 | テストされることを保証しているのだ。(使われていないインターフェー | ||
210 | スの妥当性をテストすることは不可能と言っていいだろう) | ||
211 | |||
212 | |||
213 | |||
214 | これから何をすべきか | ||
215 | ----------------------- | ||
216 | |||
217 | では、もしメインのカーネルツリーに含まれない Linux カーネルドライ | ||
218 | バがあったとして、あなたは、つまり開発者は何をするべきだろうか?全 | ||
219 | てのディストリビューションの全てのカーネルバージョン向けにバイナリ | ||
220 | のドライバを供給することは悪夢であり、カーネルインターフェースの変 | ||
221 | 更を追いかけ続けることもまた過酷な仕事だ。 | ||
222 | |||
223 | |||
224 | 答えは簡単。そのドライバをメインのカーネルツリーに入れてしまえばよ | ||
225 | い。(ここで言及しているのは、GPL に従って公開されるドライバのこと | ||
226 | だということに注意してほしい。あなたのコードがそれに該当しないなら | ||
227 | ば、さよなら。幸運を祈ります。ご自分で何とかしてください。Andrew | ||
228 | と Linus からのコメント<Andrew と Linus のコメントへのリンクをこ | ||
229 | こに置く>をどうぞ)ドライバがメインツリーに入れば、カーネルのイン | ||
230 | ターフェースが変更された場合、変更を行った開発者によってドライバも | ||
231 | 修正されることになるだろう。あなたはほとんど労力を払うことなしに、 | ||
232 | 常にビルド可能できちんと動作するドライバを手に入れることができる。 | ||
233 | |||
234 | |||
235 | ドライバをメインのカーネルツリーに入れると、非常に好ましい以下の効 | ||
236 | 果がある。 | ||
237 | - ドライバの品質が向上する一方で、(元の開発者にとっての)メンテ | ||
238 | ナンスコストは下がる。 | ||
239 | - あなたのドライバに他の開発者が機能を追加してくれる。 | ||
240 | - 誰かがあなたのドライバにあるバグを見つけ、修正してくれる。 | ||
241 | - 誰かがあなたのドライバにある改善点を見つけてくれる。 | ||
242 | - 外部インターフェースが変更されドライバの更新が必要になった場合、 | ||
243 | 誰かがあなたの代わりに更新してくれる。 | ||
244 | - ドライバを入れてくれとディストロに頼まなくても、そのドライバは | ||
245 | 全ての Linux ディストリビューションに自動的に含まれてリリース | ||
246 | される。 | ||
247 | |||
248 | |||
249 | Linux では、他のどのオペレーティングシステムよりも数多くのデバイス | ||
250 | が「そのまま」使用できるようになった。また Linux は、どのオペレー | ||
251 | ティングシステムよりも数多くのプロセッサアーキテクチャ上でそれらの | ||
252 | デバイスを使用することができるようにもなった。このように、Linux の | ||
253 | 開発モデルは実証されており、今後も間違いなく正しい方向へと進んでい | ||
254 | くだろう。:) | ||
255 | |||
256 | |||
257 | |||
258 | ------ | ||
259 | |||
260 | この文書の初期の草稿に対し、Randy Dunlap, Andrew Morton, David | ||
261 | Brownell, Hanna Linder, Robert Love, Nishanth Aravamudan から査読 | ||
262 | と助言を頂きました。感謝申し上げます。 | ||
263 | |||
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index c48bc2e159ce..854744bde224 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt | |||
@@ -817,6 +817,32 @@ and is between 256 and 4096 characters. It is defined in the file | |||
817 | js= [HW,JOY] Analog joystick | 817 | js= [HW,JOY] Analog joystick |
818 | See Documentation/input/joystick.txt. | 818 | See Documentation/input/joystick.txt. |
819 | 819 | ||
820 | kernelcore=nn[KMG] [KNL,IA-32,IA-64,PPC,X86-64] This parameter | ||
821 | specifies the amount of memory usable by the kernel | ||
822 | for non-movable allocations. The requested amount is | ||
823 | spread evenly throughout all nodes in the system. The | ||
824 | remaining memory in each node is used for Movable | ||
825 | pages. In the event, a node is too small to have both | ||
826 | kernelcore and Movable pages, kernelcore pages will | ||
827 | take priority and other nodes will have a larger number | ||
828 | of kernelcore pages. The Movable zone is used for the | ||
829 | allocation of pages that may be reclaimed or moved | ||
830 | by the page migration subsystem. This means that | ||
831 | HugeTLB pages may not be allocated from this zone. | ||
832 | Note that allocations like PTEs-from-HighMem still | ||
833 | use the HighMem zone if it exists, and the Normal | ||
834 | zone if it does not. | ||
835 | |||
836 | movablecore=nn[KMG] [KNL,IA-32,IA-64,PPC,X86-64] This parameter | ||
837 | is similar to kernelcore except it specifies the | ||
838 | amount of memory used for migratable allocations. | ||
839 | If both kernelcore and movablecore is specified, | ||
840 | then kernelcore will be at *least* the specified | ||
841 | value but may be more. If movablecore on its own | ||
842 | is specified, the administrator must be careful | ||
843 | that the amount of memory usable for all allocations | ||
844 | is not too small. | ||
845 | |||
820 | keepinitrd [HW,ARM] | 846 | keepinitrd [HW,ARM] |
821 | 847 | ||
822 | kstack=N [IA-32,X86-64] Print N words from the kernel stack | 848 | kstack=N [IA-32,X86-64] Print N words from the kernel stack |
diff --git a/Documentation/kprobes.txt b/Documentation/kprobes.txt index da5404ab7569..cb12ae175aa2 100644 --- a/Documentation/kprobes.txt +++ b/Documentation/kprobes.txt | |||
@@ -247,12 +247,6 @@ control to Kprobes.) If the probed function is declared asmlinkage, | |||
247 | fastcall, or anything else that affects how args are passed, the | 247 | fastcall, or anything else that affects how args are passed, the |
248 | handler's declaration must match. | 248 | handler's declaration must match. |
249 | 249 | ||
250 | NOTE: A macro JPROBE_ENTRY is provided to handle architecture-specific | ||
251 | aliasing of jp->entry. In the interest of portability, it is advised | ||
252 | to use: | ||
253 | |||
254 | jp->entry = JPROBE_ENTRY(handler); | ||
255 | |||
256 | register_jprobe() returns 0 on success, or a negative errno otherwise. | 250 | register_jprobe() returns 0 on success, or a negative errno otherwise. |
257 | 251 | ||
258 | 4.3 register_kretprobe | 252 | 4.3 register_kretprobe |
@@ -518,7 +512,7 @@ long jdo_fork(unsigned long clone_flags, unsigned long stack_start, | |||
518 | } | 512 | } |
519 | 513 | ||
520 | static struct jprobe my_jprobe = { | 514 | static struct jprobe my_jprobe = { |
521 | .entry = JPROBE_ENTRY(jdo_fork) | 515 | .entry = jdo_fork |
522 | }; | 516 | }; |
523 | 517 | ||
524 | static int __init jprobe_init(void) | 518 | static int __init jprobe_init(void) |
diff --git a/Documentation/lguest/Makefile b/Documentation/lguest/Makefile new file mode 100644 index 000000000000..b9b9427376e9 --- /dev/null +++ b/Documentation/lguest/Makefile | |||
@@ -0,0 +1,27 @@ | |||
1 | # This creates the demonstration utility "lguest" which runs a Linux guest. | ||
2 | |||
3 | # For those people that have a separate object dir, look there for .config | ||
4 | KBUILD_OUTPUT := ../.. | ||
5 | ifdef O | ||
6 | ifeq ("$(origin O)", "command line") | ||
7 | KBUILD_OUTPUT := $(O) | ||
8 | endif | ||
9 | endif | ||
10 | # We rely on CONFIG_PAGE_OFFSET to know where to put lguest binary. | ||
11 | include $(KBUILD_OUTPUT)/.config | ||
12 | LGUEST_GUEST_TOP := ($(CONFIG_PAGE_OFFSET) - 0x08000000) | ||
13 | |||
14 | CFLAGS:=-Wall -Wmissing-declarations -Wmissing-prototypes -O3 \ | ||
15 | -static -DLGUEST_GUEST_TOP="$(LGUEST_GUEST_TOP)" -Wl,-T,lguest.lds | ||
16 | LDLIBS:=-lz | ||
17 | |||
18 | all: lguest.lds lguest | ||
19 | |||
20 | # The linker script on x86 is so complex the only way of creating one | ||
21 | # which will link our binary in the right place is to mangle the | ||
22 | # default one. | ||
23 | lguest.lds: | ||
24 | $(LD) --verbose | awk '/^==========/ { PRINT=1; next; } /SIZEOF_HEADERS/ { gsub(/0x[0-9A-F]*/, "$(LGUEST_GUEST_TOP)") } { if (PRINT) print $$0; }' > $@ | ||
25 | |||
26 | clean: | ||
27 | rm -f lguest.lds lguest | ||
diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c new file mode 100644 index 000000000000..1432b502a2d9 --- /dev/null +++ b/Documentation/lguest/lguest.c | |||
@@ -0,0 +1,1012 @@ | |||
1 | /* Simple program to layout "physical" memory for new lguest guest. | ||
2 | * Linked high to avoid likely physical memory. */ | ||
3 | #define _LARGEFILE64_SOURCE | ||
4 | #define _GNU_SOURCE | ||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | #include <unistd.h> | ||
8 | #include <err.h> | ||
9 | #include <stdint.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <elf.h> | ||
12 | #include <sys/mman.h> | ||
13 | #include <sys/types.h> | ||
14 | #include <sys/stat.h> | ||
15 | #include <sys/wait.h> | ||
16 | #include <fcntl.h> | ||
17 | #include <stdbool.h> | ||
18 | #include <errno.h> | ||
19 | #include <ctype.h> | ||
20 | #include <sys/socket.h> | ||
21 | #include <sys/ioctl.h> | ||
22 | #include <sys/time.h> | ||
23 | #include <time.h> | ||
24 | #include <netinet/in.h> | ||
25 | #include <net/if.h> | ||
26 | #include <linux/sockios.h> | ||
27 | #include <linux/if_tun.h> | ||
28 | #include <sys/uio.h> | ||
29 | #include <termios.h> | ||
30 | #include <getopt.h> | ||
31 | #include <zlib.h> | ||
32 | typedef unsigned long long u64; | ||
33 | typedef uint32_t u32; | ||
34 | typedef uint16_t u16; | ||
35 | typedef uint8_t u8; | ||
36 | #include "../../include/linux/lguest_launcher.h" | ||
37 | #include "../../include/asm-i386/e820.h" | ||
38 | |||
39 | #define PAGE_PRESENT 0x7 /* Present, RW, Execute */ | ||
40 | #define NET_PEERNUM 1 | ||
41 | #define BRIDGE_PFX "bridge:" | ||
42 | #ifndef SIOCBRADDIF | ||
43 | #define SIOCBRADDIF 0x89a2 /* add interface to bridge */ | ||
44 | #endif | ||
45 | |||
46 | static bool verbose; | ||
47 | #define verbose(args...) \ | ||
48 | do { if (verbose) printf(args); } while(0) | ||
49 | static int waker_fd; | ||
50 | |||
51 | struct device_list | ||
52 | { | ||
53 | fd_set infds; | ||
54 | int max_infd; | ||
55 | |||
56 | struct device *dev; | ||
57 | struct device **lastdev; | ||
58 | }; | ||
59 | |||
60 | struct device | ||
61 | { | ||
62 | struct device *next; | ||
63 | struct lguest_device_desc *desc; | ||
64 | void *mem; | ||
65 | |||
66 | /* Watch this fd if handle_input non-NULL. */ | ||
67 | int fd; | ||
68 | bool (*handle_input)(int fd, struct device *me); | ||
69 | |||
70 | /* Watch DMA to this key if handle_input non-NULL. */ | ||
71 | unsigned long watch_key; | ||
72 | u32 (*handle_output)(int fd, const struct iovec *iov, | ||
73 | unsigned int num, struct device *me); | ||
74 | |||
75 | /* Device-specific data. */ | ||
76 | void *priv; | ||
77 | }; | ||
78 | |||
79 | static int open_or_die(const char *name, int flags) | ||
80 | { | ||
81 | int fd = open(name, flags); | ||
82 | if (fd < 0) | ||
83 | err(1, "Failed to open %s", name); | ||
84 | return fd; | ||
85 | } | ||
86 | |||
87 | static void *map_zeroed_pages(unsigned long addr, unsigned int num) | ||
88 | { | ||
89 | static int fd = -1; | ||
90 | |||
91 | if (fd == -1) | ||
92 | fd = open_or_die("/dev/zero", O_RDONLY); | ||
93 | |||
94 | if (mmap((void *)addr, getpagesize() * num, | ||
95 | PROT_READ|PROT_WRITE|PROT_EXEC, MAP_FIXED|MAP_PRIVATE, fd, 0) | ||
96 | != (void *)addr) | ||
97 | err(1, "Mmaping %u pages of /dev/zero @%p", num, (void *)addr); | ||
98 | return (void *)addr; | ||
99 | } | ||
100 | |||
101 | /* Find magic string marking entry point, return entry point. */ | ||
102 | static unsigned long entry_point(void *start, void *end, | ||
103 | unsigned long page_offset) | ||
104 | { | ||
105 | void *p; | ||
106 | |||
107 | for (p = start; p < end; p++) | ||
108 | if (memcmp(p, "GenuineLguest", strlen("GenuineLguest")) == 0) | ||
109 | return (long)p + strlen("GenuineLguest") + page_offset; | ||
110 | |||
111 | err(1, "Is this image a genuine lguest?"); | ||
112 | } | ||
113 | |||
114 | /* Returns the entry point */ | ||
115 | static unsigned long map_elf(int elf_fd, const Elf32_Ehdr *ehdr, | ||
116 | unsigned long *page_offset) | ||
117 | { | ||
118 | void *addr; | ||
119 | Elf32_Phdr phdr[ehdr->e_phnum]; | ||
120 | unsigned int i; | ||
121 | unsigned long start = -1UL, end = 0; | ||
122 | |||
123 | /* Sanity checks. */ | ||
124 | if (ehdr->e_type != ET_EXEC | ||
125 | || ehdr->e_machine != EM_386 | ||
126 | || ehdr->e_phentsize != sizeof(Elf32_Phdr) | ||
127 | || ehdr->e_phnum < 1 || ehdr->e_phnum > 65536U/sizeof(Elf32_Phdr)) | ||
128 | errx(1, "Malformed elf header"); | ||
129 | |||
130 | if (lseek(elf_fd, ehdr->e_phoff, SEEK_SET) < 0) | ||
131 | err(1, "Seeking to program headers"); | ||
132 | if (read(elf_fd, phdr, sizeof(phdr)) != sizeof(phdr)) | ||
133 | err(1, "Reading program headers"); | ||
134 | |||
135 | *page_offset = 0; | ||
136 | /* We map the loadable segments at virtual addresses corresponding | ||
137 | * to their physical addresses (our virtual == guest physical). */ | ||
138 | for (i = 0; i < ehdr->e_phnum; i++) { | ||
139 | if (phdr[i].p_type != PT_LOAD) | ||
140 | continue; | ||
141 | |||
142 | verbose("Section %i: size %i addr %p\n", | ||
143 | i, phdr[i].p_memsz, (void *)phdr[i].p_paddr); | ||
144 | |||
145 | /* We expect linear address space. */ | ||
146 | if (!*page_offset) | ||
147 | *page_offset = phdr[i].p_vaddr - phdr[i].p_paddr; | ||
148 | else if (*page_offset != phdr[i].p_vaddr - phdr[i].p_paddr) | ||
149 | errx(1, "Page offset of section %i different", i); | ||
150 | |||
151 | if (phdr[i].p_paddr < start) | ||
152 | start = phdr[i].p_paddr; | ||
153 | if (phdr[i].p_paddr + phdr[i].p_filesz > end) | ||
154 | end = phdr[i].p_paddr + phdr[i].p_filesz; | ||
155 | |||
156 | /* We map everything private, writable. */ | ||
157 | addr = mmap((void *)phdr[i].p_paddr, | ||
158 | phdr[i].p_filesz, | ||
159 | PROT_READ|PROT_WRITE|PROT_EXEC, | ||
160 | MAP_FIXED|MAP_PRIVATE, | ||
161 | elf_fd, phdr[i].p_offset); | ||
162 | if (addr != (void *)phdr[i].p_paddr) | ||
163 | err(1, "Mmaping vmlinux seg %i gave %p not %p", | ||
164 | i, addr, (void *)phdr[i].p_paddr); | ||
165 | } | ||
166 | |||
167 | return entry_point((void *)start, (void *)end, *page_offset); | ||
168 | } | ||
169 | |||
170 | /* This is amazingly reliable. */ | ||
171 | static unsigned long intuit_page_offset(unsigned char *img, unsigned long len) | ||
172 | { | ||
173 | unsigned int i, possibilities[256] = { 0 }; | ||
174 | |||
175 | for (i = 0; i + 4 < len; i++) { | ||
176 | /* mov 0xXXXXXXXX,%eax */ | ||
177 | if (img[i] == 0xA1 && ++possibilities[img[i+4]] > 3) | ||
178 | return (unsigned long)img[i+4] << 24; | ||
179 | } | ||
180 | errx(1, "could not determine page offset"); | ||
181 | } | ||
182 | |||
183 | static unsigned long unpack_bzimage(int fd, unsigned long *page_offset) | ||
184 | { | ||
185 | gzFile f; | ||
186 | int ret, len = 0; | ||
187 | void *img = (void *)0x100000; | ||
188 | |||
189 | f = gzdopen(fd, "rb"); | ||
190 | while ((ret = gzread(f, img + len, 65536)) > 0) | ||
191 | len += ret; | ||
192 | if (ret < 0) | ||
193 | err(1, "reading image from bzImage"); | ||
194 | |||
195 | verbose("Unpacked size %i addr %p\n", len, img); | ||
196 | *page_offset = intuit_page_offset(img, len); | ||
197 | |||
198 | return entry_point(img, img + len, *page_offset); | ||
199 | } | ||
200 | |||
201 | static unsigned long load_bzimage(int fd, unsigned long *page_offset) | ||
202 | { | ||
203 | unsigned char c; | ||
204 | int state = 0; | ||
205 | |||
206 | /* Ugly brute force search for gzip header. */ | ||
207 | while (read(fd, &c, 1) == 1) { | ||
208 | switch (state) { | ||
209 | case 0: | ||
210 | if (c == 0x1F) | ||
211 | state++; | ||
212 | break; | ||
213 | case 1: | ||
214 | if (c == 0x8B) | ||
215 | state++; | ||
216 | else | ||
217 | state = 0; | ||
218 | break; | ||
219 | case 2 ... 8: | ||
220 | state++; | ||
221 | break; | ||
222 | case 9: | ||
223 | lseek(fd, -10, SEEK_CUR); | ||
224 | if (c != 0x03) /* Compressed under UNIX. */ | ||
225 | state = -1; | ||
226 | else | ||
227 | return unpack_bzimage(fd, page_offset); | ||
228 | } | ||
229 | } | ||
230 | errx(1, "Could not find kernel in bzImage"); | ||
231 | } | ||
232 | |||
233 | static unsigned long load_kernel(int fd, unsigned long *page_offset) | ||
234 | { | ||
235 | Elf32_Ehdr hdr; | ||
236 | |||
237 | if (read(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) | ||
238 | err(1, "Reading kernel"); | ||
239 | |||
240 | if (memcmp(hdr.e_ident, ELFMAG, SELFMAG) == 0) | ||
241 | return map_elf(fd, &hdr, page_offset); | ||
242 | |||
243 | return load_bzimage(fd, page_offset); | ||
244 | } | ||
245 | |||
246 | static inline unsigned long page_align(unsigned long addr) | ||
247 | { | ||
248 | return ((addr + getpagesize()-1) & ~(getpagesize()-1)); | ||
249 | } | ||
250 | |||
251 | /* initrd gets loaded at top of memory: return length. */ | ||
252 | static unsigned long load_initrd(const char *name, unsigned long mem) | ||
253 | { | ||
254 | int ifd; | ||
255 | struct stat st; | ||
256 | unsigned long len; | ||
257 | void *iaddr; | ||
258 | |||
259 | ifd = open_or_die(name, O_RDONLY); | ||
260 | if (fstat(ifd, &st) < 0) | ||
261 | err(1, "fstat() on initrd '%s'", name); | ||
262 | |||
263 | len = page_align(st.st_size); | ||
264 | iaddr = mmap((void *)mem - len, st.st_size, | ||
265 | PROT_READ|PROT_EXEC|PROT_WRITE, | ||
266 | MAP_FIXED|MAP_PRIVATE, ifd, 0); | ||
267 | if (iaddr != (void *)mem - len) | ||
268 | err(1, "Mmaping initrd '%s' returned %p not %p", | ||
269 | name, iaddr, (void *)mem - len); | ||
270 | close(ifd); | ||
271 | verbose("mapped initrd %s size=%lu @ %p\n", name, st.st_size, iaddr); | ||
272 | return len; | ||
273 | } | ||
274 | |||
275 | static unsigned long setup_pagetables(unsigned long mem, | ||
276 | unsigned long initrd_size, | ||
277 | unsigned long page_offset) | ||
278 | { | ||
279 | u32 *pgdir, *linear; | ||
280 | unsigned int mapped_pages, i, linear_pages; | ||
281 | unsigned int ptes_per_page = getpagesize()/sizeof(u32); | ||
282 | |||
283 | /* If we can map all of memory above page_offset, we do so. */ | ||
284 | if (mem <= -page_offset) | ||
285 | mapped_pages = mem/getpagesize(); | ||
286 | else | ||
287 | mapped_pages = -page_offset/getpagesize(); | ||
288 | |||
289 | /* Each linear PTE page can map ptes_per_page pages. */ | ||
290 | linear_pages = (mapped_pages + ptes_per_page-1)/ptes_per_page; | ||
291 | |||
292 | /* We lay out top-level then linear mapping immediately below initrd */ | ||
293 | pgdir = (void *)mem - initrd_size - getpagesize(); | ||
294 | linear = (void *)pgdir - linear_pages*getpagesize(); | ||
295 | |||
296 | for (i = 0; i < mapped_pages; i++) | ||
297 | linear[i] = ((i * getpagesize()) | PAGE_PRESENT); | ||
298 | |||
299 | /* Now set up pgd so that this memory is at page_offset */ | ||
300 | for (i = 0; i < mapped_pages; i += ptes_per_page) { | ||
301 | pgdir[(i + page_offset/getpagesize())/ptes_per_page] | ||
302 | = (((u32)linear + i*sizeof(u32)) | PAGE_PRESENT); | ||
303 | } | ||
304 | |||
305 | verbose("Linear mapping of %u pages in %u pte pages at %p\n", | ||
306 | mapped_pages, linear_pages, linear); | ||
307 | |||
308 | return (unsigned long)pgdir; | ||
309 | } | ||
310 | |||
311 | static void concat(char *dst, char *args[]) | ||
312 | { | ||
313 | unsigned int i, len = 0; | ||
314 | |||
315 | for (i = 0; args[i]; i++) { | ||
316 | strcpy(dst+len, args[i]); | ||
317 | strcat(dst+len, " "); | ||
318 | len += strlen(args[i]) + 1; | ||
319 | } | ||
320 | /* In case it's empty. */ | ||
321 | dst[len] = '\0'; | ||
322 | } | ||
323 | |||
324 | static int tell_kernel(u32 pgdir, u32 start, u32 page_offset) | ||
325 | { | ||
326 | u32 args[] = { LHREQ_INITIALIZE, | ||
327 | LGUEST_GUEST_TOP/getpagesize(), /* Just below us */ | ||
328 | pgdir, start, page_offset }; | ||
329 | int fd; | ||
330 | |||
331 | fd = open_or_die("/dev/lguest", O_RDWR); | ||
332 | if (write(fd, args, sizeof(args)) < 0) | ||
333 | err(1, "Writing to /dev/lguest"); | ||
334 | return fd; | ||
335 | } | ||
336 | |||
337 | static void set_fd(int fd, struct device_list *devices) | ||
338 | { | ||
339 | FD_SET(fd, &devices->infds); | ||
340 | if (fd > devices->max_infd) | ||
341 | devices->max_infd = fd; | ||
342 | } | ||
343 | |||
344 | /* When input arrives, we tell the kernel to kick lguest out with -EAGAIN. */ | ||
345 | static void wake_parent(int pipefd, int lguest_fd, struct device_list *devices) | ||
346 | { | ||
347 | set_fd(pipefd, devices); | ||
348 | |||
349 | for (;;) { | ||
350 | fd_set rfds = devices->infds; | ||
351 | u32 args[] = { LHREQ_BREAK, 1 }; | ||
352 | |||
353 | select(devices->max_infd+1, &rfds, NULL, NULL, NULL); | ||
354 | if (FD_ISSET(pipefd, &rfds)) { | ||
355 | int ignorefd; | ||
356 | if (read(pipefd, &ignorefd, sizeof(ignorefd)) == 0) | ||
357 | exit(0); | ||
358 | FD_CLR(ignorefd, &devices->infds); | ||
359 | } else | ||
360 | write(lguest_fd, args, sizeof(args)); | ||
361 | } | ||
362 | } | ||
363 | |||
364 | static int setup_waker(int lguest_fd, struct device_list *device_list) | ||
365 | { | ||
366 | int pipefd[2], child; | ||
367 | |||
368 | pipe(pipefd); | ||
369 | child = fork(); | ||
370 | if (child == -1) | ||
371 | err(1, "forking"); | ||
372 | |||
373 | if (child == 0) { | ||
374 | close(pipefd[1]); | ||
375 | wake_parent(pipefd[0], lguest_fd, device_list); | ||
376 | } | ||
377 | close(pipefd[0]); | ||
378 | |||
379 | return pipefd[1]; | ||
380 | } | ||
381 | |||
382 | static void *_check_pointer(unsigned long addr, unsigned int size, | ||
383 | unsigned int line) | ||
384 | { | ||
385 | if (addr >= LGUEST_GUEST_TOP || addr + size >= LGUEST_GUEST_TOP) | ||
386 | errx(1, "%s:%i: Invalid address %li", __FILE__, line, addr); | ||
387 | return (void *)addr; | ||
388 | } | ||
389 | #define check_pointer(addr,size) _check_pointer(addr, size, __LINE__) | ||
390 | |||
391 | /* Returns pointer to dma->used_len */ | ||
392 | static u32 *dma2iov(unsigned long dma, struct iovec iov[], unsigned *num) | ||
393 | { | ||
394 | unsigned int i; | ||
395 | struct lguest_dma *udma; | ||
396 | |||
397 | udma = check_pointer(dma, sizeof(*udma)); | ||
398 | for (i = 0; i < LGUEST_MAX_DMA_SECTIONS; i++) { | ||
399 | if (!udma->len[i]) | ||
400 | break; | ||
401 | |||
402 | iov[i].iov_base = check_pointer(udma->addr[i], udma->len[i]); | ||
403 | iov[i].iov_len = udma->len[i]; | ||
404 | } | ||
405 | *num = i; | ||
406 | return &udma->used_len; | ||
407 | } | ||
408 | |||
409 | static u32 *get_dma_buffer(int fd, void *key, | ||
410 | struct iovec iov[], unsigned int *num, u32 *irq) | ||
411 | { | ||
412 | u32 buf[] = { LHREQ_GETDMA, (u32)key }; | ||
413 | unsigned long udma; | ||
414 | u32 *res; | ||
415 | |||
416 | udma = write(fd, buf, sizeof(buf)); | ||
417 | if (udma == (unsigned long)-1) | ||
418 | return NULL; | ||
419 | |||
420 | /* Kernel stashes irq in ->used_len. */ | ||
421 | res = dma2iov(udma, iov, num); | ||
422 | *irq = *res; | ||
423 | return res; | ||
424 | } | ||
425 | |||
426 | static void trigger_irq(int fd, u32 irq) | ||
427 | { | ||
428 | u32 buf[] = { LHREQ_IRQ, irq }; | ||
429 | if (write(fd, buf, sizeof(buf)) != 0) | ||
430 | err(1, "Triggering irq %i", irq); | ||
431 | } | ||
432 | |||
433 | static void discard_iovec(struct iovec *iov, unsigned int *num) | ||
434 | { | ||
435 | static char discard_buf[1024]; | ||
436 | *num = 1; | ||
437 | iov->iov_base = discard_buf; | ||
438 | iov->iov_len = sizeof(discard_buf); | ||
439 | } | ||
440 | |||
441 | static struct termios orig_term; | ||
442 | static void restore_term(void) | ||
443 | { | ||
444 | tcsetattr(STDIN_FILENO, TCSANOW, &orig_term); | ||
445 | } | ||
446 | |||
447 | struct console_abort | ||
448 | { | ||
449 | int count; | ||
450 | struct timeval start; | ||
451 | }; | ||
452 | |||
453 | /* We DMA input to buffer bound at start of console page. */ | ||
454 | static bool handle_console_input(int fd, struct device *dev) | ||
455 | { | ||
456 | u32 irq = 0, *lenp; | ||
457 | int len; | ||
458 | unsigned int num; | ||
459 | struct iovec iov[LGUEST_MAX_DMA_SECTIONS]; | ||
460 | struct console_abort *abort = dev->priv; | ||
461 | |||
462 | lenp = get_dma_buffer(fd, dev->mem, iov, &num, &irq); | ||
463 | if (!lenp) { | ||
464 | warn("console: no dma buffer!"); | ||
465 | discard_iovec(iov, &num); | ||
466 | } | ||
467 | |||
468 | len = readv(dev->fd, iov, num); | ||
469 | if (len <= 0) { | ||
470 | warnx("Failed to get console input, ignoring console."); | ||
471 | len = 0; | ||
472 | } | ||
473 | |||
474 | if (lenp) { | ||
475 | *lenp = len; | ||
476 | trigger_irq(fd, irq); | ||
477 | } | ||
478 | |||
479 | /* Three ^C within one second? Exit. */ | ||
480 | if (len == 1 && ((char *)iov[0].iov_base)[0] == 3) { | ||
481 | if (!abort->count++) | ||
482 | gettimeofday(&abort->start, NULL); | ||
483 | else if (abort->count == 3) { | ||
484 | struct timeval now; | ||
485 | gettimeofday(&now, NULL); | ||
486 | if (now.tv_sec <= abort->start.tv_sec+1) { | ||
487 | /* Make sure waker is not blocked in BREAK */ | ||
488 | u32 args[] = { LHREQ_BREAK, 0 }; | ||
489 | close(waker_fd); | ||
490 | write(fd, args, sizeof(args)); | ||
491 | exit(2); | ||
492 | } | ||
493 | abort->count = 0; | ||
494 | } | ||
495 | } else | ||
496 | abort->count = 0; | ||
497 | |||
498 | if (!len) { | ||
499 | restore_term(); | ||
500 | return false; | ||
501 | } | ||
502 | return true; | ||
503 | } | ||
504 | |||
505 | static u32 handle_console_output(int fd, const struct iovec *iov, | ||
506 | unsigned num, struct device*dev) | ||
507 | { | ||
508 | return writev(STDOUT_FILENO, iov, num); | ||
509 | } | ||
510 | |||
511 | static u32 handle_tun_output(int fd, const struct iovec *iov, | ||
512 | unsigned num, struct device *dev) | ||
513 | { | ||
514 | /* Now we've seen output, we should warn if we can't get buffers. */ | ||
515 | *(bool *)dev->priv = true; | ||
516 | return writev(dev->fd, iov, num); | ||
517 | } | ||
518 | |||
519 | static unsigned long peer_offset(unsigned int peernum) | ||
520 | { | ||
521 | return 4 * peernum; | ||
522 | } | ||
523 | |||
524 | static bool handle_tun_input(int fd, struct device *dev) | ||
525 | { | ||
526 | u32 irq = 0, *lenp; | ||
527 | int len; | ||
528 | unsigned num; | ||
529 | struct iovec iov[LGUEST_MAX_DMA_SECTIONS]; | ||
530 | |||
531 | lenp = get_dma_buffer(fd, dev->mem+peer_offset(NET_PEERNUM), iov, &num, | ||
532 | &irq); | ||
533 | if (!lenp) { | ||
534 | if (*(bool *)dev->priv) | ||
535 | warn("network: no dma buffer!"); | ||
536 | discard_iovec(iov, &num); | ||
537 | } | ||
538 | |||
539 | len = readv(dev->fd, iov, num); | ||
540 | if (len <= 0) | ||
541 | err(1, "reading network"); | ||
542 | if (lenp) { | ||
543 | *lenp = len; | ||
544 | trigger_irq(fd, irq); | ||
545 | } | ||
546 | verbose("tun input packet len %i [%02x %02x] (%s)\n", len, | ||
547 | ((u8 *)iov[0].iov_base)[0], ((u8 *)iov[0].iov_base)[1], | ||
548 | lenp ? "sent" : "discarded"); | ||
549 | return true; | ||
550 | } | ||
551 | |||
552 | static u32 handle_block_output(int fd, const struct iovec *iov, | ||
553 | unsigned num, struct device *dev) | ||
554 | { | ||
555 | struct lguest_block_page *p = dev->mem; | ||
556 | u32 irq, *lenp; | ||
557 | unsigned int len, reply_num; | ||
558 | struct iovec reply[LGUEST_MAX_DMA_SECTIONS]; | ||
559 | off64_t device_len, off = (off64_t)p->sector * 512; | ||
560 | |||
561 | device_len = *(off64_t *)dev->priv; | ||
562 | |||
563 | if (off >= device_len) | ||
564 | err(1, "Bad offset %llu vs %llu", off, device_len); | ||
565 | if (lseek64(dev->fd, off, SEEK_SET) != off) | ||
566 | err(1, "Bad seek to sector %i", p->sector); | ||
567 | |||
568 | verbose("Block: %s at offset %llu\n", p->type ? "WRITE" : "READ", off); | ||
569 | |||
570 | lenp = get_dma_buffer(fd, dev->mem, reply, &reply_num, &irq); | ||
571 | if (!lenp) | ||
572 | err(1, "Block request didn't give us a dma buffer"); | ||
573 | |||
574 | if (p->type) { | ||
575 | len = writev(dev->fd, iov, num); | ||
576 | if (off + len > device_len) { | ||
577 | ftruncate(dev->fd, device_len); | ||
578 | errx(1, "Write past end %llu+%u", off, len); | ||
579 | } | ||
580 | *lenp = 0; | ||
581 | } else { | ||
582 | len = readv(dev->fd, reply, reply_num); | ||
583 | *lenp = len; | ||
584 | } | ||
585 | |||
586 | p->result = 1 + (p->bytes != len); | ||
587 | trigger_irq(fd, irq); | ||
588 | return 0; | ||
589 | } | ||
590 | |||
591 | static void handle_output(int fd, unsigned long dma, unsigned long key, | ||
592 | struct device_list *devices) | ||
593 | { | ||
594 | struct device *i; | ||
595 | u32 *lenp; | ||
596 | struct iovec iov[LGUEST_MAX_DMA_SECTIONS]; | ||
597 | unsigned num = 0; | ||
598 | |||
599 | lenp = dma2iov(dma, iov, &num); | ||
600 | for (i = devices->dev; i; i = i->next) { | ||
601 | if (i->handle_output && key == i->watch_key) { | ||
602 | *lenp = i->handle_output(fd, iov, num, i); | ||
603 | return; | ||
604 | } | ||
605 | } | ||
606 | warnx("Pending dma %p, key %p", (void *)dma, (void *)key); | ||
607 | } | ||
608 | |||
609 | static void handle_input(int fd, struct device_list *devices) | ||
610 | { | ||
611 | struct timeval poll = { .tv_sec = 0, .tv_usec = 0 }; | ||
612 | |||
613 | for (;;) { | ||
614 | struct device *i; | ||
615 | fd_set fds = devices->infds; | ||
616 | |||
617 | if (select(devices->max_infd+1, &fds, NULL, NULL, &poll) == 0) | ||
618 | break; | ||
619 | |||
620 | for (i = devices->dev; i; i = i->next) { | ||
621 | if (i->handle_input && FD_ISSET(i->fd, &fds)) { | ||
622 | if (!i->handle_input(fd, i)) { | ||
623 | FD_CLR(i->fd, &devices->infds); | ||
624 | /* Tell waker to ignore it too... */ | ||
625 | write(waker_fd, &i->fd, sizeof(i->fd)); | ||
626 | } | ||
627 | } | ||
628 | } | ||
629 | } | ||
630 | } | ||
631 | |||
632 | static struct lguest_device_desc *new_dev_desc(u16 type, u16 features, | ||
633 | u16 num_pages) | ||
634 | { | ||
635 | static unsigned long top = LGUEST_GUEST_TOP; | ||
636 | struct lguest_device_desc *desc; | ||
637 | |||
638 | desc = malloc(sizeof(*desc)); | ||
639 | desc->type = type; | ||
640 | desc->num_pages = num_pages; | ||
641 | desc->features = features; | ||
642 | desc->status = 0; | ||
643 | if (num_pages) { | ||
644 | top -= num_pages*getpagesize(); | ||
645 | map_zeroed_pages(top, num_pages); | ||
646 | desc->pfn = top / getpagesize(); | ||
647 | } else | ||
648 | desc->pfn = 0; | ||
649 | return desc; | ||
650 | } | ||
651 | |||
652 | static struct device *new_device(struct device_list *devices, | ||
653 | u16 type, u16 num_pages, u16 features, | ||
654 | int fd, | ||
655 | bool (*handle_input)(int, struct device *), | ||
656 | unsigned long watch_off, | ||
657 | u32 (*handle_output)(int, | ||
658 | const struct iovec *, | ||
659 | unsigned, | ||
660 | struct device *)) | ||
661 | { | ||
662 | struct device *dev = malloc(sizeof(*dev)); | ||
663 | |||
664 | /* Append to device list. */ | ||
665 | *devices->lastdev = dev; | ||
666 | dev->next = NULL; | ||
667 | devices->lastdev = &dev->next; | ||
668 | |||
669 | dev->fd = fd; | ||
670 | if (handle_input) | ||
671 | set_fd(dev->fd, devices); | ||
672 | dev->desc = new_dev_desc(type, features, num_pages); | ||
673 | dev->mem = (void *)(dev->desc->pfn * getpagesize()); | ||
674 | dev->handle_input = handle_input; | ||
675 | dev->watch_key = (unsigned long)dev->mem + watch_off; | ||
676 | dev->handle_output = handle_output; | ||
677 | return dev; | ||
678 | } | ||
679 | |||
680 | static void setup_console(struct device_list *devices) | ||
681 | { | ||
682 | struct device *dev; | ||
683 | |||
684 | if (tcgetattr(STDIN_FILENO, &orig_term) == 0) { | ||
685 | struct termios term = orig_term; | ||
686 | term.c_lflag &= ~(ISIG|ICANON|ECHO); | ||
687 | tcsetattr(STDIN_FILENO, TCSANOW, &term); | ||
688 | atexit(restore_term); | ||
689 | } | ||
690 | |||
691 | /* We don't currently require a page for the console. */ | ||
692 | dev = new_device(devices, LGUEST_DEVICE_T_CONSOLE, 0, 0, | ||
693 | STDIN_FILENO, handle_console_input, | ||
694 | LGUEST_CONSOLE_DMA_KEY, handle_console_output); | ||
695 | dev->priv = malloc(sizeof(struct console_abort)); | ||
696 | ((struct console_abort *)dev->priv)->count = 0; | ||
697 | verbose("device %p: console\n", | ||
698 | (void *)(dev->desc->pfn * getpagesize())); | ||
699 | } | ||
700 | |||
701 | static void setup_block_file(const char *filename, struct device_list *devices) | ||
702 | { | ||
703 | int fd; | ||
704 | struct device *dev; | ||
705 | off64_t *device_len; | ||
706 | struct lguest_block_page *p; | ||
707 | |||
708 | fd = open_or_die(filename, O_RDWR|O_LARGEFILE|O_DIRECT); | ||
709 | dev = new_device(devices, LGUEST_DEVICE_T_BLOCK, 1, | ||
710 | LGUEST_DEVICE_F_RANDOMNESS, | ||
711 | fd, NULL, 0, handle_block_output); | ||
712 | device_len = dev->priv = malloc(sizeof(*device_len)); | ||
713 | *device_len = lseek64(fd, 0, SEEK_END); | ||
714 | p = dev->mem; | ||
715 | |||
716 | p->num_sectors = *device_len/512; | ||
717 | verbose("device %p: block %i sectors\n", | ||
718 | (void *)(dev->desc->pfn * getpagesize()), p->num_sectors); | ||
719 | } | ||
720 | |||
721 | /* We use fnctl locks to reserve network slots (autocleanup!) */ | ||
722 | static unsigned int find_slot(int netfd, const char *filename) | ||
723 | { | ||
724 | struct flock fl; | ||
725 | |||
726 | fl.l_type = F_WRLCK; | ||
727 | fl.l_whence = SEEK_SET; | ||
728 | fl.l_len = 1; | ||
729 | for (fl.l_start = 0; | ||
730 | fl.l_start < getpagesize()/sizeof(struct lguest_net); | ||
731 | fl.l_start++) { | ||
732 | if (fcntl(netfd, F_SETLK, &fl) == 0) | ||
733 | return fl.l_start; | ||
734 | } | ||
735 | errx(1, "No free slots in network file %s", filename); | ||
736 | } | ||
737 | |||
738 | static void setup_net_file(const char *filename, | ||
739 | struct device_list *devices) | ||
740 | { | ||
741 | int netfd; | ||
742 | struct device *dev; | ||
743 | |||
744 | netfd = open(filename, O_RDWR, 0); | ||
745 | if (netfd < 0) { | ||
746 | if (errno == ENOENT) { | ||
747 | netfd = open(filename, O_RDWR|O_CREAT, 0600); | ||
748 | if (netfd >= 0) { | ||
749 | char page[getpagesize()]; | ||
750 | memset(page, 0, sizeof(page)); | ||
751 | write(netfd, page, sizeof(page)); | ||
752 | } | ||
753 | } | ||
754 | if (netfd < 0) | ||
755 | err(1, "cannot open net file '%s'", filename); | ||
756 | } | ||
757 | |||
758 | dev = new_device(devices, LGUEST_DEVICE_T_NET, 1, | ||
759 | find_slot(netfd, filename)|LGUEST_NET_F_NOCSUM, | ||
760 | -1, NULL, 0, NULL); | ||
761 | |||
762 | /* We overwrite the /dev/zero mapping with the actual file. */ | ||
763 | if (mmap(dev->mem, getpagesize(), PROT_READ|PROT_WRITE, | ||
764 | MAP_FIXED|MAP_SHARED, netfd, 0) != dev->mem) | ||
765 | err(1, "could not mmap '%s'", filename); | ||
766 | verbose("device %p: shared net %s, peer %i\n", | ||
767 | (void *)(dev->desc->pfn * getpagesize()), filename, | ||
768 | dev->desc->features & ~LGUEST_NET_F_NOCSUM); | ||
769 | } | ||
770 | |||
771 | static u32 str2ip(const char *ipaddr) | ||
772 | { | ||
773 | unsigned int byte[4]; | ||
774 | |||
775 | sscanf(ipaddr, "%u.%u.%u.%u", &byte[0], &byte[1], &byte[2], &byte[3]); | ||
776 | return (byte[0] << 24) | (byte[1] << 16) | (byte[2] << 8) | byte[3]; | ||
777 | } | ||
778 | |||
779 | /* adapted from libbridge */ | ||
780 | static void add_to_bridge(int fd, const char *if_name, const char *br_name) | ||
781 | { | ||
782 | int ifidx; | ||
783 | struct ifreq ifr; | ||
784 | |||
785 | if (!*br_name) | ||
786 | errx(1, "must specify bridge name"); | ||
787 | |||
788 | ifidx = if_nametoindex(if_name); | ||
789 | if (!ifidx) | ||
790 | errx(1, "interface %s does not exist!", if_name); | ||
791 | |||
792 | strncpy(ifr.ifr_name, br_name, IFNAMSIZ); | ||
793 | ifr.ifr_ifindex = ifidx; | ||
794 | if (ioctl(fd, SIOCBRADDIF, &ifr) < 0) | ||
795 | err(1, "can't add %s to bridge %s", if_name, br_name); | ||
796 | } | ||
797 | |||
798 | static void configure_device(int fd, const char *devname, u32 ipaddr, | ||
799 | unsigned char hwaddr[6]) | ||
800 | { | ||
801 | struct ifreq ifr; | ||
802 | struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr; | ||
803 | |||
804 | memset(&ifr, 0, sizeof(ifr)); | ||
805 | strcpy(ifr.ifr_name, devname); | ||
806 | sin->sin_family = AF_INET; | ||
807 | sin->sin_addr.s_addr = htonl(ipaddr); | ||
808 | if (ioctl(fd, SIOCSIFADDR, &ifr) != 0) | ||
809 | err(1, "Setting %s interface address", devname); | ||
810 | ifr.ifr_flags = IFF_UP; | ||
811 | if (ioctl(fd, SIOCSIFFLAGS, &ifr) != 0) | ||
812 | err(1, "Bringing interface %s up", devname); | ||
813 | |||
814 | if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0) | ||
815 | err(1, "getting hw address for %s", devname); | ||
816 | |||
817 | memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6); | ||
818 | } | ||
819 | |||
820 | static void setup_tun_net(const char *arg, struct device_list *devices) | ||
821 | { | ||
822 | struct device *dev; | ||
823 | struct ifreq ifr; | ||
824 | int netfd, ipfd; | ||
825 | u32 ip; | ||
826 | const char *br_name = NULL; | ||
827 | |||
828 | netfd = open_or_die("/dev/net/tun", O_RDWR); | ||
829 | memset(&ifr, 0, sizeof(ifr)); | ||
830 | ifr.ifr_flags = IFF_TAP | IFF_NO_PI; | ||
831 | strcpy(ifr.ifr_name, "tap%d"); | ||
832 | if (ioctl(netfd, TUNSETIFF, &ifr) != 0) | ||
833 | err(1, "configuring /dev/net/tun"); | ||
834 | ioctl(netfd, TUNSETNOCSUM, 1); | ||
835 | |||
836 | /* You will be peer 1: we should create enough jitter to randomize */ | ||
837 | dev = new_device(devices, LGUEST_DEVICE_T_NET, 1, | ||
838 | NET_PEERNUM|LGUEST_DEVICE_F_RANDOMNESS, netfd, | ||
839 | handle_tun_input, peer_offset(0), handle_tun_output); | ||
840 | dev->priv = malloc(sizeof(bool)); | ||
841 | *(bool *)dev->priv = false; | ||
842 | |||
843 | ipfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); | ||
844 | if (ipfd < 0) | ||
845 | err(1, "opening IP socket"); | ||
846 | |||
847 | if (!strncmp(BRIDGE_PFX, arg, strlen(BRIDGE_PFX))) { | ||
848 | ip = INADDR_ANY; | ||
849 | br_name = arg + strlen(BRIDGE_PFX); | ||
850 | add_to_bridge(ipfd, ifr.ifr_name, br_name); | ||
851 | } else | ||
852 | ip = str2ip(arg); | ||
853 | |||
854 | /* We are peer 0, ie. first slot. */ | ||
855 | configure_device(ipfd, ifr.ifr_name, ip, dev->mem); | ||
856 | |||
857 | /* Set "promisc" bit: we want every single packet. */ | ||
858 | *((u8 *)dev->mem) |= 0x1; | ||
859 | |||
860 | close(ipfd); | ||
861 | |||
862 | verbose("device %p: tun net %u.%u.%u.%u\n", | ||
863 | (void *)(dev->desc->pfn * getpagesize()), | ||
864 | (u8)(ip>>24), (u8)(ip>>16), (u8)(ip>>8), (u8)ip); | ||
865 | if (br_name) | ||
866 | verbose("attached to bridge: %s\n", br_name); | ||
867 | } | ||
868 | |||
869 | /* Now we know how much memory we have, we copy in device descriptors */ | ||
870 | static void map_device_descriptors(struct device_list *devs, unsigned long mem) | ||
871 | { | ||
872 | struct device *i; | ||
873 | unsigned int num; | ||
874 | struct lguest_device_desc *descs; | ||
875 | |||
876 | /* Device descriptor array sits just above top of normal memory */ | ||
877 | descs = map_zeroed_pages(mem, 1); | ||
878 | |||
879 | for (i = devs->dev, num = 0; i; i = i->next, num++) { | ||
880 | if (num == LGUEST_MAX_DEVICES) | ||
881 | errx(1, "too many devices"); | ||
882 | verbose("Device %i: %s\n", num, | ||
883 | i->desc->type == LGUEST_DEVICE_T_NET ? "net" | ||
884 | : i->desc->type == LGUEST_DEVICE_T_CONSOLE ? "console" | ||
885 | : i->desc->type == LGUEST_DEVICE_T_BLOCK ? "block" | ||
886 | : "unknown"); | ||
887 | descs[num] = *i->desc; | ||
888 | free(i->desc); | ||
889 | i->desc = &descs[num]; | ||
890 | } | ||
891 | } | ||
892 | |||
893 | static void __attribute__((noreturn)) | ||
894 | run_guest(int lguest_fd, struct device_list *device_list) | ||
895 | { | ||
896 | for (;;) { | ||
897 | u32 args[] = { LHREQ_BREAK, 0 }; | ||
898 | unsigned long arr[2]; | ||
899 | int readval; | ||
900 | |||
901 | /* We read from the /dev/lguest device to run the Guest. */ | ||
902 | readval = read(lguest_fd, arr, sizeof(arr)); | ||
903 | |||
904 | if (readval == sizeof(arr)) { | ||
905 | handle_output(lguest_fd, arr[0], arr[1], device_list); | ||
906 | continue; | ||
907 | } else if (errno == ENOENT) { | ||
908 | char reason[1024] = { 0 }; | ||
909 | read(lguest_fd, reason, sizeof(reason)-1); | ||
910 | errx(1, "%s", reason); | ||
911 | } else if (errno != EAGAIN) | ||
912 | err(1, "Running guest failed"); | ||
913 | handle_input(lguest_fd, device_list); | ||
914 | if (write(lguest_fd, args, sizeof(args)) < 0) | ||
915 | err(1, "Resetting break"); | ||
916 | } | ||
917 | } | ||
918 | |||
919 | static struct option opts[] = { | ||
920 | { "verbose", 0, NULL, 'v' }, | ||
921 | { "sharenet", 1, NULL, 's' }, | ||
922 | { "tunnet", 1, NULL, 't' }, | ||
923 | { "block", 1, NULL, 'b' }, | ||
924 | { "initrd", 1, NULL, 'i' }, | ||
925 | { NULL }, | ||
926 | }; | ||
927 | static void usage(void) | ||
928 | { | ||
929 | errx(1, "Usage: lguest [--verbose] " | ||
930 | "[--sharenet=<filename>|--tunnet=(<ipaddr>|bridge:<bridgename>)\n" | ||
931 | "|--block=<filename>|--initrd=<filename>]...\n" | ||
932 | "<mem-in-mb> vmlinux [args...]"); | ||
933 | } | ||
934 | |||
935 | int main(int argc, char *argv[]) | ||
936 | { | ||
937 | unsigned long mem, pgdir, start, page_offset, initrd_size = 0; | ||
938 | int c, lguest_fd; | ||
939 | struct device_list device_list; | ||
940 | void *boot = (void *)0; | ||
941 | const char *initrd_name = NULL; | ||
942 | |||
943 | device_list.max_infd = -1; | ||
944 | device_list.dev = NULL; | ||
945 | device_list.lastdev = &device_list.dev; | ||
946 | FD_ZERO(&device_list.infds); | ||
947 | |||
948 | while ((c = getopt_long(argc, argv, "v", opts, NULL)) != EOF) { | ||
949 | switch (c) { | ||
950 | case 'v': | ||
951 | verbose = true; | ||
952 | break; | ||
953 | case 's': | ||
954 | setup_net_file(optarg, &device_list); | ||
955 | break; | ||
956 | case 't': | ||
957 | setup_tun_net(optarg, &device_list); | ||
958 | break; | ||
959 | case 'b': | ||
960 | setup_block_file(optarg, &device_list); | ||
961 | break; | ||
962 | case 'i': | ||
963 | initrd_name = optarg; | ||
964 | break; | ||
965 | default: | ||
966 | warnx("Unknown argument %s", argv[optind]); | ||
967 | usage(); | ||
968 | } | ||
969 | } | ||
970 | if (optind + 2 > argc) | ||
971 | usage(); | ||
972 | |||
973 | /* We need a console device */ | ||
974 | setup_console(&device_list); | ||
975 | |||
976 | /* First we map /dev/zero over all of guest-physical memory. */ | ||
977 | mem = atoi(argv[optind]) * 1024 * 1024; | ||
978 | map_zeroed_pages(0, mem / getpagesize()); | ||
979 | |||
980 | /* Now we load the kernel */ | ||
981 | start = load_kernel(open_or_die(argv[optind+1], O_RDONLY), | ||
982 | &page_offset); | ||
983 | |||
984 | /* Write the device descriptors into memory. */ | ||
985 | map_device_descriptors(&device_list, mem); | ||
986 | |||
987 | /* Map the initrd image if requested */ | ||
988 | if (initrd_name) { | ||
989 | initrd_size = load_initrd(initrd_name, mem); | ||
990 | *(unsigned long *)(boot+0x218) = mem - initrd_size; | ||
991 | *(unsigned long *)(boot+0x21c) = initrd_size; | ||
992 | *(unsigned char *)(boot+0x210) = 0xFF; | ||
993 | } | ||
994 | |||
995 | /* Set up the initial linar pagetables. */ | ||
996 | pgdir = setup_pagetables(mem, initrd_size, page_offset); | ||
997 | |||
998 | /* E820 memory map: ours is a simple, single region. */ | ||
999 | *(char*)(boot+E820NR) = 1; | ||
1000 | *((struct e820entry *)(boot+E820MAP)) | ||
1001 | = ((struct e820entry) { 0, mem, E820_RAM }); | ||
1002 | /* Command line pointer and command line (at 4096) */ | ||
1003 | *(void **)(boot + 0x228) = boot + 4096; | ||
1004 | concat(boot + 4096, argv+optind+2); | ||
1005 | /* Paravirt type: 1 == lguest */ | ||
1006 | *(int *)(boot + 0x23c) = 1; | ||
1007 | |||
1008 | lguest_fd = tell_kernel(pgdir, start, page_offset); | ||
1009 | waker_fd = setup_waker(lguest_fd, &device_list); | ||
1010 | |||
1011 | run_guest(lguest_fd, &device_list); | ||
1012 | } | ||
diff --git a/Documentation/lguest/lguest.txt b/Documentation/lguest/lguest.txt new file mode 100644 index 000000000000..821617bd6c04 --- /dev/null +++ b/Documentation/lguest/lguest.txt | |||
@@ -0,0 +1,129 @@ | |||
1 | Rusty's Remarkably Unreliable Guide to Lguest | ||
2 | - or, A Young Coder's Illustrated Hypervisor | ||
3 | http://lguest.ozlabs.org | ||
4 | |||
5 | Lguest is designed to be a minimal hypervisor for the Linux kernel, for | ||
6 | Linux developers and users to experiment with virtualization with the | ||
7 | minimum of complexity. Nonetheless, it should have sufficient | ||
8 | features to make it useful for specific tasks, and, of course, you are | ||
9 | encouraged to fork and enhance it. | ||
10 | |||
11 | Features: | ||
12 | |||
13 | - Kernel module which runs in a normal kernel. | ||
14 | - Simple I/O model for communication. | ||
15 | - Simple program to create new guests. | ||
16 | - Logo contains cute puppies: http://lguest.ozlabs.org | ||
17 | |||
18 | Developer features: | ||
19 | |||
20 | - Fun to hack on. | ||
21 | - No ABI: being tied to a specific kernel anyway, you can change anything. | ||
22 | - Many opportunities for improvement or feature implementation. | ||
23 | |||
24 | Running Lguest: | ||
25 | |||
26 | - Lguest runs the same kernel as guest and host. You can configure | ||
27 | them differently, but usually it's easiest not to. | ||
28 | |||
29 | You will need to configure your kernel with the following options: | ||
30 | |||
31 | CONFIG_HIGHMEM64G=n ("High Memory Support" "64GB")[1] | ||
32 | CONFIG_TUN=y/m ("Universal TUN/TAP device driver support") | ||
33 | CONFIG_EXPERIMENTAL=y ("Prompt for development and/or incomplete code/drivers") | ||
34 | CONFIG_PARAVIRT=y ("Paravirtualization support (EXPERIMENTAL)") | ||
35 | CONFIG_LGUEST=y/m ("Linux hypervisor example code") | ||
36 | |||
37 | and I recommend: | ||
38 | CONFIG_HZ=100 ("Timer frequency")[2] | ||
39 | |||
40 | - A tool called "lguest" is available in this directory: type "make" | ||
41 | to build it. If you didn't build your kernel in-tree, use "make | ||
42 | O=<builddir>". | ||
43 | |||
44 | - Create or find a root disk image. There are several useful ones | ||
45 | around, such as the xm-test tiny root image at | ||
46 | http://xm-test.xensource.com/ramdisks/initrd-1.1-i386.img | ||
47 | |||
48 | For more serious work, I usually use a distribution ISO image and | ||
49 | install it under qemu, then make multiple copies: | ||
50 | |||
51 | dd if=/dev/zero of=rootfile bs=1M count=2048 | ||
52 | qemu -cdrom image.iso -hda rootfile -net user -net nic -boot d | ||
53 | |||
54 | - "modprobe lg" if you built it as a module. | ||
55 | |||
56 | - Run an lguest as root: | ||
57 | |||
58 | Documentation/lguest/lguest 64m vmlinux --tunnet=192.168.19.1 --block=rootfile root=/dev/lgba | ||
59 | |||
60 | Explanation: | ||
61 | 64m: the amount of memory to use. | ||
62 | |||
63 | vmlinux: the kernel image found in the top of your build directory. You | ||
64 | can also use a standard bzImage. | ||
65 | |||
66 | --tunnet=192.168.19.1: configures a "tap" device for networking with this | ||
67 | IP address. | ||
68 | |||
69 | --block=rootfile: a file or block device which becomes /dev/lgba | ||
70 | inside the guest. | ||
71 | |||
72 | root=/dev/lgba: this (and anything else on the command line) are | ||
73 | kernel boot parameters. | ||
74 | |||
75 | - Configuring networking. I usually have the host masquerade, using | ||
76 | "iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE" and "echo 1 > | ||
77 | /proc/sys/net/ipv4/ip_forward". In this example, I would configure | ||
78 | eth0 inside the guest at 192.168.19.2. | ||
79 | |||
80 | Another method is to bridge the tap device to an external interface | ||
81 | using --tunnet=bridge:<bridgename>, and perhaps run dhcp on the guest | ||
82 | to obtain an IP address. The bridge needs to be configured first: | ||
83 | this option simply adds the tap interface to it. | ||
84 | |||
85 | A simple example on my system: | ||
86 | |||
87 | ifconfig eth0 0.0.0.0 | ||
88 | brctl addbr lg0 | ||
89 | ifconfig lg0 up | ||
90 | brctl addif lg0 eth0 | ||
91 | dhclient lg0 | ||
92 | |||
93 | Then use --tunnet=bridge:lg0 when launching the guest. | ||
94 | |||
95 | See http://linux-net.osdl.org/index.php/Bridge for general information | ||
96 | on how to get bridging working. | ||
97 | |||
98 | - You can also create an inter-guest network using | ||
99 | "--sharenet=<filename>": any two guests using the same file are on | ||
100 | the same network. This file is created if it does not exist. | ||
101 | |||
102 | Lguest I/O model: | ||
103 | |||
104 | Lguest uses a simplified DMA model plus shared memory for I/O. Guests | ||
105 | can communicate with each other if they share underlying memory | ||
106 | (usually by the lguest program mmaping the same file), but they can | ||
107 | use any non-shared memory to communicate with the lguest process. | ||
108 | |||
109 | Guests can register DMA buffers at any key (must be a valid physical | ||
110 | address) using the LHCALL_BIND_DMA(key, dmabufs, num<<8|irq) | ||
111 | hypercall. "dmabufs" is the physical address of an array of "num" | ||
112 | "struct lguest_dma": each contains a used_len, and an array of | ||
113 | physical addresses and lengths. When a transfer occurs, the | ||
114 | "used_len" field of one of the buffers which has used_len 0 will be | ||
115 | set to the length transferred and the irq will fire. | ||
116 | |||
117 | Using an irq value of 0 unbinds the dma buffers. | ||
118 | |||
119 | To send DMA, the LHCALL_SEND_DMA(key, dma_physaddr) hypercall is used, | ||
120 | and the bytes used is written to the used_len field. This can be 0 if | ||
121 | noone else has bound a DMA buffer to that key or some other error. | ||
122 | DMA buffers bound by the same guest are ignored. | ||
123 | |||
124 | Cheers! | ||
125 | Rusty Russell rusty@rustcorp.com.au. | ||
126 | |||
127 | [1] These are on various places on the TODO list, waiting for you to | ||
128 | get annoyed enough at the limitation to fix it. | ||
129 | [2] Lguest is not yet tickless when idle. See [1]. | ||
diff --git a/Documentation/oops-tracing.txt b/Documentation/oops-tracing.txt index 23e6dde7eea6..7f60dfe642ca 100644 --- a/Documentation/oops-tracing.txt +++ b/Documentation/oops-tracing.txt | |||
@@ -251,6 +251,8 @@ characters, each representing a particular tainted value. | |||
251 | 7: 'U' if a user or user application specifically requested that the | 251 | 7: 'U' if a user or user application specifically requested that the |
252 | Tainted flag be set, ' ' otherwise. | 252 | Tainted flag be set, ' ' otherwise. |
253 | 253 | ||
254 | 8: 'D' if the kernel has died recently, i.e. there was an OOPS or BUG. | ||
255 | |||
254 | The primary reason for the 'Tainted: ' string is to tell kernel | 256 | The primary reason for the 'Tainted: ' string is to tell kernel |
255 | debuggers if this is a clean kernel or if anything unusual has | 257 | debuggers if this is a clean kernel or if anything unusual has |
256 | occurred. Tainting is permanent: even if an offending module is | 258 | occurred. Tainting is permanent: even if an offending module is |
diff --git a/Documentation/power/freezing-of-tasks.txt b/Documentation/power/freezing-of-tasks.txt new file mode 100644 index 000000000000..af1a282c71a3 --- /dev/null +++ b/Documentation/power/freezing-of-tasks.txt | |||
@@ -0,0 +1,160 @@ | |||
1 | Freezing of tasks | ||
2 | (C) 2007 Rafael J. Wysocki <rjw@sisk.pl>, GPL | ||
3 | |||
4 | I. What is the freezing of tasks? | ||
5 | |||
6 | The freezing of tasks is a mechanism by which user space processes and some | ||
7 | kernel threads are controlled during hibernation or system-wide suspend (on some | ||
8 | architectures). | ||
9 | |||
10 | II. How does it work? | ||
11 | |||
12 | There are four per-task flags used for that, PF_NOFREEZE, PF_FROZEN, TIF_FREEZE | ||
13 | and PF_FREEZER_SKIP (the last one is auxiliary). The tasks that have | ||
14 | PF_NOFREEZE unset (all user space processes and some kernel threads) are | ||
15 | regarded as 'freezable' and treated in a special way before the system enters a | ||
16 | suspend state as well as before a hibernation image is created (in what follows | ||
17 | we only consider hibernation, but the description also applies to suspend). | ||
18 | |||
19 | Namely, as the first step of the hibernation procedure the function | ||
20 | freeze_processes() (defined in kernel/power/process.c) is called. It executes | ||
21 | try_to_freeze_tasks() that sets TIF_FREEZE for all of the freezable tasks and | ||
22 | sends a fake signal to each of them. A task that receives such a signal and has | ||
23 | TIF_FREEZE set, should react to it by calling the refrigerator() function | ||
24 | (defined in kernel/power/process.c), which sets the task's PF_FROZEN flag, | ||
25 | changes its state to TASK_UNINTERRUPTIBLE and makes it loop until PF_FROZEN is | ||
26 | cleared for it. Then, we say that the task is 'frozen' and therefore the set of | ||
27 | functions handling this mechanism is called 'the freezer' (these functions are | ||
28 | defined in kernel/power/process.c and include/linux/freezer.h). User space | ||
29 | processes are generally frozen before kernel threads. | ||
30 | |||
31 | It is not recommended to call refrigerator() directly. Instead, it is | ||
32 | recommended to use the try_to_freeze() function (defined in | ||
33 | include/linux/freezer.h), that checks the task's TIF_FREEZE flag and makes the | ||
34 | task enter refrigerator() if the flag is set. | ||
35 | |||
36 | For user space processes try_to_freeze() is called automatically from the | ||
37 | signal-handling code, but the freezable kernel threads need to call it | ||
38 | explicitly in suitable places. The code to do this may look like the following: | ||
39 | |||
40 | do { | ||
41 | hub_events(); | ||
42 | wait_event_interruptible(khubd_wait, | ||
43 | !list_empty(&hub_event_list)); | ||
44 | try_to_freeze(); | ||
45 | } while (!signal_pending(current)); | ||
46 | |||
47 | (from drivers/usb/core/hub.c::hub_thread()). | ||
48 | |||
49 | If a freezable kernel thread fails to call try_to_freeze() after the freezer has | ||
50 | set TIF_FREEZE for it, the freezing of tasks will fail and the entire | ||
51 | hibernation operation will be cancelled. For this reason, freezable kernel | ||
52 | threads must call try_to_freeze() somewhere. | ||
53 | |||
54 | After the system memory state has been restored from a hibernation image and | ||
55 | devices have been reinitialized, the function thaw_processes() is called in | ||
56 | order to clear the PF_FROZEN flag for each frozen task. Then, the tasks that | ||
57 | have been frozen leave refrigerator() and continue running. | ||
58 | |||
59 | III. Which kernel threads are freezable? | ||
60 | |||
61 | Kernel threads are not freezable by default. However, a kernel thread may clear | ||
62 | PF_NOFREEZE for itself by calling set_freezable() (the resetting of PF_NOFREEZE | ||
63 | directly is strongly discouraged). From this point it is regarded as freezable | ||
64 | and must call try_to_freeze() in a suitable place. | ||
65 | |||
66 | IV. Why do we do that? | ||
67 | |||
68 | Generally speaking, there is a couple of reasons to use the freezing of tasks: | ||
69 | |||
70 | 1. The principal reason is to prevent filesystems from being damaged after | ||
71 | hibernation. At the moment we have no simple means of checkpointing | ||
72 | filesystems, so if there are any modifications made to filesystem data and/or | ||
73 | metadata on disks, we cannot bring them back to the state from before the | ||
74 | modifications. At the same time each hibernation image contains some | ||
75 | filesystem-related information that must be consistent with the state of the | ||
76 | on-disk data and metadata after the system memory state has been restored from | ||
77 | the image (otherwise the filesystems will be damaged in a nasty way, usually | ||
78 | making them almost impossible to repair). We therefore freeze tasks that might | ||
79 | cause the on-disk filesystems' data and metadata to be modified after the | ||
80 | hibernation image has been created and before the system is finally powered off. | ||
81 | The majority of these are user space processes, but if any of the kernel threads | ||
82 | may cause something like this to happen, they have to be freezable. | ||
83 | |||
84 | 2. The second reason is to prevent user space processes and some kernel threads | ||
85 | from interfering with the suspending and resuming of devices. A user space | ||
86 | process running on a second CPU while we are suspending devices may, for | ||
87 | example, be troublesome and without the freezing of tasks we would need some | ||
88 | safeguards against race conditions that might occur in such a case. | ||
89 | |||
90 | Although Linus Torvalds doesn't like the freezing of tasks, he said this in one | ||
91 | of the discussions on LKML (http://lkml.org/lkml/2007/4/27/608): | ||
92 | |||
93 | "RJW:> Why we freeze tasks at all or why we freeze kernel threads? | ||
94 | |||
95 | Linus: In many ways, 'at all'. | ||
96 | |||
97 | I _do_ realize the IO request queue issues, and that we cannot actually do | ||
98 | s2ram with some devices in the middle of a DMA. So we want to be able to | ||
99 | avoid *that*, there's no question about that. And I suspect that stopping | ||
100 | user threads and then waiting for a sync is practically one of the easier | ||
101 | ways to do so. | ||
102 | |||
103 | So in practice, the 'at all' may become a 'why freeze kernel threads?' and | ||
104 | freezing user threads I don't find really objectionable." | ||
105 | |||
106 | Still, there are kernel threads that may want to be freezable. For example, if | ||
107 | a kernel that belongs to a device driver accesses the device directly, it in | ||
108 | principle needs to know when the device is suspended, so that it doesn't try to | ||
109 | access it at that time. However, if the kernel thread is freezable, it will be | ||
110 | frozen before the driver's .suspend() callback is executed and it will be | ||
111 | thawed after the driver's .resume() callback has run, so it won't be accessing | ||
112 | the device while it's suspended. | ||
113 | |||
114 | 3. Another reason for freezing tasks is to prevent user space processes from | ||
115 | realizing that hibernation (or suspend) operation takes place. Ideally, user | ||
116 | space processes should not notice that such a system-wide operation has occurred | ||
117 | and should continue running without any problems after the restore (or resume | ||
118 | from suspend). Unfortunately, in the most general case this is quite difficult | ||
119 | to achieve without the freezing of tasks. Consider, for example, a process | ||
120 | that depends on all CPUs being online while it's running. Since we need to | ||
121 | disable nonboot CPUs during the hibernation, if this process is not frozen, it | ||
122 | may notice that the number of CPUs has changed and may start to work incorrectly | ||
123 | because of that. | ||
124 | |||
125 | V. Are there any problems related to the freezing of tasks? | ||
126 | |||
127 | Yes, there are. | ||
128 | |||
129 | First of all, the freezing of kernel threads may be tricky if they depend one | ||
130 | on another. For example, if kernel thread A waits for a completion (in the | ||
131 | TASK_UNINTERRUPTIBLE state) that needs to be done by freezable kernel thread B | ||
132 | and B is frozen in the meantime, then A will be blocked until B is thawed, which | ||
133 | may be undesirable. That's why kernel threads are not freezable by default. | ||
134 | |||
135 | Second, there are the following two problems related to the freezing of user | ||
136 | space processes: | ||
137 | 1. Putting processes into an uninterruptible sleep distorts the load average. | ||
138 | 2. Now that we have FUSE, plus the framework for doing device drivers in | ||
139 | userspace, it gets even more complicated because some userspace processes are | ||
140 | now doing the sorts of things that kernel threads do | ||
141 | (https://lists.linux-foundation.org/pipermail/linux-pm/2007-May/012309.html). | ||
142 | |||
143 | The problem 1. seems to be fixable, although it hasn't been fixed so far. The | ||
144 | other one is more serious, but it seems that we can work around it by using | ||
145 | hibernation (and suspend) notifiers (in that case, though, we won't be able to | ||
146 | avoid the realization by the user space processes that the hibernation is taking | ||
147 | place). | ||
148 | |||
149 | There are also problems that the freezing of tasks tends to expose, although | ||
150 | they are not directly related to it. For example, if request_firmware() is | ||
151 | called from a device driver's .resume() routine, it will timeout and eventually | ||
152 | fail, because the user land process that should respond to the request is frozen | ||
153 | at this point. So, seemingly, the failure is due to the freezing of tasks. | ||
154 | Suppose, however, that the firmware file is located on a filesystem accessible | ||
155 | only through another device that hasn't been resumed yet. In that case, | ||
156 | request_firmware() will fail regardless of whether or not the freezing of tasks | ||
157 | is used. Consequently, the problem is not really related to the freezing of | ||
158 | tasks, since it generally exists anyway. [The solution to this particular | ||
159 | problem is to keep the firmware in memory after it's loaded for the first time | ||
160 | and upload if from memory to the device whenever necessary.] | ||
diff --git a/Documentation/power/kernel_threads.txt b/Documentation/power/kernel_threads.txt deleted file mode 100644 index fb57784986b1..000000000000 --- a/Documentation/power/kernel_threads.txt +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | KERNEL THREADS | ||
2 | |||
3 | |||
4 | Freezer | ||
5 | |||
6 | Upon entering a suspended state the system will freeze all | ||
7 | tasks. This is done by delivering pseudosignals. This affects | ||
8 | kernel threads, too. To successfully freeze a kernel thread | ||
9 | the thread has to check for the pseudosignal and enter the | ||
10 | refrigerator. Code to do this looks like this: | ||
11 | |||
12 | do { | ||
13 | hub_events(); | ||
14 | wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list)); | ||
15 | try_to_freeze(); | ||
16 | } while (!signal_pending(current)); | ||
17 | |||
18 | from drivers/usb/core/hub.c::hub_thread() | ||
19 | |||
20 | |||
21 | The Unfreezable | ||
22 | |||
23 | Some kernel threads however, must not be frozen. The kernel must | ||
24 | be able to finish pending IO operations and later on be able to | ||
25 | write the memory image to disk. Kernel threads needed to do IO | ||
26 | must stay awake. Such threads must mark themselves unfreezable | ||
27 | like this: | ||
28 | |||
29 | /* | ||
30 | * This thread doesn't need any user-level access, | ||
31 | * so get rid of all our resources. | ||
32 | */ | ||
33 | daemonize("usb-storage"); | ||
34 | |||
35 | current->flags |= PF_NOFREEZE; | ||
36 | |||
37 | from drivers/usb/storage/usb.c::usb_stor_control_thread() | ||
38 | |||
39 | Such drivers are themselves responsible for staying quiet during | ||
40 | the actual snapshotting. | ||
diff --git a/Documentation/power/notifiers.txt b/Documentation/power/notifiers.txt new file mode 100644 index 000000000000..9293e4bc857c --- /dev/null +++ b/Documentation/power/notifiers.txt | |||
@@ -0,0 +1,50 @@ | |||
1 | Suspend notifiers | ||
2 | (C) 2007 Rafael J. Wysocki <rjw@sisk.pl>, GPL | ||
3 | |||
4 | There are some operations that device drivers may want to carry out in their | ||
5 | .suspend() routines, but shouldn't, because they can cause the hibernation or | ||
6 | suspend to fail. For example, a driver may want to allocate a substantial amount | ||
7 | of memory (like 50 MB) in .suspend(), but that shouldn't be done after the | ||
8 | swsusp's memory shrinker has run. | ||
9 | |||
10 | Also, there may be some operations, that subsystems want to carry out before a | ||
11 | hibernation/suspend or after a restore/resume, requiring the system to be fully | ||
12 | functional, so the drivers' .suspend() and .resume() routines are not suitable | ||
13 | for this purpose. For example, device drivers may want to upload firmware to | ||
14 | their devices after a restore from a hibernation image, but they cannot do it by | ||
15 | calling request_firmware() from their .resume() routines (user land processes | ||
16 | are frozen at this point). The solution may be to load the firmware into | ||
17 | memory before processes are frozen and upload it from there in the .resume() | ||
18 | routine. Of course, a hibernation notifier may be used for this purpose. | ||
19 | |||
20 | The subsystems that have such needs can register suspend notifiers that will be | ||
21 | called upon the following events by the suspend core: | ||
22 | |||
23 | PM_HIBERNATION_PREPARE The system is going to hibernate or suspend, tasks will | ||
24 | be frozen immediately. | ||
25 | |||
26 | PM_POST_HIBERNATION The system memory state has been restored from a | ||
27 | hibernation image or an error occured during the | ||
28 | hibernation. Device drivers' .resume() callbacks have | ||
29 | been executed and tasks have been thawed. | ||
30 | |||
31 | PM_SUSPEND_PREPARE The system is preparing for a suspend. | ||
32 | |||
33 | PM_POST_SUSPEND The system has just resumed or an error occured during | ||
34 | the suspend. Device drivers' .resume() callbacks have | ||
35 | been executed and tasks have been thawed. | ||
36 | |||
37 | It is generally assumed that whatever the notifiers do for | ||
38 | PM_HIBERNATION_PREPARE, should be undone for PM_POST_HIBERNATION. Analogously, | ||
39 | operations performed for PM_SUSPEND_PREPARE should be reversed for | ||
40 | PM_POST_SUSPEND. Additionally, all of the notifiers are called for | ||
41 | PM_POST_HIBERNATION if one of them fails for PM_HIBERNATION_PREPARE, and | ||
42 | all of the notifiers are called for PM_POST_SUSPEND if one of them fails for | ||
43 | PM_SUSPEND_PREPARE. | ||
44 | |||
45 | The hibernation and suspend notifiers are called with pm_mutex held. They are | ||
46 | defined in the usual way, but their last argument is meaningless (it is always | ||
47 | NULL). To register and/or unregister a suspend notifier use the functions | ||
48 | register_pm_notifier() and unregister_pm_notifier(), respectively, defined in | ||
49 | include/linux/suspend.h . If you don't need to unregister the notifier, you can | ||
50 | also use the pm_notifier() macro defined in include/linux/suspend.h . | ||
diff --git a/Documentation/power/swsusp.txt b/Documentation/power/swsusp.txt index 152b510d1bbb..aea7e9209667 100644 --- a/Documentation/power/swsusp.txt +++ b/Documentation/power/swsusp.txt | |||
@@ -140,21 +140,11 @@ should be sent to the mailing list available through the suspend2 | |||
140 | website, and not to the Linux Kernel Mailing List. We are working | 140 | website, and not to the Linux Kernel Mailing List. We are working |
141 | toward merging suspend2 into the mainline kernel. | 141 | toward merging suspend2 into the mainline kernel. |
142 | 142 | ||
143 | Q: A kernel thread must voluntarily freeze itself (call 'refrigerator'). | 143 | Q: What is the freezing of tasks and why are we using it? |
144 | I found some kernel threads that don't do it, and they don't freeze | ||
145 | so the system can't sleep. Is this a known behavior? | ||
146 | |||
147 | A: All such kernel threads need to be fixed, one by one. Select the | ||
148 | place where the thread is safe to be frozen (no kernel semaphores | ||
149 | should be held at that point and it must be safe to sleep there), and | ||
150 | add: | ||
151 | |||
152 | try_to_freeze(); | ||
153 | |||
154 | If the thread is needed for writing the image to storage, you should | ||
155 | instead set the PF_NOFREEZE process flag when creating the thread (and | ||
156 | be very careful). | ||
157 | 144 | ||
145 | A: The freezing of tasks is a mechanism by which user space processes and some | ||
146 | kernel threads are controlled during hibernation or system-wide suspend (on some | ||
147 | architectures). See freezing-of-tasks.txt for details. | ||
158 | 148 | ||
159 | Q: What is the difference between "platform" and "shutdown"? | 149 | Q: What is the difference between "platform" and "shutdown"? |
160 | 150 | ||
diff --git a/Documentation/powerpc/booting-without-of.txt b/Documentation/powerpc/booting-without-of.txt index 0c2434822094..76733a3962f0 100644 --- a/Documentation/powerpc/booting-without-of.txt +++ b/Documentation/powerpc/booting-without-of.txt | |||
@@ -1250,6 +1250,12 @@ platforms are moved over to use the flattened-device-tree model. | |||
1250 | network device. This is used by the bootwrapper to interpret | 1250 | network device. This is used by the bootwrapper to interpret |
1251 | MAC addresses passed by the firmware when no information other | 1251 | MAC addresses passed by the firmware when no information other |
1252 | than indices is available to associate an address with a device. | 1252 | than indices is available to associate an address with a device. |
1253 | - phy-connection-type : a string naming the controller/PHY interface type, | ||
1254 | i.e., "mii" (default), "rmii", "gmii", "rgmii", "rgmii-id", "sgmii", | ||
1255 | "tbi", or "rtbi". This property is only really needed if the connection | ||
1256 | is of type "rgmii-id", as all other connection types are detected by | ||
1257 | hardware. | ||
1258 | |||
1253 | 1259 | ||
1254 | Example: | 1260 | Example: |
1255 | 1261 | ||
diff --git a/Documentation/rtc.txt b/Documentation/rtc.txt index 7c701b88d6d5..c931d613f641 100644 --- a/Documentation/rtc.txt +++ b/Documentation/rtc.txt | |||
@@ -385,7 +385,7 @@ test_PIE: | |||
385 | /* not all RTCs support periodic IRQs */ | 385 | /* not all RTCs support periodic IRQs */ |
386 | if (errno == ENOTTY) { | 386 | if (errno == ENOTTY) { |
387 | fprintf(stderr, "\nNo periodic IRQ support\n"); | 387 | fprintf(stderr, "\nNo periodic IRQ support\n"); |
388 | return 0; | 388 | goto done; |
389 | } | 389 | } |
390 | perror("RTC_IRQP_READ ioctl"); | 390 | perror("RTC_IRQP_READ ioctl"); |
391 | exit(errno); | 391 | exit(errno); |
diff --git a/Documentation/spi/spi-lm70llp b/Documentation/spi/spi-lm70llp new file mode 100644 index 000000000000..154bd02220b9 --- /dev/null +++ b/Documentation/spi/spi-lm70llp | |||
@@ -0,0 +1,69 @@ | |||
1 | spi_lm70llp : LM70-LLP parport-to-SPI adapter | ||
2 | ============================================== | ||
3 | |||
4 | Supported board/chip: | ||
5 | * National Semiconductor LM70 LLP evaluation board | ||
6 | Datasheet: http://www.national.com/pf/LM/LM70.html | ||
7 | |||
8 | Author: | ||
9 | Kaiwan N Billimoria <kaiwan@designergraphix.com> | ||
10 | |||
11 | Description | ||
12 | ----------- | ||
13 | This driver provides glue code connecting a National Semiconductor LM70 LLP | ||
14 | temperature sensor evaluation board to the kernel's SPI core subsystem. | ||
15 | |||
16 | In effect, this driver turns the parallel port interface on the eval board | ||
17 | into a SPI bus with a single device, which will be driven by the generic | ||
18 | LM70 driver (drivers/hwmon/lm70.c). | ||
19 | |||
20 | The hardware interfacing on the LM70 LLP eval board is as follows: | ||
21 | |||
22 | Parallel LM70 LLP | ||
23 | Port Direction JP2 Header | ||
24 | ----------- --------- ---------------- | ||
25 | D0 2 - - | ||
26 | D1 3 --> V+ 5 | ||
27 | D2 4 --> V+ 5 | ||
28 | D3 5 --> V+ 5 | ||
29 | D4 6 --> V+ 5 | ||
30 | D5 7 --> nCS 8 | ||
31 | D6 8 --> SCLK 3 | ||
32 | D7 9 --> SI/O 5 | ||
33 | GND 25 - GND 7 | ||
34 | Select 13 <-- SI/O 1 | ||
35 | ----------- --------- ---------------- | ||
36 | |||
37 | Note that since the LM70 uses a "3-wire" variant of SPI, the SI/SO pin | ||
38 | is connected to both pin D7 (as Master Out) and Select (as Master In) | ||
39 | using an arrangment that lets either the parport or the LM70 pull the | ||
40 | pin low. This can't be shared with true SPI devices, but other 3-wire | ||
41 | devices might share the same SI/SO pin. | ||
42 | |||
43 | The bitbanger routine in this driver (lm70_txrx) is called back from | ||
44 | the bound "hwmon/lm70" protocol driver through its sysfs hook, using a | ||
45 | spi_write_then_read() call. It performs Mode 0 (SPI/Microwire) bitbanging. | ||
46 | The lm70 driver then inteprets the resulting digital temperature value | ||
47 | and exports it through sysfs. | ||
48 | |||
49 | A "gotcha": National Semiconductor's LM70 LLP eval board circuit schematic | ||
50 | shows that the SI/O line from the LM70 chip is connected to the base of a | ||
51 | transistor Q1 (and also a pullup, and a zener diode to D7); while the | ||
52 | collector is tied to VCC. | ||
53 | |||
54 | Interpreting this circuit, when the LM70 SI/O line is High (or tristate | ||
55 | and not grounded by the host via D7), the transistor conducts and switches | ||
56 | the collector to zero, which is reflected on pin 13 of the DB25 parport | ||
57 | connector. When SI/O is Low (driven by the LM70 or the host) on the other | ||
58 | hand, the transistor is cut off and the voltage tied to it's collector is | ||
59 | reflected on pin 13 as a High level. | ||
60 | |||
61 | So: the getmiso inline routine in this driver takes this fact into account, | ||
62 | inverting the value read at pin 13. | ||
63 | |||
64 | |||
65 | Thanks to | ||
66 | --------- | ||
67 | o David Brownell for mentoring the SPI-side driver development. | ||
68 | o Dr.Craig Hollabaugh for the (early) "manual" bitbanging driver version. | ||
69 | o Nadir Billimoria for help interpreting the circuit schematic. | ||
diff --git a/Documentation/sysctl/vm.txt b/Documentation/sysctl/vm.txt index df3ff2095f9d..a0ccc5b60260 100644 --- a/Documentation/sysctl/vm.txt +++ b/Documentation/sysctl/vm.txt | |||
@@ -38,7 +38,8 @@ Currently, these files are in /proc/sys/vm: | |||
38 | 38 | ||
39 | dirty_ratio, dirty_background_ratio, dirty_expire_centisecs, | 39 | dirty_ratio, dirty_background_ratio, dirty_expire_centisecs, |
40 | dirty_writeback_centisecs, vfs_cache_pressure, laptop_mode, | 40 | dirty_writeback_centisecs, vfs_cache_pressure, laptop_mode, |
41 | block_dump, swap_token_timeout, drop-caches: | 41 | block_dump, swap_token_timeout, drop-caches, |
42 | hugepages_treat_as_movable: | ||
42 | 43 | ||
43 | See Documentation/filesystems/proc.txt | 44 | See Documentation/filesystems/proc.txt |
44 | 45 | ||
diff --git a/Documentation/video4linux/CARDLIST.bttv b/Documentation/video4linux/CARDLIST.bttv index b60639130a51..177159c5f4c4 100644 --- a/Documentation/video4linux/CARDLIST.bttv +++ b/Documentation/video4linux/CARDLIST.bttv | |||
@@ -66,7 +66,7 @@ | |||
66 | 65 -> Lifeview FlyVideo 2000S LR90 | 66 | 65 -> Lifeview FlyVideo 2000S LR90 |
67 | 66 -> Terratec TValueRadio [153b:1135,153b:ff3b] | 67 | 66 -> Terratec TValueRadio [153b:1135,153b:ff3b] |
68 | 67 -> IODATA GV-BCTV4/PCI [10fc:4050] | 68 | 67 -> IODATA GV-BCTV4/PCI [10fc:4050] |
69 | 68 -> 3Dfx VoodooTV FM (Euro), VoodooTV 200 (USA) [121a:3000,10b4:2637] | 69 | 68 -> 3Dfx VoodooTV FM (Euro) [10b4:2637] |
70 | 69 -> Active Imaging AIMMS | 70 | 69 -> Active Imaging AIMMS |
71 | 70 -> Prolink Pixelview PV-BT878P+ (Rev.4C,8E) | 71 | 70 -> Prolink Pixelview PV-BT878P+ (Rev.4C,8E) |
72 | 71 -> Lifeview FlyVideo 98EZ (capture only) LR51 [1851:1851] | 72 | 71 -> Lifeview FlyVideo 98EZ (capture only) LR51 [1851:1851] |
@@ -145,3 +145,5 @@ | |||
145 | 144 -> MagicTV | 145 | 144 -> MagicTV |
146 | 145 -> SSAI Security Video Interface [4149:5353] | 146 | 145 -> SSAI Security Video Interface [4149:5353] |
147 | 146 -> SSAI Ultrasound Video Interface [414a:5353] | 147 | 146 -> SSAI Ultrasound Video Interface [414a:5353] |
148 | 147 -> VoodooTV 200 (USA) [121a:3000] | ||
149 | 148 -> DViCO FusionHDTV 2 [dbc0:d200] | ||
diff --git a/Documentation/video4linux/CARDLIST.cx88 b/Documentation/video4linux/CARDLIST.cx88 index 60f838beb9c8..82ac8250e978 100644 --- a/Documentation/video4linux/CARDLIST.cx88 +++ b/Documentation/video4linux/CARDLIST.cx88 | |||
@@ -55,3 +55,4 @@ | |||
55 | 54 -> Norwood Micro TV Tuner | 55 | 54 -> Norwood Micro TV Tuner |
56 | 55 -> Shenzhen Tungsten Ages Tech TE-DTV-250 / Swann OEM [c180:c980] | 56 | 55 -> Shenzhen Tungsten Ages Tech TE-DTV-250 / Swann OEM [c180:c980] |
57 | 56 -> Hauppauge WinTV-HVR1300 DVB-T/Hybrid MPEG Encoder [0070:9600,0070:9601,0070:9602] | 57 | 56 -> Hauppauge WinTV-HVR1300 DVB-T/Hybrid MPEG Encoder [0070:9600,0070:9601,0070:9602] |
58 | 57 -> ADS Tech Instant Video PCI [1421:0390] | ||
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134 index 712e8c8333cc..3f8aeab50a10 100644 --- a/Documentation/video4linux/CARDLIST.saa7134 +++ b/Documentation/video4linux/CARDLIST.saa7134 | |||
@@ -114,3 +114,4 @@ | |||
114 | 113 -> Elitegroup ECS TVP3XP FM1246 Tuner Card (PAL,FM) [1019:4cb6] | 114 | 113 -> Elitegroup ECS TVP3XP FM1246 Tuner Card (PAL,FM) [1019:4cb6] |
115 | 114 -> KWorld DVB-T 210 [17de:7250] | 115 | 114 -> KWorld DVB-T 210 [17de:7250] |
116 | 115 -> Sabrent PCMCIA TV-PCB05 [0919:2003] | 116 | 115 -> Sabrent PCMCIA TV-PCB05 [0919:2003] |
117 | 116 -> 10MOONS TM300 TV Card [1131:2304] | ||
diff --git a/Documentation/video4linux/CARDLIST.tuner b/Documentation/video4linux/CARDLIST.tuner index 44134f04b82a..a88c02d23805 100644 --- a/Documentation/video4linux/CARDLIST.tuner +++ b/Documentation/video4linux/CARDLIST.tuner | |||
@@ -40,7 +40,7 @@ tuner=38 - Philips PAL/SECAM multi (FM1216ME MK3) | |||
40 | tuner=39 - LG NTSC (newer TAPC series) | 40 | tuner=39 - LG NTSC (newer TAPC series) |
41 | tuner=40 - HITACHI V7-J180AT | 41 | tuner=40 - HITACHI V7-J180AT |
42 | tuner=41 - Philips PAL_MK (FI1216 MK) | 42 | tuner=41 - Philips PAL_MK (FI1216 MK) |
43 | tuner=42 - Philips 1236D ATSC/NTSC dual in | 43 | tuner=42 - Philips FCV1236D ATSC/NTSC dual in |
44 | tuner=43 - Philips NTSC MK3 (FM1236MK3 or FM1236/F) | 44 | tuner=43 - Philips NTSC MK3 (FM1236MK3 or FM1236/F) |
45 | tuner=44 - Philips 4 in 1 (ATI TV Wonder Pro/Conexant) | 45 | tuner=44 - Philips 4 in 1 (ATI TV Wonder Pro/Conexant) |
46 | tuner=45 - Microtune 4049 FM5 | 46 | tuner=45 - Microtune 4049 FM5 |
@@ -72,3 +72,4 @@ tuner=70 - Samsung TCPN 2121P30A | |||
72 | tuner=71 - Xceive xc3028 | 72 | tuner=71 - Xceive xc3028 |
73 | tuner=72 - Thomson FE6600 | 73 | tuner=72 - Thomson FE6600 |
74 | tuner=73 - Samsung TCPG 6121P30A | 74 | tuner=73 - Samsung TCPG 6121P30A |
75 | tuner=75 - Philips TEA5761 FM Radio | ||
diff --git a/Documentation/video4linux/sn9c102.txt b/Documentation/video4linux/sn9c102.txt index 279717c96f63..1ffad19ce891 100644 --- a/Documentation/video4linux/sn9c102.txt +++ b/Documentation/video4linux/sn9c102.txt | |||
@@ -436,7 +436,7 @@ HV7131D Hynix Semiconductor | Yes No No No | |||
436 | HV7131R Hynix Semiconductor | No Yes Yes Yes | 436 | HV7131R Hynix Semiconductor | No Yes Yes Yes |
437 | MI-0343 Micron Technology | Yes No No No | 437 | MI-0343 Micron Technology | Yes No No No |
438 | MI-0360 Micron Technology | No Yes Yes Yes | 438 | MI-0360 Micron Technology | No Yes Yes Yes |
439 | OV7630 OmniVision Technologies | Yes Yes No No | 439 | OV7630 OmniVision Technologies | Yes Yes Yes Yes |
440 | OV7660 OmniVision Technologies | No No Yes Yes | 440 | OV7660 OmniVision Technologies | No No Yes Yes |
441 | PAS106B PixArt Imaging | Yes No No No | 441 | PAS106B PixArt Imaging | Yes No No No |
442 | PAS202B PixArt Imaging | Yes Yes No No | 442 | PAS202B PixArt Imaging | Yes Yes No No |
@@ -583,6 +583,7 @@ order): | |||
583 | - Bertrik Sikken, who reverse-engineered and documented the Huffman compression | 583 | - Bertrik Sikken, who reverse-engineered and documented the Huffman compression |
584 | algorithm used in the SN9C101, SN9C102 and SN9C103 controllers and | 584 | algorithm used in the SN9C101, SN9C102 and SN9C103 controllers and |
585 | implemented the first decoder; | 585 | implemented the first decoder; |
586 | - Ronny Standke for the donation of a webcam; | ||
586 | - Mizuno Takafumi for the donation of a webcam; | 587 | - Mizuno Takafumi for the donation of a webcam; |
587 | - an "anonymous" donator (who didn't want his name to be revealed) for the | 588 | - an "anonymous" donator (who didn't want his name to be revealed) for the |
588 | donation of a webcam. | 589 | donation of a webcam. |
diff --git a/Documentation/video4linux/zr364xx.txt b/Documentation/video4linux/zr364xx.txt index c76992d0ff4d..4d9a0c33f2fd 100644 --- a/Documentation/video4linux/zr364xx.txt +++ b/Documentation/video4linux/zr364xx.txt | |||
@@ -62,4 +62,4 @@ Vendor Product Distributor Model | |||
62 | 0x0784 0x0040 Traveler Slimline X5 | 62 | 0x0784 0x0040 Traveler Slimline X5 |
63 | 0x06d6 0x0034 Trust Powerc@m 750 | 63 | 0x06d6 0x0034 Trust Powerc@m 750 |
64 | 0x0a17 0x0062 Pentax Optio 50L | 64 | 0x0a17 0x0062 Pentax Optio 50L |
65 | 65 | 0x06d6 0x003b Trust Powerc@m 970Z | |
diff --git a/Documentation/vm/slub.txt b/Documentation/vm/slub.txt index df812b03b65d..d17f324db9f5 100644 --- a/Documentation/vm/slub.txt +++ b/Documentation/vm/slub.txt | |||
@@ -127,13 +127,20 @@ SLUB Debug output | |||
127 | 127 | ||
128 | Here is a sample of slub debug output: | 128 | Here is a sample of slub debug output: |
129 | 129 | ||
130 | *** SLUB kmalloc-8: Redzone Active@0xc90f6d20 slab 0xc528c530 offset=3360 flags=0x400000c3 inuse=61 freelist=0xc90f6d58 | 130 | ==================================================================== |
131 | Bytes b4 0xc90f6d10: 00 00 00 00 00 00 00 00 5a 5a 5a 5a 5a 5a 5a 5a ........ZZZZZZZZ | 131 | BUG kmalloc-8: Redzone overwritten |
132 | Object 0xc90f6d20: 31 30 31 39 2e 30 30 35 1019.005 | 132 | -------------------------------------------------------------------- |
133 | Redzone 0xc90f6d28: 00 cc cc cc . | 133 | |
134 | FreePointer 0xc90f6d2c -> 0xc90f6d58 | 134 | INFO: 0xc90f6d28-0xc90f6d2b. First byte 0x00 instead of 0xcc |
135 | Last alloc: get_modalias+0x61/0xf5 jiffies_ago=53 cpu=1 pid=554 | 135 | INFO: Slab 0xc528c530 flags=0x400000c3 inuse=61 fp=0xc90f6d58 |
136 | Filler 0xc90f6d50: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ | 136 | INFO: Object 0xc90f6d20 @offset=3360 fp=0xc90f6d58 |
137 | INFO: Allocated in get_modalias+0x61/0xf5 age=53 cpu=1 pid=554 | ||
138 | |||
139 | Bytes b4 0xc90f6d10: 00 00 00 00 00 00 00 00 5a 5a 5a 5a 5a 5a 5a 5a ........ZZZZZZZZ | ||
140 | Object 0xc90f6d20: 31 30 31 39 2e 30 30 35 1019.005 | ||
141 | Redzone 0xc90f6d28: 00 cc cc cc . | ||
142 | Padding 0xc90f6d50: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ | ||
143 | |||
137 | [<c010523d>] dump_trace+0x63/0x1eb | 144 | [<c010523d>] dump_trace+0x63/0x1eb |
138 | [<c01053df>] show_trace_log_lvl+0x1a/0x2f | 145 | [<c01053df>] show_trace_log_lvl+0x1a/0x2f |
139 | [<c010601d>] show_trace+0x12/0x14 | 146 | [<c010601d>] show_trace+0x12/0x14 |
@@ -155,74 +162,108 @@ Filler 0xc90f6d50: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ | |||
155 | [<c0104112>] sysenter_past_esp+0x5f/0x99 | 162 | [<c0104112>] sysenter_past_esp+0x5f/0x99 |
156 | [<b7f7b410>] 0xb7f7b410 | 163 | [<b7f7b410>] 0xb7f7b410 |
157 | ======================= | 164 | ======================= |
158 | @@@ SLUB kmalloc-8: Restoring redzone (0xcc) from 0xc90f6d28-0xc90f6d2b | ||
159 | 165 | ||
166 | FIX kmalloc-8: Restoring Redzone 0xc90f6d28-0xc90f6d2b=0xcc | ||
160 | 167 | ||
168 | If SLUB encounters a corrupted object (full detection requires the kernel | ||
169 | to be booted with slub_debug) then the following output will be dumped | ||
170 | into the syslog: | ||
161 | 171 | ||
162 | If SLUB encounters a corrupted object then it will perform the following | 172 | 1. Description of the problem encountered |
163 | actions: | ||
164 | |||
165 | 1. Isolation and report of the issue | ||
166 | 173 | ||
167 | This will be a message in the system log starting with | 174 | This will be a message in the system log starting with |
168 | 175 | ||
169 | *** SLUB <slab cache affected>: <What went wrong>@<object address> | 176 | =============================================== |
170 | offset=<offset of object into slab> flags=<slabflags> | 177 | BUG <slab cache affected>: <What went wrong> |
171 | inuse=<objects in use in this slab> freelist=<first free object in slab> | 178 | ----------------------------------------------- |
172 | 179 | ||
173 | 2. Report on how the problem was dealt with in order to ensure the continued | 180 | INFO: <corruption start>-<corruption_end> <more info> |
174 | operation of the system. | 181 | INFO: Slab <address> <slab information> |
182 | INFO: Object <address> <object information> | ||
183 | INFO: Allocated in <kernel function> age=<jiffies since alloc> cpu=<allocated by | ||
184 | cpu> pid=<pid of the process> | ||
185 | INFO: Freed in <kernel function> age=<jiffies since free> cpu=<freed by cpu> | ||
186 | pid=<pid of the process> | ||
175 | 187 | ||
176 | These are messages in the system log beginning with | 188 | (Object allocation / free information is only available if SLAB_STORE_USER is |
177 | 189 | set for the slab. slub_debug sets that option) | |
178 | @@@ SLUB <slab cache affected>: <corrective action taken> | ||
179 | 190 | ||
191 | 2. The object contents if an object was involved. | ||
180 | 192 | ||
181 | In the above sample SLUB found that the Redzone of an active object has | 193 | Various types of lines can follow the BUG SLUB line: |
182 | been overwritten. Here a string of 8 characters was written into a slab that | ||
183 | has the length of 8 characters. However, a 8 character string needs a | ||
184 | terminating 0. That zero has overwritten the first byte of the Redzone field. | ||
185 | After reporting the details of the issue encountered the @@@ SLUB message | ||
186 | tell us that SLUB has restored the redzone to its proper value and then | ||
187 | system operations continue. | ||
188 | |||
189 | Various types of lines can follow the @@@ SLUB line: | ||
190 | 194 | ||
191 | Bytes b4 <address> : <bytes> | 195 | Bytes b4 <address> : <bytes> |
192 | Show a few bytes before the object where the problem was detected. | 196 | Shows a few bytes before the object where the problem was detected. |
193 | Can be useful if the corruption does not stop with the start of the | 197 | Can be useful if the corruption does not stop with the start of the |
194 | object. | 198 | object. |
195 | 199 | ||
196 | Object <address> : <bytes> | 200 | Object <address> : <bytes> |
197 | The bytes of the object. If the object is inactive then the bytes | 201 | The bytes of the object. If the object is inactive then the bytes |
198 | typically contain poisoning values. Any non-poison value shows a | 202 | typically contain poison values. Any non-poison value shows a |
199 | corruption by a write after free. | 203 | corruption by a write after free. |
200 | 204 | ||
201 | Redzone <address> : <bytes> | 205 | Redzone <address> : <bytes> |
202 | The redzone following the object. The redzone is used to detect | 206 | The Redzone following the object. The Redzone is used to detect |
203 | writes after the object. All bytes should always have the same | 207 | writes after the object. All bytes should always have the same |
204 | value. If there is any deviation then it is due to a write after | 208 | value. If there is any deviation then it is due to a write after |
205 | the object boundary. | 209 | the object boundary. |
206 | 210 | ||
207 | Freepointer | 211 | (Redzone information is only available if SLAB_RED_ZONE is set. |
208 | The pointer to the next free object in the slab. May become | 212 | slub_debug sets that option) |
209 | corrupted if overwriting continues after the red zone. | ||
210 | |||
211 | Last alloc: | ||
212 | Last free: | ||
213 | Shows the address from which the object was allocated/freed last. | ||
214 | We note the pid, the time and the CPU that did so. This is usually | ||
215 | the most useful information to figure out where things went wrong. | ||
216 | Here get_modalias() did an kmalloc(8) instead of a kmalloc(9). | ||
217 | 213 | ||
218 | Filler <address> : <bytes> | 214 | Padding <address> : <bytes> |
219 | Unused data to fill up the space in order to get the next object | 215 | Unused data to fill up the space in order to get the next object |
220 | properly aligned. In the debug case we make sure that there are | 216 | properly aligned. In the debug case we make sure that there are |
221 | at least 4 bytes of filler. This allow for the detection of writes | 217 | at least 4 bytes of padding. This allows the detection of writes |
222 | before the object. | 218 | before the object. |
223 | 219 | ||
224 | Following the filler will be a stackdump. That stackdump describes the | 220 | 3. A stackdump |
225 | location where the error was detected. The cause of the corruption is more | 221 | |
226 | likely to be found by looking at the information about the last alloc / free. | 222 | The stackdump describes the location where the error was detected. The cause |
223 | of the corruption is may be more likely found by looking at the function that | ||
224 | allocated or freed the object. | ||
225 | |||
226 | 4. Report on how the problem was dealt with in order to ensure the continued | ||
227 | operation of the system. | ||
228 | |||
229 | These are messages in the system log beginning with | ||
230 | |||
231 | FIX <slab cache affected>: <corrective action taken> | ||
232 | |||
233 | In the above sample SLUB found that the Redzone of an active object has | ||
234 | been overwritten. Here a string of 8 characters was written into a slab that | ||
235 | has the length of 8 characters. However, a 8 character string needs a | ||
236 | terminating 0. That zero has overwritten the first byte of the Redzone field. | ||
237 | After reporting the details of the issue encountered the FIX SLUB message | ||
238 | tell us that SLUB has restored the Redzone to its proper value and then | ||
239 | system operations continue. | ||
240 | |||
241 | Emergency operations: | ||
242 | --------------------- | ||
243 | |||
244 | Minimal debugging (sanity checks alone) can be enabled by booting with | ||
245 | |||
246 | slub_debug=F | ||
247 | |||
248 | This will be generally be enough to enable the resiliency features of slub | ||
249 | which will keep the system running even if a bad kernel component will | ||
250 | keep corrupting objects. This may be important for production systems. | ||
251 | Performance will be impacted by the sanity checks and there will be a | ||
252 | continual stream of error messages to the syslog but no additional memory | ||
253 | will be used (unlike full debugging). | ||
254 | |||
255 | No guarantees. The kernel component still needs to be fixed. Performance | ||
256 | may be optimized further by locating the slab that experiences corruption | ||
257 | and enabling debugging only for that cache | ||
258 | |||
259 | I.e. | ||
260 | |||
261 | slub_debug=F,dentry | ||
262 | |||
263 | If the corruption occurs by writing after the end of the object then it | ||
264 | may be advisable to enable a Redzone to avoid corrupting the beginning | ||
265 | of other objects. | ||
266 | |||
267 | slub_debug=FZ,dentry | ||
227 | 268 | ||
228 | Christoph Lameter, <clameter@sgi.com>, May 23, 2007 | 269 | Christoph Lameter, <clameter@sgi.com>, May 30, 2007 |
diff --git a/Documentation/zh_CN/HOWTO b/Documentation/zh_CN/HOWTO new file mode 100644 index 000000000000..48fc67bfbe3d --- /dev/null +++ b/Documentation/zh_CN/HOWTO | |||
@@ -0,0 +1,536 @@ | |||
1 | Chinese translated version of Documentation/HOWTO | ||
2 | |||
3 | If you have any comment or update to the content, please contact the | ||
4 | original document maintainer directly. However, if you have problem | ||
5 | communicating in English you can also ask the Chinese maintainer for | ||
6 | help. Contact the Chinese maintainer, if this translation is outdated | ||
7 | or there is problem with translation. | ||
8 | |||
9 | Maintainer: Greg Kroah-Hartman <greg@kroah.com> | ||
10 | Chinese maintainer: Li Yang <leoli@freescale.com> | ||
11 | --------------------------------------------------------------------- | ||
12 | Documentation/HOWTO 的中文翻译 | ||
13 | |||
14 | 如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文 | ||
15 | 交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻 | ||
16 | 译存在问题,请联系中文版维护者。 | ||
17 | |||
18 | 英文版维护者: Greg Kroah-Hartman <greg@kroah.com> | ||
19 | 中文版维护者: 李阳 Li Yang <leoli@freescale.com> | ||
20 | 中文版翻译者: 李阳 Li Yang <leoli@freescale.com> | ||
21 | 中文版校译者: 钟宇 TripleX Chung <xxx.phy@gmail.com> | ||
22 | 陈琦 Maggie Chen <chenqi@beyondsoft.com> | ||
23 | 王聪 Wang Cong <xiyou.wangcong@gmail.com> | ||
24 | |||
25 | 以下为正文 | ||
26 | --------------------------------------------------------------------- | ||
27 | |||
28 | 如何参与Linux内核开发 | ||
29 | --------------------- | ||
30 | |||
31 | 这是一篇将如何参与Linux内核开发的相关问题一网打尽的终极秘笈。它将指导你 | ||
32 | 成为一名Linux内核开发者,并且学会如何同Linux内核开发社区合作。它尽可能不 | ||
33 | 包括任何关于内核编程的技术细节,但会给你指引一条获得这些知识的正确途径。 | ||
34 | |||
35 | 如果这篇文章中的任何内容不再适用,请给文末列出的文件维护者发送补丁。 | ||
36 | |||
37 | |||
38 | 入门 | ||
39 | ---- | ||
40 | |||
41 | 你想了解如何成为一名Linux内核开发者?或者老板吩咐你“给这个设备写个Linux | ||
42 | 驱动程序”?这篇文章的目的就是教会你达成这些目标的全部诀窍,它将描述你需 | ||
43 | 要经过的流程以及给出如何同内核社区合作的一些提示。它还将试图解释内核社区 | ||
44 | 为何这样运作。 | ||
45 | |||
46 | Linux内核大部分是由C语言写成的,一些体系结构相关的代码用到了汇编语言。要 | ||
47 | 参与内核开发,你必须精通C语言。除非你想为某个架构开发底层代码,否则你并 | ||
48 | 不需要了解(任何体系结构的)汇编语言。下面列举的书籍虽然不能替代扎实的C | ||
49 | 语言教育和多年的开发经验,但如果需要的话,做为参考还是不错的: | ||
50 | - "The C Programming Language" by Kernighan and Ritchie [Prentice Hall] | ||
51 | 《C程序设计语言(第2版·新版)》(徐宝文 李志 译)[机械工业出版社] | ||
52 | - "Practical C Programming" by Steve Oualline [O'Reilly] | ||
53 | 《实用C语言编程(第三版)》(郭大海 译)[中国电力出版社] | ||
54 | - "C: A Reference Manual" by Harbison and Steele [Prentice Hall] | ||
55 | 《C语言参考手册(原书第5版)》(邱仲潘 等译)[机械工业出版社] | ||
56 | |||
57 | Linux内核使用GNU C和GNU工具链开发。虽然它遵循ISO C89标准,但也用到了一些 | ||
58 | 标准中没有定义的扩展。内核是自给自足的C环境,不依赖于标准C库的支持,所以 | ||
59 | 并不支持C标准中的部分定义。比如long long类型的大数除法和浮点运算就不允许 | ||
60 | 使用。有时候确实很难弄清楚内核对工具链的要求和它所使用的扩展,不幸的是目 | ||
61 | 前还没有明确的参考资料可以解释它们。请查阅gcc信息页(使用“info gcc”命令 | ||
62 | 显示)获得一些这方面信息。 | ||
63 | |||
64 | 请记住你是在学习怎么和已经存在的开发社区打交道。它由一群形形色色的人组成, | ||
65 | 他们对代码、风格和过程有着很高的标准。这些标准是在长期实践中总结出来的, | ||
66 | 适应于地理上分散的大型开发团队。它们已经被很好得整理成档,建议你在开发 | ||
67 | 之前尽可能多的学习这些标准,而不要期望别人来适应你或者你公司的行为方式。 | ||
68 | |||
69 | |||
70 | 法律问题 | ||
71 | -------- | ||
72 | |||
73 | Linux内核源代码都是在GPL(通用公共许可证)的保护下发布的。要了解这种许可 | ||
74 | 的细节请查看源代码主目录下的COPYING文件。如果你对它还有更深入问题请联系 | ||
75 | 律师,而不要在Linux内核邮件组上提问。因为邮件组里的人并不是律师,不要期 | ||
76 | 望他们的话有法律效力。 | ||
77 | |||
78 | 对于GPL的常见问题和解答,请访问以下链接: | ||
79 | http://www.gnu.org/licenses/gpl-faq.html | ||
80 | |||
81 | |||
82 | 文档 | ||
83 | ---- | ||
84 | |||
85 | Linux内核代码中包含有大量的文档。这些文档对于学习如何与内核社区互动有着 | ||
86 | 不可估量的价值。当一个新的功能被加入内核,最好把解释如何使用这个功能的文 | ||
87 | 档也放进内核。当内核的改动导致面向用户空间的接口发生变化时,最好将相关信 | ||
88 | 息或手册页(manpages)的补丁发到mtk-manpages@gmx.net,以向手册页(manpages) | ||
89 | 的维护者解释这些变化。 | ||
90 | |||
91 | 以下是内核代码中需要阅读的文档: | ||
92 | README | ||
93 | 文件简要介绍了Linux内核的背景,并且描述了如何配置和编译内核。内核的 | ||
94 | 新用户应该从这里开始。 | ||
95 | |||
96 | Documentation/Changes | ||
97 | 文件给出了用来编译和使用内核所需要的最小软件包列表。 | ||
98 | |||
99 | Documentation/CodingStyle | ||
100 | 描述Linux内核的代码风格和理由。所有新代码需要遵守这篇文档中定义的规 | ||
101 | 范。大多数维护者只会接收符合规定的补丁,很多人也只会帮忙检查符合风格 | ||
102 | 的代码。 | ||
103 | |||
104 | Documentation/SubmittingPatches | ||
105 | Documentation/SubmittingDrivers | ||
106 | 这两份文档明确描述如何创建和发送补丁,其中包括(但不仅限于): | ||
107 | - 邮件内容 | ||
108 | - 邮件格式 | ||
109 | - 选择收件人 | ||
110 | 遵守这些规定并不能保证提交成功(因为所有补丁需要通过严格的内容和风格 | ||
111 | 审查),但是忽视他们几乎就意味着失败。 | ||
112 | |||
113 | 其他关于如何正确地生成补丁的优秀文档包括: | ||
114 | "The Perfect Patch" | ||
115 | http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt | ||
116 | "Linux kernel patch submission format" | ||
117 | http://linux.yyz.us/patch-format.html | ||
118 | |||
119 | Documentation/stable_api_nonsense.txt | ||
120 | 论证内核为什么特意不包括稳定的内核内部API,也就是说不包括像这样的特 | ||
121 | 性: | ||
122 | - 子系统中间层(为了兼容性?) | ||
123 | - 在不同操作系统间易于移植的驱动程序 | ||
124 | - 减缓(甚至阻止)内核代码的快速变化 | ||
125 | 这篇文档对于理解Linux的开发哲学至关重要。对于将开发平台从其他操作系 | ||
126 | 统转移到Linux的人来说也很重要。 | ||
127 | |||
128 | Documentation/SecurityBugs | ||
129 | 如果你认为自己发现了Linux内核的安全性问题,请根据这篇文档中的步骤来 | ||
130 | 提醒其他内核开发者并帮助解决这个问题。 | ||
131 | |||
132 | Documentation/ManagementStyle | ||
133 | 描述内核维护者的工作方法及其共有特点。这对于刚刚接触内核开发(或者对 | ||
134 | 它感到好奇)的人来说很重要,因为它解释了很多对于内核维护者独特行为的 | ||
135 | 普遍误解与迷惑。 | ||
136 | |||
137 | Documentation/stable_kernel_rules.txt | ||
138 | 解释了稳定版内核发布的规则,以及如何将改动放入这些版本的步骤。 | ||
139 | |||
140 | Documentation/kernel-docs.txt | ||
141 | 有助于内核开发的外部文档列表。如果你在内核自带的文档中没有找到你想找 | ||
142 | 的内容,可以查看这些文档。 | ||
143 | |||
144 | Documentation/applying-patches.txt | ||
145 | 关于补丁是什么以及如何将它打在不同内核开发分支上的好介绍 | ||
146 | |||
147 | 内核还拥有大量从代码自动生成的文档。它包含内核内部API的全面介绍以及如何 | ||
148 | 妥善处理加锁的规则。生成的文档会放在 Documentation/DocBook/目录下。在内 | ||
149 | 核源码的主目录中使用以下不同命令将会分别生成PDF、Postscript、HTML和手册 | ||
150 | 页等不同格式的文档: | ||
151 | make pdfdocs | ||
152 | make psdocs | ||
153 | make htmldocs | ||
154 | make mandocs | ||
155 | |||
156 | |||
157 | 如何成为内核开发者 | ||
158 | ------------------ | ||
159 | 如果你对Linux内核开发一无所知,你应该访问“Linux内核新手”计划: | ||
160 | http://kernelnewbies.org | ||
161 | 它拥有一个可以问各种最基本的内核开发问题的邮件列表(在提问之前一定要记得 | ||
162 | 查找已往的邮件,确认是否有人已经回答过相同的问题)。它还拥有一个可以获得 | ||
163 | 实时反馈的IRC聊天频道,以及大量对于学习Linux内核开发相当有帮助的文档。 | ||
164 | |||
165 | 网站简要介绍了源代码组织结构、子系统划分以及目前正在进行的项目(包括内核 | ||
166 | 中的和单独维护的)。它还提供了一些基本的帮助信息,比如如何编译内核和打补 | ||
167 | 丁。 | ||
168 | |||
169 | 如果你想加入内核开发社区并协助完成一些任务,却找不到从哪里开始,可以访问 | ||
170 | “Linux内核房管员”计划: | ||
171 | http://janitor.kernelnewbies.org/ | ||
172 | 这是极佳的起点。它提供一个相对简单的任务列表,列出内核代码中需要被重新 | ||
173 | 整理或者改正的地方。通过和负责这个计划的开发者们一同工作,你会学到将补丁 | ||
174 | 集成进内核的基本原理。如果还没有决定下一步要做什么的话,你还可能会得到方 | ||
175 | 向性的指点。 | ||
176 | |||
177 | 如果你已经有一些现成的代码想要放到内核中,但是需要一些帮助来使它们拥有正 | ||
178 | 确的格式。请访问“内核导师”计划。这个计划就是用来帮助你完成这个目标的。它 | ||
179 | 是一个邮件列表,地址如下: | ||
180 | http://selenic.com/mailman/listinfo/kernel-mentors | ||
181 | |||
182 | 在真正动手修改内核代码之前,理解要修改的代码如何运作是必需的。要达到这个 | ||
183 | 目的,没什么办法比直接读代码更有效了(大多数花招都会有相应的注释),而且 | ||
184 | 一些特制的工具还可以提供帮助。例如,“Linux代码交叉引用”项目就是一个值得 | ||
185 | 特别推荐的帮助工具,它将源代码显示在有编目和索引的网页上。其中一个更新及 | ||
186 | 时的内核源码库,可以通过以下地址访问: | ||
187 | http://sosdg.org/~coywolf/lxr/ | ||
188 | |||
189 | |||
190 | 开发流程 | ||
191 | -------- | ||
192 | |||
193 | 目前Linux内核开发流程包括几个“主内核分支”和很多子系统相关的内核分支。这 | ||
194 | 些分支包括: | ||
195 | - 2.6.x主内核源码树 | ||
196 | - 2.6.x.y -stable内核源码树 | ||
197 | - 2.6.x -git内核补丁集 | ||
198 | - 2.6.x -mm内核补丁集 | ||
199 | - 子系统相关的内核源码树和补丁集 | ||
200 | |||
201 | |||
202 | 2.6.x内核主源码树 | ||
203 | ----------------- | ||
204 | 2.6.x内核是由Linus Torvalds(Linux的创造者)亲自维护的。你可以在 | ||
205 | kernel.org网站的pub/linux/kernel/v2.6/目录下找到它。它的开发遵循以下步 | ||
206 | 骤: | ||
207 | - 每当一个新版本的内核被发布,为期两周的集成窗口将被打开。在这段时间里 | ||
208 | 维护者可以向Linus提交大段的修改,通常这些修改已经被放到-mm内核中几个 | ||
209 | 星期了。提交大量修改的首选方式是使用git工具(内核的代码版本管理工具 | ||
210 | ,更多的信息可以在http://git.or.cz/获取),不过使用普通补丁也是可以 | ||
211 | 的。 | ||
212 | - 两个星期以后-rc1版本内核发布。之后只有不包含可能影响整个内核稳定性的 | ||
213 | 新功能的补丁才可能被接受。请注意一个全新的驱动程序(或者文件系统)有 | ||
214 | 可能在-rc1后被接受是因为这样的修改完全独立,不会影响其他的代码,所以 | ||
215 | 没有造成内核退步的风险。在-rc1以后也可以用git向Linus提交补丁,不过所 | ||
216 | 有的补丁需要同时被发送到相应的公众邮件列表以征询意见。 | ||
217 | - 当Linus认为当前的git源码树已经达到一个合理健全的状态足以发布供人测试 | ||
218 | 时,一个新的-rc版本就会被发布。计划是每周都发布新的-rc版本。 | ||
219 | - 这个过程一直持续下去直到内核被认为达到足够稳定的状态,持续时间大概是 | ||
220 | 6个星期。 | ||
221 | |||
222 | 关于内核发布,值得一提的是Andrew Morton在linux-kernel邮件列表中如是说: | ||
223 | “没有人知道新内核何时会被发布,因为发布是根据已知bug的情况来决定 | ||
224 | 的,而不是根据一个事先制定好的时间表。” | ||
225 | |||
226 | |||
227 | 2.6.x.y -stable(稳定版)内核源码树 | ||
228 | ----------------------------------- | ||
229 | 由4个数字组成的内核版本号说明此内核是-stable版本。它们包含基于2.6.x版本 | ||
230 | 内核的相对较小且至关重要的修补,这些修补针对安全性问题或者严重的内核退步。 | ||
231 | |||
232 | 这种版本的内核适用于那些期望获得最新的稳定版内核并且不想参与测试开发版或 | ||
233 | 者实验版的用户。 | ||
234 | |||
235 | 如果没有2.6.x.y版本内核存在,那么最新的2.6.x版本内核就相当于是当前的稳定 | ||
236 | 版内核。 | ||
237 | |||
238 | 2.6.x.y版本由“稳定版”小组(邮件地址<stable@kernel.org>)维护,一般隔周发 | ||
239 | 布新版本。 | ||
240 | |||
241 | 内核源码中的Documentation/stable_kernel_rules.txt文件具体描述了可被稳定 | ||
242 | 版内核接受的修改类型以及发布的流程。 | ||
243 | |||
244 | |||
245 | 2.6.x -git补丁集 | ||
246 | ---------------- | ||
247 | Linus的内核源码树的每日快照,这个源码树是由git工具管理的(由此得名)。这 | ||
248 | 些补丁通常每天更新以反映Linus的源码树的最新状态。它们比-rc版本的内核源码 | ||
249 | 树更具试验性质,因为这个补丁集是全自动生成的,没有任何人来确认其是否真正 | ||
250 | 健全。 | ||
251 | |||
252 | |||
253 | 2.6.x -mm补丁集 | ||
254 | --------------- | ||
255 | 这是由Andrew Morton维护的试验性内核补丁集。Andrew将所有子系统的内核源码 | ||
256 | 和补丁拼凑到一起,并且加入了大量从linux-kernel邮件列表中采集的补丁。这个 | ||
257 | 源码树是新功能和补丁的试炼场。当补丁在-mm补丁集里证明了其价值以后Andrew | ||
258 | 或者相应子系统的维护者会将补丁发给Linus以便集成进主内核源码树。 | ||
259 | |||
260 | 在将所有新补丁发给Linus以集成到主内核源码树之前,我们非常鼓励先把这些补 | ||
261 | 丁放在-mm版内核源码树中进行测试。 | ||
262 | |||
263 | 这些内核版本不适合在需要稳定运行的系统上运行,因为运行它们比运行任何其他 | ||
264 | 内核分支都更具有风险。 | ||
265 | |||
266 | 如果你想为内核开发进程提供帮助,请尝试并使用这些内核版本,并在 | ||
267 | linux-kernel邮件列表中提供反馈,告诉大家你遇到了问题还是一切正常。 | ||
268 | |||
269 | 通常-mm版补丁集不光包括这些额外的试验性补丁,还包括发布时-git版主源码树 | ||
270 | 中的改动。 | ||
271 | |||
272 | -mm版内核没有固定的发布周期,但是通常在每两个-rc版内核发布之间都会有若干 | ||
273 | 个-mm版内核发布(一般是1至3个)。 | ||
274 | |||
275 | |||
276 | 子系统相关内核源码树和补丁集 | ||
277 | ---------------------------- | ||
278 | 相当一部分内核子系统开发者会公开他们自己的开发源码树,以便其他人能了解内 | ||
279 | 核的不同领域正在发生的事情。如上所述,这些源码树会被集成到-mm版本内核中。 | ||
280 | |||
281 | 下面是目前可用的一些内核源码树的列表: | ||
282 | 通过git管理的源码树: | ||
283 | - Kbuild开发源码树, Sam Ravnborg <sam@ravnborg.org> | ||
284 | git.kernel.org:/pub/scm/linux/kernel/git/sam/kbuild.git | ||
285 | |||
286 | - ACPI开发源码树, Len Brown <len.brown@intel.com> | ||
287 | git.kernel.org:/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6.git | ||
288 | |||
289 | - 块设备开发源码树, Jens Axboe <axboe@suse.de> | ||
290 | git.kernel.org:/pub/scm/linux/kernel/git/axboe/linux-2.6-block.git | ||
291 | |||
292 | - DRM开发源码树, Dave Airlie <airlied@linux.ie> | ||
293 | git.kernel.org:/pub/scm/linux/kernel/git/airlied/drm-2.6.git | ||
294 | |||
295 | - ia64开发源码树, Tony Luck <tony.luck@intel.com> | ||
296 | git.kernel.org:/pub/scm/linux/kernel/git/aegl/linux-2.6.git | ||
297 | |||
298 | - ieee1394开发源码树, Jody McIntyre <scjody@modernduck.com> | ||
299 | git.kernel.org:/pub/scm/linux/kernel/git/scjody/ieee1394.git | ||
300 | |||
301 | - infiniband开发源码树, Roland Dreier <rolandd@cisco.com> | ||
302 | git.kernel.org:/pub/scm/linux/kernel/git/roland/infiniband.git | ||
303 | |||
304 | - libata开发源码树, Jeff Garzik <jgarzik@pobox.com> | ||
305 | git.kernel.org:/pub/scm/linux/kernel/git/jgarzik/libata-dev.git | ||
306 | |||
307 | - 网络驱动程序开发源码树, Jeff Garzik <jgarzik@pobox.com> | ||
308 | git.kernel.org:/pub/scm/linux/kernel/git/jgarzik/netdev-2.6.git | ||
309 | |||
310 | - pcmcia开发源码树, Dominik Brodowski <linux@dominikbrodowski.net> | ||
311 | git.kernel.org:/pub/scm/linux/kernel/git/brodo/pcmcia-2.6.git | ||
312 | |||
313 | - SCSI开发源码树, James Bottomley <James.Bottomley@SteelEye.com> | ||
314 | git.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git | ||
315 | |||
316 | 使用quilt管理的补丁集: | ||
317 | - USB, PCI, 驱动程序核心和I2C, Greg Kroah-Hartman <gregkh@suse.de> | ||
318 | kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/ | ||
319 | - x86-64, 部分i386, Andi Kleen <ak@suse.de> | ||
320 | ftp.firstfloor.org:/pub/ak/x86_64/quilt/ | ||
321 | |||
322 | 其他内核源码树可以在http://git.kernel.org的列表中和MAINTAINERS文件里 | ||
323 | 找到。 | ||
324 | |||
325 | 报告bug | ||
326 | ------- | ||
327 | |||
328 | bugzilla.kernel.org是Linux内核开发者们用来跟踪内核Bug的网站。我们鼓励用 | ||
329 | 户在这个工具中报告找到的所有bug。如何使用内核bugzilla的细节请访问: | ||
330 | http://test.kernel.org/bugzilla/faq.html | ||
331 | |||
332 | 内核源码主目录中的REPORTING-BUGS文件里有一个很好的模板。它指导用户如何报 | ||
333 | 告可能的内核bug以及需要提供哪些信息来帮助内核开发者们找到问题的根源。 | ||
334 | |||
335 | |||
336 | 利用bug报告 | ||
337 | ----------- | ||
338 | |||
339 | 练习内核开发技能的最好办法就是修改其他人报告的bug。你不光可以帮助内核变 | ||
340 | 得更加稳定,还可以学会如何解决实际问题从而提高自己的技能,并且让其他开发 | ||
341 | 者感受到你的存在。修改bug是赢得其他开发者赞誉的最好办法,因为并不是很多 | ||
342 | 人都喜欢浪费时间去修改别人报告的bug。 | ||
343 | |||
344 | 要尝试修改已知的bug,请访问http://bugzilla.kernel.org网址。如果你想获得 | ||
345 | 最新bug的通知,可以订阅bugme-new邮件列表(只有新的bug报告会被寄到这里) | ||
346 | 或者订阅bugme-janitor邮件列表(所有bugzilla的变动都会被寄到这里)。 | ||
347 | |||
348 | http://lists.osdl.org/mailman/listinfo/bugme-new | ||
349 | http://lists.osdl.org/mailman/listinfo/bugme-janitors | ||
350 | |||
351 | |||
352 | 邮件列表 | ||
353 | -------- | ||
354 | |||
355 | 正如上面的文档所描述,大多数的骨干内核开发者都加入了Linux Kernel邮件列 | ||
356 | 表。如何订阅和退订列表的细节可以在这里找到: | ||
357 | http://vger.kernel.org/vger-lists.html#linux-kernel | ||
358 | 网上很多地方都有这个邮件列表的存档(archive)。可以使用搜索引擎来找到这些 | ||
359 | 存档。比如: | ||
360 | http://dir.gmane.org/gmane.linux.kernel | ||
361 | 在发信之前,我们强烈建议你先在存档中搜索你想要讨论的问题。很多已经被详细 | ||
362 | 讨论过的问题只在邮件列表的存档中可以找到。 | ||
363 | |||
364 | 大多数内核子系统也有自己独立的邮件列表来协调各自的开发工作。从 | ||
365 | MAINTAINERS文件中可以找到不同话题对应的邮件列表。 | ||
366 | |||
367 | 很多邮件列表架设在kernel.org服务器上。这些列表的信息可以在这里找到: | ||
368 | http://vger.kernel.org/vger-lists.html | ||
369 | |||
370 | 在使用这些邮件列表时,请记住保持良好的行为习惯。下面的链接提供了与这些列 | ||
371 | 表(或任何其它邮件列表)交流的一些简单规则,虽然内容有点滥竽充数。 | ||
372 | http://www.albion.com/netiquette/ | ||
373 | |||
374 | 当有很多人回复你的邮件时,邮件的抄送列表会变得很长。请不要将任何人从抄送 | ||
375 | 列表中删除,除非你有足够的理由这么做。也不要只回复到邮件列表。请习惯于同 | ||
376 | 一封邮件接收两次(一封来自发送者一封来自邮件列表),而不要试图通过添加一 | ||
377 | 些奇特的邮件头来解决这个问题,人们不会喜欢的。 | ||
378 | |||
379 | 记住保留你所回复内容的上下文和源头。在你回复邮件的顶部保留“某某某说到……” | ||
380 | 这几行。将你的评论加在被引用的段落之间而不要放在邮件的顶部。 | ||
381 | |||
382 | 如果你在邮件中附带补丁,请确认它们是可以直接阅读的纯文本(如 | ||
383 | Documentation/SubmittingPatches文档中所述)。内核开发者们不希望遇到附件 | ||
384 | 或者被压缩了的补丁。只有这样才能保证他们可以直接评论你的每行代码。请确保 | ||
385 | 你使用的邮件发送程序不会修改空格和制表符。一个防范性的测试方法是先将邮件 | ||
386 | 发送给自己,然后自己尝试是否可以顺利地打上收到的补丁。如果测试不成功,请 | ||
387 | 调整或者更换你的邮件发送程序直到它正确工作为止。 | ||
388 | |||
389 | 总而言之,请尊重其他的邮件列表订阅者。 | ||
390 | |||
391 | |||
392 | 同内核社区合作 | ||
393 | ---------------- | ||
394 | |||
395 | 内核社区的目标就是提供尽善尽美的内核。所以当你提交补丁期望被接受进内核的 | ||
396 | 时候,它的技术价值以及其他方面都将被评审。那么你可能会得到什么呢? | ||
397 | - 批评 | ||
398 | - 评论 | ||
399 | - 要求修改 | ||
400 | - 要求证明修改的必要性 | ||
401 | - 沉默 | ||
402 | |||
403 | 要记住,这些是把补丁放进内核的正常情况。你必须学会听取对补丁的批评和评论, | ||
404 | 从技术层面评估它们,然后要么重写你的补丁要么简明扼要地论证修改是不必要 | ||
405 | 的。如果你发的邮件没有得到任何回应,请过几天后再试一次,因为有时信件会湮 | ||
406 | 没在茫茫信海中。 | ||
407 | |||
408 | 你不应该做的事情: | ||
409 | - 期望自己的补丁不受任何质疑就直接被接受 | ||
410 | - 翻脸 | ||
411 | - 忽略别人的评论 | ||
412 | - 没有按照别人的要求做任何修改就重新提交 | ||
413 | |||
414 | 在一个努力追寻最好技术方案的社区里,对于一个补丁有多少好处总会有不同的见 | ||
415 | 解。你必须要抱着合作的态度,愿意改变自己的观点来适应内核的风格。或者至少 | ||
416 | 愿意去证明你的想法是有价值的。记住,犯错误是允许的,只要你愿意朝着正确的 | ||
417 | 方案去努力。 | ||
418 | |||
419 | 如果你的第一个补丁换来的是一堆修改建议,这是很正常的。这并不代表你的补丁 | ||
420 | 不会被接受,也不意味着有人和你作对。你只需要改正所有提出的问题然后重新发 | ||
421 | 送你的补丁。 | ||
422 | |||
423 | 内核社区和公司文化的差异 | ||
424 | ------------------------ | ||
425 | |||
426 | 内核社区的工作模式同大多数传统公司开发队伍的工作模式并不相同。下面这些例 | ||
427 | 子,可以帮助你避免某些可能发生问题: | ||
428 | 用这些话介绍你的修改提案会有好处: | ||
429 | - 它同时解决了多个问题 | ||
430 | - 它删除了2000行代码 | ||
431 | - 这是补丁,它已经解释了我想要说明的 | ||
432 | - 我在5种不同的体系结构上测试过它…… | ||
433 | - 这是一系列小补丁用来…… | ||
434 | - 这个修改提高了普通机器的性能…… | ||
435 | |||
436 | 应该避免如下的说法: | ||
437 | - 我们在AIX/ptx/Solaris就是这么做的,所以这么做肯定是好的…… | ||
438 | - 我做这行已经20年了,所以…… | ||
439 | - 为了我们公司赚钱考虑必须这么做 | ||
440 | - 这是我们的企业产品线所需要的 | ||
441 | - 这里是描述我观点的1000页设计文档 | ||
442 | - 这是一个5000行的补丁用来…… | ||
443 | - 我重写了现在乱七八糟的代码,这就是…… | ||
444 | - 我被规定了最后期限,所以这个补丁需要立刻被接受 | ||
445 | |||
446 | 另外一个内核社区与大部分传统公司的软件开发队伍不同的地方是无法面对面地交 | ||
447 | 流。使用电子邮件和IRC聊天工具做为主要沟通工具的一个好处是性别和种族歧视 | ||
448 | 将会更少。Linux内核的工作环境更能接受妇女和少数族群,因为每个人在别人眼 | ||
449 | 里只是一个邮件地址。国际化也帮助了公平的实现,因为你无法通过姓名来判断人 | ||
450 | 的性别。男人有可能叫李丽,女人也有可能叫王刚。大多数在Linux内核上工作过 | ||
451 | 并表达过看法的女性对在linux上工作的经历都给出了正面的评价。 | ||
452 | |||
453 | 对于一些不习惯使用英语的人来说,语言可能是一个引起问题的障碍。在邮件列表 | ||
454 | 中要正确地表达想法必需良好地掌握语言,所以建议你在发送邮件之前最好检查一 | ||
455 | 下英文写得是否正确。 | ||
456 | |||
457 | |||
458 | 拆分修改 | ||
459 | -------- | ||
460 | |||
461 | Linux内核社区并不喜欢一下接收大段的代码。修改需要被恰当地介绍、讨论并且 | ||
462 | 拆分成独立的小段。这几乎完全和公司中的习惯背道而驰。你的想法应该在开发最 | ||
463 | 开始的阶段就让大家知道,这样你就可以及时获得对你正在进行的开发的反馈。这 | ||
464 | 样也会让社区觉得你是在和他们协作,而不是仅仅把他们当作倾销新功能的对象。 | ||
465 | 无论如何,你不要一次性地向邮件列表发送50封信,你的补丁序列应该永远用不到 | ||
466 | 这么多。 | ||
467 | |||
468 | 将补丁拆开的原因如下: | ||
469 | |||
470 | 1) 小的补丁更有可能被接受,因为它们不需要太多的时间和精力去验证其正确性。 | ||
471 | 一个5行的补丁,可能在维护者看了一眼以后就会被接受。而500行的补丁则 | ||
472 | 需要数个小时来审查其正确性(所需时间随补丁大小增加大约呈指数级增长)。 | ||
473 | |||
474 | 当出了问题的时候,小的补丁也会让调试变得非常容易。一个一个补丁地回溯 | ||
475 | 将会比仔细剖析一个被打上的大补丁(这个补丁破坏了其他东西)容易得多。 | ||
476 | |||
477 | 2)不光发送小的补丁很重要,在提交之前重新编排、化简(或者仅仅重新排列) | ||
478 | 补丁也是很重要的。 | ||
479 | |||
480 | 这里有内核开发者Al Viro打的一个比方: | ||
481 | “想象一个老师正在给学生批改数学作业。老师并不希望看到学生为了得 | ||
482 | 到正确解法所进行的尝试和产生的错误。他希望看到的是最干净最优雅的 | ||
483 | 解答。好学生了解这点,绝不会把最终解决之前的中间方案提交上去。” | ||
484 | |||
485 | 内核开发也是这样。维护者和评审者不希望看到一个人在解决问题时的思 | ||
486 | 考过程。他们只希望看到简单和优雅的解决方案。 | ||
487 | |||
488 | 直接给出一流的解决方案,和社区一起协作讨论尚未完成的工作,这两者之间似乎 | ||
489 | 很难找到一个平衡点。所以最好尽早开始收集有利于你进行改进的反馈;同时也要 | ||
490 | 保证修改分成很多小块,这样在整个项目都准备好被包含进内核之前,其中的一部 | ||
491 | 分可能会先被接收。 | ||
492 | |||
493 | 必须了解这样做是不可接受的:试图将未完成的工作提交进内核,然后再找时间修 | ||
494 | 复。 | ||
495 | |||
496 | |||
497 | 证明修改的必要性 | ||
498 | ---------------- | ||
499 | 除了将补丁拆成小块,很重要的一点是让Linux社区了解他们为什么需要这样修改。 | ||
500 | 你必须证明新功能是有人需要的并且是有用的。 | ||
501 | |||
502 | |||
503 | 记录修改 | ||
504 | -------- | ||
505 | |||
506 | 当你发送补丁的时候,需要特别留意邮件正文的内容。因为这里的信息将会做为补 | ||
507 | 丁的修改记录(ChangeLog),会被一直保留以备大家查阅。它需要完全地描述补丁, | ||
508 | 包括: | ||
509 | - 为什么需要这个修改 | ||
510 | - 补丁的总体设计 | ||
511 | - 实现细节 | ||
512 | - 测试结果 | ||
513 | |||
514 | 想了解它具体应该看起来像什么,请查阅以下文档中的“ChangeLog”章节: | ||
515 | “The Perfect Patch” | ||
516 | http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt | ||
517 | |||
518 | |||
519 | 这些事情有时候做起来很难。要在任何方面都做到完美可能需要好几年时间。这是 | ||
520 | 一个持续提高的过程,它需要大量的耐心和决心。只要不放弃,你一定可以做到。 | ||
521 | 很多人已经做到了,而他们都曾经和现在的你站在同样的起点上。 | ||
522 | |||
523 | |||
524 | --------------- | ||
525 | 感谢Paolo Ciarrocchi允许“开发流程”部分基于他所写的文章 | ||
526 | (http://linux.tar.bz/articles/2.6-development_process),感谢Randy | ||
527 | Dunlap和Gerrit Huizenga完善了应该说和不该说的列表。感谢Pat Mochel, Hanna | ||
528 | Linder, Randy Dunlap, Kay Sievers, Vojtech Pavlik, Jan Kara, Josh Boyer, | ||
529 | Kees Cook, Andrew Morton, Andi Kleen, Vadim Lobanov, Jesper Juhl, Adrian | ||
530 | Bunk, Keri Harris, Frans Pop, David A. Wheeler, Junio Hamano, Michael | ||
531 | Kerrisk和Alex Shepard的评审、建议和贡献。没有他们的帮助,这篇文档是不可 | ||
532 | 能完成的。 | ||
533 | |||
534 | |||
535 | |||
536 | 英文版维护者: Greg Kroah-Hartman <greg@kroah.com> | ||
diff --git a/Documentation/zh_CN/stable_api_nonsense.txt b/Documentation/zh_CN/stable_api_nonsense.txt new file mode 100644 index 000000000000..c26a27d1ee7d --- /dev/null +++ b/Documentation/zh_CN/stable_api_nonsense.txt | |||
@@ -0,0 +1,157 @@ | |||
1 | Chinese translated version of Documentation/stable_api_nonsense.txt | ||
2 | |||
3 | If you have any comment or update to the content, please contact the | ||
4 | original document maintainer directly. However, if you have problem | ||
5 | communicating in English you can also ask the Chinese maintainer for help. | ||
6 | Contact the Chinese maintainer, if this translation is outdated or there | ||
7 | is problem with translation. | ||
8 | |||
9 | Maintainer: Greg Kroah-Hartman <greg@kroah.com> | ||
10 | Chinese maintainer: TripleX Chung <zhongyu@18mail.cn> | ||
11 | --------------------------------------------------------------------- | ||
12 | Documentation/stable_api_nonsense.txt 的中文翻译 | ||
13 | |||
14 | 如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文 | ||
15 | 交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻 | ||
16 | 译存在问题,请联系中文版维护者。 | ||
17 | |||
18 | 英文版维护者: Greg Kroah-Hartman <greg@kroah.com> | ||
19 | 中文版维护者: 钟宇 TripleX Chung <zhongyu@18mail.cn> | ||
20 | 中文版翻译者: 钟宇 TripleX Chung <zhongyu@18mail.cn> | ||
21 | 中文版校译者: 李阳 Li Yang <leoli@freescale.com> | ||
22 | 以下为正文 | ||
23 | --------------------------------------------------------------------- | ||
24 | |||
25 | 写作本文档的目的,是为了解释为什么Linux既没有二进制内核接口,也没有稳定 | ||
26 | 的内核接口。这里所说的内核接口,是指内核里的接口,而不是内核和用户空间 | ||
27 | 的接口。内核到用户空间的接口,是提供给应用程序使用的系统调用,系统调用 | ||
28 | 在历史上几乎没有过变化,将来也不会有变化。我有一些老应用程序是在0.9版本 | ||
29 | 或者更早版本的内核上编译的,在使用2.6版本内核的Linux发布上依然用得很好 | ||
30 | 。用户和应用程序作者可以将这个接口看成是稳定的。 | ||
31 | |||
32 | |||
33 | 执行纲要 | ||
34 | -------- | ||
35 | |||
36 | 你也许以为自己想要稳定的内核接口,但是你不清楚你要的实际上不是它。你需 | ||
37 | 要的其实是稳定的驱动程序,而你只有将驱动程序放到公版内核的源代码树里, | ||
38 | 才有可能达到这个目的。而且这样做还有很多其它好处,正是因为这些好处使得 | ||
39 | Linux能成为强壮,稳定,成熟的操作系统,这也是你最开始选择Linux的原因。 | ||
40 | |||
41 | |||
42 | 入门 | ||
43 | ----- | ||
44 | |||
45 | 只有那些写驱动程序的“怪人”才会担心内核接口的改变,对广大用户来说,既 | ||
46 | 看不到内核接口,也不需要去关心它。 | ||
47 | |||
48 | 首先,我不打算讨论关于任何非GPL许可的内核驱动的法律问题,这些非GPL许可 | ||
49 | 的驱动程序包括不公开源代码,隐藏源代码,二进制或者是用源代码包装,或者 | ||
50 | 是其它任何形式的不能以GPL许可公开源代码的驱动程序。如果有法律问题,请咨 | ||
51 | 询律师,我只是一个程序员,所以我只打算探讨技术问题(不是小看法律问题, | ||
52 | 法律问题很实际,并且需要一直关注)。 | ||
53 | |||
54 | 既然只谈技术问题,我们就有了下面两个主题:二进制内核接口和稳定的内核源 | ||
55 | 代码接口。这两个问题是互相关联的,让我们先解决掉二进制接口的问题。 | ||
56 | |||
57 | |||
58 | 二进制内核接口 | ||
59 | -------------- | ||
60 | 假如我们有一个稳定的内核源代码接口,那么自然而然的,我们就拥有了稳定的 | ||
61 | 二进制接口,是这样的吗?错。让我们看看关于Linux内核的几点事实: | ||
62 | - 取决于所用的C编译器的版本,不同的内核数据结构里的结构体的对齐方 | ||
63 | 式会有差别,代码中不同函数的表现形式也不一样(函数是不是被inline编译取 | ||
64 | 决于编译器行为)。不同的函数的表现形式并不重要,但是数据结构内部的对齐 | ||
65 | 方式很关键。 | ||
66 | - 取决于内核的配置选项,不同的选项会让内核的很多东西发生改变: | ||
67 | - 同一个结构体可能包含不同的成员变量 | ||
68 | - 有的函数可能根本不会被实现(比如编译的时候没有选择SMP支持 | ||
69 | ,一些锁函数就会被定义成空函数)。 | ||
70 | - 内核使用的内存会以不同的方式对齐,这取决于不同的内核配置选 | ||
71 | 项。 | ||
72 | - Linux可以在很多的不同体系结构的处理器上运行。在某个体系结构上编 | ||
73 | 译好的二进制驱动程序,不可能在另外一个体系结构上正确的运行。 | ||
74 | |||
75 | 对于一个特定的内核,满足这些条件并不难,使用同一个C编译器和同样的内核配 | ||
76 | 置选项来编译驱动程序模块就可以了。这对于给一个特定Linux发布的特定版本提 | ||
77 | 供驱动程序,是完全可以满足需求的。但是如果你要给不同发布的不同版本都发 | ||
78 | 布一个驱动程序,就需要在每个发布上用不同的内核设置参数都编译一次内核, | ||
79 | 这简直跟噩梦一样。而且还要注意到,每个Linux发布还提供不同的Linux内核, | ||
80 | 这些内核都针对不同的硬件类型进行了优化(有很多种不同的处理器,还有不同 | ||
81 | 的内核设置选项)。所以每发布一次驱动程序,都需要提供很多不同版本的内核 | ||
82 | 模块。 | ||
83 | |||
84 | 相信我,如果你真的要采取这种发布方式,一定会慢慢疯掉,我很久以前就有过 | ||
85 | 深刻的教训... | ||
86 | |||
87 | |||
88 | 稳定的内核源代码接口 | ||
89 | -------------------- | ||
90 | |||
91 | 如果有人不将他的内核驱动程序,放入公版内核的源代码树,而又想让驱动程序 | ||
92 | 一直保持在最新的内核中可用,那么这个话题将会变得没完没了。 | ||
93 | 内核开发是持续而且快节奏的,从来都不会慢下来。内核开发人员在当前接口中 | ||
94 | 找到bug,或者找到更好的实现方式。一旦发现这些,他们就很快会去修改当前的 | ||
95 | 接口。修改接口意味着,函数名可能会改变,结构体可能被扩充或者删减,函数 | ||
96 | 的参数也可能发生改变。一旦接口被修改,内核中使用这些接口的地方需要同时 | ||
97 | 修正,这样才能保证所有的东西继续工作。 | ||
98 | |||
99 | 举一个例子,内核的USB驱动程序接口在USB子系统的整个生命周期中,至少经历 | ||
100 | 了三次重写。这些重写解决以下问题: | ||
101 | - 把数据流从同步模式改成非同步模式,这个改动减少了一些驱动程序的 | ||
102 | 复杂度,提高了所有USB驱动程序的吞吐率,这样几乎所有的USB设备都能以最大 | ||
103 | 速率工作了。 | ||
104 | - 修改了USB核心代码中为USB驱动分配数据包内存的方式,所有的驱动都 | ||
105 | 需要提供更多的参数给USB核心,以修正了很多已经被记录在案的死锁。 | ||
106 | |||
107 | 这和一些封闭源代码的操作系统形成鲜明的对比,在那些操作系统上,不得不额 | ||
108 | 外的维护旧的USB接口。这导致了一个可能性,新的开发者依然会不小心使用旧的 | ||
109 | 接口,以不恰当的方式编写代码,进而影响到操作系统的稳定性。 | ||
110 | 在上面的例子中,所有的开发者都同意这些重要的改动,在这样的情况下修改代 | ||
111 | 价很低。如果Linux保持一个稳定的内核源代码接口,那么就得创建一个新的接口 | ||
112 | ;旧的,有问题的接口必须一直维护,给Linux USB开发者带来额外的工作。既然 | ||
113 | 所有的Linux USB驱动的作者都是利用自己的时间工作,那么要求他们去做毫无意 | ||
114 | 义的免费额外工作,是不可能的。 | ||
115 | 安全问题对Linux来说十分重要。一个安全问题被发现,就会在短时间内得到修 | ||
116 | 正。在很多情况下,这将导致Linux内核中的一些接口被重写,以从根本上避免安 | ||
117 | 全问题。一旦接口被重写,所有使用这些接口的驱动程序,必须同时得到修正, | ||
118 | 以确定安全问题已经得到修复并且不可能在未来还有同样的安全问题。如果内核 | ||
119 | 内部接口不允许改变,那么就不可能修复这样的安全问题,也不可能确认这样的 | ||
120 | 安全问题以后不会发生。 | ||
121 | 开发者一直在清理内核接口。如果一个接口没有人在使用了,它就会被删除。这 | ||
122 | 样可以确保内核尽可能的小,而且所有潜在的接口都会得到尽可能完整的测试 | ||
123 | (没有人使用的接口是不可能得到良好的测试的)。 | ||
124 | |||
125 | |||
126 | 要做什么 | ||
127 | ------- | ||
128 | |||
129 | 如果你写了一个Linux内核驱动,但是它还不在Linux源代码树里,作为一个开发 | ||
130 | 者,你应该怎么做?为每个发布的每个版本提供一个二进制驱动,那简直是一个 | ||
131 | 噩梦,要跟上永远处于变化之中的内核接口,也是一件辛苦活。 | ||
132 | 很简单,让你的驱动进入内核源代码树(要记得我们在谈论的是以GPL许可发行 | ||
133 | 的驱动,如果你的代码不符合GPL,那么祝你好运,你只能自己解决这个问题了, | ||
134 | 你这个吸血鬼<把Andrew和Linus对吸血鬼的定义链接到这里>)。当你的代码加入 | ||
135 | 公版内核源代码树之后,如果一个内核接口改变,你的驱动会直接被修改接口的 | ||
136 | 那个人修改。保证你的驱动永远都可以编译通过,并且一直工作,你几乎不需要 | ||
137 | 做什么事情。 | ||
138 | |||
139 | 把驱动放到内核源代码树里会有很多的好处: | ||
140 | - 驱动的质量会提升,而维护成本(对原始作者来说)会下降。 | ||
141 | - 其他人会给驱动添加新特性。 | ||
142 | - 其他人会找到驱动中的bug并修复。 | ||
143 | - 其他人会在驱动中找到性能优化的机会。 | ||
144 | - 当外部的接口的改变需要修改驱动程序的时候,其他人会修改驱动程序 | ||
145 | 。 | ||
146 | - 不需要联系任何发行商,这个驱动会自动的随着所有的Linux发布一起发 | ||
147 | 布。 | ||
148 | |||
149 | 和别的操作系统相比,Linux为更多不同的设备提供现成的驱动,而且能在更多不 | ||
150 | 同体系结构的处理器上支持这些设备。这个经过考验的开发模式,必然是错不了 | ||
151 | 的 :) | ||
152 | |||
153 | ------------- | ||
154 | 感谢 Randy Dunlap, Andrew Morton, David Brownell, Hanna Linder, | ||
155 | Robert Love, and Nishanth Aravamudan 对于本文档早期版本的评审和建议。 | ||
156 | |||
157 | 英文版维护者: Greg Kroah-Hartman <greg@kroah.com> | ||