Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: acomp - Remove request chaining

Request chaining requires the user to do too much book keeping.
Remove it from acomp.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+35 -119
+33 -84
crypto/acompress.c
··· 177 177 state->data = req->base.data; 178 178 req->base.complete = cplt; 179 179 req->base.data = state; 180 - state->req0 = req; 181 180 } 182 181 183 182 static void acomp_restore_req(struct acomp_req *req) ··· 187 188 req->base.data = state->data; 188 189 } 189 190 190 - static void acomp_reqchain_virt(struct acomp_req_chain *state, int err) 191 + static void acomp_reqchain_virt(struct acomp_req *req) 191 192 { 192 - struct acomp_req *req = state->cur; 193 + struct acomp_req_chain *state = &req->chain; 193 194 unsigned int slen = req->slen; 194 195 unsigned int dlen = req->dlen; 195 - 196 - req->base.err = err; 197 - state = &req->chain; 198 196 199 197 if (state->flags & CRYPTO_ACOMP_REQ_SRC_VIRT) 200 198 acomp_request_set_src_dma(req, state->src, slen); 201 199 else if (state->flags & CRYPTO_ACOMP_REQ_SRC_FOLIO) 202 - acomp_request_set_src_folio(req, state->sfolio, state->soff, slen); 200 + acomp_request_set_src_folio(req, state->sfolio, req->soff, slen); 203 201 if (state->flags & CRYPTO_ACOMP_REQ_DST_VIRT) 204 202 acomp_request_set_dst_dma(req, state->dst, dlen); 205 203 else if (state->flags & CRYPTO_ACOMP_REQ_DST_FOLIO) 206 - acomp_request_set_dst_folio(req, state->dfolio, state->doff, dlen); 204 + acomp_request_set_dst_folio(req, state->dfolio, req->doff, dlen); 207 205 } 208 206 209 207 static void acomp_virt_to_sg(struct acomp_req *req) ··· 225 229 size_t off = req->soff; 226 230 227 231 state->sfolio = folio; 228 - state->soff = off; 229 232 sg_init_table(&state->ssg, 1); 230 233 sg_set_page(&state->ssg, folio_page(folio, off / PAGE_SIZE), 231 234 slen, off % PAGE_SIZE); ··· 244 249 size_t off = req->doff; 245 250 246 251 state->dfolio = folio; 247 - state->doff = off; 248 252 sg_init_table(&state->dsg, 1); 249 253 sg_set_page(&state->dsg, folio_page(folio, off / PAGE_SIZE), 250 254 dlen, off % PAGE_SIZE); ··· 251 257 } 252 258 } 253 259 254 - static int acomp_do_nondma(struct acomp_req_chain *state, 255 - struct acomp_req *req) 260 + static int acomp_do_nondma(struct acomp_req *req, bool comp) 256 261 { 257 262 u32 keep = CRYPTO_ACOMP_REQ_SRC_VIRT | 258 263 CRYPTO_ACOMP_REQ_SRC_NONDMA | ··· 268 275 fbreq->slen = req->slen; 269 276 fbreq->dlen = req->dlen; 270 277 271 - if (state->op == crypto_acomp_reqtfm(req)->compress) 278 + if (comp) 272 279 err = crypto_acomp_compress(fbreq); 273 280 else 274 281 err = crypto_acomp_decompress(fbreq); ··· 277 284 return err; 278 285 } 279 286 280 - static int acomp_do_one_req(struct acomp_req_chain *state, 281 - struct acomp_req *req) 287 + static int acomp_do_one_req(struct acomp_req *req, bool comp) 282 288 { 283 - state->cur = req; 284 - 285 289 if (acomp_request_isnondma(req)) 286 - return acomp_do_nondma(state, req); 290 + return acomp_do_nondma(req, comp); 287 291 288 292 acomp_virt_to_sg(req); 289 - return state->op(req); 293 + return comp ? crypto_acomp_reqtfm(req)->compress(req) : 294 + crypto_acomp_reqtfm(req)->decompress(req); 290 295 } 291 296 292 - static int acomp_reqchain_finish(struct acomp_req *req0, int err, u32 mask) 297 + static int acomp_reqchain_finish(struct acomp_req *req, int err) 293 298 { 294 - struct acomp_req_chain *state = req0->base.data; 295 - struct acomp_req *req = state->cur; 296 - struct acomp_req *n; 297 - 298 - acomp_reqchain_virt(state, err); 299 - 300 - if (req != req0) 301 - list_add_tail(&req->base.list, &req0->base.list); 302 - 303 - list_for_each_entry_safe(req, n, &state->head, base.list) { 304 - list_del_init(&req->base.list); 305 - 306 - req->base.flags &= mask; 307 - req->base.complete = acomp_reqchain_done; 308 - req->base.data = state; 309 - 310 - err = acomp_do_one_req(state, req); 311 - 312 - if (err == -EINPROGRESS) { 313 - if (!list_empty(&state->head)) 314 - err = -EBUSY; 315 - goto out; 316 - } 317 - 318 - if (err == -EBUSY) 319 - goto out; 320 - 321 - acomp_reqchain_virt(state, err); 322 - list_add_tail(&req->base.list, &req0->base.list); 323 - } 324 - 325 - acomp_restore_req(req0); 326 - 327 - out: 299 + acomp_reqchain_virt(req); 300 + acomp_restore_req(req); 328 301 return err; 329 302 } 330 303 331 304 static void acomp_reqchain_done(void *data, int err) 332 305 { 333 - struct acomp_req_chain *state = data; 334 - crypto_completion_t compl = state->compl; 306 + struct acomp_req *req = data; 307 + crypto_completion_t compl; 335 308 336 - data = state->data; 309 + compl = req->chain.compl; 310 + data = req->chain.data; 337 311 338 - if (err == -EINPROGRESS) { 339 - if (!list_empty(&state->head)) 340 - return; 312 + if (err == -EINPROGRESS) 341 313 goto notify; 342 - } 343 314 344 - err = acomp_reqchain_finish(state->req0, err, 345 - CRYPTO_TFM_REQ_MAY_BACKLOG); 346 - if (err == -EBUSY) 347 - return; 315 + err = acomp_reqchain_finish(req, err); 348 316 349 317 notify: 350 318 compl(data, err); 351 319 } 352 320 353 - static int acomp_do_req_chain(struct acomp_req *req, 354 - int (*op)(struct acomp_req *req)) 321 + static int acomp_do_req_chain(struct acomp_req *req, bool comp) 355 322 { 356 - struct crypto_acomp *tfm = crypto_acomp_reqtfm(req); 357 - struct acomp_req_chain *state; 358 323 int err; 359 324 360 - if (crypto_acomp_req_chain(tfm) || 361 - (!acomp_request_chained(req) && acomp_request_issg(req))) 362 - return op(req); 363 - 364 325 acomp_save_req(req, acomp_reqchain_done); 365 - state = req->base.data; 366 326 367 - state->op = op; 368 - state->src = NULL; 369 - INIT_LIST_HEAD(&state->head); 370 - list_splice_init(&req->base.list, &state->head); 371 - 372 - err = acomp_do_one_req(state, req); 327 + err = acomp_do_one_req(req, comp); 373 328 if (err == -EBUSY || err == -EINPROGRESS) 374 - return -EBUSY; 329 + return err; 375 330 376 - return acomp_reqchain_finish(req, err, ~0); 331 + return acomp_reqchain_finish(req, err); 377 332 } 378 333 379 334 int crypto_acomp_compress(struct acomp_req *req) 380 335 { 381 - return acomp_do_req_chain(req, crypto_acomp_reqtfm(req)->compress); 336 + struct crypto_acomp *tfm = crypto_acomp_reqtfm(req); 337 + 338 + if (crypto_acomp_req_chain(tfm) || acomp_request_issg(req)) 339 + crypto_acomp_reqtfm(req)->compress(req); 340 + return acomp_do_req_chain(req, true); 382 341 } 383 342 EXPORT_SYMBOL_GPL(crypto_acomp_compress); 384 343 385 344 int crypto_acomp_decompress(struct acomp_req *req) 386 345 { 387 - return acomp_do_req_chain(req, crypto_acomp_reqtfm(req)->decompress); 346 + struct crypto_acomp *tfm = crypto_acomp_reqtfm(req); 347 + 348 + if (crypto_acomp_req_chain(tfm) || acomp_request_issg(req)) 349 + crypto_acomp_reqtfm(req)->decompress(req); 350 + return acomp_do_req_chain(req, false); 388 351 } 389 352 EXPORT_SYMBOL_GPL(crypto_acomp_decompress); 390 353
+2 -16
crypto/scompress.c
··· 284 284 return ret; 285 285 } 286 286 287 - static int scomp_acomp_chain(struct acomp_req *req, int dir) 288 - { 289 - struct acomp_req *r2; 290 - int err; 291 - 292 - err = scomp_acomp_comp_decomp(req, dir); 293 - req->base.err = err; 294 - 295 - list_for_each_entry(r2, &req->base.list, base.list) 296 - r2->base.err = scomp_acomp_comp_decomp(r2, dir); 297 - 298 - return err; 299 - } 300 - 301 287 static int scomp_acomp_compress(struct acomp_req *req) 302 288 { 303 - return scomp_acomp_chain(req, 1); 289 + return scomp_acomp_comp_decomp(req, 1); 304 290 } 305 291 306 292 static int scomp_acomp_decompress(struct acomp_req *req) 307 293 { 308 - return scomp_acomp_chain(req, 0); 294 + return scomp_acomp_comp_decomp(req, 0); 309 295 } 310 296 311 297 static void crypto_exit_scomp_ops_async(struct crypto_tfm *tfm)
-14
include/crypto/acompress.h
··· 52 52 struct folio; 53 53 54 54 struct acomp_req_chain { 55 - struct list_head head; 56 - struct acomp_req *req0; 57 - struct acomp_req *cur; 58 - int (*op)(struct acomp_req *req); 59 55 crypto_completion_t compl; 60 56 void *data; 61 57 struct scatterlist ssg; ··· 64 68 u8 *dst; 65 69 struct folio *dfolio; 66 70 }; 67 - size_t soff; 68 - size_t doff; 69 71 u32 flags; 70 72 }; 71 73 ··· 337 343 req->base.data = data; 338 344 req->base.flags &= keep; 339 345 req->base.flags |= flgs & ~keep; 340 - 341 - crypto_reqchain_init(&req->base); 342 346 } 343 347 344 348 /** ··· 542 550 req->base.flags &= ~CRYPTO_ACOMP_REQ_DST_NONDMA; 543 551 req->base.flags &= ~CRYPTO_ACOMP_REQ_DST_VIRT; 544 552 req->base.flags |= CRYPTO_ACOMP_REQ_DST_FOLIO; 545 - } 546 - 547 - static inline void acomp_request_chain(struct acomp_req *req, 548 - struct acomp_req *head) 549 - { 550 - crypto_request_chain(&req->base, &head->base); 551 553 } 552 554 553 555 /**
-5
include/crypto/internal/acompress.h
··· 151 151 int crypto_register_acomps(struct acomp_alg *algs, int count); 152 152 void crypto_unregister_acomps(struct acomp_alg *algs, int count); 153 153 154 - static inline bool acomp_request_chained(struct acomp_req *req) 155 - { 156 - return crypto_request_chained(&req->base); 157 - } 158 - 159 154 static inline bool acomp_request_issg(struct acomp_req *req) 160 155 { 161 156 return !(req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT |