[PATCH v8 0/2] dm: boot a mapped device without an initramfs

2017-05-19 Thread Enric Balletbo i Serra
Dear all,

So here is a new version of the patches to be reviewed, this time as
suggested by Alasdair the patches are reworked to match with the new
dmsetup bootformat feature [1]. These patches are not reviewed yet but
the format was discussed in the IRC and was suggested to send the
kernel patches in parallel.

Changes since v7:
 - Fix build error due commit
e516db4f67 (dm ioctl: add a new DM_DEV_ARM_POLL ioctl)

Changes since v6:
 - Add a new function to issue the equivalent of a DM ioctl programatically.
 - Use the new ioctl interface to create the devices.
 - Use a comma-delimited and semi-colon delimited dmsetup-like commands.

Changes since v5:
 - https://www.redhat.com/archives/dm-devel/2016-February/msg00112.html

[1] https://www.redhat.com/archives/linux-lvm/2017-May/msg00047.html

Wating for your feedback,

Enric Balletbo i Serra (1):
  dm ioctl: add a device mapper ioctl function.

Will Drewry (1):
  init: add support to directly boot to a mapped device

 Documentation/admin-guide/kernel-parameters.rst |   1 +
 Documentation/admin-guide/kernel-parameters.txt |   3 +
 Documentation/device-mapper/dm-boot.txt |  65 
 drivers/md/dm-ioctl.c   |  50 +++
 include/linux/device-mapper.h   |   6 +
 init/Makefile   |   1 +
 init/do_mounts.c|   1 +
 init/do_mounts.h|  10 +
 init/do_mounts_dm.c | 459 
 9 files changed, 596 insertions(+)
 create mode 100644 Documentation/device-mapper/dm-boot.txt
 create mode 100644 init/do_mounts_dm.c

-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 2/2] dm ioctl: add a device mapper ioctl function.

2017-05-19 Thread Enric Balletbo i Serra
Add a dm_ioctl_cmd to issue the equivalent of a DM ioctl call in kernel.

Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
 drivers/md/dm-ioctl.c | 50 +++
 include/linux/device-mapper.h |  6 ++
 2 files changed, 56 insertions(+)

diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index d45c681..033e31d 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -2011,3 +2011,53 @@ int dm_copy_name_and_uuid(struct mapped_device *md, char 
*name, char *uuid)
 
return r;
 }
+
+/**
+ * dm_ioctl_cmd - Device mapper ioctl's
+ * @command: ioctl command
+ * @param: Pointer to device mapped ioctl struct
+ */
+int dm_ioctl_cmd(uint command, struct dm_ioctl *param)
+{
+   int r = 0;
+   int ioctl_flags;
+   unsigned int cmd;
+   ioctl_fn fn = NULL;
+   size_t input_param_size;
+   struct file *filp = NULL;
+
+   if (_IOC_TYPE(command) != DM_IOCTL)
+   return -ENOTTY;
+
+   /* DM_DEV_ARM_POLL is not supported */
+   if (command == DM_DEV_ARM_POLL)
+   return -EINVAL;
+
+   cmd = _IOC_NR(command);
+
+   /*
+* Nothing more to do for the version command.
+*/
+   if (cmd == DM_VERSION_CMD)
+   return 0;
+
+   fn = lookup_ioctl(cmd, _flags);
+   if (!fn) {
+   DMWARN("dm_ioctl: unknown command 0x%x", command);
+   return -ENOTTY;
+   }
+
+   input_param_size = param->data_size;
+   r = validate_params(cmd, param);
+   if (r)
+   return r;
+
+   param->data_size = sizeof(*param);
+   r = fn(filp, param, input_param_size);
+
+   if (unlikely(param->flags & DM_BUFFER_FULL_FLAG) &&
+   unlikely(ioctl_flags & IOCTL_FLAGS_NO_PARAMS))
+   DMERR("ioctl %d tried to output some data but has 
IOCTL_FLAGS_NO_PARAMS set", cmd);
+
+   return r;
+}
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index f4c639c..f81ba42 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct dm_dev;
 struct dm_target;
@@ -446,6 +447,11 @@ int dm_noflush_suspending(struct dm_target *ti);
 void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors);
 union map_info *dm_get_rq_mapinfo(struct request *rq);
 
