@@ -1481,10 +1481,10 @@ static int check_scratch(struct i915_address_space *vm, u64 offset)
14811481
14821482static int write_to_scratch (struct i915_gem_context * ctx ,
14831483 struct intel_engine_cs * engine ,
1484+ struct drm_i915_gem_object * obj ,
14841485 u64 offset , u32 value )
14851486{
14861487 struct drm_i915_private * i915 = ctx -> i915 ;
1487- struct drm_i915_gem_object * obj ;
14881488 struct i915_address_space * vm ;
14891489 struct i915_request * rq ;
14901490 struct i915_vma * vma ;
@@ -1497,15 +1497,9 @@ static int write_to_scratch(struct i915_gem_context *ctx,
14971497 if (err )
14981498 return err ;
14991499
1500- obj = i915_gem_object_create_internal (i915 , PAGE_SIZE );
1501- if (IS_ERR (obj ))
1502- return PTR_ERR (obj );
1503-
15041500 cmd = i915_gem_object_pin_map_unlocked (obj , I915_MAP_WB );
1505- if (IS_ERR (cmd )) {
1506- err = PTR_ERR (cmd );
1507- goto out ;
1508- }
1501+ if (IS_ERR (cmd ))
1502+ return PTR_ERR (cmd );
15091503
15101504 * cmd ++ = MI_STORE_DWORD_IMM_GEN4 ;
15111505 if (GRAPHICS_VER (i915 ) >= 8 ) {
@@ -1569,17 +1563,19 @@ static int write_to_scratch(struct i915_gem_context *ctx,
15691563 i915_vma_unpin (vma );
15701564out_vm :
15711565 i915_vm_put (vm );
1572- out :
1573- i915_gem_object_put (obj );
1566+
1567+ if (!err )
1568+ err = i915_gem_object_wait (obj , 0 , MAX_SCHEDULE_TIMEOUT );
1569+
15741570 return err ;
15751571}
15761572
15771573static int read_from_scratch (struct i915_gem_context * ctx ,
15781574 struct intel_engine_cs * engine ,
1575+ struct drm_i915_gem_object * obj ,
15791576 u64 offset , u32 * value )
15801577{
15811578 struct drm_i915_private * i915 = ctx -> i915 ;
1582- struct drm_i915_gem_object * obj ;
15831579 struct i915_address_space * vm ;
15841580 const u32 result = 0x100 ;
15851581 struct i915_request * rq ;
@@ -1594,10 +1590,6 @@ static int read_from_scratch(struct i915_gem_context *ctx,
15941590 if (err )
15951591 return err ;
15961592
1597- obj = i915_gem_object_create_internal (i915 , PAGE_SIZE );
1598- if (IS_ERR (obj ))
1599- return PTR_ERR (obj );
1600-
16011593 if (GRAPHICS_VER (i915 ) >= 8 ) {
16021594 const u32 GPR0 = engine -> mmio_base + 0x600 ;
16031595
@@ -1615,7 +1607,7 @@ static int read_from_scratch(struct i915_gem_context *ctx,
16151607 cmd = i915_gem_object_pin_map_unlocked (obj , I915_MAP_WB );
16161608 if (IS_ERR (cmd )) {
16171609 err = PTR_ERR (cmd );
1618- goto out ;
1610+ goto err_unpin ;
16191611 }
16201612
16211613 memset (cmd , POISON_INUSE , PAGE_SIZE );
@@ -1651,7 +1643,7 @@ static int read_from_scratch(struct i915_gem_context *ctx,
16511643 cmd = i915_gem_object_pin_map_unlocked (obj , I915_MAP_WB );
16521644 if (IS_ERR (cmd )) {
16531645 err = PTR_ERR (cmd );
1654- goto out ;
1646+ goto err_unpin ;
16551647 }
16561648
16571649 memset (cmd , POISON_INUSE , PAGE_SIZE );
@@ -1722,8 +1714,10 @@ static int read_from_scratch(struct i915_gem_context *ctx,
17221714 i915_vma_unpin (vma );
17231715out_vm :
17241716 i915_vm_put (vm );
1725- out :
1726- i915_gem_object_put (obj );
1717+
1718+ if (!err )
1719+ err = i915_gem_object_wait (obj , 0 , MAX_SCHEDULE_TIMEOUT );
1720+
17271721 return err ;
17281722}
17291723
@@ -1757,6 +1751,7 @@ static int igt_vm_isolation(void *arg)
17571751{
17581752 struct drm_i915_private * i915 = arg ;
17591753 struct i915_gem_context * ctx_a , * ctx_b ;
1754+ struct drm_i915_gem_object * obj_a , * obj_b ;
17601755 unsigned long num_engines , count ;
17611756 struct intel_engine_cs * engine ;
17621757 struct igt_live_test t ;
@@ -1810,6 +1805,18 @@ static int igt_vm_isolation(void *arg)
18101805 vm_total = ctx_a -> vm -> total ;
18111806 GEM_BUG_ON (ctx_b -> vm -> total != vm_total );
18121807
1808+ obj_a = i915_gem_object_create_internal (i915 , PAGE_SIZE );
1809+ if (IS_ERR (obj_a )) {
1810+ err = PTR_ERR (obj_a );
1811+ goto out_file ;
1812+ }
1813+
1814+ obj_b = i915_gem_object_create_internal (i915 , PAGE_SIZE );
1815+ if (IS_ERR (obj_b )) {
1816+ err = PTR_ERR (obj_b );
1817+ goto put_a ;
1818+ }
1819+
18131820 count = 0 ;
18141821 num_engines = 0 ;
18151822 for_each_uabi_engine (engine , i915 ) {
@@ -1832,13 +1839,13 @@ static int igt_vm_isolation(void *arg)
18321839 I915_GTT_PAGE_SIZE , vm_total ,
18331840 sizeof (u32 ), alignof_dword );
18341841
1835- err = write_to_scratch (ctx_a , engine ,
1842+ err = write_to_scratch (ctx_a , engine , obj_a ,
18361843 offset , 0xdeadbeef );
18371844 if (err == 0 )
1838- err = read_from_scratch (ctx_b , engine ,
1845+ err = read_from_scratch (ctx_b , engine , obj_b ,
18391846 offset , & value );
18401847 if (err )
1841- goto out_file ;
1848+ goto put_b ;
18421849
18431850 if (value != expected ) {
18441851 pr_err ("%s: Read %08x from scratch (offset 0x%08x_%08x), after %lu reads!\n" ,
@@ -1847,7 +1854,7 @@ static int igt_vm_isolation(void *arg)
18471854 lower_32_bits (offset ),
18481855 this );
18491856 err = - EINVAL ;
1850- goto out_file ;
1857+ goto put_b ;
18511858 }
18521859
18531860 this ++ ;
@@ -1858,6 +1865,10 @@ static int igt_vm_isolation(void *arg)
18581865 pr_info ("Checked %lu scratch offsets across %lu engines\n" ,
18591866 count , num_engines );
18601867
1868+ put_b :
1869+ i915_gem_object_put (obj_b );
1870+ put_a :
1871+ i915_gem_object_put (obj_a );
18611872out_file :
18621873 if (igt_live_test_end (& t ))
18631874 err = - EIO ;
0 commit comments