Received: by 10.192.165.156 with SMTP id m28csp174683imm; Tue, 17 Apr 2018 08:18:59 -0700 (PDT) X-Google-Smtp-Source: AIpwx49O3hmcX6HK+T/OUdIPFte/gqUiepJxiV+4+HBpVvLYg0I6vqqJ49wphDjZ2g5v8zDoIRx+ X-Received: by 2002:a17:902:e01:: with SMTP id 1-v6mr2396980plw.211.1523978339487; Tue, 17 Apr 2018 08:18:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523978339; cv=none; d=google.com; s=arc-20160816; b=c/qBZMxSeYE4+vJtEHeTwsi7sgTUwXfJu/FM98JVxsSWvaeHRGLmHgk8WJXpPLWkRB xIFcyL6ZDB1LJt1RB01q/eZ0nq3HLVCvtHU9s05643YYdIrFTXd6tcnJEWFE5/XVQSIY o68Euuj6/K1KQG2avimstCHHJPP4PTUoezltrcbTIDwG6rnmSl4QBNTMak7MOmdoo5D4 Dlkb27DeKKAAVHNbnur3CelNvszC5EtokMZUdGAZ2qkkzeVbu7sCgMA8U9VjiQrW+osa hYqZ6cD+lcGbeZoeGUqG+YKxkLjQXat6I6N9ZeZRBi5tzHae6hsxSOn7wgKbIlA92B0L cpjQ== 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=h715Ci2GHsKUMzg8ICOFYL3fn2an/UB9Yo7uZp8nLPI=; b=WAc0n1nm1VBnEegqR0hUdvlu1wEQFaV3rj8GqubOhLhx2hvoBMLn1sF1A0yTOP+9ku 3rk1E7ZJUrq1Dp9pPjAP3X1Y3ceIK7FSHdUnh0mDOC0oS2yQX3/lVq1NRLReUolVSyES k7GsU3YfzrShC5rlrhOhw96iAlTbO9oERohidW0OPdsYkqhMgEDlpLOLBVNQmXzQ5bpH fIjTYKkk12Oz2QLHRjT3ht8YBtqQtLbc+H7zN+0kPWjo6gS+sOsTOZ95GTWOh7YwX/3V dfjfoaRNctVd3UOyvaUmTYNHlZQNseBRq9DGBb8Qw4DrArhnGUy8i260nkpzGog1Pnoa /pZw== 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 g186si7374445pfb.76.2018.04.17.08.18.43; Tue, 17 Apr 2018 08:18:59 -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 S1753928AbeDQOfN (ORCPT + 99 others); Tue, 17 Apr 2018 10:35:13 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51592 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752812AbeDQOfK (ORCPT ); Tue, 17 Apr 2018 10:35:10 -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 w3HEZ1dJ064475 for ; Tue, 17 Apr 2018 10:35:10 -0400 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hdj8n2d0f-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 17 Apr 2018 10:35:09 -0400 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Apr 2018 15:35:05 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 17 Apr 2018 15:34:57 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3HEYvaW56164474; Tue, 17 Apr 2018 14:34:57 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 08B2DA4057; Tue, 17 Apr 2018 15:27:06 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DE683A4053; Tue, 17 Apr 2018 15:27:03 +0100 (BST) Received: from nimbus.lab.toulouse-stg.fr.ibm.com (unknown [9.145.171.143]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 17 Apr 2018 15:27:03 +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 , 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 , David Rientjes , Jerome Glisse , Ganesh Mahendran 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, paulmck@linux.vnet.ibm.com, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v10 25/25] powerpc/mm: add speculative page fault Date: Tue, 17 Apr 2018 16:33:31 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523975611-15978-1-git-send-email-ldufour@linux.vnet.ibm.com> References: <1523975611-15978-1-git-send-email-ldufour@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041714-0020-0000-0000-00000412EC7F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041714-0021-0000-0000-000042A72D0F Message-Id: <1523975611-15978-26-git-send-email-ldufour@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-17_07:,, 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-1804170131 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch enable the speculative page fault on the PowerPC architecture. This will try a speculative page fault without holding the mmap_sem, if it returns with VM_FAULT_RETRY, the mmap_sem is acquired and the traditional page fault processing is done. The speculative path is only tried for multithreaded process as there is no risk of contention on the mmap_sem otherwise. Signed-off-by: Laurent Dufour --- arch/powerpc/mm/fault.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index c01d627e687a..37191147026e 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -464,6 +464,26 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address, if (is_exec) flags |= FAULT_FLAG_INSTRUCTION; + if (IS_ENABLED(CONFIG_SPECULATIVE_PAGE_FAULT)) { + fault = handle_speculative_fault(mm, address, flags, &vma); + /* + * Page fault is done if VM_FAULT_RETRY is not returned. + * But if the memory protection keys are active, we don't know + * if the fault is due to key mistmatch or due to a + * classic protection check. + * To differentiate that, we will need the VMA we no + * more have, so let's retry with the mmap_sem held. + */ + if (fault != VM_FAULT_RETRY && + (IS_ENABLED(CONFIG_PPC_MEM_KEYS) && + fault != VM_FAULT_SIGSEGV)) { + perf_sw_event(PERF_COUNT_SW_SPF, 1, regs, address); + goto done; + } + } else { + vma = NULL; + } + /* 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 @@ -494,7 +514,8 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address, might_sleep(); } - vma = find_vma(mm, address); + if (!vma || !can_reuse_spf_vma(vma, address)) + vma = find_vma(mm, address); if (unlikely(!vma)) return bad_area(regs, address); if (likely(vma->vm_start <= address)) @@ -551,8 +572,15 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address, */ flags &= ~FAULT_FLAG_ALLOW_RETRY; flags |= FAULT_FLAG_TRIED; - if (!fatal_signal_pending(current)) + if (!fatal_signal_pending(current)) { + /* + * Do not try to reuse this vma and fetch it + * again since we will release the mmap_sem. + */ + if (IS_ENABLED(CONFIG_SPECULATIVE_PAGE_FAULT)) + vma = NULL; goto retry; + } } /* @@ -564,6 +592,7 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address, up_read(¤t->mm->mmap_sem); +done: if (unlikely(fault & VM_FAULT_ERROR)) return mm_fault_error(regs, address, fault); -- 2.7.4