Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3608389pxu; Tue, 8 Dec 2020 17:11:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAYShaMwyGkdcZ55CgfBc6G/+8RtgSBTIEZQqOE7BI9L950lbov7Q0kXxfP0F6/sBOz6GY X-Received: by 2002:a05:6402:b57:: with SMTP id bx23mr582033edb.191.1607476301076; Tue, 08 Dec 2020 17:11:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607476301; cv=none; d=google.com; s=arc-20160816; b=SFkjZOnGvguuYCyUj5jaRD73daE/a1tRV9sI8vwrshNFTDP8Sizyyhni0AcFJnBUMp avsrOP0RzJ2Odypgv+928lRdxCnxJKRX2ITaG+nLcqoXjQQ6ie3VdMvF19bwWT10C9Ha rAV4r4121W86JSfm27Ev5Bwfd6kD92D9EUjhAiP+4HW5yokGUjtkPSftLnkTScRNlNKR T4Wy/bllggnWUv3ah8VS/USxi9DtVMVmGWIA1RN+l9qE4qjQf3R6lIEaSsIi9CDsw2Sv TkFd5UO//G2mjv9u3ama88BeUBEJTJW6FFzO8ytrD3BZNdx3WepjTZafIMUoFFVfSujc Hotg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=V4nItAG0EPAu8kz4hZeO3ACkyZ3taxsWifOesIkESXA=; b=E6/x8MCnKTV1oTa8GFI+PYWOStKPoWDcJpcm0XH4H5svHjsY/TfdpSep6Le4DG3R5s 1fMX6EqGZIOu72rhP2LDk418WBvt8vB9ESBuShHbn+rdGo4R8+l4sE0UMEviZ9vNJnQ+ IKWMv3xZ4zy4C76WFbgj8THJojapJro8Aqfqa6EO0iHW8p2uaZR/MtyvrZIF2gzOqt0f 6nbX6R7zR6U224eFG2reg/xgIJDiJvxCilltaTut9NRNnsEc9Shs9ZIjg3TFVLJ3zVOs BgYlenmuDl4/XF75wmXDo6lcjaTBVNnhwup3Sv2oTTl2HMx/Me/buk/jn0ViiunDkv+h ys5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id w10si86310ejv.730.2020.12.08.17.11.18; Tue, 08 Dec 2020 17:11:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1730133AbgLHUcE (ORCPT + 99 others); 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