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 4CD2BC433FE for ; Mon, 21 Nov 2022 18:55:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD3188E0002; Mon, 21 Nov 2022 13:55:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C83CF6B007E; Mon, 21 Nov 2022 13:55:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7C7D6B007B; Mon, 21 Nov 2022 13:55:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A79D76B007B for ; Mon, 21 Nov 2022 13:55:57 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 80DDB1C634E for ; Mon, 21 Nov 2022 18:55:57 +0000 (UTC) X-FDA: 80158353954.11.E66FBDD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 0EB751C0008 for ; Mon, 21 Nov 2022 18:55:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669056956; 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: in-reply-to:in-reply-to:references:references; bh=Z5+22swyofsVzFKE0+iGpJAFrVWZEQt1SutCN9FgWPA=; b=YGk7YB+EntsIqrhHwGlekH44uteBikNhzIBGWpwKGe4dy5Tf0RFgn2TsSm+PT0FXC06st7 JH+rFNbv/rGVHUHVrd0gipK1AS5b2aLfEE80MM6z9miPv+cOboQ7JghDFJkNgx7GNuYIag qLAd4jur67aron41hc6bveau/wY+nBA= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-22-wnH0EvGkPBWdL1l4fOljpg-1; Mon, 21 Nov 2022 13:55:54 -0500 X-MC-Unique: wnH0EvGkPBWdL1l4fOljpg-1 Received: by mail-qv1-f69.google.com with SMTP id on28-20020a056214449c00b004bbf12d7976so12110449qvb.18 for ; Mon, 21 Nov 2022 10:55:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vNb5TWM1Ex5oTrwhjEXEfbipjw7z3HX9TgJtMa+3kWw=; b=pliiRrnGE9i58q5PH46KV/E1MxMg5zBI6cf/2n9agieY1+Y2xuv/XDsXKZip32Oq4u JhdWSCfRjy7e3Hgj3+dc0jlG1OGOZsUH5f9KCfPQmQ8AGgTwIdALq/8wO2/dtFvnZFfD wqGJsyYKYu6/G31zEkWRXkRlDyI6tXbh5pM6330l3uBidsC1iALz+RdLkW6qGExwiIT+ m+dwlduhcDgBaAzyDx++ntBXXhr2g3nwTMkqIjok+VC0z2YHaY03+9rVruAqim7g/Fa9 tIbNaohBjIDMUTyC3lRJ/4dNbvEH1Vl5ScmmtsZ3XNZyY8wqaUJAYCBUuZif5RV0lj8j MiRQ== X-Gm-Message-State: ANoB5pmoKjJxXV0skkuglObIGfBcmHP4p8+mdBZLBiy7dtVXt50GV0j5 8GjK6V8AvWkWA22dvYfsQVRNlCbK0SXDpfVpJ+qLD5EOVA6NlArlQOS5bjVmvS2SgIuWDEExzAl 4doRDVe4mGVk= X-Received: by 2002:ac8:41d0:0:b0:39c:b702:8ec with SMTP id o16-20020ac841d0000000b0039cb70208ecmr18280497qtm.253.1669056953755; Mon, 21 Nov 2022 10:55:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf671XvtqVEYSSt0VvwoYRnvBNU5DmAwJSm3eexlvvQqhsxWuf1JDsdhesL0eeu6wzPGE1oNuw== X-Received: by 2002:ac8:41d0:0:b0:39c:b702:8ec with SMTP id o16-20020ac841d0000000b0039cb70208ecmr18280478qtm.253.1669056953454; Mon, 21 Nov 2022 10:55:53 -0800 (PST) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id t18-20020a05620a451200b006fafc111b12sm8931024qkp.83.2022.11.21.10.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 10:55:52 -0800 (PST) Date: Mon, 21 Nov 2022 13:55:51 -0500 From: Peter Xu To: Anatoly Pugachev , hev Cc: hev , Thorsten Leemhuis , Sparc kernel list , linux-mm Subject: Re: Test case for "mm/thp: carry over dirty bit when thp splits on pmd" Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="e9TD/csLxyFJ3Twt" Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669056957; a=rsa-sha256; cv=none; b=ZWXUI5utZw+Mi8c3gNfQhCMzHRJGH/o7Wq5NlflnxmXUZcSsueSqbxfO+TswmSEXLRoQyV vorqhuXjz92YjADD3r9NfO9Fgl7zFvzTQuoReUG8kPAYpCvNrvlO5gWNZOQdZBncvi1eEl yAdNZqSfG6qtV4RdpcnEqLyPJzzbQ5k= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YGk7YB+E; spf=pass (imf21.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1669056957; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Z5+22swyofsVzFKE0+iGpJAFrVWZEQt1SutCN9FgWPA=; b=pv8B9TB16buoQPtJs2qyAZx0Gw6kVul20RrCf6KtVzRRrufIAsFa8Mw3EhY7DKvsdcwnbM HNRQBqxW1qaplinR3nRob1g7ZwYwoxHHllXLlFQ6FpFJSHbYftni6lisIvTtfMRMxDNaZf 50GbYlMoYNQQc5iEvd1/eNAQo6WdRxQ= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0EB751C0008 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YGk7YB+E; spf=pass (imf21.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Stat-Signature: 5wguufn6h4mtqzyqe6d5i7hs4a8mthzw X-HE-Tag: 1669056956-77517 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --e9TD/csLxyFJ3Twt Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Hi, Anatoly (or/and Hev), 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, > > > > 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. > > > > Here is a simple and fast testcase (It may be helpful for sparc64): > > https://gist.github.com/heiher/72919fae6b53f04cac606a9631100506 > > (assertion: c sum == 0) > > Just tried on my sparc64 VM - fixed vs old (non-patched) kernels... > > fixed kernel (6.1.0-rc5) running ./a.out: > mator@ttip:~$ ./a.out > c sum: 0 > p sum: 35184372088832 > c sum: 0 > p sum: 35184372088832 > c sum: 0 > p sum: 35184372088832 > c sum: 0 > p sum: 35184372088832 > c sum: 0 > p sum: 35184372088832 > ... > > old (non-patched) kernel (6.1.0-rc4) : > mator@ttip:~$ ./a.out > c sum: 35150012350464 > p sum: 35184372088832 > c sum: 35150012350464 > p sum: 35184372088832 > ... I've got another patch attached that might be nicer to fix this same problem for both archs but without dropping the dirty bit, could you help check whether it works? Hopefully the new patch could replace the other one (624a2c94f5b7 Partly revert "mm/thp: carry over dirty bit when thp splits on pmd") in Andrew's tree before it lands next rc1, and this new one should be applicable directly to e.g. v6.0 tag (or need to have 624a2c94f5b7 reverted if on any of Andrew's trees). -- Peter Xu --e9TD/csLxyFJ3Twt Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="0001-mm-thp-Wr-protect-pte-after-mkdirty.patch" >From e349b24573870ef50d0c1b3bf124e14f5dfe1fa5 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Mon, 21 Nov 2022 13:36:59 -0500 Subject: [PATCH] mm/thp: Wr-protect pte after mkdirty Content-type: text/plain Anatoly Pugachev reported sparc64 breakage on the patch: https://lore.kernel.org/r/20221021160603.GA23307@u164.east.ru Hev also reported similar issue on loongarch: (the original mail was private, but Anatoly copied the list here) https://lore.kernel.org/r/CADxRZqxqb7f_WhMh=jweZP+ynf_JwGd-0VwbYgp4P+T0-AXosw@mail.gmail.com Also Hev pointed out that the issue is having HW write bit set within the pte_mkdirty() so the split pte can be written after split even if e.g. they were shared by more than one processes, causing data corrupt. Hev also tried to explain why loongarch set HW write bit in mkdirty: https://lore.kernel.org/r/CAHirt9itKO_K_HPboXh5AyJtt16Zf0cD73PtHvM=na39u_ztxA@mail.gmail.com One way to fix it is as what Huacai proposed here for loongarch: https://lore.kernel.org/r/20221117042532.4064448-1-chenhuacai@loongson.cnn Or more agressively, not sure whether (IMHO) we can remove the "optimization" to grant HW write bit in pte_mkdirty() in both archs, leaving set the write bit only in pte_mkwrite(). For now the simpler solution that'll work for all is we wr-protect after pte_mkdirty(), so the HW write bit can be persistent after thp split. Cc: Hev Cc: Andrew Morton Reported-by: Anatoly Pugachev Signed-off-by: Peter Xu --- mm/huge_memory.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e5f5a1a00596..ae90b65f6121 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2191,13 +2191,18 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, entry = maybe_mkwrite(entry, vma); if (anon_exclusive) SetPageAnonExclusive(page + i); - if (!write) - entry = pte_wrprotect(entry); if (!young) entry = pte_mkold(entry); /* NOTE: this may set soft-dirty too on some archs */ if (dirty) entry = pte_mkdirty(entry); + /* + * NOTE: this needs to happen after pte_mkdirty, + * because some archs (sparc64, loongarch) could + * set hw write bit when mkdirty. + */ + if (!write) + entry = pte_wrprotect(entry); if (soft_dirty) entry = pte_mksoft_dirty(entry); if (uffd_wp) -- 2.37.3 --e9TD/csLxyFJ3Twt--