From patchwork Thu Jul 13 09:53:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13311666 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 BCB38C001DC for ; Thu, 13 Jul 2023 09:40:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 183798D000D; Thu, 13 Jul 2023 05:40:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 134EB8D0008; Thu, 13 Jul 2023 05:40:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEF208D000D; Thu, 13 Jul 2023 05:40:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E03398D0008 for ; Thu, 13 Jul 2023 05:40:39 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id ADAB31201BD for ; Thu, 13 Jul 2023 09:40:39 +0000 (UTC) X-FDA: 81006093798.01.3DEDEA5 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf24.hostedemail.com (Postfix) with ESMTP id 2D8A6180019 for ; Thu, 13 Jul 2023 09:40:36 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=smGocFmrYZVxcmC4HyPQleNsFVdy0YNcqxX8ihatQWA=; b=HKHs1eJu7Hzk6kNmhvulfsktO5LQpj+L5Y+LiM4FdU0OGFmt1U0w2u7nIPmbXut54NT+e2 sVwphYpJzy7XqeqtproVedY4w85UFKENxo7QfMWPKh/nIr3SeWJ1rFcxDE2FvynHz/LyOx ULYBi6VWMZlLJYEFVXZOA/ugfYn/4Ks= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=T2mwpN/yf2uSVJWzlCtc5/zTgJmMroYRRoROIoqLpJHFIhe3bhwnPu4qFXtQ3MksyN1t1X cAgnMPf6YNqvehwcaZvtaJsD1MANOPGLF1ylpw0+Nzus0aLmB38n8yWZWvTAfLUTjb6WZH kexUx5nXMtxZbVcEz7xYPYfwMzoY83k= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R1qLv1v51zVjYP; Thu, 13 Jul 2023 17:39:19 +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:32 +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 09/10] loongarch: mm: add access_error() helper Date: Thu, 13 Jul 2023 17:53:37 +0800 Message-ID: <20230713095339.189715-10-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-Rspam-User: X-Stat-Signature: xmbqf4wkzhuu7fmkteqc4h96ucortgw8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2D8A6180019 X-HE-Tag: 1689241236-698654 X-HE-Meta: U2FsdGVkX1/nF+hitJFb49UFP53BfxU2hTjMy5aVIJ4ysk71T/P8xqTHoeU+iIs4hcOyP5BhtNqTDdmkMm/V3zylvIgjcFiX5TbTIVNrjhFMNv4IfOnLpe1DicT+d73vbz0/gbpRLhS13AYE+tSFhGcJG0tVVE2ubMosdYak8Y02+WlEl/rhZH39TQIc6WrI+kMAuQL2q0p2T7KYwBIbDN/VV/f59Wdjn2GAboG9ZrCkn/Hy6mnuojJp+XTPdHhBfcfDHJOUu8QGYodXXJNtHOImy1zzo/4BxYD3eERft3tDm/bBhQvg9gdGd2XlWg9LoZDREVS9pQOrNwxiPzSpaaS7JZ8vndkHRWN4YWK7JqeurcSV3r21a/hYVv6V7jIAwHS4mYZwizP/SfIKZ9eUtEZxJ7I5soihcqPKzkllDbxwOFnShot9ExrBrsuzN0gqqxamVZzoGOQW/u3Ui/9wOHbBLM7dF4ykKtNm6qP+DqdJiWUMMdubh5fDN2Ie0opgD5l5QLhoqKPbcRNhFixZUCjDFlfovg5iu89JQ4DOvHhoYJ6Xi/pm1mPyYlZqmQQPv1EtN4e/TL9IWiiipcWphraPHbJYykmmZQCYHBzdpxNZRI3Wqy1j7om6fwSadvzZ8L3kCuLeT6xQCJSfBbupgBfhtz0QaGIleWH0L72dEzqyBGDrkjVgLN0xDbtOm1udBVGIfkvlXq6O0bs1T122yT9vyDewMEJ2HhvWCfdgrpMBF0y+qmB7vz4ZblzIiZA0xjTCAe43qMBJW1Few6ZgijRpqIP4QhhZV1V27FRA02KmAaE5FQjkNu4barrCkGEBbHSKEVnJx4WmtmONzQdYtZcsr7PGB/S8pH78QUox2Xd66ww46JHyZ1t1p+P039oTtX+KNdbUdPFQY0piKtCHL2ZYAaWGbohYDnD/26iWeAU1TWIWdmXCqb7ONc3+v+j8NN3LbWmJJYoQb18Y4ei 0nE4MfhK byTa5Y2Kd52g/l3eGLmPALYUB6zBazD9K84b49Ad8ivYIxqaxdATD9hR0+BkvUUsRks5JsQIXzkq95p4po2F4PiUOwaNLpzDXlFYwIWXpOLq9V0yHpdOf5IcK2DtgkfqFPnj1wJVXO/9g3Ji1NRtGby17yBTKdQB6+5v3a2eUscLIFL9yV+5urGArIoWtUdsdlMew 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: Add access_error() to check whether vma could be accessible or not, which will be used __do_page_fault() and later vma locked based page fault. Signed-off-by: Kefeng Wang --- arch/loongarch/mm/fault.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c index 03d06ee184da..cde2ea0119fa 100644 --- a/arch/loongarch/mm/fault.c +++ b/arch/loongarch/mm/fault.c @@ -120,6 +120,22 @@ static void __kprobes do_sigsegv(struct pt_regs *regs, force_sig_fault(SIGSEGV, si_code, (void __user *)address); } +static inline bool access_error(unsigned int flags, struct pt_regs *regs, + unsigned long addr, struct vm_area_struct *vma) +{ + if (flags & FAULT_FLAG_WRITE) { + if (!(vma->vm_flags & VM_WRITE)) + return true; + } else { + if (!(vma->vm_flags & VM_READ) && addr != exception_era(regs)) + return true; + if (!(vma->vm_flags & VM_EXEC) && addr == exception_era(regs)) + return true; + } + + return false; +} + /* * This routine handles page faults. It determines the address, * and the problem, and then passes it off to one of the appropriate @@ -163,6 +179,8 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, if (user_mode(regs)) flags |= FAULT_FLAG_USER; + if (write) + flags |= FAULT_FLAG_WRITE; perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); retry: @@ -172,16 +190,8 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, si_code = SEGV_ACCERR; - if (write) { - flags |= FAULT_FLAG_WRITE; - if (!(vma->vm_flags & VM_WRITE)) - goto bad_area; - } else { - if (!(vma->vm_flags & VM_READ) && address != exception_era(regs)) - goto bad_area; - if (!(vma->vm_flags & VM_EXEC) && address == exception_era(regs)) - goto bad_area; - } + if (access_error(flags, regs, vma)) + goto bad_area; /* * If for any reason at all we couldn't handle the fault,