mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Wright <chrisw@sous-sol.org>
To: linux-kernel@vger.kernel.org
Cc: virtualization@lists.osdl.org, xen-devel@lists.xensource.com,
	Jeremy Fitzhardinge <jeremy@goop.org>, Andi Kleen <ak@suse.de>,
	Andrew Morton <akpm@osdl.org>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Zachary Amsden <zach@vmware.com>,
	Ian Pratt <ian.pratt@xensource.com>,
	Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Subject: [RFC PATCH 11/33] Add Xen-specific memory management definitions
Date: Tue, 18 Jul 2006 00:00:11 -0700	[thread overview]
Message-ID: <20060718091951.253493000@sous-sol.org> (raw)
In-Reply-To: <20060718091807.467468000@sous-sol.org>

[-- Attachment #1: i386-xen-mm --]
[-- Type: text/plain, Size: 5205 bytes --]

Add extra memory management definitions used by Xen-specific
code. These allow conversion between 'pseudophysical' memory
addresses, which provide the illusion of a physically contiguous
memory map, and underlying real machine addresses. This conversion is
neceesary when interpreting and updating PTEs. Also support write
protection of page mappings, which is needed to allow successful
validation of page tables.

The current definitions are incomplete and only a stub implementation,
allowing us to re-use existing code (drivers) which references these
memory management code changes.

Signed-off-by: Ian Pratt <ian.pratt@xensource.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>

---
 arch/i386/mach-xen/Makefile               |    2 
 arch/i386/mach-xen/memory.c               |   31 +++++++++++
 include/asm-i386/mach-default/mach_page.h |    4 +
 include/asm-i386/mach-xen/mach_page.h     |   75 +++++++++++++++++++++++++++++
 include/asm-i386/page.h                   |    2 
 5 files changed, 113 insertions(+), 1 deletion(-)


diff -r 1495c1bc43a1 arch/i386/mach-xen/Makefile
--- a/arch/i386/mach-xen/Makefile	Fri Jun 16 15:45:49 2006 -0700
+++ b/arch/i386/mach-xen/Makefile	Fri Jun 16 15:47:42 2006 -0700
@@ -2,6 +2,6 @@
 # Makefile for the linux kernel.
 #
 
-obj-y				:= setup.o setup-xen.o
+obj-y				:= setup.o setup-xen.o memory.o
 
 setup-y				:= ../mach-default/setup.o
diff -r 1495c1bc43a1 include/asm-i386/page.h
--- a/include/asm-i386/page.h	Fri Jun 16 15:45:49 2006 -0700
+++ b/include/asm-i386/page.h	Fri Jun 16 15:47:42 2006 -0700
@@ -82,6 +82,8 @@ typedef struct { unsigned long pgprot; }
 /* to align the pointer to the (next) page boundary */
 #define PAGE_ALIGN(addr)	(((addr)+PAGE_SIZE-1)&PAGE_MASK)
 
+#include <mach_page.h>
+
 /*
  * This handles the memory map.. We could make this a config
  * option, but too many people screw it up, and too few need
diff -r 1495c1bc43a1 arch/i386/mach-xen/memory.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arch/i386/mach-xen/memory.c	Fri Jun 16 15:47:42 2006 -0700
@@ -0,0 +1,31 @@
+
+#include <linux/stddef.h>
+#include <asm/desc.h>
+#include <asm/hypervisor.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+
+maddr_t arbitrary_virt_to_machine(unsigned long address)
+{
+	pte_t *pte = lookup_address(address);
+	maddr_t m;
+
+	BUG_ON(pte == NULL);
+
+	m = (maddr_t)pte_mfn(*pte) << PAGE_SHIFT;
+	return m | (address & (PAGE_SIZE - 1));
+}
+
+void make_lowmem_page_readonly(unsigned long address, unsigned int feature)
+{
+	pte_t *pte;
+	int rc;
+
+	if (xen_feature(feature))
+		return;
+
+	pte = lookup_address(address);
+	BUG_ON(pte == NULL);
+	rc = HYPERVISOR_update_va_mapping(address, pte_wrprotect(*pte), 0);
+	BUG_ON(rc);
+}
diff -r 1495c1bc43a1 include/asm-i386/mach-default/mach_page.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/asm-i386/mach-default/mach_page.h	Fri Jun 16 15:47:42 2006 -0700
@@ -0,0 +1,4 @@
+#ifndef __ASM_MACH_PAGE_H
+#define __ASM_MACH_PAGE_H
+
+#endif /* __ASM_MACH_PAGE_H */
diff -r 1495c1bc43a1 include/asm-i386/mach-xen/mach_page.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/asm-i386/mach-xen/mach_page.h	Fri Jun 16 15:47:42 2006 -0700
@@ -0,0 +1,75 @@
+#ifndef __ASM_MACH_PAGE_H
+#define __ASM_MACH_PAGE_H
+
+#ifndef __ASSEMBLY__
+
+/**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
+#define INVALID_P2M_ENTRY	(~0UL)
+
+static inline unsigned long pfn_to_mfn(unsigned long pfn)
+{
+#ifndef CONFIG_XEN_SHADOW_MODE
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return pfn;
+	return phys_to_machine_mapping[(unsigned int)(pfn)] &
+		~FOREIGN_FRAME_BIT;
+#else
+	return pfn;
+#endif
+}
+
+static inline unsigned long mfn_to_pfn(unsigned long mfn)
+{
+#ifndef CONFIG_XEN_SHADOW_MODE
+	unsigned long pfn;
+
+	if (xen_feature(XENFEAT_auto_translated_physmap))
+		return mfn;
+
+	/*
+	 * The array access can fail (e.g., device space beyond end of RAM).
+	 * In such cases it doesn't matter what we return (we return garbage),
+	 * but we must handle the fault without crashing!
+	 */
+	asm (
+		"1:	movl %1,%0\n"
+		"2:\n"
+		".section __ex_table,\"a\"\n"
+		"	.align 4\n"
+		"	.long 1b,2b\n"
+		".previous"
+		: "=r" (pfn) : "m" (machine_to_phys_mapping[mfn]) );
+
+	return pfn;
+#else
+	return mfn;
+#endif
+}
+
+/* VIRT <-> MACHINE conversion */
+#define virt_to_machine(v)	(__pa(v))
+#define virt_to_mfn(v)		(pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
+#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
+
+/* Definitions for machine and pseudophysical addresses. */
+#ifdef CONFIG_X86_PAE
+typedef unsigned long long paddr_t;
+typedef unsigned long long maddr_t;
+#else
+typedef unsigned long paddr_t;
+typedef unsigned long maddr_t;
+#endif
+
+#ifndef CONFIG_X86_PAE
+#define pte_mfn(_pte) ((_pte).pte_low >> PAGE_SHIFT)
+#else
+#define pte_mfn(_pte) (((_pte).pte_low >> PAGE_SHIFT) |\
+                       (((_pte).pte_high & 0xfff) << (32-PAGE_SHIFT)))
+#endif
+
+maddr_t arbitrary_virt_to_machine(unsigned long address);
+void make_lowmem_page_readonly(unsigned long address, unsigned int feature);
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __ASM_MACH_PAGE_H */

