Return-path: Received: from mga05.intel.com ([192.55.52.43]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fEizJ-0003wX-H2 for speck@linutronix.de; Sat, 05 May 2018 00:15:37 +0200 Subject: [MODERATED] Re: [PATCH 8/8] L1TFv3 3 References: <62b4a73ea2fd6453e0aa3d7493ce8a46b5bb13ca.1525403858.git.ak@linux.intel.com> From: Dave Hansen Message-ID: Date: Fri, 4 May 2018 15:15:34 -0700 MIME-Version: 1.0 In-Reply-To: <62b4a73ea2fd6453e0aa3d7493ce8a46b5bb13ca.1525403858.git.ak@linux.intel.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: > +bool pfn_modify_allowed(unsigned long pfn, pgprot_t prot) > +{ > + if (!boot_cpu_has(X86_BUG_L1TF)) > + return true; > + if ((pgprot_val(prot) & (_PAGE_PRESENT|_PAGE_PROTNONE)) != > + _PAGE_PROTNONE) > + return true; Just bikeshedding: it would be nice to have all the (_PAGE_PROTNONE | _PAGE_PRESENT)) == _PAGE_PROTNONE; checks consolidated into a single helper, but this adds like the 6th site that does this, so it's not just this code. > + /* If it's real memory always allow */ > + if (pfn_valid(pfn)) > + return true; > + if ((pfn & (1ULL << (boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT))) && > + !capable(CAP_SYS_ADMIN)) > + return false; The CAP_SYS_ADMIN kinda surprised me here. Was there a reason we don't just do this up front in the function? Seems like we'd always allow pfn modification if CAP_SYS_ADMIN. Also, that PFN calculation is dying for a helper. > + /* > + * Do PROT_NONE PFN permission checks here when we can still > + * bail out without undoing a lot of state. This is a rather > + * uncommon case, so doesn't need to be very optimized. > + */ > + if (arch_has_pfn_modify_check() && > + (vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) && > + (newflags & (VM_READ|VM_WRITE|VM_EXEC)) == 0) { > + error = prot_none_walk(vma, start, end, newflags); > + if (error) > + return error; > + } Otherwise it looks OK to me. The need for arch_has_pfn_modify_check() wasn't obvious until the end, but it all came together. This seems like a pretty reasonable compromise for something we think is really rare. Although, I do wonder: should we put a WARN_ONCE() or something else in here to help us see if *anybody* does this? Or even a VM counter? Or do we just wait for the bug reports from somebody doing frequent 1-page PROT_NONEs in a 100GB VMA? :)