diff options
Diffstat (limited to 'arch/s390')
31 files changed, 1065 insertions, 310 deletions
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index 2508a6f31588..4a7f14079e03 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig | |||
@@ -88,6 +88,7 @@ config S390 | |||
88 | select HAVE_KERNEL_XZ | 88 | select HAVE_KERNEL_XZ |
89 | select HAVE_GET_USER_PAGES_FAST | 89 | select HAVE_GET_USER_PAGES_FAST |
90 | select HAVE_ARCH_MUTEX_CPU_RELAX | 90 | select HAVE_ARCH_MUTEX_CPU_RELAX |
91 | select HAVE_ARCH_JUMP_LABEL if !MARCH_G5 | ||
91 | select ARCH_INLINE_SPIN_TRYLOCK | 92 | select ARCH_INLINE_SPIN_TRYLOCK |
92 | select ARCH_INLINE_SPIN_TRYLOCK_BH | 93 | select ARCH_INLINE_SPIN_TRYLOCK_BH |
93 | select ARCH_INLINE_SPIN_LOCK | 94 | select ARCH_INLINE_SPIN_LOCK |
diff --git a/arch/s390/crypto/Makefile b/arch/s390/crypto/Makefile index 1cf81d77c5a5..7f0b7cda6259 100644 --- a/arch/s390/crypto/Makefile +++ b/arch/s390/crypto/Makefile | |||
@@ -8,3 +8,4 @@ obj-$(CONFIG_CRYPTO_SHA512_S390) += sha512_s390.o sha_common.o | |||
8 | obj-$(CONFIG_CRYPTO_DES_S390) += des_s390.o | 8 | obj-$(CONFIG_CRYPTO_DES_S390) += des_s390.o |
9 | obj-$(CONFIG_CRYPTO_AES_S390) += aes_s390.o | 9 | obj-$(CONFIG_CRYPTO_AES_S390) += aes_s390.o |
10 | obj-$(CONFIG_S390_PRNG) += prng.o | 10 | obj-$(CONFIG_S390_PRNG) += prng.o |
11 | obj-$(CONFIG_CRYPTO_GHASH_S390) += ghash_s390.o | ||
diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c index 58f46734465f..a9ce135893f8 100644 --- a/arch/s390/crypto/aes_s390.c +++ b/arch/s390/crypto/aes_s390.c | |||
@@ -31,7 +31,8 @@ | |||
31 | #define AES_KEYLEN_192 2 | 31 | #define AES_KEYLEN_192 2 |
32 | #define AES_KEYLEN_256 4 | 32 | #define AES_KEYLEN_256 4 |
33 | 33 | ||
34 | static char keylen_flag = 0; | 34 | static u8 *ctrblk; |
35 | static char keylen_flag; | ||
35 | 36 | ||
36 | struct s390_aes_ctx { | 37 | struct s390_aes_ctx { |
37 | u8 iv[AES_BLOCK_SIZE]; | 38 | u8 iv[AES_BLOCK_SIZE]; |
@@ -45,6 +46,24 @@ struct s390_aes_ctx { | |||
45 | } fallback; | 46 | } fallback; |
46 | }; | 47 | }; |
47 | 48 | ||
49 | struct pcc_param { | ||
50 | u8 key[32]; | ||
51 | u8 tweak[16]; | ||
52 | u8 block[16]; | ||
53 | u8 bit[16]; | ||
54 | u8 xts[16]; | ||
55 | }; | ||
56 | |||
57 | struct s390_xts_ctx { | ||
58 | u8 key[32]; | ||
59 | u8 xts_param[16]; | ||
60 | struct pcc_param pcc; | ||
61 | long enc; | ||
62 | long dec; | ||
63 | int key_len; | ||
64 | struct crypto_blkcipher *fallback; | ||
65 | }; | ||
66 | |||
48 | /* | 67 | /* |
49 | * Check if the key_len is supported by the HW. | 68 | * Check if the key_len is supported by the HW. |
50 | * Returns 0 if it is, a positive number if it is not and software fallback is | 69 | * Returns 0 if it is, a positive number if it is not and software fallback is |
@@ -504,15 +523,337 @@ static struct crypto_alg cbc_aes_alg = { | |||
504 | } | 523 | } |
505 | }; | 524 | }; |
506 | 525 | ||
526 | static int xts_fallback_setkey(struct crypto_tfm *tfm, const u8 *key, | ||
527 | unsigned int len) | ||
528 | { | ||
529 | struct s390_xts_ctx *xts_ctx = crypto_tfm_ctx(tfm); | ||
530 | unsigned int ret; | ||
531 | |||
532 | xts_ctx->fallback->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK; | ||
533 | xts_ctx->fallback->base.crt_flags |= (tfm->crt_flags & | ||
534 | CRYPTO_TFM_REQ_MASK); | ||
535 | |||
536 | ret = crypto_blkcipher_setkey(xts_ctx->fallback, key, len); | ||
537 | if (ret) { | ||
538 | tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK; | ||
539 | tfm->crt_flags |= (xts_ctx->fallback->base.crt_flags & | ||
540 | CRYPTO_TFM_RES_MASK); | ||
541 | } | ||
542 | return ret; | ||
543 | } | ||
544 | |||
545 | static int xts_fallback_decrypt(struct blkcipher_desc *desc, | ||
546 | struct scatterlist *dst, struct scatterlist *src, | ||
547 | unsigned int nbytes) | ||
548 | { | ||
549 | struct s390_xts_ctx *xts_ctx = crypto_blkcipher_ctx(desc->tfm); | ||
550 | struct crypto_blkcipher *tfm; | ||
551 | unsigned int ret; | ||
552 | |||
553 | tfm = desc->tfm; | ||
554 | desc->tfm = xts_ctx->fallback; | ||
555 | |||
556 | ret = crypto_blkcipher_decrypt_iv(desc, dst, src, nbytes); | ||
557 | |||
558 | desc->tfm = tfm; | ||
559 | return ret; | ||
560 | } | ||
561 | |||
562 | static int xts_fallback_encrypt(struct blkcipher_desc *desc, | ||
563 | struct scatterlist *dst, struct scatterlist *src, | ||
564 | unsigned int nbytes) | ||
565 | { | ||
566 | struct s390_xts_ctx *xts_ctx = crypto_blkcipher_ctx(desc->tfm); | ||
567 | struct crypto_blkcipher *tfm; | ||
568 | unsigned int ret; | ||
569 | |||
570 | tfm = desc->tfm; | ||
571 | desc->tfm = xts_ctx->fallback; | ||
572 | |||
573 | ret = crypto_blkcipher_encrypt_iv(desc, dst, src, nbytes); | ||
574 | |||
575 | desc->tfm = tfm; | ||
576 | return ret; | ||
577 | } | ||
578 | |||
579 | static int xts_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, | ||
580 | unsigned int key_len) | ||
581 | { | ||
582 | struct s390_xts_ctx *xts_ctx = crypto_tfm_ctx(tfm); | ||
583 | u32 *flags = &tfm->crt_flags; | ||
584 | |||
585 | switch (key_len) { | ||
586 | case 32: | ||
587 | xts_ctx->enc = KM_XTS_128_ENCRYPT; | ||
588 | xts_ctx->dec = KM_XTS_128_DECRYPT; | ||
589 | memcpy(xts_ctx->key + 16, in_key, 16); | ||
590 | memcpy(xts_ctx->pcc.key + 16, in_key + 16, 16); | ||
591 | break; | ||
592 | case 48: | ||
593 | xts_ctx->enc = 0; | ||
594 | xts_ctx->dec = 0; | ||
595 | xts_fallback_setkey(tfm, in_key, key_len); | ||
596 | break; | ||
597 | case 64: | ||
598 | xts_ctx->enc = KM_XTS_256_ENCRYPT; | ||
599 | xts_ctx->dec = KM_XTS_256_DECRYPT; | ||
600 | memcpy(xts_ctx->key, in_key, 32); | ||
601 | memcpy(xts_ctx->pcc.key, in_key + 32, 32); | ||
602 | break; | ||
603 | default: | ||
604 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | ||
605 | return -EINVAL; | ||
606 | } | ||
607 | xts_ctx->key_len = key_len; | ||
608 | return 0; | ||
609 | } | ||
610 | |||
611 | static int xts_aes_crypt(struct blkcipher_desc *desc, long func, | ||
612 | struct s390_xts_ctx *xts_ctx, | ||
613 | struct blkcipher_walk *walk) | ||
614 | { | ||
615 | unsigned int offset = (xts_ctx->key_len >> 1) & 0x10; | ||
616 | int ret = blkcipher_walk_virt(desc, walk); | ||
617 | unsigned int nbytes = walk->nbytes; | ||
618 | unsigned int n; | ||
619 | u8 *in, *out; | ||
620 | void *param; | ||
621 | |||
622 | if (!nbytes) | ||
623 | goto out; | ||
624 | |||
625 | memset(xts_ctx->pcc.block, 0, sizeof(xts_ctx->pcc.block)); | ||
626 | memset(xts_ctx->pcc.bit, 0, sizeof(xts_ctx->pcc.bit)); | ||
627 | memset(xts_ctx->pcc.xts, 0, sizeof(xts_ctx->pcc.xts)); | ||
628 | memcpy(xts_ctx->pcc.tweak, walk->iv, sizeof(xts_ctx->pcc.tweak)); | ||
629 | param = xts_ctx->pcc.key + offset; | ||
630 | ret = crypt_s390_pcc(func, param); | ||
631 | BUG_ON(ret < 0); | ||
632 | |||
633 | memcpy(xts_ctx->xts_param, xts_ctx->pcc.xts, 16); | ||
634 | param = xts_ctx->key + offset; | ||
635 | do { | ||
636 | /* only use complete blocks */ | ||
637 | n = nbytes & ~(AES_BLOCK_SIZE - 1); | ||
638 | out = walk->dst.virt.addr; | ||
639 | in = walk->src.virt.addr; | ||
640 | |||
641 | ret = crypt_s390_km(func, param, out, in, n); | ||
642 | BUG_ON(ret < 0 || ret != n); | ||
643 | |||
644 | nbytes &= AES_BLOCK_SIZE - 1; | ||
645 | ret = blkcipher_walk_done(desc, walk, nbytes); | ||
646 | } while ((nbytes = walk->nbytes)); | ||
647 | out: | ||
648 | return ret; | ||
649 | } | ||
650 | |||
651 | static int xts_aes_encrypt(struct blkcipher_desc *desc, | ||
652 | struct scatterlist *dst, struct scatterlist *src, | ||
653 | unsigned int nbytes) | ||
654 | { | ||
655 | struct s390_xts_ctx *xts_ctx = crypto_blkcipher_ctx(desc->tfm); | ||
656 | struct blkcipher_walk walk; | ||
657 | |||
658 | if (unlikely(xts_ctx->key_len == 48)) | ||
659 | return xts_fallback_encrypt(desc, dst, src, nbytes); | ||
660 | |||
661 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
662 | return xts_aes_crypt(desc, xts_ctx->enc, xts_ctx, &walk); | ||
663 | } | ||
664 | |||
665 | static int xts_aes_decrypt(struct blkcipher_desc *desc, | ||
666 | struct scatterlist *dst, struct scatterlist *src, | ||
667 | unsigned int nbytes) | ||
668 | { | ||
669 | struct s390_xts_ctx *xts_ctx = crypto_blkcipher_ctx(desc->tfm); | ||
670 | struct blkcipher_walk walk; | ||
671 | |||
672 | if (unlikely(xts_ctx->key_len == 48)) | ||
673 | return xts_fallback_decrypt(desc, dst, src, nbytes); | ||
674 | |||
675 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
676 | return xts_aes_crypt(desc, xts_ctx->dec, xts_ctx, &walk); | ||
677 | } | ||
678 | |||
679 | static int xts_fallback_init(struct crypto_tfm *tfm) | ||
680 | { | ||
681 | const char *name = tfm->__crt_alg->cra_name; | ||
682 | struct s390_xts_ctx *xts_ctx = crypto_tfm_ctx(tfm); | ||
683 | |||
684 | xts_ctx->fallback = crypto_alloc_blkcipher(name, 0, | ||
685 | CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK); | ||
686 | |||
687 | if (IS_ERR(xts_ctx->fallback)) { | ||
688 | pr_err("Allocating XTS fallback algorithm %s failed\n", | ||
689 | name); | ||
690 | return PTR_ERR(xts_ctx->fallback); | ||
691 | } | ||
692 | return 0; | ||
693 | } | ||
694 | |||
695 | static void xts_fallback_exit(struct crypto_tfm *tfm) | ||
696 | { | ||
697 | struct s390_xts_ctx *xts_ctx = crypto_tfm_ctx(tfm); | ||
698 | |||
699 | crypto_free_blkcipher(xts_ctx->fallback); | ||
700 | xts_ctx->fallback = NULL; | ||
701 | } | ||
702 | |||
703 | static struct crypto_alg xts_aes_alg = { | ||
704 | .cra_name = "xts(aes)", | ||
705 | .cra_driver_name = "xts-aes-s390", | ||
706 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | ||
707 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | | ||
708 | CRYPTO_ALG_NEED_FALLBACK, | ||
709 | .cra_blocksize = AES_BLOCK_SIZE, | ||
710 | .cra_ctxsize = sizeof(struct s390_xts_ctx), | ||
711 | .cra_type = &crypto_blkcipher_type, | ||
712 | .cra_module = THIS_MODULE, | ||
713 | .cra_list = LIST_HEAD_INIT(xts_aes_alg.cra_list), | ||
714 | .cra_init = xts_fallback_init, | ||
715 | .cra_exit = xts_fallback_exit, | ||
716 | .cra_u = { | ||
717 | .blkcipher = { | ||
718 | .min_keysize = 2 * AES_MIN_KEY_SIZE, | ||
719 | .max_keysize = 2 * AES_MAX_KEY_SIZE, | ||
720 | .ivsize = AES_BLOCK_SIZE, | ||
721 | .setkey = xts_aes_set_key, | ||
722 | .encrypt = xts_aes_encrypt, | ||
723 | .decrypt = xts_aes_decrypt, | ||
724 | } | ||
725 | } | ||
726 | }; | ||
727 | |||
728 | static int ctr_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, | ||
729 | unsigned int key_len) | ||
730 | { | ||
731 | struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm); | ||
732 | |||
733 | switch (key_len) { | ||
734 | case 16: | ||
735 | sctx->enc = KMCTR_AES_128_ENCRYPT; | ||
736 | sctx->dec = KMCTR_AES_128_DECRYPT; | ||
737 | break; | ||
738 | case 24: | ||
739 | sctx->enc = KMCTR_AES_192_ENCRYPT; | ||
740 | sctx->dec = KMCTR_AES_192_DECRYPT; | ||
741 | break; | ||
742 | case 32: | ||
743 | sctx->enc = KMCTR_AES_256_ENCRYPT; | ||
744 | sctx->dec = KMCTR_AES_256_DECRYPT; | ||
745 | break; | ||
746 | } | ||
747 | |||
748 | return aes_set_key(tfm, in_key, key_len); | ||
749 | } | ||
750 | |||
751 | static int ctr_aes_crypt(struct blkcipher_desc *desc, long func, | ||
752 | struct s390_aes_ctx *sctx, struct blkcipher_walk *walk) | ||
753 | { | ||
754 | int ret = blkcipher_walk_virt_block(desc, walk, AES_BLOCK_SIZE); | ||
755 | unsigned int i, n, nbytes; | ||
756 | u8 buf[AES_BLOCK_SIZE]; | ||
757 | u8 *out, *in; | ||
758 | |||
759 | if (!walk->nbytes) | ||
760 | return ret; | ||
761 | |||
762 | memcpy(ctrblk, walk->iv, AES_BLOCK_SIZE); | ||
763 | while ((nbytes = walk->nbytes) >= AES_BLOCK_SIZE) { | ||
764 | out = walk->dst.virt.addr; | ||
765 | in = walk->src.virt.addr; | ||
766 | while (nbytes >= AES_BLOCK_SIZE) { | ||
767 | /* only use complete blocks, max. PAGE_SIZE */ | ||
768 | n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : | ||
769 | nbytes & ~(AES_BLOCK_SIZE - 1); | ||
770 | for (i = AES_BLOCK_SIZE; i < n; i += AES_BLOCK_SIZE) { | ||
771 | memcpy(ctrblk + i, ctrblk + i - AES_BLOCK_SIZE, | ||
772 | AES_BLOCK_SIZE); | ||
773 | crypto_inc(ctrblk + i, AES_BLOCK_SIZE); | ||
774 | } | ||
775 | ret = crypt_s390_kmctr(func, sctx->key, out, in, n, ctrblk); | ||
776 | BUG_ON(ret < 0 || ret != n); | ||
777 | if (n > AES_BLOCK_SIZE) | ||
778 | memcpy(ctrblk, ctrblk + n - AES_BLOCK_SIZE, | ||
779 | AES_BLOCK_SIZE); | ||
780 | crypto_inc(ctrblk, AES_BLOCK_SIZE); | ||
781 | out += n; | ||
782 | in += n; | ||
783 | nbytes -= n; | ||
784 | } | ||
785 | ret = blkcipher_walk_done(desc, walk, nbytes); | ||
786 | } | ||
787 | /* | ||
788 | * final block may be < AES_BLOCK_SIZE, copy only nbytes | ||
789 | */ | ||
790 | if (nbytes) { | ||
791 | out = walk->dst.virt.addr; | ||
792 | in = walk->src.virt.addr; | ||
793 | ret = crypt_s390_kmctr(func, sctx->key, buf, in, | ||
794 | AES_BLOCK_SIZE, ctrblk); | ||
795 | BUG_ON(ret < 0 || ret != AES_BLOCK_SIZE); | ||
796 | memcpy(out, buf, nbytes); | ||
797 | crypto_inc(ctrblk, AES_BLOCK_SIZE); | ||
798 | ret = blkcipher_walk_done(desc, walk, 0); | ||
799 | } | ||
800 | memcpy(walk->iv, ctrblk, AES_BLOCK_SIZE); | ||
801 | return ret; | ||
802 | } | ||
803 | |||
804 | static int ctr_aes_encrypt(struct blkcipher_desc *desc, | ||
805 | struct scatterlist *dst, struct scatterlist *src, | ||
806 | unsigned int nbytes) | ||
807 | { | ||
808 | struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
809 | struct blkcipher_walk walk; | ||
810 | |||
811 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
812 | return ctr_aes_crypt(desc, sctx->enc, sctx, &walk); | ||
813 | } | ||
814 | |||
815 | static int ctr_aes_decrypt(struct blkcipher_desc *desc, | ||
816 | struct scatterlist *dst, struct scatterlist *src, | ||
817 | unsigned int nbytes) | ||
818 | { | ||
819 | struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
820 | struct blkcipher_walk walk; | ||
821 | |||
822 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
823 | return ctr_aes_crypt(desc, sctx->dec, sctx, &walk); | ||
824 | } | ||
825 | |||
826 | static struct crypto_alg ctr_aes_alg = { | ||
827 | .cra_name = "ctr(aes)", | ||
828 | .cra_driver_name = "ctr-aes-s390", | ||
829 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | ||
830 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
831 | .cra_blocksize = 1, | ||
832 | .cra_ctxsize = sizeof(struct s390_aes_ctx), | ||
833 | .cra_type = &crypto_blkcipher_type, | ||
834 | .cra_module = THIS_MODULE, | ||
835 | .cra_list = LIST_HEAD_INIT(ctr_aes_alg.cra_list), | ||
836 | .cra_u = { | ||
837 | .blkcipher = { | ||
838 | .min_keysize = AES_MIN_KEY_SIZE, | ||
839 | .max_keysize = AES_MAX_KEY_SIZE, | ||
840 | .ivsize = AES_BLOCK_SIZE, | ||
841 | .setkey = ctr_aes_set_key, | ||
842 | .encrypt = ctr_aes_encrypt, | ||
843 | .decrypt = ctr_aes_decrypt, | ||
844 | } | ||
845 | } | ||
846 | }; | ||
847 | |||
507 | static int __init aes_s390_init(void) | 848 | static int __init aes_s390_init(void) |
508 | { | 849 | { |
509 | int ret; | 850 | int ret; |
510 | 851 | ||
511 | if (crypt_s390_func_available(KM_AES_128_ENCRYPT)) | 852 | if (crypt_s390_func_available(KM_AES_128_ENCRYPT, CRYPT_S390_MSA)) |
512 | keylen_flag |= AES_KEYLEN_128; | 853 | keylen_flag |= AES_KEYLEN_128; |
513 | if (crypt_s390_func_available(KM_AES_192_ENCRYPT)) | 854 | if (crypt_s390_func_available(KM_AES_192_ENCRYPT, CRYPT_S390_MSA)) |
514 | keylen_flag |= AES_KEYLEN_192; | 855 | keylen_flag |= AES_KEYLEN_192; |
515 | if (crypt_s390_func_available(KM_AES_256_ENCRYPT)) | 856 | if (crypt_s390_func_available(KM_AES_256_ENCRYPT, CRYPT_S390_MSA)) |
516 | keylen_flag |= AES_KEYLEN_256; | 857 | keylen_flag |= AES_KEYLEN_256; |
517 | 858 | ||
518 | if (!keylen_flag) | 859 | if (!keylen_flag) |
@@ -535,9 +876,40 @@ static int __init aes_s390_init(void) | |||
535 | if (ret) | 876 | if (ret) |
536 | goto cbc_aes_err; | 877 | goto cbc_aes_err; |
537 | 878 | ||
879 | if (crypt_s390_func_available(KM_XTS_128_ENCRYPT, | ||
880 | CRYPT_S390_MSA | CRYPT_S390_MSA4) && | ||
881 | crypt_s390_func_available(KM_XTS_256_ENCRYPT, | ||
882 | CRYPT_S390_MSA | CRYPT_S390_MSA4)) { | ||
883 | ret = crypto_register_alg(&xts_aes_alg); | ||
884 | if (ret) | ||
885 | goto xts_aes_err; | ||
886 | } | ||
887 | |||
888 | if (crypt_s390_func_available(KMCTR_AES_128_ENCRYPT, | ||
889 | CRYPT_S390_MSA | CRYPT_S390_MSA4) && | ||
890 | crypt_s390_func_available(KMCTR_AES_192_ENCRYPT, | ||
891 | CRYPT_S390_MSA | CRYPT_S390_MSA4) && | ||
892 | crypt_s390_func_available(KMCTR_AES_256_ENCRYPT, | ||
893 | CRYPT_S390_MSA | CRYPT_S390_MSA4)) { | ||
894 | ctrblk = (u8 *) __get_free_page(GFP_KERNEL); | ||
895 | if (!ctrblk) { | ||
896 | ret = -ENOMEM; | ||
897 | goto ctr_aes_err; | ||
898 | } | ||
899 | ret = crypto_register_alg(&ctr_aes_alg); | ||
900 | if (ret) { | ||
901 | free_page((unsigned long) ctrblk); | ||
902 | goto ctr_aes_err; | ||
903 | } | ||
904 | } | ||
905 | |||
538 | out: | 906 | out: |
539 | return ret; | 907 | return ret; |
540 | 908 | ||
909 | ctr_aes_err: | ||
910 | crypto_unregister_alg(&xts_aes_alg); | ||
911 | xts_aes_err: | ||
912 | crypto_unregister_alg(&cbc_aes_alg); | ||
541 | cbc_aes_err: | 913 | cbc_aes_err: |
542 | crypto_unregister_alg(&ecb_aes_alg); | 914 | crypto_unregister_alg(&ecb_aes_alg); |
543 | ecb_aes_err: | 915 | ecb_aes_err: |
@@ -548,6 +920,9 @@ aes_err: | |||
548 | 920 | ||
549 | static void __exit aes_s390_fini(void) | 921 | static void __exit aes_s390_fini(void) |
550 | { | 922 | { |
923 | crypto_unregister_alg(&ctr_aes_alg); | ||
924 | free_page((unsigned long) ctrblk); | ||
925 | crypto_unregister_alg(&xts_aes_alg); | ||
551 | crypto_unregister_alg(&cbc_aes_alg); | 926 | crypto_unregister_alg(&cbc_aes_alg); |
552 | crypto_unregister_alg(&ecb_aes_alg); | 927 | crypto_unregister_alg(&ecb_aes_alg); |
553 | crypto_unregister_alg(&aes_alg); | 928 | crypto_unregister_alg(&aes_alg); |
diff --git a/arch/s390/crypto/crypt_s390.h b/arch/s390/crypto/crypt_s390.h index 7ee9a1b4ad9f..49676771bd66 100644 --- a/arch/s390/crypto/crypt_s390.h +++ b/arch/s390/crypto/crypt_s390.h | |||
@@ -24,13 +24,18 @@ | |||
24 | #define CRYPT_S390_PRIORITY 300 | 24 | #define CRYPT_S390_PRIORITY 300 |
25 | #define CRYPT_S390_COMPOSITE_PRIORITY 400 | 25 | #define CRYPT_S390_COMPOSITE_PRIORITY 400 |
26 | 26 | ||
27 | #define CRYPT_S390_MSA 0x1 | ||
28 | #define CRYPT_S390_MSA3 0x2 | ||
29 | #define CRYPT_S390_MSA4 0x4 | ||
30 | |||
27 | /* s390 cryptographic operations */ | 31 | /* s390 cryptographic operations */ |
28 | enum crypt_s390_operations { | 32 | enum crypt_s390_operations { |
29 | CRYPT_S390_KM = 0x0100, | 33 | CRYPT_S390_KM = 0x0100, |
30 | CRYPT_S390_KMC = 0x0200, | 34 | CRYPT_S390_KMC = 0x0200, |
31 | CRYPT_S390_KIMD = 0x0300, | 35 | CRYPT_S390_KIMD = 0x0300, |
32 | CRYPT_S390_KLMD = 0x0400, | 36 | CRYPT_S390_KLMD = 0x0400, |
33 | CRYPT_S390_KMAC = 0x0500 | 37 | CRYPT_S390_KMAC = 0x0500, |
38 | CRYPT_S390_KMCTR = 0x0600 | ||
34 | }; | 39 | }; |
35 | 40 | ||
36 | /* | 41 | /* |
@@ -51,6 +56,10 @@ enum crypt_s390_km_func { | |||
51 | KM_AES_192_DECRYPT = CRYPT_S390_KM | 0x13 | 0x80, | 56 | KM_AES_192_DECRYPT = CRYPT_S390_KM | 0x13 | 0x80, |
52 | KM_AES_256_ENCRYPT = CRYPT_S390_KM | 0x14, | 57 | KM_AES_256_ENCRYPT = CRYPT_S390_KM | 0x14, |
53 | KM_AES_256_DECRYPT = CRYPT_S390_KM | 0x14 | 0x80, | 58 | KM_AES_256_DECRYPT = CRYPT_S390_KM | 0x14 | 0x80, |
59 | KM_XTS_128_ENCRYPT = CRYPT_S390_KM | 0x32, | ||
60 | KM_XTS_128_DECRYPT = CRYPT_S390_KM | 0x32 | 0x80, | ||
61 | KM_XTS_256_ENCRYPT = CRYPT_S390_KM | 0x34, | ||
62 | KM_XTS_256_DECRYPT = CRYPT_S390_KM | 0x34 | 0x80, | ||
54 | }; | 63 | }; |
55 | 64 | ||
56 | /* | 65 | /* |
@@ -75,6 +84,26 @@ enum crypt_s390_kmc_func { | |||
75 | }; | 84 | }; |
76 | 85 | ||
77 | /* | 86 | /* |
87 | * function codes for KMCTR (CIPHER MESSAGE WITH COUNTER) | ||
88 | * instruction | ||
89 | */ | ||
90 | enum crypt_s390_kmctr_func { | ||
91 | KMCTR_QUERY = CRYPT_S390_KMCTR | 0x0, | ||
92 | KMCTR_DEA_ENCRYPT = CRYPT_S390_KMCTR | 0x1, | ||
93 | KMCTR_DEA_DECRYPT = CRYPT_S390_KMCTR | 0x1 | 0x80, | ||
94 | KMCTR_TDEA_128_ENCRYPT = CRYPT_S390_KMCTR | 0x2, | ||
95 | KMCTR_TDEA_128_DECRYPT = CRYPT_S390_KMCTR | 0x2 | 0x80, | ||
96 | KMCTR_TDEA_192_ENCRYPT = CRYPT_S390_KMCTR | 0x3, | ||
97 | KMCTR_TDEA_192_DECRYPT = CRYPT_S390_KMCTR | 0x3 | 0x80, | ||
98 | KMCTR_AES_128_ENCRYPT = CRYPT_S390_KMCTR | 0x12, | ||
99 | KMCTR_AES_128_DECRYPT = CRYPT_S390_KMCTR | 0x12 | 0x80, | ||
100 | KMCTR_AES_192_ENCRYPT = CRYPT_S390_KMCTR | 0x13, | ||
101 | KMCTR_AES_192_DECRYPT = CRYPT_S390_KMCTR | 0x13 | 0x80, | ||
102 | KMCTR_AES_256_ENCRYPT = CRYPT_S390_KMCTR | 0x14, | ||
103 | KMCTR_AES_256_DECRYPT = CRYPT_S390_KMCTR | 0x14 | 0x80, | ||
104 | }; | ||
105 | |||
106 | /* | ||
78 | * function codes for KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST) | 107 | * function codes for KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST) |
79 | * instruction | 108 | * instruction |
80 | */ | 109 | */ |
@@ -83,6 +112,7 @@ enum crypt_s390_kimd_func { | |||
83 | KIMD_SHA_1 = CRYPT_S390_KIMD | 1, | 112 | KIMD_SHA_1 = CRYPT_S390_KIMD | 1, |
84 | KIMD_SHA_256 = CRYPT_S390_KIMD | 2, | 113 | KIMD_SHA_256 = CRYPT_S390_KIMD | 2, |
85 | KIMD_SHA_512 = CRYPT_S390_KIMD | 3, | 114 | KIMD_SHA_512 = CRYPT_S390_KIMD | 3, |
115 | KIMD_GHASH = CRYPT_S390_KIMD | 65, | ||
86 | }; | 116 | }; |
87 | 117 | ||
88 | /* | 118 | /* |
@@ -284,6 +314,45 @@ static inline int crypt_s390_kmac(long func, void *param, | |||
284 | } | 314 | } |
285 | 315 | ||
286 | /** | 316 | /** |
317 | * crypt_s390_kmctr: | ||
318 | * @func: the function code passed to KMCTR; see crypt_s390_kmctr_func | ||
319 | * @param: address of parameter block; see POP for details on each func | ||
320 | * @dest: address of destination memory area | ||
321 | * @src: address of source memory area | ||
322 | * @src_len: length of src operand in bytes | ||
323 | * @counter: address of counter value | ||
324 | * | ||
325 | * Executes the KMCTR (CIPHER MESSAGE WITH COUNTER) operation of the CPU. | ||
326 | * | ||
327 | * Returns -1 for failure, 0 for the query func, number of processed | ||
328 | * bytes for encryption/decryption funcs | ||
329 | */ | ||
330 | static inline int crypt_s390_kmctr(long func, void *param, u8 *dest, | ||
331 | const u8 *src, long src_len, u8 *counter) | ||
332 | { | ||
333 | register long __func asm("0") = func & CRYPT_S390_FUNC_MASK; | ||
334 | register void *__param asm("1") = param; | ||
335 | register const u8 *__src asm("2") = src; | ||
336 | register long __src_len asm("3") = src_len; | ||
337 | register u8 *__dest asm("4") = dest; | ||
338 | register u8 *__ctr asm("6") = counter; | ||
339 | int ret = -1; | ||
340 | |||
341 | asm volatile( | ||
342 | "0: .insn rrf,0xb92d0000,%3,%1,%4,0 \n" /* KMCTR opcode */ | ||
343 | "1: brc 1,0b \n" /* handle partial completion */ | ||
344 | " la %0,0\n" | ||
345 | "2:\n" | ||
346 | EX_TABLE(0b,2b) EX_TABLE(1b,2b) | ||
347 | : "+d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest), | ||
348 | "+a" (__ctr) | ||
349 | : "d" (__func), "a" (__param) : "cc", "memory"); | ||
350 | if (ret < 0) | ||
351 | return ret; | ||
352 | return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len; | ||
353 | } | ||
354 | |||
355 | /** | ||
287 | * crypt_s390_func_available: | 356 | * crypt_s390_func_available: |
288 | * @func: the function code of the specific function; 0 if op in general | 357 | * @func: the function code of the specific function; 0 if op in general |
289 | * | 358 | * |
@@ -291,13 +360,17 @@ static inline int crypt_s390_kmac(long func, void *param, | |||
291 | * | 360 | * |
292 | * Returns 1 if func available; 0 if func or op in general not available | 361 | * Returns 1 if func available; 0 if func or op in general not available |
293 | */ | 362 | */ |
294 | static inline int crypt_s390_func_available(int func) | 363 | static inline int crypt_s390_func_available(int func, |
364 | unsigned int facility_mask) | ||
295 | { | 365 | { |
296 | unsigned char status[16]; | 366 | unsigned char status[16]; |
297 | int ret; | 367 | int ret; |
298 | 368 | ||
299 | /* check if CPACF facility (bit 17) is available */ | 369 | if (facility_mask & CRYPT_S390_MSA && !test_facility(17)) |
300 | if (!test_facility(17)) | 370 | return 0; |
371 | if (facility_mask & CRYPT_S390_MSA3 && !test_facility(76)) | ||
372 | return 0; | ||
373 | if (facility_mask & CRYPT_S390_MSA4 && !test_facility(77)) | ||
301 | return 0; | 374 | return 0; |
302 | 375 | ||
303 | switch (func & CRYPT_S390_OP_MASK) { | 376 | switch (func & CRYPT_S390_OP_MASK) { |
@@ -316,6 +389,10 @@ static inline int crypt_s390_func_available(int func) | |||
316 | case CRYPT_S390_KMAC: | 389 | case CRYPT_S390_KMAC: |
317 | ret = crypt_s390_kmac(KMAC_QUERY, &status, NULL, 0); | 390 | ret = crypt_s390_kmac(KMAC_QUERY, &status, NULL, 0); |
318 | break; | 391 | break; |
392 | case CRYPT_S390_KMCTR: | ||
393 | ret = crypt_s390_kmctr(KMCTR_QUERY, &status, NULL, NULL, 0, | ||
394 | NULL); | ||
395 | break; | ||
319 | default: | 396 | default: |
320 | return 0; | 397 | return 0; |
321 | } | 398 | } |
@@ -326,4 +403,31 @@ static inline int crypt_s390_func_available(int func) | |||
326 | return (status[func >> 3] & (0x80 >> (func & 7))) != 0; | 403 | return (status[func >> 3] & (0x80 >> (func & 7))) != 0; |
327 | } | 404 | } |
328 | 405 | ||
406 | /** | ||
407 | * crypt_s390_pcc: | ||
408 | * @func: the function code passed to KM; see crypt_s390_km_func | ||
409 | * @param: address of parameter block; see POP for details on each func | ||
410 | * | ||
411 | * Executes the PCC (PERFORM CRYPTOGRAPHIC COMPUTATION) operation of the CPU. | ||
412 | * | ||
413 | * Returns -1 for failure, 0 for success. | ||
414 | */ | ||
415 | static inline int crypt_s390_pcc(long func, void *param) | ||
416 | { | ||
417 | register long __func asm("0") = func & 0x7f; /* encrypt or decrypt */ | ||
418 | register void *__param asm("1") = param; | ||
419 | int ret = -1; | ||
420 | |||
421 | asm volatile( | ||
422 | "0: .insn rre,0xb92c0000,0,0 \n" /* PCC opcode */ | ||
423 | "1: brc 1,0b \n" /* handle partial completion */ | ||
424 | " la %0,0\n" | ||
425 | "2:\n" | ||
426 | EX_TABLE(0b,2b) EX_TABLE(1b,2b) | ||
427 | : "+d" (ret) | ||
428 | : "d" (__func), "a" (__param) : "cc", "memory"); | ||
429 | return ret; | ||
430 | } | ||
431 | |||
432 | |||
329 | #endif /* _CRYPTO_ARCH_S390_CRYPT_S390_H */ | 433 | #endif /* _CRYPTO_ARCH_S390_CRYPT_S390_H */ |
diff --git a/arch/s390/crypto/des_check_key.c b/arch/s390/crypto/des_check_key.c deleted file mode 100644 index 5706af266442..000000000000 --- a/arch/s390/crypto/des_check_key.c +++ /dev/null | |||
@@ -1,132 +0,0 @@ | |||
1 | /* | ||
2 | * Cryptographic API. | ||
3 | * | ||
4 | * Function for checking keys for the DES and Tripple DES Encryption | ||
5 | * algorithms. | ||
6 | * | ||
7 | * Originally released as descore by Dana L. How <how@isl.stanford.edu>. | ||
8 | * Modified by Raimar Falke <rf13@inf.tu-dresden.de> for the Linux-Kernel. | ||
9 | * Derived from Cryptoapi and Nettle implementations, adapted for in-place | ||
10 | * scatterlist interface. Changed LGPL to GPL per section 3 of the LGPL. | ||
11 | * | ||
12 | * s390 Version: | ||
13 | * Copyright IBM Corp. 2003 | ||
14 | * Author(s): Thomas Spatzier | ||
15 | * Jan Glauber (jan.glauber@de.ibm.com) | ||
16 | * | ||
17 | * Derived from "crypto/des.c" | ||
18 | * Copyright (c) 1992 Dana L. How. | ||
19 | * Copyright (c) Raimar Falke <rf13@inf.tu-dresden.de> | ||
20 | * Copyright (c) Gisle Sflensminde <gisle@ii.uib.no> | ||
21 | * Copyright (C) 2001 Niels Mvller. | ||
22 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> | ||
23 | * | ||
24 | * This program is free software; you can redistribute it and/or modify | ||
25 | * it under the terms of the GNU General Public License as published by | ||
26 | * the Free Software Foundation; either version 2 of the License, or | ||
27 | * (at your option) any later version. | ||
28 | * | ||
29 | */ | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/errno.h> | ||
33 | #include <linux/crypto.h> | ||
34 | #include "crypto_des.h" | ||
35 | |||
36 | #define ROR(d,c,o) ((d) = (d) >> (c) | (d) << (o)) | ||
37 | |||
38 | static const u8 parity[] = { | ||
39 | 8,1,0,8,0,8,8,0,0,8,8,0,8,0,2,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,3, | ||
40 | 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, | ||
41 | 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, | ||
42 | 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, | ||
43 | 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, | ||
44 | 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, | ||
45 | 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, | ||
46 | 4,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,5,0,8,0,8,8,0,0,8,8,0,8,0,6,8, | ||
47 | }; | ||
48 | |||
49 | /* | ||
50 | * RFC2451: Weak key checks SHOULD be performed. | ||
51 | */ | ||
52 | int | ||
53 | crypto_des_check_key(const u8 *key, unsigned int keylen, u32 *flags) | ||
54 | { | ||
55 | u32 n, w; | ||
56 | |||
57 | n = parity[key[0]]; n <<= 4; | ||
58 | n |= parity[key[1]]; n <<= 4; | ||
59 | n |= parity[key[2]]; n <<= 4; | ||
60 | n |= parity[key[3]]; n <<= 4; | ||
61 | n |= parity[key[4]]; n <<= 4; | ||
62 | n |= parity[key[5]]; n <<= 4; | ||
63 | n |= parity[key[6]]; n <<= 4; | ||
64 | n |= parity[key[7]]; | ||
65 | w = 0x88888888L; | ||
66 | |||
67 | if ((*flags & CRYPTO_TFM_REQ_WEAK_KEY) | ||
68 | && !((n - (w >> 3)) & w)) { /* 1 in 10^10 keys passes this test */ | ||
69 | if (n < 0x41415151) { | ||
70 | if (n < 0x31312121) { | ||
71 | if (n < 0x14141515) { | ||
72 | /* 01 01 01 01 01 01 01 01 */ | ||
73 | if (n == 0x11111111) goto weak; | ||
74 | /* 01 1F 01 1F 01 0E 01 0E */ | ||
75 | if (n == 0x13131212) goto weak; | ||
76 | } else { | ||
77 | /* 01 E0 01 E0 01 F1 01 F1 */ | ||
78 | if (n == 0x14141515) goto weak; | ||
79 | /* 01 FE 01 FE 01 FE 01 FE */ | ||
80 | if (n == 0x16161616) goto weak; | ||
81 | } | ||
82 | } else { | ||
83 | if (n < 0x34342525) { | ||
84 | /* 1F 01 1F 01 0E 01 0E 01 */ | ||
85 | if (n == 0x31312121) goto weak; | ||
86 | /* 1F 1F 1F 1F 0E 0E 0E 0E (?) */ | ||
87 | if (n == 0x33332222) goto weak; | ||
88 | } else { | ||
89 | /* 1F E0 1F E0 0E F1 0E F1 */ | ||
90 | if (n == 0x34342525) goto weak; | ||
91 | /* 1F FE 1F FE 0E FE 0E FE */ | ||
92 | if (n == 0x36362626) goto weak; | ||
93 | } | ||
94 | } | ||
95 | } else { | ||
96 | if (n < 0x61616161) { | ||
97 | if (n < 0x44445555) { | ||
98 | /* E0 01 E0 01 F1 01 F1 01 */ | ||
99 | if (n == 0x41415151) goto weak; | ||
100 | /* E0 1F E0 1F F1 0E F1 0E */ | ||
101 | if (n == 0x43435252) goto weak; | ||
102 | } else { | ||
103 | /* E0 E0 E0 E0 F1 F1 F1 F1 (?) */ | ||
104 | if (n == 0x44445555) goto weak; | ||
105 | /* E0 FE E0 FE F1 FE F1 FE */ | ||
106 | if (n == 0x46465656) goto weak; | ||
107 | } | ||
108 | } else { | ||
109 | if (n < 0x64646565) { | ||
110 | /* FE 01 FE 01 FE 01 FE 01 */ | ||
111 | if (n == 0x61616161) goto weak; | ||
112 | /* FE 1F FE 1F FE 0E FE 0E */ | ||
113 | if (n == 0x63636262) goto weak; | ||
114 | } else { | ||
115 | /* FE E0 FE E0 FE F1 FE F1 */ | ||
116 | if (n == 0x64646565) goto weak; | ||
117 | /* FE FE FE FE FE FE FE FE */ | ||
118 | if (n == 0x66666666) goto weak; | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | return 0; | ||
124 | weak: | ||
125 | *flags |= CRYPTO_TFM_RES_WEAK_KEY; | ||
126 | return -EINVAL; | ||
127 | } | ||
128 | |||
129 | EXPORT_SYMBOL(crypto_des_check_key); | ||
130 | |||
131 | MODULE_LICENSE("GPL"); | ||
132 | MODULE_DESCRIPTION("Key Check function for DES & DES3 Cipher Algorithms"); | ||
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c index cc5420118393..a52bfd124d86 100644 --- a/arch/s390/crypto/des_s390.c +++ b/arch/s390/crypto/des_s390.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * s390 implementation of the DES Cipher Algorithm. | 4 | * s390 implementation of the DES Cipher Algorithm. |
5 | * | 5 | * |
6 | * Copyright IBM Corp. 2003,2007 | 6 | * Copyright IBM Corp. 2003,2011 |
7 | * Author(s): Thomas Spatzier | 7 | * Author(s): Thomas Spatzier |
8 | * Jan Glauber (jan.glauber@de.ibm.com) | 8 | * Jan Glauber (jan.glauber@de.ibm.com) |
9 | * | 9 | * |
@@ -22,22 +22,19 @@ | |||
22 | 22 | ||
23 | #include "crypt_s390.h" | 23 | #include "crypt_s390.h" |
24 | 24 | ||
25 | #define DES3_192_KEY_SIZE (3 * DES_KEY_SIZE) | 25 | #define DES3_KEY_SIZE (3 * DES_KEY_SIZE) |
26 | 26 | ||
27 | struct crypt_s390_des_ctx { | 27 | static u8 *ctrblk; |
28 | u8 iv[DES_BLOCK_SIZE]; | ||
29 | u8 key[DES_KEY_SIZE]; | ||
30 | }; | ||
31 | 28 | ||
32 | struct crypt_s390_des3_192_ctx { | 29 | struct s390_des_ctx { |
33 | u8 iv[DES_BLOCK_SIZE]; | 30 | u8 iv[DES_BLOCK_SIZE]; |
34 | u8 key[DES3_192_KEY_SIZE]; | 31 | u8 key[DES3_KEY_SIZE]; |
35 | }; | 32 | }; |
36 | 33 | ||
37 | static int des_setkey(struct crypto_tfm *tfm, const u8 *key, | 34 | static int des_setkey(struct crypto_tfm *tfm, const u8 *key, |
38 | unsigned int keylen) | 35 | unsigned int key_len) |
39 | { | 36 | { |
40 | struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); | 37 | struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); |
41 | u32 *flags = &tfm->crt_flags; | 38 | u32 *flags = &tfm->crt_flags; |
42 | u32 tmp[DES_EXPKEY_WORDS]; | 39 | u32 tmp[DES_EXPKEY_WORDS]; |
43 | 40 | ||
@@ -47,22 +44,22 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
47 | return -EINVAL; | 44 | return -EINVAL; |
48 | } | 45 | } |
49 | 46 | ||
50 | memcpy(dctx->key, key, keylen); | 47 | memcpy(ctx->key, key, key_len); |
51 | return 0; | 48 | return 0; |
52 | } | 49 | } |
53 | 50 | ||
54 | static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) | 51 | static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) |
55 | { | 52 | { |
56 | struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); | 53 | struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); |
57 | 54 | ||
58 | crypt_s390_km(KM_DEA_ENCRYPT, dctx->key, out, in, DES_BLOCK_SIZE); | 55 | crypt_s390_km(KM_DEA_ENCRYPT, ctx->key, out, in, DES_BLOCK_SIZE); |
59 | } | 56 | } |
60 | 57 | ||
61 | static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) | 58 | static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) |
62 | { | 59 | { |
63 | struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); | 60 | struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); |
64 | 61 | ||
65 | crypt_s390_km(KM_DEA_DECRYPT, dctx->key, out, in, DES_BLOCK_SIZE); | 62 | crypt_s390_km(KM_DEA_DECRYPT, ctx->key, out, in, DES_BLOCK_SIZE); |
66 | } | 63 | } |
67 | 64 | ||
68 | static struct crypto_alg des_alg = { | 65 | static struct crypto_alg des_alg = { |
@@ -71,7 +68,7 @@ static struct crypto_alg des_alg = { | |||
71 | .cra_priority = CRYPT_S390_PRIORITY, | 68 | .cra_priority = CRYPT_S390_PRIORITY, |
72 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | 69 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
73 | .cra_blocksize = DES_BLOCK_SIZE, | 70 | .cra_blocksize = DES_BLOCK_SIZE, |
74 | .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), | 71 | .cra_ctxsize = sizeof(struct s390_des_ctx), |
75 | .cra_module = THIS_MODULE, | 72 | .cra_module = THIS_MODULE, |
76 | .cra_list = LIST_HEAD_INIT(des_alg.cra_list), | 73 | .cra_list = LIST_HEAD_INIT(des_alg.cra_list), |
77 | .cra_u = { | 74 | .cra_u = { |
@@ -86,7 +83,7 @@ static struct crypto_alg des_alg = { | |||
86 | }; | 83 | }; |
87 | 84 | ||
88 | static int ecb_desall_crypt(struct blkcipher_desc *desc, long func, | 85 | static int ecb_desall_crypt(struct blkcipher_desc *desc, long func, |
89 | void *param, struct blkcipher_walk *walk) | 86 | u8 *key, struct blkcipher_walk *walk) |
90 | { | 87 | { |
91 | int ret = blkcipher_walk_virt(desc, walk); | 88 | int ret = blkcipher_walk_virt(desc, walk); |
92 | unsigned int nbytes; | 89 | unsigned int nbytes; |
@@ -97,7 +94,7 @@ static int ecb_desall_crypt(struct blkcipher_desc *desc, long func, | |||
97 | u8 *out = walk->dst.virt.addr; | 94 | u8 *out = walk->dst.virt.addr; |
98 | u8 *in = walk->src.virt.addr; | 95 | u8 *in = walk->src.virt.addr; |
99 | 96 | ||
100 | ret = crypt_s390_km(func, param, out, in, n); | 97 | ret = crypt_s390_km(func, key, out, in, n); |
101 | BUG_ON((ret < 0) || (ret != n)); | 98 | BUG_ON((ret < 0) || (ret != n)); |
102 | 99 | ||
103 | nbytes &= DES_BLOCK_SIZE - 1; | 100 | nbytes &= DES_BLOCK_SIZE - 1; |
@@ -108,7 +105,7 @@ static int ecb_desall_crypt(struct blkcipher_desc *desc, long func, | |||
108 | } | 105 | } |
109 | 106 | ||
110 | static int cbc_desall_crypt(struct blkcipher_desc *desc, long func, | 107 | static int cbc_desall_crypt(struct blkcipher_desc *desc, long func, |
111 | void *param, struct blkcipher_walk *walk) | 108 | u8 *iv, struct blkcipher_walk *walk) |
112 | { | 109 | { |
113 | int ret = blkcipher_walk_virt(desc, walk); | 110 | int ret = blkcipher_walk_virt(desc, walk); |
114 | unsigned int nbytes = walk->nbytes; | 111 | unsigned int nbytes = walk->nbytes; |
@@ -116,20 +113,20 @@ static int cbc_desall_crypt(struct blkcipher_desc *desc, long func, | |||
116 | if (!nbytes) | 113 | if (!nbytes) |
117 | goto out; | 114 | goto out; |
118 | 115 | ||
119 | memcpy(param, walk->iv, DES_BLOCK_SIZE); | 116 | memcpy(iv, walk->iv, DES_BLOCK_SIZE); |
120 | do { | 117 | do { |
121 | /* only use complete blocks */ | 118 | /* only use complete blocks */ |
122 | unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1); | 119 | unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1); |
123 | u8 *out = walk->dst.virt.addr; | 120 | u8 *out = walk->dst.virt.addr; |
124 | u8 *in = walk->src.virt.addr; | 121 | u8 *in = walk->src.virt.addr; |
125 | 122 | ||
126 | ret = crypt_s390_kmc(func, param, out, in, n); | 123 | ret = crypt_s390_kmc(func, iv, out, in, n); |
127 | BUG_ON((ret < 0) || (ret != n)); | 124 | BUG_ON((ret < 0) || (ret != n)); |
128 | 125 | ||
129 | nbytes &= DES_BLOCK_SIZE - 1; | 126 | nbytes &= DES_BLOCK_SIZE - 1; |
130 | ret = blkcipher_walk_done(desc, walk, nbytes); | 127 | ret = blkcipher_walk_done(desc, walk, nbytes); |
131 | } while ((nbytes = walk->nbytes)); | 128 | } while ((nbytes = walk->nbytes)); |
132 | memcpy(walk->iv, param, DES_BLOCK_SIZE); | 129 | memcpy(walk->iv, iv, DES_BLOCK_SIZE); |
133 | 130 | ||
134 | out: | 131 | out: |
135 | return ret; | 132 | return ret; |
@@ -139,22 +136,22 @@ static int ecb_des_encrypt(struct blkcipher_desc *desc, | |||
139 | struct scatterlist *dst, struct scatterlist *src, | 136 | struct scatterlist *dst, struct scatterlist *src, |
140 | unsigned int nbytes) | 137 | unsigned int nbytes) |
141 | { | 138 | { |
142 | struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | 139 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
143 | struct blkcipher_walk walk; | 140 | struct blkcipher_walk walk; |
144 | 141 | ||
145 | blkcipher_walk_init(&walk, dst, src, nbytes); | 142 | blkcipher_walk_init(&walk, dst, src, nbytes); |
146 | return ecb_desall_crypt(desc, KM_DEA_ENCRYPT, sctx->key, &walk); | 143 | return ecb_desall_crypt(desc, KM_DEA_ENCRYPT, ctx->key, &walk); |
147 | } | 144 | } |
148 | 145 | ||
149 | static int ecb_des_decrypt(struct blkcipher_desc *desc, | 146 | static int ecb_des_decrypt(struct blkcipher_desc *desc, |
150 | struct scatterlist *dst, struct scatterlist *src, | 147 | struct scatterlist *dst, struct scatterlist *src, |
151 | unsigned int nbytes) | 148 | unsigned int nbytes) |
152 | { | 149 | { |
153 | struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | 150 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
154 | struct blkcipher_walk walk; | 151 | struct blkcipher_walk walk; |
155 | 152 | ||
156 | blkcipher_walk_init(&walk, dst, src, nbytes); | 153 | blkcipher_walk_init(&walk, dst, src, nbytes); |
157 | return ecb_desall_crypt(desc, KM_DEA_DECRYPT, sctx->key, &walk); | 154 | return ecb_desall_crypt(desc, KM_DEA_DECRYPT, ctx->key, &walk); |
158 | } | 155 | } |
159 | 156 | ||
160 | static struct crypto_alg ecb_des_alg = { | 157 | static struct crypto_alg ecb_des_alg = { |
@@ -163,7 +160,7 @@ static struct crypto_alg ecb_des_alg = { | |||
163 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | 160 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, |
164 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | 161 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
165 | .cra_blocksize = DES_BLOCK_SIZE, | 162 | .cra_blocksize = DES_BLOCK_SIZE, |
166 | .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), | 163 | .cra_ctxsize = sizeof(struct s390_des_ctx), |
167 | .cra_type = &crypto_blkcipher_type, | 164 | .cra_type = &crypto_blkcipher_type, |
168 | .cra_module = THIS_MODULE, | 165 | .cra_module = THIS_MODULE, |
169 | .cra_list = LIST_HEAD_INIT(ecb_des_alg.cra_list), | 166 | .cra_list = LIST_HEAD_INIT(ecb_des_alg.cra_list), |
@@ -182,22 +179,22 @@ static int cbc_des_encrypt(struct blkcipher_desc *desc, | |||
182 | struct scatterlist *dst, struct scatterlist *src, | 179 | struct scatterlist *dst, struct scatterlist *src, |
183 | unsigned int nbytes) | 180 | unsigned int nbytes) |
184 | { | 181 | { |
185 | struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | 182 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
186 | struct blkcipher_walk walk; | 183 | struct blkcipher_walk walk; |
187 | 184 | ||
188 | blkcipher_walk_init(&walk, dst, src, nbytes); | 185 | blkcipher_walk_init(&walk, dst, src, nbytes); |
189 | return cbc_desall_crypt(desc, KMC_DEA_ENCRYPT, sctx->iv, &walk); | 186 | return cbc_desall_crypt(desc, KMC_DEA_ENCRYPT, ctx->iv, &walk); |
190 | } | 187 | } |
191 | 188 | ||
192 | static int cbc_des_decrypt(struct blkcipher_desc *desc, | 189 | static int cbc_des_decrypt(struct blkcipher_desc *desc, |
193 | struct scatterlist *dst, struct scatterlist *src, | 190 | struct scatterlist *dst, struct scatterlist *src, |
194 | unsigned int nbytes) | 191 | unsigned int nbytes) |
195 | { | 192 | { |
196 | struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | 193 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
197 | struct blkcipher_walk walk; | 194 | struct blkcipher_walk walk; |
198 | 195 | ||
199 | blkcipher_walk_init(&walk, dst, src, nbytes); | 196 | blkcipher_walk_init(&walk, dst, src, nbytes); |
200 | return cbc_desall_crypt(desc, KMC_DEA_DECRYPT, sctx->iv, &walk); | 197 | return cbc_desall_crypt(desc, KMC_DEA_DECRYPT, ctx->iv, &walk); |
201 | } | 198 | } |
202 | 199 | ||
203 | static struct crypto_alg cbc_des_alg = { | 200 | static struct crypto_alg cbc_des_alg = { |
@@ -206,7 +203,7 @@ static struct crypto_alg cbc_des_alg = { | |||
206 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | 203 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, |
207 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | 204 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
208 | .cra_blocksize = DES_BLOCK_SIZE, | 205 | .cra_blocksize = DES_BLOCK_SIZE, |
209 | .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), | 206 | .cra_ctxsize = sizeof(struct s390_des_ctx), |
210 | .cra_type = &crypto_blkcipher_type, | 207 | .cra_type = &crypto_blkcipher_type, |
211 | .cra_module = THIS_MODULE, | 208 | .cra_module = THIS_MODULE, |
212 | .cra_list = LIST_HEAD_INIT(cbc_des_alg.cra_list), | 209 | .cra_list = LIST_HEAD_INIT(cbc_des_alg.cra_list), |
@@ -235,10 +232,10 @@ static struct crypto_alg cbc_des_alg = { | |||
235 | * property. | 232 | * property. |
236 | * | 233 | * |
237 | */ | 234 | */ |
238 | static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, | 235 | static int des3_setkey(struct crypto_tfm *tfm, const u8 *key, |
239 | unsigned int keylen) | 236 | unsigned int key_len) |
240 | { | 237 | { |
241 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); | 238 | struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); |
242 | u32 *flags = &tfm->crt_flags; | 239 | u32 *flags = &tfm->crt_flags; |
243 | 240 | ||
244 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && | 241 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && |
@@ -248,141 +245,276 @@ static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
248 | *flags |= CRYPTO_TFM_RES_WEAK_KEY; | 245 | *flags |= CRYPTO_TFM_RES_WEAK_KEY; |
249 | return -EINVAL; | 246 | return -EINVAL; |
250 | } | 247 | } |
251 | memcpy(dctx->key, key, keylen); | 248 | memcpy(ctx->key, key, key_len); |
252 | return 0; | 249 | return 0; |
253 | } | 250 | } |
254 | 251 | ||
255 | static void des3_192_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | 252 | static void des3_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) |
256 | { | 253 | { |
257 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); | 254 | struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); |
258 | 255 | ||
259 | crypt_s390_km(KM_TDEA_192_ENCRYPT, dctx->key, dst, (void*)src, | 256 | crypt_s390_km(KM_TDEA_192_ENCRYPT, ctx->key, dst, src, DES_BLOCK_SIZE); |
260 | DES_BLOCK_SIZE); | ||
261 | } | 257 | } |
262 | 258 | ||
263 | static void des3_192_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | 259 | static void des3_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) |
264 | { | 260 | { |
265 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); | 261 | struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); |
266 | 262 | ||
267 | crypt_s390_km(KM_TDEA_192_DECRYPT, dctx->key, dst, (void*)src, | 263 | crypt_s390_km(KM_TDEA_192_DECRYPT, ctx->key, dst, src, DES_BLOCK_SIZE); |
268 | DES_BLOCK_SIZE); | ||
269 | } | 264 | } |
270 | 265 | ||
271 | static struct crypto_alg des3_192_alg = { | 266 | static struct crypto_alg des3_alg = { |
272 | .cra_name = "des3_ede", | 267 | .cra_name = "des3_ede", |
273 | .cra_driver_name = "des3_ede-s390", | 268 | .cra_driver_name = "des3_ede-s390", |
274 | .cra_priority = CRYPT_S390_PRIORITY, | 269 | .cra_priority = CRYPT_S390_PRIORITY, |
275 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | 270 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
276 | .cra_blocksize = DES_BLOCK_SIZE, | 271 | .cra_blocksize = DES_BLOCK_SIZE, |
277 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), | 272 | .cra_ctxsize = sizeof(struct s390_des_ctx), |
278 | .cra_module = THIS_MODULE, | 273 | .cra_module = THIS_MODULE, |
279 | .cra_list = LIST_HEAD_INIT(des3_192_alg.cra_list), | 274 | .cra_list = LIST_HEAD_INIT(des3_alg.cra_list), |
280 | .cra_u = { | 275 | .cra_u = { |
281 | .cipher = { | 276 | .cipher = { |
282 | .cia_min_keysize = DES3_192_KEY_SIZE, | 277 | .cia_min_keysize = DES3_KEY_SIZE, |
283 | .cia_max_keysize = DES3_192_KEY_SIZE, | 278 | .cia_max_keysize = DES3_KEY_SIZE, |
284 | .cia_setkey = des3_192_setkey, | 279 | .cia_setkey = des3_setkey, |
285 | .cia_encrypt = des3_192_encrypt, | 280 | .cia_encrypt = des3_encrypt, |
286 | .cia_decrypt = des3_192_decrypt, | 281 | .cia_decrypt = des3_decrypt, |
287 | } | 282 | } |
288 | } | 283 | } |
289 | }; | 284 | }; |
290 | 285 | ||
291 | static int ecb_des3_192_encrypt(struct blkcipher_desc *desc, | 286 | static int ecb_des3_encrypt(struct blkcipher_desc *desc, |
292 | struct scatterlist *dst, | 287 | struct scatterlist *dst, struct scatterlist *src, |
293 | struct scatterlist *src, unsigned int nbytes) | 288 | unsigned int nbytes) |
294 | { | 289 | { |
295 | struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | 290 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
296 | struct blkcipher_walk walk; | 291 | struct blkcipher_walk walk; |
297 | 292 | ||
298 | blkcipher_walk_init(&walk, dst, src, nbytes); | 293 | blkcipher_walk_init(&walk, dst, src, nbytes); |
299 | return ecb_desall_crypt(desc, KM_TDEA_192_ENCRYPT, sctx->key, &walk); | 294 | return ecb_desall_crypt(desc, KM_TDEA_192_ENCRYPT, ctx->key, &walk); |
300 | } | 295 | } |
301 | 296 | ||
302 | static int ecb_des3_192_decrypt(struct blkcipher_desc *desc, | 297 | static int ecb_des3_decrypt(struct blkcipher_desc *desc, |
303 | struct scatterlist *dst, | 298 | struct scatterlist *dst, struct scatterlist *src, |
304 | struct scatterlist *src, unsigned int nbytes) | 299 | unsigned int nbytes) |
305 | { | 300 | { |
306 | struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | 301 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
307 | struct blkcipher_walk walk; | 302 | struct blkcipher_walk walk; |
308 | 303 | ||
309 | blkcipher_walk_init(&walk, dst, src, nbytes); | 304 | blkcipher_walk_init(&walk, dst, src, nbytes); |
310 | return ecb_desall_crypt(desc, KM_TDEA_192_DECRYPT, sctx->key, &walk); | 305 | return ecb_desall_crypt(desc, KM_TDEA_192_DECRYPT, ctx->key, &walk); |
311 | } | 306 | } |
312 | 307 | ||
313 | static struct crypto_alg ecb_des3_192_alg = { | 308 | static struct crypto_alg ecb_des3_alg = { |
314 | .cra_name = "ecb(des3_ede)", | 309 | .cra_name = "ecb(des3_ede)", |
315 | .cra_driver_name = "ecb-des3_ede-s390", | 310 | .cra_driver_name = "ecb-des3_ede-s390", |
316 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | 311 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, |
317 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | 312 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
318 | .cra_blocksize = DES_BLOCK_SIZE, | 313 | .cra_blocksize = DES_BLOCK_SIZE, |
319 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), | 314 | .cra_ctxsize = sizeof(struct s390_des_ctx), |
320 | .cra_type = &crypto_blkcipher_type, | 315 | .cra_type = &crypto_blkcipher_type, |
321 | .cra_module = THIS_MODULE, | 316 | .cra_module = THIS_MODULE, |
322 | .cra_list = LIST_HEAD_INIT( | 317 | .cra_list = LIST_HEAD_INIT( |
323 | ecb_des3_192_alg.cra_list), | 318 | ecb_des3_alg.cra_list), |
324 | .cra_u = { | 319 | .cra_u = { |
325 | .blkcipher = { | 320 | .blkcipher = { |
326 | .min_keysize = DES3_192_KEY_SIZE, | 321 | .min_keysize = DES3_KEY_SIZE, |
327 | .max_keysize = DES3_192_KEY_SIZE, | 322 | .max_keysize = DES3_KEY_SIZE, |
328 | .setkey = des3_192_setkey, | 323 | .setkey = des3_setkey, |
329 | .encrypt = ecb_des3_192_encrypt, | 324 | .encrypt = ecb_des3_encrypt, |
330 | .decrypt = ecb_des3_192_decrypt, | 325 | .decrypt = ecb_des3_decrypt, |
331 | } | 326 | } |
332 | } | 327 | } |
333 | }; | 328 | }; |
334 | 329 | ||
335 | static int cbc_des3_192_encrypt(struct blkcipher_desc *desc, | 330 | static int cbc_des3_encrypt(struct blkcipher_desc *desc, |
336 | struct scatterlist *dst, | 331 | struct scatterlist *dst, struct scatterlist *src, |
337 | struct scatterlist *src, unsigned int nbytes) | 332 | unsigned int nbytes) |
338 | { | 333 | { |
339 | struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | 334 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
340 | struct blkcipher_walk walk; | 335 | struct blkcipher_walk walk; |
341 | 336 | ||
342 | blkcipher_walk_init(&walk, dst, src, nbytes); | 337 | blkcipher_walk_init(&walk, dst, src, nbytes); |
343 | return cbc_desall_crypt(desc, KMC_TDEA_192_ENCRYPT, sctx->iv, &walk); | 338 | return cbc_desall_crypt(desc, KMC_TDEA_192_ENCRYPT, ctx->iv, &walk); |
344 | } | 339 | } |
345 | 340 | ||
346 | static int cbc_des3_192_decrypt(struct blkcipher_desc *desc, | 341 | static int cbc_des3_decrypt(struct blkcipher_desc *desc, |
347 | struct scatterlist *dst, | 342 | struct scatterlist *dst, struct scatterlist *src, |
348 | struct scatterlist *src, unsigned int nbytes) | 343 | unsigned int nbytes) |
349 | { | 344 | { |
350 | struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | 345 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
351 | struct blkcipher_walk walk; | 346 | struct blkcipher_walk walk; |
352 | 347 | ||
353 | blkcipher_walk_init(&walk, dst, src, nbytes); | 348 | blkcipher_walk_init(&walk, dst, src, nbytes); |
354 | return cbc_desall_crypt(desc, KMC_TDEA_192_DECRYPT, sctx->iv, &walk); | 349 | return cbc_desall_crypt(desc, KMC_TDEA_192_DECRYPT, ctx->iv, &walk); |
355 | } | 350 | } |
356 | 351 | ||
357 | static struct crypto_alg cbc_des3_192_alg = { | 352 | static struct crypto_alg cbc_des3_alg = { |
358 | .cra_name = "cbc(des3_ede)", | 353 | .cra_name = "cbc(des3_ede)", |
359 | .cra_driver_name = "cbc-des3_ede-s390", | 354 | .cra_driver_name = "cbc-des3_ede-s390", |
360 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | 355 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, |
361 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | 356 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
362 | .cra_blocksize = DES_BLOCK_SIZE, | 357 | .cra_blocksize = DES_BLOCK_SIZE, |
363 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), | 358 | .cra_ctxsize = sizeof(struct s390_des_ctx), |
364 | .cra_type = &crypto_blkcipher_type, | 359 | .cra_type = &crypto_blkcipher_type, |
365 | .cra_module = THIS_MODULE, | 360 | .cra_module = THIS_MODULE, |
366 | .cra_list = LIST_HEAD_INIT( | 361 | .cra_list = LIST_HEAD_INIT( |
367 | cbc_des3_192_alg.cra_list), | 362 | cbc_des3_alg.cra_list), |
368 | .cra_u = { | 363 | .cra_u = { |
369 | .blkcipher = { | 364 | .blkcipher = { |
370 | .min_keysize = DES3_192_KEY_SIZE, | 365 | .min_keysize = DES3_KEY_SIZE, |
371 | .max_keysize = DES3_192_KEY_SIZE, | 366 | .max_keysize = DES3_KEY_SIZE, |
372 | .ivsize = DES_BLOCK_SIZE, | 367 | .ivsize = DES_BLOCK_SIZE, |
373 | .setkey = des3_192_setkey, | 368 | .setkey = des3_setkey, |
374 | .encrypt = cbc_des3_192_encrypt, | 369 | .encrypt = cbc_des3_encrypt, |
375 | .decrypt = cbc_des3_192_decrypt, | 370 | .decrypt = cbc_des3_decrypt, |
376 | } | 371 | } |
377 | } | 372 | } |
378 | }; | 373 | }; |
379 | 374 | ||
380 | static int des_s390_init(void) | 375 | static int ctr_desall_crypt(struct blkcipher_desc *desc, long func, |
376 | struct s390_des_ctx *ctx, struct blkcipher_walk *walk) | ||
377 | { | ||
378 | int ret = blkcipher_walk_virt_block(desc, walk, DES_BLOCK_SIZE); | ||
379 | unsigned int i, n, nbytes; | ||
380 | u8 buf[DES_BLOCK_SIZE]; | ||
381 | u8 *out, *in; | ||
382 | |||
383 | memcpy(ctrblk, walk->iv, DES_BLOCK_SIZE); | ||
384 | while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) { | ||
385 | out = walk->dst.virt.addr; | ||
386 | in = walk->src.virt.addr; | ||
387 | while (nbytes >= DES_BLOCK_SIZE) { | ||
388 | /* align to block size, max. PAGE_SIZE */ | ||
389 | n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : | ||
390 | nbytes & ~(DES_BLOCK_SIZE - 1); | ||
391 | for (i = DES_BLOCK_SIZE; i < n; i += DES_BLOCK_SIZE) { | ||
392 | memcpy(ctrblk + i, ctrblk + i - DES_BLOCK_SIZE, | ||
393 | DES_BLOCK_SIZE); | ||
394 | crypto_inc(ctrblk + i, DES_BLOCK_SIZE); | ||
395 | } | ||
396 | ret = crypt_s390_kmctr(func, ctx->key, out, in, n, ctrblk); | ||
397 | BUG_ON((ret < 0) || (ret != n)); | ||
398 | if (n > DES_BLOCK_SIZE) | ||
399 | memcpy(ctrblk, ctrblk + n - DES_BLOCK_SIZE, | ||
400 | DES_BLOCK_SIZE); | ||
401 | crypto_inc(ctrblk, DES_BLOCK_SIZE); | ||
402 | out += n; | ||
403 | in += n; | ||
404 | nbytes -= n; | ||
405 | } | ||
406 | ret = blkcipher_walk_done(desc, walk, nbytes); | ||
407 | } | ||
408 | |||
409 | /* final block may be < DES_BLOCK_SIZE, copy only nbytes */ | ||
410 | if (nbytes) { | ||
411 | out = walk->dst.virt.addr; | ||
412 | in = walk->src.virt.addr; | ||
413 | ret = crypt_s390_kmctr(func, ctx->key, buf, in, | ||
414 | DES_BLOCK_SIZE, ctrblk); | ||
415 | BUG_ON(ret < 0 || ret != DES_BLOCK_SIZE); | ||
416 | memcpy(out, buf, nbytes); | ||
417 | crypto_inc(ctrblk, DES_BLOCK_SIZE); | ||
418 | ret = blkcipher_walk_done(desc, walk, 0); | ||
419 | } | ||
420 | memcpy(walk->iv, ctrblk, DES_BLOCK_SIZE); | ||
421 | return ret; | ||
422 | } | ||
423 | |||
424 | static int ctr_des_encrypt(struct blkcipher_desc *desc, | ||
425 | struct scatterlist *dst, struct scatterlist *src, | ||
426 | unsigned int nbytes) | ||
427 | { | ||
428 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); | ||
429 | struct blkcipher_walk walk; | ||
430 | |||
431 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
432 | return ctr_desall_crypt(desc, KMCTR_DEA_ENCRYPT, ctx, &walk); | ||
433 | } | ||
434 | |||
435 | static int ctr_des_decrypt(struct blkcipher_desc *desc, | ||
436 | struct scatterlist *dst, struct scatterlist *src, | ||
437 | unsigned int nbytes) | ||
438 | { | ||
439 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); | ||
440 | struct blkcipher_walk walk; | ||
441 | |||
442 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
443 | return ctr_desall_crypt(desc, KMCTR_DEA_DECRYPT, ctx, &walk); | ||
444 | } | ||
445 | |||
446 | static struct crypto_alg ctr_des_alg = { | ||
447 | .cra_name = "ctr(des)", | ||
448 | .cra_driver_name = "ctr-des-s390", | ||
449 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | ||
450 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
451 | .cra_blocksize = 1, | ||
452 | .cra_ctxsize = sizeof(struct s390_des_ctx), | ||
453 | .cra_type = &crypto_blkcipher_type, | ||
454 | .cra_module = THIS_MODULE, | ||
455 | .cra_list = LIST_HEAD_INIT(ctr_des_alg.cra_list), | ||
456 | .cra_u = { | ||
457 | .blkcipher = { | ||
458 | .min_keysize = DES_KEY_SIZE, | ||
459 | .max_keysize = DES_KEY_SIZE, | ||
460 | .ivsize = DES_BLOCK_SIZE, | ||
461 | .setkey = des_setkey, | ||
462 | .encrypt = ctr_des_encrypt, | ||
463 | .decrypt = ctr_des_decrypt, | ||
464 | } | ||
465 | } | ||
466 | }; | ||
467 | |||
468 | static int ctr_des3_encrypt(struct blkcipher_desc *desc, | ||
469 | struct scatterlist *dst, struct scatterlist *src, | ||
470 | unsigned int nbytes) | ||
471 | { | ||
472 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); | ||
473 | struct blkcipher_walk walk; | ||
474 | |||
475 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
476 | return ctr_desall_crypt(desc, KMCTR_TDEA_192_ENCRYPT, ctx, &walk); | ||
477 | } | ||
478 | |||
479 | static int ctr_des3_decrypt(struct blkcipher_desc *desc, | ||
480 | struct scatterlist *dst, struct scatterlist *src, | ||
481 | unsigned int nbytes) | ||
482 | { | ||
483 | struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); | ||
484 | struct blkcipher_walk walk; | ||
485 | |||
486 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
487 | return ctr_desall_crypt(desc, KMCTR_TDEA_192_DECRYPT, ctx, &walk); | ||
488 | } | ||
489 | |||
490 | static struct crypto_alg ctr_des3_alg = { | ||
491 | .cra_name = "ctr(des3_ede)", | ||
492 | .cra_driver_name = "ctr-des3_ede-s390", | ||
493 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | ||
494 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
495 | .cra_blocksize = 1, | ||
496 | .cra_ctxsize = sizeof(struct s390_des_ctx), | ||
497 | .cra_type = &crypto_blkcipher_type, | ||
498 | .cra_module = THIS_MODULE, | ||
499 | .cra_list = LIST_HEAD_INIT(ctr_des3_alg.cra_list), | ||
500 | .cra_u = { | ||
501 | .blkcipher = { | ||
502 | .min_keysize = DES3_KEY_SIZE, | ||
503 | .max_keysize = DES3_KEY_SIZE, | ||
504 | .ivsize = DES_BLOCK_SIZE, | ||
505 | .setkey = des3_setkey, | ||
506 | .encrypt = ctr_des3_encrypt, | ||
507 | .decrypt = ctr_des3_decrypt, | ||
508 | } | ||
509 | } | ||
510 | }; | ||
511 | |||
512 | static int __init des_s390_init(void) | ||
381 | { | 513 | { |
382 | int ret; | 514 | int ret; |
383 | 515 | ||
384 | if (!crypt_s390_func_available(KM_DEA_ENCRYPT) || | 516 | if (!crypt_s390_func_available(KM_DEA_ENCRYPT, CRYPT_S390_MSA) || |
385 | !crypt_s390_func_available(KM_TDEA_192_ENCRYPT)) | 517 | !crypt_s390_func_available(KM_TDEA_192_ENCRYPT, CRYPT_S390_MSA)) |
386 | return -EOPNOTSUPP; | 518 | return -EOPNOTSUPP; |
387 | 519 | ||
388 | ret = crypto_register_alg(&des_alg); | 520 | ret = crypto_register_alg(&des_alg); |
@@ -394,23 +526,46 @@ static int des_s390_init(void) | |||
394 | ret = crypto_register_alg(&cbc_des_alg); | 526 | ret = crypto_register_alg(&cbc_des_alg); |
395 | if (ret) | 527 | if (ret) |
396 | goto cbc_des_err; | 528 | goto cbc_des_err; |
397 | ret = crypto_register_alg(&des3_192_alg); | 529 | ret = crypto_register_alg(&des3_alg); |
398 | if (ret) | 530 | if (ret) |
399 | goto des3_192_err; | 531 | goto des3_err; |
400 | ret = crypto_register_alg(&ecb_des3_192_alg); | 532 | ret = crypto_register_alg(&ecb_des3_alg); |
401 | if (ret) | 533 | if (ret) |
402 | goto ecb_des3_192_err; | 534 | goto ecb_des3_err; |
403 | ret = crypto_register_alg(&cbc_des3_192_alg); | 535 | ret = crypto_register_alg(&cbc_des3_alg); |
404 | if (ret) | 536 | if (ret) |
405 | goto cbc_des3_192_err; | 537 | goto cbc_des3_err; |
538 | |||
539 | if (crypt_s390_func_available(KMCTR_DEA_ENCRYPT, | ||
540 | CRYPT_S390_MSA | CRYPT_S390_MSA4) && | ||
541 | crypt_s390_func_available(KMCTR_TDEA_192_ENCRYPT, | ||
542 | CRYPT_S390_MSA | CRYPT_S390_MSA4)) { | ||
543 | ret = crypto_register_alg(&ctr_des_alg); | ||
544 | if (ret) | ||
545 | goto ctr_des_err; | ||
546 | ret = crypto_register_alg(&ctr_des3_alg); | ||
547 | if (ret) | ||
548 | goto ctr_des3_err; | ||
549 | ctrblk = (u8 *) __get_free_page(GFP_KERNEL); | ||
550 | if (!ctrblk) { | ||
551 | ret = -ENOMEM; | ||
552 | goto ctr_mem_err; | ||
553 | } | ||
554 | } | ||
406 | out: | 555 | out: |
407 | return ret; | 556 | return ret; |
408 | 557 | ||
409 | cbc_des3_192_err: | 558 | ctr_mem_err: |
410 | crypto_unregister_alg(&ecb_des3_192_alg); | 559 | crypto_unregister_alg(&ctr_des3_alg); |
411 | ecb_des3_192_err: | 560 | ctr_des3_err: |
412 | crypto_unregister_alg(&des3_192_alg); | 561 | crypto_unregister_alg(&ctr_des_alg); |
413 | des3_192_err: | 562 | ctr_des_err: |
563 | crypto_unregister_alg(&cbc_des3_alg); | ||
564 | cbc_des3_err: | ||
565 | crypto_unregister_alg(&ecb_des3_alg); | ||
566 | ecb_des3_err: | ||
567 | crypto_unregister_alg(&des3_alg); | ||
568 | des3_err: | ||
414 | crypto_unregister_alg(&cbc_des_alg); | 569 | crypto_unregister_alg(&cbc_des_alg); |
415 | cbc_des_err: | 570 | cbc_des_err: |
416 | crypto_unregister_alg(&ecb_des_alg); | 571 | crypto_unregister_alg(&ecb_des_alg); |
@@ -422,9 +577,14 @@ des_err: | |||
422 | 577 | ||
423 | static void __exit des_s390_exit(void) | 578 | static void __exit des_s390_exit(void) |
424 | { | 579 | { |
425 | crypto_unregister_alg(&cbc_des3_192_alg); | 580 | if (ctrblk) { |
426 | crypto_unregister_alg(&ecb_des3_192_alg); | 581 | crypto_unregister_alg(&ctr_des_alg); |
427 | crypto_unregister_alg(&des3_192_alg); | 582 | crypto_unregister_alg(&ctr_des3_alg); |
583 | free_page((unsigned long) ctrblk); | ||
584 | } | ||
585 | crypto_unregister_alg(&cbc_des3_alg); | ||
586 | crypto_unregister_alg(&ecb_des3_alg); | ||
587 | crypto_unregister_alg(&des3_alg); | ||
428 | crypto_unregister_alg(&cbc_des_alg); | 588 | crypto_unregister_alg(&cbc_des_alg); |
429 | crypto_unregister_alg(&ecb_des_alg); | 589 | crypto_unregister_alg(&ecb_des_alg); |
430 | crypto_unregister_alg(&des_alg); | 590 | crypto_unregister_alg(&des_alg); |
diff --git a/arch/s390/crypto/ghash_s390.c b/arch/s390/crypto/ghash_s390.c new file mode 100644 index 000000000000..b1bd170f24b1 --- /dev/null +++ b/arch/s390/crypto/ghash_s390.c | |||
@@ -0,0 +1,162 @@ | |||
1 | /* | ||
2 | * Cryptographic API. | ||
3 | * | ||
4 | * s390 implementation of the GHASH algorithm for GCM (Galois/Counter Mode). | ||
5 | * | ||
6 | * Copyright IBM Corp. 2011 | ||
7 | * Author(s): Gerald Schaefer <gerald.schaefer@de.ibm.com> | ||
8 | */ | ||
9 | |||
10 | #include <crypto/internal/hash.h> | ||
11 | #include <linux/module.h> | ||
12 | |||
13 | #include "crypt_s390.h" | ||
14 | |||
15 | #define GHASH_BLOCK_SIZE 16 | ||
16 | #define GHASH_DIGEST_SIZE 16 | ||
17 | |||
18 | struct ghash_ctx { | ||
19 | u8 icv[16]; | ||
20 | u8 key[16]; | ||
21 | }; | ||
22 | |||
23 | struct ghash_desc_ctx { | ||
24 | u8 buffer[GHASH_BLOCK_SIZE]; | ||
25 | u32 bytes; | ||
26 | }; | ||
27 | |||
28 | static int ghash_init(struct shash_desc *desc) | ||
29 | { | ||
30 | struct ghash_desc_ctx *dctx = shash_desc_ctx(desc); | ||
31 | |||
32 | memset(dctx, 0, sizeof(*dctx)); | ||
33 | |||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | static int ghash_setkey(struct crypto_shash *tfm, | ||
38 | const u8 *key, unsigned int keylen) | ||
39 | { | ||
40 | struct ghash_ctx *ctx = crypto_shash_ctx(tfm); | ||
41 | |||
42 | if (keylen != GHASH_BLOCK_SIZE) { | ||
43 | crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); | ||
44 | return -EINVAL; | ||
45 | } | ||
46 | |||
47 | memcpy(ctx->key, key, GHASH_BLOCK_SIZE); | ||
48 | memset(ctx->icv, 0, GHASH_BLOCK_SIZE); | ||
49 | |||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | static int ghash_update(struct shash_desc *desc, | ||
54 | const u8 *src, unsigned int srclen) | ||
55 | { | ||
56 | struct ghash_desc_ctx *dctx = shash_desc_ctx(desc); | ||
57 | struct ghash_ctx *ctx = crypto_shash_ctx(desc->tfm); | ||
58 | unsigned int n; | ||
59 | u8 *buf = dctx->buffer; | ||
60 | int ret; | ||
61 | |||
62 | if (dctx->bytes) { | ||
63 | u8 *pos = buf + (GHASH_BLOCK_SIZE - dctx->bytes); | ||
64 | |||
65 | n = min(srclen, dctx->bytes); | ||
66 | dctx->bytes -= n; | ||
67 | srclen -= n; | ||
68 | |||
69 | memcpy(pos, src, n); | ||
70 | src += n; | ||
71 | |||
72 | if (!dctx->bytes) { | ||
73 | ret = crypt_s390_kimd(KIMD_GHASH, ctx, buf, | ||
74 | GHASH_BLOCK_SIZE); | ||
75 | BUG_ON(ret != GHASH_BLOCK_SIZE); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | n = srclen & ~(GHASH_BLOCK_SIZE - 1); | ||
80 | if (n) { | ||
81 | ret = crypt_s390_kimd(KIMD_GHASH, ctx, src, n); | ||
82 | BUG_ON(ret != n); | ||
83 | src += n; | ||
84 | srclen -= n; | ||
85 | } | ||
86 | |||
87 | if (srclen) { | ||
88 | dctx->bytes = GHASH_BLOCK_SIZE - srclen; | ||
89 | memcpy(buf, src, srclen); | ||
90 | } | ||
91 | |||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | static void ghash_flush(struct ghash_ctx *ctx, struct ghash_desc_ctx *dctx) | ||
96 | { | ||
97 | u8 *buf = dctx->buffer; | ||
98 | int ret; | ||
99 | |||
100 | if (dctx->bytes) { | ||
101 | u8 *pos = buf + (GHASH_BLOCK_SIZE - dctx->bytes); | ||
102 | |||
103 | memset(pos, 0, dctx->bytes); | ||
104 | |||
105 | ret = crypt_s390_kimd(KIMD_GHASH, ctx, buf, GHASH_BLOCK_SIZE); | ||
106 | BUG_ON(ret != GHASH_BLOCK_SIZE); | ||
107 | } | ||
108 | |||
109 | dctx->bytes = 0; | ||
110 | } | ||
111 | |||
112 | static int ghash_final(struct shash_desc *desc, u8 *dst) | ||
113 | { | ||
114 | struct ghash_desc_ctx *dctx = shash_desc_ctx(desc); | ||
115 | struct ghash_ctx *ctx = crypto_shash_ctx(desc->tfm); | ||
116 | |||
117 | ghash_flush(ctx, dctx); | ||
118 | memcpy(dst, ctx->icv, GHASH_BLOCK_SIZE); | ||
119 | |||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | static struct shash_alg ghash_alg = { | ||
124 | .digestsize = GHASH_DIGEST_SIZE, | ||
125 | .init = ghash_init, | ||
126 | .update = ghash_update, | ||
127 | .final = ghash_final, | ||
128 | .setkey = ghash_setkey, | ||
129 | .descsize = sizeof(struct ghash_desc_ctx), | ||
130 | .base = { | ||
131 | .cra_name = "ghash", | ||
132 | .cra_driver_name = "ghash-s390", | ||
133 | .cra_priority = CRYPT_S390_PRIORITY, | ||
134 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, | ||
135 | .cra_blocksize = GHASH_BLOCK_SIZE, | ||
136 | .cra_ctxsize = sizeof(struct ghash_ctx), | ||
137 | .cra_module = THIS_MODULE, | ||
138 | .cra_list = LIST_HEAD_INIT(ghash_alg.base.cra_list), | ||
139 | }, | ||
140 | }; | ||
141 | |||
142 | static int __init ghash_mod_init(void) | ||
143 | { | ||
144 | if (!crypt_s390_func_available(KIMD_GHASH, | ||
145 | CRYPT_S390_MSA | CRYPT_S390_MSA4)) | ||
146 | return -EOPNOTSUPP; | ||
147 | |||
148 | return crypto_register_shash(&ghash_alg); | ||
149 | } | ||
150 | |||
151 | static void __exit ghash_mod_exit(void) | ||
152 | { | ||
153 | crypto_unregister_shash(&ghash_alg); | ||
154 | } | ||
155 | |||
156 | module_init(ghash_mod_init); | ||
157 | module_exit(ghash_mod_exit); | ||
158 | |||
159 | MODULE_ALIAS("ghash"); | ||
160 | |||
161 | MODULE_LICENSE("GPL"); | ||
162 | MODULE_DESCRIPTION("GHASH Message Digest Algorithm, s390 implementation"); | ||
diff --git a/arch/s390/crypto/prng.c b/arch/s390/crypto/prng.c index 975e3ab13cb5..0808fbf0f7d3 100644 --- a/arch/s390/crypto/prng.c +++ b/arch/s390/crypto/prng.c | |||
@@ -76,7 +76,7 @@ static void prng_seed(int nbytes) | |||
76 | 76 | ||
77 | /* Add the entropy */ | 77 | /* Add the entropy */ |
78 | while (nbytes >= 8) { | 78 | while (nbytes >= 8) { |
79 | *((__u64 *)parm_block) ^= *((__u64 *)buf+i*8); | 79 | *((__u64 *)parm_block) ^= *((__u64 *)(buf+i)); |
80 | prng_add_entropy(); | 80 | prng_add_entropy(); |
81 | i += 8; | 81 | i += 8; |
82 | nbytes -= 8; | 82 | nbytes -= 8; |
@@ -166,7 +166,7 @@ static int __init prng_init(void) | |||
166 | int ret; | 166 | int ret; |
167 | 167 | ||
168 | /* check if the CPU has a PRNG */ | 168 | /* check if the CPU has a PRNG */ |
169 | if (!crypt_s390_func_available(KMC_PRNG)) | 169 | if (!crypt_s390_func_available(KMC_PRNG, CRYPT_S390_MSA)) |
170 | return -EOPNOTSUPP; | 170 | return -EOPNOTSUPP; |
171 | 171 | ||
172 | if (prng_chunk_size < 8) | 172 | if (prng_chunk_size < 8) |
diff --git a/arch/s390/crypto/sha1_s390.c b/arch/s390/crypto/sha1_s390.c index f6de7826c979..e9868c6e0a08 100644 --- a/arch/s390/crypto/sha1_s390.c +++ b/arch/s390/crypto/sha1_s390.c | |||
@@ -90,7 +90,7 @@ static struct shash_alg alg = { | |||
90 | 90 | ||
91 | static int __init sha1_s390_init(void) | 91 | static int __init sha1_s390_init(void) |
92 | { | 92 | { |
93 | if (!crypt_s390_func_available(KIMD_SHA_1)) | 93 | if (!crypt_s390_func_available(KIMD_SHA_1, CRYPT_S390_MSA)) |
94 | return -EOPNOTSUPP; | 94 | return -EOPNOTSUPP; |
95 | return crypto_register_shash(&alg); | 95 | return crypto_register_shash(&alg); |
96 | } | 96 | } |
diff --git a/arch/s390/crypto/sha256_s390.c b/arch/s390/crypto/sha256_s390.c index 61a7db372121..5ed8d64fc2ed 100644 --- a/arch/s390/crypto/sha256_s390.c +++ b/arch/s390/crypto/sha256_s390.c | |||
@@ -86,7 +86,7 @@ static struct shash_alg alg = { | |||
86 | 86 | ||
87 | static int sha256_s390_init(void) | 87 | static int sha256_s390_init(void) |
88 | { | 88 | { |
89 | if (!crypt_s390_func_available(KIMD_SHA_256)) | 89 | if (!crypt_s390_func_available(KIMD_SHA_256, CRYPT_S390_MSA)) |
90 | return -EOPNOTSUPP; | 90 | return -EOPNOTSUPP; |
91 | 91 | ||
92 | return crypto_register_shash(&alg); | 92 | return crypto_register_shash(&alg); |
diff --git a/arch/s390/crypto/sha512_s390.c b/arch/s390/crypto/sha512_s390.c index 4bf73d0dc525..32a81383b69c 100644 --- a/arch/s390/crypto/sha512_s390.c +++ b/arch/s390/crypto/sha512_s390.c | |||
@@ -132,7 +132,7 @@ static int __init init(void) | |||
132 | { | 132 | { |
133 | int ret; | 133 | int ret; |
134 | 134 | ||
135 | if (!crypt_s390_func_available(KIMD_SHA_512)) | 135 | if (!crypt_s390_func_available(KIMD_SHA_512, CRYPT_S390_MSA)) |
136 | return -EOPNOTSUPP; | 136 | return -EOPNOTSUPP; |
137 | if ((ret = crypto_register_shash(&sha512_alg)) < 0) | 137 | if ((ret = crypto_register_shash(&sha512_alg)) < 0) |
138 | goto out; | 138 | goto out; |
diff --git a/arch/s390/hypfs/hypfs.h b/arch/s390/hypfs/hypfs.h index 80c1526f2af3..d9df5a060a83 100644 --- a/arch/s390/hypfs/hypfs.h +++ b/arch/s390/hypfs/hypfs.h | |||
@@ -47,7 +47,7 @@ struct hypfs_dbfs_data { | |||
47 | void *buf; | 47 | void *buf; |
48 | void *buf_free_ptr; | 48 | void *buf_free_ptr; |
49 | size_t size; | 49 | size_t size; |
50 | struct hypfs_dbfs_file *dbfs_file;; | 50 | struct hypfs_dbfs_file *dbfs_file; |
51 | struct kref kref; | 51 | struct kref kref; |
52 | }; | 52 | }; |
53 | 53 | ||
diff --git a/arch/s390/include/asm/cacheflush.h b/arch/s390/include/asm/cacheflush.h index 43a5c78046db..3e20383d0921 100644 --- a/arch/s390/include/asm/cacheflush.h +++ b/arch/s390/include/asm/cacheflush.h | |||
@@ -11,5 +11,6 @@ void kernel_map_pages(struct page *page, int numpages, int enable); | |||
11 | int set_memory_ro(unsigned long addr, int numpages); | 11 | int set_memory_ro(unsigned long addr, int numpages); |
12 | int set_memory_rw(unsigned long addr, int numpages); | 12 | int set_memory_rw(unsigned long addr, int numpages); |
13 | int set_memory_nx(unsigned long addr, int numpages); | 13 | int set_memory_nx(unsigned long addr, int numpages); |
14 | int set_memory_x(unsigned long addr, int numpages); | ||
14 | 15 | ||
15 | #endif /* _S390_CACHEFLUSH_H */ | 16 | #endif /* _S390_CACHEFLUSH_H */ |
diff --git a/arch/s390/include/asm/diag.h b/arch/s390/include/asm/diag.h index 72b2e2f2d32d..7e91c58072e2 100644 --- a/arch/s390/include/asm/diag.h +++ b/arch/s390/include/asm/diag.h | |||
@@ -9,9 +9,22 @@ | |||
9 | #define _ASM_S390_DIAG_H | 9 | #define _ASM_S390_DIAG_H |
10 | 10 | ||
11 | /* | 11 | /* |
12 | * Diagnose 10: Release pages | 12 | * Diagnose 10: Release page range |
13 | */ | 13 | */ |
14 | extern void diag10(unsigned long addr); | 14 | static inline void diag10_range(unsigned long start_pfn, unsigned long num_pfn) |
15 | { | ||
16 | unsigned long start_addr, end_addr; | ||
17 | |||
18 | start_addr = start_pfn << PAGE_SHIFT; | ||
19 | end_addr = (start_pfn + num_pfn - 1) << PAGE_SHIFT; | ||
20 | |||
21 | asm volatile( | ||
22 | "0: diag %0,%1,0x10\n" | ||
23 | "1:\n" | ||
24 | EX_TABLE(0b, 1b) | ||
25 | EX_TABLE(1b, 1b) | ||
26 | : : "a" (start_addr), "a" (end_addr)); | ||
27 | } | ||
15 | 28 | ||
16 | /* | 29 | /* |
17 | * Diagnose 14: Input spool file manipulation | 30 | * Diagnose 14: Input spool file manipulation |
diff --git a/arch/s390/include/asm/ftrace.h b/arch/s390/include/asm/ftrace.h index 3c29be4836ed..b7931faaef6d 100644 --- a/arch/s390/include/asm/ftrace.h +++ b/arch/s390/include/asm/ftrace.h | |||
@@ -11,15 +11,13 @@ struct dyn_arch_ftrace { }; | |||
11 | 11 | ||
12 | #ifdef CONFIG_64BIT | 12 | #ifdef CONFIG_64BIT |
13 | #define MCOUNT_INSN_SIZE 12 | 13 | #define MCOUNT_INSN_SIZE 12 |
14 | #define MCOUNT_OFFSET 8 | ||
15 | #else | 14 | #else |
16 | #define MCOUNT_INSN_SIZE 20 | 15 | #define MCOUNT_INSN_SIZE 20 |
17 | #define MCOUNT_OFFSET 4 | ||
18 | #endif | 16 | #endif |
19 | 17 | ||
20 | static inline unsigned long ftrace_call_adjust(unsigned long addr) | 18 | static inline unsigned long ftrace_call_adjust(unsigned long addr) |
21 | { | 19 | { |
22 | return addr - MCOUNT_OFFSET; | 20 | return addr; |
23 | } | 21 | } |
24 | 22 | ||
25 | #endif /* __ASSEMBLY__ */ | 23 | #endif /* __ASSEMBLY__ */ |
diff --git a/arch/s390/include/asm/jump_label.h b/arch/s390/include/asm/jump_label.h new file mode 100644 index 000000000000..95a6cf2b5b67 --- /dev/null +++ b/arch/s390/include/asm/jump_label.h | |||
@@ -0,0 +1,37 @@ | |||
1 | #ifndef _ASM_S390_JUMP_LABEL_H | ||
2 | #define _ASM_S390_JUMP_LABEL_H | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | |||
6 | #define JUMP_LABEL_NOP_SIZE 6 | ||
7 | |||
8 | #ifdef CONFIG_64BIT | ||
9 | #define ASM_PTR ".quad" | ||
10 | #define ASM_ALIGN ".balign 8" | ||
11 | #else | ||
12 | #define ASM_PTR ".long" | ||
13 | #define ASM_ALIGN ".balign 4" | ||
14 | #endif | ||
15 | |||
16 | static __always_inline bool arch_static_branch(struct jump_label_key *key) | ||
17 | { | ||
18 | asm goto("0: brcl 0,0\n" | ||
19 | ".pushsection __jump_table, \"aw\"\n" | ||
20 | ASM_ALIGN "\n" | ||
21 | ASM_PTR " 0b, %l[label], %0\n" | ||
22 | ".popsection\n" | ||
23 | : : "X" (key) : : label); | ||
24 | return false; | ||
25 | label: | ||
26 | return true; | ||
27 | } | ||
28 | |||
29 | typedef unsigned long jump_label_t; | ||
30 | |||
31 | struct jump_entry { | ||
32 | jump_label_t code; | ||
33 | jump_label_t target; | ||
34 | jump_label_t key; | ||
35 | }; | ||
36 | |||
37 | #endif | ||
diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h index a6f0e7cc9cde..8c277caa8d3a 100644 --- a/arch/s390/include/asm/mmu_context.h +++ b/arch/s390/include/asm/mmu_context.h | |||
@@ -23,7 +23,7 @@ static inline int init_new_context(struct task_struct *tsk, | |||
23 | #ifdef CONFIG_64BIT | 23 | #ifdef CONFIG_64BIT |
24 | mm->context.asce_bits |= _ASCE_TYPE_REGION3; | 24 | mm->context.asce_bits |= _ASCE_TYPE_REGION3; |
25 | #endif | 25 | #endif |
26 | if (current->mm->context.alloc_pgste) { | 26 | if (current->mm && current->mm->context.alloc_pgste) { |
27 | /* | 27 | /* |
28 | * alloc_pgste indicates, that any NEW context will be created | 28 | * alloc_pgste indicates, that any NEW context will be created |
29 | * with extended page tables. The old context is unchanged. The | 29 | * with extended page tables. The old context is unchanged. The |
diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile index 64230bc392fa..5ff15dacb571 100644 --- a/arch/s390/kernel/Makefile +++ b/arch/s390/kernel/Makefile | |||
@@ -23,7 +23,7 @@ CFLAGS_sysinfo.o += -Iinclude/math-emu -Iarch/s390/math-emu -w | |||
23 | obj-y := bitmap.o traps.o time.o process.o base.o early.o setup.o \ | 23 | obj-y := bitmap.o traps.o time.o process.o base.o early.o setup.o \ |
24 | processor.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o \ | 24 | processor.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o \ |
25 | s390_ext.o debug.o irq.o ipl.o dis.o diag.o mem_detect.o \ | 25 | s390_ext.o debug.o irq.o ipl.o dis.o diag.o mem_detect.o \ |
26 | vdso.o vtime.o sysinfo.o nmi.o sclp.o | 26 | vdso.o vtime.o sysinfo.o nmi.o sclp.o jump_label.o |
27 | 27 | ||
28 | obj-y += $(if $(CONFIG_64BIT),entry64.o,entry.o) | 28 | obj-y += $(if $(CONFIG_64BIT),entry64.o,entry.o) |
29 | obj-y += $(if $(CONFIG_64BIT),reipl64.o,reipl.o) | 29 | obj-y += $(if $(CONFIG_64BIT),reipl64.o,reipl.o) |
diff --git a/arch/s390/kernel/diag.c b/arch/s390/kernel/diag.c index c032d11da8a1..8237fc07ac79 100644 --- a/arch/s390/kernel/diag.c +++ b/arch/s390/kernel/diag.c | |||
@@ -9,27 +9,6 @@ | |||
9 | #include <asm/diag.h> | 9 | #include <asm/diag.h> |
10 | 10 | ||
11 | /* | 11 | /* |
12 | * Diagnose 10: Release pages | ||
13 | */ | ||
14 | void diag10(unsigned long addr) | ||
15 | { | ||
16 | if (addr >= 0x7ff00000) | ||
17 | return; | ||
18 | asm volatile( | ||
19 | #ifdef CONFIG_64BIT | ||
20 | " sam31\n" | ||
21 | " diag %0,%0,0x10\n" | ||
22 | "0: sam64\n" | ||
23 | #else | ||
24 | " diag %0,%0,0x10\n" | ||
25 | "0:\n" | ||
26 | #endif | ||
27 | EX_TABLE(0b, 0b) | ||
28 | : : "a" (addr)); | ||
29 | } | ||
30 | EXPORT_SYMBOL(diag10); | ||
31 | |||
32 | /* | ||
33 | * Diagnose 14: Input spool file manipulation | 12 | * Diagnose 14: Input spool file manipulation |
34 | */ | 13 | */ |
35 | int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode) | 14 | int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode) |
diff --git a/arch/s390/kernel/dis.c b/arch/s390/kernel/dis.c index c83726c9fe03..3d4a78fc1adc 100644 --- a/arch/s390/kernel/dis.c +++ b/arch/s390/kernel/dis.c | |||
@@ -672,6 +672,7 @@ static struct insn opcode_b2[] = { | |||
672 | { "rp", 0x77, INSTR_S_RD }, | 672 | { "rp", 0x77, INSTR_S_RD }, |
673 | { "stcke", 0x78, INSTR_S_RD }, | 673 | { "stcke", 0x78, INSTR_S_RD }, |
674 | { "sacf", 0x79, INSTR_S_RD }, | 674 | { "sacf", 0x79, INSTR_S_RD }, |
675 | { "spp", 0x80, INSTR_S_RD }, | ||
675 | { "stsi", 0x7d, INSTR_S_RD }, | 676 | { "stsi", 0x7d, INSTR_S_RD }, |
676 | { "srnm", 0x99, INSTR_S_RD }, | 677 | { "srnm", 0x99, INSTR_S_RD }, |
677 | { "stfpc", 0x9c, INSTR_S_RD }, | 678 | { "stfpc", 0x9c, INSTR_S_RD }, |
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S index 648f64239a9d..1b67fc6ebdc2 100644 --- a/arch/s390/kernel/entry.S +++ b/arch/s390/kernel/entry.S | |||
@@ -836,7 +836,7 @@ restart_base: | |||
836 | stosm __SF_EMPTY(%r15),0x04 # now we can turn dat on | 836 | stosm __SF_EMPTY(%r15),0x04 # now we can turn dat on |
837 | basr %r14,0 | 837 | basr %r14,0 |
838 | l %r14,restart_addr-.(%r14) | 838 | l %r14,restart_addr-.(%r14) |
839 | br %r14 # branch to start_secondary | 839 | basr %r14,%r14 # branch to start_secondary |
840 | restart_addr: | 840 | restart_addr: |
841 | .long start_secondary | 841 | .long start_secondary |
842 | .align 8 | 842 | .align 8 |
diff --git a/arch/s390/kernel/entry64.S b/arch/s390/kernel/entry64.S index 9d3603d6c511..9fd864563499 100644 --- a/arch/s390/kernel/entry64.S +++ b/arch/s390/kernel/entry64.S | |||
@@ -841,7 +841,7 @@ restart_base: | |||
841 | mvc __LC_SYSTEM_TIMER(8),__TI_system_timer(%r1) | 841 | mvc __LC_SYSTEM_TIMER(8),__TI_system_timer(%r1) |
842 | xc __LC_STEAL_TIMER(8),__LC_STEAL_TIMER | 842 | xc __LC_STEAL_TIMER(8),__LC_STEAL_TIMER |
843 | stosm __SF_EMPTY(%r15),0x04 # now we can turn dat on | 843 | stosm __SF_EMPTY(%r15),0x04 # now we can turn dat on |
844 | jg start_secondary | 844 | brasl %r14,start_secondary |
845 | .align 8 | 845 | .align 8 |
846 | restart_vtime: | 846 | restart_vtime: |
847 | .long 0x7fffffff,0xffffffff | 847 | .long 0x7fffffff,0xffffffff |
diff --git a/arch/s390/kernel/jump_label.c b/arch/s390/kernel/jump_label.c new file mode 100644 index 000000000000..44cc06bedf77 --- /dev/null +++ b/arch/s390/kernel/jump_label.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | * Jump label s390 support | ||
3 | * | ||
4 | * Copyright IBM Corp. 2011 | ||
5 | * Author(s): Jan Glauber <jang@linux.vnet.ibm.com> | ||
6 | */ | ||
7 | #include <linux/module.h> | ||
8 | #include <linux/uaccess.h> | ||
9 | #include <linux/stop_machine.h> | ||
10 | #include <linux/jump_label.h> | ||
11 | #include <asm/ipl.h> | ||
12 | |||
13 | #ifdef HAVE_JUMP_LABEL | ||
14 | |||
15 | struct insn { | ||
16 | u16 opcode; | ||
17 | s32 offset; | ||
18 | } __packed; | ||
19 | |||
20 | struct insn_args { | ||
21 | unsigned long *target; | ||
22 | struct insn *insn; | ||
23 | ssize_t size; | ||
24 | }; | ||
25 | |||
26 | static int __arch_jump_label_transform(void *data) | ||
27 | { | ||
28 | struct insn_args *args = data; | ||
29 | int rc; | ||
30 | |||
31 | rc = probe_kernel_write(args->target, args->insn, args->size); | ||
32 | WARN_ON_ONCE(rc < 0); | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | void arch_jump_label_transform(struct jump_entry *entry, | ||
37 | enum jump_label_type type) | ||
38 | { | ||
39 | struct insn_args args; | ||
40 | struct insn insn; | ||
41 | |||
42 | if (type == JUMP_LABEL_ENABLE) { | ||
43 | /* brcl 15,offset */ | ||
44 | insn.opcode = 0xc0f4; | ||
45 | insn.offset = (entry->target - entry->code) >> 1; | ||
46 | } else { | ||
47 | /* brcl 0,0 */ | ||
48 | insn.opcode = 0xc004; | ||
49 | insn.offset = 0; | ||
50 | } | ||
51 | |||
52 | args.target = (void *) entry->code; | ||
53 | args.insn = &insn; | ||
54 | args.size = JUMP_LABEL_NOP_SIZE; | ||
55 | |||
56 | stop_machine(__arch_jump_label_transform, &args, NULL); | ||
57 | } | ||
58 | |||
59 | #endif | ||
diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c index 63a97db83f96..63c7d9ff220d 100644 --- a/arch/s390/kernel/smp.c +++ b/arch/s390/kernel/smp.c | |||
@@ -165,12 +165,12 @@ static void do_ext_call_interrupt(unsigned int ext_int_code, | |||
165 | kstat_cpu(smp_processor_id()).irqs[EXTINT_IPI]++; | 165 | kstat_cpu(smp_processor_id()).irqs[EXTINT_IPI]++; |
166 | /* | 166 | /* |
167 | * handle bit signal external calls | 167 | * handle bit signal external calls |
168 | * | ||
169 | * For the ec_schedule signal we have to do nothing. All the work | ||
170 | * is done automatically when we return from the interrupt. | ||
171 | */ | 168 | */ |
172 | bits = xchg(&S390_lowcore.ext_call_fast, 0); | 169 | bits = xchg(&S390_lowcore.ext_call_fast, 0); |
173 | 170 | ||
171 | if (test_bit(ec_schedule, &bits)) | ||
172 | scheduler_ipi(); | ||
173 | |||
174 | if (test_bit(ec_call_function, &bits)) | 174 | if (test_bit(ec_call_function, &bits)) |
175 | generic_smp_call_function_interrupt(); | 175 | generic_smp_call_function_interrupt(); |
176 | 176 | ||
diff --git a/arch/s390/kvm/sie64a.S b/arch/s390/kvm/sie64a.S index 7e9d30d567b0..ab0e041ac54c 100644 --- a/arch/s390/kvm/sie64a.S +++ b/arch/s390/kvm/sie64a.S | |||
@@ -48,10 +48,10 @@ sie_irq_handler: | |||
48 | tm __TI_flags+7(%r2),_TIF_EXIT_SIE | 48 | tm __TI_flags+7(%r2),_TIF_EXIT_SIE |
49 | jz 0f | 49 | jz 0f |
50 | larl %r2,sie_exit # work pending, leave sie | 50 | larl %r2,sie_exit # work pending, leave sie |
51 | stg %r2,__LC_RETURN_PSW+8 | 51 | stg %r2,SPI_PSW+8(0,%r15) |
52 | br %r14 | 52 | br %r14 |
53 | 0: larl %r2,sie_reenter # re-enter with guest id | 53 | 0: larl %r2,sie_reenter # re-enter with guest id |
54 | stg %r2,__LC_RETURN_PSW+8 | 54 | stg %r2,SPI_PSW+8(0,%r15) |
55 | 1: br %r14 | 55 | 1: br %r14 |
56 | 56 | ||
57 | /* | 57 | /* |
diff --git a/arch/s390/mm/cmm.c b/arch/s390/mm/cmm.c index c66ffd8dbbb7..1f1dba9dcf58 100644 --- a/arch/s390/mm/cmm.c +++ b/arch/s390/mm/cmm.c | |||
@@ -91,7 +91,7 @@ static long cmm_alloc_pages(long nr, long *counter, | |||
91 | } else | 91 | } else |
92 | free_page((unsigned long) npa); | 92 | free_page((unsigned long) npa); |
93 | } | 93 | } |
94 | diag10(addr); | 94 | diag10_range(addr >> PAGE_SHIFT, 1); |
95 | pa->pages[pa->index++] = addr; | 95 | pa->pages[pa->index++] = addr; |
96 | (*counter)++; | 96 | (*counter)++; |
97 | spin_unlock(&cmm_lock); | 97 | spin_unlock(&cmm_lock); |
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c index 9217e332b118..ab988135e5c6 100644 --- a/arch/s390/mm/fault.c +++ b/arch/s390/mm/fault.c | |||
@@ -543,7 +543,6 @@ static void pfault_interrupt(unsigned int ext_int_code, | |||
543 | struct task_struct *tsk; | 543 | struct task_struct *tsk; |
544 | __u16 subcode; | 544 | __u16 subcode; |
545 | 545 | ||
546 | kstat_cpu(smp_processor_id()).irqs[EXTINT_PFL]++; | ||
547 | /* | 546 | /* |
548 | * Get the external interruption subcode & pfault | 547 | * Get the external interruption subcode & pfault |
549 | * initial/completion signal bit. VM stores this | 548 | * initial/completion signal bit. VM stores this |
@@ -553,14 +552,15 @@ static void pfault_interrupt(unsigned int ext_int_code, | |||
553 | subcode = ext_int_code >> 16; | 552 | subcode = ext_int_code >> 16; |
554 | if ((subcode & 0xff00) != __SUBCODE_MASK) | 553 | if ((subcode & 0xff00) != __SUBCODE_MASK) |
555 | return; | 554 | return; |
555 | kstat_cpu(smp_processor_id()).irqs[EXTINT_PFL]++; | ||
556 | 556 | ||
557 | /* | 557 | /* |
558 | * Get the token (= address of the task structure of the affected task). | 558 | * Get the token (= address of the task structure of the affected task). |
559 | */ | 559 | */ |
560 | #ifdef CONFIG_64BIT | 560 | #ifdef CONFIG_64BIT |
561 | tsk = *(struct task_struct **) param64; | 561 | tsk = (struct task_struct *) param64; |
562 | #else | 562 | #else |
563 | tsk = *(struct task_struct **) param32; | 563 | tsk = (struct task_struct *) param32; |
564 | #endif | 564 | #endif |
565 | 565 | ||
566 | if (subcode & 0x0080) { | 566 | if (subcode & 0x0080) { |
diff --git a/arch/s390/mm/pageattr.c b/arch/s390/mm/pageattr.c index 122ffbd08ce0..f05edcc3beff 100644 --- a/arch/s390/mm/pageattr.c +++ b/arch/s390/mm/pageattr.c | |||
@@ -24,12 +24,13 @@ static void change_page_attr(unsigned long addr, int numpages, | |||
24 | WARN_ON_ONCE(1); | 24 | WARN_ON_ONCE(1); |
25 | continue; | 25 | continue; |
26 | } | 26 | } |
27 | ptep = pte_offset_kernel(pmdp, addr + i * PAGE_SIZE); | 27 | ptep = pte_offset_kernel(pmdp, addr); |
28 | 28 | ||
29 | pte = *ptep; | 29 | pte = *ptep; |
30 | pte = set(pte); | 30 | pte = set(pte); |
31 | ptep_invalidate(&init_mm, addr + i * PAGE_SIZE, ptep); | 31 | ptep_invalidate(&init_mm, addr, ptep); |
32 | *ptep = pte; | 32 | *ptep = pte; |
33 | addr += PAGE_SIZE; | ||
33 | } | 34 | } |
34 | } | 35 | } |
35 | 36 | ||
@@ -53,3 +54,8 @@ int set_memory_nx(unsigned long addr, int numpages) | |||
53 | return 0; | 54 | return 0; |
54 | } | 55 | } |
55 | EXPORT_SYMBOL_GPL(set_memory_nx); | 56 | EXPORT_SYMBOL_GPL(set_memory_nx); |
57 | |||
58 | int set_memory_x(unsigned long addr, int numpages) | ||
59 | { | ||
60 | return 0; | ||
61 | } | ||
diff --git a/arch/s390/oprofile/hwsampler.c b/arch/s390/oprofile/hwsampler.c index 4952872d6f0a..33cbd373cce4 100644 --- a/arch/s390/oprofile/hwsampler.c +++ b/arch/s390/oprofile/hwsampler.c | |||
@@ -1021,20 +1021,14 @@ deallocate_exit: | |||
1021 | return rc; | 1021 | return rc; |
1022 | } | 1022 | } |
1023 | 1023 | ||
1024 | long hwsampler_query_min_interval(void) | 1024 | unsigned long hwsampler_query_min_interval(void) |
1025 | { | 1025 | { |
1026 | if (min_sampler_rate) | 1026 | return min_sampler_rate; |
1027 | return min_sampler_rate; | ||
1028 | else | ||
1029 | return -EINVAL; | ||
1030 | } | 1027 | } |
1031 | 1028 | ||
1032 | long hwsampler_query_max_interval(void) | 1029 | unsigned long hwsampler_query_max_interval(void) |
1033 | { | 1030 | { |
1034 | if (max_sampler_rate) | 1031 | return max_sampler_rate; |
1035 | return max_sampler_rate; | ||
1036 | else | ||
1037 | return -EINVAL; | ||
1038 | } | 1032 | } |
1039 | 1033 | ||
1040 | unsigned long hwsampler_get_sample_overflow_count(unsigned int cpu) | 1034 | unsigned long hwsampler_get_sample_overflow_count(unsigned int cpu) |
diff --git a/arch/s390/oprofile/hwsampler.h b/arch/s390/oprofile/hwsampler.h index 8c72b59316b5..1912f3bb190c 100644 --- a/arch/s390/oprofile/hwsampler.h +++ b/arch/s390/oprofile/hwsampler.h | |||
@@ -102,8 +102,8 @@ int hwsampler_setup(void); | |||
102 | int hwsampler_shutdown(void); | 102 | int hwsampler_shutdown(void); |
103 | int hwsampler_allocate(unsigned long sdbt, unsigned long sdb); | 103 | int hwsampler_allocate(unsigned long sdbt, unsigned long sdb); |
104 | int hwsampler_deallocate(void); | 104 | int hwsampler_deallocate(void); |
105 | long hwsampler_query_min_interval(void); | 105 | unsigned long hwsampler_query_min_interval(void); |
106 | long hwsampler_query_max_interval(void); | 106 | unsigned long hwsampler_query_max_interval(void); |
107 | int hwsampler_start_all(unsigned long interval); | 107 | int hwsampler_start_all(unsigned long interval); |
108 | int hwsampler_stop_all(void); | 108 | int hwsampler_stop_all(void); |
109 | int hwsampler_deactivate(unsigned int cpu); | 109 | int hwsampler_deactivate(unsigned int cpu); |
diff --git a/arch/s390/oprofile/init.c b/arch/s390/oprofile/init.c index c63d7e58352b..5995e9bc72d9 100644 --- a/arch/s390/oprofile/init.c +++ b/arch/s390/oprofile/init.c | |||
@@ -145,15 +145,11 @@ static int oprofile_hwsampler_init(struct oprofile_operations *ops) | |||
145 | * create hwsampler files only if hwsampler_setup() succeeds. | 145 | * create hwsampler files only if hwsampler_setup() succeeds. |
146 | */ | 146 | */ |
147 | oprofile_min_interval = hwsampler_query_min_interval(); | 147 | oprofile_min_interval = hwsampler_query_min_interval(); |
148 | if (oprofile_min_interval < 0) { | 148 | if (oprofile_min_interval == 0) |
149 | oprofile_min_interval = 0; | ||
150 | return -ENODEV; | 149 | return -ENODEV; |
151 | } | ||
152 | oprofile_max_interval = hwsampler_query_max_interval(); | 150 | oprofile_max_interval = hwsampler_query_max_interval(); |
153 | if (oprofile_max_interval < 0) { | 151 | if (oprofile_max_interval == 0) |
154 | oprofile_max_interval = 0; | ||
155 | return -ENODEV; | 152 | return -ENODEV; |
156 | } | ||
157 | 153 | ||
158 | if (oprofile_timer_init(ops)) | 154 | if (oprofile_timer_init(ops)) |
159 | return -ENODEV; | 155 | return -ENODEV; |