Enable mprotect on huge pages
Subsystems (5)
PATCH 1/1 Enable mprotect on huge pages
From: Zhang, Yanmin <[email protected]>
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.
Discussion is welcomed.
---
include/linux/hugetlb.h +4 -0
@@ -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
mm/hugetlb.c +29 -0
@@ -572,3 +572,32 @@ int follow_hugetlb_page(struct mm_structreturn 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); +} +
mm/mprotect.c +11 -7
@@ -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;
Quoted 6 lines · Yanmin
From: Zhang, Yanmin <[email protected]>
2.6.16-rc3 uses hugetlb on-demand paging, but it
doesn_tsupport hugetlb mprotect. My patch against 2.6.16-rc3 enables this capability.
Well I suppose that makes sense. It does assume that the normal pte protection-changing APIs do the right thing on all architectures which implement huge pages. That's quite possibly the case, but we should confirm that.
Quoted 28 lines
mm/hugetlb.c +28
-0+ +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); +}
Quoted 4 lines · Andrew Morton
Quoted 3 lines · Yanmin
From: Zhang, Yanmin <[email protected]>
Quoted 8 lines
Quoted 3 lines
2.6.16-rc3 uses hugetlb on-demand paging, but it
doesn_tsupport hugetlb mprotect. My patch against 2.6.16-rc3 enables this capability.Well I suppose that makes sense. It does assume that the normal pte protection-changing APIs do the right thing on all architectures which implement huge pages. That's quite possibly the case, but we should confirm that.
Well, it will need to be huge_ptep_get_and_clear() below, not the normal version. But pte_modify should be ok. I'm not sure pte_present() is safe, either, !pte_none() is what we use elsewhere in hugetlb.c.
And.. looks like lazy_mmu_prot_update() is unsafe, too. The only arch which has something here (ia64) has a function which does icache flushes on PAGE_SIZE only.
Quoted 29 lines
Quoted 28 lines
mm/hugetlb.c +28
-0+ +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); +}
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 9 lines · David Gibson
Quoted 8 lines · Andrew Morton
Quoted 6 lines · Yanmin
From: Zhang, Yanmin <[email protected]>
2.6.16-rc3 uses hugetlb on-demand paging, but it
doesn_tsupport hugetlb mprotect. My patch against 2.6.16-rc3 enables this capability.
Quoted 7 lines
Quoted 4 lines
Well I suppose that makes sense. It does assume that the normal pte protection-changing APIs do the right thing on all architectures which implement huge pages. That's quite possibly the case, but we should confirm that.
Well, it will need to be
huge_ptep_get_and_clear()below, not the normal version.
I will change it.
Quoted 3 lines
But
pte_modifyshould be ok. I'm not surepte_present()is safe, either, !pte_none() is what we use elsewhere inhugetlb.c.
pte_present is used in some files while !pte_none is used in other files. Anyway, I will change it to !pte_none.
Quoted 4 lines
And.. looks like
lazy_mmu_prot_update()is unsafe, too. The only arch which has something here (ia64) has a function which does icache flushes onPAGE_SIZEonly.
I already sent another patch to ia64 maillist to fix the issue. See http://marc.theaimsgroup.com/?l=linux-ia64&m=114066414720468&w=2
Thanks.
Quoted 8 lines · Yanmin
Quoted 7 lines · David Gibson
Quoted 6 lines · Andrew Morton
Quoted 5 lines · Yanmin
From: Zhang, Yanmin <[email protected]>
2.6.16-rc3 uses hugetlb on-demand paging, but it
doesn_tsupport hugetlb mprotect. My patch against 2.6.16-rc3 enables this capability.
Based on David's comments, I worked out a new patch against 2.6.16-rc4. Thank David.
I tested it on i386/x86_64/ia64. Who could help test it on other platforms, such like PPC64?
---
include/linux/hugetlb.h +4 -0
@@ -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
mm/hugetlb.c +29 -0
@@ -572,3 +572,32 @@ int follow_hugetlb_page(struct mm_structreturn 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_none (*ptep)) { + pte =huge_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); +} +
mm/mprotect.c +11 -7
@@ -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;
Quoted 7 lines · Yanmin
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
2.6.16-rc3 uses hugetlb on-demand paging, but it
doesn_tsupport hugetlb mprotect. My patch against 2.6.16-rc3 enables this capability.Based on David's comments, I worked out a new patch against 2.6.16-rc4. Thank David.
Please always send an updated changelog when sending an updated patch. Otherwise I have to go trolling back through the email thread to find it, then work out what needs to be changed.
Quoted 3 lines
I tested it on i386/x86_64/ia64. Who could help test it on other platforms, such like PPC64?
I can do that - please send me your test app?
Quoted 5 lines · Andrew Morton
Quoted 4 lines · Yanmin
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
2.6.16-rc3 uses hugetlb on-demand paging, but it
doesn_tsupport hugetlb mprotect. My patch against 2.6.16-rc3 enables this capability.
Quoted 7 lines
Quoted 3 lines
Based on David's comments, I worked out a new patch against 2.6.16-rc4. Thank David.
Please always send an updated changelog when sending an updated patch. Otherwise I have to go trolling back through the email thread to find it, then work out what needs to be changed.
Thanks for your kind reminder. I would do so next time.
Quoted 6 lines
Quoted 4 lines
I tested it on i386/x86_64/ia64. Who could help test it on other platforms, such like PPC64?
I can do that - please send me your test app?
I attach a test case. It will create directory /mnt/hugepages and delete it after testing automatically.
To run it by user root:
#gcc -o mprotect_testcase mprotect_testcase.c
#echo "5">/proc/sys/vm/nr_hugepages
#./mprotect_testcase
You could use gdb to step it to see the changing of the process vma maps.
Thanks.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <setjmp.h>
#define WORK_DIR "/mnt/hugepages"
#define MMAP_DIR "/mnt/hugepages/mmap"
#define MMAP_FILE "/mnt/hugepages/mmap/mmap_file"
char buff[2000];
int get_htlb_mem_stat(int *total_pages, int *free_pages, long *page_size)
{
int fd=0;
int size1=0;
char *start=0;
buff[0] = '\0';
if((fd=open("/proc/meminfo", O_RDONLY)) < 0)
{
printf("Current kernel does not support Huge TLB!\n");
exit(-1);
}
size1 = pread(fd, buff, sizeof(buff), 0);
if(size1>=sizeof(buff))
{
size1 = sizeof(buff)-1;
}
if(size1<0)
size1 = 0;
buff[size1] = '\0';
start = buff;
while(*start) {
if(isupper(*start))
*start = tolower(*start);
start ++;
}
start = strstr(buff, "hugepagesize:");
if(start==NULL)
{
printf("Current kernel does not support Huge TLB!\n");
exit(-1);
}
start += sizeof("hugepagesize:");
if(sscanf(start,"%ld", page_size) != 1)
{
printf("Current kernel does not support Huge TLB!\n");
exit(-1);
}
*page_size *= 1024; /*Convert to BYTE from KB*/
close(fd);
return 0;
}int mmap_open_mmap(int *fd, void **addr, size_t length, int prot, int flags)
{
*fd = open(MMAP_FILE, O_CREAT|O_RDWR, 0755);
if (*fd < 0) {
/*perror("Open failed");*/
exit(errno);
}
*addr = mmap(NULL, length, prot, flags, *fd, 0);
if( *addr == (void *)-1 ) {
/*perror("mmap failed");*/
close(*fd);
*fd = -1;
return -1;
}
return 0;
}int mmap_unmap(void *start, size_t length)
{
int result=0;
result = munmap(start, length);
if(result == -1 ) {
/*perror("mmap_unmap failed");*/
return -1;
}
return 0;
}int test_mmap_mprotect()
{
int result = -1;
void *addr=0;
long tt001;
int fd=-1;
int total_pages;
int free_pages;
long LPAGE_SIZE;
printf("Test mmap mprotect ...");
get_htlb_mem_stat(&total_pages, &free_pages, &LPAGE_SIZE);
result = mount("none", MMAP_DIR, "hugetlbfs", 0, NULL);
if(result != 0) {
perror("Mount fail:");
goto out1;
}
result = mmap_open_mmap(&fd, &addr, LPAGE_SIZE*3, PROT_READ|PROT_WRITE, MAP_SHARED);
if(result < 0)
goto out2;
munmap(addr, LPAGE_SIZE*3);
close(fd);
result = mmap_open_mmap(&fd, &addr, LPAGE_SIZE*3, PROT_NONE, MAP_SHARED);
if(result < 0)
goto out2;
if(mprotect(addr, LPAGE_SIZE*3, PROT_READ)) {
printf("fail!\n");
goto out2;
}
tt001 = ((long *)addr)[0];
if(mprotect(addr+LPAGE_SIZE, LPAGE_SIZE, PROT_READ|PROT_WRITE)) {
printf("fail!\n");
goto out2;
}
((char *)addr)[LPAGE_SIZE+100] = tt001;
if(mprotect(addr+LPAGE_SIZE, LPAGE_SIZE, PROT_READ)) {
printf("fail!\n");
goto out2;
}
printf("pass!\n");out3:
if(result < 0) mmap_unmap(addr, LPAGE_SIZE*3); else result = mmap_unmap(addr, LPAGE_SIZE*3); out2: close(fd); if(result < 0) umount(MMAP_DIR); else result = umount(MMAP_DIR); out1: return result; }
void init()
{
mkdir(WORK_DIR, 0777);
mkdir(MMAP_DIR, 0755);
}void uninit()
{
rmdir(MMAP_DIR);
rmdir(WORK_DIR);
}int main(int argc, char * argv)
{
int total_pages=0;
int free_pages=0;
int result=0;
init();
test_mmap_mprotect();
uninit();
return 0;
}Quoted 20 lines · Yanmin
Quoted 5 lines · Andrew Morton
Quoted 4 lines · Yanmin
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
2.6.16-rc3 uses hugetlb on-demand paging, but it
doesn_tsupport hugetlb mprotect. My patch against 2.6.16-rc3 enables this capability.Quoted 7 lines
Quoted 3 lines
Based on David's comments, I worked out a new patch against 2.6.16-rc4. Thank David.
Please always send an updated changelog when sending an updated patch. Otherwise I have to go trolling back through the email thread to find it, then work out what needs to be changed.
Thanks for your kind reminder. I would do so next time.
Quoted 5 lines
Quoted 4 lines
I tested it on i386/x86_64/ia64. Who could help test it on other platforms, such like PPC64?
Quoted 8 lines
Quoted 1 line
I can do that - please send me your test app?
I attach a test case. It will create directory
/mnt/hugepagesand delete it after testing automatically.To run it by user root:
#gcc -omprotect_testcasemprotect_testcase.c
#echo "5">/proc/sys/vm/nr_hugepages
#./mprotect_testcase
If you could adapt this testcase to fit into the libhugetlbfs testsuite, that would be really great (fromgit://ozlabs.org/~dgibson/git/libhugetlbfs.git). Otherwise I guess I will..
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 4 lines · David Gibson
Quoted 3 lines · Yanmin
Quoted 2 lines · Andrew Morton
Quoted 1 line · Yanmin
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
2.6.16-rc3 uses hugetlb on-demand paging, but it
doesn_tsupport hugetlb mprotect. My patch against 2.6.16-rc3 enables this capability.If you could adapt this testcase to fit into the libhugetlbfs testsuite, that would be really great (from
git://ozlabs.org/~dgibson/git/libhugetlbfs.git). Otherwise I guess I will..
Frankly, I wrote a hugetlb test suite with dozens of test cases. It could run on i386/x86_64/ia64 and caught many hugetlb bugs effectively. I am not sure if I could distribute it out of intel.
Quoted 24 lines · Yanmin
Quoted 5 lines · Andrew Morton
Quoted 4 lines · Yanmin
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
2.6.16-rc3 uses hugetlb on-demand paging, but it
doesn_tsupport hugetlb mprotect. My patch against 2.6.16-rc3 enables this capability.Quoted 7 lines
Quoted 3 lines
Based on David's comments, I worked out a new patch against 2.6.16-rc4. Thank David.
Please always send an updated changelog when sending an updated patch. Otherwise I have to go trolling back through the email thread to find it, then work out what needs to be changed.
Thanks for your kind reminder. I would do so next time.
Quoted 6 lines
Quoted 4 lines
I tested it on i386/x86_64/ia64. Who could help test it on other platforms, such like PPC64?
I can do that - please send me your test app?
I attach a test case. It will create directory
/mnt/hugepagesand delete it after testing automatically.
Quoted 6 lines
To run it by user root:
#gcc -omprotect_testcasemprotect_testcase.c
#echo "5">/proc/sys/vm/nr_hugepages
#./mprotect_testcaseYou could use gdb to step it to see the changing of the process vma maps.
I've just added a simpler testcase than this one to the libhugetlbfs testsuite. Both R->RW and RW->R transitions appear to work (I haven't tested EXEC transitions yet, that's hairier).
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 17 lines · Yanmin
Quoted 9 lines · David Gibson
Quoted 8 lines · Andrew Morton
Quoted 6 lines · Yanmin
From: Zhang, Yanmin <[email protected]>
2.6.16-rc3 uses hugetlb on-demand paging, but it
doesn_tsupport hugetlb mprotect. My patch against 2.6.16-rc3 enables this capability.Quoted 7 lines
Quoted 4 lines
Well I suppose that makes sense. It does assume that the normal pte protection-changing APIs do the right thing on all architectures which implement huge pages. That's quite possibly the case, but we should confirm that.
Well, it will need to be
huge_ptep_get_and_clear()below, not the normal version.
Quoted 8 lines
I will change it.
Quoted 3 lines
But
pte_modifyshould be ok. I'm not surepte_present()is safe, either, !pte_none() is what we use elsewhere inhugetlb.c.
pte_presentis used in some files while !pte_none is used in other files. Anyway, I will change it to !pte_none.
But most importantly, pte_present() is not used in mm/hugetlb.c, the generic part of the code.
Quoted 9 lines
Quoted 3 lines
And.. looks like
lazy_mmu_prot_update()is unsafe, too. The only arch which has something here (ia64) has a function which does icache flushes onPAGE_SIZEonly.I already sent another patch to ia64 maillist to fix the issue. See http://marc.theaimsgroup.com/?l=linux-ia64&m=114066414720468&w=2
Thanks.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 4 lines · Yanmin
From: Zhang, Yanmin <[email protected]>
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.
Adding another special case for hugetlb pages sounds rather bad. Could you try adding a mrotect vm_area_operation if that works out cleaner?
[2.4.32 - 2.6.15.4] e1000 - Fix mii interface
Hello,
This patch is based on Linux 2.4.32, and I've verified the same problem exists on 2.6.15.4.
Working on a machine with a 2.4.32 kernel, I was surprised to see the driver complaining when setting the speed to 100FD using mii-tool, but accepting the setting with ethtool.
Digging into the code, I found that there is some confusion with :
- DUPLEX_FULL and FULL_DUPLEX,
- DUPLEX_HALF and HALF_DUPLEX
in the code :
...
spddplx += (mii_reg & 0x100)
? FULL_DUPLEX :
HALF_DUPLEX;
retval = e1000_set_spd_dplx(adapter,
spddplx);...
and
inte1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
{
adapter->hw.autoneg = 0;
switch(spddplx) {
case SPEED_10 + DUPLEX_HALF:
adapter->hw.forced_speed_duplex = e1000_10_half;
break;....
when the constants don't have the same value.
This patch is simply changing the code in the e1000_set_spd_dplx to use the same constants as does the caller of the function : FULL_DUPLEX and HALF_DUPLEX
whose values are not 0, to make sure we have had a successfull init (DUPLEX_HALF value is 0, and the DUPLEX_xxx are defined in ethtool.h, thus are probably not meant to be used in the mii interface).
diff -urN linux-2.4.32-orig/drivers/net/e1000/e1000_main.c linux-2.4.32/drivers/net/e1000/e1000_main.c
--- linux-2.4.32-orig/drivers/net/e1000/e1000_main.c Mon Apr 4 01:42:19
2005
+++ linux-2.4.32/drivers/net/e1000/e1000_main.c Sat Feb 25 09:36:23 2006 @@ -2944,23 +2944,23 @@
adapter->hw.autoneg = 0;
switch(spddplx) {
- case SPEED_10 + DUPLEX_HALF:
+ case SPEED_10 + HALF_DUPLEX:
adapter->hw.forced_speed_duplex = e1000_10_half;
break;
- case SPEED_10 + DUPLEX_FULL:
+ case SPEED_10 + FULL_DUPLEX:
adapter->hw.forced_speed_duplex = e1000_10_full;
break;
- case SPEED_100 + DUPLEX_HALF:
+ case SPEED_100 + HALF_DUPLEX:
adapter->hw.forced_speed_duplex = e1000_100_half;
break;
- case SPEED_100 + DUPLEX_FULL:
+ case SPEED_100 + FULL_DUPLEX:
adapter->hw.forced_speed_duplex = e1000_100_full;
break;
- case SPEED_1000 + DUPLEX_FULL:
+ case SPEED_1000 + FULL_DUPLEX:
adapter->hw.autoneg = 1;
adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
break;
- case SPEED_1000 + DUPLEX_HALF: /* not supported */
+ case SPEED_1000 + HALF_DUPLEX: /* not supported */
default:
DPRINTK(PROBE, ERR,
"Unsupported Speed/Duplexity configuration\n");Paul Rolland, rol(at)as2917.net
ex-AS2917 Network administrator and Peering Coordinator
--
Please no HTML, I'm not a browser - Pas d'HTML, je ne suis pas un navigateur "Some people dream of success... while others wake up and work hard at it"
"I worry about my child and the Internet all the time, even though she's too young to have logged on yet. Here's what I worry about. I worry that 10 or 15 years from now, she will come to me and say 'Daddy, where were you when they took freedom of the press away from the Internet?'"
--Mike Godwin, Electronic Frontier Foundation
drivers/net/e1000/e1000_main.c Sat Feb 25 09:36:23 2006 renamed from drivers/net/e1000/e1000_main.c Mon Apr 4 01:42:19 2005 +6 -6
@@ -2944,23 +2944,23 @@ adapter->hw.autoneg = 0; switch(spddplx) { - case SPEED_10 + DUPLEX_HALF: + case SPEED_10 + HALF_DUPLEX: adapter->hw.forced_speed_duplex = e1000_10_half; break; - case SPEED_10 + DUPLEX_FULL: + case SPEED_10 + FULL_DUPLEX: adapter->hw.forced_speed_duplex = e1000_10_full; break; - case SPEED_100 + DUPLEX_HALF: + case SPEED_100 + HALF_DUPLEX: adapter->hw.forced_speed_duplex = e1000_100_half; break; - case SPEED_100 + DUPLEX_FULL: + case SPEED_100 + FULL_DUPLEX: adapter->hw.forced_speed_duplex = e1000_100_full; break; - case SPEED_1000 + DUPLEX_FULL: + case SPEED_1000 + FULL_DUPLEX: adapter->hw.autoneg = 1; adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; break; - case SPEED_1000 + DUPLEX_HALF: /* not supported */ + case SPEED_1000 + HALF_DUPLEX: /* not supported */ default: DPRINTK(PROBE, ERR, "Unsupported Speed/Duplexity configuration\n");
Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
Hello Paul,
Quoted 4 lines · Paul Rolland
Hello,
This patch is based on Linux 2.4.32, and I've verified the same problem exists on 2.6.15.4.
it's mangled, tabs have been turned into whitespaces. I fixed it so please use the appended one.
Quoted 73 lines
Working on a machine with a 2.4.32 kernel, I was surprised to see the driver complaining when setting the speed to 100FD using mii-tool, but accepting the setting with ethtool.
Digging into the code, I found that there is some confusion with :
-DUPLEX_FULLandFULL_DUPLEX,
-DUPLEX_HALFandHALF_DUPLEX
in the code :
...spddplx += (mii_reg & 0x100) ? FULL_DUPLEX : HALF_DUPLEX; retval = e1000_set_spd_dplx(adapter, spddplx);...
and
inte1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx){ adapter->hw.autoneg = 0; switch(spddplx) { case SPEED_10 + DUPLEX_HALF: adapter->hw.forced_speed_duplex = e1000_10_half; break;....
when the constants don't have the same value.This patch is simply changing the code in the
e1000_set_spd_dplxto use the same constants as does the caller of the function :FULL_DUPLEXandHALF_DUPLEX
whose values are not 0, to make sure we have had a successfull init (DUPLEX_HALFvalue is 0, and theDUPLEX_xxxare defined inethtool.h, thus are probably not meant to be used in the mii interface).Signed-off-by Paul Rolland <[email protected]>diff -urN
linux-2.4.32-orig/drivers/net/e1000/e1000_main.clinux-2.4.32/drivers/net/e1000/e1000_main.c
---linux-2.4.32-orig/drivers/net/e1000/e1000_main.cMon Apr 4 01:42:19
2005
+++linux-2.4.32/drivers/net/e1000/e1000_main.cSat Feb 25 09:36:23 2006(quoted diff) +6
-6@@ -2944,23 +2944,23 @@ adapter->hw.autoneg = 0; switch(spddplx) { - case SPEED_10 + DUPLEX_HALF: + case SPEED_10 + HALF_DUPLEX: adapter->hw.forced_speed_duplex = e1000_10_half; break; - case SPEED_10 + DUPLEX_FULL: + case SPEED_10 + FULL_DUPLEX: adapter->hw.forced_speed_duplex = e1000_10_full; break; - case SPEED_100 + DUPLEX_HALF: + case SPEED_100 + HALF_DUPLEX: adapter->hw.forced_speed_duplex = e1000_100_half; break; - case SPEED_100 + DUPLEX_FULL: + case SPEED_100 + FULL_DUPLEX: adapter->hw.forced_speed_duplex = e1000_100_full; break; - case SPEED_1000 + DUPLEX_FULL: + case SPEED_1000 + FULL_DUPLEX: adapter->hw.autoneg = 1; adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; break; - case SPEED_1000 + DUPLEX_HALF: /* not supported */ + case SPEED_1000 + HALF_DUPLEX: /* not supported */ default: DPRINTK(PROBE, ERR, "Unsupported Speed/Duplexity configuration\n");
Quoted 2 lines
Paul Rolland, rol(at)as2917.net
ex-AS2917 Network administrator and Peering Coordinator
Regards,
Willy
drivers/net/e1000/e1000_main.c Sat Feb 25 09:36:23 2006 renamed from drivers/net/e1000/e1000_main.c Mon Apr 4 01:42:19 2005 +6 -6
@@ -2944,23 +2944,23 @@ adapter->hw.autoneg = 0; switch(spddplx) { - case SPEED_10 + DUPLEX_HALF: + case SPEED_10 + HALF_DUPLEX: adapter->hw.forced_speed_duplex = e1000_10_half; break; - case SPEED_10 + DUPLEX_FULL: + case SPEED_10 + FULL_DUPLEX: adapter->hw.forced_speed_duplex = e1000_10_full; break; - case SPEED_100 + DUPLEX_HALF: + case SPEED_100 + HALF_DUPLEX: adapter->hw.forced_speed_duplex = e1000_100_half; break; - case SPEED_100 + DUPLEX_FULL: + case SPEED_100 + FULL_DUPLEX: adapter->hw.forced_speed_duplex = e1000_100_full; break; - case SPEED_1000 + DUPLEX_FULL: + case SPEED_1000 + FULL_DUPLEX: adapter->hw.autoneg = 1; adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; break; - case SPEED_1000 + DUPLEX_HALF: /* not supported */ + case SPEED_1000 + HALF_DUPLEX: /* not supported */ default: DPRINTK(PROBE, ERR, "Unsupported Speed/Duplexity configuration\n");
Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
Quoted 3 lines
it's mangled, tabs have been turned into whitespaces. I fixed it so please
use the appended one.
Sorry about that, thanks for the fix.
Paul
Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
In reply to Paul RollandQuoted 4 lines · Paul Rolland
Hello,
This patch is based on Linux 2.4.32, and I've verified the same problem exists on 2.6.15.4.
are you planning a 2.6 patch as well ?
--
Jesper Juhl <[email protected]>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
Hello,
Quoted 2 lines
are you planning a 2.6 patch as well ?
I'm preparing it, and I'll be carefull with Tab/space ;)
Paul
Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
Quoted 6 lines · Paul Rolland
Hello,
Quoted 2 lines
are you planning a 2.6 patch as well ?
I'm preparing it, and I'll be carefull with Tab/space ;)
Ok, great, I was just wondering since I would have made one if you had no plans to do so.
--
Jesper Juhl <[email protected]>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
Hello,
Quoted 2 lines
Ok, great, I was just wondering since I would have made one if you had no plans to do so.
Well, I was just waiting to make sure it was interesting for someone ;)
Here is it, verified with tab and not spaces... but attached as my mailer is likely to cripple anything I try to inline...
Cheers,
Paul
Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
Quoted 11 lines · Paul Rolland
Hello,
Quoted 2 lines
Ok, great, I was just wondering since I would have made one if you had no plans to do so.
Well, I was just waiting to make sure it was interesting for someone ;)
Here is it, verified with tab and not spaces... but attached as my mailer is likely to cripple anything I try to inline...
Signed-off-by Paul Rolland <[email protected]>
I've got an issue with this, as the same function is called in e1000_ethtool.c. I think the correct fix is to fix the caller in the mii-tool case, but I am working on verifiying my assumptions.
In the meantime can you send the exact command you were having the problem with?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
Quoted 15 lines
From: Paul Rolland <[email protected]>
Hello,
This patch is based on Linux 2.4.32, and I've verified the same problem exists on 2.6.15.4.
Working on a machine with a 2.4.32 kernel, I was surprised to see the driver complaining when setting the speed to 100FD using mii-tool, but accepting the setting with ethtool.
Digging into the code, I found that there is some confusion with :
-DUPLEX_FULLandFULL_DUPLEX,
-DUPLEX_HALFandHALF_DUPLEX
in the code :
...
Quoted 5 lines
spddplx += (mii_reg & 0x100)
? FULL_DUPLEX :
HALF_DUPLEX;
retval = e1000_set_spd_dplx(adapter,
spddplx);Please try this patch:
e1000: fix mii-tool access to setting speed and duplex
Paul Rolland reported that e1000 was having a hard time using mii-tool to set speed and duplex. This patch fixes the issue on both newer hardware as well as fixing the code issue that originally caused the problem.
---
drivers/net/e1000/e1000_main.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/e1000/e1000_main.c +3 -3
@@ -4269,7 +4269,7 @@ e1000_mii_ioctl(struct net_device *netdespin_unlock_irqrestore (&adapter->stats_lock, flags);return -EIO ; } -if (adapter->hw.phy_type == e1000_phy_m88) { +if (adapter->hw.media_type == e1000_media_type_copper) {switch (data->reg_num) {case PHY_CTRL :if (mii_reg &MII_CR_POWER_DOWN )
@@ -4285,8 +4285,8 @@ e1000_mii_ioctl(struct net_device *netdeelse spddplx =SPEED_10 ; spddplx += (mii_reg &0x100 ) - ?FULL_DUPLEX : -HALF_DUPLEX ; + ?DUPLEX_FULL : +DUPLEX_HALF ; retval =e1000_set_spd_dplx (adapter, spddplx);if (retval) {
Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
Hello Jesse,
drivers/net/e1000/e1000_main.c e1000_mii_ioctl(struct net_device *netde · line 4289
Quoted 5 lines
spddplx += (
mii_reg&0x100)drivers/net/e1000/e1000_main.c +2
-2- ? FULL_DUPLEX : -HALF_DUPLEX ; + ? DUPLEX_FULL : +DUPLEX_HALF ;
As I said in my first mail, I didn't want to go that way as one of the two DUPLEX_FULL or DUPLEX_HALF is defined as being 0, which prevents detecting incorrect/incomplete initializations.
The problem I had came from :
mii-tool -F 100BaseTx-FD eth0
when at the same time the ethtool interface was OK.
But you are right, the change I made missed the second caller.
The correct change is yours, though for the reason I put above, I think it'll make it harder to spot other bugs ;)
Well done,
Paul
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Yanmin
From: Zhang, Yanmin <[email protected]>
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.
Adding another special case for hugetlb pages sounds rather bad. Could you try adding a mrotect
vm_area_operationif that works out cleaner?
I don't quite understand your idea. vm_operations_struct has no mprotect function pointer. Could you elaborate it?
In current kernel, sys_mprotect would bypass hugetlb if (is_vm_hugetlb_page(vma)).