Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp633414ybm; Wed, 27 May 2020 04:22:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4ZDiBesXshVq0x1P8ExM7C2w3YWHXYbh+0DoE1viPgOrCc/F3r2U0a3rOwXs7iO4GU2RV X-Received: by 2002:a50:ee1a:: with SMTP id g26mr22874565eds.18.1590578553367; Wed, 27 May 2020 04:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590578553; cv=none; d=google.com; s=arc-20160816; b=rwRNnNI52SsK81+22fxbPHfuCxQIAmdWCnidspFpObggqm+ZHKLtIArakRTVIVCCLG v66f4PKxjMBKZcipRi9u4VVHrROoqKqSiwH3b3JQBbU4/k9yV6li2XY7KgN44VO2gdTm VlCEFQe19ttbE8QoHcq+FmcSR/lyX1hhxZOWH+OlEbVFsOSDCCUQck2nPSeuXyrEF1+n d8Z7HDU0Rl+buaJYBDe9IPGVR6MQzYrDhdh0RMLIhI3KdgoRHOEg4EdX0lmOThtIGcH0 7oPlwtgrog5tDDDBiheq0rfu4dXFucvCT79t1oXnhchL2MxqLrhU3dT6KLjhqIuLVMe1 U+xQ== 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=VqFFiZfGTbc8P2V8UkxE4/9YOD3nXn4RELpwJoqQ81I=; b=EwY1LlHGidi2Gn0QgMai0CUJFBu5pnRoLFhUGkPWKDQMQ/+1p7GOcLWr2BOETiF2Og yLZbI1Gzl+NtzrpDngWJ482Ahk9Q9GLh61P0Rc3Ga4+yxcPhyQHQYwGFGq7W7MezFL84 XUYzp2OWRg3W26H/ZYU8MYQwP+L1lQ3pGewFAivvRsfn2dUCqDCNwCH2Mhw2DgaKGfv+ EPG8AWXdDaJU6rLWoDlqO7WokUDO7gYXNd92xkxghZzQJcM5PYfV5zWxmAX5jjv/xw0R +8rdVbd2CUlvUzpDJ/XCcYexLn0knlyYrqgOa1k9agBTsVolCRd8iYzF+qXz0H13qv+A XsJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=EMK4bcnQ; 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 be4si1420434edb.610.2020.05.27.04.22.10; Wed, 27 May 2020 04:22:33 -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=EMK4bcnQ; 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 S2388277AbgE0Is5 (ORCPT + 99 others); Wed, 27 May 2020 04:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388227AbgE0Is4 (ORCPT ); Wed, 27 May 2020 04:48:56 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D97FC061A0F for ; Wed, 27 May 2020 01:48:56 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id q11so11028610wrp.3 for ; Wed, 27 May 2020 01:48:56 -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=VqFFiZfGTbc8P2V8UkxE4/9YOD3nXn4RELpwJoqQ81I=; b=EMK4bcnQ7/+Q5MfW9rh9+O6CGjH+D8d4W+4xa0rWGd2pgNmC1N2cxia66QgtL8hkJ6 kVJ283VUAzpEMylrepZH+71qgNpQvQ36boHdljw3jencpgVYymWr5N1wvioH4/r5ZMfW vLdRrBL31nK8Ib/W5DsqFKci93EFPmviaeEmI= 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=VqFFiZfGTbc8P2V8UkxE4/9YOD3nXn4RELpwJoqQ81I=; b=GMumykCDkamm/QxFtk9dFlsB2iEhHkqhRV9n7K4YzL21Nl4tf+z51kLF0fB3iozywB MS4VaGG3AAm3UAOho4Ckpgge+CzEd52RnQfTv7FYrVyqXifDXsgCy7WKr7Yl13SxlEjS wDxCMD0+ASsPK5EuVtQy1PqcRWXSyt9ekJy5G07zQU/Vr9dl1AW4ZUGM8+5Wsm3AAmHQ q0hmTDpF2jJiB9y/Ss4E9eJQkmlnb6MKPoI2FTSgVQ3KsnWff/6YK3bTQJPie79O6dv0 lIOg4QxtIuBysB+Jrl2huL0A7RiV4B7WGkQnJhyxqJ/wCbCgeDubyeiNw64aI6eGgfFk RolA== X-Gm-Message-State: AOAM530WaTZYuMemyZPvfj+x+ZSmgKXdfXOSJitwj5l2O7w7ulLtdjmx Ps8dJO4DTNB5lRmZnzy8YRoGwA== X-Received: by 2002:a5d:608d:: with SMTP id w13mr23428615wrt.298.1590569334883; Wed, 27 May 2020 01:48:54 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id 1sm2112167wms.25.2020.05.27.01.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 01:48:54 -0700 (PDT) Date: Wed, 27 May 2020 10:48:52 +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: <20200527084852.GN206103@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <69a033cf-63b2-7da6-6a5e-a5bbc94b8afb@nvidia.com> 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 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. 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