aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390
diff options
context:
space:
mode:
Diffstat (limited to 'arch/s390')
-rw-r--r--arch/s390/crypto/aes_s390.c60
-rw-r--r--arch/s390/crypto/des_s390.c360
-rw-r--r--arch/s390/crypto/sha256_s390.c29
-rw-r--r--arch/s390/kernel/process.c14
-rw-r--r--arch/s390/kernel/setup.c11
-rw-r--r--arch/s390/kernel/time.c2
-rw-r--r--arch/s390/kernel/vtime.c27
-rw-r--r--arch/s390/lib/Makefile3
-rw-r--r--arch/s390/lib/spinlock.c7
9 files changed, 385 insertions, 128 deletions
diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c
index 7a1033d8e00f..c5ca2dc5d428 100644
--- a/arch/s390/crypto/aes_s390.c
+++ b/arch/s390/crypto/aes_s390.c
@@ -114,80 +114,108 @@ static unsigned int aes_encrypt_ecb(const struct cipher_desc *desc, u8 *out,
114 const u8 *in, unsigned int nbytes) 114 const u8 *in, unsigned int nbytes)
115{ 115{
116 struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm); 116 struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm);
117 int ret;
118
119 /* only use complete blocks */
120 nbytes &= ~(AES_BLOCK_SIZE - 1);
117 121
118 switch (sctx->key_len) { 122 switch (sctx->key_len) {
119 case 16: 123 case 16:
120 crypt_s390_km(KM_AES_128_ENCRYPT, &sctx->key, out, in, nbytes); 124 ret = crypt_s390_km(KM_AES_128_ENCRYPT, &sctx->key, out, in, nbytes);
125 BUG_ON((ret < 0) || (ret != nbytes));
121 break; 126 break;
122 case 24: 127 case 24:
123 crypt_s390_km(KM_AES_192_ENCRYPT, &sctx->key, out, in, nbytes); 128 ret = crypt_s390_km(KM_AES_192_ENCRYPT, &sctx->key, out, in, nbytes);
129 BUG_ON((ret < 0) || (ret != nbytes));
124 break; 130 break;
125 case 32: 131 case 32:
126 crypt_s390_km(KM_AES_256_ENCRYPT, &sctx->key, out, in, nbytes); 132 ret = crypt_s390_km(KM_AES_256_ENCRYPT, &sctx->key, out, in, nbytes);
133 BUG_ON((ret < 0) || (ret != nbytes));
127 break; 134 break;
128 } 135 }
129 return nbytes & ~(AES_BLOCK_SIZE - 1); 136 return nbytes;
130} 137}
131 138
132static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out, 139static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out,
133 const u8 *in, unsigned int nbytes) 140 const u8 *in, unsigned int nbytes)
134{ 141{
135 struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm); 142 struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm);
143 int ret;
144
145 /* only use complete blocks */
146 nbytes &= ~(AES_BLOCK_SIZE - 1);
136 147
137 switch (sctx->key_len) { 148 switch (sctx->key_len) {
138 case 16: 149 case 16:
139 crypt_s390_km(KM_AES_128_DECRYPT, &sctx->key, out, in, nbytes); 150 ret = crypt_s390_km(KM_AES_128_DECRYPT, &sctx->key, out, in, nbytes);
151 BUG_ON((ret < 0) || (ret != nbytes));
140 break; 152 break;
141 case 24: 153 case 24:
142 crypt_s390_km(KM_AES_192_DECRYPT, &sctx->key, out, in, nbytes); 154 ret = crypt_s390_km(KM_AES_192_DECRYPT, &sctx->key, out, in, nbytes);
155 BUG_ON((ret < 0) || (ret != nbytes));
143 break; 156 break;
144 case 32: 157 case 32:
145 crypt_s390_km(KM_AES_256_DECRYPT, &sctx->key, out, in, nbytes); 158 ret = crypt_s390_km(KM_AES_256_DECRYPT, &sctx->key, out, in, nbytes);
159 BUG_ON((ret < 0) || (ret != nbytes));
146 break; 160 break;
147 } 161 }
148 return nbytes & ~(AES_BLOCK_SIZE - 1); 162 return nbytes;
149} 163}
150 164
151static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out, 165static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out,
152 const u8 *in, unsigned int nbytes) 166 const u8 *in, unsigned int nbytes)
153{ 167{
154 struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm); 168 struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm);
169 int ret;
170
171 /* only use complete blocks */
172 nbytes &= ~(AES_BLOCK_SIZE - 1);
155 173
156 memcpy(&sctx->iv, desc->info, AES_BLOCK_SIZE); 174 memcpy(&sctx->iv, desc->info, AES_BLOCK_SIZE);
157 switch (sctx->key_len) { 175 switch (sctx->key_len) {
158 case 16: 176 case 16:
159 crypt_s390_kmc(KMC_AES_128_ENCRYPT, &sctx->iv, out, in, nbytes); 177 ret = crypt_s390_kmc(KMC_AES_128_ENCRYPT, &sctx->iv, out, in, nbytes);
178 BUG_ON((ret < 0) || (ret != nbytes));
160 break; 179 break;
161 case 24: 180 case 24:
162 crypt_s390_kmc(KMC_AES_192_ENCRYPT, &sctx->iv, out, in, nbytes); 181 ret = crypt_s390_kmc(KMC_AES_192_ENCRYPT, &sctx->iv, out, in, nbytes);
182 BUG_ON((ret < 0) || (ret != nbytes));
163 break; 183 break;
164 case 32: 184 case 32:
165 crypt_s390_kmc(KMC_AES_256_ENCRYPT, &sctx->iv, out, in, nbytes); 185 ret = crypt_s390_kmc(KMC_AES_256_ENCRYPT, &sctx->iv, out, in, nbytes);
186 BUG_ON((ret < 0) || (ret != nbytes));
166 break; 187 break;
167 } 188 }
168 memcpy(desc->info, &sctx->iv, AES_BLOCK_SIZE); 189 memcpy(desc->info, &sctx->iv, AES_BLOCK_SIZE);
169 190
170 return nbytes & ~(AES_BLOCK_SIZE - 1); 191 return nbytes;
171} 192}
172 193
173static unsigned int aes_decrypt_cbc(const struct cipher_desc *desc, u8 *out, 194static unsigned int aes_decrypt_cbc(const struct cipher_desc *desc, u8 *out,
174 const u8 *in, unsigned int nbytes) 195 const u8 *in, unsigned int nbytes)
175{ 196{
176 struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm); 197 struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm);
198 int ret;
199
200 /* only use complete blocks */
201 nbytes &= ~(AES_BLOCK_SIZE - 1);
177 202
178 memcpy(&sctx->iv, desc->info, AES_BLOCK_SIZE); 203 memcpy(&sctx->iv, desc->info, AES_BLOCK_SIZE);
179 switch (sctx->key_len) { 204 switch (sctx->key_len) {
180 case 16: 205 case 16:
181 crypt_s390_kmc(KMC_AES_128_DECRYPT, &sctx->iv, out, in, nbytes); 206 ret = crypt_s390_kmc(KMC_AES_128_DECRYPT, &sctx->iv, out, in, nbytes);
207 BUG_ON((ret < 0) || (ret != nbytes));
182 break; 208 break;
183 case 24: 209 case 24:
184 crypt_s390_kmc(KMC_AES_192_DECRYPT, &sctx->iv, out, in, nbytes); 210 ret = crypt_s390_kmc(KMC_AES_192_DECRYPT, &sctx->iv, out, in, nbytes);
211 BUG_ON((ret < 0) || (ret != nbytes));
185 break; 212 break;
186 case 32: 213 case 32:
187 crypt_s390_kmc(KMC_AES_256_DECRYPT, &sctx->iv, out, in, nbytes); 214 ret = crypt_s390_kmc(KMC_AES_256_DECRYPT, &sctx->iv, out, in, nbytes);
215 BUG_ON((ret < 0) || (ret != nbytes));
188 break; 216 break;
189 } 217 }
190 return nbytes & ~(AES_BLOCK_SIZE - 1); 218 return nbytes;
191} 219}
192 220
193 221
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c
index a38bb2a3eef6..e3c37aa0a199 100644
--- a/arch/s390/crypto/des_s390.c
+++ b/arch/s390/crypto/des_s390.c
@@ -15,10 +15,8 @@
15 */ 15 */
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/mm.h>
19#include <linux/errno.h>
20#include <asm/scatterlist.h>
21#include <linux/crypto.h> 18#include <linux/crypto.h>
19
22#include "crypt_s390.h" 20#include "crypt_s390.h"
23#include "crypto_des.h" 21#include "crypto_des.h"
24 22
@@ -46,38 +44,92 @@ struct crypt_s390_des3_192_ctx {
46 u8 key[DES3_192_KEY_SIZE]; 44 u8 key[DES3_192_KEY_SIZE];
47}; 45};
48 46
49static int 47static int des_setkey(void *ctx, const u8 *key, unsigned int keylen,
50des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) 48 u32 *flags)
51{ 49{
52 struct crypt_s390_des_ctx *dctx; 50 struct crypt_s390_des_ctx *dctx = ctx;
53 int ret; 51 int ret;
54 52
55 dctx = ctx; 53 /* test if key is valid (not a weak key) */
56 //test if key is valid (not a weak key)
57 ret = crypto_des_check_key(key, keylen, flags); 54 ret = crypto_des_check_key(key, keylen, flags);
58 if (ret == 0){ 55 if (ret == 0)
59 memcpy(dctx->key, key, keylen); 56 memcpy(dctx->key, key, keylen);
60 }
61 return ret; 57 return ret;
62} 58}
63 59
60static void des_encrypt(void *ctx, u8 *out, const u8 *in)
61{
62 struct crypt_s390_des_ctx *dctx = ctx;
63
64 crypt_s390_km(KM_DEA_ENCRYPT, dctx->key, out, in, DES_BLOCK_SIZE);
65}
66
67static void des_decrypt(void *ctx, u8 *out, const u8 *in)
68{
69 struct crypt_s390_des_ctx *dctx = ctx;
70
71 crypt_s390_km(KM_DEA_DECRYPT, dctx->key, out, in, DES_BLOCK_SIZE);
72}
73
74static unsigned int des_encrypt_ecb(const struct cipher_desc *desc, u8 *out,
75 const u8 *in, unsigned int nbytes)
76{
77 struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm);
78 int ret;
79
80 /* only use complete blocks */
81 nbytes &= ~(DES_BLOCK_SIZE - 1);
82 ret = crypt_s390_km(KM_DEA_ENCRYPT, sctx->key, out, in, nbytes);
83 BUG_ON((ret < 0) || (ret != nbytes));
84
85 return nbytes;
86}
64 87
65static void 88static unsigned int des_decrypt_ecb(const struct cipher_desc *desc, u8 *out,
66des_encrypt(void *ctx, u8 *dst, const u8 *src) 89 const u8 *in, unsigned int nbytes)
67{ 90{
68 struct crypt_s390_des_ctx *dctx; 91 struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm);
92 int ret;
93
94 /* only use complete blocks */
95 nbytes &= ~(DES_BLOCK_SIZE - 1);
96 ret = crypt_s390_km(KM_DEA_DECRYPT, sctx->key, out, in, nbytes);
97 BUG_ON((ret < 0) || (ret != nbytes));
69 98
70 dctx = ctx; 99 return nbytes;
71 crypt_s390_km(KM_DEA_ENCRYPT, dctx->key, dst, src, DES_BLOCK_SIZE);
72} 100}
73 101
74static void 102static unsigned int des_encrypt_cbc(const struct cipher_desc *desc, u8 *out,
75des_decrypt(void *ctx, u8 *dst, const u8 *src) 103 const u8 *in, unsigned int nbytes)
76{ 104{
77 struct crypt_s390_des_ctx *dctx; 105 struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm);
106 int ret;
78 107
79 dctx = ctx; 108 /* only use complete blocks */
80 crypt_s390_km(KM_DEA_DECRYPT, dctx->key, dst, src, DES_BLOCK_SIZE); 109 nbytes &= ~(DES_BLOCK_SIZE - 1);
110
111 memcpy(sctx->iv, desc->info, DES_BLOCK_SIZE);
112 ret = crypt_s390_kmc(KMC_DEA_ENCRYPT, &sctx->iv, out, in, nbytes);
113 BUG_ON((ret < 0) || (ret != nbytes));
114
115 memcpy(desc->info, sctx->iv, DES_BLOCK_SIZE);
116 return nbytes;
117}
118
119static unsigned int des_decrypt_cbc(const struct cipher_desc *desc, u8 *out,
120 const u8 *in, unsigned int nbytes)
121{
122 struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm);
123 int ret;
124
125 /* only use complete blocks */
126 nbytes &= ~(DES_BLOCK_SIZE - 1);
127
128 memcpy(&sctx->iv, desc->info, DES_BLOCK_SIZE);
129 ret = crypt_s390_kmc(KMC_DEA_DECRYPT, &sctx->iv, out, in, nbytes);
130 BUG_ON((ret < 0) || (ret != nbytes));
131
132 return nbytes;
81} 133}
82 134
83static struct crypto_alg des_alg = { 135static struct crypto_alg des_alg = {
@@ -87,12 +139,19 @@ static struct crypto_alg des_alg = {
87 .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), 139 .cra_ctxsize = sizeof(struct crypt_s390_des_ctx),
88 .cra_module = THIS_MODULE, 140 .cra_module = THIS_MODULE,
89 .cra_list = LIST_HEAD_INIT(des_alg.cra_list), 141 .cra_list = LIST_HEAD_INIT(des_alg.cra_list),
90 .cra_u = { .cipher = { 142 .cra_u = {
91 .cia_min_keysize = DES_KEY_SIZE, 143 .cipher = {
92 .cia_max_keysize = DES_KEY_SIZE, 144 .cia_min_keysize = DES_KEY_SIZE,
93 .cia_setkey = des_setkey, 145 .cia_max_keysize = DES_KEY_SIZE,
94 .cia_encrypt = des_encrypt, 146 .cia_setkey = des_setkey,
95 .cia_decrypt = des_decrypt } } 147 .cia_encrypt = des_encrypt,
148 .cia_decrypt = des_decrypt,
149 .cia_encrypt_ecb = des_encrypt_ecb,
150 .cia_decrypt_ecb = des_decrypt_ecb,
151 .cia_encrypt_cbc = des_encrypt_cbc,
152 .cia_decrypt_cbc = des_decrypt_cbc,
153 }
154 }
96}; 155};
97 156
98/* 157/*
@@ -107,20 +166,18 @@ static struct crypto_alg des_alg = {
107 * Implementers MUST reject keys that exhibit this property. 166 * Implementers MUST reject keys that exhibit this property.
108 * 167 *
109 */ 168 */
110static int 169static int des3_128_setkey(void *ctx, const u8 *key, unsigned int keylen,
111des3_128_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) 170 u32 *flags)
112{ 171{
113 int i, ret; 172 int i, ret;
114 struct crypt_s390_des3_128_ctx *dctx; 173 struct crypt_s390_des3_128_ctx *dctx = ctx;
115 const u8* temp_key = key; 174 const u8* temp_key = key;
116 175
117 dctx = ctx;
118 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) { 176 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) {
119
120 *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; 177 *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
121 return -EINVAL; 178 return -EINVAL;
122 } 179 }
123 for (i = 0; i < 2; i++, temp_key += DES_KEY_SIZE) { 180 for (i = 0; i < 2; i++, temp_key += DES_KEY_SIZE) {
124 ret = crypto_des_check_key(temp_key, DES_KEY_SIZE, flags); 181 ret = crypto_des_check_key(temp_key, DES_KEY_SIZE, flags);
125 if (ret < 0) 182 if (ret < 0)
126 return ret; 183 return ret;
@@ -129,24 +186,85 @@ des3_128_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
129 return 0; 186 return 0;
130} 187}
131 188
132static void 189static void des3_128_encrypt(void *ctx, u8 *dst, const u8 *src)
133des3_128_encrypt(void *ctx, u8 *dst, const u8 *src)
134{ 190{
135 struct crypt_s390_des3_128_ctx *dctx; 191 struct crypt_s390_des3_128_ctx *dctx = ctx;
136 192
137 dctx = ctx;
138 crypt_s390_km(KM_TDEA_128_ENCRYPT, dctx->key, dst, (void*)src, 193 crypt_s390_km(KM_TDEA_128_ENCRYPT, dctx->key, dst, (void*)src,
139 DES3_128_BLOCK_SIZE); 194 DES3_128_BLOCK_SIZE);
140} 195}
141 196
142static void 197static void des3_128_decrypt(void *ctx, u8 *dst, const u8 *src)
143des3_128_decrypt(void *ctx, u8 *dst, const u8 *src)
144{ 198{
145 struct crypt_s390_des3_128_ctx *dctx; 199 struct crypt_s390_des3_128_ctx *dctx = ctx;
146 200
147 dctx = ctx;
148 crypt_s390_km(KM_TDEA_128_DECRYPT, dctx->key, dst, (void*)src, 201 crypt_s390_km(KM_TDEA_128_DECRYPT, dctx->key, dst, (void*)src,
149 DES3_128_BLOCK_SIZE); 202 DES3_128_BLOCK_SIZE);
203}
204
205static unsigned int des3_128_encrypt_ecb(const struct cipher_desc *desc,
206 u8 *out, const u8 *in,
207 unsigned int nbytes)
208{
209 struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm);
210 int ret;
211
212 /* only use complete blocks */
213 nbytes &= ~(DES3_128_BLOCK_SIZE - 1);
214 ret = crypt_s390_km(KM_TDEA_128_ENCRYPT, sctx->key, out, in, nbytes);
215 BUG_ON((ret < 0) || (ret != nbytes));
216
217 return nbytes;
218}
219
220static unsigned int des3_128_decrypt_ecb(const struct cipher_desc *desc,
221 u8 *out, const u8 *in,
222 unsigned int nbytes)
223{
224 struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm);
225 int ret;
226
227 /* only use complete blocks */
228 nbytes &= ~(DES3_128_BLOCK_SIZE - 1);
229 ret = crypt_s390_km(KM_TDEA_128_DECRYPT, sctx->key, out, in, nbytes);
230 BUG_ON((ret < 0) || (ret != nbytes));
231
232 return nbytes;
233}
234
235static unsigned int des3_128_encrypt_cbc(const struct cipher_desc *desc,
236 u8 *out, const u8 *in,
237 unsigned int nbytes)
238{
239 struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm);
240 int ret;
241
242 /* only use complete blocks */
243 nbytes &= ~(DES3_128_BLOCK_SIZE - 1);
244
245 memcpy(sctx->iv, desc->info, DES3_128_BLOCK_SIZE);
246 ret = crypt_s390_kmc(KMC_TDEA_128_ENCRYPT, &sctx->iv, out, in, nbytes);
247 BUG_ON((ret < 0) || (ret != nbytes));
248
249 memcpy(desc->info, sctx->iv, DES3_128_BLOCK_SIZE);
250 return nbytes;
251}
252
253static unsigned int des3_128_decrypt_cbc(const struct cipher_desc *desc,
254 u8 *out, const u8 *in,
255 unsigned int nbytes)
256{
257 struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm);
258 int ret;
259
260 /* only use complete blocks */
261 nbytes &= ~(DES3_128_BLOCK_SIZE - 1);
262
263 memcpy(&sctx->iv, desc->info, DES3_128_BLOCK_SIZE);
264 ret = crypt_s390_kmc(KMC_TDEA_128_DECRYPT, &sctx->iv, out, in, nbytes);
265 BUG_ON((ret < 0) || (ret != nbytes));
266
267 return nbytes;
150} 268}
151 269
152static struct crypto_alg des3_128_alg = { 270static struct crypto_alg des3_128_alg = {
@@ -156,12 +274,19 @@ static struct crypto_alg des3_128_alg = {
156 .cra_ctxsize = sizeof(struct crypt_s390_des3_128_ctx), 274 .cra_ctxsize = sizeof(struct crypt_s390_des3_128_ctx),
157 .cra_module = THIS_MODULE, 275 .cra_module = THIS_MODULE,
158 .cra_list = LIST_HEAD_INIT(des3_128_alg.cra_list), 276 .cra_list = LIST_HEAD_INIT(des3_128_alg.cra_list),
159 .cra_u = { .cipher = { 277 .cra_u = {
160 .cia_min_keysize = DES3_128_KEY_SIZE, 278 .cipher = {
161 .cia_max_keysize = DES3_128_KEY_SIZE, 279 .cia_min_keysize = DES3_128_KEY_SIZE,
162 .cia_setkey = des3_128_setkey, 280 .cia_max_keysize = DES3_128_KEY_SIZE,
163 .cia_encrypt = des3_128_encrypt, 281 .cia_setkey = des3_128_setkey,
164 .cia_decrypt = des3_128_decrypt } } 282 .cia_encrypt = des3_128_encrypt,
283 .cia_decrypt = des3_128_decrypt,
284 .cia_encrypt_ecb = des3_128_encrypt_ecb,
285 .cia_decrypt_ecb = des3_128_decrypt_ecb,
286 .cia_encrypt_cbc = des3_128_encrypt_cbc,
287 .cia_decrypt_cbc = des3_128_decrypt_cbc,
288 }
289 }
165}; 290};
166 291
167/* 292/*
@@ -177,50 +302,108 @@ static struct crypto_alg des3_128_alg = {
177 * property. 302 * property.
178 * 303 *
179 */ 304 */
180static int 305static int des3_192_setkey(void *ctx, const u8 *key, unsigned int keylen,
181des3_192_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) 306 u32 *flags)
182{ 307{
183 int i, ret; 308 int i, ret;
184 struct crypt_s390_des3_192_ctx *dctx; 309 struct crypt_s390_des3_192_ctx *dctx = ctx;
185 const u8* temp_key; 310 const u8* temp_key = key;
186 311
187 dctx = ctx;
188 temp_key = key;
189 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && 312 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
190 memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2], 313 memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
191 DES_KEY_SIZE))) { 314 DES_KEY_SIZE))) {
192 315
193 *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; 316 *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
194 return -EINVAL; 317 return -EINVAL;
195 } 318 }
196 for (i = 0; i < 3; i++, temp_key += DES_KEY_SIZE) { 319 for (i = 0; i < 3; i++, temp_key += DES_KEY_SIZE) {
197 ret = crypto_des_check_key(temp_key, DES_KEY_SIZE, flags); 320 ret = crypto_des_check_key(temp_key, DES_KEY_SIZE, flags);
198 if (ret < 0){ 321 if (ret < 0)
199 return ret; 322 return ret;
200 }
201 } 323 }
202 memcpy(dctx->key, key, keylen); 324 memcpy(dctx->key, key, keylen);
203 return 0; 325 return 0;
204} 326}
205 327
206static void 328static void des3_192_encrypt(void *ctx, u8 *dst, const u8 *src)
207des3_192_encrypt(void *ctx, u8 *dst, const u8 *src)
208{ 329{
209 struct crypt_s390_des3_192_ctx *dctx; 330 struct crypt_s390_des3_192_ctx *dctx = ctx;
210 331
211 dctx = ctx;
212 crypt_s390_km(KM_TDEA_192_ENCRYPT, dctx->key, dst, (void*)src, 332 crypt_s390_km(KM_TDEA_192_ENCRYPT, dctx->key, dst, (void*)src,
213 DES3_192_BLOCK_SIZE); 333 DES3_192_BLOCK_SIZE);
214} 334}
215 335
216static void 336static void des3_192_decrypt(void *ctx, u8 *dst, const u8 *src)
217des3_192_decrypt(void *ctx, u8 *dst, const u8 *src)
218{ 337{
219 struct crypt_s390_des3_192_ctx *dctx; 338 struct crypt_s390_des3_192_ctx *dctx = ctx;
220 339
221 dctx = ctx;
222 crypt_s390_km(KM_TDEA_192_DECRYPT, dctx->key, dst, (void*)src, 340 crypt_s390_km(KM_TDEA_192_DECRYPT, dctx->key, dst, (void*)src,
223 DES3_192_BLOCK_SIZE); 341 DES3_192_BLOCK_SIZE);
342}
343
344static unsigned int des3_192_encrypt_ecb(const struct cipher_desc *desc,
345 u8 *out, const u8 *in,
346 unsigned int nbytes)
347{
348 struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm);
349 int ret;
350
351 /* only use complete blocks */
352 nbytes &= ~(DES3_192_BLOCK_SIZE - 1);
353 ret = crypt_s390_km(KM_TDEA_192_ENCRYPT, sctx->key, out, in, nbytes);
354 BUG_ON((ret < 0) || (ret != nbytes));
355
356 return nbytes;
357}
358
359static unsigned int des3_192_decrypt_ecb(const struct cipher_desc *desc,
360 u8 *out, const u8 *in,
361 unsigned int nbytes)
362{
363 struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm);
364 int ret;
365
366 /* only use complete blocks */
367 nbytes &= ~(DES3_192_BLOCK_SIZE - 1);
368 ret = crypt_s390_km(KM_TDEA_192_DECRYPT, sctx->key, out, in, nbytes);
369 BUG_ON((ret < 0) || (ret != nbytes));
370
371 return nbytes;
372}
373
374static unsigned int des3_192_encrypt_cbc(const struct cipher_desc *desc,
375 u8 *out, const u8 *in,
376 unsigned int nbytes)
377{
378 struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm);
379 int ret;
380
381 /* only use complete blocks */
382 nbytes &= ~(DES3_192_BLOCK_SIZE - 1);
383
384 memcpy(sctx->iv, desc->info, DES3_192_BLOCK_SIZE);
385 ret = crypt_s390_kmc(KMC_TDEA_192_ENCRYPT, &sctx->iv, out, in, nbytes);
386 BUG_ON((ret < 0) || (ret != nbytes));
387
388 memcpy(desc->info, sctx->iv, DES3_192_BLOCK_SIZE);
389 return nbytes;
390}
391
392static unsigned int des3_192_decrypt_cbc(const struct cipher_desc *desc,
393 u8 *out, const u8 *in,
394 unsigned int nbytes)
395{
396 struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm);
397 int ret;
398
399 /* only use complete blocks */
400 nbytes &= ~(DES3_192_BLOCK_SIZE - 1);
401
402 memcpy(&sctx->iv, desc->info, DES3_192_BLOCK_SIZE);
403 ret = crypt_s390_kmc(KMC_TDEA_192_DECRYPT, &sctx->iv, out, in, nbytes);
404 BUG_ON((ret < 0) || (ret != nbytes));
405
406 return nbytes;
224} 407}
225 408
226static struct crypto_alg des3_192_alg = { 409static struct crypto_alg des3_192_alg = {
@@ -230,44 +413,43 @@ static struct crypto_alg des3_192_alg = {
230 .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), 413 .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx),
231 .cra_module = THIS_MODULE, 414 .cra_module = THIS_MODULE,
232 .cra_list = LIST_HEAD_INIT(des3_192_alg.cra_list), 415 .cra_list = LIST_HEAD_INIT(des3_192_alg.cra_list),
233 .cra_u = { .cipher = { 416 .cra_u = {
234 .cia_min_keysize = DES3_192_KEY_SIZE, 417 .cipher = {
235 .cia_max_keysize = DES3_192_KEY_SIZE, 418 .cia_min_keysize = DES3_192_KEY_SIZE,
236 .cia_setkey = des3_192_setkey, 419 .cia_max_keysize = DES3_192_KEY_SIZE,
237 .cia_encrypt = des3_192_encrypt, 420 .cia_setkey = des3_192_setkey,
238 .cia_decrypt = des3_192_decrypt } } 421 .cia_encrypt = des3_192_encrypt,
422 .cia_decrypt = des3_192_decrypt,
423 .cia_encrypt_ecb = des3_192_encrypt_ecb,
424 .cia_decrypt_ecb = des3_192_decrypt_ecb,
425 .cia_encrypt_cbc = des3_192_encrypt_cbc,
426 .cia_decrypt_cbc = des3_192_decrypt_cbc,
427 }
428 }
239}; 429};
240 430
241 431static int init(void)
242
243static int
244init(void)
245{ 432{
246 int ret; 433 int ret = 0;
247 434
248 if (!crypt_s390_func_available(KM_DEA_ENCRYPT) || 435 if (!crypt_s390_func_available(KM_DEA_ENCRYPT) ||
249 !crypt_s390_func_available(KM_TDEA_128_ENCRYPT) || 436 !crypt_s390_func_available(KM_TDEA_128_ENCRYPT) ||
250 !crypt_s390_func_available(KM_TDEA_192_ENCRYPT)){ 437 !crypt_s390_func_available(KM_TDEA_192_ENCRYPT))
251 return -ENOSYS; 438 return -ENOSYS;
252 }
253 439
254 ret = 0; 440 ret |= (crypto_register_alg(&des_alg) == 0) ? 0:1;
255 ret |= (crypto_register_alg(&des_alg) == 0)? 0:1; 441 ret |= (crypto_register_alg(&des3_128_alg) == 0) ? 0:2;
256 ret |= (crypto_register_alg(&des3_128_alg) == 0)? 0:2; 442 ret |= (crypto_register_alg(&des3_192_alg) == 0) ? 0:4;
257 ret |= (crypto_register_alg(&des3_192_alg) == 0)? 0:4; 443 if (ret) {
258 if (ret){
259 crypto_unregister_alg(&des3_192_alg); 444 crypto_unregister_alg(&des3_192_alg);
260 crypto_unregister_alg(&des3_128_alg); 445 crypto_unregister_alg(&des3_128_alg);
261 crypto_unregister_alg(&des_alg); 446 crypto_unregister_alg(&des_alg);
262 return -EEXIST; 447 return -EEXIST;
263 } 448 }
264
265 printk(KERN_INFO "crypt_s390: des_s390 loaded.\n");
266 return 0; 449 return 0;
267} 450}
268 451
269static void __exit 452static void __exit fini(void)
270fini(void)
271{ 453{
272 crypto_unregister_alg(&des3_192_alg); 454 crypto_unregister_alg(&des3_192_alg);
273 crypto_unregister_alg(&des3_128_alg); 455 crypto_unregister_alg(&des3_128_alg);
diff --git a/arch/s390/crypto/sha256_s390.c b/arch/s390/crypto/sha256_s390.c
index b75bdbd476c7..1ec5e92b3454 100644
--- a/arch/s390/crypto/sha256_s390.c
+++ b/arch/s390/crypto/sha256_s390.c
@@ -51,6 +51,7 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len)
51{ 51{
52 struct s390_sha256_ctx *sctx = ctx; 52 struct s390_sha256_ctx *sctx = ctx;
53 unsigned int index; 53 unsigned int index;
54 int ret;
54 55
55 /* how much is already in the buffer? */ 56 /* how much is already in the buffer? */
56 index = sctx->count / 8 & 0x3f; 57 index = sctx->count / 8 & 0x3f;
@@ -58,15 +59,29 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len)
58 /* update message bit length */ 59 /* update message bit length */
59 sctx->count += len * 8; 60 sctx->count += len * 8;
60 61
61 /* process one block */ 62 if ((index + len) < SHA256_BLOCK_SIZE)
62 if ((index + len) >= SHA256_BLOCK_SIZE) { 63 goto store;
64
65 /* process one stored block */
66 if (index) {
63 memcpy(sctx->buf + index, data, SHA256_BLOCK_SIZE - index); 67 memcpy(sctx->buf + index, data, SHA256_BLOCK_SIZE - index);
64 crypt_s390_kimd(KIMD_SHA_256, sctx->state, sctx->buf, 68 ret = crypt_s390_kimd(KIMD_SHA_256, sctx->state, sctx->buf,
65 SHA256_BLOCK_SIZE); 69 SHA256_BLOCK_SIZE);
70 BUG_ON(ret != SHA256_BLOCK_SIZE);
66 data += SHA256_BLOCK_SIZE - index; 71 data += SHA256_BLOCK_SIZE - index;
67 len -= SHA256_BLOCK_SIZE - index; 72 len -= SHA256_BLOCK_SIZE - index;
68 } 73 }
69 74
75 /* process as many blocks as possible */
76 if (len >= SHA256_BLOCK_SIZE) {
77 ret = crypt_s390_kimd(KIMD_SHA_256, sctx->state, data,
78 len & ~(SHA256_BLOCK_SIZE - 1));
79 BUG_ON(ret != (len & ~(SHA256_BLOCK_SIZE - 1)));
80 data += ret;
81 len -= ret;
82 }
83
84store:
70 /* anything left? */ 85 /* anything left? */
71 if (len) 86 if (len)
72 memcpy(sctx->buf + index , data, len); 87 memcpy(sctx->buf + index , data, len);
@@ -119,9 +134,9 @@ static struct crypto_alg alg = {
119 .cra_list = LIST_HEAD_INIT(alg.cra_list), 134 .cra_list = LIST_HEAD_INIT(alg.cra_list),
120 .cra_u = { .digest = { 135 .cra_u = { .digest = {
121 .dia_digestsize = SHA256_DIGEST_SIZE, 136 .dia_digestsize = SHA256_DIGEST_SIZE,
122 .dia_init = sha256_init, 137 .dia_init = sha256_init,
123 .dia_update = sha256_update, 138 .dia_update = sha256_update,
124 .dia_final = sha256_final } } 139 .dia_final = sha256_final } }
125}; 140};
126 141
127static int init(void) 142static int init(void)
diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
index 2ff90a1a1056..008c74526fd3 100644
--- a/arch/s390/kernel/process.c
+++ b/arch/s390/kernel/process.c
@@ -58,10 +58,18 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
58 */ 58 */
59unsigned long thread_saved_pc(struct task_struct *tsk) 59unsigned long thread_saved_pc(struct task_struct *tsk)
60{ 60{
61 struct stack_frame *sf; 61 struct stack_frame *sf, *low, *high;
62 62
63 sf = (struct stack_frame *) tsk->thread.ksp; 63 if (!tsk || !task_stack_page(tsk))
64 sf = (struct stack_frame *) sf->back_chain; 64 return 0;
65 low = task_stack_page(tsk);
66 high = (struct stack_frame *) task_pt_regs(tsk);
67 sf = (struct stack_frame *) (tsk->thread.ksp & PSW_ADDR_INSN);
68 if (sf <= low || sf > high)
69 return 0;
70 sf = (struct stack_frame *) (sf->back_chain & PSW_ADDR_INSN);
71 if (sf <= low || sf > high)
72 return 0;
65 return sf->gprs[8]; 73 return sf->gprs[8];
66} 74}
67 75
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index b03847d100d9..de8784267473 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -268,7 +268,7 @@ static void do_machine_restart_nonsmp(char * __unused)
268 reipl_diag(); 268 reipl_diag();
269 269
270 if (MACHINE_IS_VM) 270 if (MACHINE_IS_VM)
271 cpcmd ("IPL", NULL, 0); 271 cpcmd ("IPL", NULL, 0, NULL);
272 else 272 else
273 reipl (0x10000 | S390_lowcore.ipl_device); 273 reipl (0x10000 | S390_lowcore.ipl_device);
274} 274}
@@ -276,14 +276,14 @@ static void do_machine_restart_nonsmp(char * __unused)
276static void do_machine_halt_nonsmp(void) 276static void do_machine_halt_nonsmp(void)
277{ 277{
278 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0) 278 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
279 cpcmd(vmhalt_cmd, NULL, 0); 279 cpcmd(vmhalt_cmd, NULL, 0, NULL);
280 signal_processor(smp_processor_id(), sigp_stop_and_store_status); 280 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
281} 281}
282 282
283static void do_machine_power_off_nonsmp(void) 283static void do_machine_power_off_nonsmp(void)
284{ 284{
285 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0) 285 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
286 cpcmd(vmpoff_cmd, NULL, 0); 286 cpcmd(vmpoff_cmd, NULL, 0, NULL);
287 signal_processor(smp_processor_id(), sigp_stop_and_store_status); 287 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
288} 288}
289 289
@@ -315,6 +315,11 @@ void machine_power_off(void)
315 _machine_power_off(); 315 _machine_power_off();
316} 316}
317 317
318/*
319 * Dummy power off function.
320 */
321void (*pm_power_off)(void) = machine_power_off;
322
318static void __init 323static void __init
319add_memory_hole(unsigned long start, unsigned long end) 324add_memory_hole(unsigned long start, unsigned long end)
320{ 325{
diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
index b0d8ca8e5eeb..7c0fe152a111 100644
--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -214,7 +214,7 @@ void account_ticks(struct pt_regs *regs)
214#endif 214#endif
215 215
216#ifdef CONFIG_VIRT_CPU_ACCOUNTING 216#ifdef CONFIG_VIRT_CPU_ACCOUNTING
217 account_user_vtime(current); 217 account_tick_vtime(current);
218#else 218#else
219 while (ticks--) 219 while (ticks--)
220 update_process_times(user_mode(regs)); 220 update_process_times(user_mode(regs));
diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 22a895ecb7a4..dfe6f0856617 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -32,7 +32,7 @@ DEFINE_PER_CPU(struct vtimer_queue, virt_cpu_timer);
32 * Update process times based on virtual cpu times stored by entry.S 32 * Update process times based on virtual cpu times stored by entry.S
33 * to the lowcore fields user_timer, system_timer & steal_clock. 33 * to the lowcore fields user_timer, system_timer & steal_clock.
34 */ 34 */
35void account_user_vtime(struct task_struct *tsk) 35void account_tick_vtime(struct task_struct *tsk)
36{ 36{
37 cputime_t cputime; 37 cputime_t cputime;
38 __u64 timer, clock; 38 __u64 timer, clock;
@@ -76,6 +76,31 @@ void account_user_vtime(struct task_struct *tsk)
76 * Update process times based on virtual cpu times stored by entry.S 76 * Update process times based on virtual cpu times stored by entry.S
77 * to the lowcore fields user_timer, system_timer & steal_clock. 77 * to the lowcore fields user_timer, system_timer & steal_clock.
78 */ 78 */
79void account_vtime(struct task_struct *tsk)
80{
81 cputime_t cputime;
82 __u64 timer;
83
84 timer = S390_lowcore.last_update_timer;
85 asm volatile (" STPT %0" /* Store current cpu timer value */
86 : "=m" (S390_lowcore.last_update_timer) );
87 S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer;
88
89 cputime = S390_lowcore.user_timer >> 12;
90 S390_lowcore.user_timer -= cputime << 12;
91 S390_lowcore.steal_clock -= cputime << 12;
92 account_user_time(tsk, cputime);
93
94 cputime = S390_lowcore.system_timer >> 12;
95 S390_lowcore.system_timer -= cputime << 12;
96 S390_lowcore.steal_clock -= cputime << 12;
97 account_system_time(tsk, 0, cputime);
98}
99
100/*
101 * Update process times based on virtual cpu times stored by entry.S
102 * to the lowcore fields user_timer, system_timer & steal_clock.
103 */
79void account_system_vtime(struct task_struct *tsk) 104void account_system_vtime(struct task_struct *tsk)
80{ 105{
81 cputime_t cputime; 106 cputime_t cputime;
diff --git a/arch/s390/lib/Makefile b/arch/s390/lib/Makefile
index d9b97b3c597f..f20b51ff1d86 100644
--- a/arch/s390/lib/Makefile
+++ b/arch/s390/lib/Makefile
@@ -4,5 +4,6 @@
4 4
5EXTRA_AFLAGS := -traditional 5EXTRA_AFLAGS := -traditional
6 6
7lib-y += delay.o string.o spinlock.o 7lib-y += delay.o string.o
8lib-y += $(if $(CONFIG_64BIT),uaccess64.o,uaccess.o) 8lib-y += $(if $(CONFIG_64BIT),uaccess64.o,uaccess.o)
9lib-$(CONFIG_SMP) += spinlock.o \ No newline at end of file
diff --git a/arch/s390/lib/spinlock.c b/arch/s390/lib/spinlock.c
index 68d79c502081..60f80a4eed4e 100644
--- a/arch/s390/lib/spinlock.c
+++ b/arch/s390/lib/spinlock.c
@@ -13,7 +13,6 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <asm/io.h> 14#include <asm/io.h>
15 15
16atomic_t spin_retry_counter;
17int spin_retry = 1000; 16int spin_retry = 1000;
18 17
19/** 18/**
@@ -45,7 +44,6 @@ _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc)
45 _diag44(); 44 _diag44();
46 count = spin_retry; 45 count = spin_retry;
47 } 46 }
48 atomic_inc(&spin_retry_counter);
49 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0) 47 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
50 return; 48 return;
51 } 49 }
@@ -58,7 +56,6 @@ _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc)
58 int count = spin_retry; 56 int count = spin_retry;
59 57
60 while (count-- > 0) { 58 while (count-- > 0) {
61 atomic_inc(&spin_retry_counter);
62 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0) 59 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
63 return 1; 60 return 1;
64 } 61 }
@@ -77,7 +74,6 @@ _raw_read_lock_wait(raw_rwlock_t *rw)
77 _diag44(); 74 _diag44();
78 count = spin_retry; 75 count = spin_retry;
79 } 76 }
80 atomic_inc(&spin_retry_counter);
81 old = rw->lock & 0x7fffffffU; 77 old = rw->lock & 0x7fffffffU;
82 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old) 78 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
83 return; 79 return;
@@ -92,7 +88,6 @@ _raw_read_trylock_retry(raw_rwlock_t *rw)
92 int count = spin_retry; 88 int count = spin_retry;
93 89
94 while (count-- > 0) { 90 while (count-- > 0) {
95 atomic_inc(&spin_retry_counter);
96 old = rw->lock & 0x7fffffffU; 91 old = rw->lock & 0x7fffffffU;
97 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old) 92 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
98 return 1; 93 return 1;
@@ -111,7 +106,6 @@ _raw_write_lock_wait(raw_rwlock_t *rw)
111 _diag44(); 106 _diag44();
112 count = spin_retry; 107 count = spin_retry;
113 } 108 }
114 atomic_inc(&spin_retry_counter);
115 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0) 109 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
116 return; 110 return;
117 } 111 }
@@ -124,7 +118,6 @@ _raw_write_trylock_retry(raw_rwlock_t *rw)
124 int count = spin_retry; 118 int count = spin_retry;
125 119
126 while (count-- > 0) { 120 while (count-- > 0) {
127 atomic_inc(&spin_retry_counter);
128 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0) 121 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
129 return 1; 122 return 1;
130 } 123 }