From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA95A234969 for ; Mon, 13 Jan 2025 08:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736757808; cv=none; b=m2gk18Wegi9oCBpDwLSC6MIS8Syqt0mNV31AdeIGZ30PPG01Zsurj0vZ0xmnpyY6Z/5PUNVma141uU3GJsl1FJidZdDEpnd/diBDj16m+FL+xkNo6kQ3tgJ3gAp6CDvGTsmrEwznAsRNBSaJfIKcr0lhEcK4bPRpFYnG2q43+HE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736757808; c=relaxed/simple; bh=//d5wi9/EdmI+fVVzxJHzPhIlbwreeTF/f4oDiSFxCE=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=dHrZU/JaGCboJr8Vm8kO9QDvHjMEMdHA9CxCcDuUE9BsGXk76RBiI9mTYBZyYcCsluWcNVzonuMvjOBUG4fs0Cimn+ZT86vQ+LggSGrcKZbLqn+FW4OU0BkGGK+L8YBRxxx3hmYIcLdPrOSYmEowIGgQwoQ/p/WVX2tEh2x7D8s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Whg+Cjok; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Whg+Cjok" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736757805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=//d5wi9/EdmI+fVVzxJHzPhIlbwreeTF/f4oDiSFxCE=; b=Whg+CjokPf4xpYOL3sDlPb71SAIuU66nnG3xn5p/JjajSyWGok5mDNJlmHgLkO+MIcWNh3 NIdnytaXUTSO8i8V8UC9Edch4J9bDt7MMndbOspKGJ+Garv78GXvQWazNbHyF3aGuGszuS YoQFgLrUihNpNizH31qDqbL1fmnT7VI= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-MwdeLRw4Nm-Mi7s7PhA6Ig-1; Mon, 13 Jan 2025 03:43:23 -0500 X-MC-Unique: MwdeLRw4Nm-Mi7s7PhA6Ig-1 X-Mimecast-MFC-AGG-ID: MwdeLRw4Nm-Mi7s7PhA6Ig Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-216405eea1fso74146725ad.0 for ; Mon, 13 Jan 2025 00:43:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736757802; x=1737362602; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=//d5wi9/EdmI+fVVzxJHzPhIlbwreeTF/f4oDiSFxCE=; b=on3iF/HZ6JQb9UAK/OfUlsyHJyUuI8PamyuDHHKPUqM+ihb/v1o1I3Z6DvnYL6BOzS TbMXlOCVqFPRcNWkjxtLaBAwceZNIJqYFxwA7xfhmEaF/eFwVmcH28WgssNrsXY2HHds aIwUPLJrTFiVtPxGQfJSzxoX2jacJOBHT3q9b8y3rqscgh5trLWALUneS4cwnmD2ZjWD YsAjzSGorIqV3r7mrGm+BNcCsrMX3j9NQDmt0Xj0xqIjtobJS7PH2UXjPLdGh1sz2Z82 GG7zd9t/X1cuFYJdzAbBlx6MPLUIPVopMpPtyfMpx4dQcB8hYAaa67o29AW6+hfo2yw7 5ERg== X-Forwarded-Encrypted: i=1; AJvYcCWJa1nRhFsCVKaEyFeMO4oXrmiMprO1iInXv/NOktfdvq6OGGS8YJoP94QERW4Es2b2nyHaS6npX4s4/MA=@vger.kernel.org X-Gm-Message-State: AOJu0YwVUsKX4ZQWaKf4aMx9UkMaTKt/mdksSnmkerS9J094Qw1xZxyO 8Wt199f0OEAaaDGmpyswgz2hAB+8dGY8avWIvedm96+egQ4lAtc4pxt4fo/M7OWRElffSqYq7Y8 diZG7XpeyAXGkyKtG5TNNh8zLqyLLM+U7FRY7awfS/JSrwmn36Be3A8gSggKu2ujma7v1Jw== X-Gm-Gg: ASbGncuDu2U8dIvOOpS9WDj7JJx7RM0LSSFfZg1K+B5U/wBwGYTpYCTUsoacjRdNwih 6T2GrFyNIYcCk6zN28KxrMHAisM9UHlRgLG/V6HlIhMZdNIQDXxG7LI4XGwHUw8+ZLt4OBiS4NF 8Tcmt7e90CMT2iOglxXt3gkbK/P5KiAgTyWYLvKFuqQDji0+4BzZhpY62lFP4kSjIK4jRMkE3mb JO427sUrMHaeMGG4maLmckgdtRp5kQHA/etSPq1wlWpzkXjVKBSlFUkpsKRMcSAQyV0NoGankFv EYod6Dc= X-Received: by 2002:a17:902:f70f:b0:216:2a36:5b2a with SMTP id d9443c01a7336-21a83fcc890mr310103895ad.47.1736757802059; Mon, 13 Jan 2025 00:43:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IET7vlOZMmOlKp79sXTHWskQAC0dSlxlxxL5k3Rks0LDtj7tszxra4guuOgbVOVGjZY/gcMAg== X-Received: by 2002:a17:902:f70f:b0:216:2a36:5b2a with SMTP id d9443c01a7336-21a83fcc890mr310103685ad.47.1736757801731; Mon, 13 Jan 2025 00:43:21 -0800 (PST) Received: from [10.200.68.91] (nat-pool-muc-u.redhat.com. [149.14.88.27]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f22ef8fsm48838635ad.198.2025.01.13.00.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 00:43:21 -0800 (PST) Message-ID: <582e10673bb749f18ebf8a18f46ca573df396576.camel@redhat.com> Subject: Re: [PATCH] drm/sched: Fix amdgpu crash upon suspend/resume From: Philipp Stanner To: Christian =?ISO-8859-1?Q?K=F6nig?= , Philipp Reisner Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Simona Vetter , Danilo Krummrich , Philipp Stanner Date: Mon, 13 Jan 2025 09:43:12 +0100 In-Reply-To: References: <20250107140240.325899-1-philipp.reisner@linbit.com> <942c02f2-6496-4406-a73b-941d096aadfb@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.4 (3.52.4-2.fc40) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 +cc Danilo +cc myself On Wed, 2025-01-08 at 09:19 +0100, Christian K=C3=B6nig wrote: > Am 07.01.25 um 16:21 schrieb Philipp Reisner: > > [...] > > > > The OOPS happens because the rq member of entity is NULL in > > > > drm_sched_job_arm() after the call to > > > > drm_sched_entity_select_rq(). > > > >=20 > > > > In drm_sched_entity_select_rq(), the code considers that > > > > drb_sched_pick_best() might return a NULL value. When NULL, it > > > > assigns > > > > NULL to entity->rq even if it had a non-NULL value before. > > > >=20 > > > > drm_sched_job_arm() does not deal with entities having a rq of > > > > NULL. > > > >=20 > > > > Fix this by leaving the entity on the engine it was instead of > > > > assigning a NULL to its run queue member. > > > Well that is clearly not the correct approach to fixing this. So > > > clearly > > > a NAK from my side. > > >=20 > > > The real question is why is amdgpu_cs_ioctl() called when all of > > > userspace should be frozen? > > >=20 > > > Regards, > > > Christian. > > >=20 > > Could the OOPS happen at resume time? Might it be that the kernel > > activates user-space > > before all the components of the GPU finished their wakeup? > >=20 > > Maybe drm_sched_pick_best() returns NULL since no scheduler is > > ready yet? >=20 > Yeah that is exactly what I meant. It looks like either the suspend > or=20 > the resume order is somehow messed up. >=20 > In other words either some application tries to submit GPU work while > it=20 > should already been stopped, or it tries to submit GPU work before it > is=20 > started. >=20 > > Apart from whether amdgpu_cs_ioctl() should run at this point, I > > still think the > > suggested change improves the code. drm_sched_pick_best() can > > return NULL. > > drm_sched_entity_select_rq() can handle the NULL (partially). > >=20 > > drm_sched_job_arm() crashes on an entity that has rq set to NULL. >=20 > Which is actually not the worst outcome :) >=20 > With your patch applied we don't immediately crash any more in the=20 > submission path, but the whole system could then later deadlock > because=20 > the core memory management waits for a GPU submission which never > returns. >=20 > That is an even worse situation because you then can't pinpoint any > more=20 > where that is coming from. >=20 > > The handling of NULL values is half-baked. > >=20 > > In my opinion, you should define if drm_sched_pick_best() may put a > > NULL into > > rq. If your answer is yes, it might put a NULL there; then, there > > should be a > > BUG_ON(!entity->rq) after the invocation of > > drm_sched_entity_select_rq(). > > If your answer is no, the BUG_ON() should be in > > drm_sched_pick_best(). >=20 > Yeah good point. >=20 > We might not want a BUG_ON(), that is only justified when we prevent=20 > further damage (e.g. random data corruption or similar). >=20 > I suggest using a WARN(!shed, "Submission without activated > sheduler!").=20 > This way the system has at least a chance of survival should the=20 > scheduler become ready later on. >=20 > On the other hand the BUG_ON() or the NULL pointer deref should only=20 > kill the application thread which is submitting something before the=20 > driver is resumed. So that might help to pinpoint where the actually=20 > issue is. As I see it the BUG_ON() would just be a more pretty NULL pointer deref. If we agree that this is effectively a misuse of the scheduler API we probably want to add it to make it more pretty, though? @Philipp: BTW, I only just discovered this thread by coincidence. Please use get_maintainer. The scheduler currently has 4 maintainers, and none of them is on CC. Danke, P. >=20 > Regards, > Christian. >=20 > >=20 > > That helps guys with zero domain knowledge, like me, to figure out > > how > > this is all > > supposed to work. > >=20 > > best regards, > > =C2=A0 Philipp >=20