From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E15CC433DB for ; Tue, 26 Jan 2021 09:44:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D0DA522581 for ; Tue, 26 Jan 2021 09:44:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0DA522581 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F1FBF8D00B8; Tue, 26 Jan 2021 04:44:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EA9B98D00B0; Tue, 26 Jan 2021 04:44:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D71098D00B8; Tue, 26 Jan 2021 04:44:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0095.hostedemail.com [216.40.44.95]) by kanga.kvack.org (Postfix) with ESMTP id BDF8D8D00B0 for ; Tue, 26 Jan 2021 04:44:08 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 851F88249980 for ; Tue, 26 Jan 2021 09:44:08 +0000 (UTC) X-FDA: 77747440176.14.head93_2515ed32758d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id B1ECE182299A7 for ; Tue, 26 Jan 2021 09:44:07 +0000 (UTC) X-HE-Tag: head93_2515ed32758d X-Filterd-Recvd-Size: 4359 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 26 Jan 2021 09:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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; bh=1CPjkpcybqu4UmrIlyT7CxahkHobB8NLRUbQkEtv9gU=; b=OepRa5e8f56TtZHozt6NKrD7SL 7NAzZdheLyCJJIT2t2Otw19/WTxOE2bbb5RBIxNNUYL+zRG/pNHRno6mX+rkJvNO+5Yfl+od1ZH1o 3rtGWLm8NGasKwlRHdpeezA4HOMoDdHUVBSWew6rjO8PcY92SL2J2eMftsMpOjTDBCJQCdqValhdr AeFKcKWSzj40c2vTUCF4YaGOvldQpTO50q23BNz4zDOWcSz013OsCF6owkBOSq9xRDB1cv3Mej/HJ Gyy1ToJDQEi70A8gQZw19NxIxi1aE5bMFjUNAYQSV8d2xd+oCk7UIetGWvGwjarlIS2tjnoQ4lhqc TPsD0BSA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1l4Kpx-005NSo-Qp; Tue, 26 Jan 2021 09:40:58 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 50941300DB4; Tue, 26 Jan 2021 10:40:36 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 2A0E420297EDB; Tue, 26 Jan 2021 10:40:36 +0100 (CET) Date: Tue, 26 Jan 2021 10:40:36 +0100 From: Peter Zijlstra To: Borislav Petkov Cc: Yu-cheng Yu , 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 , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu Subject: Re: [PATCH v17 11/26] x86/mm: Update ptep_set_wrprotect() and pmdp_set_wrprotect() for transition from _PAGE_DIRTY to _PAGE_COW Message-ID: References: <20201229213053.16395-1-yu-cheng.yu@intel.com> <20201229213053.16395-12-yu-cheng.yu@intel.com> <20210125182709.GC23290@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jan 26, 2021 at 09:46:36AM +0100, Peter Zijlstra wrote: > On Mon, Jan 25, 2021 at 07:27:09PM +0100, Borislav Petkov wrote: > > > > + pte_t old_pte, new_pte; > > > + > > > + do { > > > + old_pte = READ_ONCE(*ptep); > > > + new_pte = pte_wrprotect(old_pte); > > > > Maybe I'm missing something but those two can happen outside of the > > loop, no? Or is *ptep somehow changing concurrently while the loop is > > doing the CMPXCHG and you need to recreate it each time? > > > > IOW, you can generate upfront and do the empty loop... > > > > > + > > > + } while (!try_cmpxchg(&ptep->pte, &old_pte.pte, new_pte.pte)); > > > + > > > + return; > > > + } > > Empty loop would be wrong, but that wants to be written like: > > old_pte = READ_ONCE(*ptep); > do { > new_pte = pte_wrprotect(old_pte); > } while (try_cmpxchg(&ptep->pte, &old_pte.pte, new_pte.pte)); ! went missing, too early, moar wake-up juice. > Since try_cmpxchg() will update old_pte on failure.