From patchwork Mon Aug 26 20:43:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13778452 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5B2DFC5321D for ; Mon, 26 Aug 2024 20:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=t75nynj+5ccZ6qy3UooqAYOOLyCQeJyCwmKKtTf1Ss4=; b=U5JGa2D8WBaVXr2jnQ+LQz5IMb RCjFgPfOt+hzYvQhYzvw/tId8vdiXo/dUav5UXlI5wCqVhRYREwfCyjFF4wXTbng+DZkmScuzFQ2R McbljlkLsMR4b+7eKh2MLyoGUwo8aiwgdvhi8IhMqwaizvrr1cNudHuTixKEhevjolmNXa+VbRIsv VtSzgGN3LmG3sNAVuTZof6aEdXg3YuFOkXufLUpJtAeho1AV/ceZj2HjiaB3POcbuo4w8pGJVvWMl GDQLC+uI9BzAV3hWgLPVhNRmJMrEiOG0tjpeVCDPQLnrKd1FAq4/jrHKexwiDoahtmfx72JoCuu4x 8wx0B5Yw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1siglm-00000008iHt-481R; Mon, 26 Aug 2024 20:56:58 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sigZh-00000008ebO-1jWO for linux-arm-kernel@lists.infradead.org; Mon, 26 Aug 2024 20:44:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724705068; 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=t75nynj+5ccZ6qy3UooqAYOOLyCQeJyCwmKKtTf1Ss4=; b=OewNm48nnEsXZ4g7ozbw/jYqwhX4mt6Y1hsL0mgpqyH6uTCnw2csiExh1uqsIAGtmZ2ORi q6yIMQDyO3onAN7MYTSsFszZfl/15J7Ksbhpyrxb/csEbZpaXX9icONu/RLJt78+tsNruR Q+dfJh3xwxLClRnVm9k00S+MxiD0aTg= Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-52-FVIMtCrjN-KYpjbvIJ4QLg-1; Mon, 26 Aug 2024 16:44:27 -0400 X-MC-Unique: FVIMtCrjN-KYpjbvIJ4QLg-1 Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-2700946649eso6410941fac.0 for ; Mon, 26 Aug 2024 13:44:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724705066; x=1725309866; 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=t75nynj+5ccZ6qy3UooqAYOOLyCQeJyCwmKKtTf1Ss4=; b=PlNWShSLHIg7CXcYI8+c3CT3hWKn8JPaXzd3bcMBbACHG2BT9SPPKOit/aNo56hK1a jo2OhTHJJLp0X2kq3z2mLpmRMGhhvzyFiEYj83ggaBrVaPmZj7He9nToOVz1dsk3A0/F /9ibqwC8b7tQ9DqK8tgNLIqfuBl2uJb6pm1AcJ2a6wsX2p9asSDUUtFOOmQKcFRsgfg4 3kgy7QMUGWWxI0vZXx9hP2xIfTKkfWhv2iKxKTYM8uLDYKHuhJ8WB26pGjPwpuGQ2S1W ZKunCRsn7sjibkZqnVTDuNPeeaXHv+nfDROmsTRhekQgdtNN20x4dYrKNi5HIJ3sHUXw 0qJg== X-Forwarded-Encrypted: i=1; AJvYcCX6ATV8SXGr4qa2nEf+FJ9uWBvmvgJ7lmAfq9EmDDeaQDTKHJtz3mn7NPXnq48J5T56kFcvkqVWkPrQB3dbkvRp@lists.infradead.org X-Gm-Message-State: AOJu0YwvikHwaTS3jUtnO6MWYR5Hxmv55Q4pLbckxNvOUTSBBAtGTXm/ VE4/gAgmcqrMlw7x9NlqTL8vLMge/ML5dL5WeOHPnKPgyscEIhApve5KK4WQu7AyVFL9E/+Nzox 07Uj2zieBBHeM6a5MvYSTHXC1iV5Bx8gdlDzbnYHZjTp2zihTHS1FTbOB2GEFc27WZ9ard/L9 X-Received: by 2002:a05:6358:3a07:b0:1ad:10ff:341e with SMTP id e5c5f4694b2df-1b5c3a3b69dmr1457842955d.4.1724705066538; Mon, 26 Aug 2024 13:44:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoPajws+HFHWojCbb3D8qBEyBE/zIeN3nkxAxD5pVBn23+qUQ20h6jqSHyvqmBY4DTTGYw+g== X-Received: by 2002:a05:6358:3a07:b0:1ad:10ff:341e with SMTP id e5c5f4694b2df-1b5c3a3b69dmr1457841255d.4.1724705066240; Mon, 26 Aug 2024 13:44:26 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 13:44:25 -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 15/19] mm/access_process_vm: Use the new follow_pfnmap API Date: Mon, 26 Aug 2024 16:43:49 -0400 Message-ID: <20240826204353.2228736-16-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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240826_134429_555428_E41CE6DE X-CRM114-Status: GOOD ( 13.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use the new API that can understand huge pfn mappings. Signed-off-by: Peter Xu --- mm/memory.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 0b136c398257..b5d07f493d5d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6342,34 +6342,34 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, resource_size_t phys_addr; unsigned long prot = 0; void __iomem *maddr; - pte_t *ptep, pte; - spinlock_t *ptl; int offset = offset_in_page(addr); int ret = -EINVAL; + bool writable; + struct follow_pfnmap_args args = { .vma = vma, .address = addr }; retry: - if (follow_pte(vma, addr, &ptep, &ptl)) + if (follow_pfnmap_start(&args)) return -EINVAL; - pte = ptep_get(ptep); - pte_unmap_unlock(ptep, ptl); + prot = pgprot_val(args.pgprot); + phys_addr = (resource_size_t)args.pfn << PAGE_SHIFT; + writable = args.writable; + follow_pfnmap_end(&args); - prot = pgprot_val(pte_pgprot(pte)); - phys_addr = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT; - - if ((write & FOLL_WRITE) && !pte_write(pte)) + if ((write & FOLL_WRITE) && !writable) return -EINVAL; maddr = ioremap_prot(phys_addr, PAGE_ALIGN(len + offset), prot); if (!maddr) return -ENOMEM; - if (follow_pte(vma, addr, &ptep, &ptl)) + if (follow_pfnmap_start(&args)) goto out_unmap; - if (!pte_same(pte, ptep_get(ptep))) { - pte_unmap_unlock(ptep, ptl); + if ((prot != pgprot_val(args.pgprot)) || + (phys_addr != (args.pfn << PAGE_SHIFT)) || + (writable != args.writable)) { + follow_pfnmap_end(&args); iounmap(maddr); - goto retry; } @@ -6378,7 +6378,7 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, else memcpy_fromio(buf, maddr + offset, len); ret = len; - pte_unmap_unlock(ptep, ptl); + follow_pfnmap_end(&args); out_unmap: iounmap(maddr);