<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=COMP3000_Operating_Systems_W25%3A_Tutorial_8</id>
	<title>COMP3000 Operating Systems W25: Tutorial 8 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=COMP3000_Operating_Systems_W25%3A_Tutorial_8"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_W25:_Tutorial_8&amp;action=history"/>
	<updated>2026-04-22T08:48:40Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_W25:_Tutorial_8&amp;diff=25034&amp;oldid=prev</id>
		<title>Lianyingzhao: Created page with &quot;In this tutorial, you’ll be learning about how virtual addresses are mapped to physical addresses (the address translation) and continue to use kernel modules to extract information that only the kernel has access to. In particular, the kernel module performs a 5-level page table walk to find out the physical address corresponding to a userspace virtual address. In addition to what was discussed in the class, You can also read [https://en.wikipedia.org/wiki/Intel_5-lev...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_W25:_Tutorial_8&amp;diff=25034&amp;oldid=prev"/>
		<updated>2025-03-07T06:01:04Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;In this tutorial, you’ll be learning about how virtual addresses are mapped to physical addresses (the address translation) and continue to use kernel modules to extract information that only the kernel has access to. In particular, the kernel module performs a 5-level page table walk to find out the physical address corresponding to a userspace virtual address. In addition to what was discussed in the class, You can also read [https://en.wikipedia.org/wiki/Intel_5-lev...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;In this tutorial, you’ll be learning about how virtual addresses are mapped to physical addresses (the address translation) and continue to use kernel modules to extract information that only the kernel has access to. In particular, the kernel module performs a 5-level page table walk to find out the physical address corresponding to a userspace virtual address. In addition to what was discussed in the class, You can also read [https://en.wikipedia.org/wiki/Intel_5-level_paging more about 5-level paging], if interested.&lt;br /&gt;
&lt;br /&gt;
==General Instructions (same for all tutorials)==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Click on Expand to view.&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Tutorials are graded based on participation and effort (&amp;#039;&amp;#039;&amp;#039;so no need to struggle to have the “correct” answers — what matters is the attempts and sufficient thinking reflected in your answers&amp;#039;&amp;#039;&amp;#039;). Submit your answers on Brightspace as a single text file named &amp;quot;&amp;lt;username&amp;gt;-comp3000-t&amp;lt;n&amp;gt;.txt&amp;quot; (where username is your MyCarletonOne username and n is the tutorial number). The first four lines of this file should be &amp;quot;COMP 3000 Tutorial &amp;lt;n&amp;gt;&amp;quot;, your name, student number, and the date of submission. Your submitted answers must at least respond to all the items in the &amp;#039;&amp;#039;&amp;#039;Tasks/Questions&amp;#039;&amp;#039;&amp;#039; section and include your thinking and exploration (or even confusion) for each question.&lt;br /&gt;
&lt;br /&gt;
The deadline is usually four days after the tutorial date (see the actual deadline on the submission entry under Tools -&amp;gt; Assignments). Note that the submission entry is enforced by the system, so you may fail to get the effort marks even if it is one minute past the deadline.&lt;br /&gt;
&lt;br /&gt;
You should also check in with your assigned TA. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
WARNING: The commands and programs in this tutorial are potentially extremely dangerous and may result in crashes or loss of data. Additionally, questions may not work as expected on a machine other than the course VM. For that reason, you are strongly encouraged to do this tutorial on the provided OpenStack or Virtualbox virtual machine.&lt;br /&gt;
&lt;br /&gt;
To get started, we will first examine the source code for &amp;lt;tt&amp;gt;3000physicalview.c&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2.c&amp;lt;/tt&amp;gt;, both of which are in [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w25/tut8/3000physicalview.tar.gz 3000physicalview.tar.gz].&lt;br /&gt;
&lt;br /&gt;
==Tasks part A: Getting Started==&lt;br /&gt;
Compile &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; using the provided &amp;lt;tt&amp;gt;Makefile&amp;lt;/tt&amp;gt; (i.e., by running &amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Insert &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; by running &amp;lt;tt&amp;gt;make insert&amp;lt;/tt&amp;gt;. Confirm that the module is inserted using &amp;lt;tt&amp;gt;lsmod&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Examine the call to &amp;lt;tt&amp;gt;copy_from_user()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;copy_to_user()&amp;lt;/tt&amp;gt; on lines 120 and 132 of &amp;lt;tt&amp;gt;3000physicalview.c&amp;lt;/tt&amp;gt; (as also discussed in the lecture). Consider the following:&lt;br /&gt;
#* How are these functions different from &amp;lt;tt&amp;gt;get_user()&amp;lt;/tt&amp;gt;/&amp;lt;tt&amp;gt;put_user()&amp;lt;/tt&amp;gt; that we have seen in the previous tutorial?&lt;br /&gt;
#* Why are these functions necessary? Couldn&amp;#039;t we just access the userspace address directly? What could happen if we did?&lt;br /&gt;
# &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; exposes its API to userspace in the form of an &amp;lt;tt&amp;gt;ioctl(2)&amp;lt;/tt&amp;gt; call. Consider the following:&lt;br /&gt;
#* What is an ioctl? How is it different from a read or write system call? Hint: check &amp;lt;tt&amp;gt;man 2 ioctl&amp;lt;/tt&amp;gt;.&lt;br /&gt;
#* How does &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; implement its ioctl? What arguments does it take?&lt;br /&gt;
#* How does &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; call the ioctl? What arguments does it pass to the ioctl?&lt;br /&gt;
# Which function does the virtual-to-physical translation? What type is &amp;lt;tt&amp;gt;current-&amp;gt;mm&amp;lt;/tt&amp;gt;? How does it give you the address of the &amp;lt;tt&amp;gt;pgd&amp;lt;/tt&amp;gt;? Recall the page table walk explained in the lecture and see how it’s reflected in this function (writing it down is optional).&lt;br /&gt;
# Once you’ve got the page frame number (pfn), how is the physical address (phys) calculated? Describe in words.&lt;br /&gt;
&lt;br /&gt;
==Tasks part B: Examining Physical Memory Mappings==&lt;br /&gt;
# With &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; inserted, run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; and examine the output. Note that it presents virtual memory addresses on the left, and physical addresses on the right. Are these mappings consistent with what you expected (e.g., in terms of patterns)?&lt;br /&gt;
# Compare &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; with &amp;lt;tt&amp;gt;3000memview&amp;lt;/tt&amp;gt; from Tutorial 2. What is similar about their code, and what is different? How similar is their output?&lt;br /&gt;
# Do you notice a pattern in the virtual addresses of &amp;lt;tt&amp;gt;buf[i]&amp;lt;/tt&amp;gt;? Is this same pattern present in the physical addresses? Why or why not?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; a few more times and consider the following:&lt;br /&gt;
#* Are the virtual addresses the same or different between runs? How about physical addresses?&lt;br /&gt;
#* Some physical addresses don&amp;#039;t seem to be changing between runs. Which ones? Why do you think this might be the case?&lt;br /&gt;
# Force the kernel to drop the virtual memory cache using &amp;lt;tt&amp;gt;sync &amp;amp;&amp;amp; echo 3 | sudo tee /proc/sys/vm/drop_caches&amp;lt;/tt&amp;gt;. Run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; one more time and note that the physical addresses that stayed the same previously have now changed. What do you think just happened?&lt;br /&gt;
&lt;br /&gt;
==Tasks part C: Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to Monitor &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt;== &lt;br /&gt;
Now recall what you tried with eBPF in Tutorial 7. We can also do something similar to watch the interaction between &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt;. &lt;br /&gt;
Note: No in-depth understanding of eBPF is expected in this course. You only need to understand what is involved and discussed. Feel free to read more if interested.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Use the following &amp;quot;one-liner&amp;quot; (as it is just a one-line string within the single quotation marks) in a new terminal session first and in the orginal one run &amp;lt;tt&amp;gt;./3000memview2&amp;lt;/tt&amp;gt; as above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;tt&amp;gt;sudo bpftrace -e &amp;#039;tracepoint:syscalls:sys_enter_ioctl { printf(&amp;quot;%s: fd=%d; cmd=%d; arg=%ld \n&amp;quot;, comm, args-&amp;gt;fd, args-&amp;gt;cmd, args-&amp;gt;arg); }&amp;#039; | grep 3000memview2&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What does this one-liner do? As always, you can check &amp;lt;tt&amp;gt;man bpftrace&amp;lt;/tt&amp;gt; if needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;(&amp;lt;b&amp;gt;Optional&amp;lt;/b&amp;gt; in the submission but you should do it) It seems the command above does not show useful information as the third argument is actually a pointer. So, to be able to show the two arguments &amp;lt;tt&amp;gt;virt&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;phys&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;3000physicalview.h&amp;lt;/tt&amp;gt;, you will need to create a *.bt file.&lt;br /&gt;
Refer to &amp;lt;tt&amp;gt;/usr/sbin/*.bt&amp;lt;/tt&amp;gt; and convert the one-liner above into something like &amp;lt;tt&amp;gt;snoop3000physicalview.bt&amp;lt;/tt&amp;gt;, so that when it runs it prints the &amp;lt;tt&amp;gt;virt&amp;lt;/tt&amp;gt; passed in and the &amp;lt;tt&amp;gt;phys&amp;lt;/tt&amp;gt; that is returned.&lt;br /&gt;
The code will be posted and explained.&lt;br /&gt;
&amp;lt;br&amp;gt; Note: if you choose to directly include the header file you need to create a copy and remove the &amp;lt;tt&amp;gt;MODULE_*&amp;lt;/tt&amp;gt; macros. Otherwise, you can simply include the struct definition.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lianyingzhao</name></author>
	</entry>
</feed>