Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2407181rwb; Fri, 16 Dec 2022 01:23:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf4tL1L0iv/jmkKRz6BF+9jiy2M9Z9Jp2kSH0Ui8aoHykhm/70ChUNet6S2W/VHsQZc50AWh X-Received: by 2002:a17:902:aa47:b0:186:6661:1f54 with SMTP id c7-20020a170902aa4700b0018666611f54mr31284093plr.39.1671182620333; Fri, 16 Dec 2022 01:23:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671182620; cv=none; d=google.com; s=arc-20160816; b=X+K+GsEDoQzvj6K5YO3eZRydCq9X0wKY2FRrZFdbjf3q8cRMRlDtuEkSbpg00oqWOC +KrL76G0TNGel/I0qQntIMAon9D24QBWSDgjQKfvoRqj5DhSBhE4YQQEhnHWRGTqvVx0 wEiFHUkJYHWCx7UxU2/GbiSKJSpr1LZ/wq1+r6FlUAvGBDZX5bkt4ub6YZ698r5cDhgL CL1R1wHRmRYVG9pHDeztuVraShRSHseMTEqRhPQIO/mL9SDnSdwdgr+rISU8RdmYqj/8 5PQCaMLwUGeSQONf2cSGow/BVWcNpvPDckxZxyM4PSYI6goArxIGZoAtQ5QHa2B07cvB 6mHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=LJMVmx5617wnYVO/Ti21QHTcgxd/PcheSNh2Us8/9os=; b=0QjK5dqqXQ0seE9DWydntoyrsKEFQHAQ3jZw6WLXC/7GCEr1ipNZQ9hmc/bgYMhg9H 6GyvTYvkGm0eAEE/MtglU9a6fmSJ/PJ5io7oP4/39lvhImM5Wj5tXPAdMlozF7KAWgg7 4O/l1D/PWATH5cTnBbU2rKsfbCJGpCkEQCF4zxZtkTHYwFKSRIxEJjVbCi5CxBOG6MU0 5fezCNQNfGQzKCm0BypmO8ioPNAqmWGjZiuPL3HwapK0emxCuW3ByIS/YDz6QzS4yi9B ItTO6Wa3CifJ4HnnPA7QuEnLgEEd7kN5L+PyyvRM84JRq8LpkRvZc1+0sc7EkEIMOVnA T0Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aozE8vGo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q7-20020a170902eb8700b0016f1781307csi1870364plg.303.2022.12.16.01.23.29; Fri, 16 Dec 2022 01:23:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aozE8vGo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230071AbiLPJFk (ORCPT + 69 others); Fri, 16 Dec 2022 04:05:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbiLPJFO (ORCPT ); Fri, 16 Dec 2022 04:05:14 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AEE42E9EE for ; Fri, 16 Dec 2022 01:04:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671181471; 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=LJMVmx5617wnYVO/Ti21QHTcgxd/PcheSNh2Us8/9os=; b=aozE8vGo+gT+EvRZ0u9JZaPAUTu72QqzSOO5gkndp7sHZLKKpKpWn2sVaKP+GbXfdR81zB zydYcUitc0gjQVtlc0vKd13R4PZAfZ8bGVyxfqSEUxu5sA1rpvqIAZBA8JKfrx2q6ZC9OH FnFaK6lNS8atNHvVoPRzgkAgvw7qwBs= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-36-GDodXZT1O7C0YBWLAH1yUg-1; Fri, 16 Dec 2022 04:04:30 -0500 X-MC-Unique: GDodXZT1O7C0YBWLAH1yUg-1 Received: by mail-wm1-f69.google.com with SMTP id p14-20020a05600c204e00b003cf4cce4da5so442309wmg.0 for ; Fri, 16 Dec 2022 01:04:30 -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:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LJMVmx5617wnYVO/Ti21QHTcgxd/PcheSNh2Us8/9os=; b=ZqaoWJAC5ccAb9cAu3k0mcEjx/JQBKuyjCHoT1WRz4PhDv4yCdQZTkyY2V9xyhUurs 32XyfXMGXGRvDjf9i4s1DCHNRJddABgwBko63GltWbPL+oJOmgADd1t7XRn5Smk5GXSQ pn0ARruJSmyNMc/AXmHb01B5r8Vv5EfAitLqKDu6eg/k3Ii1KTZnoczhQHrYEigmzNL9 09k76+YjNescEi8cq2UceOlMkjkaw4tlNv9peRkbKzplmjNqe4nGjEzLb5vAoumRUU6E MJxTmZw9r5zF56bWNjzAfbFs3LMdBmp3iIs//5/Rg+UVzc7yqZ5JKRr2yq2K6tUOBRpp iRFg== X-Gm-Message-State: ANoB5plpPQ5igTxEeKaDi8tJbIQRqdiNnSwrLWkf7cYN4u2bbtF++cl/ qQiL0yC5v4lsd5ksU3BsH5OB6+c/MEgLcucGEeHj1YEryDyf6b768QAoy+ZIAAfxADVux9aG3oc N7ekDdnVuUXg9Nqs00i5azFal X-Received: by 2002:a05:600c:5570:b0:3d1:ee6c:f897 with SMTP id ja16-20020a05600c557000b003d1ee6cf897mr24618889wmb.3.1671181469142; Fri, 16 Dec 2022 01:04:29 -0800 (PST) X-Received: by 2002:a05:600c:5570:b0:3d1:ee6c:f897 with SMTP id ja16-20020a05600c557000b003d1ee6cf897mr24618865wmb.3.1671181468820; Fri, 16 Dec 2022 01:04:28 -0800 (PST) Received: from ?IPV6:2003:cb:c71c:3900:7211:d436:8d8b:531c? (p200300cbc71c39007211d4368d8b531c.dip0.t-ipconnect.de. [2003:cb:c71c:3900:7211:d436:8d8b:531c]) by smtp.gmail.com with ESMTPSA id k5-20020a05600c1c8500b003d237d60318sm2096196wms.2.2022.12.16.01.04.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Dec 2022 01:04:28 -0800 (PST) Message-ID: <618b69be-0e99-e35f-04b3-9c63d78ece50@redhat.com> Date: Fri, 16 Dec 2022 10:04:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Content-Language: en-US To: Peter Xu , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrea Arcangeli , Pengfei Xu , Nadav Amit , Andrew Morton , Miaohe Lin , Huang Ying , stable@vger.kernel.org References: <20221214200453.1772655-1-peterx@redhat.com> <20221214200453.1772655-2-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH 1/2] mm/uffd: Fix pte marker when fork() without fork event In-Reply-To: <20221214200453.1772655-2-peterx@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14.12.22 21:04, Peter Xu wrote: > When fork(), dst_vma is not guaranteed to have VM_UFFD_WP even if src may > have it and has pte marker installed. The warning is improper along with > the comment. The right thing is to inherit the pte marker when needed, or > keep the dst pte empty. > > A vague guess is this happened by an accident when there's the prior patch > to introduce src/dst vma into this helper during the uffd-wp feature got > developed and I probably messed up in the rebase, since if we replace > dst_vma with src_vma the warning & comment it all makes sense too. > > Hugetlb did exactly the right here (copy_hugetlb_page_range()). Fix the > general path. > > Reproducer: > > https://github.com/xupengfe/syzkaller_logs/blob/main/221208_115556_copy_page_range/repro.c > > Cc: # 5.19+ > Fixes: c56d1b62cce8 ("mm/shmem: handle uffd-wp during fork()") > Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216808 > Reported-by: Pengfei Xu > Signed-off-by: Peter Xu > --- > mm/memory.c | 8 ++------ > 1 file changed, 2 insertions(+), 6 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index aad226daf41b..032ef700c3e8 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -828,12 +828,8 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, > return -EBUSY; > return -ENOENT; > } else if (is_pte_marker_entry(entry)) { > - /* > - * We're copying the pgtable should only because dst_vma has > - * uffd-wp enabled, do sanity check. > - */ > - WARN_ON_ONCE(!userfaultfd_wp(dst_vma)); > - set_pte_at(dst_mm, addr, dst_pte, pte); > + if (userfaultfd_wp(dst_vma)) > + set_pte_at(dst_mm, addr, dst_pte, pte); > return 0; > } > if (!userfaultfd_wp(dst_vma)) Staring at the code first made me go "what about other PTE markers". I then looked into the discussion in patch #2. The fix as is is suboptimal, because it 1) Removes the warning which is good, but 2) Silently drops swapin errors now So it silently breaks something else temporarily ... I remember, that theoretically we could have multiple markers stored in a single PTE marker. Wouldn't it be cleaner to be able to "clean" specific markers from a PTE marker without having to special case on each and everyone? I mean, only uffd-wp is really special such that it might disappear for the target. Something like (pseudocode): if (!userfaultfd_wp(dst_vma)) pte_marker_clear_uff_wp(entry); if (!pte_marker_empty(entry)) { pte = make_pte_marker(pte_marker_get(entry)); set_pte_at(dst_mm, addr, dst_pte, pte); } Then this fix would be correct and backport-able even without #2. And it would work for new types of markers :) I'd prefer a fix that doesn't break something else temporarily, even if the stable backport might require 5 additional minutes to do. So squashing #2 into #1 would also work. -- Thanks, David / dhildenb