Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp11040401rwb; Fri, 25 Nov 2022 10:21:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf7y6iNH9oy+XVWjmJgPfouMkbZm0vgp0OWhUuu+Qp4NMbvlVeGH7PytE90aOjMfHpqgcaru X-Received: by 2002:a17:902:f313:b0:186:59e9:20f6 with SMTP id c19-20020a170902f31300b0018659e920f6mr24749742ple.39.1669400472127; Fri, 25 Nov 2022 10:21:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669400472; cv=none; d=google.com; s=arc-20160816; b=aUVf8tAZVSvM/swvyp0yy/fQHmKrNJJK9S731A6RAOpPvc3KKGuq+rjGQIhCaq+IMc e8FTLUXQIKxp0G/QfcB1qi2yrYyfoCqb3FBRLBgB/qkA3UjDyzR5eREWY+3wzraAezJl jT4MIJqqfGtzrA+XCvbIMFe7Sh4E5hJevUvl+q4P9Tnc5vRLzg9ErDiw0mM0SQeJoedV 3YZaMjVdJmgwuuKRB4miUn60TwxHsUn567IQL4NfgHdeGSJqk4VMcY84sPGbNoVujcB3 9eSbsl6C0Muavo4q0/F16pP+ZWiIeVePSvX3KeVlYVUEiQcahZ0VYr9NCXkLypbqUbo+ E2Iw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vQnZdDaeMZRvzZ/f0hEi9Onn6iiUNEza8dUpGkzrSeM=; b=Cfr04TGLDIEgk5EFRs3URcBIDaBQNjfWMFSJfOaTY0vIbKjm9VpiIA65PRFgXcHms8 OL4/7OM0pRRfs5wV/A6oD3hiTqXCiMyu2pS6IWd4qR3oCeCoijp9yeBhVSUPYWAiwNZ/ 8OyE7n4oGYvdIb7bvTNWg7UTIqjvMccCxGRixLwnGvcvoKo/vVVwl90YX8Sie9U+RriY c3g2gCjI0U0V9DWmfitLmmt+mvj9FywmV3VuUFIiIz1+LFMpooZhas0P2dZEbaJ5o5hR HCON7l1D9ztSkV2fW+rP1NwQFfMi/Ot8B021AxzYy1L24xe6HgxaS8dypFUAYjz8WlWb fEMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=eBfRP+3p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mi5-20020a17090b4b4500b0020da3876a77si5055556pjb.119.2022.11.25.10.21.00; Fri, 25 Nov 2022 10:21:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=eBfRP+3p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbiKYRwh (ORCPT + 85 others); Fri, 25 Nov 2022 12:52:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbiKYRwf (ORCPT ); Fri, 25 Nov 2022 12:52:35 -0500 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FD01E0DB for ; Fri, 25 Nov 2022 09:52:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=vQnZdDaeMZRvzZ/f0hEi9Onn6iiUNEza8dUpGkzrSeM=; b=eBfRP+3pYLn7TV2us+hnRzIDk/ u/PT+0Tj/Wck/hBuidjtLiwownsVUSKnoQ/m6CxTwrXC+VxNzJkQEbvMxhPnkWHMOOb7XM0+RA46a UhVTuBUvTfAR+9LVVVz0lDcVKMpQXqttHI4SXQiOIarZoZlmAyslMSY4PfPr1mfigllJdD/XUmF+9 IyT0s1YXh2A9SxDqP3bmqnIIazJ4+UVUVXDgThO+JBhIqJDQHi/e5fcNM9Jq+FkIZ6d/DR37T5gbl ZKkHVwS9Guc6LB4SYhXAqFlEzCJrFpFPZhwH8gQpnhkdfIdPe/H3M5E3D2koBAz/eyi6PqKqYwUvg OvGbfbSw==; Received: from 200-148-10-170.dsl.telesp.net.br ([200.148.10.170] helo=steammachine.lan) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1oycsI-008yzi-Fe; Fri, 25 Nov 2022 18:52:30 +0100 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: kernel-dev@igalia.com, alexander.deucher@amd.com, contactshashanksharma@gmail.com, amaranath.somalapuram@amd.com, christian.koenig@amd.com, pierre-eric.pelloux-prayer@amd.com, Simon Ser , Rob Clark , Andrey Grodzovsky , Pekka Paalanen , Daniel Vetter , Daniel Stone , =?UTF-8?q?=27Marek=20Ol=C5=A1=C3=A1k=27?= , Dave Airlie , "Pierre-Loup A . Griffais" , Shashank Sharma , =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v3 1/2] drm: Add GPU reset sysfs event Date: Fri, 25 Nov 2022 14:52:02 -0300 Message-Id: <20221125175203.52481-2-andrealmeid@igalia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221125175203.52481-1-andrealmeid@igalia.com> References: <20221125175203.52481-1-andrealmeid@igalia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shashank Sharma Add a sysfs event to notify userspace about GPU resets providing: - PID that triggered the GPU reset, if any. Resets can happen from kernel threads as well, in that case no PID is provided - Information about the reset (e.g. was VRAM lost?) Co-developed-by: André Almeida Signed-off-by: André Almeida Signed-off-by: Shashank Sharma --- V3: - Reduce information to just PID and flags - Use pid pointer instead of just pid number - BUG() if no reset info is provided V2: - Addressed review comments from Christian and Amar - move the reset information structure to DRM layer - drop _ctx from struct name - make pid 32 bit(than 64) - set flag when VRAM invalid (than valid) - add process name as well (Amar) --- drivers/gpu/drm/drm_sysfs.c | 26 ++++++++++++++++++++++++++ include/drm/drm_sysfs.h | 13 +++++++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c index 430e00b16eec..85777abf4194 100644 --- a/drivers/gpu/drm/drm_sysfs.c +++ b/drivers/gpu/drm/drm_sysfs.c @@ -409,6 +409,32 @@ void drm_sysfs_hotplug_event(struct drm_device *dev) } EXPORT_SYMBOL(drm_sysfs_hotplug_event); +/** + * drm_sysfs_reset_event - generate a DRM uevent to indicate GPU reset + * @dev: DRM device + * @reset_info: The contextual information about the reset (like PID, flags) + * + * Send a uevent for the DRM device specified by @dev. This informs + * user that a GPU reset has occurred, so that an interested client + * can take any recovery or profiling measure. + */ +void drm_sysfs_reset_event(struct drm_device *dev, struct drm_reset_event_info *reset_info) +{ + unsigned char pid_str[13]; + unsigned char flags_str[18]; + unsigned char reset_str[] = "RESET=1"; + char *envp[] = { reset_str, pid_str, flags_str, NULL }; + + DRM_DEBUG("generating reset event\n"); + + BUG_ON(!reset_info); + + snprintf(pid_str, sizeof(pid_str), "PID=%u", pid_vnr(reset_info->pid)); + snprintf(flags_str, sizeof(flags_str), "FLAGS=0x%llx", reset_info->flags); + kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, envp); +} +EXPORT_SYMBOL(drm_sysfs_reset_event); + /** * drm_sysfs_connector_hotplug_event - generate a DRM uevent for any connector * change diff --git a/include/drm/drm_sysfs.h b/include/drm/drm_sysfs.h index 6273cac44e47..dbb0ac6230b8 100644 --- a/include/drm/drm_sysfs.h +++ b/include/drm/drm_sysfs.h @@ -2,15 +2,28 @@ #ifndef _DRM_SYSFS_H_ #define _DRM_SYSFS_H_ +#define DRM_RESET_EVENT_VRAM_LOST (1 << 0) + struct drm_device; struct device; struct drm_connector; struct drm_property; +/** + * struct drm_reset_event_info - Information about a GPU reset event + * @pid: Process that triggered the reset, if any + * @flags: Extra information around the reset event (e.g. is VRAM lost?) + */ +struct drm_reset_event_info { + struct pid *pid; + uint64_t flags; +}; + int drm_class_device_register(struct device *dev); void drm_class_device_unregister(struct device *dev); void drm_sysfs_hotplug_event(struct drm_device *dev); +void drm_sysfs_reset_event(struct drm_device *dev, struct drm_reset_event_info *reset_info); void drm_sysfs_connector_hotplug_event(struct drm_connector *connector); void drm_sysfs_connector_status_event(struct drm_connector *connector, struct drm_property *property); -- 2.38.1