From patchwork Wed Apr 3 08:38:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13615374 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 702E2C6FD1F for ; Wed, 3 Apr 2024 08:38:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9EBAF6B0095; Wed, 3 Apr 2024 04:38:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94F2D6B0098; Wed, 3 Apr 2024 04:38:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72C566B0099; Wed, 3 Apr 2024 04:38:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4360B6B0095 for ; Wed, 3 Apr 2024 04:38:35 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0028880D0C for ; Wed, 3 Apr 2024 08:38:34 +0000 (UTC) X-FDA: 81967569348.08.8E7B765 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf20.hostedemail.com (Postfix) with ESMTP id 737201C001E for ; Wed, 3 Apr 2024 08:38:32 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712133513; 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=lmVlreGnPFbXRLejlXB9QDif0bxo2zNzlVV4g4MDH8w=; b=Jwja55E3UFPoTafZtDVmNs8VjMvfFdnrHC1YwoIzWXebtgHWwjaJwsdAfzZFfOjrmTM5N4 Wc84oue0WBOUQ0NmgtxMfw6m156dvk5xIDHtQ/UigLHFYYka4y2M3o24qWxNE+yRqExRU+ prWFxg8CggosTj2pn2FB8ory6pB8WL0= 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 wangkefeng.wang@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712133513; a=rsa-sha256; cv=none; b=SGi43ZVnBEseCp+TcyH+g9iwSo03XV4oodjOetfmtjFqTZfcwDputrxlcxflTlmKiUbCfP FIds3jj0hlq/dlwFF+pnF99/OIpAeAY3VZqmkAWNnBqSHTkhaw8QwhWy7xbDGfY+QYUbWX YTebTTYRI/Y1C4+Ehh49yN83bW0iJIo= Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4V8dRP0T1xz17MxK; Wed, 3 Apr 2024 16:37:37 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 67C731A016C; Wed, 3 Apr 2024 16:38:29 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 3 Apr 2024 16:38:28 +0800 From: Kefeng Wang To: CC: Russell King , Catalin Marinas , Will Deacon , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Dave Hansen , Andy Lutomirski , Peter Zijlstra , , , , , , , , Kefeng Wang Subject: [PATCH v2 7/7] x86: mm: accelerate pagefault when badaccess Date: Wed, 3 Apr 2024 16:38:05 +0800 Message-ID: <20240403083805.1818160-8-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240403083805.1818160-1-wangkefeng.wang@huawei.com> References: <20240403083805.1818160-1-wangkefeng.wang@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 dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Queue-Id: 737201C001E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 8t3hcb7pewa69bhack7k9qroin9e7pop X-HE-Tag: 1712133512-892161 X-HE-Meta: U2FsdGVkX1819Fc9Njmvfdr1081TVsvBTQlHMQyrUDLjkYj5bJsSNdoxH6nRCseEmJwSRgu+orET/0neNporPXKihjBe6HvNsBe/ALIIXeqmttjkUWpZ+H3qGfT0a61x7zRa8Bu0vd+fwTg3pG5G0bs2BWDenhI2DFCllFoYc78u2C31HOtEZMpv0emqJGPnGJZV9GMSbmf5XBgUWawGs5Fb0sone7WUZ3vSvPQVeDF3EFkLhsr5+quFB1BpDwqkP8/DZ6KOtwK+n3ILu5zw65QeWYa3qyu1wPdM9JCDBOziEL8jLQEsCzTir+jXZsLTHXFKcQQUgAWXRvAZm5CJ6vZmH0DWNy6osRE4y9M/b7QXBz9sX+hfX1981e7QUfIQFTTrWE8UBl1dkLRG4QrQcn5WVnILs7lf0loYzk85tE4vq3md3zSFVzi6jd6ZTUwe9M+x6mgvbxrg1bpMWOUvranel1p4vjZMwtIneo/AkavHB6CkW1Efyg4Dlz2Jbd0XAAT4ip+kBqfTHmEoh6eyAt91HxDgC7bUkowni+bgKcyhwP7peIbCs9n58NdQ/Lz2tvwfq/x0K+DQuHo3McNgeWWfW1GXTGjT0SMFiutzu2VDSqhRmT47hElOT5TIUhzICNuX/9U35lWTGu4jzKCc4o2/4SOalwU9/i7LTUaBxFSMp5U2WSLWh8DYpS8cTGqyVGGvPFJ8h3wUL/VIRqGKAcEaF+5TavPhis8zbP42DsI5vYbtx5wPLEsdviMLzT0S5/iTsSw3IlIYXFw5ZI3yZwq/cwV1+joIotwH/XxhzFHt5TIuCG6f9e7IK+KpIk+Iu+tukJBTFG/vhUWTUz4Qs1+b1zPRDLlEIyYjTMuANo4F/NLxVOSDMeiMVZ4SGpyCQ/vFQ8/HfNJzHv05NOiMnz5P5XHp8WnRsgFUqjuFEBmPwux8pveOuGgsmmSbxX6qx06gLB5CHYCbYRovhYf sQHBS1K8 kCXinhBrOFi1eP9391wB+VJCbX2PkyvG1a3pIu24yiyhIciaEb9Yr0znNRikzFvlGEpLo6tamw1hfi2leVo3VJMIw3YueT+cfnHgiVBeACG5AcWC+jnXFXZt69mgMDEf2s//0n7FH9fHMizUI3lQ9akKW6u0mxWOAlP54 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: List-Subscribe: List-Unsubscribe: The access_error() of vma already checked under per-VMA lock, if it is a bad access, directly handle error, no need to retry with mmap_lock again. In order to release the correct lock, pass the mm_struct into bad_area_access_error(), if mm is NULL, release vma lock, or release mmap_lock. Since the page faut is handled under per-VMA lock, count it as a vma lock event with VMA_LOCK_SUCCESS. Reviewed-by: Suren Baghdasaryan Signed-off-by: Kefeng Wang --- arch/x86/mm/fault.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index a4cc20d0036d..67b18adc75dd 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -866,14 +866,17 @@ bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code, static void __bad_area(struct pt_regs *regs, unsigned long error_code, - unsigned long address, u32 pkey, int si_code) + unsigned long address, struct mm_struct *mm, + struct vm_area_struct *vma, u32 pkey, int si_code) { - struct mm_struct *mm = current->mm; /* * Something tried to access memory that isn't in our memory map.. * Fix it, but check if it's kernel or user first.. */ - mmap_read_unlock(mm); + if (mm) + mmap_read_unlock(mm); + else + vma_end_read(vma); __bad_area_nosemaphore(regs, error_code, address, pkey, si_code); } @@ -897,7 +900,8 @@ static inline bool bad_area_access_from_pkeys(unsigned long error_code, static noinline void bad_area_access_error(struct pt_regs *regs, unsigned long error_code, - unsigned long address, struct vm_area_struct *vma) + unsigned long address, struct mm_struct *mm, + struct vm_area_struct *vma) { /* * This OSPKE check is not strictly necessary at runtime. @@ -927,9 +931,9 @@ bad_area_access_error(struct pt_regs *regs, unsigned long error_code, */ u32 pkey = vma_pkey(vma); - __bad_area(regs, error_code, address, pkey, SEGV_PKUERR); + __bad_area(regs, error_code, address, mm, vma, pkey, SEGV_PKUERR); } else { - __bad_area(regs, error_code, address, 0, SEGV_ACCERR); + __bad_area(regs, error_code, address, mm, vma, 0, SEGV_ACCERR); } } @@ -1357,8 +1361,9 @@ void do_user_addr_fault(struct pt_regs *regs, goto lock_mmap; if (unlikely(access_error(error_code, vma))) { - vma_end_read(vma); - goto lock_mmap; + bad_area_access_error(regs, error_code, address, NULL, vma); + count_vm_vma_lock_event(VMA_LOCK_SUCCESS); + return; } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) @@ -1394,7 +1399,7 @@ void do_user_addr_fault(struct pt_regs *regs, * we can handle it.. */ if (unlikely(access_error(error_code, vma))) { - bad_area_access_error(regs, error_code, address, vma); + bad_area_access_error(regs, error_code, address, mm, vma); return; }