+/*
+ * Device mapper ioctl function.
+ */
+int dm_ioctl_cmd(unsigned int command, struct dm_ioctl *param);
+
 struct queue_limits *dm_get_queue_limits(struct mapped_device *md);
 
 /*
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 1/2] init: add support to directly boot to a mapped device

2017-05-19 Thread Enric Balletbo i Serra
From: Will Drewry <w...@chromium.org>

Add a dm= kernel parameter modeled after the md= parameter from
do_mounts_md. It allows for device-mapper targets to be configured at
boot time for use early in the boot process (as the root device or
otherwise).

Signed-off-by: Will Drewry <w...@chromium.org>
Signed-off-by: Kees Cook <keesc...@chromium.org>
[rework to use dm_ioctl calls]
Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
 Documentation/admin-guide/kernel-parameters.rst |   1 +
 Documentation/admin-guide/kernel-parameters.txt |   3 +
 Documentation/device-mapper/dm-boot.txt |  65 
 init/Makefile   |   1 +
 init/do_mounts.c|   1 +
 init/do_mounts.h|  10 +
 init/do_mounts_dm.c | 459 
 7 files changed, 540 insertions(+)
 create mode 100644 Documentation/device-mapper/dm-boot.txt
 create mode 100644 init/do_mounts_dm.c

diff --git a/Documentation/admin-guide/kernel-parameters.rst 
b/Documentation/admin-guide/kernel-parameters.rst
index d76ab39..5301f45 100644
--- a/Documentation/admin-guide/kernel-parameters.rst
+++ b/Documentation/admin-guide/kernel-parameters.rst
@@ -92,6 +92,7 @@ parameter is applicable::
BLACKFIN Blackfin architecture is enabled.
CLK Common clock infrastructure is enabled.
CMA Contiguous Memory Area support is enabled.
+   DM  Device mapper support is enabled.
DRM Direct Rendering Management support is enabled.
DYNAMIC_DEBUG Build in debug messages and enable them at runtime
EDD BIOS Enhanced Disk Drive Services (EDD) is enabled
diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index f85bfe0..0ea65c2 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -829,6 +829,9 @@
 
dis_ucode_ldr   [X86] Disable the microcode loader.
 
+   dm= [DM] Allows early creation of a device-mapper device.
+   See Documentation/device-mapper/boot.txt.
+
dma_debug=off   If the kernel is compiled with DMA_API_DEBUG support,
this option disables the debugging code at boot.
 
diff --git a/Documentation/device-mapper/dm-boot.txt 
b/Documentation/device-mapper/dm-boot.txt
new file mode 100644
index 000..50f08ec
--- /dev/null
+++ b/Documentation/device-mapper/dm-boot.txt
@@ -0,0 +1,65 @@
+Boot time creation of mapped devices
+
+
+It is possible to configure a device mapper device to act as the root
+device for your system in two ways.
+
+The first is to build an initial ramdisk which boots to a minimal
+userspace which configures the device, then pivot_root(8) in to it.
+
+The second is to possible when the device-mapper and any targets are
+compiled into the kernel (not a module), one or more device-mappers may
+be created and used as the root device at boot time with the parameters
+given with the boot line dm=...
+
+The format is specified as a simple string of data separated by commas and
+optionally semi-colons, where:
+ - a comma is used to separate fields like name, uuid, flags and table 
(specifies
+   one device)
+ - a semi-colon is used to separate devices.
+
+So the format will look like this:
+
+ 
dm=,,,[,+][;,,,[,+]]+
+
+Where,
+ ::= The device name.
+ ::= ---- | ""
+::= "ro" | "rw"
+::=
+ ::= "verity" | "bootcache" | ...
+
+The dm line may be as normal when using the dmsetup tool when using the
+--bootformat argument.
+
+Unless renamed by udev, the device node created will be dm-0 as the
+first minor number for the device-mapper is used during early creation.
+
+Examples
+
+An example of booting to a linear array made up of user-mode linux block
+devices:
+
+  dm="lroot,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" \
+  root=/dev/dm-0
+
+This will boot to a rw dm-linear target of 8192 sectors split across two
+block devices identified by their major:minor numbers.  After boot, udev
+will rename this target to /dev/mapper/lroot (depending on the rules).
+No uuid was assigned.
+
+An example of multiple device-mappers, with the dm="..." contents shown
+here split on multiple lines for readability:
+
+vboot,,ro,
+  0 1768000 bootcache
+aa55b119-2a47-8c45-946a-5ac57765011f+1
+76e9be054b15884a9fa85973e9cb274c93afadb6
+1768000 10 23 2;
+vroot,,ro,
+  0 1740800 verity 254:0 254:0 1740800 sha1
+76e9be054b15884a9fa85973e9cb274c93afadb6
+5b3549d54d6c7a3837b9b81ed72e49463a64c03680c47835bef94d768e5646fe;
+vram,,rw,
+  0 32768 linear 1

[PATCH v7 2/2] dm ioctl: add a device mapper ioctl function.

2017-05-18 Thread Enric Balletbo i Serra
Add a dm_ioctl_cmd to issue the equivalent of a DM ioctl call in kernel.

Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
 drivers/md/dm-ioctl.c | 45 +++
 include/linux/device-mapper.h |  6 ++
 2 files changed, 51 insertions(+)

diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 4951bf9..d79a41a 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1954,3 +1954,48 @@ int dm_copy_name_and_uuid(struct mapped_device *md, char 
*name, char *uuid)
 
return r;
 }
+
+/**
+ * dm_ioctl_cmd - Device mapper ioctl's
+ * @command: ioctl command
+ * @param: Pointer to device mapped ioctl struct
+ */
+int dm_ioctl_cmd(uint command, struct dm_ioctl *param)
+{
+   int r = 0;
+   int ioctl_flags;
+   unsigned int cmd;
+   ioctl_fn fn = NULL;
+   size_t input_param_size;
+
+   if (_IOC_TYPE(command) != DM_IOCTL)
+   return -ENOTTY;
+
+   cmd = _IOC_NR(command);
+
+   /*
+* Nothing more to do for the version command.
+*/
+   if (cmd == DM_VERSION_CMD)
+   return 0;
+
+   fn = lookup_ioctl(cmd, _flags);
+   if (!fn) {
+   DMWARN("dm_ioctl: unknown command 0x%x", command);
+   return -ENOTTY;
+   }
+
+   input_param_size = param->data_size;
+   r = validate_params(cmd, param);
+   if (r)
+   return r;
+
+   param->data_size = sizeof(*param);
+   r = fn(param, input_param_size);
+
+   if (unlikely(param->flags & DM_BUFFER_FULL_FLAG) &&
+   unlikely(ioctl_flags & IOCTL_FLAGS_NO_PARAMS))
+   DMERR("ioctl %d tried to output some data but has 
IOCTL_FLAGS_NO_PARAMS set", cmd);
+
+   return r;
+}
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index 81272c8..efa83ff 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct dm_dev;
 struct dm_target;
@@ -444,6 +445,11 @@ int dm_noflush_suspending(struct dm_target *ti);
 void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors);
 union map_info *dm_get_rq_mapinfo(struct request *rq);
 
