From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mga18.intel.com ([134.134.136.126]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fGv3F-0006Dg-1j for speck@linutronix.de; Fri, 11 May 2018 01:32:45 +0200 Date: Thu, 10 May 2018 16:32:40 -0700 From: Andi Kleen Subject: [MODERATED] Re: [PATCH v4 3/8] L1TFv4 6 Message-ID: <20180510233240.GL13616@tassilo.jf.intel.com> References: <07a23314494bcaf78e47852462364a6d57e9b3b1.1525900921.git.ak@linux.intel.com> MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: > > +static inline u64 flip_protnone_guard(u64 oldval, u64 val, u64 mask) > > +{ > > + /* > > + * When a PTE transitions from NONE to !NONE or vice-versa > > + * invert the PFN part to stop speculation. > > + * pte_pfn undoes this when needed. > > + */ > > + if ((oldval & _PAGE_PROTNONE) != (val & _PAGE_PROTNONE)) > > I might be missing something, but. pte_pfn() uses protnone_mask() which in > turn uses __pte_needs_invert(). __pte_needs_invert() checks for > > (val & (_PAGE_PRESENT|_PAGE_PROTNONE)) == _PAGE_PROTNONE > > so the above condition is not matching the counterpart. So shouldn't that > be: > > if (__pte_needs_invert(oldval) != __pte_needs_invert(val)) > > Hmm? _PAGE_PROTNONE aliases with global. For the general case you have to check P to avoid mishandling kernel ptes. I believe it's safe in that case because noone will change global through pte_modify. But can use the inlines too. It likely will generate a few more instructions, but I doubt we need any micro optimization here. -Andi