36
36
#include <linux/mman.h>
37
37
#include <linux/ptrace.h>
38
38
#include <linux/dma-buf.h>
39
- #include <linux/fdtable.h>
40
39
#include <linux/processor.h>
41
40
#include "kfd_priv.h"
42
41
#include "kfd_device_queue_manager.h"
@@ -1835,7 +1834,8 @@ static uint32_t get_process_num_bos(struct kfd_process *p)
1835
1834
}
1836
1835
1837
1836
static int criu_get_prime_handle (struct kgd_mem * mem ,
1838
- int flags , u32 * shared_fd )
1837
+ int flags , u32 * shared_fd ,
1838
+ struct file * * file )
1839
1839
{
1840
1840
struct dma_buf * dmabuf ;
1841
1841
int ret ;
@@ -1846,20 +1846,40 @@ static int criu_get_prime_handle(struct kgd_mem *mem,
1846
1846
return ret ;
1847
1847
}
1848
1848
1849
- ret = dma_buf_fd ( dmabuf , flags );
1849
+ ret = get_unused_fd_flags ( flags );
1850
1850
if (ret < 0 ) {
1851
1851
pr_err ("dmabuf create fd failed, ret:%d\n" , ret );
1852
1852
goto out_free_dmabuf ;
1853
1853
}
1854
1854
1855
1855
* shared_fd = ret ;
1856
+ * file = dmabuf -> file ;
1856
1857
return 0 ;
1857
1858
1858
1859
out_free_dmabuf :
1859
1860
dma_buf_put (dmabuf );
1860
1861
return ret ;
1861
1862
}
1862
1863
1864
+ static void commit_files (struct file * * files ,
1865
+ struct kfd_criu_bo_bucket * bo_buckets ,
1866
+ unsigned int count ,
1867
+ int err )
1868
+ {
1869
+ while (count -- ) {
1870
+ struct file * file = files [count ];
1871
+
1872
+ if (!file )
1873
+ continue ;
1874
+ if (err ) {
1875
+ fput (file );
1876
+ put_unused_fd (bo_buckets [count ].dmabuf_fd );
1877
+ } else {
1878
+ fd_install (bo_buckets [count ].dmabuf_fd , file );
1879
+ }
1880
+ }
1881
+ }
1882
+
1863
1883
static int criu_checkpoint_bos (struct kfd_process * p ,
1864
1884
uint32_t num_bos ,
1865
1885
uint8_t __user * user_bos ,
@@ -1868,6 +1888,7 @@ static int criu_checkpoint_bos(struct kfd_process *p,
1868
1888
{
1869
1889
struct kfd_criu_bo_bucket * bo_buckets ;
1870
1890
struct kfd_criu_bo_priv_data * bo_privs ;
1891
+ struct file * * files = NULL ;
1871
1892
int ret = 0 , pdd_index , bo_index = 0 , id ;
1872
1893
void * mem ;
1873
1894
@@ -1881,6 +1902,12 @@ static int criu_checkpoint_bos(struct kfd_process *p,
1881
1902
goto exit ;
1882
1903
}
1883
1904
1905
+ files = kvzalloc (num_bos * sizeof (struct file * ), GFP_KERNEL );
1906
+ if (!files ) {
1907
+ ret = - ENOMEM ;
1908
+ goto exit ;
1909
+ }
1910
+
1884
1911
for (pdd_index = 0 ; pdd_index < p -> n_pdds ; pdd_index ++ ) {
1885
1912
struct kfd_process_device * pdd = p -> pdds [pdd_index ];
1886
1913
struct amdgpu_bo * dumper_bo ;
@@ -1923,7 +1950,7 @@ static int criu_checkpoint_bos(struct kfd_process *p,
1923
1950
ret = criu_get_prime_handle (kgd_mem ,
1924
1951
bo_bucket -> alloc_flags &
1925
1952
KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ? DRM_RDWR : 0 ,
1926
- & bo_bucket -> dmabuf_fd );
1953
+ & bo_bucket -> dmabuf_fd , & files [ bo_index ] );
1927
1954
if (ret )
1928
1955
goto exit ;
1929
1956
} else {
@@ -1974,12 +2001,8 @@ static int criu_checkpoint_bos(struct kfd_process *p,
1974
2001
* priv_offset += num_bos * sizeof (* bo_privs );
1975
2002
1976
2003
exit :
1977
- while (ret && bo_index -- ) {
1978
- if (bo_buckets [bo_index ].alloc_flags
1979
- & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT ))
1980
- close_fd (bo_buckets [bo_index ].dmabuf_fd );
1981
- }
1982
-
2004
+ commit_files (files , bo_buckets , bo_index , ret );
2005
+ kvfree (files );
1983
2006
kvfree (bo_buckets );
1984
2007
kvfree (bo_privs );
1985
2008
return ret ;
@@ -2331,7 +2354,8 @@ static int criu_restore_memory_of_gpu(struct kfd_process_device *pdd,
2331
2354
2332
2355
static int criu_restore_bo (struct kfd_process * p ,
2333
2356
struct kfd_criu_bo_bucket * bo_bucket ,
2334
- struct kfd_criu_bo_priv_data * bo_priv )
2357
+ struct kfd_criu_bo_priv_data * bo_priv ,
2358
+ struct file * * file )
2335
2359
{
2336
2360
struct kfd_process_device * pdd ;
2337
2361
struct kgd_mem * kgd_mem ;
@@ -2383,7 +2407,7 @@ static int criu_restore_bo(struct kfd_process *p,
2383
2407
if (bo_bucket -> alloc_flags
2384
2408
& (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT )) {
2385
2409
ret = criu_get_prime_handle (kgd_mem , DRM_RDWR ,
2386
- & bo_bucket -> dmabuf_fd );
2410
+ & bo_bucket -> dmabuf_fd , file );
2387
2411
if (ret )
2388
2412
return ret ;
2389
2413
} else {
@@ -2400,6 +2424,7 @@ static int criu_restore_bos(struct kfd_process *p,
2400
2424
{
2401
2425
struct kfd_criu_bo_bucket * bo_buckets = NULL ;
2402
2426
struct kfd_criu_bo_priv_data * bo_privs = NULL ;
2427
+ struct file * * files = NULL ;
2403
2428
int ret = 0 ;
2404
2429
uint32_t i = 0 ;
2405
2430
@@ -2413,6 +2438,12 @@ static int criu_restore_bos(struct kfd_process *p,
2413
2438
if (!bo_buckets )
2414
2439
return - ENOMEM ;
2415
2440
2441
+ files = kvzalloc (args -> num_bos * sizeof (struct file * ), GFP_KERNEL );
2442
+ if (!files ) {
2443
+ ret = - ENOMEM ;
2444
+ goto exit ;
2445
+ }
2446
+
2416
2447
ret = copy_from_user (bo_buckets , (void __user * )args -> bos ,
2417
2448
args -> num_bos * sizeof (* bo_buckets ));
2418
2449
if (ret ) {
@@ -2438,7 +2469,7 @@ static int criu_restore_bos(struct kfd_process *p,
2438
2469
2439
2470
/* Create and map new BOs */
2440
2471
for (; i < args -> num_bos ; i ++ ) {
2441
- ret = criu_restore_bo (p , & bo_buckets [i ], & bo_privs [i ]);
2472
+ ret = criu_restore_bo (p , & bo_buckets [i ], & bo_privs [i ], & files [ i ] );
2442
2473
if (ret ) {
2443
2474
pr_debug ("Failed to restore BO[%d] ret%d\n" , i , ret );
2444
2475
goto exit ;
@@ -2453,11 +2484,8 @@ static int criu_restore_bos(struct kfd_process *p,
2453
2484
ret = - EFAULT ;
2454
2485
2455
2486
exit :
2456
- while (ret && i -- ) {
2457
- if (bo_buckets [i ].alloc_flags
2458
- & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT ))
2459
- close_fd (bo_buckets [i ].dmabuf_fd );
2460
- }
2487
+ commit_files (files , bo_buckets , i , ret );
2488
+ kvfree (files );
2461
2489
kvfree (bo_buckets );
2462
2490
kvfree (bo_privs );
2463
2491
return ret ;
0 commit comments