From: Christoph Hellwig <hch@lst.de>
To: airlied@linux.ie, dri-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: mmap abuses in drm
Date: Tue, 19 Dec 2006 12:41:08 +0100 [thread overview]
Message-ID: <20061219114108.GA3189@lst.de> (raw)
Folks, could someone explain what the heck is going on here:
static int i830_map_buffer(drm_buf_t * buf, struct file *filp)
{
drm_file_t *priv = filp->private_data;
drm_device_t *dev = priv->head->dev;
drm_i830_buf_priv_t *buf_priv = buf->dev_private;
drm_i830_private_t *dev_priv = dev->dev_private;
const struct file_operations *old_fops;
unsigned long virtual;
int retcode = 0;
if (buf_priv->currently_mapped == I830_BUF_MAPPED)
return -EINVAL;
down_write(¤t->mm->mmap_sem);
old_fops = filp->f_op;
filp->f_op = &i830_buffer_fops;
dev_priv->mmap_buffer = buf;
virtual = do_mmap(filp, 0, buf->total, PROT_READ | PROT_WRITE,
MAP_SHARED, buf->bus_address);
dev_priv->mmap_buffer = NULL;
filp->f_op = old_fops;
if (IS_ERR((void *)virtual)) { /* ugh */
/* Real error */
DRM_ERROR("mmap error\n");
retcode = PTR_ERR((void *)virtual);
buf_priv->virtual = NULL;
} else {
buf_priv->virtual = (void __user *)virtual;
}
up_write(¤t->mm->mmap_sem);
return retcode;
}
(and same crap in i810_dma.c aswell)
Overriding the file operations just for mmap is for one thing racy
as hell and for another very fragile as the mmap and nopage routines
have to agree closely on what to do.
Even further why in hell do you call do_mmap from a driver? Mapping
memory into userspace from anything but syscall dedicated to it is
surely a desaster waiting to happen.
Is there any chance we can get rid of this crap (and similar stuff in
drm_bufs.c) as part of the memory manager overhaul? Long-term I'd
like to get rid of the do_mmap(_pgoff) export to avoid that people
introduce similar braindamage again.
next reply other threads:[~2006-12-19 11:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-19 11:41 Christoph Hellwig [this message]
2006-12-19 22:59 ` mmap abuses in drm Dave Airlie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061219114108.GA3189@lst.de \
--to=hch@lst.de \
--cc=airlied@linux.ie \
--cc=dri-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox