From patchwork Fri Aug 11 18:55:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 134673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1334968vqi; Fri, 11 Aug 2023 13:21:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXvhWmhzsAuNorxE4kxBVQDUHHnM0pfDiaS0iWfh+/E2NdAoIeJjdMUbn+OyPPrGM6vS0D X-Received: by 2002:a05:6a20:458:b0:134:a8a1:3bf with SMTP id b24-20020a056a20045800b00134a8a103bfmr2755383pzb.30.1691785273581; Fri, 11 Aug 2023 13:21:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691785273; cv=none; d=google.com; s=arc-20160816; b=WAtE5+jxup1gop86MBzoqZulrlF8c9ay6o2kyA+4FVRm48t3BpqpUUqhzEOkH7T93u QFn0qJFYbtJuQ+7J5mlsws5oo6XsW+Wxtx4YSgFLh3kJrqBmvYJLs4M4VB/c+/3u97G0 gqtlyCvtNm2Z9y7QHST/9vgBNP2/PA0MZ4U7iGP4msYlkM94pnMmccQ1V8k376iGldPP WxH88CxzqX777l3mgodEUrkj6rOmZDjiXEALKBrL0HL0RgyMUi/ZM6chN0g8AraMpgMT Gs5IP35YGZTqm+Y/9ciSNZbdaYht14Dadt2dXbATKZ0/r6IVbkZownmNcdx/7BM88/Io YDAg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=rpc/DUjgplEAz24IA0Nc53yNh/mqO8R39tjBJ2uiGRg=; fh=Hj7hGM+Ky9wReyitX9WwxKBhMuxFl31dL/DwxEPLzJ0=; b=wsBeksmtUCQTZFmgIs2VyZgDjhoLRJTa3GbJzLgfkHJ0l9Bao+p/Tte+LHQEjbsgmD UXeO2mn2QqAmv1CjVwUiIvx32WN46zwuiV2kqy4ymQ9ID++si0xuLa1ZMyiwHRshq1f4 EvfCHAK9Ouz9ViH75okiw0VH9j+76XyYI+uDDKu5J2te7ILg9WvlsNl36IX/4bnmXAJX /aDaSFw/hefOVZzYerps3igH5MPOn81pUrtfXZK5DPsOrvD8RGqlcrj6FPjRKFx6QYzd 18G/bo/g7SSTmeNOXGpCcgTraH8FLfCz5uuzC4HurQGe6bICxcVVcBOZXsp5Z3jZYulQ dCRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=B7KpOWP1; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020a6566c4000000b0055c7da0216dsi3898744pgw.635.2023.08.11.13.20.59; Fri, 11 Aug 2023 13:21:13 -0700 (PDT) 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=B7KpOWP1; 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 S235786AbjHKSzZ (ORCPT + 99 others); Fri, 11 Aug 2023 14:55:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbjHKSzY (ORCPT ); Fri, 11 Aug 2023 14:55:24 -0400 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97979A8 for ; Fri, 11 Aug 2023 11:55:22 -0700 (PDT) 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: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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=rpc/DUjgplEAz24IA0Nc53yNh/mqO8R39tjBJ2uiGRg=; b=B7KpOWP1f3ggX3pO/4mshWOYgd HBEL/3KxX/u63kEe81UVBGhS/FchIuyat7Pwv5s6srtdTgIjWAwRLenKINChd8PE7LMT66fHv53ov zcCFtqTr+4eYd3S5U/6wF5bjBssRB7mU5044QY51sq1+t9Jf52aJ09QkbDV0C2M195Njw3wHhEfCx ADSQC/FfRemwuYHs2Tg5pPTaWpk8kAHc3m2SX6P4LpuUamh7ThTo+63AGkTH0kcp+iwrtZ73zQy39 lgD+bBrBHTS4aerUDGUJZS0YNkDBCHcsm1UQnLVxrmnM2AY18LN1NHYoy6PIXrbVHxmUqJyNN5C3L +CuiPoQQ==; Received: from [191.193.179.209] (helo=steammachine.lan) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1qUXI4-00HGeL-GV; Fri, 11 Aug 2023 20:55:16 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= 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, christian.koenig@amd.com, pierre-eric.pelloux-prayer@amd.com, Simon Ser , Rob Clark , Pekka Paalanen , Daniel Vetter , Daniel Stone , =?utf-8?b?J01hcmVrIE9sxaHDoWsn?= , Dave Airlie , =?utf-8?q?Michel_D=C3=A4nzer?= , Samuel Pitoiset , =?utf-8?q?Timur_Krist=C3=B3f?= , Bas Nieuwenhuizen , Randy Dunlap , =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v6] drm/doc: Document DRM device reset expectations Date: Fri, 11 Aug 2023 15:55:08 -0300 Message-ID: <20230811185508.252194-1-andrealmeid@igalia.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 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, URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773965435278099011 X-GMAIL-MSGID: 1773965435278099011 Create a section that specifies how to deal with DRM device resets for kernel and userspace drivers. Signed-off-by: André Almeida --- Changes: - Due to substantial changes in the content, dropped Pekka's Acked-by - Grammar fixes (Randy) - Add paragraph about disabling device resets - Add note about integrating reset tracking in drm/sched - Add note that KMD should return failure for contexts affected by resets and UMD should check for this - Add note about lack of consensus around what to do about non-robust apps v5: https://lore.kernel.org/dri-devel/20230627132323.115440-1-andrealmeid@igalia.com/ --- Documentation/gpu/drm-uapi.rst | 77 ++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/Documentation/gpu/drm-uapi.rst b/Documentation/gpu/drm-uapi.rst index 65fb3036a580..6bfaf7d4c074 100644 --- a/Documentation/gpu/drm-uapi.rst +++ b/Documentation/gpu/drm-uapi.rst @@ -285,6 +285,83 @@ for GPU1 and GPU2 from different vendors, and a third handler for mmapped regular files. Threads cause additional pain with signal handling as well. +Device reset +============ + +The GPU stack is really complex and is prone to errors, from hardware bugs, +faulty applications and everything in between the many layers. Some errors +require resetting the device in order to make the device usable again. This +section describes the expectations for DRM and usermode drivers when a +device resets and how to propagate the reset status. + +Device resets can not be disabled without tainting the kernel, which can lead to +hanging the entire kernel through shrinkers/mmu_notifiers. Userspace role in +device resets is to propagate the message to the application and apply any +special policy for blocking guilty applications, if any. Corollary is that +debugging a hung GPU context require hardware support to be able to preempt such +a GPU context while it's stopped. + +Kernel Mode Driver +------------------ + +The KMD is responsible for checking if the device needs a reset, and to perform +it as needed. Usually a hang is detected when a job gets stuck executing. KMD +should keep track of resets, because userspace can query any time about the +reset status for a specific context. This is needed to propagate to the rest of +the stack that a reset has happened. Currently, this is implemented by each +driver separately, with no common DRM interface. Ideally this should be properly +integrated at DRM scheduler to provide a common ground for all drivers. After a +reset, KMD should reject new command submissions for affected contexts. + +User Mode Driver +---------------- + +After command submission, UMD should check if the submission was accepted or +rejected. After a reset, KMD should reject submissions, and UMD can issue an +ioclt to the KMD to check the reset status, and this can be checked more often +if the UMD requires it. After detecting a reset, UMD will then proceed to report +it to the application using the appropriate API error code, as explained in the +section below about robustness. + +Robustness +---------- + +The only way to try to keep an application working after a reset is if it +complies with the robustness aspects of the graphical API that it is using. + +Graphical APIs provide ways to applications to deal with device resets. However, +there is no guarantee that the app will use such features correctly, and a +userspace that doesn't support robust interfaces (like an non-robust +OpenGL context or API without any robustness support like libva) leave the +robustness handling entirely to the userspace driver. There is no strong +community consensus on what the userspace driver should do in that case, +since all reasonable approaches have some clear downsides. + +OpenGL +~~~~~~ + +Apps using OpenGL should use the available robust interfaces, like the +extension ``GL_ARB_robustness`` (or ``GL_EXT_robustness`` for OpenGL ES). This +interface tells if a reset has happened, and if so, all the context state is +considered lost and the app proceeds by creating new ones. There's no consensus +on what to do to if robustness is not in use. + +Vulkan +~~~~~~ + +Apps using Vulkan should check for ``VK_ERROR_DEVICE_LOST`` for submissions. +This error code means, among other things, that a device reset has happened and +it needs to recreate the contexts to keep going. + +Reporting causes of resets +-------------------------- + +Apart from propagating the reset through the stack so apps can recover, it's +really useful for driver developers to learn more about what caused the reset in +the first place. DRM devices should make use of devcoredump to store relevant +information about the reset, so this information can be added to user bug +reports. + .. _drm_driver_ioctl: IOCTL Support on Device Nodes