From patchwork Sun Mar 24 23:45:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13600983 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 1B4F6C47DD9 for ; Sun, 24 Mar 2024 23:45:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E520D6B0082; Sun, 24 Mar 2024 19:45:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E00FB6B0083; Sun, 24 Mar 2024 19:45:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC8476B0087; Sun, 24 Mar 2024 19:45:56 -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 C0F126B0082 for ; Sun, 24 Mar 2024 19:45:56 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8C7A914036E for ; Sun, 24 Mar 2024 23:45:56 +0000 (UTC) X-FDA: 81933567912.21.DDF3168 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id E5E3EC0011 for ; Sun, 24 Mar 2024 23:45:53 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=JkAT4erV; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711323954; 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=/JEts1OStKnPL5ABrwf0B3OJqNn8LrF0B4WO72a4AMQ=; b=HuIf27PEsJpTDHbhT1bMxzB8i994nDA5N4hH4GLvG/aezwFtNLxzTJnqY4tti+Xo8pj17k 48OWx9Web+dz1YC5zhUztIOPSB/3p0XW0p/o7DJh7xdYFmnkHe2kW9OyEzLeklDTEsykBZ dj246sgRuxrTs5TE078SSSDs7n0ur3g= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=JkAT4erV; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711323954; a=rsa-sha256; cv=none; b=jz6W2cO4PpZRawfhAxvEfzYzlfHb3HNay+ddDbYA+vPlEFXMdn+kbTRMzr9nZenGBdfz6a OkXwGkhPBmJ9y2NUUaXoXBXenIW8oIFYrsbkjn/YwcsOX3JBkECY/INApZNGwdtOEhaeSU cLk/MO1F53pMCctAUpN+wBu6WSbm6JY= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=/JEts1OStKnPL5ABrwf0B3OJqNn8LrF0B4WO72a4AMQ=; b=JkAT4erVPwVXLqkZ8mTIARGcGd M9o2nNwfv7CTTDIwlTGg7CUQK/qczAKCkd+z+0GSrayHlDZ/hT4jdOmKjWFVLcDcXidxYqVZENAdm dX3U55q7sIMTP+3kykLhJL6ZT+JH4aWBmM0ywIlXAMUZuvxVYuCevnRwdDwyqWAkOEZPCQTiZumuR QavHISGR/mTImQqRIAUIbEcXpUfBgrH/pu+xdTaGpZkkFel0gqtkcQ9T7/vggDqk0OS5UMygq1E2T SASwhv9yVsP8WQRVBPXXUyREMDTxQWG2sHQGWg1mtEfrTtrjmoA2mI2JY0gDrPiOI1NXESTn7rrRJ 6u5kqtWw==; Received: from [210.13.83.2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1roXXD-0000000DwmR-14sN; Sun, 24 Mar 2024 23:45:51 +0000 From: Christoph Hellwig To: Andrew Morton , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Fei Li Cc: x86@kernel.org, linux-mm@kvack.org Subject: [PATCH 1/3] virt: acrn: stop using follow_pfn Date: Mon, 25 Mar 2024 07:45:40 +0800 Message-Id: <20240324234542.2038726-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240324234542.2038726-1-hch@lst.de> References: <20240324234542.2038726-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: E5E3EC0011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 9rf4od6o19cei3isddmzku8ppxn3oamx X-HE-Tag: 1711323953-337933 X-HE-Meta: U2FsdGVkX19MkB4Fcimqytd7HjBDCN/EYB17GZXez+aKMr6gS29r8N0RzU0/b4LypVkECPvhf7Rj9UwB2lQze87Sv+uA4mlvaVH7Yg5JTw++CEdeDJOhfzrFN072erR1CdkqpAQMfgUc+iKSndvJQ7eZAwBbE9d/6g7ALs4wIVXc/hbCeGSimlYfO2qeaDH/UvIZ8dVyGEvAZug1bVa/4BgMRL5KfYBfp3Ddkkgp1zlBh24mJ/bybvtSMr+4OsLF8HQh+6k7Ji05ZkLlgcdFTEVZ0b3usgMPJ4z61llO8IDM3ZuDAejSlE2ed17b2PdHZf7nCLSPes0ca7tA09YHVyRCMUIQvh+KwIoA9ORd804PiP/Ci6Y+6JcbpOFoRYN7T05/CjM18HfGPak3D4nJo1SVAhBP0/uEtmV0/jTnxXGEqHDY7tlltQJ+z2ZutFpKWjEIwGvN092ejQ9DVGd0phBYyo/SIFkCVVvMuq2vn74Ljz+lMQqY5wnHxNIwTd3dAC9yKPcj5RX74O6DM7DadGVJw7T//JU0Kh32UpBU2COPbcaynHiKtpwgxO1jNxggcswlwlILsy4RMmtHzinzd2IFpx60LfWItYiz6O8w9jfKTiiEt+q1szeGBoeSydfKLRrlkufT3c/HJuEejzkvKESSwePgenR2dFGAv9ZPbuKZxAWJtUNzn/UpFpUD3PRklUxoAMzAwKYcSbAwt9F7097oAWC6lMtGvdB50sq/yOrMXTs3z7DP/6/fkMm1a+cFRHDQKDgdTRlwnEKTzSzx2KHlPF0NQZVLsWQk6fXhzFKA59fhlKlAElA4eVu6Ze0fwaAWrmN/a52AhkSRwjBYF9hfXVTVTCb27lI+YT2dOTXOkpkwHchkAeNpx0TpQQTHiEzf0gkcFF2fthM5cephMVVyXQ7BD6kAXU8X0dPbMONVUDkzJ//9efWNTAY1S+lgs4J9p9+B2gmhswCaGfp wZr6rAdW 2nOjyMHGsHxbI9O73Vus/PGwOejKag9AEPRKFZH9FBNTbSytgxhELuQze8HG67qVVMpYJrdbhnDIybUlVUyFM7QGJUo7wI9eUHQg5TyyW+b+rBCOVVU/N+gUYVx6qrNwKCWXoPOhd6btlq/jPuG6NfQaj2Y+eL+SDUAA0NAjHJSBgGItEDSaxIrQfxVeNtIW28EYV02zYIGd+32lJv395LgR56XFndNCXZ5WATBGHoliOLADaAgyFMP+SOFxbKyJhWqK7Z01y5YIeeq/7TxoNSnwm9oeXxWIoByizKcI6uGJ88Qwj/xNXJ3W/QfsYYbbIsww1bDJE/h+y/3LLbCfdtDlWPdZysYaywVyEuQh5o6I/EzVjM4cQJfNX2G5yLSTsOf2eraTJPfUyB++ddAzweFLPgYmItj0c6EvnTcygG9ATiyKJ3FLz6LMWdQ== 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: Switch from follow_pfn to follow_pte so that we can get rid of follow_pfn. Note that this doesn't fix any of the pre-existing raciness and lack of permission checking in the code. Signed-off-by: Christoph Hellwig Reviewed-by: David Hildenbrand --- drivers/virt/acrn/mm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/virt/acrn/mm.c b/drivers/virt/acrn/mm.c index fa5d9ca6be5706..69c3f619f88196 100644 --- a/drivers/virt/acrn/mm.c +++ b/drivers/virt/acrn/mm.c @@ -171,18 +171,24 @@ int acrn_vm_ram_map(struct acrn_vm *vm, struct acrn_vm_memmap *memmap) mmap_read_lock(current->mm); vma = vma_lookup(current->mm, memmap->vma_base); if (vma && ((vma->vm_flags & VM_PFNMAP) != 0)) { + spinlock_t *ptl; + pte_t *ptep; + if ((memmap->vma_base + memmap->len) > vma->vm_end) { mmap_read_unlock(current->mm); return -EINVAL; } - ret = follow_pfn(vma, memmap->vma_base, &pfn); - mmap_read_unlock(current->mm); + ret = follow_pte(vma->vm_mm, memmap->vma_base, &ptep, &ptl); if (ret < 0) { + mmap_read_unlock(current->mm); dev_dbg(acrn_dev.this_device, "Failed to lookup PFN at VMA:%pK.\n", (void *)memmap->vma_base); return ret; } + pfn = pte_pfn(ptep_get(ptep)); + pte_unmap_unlock(ptep, ptl); + mmap_read_unlock(current->mm); return acrn_mm_region_add(vm, memmap->user_vm_pa, PFN_PHYS(pfn), memmap->len, From patchwork Sun Mar 24 23:45:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13600984 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 ED676C54E58 for ; Sun, 24 Mar 2024 23:46:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E93D6B0087; Sun, 24 Mar 2024 19:46:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 771F26B0088; Sun, 24 Mar 2024 19:46:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6129F6B0089; Sun, 24 Mar 2024 19:46:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4D6676B0087 for ; Sun, 24 Mar 2024 19:46:09 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 23D4280183 for ; Sun, 24 Mar 2024 23:46:09 +0000 (UTC) X-FDA: 81933568458.06.9951242 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id A2B4BC000A for ; Sun, 24 Mar 2024 23:46:07 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Zs83sjYR; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711323967; 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=QR9PmT9kuEPLqJlaQ7HoUyIFQl+oTbi7KFvMo1nZb5I=; b=EuV7dXstikoNWmVYr3YWLmpxLxv6f/2DkGypHRarvWNsFHblPxSqYCDYI/q8ersOFm7nLM 1xBxZoMGzAuG751HyY6twm1UQ/cgQSnQPeyRyA7bSWEjO06PXcYa3G4hOrJ7wO1wjeVIvq 279Y/TbbG0fDd5Df4B99mUlbOAXbi1c= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Zs83sjYR; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711323967; a=rsa-sha256; cv=none; b=64mobmSsFVoXqAQxaVDGOF0NOKcn/NPk0NQPMw8wdKZ4lXuMjtfUag8pHCfVFWjvdsSMQi Z3HIr1NgO5Zl6f/I/UHElBL9iyVl/Ki2R7/9OfGncyGYV6qZoqZhWM/EJSiskEa0zTiBWo tVvJaIAizVgVUB2mK7RWyTANP7wdjJM= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=QR9PmT9kuEPLqJlaQ7HoUyIFQl+oTbi7KFvMo1nZb5I=; b=Zs83sjYRCSzsRs0rqWWvIZyqvC 3cfZJiBgQclExbKdvY0+fg95kokQpyTjkch7QxseKHpCjFxkDFSTUhR1cvUva5t4vz3B3ROGCFChI 9hXCd0YFpu4KSDAP5X5kEj8xdwxnxrkhfxg6SoMOEP50b4+/sGgi2/pUIdoXvwXtBUl7LRbJquTcM etu8XL/Pa9y4QHIa0Qh6BAyTrf83lnrRYRJ9BsZ3cDjI9TOu9YDdIXAMOgLXFgKiz3XLD3NvtGiFP JTf1ZN3MJ8SdCK9AC/1WmKGAzHLZcOPdvosqqE2zolMI8nG1rJBlTyU9fd0yx0jLBgtAgg6/1fs20 JW2YFUMg==; Received: from [210.13.83.2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1roXXG-0000000DwnQ-22qb; Sun, 24 Mar 2024 23:45:55 +0000 From: Christoph Hellwig To: Andrew Morton , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Fei Li Cc: x86@kernel.org, linux-mm@kvack.org Subject: [PATCH 2/3] mm: remove follow_pfn Date: Mon, 25 Mar 2024 07:45:41 +0800 Message-Id: <20240324234542.2038726-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240324234542.2038726-1-hch@lst.de> References: <20240324234542.2038726-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: A2B4BC000A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: eukg7rziijyptyb7cqttykp9piu7mmq4 X-HE-Tag: 1711323967-406613 X-HE-Meta: U2FsdGVkX19cKDn9Q3JeRg1lcNdpe5yKSm18655vTfdZCbE0GbIQ4SPIhk7UhcmPpZ9gLbAhsUJ3P+UUilLV4gkBoyNB/5i+Fqltsg6hutf7U4TO7RjhfkKOjB7rsS+5D0z8ssjCsQ5RsYjWH170hasmYa6lserKdD6CzZ73D4Ursg7oKsjFu7W1h6RapMXk4/vPjnnqezLigsQSttM1C6b0sJOCRhenr8qoLe5EjEgOJ1tTBZoI+cckJY4XIleRDSYDH4/LSW09IYPONy694HjJgba56rMkx1T45nGt7y9zeCgy/iyRdPD1ctsKhzLGeDd/TcYWgrCZ+D2r65AdNX7eNCkbubaaqZkMpgVs7NkPT3zEO31GCGLIv+oxxrCfjqNfgiGpNvhdaQ7H/OmG/WoxnfxZvFffkHpBpa75LSlqmN/Kl10Pn5FjR40JBBw4nMeIjXNkwEcnr4o+ISktO2ojm2dSZlxQe3RjOqWDmTdR204WHW6hUARSPEdgxlaGZSWMtsqZgXSv0elXA0+mc3eXLxb2BqPOnzxOW5fg7Iqplmm9oRZbtdMpovgCcRVtn/o7H7fT+Dl2BYomZfB6I0+XoU5P7h7FASP/mrHTPkR4xjOG/yfltuF51NbQ8weFIKSjYAYMMcBeHxfmza5okoUDwRBcShUsZyCI460TqaQbYrQNgr7oaO3gnhLbCDMWkQglru3v4awH8z3dt5g0Rcg1IY1Nt8o8AXhCGpEhcsYUxv618FzGV1o3wnxP24jkFaUJiWVI24DpL4BcBMU4KPwCmsvyaC6//jLc8yjBbLffk6pNi+Fyto40vO+IBkLB9NQRuq/SIWib5sZkXSJne0M1h1rH6fFkO5cHRIF8Cn0QzS8kR1YV5SHKkO00saMvPa+C7yBVjOnfIxqMD8/a6jCWZupgdy382ly7Nmor0oOoQZ3f/b2opYcYpj8WTeZG4yoN0/ZbxfSLe+r3FrS z/uNvpTI 9uPEn9+B/RxtUSrowv9ZIUSr92yWnezedCK1Zlg79QZlpEyKm6t9ZNn7TXFWROD2Pq/7VAuaf9psCbZxBRRKaxakV8CcRXFxXLXaLORtSWAcgX9ewz/bG5iJZ5qKCYt/2Gtxolt8OAL+TlTHFrJtIPnvgSwNv5vMR7K9g5wn4b2JdVdJNNR54T9tdNC3by6b/MmR4E49ALGLBH45oc6/6OfowgA== 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: Remove follow_pfn now that the last user is gone. Signed-off-by: Christoph Hellwig Reviewed-by: David Hildenbrand --- include/linux/mm.h | 2 -- mm/memory.c | 36 ++---------------------------------- mm/nommu.c | 21 --------------------- 3 files changed, 2 insertions(+), 57 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 0436b919f1c7fc..9cd2c69f913601 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2393,8 +2393,6 @@ int copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma); int follow_pte(struct mm_struct *mm, unsigned long address, pte_t **ptepp, spinlock_t **ptlp); -int follow_pfn(struct vm_area_struct *vma, unsigned long address, - unsigned long *pfn); int follow_phys(struct vm_area_struct *vma, unsigned long address, unsigned int flags, unsigned long *prot, resource_size_t *phys); int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, diff --git a/mm/memory.c b/mm/memory.c index f2bc6dd15eb830..d7f09d5aae6e53 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5880,8 +5880,8 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address) * Only IO mappings and raw PFN mappings are allowed. The mmap semaphore * should be taken for read. * - * KVM uses this function. While it is arguably less bad than ``follow_pfn``, - * it is not a good general-purpose API. + * KVM uses this function. While it is arguably less bad than the historic + * ``follow_pfn``, it is not a good general-purpose API. * * Return: zero on success, -ve otherwise. */ @@ -5923,38 +5923,6 @@ int follow_pte(struct mm_struct *mm, unsigned long address, } EXPORT_SYMBOL_GPL(follow_pte); -/** - * follow_pfn - look up PFN at a user virtual address - * @vma: memory mapping - * @address: user virtual address - * @pfn: location to store found PFN - * - * Only IO mappings and raw PFN mappings are allowed. - * - * This function does not allow the caller to read the permissions - * of the PTE. Do not use it. - * - * Return: zero and the pfn at @pfn on success, -ve otherwise. - */ -int follow_pfn(struct vm_area_struct *vma, unsigned long address, - unsigned long *pfn) -{ - int ret = -EINVAL; - spinlock_t *ptl; - pte_t *ptep; - - if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) - return ret; - - ret = follow_pte(vma->vm_mm, address, &ptep, &ptl); - if (ret) - return ret; - *pfn = pte_pfn(ptep_get(ptep)); - pte_unmap_unlock(ptep, ptl); - return 0; -} -EXPORT_SYMBOL(follow_pfn); - #ifdef CONFIG_HAVE_IOREMAP_PROT int follow_phys(struct vm_area_struct *vma, unsigned long address, unsigned int flags, diff --git a/mm/nommu.c b/mm/nommu.c index 5ec8f44e7ce976..38d3ecc30c3ba9 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -110,27 +110,6 @@ unsigned int kobjsize(const void *objp) return page_size(page); } -/** - * follow_pfn - look up PFN at a user virtual address - * @vma: memory mapping - * @address: user virtual address - * @pfn: location to store found PFN - * - * Only IO mappings and raw PFN mappings are allowed. - * - * Returns zero and the pfn at @pfn on success, -ve otherwise. - */ -int follow_pfn(struct vm_area_struct *vma, unsigned long address, - unsigned long *pfn) -{ - if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) - return -EINVAL; - - *pfn = address >> PAGE_SHIFT; - return 0; -} -EXPORT_SYMBOL(follow_pfn); - void vfree(const void *addr) { kfree(addr); From patchwork Sun Mar 24 23:45:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13600985 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 35906C54E58 for ; Sun, 24 Mar 2024 23:46:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACF486B0089; Sun, 24 Mar 2024 19:46:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A59456B008A; Sun, 24 Mar 2024 19:46:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D1D46B008C; Sun, 24 Mar 2024 19:46:12 -0400 (EDT) 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 76D6D6B0089 for ; Sun, 24 Mar 2024 19:46:12 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 188874037A for ; Sun, 24 Mar 2024 23:46:11 +0000 (UTC) X-FDA: 81933568542.27.B7F2443 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf18.hostedemail.com (Postfix) with ESMTP id 6FFF81C0004 for ; Sun, 24 Mar 2024 23:46:09 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QXgZMMpR; dmarc=none; spf=none (imf18.hostedemail.com: domain of BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711323969; 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=FQRJSVyMberX2vDsUp5mo/S6Q3R7hY4FU2pyCrHDOe0=; b=LUFPCvS7rDdGik73HAsTFHdrAW/B2HTHuJ4nNW2JwAd6IyxmI2/FDKeNSYyCRu3jN0MMEU KgTOmV6UsTtBdXen/keOJbgKNi8munPXI+n5D+8+9kmUsNurLl8FItC71TlBp8+cVCSHRR k6o+uKXDvdHzysEAOiibQCuQnth8VFA= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QXgZMMpR; dmarc=none; spf=none (imf18.hostedemail.com: domain of BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+9b69c840030af2843ecd+7518+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711323969; a=rsa-sha256; cv=none; b=WhsCPmAXYFDg8OXuD8hXjenLWvmkY/nBZKR1XsC3QdLomauYv9D+EHYkbRk/ETIJZwaK6k FHXvNq3MHhwqZqq3ELhzv6xe9LBXUe5pumtULcW+Uz6m2sZQcVgo/oPSVmqWpf2j0TtgyM HjcduKNTEQ2wLfhAnf9/b/SXuDBIksM= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=FQRJSVyMberX2vDsUp5mo/S6Q3R7hY4FU2pyCrHDOe0=; b=QXgZMMpRAeBhlDPEQ/H3RGaM6C x+hPwZQYb3wzFzDU61HYmSZ2Rge7XmehQrFxRqptqv/R86TQ0ZffkPpwZgFzK5MKxMvgTaoiiCcRp a9cYSZs9Hb4uezqI+FRRIT0/n15I4rRsJpLnOQOPwInPVUK4aRtfrL7xXjm6tdoYmg+ckl1Up3lvy lGu5PGn2Cize38l7sJxRR4EtIMnJ6PUWXKXUdMvUKIruM5Ca+T2EThBs8YkYvyHCUq8lQxw3ZtQC2 +o3KNpkpf+Dy0IW9+46E5H2dv+YEPbARTLWDBlKZhXygaG3CmWMBxtnXa0Cld/Dk99FzMh62Ghd0K qVcMe1fA==; Received: from [210.13.83.2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1roXXK-0000000Dwp3-0WZY; Sun, 24 Mar 2024 23:46:07 +0000 From: Christoph Hellwig To: Andrew Morton , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Fei Li Cc: x86@kernel.org, linux-mm@kvack.org Subject: [PATCH 3/3] mm: move follow_phys to arch/x86/mm/pat/memtype.c Date: Mon, 25 Mar 2024 07:45:42 +0800 Message-Id: <20240324234542.2038726-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240324234542.2038726-1-hch@lst.de> References: <20240324234542.2038726-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Stat-Signature: hjysun51b4gbrkozzasow5d5f5qst18c X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6FFF81C0004 X-HE-Tag: 1711323969-633305 X-HE-Meta: U2FsdGVkX1+m+CJ604t14nlUaEF1omNX8jk9P6OqoSwhAlafub5ntlKotXsyyPSxfSLJmOom1C5BxrOhUfRHqBN3ISozYbLIgY2brzaCQGeg9cmCHGI6twHyUL82PEFVq4rFmv1LZ18krdLtT2tVgaGvNKNmNf9BsuCGkeAIj58NwS8bwzpOLu6vXxKNKtCzodRQ8MfByqTptHgwWtYpvaoJSRw8dGU9AbUdF5pOYnlvV8npNbt9WbQeKZFv6Ah0RK66M5xwl2acrEM5Jj+ncVCW9QhhZU9tWtLGTENWTXdrFRpg8e1bxAe39Z6178Qv/Nz+s1YaiLMUiY1GIaGxLy3lOjVjKiXVIv4Gg4afiMlu21gK1EyWHBsGbEHctcCg+NgWRlI5MGxj5L2BTMZxph2oZmpUJl9r7bMKt4aHlEcuOMW+pNnpWLPFWv2Vg4el6eyCRIkdygE/02VUxdjL8ogNhnmHGGn/zkXOO+hHjc7JplzTIFmu5aBpDc3LnxNQSehXK9OhlmRDrJbMNE8IbQoOBO6KJjxUnC2bQ6tYyeAfr2CY016+BnPH+Wq0GGTGRSoCFZg9g3MmPLT0dmCOuY0mgvxvFhqmAmd5CC3wRBQuNnraEzYdH78F39fyy1dnQv2oEVQ7rnhqDqW6XDvpcPivuipsD6GbqJENn/HUsTwzeZ0VOSHG7MoTvYGennrJ/CqKloTrB5uS4HDnjqa+vwhMG3rbb+Hn1+jD+DxV1aCbnBfz4AgnWSoih8pnHj/n0zMlwpsmVDDVpJJp6sANmicg7koEJwvJSn5ZGwh7+MQEbE20PAV79ujBtstoODIPFCz28HWUQhDZtBhqdzb1yJzaaABUax9xoYs1Kk0QPk3ybjGC+NCYFF+BcwE7+cIE/R5zAJp53d8DhH12YzhbxEU9vZbDaF/PESVYjN0ccilFu2F5FLFxN8hG0h1Hq1iVIziwwdYrWqo+gV/JAWH ERdQDeWY BunLmWHwdERhPXkSckamVQslQkCoXTaa8ASGH9JTrEkBekPi9AlXW4QOULVfKkGxhDsDiWYetYHwpEJ2DiLVkRpCmYZDn/KU1bDGRz5nlTUoBACDXrZNGt9kBOe9tT9deJszsE3rCE7pTopPhS8dsMVMOF3Ew8G9DrDg2xU5Vc0naPWOLPTlat22BufLYcgtLMIS6/K07zqKE4KriI2nLCnPgpRQqCdqYLkA2CuD+/nk74LBIkJLMyT5qO2r7gz8jfAQdnnSEU3j+WAtbmybyOHYBIrp9uao8cAB8NLY+hHyrAHqc8j8JW5675XUTP6KoYYCzMZppBjnWLlAS0arM1LcyH2Vy/REscLjB86r+90cserg1jdNad9RUPAfJD0oz69Hj7udPCEjTGKSbl/2PFA44lRNJsEiQodJxUM0QKnkusCRmRJXL0i6m8Q== 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: follow_phys is only used by two allers in arch/x86/mm/pat/memtype.c. Move it there and hardcode the two arguments that get the same values passed by both caller. Signed-off-by: Christoph Hellwig --- arch/x86/mm/pat/memtype.c | 22 ++++++++++++++++++++-- include/linux/mm.h | 2 -- mm/memory.c | 28 ---------------------------- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 0d72183b5dd028..bad99eb5c95b0d 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -947,6 +947,24 @@ static void free_pfn_range(u64 paddr, unsigned long size) memtype_free(paddr, paddr + size); } +static int follow_phys(struct vm_area_struct *vma, unsigned long *prot, + resource_size_t *phys) +{ + pte_t *ptep, pte; + spinlock_t *ptl; + + if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) + return -EINVAL; + + if (follow_pte(vma->vm_mm, vma->vm_start, &ptep, &ptl)) + return -EINVAL; + pte = ptep_get(ptep); + *prot = pgprot_val(pte_pgprot(pte)); + *phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT; + pte_unmap_unlock(ptep, ptl); + return 0; +} + /* * track_pfn_copy is called when vma that is covering the pfnmap gets * copied through copy_page_range(). @@ -966,7 +984,7 @@ int track_pfn_copy(struct vm_area_struct *vma) * reserve the whole chunk covered by vma. We need the * starting address and protection from pte. */ - if (follow_phys(vma, vma->vm_start, 0, &prot, &paddr)) { + if (follow_phys(vma, &prot, &paddr)) { WARN_ON_ONCE(1); return -EINVAL; } @@ -1053,7 +1071,7 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn, /* free the chunk starting from pfn or the whole chunk */ paddr = (resource_size_t)pfn << PAGE_SHIFT; if (!paddr && !size) { - if (follow_phys(vma, vma->vm_start, 0, &prot, &paddr)) { + if (follow_phys(vma, &prot, &paddr)) { WARN_ON_ONCE(1); return; } diff --git a/include/linux/mm.h b/include/linux/mm.h index 9cd2c69f913601..51cfc8267da755 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2393,8 +2393,6 @@ int copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma); int follow_pte(struct mm_struct *mm, unsigned long address, pte_t **ptepp, spinlock_t **ptlp); -int follow_phys(struct vm_area_struct *vma, unsigned long address, - unsigned int flags, unsigned long *prot, resource_size_t *phys); int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, void *buf, int len, int write); diff --git a/mm/memory.c b/mm/memory.c index d7f09d5aae6e53..d18f6d15f56e6c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5924,34 +5924,6 @@ int follow_pte(struct mm_struct *mm, unsigned long address, EXPORT_SYMBOL_GPL(follow_pte); #ifdef CONFIG_HAVE_IOREMAP_PROT -int follow_phys(struct vm_area_struct *vma, - unsigned long address, unsigned int flags, - unsigned long *prot, resource_size_t *phys) -{ - int ret = -EINVAL; - pte_t *ptep, pte; - spinlock_t *ptl; - - if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) - goto out; - - if (follow_pte(vma->vm_mm, address, &ptep, &ptl)) - goto out; - pte = ptep_get(ptep); - - if ((flags & FOLL_WRITE) && !pte_write(pte)) - goto unlock; - - *prot = pgprot_val(pte_pgprot(pte)); - *phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT; - - ret = 0; -unlock: - pte_unmap_unlock(ptep, ptl); -out: - return ret; -} - /** * generic_access_phys - generic implementation for iomem mmap access * @vma: the vma to access