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 08F4EC4332F for ; Thu, 17 Nov 2022 18:28:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A3D68E0002; Thu, 17 Nov 2022 13:28:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7541C6B0075; Thu, 17 Nov 2022 13:28:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F5428E0002; Thu, 17 Nov 2022 13:28:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 513F26B0073 for ; Thu, 17 Nov 2022 13:28:59 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2E42940191 for ; Thu, 17 Nov 2022 18:28:59 +0000 (UTC) X-FDA: 80143770798.24.9F0F197 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 848AE40008 for ; Thu, 17 Nov 2022 18:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668709736; 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=SCwrHAH8w/75e7RIvwniXR2/IhWfvKJ1bBk1DvOk8y4=; b=cWnQPGXfdwVAJY8FJ+DDH2B9TeGKbYoW739RsJRsp04qGPmLAaPosSL8yzCdRdUInMIwgP Cp+ObXVUjHRoiiRMOG/uMrUtYYxb/Mw/nGHkTsAHOwEJPa7WtdYAgR94Lb2QmeVfbvJm79 igbBZrcF5TXUKfDYLKZw6mDIor0FKD8= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-626-pfuP3MPTM1yvX7YvVh7Cew-1; Thu, 17 Nov 2022 13:28:55 -0500 X-MC-Unique: pfuP3MPTM1yvX7YvVh7Cew-1 Received: by mail-qk1-f198.google.com with SMTP id i17-20020a05620a249100b006fa2e10a2ecso3125116qkn.16 for ; Thu, 17 Nov 2022 10:28:55 -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=SCwrHAH8w/75e7RIvwniXR2/IhWfvKJ1bBk1DvOk8y4=; b=1BaSwsSGxqaqTiZXVNTu+hqgNBJWG9A8oUilruWXn89hhpKQ/jBd+wBgq447IzDCph uMSB9xxMVH6ULP2dxxUO0FiDAqjd9vcOl39QSfLcX10mhsh66maykUnoUCWcQrYRPkWU FCVnUAewnf+PvZYcO6z4Xyax7z3/hRac1e5dZEVNo/UbgBD3QHwaxyo7tdJKZS1aME2I 7aCL6Lab5Hrwg69F7NhwyCpMNSdmKxvJ08L7cVKF55hPmL/tn01+BvTSiKQkCDoLW+H7 TcC1vJNjdOP+wd94PtrgkTUbpRFpJB2S5T4YJvDTZRLazwCFmUijPt9+dd1cke14cpWI d2/w== X-Gm-Message-State: ANoB5pnCJWBNzU912iRUCwqhVMujj8GWfsGaeJAGKd+GsVGda38xc0M8 oEKN+MBlnpSYkvr5nNeNcYITXkviKPfimvSvEZRFa7XZl0oz23gVrG3yBdgMeFY2jmlcuUF6wgu kIix8z7Hrx04= X-Received: by 2002:a37:aad6:0:b0:6fa:e0bb:cb6d with SMTP id t205-20020a37aad6000000b006fae0bbcb6dmr2861717qke.707.1668709735336; Thu, 17 Nov 2022 10:28:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf6x5K8X5t9p31ZONbie6/kQJJQKF067lEy8gKV5E7CZydHtJU7W40Elm22ZNmEjr6VTLNzuwA== X-Received: by 2002:a37:aad6:0:b0:6fa:e0bb:cb6d with SMTP id t205-20020a37aad6000000b006fae0bbcb6dmr2861702qke.707.1668709735067; Thu, 17 Nov 2022 10:28:55 -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 o10-20020ac841ca000000b00399fe4aac3esm733817qtm.50.2022.11.17.10.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 10:28:54 -0800 (PST) Date: Thu, 17 Nov 2022 13:28:53 -0500 From: Peter Xu To: hev Cc: Anatoly Pugachev , 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: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668709737; a=rsa-sha256; cv=none; b=j14S6thmm19WRB1PtS17oZdHotdXIyMpmJQjhP2dn68nW7y3M6I+zV5q1SV+3Jj2yElF4P TWTulJqFKfiVLp1m0hYaZazHIkjyWY8ADCrlQ9EMVjyadoKFjeg88kK/xQewl9bcyl3l9K 7aJhsPUuobjYfko7HZlVtBv/mydE2vA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cWnQPGXf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668709737; 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=SCwrHAH8w/75e7RIvwniXR2/IhWfvKJ1bBk1DvOk8y4=; b=Eg0JXWumMLNvKr/Kd+KmijvPAHdtCMWbhhye3hpLgTkJfWIrSZWoW+J5y1TPZUn5IIHePH 1QKCAEgZ4GSjQwx10GywbbJTGjR+l0eFbq/Ati8ptc1QtMzOApAwuJWe2IDprjXzYix5uJ tdTHkgZaXtC30gwjHAUVTXeSmxjwA0w= Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cWnQPGXf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspam-User: X-Stat-Signature: p5z5p4ggddeh6uak397ougk76kdb5aba X-Rspamd-Queue-Id: 848AE40008 X-Rspamd-Server: rspam11 X-HE-Tag: 1668709737-415103 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: 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? But I agree the write bit is not set, not because !VM_WRITE, but because we take care of that explicitly to make sure pte has the same write bit as pmd: (pmd used to be wr-protected due to fork()) write = pmd_write(old_pmd); ... (then when split pte shouldn't have write bit too) if (!write) entry = pte_wrprotect(entry); > > and the dirty is true, > > if (dirty) > entry = pte_mkdirty(entry); > > so the incorrect arch's pte_mkdirty set hardware writable > bit(_PAGE_DIRTY) in unconditional for read-only pages. True, that does also apply to sparc64 pte_mkdirty() with _PAGE_W_4[UV]. I should have noticed earlier that its comment told me that's a write bit already.. #define _PAGE_W_4U _AC(0x0000000000000002,UL) /* Writable */ Thanks, -- Peter Xu