Skip to content

Commit aa96951

Browse files
ardbiesheuvelherbertx
authored andcommitted
crypto: scatterwalk - use kmap_local() not kmap_atomic()
kmap_atomic() is used to create short-lived mappings of pages that may not be accessible via the kernel direct map. This is only needed on 32-bit architectures that implement CONFIG_HIGHMEM, but it can be used on 64-bit other architectures too, where the returned mapping is simply the kernel direct address of the page. However, kmap_atomic() does not support migration on CONFIG_HIGHMEM configurations, due to the use of per-CPU kmap slots, and so it disables preemption on all architectures, not just the 32-bit ones. This implies that all scatterwalk based crypto routines essentially execute with preemption disabled all the time, which is less than ideal. So let's switch scatterwalk_map/_unmap and the shash/ahash routines to kmap_local() instead, which serves a similar purpose, but without the resulting impact on preemption on architectures that have no need for CONFIG_HIGHMEM. Cc: Eric Biggers <[email protected]> Cc: Herbert Xu <[email protected]> Cc: "Elliott, Robert (Servers)" <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent b517b0f commit aa96951

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

crypto/ahash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
4545
unsigned int nbytes = min(walk->entrylen,
4646
((unsigned int)(PAGE_SIZE)) - offset);
4747

48-
walk->data = kmap_atomic(walk->pg);
48+
walk->data = kmap_local_page(walk->pg);
4949
walk->data += offset;
5050

5151
if (offset & alignmask) {
@@ -95,7 +95,7 @@ int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err)
9595
}
9696
}
9797

98-
kunmap_atomic(walk->data);
98+
kunmap_local(walk->data);
9999
crypto_yield(walk->flags);
100100

101101
if (err)

crypto/shash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc)
320320
nbytes <= min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset))) {
321321
void *data;
322322

323-
data = kmap_atomic(sg_page(sg));
323+
data = kmap_local_page(sg_page(sg));
324324
err = crypto_shash_digest(desc, data + offset, nbytes,
325325
req->result);
326-
kunmap_atomic(data);
326+
kunmap_local(data);
327327
} else
328328
err = crypto_shash_init(desc) ?:
329329
shash_ahash_finup(req, desc);

include/crypto/scatterwalk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static inline struct page *scatterwalk_page(struct scatter_walk *walk)
5353

5454
static inline void scatterwalk_unmap(void *vaddr)
5555
{
56-
kunmap_atomic(vaddr);
56+
kunmap_local(vaddr);
5757
}
5858

5959
static inline void scatterwalk_start(struct scatter_walk *walk,
@@ -65,7 +65,7 @@ static inline void scatterwalk_start(struct scatter_walk *walk,
6565

6666
static inline void *scatterwalk_map(struct scatter_walk *walk)
6767
{
68-
return kmap_atomic(scatterwalk_page(walk)) +
68+
return kmap_local_page(scatterwalk_page(walk)) +
6969
offset_in_page(walk->offset);
7070
}
7171

0 commit comments

Comments
 (0)