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+CJ604t14nlUaEF1omNX8jk9P6OqoSwhAlafub5ntlKotXsyyPSxfSLJmOom1C5BxrOhUfRHqBN3ISozYbLIgY2brzaCQGeg9cmCHGI6twHyUL82PEFVq4rFmv1LZ18krdLtT2tVgaGvNKNmNf9BsuCGkeAIj58NwS8bwzpOLu6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U3j+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