From: Izik Eidus <izike-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: kvm-devel
<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
andrea-atKUWr5tajBWk0Htik3J/w@public.gmane.org,
avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org,
dor.laor-atKUWr5tajBWk0Htik3J/w@public.gmane.org,
linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org,
yaniv-atKUWr5tajBWk0Htik3J/w@public.gmane.org
Subject: [RFC][PATCH 2/5] add new exported function replace_page()
Date: Mon, 21 Jan 2008 18:10:50 +0200 [thread overview]
Message-ID: <4794C40A.3020500@qumranet.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 12 bytes --]
--
woof.
[-- Attachment #2: 0005-memory.c-add-new-exported-function-replace_page.patch --]
[-- Type: text/x-patch, Size: 2904 bytes --]
>From c6fc21397e37481696723115cb1680f42661be48 Mon Sep 17 00:00:00 2001
From: Izik Eidus <izike-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Date: Mon, 21 Jan 2008 17:04:45 +0200
Subject: [PATCH] memory.c: add new exported function replace_page()
replace_page() - replace the pte mapping related to vm area between two pages
(from oldpage to newpage)
Signed-off-by: Izik Eidus <izike-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
---
include/linux/mm.h | 5 +++-
mm/memory.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 1 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 1b7b95c..a311c25 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1094,7 +1094,10 @@ int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
unsigned long pfn, unsigned long size, pgprot_t);
int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page *);
int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
- unsigned long pfn);
+ unsigned long pfn);
+
+int replace_page(struct vm_area_struct *vma, struct page *oldpage,
+ struct page *newpage, pgprot_t prot);
struct page *follow_page(struct vm_area_struct *, unsigned long address,
unsigned int foll_flags);
diff --git a/mm/memory.c b/mm/memory.c
index 4bf0b6d..d8cb36b 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2360,6 +2360,66 @@ static int do_linear_fault(struct mm_struct *mm, struct vm_area_struct *vma,
return __do_fault(mm, vma, address, pmd, pgoff, flags, orig_pte);
}
+/**
+ * replace_page - replace the pte mapping related to vm area between two pages
+ * (from oldpage to newpage)
+ */
+int replace_page(struct vm_area_struct *vma, struct page *oldpage,
+ struct page *newpage, pgprot_t prot)
+{
+ struct mm_struct *mm = vma->vm_mm;
+ pgd_t *pgd;
+ pud_t *pud;
+ pmd_t *pmd;
+ pte_t *ptep;
+ spinlock_t *ptl;
+ unsigned long addr;
+ int ret;
+
+ BUG_ON(!PageLocked(oldpage));
+
+ ret = -EFAULT;
+ addr = page_address_in_vma(oldpage, vma);
+ if (addr == -EFAULT)
+ goto out;
+
+ pgd = pgd_offset(mm, addr);
+ if (!pgd_present(*pgd))
+ goto out;
+
+ pud = pud_offset(pgd, addr);
+ if (!pud_present(*pud))
+ goto out;
+
+ pmd = pmd_offset(pud, addr);
+ if (!pmd_present(*pmd))
+ goto out;
+
+ ptep = pte_offset_map_lock(mm, pmd, addr, &ptl);
+ if (!ptep)
+ goto out;
+
+ ret = 0;
+ get_page(newpage);
+ page_add_file_rmap(newpage);
+
+ flush_cache_page(vma, addr, pte_pfn(*ptep));
+ ptep_clear_flush(vma, addr, ptep);
+ set_pte_at(mm, addr, ptep, mk_pte(newpage, prot));
+
+ page_remove_rmap(oldpage, vma);
+ if (PageAnon(oldpage)) {
+ dec_mm_counter(mm, anon_rss);
+ inc_mm_counter(mm, file_rss);
+ }
+ put_page(oldpage);
+
+ pte_unmap_unlock(ptep, ptl);
+out:
+ return ret;
+}
+EXPORT_SYMBOL_GPL(replace_page);
+
/*
* do_no_pfn() tries to create a new page mapping for a page without
--
1.5.3.6
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 186 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel
WARNING: multiple messages have this Message-ID (diff)
From: Izik Eidus <izike@qumranet.com>
To: kvm-devel <kvm-devel@lists.sourceforge.net>,
andrea@qumranet.com, avi@qumranet.com, dor.laor@qumranet.com,
linux-mm@kvack.org, yaniv@qumranet.com
Subject: [RFC][PATCH 2/5] add new exported function replace_page()
Date: Mon, 21 Jan 2008 18:10:50 +0200 [thread overview]
Message-ID: <4794C40A.3020500@qumranet.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 12 bytes --]
--
woof.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0005-memory.c-add-new-exported-function-replace_page.patch --]
[-- Type: text/x-patch; name="0005-memory.c-add-new-exported-function-replace_page.patch", Size: 0 bytes --]
next reply other threads:[~2008-01-21 16:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-21 16:10 Izik Eidus [this message]
2008-01-21 16:10 ` [RFC][PATCH 2/5] add new exported function replace_page() Izik Eidus
[not found] ` <4794C40A.3020500-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-01-23 18:04 ` Rik van Riel
2008-01-23 18:04 ` [kvm-devel] " Rik van Riel
[not found] ` <20080123130426.45dad2db-Fuq27k0DHcCSkoNiqTzCLQ@public.gmane.org>
2008-01-23 18:13 ` Izik Eidus
2008-01-23 18:13 ` [kvm-devel] " Izik Eidus
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=4794C40A.3020500@qumranet.com \
--to=izike-atkuwr5tajbwk0htik3j/w@public.gmane.org \
--cc=andrea-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
--cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
--cc=dor.laor-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
--cc=yaniv-atKUWr5tajBWk0Htik3J/w@public.gmane.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.