From patchwork Mon Aug 21 12:30:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13359375 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 66448EE4996 for ; Mon, 21 Aug 2023 12:31:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D9038D0011; Mon, 21 Aug 2023 08:31:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 888DD8D0002; Mon, 21 Aug 2023 08:31:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7518A8D0011; Mon, 21 Aug 2023 08:31:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 62A688D0002 for ; Mon, 21 Aug 2023 08:31:29 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3677F1A0B77 for ; Mon, 21 Aug 2023 12:31:29 +0000 (UTC) X-FDA: 81148047498.04.7CD8717 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf15.hostedemail.com (Postfix) with ESMTP id 12AA6A000F for ; Mon, 21 Aug 2023 12:31:25 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692621087; 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=0BPre1mji4iNkocWD89whAC0rMq3U6GyUcT+h0WZYyY=; b=kPIcK50NJIxoNnN+rr9ijU83SAFSW31BMiSYaUSoCzQZTovM76TkP5lDFPaNYQH4KzO1E6 oGPjxNsPp1kq8ZkFalLz6sEdtyl1LaEOi7DD3xGwHNTMSdBHWvb8KQAQ8KtC4JEYr2L4d0 f8uiczSHNvGZFHu/gLLOctCJgRlJVpQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692621087; a=rsa-sha256; cv=none; b=olJIYnvDaFTdMAAM57hphsUWHdMOijV/rcX1luj98erBZGCgc62O2J7u7ewsRtm3LxwerJ RzW66N7cPEwYGTHX1ZWABhqil8HjzcL6QpjqMNljONQWXbPHTVzDaZc19Lt8PYBtLADjlX xVAtnyAsWMk4+m1qwdS+PKJWkF6NDz0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RTsGs73pWzVks8; Mon, 21 Aug 2023 20:29:09 +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_128_GCM_SHA256) id 15.1.2507.31; Mon, 21 Aug 2023 20:31:21 +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 , , "H . Peter Anvin" , , , , , , , Kefeng Wang Subject: [PATCH rfc v2 08/10] loongarch: mm: cleanup __do_page_fault() Date: Mon, 21 Aug 2023 20:30:54 +0800 Message-ID: <20230821123056.2109942-9-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230821123056.2109942-1-wangkefeng.wang@huawei.com> References: <20230821123056.2109942-1-wangkefeng.wang@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 dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 12AA6A000F X-Rspam-User: X-Stat-Signature: 7umftuy9xuf3ejhmy85brrtaryaen54e X-Rspamd-Server: rspam03 X-HE-Tag: 1692621085-253481 X-HE-Meta: U2FsdGVkX1933hSpYFWDKPUzL73aYDRPYP8VpTlE8tJ9XddFAVcKilCE5S7QJuFiAOW66ouhEb1Xh7rNM2lvhZMT1KbBIBnH1dG7XJlZxJeGrW9RjITLWr78dcA0ZlXX23vsCHC7+d9s/CSlCN/hWbAKNuSn5yxQ4rizmxVn9KeJo1LJ4b6eN198Oe3I7upmVonAyHJdB74uUAXwKxr5Q6gpyvNUjTq6uUcn8PFVVT6/XAXxqWvufnExXis6Z9KDe28fJ7Y9vNx6yX3knu0A4LdFPVaj+1/6fo/OkRtj7nG9lq/2521PMYeaarefeDSIAx+j6xI22BM8f26bjtx6T744BkbQWv867MNa9KgXIr94L4kvsVIkAaLyAwolBYHi2cFbuQeVS9lDXv4u+otTcrRLKEmgnj6pfc/4SW5hZjqzBvlgY8QyZ08SzkqFl9OgqdT0dwHHzDLOvPH76aTZwhZry50aV9sItMaZhMab6CMmDkCz+Jgm7xBLzt6gjqoub/xtRzGHw6J9RH+iifOpj/UBfvTP52gi9aRL7dQYaWZZUtw2VIfSqZIMAw5eJg1ks8N1wK4+RLR3pDy4CfrQy/sxznTFsA3CL7ut9IYQX5k7p3Aqn10AnvAXr4rZl4dhpNjnvwpdZDVH5v+RhBTmO28hSyc+SEJzbxsmN3Y7MUNa33PFtaL6JxbW4dTHkH9Si8zaYU0KgDKL4Bz8GVSbbTnL2voJTZP9an0TJdwNVJrj8Ufdc0Zui/dxZpvo3109rgjO6zSbuySP9HciZkZgJDDmw4bGnPMbxn5zr3acpxJ7YrFFpsAqA6QA4jIx16Uw60BOqOOG+0l1eV4ZodORztG82dlwCarbCkJiY1KAugTc1YQcZsHuihYLH0FMbCzNzeCzmYfUEFxdHpNAJHvBn9J/DVpFto/6ZXtHqH0BV2oZKVTZ/Tqcz/GYGjpwsBWJDtLyZqSXMWP3QN5RZge lFisbHyU 110WAIyS125oF6afB9+2ZI3dYBN+J2jkjFLZOP88Pma9NZpg4DAVQqE3CayGdreDYDfv7Gz1jjZBud225FVhcnbxJXHd2VCFP6N3OX0Qb6KBSg4fqiO9LOvghpP3oUxEnJqXHfYV2xQnlaUG4O5F8uWEjyxaC6S02W21XOf8c6wG5yQXwzx1i/tIpnIbmjDXyCsDS/LysA1U8K1M= 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 | 48 +++++++++++++-------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c index e6376e3dce86..5d4c742c4bc5 100644 --- a/arch/loongarch/mm/fault.c +++ b/arch/loongarch/mm/fault.c @@ -157,18 +157,15 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, if (!user_mode(regs)) no_context(regs, write, 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; @@ -178,23 +175,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) { @@ -235,22 +216,25 @@ 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) { + if (fault & VM_FAULT_OOM) do_out_of_memory(regs, write, address); - return; - } else if (fault & VM_FAULT_SIGSEGV) { - do_sigsegv(regs, write, address, si_code); - return; - } else if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) { + else if (fault & VM_FAULT_SIGSEGV) + 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; - } - BUG(); + else + 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,