--

  parent reply	other threads:[~2006-07-18  9:22 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-18  9:18 [RFC PATCH 00/33] Xen i386 paravirtualization support Chris Wright
2006-07-18  7:00 ` [RFC PATCH 01/33] Add apply_to_page_range() function Chris Wright
2006-07-18 10:38   ` Adrian Bunk
2006-07-18 19:29     ` Chris Wright
2006-07-20  6:17       ` Adrian Bunk
2006-07-18  7:00 ` [RFC PATCH 02/33] Add sync bitops Chris Wright
2006-07-18  9:56   ` Arjan van de Ven
2006-07-18 10:18     ` Keir Fraser
2006-07-19 12:54     ` Andi Kleen
2006-07-18 10:34   ` Adrian Bunk
2006-07-18  7:00 ` [RFC PATCH 03/33] Add nosegneg capability to the vsyscall page notes Chris Wright
2006-07-18  7:00 ` [RFC PATCH 04/33] Add XEN config options and disable unsupported config options Chris Wright
2006-07-18  9:59   ` Arjan van de Ven
2006-07-18 10:21     ` Keir Fraser
2006-07-18  7:00 ` [RFC PATCH 05/33] Makefile support to build Xen subarch Chris Wright
2006-07-18 10:00   ` Arjan van de Ven
2006-07-18 11:40     ` Andrew Morton
2006-07-18 20:41       ` Jeremy Fitzhardinge
2006-07-18 20:15     ` Jeremy Fitzhardinge
2006-07-18  7:00 ` [RFC PATCH 06/33] Add Xen interface header files Chris Wright
2006-07-18  7:00 ` [RFC PATCH 07/33] Hypervisor " Chris Wright
2006-07-18  7:00 ` [RFC PATCH 08/33] Add vmlinuz build target Chris Wright
2006-07-18  7:00 ` [RFC PATCH 09/33] Add start-of-day setup hooks to subarch Chris Wright
2006-07-18 10:03   ` Arjan van de Ven
2006-07-18 20:49     ` Jeremy Fitzhardinge
2006-07-20  6:07   ` Adrian Bunk
2006-07-20 12:10     ` Keir Fraser
2006-07-20 13:27       ` Jeremy Fitzhardinge
2006-07-18  7:00 ` [RFC PATCH 10/33] add support for Xen feature queries Chris Wright
2006-07-18  7:00 ` Chris Wright [this message]
2006-07-18  7:00 ` [RFC PATCH 12/33] Change __FIXADDR_TOP to leave room for the hypervisor Chris Wright
2006-07-18  7:00 ` [RFC PATCH 13/33] Add a new head.S start-of-day file for booting on Xen Chris Wright
2006-07-18 10:06   ` Arjan van de Ven
2006-07-18 20:13     ` Jeremy Fitzhardinge
2006-07-18  7:00 ` [RFC PATCH 14/33] subarch support for controlling interrupt delivery Chris Wright
2006-07-18  7:00 ` [RFC PATCH 15/33] move segment checks to subarch Chris Wright
2006-07-18 10:09   ` Arjan van de Ven
2006-07-18 11:28     ` Zachary Amsden
2006-07-18 19:06   ` Rusty Russell
2006-07-18 19:25     ` Chris Wright
2006-07-18 20:00       ` [Xen-devel] " Rusty Russell
2006-07-18  7:00 ` [RFC PATCH 16/33] Add support for Xen to entry.S Chris Wright
2006-07-18 10:11   ` Arjan van de Ven
2006-07-18 20:04     ` Jeremy Fitzhardinge
2006-07-18 19:17   ` Rusty Russell
2006-07-18 20:43     ` Chris Wright
2006-07-18 23:03       ` Jeremy Fitzhardinge
2006-07-19  5:30         ` Chris Wright
2006-07-18  7:00 ` [RFC PATCH 17/33] Support loading an initrd when running on Xen Chris Wright
2006-07-18  7:00 ` [RFC PATCH 18/33] Subarch support for CPUID instruction Chris Wright
2006-07-18 10:14   ` Arjan van de Ven
2006-07-18 10:26     ` Keir Fraser
2006-07-18 10:38       ` Arjan van de Ven
2006-07-18 11:33     ` Zachary Amsden
2006-07-18 20:46       ` David Miller
2006-07-18 21:00         ` Chris Wright
2006-07-18  7:00 ` [RFC PATCH 19/33] Support gdt/idt/ldt handling on Xen Chris Wright
2006-07-18  7:00 ` [RFC PATCH 20/33] subarch support for interrupt and exception gates Chris Wright
2006-07-18  7:00 ` [RFC PATCH 21/33] subarch support for control register accesses Chris Wright
2006-07-18  7:00 ` [RFC PATCH 22/33] subarch stack pointer update Chris Wright
2006-07-18  7:00 ` [RFC PATCH 23/33] subarch TLB support Chris Wright
2006-07-18 20:39   ` David Miller
2006-07-18 21:00     ` Chris Wright
2006-07-18  7:00 ` [RFC PATCH 24/33] Add support for Xen event channels Chris Wright
2006-07-18  7:00 ` [RFC PATCH 25/33] Implement timekeeping for Xen Chris Wright
2006-07-25  2:49   ` john stultz
2006-07-25 20:05     ` Jeremy Fitzhardinge
2006-07-18  7:00 ` [RFC PATCH 26/33] subarch suport for idle loop (NO_IDLE_HZ for Xen) Chris Wright
2006-07-18  7:00 ` [RFC PATCH 27/33] Add the Xen virtual console driver Chris Wright
2006-07-18 10:24   ` Arjan van de Ven
2006-07-18 10:31     ` Keir Fraser
2006-07-27 15:05   ` Hollis Blanchard
2006-07-18  7:00 ` [RFC PATCH 28/33] Add Xen grant table support Chris Wright
2006-07-19 10:04   ` [Xen-devel] " Harry Butterworth
2006-07-25 18:30   ` Hollis Blanchard
2006-07-25 18:45     ` Keir Fraser
2006-07-25 19:06     ` Segher Boessenkool
2006-07-18  7:00 ` [RFC PATCH 29/33] Add Xen driver utility functions Chris Wright
2006-07-18  7:00 ` [RFC PATCH 30/33] Add the Xenbus sysfs and virtual device hotplug driver Chris Wright
2006-07-18  7:00 ` [RFC PATCH 31/33] Add Xen subarch reboot support Chris Wright
2006-07-20  6:16   ` Adrian Bunk
2006-07-18  7:00 ` [RFC PATCH 32/33] Add the Xen virtual network device driver Chris Wright
2006-07-18 10:27   ` Arjan van de Ven
2006-07-18 10:35     ` Keir Fraser
2006-07-18 10:42       ` Arjan van de Ven
2006-07-18 12:18         ` Dave Boutcher
2006-07-18 12:39     ` jamal
2006-07-18 13:08       ` Herbert Xu
2006-07-18 13:25         ` John Haller
2006-07-18 15:22           ` Herbert Xu
2006-07-18 15:44   ` Stephen Hemminger
2006-07-19  3:55     ` Herbert Xu
2006-07-18 20:42   ` David Miller
2006-07-18 21:09     ` Chris Wright
2006-07-18  7:00 ` [RFC PATCH 33/33] Add Xen virtual block " Chris Wright
2006-07-18 10:34   ` Arjan van de Ven
2006-07-18 20:57     ` Jeremy Fitzhardinge
2006-07-18 13:01   ` Dave Boutcher
2006-07-18 16:25     ` Jeff Garzik
2006-07-18 19:28     ` Chris Wright
2006-07-18 21:22     ` Jeremy Fitzhardinge

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=20060718091951.253493000@sous-sol.org \
    --to=chrisw@sous-sol.org \
    --cc=Christian.Limpach@cl.cam.ac.uk \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=ian.pratt@xensource.com \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=virtualization@lists.osdl.org \
    --cc=xen-devel@lists.xensource.com \
    --cc=zach@vmware.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

Powered by JetHome