Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp740305pxf; Wed, 7 Apr 2021 10:20:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjef3Fvy+vb44qU8knHyRf7KCAKuSUphdeE0Cuz/owX1kvFCpik6LcxY4pqUztyvi/vDrX X-Received: by 2002:a05:6638:2390:: with SMTP id q16mr4561032jat.27.1617816014837; Wed, 07 Apr 2021 10:20:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617816014; cv=none; d=google.com; s=arc-20160816; b=WzgsqfyUWjJRbMfPpV0MU9z4Gk2eb9k3XQBFWAZKZS57CSfjm0z09KJIkdELnRQy4J GMh0XtwkclA5fFpD3M1STdcjHjezcy9CLEaJ/AFIswuF53GaD2u3VBuA0kgDBx4AK5SU 91poaE6136PBKoN1bBbFXMCh5DuPdfb67UEBb06SuqmaM6xBd2xC9JSC4SAUrJ/rhQhm jQCHpWGhT5pLQMQzXcJ/wyf2bppJ/BGiOqps9fZwnfo8Wr8Kn2HRmD5L9wCd3gRpeJn1 q1D8friR8jNlkObBN9cQOpzAUAbMOO7jXqZs5W8jKcY1//EqN2j3bMW6hLdLrysCo7s/ +b0w== 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=JYD3Wgnyn5x/hzU8kfQiO6ZPV5GuIxiA+PXDzohUvGA=; b=A/uAcxh9qy55b3z76NPXn3Xo4GRvl4aYWwIzGLKDaNpsfUst1XR2n/bZaY77gyYK9H cmkc7w9Gc1SWEGlDsrB+8+x1SUIEnyHuv/WE1sOYsGX8cT05FnaBz0s3jl/mAnfzDEsR bu0VH84SgG7+FF2/QhwLMhtldBrUuFB3bfYl29Wimf9sbIBIGdWZCiaN3mTX2bRRIsdz ymuHs+6d++q0nyZ9lngvKCHkksyaSgoMbqFK9rDjwv3T0xR8MMMe08cmPBdlx5+MPget Hf7zaB1NKhji3jyFsIDvMESa3cCOnnpaYNdSx5YCkyzIvdzz6PrNIwDcw3j1eK8dVu3K GB0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org header.s=srv-11-ed header.b=zcbm6TYG; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b=lMWJGAHO; 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 w18si20971409iod.102.2021.04.07.10.20.02; Wed, 07 Apr 2021 10:20:14 -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=zcbm6TYG; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-11-rsa header.b=lMWJGAHO; 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 S1348039AbhDGBxe (ORCPT + 99 others); Tue, 6 Apr 2021 21:53:34 -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 S241481AbhDGBvx (ORCPT ); Tue, 6 Apr 2021 21:51:53 -0400 Received: from server.lespinasse.org (unknown [IPv6:2602:303:fcdc:ce10::100:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAAECC0613DA for ; Tue, 6 Apr 2021 18:51:41 -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=JYD3Wgnyn5x/hzU8kfQiO6ZPV5GuIxiA+PXDzohUvGA=; b=zcbm6TYGSbg1fogm0a+YNIILcHGu1mT6vUKLDLx8xjYgGqbgnupaWpyFUw2L92FSmnjah aEpUwZWtViFUqIICw== 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=JYD3Wgnyn5x/hzU8kfQiO6ZPV5GuIxiA+PXDzohUvGA=; b=lMWJGAHOqeFns527xMlZ3Fyq6hnMk8R4Zi2s4J9BM4hIMv3x4lvNwIXSLvh4Re3SmRDIp QGdMUOLpTfyjweRiRr7ZfG6L/r96l8Q2zb9f40lLLvOEJjDy1dbzpNDwgBwHsux6qykTCmt XjTi6WRidOzS4QLMOOBd6GxKcUgtXKRBWI37pGuwdjraLXfHcYfFMJa4SA38fN+jOoYr5GQ klq7PozMEUef5/a5ixDM0l4FrhbuhaVk3X4jtOHqYrc8HtYOqWZJCPiDRK9waQs5f1YlVvU hH4vEg45qTroyA2tacBcSHTZIlQxGzBz9XwxiZT/OV1aW6mLHzBgv+owcBbQ== Received: from zeus.lespinasse.org (zeus.lespinasse.org [IPv6:fd00::150:0]) by server.lespinasse.org (Postfix) with ESMTPS id 274A0160390; Tue, 6 Apr 2021 18:45:03 -0700 (PDT) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id 17FCA19F31E; 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 26/37] mm: implement speculative fault handling in finish_fault() Date: Tue, 6 Apr 2021 18:44:51 -0700 Message-Id: <20210407014502.24091-27-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 the speculative case, we want to avoid direct pmd checks (which would require some extra synchronization to be safe), and rely on pte_map_lock which will both lock the page table and verify that the pmd has not changed from its initial value. Signed-off-by: Michel Lespinasse --- mm/memory.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7139004c624d..13e2aaf900e5 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3915,23 +3915,25 @@ vm_fault_t finish_fault(struct vm_fault *vmf) return ret; } - if (pmd_none(*vmf->pmd)) { - if (PageTransCompound(page)) { - ret = do_set_pmd(vmf, page); - if (ret != VM_FAULT_FALLBACK) - return ret; + if (!(vmf->flags & FAULT_FLAG_SPECULATIVE)) { + if (pmd_none(*vmf->pmd)) { + if (PageTransCompound(page)) { + ret = do_set_pmd(vmf, page); + if (ret != VM_FAULT_FALLBACK) + return ret; + } + + if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd))) + return VM_FAULT_OOM; } - if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd))) - return VM_FAULT_OOM; + /* See comment in __handle_mm_fault() */ + if (pmd_devmap_trans_unstable(vmf->pmd)) + return 0; } - /* See comment in __handle_mm_fault() */ - if (pmd_devmap_trans_unstable(vmf->pmd)) - return 0; - - vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, - vmf->address, &vmf->ptl); + if (!pte_map_lock(vmf)) + return VM_FAULT_RETRY; ret = 0; /* Re-check under ptl */ if (likely(pte_none(*vmf->pte))) -- 2.20.1