Skip to contentSkip to conversation

This is the security processor driver for the Intel mid platform

PATCH In review Mark Allyn 5 participants 5 messages Jul 8, 2009 – Jul 10, 2009

lore
Share & tools
lore

Mark Allyn

author
#0 lore raw

PATCH 1/1 This is the security processor driver for the Intel mid platform

This is the driver for the Security Processor (SEP) for the Intel MID Platform.

This device driver is used by userspace applications to use the hardware based security processor that is on some Intel Mobile Internet (MID) devices.

This patch is applied against 2.6.31

Signed off my Mark Allyn <[email protected]>

---
 drivers/Kconfig                       |    2 +
 drivers/Makefile                      |    1 +
 drivers/sep/Kconfig                   |    9 +
 drivers/sep/Makefile                  |    3 +
 drivers/sep/sep_driver_api.h          |  544 +++++
 drivers/sep/sep_driver_config.h       |  304 +++
 drivers/sep/sep_driver_ext_api.h      |  105 +
 drivers/sep/sep_driver_hw_defs.h      |  239 ++
 drivers/sep/sep_ext_with_pci_driver.c |  630 ++++++
 drivers/sep/sep_main_mod.c            | 3892 +++++++++++++++++++++++++++++++++
 10 files changed, 5729 insertions(+), 0 deletions(-)
 create mode 100644 drivers/sep/Kconfig
 create mode 100644 drivers/sep/Makefile
 create mode 100644 drivers/sep/sep_driver_api.h
 create mode 100644 drivers/sep/sep_driver_config.h
 create mode 100644 drivers/sep/sep_driver_ext_api.h
 create mode 100644 drivers/sep/sep_driver_hw_defs.h
 create mode 100644 drivers/sep/sep_ext_with_pci_driver.c
 create mode 100644 drivers/sep/sep_main_mod.c
drivers/Kconfig +2 -0
index 48bbdbe..08e8d87 100644
@@ -113,4 +113,6 @@ source "drivers/xen/Kconfig"
 source "drivers/staging/Kconfig"
 
 source "drivers/platform/Kconfig"
+
+source "drivers/sep/Kconfig"
 endmenu
drivers/Makefile +1 -0
index 988d531..935042c 100644
@@ -109,4 +109,5 @@ obj-$(CONFIG_VIRTIO)		+= virtio/
 obj-$(CONFIG_VLYNQ)		+= vlynq/
 obj-$(CONFIG_STAGING)		+= staging/
 obj-y				+= platform/
+obj-$(CONFIG_DX_SEP)            += sep/
 obj-y				+= ieee802154/
drivers/sep/Kconfig new file +9 -0
new file mode 100644
index 0000000..316b79c
@@ -0,0 +1,9 @@
+config DX_SEP
+	tristate "SEP driver"
+	depends on MRST
+	default y
+	help
+	  Security Processor driver
+
+	  If unsure say M. The compiled module will be
+	  called sep_driver.ko
drivers/sep/Makefile new file +3 -0
new file mode 100644
index 0000000..2e0c4cb
@@ -0,0 +1,3 @@
+EXTRA_CFLAGS += -DLITTLE__ENDIAN -DDX_CC5_SEP_PLAT -DCRYS_NO_EXT_IF_MODE_SUPPORT
+obj-$(CONFIG_DX_SEP) := sep_driver.o
+sep_driver-objs := sep_main_mod.o sep_ext_with_pci_driver.o
drivers/sep/sep_driver_api.h new file +544 -0

544 lines not on this page · raw message

drivers/sep/sep_driver_config.h new file +304 -0

304 lines not on this page · raw message

drivers/sep/sep_driver_ext_api.h new file +105 -0

105 lines not on this page · raw message

drivers/sep/sep_driver_hw_defs.h new file +239 -0

239 lines not on this page · raw message

drivers/sep/sep_ext_with_pci_driver.c new file +630 -0

630 lines not on this page · raw message

drivers/sep/sep_main_mod.c new file +3892 -0

1,155 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.6.0.6

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 8 lines · On Wed, 8 Jul 2009 13:01:02 -0700 Mark Allyn <[email protected]> wrote:

This is the driver for the Security Processor (SEP) for the Intel MID Platform.

