Skip to contentSkip to conversation

x86: Add IMR support to Quark/Galileo

PATCH Superseded Bryan O'Donoghue 1 participant 2 messages Jan 26, 2015

Subsystems (2)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover x86: Add IMR support to Quark/Galileo

This patchset adds support for Isolated Memory Regions to the kernel.

Quark SoC X1000 contains a set of registers called Isolated Memory Regions. IMRs provide fine grained memory access control to various system agents within the SoC such as CPU SMM/non-SMM mode, PCIe virtual channels, CPU snoop cycles, eSRAM flush cycles and the RMU. In simple terms, IMRs provide a mechanism to protect memory regions from unwarranted access by system agents that should not have access to that memory.

IMRs support a lock bit. Once a lock bit is set for an individual IMR it is not possible to tear down that IMR without performing a cold boot of the system. IMRs support reporting of violations. The SoC system can be configured to reboot immediately when an IMR violation has taken place. Immediate reboot of the system on IMR violation is recommended and is currently how Quark BIOS configures the system.

An example of IMRs in use is given with Arduino compatiable Galileo boards which ship with an IMR around the ACPI runtime services memory. If a DMA read/write cycle were to occur to this region of memory this would trigger the IMR violation mechansim.

As part of the IMR init code all unlocked IMRs are removed to ensure the EFI memory map and IMR memory map are consistent. This is necessary since at various stages during the boot of Quark systems firmware and second stage bootloader will place unlocked IMRs around various assets in memory, with the expectation that subsequent phases of boot will tear-down unlocked/stale IMRs before proceeding. The kernel needs to tear-down unlocked IMRs placed around the boot params structure and compressed kernel in memory. Without doing so DMA addresses given out by the kernel to DMA capable hardware runs the risk of triggering an IMR fault when DMA happens to those addresses. As a result any unlocked IMR must be torn down by the kernel early in the boot process to sanitize the memory map.

As an additional protection to the run-time kernel from unwarranted memory transactions an IMR is placed around the kernel's .text and .rodata sections.

Changes since v3:
- Remove reference to imr.o in arch/x86/kernel/Makefile Bryan O'Donoghue

Changes since v2:
- Move IMR code to arch/x86/platform/intel-quark/imr.c
Thomas Gleixner/Darren Hart
- #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Andy Shevchenko
- ret = iosf_mbi_read()
Style made consistent in imr_write
Andy Shevchenko
- reg++/IMR_NUM_REGS
Offset used for lock bit in imr_write
Andy Shevchenko
- debugfs s->private pointer used
Andy Shevchenko
- debugfs
Conditional compilation defines removed
Andy Shevchenko
- debugfs
Failure to hook debugfs treated as non-fatal
Andy Shevchenko
- phys_addr_t
Updated API to use phys_addr_t in place of unsigned long for base param Andy Shevchenko
- printk
"KiB" instead of "k"
Andy Shevchenko
- imr_enabled
-> static inline imr_is_enabled
Ong, Boon Leong/Andy Shevchenko
- imr_write
trap final ret from iosf_mbi_write for lock bit in imr_write - bugfix Ong, Boon Leong
- imr_fixup_size
-> static inline imr_fixup_size
Ong, Boon Leong
- imr_address_overlap
-> imr_address_overlap
Ong, Boon Leong
- imr_add_range
End address in imr_add_range calculated after imr_fixup_size() Ong, Boon Leong
- imr_del_range
Pass i in place of reg in imr_del_range() - bugfix
Ong, Boon Leong
- Add test case
imr_del_range(-1, addr, size)
Ong, Boon Leong/Andy Shevchenko
- Added text "aligned to 1 KiB" removed reference to "4 k"
Ong, Boon Leong
- imr_is_enabled
Definition of enabled updated to be negation of disabled
Bryan O'Donoghue
- imr_add_range
Add check for adding an IMR in the disabled state
Bryan O'Donoghue
- Add test case IMR @ invalid address, @0 with rmask/wmask=CPU, @ 0 size 0x800 Bryan O'Donoghue
- Add WARN() to failed IMR test in print routine
Bryan O'Donoghue
- Update license to Dual BSD/GPL
Reflect licensing in Intel reference code
Bryan O'Donoghue

