Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp112793imm; Tue, 14 Aug 2018 15:08:46 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxjokQBOG8X96MtHzw+GfpooJjaBVeotXblk5GT74DcPOhsW5jkTHlu3xOq0nbRG0l6hiD4 X-Received: by 2002:a63:c50c:: with SMTP id f12-v6mr22178916pgd.88.1534284526922; Tue, 14 Aug 2018 15:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534284526; cv=none; d=google.com; s=arc-20160816; b=dn6e8Opp+b0609pf+tUXwgtUQTP9CR+8qIKkFFL0B7Dg/1kBqSYwdmzPA8hmBilFMn +rMyOjCIHMtG9Rzow+9PmrlpYHdR+Y6YC7k1ByRaYHdv3eTlxBtWYsh0Y/TlNZdtKUBH vyhqeK5dY7Jpl5yzip9DLBMtwm4MtbZWOaumGezGR2O/5NmQpl0nh+qh1wvCH4JS0SAf Gbt2AT5QTdXgfi2K9vA684njjFT8I/IISx5kHAwKxDrwYlkie2epzuApF7HyJrPlM/X3 L9RiX87hixVN3qao2MqQdVRWcBM3j3MNaFev9dGhMlujgaAprtyW79JPIK4oeIw1/UB7 5fpQ== 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:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=o3CYMRoVYYPyjnuDfuZgNsqZ9CVtkLqc2DeyDUeNX3E=; b=jMf6aW4m6pIVkTTN9rT7xv+NfrNO2QvsFMHMM4GfH7E0d2nMOQIiI6fLHwZuGHTi4u oG097HLpCACrYn1NVYbqI5FT8DHK1mCOhOa+eOeZ7x+TZ6K1snNhX2vpdQqQkAA4WNh0 TUxPFvc7buacvny023rPvaeVwg6UKy2JpY7Aa3up5MKjAJ6qlWe07OrBdy0/IHti4xSP DN+oZpsI4DAUUVojLhOcovEtRuVEYPK5VtptOaTiReIXICayJ9juKFzaSE35DINHdMkI 54I7L8kmVNsiQBs72I64/GXQ+rgMyjqdd7+2wep9NlrQptyZuDl4/j09mKsY71O0MxpZ 7aNA== 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 o19-v6si21919075pgl.212.2018.08.14.15.08.31; Tue, 14 Aug 2018 15:08: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 S1732521AbeHOASU (ORCPT + 99 others); Tue, 14 Aug 2018 20:18:20 -0400 Received: from mga05.intel.com ([192.55.52.43]:10599 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725877AbeHOAST (ORCPT ); Tue, 14 Aug 2018 20:18:19 -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 fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Aug 2018 14:29:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,240,1531810800"; d="scan'208";a="80299382" Received: from 2b52.sc.intel.com ([143.183.136.51]) by fmsmga004.fm.intel.com with ESMTP; 14 Aug 2018 14:29:15 -0700 Message-ID: <1534282125.24160.9.camel@intel.com> Subject: Re: [RFC PATCH v2 13/27] mm: Handle shadow stack page fault From: Yu-cheng Yu To: Peter Zijlstra , Dave Hansen Cc: 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 , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , "Ravi V. Shankar" , Vedvyas Shanbhogue Date: Tue, 14 Aug 2018 14:28:45 -0700 In-Reply-To: <20180711090656.GS2476@hirez.programming.kicks-ass.net> References: <20180710222639.8241-1-yu-cheng.yu@intel.com> <20180710222639.8241-14-yu-cheng.yu@intel.com> <2f3ff321-c629-3e00-59f6-8bca510650d4@linux.intel.com> <20180711090656.GS2476@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-07-11 at 11:06 +0200, Peter Zijlstra wrote: > On Tue, Jul 10, 2018 at 04:06:25PM -0700, Dave Hansen wrote: > > > > On 07/10/2018 03:26 PM, Yu-cheng Yu wrote: > > > > > > + if (is_shstk_mapping(vma->vm_flags)) > > > + entry = pte_mkdirty_shstk(entry); > > > + else > > > + entry = pte_mkdirty(entry); > > > + > > > + entry = maybe_mkwrite(entry, vma); > > >   if (ptep_set_access_flags(vma, vmf->address, vmf->pte, > > > entry, 1)) > > >   update_mmu_cache(vma, vmf->address, vmf->pte); > > >   pte_unmap_unlock(vmf->pte, vmf->ptl); > > > @@ -2526,7 +2532,11 @@ static int wp_page_copy(struct vm_fault > > > *vmf) > > >   } > > >   flush_cache_page(vma, vmf->address, > > > pte_pfn(vmf->orig_pte)); > > >   entry = mk_pte(new_page, vma->vm_page_prot); > > > - entry = maybe_mkwrite(pte_mkdirty(entry), vma); > > > + if (is_shstk_mapping(vma->vm_flags)) > > > + entry = pte_mkdirty_shstk(entry); > > > + else > > > + entry = pte_mkdirty(entry); > > > + entry = maybe_mkwrite(entry, vma); > > Do we want to lift this hunk of code and put it elsewhere?  Maybe: > > > > entry = pte_set_vma_features(entry, vma); > > > > and then: > > > > pte_t pte_set_vma_features(pte_t entry, struct vm_area_struct) > > { > > /* > >  * Shadow stack PTEs are always dirty and always > >  * writable.  They have a different encoding for > >  * this than normal PTEs, though. > >  */ > > if (is_shstk_mapping(vma->vm_flags)) > > entry = pte_mkdirty_shstk(entry); > > else > > entry = pte_mkdirty(entry); > > > > entry = maybe_mkwrite(entry, vma); > > > > return entry; > > } > Yes, that wants a helper like that. Not sold on the name, but > whatever. > > Is there any way we can hide all the shadow stack magic in arch > code? We use is_shstk_mapping() only to determine PAGE_DIRTY_SW or PAGE_DIRTY_HW should be set in a PTE.  One way to remove this shadow stack code from generic code is changing pte_mkdirty(pte) to pte_mkdirty(pte, vma), and in the arch code we handle shadow stack. Is this acceptable? Thanks, Yu-cheng