Skip to contentSkip to conversation

mm/sparse: reset section's mem_map when fully deactivated

PATCH Superseded Pingfan Liu 6 participants 16 messages Jan 16, 2020 – Jan 20, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/sparse: reset section's mem_map when fully deactivated

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

The bug can be reproduced on IBM POWERVM by "drmgr -c mem -r -q 5" , trigger a crash, and save vmcore by makedumpfile

To: [email protected]
Cc: Andrew Morton <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Oscar Salvador <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: [email protected]
Cc: Kazuhito Hagio <[email protected]>

---
 mm/sparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/sparse.c +1 -1
index 3822ecb..fddac80 100644
@@ -789,7 +789,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
 			ms->usage = NULL;
 		}
 		memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr);
-		ms->section_mem_map = sparse_encode_mem_map(NULL, section_nr);
+		ms->section_mem_map = NULL;
 	}
 
 	if (section_is_early && memmap)
Signature · 1 line
2.7.5
#1 lore raw
Quoted 9 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

Well, tools like makedumpfile and the crash utility always has to copy with low kernel implementation details changes like this. Why is it different this time?

Quoted 34 lines

The bug can be reproduced on IBM POWERVM by "drmgr -c mem -r -q 5" , trigger a crash, and save vmcore by makedumpfile

To: [email protected]
Cc: Andrew Morton <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Oscar Salvador <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: [email protected]
Cc: Kazuhito Hagio <[email protected]>
---
mm/sparse.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/sparse.c +1 -1
index 3822ecb..fddac80 100644
@@ -789,7 +789,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
 			ms->usage = NULL;
 		}
 		memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr);
-		ms->section_mem_map = sparse_encode_mem_map(NULL, section_nr);
+		ms->section_mem_map = NULL;
 	}
 
 	if (section_is_early && memmap)
Signature · 1 line
2.7.5
#2 lore raw
Quoted 5 lines · Qian Cai
Quoted 5 lines · Pingfan Liu
Quoted 7 lines
Quoted 5 lines

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

Well, tools like makedumpfile and the crash utility always has to copy with

                            ^^^ cope ?
Quoted 1 line

low kernel implementation details changes like this. Why is it different this time?

Yeah, there are two direction. But as the first argument, it is meaningless to keep the value.

Thanks,
Pingfan

reviewer
#3 lore raw
In reply to Pingfan Liu
Quoted 5 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

We used to do that before ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug"). Dan was this an intentional change?

Quoted 31 lines

The bug can be reproduced on IBM POWERVM by "drmgr -c mem -r -q 5" , trigger a crash, and save vmcore by makedumpfile

To: [email protected]
Cc: Andrew Morton <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Oscar Salvador <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: [email protected]
Cc: Kazuhito Hagio <[email protected]>

---
 mm/sparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/sparse.c +1 -1
index 3822ecb..fddac80 100644
@@ -789,7 +789,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
 			ms->usage = NULL;
 		}
 		memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr);
-		ms->section_mem_map = sparse_encode_mem_map(NULL, section_nr);
+		ms->section_mem_map = NULL;
 	}
 
 	if (section_is_early && memmap)
Signature · 1 line
2.7.5
Signature · 2 lines
Michal Hocko
SUSE Labs
#10 lore raw
In reply to Pingfan Liu
Quoted 8 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

The bug can be reproduced on IBM POWERVM by "drmgr -c mem -r -q 5" , trigger a crash, and save vmcore by makedumpfile

Are you using an up-to-date makedumfile and did kdump.service properly get reloaded on the udev events? I remember that this works.

makedumpfile will not dump memory sections that a) are not marked offline (SECTION_IS_ONLINE) - after offlining b) are not part of an iomem resource - after memory unplug.

The current code makes sure that sparse_decode_mem_map() will return NULL.

Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by
#11 lore raw
Quoted 13 lines · David Hildenbrand
Quoted 8 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

The bug can be reproduced on IBM POWERVM by "drmgr -c mem -r -q 5" , trigger a crash, and save vmcore by makedumpfile

Are you using an up-to-date makedumfile and did kdump.service properly get reloaded on the udev events? I remember that this works.

Quoted 7 lines

makedumpfile will not dump memory sections that a) are not marked offline (SECTION_IS_ONLINE) - after offlining b) are not part of an iomem resource - after memory unplug.

The current code makes sure that sparse_decode_mem_map() will return NULL.

... but it's only used at this very place. I think we should add a
Fixes: tag, although this might be fixed as well in makedumpfile (so people are aware that patch broke something)

Signature · 3 lines
Thanks,

