linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Enable mprotect on huge pages
@ 2006-02-23  3:19 Zhang, Yanmin
  2006-02-24 22:28 ` Andrew Morton
  2006-02-25  8:54 ` Christoph Hellwig
  0 siblings, 2 replies; 23+ messages in thread
From: Zhang, Yanmin @ 2006-02-23  3:19 UTC (permalink / raw)
  To: linux-kernel; +Cc: kenneth.w.chen, yanmin.zhang

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;



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  2006-02-23  3:19 [PATCH] Enable mprotect on huge pages Zhang, Yanmin
@ 2006-02-24 22:28 ` Andrew Morton
  2006-02-26 23:09   ` David Gibson
  2006-02-25  8:54 ` Christoph Hellwig
  1 sibling, 1 reply; 23+ messages in thread
From: Andrew Morton @ 2006-02-24 22:28 UTC (permalink / raw)
  To: Zhang, Yanmin
  Cc: linux-kernel, kenneth.w.chen, yanmin.zhang, David S. Miller,
	Paul Mackerras, Benjamin Herrenschmidt, David Gibson,
	William Lee Irwin III, Paul Mundt, kkojima, Luck, Tony

"Zhang, Yanmin" <yanmin_zhang@linux.intel.com> wrote:
>
> 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.
> 

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.

> +
> +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);
> +}


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  2006-02-23  3:19 [PATCH] Enable mprotect on huge pages Zhang, Yanmin
  2006-02-24 22:28 ` Andrew Morton
@ 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-27  5:09   ` [PATCH] Enable mprotect on huge pages Zhang, Yanmin
  1 sibling, 2 replies; 23+ messages in thread
From: Christoph Hellwig @ 2006-02-25  8:54 UTC (permalink / raw)
  To: Zhang, Yanmin; +Cc: linux-kernel, kenneth.w.chen, yanmin.zhang

On Thu, Feb 23, 2006 at 11:19:40AM +0800, Zhang, Yanmin wrote:
> 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.

Adding another special case for hugetlb pages sounds rather bad.  Could
you try adding a mrotect vm_area_operation if that works out cleaner?


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
  2006-02-25  8:54 ` Christoph Hellwig
@ 2006-02-25 10:08   ` Paul Rolland
  2006-02-26 10:42     ` Willy TARREAU
                       ` (2 more replies)
  2006-02-27  5:09   ` [PATCH] Enable mprotect on huge pages Zhang, Yanmin
  1 sibling, 3 replies; 23+ messages in thread
From: Paul Rolland @ 2006-02-25 10:08 UTC (permalink / raw)
  To: linux-kernel; +Cc: netdev, linux.nics, cramerj, john.ronciak, Ganesh.Venkatesan

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

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
int
e1000_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).

Signed-off-by: Paul Rolland <rol@as2917.net>

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 
 