This device driver is used by userspace applications to use the hardware based security processor that is on some Intel Mobile Internet (MID) devices.

This patch is applied against 2.6.31

Signed off my Mark Allyn <[email protected]>

Something weird seems to have happened to the formatting (at least if it was tab formatted bits of it aren't any more - nasty accident with MS Exchange perhaps ?)

drivers/sep/Kconfig line 2

Quoted 8 lines
drivers/sep/Kconfig new file +2 -0
new file mode 100644
index 0000000..316b79c
@@ -0,0 +1,9 @@
+config DX_SEP
+	tristate "SEP driver"

Whats a SEP ? (I know that but I work for Intel ;)). This needs a longer text and a description that would be useful to more people. The one in your intro text is probably pretty close.

drivers/sep/sep_driver_api.h

Quoted 1 line
drivers/sep/sep_driver_api.h +0 -0

I'll skip over the API and the API related code for the moment. I think that perhaps this should land in staging/sep first ? It's new hardware, new support so would be good to get in soon but it needs lots of cleanup and once its in staging that can be community and Intel done with a fast turnaround. It also needs a rather different API I think (plus wiring into the kernel crypto layer possibly ?)

drivers/sep/sep_driver_api.h

Quoted 5 lines

+++ b/drivers/sep/sep_driver_config.h

drivers/sep/sep_driver_api.h +3 -0
+	the maximum length of the message - the rest of the message shared
+	area will be dedicated to the dma lli tables
+*/

I think we'd assume SIZE_IN_BYTES but if you like typing a lot 8)

drivers/sep/sep_driver_api.h

Quoted 3 lines
drivers/sep/sep_driver_api.h +3 -0
+/* FUNCTIONAL MACROS */
+
+/* debug macro without paramaters */

Use the standard dbg_ macros

drivers/sep/sep_driver_api.h

Quoted 2 lines
drivers/sep/sep_driver_api.h +2 -0
+#define SEP_WRITE_REGISTER(address, value)  writel((value), (void *)(address))
+#define SEP_READ_REGISTER(address, value)  (value) = readl((void *)(address))

All of the I/O registers should be void __iomem *, this allows sparse and other tools to be used to check for bugs.

drivers/sep/sep_driver_ext_api.h

Quoted 4 lines
drivers/sep/sep_driver_ext_api.h new file +1 -0
new file mode 100644
 
+extern int sepDebug;

stylistically we normally use sep_ etc for globals (the rest have done)

Quoted 1 line

+extern unsigned long g_sep_reg_base_address;

no g_ by preference (that seems to be an Intel style characteristing but its not an intel one)

drivers/sep/sep_driver_ext_api.h

Quoted 6 lines

+++ b/drivers/sep/sep_ext_with_pci_driver.c

drivers/sep/sep_driver_ext_api.h new file +3 -0
@@ -0,0 +1,630 @@
 
+static unsigned long CRYS_SEP_ROM[] = {
+	#include "SEP_ROM_image.h"
+};

Firmware interface not compiled in.

Quoted 1 line

+void *io_memory_start_virtual_address;

Not a good name for a global - and to be honest all of this stuff including the IRQ would be better as a single "struct sep_device" or similar that kept all the globals in one struct cleanly. It also saves your backside if you ever have a future system with a two of them.

drivers/sep/sep_driver_ext_api.h

Quoted 2 lines
drivers/sep/sep_driver_ext_api.h new file +2 -0
+/* temporary */
+unsigned long jiffies_future;

????

drivers/sep/sep_driver_ext_api.h

Quoted 2 lines
drivers/sep/sep_driver_ext_api.h new file +2 -0
+static struct pci_device_id sep_pci_id_tbl[] = {
+	{ PCI_DEVICE(VENDOR_ID, 0x080c) },

PCI_VENDOR_ID_INTEL,

Quoted 7 lines
drivers/sep/sep_driver_ext_api.h new file +7 -0
+	{ 0 }
+};
+
+MODULE_DEVICE_TABLE(pci, sep_pci_id_tbl);
+
+static unsigned long    rar_region_addr;
+

drivers/sep/sep_driver_ext_api.h

