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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 790EAC38A2D for ; Tue, 25 Oct 2022 13:34:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DD5F8E0002; Tue, 25 Oct 2022 09:34:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98C778E0001; Tue, 25 Oct 2022 09:34:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 854708E0002; Tue, 25 Oct 2022 09:34:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 736C48E0001 for ; Tue, 25 Oct 2022 09:34:10 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 37E041A0DD1 for ; Tue, 25 Oct 2022 13:34:10 +0000 (UTC) X-FDA: 80059565460.04.92B08F7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP id 286CC1C003B for ; Tue, 25 Oct 2022 13:34:07 +0000 (UTC) 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> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666704849; a=rsa-sha256; cv=none; b=mJMFp/hzTVNvdnC+/gMqpat6Rm3Us/htpFzHKEdiu7NgN+LfVu80QjIiL+8e2kdAojk6kU 1UhepVtPFkvDflJOWO8TowQXdX1xnIYr1inX+QfOLmD97PAjP+mmMFDNeiBBYTz1/FPQTC UaY1+vm6HR2YwZj9WI0SnUMQNNB/b8w= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=EplYQi+2; dmarc=none; spf=none (imf18.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666704849; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/0LrqpBKoT14DLc9iF9kREM8XNEtSFkQdKsz+ozJdig=; b=hKBvCnmAErmmJxRBvPBC+8PGaSD3QTaMWC7ihGk76zsuEfiApoFM2cRIfmuR4X8Vyc5So9 HAaZlXpqa2AI7pxnY0lxWZIurjwpfrd7PmNdDdE1IqxCiNG0J9qDO+zLmSR3RR8EzwKK8U l/tu+j8BP93Oyz/IGVn1dMq1cyu0hHU= X-Stat-Signature: qib7heuxzwh3kz5n3m7xus9q6j5inzhg X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 286CC1C003B Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=EplYQi+2; dmarc=none; spf=none (imf18.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org X-HE-Tag: 1666704847-122556 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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).