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=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 4037CC2D0EC for ; Sun, 12 Apr 2020 21:45:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 00A34206E5 for ; Sun, 12 Apr 2020 21:45:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JX8EIeN9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 00A34206E5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A118A8E00EF; Sun, 12 Apr 2020 17:45:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C2CF8E00D0; Sun, 12 Apr 2020 17:45:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88AD98E00EF; Sun, 12 Apr 2020 17:45:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 722DB8E00D0 for ; Sun, 12 Apr 2020 17:45:53 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 286024403 for ; Sun, 12 Apr 2020 21:45:53 +0000 (UTC) X-FDA: 76700535786.21.jail76_8aa321095ad27 X-HE-Tag: jail76_8aa321095ad27 X-Filterd-Recvd-Size: 6502 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Sun, 12 Apr 2020 21:45:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586727952; 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=1YrVEfVATlkusm7GWPMt4fu995oJMyWZhfaJGZ4arQw=; b=JX8EIeN9lmmsZabzA2s2iKaStz92zY1Gt2I/cebjhL4S/NQgm1jJghw1LpG1vb0SLS64ht xcgpk+qWsf2J5+xAdrOzmUJbpVfR7VZ9TESxC0wQFXh1khykuYhHDYHLIzjrTxV6UPylzQ uI2sWhXD0hCPQuOeEI9JuDN03SKYfu8= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-29-w0SV9VD4MxCg8wSOeLlreg-1; Sun, 12 Apr 2020 17:45:47 -0400 X-MC-Unique: w0SV9VD4MxCg8wSOeLlreg-1 Received: by mail-qk1-f200.google.com with SMTP id f187so5622790qkd.11 for ; Sun, 12 Apr 2020 14:45:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=gDOZbGbYc6a0ITpk5OWVoS7nLueP9baBRaeKv2m/AsE=; b=bTa15dXCRtFhJ81z6UO39kMD5pzl1Idd8uet8fZdodUEFnNM1LXwroFSbH4Kw0QUZ0 yjvRYJ56mh/XWz6fNAr3c8jMql+hKl1ahvGbRYpt39iqlzCQi9yfm1dP9NxdMVpRetaz PjSvcthG72x+9P2vQLktlAiEqBkYyATNNHvXEJh7d/BdRg6LdUjGjPWTTCupFxS0JkUO zx5aEpgrtrTfvxmMYno94TsfMlWCU44QrnFPtmOoWwhddHqWgAhtFZtCOLgOZjLBfNhR cAfSKOJg+AYJEeEUyr7ifNVcyi54HN+cNfAj9uImduaGLMSUb+8H8rjKGQPuhgsm47l5 gO7g== X-Gm-Message-State: AGi0PubUYdA1ksLyQSFmRsBsWlyLoTjokGHbAPx4GNQk/2Nrwpbr8CcK EV436GTwtfXmTXZhLs24KkuRM+tRU8OvkCWAQWEQIMOnqEN9BF1lH4UINs0G6RsUgXsPNT5b40b RXiLaJCbq2Ow= X-Received: by 2002:a0c:ffcb:: with SMTP id h11mr2115022qvv.166.1586727946967; Sun, 12 Apr 2020 14:45:46 -0700 (PDT) X-Google-Smtp-Source: APiQypJHpqxXU+mPC9x54gU9Fp9TiGbPpXJJG6ATF65B0HQPWkrjAxOez+nEQRO0BEdJ//5gIJignA== X-Received: by 2002:a0c:ffcb:: with SMTP id h11mr2115009qvv.166.1586727946729; Sun, 12 Apr 2020 14:45:46 -0700 (PDT) Received: from xz-x1 ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id u14sm6944716qtq.41.2020.04.12.14.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2020 14:45:46 -0700 (PDT) Date: Sun, 12 Apr 2020 17:45:45 -0400 From: Peter Xu To: Hillf Danton Cc: mm , lkml Subject: Re: f45ec5ff16 ("userfaultfd: wp: support swap and page migration"): [ 140.777858] BUG: Bad rss-counter state mm:b278fc66 type:MM_ANONPAGES val:1 Message-ID: <20200412214545.GC38470@xz-x1> References: <20200410002518.GG8179@shao2-debian> <20200410073209.11164-1-hdanton@sina.com> <20200412125408.18008-1-hdanton@sina.com> MIME-Version: 1.0 In-Reply-To: <20200412125408.18008-1-hdanton@sina.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 Sun, Apr 12, 2020 at 08:54:08PM +0800, Hillf Danton wrote: >=20 > On Fri, 10 Apr 2020 11:32:34 -0400 Peter Xu wrote: > >=20 > > I'm not sure this is correct. As I mentioned, the commit wanted to > > apply the uffd-wp bit even for the swap entries so that even the swap > > entries got swapped in, the page will still be write protected. So > > IIUC think we can't remove that. >=20 > Yes you are right. >=20 > Now both CONFIG_MIGRATION and swap entry are restored after making uffd_w= q > survive migrate the same way as soft_dirty. >=20 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -236,6 +236,8 @@ static bool remove_migration_pte(struct > =09=09pte =3D pte_mkold(mk_pte(new, READ_ONCE(vma->vm_page_prot))); > =09=09if (pte_swp_soft_dirty(*pvmw.pte)) > =09=09=09pte =3D pte_mksoft_dirty(pte); > +=09=09if (pte_swp_uffd_wp(*pvmw.pte)) > +=09=09=09pte =3D pte_mkuffd_wp(pte); > =20 > =09=09/* > =09=09 * Recheck VMA as permissions can change since migration started > @@ -243,15 +245,11 @@ static bool remove_migration_pte(struct > =09=09entry =3D pte_to_swp_entry(*pvmw.pte); > =09=09if (is_write_migration_entry(entry)) > =09=09=09pte =3D maybe_mkwrite(pte, vma); > -=09=09else if (pte_swp_uffd_wp(*pvmw.pte)) > -=09=09=09pte =3D pte_mkuffd_wp(pte); > =20 > =09=09if (unlikely(is_zone_device_page(new))) { > =09=09=09if (is_device_private_page(new)) { > =09=09=09=09entry =3D make_device_private_entry(new, pte_write(pte)); > =09=09=09=09pte =3D swp_entry_to_pte(entry); > -=09=09=09=09if (pte_swp_uffd_wp(*pvmw.pte)) > -=09=09=09=09=09pte =3D pte_mkuffd_wp(pte); > =09=09=09} > =09=09} > =20 > --- a/mm/mprotect.c > +++ b/mm/mprotect.c > @@ -139,11 +139,13 @@ static unsigned long change_pte_range(st > =09=09=09} > =09=09=09ptep_modify_prot_commit(vma, addr, pte, oldpte, ptent); > =09=09=09pages++; > -=09=09} else if (is_swap_pte(oldpte)) { > +=09=09} else if (IS_ENABLED(CONFIG_MIGRATION)) { > =09=09=09swp_entry_t entry =3D pte_to_swp_entry(oldpte); > =09=09=09pte_t newpte; > =20 > -=09=09=09if (is_write_migration_entry(entry)) { > +=09=09=09if (!non_swap_entry(entry)) { > +=09=09=09=09newpte =3D oldpte; > +=09=09=09} else if (is_write_migration_entry(entry)) { > =09=09=09=09/* > =09=09=09=09 * A protection check is difficult so > =09=09=09=09 * just be safe and disable write > @@ -164,7 +166,7 @@ static unsigned long change_pte_range(st > =09=09=09=09if (pte_swp_uffd_wp(oldpte)) > =09=09=09=09=09newpte =3D pte_swp_mkuffd_wp(newpte); > =09=09=09} else { > -=09=09=09=09newpte =3D oldpte; > +=09=09=09=09continue; > =09=09=09} > =20 > =09=09=09if (uffd_wp) >=20 >=20 Hi, Hillf, Feel free to have a look at another report, which I think is the same issue of this: https://lore.kernel.org/lkml/CA+G9fYsRGvkqtpdGv_aVr+Hn17KgYq04Q=3DEE=3DpB77= 4qVxRqOeg@mail.gmail.com/ IMHO this bisected commit is correct itself, it's just that we shouldn't enable uffd-wp on 32bit system. Thanks, --=20 Peter Xu