David / dhildenb
#12 lore raw
Quoted 11 lines · David Hildenbrand
Quoted 10 lines · David Hildenbrand
Quoted 8 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

The bug can be reproduced on IBM POWERVM by "drmgr -c mem -r -q 5" , trigger a crash, and save vmcore by makedumpfile

Quoted 6 lines
Quoted 6 lines

Are you using an up-to-date makedumfile and did kdump.service properly get reloaded on the udev events? I remember that this works.

makedumpfile will not dump memory sections that a) are not marked offline (SECTION_IS_ONLINE) - after offlining b) are not part of an iomem resource - after memory unplug.

Makedumpfile seems to only check SECTION_MARKED_PRESENT. Then the NULL memmap will fail vmcore dumping, I guess.

Quoted 8 lines
Quoted 4 lines

The current code makes sure that sparse_decode_mem_map() will return NULL.

... but it's only used at this very place. I think we should add a
Fixes: tag, although this might be fixed as well in makedumpfile (so people are aware that patch broke something)

Agree, it's worth fixing it too in makedumpfile side to enhance.

#13 lore raw
Quoted 15 lines · Baoquan He
Quoted 14 lines · David Hildenbrand
Quoted 13 lines · David Hildenbrand
Quoted 8 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

The bug can be reproduced on IBM POWERVM by "drmgr -c mem -r -q 5" , trigger a crash, and save vmcore by makedumpfile

Are you using an up-to-date makedumfile and did kdump.service properly get reloaded on the udev events? I remember that this works.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

makedumpfile will not dump memory sections that a) are not marked offline (SECTION_IS_ONLINE) - after offlining b) are not part of an iomem resource - after memory unplug.

Makedumpfile seems to only check SECTION_MARKED_PRESENT. Then the NULL memmap will fail vmcore dumping, I guess.

But why should the section be marked SECTION_MARKED_PRESENT? After unplugging a section, the flag will be cleared.

validate_mem_section() seems to iterate over all sections 0..num_section
- 1 and validates them.

section = nr_to_section(section_nr, mem_sec);
if (section == NOT_KV_ADDR) {
mem_map = NOT_MEMMAP_ADDR:

} else {
	mem_map = section_mem_map_addr(section, &map_mask)
	if (!(map_mask & SECTION_MARKED_PRESENT)) {
		return FALSE;
	}
	if (mem_map == 0) {
		mem_map = NOT_MEMMAP_ADDR;
	} else {
	...

But here it is:

section_mem_map_addr():

map = ULONG(mem_section + OFFSET(mem_section.section_mem_map)); mask = SECTION_MAP_MASK;
*map_mask = map & ~mask;
if (map == 0x0)

	*map_mask |= SECTION_MARKED_PRESENT;

If the map is zero, the section is assumed to be present. The way the map is calculated, it will be zero due to the changes in the kernel.

Signature · 3 lines
Thanks,

David / dhildenb
#15 lore raw
In reply to David Hildenbrand
Quoted 5 lines · David Hildenbrand
Quoted 3 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Quoted 8 lines
Quoted 5 lines

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

The bug can be reproduced on IBM POWERVM by "drmgr -c mem -r -q 5" , trigger a crash, and save vmcore by makedumpfile

Are you using an up-to-date makedumfile and did kdump.service properly get reloaded on the udev events? I remember that this works.

I tried to get a machine and double-check it. The latest devel branch of makedumpfile can not work.

Quoted 4 lines

makedumpfile will not dump memory sections that a) are not marked offline (SECTION_IS_ONLINE) - after offlining b) are not part of an iomem resource - after memory unplug.

I think the current implementation of makedumpfile should improve the handling process.

And my primary argument for this patch is a pattern like alloc/free. And when fully deactivated, it is meaningless to keep the section start pfn info

Quoted 3 lines

The current code makes sure that sparse_decode_mem_map() will return NULL.

Do you mean the code in makedumpfile? If yes, it can. But makedumpfile related code has some bug, and should be improved to utilize this function.

Thanks,
Pingfan

Quoted 6 lines

--
Thanks,

David / dhildenb

#14 lore raw
In reply to Baoquan He
Quoted 16 lines · Baoquan He
Quoted 14 lines · David Hildenbrand
Quoted 13 lines · David Hildenbrand
Quoted 8 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

The bug can be reproduced on IBM POWERVM by "drmgr -c mem -r -q 5" , trigger a crash, and save vmcore by makedumpfile

Are you using an up-to-date makedumfile and did kdump.service properly get reloaded on the udev events? I remember that this works.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

makedumpfile will not dump memory sections that a) are not marked offline (SECTION_IS_ONLINE) - after offlining b) are not part of an iomem resource - after memory unplug.

