Skip to content

Commit 537a1bf

Browse files
Krzysztof-Htorvalds
authored andcommitted
fbdev: add mutex for fb_mmap locking
Add a mutex to avoid a circular locking problem between the mm layer semaphore and fbdev ioctl mutex through the fb_mmap() call. Also, add mutex to all places where smem_start and smem_len fields change so the mutex inside the fb_mmap() is actually used. Changing of these fields before calling the framebuffer_register() are not mutexed. This is 2.6.31 material. It removes one lockdep (fb_mmap() and register_framebuffer()) but there is still another one (fb_release() and register_framebuffer()). It also cleans up handling of the smem_start and smem_len fields used by mutexed section of the fb_mmap(). Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: "Rafael J. Wysocki" <rjw@sisk.pl> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 70d6027 commit 537a1bf

16 files changed

Lines changed: 74 additions & 42 deletions

File tree

‎drivers/video/atafb.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,10 @@ static int atafb_get_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
24142414
if (err)
24152415
return err;
24162416
memset(fix, 0, sizeof(struct fb_fix_screeninfo));
2417-
return fbhw->encode_fix(fix, &par);
2417+
mutex_lock(&info->mm_lock);
2418+
err = fbhw->encode_fix(fix, &par);
2419+
mutex_unlock(&info->mm_lock);
2420+
return err;
24182421
}
24192422

24202423
static int atafb_get_var(struct fb_var_screeninfo *var, struct fb_info *info)
@@ -2743,7 +2746,9 @@ static int atafb_set_par(struct fb_info *info)
27432746

27442747
/* Decode wanted screen parameters */
27452748
fbhw->decode_var(&info->var, par);
2749+
mutex_lock(&info->mm_lock);
27462750
fbhw->encode_fix(&info->fix, par);
2751+
mutex_unlock(&info->mm_lock);
27472752

27482753
/* Set new videomode */
27492754
ata_set_par(par);

‎drivers/video/atmel_lcdfb.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ static int atmel_lcdfb_alloc_video_memory(struct atmel_lcdfb_info *sinfo)
270270

271271
smem_len = (var->xres_virtual * var->yres_virtual
272272
* ((var->bits_per_pixel + 7) / 8));
273+
mutex_lock(&info->mm_lock);
273274
info->fix.smem_len = max(smem_len, sinfo->smem_len);
275+
mutex_unlock(&info->mm_lock);
274276

275277
info->screen_base = dma_alloc_writecombine(info->device, info->fix.smem_len,
276278
(dma_addr_t *)&info->fix.smem_start, GFP_KERNEL);

‎drivers/video/fbmem.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,6 @@ static long fb_compat_ioctl(struct file *file, unsigned int cmd,
13101310

13111311
static int
13121312
fb_mmap(struct file *file, struct vm_area_struct * vma)
1313-
__acquires(&info->lock)
1314-
__releases(&info->lock)
13151313
{
13161314
int fbidx = iminor(file->f_path.dentry->d_inode);
13171315
struct fb_info *info = registered_fb[fbidx];
@@ -1325,30 +1323,28 @@ __releases(&info->lock)
13251323
off = vma->vm_pgoff << PAGE_SHIFT;
13261324
if (!fb)
13271325
return -ENODEV;
1326+
mutex_lock(&info->mm_lock);
13281327
if (fb->fb_mmap) {
13291328
int res;
1330-
mutex_lock(&info->lock);
13311329
res = fb->fb_mmap(info, vma);
1332-
mutex_unlock(&info->lock);
1330+
mutex_unlock(&info->mm_lock);
13331331
return res;
13341332
}
13351333

1336-
mutex_lock(&info->lock);
1337-
13381334
/* frame buffer memory */
13391335
start = info->fix.smem_start;
13401336
len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len);
13411337
if (off >= len) {
13421338
/* memory mapped io */
13431339
off -= len;
13441340
if (info->var.accel_flags) {
1345-
mutex_unlock(&info->lock);
1341+
mutex_unlock(&info->mm_lock);
13461342
return -EINVAL;
13471343
}
13481344
start = info->fix.mmio_start;
13491345
len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
13501346
}
1351-
mutex_unlock(&info->lock);
1347+
mutex_unlock(&info->mm_lock);
13521348
start &= PAGE_MASK;
13531349
if ((vma->vm_end - vma->vm_start + off) > len)
13541350
return -EINVAL;
@@ -1518,6 +1514,7 @@ register_framebuffer(struct fb_info *fb_info)
15181514
break;
15191515
fb_info->node = i;
15201516
mutex_init(&fb_info->lock);
1517+
mutex_init(&fb_info->mm_lock);
15211518

15221519
fb_info->dev = device_create(fb_class, fb_info->device,
15231520
MKDEV(FB_MAJOR, i), NULL, "fb%d", i);

‎drivers/video/fsl-diu-fb.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -750,24 +750,26 @@ static void update_lcdc(struct fb_info *info)
750750
static int map_video_memory(struct fb_info *info)
751751
{
752752
phys_addr_t phys;
753+
u32 smem_len = info->fix.line_length * info->var.yres_virtual;
753754

754755
pr_debug("info->var.xres_virtual = %d\n", info->var.xres_virtual);
755756
pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
756757
pr_debug("info->fix.line_length = %d\n", info->fix.line_length);
758+
pr_debug("MAP_VIDEO_MEMORY: smem_len = %u\n", smem_len);
757759

758-
info->fix.smem_len = info->fix.line_length * info->var.yres_virtual;
759-
pr_debug("MAP_VIDEO_MEMORY: smem_len = %d\n", info->fix.smem_len);
760-
info->screen_base = fsl_diu_alloc(info->fix.smem_len, &phys);
760+
info->screen_base = fsl_diu_alloc(smem_len, &phys);
761761
if (info->screen_base == NULL) {
762762
printk(KERN_ERR "Unable to allocate fb memory\n");
763763
return -ENOMEM;
764764
}
765+
mutex_lock(&info->mm_lock);
765766
info->fix.smem_start = (unsigned long) phys;
767+
info->fix.smem_len = smem_len;
768+
mutex_unlock(&info->mm_lock);
766769
info->screen_size = info->fix.smem_len;
767770

768771
pr_debug("Allocated fb @ paddr=0x%08lx, size=%d.\n",
769-
info->fix.smem_start,
770-
info->fix.smem_len);
772+
info->fix.smem_start, info->fix.smem_len);
771773
pr_debug("screen base %p\n", info->screen_base);
772774

773775
return 0;
@@ -776,9 +778,11 @@ static int map_video_memory(struct fb_info *info)
776778
static void unmap_video_memory(struct fb_info *info)
777779
{
778780
fsl_diu_free(info->screen_base, info->fix.smem_len);
781+
mutex_lock(&info->mm_lock);
779782
info->screen_base = NULL;
780783
info->fix.smem_start = 0;
781784
info->fix.smem_len = 0;
785+
mutex_unlock(&info->mm_lock);
782786
}
783787

784788
/*

‎drivers/video/i810/i810_main.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,10 @@ static int encode_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
10901090
memset(fix, 0, sizeof(struct fb_fix_screeninfo));
10911091

10921092
strcpy(fix->id, "I810");
1093+
mutex_lock(&info->mm_lock);
10931094
fix->smem_start = par->fb.physical;
10941095
fix->smem_len = par->fb.size;
1096+
mutex_unlock(&info->mm_lock);
10951097
fix->type = FB_TYPE_PACKED_PIXELS;
10961098
fix->type_aux = 0;
10971099
fix->xpanstep = 8;

‎drivers/video/matrox/matroxfb_base.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,10 @@ static void matroxfb_update_fix(WPMINFO2)
724724
struct fb_fix_screeninfo *fix = &ACCESS_FBINFO(fbcon).fix;
725725
DBG(__func__)
726726

727+
mutex_lock(&ACCESS_FBINFO(fbcon).mm_lock);
727728
fix->smem_start = ACCESS_FBINFO(video.base) + ACCESS_FBINFO(curr.ydstorg.bytes);
728729
fix->smem_len = ACCESS_FBINFO(video.len_usable) - ACCESS_FBINFO(curr.ydstorg.bytes);
730+
mutex_unlock(&ACCESS_FBINFO(fbcon).mm_lock);
729731
}
730732

731733
static int matroxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
@@ -2081,6 +2083,7 @@ static int matroxfb_probe(struct pci_dev* pdev, const struct pci_device_id* dumm
20812083
spin_lock_init(&ACCESS_FBINFO(lock.accel));
20822084
init_rwsem(&ACCESS_FBINFO(crtc2.lock));
20832085
init_rwsem(&ACCESS_FBINFO(altout.lock));
2086+
mutex_init(&ACCESS_FBINFO(fbcon).mm_lock);
20842087
ACCESS_FBINFO(irq_flags) = 0;
20852088
init_waitqueue_head(&ACCESS_FBINFO(crtc1.vsync.wait));
20862089
init_waitqueue_head(&ACCESS_FBINFO(crtc2.vsync.wait));

‎drivers/video/matrox/matroxfb_crtc2.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,16 @@ static int matroxfb_dh_release(struct fb_info* info, int user) {
289289
#undef m2info
290290
}
291291

292-
static void matroxfb_dh_init_fix(struct matroxfb_dh_fb_info *m2info) {
292+
static void matroxfb_dh_init_fix(struct matroxfb_dh_fb_info *m2info)
293+
{
293294
struct fb_fix_screeninfo *fix = &m2info->fbcon.fix;
294295

295296
strcpy(fix->id, "MATROX DH");
296297

298+
mutex_lock(&m2info->fbcon.mm_lock);
297299
fix->smem_start = m2info->video.base;
298300
fix->smem_len = m2info->video.len_usable;
301+
mutex_unlock(&m2info->fbcon.mm_lock);
299302
fix->ypanstep = 1;
300303
fix->ywrapstep = 0;
301304
fix->xpanstep = 8; /* TBD */

‎drivers/video/mx3fb.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ static uint32_t bpp_to_pixfmt(int bpp)
669669
}
670670

