Message ID | 1652860121-24092-5-git-send-email-quic_vivekuma@quicinc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Bootloader based hibernation | expand |
On Wed, May 18, 2022 at 01:18:39PM +0530, Vivek Kumar wrote: > Add addtional check on swapon/swapoff sycalls to disable > randomization of swap offsets if GENHD_FL_NO_RANDOMIZE > flag is passed. Is there already a flag in the image header which tells you if the image is randomozied or not? I assume the bootloader needs to know, doing a linear read of a randomized image is not going to end well. Andrew
diff --git a/mm/swapfile.c b/mm/swapfile.c index 1c3d5b9..a3eeab6 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2474,7 +2474,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) if (p->flags & SWP_CONTINUED) free_swap_count_continuations(p); - if (!p->bdev || !bdev_nonrot(p->bdev)) + if (!p->bdev || (p->bdev->bd_disk->flags & GENHD_FL_NO_RANDOMIZE) + || !bdev_nonrot(p->bdev)) atomic_dec(&nr_rotate_swap); mutex_lock(&swapon_mutex); @@ -3065,7 +3066,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) if (p->bdev && p->bdev->bd_disk->fops->rw_page) p->flags |= SWP_SYNCHRONOUS_IO; - if (p->bdev && bdev_nonrot(p->bdev)) { + if (p->bdev && !(p->bdev->bd_disk->flags & GENHD_FL_NO_RANDOMIZE) && + bdev_nonrot(p->bdev)) { int cpu; unsigned long ci, nr_cluster;