Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp621957imm; Fri, 31 Aug 2018 08:55:22 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZOOTFRSkS86ZIefzLtykIziYcSN/yXWTgZ3+zKcGnq0AadLHAgah96Wew3S2OnEWPRYSWK X-Received: by 2002:a63:d613:: with SMTP id q19-v6mr15063517pgg.327.1535730922525; Fri, 31 Aug 2018 08:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535730922; cv=none; d=google.com; s=arc-20160816; b=s26jqsvWja9buk+JPEJ7RaDLHKb/4R8feO92IT0YR75i38oFO47UJKV5sG1si/fd4u hqPrzBlylebFKiajlm3d86EYjvi3gJpuUaPeTwEfiRim20Y54SaqUzvGdz0v00jEQgab pSvGG7mbrnBj9tASMk3sfe3bJ41G1LavLv8oQ6zQnJR20YsI7qOJ9H/aYB7izhPur23w MTKK42P/8Xw1DtJTHfaeFMuwvH7OuOddRJEF/45PazP32vR95fGh7cZRGKDgoywVgqVh ll5q9Ufb36KEmnQVN9r7Z2DDUHnXWhnWes68dyUCyyNqzZy8AcRLJoumDADYJ+EsaM4n wTGg== 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=pgDz4L73zq6lORN6rXh91+6fPJTSIxc3/jZ1HisabG8=; b=zak1qlRzLHKlo721nS2bPPnOvkelDFnKBePUR5R1GLsDBhWcUMTQMt+YAGuiAB3mWL BIr4blRnJF7Eye24DUNf89oBfpC5j7/8Vc84X7ah7KFXkq1vBBuvv+MZC4FuUC3tkloj OMlbG2xmoTXX3TagczUQKs2E7KZxvHEQBxm0wWziphd8UA5/DTUaDm0rwkCKwqY2XjGz b6i/3mWepn2jnHHeCr0DH0DQJGmn1RBjSSF6X6xIDtpy2JgsyHhs9L85krTVgfHCbFSy wTSvCWfxSbeoK/okFJlDsDDYMw+7iKUBpuprEdvvQZLOVmMv4jLUkIL7IjLrLqLqksy3 fLuA== 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 s32-v6si10312564pgl.531.2018.08.31.08.55.07; Fri, 31 Aug 2018 08:55:22 -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 S1729238AbeHaUBJ (ORCPT + 99 others); Fri, 31 Aug 2018 16:01:09 -0400 Received: from mga09.intel.com ([134.134.136.24]:44719 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727957AbeHaUBI (ORCPT ); Fri, 31 Aug 2018 16:01:08 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Aug 2018 08:53:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,312,1531810800"; d="scan'208";a="259697793" Received: from 2b52.sc.intel.com ([143.183.136.52]) by fmsmga006.fm.intel.com with ESMTP; 31 Aug 2018 08:53:00 -0700 Message-ID: <1535730524.501.13.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 , Jann Horn Cc: 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@chromiun.org, Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , ravi.v.shankar@intel.com, vedvyas.shanbhogue@intel.com Date: Fri, 31 Aug 2018 08:48:44 -0700 In-Reply-To: References: <1535649960.26689.15.camel@intel.com> <33d45a12-513c-eba2-a2de-3d6b630e928e@linux.intel.com> <1535651666.27823.6.camel@intel.com> <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> 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-08-31 at 07:47 -0700, Dave Hansen wrote: > On 08/31/2018 07:33 AM, Yu-cheng Yu wrote: > > > > Please use the form: > > > > pte_t new_pte, pte = READ_ONCE(*ptep); > > do { > > new_pte = /* ... */; > > } while (!try_cmpxchg(ptep, &pte, new_pte); > It's probably also worth doing some testing to see if you can detect > the > cost of the cmpxchg.  It's definitely more than the old code. > > A loop that does mprotect(PROT_READ) followed by > mprotect(PROT_READ|PROT_WRITE) should do it. I created the test, https://github.com/yyu168/cet-smoke-test/blob/quick/quick/mprotect_ben ch.c then realized this won't work. To trigger a race in ptep_set_wrprotect(), we need to fork from one of three pthread siblings. Or do we measure only how much this affects fork? If there is no racing, the effect should be minimal. Yu-cheng