Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3037193pxb; Mon, 18 Oct 2021 07:04:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTlSqQ3+J5DAK+V4kTHU/RChcSpjw7Cva67vKPKCz7FAQHo1VzxghFONLinGRXv/OXxcAo X-Received: by 2002:a05:6a00:181d:b0:44d:8425:fbe3 with SMTP id y29-20020a056a00181d00b0044d8425fbe3mr25001266pfa.6.1634565879391; Mon, 18 Oct 2021 07:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634565879; cv=none; d=google.com; s=arc-20160816; b=uN16JddyysZysJ9F2d5/hRH4Gsj2JPZhbOxEj2te9EsRqAtiOFbLsp4xdfg616f3MJ v2uOnK4r66DFvJASCDIkhTmDIoN1VoRCi1sy10sITw6dUuxgvbMsVslsWirzmzkjqN6d FjYbrSALp/uALdhXnkAhh2s3kQajwspbu3G6mvandCALQc9Z0hWIqcpBBT1qK4TlIx+q zCl/fYUcKsAxedCvKSo3a9zh2jh39YBKi1VK5YMm6k0mbBkTe/dgAN0LoLZ4c9Fm1A0h Jc92R+e53CW0Ra4WXE6HXMCz08K3bA40nhVMuHQl2nNsu39KZDV1iX00KYs7G2xYfjml epgA== 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=ai60PcLknx0t58epzCxZbR7xLoE77/z/sB007A9RSrg=; b=G0V+0o6tYxW3TAt4pBOMqOMyrOjRN/n5uomDEQCVSjRPDu2LF2+Q0h29aAY1j4oovm iXvYI+Xne+NjGYiTZnXrsT4GMJWzyOm/iOQuc+pkoG/ZieCUsdxxx3V67L0gV5Y9rwgG PPdPdFDdGbRnacRqCGxqCZVQNltRGhvGjoAo3pbrQir3fXc5cS1XQbPWEJfNQiT1tNy8 Hh7qLUptA/rmLl0097qGvRP8ZjilxzMLeKdFlfNVB5pcHcRf+dh+tN/5jM+TgurMPWHm tZd3FKJijOLRGVRTM7dnZYr2rQqJYJd5c5QfudhNDyEhCgvV2XfklHCP6DDkjMsTmGoM uEtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2PYiskVc; 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 f7si25520442pgk.560.2021.10.18.07.04.23; Mon, 18 Oct 2021 07:04:39 -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=2PYiskVc; 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 S233560AbhJROFF (ORCPT + 99 others); Mon, 18 Oct 2021 10:05:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:38968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234722AbhJROAy (ORCPT ); Mon, 18 Oct 2021 10:00:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 75CEA614C8; Mon, 18 Oct 2021 13:42:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564547; bh=cGeHEmM9en7hGcOg7c05e1reK0g+LmJ4GhENykDmanM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2PYiskVc1jWmZzMNvMnUKNPOSytl34d/0Hs/rmDHYuW3uMWJD5zf84n1fn3751ySS V2p+CNpt/iQSgw7yXpTGNaCabIoMAWXu+DSl6BAqU7k0Y/y2H2EyKtsg9ZBvtBWEne +z1kIwcQalFecewY96nM9r+sKYno+dAhDUjgr8Qo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rob Clark Subject: [PATCH 5.14 130/151] drm/msm/a6xx: Track current ctx by seqno Date: Mon, 18 Oct 2021 15:25:09 +0200 Message-Id: <20211018132344.889672772@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132340.682786018@linuxfoundation.org> References: <20211018132340.682786018@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 @@ -102,7 +102,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)) @@ -135,7 +135,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) @@ -1053,7 +1053,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 @@ -619,6 +619,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; @@ -632,6 +633,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 @@ -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 {