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 4A456C4321E for ; Mon, 28 Nov 2022 20:12:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAA216B0071; Mon, 28 Nov 2022 15:12:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C59846B0072; Mon, 28 Nov 2022 15:12:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B48596B0073; Mon, 28 Nov 2022 15:12:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A525E6B0071 for ; Mon, 28 Nov 2022 15:12:06 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7A772407F5 for ; Mon, 28 Nov 2022 20:12:06 +0000 (UTC) X-FDA: 80183947452.15.974C517 Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) by imf23.hostedemail.com (Postfix) with ESMTP id 0E4A714000E for ; Mon, 28 Nov 2022 20:12:05 +0000 (UTC) Received: by mail-io1-f53.google.com with SMTP id p141so8487960iod.6 for ; Mon, 28 Nov 2022 12:12:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/ef+VxAVqyHNr3SIX9M4C8tTATvFzdBIjqbBoKeAT+Q=; b=WBerXZPwEY1ilK6ZRkS8aWtbp5YXuT+JdxrGYFOKDBn4r0Q4V2jugeRsZXa3Ock23K S6pwgBWt6in8Yxc4ZlJm4tP1WFl5QZy2PzhQp7BhODjl6SOS81LGOY+BlbVVdeYZFDUw ocrv43TXSTsP3mf1H2S/2ARq/DcyWeojRiMr2Kt2nhhnn2zsy8obV4Drstznj4/gxz90 NImGfj5rl/1U3K+x3BtTEe/zCDf/ElQ6PEOLNQroeQvJMJ0L51px6T3M7e5AfTvUlcRo Xvq9IMZv2VXbij3sp942Lrk7TpfkTLelHENbRsgwt5nIBP/hw3PDS3rlSZuWYo4X2v8y ViWw== 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:message-id :reply-to; bh=/ef+VxAVqyHNr3SIX9M4C8tTATvFzdBIjqbBoKeAT+Q=; b=H99SH7zR5BZ7KHEcSS8tOTQGMHOw/6yuhp6XN/0hTAgs9e/n/tVt4V2K+p4t+ncG+O KsvkHsQ742WX7tIqBJJtCjjC+7PZNnol7L9nAbUkHHde0dd9vo1VL8ehgwNWbcBX5HUH +Hrkvcp7gBNje069JtJjDa3OTsZPcQUVEwpuLijmw6zPHjzQzF8R8Y8rmjH3QZ27pQcf GMR70ZMdf8rxGOxtdnNCLKIT2BoWslD+TPH1sAfye2ZhRuIF2MUkjVI4IoXjgvOYX97t 73+dcwsTOEFjNjuhPY9jdYDeDLXB570R8kfiQR5wy4rMWdNKKlfzxlyLQS1yJ84haFiH DHWA== X-Gm-Message-State: ANoB5pkL1xGHwBeNHF9UnXyP9UaPisCoAVy7PuoPBpjLf0Pc4aANnkzM lrZ2p4lTZIt7uiQetl/AMuZTBgnuPG93TDz4dMKzxA== X-Google-Smtp-Source: AA0mqf6q73ZTVx3zBynrC3mn6j/laWnf08B+SH0wU0NXTLKIdZBH0dXhTwxc0bf0O7UxA8dd02ampkkuFzk1DnCQUTM= X-Received: by 2002:a5d:8f84:0:b0:6d9:56fc:ef25 with SMTP id l4-20020a5d8f84000000b006d956fcef25mr15350157iol.56.1669666325140; Mon, 28 Nov 2022 12:12:05 -0800 (PST) MIME-Version: 1.0 References: <20221128180252.1684965-1-jannh@google.com> <20221128180252.1684965-2-jannh@google.com> In-Reply-To: From: Jann Horn Date: Mon, 28 Nov 2022 21:11:29 +0100 Message-ID: Subject: Re: [PATCH v4 2/3] mm/khugepaged: Fix GUP-fast interaction by sending IPI To: Yang Shi Cc: security@kernel.org, Andrew Morton , David Hildenbrand , Peter Xu , John Hubbard , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=WBerXZPw; spf=pass (imf23.hostedemail.com: domain of jannh@google.com designates 209.85.166.53 as permitted sender) smtp.mailfrom=jannh@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669666326; a=rsa-sha256; cv=none; b=CFttzeO6rzAZJttFNimikATHgcAczprwnkm8Tb91ce4Sm6qxqIQYaiOCRsqoQ3z0Q3+nNk XckJ5G91bzfkT8S/EFyoUkl6QxMX4feYbxJD5VTJiW5xirpUO17oZckthbJOxthtdJqfxf +iPsqlN5AAdzdKJhfubDN3Uvhp99+hI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669666326; 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=/ef+VxAVqyHNr3SIX9M4C8tTATvFzdBIjqbBoKeAT+Q=; b=7fdPa/Hswkc+Wq9puJJr5/xeIikvY5DqsPaB1X4tmtR9/+51RELx121Hu8LlgKGld3wcGD +bKfbN+tjaaMRV9/2IX+vwvzB9z8tsUMQKeLQaRC9DN1It9Qrze7+JojanXyaq98Wfoy9Z eDGixjdVHQxJR65gEW08utsE+CN6C+4= Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=WBerXZPw; spf=pass (imf23.hostedemail.com: domain of jannh@google.com designates 209.85.166.53 as permitted sender) smtp.mailfrom=jannh@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0E4A714000E X-Stat-Signature: wf4saxs8ocnbgyfnrjwtq7uo7mmdwfm5 X-Rspam-User: X-HE-Tag: 1669666325-322053 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 Mon, Nov 28, 2022 at 9:10 PM Yang Shi wrote: > On Mon, Nov 28, 2022 at 11:57 AM Jann Horn wrote: > > > > On Mon, Nov 28, 2022 at 8:54 PM Yang Shi wrote: > > > > > > On Mon, Nov 28, 2022 at 10:03 AM Jann Horn wrote: > > > > > > > > Since commit 70cbc3cc78a99 ("mm: gup: fix the fast GUP race against THP > > > > collapse"), the lockless_pages_from_mm() fastpath rechecks the pmd_t to > > > > ensure that the page table was not removed by khugepaged in between. > > > > > > > > However, lockless_pages_from_mm() still requires that the page table is not > > > > concurrently freed or reused to store non-PTE data. Otherwise, problems > > > > can occur because: > > > > > > > > - deposited page tables can be freed when a THP page somewhere in the > > > > mm is removed > > > > - some architectures store non-PTE information inside deposited page > > > > tables (see radix__pgtable_trans_huge_deposit()) > > > > > > > > Additionally, lockless_pages_from_mm() is also somewhat brittle with > > > > regards to page tables being repeatedly moved back and forth, but > > > > that shouldn't be an issue in practice. > > > > > > > > Fix it by sending IPIs (if the architecture uses > > > > semi-RCU-style page table freeing) before freeing/reusing page tables. > > > > > > > > As noted in mm/gup.c, on configs that define CONFIG_HAVE_FAST_GUP, > > > > there are two possible cases: > > > > > > > > 1. CONFIG_MMU_GATHER_RCU_TABLE_FREE is set, causing > > > > tlb_remove_table_sync_one() to send an IPI to synchronize with > > > > lockless_pages_from_mm(). > > > > 2. CONFIG_MMU_GATHER_RCU_TABLE_FREE is unset, indicating that all > > > > TLB flushes are already guaranteed to send IPIs. > > > > tlb_remove_table_sync_one() will do nothing, but we've already > > > > run pmdp_collapse_flush(), which did a TLB flush, which must have > > > > involved IPIs. > > > > > > I'm trying to catch up with the discussion after the holiday break. I > > > understand you switched from always allocating a new page table page > > > (we decided before) to sending IPIs to serialize against fast-GUP, > > > this is fine to me. > > > > > > So the code now looks like: > > > pmdp_collapse_flush() > > > sending IPI > > > > > > But the missing part is how we reached "TLB flushes are already > > > guaranteed to send IPIs" when CONFIG_MMU_GATHER_RCU_TABLE_FREE is > > > unset? ARM64 doesn't do it IIRC. Or did I miss something? > > > > From arch/arm64/Kconfig: > > > > select MMU_GATHER_RCU_TABLE_FREE > > > > CONFIG_MMU_GATHER_RCU_TABLE_FREE is not a config option that the user > > can freely toggle; it is an option selected by the architecture. > > Aha, I see :-) BTW, shall we revert "mm: gup: fix the fast GUP race > against THP collapse"? It seems not necessary anymore if this approach > is used IIUC. Yeah, I agree. > Reviewed-by: Yang Shi Thanks!