Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp278214imm; Wed, 11 Jul 2018 02:12:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdv9yh4QDSk+RS2uZUZMchnglBytemv2MlnJtpxDiwkmqjNDS1b/FvmCX2RRDvJAATFBt9m X-Received: by 2002:a63:704f:: with SMTP id a15-v6mr25872028pgn.443.1531300336547; Wed, 11 Jul 2018 02:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531300336; cv=none; d=google.com; s=arc-20160816; b=etHpm5Y3bmkw9G/5tZrRtUa9utnYGxdusPh9Ahi7KjYbwMRjAXzPchRXMLWbNBmdll 4E3upNpi983xLJ/TCVXmkI6wL+CGCnAZm4aLS09c2YthAXdmUWUvZrRhAP0XjBxExqH6 Rx5Q7+JlOja8tbbxtF9OFJduXCWPsjssmdEIz5ju/NeTRKeDtn6Op0MPi/BPSCLi8g1b mrzSPtKHFAFHfb+04dzHxXZPTszf1V2k3zXLmAai8YNWc5IHob1L8o/34v2LvANgBxB0 yTPigSWibsAmLtiXP7gvrEynvMLDdsLg03oiAokh0LE4L8PpWN6ABcvmeQRBETtCSdig c7tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=axBSON5cvs4xwlba/fqyRyd7rPG8BRp78PXGOPrsffs=; b=QG1axu+Vdekatw36bDdZuwz0BBMeYBpHbCpuOdRz6j4zrJNRy+C6WEN4LfWsoDYlhx RYrzA+JXXuxFZ0OosaFjWO6DyND2Q58aWpD4oHVtRhhpquHqQA6CKJK1G8wlm44TVbN+ aAZ5N4d2Aqra2aOO6pQXZS+iDnWk52nqRVXhCcpycUAMjSsTaUuaqM6CGXjFJqJdd13j wTszVahdH+z1F5kjUndKITJTlo0y6962XaGrx3G9FhBp9zy4jZUE+kzp6hC80GmI3VeP kpt7HD8Of26AMPGtLTX+G5DZ0MYiCF9H4EPPe6SdKJOmDBERroGDnWEEQLhnLjqzWZzS rdyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=eSTn1Zy5; 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 z13-v6si18377119pgk.127.2018.07.11.02.11.58; Wed, 11 Jul 2018 02:12:16 -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=eSTn1Zy5; 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 S1732305AbeGKJNt (ORCPT + 99 others); Wed, 11 Jul 2018 05:13:49 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:60880 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726289AbeGKJNt (ORCPT ); Wed, 11 Jul 2018 05:13:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding: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=axBSON5cvs4xwlba/fqyRyd7rPG8BRp78PXGOPrsffs=; b=eSTn1Zy5c/Aun+4usiHSDLp+M wgUUGJcLaFMiOOg2URSQvlxCY5ynPBHcRD1sSnmB9b7tRvnhXPsrDGtqggLQjBwqHBhOtE+qpa78Z D3xMoaMW6WtqxFPk84rnDXcFhehpXAmMxFg5RxtGXcYnB17IDfrQjbX7AayPZ0/GyReFR5oOtmYwj bYESxGDxIMMU8efDlu9egWY48SH5/olLkjJNdA0B0DlQOeQrmLLYNZIlfZ8r7TZvtEqFU/15fmJZP 6UUlbqu0g5FUG3Db+CSM5KTe8gEPTeR29TRI5/X4MeEB34OWmmLpBBLgz4RW6uB1gmSifmtT6k2QV mNAIfkiPQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fdB8h-0004nw-Q0; Wed, 11 Jul 2018 09:10:23 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 4727320291063; Wed, 11 Jul 2018 11:10:22 +0200 (CEST) Date: Wed, 11 Jul 2018 11:10:22 +0200 From: Peter Zijlstra To: Yu-cheng Yu 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 , Dave Hansen , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , "Ravi V. Shankar" , Vedvyas Shanbhogue Subject: Re: [RFC PATCH v2 14/27] mm: Handle THP/HugeTLB shadow stack page fault Message-ID: <20180711091022.GT2476@hirez.programming.kicks-ass.net> References: <20180710222639.8241-1-yu-cheng.yu@intel.com> <20180710222639.8241-15-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180710222639.8241-15-yu-cheng.yu@intel.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 10, 2018 at 03:26:26PM -0700, Yu-cheng Yu wrote: > diff --git a/mm/memory.c b/mm/memory.c > index a2695dbc0418..f7c46d61eaea 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -4108,7 +4108,13 @@ static int __handle_mm_fault(struct vm_area_struct *vma, unsigned long address, > if (pmd_protnone(orig_pmd) && vma_is_accessible(vma)) > return do_huge_pmd_numa_page(&vmf, orig_pmd); > > - if (dirty && !pmd_write(orig_pmd)) { > + /* > + * Shadow stack trans huge PMDs are copy-on-access, > + * so wp_huge_pmd() on them no mater if we have a > + * write fault or not. > + */ > + if (is_shstk_mapping(vma->vm_flags) || > + (dirty && !pmd_write(orig_pmd))) { > ret = wp_huge_pmd(&vmf, orig_pmd); > if (!(ret & VM_FAULT_FALLBACK)) > return ret; Can't we do this (and the do_wp_page thing) by setting FAULT_FLAG_WRITE in the arch fault handler on shadow stack faults?