From patchwork Fri Aug 9 16:09:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13758938 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 7AA27C3DA4A for ; Fri, 9 Aug 2024 16:09:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 682496B008C; Fri, 9 Aug 2024 12:09:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E3956B00AF; Fri, 9 Aug 2024 12:09:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EAF06B00B0; Fri, 9 Aug 2024 12:09:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1C8FF6B008C for ; Fri, 9 Aug 2024 12:09:50 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BA37314113B for ; Fri, 9 Aug 2024 16:09:49 +0000 (UTC) X-FDA: 82433192898.19.2E6484D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 7D5BA140016 for ; Fri, 9 Aug 2024 16:09:47 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=O60UKNzU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723219777; a=rsa-sha256; cv=none; b=GDEXrfyLRFZ/3tWUo9nmvHtju+p0P0l7bCDJJIaJYsO2wIEh0eUFIs0nBj1q0rS5g+g7l5 tD9tAzBXmSNwjPj9MypYlLFryMrZo6cniYebDOfFasOatlU3j/R5h9wXzNgNIFjnx+d4AG gYuKg9vObKVmhCql7UjMbCUuB7f4T/E= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=O60UKNzU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723219777; 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=HLBqit68L/U2mdwYaFkydFK3txHa+LkmL8n2YTQXnnw=; b=bR4+gyt468CIVyp9BL8/u+SwJUWJLW0IQBcloPyRyNG4jAPDDPd1x7b+1CFqoD5d83i6QG EFFSYoHDe5ZbjJp3s6tYZjU5J6zWsr3tcKWk+mEnH4K0rkAJ4KbmRqArzO2ZgeM9rw8zNb oLGY26OIgN7qvJDugF8sIMofMkArRDY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723219786; 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=HLBqit68L/U2mdwYaFkydFK3txHa+LkmL8n2YTQXnnw=; b=O60UKNzUmBZ03y1iKh7v9QxiN8SPmfZ0APY24e/9nMjRxsiRiG8IaSFEGOJSr7eHCpwpKe 2+89+RpXi55Tpi4vxaixMF0e2gZKGkBrpYo5egTMQnSxUP3ezoIksxcBFqHn7DDNKlHmtY JzGuS0ZKWptjDxYdw4/mAM41C0mohzM= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-557-USvTRhHsP5GrU_EuTZT-8w-1; Fri, 09 Aug 2024 12:09:45 -0400 X-MC-Unique: USvTRhHsP5GrU_EuTZT-8w-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-45009e27b83so4905811cf.1 for ; Fri, 09 Aug 2024 09:09:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723219785; x=1723824585; 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=HLBqit68L/U2mdwYaFkydFK3txHa+LkmL8n2YTQXnnw=; b=Z05lWvR4Ge1G2+XgT19/nawSYL6BCn86Ofi2lSTETeBYuzTmzd6gDO5LzpugCvJoZM PZn8Jm9yVfAlx4TmNmd3FC2Bu2iBBQ5R+dvmd/F9tQ6qZrpqYcDwF4BrNBA9Z39VelRj jUYMx0BAgY5EvmwiSirhI7DR2Fnqrt6UqcVrFAlaWmVz+zTF4qgt/+a8AcAUW1PLR62x 5LLg+VqgVjkFUbvGJD9j9fSUhE51NXIb9WlLKLwCgdd5PfIs+sVJOOj4e21RcWFdctF1 0Z2VhxayhVbh8nJrd1MkV/2LFLOqAULifLP2ma+K2so9vyx1yTpT2jyxatscnmIuAaBd n3Tg== X-Gm-Message-State: AOJu0Yx7dN50o2Y6Nn7iYwzDrCp4JshRux+iS2XWh6KkoWRJfywJqHeo 8QgjHkRlNAGm4H5VMwkX+ZOuHSwVxOm0W8n277p+Ap6HIhSAx4Mpu2PB02G+ReebPYlTAYsOV7B Vg9iJwYYYaewf3yiS5D5IaT42fV0d7LJRFCF97rAM23QTeRzMsBA1mX9Iy4gEne6qgeTqVN6CE5 NCngCauN5mLJHsqEOis+IGzScf+CmfQEHY X-Received: by 2002:ac8:5f10:0:b0:450:349:1170 with SMTP id d75a77b69052e-4531255c62dmr14745591cf.6.1723219784710; Fri, 09 Aug 2024 09:09:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFbC3kPrc0fRPufwvcIMbfwNKbDcEyDmf8f6qiGpsAJzwvtAb4AIbgx0osGWWLWwEBOAE+Pw== X-Received: by 2002:ac8:5f10:0:b0:450:349:1170 with SMTP id d75a77b69052e-4531255c62dmr14745171cf.6.1723219784295; Fri, 09 Aug 2024 09:09:44 -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 d75a77b69052e-451c870016csm22526741cf.19.2024.08.09.09.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 09:09:43 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Sean Christopherson , Oscar Salvador , Jason Gunthorpe , Axel Rasmussen , linux-arm-kernel@lists.infradead.org, x86@kernel.org, peterx@redhat.com, Will Deacon , Gavin Shan , Paolo Bonzini , Zi Yan , Andrew Morton , Catalin Marinas , Ingo Molnar , Alistair Popple , Borislav Petkov , David Hildenbrand , Thomas Gleixner , kvm@vger.kernel.org, Dave Hansen , Alex Williamson , Yan Zhao Subject: [PATCH 13/19] vfio: Use the new follow_pfnmap API Date: Fri, 9 Aug 2024 12:09:03 -0400 Message-ID: <20240809160909.1023470-14-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240809160909.1023470-1-peterx@redhat.com> References: <20240809160909.1023470-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Queue-Id: 7D5BA140016 X-Rspamd-Server: rspam01 X-Stat-Signature: fruc3t48geg96drthbeticu8smn9dqxr X-HE-Tag: 1723219787-579020 X-HE-Meta: U2FsdGVkX180YjtvONE/l0bPVFvx7hiw7VbI29tqu41exYLNiG5JM6HLb9bb9IrIYouoiEulZzu9S24fJUUB6dMe+axrngSa2gTnDrc03hcTgPBiqPnVkHcYA8voeNL0xd0XLuY8iSOUAG7dwyOcVuVFrV6oyy61qHo/ZwYvPbU3WX2MqC8cFROUugG8HEBpXSxQHJP4r811m3N+QNkcPXVr64FG1PysjqRq+AdD9GyZrLK1yjXaMOROJS5YWpNS+SCpZyzpYV2slZOpUrOhfx4LWGoYwk5T0w2Cyf+zjcQZaFXEkLdTQCUewUgqHc3BQ3VrRX0c9BlcJCNZ/QNpq2wjuurFcY72BvpwMfutux1c1wP+t2Yo2L2ftsFdt7K4u2AgnIIBbmc0Pbiac4UfDQf2iHqYureliSfNihsK6fSj/0zPpjdJAha7224vdMCs+4wNeMvuSk7LAk9yiQeZlGgzPoH1Igov9n41TWb7RoiTG4QnfehKclKKmMQaC8K7VG1Ldd21DXTOgaMpp2P/XEuzoEWm9W138elaA8YNiovs8NEiUiKvoeimSTaYBfV8h565q6WCbM1Nc5VXulquDcvzI83N99MsdNsqnNM0TK361/DMxQlD/Zo7niefiKU3wqbBBKtlW10QiHXFLgC5SBj52x6vpW+m43N1C8QKjfvitIc85SE9/p+jad+DGWIwqbzlYEZ6DHbDgYSYRURep0f6nBEnoW0Swp22rYJFZsfVsgZQ4EVez1r/dBTIgsmbjCEFPmj7cVx0jwbTyk6q8n2KgzbjXRD0EFfy1VXskKQfvtH66Lh3n1I7cgfQmmokFXXmnH/vEO1UedwGbI/5ZKLk+yHFXj6jKLGBSWyLW65dPfPFn5Y6xpq1MKK4676w3OAR0R31ldAONWksLStjwJA7SA6DF9lOHht85iMWmYidhAbIFbFIDUnOR9t+ouJbPs4xcFpxnXDgStnKrN8 eX5TYnsa O821mXSroI+2h1OIhwpUr5EdRPX7+HyP4LnP0B8KhzQCkR65tSTrk3TWvwebVNioK6+r5dsLO8YBjLe3vo8U8lg119OSEp3t2UWJ1AQc1UDkWJHphwquFOzQiJe8ks99D1rf5/VbZkBexmDhJTls3OzM5EiBXP+vTaZbdg2wgU3FNm4uVA6yKW+sJLMmeZKJ5UHAxiWbFe8ePPrKc3rVDBaCXE4KwzHQuWomj4UqKuMsW113aBRlxv21zRTDFXYXTqcNZDbPXiHyFfJLHr22EhutA7HsUjzcotMQ7CUFY4DPpGKKV/tSgBta8zJfBO0A1IX5BcwZhxgPY5t7aP3NuYFj5I9L7u7gYAVaeW5/Qkruuh6Pu7b4wQtgCNkJ6vpzxoCEAL+Zsk4a7wlSIqORJppBwbj75XdBnI/FTUUsxE4WjmyoyH57AbzKixC5nUwnKLymxRwf7aw29ach9EsnK/ZNegIXFq3UZ2jWno/23Hpz51zVGJKYbvYW+vRbLyY+vj082h0nNChFV0AhqxHmE1QAggA== 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: Use the new API that can understand huge pfn mappings. Cc: Alex Williamson Cc: Jason Gunthorpe Signed-off-by: Peter Xu --- drivers/vfio/vfio_iommu_type1.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 0960699e7554..bf391b40e576 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -513,12 +513,10 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm, unsigned long vaddr, unsigned long *pfn, bool write_fault) { - pte_t *ptep; - pte_t pte; - spinlock_t *ptl; + struct follow_pfnmap_args args = { .vma = vma, .address = vaddr }; int ret; - ret = follow_pte(vma, vaddr, &ptep, &ptl); + ret = follow_pfnmap_start(&args); if (ret) { bool unlocked = false; @@ -532,19 +530,17 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm, if (ret) return ret; - ret = follow_pte(vma, vaddr, &ptep, &ptl); + ret = follow_pfnmap_start(&args); if (ret) return ret; } - pte = ptep_get(ptep); - - if (write_fault && !pte_write(pte)) + if (write_fault && !args.writable) ret = -EFAULT; else - *pfn = pte_pfn(pte); + *pfn = args.pfn; - pte_unmap_unlock(ptep, ptl); + follow_pfnmap_end(&args); return ret; }