From patchwork Sat Mar 25 06:56:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13187631 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 9F79CC77B60 for ; Sat, 25 Mar 2023 06:56:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 084656B0078; Sat, 25 Mar 2023 02:56:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F287F6B0075; Sat, 25 Mar 2023 02:56:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF0D96B007D; Sat, 25 Mar 2023 02:56:25 -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 ABC326B0075 for ; Sat, 25 Mar 2023 02:56:25 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7B9ADC0121 for ; Sat, 25 Mar 2023 06:56:25 +0000 (UTC) X-FDA: 80606511930.24.86451B8 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf22.hostedemail.com (Postfix) with ESMTP id D6091C0014 for ; Sat, 25 Mar 2023 06:56:21 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.188 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=1679727383; 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=kHAvzVHI6LRMiiNYBPBqlBYP1x/JpIh+mHHtGaE3lL4=; b=FSWu/3ndVVLctUb+jZf9kn//tn8t9/v8qHN4BcPheaH+eeB1QQ/ihH44oZxTGE1uDpgCBq 0umfnIapn2t4MddP8RO6e//00jS6fNCapzUsYE5l0YLa5ncWVzf20Zm5TS/b8vaX5g5U7w Gqfy+SimV/C6pmPIqd4744PQVbyAp10= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679727383; a=rsa-sha256; cv=none; b=bOMygpMsF0J0J5FjephQ2HmAgJQxxnkXkJPCv6a96ih+9h5t+dQ4+dO/G19Sq39rLXiM0A 5OWWxtGpUsRmtPJu2Zqrm263n+TqxBYkKkc36r3tK+Ud31erQKQYPrYoJc32KbSI32bKoD IgafS9vIdFBSiNQN6LvGGPDHxGMu7lY= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pk8sW1n6VzSnxP; Sat, 25 Mar 2023 14:52:47 +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; Sat, 25 Mar 2023 14:56:15 +0800 From: Peng Zhang To: , , , CC: , , , , , , ZhangPeng Subject: [PATCH v3 2/6] userfaultfd: use kmap_local_page() in copy_huge_page_from_user() Date: Sat, 25 Mar 2023 14:56:04 +0800 Message-ID: <20230325065608.601391-3-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230325065608.601391-1-zhangpeng362@huawei.com> References: <20230325065608.601391-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-Server: rspam07 X-Rspamd-Queue-Id: D6091C0014 X-Rspam-User: X-Stat-Signature: zihe9ocwksxmdskiw6d1f9wrc7hrjoxd X-HE-Tag: 1679727381-924151 X-HE-Meta: U2FsdGVkX19+qTb9wsYM9vdg2KD2AExfYeTqKad3dyM0Bn82OagYEGwlRhRUyQT2RosHE7pJkm19id9qy1WacOUQRtfUMxRxOehN8LxjVYYmw5BZBUBXf5yMXyyJcN2C9g1P8ft6Efer1qKfQIEtNYxUhbOeaZEqk0IkulxEStld4Sv0E7JFU3b4JWZCLeoRuCZtBMHVWWnI6dRiRcSR/+EzFt3mw0uIiFBYDSpXAcX02Qlg8HVVPq9m4oIAbwKnUrBfphSgTzCYJDIfrujx/n3e7Qu4EGb0bif7U2vpy305Ry6OXjZsv+Io7naVQCwzaZenKSe6Pb5p9rUSPjBlcE1+eutympGNdMnqNRDnyW0FLziU2RXGZd0b1jYRo4ADoFWtqzCtgfpJ5w4hsRWiXaksBsgzu/HwYuY9G1laT3fLSMqi5tZW+HjIe7RKyZV4sZzi1nQkAYyP4u1H8NLNRwWjhXVy4nU1SjZEAtt65+o+snEtQIKu7EYW1TLxPhmPlzh0oQW0KDndUFEHl6UhSTXWkpAZmS1zTmhU1VVjjikAC/gM6b+cTs7WElVbtu3BUAGsj1jVmk/sbNTQLbZ8rAioH9egnFhztGAD6g4JTHaUr4AgzsnfmbbxThCN6XUiU0w/1RYdu4oVL5ar7zq+hRRmEv9+osNqJBHI9broQcpEvwYBtdE5MYx+6SptgOBswgNyukmkpwE6zEleCL9JN7QVw7lsMqNCGG7AjAlHQ8PyBk4fi4oqRa9WSXNkEJ2MBiE7IAtIJKx1B8qet+oDptYFDX3S5x9xcEpH9AZoPPCLWTYi463NpiNHGbzm/fDGbKaOIp/06sR7zIrUDLiUfoDm+SRB7UW+zmSoteuJCzmixsxm20+gy207flJ6Ktlk05vznsUZNf3ZqDwtBVN5rHz68l2XgFZFG/eGZAPBX+OysbG43jk30DLIcjQS5B1uByU0Nw63bTLdxp5t0fg bEkvu3fW J8+4+WFVI4Xo9+iYR9EKhm7kMD3QDmQ85l/ZH2QgXetRJqBIpgdMl8AejFNUGbpw+/guStgrfqKrPnHRlLsyx+iYwxGVdEwf2KuuAbWmx4wRpnvdOeBugzZ4CbwufPoewbNJK6BOfdxFBj/Bc3ATp5JW6DOlNpVdcs7mGCmyOwUFQbGMZ+Yl/2B45H+lltsn3dnnbFxfidO3dhZocI4AqunqMNTxqJmDf1HGkhsUNb4VeR76otNYnhkqEqHJDcDYf7TlVtcsS5WsVf3mg5HRgUey7Q8ssRzvIQkusR7G0isYhCBLvjXYoVVo8YgYbXZo6i48wn1A5Ky0BOja4C+63Xbm9ymflSngFO5b0iYdJzK/5Hbo= 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 f456f3b5049c..062bd215bea8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5781,16 +5781,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)