Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp633936ybm; Wed, 27 May 2020 04:23:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJbe4obpoIkyML0kuZVKJJU8j4Cf/HFkKH1BBuxGAntCDD5Ix7MGHGcMpBvV5YPqThYBkr X-Received: by 2002:a17:906:a88c:: with SMTP id ha12mr5416576ejb.220.1590578593749; Wed, 27 May 2020 04:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590578593; cv=none; d=google.com; s=arc-20160816; b=zHGPDy5t7zOnKIJgwb+kUBfdcXSthHt7nhxl7HEbIJHul0GYvWKv4E4tib6IrVRZS3 H8gWJinLxHZto8jLpCa5ZWl01uYC4jhASgmRQ5D2ep/QAYMat0AiYSVls0KxQhYRVw50 mpP6ABuiB/lhdnwGmhx7Z41d+KpVSM6iNu0XkoaFKIRzMQ7/XYaslvkSdera97rhJDRx tKFfOs5Bp6h/aBNCRe9wnCsgivIGLhuo4gJLxwXzTWs3KjSBPuh8OtNGwfA4Xls+7rF5 OuUjbKdgmndk3d6icddPobWZk2MeaMI/o69ZPD1KQRq5KOKDJcnTFmM3YMgERobZG4Np ocOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:mail-followup-to:message-id:subject:cc:to :from:date:dkim-signature; bh=fhMSWvuNPBXpgKYtNNiDpeOzCXthXUhwfothIO9NKNc=; b=UkvnccGPOUr/DgP798ZXGuyYNGE2blWhlAAoonOiP3fchOL/Zay3pEq2zOWij3F0NV G9gFSpEgKev0F5wS6gkZxtNHfDZRajFsaZ1nTbZ70LRcTR7bd6y2GYjuROvRc0dZVdo+ SmfbsIjP8X/teExGIcA1H+eFKfxXdS3AXxN/n0CIYU9XJogK/JOpxk0x4mbU3atkOaz9 bG/K2sQ3kAop3yDD6Nyi/+hAiQ3SvPltSXH+kfcgAKc2SQVl6dpqtDuowhYwjHgGPaqC yEgKWHTFfnL91EbTGV8CotMq5UC7+8/7Irpaqu73wBPPeGBgQUlIYZ/gB/zFNmkog10b 7kVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b="Xv/iIwQL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt12si2437070ejc.99.2020.05.27.04.22.49; Wed, 27 May 2020 04:23:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b="Xv/iIwQL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388253AbgE0IvV (ORCPT + 99 others); Wed, 27 May 2020 04:51:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388070AbgE0IvV (ORCPT ); Wed, 27 May 2020 04:51:21 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 033EEC061A0F for ; Wed, 27 May 2020 01:51:21 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id r7so6495878wro.1 for ; Wed, 27 May 2020 01:51:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=fhMSWvuNPBXpgKYtNNiDpeOzCXthXUhwfothIO9NKNc=; b=Xv/iIwQLTMFPM9ojjW89x4wU6m1Nk4zxlV2lFYOzK/YeX5SVJ2QS7zKO2ep51C8Idy stbGc0fsYeZ7fht0c/o9lfGLZTtr8jZZBFGQQMOpEetaU5IW4UPpENwNAuCY9GCGjkKW g12dEH4XXpkOyUjPEX3PfxZJomdQ1I72fgCGo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=fhMSWvuNPBXpgKYtNNiDpeOzCXthXUhwfothIO9NKNc=; b=p9EDT/XXRf8dBvaPng9QH9EKqI1sKBkkk0ldt26U5icIA4sork/Il6C9+/7mV00aaW 5n0VdlnYdgH9TKtGOvKv6EBorCJvapcov0ltwzaHGNFD0E1udsXCybK8qd2WSVlIRiTk xyYbF5ycxfw3nC3rVm5a4ARiXoGpgImHx/rKHb9i9LzJbLYhf21YYS0VbzZgGVC2rruA gmxK2YhxrW5B+5vurldxTnrbH84fgRga3z3ZuYGMkLLNDryPIqSiXLAki8Itg6H9oXFJ JSZGy6Pd2NCXWBCEiNSibTdvYD0QZ3wHGLjNXgraiVJI63x+U+86qDzu0gOBmqi4Ki1Q S4JQ== X-Gm-Message-State: AOAM533pcTG8XIcNhsivzQsZalvQQrGxnqV8MxvmIMU0s0OFgarrYuYn GnrlGdtYW58mJnwmFB6suQwsHw== X-Received: by 2002:a5d:4841:: with SMTP id n1mr25171654wrs.64.1590569479666; Wed, 27 May 2020 01:51:19 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id q13sm2157909wrn.84.2020.05.27.01.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 01:51:19 -0700 (PDT) Date: Wed, 27 May 2020 10:51:17 +0200 From: Daniel Vetter To: John Hubbard Cc: Souptick Joarder , alexander.deucher@amd.com, christian.koenig@amd.com, David1.Zhou@amd.com, daniel@ffwll.ch, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drm/radeon: Convert get_user_pages() --> pin_user_pages() Message-ID: <20200527085117.GO206103@phenom.ffwll.local> Mail-Followup-To: John Hubbard , Souptick Joarder , alexander.deucher@amd.com, christian.koenig@amd.com, David1.Zhou@amd.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <1590526802-3008-1-git-send-email-jrdr.linux@gmail.com> <69a033cf-63b2-7da6-6a5e-a5bbc94b8afb@nvidia.com> <20200527084852.GN206103@phenom.ffwll.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200527084852.GN206103@phenom.ffwll.local> X-Operating-System: Linux phenom 5.6.0-1-amd64 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 27, 2020 at 10:48:52AM +0200, Daniel Vetter wrote: > On Tue, May 26, 2020 at 03:57:45PM -0700, John Hubbard wrote: > > On 2020-05-26 14:00, Souptick Joarder wrote: > > > This code was using get_user_pages(), in a "Case 2" scenario > > > (DMA/RDMA), using the categorization from [1]. That means that it's > > > time to convert the get_user_pages() + release_pages() calls to > > > pin_user_pages() + unpin_user_pages() calls. > > > > > > There is some helpful background in [2]: basically, this is a small > > > part of fixing a long-standing disconnect between pinning pages, and > > > file systems' use of those pages. > > > > > > [1] Documentation/core-api/pin_user_pages.rst > > > > > > [2] "Explicit pinning of user-space pages": > > > https://lwn.net/Articles/807108/ > > I don't think this is a case 2 here, nor is it any of the others. Feels > like not covered at all by the doc. > > radeon has a mmu notifier (might be a bit broken, but hey whatever there's > other drivers which have the same concept, but less broken). So when you > do an munmap, radeon will release the page refcount. I forgot to add: It's also not case 3, since there's no hw page fault support. It's all faked in software, and explicitly synchronizes against pending io (or preempts it, that depends a bit upon the jobs running). > Which case it that? > > Note that currently only amdgpu doesn't work like that for gpu dma > directly to userspace ranges, it uses hmm and afaiui doens't hold a full > page pin refcount. > > Cheers, Daniel > > > > > > > > Signed-off-by: Souptick Joarder > > > Cc: John Hubbard > > > > > > Hi, > > > > > > I'm compile tested this, but unable to run-time test, so any testing > > > help is much appriciated. > > > --- > > > drivers/gpu/drm/radeon/radeon_ttm.c | 6 +++--- > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c > > > index 5d50c9e..e927de2 100644 > > > --- a/drivers/gpu/drm/radeon/radeon_ttm.c > > > +++ b/drivers/gpu/drm/radeon/radeon_ttm.c > > > @@ -506,7 +506,7 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_tt *ttm) > > > uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE; > > > struct page **pages = ttm->pages + pinned; > > > - r = get_user_pages(userptr, num_pages, write ? FOLL_WRITE : 0, > > > + r = pin_user_pages(userptr, num_pages, write ? FOLL_WRITE : 0, > > > pages, NULL); > > > if (r < 0) > > > goto release_pages; > > > @@ -535,7 +535,7 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_tt *ttm) > > > kfree(ttm->sg); > > > release_pages: > > > - release_pages(ttm->pages, pinned); > > > + unpin_user_pages(ttm->pages, pinned); > > > return r; > > > } > > > @@ -562,7 +562,7 @@ static void radeon_ttm_tt_unpin_userptr(struct ttm_tt *ttm) > > > set_page_dirty(page); > > > > > > Maybe we also need a preceding patch, to fix the above? It should be > > set_page_dirty_lock(), rather than set_page_dirty(), unless I'm overlooking > > something (which is very possible!). > > > > Either way, from a tunnel vision perspective of changing gup to pup, this > > looks good to me, so > > > > Acked-by: John Hubbard > > > > > > thanks, > > -- > > John Hubbard > > NVIDIA > > > > > mark_page_accessed(page); > > > - put_page(page); > > > + unpin_user_page(page); > > > } > > > sg_free_table(ttm->sg); > > > > > > > -- > Daniel Vetter > Software Engineer, Intel Corporation > http://blog.ffwll.ch -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch