All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
@ 2017-04-12  5:01 ` Hoeun Ryu
  0 siblings, 0 replies; 14+ messages in thread
From: Hoeun Ryu @ 2017-04-12  5:01 UTC (permalink / raw)
  To: Andrew Morton, Andrey Ryabinin, Andreas Dilger, Vlastimil Babka,
	Michal Hocko, Chris Wilson, Ingo Molnar, zijun_hu,
	Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov
  Cc: linux-arch, Hoeun Ryu, linux-mm, linux-kernel

vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
during boot process and those virtually mapped areas are never unmapped.
So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
existing vmlist entries and prevent those areas from being removed from the
rbtree by accident.

Signed-off-by: Hoeun Ryu <hoeun.ryu@gmail.com>
---
 include/linux/vmalloc.h | 1 +
 mm/vmalloc.c            | 9 ++++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 46991ad..3df53fc 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -19,6 +19,7 @@ struct notifier_block;		/* in notifier.h */
 #define VM_UNINITIALIZED	0x00000020	/* vm_struct is not fully initialized */
 #define VM_NO_GUARD		0x00000040      /* don't add guard page */
 #define VM_KASAN		0x00000080      /* has allocated kasan shadow memory */
+#define VM_STATIC		0x00000200
 /* bits [20..32] reserved for arch specific ioremap internals */
 
 /*
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 8ef8ea1..fb5049a 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1262,7 +1262,7 @@ void __init vmalloc_init(void)
 	/* Import existing vmlist entries. */
 	for (tmp = vmlist; tmp; tmp = tmp->next) {
 		va = kzalloc(sizeof(struct vmap_area), GFP_NOWAIT);
-		va->flags = VM_VM_AREA;
+		va->flags = VM_VM_AREA | VM_STATIC;
 		va->va_start = (unsigned long)tmp->addr;
 		va->va_end = va->va_start + tmp->size;
 		va->vm = tmp;
@@ -1480,7 +1480,7 @@ struct vm_struct *remove_vm_area(const void *addr)
 	might_sleep();
 
 	va = find_vmap_area((unsigned long)addr);
-	if (va && va->flags & VM_VM_AREA) {
+	if (va && va->flags & VM_VM_AREA && likely(!(va->flags & VM_STATIC))) {
 		struct vm_struct *vm = va->vm;
 
 		spin_lock(&vmap_area_lock);
@@ -1510,7 +1510,7 @@ static void __vunmap(const void *addr, int deallocate_pages)
 
 	area = remove_vm_area(addr);
 	if (unlikely(!area)) {
-		WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n",
+		WARN(1, KERN_ERR "Trying to vfree() nonexistent or static vm area (%p)\n",
 				addr);
 		return;
 	}
@@ -2708,6 +2708,9 @@ static int s_show(struct seq_file *m, void *p)
 	if (v->phys_addr)
 		seq_printf(m, " phys=%pa", &v->phys_addr);
 
+	if (v->flags & VM_STATIC)
+		seq_puts(m, " static");
+
 	if (v->flags & VM_IOREMAP)
 		seq_puts(m, " ioremap");
 
-- 
2.7.4

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

* [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
@ 2017-04-12  5:01 ` Hoeun Ryu
  0 siblings, 0 replies; 14+ messages in thread
From: Hoeun Ryu @ 2017-04-12  5:01 UTC (permalink / raw)
  To: Andrew Morton, Andrey Ryabinin, Andreas Dilger, Vlastimil Babka,
	Michal Hocko, Chris Wilson, Ingo Molnar, zijun_hu,
	Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov
  Cc: linux-arch, Hoeun Ryu, linux-mm, linux-kernel

vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
during boot process and those virtually mapped areas are never unmapped.
So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
existing vmlist entries and prevent those areas from being removed from the
rbtree by accident.

Signed-off-by: Hoeun Ryu <hoeun.ryu@gmail.com>
---
 include/linux/vmalloc.h | 1 +
 mm/vmalloc.c            | 9 ++++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 46991ad..3df53fc 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -19,6 +19,7 @@ struct notifier_block;		/* in notifier.h */
 #define VM_UNINITIALIZED	0x00000020	/* vm_struct is not fully initialized */
 #define VM_NO_GUARD		0x00000040      /* don't add guard page */
 #define VM_KASAN		0x00000080      /* has allocated kasan shadow memory */
