From patchwork Thu Mar 28 08:46:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13608186 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 7E356C54E67 for ; Thu, 28 Mar 2024 08:46:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED0796B0099; Thu, 28 Mar 2024 04:46:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E81896B009A; Thu, 28 Mar 2024 04:46:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D22696B009B; Thu, 28 Mar 2024 04:46:40 -0400 (EDT) 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 AE3FB6B0099 for ; Thu, 28 Mar 2024 04:46:40 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BD3FC1210EF for ; Thu, 28 Mar 2024 08:46:39 +0000 (UTC) X-FDA: 81945816918.18.0C99FF8 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 2060240008 for ; Thu, 28 Mar 2024 08:46:37 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fJQ4qQ6+; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+62e9139b449b679ee457+7522+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=1711615598; 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=k8Anl1as3ek0+VrxzOKuWdGKsmgPAuR9n8xz26CHgC4=; b=2O7p18HJMROKNDbfBVaIUXQFQB59NCyALJRVgu10wmg7TBTeeM7/qHFrZpgCIBf57C0ZeC nqsBvL+asQjlcM9sjhFbBXDy/e2CbEDwtXrHMRJObQaCALBYclQsmhwPM/9565MUpuQbLJ 5ufziObq/nlZ5574cY1+eRBey74UCoQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fJQ4qQ6+; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711615598; a=rsa-sha256; cv=none; b=GqVOs+weMR/L0fVkK9WxoKwt4OZNA4BrxzHtxIa7PKquAvKNGmF5xK84CJJHboYHgc8+Cd MP/WYASW0V5LJuUW/QiiHeRPq8OYQ5otx5Llhap8thswapqkT7F3C+nCaVAb47IzrH9/m/ qwOH2fsziC3SXVGlkV46640s1qAgMRM= 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=k8Anl1as3ek0+VrxzOKuWdGKsmgPAuR9n8xz26CHgC4=; b=fJQ4qQ6+efadpvyiPGzbB6yn3W is9aFsbjv94+FOQOohTsKRYu1W6DSsp5NfqW6Wckuah3F6AsXxYRjGBa6RF4j2wanPx5Q6IHe626K xGZ/x8eEh3/TFz9SbsmIzz+oyJuhAxtD1tmrI0Sb+y7DI14mSa3QF7MCJeNThehft60vVWlAKMUq6 bD+CqD55VpmhwVU5p4RVj4TDhfv/QnZRiYBwXVsy8MkjVl8nrumR7A70rKWfKhBAsOrPFmbDHgft5 qDG3ds0T7Vl6dTWoAkEdCxMX+L1g/kuujRTtxA0om0N3sZxsOIfNTc78yRBjCX0EXOklcKH2yzpwQ wfZU9scA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rplP9-0000000D8gV-1oP8; Thu, 28 Mar 2024 08:46:35 +0000 From: Christoph Hellwig To: Andrew Morton , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Fei Li Cc: x86@kernel.org, linux-mm@kvack.org, David Hildenbrand Subject: [PATCH 1/3] virt: acrn: stop using follow_pfn Date: Thu, 28 Mar 2024 09:46:27 +0100 Message-Id: <20240328084629.2955393-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240328084629.2955393-1-hch@lst.de> References: <20240328084629.2955393-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: j9py1an1ditrt1jih7kgjee8zfjoqbe7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2060240008 X-HE-Tag: 1711615597-157549 X-HE-Meta: U2FsdGVkX19sv07RdztV9vwC2KmkvRcLS1bYhcsoSqlppv+IIBuhi5NJiZiptHSgqLjK/wt4nR2HWRh8AYOziqrooDfOmTFgt82hEu5jql/ubjfIH+iKEaDkuI7cTM7cVLkrUg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ikjrMa/ssd9D7gWWPJHtiDWIxoUaV7e8g7CZXXb0sVSaB+irDVVyGx66Pu7itwfCn8yED59VrkdVzcFQ4aA/2c2i8lKIppnJct78rUWJQ/qsl6JeWOrJL2OtZCDbZRrDsgy/fCFvoWLHVm43DP4p+/Nm2WkqTRxXS1m9gkwNx6NwHOHnj6ZnmSHzQAwn3/5/TVfvYWIvw42Qdv/fNw01KwqwR83eCE1ehhGgsNks+caBmM8Iv8K7V0GaOSnibf/aOnsZlG2zVGhKcUJ4= 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 Thu Mar 28 08:46:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13608187 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 31F65CD11DD for ; Thu, 28 Mar 2024 08:46:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BA7F6B007B; Thu, 28 Mar 2024 04:46:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 66AFA6B0082; Thu, 28 Mar 2024 04:46:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50CA86B0085; Thu, 28 Mar 2024 04:46:42 -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 2C50D6B007B for ; Thu, 28 Mar 2024 04:46:42 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D73C8141004 for ; Thu, 28 Mar 2024 08:46:41 +0000 (UTC) X-FDA: 81945817002.11.4CFDA6A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf25.hostedemail.com (Postfix) with ESMTP id 387C0A000D for ; Thu, 28 Mar 2024 08:46:39 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=mcw3eN85; dmarc=none; spf=none (imf25.hostedemail.com: domain of BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+62e9139b449b679ee457+7522+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=1711615600; 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=ufsEjvPUOPudX1DkAEKQaH/I0oOilNFfYnYStusOBYs=; b=B6+4Chg+k4eAgMg1nsX2JooQKnoNMdnP+7bWDb2qGcxJsqGWDy1tFdpwTVgZiNQqZTeOGA HvNtUb2a0rBF+STKJ52zxcokVjS5treG7hJyNKr9aZNuvrrnolVZKGIfVwBgKC+DahS3dL Yu8+hdF3YKlJgw13VD8do4GZqqfS/BU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=mcw3eN85; dmarc=none; spf=none (imf25.hostedemail.com: domain of BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711615600; a=rsa-sha256; cv=none; b=y30W9kB9GYMGwRWfsA7NLEGRJbqYtNLJai0fxem5/RgcUfcj1t2bZIvl0v1vd49FIBlGV9 FwtnNT01+t9j3NNOwVYleAm6k2dymaYv204Mc77wJCDwEPqp9b/pttXHGjh6fpV4Iy8BhK c03wX0Pj4I6e/pOxh1hjKQwjqRR1IX0= 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=ufsEjvPUOPudX1DkAEKQaH/I0oOilNFfYnYStusOBYs=; b=mcw3eN85e3HV/AabT1H20sM66K KeNY4IRShDHsVwq1ZDac5u6dTub9w2QvF4eRLh//rBmZn+8TNknEP2QkKuDC3+C5bTvTLg8ukEdS3 pc2yH74GcrjQYLIF2kqkZrMTxDCbm9g9h11YBwEBSghlf3cgRPdpc19PmRhZieGioZfzbFhI0Fmor hxHODWTaEILXwJQj9Mc9311Uy1gQeYwzvbXv5SOJOWrwxeDWfbk5nrJsCFK3KO4/h7lSKwqR10CGK ICA3Pf6622si855Mwz7COJH6WDxuu5kXajx6/yNcZo0h4waZeZcwzeLoeyLje2aQgFI/TRz1USOxA fkv2gPQA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rplPC-0000000D8gv-1QIi; Thu, 28 Mar 2024 08:46:38 +0000 From: Christoph Hellwig To: Andrew Morton , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Fei Li Cc: x86@kernel.org, linux-mm@kvack.org, David Hildenbrand Subject: [PATCH 2/3] mm: remove follow_pfn Date: Thu, 28 Mar 2024 09:46:28 +0100 Message-Id: <20240328084629.2955393-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240328084629.2955393-1-hch@lst.de> References: <20240328084629.2955393-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: 387C0A000D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: m6cbjhwe93sgmjqyq1t63di13f6uwcxx X-HE-Tag: 1711615599-807628 X-HE-Meta: U2FsdGVkX180BVmkcrtmgRZHCze/i1knTLbHxRsvZx5tSeuuLn5MBArD7+T846ZNiym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w6K3r4HgGq7hV/eaJJYDSf3KHhdv3uhAkGfv9xEhz6vOc0jKrRaf8N5Qp1jGvvgvZ/uiZuyaWgqW1SyI1meDAH3+B8iiIg6ZERXzWfZFtqdqFpNcVrDlAOQJcvZsuPkYBlfkV/k2/LvkqJ/w79pTg5LBU1wv7JSajF7vaHowP7J30fSvuIvWeiY73u1+ukfVTDh2/i9oCvQb8wo/6eiBBqTUSIZRohbQBGoIX/I/lHHSKRZw5LCZaaAI5WTaXUAiHDnoCRSXMQQLvY25A/3plZIlMDGFO7wFpk9s05KNsGXKU5RcenSjGgsCnNkBpScevqqicAOYIRGGCQDNr3Q= 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 904f70b994985a..33559720f0aab9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5882,8 +5882,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. */ @@ -5925,38 +5925,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 Thu Mar 28 08:46:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13608188 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 D9EEAC54E67 for ; Thu, 28 Mar 2024 08:46:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 757166B009B; Thu, 28 Mar 2024 04:46:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E0856B009C; Thu, 28 Mar 2024 04:46:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 581AA6B009D; Thu, 28 Mar 2024 04:46:45 -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 35B7F6B009B for ; Thu, 28 Mar 2024 04:46:45 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DBB06A1687 for ; Thu, 28 Mar 2024 08:46:44 +0000 (UTC) X-FDA: 81945817128.30.5E93DA2 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf03.hostedemail.com (Postfix) with ESMTP id 390C120003 for ; Thu, 28 Mar 2024 08:46:43 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=bThOeOzH; dmarc=none; spf=none (imf03.hostedemail.com: domain of BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+62e9139b449b679ee457+7522+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=1711615603; 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=r1km+gQJV2RGGqgd+ndA0x/XaOcGVb0lxKd0daLgq8w=; b=UEfw/cG5Kh/OOp0e3T5Jrk4ED/rMFI85HO1gGhNoJqmWmrLSgTKE2lWBYFoz0vLIpt2Q2I 9/2teseagiBRZ1zxciRoFpXW47u44qulrrEVpS8IMwTPp/B3DVu2c6fI61amNb2jzJMQ/F HxBw+fTR8f7TqNwqHK5Ch7vRl+YvCZQ= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=bThOeOzH; dmarc=none; spf=none (imf03.hostedemail.com: domain of BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+62e9139b449b679ee457+7522+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711615603; a=rsa-sha256; cv=none; b=rASSSfxzTDtbvjWAUFnZDP+7p8EAUxpt27LDBRzBoVuwjz/fMAbyzGlfXz+pc05qC6O8Sg r9We+nfGwDX+PybfIl0NW1CbowJHT7VoTOnizca+MXtWrdbrILsxfth6TD0MgvSBDjDNWe QnbWYt+RxSWtcqN1HwgDH93aEYMaZ60= 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=r1km+gQJV2RGGqgd+ndA0x/XaOcGVb0lxKd0daLgq8w=; b=bThOeOzHqXNM7LjCRevtHzIeNG DGt89zOIHlQYFHUi86W1eOo9YSHeq5lUtUql5W0/HEG9sQujSn9oOj/LxUc0z6//VnnhKw0tVrM3t EP2JZXSmUS8PR/Ix5cp+oo53Uogh8GyfO1V+/OutE5U1fsu+o15Y2aCLKT/mejZerf1Qpmzq7LAJM WSiI0F45gWtxewylgHE8F3t0RMEXqj+EqscFe/rLlPNdfra0OSzWXEH5gT07nWjgG7qUXoTUPTUyr +pkEgKc5gzRnWlUKiYFxUUsL2qMamOJRZV35E8p22C75oFYEdGH4/dPZ3bgiuDHj3KTJWWgCIbWTE A9hplXtg==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rplPF-0000000D8hm-0N25; Thu, 28 Mar 2024 08:46:41 +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: Thu, 28 Mar 2024 09:46:29 +0100 Message-Id: <20240328084629.2955393-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240328084629.2955393-1-hch@lst.de> References: <20240328084629.2955393-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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 390C120003 X-Stat-Signature: mgo7m98mwxdipfnwe1war9e5swk9gupx X-HE-Tag: 1711615603-184259 X-HE-Meta: U2FsdGVkX18kAsdFsrxMS0JIz+KlRV/e0wdECR7xE9cCC4XEUcf11eMAPfj74+LMk4oO+llIuFMtZdnK9smszZrOk6D79PKESE3onHUiVN8QOrZYoFfrIV1Kcw6y7esaBBEsNRzP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zJQItis2OKEtOiL84ePKjSzwd1POWl4g7XX8WW26gQNcNjxW8hOjAlEv553xo+ULaMqMx723auRfr3163Y/TcyOFsmvdtVJGo1J/iUAuNRULFboGFTL+pIgiv/4hniWvHGhCl/HGXeQuxtHCpu3pFzJwhgqceqyjSXlowMHdFxr9NyENK6e2eMDZRZgd6XP0VK5z1l+4jx+sqrAT8Hzisq1LsAAzJXWOfMt97Pjtu5Dqoql0= 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 callers in arch/x86/mm/pat/memtype.c. Move it there and hardcode the two arguments that get the same values passed by both callers. Signed-off-by: Christoph Hellwig Reviewed-by: David Hildenbrand --- arch/x86/mm/pat/memtype.c | 23 +++++++++++++++++++++-- include/linux/mm.h | 2 -- mm/memory.c | 28 ---------------------------- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 0d72183b5dd028..c64f07b0fc2099 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -947,6 +947,25 @@ 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 +985,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 +1072,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 33559720f0aab9..86c9eb92b5e03c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5926,34 +5926,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