From patchwork Fri Nov 1 12:08:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asahi Lina X-Patchwork-Id: 13859290 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 4A839E6B24F for ; Fri, 1 Nov 2024 12:08:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B77F56B0092; Fri, 1 Nov 2024 08:08:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B27EF6B0093; Fri, 1 Nov 2024 08:08:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A16E26B0095; Fri, 1 Nov 2024 08:08:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 84A6C6B0092 for ; Fri, 1 Nov 2024 08:08:16 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1F63FC012A for ; Fri, 1 Nov 2024 12:08:16 +0000 (UTC) X-FDA: 82737401964.01.BA5DB1F Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by imf06.hostedemail.com (Postfix) with ESMTP id 94F8718001F for ; Fri, 1 Nov 2024 12:07:53 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=asahilina.net header.s=default header.b=WO+6k39q; dmarc=pass (policy=quarantine) header.from=asahilina.net; spf=pass (imf06.hostedemail.com: domain of lina@asahilina.net designates 212.63.210.85 as permitted sender) smtp.mailfrom=lina@asahilina.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730462838; a=rsa-sha256; cv=none; b=7SZ78jOpaQt/zidcyVkeArsekhbo2Ewyudmk1dVquyYPAvHlACq3dVa/DQpYbGo1k25vpH LO249dP0K10sqIPusQXE5wZAfjiCMYwf5MOuioCC2190cboK/qvqP4R1nQS6tLY2fROMNa CtDQWpGxH/DfCkZkUYeZ1Y2sN3pIHuI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=asahilina.net header.s=default header.b=WO+6k39q; dmarc=pass (policy=quarantine) header.from=asahilina.net; spf=pass (imf06.hostedemail.com: domain of lina@asahilina.net designates 212.63.210.85 as permitted sender) smtp.mailfrom=lina@asahilina.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730462838; 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=PUZmuF0oq++NJBv/kw/mF57QTZdoi19ibFR2r2hnxdA=; b=hkQam9HEOtSs9jcuS4VJNZoS6/uo6wOz+TyURoipdAqKihdf2uEbD2aUmWK05zTNyFyMEx fW8d4GkMqpOBx0cS7RKK04/KOAFAuXAoLrbJlxZUzRQhSrca3Wij/zhAg+GMfWEfS5CLkF 5Ub9AvYPKkX2Hxmap3fGepNhd3JJB0o= Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sendonly@marcansoft.com) by mail.marcansoft.com (Postfix) with ESMTPSA id 8CEA04346B; Fri, 1 Nov 2024 12:08:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=asahilina.net; s=default; t=1730462890; bh=evphT9Levh8iSGrIyA3iV2Q4n/gTxYKNQhtxs27IDSU=; h=From:Date:Subject:To:Cc; b=WO+6k39q9hO90X4GxNxwlk1Ts7Z0sQPh1L6QVxAwpnAx+FII85VLWxvS9V/dnZKSV wswPp9+3bdPA5ekkeO3Qd915naCXSm6wgCXyE2K7AXtxAgsgAsHb4cq2s98JRLz3Zt I3Z0nNqxd2d3nQDzvwbk4EpiMyso2IYckrkYkmZ9G5VoOLQcZ5HL411glRDe+25k5L 8mJtVoBPrKBDeRlOSlDEE0HaqeWwCiLjhOcuV8uPAz0f72envqtAbZ77z+wOmxd0el 5I4xgRhC+zw5+NbEFbJ44VCPDsLLswPDxwQJJqMAd/dH8hdDKX905ieMucKGDHcD4Y H5z/xqrLqKVIw== From: Asahi Lina Date: Fri, 01 Nov 2024 21:08:02 +0900 Subject: [PATCH] mm: Fix __wp_page_copy_user fallback path for remote mm MIME-Version: 1.0 Message-Id: <20241101-mm-remote-pfn-v1-1-080b609270b7@asahilina.net> X-B4-Tracking: v=1; b=H4sIAKHEJGcC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxNDQwND3dxc3aLU3PySVN2CtDzdFCNTIzMzyyRLE3NTJaCegqLUtMwKsHn RsbW1AJDfJgVfAAAA X-Change-ID: 20241101-mm-remote-pfn-d252669b9475 To: Andrew Morton Cc: Sergio Lopez Pascual , linux-mm@kvack.org, linux-kernel@vger.kernel.org, asahi@lists.linux.dev, Asahi Lina X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730462889; l=3847; i=lina@asahilina.net; s=20240902; h=from:subject:message-id; bh=evphT9Levh8iSGrIyA3iV2Q4n/gTxYKNQhtxs27IDSU=; b=hflyZWsN1dNrY23uoJlhzkdpkOKAbGfGkZG7106swJktCq92mh4pd3ABT59AikfQWEZx02yc3 sSn4Z9BNz22BNzzImHeFplX7auEfLtZxU01IhqdRyPL0ZCYiGPXywoh X-Developer-Key: i=lina@asahilina.net; a=ed25519; pk=tpv7cWfUnHNw5jwf6h4t0gGgglt3/xcwlfs0+A/uUu8= X-Rspam-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BCym0MI 64oJCasn H2jLBxbFFipXkSGAbRS2vVehtw/6ET20xDjRAbGTEuEdZuHbWrXV37klfAKmCDBSLESsVtORAqcM+gZGRkarwcS0sK8bz+NoWoLUD45AszulT2EVpPSYdJnBuqD2h5zJeBof4KC+4A9XQIWubvnfd2hMDWA9KAKRrjQcrx6you/MdM/+4eXmFzxC8ougslwVK+axtAewhcEkLYRNYXdmSIozEE1AtoJt+Yu8LSH1HF+WCB5X4EPjGOYp6jHybXcXBvdlfcuQ/s3QvKSguzzWc3K7c+GUmcI4XAScB0kKPG3fLUqRFo58hfxn5psU4sMJ3luQh5ky/cSZgDUW0rJ7JgOSsOg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.002212, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: If the source page is a PFN mapping, we copy back from userspace. However, if this fault is a remote access, we cannot use __copy_from_user_inatomic. Instead, use access_remote_vm() in this case. Fixes WARN and incorrect zero-filling when writing to CoW mappings in a remote process, such as when using gdb on a binary present on a DAX filesystem. [ 143.683782] ------------[ cut here ]------------ [ 143.683784] WARNING: CPU: 1 PID: 350 at mm/memory.c:2904 __wp_page_copy_user+0x120/0x2bc [ 143.683793] CPU: 1 PID: 350 Comm: gdb Not tainted 6.6.52 #1 [ 143.683794] Hardware name: linux,dummy-virt (DT) [ 143.683795] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 143.683796] pc : __wp_page_copy_user+0x120/0x2bc [ 143.683798] lr : __wp_page_copy_user+0x254/0x2bc [ 143.683799] sp : ffff80008272b8b0 [ 143.683799] x29: ffff80008272b8b0 x28: 0000000000000000 x27: ffff000083bad580 [ 143.683801] x26: 0000000000000000 x25: 0000fffff7fd5000 x24: ffff000081db04c0 [ 143.683802] x23: ffff00014f24b000 x22: fffffc00053c92c0 x21: ffff000083502150 [ 143.683803] x20: 0000fffff7fd5000 x19: ffff80008272b9d0 x18: 0000000000000000 [ 143.683804] x17: ffff000081db0500 x16: ffff800080fe52a0 x15: 0000fffff7fd5000 [ 143.683804] x14: 0000000000bb1845 x13: 0000000000000080 x12: ffff80008272b880 [ 143.683805] x11: ffff000081d13600 x10: ffff000081d13608 x9 : ffff000081d1360c [ 143.683806] x8 : ffff000083a16f00 x7 : 0000000000000010 x6 : ffff00014f24b000 [ 143.683807] x5 : ffff00014f24c000 x4 : 0000000000000000 x3 : ffff000083582000 [ 143.683807] x2 : 0000000000000f80 x1 : 0000fffff7fd5000 x0 : 0000000000001000 [ 143.683808] Call trace: [ 143.683809] __wp_page_copy_user+0x120/0x2bc [ 143.683810] wp_page_copy+0x98/0x5c0 [ 143.683813] do_wp_page+0x250/0x530 [ 143.683814] __handle_mm_fault+0x278/0x284 [ 143.683817] handle_mm_fault+0x64/0x1e8 [ 143.683819] faultin_page+0x5c/0x110 [ 143.683820] __get_user_pages+0xc8/0x2f4 [ 143.683821] get_user_pages_remote+0xac/0x30c [ 143.683823] __access_remote_vm+0xb4/0x368 [ 143.683824] access_remote_vm+0x10/0x1c [ 143.683826] mem_rw.isra.0+0xc4/0x218 [ 143.683831] mem_write+0x18/0x24 [ 143.683831] vfs_write+0xa0/0x37c [ 143.683834] ksys_pwrite64+0x7c/0xc0 [ 143.683834] __arm64_sys_pwrite64+0x20/0x2c [ 143.683835] invoke_syscall+0x48/0x10c [ 143.683837] el0_svc_common.constprop.0+0x40/0xe0 [ 143.683839] do_el0_svc+0x1c/0x28 [ 143.683841] el0_svc+0x3c/0xdc [ 143.683846] el0t_64_sync_handler+0x120/0x12c [ 143.683848] el0t_64_sync+0x194/0x198 [ 143.683849] ---[ end trace 0000000000000000 ]--- Signed-off-by: Asahi Lina --- mm/memory.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- base-commit: 81983758430957d9a5cb3333fe324fd70cf63e7e change-id: 20241101-mm-remote-pfn-d252669b9475 Cheers, ~~ Lina diff --git a/mm/memory.c b/mm/memory.c index 3ccee51adfbbd007b24331fe6874265f231a877b..dba25d9734063ac02cdaeb0a5cd5432473f6372e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3081,13 +3081,18 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src, update_mmu_cache_range(vmf, vma, addr, vmf->pte, 1); } + /* If the mm is a remote mm, copy in the page using access_remote_vm() */ + if (current->mm != mm) { + if (access_remote_vm(mm, (unsigned long)uaddr, kaddr, PAGE_SIZE, 0) != PAGE_SIZE) + goto warn; + } /* * This really shouldn't fail, because the page is there * in the page tables. But it might just be unreadable, * in which case we just give up and fill the result with * zeroes. */ - if (__copy_from_user_inatomic(kaddr, uaddr, PAGE_SIZE)) { + else if (__copy_from_user_inatomic(kaddr, uaddr, PAGE_SIZE)) { if (vmf->pte) goto warn;