Skip to contentSkip to conversation

arch: metag: kernel: dma.c: check 'pud' whether is NULL in dma_alloc_init()

PATCH NAK Chen Gang 5 participants 11 messages Nov 14, 2013 6 messages not in the archive

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 arch: metag: kernel: dma.c: check 'pud' whether is NULL in dma_alloc_init()

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

---
 arch/metag/kernel/dma.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/metag/kernel/dma.c +5 -0
index db589ad..e6cf39b 100644
@@ -398,6 +398,11 @@ static int __init dma_alloc_init(void)
 		int offset = pgd_index(CONSISTENT_START);
 		pgd = pgd_offset(&init_mm, CONSISTENT_START);
 		pud = pud_alloc(&init_mm, pgd, CONSISTENT_START);
+		if (!pud) {
+			pr_err("%s: no pud tables\n", __func__);
+			ret = -ENOMEM;
+			break;
+		}
 		pmd = pmd_alloc(&init_mm, pud, CONSISTENT_START);
 		if (!pmd) {
 			pr_err("%s: no pmd tables\n", __func__);
Signature · 5 lines
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 3 lines · On Thursday 14 November 2013 16:11:21 Chen Gang wrote:

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

NAK.

pud_alloc folds to pud_offset on Meta so it cannot fail.

Cheers
James

Quoted 10 lines
---
 arch/metag/kernel/dma.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/metag/kernel/dma.c +0 -0
index db589ad..e6cf39b 100644
@@ -398,6 +398,11 @@ static int __init dma_alloc_init(void)
 		int offset = pgd_index(CONSISTENT_START);

arch/metag/kernel/dma.c static int __init dma_alloc_init(void) · line 408

Quoted 10 lines
arch/metag/kernel/dma.c +5 -0
 		pgd = pgd_offset(&init_mm, CONSISTENT_START);
 		pud = pud_alloc(&init_mm, pgd, CONSISTENT_START);
+		if (!pud) {
+			pr_err("%s: no pud tables\n", __func__);
+			ret = -ENOMEM;
+			break;
+		}
 		pmd = pmd_alloc(&init_mm, pud, CONSISTENT_START);
 		if (!pmd) {
 			pr_err("%s: no pmd tables\n", __func__);

--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#3 lore raw
Quoted 9 lines · James Hogan
Quoted 3 lines · On Thursday 14 November 2013 16:11:21 Chen Gang wrote:

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

NAK.

pud_alloc folds to pud_offset on Meta so it cannot fail.

If so, can pmd_alloc() be fail?

I checked the related definitions, it seems a little complex, can we assume p?d_alloc() are in the same condition?

Thanks.

Quoted 25 lines

Cheers
James

Quoted 20 lines
---
 arch/metag/kernel/dma.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/metag/kernel/dma.c +5 -0
index db589ad..e6cf39b 100644
@@ -398,6 +398,11 @@ static int __init dma_alloc_init(void)
 		int offset = pgd_index(CONSISTENT_START);
 		pgd = pgd_offset(&init_mm, CONSISTENT_START);
 		pud = pud_alloc(&init_mm, pgd, CONSISTENT_START);
+		if (!pud) {
+			pr_err("%s: no pud tables\n", __func__);
+			ret = -ENOMEM;
+			break;
+		}
 		pmd = pmd_alloc(&init_mm, pud, CONSISTENT_START);
 		if (!pmd) {
 			pr_err("%s: no pmd tables\n", __func__);
Signature · 5 lines
Chen Gang
--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 4 lines · Chen Gang
Quoted 3 lines · James Hogan
Quoted 2 lines · On Thursday 14 November 2013 16:11:21 Chen Gang wrote:

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

NAK.

pud_alloc folds to pud_offset on Meta so it cannot fail.

If so, can pmd_alloc() be fail?

No. pmd_alloc folds to pmd_offset so it also cannot fail, and the existing !pmd check is dead code. The following would be better.

Cheers
James

From 85a386a9c7df666b1f438435be8a89581bc7e8b3 Mon Sep 17 00:00:00 2001
From: James Hogan <[email protected]>
Date: Thu, 14 Nov 2013 10:14:37 +0000
Subject: [PATCH 1/1] metag: dma: remove dead code in dma_alloc_init()

Meta has 2 levels of page table so the pmd folds into the pud which folds into the pgd. Therefore the !pmd check in dma_alloc_init() is dead code since it essentially checks whether:
(init_mm->pgd + 0x770) == 0

Remove the check.

---
 arch/metag/kernel/dma.c | 5 -----
 1 file changed, 5 deletions(-)
arch/metag/kernel/dma.c +0 -5
index 8c00dedadc54..78205dbc2b86 100644
@@ -401,11 +401,6 @@ static int __init dma_alloc_init(void)
 		pgd = pgd_offset(&init_mm, CONSISTENT_START);
 		pud = pud_alloc(&init_mm, pgd, CONSISTENT_START);
 		pmd = pmd_alloc(&init_mm, pud, CONSISTENT_START);
-		if (!pmd) {
-			pr_err("%s: no pmd tables\n", __func__);
-			ret = -ENOMEM;
-			break;
-		}
 		WARN_ON(!pmd_none(*pmd));
 
 		pte = pte_alloc_kernel(pmd, CONSISTENT_START);
Signature · 6 lines
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 20 lines · James Hogan
Quoted 4 lines · Chen Gang
Quoted 3 lines · James Hogan
Quoted 2 lines · On Thursday 14 November 2013 16:11:21 Chen Gang wrote:

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

NAK.

pud_alloc folds to pud_offset on Meta so it cannot fail.

If so, can pmd_alloc() be fail?

No. pmd_alloc folds to pmd_offset so it also cannot fail, and the existing !pmd check is dead code. The following would be better.

Cheers
James

Quoted 6 lines
Quoted 1 line

From 85a386a9c7df666b1f438435be8a89581bc7e8b3 Mon Sep 17 00:00:00 2001

From: James Hogan <[email protected]>
Date: Thu, 14 Nov 2013 10:14:37 +0000
Subject: [PATCH 1/1] metag: dma: remove dead code in dma_alloc_init()

Meta has 2 levels of page table so the pmd folds into the pud which

Hi James,

"Meta has 2 levels of page table", so it use
"#define pud_alloc(mm, pgd, address) (pgd)", right?
and if the arch is x86_64, we should check the pmd and pud, right?

Thanks,
Xishi Qiu

Quoted 18 lines

folds into the pgd. Therefore the !pmd check in dma_alloc_init() is dead code since it essentially checks whether:
(init_mm->pgd + 0x770) == 0

Remove the check.

---
 arch/metag/kernel/dma.c | 5 -----
 1 file changed, 5 deletions(-)
arch/metag/kernel/dma.c +0 -0
index 8c00dedadc54..78205dbc2b86 100644
@@ -401,11 +401,6 @@ static int __init dma_alloc_init(void)
 		pgd = pgd_offset(&init_mm, CONSISTENT_START);

arch/metag/kernel/dma.c static int __init dma_alloc_init(void) · line 406

Quoted 10 lines
arch/metag/kernel/dma.c +0 -5
 		pud = pud_alloc(&init_mm, pgd, CONSISTENT_START);
 		pmd = pmd_alloc(&init_mm, pud, CONSISTENT_START);
-		if (!pmd) {
-			pr_err("%s: no pmd tables\n", __func__);
-			ret = -ENOMEM;
-			break;
-		}
 		WARN_ON(!pmd_none(*pmd));
 
 		pte = pte_alloc_kernel(pmd, CONSISTENT_START);

--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 27 lines · Xishi Qiu
Quoted 25 lines · James Hogan
Quoted 4 lines · Chen Gang
Quoted 3 lines · James Hogan
Quoted 2 lines · On Thursday 14 November 2013 16:11:21 Chen Gang wrote:

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

NAK.

pud_alloc folds to pud_offset on Meta so it cannot fail.

If so, can pmd_alloc() be fail?

No. pmd_alloc folds to pmd_offset so it also cannot fail, and the existing !pmd check is dead code. The following would be better.

Cheers
James

Quoted 1 line

From 85a386a9c7df666b1f438435be8a89581bc7e8b3 Mon Sep 17 00:00:00 2001

From: James Hogan <[email protected]>
Date: Thu, 14 Nov 2013 10:14:37 +0000
Subject: [PATCH 1/1] metag: dma: remove dead code in dma_alloc_init()

Quoted 6 lines
Quoted 1 line

Meta has 2 levels of page table so the pmd folds into the pud which

Hi James,

"Meta has 2 levels of page table", so it use
"#define pud_alloc(mm, pgd, address) (pgd)", right?

Essentially yes. It uses the definitions in include/linux/mm.h:

Quoted 11 lines

static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)

{
	return (unlikely(pgd_none(*pgd)) && __pud_alloc(mm, pgd, address))?
		NULL: pud_offset(pgd, address);
}

static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)

{
	return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
		NULL: pmd_offset(pud, address);
}

arch/metag/include/asm/pgtable.h includes asm-generic/pgtable-nopmd.h which includes asm-generic/pgtable-nopud.h, so:

pgd_none() is always 0
__pud_alloc() is always 0
pud_alloc() = pud_offset() = pgd

pud_none() is always 0
__pmd_alloc() is always 0
pmd_alloc() = pmd_offset() = pud

Quoted 1 line

and if the arch is x86_64, we should check the pmd and pud, right?

I believe x86_64 uses 4 level page tables so yes, but you're probably best off checking the relevant definitions, disassembling some code, or asking the x86 maintainers. I believe there's been an article or two about 4 level page tables on LWN too.

Cheers
James

--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw
In reply to a message not in the archive
Quoted 12 lines · James Hogan
Quoted 11 lines · Chen Gang
Quoted 9 lines · James Hogan
Quoted 3 lines · On Thursday 14 November 2013 16:11:21 Chen Gang wrote:

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

NAK.

pud_alloc folds to pud_offset on Meta so it cannot fail.

Quoted 8 lines
Quoted 1 line

If so, can pmd_alloc() be fail?

No. pmd_alloc folds to pmd_offset so it also cannot fail, and the existing !pmd check is dead code. The following would be better.

Cheers
James

Hi James,

__PAGETABLE_PUD_FOLDED and __PAGETABLE_PMD_FOLDED are defined,
so __pud_alloc() and __pmd_alloc() always return 0,
and pud_offset() just return (pud_t *)pgd, pmd_offset() just return (pmd_t *)pud, is that right?

Thanks,
Xishi Qiu

Quoted 24 lines
Quoted 1 line

From 85a386a9c7df666b1f438435be8a89581bc7e8b3 Mon Sep 17 00:00:00 2001

From: James Hogan <[email protected]>
Date: Thu, 14 Nov 2013 10:14:37 +0000
Subject: [PATCH 1/1] metag: dma: remove dead code in dma_alloc_init()

Meta has 2 levels of page table so the pmd folds into the pud which folds into the pgd. Therefore the !pmd check in dma_alloc_init() is dead code since it essentially checks whether:
(init_mm->pgd + 0x770) == 0

Remove the check.

---
 arch/metag/kernel/dma.c | 5 -----
 1 file changed, 5 deletions(-)
arch/metag/kernel/dma.c +0 -0
index 8c00dedadc54..78205dbc2b86 100644
@@ -401,11 +401,6 @@ static int __init dma_alloc_init(void)
 		pgd = pgd_offset(&init_mm, CONSISTENT_START);

arch/metag/kernel/dma.c static int __init dma_alloc_init(void) · line 406

Quoted 10 lines
arch/metag/kernel/dma.c +0 -5
 		pud = pud_alloc(&init_mm, pgd, CONSISTENT_START);
 		pmd = pmd_alloc(&init_mm, pud, CONSISTENT_START);
-		if (!pmd) {
-			pr_err("%s: no pmd tables\n", __func__);
-			ret = -ENOMEM;
-			break;
-		}
 		WARN_ON(!pmd_none(*pmd));
 
 		pte = pte_alloc_kernel(pmd, CONSISTENT_START);

--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw
Quoted 23 lines · Xishi Qiu
Quoted 12 lines · James Hogan
Quoted 11 lines · Chen Gang
Quoted 9 lines · James Hogan
Quoted 3 lines · On Thursday 14 November 2013 16:11:21 Chen Gang wrote:

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

NAK.

pud_alloc folds to pud_offset on Meta so it cannot fail.

Quoted 8 lines
Quoted 1 line

If so, can pmd_alloc() be fail?

No. pmd_alloc folds to pmd_offset so it also cannot fail, and the existing !pmd check is dead code. The following would be better.

Cheers
James

Quoted 6 lines

Hi James,

__PAGETABLE_PUD_FOLDED and __PAGETABLE_PMD_FOLDED are defined,
so __pud_alloc() and __pmd_alloc() always return 0,
and pud_offset() just return (pud_t *)pgd, pmd_offset() just return (pmd_t *)pud, is that right?

Yes exactly (although technically __pud_alloc() and __pmd_alloc() would never get called due to pgd_none() and pud_none() returning 0, but it makes little difference).

Cheers
James

Quoted 34 lines
Quoted 34 lines
Quoted 2 lines

From 85a386a9c7df666b1f438435be8a89581bc7e8b3 Mon Sep 17 00:00:00 2001

From: James Hogan <[email protected]>
Date: Thu, 14 Nov 2013 10:14:37 +0000
Subject: [PATCH 1/1] metag: dma: remove dead code in dma_alloc_init()

Meta has 2 levels of page table so the pmd folds into the pud which folds into the pgd. Therefore the !pmd check in dma_alloc_init() is dead code since it essentially checks whether:
(init_mm->pgd + 0x770) == 0

Remove the check.

---
 arch/metag/kernel/dma.c | 5 -----
 1 file changed, 5 deletions(-)
arch/metag/kernel/dma.c +0 -5
index 8c00dedadc54..78205dbc2b86 100644
@@ -401,11 +401,6 @@ static int __init dma_alloc_init(void)
 		pgd = pgd_offset(&init_mm, CONSISTENT_START);
 		pud = pud_alloc(&init_mm, pgd, CONSISTENT_START);
 		pmd = pmd_alloc(&init_mm, pud, CONSISTENT_START);
-		if (!pmd) {
-			pr_err("%s: no pmd tables\n", __func__);
-			ret = -ENOMEM;
-			break;
-		}
 		WARN_ON(!pmd_none(*pmd));
 
Quoted 3 lines

arch/metag/kernel/dma.c static int __init dma_alloc_init(void) · line 406

Quoted 1 line
arch/metag/kernel/dma.c +0 -0
 		pte = pte_alloc_kernel(pmd, CONSISTENT_START);

--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#14 lore raw
Quoted 26 lines · James Hogan
Quoted 25 lines · Xishi Qiu
Quoted 12 lines · James Hogan
Quoted 11 lines · Chen Gang
Quoted 9 lines · James Hogan
Quoted 3 lines · On Thursday 14 November 2013 16:11:21 Chen Gang wrote:

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

NAK.

pud_alloc folds to pud_offset on Meta so it cannot fail.

Quoted 8 lines
Quoted 1 line

If so, can pmd_alloc() be fail?

No. pmd_alloc folds to pmd_offset so it also cannot fail, and the existing !pmd check is dead code. The following would be better.

Cheers
James

Hi James,

Quoted 9 lines
Quoted 4 lines

__PAGETABLE_PUD_FOLDED and __PAGETABLE_PMD_FOLDED are defined,
so __pud_alloc() and __pmd_alloc() always return 0,
and pud_offset() just return (pud_t *)pgd, pmd_offset() just return (pmd_t *)pud, is that right?

Yes exactly (although technically __pud_alloc() and __pmd_alloc() would never get called due to pgd_none() and pud_none() returning 0, but it makes little difference).

Thank all of you (originally, I did not notice about "linux/mm.h" include "asm/pgtable.h" -- which maybe be a common sense).

:-)

