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+llIuFMtZdnK9smszZrOk6D79PKESE3onHUiVN8QOrZYoFfrIV1Kcw6y7esaBBEs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xCv92zJQItis2OKEtOiL84ePKjSzwd1POWl4g7XX8WW26gQNcNjxW8hOjAlEv553xo+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