Quoted 10 lines
drivers/sep/sep_driver_ext_api.h new file +10 -0
+
+/* field for registering driver to PCI device */
+static struct pci_driver sep_pci_driver = {
+	.name = "sep_sec_driver",
+	.id_table = sep_pci_id_tbl,
+	.probe = sep_probe
+};
+
+/* pointer to pci dev received during probe */
+struct pci_dev *sep_pci_dev_ptr;

More global that will get you later.

drivers/sep/sep_driver_ext_api.h

Quoted 5 lines
drivers/sep/sep_driver_ext_api.h new file +5 -0
+/*
+  This functions copies the cache and resident from their source location into
+  destination memory, which is external to Linux VM and is given as
+   physical address
+*/

Kerneldoc format

/**
* sep_copy_cache_etc - does stuff 1 line
* @each arg: what it is
*
* Text
* Text
*/

That way the tools we have can automatically extract documentation

drivers/sep/sep_driver_ext_api.h

Quoted 9 lines
drivers/sep/sep_driver_ext_api.h new file +8 -0
+int sep_copy_cache_resident_to_area(unsigned long   src_cache_addr,
+				unsigned long   cache_size_in_bytes,
+				unsigned long   src_resident_addr,
+				unsigned long   resident_size_in_bytes,
+				unsigned long *dst_new_cache_addr_ptr,
+				unsigned long *dst_new_resident_addr_ptr)
+{
 
+	memcpy((void *)cache_virtual_address, (void *)fw->data, fw->size);

If this is ioremap space as it seems then memcpy_to_io(void __iomem *), ..)

drivers/sep/sep_driver_ext_api.h

Quoted 1 line
drivers/sep/sep_driver_ext_api.h new file +1 -0
+	memcpy((void *)resident_virtual_address, (void *)fw->data, fw->size);

ditto

drivers/sep/sep_driver_ext_api.h

Quoted 3 lines
drivers/sep/sep_driver_ext_api.h new file +3 -0
+	/* physical addresses */
+	*dst_new_cache_addr_ptr = cache_physical_address;
+	*dst_new_resident_addr_ptr = resident_physical_address;

and would also be cleaned up by using a struct to hold all your context and passing it around

drivers/sep/sep_driver_ext_api.h

