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 F130CC433F5 for ; Fri, 18 Feb 2022 04:00:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 047046B0074; Thu, 17 Feb 2022 23:00:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F119C6B0075; Thu, 17 Feb 2022 23:00:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8B186B0078; Thu, 17 Feb 2022 23:00:15 -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 C572B6B0074 for ; Thu, 17 Feb 2022 23:00:15 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7DF51181AC9C6 for ; Fri, 18 Feb 2022 04:00:15 +0000 (UTC) X-FDA: 79154547990.13.2053DB3 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf14.hostedemail.com (Postfix) with ESMTP id 1459D100004 for ; Fri, 18 Feb 2022 04:00:14 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id y11so1334569pfi.11 for ; Thu, 17 Feb 2022 20:00:14 -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=ihLiOYcLhTMPKpJLMj5Tcvek92eXFj8sFzSo0F05Ymk=; b=pIPoApkrX30YDDBNdGp6eV2JElpXwud6oNJVeUlD9IznP9aVydbOdq3Sy0g44hueuM qUoj39ctB90j7EhecKSVUicUETtlDD73hcbAunuP6Q3FiBYE3njACWQFnK7c5nNhFiEF lUUoYxGK8bsGf8CBQpJIQbYD9M3XY2vA6qmBvlyWX0exlrKOHrPhL1RawXIB//MahZY4 OHF7j5WUkkHgvfzRACkBcTLCVGlHCPNNJCRXET4lUK2g8rDTRdq1WphzK/DyfakWMz1b RuiMNnkLjC2yCptt1mhTH6iiCcbcQ49BxIPuS/DzzxT0EJNXRExJQCC6dqVsE2YH/7KK 2Vww== 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=ihLiOYcLhTMPKpJLMj5Tcvek92eXFj8sFzSo0F05Ymk=; b=Qz0zWmvieoz/QtcGFOoS56j4xVqjg1LUi2vpXpeKn5FxloVNYqhZ7yPPEWW0wluZia RD/aHDDfy4lBffF1EiNznOayeXvhQqZX5bzwadbG2WMAzYN+IcT2aNDd3UOpaGtqCKfA 0PxMBWWlKEOZRYcaw2jUur1dhgSvrhgF4R1yNk5C6M9C+SM0bZvJOEsWlqQKulwjLmiL Jkq5r+NJocm5HIQsC79gUKu1XY22aZFF8zTaoc8x1OEhZIlZyGZdkbvxliwT4f8dK91Q Dv975r76TagFlF0E0sBUF7obfN5wOD0+B5atN/Odr6SWSzhEadtzku7EP3yTsXaF6A92 nH6A== X-Gm-Message-State: AOAM5331PdC6jW4MZHnNqhcRcBVJZQq8bkkLxQihY+NKSNXNBWb6LYg0 NFM7RRZmKP71MdKibc0rW9M= X-Google-Smtp-Source: ABdhPJxYyypJbNOuwt4vgDz1vftdsFnrY5uV4Gx1bPJS93SxoDwfJYv2PSpBNGU+FrRdcMOeeJgVzw== X-Received: by 2002:a05:6a00:189d:b0:4e1:dc82:eded with SMTP id x29-20020a056a00189d00b004e1dc82ededmr4041440pfh.27.1645156813835; Thu, 17 Feb 2022 20:00:13 -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 z27sm9228192pgk.78.2022.02.17.20.00.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Feb 2022 20:00:13 -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: Date: Thu, 17 Feb 2022 20:00:12 -0800 Cc: Andrew Morton , Linux-MM , Mike Rapoport , Andrea Arcangeli , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <68B04C0D-F8CE-4C95-9032-CF703436DC99@gmail.com> References: <20220217211602.2769-1-namit@vmware.com> To: Peter Xu X-Mailer: Apple Mail (2.3693.40.0.1.81) X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=pIPoApkr; spf=pass (imf14.hostedemail.com: domain of nadav.amit@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=nadav.amit@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1459D100004 X-Stat-Signature: nzsibzimqcewcbq8u9qo8e1izfzgrctu X-HE-Tag: 1645156814-890361 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000063, 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 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); >> } 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. 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. So basically the condition should have been based on !dirty_accountable, i.e. the inverted value of dirty_accountable. 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. Am I missing something?