From patchwork Thu Jan 11 12:09:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 187354 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1399669dyi; Thu, 11 Jan 2024 04:10:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdrYnQmIZS3gnmg+RYf7HBqUL1BICjXvQjZRe8q5AcOsGnzFB2hGJMg28kPLbCNdnplNY9 X-Received: by 2002:a05:6402:22fa:b0:558:a219:730 with SMTP id dn26-20020a05640222fa00b00558a2190730mr312031edb.65.1704975020049; Thu, 11 Jan 2024 04:10:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704975020; cv=none; d=google.com; s=arc-20160816; b=BlDhsdP+Tm0E+JnB+sJLYWPojSecrfVU4mECnkL0GqZoBNwRWxXdw/rfnaFmBpEo9g qXDGjAMf7g7LKDcK4T4+eN7TDPRzT0LCiDmrsCg+KADc9EYwYY7Nxdp6kD6hsNcYQ4F9 hkKsi3W4mP7niJycCCcK45O+x6HFflrePeVQVrFP8o0qXiSu8lqFN/xU4V8Zp2HsRoSL +IUWrHW//r6fPkrB5nC1oU260g2IcbL/hsZH64/875fzt0WaCuYk1XVNzo21cOEU52VK 3bv5D4aqwp5Vq04H1YUwhcyCJf2CuFhuQXMZvnixY/F9FXIKP5aLxNYiGz+ZDC4w6yya 7ETQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=CTcrWt1JMcfwmP8xdJ71qDD3DYvOhIlDmg4Ust+Qc50=; fh=VDFt/Ez8CwS+3hxzG1nckgKJ9OcfII+UembkYqexFFw=; b=OweLPxK+nrr+4iBUTCAttj0RQ+lvycv/xpV/mY/tIrniLUUDq3FpdbQr+2QdFn4hLG cGqMHTaADqERybvbUFr4UKWXwAlCr0TSd2x+3M8GmA4svNMoLpVyyXg3vyA/AyL03SEe HDux52eZMZimq0bPxU5u5nzhYASYeiHES/0WJwKB+qPcDX1IzBUL3z1v1eJR1CdWdx9j /zYviTfeanHq4Ach3E776ZyKIxuGRyPNxioK06mroQx4U8YD+WhT3J8T3q8KA7d2VfaE tqj5v2GVcqT2eAJ983FGMecwwej79IvY5jt1pBtXxHtRl59WrcziAl+qCE4kSWYH78Ar gRaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23561-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23561-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v13-20020aa7d80d000000b0055817008770si472870edq.514.2024.01.11.04.10.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 04:10:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23561-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23561-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23561-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A5E281F250C6 for ; Thu, 11 Jan 2024 12:10:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C936215E8B; Thu, 11 Jan 2024 12:09:39 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E524415AD1 for ; Thu, 11 Jan 2024 12:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4T9k2S6Bzfz2LXKD; Thu, 11 Jan 2024 20:08:00 +0800 (CST) Received: from dggpemd200001.china.huawei.com (unknown [7.185.36.224]) by mail.maildlp.com (Postfix) with ESMTPS id 8F97B1A0172; Thu, 11 Jan 2024 20:09:33 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemd200001.china.huawei.com (7.185.36.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Thu, 11 Jan 2024 20:09:33 +0800 From: Wupeng Ma To: , , , , CC: , , , , Subject: [PATCH v3 1/3] x86/mm/pat: Move follow_phys to pat-related file Date: Thu, 11 Jan 2024 20:09:27 +0800 Message-ID: <20240111120929.2694440-2-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240111120929.2694440-1-mawupeng1@huawei.com> References: <20240111120929.2694440-1-mawupeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemd200001.china.huawei.com (7.185.36.224) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787795886738035408 X-GMAIL-MSGID: 1787795886738035408 From: Ma Wupeng Since only PAT in x86 use follow_phys(), move this to from memory.c to memtype.c and make it static. Since config HAVE_IOREMAP_PROT is selected by x86, drop this config macro. Signed-off-by: Ma Wupeng --- arch/x86/mm/pat/memtype.c | 28 ++++++++++++++++++++++++++++ include/linux/mm.h | 2 -- mm/memory.c | 28 ---------------------------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index de10800cd4dd..a6a88679c92e 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -950,6 +950,34 @@ 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 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; +} + /* * track_pfn_copy is called when vma that is covering the pfnmap gets * copied through copy_page_range(). diff --git a/include/linux/mm.h b/include/linux/mm.h index da5219b48d52..8c4fa44e0e4b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2364,8 +2364,6 @@ 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, void *buf, int len, int write); diff --git a/mm/memory.c b/mm/memory.c index 6e0712d06cd4..a555f7ebd4ef 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5697,34 +5697,6 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address, EXPORT_SYMBOL(follow_pfn); #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