Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp577471pxf; Wed, 7 Apr 2021 06:52:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaf1TNM8owQ164whVcEBxytmTxZ3rGwXB7aJp8ikltp/dDmBXRx0V2+JhORVVjoxkFlCyh X-Received: by 2002:a17:906:f283:: with SMTP id gu3mr3780776ejb.91.1617803541549; Wed, 07 Apr 2021 06:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617803541; cv=none; d=google.com; s=arc-20160816; b=upYGXA+sVH4UmvDgUmHp1q709gudyMAaRzzg5H9JkoGxpcsZrr0YG7w43fXnnHyR+J vhAFEd31wXbPsuTXSacR7CTtqSGRjmqtFONbc91kYK7BSVx7DQ5jynV6p2lWMdwiuxIv HwaGkXYgAR0OMZqGWiE89ZZEQIld7NGXHe8W4iq9Q9Fy8JMInJWB8qD15O/WQKF7aEjr Clg0kvFAR4RWyzSl2mjb4S8FmDyMPE+1WcMVNj0roeX3El/LVvB+pMK7r7WuSngIo+pl L0Kusme+tvq3gUi80cXJMk0LGBuoblnbwP+pph9wXBvwkfnUIeXHFRq9vuuplFueJYYO 8tUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=1pcgL6msPKrfTRZ1fn8ZYvCmKEa5WSF8jkX3M1HqC8Q=; b=gkxef0icu9CKUvcBGT3IUbqlyoLVidKoWHDEJLmlyVAGehmWD6+YLmmkfHtftlQVRK 62vavJDzP2SkGxBLA6cUQ5CWguv9cKQrXzpPSWdL+XqReXmmXn1caPG2+rAIKmTLHh14 wySV+kvdiAQEtHwXxN/Dtypnw/2krgdnkRPG7QJwxXnwUV0WrSmD9L0vA/JP4+lhYeS1 t6yii9n7l6/KdNCmeTKYUCkFnbaWBeVJkvk3BGl2fd8IKMwpuNViN60u5DO4BKBwhqyX vMhRIfmFj94ugaEBXne9G6qxAHVXGfHdMnC67N5eCvZj0oMUXUJLYXdOinG3XhGN+rUB ZAeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org header.s=srv-11-ed header.b=hQvw4qVA; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b="iNI/FbYx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lespinasse.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bc27si12719243edb.130.2021.04.07.06.51.58; Wed, 07 Apr 2021 06:52:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org header.s=srv-11-ed header.b=hQvw4qVA; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b="iNI/FbYx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lespinasse.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347962AbhDGBw3 (ORCPT + 99 others); Tue, 6 Apr 2021 21:52:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347828AbhDGBvv (ORCPT ); Tue, 6 Apr 2021 21:51:51 -0400 Received: from server.lespinasse.org (unknown [IPv6:2602:303:fcdc:ce10::100:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D8CEC06174A for ; Tue, 6 Apr 2021 18:51:40 -0700 (PDT) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-11-ed; t=1617759903; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=1pcgL6msPKrfTRZ1fn8ZYvCmKEa5WSF8jkX3M1HqC8Q=; b=hQvw4qVAk9RjFRT0YurEoXBUfSyibVWfDTUoCsMeXQbkWLv85cnNBgYIduwwAJSYkk9nX dBueIiIj6nFh/usBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-11-rsa; t=1617759903; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=1pcgL6msPKrfTRZ1fn8ZYvCmKEa5WSF8jkX3M1HqC8Q=; b=iNI/FbYx7Xyn86mRVSOET3lACzR7zhpyLEsLKAwjwO+52vhn4w0U0kT1L0VFRgTFDJbI2 H+KlbaIoIomCY6TbjUUQPaYfgiJ6rZVCYGClP+LomXZzhbY1WTNzfv3hZEwwzs92mNG7C+v GP9g4TVH4xBdqqSwehvTgygusMqE2oUqC2cGKIhgfVDEQJW/t4ekzDi26VXIW9QP8njhll6 W0l7WVqhhxQ27zpWV/j/6rOgMkyYz/GQG816a5JEhhLkMGlGgeM+ljwkBxELBaJJrztnNGD dspGKP7paDbt7nX+v18rbCFEypfvuS9gOBP0r6AEOcN+wfVRX8sB8ybKE+HA== Received: from zeus.lespinasse.org (zeus.lespinasse.org [IPv6:fd00::150:0]) by server.lespinasse.org (Postfix) with ESMTPS id 7880A1606A3; Tue, 6 Apr 2021 18:45:03 -0700 (PDT) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id 673BE19F320; Tue, 6 Apr 2021 18:45:03 -0700 (PDT) From: Michel Lespinasse To: Linux-MM Cc: Laurent Dufour , Peter Zijlstra , Michal Hocko , Matthew Wilcox , Rik van Riel , Paul McKenney , Andrew Morton , Suren Baghdasaryan , Joel Fernandes , Rom Lemarchand , Linux-Kernel , Michel Lespinasse Subject: [RFC PATCH 37/37] arm64/mm: attempt speculative mm faults first Date: Tue, 6 Apr 2021 18:45:02 -0700 Message-Id: <20210407014502.24091-38-michel@lespinasse.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210407014502.24091-1-michel@lespinasse.org> References: <20210407014502.24091-1-michel@lespinasse.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Attempt speculative mm fault handling first, and fall back to the existing (non-speculative) code if that fails. This follows the lines of the x86 speculative fault handling code, but with some minor arch differences such as the way that the VM_FAULT_BADACCESS case is handled. Signed-off-by: Michel Lespinasse --- arch/arm64/mm/fault.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index f37d4e3830b7..3757bfbb457a 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -530,6 +531,9 @@ static int __kprobes do_page_fault(unsigned long far, unsigned int esr, unsigned long vm_flags = VM_ACCESS_FLAGS; unsigned int mm_flags = FAULT_FLAG_DEFAULT; unsigned long addr = untagged_addr(far); + struct vm_area_struct *vma; + struct vm_area_struct pvma; + unsigned long seq; if (kprobe_page_fault(regs, esr)) return 0; @@ -564,6 +568,53 @@ static int __kprobes do_page_fault(unsigned long far, unsigned int esr, perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); + /* Only try spf for multithreaded user space faults. */ + if (!(mm_flags & FAULT_FLAG_USER) || atomic_read(&mm->mm_users) == 1) + goto no_spf; + + count_vm_event(SPF_ATTEMPT); + seq = mmap_seq_read_start(mm); + if (seq & 1) { + count_vm_spf_event(SPF_ABORT_ODD); + goto spf_abort; + } + rcu_read_lock(); + vma = find_vma(mm, addr); + if (!vma || vma->vm_start > addr) { + rcu_read_unlock(); + count_vm_spf_event(SPF_ABORT_UNMAPPED); + goto spf_abort; + } + if (!vma_can_speculate(vma, mm_flags)) { + rcu_read_unlock(); + count_vm_spf_event(SPF_ABORT_NO_SPECULATE); + goto spf_abort; + } + pvma = *vma; + rcu_read_unlock(); + if (!mmap_seq_read_check(mm, seq, SPF_ABORT_VMA_COPY)) + goto spf_abort; + vma = &pvma; + if (!(vma->vm_flags & vm_flags)) { + count_vm_spf_event(SPF_ABORT_ACCESS_ERROR); + goto spf_abort; + } + fault = do_handle_mm_fault(vma, addr & PAGE_MASK, + mm_flags | FAULT_FLAG_SPECULATIVE, seq, regs); + + /* Quick path to respond to signals */ + if (fault_signal_pending(fault, regs)) { + if (!user_mode(regs)) + goto no_context; + return 0; + } + if (!(fault & VM_FAULT_RETRY)) + goto done; + +spf_abort: + count_vm_event(SPF_ABORT); +no_spf: + /* * As per x86, we may deadlock here. However, since the kernel only * validly references user space from well defined areas of the code, @@ -604,6 +655,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned int esr, } } mmap_read_unlock(mm); +done: /* * Handle the "normal" (no error) case first. -- 2.20.1