Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1710520rwl; Sun, 26 Mar 2023 07:48:43 -0700 (PDT) X-Google-Smtp-Source: AKy350ZUPrU34+h/3oYjK+eT3Qn+YqIRM+ZZXeeK2v3+JKs2AYAdyINLO+hSwjPaLlXg0KqYKIM/ X-Received: by 2002:a62:84c8:0:b0:626:18da:1afe with SMTP id k191-20020a6284c8000000b0062618da1afemr8954011pfd.33.1679842123495; Sun, 26 Mar 2023 07:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679842123; cv=none; d=google.com; s=arc-20160816; b=zLMaS3sraQqW2VckvJ4boTJbv0zwOso/ymAC2OHV9wbDQK+/992t9QneW2DNhkEwcg Tvpl58CL8CRowV/9ol6KPF2JOxmLnvt6j7k/rtHVqCrDxh4S7g1ZP3fHk8GOuipyXtCu abHw8ip6vIuY6cIfqg+4EqleNZKWZ2VofoTL+HzA5MDKMd6HyizemLyLGS3t35WZqtbK uvOcNjEqr5r0VqPwmdCmQhBOdvBIulspSN1EvGO2TZXHCiATlTAgnc9HCv+1D+zajIHe u+NhvJglKV4KHowofHTmJUpiObVvMUegSKEKSL1AV2P2hXt5tPI/kOwLPkWjj2Geqk2T D3rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NCwOxvpkJi/AFwFKPQO+eqD2wLsuChYdcKGvoGw4Tsg=; b=Ro0pXs0cVuuXuats89Zsw/PuQOiWLIE0kGuD60/RA6wXSQDsbkJo1q9dOS+SFLfdQn 0Oe1nnhbG7d1wykWR24pu5pC6FZeRDn6bhT6NMf8Qd+sg4tF+JNWmYT/vWF9rF+o1LEl Tyy+tegN0rymG23Ef+PsyL+ctEZcMSJY1AwqlYUXYWdZyvMOnFLjr5g3xouOGWezTnE+ NCRh4YEAvOi65aDq+LxPbJ/xHpiIGmQ+gTsKVIVQjkaq8NCtTt9yio4oaMFY7xdnrIMc k85yrDHEx3YUvA7GYAsLqx9omJ/DfkEPKZvIEcWrC44nn2sHR/Rjru/csCsIXf/+Skip fy1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Lg5t5cvT; 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 q2-20020aa78422000000b005941ff7940dsi5742061pfn.203.2023.03.26.07.48.32; Sun, 26 Mar 2023 07:48:43 -0700 (PDT) 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=Lg5t5cvT; 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 S231960AbjCZOrO (ORCPT + 99 others); Sun, 26 Mar 2023 10:47:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231258AbjCZOrN (ORCPT ); Sun, 26 Mar 2023 10:47:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAEC14682 for ; Sun, 26 Mar 2023 07:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679841987; 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=NCwOxvpkJi/AFwFKPQO+eqD2wLsuChYdcKGvoGw4Tsg=; b=Lg5t5cvTOKmuZ2hG0tMHvhn51sbYjW7adE2UzK+wf0mjSHiBK1ul87WnTra8Ig+B4bAgTe +Q9xM0OjFjqqPWDRNHDP9idVHf15+lBIJuklcDmvmuzZCyXIO1TSIZJIH4UusY6RzjJEVZ jYX5cQycnhDqy61yaCBSx8nLzmSXh0k= Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-247-NigeDiCGOiK6Q33tageoCw-1; Sun, 26 Mar 2023 10:46:26 -0400 X-MC-Unique: NigeDiCGOiK6Q33tageoCw-1 Received: by mail-yb1-f200.google.com with SMTP id 3f1490d57ef6-b7294bdd4e3so51146276.0 for ; Sun, 26 Mar 2023 07:46:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679841985; 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=NCwOxvpkJi/AFwFKPQO+eqD2wLsuChYdcKGvoGw4Tsg=; b=zFrCeBnMgJ6ayrZaIcZFV+3mdIENDkhZOPeHBIkiUMZmT+6fokHRibFdFb3cJoApy7 mkea1rdCNRUiAxlClckObx6hyhJIGFJX6n+8nf7pekLilR2OEoXC2jHuKCaG6Mez/4k6 9qSLe+KYuD2v1wVcff/G322E8OkJ3xWWrZOrpq77pBFDvDdMDn3Lxzr/MyTwgeEtjQ7h Y4t3fpCAYVj/4vra3kSFwHgGTnPVKUNzuBP65Xfbl3zsrKz12MinY+ZJ+O3a74NLMkgE fwNgEJXwHmTsnFzIDgY/nPLCL2EnruUtT8CyqHAktuR3DwGK2RrWr9yOBrqYGcKw3PNN 22ow== X-Gm-Message-State: AAQBX9dH5mRo5Ori8JbSkBpjFx55bl6/jzaWfglYbJZhUhdNAxQPl+xf SkHO8QfCzoNA+2NNXS60CmaFx6kF9f/nFpP1xM+htXmV1mdXb/UgjHMPIXefsL65UXVRMtl+Bas 45MbU8YAkvqseK47YOdrLJS9K1pukxqHh X-Received: by 2002:a25:aca5:0:b0:b74:4bff:53fa with SMTP id x37-20020a25aca5000000b00b744bff53famr7539679ybi.6.1679841985577; Sun, 26 Mar 2023 07:46:25 -0700 (PDT) X-Received: by 2002:a25:aca5:0:b0:b74:4bff:53fa with SMTP id x37-20020a25aca5000000b00b744bff53famr7539662ybi.6.1679841985233; Sun, 26 Mar 2023 07:46:25 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id v130-20020a252f88000000b00b7767ca7490sm1755262ybv.45.2023.03.26.07.46.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Mar 2023 07:46:24 -0700 (PDT) Date: Sun, 26 Mar 2023 10:46:22 -0400 From: Peter Xu To: David Hildenbrand Cc: Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Mike Rapoport , Nadav Amit , Axel Rasmussen , Andrea Arcangeli , Muhammad Usama Anjum , linux-stable Subject: Re: [PATCH v3] mm/hugetlb: Fix uffd wr-protection for CoW optimization path Message-ID: References: <20230324142620.2344140-1-peterx@redhat.com> <20230324222707.GA3046@monkey> <8a06be33-1b44-b992-f80a-8764810ebf3f@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <8a06be33-1b44-b992-f80a-8764810ebf3f@redhat.com> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Fri, Mar 24, 2023 at 11:36:53PM +0100, David Hildenbrand wrote: > > > @@ -5487,6 +5487,17 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, > > > unsigned long haddr = address & huge_page_mask(h); > > > struct mmu_notifier_range range; > > > + /* > > > + * Never handle CoW for uffd-wp protected pages. It should be only > > > + * handled when the uffd-wp protection is removed. > > > + * > > > + * Note that only the CoW optimization path (in hugetlb_no_page()) > > > + * can trigger this, because hugetlb_fault() will always resolve > > > + * uffd-wp bit first. > > > + */ > > > + if (!unshare && huge_pte_uffd_wp(pte)) > > > + return 0; > > > > This looks correct. However, since the previous version looked correct I must > > ask. Can we have unshare set and huge_pte_uffd_wp true? If so, then it seems > > we would need to possibly propogate that uffd_wp to the new pte as in v2 Good point, thanks for spotting! > > We can. A reproducer would share an anon hugetlb page because parent and > child. In the parent, we would uffd-wp that page. We could trigger unsharing > by R/O-pinning that page. Right. This seems to be a separate bug.. It should be triggered in totally different context and much harder due to rare use of RO pins, meanwhile used with userfault-wp. If both of you agree, I can prepare a separate patch for this bug, and I'll better prepare a reproducer/selftest with it. -- Peter Xu