Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp721663pxf; Wed, 7 Apr 2021 09:56:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/1ty5HCs52XdvsO2n+8dLUf1QKDE4gDdkj5VaV7/aak/QKHSf5xiEIN5hLZw1TFNTQ/3k X-Received: by 2002:a17:906:2e14:: with SMTP id n20mr4749171eji.16.1617814581699; Wed, 07 Apr 2021 09:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617814581; cv=none; d=google.com; s=arc-20160816; b=qo9BKQCQEp9beJka3tcRtbxxruebdkF2xupre/0ZJPGN7o6D7wkeuSL+cZlx22QSwq wzQjjnEzlN/Xrd5CtdVdOJ6XMETL/LMBSDHvgHgC/OSWMhge5420w9SRXwV7tv4bdPub 8NJk+M5jIZlD7Eo0QFussgRaQB/HpsawG/XMlqw95aP/dQfDxQi8QGbS5F7K6luKhd26 fFM7sKXr5BVkedpMYPlruhNeYvX3AxxmVNBvRuhafyveTNNd79UeZQDpUHNPy7d8DhWt /6bM8gFnBbXy6tRTAfWcGwFtDvCJGAl9qvH+r7QVvdIDAvqzoVLNGQun6GI3R9uz0IIE dzPA== 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=Iko8U1DIjbSXvB60SArqfpM0eO/JE4XY/9ww0rF5/tY=; b=tGOXFL4z7zbLVv3EGdyZ86HIXVJmy/04iuivkWezke2pIk5K8JuO/CmMTJntSLSZl+ +3jSHTwSzaubupxtuVEIc9qSB9wCfbdS/T6MPxlhzTGNJu98oWlDhaxjamMi1EtgS0yZ n1bL6K2RYfJairXiM8zhaZ4INlqhRoqK08fxMvKiAQfKR0LnaUwGGHln0c89dVwhiBmI Ct/cZigqUs60eC1/aroSdRin2cwrZCzmwSVHY6Fr22yWkKhqK5370DS3q5zGs+RN6ar2 E6zH+GMeyPaQv2RdK6Of9eOhJ9/zmXpXHcD4avHI6kLcbbvnRuxjEVEr3sjINRwCyDrV HCig== 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-11-rsa header.b=dQPZHYw1; 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 mt16si12737329ejc.423.2021.04.07.09.55.57; Wed, 07 Apr 2021 09:56: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; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b=dQPZHYw1; 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 S1347856AbhDGBvw (ORCPT + 99 others); Tue, 6 Apr 2021 21:51:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343615AbhDGBvs (ORCPT ); Tue, 6 Apr 2021 21:51:48 -0400 X-Greylist: delayed 398 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 06 Apr 2021 18:51:40 PDT Received: from server.lespinasse.org (unknown [IPv6:2602:303:fcdc:ce10::100:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30E73C06174A 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=1617759902; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=Iko8U1DIjbSXvB60SArqfpM0eO/JE4XY/9ww0rF5/tY=; b=JVh6JjMxzNn89HcbkhtljBCgR0nVPb//5K8shZAbIxj2Lntf8NNBDz3YEx3UFhO1kxgKJ 5YqE9FEx0+LD369DQ== 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=Iko8U1DIjbSXvB60SArqfpM0eO/JE4XY/9ww0rF5/tY=; b=dQPZHYw1jXJV689ACtM7eUIebt/kBXCd1dvdwBsYusq7L0GLbnqv2wFVikzZALG4eQHo0 hoYZ698ZhW9JVnYeTvVtYzKqNbyqh3sPMi8zirwDBwYhqXnd3a1YM2zYR+HuhFYu7FhwnJk VxWIMqJfqNWERV00aB2/UL2n2xZ2W6Rk2nQIPywaAzkmH+w2K6j4UepxDlR4xyiX9KSqoF0 lAwEqlEnrdlUjWpgBD+rlPCDDg75oOc+D9ZigT09EvxvepHfigE3X9S5ubzIc+GPWGt8qAy nyTOnIaOpDbdhTh2qphkLIKriI8niYvWYpvqDBXm8jrwEDynAzF4+3+P9+LQ== Received: from zeus.lespinasse.org (zeus.lespinasse.org [10.0.0.150]) by server.lespinasse.org (Postfix) with ESMTPS id CE9BA1602D7; Tue, 6 Apr 2021 18:45:02 -0700 (PDT) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id BE65319F31F; 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 15/37] mm: implement speculative handling in do_anonymous_page() Date: Tue, 6 Apr 2021 18:44:40 -0700 Message-Id: <20210407014502.24091-16-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 Change do_anonymous_page() to handle the speculative case. This involves aborting speculative faults if they have to allocate a new anon_vma, and using pte_map_lock() instead of pte_offset_map_lock() to complete the page fault. Signed-off-by: Michel Lespinasse --- mm/memory.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 3e192d5f89a6..fd84576f9c01 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3598,8 +3598,12 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) vma->vm_page_prot)); } else { /* Allocate our own private page. */ - if (unlikely(anon_vma_prepare(vma))) - goto oom; + if (unlikely(!vma->anon_vma)) { + if (vmf->flags & FAULT_FLAG_SPECULATIVE) + return VM_FAULT_RETRY; + if (__anon_vma_prepare(vma)) + goto oom; + } page = alloc_zeroed_user_highpage_movable(vma, vmf->address); if (!page) goto oom; @@ -3620,8 +3624,10 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) entry = pte_mkwrite(pte_mkdirty(entry)); } - vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, - &vmf->ptl); + if (!pte_map_lock(vmf)) { + ret = VM_FAULT_RETRY; + goto release; + } if (!pte_none(*vmf->pte)) { update_mmu_tlb(vma, vmf->address, vmf->pte); goto unlock; @@ -3636,6 +3642,8 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) pte_unmap_unlock(vmf->pte, vmf->ptl); if (page) put_page(page); + if (vmf->flags & FAULT_FLAG_SPECULATIVE) + return VM_FAULT_RETRY; return handle_userfault(vmf, VM_UFFD_MISSING); } @@ -3653,6 +3661,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) return 0; unlock: pte_unmap_unlock(vmf->pte, vmf->ptl); +release: if (page) put_page(page); return ret; -- 2.20.1