All of lore.kernel.org
 help / color / mirror / Atom feed
From: suzuki <suzuki@in.ibm.com>
To: linux-mm <linux-mm@kvack.org>
Subject: [RFC] [PATCH] madvise() does not always return -EBADF on non-file mapped area
Date: Wed, 06 Jul 2005 12:28:54 +0530	[thread overview]
Message-ID: <42CB812E.8060605@in.ibm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 536 bytes --]

hi,

I came across the following problem. The madvise() system call returns 
-EBADF for areas which does not map to files, only for *behaviour* 
request MADV_WILLNEED.

Is this the intended behaviour of madvise() ?

According to man pages, madvise returns :

EBADF - the map exists, but the area maps something that isn?t a file.

I have attached a patch which could resolve the issue.

[ There is already a bug reported in OSDL regarding this issue: Bug # 
2995 ].


-- 
regards,

Suzuki K P
Linux Technology Centre
IBM Software Labs


[-- Attachment #2: madvise-ebadf-fix.patch --]
[-- Type: text/plain, Size: 920 bytes --]

Patch to fix madvise() syscall to return -EBADF on non-file mapped regions.

Signed Off by: Suzuki K P <suzuki@in.ibm.com>

--- mm/madvise.c	2005-07-01 16:08:26.000000000 +0530
+++ mm/madvise.c.new	2005-07-01 16:07:45.000000000 +0530
@@ -62,9 +62,6 @@ static long madvise_willneed(struct vm_a
 {
 	struct file *file = vma->vm_file;
 
-	if (!file)
-		return -EBADF;
-
 	start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
 	if (end > vma->vm_end)
 		end = vma->vm_end;
@@ -114,8 +111,12 @@ static long madvise_dontneed(struct vm_a
 static long madvise_vma(struct vm_area_struct * vma, unsigned long start,
 			unsigned long end, int behavior)
 {
+	struct file* filp = vma->vm_file;
 	long error = -EBADF;
 
+	if(!filp)
+		goto  out;
+
 	switch (behavior) {
 	case MADV_NORMAL:
 	case MADV_SEQUENTIAL:
@@ -136,6 +137,7 @@ static long madvise_vma(struct vm_area_s
 		break;
 	}
 		
+out:	
 	return error;
 }
 

             reply	other threads:[~2005-07-06  6:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-06  6:58 suzuki [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-07-01 10:55 [RFC] [PATCH] madvise() does not always return -EBADF on non-file mapped area suzuki

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=42CB812E.8060605@in.ibm.com \
    --to=suzuki@in.ibm.com \
    --cc=linux-mm@kvack.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.