Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp50291rwe; Wed, 31 Aug 2022 16:12:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR61zQNq6BPM9C7aNuUxuiYzDSjC0ZtLcTmGSEhVfhki+1QxFQW5TUjPAjHXTT1RvKVPTUVh X-Received: by 2002:a17:903:32d0:b0:174:ce51:223f with SMTP id i16-20020a17090332d000b00174ce51223fmr16589498plr.117.1661987548812; Wed, 31 Aug 2022 16:12:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661987548; cv=none; d=google.com; s=arc-20160816; b=sLxES5qNtX1sYX7rI5uPZXbXlDY7QnPrGrudZQps1r9IEVHwJm++fULFDOVcdb6Iku RA7LUlIg+wEjlyNIXjC6W6qi5oSMHVX21IcRPed4Cdqceyg4j0aPrh4cDMjJxE5CCBfM LQfbZvECSe4fXWAEM7Y2AyrM3/Kes3G9OQgMwcsVMR6PUdXVK62usFliDJ+GFB8kiN+T yh9D4wNIQFgT6tdZthENVYGOsI3UFxx6w4wBJjPlxyE4tmm+NkLBrjMWlWhDO5h6it7b NkctyB3ikCtJkXJVuPsX3vSMPFDgNmo0n/j3dgLmqSza/Lh+XD9SoJubeql0akhR5n9f JqSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WRCQZgWLTXU/lpwaQlz63bh8ZvhuW6knrkLWrQ9v+Ds=; b=yAePnoLh1It1Qe5QwuZnNv/E+HR1uc/VHkPI3e1/sw+uzUzWCPAQ2a/81DAulDhjOZ wskOgwyZ2kpLNQ8+ccfLfMLMNKZ0gpku/3TskWnGcfJz4DKrRsJ3PclKDqYlZ+X8Z4NT DofI+37xCoWYM4mtVCLADmkS5E8Z0rFeq0HR22p1qSK5xbcOeuzJa5/GQipNKxYXg/VE Fp4tjLtq2eaWUO6s7jFZ28kMLRT2+CUkLniCz3nObvF9OibObWDaKUpwnmh1s7c51jjh pGYmkZZOyMzWypHpsgl1zNJlIslcNV7Bcz6G/6B0K7rYWyPic2dZ9ZmcnJIg1iGgnuYo xWeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DHX2VRhk; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a656944000000b0042a020bd06bsi6713659pgq.781.2022.08.31.16.11.54; Wed, 31 Aug 2022 16:12:28 -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=@gmail.com header.s=20210112 header.b=DHX2VRhk; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbiHaVo5 (ORCPT + 99 others); Wed, 31 Aug 2022 17:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232279AbiHaVox (ORCPT ); Wed, 31 Aug 2022 17:44:53 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD553270B for ; Wed, 31 Aug 2022 14:44:47 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id t11-20020a17090a510b00b001fac77e9d1fso539131pjh.5 for ; Wed, 31 Aug 2022 14:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=WRCQZgWLTXU/lpwaQlz63bh8ZvhuW6knrkLWrQ9v+Ds=; b=DHX2VRhksok+uLiBnn5V9eNyQQ6MwdoobPxth/5Ok1rK0Lb3E4TIsiEGwWMxYGYSQx Dj8Dxjvu4F/y2801SdQtXiPkrNlyF0leyPC/W4BzZi8Zfg1KqA9jMIFPRQJ6NSQhH0si 82PMXpVUg1TEwi58+eg/k8yoxwvaU4rCjawWNsKU5KdWNU9VwI424vkwqBQhEd7E2WhL UPLGytahb8T6YERt11ky+8I2I1+xEKdk69wgypF+QqLyKdukTML83N7Qa24y3ywsR4Zd jJ68BV04GQryJkVUgSR2vQh3eCAIuTAAtHy0UdswJ9yIf05/3LJM28UfxsnPYI0WRsgc yzSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=WRCQZgWLTXU/lpwaQlz63bh8ZvhuW6knrkLWrQ9v+Ds=; b=GJI7ernKfVT4e7ujji/3uiqqcCNEl39svRHekW7KQc9VaNeijoiNIfRSd3UCbtCl+v TSp4qBLsML0jo8hTAwaWgiRQg8K5Srx9ghBeh8MVB8Q0TwhqtZNGJwdENJ2+j+xHPWxF NGVnGLm1cFdshiGUbAhzx70FW1PUH3Ua5OdAXVxX09EoP4WCUsciDV/THn9DFvWdiD4N OgpN9foANM7l88J7Tl2idgDE5vN7Fg63AUaNibZPR69q1+DjRTsKaXjCT9Cf104CFYll Q8L62vWSNiboYQ+plEGLVw7XNaaQnAUzLHjLly0jqHs+sP7GF23CHSzRb5zpfzAdllMw 2l0g== X-Gm-Message-State: ACgBeo1+Io8YUcTHglVwFIChmlQVrQQjyE1/DpCDBzNEo+IyjQPOfm9O 59Xtrfm3by549oUUcJA23VczP0BFJRSFM3PGDns= X-Received: by 2002:a17:902:e5c3:b0:175:534:1735 with SMTP id u3-20020a170902e5c300b0017505341735mr11716724plf.87.1661982286512; Wed, 31 Aug 2022 14:44:46 -0700 (PDT) MIME-Version: 1.0 References: <20220831083024.37138-1-david@redhat.com> In-Reply-To: From: Yang Shi Date: Wed, 31 Aug 2022 14:44:33 -0700 Message-ID: Subject: Re: [PATCH v1] mm/ksm: update stale comment in write_protect_page() To: Peter Xu 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" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, 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 2:09 PM Peter Xu wrote: > > 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. Yeah, so ptep_clear() is used in __collapse_huge_page_copy() instead of clear and flush. > > 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. This was what I thought before I saw this patch. > > -- > Peter Xu >