Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp475944pxj; Thu, 10 Jun 2021 05:32:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzthzQqOfjQrG1L3EdaJPO+m87SZ40e7K7w6RUZkFXWuWkHqR/FtsGE8cPQqP+ifrm8xvzT X-Received: by 2002:a17:906:1d0a:: with SMTP id n10mr4235201ejh.341.1623328339446; Thu, 10 Jun 2021 05:32:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623328339; cv=none; d=google.com; s=arc-20160816; b=x8A1zFhS0bKppNR+EqRMVSNMVZTpIu6M0o21dBhnSmYBcllronP7ZHN7wjqMfCGAap gnA0F6L3oNyzSs/1IKYqvbs/MvyShSG4XswfBK1EzGerx5Qr1VZQfzyOlPJ+YW8dp8NU KkEVa51v4qsKaIRFe+zeG666nYP78tMKTWNy2fUeM24WC74FGvowQy27iS3A7sYKEx2n BhYoYcKAsXUMKfkDd3F4Uh5oSWC1ASaK1BYuEDcUxsUICTtfg0t39/RBq66Jx82ewu+P J5RZb9hMOAQTygXULWG5ZJafnK0sQWn9xk9NmBjv9os8+OMEd9Qs1LLHdU9tWAUpg7Z2 iv6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=S3QpcjLdI+v9frgfqrSTR4ispBOSD7WrDM3vBab2iOQ=; b=oIAKwtVn2ZwAN5Vb4Vc/JsH634nC1Mm/siZTTOsmmrjBhbecbcy3IuDoLlDSqkF/Wo deSuUOEduAshOauRoNQl3DtPwjGwKwmThnBsdEcGPTPaFcBSS0J+MDAPce8F/eOy9SBM tkQf93BKtHG0+PO9WMdfHnVKU/hapibSoHqYce3uHI35pK3hss0tvNMSyoDQJl+4aOxp F0m2PhvqtlWp5WdecLjizrDX6iJ9+rQi5+mwWhZt+La1yuFi2LdC3QKTUCltjMYMveHX AJ21nTWGrdUM4jD2oyWFmbDvMkIfbquDNDhtMAFqgaiIOevcwq1w4tNSXeBXHMI/ASUQ mubw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f2si1742840edt.405.2021.06.10.05.31.56; Thu, 10 Jun 2021 05:32:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbhFJM3m (ORCPT + 99 others); Thu, 10 Jun 2021 08:29:42 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:5324 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230346AbhFJM3O (ORCPT ); Thu, 10 Jun 2021 08:29:14 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4G135C1VKMz1BL5B; Thu, 10 Jun 2021 20:22:23 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 10 Jun 2021 20:27:16 +0800 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.2176.2; Thu, 10 Jun 2021 20:27:10 +0800 From: Kefeng Wang To: Russell King , CC: Catalin Marinas , , Andrew Morton , Jungseung Lee , Will Deacon , Kefeng Wang Subject: [PATCH v3 3/6] ARM: mm: Cleanup access_error() Date: Thu, 10 Jun 2021 20:35:53 +0800 Message-ID: <20210610123556.171328-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210610123556.171328-1-wangkefeng.wang@huawei.com> References: <20210610123556.171328-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now the write fault check in do_page_fault() and access_error() twice, we can cleanup access_error(), and make the fault check and vma flags set into do_page_fault() directly, then pass the vma flags to __do_page_fault. No functional change. Signed-off-by: Kefeng Wang --- arch/arm/mm/fault.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 249db395bdf0..9a6d74f6ea1d 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -183,26 +183,9 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs) #define VM_FAULT_BADMAP 0x010000 #define VM_FAULT_BADACCESS 0x020000 -/* - * Check that the permissions on the VMA allow for the fault which occurred. - * If we encountered a write fault, we must have write permission, otherwise - * we allow any permission. - */ -static inline bool access_error(unsigned int fsr, struct vm_area_struct *vma) -{ - unsigned int mask = VM_ACCESS_FLAGS; - - if ((fsr & FSR_WRITE) && !(fsr & FSR_CM)) - mask = VM_WRITE; - if (fsr & FSR_LNX_PF) - mask = VM_EXEC; - - return vma->vm_flags & mask ? false : true; -} - static vm_fault_t __kprobes -__do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, - unsigned int flags, struct pt_regs *regs) +__do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int flags, + unsigned long vma_flags, struct pt_regs *regs) { struct vm_area_struct *vma = find_vma(mm, addr); if (unlikely(!vma)) @@ -218,10 +201,10 @@ __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, } /* - * Ok, we have a good vm_area for this - * memory access, so we can handle it. + * ok, we have a good vm_area for this memory access, check the + * permissions on the VMA allow for the fault which occurred. */ - if (access_error(fsr, vma)) + if (!(vma->vm_flags & vma_flags)) return VM_FAULT_BADACCESS; return handle_mm_fault(vma, addr & PAGE_MASK, flags, regs); @@ -234,6 +217,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) int sig, code; vm_fault_t fault; unsigned int flags = FAULT_FLAG_DEFAULT; + unsigned long vm_flags = VM_ACCESS_FLAGS; if (kprobe_page_fault(regs, fsr)) return 0; @@ -252,8 +236,14 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) if (user_mode(regs)) flags |= FAULT_FLAG_USER; - if ((fsr & FSR_WRITE) && !(fsr & FSR_CM)) + + if ((fsr & FSR_WRITE) && !(fsr & FSR_CM)) { flags |= FAULT_FLAG_WRITE; + vm_flags = VM_WRITE; + } + + if (fsr & FSR_LNX_PF) + vm_flags = VM_EXEC; perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); @@ -281,7 +271,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) #endif } - fault = __do_page_fault(mm, addr, fsr, flags, regs); + fault = __do_page_fault(mm, addr, flags, vm_flags, regs); /* If we need to retry but a fatal signal is pending, handle the * signal first. We do not need to release the mmap_lock because -- 2.26.2