{"id":1332,"date":"2015-02-23T18:12:11","date_gmt":"2015-02-23T18:12:11","guid":{"rendered":"http:\/\/rglinuxtech.com\/?p=1332"},"modified":"2015-02-23T18:18:28","modified_gmt":"2015-02-23T18:18:28","slug":"nvidia-driver-fix-for-kernel-4-0-and-earlier","status":"publish","type":"post","link":"https:\/\/rglinuxtech.com\/?p=1332","title":{"rendered":"NVIDIA &#8211; Driver Fix, for Kernel 4.0. and Earlier.."},"content":{"rendered":"<p>I have hacked together a kernel-version-friendly fix for the latest NVIDIA driver (<strong>346.35<\/strong>) which works with Kernel <strong>4.0-rc1<\/strong> (and later) and also for previous kernel versions..\u00a0\u00a0 Thanks are due to <strong><em>juston_li<\/em> <\/strong>for producing the actual code changes needed..\u00a0 <a title=\"https:\/\/devtalk.nvidia.com\/default\/topic\/813458\/linux\/linux-4-0-rc1-346-35-build-error-_cr4-functions-fix\/\" href=\"https:\/\/devtalk.nvidia.com\/default\/topic\/813458\/linux\/linux-4-0-rc1-346-35-build-error-_cr4-functions-fix\/\" target=\"_blank\">https:\/\/devtalk.nvidia.com\/default\/topic\/813458\/linux\/linux-4-0-rc1-346-35-build-error-_cr4-functions-fix\/<\/a><\/p>\n<p>Unpack the NVIDIA driver:<\/p>\n<pre><em><strong>.\/NVIDIA-Linux-x86_64-346.35.run -x<\/strong><\/em><\/pre>\n<p>Edit <strong>NVIDIA-Linux-x86_64-346.35\/kernel\/nv-pat.c<\/strong><\/p>\n<p>Around line 34, change<\/p>\n<pre><strong>{<\/strong>\r\n<strong> unsigned long cr0 = read_cr0();<\/strong>\r\n<strong> write_cr0(((cr0 &amp; (0xdfffffff)) | 0x40000000));<\/strong>\r\n<strong> wbinvd();<\/strong>\r\n<strong> *cr4 = read_cr4();<\/strong>\r\n<strong> if (*cr4 &amp; 0x80) write_cr4(*cr4 &amp; ~0x80);<\/strong>\r\n<strong> __flush_tlb();<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>to<\/p>\n<pre><strong>{<\/strong>\r\n<strong> unsigned long cr0 = read_cr0();<\/strong>\r\n<strong> write_cr0(((cr0 &amp; (0xdfffffff)) | 0x40000000));<\/strong>\r\n<strong> wbinvd();<\/strong>\r\n<strong>#if LINUX_VERSION_CODE &lt; KERNEL_VERSION(4, 0, 0)<\/strong>\r\n<strong> *cr4 = read_cr4();<\/strong>\r\n<strong> if (*cr4 &amp; 0x80) write_cr4(*cr4 &amp; ~0x80);<\/strong>\r\n<strong> __flush_tlb();<\/strong>\r\n<strong>#else<\/strong>\r\n<strong> *cr4 = __read_cr4();<\/strong>\r\n<strong> if (*cr4 &amp; 0x80) __write_cr4(*cr4 &amp; ~0x80);<\/strong>\r\n<strong> __flush_tlb();<\/strong>\r\n<strong>#endif<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>..and around line 46, change<\/p>\n<pre><strong>  wbinvd();<\/strong>\r\n <strong> __flush_tlb();<\/strong>\r\n <strong> write_cr0((cr0 &amp; 0x9fffffff));<\/strong>\r\n <strong> if (cr4 &amp; 0x80) write_cr4(cr4);<\/strong>\r\n <strong>}<\/strong><\/pre>\n<p>to<\/p>\n<pre><strong>  wbinvd();<\/strong>\r\n <strong> __flush_tlb();<\/strong>\r\n <strong> write_cr0((cr0 &amp; 0x9fffffff));<\/strong>\r\n <strong>#if LINUX_VERSION_CODE &lt; KERNEL_VERSION(4, 0, 0)<\/strong>\r\n <strong> if (cr4 &amp; 0x80) write_cr4(cr4);<\/strong>\r\n <strong>#else<\/strong>\r\n <strong> if (cr4 &amp; 0x80) __write_cr4(cr4);<\/strong>\r\n <strong>#endif<\/strong>\r\n <strong>}<\/strong><\/pre>\n<p>Then recompile, etc&#8230;<\/p>\n<p>I have tested this with both Kernel <strong>4.0-rc1<\/strong> and <strong>3.19.0<\/strong>, and the compile now completes successfully on both versions..<\/p>\n<p><em>Robert Gadsdon.\u00a0\u00a0 February 23, 2015.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have hacked together a kernel-version-friendly fix for the latest NVIDIA driver (346.35) which works with Kernel 4.0-rc1 (and later) and also for previous kernel versions..\u00a0\u00a0 Thanks are due to juston_li for producing the actual code changes needed..\u00a0 https:\/\/devtalk.nvidia.com\/default\/topic\/813458\/linux\/linux-4-0-rc1-346-35-build-error-_cr4-functions-fix\/ Unpack the NVIDIA driver: .\/NVIDIA-Linux-x86_64-346.35.run -x Edit NVIDIA-Linux-x86_64-346.35\/kernel\/nv-pat.c Around line 34, change { unsigned long cr0 = read_cr0(); <span class=\"excerpt-dots\">&hellip;<\/span> <a class=\"more-link\" href=\"https:\/\/rglinuxtech.com\/?p=1332\"><span class=\"more-msg\">Continue reading &rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5,6,11,14,15,18,19],"tags":[161,1019,1025,1024,983,1175],"class_list":["post-1332","post","type-post","status-publish","format-standard","hentry","category-compilation","category-crash-and-burn","category-hacks","category-kernel","category-linux-2","category-nvidia","category-opinion","tag-fix","tag-kernel-4-0-rc1","tag-kernel-version-friendly","tag-nv-pat-c","tag-nvidia-346-35","tag-success"],"_links":{"self":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts\/1332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1332"}],"version-history":[{"count":3,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts\/1332\/revisions"}],"predecessor-version":[{"id":1335,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts\/1332\/revisions\/1335"}],"wp:attachment":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}