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 1C5E9ECAAA1 for ; Sun, 30 Oct 2022 18:19:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BD246B0071; Sun, 30 Oct 2022 14:19:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26D9F6B0073; Sun, 30 Oct 2022 14:19:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 135BB6B0074; Sun, 30 Oct 2022 14:19:58 -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 F42386B0071 for ; Sun, 30 Oct 2022 14:19:57 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BB897C0563 for ; Sun, 30 Oct 2022 18:19:57 +0000 (UTC) X-FDA: 80078429634.26.EF04845 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by imf18.hostedemail.com (Postfix) with ESMTP id 671221C0014 for ; Sun, 30 Oct 2022 18:19:56 +0000 (UTC) Received: by mail-qv1-f50.google.com with SMTP id j6so7187256qvn.12 for ; Sun, 30 Oct 2022 11:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Nhjvm4CLfjf8sZh4i2SvI4bcfGTGarDkiioYf9j/q80=; b=fN3naw36QXCqqTVPHS+dkD5oxumRUFB/LNJ+o5y4bb9W32TVqB285knxQkX7u6XkmS Yn5BMZWYJT09H0YWWX9PvBHq4pL9ArHEIWnYEICha7ZVsiJKLEIJ2wqnI0zWXzpbxA1D 5WSsG7eVfB/2HH+LnLuoxguol6B3WgeqRXu8c= 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=Nhjvm4CLfjf8sZh4i2SvI4bcfGTGarDkiioYf9j/q80=; b=IPbTCk3f7hcvYc7j6dFgBZ7w8VEQmfXHy0AcaTKdjIvul7SJnZ3549RTBGpY9fJoAF qUcJhUF9NRilbaRgRMuGasqgk49WRtuwxRqHtFxB0sMWF3GsbvnPSAdrDtw+bI0Xgbb4 HcuFxbxzAuoUiayhGMwsOkNj56HfJJ34TMdRjkTmhQlBdrGPgwJABquRXLqF3rZT5vcT BZCcJ0ChIIigw8bP3oSBangFRXUxJkZSejGNCmZsY6vsHoQx8/npsSIsHUq+wsEzK5h2 FSosWmdpZ7OcMUulDAy+YoXz7H0iOL+a6kG8IriWiwPbMGBwleK+bUKF2xadCbJ0lKX6 kR2A== X-Gm-Message-State: ACrzQf003lrUJYSAiejThpsT3/WPGwA6E7tHpkClvl6Doh++fH8yIMES xymoqaoahub8exYiWg4VNcJ6c/1kG9R3iw== X-Google-Smtp-Source: AMsMyM5TgKpNxcjUvo2uId8vbEJ33CwTgXupOtqukbLWhgxY//iOOiA+FbL7YkUUIvdxvhe2BBJ5EA== X-Received: by 2002:ad4:574a:0:b0:4bb:691a:80f9 with SMTP id q10-20020ad4574a000000b004bb691a80f9mr7733513qvx.14.1667153995240; Sun, 30 Oct 2022 11:19:55 -0700 (PDT) Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com. [209.85.128.180]) by smtp.gmail.com with ESMTPSA id z16-20020ac87cb0000000b0039a372fbaa5sm2493067qtv.69.2022.10.30.11.19.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 30 Oct 2022 11:19:53 -0700 (PDT) Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-36a4b86a0abso90652887b3.7 for ; Sun, 30 Oct 2022 11:19:52 -0700 (PDT) X-Received: by 2002:a0d:c246:0:b0:370:2d8c:81d6 with SMTP id e67-20020a0dc246000000b003702d8c81d6mr9315634ywd.112.1667153992578; Sun, 30 Oct 2022 11:19:52 -0700 (PDT) MIME-Version: 1.0 References: <20221022111403.531902164@infradead.org> <20221022114424.515572025@infradead.org> <2c800ed1-d17a-def4-39e1-09281ee78d05@nvidia.com> <6C548A9A-3AF3-4EC1-B1E5-47A7FFBEB761@gmail.com> <47678198-C502-47E1-B7C8-8A12352CDA95@gmail.com> <140B437E-B994-45B7-8DAC-E9B66885BEEF@gmail.com> In-Reply-To: <140B437E-B994-45B7-8DAC-E9B66885BEEF@gmail.com> From: Linus Torvalds Date: Sun, 30 Oct 2022 11:19:36 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 01/13] mm: Update ptep_get_lockless()s comment To: Nadav Amit Cc: Peter Zijlstra , Jann Horn , John Hubbard , X86 ML , Matthew Wilcox , Andrew Morton , kernel list , Linux-MM , Andrea Arcangeli , "Kirill A . Shutemov" , jroedel@suse.de, ubizjak@gmail.com, Alistair Popple Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667153996; 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=Nhjvm4CLfjf8sZh4i2SvI4bcfGTGarDkiioYf9j/q80=; b=RowdRtcNU1UXR2yIZqn/5dNwOxXVIhQSqSKnnYd0jElfaMpJQ3ZvJUma3VQdmdhFgc2Sg/ gxxApN0ECUkUIMk9hLWrtU8PfoI4gNPitHZZioxq53DziyS58mTtwJU1Ju/Y/D6lx6Pvtj T3Wy4VK1X1OJnCL6lPvOv3GkRHog3Jc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=fN3naw36; spf=pass (imf18.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.219.50 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667153996; a=rsa-sha256; cv=none; b=XgxifRa0NyV6yuzFE00yfxzTCIZ4+9pDhgF8j/uZYMzL8UC9iiraBHKCpdzPBKRfTUev3+ t8AIpGmhTr105xVhhPAUFqAG/qdJgSnHGwFxicF359Ev/EATmprsyDyOiyy8AfupN+YZfd Qa1TAmHoxuVuEpgrwsWQ/JWQrW1XDdo= Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=fN3naw36; spf=pass (imf18.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.219.50 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-Rspam-User: X-Rspamd-Queue-Id: 671221C0014 X-Rspamd-Server: rspam03 X-Stat-Signature: 3zh6cugtc14hp8qx6n33tcr3sx9teegx X-HE-Tag: 1667153996-545717 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 Sat, Oct 29, 2022 at 7:17 PM Nadav Amit wrote: > > Running the PoC on Linux 6.0.6 with these patches caused the following splat > on the following line: > > WARN_ON_ONCE(!folio_test_locked(folio) && !folio_test_dirty(folio)); Yeah, this is a sign of that "folio_mkclean() serializes with folio_mark_dirty using rmap and the page table lock". And page_remove_rmap() could *almost* be called later, but it does have code that also depends on the page table lock, although it looks like realistically that's just because it "knows" that means that preemption is disabled, so it uses non-atomic statistics update. I say "knows" in quotes, because that's what the comment says, but it turns out that __mod_node_page_state() has to deal with CONFIG_RT anyway and does that preempt_disable_nested(); ... preempt_enable_nested(); thing. And then it wants to see the vma, although that's actually only to see if it's 'mlock'ed, so we could just squirrel that away. So we *could* move page_remove_rmap() later into the TLB flush region, but then we would have lost the page table lock anyway, so then folio_mkclean() can come in regardless. So that doesn't even help. End result: we do want to do the page_set_dirty() and the remove_rmap() under the paeg table lock, because it's what serializes folio_mkclean(). And we'd _like_ to do the TLB flush before the remove_rmap(), but we *really* don't want to do that for every page. So my current gut feel is that we should just say that if you do "MADV_DONTNEED or do a munmap() (which includes the "re-mmap() over the area", while some other thread is still writing to that memory region, you may lose writes. IOW, just accept the behavior that Nadav's test-program tries to show, and say "look, you're doing insane things, we've never given you any other semantics, it's your problem" to any user program that does that. If a user program does MADV_DONTNEED on an area that it is actively using at the same time in another thread, that sounds really really bogus. Same goes doubly for 'munmap()' or over-mapping. Linus