All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marco <marco.stornelli@gmail.com>
To: Linux FS Devel <linux-fsdevel@vger.kernel.org>
Cc: Linux Embedded <linux-embedded@vger.kernel.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	Daniel Walker <dwalker@soe.ucsc.edu>
Subject: [PATCH 13/14] Pramfs: Write protection
Date: Sat, 13 Jun 2009 15:23:01 +0200	[thread overview]
Message-ID: <4A33A835.901@gmail.com> (raw)

From: Marco Stornelli <marco.stornelli@gmail.com>

Write protection.

Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
---

diff -uprN linux-2.6.30-orig/fs/pramfs/wprotect.c linux-2.6.30/fs/pramfs/wprotect.c
--- linux-2.6.30-orig/fs/pramfs/wprotect.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.30/fs/pramfs/wprotect.c	2009-06-13 12:54:16.000000000 +0200
@@ -0,0 +1,84 @@
+/*
+ * FILE NAME fs/pramfs/wprotect.c
+ *
+ * BRIEF DESCRIPTION
+ *
+ * Write protection for the filesystem pages.
+ *
+ * Copyright 2009 Marco Stornelli <marco.stornelli@gmail.com>
+ * Copyright 2003 Sony Corporation
+ * Copyright 2003 Matsushita Electric Industrial Co., Ltd.
+ * 2003-2004 (c) MontaVista Software, Inc. , Steve Longerbeam
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/mm.h>
+#include <asm/pgtable.h>
+#include <asm/pgalloc.h>
+#include <asm/tlbflush.h>
+#include "pram_fs.h"
+
+/* init_mm.page_table_lock must be held before calling! */
+static void pram_page_writeable(unsigned long addr, int rw)
+{
+	pgd_t *pgdp;
+	pud_t *pudp;
+	pmd_t *pmdp;
+	pte_t *ptep;
+
+	pgdp = pgd_offset_k(addr);
+	if (!pgd_none(*pgdp)) {
+		pudp = pud_offset(pgdp, addr);
+		if (!pud_none(*pudp)) {
+			pmdp = pmd_offset(pudp, addr);
+			if (!pmd_none(*pmdp)) {
+				pte_t pte;
+				ptep = pte_offset_kernel(pmdp, addr);
+				pte = *ptep;
+				if (pte_present(pte)) {
+					pte = rw ? pte_mkwrite(pte) :
+						pte_wrprotect(pte);
+					set_pte(ptep, pte);
+				}
+			}
+		}
+	}
+}
+
+/* init_mm.page_table_lock must be held before calling! */
+void pram_writeable(void *vaddr, unsigned long size, int rw)
+{
+	unsigned long addr = (unsigned long)vaddr & PAGE_MASK;
+	unsigned long end = (unsigned long)vaddr + size;
+	unsigned long start = addr;
+
+	do {
+		pram_page_writeable(addr, rw);
+		addr += PAGE_SIZE;
+	} while (addr && (addr < end));
+
+
+	/*
+	 * NOTE: we will always flush just one page (one TLB
+	 * entry) except possibly in one case: when a new
+	 * filesystem is initialized at mount time, when pram_read_super
+	 * calls pram_lock_range to make the super block, inode
+	 * table, and bitmap writeable.
+	 */
+#if defined(CONFIG_ARM) || defined(CONFIG_M68K) || defined(CONFIG_H8300) || \
+	defined(CONFIG_BLACKFIN)
+	/*
+	 * FIXME: so far only these archs have flush_tlb_kernel_page(),
+	 * for the rest just use flush_tlb_kernel_range(). Not ideal
+	 * to use _range() because many archs just flush the whole TLB.
+	 */
+	if (end <= start + PAGE_SIZE)
+		flush_tlb_kernel_page(start);
+	else
+#endif
+		flush_tlb_kernel_range(start, end);
+}


             reply	other threads:[~2009-06-13 13:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-13 13:23 Marco [this message]
2009-06-17  2:35 ` [PATCH 13/14] Pramfs: Write protection Jared Hulbert
2009-06-17  7:07   ` Paul Mundt
  -- strict thread matches above, loose matches on Subject: below --
2009-06-17 16:58 [PATCH 13/14] Pramfs: Write Protection Marco
2009-06-17 16:58 Marco
2009-06-17 16:58 ` Marco
2009-06-17 17:10 ` Mike Frysinger
2009-06-17 17:10 ` Mike Frysinger
2009-06-17 17:10   ` Mike Frysinger
2009-06-18  2:57 ` Paul Mundt
2009-06-18  2:57 ` Paul Mundt
2009-06-18  2:57   ` Paul Mundt
2009-06-18  6:24   ` Marco Stornelli
2009-06-18  6:24     ` Marco Stornelli
2009-06-18  6:28     ` Paul Mundt
2009-06-18  6:28       ` Paul Mundt
2009-06-18  6:28     ` Paul Mundt
2009-06-18  6:24   ` Marco Stornelli

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=4A33A835.901@gmail.com \
    --to=marco.stornelli@gmail.com \
    --cc=dwalker@soe.ucsc.edu \
    --cc=linux-embedded@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --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 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.