From patchwork Sun Apr 7 08:12:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13620044 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 423B7CD1292 for ; Sun, 7 Apr 2024 08:12:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BA116B0093; Sun, 7 Apr 2024 04:12:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AECB6B0096; Sun, 7 Apr 2024 04:12:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68C416B009B; Sun, 7 Apr 2024 04:12:26 -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 435296B0096 for ; Sun, 7 Apr 2024 04:12:26 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0609E1608CC for ; Sun, 7 Apr 2024 08:12:26 +0000 (UTC) X-FDA: 81982018692.09.40B4F3D Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf05.hostedemail.com (Postfix) with ESMTP id 59C35100011 for ; Sun, 7 Apr 2024 08:12:22 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 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=1712477544; 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=ULNBkPgbSEHebVTZpMnjhm/VZsW9ZzTVVDCMVJEkNg0=; b=WK2XvD+pjP5bUr+Gb7VRjjHVYzK9BIXvXz0CM1HkMjYMpIleHpEy16Lyyv/1Bjv2HuyHHU sHoh+KvWdR915bqGRsh7h3TeXsBHHpFYNvHnIm71M0AOUcAWHvR+lhqnzaWG7br1RXqm2e t2j7sJFlecRcUgaToxY6kLRcOQ99vnU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712477544; a=rsa-sha256; cv=none; b=1KcM+bF8eWagL/iMHB34yKHrxiqW6PX63wq69Qv8WEYzTGEr/n/dZBaKLtIrykA/WkPAdl PY8y8hYciZZMOtcfCu/Y3Z6QrQuQeKLgUloOTfY3wFzcGGC5Q8dzv1CjTBFCYYwqfWhgWj ktJ/rbfZYWxS3nRca5okENXdTXZXhL4= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4VC4dq2PdDz1ymJp; Sun, 7 Apr 2024 16:10:07 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id A06811400D3; Sun, 7 Apr 2024 16:12:19 +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; Sun, 7 Apr 2024 16:12:19 +0800 From: Kefeng Wang To: Andrew Morton , Russell King , Catalin Marinas , Will Deacon CC: , , Kefeng Wang Subject: [PATCH 1/2] arm64: mm: drop VM_FAULT_BADMAP/VM_FAULT_BADACCESS Date: Sun, 7 Apr 2024 16:12:10 +0800 Message-ID: <20240407081211.2292362-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240407081211.2292362-1-wangkefeng.wang@huawei.com> References: <20240407081211.2292362-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Queue-Id: 59C35100011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6fo14dk3bt8ech1zd54f51a1wifqqx93 X-HE-Tag: 1712477542-996464 X-HE-Meta: U2FsdGVkX18w6UYVfQmVL0OPjT/zyn9V8BKJ7BJcMmZ/Yk12TgXLVMLB4vi2akmLqXTJP65KKotQk6pxqrCTr7sSIf7FXfXhZ7JkBNYrr3YwEjNHHFbfBPJr7rJytvdh/iCUHxYn3H0Bn/4KNTpgqFAwCa2/L7796Jqkaga5rZA4aDPta88UgxQrM680dhQ/I05/b//q82HKpMvqmkKlrOWgJN0tJ1shYDP0fNQk0u05XyJxdwtlICmMgfjvTZA/zOJCzckbF3rWvwFSidG3Td4xnFh6vsgaLyP/biljBqavmIoh2fpQ7IXekz6NLfHu1wtf0vjNY0Oe1INhDNDKPCVF38A8kqEBec59wrjED9qrN9UZ3pKEbJOQDQi684KUjGE9ENQ/e3fjbRtxLTpTemoYPLmu8AbESzJVWHdK46lOOtIGTo7RaFhW6vsV52b639ZFSyxuZrRW01HBAoZPGzXML49T9uiKvfkjQnFOjWpG3RASOQtjiNV1KzhzJDx2S+Kqf+/3OpQZoqtvKQjLboFermAlyIZpAYu/26+G7HyyGcqkF1gTpfNpLkYgXbMBPPfZ/KI/Y5wES9AepS5J5Eb+xzfkMW2+6i+WXiTVIP2vWI9tKS7bfyEUntgGCCgo6/ZWDoLQmicylByAA9u8y5PJ7MZqCt/vbL4EXRNI6yn9sZFY7YB0S1PONLX5Zs0OUUM4Coq8eQ9nLvFUR73LMHxxRjpjTzMpoKtI5Ec28OkWqFTk6AYFG3hlOuZR4qrPIjp25HFhkHvtSTRYvQCQ8+E8q2quyeGq3ym4y5oDA7C9gUUH2HLIiSc1ZH6F+2mXUOroCFd1HYTPCT+isUQTMYqf2jHJANtl7Qz9D4K2VFCFPruePUyRtHQo3eXxWCHQticD554XWBgmhbmhddnVwaVo4AiAnnVX0BK0kdwFMnuS/Uh+vbDcCEyZOa+1KQ3YQGQGi1r8ZJTCQXKcOkc KKmHFbe6 vRKqBsGE3SUM/9Tenvi5G/nTYmJr2pytb/m4jxs02UZg38+u7TgdBWFZt+IBeKjMZP9whhQirMTGRIo8n2mFC8yU+TjMiQIZJRSKn8VCu0fN3j8CNcp+IfSBxLWE0N0yTFobnIqC6UcBmZw1L1hVASMsnbfTWbMCk6VMRhMkBx1ONplvWxr7lDc/3Hmh+fX/fQk2v 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: If bad map or access, directly set si_code to SEGV_MAPRR or SEGV_ACCERR, also set fault to 0 and goto error handling, which make us to drop the arch's special vm fault reason. Signed-off-by: Kefeng Wang --- arch/arm64/mm/fault.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 405f9aa831bd..61a2acae0dca 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -500,9 +500,6 @@ static bool is_write_abort(unsigned long esr) return (esr & ESR_ELx_WNR) && !(esr & ESR_ELx_CM); } -#define VM_FAULT_BADMAP ((__force vm_fault_t)0x010000) -#define VM_FAULT_BADACCESS ((__force vm_fault_t)0x020000) - static int __kprobes do_page_fault(unsigned long far, unsigned long esr, struct pt_regs *regs) { @@ -513,6 +510,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, unsigned int mm_flags = FAULT_FLAG_DEFAULT; unsigned long addr = untagged_addr(far); struct vm_area_struct *vma; + int si_code; if (kprobe_page_fault(regs, esr)) return 0; @@ -572,9 +570,10 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, if (!(vma->vm_flags & vm_flags)) { vma_end_read(vma); - fault = VM_FAULT_BADACCESS; + fault = 0; + si_code = SEGV_ACCERR; count_vm_vma_lock_event(VMA_LOCK_SUCCESS); - goto done; + goto bad_area; } fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs); if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) @@ -599,15 +598,18 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, retry: vma = lock_mm_and_find_vma(mm, addr, regs); if (unlikely(!vma)) { - fault = VM_FAULT_BADMAP; - goto done; + fault = 0; + si_code = SEGV_MAPERR; + goto bad_area; } - if (!(vma->vm_flags & vm_flags)) - fault = VM_FAULT_BADACCESS; - else - fault = handle_mm_fault(vma, addr, mm_flags, regs); + if (!(vma->vm_flags & vm_flags)) { + fault = 0; + si_code = SEGV_ACCERR; + goto bad_area; + } + fault = handle_mm_fault(vma, addr, mm_flags, regs); /* Quick path to respond to signals */ if (fault_signal_pending(fault, regs)) { if (!user_mode(regs)) @@ -626,13 +628,11 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, mmap_read_unlock(mm); done: - /* - * Handle the "normal" (no error) case first. - */ - if (likely(!(fault & (VM_FAULT_ERROR | VM_FAULT_BADMAP | - VM_FAULT_BADACCESS)))) + /* Handle the "normal" (no error) case first. */ + if (likely(!(fault & VM_FAULT_ERROR))) return 0; +bad_area: /* * If we are in kernel mode at this point, we have no context to * handle this fault with. @@ -667,13 +667,8 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, arm64_force_sig_mceerr(BUS_MCEERR_AR, far, lsb, inf->name); } else { - /* - * Something tried to access memory that isn't in our memory - * map. - */ - arm64_force_sig_fault(SIGSEGV, - fault == VM_FAULT_BADACCESS ? SEGV_ACCERR : SEGV_MAPERR, - far, inf->name); + /* Something tried to access memory that out of memory map */ + arm64_force_sig_fault(SIGSEGV, si_code, far, inf->name); } return 0;