Return-Path: Received: from mga07.intel.com ([134.134.136.100]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fLcap-0003ZI-OG for speck@linutronix.de; Thu, 24 May 2018 00:50:52 +0200 Subject: [MODERATED] Re: [PATCH v5 8/8] L1TFv4 1 References: <20180523215726.A931B61157@crypto-ml.lab.linutronix.de> From: Dave Hansen Message-ID: <388e3d89-7af0-a284-893e-173904bff471@linux.intel.com> Date: Wed, 23 May 2018 15:50:46 -0700 MIME-Version: 1.0 In-Reply-To: <20180523215726.A931B61157@crypto-ml.lab.linutronix.de> Content-Type: multipart/mixed; boundary="KoqKVVwt9l7oOK9Fd6hJU5kjIwMoFGxlb"; protected-headers="v1" To: speck@linutronix.de List-ID: This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) --KoqKVVwt9l7oOK9Fd6hJU5kjIwMoFGxlb Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable =2E.. > +bool pfn_modify_allowed(unsigned long pfn, pgprot_t prot) > +{ > + if (!boot_cpu_has(X86_BUG_L1TF)) > + return true; > + if (!__pte_needs_invert(pgprot_val(prot))) > + return true; > + /* If it's real memory always allow */ > + if (pfn_valid(pfn)) > + return true; > + if (pfn > l1tf_pfn_limit() && !capable(CAP_SYS_ADMIN)) > + return false; > + return true; > +} =2E.. > + /* > + * 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)) =3D=3D 0) { > + error =3D prot_none_walk(vma, start, end, newflags); > + if (error) > + return error; > + } Is it worth moving the boot_cpu_has(X86_BUG_L1TF) check into arch_has_pfn_modify_check()? As it stands now, we will always unconditionally do the prot_none_walk() for vulnerable VMAs, but we don't even have to do *that* if we are not vulnerable. It probably doesn't matter as you mentioned because doing an mprotect(PROT_NONE) on a VM_PFNMAP|VM_MIXEDMAP VMA is likely to be rare, but we might as well avoid the walk if we can. --KoqKVVwt9l7oOK9Fd6hJU5kjIwMoFGxlb--