<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux Kernel Study</title>
	<atom:link href="http://kernelstudy.net/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://kernelstudy.net</link>
	<description></description>
	<lastBuildDate>Tue, 11 May 2010 02:17:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Interesting article &#8216;Interview: Ingo Molnar&#8217;</title>
		<link>http://kernelstudy.net/?p=177</link>
		<comments>http://kernelstudy.net/?p=177#comments</comments>
		<pubDate>Tue, 11 May 2010 02:06:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[vm]]></category>

		<guid isPermaLink="false">http://kernelstudy.net/?p=177</guid>
		<description><![CDATA[One of the main contributor into the Linux kernel is Ingo Molnar. I found this article while checking removal of &#8216;get_irqlock()&#8217; in Kernel 2.6. Even though, it doesn&#8217;t mention about this in detail, it was good material to understand what jobs Ingo did and what was the main feature of O(1) scheduler and others. Check [...]]]></description>
			<content:encoded><![CDATA[<p>One of the main contributor into the Linux kernel is Ingo Molnar. I found this article while checking removal of &#8216;get_irqlock()&#8217; in Kernel 2.6.</p>
<p>Even though, it doesn&#8217;t mention about this in detail, it was good material to understand what jobs Ingo did and what was the main feature of O(1) scheduler and others.</p>
<p>Check this out : <a href="http://kerneltrap.org/node/517">http://kerneltrap.org/node/517</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kernelstudy.net/?feed=rss2&amp;p=177</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>meaning of flags field in /proc/cpuinfo</title>
		<link>http://kernelstudy.net/?p=175</link>
		<comments>http://kernelstudy.net/?p=175#comments</comments>
		<pubDate>Tue, 13 Apr 2010 00:42:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Process]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[flags]]></category>
		<category><![CDATA[proc]]></category>

		<guid isPermaLink="false">http://kernelstudy.net/?p=175</guid>
		<description><![CDATA[Cited from : http://www.gentoo-wiki.info/Gentoo:/proc/cpuinfo About This file contains useful information about your processor(s). This page explains, what this file actually tells you. The following is an output from /proc/cpuinfo on a laptop with a Core 2 Duo T7200 CPU. processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 15 model name : [...]]]></description>
			<content:encoded><![CDATA[<p>Cited from : http://www.gentoo-wiki.info/Gentoo:/proc/cpuinfo</p>
<p> About</p>
<p>This file contains useful information about your processor(s). This page explains, what this file actually tells you.</p>
<p>The following is an output from /proc/cpuinfo on a laptop with a Core 2 Duo T7200 CPU.</p>
<p>processor       : 1<br />
vendor_id       : GenuineIntel<br />
cpu family      : 6<br />
model           : 15<br />
model name      : Intel(R) Core(TM)2 CPU         T7200  @ 2.00GHz<br />
stepping        : 6<br />
cpu MHz         : 1000.000<br />
cache size      : 4096 KB<br />
physical id     : 0<br />
siblings        : 2<br />
core id         : 1<br />
cpu cores       : 2<br />
fdiv_bug        : no<br />
hlt_bug         : no<br />
f00f_bug        : no<br />
coma_bug        : no<br />
fpu             : yes<br />
fpu_exception   : yes<br />
cpuid level     : 10<br />
wp              : yes<br />
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm<br />
bogomips        : 3990.09<br />
clflush size    : 64</p>
<p>As you can see, the file tells us we have one processor with two cores. Furthermore the cpu is clocked down to 1000 MHz. We also have a bunch of flags which tells us what extra instructions this processor has to offer.<br />
flags</p>
<p>The flags line tells us what extra instructions the processor has to offer. This is a listing of flags with a short explanation of each. There is an even shorter explanation in the file /usr/include/asm/cpufeature.h.</p>
<p>Intel flags (This table is currently identical with /usr/include/asm/cpufeature.h. Hopefully some hardware god will share his wisdom and expand this table. )<br />
Flag	Description	Common in processor types<br />
fpu	Onboard (x87) Floating Point Unit<br />
vme	Virtual Mode Extension<br />
de	Debugging Extensions<br />
pse	Page Size Extensions<br />
tsc	Time Stamp Counter: support for RDTSC and WRTSC instructions<br />
msr	Model-Specific Registers<br />
pae	Physical Address Extensions: ability to access 64GB of memory; only 4GB can be accessed at a time though<br />
mce	Machine Check Architecture<br />
cx8	CMPXCHG8 instruction<br />
apic	Onboard Advanced Programmable Interrupt Controller<br />
sep	Sysenter/Sysexit Instructions; SYSENTER is used for jumps to kernel memory during system calls, and SYSEXIT is used for jumps back to the user code<br />
mtrr	Memory Type Range Registers<br />
pge	Page Global Enable<br />
mca	Machine Check Architecture<br />
cmov	CMOV instruction<br />
pat	Page Attribute Table<br />
pse36	36-bit Page Size Extensions: allows to map 4 MB pages into the first 64GB RAM, used with PSE.<br />
pn	Processor Serial-Number; only available on Pentium 3<br />
clflush	CLFLUSH instruction<br />
dtes	Debug Trace Store<br />
acpi	ACPI via MSR<br />
mmx	MultiMedia Extension<br />
fxsr	FXSAVE and FXSTOR instructions<br />
sse	Streaming SIMD Extensions. Single instruction multiple data. Lets you do a bunch of the same operation on different pieces of input in a single clock tick.<br />
sse2	Streaming SIMD Extensions-2. More of the same.<br />
selfsnoop	CPU self snoop<br />
acc	Automatic Clock Control<br />
IA64	IA-64 processor Itanium.<br />
ht	HyperThreading. Introduces an imaginary second processor that doesn&#8217;t do much but lets you run threads in the same process a bit quicker.<br />
nx	No Execute bit. Prevents arbitrary code running via buffer overflows.<br />
pni	Prescott New Instructions aka. SSE3<br />
vmx	Intel Vanderpool hardware virtualization technology<br />
svm	AMD &#8220;Pacifica&#8221; hardware virtualization technology<br />
lm	&#8220;Long Mode,&#8221; which means the chip supports the AMD64 instruction set<br />
tm	&#8220;Thermal Monitor&#8221; Thermal throttling with IDLE instructions. Usually hardware controlled in response to CPU temperature.<br />
tm2	&#8220;Thermal Monitor 2&#8243; Decrease speed by reducing multipler and vcore.<br />
est	&#8220;Enhanced SpeedStep&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://kernelstudy.net/?feed=rss2&amp;p=175</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make a VM template without using LVM in KVM</title>
		<link>http://kernelstudy.net/?p=173</link>
		<comments>http://kernelstudy.net/?p=173#comments</comments>
		<pubDate>Wed, 03 Mar 2010 06:58:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Virt]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[qemu-img]]></category>
		<category><![CDATA[qemu-kvm]]></category>
		<category><![CDATA[virt-install]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://kernelstudy.net/?p=173</guid>
		<description><![CDATA[In my opinion, template is the most useful feature in virtualization technology. After creating one fully installed VM, you can create several temporary VMs from the original without spend lots of hours or lots of disk space. In LVM environment, you can use &#8216;snapshot&#8217; feature of lvcreate command. But, LVM volume is not easy to [...]]]></description>
			<content:encoded><![CDATA[<p>In my opinion, template is the most useful feature in virtualization technology. After creating one fully installed VM, you can create several temporary VMs from the original without spend lots of hours or lots of disk space. In LVM environment, you can use &#8216;snapshot&#8217; feature of lvcreate command. But, LVM volume is not easy to move between systems especially when you want to upgrade to the latest distribution just like Fedora.</p>
<p>If we can create new VMs from the file-based image, it could be very convenient to migrate between systems and easy to back up. With qemu-img utility you can do the same thing as LVM do.</p>
<p>Following are the steps I did to create new VM from the old one which is file-based.</p>

<div class="wp_codebox"><table><tr id="p1732"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p173code2"><pre class="bash" style="font-family:monospace;">$ qemu-img convert rhel4u5.img <span style="color: #660033;">-O</span> qcow2 rhel4u5.qcow2
$ qemu-img create <span style="color: #660033;">-b</span> rhel4u5.qcow2 <span style="color: #660033;">-f</span> qcow2 rhel4u5-test1.qcow2
$ virt-install <span style="color: #660033;">-nrhel4u5-test1</span> <span style="color: #660033;">-r512</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">--os-type</span>=linux <span style="color: #660033;">--os-variant</span>=rhel4 <span style="color: #660033;">--import</span> <span style="color: #660033;">--disk</span> <span style="color: #007800;">path</span>=rhel4u5-test1.qcow2</pre></td></tr></table></div>

<p>Easy, isn&#8217;t it?<br />
The first step is only necessary when your original VM was created with raw format.</p>
]]></content:encoded>
			<wfw:commentRss>http://kernelstudy.net/?feed=rss2&amp;p=173</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How could I reduce kernel&#8217;s binary size as small as distribution&#8217;s size</title>
		<link>http://kernelstudy.net/?p=167</link>
		<comments>http://kernelstudy.net/?p=167#comments</comments>
		<pubDate>Mon, 22 Feb 2010 01:28:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Core]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[fedora12]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[rhel5]]></category>

		<guid isPermaLink="false">http://kernelstudy.net/?p=167</guid>
		<description><![CDATA[The basic steps to compile kernel and modules are similar to following. 1 make modules &#38;&#38; make bzImage &#38;&#38; make modules_install &#38;&#38; make install It will install the kernel related files into the proper location after compile modules and kernel. But maybe you could be surprised by the final binaries size. Sometimes, it shows more [...]]]></description>
			<content:encoded><![CDATA[<p>The basic steps to compile kernel and modules are similar to following.</p>

<div class="wp_codebox"><table><tr id="p1677"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p167code7"><pre class="text" style="font-family:monospace;">make modules &amp;&amp; make bzImage &amp;&amp; make modules_install &amp;&amp; make install</pre></td></tr></table></div>

<p>It will install the kernel related files into the proper location after compile modules and kernel. But maybe you could be surprised by the final binaries size. Sometimes, it shows more than 10 times bigger size than distributor&#8217;s module and kernel size. It even happened with distribution&#8217;s configuration.</p>
<p>I will show some basic tips you can use to build your own kernel from distribution&#8217;s source files without any increase in size.</p>
<p>First, you should download source files from distributor&#8217;s site or get it from distribution media. In my case, I downloaded the kernel rpm from Red Hat Network (http://rhn.redhat.com).</p>
<p>After installing source rpms and you need to rebuild source codes from the spec.</p>

<div class="wp_codebox"><table><tr id="p1678"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p167code8"><pre class="text" style="font-family:monospace;">$ rpm -ivh kernel-2.6.18-128.1.1.el5.src.rpm
$ cd /usr/src/redhat/SPECS
$ rpmbuild -bp --target=i686 kernel-2.6.spec
$ cd /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.x86_64/</pre></td></tr></table></div>

<p>You can see the patched kernel codes in BUILD directory. After doing some modification for your purpose, it is time to rebuild kernel. To reduce kernel size, add &#8216;INSTALL_MOD_STRIP=1&#8242; options in make command.</p>

<div class="wp_codebox"><table><tr id="p1679"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p167code9"><pre class="text" style="font-family:monospace;">make modules &amp;&amp; make bzImage &amp;&amp; make INSTALL_MOD_STRIP=1 modules_install &amp;&amp; make INSTALL_MOD_STRIP=1 install</pre></td></tr></table></div>

<p>It will strip off unnecessary debug information from the compiled images. If you can keep another kernel images separately which has debug information for the debugging purpose.</p>
<p>This methods work for RHEL5 and Fedora 11 or 12 (I couldn&#8217;t check this with earlier version but would be applied for earlier version of Fedora). If you want to reduce sizes in RHEL4 or earlier version, you should strip off DEBUG_* related options from the configuration file before do compile.</p>
<p>Following is the part of RHEL4 spec file.</p>

<div class="wp_codebox"><table><tr id="p16710"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p167code10"><pre class="text" style="font-family:monospace;"># set the EXTRAVERSION to &lt;version&gt;custom, so that people who follow a kernel building howto
# don't accidentally overwrite their currently working moduleset and hose
# their system
perl -p -i -e &quot;s/^EXTRAVERSION.*/EXTRAVERSION = -%{release}custom/&quot; $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/Makefile
&nbsp;
# some config options may be appropriate for an rpm kernel build but are less so for custom user builds,
# change those to values that are more appropriate as default for people who build their own kernel.
perl -p -i -e &quot;s/^CONFIG_DEBUG_INFO.*/# CONFIG_DEBUG_INFO is not set/&quot; $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/configs/*
perl -p -i -e &quot;s/^.*CONFIG_DEBUG_PAGEALLOC.*/# CONFIG_DEBUG_PAGEALLOC is not set/&quot; $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/configs/*
perl -p -i -e &quot;s/^.*CONFIG_DEBUG_SLAB.*/# CONFIG_DEBUG_SLAB is not set/&quot; $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/configs/*
perl -p -i -e &quot;s/^.*CONFIG_DEBUG_SPINLOCK.*/# CONFIG_DEBUG_SPINLOCK is not set/&quot; $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/configs/*
perl -p -i -e &quot;s/^.*CONFIG_DEBUG_HIGHMEM.*/# CONFIG_DEBUG_HIGHMEM is not set/&quot; $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/configs/*
perl -p -i -e &quot;s/^.*CONFIG_MODULE_SIG.*/# CONFIG_MODULE_SIG is not set/&quot; $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/configs/*</pre></td></tr></table></div>

<p>As you can see, it strips off some DEBUG related options to blank.</p>
]]></content:encoded>
			<wfw:commentRss>http://kernelstudy.net/?feed=rss2&amp;p=167</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring a Bridge Interface for the KVM-based virtual machines</title>
		<link>http://kernelstudy.net/?p=165</link>
		<comments>http://kernelstudy.net/?p=165#comments</comments>
		<pubDate>Mon, 22 Feb 2010 00:26:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Virt]]></category>
		<category><![CDATA[bridge]]></category>
		<category><![CDATA[fedora12]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[NET]]></category>
		<category><![CDATA[virsh]]></category>
		<category><![CDATA[vm]]></category>

		<guid isPermaLink="false">http://kernelstudy.net/?p=165</guid>
		<description><![CDATA[If you are going to run virtualized host as a web server or some services for the clients, the systems should be accessible from the outside. Unfortunately, the default network configuration in KVM is NAT (Network Address Translation). It is good for some VMs who will co-work with other VMs, but for the server, it [...]]]></description>
			<content:encoded><![CDATA[<p>If you are going to run virtualized host as a web server or some services for the clients, the systems should be accessible from the outside. Unfortunately, the default network configuration in KVM is NAT (Network Address Translation). It is good for some VMs who will co-work with other VMs, but for the server, it can be a big obstacle.</p>
<p>The bridged network is a solution for that circumstances. Bridged network allows VMs to have their own IP addresses which are accessible from the outside.</p>
<p>I&#8217;ll show how you can create bridged network in here with one physical network device &#8211; eth0. In ethernet environment, you can use &#8216;brctl&#8217; command to administrate bridged network.</p>

<div class="wp_codebox"><table><tr id="p16520"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p165code20"><pre class="text" style="font-family:monospace;">[root@dhcp-160-193 ~]# brctl show
bridge name	bridge id		STP enabled	interfaces</pre></td></tr></table></div>

<p>Before you create bridge, you should make a backup of the files which will be used in this example.</p>

<div class="wp_codebox"><table><tr id="p16521"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p165code21"><pre class="text" style="font-family:monospace;">[root@dhcp-165-234 ~]# brctl show
bridge name	bridge id		STP enabled	interfaces
[root@dhcp-165-234 ~]# cd /etc/sysconfig/network-scripts/
[root@dhcp-165-234 network-scripts]# ls ifcfg-*
ifcfg-eth0  ifcfg-lo
[root@dhcp-165-234 network-scripts]# mkdir backup
[root@dhcp-165-234 network-scripts]# cp ifcfg-* backup</pre></td></tr></table></div>

<p>Dump current eth0 configuration using virsh command.</p>

<div class="wp_codebox"><table><tr id="p16522"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p165code22"><pre class="text" style="font-family:monospace;">[root@dhcp-165-234 network-scripts]# virsh iface-dumpxml eth0
&lt;interface type='ethernet' name='eth0'&gt;
  &lt;start mode='onboot'/&gt;
  &lt;mac address='00:21:9B:04:05:99'/&gt;
  &lt;protocol family='ipv4'&gt;
    &lt;dhcp peerdns='yes'/&gt;
  &lt;/protocol&gt;
&lt;/interface&gt;
[root@dhcp-165-234 network-scripts]# virsh iface-dumpxml eth0 &gt; bakup/eth0.xml</pre></td></tr></table></div>

<p>It will save your eth0&#8242;s configuration into backup/eth0.xml file. Next thing you need to is create XML file for bridge using the saved eth0.xml. Following is the br0.xml I created from eth0.xml.</p>

<div class="wp_codebox"><table><tr id="p16523"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p165code23"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;interface</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">'bridge'</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">'br0'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;start</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">'onboot'</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;protocol</span> <span style="color: #000066;">family</span>=<span style="color: #ff0000;">'ipv4'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dhcp</span> <span style="color: #000066;">peerdns</span>=<span style="color: #ff0000;">'yes'</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/protocol<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bridge<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;interface</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">'ethernet'</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">'eth0'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mac</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">'00:21:9B:04:05:99'</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bridge<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Next thing to do is define the bridge interface to libvirt as shown below.</p>

<div class="wp_codebox"><table><tr id="p16524"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p165code24"><pre class="text" style="font-family:monospace;">[root@dhcp-165-234 network-scripts]# virsh iface-define br0.xml
error: Failed to define interface from br0.xml
error: invalid argument in virGetInterface</pre></td></tr></table></div>

<p>It will show error messages but it&#8217;s OK at this point. Next step is to configure ifcfg-eth0 and create ifcfg-br0 interface. Following is my configuration.</p>

<div class="wp_codebox"><table><tr id="p16525"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p165code25"><pre class="text" style="font-family:monospace;">[root@dhcp-160-181 network-scripts]# cat ifcfg-eth0
DEVICE=eth0
HWADDR=00:21:9B:04:05:99
ONBOOT=yes
BRIDGE=br0
[root@dhcp-160-181 network-scripts]# cat ifcfg-br0
DEVICE=br0
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=dhcp
PEERDNS=yes</pre></td></tr></table></div>

<p>Next step is restart network service. You also need to stop NetworkManager service.</p>

<div class="wp_codebox"><table><tr id="p16526"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p165code26"><pre class="text" style="font-family:monospace;">[root@dhcp-160-181 network-scripts]# service network restart
Shutting down interface eth0:  bridge br0 does not exist!
                                                           [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Disabling IPv4 packet forwarding:  net.ipv4.ip_forward = 0
                                                           [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]
Bringing up interface br0:                                 [  OK  ]</pre></td></tr></table></div>

<p>Now, br0 is activated.</p>

<div class="wp_codebox"><table><tr id="p16527"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" id="p165code27"><pre class="text" style="font-family:monospace;">[root@dhcp-160-181 network-scripts]# virsh iface-list
Name                 State      MAC Address
--------------------------------------------
br0                  active     00:21:9b:04:05:99
lo                   active     00:00:00:00:00:00
&nbsp;
[root@dhcp-160-181 network-scripts]# ifconfig 
br0       Link encap:Ethernet  HWaddr 00:21:9B:04:05:99  
          inet addr:100.20.50.181  Bcast:100.20.50.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1021814 errors:0 dropped:0 overruns:0 frame:0
          TX packets:583293 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:373480692 (356.1 MiB)  TX bytes:170390832 (162.4 MiB)
&nbsp;
eth0      Link encap:Ethernet  HWaddr 00:21:9B:04:05:99  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1812236 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1342244 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:666795722 (635.9 MiB)  TX bytes:263334525 (251.1 MiB)
          Memory:fdfc0000-fdfe0000 
...</pre></td></tr></table></div>

<p>Now you are ready to use bridge interface in VMs. If you have a guest already, you only need to change the interface part as shown below. You don&#8217;t need to change mac address of course. <img src='http://kernelstudy.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_codebox"><table><tr id="p16528"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p165code28"><pre class="text" style="font-family:monospace;">[root@dhcp-160-181 networks]# virsh dumpxml win2003 | grep -A 3 interface
    &lt;interface type='bridge'&gt;
      &lt;mac address='52:54:00:42:54:04'/&gt;
      &lt;source bridge='br0'/&gt;
      &lt;target dev='vnet0'/&gt;
    &lt;/interface&gt;</pre></td></tr></table></div>

<p>If you are creating new virtual machines, your only job is to choose &#8216;eth0 (Bridge br0)&#8217; in Network configuration step.</p>
<p>Unfortunately, at this time I write this, RHEL5 does not have some features in libvirt so not working well. I tested this on Fedora 12 and some other useful links when you use RHEL5.4 instead of Fedora 12 are <a href="http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5.4/html/Virtualization_Guide/sect-Virtualization-Network_Configuration-Bridged_networking_with_libvirt.html">http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5.4/html/Virtualization_Guide/sect-Virtualization-Network_Configuration-Bridged_networking_with_libvirt.html</a> and <a href="http://benincosa.org/blog/?p=93">http://benincosa.org/blog/?p=93</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://kernelstudy.net/?feed=rss2&amp;p=165</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set up test environment with two virtual machines.</title>
		<link>http://kernelstudy.net/?p=157</link>
		<comments>http://kernelstudy.net/?p=157#comments</comments>
		<pubDate>Mon, 18 Jan 2010 02:19:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Virt]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[FS]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[NET]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://kernelstudy.net/?p=157</guid>
		<description><![CDATA[To test some problems usually I have to have two machines which is not easy to have. Especially if I have to configure it for each version, RHEL4, RHEL5, Fedora, etc. Virtualzation comes here to solve those kinds of difficulty. But, just installing new operating system each time is also not a perfect solution. You [...]]]></description>
			<content:encoded><![CDATA[<p>To test some problems usually I have to have two machines which is not easy to have. Especially if I have to configure it for each version, RHEL4, RHEL5, Fedora, etc.</p>
<p>Virtualzation comes here to solve those kinds of difficulty. But, just installing new operating system each time is also not a perfect solution. You should wait couple of hours before you can do test something. It&#8217;s also applied even though you already have that operating system because you need fresh system. Most easiest way is to use LVM&#8217;s snapshot feature.</p>
<p>Here are the steps I did to build my own test environment.</p>
<p>To use snapshot feature, you should make LVM partition first. There are many useful documentations for this steps. Easiest way to make room for virtual image is using &#8216;system-config-lvm&#8217; if you use Fedora or RHEL. With GUI, you can resize the existing volume and make new volume on the free space. This new volume will be the space for the original operating system.</p>
<p>If you preper command line tools, you can use &#8216;lvreduce&#8217; for reducing exsiting filesystem&#8217;s size and &#8216;lvcreate&#8217; for creating new logical volume.</p>
<p>In my case, I created logical volume for RHEL5U4 with name rhel5u4. Following is the output from &#8216;lvdisplay&#8217; command.</p>

<div class="wp_codebox"><table><tr id="p15733"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p157code33"><pre class="text" style="font-family:monospace;">  --- Logical volume ---
  LV Name                /dev/VolGroup/rhel5u4
  VG Name                VolGroup
  LV UUID                kkk383-IDE3-Lzh1-tKm4-a3YT-3k23-EIKFD5E
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                20.00 GB
  Current LE             5120
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3</pre></td></tr></table></div>

<p>Create new virtual system with this volume. &#8216;virt-manager&#8217; is a good tool to this. I&#8217;ll not describe how to install new operating system with &#8216;virt-manager&#8217;.</p>
<p>After installing new operating system and configured everything that will be necessary to work basically, you also need to edit &#8216;/etc/hosts&#8217; file in this operating system if you want to make two different virtual machine easily communicate. I did it as following for my test environment.</p>

<div class="wp_codebox"><table><tr id="p15734"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p157code34"><pre class="text" style="font-family:monospace;">192.168.122.100		station1.example.com		station1
192.168.122.101		station2.example.com		station2</pre></td></tr></table></div>

<p>If you want have more than two systems, you also add more lines with new IP address. I decided to use internal IP addresses but if you want the systems accessible from the outside, you should build bridge network first. I&#8217;ll not describe it here. After add above lines in to the &#8216;etc/hosts&#8217; you need to shutdown the virtual machine and you will not use it until you want to install something common between each virtual machine.</p>
<p>It is time to create new volume for each virtual machine. I made simple script for this.</p>

<div class="wp_codebox"><table><tr id="p15735"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p157code35"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>VolGroup<span style="color: #000000; font-weight: bold;">/</span>rhel5u4_test1 <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	lvremove <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>VolGroup<span style="color: #000000; font-weight: bold;">/</span>rhel5u4_test1
<span style="color: #000000; font-weight: bold;">fi</span>
lvcreate <span style="color: #660033;">--size</span> 1g <span style="color: #660033;">--snapshot</span> <span style="color: #660033;">--name</span> rhel5u4_test1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>VolGroup<span style="color: #000000; font-weight: bold;">/</span>rhel5u4
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>VolGroup<span style="color: #000000; font-weight: bold;">/</span>rhel5u4_test2 <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	lvremove <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>VolGroup<span style="color: #000000; font-weight: bold;">/</span>rhel5u4_test2
<span style="color: #000000; font-weight: bold;">fi</span>
lvcreate <span style="color: #660033;">--size</span> 1g <span style="color: #660033;">--snapshot</span> <span style="color: #660033;">--name</span> rhel5u4_test2 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>VolGroup<span style="color: #000000; font-weight: bold;">/</span>rhel5u4</pre></td></tr></table></div>

<p>It will remove exsiting volume and will create new volume as a snapshot based on existing rhel5u4 volume with 1G of space for modification.</p>
<p>As a last step, you should fix IP address for each machine. If you do not, you can&#8217;t reach each machine with their name and always have to recheck current IP address for testing. Some documents says that it is necessary to restart dnsmasq because virtual machine get address from dnsmasq, but it it not true. Only thing you should have to do is stay on &#8216;virsh&#8217; command.</p>
<p>Basic steps are as something like following.</p>
<p>1. cd /etc/libvirt/qemu/networks/<br />
2. vi default.xml<br />
3. virsh net-destroy default<br />
4. virsh net-define default.xml<br />
5. virsh net-start default</p>
<p>At the second step, you should add each virtual machine&#8217;s MAC address with desired IP address. As a result, mine is something like this.</p>

<div class="wp_codebox"><table><tr id="p15736"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p157code36"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;network<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>default<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uuid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>8dc538f3-ce99-4708-8e53-46aad24e6157<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/uuid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forward</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">'nat'</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bridge</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">'virbr0'</span> <span style="color: #000066;">stp</span>=<span style="color: #ff0000;">'on'</span> <span style="color: #000066;">delay</span>=<span style="color: #ff0000;">'0'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ip</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">'192.168.122.1'</span> <span style="color: #000066;">netmask</span>=<span style="color: #ff0000;">'255.255.255.0'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dhcp<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;range</span> <span style="color: #000066;">start</span>=<span style="color: #ff0000;">'192.168.122.2'</span> <span style="color: #000066;">end</span>=<span style="color: #ff0000;">'192.168.122.254'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;host</span> <span style="color: #000066;">mac</span>=<span style="color: #ff0000;">'52:54:00:77:c8:94'</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">'station1.example.com'</span> <span style="color: #000066;">ip</span>=<span style="color: #ff0000;">'192.168.122.100'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;host</span> <span style="color: #000066;">mac</span>=<span style="color: #ff0000;">'52:54:00:af:5d:59'</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">'station2.example.com'</span> <span style="color: #000066;">ip</span>=<span style="color: #ff0000;">'192.168.122.101'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dhcp<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/network<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>You don&#8217;t need to restart dnsmasq or libvirtd at all. Just update this configuration file and restart each virtual machine is the enough step. From now, you have configured two systems and at any time you can restart with recreate snapshot.</p>
]]></content:encoded>
			<wfw:commentRss>http://kernelstudy.net/?feed=rss2&amp;p=157</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Videos about Android architecture</title>
		<link>http://kernelstudy.net/?p=147</link>
		<comments>http://kernelstudy.net/?p=147#comments</comments>
		<pubDate>Mon, 28 Dec 2009 11:54:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Core]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[phone]]></category>

		<guid isPermaLink="false">http://kernelstudy.net/?p=147</guid>
		<description><![CDATA[Recently, I&#8217;m fascinated by the Google&#8217;s Android platform. So, I started to study this but I hope I can start from very basic tutorials and hope it could be more helpful if it has a video format. Fortunately, Google provides several videos regarding Android. Here are some useful very basic videos.]]></description>
			<content:encoded><![CDATA[<p>Recently, I&#8217;m fascinated by the Google&#8217;s Android platform. So, I started to study this but I hope I can start from very basic tutorials and hope it could be more helpful if it has a video format.</p>
<p>Fortunately, Google provides several videos regarding Android.</p>
<p>Here are some useful very basic videos.</p>
<p><center><br />
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/Mm6Ju0xhUW8&#038;hl=ko_KR&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Mm6Ju0xhUW8&#038;hl=ko_KR&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/ITfRuRkf2TM&#038;hl=ko_KR&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ITfRuRkf2TM&#038;hl=ko_KR&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/iiD4fGjjXcc&#038;hl=ko_KR&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/iiD4fGjjXcc&#038;hl=ko_KR&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/ENRcZcnoptM&#038;hl=ko_KR&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ENRcZcnoptM&#038;hl=ko_KR&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br />
</center></p>
]]></content:encoded>
			<wfw:commentRss>http://kernelstudy.net/?feed=rss2&amp;p=147</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>/dev/kvm</title>
		<link>http://kernelstudy.net/?p=119</link>
		<comments>http://kernelstudy.net/?p=119#comments</comments>
		<pubDate>Thu, 11 Jun 2009 06:46:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Virt]]></category>
		<category><![CDATA[kvm]]></category>

		<guid isPermaLink="false">http://kernelstudy.net/?p=119</guid>
		<description><![CDATA[I&#8217;ll show the very basic path into the KVM from the User Space. If you loaded &#8216;kvm&#8217; module, you can find kvm as a device node, usually in /dev/ directory. This character device node provides the way to control Virtualization features such as checking the ability, creating VM, and destroying VM. While kvm module loading, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll show the very basic path into the KVM from the User Space. If you loaded &#8216;kvm&#8217; module, you can find kvm as a device node, usually in /dev/ directory. This character device node provides the way to control Virtualization features such as checking the ability, creating VM, and destroying VM.</p>
<p>While kvm module loading, it registers character device as a misc device.</p>

<div class="wp_codebox"><table><tr id="p11939"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p119code39"><pre class="c" style="font-family:monospace;">r <span style="color: #339933;">=</span> misc_register<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>kvm_dev<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">struct</span> file_operations kvm_chardev_ops <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        .<span style="color: #202020;">unlocked_ioctl</span> <span style="color: #339933;">=</span> kvm_dev_ioctl<span style="color: #339933;">,</span>
        .<span style="color: #202020;">compat_ioctl</span>   <span style="color: #339933;">=</span> kvm_dev_ioctl<span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">struct</span> miscdevice kvm_dev <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        KVM_MINOR<span style="color: #339933;">,</span>
        <span style="color: #ff0000;">&quot;kvm&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #339933;">&amp;</span>kvm_chardev_ops<span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>As you can see here, they only implemented ioctl call. It means that you can&#8217;t find anything useful with general read/write call or redirection on the command line. You always have to write an application to use kvm&#8217;s feature.</p>
<p>kvm_dev_ioctl function is implemented as following:</p>

<div class="wp_codebox"><table><tr id="p11940"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code" id="p119code40"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">long</span> kvm_dev_ioctl<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> file <span style="color: #339933;">*</span>filp<span style="color: #339933;">,</span>
                          <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> ioctl<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> arg<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">long</span> r <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>EINVAL<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>ioctl<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">case</span> KVM_GET_API_VERSION<span style="color: #339933;">:</span>
                r <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>EINVAL<span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>arg<span style="color: #009900;">&#41;</span>
                        <span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
                r <span style="color: #339933;">=</span> KVM_API_VERSION<span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">case</span> KVM_CREATE_VM<span style="color: #339933;">:</span>
                r <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>EINVAL<span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>arg<span style="color: #009900;">&#41;</span>
                        <span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
                r <span style="color: #339933;">=</span> kvm_dev_ioctl_create_vm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">case</span> KVM_CHECK_EXTENSION<span style="color: #339933;">:</span>
                r <span style="color: #339933;">=</span> kvm_dev_ioctl_check_extension_generic<span style="color: #009900;">&#40;</span>arg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">case</span> KVM_GET_VCPU_MMAP_SIZE<span style="color: #339933;">:</span>
                r <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>EINVAL<span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>arg<span style="color: #009900;">&#41;</span>
                        <span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
                r <span style="color: #339933;">=</span> PAGE_SIZE<span style="color: #339933;">;</span>     <span style="color: #808080; font-style: italic;">/* struct kvm_run */</span>
<span style="color: #339933;">#ifdef CONFIG_X86</span>
                r <span style="color: #339933;">+=</span> PAGE_SIZE<span style="color: #339933;">;</span>    <span style="color: #808080; font-style: italic;">/* pio data page */</span>
<span style="color: #339933;">#endif</span>
<span style="color: #339933;">#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET</span>
                r <span style="color: #339933;">+=</span> PAGE_SIZE<span style="color: #339933;">;</span>    <span style="color: #808080; font-style: italic;">/* coalesced mmio ring page */</span>
<span style="color: #339933;">#endif</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">case</span> KVM_TRACE_ENABLE<span style="color: #339933;">:</span>
        <span style="color: #b1b100;">case</span> KVM_TRACE_PAUSE<span style="color: #339933;">:</span>
        <span style="color: #b1b100;">case</span> KVM_TRACE_DISABLE<span style="color: #339933;">:</span>
                r <span style="color: #339933;">=</span> kvm_trace_ioctl<span style="color: #009900;">&#40;</span>ioctl<span style="color: #339933;">,</span> arg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                <span style="color: #b1b100;">return</span> kvm_arch_dev_ioctl<span style="color: #009900;">&#40;</span>filp<span style="color: #339933;">,</span> ioctl<span style="color: #339933;">,</span> arg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
out<span style="color: #339933;">:</span>
        <span style="color: #b1b100;">return</span> r<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>There are 7 predefined commands. If it is not recognized by this function, it goes into kvm_arch_dev_ioctl() function which do additional check with actual hardware module such as kvm_intel and kvm_adm.</p>
<p><strong>KVM_GET_API_VERSION</strong><br />
It returns the version of KVM. In kernel 2.6.30, it is 12 (defined in kvm.h as a KVM_API_VERSION).</p>
<p><strong>KVM_CREATE_VM</strong></p>
<p><strong>KVM_CHECK_EXTENSION</strong></p>
<p><strong>KVM_GET_VCPU_MMAP_SIZE</strong></p>
<p><strong>KVM_TRACE_ENABLE<br />
KVM_TRACE_PAUSE<br />
KVM_TRACE_DISABLE<br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://kernelstudy.net/?feed=rss2&amp;p=119</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How kernel determind the low and high memory zone?</title>
		<link>http://kernelstudy.net/?p=115</link>
		<comments>http://kernelstudy.net/?p=115#comments</comments>
		<pubDate>Tue, 24 Mar 2009 05:10:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MM]]></category>

		<guid isPermaLink="false">http://kernelstudy.net/?p=115</guid>
		<description><![CDATA[I thought Linux fixed highmem zone and low mem zone at the compile time. But, I was wrong. I even found the command line parameter named &#8216;highmem=&#8217; which can set the highmem size. Actually, this calculation is done during the initialization and following is the code which actually do the thing. 1 2 3 4 [...]]]></description>
			<content:encoded><![CDATA[<p>I thought Linux fixed highmem zone and low mem zone at the compile time. But, I was wrong. I even found the command line parameter named &#8216;highmem=&#8217; which can set the highmem size.</p>
<p>Actually, this calculation is done during the initialization and following is the code which actually do the thing.</p>

<div class="wp_codebox"><table><tr id="p11542"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
</pre></td><td class="code" id="p115code42"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
 * Determine low and high memory ranges:
 */</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> __init find_max_low_pfn<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> max_low_pfn<span style="color: #339933;">;</span>
&nbsp;
        max_low_pfn <span style="color: #339933;">=</span> max_pfn<span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>max_low_pfn <span style="color: #339933;">&gt;</span> MAXMEM_PFN<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>highmem_pages <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
                        highmem_pages <span style="color: #339933;">=</span> max_pfn <span style="color: #339933;">-</span> MAXMEM_PFN<span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>highmem_pages <span style="color: #339933;">+</span> MAXMEM_PFN <span style="color: #339933;">&lt;</span> max_pfn<span style="color: #009900;">&#41;</span>
                        max_pfn <span style="color: #339933;">=</span> MAXMEM_PFN <span style="color: #339933;">+</span> highmem_pages<span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>highmem_pages <span style="color: #339933;">+</span> MAXMEM_PFN <span style="color: #339933;">&gt;</span> max_pfn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        printk<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;only %luMB highmem pages available, ignoring highmem size of %uMB.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> pages_to_mb<span style="color: #009900;">&#40;</span>max_pfn <span style="color: #339933;">-</span> MAXMEM_PFN<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> pages_to_mb<span style="color: #009900;">&#40;</span>highmem_pages<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        highmem_pages <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                max_low_pfn <span style="color: #339933;">=</span> MAXMEM_PFN<span style="color: #339933;">;</span>
<span style="color: #339933;">#ifndef CONFIG_HIGHMEM</span>
                <span style="color: #808080; font-style: italic;">/* Maximum memory usable is what is directly addressable */</span>
                printk<span style="color: #009900;">&#40;</span>KERN_WARNING <span style="color: #ff0000;">&quot;Warning only %ldMB will be used.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
                                        MAXMEM<span style="color: #339933;">&gt;&gt;</span><span style="color: #0000dd;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>max_pfn <span style="color: #339933;">&gt;</span> MAX_NONPAE_PFN<span style="color: #009900;">&#41;</span>
                        printk<span style="color: #009900;">&#40;</span>KERN_WARNING <span style="color: #ff0000;">&quot;Use a PAE enabled kernel.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">else</span>
                        printk<span style="color: #009900;">&#40;</span>KERN_WARNING <span style="color: #ff0000;">&quot;Use a HIGHMEM enabled kernel.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                max_pfn <span style="color: #339933;">=</span> MAXMEM_PFN<span style="color: #339933;">;</span>
<span style="color: #339933;">#else /* !CONFIG_HIGHMEM */</span>
<span style="color: #339933;">#ifndef CONFIG_X86_PAE</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>max_pfn <span style="color: #339933;">&gt;</span> MAX_NONPAE_PFN<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        max_pfn <span style="color: #339933;">=</span> MAX_NONPAE_PFN<span style="color: #339933;">;</span>
                        printk<span style="color: #009900;">&#40;</span>KERN_WARNING <span style="color: #ff0000;">&quot;Warning only 4GB will be used.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        printk<span style="color: #009900;">&#40;</span>KERN_WARNING <span style="color: #ff0000;">&quot;Use a PAE enabled kernel.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">#endif /* !CONFIG_X86_PAE */</span>
<span style="color: #339933;">#endif /* !CONFIG_HIGHMEM */</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>highmem_pages <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
                        highmem_pages <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #339933;">#ifdef CONFIG_HIGHMEM</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>highmem_pages <span style="color: #339933;">&gt;=</span> max_pfn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        printk<span style="color: #009900;">&#40;</span>KERN_ERR <span style="color: #ff0000;">&quot;highmem size specified (%uMB) is bigger than pages available (%luMB)!.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> pages_to_mb<span style="color: #009900;">&#40;</span>highmem_pages<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> pages_to_mb<span style="color: #009900;">&#40;</span>max_pfn<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        highmem_pages <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>highmem_pages<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>max_low_pfn<span style="color: #339933;">-</span>highmem_pages <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">64</span><span style="color: #339933;">*</span><span style="color: #0000dd;">1024</span><span style="color: #339933;">*</span><span style="color: #0000dd;">1024</span><span style="color: #339933;">/</span>PAGE_SIZE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                                printk<span style="color: #009900;">&#40;</span>KERN_ERR <span style="color: #ff0000;">&quot;highmem size %uMB results in smaller than 64MB lowmem, ignoring it.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> pages_to_mb<span style="color: #009900;">&#40;</span>highmem_pages<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                highmem_pages <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                        max_low_pfn <span style="color: #339933;">-=</span> highmem_pages<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">#else</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>highmem_pages<span style="color: #009900;">&#41;</span>
                        printk<span style="color: #009900;">&#40;</span>KERN_ERR <span style="color: #ff0000;">&quot;ignoring highmem size on non-highmem kernel!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">#endif</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> max_low_pfn<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kernelstudy.net/?feed=rss2&amp;p=115</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how linux get maximum pfn number?</title>
		<link>http://kernelstudy.net/?p=111</link>
		<comments>http://kernelstudy.net/?p=111#comments</comments>
		<pubDate>Tue, 24 Mar 2009 04:52:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MM]]></category>

		<guid isPermaLink="false">http://kernelstudy.net/?p=111</guid>
		<description><![CDATA[I wondered where linux get information about memory capacity in the machine. In i386 machine, we can get information from BIOS or e820 which is shorthand for BIOS function name. You can find some information from whikipedia : http://en.wikipedia.org/wiki/E820 Anyway, after checking basic memory map information, kernel call following function to get max_pfn value. 1 [...]]]></description>
			<content:encoded><![CDATA[<p>I wondered where linux get information about memory capacity in the machine. In i386 machine, we can get information from BIOS or e820 which is shorthand for BIOS function name. You can find some information from whikipedia : http://en.wikipedia.org/wiki/E820</p>
<p>Anyway, after checking basic memory map information, kernel call following function to get max_pfn value.</p>

<div class="wp_codebox"><table><tr id="p11144"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code" id="p111code44"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
 * Find the highest page frame number we have available
 */</span>
<span style="color: #993333;">void</span> __init find_max_pfn<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
&nbsp;
        max_pfn <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>efi_enabled<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                efi_memmap_walk<span style="color: #009900;">&#40;</span>efi_find_max_pfn<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>max_pfn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> e820.<span style="color: #202020;">nr_map</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> start<span style="color: #339933;">,</span> end<span style="color: #339933;">;</span>
                <span style="color: #808080; font-style: italic;">/* RAM? */</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>e820.<span style="color: #202020;">map</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">type</span> <span style="color: #339933;">!=</span> E820_RAM<span style="color: #009900;">&#41;</span>
                        <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
                start <span style="color: #339933;">=</span> PFN_UP<span style="color: #009900;">&#40;</span>e820.<span style="color: #202020;">map</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">addr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                end <span style="color: #339933;">=</span> PFN_DOWN<span style="color: #009900;">&#40;</span>e820.<span style="color: #202020;">map</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">addr</span> <span style="color: #339933;">+</span> e820.<span style="color: #202020;">map</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>start <span style="color: #339933;">&gt;=</span> end<span style="color: #009900;">&#41;</span>
                        <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>end <span style="color: #339933;">&gt;</span> max_pfn<span style="color: #009900;">&#41;</span>
                        max_pfn <span style="color: #339933;">=</span> end<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kernelstudy.net/?feed=rss2&amp;p=111</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