[-- Attachment #2: e1000.patch --]
[-- Type: application/octet-stream, Size: 1487 bytes --]

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");


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
  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
       [not found]     ` <4807377b0602271234v4b6cdeecpbcf8d4a6ac51cd20@mail.gmail.com>
  2 siblings, 1 reply; 23+ messages in thread
From: Willy TARREAU @ 2006-02-26 10:42 UTC (permalink / raw)
  To: Paul Rolland
  Cc: linux-kernel, netdev, linux.nics, cramerj, john.ronciak,
	Ganesh.Venkatesan

Hello Paul,

On Sat, Feb 25, 2006 at 11:08:49AM +0100, Paul Rolland wrote:
> 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.

> 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
> int
> e1000_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).
> 
> Signed-off-by: Paul Rolland <rol@as2917.net>
> 
> 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

Regards,
Willy


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");




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
  2006-02-26 10:42     ` Willy TARREAU
@ 2006-02-26 11:39       ` Paul Rolland
  0 siblings, 0 replies; 23+ messages in thread
From: Paul Rolland @ 2006-02-26 11:39 UTC (permalink / raw)
  To: 'Willy TARREAU'
  Cc: linux-kernel, netdev, linux.nics, cramerj, john.ronciak,
	Ganesh.Venkatesan

> 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


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
  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 12:59     ` Jesper Juhl
  2006-02-26 14:55       ` Paul Rolland
       [not found]     ` <4807377b0602271234v4b6cdeecpbcf8d4a6ac51cd20@mail.gmail.com>
  2 siblings, 1 reply; 23+ messages in thread
From: Jesper Juhl @ 2006-02-26 12:59 UTC (permalink / raw)
  To: rol
  Cc: linux-kernel, netdev, linux.nics, cramerj, john.ronciak,
	Ganesh.Venkatesan

On 2/25/06, Paul Rolland <rol@as2917.net> wrote:
> 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 <jesper.juhl@gmail.com>
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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
  2006-02-26 12:59     ` Jesper Juhl
@ 2006-02-26 14:55       ` Paul Rolland
  2006-02-26 15:00         ` Jesper Juhl
  0 siblings, 1 reply; 23+ messages in thread
From: Paul Rolland @ 2006-02-26 14:55 UTC (permalink / raw)
  To: 'Jesper Juhl'
  Cc: linux-kernel, netdev, linux.nics, cramerj, john.ronciak,
	Ganesh.Venkatesan

Hello,

> are you planning a 2.6 patch as well ?
> 
I'm preparing it, and I'll be carefull with Tab/space ;)

Paul


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
  2006-02-26 14:55       ` Paul Rolland
@ 2006-02-26 15:00         ` Jesper Juhl
  2006-02-26 15:12           ` Paul Rolland
  0 siblings, 1 reply; 23+ messages in thread
From: Jesper Juhl @ 2006-02-26 15:00 UTC (permalink / raw)
  To: Paul Rolland
  Cc: linux-kernel, netdev, linux.nics, cramerj, john.ronciak,
	Ganesh.Venkatesan

On 2/26/06, Paul Rolland <rol@witbe.net> wrote:
> Hello,
>
> > 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 <jesper.juhl@gmail.com>
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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
  2006-02-26 15:00         ` Jesper Juhl
@ 2006-02-26 15:12           ` Paul Rolland
  2006-02-27 19:26             ` Jesse Brandeburg
  0 siblings, 1 reply; 23+ messages in thread
From: Paul Rolland @ 2006-02-26 15:12 UTC (permalink / raw)
  To: 'Jesper Juhl'
  Cc: linux-kernel, netdev, linux.nics, cramerj, john.ronciak,
	Ganesh.Venkatesan

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

Hello,

> 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 <rol@as2917.net>

Cheers,
Paul

[-- Attachment #2: e1000.patch-2.6.15.4 --]
[-- Type: application/octet-stream, Size: 1507 bytes --]

diff -urN linux-2.6.15.4.orig/drivers/net/e1000/e1000_main.c linux-2.6.15.4/drivers/net/e1000/e1000_main.c
--- linux-2.6.15.4.orig/drivers/net/e1000/e1000_main.c	Fri Feb 10 07:22:48 2006
+++ linux-2.6.15.4/drivers/net/e1000/e1000_main.c	Sun Feb 26 15:04:40 2006
@@ -4153,29 +4153,29 @@
 
 	/* Fiber NICs only allow 1000 gbps Full duplex */
 	if((adapter->hw.media_type == e1000_media_type_fiber) &&
-		spddplx != (SPEED_1000 + DUPLEX_FULL)) {
+		spddplx != (SPEED_1000 + FULL_DUPLEX)) {
 		DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
 		return -EINVAL;
 	}
 
 	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/Duplex configuration\n");
 		return -EINVAL;

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  2006-02-24 22:28 ` Andrew Morton
@ 2006-02-26 23:09   ` David Gibson
  2006-02-27  5:36     ` Zhang, Yanmin
  0 siblings, 1 reply; 23+ messages in thread
From: David Gibson @ 2006-02-26 23:09 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Zhang, Yanmin, linux-kernel, kenneth.w.chen, yanmin.zhang,
	David S. Miller, Paul Mackerras, Benjamin Herrenschmidt,
	William Lee Irwin III, Paul Mundt, kkojima, Luck, Tony

On Fri, Feb 24, 2006 at 02:28:44PM -0800, Andrew Morton wrote:
> "Zhang, Yanmin" <yanmin_zhang@linux.intel.com> wrote:
> >
> > 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.
> > 
> 
> 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.

> > +
> > +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);
> > +}
> 

