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 3FEAEC433EF for ; Fri, 18 Feb 2022 04:05:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C00DE6B0074; Thu, 17 Feb 2022 23:05:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BAF976B0075; Thu, 17 Feb 2022 23:05:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A51046B0078; Thu, 17 Feb 2022 23:05:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id 979656B0074 for ; Thu, 17 Feb 2022 23:05:52 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5E4E08249980 for ; Fri, 18 Feb 2022 04:05:52 +0000 (UTC) X-FDA: 79154562144.13.EDC9CEC Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf31.hostedemail.com (Postfix) with ESMTP id 07FCB20006 for ; Fri, 18 Feb 2022 04:05:51 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id m11so2639984pls.5 for ; Thu, 17 Feb 2022 20:05:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=HhZ+gUX30hM17AylnTVI1rNaaPl74E0Ggeyqli65+jw=; b=nV/wLVqj16n/UUibEktm9eHsmp7NC73nSrQEkzT9CZG8bVQ2mCx2rwfWP/wNrdwOCe C0QHlpPDMPH92D7zn1UxkTsCvR4jQj+Sr6niQNGt2Nz2LOfGrmhk82mVFtPEZ7kndrHL 31XglZl+RdjwxUtM61yK5y6oM5crpexIoklCoMzBUHviWZUTXZsR9a/N+AiF1G261aaw LykKHEkRzHCbb8frgcnFJldEo+3xEbCyChRg5FX9GX5XG3KyPJ/DALFL6unFc17WnedZ 6j8LfsV0SIj83N8VZLE1kM8wkuDaZwBhUtFp6YF1287n37cPm8yJ9K/WCw701O4/KzB7 bVXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=HhZ+gUX30hM17AylnTVI1rNaaPl74E0Ggeyqli65+jw=; b=hJiJ7kMkEJ46+bot4CZp9pM9RXHza93jWxBYLV85MKTTcO9ogKCzkZ4zoNhwaNXbmF 1/VQJfYFjwGpeEQwkVAdei+d03tGlPTyH1kacqgSK7Tk0hdffGGH4JYWiaUCauSamB6V lF3NYUMdCOL2eAysgvA61horPn604E/Np2XhAIwVcJ0QLnbfVxpaYWtGfqYNmrTDuyjq GY8fUUnWqKybrJK5KilQ+HDHn4ELMQAcBV/Z0ZNMoTVho4kw5HtjVJeqjC6Ne8YVtd1p 74xoZBLoc2pySpQBmauVIHs+amBazX95WdpmeibM95GyPhr9ShhQ1Yim5ClNRJm38/62 nTFg== X-Gm-Message-State: AOAM531fiHIcLlfLQsCIJyIS+655bWKq1dOrtO3Ra+eb8NvuS9NTnuy2 2BMGyCMVA8jqnjkLkBnIziS7AQhK6uY= X-Google-Smtp-Source: ABdhPJyoLwCYZ4uByLJN3/vT1bKkSrVVe/k/ceQZNy0crerUR69DMV7awuHutF6G8WFIoLF+Li4RQA== X-Received: by 2002:a17:90b:314e:b0:1b9:ef8b:d441 with SMTP id ip14-20020a17090b314e00b001b9ef8bd441mr10663313pjb.215.1645157150906; Thu, 17 Feb 2022 20:05:50 -0800 (PST) Received: from smtpclient.apple (c-24-6-216-183.hsd1.ca.comcast.net. [24.6.216.183]) by smtp.gmail.com with ESMTPSA id j15sm1117734pfj.102.2022.02.17.20.05.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Feb 2022 20:05:50 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Subject: Re: [PATCH] userfaultfd: mark uffd_wp regardless of VM_WRITE flag From: Nadav Amit In-Reply-To: <68B04C0D-F8CE-4C95-9032-CF703436DC99@gmail.com> Date: Thu, 17 Feb 2022 20:05:49 -0800 Cc: Andrew Morton , Linux-MM , Mike Rapoport , Andrea Arcangeli , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <3E9C755C-7335-4636-8280-D5CB9735A76A@gmail.com> References: <20220217211602.2769-1-namit@vmware.com> <68B04C0D-F8CE-4C95-9032-CF703436DC99@gmail.com> To: Peter Xu X-Mailer: Apple Mail (2.3693.40.0.1.81) X-Rspamd-Queue-Id: 07FCB20006 X-Stat-Signature: 67j4xb9qx4ftiiewdsahyqwzwz7n7gcn X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="nV/wLVqj"; spf=pass (imf31.hostedemail.com: domain of nadav.amit@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=nadav.amit@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam05 X-HE-Tag: 1645157151-269296 X-Bogosity: Ham, tests=bogofilter, spamicity=0.001202, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: > On Feb 17, 2022, at 8:00 PM, Nadav Amit wrote: >=20 >=20 >> On Feb 17, 2022, at 6:23 PM, Nadav Amit wrote: >>=20 >>> PS: I always think here the VM_SOFTDIRTY check is wrong, IMHO it = should be: >>>=20 >>> if (dirty_accountable && pte_dirty(ptent) && >>> (pte_soft_dirty(ptent) || >>> (vma->vm_flags & VM_SOFTDIRTY))) { >>> ptent =3D pte_mkwrite(ptent); >>> } >=20 > I know it is off-topic (not directly related to my patch), but > I tried to understand the logic - both of the existing code and of > your suggested change - and I failed. >=20 > IIUC dirty_accountable (whose value is taken from > vma_wants_writenotify()) means that the writes *should* be tracked, > and therefore the page should remain read-only. >=20 > So basically the condition should have been based on > !dirty_accountable, i.e. the inverted value of dirty_accountable. >=20 > The problem is that dirty_accountable also reflects VM_SOFTDIRTY > considerations, so looking on the PTE does not tell you whether > the PTE should remain write-protected even if it is dirty. Just as I pressed send, I understood your suggestion. It is still confusing for me how setting write-permissions for dirty_accountable PTEs is safe (as long as they are dirty), and yet in the general case it is not safe. I need to further think of it.=