+/*
+ * Device mapper ioctl function.
+ */
+int dm_ioctl_cmd(unsigned int command, struct dm_ioctl *param);
+
 struct queue_limits *dm_get_queue_limits(struct mapped_device *md);
 
 /*
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 1/2] init: add support to directly boot to a mapped device

2017-05-18 Thread Enric Balletbo i Serra
From: Will Drewry <w...@chromium.org>

Add a dm= kernel parameter modeled after the md= parameter from
do_mounts_md. It allows for device-mapper targets to be configured at
boot time for use early in the boot process (as the root device or
otherwise).

Signed-off-by: Will Drewry <w...@chromium.org>
Signed-off-by: Kees Cook <keesc...@chromium.org>
[rework to use dm_ioctl calls]
Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
 Documentation/admin-guide/kernel-parameters.rst |   1 +
 Documentation/admin-guide/kernel-parameters.txt |   3 +
 Documentation/device-mapper/dm-boot.txt |  65 
 init/Makefile   |   1 +
 init/do_mounts.c|   1 +
 init/do_mounts.h|  10 +
 init/do_mounts_dm.c | 459 
 7 files changed, 540 insertions(+)
 create mode 100644 Documentation/device-mapper/dm-boot.txt
 create mode 100644 init/do_mounts_dm.c

diff --git a/Documentation/admin-guide/kernel-parameters.rst 
b/Documentation/admin-guide/kernel-parameters.rst
index 33b90e27..9de2984 100644
--- a/Documentation/admin-guide/kernel-parameters.rst
+++ b/Documentation/admin-guide/kernel-parameters.rst
@@ -93,6 +93,7 @@ parameter is applicable::
BLACKFIN Blackfin architecture is enabled.
CLK Common clock infrastructure is enabled.
CMA Contiguous Memory Area support is enabled.
+   DM  Device mapper support is enabled.
DRM Direct Rendering Management support is enabled.
DYNAMIC_DEBUG Build in debug messages and enable them at runtime
EDD BIOS Enhanced Disk Drive Services (EDD) is enabled
diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 33a3b54..4415254 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -830,6 +830,9 @@
 
dis_ucode_ldr   [X86] Disable the microcode loader.
 
+   dm= [DM] Allows early creation of a device-mapper device.
+   See Documentation/device-mapper/boot.txt.
+
dma_debug=off   If the kernel is compiled with DMA_API_DEBUG support,
this option disables the debugging code at boot.
 
diff --git a/Documentation/device-mapper/dm-boot.txt 
b/Documentation/device-mapper/dm-boot.txt
new file mode 100644
index 000..50f08ec
--- /dev/null
+++ b/Documentation/device-mapper/dm-boot.txt
@@ -0,0 +1,65 @@
+Boot time creation of mapped devices
+
+
+It is possible to configure a device mapper device to act as the root
+device for your system in two ways.
+
+The first is to build an initial ramdisk which boots to a minimal
+userspace which configures the device, then pivot_root(8) in to it.
+
+The second is to possible when the device-mapper and any targets are
+compiled into the kernel (not a module), one or more device-mappers may
+be created and used as the root device at boot time with the parameters
+given with the boot line dm=...
+
+The format is specified as a simple string of data separated by commas and
+optionally semi-colons, where:
+ - a comma is used to separate fields like name, uuid, flags and table 
(specifies
+   one device)
+ - a semi-colon is used to separate devices.
+
+So the format will look like this:
+
+ 
dm=,,,[,+][;,,,[,+]]+
+
+Where,
+ ::= The device name.
+ ::= ---- | ""
+::= "ro" | "rw"
+::=
+ ::= "verity" | "bootcache" | ...
+
+The dm line may be as normal when using the dmsetup tool when using the
+--bootformat argument.
+
+Unless renamed by udev, the device node created will be dm-0 as the
+first minor number for the device-mapper is used during early creation.
+
+Examples
+
+An example of booting to a linear array made up of user-mode linux block
+devices:
+
+  dm="lroot,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" \
+  root=/dev/dm-0
+
+This will boot to a rw dm-linear target of 8192 sectors split across two
+block devices identified by their major:minor numbers.  After boot, udev
+will rename this target to /dev/mapper/lroot (depending on the rules).
+No uuid was assigned.
+
+An example of multiple device-mappers, with the dm="..." contents shown
+here split on multiple lines for readability:
+
+vboot,,ro,
+  0 1768000 bootcache
+aa55b119-2a47-8c45-946a-5ac57765011f+1
+76e9be054b15884a9fa85973e9cb274c93afadb6
+1768000 10 23 2;
+vroot,,ro,
+  0 1740800 verity 254:0 254:0 1740800 sha1
+76e9be054b15884a9fa85973e9cb274c93afadb6
+5b3549d54d6c7a3837b9b81ed72e49463a64c03680c47835bef94d768e5646fe;
+vram,,rw,
+  0 32768 linear 1

[PATCH v6 1/3] dm: make some mapped_device functions available

2017-04-18 Thread Enric Balletbo i Serra
From: Brian Norris <briannor...@chromium.org>

For init to build a mapped_device, it must hold the appropriate locks,
able to use dm_table_destroy() and the functions to get/set the md
type, so move these to the common header.

Signed-off-by: Brian Norris <briannor...@chromium.org>
Signed-off-by: Kees Cook <keesc...@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
v6: added more functions required
v5: first version of this specific patch in the series
---
 drivers/md/dm.h   |  8 
 include/linux/device-mapper.h | 13 +
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index f298b01..6b501b5 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -48,7 +48,6 @@ struct dm_md_mempools;
 /*-
  * Internal table functions.
  *---*/
-void dm_table_destroy(struct dm_table *t);
 void dm_table_event_callback(struct dm_table *t,
 void (*fn)(void *), void *context);
 struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index);
@@ -64,7 +63,6 @@ void dm_table_presuspend_undo_targets(struct dm_table *t);
 void dm_table_postsuspend_targets(struct dm_table *t);
 int dm_table_resume_targets(struct dm_table *t);
 int dm_table_any_congested(struct dm_table *t, int bdi_bits);
-unsigned dm_table_get_type(struct dm_table *t);
 struct target_type *dm_table_get_immutable_target_type(struct dm_table *t);
 struct dm_target *dm_table_get_immutable_target(struct dm_table *t);
 struct dm_target *dm_table_get_wildcard_target(struct dm_table *t);
@@ -74,14 +72,8 @@ bool dm_table_all_blk_mq_devices(struct dm_table *t);
 void dm_table_free_md_mempools(struct dm_table *t);
 struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t);
 
