From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E191ACD1284 for ; Tue, 9 Apr 2024 14:29:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=it7lOX6k5+LJw+AVOsHTuZk8YCjPRxedFTl9/HRVrVU=; b=agV8zzmj6WUfXo yUzwjrX6UVXzlyKD+NDRZCMTifG1qfdfz0nJ1z/mvLC5mWLCmkUWLhVM80UpMIwtFicOa/JGHnwoR /27ZlhCUaNPwgKEGhoxaWsyIAG5E9YaqSAdc/9fUw8GRRoT5Uhby6Wr77u3oazUo5hvUy18mK1vX2 zhV9OyxItbSsFvrzPM4uMroTjA2hR6RR4vjlkmdkuGE9Gk7nmZHXRhmG0TOMHuhOo/2ZDhVvzCpEh wKupbS/0Bgi9IBRRP5iU/OTl2Wevf9JSKInZ1gYWLdUqbHWi0uw53X7a4VwucosHPGfTz8YLL+sSj JFRh9Dcgs9z+I+3Hpx6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruCT7-00000002Q0a-0I8J; Tue, 09 Apr 2024 14:29:01 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruCT3-00000002PyT-23Id for linux-arm-kernel@lists.infradead.org; Tue, 09 Apr 2024 14:28:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 4F752CE11BD; Tue, 9 Apr 2024 14:28:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42475C433F1; Tue, 9 Apr 2024 14:28:51 +0000 (UTC) Date: Tue, 9 Apr 2024 15:28:44 +0100 From: Catalin Marinas To: Kefeng Wang Cc: Andrew Morton , Russell King , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: Re: [PATCH 1/2] arm64: mm: drop VM_FAULT_BADMAP/VM_FAULT_BADACCESS Message-ID: References: <20240407081211.2292362-1-wangkefeng.wang@huawei.com> <20240407081211.2292362-2-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240407081211.2292362-2-wangkefeng.wang@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240409_072857_912093_DA148CB0 X-CRM114-Status: GOOD ( 25.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Kefeng, On Sun, Apr 07, 2024 at 04:12:10PM +0800, Kefeng Wang wrote: > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c > index 405f9aa831bd..61a2acae0dca 100644 > --- a/arch/arm64/mm/fault.c > +++ b/arch/arm64/mm/fault.c > @@ -500,9 +500,6 @@ static bool is_write_abort(unsigned long esr) > return (esr & ESR_ELx_WNR) && !(esr & ESR_ELx_CM); > } > > -#define VM_FAULT_BADMAP ((__force vm_fault_t)0x010000) > -#define VM_FAULT_BADACCESS ((__force vm_fault_t)0x020000) > - > static int __kprobes do_page_fault(unsigned long far, unsigned long esr, > struct pt_regs *regs) > { > @@ -513,6 +510,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, > unsigned int mm_flags = FAULT_FLAG_DEFAULT; > unsigned long addr = untagged_addr(far); > struct vm_area_struct *vma; > + int si_code; I think we should initialise this to 0. Currently all paths seem to set si_code to something meaningful but I'm not sure the last 'else' close in this patch is guaranteed to always cover exactly those earlier code paths updating si_code. I'm not talking about the 'goto bad_area' paths since they set 'fault' to 0 but the fall through after the second (under the mm lock) handle_mm_fault(). > if (kprobe_page_fault(regs, esr)) > return 0; > @@ -572,9 +570,10 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, > > if (!(vma->vm_flags & vm_flags)) { > vma_end_read(vma); > - fault = VM_FAULT_BADACCESS; > + fault = 0; > + si_code = SEGV_ACCERR; > count_vm_vma_lock_event(VMA_LOCK_SUCCESS); > - goto done; > + goto bad_area; > } > fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs); > if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) > @@ -599,15 +598,18 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, > retry: > vma = lock_mm_and_find_vma(mm, addr, regs); > if (unlikely(!vma)) { > - fault = VM_FAULT_BADMAP; > - goto done; > + fault = 0; > + si_code = SEGV_MAPERR; > + goto bad_area; > } > > - if (!(vma->vm_flags & vm_flags)) > - fault = VM_FAULT_BADACCESS; > - else > - fault = handle_mm_fault(vma, addr, mm_flags, regs); > + if (!(vma->vm_flags & vm_flags)) { > + fault = 0; > + si_code = SEGV_ACCERR; > + goto bad_area; > + } What's releasing the mm lock here? Prior to this change, it is falling through to mmap_read_unlock() below or handle_mm_fault() was releasing the lock (VM_FAULT_RETRY, VM_FAULT_COMPLETED). > > + fault = handle_mm_fault(vma, addr, mm_flags, regs); > /* Quick path to respond to signals */ > if (fault_signal_pending(fault, regs)) { > if (!user_mode(regs)) > @@ -626,13 +628,11 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, > mmap_read_unlock(mm); > > done: > - /* > - * Handle the "normal" (no error) case first. > - */ > - if (likely(!(fault & (VM_FAULT_ERROR | VM_FAULT_BADMAP | > - VM_FAULT_BADACCESS)))) > + /* Handle the "normal" (no error) case first. */ > + if (likely(!(fault & VM_FAULT_ERROR))) > return 0; > > +bad_area: > /* > * If we are in kernel mode at this point, we have no context to > * handle this fault with. > @@ -667,13 +667,8 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, > > arm64_force_sig_mceerr(BUS_MCEERR_AR, far, lsb, inf->name); > } else { > - /* > - * Something tried to access memory that isn't in our memory > - * map. > - */ > - arm64_force_sig_fault(SIGSEGV, > - fault == VM_FAULT_BADACCESS ? SEGV_ACCERR : SEGV_MAPERR, > - far, inf->name); > + /* Something tried to access memory that out of memory map */ > + arm64_force_sig_fault(SIGSEGV, si_code, far, inf->name); > } We can get to the 'else' close after the second handle_mm_fault(). Do we guarantee that 'fault == 0' in this last block? If not, maybe a warning and some safe initialisation for 'si_code' to avoid leaking stack data. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel