Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp722308pxf; Wed, 7 Apr 2021 09:57:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4fu3fY6jTjB8WkLBX3ji/nggKO4HhNEtOy5RNxIFOTyiIzuKESbF+0PX7DoDMbDiUCAhe X-Received: by 2002:a05:6402:254a:: with SMTP id l10mr5648923edb.160.1617814639158; Wed, 07 Apr 2021 09:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617814639; cv=none; d=google.com; s=arc-20160816; b=m8HSYY6OS8TQ32rZDkDyGZxpCETo9VsGzqmBSdiiTCP6wYBUjSKk4BoZGcF+ONhVyF pqHQI6/U+4Alo4sv5KkwihAHp3Iamiux8I1B+Ti+aEDXFickz0iKV0eQGglwKj8NBnMA 0AVLITmHGpOCdPEkMH5yWW17S2a36kaMKz0QY3mc86Ak7s5rd2+g/12xaT0EBFWW0i1B 1xQiGIghL70q8OR8GS8BnsdWyuSy3h3lKu45VKMRwQJF6O27fVuncdnjo4blYHw+WzDw 2+etxwxvEYo0emvYy8gwEAOiEBKIFbu/F+xwCVGNO0X/egOVUHHOsZ0dKJP+L5gaCYqy iBpw== 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=8COoG1kyMAyzmcjmtCVhUuZfAMmUT556bb2lAEkl2Jk=; b=rgJfA7atxyWVJGj2afMHPFdmgo3a9+FfvEYpL1/hkcHepVhRdTM8kN3y/ZUnzxDt0v I4nBvv6Mp2hxKX+as3oh81i6tXyJts4s31dyDqEIR7GfgDaVshimylrYERdXZptJFdiU N44GZH9hgyblwgrEWzQE6RXB0Ir1f6Q1S8xlqLpQn4gMUqpapnN0/kWEBwiNtmfTcVX6 9zTI94sCmDMBJwn3xPTw16w/8R/ODToCZiamAT8by3GJgPcbF9co4rIdmoCXIzv0xuht t+n/bvlHYbDEWywpP2feGdglht6vIx4sQaqKjnFviR2KbhS6d2IcMQhAPTvC3ZjaruOU H5iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org header.s=srv-11-ed header.b=PHxlIUq8; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b=Xj0qGgON; 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 z10si14412394edd.211.2021.04.07.09.56.55; Wed, 07 Apr 2021 09:57:19 -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=PHxlIUq8; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b=Xj0qGgON; 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 S1347954AbhDGBw1 (ORCPT + 99 others); Tue, 6 Apr 2021 21:52:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347831AbhDGBvv (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 C6372C061762 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=8COoG1kyMAyzmcjmtCVhUuZfAMmUT556bb2lAEkl2Jk=; b=PHxlIUq8Gez4GGg1T1vZB3f/iGsF8+rBmKPA5lGRVNAhdo4q0AcUCTl4jG0ud1ymS98BV pXuyifekidg4jc1BQ== 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=8COoG1kyMAyzmcjmtCVhUuZfAMmUT556bb2lAEkl2Jk=; b=Xj0qGgONLfNk5zEaM5IEBqutABXQbilGjAJuQCGy/NJElYzNQNWVz/qj9s1C6jR2zMKsp CjgSDeSQCsFCM+kAwSicmrOf/jMLccvhMVOhjghOl1FsBmbeoi8ks/+cPqSCRaAA0S5gXBo wH6j2k0bx/8iypailFquYrsYVPFz097+Hi4V3IjA75FYXoRM5H3/nt2VmtdgV28sESHbThT nPem9Matb4e4goClyC4hD+hIaDWZ5mKOjFOWWWxDQ0KasRhTnPowHxV9A95siPdM+tgbJcM rKG/7yOOiDxRufdYxGz6E0iQRg9rMSq43GJ4K/9MnRhNIYT5b2usXjV3CPcA== Received: from zeus.lespinasse.org (zeus.lespinasse.org [10.0.0.150]) by server.lespinasse.org (Postfix) with ESMTPS id E7B4016031A; Tue, 6 Apr 2021 18:45:02 -0700 (PDT) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id D9CBE19F31D; 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 19/37] mm: implement speculative handling in wp_page_copy() Date: Tue, 6 Apr 2021 18:44:44 -0700 Message-Id: <20210407014502.24091-20-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 wp_page_copy() to handle the speculative case. This involves aborting speculative faults if they have to allocate an anon_vma, and using pte_map_lock() instead of pte_offset_map_lock() to complete the page fault. Also change call sites to clear vmf->pte after unmapping the page table, in order to satisfy pte_map_lock()'s preconditions. Signed-off-by: Michel Lespinasse --- mm/memory.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index eea72bd78d06..547d9d0ee962 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2911,20 +2911,27 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) pte_t entry; int page_copied = 0; struct mmu_notifier_range range; + vm_fault_t ret = VM_FAULT_OOM; - if (unlikely(anon_vma_prepare(vma))) - goto oom; + if (unlikely(!vma->anon_vma)) { + if (vmf->flags & FAULT_FLAG_SPECULATIVE) { + ret = VM_FAULT_RETRY; + goto out; + } + if (__anon_vma_prepare(vma)) + goto out; + } if (is_zero_pfn(pte_pfn(vmf->orig_pte))) { new_page = alloc_zeroed_user_highpage_movable(vma, vmf->address); if (!new_page) - goto oom; + goto out; } else { new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address); if (!new_page) - goto oom; + goto out; if (!cow_user_page(new_page, old_page, vmf)) { /* @@ -2941,7 +2948,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) } if (mem_cgroup_charge(new_page, mm, GFP_KERNEL)) - goto oom_free_new; + goto out_free_new; cgroup_throttle_swaprate(new_page, GFP_KERNEL); __SetPageUptodate(new_page); @@ -2954,7 +2961,11 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) /* * Re-check the pte - we dropped the lock */ - vmf->pte = pte_offset_map_lock(mm, vmf->pmd, vmf->address, &vmf->ptl); + if (!pte_map_lock(vmf)) { + ret = VM_FAULT_RETRY; + /* put_page() will uncharge the page */ + goto out_free_new; + } if (likely(pte_same(*vmf->pte, vmf->orig_pte))) { if (old_page) { if (!PageAnon(old_page)) { @@ -3042,12 +3053,12 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) put_page(old_page); } return page_copied ? VM_FAULT_WRITE : 0; -oom_free_new: +out_free_new: put_page(new_page); -oom: +out: if (old_page) put_page(old_page); - return VM_FAULT_OOM; + return ret; } /** @@ -3190,6 +3201,7 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) return wp_pfn_shared(vmf); pte_unmap_unlock(vmf->pte, vmf->ptl); + vmf->pte = NULL; return wp_page_copy(vmf); } @@ -3228,6 +3240,7 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) get_page(vmf->page); pte_unmap_unlock(vmf->pte, vmf->ptl); + vmf->pte = NULL; return wp_page_copy(vmf); } -- 2.20.1