diff options
-rw-r--r-- | Documentation/device-mapper/dm-crypt.txt | 7 | ||||
-rw-r--r-- | drivers/md/dm-crypt.c | 49 |
2 files changed, 40 insertions, 16 deletions
diff --git a/Documentation/device-mapper/dm-crypt.txt b/Documentation/device-mapper/dm-crypt.txt index c81839b52c4d..571f24ffc91c 100644 --- a/Documentation/device-mapper/dm-crypt.txt +++ b/Documentation/device-mapper/dm-crypt.txt | |||
@@ -51,7 +51,7 @@ Parameters: <cipher> <key> <iv_offset> <device path> \ | |||
51 | Otherwise #opt_params is the number of following arguments. | 51 | Otherwise #opt_params is the number of following arguments. |
52 | 52 | ||
53 | Example of optional parameters section: | 53 | Example of optional parameters section: |
54 | 1 allow_discards | 54 | 2 allow_discards same_cpu_crypt |
55 | 55 | ||
56 | allow_discards | 56 | allow_discards |
57 | Block discard requests (a.k.a. TRIM) are passed through the crypt device. | 57 | Block discard requests (a.k.a. TRIM) are passed through the crypt device. |
@@ -63,6 +63,11 @@ allow_discards | |||
63 | used space etc.) if the discarded blocks can be located easily on the | 63 | used space etc.) if the discarded blocks can be located easily on the |
64 | device later. | 64 | device later. |
65 | 65 | ||
66 | same_cpu_crypt | ||
67 | Perform encryption using the same cpu that IO was submitted on. | ||
68 | The default is to use an unbound workqueue so that encryption work | ||
69 | is automatically balanced between available CPUs. | ||
70 | |||
66 | Example scripts | 71 | Example scripts |
67 | =============== | 72 | =============== |
68 | LUKS (Linux Unified Key Setup) is now the preferred way to set up disk | 73 | LUKS (Linux Unified Key Setup) is now the preferred way to set up disk |
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 08981be7baa1..5063c901c0f5 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c | |||
@@ -108,7 +108,7 @@ struct iv_tcw_private { | |||
108 | * Crypt: maps a linear range of a block device | 108 | * Crypt: maps a linear range of a block device |
109 | * and encrypts / decrypts at the same time. | 109 | * and encrypts / decrypts at the same time. |
110 | */ | 110 | */ |
111 | enum flags { DM_CRYPT_SUSPENDED, DM_CRYPT_KEY_VALID }; | 111 | enum flags { DM_CRYPT_SUSPENDED, DM_CRYPT_KEY_VALID, DM_CRYPT_SAME_CPU }; |
112 | 112 | ||
113 | /* | 113 | /* |
114 | * The fields in here must be read only after initialization. | 114 | * The fields in here must be read only after initialization. |
@@ -1688,7 +1688,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
1688 | char dummy; | 1688 | char dummy; |
1689 | 1689 | ||
1690 | static struct dm_arg _args[] = { | 1690 | static struct dm_arg _args[] = { |
1691 | {0, 1, "Invalid number of feature args"}, | 1691 | {0, 2, "Invalid number of feature args"}, |
1692 | }; | 1692 | }; |
1693 | 1693 | ||
1694 | if (argc < 5) { | 1694 | if (argc < 5) { |
@@ -1788,15 +1788,23 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
1788 | if (ret) | 1788 | if (ret) |
1789 | goto bad; | 1789 | goto bad; |
1790 | 1790 | ||
1791 | opt_string = dm_shift_arg(&as); | 1791 | while (opt_params--) { |
1792 | opt_string = dm_shift_arg(&as); | ||
1793 | if (!opt_string) { | ||
1794 | ti->error = "Not enough feature arguments"; | ||
1795 | goto bad; | ||
1796 | } | ||
1792 | 1797 | ||
1793 | if (opt_params == 1 && opt_string && | 1798 | if (!strcasecmp(opt_string, "allow_discards")) |
1794 | !strcasecmp(opt_string, "allow_discards")) | 1799 | ti->num_discard_bios = 1; |
1795 | ti->num_discard_bios = 1; | 1800 | |
1796 | else if (opt_params) { | 1801 | else if (!strcasecmp(opt_string, "same_cpu_crypt")) |
1797 | ret = -EINVAL; | 1802 | set_bit(DM_CRYPT_SAME_CPU, &cc->flags); |
1798 | ti->error = "Invalid feature arguments"; | 1803 | |
1799 | goto bad; | 1804 | else { |
1805 | ti->error = "Invalid feature arguments"; | ||
1806 | goto bad; | ||
1807 | } | ||
1800 | } | 1808 | } |
1801 | } | 1809 | } |
1802 | 1810 | ||
@@ -1807,8 +1815,11 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
1807 | goto bad; | 1815 | goto bad; |
1808 | } | 1816 | } |
1809 | 1817 | ||
1810 | cc->crypt_queue = alloc_workqueue("kcryptd", | 1818 | if (test_bit(DM_CRYPT_SAME_CPU, &cc->flags)) |
1811 | WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM, 1); | 1819 | cc->crypt_queue = alloc_workqueue("kcryptd", WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM, 1); |
1820 | else | ||
1821 | cc->crypt_queue = alloc_workqueue("kcryptd", WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM | WQ_UNBOUND, | ||
1822 | num_online_cpus()); | ||
1812 | if (!cc->crypt_queue) { | 1823 | if (!cc->crypt_queue) { |
1813 | ti->error = "Couldn't create kcryptd queue"; | 1824 | ti->error = "Couldn't create kcryptd queue"; |
1814 | goto bad; | 1825 | goto bad; |
@@ -1860,6 +1871,7 @@ static void crypt_status(struct dm_target *ti, status_type_t type, | |||
1860 | { | 1871 | { |
1861 | struct crypt_config *cc = ti->private; | 1872 | struct crypt_config *cc = ti->private; |
1862 | unsigned i, sz = 0; | 1873 | unsigned i, sz = 0; |
1874 | int num_feature_args = 0; | ||
1863 | 1875 | ||
1864 | switch (type) { | 1876 | switch (type) { |
1865 | case STATUSTYPE_INFO: | 1877 | case STATUSTYPE_INFO: |
@@ -1878,8 +1890,15 @@ static void crypt_status(struct dm_target *ti, status_type_t type, | |||
1878 | DMEMIT(" %llu %s %llu", (unsigned long long)cc->iv_offset, | 1890 | DMEMIT(" %llu %s %llu", (unsigned long long)cc->iv_offset, |
1879 | cc->dev->name, (unsigned long long)cc->start); | 1891 | cc->dev->name, (unsigned long long)cc->start); |
1880 | 1892 | ||
1881 | if (ti->num_discard_bios) | 1893 | num_feature_args += !!ti->num_discard_bios; |
1882 | DMEMIT(" 1 allow_discards"); | 1894 | num_feature_args += test_bit(DM_CRYPT_SAME_CPU, &cc->flags); |
1895 | if (num_feature_args) { | ||
1896 | DMEMIT(" %d", num_feature_args); | ||
1897 | if (ti->num_discard_bios) | ||
1898 | DMEMIT(" allow_discards"); | ||
1899 | if (test_bit(DM_CRYPT_SAME_CPU, &cc->flags)) | ||
1900 | DMEMIT(" same_cpu_crypt"); | ||
1901 | } | ||
1883 | 1902 | ||
1884 | break; | 1903 | break; |
1885 | } | 1904 | } |
@@ -1976,7 +1995,7 @@ static int crypt_iterate_devices(struct dm_target *ti, | |||
1976 | 1995 | ||
1977 | static struct target_type crypt_target = { | 1996 | static struct target_type crypt_target = { |
1978 | .name = "crypt", | 1997 | .name = "crypt", |
1979 | .version = {1, 13, 0}, | 1998 | .version = {1, 14, 0}, |
1980 | .module = THIS_MODULE, | 1999 | .module = THIS_MODULE, |
1981 | .ctr = crypt_ctr, | 2000 | .ctr = crypt_ctr, |
1982 | .dtr = crypt_dtr, | 2001 | .dtr = crypt_dtr, |