From patchwork Mon Aug 21 12:30:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13359379 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 5405FEE49AC for ; Mon, 21 Aug 2023 12:31:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30DA48D0015; Mon, 21 Aug 2023 08:31:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26FF48D0002; Mon, 21 Aug 2023 08:31:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1108B8D0015; Mon, 21 Aug 2023 08:31:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E98DF8D0002 for ; Mon, 21 Aug 2023 08:31:37 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BD53640410 for ; Mon, 21 Aug 2023 12:31:37 +0000 (UTC) X-FDA: 81148047834.16.120D3A5 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf30.hostedemail.com (Postfix) with ESMTP id 5BCF480021 for ; Mon, 21 Aug 2023 12:31:31 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf30.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=1692621095; 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=gIldAat6PTqp0m0qcFfSiDczJB9xcWWS8CD3qklnWTo=; b=YXaIiCdxbnpjxpNlmMpbVf4n20yNnhf1TdxpUavuqPhR5O25GtFURYPchY08Uh70dwhkMb cngRotRVJtXwvkdOZHq+CO9+ylZgcEwzMARyQ8UueR3H8izKHoPoRPp3ZG/2LmynE7TXEB IrB4UUSQtkHf/Q1io8yXJ0W0VgW/Lk4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf30.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=1692621095; a=rsa-sha256; cv=none; b=qoQXJwHoH7mJ0L6RMBFvr4tu4o1AQYVh5e7hU987JM2IZcYRn9sys1NQs2ONedWbgM/MZY l3Pu1qs2SwDiS8ABp3j21M616nx7le35vbJOagPWosB6yLk/HMMu+x9Ee9amnCSwpvibhr LHYIUuKktDV3636Tq17Z7bMZWJQmmiE= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RTsGv1szHzVksj; Mon, 21 Aug 2023 20:29:11 +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:23 +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 09/10] loongarch: mm: add access_error() helper Date: Mon, 21 Aug 2023 20:30:55 +0800 Message-ID: <20230821123056.2109942-10-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: 5BCF480021 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 353thj9pa3ydmmdj3nfeg1ubfkreuwnm X-HE-Tag: 1692621091-229924 X-HE-Meta: U2FsdGVkX1/lcPXSoGyZYMBAzoK8ZRoXk25gXpTpceJCyPv4RqlDBfcx9+65Kc0DLH9oJOTTRB7qRA0gSEInhmEcE5td6zw/Zet33TkB052OiYLkJyhz4JSmurbv8co8JOjV7hSQvPHFsUX5SPH3iowsH8WYnyqVH8LMp+3XNnOKpkMG+udKXTg3eqAXQBGhKMMGjnQTPkmjdoRxxGFPIcN7mdfCKJH3WjLx5QTEQ8ufwKy0oWXztqm+LQZp02ejBTi4MQ3rY6XWtC8kowLo+fkO82v6HpJjyQnVJ89Yg4URbgeR4/k4cEEib2vKeg72sdyKgkoU0lYvWkOmEFuVhSxRZ3sMs1iAlQqWncXZWj8gZmMKRYsPgGnDWza+2fCwAb/q8LlmDhArLSOkQ1OF0pC0iRTsCaJuhsoJgafI8YUGWMcQBNLzI3i0xfADet9caOquOXHBdPj+/dR/4qaU/nL94r2FogIg8zR+K2X2hIFF7Y5uSFUXtT1a7y0PRw1gn1l0iytXXFC03uBdq8jC9HEy+qy5VJFDmr7Tp7120cEMkQxbgJos/2oCzi14ShzBnjEFNoatXcCbj1DmuyBHnXrvLKdkLGAsn+2PbyKJKXPg2iKDmTDa/MJtlmAiEw+FnqtwRcMhYQIVAzJtR8VQG7j2YT3dAZLjqA7e3kDErJNppNx7T6UesEQOcqSrObwlx9XlhEcUKgAa1ZkG4V+7KkWIUcSl/hOfr3yOD5BR6esDHveesadoREk0l6QeW776IGAlf/HnEShFyoOE5EtFVittTSK1tODbtXuEEswYGw/wYBfFcqhkQ88GEyRW65CEZd8njhUlve5vfyawiEXevdN5wvrzKKcyp21UInQ6UKSNk/21f9QPmS30aDXYbsXuYpDo0o/I7J6yLl0+b/KyOHUo106Ft5S4UZPZOMsx+LPMteEKbZpclerkS7BUK9EeI6wva+mN1x4L81iVQaA 3VJTJIrU Zv1SsqWQXM+ybgRgSovjBq+KyxEPWmq1lzrPvVZKmPsdpBE++oeOEoVFRW41WfT1x2iWvzjT8E6EP3iIzREKfeWuckbTpjjZoSFn7oSeTUQ5hL+3wouT5RucUZXEVyj5X8kmF0tzYd8BXDdtknxAvbU5ihjkTyFOubE1q6sEynS2dVqsfyZQ+bbM4/DVAR1QQjxoI 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 5d4c742c4bc5..2a45e9f3a485 100644 --- a/arch/loongarch/mm/fault.c +++ b/arch/loongarch/mm/fault.c @@ -126,6 +126,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 @@ -169,6 +185,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: @@ -178,16 +196,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,