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 5619FC43334 for ; Wed, 20 Jul 2022 19:33:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B93856B0071; Wed, 20 Jul 2022 15:33:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B438B6B0073; Wed, 20 Jul 2022 15:33:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0ADB6B0074; Wed, 20 Jul 2022 15:33:40 -0400 (EDT) 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 8F22B6B0071 for ; Wed, 20 Jul 2022 15:33:40 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6891B1A056E for ; Wed, 20 Jul 2022 19:33:40 +0000 (UTC) X-FDA: 79708477800.22.03EB6DC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 96DFCA001A for ; Wed, 20 Jul 2022 19:33:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658345619; h=from:from: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; bh=Mn98tBM+3OLRK7fELHKIBmz9kutRk009kDVFdDSnBwY=; b=Vas/bP/5TsPL6oAw/oOAvNTFRsm5bou99WPnXUH52FHZRntNX4t0OxAkWCWW9gchDF9atl MdY1FK0BCL6bvGpHGBGbgPsyIpdUmtgRnqkfyRoBZqVrYLUnlYyK8GDpcbhn5hzebARNjp julkUsNnIT1w7miUZewt+t1CeJnyEeM= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-5-gb8NMKNiMdK8jrvIkxAn0Q-1; Wed, 20 Jul 2022 15:33:38 -0400 X-MC-Unique: gb8NMKNiMdK8jrvIkxAn0Q-1 Received: by mail-wr1-f72.google.com with SMTP id c11-20020adfa30b000000b0021e4e471279so402522wrb.12 for ; Wed, 20 Jul 2022 12:33:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=Mn98tBM+3OLRK7fELHKIBmz9kutRk009kDVFdDSnBwY=; b=Fe2DsDiC15vINdBoDO7We3+MNYFUuFg817vI57tfRa+4iMGLPuLhENEU8GsWIW7nyk E07uV7JqV8XpdsniP7X2bgz5cNaBZS2pdhgzDIh3hKSupFZGS3bBGBITNdZBFElYMJ0J 7zgASNcl1PzGt3Daj52IFdo37V9bk/ofkfkMWKYdBjNfYcZppdIVBMJSWaPEGuzHFFhz kkQEX8/E0+Zyv2a2i/yztMj+Y/LnHgZ33Pn6sL8PwmNmWdioiQZfT8KFXZULPTp1mKJ9 mrbAuItRRxSfS0HIJCNlXAneCXDnY8EsbVn+IoEoicW0NejqP/Me2Zzyx0NfTcKDw6xX ULIg== X-Gm-Message-State: AJIora8F11w9puH7YD47pwETO2z5Sq3paeSUciaPHerx3Qb7mEtUCrCN lD1fk44E1gpIwawkSATrEQzfkcMfIIEsIpdvEAKm3H7KdozdNb9yLiL3sgc/diaGN44u+yLYy4r Sp7NjZU5NzRY= X-Received: by 2002:a05:6000:1e04:b0:21d:7ec3:fe5a with SMTP id bj4-20020a0560001e0400b0021d7ec3fe5amr32280366wrb.116.1658345616803; Wed, 20 Jul 2022 12:33:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tBqSfg7bH069Byd/vRG4bt0BOfT4AODrDs7R/jaof9TDEfBaGFUwZYl1U3qluoU6u2j0rASQ== X-Received: by 2002:a05:6000:1e04:b0:21d:7ec3:fe5a with SMTP id bj4-20020a0560001e0400b0021d7ec3fe5amr32280339wrb.116.1658345616505; Wed, 20 Jul 2022 12:33:36 -0700 (PDT) Received: from ?IPV6:2003:cb:c706:e00:8d96:5dba:6bc4:6e89? (p200300cbc7060e008d965dba6bc46e89.dip0.t-ipconnect.de. [2003:cb:c706:e00:8d96:5dba:6bc4:6e89]) by smtp.gmail.com with ESMTPSA id bp7-20020a5d5a87000000b0021d80f53324sm16981122wrb.7.2022.07.20.12.33.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Jul 2022 12:33:36 -0700 (PDT) Message-ID: <69022bad-d6f1-d830-224d-eb8e5c90d5c7@redhat.com> Date: Wed, 20 Jul 2022 21:33:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 To: Peter Xu Cc: Nadav Amit , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Mike Rapoport , Axel Rasmussen , Nadav Amit , Andrea Arcangeli , Andrew Cooper , Andy Lutomirski , Dave Hansen , Peter Zijlstra , Thomas Gleixner , Will Deacon , Yu Zhao , Nick Piggin References: <20220718120212.3180-1-namit@vmware.com> <20220718120212.3180-2-namit@vmware.com> <017facf0-7ef8-3faf-138d-3013a20b37db@redhat.com> <2b4393ce-95c9-dd3e-8495-058a139e771e@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [RFC PATCH 01/14] userfaultfd: set dirty and young on writeprotect In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Vas/bP/5"; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658345620; a=rsa-sha256; cv=none; b=CzrKmBK0ZxNisRWPUzGwj/UCzuURREKcGjk/dewGyz3UXuIP71Sks/ayPibkHXac0QBp2n KCDCp66yQgEuYXxRhC+yjoeO3f6Idlrzzh2AS6gUMGFdSr/Ya4EQWfBCgjKnORGMuFOnhZ UbM7f/BP5k9zP+ra/NrYaYVoWem8uoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658345620; 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=Mn98tBM+3OLRK7fELHKIBmz9kutRk009kDVFdDSnBwY=; b=5B+xIAGFquni7ReKkguMauu9xlyolAQ2lKm3Z6ysgoJqvMOtHQC3wX+vpM5WP99uhhy+VL YTZzt8aZdDZeP4e+E2WVZAxZq6GMFHwgs4O7uO09kAICyjNOODqS2OPO51gOotdvpSwX4e B8NgjFKJgYobgms7IYrIfvIoDpR2URE= Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Vas/bP/5"; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam01 X-Stat-Signature: 8ebtgjoyc4xsrpmzi9oio4a68rra76q6 X-Rspamd-Queue-Id: 96DFCA001A X-HE-Tag: 1658345619-51744 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000010, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 20.07.22 21:15, Peter Xu wrote: > On Wed, Jul 20, 2022 at 05:10:37PM +0200, David Hildenbrand wrote: >> For pagecache pages it may as well be *plain wrong* to bypass the write >> fault handler and simply mark pages dirty+map them writable. > > Could you elaborate? Write-fault handling for some filesystems (that even require this "slow path") is a bit special. For example, do_shared_fault() might have to call page_mkwrite(). AFAIK file systems use that for lazy allocation of disk blocks. If you simply go ahead and map a !dirty pagecache page writable and mark it dirty, it will not trigger page_mkwrite() and you might end up corrupting data. That's why we the old change_pte_range() code never touched anything if the pte wasn't already dirty. Because as long as it's not writable, the FS might have to be informed about the write-unprotect. And we end up in the case here for VM_SHARED with vma_wants_writenotify(). Where we, for example, check /* The backer wishes to know when pages are first written to? * if (vm_ops && (vm_ops->page_mkwrite || vm_ops->pfn_mkwrite))$ return 1; Long story short, we should be really careful with write-fault handler bypasses, especially when deciding to set dirty bits. For pagecache pages, we have to be especially careful. For exclusive anon pages it's mostly ok, because wp_page_reuse() doesn't really contain that much magic. The only thing to consider for ordinary mprotect() is that there is -- IMHO -- absolutely no guarantee that someone will write to a specific write-unprotected page soon. For uffd-wp-unprotect it might be easier to guess, especially, if we un-protect only a single page. -- Thanks, David / dhildenb