All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Rohland <cr@sap.com>
To: Alan Cox <alan@redhat.com>
Cc: "Dieter Nützel" <Dieter.Nuetzel@hamburg.de>,
	"Joris van Rantwijk" <joris@deadlock.et.tudelft.nl>,
	"Oliver Paukstadt" <pstadt@stud.fh-heilbronn.de>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Subject: Re: Linux 2.4.5-ac14
Date: 15 Jun 2001 12:01:42 +0200	[thread overview]
Message-ID: <m3bsnq83jt.fsf@linux.local> (raw)
In-Reply-To: <20010615022033Z261561-17720+4111@vger.kernel.org>
In-Reply-To: Dieter Nützel's message of "Fri, 15 Jun 2001 04:33:22 +0200"

Hi Dieter,

On Fri, 15 Jun 2001, Dieter Nützel wrote:
> I see 4.29 GB under shm with your latest try.
> something wrong?

Yes, this is nasty. The appended patch fixes that. (I am not really
happy to need the PG_marker flag for writepage.)

The patch also fixes two other problems:
- shmem_file_setup has to check the given size. Else we can corrupt
  kernel memory on 64bit machines. (Thanks to Oliver Paukstadt for
  detecting this)
- shmem_remount_fs does not initialize the parameters and thus
  corrupts the sizes (detected by Joris van Rantwijk)

Alan, please apply.

Greetings
		Christoph

diff -uNr 5-ac14/include/linux/mm.h 5-ac14-fix/include/linux/mm.h
--- 5-ac14/include/linux/mm.h	Fri Jun 15 10:37:21 2001
+++ 5-ac14-fix/include/linux/mm.h	Fri Jun 15 11:24:06 2001
@@ -357,6 +357,7 @@
 
 #define PageMarker(page)	test_bit(PG_marker, &(page)->flags)
 #define SetPageMarker(page)	set_bit(PG_marker, &(page)->flags)
+#define ClearPageMarker(page)	clear_bit(PG_marker, &(page)->flags)
 
 #ifdef CONFIG_HIGHMEM
 #define PageHighMem(page)		test_bit(PG_highmem, &(page)->flags)
diff -uNr 5-ac14/mm/shmem.c 5-ac14-fix/mm/shmem.c
--- 5-ac14/mm/shmem.c	Fri Jun 15 10:09:21 2001
+++ 5-ac14-fix/mm/shmem.c	Fri Jun 15 11:37:44 2001
@@ -34,6 +34,7 @@
 #define TMPFS_MAGIC	0x01021994
 
 #define ENTRIES_PER_PAGE (PAGE_SIZE/sizeof(unsigned long))
+#define SHMEM_MAX_BLOCKS (SHMEM_NR_DIRECT + ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
 
 #define SHMEM_SB(sb) (&sb->u.shmem_sb)
 
@@ -56,10 +57,12 @@
 	struct inode *inode = (struct inode *)page->mapping->host;
 	struct shmem_sb_info * sbinfo = SHMEM_SB(inode->i_sb);
 
-	inode->i_blocks -= BLOCKS_PER_PAGE;
-	spin_lock (&sbinfo->stat_lock);
-	sbinfo->free_blocks++;
-	spin_unlock (&sbinfo->stat_lock);
+	if (!PageMarker(page)) {
+		inode->i_blocks -= BLOCKS_PER_PAGE;
+		spin_lock (&sbinfo->stat_lock);
+		sbinfo->free_blocks++;
+		spin_unlock (&sbinfo->stat_lock);
+	}
 	atomic_dec(&shmem_nrpages);
 }
 
@@ -241,9 +244,10 @@
 	*entry = swap;
 	error = 0;
 	/* Remove the page from the page cache */
-	atomic_dec(&shmem_nrpages);
 	lru_cache_del(page);
+	SetPageMarker(page);
 	remove_inode_page(page);
+	ClearPageMarker(page);
 
 	/* Add it to the swap cache */
 	add_to_swap_cache(page, swap);
