Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3139731imm; Thu, 17 May 2018 04:10:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq+6OLv+VmHrw/YTY/vwuU4GmpuwVJion0Z/3MGEzQ47hWhMcyV5q/Rx/RWDIqqFaq9UKOp X-Received: by 2002:a17:902:5382:: with SMTP id c2-v6mr4769012pli.335.1526555406405; Thu, 17 May 2018 04:10:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526555406; cv=none; d=google.com; s=arc-20160816; b=unIOoe8ADO2H/ryJEysU4IPOO42t7yN3YT4sLhZphNbp6EXTNfoVrBXecnCY9oeSkE sgkxGuSdvY80BPCrvy8GcwxUxaGbs70+BBXAH+PRoDxvm0dNO4NZRycWIvZqmkYY9Wgw 7G6mZTZNclCufCZloPYHaPI8EW1HRCpfjYDd/Ao2L5rRrHjCuRru9j5n5sugOP+A/JW1 ak2xsCK6J10njCldNQum6rqqHAqOesBkx+jGw9B48LlBym6F1tdOXhoidS2MVkLD5Rap Rsc3PPOgH+SUmrLRS2iC7se+mJMf8YGOzmEDq/BJJmWPtqIb0I5KwHPEo+dSSWm55g/t EwpA== 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=+4fTvVaRDrdv4rhm702Fq4GpOJNFqWOpusLY8yl1ia8=; b=RRrK2wll98T2kWswT+39K7dNEK0Ax9yFNxI8jpPSFFPfdFK/ZbEMjmcaKnFo0cj4UD ky78M4HzdQPw99jxpbh26VA4uxuFrag7Yaixov/x6MgqdU/PKB1JkjWqNmlxdMSjKHW9 faLfen80hQjHvviUqCaAZ0zsn4I9NhLFaRJWFjZpdYXu6c8sZQjwtaU8tvI7vohuX5hT d6Fn5wITXc1GeDS+5KKYsaD+s4K07hfzlGjEgmqkwwamAuZFHXpoS4+7zuWz3GMwWQLk KCouFbquBx3G4zRbfqEe71Aki8izu+ikHAf+W7rAkLuGznlLFN778QZOWMseV67fcBKh UdsA== 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 j28-v6si3954783pgn.78.2018.05.17.04.09.51; Thu, 17 May 2018 04:10:06 -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 S1752473AbeEQLIS (ORCPT + 99 others); Thu, 17 May 2018 07:08:18 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33668 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752386AbeEQLHp (ORCPT ); Thu, 17 May 2018 07:07:45 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4HB4FEv024199 for ; Thu, 17 May 2018 07:07:45 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j16wmw3gf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 17 May 2018 07:07:44 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 17 May 2018 12:07:41 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 17 May 2018 12:07:31 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4HB7Vn959310160; Thu, 17 May 2018 11:07:31 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C05264C050; Thu, 17 May 2018 11:59:19 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 88D044C04E; Thu, 17 May 2018 11:59:18 +0100 (BST) Received: from nimbus.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.33]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 17 May 2018 11:59:18 +0100 (BST) From: Laurent Dufour To: akpm@linux-foundation.org, mhocko@kernel.org, peterz@infradead.org, kirill@shutemov.name, ak@linux.intel.com, dave@stgolabs.net, jack@suse.cz, Matthew Wilcox , khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, benh@kernel.crashing.org, mpe@ellerman.id.au, paulus@samba.org, Thomas Gleixner , Ingo Molnar , hpa@zytor.com, Will Deacon , Sergey Senozhatsky , sergey.senozhatsky.work@gmail.com, Andrea Arcangeli , Alexei Starovoitov , kemi.wang@intel.com, Daniel Jordan , David Rientjes , Jerome Glisse , Ganesh Mahendran , Minchan Kim , Punit Agrawal , vinayak menon , Yang Shi Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, haren@linux.vnet.ibm.com, npiggin@gmail.com, bsingharora@gmail.com, paulmck@linux.vnet.ibm.com, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v11 24/26] x86/mm: add speculative pagefault handling Date: Thu, 17 May 2018 13:06:31 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526555193-7242-1-git-send-email-ldufour@linux.vnet.ibm.com> References: <1526555193-7242-1-git-send-email-ldufour@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18051711-0044-0000-0000-000005537523 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051711-0045-0000-0000-00002894E904 Message-Id: <1526555193-7242-25-git-send-email-ldufour@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-17_05:,, 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-1805170100 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] [Handle memory protection key fault] Signed-off-by: Laurent Dufour --- arch/x86/mm/fault.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index fd84edf82252..11944bfc805a 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1224,7 +1224,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code, struct mm_struct *mm; int fault, major = 0; unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; - u32 pkey; + u32 pkey, *pt_pkey = &pkey; tsk = current; mm = tsk->mm; @@ -1314,6 +1314,27 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code, flags |= FAULT_FLAG_INSTRUCTION; /* + * Do not try to do a speculative page fault if the fault was due to + * protection keys since it can't be resolved. + */ + if (!(error_code & X86_PF_PK)) { + fault = handle_speculative_fault(mm, address, flags); + if (fault != VM_FAULT_RETRY) { + perf_sw_event(PERF_COUNT_SW_SPF, 1, regs, address); + /* + * Do not advertise for the pkey value since we don't + * know it. + * This is not a matter as we checked for X86_PF_PK + * earlier, so we should not handle pkey fault here, + * but to be sure that mm_fault_error() callees will + * not try to use it, we invalidate the pointer. + */ + pt_pkey = NULL; + goto done; + } + } + + /* * 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 @@ -1427,8 +1448,10 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code, } up_read(&mm->mmap_sem); + +done: if (unlikely(fault & VM_FAULT_ERROR)) { - mm_fault_error(regs, error_code, address, &pkey, fault); + mm_fault_error(regs, error_code, address, pt_pkey, fault); return; } -- 2.7.4