Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp396321imm; Fri, 31 Aug 2018 03:30:14 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaTyBBnZGUX2SuIpKBv55ONcDAfkkPLEiz534CwudKYTHGQ7IPSR31sq/paNa8a4dL/S7TF X-Received: by 2002:a63:2787:: with SMTP id n129-v6mr4851038pgn.220.1535711413975; Fri, 31 Aug 2018 03:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535711413; cv=none; d=google.com; s=arc-20160816; b=CA17/w8+zQhn0ZgRN7xuIasw9+5bBJih3gvmcnzgmnVPf00inkkF/8gzwHyEtzreHh 4g7my0DmZVCJLDQa2tY/vVY91MUING8mmjI84fecOKRecGe8hgtMQSynlb5w+A3IZsWI 9rrHvwOnMNGXSOpowi8mZ/H+IV5UloibuBVs9riUF7ky1TfAtA0O1D1KxYYOhwe4u9qX 4tY9pzfKXLGV8nh51hL9oghrJJ+O0XV6HplN49IC8X9s6xQEsHFtUO9UcoVdsP/PZvjh TipPUKskpbaX7cdtOfyY2IjuHuBxjP7loaywxD50ZDt6Qwt0So0OGUWNis37qSIEZyJE 6wEQ== 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=1Z9clxjW3U+Fz0CBnB0Xf1KD0++mL+Gum5NfWi0pfRE=; b=lJxr8dsLxOMbtE722UkEP6H2s8luaK2zmjQgdTajYlKK/2suxS51eONUSiPIeWAvZE fVBQqwMdD71BN8uqM+dsun2bJ0YDH0JPweqMIigBOWe4SYVuh3n7m3DgdBeZt8QfcYR2 pVnCcqPbBpnZEtTr1iXcsrRpZApdZ/g60s5zPwAicsfIPhH1bMwEJGixkRCPD7rGEvjZ uOTR8Jk2puJxc/X2NHLmkK/AhuFdDL+ka0SOdtOKNX7NxyaciTa8mGKnAAhZJgVW2wr/ NuCoi5rc7mjX1r35KFDyW/Xr1phSrBJnuN2w7Vl07CoBzpqwTKFnLp8a/wXdSZVaSaeb e2KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=PP3cIKmP; 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 5-v6si8957323pgf.18.2018.08.31.03.29.43; Fri, 31 Aug 2018 03:30:13 -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=merlin.20170209 header.b=PP3cIKmP; 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 S1727948AbeHaOAa (ORCPT + 99 others); Fri, 31 Aug 2018 10:00:30 -0400 Received: from merlin.infradead.org ([205.233.59.134]:45760 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727268AbeHaOAa (ORCPT ); Fri, 31 Aug 2018 10:00:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=1Z9clxjW3U+Fz0CBnB0Xf1KD0++mL+Gum5NfWi0pfRE=; b=PP3cIKmP5FW8cPZQltFqraD5M SBQU8PR7OlGE+W8n5eIueLjaMEnKjNuNFP5eZA5Cu37PMu73qny/kfL1O+HU7unmyruQH4XaPNO83 T8gQJ9kPmpC5NEhEyjfjK9y6L830NFfSOQ/hKGtXJPhJ5Yl9eUvr6+0G0cIAZmqn8Fo8wBXlwPKCU q3elfpJ0qy6wFWOnkCFaNsttVrywd1grQSd1sy133xNymKAK37E6adqngjveQ+envgjiFkaY0IiWs Ervf3MSWMFcWtiOhf4gqnbeUIsn7HKJKL4Q6PGyzHN9Ja+F75PhacrTMrhs6/rxhjLYbRdgTtcD3U OJlOsVqjw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvg6v-0006BR-7p; Fri, 31 Aug 2018 09:53:01 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 12B222024D700; Fri, 31 Aug 2018 11:53:00 +0200 (CEST) Date: Fri, 31 Aug 2018 11:53:00 +0200 From: Peter Zijlstra To: Jann Horn Cc: yu-cheng.yu@intel.com, Dave Hansen , 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 Subject: Re: [RFC PATCH v3 12/24] x86/mm: Modify ptep_set_wrprotect and pmdp_set_wrprotect for _PAGE_DIRTY_SW Message-ID: <20180831095300.GF24124@hirez.programming.kicks-ass.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Thu, Aug 30, 2018 at 11:47:16PM +0200, Jann Horn wrote: > do { > pte = pte_wrprotect(pte); > /* note: relies on _PAGE_DIRTY_HW < _PAGE_DIRTY_SW */ > /* dirty direct bit-twiddling; you can probably write > this in a nicer way */ > pte.pte |= (pte.pte & _PAGE_DIRTY_HW) >> > _PAGE_BIT_DIRTY_HW << _PAGE_BIT_DIRTY_SW; > pte.pte &= ~_PAGE_DIRTY_HW; > pte = cmpxchg(ptep, pte, new_pte); > } while (pte != new_pte); Please use the form: pte_t new_pte, pte = READ_ONCE(*ptep); do { new_pte = /* ... */; } while (!try_cmpxchg(ptep, &pte, new_pte); Also, this will fail to build on i386-PAE, but I suspect this code will be under some CONFIG option specific to x86_64 anyway.