From: Adrian Hunter <adrian.hunter@intel.com>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Borislav Petkov <bp@alien8.de>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Dave Hansen <dave.hansen@intel.com>,
Vlastimil Babka <vbabka@suse.cz>,
Mike Rapoport <rppt@linux.ibm.com>,
Lorenzo Stoakes <lstoakes@gmail.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Baoquan He <bhe@redhat.com>, Vivek Goyal <vgoyal@redhat.com>,
Dave Young <dyoung@redhat.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, linux-coco@lists.linux.dev,
linux-efi@vger.kernel.org, kexec@lists.infradead.org
Subject: [PATCH 1/3] proc/vmcore: Do not map unaccepted memory
Date: Wed, 6 Sep 2023 10:39:00 +0300 [thread overview]
Message-ID: <20230906073902.4229-2-adrian.hunter@intel.com> (raw)
In-Reply-To: <20230906073902.4229-1-adrian.hunter@intel.com>
Support for unaccepted memory was added recently, refer commit
dcdfdd40fa82 ("mm: Add support for unaccepted memory"), whereby
a virtual machine may need to accept memory before it can be used.
Do not map unaccepted memory because it can cause the guest to fail.
For /proc/vmcore, which is read-only, this means a read or mmap of
unaccepted memory will return zeros.
Fixes: dcdfdd40fa82 ("mm: Add support for unaccepted memory")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
fs/proc/vmcore.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index 1fb213f379a5..a28da2033ce8 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -118,6 +118,13 @@ static bool pfn_is_ram(unsigned long pfn)
return ret;
}
+static bool pfn_is_unaccepted_memory(unsigned long pfn)
+{
+ phys_addr_t paddr = pfn << PAGE_SHIFT;
+
+ return range_contains_unaccepted_memory(paddr, paddr + PAGE_SIZE);
+}
+
static int open_vmcore(struct inode *inode, struct file *file)
{
spin_lock(&vmcore_cb_lock);
@@ -150,7 +157,7 @@ ssize_t read_from_oldmem(struct iov_iter *iter, size_t count,
nr_bytes = count;
/* If pfn is not ram, return zeros for sparse dump files */
- if (!pfn_is_ram(pfn)) {
+ if (!pfn_is_ram(pfn) || pfn_is_unaccepted_memory(pfn)) {
tmp = iov_iter_zero(nr_bytes, iter);
} else {
if (encrypted)
@@ -511,7 +518,7 @@ static int remap_oldmem_pfn_checked(struct vm_area_struct *vma,
pos_end = pfn + (size >> PAGE_SHIFT);
for (pos = pos_start; pos < pos_end; ++pos) {
- if (!pfn_is_ram(pos)) {
+ if (!pfn_is_ram(pos) || pfn_is_unaccepted_memory(pos)) {
/*
* We hit a page which is not ram. Remap the continuous
* region between pos_start and pos-1 and replace
@@ -552,6 +559,7 @@ static int vmcore_remap_oldmem_pfn(struct vm_area_struct *vma,
unsigned long from, unsigned long pfn,
unsigned long size, pgprot_t prot)
{
+ phys_addr_t paddr = pfn << PAGE_SHIFT;
int ret, idx;
/*
@@ -559,7 +567,8 @@ static int vmcore_remap_oldmem_pfn(struct vm_area_struct *vma,
* pages without a reason.
*/
idx = srcu_read_lock(&vmcore_cb_srcu);
- if (!list_empty(&vmcore_cb_list))
+ if (!list_empty(&vmcore_cb_list) ||
+ range_contains_unaccepted_memory(paddr, paddr + size))
ret = remap_oldmem_pfn_checked(vma, from, pfn, size, prot);
else
ret = remap_oldmem_pfn_range(vma, from, pfn, size, prot);
--
2.34.1
next prev parent reply other threads:[~2023-09-06 7:39 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-06 7:38 [PATCH 0/3] Do not map unaccepted memory Adrian Hunter
2023-09-06 7:39 ` Adrian Hunter [this message]
2023-09-07 15:39 ` [PATCH 1/3] proc/vmcore: " Dave Hansen
2023-09-07 15:44 ` Adrian Hunter
2023-09-07 15:51 ` Dave Hansen
2023-09-11 8:03 ` David Hildenbrand
2023-09-11 8:41 ` Kirill A. Shutemov
2023-09-11 8:42 ` David Hildenbrand
2023-09-11 9:27 ` Kirill A. Shutemov
2023-09-11 9:50 ` David Hildenbrand
2023-09-11 10:05 ` Kirill A. Shutemov
2023-09-11 14:33 ` David Hildenbrand
2023-09-06 7:39 ` [PATCH 2/3] proc/kcore: " Adrian Hunter
2023-09-07 15:36 ` Dave Hansen
2023-09-07 15:43 ` Dave Hansen
2023-09-06 7:39 ` [PATCH 3/3] /dev/mem: " Adrian Hunter
2023-09-07 10:06 ` Kirill A. Shutemov
2023-09-07 14:15 ` Dave Hansen
2023-09-07 14:25 ` Kirill A. Shutemov
2023-09-07 14:46 ` Dave Hansen
2023-09-07 15:04 ` Dave Hansen
2023-09-11 8:09 ` David Hildenbrand
2023-09-11 14:32 ` Dave Hansen
2023-09-07 10:07 ` [PATCH 0/3] " Kirill A. Shutemov
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=20230906073902.4229-2-adrian.hunter@intel.com \
--to=adrian.hunter@intel.com \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=dyoung@redhat.com \
--cc=kexec@lists.infradead.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-efi@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lstoakes@gmail.com \
--cc=rppt@linux.ibm.com \
--cc=thomas.lendacky@amd.com \
--cc=vbabka@suse.cz \
--cc=vgoyal@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).