From patchwork Mon Aug 12 16:42:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 13760845 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 C6733C3DA7F for ; Mon, 12 Aug 2024 16:48:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EF3C6B0095; Mon, 12 Aug 2024 12:48:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 29ED06B0098; Mon, 12 Aug 2024 12:48:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 166F36B009A; Mon, 12 Aug 2024 12:48:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id ECC516B0095 for ; Mon, 12 Aug 2024 12:48:11 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9F08212029A for ; Mon, 12 Aug 2024 16:48:11 +0000 (UTC) X-FDA: 82444175982.13.5E7589A Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by imf28.hostedemail.com (Postfix) with ESMTP id 89A2EC000E for ; Mon, 12 Aug 2024 16:48:09 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rxrbD0uc; spf=pass (imf28.hostedemail.com: domain of jannh@google.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=jannh@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723481219; 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=DJlU1qRayR5F9JUx5MXjL9SPDXmWr10IpUL5fPzVi5M=; b=7l/Yy8kTKBa3Nrrz0WmvoosRr0gUgmuQp0EzoH0TOklfJ1uZtCDZIyY0if6cTgYx0+kF20 q6dHq2mqxCv1Ov40a+mLgOobqNy05TPvWu+dhmgUw7xqrhqQxbfGPr35+ZRa+QudsZhF6B uf9OvYij/8QzbgxgmWWsC9lQ/EcPsaI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723481219; a=rsa-sha256; cv=none; b=hykgkkKEiESsRKNSeWDXxGDRnW+IrIF0/n9ZLSOx8UObG27smrvh5KtLG+P9ThpxRdFGQc wwnulV+eYwzRvfapIpnZeWAKy0m7fnUGrkujoDHlVdKhhe6ZLFBv8SiTkdl+cYuT6lgXLj ZqJYB2xd4uU6dO7WslpbH2UFhieaWxg= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rxrbD0uc; spf=pass (imf28.hostedemail.com: domain of jannh@google.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=jannh@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-42807cb6afdso305e9.1 for ; Mon, 12 Aug 2024 09:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723481288; x=1724086088; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DJlU1qRayR5F9JUx5MXjL9SPDXmWr10IpUL5fPzVi5M=; b=rxrbD0ucOCmKhbQrkxGJMIjwSKuBUFw+QJ5AMxodoq3uixYqYDidTswujLbCL+N9Pk NOsby6nQar8KTl5aE33mENAZIfB03FC/Bf+zN6ieRvCIr8TkFSTpYzogH6Y4JSRoO+JP tGeGre8YFuDNQyDP09279GrZGSW3xcx7+L7qcjnzoS8XsdpCtyfzeFlHBfdpIE2A+xnq uf+KLSiI+5VlrfsknsLrgWiG9VdnyhDCCO22EYJiNAiDuGn993PWowrpowS0Q5GiRmC/ hrO4Nqv62v2l10B+1Qj0ZW4ImGe8FGds38qK+J9zziTJIdtEbclaEjm8o0mFZW/9eWth bTdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723481288; x=1724086088; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DJlU1qRayR5F9JUx5MXjL9SPDXmWr10IpUL5fPzVi5M=; b=wVaCFoeFUiquZxkronb8zyouzqCNkve9btHDJ3IruClMmmSW/Fu4DmauVlm+0rmt5m FoWyb5OUHGlGC5KJZXFjT0RdngS8kZJpNPFAIOthaBny3z0Mw1UYj+jxzIBAucb1/5OV P4hNJEamfvNByJCBbBt2G20s0aa7FxvKZ2XaS6juUI7PUGuItx2nrQD0QufPu0bmCx8H fHnebn/ibWuWTjJxDW83U8SPd4UgqYNagKw5uqzlMFPaVNZQk0Q0BIuUXMjP1uGb92T5 l7jv+fv/Af0WhbH/u7gW2FpQYHcU+JD6bz1Tu4GXOGK8jeCkqf2c3V0cIiVArpiSkCIP 1YDA== X-Gm-Message-State: AOJu0YybT3PnNsyMzN2cqc8FuTLXrYqLdiF56shQAioYjwz8BF2/kDhD CQugaEI91F361P6IYJ12GA7K9kPI1y0d0e+cam8VLB28a2lBnb0qY5rGY+q5eydRxeJ/n8vL18g EWD1t X-Google-Smtp-Source: AGHT+IF3zlvPwjqUofQiL0ZC5eEQF3fcknxLRKQAkZEkHYcLKefHOkHnk0bRtOc+kUzO6CYwrPRQqA== X-Received: by 2002:a05:600c:1d9d:b0:428:e6eb:1340 with SMTP id 5b1f17b1804b1-429c7ab73f3mr3104265e9.4.1723480961010; Mon, 12 Aug 2024 09:42:41 -0700 (PDT) Received: from localhost ([2a00:79e0:9d:4:731e:4844:d154:4cec]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36e4ecc7ab6sm7913066f8f.104.2024.08.12.09.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 09:42:40 -0700 (PDT) From: Jann Horn Date: Mon, 12 Aug 2024 18:42:16 +0200 Subject: [PATCH 1/2] userfaultfd: Fix pmd_trans_huge() recheck race MIME-Version: 1.0 Message-Id: <20240812-uffd-thp-flip-fix-v1-1-4fc1db7ccdd0@google.com> References: <20240812-uffd-thp-flip-fix-v1-0-4fc1db7ccdd0@google.com> In-Reply-To: <20240812-uffd-thp-flip-fix-v1-0-4fc1db7ccdd0@google.com> To: Andrew Morton , Pavel Emelyanov , Andrea Arcangeli , Hugh Dickins Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jann Horn , stable@vger.kernel.org X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1723480955; l=1791; i=jannh@google.com; s=20240730; h=from:subject:message-id; bh=cyEqwtJdd73Z0XZVi41RqSUaVwXAJZY8AuIAhW9WDHE=; b=aJA7M7sFrH6fD8l5+lxzjeojnHNOZEjoqfdSfrX7+15r0/hEZsfJhoS9jBzIQjwlC/09kjeLt aliIZZ7VCkXCOia7BI5iwegqhOGJUdxnMWHy2QCvS7PsVHzM0h5yHQr X-Developer-Key: i=jannh@google.com; a=ed25519; pk=AljNtGOzXeF6khBXDJVVvwSEkVDGnnZZYqfWhP1V+C8= X-Stat-Signature: cuj38cqt683i1ryw7bgmgsmcdbfzkyop X-Rspamd-Queue-Id: 89A2EC000E X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723481289-54393 X-HE-Meta: U2FsdGVkX18ifjkKVlgE3GMm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u/krvtrisEIlbzYnSit2C/n3GYAu3jpSmj2TBDqrQkaURU8kJ5ZNAZlqcXr32deZkIvkd6HUmN0lNcMjET7Sn9/dzieHgvF2GlAwnxvm5q+vmnIRnI8tKk48JnmcHcfRu1h55XoyGYmGe2mPSj5VI4xeS0fXC2gpTBM49QM8YyxIMS3Bs0j4UE4+JgsZCaGhPgGJexYTmR9b0Hj399ZvNEoeSdJdHIV1wUEayxXULmQFPbtwc1NTawoPMiUvrBO4SEpggQRVgIP0IE0tLLSHYxAaq8KmAHDQc2MA== 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: The following race can occur: mfill_atomic other thread ============ ============ pmdp_get_lockless() [reads none pmd] __pte_alloc [no-op] BUG_ON(pmd_none(*dst_pmd)) I have experimentally verified this in a kernel with extra mdelay() calls; the BUG_ON(pmd_none(*dst_pmd)) triggers. On kernels newer than commit 0d940a9b270b ("mm/pgtable: allow pte_offset_map[_lock]() to fail"), this can't lead to anything worse than a BUG_ON(), since the page table access helpers are actually designed to deal with page tables concurrently disappearing; but on older kernels (<=6.4), I think we could probably theoretically race past the two BUG_ON() checks and end up treating a hugepage as a page table. Cc: stable@vger.kernel.org Fixes: c1a4de99fada ("userfaultfd: mcopy_atomic|mfill_zeropage: UFFDIO_COPY|UFFDIO_ZEROPAGE preparation") Signed-off-by: Jann Horn Acked-by: David Hildenbrand --- mm/userfaultfd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index e54e5c8907fa..ec3750467aa5 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -801,7 +801,8 @@ static __always_inline ssize_t mfill_atomic(struct userfaultfd_ctx *ctx, break; } /* If an huge pmd materialized from under us fail */ - if (unlikely(pmd_trans_huge(*dst_pmd))) { + dst_pmdval = pmdp_get_lockless(dst_pmd); + if (unlikely(pmd_none(dst_pmdval) || pmd_trans_huge(dst_pmdval))) { err = -EFAULT; break; } From patchwork Mon Aug 12 16:42:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 13760847 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 18A24C52D7C for ; Mon, 12 Aug 2024 16:49:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 932956B0089; Mon, 12 Aug 2024 12:49:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E2356B00A1; Mon, 12 Aug 2024 12:49:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A9FE6B00A2; Mon, 12 Aug 2024 12:49:45 -0400 (EDT) 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 5ADE66B0089 for ; Mon, 12 Aug 2024 12:49:45 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CE6DC402FE for ; Mon, 12 Aug 2024 16:49:44 +0000 (UTC) X-FDA: 82444179888.18.27BC9B8 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf02.hostedemail.com (Postfix) with ESMTP id C01DF80023 for ; Mon, 12 Aug 2024 16:49:42 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="MtJ/Z1kj"; spf=pass (imf02.hostedemail.com: domain of jannh@google.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=jannh@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723481348; 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=/Pwh5Yck0NJ63ftZanRvFS8ng+FvBnwXPy4oihzU0QE=; b=122uyVfANKbYnHbsLzEV3CwUJtsvnPP3OHsYPqGpKnYIrP4vD66mz3ihm5qKx786eeBIml ejQ7vKqqGUTZ0Pt23rN29tdmOJDn72yRTwsCpxJFi61D8gu5fzTfLqUC74uBNciL36HyhW vjG6Rey/SI23e06L7W/3jPwUdDIO168= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="MtJ/Z1kj"; spf=pass (imf02.hostedemail.com: domain of jannh@google.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=jannh@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723481348; a=rsa-sha256; cv=none; b=8Hz3U3kJIPzuhvcTHe3h/gntIBcdWQyIz+IKc66jP5hbjyogBhzmKsK8/7xKUCGFras6zn WWtACdRnNWsV9GHkEkjpEXY8GsFSVEiEstqIGXkP2cLC+FOggwkEKzICZmwjZ8SMP9Pn4z r+DIAnq5GZbhnzBBpKD1qhRdZZQLjd4= Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-429d1a9363aso1055e9.1 for ; Mon, 12 Aug 2024 09:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723481381; x=1724086181; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=/Pwh5Yck0NJ63ftZanRvFS8ng+FvBnwXPy4oihzU0QE=; b=MtJ/Z1kjsEMGYU0Ny8TGUFRGVvwFk6aIrN5/cRbFGGcRYdF4hlGgK3qV1AvfBRB5pG xM+zL+M/SpuOqT9hjRcc69p3av/+kVVjeRdO08zY8TGG8g5O+LoiWjilatW8twAzakci tqPJrAvYGJLTckBwvZWQ1J8jlIDDKNAlm9XNWX+oKsovRcJK9QCMuJn1mAytwOeSxel5 mA+/WghaLbAe1KydBYinZ8l66XRJcsSzP49JCS5g/Z7L+K/zCOluKEXrCXqXGHfOjK9H FyjS/aTraSfYTXvNn2nW4nu73glZSjUcTE5yjK9x9UENXDql3/qooc5sj4Ee8Bl8dmZh o0JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723481381; x=1724086181; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/Pwh5Yck0NJ63ftZanRvFS8ng+FvBnwXPy4oihzU0QE=; b=FxPTOVL2Zm/0Yd32AXUiPB/YSDDypPYJs6Q7h3PUDTAv1nhKkO8PLSQQihO3sooSQt c9h2wqTUcghiBkdB1Fix16XEJsqXcg90zJjjO2hjKK9BozhiyglAHvDR+XW6dipnBEfm Q9ajL0RciIOPMJr87N77nnfRCmpTYXIGD6St9uQy1UNhjtaC+S1AumOQZkd0JyzibCFl OVdgsFavxZVGQjja3vrWC8iLMWTdMzR+goXnTCqa0mzmTy1luSrTDoMC/7TL0Y3/fs+m YO+2qbzziq7moTZ/OOXNkkRl7DgpkBhIf8STlyhUsPsWHKSn6kdeg62ruTNHQQaV25+5 Zf6A== X-Gm-Message-State: AOJu0YzyOLVOmkxwm/eidEv05pg9sgGKXNUggMXwdDLG7Ay50ZYjDkyt JliwDQ4GeinoyfGpzI2iBPlfm+cfCqH/wfjoC2DcHcqJkuhDMuL07WQU5dZHMg== X-Google-Smtp-Source: AGHT+IHfHCfh/WSuaqttUqyZE+PyNP9LtWGsB/jH2gcAVk2r+RVkhkgxxEdBJPnJp7LHUeTtjOy/kw== X-Received: by 2002:a05:600c:3d0f:b0:424:898b:522b with SMTP id 5b1f17b1804b1-429c827a41dmr2993975e9.1.1723480961958; Mon, 12 Aug 2024 09:42:41 -0700 (PDT) Received: from localhost ([2a00:79e0:9d:4:731e:4844:d154:4cec]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36e4ebd3416sm7942206f8f.100.2024.08.12.09.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 09:42:41 -0700 (PDT) From: Jann Horn Date: Mon, 12 Aug 2024 18:42:17 +0200 Subject: [PATCH 2/2] userfaultfd: Don't BUG_ON() if khugepaged yanks our page table MIME-Version: 1.0 Message-Id: <20240812-uffd-thp-flip-fix-v1-2-4fc1db7ccdd0@google.com> References: <20240812-uffd-thp-flip-fix-v1-0-4fc1db7ccdd0@google.com> In-Reply-To: <20240812-uffd-thp-flip-fix-v1-0-4fc1db7ccdd0@google.com> To: Andrew Morton , Pavel Emelyanov , Andrea Arcangeli , Hugh Dickins Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jann Horn , stable@vger.kernel.org X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1723480955; l=1297; i=jannh@google.com; s=20240730; h=from:subject:message-id; bh=DZesoZHTRWCbLwwNstyM7gJ5jwQEg9bMdX+DVGz6a38=; b=ZH3EnaCLnxnBAMGfLvSGP0Eka8HeLuZeSjPlA42GsqIFj8e3TEDej8ARd5JVzffIeA0SjAHpP K2ENAU38N1DDTzCRll9WxUJ6b3Q4wSjqJacAcWC80k9zPshbwINOyyv X-Developer-Key: i=jannh@google.com; a=ed25519; pk=AljNtGOzXeF6khBXDJVVvwSEkVDGnnZZYqfWhP1V+C8= X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: C01DF80023 X-Stat-Signature: k5n1gijnd4613go13gsbz48m9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Ts7aYMdgarO/lgzdT31jIVVJSQKDVE3fSw/ibKz2j3VWvrCLGDufRnn2YRywYxoUkVoVToe1dkCk3Q34cysD/qVKP21IXz61sYSoJxQWCDHu+U9ecHkSzvEuPl9izMTnRiSqTAsXxsiJnJR78R9kgGjniOR1PotnXMVJtVV++Z8xgg1VsC/xzwW3vJeghqa1DLNx+EHy3I2/sJUvkN3g+gNoZy/LDJ/jT49RGTQPhYDqT7UrKE4ViY90wF7rR0SiucocxXhaAfmK5kRvC+KlWND5eq82MqDlmq0+R6X+0aw/BYoPUqmZSQeipYg6wDAlRAVCD9f/2NJCdenp1ir6QmisUyyWMzI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since khugepaged was changed to allow retracting page tables in file mappings without holding the mmap lock, these BUG_ON()s are wrong - get rid of them. We could also remove the preceding "if (unlikely(...))" block, but then we could reach pte_offset_map_lock() with transhuge pages not just for file mappings but also for anonymous mappings - which would probably be fine but I think is not necessarily expected. Cc: stable@vger.kernel.org Fixes: 1d65b771bc08 ("mm/khugepaged: retract_page_tables() without mmap or vma lock") Signed-off-by: Jann Horn Reviewed-by: Qi Zheng Acked-by: David Hildenbrand --- mm/userfaultfd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index ec3750467aa5..0dfa97db6feb 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -806,9 +806,10 @@ static __always_inline ssize_t mfill_atomic(struct userfaultfd_ctx *ctx, err = -EFAULT; break; } - - BUG_ON(pmd_none(*dst_pmd)); - BUG_ON(pmd_trans_huge(*dst_pmd)); + /* + * For shmem mappings, khugepaged is allowed to remove page + * tables under us; pte_offset_map_lock() will deal with that. + */ err = mfill_atomic_pte(dst_pmd, dst_vma, dst_addr, src_addr, flags, &folio);