diff mbox

[1/5] drm/i915: Assert that the partial VMA fits within the object

Message ID 20161222105625.10832-1-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson Dec. 22, 2016, 10:56 a.m. UTC
When creating a partial VMA assert that it first fits with the parent
object, and that if it covers the whole of the parent a normal view was
created instead.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_vma.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Joonas Lahtinen Dec. 22, 2016, 11:02 a.m. UTC | #1
On to, 2016-12-22 at 10:56 +0000, Chris Wilson wrote:
> When creating a partial VMA assert that it first fits with the parent
> object, and that if it covers the whole of the parent a normal view was
> created instead.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

Regards, Joonas
kernel test robot Dec. 22, 2016, 11:55 a.m. UTC | #2
Hi Chris,

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on next-20161222]
[cannot apply to v4.9]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Chris-Wilson/drm-i915-Assert-that-the-partial-VMA-fits-within-the-object/20161222-190222
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: i386-randconfig-s1-201651 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All error/warnings (new ones prefixed by >>):

   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/linux/io-mapping.h:21,
                    from drivers/gpu/drm/i915/i915_vma.h:28,
                    from drivers/gpu/drm/i915/i915_vma.c:25:
   drivers/gpu/drm/i915/i915_vma.c: In function '__i915_vma_create':
>> drivers/gpu/drm/i915/i915_vma.c:98:15: error: implicit declaration of function 'range_overflows_t' [-Werror=implicit-function-declaration]
       GEM_BUG_ON(range_overflows_t(u64,
                  ^
   include/linux/compiler.h:139:45: note: in definition of macro 'unlikely'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                ^
>> drivers/gpu/drm/i915/i915_gem.h:29:26: note: in expansion of macro 'BUG_ON'
    #define GEM_BUG_ON(expr) BUG_ON(expr)
                             ^~~~~~
>> drivers/gpu/drm/i915/i915_vma.c:98:4: note: in expansion of macro 'GEM_BUG_ON'
       GEM_BUG_ON(range_overflows_t(u64,
       ^~~~~~~~~~
>> drivers/gpu/drm/i915/i915_vma.c:98:33: error: expected expression before 'u64'
       GEM_BUG_ON(range_overflows_t(u64,
                                    ^
   include/linux/compiler.h:139:45: note: in definition of macro 'unlikely'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                ^
>> drivers/gpu/drm/i915/i915_gem.h:29:26: note: in expansion of macro 'BUG_ON'
    #define GEM_BUG_ON(expr) BUG_ON(expr)
                             ^~~~~~
>> drivers/gpu/drm/i915/i915_vma.c:98:4: note: in expansion of macro 'GEM_BUG_ON'
       GEM_BUG_ON(range_overflows_t(u64,
       ^~~~~~~~~~
>> drivers/gpu/drm/i915/i915_vma.c:98:33: error: expected expression before 'u64'
       GEM_BUG_ON(range_overflows_t(u64,
                                    ^
   include/linux/compiler.h:139:53: note: in definition of macro 'unlikely'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                        ^
>> drivers/gpu/drm/i915/i915_gem.h:29:26: note: in expansion of macro 'BUG_ON'
    #define GEM_BUG_ON(expr) BUG_ON(expr)
                             ^~~~~~
>> drivers/gpu/drm/i915/i915_vma.c:98:4: note: in expansion of macro 'GEM_BUG_ON'
       GEM_BUG_ON(range_overflows_t(u64,
       ^~~~~~~~~~
>> drivers/gpu/drm/i915/i915_vma.c:98:33: error: expected expression before 'u64'
       GEM_BUG_ON(range_overflows_t(u64,
                                    ^
   include/linux/compiler.h:112:47: note: in definition of macro 'likely_notrace'
    #define likely_notrace(x) __builtin_expect(!!(x), 1)
                                                  ^
   include/linux/compiler.h:139:58: note: in expansion of macro '__branch_check__'
    #  define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
                                                             ^~~~~~~~~~~~~~~~
   include/asm-generic/bug.h:55:36: note: in expansion of macro 'unlikely'
    #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                                       ^~~~~~~~
>> drivers/gpu/drm/i915/i915_gem.h:29:26: note: in expansion of macro 'BUG_ON'
    #define GEM_BUG_ON(expr) BUG_ON(expr)
                             ^~~~~~
>> drivers/gpu/drm/i915/i915_vma.c:98:4: note: in expansion of macro 'GEM_BUG_ON'
       GEM_BUG_ON(range_overflows_t(u64,
       ^~~~~~~~~~
   cc1: all warnings being treated as errors

vim +/range_overflows_t +98 drivers/gpu/drm/i915/i915_vma.c

    19	 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    20	 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    21	 * IN THE SOFTWARE.
    22	 *
    23	 */
    24	 
  > 25	#include "i915_vma.h"
    26	
    27	#include "i915_drv.h"
    28	#include "intel_ringbuffer.h"
    29	#include "intel_frontbuffer.h"
    30	
    31	#include <drm/drm_gem.h>
    32	
    33	static void
    34	i915_vma_retire(struct i915_gem_active *active,
    35			struct drm_i915_gem_request *rq)
    36	{
    37		const unsigned int idx = rq->engine->id;
    38		struct i915_vma *vma =
    39			container_of(active, struct i915_vma, last_read[idx]);
    40		struct drm_i915_gem_object *obj = vma->obj;
    41	
    42		GEM_BUG_ON(!i915_vma_has_active_engine(vma, idx));
    43	
    44		i915_vma_clear_active(vma, idx);
    45		if (i915_vma_is_active(vma))
    46			return;
    47	
    48		list_move_tail(&vma->vm_link, &vma->vm->inactive_list);
    49		if (unlikely(i915_vma_is_closed(vma) && !i915_vma_is_pinned(vma)))
    50			WARN_ON(i915_vma_unbind(vma));
    51	
    52		GEM_BUG_ON(!i915_gem_object_is_active(obj));
    53		if (--obj->active_count)
    54			return;
    55	
    56		/* Bump our place on the bound list to keep it roughly in LRU order
    57		 * so that we don't steal from recently used but inactive objects
    58		 * (unless we are forced to ofc!)
    59		 */
    60		if (obj->bind_count)
    61			list_move_tail(&obj->global_link, &rq->i915->mm.bound_list);
    62	
    63		obj->mm.dirty = true; /* be paranoid  */
    64	
    65		if (i915_gem_object_has_active_reference(obj)) {
    66			i915_gem_object_clear_active_reference(obj);
    67			i915_gem_object_put(obj);
    68		}
    69	}
    70	
    71	static struct i915_vma *
    72	__i915_vma_create(struct drm_i915_gem_object *obj,
    73			  struct i915_address_space *vm,
    74			  const struct i915_ggtt_view *view)
    75	{
    76		struct i915_vma *vma;
    77		struct rb_node *rb, **p;
    78		int i;
    79	
    80		GEM_BUG_ON(vm->closed);
    81	
    82		vma = kmem_cache_zalloc(to_i915(obj->base.dev)->vmas, GFP_KERNEL);
    83		if (vma == NULL)
    84			return ERR_PTR(-ENOMEM);
    85	
    86		INIT_LIST_HEAD(&vma->exec_list);
    87		for (i = 0; i < ARRAY_SIZE(vma->last_read); i++)
    88			init_request_active(&vma->last_read[i], i915_vma_retire);
    89		init_request_active(&vma->last_fence, NULL);
    90		list_add(&vma->vm_link, &vm->unbound_list);
    91		vma->vm = vm;
    92		vma->obj = obj;
    93		vma->size = obj->base.size;
    94	
    95		if (view) {
    96			vma->ggtt_view = *view;
    97			if (view->type == I915_GGTT_VIEW_PARTIAL) {
  > 98				GEM_BUG_ON(range_overflows_t(u64,
    99							     view->params.partial.offset,
   100							     view->params.partial.size,
   101							     obj->base.size >> PAGE_SHIFT));

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index cfec4222b04e..3229f37eabea 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -95,8 +95,13 @@  __i915_vma_create(struct drm_i915_gem_object *obj,
 	if (view) {
 		vma->ggtt_view = *view;
 		if (view->type == I915_GGTT_VIEW_PARTIAL) {
+			GEM_BUG_ON(range_overflows_t(u64,
+						     view->params.partial.offset,
+						     view->params.partial.size,
+						     obj->base.size >> PAGE_SHIFT));
 			vma->size = view->params.partial.size;
 			vma->size <<= PAGE_SHIFT;
+			GEM_BUG_ON(vma->size >= obj->base.size);
 		} else if (view->type == I915_GGTT_VIEW_ROTATED) {
 			vma->size =
 				intel_rotation_info_size(&view->params.rotated);