-void dm_lock_md_type(struct mapped_device *md);
-void dm_unlock_md_type(struct mapped_device *md);
-void dm_set_md_type(struct mapped_device *md, unsigned type);
-unsigned dm_get_md_type(struct mapped_device *md);
 struct target_type *dm_get_immutable_target_type(struct mapped_device *md);
 
-int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t);
-
 /*
  * To check the return value from dm_table_find_target().
  */
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index b7ab76e..9f70b21 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -479,6 +479,11 @@ void dm_table_set_type(struct dm_table *t, unsigned type);
 int dm_table_complete(struct dm_table *t);
 
 /*
+ * Destroy the table when finished.
+ */
+void dm_table_destroy(struct dm_table *t);
+
+/*
  * Target may require that it is never sent I/O larger than len.
  */
 int __must_check dm_set_target_max_io_len(struct dm_target *ti, sector_t len);
@@ -515,6 +520,14 @@ void dm_table_run_md_queue_async(struct dm_table *t);
 struct dm_table *dm_swap_table(struct mapped_device *md,
   struct dm_table *t);
 
+unsigned dm_table_get_type(struct dm_table *t);
+
+void dm_lock_md_type(struct mapped_device *md);
+void dm_unlock_md_type(struct mapped_device *md);
+void dm_set_md_type(struct mapped_device *md, unsigned type);
+unsigned dm_get_md_type(struct mapped_device *md);
+int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t);
+
 /*
  * A wrapper around vmalloc.
  */
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 0/3] dm: boot a mapped device without an initramfs

2017-04-18 Thread Enric Balletbo i Serra
Hello,

Some of these patches were send few years back, I saw that first
version was send to this list in 2010, and after version 4 did not
land [1]. Some days ago I resend the patches [2] and few hours later I
noticed that one year ago was send a v5 version [3] and I was not aware.

There was some discussion about v5 and during the discussion Mike Snitzer
proposed that at least a change of the syntax is required, we're really
interested on see this upstream as is extensively used in ChromeOS based
devices so I'm wondering if we can restart the discussion and hopefully
we will be able to do the modifications needed.

So my first question is, apart of the change of the syntax, what more
should be changed?

Thanks for your help,
 Enric

[1] Patchwork links:
https://patchwork.kernel.org/patch/104857/
https://patchwork.kernel.org/patch/104856/
https://patchwork.kernel.org/patch/104858/

[2] https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1375276.html

[3] https://www.redhat.com/archives/dm-devel/2016-February/msg00112.html


Brian Norris (1):
  dm: make some mapped_device functions available

Will Drewry (2):
  dm: export a table+mapped device to the ioctl interface
  init: add support to directly boot to a mapped device

 Documentation/admin-guide/kernel-parameters.rst |   1 +
 Documentation/admin-guide/kernel-parameters.txt |   3 +
 Documentation/device-mapper/boot.txt|  65 
 drivers/md/dm-ioctl.c   |  36 ++
 drivers/md/dm.h |   8 -
 include/linux/device-mapper.h   |  19 +
 init/Makefile   |   1 +
 init/do_mounts.c|   1 +
 init/do_mounts.h|  10 +
 init/do_mounts_dm.c | 448 
 10 files changed, 584 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/device-mapper/boot.txt
 create mode 100644 init/do_mounts_dm.c

-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 3/3] init: add support to directly boot to a mapped device

2017-04-18 Thread Enric Balletbo i Serra
From: Will Drewry <w...@chromium.org>

Add a dm= kernel parameter modeled after the md= parameter from
do_mounts_md. It allows for device-mapper targets to be configured at
boot time for use early in the boot process (as the root device or
otherwise).

Signed-off-by: Will Drewry <w...@chromium.org>
Signed-off-by: Kees Cook <keesc...@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
v6: setup md->queue to reflect md's type, fix memory leak on error path
v5: resurrection, multiple devices, cleanups, error reporting improvements
v4: https://patchwork.kernel.org/patch/104861/
---
 Documentation/admin-guide/kernel-parameters.rst |   1 +
 Documentation/admin-guide/kernel-parameters.txt |   3 +
 Documentation/device-mapper/boot.txt|  65 
 init/Makefile   |   1 +
 init/do_mounts.c|   1 +
 init/do_mounts.h|  10 +
 init/do_mounts_dm.c | 448 
 7 files changed, 529 insertions(+)
 create mode 100644 Documentation/device-mapper/boot.txt
 create mode 100644 init/do_mounts_dm.c

diff --git a/Documentation/admin-guide/kernel-parameters.rst 
b/Documentation/admin-guide/kernel-parameters.rst
index c5eae20..b1d4c39 100644
--- a/Documentation/admin-guide/kernel-parameters.rst
+++ b/Documentation/admin-guide/kernel-parameters.rst
@@ -91,6 +91,7 @@ parameter is applicable::
BLACKFIN Blackfin architecture is enabled.
CLK Common clock infrastructure is enabled.
CMA Contiguous Memory Area support is enabled.
+   DM  Device mapper support is enabled.
DRM Direct Rendering Management support is enabled.
DYNAMIC_DEBUG Build in debug messages and enable them at runtime
EDD BIOS Enhanced Disk Drive Services (EDD) is enabled
diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index fdca2f2..5b06d0f 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -830,6 +830,9 @@
 
dis_ucode_ldr   [X86] Disable the microcode loader.
 
+   dm= [DM] Allows early creation of a device-mapper device.
+   See Documentation/device-mapper/boot.txt.
+
dma_debug=off   If the kernel is compiled with DMA_API_DEBUG support,
this option disables the debugging code at boot.
 
diff --git a/Documentation/device-mapper/boot.txt 
b/Documentation/device-mapper/boot.txt
new file mode 100644
index 000..1d4ac1d
--- /dev/null
+++ b/Documentation/device-mapper/boot.txt
@@ -0,0 +1,65 @@
+Boot time creation of mapped devices
+
+
+It is possible to configure a device mapper device to act as the root
+device for your system in two ways.
+
+The first is to build an initial ramdisk which boots to a minimal
+userspace which configures the device, then pivot_root(8) in to it.
+
+The second is to possible when the device-mapper and any targets are
+compiled into the kernel (not a module), one or more device-mappers may
+be created and used as the root device at boot time with the parameters
+given with the boot line dm=...
+
+Multiple device-mappers can be stacked by specifying the number of
+devices. A device can have multiple tables if the the number of tables
+is specified.
+
+   ::=  +
+::=  "," +
+ ::=[]
+::= ","
+ ::= "ro" | "rw"
+ ::= ---- | "none"
+ ::= "verity" | "bootcache" | ...
+
+Each tables line may be as normal when using the dmsetup tool except for
+two variations:
+1. Any use of commas will be interpreted as a newline
+2. Quotation marks cannot be escaped and cannot be used without
+   terminating the dm= argument.
+
+Unless renamed by udev, the device node created will be dm-0 as the
+first minor number for the device-mapper is used during early creation.
+
+The  field is optional and assumed to be 1.
+
+Examples
+
+An example of booting to a linear array made up of user-mode linux block
+devices:
+
+  dm="1 lroot none rw 2, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" \
+  root=/dev/dm-0
+
+This will boot to a rw dm-linear target of 8192 sectors split across two
+block devices identified by their major:minor numbers.  After boot, udev
+will rename this target to /dev/mapper/lroot (depending on the rules).
+No uuid was assigned.
+
+An example of multiple device-mappers, with the dm="..." contents shown
+here split on multiple lines for readability:
+
+  3 vboot none ro,
+  0 1768000 bootcache
+device=aa55b119-2a47-8c45-946a-5ac57765011f+1
+signature=76e9be054b15884a9fa8

Re: [PATCH 5/5] dm verity: add support for version 0 of the on-disk format

2017-04-11 Thread Enric Balletbo i Serra


On 11/04/17 19:21, Milan Broz wrote:
> On 04/11/2017 05:33 PM, Enric Balletbo i Serra wrote:
>> From: Will Drewry <w...@chromium.org>
>>
>> Version 0 of the on-disk format is compatible with the format used in the
>> Chromium OS. This patch adds support for this version.
>>
>> Format type 0 is the original Chrome OS version, whereas the format type 1
>> is current version, but 0, the original format used in the Chromium OS is
>> still used in most devices. This patch adds support for the original
>> on-disk format so you can decide which want you want to use.
> 
> NACK!
> 
> What the ...  is this patch doing?
> 

Argh! Very sorry about that was *not* my intention add this patch in this
series, I was only trying to submit 1 to 4 which contains the patches already
send long time ago and the patches to move to the public header some functions
needed for init/do_mount_dm.c

I'm using this specific patch to test 1 to 4 and to boot against a chromeos
rootfs as it parses the current chromeos args, this patch also has the use of
some deprecated functions like simple_strtoull, so definitely this *shouldn't*
be here, my bad.

Besides that, with the below comments, you have made me see that I have some
lacks and I need to rethink some things that I wanted to send after this series,
so many thanks and sorry again if you spend some time looking at this.

> Isn't the format 0 already there? According to
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/device-mapper/verity.txt
> 
> 
> This is the type of the on-disk hash format.
> 
> 0 is the original format used in the Chromium OS.
>   The salt is appended when hashing, digests are stored continuously and
>   the rest of the block is padded with zeroes.
> 
> Reading this patch, it does something completely different than it describes
> in header.
> 
> How is superblock format related to:
> +MODULE_PARM_DESC(dev_wait, "Wait forever for a backing device");
> ...
> not mentioning complete rewrite of verity table parsing... why?
> 
> Also please note that there is userspace (veritysetup) that have to work with
> the old format as well (I think it does already).
> I think we solved the compatibility years ago.
> 
> If not, please describe properly what is missing.
> I do not see any on-disk format changes here...
> 
> Milan
> 
>>
>> Signed-off-by: Will Drewry <w...@chromium.org>
>> Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
>> ---
>>  drivers/md/dm-verity-target.c | 279 
>> --
>>  init/do_mounts_dm.c   |  16 +--
>>  2 files changed, 220 insertions(+), 75 deletions(-)
>>
>> diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
>> index 7335d8a..c098d22 100644
>> --- a/drivers/md/dm-verity-target.c
>> +++ b/drivers/md/dm-verity-target.c
>> @@ -17,6 +17,7 @@
>>  #include "dm-verity.h"
>>  #include "dm-verity-fec.h"
>>  
>> +#include 
>>  #include 
>>  #include 
>>  
>> @@ -28,6 +29,7 @@
>>  #define DM_VERITY_DEFAULT_PREFETCH_SIZE 262144
>>  
>>  #define DM_VERITY_MAX_CORRUPTED_ERRS100
>> +#define DM_VERITY_NUM_POSITIONAL_ARGS   10
>>  
>>  #define DM_VERITY_OPT_LOGGING   "ignore_corruption"
>>  #define DM_VERITY_OPT_RESTART   "restart_on_corruption"
>> @@ -46,6 +48,11 @@ struct dm_verity_prefetch_work {
>>  unsigned n_blocks;
>>  };
>>  
>> +/* Controls whether verity_get_device will wait forever for a device. */
>> +static int dev_wait;
>> +module_param(dev_wait, int, 0444);
>> +MODULE_PARM_DESC(dev_wait, "Wait forever for a backing device");
>> +
>>  /*
>>   * Auxiliary structure appended to each dm-bufio buffer. If the value
>>   * hash_verified is nonzero, hash of the block has been verified.
>> @@ -803,6 +810,183 @@ static int verity_parse_opt_args(struct dm_arg_set 
>> *as, struct dm_verity *v)
>>  return r;
>>  }
>>  
>> +static int verity_get_device(struct dm_target *ti, const char *devname,
>> + struct dm_dev **dm_dev)
>> +{
>> +do {
>> +/* Try the normal path first since if everything is ready, it
>> + * will be the fastest.
>> + */
>> +if (!dm_get_device(ti, devname, /*FMODE_READ*/
>> +   dm_table_get_mode(ti->table), dm_dev))
>> +return 0;
>> +
>> +if (!dev_wai

[PATCH 2/5] dm: move dm definitions outside the private header to boot dm targets.

2017-04-11 Thread Enric Balletbo i Serra
To boot to device-mapper targets without an initr* we should be able to
use some dm functions, move these to the device-mapper include file so
we can call these functions from init/*

The functions moved are:

  dm_table_get_type()
  dm_lock_md_type()
  dm_unlock_md_type()
  dm_set_md_type()
  dm_get_md_type()
  dm_setup_md_queue()

Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
 drivers/md/dm.h   | 7 ---
 include/linux/device-mapper.h | 8 
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index c54d2f1..6b501b5 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -63,7 +63,6 @@ void dm_table_presuspend_undo_targets(struct dm_table *t);
 void dm_table_postsuspend_targets(struct dm_table *t);
 int dm_table_resume_targets(struct dm_table *t);
 int dm_table_any_congested(struct dm_table *t, int bdi_bits);
-unsigned dm_table_get_type(struct dm_table *t);
 struct target_type *dm_table_get_immutable_target_type(struct dm_table *t);
 struct dm_target *dm_table_get_immutable_target(struct dm_table *t);
 struct dm_target *dm_table_get_wildcard_target(struct dm_table *t);
@@ -73,14 +72,8 @@ bool dm_table_all_blk_mq_devices(struct dm_table *t);
 void dm_table_free_md_mempools(struct dm_table *t);
 struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t);
 
-void dm_lock_md_type(struct mapped_device *md);
-void dm_unlock_md_type(struct mapped_device *md);
-void dm_set_md_type(struct mapped_device *md, unsigned type);
-unsigned dm_get_md_type(struct mapped_device *md);
 struct target_type *dm_get_immutable_target_type(struct mapped_device *md);
 
-int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t);
-
 /*
  * To check the return value from dm_table_find_target().
  */
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index 70cb6af..013ac2e 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -513,6 +513,14 @@ void dm_table_run_md_queue_async(struct dm_table *t);
 struct dm_table *dm_swap_table(struct mapped_device *md,
   struct dm_table *t);
 
+unsigned dm_table_get_type(struct dm_table *t);
+
+void dm_lock_md_type(struct mapped_device *md);
+void dm_unlock_md_type(struct mapped_device *md);
+void dm_set_md_type(struct mapped_device *md, unsigned type);
+unsigned dm_get_md_type(struct mapped_device *md);
+int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t);
+
 /*
  * A wrapper around vmalloc.
  */
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/5] dm: export a table+mapped device to the ioctl interface

2017-04-11 Thread Enric Balletbo i Serra
From: Will Drewry <w...@chromium.org>

One function is added which allows for a programmatically created
mapped device to be inserted into the dm-ioctl hash table. This binds
the device to a name and, optional, uuid which is needed by udev and
allows for userspace management of the mapped device.

Signed-off-by: Will Drewry <w...@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
 drivers/md/dm-ioctl.c | 39 +++
 include/linux/device-mapper.h |  6 ++
 2 files changed, 45 insertions(+)

diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 4da6fc6..cdd7a14 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1929,6 +1929,45 @@ void dm_interface_exit(void)
 }
 
 /**
+ * dm_ioctl_export - Permanently export a mapped device via the ioctl interface
+ * @md: Pointer to mapped_device
+ * @name: Buffer (size DM_NAME_LEN) for name
+ * @uuid: Buffer (size DM_UUID_LEN) for uuid or NULL if not desired
+ */
+int dm_ioctl_export(struct mapped_device *md, const char *name,
+   const char *uuid)
+{
+   int r = 0;
+   struct hash_cell *hc;
+
+   if (!md) {
+   r = -ENXIO;
+   goto out;
+   }
+
+   /* The name and uuid can only be set once. */
+   mutex_lock(_hash_cells_mutex);
+   hc = dm_get_mdptr(md);
+   mutex_unlock(_hash_cells_mutex);
+   if (hc) {
+   DMERR("%s: already exported", dm_device_name(md));
+   r = -ENXIO;
+   goto out;
+   }
+
+   r = dm_hash_insert(name, uuid, md);
+   if (r) {
+   DMERR("%s: could not bind to '%s'", dm_device_name(md), name);
+   goto out;
+   }
+
+   /* Let udev know we've changed. */
+   dm_kobject_uevent(md, KOBJ_CHANGE, dm_get_event_nr(md));
+out:
+   return r;
+}
+
+/**
  * dm_copy_name_and_uuid - Copy mapped device name & uuid into supplied buffers
  * @md: Pointer to mapped_device
  * @name: Buffer (size DM_NAME_LEN) for name
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index 013ac2e..b60892e 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -405,6 +405,12 @@ void dm_set_mdptr(struct mapped_device *md, void *ptr);
 void *dm_get_mdptr(struct mapped_device *md);
 
 /*
+ * Export the device via the ioctl interface (uses mdptr).
+ */
+int dm_ioctl_export(struct mapped_device *md, const char *name,
+   const char *uuid);
+
+/*
  * A device can still be used while suspended, but I/O is deferred.
  */
 int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/5] init: add support to directly boot to a mapped device

2017-04-11 Thread Enric Balletbo i Serra
From: Will Drewry <w...@chromium.org>

Add a dm= kernel parameter modeled after the md= parameter from
do_mounts_md. It allows for device-mapper targets to be configured at
boot time for use early in the boot process (as the root device or
otherwise).

Signed-off-by: Will Drewry <w...@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
 Documentation/admin-guide/kernel-parameters.rst |   1 +
 Documentation/admin-guide/kernel-parameters.txt |   3 +
 Documentation/device-mapper/boot.txt|  42 +++
 init/Makefile   |   1 +
 init/do_mounts.c|   1 +
 init/do_mounts.h|  10 +
 init/do_mounts_dm.c | 478 
 7 files changed, 536 insertions(+)
 create mode 100644 Documentation/device-mapper/boot.txt
 create mode 100644 init/do_mounts_dm.c

