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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B253C433FE for ; Mon, 21 Nov 2022 19:57:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9F586B0074; Mon, 21 Nov 2022 14:57:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4F906B0075; Mon, 21 Nov 2022 14:57:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D16EB8E0001; Mon, 21 Nov 2022 14:57:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C2A3E6B0074 for ; Mon, 21 Nov 2022 14:57:52 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8A267A09F1 for ; Mon, 21 Nov 2022 19:57:52 +0000 (UTC) X-FDA: 80158509984.16.40D7391 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 8F0AC140004 for ; Mon, 21 Nov 2022 19:57:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669060669; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XPlBQXmJ5evKwNgTVcA7C80tIxQSellMXEsHFcRanUk=; b=G2BqKw0zHv3fMQoOZGRxYNUzsvFPbe/O1U7bowLBOkQu8Hdde7PlvHZ7hCTMkAXGW2QniM uh8jAWrkOjcxjfRR9Mll/XBCLcpjnBuQ2KeR1EZw8pHTHYnTWYdufwslHlPcviJ6n3/6GX FAbCCmOe7d2C7dN4OiiDizgfnfGZp9M= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-522-aSyVKubFOg6RipiOWgwmug-1; Mon, 21 Nov 2022 14:57:46 -0500 X-MC-Unique: aSyVKubFOg6RipiOWgwmug-1 Received: by mail-wm1-f72.google.com with SMTP id ay19-20020a05600c1e1300b003cf758f1617so9791554wmb.5 for ; Mon, 21 Nov 2022 11:57:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XPlBQXmJ5evKwNgTVcA7C80tIxQSellMXEsHFcRanUk=; b=d/nicAmb9qzNzPgq0DZ6lRlHyF9LKuKn3F0Unh6yqBnt4mohw7C9XlQKITX//J3bWb VuDHC9ZzR0/MW1d+/81xWJ6YIvf6P0sBhEQKu8mRXswIsIH+BY9t/iE78hrB3YxEiGnr ppw+eg38esFR407bBPMvrgk66oNflyOf1OY3QxJr/wD6pYgWmCn47+TmtXRCMQUHxjLX Z6V5WFXJ6L8500Gvf77wxKnr6/iOJH/jtluCl+gt+C/BNBKwDqiU5fnpuL2PBvMz/bzM VNEN2cAAg556e2+/3RQSZo79CXsvK/UVpv/f3wv45A76l/pyVpr9XBzz3b/YyHqAwJu7 M6sQ== X-Gm-Message-State: ANoB5pm9z2Yoo0wNrrUyQ9I6pLiJ8a4hLNGW9iiAbgibpG9prw2JzrnE SaHOC2Cl1OhUcx050QRaYJI9Spk39k7DeSvfxhSicLwxLD3vpntCBFdA0nrH6+kiHmP2+vBLCa8 Okk8fEw/eC6M= X-Received: by 2002:a05:600c:4e13:b0:3cf:86b8:71f7 with SMTP id b19-20020a05600c4e1300b003cf86b871f7mr18148000wmq.76.1669060665333; Mon, 21 Nov 2022 11:57:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf65NRVPabgH8LNOkymNHBwNkhBJEr9UcjvaSftZKvy8dJsW7/2IKe/d/GMGIfuMBDFu66FvcQ== X-Received: by 2002:a05:600c:4e13:b0:3cf:86b8:71f7 with SMTP id b19-20020a05600c4e1300b003cf86b871f7mr18147982wmq.76.1669060664987; Mon, 21 Nov 2022 11:57:44 -0800 (PST) Received: from [192.168.3.108] (p5b0c67dc.dip0.t-ipconnect.de. [91.12.103.220]) by smtp.gmail.com with ESMTPSA id g18-20020a5d5412000000b00241bd7a7165sm10998413wrv.82.2022.11.21.11.57.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Nov 2022 11:57:44 -0800 (PST) Message-ID: <79cf9e73-440c-5ff0-856f-3df6c13061ef@redhat.com> Date: Mon, 21 Nov 2022 20:57:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: Test case for "mm/thp: carry over dirty bit when thp splits on pmd" To: hev , Peter Xu Cc: Anatoly Pugachev , Thorsten Leemhuis , Sparc kernel list , linux-mm References: From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669060671; a=rsa-sha256; cv=none; b=M2FoQU2DCXtcu9nhwdHPYvtgOOYi60w3HyAQM6oNtjl2Rno65aZ92FGmGaB0Is3ec6imOg 2Cqx0flPsfPFR/tKPDBPuJOJNUsR5RylP0hlagnbQLGEqLpCTXHM+4As0O5PJ23CzqrAu2 q7MmM+qJoTSASOg7ghXgGorPbuAUlS4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=G2BqKw0z; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669060671; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=XPlBQXmJ5evKwNgTVcA7C80tIxQSellMXEsHFcRanUk=; b=jH1I+IZg+2D4yoeObttTWbm/fq+z52JnM2Aghyue3YbylpdprR2JzHwQXfTUgEaQfXWzXp WtU6AfPd2ziXzxJVa4HyhVRhcC533OczmNaT0/gzpXradJysblG27KiRN70JtX1bdNgIfN 0B5lG7Fo/7jEuzHzoz/cJZwml88HGRc= X-Rspam-User: X-Stat-Signature: kszgpxfsm8sjbt19sg9mw7dwhxo64ran X-Rspamd-Queue-Id: 8F0AC140004 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=G2BqKw0z; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam07 X-HE-Tag: 1669060670-465159 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000146, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 19.11.22 15:06, hev wrote: > Hi, Peter, > > On Fri, Nov 18, 2022 at 2:29 AM Peter Xu wrote: >> >> On Thu, Nov 17, 2022 at 10:29:57AM +0800, hev wrote: >>> Hi Peter, >> >> Hi, Hev, >> >>> >>> On Thu, Nov 17, 2022 at 12:25 AM Peter Xu wrote: >>>> >>>> On Wed, Nov 16, 2022 at 01:45:15PM +0300, Anatoly Pugachev wrote: >>>>> On Wed, Nov 16, 2022 at 11:49 AM hev wrote: >>>>>> >>>>>> Hello Peter, >>>> >>>> Hi, Hev, >>>> >>>> Thanks for letting me know. >>>> >>>>>> >>>>>> I see a random crash issue on the LoongArch system, that is caused by >>>>>> commit 0ccf7f1 ("mm/thp: carry over dirty bit when thp splits on >>>>>> pmd"). >>>>>> >>>>>> Now, the thing is already resolved. The root cause is arch's mkdirty >>>>>> is set hardware writable bit in unconditional. That breaks >>>>>> write-protect and then breaks COW. >>>> >>>> Could you help explain how that happened? >>>> >>>> I'm taking example of loongarch here: >>>> >>>> static inline pte_t pte_mkdirty(pte_t pte) >>>> { >>>> pte_val(pte) |= (_PAGE_DIRTY | _PAGE_MODIFIED); >>>> return pte; >>>> } >>>> >>>> #define _PAGE_MODIFIED (_ULCAST_(1) << _PAGE_MODIFIED_SHIFT) >>>> #define _PAGE_MODIFIED_SHIFT 9 >>> >>> _PAGE_MODIFIED is a software dirty bit >>> >>>> #define _PAGE_DIRTY (_ULCAST_(1) << _PAGE_DIRTY_SHIFT) >>>> #define _PAGE_DIRTY_SHIFT 1 >>> >>> _PAGE_DIRTY is a hardware writable bit (bad naming), meaning that mmu >>> allows write memory without any exception raised. >> >> (I just missed this email before I reply to the other one, I should have >> read this one first..) >> >> I see. This surprises me a bit, as I can't quickly tell how it'll always >> work with the generic mm code. >> >> Say, is there a quick answer on why _PAGE_DIRTY is set here rather than >> pte_mkwrite()? Because AFAIU that's where the mm wants to grant write >> permission to a page table entry as the API, no? >> >>> >>>> >>>> I don't see when write bit is set, which is bit 8 instead: >>>> >>>> #define _PAGE_WRITE (_ULCAST_(1) << _PAGE_WRITE_SHIFT) >>>> #define _PAGE_WRITE_SHIFT 8 >>> >>> _PAGE_WRITE is a software writable bit (not hardware). >>> >>> As David said, In __split_huge_pmd_locked, the VMA does not include VM_WRITE, >>> >>> entry = maybe_mkwrite(entry, vma); >>> >>> so the pte does not include software writable bit (_PAGE_WRITE). >> >> Are you sure? In your test case you mapped with RW, IIUC it means even >> after the fork() VM_WRITE is set on both sides? > > Sorry, I was wrong. > > In this case, both VMAs are writable, the pte's writable bit is > cleared by pte_wrprotect. So if pte_mkdirty sets hardware writable bit > unconditionally, then there will be no way to catch writes to > implement COW. > > I will try to explain how it works about pte write, dirty and > write-protect on LoongArch in the LoongArch mailing-list. Just to ask again, is code like maybe_mkwrite(pte_mkdirty(entry), vma); Like we have in copy_present_page(), wp_page_reuse(), wp_page_copy() ... broken on LoongArch of the VMA lacks VM_WRITE? That would need *real* fixing, no hacks around that in other code areas. -- Thanks, David / dhildenb