Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp12863imm; Thu, 30 Aug 2018 13:01:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYfe7lq7qBVliu902gxXSJJDRp17T6Fy7r8fJpjRQwcK4Cgy0u4VYTI/0nN9lVXED0h/NVM X-Received: by 2002:a62:bd4:: with SMTP id 81-v6mr12146576pfl.67.1535659306234; Thu, 30 Aug 2018 13:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535659306; cv=none; d=google.com; s=arc-20160816; b=zQ/qU/e8DD6GaPfWmObkkeGVl05sWubeOuwoY5ty6+eb/AIGZg6RIZmSt1+Sq9Qdf3 hApU5fFzRXe8AllCLE1xKrJTxIhIILEZFkQq7XbGlLcmR1xl2wWIGj1ax3OSsoYjiLhi /3o5pBeiLlBc9LW7wmyTuvnA4cyk4mcWGAsfQjL/GQW29O0htkwRDQ4g4eqiN3e6SDK2 EHh2HIb/YZID38cjUikB9PvXLACAeVjGjnxrxIlLnUCE4Z5qODaMl6/XmHCHPRkbs5H8 Zeis7z6vA0XeGFrzFESF5f9IYgrhT6gVlLu0bfGTO/sAf1RwMrNehACp/AeaVeyITlDn 0Htg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature :arc-authentication-results; bh=g+rQpy8djYi0Iw6RI5TwjdBXdXca8lOddTytVmpYKx8=; b=Vug6aD9Tb9m+1zYiqJE5L/Fd4yUzJqn4eI3dnkJynizjIez0mpdOU7QwQ9grToc/Rg 8/PVFNdiAOdmx+GHO6Wp/ups9fXog2yvx4bLZMazBDqtQQEVlmW4XXnNFMiT3dTJLtlw hRjnv7uQpWi2QbjHISTc7n3SzN2Iwsu8T4Sv/XebXXRF+HOnLE3Rq/aXBUgsLu/9F1RN gpj8/U10cYsi9Ea4WTJZLKekDzoaBbbNQ/XJn2eqUk0bBYMLo+Y6kkrvrazptJlRxxhG K8V5+57ImOwVZ0CU7TQ+x6nfwMDj0z1FDfPPEc9ljQ52YkAqpSftVjlQnZ60YaNne5JZ g/Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Rj8y1i49; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k193-v6si7225878pge.4.2018.08.30.13.01.30; Thu, 30 Aug 2018 13:01:46 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Rj8y1i49; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727341AbeHaAD2 (ORCPT + 99 others); Thu, 30 Aug 2018 20:03:28 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:42506 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725893AbeHaAD1 (ORCPT ); Thu, 30 Aug 2018 20:03:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:To: Subject:Sender:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=g+rQpy8djYi0Iw6RI5TwjdBXdXca8lOddTytVmpYKx8=; b=Rj8y1i49574dk80BKAL+8+TJP I3MTT22buHOjJa/cimLape/XlGRnZspKxiq70xq0a3GT02khMAHjEGx3dIVlm0oZq53XHQCiWJtfk cwWvHg0FzdJYMz2sgc3dvaEMp4cNyELX5p1BZB0Ii/jhCYHhWG89IDJzSElPAar+zRZyJ5Tg8ABxl hDAn6szm0VVlr9dTCrpmUa0hKOlTiUElsKzyP41ss9zcEfJ0K4+IKYnmDINFwZ7VFM+oZc6tEZ5NE BjlWN4Ph8hcQhVLNCAGA2hb7Y2m39LvDQnJu0TZjUbkiNZlC6e8bMKeq8AifiKXIk9aFYBRtPnQV+ tztiUcKkA==; Received: from static-50-53-52-16.bvtn.or.frontiernet.net ([50.53.52.16] helo=midway.dunlab) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvT6B-0002oI-R2; Thu, 30 Aug 2018 19:59:23 +0000 Subject: Re: [RFC PATCH v3 12/24] x86/mm: Modify ptep_set_wrprotect and pmdp_set_wrprotect for _PAGE_DIRTY_SW To: Yu-cheng Yu , 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 References: <20180830143904.3168-1-yu-cheng.yu@intel.com> <20180830143904.3168-13-yu-cheng.yu@intel.com> From: Randy Dunlap Message-ID: <9879c17a-24da-d84a-5a7c-30bcbb473914@infradead.org> Date: Thu, 30 Aug 2018 12:59:21 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180830143904.3168-13-yu-cheng.yu@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/30/2018 07:38 AM, Yu-cheng Yu wrote: > When Shadow Stack is enabled, the read-only and PAGE_DIRTY_HW PTE > setting is reserved only for the Shadow Stack. To track dirty of > non-Shadow Stack read-only PTEs, we use PAGE_DIRTY_SW. > > Update ptep_set_wrprotect() and pmdp_set_wrprotect(). > > Signed-off-by: Yu-cheng Yu > --- > arch/x86/include/asm/pgtable.h | 42 ++++++++++++++++++++++++++++++++++ > 1 file changed, 42 insertions(+) > > diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h > index 4d50de77ea96..556ef258eeff 100644 > --- a/arch/x86/include/asm/pgtable.h > +++ b/arch/x86/include/asm/pgtable.h > @@ -1203,7 +1203,28 @@ 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; > + > + /* > + * Some processors can start a write, but ending up seeing but end up seeing > + * a read-only PTE by the time they get to the Dirty bit. > + * In this case, they will set the Dirty bit, leaving a > + * read-only, Dirty PTE which looks like a Shadow Stack PTE. > + * > + * However, this behavior has been improved and will not occur > + * on processors supporting Shadow Stacks. Without this > + * guarantee, a transition to a non-present PTE and flush the > + * TLB would be needed. > + * > + * When change a writable PTE to read-only and if the PTE has changing > + * _PAGE_DIRTY_HW set, we move that bit to _PAGE_DIRTY_SW so > + * that the PTE is not a valid Shadow Stack PTE. > + */ > + 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) > @@ -1266,7 +1287,28 @@ 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; > + > + /* > + * Some processors can start a write, but ending up seeing but end up seeing > + * a read-only PTE by the time they get to the Dirty bit. > + * In this case, they will set the Dirty bit, leaving a > + * read-only, Dirty PTE which looks like a Shadow Stack PTE. > + * > + * However, this behavior has been improved and will not occur > + * on processors supporting Shadow Stacks. Without this > + * guarantee, a transition to a non-present PTE and flush the > + * TLB would be needed. > + * > + * When change a writable PTE to read-only and if the PTE has changing > + * _PAGE_DIRTY_HW set, we move that bit to _PAGE_DIRTY_SW so > + * that the PTE is not a valid Shadow Stack PTE. > + */ > + pmd = pmd_move_flags(pmd, _PAGE_DIRTY_HW, _PAGE_DIRTY_SW); > + set_pmd_at(mm, addr, pmdp, pmd); > } > > #define pud_write pud_write > -- ~Randy