Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1260725imm; Fri, 14 Sep 2018 14:13:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaRAFggr05uzsfgX2xxPrke17uToEi90FCOKS4GTBrSDy9NvqC3+gJ3ZLTKEJR6+gLQF9Jn X-Received: by 2002:a63:7557:: with SMTP id f23-v6mr13419638pgn.135.1536959639655; Fri, 14 Sep 2018 14:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536959639; cv=none; d=google.com; s=arc-20160816; b=oItqrjm7sQ9CszUgpLxe0FvSABMbNpTWsd2fch3mPgdXcVALTLpHFsPLDFqg8CN/L+ hsSfGdELf9qJ759//n7asi3KIf+ClzF8x9b+RCDWQ07mReTTSx7MhKShSPxLO2lBX+X4 8eXiU4B7XzTvNvuzu33uIFeYyapW/WmDoTN8sPCyRaFdylOcQCQ9La61OEdkE3ZeiuZx 7Dkl3qaDUVbzhjQgw+UTCamRe2o+eUUFsXaOAGVfqOh3YCwPsyJJr7F4w/JU9jqKqGzo BruP1ralXhyCev6H1BMqe6ShEL+KC9USBLKDoeBC14ju+uYPspuUU4B4XVbjQ8koUIdK X3Ag== 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; bh=x17qpZKvafLL1ISfbZW65/H61JZBmeIMniqo21OZuls=; b=FFpnfgr52yqsfCKXoXk2ueFLzI5RsRk0y8bu3hXsgHOHSn0iiArQ3wrS97kkU47TD8 d42MrJQUoC1TN2jfyzNz+3rvljGAWUS0AwQHc500hyW+QoPjwXdQNY9/SfvBxSdmOJQd 44R3E7nX5axGh1KmAmWnMvnjUvCJiP3kZ65JVgHnfMJSj1sI98ewIMfxZ5A4h9GIE8hr f9o4ZAOiOlPWkOs3/xMud6yU9bs946UiZaCTXRLZU01m6cQJ5hJLw22HUBKml+5aV56X Ru4ES2QfiPwuUca6WGLzh+BNj7bxlrd0XseSYM8AW5wOGsfVHN2dISc8Azpe1zUzEKzL YH0w== 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 q20-v6si8296970pgb.596.2018.09.14.14.13.43; Fri, 14 Sep 2018 14:13:59 -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 S1728218AbeIOC3u (ORCPT + 99 others); Fri, 14 Sep 2018 22:29:50 -0400 Received: from mga02.intel.com ([134.134.136.20]:39286 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727716AbeIOC3u (ORCPT ); Fri, 14 Sep 2018 22:29:50 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 14:13:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="257351283" Received: from 2b52.sc.intel.com ([143.183.136.51]) by orsmga005.jf.intel.com with ESMTP; 14 Sep 2018 14:13:25 -0700 Message-ID: <1536959337.12990.27.camel@intel.com> Subject: Re: [RFC PATCH v3 12/24] x86/mm: Modify ptep_set_wrprotect and pmdp_set_wrprotect for _PAGE_DIRTY_SW From: Yu-cheng Yu To: Dave Hansen , Peter Zijlstra Cc: Jann Horn , the arch/x86 maintainers , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , linux-doc@vger.kernel.org, Linux-MM , linux-arch , Linux API , Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Florian Weimer , hjl.tools@gmail.com, Jonathan Corbet , keescook@chromium.org, Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , ravi.v.shankar@intel.com, vedvyas.shanbhogue@intel.com Date: Fri, 14 Sep 2018 14:08:57 -0700 In-Reply-To: <8d9ce0e9-8fc7-8c68-4aa9-9aed9ee949f2@linux.intel.com> References: <1535660494.28258.36.camel@intel.com> <1535662366.28781.6.camel@intel.com> <20180831095300.GF24124@hirez.programming.kicks-ass.net> <1535726032.32537.0.camel@intel.com> <1535730524.501.13.camel@intel.com> <6d31bd30-6d5b-bbde-1e97-1d8255eff76d@linux.intel.com> <20180831162920.GQ24124@hirez.programming.kicks-ass.net> <1536957543.12990.9.camel@intel.com> <8d9ce0e9-8fc7-8c68-4aa9-9aed9ee949f2@linux.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-09-14 at 13:46 -0700, Dave Hansen wrote: > On 09/14/2018 01:39 PM, Yu-cheng Yu wrote: > > > > With the updated ptep_set_wrprotect() below, I did MADV_WILLNEED to a shadow > > stack of 8 MB, then 10,000 fork()'s, but could not prove it is more or less > > efficient than the other.  So can we say this is probably fine in terms of > > efficiency? > Well, the first fork() will do all the hard work.  I don't think > subsequent fork()s will be affected. Are you talking about a recent commit:     1b2de5d0 mm/cow: don't bother write protecting already write-protected pages With that, subsequent fork()s will not do all the hard work. However, I have not done that for shadow stack PTEs (do we want to do that?). I think the additional benefit for shadow stack is small? > > Did you do something to ensure this code was being run? > > I would guess that a loop like this: > > for (i = 0; i < 10000; i++) { > mprotect(addr, len, PROT_READ); > mprotect(addr, len, PROT_READ|PROT_WRITE); > } > > might show it better. Would mprotect() do copy_one_pte()?  Otherwise it will not go through ptep_set_wrprotect()?