Received: by 2002:ab2:31c4:0:b0:1ef:b27b:cc29 with SMTP id d4csp245706lqf; Thu, 4 Apr 2024 05:37:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVep4jq0koxXv27eIFmwVGHUPB7hVGTUs9PUhfM1tDKfMy/Lk4sftzFac0gi2/z2/6t2bEaXhrsh6mTymX48Z+h/2GqCIIw9INetpT72w== X-Google-Smtp-Source: AGHT+IEgY4PZtZfROPVOksD3/Ud8ZJLnFwL9ta6Rikc7rAoO8wgrk7tKGojbVutcovONf2tmDTxU X-Received: by 2002:a05:6830:611:b0:6e9:ed5d:b77d with SMTP id w17-20020a056830061100b006e9ed5db77dmr1281274oti.4.1712234222073; Thu, 04 Apr 2024 05:37:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712234222; cv=pass; d=google.com; s=arc-20160816; b=AAPMTCCaGrblLRj8GxJH3EvbOV1j0V58BH9L8KBJbPAlIsl/3CUMcSZRIKl3lUr2g+ OxeFg1TUuz6VAM0zTit4Twa2nps6PCdImuyeXkYnyDjd55MagL+wwolosRsODoHp0toN KzYgpQiWXWBFylSxICNA3Rs0ucdXGpf1cmZ+JFhxHtgSDFlckwsWILjfTMmKOlIzDo0r lVbQzujKqMnoKLsoN45ABcyji8kMz5rdX33x9NftYpEVzo5p1OCaNeGWCn+lW2VAT8Wq 0JLuPLIkdXRLHyJnrpZ9sBViRFm//A5esejrUSNGn/oegqSYne2qWRfLhdgvCma+tf5f /3lQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=GXyy4yHP0CZTf1IBrBojXYAs2I6dwIFFKPaznXSQtH8=; fh=5i4oxtoc8ZM3f5qD61AhO6HOils7k/+q0mmD+7wRao0=; b=XItdhzayyiwTkJ2DeQFKDvmy8t+M+YbUo3Vdu5rzhGbqf6x0Hary58K0ccIW7UOmPe fud0/KKzOS8rOMKzPqlLIgPGVODMtqbkkX+y6R5btvRGI/a8tsMnQtc9m4+ncadIfZ40 bIcxHLykNXIp7HT5FrqNiLIlQxZQkYg2WGi2fIRF9ErhOUQOTGax/hQHmMOtHK1EE5i7 01XtMgubrD+fYPu153bgqJyoJlHTPTUw6LCJBdpRQ0yLBmaS5G+Ep3k0D+OJ1qkUsQSS ACl0CF/7SmfEezw40B2JmLyfoEA9Qh9/PR/rKI+TtCgzPvCdRhzuGCildNSZ0++VAT+S rPCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=g4I28LMd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-131441-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131441-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n12-20020ae9c30c000000b00789e9c45a5asi3485066qkg.141.2024.04.04.05.37.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 05:37:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131441-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=g4I28LMd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-131441-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131441-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A62EC1C21E4C for ; Thu, 4 Apr 2024 12:37:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2505D12B153; Thu, 4 Apr 2024 12:32:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g4I28LMd" Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98CCC6CDDC for ; Thu, 4 Apr 2024 12:32:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712233974; cv=none; b=MYIu0Bw57ygawWe4VHtBx7u3P4s+c6wUWBHe4y6Dp345idAaW77SHJWI26OgptEeHaulYFIrwnObeiT5RObv06Rm/T/IFXaSXpZFYpTtJ1QdSZQxnLSB6nxDFWgktLGG8Ak6h2P7r4Vk1UKRChoiAkU2QBCgHiPsAjDLhD6KoTM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712233974; c=relaxed/simple; bh=FCba+Q7d/nRYVtI/cBtG4cNHzK5S9qSoPYInruzyPS4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=H56EXv6q6uzdhSO7k7rt4LTvXloTaDG7Gx4KJx0f0K75ytoUN5XN05SpOi5mwShY5bLeeVHXiDNwQNAc34qkJOeVRu7Nu0Xi4mwaAEp6yitFzggTDAGAww0UA7OwPkJPY7reAukdFQGLXo1vEdyj7vlC3ArDzJQQTA8nKzTF8vM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g4I28LMd; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-56b0af675deso1035135a12.1 for ; Thu, 04 Apr 2024 05:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712233971; x=1712838771; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=GXyy4yHP0CZTf1IBrBojXYAs2I6dwIFFKPaznXSQtH8=; b=g4I28LMdcSauRzgoGd9NWm2/0Azcdw2i2zH4g9tgLh1oHB31lfA8Caog+Vh9ptF2D3 1FdVHqfkQ/V6yixohcHk2wJcbtLoE2h3d2Ka9VwIRxXKFvx7yowA8ZQ5Pi6a++SwMJHt mC8RRXHceka8IACc0CtlEH1wxqKqP+sJ740KKFxQ3giwuuMkvMDlOkCA9xDSxb3yUOF6 tEkjUq0OlykIHm5Uv8j9R+uvMFF4t2N7f2xd8s0tBE9+8wWFeewVu9591iNjIPN2+CKY /8EiK/XJIiU+npX8uOgrszEsD/4lGw5BDblIAU/uOf65PSQz7FQl2xahCiJkFqxv4Yvn rxKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712233971; x=1712838771; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GXyy4yHP0CZTf1IBrBojXYAs2I6dwIFFKPaznXSQtH8=; b=b1VBHUeekRNFkg7hbquIQhzPKtcfYlVelXMIdc+cKi2PdQWKpUzMHciI8X+oAn2aop lxESN5BGN5/Ij6e+okBfOoxUKwbdJ73N77S9Y9JokffXtp+igNifQqPJjFqy9n0uSlwR 9JvU25+e4XcmL8AfeYCIoJpLsUB40sCSInXbTds2EFzP1LdoomsGP0Ao2BeV9FaiK468 t5WotK4OHSBr+xVZrb2qNpIouOTXViomQDCT5/M1ImHnj76hD7nz+xRbWIq9ZLDs6b9s ukqyNzrap8NCSE/H3h/4Lr+VnL2Z9lAiivl9qa3NsnExKDgFGubrLFwKTZkgnjwrQgg9 JeQw== X-Forwarded-Encrypted: i=1; AJvYcCU7zJBKItJmw4Ac5h0bzAmDxIbFeT/Q8dtnAz5G4IM0DAJqEDu/5qYNTTuizFltm5VJpL9LpxWrrAbGCg2BZXZ4G6ncIzAMJMj4Va60 X-Gm-Message-State: AOJu0YxfzzULUZzhVaiJYSaVx1Zgc+fgP4U3pCChp1968ZIm6rFQCDoY Y3I3B8PIHY1yWGuib/BrLQXNX91g9NON0oB8oomSzmGzF2URckjgvnQEiMM8SlhYwcSGBDxHowq 5SJu16ieQwHaDJS6j5erDYNX9fsc= X-Received: by 2002:a50:8a9a:0:b0:56d:f7ce:e879 with SMTP id j26-20020a508a9a000000b0056df7cee879mr1553500edj.37.1712233970904; Thu, 04 Apr 2024 05:32:50 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240401212002.1191549-1-nunes.erico@gmail.com> <20240401212002.1191549-3-nunes.erico@gmail.com> In-Reply-To: <20240401212002.1191549-3-nunes.erico@gmail.com> From: Qiang Yu Date: Thu, 4 Apr 2024 20:32:39 +0800 Message-ID: Subject: Re: [PATCH 2/2] drm/lima: mask irqs in timeout path before hard reset To: Erico Nunes Cc: anarsoul@gmail.com, dri-devel@lists.freedesktop.org, lima@lists.freedesktop.org, Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , christian.koenig@amd.com, megi@xff.cz, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Reviewed-by: Qiang Yu On Tue, Apr 2, 2024 at 5:20=E2=80=AFAM Erico Nunes = wrote: > > There is a race condition in which a rendering job might take just long > enough to trigger the drm sched job timeout handler but also still > complete before the hard reset is done by the timeout handler. > This runs into race conditions not expected by the timeout handler. > In some very specific cases it currently may result in a refcount > imbalance on lima_pm_idle, with a stack dump such as: > > [10136.669170] WARNING: CPU: 0 PID: 0 at drivers/gpu/drm/lima/lima_devfre= q.c:205 lima_devfreq_record_idle+0xa0/0xb0 > ... > [10136.669459] pc : lima_devfreq_record_idle+0xa0/0xb0 > ... > [10136.669628] Call trace: > [10136.669634] lima_devfreq_record_idle+0xa0/0xb0 > [10136.669646] lima_sched_pipe_task_done+0x5c/0xb0 > [10136.669656] lima_gp_irq_handler+0xa8/0x120 > [10136.669666] __handle_irq_event_percpu+0x48/0x160 > [10136.669679] handle_irq_event+0x4c/0xc0 > > We can prevent that race condition entirely by masking the irqs at the > beginning of the timeout handler, at which point we give up on waiting > for that job entirely. > The irqs will be enabled again at the next hard reset which is already > done as a recovery by the timeout handler. > > Signed-off-by: Erico Nunes > --- > drivers/gpu/drm/lima/lima_sched.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/gpu/drm/lima/lima_sched.c b/drivers/gpu/drm/lima/lim= a_sched.c > index 66841503a618..bbf3f8feab94 100644 > --- a/drivers/gpu/drm/lima/lima_sched.c > +++ b/drivers/gpu/drm/lima/lima_sched.c > @@ -430,6 +430,13 @@ static enum drm_gpu_sched_stat lima_sched_timedout_j= ob(struct drm_sched_job *job > return DRM_GPU_SCHED_STAT_NOMINAL; > } > > + /* > + * The task might still finish while this timeout handler runs. > + * To prevent a race condition on its completion, mask all irqs > + * on the running core until the next hard reset completes. > + */ > + pipe->task_mask_irq(pipe); > + > if (!pipe->error) > DRM_ERROR("%s job timeout\n", lima_ip_name(ip)); > > -- > 2.44.0 >