From patchwork Tue Dec 17 05:12:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13911034 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 0ED05E77184 for ; Tue, 17 Dec 2024 05:15:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8F746B00A6; Tue, 17 Dec 2024 00:15:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C46696B00A7; Tue, 17 Dec 2024 00:15:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A402F6B00A9; Tue, 17 Dec 2024 00:15:43 -0500 (EST) 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 844866B00A6 for ; Tue, 17 Dec 2024 00:15:43 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 017151C6ADC for ; Tue, 17 Dec 2024 05:15:42 +0000 (UTC) X-FDA: 82903287600.30.5F5F403 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2045.outbound.protection.outlook.com [40.107.223.45]) by imf20.hostedemail.com (Postfix) with ESMTP id BA3921C0006 for ; Tue, 17 Dec 2024 05:15:08 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=JIVvDalB; spf=pass (imf20.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.45 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734412517; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=H5MhO/dRA0tjI1dUV5ZoqTSusZp5BthCYTx40EefRUo=; b=5lSyMGx96vMTLahBS5F3stqUmH+iWajpYcwTq8oQVwbazyiR/c1q+rigq7CQUtlaSEg4YG WEuJGkIo/f/QShQ1jov3JQ5a8Hp8ElO6ib7EhpcK5DKk8R8CHkq5zvyMBANAxPB2/BTCB+ GBPY2L6DcjhRZFHc5WZ7L+b5B7CPr/E= ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=JIVvDalB; spf=pass (imf20.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.45 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1734412517; a=rsa-sha256; cv=pass; b=wLaEABX1VdzS3wP4hdqBqtreGO2LxDcoLMrphuumqFw7/nOSPpXgArPbHPMHAf66UNEJtz dplcp/6sfHOvC/iJJTJ/IXtXb2nk3Km7v55+smfaCGXuXeB0+x5n1r4EfZAEyLTuMfXA6E R3GO10Bmne/dG/Y5QJ04EpusB+qCRVw= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=x8nnEn1ajo+2Pj76utqjNUhwM1VIb1yjyfJl60/dlnw9nDy8wuh593+D290FZwxaP1vmLdMiw6sSctmrSoQPAwY2DyAF3VV4fTiD2DMUoLng7Pjjw5B94QuV2rFHyT1KCW9hFU2qpBps48Z2f3kKaSYChhFK/xdmbv6b18IWa+Yokf4UQp9HJR9g0vMLOE6gGfI6gwuYY2JwhWRTg/su5Rk1/nst3B0skfGsKb751gSjml9ACvskAOvNjPerIvqhYfEFmIwnxi2Hko9/ffGYVHZ6myAocnwMMjr+ssgziKRjdq8gkCEiVbXWvYOcQlODXmt8DVvCjZJK+xxAqSvy6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H5MhO/dRA0tjI1dUV5ZoqTSusZp5BthCYTx40EefRUo=; b=VsN5TdvIUvW7jm5aLviM9G6LT3yNMzFC2VNpK9JrYQVOuupY8oEUSPZkrfoZjCf/dskeqGqI0thmzakWDTiUjXZ7hiV/TBs9m9cQZ6CdUjcftAWQ/Ml+XvczUviqIsBj9AI/IxUbDJq4OK7fRTTYzWvXaFyQrBDEJ2djSTFNSU4ZuqBS1sUFsf3w/e1YHbXs1ngjoPHbxTxyz+5XUK6S9r9vrU6W1Ge1nrY8iuq1t7BUA/i5HDOay8MX8vC4pjOVRiuDG2N8pDh7nPuEmEy1/8xAhXxmpfpE85lGV/0qNJ/4lZTQpD9wMR1U38SO7x8gtB2urI+eTiZt/+4hNclD4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H5MhO/dRA0tjI1dUV5ZoqTSusZp5BthCYTx40EefRUo=; b=JIVvDalB7NE70/AIzHzsl59yFKa5FIM/rudzetMB87Wwh7YZs9CAR/64BGWedSXATj0V6+KG6K6x7NVZZQz+I27jpwM+ziwzZgwV3Jxp2byuAlEy7O3e1DOTGDsDUhDgy5az2aUYwaj96E+QTNFPpRQwY3mT4RXXzg5j6a9E6zkT6Rl2ov58sx/ad02FJBhIuk2VuofMCxcDi1WJaXkdwTaysh5EqpUYGVLPVCI9J5OqqhP1K7miSLHu8G3Zrl3Hh+pp64bhUR/Lcg8GhHwzT4j3YP69xQHXfblNlWd5D3g8Zk6LiBj9xV1AO64ousRMKjniFn0k78xnyg/AKZFlJA== Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by CH3PR12MB8936.namprd12.prod.outlook.com (2603:10b6:610:179::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.22; Tue, 17 Dec 2024 05:14:44 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%4]) with mapi id 15.20.8251.015; Tue, 17 Dec 2024 05:14:44 +0000 From: Alistair Popple To: akpm@linux-foundation.org, dan.j.williams@intel.com, linux-mm@kvack.org Cc: Alistair Popple , lina@asahilina.net, zhang.lyra@gmail.com, gerald.schaefer@linux.ibm.com, vishal.l.verma@intel.com, dave.jiang@intel.com, logang@deltatee.com, bhelgaas@google.com, jack@suse.cz, jgg@ziepe.ca, catalin.marinas@arm.com, will@kernel.org, mpe@ellerman.id.au, npiggin@gmail.com, dave.hansen@linux.intel.com, ira.weiny@intel.com, willy@infradead.org, djwong@kernel.org, tytso@mit.edu, linmiaohe@huawei.com, david@redhat.com, peterx@redhat.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, jhubbard@nvidia.com, hch@lst.de, david@fromorbit.com Subject: [PATCH v4 13/25] mm/memory: Add vmf_insert_page_mkwrite() Date: Tue, 17 Dec 2024 16:12:56 +1100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SYYP282CA0016.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:b4::26) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|CH3PR12MB8936:EE_ X-MS-Office365-Filtering-Correlation-Id: 707a850a-c47f-486d-7807-08dd1e59b788 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|366016; X-Microsoft-Antispam-Message-Info: Kt66ZZU9iGjMeOzPDja6nI82dO8l/qPHRxslb32KOWvmTSnvJTYkVlk//pGVUktMqE6bblUs3yAsSvfNBCr4mG+iZWBxyEz7PiJeWpUBCxWMXlR0aOUsLQGbO2U2xSFkTNxaF9nwXDyiU+HnKAjWmdD3PfgzWpEfnjNvxZNqhGlpve0kPUvP40dCl1KWf4AeGIQU9h6zusWFOW+4mCN71aXKh32qb0wwqCBAqniCprZY9UQA+NTmI5NuRfEJv9RBOKW7zmoM9bmK1F58h/K2wwbJZe7wPyMa7tkaBUEXBG+2kPhltXgt0KGdW2USi0Qwvq5vLLjEZRc0X8vUZwZsTUlVXpDVfAnb97/xJR7SCh6YcmgyyH7XcwDeOXAgLAUy1IdBVcVWPr5oTqw/T49xt5lHH1CaWo0Exy3uUwF3UqWBPV5o0xLWA7XF1f4ylUxkypqKOf3j0AbxKA7gOLTUwjg1W7zDrQrwSBsdLCSuuug83kyzx5WjI1oZI6pnwMvA5mBQRIjAZcAOGOj0FC80ZuTrDRa+eaVeuoGErKiS8p+RsbXBys2mtr5KKlTkFVsl+ZCJEp0Xk1iYqQ2semyMJW7/opn35URHJ9fdLqGVCdl50xEI+Umk+7P8A24pf0CznBDhFy+4JNjVvrgqJoKF0liajL583dz8UMc7puiHJUVcJ0EY2PppaD3SygvJBoeXsWyIaHjULjS14e+9R2h89GxTrX4LZLjYehumIXLSwVtMxg2xpgK+oDF+uEj2GBfdXs0jY3eJOYRxrATIAOpw/XcuZGUSrFhNVePo795c6SOjzCiLNhT/Oc36eoFgLDSgItx1cASoEelbMiKpvlGGeQ4yU8im0VS5Jhseq70MvsZEwkMGhSmftB/Shbuz1ZbuZnteq2kQThhX/3BKp524Jf2wW5OmZv/pHnnBgsmncQ2CLgB3XWxWtMGCaBenhpmzKUaM0YB9v/tHdY1KjNDDNyxby5uxsLvH2fjDbo2/ALCfgrT1EBog25xFSAtQaBVmuXmfVPnB0c6SJqCcUecqoDw0UycI6ZUOW//7GCQp5egXOxNPI5+X67W+WqDnkRnwJDQKv49wAtnGt7RWsbbAoK9+0enXwMNBopH/8wogg2Oag2bcpBtW6dqi1EYq1CxZtsB5AD2Boru/R2g0C9/Sjfnu8tSVEhcaiNUObIBEFfTGSQtGz18bi6i/KweLO0leJC06XSsLB7hzkP2ut0zbcyQlYLudrRFyeKOmxCEoJu5KWE6ShHODGNsHHlGjwpo19BI3v6HRRWf3+UUlvCjJOep+g0ts8RTWv32CL60yYUMuZGz54mVDsDW4Y1htBjrb1aCQpsXt7chxgPg9tWcNEHygtL1/BBe+fM2UWlsHLLg5BXBMywdjxl/4cDIwLhFz X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB7726.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: amY/o2cdeFIYVbsbGUtboZ6nfjsYmT6sdCKyFJ+YBQTeaEyqy/hGX84S1OZBHi71KqIBOvLG/ryD84984F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ed4rCpKUkU24nKPtb5+7jBctGtWzIXY8Uts0knsx4XyFPQuELXAuINR4KaAk88wF743npdhz0/6mM0ZZJGLKoxF1h5uADermedp4ZolfMdtnZPT4ukxBXslfd1+ma3+Qz9Vsy2hOSWEjCZmfnmfNYA6H5dQt9buZMb3rK011nVzfBsuI2Ezd5Sydb2PZW/t0YrrS6Qgoihydmb9zphdLLnonXFbfXvd1u/9xyIO53t188x/VCzEx7ls2K3IG3GYCpfiilSzDVFnxz0ac6seIiMDhp0WNgyrMp4y/DPzM1SXvnS/xLhtZ19YfjAIsRaQOWIXIKsaDb8cKStNLJLCjF1aYI/x1Bgo4+UymDkT8JwNk6IG9MUYi1wJAmeK99HdcUukt/THQ9KzR53TmKU5i/+iNljd37GDEIlxwQpmhuFa X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 707a850a-c47f-486d-7807-08dd1e59b788 X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2024 05:14:43.9655 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XrxOoINxJEPydz6kQXH89kVqUovVV1L7w3zmdQddH+16k9iBybaFjljYMzUw59MsXTnPCwWejuetQgi0zr5rjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8936 X-Rspamd-Queue-Id: BA3921C0006 X-Rspamd-Server: rspam12 X-Stat-Signature: u3cb9z35suexiqkc17gwn3qis65zbhe3 X-Rspam-User: X-HE-Tag: 1734412508-665058 X-HE-Meta: U2FsdGVkX1/kzeZ+IyfCqoSax69H+cIa8zVFQNSipvht7enPfnWYZrhoiiH1uL8z7P1GINKQX4cXuiY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UrVH4d7kvo7AbthQRUMiQ9hng/489kRYts9S3dZacoIkjNrinHL9Q2uZN1dwuu63pnAtTWlNcMUSMrerF/lSmxtg5VEXPXbTOgtxnu+vTgqzSq7IjJauaGzpDU2ujdPHH7F8zJgUwce+y7PjpfPeexFflibeC1HuEksBGMs2ki0Cb3NVHcX6UEg4kd41wY2lB++r2iCeAGHpngMy1QNYZVtLY+R+l4DBXSAGmJV3CMmzfWcLmstkgbgD5c1cXzsD563T51mB/bHK1ldBqPsNfuPQaY271TmbHSxNAA== 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: List-Subscribe: List-Unsubscribe: Currently to map a DAX page the DAX driver calls vmf_insert_pfn. This creates a special devmap PTE entry for the pfn but does not take a reference on the underlying struct page for the mapping. This is because DAX page refcounts are treated specially, as indicated by the presence of a devmap entry. To allow DAX page refcounts to be managed the same as normal page refcounts introduce vmf_insert_page_mkwrite(). This will take a reference on the underlying page much the same as vmf_insert_page, except it also permits upgrading an existing mapping to be writable if requested/possible. Signed-off-by: Alistair Popple --- Updates from v2: - Rename function to make not DAX specific - Split the insert_page_into_pte_locked() change into a separate patch. Updates from v1: - Re-arrange code in insert_page_into_pte_locked() based on comments from Jan Kara. - Call mkdrity/mkyoung for the mkwrite case, also suggested by Jan. --- include/linux/mm.h | 2 ++ mm/memory.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index e790298..f267b06 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3620,6 +3620,8 @@ int vm_map_pages(struct vm_area_struct *vma, struct page **pages, unsigned long num); int vm_map_pages_zero(struct vm_area_struct *vma, struct page **pages, unsigned long num); +vm_fault_t vmf_insert_page_mkwrite(struct vm_fault *vmf, struct page *page, + bool write); vm_fault_t vmf_insert_pfn(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn); vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr, diff --git a/mm/memory.c b/mm/memory.c index cd82952..4f73454 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2632,6 +2632,42 @@ static vm_fault_t __vm_insert_mixed(struct vm_area_struct *vma, return VM_FAULT_NOPAGE; } +vm_fault_t vmf_insert_page_mkwrite(struct vm_fault *vmf, struct page *page, + bool write) +{ + struct vm_area_struct *vma = vmf->vma; + pgprot_t pgprot = vma->vm_page_prot; + unsigned long pfn = page_to_pfn(page); + unsigned long addr = vmf->address; + int err; + + if (addr < vma->vm_start || addr >= vma->vm_end) + return VM_FAULT_SIGBUS; + + track_pfn_insert(vma, &pgprot, pfn_to_pfn_t(pfn)); + + if (!pfn_modify_allowed(pfn, pgprot)) + return VM_FAULT_SIGBUS; + + /* + * We refcount the page normally so make sure pfn_valid is true. + */ + if (!pfn_valid(pfn)) + return VM_FAULT_SIGBUS; + + if (WARN_ON(is_zero_pfn(pfn) && write)) + return VM_FAULT_SIGBUS; + + err = insert_page(vma, addr, page, pgprot, write); + if (err == -ENOMEM) + return VM_FAULT_OOM; + if (err < 0 && err != -EBUSY) + return VM_FAULT_SIGBUS; + + return VM_FAULT_NOPAGE; +} +EXPORT_SYMBOL_GPL(vmf_insert_page_mkwrite); + vm_fault_t vmf_insert_mixed(struct vm_area_struct *vma, unsigned long addr, pfn_t pfn) {