From patchwork Tue Aug 25 06:42:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 11734999 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F9F6913 for ; Tue, 25 Aug 2020 06:43:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F28AD2075F for ; Tue, 25 Aug 2020 06:43:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=popple.id.au header.i=@popple.id.au header.b="TbR5NIO3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F28AD2075F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=popple.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3A0328E0010; Tue, 25 Aug 2020 02:43:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 352308D0003; Tue, 25 Aug 2020 02:43:30 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28F8C8E0010; Tue, 25 Aug 2020 02:43:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id 120ED8D0003 for ; Tue, 25 Aug 2020 02:43:30 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C72841EE6 for ; Tue, 25 Aug 2020 06:43:29 +0000 (UTC) X-FDA: 77188149738.20.back94_3d00a9927059 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 58241180C0616 for ; Tue, 25 Aug 2020 06:43:19 +0000 (UTC) X-Spam-Summary: 1,0,0,cdd501cb07469928,d41d8cd98f00b204,alistair@popple.id.au,,RULES_HIT:41:355:379:541:800:960:968:973:988:989:1260:1261:1311:1314:1345:1431:1437:1515:1534:1541:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:4250:5007:6261:6653:7903:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:13069:13311:13357:13894:14093:14096:14181:14384:14394:14721:21080:21451:21627:30054,0,RBL:203.11.71.1:@popple.id.au:.lbl8.mailshell.net-64.100.201.201 62.2.32.100;04yf455t3ux7nhgc6qsk753fcuhgmopsrcktuhm6osfsueg5sfixifuto6zmq6f.gxz6ir5mms8w5jpnfaq89889f6gxbfbp419qy9tuksgy4otkz5sfpm1xgxdr38i.e-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:232,LUA_SUMMARY:none X-HE-Tag: back94_3d00a9927059 X-Filterd-Recvd-Size: 2827 Received: from ozlabs.org (ozlabs.org [203.11.71.1]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Tue, 25 Aug 2020 06:43:17 +0000 (UTC) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4BbKFG27zGz9sTY; Tue, 25 Aug 2020 16:43:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=popple.id.au; s=202006; t=1598337794; bh=8N/iHSLK5FilP1L0fcoIeCnUrRCEEemp2bK1xK1CiXE=; h=From:To:Cc:Subject:Date:From; b=TbR5NIO3aYdM28GtfQB11RYJxtU09KXKYg8mxSd0JD5+dFdQevRo3DoKjLE3vFvsp w2UMfmNBu3id0uQVBz65bTd+ICw/H9WJP8C5CpODzNh45VhwLmNPsE4aUjwxGq2O3f BEXPAIRdAcdpnji85sNXQWfgkGX4snxAHuadTNCulqhBecWXEZGv1V9suxmDFUIme/ T4Cnl6pxuaMJMF/Juk3poqX2ZR79/yKVm/AiGQFF3OKbT7nRWSHhb2blGRaE455JU2 /DUQLD8PGzbJpO1yB+KKULq0bHgOgc59d7Bw3cc/+CDACobxtdlnJxJlII/a3fM53v 1+rY1ZxMmftvQ== From: Alistair Popple To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Peter Xu , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , Ralph Campbell , Alistair Popple , stable@vger.kernel.org Subject: [PATCH v2 1/2] mm/migrate: Fixup setting UFFD_WP flag Date: Tue, 25 Aug 2020 16:42:31 +1000 Message-Id: <20200825064232.10023-1-alistair@popple.id.au> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 58241180C0616 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: Commit f45ec5ff16a75 ("userfaultfd: wp: support swap and page migration") introduced support for tracking the uffd wp bit during page migration. However the non-swap PTE variant was used to set the flag for zone device private pages which are a type of swap page. This leads to corruption of the swap offset if the original PTE has the uffd_wp flag set. Fixes: f45ec5ff16a75 ("userfaultfd: wp: support swap and page migration") Signed-off-by: Alistair Popple Reviewed-by: Peter Xu Cc: stable@vger.kernel.org --- mm/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index 34a842a8eb6a..ddb64253fe3e 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -251,7 +251,7 @@ static bool remove_migration_pte(struct page *page, struct vm_area_struct *vma, entry = make_device_private_entry(new, pte_write(pte)); pte = swp_entry_to_pte(entry); if (pte_swp_uffd_wp(*pvmw.pte)) - pte = pte_mkuffd_wp(pte); + pte = pte_swp_mkuffd_wp(pte); } } From patchwork Tue Aug 25 06:42:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 11734997 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3458C1731 for ; Tue, 25 Aug 2020 06:43:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E28812075F for ; Tue, 25 Aug 2020 06:43:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=popple.id.au header.i=@popple.id.au header.b="Sl6HnPeF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E28812075F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=popple.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E762F8E000D; Tue, 25 Aug 2020 02:43:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E26C68D0003; Tue, 25 Aug 2020 02:43:19 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D14798E000D; Tue, 25 Aug 2020 02:43:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id B84478D0003 for ; Tue, 25 Aug 2020 02:43:19 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7A68F180AD811 for ; Tue, 25 Aug 2020 06:43:19 +0000 (UTC) X-FDA: 77188149318.28.bat50_59099b127059 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 3CAC06C1F for ; Tue, 25 Aug 2020 06:43:19 +0000 (UTC) X-Spam-Summary: 1,0,0,cdd11201388fcf2f,d41d8cd98f00b204,alistair@popple.id.au,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1261:1311:1314:1345:1359:1431:1437:1515:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:2897:2914:3138:3139:3140:3141:3142:3354:3865:3867:3868:3870:3871:4321:5007:6117:6261:6653:7903:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:12986:13894:14093:14096:14181:14394:14721:21080:21451:21627:30003:30012:30025:30054:30056,0,RBL:203.11.71.1:@popple.id.au:.lbl8.mailshell.net-64.100.201.201 62.2.32.100;04yrtyp1cs1xskg8n15nz7qjrcxgwypk486up79s6ekhd5dbnt8fktt7cqkppup.oxa7rcdmf6ty4cf357y1e5jtrhix8shen85oeywfqoeoh1tqakmkfaj85gpjziq.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:217,LUA_SUMMARY:none X-HE-Tag: bat50_59099b127059 X-Filterd-Recvd-Size: 4638 Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Tue, 25 Aug 2020 06:43:18 +0000 (UTC) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4BbKFG6w2bz9sTg; Tue, 25 Aug 2020 16:43:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=popple.id.au; s=202006; t=1598337795; bh=Sj46gycTZgpbO+qnDzJk+GkyULtzfVTSJY3XqVv4wBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sl6HnPeF9b+3VaBws8Pbzu+/2SveSr2RUMDdlLJ1rp/tIB7/NhESW8q7xHu4UnG3+ dyBpdqE1G/KFNbtz3N7yDL/74VJgTzbGUBGDxlK2pHVhSJyrJZn0xN+veKqQpYuNGb atJHD8hrDQosK6//AgWADTybAiuKcX3MwbBL/ohsUQx3eHz1KTc5IIEG4Js35Ay0a6 VZGpV5IWKFnDiyZHLyt/6Wr62R1tui2nEcCA5xXHDAm8Xn0I2AD4oLS2kyBsfxSCli ocCYp6UZ/wL9cLX1Cl0ZqswYRnXofhgj3VP9K5VbgbBPo7YUQGLDkffOfzx6HWo7hW CX0eTU9yaV6XQ== From: Alistair Popple To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Peter Xu , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , Ralph Campbell , Alistair Popple , stable@vger.kernel.org Subject: [PATCH v2 2/2] mm/rmap: Fixup copying of soft dirty and uffd ptes Date: Tue, 25 Aug 2020 16:42:32 +1000 Message-Id: <20200825064232.10023-2-alistair@popple.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200825064232.10023-1-alistair@popple.id.au> References: <20200825064232.10023-1-alistair@popple.id.au> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3CAC06C1F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: During memory migration a pte is temporarily replaced with a migration swap pte. Some pte bits from the existing mapping such as the soft-dirty and uffd write-protect bits are preserved by copying these to the temporary migration swap pte. However these bits are not stored at the same location for swap and non-swap ptes. Therefore testing these bits requires using the appropriate helper function for the given pte type. Unfortunately several code locations were found where the wrong helper function is being used to test soft_dirty and uffd_wp bits which leads to them getting incorrectly set or cleared during page-migration. Fix these by using the correct tests based on pte type. Fixes: a5430dda8a3a ("mm/migrate: support un-addressable ZONE_DEVICE page in migration") Fixes: 8c3328f1f36a ("mm/migrate: migrate_vma() unmap page from vma while collecting pages") Fixes: f45ec5ff16a7 ("userfaultfd: wp: support swap and page migration") Signed-off-by: Alistair Popple Cc: stable@vger.kernel.org Reviewed-by: Peter Xu --- mm/migrate.c | 15 +++++++++++---- mm/rmap.c | 9 +++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index ddb64253fe3e..12f63806d0ac 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2427,10 +2427,17 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, entry = make_migration_entry(page, mpfn & MIGRATE_PFN_WRITE); swp_pte = swp_entry_to_pte(entry); - if (pte_soft_dirty(pte)) - swp_pte = pte_swp_mksoft_dirty(swp_pte); - if (pte_uffd_wp(pte)) - swp_pte = pte_swp_mkuffd_wp(swp_pte); + if (pte_present(pte)) { + if (pte_soft_dirty(pte)) + swp_pte = pte_swp_mksoft_dirty(swp_pte); + if (pte_uffd_wp(pte)) + swp_pte = pte_swp_mkuffd_wp(swp_pte); + } else { + if (pte_swp_soft_dirty(pte)) + swp_pte = pte_swp_mksoft_dirty(swp_pte); + if (pte_swp_uffd_wp(pte)) + swp_pte = pte_swp_mkuffd_wp(swp_pte); + } set_pte_at(mm, addr, ptep, swp_pte); /* diff --git a/mm/rmap.c b/mm/rmap.c index 83cc459edc40..9425260774a1 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1511,9 +1511,14 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, */ entry = make_migration_entry(page, 0); swp_pte = swp_entry_to_pte(entry); - if (pte_soft_dirty(pteval)) + + /* + * pteval maps a zone device page and is therefore + * a swap pte. + */ + if (pte_swp_soft_dirty(pteval)) swp_pte = pte_swp_mksoft_dirty(swp_pte); - if (pte_uffd_wp(pteval)) + if (pte_swp_uffd_wp(pteval)) swp_pte = pte_swp_mkuffd_wp(swp_pte); set_pte_at(mm, pvmw.address, pvmw.pte, swp_pte); /*