Skip to content

Commit a82f711

Browse files
rjwysockilenb
authored andcommitted
Hibernation: Fix mark_nosave_pages()
There is a problem in the hibernation code that triggers on some NUMA systems on which pfn_valid() returns 'true' for some PFNs that don't belong to any zone. Namely, there is a BUG_ON() in memory_bm_find_bit() that triggers for PFNs not belonging to any zone and passing the pfn_valid() test. On the affected systems it triggers when we mark PFNs reported by the platform as not saveable, because the PFNs in question belong to a region mapped directly using iorepam() (i.e. the ACPI data area) and they pass the pfn_valid() test. Modify memory_bm_find_bit() so that it returns an error if given PFN doesn't belong to any zone instead of crashing the kernel and ignore the result returned by it in mark_nosave_pages(), while marking the "nosave" memory regions. This doesn't affect the hibernation functionality, as we won't touch the PFNs in question anyway. http://bugzilla.kernel.org/show_bug.cgi?id=9966 . Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent baadac8 commit a82f711

1 file changed

Lines changed: 34 additions & 7 deletions

File tree

‎kernel/power/snapshot.c‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free)
447447
* of @bm->cur_zone_bm are updated.
448448
*/
449449

450-
static void memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn,
450+
static int memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn,
451451
void **addr, unsigned int *bit_nr)
452452
{
453453
struct zone_bitmap *zone_bm;
@@ -461,7 +461,8 @@ static void memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn,
461461
while (pfn < zone_bm->start_pfn || pfn >= zone_bm->end_pfn) {
462462
zone_bm = zone_bm->next;
463463

464-
BUG_ON(!zone_bm);
464+
if (!zone_bm)
465+
return -EFAULT;
465466
}
466467
bm->cur.zone_bm = zone_bm;
467468
}
@@ -479,32 +480,51 @@ static void memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn,
479480
pfn -= bb->start_pfn;
480481
*bit_nr = pfn % BM_BITS_PER_CHUNK;
481482
*addr = bb->data + pfn / BM_BITS_PER_CHUNK;
483+
return 0;
482484
}
483485

484486
static void memory_bm_set_bit(struct memory_bitmap *bm, unsigned long pfn)
485487
{
486488
void *addr;
487489
unsigned int bit;
490+
int error;
488491

489-
memory_bm_find_bit(bm, pfn, &addr, &bit);
492+
error = memory_bm_find_bit(bm, pfn, &addr, &bit);
493+
BUG_ON(error);
490494
set_bit(bit, addr);
491495
}
492496

497+
static int mem_bm_set_bit_check(struct memory_bitmap *bm, unsigned long pfn)
498+
{
499+
void *addr;
500+
unsigned int bit;
501+
int error;
502+
503+
error = memory_bm_find_bit(bm, pfn, &addr, &bit);
504+
if (!error)
505+
set_bit(bit, addr);
506+
return error;
507+
}
508+
493509
static void memory_bm_clear_bit(struct memory_bitmap *bm, unsigned long pfn)
494510
{
495511
void *addr;
496512
unsigned int bit;
513+
int error;
497514

498-
memory_bm_find_bit(bm, pfn, &addr, &bit);
515+
error = memory_bm_find_bit(bm, pfn, &addr, &bit);
516+
BUG_ON(error);
499517
clear_bit(bit, addr);
500518
}
501519

502520
static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
503521
{
504522
void *addr;
505523
unsigned int bit;
524+
int error;
506525

507-
memory_bm_find_bit(bm, pfn, &addr, &bit);
526+
error = memory_bm_find_bit(bm, pfn, &addr, &bit);
527+
BUG_ON(error);
508528
return test_bit(bit, addr);
509529
}
510530

@@ -709,8 +729,15 @@ static void mark_nosave_pages(struct memory_bitmap *bm)
709729
region->end_pfn << PAGE_SHIFT);
710730

711731
for (pfn = region->start_pfn; pfn < region->end_pfn; pfn++)
712-
if (pfn_valid(pfn))
713-
memory_bm_set_bit(bm, pfn);
732+
if (pfn_valid(pfn)) {
733+
/*
734+
* It is safe to ignore the result of
735+
* mem_bm_set_bit_check() here, since we won't
736+
* touch the PFNs for which the error is
737+
* returned anyway.
738+
*/
739+
mem_bm_set_bit_check(bm, pfn);
740+
}
714741
}
715742
}
716743

0 commit comments

Comments
 (0)