Skip to content

Commit 42d842d

Browse files
author
deployBot
committed
Deploy at Wed Apr 10 00:57:48 UTC 2024
1 parent a33ff5b commit 42d842d

36 files changed

+174
-237
lines changed
Lines changed: 51 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,64 @@
11
==================================
2-
Assignment 1 - Kprobe based tracer
2+
作业 1——基于 Kprobe 的跟踪器
33
==================================
44

5-
- Deadline: :command:`Monday, 10 April 2023, 23:00`
5+
- 截止日期: :command:`2023 年 4 月 10 日,23:00`
66

7-
Assignment's Objectives
7+
作业目标
88
=======================
99

10-
* gaining knowledge related to the instrumentation of functions in the Linux kernel (``kretprobes`` mechanism)
11-
* gaining knowledge regarding the ``/proc`` file system from the Linux kernel
12-
* get familiar with data structures specific to the Linux kernel (``hash table`` and ``list``)
10+
* 掌握与 Linux 内核中函数仪器化(instrumentation)相关的知识 (``kretprobes`` 机制)
11+
* 掌握 Linux 内核中的 ``/proc`` 文件系统
12+
* 熟悉 Linux 内核特定的数据结构 (``哈希表`` ``链表``)
1313

14-
Statement
14+
题目描述
1515
=========
1616

17-
Build a kernel operations surveillant.
17+
构建一个内核操作监视器(surveillant)。
1818

19-
With this surveillant, we aim to intercept:
19+
通过这个监视器,我们的目标是拦截:
2020

21-
* ``kmalloc`` and ``kfree`` calls
22-
* ``schedule`` calls
23-
* ``up`` and ``down_interruptible`` calls
24-
* ``mutex_lock`` and ``mutex_unlock`` calls
21+
* ``kmalloc`` ``kfree`` 调用
22+
* ``schedule`` 调用
23+
* ``up`` ``down_interruptible`` 调用
24+
* ``mutex_lock`` ``mutex_unlock`` 调用
2525

26-
The surveillant will hold, at the process level, the number of calls for each of the above functions.
27-
For the ``kmalloc`` and ``kfree`` calls the total quantity of allocated and deallocated memory will be
28-
shown.
26+
监视器将在进程级别上保存上述每个函数的调用次数。对于 ``kmalloc`` 和 ``kfree`` 调用,将显示已分配和释放的内存总量。
2927

30-
The surveillant will be implemented as a kernel module with the name ``tracer.ko``.
28+
监视器需要以内核模块的形式实现,名称为 ``tracer.ko``
3129

32-
Implementation details
30+
实现细节
3331
----------------------
3432

35-
The interception will be done by recording a sample (``kretprobe``) for each of the above functions. The
36-
surveillant will retain a list/hashtable with the monitored processes and will account for
37-
the above information for these processes.
33+
拦截将通过记录每个上述函数的样本 (``kretprobe``) 来完成。监视器将保留一个包含被监视进程的列表/哈希表,并为这些进程记录上述信息。
3834

39-
For the control of the list/hashtable with the monitored processes, a char device called ``/dev/tracer``
40-
will be used, with major `10` and minor `42`. It will expose an ``ioctl`` interface with two arguments:
35+
为了控制包含被监视进程的列表/哈希表,我们需要使用名为 ``/dev/tracer`` 的字符设备,主设备号为 `10`,次设备号为 `42`。它将暴露一个带有两个参数的 ``ioctl`` 接口:
4136

42-
* the first argument is the request to the monitoring subsystem:
37+
* 第一个参数是对监视子系统的请求:
4338

4439
* ``TRACER_ADD_PROCESS``
4540
* ``TRACER_REMOVE_PROCESS``
4641

47-
* the second argument is the PID of the process for which the monitoring request will be executed
42+
* 第二个参数是要执行监视请求的进程的 PID
4843

49-
In order to create a char device with major `10` you will need to use the `miscdevice <https://elixir.bootlin.com/linux/latest/source/include/linux/miscdevice.h>`__ interface in the kernel.
50-
Definitions of related macros can be found in the `tracer.h header <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/src/tracer.h>`__.
44+
为了使用主设备号 `10` 创建字符设备,你需要在内核中使用 `miscdevice <https://elixir.bootlin.com/linux/latest/source/include/linux/miscdevice.h>`__ 接口。相关宏的定义可以在 `tracer.h 头文件 <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/src/tracer.h>`__ 中找到。
5145

52-
Since the ``kmalloc`` function is inline for instrumenting the allocated amount of memory, the ``__kmalloc``
53-
function will be inspected as follows:
46+
由于 ``kmalloc`` 函数是内联的,无法对分配的内存量进行仪器化,因此我们将检查 ``__kmalloc`` 函数:
5447

