Advertisement
Guest User

Eudyptula Challenge

a guest
Aug 27th, 2019
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.19 KB | None | 0 0
  1. This is Task 01 of the Eudyptula Challenge
  2. ------------------------------------------
  3.  
  4. Write a Linux kernel module, and stand-alone Makefile, that when loaded
  5. prints to the kernel debug log level, "Hello World!" Be sure to make
  6. the module be able to be unloaded as well.
  7.  
  8. The Makefile should build the kernel module against the source for the
  9. currently running kernel, or, use an environment variable to specify
  10. what kernel tree to build it against.
  11.  
  12. Please show proof of this module being built, and running, in your
  13. kernel. What this proof is is up to you, I'm sure you can come up with
  14. something. Also be sure to send the kernel module you wrote, along with
  15. the Makefile you created to build the module.
  16.  
  17. Remember to use your ID assigned to you in the Subject: line when
  18. responding to this task, so that I can figure out who to attribute it
  19. to. You can just respond to the task with the answers and all should be
  20. fine.
  21.  
  22. If you forgot, your id is "7c1caf2f50d1". But of course you have not
  23. forgotten that yet, you are better than that.
  24.  
  25. This is Task 02 of the Eudyptula Challenge
  26. ------------------------------------------
  27.  
  28. Now that you have written your first kernel module, it's time to take
  29. off the training wheels and move on to building a custom kernel. No
  30. more distro kernels for you, for this task you must run your own kernel.
  31. And use git! Exciting isn't it! No, oh, ok...
  32.  
  33. The tasks for this round is:
  34. - download Linus's latest git tree from git.kernel.org (you have to
  35. figure out which one is his, it's not that hard, just remember what
  36. his last name is and you should be fine.)
  37. - build it, install it, and boot it. You can use whatever kernel
  38. configuration options you wish to use, but you must enable
  39. CONFIG_LOCALVERSION_AUTO=y.
  40. - show proof of booting this kernel. Bonus points for you if you do
  41. it on a "real" machine, and not a virtual machine (virtual machines
  42. are acceptable, but come on, real kernel developers don't mess
  43. around with virtual machines, they are too slow. Oh yeah, we aren't
  44. real kernel developers just yet. Well, I'm not anyway, I'm just a
  45. script...) Again, proof of running this kernel is up to you, I'm
  46. sure you can do well.
  47.  
  48. Hint, you should look into the 'make localmodconfig' option, and base
  49. your kernel configuration on a working distro kernel configuration.
  50. Don't sit there and answer all 1625 different kernel configuration
  51. options by hand, even I, a foolish script, know better than to do that!
  52.  
  53. After doing this, don't throw away that kernel and git tree and
  54. configuration file. You'll be using it for later tasks, a working
  55. kernel configuration file is a precious thing, all kernel developers
  56. have one they have grown and tended to over the years. This is the
  57. start of a long journey with yours, don't discard it like was a broken
  58. umbrella, it deserves better than that.
  59.  
  60. Remember to use your ID assigned to you in the Subject: line when
  61. responding to this task, so that I can figure out who to attribute it
  62. to.
  63.  
  64. If you forgot, your id is "7c1caf2f50d1". But why do I repeat myself?
  65. Of course you know your id, you made it through the first task just fine
  66. with it.
  67.  
  68. This is Task 03 of the Eudyptula Challenge
  69. ------------------------------------------
  70.  
  71. Now that you have your custom kernel up and running, it's time to modify
  72. it!
  73.  
  74. The tasks for this round is:
  75. - take the kernel git tree from Task 02 and modify the Makefile to
  76. and modify the EXTRAVERSION field. Do this in a way that the
  77. running kernel (after modifying the Makefile, rebuilding, and
  78. rebooting) has the characters "-eudyptula" in the version string.
  79. - show proof of booting this kernel. Extra cookies for you by
  80. providing creative examples, especially if done in intrepretive
  81. dance at your local pub.
  82. - Send a patch that shows the Makefile modified. Do this in a manner
  83. that would be acceptable for merging in the kernel source tree.
  84. (Hint, read the file Documentation/SubmittingPatches and follow the
  85. steps there.)
  86.  
  87. Remember to use your ID assigned to you in the Subject: line when
  88. responding to this task, so that I can figure out who to attribute it
  89. to.
  90.  
  91. If you forgot, your id is "7c1caf2f50d1". Surely I don't need to keep
  92. saying this right? I know, _you_ wouldn't forget, but someone else, of
  93. course they would, so I'll just leave it here for those "others".
  94.  
  95. This is Task 04 of the Eudyptula Challenge
  96. ------------------------------------------
  97.  
  98. Wonderful job in making it this far, I hope you have been having fun.
  99. Oh, you're getting bored, just booting and installing kernels? Well,
  100. time for some pedantic things to make you feel that those kernel builds
  101. are actually fun!
  102.  
  103. Part of the job of being a kernel developer is recognizing the proper
  104. Linux kernel coding style. The full description of this coding style
  105. can be found in the kernel itself, in the Documentation/CodingStyle
  106. file. I'd recommend going and reading that right now, it's pretty
  107. simple stuff, and something that you are going to need to know and
  108. understand. There is also a tool in the kernel source tree in the
  109. scripts/ directory called checkpatch.pl that can be used to test for
  110. adhering to the coding style rules, as kernel programmers are lazy and
  111. prefer to let scripts do their work for them...
  112.  
  113. And why a coding standard at all? That's because of your brain (yes,
  114. yours, not mine, remember, I'm just some dumb shell scripts). Once your
  115. brain learns the patterns, the information contained really starts to
  116. sink in better. So it's important that everyone follow the same
  117. standard so that the patterns become consistent. In other words, you
  118. want to make it really easy for other people to find the bugs in your
  119. code, and not be confused and distracted by the fact that you happen to
  120. prefer 5 spaces instead of tabs for indentation. Of course you would
  121. never prefer such a thing, I'd never accuse you of that, it was just an
  122. example, please forgive my impertinence!
  123.  
  124. Anyway, the tasks for this round all deal with the Linux kernel coding
  125. style. Attached to this message are two kernel modules that do not
  126. follow the proper Linux kernel coding style rules. Please fix both of
  127. them up, and send it back to me in such a way that does follow the
  128. rules.
  129.  
  130. What, you recognize one of these modules? Imagine that, perhaps I was
  131. right to accuse you of the using a "wrong" coding style :)
  132.  
  133. Yes, the logic in the second module is crazy, and probably wrong, but
  134. don't focus on that, just look at the patterns here, and fix up the
  135. coding style, do not remove lines of code.
  136.  
  137. As always, please remember to use your ID assigned to you in the
  138. Subject: line when responding to this task, so that I can figure out who
  139. to attribute it to. And if you forgot (which of course you have not,
  140. we've been through all of this before), your id is "7c1caf2f50d1".
  141.  
  142. This is Task 05 of the Eudyptula Challenge
  143. ------------------------------------------
  144.  
  145. Yeah, you survived the coding style mess! Now, on to some "real"
  146. things, as I know you are getting bored by these so far.
  147.  
  148. So, simple task this time around:
  149. - take the kernel module you wrote for task 01, and modify it so that
  150. when a USB keyboard is plugged in, the module will be automatically
  151. loaded by the correct userspace hotplug tools (which are implemented
  152. by depmod / kmod / udev / mdev / systemd, depending on what distro
  153. you are using.)
  154.  
  155. Yes, so simple, and yet, it's a bit tricky. As a hint, go read chapter
  156. 14 of the book, "Linux Device Drivers, 3rd edition." Don't worry, it's
  157. free, and online, no need to go buy anything.
  158.  
  159. As always, please remember to use your ID assigned to you, yadda yadda
  160. yadda... It's "7c1caf2f50d1" of course.
  161.  
  162. This is Task 06 of the Eudyptula Challenge
  163. ------------------------------------------
  164.  
  165. Nice job with the module loading macros, those are tricky, but a very
  166. valuable skill to know about, especially when running across them in
  167. real kernel code.
  168.  
  169. Speaking of real kernel code, let's write some!
  170.  
  171. The task this time is this:
  172. - Take the kernel module you wrote for task 01, and modify it to be a
  173. misc char device driver. The misc interface is a very simple way to
  174. be able to create a character device, without having to worry about
  175. all of the sysfs and character device registration mess. And what a
  176. mess it is, so stick to the simple interfaces wherever possible.
  177. - The misc device should be created with a dynamic minor number, no
  178. need running off and trying to reserve a real minor number for your
  179. test module, that would be crazy.
  180. - The misc device should implement the read and write functions.
  181. - The misc device node should show up in /dev/eudyptula.
  182. - When the character device node is read from, your assigned id is
  183. returned to the caller.
  184. - When the character device node is written to, the data sent to the
  185. kernel needs to be checked. If it matches your assigned id, then
  186. return a correct write return value. If the value does not match
  187. your assigned id, return the "invalid value" error value.
  188. - The misc device should be registered when your module is loaded, and
  189. unregistered when it is unloaded.
  190. - Provide some "proof" this all works properly.
  191.  
  192. As you will be putting your id into the kernel module, of course you
  193. haven't forgotten it, but just to be safe, it's "7c1caf2f50d1".
  194.  
  195. This is Task 07 of the Eudyptula Challenge
  196. ------------------------------------------
  197.  
  198. Great work with that misc device driver. Isn't that a nice and simple
  199. way to write a character driver?
  200.  
  201. Just when you think this challenge is all about writing kernel code,
  202. this task is a throwback to your second one. Yes, that's right,
  203. building kernels. Turns out that's what most developers end up doing,
  204. tons and tons of rebuilds, not writing new code. Sad, but it is a good
  205. skill to know.
  206.  
  207. The tasks this round are:
  208. - Download the linux-next kernel for today. Or tomorrow, just use
  209. the latest one. It changes every day so there is no specific one
  210. you need to pick. Build it. Boot it. Provide proof that you built
  211. and booted it.
  212.  
  213. What is the linux-next kernel? Ah, that's part of the challenge.
  214.  
  215. For a hint, you should read the excellent documentation about how the
  216. Linux kernel is developed in Documentation/development-process/ in the
  217. kernel source itself. It's a great read, and should tell you all you
  218. never wanted to know about what Linux kernel developers do and how they
  219. do it.
  220.  
  221. As always, please respond to this challenge with your id. I know you
  222. know what it is. I'll not even include it this time, I trust you.
  223. Don't make me feel that is a mistake.
  224.  
  225. This is Task 08 of the Eudyptula Challenge
  226. ------------------------------------------
  227.  
  228. We will come back to the linux-next kernel in a later exercise, so don't
  229. go and delete that directory, you'll want it around. But enough of
  230. building kernels, let's write more code!
  231.  
  232. This task is much like the 06 task with the misc device, but this time
  233. we are going to focus on another user/kernel interface, debugfs. It is
  234. rumored that the creator of debugfs said that there is only one rule for
  235. debugfs use, "There are no rules when using debugfs." So let's take
  236. them up on that offer and see how to use it.
  237.  
  238. debugfs should be mounted by your distro in /sys/kernel/debug/, if it
  239. isn't, then you can mount it with the line:
  240. mount -t debugfs none /sys/kernel/debug/
  241.  
  242. Make sure it is enabled in your kernel, with the CONFIG_DEBUG_FS option,
  243. you will need it for this task.
  244.  
  245. The task, in specifics is:
  246.  
  247. - Take the kernel module you wrote for task 01, and modify it to be
  248. create a debugfs subdirectory called "eudyptula". In that
  249. directory, create 3 virtual files called "id", "jiffies", and "foo".
  250. - The file "id" operates just like it did for example 06, use the same
  251. logic there, the file must be readable and writable by any user.
  252. - The file "jiffies" is to be read only by any user, and when read,
  253. should return the current value of the jiffies kernel timer.
  254. - The file "foo" needs to be writable only by root, but readable by
  255. anyone. When writing to it, the value must be stored, up to one
  256. page of data. When read, which can be done by any user, the value
  257. must be returned that is stored it it. Properly handle the fact
  258. that someone could be reading from the file while someone else is
  259. writing to it (oh, a locking hint!)
  260. - When the module is unloaded, all of the debugfs files are cleaned
  261. up, and any memory allocated is freed.
  262. - Provide some "proof" this all works.
  263.  
  264. Again, you are using your id in the code, so you know what it is by now,
  265. no need to repeat it again.
  266.  
  267. This is Task 09 of the Eudyptula Challenge
  268. ------------------------------------------
  269.  
  270. Nice job with debugfs, that is a handy thing to remember when wanting to
  271. print out some debugging information. Never use /proc/ that is only for
  272. processes, use debugfs instead.
  273.  
  274. Along with debugfs, sysfs is a common place to put information that
  275. needs to move from the user to the kernel. So let us focus on sysfs for
  276. this task.
  277.  
  278. The task this time:
  279.  
  280. - Take the code you wrote in task 08, and move it to sysfs. Put the
  281. "eudyptula" directory under the /sys/kernel/ location in sysfs.
  282. - Provide some "proof" this works.
  283.  
  284. That's it! Simple, right? No, you are right, it's more complex, sysfs
  285. is complicated. I'd recommend reading Documentation/kobject.txt as a
  286. primer on how to use kobjects and sysfs.
  287.  
  288. Feel free to ask for hints and help with this one if you have questions
  289. by sending in code to review if you get stuck, many people have dropped
  290. out in the challenge at this point in time, so don't feel bad about
  291. asking, we don't want to see you go away just because sysfs is so damn
  292. complicated.
  293.  
  294. This is Task 10 of the Eudyptula Challenge
  295. ------------------------------------------
  296.  
  297. Yeah, you conquered the sysfs monster, great job!
  298.  
  299. Now you know to never want to mess with a kobject again, right? Trust
  300. me, there are easier ways to create sysfs files, and we will get into
  301. that for a future task, but for now, let's make it a bit more simple
  302. after all of that coding.
  303.  
  304. For this task, go back to the linux-next tree you used for task 07.
  305. Update it, and then do the following:
  306. - Create a patch that fixes one coding style problem in any of the
  307. files in drivers/staging/
  308. - Make sure the patch is correct by running it through
  309. scripts/checkpatch.pl
  310. - Submit the code to the maintainer of the driver/subsystem, finding
  311. the proper name and mailing lists to send it to by running the tool,
  312. scripts/get_maintainer.pl on your patch.
  313. - Send a web link back to me of your patch on the public mailing list
  314. archive (don't cc: me on the patch, that will only confuse me and
  315. everyone in the kernel development community.)
  316. - If you want to mention the Eudyptula Challenge as the reason for
  317. writing the patch, feel free to do so in the body of the patch, but
  318. it's not necessary at all.
  319.  
  320. Hopefully this patch will be accepted into the kernel tree, and all of a
  321. sudden, you are an "official" kernel developer!
  322.  
  323. Don't worry, there's plenty more tasks coming, but a little breather
  324. every now and again for something simple is always nice to have.
  325.  
  326. This is Task 11 of the Eudyptula Challenge
  327. ------------------------------------------
  328.  
  329. You made a successful patch to the kernel source tree, that's a great
  330. step!
  331.  
  332. But, let's not rest, time to get back to code.
  333.  
  334. Remember that mess of kobject and sysfs code back in task 09? Let's
  335. move one level up the tree and start to mess with devices and not raw
  336. kobjects.
  337.  
  338. For this task:
  339. - Write a patch against any driver that you are currently using on
  340. your machine. So first you have to figure out which drivers you are
  341. using, and where the source code in the kernel tree is for that
  342. driver.
  343. - In that driver, add a sysfs file to show up in the /sys/devices/
  344. tree for the device that is called "id". As you might expect, this
  345. file follows the same rules as task 09 as for what you can read and
  346. write to it.
  347. - The file is to show up only for devices that are controlled by a
  348. single driver, not for all devices of a single type (like all USB
  349. devices. But all USB maibox LEDs would be acceptable, if you happen
  350. to have the device that that driver controls.)
  351.  
  352. Submit both the patch, in proper kernel commit form, and "proof" of it
  353. working properly on your machine.
  354.  
  355. And as always, please use your id in the subject line. If you happened
  356. to forget it, as it has been a while since I reminded you of it, it is
  357. "7c1caf2f50d1".
  358.  
  359. This is Task 12 of the Eudyptula Challenge
  360. ------------------------------------------
  361.  
  362. Nice job with the driver patch. That took some work in finding the
  363. proper place to modify, and demonstrates a great skill in tracking down
  364. issues when you can't get a specific piece of hardware working.
  365.  
  366. Now let's step back from drivers (they are boring things), and focus on
  367. the kernel core. To do that, we need to go way back to the basics --
  368. stuff you would learn in your "intro to data structures" class, if you
  369. happened to take one.
  370.  
  371. Yes, I'm talking about linked lists.
  372.  
  373. The kernel has a unique way of creating and handling linked lists, that
  374. is quite different than the "textbook" way of doing so. But, it turns
  375. out to be faster, and simpler, than a "textbook" would describe, so
  376. that's a good thing.
  377.  
  378. For this task, write a kernel module, based on your cleaned up one from
  379. task 04, that does the following:
  380. - You have a structure that has 3 fields:
  381. char name[20];
  382. int id;
  383. bool busy;
  384. name this structure "identity".
  385. - Your module has a static variable that points to a list of these
  386. "identity" structures.
  387. - Write a function that looks like:
  388. int identity_create(char *name, int id)
  389. that creates the structure "identity", copies in the 'name' and 'id'
  390. fields and sets 'busy' to false. Proper error checking for out of
  391. memory issues is required. Return 0 if everything went ok; an error
  392. value if something went wrong.
  393. - Write a function that looks like:
  394. struct identity *identity_find(int id);
  395. that takes a given id, iterates over the list of all ids, and
  396. returns the proper 'struct identity' associated with it. If the
  397. identity is not found, return NULL.
  398. - Write a function that looks like:
  399. void identity_destroy(int id);
  400. that given an id, finds the proper 'struct identity' and removes it
  401. from the system.
  402. - Your module_init() function will look much like the following:
  403.  
  404. struct identity *temp;
  405.  
  406. identity_create("Alice", 1);
  407. identity_create("Bob", 2);
  408. identity_create("Dave", 3);
  409. identity_create("Gena", 10);
  410.  
  411. temp = identity_find(3);
  412. pr_debug("id 3 = %s\n", temp->name);
  413.  
  414. temp = identity_find(42);
  415. if (temp == NULL)
  416. pr_debug("id 42 not found\n");
  417.  
  418. identity_destroy(2);
  419. identity_destroy(1);
  420. identity_destroy(10);
  421. identity_destroy(42);
  422. identity_destroy(3);
  423.  
  424. Bonus points for properly checking return values of the above
  425. functions.
  426.  
  427. As always, please send the full module (following the proper kernel
  428. coding style rules), and "proof" of it working properly. And remember
  429. to use your id of "7c1caf2f50d1" in the Subject line properly.
  430.  
  431. This is Task 13 of the Eudyptula Challenge
  432. ------------------------------------------
  433.  
  434. Weren't those lists fun to play with? You should get used to them, they
  435. are used all over the kernel in lots of different places.
  436.  
  437. Now that we are allocating a structure that we want to use a lot of, we
  438. might want to start caring about the speed of the allocation, and not
  439. have to worry about the creation of those objects from the "general"
  440. memory pools of the kernel.
  441.  
  442. This task is to take the code written in task 12, and cause all memory
  443. allocated from the 'struct identity' to come from a private slab cache
  444. just for the fun of it.
  445.  
  446. Instead of using kmalloc() and kfree() in the module, use
  447. kmem_cache_alloc() and kmem_cache_free() instead. Of course this means
  448. you will have to initialize your memory cache properly when the module
  449. starts up. Don't forget to do that. You are free to name your memory
  450. cache whatever you wish, but it should show up in the /proc/slabinfo
  451. file.
  452.  
  453. Don't send the full module for this task, only a patch with the diff
  454. from task 12 showing the lines changed. This means you will have to
  455. keep a copy of your 12 task results somewhere to make sure you don't
  456. overwrite them.
  457.  
  458. Also show the output of /proc/slabinfo with your module loaded.
  459.  
  460. This is Task 14 of the Eudyptula Challenge
  461. ------------------------------------------
  462.  
  463. Now that you have the basics of lists, and we glossed over the custom
  464. allocators (the first cut at that task was much harder, you got off
  465. easy), it's time to move on to something a bit more old-school: tasks.
  466.  
  467. For this task:
  468. - Add a new field to the core kernel task structure called, wait for
  469. it, "id".
  470. - When the task is created, set the id to your id. Imaginative, I
  471. know. You try writing these tasks.
  472. - Add a new proc file for every task called, "id", located in the
  473. /proc/${PID}/ directory for that task.
  474. - When the proc file is read from, have it print out the value of
  475. your id, and then increment it by one, allowing different tasks to
  476. have different values for the "id" file over time as they are read
  477. from.
  478. - Provide some "proof" it all works properly.
  479.  
  480. As you are touching files all over the kernel tree, a patch is the
  481. required result to be sent in here. Please specify which kernel version
  482. you make this patch against, to give my virtual machines a chance to
  483. figure out how to apply it.
  484.  
  485. Also provide some kind of proof that you tested the patch.
  486.  
  487. And, in case you happened to forget it, your id is "7c1caf2f50d1".
  488.  
  489. This is Task 15 of the Eudyptula Challenge
  490. ------------------------------------------
  491.  
  492. That process task turned out to not be all that complex, but digging
  493. through the core kernel was a tough task, nice work with that.
  494.  
  495. Speaking of "core kernel" tasks, let's do another one. It's one of the
  496. most common undergraduate tasks there is: create a new syscall!
  497. Yeah, loads of fun, but it's good to know the basics of how to do this,
  498. and, how to call it from userspace.
  499.  
  500. For this task:
  501. - Add a new syscall to the kernel called "sys_eudyptula", so this is
  502. all going to be changes to the kernel tree itself, no stand-alone
  503. module needed for this task (unless you want to do it that way
  504. without hacking around the syscall table, if so, bonus points for
  505. you...)
  506. - The syscall number needs to be the next syscall number for the
  507. architecture you test it on (some of you all are doing this on ARM
  508. systems, showoffs, and syscall numbers are not the same across all
  509. architectures). Document the arch you are using and why you picked
  510. this number in the module.
  511. - The syscall should take two parameters: int high_id, int low_id.
  512. - The syscall will take the two values, mush them together into one
  513. 64bit value (low_id being the lower 32bits of the id, high_id being
  514. the upper 32bits of the id).
  515. - If the id value matches your id (which of course you know as
  516. "7c1caf2f50d1", then the syscall returns success. Otherwise it
  517. returns a return code signifying an invalid value was passed to it.
  518. - Write a userspace C program that calls the syscall and properly
  519. exercises it (valid and invalid calls need to be made).
  520. - "Proof" of running the code needs to be provided.
  521.  
  522. So you need to send in a .c userspace program, a kernel patch, and
  523. "proof" that it all works, as a response.
  524.  
  525. This is Task 16 of the Eudyptula Challenge
  526. ------------------------------------------
  527.  
  528. Good job with the new syscall. The odds of you ever having to write a
  529. new syscall is pretty rare, but now you know where to look them up, and
  530. what the code involved in creating one looks like, which is useful when
  531. you try to debug things.
  532.  
  533. Let's take a breather after all of that code, and go back to doing a bit
  534. of reading, and learn some more about some common kernel tools.
  535.  
  536. Go install the tool 'sparse'. It was started by Linus as a
  537. static-analysis tool that acts much like a compiler. The kernel build
  538. system is set up to have it run if you ask it to, and it will report a
  539. bunch of issues in C code that are really specific to the kernel.
  540.  
  541. When you build the kernel, pass the "C=1" option to the build, to have
  542. sparse run on the .c file before gcc is run. Depending on the file,
  543. nothing might be printed out, or something might. Here's an example of
  544. it being run on the ext4 code:
  545.  
  546. $ make C=1 M=fs/ext4
  547. CHECK fs/ext4/balloc.c
  548. CC fs/ext4/balloc.o
  549. CHECK fs/ext4/bitmap.c
  550. CC fs/ext4/bitmap.o
  551. CHECK fs/ext4/dir.c
  552. CC fs/ext4/dir.o
  553. CHECK fs/ext4/file.c
  554. CC fs/ext4/file.o
  555. CHECK fs/ext4/fsync.c
  556. CC fs/ext4/fsync.o
  557. CHECK fs/ext4/ialloc.c
  558. CC fs/ext4/ialloc.o
  559. CHECK fs/ext4/inode.c
  560. CC fs/ext4/inode.o
  561. CHECK fs/ext4/page-io.c
  562. CC fs/ext4/page-io.o
  563. CHECK fs/ext4/ioctl.c
  564. CC fs/ext4/ioctl.o
  565. CHECK fs/ext4/namei.c
  566. CC fs/ext4/namei.o
  567. CHECK fs/ext4/super.c
  568. CC fs/ext4/super.o
  569. CHECK fs/ext4/symlink.c
  570. CC fs/ext4/symlink.o
  571. CHECK fs/ext4/hash.c
  572. CC fs/ext4/hash.o
  573. CHECK fs/ext4/resize.c
  574. CC fs/ext4/resize.o
  575. CHECK fs/ext4/extents.c
  576. CC fs/ext4/extents.o
  577. CHECK fs/ext4/ext4_jbd2.c
  578. CC fs/ext4/ext4_jbd2.o
  579. CHECK fs/ext4/migrate.c
  580. CC fs/ext4/migrate.o
  581. CHECK fs/ext4/mballoc.c
  582. fs/ext4/mballoc.c:5018:9: warning: context imbalance in 'ext4_trim_extent' - unexpected unlock
  583. CC fs/ext4/mballoc.o
  584. CHECK fs/ext4/block_validity.c
  585. CC fs/ext4/block_validity.o
  586. CHECK fs/ext4/move_extent.c
  587. CC fs/ext4/move_extent.o
  588. CHECK fs/ext4/mmp.c
  589. CC fs/ext4/mmp.o
  590. CHECK fs/ext4/indirect.c
  591. CC fs/ext4/indirect.o
  592. CHECK fs/ext4/extents_status.c
  593. CC fs/ext4/extents_status.o
  594. CHECK fs/ext4/xattr.c
  595. CC fs/ext4/xattr.o
  596. CHECK fs/ext4/xattr_user.c
  597. CC fs/ext4/xattr_user.o
  598. CHECK fs/ext4/xattr_trusted.c
  599. CC fs/ext4/xattr_trusted.o
  600. CHECK fs/ext4/inline.c
  601. CC fs/ext4/inline.o
  602. CHECK fs/ext4/acl.c
  603. CC fs/ext4/acl.o
  604. CHECK fs/ext4/xattr_security.c
  605. CC fs/ext4/xattr_security.o
  606. LD fs/ext4/ext4.o
  607. LD fs/ext4/built-in.o
  608. Building modules, stage 2.
  609. MODPOST 0 modules
  610.  
  611. As you can see, only one warning was found here, and odds are, it is a
  612. false-positive, as I'm sure those ext4 developers know what they are
  613. doing with their locking functions, right?
  614.  
  615. Anyway the task this time is:
  616. - Run sparse on the drivers/staging/ directory, yes, that horrible
  617. code again, sorry.
  618. - Find one warning that looks interesting.
  619. - Write a patch that resolves the issue.
  620. - Make sure the patch is correct by running it through
  621. scripts/checkpatch.pl
  622. - Submit the code to the maintainer of the driver/subsystem, finding
  623. the proper name and mailing lists to send it to by running the tool,
  624. scripts/get_maintainer.pl on your patch.
  625. - Send a web link back to me of your patch in the public mailing list
  626. archive (don't cc: me on the patch, that will only confuse me and
  627. everyone in the kernel development community.)
  628. - If you want to mention the Eudyptula Challenge as the reason for
  629. writing the patch, feel free to do so in the body of the patch, but
  630. it's not necessary at all.
  631.  
  632. That's it, much like task 10 was, but this time you are fixing logical
  633. issues, not just pesky coding style issues. You are a real developer
  634. now, fixing real bugs!
  635.  
  636. This is Task 17 of the Eudyptula Challenge
  637. ------------------------------------------
  638.  
  639. Another patch made and sent in. See, that wasn't so hard. Keep sending
  640. in kernel patches outside of this challenge, those lazy kernel
  641. developers need all the help they can get in cleaning up their code.
  642.  
  643. It is time to start putting the different pieces of what we have done in
  644. the past together, into a much larger module, doing more complex things.
  645. Much more like what a "real" kernel module has to do.
  646.  
  647. Go dig up your code from task 06, the misc char device driver, and make
  648. the following changes:
  649.  
  650. - Delete the read function. You don't need that anymore, so make it a
  651. write-only misc device and be sure to set the mode of the device to
  652. be write-only, by anyone. If you do this right, udev will set up the
  653. node automatically with the correct permissions.
  654. - Create a wait queue, name it "wee_wait".
  655. - In your module init function, create a kernel thread, named of course
  656. "eudyptula".
  657. - The thread's main function should not do anything at this point in
  658. time, except make sure to shutdown if asked to, and wait on the
  659. "wee_wait" waitqueue.
  660. - In your module exit function, shut down the kernel thread you started
  661. up.
  662.  
  663. Load and unload the module and "prove" that it works properly (that the
  664. thread is created, it can be found in the process list, and that the
  665. device node is created with the correct permission value.) Send in the
  666. proof and the .c file for the module.
  667.  
  668. Be sure to keep this code around, as we will be doing more with it next
  669. time.
  670.  
  671. This is Task 18 of the Eudyptula Challenge
  672. ------------------------------------------
  673.  
  674. Nice job with the kernel thread. It really doesn't take much code at
  675. all to create a new thread. So now let us get some data into the module
  676. to give the thread something to do.
  677.  
  678. Base all of this work on your task 17 codebase.
  679.  
  680. Go back and dig up task 12's source code, the one with the list
  681. handling. Copy the structure into this module, and the
  682. identity_create(), identity_find(), and identity_destroy() functions
  683. into this module as well.
  684.  
  685. Write a new function, identity_get(), that looks like:
  686. struct identity identity_get(void);
  687. and returns the next "identity" structure that is on the list, and
  688. removes it from the list. If nothing is on the list, return NULL.
  689.  
  690. Then, hook up the misc char device "write" function to do the following:
  691. - If a write is larger than 19 characters, truncate it at 19.
  692. - Take the write data and pass it to identity_create() as the string,
  693. and use an incrementing counter as the "id" value.
  694. - Wake up the "wee_wait" queue.
  695.  
  696. In the kernel thread function:
  697. - If the "wee_wait" queue wakes us up, get the next identity in the
  698. system with a call to identity_get().
  699. - Sleep (in an interruptable state, don't go increasing the system
  700. load in a bad way) for 5 seconds.
  701. - Write out the identity name, and id to the debug kernel log and then
  702. free the memory.
  703.  
  704. When the module exits, clean up the whole list by using the functions
  705. given, no fair mucking around with the list variables directly.
  706.  
  707. Yes, it's a bit clunky, but it shows the basics of taking work from
  708. userspace, and then quickly returning to the user, and then going off
  709. and doing something else with the data and cleaning everything up. It's
  710. a common pattern for a kernel, as it's really all that a kernel ends up
  711. doing most of the time (get a disk block, write a disk block, handle a
  712. mouse event, etc.)
  713.  
  714. Load and unload the module and "prove" that it works properly by writing
  715. and looking at the debug log, and that everything cleans up properly
  716. when the module is unloaded.
  717.  
  718. Send in the proof and the .c file for the module.
  719.  
  720. A good test script would be the following:
  721. echo "Alice" > /dev/eudyptula
  722. echo "Bob" > /dev/eudyptula
  723. sleep 15
  724. echo "Dave" > /dev/eudyptula
  725. echo "Gena" > /dev/eudyptula
  726. rmmod task18
  727.  
  728. Removing the module while there is pending work is always a good stress
  729. test.
  730.  
  731. This is Task 19 of the Eudyptula Challenge
  732. ------------------------------------------
  733.  
  734. Handling delayed work is easy now, right? So, time to move on to
  735. something totally different. How about networking? We have been
  736. ignoring that part of the kernel, so let us now focus on the network
  737. side of the kernel, as that is a huge reason for why Linux has taken
  738. over the world.
  739.  
  740. For this task, write a netfilter kernel module that does the following:
  741. - monitors all IPv4 network traffic that is coming into the machine
  742. - prints the id to the kernel debug log if the network traffic stream
  743. contains your id.
  744. - properly unregisters you from the netfilter core when the module
  745. unloads.
  746.  
  747. Test this by sending yourself an email with your id in the subject, much
  748. like the email you need to send back to me.
  749.  
  750. Send in the proof and the .c file for the module.
  751.  
  752. This is Task 20 of the Eudyptula Challenge
  753. ------------------------------------------
  754.  
  755. Networking filters turned out to be not all that complex in the end,
  756. great work with that.
  757.  
  758. So, here's the final task.
  759.  
  760. There might be other tasks that get created and sent out later on, but
  761. the original challenge had 20 tasks, so after finishing this one, you
  762. can consider yourself done!
  763.  
  764. Let's try something a bit harder. Something that might cause some data
  765. loss on a filesystem, always a fun thing to play with, if for no other
  766. reason than to not be afraid of things like that in the future.
  767.  
  768. This task requires you to work on the fat filesystem code:
  769. - Add an ioctl to modify the volume label of a mounted fat filesystem.
  770. Be sure to handle both 16 and 32 bit fat filesystems {hint!}
  771. - Provide a userspace .c program to test this new ioctl.
  772.  
  773. That's it! Seems so simple, right? I wonder why that option isn't in
  774. the kernel tree already...
  775.  
  776. Anyway, provide a patch to the kernel, and the .c file used to test the
  777. new ioctl, as well as "proof" of this working. Make sure you don't run
  778. into 32/64bit kernel issues with the ioctl, if you do things correctly,
  779. you shouldn't have any problems.
  780.  
  781. I recommend doing this work on either a loop-back fat filesystem on your
  782. "normal" filesystem, or on a USB stick. Either will work just as well,
  783. and make things easier to debug and test.
  784.  
  785. Watch out for locking issues, as well as dirty filesystem state
  786. problems.
  787.  
  788. Best of luck!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement