Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'drm-next' of git://people.freedesktop.org/~airlied/linux

Pull drm fixes from Dave Airlie:
"Just a couple of dma-buf related fixes and some amdgpu fixes, along
with a regression fix for radeon off but default feature, but makes my
30" monitor happy again"

* 'drm-next' of git://people.freedesktop.org/~airlied/linux:
drm/radeon/mst: cleanup code indentation
drm/radeon/mst: fix regression in lane/link handling.
drm/amdgpu: add invalidate_page callback for userptrs
drm/amdgpu: Revert "remove the userptr rmn->lock"
drm/amdgpu: clean up path handling for powerplay
drm/amd/powerplay: fix memory leak of tdp_table
dma-buf/fence: fix fence_is_later v2
dma-buf: Update docs for SYNC ioctl
drm: remove excess description
dma-buf, drm, ion: Propagate error code from dma_buf_start_cpu_access()
drm/atmel-hlcdc: use helper to get crtc state
drm/atomic: use helper to get crtc state

+147 -98
+6 -5
Documentation/dma-buf-sharing.txt
··· 352 352 353 353 No special interfaces, userspace simply calls mmap on the dma-buf fd, making 354 354 sure that the cache synchronization ioctl (DMA_BUF_IOCTL_SYNC) is *always* 355 - used when the access happens. This is discussed next paragraphs. 355 + used when the access happens. Note that DMA_BUF_IOCTL_SYNC can fail with 356 + -EAGAIN or -EINTR, in which case it must be restarted. 356 357 357 358 Some systems might need some sort of cache coherency management e.g. when 358 359 CPU and GPU domains are being accessed through dma-buf at the same time. To ··· 367 366 want (with the new data being consumed by the GPU or say scanout device) 368 367 - munmap once you don't need the buffer any more 369 368 370 - Therefore, for correctness and optimal performance, systems with the memory 371 - cache shared by the GPU and CPU i.e. the "coherent" and also the 372 - "incoherent" are always required to use SYNC_START and SYNC_END before and 373 - after, respectively, when accessing the mapped address. 369 + For correctness and optimal performance, it is always required to use 370 + SYNC_START and SYNC_END before and after, respectively, when accessing the 371 + mapped address. Userspace cannot rely on coherent access, even when there 372 + are systems where it just works without calling these ioctls. 374 373 375 374 2. Supporting existing mmap interfaces in importers 376 375
+12 -7
drivers/dma-buf/dma-buf.c
··· 259 259 struct dma_buf *dmabuf; 260 260 struct dma_buf_sync sync; 261 261 enum dma_data_direction direction; 262 + int ret; 262 263 263 264 dmabuf = file->private_data; 264 265 ··· 286 285 } 287 286 288 287 if (sync.flags & DMA_BUF_SYNC_END) 289 - dma_buf_end_cpu_access(dmabuf, direction); 288 + ret = dma_buf_end_cpu_access(dmabuf, direction); 290 289 else 291 - dma_buf_begin_cpu_access(dmabuf, direction); 290 + ret = dma_buf_begin_cpu_access(dmabuf, direction); 292 291 293 - return 0; 292 + return ret; 294 293 default: 295 294 return -ENOTTY; 296 295 } ··· 612 611 * @dmabuf: [in] buffer to complete cpu access for. 613 612 * @direction: [in] length of range for cpu access. 614 613 * 615 - * This call must always succeed. 614 + * Can return negative error values, returns 0 on success. 616 615 */ 617 - void dma_buf_end_cpu_access(struct dma_buf *dmabuf, 618 - enum dma_data_direction direction) 616 + int dma_buf_end_cpu_access(struct dma_buf *dmabuf, 617 + enum dma_data_direction direction) 619 618 { 619 + int ret = 0; 620 + 620 621 WARN_ON(!dmabuf); 621 622 622 623 if (dmabuf->ops->end_cpu_access) 623 - dmabuf->ops->end_cpu_access(dmabuf, direction); 624 + ret = dmabuf->ops->end_cpu_access(dmabuf, direction); 625 + 626 + return ret; 624 627 } 625 628 EXPORT_SYMBOL_GPL(dma_buf_end_cpu_access); 626 629
+86 -34
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
··· 48 48 /* protected by adev->mn_lock */ 49 49 struct hlist_node node; 50 50 51 - /* objects protected by mm->mmap_sem */ 51 + /* objects protected by lock */ 52 + struct mutex lock; 52 53 struct rb_root objects; 53 54 }; 54 55 ··· 73 72 struct amdgpu_bo *bo, *next_bo; 74 73 75 74 mutex_lock(&adev->mn_lock); 76 - down_write(&rmn->mm->mmap_sem); 75 + mutex_lock(&rmn->lock); 77 76 hash_del(&rmn->node); 78 77 rbtree_postorder_for_each_entry_safe(node, next_node, &rmn->objects, 79 78 it.rb) { ··· 83 82 } 84 83 kfree(node); 85 84 } 86 - up_write(&rmn->mm->mmap_sem); 85 + mutex_unlock(&rmn->lock); 87 86 mutex_unlock(&adev->mn_lock); 88 87 mmu_notifier_unregister_no_release(&rmn->mn, rmn->mm); 89 88 kfree(rmn); ··· 103 102 struct amdgpu_mn *rmn = container_of(mn, struct amdgpu_mn, mn); 104 103 INIT_WORK(&rmn->work, amdgpu_mn_destroy); 105 104 schedule_work(&rmn->work); 105 + } 106 + 107 + /** 108 + * amdgpu_mn_invalidate_node - unmap all BOs of a node 109 + * 110 + * @node: the node with the BOs to unmap 111 + * 112 + * We block for all BOs and unmap them by move them 113 + * into system domain again. 114 + */ 115 + static void amdgpu_mn_invalidate_node(struct amdgpu_mn_node *node, 116 + unsigned long start, 117 + unsigned long end) 118 + { 119 + struct amdgpu_bo *bo; 120 + long r; 121 + 122 + list_for_each_entry(bo, &node->bos, mn_list) { 123 + 124 + if (!amdgpu_ttm_tt_affect_userptr(bo->tbo.ttm, start, end)) 125 + continue; 126 + 127 + r = amdgpu_bo_reserve(bo, true); 128 + if (r) { 129 + DRM_ERROR("(%ld) failed to reserve user bo\n", r); 130 + continue; 131 + } 132 + 133 + r = reservation_object_wait_timeout_rcu(bo->tbo.resv, 134 + true, false, MAX_SCHEDULE_TIMEOUT); 135 + if (r <= 0) 136 + DRM_ERROR("(%ld) failed to wait for user bo\n", r); 137 + 138 + amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_CPU); 139 + r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); 140 + if (r) 141 + DRM_ERROR("(%ld) failed to validate user bo\n", r); 142 + 143 + amdgpu_bo_unreserve(bo); 144 + } 145 + } 146 + 147 + /** 148 + * amdgpu_mn_invalidate_page - callback to notify about mm change 149 + * 150 + * @mn: our notifier 151 + * @mn: the mm this callback is about 152 + * @address: address of invalidate page 153 + * 154 + * Invalidation of a single page. Blocks for all BOs mapping it 155 + * and unmap them by move them into system domain again. 156 + */ 157 + static void amdgpu_mn_invalidate_page(struct mmu_notifier *mn, 158 + struct mm_struct *mm, 159 + unsigned long address) 160 + { 161 + struct amdgpu_mn *rmn = container_of(mn, struct amdgpu_mn, mn); 162 + struct interval_tree_node *it; 163 + 164 + mutex_lock(&rmn->lock); 165 + 166 + it = interval_tree_iter_first(&rmn->objects, address, address); 167 + if (it) { 168 + struct amdgpu_mn_node *node; 169 + 170 + node = container_of(it, struct amdgpu_mn_node, it); 171 + amdgpu_mn_invalidate_node(node, address, address); 172 + } 173 + 174 + mutex_unlock(&rmn->lock); 106 175 } 107 176 108 177 /** ··· 197 126 /* notification is exclusive, but interval is inclusive */ 198 127 end -= 1; 199 128 129 + mutex_lock(&rmn->lock); 130 + 200 131 it = interval_tree_iter_first(&rmn->objects, start, end); 201 132 while (it) { 202 133 struct amdgpu_mn_node *node; 203 - struct amdgpu_bo *bo; 204 - long r; 205 134 206 135 node = container_of(it, struct amdgpu_mn_node, it); 207 136 it = interval_tree_iter_next(it, start, end); 208 137 209 - list_for_each_entry(bo, &node->bos, mn_list) { 210 - 211 - if (!amdgpu_ttm_tt_affect_userptr(bo->tbo.ttm, start, 212 - end)) 213 - continue; 214 - 215 - r = amdgpu_bo_reserve(bo, true); 216 - if (r) { 217 - DRM_ERROR("(%ld) failed to reserve user bo\n", r); 218 - continue; 219 - } 220 - 221 - r = reservation_object_wait_timeout_rcu(bo->tbo.resv, 222 - true, false, MAX_SCHEDULE_TIMEOUT); 223 - if (r <= 0) 224 - DRM_ERROR("(%ld) failed to wait for user bo\n", r); 225 - 226 - amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_CPU); 227 - r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); 228 - if (r) 229 - DRM_ERROR("(%ld) failed to validate user bo\n", r); 230 - 231 - amdgpu_bo_unreserve(bo); 232 - } 138 + amdgpu_mn_invalidate_node(node, start, end); 233 139 } 140 + 141 + mutex_unlock(&rmn->lock); 234 142 } 235 143 236 144 static const struct mmu_notifier_ops amdgpu_mn_ops = { 237 145 .release = amdgpu_mn_release, 146 + .invalidate_page = amdgpu_mn_invalidate_page, 238 147 .invalidate_range_start = amdgpu_mn_invalidate_range_start, 239 148 }; 240 149 ··· 247 196 rmn->adev = adev; 248 197 rmn->mm = mm; 249 198 rmn->mn.ops = &amdgpu_mn_ops; 199 + mutex_init(&rmn->lock); 250 200 rmn->objects = RB_ROOT; 251 201 252 202 r = __mmu_notifier_register(&rmn->mn, mm); ··· 294 242 295 243 INIT_LIST_HEAD(&bos); 296 244 297 - down_write(&rmn->mm->mmap_sem); 245 + mutex_lock(&rmn->lock); 298 246 299 247 while ((it = interval_tree_iter_first(&rmn->objects, addr, end))) { 300 248 kfree(node); ··· 308 256 if (!node) { 309 257 node = kmalloc(sizeof(struct amdgpu_mn_node), GFP_KERNEL); 310 258 if (!node) { 311 - up_write(&rmn->mm->mmap_sem); 259 + mutex_unlock(&rmn->lock); 312 260 return -ENOMEM; 313 261 } 314 262 } ··· 323 271 324 272 interval_tree_insert(&node->it, &rmn->objects); 325 273 326 - up_write(&rmn->mm->mmap_sem); 274 + mutex_unlock(&rmn->lock); 327 275 328 276 return 0; 329 277 } ··· 349 297 return; 350 298 } 351 299 352 - down_write(&rmn->mm->mmap_sem); 300 + mutex_lock(&rmn->lock); 353 301 354 302 /* save the next list entry for later */ 355 303 head = bo->mn_list.next; ··· 364 312 kfree(node); 365 313 } 366 314 367 - up_write(&rmn->mm->mmap_sem); 315 + mutex_unlock(&rmn->lock); 368 316 mutex_unlock(&adev->mn_lock); 369 317 }
+7 -7
drivers/gpu/drm/amd/powerplay/Makefile
··· 1 1 2 2 subdir-ccflags-y += -Iinclude/drm \ 3 - -Idrivers/gpu/drm/amd/powerplay/inc/ \ 4 - -Idrivers/gpu/drm/amd/include/asic_reg \ 5 - -Idrivers/gpu/drm/amd/include \ 6 - -Idrivers/gpu/drm/amd/powerplay/smumgr\ 7 - -Idrivers/gpu/drm/amd/powerplay/hwmgr \ 8 - -Idrivers/gpu/drm/amd/powerplay/eventmgr 3 + -I$(FULL_AMD_PATH)/powerplay/inc/ \ 4 + -I$(FULL_AMD_PATH)/include/asic_reg \ 5 + -I$(FULL_AMD_PATH)/include \ 6 + -I$(FULL_AMD_PATH)/powerplay/smumgr\ 7 + -I$(FULL_AMD_PATH)/powerplay/hwmgr \ 8 + -I$(FULL_AMD_PATH)/powerplay/eventmgr 9 9 10 10 AMD_PP_PATH = ../powerplay 11 11 12 12 PP_LIBS = smumgr hwmgr eventmgr 13 13 14 - AMD_POWERPLAY = $(addsuffix /Makefile,$(addprefix drivers/gpu/drm/amd/powerplay/,$(PP_LIBS))) 14 + AMD_POWERPLAY = $(addsuffix /Makefile,$(addprefix $(FULL_AMD_PATH)/powerplay/,$(PP_LIBS))) 15 15 16 16 include $(AMD_POWERPLAY) 17 17
+3 -1
drivers/gpu/drm/amd/powerplay/hwmgr/tonga_processpptables.c
··· 512 512 513 513 hwmgr->dyn_state.cac_dtp_table = kzalloc(table_size, GFP_KERNEL); 514 514 515 - if (NULL == hwmgr->dyn_state.cac_dtp_table) 515 + if (NULL == hwmgr->dyn_state.cac_dtp_table) { 516 + kfree(tdp_table); 516 517 return -ENOMEM; 518 + } 517 519 518 520 memset(hwmgr->dyn_state.cac_dtp_table, 0x00, table_size); 519 521
+1 -1
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
··· 558 558 if (!state->base.crtc || !fb) 559 559 return 0; 560 560 561 - crtc_state = s->state->crtc_states[drm_crtc_index(s->crtc)]; 561 + crtc_state = drm_atomic_get_existing_crtc_state(s->state, s->crtc); 562 562 mode = &crtc_state->adjusted_mode; 563 563 564 564 state->src_x = s->src_x;
-1
drivers/gpu/drm/drm_atomic.c
··· 380 380 * drm_atomic_replace_property_blob - replace a blob property 381 381 * @blob: a pointer to the member blob to be replaced 382 382 * @new_blob: the new blob to replace with 383 - * @expected_size: the expected size of the new blob 384 383 * @replaced: whether the blob has been replaced 385 384 * 386 385 * RETURNS:
+8 -6
drivers/gpu/drm/drm_atomic_helper.c
··· 67 67 struct drm_crtc_state *crtc_state; 68 68 69 69 if (plane->state->crtc) { 70 - crtc_state = state->crtc_states[drm_crtc_index(plane->state->crtc)]; 70 + crtc_state = drm_atomic_get_existing_crtc_state(state, 71 + plane->state->crtc); 71 72 72 73 if (WARN_ON(!crtc_state)) 73 74 return; ··· 77 76 } 78 77 79 78 if (plane_state->crtc) { 80 - crtc_state = 81 - state->crtc_states[drm_crtc_index(plane_state->crtc)]; 79 + crtc_state = drm_atomic_get_existing_crtc_state(state, 80 + plane_state->crtc); 82 81 83 82 if (WARN_ON(!crtc_state)) 84 83 return; ··· 375 374 if (!conn_state->crtc || !conn_state->best_encoder) 376 375 continue; 377 376 378 - crtc_state = 379 - state->crtc_states[drm_crtc_index(conn_state->crtc)]; 377 + crtc_state = drm_atomic_get_existing_crtc_state(state, 378 + conn_state->crtc); 380 379 381 380 /* 382 381 * Each encoder has at most one connector (since we always steal ··· 680 679 if (!old_conn_state->crtc) 681 680 continue; 682 681 683 - old_crtc_state = old_state->crtc_states[drm_crtc_index(old_conn_state->crtc)]; 682 + old_crtc_state = drm_atomic_get_existing_crtc_state(old_state, 683 + old_conn_state->crtc); 684 684 685 685 if (!old_crtc_state->active || 686 686 !drm_atomic_crtc_needs_modeset(old_conn_state->crtc->state))
+5 -10
drivers/gpu/drm/i915/i915_gem_dmabuf.c
··· 228 228 return ret; 229 229 } 230 230 231 - static void i915_gem_end_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction) 231 + static int i915_gem_end_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction) 232 232 { 233 233 struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf); 234 234 struct drm_device *dev = obj->base.dev; 235 - struct drm_i915_private *dev_priv = to_i915(dev); 236 - bool was_interruptible; 237 235 int ret; 238 236 239 - mutex_lock(&dev->struct_mutex); 240 - was_interruptible = dev_priv->mm.interruptible; 241 - dev_priv->mm.interruptible = false; 237 + ret = i915_mutex_lock_interruptible(dev); 238 + if (ret) 239 + return ret; 242 240 243 241 ret = i915_gem_object_set_to_gtt_domain(obj, false); 244 - 245 - dev_priv->mm.interruptible = was_interruptible; 246 242 mutex_unlock(&dev->struct_mutex); 247 243 248 - if (unlikely(ret)) 249 - DRM_ERROR("unable to flush buffer following CPU access; rendering may be corrupt\n"); 244 + return ret; 250 245 } 251 246 252 247 static const struct dma_buf_ops i915_dmabuf_ops = {
+3 -2
drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
··· 97 97 return omap_gem_get_pages(obj, &pages, true); 98 98 } 99 99 100 - static void omap_gem_dmabuf_end_cpu_access(struct dma_buf *buffer, 101 - enum dma_data_direction dir) 100 + static int omap_gem_dmabuf_end_cpu_access(struct dma_buf *buffer, 101 + enum dma_data_direction dir) 102 102 { 103 103 struct drm_gem_object *obj = buffer->priv; 104 104 omap_gem_put_pages(obj); 105 + return 0; 105 106 } 106 107 107 108
+6 -16
drivers/gpu/drm/radeon/radeon_dp_mst.c
··· 510 510 { 511 511 struct radeon_encoder_mst *mst_enc; 512 512 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 513 + struct radeon_connector_atom_dig *dig_connector; 513 514 int bpp = 24; 514 515 515 516 mst_enc = radeon_encoder->enc_priv; ··· 524 523 525 524 526 525 drm_mode_set_crtcinfo(adjusted_mode, 0); 527 - { 528 - struct radeon_connector_atom_dig *dig_connector; 529 - int ret; 530 - 531 - dig_connector = mst_enc->connector->con_priv; 532 - ret = radeon_dp_get_dp_link_config(&mst_enc->connector->base, 533 - dig_connector->dpcd, adjusted_mode->clock, 534 - &dig_connector->dp_lane_count, 535 - &dig_connector->dp_clock); 536 - if (ret) { 537 - dig_connector->dp_lane_count = 0; 538 - dig_connector->dp_clock = 0; 539 - } 540 - DRM_DEBUG_KMS("dig clock %p %d %d\n", dig_connector, 541 - dig_connector->dp_lane_count, dig_connector->dp_clock); 542 - } 526 + dig_connector = mst_enc->connector->con_priv; 527 + dig_connector->dp_lane_count = drm_dp_max_lane_count(dig_connector->dpcd); 528 + dig_connector->dp_clock = drm_dp_max_link_rate(dig_connector->dpcd); 529 + DRM_DEBUG_KMS("dig clock %p %d %d\n", dig_connector, 530 + dig_connector->dp_lane_count, dig_connector->dp_clock); 543 531 return true; 544 532 } 545 533
+2 -2
drivers/gpu/drm/udl/udl_fb.c
··· 423 423 } 424 424 425 425 if (ufb->obj->base.import_attach) { 426 - dma_buf_end_cpu_access(ufb->obj->base.import_attach->dmabuf, 427 - DMA_FROM_DEVICE); 426 + ret = dma_buf_end_cpu_access(ufb->obj->base.import_attach->dmabuf, 427 + DMA_FROM_DEVICE); 428 428 } 429 429 430 430 unlock:
+4 -2
drivers/staging/android/ion/ion.c
··· 1141 1141 return PTR_ERR_OR_ZERO(vaddr); 1142 1142 } 1143 1143 1144 - static void ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, 1145 - enum dma_data_direction direction) 1144 + static int ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, 1145 + enum dma_data_direction direction) 1146 1146 { 1147 1147 struct ion_buffer *buffer = dmabuf->priv; 1148 1148 1149 1149 mutex_lock(&buffer->lock); 1150 1150 ion_buffer_kmap_put(buffer); 1151 1151 mutex_unlock(&buffer->lock); 1152 + 1153 + return 0; 1152 1154 } 1153 1155 1154 1156 static struct dma_buf_ops dma_buf_ops = {
+3 -3
include/linux/dma-buf.h
··· 94 94 void (*release)(struct dma_buf *); 95 95 96 96 int (*begin_cpu_access)(struct dma_buf *, enum dma_data_direction); 97 - void (*end_cpu_access)(struct dma_buf *, enum dma_data_direction); 97 + int (*end_cpu_access)(struct dma_buf *, enum dma_data_direction); 98 98 void *(*kmap_atomic)(struct dma_buf *, unsigned long); 99 99 void (*kunmap_atomic)(struct dma_buf *, unsigned long, void *); 100 100 void *(*kmap)(struct dma_buf *, unsigned long); ··· 224 224 enum dma_data_direction); 225 225 int dma_buf_begin_cpu_access(struct dma_buf *dma_buf, 226 226 enum dma_data_direction dir); 227 - void dma_buf_end_cpu_access(struct dma_buf *dma_buf, 228 - enum dma_data_direction dir); 227 + int dma_buf_end_cpu_access(struct dma_buf *dma_buf, 228 + enum dma_data_direction dir); 229 229 void *dma_buf_kmap_atomic(struct dma_buf *, unsigned long); 230 230 void dma_buf_kunmap_atomic(struct dma_buf *, unsigned long, void *); 231 231 void *dma_buf_kmap(struct dma_buf *, unsigned long);
+1 -1
include/linux/fence.h
··· 294 294 if (WARN_ON(f1->context != f2->context)) 295 295 return false; 296 296 297 - return f1->seqno - f2->seqno < INT_MAX; 297 + return (int)(f1->seqno - f2->seqno) > 0; 298 298 } 299 299 300 300 /**