From patchwork Thu Mar 30 13:40:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13194189 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 72940C761A6 for ; Thu, 30 Mar 2023 13:41:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDC366B0074; Thu, 30 Mar 2023 09:41:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8B396B007D; Thu, 30 Mar 2023 09:41:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D52F96B0080; Thu, 30 Mar 2023 09:41:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BD3D96B0074 for ; Thu, 30 Mar 2023 09:41:37 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8D2BD1209C4 for ; Thu, 30 Mar 2023 13:41:37 +0000 (UTC) X-FDA: 80625677034.18.C9B0007 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf07.hostedemail.com (Postfix) with ESMTP id 18C8640006 for ; Thu, 30 Mar 2023 13:41:34 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680183695; 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; bh=sqFhQUDXgIlzpli4zj+/EhLZe7JDjqB2+tFA0MAoZA8=; b=2Jq4yAPIFd+Xq9mh2fJp0L1MlACAE++VAGJNvEoFyudzHzxwpHO4xlVg9HgIYb0YXioyWq Z32o0zOgl+uc+SZICODnzeM6hgficgdvyhFBb9Du0LzKG4QtwRN8DsnmEQhu7lE7EmAPvH L2PtOJqfwMoOMs61nkdhT6zKEHmEv1o= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680183695; a=rsa-sha256; cv=none; b=Z6JRDfFzR8L7bAUoFCU/WP/eHcMO0DEYqHV1kLmv+Dyzz6xG7t1XN8nqyVExb9yjoyXNVr I7zNylRk2/3EuechcVv9F7wvZTsOSwZsQreumGcBc0FYSGc4SwTy0SjYhyhq8SKYxERtAj Ctx6Xbk2t/G0zJ/CHMMNfisfjzbjbKI= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4PnPhD0nzCzKqDF; Thu, 30 Mar 2023 21:41:00 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 30 Mar 2023 21:41:29 +0800 From: Peng Zhang To: , , , , CC: , , , , , ZhangPeng Subject: [PATCH v4 2/6] userfaultfd: use kmap_local_page() in copy_huge_page_from_user() Date: Thu, 30 Mar 2023 21:40:41 +0800 Message-ID: <20230330134045.375163-3-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230330134045.375163-1-zhangpeng362@huawei.com> References: <20230330134045.375163-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 18C8640006 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: gkh699q4qr11zrzbozfira73g1ntgi5x X-HE-Tag: 1680183694-925252 X-HE-Meta: U2FsdGVkX1+rJSwS0JiHK1hzIbdN1pgl6/2xjoOgzrarlu8sLZYD45CqD7a/qiZK2hHvdC0V8oS3IumUtxLPp4THZHVsw1nga4d1UnLgkM8ioJCTJRy321SfRm0UA6Ur35wNyEVBTJ64NqVP2K5MPRqoTLNXwxdbTyfsQ5VMhG8zovbfPGgGlMyvDN9N8/DWN5pODIiK1klBu2C0oLvFuaZyhoGW2MR7da2LBuFN6pQsMR6usEtaPYtT7b8xvUhCDJkaELPVG/i02bSQ8A52vy7szkiHRuQTWrFSBY+5rcVEtn+B1OHwEamhCUibWlGZkX6NaUpcOyuRBKSIlTSSZrCNl6+78z3jHg0SW/iNAgdexFcn1YzaxPwMVAKLj7sNVRW5Th6AeqbBYxJa6Mk+CiKwg3JP1ulS3bFo2GPgC4FYWEPCPTzfRhbHJaBuxMvyUnJW8fuoD3lkP5YMCh/Hh0IBeEkstwk5pZ/MktaBwO+ROUhV62/AcJH7EKc5JLmymODbhTPPLlSEm3RVOk7J6EPAFJTZTJG5cCeXF90nAr7hsqHyVbAncEded6EmYrgOab3Piyto3N/PGd4N2QA7kiuTqwGEkD+w4fcASFMhZUG930hE36RfhYwGQcipi4kw9uG5OWyoTGV97rO9ky5sH9Ix8IkBfj8PEYmoGt1e+fzodxw1mrpv/e26eq/DtwceCOfgmIa7kywa5+JxgbYB2yZ/1i1pnwTwl6JCbwz0D97CLvMCGCr50rKPziOZbA1LVfdj9WpmyB7sqnA2FMBBKhNIrM/B6n6NhhAq6TATZViUinF8xEiNy5AOnR1bWiNoJlZf2pta3s97wRVAW0p+ScZq4SJJQ8OukqVV0t27h2wryRRCU3/aFIM1VeavREiEsXwEFtchLNUtll4U3btneYqlMTwbIGWdUyztAksOXRV32xB4CAdod5q3Mfc2D8PPL6Sb3CdxdrGouWRfOC4 SVRNfBMD 8AoxfOeLfeI4Aj5H40bs+ch/sEjBA3bzQnIqHyQ4p9WmkV2nhxgsDTL3d7Z9eWQGNcYEO2hqEncbaKTZqcvqeDsIwS0Z1bJOCgA6v/XtglS2LWZsAyjsm3DWRCqAfq6RsIyDkAGE7od3Kt1q/GxFfjZYvIOL6FAYxkaUpalivuaQeKkc21/CMzUiejgfaM9vl6VcB2RRZmki+2n5kdHdngDkYtq4J2gA4OOK760HorQMq7Bf2P21yEljekgt0yrmSGgKu4xa3w46xuEQlB7CfNP2unq91gAxjyFFYK6oWiQlbnfDwnnt31wHbwXRttGgZz9suYO6rmyveUp7ORjk+7wrQ1qPurqTtgv48Gmwcz3mk9xY= 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: From: ZhangPeng kmap() and kmap_atomic() are being deprecated in favor of kmap_local_page() which is appropriate for any thread local context.[1] Let's replace the kmap() and kmap_atomic() with kmap_local_page() in copy_huge_page_from_user(). When allow_pagefault is false, disable page faults to prevent potential deadlock.[2] [1] https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com/ [2] https://lkml.kernel.org/r/20221025220136.2366143-1-ira.weiny@intel.com Signed-off-by: ZhangPeng --- mm/memory.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index f77fccb5310c..c47b8991410a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5866,16 +5866,14 @@ long copy_huge_page_from_user(struct page *dst_page, for (i = 0; i < pages_per_huge_page; i++) { subpage = nth_page(dst_page, i); - if (allow_pagefault) - page_kaddr = kmap(subpage); - else - page_kaddr = kmap_atomic(subpage); + page_kaddr = kmap_local_page(subpage); + if (!allow_pagefault) + pagefault_disable(); rc = copy_from_user(page_kaddr, usr_src + i * PAGE_SIZE, PAGE_SIZE); - if (allow_pagefault) - kunmap(subpage); - else - kunmap_atomic(page_kaddr); + if (!allow_pagefault) + pagefault_enable(); + kunmap_local(page_kaddr); ret_val -= (PAGE_SIZE - rc); if (rc)