Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3023381pxb; Mon, 18 Oct 2021 06:48:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZnDKySknPil+YVaMrj4hvhQMvtz0V50Lw1NrkBBflkkjhek6AdQFkonL6mwocpsE874BP X-Received: by 2002:a63:1d53:: with SMTP id d19mr23450462pgm.85.1634564912612; Mon, 18 Oct 2021 06:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564912; cv=none; d=google.com; s=arc-20160816; b=dFEvuaiLaa/LyZ91xZdOpcupk6vZVZfbbGwEchF1XzlC1zjMOvNcQlQTaGkPblECl8 pDFoTUkMAZldC0lOZEh+nU8See1WyhzEWXkV78QUv5JhGkOmF92jYEeI5foPYWFOamFf r9+koHZvzdE8WqzF7fOLhiKXWMg28zE+lW+1+PMPnc33q8sAe/7OGvMvATfGchUrntwH r/VS2zEpsDoNHXin+HrRFH+eQUPcO9sYr4KbAEPiV9owR0UyO+bfojZHCORxe+al0WGY T+yhsBphY8XOZYV2zY8ng7eITeQb0FHBLIdYuzYF1Td68ItK1DZU+I5W43/8HLrzL86+ sjeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5mk4swNGqGvUh4Km4RxrvUTXgkxUVRebqLc3G8BTNmk=; b=mLDIA20RbeFC3srkjSv+UnaB7JlrujIIG9QCXBCHub3jzsZdWgpdyieiQJSbpDBsme IsqMK3FAr/w6MYpujkswiqbDdfdywDmFmL3dDg9ZPhW3elGELChammS0+nhx8E0sIUYH X53XSNVRDyFyXeJx9Cjik7+991xRkFiJP5JoVKB3OVWpqk4TsZ1+XgP/Y33dEQAGs7O0 HqAJvtUnlu/CJS6KlFcVjqgiI0qoWi6JH9989pqw9cUKyFEM+qBUKdcBiWjHLTU4+T6D l9DHZV3cdOX4B7IbPwAlnwqFXr78CMjFhlhexgcBPbXuJuGbbi0IhMGxbexR7ltxv1Ix zJxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I4s5zIxS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pf8si2908194pjb.84.2021.10.18.06.48.20; Mon, 18 Oct 2021 06:48:32 -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=@linuxfoundation.org header.s=korg header.b=I4s5zIxS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232105AbhJRNtM (ORCPT + 99 others); Mon, 18 Oct 2021 09:49:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:40810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232251AbhJRNqs (ORCPT ); Mon, 18 Oct 2021 09:46:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 85E9161260; Mon, 18 Oct 2021 13:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564170; bh=OPELsX+G3nNokelY+Dgmcg/1sm+5kutmhKH3M0UZRFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I4s5zIxSlQhATFVgvT9oJ2iaUXUI4z5v9qKQjILlLffxFaeGGyvGVcjxFisrZOhU/ rBxQzziyK81NssLnYL/Of5TjqTphDfFePkVYubzYqGABZ6xomtPcds4rzsIhjdy0RD fFmkDYMto5/xWNuQ4OiSlgJCoRWgGy6CGSrMFOVs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rob Clark Subject: [PATCH 5.10 092/103] drm/msm/a6xx: Track current ctx by seqno Date: Mon, 18 Oct 2021 15:25:08 +0200 Message-Id: <20211018132337.843296301@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132334.702559133@linuxfoundation.org> References: <20211018132334.702559133@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rob Clark commit 14eb0cb4e9a7323c8735cf6c681ed8423ce6ae06 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- 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(-) --- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c @@ -99,7 +99,7 @@ static void a6xx_set_pagetable(struct a6 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)) @@ -132,7 +132,7 @@ static void a6xx_set_pagetable(struct a6 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) @@ -887,7 +887,7 @@ static int a6xx_hw_init(struct msm_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); --- 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; --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -581,6 +581,7 @@ static void load_gpu(struct drm_device * 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; @@ -594,6 +595,8 @@ static int context_init(struct drm_devic ctx->aspace = msm_gpu_create_private_address_space(priv->gpu, current); file->driver_priv = ctx; + ctx->seqno = atomic_inc_return(&ident); + return 0; } --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -58,6 +58,7 @@ struct msm_file_private { int queueid; struct msm_gem_address_space *aspace; struct kref ref; + int seqno; }; enum msm_mdp_plane_property {