From patchwork Thu Jul 13 09:53:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13311665 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 F3EB0C001E0 for ; Thu, 13 Jul 2023 09:40:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83B0E8D000C; Thu, 13 Jul 2023 05:40:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E9CA8D0008; Thu, 13 Jul 2023 05:40:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68B0A8D000C; Thu, 13 Jul 2023 05:40:39 -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 50AD98D0008 for ; Thu, 13 Jul 2023 05:40:39 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1AA5F120194 for ; Thu, 13 Jul 2023 09:40:39 +0000 (UTC) X-FDA: 81006093798.05.E65856B Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf11.hostedemail.com (Postfix) with ESMTP id 920C64001B for ; Thu, 13 Jul 2023 09:40:36 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1689241237; 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=58o4MR5l0Nei2gEa3JbIAdGHk1zCv0Ec6/i0uRr1oCU=; b=W30LoIfRYj9C9BLiXwoFURXn5ste3MMmkEjY/WBdDWW3+fJOIa9Wb4yjiJ+0JHe28ixaGV ir6nBfIvAw5bE4qnuye/bWybCVETGJRTJnGYBdGqzzYcfIyDtRgrTHC2wq6chCUv3cSgnn em+MpzR/YVM9K0BXRe2c2tA7w9uAOzA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689241237; a=rsa-sha256; cv=none; b=3se6zbT9A6sOpMxE8kka5dI2xgtyTQ2qyj7vI4kSC0TwjVNWHNJRIkq2P/ktLizoQBVe4E m60rdE4Q3ZrxDhm0M+nvsp8EVMfdMyYbLVCxYRL/XeDt2dvNeCRBCWqOq8729vutHeSQiu Lq7naMPyvD+NSe9uj/0SFUdMc1YtpgI= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4R1qMc4wfvz18Lt7; Thu, 13 Jul 2023 17:39:56 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 13 Jul 2023 17:40:31 +0800 From: Kefeng Wang To: , Andrew Morton , CC: Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , , , , , , , , Kefeng Wang Subject: [PATCH rfc -next 08/10] loongarch: mm: cleanup __do_page_fault() Date: Thu, 13 Jul 2023 17:53:36 +0800 Message-ID: <20230713095339.189715-9-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713095339.189715-1-wangkefeng.wang@huawei.com> References: <20230713095339.189715-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 920C64001B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 384zxy5momwz7mcksmd846pzpb3i7nnx X-HE-Tag: 1689241236-589738 X-HE-Meta: U2FsdGVkX1+bFGd62XL5Oxbxb0qmadHuAoZkQ8HKeT9VHeINLbDriFfJS0fiZQXRCWaXiZyZ3LfMKSzbn33rgMjGcYrxjela5OPfveRX6BLR1ikXC4hpXKepz7E44bf6j2gy0pxkU8wAFD8d1PK6V9DR/6wpguSshjhnOLcXQZXiNrxxtMxxMNrxRHhi5+nLRctUTT58lIkD9uB/xooigqqlDyOp6qFhYSkcq4KJJQU7VxFt6ZaB90Ay4l3rwGFlClKkpda5DsMtGrkKdAHqCyig200k9xbt1RUxcT5HtqkUAaW2zsd4Tfz/3Znbf6MZdemiTm+haYeqKwJ2wYP0v3YTD9XCZSbTY2nihah0S1jNpKpAyrL0AeaVqkCSTKcIwoW8z1q1RQjkRZIe/SGT+XCtCvkg27wO/+G8qzmF+zxSer9EUnjnyz8tNBTYqCzXdxxPWWL8hgJsJfP+Xf6jUTjEDYIzPSmsrxp5+b4PZVgWmcvxq1IIkQoOIX8Gq5tRufHFKZRdCgpNVAA4b9k92Ts4d2zxovwiNB6qnci1nL6AVZmi5BjcqFg+cS46Fxn1xiLsmMXfhER7xUnKffADrJTLdpWdl25sPuCoC5jRXm4lyAVkG38tAlu9zs+2618TAKOxJ8r18Il9/0Lmkzv2h5ghKYJzWK4/wQTdg95MUz6MRdUFWB6KBO36f7VT/lLggfqEfN+S4fIK4XKrsjvh6Ja2Cz9NASYgtf174cNec068GBkCtUy99oisx6xVBdM088DqVIeNtxEctPMBj7H0AfIEc9xoznZ23s1v/0x9wXrFRippu68iybdJNc779nzJDrpcjLLDvXumtijwzviJgYKJIqWppA3tuf4SE6EFlQfoulKiLarB5GJnm/QzJq3Ha6ubHfqR/aJ5VkJVNl+tWWBwlyQynkwrvkSj7a1VUxMcRq0yEweCKMRmJLu7x2cbYYK2cj/CF67JPvLkCww rvl4Ssub VmnNiY2cqXL7OdFVteU7i/523u9TzM6in1xtY3DD3+uWdheJQ+gqWW4KK/TWZjTux6TPm9KykE8EBkEkSWme5xqD/jeIm0OQ5hKgcYzM3ycSb9SGuesSbfTAUSjmSJeDB8B4KqQLULE5aesCpQjNdJTNOu1Tr6Q1FpwvycsExmUYhTX5MUbqrKhx+83SvWzn2xX7B 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: Cleanup __do_page_fault() by reuse bad_area_nosemaphore and bad_area label. Signed-off-by: Kefeng Wang --- arch/loongarch/mm/fault.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c index da5b6d518cdb..03d06ee184da 100644 --- a/arch/loongarch/mm/fault.c +++ b/arch/loongarch/mm/fault.c @@ -151,18 +151,15 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, if (!user_mode(regs)) no_context(regs, address); else - do_sigsegv(regs, write, address, si_code); - return; + goto bad_area_nosemaphore; } /* * If we're in an interrupt or have no user * context, we must not take the fault.. */ - if (faulthandler_disabled() || !mm) { - do_sigsegv(regs, write, address, si_code); - return; - } + if (faulthandler_disabled() || !mm) + goto bad_area_nosemaphore; if (user_mode(regs)) flags |= FAULT_FLAG_USER; @@ -172,23 +169,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, vma = lock_mm_and_find_vma(mm, address, regs); if (unlikely(!vma)) goto bad_area_nosemaphore; - goto good_area; - -/* - * Something tried to access memory that isn't in our memory map.. - * Fix it, but check if it's kernel or user first.. - */ -bad_area: - mmap_read_unlock(mm); -bad_area_nosemaphore: - do_sigsegv(regs, write, address, si_code); - return; -/* - * Ok, we have a good vm_area for this memory access, so - * we can handle it.. - */ -good_area: si_code = SEGV_ACCERR; if (write) { @@ -229,14 +210,15 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, */ goto retry; } + + mmap_read_unlock(mm); + if (unlikely(fault & VM_FAULT_ERROR)) { - mmap_read_unlock(mm); if (fault & VM_FAULT_OOM) { do_out_of_memory(regs, address); return; } else if (fault & VM_FAULT_SIGSEGV) { - do_sigsegv(regs, write, address, si_code); - return; + goto bad_area_nosemaphore; } else if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) { do_sigbus(regs, write, address, si_code); return; @@ -244,7 +226,11 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, BUG(); } + return; +bad_area: mmap_read_unlock(mm); +bad_area_nosemaphore: + do_sigsegv(regs, write, address, si_code); } asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,