From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2980C04A95 for ; Tue, 25 Oct 2022 13:34:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232786AbiJYNeR (ORCPT ); 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> 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).