Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp586732pxb; Thu, 30 Sep 2021 12:26:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6Ai5roH22Epufto/nnnb7D9NQ0Zzfg8TAAqBHkSHJajl0tGau+cQjcr0rZM6hlaMmcwZp X-Received: by 2002:a17:906:2cd6:: with SMTP id r22mr1131776ejr.398.1633030003962; Thu, 30 Sep 2021 12:26:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633030003; cv=none; d=google.com; s=arc-20160816; b=O5q0quvL3RfJvdkheY3uQSYOGA80tNGlpf0Ylr0yeyr1hmbgcuS3gJ11/EkzfA0jo5 0RTwmbHMvFVcVfxfgHN0LsNY4sjT2eOosk9SCR7/fxWCKriZJCk0uzGz98XYCF1RoeST 6UgHLEK19oIhBOOwogmN32X2aoVFWgttGbXLNbBisBsf5d6k/h7Sp/+IvWfRYzHK0FS/ CM24ogE6BZBr7biw2lnG+rqW765tHmzOF6xA6UxiYlSSszRn0mJD3KBGAs90y9z2yu5i NuvMfO41HONyo3iz7Ff2PMWSO8Zf2w2tiGT6OTvXqAQRwkJap2AI4EzDIuQV1hWPYtPd LL+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WzEFhcvH/Na9w/rh3vRVxZizFbaM18w+Th+vRdfVjxw=; b=SA2Ftwqi4rfl5SrdmbXqOMjJafSBpYEx4jv80eDBs+zK66HG8xiVgnxM7RtHPD/rTn 3M4t74UxNc5+FWtqiEwnImcGXq+CxWq9z8toNqzGrRkC0UFIHcTvfHt/wqfcIPgJaGgK MUcjSviwDlo4L7+GjkaQ6fhWl6qizS41VpOCD2LJJzKumsE0kF+qimcJGD1a54SU8fre G37ZH3L1zU75oxioXfNLsAX4UkF+JzcHPPxK/Xb4tOpLyLgIlk7qkw++5qdydK0yM6sX gmBrL1QIuMTaOTwFe/+v5zE4/mpQ6ygmpV3O8RLAQDhxWG3yM5IHmOo1sglJlVm764u4 Vt4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=OKZoY3nu; 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 l8si4394947edi.356.2021.09.30.12.26.18; Thu, 30 Sep 2021 12:26: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=OKZoY3nu; 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 S1343700AbhI3Sg1 (ORCPT + 99 others); Thu, 30 Sep 2021 14:36:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbhI3SgZ (ORCPT ); Thu, 30 Sep 2021 14:36:25 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F4B8C06176C for ; Thu, 30 Sep 2021 11:34:42 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id a3so8498137oid.6 for ; Thu, 30 Sep 2021 11:34:42 -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=WzEFhcvH/Na9w/rh3vRVxZizFbaM18w+Th+vRdfVjxw=; b=OKZoY3nu59ohhZIGR9rXi4peRz7SQuNBkUJQZfiWyWMgNU31fC/2YKvc3uv3oLDxVz QupNMRm1Kou669rMbTjmKfydZLdm1h/SeITsid38QYO5+BBNQVc1DxwVgPZhI13xf7Vc YHe7NepSVTMn6I3JqwOQkIQqqKmwYSs2pWsH0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WzEFhcvH/Na9w/rh3vRVxZizFbaM18w+Th+vRdfVjxw=; b=FZmahfQh2gcvZyF+KpDtnYn+ITa0nFhaH8h7N7OEPQDN0+43BlAZbJvjS9RO31EVJK ETy96GIsvnUm/PpCU1Z3hQjirHB8L4jJMENai3ZR9EHdKs/yXzBUdLf5GNGNLszqZeX2 8bOT8DREEsnuHsbaNX1ByRk1g1npglNffhgdoqMLB5R5BRUfnuC8/wXXLAPA8N2naKwX SOgEqUojkR8pALKXOxn6fItLpgANq9UvWMfaCDgUiS09/LrAuuYdbCY+dP1918wfu9eV jpK+CUtIQk5+HS1kWha5qv2atC0GZrSyghVkHZ3NK97DDGvxPQX0hO9fBU+NVeL/LdfN YOmg== X-Gm-Message-State: AOAM5312Tj4xxxPfY+fLFGEMlD1v2Q6LuF+OzaS3IZpFJaeA8DlpZfD6 vwlZ/D3TwtLOE/X0PRCkMk91MU5LsYJRj7vB12zoFa7b8GU= X-Received: by 2002:a05:6808:697:: with SMTP id k23mr620644oig.128.1633026881376; Thu, 30 Sep 2021 11:34:41 -0700 (PDT) MIME-Version: 1.0 References: <20210930182506.1236811-1-robdclark@gmail.com> In-Reply-To: <20210930182506.1236811-1-robdclark@gmail.com> From: Daniel Vetter Date: Thu, 30 Sep 2021 20:34:30 +0200 Message-ID: Subject: Re: [PATCH] drm/msm/a6xx: Track current ctx by seqno To: Rob Clark Cc: dri-devel , freedreno , linux-arm-msm , Jordan Crouse , Rob Clark , Sean Paul , David Airlie , Akhil P Oommen , Jonathan Marek , Dmitry Baryshkov , Sharat Masetty , Douglas Anderson , Sai Prakash Ranjan , Yangtao Li , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 30, 2021 at 8:20 PM Rob Clark wrote: > > From: Rob Clark > > In theory a context can be destroyed and a new one allocated at the same > address, making the pointer comparision to detect when we don't need to > update the current pagetables invalid. Instead assign a sequence number > to each context on creation, and use this for the check. > > Fixes: 84c31ee16f90 ("drm/msm/a6xx: Add support for per-instance pagetables") > Signed-off-by: Rob Clark Usually the weak reference pattern is to wrap a spinlock or something around it and clear it out on destruction. Or hold a full reference (e.g. on intel hw the hw goes unhappy if there's no context/pagetables at all, so we always need some). But I guess this works too. -Daniel > --- > drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 6 +++--- > drivers/gpu/drm/msm/adreno/a6xx_gpu.h | 11 ++++++++++- > drivers/gpu/drm/msm/msm_drv.c | 3 +++ > drivers/gpu/drm/msm/msm_drv.h | 1 + > 4 files changed, 17 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c > index 5e1ae3df42ba..e0a8b2fd1ff0 100644 > --- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c > +++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c > @@ -106,7 +106,7 @@ static void a6xx_set_pagetable(struct a6xx_gpu *a6xx_gpu, > u32 asid; > u64 memptr = rbmemptr(ring, ttbr0); > > - if (ctx == a6xx_gpu->cur_ctx) > + if (ctx->seqno == a6xx_gpu->cur_ctx_seqno) > return; > > if (msm_iommu_pagetable_params(ctx->aspace->mmu, &ttbr, &asid)) > @@ -139,7 +139,7 @@ static void a6xx_set_pagetable(struct a6xx_gpu *a6xx_gpu, > OUT_PKT7(ring, CP_EVENT_WRITE, 1); > OUT_RING(ring, 0x31); > > - a6xx_gpu->cur_ctx = ctx; > + a6xx_gpu->cur_ctx_seqno = ctx->seqno; > } > > static void a6xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit) > @@ -1081,7 +1081,7 @@ static int hw_init(struct msm_gpu *gpu) > /* Always come up on rb 0 */ > a6xx_gpu->cur_ring = gpu->rb[0]; > > - a6xx_gpu->cur_ctx = NULL; > + a6xx_gpu->cur_ctx_seqno = 0; > > /* Enable the SQE_to start the CP engine */ > gpu_write(gpu, REG_A6XX_CP_SQE_CNTL, 1); > diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.h b/drivers/gpu/drm/msm/adreno/a6xx_gpu.h > index 0bc2d062f54a..8e5527c881b1 100644 > --- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.h > +++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.h > @@ -19,7 +19,16 @@ struct a6xx_gpu { > uint64_t sqe_iova; > > struct msm_ringbuffer *cur_ring; > - struct msm_file_private *cur_ctx; > + > + /** > + * cur_ctx_seqno: > + * > + * The ctx->seqno value of the context with current pgtables > + * installed. Tracked by seqno rather than pointer value to > + * avoid dangling pointers, and cases where a ctx can be freed > + * and a new one created with the same address. > + */ > + int cur_ctx_seqno; > > struct a6xx_gmu gmu; > > diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c > index 624078b3adf2..30c1efc3d8a0 100644 > --- a/drivers/gpu/drm/msm/msm_drv.c > +++ b/drivers/gpu/drm/msm/msm_drv.c > @@ -711,6 +711,7 @@ static void load_gpu(struct drm_device *dev) > > static int context_init(struct drm_device *dev, struct drm_file *file) > { > + static atomic_t ident = ATOMIC_INIT(0); > struct msm_drm_private *priv = dev->dev_private; > struct msm_file_private *ctx; > > @@ -727,6 +728,8 @@ static int context_init(struct drm_device *dev, struct drm_file *file) > ctx->aspace = msm_gpu_create_private_address_space(priv->gpu, current); > file->driver_priv = ctx; > > + ctx->seqno = atomic_inc_return(&ident); > + > return 0; > } > > diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h > index de062450add4..8633d0059a3e 100644 > --- a/drivers/gpu/drm/msm/msm_drv.h > +++ b/drivers/gpu/drm/msm/msm_drv.h > @@ -59,6 +59,7 @@ struct msm_file_private { > int queueid; > struct msm_gem_address_space *aspace; > struct kref ref; > + int seqno; > }; > > enum msm_mdp_plane_property { > -- > 2.31.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch