Skip to content

Commit 5f76eea

Browse files
David HildenbrandIngo Molnar
authored andcommitted
sched/preempt, powerpc: Disable preemption in enable_kernel_altivec() explicitly
enable_kernel_altivec() has to be called with disabled preemption. Let's make this explicit, to prepare for pagefault_disable() not touching preemption anymore. Reviewed-and-tested-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: David.Laight@ACULAB.COM Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: airlied@linux.ie Cc: akpm@linux-foundation.org Cc: bigeasy@linutronix.de Cc: borntraeger@de.ibm.com Cc: daniel.vetter@intel.com Cc: heiko.carstens@de.ibm.com Cc: herbert@gondor.apana.org.au Cc: hocko@suse.cz Cc: hughd@google.com Cc: mst@redhat.com Cc: paulus@samba.org Cc: ralf@linux-mips.org Cc: schwidefsky@de.ibm.com Cc: yang.shi@windriver.com Link: http://lkml.kernel.org/r/1431359540-32227-14-git-send-email-dahi@linux.vnet.ibm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 2f09b22 commit 5f76eea

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

arch/powerpc/lib/vmx-helper.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ int enter_vmx_usercopy(void)
2727
if (in_interrupt())
2828
return 0;
2929

30-
/* This acts as preempt_disable() as well and will make
31-
* enable_kernel_altivec(). We need to disable page faults
32-
* as they can call schedule and thus make us lose the VMX
33-
* context. So on page faults, we just fail which will cause
34-
* a fallback to the normal non-vmx copy.
30+
preempt_disable();
31+
/*
32+
* We need to disable page faults as they can call schedule and
33+
* thus make us lose the VMX context. So on page faults, we just
34+
* fail which will cause a fallback to the normal non-vmx copy.
3535
*/
3636
pagefault_disable();
3737

@@ -47,6 +47,7 @@ int enter_vmx_usercopy(void)
4747
int exit_vmx_usercopy(void)
4848
{
4949
pagefault_enable();
50+
preempt_enable();
5051
return 0;
5152
}
5253

drivers/crypto/vmx/aes.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ static int p8_aes_setkey(struct crypto_tfm *tfm, const u8 *key,
7878
int ret;
7979
struct p8_aes_ctx *ctx = crypto_tfm_ctx(tfm);
8080

81+
preempt_disable();
8182
pagefault_disable();
8283
enable_kernel_altivec();
8384
ret = aes_p8_set_encrypt_key(key, keylen * 8, &ctx->enc_key);
8485
ret += aes_p8_set_decrypt_key(key, keylen * 8, &ctx->dec_key);
8586
pagefault_enable();
86-
87+
preempt_enable();
88+
8789
ret += crypto_cipher_setkey(ctx->fallback, key, keylen);
8890
return ret;
8991
}
@@ -95,10 +97,12 @@ static void p8_aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
9597
if (in_interrupt()) {
9698
crypto_cipher_encrypt_one(ctx->fallback, dst, src);
9799
} else {
100+
preempt_disable();
98101
pagefault_disable();
99102
enable_kernel_altivec();
100103
aes_p8_encrypt(src, dst, &ctx->enc_key);
101104
pagefault_enable();
105+
preempt_enable();
102106
}
103107
}
104108

@@ -109,10 +113,12 @@ static void p8_aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
109113
if (in_interrupt()) {
110114
crypto_cipher_decrypt_one(ctx->fallback, dst, src);
111115
} else {
116+
preempt_disable();
112117
pagefault_disable();
113118
enable_kernel_altivec();
114119
aes_p8_decrypt(src, dst, &ctx->dec_key);
115120
pagefault_enable();
121+
preempt_enable();
116122
}
117123
}
118124