-- 
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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  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-27  5:09   ` Zhang, Yanmin
  1 sibling, 0 replies; 23+ messages in thread
From: Zhang, Yanmin @ 2006-02-27  5:09 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel, kenneth.w.chen, yanmin.zhang

On Sat, 2006-02-25 at 16:54, Christoph Hellwig wrote:
> On Thu, Feb 23, 2006 at 11:19:40AM +0800, Zhang, Yanmin wrote:
> > 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.
> 
> Adding another special case for hugetlb pages sounds rather bad.  Could
> you try adding a mrotect vm_area_operation if 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)).



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  2006-02-26 23:09   ` David Gibson
@ 2006-02-27  5:36     ` Zhang, Yanmin
  2006-02-27  6:33       ` Zhang, Yanmin
  2006-02-27  7:26       ` David Gibson
  0 siblings, 2 replies; 23+ messages in thread
From: Zhang, Yanmin @ 2006-02-27  5:36 UTC (permalink / raw)
  To: David Gibson
  Cc: Andrew Morton, linux-kernel, kenneth.w.chen, yanmin.zhang,
	David S. Miller, Paul Mackerras, Benjamin Herrenschmidt,
	William Lee Irwin III, Paul Mundt, kkojima, Luck, Tony

On Mon, 2006-02-27 at 07:09, David Gibson wrote:
> On Fri, Feb 24, 2006 at 02:28:44PM -0800, Andrew Morton wrote:
> > "Zhang, Yanmin" <yanmin_zhang@linux.intel.com> wrote:
> > >
> > > 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.
> > > 
> > 
> > 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.


>   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.
pte_present is used in some files while !pte_none is used 
in other files. Anyway, I will change it to !pte_none.


> 
> 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.
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.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  2006-02-27  5:36     ` Zhang, Yanmin
@ 2006-02-27  6:33       ` Zhang, Yanmin
  2006-02-28  1:34         ` Andrew Morton
  2006-02-27  7:26       ` David Gibson
  1 sibling, 1 reply; 23+ messages in thread
From: Zhang, Yanmin @ 2006-02-27  6:33 UTC (permalink / raw)
  To: David Gibson, Andrew Morton
  Cc: linux-kernel, kenneth.w.chen, yanmin.zhang, David S. Miller,
	Paul Mackerras, Benjamin Herrenschmidt, William Lee Irwin III,
	Paul Mundt, kkojima, Luck, Tony

On Mon, 2006-02-27 at 13:36, Zhang, Yanmin wrote:
> On Mon, 2006-02-27 at 07:09, David Gibson wrote:
> > On Fri, Feb 24, 2006 at 02:28:44PM -0800, Andrew Morton wrote:
> > > "Zhang, Yanmin" <yanmin_zhang@linux.intel.com> wrote:
> > > >
> > > > 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.

Based on David's comments, I worked out a new patch against 2.6.16-rc4.
Thank David.

Signed-off-by: Zhang Yanmin <yanmin.zhang@intel.com>

I tested it on i386/x86_64/ia64. Who could help test it on other
platforms, such like PPC64?

---

diff -Nraup linux-2.6.16-rc4/include/linux/hugetlb.h linux-2.6.16-rc4_mprotect/include/linux/hugetlb.h
--- linux-2.6.16-rc4/include/linux/hugetlb.h	2006-02-22 19:19:04.000000000 +0800
+++ linux-2.6.16-rc4_mprotect/include/linux/hugetlb.h	2006-02-27 20:58:33.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-rc4/mm/hugetlb.c linux-2.6.16-rc4_mprotect/mm/hugetlb.c
--- linux-2.6.16-rc4/mm/hugetlb.c	2006-02-22 19:19:05.000000000 +0800
+++ linux-2.6.16-rc4_mprotect/mm/hugetlb.c	2006-02-27 20:57:17.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_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);
+}
+
diff -Nraup linux-2.6.16-rc4/mm/mprotect.c linux-2.6.16-rc4_mprotect/mm/mprotect.c
--- linux-2.6.16-rc4/mm/mprotect.c	2006-02-22 19:18:21.000000000 +0800
+++ linux-2.6.16-rc4_mprotect/mm/mprotect.c	2006-02-27 20:55:10.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;



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  2006-02-27  5:36     ` Zhang, Yanmin
  2006-02-27  6:33       ` Zhang, Yanmin
@ 2006-02-27  7:26       ` David Gibson
  1 sibling, 0 replies; 23+ messages in thread
