Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2322074imm; Thu, 7 Jun 2018 08:45:46 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKpBQy7jNr97Xv/B/bRHDniQRFeKA/BNZRY4ZGvFRw9y6AoyTK63nET7711BiBKo+7oSIJS X-Received: by 2002:a63:18c:: with SMTP id 134-v6mr2026681pgb.138.1528386346222; Thu, 07 Jun 2018 08:45:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528386346; cv=none; d=google.com; s=arc-20160816; b=YguNk45v7sNC65Zw/mp9OJM3intN1tExg16ojxX4OQFyDjUHD4bNbw7UN+Xs0o0hFI vxp87vUiG1VAVsrqto75gQaR/pobw7Olwgkc6XvCxUmqZv+L1ZCCYzdR1ZXViHnqD6QY VypPU3WpWwazGNSyAtABv4LY5qDWu1kwZ6H13XlIz02V4mFNVFLTTagSaBI6yMzLfKWo F9ONcqc/bykgbvR4Uhpj3Lj8W+SRHtFRVhKd+prX3jASe4VHDSut6jlCqbm4zFeGig+Z cTWorpDQkKPWIDmKDuR77VesBb/aKV9RnOnYX3/QVJG3FaYOTPch0YXj/jCEeeDGrLLH A1mA== 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=TSPHs9ydqq8JNTOQgp5u6L6bnwZ3z11dRvC6SXn4whQ=; b=LIKdOvZGKKRtcSS06eHczvOfIbJi6ymWHLy85x7zXJOdvQBb8mQQm3NI+1Zcq4jh9L AVRMvQJGrsfLnH3Kd9z9K3yHZh0Gk+4YduaBBr+U9gAU78P8hM5j5Za1/StUHpPQtnp4 h7lr89Nh9J/vcOzt3qJ/ZsJl6gsG3uf5Kh1cqrL9CiQ0Qx4SEKa6pQPYybbghYGj6Kfb GxlRdzIWpl30lORVmaLGqB4kHNkiJS7zzub/CPm7U4CWPOUB9k6dgg7zNdPq+4FYFuL2 SP1IvCFeCGbep0BmBgc/jD9sSjd3X7OOt1YH6yI+DLgmOiqqTrX0fuhqe/sTovfyR1df 8isQ== 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 v18-v6si6900270pfg.343.2018.06.07.08.45.14; Thu, 07 Jun 2018 08:45: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; 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 S934560AbeFGOks (ORCPT + 99 others); Thu, 7 Jun 2018 10:40:48 -0400 Received: from mga09.intel.com ([134.134.136.24]:36283 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934513AbeFGOkk (ORCPT ); Thu, 7 Jun 2018 10:40:40 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jun 2018 07:40:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,486,1520924400"; d="scan'208";a="47542315" Received: from 2b52.sc.intel.com ([143.183.136.51]) by orsmga008.jf.intel.com with ESMTP; 07 Jun 2018 07:40:34 -0700 From: Yu-cheng Yu To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H.J. Lu" , Vedvyas Shanbhogue , "Ravi V. Shankar" , Dave Hansen , Andy Lutomirski , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , Mike Kravetz Cc: Yu-cheng Yu Subject: [PATCH 9/9] x86/cet: Handle THP/HugeTLB shadow stack page copying Date: Thu, 7 Jun 2018 07:37:05 -0700 Message-Id: <20180607143705.3531-10-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180607143705.3531-1-yu-cheng.yu@intel.com> References: <20180607143705.3531-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 This patch implements THP shadow stack memory copying in the same way as the previous patch for regular PTE. In copy_huge_pmd(), we clear the dirty bit from the PMD. On the next shadow stack access to the PMD, a page fault occurs. At that time, the page is copied/re-used and the PMD is fixed. Signed-off-by: Yu-cheng Yu --- mm/huge_memory.c | 10 +++++++++- mm/hugetlb.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index a3a1815f8e11..c6e72ccc4274 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -600,6 +600,8 @@ static int __do_huge_pmd_anonymous_page(struct vm_fault *vmf, struct page *page, entry = mk_huge_pmd(page, vma->vm_page_prot); entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); + if (is_shstk_mapping(vma->vm_flags)) + entry = pmd_mkdirty_shstk(entry); page_add_new_anon_rmap(page, vma, haddr, true); mem_cgroup_commit_charge(page, memcg, false, true); lru_cache_add_active_or_unevictable(page, vma); @@ -976,7 +978,7 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, mm_inc_nr_ptes(dst_mm); pgtable_trans_huge_deposit(dst_mm, dst_pmd, pgtable); - pmdp_set_wrprotect(src_mm, addr, src_pmd); + pmdp_set_wrprotect_flush(vma, addr, src_pmd); pmd = pmd_mkold(pmd_wrprotect(pmd)); set_pmd_at(dst_mm, addr, dst_pmd, pmd); @@ -1196,6 +1198,8 @@ static int do_huge_pmd_wp_page_fallback(struct vm_fault *vmf, pmd_t orig_pmd, pte_t entry; entry = mk_pte(pages[i], vma->vm_page_prot); entry = maybe_mkwrite(pte_mkdirty(entry), vma); + if (is_shstk_mapping(vma->vm_flags)) + entry = pte_mkdirty_shstk(entry); memcg = (void *)page_private(pages[i]); set_page_private(pages[i], 0); page_add_new_anon_rmap(pages[i], vmf->vma, haddr, false); @@ -1280,6 +1284,8 @@ int do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd) pmd_t entry; entry = pmd_mkyoung(orig_pmd); entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); + if (is_shstk_mapping(vma->vm_flags)) + entry = pmd_mkdirty_shstk(entry); if (pmdp_set_access_flags(vma, haddr, vmf->pmd, entry, 1)) update_mmu_cache_pmd(vma, vmf->address, vmf->pmd); ret |= VM_FAULT_WRITE; @@ -1350,6 +1356,8 @@ int do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd) pmd_t entry; entry = mk_huge_pmd(new_page, vma->vm_page_prot); entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); + if (is_shstk_mapping(vma->vm_flags)) + entry = pmd_mkdirty_shstk(entry); pmdp_huge_clear_flush_notify(vma, haddr, vmf->pmd); page_add_new_anon_rmap(new_page, vma, haddr, true); mem_cgroup_commit_charge(new_page, memcg, false, true); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 218679138255..d694cfab9f90 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3293,7 +3293,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, * * See Documentation/vm/mmu_notifier.txt */ - huge_ptep_set_wrprotect(src, addr, src_pte); + huge_ptep_set_wrprotect_flush(vma, addr, src_pte); } entry = huge_ptep_get(src_pte); ptepage = pte_page(entry); -- 2.15.1