Received: by 10.192.165.148 with SMTP id m20csp341593imm; Wed, 2 May 2018 00:55:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZprQNy55pf0aFwIEBr0eHuLMXksbcrmhLFA8q5ZNyUFogDLI/Uw0YlSuCWDWhQ25jKUh4XV X-Received: by 10.98.234.26 with SMTP id t26mr18445417pfh.117.1525247739298; Wed, 02 May 2018 00:55:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525247739; cv=none; d=google.com; s=arc-20160816; b=fcOBML6LCsQIHjM4QYcmzyd6qqWiU+q19cS2yAOd7MByGGf8whiRyHh15g7vHWNFu+ T0Idlefeb27txRoY6a2I6JCEx7N5BndjLeJmMbF71HQu7HpqNMwE6dMxITy2bZB2AJ70 4DmcxwuJma+EqJYsz9SJ7BvE/5Wn2DgnKtguDB/vQX4r96cHi/PSVdAiT+7FREr2yKDi T1DzO0xzsnBEXblJFdgCfEPIZ7x2xW4hgZqqHAxNS2U3kYgi6oxtxfADXft5n34onJzQ YLprFVqSU2NnDbEslCnypFVLK+w8J7vmH+8jxz9+4+kFOiqPiwCdZkF92EwvDI7qU8Bs LX4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=CiAlOV2oRbz+VZO/tptorF+KuBCIfAyji69OyNiRK7M=; b=yqT1Ew93VaM0CUIitSIzUhHRcySHfokO8BVbiCljxMPo57Rsdsx1TRt1JnYcwrBD5E 1rEpRuextY1aJFKTaT5dcAXh+edtASczIEU+Qm57M/Uyi8rEETbzUil3p1g1msUlIX/Z TzMwmkWjQkw5cG8bntYxZsYq6gWbrg77uDElxq3GKtMsKRyLtqb3QYV3VQtNwV+GZmZX FZOtduIrHpojQar8JszirnUr4uiaG/my3ax0tK8T1AY9wgHmwXjg/yaHlmUP0zjN06vr jOAXIcQw63tlCNE0wtKWPlIU8WvgfkaEQmG/nxLeWn8Do44td9gNCAAZGAMpczaugohI HchQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CyLqtnKY; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j123si10906089pfg.156.2018.05.02.00.55.24; Wed, 02 May 2018 00:55:39 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CyLqtnKY; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751245AbeEBHzC (ORCPT + 99 others); Wed, 2 May 2018 03:55:02 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:45907 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751025AbeEBHy7 (ORCPT ); Wed, 2 May 2018 03:54:59 -0400 Received: by mail-pg0-f68.google.com with SMTP id i29-v6so10014303pgn.12 for ; Wed, 02 May 2018 00:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CiAlOV2oRbz+VZO/tptorF+KuBCIfAyji69OyNiRK7M=; b=CyLqtnKYJmmW7Nm67LwUm+I6vk5grrNsCOzGmYSmF4EOhsR5M0Dz/nNRr3SjGNwbOz Zrz9ETn++eeyT34cNF3EWEKoF1iRe8p5A9VN5PrEYEkfcn5xOOVrVxFRzcaiIOekLG8V H/K1yZT/Mkc/jX/5t30F+btddzRffyi9MYm6JMrcP0ztiy0SxsDNfWrzmAjjMnBq9Kuj kYfpPnDdb3ik69kZ5S4tH9REq5xbMdBs1WhzlS2zP00LmnKegPk4wlIljjRYYIW8wbD5 9iys37OfYumj/hCe+731YYoRp/UO2nXZ+K/3Lk3DvmasYy/PgjlRbaFjBAnUBXUsTXhI Rr4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CiAlOV2oRbz+VZO/tptorF+KuBCIfAyji69OyNiRK7M=; b=CXS4218pe+y/yeIw6fbRLAUYpsgVhdiuaHjq5BPBwMnzNPTACfBrerPO6FerUR62oR iZ0eBF7PR+7Ve2R7cykYDzs/Xkqal/OofQwKyuRNoqPsXenQ2RBF5VJaJtmzdjGkbUo5 FYQ/FTxb8RnijTdZt1daOnuB9OgX+gelVbaH2CJBMGiVhkcFrLLMm3rE1Y56Yj5F9d19 1U1E5cbgtHvEFRO1p57E9PrHtqGLy56nZBoGTJJ2irHBLZ6BBqUMemoqy6Y5NcWWRh4Z jS49SLG8MtMp+yEpZZrGOr2CpwBhcLM0ON8H/6PnReY4U8+f4xRXTRCe8mu5ji8rp4is n+Rw== X-Gm-Message-State: ALQs6tCRKEA3P/a1jMwue004quH7dDjLedin1C8s1r4SzRr06m4Y/L9C bBB8E9U5UCEDwM/W40eh/r0= X-Received: by 10.98.31.3 with SMTP id f3mr15178813pff.213.1525247699432; Wed, 02 May 2018 00:54:59 -0700 (PDT) Received: from localhost (outboundhk.mxmail.xiaomi.com. [207.226.244.123]) by smtp.gmail.com with ESMTPSA id k7-v6sm10922676pgc.42.2018.05.02.00.54.58 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 May 2018 00:54:59 -0700 (PDT) From: Ganesh Mahendran To: ldufour@linux.vnet.ibm.com, catalin.marinas@arm.com, will.deacon@arm.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ganesh Mahendran Subject: [PATCH 2/2] arm64/mm: add speculative page fault Date: Wed, 2 May 2018 15:54:32 +0800 Message-Id: <1525247672-2165-2-git-send-email-opensource.ganesh@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525247672-2165-1-git-send-email-opensource.ganesh@gmail.com> References: <1525247672-2165-1-git-send-email-opensource.ganesh@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch enables the speculative page fault on the arm64 architecture. I completed spf porting in 4.9. From the test result, we can see app launching time improved by about 10% in average. For the apps which have more than 50 threads, 15% or even more improvement can be got. Signed-off-by: Ganesh Mahendran --- This patch is on top of Laurent's v10 spf --- arch/arm64/mm/fault.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 4165485..e7992a3 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -322,11 +322,13 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re static int __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int mm_flags, unsigned long vm_flags, - struct task_struct *tsk) + struct task_struct *tsk, struct vm_area_struct *vma) { - struct vm_area_struct *vma; int fault; + if (!vma || !can_reuse_spf_vma(vma, addr)) + vma = find_vma(mm, addr); + vma = find_vma(mm, addr); fault = VM_FAULT_BADMAP; if (unlikely(!vma)) @@ -371,6 +373,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, int fault, major = 0; unsigned long vm_flags = VM_READ | VM_WRITE; unsigned int mm_flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; + struct vm_area_struct *vma; if (notify_page_fault(regs, esr)) return 0; @@ -409,6 +412,25 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); + if (IS_ENABLED(CONFIG_SPECULATIVE_PAGE_FAULT)) { + fault = handle_speculative_fault(mm, addr, mm_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 && + fault != VM_FAULT_SIGSEGV) { + perf_sw_event(PERF_COUNT_SW_SPF, 1, regs, addr); + goto done; + } + } else { + vma = NULL; + } + /* * As per x86, we may deadlock here. However, since the kernel only * validly references user space from well defined areas of the code, @@ -431,7 +453,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, #endif } - fault = __do_page_fault(mm, addr, mm_flags, vm_flags, tsk); + fault = __do_page_fault(mm, addr, mm_flags, vm_flags, tsk, vma); major |= fault & VM_FAULT_MAJOR; if (fault & VM_FAULT_RETRY) { @@ -454,11 +476,21 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, if (mm_flags & FAULT_FLAG_ALLOW_RETRY) { mm_flags &= ~FAULT_FLAG_ALLOW_RETRY; mm_flags |= FAULT_FLAG_TRIED; + + /* + * 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; } } up_read(&mm->mmap_sem); +done: + /* * Handle the "normal" (no error) case first. */ -- 1.9.1