Fix the similar warning when hotplugging: [ 155.585721] kernfs: can not remove 'enforce_isolation', no directory [ 155.592201] WARNING: CPU: 3 PID: 6960 at fs/kernfs/dir.c:1683 kernfs_remove_by_name_ns+0xb9/0xc0 [ 155.601145] Modules linked in: xt_MASQUERADE xt_comment nft_compat veth bridge stp llc overlay nft_fib_inet nft_fib_ipv4 nft_fib_ipv6 nft_fib nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 ip_set nf_tables nfnetlink qrtr intel_rapl_msr amd_atl intel_rapl_common amd64_edac edac_mce_amd amdgpu kvm_amd kvm ipmi_ssif amdxcp rapl drm_exec gpu_sched drm_buddy i2c_algo_bit drm_suballoc_helper drm_ttm_helper ttm pcspkr drm_display_helper acpi_cpufreq drm_kms_helper video wmi k10temp i2c_piix4 acpi_ipmi ipmi_si drm zram ip_tables loop squashfs dm_multipath crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intel sha512_ssse3 sha256_ssse3 sha1_ssse3 sp5100_tco ixgbe rfkill ccp dca sunrpc be2iscsi bnx2i cnic uio cxgb4i cxgb4 tls cxgb3i cxgb3 mdio libcxgbi libcxgb qla4xxx iscsi_boot_sysfs iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi ipmi_devintf ipmi_msghandler fuse [ 155.685224] systemd-journald[1354]: Compressed data object 957 -> 524 using ZSTD [ 155.685687] CPU: 3 PID: 6960 Comm: amd_pci_unplug Not tainted 6.10.0-1148853.1.zuul.164395107d6642bdb451071313e9378d #1 [ 155.704149] Hardware name: TYAN B8021G88V2HR-2T/S8021GM2NR-2T, BIOS V1.03.B10 04/01/2019 [ 155.712383] RIP: 0010:kernfs_remove_by_name_ns+0xb9/0xc0 [ 155.717805] Code: a0 00 48 89 ef e8 37 96 c7 ff 5b b8 fe ff ff ff 5d 41 5c 41 5d e9 f7 96 a0 00 0f 0b eb ab 48 c7 c7 48 ba 7e 8f e8 f7 66 bf ff <0f> 0b eb dc 0f 1f 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 [ 155.736766] RSP: 0018:ffffb1685d7a3e20 EFLAGS: 00010296 [ 155.742108] RAX: 0000000000000038 RBX: ffff929e94c80000 RCX: 0000000000000000 [ 155.749363] RDX: ffff928e1efaf200 RSI: ffff928e1efa18c0 RDI: ffff928e1efa18c0 [ 155.756612] RBP: 0000000000000008 R08: 0000000000000000 R09: 0000000000000003 [ 155.763855] R10: ffffb1685d7a3cd8 R11: ffffffff8fb3e1c8 R12: ffffffffc1ef5341 [ 155.771104] R13: ffff929e94cc5530 R14: 0000000000000000 R15: 0000000000000000 [ 155.778357] FS: 00007fd9dd8d9c40(0000) GS:ffff928e1ef80000(0000) knlGS:0000000000000000 [ 155.786594] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 155.792450] CR2: 0000561245ceee38 CR3: 0000000113018000 CR4: 00000000003506f0 [ 155.799702] Call Trace: [ 155.802254] <TASK> [ 155.804460] ? __warn+0x80/0x120 [ 155.807798] ? kernfs_remove_by_name_ns+0xb9/0xc0 [ 155.812617] ? report_bug+0x164/0x190 [ 155.816393] ? handle_bug+0x3c/0x80 [ 155.819994] ? exc_invalid_op+0x17/0x70 [ 155.823939] ? asm_exc_invalid_op+0x1a/0x20 [ 155.828235] ? kernfs_remove_by_name_ns+0xb9/0xc0 [ 155.833058] amdgpu_gfx_sysfs_fini+0x59/0xd0 [amdgpu] [ 155.838637] gfx_v9_0_sw_fini+0x123/0x1c0 [amdgpu] [ 155.843887] amdgpu_device_fini_sw+0xbc/0x3e0 [amdgpu] [ 155.849432] amdgpu_driver_release_kms+0x16/0x30 [amdgpu] [ 155.855235] drm_dev_put.part.0+0x3c/0x60 [drm] [ 155.859914] drm_release+0x8b/0xc0 [drm] [ 155.863978] __fput+0xf1/0x2c0 [ 155.867141] __x64_sys_close+0x3c/0x80 [ 155.870998] do_syscall_64+0x64/0x170 V2: Add details in comments (Tim) Signed-off-by: Jesse Zhang <jesse.zhang@amd.com> Reported-by: Andy Dong <andy.dong@amd.com> Reviewed-by: Tim Huang <tim.huang@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
145 lines
4.3 KiB
C
145 lines
4.3 KiB
C
// SPDX-License-Identifier: GPL-2.0 OR MIT
|
|
/*
|
|
* Copyright 2016-2021 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.
|
|
*
|
|
* Authors: Christian König, Felix Kuehling
|
|
*/
|
|
|
|
#include "amdgpu.h"
|
|
|
|
/**
|
|
* DOC: mem_info_preempt_used
|
|
*
|
|
* The amdgpu driver provides a sysfs API for reporting current total amount of
|
|
* used preemptible memory.
|
|
* The file mem_info_preempt_used is used for this, and returns the current
|
|
* used size of the preemptible block, in bytes
|
|
*/
|
|
static ssize_t mem_info_preempt_used_show(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct drm_device *ddev = dev_get_drvdata(dev);
|
|
struct amdgpu_device *adev = drm_to_adev(ddev);
|
|
struct ttm_resource_manager *man = &adev->mman.preempt_mgr;
|
|
|
|
return sysfs_emit(buf, "%llu\n", ttm_resource_manager_usage(man));
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(mem_info_preempt_used);
|
|
|
|
/**
|
|
* amdgpu_preempt_mgr_new - allocate a new node
|
|
*
|
|
* @man: TTM memory type manager
|
|
* @tbo: TTM BO we need this range for
|
|
* @place: placement flags and restrictions
|
|
* @res: TTM memory object
|
|
*
|
|
* Dummy, just count the space used without allocating resources or any limit.
|
|
*/
|
|
static int amdgpu_preempt_mgr_new(struct ttm_resource_manager *man,
|
|
struct ttm_buffer_object *tbo,
|
|
const struct ttm_place *place,
|
|
struct ttm_resource **res)
|
|
{
|
|
*res = kzalloc(sizeof(**res), GFP_KERNEL);
|
|
if (!*res)
|
|
return -ENOMEM;
|
|
|
|
ttm_resource_init(tbo, place, *res);
|
|
(*res)->start = AMDGPU_BO_INVALID_OFFSET;
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* amdgpu_preempt_mgr_del - free ranges
|
|
*
|
|
* @man: TTM memory type manager
|
|
* @res: TTM memory object
|
|
*
|
|
* Free the allocated GTT again.
|
|
*/
|
|
static void amdgpu_preempt_mgr_del(struct ttm_resource_manager *man,
|
|
struct ttm_resource *res)
|
|
{
|
|
ttm_resource_fini(man, res);
|
|
kfree(res);
|
|
}
|
|
|
|
static const struct ttm_resource_manager_func amdgpu_preempt_mgr_func = {
|
|
.alloc = amdgpu_preempt_mgr_new,
|
|
.free = amdgpu_preempt_mgr_del,
|
|
};
|
|
|
|
/**
|
|
* amdgpu_preempt_mgr_init - init PREEMPT manager and DRM MM
|
|
*
|
|
* @adev: amdgpu_device pointer
|
|
*
|
|
* Allocate and initialize the GTT manager.
|
|
*/
|
|
int amdgpu_preempt_mgr_init(struct amdgpu_device *adev)
|
|
{
|
|
struct ttm_resource_manager *man = &adev->mman.preempt_mgr;
|
|
int ret;
|
|
|
|
man->use_tt = true;
|
|
man->func = &amdgpu_preempt_mgr_func;
|
|
|
|
ttm_resource_manager_init(man, &adev->mman.bdev, (1 << 30));
|
|
|
|
ret = device_create_file(adev->dev, &dev_attr_mem_info_preempt_used);
|
|
if (ret) {
|
|
DRM_ERROR("Failed to create device file mem_info_preempt_used\n");
|
|
return ret;
|
|
}
|
|
|
|
ttm_set_driver_manager(&adev->mman.bdev, AMDGPU_PL_PREEMPT, man);
|
|
ttm_resource_manager_set_used(man, true);
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* amdgpu_preempt_mgr_fini - free and destroy GTT manager
|
|
*
|
|
* @adev: amdgpu_device pointer
|
|
*
|
|
* Destroy and free the GTT manager, returns -EBUSY if ranges are still
|
|
* allocated inside it.
|
|
*/
|
|
void amdgpu_preempt_mgr_fini(struct amdgpu_device *adev)
|
|
{
|
|
struct ttm_resource_manager *man = &adev->mman.preempt_mgr;
|
|
int ret;
|
|
|
|
ttm_resource_manager_set_used(man, false);
|
|
|
|
ret = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
|
|
if (ret)
|
|
return;
|
|
|
|
if (adev->dev->kobj.sd)
|
|
device_remove_file(adev->dev, &dev_attr_mem_info_preempt_used);
|
|
|
|
ttm_resource_manager_cleanup(man);
|
|
ttm_set_driver_manager(&adev->mman.bdev, AMDGPU_PL_PREEMPT, NULL);
|
|
}
|