Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1504803rdb; Mon, 19 Feb 2024 19:48:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWruYfge+dX+S5aTrPlskqRsDXrI10p3AwgIULPPHnSy2no1IYo4uBysqqHxC/ZTevX0lXiCVUFlXFv5tTvVBkhPXgC7Nf2ufPWvHum8Q== X-Google-Smtp-Source: AGHT+IEe8LN9aE2H4NYuEGE01iAAbIgEAZXMS0eCRf7xv5ZAi9ZcBBwJW+NhYU1GGJXqlGAScmmz X-Received: by 2002:a17:90a:1648:b0:299:305e:68fa with SMTP id x8-20020a17090a164800b00299305e68famr9767729pje.8.1708400930865; Mon, 19 Feb 2024 19:48:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708400930; cv=pass; d=google.com; s=arc-20160816; b=IGJpkjLFCYK5E+txlZ7oU96bK1E/vJoiH++T9eJf2Bn2OQjwLC7ATSyZQX9i7TyW4p Oa8QR2LyK1gWU3juitBiDP16kScg/nWlh2QYtJfDY/59zewzSc3VvvMYEIzUWnTAurGC uH0QcidKXWZRvGfnp3yKN9bwvwxJSGn5MVZ57rkZUSfocaNmqsMZTvyEAx9d14burfv4 x6ZAzyA1XFtk8433LF59OIi2ClXISEeEuGepNT8ETC8s1QkI2Lf57fQJdfpVxhy8NJRM yygSFKxgb0mSCj3AJFoOwxubW8Ta7QCHGhvVZudNibEQNtfTLFEbtY/cpleaNmI+OBSo /p8g== ARC-Message-Signature: i=2; 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=fr65SOWCv23X2MiY+qvdBo27LS6DAuaxHnQjCbyPxrg=; fh=zpgpHhi7NFRm0UrQnwLzLdFqTpbxRncqQ6HhcVWeB8c=; b=VlPLgWOwZJqzXiPfrAVdyZOb0J0SZMwr9GoKTg6rPFGfU8mOBnh3zxEVFUJS7jcXBy FdYVHD5TBYjyKILiBhUO7dfPFSrVSOdtWPJFDiVMbqp1hAY0yS0NxfYuRx0KYINrbuYc oNyaplpt/IUTFbMe5j/OEqjX1BD1YV2RMc0XrButqhOqFjLosmFGMs2TzTf7cZHzX0f6 LXAxYn2jYcBcRy4Zv/QlDtI3dUgsnLZhxwdWLQgdnVvLpGb4Ys1//5rr3lvmAjDWFCK/ pIT/xZ1K1Vys1g887cjxj0OZyHSQQA1d9HxUy+iX2IuFACWXzG+xAPvFO8AOZ0HHD/W8 Bqpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-72285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72285-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v5-20020a17090a898500b002995d9514dasi4817677pjn.119.2024.02.19.19.48.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:48:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-72285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72285-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 38F062820BD for ; Tue, 20 Feb 2024 03:48:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D19D51C3B; Tue, 20 Feb 2024 03:48:46 +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 D53891C2E for ; Tue, 20 Feb 2024 03:48:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708400925; cv=none; b=SeUpQSKFPRTRwOZyUI2+uLhOB/vUGReNzEIg+fgrdpiUiQJ5vsqxhNnGIZ1onh3GWuXfFUIBf7X8oVRSLaGnvP0lbIP6E4PRlmtwcnRM1hgCXprlj4FT+1YC7IlSVriLHLyrKIFoFPsdw3nX6Ob5vJlz9FR1hKVbbMVRteDRdio= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708400925; c=relaxed/simple; bh=HZH4hKQzxLHFZ1M195Fil/k9uUanGNnlf5EBFb/dF+8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LnVTWssaRwKSYk6yQ5IeKLTPrBZogdlgTjvgi4Je5V8s6w8OUqczj/swJCC4ft8E4eNZqJhJluSPru2RgS15V4xKiwYne9sM3D80SpE91Bm0HTui2MT2RhvjDjNuLN6TI9dQGmcVCln3OmWdr9NJ5VGNAEjSdWTCrCxkMO0eHQA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 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.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Tf4yF70nMz1FKnT; Tue, 20 Feb 2024 11:43:49 +0800 (CST) Received: from dggpemd200001.china.huawei.com (unknown [7.185.36.224]) by mail.maildlp.com (Postfix) with ESMTPS id 50EA11402DE; Tue, 20 Feb 2024 11:48:40 +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; Tue, 20 Feb 2024 11:48:39 +0800 From: Wupeng Ma To: , , , , , CC: , , , , , , , Subject: [PATCH v4 1/3] x86/mm/pat: Move follow_phys to pat-related file Date: Tue, 20 Feb 2024 11:48:33 +0800 Message-ID: <20240220034835.507022-2-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220034835.507022-1-mawupeng1@huawei.com> References: <20240220034835.507022-1-mawupeng1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemd200001.china.huawei.com (7.185.36.224) 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 0904d7e8e126..d8c37aaaf041 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 f5a97dec5169..75c683f2f5ae 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2375,8 +2375,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 15f8b10ea17c..86ad7f1ca3af 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5802,34 +5802,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 -- 2.25.1