From mboxrd@z Thu Jan 1 00:00:00 1970 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 1B600C531DC for ; Wed, 14 Aug 2024 17:15:59 +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-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=eCQFSIeDwOTQt5HDmaLH+zjBp75O10MjJ4dyFVJRUrI=; b=4QlE+tFerrbXBGIzbHCGtZS3Qq FhKH9wz+3q/maX/qqDpyq+5D8CURgu9SMtM7eMrip/y5j5cCK2ugBpk/kKtsRmmdzwWSOxqfJhfsT 0shduOcVX1nJjfSTrOUXddDv1qk9TGBMrKzVz7igw3YcZFKXTxcQuv5plR+1wx81pOUI+3JdhNcS2 Uzt48e0X9Y7KHPKd5cOly/ZPyEORE8DOsF+Ep5O7ogSfqKftEAEa9AF0ztzfzUktxUfImu4e/KgAF tUjrq7Ftek0hsQgeIVPT+f7kQ3JPB3SRzu6N0dp1n3WJAKUpZ+DyMMHBrEv24mToZNTC9vzV7++bN 3VQbkZ+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1seHbB-00000007n63-267M; Wed, 14 Aug 2024 17:15:49 +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 1seGZw-00000007biT-2OHC for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2024 16:10:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723651827; 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=eCQFSIeDwOTQt5HDmaLH+zjBp75O10MjJ4dyFVJRUrI=; b=D6ypMU+JcsJwkrdfriyPwVYju957G4KST8Yddz9ZJXeJL7ho2kSEC5j71twHstndykmO5k Q//fJVu9SQlydVpPDMsZUgoDqeBJp76nFDkmBAR6l8oBSJWdsSjq/QclOS8Z5j5DVXFrWw +YcJdAcqzZwkCT9pIWSPIP63+tEM4PQ= Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-PKQq7ge4P_aqHNmahQ7_XQ-1; Wed, 14 Aug 2024 12:08:52 -0400 X-MC-Unique: PKQq7ge4P_aqHNmahQ7_XQ-1 Received: by mail-io1-f70.google.com with SMTP id ca18e2360f4ac-824cad19812so9103239f.1 for ; Wed, 14 Aug 2024 09:08:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723651732; x=1724256532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eCQFSIeDwOTQt5HDmaLH+zjBp75O10MjJ4dyFVJRUrI=; b=h7LsUVcsuFp+x4eWryD0SQSg6ukwwYiPkLAhT2P7BNvxHLtyq0pUcJUP6Okl/hIvJV 3onmrvM/jx+/xi42V6fWg1KJe4YiTq/vsJYurXrFvSBHupD0o4QRQEs7+LwAVJuL74KA yvLa33JPJR4CIYgYsRnNVeR4f+f9hc96uHsfboc5ZMtQyLi/jKMSMLeUc9+sjpdcG1PL Ux15/guDnvo4rG6VVcXpVqp9Eq73OU+DSRNtKqscxUOOE6Jz50ryZmUIMSsASra67ce3 vgcmYeC1LfjLhbRvV/HgGe1NhiCnb+kleY/M9i/m+kKhE8u8mjt45Hu/A/k/uOvChk+4 6T7w== X-Forwarded-Encrypted: i=1; AJvYcCUwaaBFNOY9HTLIcE5fdiAmLMKm9dpN1FqvvWvE63Z17iAzaMNLeZ2oXzlHC8dARW9W4xzvG9rKH/c3ageOOLyWsyj4T/57to7MqEGNQrFEjd2mLIA= X-Gm-Message-State: AOJu0Yzl7UrPJrUoS/rhvZH7XsZ/b/O30sVhch+viQdeQbDEO66XvyTr AB+27b06QARvt/a/SRaJgHtigalxGc80F2DPuQ3d8WxQnWc4Di1n/jxunZIga/sqYfER6y7qtSd 0lr3Bga+QcxICulw8ZOhF4GSqXegyopMk59HTp4uVeRVItvF56KMiU6pwF7t3Y+XwOD4WuPlg X-Received: by 2002:a05:6602:6d19:b0:81f:9215:80da with SMTP id ca18e2360f4ac-824dacdaf5amr442807839f.4.1723651732032; Wed, 14 Aug 2024 09:08:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyNuZ7oXWmfRZ0F1HaRl5CrVwWgXo73deaQcT2xIvtNUe5RT9qbnqyv76Wse5AYqDjEvk6VA== X-Received: by 2002:a05:6602:6d19:b0:81f:9215:80da with SMTP id ca18e2360f4ac-824dacdaf5amr442801939f.4.1723651731455; Wed, 14 Aug 2024 09:08:51 -0700 (PDT) Received: from redhat.com ([38.15.36.11]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ca769102a4sm3320413173.18.2024.08.14.09.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 09:08:50 -0700 (PDT) Date: Wed, 14 Aug 2024 10:08:49 -0600 From: Alex Williamson To: Jason Gunthorpe Cc: Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sean Christopherson , Oscar Salvador , Axel Rasmussen , linux-arm-kernel@lists.infradead.org, x86@kernel.org, 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 , Yan Zhao Subject: Re: [PATCH 19/19] vfio/pci: Implement huge_fault support Message-ID: <20240814100849.601c14da.alex.williamson@redhat.com> In-Reply-To: <20240814132508.GM2032816@nvidia.com> References: <20240809160909.1023470-1-peterx@redhat.com> <20240809160909.1023470-20-peterx@redhat.com> <20240814132508.GM2032816@nvidia.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.43; x86_64-redhat-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240814_091028_697354_7298BD83 X-CRM114-Status: GOOD ( 19.63 ) 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 On Wed, 14 Aug 2024 10:25:08 -0300 Jason Gunthorpe wrote: > On Fri, Aug 09, 2024 at 12:09:09PM -0400, Peter Xu wrote: > > @@ -1672,30 +1679,49 @@ static vm_fault_t vfio_pci_mmap_fault(struct vm_fault *vmf) > > if (vdev->pm_runtime_engaged || !__vfio_pci_memory_enabled(vdev)) > > goto out_unlock; > > > > - ret = vmf_insert_pfn(vma, vmf->address, pfn + pgoff); > > - if (ret & VM_FAULT_ERROR) > > - goto out_unlock; > > - > > - /* > > - * Pre-fault the remainder of the vma, abort further insertions and > > - * supress error if fault is encountered during pre-fault. > > - */ > > - for (; addr < vma->vm_end; addr += PAGE_SIZE, pfn++) { > > - if (addr == vmf->address) > > - continue; > > - > > - if (vmf_insert_pfn(vma, addr, pfn) & VM_FAULT_ERROR) > > - break; > > + switch (order) { > > + case 0: > > + ret = vmf_insert_pfn(vma, vmf->address, pfn + pgoff); > > + break; > > +#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP > > + case PMD_ORDER: > > + ret = vmf_insert_pfn_pmd(vmf, __pfn_to_pfn_t(pfn + pgoff, > > + PFN_DEV), false); > > + break; > > +#endif > > +#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP > > + case PUD_ORDER: > > + ret = vmf_insert_pfn_pud(vmf, __pfn_to_pfn_t(pfn + pgoff, > > + PFN_DEV), false); > > + break; > > +#endif > > I feel like this switch should be in some general function? > > vmf_insert_pfn_order(vmf, order, __pfn_to_pfn_t(pfn + pgoff, PFN_DEV), false); > > No reason to expose every driver to this when you've already got a > nice contract to have the driver work on the passed in order. > > What happens if the driver can't get a PFN that matches the requested > order? There was some alignment and size checking chopped from the previous reply that triggered a fallback, but in general PCI BARs are a power of two and naturally aligned, so there should always be an order aligned pfn. Thanks, Alex