Skip to content

Commit 771d3fe

Browse files
committed
Merge branch 'work.drm' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull DRM compat ioctl handling updates from Al Viro: "This kills the double-copies in there and tons of field-by-field copyin/copyout. Several dead ioctls put to rest, while we are at it - the native counterparts had been gone for a decade, so we can bloody well fail early on the compat side. No point rearranging the 32bit structure into 64bit one (and back) only to be told "piss off, I don't know that ioctl" by the native code..." * 'work.drm' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (29 commits) Fix trivial misannotations mga: switch compat ioctls to drm_ioctl_kernel() radeon: take out dead compat ioctls drm compat: ia64 is not biarch drm_compat_ioctl(): tidy up a bit switch compat_drm_mapbufs() to drm_ioctl_kernel() switch compat_drm_rmmap() to drm_ioctl_kernel() switch compat_drm_mode_addfb2() to drm_ioctl_kernel() switch compat_drm_wait_vblank() to drm_ioctl_kernel() switch compat_drm_update_draw() compat_drm: switch sg ioctls compat_drm: switch AGP compat ioctls to drm_ioctl_kernel() switch compat_drm_dma() to drm_ioctl_kernel() switch compat_drm_resctx() to drm_ioctl_kernel() switch compat_drm_getsareactx() to drm_ioctl_kernel() switch compat_drm_setsareactx() to drm_ioctl_kernel() switch compat_drm_freebufs() to drm_ioctl_kernel() switch compat_drm_markbufs() to drm_ioctl_kernel() switch compat_drm_addmap() to drm_ioctl_kernel() switch compat_drm_getstats() to drm_ioctl_kernel() ...
2 parents 2074006 + b87b786 commit 771d3fe

12 files changed

Lines changed: 476 additions & 1045 deletions

File tree

