Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8456316rwi; Tue, 25 Oct 2022 07:00:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM50OuZvQ0QhY5CE0zJR+yZaR5R4VWl2U6DZ/PyEylQRJsEdBUPvCwoETo4Qy/FvsIyjIAYB X-Received: by 2002:a05:6402:8cc:b0:45c:a5c9:c0a with SMTP id d12-20020a05640208cc00b0045ca5c90c0amr35741976edz.135.1666706430249; Tue, 25 Oct 2022 07:00:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666706430; cv=none; d=google.com; s=arc-20160816; b=sC4NDgfJMJjXdeqVYE9odAKkRp1VMPZCn6cvc/Wu2LMFk+Va2YHoi0cMoomIzb35mU gk6yEjZlDRzfJK7+kHrD9tomT/lqJWfyqgiUn5+4Q5RmfXOtMkq3dXI2o0YsU1jqEnMt ah25bq5U5e8HhYWpAChEXRjV3BgZvmo2YcESuhxD+4zZIJhHG98b8nEWbtKZ+89vutM7 YBKgN04lbh1ET9e1cDR5TM0dRp55rPyfiztnU24M3YsGdzwhJ5fUZpHZLRXXkTD8M21M NAlpey1pq5naEXUhQ2eJMt2H2bU/8h4M3sGWkBkk6ErteWYEEF4dfQwNqnnh0l0FZzeZ wixw== 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=/0LrqpBKoT14DLc9iF9kREM8XNEtSFkQdKsz+ozJdig=; b=l+YB1rTneacSnbsep/FtFdrsHhq+WvAf/8KEomnT5LCNX+Pkr6Mk4WL2VKxzzyVTGS vOYAmMc9Pxv/vhKUAXmXetxD1VqSjrQui8PNUjj5cdiEA+GYYLvD4s9b+sahCLcPIQz+ S273EEGdZb9N1r2qQSAJihRAFoooro2FQFjUCJzGGoRW3/QLwKZceojOGcEWgiWPcHQQ fCbm+YhAR7hu/NIvtmZTv5mhIEaa2rwDFlfEjGtsOdGu7XBi2QJXtaRyOIaEM/Oc+4nx YFreujjEfl3r5Fr05k3sQ1+rdf0YFc0r+Dzdrl7ReUIrjopfYCcqICmXKFGe3iEB9SA4 nkfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=EplYQi+2; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ke9-20020a17090798e900b0073d8a8fedbfsi2504312ejc.386.2022.10.25.06.59.56; Tue, 25 Oct 2022 07:00:30 -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=@infradead.org header.s=casper.20170209 header.b=EplYQi+2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232768AbiJYNeR (ORCPT + 99 others); Tue, 25 Oct 2022 09:34:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbiJYNeP (ORCPT ); Tue, 25 Oct 2022 09:34:15 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ECC9191886 for ; Tue, 25 Oct 2022 06:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=/0LrqpBKoT14DLc9iF9kREM8XNEtSFkQdKsz+ozJdig=; b=EplYQi+2FgRyy0nKXiWzha1VVW h6QzijZ/jUs57waHQY33Dsvn+kKDJxKDyKJs/6kaDtoBfnwR+M+QIq7gjyzIyWrLSdPKyTtICxAO0 JLraK5zEuXwVhgmoXt5SYLsPlceM2WnSy1vKvITeZGo/kGYkJqNvuLP49m1UpWIrq39Ghm/lEetFX XhuJ8Nv4ncszPCvUPalhXcKygzRcQvJth3QPXjvhPMw0EU9SGSEUZvDA9XAUhI444x0c2vT6H5eFR AZLVZlL4tMOgUc3s8E/Xu1zlP6sKRZ4t83EVE8WoyGHT9kDcBJv0/34l0LKztZp9aK91lODkZfbhM icqb7BVA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1onK4B-00GIRC-Rm; Tue, 25 Oct 2022 13:34:03 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 74F313000DD; Tue, 25 Oct 2022 15:33:58 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 502E22C22E2E2; Tue, 25 Oct 2022 15:33:58 +0200 (CEST) Date: Tue, 25 Oct 2022 15:33:58 +0200 From: Peter Zijlstra To: Alistair Popple Cc: Matthew Wilcox , Jann Horn , Linus Torvalds , John Hubbard , x86@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, aarcange@redhat.com, kirill.shutemov@linux.intel.com, jroedel@suse.de, ubizjak@gmail.com Subject: Re: [PATCH 01/13] mm: Update ptep_get_lockless()s comment Message-ID: References: <20221022111403.531902164@infradead.org> <20221022114424.515572025@infradead.org> <2c800ed1-d17a-def4-39e1-09281ee78d05@nvidia.com> <87fsfcuxu6.fsf@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87fsfcuxu6.fsf@nvidia.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED 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 Tue, Oct 25, 2022 at 06:54:10PM +1100, Alistair Popple wrote: > > First we (locklessly) load the page table entry, then we grab a > > reference to the folio that contains it (which can fail if the > > refcount is zero, in that case we bail), then we recheck that the > > page table entry is still the same, and if it changed in between, > > we drop the folio reference and bail. > > This can, again, grab a reference to a folio after it has > > already been freed and reallocated. The reason why this is > > fine is that the metadata structure that holds this refcount, > > `struct folio` is never freed; even when a folio is > > freed and reallocated, the corresponding `struct folio` > > stays. > > I'm probably missing something obvious but how is that synchronised > against memory hotplug? AFAICT if it isn't couldn't the pages be freed > and memory removed? In that case the above would no longer hold because > (I think) the metadata structure could have been freed. Note, this scheme is older than memory hot-plug, so if anybody is to blame it's the memory hotplug code. Anyway, since all that is done with IRQs disabled, all the hotplug stuff needs to do is rcu_synchronize() in order to ensure all active IRQ-disabled regions are finshed (between ensuring the memory is unused and taking out the struct page).