@@ -1062,6 +1066,8 @@
 	unsigned long max_inodes, inodes;
 	struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
 
+	max_blocks = sbinfo->max_blocks;
+	max_inodes = sbinfo->max_inodes;
 	if (shmem_parse_options (data, NULL, &max_blocks, &max_inodes))
 		return -EINVAL;
 
@@ -1110,7 +1116,7 @@
 	sbinfo->free_blocks = blocks;
 	sbinfo->max_inodes = inodes;
 	sbinfo->free_inodes = inodes;
-	sb->s_maxbytes = (unsigned long long)(SHMEM_NR_DIRECT + (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)) << PAGE_CACHE_SHIFT;
+	sb->s_maxbytes = (unsigned long long) SHMEM_MAX_BLOCKS << PAGE_CACHE_SHIFT;
 	sb->s_blocksize = PAGE_CACHE_SIZE;
 	sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
 	sb->s_magic = TMPFS_MAGIC;
@@ -1311,9 +1317,11 @@
 	struct qstr this;
 	int vm_enough_memory(long pages);
 
-	error = -ENOMEM;
+	if (size > (unsigned long long) SHMEM_MAX_BLOCKS << PAGE_CACHE_SHIFT)
+		return ERR_PTR(-EINVAL);
+
 	if (!vm_enough_memory((size) >> PAGE_SHIFT))
-		goto out;
+		return ERR_PTR(-ENOMEM);
 
 	this.name = name;
 	this.len = strlen(name);
@@ -1321,7 +1329,7 @@
 	root = tmpfs_fs_type.kern_mnt->mnt_root;
 	dentry = d_alloc(root, &this);
 	if (!dentry)
-		goto out;
+		return ERR_PTR(-ENOMEM);
 
 	error = -ENFILE;
 	file = get_empty_filp();
@@ -1347,7 +1355,6 @@
 	put_filp(file);
 put_dentry:
 	dput (dentry);
-out:
 	return ERR_PTR(error);	
 }
 /*


  parent reply	other threads:[~2001-06-15 10:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-15  2:33 Linux 2.4.5-ac14 Dieter Nützel
2001-06-15  2:30 ` John Cavan
2001-06-15  3:32   ` Dieter Nützel
2001-06-15  4:55   ` Dieter Nützel
     [not found]   ` <200106150442.AAA22505@spqr.damncats.org>
2001-06-15 11:24     ` John Cavan
2001-06-15 10:01 ` Christoph Rohland [this message]
     [not found] <200106162255.SAA02119@olimpo.networx.com.br.suse.lists.linux.kernel>
     [not found] ` <E15B0vv-000780-00@the-village.bc.nu.suse.lists.linux.kernel>
     [not found]   ` <15146.33742.299279.102372@pizda.ninka.net.suse.lists.linux.kernel>
2001-06-16  5:57     ` Andi Kleen
2001-06-16  6:15       ` Alexander Viro
2001-06-16  7:37       ` Alexander Viro
2001-06-16  8:20         ` Marc ZYNGIER
2001-06-16  8:36           ` Alexander Viro
2001-06-17 20:47         ` Olaf Hering
2001-06-16 16:33       ` David S. Miller
  -- strict thread matches above, loose matches on Subject: below --
2001-06-14 22:44 Alan Cox
2001-06-15 21:05 ` Thiago Vinhas de Moraes
2001-06-15 21:15   ` Alan Cox
2001-06-15 21:37     ` Andreas Dilger
2001-06-15 21:53     ` David S. Miller
2001-06-16 20:56     ` Thiago Vinhas de Moraes
2001-06-16 21:14       ` Arnaldo Carvalho de Melo

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=m3bsnq83jt.fsf@linux.local \
    --to=cr@sap.com \
    --cc=Dieter.Nuetzel@hamburg.de \
    --cc=alan@redhat.com \
    --cc=joris@deadlock.et.tudelft.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pstadt@stud.fh-heilbronn.de \
    /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.