1 |
commit: 226f35b4faf8c37111b54e1449a20137b0b3212c |
2 |
Author: Mike Pagano <mpagano <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Sep 28 23:44:18 2015 +0000 |
4 |
Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Sep 28 23:44:18 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=226f35b4 |
7 |
|
8 |
dm crypt: constrain crypt device's max_segment_size to PAGE_SIZE. See bug #561558. Thanks to kipplasterjoe for reporting. |
9 |
|
10 |
0000_README | 4 ++ |
11 |
1600_dm-crypt-limit-max-segment-size.patch | 84 ++++++++++++++++++++++++++++++ |
12 |
2 files changed, 88 insertions(+) |
13 |
|
14 |
diff --git a/0000_README b/0000_README |
15 |
index 93b94b6..551dcf3 100644 |
16 |
--- a/0000_README |
17 |
+++ b/0000_README |
18 |
@@ -55,6 +55,10 @@ Patch: 1510_fs-enable-link-security-restrictions-by-default.patch |
19 |
From: http://sources.debian.net/src/linux/3.16.7-ckt4-3/debian/patches/debian/fs-enable-link-security-restrictions-by-default.patch/ |
20 |
Desc: Enable link security restrictions by default. |
21 |
|
22 |
+Patch: 1600_dm-crypt-limit-max-segment-size.patch |
23 |
+From: https://bugzilla.kernel.org/show_bug.cgi?id=104421 |
24 |
+Desc: dm crypt: constrain crypt device's max_segment_size to PAGE_SIZE. |
25 |
+ |
26 |
Patch: 2700_ThinkPad-30-brightness-control-fix.patch |
27 |
From: Seth Forshee <seth.forshee@×××××××××.com> |
28 |
Desc: ACPI: Disable Windows 8 compatibility for some Lenovo ThinkPads. |
29 |
|
30 |
diff --git a/1600_dm-crypt-limit-max-segment-size.patch b/1600_dm-crypt-limit-max-segment-size.patch |
31 |
new file mode 100644 |
32 |
index 0000000..82aca44 |
33 |
--- /dev/null |
34 |
+++ b/1600_dm-crypt-limit-max-segment-size.patch |
35 |
@@ -0,0 +1,84 @@ |
36 |
+From 586b286b110e94eb31840ac5afc0c24e0881fe34 Mon Sep 17 00:00:00 2001 |
37 |
+From: Mike Snitzer <snitzer@××××××.com> |
38 |
+Date: Wed, 9 Sep 2015 21:34:51 -0400 |
39 |
+Subject: dm crypt: constrain crypt device's max_segment_size to PAGE_SIZE |
40 |
+ |
41 |
+Setting the dm-crypt device's max_segment_size to PAGE_SIZE is an |
42 |
+unfortunate constraint that is required to avoid the potential for |
43 |
+exceeding dm-crypt's underlying device's max_segments limits -- due to |
44 |
+crypt_alloc_buffer() possibly allocating pages for the encryption bio |
45 |
+that are not as physically contiguous as the original bio. |
46 |
+ |
47 |
+It is interesting to note that this problem was already fixed back in |
48 |
+2007 via commit 91e106259 ("dm crypt: use bio_add_page"). But Linux 4.0 |
49 |
+commit cf2f1abfb ("dm crypt: don't allocate pages for a partial |
50 |
+request") regressed dm-crypt back to _not_ using bio_add_page(). But |
51 |
+given dm-crypt's cpu parallelization changes all depend on commit |
52 |
+cf2f1abfb's abandoning of the more complex io fragments processing that |
53 |
+dm-crypt previously had we cannot easily go back to using |
54 |
+bio_add_page(). |
55 |
+ |
56 |
+So all said the cleanest way to resolve this issue is to fix dm-crypt to |
57 |
+properly constrain the original bios entering dm-crypt so the encryption |
58 |
+bios that dm-crypt generates from the original bios are always |
59 |
+compatible with the underlying device's max_segments queue limits. |
60 |
+ |
61 |
+It should be noted that technically Linux 4.3 does _not_ need this fix |
62 |
+because of the block core's new late bio-splitting capability. But, it |
63 |
+is reasoned, there is little to be gained by having the block core split |
64 |
+the encrypted bio that is composed of PAGE_SIZE segments. That said, in |
65 |
+the future we may revert this change. |
66 |
+ |
67 |
+Fixes: cf2f1abfb ("dm crypt: don't allocate pages for a partial request") |
68 |
+Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=104421 |
69 |
+Suggested-by: Jeff Moyer <jmoyer@××××××.com> |
70 |
+Signed-off-by: Mike Snitzer <snitzer@××××××.com> |
71 |
+Cc: stable@×××××××××××.org # 4.0+ |
72 |
+ |
73 |
+diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c |
74 |
+index d60c88d..4b3b6f8 100644 |
75 |
+--- a/drivers/md/dm-crypt.c |
76 |
++++ b/drivers/md/dm-crypt.c |
77 |
+@@ -968,7 +968,8 @@ static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone); |
78 |
+ |
79 |
+ /* |
80 |
+ * Generate a new unfragmented bio with the given size |
81 |
+- * This should never violate the device limitations |
82 |
++ * This should never violate the device limitations (but only because |
83 |
++ * max_segment_size is being constrained to PAGE_SIZE). |
84 |
+ * |
85 |
+ * This function may be called concurrently. If we allocate from the mempool |
86 |
+ * concurrently, there is a possibility of deadlock. For example, if we have |
87 |
+@@ -2045,9 +2046,20 @@ static int crypt_iterate_devices(struct dm_target *ti, |
88 |
+ return fn(ti, cc->dev, cc->start, ti->len, data); |
89 |
+ } |
90 |
+ |
91 |
++static void crypt_io_hints(struct dm_target *ti, struct queue_limits *limits) |
92 |
++{ |
93 |
++ /* |
94 |
++ * Unfortunate constraint that is required to avoid the potential |
95 |
++ * for exceeding underlying device's max_segments limits -- due to |
96 |
++ * crypt_alloc_buffer() possibly allocating pages for the encryption |
97 |
++ * bio that are not as physically contiguous as the original bio. |
98 |
++ */ |
99 |
++ limits->max_segment_size = PAGE_SIZE; |
100 |
++} |
101 |
++ |
102 |
+ static struct target_type crypt_target = { |
103 |
+ .name = "crypt", |
104 |
+- .version = {1, 14, 0}, |
105 |
++ .version = {1, 14, 1}, |
106 |
+ .module = THIS_MODULE, |
107 |
+ .ctr = crypt_ctr, |
108 |
+ .dtr = crypt_dtr, |
109 |
+@@ -2058,6 +2070,7 @@ static struct target_type crypt_target = { |
110 |
+ .resume = crypt_resume, |
111 |
+ .message = crypt_message, |
112 |
+ .iterate_devices = crypt_iterate_devices, |
113 |
++ .io_hints = crypt_io_hints, |
114 |
+ }; |
115 |
+ |
116 |
+ static int __init dm_crypt_init(void) |
117 |
+-- |
118 |
+cgit v0.10.2 |
119 |
+ |