From: David Gibson @ 2006-02-27  7:26 UTC (permalink / raw)
  To: Zhang, Yanmin
  Cc: Andrew Morton, linux-kernel, kenneth.w.chen, yanmin.zhang,
	David S. Miller, Paul Mackerras, Benjamin Herrenschmidt,
	William Lee Irwin III, Paul Mundt, kkojima, Luck, Tony

On Mon, Feb 27, 2006 at 01:36:32PM +0800, Zhang, Yanmin wrote:
> On Mon, 2006-02-27 at 07:09, David Gibson wrote:
> > On Fri, Feb 24, 2006 at 02:28:44PM -0800, Andrew Morton wrote:
> > > "Zhang, Yanmin" <yanmin_zhang@linux.intel.com> wrote:
> > > >
> > > > 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.
> > > > 
> > > 
> > > 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.
> 
> 
> >   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.
> pte_present is 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.

> > 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.
> 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.
> 
> 

-- 
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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
  2006-02-26 15:12           ` Paul Rolland
@ 2006-02-27 19:26             ` Jesse Brandeburg
  0 siblings, 0 replies; 23+ messages in thread
From: Jesse Brandeburg @ 2006-02-27 19:26 UTC (permalink / raw)
  To: Paul Rolland, Jeff Garzik
  Cc: Jesper Juhl, linux-kernel, netdev, cramerj, john.ronciak

On 2/26/06, Paul Rolland <rol@witbe.net> wrote:
> Hello,
>
> > 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 <rol@as2917.net>

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?

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  2006-02-27  6:33       ` Zhang, Yanmin
@ 2006-02-28  1:34         ` Andrew Morton
  2006-02-28  3:23           ` Zhang, Yanmin
  0 siblings, 1 reply; 23+ messages in thread
From: Andrew Morton @ 2006-02-28  1:34 UTC (permalink / raw)
  To: Zhang, Yanmin
  Cc: david, linux-kernel, kenneth.w.chen, yanmin.zhang, davem, paulus,
	benh, wli, lethal, kkojima, tony.luck

"Zhang, Yanmin" <yanmin_zhang@linux.intel.com> wrote:
>
> > > > > 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.
> 
>  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.

> 
>  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?

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
       [not found]     ` <4807377b0602271234v4b6cdeecpbcf8d4a6ac51cd20@mail.gmail.com>
@ 2006-02-28  2:31       ` Jesse Brandeburg
  2006-02-28 10:46         ` Paul Rolland
  0 siblings, 1 reply; 23+ messages in thread
From: Jesse Brandeburg @ 2006-02-28  2:31 UTC (permalink / raw)
  To: rol, linux-kernel; +Cc: Brandeburg, Jesse, netdev, john.ronciak


> From: Paul Rolland <rol@as2917.net>
> 
> 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);

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.

Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
CC: Paul Rolland <rol@as2917.net>

