From patchwork Fri Jan 31 00:18:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vishal Moola (Oracle)" X-Patchwork-Id: 13955034 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 9A428C0218A for ; Fri, 31 Jan 2025 00:19:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 325242800DD; Thu, 30 Jan 2025 19:19:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AF0D2800DC; Thu, 30 Jan 2025 19:19:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 128852800DD; Thu, 30 Jan 2025 19:19:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E09AD2800DC for ; Thu, 30 Jan 2025 19:19:30 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 12CF31C7155 for ; Fri, 31 Jan 2025 00:19:30 +0000 (UTC) X-FDA: 83065838100.08.033FEE1 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf08.hostedemail.com (Postfix) with ESMTP id 3F0C216000A for ; Fri, 31 Jan 2025 00:19:28 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=j+gp1gr4; spf=pass (imf08.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738282768; 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=TyKozpykEAjFCoENnU5v7/kSmkHMXuR/AybReX8XXa8=; b=Lo5AsTXyonUHAN/RQ0atnDaC1fET0P+k8lCYHUHXrC24ETTDoiVgdKnRJgGAHedPqTfriR wVTXTQegv8EEjzkWSQsAitLnc7yZ2wRaGmlGCdPbJ6W93sfpziRQruo2f+4+xRK5JZmjqX rtmCTV4dc9zZhIVToNQdGM41OtH/nP0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738282768; a=rsa-sha256; cv=none; b=WT7Pojj+itmFKbfZ/BQDZ4aIy55inNAE4hRAU5wU3lahpJ99hhPwKQyNhDavAXe+UGgPUB FFMXGLHcctzouFgAaGMBLx/QyL2rz1hXngMGe/xPfi+u6wQn3mPCjHvTdz5hRdeM68qCuV CkWiO1kw37K2YO+b3TaZ1HNxQ9E+cpY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=j+gp1gr4; spf=pass (imf08.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2ee50ffcf14so4013247a91.0 for ; Thu, 30 Jan 2025 16:19:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738282767; x=1738887567; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TyKozpykEAjFCoENnU5v7/kSmkHMXuR/AybReX8XXa8=; b=j+gp1gr4U+hGcPwmLwl07IbToLk7XIE9GWAqCcfSAyN4gZZsqXs61ONWWMkxi7eKME ywby1oIyUr6qc3Oq32JUvcD6+5nebOuUrxLzPvUFN94iz0oA7XDQnrwq5ZjXieJbH3YU kzr2CizxnHeEJXXNbz7XCnKjDlAWuwHH6LmMipf2H1e8B7HeZTiVjS7L2H/By0kfa82D 2KSOe3f+Wa4EdG2ZhmUkhYQiGWZKTMt47ePj94wzodBLvt/aC99s9RlhZwjA22MyUQ0w alLtVYSsheHPPtOuDPDbuqUGC+UADQuBEIeajwd0+QnYpEEjGty89O4+qZ9DLEotu68x y3ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738282767; x=1738887567; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TyKozpykEAjFCoENnU5v7/kSmkHMXuR/AybReX8XXa8=; b=QBFtoFzf9wp4FeM/hJnlXtFbm9CKDxIpGuNl9ikBllyXpSRJzlxcJgtmol0SYutmO9 39dUqmTEXvlpt0Sa6ID6pQQ4memjNFnz8bPENHcEDmtDygR8xwxjTwrcnkwTAZylzqa+ I/3dHSadkuJbylOspe/kz7r5s7XKlynIuL06fVZGDBeKzEQt/Iq4hbap2NVMxgkd21fT Dj+FrC2gBn3nsjpIsYzWbqc2v/wuxT2ybaT6KNW/IYDwP/l1ubNjciVS8N4FeXTQLHlc oTRy3yEMrD8UhFdAoczeZF+48IcJWzzUgKI1cwgvE2adCGpxCaTRgBho7A0LM0hm8PXl rJDQ== X-Gm-Message-State: AOJu0YwKki1fZ6fuSbFxHLUFmRzpiYJYKLHH4WHn2Od715olYQqGRRQ2 yo9MCC3+tZuvWww+HiFOCJNkKvMnMMzpiKOvGlfJ7VAGv2iRdaHP X-Gm-Gg: ASbGnct57kapgidK8zHpeA+xTOhCTw3zgvapepxYmzgKmiVwpbVoY4rzYN6FXcp8GKU E6a7FATs6WsyVCNKiRKd+5MGVyGcWX9JFbBWfYEDOZwG6bo9xZG5meLP5JR9k1bMvc0qnylR2gV cOUuY0YeGOOXud6kugFwY3PInmVFMBq1sz3rDpHSzhNLkBMhH1ucj/CVww6I9r+P/iAC6dQbqe8 8hkUiocZPXpDurQkeyG31xWV4WCCHPnu0j+9GLju+GIU59i7aZUI2sLZFE3hjotKMaG2dKDA1OR wccCLZePGuMTUd7kpQtgrpY5xAae4Qc+lONXApXeXLbmG7ejTw== X-Google-Smtp-Source: AGHT+IGTcJ0wEj7nw/VAr9mFtCvAOb9swQCbE3NNKbAN9EVVCz2Q0TQQOwiAKxPFXeABEt6KtjxpUQ== X-Received: by 2002:a05:6a00:1386:b0:725:41c4:dbc7 with SMTP id d2e1a72fcca58-72fe2d1f669mr9530361b3a.4.1738282766749; Thu, 30 Jan 2025 16:19:26 -0800 (PST) Received: from fedora.. (c-67-164-59-41.hsd1.ca.comcast.net. [67.164.59.41]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72fe6429218sm2148234b3a.66.2025.01.30.16.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2025 16:19:26 -0800 (PST) From: "Vishal Moola (Oracle)" To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, hch@infradead.org, urezki@gmail.com, intel-gfx@lists.freedesktop.org, "Vishal Moola (Oracle)" Subject: [PATCH 1/2] mm/vmalloc: Introduce vmap_file() Date: Thu, 30 Jan 2025 16:18:05 -0800 Message-ID: <20250131001806.92349-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250131001806.92349-1-vishal.moola@gmail.com> References: <20250131001806.92349-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Stat-Signature: jg4gmbqnzd8ycs4nptyy9wuf19e3guhw X-Rspam-User: X-Rspamd-Queue-Id: 3F0C216000A X-Rspamd-Server: rspam03 X-HE-Tag: 1738282768-592176 X-HE-Meta: U2FsdGVkX1/s1zuMzXKol8gcL2gkmGjgzKP77+RVtk7CysLwUNkIJC4JTVIrBvZGwVzWLrGYCuXMAzHH+opjE+7yDJuI70DPMY4+XqExby0/GMKAuQV0XacRF/xtbCRESfkpMzVYyw/qX5atsbUeFZ2vl52OA2mme3eCdj810eKmWetoyGYtfRz8U09yLjabiC8ljCdWPXBaSvI3391qdCkMQGom1moz6W/mTwVUVhVLIs8iiK1iPdL5aTdHTMus2HbIp0HbIFdNZD66RFAIr4Y1XDyDsO7Zr//qdtc4bE2F6ywT3DbSCCyr5ysypP3kjskJAMGPZ8e43clWtze7Ybtf/xjDROCLKR2IXJqGpMBI8CJDwb152TA39K1nYXed4rwj/C39uR6bCqpN3FlqpdwuXQ/75FzeME8gflemMrFg+L8DkkmQeLOqqErU+TNcrom2Y+qHFClsPX/zMkxBSEJLDfejfZPEUQN9neKMpspVptSdfGNg3tV3nuEmwsQKghaL13LiKPgcw844SsTVJyMe99i8pzwyww890LBu6cj1k8AEWYGz/ur8mdN/w/oaS1TGrQzidhC3/CH25VUdEdMxHO4msVRpKLyqHjgmPxLRcq8fQLwJY1MUEFwwNURYAxKekzMeSEr+JHkZ7YB/b24Ii58uLctwlWeHuqcRsaNjjsrAMKucFa+PKVMOZd/vDydgUDc1uXfOpFU0WqsNxy+KDn4O7H2OYWLO6/xuc25vgkwoekzTSY/UdnXPtVq/e9uONJzr8KGAAD1ZclRGqRWqqKkv2B8IEB8ciF3mFTpc4COjWNryVxgyxkh/xhygkww2D9F+dLyQ5MYEpQepmP6YH7+FFuNxJjLUyHjbfAFN2N2b4/vyT9cVLff+EwW5tmMiZVV6Uh4vCzG7etWUaxe6o5iuvfo0Fdvg3iqkCezgTGdbVEQ4sCIPLTXO/eEXu+nVPGCdWtOCv7apST+ CxxPofa+ QDFxyX7IBI8CRPnkAvF6VWMJV5RQ5D1OhbKPYaJit3K9cahkzdZ6rbIJnPO/X+0MqFwMf8ICEZ3zebW3cI4o0KyT6zgn+UubJi5vq5GRMhVqctD0kdPFiw9vN+gde/o1qhvLbsd2Ux5W6BKOXaoAuvrmXLrpk4ZWvXJVE9kj/YdeB1L5a/HyOLJvg2xAiauuf2YSZH1ZA6IaYfKUbHz2F7IRuOmWxzfVOBrlPycf4n7n5ew3eyNxDhQ0BoOfEHuHaJxWHaESfmP0XSDIbwJAba426uTE10dhp8EsxwaF8fSptdB896JagquvJ9nc87MywPjM7R1PLxFTt2KhIw8qmet/8u00v3RK+reDZ73Dcn6PFylawr1LmAi++Bpd3V+3kGCNThmbWbvcKNmUrFMqq5symR9QeMVnAYau7MFEVYX/Ktk1GuZXXdNBWA+wIi7EVpdn5dBXwVH//xTUp6wAF4ySkkJXh/R7iVjDU9lYBq9tLKL1+t6Am1YGCCtTbT21CxUis2Odi20ZjTDA= 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: vmap_file() is effectively an in-kernel equivalent to calling mmap() on a file. A user can pass in a file mapping, and vmap_file() will map the specified portion of that file directly to kernel virtual space. Signed-off-by: Vishal Moola (Oracle) --- include/linux/vmalloc.h | 2 + mm/vmalloc.c | 97 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 31e9ffd936e3..d5420985865f 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -192,6 +192,8 @@ extern void vfree_atomic(const void *addr); extern void *vmap(struct page **pages, unsigned int count, unsigned long flags, pgprot_t prot); +void *vmap_file(struct address_space *mapping, loff_t start, loff_t end, + unsigned long flags, pgprot_t prot); void *vmap_pfn(unsigned long *pfns, unsigned int count, pgprot_t prot); extern void vunmap(const void *addr); diff --git a/mm/vmalloc.c b/mm/vmalloc.c index a6e7acebe9ad..4b1e31a8aad9 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3475,6 +3475,103 @@ void *vmap(struct page **pages, unsigned int count, } EXPORT_SYMBOL(vmap); +/** + * vmap_file - map all folios in a file to virtually contiguous space. + * @mapping: The address space to map. + * @start: The starting byte. + * @end: The final byte to map. + * @flags: vm_area->flags. + * @prot: page protection for the mapping. + * + * Maps a file into contiguous kernel virtual space. The caller is expected + * to ensure that the folios caching the file are present and uptodate. The + * folios must remain so until the file is unmapped. + * + * If @start or @end are not PAGE_ALIGNED, vmap_file() will round + * @start down and @end up to encompass the entire range. The + * address returned is always PAGE_ALIGNED. + * + * Return: the address of the area or %NULL on failure. + */ +void *vmap_file(struct address_space *mapping, loff_t start, loff_t end, + unsigned long flags, pgprot_t prot) +{ + struct vm_struct *area; + struct folio *folio; + unsigned long addr; + pgoff_t first = start >> PAGE_SHIFT; + pgoff_t last = end >> PAGE_SHIFT; + XA_STATE(xas, &mapping->i_pages, first); + + unsigned long size = (last - first + 1) << PAGE_SHIFT; + + if (WARN_ON_ONCE(flags & VM_FLUSH_RESET_PERMS)) + return NULL; + + /* + * Your top guard is someone else's bottom guard. Not having a top + * guard compromises someone else's mappings too. + */ + if (WARN_ON_ONCE(flags & VM_NO_GUARD)) + flags &= ~VM_NO_GUARD; + + area = get_vm_area_caller(size, flags, __builtin_return_address(0)); + if (!area) + return NULL; + + addr = (unsigned long) area->addr; + + rcu_read_lock(); + xas_for_each(&xas, folio, last) { + int err; + bool pmd_bound; + + if (xas_retry(&xas, folio)) + continue; + if (!folio || xa_is_value(folio) || + !folio_test_uptodate(folio)) + goto out; + + /* We need to check if this folio will cross the pmd boundary. + * If it does, we drop the rcu lock to allow for a new page + * table allocation. + */ + + pmd_bound = (addr == (unsigned long) area->addr) || + (IS_ALIGNED(addr, PMD_SIZE)) || + ((addr & PMD_MASK) != + ((addr + folio_size(folio)) & PMD_MASK)); + + if (pmd_bound) { + xas_pause(&xas); + rcu_read_unlock(); + } + + err = vmap_range_noflush(addr, addr + folio_size(folio), + folio_pfn(folio) << PAGE_SHIFT, prot, + PAGE_SHIFT); + + if (pmd_bound) + rcu_read_lock(); + + if (err) { + vunmap(area->addr); + area->addr = NULL; + goto out; + } + + addr += folio_size(folio); + } + +out: + rcu_read_unlock(); + flush_cache_vmap((unsigned long)area->addr, + (unsigned long)area->addr + size); + + return area->addr; +} +EXPORT_SYMBOL(vmap_file); + #ifdef CONFIG_VMAP_PFN struct vmap_pfn_data { unsigned long *pfns; From patchwork Fri Jan 31 00:18:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vishal Moola (Oracle)" X-Patchwork-Id: 13955035 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 75E83C0218F for ; Fri, 31 Jan 2025 00:19:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 066892800DE; Thu, 30 Jan 2025 19:19:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F32282800DC; Thu, 30 Jan 2025 19:19:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D849E2800DE; Thu, 30 Jan 2025 19:19:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B50DB2800DC for ; Thu, 30 Jan 2025 19:19:41 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5F2E2120421 for ; Fri, 31 Jan 2025 00:19:41 +0000 (UTC) X-FDA: 83065838562.07.C79D650 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf14.hostedemail.com (Postfix) with ESMTP id 848C6100015 for ; Fri, 31 Jan 2025 00:19:39 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TK1YWWda; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738282779; a=rsa-sha256; cv=none; b=R8jQIm49VPJsxo2RvryzvZRILPWtG52l19o3EA9yQ/IIOjC7F43+Kc7+I3FHbEopC1bMT+ la3/qgSKw8A/7i6e0mLGZNUQiCk23lNOUo002OUKyO/U42hN7G5IoKb0ynooctGrQZ+k7L jT7O9DchVaxeDequaPdx8kdiayql6D0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TK1YWWda; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738282779; 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=eu4iajeZxMqtVBb9GVR/egkCI7uYsEZ5rCFcV7XgAIk=; b=q4OyqkKD3srf72dH53qGdjXXKsczYxHMuGUO4OMOD3VnkHcx8ghBKvu5LZ8Of53JG8IQYA +Fw71fNtoOEktMQIljSF4DzPSk3vx0bnGzqgbGMm+bWRJRA6llxEqUz/A4NFKqmEsiZyJW MntnJ+RNBFmXuaJ4HTPNrQ/tQtfHSpw= Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21631789fcdso34294635ad.1 for ; Thu, 30 Jan 2025 16:19:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738282778; x=1738887578; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eu4iajeZxMqtVBb9GVR/egkCI7uYsEZ5rCFcV7XgAIk=; b=TK1YWWdashCN/ZoOl6KJmOicr6P/W5SQ8gpi7LKR2alwuEdYruFnrU/Y/M9WSLT7Nx R/H7hi1fOdSNEVUoalAkOizXE9KWx4d3TH9T32Eo6ln8T6iUl48v/aZGTb9IZGJGu3Z1 Kcv9iY85ij0BeoaIom+PsGoCNpIME4eVdFDhiu37lJ+IWMg7vQEJF/KXAPboOwey2PKw ZQmpyCWnATNhsXKHtE9C6+hR4NiZmqBiw7JSrtF1YJksMzfzhtUXBuKoIwJAW3B1wTbX DSGEPrSKXVyAxTdEjPucvXUaYWEak2w6NTcXE8eb2p1RNr400TRJ5CDNZdfJBmqwhn1w 62Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738282778; x=1738887578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eu4iajeZxMqtVBb9GVR/egkCI7uYsEZ5rCFcV7XgAIk=; b=DiyFdcAK1Wmj+CIEKqaRprsBx8a/lu0ESJ/84kr4xLpyqG4FhnLchsm6k4ywIMECx3 auvnSvfLCY1An0MeF1IyB/DZ4SQTvBAR43h9zF25Ya4+gGOFxI4YYcRmo3gXu+Q0HvCH LPXjkuUIV4VS314m3e8QaAPusikT2RU0RC/3kd+VnLYM8CS4W8SMIceC9zkUQZh4e03M LZK3p1GvFaMVTcFGssKI7gem1qHD4x4KvD6u2flcxT8147cXr1dQt+6S13MGPmo08xOD DmsK2Dqu6DXQ/34+8je0TFshPYz0mhbjk5S4IAy9/JKXSxEz4vFJReEgaF9FGdhKay/r AHaQ== X-Gm-Message-State: AOJu0YybXaXhCe6M+j3Xy5PuUS01arvZ0T4W/vIIecUBhPoktICjGlhb 1SXnI5dtcdWqgzWd0WuI8DvJPQQpjQLWizaShr2NXYL4uXQG5Xci X-Gm-Gg: ASbGnctxB1QMRy7JhDsfkdlX5yEOZj535Fl51IgHFicgE59o5Y47hyOTeax3WYcTrle 8ak0RrxS0g72yLlqpy7YsJ/79pqQRB/Fu+7plex4RKVRqTZttSQJ0yGZenO3v5cgDtcuWP7N07V DKlMAuO6Xpvu/aYouk1AXRg0qvYr25uCeJrH0NcaN4lDHPCmRd+3NGpJ990Sde4QTxg5vGZDPy4 Oi9cZDaU7fthnf83+x2K946byosEbky7GAJMXDaFLL5tPH7uWB0eMPn1n0sc8iF7X3+VtrSAcsb aggZeuDRnGGYNyspOgzMAwTIL9ZEQ4XUkC34PVBhPhD/AMJzBQ== X-Google-Smtp-Source: AGHT+IFWUrM+SSQZrqyoWMSFp3NDXsO+kZxdPxA8Q4VeZa5JZviHD3s/5EQZ9UOZA/4M1BU6EsIymg== X-Received: by 2002:a05:6a00:2b43:b0:725:ebc2:c321 with SMTP id d2e1a72fcca58-72ff2b659e1mr2202540b3a.4.1738282778289; Thu, 30 Jan 2025 16:19:38 -0800 (PST) Received: from fedora.. (c-67-164-59-41.hsd1.ca.comcast.net. [67.164.59.41]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72fe6429218sm2148234b3a.66.2025.01.30.16.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2025 16:19:37 -0800 (PST) From: "Vishal Moola (Oracle)" To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, hch@infradead.org, urezki@gmail.com, intel-gfx@lists.freedesktop.org, "Vishal Moola (Oracle)" Subject: [PATCH 2/2] drm: Use vmap_file() in shmem_pin_map() Date: Thu, 30 Jan 2025 16:18:06 -0800 Message-ID: <20250131001806.92349-3-vishal.moola@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250131001806.92349-1-vishal.moola@gmail.com> References: <20250131001806.92349-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 848C6100015 X-Stat-Signature: y46ikgbzkmaxmuwf5fbhktyo3x4ttz6r X-Rspam-User: X-HE-Tag: 1738282779-29241 X-HE-Meta: U2FsdGVkX18Cq0FuoZNv5ndYsumKOL/ibuDDbxHOCRoEXIUilqaVuUWfT/eushKznCSq1yN/A8PPdRrkWO5Ery6b6/YQAv7XAorFRd3rILk42yJ7l7YmUxi2C2GunHxXwFN8xj5YVpSFZv9L6EEmh3YrSq5eELFiNWHi8MEwRp3FI3IEqUMjQRW/zc8xyt7dlBJpXgn7iPPLFcB2TsYsGZYynzR+jwO6DRzm0IMklSV5eniM4DjmxgWeMdnWUI7qXVMPGH/KTmlETuMzQ7bQ4KmzRJBitL/AIb2xv1dLtdHd1g/gLCMEK/ZrS3OfRRuYepTRfcQ8Nrx2xR5qVcc5VwxJohK2WZip8puM4tLyyMI3oaIJbnZud7i7408HZqkFm+n14PWoB6gNUaboi/tR3mUfCay212ZWJc0Ujs1HIq7mIRbI2spgiESvrmnhvejxbqQulbz0Rwegmxl+0IZMqiowesZ9vt7w/+lDK0EwzVsgk1p1b7YLYp2hwTJv/3k6hDlRVbh4/Rkv9w1ZGnANcJdPLY/Nu1AY1kFOU94cgdih3c0odrlIuruD2jx53qfxPP4uho+q0j606jThof8O/2C3IheD+GxVYA7m1JvyK8OShdSCJrOjlH6iCq5h8zR+hcpZZPWvbqRQ29GLwDFV5N4EbuTB6sYU/RQ2Lrhql9eMPWl5sch6ZKtK16FOoScan0eaMh/Z0n4kVVk2OVWuXSAUbXiW92hIFTRiiIF9GFINBGUT58ESVIiXTylPMRWZS7sYrjORzFdY5qdOOuz9XtWvtHxx2m0QyTXMQhRzjaXHS/mxmc3Jb6Yo3lWA4H8Dhl/Hd1Onmou8O5q0bHivvb9Oub1s/Y3/Cc8ceC2WeuDl649t0VhcNTzoKOOa2PrDxSnosh3LrXUtGV0Izd2rGQVYhMpyBvrz+nwdBPpktloV2QBUEBSZokl/JORe2LruEwlenDm4r2KtDrtDuFU 4Hxvv1MX rgPrQ/fAGp/pi+aHGPY73ZeLCN+vH5RpmJPpLZJU5TomVoBTpcVsfI8bniNcpni0tQ+ZyAwx++ZWZZHZw5SvIC9XmVNeRM/1bD0InJXacAG11LK5w3P+GtOfvtIyu1Xi4zraCgGWdANJWKkppvsqntLIDJyWQM7A1XZY7PkZO2gzGgNyFSt2B1KMoRrJaPl4M5u9u6QmL9ckORxfQRLJynemaByQd2ZqlRtppJWe/94mtNwXep1KV+KbwGgTHqOQ8EEIDb0dVvDfch5yCkOVSFLFhcE4wsDyxxfZSdsobt6Bqas4hUfaToDiWVwkloYSJUZ0Rr1XTI/GqeW8DCF/GCeuwC9JpaLtntwlbwvlNOyiHCcEC8mWd0o9W1VxaiHMeM5b7bcbV7AfYa+vModzPUVmxwy91PqwOj34drYv+dH3ELNdxjIUq3++2hd8THcZph32lFTTxOA2JcLtb5kV6cUjEHToyZzU0om1D+LVIJJHE84ZCAvKlz0zeGqK9MC9c7VbpJMPZUReYHfs= 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: We no longer need to allocate a new array of pages to map this file to kernel virtual space. This simplifies shmem_pin_map(), and gets rid of a user of VM_MAP_PUT_PAGES. Signed-off-by: Vishal Moola (Oracle) --- drivers/gpu/drm/i915/gt/shmem_utils.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/shmem_utils.c b/drivers/gpu/drm/i915/gt/shmem_utils.c index bb696b29ee2c..79d930ed5229 100644 --- a/drivers/gpu/drm/i915/gt/shmem_utils.c +++ b/drivers/gpu/drm/i915/gt/shmem_utils.c @@ -57,32 +57,15 @@ struct file *shmem_create_from_object(struct drm_i915_gem_object *obj) void *shmem_pin_map(struct file *file) { - struct page **pages; - size_t n_pages, i; void *vaddr; - n_pages = file->f_mapping->host->i_size >> PAGE_SHIFT; - pages = kvmalloc_array(n_pages, sizeof(*pages), GFP_KERNEL); - if (!pages) - return NULL; - - for (i = 0; i < n_pages; i++) { - pages[i] = shmem_read_mapping_page_gfp(file->f_mapping, i, - GFP_KERNEL); - if (IS_ERR(pages[i])) - goto err_page; - } + vaddr = vmap_file(file->f_mapping, 0, file->f_mapping->host->i_size, + VM_MAP, PAGE_KERNEL); - vaddr = vmap(pages, n_pages, VM_MAP_PUT_PAGES, PAGE_KERNEL); if (!vaddr) - goto err_page; + return NULL; mapping_set_unevictable(file->f_mapping); return vaddr; -err_page: - while (i--) - put_page(pages[i]); - kvfree(pages); - return NULL; } void shmem_unpin_map(struct file *file, void *ptr)