Changes since v1:
- Galileo platform code
Removed completely. Policy to tear-down unlocked IMRs and setup IMR around kernel .text and .rodata as part of IMR init code. Darren Hart/Ong, Boon Leong
- imr_add/imr_del
Renamed to imr_add_range and imr_del_range respectively. Andy Shevchenko
- x86_match_cpu
Used in place of DMI strings specific to Galileo.
Andy Shevchenko/Ong, Boon Leong
- Expanded git log definitions of IMRs
Addition of more descriptive text to deliniate between different IMR types.
Ong, Boon Leong
- struct imr
Renamed to struct imr_regs
Andy Shevchenko/Darren Hart
- imr_read/imr_write
Flow reworked flow of register indexing
Andy Shevchenko
- debugfs hooks changed
Andy Shevchenko
- imr_enabled
Definition of an enabled IMR updated to include read/write mask values present in IMR. Address @ zero and read/write mask in conjunction will be the definition of a disabled IMR on X1000 to be consistent with firmware both old and current which also defines a disabled IMR this way.
Darren Hart/Ong, Boon Leong
- Overlapping
Comment added to code to explain the design decision not to allow IMR overlaps.
Darren Hart/Ong, Boon Leong
- CONFIG_DEBUG_IMR_SELFTEST
Automated IMR self test moved from removed Galileo platform code and added to IMR init code. Option exists in the kernel hacking section. Darren Hart
- IMR self test
Expanded to over more scenarios
Bryan O'Donoghue
- Remove reference to IMR_ENABLE bit
Undocumented bit with respect to Quark X1000
Ong, Boon Leong
- Expanded kernel IMR to encompass .text and .rodata
IMR protecting both .text and .rodata as in the same way as .text and .rodata are marked read-only in the relevant page-table entries. Bryan O'Donoghue
- Overlap bounds checking
Moved range checking of overlap into a function
Andy Shevchenko

Bryan O'Donoghue (1):
x86: Add Isolated Memory Regions for Quark X1000

 arch/x86/Kconfig                       |  15 +
 arch/x86/Kconfig.debug                 |  12 +
 arch/x86/include/asm/imr.h             |  60 +++
 arch/x86/platform/Makefile             |   1 +
 arch/x86/platform/intel-quark/Makefile |   1 +
 arch/x86/platform/intel-quark/imr.c    | 713 +++++++++++++++++++++++++++++++++
 drivers/platform/x86/Kconfig           |  25 ++
 7 files changed, 827 insertions(+)
 create mode 100644 arch/x86/include/asm/imr.h
 create mode 100644 arch/x86/platform/intel-quark/Makefile
 create mode 100644 arch/x86/platform/intel-quark/imr.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 1/1 x86: Add Isolated Memory Regions for Quark X1000

Intel's Quark X1000 SoC contains a set of registers called Isolated Memory Regions. IMRs are accessed over the IOSF mailbox interface. IMRs are areas carved out of memory that define read/write access rights to the various system agents within the Quark system. For a given agent in the system it is possible to specify if that agent may read or write an area of memory defined by an IMR with a granularity of 1 KiB.

Quark_SecureBootPRM_330234_001.pdf section 4.5 details the concept of IMRs quark-x1000-datasheet.pdf section 12.7.4 details the implementation of IMRs in silicon.

eSRAM flush, CPU Snoop write-only, CPU SMM Mode, CPU non-SMM mode, RMU and PCIe Virtual Channels (VC0 and VC1) can have individual read/write access masks applied to them for a given memory region in Quark X1000. This enables IMRs to treat each memory transaction type listed above on an individual basis and to filter appropriately based on the IMR access mask for the memory region. Quark supports eight IMRs.

Since all of the DMA capable SoC components in the X1000 are mapped to VC0 it is possible to define sections of memory as invalid for DMA write operations originating from Ethernet, USB, SD and any other DMA capable south-cluster component on VC0. Similarly it is possible to mark kernel memory as non-SMM mode read/write only or to mark BIOS runtime memory as SMM mode accessible only depending on the particular memory footprint on a given system.

On an IMR violation Quark SoC X1000 systems are configured to reset the system, so ensuring that the IMR memory map is consistent with the EFI provided memory map is critical to ensure no IMR violations reset the system.

The API for accessing IMRs is based on MTRR code but doesn't provide a /proc or /sys interface to manipulate IMRs. Defining the size and extent of IMRs is exclusively the domain of in-kernel code.

Quark firmware sets up a series of locked IMRs around pieces of memory that firmware owns such as ACPI runtime data. During boot a series of unlocked IMRs are placed around items in memory to guarantee no DMA modification of those items can take place. Grub also places an unlocked IMR around the kernel boot params data structure and compressed kernel image. It is necessary for the kernel to tear down all unlocked IMRs in order to ensure that the kernel's view of memory passed via the EFI memory map is consistent with the IMR memory map. Without tearing down all unlocked IMRs on boot transitory IMRs such as those used to protect the compressed kernel image will cause IMR violations and system reboots.