Quoted 43 lines

Cheers
James

Quoted 37 lines
Quoted 35 lines
Quoted 2 lines

From 85a386a9c7df666b1f438435be8a89581bc7e8b3 Mon Sep 17 00:00:00 2001

From: James Hogan <[email protected]>
Date: Thu, 14 Nov 2013 10:14:37 +0000
Subject: [PATCH 1/1] metag: dma: remove dead code in dma_alloc_init()

Meta has 2 levels of page table so the pmd folds into the pud which folds into the pgd. Therefore the !pmd check in dma_alloc_init() is dead code since it essentially checks whether:
(init_mm->pgd + 0x770) == 0

Remove the check.

---
 arch/metag/kernel/dma.c | 5 -----
 1 file changed, 5 deletions(-)
arch/metag/kernel/dma.c +0 -5
index 8c00dedadc54..78205dbc2b86 100644
@@ -401,11 +401,6 @@ static int __init dma_alloc_init(void)
 		pgd = pgd_offset(&init_mm, CONSISTENT_START);
 		pud = pud_alloc(&init_mm, pgd, CONSISTENT_START);
 		pmd = pmd_alloc(&init_mm, pud, CONSISTENT_START);
-		if (!pmd) {
-			pr_err("%s: no pmd tables\n", __func__);
-			ret = -ENOMEM;
-			break;
-		}
 		WARN_ON(!pmd_none(*pmd));
 
 		pte = pte_alloc_kernel(pmd, CONSISTENT_START);
