Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp993220ybl; Wed, 28 Aug 2019 08:09:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQBE2Lun9BeZcn8nQcxYUs/lZboL300ro18jX27AH6PAzP2jLKmqTXdrpdT51x1ADGPFPy X-Received: by 2002:a65:6093:: with SMTP id t19mr3855595pgu.79.1567004993124; Wed, 28 Aug 2019 08:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567004993; cv=none; d=google.com; s=arc-20160816; b=Ld6ObkmL6aG3KUMK01ou2XjXFrjPb89YfVbzqIcaNT6G9GSOmSCqOcRtqub4QHecEN 3IyDLwpt7EokeUJiIU8gRFwo9EKzWlXVWc3z9IftRnuP8Ey6hpa1H9EZX+7Jis/h/w+a 5A1r7J75quZ87v3jpEz+8d/mtUJmLYsp6FJm54MuuWkRivJYAGD7PVSC0Eh+/J1e2Egx 0nNGIHc2YSgCNLgkL3sqhTN1SCcV5NxArGX9SYo/FJ/YLoJVDq6jGxactjXlcAbKKPLE dajbfsiWuDXxEvNA3T980trER5jzVMpau2+0KAP2QUjL/pHBrcUNUpKvTW5JYK5O/Jdm zt4g== 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=2D8XI6RRwHXSYBkhlVPN0sDbyCqcL/XC6y2L1vFoTRU=; b=0/RgyKTH5RwcRCMLhFb6zKZhmm76covV2ByVJHDGlyG9yiCOp3xEE27yZ9xTdr+tfm UMQhVEO3ax2gn/7W8YIZHs9ofSMJoY862aBBkV9rsUaFVQeC65IVUM3gLM2L6S/K4aiE IWqvs9YKPfQy68L3622BMPcJIl5GIOl4ITAuVwObL39iw+QB7JAAu73WQW3FgocoiLDQ sKsL9jlCreSFTTeU01LUmVhDs0ZcP5HagTOD9gUVgoY2atMhlhvbcaren5nRU2PjoaDc ZOJbKOiMhTXggpjGXAuT8No9KZcrvlPwKr1YsUl1kDRXF8NqAYBubDH81sqSusPM/g6G zejA== 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 q11si2039712pls.424.2019.08.28.08.09.36; Wed, 28 Aug 2019 08:09:53 -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 S1726844AbfH1PHC (ORCPT + 99 others); Wed, 28 Aug 2019 11:07:02 -0400 Received: from mga02.intel.com ([134.134.136.20]:6091 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726440AbfH1PHB (ORCPT ); Wed, 28 Aug 2019 11:07:01 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Aug 2019 08:07:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,441,1559545200"; d="scan'208";a="380429742" Received: from yyu32-desk1.sc.intel.com ([10.144.153.205]) by fmsmga005.fm.intel.com with ESMTP; 28 Aug 2019 08:06:59 -0700 Message-ID: <29e6afa9cd7a7b0069ec6b999a2830cbbbe50a56.camel@intel.com> Subject: Re: [PATCH v8 11/27] x86/mm: Introduce _PAGE_DIRTY_SW From: Yu-cheng Yu To: Peter Zijlstra 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 Date: Wed, 28 Aug 2019 07:57:41 -0700 In-Reply-To: <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> <20190828070308.GJ2332@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.1-2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2019-08-28 at 09:03 +0200, Peter Zijlstra wrote: > 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. Yes, I will work on that. Yu-cheng