Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp874203rwl; Wed, 12 Apr 2023 05:28:45 -0700 (PDT) X-Google-Smtp-Source: AKy350azqK0gICgXujxut5pq1PmoV3xSK/rT1iQgdWvwm07EFwetlSUJ33OK9p8EADhT4wmfh9bW X-Received: by 2002:a17:90b:388b:b0:246:aca1:b444 with SMTP id mu11-20020a17090b388b00b00246aca1b444mr12606956pjb.33.1681302524919; Wed, 12 Apr 2023 05:28:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681302524; cv=pass; d=google.com; s=arc-20160816; b=0JRNKqgv8mAbyES3gMxyNgImDKI9De4rLQ4qPIE9v5nhoWSKNROlL10JeR+sM4TZxR O9M7jqa18JfPbOeKB5YUaDi+S0C5ovn2s/7g6se225XG5IPgcvJOviGsASqOgut2jJ7U fdhjW1ciO5L79xWYBJd+UnSsle8R/txtQ/7nxEs7NWwSK6GyOCbPEA7DGQCE4ZDnlljv 6WMDcJfjlwao1Azvou30QFgDFJJf4OKGJDwLMF9Z7OaH/poxYs9HgYrQv7ep+NOxDY2c y9ugmC8YSy1j9hDk9sl+VhP2dSUayEVrvwRw3G27cfiSXt52WqKhd35Sh3jNchh3JNHh +gRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=XzoBGlPyz/0C5YDqIrsoGmTxY3u6xzR1KsHab1lvDnQ=; b=S3HbIPxNVr4rjz4LBQliOSPdTAtmkWrp/kkgW+eEC3Nscq4tHQucEvhV/u6Mi4UKeo M2zF2v3Y200KWPKzuemBagZTb3oVmfqACkbbPORPmABitdLhGPfzFbO1+NIkRpLCw2dC RJM1ivV+drN32NG3/PXiMzB2BCLyc8DpYjdH8QfvMh60IOMen3NXLlDIhqVfldvCfEW5 2rRPHvaTQXdeN/KHi+Y28qnPPeJ101xR9exC1gskK2hKM0vXN8P4KcKTdzjWFRsWibAK yERj/7aapyzQYxTSMbRu36nFQa+4eH9HZtUqBOuFV7bAee1Larzx8civoaY5xdIZWdKN KJRA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=dd31rVTh; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l4-20020a17090a850400b00240cf599d83si1790346pjn.144.2023.04.12.05.28.33; Wed, 12 Apr 2023 05:28:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=dd31rVTh; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229853AbjDLMNn (ORCPT + 99 others); Wed, 12 Apr 2023 08:13:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbjDLMNm (ORCPT ); Wed, 12 Apr 2023 08:13:42 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2058.outbound.protection.outlook.com [40.107.244.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECFFA30C8 for ; Wed, 12 Apr 2023 05:13:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iQh68MQGAIBBMLxLArZ/MYGyR/7jV2ahWklfU8buF7fdbiDmxCc+2bVubskbnBFOJK7GXd7QP7nwv+01FZe8aaCALcvQgPK66Up/FS/cA1SHj55S8gkYH3s0RPvucN5r/cJs/iqiDpUq3YTiK/x//X7OVTGhx7/eEiUo5GEKPEZrT2C7kFzvmym16na7xkg7LYhwcpb+bC/SWIgS1WGSk1UkKoBUNpgUiobWhywNdtkKOa54sww9cacNTXVCz0g7LgsdexVkS9j1REz84LxTmjQxjeaim+GWiYY6Og4u6aZvvFHnnWKPWSmjxqbFX8E6e0pBe1yP0KxO3KarRRk9kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XzoBGlPyz/0C5YDqIrsoGmTxY3u6xzR1KsHab1lvDnQ=; b=a9qTgYhMImnmNmLdB1uXt9AIthzsSbGRUFySzxiKe6vWZkfHlmuOFJl0tpDEm+VIBFPnuZ7K6px/BvISJudYN90Ljc3kemhJpq5zz7dP6xtcHDU6X2BDKamjlOEXbYdzPrkAMTsKnJ5rJAk62CvsWkWTobaZ1W+FdFkkhhSnNwNDj5PEcxR2jwxSiIHAkvhYvUNrqYyp1PRnMnp0lzVJBF4eoFLGfVgMAbqTin797IbY893DO6IUNMMp5+bmJkW/gxPgSsllNDsXPonJ42on9mClKlmdeBn+Egu/7n4bfYq8XaFVPgw8ZpCEO/GjTEMcBU+WQ1Bl/v57fVwba2WSvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XzoBGlPyz/0C5YDqIrsoGmTxY3u6xzR1KsHab1lvDnQ=; b=dd31rVThoj1FBohtSSdhX/x3LARm/zbFJQwmBfOHV4ClNzq3dtN1ckrF0+UfCdXAw0WSS3i3i4tGEgnq3f6vUhHDFdywW1oFYpKYFMKfxRFum/x2RJcZbPhzraIZsj8swCcR6jatJi+oo5SwF6GsehLkeFBCyA1OdUltWGhoBp4= Received: from PH0PR12MB5606.namprd12.prod.outlook.com (2603:10b6:510:141::16) by MN2PR12MB4221.namprd12.prod.outlook.com (2603:10b6:208:1d2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.30; Wed, 12 Apr 2023 12:13:38 +0000 Received: from PH0PR12MB5606.namprd12.prod.outlook.com ([fe80::2aa9:44d8:ff48:164a]) by PH0PR12MB5606.namprd12.prod.outlook.com ([fe80::2aa9:44d8:ff48:164a%4]) with mapi id 15.20.6298.030; Wed, 12 Apr 2023 12:13:38 +0000 From: "Teterevkov, Ivan" To: Jan Kara CC: Alistair Popple , "linux-mm@kvack.org" , "jhubbard@nvidia.com" , "rppt@linux.ibm.com" , "jglisse@redhat.com" , "ira.weiny@intel.com" , "linux-kernel@vger.kernel.org" Subject: RE: find_get_page() VS pin_user_pages() Thread-Topic: find_get_page() VS pin_user_pages() Thread-Index: AdlsqyEC2Ib370amRP6esQRt2dSqSwAI4d6AABNzQCAAA7uWgAACkwJA Date: Wed, 12 Apr 2023 12:13:38 +0000 Message-ID: References: <87mt3ehti4.fsf@nvidia.com> <20230412104151.hkl5navnaoc7l7ob@quack3> In-Reply-To: <20230412104151.hkl5navnaoc7l7ob@quack3> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH0PR12MB5606:EE_|MN2PR12MB4221:EE_ x-ms-office365-filtering-correlation-id: abeb72f1-6708-438a-e2e4-08db3b4f58d0 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dWV+gixsKpjCSNJ4H/llWfYnPKpgnflVcasq653XLewj3BTLqW0VIma0G4mZD/Y/rZLFezR6NixZ14trfUKnYLuKn23XAM7+V+4v8HcmT1p+oP0Y0mHg7ocn+vKbzkmhPCXUdgIb1igtJpLIpx8crszkpbPRGX0TC9/DTJt6aW/KqmZOaBwISZi2UWahZeis907BadcgvZGq7Gd6hpRgrEN3qGk9w+pbur9PEQGMSeZM4SBtLaz/1m9w0iQL32pU4CBhewF5fSKNdhw12MOfOc9g+ysb/y3RBiG9I52TOkw2ccbHNO8ij/oAKZh/FHd3k5owtG44dZe0qgkCe5WPyAVREMfiWluQz2u5z9w1MojyMnQgTTuzKZdWR8xAvPZaHtz5TCYLn1ccImyXEr2OKpvgNh+3sMe+9UeIFKhzCpr3B88s46bNzJgk7ae+2I5Oo3PGvJoybSx8JgDgC8w7N3DIaWe+nLcc59+rrMbLyNcQcFhF19C94Q6unlt5+HkNKkfJh5XwGcu9XyFn+CEHNiCP63MCbiaNDXIePGIMpOJ15AVW9b/ztLNvmc6NcCdGLCeYlNOEzah6z7Zf7CBkz56G68yvY30y29jhVNup4RXPjM9fcbmoiODAP8UhCogM x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR12MB5606.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(39860400002)(136003)(396003)(366004)(451199021)(122000001)(83380400001)(41300700001)(5660300002)(2906002)(52536014)(38070700005)(38100700002)(8676002)(8936002)(186003)(9686003)(6506007)(26005)(66899021)(66556008)(4326008)(64756008)(6916009)(71200400001)(7696005)(66446008)(66476007)(54906003)(66946007)(86362001)(76116006)(55016003)(316002)(478600001)(33656002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?swzfvSn2WzVyPGcSazLjlzBCCBK1aMD4OgmP0iUiSEH2O5WeDskSbcNdap1v?= =?us-ascii?Q?8kz6hVJRx1g7Ftp8nQBPHmawIOEW7iwcMPutPwhsTCUFqKfi3KlGQv2+TxO9?= =?us-ascii?Q?z8ykuHFm4D+sTj2yf7r5i4x9ih69lj+QReHLQTwqxhfP7Ga/BP9asHHteiXa?= =?us-ascii?Q?JFod5MAtsJrSeSlrHL1/mOew3nwykucWldfxd2G2KoocB4+OnIe1tFw0y0pN?= =?us-ascii?Q?oE/xKQLf3A+hwmaoSM+n9saSCwOGzwuQGcSX9kyTK82EPIfTmwo36CONjTrZ?= =?us-ascii?Q?NAjGucF3JXZdUx4eIj3HxtD8Hxi8//ZTPdU+ec2Lu4nY243mFT01qv/e/5CD?= =?us-ascii?Q?skw1QDeofNX3E3HLspESikmDvFVaB2pjYYPBBwQ+VR9o3AtQs+U5j4HcUWzg?= =?us-ascii?Q?P6SpdyFWj4dVH2QGmJN7MZjB/UJMmOEPQtpb06DBokU6RoliIfYCrNVFpSOD?= =?us-ascii?Q?vLAnd8tRsh5yR/5SW3YuyU6lvBsbzpk1/RKp6638rXaC+RXe63gNG5i9drjD?= =?us-ascii?Q?IB6oaf/rREIoaS6ZhLINnRiwem/IA+i5EmHoZFo53O0edf4K7ckAGNuZnWFd?= =?us-ascii?Q?z3jKkKsj0AMGvfXVtEIpFulJHa8RGrdBbhojUotgF4hbsoOlsXzP4bB11A6o?= =?us-ascii?Q?pDZsxHJ1z7sESKSyDMNtMnC4epNMn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Q?ovjlUj1CNq02MuzjOuM=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH0PR12MB5606.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: abeb72f1-6708-438a-e2e4-08db3b4f58d0 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Apr 2023 12:13:38.1429 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: QIWiz2BNJBxvAW+d5V+bEugHBdZ2Z2LomfCJsyN5yMLD3iXFXJjBPfBm7q6UTWX/f3vPqEVqMndW4eBeE04DWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4221 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara =20 > I'm a bit confused. Above you write that: >=20 > "The memory allocation workflow begins in the userspace, which creates a = new > file backed by 2MiB hugepages with memfd_create(MFD_HUGETLB, MFD_HUGE_2MB= ) > and fallocate(). Then the userspace makes an IOCTL to the kernel module > with the file descriptor and size so that the kernel module can get the > struct page with find_get_page()." >=20 > So the memory allocation actually does happen from fallocate(2) as far as= I > can tell. What guys are suggesting is that instead of passing the prepare= d > 'fd' to ioctl(2), your application should mmap the file and pass the > address of the mmapped area. That's how things are usually done and it al= so > gives userspace more freedom over how it prepares buffers for DMA. Also t= hen > pin_user_pages() comes as a natural API to use in the driver. >=20 I failed to explain that the kernel module might call vfs_fallocate() to allocate hugepages, then find_get_page() and finally dma_map_single(), all before the userspace maps it. Sorry for the confusion. > Now I'm not sure whether changing the ioctl(2) is still an option for you= . > If not, then you have to resort to some kind of workaround as you > mentioned. But still pin_user_pages(FOLL_LONGTERM) is definitely the API > you should be using for telling the kernel you are going to DMA into thes= e > pages and want to hold onto them for a long time. >=20 Changing the application workflow and then doing ioctl() with the address i= s what I ideally want with either find_get_page() alone or vm_mmap() with pin_user_pages() as a workaround, and the latter is preferred. Thanks, Ivan