Skip to content

Commit b529371

Browse files
committed
Merge tag 'drm-intel-fixes-2020-01-23' of git://anongit.freedesktop.org/drm/drm-intel into drm-fixes
- Avoid overflow with huge userptr objects - uAPI fix to correctly handle negative values in engine->uabi_class/instance (cc: stable) Signed-off-by: Dave Airlie <airlied@redhat.com> From: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200123135045.GA12584@jlahtine-desk.ger.corp.intel.com
2 parents a48d4a3 + 5eec718 commit b529371

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

drivers/gpu/drm/i915/gem/i915_gem_busy.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
#include "i915_gem_ioctls.h"
1010
#include "i915_gem_object.h"
1111

12-
static __always_inline u32 __busy_read_flag(u8 id)
12+
static __always_inline u32 __busy_read_flag(u16 id)
1313
{
14-
if (id == (u8)I915_ENGINE_CLASS_INVALID)
14+
if (id == (u16)I915_ENGINE_CLASS_INVALID)
1515
return 0xffff0000u;
1616

1717
GEM_BUG_ON(id >= 16);
1818
return 0x10000u << id;
1919
}
2020

21-
static __always_inline u32 __busy_write_id(u8 id)
21+
static __always_inline u32 __busy_write_id(u16 id)
2222
{
2323
/*
2424
* The uABI guarantees an active writer is also amongst the read
@@ -29,14 +29,14 @@ static __always_inline u32 __busy_write_id(u8 id)
2929
* last_read - hence we always set both read and write busy for
3030
* last_write.
3131
*/
32-
if (id == (u8)I915_ENGINE_CLASS_INVALID)
32+
if (id == (u16)I915_ENGINE_CLASS_INVALID)
3333
return 0xffffffffu;
3434

3535
return (id + 1) | __busy_read_flag(id);
3636
}
3737

3838
static __always_inline unsigned int
39-
__busy_set_if_active(const struct dma_fence *fence, u32 (*flag)(u8 id))
39+
__busy_set_if_active(const struct dma_fence *fence, u32 (*flag)(u16 id))
4040
{
4141
const struct i915_request *rq;
4242

@@ -57,7 +57,7 @@ __busy_set_if_active(const struct dma_fence *fence, u32 (*flag)(u8 id))
5757
return 0;
5858

5959
/* Beware type-expansion follies! */
60-
BUILD_BUG_ON(!typecheck(u8, rq->engine->uabi_class));
60+
BUILD_BUG_ON(!typecheck(u16, rq->engine->uabi_class));
6161
return flag(rq->engine->uabi_class);
6262
}
6363

drivers/gpu/drm/i915/gem/i915_gem_userptr.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ struct get_pages_work {
402402

403403
static struct sg_table *
404404
__i915_gem_userptr_alloc_pages(struct drm_i915_gem_object *obj,
405-
struct page **pvec, int num_pages)
405+
struct page **pvec, unsigned long num_pages)
406406
{
407407
unsigned int max_segment = i915_sg_segment_size();
408408
struct sg_table *st;
@@ -448,9 +448,10 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work)
448448
{
449449
struct get_pages_work *work = container_of(_work, typeof(*work), work);
450450
struct drm_i915_gem_object *obj = work->obj;
451-
const int npages = obj->base.size >> PAGE_SHIFT;
451+
const unsigned long npages = obj->base.size >> PAGE_SHIFT;
452+
unsigned long pinned;
452453
struct page **pvec;
453-
int pinned, ret;
454+
int ret;
454455

455456
ret = -ENOMEM;
456457
pinned = 0;
@@ -553,7 +554,7 @@ __i915_gem_userptr_get_pages_schedule(struct drm_i915_gem_object *obj)
553554

554555
static int i915_gem_userptr_get_pages(struct drm_i915_gem_object *obj)
555556
{
556-
const int num_pages = obj->base.size >> PAGE_SHIFT;
557+
const unsigned long num_pages = obj->base.size >> PAGE_SHIFT;
557558
struct mm_struct *mm = obj->userptr.mm->mm;
558559
struct page **pvec;
559560
struct sg_table *pages;

drivers/gpu/drm/i915/gt/intel_engine_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ struct intel_engine_cs {
274274
u8 class;
275275
u8 instance;
276276

277-
u8 uabi_class;
278-
u8 uabi_instance;
277+
u16 uabi_class;
278+
u16 uabi_instance;
279279

280280
u32 uabi_capabilities;
281281
u32 context_size;

drivers/gpu/drm/i915/i915_gem_gtt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ gen8_ppgtt_insert_pte(struct i915_ppgtt *ppgtt,
11771177
pd = i915_pd_entry(pdp, gen8_pd_index(idx, 2));
11781178
vaddr = kmap_atomic_px(i915_pt_entry(pd, gen8_pd_index(idx, 1)));
11791179
do {
1180+
GEM_BUG_ON(iter->sg->length < I915_GTT_PAGE_SIZE);
11801181
vaddr[gen8_pd_index(idx, 0)] = pte_encode | iter->dma;
11811182

11821183
iter->dma += I915_GTT_PAGE_SIZE;
@@ -1660,6 +1661,7 @@ static void gen6_ppgtt_insert_entries(struct i915_address_space *vm,
16601661

16611662
vaddr = kmap_atomic_px(i915_pt_entry(pd, act_pt));
16621663
do {
1664+
GEM_BUG_ON(iter.sg->length < I915_GTT_PAGE_SIZE);
16631665
vaddr[act_pte] = pte_encode | GEN6_PTE_ADDR_ENCODE(iter.dma);
16641666

16651667
iter.dma += I915_GTT_PAGE_SIZE;

0 commit comments

Comments
 (0)