From patchwork Mon Apr 10 13:39:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13206367 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 134E5C76196 for ; Mon, 10 Apr 2023 13:39:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 474C9280019; Mon, 10 Apr 2023 09:39:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FE0D280002; Mon, 10 Apr 2023 09:39:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29F26280019; Mon, 10 Apr 2023 09:39:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1BD58280002 for ; Mon, 10 Apr 2023 09:39:51 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4C63B40A91 for ; Mon, 10 Apr 2023 13:39:50 +0000 (UTC) X-FDA: 80665589340.28.5B6F1E1 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf20.hostedemail.com (Postfix) with ESMTP id DD14B1C0018 for ; Mon, 10 Apr 2023 13:39:46 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.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=1681133987; 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=b/KcJHRk+/LYqoppATynjeN/hY0TLo6z9gkPQIifU7U=; b=fppfPs3rrF/0iOoekQDs1dZdoDG2WWnCfEMHycfecBMpDkaM4dHAd7/WFihESIxECIhIxm l8SIt08Lzkz/qpOWX19BZuuVMd4/FWZbw6k8+2jtv/3jOKTCbf8gh0Dr2BTVBZ5uM+jUHU svnbjiPPtJeU9IvKdCrWj29Bv47D8qQ= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.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=1681133987; a=rsa-sha256; cv=none; b=1nTZoG+srL5kuygtydFWkV7RXszRTDwtL83wjNCDwXSTqU12V1dqW8W8p+Jujx5GTf2cBa tvRxIaoSEPFusg1VUf1yW0yRM28qNsVF9LdLNTOQB5ei9PMKrTe3F2SG9L1IpmWnw3ini9 OBsmkufcD41Z9KfvC8MMO+NXuBvNL14= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Pw96q713xzKrfJ; Mon, 10 Apr 2023 21:38:59 +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.23; Mon, 10 Apr 2023 21:39:41 +0800 From: Peng Zhang To: , , , , , , CC: , , , ZhangPeng Subject: [PATCH v6 2/6] userfaultfd: use kmap_local_page() in copy_huge_page_from_user() Date: Mon, 10 Apr 2023 21:39:28 +0800 Message-ID: <20230410133932.32288-3-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230410133932.32288-1-zhangpeng362@huawei.com> References: <20230410133932.32288-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DD14B1C0018 X-Rspam-User: X-Stat-Signature: huernci7wip91ezfygcxbonoacso7tmr X-HE-Tag: 1681133986-697387 X-HE-Meta: U2FsdGVkX191pi3IaNrU/b//f+d86Mf1GnQlvvjpIx56r59PUM5Umn62s7yzOL+d2HVkxcAgZtsfemx0+ZzhStRWPWVHdp7FVoHyaICXfkIXjX7hp9eIPjxfbXs3Tg59Kb4dFrytpdt5aCEWknsmZtSuIqpTlXFdw+dAqkVDqwFfsKKvAcbIVHanjkBZZy8fYDQB0dVVOOHEkhnI5LgCUSi66l3DiwEyVdqNE0VSUWhJfj9/cbGo5mTNiTIW+3Hs6OCU3QDGzNE0CkoKaVP9dchuGiTxaF2kmJQl6ciX1oDsf30zlsOwke9ekXM5bzqsaxHt+ZfeCPkBB7JRD3Ar+81ZYvYwzxEvEHKJQdiL1wLDsgGRRUmQx2P/vAP4Q9vmNkGBFCnVwHRSP94WgmWVx6LBnibZgyNOPwaeyfnT73jX0zkZPfStTG+XX6eFXK0Mk2kPy22kLE48VIsWdXpDoBhVBo4SxXT6n3M+59XPoaXzCvVnOyoequ5pLTj5JNJsOBcRjy3CU4pxxPmiIJjtPgn+1zOQS5I4nyD0tWd5UiZKZaJY/Ay2v/Yn+1sYBUR3z3O4k7vRYmil4D+Rmpzf9XcyeSirjGQBQXQbca1JnegZLV70k63QYPZbQ0seL+1Ixz+gizFn+yMF7U14I281mOjv7oXgkgQ2xZ6BUionMDkL7ZKNAg+8TnGmvepMXpoKbHEJOuCBd6l2Y31wxti8qL7kAIrxSGYIBv+7rRb/M4HUw2k99cKOqmL7mYW5K90KDOsuSZkBSRXkbe6UtOKRxVBSbcohpezo3qlLgwWYk7QN8WetmdJkuLfQHCsQewArNM8mfH0YbNrAWSKn0JeCwtsiPM7gD7Tm6uFunfMqWJidrc/igoEdDN+KWS7YGu6mUo7xW/+rbtq3J2R6zJMWdWi9pHnzjCnbNNT51tDd3aS0cfkaHctuixym1pTy8YXP95sRXB4SbdPs0qjZcjm IlBMm5mn L9LHwzshhwHJbvGWSiEst3L6vlxV1mhI+1MTXs1PkiSnh7WiM13/uFHxgrRcOle+UstbXXMyfP1DzJB0oCZxzmD7rL9mBlKqdTAgJMtTOuq2x/TMOOepGkKBncCj8C5IsP1hGjsGBMwPAOukVnBWvKkC3uvBqaRCh8gdduXvvMHYn6vSO0uKPdo+8ns6XxU42Pmlhr9xmmNo6KrSQDsEkZKCPBE4Pt4m0XTCXQAK0vcLHnhWi0QOZN48SNeRyKj+DtsouwLiaKwjIbSGwkouwvyB4yuj/I8D+M0JFJ8KO9FjsaznlEoNmDDfbQZ5RoHGLiLJ8wOWAGbmfgJRuMgs8VUs/rLSzhpbNFjnlcQuUaLgb9UXH5MYWvrnCb5LCCRmblk6B 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 Reviewed-by: Mike Kravetz --- mm/memory.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 387226d6094d..808f354bce65 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5880,16 +5880,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)