---

  drivers/net/e1000/e1000_main.c |    6 +++---
  1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 31e3329..9730c2e 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -4269,7 +4269,7 @@ e1000_mii_ioctl(struct net_device *netde
  			spin_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 *netde
  					else
  						spddplx = SPEED_10;
  					spddplx += (mii_reg & 0x100)
-						   ? FULL_DUPLEX :
-						   HALF_DUPLEX;
+						   ? DUPLEX_FULL :
+						   DUPLEX_HALF;
  					retval = e1000_set_spd_dplx(adapter,
  								    spddplx);
  					if (retval) {

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  2006-02-28  1:34         ` Andrew Morton
@ 2006-02-28  3:23           ` Zhang, Yanmin
  2006-02-28  3:32             ` David Gibson
  2006-02-28  8:24             ` David Gibson
  0 siblings, 2 replies; 23+ messages in thread
From: Zhang, Yanmin @ 2006-02-28  3:23 UTC (permalink / raw)
  To: Andrew Morton
  Cc: david, linux-kernel, kenneth.w.chen, yanmin.zhang, davem, paulus,
	benh, wli, lethal, kkojima, tony.luck

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

On Tue, 2006-02-28 at 09:34, Andrew Morton wrote:
> "Zhang, Yanmin" <yanmin_zhang@linux.intel.com> wrote:
> >
> > > > > > 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.
> > 
> >  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.

> 
> > 
> >  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.



[-- Attachment #2: mprotect_testcase.c --]
[-- Type: text/x-c, Size: 3514 bytes --]

#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;
}



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  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
  1 sibling, 1 reply; 23+ messages in thread
From: David Gibson @ 2006-02-28  3:32 UTC (permalink / raw)
  To: Zhang, Yanmin
  Cc: Andrew Morton, linux-kernel, kenneth.w.chen, yanmin.zhang, davem,
	paulus, benh, wli, lethal, kkojima, tony.luck

On Tue, Feb 28, 2006 at 11:23:54AM +0800, Zhang, Yanmin wrote:
> On Tue, 2006-02-28 at 09:34, Andrew Morton wrote:
> > "Zhang, Yanmin" <yanmin_zhang@linux.intel.com> wrote:
> > >
> > > > > > > 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.
> > > 
> > >  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.
> 
> > 
> > > 
> > >  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

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..

-- 
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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  2006-02-28  3:32             ` David Gibson
@ 2006-02-28  3:37               ` Zhang, Yanmin
  0 siblings, 0 replies; 23+ messages in thread
From: Zhang, Yanmin @ 2006-02-28  3:37 UTC (permalink / raw)
  To: David Gibson
  Cc: Andrew Morton, linux-kernel, kenneth.w.chen, yanmin.zhang, davem,
	paulus, benh, wli, lethal, kkojima, tony.luck

On Tue, 2006-02-28 at 11:32, David Gibson wrote:
> On Tue, Feb 28, 2006 at 11:23:54AM +0800, Zhang, Yanmin wrote:
> > On Tue, 2006-02-28 at 09:34, Andrew Morton wrote:
> > > "Zhang, Yanmin" <yanmin_zhang@linux.intel.com> wrote:
> > > >
> > > > > > > > 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.
> > > > 

> 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.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] Enable mprotect on huge pages
  2006-02-28  3:23           ` Zhang, Yanmin
  2006-02-28  3:32             ` David Gibson
@ 2006-02-28  8:24             ` David Gibson
  1 sibling, 0 replies; 23+ messages in thread
From: David Gibson @ 2006-02-28  8:24 UTC (permalink / raw)
  To: Zhang, Yanmin
  Cc: Andrew Morton, linux-kernel, kenneth.w.chen, yanmin.zhang, davem,
	paulus, benh, wli, lethal, kkojima, tony.luck

On Tue, Feb 28, 2006 at 11:23:54AM +0800, Zhang, Yanmin wrote:
> On Tue, 2006-02-28 at 09:34, Andrew Morton wrote:
> > "Zhang, Yanmin" <yanmin_zhang@linux.intel.com> wrote:
> > >
> > > > > > > 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.
> > > 
> > >  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.
> 
> > 
> > > 
> > >  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.

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).

-- 
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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [2.4.32 - 2.6.15.4] e1000 - Fix mii interface
  2006-02-28  2:31       ` Jesse Brandeburg
@ 2006-02-28 10:46         ` Paul Rolland
  0 siblings, 0 replies; 23+ messages in thread
From: Paul Rolland @ 2006-02-28 10:46 UTC (permalink / raw)
  To: 'Jesse Brandeburg', linux-kernel; +Cc: netdev, john.ronciak

Hello Jesse,

>   					spddplx += (mii_reg & 0x100)
> -						   ? 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


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2006-02-28 10:46 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-23  3:19 [PATCH] Enable mprotect on huge pages Zhang, Yanmin
2006-02-24 22:28 ` 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

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).