From patchwork Wed Mar 13 21:31:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13591879 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 45F13C54E58 for ; Wed, 13 Mar 2024 21:31:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2DDA940010; Wed, 13 Mar 2024 17:31:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADE496B007B; Wed, 13 Mar 2024 17:31:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97FD6940010; Wed, 13 Mar 2024 17:31:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 895BF6B0071 for ; Wed, 13 Mar 2024 17:31:15 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E6C021A093A for ; Wed, 13 Mar 2024 21:31:14 +0000 (UTC) X-FDA: 81893311668.23.190AAD0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 7D239C000C for ; Wed, 13 Mar 2024 21:31:12 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OC1teFxM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710365472; 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: references:dkim-signature; bh=zSHMA3F9Ys9+S9b2CLlCHNAI2GjKD9Vh5g00AYRvICU=; b=jC4vHkAQ3/ZCu/rwXV8JAfvy9P8dA8LQ5MxshAAE40gU03T7PegR10YvGOI4oJcyqAFMQq q4RSFtfoOgJB0DfpP9Ua4UDkolC+3fjQ0hLiLU8kZIfQadp+wNTwRO5BdkuwDULKVmE8p4 uOGKFQ03YoxQ9/ChLKbLKuoUR0uDZKA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OC1teFxM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710365472; a=rsa-sha256; cv=none; b=PznZF343HK634QjPbCmJBpJkufSX+X0gBGzwzikbcaKU6ATXznF3zKJ1+YwBdz06GUWPL0 D505pBsGKzqdwkRWEkPPK31ca6+1uvewIKYf16pHdb0SbxloKYvrdP5J7WoJhMLmx/h3qx ZP1HWuLfqQYQ1+5GI12ZAvJ3bxo6t9s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710365471; 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; bh=zSHMA3F9Ys9+S9b2CLlCHNAI2GjKD9Vh5g00AYRvICU=; b=OC1teFxMsdTk489nhG9k7KbTIAG2taDn7HZiq7ZtphM+UuMLVGym+Y+pGYqSvJWTXzMKYj JBE1NFdX4QY0xQqMn+qkNfegP1GZP4XxnfK9LdwvqpgT14n5f432PbnXssDP1IJLOvLi5X GP/VCLs5VA8KR6v2tVGwGU/7Aog1ffs= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-17-Dyz_KKzpP4ikEJV52MXWEw-1; Wed, 13 Mar 2024 17:31:10 -0400 X-MC-Unique: Dyz_KKzpP4ikEJV52MXWEw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6912513fc7bso1605866d6.1 for ; Wed, 13 Mar 2024 14:31:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710365470; x=1710970270; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zSHMA3F9Ys9+S9b2CLlCHNAI2GjKD9Vh5g00AYRvICU=; b=PrpDtfqaZoOfzUvZaYO3v34+ecRH1hE7SuypH9+i4s3j425x/gJWyD++QkU9u8JOmm rDEqNb/soCR+5KFTuH4MpnMfee1gKF/25YcQkHHY4PbIZxJEaVkjWiMXVrapAh/0+Xw0 HKzgURQ/oVGB3UPhbEd4vvmDS6Heu8+bGiY/GI2C/Bft0AUKcZKpyYXW2L4bnIn8E/bW yjxZPive6AVl4P26Ph/Px/tYbBbKCjFK+SS6ihRALdpQ7k/b11e0CwqWudWFBoc89Tf4 jt5+kURE5Qg2mxL25i70vEuhiNfn3yxacNK7Zg5nDcYureOb7siU2LvZc13JHknrM10H VLCg== X-Gm-Message-State: AOJu0YzOiZifzUNg2cdjAWqx0oo8pEMSESBTZOxiDj/FJd5oJuS6iayw w0O+ZGjMV24TJZjIEWDRCL7f9sBmSok45xRXKmAJQmGZdwJkZmUguSPAkVj2hWrpQ5+Sh+f73Re qwR1gAdnw61MIfOlynPTEvRrmLHnLH+VW9iQAt2INqwd2zrY9pIqMows336keldy2hAAm0oolW7 jga15MMeLncu7T290fEB/7LtEYgn3cfw== X-Received: by 2002:a0c:eac3:0:b0:691:2524:2d87 with SMTP id y3-20020a0ceac3000000b0069125242d87mr2283304qvp.2.1710365469783; Wed, 13 Mar 2024 14:31:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsLh8aQhtPreOjP5bc4Hiwu2Giqo97Es+TwECM0aBYGuG0Rd6UIY+m2f6qoD6cxMewmR3UBA== X-Received: by 2002:a0c:eac3:0:b0:691:2524:2d87 with SMTP id y3-20020a0ceac3000000b0069125242d87mr2283267qvp.2.1710365469157; Wed, 13 Mar 2024 14:31:09 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id f7-20020a0562141d2700b00690f23c8605sm57087qvd.23.2024.03.13.14.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 14:31:08 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , peterx@redhat.com, Muhammad Usama Anjum , David Hildenbrand Subject: [PATCH] mm/memory: Fix missing pte marker for !page on pte zaps Date: Wed, 13 Mar 2024 17:31:07 -0400 Message-ID: <20240313213107.235067-1-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 7D239C000C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ak5k6u19thx4rx8ixdp5nj5dahghami9 X-HE-Tag: 1710365472-13588 X-HE-Meta: U2FsdGVkX1+VTJKHcgRbrwk76nwE0S2Mj0OssDF1z/8SD7UcQKsCFJ+rIz+ozT74QmLma4E4GnTMkPrRd24ukFOZ0pRodHbuF++cCZTMrP2zfHxxFStZRov3T9hWdNju718o/vDdlmmrS1zqsTQhtwNaSXtH+NFN1jTtNLVl3jC8atpqA2WkLhiBcXNcNLsXy/Wb/albYu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BQoPxb8MI9xRglsS2azPIBaLaI3/kl3PAVPfftWgRDkGv7QaEKGYyIz9DmyT5w9CIn55o4XyHvsJEApshsnd46rUbE0G5gK2CIENZNk773BLrMKRpR7ML2r/YSl7Yczq2paQzBplPAwEkiIJyVd5ND+nrAOvArVAc8MmoIZ3pMgDC3VDckrRorNK0zdmEeOrOBQeeqpKrr30ZGDLHqKv8AO8/6cEh8lCr8Ufr6QscRCGvHndZcCF 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: List-Subscribe: List-Unsubscribe: From: Peter Xu Commit 0cf18e839f64 of large folio zap work broke uffd-wp. Now mm's uffd unit test "wp-unpopulated" will trigger this WARN_ON_ONCE(). The WARN_ON_ONCE() asserts that an VMA cannot be registered with userfaultfd-wp if it contains a !normal page, but it's actually possible. One example is an anonymous vma, register with uffd-wp, read anything will install a zero page. Then when zap on it, this should trigger. What's more, removing that WARN_ON_ONCE may not be enough either, because we should also not rely on "whether it's a normal page" to decide whether pte marker is needed. For example, one can register wr-protect over some DAX regions to track writes when UFFD_FEATURE_WP_ASYNC enabled, in which case it can have page==NULL for a devmap but we may want to keep the marker around. Cc: Muhammad Usama Anjum Cc: David Hildenbrand Fixes: 0cf18e839f64 ("mm/memory: handle !page case in zap_present_pte() separately") Signed-off-by: Peter Xu Acked-by: David Hildenbrand --- mm/memory.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index f2bc6dd15eb8..904f70b99498 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1536,7 +1536,9 @@ static inline int zap_present_ptes(struct mmu_gather *tlb, ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); arch_check_zapped_pte(vma, ptent); tlb_remove_tlb_entry(tlb, pte, addr); - VM_WARN_ON_ONCE(userfaultfd_wp(vma)); + if (userfaultfd_pte_wp(vma, ptent)) + zap_install_uffd_wp_if_needed(vma, addr, pte, 1, + details, ptent); ksm_might_unmap_zero_page(mm, ptent); return 1; }