Makedumpfile seems to only check SECTION_MARKED_PRESENT. Then the NULL memmap will fail vmcore dumping, I guess.

makedumpfile.c / validate_mem_section() has some trick, so it will not fail.

Quoted 12 lines
Quoted 9 lines
Quoted 5 lines

The current code makes sure that sparse_decode_mem_map() will return NULL.

... but it's only used at this very place. I think we should add a
Fixes: tag, although this might be fixed as well in makedumpfile (so people are aware that patch broke something)

Agree, it's worth fixing it too in makedumpfile side to enhance.

Yeah, I also agree :)

#4 lore raw
In reply to Michal Hocko
Quoted 10 lines · Michal Hocko
Quoted 5 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

We used to do that before ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug"). Dan was this an intentional change?

I do not know the purpose of this. But the change just leave section start pfn in fully deactivated section_mem_map, and not used any more.

Thanks,
Pingfan

#5 lore raw
Quoted 7 lines · Pingfan Liu
Quoted 5 lines · Michal Hocko
Quoted 3 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

We used to do that before ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug"). Dan was this an intentional change?

I do not know the purpose of this. But the change just leave section start pfn in fully deactivated section_mem_map, and not used any more.

Not intentional, IIRC at the time I had convinced myself that the value would always be translated by sparse_decode_mem_map(), so I thought it could be hiding NULL de-references. I don't see any harm in the patch.

reviewer
#6 lore raw
Quoted 13 lines · Dan Williams
Quoted 12 lines · Pingfan Liu
Quoted 10 lines · Michal Hocko
Quoted 5 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

We used to do that before ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug"). Dan was this an intentional change?

Quoted 7 lines
Quoted 2 lines

I do not know the purpose of this. But the change just leave section start pfn in fully deactivated section_mem_map, and not used any more.

Not intentional, IIRC at the time I had convinced myself that the value would always be translated by sparse_decode_mem_map(), so I thought it could be hiding NULL de-references. I don't see any harm in the patch.

Thanks for the confirmation. It would be great to have this in the changelog.

Signature · 2 lines
Michal Hocko
SUSE Labs
#7 lore raw
Quoted 18 lines · Michal Hocko
Quoted 16 lines · Dan Williams
Quoted 14 lines · Pingfan Liu
Quoted 10 lines · Michal Hocko
Quoted 5 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

We used to do that before ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug"). Dan was this an intentional change?

I do not know the purpose of this. But the change just leave section start pfn in fully deactivated section_mem_map, and not used any more.

Quoted 7 lines
Quoted 4 lines

Not intentional, IIRC at the time I had convinced myself that the value would always be translated by sparse_decode_mem_map(), so I thought it could be hiding NULL de-references. I don't see any harm in the patch.

Thanks for the confirmation. It would be great to have this in the changelog.

Should I post V2 with this commit log?

Thanks,
Pingfan

#8 lore raw
Quoted 24 lines · Pingfan Liu
Quoted 23 lines · Michal Hocko
Quoted 20 lines · Dan Williams
Quoted 7 lines · Pingfan Liu
Quoted 5 lines · Michal Hocko
Quoted 3 lines · Pingfan Liu

When fully deactivated, it is meaningless to keep the value of a section's mem_map. And its mem_map will be reassigned during re-added.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Beside this, it breaks the user space tool "makedumpfile", which makes assumption that a hot-removed section having mem_map as NULL.

We used to do that before ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug"). Dan was this an intentional change?

I do not know the purpose of this. But the change just leave section start pfn in fully deactivated section_mem_map, and not used any more.

Not intentional, IIRC at the time I had convinced myself that the value would always be translated by sparse_decode_mem_map(), so I thought it could be hiding NULL de-references. I don't see any harm in the patch.

Quoted 7 lines
Quoted 2 lines

Thanks for the confirmation. It would be great to have this in the changelog.

Should I post V2 with this commit log?

Thanks,
Pingfan

Id' say yes, and maybe also add some details why this makes makedumpfile bail out now, so people looking at this commit only know what's happening.

Signature · 3 lines
Thanks,

David / dhildenb
#9 lore raw
Quoted 1 line · David Hildenbrand

[...]

Quoted 10 lines
Quoted 7 lines
Quoted 2 lines

Thanks for the confirmation. It would be great to have this in the changelog.

Should I post V2 with this commit log?

Thanks,
Pingfan

Id' say yes, and maybe also add some details why this makes makedumpfile bail out now, so people looking at this commit only know what's happening.

OK, thanks for the suggestion.

I have sent another patch for makedumpfile and cc you.

Thanks,
Pingfan