drivers/crypto/vmx/aes_cbc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ static int p8_aes_cbc_setkey(struct crypto_tfm *tfm, const u8 *key,
7979
int ret;
8080
struct p8_aes_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
8181

82+
preempt_disable();
8283
pagefault_disable();
8384
enable_kernel_altivec();
8485
ret = aes_p8_set_encrypt_key(key, keylen * 8, &ctx->enc_key);
8586
ret += aes_p8_set_decrypt_key(key, keylen * 8, &ctx->dec_key);
8687
pagefault_enable();
88+
preempt_enable();
8789

8890
ret += crypto_blkcipher_setkey(ctx->fallback, key, keylen);
8991
return ret;
@@ -106,6 +108,7 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
106108
if (in_interrupt()) {
107109
ret = crypto_blkcipher_encrypt(&fallback_desc, dst, src, nbytes);
108110
} else {
111+
preempt_disable();
109112
pagefault_disable();
110113
enable_kernel_altivec();
111114

@@ -119,6 +122,7 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
119122
}
120123

121124
pagefault_enable();
125+
preempt_enable();
122126
}
123127

124128
return ret;
@@ -141,6 +145,7 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
141145
if (in_interrupt()) {
142146
ret = crypto_blkcipher_decrypt(&fallback_desc, dst, src, nbytes);
143147
} else {
148+
preempt_disable();
144149
pagefault_disable();
145150
enable_kernel_altivec();
146151

@@ -154,6 +159,7 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
154159
}
155160

156161
pagefault_enable();
162+
preempt_enable();
157163
}
158164

159165
return ret;

drivers/crypto/vmx/ghash.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ static int p8_ghash_setkey(struct crypto_shash *tfm, const u8 *key,
114114
if (keylen != GHASH_KEY_LEN)
115115
return -EINVAL;
116116

117+
preempt_disable();
117118
pagefault_disable();
118119
enable_kernel_altivec();
119120
enable_kernel_fp();
120121
gcm_init_p8(ctx->htable, (const u64 *) key);
121122
pagefault_enable();
123+
preempt_enable();
122124
return crypto_shash_setkey(ctx->fallback, key, keylen);
123125
}
124126

@@ -140,23 +142,27 @@ static int p8_ghash_update(struct shash_desc *desc,
140142
}
141143
memcpy(dctx->buffer + dctx->bytes, src,
142144
GHASH_DIGEST_SIZE - dctx->bytes);
145+
preempt_disable();
143146
pagefault_disable();
144147
enable_kernel_altivec();
145148
enable_kernel_fp();
146149
gcm_ghash_p8(dctx->shash, ctx->htable, dctx->buffer,
147150
GHASH_DIGEST_SIZE);
148151
pagefault_enable();
152+
preempt_enable();
149153
src += GHASH_DIGEST_SIZE - dctx->bytes;
150154
srclen -= GHASH_DIGEST_SIZE - dctx->bytes;
151155
dctx->bytes = 0;
152156
}
153157
len = srclen & ~(GHASH_DIGEST_SIZE - 1);
154158
if (len) {
159+
preempt_disable();
155160
pagefault_disable();
156161
enable_kernel_altivec();
157162
enable_kernel_fp();
158163
gcm_ghash_p8(dctx->shash, ctx->htable, src, len);
159164
pagefault_enable();
165+
preempt_enable();
160166
src += len;
161167
srclen -= len;
162168
}
@@ -180,12 +186,14 @@ static int p8_ghash_final(struct shash_desc *desc, u8 *out)
180186
if (dctx->bytes) {
181187
for (i = dctx->bytes; i < GHASH_DIGEST_SIZE; i++)
182188
dctx->buffer[i] = 0;
189+
preempt_disable();
183190
pagefault_disable();
184191
enable_kernel_altivec();
185192
enable_kernel_fp();
186193
gcm_ghash_p8(dctx->shash, ctx->htable, dctx->buffer,
187194
GHASH_DIGEST_SIZE);
188195
pagefault_enable();
196+
preempt_enable();
189197
dctx->bytes = 0;
190198
}
191199
memcpy(out, dctx->shash, GHASH_DIGEST_SIZE);

0 commit comments

Comments
 (0)