Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2283862yba; Fri, 10 May 2019 09:02:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHwQRAsK5OHdOTT9bF7uTeeKEm/SImW82+AkUFwQMDpfJIIXiVtEZeV65e36fsP0QIpRGC X-Received: by 2002:a17:902:7084:: with SMTP id z4mr14167016plk.259.1557504142245; Fri, 10 May 2019 09:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557504142; cv=none; d=google.com; s=arc-20160816; b=nQARe8Qh+9k/siHuIi8FUc9hmppOeSBbtjHi57KwhRzjCdC355PbkgBQuJ46ZcKHyJ O14AF11t1ftq2c/ZldhH9PLTAQjmM+Of8jnNdm5js60n5Oop2wOGb1NmGMdwqA0zWA4J QKHybdWcXZZHr92b8XyU6IEGkjqbMX5BlS2dDotXGgFqDIKVoQTjr7pBLmTZiXKqhL3U 9KYLWY0tekfsydwEVbsl1bSYKd/xnZ/4aq7J+L+rYwEjLnW8oPTdF81isbJcDK5GGhjf AphLYaxasMRcNoGGWutoMsREtDlK8McttL7Vn5QthlyEZXqRgZWbd3SQKSiL2Dm+amsZ g2Rg== 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:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=VUrXh1AFeG9J6AAd0viC1Cmz1lJRlMRFQPT4JUtvkd8=; b=lkmxbxCCuXfezEg95zWxNnUcG8KI6BO/Ruc4adnQR4OWfmbdaPR/TGRKKbCNUNXyc7 lgkZe0i/f13nbxqGy4wxEVWbSZEiKaIciJ8BQBkbgNaSRkQVN3LBPUALTO8mfxPd7vR7 AoT8GbuGF7E60J97YE7PFzpAeHueSrODfq3xWiLPc5zChkZI1F5zSwjMN5+iSoIo6brM aAA6ZVU9dC9huz7q1MIddGJoYsptK8jTjMP4Qan/L1LEwP34aX7SnC/cOLtSpDQCaoHe DoZkUeqY9ubqcOvTbGHYfM/0iDOaqZ8LCcb0srSGPlEs+m9tBno2p5BTH2OJEKmTgP++ KqEA== ARC-Authentication-Results: i=1; mx.google.com; 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 d31si7672710pla.89.2019.05.10.09.02.04; Fri, 10 May 2019 09:02:22 -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; 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 S1727472AbfEJPtI (ORCPT + 99 others); Fri, 10 May 2019 11:49:08 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:38435 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726930AbfEJPtI (ORCPT ); Fri, 10 May 2019 11:49:08 -0400 X-Originating-IP: 90.88.28.253 Received: from aptenodytes (aaubervilliers-681-1-86-253.w90-88.abo.wanadoo.fr [90.88.28.253]) (Authenticated sender: paul.kocialkowski@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 882431BF207; Fri, 10 May 2019 15:49:03 +0000 (UTC) Message-ID: <2fe2b72a28a7892797fed6d3db86b7c7912fe8c9.camel@bootlin.com> Subject: Re: [PATCH v8 4/4] drm/vc4: Allocate binner bo when starting to use the V3D From: Paul Kocialkowski To: Eric Anholt , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: David Airlie , Daniel Vetter , Maxime Ripard , Eben Upton , Thomas Petazzoni Date: Fri, 10 May 2019 17:48:39 +0200 In-Reply-To: <87r2973222.fsf@anholt.net> References: <20190503081242.29039-1-paul.kocialkowski@bootlin.com> <20190503081242.29039-5-paul.kocialkowski@bootlin.com> <87r2973222.fsf@anholt.net> Organization: Bootlin Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thu, 2019-05-09 at 11:39 -0700, Eric Anholt wrote: > Paul Kocialkowski writes: > > > The binner BO is not required until the V3D is in use, so avoid > > allocating it at probe and do it on the first non-dumb BO allocation. > > > > Keep track of which clients are using the V3D and liberate the buffer > > when there is none left, using a kref. Protect the logic with a > > mutex to avoid race conditions. > > > > The binner BO is created at the time of the first render ioctl and is > > destroyed when there is no client and no exec job using it left. > > > > The Out-Of-Memory (OOM) interrupt also gets some tweaking, to avoid > > enabling it before having allocated a binner bo. > > > > We also want to keep the BO alive during runtime suspend/resume to avoid > > failing to allocate it at resume. This happens when the CMA pool is > > full at that point and results in a hard crash. > > > > Signed-off-by: Paul Kocialkowski > > @@ -313,6 +321,49 @@ static int bin_bo_alloc(struct vc4_dev *vc4) > > return ret; > > } > > > > +int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used) > > +{ > > + int ret = 0; > > + > > + mutex_lock(&vc4->bin_bo_lock); > > + > > + if (used && *used) > > + goto complete; > > > > + > > + if (used) > > + *used = true; > > + > > + if (vc4->bin_bo) { > > + kref_get(&vc4->bin_bo_kref); > > + goto complete; > > + } > > + > > + ret = bin_bo_alloc(vc4); > > I think this block wants to be: > > if (vc4->bin_bo) > kref_get(&vc4->bin_bo_kref); > else > ret = bin_bo_alloc(vc4); > > if (ret == 0 && used) > *used = true; > > (so we don't flag used if bin_bo_alloc fails) > > If you agree, then the series is: I totally agree, and had definitely lost sight of the return value. Thanks for the thorough code review once more! Cheers, Paul > Reviewed-by: Eric Anholt > > > + > > +complete: > > + mutex_unlock(&vc4->bin_bo_lock); > > + > > + return ret; > > +} -- Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com