diff --git a/Documentation/admin-guide/kernel-parameters.rst 
b/Documentation/admin-guide/kernel-parameters.rst
index b516164..ecb58d6 100644
--- a/Documentation/admin-guide/kernel-parameters.rst
+++ b/Documentation/admin-guide/kernel-parameters.rst
@@ -91,6 +91,7 @@ parameter is applicable::
BLACKFIN Blackfin architecture is enabled.
CLK Common clock infrastructure is enabled.
CMA Contiguous Memory Area support is enabled.
+   DM  Device mapper support is enabled.
DRM Direct Rendering Management support is enabled.
DYNAMIC_DEBUG Build in debug messages and enable them at runtime
EDD BIOS Enhanced Disk Drive Services (EDD) is enabled
diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 2ba45ca..686453d 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -830,6 +830,9 @@
 
dis_ucode_ldr   [X86] Disable the microcode loader.
 
+   dm= [DM] Allows early creation of a device-mapper device.
+   See Documentation/device-mapper/boot.txt.
+
dma_debug=off   If the kernel is compiled with DMA_API_DEBUG support,
this option disables the debugging code at boot.
 
diff --git a/Documentation/device-mapper/boot.txt 
b/Documentation/device-mapper/boot.txt
new file mode 100644
index 000..76ea6ac
--- /dev/null
+++ b/Documentation/device-mapper/boot.txt
@@ -0,0 +1,42 @@
+Boot time creation of mapped devices
+===
+
+It is possible to configure a device mapper device to act as the root
+device for your system in two ways.
+
+The first is to build an initial ramdisk which boots to a minimal
+userspace which configures the device, then pivot_root(8) in to it.
+
+For simple device mapper configurations, it is possible to boot directly
+using the following kernel command line:
+
+dm="  ,table line 1,...,table line n"
+
+name = the name to associate with the device
+   after boot, udev, if used, will use that name to label
+   the device node.
+uuid = may be 'none' or the UUID desired for the device.
+ro = may be 'ro' or 'rw'.  If 'ro', the device and device table will be
+   marked read-only.
+
+Each table line may be as normal when using the dmsetup tool except for
+two variations:
+1. Any use of commas will be interpreted as a newline
+2. Quotation marks cannot be escaped and cannot be used without
+   terminating the dm= argument.
+
+Unless renamed by udev, the device node created will be dm-0 as the
+first minor number for the device-mapper is used during early creation.
+
+Example
+===
+
+- Booting to a linear array made up of user-mode linux block devices:
+
+  dm="lroot none 0, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" \
+  root=/dev/dm-0
+
+Will boot to a rw dm-linear target of 8192 sectors split across two
+block devices identified by their major:minor numbers.  After boot, udev
+will rename this target to /dev/mapper/lroot (depending on the rules).
+No uuid was assigned.
diff --git a/init/Makefile b/init/Makefile
index c4fb455..30424d7 100644
--- a/init/Makefile
+++ b/init/Makefile
@@ -20,6 +20,7 @@ mounts-y  := do_mounts.o
 mounts-$(CONFIG_BLK_DEV_RAM)   += do_mounts_rd.o
 mounts-$(CONFIG_BLK_DEV_INITRD)+= do_mounts_initrd.o
 mounts-$(CONFIG_BLK_DEV_MD)+= do_mounts_md.o
+mounts-$(CONFIG_BLK_DEV_DM)+= do_mounts_dm.o
 
 # dependencies on generated files need to be listed explicitly
 $(obj)/version.o: include/generated/compile.h
diff --git a/init/do_mounts.c b/init/do_mounts.c
index c2de510..8b9182b 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -566,6 +566,7 @@ void __init prepare_namespace(void)
wait_for_device_probe();
 
md_run_setup();
+   dm_run_setup();
 