55-
* a ``kretprobe`` will be used, which will retain the amount of memory allocated and the address of the allocated memory area.
56-
* the ``.entry_handler`` and ``.handler`` fields in the ``kretprobe`` structure will be used to retain information about the amount of memory allocated and the address from which the allocated memory starts.
48+
* 我们需要使用 ``kretprobe``,它将保留已分配的内存量和已分配内存区域的地址。
49+
* ``kretprobe`` 结构中的 ``.entry_handler`` 和 ``.handler`` 字段将用于保留已分配的内存量和分配的内存起始地址。
5750

5851
.. code-block:: C
5952
6053
static struct kretprobe kmalloc_probe = {
61-
.entry_handler = kmalloc_probe_entry_handler, /* entry handler */
62-
.handler = kmalloc_probe_handler, /* return probe handler */
54+
.entry_handler = kmalloc_probe_entry_handler, /* 进入处理程序 */
55+
.handler = kmalloc_probe_handler, /* 返回 probe 处理程序 */
6356
.maxactive = 32,
6457
};
6558
66-
Since the ``kfree`` function only receives the address of the memory area to be freed, in order to determine
67-
the total amount of memory freed, we will need to determine its size based on the address of the area.
68-
This is possible because there is an address-size association made when inspecting the ``__kmalloc`` function.
59+
由于 ``kfree`` 函数只接收要释放的内存区域的地址,为了确定释放的总内存量,我们需要根据该区域的地址确定其大小。这是可行的,因为系统在检查 ``__kmalloc`` 函数时进行了地址大小的关联。
6960

70-
For the rest of the instrumentation functions it is enough to use a ``kretprobe``.
61+
对于其余的仪器化函数,使用 ``kretprobe`` 就足够了。
7162

7263
.. code-block:: C
7364
@@ -76,18 +67,11 @@ For the rest of the instrumentation functions it is enough to use a ``kretprobe`
7667
.maxactive = 32,
7768
};
7869
79-
The virtual machine kernel has the ``CONFIG_DEBUG_LOCK_ALLOC`` option enabled where the ``mutex_lock`` symbol
80-
is a macro that expands to ``mutex_lock_nested``. Thus, in order to obtain information about the ``mutex_lock``
81-
function you will have to instrument the ``mutex_lock_nested`` function.
70+
虚拟机内核已启用 ``CONFIG_DEBUG_LOCK_ALLOC`` 选项,其中 ``mutex_lock`` 符号是一个将展开为 ``mutex_lock_nested`` 的宏。因此,为了获取有关 ``mutex_lock`` 函数的信息,你需要对 ``mutex_lock_nested`` 函数进行仪器化。
8271

83-
Processes that have been added to the list/hashtable and that end their execution will be removed
84-
from the list/hashtable. Also, a process will be removed from the dispatch list/hashtable following
85-
the ``TRACER_REMOVE_PROCESS`` operation.
72+
添加到列表/哈希表的进程在执行结束时将从列表/哈希表中移除。此外,根据 ``TRACER_REMOVE_PROCESS`` 操作,系统将从调度列表/哈希表中移除一个进程。
8673

87-
The information retained by the surveillant will be displayed via the procfs file system, in the ``/proc/tracer`` file.
88-
For each monitored process an entry is created in the ``/proc/tracer`` file having as first field the process PID.
89-
The entry will be read-only, and a read operation on it will display the retained results. An example of
90-
displaying the contents of the entry is:
74+
监视器保留的信息将通过 procfs 文件系统显示在 ``/proc/tracer`` 文件中。每个受监视的进程,在 ``/proc/tracer`` 文件中都会有一个条目,其第一个字段是进程的 PID。该条目是只读的,对其进行读操作将显示保留的结果。显示条目内容的示例:
9175

9276
.. code-block:: console
9377
@@ -98,31 +82,23 @@ displaying the contents of the entry is:
9882
1244 0 0 0 0 1221 100 1023 1023 1002
9983
1337 123 99 125952 101376 193821 992 81921 7421 6392
10084
101-
Testing
85+
测试
10286
=======
10387

104-
In order to simplify the assignment evaluation process, but also to reduce the mistakes of the submitted assignments,
105-
the assignment evaluation will be done automatically with the help of a
106-
`test script <https://github.com/linux-kernel-labs/linux/blob/master/tools/labs/templates/assignments/1-tracer/checker/_checker>`__ called `_checker`.
107-
The test script assumes that the kernel module is called `tracer.ko`.
88+
为了简化作业评估过程,同时也为了减少提交作业时的错误,作业评估将通过一个名为 `_checker` 的 `测试脚本 <https://github.com/linux-kernel-labs/linux/blob/master/tools/labs/templates/assignments/1-tracer/checker/_checker>`__ 自动进行。测试脚本假定内核模块名为 `tracer.ko`。
10889

