From patchwork Mon Jul 24 18:54:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13325262 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 4737FEB64DD for ; Mon, 24 Jul 2023 18:54:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBFCD6B007D; Mon, 24 Jul 2023 14:54:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D481E6B007E; Mon, 24 Jul 2023 14:54:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C36CC8E0001; Mon, 24 Jul 2023 14:54:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B65C66B007D for ; Mon, 24 Jul 2023 14:54:29 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8C300C09DF for ; Mon, 24 Jul 2023 18:54:29 +0000 (UTC) X-FDA: 81047406258.26.4197E5F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id C372F16000A for ; Mon, 24 Jul 2023 18:54:27 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=EL5lMUFn; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690224867; 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=hJu05/6R+2/+R58/bqnW2667sqrjvy4Vo+FjhIXzCu0=; b=KdrPF0ISURF0MZQdbqE+lKqQpE9ZKr9F6ZdSER5Qrpi995V52HlcV9J4x4gbhOOZoabz1z 8Z6pTLRxg1OZZDAn0e1C/Wbm8FEvpW6wlEFXHI9unR4iY/eBsqCmgWYy+Pt4ARz6a54PTY TVbwPMzD18gAqpy6zqtcuDw6xxBODyY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690224867; a=rsa-sha256; cv=none; b=0Pac9CxzHaTObjck282ByMTR6M+ERP6g37b2zkNzVO8VUWgru/h7OKrhtxh4yrDepN7zLo HT7d11hv6NvB/5Y4HOZJuZ8wI5NHuj9MdN8b1eAn70ngNKJXX3f+eZ6HHGPoCLd+nFoeiq 4hoTBmISQgq45o4ypHdUZ2XL4hPvIQA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=EL5lMUFn; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=hJu05/6R+2/+R58/bqnW2667sqrjvy4Vo+FjhIXzCu0=; b=EL5lMUFnNoPCZMe0eS0Hvijf+2 j32meE393cAjsq10i8jRMBUAvHcjjnw4BZyBiVirhYCjv44Xl4PLoH/sWyaqKSIwj0MCPc3w4382H sMSy+UNGoiKw8jyI5NZzdHT00TMqbw5mU8dWWw9oQPdxKe0U3T6zDJ0FWgJfc8FxlIPQcYk7vEW/o ZuTt6UHN7KrKdU+56Av7l32r4Eo7vG1SZaOKkWH+D5hZLNwYGjYrfh6DSX0Lc98neqYSZBttPU1cN Ul9efZMKPBrSxs/5R+8v5NbJUr06vyCHOrd6yf9uuxA58P9XcM8NezBphhwdnh8O+svpoAzp2Swxq rE7Bc2kA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qO0hA-004iR9-Cu; 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 Subject: [PATCH v3 05/10] mm: Handle some PMD faults under the VMA lock Date: Mon, 24 Jul 2023 19:54:05 +0100 Message-Id: <20230724185410.1124082-6-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: C372F16000A X-Rspam-User: X-Stat-Signature: ghm9y6c6o6zctdsrhhfju7xhzinpjnkj X-Rspamd-Server: rspam03 X-HE-Tag: 1690224867-87168 X-HE-Meta: U2FsdGVkX199xRlmt7fhiZTxrHMHpy/2/6KdwD4IGytfkISaOPWS+MkPs7IoQw9d59xpqDyZ0k0isYT2OdJc/42HSCxgtfGCv1izJvcV6NM7EcczH3D91AO9go4u1PSK6vhhJuxJLi5wwPobIn/IyUULzbW11+V/l0oHbUZdtVxcUsGJlPtxufSv4KYZHOJjLS5uWOysxVN8+2BASNnhUrtwoS5PSIaPRHOIIUxvw8RdMBaL9tfrsaQpfHdygrmcgu9NilzgVUULkdoJ6dZn+3MAHf51wYHLtn+66RpmXiJ6J+2korMCEEjHVRvsmCjIcYoulnXHHQ4vLpVkhCE3ruMVat+OS1hLMF9sDf4Bz2Rsjr9rHYQYxA8nQG2e4DFTmKwdkbW6Z8JofFxwUwERC2fU9qmFbHqVioS5JQWISBZzTiccedhJpL+dW7G6QjVO6Ae1dwbjdUS3Mt/tQX5h/25UztgwTayTUDu59fuUvSQtmNdwZRmqf8ZyBSCWw6SL4PshBoCyrMlZkjtNE8JSUdgo7kMD038ivkGUCUrcbch3/7NeHlegOJ9XelfwX0HqKkEvenkZUvcVL4sCVtE8JwHuUmmpy0jI0rgFlTcbx0gRFdXmQPd1WPhU/r2BZRVEfeIEndaSsf4Z/z40JPjWag84OwAMj9krCK7v/e2iTy7zpPNz5wKTiQnnT91Ug5rUOXeUFlbxmbCo8YQwkYVGljHSg29JeDF4vjOdKRh5ecAy/0uf4xwbxTVFeF1EItsikdTWRoVRvomTumFacvFNZYVTtnrqbFnVfRmp6/KnwTt0137USd3pY1sD7QPBuUPIRr7a4F9gi8wOsF/eskYnXTVlNyF4SfHwY9DdEy1q9goiGPLV9wUh1cggCQa5+T2gKVJPn91Py9xG0pHhh3z6YaV4qUGDyURYsVpL2RSfDExNN4DstQFkCy8yrt4GSVzBH13mtZnvIJJX34ZAbWx 5/DiC1mM J0JGqbq9Mn5aoHC3QALuH5LtMDOOrdHBmH5KyYhyK4K0F7wiP6qnyGya7p910fZGsi7XR/Y2gzq0tKMbw8DYpHNarJSeSfGCQ0ZFubf4bxYYVaQjxmK1h44lOG64NFDLJJKX/ZuYr52SY+Te2vwPYdkVUPGll3JYQnum9L1nd4DQCxYPPx6M2beQ7Sw== 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: Push the VMA_LOCK check down from __handle_mm_fault() to handle_pte_fault(). Once again, we refuse to call ->huge_fault() with the VMA lock held, but we will wait for a PMD migration entry with the VMA lock held, handle NUMA migration and set the accessed bit. We were already doing this for anonymous VMAs, so it should be safe. Signed-off-by: Matthew Wilcox (Oracle) --- mm/memory.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7fec616f490b..9e4dd65e06ac 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4949,36 +4949,47 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) { - if (vma_is_anonymous(vmf->vma)) + struct vm_area_struct *vma = vmf->vma; + if (vma_is_anonymous(vma)) return do_huge_pmd_anonymous_page(vmf); - if (vmf->vma->vm_ops->huge_fault) - return vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PMD); + if (vma->vm_ops->huge_fault) { + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + vma_end_read(vma); + return VM_FAULT_RETRY; + } + return vma->vm_ops->huge_fault(vmf, PE_SIZE_PMD); + } return VM_FAULT_FALLBACK; } /* `inline' is required to avoid gcc 4.1.2 build error */ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) { + struct vm_area_struct *vma = vmf->vma; const bool unshare = vmf->flags & FAULT_FLAG_UNSHARE; vm_fault_t ret; - if (vma_is_anonymous(vmf->vma)) { + if (vma_is_anonymous(vma)) { if (likely(!unshare) && - userfaultfd_huge_pmd_wp(vmf->vma, vmf->orig_pmd)) + userfaultfd_huge_pmd_wp(vma, vmf->orig_pmd)) return handle_userfault(vmf, VM_UFFD_WP); return do_huge_pmd_wp_page(vmf); } - if (vmf->vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { - if (vmf->vma->vm_ops->huge_fault) { - ret = vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PMD); + if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { + if (vma->vm_ops->huge_fault) { + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + vma_end_read(vma); + return VM_FAULT_RETRY; + } + ret = vma->vm_ops->huge_fault(vmf, PE_SIZE_PMD); if (!(ret & VM_FAULT_FALLBACK)) return ret; } } /* COW or write-notify handled on pte level: split pmd. */ - __split_huge_pmd(vmf->vma, vmf->pmd, vmf->address, false, NULL); + __split_huge_pmd(vma, vmf->pmd, vmf->address, false, NULL); return VM_FAULT_FALLBACK; } @@ -5049,6 +5060,11 @@ 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 @@ -5188,11 +5204,6 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, if (pud_trans_unstable(vmf.pud)) goto retry_pud; - if ((flags & FAULT_FLAG_VMA_LOCK) && !vma_is_anonymous(vma)) { - vma_end_read(vma); - return VM_FAULT_RETRY; - } - if (pmd_none(*vmf.pmd) && hugepage_vma_check(vma, vm_flags, false, true, true)) { ret = create_huge_pmd(&vmf);