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 X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A48C2C4741F for ; Wed, 7 Oct 2020 21:51:02 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2CC19215A4 for ; Wed, 7 Oct 2020 21:51:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="RYITGyTp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2CC19215A4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7681F6E9BC; Wed, 7 Oct 2020 21:51:01 +0000 (UTC) Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id EACAD6E9BA for ; Wed, 7 Oct 2020 21:50:59 +0000 (UTC) Received: by mail-oi1-x244.google.com with SMTP id n2so4188002oij.1 for ; Wed, 07 Oct 2020 14:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dWGCIOydys/PVXDkI8D7/WYJ3+tXIlDPLmJQQeojkP4=; b=RYITGyTpDQrhaTy45WCQWB7S0cwfaHHh3OpiGBmEPf/5Sn9SZhBTUrfuBI5sApAVCz T91G4l95cIiLFkCFoy02NhuBItioeoq67OA++h3qBN6BlQdZ2cpqUetUKAyKzW4kFQ0w 5Qtqca0SmLP0UhiDont79zDLISy/mkOvxYGHE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dWGCIOydys/PVXDkI8D7/WYJ3+tXIlDPLmJQQeojkP4=; b=GpTSPZ8oBsxJTsy2YxzHdnATG4fF45QpNpewxjSveNlboY8S4g/ASWvMyI1j8RazTV uRQeBzJNMB2xbzPp9soQxf77Tq9W8+QtVGlc6oFrjjwHuT2/84PkAToMA9aqqG0acc/f 8ehfk1Oju6uHzb4EbPCdCW6iSmebHBiQfK03PFnQHOgDh940AaVQI477TwRb4Wmasw0X ADHzqzkI5gWHkoh4kPMLN51rTihn0Y73ElgmCx3rrbuQ2W5zZsfODis9YN1zZTUau9pF +bfB5jbVWlX74OdNth8Vazh4urk1bleYGvpj8MmaD2DRDLhr723qU1heBvGi8nmVvPt5 PAKA== X-Gm-Message-State: AOAM533CEKrR5CKNgahT1Is5CZ6hIz54PsokyqbxhLidW49V9IoGofCZ wbq0E2x+rG40yO+2VqtreOL+xepysyoIl5ltf+Ft1jJRJC64YA== X-Google-Smtp-Source: ABdhPJywVeOO6ZiDQcLcwu4Td5CgpCTJ9U8XcX1hFxhlIWItjEaKhv17whEr41y9mEAabwbRCVa0NcIfbphA+xnz5sQ= X-Received: by 2002:aca:6083:: with SMTP id u125mr3249940oib.14.1602107459110; Wed, 07 Oct 2020 14:50:59 -0700 (PDT) MIME-Version: 1.0 References: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> <20201007164426.1812530-2-daniel.vetter@ffwll.ch> <80718789-b3de-c30a-03c5-7c8cbf41f7d9@nvidia.com> <895eb064-1c8f-ecfc-0a98-1fbe40cb3161@nvidia.com> In-Reply-To: <895eb064-1c8f-ecfc-0a98-1fbe40cb3161@nvidia.com> From: Daniel Vetter Date: Wed, 7 Oct 2020 23:50:47 +0200 Message-ID: Subject: Re: [PATCH 01/13] drm/exynos: Stop using frame_vector helpers To: John Hubbard X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , linux-s390@vger.kernel.org, linux-samsung-soc , Jan Kara , Joonyoung Shim , kvm@vger.kernel.org, Jason Gunthorpe , Seung-Woo Kim , LKML , DRI Development , Linux MM , Kyungmin Park , Kukjin Kim , Krzysztof Kozlowski , Daniel Vetter , Andrew Morton , Dan Williams , Linux ARM , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Wed, Oct 7, 2020 at 11:37 PM John Hubbard wrote: > > On 10/7/20 2:32 PM, Daniel Vetter wrote: > > On Wed, Oct 7, 2020 at 10:33 PM John Hubbard wrote: > >> > >> On 10/7/20 9:44 AM, Daniel Vetter wrote: > ... > >>> @@ -398,15 +399,11 @@ static void g2d_userptr_put_dma_addr(struct g2d_data *g2d, > >>> dma_unmap_sgtable(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt, > >>> DMA_BIDIRECTIONAL, 0); > >>> > >>> - pages = frame_vector_pages(g2d_userptr->vec); > >>> - if (!IS_ERR(pages)) { > >>> - int i; > >>> + for (i = 0; i < g2d_userptr->npages; i++) > >>> + set_page_dirty_lock(g2d_userptr->pages[i]); > >>> > >>> - for (i = 0; i < frame_vector_count(g2d_userptr->vec); i++) > >>> - set_page_dirty_lock(pages[i]); > >>> - } > >>> - put_vaddr_frames(g2d_userptr->vec); > >>> - frame_vector_destroy(g2d_userptr->vec); > >>> + unpin_user_pages(g2d_userptr->pages, g2d_userptr->npages); > >>> + kvfree(g2d_userptr->pages); > >> > >> You can avoid writing your own loop, and just simplify the whole thing down to > >> two lines: > >> > >> unpin_user_pages_dirty_lock(g2d_userptr->pages, g2d_userptr->npages, > >> true); > >> kvfree(g2d_userptr->pages); > > > > Oh nice, this is neat. I'll also roll it out in the habanalabs patch, > > that has the same thing. Well almost, it only uses set_page_dirty, not > > the _lock variant. But I have no idea whether that matters or not? > > > It matters. And invariably, call sites that use set_page_dirty() instead > of set_page_dirty_lock() were already wrong. Which is why I never had to > provide anything like "unpin_user_pages_dirty (not locked)". > > Although in habanalabs case, I just reviewed patch 3 and I think they *were* > correctly using set_page_dirty_lock()... Yeah I mixed that up with some other code I read, habanalabs is using _lock. I have seen a pile of gup/pup code though that only uses set_page_dirty. And looking around I did not really parse the comment above set_page_dirty(). I guess just using the _lock variant shouldn't hurt too much. I've found a comment though from the infiniband umem notifier that it's sometimes called with the page locked, and sometimes not, so life is complicated there. But how it avoids races I didn't understand. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel