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.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 BDC62C47420 for ; Wed, 7 Oct 2020 21:51:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50E8020882 for ; Wed, 7 Oct 2020 21:51:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="RYITGyTp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728777AbgJGVvC (ORCPT ); Wed, 7 Oct 2020 17:51:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728738AbgJGVvB (ORCPT ); Wed, 7 Oct 2020 17:51:01 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6EF1C0613D3 for ; Wed, 7 Oct 2020 14:50:59 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id m128so4128216oig.7 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=G2/UgK46rnj/gWmpK3FoDy94hkXbRGbuaD0Z1KoWw+0MwWxFnD7uJkO/HC2MVM3Hos TgS+B+n8zn6Dn76iXrJSPwb7ug4APgoYIidWIufele8DTYuPfSxmVhf9LEWc6HEved+m H4hRZyaSMcukyQQfTfONgFtzUl9Vc6o3dLgEVN/WfBA7Q5rI0oMdtSxPaa8RPVS630vC 0PvZnp1nh+qPGzluqCvzbjdp260FhE3daNXzLKrxz4E6vh6Ipizn8D+fRqLaQyuHtrQD AT8ZSxAEt5x3CdzUM72T59vvmupuBeatCeZoM1bvHkXO19BRlyG9O5PElZyEe+fsEynR NWlg== X-Gm-Message-State: AOAM533uf2ZJBypKZZHCP8hQKtCwctcrXWSMpgADNUUPsR4JZoTMIWfq HyE0Wkm2Frh10nrkWw17b8FkzgsKjsOiB0lU6qP3kg== 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 Cc: DRI Development , LKML , kvm@vger.kernel.org, Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , linux-s390@vger.kernel.org, Daniel Vetter , Jason Gunthorpe , Inki Dae , Joonyoung Shim , Seung-Woo Kim , Kyungmin Park , Kukjin Kim , Krzysztof Kozlowski , Andrew Morton , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Dan Williams Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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=-4.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 90B62C4363D for ; Wed, 7 Oct 2020 21:52:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 191CC20882 for ; Wed, 7 Oct 2020 21:52:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="T4cYk/6b"; 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 191CC20882 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZjKgn1JbKAMbON98Swyy1M8rLLQoqZhg3mr2tdVYQx4=; b=T4cYk/6btyBjEPmRj8tV5gGkN hpTwYlbM+yaKx1Va+SPLsKiqZDiPDYgmptbLrkLSjVZCLvKwOT3WWQdkOBD202Z6fieThjPZ2Hyc3 Z8yn8uNHIPHwwvvQgUb2sUk5oRnHxFbFHshqhZelQvRPFDxHuwF+2qknVQld0Z4vIpbS8+FAks/CC dMN1asHZZmo0DPA9cXzpfiDO8yf6pq0uZwj29ukV1haWeIu9wfdbpJdMyN+ydH1LKV4ei7Cy5IMSY tpnwKqcJnBgnBA691pvFfUHM403wdDPgiBg7nuqCbi5A84xfYdY7DTUgygkIDzG2xuBIhWqczgYv0 t2unswgCg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQHKy-0001MR-8T; Wed, 07 Oct 2020 21:51:04 +0000 Received: from mail-oi1-x241.google.com ([2607:f8b0:4864:20::241]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQHKu-0001L7-Vz for linux-arm-kernel@lists.infradead.org; Wed, 07 Oct 2020 21:51:01 +0000 Received: by mail-oi1-x241.google.com with SMTP id c13so4136597oiy.6 for ; Wed, 07 Oct 2020 14:51:00 -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=EPJKG+WbZTFT7okoj/XSfqHzJsEa7MLbHAQYQjKOyt1KdhE74ZnnFKP393d0avDOP/ dyPY/VnE01IYHflqMEhb5eOY7l1MEN4dySNDJNdPagg3ZKxq/XaqDAq7iisKTl1xmlk8 dmnS+nXcc7yhgIiPnKoQIEWAR+nTadKwlN2YDebjk06SLiH9l+uDNosQeAXtmMiVCkSo 8dZ2S2BRi6v2L9umlh5Zr+jLQ8TQIFBvCDnds4P0NRuZvR3LbdnFg2SYgH5TKVB27j/A 7/gf2/XmtKKralXo9WQ7bwlhJrn7Pp4BwTyiQl60VhfPH+6NsaJSbkyC3rBxSSnzOSqy 8dkA== X-Gm-Message-State: AOAM5309eZyGP8ZIEjW7pjdT6xmrFX9CA7bubpni9gZQOCufSWeTbS++ 1DjG1Z0IkIwSTglokRzRduLBQs0xqAzYKqWjqe6GSA== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201007_175101_032015_877F05E7 X-CRM114-Status: GOOD ( 22.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 , Inki Dae , 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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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