Received: by 10.223.185.116 with SMTP id b49csp1039690wrg; Wed, 21 Feb 2018 11:02:00 -0800 (PST) X-Google-Smtp-Source: AH8x226NeEPg25H16eqCzbdQPpAHA6250IENQ+xdIc8PVEPcpJrqxA4uLMp8Q13DQVA+xpNinYOS X-Received: by 2002:a17:902:7587:: with SMTP id j7-v6mr4133169pll.135.1519239720299; Wed, 21 Feb 2018 11:02:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519239720; cv=none; d=google.com; s=arc-20160816; b=HXaBZXWmqKgPzlntKn0DdzJnZDagOIXt1L3O2dTcM57bzun40Cxpda5dWXmYu+hYUp kfSpYotzhs2l0QvokcJAb5ox75v7KJGBVdL/qQVFfoyqzguhini8C6jEQf4lae3bDuA3 QzBVFmj56JVzVv4TFBF5B0M/a2mzZ/OV7Uqi2EdxPbDfB8bA/zvOzf4wfgIrekMsJSjG xJRblWOotgK6nTSKDUFcDj2tot3ILk4lsekxLhFP85iBOSWIFsJe/LTt1bQmL46UZzA3 7NC/slKJD4xm95lBKWlipvRrsIZHlu+tjrREpyGCkrDn0OadRLIdtfFKwKdqv3aIVSWx 31QA== 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:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=bDMXKjSDgqZsZICgJQo0UAnJu6IxrcNiW7PNPvIKJA4=; b=SGTE8Fi6wILeUGBwpdUlHV+DbPhGMyhwmNUHnsIqn8EdfIyptfSFexRT3cEmR+7hIY j69o+z8jwx/ZKaaSfp7BWulLdbiCdU1KH8hb0/4P644KKJj0O/PvfMIPgQ6W3TO14cwD xCSU9jgaPZDDpD6T0HlDgTY03cUhrkqpWJut/ESP3JalIVuIkCLm/e7xXBwrFTq1RXuY zdX6ycCkbV2fCXIWRjRXCJ7TU1/eaIZffkXhM/ow03ScmLGJUK8hRL0zf+MKFp23w0Tu YqCRH4eF2g93v1T6mftW0rKshTuzZe4h0qExwla9j9x2BQgI+WwDJNH3gGWgJ/ytptwA cehA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Tsoranr4; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m197si2605438pga.206.2018.02.21.11.01.44; Wed, 21 Feb 2018 11:02:00 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=Tsoranr4; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932314AbeBUQRZ (ORCPT + 99 others); Wed, 21 Feb 2018 11:17:25 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:36676 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932254AbeBUQRX (ORCPT ); Wed, 21 Feb 2018 11:17:23 -0500 Received: by mail-io0-f194.google.com with SMTP id t22so2696532iob.3; Wed, 21 Feb 2018 08:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=bDMXKjSDgqZsZICgJQo0UAnJu6IxrcNiW7PNPvIKJA4=; b=Tsoranr4sowzTNwMs9fuct8cOP3zh9aSdyYD1GvvR47WkDmv2Ez0vg63wk6F7P5jW4 HOI4LvgaRrpYgta5ExTsQpSp7ytQJbuFwfp6hIKfdVhugZrtmFK8X6aW3W+HWB5p9OUj 4+Oz9CfsLHeV6gvKdu2PZNSGMzKB7qXGwt5c/4g1GlIJ9kRnXKDC4pqznxLrQnPMnJjE 69WLblE25OqT394ShpX3ROqOr8mBMpU32NDfQrHzXiNJ18FO1L/Ja/0KBLtmja0wC3IH NeVSzedfOnzstsQNZ7WXg/O7B7bhmxzR7BAogo/GswlGZU0Q3iVhvr7mCya6dI7Qa8E2 oiFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=bDMXKjSDgqZsZICgJQo0UAnJu6IxrcNiW7PNPvIKJA4=; b=jC6eogOn27xe2jBAiY3L2idmq3VEDxOxH5ZQ5RqpzJqfeChJi6zMb8kYxBXTnokyIh OvU0EH321+shCaPaQjZdagAXk91L6kVbIdO1pwcJm5aK1zez4A7dQ+FDBwrTpgG83ARV pONRIs8tlZ7iMxSwcyUZVyLXyRMBVaZCUuM04ULG8lSqUeaDRb1Z7Es6H+MpW4UeFnF8 7NcbnayQ2/m22vSaw5crZEVb9f5+anEBX/VcFT2bD+Fph7tWs8RhA7XccAlQ0PFPjVfR 3ov5QCdF4+WN95ZADlL52QOVXP3hQj3T+wOx52obwo3DJnlvabHsmphYyuw0TLu6keUG cQ0w== X-Gm-Message-State: APf1xPDytRj5VllKSKU9oyxEe2sBx8SftQTYwXcVyIwm1vJWK1iePzIM vA7VQ8fPGlxpcxlhNlkbwP/Sn2RHpVPvWVGAHuo= X-Received: by 10.107.151.209 with SMTP id z200mr4680813iod.29.1519229842096; Wed, 21 Feb 2018 08:17:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.92.211 with HTTP; Wed, 21 Feb 2018 08:17:21 -0800 (PST) In-Reply-To: <20180221155410.GQ5453@intel.com> References: <20180221143730.30285-1-robdclark@gmail.com> <20180221143730.30285-2-robdclark@gmail.com> <20180221144919.GN5453@intel.com> <20180221150727.GO5453@intel.com> <20180221152720.GP5453@intel.com> <20180221155410.GQ5453@intel.com> From: Rob Clark Date: Wed, 21 Feb 2018 11:17:21 -0500 Message-ID: Subject: Re: [PATCH 1/4] drm/atomic: integrate modeset lock with private objects To: =?UTF-8?B?VmlsbGUgU3lyasOkbMOk?= Cc: dri-devel , David Airlie , linux-arm-msm , Linux Kernel Mailing List 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 Wed, Feb 21, 2018 at 10:54 AM, Ville Syrj=C3=A4l=C3=A4 wrote: > On Wed, Feb 21, 2018 at 10:36:06AM -0500, Rob Clark wrote: >> On Wed, Feb 21, 2018 at 10:27 AM, Ville Syrj=C3=A4l=C3=A4 >> wrote: >> > On Wed, Feb 21, 2018 at 10:20:03AM -0500, Rob Clark wrote: >> >> On Wed, Feb 21, 2018 at 10:07 AM, Ville Syrj=C3=A4l=C3=A4 >> >> wrote: >> >> > On Wed, Feb 21, 2018 at 09:54:49AM -0500, Rob Clark wrote: >> >> >> On Wed, Feb 21, 2018 at 9:49 AM, Ville Syrj=C3=A4l=C3=A4 >> >> >> wrote: >> >> >> > On Wed, Feb 21, 2018 at 09:37:21AM -0500, Rob Clark wrote: >> >> >> >> Follow the same pattern of locking as with other state objects.= This >> >> >> >> avoids boilerplate in the driver. >> >> >> > >> >> >> > I'm not sure we really want to do this. What if the driver wants= a >> >> >> > custom locking scheme for this state? >> >> >> >> >> >> That seems like something we want to discourage, ie. all the more >> >> >> reason for this patch. >> >> >> >> >> >> There is no reason drivers could not split their global state into >> >> >> multiple private objs's, each with their own lock, for more fine >> >> >> grained locking. That is basically the only valid reason I can th= ink >> >> >> of for "custom locking". >> >> > >> >> > In i915 we have at least one case that would want something close t= o an >> >> > rwlock. Any crtc lock is enough for read, need all of them for writ= e. >> >> > Though if we wanted to use private objs for that we might need to >> >> > actually make the states refcounted as well, otherwise I can imagin= e >> >> > we might land in some use-after-free issues once again. >> >> > >> >> > Maybe we could duplicate the state into per-crtc and global copies,= but >> >> > then we have to keep all of those in sync somehow which doesn't sou= nd >> >> > particularly pleasant. >> >> >> >> Or just keep your own driver lock for read, and use that plus the cor= e >> >> modeset lock for write? >> > >> > If we can't add the private obj to the state we can't really use it. >> > >> >> I'm not sure why that is strictly true (that you need to add it to the >> state if for read-only), since you'd be guarding it with your own >> driver read-lock you can just priv->foo_state->bar. >> >> Since it is read-only access, there is no roll-back to worry about for >> test-only or failed atomic_check()s.. > > That would be super ugly. We want to access the information the same > way whether it has been modified or not. Well, I mean the whole idea of what you want to do seems a bit super-ugly ;= -) I mean, in mdp5 the assigned global resources go in plane/crtc state, and tracking of what is assigned to which plane/crtc is in global state, so it fits nicely in the current locking model. For i915, I'm not quite sure what is the global state you are concerned about, so it is a bit hard to talk about the best solution in the abstract. Maybe the better option is to teach modeset-lock how to be a rwlock instead? BR, -R >> >> BR, >> -R >> >> >> >> >> >> BR, >> >> -R >> >> >> >> > >> >> >> >> >> >> (And ofc drivers could add there own locks in addition to what is = done >> >> >> by core, but I'd rather look at that on a case by case basis, rath= er >> >> >> than it being part of the boilerplate in each driver.) >> >> >> >> >> >> BR, >> >> >> -R >> >> >> >> >> >> >> >> >> >> >> Signed-off-by: Rob Clark >> >> >> >> --- >> >> >> >> drivers/gpu/drm/drm_atomic.c | 9 ++++++++- >> >> >> >> include/drm/drm_atomic.h | 5 +++++ >> >> >> >> 2 files changed, 13 insertions(+), 1 deletion(-) >> >> >> >> >> >> >> >> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm= _atomic.c >> >> >> >> index fc8c4da409ff..004e621ab307 100644 >> >> >> >> --- a/drivers/gpu/drm/drm_atomic.c >> >> >> >> +++ b/drivers/gpu/drm/drm_atomic.c >> >> >> >> @@ -1078,6 +1078,8 @@ drm_atomic_private_obj_init(struct drm_pr= ivate_obj *obj, >> >> >> >> { >> >> >> >> memset(obj, 0, sizeof(*obj)); >> >> >> >> >> >> >> >> + drm_modeset_lock_init(&obj->lock); >> >> >> >> + >> >> >> >> obj->state =3D state; >> >> >> >> obj->funcs =3D funcs; >> >> >> >> } >> >> >> >> @@ -1093,6 +1095,7 @@ void >> >> >> >> drm_atomic_private_obj_fini(struct drm_private_obj *obj) >> >> >> >> { >> >> >> >> obj->funcs->atomic_destroy_state(obj, obj->state); >> >> >> >> + drm_modeset_lock_fini(&obj->lock); >> >> >> >> } >> >> >> >> EXPORT_SYMBOL(drm_atomic_private_obj_fini); >> >> >> >> >> >> >> >> @@ -1113,7 +1116,7 @@ struct drm_private_state * >> >> >> >> drm_atomic_get_private_obj_state(struct drm_atomic_state *stat= e, >> >> >> >> struct drm_private_obj *obj) >> >> >> >> { >> >> >> >> - int index, num_objs, i; >> >> >> >> + int index, num_objs, i, ret; >> >> >> >> size_t size; >> >> >> >> struct __drm_private_objs_state *arr; >> >> >> >> struct drm_private_state *obj_state; >> >> >> >> @@ -1122,6 +1125,10 @@ drm_atomic_get_private_obj_state(struct = drm_atomic_state *state, >> >> >> >> if (obj =3D=3D state->private_objs[i].ptr) >> >> >> >> return state->private_objs[i].state; >> >> >> >> >> >> >> >> + ret =3D drm_modeset_lock(&obj->lock, state->acquire_ctx); >> >> >> >> + if (ret) >> >> >> >> + return ERR_PTR(ret); >> >> >> >> + >> >> >> >> num_objs =3D state->num_private_objs + 1; >> >> >> >> size =3D sizeof(*state->private_objs) * num_objs; >> >> >> >> arr =3D krealloc(state->private_objs, size, GFP_KERNEL); >> >> >> >> diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.= h >> >> >> >> index 09076a625637..9ae53b73c9d2 100644 >> >> >> >> --- a/include/drm/drm_atomic.h >> >> >> >> +++ b/include/drm/drm_atomic.h >> >> >> >> @@ -218,6 +218,11 @@ struct drm_private_state_funcs { >> >> >> >> * &drm_modeset_lock is required to duplicate and update this = object's state. >> >> >> >> */ >> >> >> >> struct drm_private_obj { >> >> >> >> + /** >> >> >> >> + * @lock: Modeset lock to protect the state object. >> >> >> >> + */ >> >> >> >> + struct drm_modeset_lock lock; >> >> >> >> + >> >> >> >> /** >> >> >> >> * @state: Current atomic state for this driver private o= bject. >> >> >> >> */ >> >> >> >> -- >> >> >> >> 2.14.3 >> >> >> >> >> >> >> >> _______________________________________________ >> >> >> >> dri-devel mailing list >> >> >> >> dri-devel@lists.freedesktop.org >> >> >> >> https://lists.freedesktop.org/mailman/listinfo/dri-devel >> >> >> > >> >> >> > -- >> >> >> > Ville Syrj=C3=A4l=C3=A4 >> >> >> > Intel OTC >> >> > >> >> > -- >> >> > Ville Syrj=C3=A4l=C3=A4 >> >> > Intel OTC >> > >> > -- >> > Ville Syrj=C3=A4l=C3=A4 >> > Intel OTC > > -- > Ville Syrj=C3=A4l=C3=A4 > Intel OTC