Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp636325pxy; Fri, 30 Apr 2021 12:55:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuaWovS3CmHMadGn1sHEA5UhgtUMHhCHqGzyyVhOjVLJxavCHDOrxC8Nv2ND+Uy4z6pZay X-Received: by 2002:a17:90a:8592:: with SMTP id m18mr16170222pjn.165.1619812540753; Fri, 30 Apr 2021 12:55:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619812540; cv=none; d=google.com; s=arc-20160816; b=qsRB1bSK4q8nMh+ddSfWKzxO0Y+aWY9YLtkWqZDoOnuh4lnE49Uvxd8loE0vmHhHDY sFJTYk8NovZs2WlALNH0x2LXY7C2z2AoptiMhSG8pVRwj97bo1vnBOTq8hTH8TDup4R/ ciDFKpntPtwAGdDKPffHbOg5r4AnvhDsEs/kQB4ZVDCCw4PSxSHUdMdRUAmpdtIIS7wM ZNGvF/vEKHQT3AVsvRLmZDb78eDI7t6zJxHqXnD17wnuKLfGR5IsLKoIsHybS2fcZ+AD TvK4VGg4HgN3far+HhgH9deg1+ouwl00CTkjH1KTOJw5DJiA4vpuODznxrWXvT2RrvRj naUA== 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=M/Ev9iks2mpuHbjoGtjSBN2w1TDQW6+EFN9w5Lcsf9s=; b=jbmKYF3xMMROkx7XRBNLjR++4Su+PSVejJXYZZEtvrbVJ/H21Zrc7H+L1BK6VdMAV6 6fHwPZfUWPtV43CH0FosraHS+/+yhn+ftkXhdiob+yRJbRzR6YbZOp3RImLDdjDvX/G4 iGsDtoqS6/opbzIXX1v+qy/dJ4SV6N9T6aFE3aSw0vcy9OtW6eYHKyRe6wBQKClBrKMD mYf9Yn7o4irshq1DTzGjEnI3QZZkVIU319640FVJA1YUa0WdhYioZ1RBnOmnkh3+iY7O Sq+ng1GYTaBqZWTBsIechARtbvCYtngw3fQ39sxK4Kdoj0U6jqiYzZMklpPvXVyzb7R2 UDLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-14-rsa header.b=MN4K5XVl; 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 k6si4871883plk.398.2021.04.30.12.55.28; Fri, 30 Apr 2021 12:55:40 -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; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-14-rsa header.b=MN4K5XVl; 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 S233726AbhD3TyF (ORCPT + 99 others); Fri, 30 Apr 2021 15:54:05 -0400 Received: from server.lespinasse.org ([63.205.204.226]:44335 "EHLO server.lespinasse.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232400AbhD3Tx3 (ORCPT ); Fri, 30 Apr 2021 15:53:29 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-14-ed; t=1619812353; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=M/Ev9iks2mpuHbjoGtjSBN2w1TDQW6+EFN9w5Lcsf9s=; b=qorJ25mBWnaXh0kvHjZNSgrUysLUviTXD8V7S8+PwBGxSEadwdDSK9yKOVct7cU71wJ+c lJxszXP8H/LLEEjBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-14-rsa; t=1619812353; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=M/Ev9iks2mpuHbjoGtjSBN2w1TDQW6+EFN9w5Lcsf9s=; b=MN4K5XVli33rheSlcHq6WD+tJr0i33+3ECUXM250WDhfV/hi/b9nxA2FOVZ2OJ4c29FMR PyUziXaigVfVLZ1msDdWuOEdkbN3if8wd+k7eOw4ytg1Hxosv0a4tz95lFMYMjH2RiIZHgX /A+eAocU1836zWv3dQ21RQfQGT5kn7sVQa9NF8CJ+0ZfoRMvHeEO0fZjcI4/tALfGyNfpiK LLM0GR1pOO3Bk/qWTd68h7gbggzMpcm0odD7zAxxEftdcjUxSyIh1TK5iMS0d2YrvWzYXfA FeEzFo+fcTRfEqx93bgoQS6GbIIwnE2+6cPHHMwNSOpAI7T5V02hJNd1PxDw== Received: from zeus.lespinasse.org (zeus.lespinasse.org [IPv6:fd00::150:0]) by server.lespinasse.org (Postfix) with ESMTPS id 85DF616032B; Fri, 30 Apr 2021 12:52:33 -0700 (PDT) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id 765F619F521; Fri, 30 Apr 2021 12:52:33 -0700 (PDT) From: Michel Lespinasse To: Linux-MM , Linux-Kernel Cc: Laurent Dufour , Peter Zijlstra , Michal Hocko , Matthew Wilcox , Rik van Riel , Paul McKenney , Andrew Morton , Suren Baghdasaryan , Joel Fernandes , Andy Lutomirski , Michel Lespinasse Subject: [PATCH 18/29] mm: enable speculative fault handling through do_anonymous_page() Date: Fri, 30 Apr 2021 12:52:19 -0700 Message-Id: <20210430195232.30491-19-michel@lespinasse.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210430195232.30491-1-michel@lespinasse.org> References: <20210430195232.30491-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 0e8abe43d032..463061186827 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1327,7 +1327,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 d95826c48f1d..eceb1b6e904c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4120,6 +4120,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 */ @@ -4357,6 +4359,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); @@ -4685,8 +4692,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); @@ -4708,10 +4714,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