671671
static int mx3fb_blank(int blank, struct fb_info *fbi);
672-
static int mx3fb_map_video_memory(struct fb_info *fbi);
672+
static int mx3fb_map_video_memory(struct fb_info *fbi, unsigned int mem_len);
673673
static int mx3fb_unmap_video_memory(struct fb_info *fbi);
674674

675675
/**
@@ -742,8 +742,7 @@ static int mx3fb_set_par(struct fb_info *fbi)
742742
if (fbi->fix.smem_start)
743743
mx3fb_unmap_video_memory(fbi);
744744

745-
fbi->fix.smem_len = mem_len;
746-
if (mx3fb_map_video_memory(fbi) < 0) {
745+
if (mx3fb_map_video_memory(fbi, mem_len) < 0) {
747746
mutex_unlock(&mx3_fbi->mutex);
748747
return -ENOMEM;
749748
}
@@ -1198,30 +1197,34 @@ static int mx3fb_resume(struct platform_device *pdev)
11981197
/**
11991198
* mx3fb_map_video_memory() - allocates the DRAM memory for the frame buffer.
12001199
* @fbi: framebuffer information pointer
1200+
* @mem_len: length of mapped memory
12011201
* @return: Error code indicating success or failure
12021202
*
12031203
* This buffer is remapped into a non-cached, non-buffered, memory region to
12041204
* allow palette and pixel writes to occur without flushing the cache. Once this
12051205
* area is remapped, all virtual memory access to the video memory should occur
12061206
* at the new region.
12071207
*/
1208-
static int mx3fb_map_video_memory(struct fb_info *fbi)
1208+
static int mx3fb_map_video_memory(struct fb_info *fbi, unsigned int mem_len)
12091209
{
12101210
int retval = 0;
12111211
dma_addr_t addr;
12121212

12131213
fbi->screen_base = dma_alloc_writecombine(fbi->device,
1214-
fbi->fix.smem_len,
1214+
mem_len,
12151215
&addr, GFP_DMA);
12161216

12171217
if (!fbi->screen_base) {
12181218
dev_err(fbi->device, "Cannot allocate %u bytes framebuffer memory\n",
1219-
fbi->fix.smem_len);
1219+
mem_len);
12201220
retval = -EBUSY;
12211221
goto err0;
12221222
}
12231223

1224+
mutex_lock(&fbi->mm_lock);
12241225
fbi->fix.smem_start = addr;
1226+
fbi->fix.smem_len = mem_len;
1227+
mutex_unlock(&fbi->mm_lock);
12251228

12261229
dev_dbg(fbi->device, "allocated fb @ p=0x%08x, v=0x%p, size=%d.\n",
12271230
(uint32_t) fbi->fix.smem_start, fbi->screen_base, fbi->fix.smem_len);
@@ -1251,8 +1254,10 @@ static int mx3fb_unmap_video_memory(struct fb_info *fbi)
12511254
fbi->screen_base, fbi->fix.smem_start);
12521255

12531256
fbi->screen_base = 0;
1257+
mutex_lock(&fbi->mm_lock);
12541258
fbi->fix.smem_start = 0;
12551259
fbi->fix.smem_len = 0;
1260+
mutex_unlock(&fbi->mm_lock);
12561261
return 0;
12571262
}
12581263

‎drivers/video/omap/omapfb_main.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,10 @@ static void set_fb_fix(struct fb_info *fbi)
393393

394394
rg = &plane->fbdev->mem_desc.region[plane->idx];
395395
fbi->screen_base = rg->vaddr;
396+
mutex_lock(&fbi->mm_lock);
396397
fix->smem_start = rg->paddr;
397398
fix->smem_len = rg->size;
399+
mutex_unlock(&fbi->mm_lock);
398400

399401
fix->type = FB_TYPE_PACKED_PIXELS;
400402
bpp = var->bits_per_pixel;
@@ -886,8 +888,10 @@ static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
886888
* plane memory is dealloce'd, the other
887889
* screen parameters in var / fix are invalid.
888890
*/
891+
mutex_lock(&fbi->mm_lock);
889892
fbi->fix.smem_start = 0;
890893
fbi->fix.smem_len = 0;
894+
mutex_unlock(&fbi->mm_lock);
891895
}
892896
}
893897
}

‎drivers/video/platinumfb.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ static int platinumfb_set_par (struct fb_info *info)
141141
offset = 0x10;
142142

143143
info->screen_base = pinfo->frame_buffer + init->fb_offset + offset;
144+
mutex_lock(&info->mm_lock);
144145
info->fix.smem_start = (pinfo->frame_buffer_phys) + init->fb_offset + offset;
146+
mutex_unlock(&info->mm_lock);
145147
info->fix.visual = (pinfo->cmode == CMODE_8) ?
146148
FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
147149
info->fix.line_length = vmode_attrs[pinfo->vmode-1].hres * (1<<pinfo->cmode)

0 commit comments

Comments
 (0)