Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp962259rwe; Wed, 31 Aug 2022 14:24:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR4v8dFOAhOtliig0OeyxyhYB8K+t3+1jQalfsG6Xqxi7N3TaHdvFYdJsIcACn2l+DluN+7R X-Received: by 2002:a05:6402:cbc:b0:448:95be:397 with SMTP id cn28-20020a0564020cbc00b0044895be0397mr11482499edb.417.1661981087071; Wed, 31 Aug 2022 14:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661981087; cv=none; d=google.com; s=arc-20160816; b=wXj4nS7xRKzb3DnFUR1xYWmxngSGt2apnk4/Kw2efw+nHxVnhfdlAbljYqzBKpsWqZ 5yntQRGffgh7t+7nTnGHQPrEG5R0wUvLaU5tF2CRYXnkWvlJ8Qg+Cib9OsnGa+nBIhT1 yfnK3mi1hAYz3L3ALK53de7iHo2HflrmsYFWJzHSeEyjmsik1dYAf0JHPedOBTjaTLFC ds2yAz+WIJ/kFVkb7YKRO/qimGqOxDgWPtUHdK1eFDGp3LDwRgS9+k00Aq7EeZcfutes Trn6PQYOejzE+monvPhLQoOnIKbX5TorlfIwoy4gDjXwbvX1nfH2F8CwQtDUSOa3Nt3j 6DbA== 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=O7Gxcm/s5JjFXHzoKoyt8QS8s8qTIKG6E+N6uf7ppnw=; b=lC0ADgC4Eo25xvUVqSZsH7CYL1+eTBbljwwEC3NnXnW209pEAz60FGpQmGqcwYZaan eEyNYC5OMZBDUxw4728QOyvzryAS11i8SkBlehcZcjPsBqk1k3iIYoZS2dvRV2717Mva ri1zcHeF4bLtLHSNfJ4aFfpb+LZiQxeKy+Vby2AdBadGvGWhme0vk9mwfG+zKHf1jJc9 6fx7TbtGzywmz4NeTikJobSbBLeQsXSnP1OGfUsS2Q4rwtesiCSonKBYQmG40AYRSBhD 2OOCz5WuStxt1fgl9yImQJUL/HJxwlM3D3KJ2bsNBY9/litZflTSbikokuGO6YlFHdg/ 2h4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FAb4Wlkl; 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 y25-20020a50e619000000b0044838667a9fsi188060edm.357.2022.08.31.14.23.52; Wed, 31 Aug 2022 14:24:47 -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=FAb4Wlkl; 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 S231645AbiHaVJZ (ORCPT + 99 others); Wed, 31 Aug 2022 17:09:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiHaVJY (ORCPT ); Wed, 31 Aug 2022 17:09:24 -0400 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 7B4C6F32C2 for ; Wed, 31 Aug 2022 14:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661980161; 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=O7Gxcm/s5JjFXHzoKoyt8QS8s8qTIKG6E+N6uf7ppnw=; b=FAb4WlklL3KknZOocXoXZ8D6js2ET7AOFnp7RgoL0IxK9nMZIkMLZyxPZJqmc87rPe2uQG ee2YzgCO4Z1Ii6VZ3AqauvTkcHUvBbuy7wmLCVuUs1IXzIEaxHLeiJiVzf6ZE7rOZ8TNzh S3jpkEltYZADx0PM6OZIngsWs4WIEfM= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-424-yWwy2qHMPeejgnJLok1-hA-1; Wed, 31 Aug 2022 17:09:20 -0400 X-MC-Unique: yWwy2qHMPeejgnJLok1-hA-1 Received: by mail-qt1-f199.google.com with SMTP id fv24-20020a05622a4a1800b003445e593889so12057898qtb.2 for ; Wed, 31 Aug 2022 14:09:20 -0700 (PDT) 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; bh=O7Gxcm/s5JjFXHzoKoyt8QS8s8qTIKG6E+N6uf7ppnw=; b=e7q04sG2JXHfp4fJk4Dnfw4FPw0YkRULP14O2zAkAy7x0EbXEVMngr1NR1TBqFWyev MAd112aeC1eOOfzAWSenOrAMrmTl8dlQT/Mfet3SxWXQ9e5uNhqxyVTVEuIvA2ta0i25 xWl06YZZ+uD+X8KbSosXVbso4In8jBHeBhMCcbEo8OTUppmRuz9skk/8zwzoW0s0K0cT ACwiQtYxkNOh8YiAeO84FYh/+Nxrryr3L5FmjOtDgdq55YLX5tQ0TZx6c/S2X4mrrD7G K3i2z/TpJ4IGhCB9WOwLgg7JKy8wzFJ/Gc3ecKyUnjhswP1//9JKiths+zR54iuFTDeS PYNw== X-Gm-Message-State: ACgBeo3DWfsUhuXOt18sEAbp0gE/J6Ti/GpND+c/PM7FvFfzO8fGySWr WSvYdcU/q+nRmuOdBPs17baIblXBpq+ditTjNkSzZvUbSvIlW8RLyXpXERhiVK7pfs26/tvz2rj 6NyAZ+XINGlBN79U9g0qailw+ X-Received: by 2002:a05:6214:2a4b:b0:499:eb9:6ed3 with SMTP id jf11-20020a0562142a4b00b004990eb96ed3mr9976096qvb.66.1661980160119; Wed, 31 Aug 2022 14:09:20 -0700 (PDT) X-Received: by 2002:a05:6214:2a4b:b0:499:eb9:6ed3 with SMTP id jf11-20020a0562142a4b00b004990eb96ed3mr9976082qvb.66.1661980159943; Wed, 31 Aug 2022 14:09:19 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id s18-20020a05620a255200b006bbc09af9f5sm11066305qko.101.2022.08.31.14.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 14:09:19 -0700 (PDT) Date: Wed, 31 Aug 2022 17:09:17 -0400 From: Peter Xu To: Yang Shi Cc: David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Jason Gunthorpe , John Hubbard , Andrea Arcangeli , Hugh Dickins , "Kirill A. Shutemov" Subject: Re: [PATCH v1] mm/ksm: update stale comment in write_protect_page() Message-ID: References: <20220831083024.37138-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Wed, Aug 31, 2022 at 01:38:21PM -0700, Yang Shi wrote: > On Wed, Aug 31, 2022 at 11:52 AM Peter Xu wrote: > > > > On Wed, Aug 31, 2022 at 10:55:43AM -0700, Yang Shi wrote: > > > On Wed, Aug 31, 2022 at 1:30 AM David Hildenbrand wrote: > > > > > > > > The comment is stale, because a TLB flush is no longer sufficient and > > > > required to synchronize against concurrent GUP-fast. This used to be true > > > > in the past, whereby a TLB flush would have implied an IPI on architectures > > > > that support GUP-fast, resulting in GUP-fast that disables local interrupts > > > > from completing before completing the flush. > > > > > > Hmm... it seems there might be problem for THP collapse IIUC. THP > > > collapse clears and flushes pmd before doing anything on pte and > > > relies on interrupt disable of fast GUP to serialize against fast GUP. > > > But if TLB flush is no longer sufficient, then we may run into the > > > below race IIUC: > > > > > > CPU A CPU B > > > THP collapse fast GUP > > > > > > gup_pmd_range() <-- see valid pmd > > > > > > gup_pte_range() <-- work on pte > > > clear pmd and flush TLB > > > __collapse_huge_page_isolate() > > > isolate page <-- before GUP bump refcount > > > > > > pin the page > > > __collapse_huge_page_copy() > > > copy data to huge page > > > clear pte (don't flush TLB) > > > Install huge pmd for huge page > > > > > > return the obsolete page > > > > Maybe the pmd level tlb flush is still needed, but on pte level it's > > optional (where we can rely on fast-gup rechecking on the pte change)? > > Do you mean in khugepaged? What I wanted to say before was that the immediate tlb flush (after pgtable entry cleared) seems to be only needed by pmd level to guarantee safety with concurrent fast-gup, since fast-gup can detect pte change after pinning, and that should already guarantee safe concurrent fast-gup to me. After reading the other emails, afaiu we're on the same page. > It does TLB flush, but some arches may not use IPI. Yeah, I see that ppc book3s code has customized pmdp_collapse_flush() to explicit do the IPIs besides tlb flush using smp calls. I assume pmdp_collapse_flush() should always be properly implemented to guarantee safety against fast-gup, or I also agree it could be a bug. -- Peter Xu