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 CFC67C4332F for ; Wed, 14 Dec 2022 10:59:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4EBC28E0005; Wed, 14 Dec 2022 05:59:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 49A5A8E0002; Wed, 14 Dec 2022 05:59:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 361E88E0005; Wed, 14 Dec 2022 05:59:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 25D928E0002 for ; Wed, 14 Dec 2022 05:59:43 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E8590120D29 for ; Wed, 14 Dec 2022 10:59:42 +0000 (UTC) X-FDA: 80240616204.05.7D21F63 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id A983240018 for ; Wed, 14 Dec 2022 10:59:40 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RmLIY0nD; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1671015581; a=rsa-sha256; cv=none; b=prcfiQ62C+tCC+9ftRMgXKFtxZ4BNgSufqIlfdzBqlr8RZLowDcgVPY48ZFRphxaUtM3/a UMqlrVRXHaKk4D/J5mWTncmj4UuF3ABn7OVfroQC56px7UFFEn9vISORZxOK/I+pMzCaoB BxBucrgRgnYcreIIJFd76/qCGyA0JbE= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RmLIY0nD; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671015581; 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=s+HlVbpIO8Te0sbGMri/YTfV3Faqo0WekfaQjrNCjXM=; b=Nhmyjrrdb/5z+3S9z3UxUxURPxGdSaxlCSnbgKFO+FL+8/B5Ji5BO+CfrtWqbmONV6S0zX myg48K6hJoQ8wtkpt1Tt7t08xBOmukaeo83xrdonMk8PQCyzMfpz501HeuZn44B/0lmH+2 fky6xu0pl+V3GYZoNQs0iWXOAVTC4Xo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671015579; 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=s+HlVbpIO8Te0sbGMri/YTfV3Faqo0WekfaQjrNCjXM=; b=RmLIY0nDUQZmsIX+JrmcDpxnvCSFXV1Jq82yMlS231ImZUbbYkk/tqKnvB3/Iio4w7A5+7 Klo7bJ8PauE4h4Ah0TyUd/mJ9cVvYFRDJEfTY2IcJt/XoCv0NqX+ucc2IJdoVoIuZ7zrvg UmcqLkM/sF7j02MfUtFeHa3Y20K1z04= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-646-xo41CynnMYqjszFgi9W1oA-1; Wed, 14 Dec 2022 05:59:38 -0500 X-MC-Unique: xo41CynnMYqjszFgi9W1oA-1 Received: by mail-wr1-f69.google.com with SMTP id p2-20020adfaa02000000b00241d7fb17d7so3452821wrd.5 for ; Wed, 14 Dec 2022 02:59:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=s+HlVbpIO8Te0sbGMri/YTfV3Faqo0WekfaQjrNCjXM=; b=cQnjuDfwv4hYcwNOaYUplK6A/I2j7FeVWb62nMdBIyqB42ngKZbGgAWIKWiByIygTa 8SOJ/Pq9zM5V9ZCv4xLOdjkzsU2n6YhRVh7BTn9rhumrzljadmZZB8NgsxWyWLNHld0r 3Z1Ha0/IeAZ+sGULZEncUAJe2sEvkIkXzivCxnrNjEt+2YFiSoZizw4AHruauaA66mPm fpbEFQAJyW48r8nC52llrlQxqh27/U8hFmxUE6qGDCtQCjKzrQ055XxXoLzdcBr6x3gm 2vko8oX6uGmDhgh/94tEuhHxcbhDRR7FY7hE1exWak+GZDmZew+J3CwD1reP4EpvNe+f RihA== X-Gm-Message-State: ANoB5pkAxe0qds40U4lZkXVoYl1JklGPIE6GpckPCj5ROn3n+SIFxBm1 vpWhHaSNLImU4h8N4d863aBUUSW48PEM8MWu3glOqfMfr5LEvqKVNEZus0rrSz5INqXmiIYY78W OTg/hq2UwVRo= X-Received: by 2002:adf:e7c3:0:b0:242:eb5:254f with SMTP id e3-20020adfe7c3000000b002420eb5254fmr16627818wrn.48.1671015577565; Wed, 14 Dec 2022 02:59:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf4wb5ut4amZ+rSu0sdNHb6RbhZiqPSJyrln8tMZoaZEtKy7rmsy7KhY5jMcuxRnkRr7ab+fcg== X-Received: by 2002:adf:e7c3:0:b0:242:eb5:254f with SMTP id e3-20020adfe7c3000000b002420eb5254fmr16627801wrn.48.1671015577263; Wed, 14 Dec 2022 02:59:37 -0800 (PST) Received: from ?IPV6:2003:cb:c703:7700:dd7c:92f8:481f:b96b? (p200300cbc7037700dd7c92f8481fb96b.dip0.t-ipconnect.de. [2003:cb:c703:7700:dd7c:92f8:481f:b96b]) by smtp.gmail.com with ESMTPSA id g17-20020a7bc4d1000000b003cf6e1df4a8sm2016994wmk.15.2022.12.14.02.59.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Dec 2022 02:59:36 -0800 (PST) Message-ID: Date: Wed, 14 Dec 2022 11:59:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] mm/uffd: Always wr-protect pte in pte|pmd_mkuffd_wp() To: Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , Nadav Amit , Hugh Dickins , Ives van Hoorne , Mike Kravetz , Andrew Morton References: <20221208194628.766316-1-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20221208194628.766316-1-peterx@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: A983240018 X-Rspamd-Server: rspam01 X-Stat-Signature: 86xy1gyeh8hwanyabfxdaeopjgy5fzbh X-HE-Tag: 1671015580-744388 X-HE-Meta: U2FsdGVkX18CMjqpRLai5BoKX4lUjWBC6CnLdas27y7SUSWfowgjPMmCuBjkGLhNC0PQ9RD6ur1eVTQrqH5Xd+cEv/BqC37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YN7bLiVw+CA5yA280wjqtPc1AVqS3o/L/rhHgTopID5KstNkaCWuneoX4biwxm0gd7o6rhvj 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 08.12.22 20:46, Peter Xu wrote: > This patch is a cleanup to always wr-protect pte/pmd in mkuffd_wp paths. > > The reasons I still think this patch is worthwhile, are: > > (1) It is a cleanup already; diffstat tells. > > (2) It just feels natural after I thought about this, if the pte is uffd > protected, let's remove the write bit no matter what it was. > > (2) Since x86 is the only arch that supports uffd-wp, it also redefines > pte|pmd_mkuffd_wp() in that it should always contain removals of > write bits. It means any future arch that want to implement uffd-wp > should naturally follow this rule too. It's good to make it a > default, even if with vm_page_prot changes on VM_UFFD_WP. > > (3) It covers more than vm_page_prot. So no chance of any potential > future "accident" (like pte_mkdirty() sparc64 or loongarch, even > though it just got its pte_mkdirty fixed <1 month ago). It'll be > fairly clear when reading the code too that we don't worry anything > before a pte_mkuffd_wp() on uncertainty of the write bit. Don't necessarily agree with (3). If you'd have a broken pte_mkdirty() and do the pte_mkdirty() after pte_mkuffd_wp() it would still be broken. Because sparc64 and loongarch are simply broken. > > We may call pte_wrprotect() one more time in some paths (e.g. thp split), > but that should be fully local bitop instruction so the overhead should be > negligible. > > Although this patch should logically also fix all the known issues on > uffd-wp too recently on either page migration or numa balancing, but this > is not the plan for that fix. So no fixes, and stable doesn't need this. I don't see how this would fix do_numa_page(), where we only do a pte_modify(). > > Signed-off-by: Peter Xu > --- > > Note: this patch should be able to apply cleanly with/without the other > mm/migrate patch, or David's vm_page_prot changes. > --- > arch/x86/include/asm/pgtable.h | 24 ++++++++++++------------ > include/asm-generic/hugetlb.h | 16 ++++++++-------- > mm/huge_memory.c | 8 +++----- > mm/hugetlb.c | 4 ++-- > mm/memory.c | 8 +++----- > mm/mprotect.c | 6 ++---- > mm/userfaultfd.c | 18 ++---------------- > 7 files changed, 32 insertions(+), 52 deletions(-) It's certainly a cleanup, even though we might unnecessarily wrprotect (I don't think we care). -- Thanks, David / dhildenb