Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2973919imm; Fri, 20 Jul 2018 08:02:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfXs3tr8XuNjiJv6oU5ImKgfCuB4Ses6EBOOPqxWu0T9uLfGUAzwOXA/7tiaLroO9XuI2Kv X-Received: by 2002:a62:41d6:: with SMTP id g83-v6mr2513603pfd.219.1532098974644; Fri, 20 Jul 2018 08:02:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532098974; cv=none; d=google.com; s=arc-20160816; b=LfBr5pOaKGVCZCzixZvIgj8pk7IjnfADDaZsPyytDSHzZ2OgWSFaP4PjeqHjwiGVRf wIZHapd9C7PAb0DDph0HlrVRlv0nUUammxFFK21p2vvmTIci7LvbyPP7L2ppGDvMuzEh MijyYyxOFfJYdPIzNm9U738kc9cIPPtW6VFM834wh1136mqJP+4ZhHWdmPep13NTMfHl X2xZifsm1BE6qYA9nLtyD7xRg19vjrFnlqjHbc3DlSwO94b0tzsFpbWHp+mkdpNQFfbF qct5uC/zwwLrBvxNycMd/sbsAXdiUFxjAKOf+O4bvQh3cHBWFq0sCEeuIUVu3am6Zw6y F+HA== 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:to:from:subject:message-id :arc-authentication-results; bh=LCBxGFVkm/jmd6CVXvevhwuCZEKO/9eXy9N/jadYFq4=; b=Ly9WuK9JvY2xYzwFdstRv0Oo7lyRyvGzckW8elvgz8bIZ0I3AGN3nXdUOYv5RCvZOk 5drXfxr5f+GkkYEnGU45jDGlm8qVeLbALCkANoIKwZV5BMP6zAGs/3ZkKo76QCSm2MOh G61JFxoB6/lPz7eDqEFDQLmNx/5YHzW3/PHMHc6S0/l9QWw/+X5QcwzUJetcjs93rMju AOK+im2vtIq7EzQxEBYY2NMUDrMKX5n2FRVsBS55qw8z/E1fFOrPyMSod9KqQmVJ+xY6 i2Eev3klBztfOaNhFBosniftncQl+ys3k59FTyyUqyYQ0+ndSs1Ps5V6ngZAu/BSwGlP +z2g== 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 z1-v6si1785905plb.152.2018.07.20.08.02.38; Fri, 20 Jul 2018 08:02:54 -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 S1732042AbeGTPun (ORCPT + 99 others); Fri, 20 Jul 2018 11:50:43 -0400 Received: from mga03.intel.com ([134.134.136.65]:7402 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731731AbeGTPum (ORCPT ); Fri, 20 Jul 2018 11:50:42 -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 orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jul 2018 08:02:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,380,1526367600"; d="scan'208";a="73077337" Received: from unknown (HELO [143.183.136.146]) ([143.183.136.146]) by fmsmga004.fm.intel.com with ESMTP; 20 Jul 2018 08:02:00 -0700 Message-ID: <1532098688.23487.0.camel@intel.com> Subject: Re: [RFC PATCH v2 14/27] mm: Handle THP/HugeTLB shadow stack page fault From: Yu-cheng Yu To: Dave Hansen , 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 , Peter Zijlstra , "Ravi V. Shankar" , Vedvyas Shanbhogue Date: Fri, 20 Jul 2018 07:58:08 -0700 In-Reply-To: References: <20180710222639.8241-1-yu-cheng.yu@intel.com> <20180710222639.8241-15-yu-cheng.yu@intel.com> 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 Fri, 2018-07-20 at 07:20 -0700, Dave Hansen wrote: > On 07/10/2018 03:26 PM, Yu-cheng Yu wrote: > > > > @@ -1193,6 +1195,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); > Peter Z was pointing out that we should get rid of all this generic > code > manipulation.  We might not easily be able to do it *all*, but we > can do > better than what we've got here. > > Basically, if you have code outside of arch/x86 in your patch set > that > refers to shadow stacks, you should consider it a bug (for now), > especially if you have to hack .c files. > > For instance, in the code above, you could move the > is_shstk_mapping() into: > > static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct > *vma) > { >         if (likely(vma->vm_flags & VM_WRITE)) >                 pte = pte_mkwrite(pte); > > + pte = arch_pte_mkwrite(pte, vma); > + >         return pte; > } > > ... and add an arch callback that does: > > static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct > *vma) > { > if (!is_shstk_mapping(vma->vm_flags)) > return pte; > > WARN_ON(... pte bits incompatible with shadow stacks?); > > /* Lots of comments of course */ > entry = pte_mkdirty_shstk(entry); > } > > This is just one example.  You are probably going to need a couple > of > similar things.  Just remember: the bar is very high to make changes > to > .c files outside of arch/x86.  You can do a _bit_ more in non-x86 > headers, but you have the most freedom to patch what you want as > long as > it's in arch/x86. Ok, I will work on that.  Thanks! Yu-cheng