The IMR init code tears down all unlocked IMRs and sets a protective IMR around the kernel .text and .rodata as one contiguous block. This sanitizes the IMR memory map with respect to the EFI memory map and protects the read-only portions of the kernel from unwarranted DMA access.

---
 arch/x86/Kconfig                       |  15 +
 arch/x86/Kconfig.debug                 |  12 +
 arch/x86/include/asm/imr.h             |  60 +++
 arch/x86/platform/Makefile             |   1 +
 arch/x86/platform/intel-quark/Makefile |   1 +
 arch/x86/platform/intel-quark/imr.c    | 713 +++++++++++++++++++++++++++++++++
 drivers/platform/x86/Kconfig           |  25 ++
 7 files changed, 827 insertions(+)
 create mode 100644 arch/x86/include/asm/imr.h
 create mode 100644 arch/x86/platform/intel-quark/Makefile
 create mode 100644 arch/x86/platform/intel-quark/imr.c
arch/x86/Kconfig +15 -0
index 0dc9d01..e186716 100644
@@ -485,6 +485,21 @@ config X86_INTEL_MID
 	  Intel MID platforms are based on an Intel processor and chipset which
 	  consume less power than most of the x86 derivatives.
 
+config X86_INTEL_QUARK
+	bool "Intel Quark platform support"
+	depends on X86_32
+	depends on X86_EXTENDED_PLATFORM
+	depends on X86_PLATFORM_DEVICES
+	depends on PCI
+	depends on PCI_GOANY
+	depends on X86_IO_APIC
+	select IOSF_MBI
+	select INTEL_IMR
+	---help---
+	  Select to include support for Quark X1000 SoC.
+	  Say Y here if you have a Quark based system such as the Arduino
+	  compatible Intel Galileo.
+
 config X86_INTEL_LPSS
 	bool "Intel Low Power Subsystem Support"
 	depends on ACPI
arch/x86/Kconfig.debug +12 -0
index 61bd2ad..fcf5701 100644
@@ -313,6 +313,18 @@ config DEBUG_NMI_SELFTEST
 
 	  If unsure, say N.
 
+config DEBUG_IMR_SELFTEST
+	bool "Isolated Memory Region self test"
+	default n
+	depends on INTEL_IMR
+	---help---
+	  This option enables automated sanity testing of the IMR code.
+	  Some simple tests are run to verify IMR bounds checking, alignment
+	  and overlapping. This option is really only useful if you are
+	  debugging an IMR memory map or are modifying the IMR code and want to
+	  test your changes.
+
+	  If unsure say N here.
 config X86_DEBUG_STATIC_CPU_HAS
 	bool "Debug alternatives"
 	depends on DEBUG_KERNEL
arch/x86/include/asm/imr.h new file +60 -0

60 lines not on this page · raw message

arch/x86/platform/Makefile +1 -0
index 85afde1..a62e0be 100644
@@ -5,6 +5,7 @@ obj-y	+= geode/
 obj-y	+= goldfish/
 obj-y	+= iris/
 obj-y	+= intel-mid/
+obj-y	+= intel-quark/
 obj-y	+= olpc/
 obj-y	+= scx200/
 obj-y	+= sfi/
arch/x86/platform/intel-quark/Makefile new file +1 -0
new file mode 100644
index 0000000..3180df5
@@ -0,0 +1 @@
+obj-$(CONFIG_INTEL_IMR) += imr.o
arch/x86/platform/intel-quark/imr.c new file +713 -0

713 lines not on this page · raw message

drivers/platform/x86/Kconfig +25 -0
index 638e7970..9752761 100644
@@ -735,6 +735,31 @@ config INTEL_IPS
 	  functionality.  If in doubt, say Y here; it will only load on
 	  supported platforms.
 
+config INTEL_IMR
+	bool "Intel Isolated Memory Region support"
+	default n
+	depends on X86_INTEL_QUARK && IOSF_MBI
+	---help---
+	  This option provides a means to manipulate Isolated Memory Regions.
+	  IMRs are a set of registers that define read and write access masks
+	  to prohibit certain system agents from accessing memory with 1 KiB
+	  granularity.
+
+	  IMRs make it possible to control read/write access to an address
+	  by hardware agents inside the SoC. Read and write masks can be
+	  defined for:
+		- eSRAM flush
+		- Dirty CPU snoop (write only)
+		- RMU access
+		- PCI Virtual Channel 0/Virtual Channel 1
+		- SMM mode
+		- Non SMM mode
+
+	  Quark contains a set of eight IMR registers and makes use of those
+	  registers during its bootup process.
+
+	  If you are running on a Galileo/Quark say Y here.
+
 config IBM_RTL
 	tristate "Device driver to enable PRTL support"
 	depends on X86 && PCI
Signature · 1 line
1.9.1