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 618B1C282C1 for ; Fri, 28 Feb 2025 16:32:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE336280006; Fri, 28 Feb 2025 11:32:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C9363280001; Fri, 28 Feb 2025 11:32:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5C36280006; Fri, 28 Feb 2025 11:32:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9C552280001 for ; Fri, 28 Feb 2025 11:32:44 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 37E29120F01 for ; Fri, 28 Feb 2025 16:32:44 +0000 (UTC) X-FDA: 83169897048.02.A60F187 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id CB39D1C0004 for ; Fri, 28 Feb 2025 16:32:41 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZT75VT8l; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of alex.williamson@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=alex.williamson@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740760362; a=rsa-sha256; cv=none; b=jhPs1LiWqHxqaK8r/tkE4oC7pzfByDuBpThJBHo2/d4XAxVsF71INi78PqRT1LyZSE6XT6 VaP7JqimYR8JidtnDQSV47/O2gXCrcQnucPF68vkWWDnM1bdnfjLax1smDa7gSHHcKpy9B BZs92x/BDQmDepamFfXJdyPhMT77juI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZT75VT8l; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of alex.williamson@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=alex.williamson@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740760362; 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=dmEeb9lKrGzm9PpnwIENCXTvdUKNgeT1Zk6eq2x1XqY=; b=KNztzwVYaglHstYL/VfjyfUwh6pqKmQR0hMcOxZup+iCYdWQYCHMa/sDz/6i/sOzSqe5FQ GKaClKwDSbXf2OnFNXS7BxJoV0wIb2E6n9GgHqxFQy5XyEfQGMwFss9d7Lz0Hd2n19g14V K+7kgN/z5uBCRSCG/xxcXhTCUF5et+Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740760361; 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=dmEeb9lKrGzm9PpnwIENCXTvdUKNgeT1Zk6eq2x1XqY=; b=ZT75VT8l75BGehIWhwf6lWqRjDZuYrcNaqUwyrxNodw1PwFsdW8g0OGJ8dFHSkzpmmzNxh tLS6ijo/BxTJLEAkFzscf/R7jN/kJrGx3ar52eaPbHqxwswKOMY5I/xvu8TBc2ST6+vmLZ PDc/e9m1ejn8egMx9hzm45oc4mC9FLk= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-394-u36wCdEOOMmU08xZSi4mHg-1; Fri, 28 Feb 2025 11:32:37 -0500 X-MC-Unique: u36wCdEOOMmU08xZSi4mHg-1 X-Mimecast-MFC-AGG-ID: u36wCdEOOMmU08xZSi4mHg_1740760357 Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3ce8c06be57so1867155ab.1 for ; Fri, 28 Feb 2025 08:32:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740760357; x=1741365157; h=content-transfer-encoding:mime-version:organization: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=dmEeb9lKrGzm9PpnwIENCXTvdUKNgeT1Zk6eq2x1XqY=; b=cQ273fXeD3RcobT0GW757BTyPkYr22Krg2Rpb+EXrEcSF6oBHK8pGoO1hlh7+BEuzo U2ot+SCfr6Q4hidYGt+n9tuSpIvGYdXFnK3Se7HZtxFiLe62SOE6PqfDNXfRTS0xRJJt bEPCRrqiO1R3GElhn3uf3IXo25HiyVTTIfXDpdUiCw98ryseSPt8GRqyHgmDtugJf9Lp pvaKgvDjMZ4J58JqCaTrGEdiBLT+NbaP1m2ZQr20QnEUP+gyRtMhmkWK53e98OjK493z UBaR5BupG/a00+XQQ+t+MxlRIhRvsFKCwK+e0lRClVxxcftCXt3B3Fj/TSBjxv8W0nil THCQ== X-Forwarded-Encrypted: i=1; AJvYcCV9/E7TLlyFcdN9A8N30h7q7VuMihprvEZ5hKG8RKkrdVqQP11yntLodMg1GxLkuLxCbsZqeKeRNQ==@kvack.org X-Gm-Message-State: AOJu0YxWRRxC1xKmHJ5f1P5UpPZn5SBQBCW/R4MdrdoTa8cccfHusDci UaRPMbqYJcNJMqXR+94JJ63krrM9euctN9Mo9w6BS8kPSjUGclQAm3i+TiRXcm1HMjYQfqQE/GW Z95wGWT//bFUfe+2PQHN2vMpFXW4tljCwLJkDMCBn2K9OeJSZ X-Gm-Gg: ASbGncum+KgzYNDyHeIDhHRSAcrgYQ7Iv2s2AEXCzCqczzq+e7c7ROdw0lRmJ9FvZ9F eX5gguQFQaShc/YzQVSFhfTSbs87z/HgH5/EesGEGlv5IWA4lE4RVzxE1siniQcHHyfdFsPbRqn uyPnf6Jf0QQ+1km9RwgOsTPRqWxIK+Se62V17luWVleQ7LpXx/6ISr39cjUPDTW24pZjKgBNtlE xG5hiDZ0eb46eYQKmiZtl41s6kJLmELGWFZqorzjkq2Yi60DcPvmrCA37Mzlu/1gkJKCwo6HY/i f4ubVDWOghpKb7zDJmY= X-Received: by 2002:a05:6e02:1748:b0:3d3:d156:7836 with SMTP id e9e14a558f8ab-3d3e6f97e8bmr12715915ab.7.1740760357003; Fri, 28 Feb 2025 08:32:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1OqqoD77aeXTkALnv9pFGNxbF4QLi2N/iLQZh/bOT8+63cQ478MEpB3v7yPmmrcMIMSMziQ== X-Received: by 2002:a05:6e02:1748:b0:3d3:d156:7836 with SMTP id e9e14a558f8ab-3d3e6f97e8bmr12715695ab.7.1740760356621; Fri, 28 Feb 2025 08:32:36 -0800 (PST) Received: from redhat.com ([38.15.36.11]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3d3dee6ff9fsm9202015ab.32.2025.02.28.08.32.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 08:32:34 -0800 (PST) Date: Fri, 28 Feb 2025 09:32:31 -0700 From: Alex Williamson To: alex.williamson@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, peterx@redhat.com, mitchell.augustin@canonical.com, clg@redhat.com, jgg@nvidia.com, akpm@linux-foundation.org, linux-mm@kvack.org, david@redhat.com, willy@infradead.org Subject: Re: [PATCH v2 0/6] vfio: Improve DMA mapping performance for huge pfnmaps Message-ID: <20250228093231.338c9f06.alex.williamson@redhat.com> In-Reply-To: <20250218222209.1382449-1-alex.williamson@redhat.com> References: <20250218222209.1382449-1-alex.williamson@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: tYcQFDJHrAn7kvQqHDDqtxHM83PUoMiFVsVWuLM2FMI_1740760357 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: CB39D1C0004 X-Stat-Signature: xwtnfdqpf1gni96stsbpmyxzwum7tsw5 X-Rspam-User: X-HE-Tag: 1740760361-612735 X-HE-Meta: U2FsdGVkX18Ay90c/hBGV7cr/WPJPnW/MqmrggOS4GzA7fBhJJsUtuO+k7pPfROAFunB51Z1Pns2oP+YL5JYoiYycMLW/6Ve1R8GeD6qXXHani06uXPiIVaDWCRT7m8ti+wGTDysK6JY3yxzhexGpa9Kkv//APL5a5zcqe9Qe77Nwhr8E6ZIrAOv+CjB0+DCzT7VZPZBnZ7uBDm4yoO5quvnWO8E1jWhPyyrGpwx05t/1st/pBT+nxZm4j6NFUX0Yalzk+Gcka4lWbmQlwb7mXRnZi70k6YUS8LWrOUvWwaSj0iIkY/9csIlXetditl/Bbf5S1JkVHGFp/FtjFTfppWxICSBTpR4GIsew4Vv9ZMOSfjf1BEuXswrYMGPgdXmoFmc+sZ+Iw6P9hHaJKwoMZazr1dJegO9aZbPjrG7FsptNVsfrHRiwmOAyrYIiqL07JgnpUodxgt/02GkJPnwr+SMCPoDq4+Wx1UfawXyp9y1oAQpScJGwai9VCGuTsdnqPpAzKILFsPngBHItTYAP+yXNEFj/OEVE8I9wmlcFWdGPJARF6JRL3vxnOFiOhdByTCDwlWUa1Dk580j2voIFU8dpB31JNrtqyiLKUbkNCFpbsRvFyB3BQt6fGPAbnMrl3fm0H3uF/tIu1dhrScK16k2fd6ExlVZkcFs63w93btrYV9d1a/EtRKjFTXANCBzlLoLy8Hy7xCrNxfYz9KYa480ylIcETgNw8ehRAMAWHo3XBpJp1SoWhtklmHk2U26EzhU8hIzSbiiA+agfNiZ7FdbtUDSfcBgdYVkr61RQeKUF2dCfDIbQM8UiO+7r831bZCs1qsmvFsviAS/z5vitg9KQXUuYm4tNlJR1IAYBRAp+UYd7lycIbTz8yTjN8N+bEokFWd0Myn4RirXVza7LD2XTLGE36SqR/XU5yr3xneGF0ag7PSBHHT5wGu61lmNhxZxCv4gg0bLmU1sy7K sPE2MfJ4 4ZHzmvwtLPZJ7Dk5vBtbwSR1aIzx9EZpNTcJRJzI5Iijc3rENqkKZedX+fWTzmqsI5cbxAU0179g6JFBdI7redS+ma6e49ri01ynGw0DvhQoBahzKmkPnUlXE7nCLAI5WCtb2/qJr+ZZwSfKVCtPARd3OpqB4eTzga8s1kdQ491ewTOflog3huvuAG59qfjplUIJY2bXRZtM/w9w2gXJjTBzg1Adqb1tnLaRtDS9WM0yXbxjjMJqaKdetLG/L09WFi36WwnbrwFgzo9lobRXmqTer2GZhKYyetrE/aaV0UBfHubRG08PZe5ZTvBAkGXKPbj71Kdz5UKGsBNx926OAyzxoNN0WczcKkcaCfQFSFjRiGLDoJyPWzIAxF/AZXp7jXDQom2+oZ+oRxpVtURsQXiKNULOY+8kdU212zbIDjCtk/9cGzaqfGR8sgmZdYmXHPVVA7/hmbSq554w= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, 18 Feb 2025 15:22:00 -0700 Alex Williamson wrote: > v2: > - Rewrapped comment block in 3/6 > - Added 4/6 to use consistent types (Jason) > - Renamed s/pgmask/addr_mask/ (David) > - Updated 6/6 with proposed epfn algorithm (Jason) > - Applied and retained sign-offs for all but 6/6 where the epfn > calculation changed > > v1: https://lore.kernel.org/all/20250205231728.2527186-1-alex.williamson@redhat.com/ > > As GPU BAR sizes increase, the overhead of DMA mapping pfnmap ranges has > become a significant overhead for VMs making use of device assignment. > Not only does each mapping require upwards of a few seconds, but BARs > are mapped in and out of the VM address space multiple times during > guest boot. Also factor in that multi-GPU configurations are > increasingly commonplace and BAR sizes are continuing to increase. > Configurations today can already be delayed minutes during guest boot. > > We've taken steps to make Linux a better guest by batching PCI BAR > sizing operations[1], but it only provides and incremental improvement. > > This series attempts to fully address the issue by leveraging the huge > pfnmap support added in v6.12. When we insert pfnmaps using pud and pmd > mappings, we can later take advantage of the knowledge of the mapping > level page mask to iterate on the relevant mapping stride. In the > commonly achieved optimal case, this results in a reduction of pfn > lookups by a factor of 256k. For a local test system, an overhead of > ~1s for DMA mapping a 32GB PCI BAR is reduced to sub-millisecond (8M > page sized operations reduced to 32 pud sized operations). > > Please review, test, and provide feedback. I hope that mm folks can > ack the trivial follow_pfnmap_args update to provide the mapping level > page mask. Naming is hard, so any preference other than pgmask is > welcome. Thanks, > > Alex > > [1]https://lore.kernel.org/all/20250120182202.1878581-1-alex.williamson@redhat.com/ > > > Alex Williamson (6): > vfio/type1: Catch zero from pin_user_pages_remote() > vfio/type1: Convert all vaddr_get_pfns() callers to use vfio_batch > vfio/type1: Use vfio_batch for vaddr_get_pfns() > vfio/type1: Use consistent types for page counts > mm: Provide address mask in struct follow_pfnmap_args > vfio/type1: Use mapping page mask for pfnmaps > > drivers/vfio/vfio_iommu_type1.c | 123 ++++++++++++++++++++------------ > include/linux/mm.h | 2 + > mm/memory.c | 1 + > 3 files changed, 80 insertions(+), 46 deletions(-) With David's blessing relative to mm, applied to vfio next branch for v6.15. Thanks all for the reviews and testing! Alex