From patchwork Wed Apr 3 21:21:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13616710 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 19450CD128A for ; Wed, 3 Apr 2024 21:21:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 858406B008A; Wed, 3 Apr 2024 17:21:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 807D06B0092; Wed, 3 Apr 2024 17:21:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CECE6B0093; Wed, 3 Apr 2024 17:21:50 -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 4F7586B008A for ; Wed, 3 Apr 2024 17:21:50 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 04816A127D for ; Wed, 3 Apr 2024 21:21:49 +0000 (UTC) X-FDA: 81969492780.08.9C402A3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 42F3D180016 for ; Wed, 3 Apr 2024 21:21:48 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M2boKSrG; spf=pass (imf06.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712179308; 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=g0bue21sVFDV6mnO+mYp+9W9/z08Eqmsuy0DOkkfVG0=; b=i80Wp/LOe1H1xPR2cSX7bCCKcIrTcL/3YqKkBZRrNgTLMf3NY4bEUveH6gWkm80uYmKzAn E2txprMwHVoxm/lnBctfmpBMyBhX8ELgK+CXepotNBUXIB0MzqacJzBe2Bb9m7RRTgwTwl NqkxXdEQ3ctpdL2Ccnl/mujh8byTDLw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712179308; a=rsa-sha256; cv=none; b=pvsu7a6vmf5vICrrMKgzKQPmCPlB0SPC5M4+GDY8D3sa+v3UWa6aBdYT3tl00/5AfLqqBu uJ34mpFyRsJYoZgf49GiSDEfNmTqrlzMLYC6rqzi7PmId1M8iUi2VyfHaZ7a/qO9BB4s47 vrbI9GowhRVa1acHGWzAFxCo1mnj3oU= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M2boKSrG; spf=pass (imf06.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712179307; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g0bue21sVFDV6mnO+mYp+9W9/z08Eqmsuy0DOkkfVG0=; b=M2boKSrGhLlTZIJJK7zriww7hfT5UAHbgLLrzsafpCbAvwva+YUFjrsCfWRaNcfvE4f6b5 p/BYIlorGY8ci+Ltrg5xMbjqP6oh6D1Eom4irBosu3f362NxyyWoUyav6MIdOKwrWfzKZ8 /81QXoZe8CN2Lruw0lmYTWHVhdY1pFk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-504-YCtSuczBNGSVezlxIXJuOQ-1; Wed, 03 Apr 2024 17:21:45 -0400 X-MC-Unique: YCtSuczBNGSVezlxIXJuOQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 542C33C13920; Wed, 3 Apr 2024 21:21:44 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0C1D1121306; Wed, 3 Apr 2024 21:21:40 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, x86@kernel.org, David Hildenbrand , Andrew Morton , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Christoph Hellwig , Borislav Petkov , "H. Peter Anvin" , Andy Lutomirski , Dave Hansen , Fei Li , Nathan Chancellor Subject: [PATCH v2 1/3] [mm-unstable] Revert "mm: move follow_phys to arch/x86/mm/pat/memtype.c" Date: Wed, 3 Apr 2024 23:21:29 +0200 Message-ID: <20240403212131.929421-2-david@redhat.com> In-Reply-To: <20240403212131.929421-1-david@redhat.com> References: <20240403212131.929421-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Rspamd-Queue-Id: 42F3D180016 X-Rspam-User: X-Stat-Signature: csxbhktwikhkfaa5n1icefbioeyied5h X-Rspamd-Server: rspam03 X-HE-Tag: 1712179308-911680 X-HE-Meta: U2FsdGVkX18sn0pF/s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CkecTMLA3+qkhpgFPKwrl4SR0eJuK0LdHVH1WPsO49pG0Rjiyup/AKd1iOHsSYNFuArwJv8D+AmA6zu7qjBhT1WabAlVc59ZDoX/ThnVWpv4ZBTRXKIGYL 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: Revert mm-unstable patches: * mm-move-follow_phys-to-arch-x86-mm-pat-memtypec-fix-2 * mm-move-follow_phys-to-arch-x86-mm-pat-memtypec-fix * mm: move follow_phys to arch/x86/mm/pat/memtype.c Signed-off-by: David Hildenbrand --- arch/x86/mm/pat/memtype.c | 24 ++---------------------- include/linux/mm.h | 2 ++ mm/memory.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 143d1e3d3fd2..0d72183b5dd0 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -39,7 +39,6 @@ #include #include #include -#include #include #include @@ -948,25 +947,6 @@ 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(). @@ -986,7 +966,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, &prot, &paddr)) { + if (follow_phys(vma, vma->vm_start, 0, &prot, &paddr)) { WARN_ON_ONCE(1); return -EINVAL; } @@ -1073,7 +1053,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, &prot, &paddr)) { + if (follow_phys(vma, vma->vm_start, 0, &prot, &paddr)) { WARN_ON_ONCE(1); return; } diff --git a/include/linux/mm.h b/include/linux/mm.h index bc0cd34a8042..97e779993c74 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2424,6 +2424,8 @@ 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 912cd738ec03..1211e2090c1a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5987,6 +5987,34 @@ 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