109-
QuickStart
90+
快速开始
11091
==========
11192

112-
It is mandatory to start the implementation of the assignment from the code skeleton found in the `src <https://gitlab.cs.pub.ro/so2/1-tracer/-/tree/master/src>`__ directory.
113-
There is only one header in the skeleton called `tracer.h <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/src/tracer.h>`__.
114-
You will provide the rest of the implementation. You can add as many `*.c`` sources and additional `*.h`` headers.
115-
You should also provide a Kbuild file that will compile the kernel module called `tracer.ko`.
116-
Follow the instructions in the `README.md file <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/README.md>`__ of the `assignment's repo <https://gitlab.cs.pub.ro/so2/1-tracer>`__.
93+
你必须从 `src <https://gitlab.cs.pub.ro/so2/1-tracer/-/tree/master/src>`__ 目录中的代码模板开始实现作业。模板中只有一个名为 `tracer.h <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/src/tracer.h>`__ 的头文件。你需要提供其余的实现。你可以添加任意数量的 `*.c` 源文件和额外的 `*.h` 头文件。你还应该提供一个名为 `tracer.ko` 的 Kbuild 文件来编译内核模块。请按照 `作业仓库 <https://gitlab.cs.pub.ro/so2/1-tracer>`__ 的 `README.md 文件 <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/README.md>`__ 中的说明进行操作。
11794

11895

119-
Tips
96+
提示
12097
----
12198

122-
To increase your chances of getting the highest grade, read and follow the Linux kernel
123-
coding style described in the `Coding Style document <https://elixir.bootlin.com/linux/v4.19.19/source/Documentation/process/coding-style.rst>`__.
99+
要想增加获得最高分的机会,请阅读并遵循 Linux 内核中描述的 `编码风格规范 <https://elixir.bootlin.com/linux/v4.19.19/source/Documentation/process/coding-style.rst>`__。
124100

125-
Also, use the following static analysis tools to verify the code:
101+
此外,使用以下静态分析工具来验证代码:
126102

127103
- checkpatch.pl
128104

@@ -145,38 +121,30 @@ Also, use the following static analysis tools to verify the code:
145121
$ sudo apt-get install cppcheck
146122
$ cppcheck /path/to/your/tracer.c
147123
148-
Penalties
124+
扣分项
149125
---------
150126

151-
Information about assigments penalties can be found on the
152-
`General Directions page <https://ocw.cs.pub.ro/courses/so2/teme/general>`__. In addition, the following
153-
elements will be taken into account:
127+
关于作业扣分的信息可以在 `基本说明文件 <https://ocw.cs.pub.ro/courses/so2/teme/general>`__ 中找到。此外,以下因素还将被考虑:
154128

155-
* *-2*: missing of proper disposal of resources (``kretprobes``, entries in ``/proc``)
156-
* *-2*: data synchronization issues for data used by multiple executing instances (e.g. the list/hashtable)
129+
* *-2*:未正确释放资源 (``kretprobes``, ``/proc`` 中的条目)
130+
* *-2*:多个执行实例使用的数据的数据同步问题(例如,列表/哈希表)
157131

158-
In exceptional cases (the assigment passes the tests but it is not complying with the requirements)
159-
and if the assigment does not pass all the tests, the grade may decrease more than mentioned above.
132+
在特殊情况下(作业通过了测试但不符合要求),以及如果作业未全部通过测试,成绩可能会降低得更多。
160133

161-
Submitting the assigment
134+
提交作业
162135
------------------------
163136

164-
The assignment will be graded automatically using the `vmchecker-next <https://github.com/systems-cs-pub-ro/vmchecker-next/wiki/Student-Handbook>`__ infrastructure.
165-
The submission will be made on moodle on the `course's page <https://curs.upb.ro/2022/course/view.php?id=5121>`__ to the related assignment.
166-
You will find the submission details in the `README.md file <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/README.md>`__ of the `repo <https://gitlab.cs.pub.ro/so2/1-tracer>`__.
137+
作业将由 `vmchecker-next <https://github.com/systems-cs-pub-ro/vmchecker-next/wiki/Student-Handbook>`__ 基础设施自动评分。提交作业将在 moodle 的 `课程页面 <https://curs.upb.ro/2022/course/view.php?id=5121>`__ 上与相关作业相关联。你可以在 `仓库 <https://gitlab.cs.pub.ro/so2/1-tracer>`__ 的 `README.md 文件 <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/README.md>`__ 中找到提交详细信息。
167138

