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 A39EFD21690 for ; Tue, 15 Oct 2024 12:41:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEF376B0082; Tue, 15 Oct 2024 08:41:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9FC56B0083; Tue, 15 Oct 2024 08:41:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D40626B0085; Tue, 15 Oct 2024 08:41:33 -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 B4C476B0082 for ; Tue, 15 Oct 2024 08:41:33 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 685D9160185 for ; Tue, 15 Oct 2024 12:41:23 +0000 (UTC) X-FDA: 82675797456.30.3E2A3E6 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) by imf30.hostedemail.com (Postfix) with ESMTP id 6EBF680006 for ; Tue, 15 Oct 2024 12:41:16 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=AEjozf0Y; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf30.hostedemail.com: domain of thomas.hellstrom@linux.intel.com has no SPF policy when checking 192.198.163.13) smtp.mailfrom=thomas.hellstrom@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728995974; a=rsa-sha256; cv=none; b=lNhq9ZBeKnANTB4tEym0OuEfXrShplgLi7/O6fj5aucz06TFYxm7jJb+ZWcOa0PI4OBwwY 29ccecDadw2YuUiq3aWa1n75yFqnwMgBY/puMYR2QuJao1rtJSYZBLhRi8QRvtPMbxsJ/K xwklg4MKiBvx1KWiqaf5CiEBY1Ol6gI= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=AEjozf0Y; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf30.hostedemail.com: domain of thomas.hellstrom@linux.intel.com has no SPF policy when checking 192.198.163.13) smtp.mailfrom=thomas.hellstrom@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728995974; 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=3keHc+z/2Lbw/ZqA20gFb4NDvM5z7xaYiH7FKwy52yY=; b=XT3ou3iPp9FUuShHj27FFhsEntIj0uhkbDbu+Dnk86E6Y5ugJmH3EcgDqE2/UGNgIgOugf VbwFaVnLtSim/ZTK2zGtMzMtUSTYyeD4gvwwr4WVpzhooRf3ptWp7ZuSPdVPwHpvFTe2a/ hCFgT9PTvaaOUR3rs5rr19K065S/Zpc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728996090; x=1760532090; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=+GiexxCIP40VgtIsNMOgBvOvMGy6SLDeRcCatZeWG6A=; b=AEjozf0YuMpso3Jf/FfIqPKSB3USd1Jlelc6OwEtC4TeCHnCHq/YQB6Q YYUf14fBNTyqcSBBZCvctQnvxPRDmQV/qcNrResh/yXq/7R8mwQSMRzec daVPijDGu3/sMzbP6lYZF1/GdhlottSwiHp1UB3GjKBtU6bF4BgeokQBw y/UxG7kCp8xcKW1o0vEskC+7L5ezSQpbje5HUYVlC7nllEk33+7O6DyRv gJ+Ffna2KrWZCyHWexybrquMRTV5rAWmMr4wZD58B2Aa1GPhw942UJz95 ra7wFcjClUdWgfHEj3+JXdEFOi+5KkY1fcD00QuYWzbMoJ2mcEOWsZzwJ Q==; X-CSE-ConnectionGUID: LE8gXaGPReiVYU4YdwlEyA== X-CSE-MsgGUID: RatOQgU2TFG4964RWrJiQA== X-IronPort-AV: E=McAfee;i="6700,10204,11225"; a="31259565" X-IronPort-AV: E=Sophos;i="6.11,205,1725346800"; d="scan'208";a="31259565" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2024 05:41:29 -0700 X-CSE-ConnectionGUID: EaHlclDNQCmecShcQia82g== X-CSE-MsgGUID: 1EGf41f2TkG7TVkHfeLzYA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,205,1725346800"; d="scan'208";a="82534521" Received: from cpetruta-mobl1.ger.corp.intel.com (HELO [10.245.246.43]) ([10.245.246.43]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2024 05:41:26 -0700 Message-ID: <19fb79c069b812b164abd4f79d38bb12d2f5afa4.camel@linux.intel.com> Subject: Re: [RFC PATCH] mm/hmm, mm/migrate_device: Allow p2p access and p2p migration From: Thomas =?ISO-8859-1?Q?Hellstr=F6m?= To: Jason Gunthorpe Cc: intel-xe@lists.freedesktop.org, Matthew Brost , Simona Vetter , DRI-devel , Linux Memory Management List , LKML Date: Tue, 15 Oct 2024 14:41:24 +0200 In-Reply-To: <20241015121759.GG3394334@nvidia.com> References: <20241015111322.97514-1-thomas.hellstrom@linux.intel.com> <20241015121759.GG3394334@nvidia.com> Autocrypt: addr=thomas.hellstrom@linux.intel.com; prefer-encrypt=mutual; keydata=mDMEZaWU6xYJKwYBBAHaRw8BAQdAj/We1UBCIrAm9H5t5Z7+elYJowdlhiYE8zUXgxcFz360SFRob21hcyBIZWxsc3Ryw7ZtIChJbnRlbCBMaW51eCBlbWFpbCkgPHRob21hcy5oZWxsc3Ryb21AbGludXguaW50ZWwuY29tPoiTBBMWCgA7FiEEbJFDO8NaBua8diGTuBaTVQrGBr8FAmWllOsCGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQuBaTVQrGBr/yQAD/Z1B+Kzy2JTuIy9LsKfC9FJmt1K/4qgaVeZMIKCAxf2UBAJhmZ5jmkDIf6YghfINZlYq6ixyWnOkWMuSLmELwOsgPuDgEZaWU6xIKKwYBBAGXVQEFAQEHQF9v/LNGegctctMWGHvmV/6oKOWWf/vd4MeqoSYTxVBTAwEIB4h4BBgWCgAgFiEEbJFDO8NaBua8diGTuBaTVQrGBr8FAmWllOsCGwwACgkQuBaTVQrGBr/P2QD9Gts6Ee91w3SzOelNjsus/DcCTBb3fRugJoqcfxjKU0gBAKIFVMvVUGbhlEi6EFTZmBZ0QIZEIzOOVfkaIgWelFEH Organization: Intel Sweden AB, Registration Number: 556189-6027 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.4 (3.50.4-1.fc39) MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6EBF680006 X-Stat-Signature: 7n5qnurror6zi9jw5735ob9xxdi3e45e X-Rspam-User: X-HE-Tag: 1728996076-2699 X-HE-Meta: U2FsdGVkX1+31i+CYwxIx9AOS63Clg0lCzy063htLF+Vdvcinkpj6U901Ibmsq4EALJ1cfLLDTU5x/Irw2fTUpco6X/isNMZ6swe7XsBFnBOnSvcw6IWOpGD6mDLxVeIS4rkc2lWFFdFXlEzwmdrKbwSdVY24XWZAZyejFMELhMDxQLgPRcxFZ36Kwf2daGaOOfOseUpW9Z5B2hb+nqVPfA+r1/FRFhhh49mdOJooUuFoiW89v8vCRzvdBHVPUlB3hwhpE1JFLta+e9MNBhbKkn566e4ozCQrqx8WQgMURSELlzsK1CGIDj80WhFbYrNNmFrt6CZ2MkfPzaXxwvvaKFhDCrudWDTmpj0ygMbYNAEPtqx4WXkZcYj7emtOI8HEPmbcp0KkB9ZbxE4EbRmwncKSNscUVzMr6qJX6GRaF55/xF+VvPHClHS27wpDI/VpncQNraeiLq0V7F4LKbE4dbVgcri+csl1cPz4ItcFATDp5o5qTFPnzOsA+iLzkiPmqnIeUl3VLznkGJ7BfBS91SeHC7N/VU9crMSDSe5bKJX8zHBHwrDBInZdA5RYQ0/wTyV+QPzxkBXjis2la3i3FVY47GVdCOZGPdx/AM4lfJCmqMKz/QmiE/YJZdEtNE9fgHiwmyTNwbizuxI1R7B9d5TmF9twOdgZZ2g+LiaATOGEfJf2vnzaw98MjA0+94JMV2FXQ9dRJ6oAAUO3jjE6mlQl30klfeQpFqwFfbWrArP1rEFE0frAIUj5L0wflgOSdH6/WHqfl0rFroAORyAMxd4IvRGsguWFKL75mtPVaFljdQdWnwTVsLkLmM+Eybv28DPiEfTAp5j0U4uGW8UjTWvM/TtFPbSTtlOFh9ljCGKKl7cr/R6Z5XubBXCrFxHcxz5zLQ8dX6H8hXhxBk3drkFSra7SHqsrIUPXX7IsCEnBAGzsiuboym/Hq4JPysJPKpLTlxCgJ6ExI0etdh cg/vTQOg Rmp10R59hFwO9CR3+jGykQUT0HXGhxN4tWe70bluCIv3AfgOfMC4FiAfligyKu+aYqewUzHNowfCiks3zMrwKXKTTYdl18HNrDau7G9fv6DO3k4gMhWPA5Kn5FopufJAO+4olfpGsth1GN7JHLG6fkLf6F3PZEnT6TEaDACjn2K1S0qDFmY894TA+mMykNHTJNSAWI0F5wwuo0m8TgYARt++c4ulMddRxfi6F+9YWOR+ot6fKxbXNw8+anzq43Scsncn33PnJC8oiWZIlAbqDqc29LQ== 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: Hi, Jason. Thanks for the feedback. On Tue, 2024-10-15 at 09:17 -0300, Jason Gunthorpe wrote: > On Tue, Oct 15, 2024 at 01:13:22PM +0200, Thomas Hellstr=C3=B6m wrote: > > Introduce a way for hmm_range_fault() and migrate_vma_setup() to > > identify > > foreign devices with fast interconnect and thereby allow > > both direct access over the interconnect and p2p migration. > >=20 > > The need for a callback arises because without it, the p2p ability > > would > > need to be static and determined at dev_pagemap creation time. With > > a callback it can be determined dynamically, and in the migrate > > case > > the callback could separate out local device pages. >=20 >=20 > > +static bool hmm_allow_devmem(struct hmm_range *range, struct page > > *page) > > +{ > > + if (likely(page->pgmap->owner =3D=3D range- > > >dev_private_owner)) > > + return true; > > + if (likely(!range->p2p)) > > + return false; > > + return range->p2p->ops->p2p_allow(range->p2p, page); > > +} > > + > > =C2=A0static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long > > addr, > > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long end, pmd_t *pmdp, > > pte_t *ptep, > > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long *hmm_pfn) > > @@ -248,8 +258,7 @@ static int hmm_vma_handle_pte(struct mm_walk > > *walk, unsigned long addr, > > =C2=A0 * just report the PFN. > > =C2=A0 */ > > =C2=A0 if (is_device_private_entry(entry) && > > - =C2=A0=C2=A0=C2=A0 pfn_swap_entry_to_page(entry)->pgmap->owner =3D= =3D > > - =C2=A0=C2=A0=C2=A0 range->dev_private_owner) { > > + =C2=A0=C2=A0=C2=A0 hmm_allow_devmem(range, > > pfn_swap_entry_to_page(entry))) { > > =C2=A0 cpu_flags =3D HMM_PFN_VALID; > > =C2=A0 if > > (is_writable_device_private_entry(entry)) > > =C2=A0 cpu_flags |=3D HMM_PFN_WRITE; >=20 > This is really misnamed and took me a while to get it. >=20 > It has nothing to do with kernel P2P, you are just allowing more > selective filtering of dev_private_owner. You should focus on that in > the naming, not p2p. ie allow_dev_private() >=20 > P2P is stuff that is dealing with MEMORY_DEVICE_PCI_P2PDMA. Yes, although the intention was to incorporate also other fast interconnects in "P2P", not just "PCIe P2P", but I'll definitely take a look at the naming. >=20 > This is just allowing more instances of the same driver to co- > ordinate > their device private memory handle, for whatever purpose. Exactly, or theoretically even cross-driver. >=20 > Otherwise I don't see a particular problem, though we have talked > about widening the matching for device_private more broadly using > some > kind of grouping tag or something like that instead of a callback. > You > may consider that as an alternative Yes. Looked at that, but (if I understand you correctly) that would be the case mentioned in the commit message where the group would be set up statically at dev_pagemap creation time?=20 >=20 > I would also probably try to have less indirection, you can embedd > the > hmm_range struct inside a caller private data struct and use that > instead if inventing a whole new struct and pointer. Our first attempt was based on that but then that wouldn't be reusable in the migrate_device.c code. Hence the extra indirection. Thanks, Thomas >=20 > Jason