Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp636153pxy; Fri, 30 Apr 2021 12:55:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKSFeBLPH9/3/YdiCHyaWfVuxBOZhVU7gLq9ewPHB3EWc4j1f84Fhh1yd07J4tx9rsv537 X-Received: by 2002:a63:a62:: with SMTP id z34mr5965881pgk.189.1619812522370; Fri, 30 Apr 2021 12:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619812522; cv=none; d=google.com; s=arc-20160816; b=FD04SdkiJK3VDTI8j2J5Ge3cUfRSu9PiDr1qFOXlEXA6pF4is9jX5TlF2ApaNhwTTT /td7sximBRZEy6il7zt2v8mjNzhV0E8eGwtK91FTWGp5WJptwwYjYrGXuvm+K3VnCtWJ nbCx4lhjTJRdwnCMef0Z6t9z7HQjZnUFa4+uDerNu/x81G1PlOBeGVzv9/rdtiFm0atr YRYXVKnOuVuQnzgA1FWtYn+zWm3tpsmRzZej9YjPZi88Ivp9xzKjLYx0TAekNgOsGQr0 IAIymMmXWAtlgn+BVZ0yWsPZ3GMdKVPznGWz/mCWELUiusXZ3kV54U86saQqxXVo9n7j yDaQ== 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=eULoJwQoISRJDyWh6sQIkPbJRau/grHqDfGiWr2ndBc=; b=xRFpPA97TgsazP+rr4Ki2L27qB6WHpypBkUVFTgHVJyY8ZhF1aSMkEMM1DWqVcr4+L r7idspDm2PE296n5wLW3Bo9KCCB4oZNF+fjpcFWw1Pk9aI4+70MXlUAvftKV74IV93KS htUpllIKZTyPa/O2wA+jOUuWjV0tha0/Zt9NXmavIYs342iF5Nskc6fnqyQTjrpBaMVK 1dZTORz0uILtkamAzohXsrjWcnEYU5LXkSjM6wJiTwTNEZuhxfe1Aoa/yDQ1T3G5rzka EhVntXYjHa5uhzuHxDLSFJGErUzzQwRGDSU6fBFh1+Gis4q68OZnXF704GD4VsqHc9re FXlg== 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=LLcNJN4Q; 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 h11si1186171plk.46.2021.04.30.12.55.10; Fri, 30 Apr 2021 12:55:22 -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=LLcNJN4Q; 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 S233894AbhD3TzG (ORCPT + 99 others); Fri, 30 Apr 2021 15:55:06 -0400 Received: from server.lespinasse.org ([63.205.204.226]:47923 "EHLO server.lespinasse.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233357AbhD3Txi (ORCPT ); Fri, 30 Apr 2021 15:53:38 -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=eULoJwQoISRJDyWh6sQIkPbJRau/grHqDfGiWr2ndBc=; b=hNOAqV+Bi3m/G9I1+p/zbTgoypBTOIz9B9w7EuLXDESQcB7YB+wNpudjM89Jlv4pGyn1d eppGrtsnZHr/cNRBg== 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=eULoJwQoISRJDyWh6sQIkPbJRau/grHqDfGiWr2ndBc=; b=LLcNJN4Q0cNreUi2QNRCmvi9zlH+OSkbXB/q3IC4eYa3yeOiFOzGf7On1WAFSRGdYS4Hy jDWbNZpT8l72PTG6DCd9W22CDTlebRhwdA69DEVWWQB8UZGfktRR0w/+VDx3geYu4Qt37My vBe5z2c36M/iQlLy1RWER9bUFrR63ZNDfJnizhjBtrQsR5QMmlaz2b/zziuf959oknLxTF6 XHkWLqzy4v3htaBTYFcJVZqEnFtjBbFHdLnnsvn1gxQj7eIjoYN3F62t5hvwB9Ky2p/2+Gh S6Lvbcn9dW4G2XDxg5zPVBk62nFgrXWu/01L/iNX///ZO6Nc3ebsipAsTkeQ== Received: from zeus.lespinasse.org (zeus.lespinasse.org [IPv6:fd00::150:0]) by server.lespinasse.org (Postfix) with ESMTPS id DBD20160372; Fri, 30 Apr 2021 12:52:33 -0700 (PDT) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id CCB6D19F523; 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 31/31] powerpc/mm: attempt speculative mm faults first Date: Fri, 30 Apr 2021 12:52:32 -0700 Message-Id: <20210430195232.30491-32-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 access_pkey_error case is handled Signed-off-by: Michel Lespinasse --- arch/powerpc/mm/fault.c | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index bb368257b55c..d7c820751a58 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -398,6 +398,10 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, int is_write = page_fault_is_write(error_code); vm_fault_t fault, major = 0; bool kprobe_fault = kprobe_page_fault(regs, 11); +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT + struct vm_area_struct pvma; + unsigned long seq; +#endif if (unlikely(debugger_fault_handler(regs) || kprobe_fault)) return 0; @@ -450,6 +454,64 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, if (is_exec) flags |= FAULT_FLAG_INSTRUCTION; +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT + + /* + * No need to try speculative faults for kernel or + * single threaded user space. + */ + if (!(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, address); + if (!vma || vma->vm_start > address) { + 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; +#ifdef CONFIG_PPC_MEM_KEYS + if (unlikely(access_pkey_error(is_write, is_exec, + (error_code & DSISR_KEYFAULT), vma))) { + count_vm_spf_event(SPF_ABORT_ACCESS_ERROR); + goto spf_abort; + } +#endif /* CONFIG_PPC_MEM_KEYS */ + if (unlikely(access_error(is_write, is_exec, vma))) { + count_vm_spf_event(SPF_ABORT_ACCESS_ERROR); + goto spf_abort; + } + fault = do_handle_mm_fault(vma, address, + flags | FAULT_FLAG_SPECULATIVE, seq, regs); + major |= fault & VM_FAULT_MAJOR; + + if (fault_signal_pending(fault, regs)) + return user_mode(regs) ? 0 : SIGBUS; + if (!(fault & VM_FAULT_RETRY)) + goto done; + +spf_abort: + count_vm_event(SPF_ABORT); +no_spf: + +#endif /* CONFIG_SPECULATIVE_PAGE_FAULT */ + /* When running in the kernel we expect faults to occur only to * addresses in user space. All other faults represent errors in the * kernel and should generate an OOPS. Unfortunately, in the case of an @@ -525,6 +587,9 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, } mmap_read_unlock(current->mm); +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT +done: +#endif if (unlikely(fault & VM_FAULT_ERROR)) return mm_fault_error(regs, address, fault); -- 2.20.1