Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp563492ybi; Sat, 15 Jun 2019 06:57:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyrQV8Yv90c8cgO9wisQWjQVOMkfNMQAlhLJAUkxeFK4/rEn1ryA6yir1koTL3O3QdYV0Wk X-Received: by 2002:a17:90a:480d:: with SMTP id a13mr15925979pjh.40.1560607059359; Sat, 15 Jun 2019 06:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560607059; cv=none; d=google.com; s=arc-20160816; b=pq48utsJh4PNgXiwoP7zSCUgG4aELUa20FgRwk9ztDbT6jYhp488fYl8BYwG511Wwa pfggwuWVRgGXJ8+5Nu68jt6Oai644o/D5BtQqKVQzw3jr4rlFrwtvJvKkPFpo3k/RYWP WNscJpFLMMWmnD3fLP6a2ZtfC5wgNnSM4ok+2sIvc9pKOIhh1kX9U/mk1qbMlfFoAl1S b+Xs+s1EQl0R8pNfwHR4S24Fak5cWjlGcpcuIdoUkGkZUVAmzQhDTZK0VzsueAKEyPB8 sWOfxFO+5GfCAcZfosgsy/9q5p/nQ6nTLIPnnvYaZDnH/R1b7GkL0mr23dt0ZaCX9/LW 7ycQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=QHCR3JSgS0RSHcF2VNdae/EolEZLrPS/qHWaU1BJy7I=; b=ZQ68WlXNlWxVwQhGqz0oA+P4uRT71zg775DMGuZbTVkUdTll49CvpoStmAaqG0NwRi GXHOrnsTPKhDhi3phHQJM92gKkgMpiwFQuyhKV+W9e5awq0haRHj/XOV0bQfxxVubbAt a5ZrNpEKAmQqZ5KhJuZcTvLwmzfbLDrfyy4bShTHXRCY2ZYl4IAy0QL4wLNDcetxYqg5 gkJKikCoxYTzVbFoZjwVDURHHUP4MQTIdXfIqugPWoFwL6y9yoyqzYy7p9+2jNAQuj9D tVb8wyhO9TdAjzGv9H8ShxYCXMFsS2MHowt/jSFihD5+zfz+XsNE31Vgg3RwraQDA1ja pYug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=eqKeNfV0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si5250749pgs.312.2019.06.15.06.57.22; Sat, 15 Jun 2019 06:57:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=eqKeNfV0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726703AbfFON4k (ORCPT + 99 others); Sat, 15 Jun 2019 09:56:40 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:40296 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726236AbfFON4k (ORCPT ); Sat, 15 Jun 2019 09:56:40 -0400 Received: by mail-ot1-f67.google.com with SMTP id e8so4336803otl.7 for ; Sat, 15 Jun 2019 06:56:39 -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:content-transfer-encoding; bh=QHCR3JSgS0RSHcF2VNdae/EolEZLrPS/qHWaU1BJy7I=; b=eqKeNfV0/DKNowmDgDytbRxKZe/YIBslrcI+/6UoW6VrIQ4IXERd15SuP4HEEcg941 umwYW8yVMX0fH5rPsS/8iFnnYX4ETfea2MKPxtaeV5ezaDMj8CoGpnSE2rPwoSlgtmfb qGCQ6MDTBLprBStkIIHLT16NSSx+g4XaelLxw= 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:content-transfer-encoding; bh=QHCR3JSgS0RSHcF2VNdae/EolEZLrPS/qHWaU1BJy7I=; b=IYd2AD6JKZrY+ZbHEMMFfzbG78fDcP18s9OQSQ+KlFCOOqZ/4ltZPQulNagXZ2iXlu vdJI4NhR5VXUGtNardXRqkgCTlJth6N+Fc2U90dbHmrpuOx7lZ8S3AJmoZcjbtX2Moo0 BpcnregTNgFetWn6KgdDCRGGbR8mizLegxXjCbTvwYJ+O3rHNjaWcG1eDBBkZc8tZaUM ydFYZ42DZOtZIlyZbwYlPctc9GYgABajLkybwMNLzNJ4EM24IOotoAu7+Iczh3tKUoA1 4wYkzekIYOdBMlEwZw6NIems/oiz/a0Qd+F8d9Yqlo3R18VWl+dW9rhNef5+5Rc3/gpt kIsw== X-Gm-Message-State: APjAAAUW116yWy+r5rTM0PS1zz+PGI5yGOtrsykx89V9DtGisDS4Cjlo vVhg0vSG0pmrkJSMhmN4MwbzFPxu3e7zeFOUP9Giqg== X-Received: by 2002:a05:6830:ce:: with SMTP id x14mr34286891oto.188.1560606998809; Sat, 15 Jun 2019 06:56:38 -0700 (PDT) MIME-Version: 1.0 References: <20190614124125.124181-1-christian.koenig@amd.com> <20190614124125.124181-4-christian.koenig@amd.com> <20190614131916.GQ3436@hirez.programming.kicks-ass.net> <20190614152242.GC23020@phenom.ffwll.local> <094da0f7-a0f0-9ed4-d2da-8c6e6d165380@gmail.com> <20190614203040.GE23020@phenom.ffwll.local> In-Reply-To: <20190614203040.GE23020@phenom.ffwll.local> From: Daniel Vetter Date: Sat, 15 Jun 2019 15:56:25 +0200 Message-ID: Subject: Re: [PATCH 3/6] drm/gem: use new ww_mutex_(un)lock_for_each macros To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Peter Zijlstra , Lucas Stach , Russell King , Christian Gmeiner , Qiang Yu , "Anholt, Eric" , Thomas Hellstrom , dri-devel , Linux Kernel Mailing List , The etnaviv authors , lima@lists.freedesktop.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 14, 2019 at 10:30 PM Daniel Vetter wrote: > > On Fri, Jun 14, 2019 at 08:51:11PM +0200, Christian K=C3=B6nig wrote: > > Am 14.06.19 um 20:24 schrieb Daniel Vetter: > > > > > > On Fri, Jun 14, 2019 at 8:10 PM Christian K=C3=B6nig wrote: > > > > [SNIP] > > > > WW_MUTEX_LOCK_BEGIN() > > > > > > > > lock(lru_lock); > > > > > > > > while (bo =3D list_first(lru)) { > > > > if (kref_get_unless_zero(bo)) { > > > > unlock(lru_lock); > > > > WW_MUTEX_LOCK(bo->ww_mutex); > > > > lock(lru_lock); > > > > } else { > > > > /* bo is getting freed, steal it from the freeing process > > > > * or just ignore */ > > > > } > > > > } > > > > unlock(lru_lock) > > > > > > > > WW_MUTEX_LOCK_END; > > > > Ah, now I know what you mean. And NO, that approach doesn't work. > > > > See for the correct ww_mutex dance we need to use the iterator multiple > > times. > > > > Once to give us the BOs which needs to be locked and another time to gi= ve us > > the BOs which needs to be unlocked in case of a contention. > > > > That won't work with the approach you suggest here. > > A right, drat. > > Maybe give up on the idea to make this work for ww_mutex in general, and > just for drm_gem_buffer_object? I'm just about to send out a patch series > which makes sure that a lot more drivers set gem_bo.resv correctly (it > will alias with ttm_bo.resv for ttm drivers ofc). Then we could add a > list_head to gem_bo (won't really matter, but not something we can do wit= h > ww_mutex really), so that the unlock walking doesn't need to reuse the > same iterator. That should work I think ... > > Also, it would almost cover everything you want to do. For ttm we'd need > to make ttm_bo a subclass of gem_bo (and maybe not initialize that > embedded gem_bo for vmwgfx and shadow bo and driver internal stuff). > > Just some ideas, since copypasting the ww_mutex dance into all drivers is > indeed not great. Even better we don't need to force everyone to use drm_gem_object, the hard work is already done with the reservation_object. We could add a list_head there for unwinding, and then the locking helpers would look a lot cleaner and simpler imo. reservation_unlock_all() would even be a real function! And if we do this then I think we should also have a reservation_acquire_ctx, to store the list_head and maybe anything else. Plus all the code you want to touch is dealing with reservation_object, so that's all covered. And it mirros quite a bit what we've done with struct drm_modeset_lock, to wrap ww_mutex is something easier to deal with for kms. -Daniel > -Daniel > > > > > Regards, > > Christian. > > > > > > > > > > > Also I think if we allow this we could perhaps use this to implement = the > > > modeset macros too. > > > -Daniel > > > > > > > > > > > > > > > > > This is kinda what we went with for modeset locks with > > > > > DRM_MODESET_LOCK_ALL_BEGIN/END, you can grab more locks in betwee= n the > > > > > pair at least. But it's a lot more limited use-cases, maybe too f= ragile an > > > > > idea for ww_mutex in full generality. > > > > > > > > > > Not going to type this out because too much w/e mode here already= , but I > > > > > can give it a stab next week. > > > > > -Daniel > > > > _______________________________________________ > > > > dri-devel mailing list > > > > dri-devel@lists.freedesktop.org > > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel > > > > > > > > > > _______________________________________________ > > dri-devel mailing list > > dri-devel@lists.freedesktop.org > > https://lists.freedesktop.org/mailman/listinfo/dri-devel > > -- > Daniel Vetter > Software Engineer, Intel Corporation > http://blog.ffwll.ch --=20 Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch