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

crypto/nx/nx-842: Fix handling of vmalloc addresses

The powerpc specific nx-842 compression driver does not currently
handle translating a vmalloc address to a physical address.

The current driver uses __pa() for all addresses which does not
properly handle vmalloc addresses and thus causes a failure since
we do not pass a proper physical address to the hypervisor.

This patch adds a routine to convert an address to a physical
address by checking for vmalloc addresses and handling them properly.

Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
---
drivers/crypto/nx/nx-842.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Nathan Fontenot and committed by
Benjamin Herrenschmidt
0ba3e101 8d4887ee

+19 -10
+19 -10
drivers/crypto/nx/nx-842.c
··· 158 158 return sl->entry_nr * sizeof(struct nx842_slentry); 159 159 } 160 160 161 + static inline unsigned long nx842_get_pa(void *addr) 162 + { 163 + if (is_vmalloc_addr(addr)) 164 + return page_to_phys(vmalloc_to_page(addr)) 165 + + offset_in_page(addr); 166 + else 167 + return __pa(addr); 168 + } 169 + 161 170 static int nx842_build_scatterlist(unsigned long buf, int len, 162 171 struct nx842_scatterlist *sl) 163 172 { ··· 177 168 178 169 entry = sl->entries; 179 170 while (len) { 180 - entry->ptr = __pa(buf); 171 + entry->ptr = nx842_get_pa((void *)buf); 181 172 nextpage = ALIGN(buf + 1, NX842_HW_PAGE_SIZE); 182 173 if (nextpage < buf + len) { 183 174 /* we aren't at the end yet */ ··· 379 370 op.flags = NX842_OP_COMPRESS; 380 371 csbcpb = &workmem->csbcpb; 381 372 memset(csbcpb, 0, sizeof(*csbcpb)); 382 - op.csbcpb = __pa(csbcpb); 383 - op.out = __pa(slout.entries); 373 + op.csbcpb = nx842_get_pa(csbcpb); 374 + op.out = nx842_get_pa(slout.entries); 384 375 385 376 for (i = 0; i < hdr->blocks_nr; i++) { 386 377 /* ··· 410 401 */ 411 402 if (likely(max_sync_size == NX842_HW_PAGE_SIZE)) { 412 403 /* Create direct DDE */ 413 - op.in = __pa(inbuf); 404 + op.in = nx842_get_pa((void *)inbuf); 414 405 op.inlen = max_sync_size; 415 406 416 407 } else { 417 408 /* Create indirect DDE (scatterlist) */ 418 409 nx842_build_scatterlist(inbuf, max_sync_size, &slin); 419 - op.in = __pa(slin.entries); 410 + op.in = nx842_get_pa(slin.entries); 420 411 op.inlen = -nx842_get_scatterlist_size(&slin); 421 412 } 422 413 ··· 574 565 op.flags = NX842_OP_DECOMPRESS; 575 566 csbcpb = &workmem->csbcpb; 576 567 memset(csbcpb, 0, sizeof(*csbcpb)); 577 - op.csbcpb = __pa(csbcpb); 568 + op.csbcpb = nx842_get_pa(csbcpb); 578 569 579 570 /* 580 571 * max_sync_size may have changed since compression, ··· 606 597 if (likely((inbuf & NX842_HW_PAGE_MASK) == 607 598 ((inbuf + hdr->sizes[i] - 1) & NX842_HW_PAGE_MASK))) { 608 599 /* Create direct DDE */ 609 - op.in = __pa(inbuf); 600 + op.in = nx842_get_pa((void *)inbuf); 610 601 op.inlen = hdr->sizes[i]; 611 602 } else { 612 603 /* Create indirect DDE (scatterlist) */ 613 604 nx842_build_scatterlist(inbuf, hdr->sizes[i] , &slin); 614 - op.in = __pa(slin.entries); 605 + op.in = nx842_get_pa(slin.entries); 615 606 op.inlen = -nx842_get_scatterlist_size(&slin); 616 607 } 617 608 ··· 622 613 */ 623 614 if (likely(max_sync_size == NX842_HW_PAGE_SIZE)) { 624 615 /* Create direct DDE */ 625 - op.out = __pa(outbuf); 616 + op.out = nx842_get_pa((void *)outbuf); 626 617 op.outlen = max_sync_size; 627 618 } else { 628 619 /* Create indirect DDE (scatterlist) */ 629 620 nx842_build_scatterlist(outbuf, max_sync_size, &slout); 630 - op.out = __pa(slout.entries); 621 + op.out = nx842_get_pa(slout.entries); 631 622 op.outlen = -nx842_get_scatterlist_size(&slout); 632 623 } 633 624