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 85BF0C4167B for ; Wed, 14 Dec 2022 14:26:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C40798E0003; Wed, 14 Dec 2022 09:26:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BF0628E0002; Wed, 14 Dec 2022 09:26:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB7E78E0003; Wed, 14 Dec 2022 09:26:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9C3C08E0002 for ; Wed, 14 Dec 2022 09:26:51 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 75B96AB585 for ; Wed, 14 Dec 2022 14:26:51 +0000 (UTC) X-FDA: 80241138222.14.48B47DD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id ABF1420016 for ; Wed, 14 Dec 2022 14:26:47 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FBjV6Dl2; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671028009; a=rsa-sha256; cv=none; b=ds28oB/nUVTAZJp6doaOidw0/acei4Nib5kILYb46NtJhmIWAal8IOh4EBTX0Hpn/BxXt2 2+M2A32+brMOkRXmgE5ZqwzRLYPswTf/w3S2Tz35FrAn7YAWrY5TNgITztQLPd/s97z9gU bw14QTv5eePwjC3p1F8I3d0qkMgeMCw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FBjV6Dl2; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1671028009; 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=eooKpcnT0zqUtx7o1Z+gXVL8gr4qa58YSOigvkF0Wx4=; b=wPrw7TcQvyklXfU5AwWVVHQHaIS6UqgBdbDmbsbzI6t+gVtXxG9Sq415bE+7Bb1EkT7l9Q 1oqhnGqcNfgDftpkPRUGh1ymEkPL41zSm66cAEipXIotW6xN8kyHALUryg1+De96Z/4LEc LsZb3rMtgjhyW2JFZBydpjNyPv5/qso= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671028006; 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: in-reply-to:in-reply-to:references:references; bh=eooKpcnT0zqUtx7o1Z+gXVL8gr4qa58YSOigvkF0Wx4=; b=FBjV6Dl2UjG5nvVhYDNj/9quhGmvlcywAvOUC4ZEhnmouYI26X1dvYC4a91uw0dQWeL3An FIWAOaq3cNirdqs2vrmzhg24o62y8hwKdqSymKMaws/zO+e4NgHpUhA9CfsPwkby5/g2dC bRBJppl2a25XtaBIiJAkXi8Ju2jrhqg= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-433-Ga_nC4AhNTeveaIB-V9BlA-1; Wed, 14 Dec 2022 09:26:45 -0500 X-MC-Unique: Ga_nC4AhNTeveaIB-V9BlA-1 Received: by mail-qk1-f199.google.com with SMTP id f13-20020a05620a408d00b006fc740f837eso3196354qko.20 for ; Wed, 14 Dec 2022 06:26:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=eooKpcnT0zqUtx7o1Z+gXVL8gr4qa58YSOigvkF0Wx4=; b=YTRKPry4fU+tU2Nzq77pN3uIsB0d7aGu9t1jEXf4x6gHSk+Bs2YWlONZnT9kLRs1hY dWAA1n4mT/CEltT7awlMWqeU3MF6QfO71PtrncdtOKW1ryvX+1wZdHiu4e2UY1fp6BYm ZSwnFRVTwUrBVK5xmamaeFv/Lfue7dBilJ1c8je12836pFpR1Vlm8Tp5RdSlobupbp/g Pq1965uup+idg2YcVaYh7/h1AGJzalMKSub/XBMqZoU9+1DNiFM4yMoFJ7R+Q0pP0e/o FOLBBAy69A+ey/nWFeluWDE/sRpahanYX2nJ5O34wrl6XUAr+XBC+ZXElWFTQqcy2Rq8 y1KA== X-Gm-Message-State: ANoB5plKPq3O28d5/Ashc1NS5/czOSiPEEvJS2YAmVVdwtcRBCKggDaT itLFzIGn+6lCZomN+h3mKy+QOEanXTP9FZcWaQ99nBkpzb0vkQpt9inPrZHvUnLHb4OpgSHFvhP eRrQP5SBczP0= X-Received: by 2002:ac8:70c:0:b0:3a8:55c:a893 with SMTP id g12-20020ac8070c000000b003a8055ca893mr30246116qth.0.1671028005170; Wed, 14 Dec 2022 06:26:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf7HtzN9hkRDnpf0x0IYTdENk7AWzeJ7UjVmRKdjEY7WEjGc354jNbZbpmDeDy4zW9BmPJFSbg== X-Received: by 2002:ac8:70c:0:b0:3a8:55c:a893 with SMTP id g12-20020ac8070c000000b003a8055ca893mr30246094qth.0.1671028004869; Wed, 14 Dec 2022 06:26:44 -0800 (PST) Received: from x1n (bras-base-aurron9127w-grc-45-70-31-26-132.dsl.bell.ca. [70.31.26.132]) by smtp.gmail.com with ESMTPSA id r10-20020ac85e8a000000b00342f8d4d0basm1738313qtx.43.2022.12.14.06.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 06:26:44 -0800 (PST) Date: Wed, 14 Dec 2022 09:26:42 -0500 From: Peter Xu To: David Hildenbrand Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrea Arcangeli , Nadav Amit , Hugh Dickins , Ives van Hoorne , Mike Kravetz , Andrew Morton Subject: Re: [PATCH] mm/uffd: Always wr-protect pte in pte|pmd_mkuffd_wp() Message-ID: References: <20221208194628.766316-1-peterx@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspam-User: X-Rspamd-Queue-Id: ABF1420016 X-Rspamd-Server: rspam01 X-Stat-Signature: g6hnqwcsjg5f17dg1x8ucups55eoy3n7 X-HE-Tag: 1671028007-814730 X-HE-Meta: U2FsdGVkX18qR+z6vh5aCffR9mE0wzGengzQ2xyBF+2tSxkjEL+hc6E6qDkwmaS18WcKqII4BPcrrDFnF8WPCBt8O5b0Iq4BY7qx4Vt3+LC2ccyggI8EgOxbKxmQFbplKiBdnMNZ2GCqHkezOD6mMtz/Yh5jFSrflUY5dgfRTgTNyQTCQIQPnFylKXePf/IzB3zAiPOa4uDp5IW12GboxwwHAWUix18sJWYBz2BThpgdbxoBdSLI25XDtcaGChYs3FNtKXADI6PWCB0NF56Db+cLLRhg/ArDh3AlttSSxkeodksJf7/cYZQ0Y7PfXWP5qGVz442rOIYXpBK+9SCUSN491jR2YoVpN+YQFOm4oMGGk8aP9tnBEExEBR5huMNpzzQeyew37kCH0YuyFAA+5bB9wHuIQx0+OFPDgAnQ4DVdkcW6J2Ym1OEMaI03TN6nlfUxsyF5lWdmkccOiif0t+xt0Qn8idYy00nmpy5t3LBc/aZ8nwCAA5ydhKWae7bxMXMmdY8uSeT5wNC6hmSpfSkklO/YUS00vLFVqA2XPjnoMKe5SV3gx1vRyRwmUvAS9Ll+XjuewA/GGyNYG7nAEz7vYETOcCTp7V2CxhX4L6gmivXSxH2WKdTBQ58rtsQHp7wef+1yGnj8BEJaQVijxfmIbaEZgC2gU/DsHI+aHAOgKffFEF3V7+623YjzeF5RKQp9YEh3pdHdwoRI+77fR22hv41BuiIo2To/U1A0LJdDrbnTGbJ5A0MxcHaV9FzYY3yHpJLfjVf/tyQeu75exzdoArT45kf6pB4qP9pC2u6c9A2QHft0QGBWNVLeXZ8xpTFWMhEvdtKq8RBoeHEvXucGIIDCSS9C2Xxj8WEE/+VGYSrJUSEarHD479msKVGemgn2SuW78LZfbceyzPr00fVmM/dIMDIYi4JSJPaeA6sKzd+to5Tkc9J/8R4432w5actRem3ER/A8EAK1eoh kVviVJdD yqCiJUG60BaO3ePZdFdeZjpxfiKnkQ6CT9a8csK2xfoe9LCyRWpInUQVJYZGFw7fckFT8y30XiOuZQthM0NOOf/EBbfAv88xueaLA41a3vlT2R/sRYG9pQjKEAp+tvzeEpAl/7oZUPt5DZyTy9x+tJaNlCLeYhHLW9xeXnXKCr3Je00NDlLhEtDX4OhXcwo3eKZVMU1Ff64UqyfKqfd30xKqcv7AgvBA6GO0j 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 Wed, Dec 14, 2022 at 11:59:35AM +0100, David Hildenbrand wrote: > 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. That's why I mentioned on the order of operations matters. > > > > > 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(). Yes, this patch won't, because it's a pure cleanup. Otherwise we need another line of wr-protect in numa recover path. I can remove that sentence in v2 commit log. -- Peter Xu