Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp460500ybl; Wed, 28 Aug 2019 00:05:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxy9DKa7JcNMHX7itK459H8fBNhEafPe0NwSWuX5/uv9Y5m8pcIctavKpduAGq7dtcOaqVa X-Received: by 2002:a17:90a:2629:: with SMTP id l38mr2801862pje.71.1566975909260; Wed, 28 Aug 2019 00:05:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566975909; cv=none; d=google.com; s=arc-20160816; b=qIyFzjBWA2dXfPpPMK3aW1N+WEOcU7+JLZ5YPx5Meaka6ie80MddwtqeCzem8d1eNN g6dM9JJG/XS8P+xZG22vcQS0DgzgrH+/dW6zFkoAsQPct6C2wnS1k+tbu6vII5voLTYw x0GmGT/Kq/XIC/NaEB9BRRL/gLe0QLCo99qbdrqJowkzu3Sdq8Ejm7RJA3QH3GfxVnmv 0bGV5aSv7kEmnGZuOka1wPkWpFCItSZNYMRxJ5bhksJkQBP2qsgbdKbaTXKcU7PQlDnv L2pugsvQQsLgIR8RAb9ZqNtGLmzzFbLbPWTOhZVzc+miF6uLR0XH60YusdqBqYGM8BKZ rfBw== 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; bh=b0lWlRYuwpcJp7FZARuB7iv+wNKnjSY45sYdI3qTaw0=; b=gox1z2iqLrEVX6MOGz9/3X9Ev2iO5P24Ag1rl+ZfGTP7guxchnETQRS53vY+ZkQXzl 4hjhtk4LgdM64GRefKDBg2+tVl61GXuIQJjsQT/JI2GG58nhtH7igrIqIZs+2GW67Pm4 7yVWDWkK/JDOuXD4aB293tr9/8/ZrAQYlNxGP+YoHxx9S8kQ6qf88F3IYedmr52nVgGS xnGbLU44SU13jqQ7/OTF3kAd2TEwlTbLX9U/bckOT0dV4ECrgAXL5I0A/pCANlQ8r9Jf My4nRAiVx33Mge7V/4VqUyxOZjnCff71W9OBsBac8jCa5XGzoN7v44sf9INy1jFE+P+z ecRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=SRcswj1N; 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 h38si1466688pgi.327.2019.08.28.00.04.50; Wed, 28 Aug 2019 00:05:09 -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=SRcswj1N; 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 S1726340AbfH1HEA (ORCPT + 99 others); Wed, 28 Aug 2019 03:04:00 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:39024 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726169AbfH1HD7 (ORCPT ); Wed, 28 Aug 2019 03:03:59 -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=b0lWlRYuwpcJp7FZARuB7iv+wNKnjSY45sYdI3qTaw0=; b=SRcswj1NZftwI/XnJvFP3pShU znc/n+mtlRHu6TFjynsrTcX7AJbxhiAxqbwLDQuGtAPg3JfrBRRm0ct4NUb75sMosNwo6zzPno6++ UalJ7tB/CF1fibAZwF3XnkUahC3vLwVicDfZaOzdUfznqQYyj4cqeEELzUx5OBLE/UoBVq4xNa3fb MAGABj29H9rsz6o5r+c35Ec806uTVIFEp3KPjzXh72MNxZwttb5puS+/o9mL5A6kR9sqWGaybBoG8 jFsHa7toIBBHEB+Y8OPHVqgL3GH3gy6DAyVnffryEZ3lpK0XGznfntg42Nb/sbcfkNgDjX3ozypqN oKJ6ql6IQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i2rz6-0000Q5-2E; Wed, 28 Aug 2019 07:03:12 +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 95D553070F4; Wed, 28 Aug 2019 09:02:34 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7D7E02018508C; Wed, 28 Aug 2019 09:03:08 +0200 (CEST) Date: Wed, 28 Aug 2019 09:03:08 +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 , Borislav Petkov , 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 Subject: Re: [PATCH v8 11/27] x86/mm: Introduce _PAGE_DIRTY_SW Message-ID: <20190828070308.GJ2332@hirez.programming.kicks-ass.net> References: <20190813205225.12032-1-yu-cheng.yu@intel.com> <20190813205225.12032-12-yu-cheng.yu@intel.com> <20190823140233.GC2332@hirez.programming.kicks-ass.net> <6c3dc33e16c8bbb6d45c0a6ec7c684de197fa065.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6c3dc33e16c8bbb6d45c0a6ec7c684de197fa065.camel@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 27, 2019 at 03:37:12PM -0700, Yu-cheng Yu wrote: > On Fri, 2019-08-23 at 16:02 +0200, Peter Zijlstra wrote: > > On Tue, Aug 13, 2019 at 01:52:09PM -0700, Yu-cheng Yu wrote: > > > > > +static inline pte_t pte_move_flags(pte_t pte, pteval_t from, pteval_t to) > > > +{ > > > + if (pte_flags(pte) & from) > > > + pte = pte_set_flags(pte_clear_flags(pte, from), to); > > > + return pte; > > > +} > > > > Aside of the whole conditional thing (I agree it would be better to have > > this unconditionally); the function doesn't really do as advertised. > > > > That is, if @from is clear, it doesn't endeavour to make sure @to is > > also clear. > > > > Now it might be sufficient, but in that case it really needs a comment > > and or different name. > > > > An implementation that actually moves the bit is something like: > > > > pteval_t a,b; > > > > a = native_pte_value(pte); > > b = (a >> from_bit) & 1; > > a &= ~((1ULL << from_bit) | (1ULL << to_bit)); > > a |= b << to_bit; > > return make_native_pte(a); > > There can be places calling pte_wrprotect() on a PTE that is already RO + > DIRTY_SW. Then in pte_move_flags(pte, _PAGE_DIRTY_HW, _PAGE_DIRTY_SW) we do not > want to clear _PAGE_DIRTY_SW. But, I will look into this and make it more > obvious. Well, then the name 'move' is just wrong, because that is not the semantics you're looking for. So the thing is; if you provide a generic function that 'munges' two bits, then it's name had better be accurate. But AFAICT you only ever used this for the DIRTY bits, so it might be better to have a function specifically for that and with a comment that spells out the exact semantics and reasons for them.