Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2212417imm; Tue, 10 Jul 2018 15:34:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpel/tfQDfjknUVTf8tEKKl1DAXD4Ex+W3LVGZJ4I3nlTMDuCGacN3eXoA+7v7J/bz1Bk+5v X-Received: by 2002:a63:9902:: with SMTP id d2-v6mr24341934pge.343.1531262081940; Tue, 10 Jul 2018 15:34:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531262081; cv=none; d=google.com; s=arc-20160816; b=DVPw8Z34OyjpWio80U1i+3XUrEDflMnzT32pMAGunML+SLAU8BSUU68BSGGcxHOv+x ld1KfxcEOVOeySTmB2J3eHZnZhqrP+IFFfs22ABUXT2I03aR1sbHHXXtEx1EsXY/5LO3 QPAfT0WPhifwNAWBrYIvai0VRTkpte+owN1/SPCtgUV4qvdFBucpAB5DjE6ql7cXn7sm VE7LDQewDopr6tKJUEyfWP1WuxE6opSJl7xr/vS0GVB7zc8hrTMUZzd2eVPBC+HT5LjO dlb2EJ+52LT20YJ4jOO+4bfv/tZ5dAhaSz+KrjswuO0BK9CwDUx+yottKNPPIzqZ7Gl4 pSgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=P7qLkyvMM20psQjOrTd1tFs8X6D34ICWpOYJuJEy8us=; b=mATCr2xYrVLNGpeGjFzdY3uFu+b/3zJDTy2jYxAdFx2olrWtmHcQ/zcC256znGr/P+ 67+PMsUpiq/SWLw1N7y+BzSqKkQWsrQ87X6Wsn5lbRpYQATD6tHy9UOPvOk8RbxAAq8J 80Ad3/1iGAwfc7Q0j9aSfdp7ljhclDYwwBbPllAq3VwF4mcszwGert1V3qTiXdmoginn q+zUoVjKWYdcW4o02obRmqVqaUldy77qS58fF4jM1zE2DUCR13S+xuT8izJrNiXOieLE gR1C4wZvDHyqp5uphrugp0yrS2NpJMPkK4dpjs3nD2ZcfHw27fDZifTkWai9DJyhpGo+ S8OQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j3-v6si17779806pgs.329.2018.07.10.15.34.27; Tue, 10 Jul 2018 15:34:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732690AbeGJWdw (ORCPT + 99 others); Tue, 10 Jul 2018 18:33:52 -0400 Received: from mga12.intel.com ([192.55.52.136]:33775 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732461AbeGJWc0 (ORCPT ); Tue, 10 Jul 2018 18:32:26 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2018 15:31:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,335,1526367600"; d="scan'208";a="70305403" Received: from 2b52.sc.intel.com ([143.183.136.52]) by fmsmga004.fm.intel.com with ESMTP; 10 Jul 2018 15:31:12 -0700 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , "Ravi V. Shankar" , Vedvyas Shanbhogue Cc: Yu-cheng Yu Subject: [RFC PATCH v2 11/27] x86/mm: Modify ptep_set_wrprotect and pmdp_set_wrprotect for _PAGE_DIRTY_SW Date: Tue, 10 Jul 2018 15:26:23 -0700 Message-Id: <20180710222639.8241-12-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180710222639.8241-1-yu-cheng.yu@intel.com> References: <20180710222639.8241-1-yu-cheng.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Update ptep_set_wrprotect() and pmdp_set_wrprotect() for _PAGE_DIRTY_SW. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/pgtable.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index ecbd3539a864..456a864aa605 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1170,7 +1170,18 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { + pte_t pte; + clear_bit(_PAGE_BIT_RW, (unsigned long *)&ptep->pte); + pte = *ptep; + + /* + * On platforms before CET, other threads could race to + * create a RO and _PAGE_DIRTY_HW PTE again. However, + * on CET platforms, this is safe without a TLB flush. + */ + pte = pte_move_flags(pte, _PAGE_DIRTY_HW, _PAGE_DIRTY_SW); + set_pte_at(mm, addr, ptep, pte); } #define flush_tlb_fix_spurious_fault(vma, address) do { } while (0) @@ -1220,7 +1231,18 @@ static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm, static inline void pmdp_set_wrprotect(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp) { + pmd_t pmd; + clear_bit(_PAGE_BIT_RW, (unsigned long *)pmdp); + pmd = *pmdp; + + /* + * On platforms before CET, other threads could race to + * create a RO and _PAGE_DIRTY_HW PMD again. However, + * on CET platforms, this is safe without a TLB flush. + */ + pmd = pmd_move_flags(pmd, _PAGE_DIRTY_HW, _PAGE_DIRTY_SW); + set_pmd_at(mm, addr, pmdp, pmd); } #define pud_write pud_write -- 2.17.1