From patchwork Mon Apr 3 19:40:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Ashton X-Patchwork-Id: 13198644 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1FF0FC76188 for ; Mon, 3 Apr 2023 19:41:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FD0A10E1AE; Mon, 3 Apr 2023 19:41:19 +0000 (UTC) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7586910E176 for ; Mon, 3 Apr 2023 19:41:16 +0000 (UTC) Received: by mail-wm1-x330.google.com with SMTP id j1-20020a05600c1c0100b003f04da00d07so38749wms.1 for ; Mon, 03 Apr 2023 12:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=froggi.es; s=google; t=1680550875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PFmiqpkCTFnjtf4my3WK3tS/w7ej04x/lzeSFwb3rYY=; b=YqN1soupUIAmrp0wYyCdXGtkFaPd2VA3aa61JIlPlNUHbqDhXCn7/qmBf7b7+opIEk +Fnq3D7BP5l3LBPYU7junoPZ/HyjKcxicHcJ8ypefIMdhiow66RuMP+Waq6MneOrho/C t9C+Vw6OeAWhjKfcsaW/0Yqe4U0lh4IgRFRaA88R3wLHGGi9aH9TYl9Yqnyt6++RdYrC 72stou26QuIyZ7qwRzradlWGiQnRO0I6pPPiKmDZ8DutPSI4CF/KDcQEtCxhiPWFN1jo n3NqqVOIxQ8RjaV/J0ZAleVDZnL+UW0oGqki4Pf5IvTmZh+FwHpDK2o46Rymsz9gI9O1 eEEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680550875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PFmiqpkCTFnjtf4my3WK3tS/w7ej04x/lzeSFwb3rYY=; b=7cNhIPXlhNxFZx9I0IbY9V3VztHgA9QVJZHPDwaTKZTUbGmdnqE+1L+gq2WXNC7lrO A4Cam/5Kd876R/E3jpT7TgbOazGIpJ62diE611qqT1RY0JTdIlNhUxtoEly09U0BOK66 ASEeKsdTsG1GWUZfUcKfHlS+jGdvaWqfvhkAmJjbmV+g0JdaTUjur3KUL0149/sb2F9h v22OoXjYn3LGqtvbByzqaDWrIWk8cvshztdMVAzVOGoK8fHobAm4S6Idh12SKi1eRXuI 9myPdd0hVHtSF8Qz46Wq6VgTjtuL7BguVzZJsTUxuN/haE+HSf10kWo9dttkYTv7PdwL +ncw== X-Gm-Message-State: AAQBX9fXoRKkoV7T0WCGZxmgtMEJnBiMyc5moIEW/TtqdZZmePb6ROeL qFe878s9zMi6l0VWHND7+hl+r/j8e2DlwXScoR8= X-Google-Smtp-Source: AKy350Yh5yTxinihKbIM/Y9VPkw8VbxSG/Vln+iAV1Ckvhwi3vj/k7P3pOEQHDVlZsqUxvhLHD9fsg== X-Received: by 2002:a7b:c4d3:0:b0:3ed:b590:96e6 with SMTP id g19-20020a7bc4d3000000b003edb59096e6mr417958wmk.4.1680550874973; Mon, 03 Apr 2023 12:41:14 -0700 (PDT) Received: from localhost.localdomain (darl-09-b2-v4wan-165404-cust288.vm5.cable.virginm.net. [86.17.61.33]) by smtp.gmail.com with ESMTPSA id u17-20020a7bcb11000000b003ef5db16176sm13036342wmj.32.2023.04.03.12.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 12:41:14 -0700 (PDT) From: Joshua Ashton To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [RFC PATCH 1/4] drm/scheduler: Add DRM_SCHED_PRIORITY_VERY_HIGH Date: Mon, 3 Apr 2023 20:40:55 +0100 Message-Id: <20230403194058.25958-2-joshua@froggi.es> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230403194058.25958-1-joshua@froggi.es> References: <20230403194058.25958-1-joshua@froggi.es> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joshua Ashton Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This allows AMDGPU scheduler priority above normal to be expressed using the DRM_SCHED_PRIORITY enum. Signed-off-by: Joshua Ashton --- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +- drivers/gpu/drm/msm/msm_gpu.h | 2 +- include/drm/gpu_scheduler.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c index d2139ac12159..8ec255091c4a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c @@ -79,7 +79,7 @@ amdgpu_ctx_to_drm_sched_prio(int32_t ctx_prio) return DRM_SCHED_PRIORITY_HIGH; case AMDGPU_CTX_PRIORITY_VERY_HIGH: - return DRM_SCHED_PRIORITY_HIGH; + return DRM_SCHED_PRIORITY_VERY_HIGH; /* This should not happen as we sanitized userspace provided priority * already, WARN if this happens. diff --git a/drivers/gpu/drm/msm/msm_gpu.h b/drivers/gpu/drm/msm/msm_gpu.h index fc1c0d8611a8..e3495712b236 100644 --- a/drivers/gpu/drm/msm/msm_gpu.h +++ b/drivers/gpu/drm/msm/msm_gpu.h @@ -336,7 +336,7 @@ struct msm_gpu_perfcntr { * DRM_SCHED_PRIORITY_KERNEL priority level is treated specially in some * cases, so we don't use it (no need for kernel generated jobs). */ -#define NR_SCHED_PRIORITIES (1 + DRM_SCHED_PRIORITY_HIGH - DRM_SCHED_PRIORITY_MIN) +#define NR_SCHED_PRIORITIES (1 + DRM_SCHED_PRIORITY_VERY_HIGH - DRM_SCHED_PRIORITY_MIN) /** * struct msm_file_private - per-drm_file context diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index 9935d1e2ff69..a62071660602 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -55,6 +55,7 @@ enum drm_sched_priority { DRM_SCHED_PRIORITY_MIN, DRM_SCHED_PRIORITY_NORMAL, DRM_SCHED_PRIORITY_HIGH, + DRM_SCHED_PRIORITY_VERY_HIGH, DRM_SCHED_PRIORITY_KERNEL, DRM_SCHED_PRIORITY_COUNT, From patchwork Mon Apr 3 19:40:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Ashton X-Patchwork-Id: 13198646 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B1F9C761AF for ; Mon, 3 Apr 2023 19:41:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DD63F10E2E8; Mon, 3 Apr 2023 19:41:21 +0000 (UTC) Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by gabe.freedesktop.org (Postfix) with ESMTPS id A16CF10E176 for ; Mon, 3 Apr 2023 19:41:17 +0000 (UTC) Received: by mail-wr1-x434.google.com with SMTP id y14so30548657wrq.4 for ; Mon, 03 Apr 2023 12:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=froggi.es; s=google; t=1680550876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oU+L5nIaiDPDPyp7C6mhI8cKJn6SnKYd8OI0WaI/OCc=; b=hrkjpiLs2p89GoYvmMQvTNwCnAlkV+809xMgqK+qRerqH20me7sRj0tdKFBLmPa1Yt CwmwP5YjbavaNpn7EiMwwkj+8UN6tG7ns4x5a4Ghw/7oH7CrB5dTliV8uwhl1Sga1/1o 0MF8J3DbDFjCFqsZNNIwS1ZDeRq9X41WtIr41rz0ZSMBK45EFJxiSdLMbMCZz64de/DB k+a1N8iuegfqqngvIH3tGZjEjP5TUkQ645/FCk9zpJgSny+DWikIY/wYdQZJTFwPGLY5 TXfI5YTMxotKOdsZ67RVCD82zShFgosrpP0e7K9PF1uKnyNirBpZHmgRJvroyOBCPdU4 TYEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680550876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oU+L5nIaiDPDPyp7C6mhI8cKJn6SnKYd8OI0WaI/OCc=; b=e3vD3r27OwBaYi3ZKYlAopTJ9e2ZHWxX+4rk4skOM5DTBySz1bI+yUc7YeZkPps272 fuZEGN9aSM0dOASGX5dwuFe1DJJ3PTm78HfDFuLnWw6bd2rOoOqxyuO+y+4vovXkcEb6 7SL2/3kOOI3ZhECcyA5kGsTuGwZYppiEmUcawJ6AAuZtms++My8STkwv1qrn2Yi3CwxJ f09eUCQUnmiX8RkD5T0OitrSUPouuls2V6erXf7fHO3IQEzrcoMazczVyiHY4g7Q6SeV PA31xSwZBo1xIaNRscLrBaX1jf0AKeTyi9YEUS4rU9Lw06WpRV0Zw54a5z2ZbAVT+H4Z 2TBw== X-Gm-Message-State: AAQBX9cpRLjV6M0AWGkFNckYlOKXW/6nEXIUtdGR64pkF2ZkW1asczc8 4qiXykmoX630DdokX8cwfdU2qvpPr/AnUQWLPxE= X-Google-Smtp-Source: AKy350Y6QcVh3jMCJP1CeIEoEigMyHei8BCcc6GYjm2rfJ9DP96MlxtUrUdIv9DDl/8lZGk89hJDxQ== X-Received: by 2002:a5d:458f:0:b0:2ce:a703:1937 with SMTP id p15-20020a5d458f000000b002cea7031937mr26791351wrq.50.1680550875792; Mon, 03 Apr 2023 12:41:15 -0700 (PDT) Received: from localhost.localdomain (darl-09-b2-v4wan-165404-cust288.vm5.cable.virginm.net. [86.17.61.33]) by smtp.gmail.com with ESMTPSA id u17-20020a7bcb11000000b003ef5db16176sm13036342wmj.32.2023.04.03.12.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 12:41:15 -0700 (PDT) From: Joshua Ashton To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [RFC PATCH 2/4] drm/scheduler: Split out drm_sched_priority to own file Date: Mon, 3 Apr 2023 20:40:56 +0100 Message-Id: <20230403194058.25958-3-joshua@froggi.es> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230403194058.25958-1-joshua@froggi.es> References: <20230403194058.25958-1-joshua@froggi.es> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joshua Ashton Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This allows it to be used by other parts of the codebase without fear of a circular include dependency being introduced. Signed-off-by: Joshua Ashton --- include/drm/drm_sched_priority.h | 41 ++++++++++++++++++++++++++++++++ include/drm/gpu_scheduler.h | 15 +----------- 2 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 include/drm/drm_sched_priority.h diff --git a/include/drm/drm_sched_priority.h b/include/drm/drm_sched_priority.h new file mode 100644 index 000000000000..85a7bb011e27 --- /dev/null +++ b/include/drm/drm_sched_priority.h @@ -0,0 +1,41 @@ +/* + * Copyright 2015 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef _DRM_SCHED_PRIORITY_H_ +#define _DRM_SCHED_PRIORITY_H_ + +/* These are often used as an (initial) index + * to an array, and as such should start at 0. + */ +enum drm_sched_priority { + DRM_SCHED_PRIORITY_MIN, + DRM_SCHED_PRIORITY_NORMAL, + DRM_SCHED_PRIORITY_HIGH, + DRM_SCHED_PRIORITY_VERY_HIGH, + DRM_SCHED_PRIORITY_KERNEL, + + DRM_SCHED_PRIORITY_COUNT, + DRM_SCHED_PRIORITY_UNSET = -2 +}; + +#endif diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index a62071660602..9228ff0d515e 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -29,6 +29,7 @@ #include #include #include +#include #define MAX_WAIT_SCHED_ENTITY_Q_EMPTY msecs_to_jiffies(1000) @@ -48,20 +49,6 @@ struct drm_gem_object; struct drm_gpu_scheduler; struct drm_sched_rq; -/* These are often used as an (initial) index - * to an array, and as such should start at 0. - */ -enum drm_sched_priority { - DRM_SCHED_PRIORITY_MIN, - DRM_SCHED_PRIORITY_NORMAL, - DRM_SCHED_PRIORITY_HIGH, - DRM_SCHED_PRIORITY_VERY_HIGH, - DRM_SCHED_PRIORITY_KERNEL, - - DRM_SCHED_PRIORITY_COUNT, - DRM_SCHED_PRIORITY_UNSET = -2 -}; - /* Used to chose between FIFO and RR jobs scheduling */ extern int drm_sched_policy; From patchwork Mon Apr 3 19:40:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Ashton X-Patchwork-Id: 13198645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3B2BC76188 for ; Mon, 3 Apr 2023 19:41:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DFE2110E1A6; Mon, 3 Apr 2023 19:41:20 +0000 (UTC) Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by gabe.freedesktop.org (Postfix) with ESMTPS id 270A210E176 for ; Mon, 3 Apr 2023 19:41:18 +0000 (UTC) Received: by mail-wr1-x436.google.com with SMTP id y14so30548687wrq.4 for ; Mon, 03 Apr 2023 12:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=froggi.es; s=google; t=1680550876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HdKXVkAVOqX9vK99Q2g5Z+5QvHFDzkHWbDD4urN+YpM=; b=MGFH3KHyvJPi7+iWaRXLrIdFo4TAx4Yd8kqhc5xXzrtsrsl2Wxc3ASN1wGO7kRc7VF QyLSJaF1vnfW06Rmp0+U4dd6UuETmVctr4BZPeDSet6uRjo7fXfhC52EFnxwQ9M7SJ7V X4KAJ8y2/DK3IZQ28qnPOLLmI77Ru6oarOnIA28+7ILZUXjaVhe+EMSm6iAGz2U0jXcz GShsIaU7w+z9ZAk59TMv7YFI/4M3rPhSAVjmocX0xjC/jlAJ4cKFkGJJ8yycKIBtCvFT 6Trg4LyLvXvX4N3/fDq3CJOVKHXG8ytqCxvOk1X0uIbz/jznXVnNm1VJgOWhmyAY9FIb 6D2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680550876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HdKXVkAVOqX9vK99Q2g5Z+5QvHFDzkHWbDD4urN+YpM=; b=6aXK/bmB3ROujLoWf7yC17DMPGDVRt0E7YmYBO10Ht0ksSyp2qZpiY+1s9TDdArTJP lAzQ38Flu+L1omGAdzB2dqBcE00HFDAm0Rn2xIyPlNuKj6m8ZF75AOvXHv8yZO2ucjF4 AVBdpTWWF9xkKF5udgTKPRqzUl7wRSgxe5zk74U0b2DXLSRoGbRB9iDQ/U02QklUBWSg AQ9ks25Hj/9muj1p2KRlip+kqMrXfFybes6vuWltLHGFclRGCFqlgq+JM6BRxtQRmxVJ Nx8ruOGvF8RfuWjRLmO10ep4OOsERoaH52MCK7fuZziFsDZ2hc0M6LfpvTqCXkKiedxX QSTQ== X-Gm-Message-State: AAQBX9fxpeXCjhdnKKW1/hAexOpKggNg1nYMgOWia86f/b1PD4OseCgC tW1fXNc6L2j7HD8pfRv+BnHbn2/P62+NM9iNQsI= X-Google-Smtp-Source: AKy350a0CUTa/6G0VaCS6DSNTzq+edRh7ekL35jspvxMho65Mu8MeqFKneOW/a0LnHPTyQXGPRqx8w== X-Received: by 2002:a5d:67cd:0:b0:2d7:babe:104c with SMTP id n13-20020a5d67cd000000b002d7babe104cmr26935034wrw.15.1680550876616; Mon, 03 Apr 2023 12:41:16 -0700 (PDT) Received: from localhost.localdomain (darl-09-b2-v4wan-165404-cust288.vm5.cable.virginm.net. [86.17.61.33]) by smtp.gmail.com with ESMTPSA id u17-20020a7bcb11000000b003ef5db16176sm13036342wmj.32.2023.04.03.12.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 12:41:16 -0700 (PDT) From: Joshua Ashton To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [RFC PATCH 3/4] uapi: Add RLIMIT_GPUPRIO Date: Mon, 3 Apr 2023 20:40:57 +0100 Message-Id: <20230403194058.25958-4-joshua@froggi.es> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230403194058.25958-1-joshua@froggi.es> References: <20230403194058.25958-1-joshua@froggi.es> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joshua Ashton Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Introduce a new RLIMIT that allows the user to set a runtime limit on the GPU scheduler priority for tasks. This avoids the need for leased compositors such as SteamVR's vrcompositor to be launched via a setcap'ed executable with CAP_SYS_NICE. This is required for SteamVR as it doesn't run as a DRM master, but rather on a DRM lease using the HMD's connector. The current situation is bad for a few reasons, one being that in order to setcap the executable, typically one must run as root which involves a pretty high privelage escalation in order to achieve one small feat, a realtime async compute queue queue for VR or a compositor. The executable cannot be setcap'ed inside a container nor can the setcap'ed executable be run in a container with NO_NEW_PRIVS. Even in cases where one may think the DRM master check to be useful, such as Gamescope where it is the DRM master, the part of the compositor that runs as the DRM master is entirely separate to the Vulkan device with it's own DRM device fd doing the GPU work that demands the realtime priority queue. Additionally, Gamescope can also run nested in a traditional compositor where there is no DRM master, but having a realtime queue is still advantageous. With adding RLIMIT_GPUPRIO, a process outside of a container or eg. rtkit could call `prlimit` on the process inside to allow it to make a realtime queue and solve these problems. Signed-off-by: Joshua Ashton --- fs/proc/base.c | 1 + include/asm-generic/resource.h | 3 ++- include/uapi/asm-generic/resource.h | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 5e0e0ccd47aa..a5c9a9f23f08 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -589,6 +589,7 @@ static const struct limit_names lnames[RLIM_NLIMITS] = { [RLIMIT_NICE] = {"Max nice priority", NULL}, [RLIMIT_RTPRIO] = {"Max realtime priority", NULL}, [RLIMIT_RTTIME] = {"Max realtime timeout", "us"}, + [RLIMIT_GPUPRIO] = {"Max DRM GPU priority", NULL}, }; /* Display limits for a process */ diff --git a/include/asm-generic/resource.h b/include/asm-generic/resource.h index 8874f681b056..cefee1a8d9db 100644 --- a/include/asm-generic/resource.h +++ b/include/asm-generic/resource.h @@ -3,7 +3,7 @@ #define _ASM_GENERIC_RESOURCE_H #include - +#include /* * boot-time rlimit defaults for the init task: @@ -26,6 +26,7 @@ [RLIMIT_NICE] = { 0, 0 }, \ [RLIMIT_RTPRIO] = { 0, 0 }, \ [RLIMIT_RTTIME] = { RLIM_INFINITY, RLIM_INFINITY }, \ + [RLIMIT_GPUPRIO] = { DRM_SCHED_PRIORITY_NORMAL, DRM_SCHED_PRIORITY_NORMAL }, \ } #endif diff --git a/include/uapi/asm-generic/resource.h b/include/uapi/asm-generic/resource.h index f12db7a0da64..85027b07a420 100644 --- a/include/uapi/asm-generic/resource.h +++ b/include/uapi/asm-generic/resource.h @@ -46,7 +46,8 @@ 0-39 for nice level 19 .. -20 */ #define RLIMIT_RTPRIO 14 /* maximum realtime priority */ #define RLIMIT_RTTIME 15 /* timeout for RT tasks in us */ -#define RLIM_NLIMITS 16 +#define RLIMIT_GPUPRIO 16 /* maximum GPU priority */ +#define RLIM_NLIMITS 17 /* * SuS says limits have to be unsigned. From patchwork Mon Apr 3 19:40:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Ashton X-Patchwork-Id: 13198647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36A10C77B62 for ; Mon, 3 Apr 2023 19:41:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0E3CB10E542; Mon, 3 Apr 2023 19:41:22 +0000 (UTC) Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4CF9610E18C for ; Mon, 3 Apr 2023 19:41:19 +0000 (UTC) Received: by mail-wm1-x333.google.com with SMTP id r19-20020a05600c459300b003eb3e2a5e7bso18766553wmo.0 for ; Mon, 03 Apr 2023 12:41:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=froggi.es; s=google; t=1680550877; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jeihcfukgEVdleWTzZvtjv81OMqMHDJ4MNDRBvosf9w=; b=QAChqaneuBG+aMnrz0m53k+wnMZ8xvjACevW8eT4V+BciT++1q+2YGIM7bpuHE7CbS 7nYPi30ASA4H+rjTbV6JbJAgyBgmGsUv6tg2h3sFQYDrqOTQwV2v4ZYlXqvAH+FLuiM3 V9n7i5fzaN3AAYTB/pHZugYEF4AJkwuhH9mnY9Y8IjKczce0ttduntpy/qJGu5reGwWs wemQ+ZWyoVKz7aVsQlu5qt3XyBiHcdXBIvGiY1nUnsNT6KwnXgIW86qm6kTnSOXdK5+i dMs0AdlHjl21IbXBr0A/qj67SdQ4XWw9IDOemtglSbdmUpfhHl/GBuYm2EtQ4r5xfUvg 2f5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680550877; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jeihcfukgEVdleWTzZvtjv81OMqMHDJ4MNDRBvosf9w=; b=Hw3Q8aCvykmJlB0xO7ma1qmLB9pra17v0pnY/CmLRuB8CnKHPmSEVrDRErW/Oeb6sd GNPhd7ZmRANu6B+TAmovcCEB1xu7KafHUpsj3NTcg+6lNehJN+dHgd2ehAiBJquQmElF 4oaSWpQtHHudTu8jU/sCFLKIOvfHx/WUi7ti7/sKPYcN5qhy72LHx7dnZMNsZKn0AsLm NguBnALDc1x4oUH+XK3lp9ckBIPp9qykyOAu2ukZw+umOKe45Vf9PxKRNIL5p03UWdeD WIMW1dTDH17kijK3dT3FW+eNVHCX7SBLT1mJLqK1ycv9D9ln60indwENQIbalQBIR+Eu YvAA== X-Gm-Message-State: AAQBX9cFTIWU2ZHVQKoSxX0ieyeBKJzoq1YyKZpqov3RQBIc1VZuipN5 zXqDO8b2cRKRpzBZuILplUFT8HkUy8jWxuuXA20= X-Google-Smtp-Source: AKy350ZugkhHY/2mxIMYNHBkqx30+syG2zupYyi0bllEk5Jq3cP7PWoj1FUolku4GnuaseopCZmD0A== X-Received: by 2002:a05:600c:225a:b0:3ed:9576:34ce with SMTP id a26-20020a05600c225a00b003ed957634cemr421533wmm.9.1680550877507; Mon, 03 Apr 2023 12:41:17 -0700 (PDT) Received: from localhost.localdomain (darl-09-b2-v4wan-165404-cust288.vm5.cable.virginm.net. [86.17.61.33]) by smtp.gmail.com with ESMTPSA id u17-20020a7bcb11000000b003ef5db16176sm13036342wmj.32.2023.04.03.12.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 12:41:17 -0700 (PDT) From: Joshua Ashton To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [RFC PATCH 4/4] drm/amd/amdgpu: Check RLIMIT_GPUPRIO in priority permissions Date: Mon, 3 Apr 2023 20:40:58 +0100 Message-Id: <20230403194058.25958-5-joshua@froggi.es> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230403194058.25958-1-joshua@froggi.es> References: <20230403194058.25958-1-joshua@froggi.es> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joshua Ashton Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add support for the new RLIMIT_GPUPRIO when doing the priority checks creating an amdgpu_ctx. Signed-off-by: Joshua Ashton --- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c index 8ec255091c4a..4ac645455bc1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c @@ -28,6 +28,8 @@ #include "amdgpu_sched.h" #include "amdgpu_ras.h" #include +#include +#include #define to_amdgpu_ctx_entity(e) \ container_of((e), struct amdgpu_ctx_entity, entity) @@ -94,11 +96,16 @@ amdgpu_ctx_to_drm_sched_prio(int32_t ctx_prio) static int amdgpu_ctx_priority_permit(struct drm_file *filp, int32_t priority) { + enum drm_sched_priority in_drm_priority, rlim_drm_priority; + if (!amdgpu_ctx_priority_is_valid(priority)) return -EINVAL; - /* NORMAL and below are accessible by everyone */ - if (priority <= AMDGPU_CTX_PRIORITY_NORMAL) + /* Check priority against RLIMIT to see what is allowed. */ + in_drm_priority = amdgpu_ctx_to_drm_sched_prio(priority); + rlim_drm_priority = (enum drm_sched_priority)rlimit(RLIMIT_GPUPRIO); + + if (in_drm_priority <= rlim_drm_priority) return 0; if (capable(CAP_SYS_NICE))