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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CC47C433F5 for ; Sun, 30 Jan 2022 09:13:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1598F6B0072; Sun, 30 Jan 2022 04:13:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10CEE6B0073; Sun, 30 Jan 2022 04:13:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3A8C6B0074; Sun, 30 Jan 2022 04:13:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id E88F26B0072 for ; Sun, 30 Jan 2022 04:13:41 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9748318147594 for ; Sun, 30 Jan 2022 09:13:41 +0000 (UTC) X-FDA: 79086390642.04.F2A9419 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 0ABABA0003 for ; Sun, 30 Jan 2022 09:13:40 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 05A546109E; Sun, 30 Jan 2022 09:13:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0ADE5C340E4; Sun, 30 Jan 2022 09:13:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643534019; bh=cM8a1BT6LaZu1DHKkrAqCukI0JB0jBgJb3lYj9h6XPA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=a+gXD0U3XoWUJpZx0ZUh1LuX+WqDimVnzKpgu+HDf0we7IkWiCUO6E/Rw574s6zGM n2m78pjt2B6yGu6BLWYm+5buzmGJrY0tWokjFw627i5JVNY6mxIfRON1qudqp6R1T6 bzg+BEIAGwUKxFPwn8Wy91r7wkndzEn6fgKlmMBfQeMNTbUKyMb70aD8JwHaSRUBmY 9ZLcRlIgwLHWnWdlVpRwSlZEMqt/l6Dlg/oYb0XpibcKnIe5aH4WMb5x6nKL8UXJKE S8jgdcRdn88DTjtOQzt+3mHvwGzulfZoFkdrsPr6XZ8IenHn+oivn4p3IArg7Hwkmj yEPgTiArK9pkw== Date: Sun, 30 Jan 2022 11:13:26 +0200 From: Mike Rapoport To: Michel Lespinasse Cc: Linux-MM , linux-kernel@vger.kernel.org, Andrew Morton , kernel-team@fb.com, Laurent Dufour , Jerome Glisse , Peter Zijlstra , Michal Hocko , Vlastimil Babka , Davidlohr Bueso , Matthew Wilcox , Liam Howlett , Rik van Riel , Paul McKenney , Song Liu , Suren Baghdasaryan , Minchan Kim , Joel Fernandes , David Rientjes , Axel Rasmussen , Andy Lutomirski Subject: Re: [PATCH v2 33/35] arm64/mm: attempt speculative mm faults first Message-ID: References: <20220128131006.67712-1-michel@lespinasse.org> <20220128131006.67712-34-michel@lespinasse.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220128131006.67712-34-michel@lespinasse.org> X-Stat-Signature: n5owb84rj5f15od9gzdkh1qu4acxmcy3 X-Rspam-User: nil Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=a+gXD0U3; spf=pass (imf15.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0ABABA0003 X-HE-Tag: 1643534020-137041 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: On Fri, Jan 28, 2022 at 05:10:04AM -0800, Michel Lespinasse wrote: > Attempt speculative mm fault handling first, and fall back to the > existing (non-speculative) code if that fails. > > This follows the lines of the x86 speculative fault handling code, > but with some minor arch differences such as the way that the > VM_FAULT_BADACCESS case is handled. > > Signed-off-by: Michel Lespinasse > --- > arch/arm64/mm/fault.c | 62 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 62 insertions(+) > > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c > index 77341b160aca..2598795f4e70 100644 > --- a/arch/arm64/mm/fault.c > +++ b/arch/arm64/mm/fault.c > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -524,6 +525,11 @@ static int __kprobes do_page_fault(unsigned long far, unsigned int esr, > unsigned long vm_flags; > unsigned int mm_flags = FAULT_FLAG_DEFAULT; > unsigned long addr = untagged_addr(far); > +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT > + struct vm_area_struct *vma; > + struct vm_area_struct pvma; > + unsigned long seq; > +#endif > > if (kprobe_page_fault(regs, esr)) > return 0; > @@ -574,6 +580,59 @@ static int __kprobes do_page_fault(unsigned long far, unsigned int esr, > > perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); > > +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT > + /* > + * No need to try speculative faults for kernel or > + * single threaded user space. > + */ > + if (!(mm_flags & FAULT_FLAG_USER) || atomic_read(&mm->mm_users) == 1) > + goto no_spf; > + > + count_vm_event(SPF_ATTEMPT); > + seq = mmap_seq_read_start(mm); > + if (seq & 1) { > + count_vm_spf_event(SPF_ABORT_ODD); > + goto spf_abort; > + } > + rcu_read_lock(); > + vma = __find_vma(mm, addr); > + if (!vma || vma->vm_start > addr) { > + rcu_read_unlock(); > + count_vm_spf_event(SPF_ABORT_UNMAPPED); > + goto spf_abort; > + } > + if (!vma_is_anonymous(vma)) { > + rcu_read_unlock(); > + count_vm_spf_event(SPF_ABORT_NO_SPECULATE); > + goto spf_abort; > + } > + pvma = *vma; > + rcu_read_unlock(); > + if (!mmap_seq_read_check(mm, seq, SPF_ABORT_VMA_COPY)) > + goto spf_abort; > + vma = &pvma; > + if (!(vma->vm_flags & vm_flags)) { > + count_vm_spf_event(SPF_ABORT_ACCESS_ERROR); > + goto spf_abort; > + } > + fault = do_handle_mm_fault(vma, addr & PAGE_MASK, > + mm_flags | FAULT_FLAG_SPECULATIVE, seq, regs); > + > + /* Quick path to respond to signals */ > + if (fault_signal_pending(fault, regs)) { > + if (!user_mode(regs)) > + goto no_context; > + return 0; > + } > + if (!(fault & VM_FAULT_RETRY)) > + goto done; > + > +spf_abort: > + count_vm_event(SPF_ABORT); > +no_spf: > + > +#endif /* CONFIG_SPECULATIVE_PAGE_FAULT */ The speculative page fault implementation here (and for PowerPC as well) looks very similar to x86. Can we factor it our rather than copy 3 (or more) times? > + > /* > * As per x86, we may deadlock here. However, since the kernel only > * validly references user space from well defined areas of the code, > @@ -612,6 +671,9 @@ static int __kprobes do_page_fault(unsigned long far, unsigned int esr, > goto retry; > } > mmap_read_unlock(mm); > +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT > +done: > +#endif > > /* > * Handle the "normal" (no error) case first. > -- > 2.20.1 > > -- Sincerely yours, Mike.