if (saved_root_name[0]) {
root_device_name = saved_root_name;
diff --git a/init/do_mou

[PATCH 5/5] dm verity: add support for version 0 of the on-disk format

2017-04-11 Thread Enric Balletbo i Serra
From: Will Drewry <w...@chromium.org>

Version 0 of the on-disk format is compatible with the format used in the
Chromium OS. This patch adds support for this version.

Format type 0 is the original Chrome OS version, whereas the format type 1
is current version, but 0, the original format used in the Chromium OS is
still used in most devices. This patch adds support for the original
on-disk format so you can decide which want you want to use.

Signed-off-by: Will Drewry <w...@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
 drivers/md/dm-verity-target.c | 279 --
 init/do_mounts_dm.c   |  16 +--
 2 files changed, 220 insertions(+), 75 deletions(-)

diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
index 7335d8a..c098d22 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -17,6 +17,7 @@
 #include "dm-verity.h"
 #include "dm-verity-fec.h"
 
+#include 
 #include 
 #include 
 
@@ -28,6 +29,7 @@
 #define DM_VERITY_DEFAULT_PREFETCH_SIZE262144
 
 #define DM_VERITY_MAX_CORRUPTED_ERRS   100
+#define DM_VERITY_NUM_POSITIONAL_ARGS  10
 
 #define DM_VERITY_OPT_LOGGING  "ignore_corruption"
 #define DM_VERITY_OPT_RESTART  "restart_on_corruption"
@@ -46,6 +48,11 @@ struct dm_verity_prefetch_work {
unsigned n_blocks;
 };
 
+/* Controls whether verity_get_device will wait forever for a device. */
+static int dev_wait;
+module_param(dev_wait, int, 0444);
+MODULE_PARM_DESC(dev_wait, "Wait forever for a backing device");
+
 /*
  * Auxiliary structure appended to each dm-bufio buffer. If the value
  * hash_verified is nonzero, hash of the block has been verified.
@@ -803,6 +810,183 @@ static int verity_parse_opt_args(struct dm_arg_set *as, 
struct dm_verity *v)
return r;
 }
 
+static int verity_get_device(struct dm_target *ti, const char *devname,
+struct dm_dev **dm_dev)
+{
+   do {
+   /* Try the normal path first since if everything is ready, it
+* will be the fastest.
+*/
+   if (!dm_get_device(ti, devname, /*FMODE_READ*/
+  dm_table_get_mode(ti->table), dm_dev))
+   return 0;
+
+   if (!dev_wait)
+   break;
+
+   /* No need to be too aggressive since this is a slow path. */
+   msleep(500);
+   } while (driver_probe_done() != 0 || !(*dm_dev));
+   return -1;
+}
+
+struct verity_args {
+   int version;
+   char *data_device;
+   char *hash_device;
+   int data_block_size_bits;
+   int hash_block_size_bits;
+   u64 num_data_blocks;
+   u64 hash_start_block;
+   char *algorithm;
+   char *digest;
+   char *salt;
+};
+
+static void pr_args(struct verity_args *args)
+{
+   printk(KERN_INFO "VERITY args: version=%d data_device=%s hash_device=%s"
+   " data_block_size_bits=%d hash_block_size_bits=%d"
+   " num_data_blocks=%lld hash_start_block=%lld"
+   " algorithm=%s digest=%s salt=%s\n",
+   args->version,
+   args->data_device,
+   args->hash_device,
+   args->data_block_size_bits,
+   args->hash_block_size_bits,
+   args->num_data_blocks,
+   args->hash_start_block,
+   args->algorithm,
+   args->digest,
+   args->salt);
+}
+
+/*
+ * positional_args - collects the argments using the positional
+ * parameters.
+ * arg# - parameter
+ *0 - version
+ *1 - data device
+ *2 - hash device - may be same as data device
+ *3 - data block size log2
+ *4 - hash block size log2
+ *5 - number of data blocks
+ *6 - hash start block
+ *7 - algorithm
+ *8 - digest
+ *9 - salt
+ */
+static char *positional_args(unsigned argc, char **argv,
+struct verity_args *args)
+{
+   unsigned int num;
+   unsigned long long num_ll;
+   char dummy;
+
+   if (argc < DM_VERITY_NUM_POSITIONAL_ARGS)
+   return "Invalid argument count: at least 10 arguments required";
+
+   if (sscanf(argv[0], "%d%c", , ) != 1 ||
+   num < 0 || num > 1)
+   return "Invalid version";
+   args->version = num;
+
+   args->data_device = argv[1];
+   args->hash_device = argv[2];
+
+   if (sscanf(argv[3], "%u%c", , ) != 1 ||
+   !num || (num & (num - 1)) ||
+   num > PAGE_SIZE)
+   return "Invalid data device block size";
+   args->data_block_size_bits = ffs(num) - 1;
+
+   if (sscanf(argv[4], "%u%c", , ) != 1 |

[PATCH 0/5] dm: boot a mapped device without an initramfs

2017-04-11 Thread Enric Balletbo i Serra
Hello,

Some of these patches were send few years back, I saw that first
version was send to this list in 2010, and after some reviews did not
landi [1] , apparently without any reason.

The patches has been used and working well on the ChromeOS kernel for
long time, this version is basically a rebase on top of mainline based
on latest version found in chromeos 4.4 kernel, the patches has also
been tested on a veyron device.

This a new attempt to try to land these patches again, so I'll wait
for comments/reviews and send new version to the list.

[1] Patchwork links:
https://patchwork.kernel.org/patch/104857/
https://patchwork.kernel.org/patch/104856/
https://patchwork.kernel.org/patch/104858/

Best regards,
 Enric

Brian Norris (1):
  dm: move dm_table_destroy() to same header as dm_table_create()

Enric Balletbo i Serra (1):
  dm: move dm definitions outside the private header to boot dm targets.

Will Drewry (3):
  dm: export a table+mapped device to the ioctl interface
  init: add support to directly boot to a mapped device
  dm verity: add support for version 0 of the on-disk format

 Documentation/admin-guide/kernel-parameters.rst |   1 +
 Documentation/admin-guide/kernel-parameters.txt |   3 +
 Documentation/device-mapper/boot.txt|  42 +++
 drivers/md/dm-ioctl.c   |  39 ++
 drivers/md/dm-verity-target.c   | 279 ++
 drivers/md/dm.h |   8 -
 include/linux/device-mapper.h   |  19 +
 init/Makefile   |   1 +
 init/do_mounts.c|   1 +
 init/do_mounts.h|  10 +
 init/do_mounts_dm.c | 472 
 11 files changed, 803 insertions(+), 72 deletions(-)
 create mode 100644 Documentation/device-mapper/boot.txt
 create mode 100644 init/do_mounts_dm.c

-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/5] dm: move dm_table_destroy() to same header as dm_table_create()

2017-04-11 Thread Enric Balletbo i Serra
From: Brian Norris <briannor...@chromium.org>

If anyone is going to use dm_table_create(), they probably should be
able to use dm_table_destroy() too. Move the dm_table_destroy()
definition outside the private header, near dm_table_create()

Signed-off-by: Brian Norris <briannor...@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balle...@collabora.com>
---
 drivers/md/dm.h   | 1 -
 include/linux/device-mapper.h | 5 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index f298b01..c54d2f1 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -48,7 +48,6 @@ struct dm_md_mempools;
 /*-
  * Internal table functions.
  *---*/
-void dm_table_destroy(struct dm_table *t);
 void dm_table_event_callback(struct dm_table *t,
 void (*fn)(void *), void *context);
 struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index);
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index a7e6903..70cb6af 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -472,6 +472,11 @@ void dm_table_set_type(struct dm_table *t, unsigned type);
 int dm_table_complete(struct dm_table *t);
 
 /*
+ * Destroy the table when finished.
+ */
+void dm_table_destroy(struct dm_table *t);
+
+/*
  * Target may require that it is never sent I/O larger than len.
  */
 int __must_check dm_set_target_max_io_len(struct dm_target *ti, sector_t len);
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html