Received: by 10.213.65.68 with SMTP id h4csp501743imn; Tue, 13 Mar 2018 11:03:04 -0700 (PDT) X-Google-Smtp-Source: AG47ELvKXMfz/7VRoAXM+SMyN9rHiTGRqPc1V8XMiEbop8q3xZ3+AmHyw/mYsGCEFf8hW/Fpz/M9 X-Received: by 10.98.66.89 with SMTP id p86mr1441650pfa.228.1520964184064; Tue, 13 Mar 2018 11:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520964184; cv=none; d=google.com; s=arc-20160816; b=DHya/8E/4ygtnUaM+JdVQPWs/dNW5FO4c2AFFbE2Es2Egr1k+xwY0miq0hdnxN4kOR ZVrtlhgWbicPF4cGa4kkbjbWj8/sfjIRTzYFJNW0zwwaQ7UwUdFrRc9lxFFydDYiLxx0 yIFuhBhHQr5N8OiUHHNRFY+KNOVsG3pxhebTGNWb0r9B9IYdBaOrKDB2u1zZlNXww5M4 OHqi0/c4qh8coDkiaTIiek1R7H7WUukGpnDclg3XVxxeU0vl6jzzwtPNnAI2bYLmkTNE mQBECEE9dLOzhUCtAcNKJlsKnGscOfhSlwMIDlnsknFcefaUgNZIMfKPjJ7AovP0PFHk yx4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=0z4P8m0yVGLk72wEmmfnX7cVq9Sls4scIU7EZAiWIiM=; b=seAg83VBT8kTUjJEGHfl02GuQN7LU7uTNARJFHQCJC0jCEMsVFVhTAPhExbbkhMwwG 3YCZqSpHlksQh6NONoVpaHW8rYsjSNityMYQHIyWVnwqPkp9SaAcXGQ25Hjtopy7Ushq Yw6Lpmv2H3uehNbpgeCVcgvcaNHf45reuMq7Fd2LACmVxfhPOslVtfBdFLn0h6NLaL10 kQ69449Aco+PMuMD+23dqrrpqJJx8o5inLcn6qwvAR+Xo8zNSZvwuQmp2IUl2U30THQL SgqqKUh5MUZaOrZ4ejg3p8wbb+m0/ty4X1Fvx16exmvIkRt23e8qJZ3SkXcDhGSk5+XQ cNpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d71si436276pgc.411.2018.03.13.11.02.40; Tue, 13 Mar 2018 11:03:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752947AbeCMSBG (ORCPT + 99 others); Tue, 13 Mar 2018 14:01:06 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:52598 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752039AbeCMSA6 (ORCPT ); Tue, 13 Mar 2018 14:00:58 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2DHsK4f041412 for ; Tue, 13 Mar 2018 14:00:57 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gpj5ckncv-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 13 Mar 2018 14:00:56 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Mar 2018 18:00:54 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 13 Mar 2018 18:00:47 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2DI0kVa52625558; Tue, 13 Mar 2018 18:00:46 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8444042041; Tue, 13 Mar 2018 17:53:02 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6C3A942042; Tue, 13 Mar 2018 17:53:01 +0000 (GMT) Received: from nimbus.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.33]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 13 Mar 2018 17:53:01 +0000 (GMT) From: Laurent Dufour To: paulmck@linux.vnet.ibm.com, peterz@infradead.org, akpm@linux-foundation.org, kirill@shutemov.name, ak@linux.intel.com, mhocko@kernel.org, dave@stgolabs.net, jack@suse.cz, Matthew Wilcox , benh@kernel.crashing.org, mpe@ellerman.id.au, paulus@samba.org, Thomas Gleixner , Ingo Molnar , hpa@zytor.com, Will Deacon , Sergey Senozhatsky , Andrea Arcangeli , Alexei Starovoitov , kemi.wang@intel.com, sergey.senozhatsky.work@gmail.com, Daniel Jordan Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, haren@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com, npiggin@gmail.com, bsingharora@gmail.com, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v9 23/24] x86/mm: Add speculative pagefault handling Date: Tue, 13 Mar 2018 18:59:53 +0100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520963994-28477-1-git-send-email-ldufour@linux.vnet.ibm.com> References: <1520963994-28477-1-git-send-email-ldufour@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18031318-0040-0000-0000-0000044001AC X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031318-0041-0000-0000-000020E301A3 Message-Id: <1520963994-28477-24-git-send-email-ldufour@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-13_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803130203 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra Try a speculative fault before acquiring mmap_sem, if it returns with VM_FAULT_RETRY continue with the mmap_sem acquisition and do the traditional fault. Signed-off-by: Peter Zijlstra (Intel) [Clearing of FAULT_FLAG_ALLOW_RETRY is now done in handle_speculative_fault()] [Retry with usual fault path in the case VM_ERROR is returned by handle_speculative_fault(). This allows signal to be delivered] [Don't build SPF call if !CONFIG_SPECULATIVE_PAGE_FAULT] [Try speculative fault path only for multi threaded processes] [Try to the VMA fetch during the speculative path in case of retry] Signed-off-by: Laurent Dufour --- arch/x86/mm/fault.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index e6af2b464c3d..a73cf227edd6 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1239,6 +1239,9 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address) { struct vm_area_struct *vma; +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT + struct vm_area_struct *spf_vma = NULL; +#endif struct task_struct *tsk; struct mm_struct *mm; int fault, major = 0; @@ -1332,6 +1335,27 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code, if (error_code & X86_PF_INSTR) flags |= FAULT_FLAG_INSTRUCTION; +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT + if ((error_code & X86_PF_USER) && (atomic_read(&mm->mm_users) > 1)) { + fault = handle_speculative_fault(mm, address, flags, + &spf_vma); + + if (!(fault & VM_FAULT_RETRY)) { + if (!(fault & VM_FAULT_ERROR)) { + perf_sw_event(PERF_COUNT_SW_SPF, 1, + regs, address); + goto done; + } + /* + * In case of error we need the pkey value, but + * can't get it from the spf_vma as it is only returned + * when VM_FAULT_RETRY is returned. So we have to + * retry the page fault with the mmap_sem grabbed. + */ + } + } +#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 @@ -1365,7 +1389,16 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code, might_sleep(); } - vma = find_vma(mm, address); +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT + if (spf_vma) { + if (can_reuse_spf_vma(spf_vma, address)) + vma = spf_vma; + else + vma = find_vma(mm, address); + spf_vma = NULL; + } else +#endif + vma = find_vma(mm, address); if (unlikely(!vma)) { bad_area(regs, error_code, address); return; @@ -1451,6 +1484,9 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code, return; } +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT +done: +#endif /* * Major/minor page fault accounting. If any of the events * returned VM_FAULT_MAJOR, we account it as a major fault. -- 2.7.4