<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Dear Fellow Kernelnewbies,<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">I wrote an application that calls mmap64() on /dev/kmem to memory map all of kernel virtual memory in this kernel address range from Documentation/x86/x86_64/mm.txt:<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">ffff880000000000 - ffffc7ffffffffff (=64 TB) direct mapping of all phys. Memory<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">I limit the top of the range to what&#8217;s in the kernel variable high_memory, which I obtained for use in user space by printk()ing it from a simple kernel module that I wrote for that purpose. Sloppy, I know, but this is prototype code at
 this point.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">First thing I found was that the mmap64() call failed because my kernel (RHEL6) didn&#8217;t have CONFIG_DEVKMEM defined so /dev/kmem didn&#8217;t even exist. So I rebuilt the kernel with CONFIG_DEVKMEM configured. Now /dev/kmem exists, but the mmap64()
 call still fails due to CONFIG_STRICT_DEVMEN being configured, the purpose of which seems to be to cripple /dev/kmem and /dev/mem so that only the first MB of RAM and ioremapped registers can be accessed as part of a security thing.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">So I am now contemplating turning CONFIG_STRICT_DEVMEN off in my configuration and rebuilding the kernel, but I am concerned that it&#8217;s still going to fail because CONFIG_X86_PAT is configured and looking at the code it appears that so long
 as CONFIG_X86_PAT is configured mmap access to RAM via these devices is going to be prohibited either by the range_is_allowed() function in drivers/char/mem.c (which kicks in when CONFIG_STRICT_DEVMEN is enabled) or the identical range_is_allowed() function
 in arch/x86/pat.c (which kicks in when CONFIG_STRICT_DEVMEM is not configured). In the latter case it appears the mem driver&#8217;s call to phys_mem_access_prot_allowed() via the weak alias in mem.c will be replaced by the strong one in pat.c, which calls its range_is_allowed()
 function.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Am I reading this right, that if I keep CONFIG_X86_PAT enabled I will not be able to mmap kernel memory regardless of my setting of CONFIG_STRICT_DEVMEM?<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">If so, can somebody explain why this needs to be like this when CONFIG_X86_PAT is enabled?<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">There&#8217;s comments in the source about avoiding &#8220;cache aliasing&#8221; in pat.c, but I don&#8217;t understand what that means.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">What are the downsides of disabling CONFIG_X86_PAT?<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Jeff Haran<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body>
</html>