linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Will Huck <will.huckk@gmail.com>
To: Gil Weber <gilw@cse-semaphore.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	Michal Hocko <mhocko@suse.cz>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Hugh Dickins <hughd@google.com>
Subject: Re: mmap sync issue
Date: Sun, 17 Mar 2013 07:39:34 +0800	[thread overview]
Message-ID: <514502B6.2090804@gmail.com> (raw)
In-Reply-To: <DEACCBA4C6A9D145A6A68B5F5BE581B80FC057AB@HKXPRD0310MB353.apcprd03.prod.outlook.com>

Cc experts
On 03/15/2013 07:39 PM, Gil Weber wrote:
> Hello,
> I am experiencing an issue with my device driver. I am using mmap and ioctl to share information with my user space application.
> The thing is that the shared memory does not seems to be synced. Do check this, I have done a simple test:
>
> int fd = open("/dev/test", O_RDWR | O_SYNC);
> int * addr = mmap(0, 4, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
> 	
> for (i=0 ; i<100 ; i++ )
> {
> 	*addr = i;
> 	ioctl(fd, 0, 0);
> }
>
>
> In my device driver, the only thing I do in ioctl is to display the content of the shared memory, and here is the result:
>
> [ 5158.967000] Value : 0
> [ 5158.967000] Value : 1
> [ 5158.967000] Value : 1
> [ 5158.967000] Value : 1
> [ 5158.967000] Value : 1
> [ 5158.967000] Value : 1
> [ 5158.967000] Value : 1
> [ 5158.967000] Value : 1
> [ 5158.967000] Value : 1
> [ 5158.967000] Value : 1
> [ 5158.967000] Value : 1
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> [ 5158.968000] Value : 11
> ...
>
>
> So, clearly, memory is not synced...
> Here is the code in my device driver:
>
> static int test_open(struct inode *inode, struct file *filp)
> {
> 	return 0;
> }
>
> static int test_release(struct inode *inode, struct file *filp)
> {
> 	return 0;
> }
>
> static int test_mmap(struct file *filp, struct vm_area_struct *vma)
> {
> 	int ret;
> 	unsigned long start = vma->vm_start;
> 	unsigned long pfn;
>
> 	pfn = vmalloc_to_pfn(vmalloc_area);
> 	if ((ret = remap_pfn_range(vma, start, pfn, PAGE_SIZE, PAGE_SHARED)) < 0) {
> 		return ret;
> 	}
> 	
> 	return 0;
> }
>
> static long test_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
> {
> 	printk (KERN_INFO "Value : %d\n", vmalloc_area[0]);
> 	return 0;
> }
>
> static struct file_operations test_fops = {
> 	.open = test_open,
> 	.release = test_release,
> 	.mmap = test_mmap,
> 	.unlocked_ioctl = test_ioctl,
> 	.owner = THIS_MODULE,
> };
>
> This is done on an arm architecture (AT91 SAM9X5) with a kernel 3.5.
> I have done the test, with the same code, on a powerpc target, with a kernel 2.6.27, and it seems to work (but maybe by chance?)
> Am I missing something?
> Maybe I need to implement the sync function in file operations, but in that case, how can I know that all mapped memory is synced?
>
> Thanks in advance,
> Gil Weber
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=ilto:"dont@kvack.org"> email@kvack.org </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2013-03-16 23:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-15 11:39 Gil Weber
2013-03-16 23:39 ` Will Huck [this message]
2013-03-17  0:42   ` Michel Lespinasse
2013-03-18  2:33     ` Hugh Dickins

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=514502B6.2090804@gmail.com \
    --to=will.huckk@gmail.com \
    --cc=gilw@cse-semaphore.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.cz \
    /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