From: "Zhang, Yanmin" <yanmin_zhang@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: kenneth.w.chen@intel.com,
"yanmin.zhang@intel.com" <yanmin.zhang@intel.com>
Subject: [PATCH] Enable mprotect on huge pages
Date: Thu, 23 Feb 2006 11:19:40 +0800 [thread overview]
Message-ID: <1140664780.12944.26.camel@ymzhang-perf.sh.intel.com> (raw)
From: Zhang, Yanmin <yanmin.zhang@intel.com>
2.6.16-rc3 uses hugetlb on-demand paging, but it doesn’t support hugetlb
mprotect. My patch against 2.6.16-rc3 enables this capability.
Signed-off-by: Zhang Yanmin <yanmin.zhang@intel.com>
Discussion is welcomed.
---
diff -Nraup linux-2.6.16-rc3/include/linux/hugetlb.h linux-2.6.16-rc3_mprotect/include/linux/hugetlb.h
--- linux-2.6.16-rc3/include/linux/hugetlb.h 2006-02-14 16:43:50.000000000 +0800
+++ linux-2.6.16-rc3_mprotect/include/linux/hugetlb.h 2006-02-22 00:12:35.000000000 +0800
@@ -41,6 +41,8 @@ struct page *follow_huge_pmd(struct mm_s
pmd_t *pmd, int write);
int is_aligned_hugepage_range(unsigned long addr, unsigned long len);
int pmd_huge(pmd_t pmd);
+void hugetlb_change_protection(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end, pgprot_t newprot);
#ifndef ARCH_HAS_HUGEPAGE_ONLY_RANGE
#define is_hugepage_only_range(mm, addr, len) 0
@@ -101,6 +103,8 @@ static inline unsigned long hugetlb_tota
#define free_huge_page(p) ({ (void)(p); BUG(); })
#define hugetlb_fault(mm, vma, addr, write) ({ BUG(); 0; })
+#define hugetlb_change_protection(vma, address, end, newprot)
+
#ifndef HPAGE_MASK
#define HPAGE_MASK PAGE_MASK /* Keep the compiler happy */
#define HPAGE_SIZE PAGE_SIZE
diff -Nraup linux-2.6.16-rc3/mm/hugetlb.c linux-2.6.16-rc3_mprotect/mm/hugetlb.c
--- linux-2.6.16-rc3/mm/hugetlb.c 2006-02-14 16:43:50.000000000 +0800
+++ linux-2.6.16-rc3_mprotect/mm/hugetlb.c 2006-02-22 00:12:35.000000000 +0800
@@ -572,3 +572,32 @@ int follow_hugetlb_page(struct mm_struct
return i;
}
+
+void hugetlb_change_protection(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end, pgprot_t newprot)
+{
+ struct mm_struct *mm = vma->vm_mm;
+ unsigned long start = address;
+ pte_t *ptep;
+ pte_t pte;
+
+ BUG_ON(address >= end);
+ flush_cache_range(vma, address, end);
+
+ spin_lock(&mm->page_table_lock);
+ for (; address < end; address += HPAGE_SIZE) {
+ ptep = huge_pte_offset(mm, address);
+ if (!ptep)
+ continue;
+ if (pte_present(*ptep)) {
+ pte = ptep_get_and_clear(mm, address, ptep);
+ pte = pte_modify(pte, newprot);
+ set_huge_pte_at(mm, addr, ptep, pte);
+ lazy_mmu_prot_update(pte);
+ }
+ }
+ spin_unlock(&mm->page_table_lock);
+
+ flush_tlb_range(vma, start, end);
+}
+
diff -Nraup linux-2.6.16-rc3/mm/mprotect.c linux-2.6.16-rc3_mprotect/mm/mprotect.c
--- linux-2.6.16-rc3/mm/mprotect.c 2006-01-25 21:54:15.000000000 +0800
+++ linux-2.6.16-rc3_mprotect/mm/mprotect.c 2006-02-22 00:13:34.000000000 +0800
@@ -124,7 +124,7 @@ mprotect_fixup(struct vm_area_struct *vm
* a MAP_NORESERVE private mapping to writable will now reserve.
*/
if (newflags & VM_WRITE) {
- if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_SHARED|VM_HUGETLB))) {
+ if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_SHARED))) {
charged = nrpages;
if (security_vm_enough_memory(charged))
return -ENOMEM;
@@ -166,7 +166,10 @@ success:
*/
vma->vm_flags = newflags;
vma->vm_page_prot = newprot;
- change_protection(vma, start, end, newprot);
+ if (is_vm_hugetlb_page(vma))
+ hugetlb_change_protection(vma, start, end, newprot);
+ else
+ change_protection(vma, start, end, newprot);
vm_stat_account(mm, oldflags, vma->vm_file, -nrpages);
vm_stat_account(mm, newflags, vma->vm_file, nrpages);
return 0;
@@ -240,11 +243,6 @@ sys_mprotect(unsigned long start, size_t
/* Here we know that vma->vm_start <= nstart < vma->vm_end. */
- if (is_vm_hugetlb_page(vma)) {
- error = -EACCES;
- goto out;
- }
-
newflags = vm_flags | (vma->vm_flags & ~(VM_READ | VM_WRITE | VM_EXEC));
/* newflags >> 4 shift VM_MAY% in place of VM_% */
@@ -260,6 +258,12 @@ sys_mprotect(unsigned long start, size_t
tmp = vma->vm_end;
if (tmp > end)
tmp = end;
+ if (is_vm_hugetlb_page(vma) &&
+ is_aligned_hugepage_range(nstart, tmp - nstart)) {
+ error = -EINVAL;
+ goto out;
+ }
+
error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
if (error)
goto out;
next reply other threads:[~2006-02-23 3:21 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-23 3:19 Zhang, Yanmin [this message]
2006-02-24 22:28 ` [PATCH] Enable mprotect on huge pages Andrew Morton
2006-02-26 23:09 ` David Gibson
2006-02-27 5:36 ` Zhang, Yanmin
2006-02-27 6:33 ` Zhang, Yanmin
2006-02-28 1:34 ` Andrew Morton
2006-02-28 3:23 ` Zhang, Yanmin
2006-02-28 3:32 ` David Gibson
2006-02-28 3:37 ` Zhang, Yanmin
2006-02-28 8:24 ` David Gibson
2006-02-27 7:26 ` David Gibson
2006-02-25 8:54 ` Christoph Hellwig
2006-02-25 10:08 ` [2.4.32 - 2.6.15.4] e1000 - Fix mii interface Paul Rolland
2006-02-26 10:42 ` Willy TARREAU
2006-02-26 11:39 ` Paul Rolland
2006-02-26 12:59 ` Jesper Juhl
2006-02-26 14:55 ` Paul Rolland
2006-02-26 15:00 ` Jesper Juhl
2006-02-26 15:12 ` Paul Rolland
2006-02-27 19:26 ` Jesse Brandeburg
[not found] ` <4807377b0602271234v4b6cdeecpbcf8d4a6ac51cd20@mail.gmail.com>
2006-02-28 2:31 ` Jesse Brandeburg
2006-02-28 10:46 ` Paul Rolland
2006-02-27 5:09 ` [PATCH] Enable mprotect on huge pages Zhang, Yanmin
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=1140664780.12944.26.camel@ymzhang-perf.sh.intel.com \
--to=yanmin_zhang@linux.intel.com \
--cc=kenneth.w.chen@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=yanmin.zhang@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).