From patchwork Thu May 17 11:06:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 10406433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3CF2860247 for ; Thu, 17 May 2018 11:08:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D08D28887 for ; Thu, 17 May 2018 11:08:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21495288E0; Thu, 17 May 2018 11:08:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F38028887 for ; Thu, 17 May 2018 11:08:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A80E6B04C7; Thu, 17 May 2018 07:07:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1E12C6B04C9; Thu, 17 May 2018 07:07:46 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05D6B6B04C8; Thu, 17 May 2018 07:07:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f197.google.com (mail-qk0-f197.google.com [209.85.220.197]) by kanga.kvack.org (Postfix) with ESMTP id C501F6B04C6 for ; Thu, 17 May 2018 07:07:45 -0400 (EDT) Received: by mail-qk0-f197.google.com with SMTP id 65-v6so1301300qkl.11 for ; Thu, 17 May 2018 04:07:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:in-reply-to:references:message-id; bh=+4fTvVaRDrdv4rhm702Fq4GpOJNFqWOpusLY8yl1ia8=; b=hiH0dWUOym2rEqy9Ok/aCmelpiv25TVxP6IiRCWwECZFpjIoVdy/h7lIegerEwcqAT m+E8p5+lgpqH3bdc2g0U38Lcs4iCoZ7ZG8IVgjV9/sosvS3DVfYK3KdA5z3EOqOWXPgs 3H9i28KK+Fd4wptUP23sj1OXelbILU136IGC0MjWdVOsJRDx9D0Nun6i23OcOQF9x2ue wMcTMFbRvF2afGEnp9TYFXwHD8VyeOZCo8TDT9BMld6T/269TY1z6vlk9EyBPGdA4uY4 fPajWl9iNa3OIIA9yUzZpjLcIC7KAj4gXW+b6i3dbh9ZeZe0yWH5XGsK7vwERYS3hW+c qaHA== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 148.163.156.1 is neither permitted nor denied by best guess record for domain of ldufour@linux.vnet.ibm.com) smtp.mailfrom=ldufour@linux.vnet.ibm.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: ALKqPwdgnlyoTDmSIqi7LydLahsFlqwNj3S0wisAKYwDT4bTKIEtG6TC xAELr4mv0592/ZpPqfJU8pLQfEOxWLWB86Kz6UGlglLriKMgFFOHI/YZYBq0vy2AWV8FkMVJVKm BQodWw4eI24bFLDp4iFdEtUs51FD0t2B0qHT0PE/r5h/RggAlv6AshEpNhS1/o6k= X-Received: by 2002:ac8:f11:: with SMTP id e17-v6mr4886754qtk.261.1526555265607; Thu, 17 May 2018 04:07:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpcrKRU50OF6BDKndcWTs/07ue8aKkyTVsZQWsEo7FWD0SR0bNnmb6PGataAdswMlySzlCT X-Received: by 2002:ac8:f11:: with SMTP id e17-v6mr4886713qtk.261.1526555265002; Thu, 17 May 2018 04:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526555264; cv=none; d=google.com; s=arc-20160816; b=EaqfYTz0I5wzOyXiSspw/CaXRVCc0nXnQFv04h29vrI3PvHsCp3xym3Uj63ZvmBuPN Fhi5SZYfSbVhtdmzOfEBfhbs5TIEdpCyyX+8EtuMWouVDGr2xNuiN3FaF8+wgTUJidTB KHqh4R6aWIM0k6EfDrLkE4EuxtFCqC6fyp/+QTh6CSQSfdWMLOH0ALBXhRgUnfBzgk2c WgDGzNDxXOV+tSbazEEebkJ+LQIzddCKCoUInFwugFT1Os11tViUdbePRf3CK3TQMhTi h8606stUW0+FXbyQ1biMSbGnGQt6FJQHUQ4KNuMq8ub8aXJlrmMfiVW9nVnCtz7uPIHt VPsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:references:in-reply-to:date:subject:cc:to:from :arc-authentication-results; bh=+4fTvVaRDrdv4rhm702Fq4GpOJNFqWOpusLY8yl1ia8=; b=l0Si/bCFRLEnfyjKnqovrlAHWQpmceIMwq3NsNL8C510VXy46qwSXA5fnOdQqrFazP /uUksR2Te3oFZGViNprFWf+wR/hfVxScRPvUCT27m0SgFQPxtnGqXukFcQV1CyMK7zI5 BXAWGmTiXo4T4opL36PjAOf8wtiqttOnnq8zBrRPDgxqCYGcNK5H6JKi0IXzCoInpQ8R 1LhRFjxgWIXSxy/KHgVb7XVs8j3c1h0ALWzqFJ3GLFa1haHJ439yQjIsh1TNpt3d46L0 mxzMmzbjrAPtKDtx0IHfYamHlZjiV1/BZHBzoEoBSgfI4ZzOTW7cxZcDGurku/gpEgwb Vu8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 148.163.156.1 is neither permitted nor denied by best guess record for domain of ldufour@linux.vnet.ibm.com) smtp.mailfrom=ldufour@linux.vnet.ibm.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com. [148.163.156.1]) by mx.google.com with ESMTPS id t60-v6si779750qtd.179.2018.05.17.04.07.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 May 2018 04:07:44 -0700 (PDT) Received-SPF: neutral (google.com: 148.163.156.1 is neither permitted nor denied by best guess record for domain of ldufour@linux.vnet.ibm.com) client-ip=148.163.156.1; Authentication-Results: mx.google.com; spf=neutral (google.com: 148.163.156.1 is neither permitted nor denied by best guess record for domain of ldufour@linux.vnet.ibm.com) smtp.mailfrom=ldufour@linux.vnet.ibm.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4HB4DHR138401 for ; Thu, 17 May 2018 07:07:44 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j18149qbx-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 17 May 2018 07:07:43 -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 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: X-Virus-Scanned: ClamAV using ClamSMTP 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; }