From patchwork Sun Feb 14 09:16:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 8301581 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0D2CFC02AA for ; Sun, 14 Feb 2016 09:17:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 04E1A203E3 for ; Sun, 14 Feb 2016 09:17:50 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 4D956203DA for ; Sun, 14 Feb 2016 09:17:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1975E6E41A; Sun, 14 Feb 2016 01:17:47 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2541F6E41A for ; Sun, 14 Feb 2016 01:17:46 -0800 (PST) Received: by mail-wm0-f65.google.com with SMTP id c200so10624917wme.0 for ; Sun, 14 Feb 2016 01:17:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D75fMy3SrdnowUU4nqdKyFvjG+snx+dSoUag10Ju+E8=; b=XI/J0HofbHA4KIOtLlEL6Tv0oKjUK5v9P8YwE69nVxf2YWW5hxFcAovl/tr/t08MSI lLYqVjVPBzixuevieR4v7H3I2X2irjp8nSlcKd/0pNvorMwbRLAVdBmZ8ujz2Bp6qVZW v8+IELxddHd/W+nsLNACDMVlElgtZ08GvyiFWRX4oQ41fDQwDrhIu4Ux6T9S9P7rvsOK Mx7596CFLGKcWTxeFEhhrFK94Y6UHsgX0t1u80P7Ju7L6EzfRniWwZByVSfsqZvNUFGB TSDtRglpfx5gYxW1hZhip6I/3A1KDPVbSq4XE84XNyYJFN8bEwnaSMdNF5ZDX65nuTDx Hoyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=D75fMy3SrdnowUU4nqdKyFvjG+snx+dSoUag10Ju+E8=; b=ImCemAlhSmkRQsw0kMIfFET5S98cQ64+t8DRhXSUhgvyz58Wx4LHp+owchGL19+7CN 4ExN0uUoiVJYCjz0tjqhApE0z/eRDxH5wUcXjN9cXy0avRMRRqiDbTc0G9/Fd82Pk8Ps 6/4Q9zl6ev0ACARlVlg6TWodZAUD5FyQtKvgqoPG6tXhaSmfabDi4k9E/0ugx6fMd2nl PM2c79HrAPwggVourdT/3AyQqoz7F2spKdsxbqBdKFinoO1jzwRB5EyhSSb285WYBaEF 2Ytrp5SrIqbTRf1EM5XAGPsS+ewIII136vcBW8jiPdthoyo+OA99b3QSBxagJOfjZPWk 9Otw== X-Gm-Message-State: AG10YOR0FOyHEJIu7BQTTCq6YEQN/LKAFCYAGKFH0CygcPK75xAaENitY3zdEyGeiJGGzw== X-Received: by 10.28.46.82 with SMTP id u79mr7041896wmu.67.1455441419863; Sun, 14 Feb 2016 01:16:59 -0800 (PST) Received: from odedg-tlv.redhat.com ([77.125.92.242]) by smtp.gmail.com with ESMTPSA id r10sm19821938wjz.24.2016.02.14.01.16.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Feb 2016 01:16:59 -0800 (PST) From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] drm/amdkfd: Track when module's init is complete Date: Sun, 14 Feb 2016 11:16:53 +0200 Message-Id: <1455441415-16901-2-git-send-email-oded.gabbay@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455441415-16901-1-git-send-email-oded.gabbay@gmail.com> References: <1455441415-16901-1-git-send-email-oded.gabbay@gmail.com> Cc: daniel.vetter@ffwll.ch X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Current dependencies between amdkfd and radeon/amdgpu force the loading of amdkfd _before_ radeon and/or amdgpu are loaded. When all these kernel drivers are built as modules, this ordering is enforced by the kernel built-in mechanism of loading dependent modules. However, there is no such mechanism in case where all these drivers are compiled inside the kernel image (not as modules). The current way to enforce loading of amdkfd before radeon/amdgpu, is to put amdkfd before radeon/amdgpu in the drm Makefile, but that method is way too fragile. In addition, there is no kernel mechanism to check whether a kernel driver that is built inside the kernel image, has already been loaded. To solve this, this patch adds to kfd_module.c a new static variable, amdkfd_init_completed, that is set to 1 only when amdkfd's module initialization function has been completed (successfully). kgd2kfd_init(), which is the initialization function of the kgd-->kfd interface, and which is the first function in amdkfd called by radeon/amdgpu, will return successfully only if amdkfd_init_completed is equal 1. If amdkfd_init_completed is not equal to 1, kgd2kfd_init() will return -EPROBE_DEFER to signal radeon/amdgpu they need to defer their loading until amdkfd is loaded. Signed-off-by: Oded Gabbay --- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 4 ++-- drivers/gpu/drm/amd/amdkfd/kfd_module.c | 15 ++++++++++++--- drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 2 +- drivers/gpu/drm/radeon/radeon_kfd.c | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c index 84d68d6..44ba8be 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c @@ -70,7 +70,7 @@ bool amdgpu_amdkfd_load_interface(struct amdgpu_device *rdev) return false; } - if (!kgd2kfd_init_p(KFD_INTERFACE_VERSION, &kgd2kfd)) { + if (kgd2kfd_init_p(KFD_INTERFACE_VERSION, &kgd2kfd)) { symbol_put(kgd2kfd_init); kfd2kgd = NULL; kgd2kfd = NULL; @@ -80,7 +80,7 @@ bool amdgpu_amdkfd_load_interface(struct amdgpu_device *rdev) return true; #elif defined(CONFIG_HSA_AMD) - if (!kgd2kfd_init(KFD_INTERFACE_VERSION, &kgd2kfd)) { + if (kgd2kfd_init(KFD_INTERFACE_VERSION, &kgd2kfd)) { kfd2kgd = NULL; kgd2kfd = NULL; return false; diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_module.c b/drivers/gpu/drm/amd/amdkfd/kfd_module.c index ca8410e..850a562 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_module.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_module.c @@ -59,18 +59,23 @@ module_param(send_sigterm, int, 0444); MODULE_PARM_DESC(send_sigterm, "Send sigterm to HSA process on unhandled exception (0 = disable, 1 = enable)"); -bool kgd2kfd_init(unsigned interface_version, const struct kgd2kfd_calls **g2f) +static int amdkfd_init_completed; + +int kgd2kfd_init(unsigned interface_version, const struct kgd2kfd_calls **g2f) { + if (!amdkfd_init_completed) + return -EPROBE_DEFER; + /* * Only one interface version is supported, * no kfd/kgd version skew allowed. */ if (interface_version != KFD_INTERFACE_VERSION) - return false; + return -EINVAL; *g2f = &kgd2kfd; - return true; + return 0; } EXPORT_SYMBOL(kgd2kfd_init); @@ -111,6 +116,8 @@ static int __init kfd_module_init(void) kfd_process_create_wq(); + amdkfd_init_completed = 1; + dev_info(kfd_device, "Initialized module\n"); return 0; @@ -125,6 +132,8 @@ err_pasid: static void __exit kfd_module_exit(void) { + amdkfd_init_completed = 0; + kfd_process_destroy_wq(); kfd_topology_shutdown(); kfd_chardev_exit(); diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h index 888250b..a09d9f3 100644 --- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h +++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h @@ -221,7 +221,7 @@ struct kgd2kfd_calls { int (*resume)(struct kfd_dev *kfd); }; -bool kgd2kfd_init(unsigned interface_version, +int kgd2kfd_init(unsigned interface_version, const struct kgd2kfd_calls **g2f); #endif /* KGD_KFD_INTERFACE_H_INCLUDED */ diff --git a/drivers/gpu/drm/radeon/radeon_kfd.c b/drivers/gpu/drm/radeon/radeon_kfd.c index 9a4d69e..83c2704 100644 --- a/drivers/gpu/drm/radeon/radeon_kfd.c +++ b/drivers/gpu/drm/radeon/radeon_kfd.c @@ -142,7 +142,7 @@ bool radeon_kfd_init(void) if (kgd2kfd_init_p == NULL) return false; - if (!kgd2kfd_init_p(KFD_INTERFACE_VERSION, &kgd2kfd)) { + if (kgd2kfd_init_p(KFD_INTERFACE_VERSION, &kgd2kfd)) { symbol_put(kgd2kfd_init); kgd2kfd = NULL; @@ -151,7 +151,7 @@ bool radeon_kfd_init(void) return true; #elif defined(CONFIG_HSA_AMD) - if (!kgd2kfd_init(KFD_INTERFACE_VERSION, &kgd2kfd)) { + if (kgd2kfd_init(KFD_INTERFACE_VERSION, &kgd2kfd)) { kgd2kfd = NULL; return false;