summaryrefslogtreecommitdiffstats
path: root/drivers/crypto
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-11-16 15:47:46 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-11-16 15:47:46 -0500
commit5b0e2cb020085efe202123162502e0b551e49a0e (patch)
tree534bbb4c9f98c2ed9a520e11107029e5df38c3c2 /drivers/crypto
parent758f875848d78148cf9a9cdb3ff1ddf29b234056 (diff)
parent3ffa9d9e2a7c10127d8cbf91ea2be15390b450ed (diff)
Merge tag 'powerpc-4.15-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux
Pull powerpc updates from Michael Ellerman: "A bit of a small release, I suspect in part due to me travelling for KS. But my backlog of patches to review is smaller than usual, so I think in part folks just didn't send as much this cycle. Non-highlights: - Five fixes for the >128T address space handling, both to fix bugs in our implementation and to bring the semantics exactly into line with x86. Highlights: - Support for a new OPAL call on bare metal machines which gives us a true NMI (ie. is not masked by MSR[EE]=0) for debugging etc. - Support for Power9 DD2 in the CXL driver. - Improvements to machine check handling so that uncorrectable errors can be reported into the generic memory_failure() machinery. - Some fixes and improvements for VPHN, which is used under PowerVM to notify the Linux partition of topology changes. - Plumbing to enable TM (transactional memory) without suspend on some Power9 processors (PPC_FEATURE2_HTM_NO_SUSPEND). - Support for emulating vector loads form cache-inhibited memory, on some Power9 revisions. - Disable the fast-endian switch "syscall" by default (behind a CONFIG), we believe it has never had any users. - A major rework of the API drivers use when initiating and waiting for long running operations performed by OPAL firmware, and changes to the powernv_flash driver to use the new API. - Several fixes for the handling of FP/VMX/VSX while processes are using transactional memory. - Optimisations of TLB range flushes when using the radix MMU on Power9. - Improvements to the VAS facility used to access coprocessors on Power9, and related improvements to the way the NX crypto driver handles requests. - Implementation of PMEM_API and UACCESS_FLUSHCACHE for 64-bit. Thanks to: Alexey Kardashevskiy, Alistair Popple, Allen Pais, Andrew Donnellan, Aneesh Kumar K.V, Arnd Bergmann, Balbir Singh, Benjamin Herrenschmidt, Breno Leitao, Christophe Leroy, Christophe Lombard, Cyril Bur, Frederic Barrat, Gautham R. Shenoy, Geert Uytterhoeven, Guilherme G. Piccoli, Gustavo Romero, Haren Myneni, Joel Stanley, Kamalesh Babulal, Kautuk Consul, Markus Elfring, Masami Hiramatsu, Michael Bringmann, Michael Neuling, Michal Suchanek, Naveen N. Rao, Nicholas Piggin, Oliver O'Halloran, Paul Mackerras, Pedro Miraglia Franco de Carvalho, Philippe Bergheaud, Sandipan Das, Seth Forshee, Shriya, Stephen Rothwell, Stewart Smith, Sukadev Bhattiprolu, Tyrel Datwyler, Vaibhav Jain, Vaidyanathan Srinivasan, and William A. Kennington III" * tag 'powerpc-4.15-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (151 commits) powerpc/64s: Fix Power9 DD2.0 workarounds by adding DD2.1 feature powerpc/64s: Fix masking of SRR1 bits on instruction fault powerpc/64s: mm_context.addr_limit is only used on hash powerpc/64s/radix: Fix 128TB-512TB virtual address boundary case allocation powerpc/64s/hash: Allow MAP_FIXED allocations to cross 128TB boundary powerpc/64s/hash: Fix fork() with 512TB process address space powerpc/64s/hash: Fix 128TB-512TB virtual address boundary case allocation powerpc/64s/hash: Fix 512T hint detection to use >= 128T powerpc: Fix DABR match on hash based systems powerpc/signal: Properly handle return value from uprobe_deny_signal() powerpc/fadump: use kstrtoint to handle sysfs store powerpc/lib: Implement UACCESS_FLUSHCACHE API powerpc/lib: Implement PMEM API powerpc/powernv/npu: Don't explicitly flush nmmu tlb powerpc/powernv/npu: Use flush_all_mm() instead of flush_tlb_mm() powerpc/powernv/idle: Round up latency and residency values powerpc/kprobes: refactor kprobe_lookup_name for safer string operations powerpc/kprobes: Blacklist emulate_update_regs() from kprobes powerpc/kprobes: Do not disable interrupts for optprobes and kprobes_on_ftrace powerpc/kprobes: Disable preemption before invoking probe handler for optprobes ...
Diffstat (limited to 'drivers/crypto')
-rw-r--r--drivers/crypto/nx/nx-842-powernv.c167
-rw-r--r--drivers/crypto/nx/nx-842.c2
2 files changed, 72 insertions, 97 deletions
diff --git a/drivers/crypto/nx/nx-842-powernv.c b/drivers/crypto/nx/nx-842-powernv.c
index 0f20f5ec9617..f2246a5abcf6 100644
--- a/drivers/crypto/nx/nx-842-powernv.c
+++ b/drivers/crypto/nx/nx-842-powernv.c
@@ -46,7 +46,6 @@ struct nx842_workmem {
46 46
47 ktime_t start; 47 ktime_t start;
48 48
49 struct vas_window *txwin; /* Used with VAS function */
50 char padding[WORKMEM_ALIGN]; /* unused, to allow alignment */ 49 char padding[WORKMEM_ALIGN]; /* unused, to allow alignment */
51} __packed __aligned(WORKMEM_ALIGN); 50} __packed __aligned(WORKMEM_ALIGN);
52 51
@@ -65,7 +64,7 @@ struct nx842_coproc {
65 * Send the request to NX engine on the chip for the corresponding CPU 64 * Send the request to NX engine on the chip for the corresponding CPU
66 * where the process is executing. Use with VAS function. 65 * where the process is executing. Use with VAS function.
67 */ 66 */
68static DEFINE_PER_CPU(struct nx842_coproc *, coproc_inst); 67static DEFINE_PER_CPU(struct vas_window *, cpu_txwin);
69 68
70/* no cpu hotplug on powernv, so this list never changes after init */ 69/* no cpu hotplug on powernv, so this list never changes after init */
71static LIST_HEAD(nx842_coprocs); 70static LIST_HEAD(nx842_coprocs);
@@ -586,16 +585,11 @@ static int nx842_exec_vas(const unsigned char *in, unsigned int inlen,
586 ccw = SET_FIELD(CCW_FC_842, ccw, fc); 585 ccw = SET_FIELD(CCW_FC_842, ccw, fc);
587 crb->ccw = cpu_to_be32(ccw); 586 crb->ccw = cpu_to_be32(ccw);
588 587
589 txwin = wmem->txwin;
590 /* shoudn't happen, we don't load without a coproc */
591 if (!txwin) {
592 pr_err_ratelimited("NX-842 coprocessor is not available");
593 return -ENODEV;
594 }
595
596 do { 588 do {
597 wmem->start = ktime_get(); 589 wmem->start = ktime_get();
598 preempt_disable(); 590 preempt_disable();
591 txwin = this_cpu_read(cpu_txwin);
592
599 /* 593 /*
600 * VAS copy CRB into L2 cache. Refer <asm/vas.h>. 594 * VAS copy CRB into L2 cache. Refer <asm/vas.h>.
601 * @crb and @offset. 595 * @crb and @offset.
@@ -689,25 +683,6 @@ static inline void nx842_add_coprocs_list(struct nx842_coproc *coproc,
689 list_add(&coproc->list, &nx842_coprocs); 683 list_add(&coproc->list, &nx842_coprocs);
690} 684}
691 685
692/*
693 * Identify chip ID for each CPU and save coprocesor adddress for the
694 * corresponding NX engine in percpu coproc_inst.
695 * coproc_inst is used in crypto_init to open send window on the NX instance
696 * for the corresponding CPU / chip where the open request is executed.
697 */
698static void nx842_set_per_cpu_coproc(struct nx842_coproc *coproc)
699{
700 unsigned int i, chip_id;
701
702 for_each_possible_cpu(i) {
703 chip_id = cpu_to_chip_id(i);
704
705 if (coproc->chip_id == chip_id)
706 per_cpu(coproc_inst, i) = coproc;
707 }
708}
709
710
711static struct vas_window *nx842_alloc_txwin(struct nx842_coproc *coproc) 686static struct vas_window *nx842_alloc_txwin(struct nx842_coproc *coproc)
712{ 687{
713 struct vas_window *txwin = NULL; 688 struct vas_window *txwin = NULL;
@@ -725,15 +700,58 @@ static struct vas_window *nx842_alloc_txwin(struct nx842_coproc *coproc)
725 * Open a VAS send window which is used to send request to NX. 700 * Open a VAS send window which is used to send request to NX.
726 */ 701 */
727 txwin = vas_tx_win_open(coproc->vas.id, coproc->ct, &txattr); 702 txwin = vas_tx_win_open(coproc->vas.id, coproc->ct, &txattr);
728 if (IS_ERR(txwin)) { 703 if (IS_ERR(txwin))
729 pr_err("ibm,nx-842: Can not open TX window: %ld\n", 704 pr_err("ibm,nx-842: Can not open TX window: %ld\n",
730 PTR_ERR(txwin)); 705 PTR_ERR(txwin));
731 return NULL;
732 }
733 706
734 return txwin; 707 return txwin;
735} 708}
736 709
710/*
711 * Identify chip ID for each CPU, open send wndow for the corresponding NX
712 * engine and save txwin in percpu cpu_txwin.
713 * cpu_txwin is used in copy/paste operation for each compression /
714 * decompression request.
715 */
716static int nx842_open_percpu_txwins(void)
717{
718 struct nx842_coproc *coproc, *n;
719 unsigned int i, chip_id;
720
721 for_each_possible_cpu(i) {
722 struct vas_window *txwin = NULL;
723
724 chip_id = cpu_to_chip_id(i);
725
726 list_for_each_entry_safe(coproc, n, &nx842_coprocs, list) {
727 /*
728 * Kernel requests use only high priority FIFOs. So
729 * open send windows for these FIFOs.
730 */
731
732 if (coproc->ct != VAS_COP_TYPE_842_HIPRI)
733 continue;
734
735 if (coproc->chip_id == chip_id) {
736 txwin = nx842_alloc_txwin(coproc);
737 if (IS_ERR(txwin))
738 return PTR_ERR(txwin);
739
740 per_cpu(cpu_txwin, i) = txwin;
741 break;
742 }
743 }
744
745 if (!per_cpu(cpu_txwin, i)) {
746 /* shoudn't happen, Each chip will have NX engine */
747 pr_err("NX engine is not availavle for CPU %d\n", i);
748 return -EINVAL;
749 }
750 }
751
752 return 0;
753}
754
737static int __init vas_cfg_coproc_info(struct device_node *dn, int chip_id, 755static int __init vas_cfg_coproc_info(struct device_node *dn, int chip_id,
738 int vasid) 756 int vasid)
739{ 757{
@@ -819,14 +837,6 @@ static int __init vas_cfg_coproc_info(struct device_node *dn, int chip_id,
819 coproc->vas.id = vasid; 837 coproc->vas.id = vasid;
820 nx842_add_coprocs_list(coproc, chip_id); 838 nx842_add_coprocs_list(coproc, chip_id);
821 839
822 /*
823 * Kernel requests use only high priority FIFOs. So save coproc
824 * info in percpu coproc_inst which will be used to open send
825 * windows for crypto open requests later.
826 */
827 if (coproc->ct == VAS_COP_TYPE_842_HIPRI)
828 nx842_set_per_cpu_coproc(coproc);
829
830 return 0; 840 return 0;
831 841
832err_out: 842err_out:
@@ -847,24 +857,12 @@ static int __init nx842_powernv_probe_vas(struct device_node *pn)
847 return -EINVAL; 857 return -EINVAL;
848 } 858 }
849 859
850 for_each_compatible_node(dn, NULL, "ibm,power9-vas-x") { 860 vasid = chip_to_vas_id(chip_id);
851 if (of_get_ibm_chip_id(dn) == chip_id) 861 if (vasid < 0) {
852 break; 862 pr_err("Unable to map chip_id %d to vasid\n", chip_id);
853 }
854
855 if (!dn) {
856 pr_err("Missing VAS device node\n");
857 return -EINVAL; 863 return -EINVAL;
858 } 864 }
859 865
860 if (of_property_read_u32(dn, "ibm,vas-id", &vasid)) {
861 pr_err("Missing ibm,vas-id device property\n");
862 of_node_put(dn);
863 return -EINVAL;
864 }
865
866 of_node_put(dn);
867
868 for_each_child_of_node(pn, dn) { 866 for_each_child_of_node(pn, dn) {
869 if (of_device_is_compatible(dn, "ibm,p9-nx-842")) { 867 if (of_device_is_compatible(dn, "ibm,p9-nx-842")) {
870 ret = vas_cfg_coproc_info(dn, chip_id, vasid); 868 ret = vas_cfg_coproc_info(dn, chip_id, vasid);
@@ -928,6 +926,19 @@ static int __init nx842_powernv_probe(struct device_node *dn)
928static void nx842_delete_coprocs(void) 926static void nx842_delete_coprocs(void)
929{ 927{
930 struct nx842_coproc *coproc, *n; 928 struct nx842_coproc *coproc, *n;
929 struct vas_window *txwin;
930 int i;
931
932 /*
933 * close percpu txwins that are opened for the corresponding coproc.
934 */
935 for_each_possible_cpu(i) {
936 txwin = per_cpu(cpu_txwin, i);
937 if (txwin)
938 vas_win_close(txwin);
939
940 per_cpu(cpu_txwin, i) = 0;
941 }
931 942
932 list_for_each_entry_safe(coproc, n, &nx842_coprocs, list) { 943 list_for_each_entry_safe(coproc, n, &nx842_coprocs, list) {
933 if (coproc->vas.rxwin) 944 if (coproc->vas.rxwin)
@@ -954,46 +965,6 @@ static struct nx842_driver nx842_powernv_driver = {
954 .decompress = nx842_powernv_decompress, 965 .decompress = nx842_powernv_decompress,
955}; 966};
956 967
957static int nx842_powernv_crypto_init_vas(struct crypto_tfm *tfm)
958{
959 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
960 struct nx842_workmem *wmem;
961 struct nx842_coproc *coproc;
962 int ret;
963
964 ret = nx842_crypto_init(tfm, &nx842_powernv_driver);
965
966 if (ret)
967 return ret;
968
969 wmem = PTR_ALIGN((struct nx842_workmem *)ctx->wmem, WORKMEM_ALIGN);
970 coproc = per_cpu(coproc_inst, smp_processor_id());
971
972 ret = -EINVAL;
973 if (coproc && coproc->vas.rxwin) {
974 wmem->txwin = nx842_alloc_txwin(coproc);
975 if (!IS_ERR(wmem->txwin))
976 return 0;
977
978 ret = PTR_ERR(wmem->txwin);
979 }
980
981 return ret;
982}
983
984void nx842_powernv_crypto_exit_vas(struct crypto_tfm *tfm)
985{
986 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
987 struct nx842_workmem *wmem;
988
989 wmem = PTR_ALIGN((struct nx842_workmem *)ctx->wmem, WORKMEM_ALIGN);
990
991 if (wmem && wmem->txwin)
992 vas_win_close(wmem->txwin);
993
994 nx842_crypto_exit(tfm);
995}
996
997static int nx842_powernv_crypto_init(struct crypto_tfm *tfm) 968static int nx842_powernv_crypto_init(struct crypto_tfm *tfm)
998{ 969{
999 return nx842_crypto_init(tfm, &nx842_powernv_driver); 970 return nx842_crypto_init(tfm, &nx842_powernv_driver);
@@ -1044,9 +1015,13 @@ static __init int nx842_powernv_init(void)
1044 1015
1045 nx842_powernv_exec = nx842_exec_icswx; 1016 nx842_powernv_exec = nx842_exec_icswx;
1046 } else { 1017 } else {
1018 ret = nx842_open_percpu_txwins();
1019 if (ret) {
1020 nx842_delete_coprocs();
1021 return ret;
1022 }
1023
1047 nx842_powernv_exec = nx842_exec_vas; 1024 nx842_powernv_exec = nx842_exec_vas;
1048 nx842_powernv_alg.cra_init = nx842_powernv_crypto_init_vas;
1049 nx842_powernv_alg.cra_exit = nx842_powernv_crypto_exit_vas;
1050 } 1025 }
1051 1026
1052 ret = crypto_register_alg(&nx842_powernv_alg); 1027 ret = crypto_register_alg(&nx842_powernv_alg);
diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
index da3cb8c35ec7..d94e25df503b 100644
--- a/drivers/crypto/nx/nx-842.c
+++ b/drivers/crypto/nx/nx-842.c
@@ -116,7 +116,7 @@ int nx842_crypto_init(struct crypto_tfm *tfm, struct nx842_driver *driver)
116 116
117 spin_lock_init(&ctx->lock); 117 spin_lock_init(&ctx->lock);
118 ctx->driver = driver; 118 ctx->driver = driver;
119 ctx->wmem = kzalloc(driver->workmem_size, GFP_KERNEL); 119 ctx->wmem = kmalloc(driver->workmem_size, GFP_KERNEL);
120 ctx->sbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER); 120 ctx->sbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER);
121 ctx->dbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER); 121 ctx->dbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER);
122 if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) { 122 if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) {