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 C9259C02194 for ; Fri, 7 Feb 2025 01:39:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 359F9280003; Thu, 6 Feb 2025 20:39:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3099C280001; Thu, 6 Feb 2025 20:39:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D128280003; Thu, 6 Feb 2025 20:39:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F09EC280001 for ; Thu, 6 Feb 2025 20:39:35 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7B7BBC0C95 for ; Fri, 7 Feb 2025 01:39:35 +0000 (UTC) X-FDA: 83091441510.24.CE60A45 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by imf30.hostedemail.com (Postfix) with ESMTP id 5D12A80003 for ; Fri, 7 Feb 2025 01:39:33 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=canonical.com header.s=20210705 header.b=nCh6LIlO; spf=pass (imf30.hostedemail.com: domain of mitchell.augustin@canonical.com designates 185.125.188.122 as permitted sender) smtp.mailfrom=mitchell.augustin@canonical.com; dmarc=pass (policy=none) header.from=canonical.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738892373; 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=b1dO1A4fPI5eS8WT6hBCvAO68gaA09DjpLJhuG6VUwI=; b=4SAk23JiPBedGdLZu9mx4NmT9QXsSqcVdEDnudavCOVxcxjTrsLxediQSl1SyepSs874Y6 ljx/902UUKelb1tMPqKP89Z0BGJv29dOV86hwaqvb/PW3wEG8bhYBWJ4iV6I1vsk9pBGAu Kcd0whb1UulunQx9LxGV/vTHgor47V0= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=canonical.com header.s=20210705 header.b=nCh6LIlO; spf=pass (imf30.hostedemail.com: domain of mitchell.augustin@canonical.com designates 185.125.188.122 as permitted sender) smtp.mailfrom=mitchell.augustin@canonical.com; dmarc=pass (policy=none) header.from=canonical.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738892373; a=rsa-sha256; cv=none; b=qwVbxPNu0Q1Asp7i+9utD47gPS1WNhmS9nk/0Cc586T0q+g5s/+f3zeGCbTLnw1zSTLkPb ulQow31uOwQ1FX32OgV+d80JaXNBtEC91KgfcKYnt9hraggzLEo8en43JydmTcfZtaYC8j Haoha61JnAUVi7UgoiB7LDmjNLYBNPk= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 8E0F23FA60 for ; Fri, 7 Feb 2025 01:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1738892371; bh=b1dO1A4fPI5eS8WT6hBCvAO68gaA09DjpLJhuG6VUwI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=nCh6LIlOnjgqqeP9LxXFZRsOb9TUbGy6sVjP5vVSIbwjloFpe15NSIIKLBjRlAzzQ FDeudwsRRE/+qb5s/G4XpdQvTVEloNOogMMApLwQzcVMa9OD2txBQ8vMt90iV+iSbF HWbi13C/SQ10L0+Hh94a/wl8Iw8fJroq5fGGsn3gAbv8IYFljLWUEombSoOpg6HA4t UEQrigZ2UL0oj7zeELSud4T1+tf/0d614ggd2BkBlnikhrDM5s1AiKH3VZ/nOL5QrL IObnomQdfTVqFm+SorR+4GxzYJeXqf3xRNPP5YY986ClqPq8I5on/qBltuD0Aj7bzS sqL99U3opna6w== Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5d9fcb4a122so1826540a12.0 for ; Thu, 06 Feb 2025 17:39:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738892371; x=1739497171; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b1dO1A4fPI5eS8WT6hBCvAO68gaA09DjpLJhuG6VUwI=; b=ABv46/4NYrC8ilb6DD7ZEamPmun8z8OK247qKCSocIC9JL95FbceUMkgi2OAnDNOBY AnzDjX/eYgEIHaMlsSsIqNt2iuwtJYgpXuLubqWcfQznpka+e6s5qYx+HBJsTr0xtU1v EdG36JwHZPYNIO/rBws7gjwxEB1cbfz5NBng/DJpnlIC5KVE/n7rJ0TSR0bVaKoJ07ls WHaUVFoWKuTDDjI3sasMs1Dq0tpYKUsSdqE3Pht/l1l29uloFJTqT3EbeQeps3RwId92 QsW0R1nfhQ3ys49mJcL6Mj5LBSmJW291AGr1UCzDdTfohJ2VdOhvWmvq2PHbXoOliEjS oKBA== X-Forwarded-Encrypted: i=1; AJvYcCUikZ5pRGy8Bl0P4fmZNnSQ0I21ICR9jvAzpjIUoJ1cdQdec+pNqjwqFX2bs8gJRCABI2cVRbw/Pw==@kvack.org X-Gm-Message-State: AOJu0YwhjmZ/sPiTsRfQ9TTWAG1Nj/Zf31hlUbofQoumUK3wrdjtNNaU bPL6VG4hlkou+gj8Y8QPNIn+nXccHfRlgSNLdPYOP5MXtqo9qM6lL9lfwH5qannRR+DJbSYH+zf sScXQTzC+79vCWK6rSGXNOViZLylWtelIFo9ScK4BtwjF50tVGCOM4Neab0xNkNOs53zPeRa5U9 n19O+ISPOWhcsrKI9AeglGMBodcz793Mf1bE9pobg= X-Gm-Gg: ASbGncshtY10LdylrEY7+mpRSaI9fF6JI8oc+VGFfYnt0Yzu4hPPiZcinWuO0OnPuuz h7ZgFmTKbWP262s7tGB29alFL3BWOLtFRrsrGQ3G1sDQ3WVdN25aKYEPtXMBW X-Received: by 2002:a05:6402:c4b:b0:5d3:e766:6143 with SMTP id 4fb4d7f45d1cf-5de4509b566mr1816313a12.30.1738892370704; Thu, 06 Feb 2025 17:39:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEA1P4T7CyKNlBjCPd3feXPu3bSKDsKVxl2JRQltjEhhWAvnx988Pg7gPW3EJvoLdjd/bz9pbKIj2MWA4uYR6c= X-Received: by 2002:a05:6402:c4b:b0:5d3:e766:6143 with SMTP id 4fb4d7f45d1cf-5de4509b566mr1816302a12.30.1738892370367; Thu, 06 Feb 2025 17:39:30 -0800 (PST) MIME-Version: 1.0 References: <20250205231728.2527186-1-alex.williamson@redhat.com> In-Reply-To: <20250205231728.2527186-1-alex.williamson@redhat.com> From: Mitchell Augustin Date: Thu, 6 Feb 2025 19:39:19 -0600 X-Gm-Features: AWEUYZkVdVSE3YCdOATSd_ps38BYnjbfjtvXK9l_0oGFFYSaahc9EADcxC_JmYI Message-ID: Subject: Re: [PATCH 0/5] vfio: Improve DMA mapping performance for huge pfnmaps To: Alex Williamson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, peterx@redhat.com, clg@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server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Qoym KK2Z89Z9GlV9aE5jTypJ0RIk0JegKm5rcfPBjpDtmECwp/Fj+4tSPiqC3JeDVXzmTOrsd70njj05xCO33dbR7Q0Frs2tcOdS1IlH6RcNuf23n5/MsLYtkB+mf+bWM1kmf0noFLFMnKvHx2kZB0uGdz3LgCQ6Euy5+81Qu3v/NUJ6PbhpJC/G5w4p27AF0IIpmWQT0l9qFOLM8Gko8+VQEnFxOL2hA6HCIh+SNVUb2+jKkctyXjq48+Pyh+985Y9iOT9cfs9NFkCFxMtUA//sXrC9ph7Vi228Q09ThX6kx4dUMAhvOEIpa4oi3kzGTyqVh5M6dTv5NMl1Ber28IV9Nk7FB+Ox1kjE3RYrB X-Bogosity: Ham, tests=bogofilter, spamicity=0.001504, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Thanks Alex, this all looks great to me and completely eliminates the boot time slowdown I was seeing in my tests on our DGX H100 and A100. I also double-checked the memory mappings reported in /proc/iomem, and everything looks consistent with how it was prior to this series on both devices. Reported-by: "Mitchell Augustin" Reviewed-by: "Mitchell Augustin" Tested-by: "Mitchell Augustin" On Wed, Feb 5, 2025 at 5:18=E2=80=AFPM Alex Williamson wrote: > > 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@r= edhat.com/ > > > Alex Williamson (5): > 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() > mm: Provide page mask in struct follow_pfnmap_args > vfio/type1: Use mapping page mask for pfnmaps > > drivers/vfio/vfio_iommu_type1.c | 107 ++++++++++++++++++++------------ > include/linux/mm.h | 2 + > mm/memory.c | 1 + > 3 files changed, 72 insertions(+), 38 deletions(-) > > -- > 2.47.1 > -- Mitchell Augustin Software Engineer - Ubuntu Partner Engineering