Signature · 5 lines
Chen Gang
--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#15 lore raw
In reply to Chen Gang
Quoted 12 lines · Chen Gang

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

---
 arch/metag/kernel/dma.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/metag/kernel/dma.c +0 -0
index db589ad..e6cf39b 100644

arch/metag/kernel/dma.c static int __init dma_alloc_init(void) · line 405

Quoted 8 lines
arch/metag/kernel/dma.c +5 -0
@@ -398,6 +398,11 @@ static int __init dma_alloc_init(void)
 		int offset = pgd_index(CONSISTENT_START);
 		pgd = pgd_offset(&init_mm, CONSISTENT_START);
 		pud = pud_alloc(&init_mm, pgd, CONSISTENT_START);
+		if (!pud) {
+			pr_err("%s: no pud tables\n", __func__);
+			ret = -ENOMEM;
+			break;
+		}

It looks fine to me.

Thanks,
Xishi Qiu

arch/metag/kernel/dma.c static int __init dma_alloc_init(void) · line 408

Quoted 3 lines
arch/metag/kernel/dma.c +0 -0
 		pmd = pmd_alloc(&init_mm, pud, CONSISTENT_START);
 		if (!pmd) {
 			pr_err("%s: no pmd tables\n", __func__);

--
To unsubscribe from this list: send the line "unsubscribe linux-metag" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#16 lore raw
Quoted 9 lines · Xishi Qiu
Quoted 7 lines · Chen Gang

Like another p?d_alloc(), pud_alloc() also may fail, so need check it.

---
 arch/metag/kernel/dma.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
Quoted 16 lines

arch/metag/kernel/dma.c static int __init dma_alloc_init(void) · line 405

Quoted 13 lines
arch/metag/kernel/dma.c +5 -0
index db589ad..e6cf39b 100644
@@ -398,6 +398,11 @@ static int __init dma_alloc_init(void)
 		int offset = pgd_index(CONSISTENT_START);
 		pgd = pgd_offset(&init_mm, CONSISTENT_START);
 		pud = pud_alloc(&init_mm, pgd, CONSISTENT_START);
+		if (!pud) {
+			pr_err("%s: no pud tables\n", __func__);
+			ret = -ENOMEM;
+			break;
+		}

It looks fine to me.

Thank you too.

James has his opinion about it, we are just discussing, welcome you join.

:-)

Thanks.

Quoted 10 lines

Thanks,
Xishi Qiu

Quoted 3 lines
arch/metag/kernel/dma.c +0 -0
 		pmd = pmd_alloc(&init_mm, pud, CONSISTENT_START);
 		if (!pmd) {
 			pr_err("%s: no pmd tables\n", __func__);
Signature · 1 line
Chen Gang