From patchwork Tue Apr 4 13:58:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13200238 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 9FEB2C77B6C for ; Tue, 4 Apr 2023 13:59:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA71B900002; Tue, 4 Apr 2023 09:59:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5877900004; Tue, 4 Apr 2023 09:59:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF7AA900003; Tue, 4 Apr 2023 09:59:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A0C6B900002 for ; Tue, 4 Apr 2023 09:59:05 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 74525160EA0 for ; Tue, 4 Apr 2023 13:59:05 +0000 (UTC) X-FDA: 80643865050.18.DAC7717 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP id C4B2E1C0017 for ; Tue, 4 Apr 2023 13:59:03 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=wOhh5MI6; spf=none (imf18.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=1680616743; 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=52BqLkPH7JK+YVgxAe2fuxeKTYdfJ/oXPMwp85njK/A=; b=T8MhFpCrL94iopFsv5+qSHSCi2gEUKRPUUPgD/gM1jpxinXJnMNxxPxiku+pDolr31LfMo muG1BmI0UEsvNdmYOC/ROT7jNEGaIBFgRY9JIlCdXMI8G0XYjbMzMpdPhi3QQqYNJ9NtO2 9nFls3gaUZV2MsXn2pJ0GdSGKxQUOKM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=wOhh5MI6; spf=none (imf18.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680616743; a=rsa-sha256; cv=none; b=vmdyx2f5GAf7Ex5oEM3QTl+ug67b6QCT7L/47m8CCY95aCbj1IfDB3/BaVYlTvGIzaip8m siUwlsR9nxVUsX22+h/nJ9lg8z5sOid99Sj2sBPJHZYThTB6xjq5TZL8ExscOhJnyPLZTH XNzfs99mYHtFSmjEQT+bq9lxYkGSsec= 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=52BqLkPH7JK+YVgxAe2fuxeKTYdfJ/oXPMwp85njK/A=; b=wOhh5MI6+I4NGse+vua1IB8f4A hZZCG95HJrdfyK8JqiDCfGDmfPoatJwd6OUBpDjbZLS1rpRg/INo4Zm7QMNbZUmHWr1+FTPGtFy+1 4tXsE9cGWheBFU8hBh3jvu+vwuyrSNhEA0qwcC3LvgvRLxmpKZKvbxXay4xYHkbEz0oy8m2BdpdO2 XfBSQZsFz3NVZ2WSiG8L6CJs9EpamaXyYXMfqe5PifW8V2fCb0gwJ63XmPTArO/gT6m84+xT34D6x AiB3JXxroKqcRT8kYynhag8ZVBv5Avf0fW91FS2TVRCCvnKSgSfVnHl2ZxjaIvJQoz7e2eN9c4SLG /LGz7mag==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pjhBU-00FPcf-4A; Tue, 04 Apr 2023 13:58:52 +0000 From: "Matthew Wilcox (Oracle)" To: Suren Baghdasaryan Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Punit Agrawal Subject: [PATCH 1/6] mm: Allow per-VMA locks on file-backed VMAs Date: Tue, 4 Apr 2023 14:58:45 +0100 Message-Id: <20230404135850.3673404-2-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230404135850.3673404-1-willy@infradead.org> References: <20230404135850.3673404-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C4B2E1C0017 X-Rspam-User: X-Stat-Signature: oq7wu1fdwf6j19e5f8tw49hh9fe9azq6 X-HE-Tag: 1680616743-968674 X-HE-Meta: U2FsdGVkX1/aXHRPNBOJGIoeuLp72tP0ab8o6EHSx/yBg2O+pCK5W1KK2OO/1pUzndDy4aDwXSEanQP9FSHHoN1DT3+e5m7IscjNN4Osw5A8VnX6O2cRKUj9qXNc1SFmOsG0myAYKNR/zbonmb5JxxJdblKfM8CZ0dI+8MLMtyPai2D1SpxN0UXEbEqsjVOteRRDK+K9YKtjuTukYtjwde/DI7dXoi/yOvmVUx6H473fz7MbUUw81950aYppLy3FtIpRT2UkY/mJZXP5Ce2MSHBUqh69WBjU+SHMx3k1jK1XZ2L02iOF6g+Vq1Zj+Dnj2zo1b96zUDydr3vrQmU3BFaRqLaH/QLopXhgbYFta5oJAKZafRfX0QQ2BS7dtrCPgNJPjEYepe/0hzyE/bTi3wYSBuHk09CU/pRxoPbS7v/Y43bFhH0M6sEc92CzrGz9LkMGz0H09WYXlyk5fTAW4eQcVxftuE8wZe1AZkka7Az3WZbzD9J833Rwwp+2KskDcJjK/lsBjoRwwJvAOzBEkgoGPOvL0fZEwxa9KiO174PE7UKJB8ndk0RNw4d+a481fMZQ3mBXUenm8qihphKL1/YGb9DtUFZsAxkIWi81vTqFplOEQXVUn/oE/6P/clVY6i9aYkU3xgG+bCVMM1xO9c6HNHrN2vHnMkP6Tb+WXHcmDvipWejqjWP3WeF6LP+ww0FA0V85qeOGoaHkhffb6Ety5/mXAyJElZxhJoVOtxzx8gPfyWalIl2Io1OxY3raggacKPSl4qX8/gRD8/vziGV0n71Krnpia+w3C92rxVQPCh4F3Angu6Ja/m5l4mGwQ8PWCjNv02G3/aa+NTAMuPzimHYfHgjxrMnOBKO2f/kdTbi1ro3exvnZS+36woLJ4SdRWjxBr6bj0gCtQSxeUUrIpk5w0a0bPUXLQxGoj6ryN3UpGSOLAbZChAoLUOt9bRWII9s2hUv/AW58jgg 1Wf4MKJH FRqOgppErRZG4zSXH7FHfbjNJDPEE0rxZ7vv6sJJGXejttg3lLOaSUDaP+L5SyFL1aE1nqcADAyBH359IwxyicpXcwtYzVcHulQJ1ZAIWA3ivzN4SR0qG/WXMsL7IhRXJFNs9Z8Ut/vxQyhTSXS/SA4lrv0MGnyJptP+qurGd3QCLCAd7bBRunfWyamUKh9rz5ck3 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: The fault path will immediately fail in handle_mm_fault(), so this is the minimal step which allows the per-VMA lock to be taken on file-backed VMAs. There may be a small performance reduction as a little unnecessary work will be done on each page fault. See later patches for the improvement. Signed-off-by: Matthew Wilcox (Oracle) --- mm/memory.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index fdaec7772fff..f726f85f0081 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5223,6 +5223,9 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, flags & FAULT_FLAG_REMOTE)) return VM_FAULT_SIGSEGV; + if ((flags & FAULT_FLAG_VMA_LOCK) && !vma_is_anonymous(vma)) + return VM_FAULT_RETRY; + /* * Enable the memcg OOM handling for faults triggered in user * space. Kernel faults are handled more gracefully. @@ -5275,12 +5278,8 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, if (!vma) goto inval; - /* Only anonymous vmas are supported for now */ - if (!vma_is_anonymous(vma)) - goto inval; - /* find_mergeable_anon_vma uses adjacent vmas which are not locked */ - if (!vma->anon_vma) + if (vma_is_anonymous(vma) && !vma->anon_vma) goto inval; if (!vma_start_read(vma))