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 D15F4D6004C for ; Tue, 19 Nov 2024 08:02:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FCE46B0083; Tue, 19 Nov 2024 03:02:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AC0A6B0085; Tue, 19 Nov 2024 03:02:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 473EC6B0088; Tue, 19 Nov 2024 03:02:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2810D6B0083 for ; Tue, 19 Nov 2024 03:02:37 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CAB1712026E for ; Tue, 19 Nov 2024 08:02:36 +0000 (UTC) X-FDA: 82802101158.10.5B5A88D Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf25.hostedemail.com (Postfix) with ESMTP id A6486A000F for ; Tue, 19 Nov 2024 08:01:57 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VR5McjE9; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732003220; a=rsa-sha256; cv=none; b=ZgqN6oIBx6uorCdPPVHLyKcoQe2guZih2fm/SplrNy73KqpV5T2Kn87+g79wSsT72rxb9v tLKoDj3zuVfZwDk3ThnsAOMvSYY+/zlPliT/FMn/mts1MtKd5Q7/HQw7uMOOTDk3QWf4Fo EvxkK2vLaqcTHbFVCw0JnnnXwXDoTa0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VR5McjE9; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732003220; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3ptxWOLhwY83i5UqA3Iw8IEjORQN26nE+qFNN5zhqLE=; b=Ji2HngobkqDxne/i7RpYtQ1Tr08i4qi127popqqTc6fH+LOph/WYCc9i6m63nLUXAl9t7+ MW6bk5hQ40PmzFqYKBvX40PgFPWgZK9Q2+v7aaj0/4DgqMppcAyIEaTE0Sxuv5TF88kNQ+ MWThIRcmD2LKPF3lVjsU0A3P2NZVEYM= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-724a96f188cso990950b3a.1 for ; Tue, 19 Nov 2024 00:02:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1732003352; x=1732608152; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=3ptxWOLhwY83i5UqA3Iw8IEjORQN26nE+qFNN5zhqLE=; b=VR5McjE94XMyFNLKuwdNIAPBGO434O1DZDfjwQeo8vEDyxOdP9QES8OEF+QD3N2u4G 4Z/Ls0Is2Cuq3bhtjxpgnaeUWqVGDuoAwi6PpYMko5jEw1yxMRNCcSZLXTXd3HuUYnxm Kg7E/cusr4pPuGINktIio9P5r3PGOa7v70uQ47UcTfZ0yJps9d+IrEcWHAazKztyArCd c+WX/kZaOmdefAjzqtTvwXbuqZExM03iKw2/FeHlMBOgkK3bk22tpv9XT3UeQf1ai9RA JdkISpLZgMnruDbJYIYCE4s866ewsIx98ACHXtORs9jRXuq334ERAyLRtzJs5kJuaxjW PQig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732003352; x=1732608152; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3ptxWOLhwY83i5UqA3Iw8IEjORQN26nE+qFNN5zhqLE=; b=W8Q8biDcAdVKCSM57AujNYddFlDXOGulLEai7AW5c7DxCkEgeRrhel7CT/4cU6VlQj ZisNQ/JwVqWddjRdeUk2vzPn2Fiwr+/Mw5JE+zMKBBGSvvqZf03eYMFyMetHvgw7kX4y 5sxL19zlNdjnaHbQ2Qr+Xmp+A90sUP/hTGJjgYZ1HsSenzlCu2K1+7J72nfjP2Xbk57v jUgAo9Z5Wu87Yw/bchh12nFHrO0aItYrnrjUGCZQzajVMxwot+7GLfREVosokKbQBQpP tXgcIxGVGNMtFp09hMNSJXgN9l48hp6BMi4Nj+iTnq1WoKg4PfpkRvflkl7y6cSJL4iw BH4w== X-Forwarded-Encrypted: i=1; AJvYcCVamSsaOn/Zx9uAJsADCpaEvvPPOWzJboTjkf+Mko0kMITKTVGOHMMWQ7ZKrjhijzLY/5NkRULZ9Q==@kvack.org X-Gm-Message-State: AOJu0YzOWKsUX9i0E+uodWR0SmIb9GEPWcdhUSFM9Rx8wWmqgN/8PyMU 2TYRcNJsE2MG1s17Mt48EmY5XAKQigLeECA9OZ/j1P6wwQku6HQ48x8Gu0I4PKQ= X-Google-Smtp-Source: AGHT+IFSWv+2WRwnRxskSn9wpDBXbKF5P/y3Yv7eTYqxzDn6NDsCS5xMho5ZtmuTYi+6cJfHNobtnA== X-Received: by 2002:a05:6a20:6a26:b0:1dc:6fed:6248 with SMTP id adf61e73a8af0-1dc90b47d0emr23645373637.22.1732003352420; Tue, 19 Nov 2024 00:02:32 -0800 (PST) Received: from [10.84.149.95] ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724771c04e3sm7696427b3a.102.2024.11.19.00.02.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Nov 2024 00:02:31 -0800 (PST) Message-ID: <9c12aa68-47c5-4def-92ff-7f91502d85a5@bytedance.com> Date: Tue, 19 Nov 2024 16:02:23 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] docs/mm: add more warnings around page table access Content-Language: en-US To: Lorenzo Stoakes Cc: Jann Horn , Andrew Morton , Jonathan Corbet , "Liam R . Howlett" , Vlastimil Babka , Alice Ryhl , Boqun Feng , Matthew Wilcox , Mike Rapoport , Suren Baghdasaryan , Hillf Danton , SeongJae Park , Bagas Sanjaya , linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Matteo Rizzo References: <20241118-vma-docs-addition1-onv3-v2-1-c9d5395b72ee@google.com> <21195425-53d9-4007-a020-8106f94158dc@bytedance.com> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: A6486A000F X-Stat-Signature: 6z3bpzum1kd1yjcpjmw8aegkp5ur4n8r X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732003317-883404 X-HE-Meta: U2FsdGVkX18MO7Ia7UMr2K6Y6nMyGcwb9xhyzhPY55FXv/tZR+NdBqVMbgoPPT50yqthKXxzt9PEkGcLIerdDxKXfh5sVE9TOXLagbig8+tNKPfg/ENAy0WZ0KWFQ873cLlV+SChesmXCBzYoosV2u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hUHEdkQXvlgk02BF81uvq2Pdjtzjsu4sTmAsU98gDWZAm3MgpeGeAxzAZ27gqr1jhavZCd7VdgG4i10vGrrEcdAwPsGTPUSWnMb06mg0ZiYvLnm8nOJ5UVLhRktAizmQwjs4lvEO8QqXg+vGfTLrcgvOH0bwMD4QUntR3yWuxrWuI2n8J+JDSAjQJ/JwevJ79LVgWoZGNoXIDBQiStVMg2/dFbupY3D/GAMNfBbF7NmaWbxAscCOFiN57iMwl4AcMRgVcrOlA== 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: List-Subscribe: List-Unsubscribe: On 2024/11/19 15:48, Lorenzo Stoakes wrote: > On Tue, Nov 19, 2024 at 02:53:52PM +0800, Qi Zheng wrote: >> >> >> On 2024/11/19 00:47, Jann Horn wrote: >>> Make it clearer that holding the mmap lock in read mode is not enough >>> to traverse page tables, and that just having a stable VMA is not enough >>> to read PTEs. >>> >>> Suggested-by: Matteo Rizzo >>> Suggested-by: Lorenzo Stoakes >>> Signed-off-by: Jann Horn >> >> Acked-by: Qi Zheng >> >>> + >>> +* On 32-bit architectures, they may be in high memory (meaning they need to be >>> + mapped into kernel memory to be accessible). >>> +* When empty, they can be unlinked and RCU-freed while holding an mmap lock or >>> + rmap lock for reading in combination with the PTE and PMD page table locks. >>> + In particular, this happens in :c:func:`!retract_page_tables` when handling >>> + :c:macro:`!MADV_COLLAPSE`. >>> + So accessing PTE-level page tables requires at least holding an RCU read lock; >>> + but that only suffices for readers that can tolerate racing with concurrent >>> + page table updates such that an empty PTE is observed (in a page table that >>> + has actually already been detached and marked for RCU freeing) while another >>> + new page table has been installed in the same location and filled with >>> + entries. Writers normally need to take the PTE lock and revalidate that the >>> + PMD entry still refers to the same PTE-level page table. >>> + >> >> In practice, this also happens in the retract_page_tables(). Maybe can >> add a note about this after my patch[1] is merged. ;) >> >> [1]. https://lore.kernel.org/lkml/e5b321ffc3ebfcc46e53830e917ad246f7d2825f.1731566457.git.zhengqi.arch@bytedance.com/ > > You could even queue the doc change up there? :>) OK, I can add this note to my patch after this patch is merged. > > I think one really nice thing with having docs in-tree like this is when we > change things that alter the doc's accuracy we can queue them up with the > patch so the doc always stays in sync. Agree. > > I feel you may have accidentally self-volunteered there ;) > >> >> Thanks! >> >>>