Skip to content

Commit 6fd979c

Browse files
committed
drm/xe: Add SVM init / close / fini to faulting VMs
Add SVM init / close / fini to faulting VMs. Minimual implementation acting as a placeholder for follow on patches. v2: - Add close function v3: - Better commit message (Thomas) - Kernel doc (Thomas) - Update chunk array to be unsigned long (Thomas) - Use new drm_gpusvm.h header location (Thomas) - Newlines between functions in xe_svm.h (Thomas) - Call drm_gpusvm_driver_set_lock in init (Thomas) v6: - Only compile if CONFIG_DRM_GPUSVM selected (CI, Lucas) v7: - Only select CONFIG_DRM_GPUSVM if DEVICE_PRIVATE (CI) Signed-off-by: Matthew Brost <[email protected]> Reviewed-by: Himal Prasad Ghimiray <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent b43e864 commit 6fd979c

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed

drivers/gpu/drm/xe/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ xe-y += xe_bb.o \
124124
xe_wopcm.o
125125

126126
xe-$(CONFIG_HMM_MIRROR) += xe_hmm.o
127+
xe-$(CONFIG_DRM_GPUSVM) += xe_svm.o
127128

128129
# graphics hardware monitoring (HWMON) support
129130
xe-$(CONFIG_HWMON) += xe_hwmon.o

drivers/gpu/drm/xe/xe_svm.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// SPDX-License-Identifier: MIT
2+
/*
3+
* Copyright © 2024 Intel Corporation
4+
*/
5+
6+
#include "xe_svm.h"
7+
#include "xe_vm.h"
8+
#include "xe_vm_types.h"
9+
10+
static void xe_svm_invalidate(struct drm_gpusvm *gpusvm,
11+
struct drm_gpusvm_notifier *notifier,
12+
const struct mmu_notifier_range *mmu_range)
13+
{
14+
/* TODO: Implement */
15+
}
16+
17+
static const struct drm_gpusvm_ops gpusvm_ops = {
18+
.invalidate = xe_svm_invalidate,
19+
};
20+
21+
static const unsigned long fault_chunk_sizes[] = {
22+
SZ_2M,
23+
SZ_64K,
24+
SZ_4K,
25+
};
26+
27+
/**
28+
* xe_svm_init() - SVM initialize
29+
* @vm: The VM.
30+
*
31+
* Initialize SVM state which is embedded within the VM.
32+
*
33+
* Return: 0 on success, negative error code on error.
34+
*/
35+
int xe_svm_init(struct xe_vm *vm)
36+
{
37+
int err;
38+
39+
err = drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM", &vm->xe->drm,
40+
current->mm, NULL, 0, vm->size,
41+
SZ_512M, &gpusvm_ops, fault_chunk_sizes,
42+
ARRAY_SIZE(fault_chunk_sizes));
43+
if (err)
44+
return err;
45+
46+
drm_gpusvm_driver_set_lock(&vm->svm.gpusvm, &vm->lock);
47+
48+
return 0;
49+
}
50+
51+
/**
52+
* xe_svm_close() - SVM close
53+
* @vm: The VM.
54+
*
55+
* Close SVM state (i.e., stop and flush all SVM actions).
56+
*/
57+
void xe_svm_close(struct xe_vm *vm)
58+
{
59+
xe_assert(vm->xe, xe_vm_is_closed(vm));
60+
}
61+
62+
/**
63+
* xe_svm_fini() - SVM finalize
64+
* @vm: The VM.
65+
*
66+
* Finalize SVM state which is embedded within the VM.
67+
*/
68+
void xe_svm_fini(struct xe_vm *vm)
69+
{
70+
xe_assert(vm->xe, xe_vm_is_closed(vm));
71+
72+
drm_gpusvm_fini(&vm->svm.gpusvm);
73+
}

drivers/gpu/drm/xe/xe_svm.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* SPDX-License-Identifier: MIT */
2+
/*
3+
* Copyright © 2024 Intel Corporation
4+
*/
5+
6+
#ifndef _XE_SVM_H_
7+
#define _XE_SVM_H_
8+
9+
struct xe_vm;
10+
11+
#if IS_ENABLED(CONFIG_DRM_GPUSVM)
12+
int xe_svm_init(struct xe_vm *vm);
13+
14+
void xe_svm_fini(struct xe_vm *vm);
15+
16+
void xe_svm_close(struct xe_vm *vm);
17+
#else
18+
static inline
19+
int xe_svm_init(struct xe_vm *vm)
20+
{
21+
return 0;
22+
}
23+
24+
static inline
25+
void xe_svm_fini(struct xe_vm *vm)
26+
{
27+
}
28+
29+
static inline
30+
void xe_svm_close(struct xe_vm *vm)
31+
{
32+
}
33+
#endif
34+
35+
#endif

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "xe_pt.h"
3636
#include "xe_pxp.h"
3737
#include "xe_res_cursor.h"
38+
#include "xe_svm.h"
3839
#include "xe_sync.h"
3940
#include "xe_trace_bo.h"
4041
#include "xe_wa.h"
@@ -1582,6 +1583,12 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
15821583
}
15831584
}
15841585

1586+
if (flags & XE_VM_FLAG_FAULT_MODE) {
1587+
err = xe_svm_init(vm);
1588+
if (err)
1589+
goto err_close;
1590+
}
1591+
15851592
if (number_tiles > 1)
15861593
vm->composite_fence_ctx = dma_fence_context_alloc(1);
15871594

@@ -1627,6 +1634,8 @@ void xe_vm_close_and_put(struct xe_vm *vm)
16271634
xe_vm_close(vm);
16281635
if (xe_vm_in_preempt_fence_mode(vm))
16291636
flush_work(&vm->preempt.rebind_work);
1637+
if (xe_vm_in_fault_mode(vm))
1638+
xe_svm_close(vm);
16301639

16311640
down_write(&vm->lock);
16321641
for_each_tile(tile, xe, id) {
@@ -1695,6 +1704,9 @@ void xe_vm_close_and_put(struct xe_vm *vm)
16951704
xe_vma_destroy_unlocked(vma);
16961705
}
16971706

1707+
if (xe_vm_in_fault_mode(vm))
1708+
xe_svm_fini(vm);
1709+
16981710
up_write(&vm->lock);
16991711

17001712
down_write(&xe->usm.lock);

drivers/gpu/drm/xe/xe_vm_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef _XE_VM_TYPES_H_
77
#define _XE_VM_TYPES_H_
88

9+
#include <drm/drm_gpusvm.h>
910
#include <drm/drm_gpuvm.h>
1011

1112
#include <linux/dma-resv.h>
@@ -144,6 +145,12 @@ struct xe_vm {
144145
/** @gpuvm: base GPUVM used to track VMAs */
145146
struct drm_gpuvm gpuvm;
146147

148+
/** @svm: Shared virtual memory state */
149+
struct {
150+
/** @svm.gpusvm: base GPUSVM used to track fault allocations */
151+
struct drm_gpusvm gpusvm;
152+
} svm;
153+
147154
struct xe_device *xe;
148155

149156
/* exec queue used for (un)binding vma's */

0 commit comments

Comments
 (0)