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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DF9AD5B861 for ; Tue, 29 Oct 2024 02:50:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C78B46B00C7; Mon, 28 Oct 2024 22:50:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C283B6B00C8; Mon, 28 Oct 2024 22:50:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC8006B00C9; Mon, 28 Oct 2024 22:50:21 -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 89CF06B00C7 for ; Mon, 28 Oct 2024 22:50:21 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0E81E140B99 for ; Tue, 29 Oct 2024 02:50:21 +0000 (UTC) X-FDA: 82725110454.05.6B81198 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by imf04.hostedemail.com (Postfix) with ESMTP id 8DFB84000B for ; Tue, 29 Oct 2024 02:49:44 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=VpaPZFxk; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf04.hostedemail.com: domain of qinyuntan@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=qinyuntan@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730170088; a=rsa-sha256; cv=none; b=ryOQnvcPycFZsZjLu3cadEY2iCf/tVolFbfz8nxhhBnJVp5RUiHJAnkvoZybxZZ2TQf13m Fs5pbU4k7+fzJkSuxtWzmln3tHv6B9LPTqH541J3crrbFRG+tNMtTAWSElK/+AZ19RR8H1 EswHl//FSYnSJqudUZ95dLaO9OMsucc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=VpaPZFxk; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf04.hostedemail.com: domain of qinyuntan@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=qinyuntan@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730170088; 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=+LYH/w9vwFz4HfaTT2wWGyjrIaDoiS8YNbevERY3lVw=; b=MEUtIjIflvBn78Dcts+MBfuIObBlPLGlT7dBVdT4S6aJ3VAHLAnMaoS4oShY7gXKE/ZE32 +nFO5Qr7aDH71A3TV1YVzr2ubsEIBaUzr9udu64ayw1BNyzQ+aHe9cWWYzjDe2fQbln95A Xp16lzvZNA6LgzOgwd5ESwhdR6UPpAg= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1730170212; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To; bh=+LYH/w9vwFz4HfaTT2wWGyjrIaDoiS8YNbevERY3lVw=; b=VpaPZFxk0W9CJrV49olLc5Q7QkZooHSdQQ31RsqgYG3Q6F6HZB/wFBOUe6R3BZeMUBpb49nX9kuBCpq3ePMJSN2gRbur9Ewc9RiglqUPADOn8QN4InqhGmRSTP0ES69+6N7v4xhYaPV6P35OjY9ePl4OthJNP9eWmJ2dsfXGicM= Received: from smtpclient.apple(mailfrom:qinyuntan@linux.alibaba.com fp:SMTPD_---0WI8SNPI_1730170210 cluster:ay36) by smtp.aliyun-inc.com; Tue, 29 Oct 2024 10:50:11 +0800 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3818.100.11.1.3\)) Subject: Re: [PATCH v1: vfio: avoid unnecessary pin memory when dma map io address space 0/2] From: =?utf-8?B?5Y2K5Y+2?= In-Reply-To: <20241024110624.63871cfa.alex.williamson@redhat.com> Date: Tue, 29 Oct 2024 10:50:00 +0800 Cc: Andrew Morton , linux-mm@kvack.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <90A096B9-0E6F-484E-A741-9C60E001E78C@linux.alibaba.com> References: <20241024110624.63871cfa.alex.williamson@redhat.com> To: Alex Williamson X-Mailer: Apple Mail (2.3818.100.11.1.3) X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8DFB84000B X-Stat-Signature: xq57cs65tx35t1nftf5n4pdmumssmgj3 X-Rspam-User: X-HE-Tag: 1730170184-390443 X-HE-Meta: U2FsdGVkX18v+HQvUvA/ObSLUhEbXX5jyAwIB4cbPfMZhD46uP8aHjMb3uSWDlaCPeuVw2qvt0fNzjLttYx0/u+/CPRoEHzjiUUa1Eh38pVkroe0UuH5+erNjc9TamdVidYyTeyFa/y2lMpC3DBXlHqa0VlcOlj6LorLd4lKKO4lPZYf7TA40waKzS5uR9bVM07vDuLzrsqPjI6fkwtrDhanhHuJ+7Wu8e7fyJZ7w4YN5Pnz5OYb4C8tzuNuIsaK66YeK8mX1WhHmrMuBtG5xyuvarn0HCzna5U5oPvKNE4fo24ZETA9bleb4L48zLohLdz0lDPr/5T4gBeY4XxYgPZJuCf3QTWo3w/sV0elCkzSHyUvedAGy4I6cIvJjUF9lYrP/7QN6cMakdi6MVifg9WCqFSUOx/rXM7lF/04sYJGoW//CfeFr9/R7s8D+HxF8ftrT4V3uTJrOerDfYR7FA5wFFIk2Wj5DujZ3uTRN2AmgQH+8UL81d7M9zMr/1Y+GF9jQ3jXqA60ZkqXpUFqWMoT2eaA2EfBFtq/j0A/qff5ybhDzp5xiZwn59NH4ipNKcPs74Ap0YMgbNYRE6GhJqAf863JibT+BPTcqdI5uP2y7qb3yDOCG+kGg9L70X8S9GuMykOWSs7BF79R3TB4VpbVeUUhu13KshURZLUFJk9nJpeayhlaXsbS/WZa6srpwGbxPqXZh62UHYzCKXqvvDQQ7crtx/Rg94P8lXaPXkXiugbE8SK0xFc2onaz5pc3pkStZfCHwrRIprxJFqeR0VEHk81VnuYgaUIgvkRwLCYYUb+P6AI1W4hIld1oR2gbTODxa1dRzOjk3BfWWFM6jkMpr6PPdZShAfJG8htvYTbTTVuDQfKgUSXEnbWUxvRpWBUhcziYyl+/VktJEfKHTTSFDJqNdP3Rkknet48nzq514klvBPwtsPFtyS7LqOJcmDgdJgseyFR8hjM6UPo hOJcH1b6 lGrQ8JlpixPhd+QQQ12jH9jhBIoKYOUCJ5JR1tlmSfD7wU2BBgb+vGZksvPylXMfo5UQOApEbS5KGYGDEHeM6y9CjfVv1sdikixvpSgDQJVh7CiYVatt0iy9A+lVMLZMzRtxxEAt240r3Pv2TH7fGEtbG1rQuEVbsalezl6vMbZ4B4mDB9wGKBHP1WyqbpkCCBskC+J/W6bIXOTLui2nmD1xa+ar8bUnaPtjEm/u96I/zCIyfq4wFmAB6KdOMfcilhENhsJ4aZa4R4gGP/x+Yo2JujWRATP9C8XeNfaEnZtdrtyy6N1bA+NvKZg== 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: > 2024=E5=B9=B410=E6=9C=8825=E6=97=A5 01:06=EF=BC=8CAlex Williamson = =E5=86=99=E9=81=93=EF=BC=9A >=20 > On Thu, 24 Oct 2024 17:34:42 +0800 > Qinyun Tan wrote: >=20 >> When user application call ioctl(VFIO_IOMMU_MAP_DMA) to map a dma = address, >> the general handler 'vfio_pin_map_dma' attempts to pin the memory and >> then create the mapping in the iommu. >>=20 >> However, some mappings aren't backed by a struct page, for example an >> mmap'd MMIO range for our own or another device. In this scenario, a = vma >> with flag VM_IO | VM_PFNMAP, the pin operation will fail. Moreover, = the >> pin operation incurs a large overhead which will result in a longer >> startup time for the VM. We don't actually need a pin in this = scenario. >>=20 >> To address this issue, we introduce a new DMA MAP flag >> 'VFIO_DMA_MAP_FLAG_MMIO_DONT_PIN' to skip the 'vfio_pin_pages_remote' >> operation in the DMA map process for mmio memory. Additionally, we = add >> the 'VM_PGOFF_IS_PFN' flag for vfio_pci_mmap address, ensuring that = we can >> directly obtain the pfn through vma->vm_pgoff. >>=20 >> This approach allows us to avoid unnecessary memory pinning = operations, >> which would otherwise introduce additional overhead during DMA = mapping. >>=20 >> In my tests, using vfio to pass through an 8-card AMD GPU which with = a >> large bar size (128GB*8), the time mapping the 192GB*8 bar was = reduced >> from about 50.79s to 1.57s. >=20 > If the vma has a flag to indicate pfnmap, why does the user need to > provide a mapping flag to indicate not to pin? We generally cannot > trust such a user directive anyway, nor do we in this series, so it = all > seems rather redundant. >=20 > What about simply improving the batching of pfnmap ranges rather than > imposing any sort of mm or uapi changes? Or perhaps, since we're now > using huge_fault to populate the vma, maybe we can iterate at PMD or > PUD granularity rather than PAGE_SIZE? Seems like we have plenty of > optimizations to pursue that could be done transparently to the user. > Thanks, >=20 > Alex