From patchwork Mon Aug 26 20:43:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13778410 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 117FCC5472C for ; Mon, 26 Aug 2024 20:44:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 747EB6B00A9; Mon, 26 Aug 2024 16:44:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A9896B00AA; Mon, 26 Aug 2024 16:44:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D5F96B00AB; Mon, 26 Aug 2024 16:44:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 28DAE6B00A9 for ; Mon, 26 Aug 2024 16:44:33 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CD93314121F for ; Mon, 26 Aug 2024 20:44:32 +0000 (UTC) X-FDA: 82495574784.28.07E7E7C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id B75DF180020 for ; Mon, 26 Aug 2024 20:44:30 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y8SkvWu2; spf=pass (imf16.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1724705002; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=X8WHCJ7kNzF2XCQH70BbHdio2suKNHxAf6rhsHMkPbs=; b=Ylsb6x4zUJmBHXVNlH6hQvHjfgFGPwddJzKn9nvoZu/6qYnV8XCOdpzvMYEPAuHXqK1Rpr hLqoq/Rwvu2W9HN8t7hOTuBGaYL+NIIyb2RCcUCyQlOdZyY5AnICRFOTiXICqjNIF+nP7a j3KN7ndgN50nDYG6276ZgpoZqeeejCk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y8SkvWu2; spf=pass (imf16.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724705002; a=rsa-sha256; cv=none; b=5ux2P2TofTNIDctrI8qoWxcQRg0RtbmZVVu6S7oupT5xZTdq4bDEgy2oEYWc5LtBLWE2ZF ePbPmyV0IEYvnIzWGJO3FCfrwvkbrb6RSfUnnGwaGELfQrESjTf3KY9RqJ88SdulLzVbiP sg3mejfC+YRgeO8JMXCfJ08AHWa0wbA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724705070; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X8WHCJ7kNzF2XCQH70BbHdio2suKNHxAf6rhsHMkPbs=; b=Y8SkvWu2LOubSTzyFjhJG+uaffHluqMJERUI1Eu1Uw/9ljdkiwXGV1hGP183x9gafw8i3I j7tSUSw3ajrzFTK6pgtF3iqMCJsMlviAcKYcA7qksr2PXh+k1frHWfPTuz/PccEMarvGs6 4RIvB1FJ+sHyXnt2nwT3G80QRCHjWwI= Received: from mail-ua1-f72.google.com (mail-ua1-f72.google.com [209.85.222.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-718lCt5dM7a8WjbAifUNaw-1; Mon, 26 Aug 2024 16:44:29 -0400 X-MC-Unique: 718lCt5dM7a8WjbAifUNaw-1 Received: by mail-ua1-f72.google.com with SMTP id a1e0cc1a2514c-842f7fc5cb5so1351924241.0 for ; Mon, 26 Aug 2024 13:44:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724705068; x=1725309868; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X8WHCJ7kNzF2XCQH70BbHdio2suKNHxAf6rhsHMkPbs=; b=npQtJeBPQGiFox2cRFW2wVg5UylMVgfgeExKidRcKQyl8IXV0I6I8enuffQKMhAJWM SUMlgsHkUDft1Fj8YaKuBnXv4cac8TYFkmuJrco3EmFFuZyb5hbI9Yyyy88eIKysHJJD orJeuFJSVs2c45O70sG81Kciig4nm7vb5wP3b/7OGpsNoQ09eX/T43INzw25cjpL+SdO BQ0Pyz8zXsHUP+CVgT0CCseYzDFIZDGx/CEx8VJM+z1nH0wuRHyqs2TZkqdKnzzFU0WG K3lcWN6SWcwiGZQ0x+5G3RG/XT9kc4MWY80MtoupHHzQngbQpzo8FVFGrfNYDw7rch9y NoNA== X-Forwarded-Encrypted: i=1; AJvYcCV/L/LJWJ8h28WdtqIShs5dzHyNVpUUcID/9wi+IqKvzKc9XQm2mLOYHNEHzLBTFT2fbmaoCOEgmQ==@kvack.org X-Gm-Message-State: AOJu0YxSxz2HkoWPpoq34U6y56x819cAXG6O1A2Mt6KpasWtCHFGld36 t7AM/pU2Mt/jaShhrZ4B+B3Ho2enNL2YpoJXviZZRhb6IhVWGXiVhUTJwYy9kjHbyiEAfAn2FJA yxNCE08dQ8WQesO8o/VpwnwZBbbL+ALKFHdP9YWftiJe89miO X-Received: by 2002:a05:6102:3e94:b0:493:e585:6ce3 with SMTP id ada2fe7eead31-49a3bd1cd83mr1005184137.31.1724705068473; Mon, 26 Aug 2024 13:44:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGKOe4NKlkU/HSIr+h3CCvXyG5C70MeRvYsCyQPr65oWdFZ+m1iMwzpLlsyBV/cJVa8qCplQQ== X-Received: by 2002:a05:6102:3e94:b0:493:e585:6ce3 with SMTP id ada2fe7eead31-49a3bd1cd83mr1005176137.31.1724705068153; Mon, 26 Aug 2024 13:44:28 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a67f3fd6c1sm491055185a.121.2024.08.26.13.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 13:44:27 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Gavin Shan , Catalin Marinas , x86@kernel.org, Ingo Molnar , Andrew Morton , Paolo Bonzini , Dave Hansen , Thomas Gleixner , Alistair Popple , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sean Christopherson , peterx@redhat.com, Oscar Salvador , Jason Gunthorpe , Borislav Petkov , Zi Yan , Axel Rasmussen , David Hildenbrand , Yan Zhao , Will Deacon , Kefeng Wang , Alex Williamson Subject: [PATCH v2 16/19] mm: Remove follow_pte() Date: Mon, 26 Aug 2024 16:43:50 -0400 Message-ID: <20240826204353.2228736-17-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826204353.2228736-1-peterx@redhat.com> References: <20240826204353.2228736-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: fobd1n9dtxaufj6nkoxgz3u85m1babtk X-Rspam-User: X-Rspamd-Queue-Id: B75DF180020 X-Rspamd-Server: rspam02 X-HE-Tag: 1724705070-662681 X-HE-Meta: U2FsdGVkX194q9wsiAup6hYZtb3cCwVpJD6JNTly1zFe07gY0Uju9k3ck7+aCZQCvzlhYm2bvnymEEtLFzHPj0MjblQ/rMPx/R1IRzZbdrJq70VYcd3oDH2GEEQ6yxwm6yqrTbpcVvSfCjsah/w5uIeia6gW0IMEO5cz+nH9+CnAp3+zmf7lNVU3Q10/obcBWKcbRmuUBgataf+1RpW1ArwGMhj8PWaTt0Ek69SUbmCzy8h/mvLfg//6keTEgk0zpyVmY5f3DnvQbQB2MOSP3vFAOloytygGxWBHNDbxrXYTbw8Cwjsa4+r6sLshJzBAEZ4BAtTXmjZrIJV1yQZ8fZq8GxoBDO5sXK5auuoO7v4xQ7m3yg6U9qz99z+P+DZobQ7LfBw1KoRYBus66xz6zWzaQTpKla7IJhOu+yQ9QUjhi05Da3LSKo01Xa6wUIhDScUni/LJD82IDmXHtnoKWRdygLeD+uwQXYGLJ2AYJD1yM4RcH7P7uwef81413phZJ0ovRa0+lBq2xc08git95RqSG0NnFRJO9SU/1zf+nrIpE1U1Yf7VOlSbPqalVeO72MPjwur4jE2clJqakmqe/KYKQDDIBaovS8YvL+hwbARW4Mm1Gv9bvGtItZW4OgX4Z+O9au/QC2VzQU1rT5kMSW64N8ADoq3yIOBvU5MJL7+pR946PKr/uTwGD6eIAUi9LvO0a4rjLgN2B+90zmK2J/XlNO8P14zbrbaSNkMZkdAR8qW8b14m8vpmyufy6FpdBZ4QJIqmWT7PbOjTD8fPjdulEaDef65+2RG60mLTamHaV8uBeR0GeT+14R9F2TgJm+cv/BwgZXBjAWE5HT4umS2p70WnH7iaDwavdJ4r6f1ttpZ6xuCWuB2xfOBF6RWG3i+aBlhYQCEiJLFLHLUpZoJUD4WuHXnCgaRP6DiBRkAYOjLG7NAAPVhE7OwohbDNzYpDi2LMI6CmbhnznmY s5MaQIhN 0EyIMm6QxbV7yyEjDklpp3FF8tzWJuA1f6RUa5tFi+liWx3lXCkPzF+Q7pySacvYYo9nsqpPPyj5orBDmKMajrU+J31UjTaZnpkPlcjII/0MGDN4/ep0vlFZmU+NL9VbrLxDsgFpaGM+UfB8+ier/vXCxkrKjZbWhcdoaNG7CiC2Ai9X9apx2GxUv4cmX4fjjWN/tKXyIc5ySA7Qzqp3RUSKhCPsDvSTM3E1PncIsNfa7f+cMsLMIuzA9BjAXGu7m9kNL+COatwZYs/lkNajFEkBTNurvv+THckK3GQOZdNL09TrziIhtHte7jZI9kCZTyJCbioQVD3qoJ8AJPD+j9Y82Dg== 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_pte() users have been converted to follow_pfnmap*(). Remove the API. Signed-off-by: Peter Xu --- include/linux/mm.h | 2 -- mm/memory.c | 73 ---------------------------------------------- 2 files changed, 75 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 161d496bfd18..b31d4bdd65ad 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2368,8 +2368,6 @@ void free_pgd_range(struct mmu_gather *tlb, unsigned long addr, unsigned long end, unsigned long floor, unsigned long ceiling); int copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma); -int follow_pte(struct vm_area_struct *vma, unsigned long address, - pte_t **ptepp, spinlock_t **ptlp); 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 b5d07f493d5d..288f81a8698e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6100,79 +6100,6 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address) } #endif /* __PAGETABLE_PMD_FOLDED */ -/** - * follow_pte - look up PTE at a user virtual address - * @vma: the memory mapping - * @address: user virtual address - * @ptepp: location to store found PTE - * @ptlp: location to store the lock for the PTE - * - * On a successful return, the pointer to the PTE is stored in @ptepp; - * the corresponding lock is taken and its location is stored in @ptlp. - * - * The contents of the PTE are only stable until @ptlp is released using - * pte_unmap_unlock(). This function will fail if the PTE is non-present. - * Present PTEs may include PTEs that map refcounted pages, such as - * anonymous folios in COW mappings. - * - * Callers must be careful when relying on PTE content after - * pte_unmap_unlock(). Especially if the PTE maps a refcounted page, - * callers must protect against invalidation with MMU notifiers; otherwise - * access to the PFN at a later point in time can trigger use-after-free. - * - * Only IO mappings and raw PFN mappings are allowed. The mmap semaphore - * should be taken for read. - * - * This function must not be used to modify PTE content. - * - * Return: zero on success, -ve otherwise. - */ -int follow_pte(struct vm_area_struct *vma, unsigned long address, - pte_t **ptepp, spinlock_t **ptlp) -{ - struct mm_struct *mm = vma->vm_mm; - pgd_t *pgd; - p4d_t *p4d; - pud_t *pud; - pmd_t *pmd; - pte_t *ptep; - - mmap_assert_locked(mm); - if (unlikely(address < vma->vm_start || address >= vma->vm_end)) - goto out; - - if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) - goto out; - - pgd = pgd_offset(mm, address); - if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd))) - goto out; - - p4d = p4d_offset(pgd, address); - if (p4d_none(*p4d) || unlikely(p4d_bad(*p4d))) - goto out; - - pud = pud_offset(p4d, address); - if (pud_none(*pud) || unlikely(pud_bad(*pud))) - goto out; - - pmd = pmd_offset(pud, address); - VM_BUG_ON(pmd_trans_huge(*pmd)); - - ptep = pte_offset_map_lock(mm, pmd, address, ptlp); - if (!ptep) - goto out; - if (!pte_present(ptep_get(ptep))) - goto unlock; - *ptepp = ptep; - return 0; -unlock: - pte_unmap_unlock(ptep, *ptlp); -out: - return -EINVAL; -} -EXPORT_SYMBOL_GPL(follow_pte); - static inline void pfnmap_args_setup(struct follow_pfnmap_args *args, spinlock_t *lock, pte_t *ptep, pgprot_t pgprot, unsigned long pfn_base,