‎drivers/gpu/drm/drm_bufs.c‎

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,11 +1258,11 @@ int drm_legacy_addbufs(struct drm_device *dev, void *data,
12581258
* lock, preventing of allocating more buffers after this call. Information
12591259
* about each requested buffer is then copied into user space.
12601260
*/
1261-
int drm_legacy_infobufs(struct drm_device *dev, void *data,
1262-
struct drm_file *file_priv)
1261+
int __drm_legacy_infobufs(struct drm_device *dev,
1262+
void *data, int *p,
1263+
int (*f)(void *, int, struct drm_buf_entry *))
12631264
{
12641265
struct drm_device_dma *dma = dev->dma;
1265-
struct drm_buf_info *request = data;
12661266
int i;
12671267
int count;
12681268

@@ -1290,26 +1290,12 @@ int drm_legacy_infobufs(struct drm_device *dev, void *data,
12901290

12911291
DRM_DEBUG("count = %d\n", count);
12921292

1293-
if (request->count >= count) {
1293+
if (*p >= count) {
12941294
for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
1295-
if (dma->bufs[i].buf_count) {
1296-
struct drm_buf_desc __user *to =
1297-
&request->list[count];
1298-
struct drm_buf_entry *from = &dma->bufs[i];
1299-
if (copy_to_user(&to->count,
1300-
&from->buf_count,
1301-
sizeof(from->buf_count)) ||
1302-
copy_to_user(&to->size,
1303-
&from->buf_size,
1304-
sizeof(from->buf_size)) ||
1305-
copy_to_user(&to->low_mark,
1306-
&from->low_mark,
1307-
sizeof(from->low_mark)) ||
1308-
copy_to_user(&to->high_mark,
1309-
&from->high_mark,
1310-
sizeof(from->high_mark)))
1295+
struct drm_buf_entry *from = &dma->bufs[i];
1296+
if (from->buf_count) {
1297+
if (f(data, count, from) < 0)
13111298
return -EFAULT;
1312-
13131299
DRM_DEBUG("%d %d %d %d %d\n",
13141300
i,
13151301
dma->bufs[i].buf_count,
@@ -1320,11 +1306,29 @@ int drm_legacy_infobufs(struct drm_device *dev, void *data,
13201306
}
13211307
}
13221308
}
1323-
request->count = count;
1309+
*p = count;
13241310

13251311
return 0;
13261312
}
13271313

1314+
static int copy_one_buf(void *data, int count, struct drm_buf_entry *from)
1315+
{
1316+
struct drm_buf_info *request = data;
1317+
struct drm_buf_desc __user *to = &request->list[count];
1318+
struct drm_buf_desc v = {.count = from->buf_count,
1319+
.size = from->buf_size,
1320+
.low_mark = from->low_mark,
1321+
.high_mark = from->high_mark};
1322+
return copy_to_user(to, &v, offsetof(struct drm_buf_desc, flags));
1323+
}
1324+
1325+
int drm_legacy_infobufs(struct drm_device *dev, void *data,
1326+
struct drm_file *file_priv)
1327+
{
1328+
struct drm_buf_info *request = data;
1329+
return __drm_legacy_infobufs(dev, data, &request->count, copy_one_buf);
1330+
}
1331+
13281332
/**
13291333
* Specifies a low and high water mark for buffer allocation
13301334
*
@@ -1439,15 +1443,15 @@ int drm_legacy_freebufs(struct drm_device *dev, void *data,
14391443
* offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls
14401444
* drm_mmap_dma().
14411445
*/
1442-
int drm_legacy_mapbufs(struct drm_device *dev, void *data,
1443-
struct drm_file *file_priv)
1446+
int __drm_legacy_mapbufs(struct drm_device *dev, void *data, int *p,
1447+
void __user **v,
1448+
int (*f)(void *, int, unsigned long,
1449+
struct drm_buf *),
1450+
struct drm_file *file_priv)
14441451
{
14451452
struct drm_device_dma *dma = dev->dma;
14461453
int retcode = 0;
1447-
const int zero = 0;
14481454
unsigned long virtual;
1449-
unsigned long address;
1450-
struct drm_buf_map *request = data;
14511455
int i;
14521456

14531457
if (!drm_core_check_feature(dev, DRIVER_LEGACY))
@@ -1467,7 +1471,7 @@ int drm_legacy_mapbufs(struct drm_device *dev, void *data,
14671471
dev->buf_use++; /* Can't allocate more after this call */
14681472
spin_unlock(&dev->buf_lock);
14691473

1470-
if (request->count >= dma->buf_count) {
1474+
if (*p >= dma->buf_count) {
14711475
if ((dev->agp && (dma->flags & _DRM_DMA_USE_AGP))
14721476
|| (drm_core_check_feature(dev, DRIVER_SG)
14731477
&& (dma->flags & _DRM_DMA_USE_SG))) {
@@ -1492,41 +1496,51 @@ int drm_legacy_mapbufs(struct drm_device *dev, void *data,
14921496
retcode = (signed long)virtual;
14931497
goto done;
14941498
}
1495-
request->virtual = (void __user *)virtual;
1499+
*v = (void __user *)virtual;
14961500

14971501
for (i = 0; i < dma->buf_count; i++) {
1498-
if (copy_to_user(&request->list[i].idx,
1499-
&dma->buflist[i]->idx,
1500-
sizeof(request->list[0].idx))) {
1501-
retcode = -EFAULT;
1502-
goto done;
1503-
}
1504-
if (copy_to_user(&request->list[i].total,
1505-
&dma->buflist[i]->total,
1506-
sizeof(request->list[0].total))) {
1507-
retcode = -EFAULT;
1508-
goto done;
1509-
}
1510-
if (copy_to_user(&request->list[i].used,
1511-
&zero, sizeof(zero))) {
1512-
retcode = -EFAULT;
1513-
goto done;
1514-
}
1515-
address = virtual + dma->buflist[i]->offset; /* *** */
1516-
if (copy_to_user(&request->list[i].address,
1517-
&address, sizeof(address))) {
1502+
if (f(data, i, virtual, dma->buflist[i]) < 0) {
15181503
retcode = -EFAULT;
15191504
goto done;
15201505
}
15211506
}
15221507
}
15231508
done:
1524-
request->count = dma->buf_count;
1525-
DRM_DEBUG("%d buffers, retcode = %d\n", request->count, retcode);
1509+
*p = dma->buf_count;
1510+
DRM_DEBUG("%d buffers, retcode = %d\n", *p, retcode);
15261511

15271512
return retcode;
15281513
}
15291514

1515+
static int map_one_buf(void *data, int idx, unsigned long virtual,
1516+
struct drm_buf *buf)
1517+
{
1518+
struct drm_buf_map *request = data;
1519+
unsigned long address = virtual + buf->offset; /* *** */
1520+
1521+
if (copy_to_user(&request->list[idx].idx, &buf->idx,
1522+
sizeof(request->list[0].idx)))
1523+
return -EFAULT;
1524+
if (copy_to_user(&request->list[idx].total, &buf->total,
1525+
sizeof(request->list[0].total)))
1526+
return -EFAULT;
1527+
if (clear_user(&request->list[idx].used, sizeof(int)))
1528+
return -EFAULT;
1529+
if (copy_to_user(&request->list[idx].address, &address,
1530+
sizeof(address)))
1531+
return -EFAULT;
1532+
return 0;
1533+
}
1534+
1535+
int drm_legacy_mapbufs(struct drm_device *dev, void *data,
1536+
struct drm_file *file_priv)
1537+
{
1538+
struct drm_buf_map *request = data;
1539+
return __drm_legacy_mapbufs(dev, data, &request->count,
1540+
&request->virtual, map_one_buf,
1541+
file_priv);
1542+
}
1543+
15301544
int drm_legacy_dma_ioctl(struct drm_device *dev, void *data,
15311545
struct drm_file *file_priv)
15321546
{

‎drivers/gpu/drm/drm_internal.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,6 @@ static inline int drm_debugfs_crtc_crc_add(struct drm_crtc *crtc)
143143
return 0;
144144
}
145145
#endif
146+
drm_ioctl_t drm_version;
147+
drm_ioctl_t drm_getunique;
148+
drm_ioctl_t drm_getclient;

0 commit comments

Comments
 (0)