Quoted 5 lines
drivers/sep/sep_driver_ext_api.h new file +5 -0
+int sep_map_and_alloc_shared_area(unsigned long shared_area_size,
+				unsigned long *kernel_shared_area_addr_ptr,
+				unsigned long *phys_shared_area_addr_ptr)
+{
+	// shared_virtual_address = ioremap_nocache(0xda00000,shared_area_size);

No C++ comments.

drivers/sep/sep_driver_ext_api.h

Quoted 8 lines
drivers/sep/sep_driver_ext_api.h new file +8 -0
+	shared_virtual_address = kmalloc(shared_area_size, GFP_KERNEL);
+	if (!shared_virtual_address) {
+		DEBUG_PRINT_0(SEP_DEBUG_LEVEL_EXTENDED,
+		  "sep_driver:shared memory kmalloc failed\n");
+		return -1;
+	}
+
+	shared_physical_address = __pa(shared_virtual_address);

Ugly.. not sure what the best way to handle that is, but probably to use the dma_ APIs to allocate a coherent region not use kmalloc

drivers/sep/sep_driver_ext_api.h

Quoted 2 lines
drivers/sep/sep_driver_ext_api.h new file +2 -0
+/*
+  function that is activaed on the succesfull probe of the SEP device

Its called when one is found - not neccessarily on "successful" (one l)

drivers/sep/sep_driver_ext_api.h

Quoted 10 lines
drivers/sep/sep_driver_ext_api.h new file +9 -0
+*/
+static int __devinit sep_probe(struct pci_dev *pdev,
+			const struct pci_device_id *ent)
+{
 
+	/* set the pci dev pointer */
+	sep_pci_dev_ptr = pdev;
+
+	/* get the io memory start address */
+	io_memory_start_physical_address = pci_resource_start(pdev, 0);

This demonstrates part of why we don't want globals. A typical Linux driver looks something like

	x = kzalloc(sizeof(struct foo), GFP_KERNEL);
	x->phys_addr = pci_resource_start(pdev, 0);

drivers/sep/sep_driver_ext_api.h

Quoted 2 lines
drivers/sep/sep_driver_ext_api.h new file +2 -0
+	io_memory_size = io_memory_end_physical_address -
+	  io_memory_start_physical_address + 1;

pci_resource_len()

drivers/sep/sep_driver_ext_api.h

Quoted 3 lines
drivers/sep/sep_driver_ext_api.h new file +3 -0
+	io_memory_start_virtual_address =
+	  ioremap_nocache(io_memory_start_physical_address,
+	  io_memory_size);

pci_ioremap_bar()

drivers/sep/sep_driver_ext_api.h

Quoted 1 line
drivers/sep/sep_driver_ext_api.h new file +1 -0
+	g_sep_reg_base_address = (unsigned long)io_memory_start_virtual_address;

More globals we don't need

drivers/sep/sep_driver_ext_api.h

Quoted 12 lines
drivers/sep/sep_driver_ext_api.h new file +12 -0
+	/* set up system base address and shared memory location */
+
+	rar_virtual_address = kmalloc(2 * SEP_RAR_IO_MEM_REGION_SIZE,
+	  GFP_KERNEL);
+
+	if (!rar_virtual_address) {
+		DEBUG_PRINT_0(SEP_DEBUG_LEVEL_EXTENDED,
+		  "SEP Driver:cant kmalloc rar\n");
+		goto end_function;
+		}
+
+	rar_physical_address = __pa(rar_virtual_address);

pci_alloc_coherent

Quoted 1 line

+#if !SEP_DRIVER_POLLING_MODE

Should probably be a separate routine, and any reason why polling mode is compile not runtime selected ?

Quoted 1 line

+end_function:

Various things goto this but don't free the resources they allocated before failing

Quoted 1 line

+void sep_load_rom_code()

void sep_load_rom_code(void)

drivers/sep/sep_driver_ext_api.h

Quoted 2 lines
drivers/sep/sep_driver_ext_api.h new file +2 -0
+{
+#if SEP_DRIVER_ARM_DEBUG_MODE

Probably this lot doesn't belong in the upstream driver

Quoted 9 lines
drivers/sep/sep_main_mod.c +7 -0
 
+/* address of the shared memory allocated during init for SEP driver */
+static unsigned long			g_sep_shared_area_addr;
+
+/* the physical address of the shared area */
+static unsigned long			g_sep_phys_shared_area_addr;
+
+/* Message Shared Area start address - will be allocated during init */

drivers/sep/sep_main_mod.c line 88

Quoted 10 lines
drivers/sep/sep_main_mod.c +10 -0
+static unsigned long			g_message_shared_area_addr;
+
+/* major and minor device numbers */
+static dev_t					g_sep_device_number;
+
+/* the files operations structure of the driver */
+static struct file_operations  g_sep_fops;
+
+/* cdev struct of the driver */
+static struct cdev			g_sep_cdev;

All stuff that belongs in the per device struct

drivers/sep/sep_main_mod.c line 374

Quoted 5 lines
drivers/sep/sep_main_mod.c +5 -0
+  this function locks SEP by locking the semaphore
+*/
+int sep_lock()
+{
+  mutex_lock(&sep_mutex);

Except its a mutex, and it doesn't need wrapping

Quoted 9 lines
drivers/sep/sep_main_mod.c +9 -0
+static int sep_open(struct inode *inode_ptr, struct file *file_ptr)
+{
+  /* return value */
+  int			error;
+
+  /*-----------------
+	CODE
+  ---------------------*/
+

drivers/sep/sep_main_mod.c line 454

Quoted 10 lines
drivers/sep/sep_main_mod.c +10 -0
+  DEBUG_PRINT_0(SEP_DEBUG_LEVEL_BASIC, "SEP Driver:--------> open start\n");
+
+  error = 0;
+
+  /* check the blocking mode */
+  if (g_sep_block_mode_flag)
+	/* lock mutex */
+	mutex_lock(&sep_mutex);
+  else
+	error = mutex_trylock(&sep_mutex);

Blocking mode comes from filp->f_flags O_NDELAY flag.

Also don't use mutexes across returns to user space, it makes life far too interesting for real time people.

I'm not even clear what the goal here is for the mutex ?

drivers/sep/sep_main_mod.c line 543

Quoted 8 lines
drivers/sep/sep_main_mod.c +7 -0
+/*---------------------------------------------------------------
+  map function - this functions maps the message shared area
+-----------------------------------------------------------------*/
+static int sep_mmap(struct file  *filp, struct vm_area_struct  *vma)
+{
 
+  /* get physical address */
+  phys_addr  = g_sep_phys_shared_area_addr;

All of this global stuff needs to go away. Create a single instance of a struct holding the general stuff (which could become an array of pointers in future). Assign the filp->private_data pointer to it in the _open method and it'll begin to look like usual Linux code.

drivers/sep/sep_main_mod.c line 596

Quoted 2 lines
drivers/sep/sep_main_mod.c +2 -0
+	*((unsigned long *)(g_sep_shared_area_addr +
+	SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES + count)));

If that is from the ioremap external memory (its hard to tell as you don't use __iomem anywhere consistently) this needs to be using readl and friends, but I can't tell

drivers/sep/sep_main_mod.c line 624

Quoted 5 lines
drivers/sep/sep_main_mod.c +5 -0
+	for (count = 0; count < 10 * 4; count += 4)
+	DEBUG_PRINT_2(SEP_DEBUG_LEVEL_EXTENDED,
+	"Debug Data Word %lu of the message is %lu\n",
+	count,
+	*((unsigned long *)(g_sep_shared_area_addr + 0x1800 + count)));

What locks poll v write v read v other poll etc ?

Quoted 17 lines
drivers/sep/sep_main_mod.c +16 -0
+/*
+  this function registers the driver to the file system
+*/
+static int  sep_register_driver_to_fs(void)
+{
+  /* return value */
+  int			ret_val;
+
+  /*---------------------
+	CODE
+  -----------------------*/
+
+  ret_val = alloc_chrdev_region(&g_sep_device_number, 0, 1, "sep_sec_driver");
+  if (ret_val) {
+	DEBUG_PRINT_1(SEP_DEBUG_LEVEL_EXTENDED,
+	"sep_driver:major number allocation failed, retval is %d\n", ret_val);

drivers/sep/sep_main_mod.c line 837

Quoted 10 lines
drivers/sep/sep_main_mod.c +10 -0
+	goto end_function;
+  }
+
+  /* set the files operations structure */
+  g_sep_fops.owner = THIS_MODULE;
+  g_sep_fops.ioctl = sep_ioctl;
+  g_sep_fops.poll = sep_poll;
+  g_sep_fops.open = sep_open;
+  g_sep_fops.release = sep_release;
+  g_sep_fops.mmap = sep_mmap;

Could be a static structure which is how must folks do it.

Quoted 1 line

+ iounmap((void *)g_sep_reg_base_address);

again void __iomem *, but if you kept it void __iomem * you could dump all the casting

drivers/sep/sep_main_mod.c line 1054

Quoted 7 lines
drivers/sep/sep_main_mod.c +7 -0
+  /* calculate the total size for de-allocation */
+  size = SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES +
+		SEP_DRIVER_SYNCHRONIC_DMA_TABLES_AREA_SIZE_IN_BYTES +
+		SEP_DRIVER_DATA_POOL_SHARED_AREA_SIZE_IN_BYTES +
+		SEP_DRIVER_FLOW_DMA_TABLES_AREA_SIZE_IN_BYTES +
+		SEP_DRIVER_STATIC_AREA_SIZE_IN_BYTES +
+		SEP_DRIVER_SYSTEM_DATA_MEMORY_SIZE_IN_BYTES;

Why isn't the total size a define ?

drivers/sep/sep_main_mod.c line 1129

Quoted 9 lines
drivers/sep/sep_main_mod.c +8 -0
+  interrupt handler function
+*/
+irqreturn_t sep_inthandler(int irq, void *dev_id)
+{
+  /* int error */
 
+	if (reg_val & (0x1 << 13)) {
+		/* update the counter of reply messages */
+		sep_sep_to_host_reply_counter++;

What locks this v other users callers etc ?

#2 lore raw
Quoted 9 lines · Alan Cox
Quoted 2 lines · On Wed, 8 Jul 2009 13:01:02 -0700 Mark Allyn <[email protected]> wrote:

This is the driver for the Security Processor (SEP) for the Intel MID Platform.

Whats a SEP ? (I know that but I work for Intel ;)). This needs a longer text and a description that would be useful to more people. The one in your intro text is probably pretty close.

Also, please cc the linux-security-module list with security related code, and also possibly the crypto list
(see http://vger.kernel.org/vger-lists.html)

Here's the output of checkpatch.pl with your patch:

total: 15 errors, 29 warnings, 4 checks, 5737 lines checked

The errors need to be fixed or justified; see section 4 of Documentation/SubmittingPatches.

- James

Signature · 2 lines
James Morris
<[email protected]>
#3 lore raw
In reply to Mark Allyn
Quoted 4 lines · Mark Allyn

This is the driver for the Security Processor (SEP) for the Intel MID Platform.

This device driver is used by userspace applications to use the hardware based security processor that is on some Intel Mobile Internet (MID) devices.

This text should probably be repeated...

Quoted 6 lines
drivers/sep/Kconfig new file +0 -0
new file mode 100644
index 0000000..316b79c

drivers/sep/Kconfig line 9

Quoted 9 lines
drivers/sep/Kconfig new file +9 -0
@@ -0,0 +1,9 @@
+config DX_SEP
+	tristate "SEP driver"
+	depends on MRST
+	default y
+	help
+	  Security Processor driver
+
+	  If unsure say M. The compiled module will be
+	  called sep_driver.ko

here, so the poor slob building a kernel has a clue what it's for and whether he wants one.

Also, if you have a link to a datasheet or other info, that would be nice, even if it's just up in the changelog section, so those of us that have never heard of the chipset can get at least a clue how it's supposed to work.

Especially for a 'Security Processor' - it's a *lot* easier to do a code review knowing what the threat model is. If this chipset doesn't even claim to protect against some things, then we don't need to look at those threats. Similarly, if it *does* claim to do X, Y, and Z, we can look at ways those could be subverted.

I'm *guessing* it does accelerated crypto for network connections, but that's based on this one comment:

+/*

+  This function builds input and output DMA tables for synhronic
+  symmetric operations (AES, DES). It also checks that each table
+  is of the modular block size

+*/
+int sep_prepare_input_output_dma_table(unsigned long app_virt_in_addr,

Other comments based on a quick read of the code:

There seems to be a *lot* of memory allocation/deallocation code in here (as in "most of the driver"). Is the chipset design oddball enough that it needs that much marshalling code, and the existing kernel code isn't suitable?

Looks like it does *all* it's locking under one mutex (&sep_mutex). That's certainly *workable*, but I can't tell if the expected activity level of the code is enough that we may want to make it more fine-grained eventually.

I'm sure somebody else will contribute more detailed comments...

#4 lore raw
In reply to Mark Allyn
Quoted 7 lines

+ *
+ * CHANGES:
+ *
+ * 2009.06.26 Initial publish
+ *
+ */

No changelogs in source files, please...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+  /* start address of resident */

Eh?

drivers/sep/sep_driver_api.h line 122

Quoted 7 lines
drivers/sep/sep_driver_api.h new file +6 -0
+  unsigned long   message_size_in_words;
+
+};
 
+struct sep_driver_realloc_cache_resident_t {
+  /* base address */
+  unsigned long   base_addr;

Most useless comment, ever.

drivers/sep/sep_driver_api.h line 128

Quoted 2 lines
drivers/sep/sep_driver_api.h new file +2 -0
+  /* cache size in bytes*/
+  unsigned long   cache_size_in_bytes;

...and more.

drivers/sep/sep_driver_api.h line 143

Quoted 5 lines
drivers/sep/sep_driver_api.h new file +5 -0
+  /* new resident address */
+  unsigned long   new_resident_addr;
+
+  /* new resident address */
+  unsigned long   new_shared_area_addr;

Ouch. Copy & paste error?

drivers/sep/sep_driver_api.h line 146

Quoted 2 lines
drivers/sep/sep_driver_api.h new file +2 -0
+  /* new base address */
+  unsigned long   new_base_addr;

Did they tell you you have to document it, so you did? Bad comments
are worse than no comments...
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html