From: Avi Kivity <avi@qumranet.com>
To: kvm-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org, Heiko Carstens <heiko.carstens@de.ibm.com>
Subject: [PATCH 03/45] s390: KVM preparation: host memory management changes for s390 kvm
Date: Thu, 17 Apr 2008 12:10:08 +0300 [thread overview]
Message-ID: <1208423450-29415-4-git-send-email-avi@qumranet.com> (raw)
In-Reply-To: <1208423450-29415-1-git-send-email-avi@qumranet.com>
From: Heiko Carstens <heiko.carstens@de.ibm.com>
From: Christian Borntraeger <borntraeger@de.ibm.com>
This patch changes the s390 memory management defintions to use the pgste field
for dirty and reference bit tracking of host and guest code. Usually on s390,
dirty and referenced are tracked in storage keys, which belong to the physical
page. This changes with virtualization: The guest and host dirty/reference bits
are defined to be the logical OR of the values for the mapping and the physical
page. This patch implements the necessary changes in pgtable.h for s390.
There is a common code change in mm/rmap.c, the call to
page_test_and_clear_young must be moved. This is a no-op for all
architecture but s390. page_referenced checks the referenced bits for
the physiscal page and for all mappings:
o The physical page is checked with page_test_and_clear_young.
o The mappings are checked with ptep_test_and_clear_young and friends.
Without pgstes (the current implementation on Linux s390) the physical page
check is implemented but the mapping callbacks are no-ops because dirty
and referenced are not tracked in the s390 page tables. The pgstes introduces
guest and host dirty and reference bits for s390 in the host mapping. These
mapping must be checked before page_test_and_clear_young resets the reference
bit.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Acked-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
include/asm-s390/pgtable.h | 92 ++++++++++++++++++++++++++++++++++++++++++-
mm/rmap.c | 7 ++-
2 files changed, 93 insertions(+), 6 deletions(-)
diff --git a/include/asm-s390/pgtable.h b/include/asm-s390/pgtable.h
index 8e9a629..7fe5c4b 100644
--- a/include/asm-s390/pgtable.h
+++ b/include/asm-s390/pgtable.h
@@ -30,6 +30,7 @@
*/
#ifndef __ASSEMBLY__
#include <linux/mm_types.h>
+#include <asm/bitops.h>
#include <asm/bug.h>
#include <asm/processor.h>
@@ -258,6 +259,13 @@ extern char empty_zero_page[PAGE_SIZE];
* swap pte is 1011 and 0001, 0011, 0101, 0111 are invalid.
*/
+/* Page status table bits for virtualization */
+#define RCP_PCL_BIT 55
+#define RCP_HR_BIT 54
+#define RCP_HC_BIT 53
+#define RCP_GR_BIT 50
+#define RCP_GC_BIT 49
+
#ifndef __s390x__
/* Bits in the segment table address-space-control-element */
@@ -513,6 +521,48 @@ static inline int pte_file(pte_t pte)
#define __HAVE_ARCH_PTE_SAME
#define pte_same(a,b) (pte_val(a) == pte_val(b))
+static inline void rcp_lock(pte_t *ptep)
+{
+#ifdef CONFIG_PGSTE
+ unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
+ preempt_disable();
+ while (test_and_set_bit(RCP_PCL_BIT, pgste))
+ ;
+#endif
+}
+
+static inline void rcp_unlock(pte_t *ptep)
+{
+#ifdef CONFIG_PGSTE
+ unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
+ clear_bit(RCP_PCL_BIT, pgste);
+ preempt_enable();
+#endif
+}
+
+/* forward declaration for SetPageUptodate in page-flags.h*/
+static inline void page_clear_dirty(struct page *page);
+#include <linux/page-flags.h>
+
+static inline void ptep_rcp_copy(pte_t *ptep)
+{
+#ifdef CONFIG_PGSTE
+ struct page *page = virt_to_page(pte_val(*ptep));
+ unsigned int skey;
+ unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
+
+ skey = page_get_storage_key(page_to_phys(page));
+ if (skey & _PAGE_CHANGED)
+ set_bit(RCP_GC_BIT, pgste);
+ if (skey & _PAGE_REFERENCED)
+ set_bit(RCP_GR_BIT, pgste);
+ if (test_and_clear_bit(RCP_HC_BIT, pgste))
+ SetPageDirty(page);
+ if (test_and_clear_bit(RCP_HR_BIT, pgste))
+ SetPageReferenced(page);
+#endif
+}
+
/*
* query functions pte_write/pte_dirty/pte_young only work if
* pte_present() is true. Undefined behaviour if not..
@@ -599,6 +649,8 @@ static inline void pmd_clear(pmd_t *pmd)
static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
{
+ if (mm->context.pgstes)
+ ptep_rcp_copy(ptep);
pte_val(*ptep) = _PAGE_TYPE_EMPTY;
if (mm->context.noexec)
pte_val(ptep[PTRS_PER_PTE]) = _PAGE_TYPE_EMPTY;
@@ -667,6 +719,24 @@ static inline pte_t pte_mkyoung(pte_t pte)
static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep)
{
+#ifdef CONFIG_PGSTE
+ unsigned long physpage;
+ int young;
+ unsigned long *pgste;
+
+ if (!vma->vm_mm->context.pgstes)
+ return 0;
+ physpage = pte_val(*ptep) & PAGE_MASK;
+ pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
+
+ young = ((page_get_storage_key(physpage) & _PAGE_REFERENCED) != 0);
+ rcp_lock(ptep);
+ if (young)
+ set_bit(RCP_GR_BIT, pgste);
+ young |= test_and_clear_bit(RCP_HR_BIT, pgste);
+ rcp_unlock(ptep);
+ return young;
+#endif
return 0;
}
@@ -674,7 +744,13 @@ static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
unsigned long address, pte_t *ptep)
{
- /* No need to flush TLB; bits are in storage key */
+ /* No need to flush TLB
+ * On s390 reference bits are in storage key and never in TLB
+ * With virtualization we handle the reference bit, without we
+ * we can simply return */
+#ifdef CONFIG_PGSTE
+ return ptep_test_and_clear_young(vma, address, ptep);
+#endif
return 0;
}
@@ -693,15 +769,25 @@ static inline void __ptep_ipte(unsigned long address, pte_t *ptep)
: "=m" (*ptep) : "m" (*ptep),
"a" (pto), "a" (address));
}
- pte_val(*ptep) = _PAGE_TYPE_EMPTY;
}
static inline void ptep_invalidate(struct mm_struct *mm,
unsigned long address, pte_t *ptep)
{
+ if (mm->context.pgstes) {
+ rcp_lock(ptep);
+ __ptep_ipte(address, ptep);
+ ptep_rcp_copy(ptep);
+ pte_val(*ptep) = _PAGE_TYPE_EMPTY;
+ rcp_unlock(ptep);
+ return;
+ }
__ptep_ipte(address, ptep);
- if (mm->context.noexec)
+ pte_val(*ptep) = _PAGE_TYPE_EMPTY;
+ if (mm->context.noexec) {
__ptep_ipte(address, ptep + PTRS_PER_PTE);
+ pte_val(*(ptep + PTRS_PER_PTE)) = _PAGE_TYPE_EMPTY;
+ }
}
/*
diff --git a/mm/rmap.c b/mm/rmap.c
index 997f069..e9bb6b1 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -413,9 +413,6 @@ int page_referenced(struct page *page, int is_locked,
{
int referenced = 0;
- if (page_test_and_clear_young(page))
- referenced++;
-
if (TestClearPageReferenced(page))
referenced++;
@@ -433,6 +430,10 @@ int page_referenced(struct page *page, int is_locked,
unlock_page(page);
}
}
+
+ if (page_test_and_clear_young(page))
+ referenced++;
+
return referenced;
}
--
1.5.5
next prev parent reply other threads:[~2008-04-17 9:12 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-17 9:10 [PATCH 00/45] KVM updates for the 2.6.26 merge window (part III) Avi Kivity
2008-04-17 9:10 ` [PATCH 01/45] s390: fixup for kvm Avi Kivity
2008-04-17 9:10 ` [PATCH 02/45] s390: KVM preparation: provide hook to enable pgstes in user pagetable Avi Kivity
2008-04-17 9:10 ` Avi Kivity [this message]
2008-04-17 9:10 ` [PATCH 04/45] s390: KVM preparation: address of the 64bit extint parm in lowcore Avi Kivity
2008-04-17 9:10 ` [PATCH 05/45] s390: KVM preparation: split sysinfo defintions for kvm use Avi Kivity
2008-04-17 9:10 ` [PATCH 06/45] KVM: s390: arch backend for the kvm kernel module Avi Kivity
2008-04-17 9:10 ` [PATCH 07/45] KVM: s390: sie intercept handling Avi Kivity
2008-04-17 9:10 ` [PATCH 08/45] KVM: s390: interrupt subsystem, cpu timer, waitpsw Avi Kivity
2008-04-17 9:10 ` [PATCH 09/45] KVM: s390: intercepts for privileged instructions Avi Kivity
2008-04-17 9:10 ` [PATCH 10/45] KVM: s390: interprocessor communication via sigp Avi Kivity
2008-04-17 9:10 ` [PATCH 11/45] KVM: s390: intercepts for diagnose instructions Avi Kivity
2008-04-17 9:10 ` [PATCH 12/45] KVM: s390: add kvm to kconfig on s390 Avi Kivity
2008-04-17 9:10 ` [PATCH 13/45] KVM: s390: API documentation Avi Kivity
2008-04-17 15:11 ` Randy Dunlap
2008-04-17 15:42 ` Carsten Otte
2008-04-17 9:10 ` [PATCH 14/45] KVM: s390: update maintainers Avi Kivity
2008-04-17 9:10 ` [PATCH 15/45] s390: KVM guest: detect when running on kvm Avi Kivity
2008-04-17 9:10 ` [PATCH 16/45] s390: KVM guest: virtio device support, and kvm hypercalls Avi Kivity
2008-04-17 9:10 ` [PATCH 17/45] KVM: VMX: Enable MSR Bitmap feature Avi Kivity
2008-04-17 9:10 ` [PATCH 18/45] KVM: MMU: unify slots_lock usage Avi Kivity
2008-04-17 9:10 ` [PATCH 19/45] KVM: MMU: allow the vm to shrink the kvm mmu shadow caches Avi Kivity
2008-04-17 9:10 ` [PATCH 20/45] KVM: Free apic access page on vm destruction Avi Kivity
2008-04-17 9:10 ` [PATCH 21/45] KVM: function declaration parameter name cleanup Avi Kivity
2008-04-17 9:10 ` [PATCH 22/45] KVM: add vm refcounting Avi Kivity
2008-04-17 9:10 ` [PATCH 23/45] KVM: MMU: Only mark_page_accessed() if the page was accessed by the guest Avi Kivity
2008-04-17 9:10 ` [PATCH 24/45] KVM: MMU: prepopulate guest pages after write-protecting Avi Kivity
2008-04-17 9:10 ` [PATCH 25/45] KVM: s390: Fix incorrect return value Avi Kivity
2008-04-17 9:10 ` [PATCH 26/45] KVM: s390: rename stfl to kvm_stfl Avi Kivity
2008-04-17 9:10 ` [PATCH 27/45] KVM: s390: Improve pgste accesses Avi Kivity
2008-04-17 9:10 ` [PATCH 28/45] ia64: Add API for allocating Dynamic TR resource Avi Kivity
2008-04-17 9:10 ` [PATCH 29/45] ia64: Implement smp_call_function_mask for ia64 Avi Kivity
2008-04-17 9:10 ` [PATCH 30/45] KVM: ia64: Prepare some structure and routines for kvm use Avi Kivity
2008-04-17 9:10 ` [PATCH 31/45] KVM: ia64: Add header files for kvm/ia64 Avi Kivity
2008-04-17 9:10 ` [PATCH 32/45] KVM: ia64: Add kvm arch-specific core code " Avi Kivity
2008-04-17 9:10 ` [PATCH 33/45] KVM: ia64: Add header files " Avi Kivity
2008-04-17 9:10 ` [PATCH 34/45] KVM: ia64: VMM module interfaces Avi Kivity
2008-04-17 9:10 ` [PATCH 35/45] KVM: ia64: Add TLB virtulization support Avi Kivity
2008-04-17 9:10 ` [PATCH 36/45] KVM: ia64: Add interruption vector table for vmm Avi Kivity
2008-04-17 9:10 ` [PATCH 37/45] KVM: ia64: Add mmio decoder for kvm/ia64 Avi Kivity
2008-04-17 9:10 ` [PATCH 38/45] KVM: ia64: Add trampoline for guest/host mode switch Avi Kivity
2008-04-17 9:10 ` [PATCH 39/45] KVM: ia64: Add processor virtulization support Avi Kivity
2008-04-17 9:10 ` [PATCH 40/45] KVM: ia64: Add optimization for some virtulization faults Avi Kivity
2008-04-17 9:10 ` [PATCH 41/45] KVM: ia64: Generate offset values for assembly code use Avi Kivity
2008-04-17 9:10 ` [PATCH 42/45] KVM: ia64: Add guest interruption injection support Avi Kivity
2008-04-17 9:10 ` [PATCH 43/45] KVM: ia64: Add kvm sal/pal virtulization support Avi Kivity
2008-04-17 9:10 ` [PATCH 44/45] KVM: ia64: Enable kvm build for ia64 Avi Kivity
2008-04-17 9:10 ` [PATCH 45/45] KVM: ia64: Add a guide about how to create kvm guests on ia64 Avi Kivity
2008-04-17 15:15 ` Randy Dunlap
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=1208423450-29415-4-git-send-email-avi@qumranet.com \
--to=avi@qumranet.com \
--cc=heiko.carstens@de.ibm.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®