From patchwork Mon Jul 24 18:54:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13325266 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29A73C00528 for ; Mon, 24 Jul 2023 18:54:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5F5D6B0082; Mon, 24 Jul 2023 14:54:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C38018E0001; Mon, 24 Jul 2023 14:54:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFE336B0085; Mon, 24 Jul 2023 14:54:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A177A6B0082 for ; Mon, 24 Jul 2023 14:54:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6FD37160AD6 for ; Mon, 24 Jul 2023 18:54:41 +0000 (UTC) X-FDA: 81047406762.23.FF94BF1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id B239F4001A for ; Mon, 24 Jul 2023 18:54:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=BFJKXQAH; dmarc=none; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690224879; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=j/+5nvHmLcQr2gQNLZnma/P8C+KH0GEPUfvfP6aRFCA=; b=WzW1/sXHFXDB0x3k96xHQVr0ohuKSqBKcSpaW0ZyCJlLBczA2J81dxiwCsh9LCUXHI78yj Q8xlgSxVaxSym9bNLAdrxEEIh9RHlDQckDppM8eKma7hUbYxuRxbJpQ9wGjv3RX2NOwVth 0qo+6unv/Nfsz2Dm4qgfHgBnzIrtxnM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=BFJKXQAH; dmarc=none; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690224879; a=rsa-sha256; cv=none; b=Oj52bUkk8WpFFOTcufRzBCcZp/e8CovSeZ8Jf43Stvtdi/jOvpzlPddPB+FBMEcr8P9u0Y MsX1K3NOr1y3BeNnFlWHjghoUkHwYHP2/zHNf8+wu5Eu3vYUKh9fstk2VYrYZdrVvrsmRk FjWo9yxE/u9iXpBwbZhZ/5WcpWc15GQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=j/+5nvHmLcQr2gQNLZnma/P8C+KH0GEPUfvfP6aRFCA=; b=BFJKXQAH8Ld9mSwUnjlCJ9Cgoh fHUbEJMazDTd4xQQptvmIIdTFyaEH2YONUrjuOkX0UZQQ3TTYhtjroUHubNIxcQHwaE5xTUDqOCJs 0VU0ypfcwtPQHyWFq4J4BuPx+zIDlFkLgft+yQUGk+0ivxv9RpxA2BtSphe+v5RvSEm05/oiXwvrR /Af8Ms5TsZWa/9POSZcp9IVBoKd4YybnnKWboaz7rRkZcWp7CN8Ot7LXch5abDyrcgIJSZMVUI+7z zu1lLMHI/+0UzRSBkH2VswJg10brdZ4gtKKnSmFrNxMIEaU9Dx578le2dcBm6S3Rj+jhQQWKd8ygJ E9UgB4KA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qO0hA-004iRB-Fc; Mon, 24 Jul 2023 18:54:12 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Punit Agrawal , Suren Baghdasaryan Subject: [PATCH v3 06/10] mm: Move FAULT_FLAG_VMA_LOCK check down in handle_pte_fault() Date: Mon, 24 Jul 2023 19:54:06 +0100 Message-Id: <20230724185410.1124082-7-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230724185410.1124082-1-willy@infradead.org> References: <20230724185410.1124082-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: B239F4001A X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: efbbzy3pitn1hir4wg1y7q8zq1bqztam X-HE-Tag: 1690224879-131929 X-HE-Meta: U2FsdGVkX19cRfKmbjmQyQYSc4t3Z9GYW2+zPaP+wjr9a7FZ2aidX8KISP2hc2ZmoauKyiZCCNZ7Yh8XhekLRNabTC+yRqcwid4pKX/3Jv5xOH/TSOEeitoEirLCOcRDipZIYBHU21ygD/OjdPgkN2WGZId8vMJnwNmor0h7bi6SqRcVLBs35EqRo5ijZ3kTm6BEu+tHLuWILEtyck3dlL4rRX0SSKDuHz/sOGr9RLQIIFsUVQ/IgInSkpfZfi+X477eO0oX3HBPWTINibIwCIkMrgNC2r3cvj7Vsg/UH+U0ZN6K9YIDoVEoEwum13COJW0LzjYish4sEOiC+4P1rD7pSswQfUv2bH/mRu+9ysc/XMCQyorZNT51XBHov96yw9UH7DNkIgZDopfDSuPDWi2EwHxdmp86aRR4VlqMv+nfHvvM55l41j36T2HvZyjZwUfcYrvcXtt7tdndNnIsz+uGGdDtw/teJCwwSfdAFbF0QyJVCkdCUtNxyw+zh4Gz5fuHkfP+qGuTrCu40lpKb7vPrNTzwWG/gRDIdAL3T28kFP235ahyVd2tXyBfsKv6hXmnqB7pKL/K6dBev0XF2XD2uDjeE9FaSGNy/VgL384wunsXicREdD+grNYJSEN/pH+w59ehvjAqe8NEyJ/sjCi597p+Of/kaosTwdWzHgwJEd2F28d8rH3fwVo65Sjm4ZGdLHr5zh18JT+i+S58KGgg8DbFdmhTDxFg7t6pLKHS3NYGl6uZtgcA9m/x7//fGCn1vUFrrJ5TrOjH740pJSH+54ns7itJoPeuvfNH5OFDGDz26MZbYl9gs15nmFaWb3bX/BqQe0Z58Jdzx/NwZlk15XjDkawlbqqvqcTRc6ngvoTH19RwCvAE93a96xDA4nHwfACu5HxhXq4vWfmmm5QdJB1Iagu/jgWvSysKuFs1iH56AkwNTtpd8uULBC+nuCz755fEplc3L9tMuvk /lRhnb6j TKRsPk5H8XVEzOWtX3y/ZOw+IjE1KcYPA+HlRcYLao67Pn/qhhNTEEAiTs4ZqvXis3DiAzFBlg71EhKJ2lAu8GFclBV0mkvDwQdGiZi2dmXPpWZNZ//Y324zpy09bmxnUK4guPeM8i89CJptyDO3802qrBWG1nBZ3deqDpslQ9Sbu5a0zjhMCBB2LT7HGYy3UIazAXS7s48Pf50MXCO6PvhK7IH3Nu6c5L+PUwUn13xUKYZ8HdVu9iKcbRg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Call do_pte_missing() under the VMA lock ... then immediately retry in do_fault(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Suren Baghdasaryan --- mm/memory.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 9e4dd65e06ac..11b337876477 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4775,6 +4775,11 @@ static vm_fault_t do_fault(struct vm_fault *vmf) struct mm_struct *vm_mm = vma->vm_mm; vm_fault_t ret; + if (vmf->flags & FAULT_FLAG_VMA_LOCK){ + vma_end_read(vma); + return VM_FAULT_RETRY; + } + /* * The VMA was not fully populated on mmap() or missing VM_DONTEXPAND */ @@ -5060,11 +5065,6 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) { pte_t entry; - if ((vmf->flags & FAULT_FLAG_VMA_LOCK) && !vma_is_anonymous(vmf->vma)) { - vma_end_read(vmf->vma); - return VM_FAULT_RETRY; - } - if (unlikely(pmd_none(*vmf->pmd))) { /* * Leave __pte_alloc() until later: because vm_ops->fault may @@ -5097,6 +5097,12 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) if (!vmf->pte) return do_pte_missing(vmf); + if ((vmf->flags & FAULT_FLAG_VMA_LOCK) && !vma_is_anonymous(vmf->vma)) { + pte_unmap(vmf->pte); + vma_end_read(vmf->vma); + return VM_FAULT_RETRY; + } + if (!pte_present(vmf->orig_pte)) return do_swap_page(vmf);