168-
169-
Resources
139+
资源
170140
=========
171141

172-
* `Documentation/kprobes.txt <https://www.kernel.org/doc/Documentation/kprobes.txt>`__ - description of the ``kprobes`` subsystem from Linux kernel sources.
173-
* `samples/kprobes/ <https://elixir.bootlin.com/linux/latest/source/samples/kprobes>`__ - some examples of using ``kprobes`` from Linux kernel sources.
142+
* `Documentation/kprobes.txt <https://www.kernel.org/doc/Documentation/kprobes.txt>`__ ——Linux 内核源代码中关于 ``kprobes`` 子系统的描述。
143+
* `samples/kprobes/ <https://elixir.bootlin.com/linux/latest/source/samples/kprobes>`__ ——Linux 内核源代码中使用 ``kprobes`` 的一些示例。
174144

175-
We recommend that you use gitlab to store your homework. Follow the directions in
176-
`README <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/README.md>`__.
145+
我们建议你使用 gitlab 来存储你的作业。请按照 `README <https://gitlab.cs.pub.ro/so2/1-tracer/-/blob/master/README.md>`__ 中的说明操作。
177146

178-
Questions
147+
问题
179148
=========
180149

181-
For questions about the topic, you can consult the mailing `list archives <http://cursuri.cs.pub.ro/pipermail/so2/>`__
182-
or you can write a question on the dedicated Teams channel.
150+
如有相关问题,你可以参考邮件 `列表存档 <http://cursuri.cs.pub.ro/pipermail/so2/>`__ 或在专用的 Teams 频道上提问。

index.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -945,21 +945,21 @@ <h1>Linux 内核教学<a class="headerlink" href="#linux" title="永久链接至
945945
<li class="toctree-l3"><a class="reference internal" href="so2/assign0-kernel-api.html#section-9">问题</a></li>
946946
</ul>
947947
</li>
948-
<li class="toctree-l2"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html">Assignment 1 - Kprobe based tracer</a><ul>
949-
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#assignment-s-objectives">Assignment's Objectives</a></li>
950-
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#statement">Statement</a><ul>
951-
<li class="toctree-l4"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#implementation-details">Implementation details</a></li>
948+
<li class="toctree-l2"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html">作业 1——基于 Kprobe 的跟踪器</a><ul>
949+
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-1">作业目标</a></li>
950+
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-2">题目描述</a><ul>
951+
<li class="toctree-l4"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-3">实现细节</a></li>
952952
</ul>
953953
</li>
954-
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#testing">Testing</a></li>
955-
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#quickstart">QuickStart</a><ul>
956-
<li class="toctree-l4"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#tips">Tips</a></li>
957-
<li class="toctree-l4"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#penalties">Penalties</a></li>
958-
<li class="toctree-l4"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#submitting-the-assigment">Submitting the assigment</a></li>
954+
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-4">测试</a></li>
955+
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-5">快速开始</a><ul>
956+
<li class="toctree-l4"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-6">提示</a></li>
957+
<li class="toctree-l4"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-7">扣分项</a></li>
958+
<li class="toctree-l4"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-8">提交作业</a></li>
959959
</ul>
960960
</li>
961-
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#resources">Resources</a></li>
962-
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#questions">Questions</a></li>
961+
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-9">资源</a></li>
962+
<li class="toctree-l3"><a class="reference internal" href="so2/assign1-kprobe-based-tracer.html#section-10">问题</a></li>
963963
</ul>
964964
</li>
965965
<li class="toctree-l2"><a class="reference internal" href="so2/assign2-driver-uart.html">Assignment 2 - Driver UART</a><ul>

objects.inv

28 Bytes
Binary file not shown.

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

so2/assign-collaboration.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
</ul>
9393
</li>
9494
<li class="toctree-l2"><a class="reference internal" href="assign0-kernel-api.html">作业 0——内核 API</a></li>
95-
<li class="toctree-l2"><a class="reference internal" href="assign1-kprobe-based-tracer.html">Assignment 1 - Kprobe based tracer</a></li>
95+
<li class="toctree-l2"><a class="reference internal" href="assign1-kprobe-based-tracer.html">作业 1——基于 Kprobe 的跟踪器</a></li>
9696
<li class="toctree-l2"><a class="reference internal" href="assign2-driver-uart.html">Assignment 2 - Driver UART</a></li>
9797
<li class="toctree-l2"><a class="reference internal" href="assign3-software-raid.html">Assignment 3 - Software RAID</a></li>
9898
<li class="toctree-l2"><a class="reference internal" href="assign4-transport-protocol.html">Assignment 4 - SO2 Transport Protocol</a></li>

0 commit comments

Comments
 (0)