Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp635811pxy; Fri, 30 Apr 2021 12:54:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJza7e9tBx28qqUP/H0xxDh9/zVTxdaH6XQ1TI0aWeJCknmm95hTOyDUytp22NSI74psK3YP X-Received: by 2002:a63:c157:: with SMTP id p23mr5974599pgi.162.1619812489593; Fri, 30 Apr 2021 12:54:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619812489; cv=none; d=google.com; s=arc-20160816; b=bUdXLFhgFQWFVscPzPYmbJxdb+ZyKMzQGNDoI9MV/KcJjjbVGbEG4dvkCrJa1fCR9h MZ8wIuttAf9jGASWYISMyDRsCnc3ZjofcbTE4CCUwluJp1GBBO9bSeYYhWFd+ih32koO RSIuHLWGIRO7cAdk+hsP1hI+TCoPBamcbAF0PfyijYA010plLwpyNDTtfPiMH/bq5Ihm 2ctEfVOmxYfWOaP/CTkHofkd4ns1wZvmACGUd9+5ddg29bQ+Jf6Bie0nPK0xFl55K2VK TNyhy25E9ntiUSZqtzOuiBNPxfbuTncqUnFfb6mncr1XfJpD6wsv0TSDpTMNMr9RTwvD 01rA== 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 :dkim-signature:dkim-signature; bh=FTmd8q5bXeYtX6zqFZAxa8+xy7tYwTDwfSzy7iAnfZo=; b=gOBC5slDBwGtwCwweBHJwf6uXPZ13FL8wILEqiXB+ZvQv5lduPL+dTv0v/ySZHYOVG G0u7R10i6GRy56y812svLpkqebXIcSE0CAZNh/nUj2CryCBpeHoYw0SZIMwB6aI/0E+k cpDx/p/FRLmvW+isrGG0RtLf4bwxbxXrGOCgtG3u+SOKZd5Zg6QhMl4vKKPVjWve2iXr HUO6ET1r3Buf6/38rhyNsVK65prB7X4Mk9eqzufBSmfQcsaJ/RM+Qzx3/G4Pc0VGcQKI uoRDUkg+sGBRq6YfbbOhCMeIq0wf0/QwAUdXCoRZ1qQOpgahupM3vxayPbIQcxmFpUkl GV9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-14-rsa header.b=PmpwOhrU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=lespinasse.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t17si3988080pgm.289.2021.04.30.12.54.37; Fri, 30 Apr 2021 12:54:49 -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; dkim=neutral (no key) header.i=@lespinasse.org; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-14-rsa header.b=PmpwOhrU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=lespinasse.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233919AbhD3Tyk (ORCPT + 99 others); Fri, 30 Apr 2021 15:54:40 -0400 Received: from server.lespinasse.org ([63.205.204.226]:45461 "EHLO server.lespinasse.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232494AbhD3Txh (ORCPT ); Fri, 30 Apr 2021 15:53:37 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-14-ed; t=1619812353; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=FTmd8q5bXeYtX6zqFZAxa8+xy7tYwTDwfSzy7iAnfZo=; b=ZulnIIq8a4SfDWkrfX/OUtIvvvF7dZx7gaKOvE4F0it1bDwwukBrcIykrRJ86Xw5/d0Ri g3rZSQUQjZOfd6JBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-14-rsa; t=1619812353; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=FTmd8q5bXeYtX6zqFZAxa8+xy7tYwTDwfSzy7iAnfZo=; b=PmpwOhrUj9PXxXes471bRWBh2GoLrbZ85V8g5GC4KXE0WEvlpmV0L03hppw1kXO7SmZ6a g0LcSRCyYWeWKva4E7tFkRYs/PQGhfa3Pseay7k6iGYcQitfgZVH2HddXgr5oQLiqnvtm5W blzgBE54N/Y1xL4UstFKJRsEKXrxr1oMCJvBVPVpoQa1VlnrpucugfXBZnAqLrnHs7ZUO42 B8DnYDMypFIvB0IskZIHlD1AXOGeJnEmbDUIekM0mtMERqMY4tdE6Vu6kOQef2NkmV3a5IN /12olEZIe2g2Cu36KvTlwMYeEjMQ4tC7WO4m/beAYKqcUWqCFrAKQDDEb+bQ== Received: from zeus.lespinasse.org (zeus.lespinasse.org [10.0.0.150]) by server.lespinasse.org (Postfix) with ESMTPS id CE7B3160368; Fri, 30 Apr 2021 12:52:33 -0700 (PDT) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id BE0D219F521; Fri, 30 Apr 2021 12:52:33 -0700 (PDT) From: Michel Lespinasse To: Linux-MM , Linux-Kernel Cc: Laurent Dufour , Peter Zijlstra , Michal Hocko , Matthew Wilcox , Rik van Riel , Paul McKenney , Andrew Morton , Suren Baghdasaryan , Joel Fernandes , Andy Lutomirski , Michel Lespinasse Subject: [PATCH 29/29] arm64/mm: attempt speculative mm faults first Date: Fri, 30 Apr 2021 12:52:30 -0700 Message-Id: <20210430195232.30491-30-michel@lespinasse.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210430195232.30491-1-michel@lespinasse.org> References: <20210430195232.30491-1-michel@lespinasse.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index f37d4e3830b7..f2d09f8e4bc2 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -530,6 +531,11 @@ static int __kprobes do_page_fault(unsigned long far, unsigned int esr, unsigned long vm_flags = VM_ACCESS_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; @@ -564,6 +570,60 @@ 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 */ + /* * As per x86, we may deadlock here. However, since the kernel only * validly references user space from well defined areas of the code, @@ -604,6 +664,9 @@ static int __kprobes do_page_fault(unsigned long far, unsigned int esr, } } mmap_read_unlock(mm); +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT +done: +#endif /* * Handle the "normal" (no error) case first. -- 2.20.1