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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 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 D9D1AC4167B for ; Tue, 8 Dec 2020 20:32:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2BA923AA8 for ; Tue, 8 Dec 2020 20:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730139AbgLHUcE (ORCPT ); Tue, 8 Dec 2020 15:32:04 -0500 Received: from mga05.intel.com ([192.55.52.43]:9234 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbgLHUcD (ORCPT ); Tue, 8 Dec 2020 15:32:03 -0500 IronPort-SDR: LzMBVq1Ey1fd9+7nnwuV7N7TpPXukRIUFX1KZZYRNs07xl2z6Mrf4c8o9wQYWclU4moncwkBQz HZQ1cJEVA6KQ== X-IronPort-AV: E=McAfee;i="6000,8403,9829"; a="258665284" X-IronPort-AV: E=Sophos;i="5.78,403,1599548400"; d="scan'208";a="258665284" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:24:17 -0800 IronPort-SDR: uTi/Mmkl/xKuBC/AXfiazJdiwWLlLG6xSH3fWQdFdTUbXRcuwFtEp5b5pUVtQ+yM50I5q+Vvf8 X9TzX8nXSQNQ== X-IronPort-AV: E=Sophos;i="5.78,403,1599548400"; d="scan'208";a="317940844" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.209.139.184]) ([10.209.139.184]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 11:24:16 -0800 Subject: Re: [PATCH v15 08/26] x86/mm: Introduce _PAGE_COW To: Borislav Petkov 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 , 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 , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu References: <20201110162211.9207-1-yu-cheng.yu@intel.com> <20201110162211.9207-9-yu-cheng.yu@intel.com> <20201208175014.GD27920@zn.tnic> <218503f6-eec1-94b0-8404-6f92c55799e3@intel.com> <20201208184727.GF27920@zn.tnic> From: "Yu, Yu-cheng" Message-ID: Date: Tue, 8 Dec 2020 11:24:16 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: <20201208184727.GF27920@zn.tnic> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/8/2020 10:47 AM, Borislav Petkov wrote: > On Tue, Dec 08, 2020 at 10:25:15AM -0800, Yu, Yu-cheng wrote: >>> Both are "R/O + _PAGE_COW". Where's the difference? The dirty bit? >> >> The PTEs are the same for both (a) and (b), but come from different routes. > > Do not be afraid to go into detail and explain to me what those routes > are please. Case (a) is a normal writable data page that has gone through fork(). So it has W=0, D=1. But here, the software chooses not to use the D bit, and instead, W=0, COW=1. Case (b) is a normal read-only data page. Since it is read-only, fork() won't affect it. In __get_user_pages(), a copy of the read-only page is needed, and the page is duplicated. The software sets COW=1 for the new copy. >>>> (e) A page where the processor observed a Write=1 PTE, started a write, set >>>> Dirty=1, but then observed a Write=0 PTE. >>> >>> How does that happen? Something changed the PTE's W bit to 0 in-between? >> >> Yes. > > Also do not scare from going into detail and explaining what you mean > here. Example? Thread-A is writing to a writable page, and the page's PTE is becoming W=1, D=1. In the middle of it, Thread-B is changing the PTE to W=0. >>> Does _PAGE_COW mean dirty too? >> >> Yes. Basically [read-only & dirty] is created by software. Now the >> software uses a different bit. > > That convention: > > "[read-only & dirty] is created by software." > > needs some prominent writeup somewhere explaining what it is. > > Thx. > I will put these into the comments. -- Yu-cheng