Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp735241pxf; Wed, 7 Apr 2021 10:13:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwde61G9DV3lfvbf14Cr093vu0/PnpDFEBphVt9/LGbXlR3oPslA+ecX+pBFoJgR7dl+pK5 X-Received: by 2002:a92:6e0e:: with SMTP id j14mr3512402ilc.90.1617815622901; Wed, 07 Apr 2021 10:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617815622; cv=none; d=google.com; s=arc-20160816; b=XBjeiwZfUcebtEqdbYmh2l8k9ad2e38SS3dHOnqiLOcnZRQDG0ICVTDMWk5/eIIoQA kIrDzq0DPHkTJzzj5mGsTM+y5rWWjWAOJ/2IYwR3gkkc3U/lmOl7hv68IzkSf8U6wl62 ewJDtNAfDRcLYoRBiCKWVvYCSSU/0qkzG1kq3Fua9rkckKsE+YWZYJ7zLTQqEUV+1AaR 8ITeLh63ibizgiIAMISflnK9al40Eq2LtaYv/rRUvpKmc9kWPTa6vnBHFZYVWkz/QpQI +Mocwa4illZjyGe+vNboMJnD2CFvnWuLrc9c+FKH3lEVwWFAg/Nu7/kti5pJ7oPBLxoM 7DuA== 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=Mm4sRKZ9oPWWjYrlQVTDWSlP7K2SJOXE1Iezs0Haf/4=; b=tk4j8g6qqGffhhNe92TiOdc1hKrkujazsTnqRBcrmMMY1S9ayGWrUdineh/2lBs9LO M0W/ZUJ9edfT8hVWBrZMMaz5yHuMd3RcKignzS7oOYybM/bk64ByqQIsTQQYa2pJfUEg 0uEJ+CFZtUL+sRvzV4dIKoOB1bkKrAPX27W9QKTVGBfzyitXZX9TM+zyT1vVGd+4nd17 orwTD3Tu+mJxYe8tpTRe7Xl/eVNkWtcVuuwvI7OrO2v1mk/foPX+UmmM4wIa8gsKwOr2 Le2/zDMaszB55qzrbQ+CDgLd3cI4G2XORKdFIQkg15xDJgCNjcxXuUQMl+bs5do8WMvV DQ6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org header.b=hJKxBzc+; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b=oNyM6JjS; 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 y18si4478156ili.52.2021.04.07.10.13.30; Wed, 07 Apr 2021 10:13:42 -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.b=hJKxBzc+; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b=oNyM6JjS; 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 S1347927AbhDGBwL (ORCPT + 99 others); Tue, 6 Apr 2021 21:52:11 -0400 Received: from server.lespinasse.org ([63.205.204.226]:44459 "EHLO server.lespinasse.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347808AbhDGBvu (ORCPT ); Tue, 6 Apr 2021 21:51:50 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-11-ed; t=1617759902; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=Mm4sRKZ9oPWWjYrlQVTDWSlP7K2SJOXE1Iezs0Haf/4=; b=hJKxBzc+YjcRxjNqDuMMXauTqpgX6EMXmblbyYlLywC9uaLxI4Z+Bio3AkTWuAVx/1JC4 4hIOBBUYzycNFX2Aw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-11-rsa; t=1617759902; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=Mm4sRKZ9oPWWjYrlQVTDWSlP7K2SJOXE1Iezs0Haf/4=; b=oNyM6JjSd6DoO5pFFb7RFw2adq0RuCvDIcOprNuCa7GNE9NteCWGBTYF1RjLLOYs5q6NG hyyyt+UrHy8Svrf6p35yGy6pUQg6E26BAYUi1wuMWsq24vIL4XqSvQhJ449QW2yaNFTEHDX eX4Bs6oSx9b4ZiV2n/gVaK7o28yIR31cY2TMUdmFE2EBUx1WOe0xWBqcPcCZYRdp0ZSJLhb Tv1wO7MMA3GpFI6tr4H67khd0Kdb5EKmCcjdB4GXl5KjEwBkoI/dNUMuMVffJsBZYLvPWfy vrB3LR7z41KD9Pn3d3tMfA76/tU1tf90D+gAKXg8hwdc3LA9T7VTmlGsZh+A== Received: from zeus.lespinasse.org (zeus.lespinasse.org [IPv6:fd00::150:0]) by server.lespinasse.org (Postfix) with ESMTPS id D62311602F1; Tue, 6 Apr 2021 18:45:02 -0700 (PDT) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id C57F019F31E; Tue, 6 Apr 2021 18:45:02 -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 16/37] mm: enable speculative fault handling through do_anonymous_page() Date: Tue, 6 Apr 2021 18:44:41 -0700 Message-Id: <20210407014502.24091-17-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 in x86 fault handler, only attempt spf if the vma is anonymous. In do_handle_mm_fault(), let speculative page faults proceed as long as they fall into anonymous vmas. This enables the speculative handling code in __handle_mm_fault() and do_anonymous_page(). In handle_pte_fault(), if vmf->pte is set (the original pte was not pte_none), catch speculative faults and return VM_FAULT_RETRY as those cases are not implemented yet. Also assert that do_fault() is not reached in the speculative case. Signed-off-by: Michel Lespinasse --- arch/x86/mm/fault.c | 2 +- mm/memory.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index f8c8e325af77..fbf265f56a06 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1324,7 +1324,7 @@ void do_user_addr_fault(struct pt_regs *regs, goto spf_abort; rcu_read_lock(); vma = find_vma(mm, address); - if (!vma || vma->vm_start > address) { + if (!vma || vma->vm_start > address || !vma_is_anonymous(vma)) { rcu_read_unlock(); goto spf_abort; } diff --git a/mm/memory.c b/mm/memory.c index fd84576f9c01..a2c5bf29f989 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4103,6 +4103,8 @@ static vm_fault_t do_fault(struct vm_fault *vmf) struct mm_struct *vm_mm = vma->vm_mm; vm_fault_t ret; + VM_BUG_ON(vmf->flags & FAULT_FLAG_SPECULATIVE); + /* * The VMA was not fully populated on mmap() or missing VM_DONTEXPAND */ @@ -4340,6 +4342,11 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) return do_fault(vmf); } + if (vmf->flags & FAULT_FLAG_SPECULATIVE) { + pte_unmap(vmf->pte); + return VM_FAULT_RETRY; + } + if (!pte_present(vmf->orig_pte)) return do_swap_page(vmf); @@ -4668,8 +4675,7 @@ vm_fault_t do_handle_mm_fault(struct vm_area_struct *vma, { vm_fault_t ret; - if (flags & FAULT_FLAG_SPECULATIVE) - return VM_FAULT_RETRY; + VM_BUG_ON((flags & FAULT_FLAG_SPECULATIVE) && !vma_is_anonymous(vma)); __set_current_state(TASK_RUNNING); @@ -4691,10 +4697,12 @@ vm_fault_t do_handle_mm_fault(struct vm_area_struct *vma, if (flags & FAULT_FLAG_USER) mem_cgroup_enter_user_fault(); - if (unlikely(is_vm_hugetlb_page(vma))) + if (unlikely(is_vm_hugetlb_page(vma))) { + VM_BUG_ON(flags & FAULT_FLAG_SPECULATIVE); ret = hugetlb_fault(vma->vm_mm, vma, address, flags); - else + } else { ret = __handle_mm_fault(vma, address, flags, seq); + } if (flags & FAULT_FLAG_USER) { mem_cgroup_exit_user_fault(); -- 2.20.1