+#define VM_STATIC		0x00000200
 /* bits [20..32] reserved for arch specific ioremap internals */
 
 /*
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 8ef8ea1..fb5049a 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1262,7 +1262,7 @@ void __init vmalloc_init(void)
 	/* Import existing vmlist entries. */
 	for (tmp = vmlist; tmp; tmp = tmp->next) {
 		va = kzalloc(sizeof(struct vmap_area), GFP_NOWAIT);
-		va->flags = VM_VM_AREA;
+		va->flags = VM_VM_AREA | VM_STATIC;
 		va->va_start = (unsigned long)tmp->addr;
 		va->va_end = va->va_start + tmp->size;
 		va->vm = tmp;
@@ -1480,7 +1480,7 @@ struct vm_struct *remove_vm_area(const void *addr)
 	might_sleep();
 
 	va = find_vmap_area((unsigned long)addr);
-	if (va && va->flags & VM_VM_AREA) {
+	if (va && va->flags & VM_VM_AREA && likely(!(va->flags & VM_STATIC))) {
 		struct vm_struct *vm = va->vm;
 
 		spin_lock(&vmap_area_lock);
@@ -1510,7 +1510,7 @@ static void __vunmap(const void *addr, int deallocate_pages)
 
 	area = remove_vm_area(addr);
 	if (unlikely(!area)) {
-		WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n",
+		WARN(1, KERN_ERR "Trying to vfree() nonexistent or static vm area (%p)\n",
 				addr);
 		return;
 	}
@@ -2708,6 +2708,9 @@ static int s_show(struct seq_file *m, void *p)
 	if (v->phys_addr)
 		seq_printf(m, " phys=%pa", &v->phys_addr);
 
+	if (v->flags & VM_STATIC)
+		seq_puts(m, " static");
+
 	if (v->flags & VM_IOREMAP)
 		seq_puts(m, " ioremap");
 
-- 
2.7.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
  2017-04-12  5:01 ` Hoeun Ryu
@ 2017-04-12  6:02   ` Christoph Hellwig
  -1 siblings, 0 replies; 14+ messages in thread
From: Christoph Hellwig @ 2017-04-12  6:02 UTC (permalink / raw)
  To: Hoeun Ryu
  Cc: Andrew Morton, Andrey Ryabinin, Andreas Dilger, Vlastimil Babka,
	Michal Hocko, Chris Wilson, Ingo Molnar, zijun_hu,
	Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov, linux-arch,
	linux-mm, linux-kernel

On Wed, Apr 12, 2017 at 02:01:59PM +0900, Hoeun Ryu wrote:
> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
> during boot process and those virtually mapped areas are never unmapped.
> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
> existing vmlist entries and prevent those areas from being removed from the
> rbtree by accident.

How would they be removed "by accident"?

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
@ 2017-04-12  6:02   ` Christoph Hellwig
  0 siblings, 0 replies; 14+ messages in thread
From: Christoph Hellwig @ 2017-04-12  6:02 UTC (permalink / raw)
  To: Hoeun Ryu
  Cc: Andrew Morton, Andrey Ryabinin, Andreas Dilger, Vlastimil Babka,
	Michal Hocko, Chris Wilson, Ingo Molnar, zijun_hu,
	Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov, linux-arch,
	linux-mm, linux-kernel

On Wed, Apr 12, 2017 at 02:01:59PM +0900, Hoeun Ryu wrote:
> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
> during boot process and those virtually mapped areas are never unmapped.
> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
> existing vmlist entries and prevent those areas from being removed from the
> rbtree by accident.

How would they be removed "by accident"?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
  2017-04-12  6:02   ` Christoph Hellwig
@ 2017-04-12 11:42     ` Hoeun Ryu
  -1 siblings, 0 replies; 14+ messages in thread
From: Hoeun Ryu @ 2017-04-12 11:42 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Andrew Morton, Andrey Ryabinin, Andreas Dilger, Vlastimil Babka,
	Michal Hocko, Chris Wilson, Ingo Molnar, zijun_hu,
	Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov, linux-arch,
	linux-mm, linux-kernel


> On Apr 12, 2017, at 3:02 PM, Christoph Hellwig <hch@infradead.org> wrote:
> 
>> On Wed, Apr 12, 2017 at 02:01:59PM +0900, Hoeun Ryu wrote:
>> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
>> during boot process and those virtually mapped areas are never unmapped.
>> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
>> existing vmlist entries and prevent those areas from being removed from the
>> rbtree by accident.
> 
> How would they be removed "by accident"?

I don't mean actual use-cases, but I just want to make it robust against like programming errors.

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
@ 2017-04-12 11:42     ` Hoeun Ryu
  0 siblings, 0 replies; 14+ messages in thread
From: Hoeun Ryu @ 2017-04-12 11:42 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Andrew Morton, Andrey Ryabinin, Andreas Dilger, Vlastimil Babka,
	Michal Hocko, Chris Wilson, Ingo Molnar, zijun_hu,
	Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov, linux-arch,
	linux-mm, linux-kernel


> On Apr 12, 2017, at 3:02 PM, Christoph Hellwig <hch@infradead.org> wrote:
> 
>> On Wed, Apr 12, 2017 at 02:01:59PM +0900, Hoeun Ryu wrote:
>> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
>> during boot process and those virtually mapped areas are never unmapped.
>> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
>> existing vmlist entries and prevent those areas from being removed from the
>> rbtree by accident.
> 
> How would they be removed "by accident"?

I don't mean actual use-cases, but I just want to make it robust against like programming errors.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
  2017-04-12 11:42     ` Hoeun Ryu
@ 2017-04-12 17:31       ` Christoph Hellwig
  -1 siblings, 0 replies; 14+ messages in thread
From: Christoph Hellwig @ 2017-04-12 17:31 UTC (permalink / raw)
  To: Hoeun Ryu
  Cc: Christoph Hellwig, Andrew Morton, Andrey Ryabinin,
	Andreas Dilger, Vlastimil Babka, Michal Hocko, Chris Wilson,
	Ingo Molnar, zijun_hu, Matthew Wilcox, Thomas Garnier,
	Kirill A. Shutemov, linux-arch, linux-mm, linux-kernel

On Wed, Apr 12, 2017 at 08:42:08PM +0900, Hoeun Ryu wrote:
> 
> > On Apr 12, 2017, at 3:02 PM, Christoph Hellwig <hch@infradead.org> wrote:
> > 
> >> On Wed, Apr 12, 2017 at 02:01:59PM +0900, Hoeun Ryu wrote:
> >> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
> >> during boot process and those virtually mapped areas are never unmapped.
> >> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
> >> existing vmlist entries and prevent those areas from being removed from the
> >> rbtree by accident.
> > 
> > How would they be removed "by accident"?
> 
> I don't mean actual use-cases, but I just want to make it robust against like programming errors.

Oh, ok.  The patch makes sense then, although the changelog could use
a little update.

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
@ 2017-04-12 17:31       ` Christoph Hellwig
  0 siblings, 0 replies; 14+ messages in thread
From: Christoph Hellwig @ 2017-04-12 17:31 UTC (permalink / raw)
  To: Hoeun Ryu
  Cc: Christoph Hellwig, Andrew Morton, Andrey Ryabinin,
	Andreas Dilger, Vlastimil Babka, Michal Hocko, Chris Wilson,
	Ingo Molnar, zijun_hu, Matthew Wilcox, Thomas Garnier,
	Kirill A. Shutemov, linux-arch, linux-mm, linux-kernel

On Wed, Apr 12, 2017 at 08:42:08PM +0900, Hoeun Ryu wrote:
> 
> > On Apr 12, 2017, at 3:02 PM, Christoph Hellwig <hch@infradead.org> wrote:
> > 
> >> On Wed, Apr 12, 2017 at 02:01:59PM +0900, Hoeun Ryu wrote:
> >> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
> >> during boot process and those virtually mapped areas are never unmapped.
> >> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
> >> existing vmlist entries and prevent those areas from being removed from the
> >> rbtree by accident.
> > 
> > How would they be removed "by accident"?
> 
> I don't mean actual use-cases, but I just want to make it robust against like programming errors.

Oh, ok.  The patch makes sense then, although the changelog could use
a little update.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
  2017-04-12 17:31       ` Christoph Hellwig
@ 2017-04-13  1:03         ` Ho-Eun Ryu
  -1 siblings, 0 replies; 14+ messages in thread
From: Ho-Eun Ryu @ 2017-04-13  1:03 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Andrew Morton, Andrey Ryabinin, Andreas Dilger, Vlastimil Babka,
	Michal Hocko, Chris Wilson, Ingo Molnar, zijun_hu,
	Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov, linux-arch,
	linux-mm, LKML


> On 13 Apr 2017, at 2:31 AM, Christoph Hellwig <hch@infradead.org> wrote:
> 
> On Wed, Apr 12, 2017 at 08:42:08PM +0900, Hoeun Ryu wrote:
>> 
>>> On Apr 12, 2017, at 3:02 PM, Christoph Hellwig <hch@infradead.org> wrote:
>>> 
>>>> On Wed, Apr 12, 2017 at 02:01:59PM +0900, Hoeun Ryu wrote:
>>>> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
>>>> during boot process and those virtually mapped areas are never unmapped.
>>>> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
>>>> existing vmlist entries and prevent those areas from being removed from the
>>>> rbtree by accident.
>>> 
>>> How would they be removed "by accident"?
>> 
>> I don't mean actual use-cases, but I just want to make it robust against like programming errors.
> 
> Oh, ok.  The patch makes sense then, although the changelog could use
> a little update.

OK, I will.
Any other suggestions for code itself ?

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
@ 2017-04-13  1:03         ` Ho-Eun Ryu
  0 siblings, 0 replies; 14+ messages in thread
From: Ho-Eun Ryu @ 2017-04-13  1:03 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Andrew Morton, Andrey Ryabinin, Andreas Dilger, Vlastimil Babka,
	Michal Hocko, Chris Wilson, Ingo Molnar, zijun_hu,
	Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov, linux-arch,
	linux-mm, LKML


> On 13 Apr 2017, at 2:31 AM, Christoph Hellwig <hch@infradead.org> wrote:
> 
> On Wed, Apr 12, 2017 at 08:42:08PM +0900, Hoeun Ryu wrote:
>> 
>>> On Apr 12, 2017, at 3:02 PM, Christoph Hellwig <hch@infradead.org> wrote:
>>> 
>>>> On Wed, Apr 12, 2017 at 02:01:59PM +0900, Hoeun Ryu wrote:
>>>> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
>>>> during boot process and those virtually mapped areas are never unmapped.
>>>> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
>>>> existing vmlist entries and prevent those areas from being removed from the
>>>> rbtree by accident.
>>> 
>>> How would they be removed "by accident"?
>> 
>> I don't mean actual use-cases, but I just want to make it robust against like programming errors.
> 
> Oh, ok.  The patch makes sense then, although the changelog could use
> a little update.

OK, I will.
Any other suggestions for code itself ?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
  2017-04-12  5:01 ` Hoeun Ryu
@ 2017-04-13  4:17   ` Anshuman Khandual
  -1 siblings, 0 replies; 14+ messages in thread
From: Anshuman Khandual @ 2017-04-13  4:17 UTC (permalink / raw)
  To: Hoeun Ryu, Andrew Morton, Andrey Ryabinin, Andreas Dilger,
	Vlastimil Babka, Michal Hocko, Chris Wilson, Ingo Molnar,
	zijun_hu, Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov
  Cc: linux-arch, linux-mm, linux-kernel

On 04/12/2017 10:31 AM, Hoeun Ryu wrote:
> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
> during boot process and those virtually mapped areas are never unmapped.
> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
> existing vmlist entries and prevent those areas from being removed from the
> rbtree by accident.

I am wondering whether protection against accidental deletion
of any vmap area should be done in remove_vm_area() function
or the callers should take care of it. But I guess either way
it works.

> 
> Signed-off-by: Hoeun Ryu <hoeun.ryu@gmail.com>
> ---
>  include/linux/vmalloc.h | 1 +
>  mm/vmalloc.c            | 9 ++++++---
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
> index 46991ad..3df53fc 100644
> --- a/include/linux/vmalloc.h
> +++ b/include/linux/vmalloc.h
> @@ -19,6 +19,7 @@ struct notifier_block;		/* in notifier.h */
>  #define VM_UNINITIALIZED	0x00000020	/* vm_struct is not fully initialized */
>  #define VM_NO_GUARD		0x00000040      /* don't add guard page */
>  #define VM_KASAN		0x00000080      /* has allocated kasan shadow memory */
> +#define VM_STATIC		0x00000200

You might want to add some description in the comment saying
its a sticky VM area which will never go away or something.

>  /* bits [20..32] reserved for arch specific ioremap internals */
>  
>  /*
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 8ef8ea1..fb5049a 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -1262,7 +1262,7 @@ void __init vmalloc_init(void)
>  	/* Import existing vmlist entries. */
>  	for (tmp = vmlist; tmp; tmp = tmp->next) {
>  		va = kzalloc(sizeof(struct vmap_area), GFP_NOWAIT);
> -		va->flags = VM_VM_AREA;
> +		va->flags = VM_VM_AREA | VM_STATIC;
>  		va->va_start = (unsigned long)tmp->addr;
>  		va->va_end = va->va_start + tmp->size;
>  		va->vm = tmp;
> @@ -1480,7 +1480,7 @@ struct vm_struct *remove_vm_area(const void *addr)
>  	might_sleep();
>  
>  	va = find_vmap_area((unsigned long)addr);
> -	if (va && va->flags & VM_VM_AREA) {
> +	if (va && va->flags & VM_VM_AREA && likely(!(va->flags & VM_STATIC))) {


You might want to move the VM_STATIC check before the VM_VM_AREA
check so in cases where the former is set we can save one more
conditional check.

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
@ 2017-04-13  4:17   ` Anshuman Khandual
  0 siblings, 0 replies; 14+ messages in thread
From: Anshuman Khandual @ 2017-04-13  4:17 UTC (permalink / raw)
  To: Hoeun Ryu, Andrew Morton, Andrey Ryabinin, Andreas Dilger,
	Vlastimil Babka, Michal Hocko, Chris Wilson, Ingo Molnar,
	zijun_hu, Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov
  Cc: linux-arch, linux-mm, linux-kernel

On 04/12/2017 10:31 AM, Hoeun Ryu wrote:
> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
> during boot process and those virtually mapped areas are never unmapped.
> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
> existing vmlist entries and prevent those areas from being removed from the
> rbtree by accident.

I am wondering whether protection against accidental deletion
of any vmap area should be done in remove_vm_area() function
or the callers should take care of it. But I guess either way
it works.

> 
> Signed-off-by: Hoeun Ryu <hoeun.ryu@gmail.com>
> ---
>  include/linux/vmalloc.h | 1 +
>  mm/vmalloc.c            | 9 ++++++---
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
> index 46991ad..3df53fc 100644
> --- a/include/linux/vmalloc.h
> +++ b/include/linux/vmalloc.h
> @@ -19,6 +19,7 @@ struct notifier_block;		/* in notifier.h */
>  #define VM_UNINITIALIZED	0x00000020	/* vm_struct is not fully initialized */
>  #define VM_NO_GUARD		0x00000040      /* don't add guard page */
>  #define VM_KASAN		0x00000080      /* has allocated kasan shadow memory */
> +#define VM_STATIC		0x00000200

You might want to add some description in the comment saying
its a sticky VM area which will never go away or something.

>  /* bits [20..32] reserved for arch specific ioremap internals */
>  
>  /*
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 8ef8ea1..fb5049a 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -1262,7 +1262,7 @@ void __init vmalloc_init(void)
>  	/* Import existing vmlist entries. */
>  	for (tmp = vmlist; tmp; tmp = tmp->next) {
>  		va = kzalloc(sizeof(struct vmap_area), GFP_NOWAIT);
> -		va->flags = VM_VM_AREA;
> +		va->flags = VM_VM_AREA | VM_STATIC;
>  		va->va_start = (unsigned long)tmp->addr;
>  		va->va_end = va->va_start + tmp->size;
>  		va->vm = tmp;
> @@ -1480,7 +1480,7 @@ struct vm_struct *remove_vm_area(const void *addr)
>  	might_sleep();
>  
>  	va = find_vmap_area((unsigned long)addr);
> -	if (va && va->flags & VM_VM_AREA) {
> +	if (va && va->flags & VM_VM_AREA && likely(!(va->flags & VM_STATIC))) {


You might want to move the VM_STATIC check before the VM_VM_AREA
check so in cases where the former is set we can save one more
conditional check.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
  2017-04-13  4:17   ` Anshuman Khandual
@ 2017-04-14  0:25     ` Hoeun Ryu
  -1 siblings, 0 replies; 14+ messages in thread
From: Hoeun Ryu @ 2017-04-14  0:25 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: Andrew Morton, Andrey Ryabinin, Andreas Dilger, Vlastimil Babka,
	Michal Hocko, Chris Wilson, Ingo Molnar, zijun_hu,
	Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov, linux-arch,
	linux-mm, linux-kernel


> On Apr 13, 2017, at 1:17 PM, Anshuman Khandual <khandual@linux.vnet.ibm.com> wrote:
> 
>> On 04/12/2017 10:31 AM, Hoeun Ryu wrote:
>> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
>> during boot process and those virtually mapped areas are never unmapped.
>> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
>> existing vmlist entries and prevent those areas from being removed from the
>> rbtree by accident.
> 
> I am wondering whether protection against accidental deletion
> of any vmap area should be done in remove_vm_area() function
> or the callers should take care of it. But I guess either way
> it works.
> 
>> 
>> Signed-off-by: Hoeun Ryu <hoeun.ryu@gmail.com>
>> ---
>> include/linux/vmalloc.h | 1 +
>> mm/vmalloc.c            | 9 ++++++---
>> 2 files changed, 7 insertions(+), 3 deletions(-)
>> 
>> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
>> index 46991ad..3df53fc 100644
>> --- a/include/linux/vmalloc.h
>> +++ b/include/linux/vmalloc.h
>> @@ -19,6 +19,7 @@ struct notifier_block;        /* in notifier.h */
>> #define VM_UNINITIALIZED    0x00000020    /* vm_struct is not fully initialized */
>> #define VM_NO_GUARD        0x00000040      /* don't add guard page */
>> #define VM_KASAN        0x00000080      /* has allocated kasan shadow memory */
>> +#define VM_STATIC        0x00000200
> 
> You might want to add some description in the comment saying
> its a sticky VM area which will never go away or something.
> 

OK. I will add some description.

>> /* bits [20..32] reserved for arch specific ioremap internals */
>> 
>> /*
>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>> index 8ef8ea1..fb5049a 100644
>> --- a/mm/vmalloc.c
>> +++ b/mm/vmalloc.c
>> @@ -1262,7 +1262,7 @@ void __init vmalloc_init(void)
>>    /* Import existing vmlist entries. */
>>    for (tmp = vmlist; tmp; tmp = tmp->next) {
>>        va = kzalloc(sizeof(struct vmap_area), GFP_NOWAIT);
>> -        va->flags = VM_VM_AREA;
>> +        va->flags = VM_VM_AREA | VM_STATIC;
>>        va->va_start = (unsigned long)tmp->addr;
>>        va->va_end = va->va_start + tmp->size;
>>        va->vm = tmp;
>> @@ -1480,7 +1480,7 @@ struct vm_struct *remove_vm_area(const void *addr)
>>    might_sleep();
>> 
>>    va = find_vmap_area((unsigned long)addr);
>> -    if (va && va->flags & VM_VM_AREA) {
>> +    if (va && va->flags & VM_VM_AREA && likely(!(va->flags & VM_STATIC))) {
> 
> 
> You might want to move the VM_STATIC check before the VM_VM_AREA
> check so in cases where the former is set we can save one more
> conditional check.
> 

OK, I'll fix this in the next version

Thank you for the review.

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

* Re: [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas
@ 2017-04-14  0:25     ` Hoeun Ryu
  0 siblings, 0 replies; 14+ messages in thread
From: Hoeun Ryu @ 2017-04-14  0:25 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: Andrew Morton, Andrey Ryabinin, Andreas Dilger, Vlastimil Babka,
	Michal Hocko, Chris Wilson, Ingo Molnar, zijun_hu,
	Matthew Wilcox, Thomas Garnier, Kirill A. Shutemov, linux-arch,
	linux-mm, linux-kernel


> On Apr 13, 2017, at 1:17 PM, Anshuman Khandual <khandual@linux.vnet.ibm.com> wrote:
> 
>> On 04/12/2017 10:31 AM, Hoeun Ryu wrote:
>> vm_area_add_early/vm_area_register_early() are used to reserve vmalloc area
>> during boot process and those virtually mapped areas are never unmapped.
>> So `OR` VM_STATIC flag to the areas in vmalloc_init() when importing
>> existing vmlist entries and prevent those areas from being removed from the
>> rbtree by accident.
> 
> I am wondering whether protection against accidental deletion
> of any vmap area should be done in remove_vm_area() function
> or the callers should take care of it. But I guess either way
> it works.
> 
>> 
>> Signed-off-by: Hoeun Ryu <hoeun.ryu@gmail.com>
>> ---
>> include/linux/vmalloc.h | 1 +
>> mm/vmalloc.c            | 9 ++++++---
>> 2 files changed, 7 insertions(+), 3 deletions(-)
>> 
>> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
>> index 46991ad..3df53fc 100644
>> --- a/include/linux/vmalloc.h
>> +++ b/include/linux/vmalloc.h
>> @@ -19,6 +19,7 @@ struct notifier_block;        /* in notifier.h */
>> #define VM_UNINITIALIZED    0x00000020    /* vm_struct is not fully initialized */
>> #define VM_NO_GUARD        0x00000040      /* don't add guard page */
>> #define VM_KASAN        0x00000080      /* has allocated kasan shadow memory */
>> +#define VM_STATIC        0x00000200
> 
> You might want to add some description in the comment saying
> its a sticky VM area which will never go away or something.
> 

OK. I will add some description.

>> /* bits [20..32] reserved for arch specific ioremap internals */
>> 
>> /*
>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>> index 8ef8ea1..fb5049a 100644
>> --- a/mm/vmalloc.c
>> +++ b/mm/vmalloc.c
>> @@ -1262,7 +1262,7 @@ void __init vmalloc_init(void)
>>    /* Import existing vmlist entries. */
>>    for (tmp = vmlist; tmp; tmp = tmp->next) {
>>        va = kzalloc(sizeof(struct vmap_area), GFP_NOWAIT);
>> -        va->flags = VM_VM_AREA;
>> +        va->flags = VM_VM_AREA | VM_STATIC;
>>        va->va_start = (unsigned long)tmp->addr;
>>        va->va_end = va->va_start + tmp->size;
>>        va->vm = tmp;
>> @@ -1480,7 +1480,7 @@ struct vm_struct *remove_vm_area(const void *addr)
>>    might_sleep();
>> 
>>    va = find_vmap_area((unsigned long)addr);
>> -    if (va && va->flags & VM_VM_AREA) {
>> +    if (va && va->flags & VM_VM_AREA && likely(!(va->flags & VM_STATIC))) {
> 
> 
> You might want to move the VM_STATIC check before the VM_VM_AREA
> check so in cases where the former is set we can save one more
> conditional check.
> 

OK, I'll fix this in the next version

Thank you for the review.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2017-04-14  0:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-12  5:01 [PATCH] mm: add VM_STATIC flag to vmalloc and prevent from removing the areas Hoeun Ryu
2017-04-12  5:01 ` Hoeun Ryu
2017-04-12  6:02 ` Christoph Hellwig
2017-04-12  6:02   ` Christoph Hellwig
2017-04-12 11:42   ` Hoeun Ryu
2017-04-12 11:42     ` Hoeun Ryu
2017-04-12 17:31     ` Christoph Hellwig
2017-04-12 17:31       ` Christoph Hellwig
2017-04-13  1:03       ` Ho-Eun Ryu
2017-04-13  1:03         ` Ho-Eun Ryu
2017-04-13  4:17 ` Anshuman Khandual
2017-04-13  4:17   ` Anshuman Khandual
2017-04-14  0:25   ` Hoeun Ryu
2017-04-14  0:25     ` Hoeun Ryu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.