All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vivek Kumar <quic_vivekuma@quicinc.com>
To: <corbet@lwn.net>, <catalin.marinas@arm.com>, <will@kernel.org>,
	<tglx@linutronix.de>, <maz@kernel.org>, <axboe@kernel.dk>,
	<rafael@kernel.org>, <akpm@linux-foundation.org>,
	<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-block@vger.kernel.org>, <linux-pm@vger.kernel.org>,
	<linux-mm@kvack.org>
Cc: <len.brown@intel.com>, <pavel@ucw.cz>, <paulmck@kernel.org>,
	<bp@suse.de>, <keescook@chromium.org>, <songmuchun@bytedance.com>,
	<rdunlap@infradead.org>, <damien.lemoal@opensource.wdc.com>,
	<pasha.tatashin@soleen.com>, <tabba@google.com>,
	<ardb@kernel.org>, <tsoni@quicinc.com>,
	<quic_psodagud@quicinc.com>, <quic_svaddagi@quicinc.com>,
	Vivek Kumar <quic_vivekuma@quicinc.com>,
	Prasanna Kumar <quic_kprasan@quicinc.com>
Subject: [RFC 5/6] Hibernate: Add check for pte_valid in saveable page
Date: Wed, 18 May 2022 13:18:40 +0530	[thread overview]
Message-ID: <1652860121-24092-6-git-send-email-quic_vivekuma@quicinc.com> (raw)
In-Reply-To: <1652860121-24092-1-git-send-email-quic_vivekuma@quicinc.com>

Add check for pte_valid in saveable page after being checked for
the rest. This is required as PTE is removed for pages allocated
with dma_alloc_coherent with DMA_ATTR_NO_KERNEL_MAPPING flag set.
This patch makes sure that these pages are not considered for
snapshot.

Signed-off-by: Vivek Kumar <quic_vivekuma@quicinc.com>
Signed-off-by: Prasanna Kumar <quic_kprasan@quicinc.com>
---
 kernel/power/snapshot.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 2a40675..a6ad2a5 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -1308,6 +1308,41 @@ static inline void *saveable_highmem_page(struct zone *z, unsigned long p)
 }
 #endif /* CONFIG_HIGHMEM */
 
+static bool kernel_pte_present(struct page *page)
+{
+	pgd_t *pgdp;
+	p4d_t *p4dp;
+	pud_t *pudp, pud;
+	pmd_t *pmdp, pmd;
+	pte_t *ptep;
+	unsigned long addr = (unsigned long)page_address(page);
+
+	pgdp = pgd_offset_k(addr);
+	if (pgd_none(READ_ONCE(*pgdp)))
+		return false;
+
+	p4dp = p4d_offset(pgdp, addr);
+	if (p4d_none(READ_ONCE(*p4dp)))
+		return false;
+
+	pudp = pud_offset(p4dp, addr);
+	pud = READ_ONCE(*pudp);
+	if (pud_none(pud))
+		return false;
+	if (pud_sect(pud))
+		return true;
+
+	pmdp = pmd_offset(pudp, addr);
+	pmd = READ_ONCE(*pmdp);
+	if (pmd_none(pmd))
+		return false;
+	if (pmd_sect(pmd))
+		return true;
+
+	ptep = pte_offset_kernel(pmdp, addr);
+	return pte_valid(READ_ONCE(*ptep));
+}
+
 /**
  * saveable_page - Check if the given page is saveable.
  *
@@ -1341,6 +1376,14 @@ static struct page *saveable_page(struct zone *zone, unsigned long pfn)
 	    && (!kernel_page_present(page) || pfn_is_nosave(pfn)))
 		return NULL;
 
+	/*
+	 * Even if page is not reserved and if it's not present in kernel PTE;
+	 * don't snapshot it ! This happens to the pages allocated using
+	 * __dma_alloc_coherent with DMA_ATTR_NO_KERNEL_MAPPING flag set.
+	 */
+	if (!kernel_pte_present(page))
+		return NULL;
+
 	if (page_is_guard(page))
 		return NULL;
 
-- 
2.7.4


WARNING: multiple messages have this Message-ID (diff)
From: Vivek Kumar <quic_vivekuma@quicinc.com>
To: <corbet@lwn.net>, <catalin.marinas@arm.com>, <will@kernel.org>,
	<tglx@linutronix.de>, <maz@kernel.org>, <axboe@kernel.dk>,
	<rafael@kernel.org>, <akpm@linux-foundation.org>,
	<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-block@vger.kernel.org>, <linux-pm@vger.kernel.org>,
	<linux-mm@kvack.org>
Cc: <len.brown@intel.com>, <pavel@ucw.cz>, <paulmck@kernel.org>,
	<bp@suse.de>,  <keescook@chromium.org>,
	<songmuchun@bytedance.com>, <rdunlap@infradead.org>,
	 <damien.lemoal@opensource.wdc.com>, <pasha.tatashin@soleen.com>,
	<tabba@google.com>, <ardb@kernel.org>, <tsoni@quicinc.com>,
	<quic_psodagud@quicinc.com>, <quic_svaddagi@quicinc.com>,
	Vivek Kumar <quic_vivekuma@quicinc.com>,
	Prasanna Kumar <quic_kprasan@quicinc.com>
Subject: [RFC 5/6] Hibernate: Add check for pte_valid in saveable page
Date: Wed, 18 May 2022 13:18:40 +0530	[thread overview]
Message-ID: <1652860121-24092-6-git-send-email-quic_vivekuma@quicinc.com> (raw)
In-Reply-To: <1652860121-24092-1-git-send-email-quic_vivekuma@quicinc.com>

Add check for pte_valid in saveable page after being checked for
the rest. This is required as PTE is removed for pages allocated
with dma_alloc_coherent with DMA_ATTR_NO_KERNEL_MAPPING flag set.
This patch makes sure that these pages are not considered for
snapshot.

Signed-off-by: Vivek Kumar <quic_vivekuma@quicinc.com>
Signed-off-by: Prasanna Kumar <quic_kprasan@quicinc.com>
---
 kernel/power/snapshot.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 2a40675..a6ad2a5 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -1308,6 +1308,41 @@ static inline void *saveable_highmem_page(struct zone *z, unsigned long p)
 }
 #endif /* CONFIG_HIGHMEM */
 
+static bool kernel_pte_present(struct page *page)
+{
+	pgd_t *pgdp;
+	p4d_t *p4dp;
+	pud_t *pudp, pud;
+	pmd_t *pmdp, pmd;
+	pte_t *ptep;
+	unsigned long addr = (unsigned long)page_address(page);
+
+	pgdp = pgd_offset_k(addr);
+	if (pgd_none(READ_ONCE(*pgdp)))
+		return false;
+
+	p4dp = p4d_offset(pgdp, addr);
+	if (p4d_none(READ_ONCE(*p4dp)))
+		return false;
+
+	pudp = pud_offset(p4dp, addr);
+	pud = READ_ONCE(*pudp);
+	if (pud_none(pud))
+		return false;
+	if (pud_sect(pud))
+		return true;
+
+	pmdp = pmd_offset(pudp, addr);
+	pmd = READ_ONCE(*pmdp);
+	if (pmd_none(pmd))
+		return false;
+	if (pmd_sect(pmd))
+		return true;
+
+	ptep = pte_offset_kernel(pmdp, addr);
+	return pte_valid(READ_ONCE(*ptep));
+}
+
 /**
  * saveable_page - Check if the given page is saveable.
  *
@@ -1341,6 +1376,14 @@ static struct page *saveable_page(struct zone *zone, unsigned long pfn)
 	    && (!kernel_page_present(page) || pfn_is_nosave(pfn)))
 		return NULL;
 
+	/*
+	 * Even if page is not reserved and if it's not present in kernel PTE;
+	 * don't snapshot it ! This happens to the pages allocated using
+	 * __dma_alloc_coherent with DMA_ATTR_NO_KERNEL_MAPPING flag set.
+	 */
+	if (!kernel_pte_present(page))
+		return NULL;
+
 	if (page_is_guard(page))
 		return NULL;
 
-- 
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-05-18  7:49 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-18  7:48 [RFC 0/6] Bootloader based hibernation Vivek Kumar
2022-05-18  7:48 ` Vivek Kumar
2022-05-18  7:48 ` [RFC 1/6] arm64: hibernate: Introduce new entry point to kernel Vivek Kumar
2022-05-18  7:48   ` Vivek Kumar
2022-05-19 15:27   ` Marc Zyngier
2022-05-19 15:27     ` Marc Zyngier
2022-05-18  7:48 ` [RFC 2/6] PM: Hibernate: Add option to disable disk offset randomization Vivek Kumar
2022-05-18  7:48   ` Vivek Kumar
2022-05-18 12:19   ` Andrew Lunn
2022-05-18 12:19     ` Andrew Lunn
2022-05-18 13:00   ` Christoph Hellwig
2022-05-18 13:00     ` Christoph Hellwig
2022-05-23 20:49   ` Randy Dunlap
2022-05-23 20:49     ` Randy Dunlap
2022-05-18  7:48 ` [RFC 3/6] block: gendisk: Add a new genhd capability flag Vivek Kumar
2022-05-18  7:48   ` Vivek Kumar
2022-05-18  8:08   ` Christoph Hellwig
2022-05-18  8:08     ` Christoph Hellwig
2022-05-18  7:48 ` [RFC 4/6] mm: swap: Add randomization check for swapon/off calls Vivek Kumar
2022-05-18  7:48   ` Vivek Kumar
2022-05-18 12:27   ` Andrew Lunn
2022-05-18 12:27     ` Andrew Lunn
2022-05-18  7:48 ` Vivek Kumar [this message]
2022-05-18  7:48   ` [RFC 5/6] Hibernate: Add check for pte_valid in saveable page Vivek Kumar
2022-05-18 13:09   ` Christoph Hellwig
2022-05-18 13:09     ` Christoph Hellwig
2022-05-18  7:48 ` [RFC 6/6] irqchip/gic-v3: Re-init GIC hardware upon hibernation restore Vivek Kumar
2022-05-18  7:48   ` Vivek Kumar
2022-05-19  7:59   ` Marc Zyngier
2022-05-19  7:59     ` Marc Zyngier
2022-05-18 16:55 ` [RFC 0/6] Bootloader based hibernation Pasha Tatashin
2022-05-18 16:55   ` Pasha Tatashin
2022-05-20 16:43 ` Mark Rutland
2022-05-20 16:43   ` Mark Rutland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1652860121-24092-6-git-send-email-quic_vivekuma@quicinc.com \
    --to=quic_vivekuma@quicinc.com \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bp@suse.de \
    --cc=catalin.marinas@arm.com \
    --cc=corbet@lwn.net \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=keescook@chromium.org \
    --cc=len.brown@intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=paulmck@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=quic_kprasan@quicinc.com \
    --cc=quic_psodagud@quicinc.com \
    --cc=quic_svaddagi@quicinc.com \
    --cc=rafael@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=songmuchun@bytedance.com \
    --cc=tabba@google.com \
    --cc=tglx@linutronix.de \
    --cc=tsoni@quicinc.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.