Commit Graph

170 Commits

Author SHA1 Message Date
RinHizakura
2cc4264f72 Introduce the new method for chardev registration
Instead of using the old register_chrdev / unregister_chrdev API,
cdev interface which is newer and would be better for new driver programmers
in most cases. This commit is trying to give the brief overview for
this different interface.
2021-12-23 21:12:14 -08:00
Jim Huang
e4016013b2 modinfo does not require superuser permission 2021-12-04 16:13:22 +00:00
lyctw
e2a6fcdae9 Fix typo 2021-11-16 14:50:01 +08:00
Jim Huang
d88d0cd227
Merge pull request #123 from fennecJ/patch
Generate contributor list as a modular inclusion
2021-11-08 12:07:57 +08:00
manbing
07a9741f79
Adjust the position of Figure 1 (#126) 2021-11-08 12:06:19 +08:00
fennecJ
af09a8a1e5 Add script to gen contributor list and contrib.tex
This script do mainly 2 things:
1.
Generate file `Contributors` with git log in following format:
Contributor's name,<1-st e-mail>[,<2nd e-mail>][,<3rd e-mail>]...
The 2-nd email and so on are based on file `.mailmap` in the root
directory of the repo.
Note that it will also append contributors in File `Include`; and
will NOT append contributors in File `Exclude`.
If there are new contributors, script will sort `Contributor` after
append new contributors into each file; Otherwise it do nothing.

2.
Generate contrib.tex based on `Contributors` into lib/contrib.tex in
following format:
[name], (reasonable width) % [1-st e-mail]
Which is inspired by The Not So Short Introduction to Latex 2e[1]

We need to maintain `.mailmap`, `Exclude` and `Include` manually.
All Chinese name should be converted into English/Pinyin in `.mailmap`,
otherwise we may need extra pkg for latex to parse Chinese characters.

[1] - https://tobi.oetiker.ch/lshort/lshort.pdf

Close #68
2021-11-03 19:32:48 +08:00
tzuyichan
b95f6f5cf6
Fix grammar
in the hope ... will -> in the hope that ... would
get -> got
where are ... gone -> where have ... gone
For those not -> For those who are not
2021-10-27 05:00:05 +08:00
demonsome
67149719a4
Explain inode at the first occurrence (#115)
The explanation of "inode" should appear at the first occurrence to which readers
can refer.
2021-10-25 22:46:02 +08:00
Jim Huang
28018227fc Remove out-of-date syscall information
Close #121
2021-10-14 20:51:09 +08:00
Jim Huang
151a91ecf4 Fix wording 2021-10-10 21:45:12 +08:00
Marconi Jiang
89755e146a Correct English gramma 2021-09-29 06:41:31 -07:00
Jim Huang
0a176fbb19 Simplify the epilog 2021-09-25 19:53:13 +08:00
Jim Huang
707e193cbe Always run "dmesg" with sudo
The dmesg command allows you to review the messages that are stored in the
ring buffer. Some Linux distributions have strict requirements for
dmesg, and you need to use sudo to use dmesg.
2021-09-25 02:09:13 +08:00
Jim Huang
11e40dc8ef Remove unintended code block 2021-09-25 02:06:26 +08:00
Marconi Jiang
a1c3cca6db
Dump the message of hello-5 explicitly (#112)
Close #111
2021-09-25 02:03:44 +08:00
linD026
1a6fb67cf2
Fix potential concurrent access problems with VFS (#108)
Since Linux v3.14, the read, write and seek operations of "struct file" are
guaranteed for thread safety [1][2]. This patch added an explanation.

Here are the potential problems:
chardev.c:
- Move the "msg_ptr" pointer into the read function to remove unnecessary usage.
- List the clear states of "already_open" by using mnemonic enumeration.

chardev2.c:
- The "buffer" in the write function is user space data. It cannot use in the
  kernel space.
- Reduce the redundant type transformation.
- List the states of "already_open". Same as chardev.c.

[1] https://lore.kernel.org/lkml/20140303210359.26624.qmail@science.horizon.com/T/#u
[2] 9c225f2655
2021-09-23 12:20:10 +08:00
Jim Huang
027f39c0c1 Denote LWN hyperlink 2021-09-23 00:36:42 +08:00
Ylowy
24257e837e
Typo. 2021-09-19 20:39:56 +08:00
Stacy Prowell
728b7fd432
Fixed parameter name for hello-5.
Parameters are case-sensitive, so myintArray is different from myintarray, and people who are running the example with copy/paste will find it doesn't work as described in the text.
2021-09-15 16:05:26 -04:00
Gilad Reti
e8d5bf7fd4
fix typo: compatibiity -> compatibility 2021-09-12 08:54:53 +03:00
Jim Huang
c519f57403 Simplify the wording 2021-09-10 14:19:22 +00:00
linD026
62dbb1b7b8
Adapt the timer API Usage (#98)
Since v4.14 [1], the timer API has been changed to improve memory safety.
The series of improvements ended up at v4.15 [2].

Reference: https://lwn.net/Articles/735887/

Close #97

[1] 686fef928b
[2] 841b86f328
2021-09-10 12:29:48 +08:00
linD026
148fb013ee
Avoid unexpected concurrent access (#94)
In file {chardev,chardev2,sleep}.c, the variable to determine
the exclusive access was of integer type, which led to race
condition.

This patch rewrote the above with atomic CAS respectively
to eliminate the race.

Close #93
2021-09-07 23:42:06 +08:00
ccs100203
56c99328b3 Fix Typo
from "mask" to "masks"
from "quick" to "quickly"
from "a" to "an"
2021-09-03 23:02:17 +08:00
Jim Huang
6110f8ee3c Rewrite the descriptions about bottom half 2021-09-01 12:07:25 +08:00
linzhien
5cd96a80c9 Fix typo 2021-09-01 07:44:40 +08:00
linD026
cccc98ab2c
Fix disallowed cr0 write protection and close_fd (#80)
Since the commit 8dbec27a242cd3e2816eeb98d3237b9f57cf6232 [1]
(kernel version v5.3+ [2]) the sensitive CR0 bits in x86 is pinned,
we need to use the inline asm [3][4] to bypass it.

commit 8dbec27a242cd3e2816eeb98d3237b9f57cf6232 :
> With sensitive CR4 bits pinned now, it's possible that the WP bit for
> CR0 might become a target as well.
>
> Following the same reasoning for the CR4 pinning, pin CR0's WP
> bit. Contrary to the cpu feature dependend CR4 pinning this can be done
> with a constant value.

Also, getting "sys_call_table" [8] from the symbol lookup by using the address
of "close_fd" does not work for v5.11+ [5][6]. The reason is the entry of
"sys_call_table[__NR_close]" is not the address of "close_fd", actually
it is "__x64_sys_close" in x86.

Two solutions were proposed: using "kallsyms_lookup_name" [7] or just specifying
the address into the module. The symbol "kallsyms_lookup_name"  is unexported
since v5.7; the address of "sys_call_table" can be found in
"/boot/System.map" or "/proc/kallsyms".

Since v5.7, the manual symbol lookup is not guaranteed to work
because of control-flow integrity (or control-flow enforcement [9][10]) is added
[11] for x86, but it is disabled since v5.11 [12][13]. To make sure manual symbol
lookup work, it only uses up to v5.4.

Reference:
[1] 8dbec27a24
[2] https://outflux.net/blog/archives/2019/11/14/security-things-in-linux-v5-3/
[3] https://patchwork.kernel.org/project/linux-kbuild/patch/20200903203053.3411268-3-samitolvanen@google.com/
[4] https://stackoverflow.com/questions/58512430/how-to-write-to-protected-pages-in-the-linux-kernel
[5] https://lore.kernel.org/bpf/20201120231441.29911-21-ebiederm@xmission.com/
[6] https://lore.kernel.org/bpf/87blj83ysq.fsf@x220.int.ebiederm.org/
[7] 0bd476e6c6
[8] 8f27766a88
[9] https://lore.kernel.org/lkml/20200204171425.28073-1-yu-cheng.yu@intel.com/
[10] https://lore.kernel.org/linux-doc/20201110162211.9207-1-yu-cheng.yu@intel.com/T/
[11] 5790921bc1
[12] 20bf2b3787
[13] https://lore.kernel.org/bpf/20210128123842.c9e33949e62f504b84bfadf5@gmail.com/
2021-08-31 11:07:01 +08:00
xatier
1f9f201940
Update Archlinux kernel headers instructions
`linux-libre-headers` has been moved to AUR [1]. We can simply install `linux-headers` [2] instead.

[1] https://aur.archlinux.org/packages/linux-libre-headers/
[2] https://archlinux.org/packages/core/x86_64/linux-headers/
2021-08-25 20:11:27 -07:00
Jim Huang
ecfe9606de Get rid of the initial 0 that shows up in every (sub)section
Every section and subsection number can be eliminated by adding the
renewcommand.

Suggested by Lars Engebretsen.
2021-08-24 19:02:16 +08:00
Brad Baker
8012508508 Fixing typo 2021-08-24 00:15:47 -04:00
fennecJ
870b26fa2d Update several example code for newer kernel
Known issues with current example code:
If you using newer kernel(e.g linux 5.11.x) to compile the example code,
you may meet following error:
1. syscall.c:83:50: error: ‘ksys_close’ undeclared;
2. cryptosk.c:17:24: error: field ‘sg’ has incomplete type
3. cryptosk.c:143:9: error: implicit declaration of function
‘get_random_bytes’
4. error: macro "DECLARE_TASKLET" passed 3 arguments, but takes just 2

Solutions/workaround:
1. In syscall.c, replace #include <linux/syscalls.h> with
#include <linux/fdtable.h> and replace  ksys_close with close_fd
if the kernel version >= 5.11. [1][2]
2. Add #include <linux/scatterlist.h> into cryptosk.c
3. Add #include <linux/random.h> into cryptosk.c
4. In bottomhalf.c and example_tasklet.c, replace DECLARE_TASKLET
with DECLARE_TASKLET_OLD and dispose third argument(0L). [3]

[1] - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1572bfdf21d4d50e51941498ffe0b56c2289f783
[2] - https://www.mail-archive.com/meta-arago@arago-project.org//msg11939.html
[3] - https://patchwork.kernel.org/project/kernel-hardening/patch/20200716030847.1564131-3-keescook@chromium.org/
2021-08-23 21:30:43 +08:00
Jim Huang
22e50f3ce9 Use recent kernel build messages 2021-08-20 01:05:51 +08:00
Jim Huang
f7e2186e6b Revise the version magic descriptions for recent kernels 2021-08-20 01:02:20 +08:00
Jim Huang
3c742b0c7c Fix wording 2021-08-20 00:29:43 +08:00
Cyril Brulebois
98aa78e4d2 Adjust link to ioctl-number.rst 2021-08-16 21:54:03 +02:00
Cyril Brulebois
c43c01db31 Improve wording (avoid a send/sent repetition along the way) 2021-08-16 21:54:03 +02:00
Cyril Brulebois
08b6de2cde Use an https:// link for LWN 2021-08-16 21:54:03 +02:00
Cyril Brulebois
8861d1ead7 Improve wording (statistics seem gathered, not stat-ed) 2021-08-16 21:54:03 +02:00
Cyril Brulebois
4d5649fc08 Improve wording (there's only one kernel) 2021-08-16 21:54:03 +02:00
Cyril Brulebois
3e05439b6d Add emphasis for the y/m values 2021-08-16 21:54:03 +02:00
Cyril Brulebois
b5ab7c5e88 Fix various typos 2021-08-16 21:54:03 +02:00
fennecJ
467cc83cc7
Improve the descriptions about reference count (#62)
The term "reference count" would be better than "use count."
In addition, the usage of module_refcount(THIS_MODULE) was appended
for the reference counter query.
2021-08-17 00:23:22 +08:00
fennecj
99faf5ed0f Fix typo 2021-08-16 23:48:04 +08:00
Jim Huang
4acc65b740 Use \verb for the identifiers starting with "--" 2021-08-16 21:21:10 +08:00
Chih-Yu Chen
c8238430b2
Avoid incorrectly separated words (#55)
This patch fixed some typos and added the missing punctuation.
2021-08-16 18:45:43 +08:00
fennecj
15e44bffa8 Fix grammar and typo 2021-08-16 00:47:23 +08:00
Jim Huang
964f14dda6 Annotate more directories/files 2021-08-13 01:02:21 +08:00
fennecj
990358d75a Fix typo 2021-08-13 00:52:33 +08:00
fennecj
b656755300 Fix typo 2021-08-11 18:34:23 +08:00
Jim Huang
8d7caa7fc9 Make insmod/rmmod more consistent 2021-08-11 15:08:08 +08:00
fennecj
e87998c224 Fix incorrect path
There should be a space between uname and -r
2021-08-10 18:22:33 +08:00
Jim Huang
6b6083fca2 Remove out-of-date information 2021-08-09 23:59:59 +08:00
Jim Huang
b002e43bb8 Annotate NULL 2021-08-09 23:57:30 +08:00
Jim Huang
e800505b8f Point to corresponding kernel header 2021-08-09 23:26:01 +08:00
Jim Huang
a4c44ed3d1 Annotate more commands 2021-08-09 23:23:08 +08:00
Jim Huang
2d368210ce Introduce \src to generate Linux kernel source hyperlinks
The new command \src was introduced for preliminary hyperlink generation
which points to Linux kernel source code. At present, stable/linux.git
was referred:
  https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

We might switch to specific LTS kernels once requested.
2021-08-09 23:01:34 +08:00
Jim Huang
da3dd34cd2 Revise the path of Linux kernel headers
This patch uses the relative path to Linux kernel headers in source tree
rather than what they are usually inclused in LKM. It would be great to
introduce \href with appropriate hyperlinks to Linux kernel tree.
2021-08-09 22:37:20 +08:00
Jim Huang
e551c98dde Clarify kernel header inclusion
Both <linux/module.h> and <linux/kernel.h> are essential headers, and
LKM should include them. Here, we do not use the fully qualified path
specifying the headers.
2021-08-09 22:05:08 +08:00
Jim Huang
251adeb075 Change the header file which defines sys_delete_module 2021-08-09 22:00:57 +08:00
Jim Huang
526ad3c842 Annotate function calls 2021-08-09 21:41:50 +08:00
Jim Huang
53ef0614e8 Annotate more commands 2021-08-09 21:35:19 +08:00
Jim Huang
971148e3ed Annotate 'mknod' command 2021-08-09 21:19:40 +08:00
Jim Huang
2ac8a81945 Add hyperlinks to microkernel examples 2021-08-09 21:17:22 +08:00
Jim Huang
5786975d89 Update tLDP hyperlink 2021-08-09 21:12:04 +08:00
Jim Huang
bb3466461a Add hyperlink to Understanding The Linux Kernel 2021-08-09 21:11:15 +08:00
Jim Huang
e0ad741c8c Fix layout with \LaTeX 2021-08-09 21:07:35 +08:00
Jim Huang
3208d46d46 Always mention \LaTeX rather than plain text form 2021-08-09 20:53:50 +08:00
Jim Huang
fe0ad50e6f Fix cross reference 2021-08-09 20:51:12 +08:00
Jim Huang
ebfe5404c0 Use the newer entries for Linux kernel documentation 2021-08-09 20:40:09 +08:00
Jim Huang
1b487e5931 Annotate the path 2021-08-09 20:35:24 +08:00
Jim Huang
91418dec73 Remove out-of-date kernel source descriptions 2021-08-09 20:31:03 +08:00
Jim Huang
375bdd0ccf Unify the annotations
This patch enforces the annotations by means of the following:
  * \cpp : C/C++ code, functions, variables, macros, symbols
  * \sh : commands, executable files
  * \verb : path and filenames
2021-08-09 20:20:38 +08:00
VxTeemo
d1c0efeec9
fix minor typo
verb warp wrong at line 330 "linux/.config"
2021-08-09 17:21:56 +08:00
Arush Sharma
51d96f56e5
fix minor typo
Fixes a very minor typo.
2021-08-08 02:23:07 +05:30
Jim Huang
d0721da3d9 Tidy the rest of chapters 2021-08-07 18:35:28 +08:00
Jim Huang
2303d5c851 Tidy section: Optimizations 2021-08-07 11:02:49 +08:00
Jim Huang
40e83aa14b Tidy section: The Device Model 2021-08-07 10:59:15 +08:00
Jim Huang
939bd4e9ab Tidy section: Crypto 2021-08-07 10:56:16 +08:00
Jim Huang
e1d31e9500 Tidy section: Interrupt Handlers 2021-08-07 10:35:52 +08:00
Jim Huang
768b70e95e Tidy section: Scheduling Tasks 2021-08-07 10:27:05 +08:00
Jim Huang
2c1f4d185b Tidy section: Replacing Print Macros
FIXME: we should rewrite this section
2021-08-07 10:24:08 +08:00
Jim Huang
4a34cc69b3 Tidy section: Avoiding Collisions and Deadlocks 2021-08-07 10:16:08 +08:00
Jim Huang
678757e19c Tidy section: Blocking Processes and threads 2021-08-07 10:07:22 +08:00
Jim Huang
3070689d19 Update document maintainer information 2021-08-07 09:52:03 +08:00
asas1asas200
92b646ed64
proc_ops: Be aware of kernel API changes (#13)
The proc_ops structure is defined in <include/linux/proc_fs.h> since
Linux v5.6+.
In older kernels, file_operations structure is used for custom hooks in
/proc file system. However, it contains some members that are unnecessary
in VFS, and every time VFS expands file_operations set, /proc code comes
bloated.

On the other hand, not only the space, but also some operations were
saved by this structure to improve its performance.
2021-08-06 18:08:05 +08:00
Jim Huang
466e8a00fd cat_nonblock: Use canonical name scheme and fix unintended assignment 2021-08-05 14:28:12 +08:00
吳建興
634c3659a8
Fix typo. 2021-08-05 02:16:36 +08:00
RinHizakura
5940dd9faa
Revise hello-5 and its output (#38)
For the example module hello_5, the book showed the incorrect output
in corresponding with its execution results.

In addition, this patch changes from myintArray[2] = {-1, -1} to
myintArray[2] = {420, 420}, which help the readers distinguish from
the kernel messages.
2021-08-04 23:42:10 +08:00
吳建興
a7f81a2cfc
Fix typo.
There is a typo in chapter 0.6.3.
2021-08-04 09:33:21 +08:00
Jim Huang
7c129a4276 Minor wording tweak 2021-08-03 06:29:52 +08:00
demonsome
45769753d3
procfs1: Fix parameter descriptions (#34)
In "procfs1.c," the "buffer" is actually the second parameter of procfile_read().
The "offset" is the fourth one.
2021-08-02 23:01:34 +08:00
demonsome
65a8f5a1d6
Unify device node name "/proc/helloworld" (#33)
The file name "proc helloworld" was not consistent with that of the later
sentences. The latter sentences use the device node name "/proc/helloworld".
2021-08-02 22:59:19 +08:00
Jim Huang
749f0392bb Tidy section: system calls 2021-08-02 02:57:31 +08:00
Jim Huang
6689090085 Tidy section: device files 2021-08-02 02:43:35 +08:00
fennecJ
044cfefe65
Generate HTML via make4ht (#20)
This patch generates HTML files with "make4ht" in the "html" directory.

Known issues with "make4ht":
Running "make4ht -suf html5 -d html lkmpg.tex" will cause the following
flaws:
1. The layout was unsatisfying.
2. After parsing TeX, it stoped at "\tableofcontents" with errors.
3. Several unneeded files were generated.
4. No way to specify the destination filename for HTML generation.

Solutions/workaround:
1. Use customized configuration file "html.cfg" to specify the layout style.
2. Turn off the \tableofcontents section when using make4ht. However, this
    results in the lack of table of contents in HTML. It can be fixed by
    appending "\Configure{tableofcontents*}{chapter,section,subsection}"
    to configuration file.
3. The build system removes the temporary files.
4. Use a symbolic link "index.html" to "lkmpg.html".
2021-08-02 02:42:39 +08:00
Hsin-Hsiang Peng
d097d0c472
Add package xparse (#31)
The package xparse should be included since
\NewDocumentCommand is part of it
2021-08-02 02:24:09 +08:00
Jim Huang
4639ca1b26 Remove out-of-date versioing scheme 2021-08-01 22:41:28 +08:00
Jim Huang
6026699a40 Tidy section: Character Device drivers 2021-08-01 16:21:01 +08:00
Jim Huang
4257b6ddcb Tidy section: Preliminaries 2021-08-01 15:03:49 +08:00
Jim Huang
09bde29531 Zircon kernel was formerly called Magenta
The renaming appeared in 2017.
2021-08-01 14:15:59 +08:00