Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4424625ybg; Mon, 8 Jun 2020 07:34:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJDF8rjAGvATnRTD7xZSkAWx81qqWPGH9I9nihPcBoBt2BYbkKXUNHNQOxAy80yjTQh7XE X-Received: by 2002:a17:906:fc13:: with SMTP id ov19mr20778183ejb.212.1591626883145; Mon, 08 Jun 2020 07:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591626883; cv=none; d=google.com; s=arc-20160816; b=bxJ3/GGxTgQEST/P+eVnxg4MiOhR/io23t0wbBSkM0J5l7AZiybe4dHni0Cr3aU4K5 yrLtk63m+sNiz8/LDhj4Q1EsdPKDZZ15eQo1HCZtCWetGvbxzyGgMUQAhl+lvXm72qwD F11p2PJfZOLkFScetkol85MZYyIZg3QOuqKdSm9p7VNF4Qoxb9SDmWSIMUEzZFCIrXl0 tuVe1g/kBo342j7d1ZM5oTN7lCsPiZqk60u/zuLb52QoteLmrz6hyQWawHY+7G2qPh0H FZXT7Q6egROMMltvkzPfcWRRk+HiaFZqsFZ7CUI/5oZDLULhfF1zKzqh/Bh6zFErZUX4 dCVQ== 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=GKWIm0azDCxLSg6UcyWc7rSovYmDP72I/JD5+Yb/qNE=; b=U9O0Z6HWFGbnm7XtKkQzZLaJQpWqAOU/TL/M/jL1DUFU6fp0kYe191Vfkl8HUarUHR uDjxQUEIHkGZpR5mKh5Nowl9CzhvGYbfUOESMnUl2gHokFQbDiDft6009DKCOJD06TvE WMYvQMVPsdCNFxTBGgOYpidQZc8tRccTrJDvpB8HaCepXbmZ7d4iVaZNeTzF9J9wCuvg 2rWzuV+hV+oeYkOCHqILbx6hu28M+eAdVhP3/UglKAseszzwHuEOhS7jSmcz4vhyCOj2 1ho/Zhxj2PB3XOf5QSVa3uttn8dogkawBiocuzmeEFjSA49oTZIsxAtkaIYhq8tJ6yZx +AOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=lNzJXJgV; 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 y5si8386718edw.121.2020.06.08.07.34.19; Mon, 08 Jun 2020 07:34:43 -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=lNzJXJgV; 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 S1729938AbgFHOca (ORCPT + 99 others); Mon, 8 Jun 2020 10:32:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726074AbgFHOc3 (ORCPT ); Mon, 8 Jun 2020 10:32:29 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A28B7C08C5C2 for ; Mon, 8 Jun 2020 07:32:27 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id c71so15526583wmd.5 for ; Mon, 08 Jun 2020 07:32:27 -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=GKWIm0azDCxLSg6UcyWc7rSovYmDP72I/JD5+Yb/qNE=; b=lNzJXJgV2fHm7TbizH361S90IASi17wyWUHqzcwW4u7tTxae6KXr+C0LjMAmLQqmKP 0D9QnO8zqY1Ku4ticsen8nhFZvrqes1Rh+D6z8U36MCINpOa3IdoSISvvKhbwOYPoog7 sEMZmDKY75gvwAZ5YCSvtqnBOKLBIgs9/jUtI= 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=GKWIm0azDCxLSg6UcyWc7rSovYmDP72I/JD5+Yb/qNE=; b=d1sAHxLk5RO95T4h7dGo7OlnfdRunnumqJqvaznsojdiOavesyYZqShqW4D2SBXYu4 jZifFeC9rbh4fxj88lVtruS4LbQyoUSnn6GD0wcZ9bmdWHjtDOXTFRMlymgLZ43viBcQ cJgg74R9pdPGEt61cml9NhBpvMSGxLNa/ePPWgQt/tIL7SQNCiczQR5M/w1QC9j0OqMb O+MLKF1CdlJ2FZsceDezr3TSKOcLxwKGjoWELTfpNEouhGMCZ4VqDr6RDFXWvKnppcA4 l2Hg50Eor6UNom0+wsSwif9Ny8eKw9ertO1pajc+6vI18tzNRhXHGmflRsIg44oRsPnL qqaw== X-Gm-Message-State: AOAM5328wq55XLJ3n3byFAXfn0t7uxqJZB/Ug0vcChzIOxNEeykkT7yi xtUahM26N/f2uCkUr3KIg9g44Q== X-Received: by 2002:a1c:e389:: with SMTP id a131mr17386232wmh.46.1591626745819; Mon, 08 Jun 2020 07:32:25 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id h188sm23593079wmh.2.2020.06.08.07.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2020 07:32:24 -0700 (PDT) Date: Mon, 8 Jun 2020 16:32:21 +0200 From: Daniel Vetter To: "Ahmed S. Darwish" Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , Thomas Gleixner , "Paul E. McKenney" , "Sebastian A. Siewior" , Steven Rostedt , LKML , Daniel Vetter , David Airlie , Sumit Semwal , Felix Kuehling , Alex Deucher , Christian =?iso-8859-1?Q?K=F6nig?= , "David (ChunMing) Zhou" , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: Re: [PATCH v2 06/18] dma-buf: Use sequence counter with associated wound/wait mutex Message-ID: <20200608143221.GW20149@phenom.ffwll.local> Mail-Followup-To: "Ahmed S. Darwish" , Peter Zijlstra , Ingo Molnar , Will Deacon , Thomas Gleixner , "Paul E. McKenney" , "Sebastian A. Siewior" , Steven Rostedt , LKML , David Airlie , Sumit Semwal , Felix Kuehling , Alex Deucher , Christian =?iso-8859-1?Q?K=F6nig?= , "David (ChunMing) Zhou" , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200608005729.1874024-1-a.darwish@linutronix.de> <20200608005729.1874024-7-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200608005729.1874024-7-a.darwish@linutronix.de> 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 Mon, Jun 08, 2020 at 02:57:17AM +0200, Ahmed S. Darwish wrote: > A sequence counter write side critical section must be protected by some > form of locking to serialize writers. If the serialization primitive is > not disabling preemption implicitly, preemption has to be explicitly > disabled before entering the sequence counter write side critical > section. > > The dma-buf reservation subsystem uses plain sequence counters to manage > updates to reservations. Writer serialization is accomplished through a > wound/wait mutex. > > Acquiring a wound/wait mutex does not disable preemption, so this needs > to be done manually before and after the write side critical section. > > Use the newly-added seqcount_ww_mutex_t instead: > > - It associates the ww_mutex with the sequence count, which enables > lockdep to validate that the write side critical section is properly > serialized. > > - It removes the need to explicitly add preempt_disable/enable() > around the write side critical section because the write_begin/end() > functions for this new data type automatically do this. > > If lockdep is disabled this ww_mutex lock association is compiled out > and has neither storage size nor runtime overhead. > > Signed-off-by: Ahmed S. Darwish I'm not seeing the patch that adds the seqcount ww_mutex glue and not quite motivated enough to grab it from lore, so someone else needs to check the details. Just Acked-by: Daniel Vetter for merging through whatever tree/branch makes sense from me. -Daniel > --- > drivers/dma-buf/dma-resv.c | 8 +------- > drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 -- > include/linux/dma-resv.h | 2 +- > 3 files changed, 2 insertions(+), 10 deletions(-) > > diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c > index 590ce7ad60a0..3aba2b2bfc48 100644 > --- a/drivers/dma-buf/dma-resv.c > +++ b/drivers/dma-buf/dma-resv.c > @@ -128,7 +128,7 @@ subsys_initcall(dma_resv_lockdep); > void dma_resv_init(struct dma_resv *obj) > { > ww_mutex_init(&obj->lock, &reservation_ww_class); > - seqcount_init(&obj->seq); > + seqcount_ww_mutex_init(&obj->seq, &obj->lock); > > RCU_INIT_POINTER(obj->fence, NULL); > RCU_INIT_POINTER(obj->fence_excl, NULL); > @@ -259,7 +259,6 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence) > fobj = dma_resv_get_list(obj); > count = fobj->shared_count; > > - preempt_disable(); > write_seqcount_begin(&obj->seq); > > for (i = 0; i < count; ++i) { > @@ -281,7 +280,6 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence) > smp_store_mb(fobj->shared_count, count); > > write_seqcount_end(&obj->seq); > - preempt_enable(); > dma_fence_put(old); > } > EXPORT_SYMBOL(dma_resv_add_shared_fence); > @@ -308,14 +306,12 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence) > if (fence) > dma_fence_get(fence); > > - preempt_disable(); > write_seqcount_begin(&obj->seq); > /* write_seqcount_begin provides the necessary memory barrier */ > RCU_INIT_POINTER(obj->fence_excl, fence); > if (old) > old->shared_count = 0; > write_seqcount_end(&obj->seq); > - preempt_enable(); > > /* inplace update, no shared fences */ > while (i--) > @@ -393,13 +389,11 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) > src_list = dma_resv_get_list(dst); > old = dma_resv_get_excl(dst); > > - preempt_disable(); > write_seqcount_begin(&dst->seq); > /* write_seqcount_begin provides the necessary memory barrier */ > RCU_INIT_POINTER(dst->fence_excl, new); > RCU_INIT_POINTER(dst->fence, dst_list); > write_seqcount_end(&dst->seq); > - preempt_enable(); > > dma_resv_list_free(src_list); > dma_fence_put(old); > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c > index 6a5b91d23fd9..c71c0bb6ce26 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c > @@ -258,11 +258,9 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, > new->shared_count = k; > > /* Install the new fence list, seqcount provides the barriers */ > - preempt_disable(); > write_seqcount_begin(&resv->seq); > RCU_INIT_POINTER(resv->fence, new); > write_seqcount_end(&resv->seq); > - preempt_enable(); > > /* Drop the references to the removed fences or move them to ef_list */ > for (i = j, k = 0; i < old->shared_count; ++i) { > diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h > index a6538ae7d93f..d44a77e8a7e3 100644 > --- a/include/linux/dma-resv.h > +++ b/include/linux/dma-resv.h > @@ -69,7 +69,7 @@ struct dma_resv_list { > */ > struct dma_resv { > struct ww_mutex lock; > - seqcount_t seq; > + seqcount_ww_mutex_t seq; > > struct dma_fence __rcu *fence_excl; > struct dma_resv_list __rcu *fence; > -- > 2.20.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch