From patchwork Sun Apr 11 00:29:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195973 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6AA7C433B4 for ; Sun, 11 Apr 2021 00:29:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B18E461008 for ; Sun, 11 Apr 2021 00:29:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234680AbhDKA3u (ORCPT ); Sat, 10 Apr 2021 20:29:50 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43460 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKA3u (ORCPT ); Sat, 10 Apr 2021 20:29:50 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B04KuJ145885; Sat, 10 Apr 2021 20:29:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=BpUOCiXkn3Lnaz7oK7kSbg4xQWKMOF02ZZA9A0eflHg=; b=aXxG2RdsdtWHw1zhQk6R9YUCiLctAgrfvQa/P/OWIxkFLBDU6r8d2bozgdHaDmIdWUbk QcQdOgJQlfz+ko8212YSAnmmjV5NV9YsiwLie+W5LBD3Wnnq7oEuhZ/g+wjemoK857nE +fZDy6qyXtfFkcUZ0QKPh5dJEbc38TsY+gnUNHLpVjqWZWgZqZHazexxldo2Akj80x4K T2gIB1Y2oXHHPrnFzYRZZwbd/T4hRygSyPIHRjwtmbV1uCWAsCQ5gT/IRLAaGAIlkJdA ahFZ3pHzbXotiGPc+6cAOaAW7fiZC9J5P7AjxoDu42bMA8OtCrrU8T9Axkb4H1n19NuI Ug== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u85xc3g7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:29:29 -0400 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0H8fF179570; Sat, 10 Apr 2021 20:29:29 -0400 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u85xc3g1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:29:29 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0Swq2002031; Sun, 11 Apr 2021 00:29:28 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma03dal.us.ibm.com with ESMTP id 37u3n8ebvq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:29:28 +0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0TRNs26935730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:29:27 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 00BED6E04E; Sun, 11 Apr 2021 00:29:27 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C0CC6E04C; Sun, 11 Apr 2021 00:29:25 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:29:25 +0000 (GMT) Message-ID: <3d21a23080fd0efc09a4784791abb94968b2bad8.camel@linux.ibm.com> Subject: [PATCH 01/16] powerpc/powernv/vas: Rename register/unregister functions From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@us.ibm.com Date: Sat, 10 Apr 2021 17:29:23 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: uo0BjxXah-u77BmoD37Hz1TmNF5xETRw X-Proofpoint-GUID: WjkyLHJjqa5xahQWvA9mP9Cm682n3h6N X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 spamscore=0 phishscore=0 malwarescore=0 impostorscore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104100182 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org powerNV and pseries drivers register / unregister to the corresponding VAS code separately. So rename powerNV VAS API register/unregister functions. Signed-off-by: Haren Myneni --- arch/powerpc/include/asm/vas.h | 6 +++--- arch/powerpc/platforms/powernv/vas-api.c | 10 +++++----- drivers/crypto/nx/nx-common-powernv.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h index e33f80b0ea81..41f73fae7ab8 100644 --- a/arch/powerpc/include/asm/vas.h +++ b/arch/powerpc/include/asm/vas.h @@ -170,8 +170,8 @@ int vas_paste_crb(struct vas_window *win, int offset, bool re); * Only NX GZIP coprocessor type is supported now, but this API can be * used for others in future. */ -int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, - const char *name); -void vas_unregister_coproc_api(void); +int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, + const char *name); +void vas_unregister_api_powernv(void); #endif /* __ASM_POWERPC_VAS_H */ diff --git a/arch/powerpc/platforms/powernv/vas-api.c b/arch/powerpc/platforms/powernv/vas-api.c index 98ed5d8c5441..72d8ce39e56c 100644 --- a/arch/powerpc/platforms/powernv/vas-api.c +++ b/arch/powerpc/platforms/powernv/vas-api.c @@ -207,8 +207,8 @@ static struct file_operations coproc_fops = { * Supporting only nx-gzip coprocessor type now, but this API code * extended to other coprocessor types later. */ -int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, - const char *name) +int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, + const char *name) { int rc = -EINVAL; dev_t devno; @@ -262,9 +262,9 @@ int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, unregister_chrdev_region(coproc_device.devt, 1); return rc; } -EXPORT_SYMBOL_GPL(vas_register_coproc_api); +EXPORT_SYMBOL_GPL(vas_register_api_powernv); -void vas_unregister_coproc_api(void) +void vas_unregister_api_powernv(void) { dev_t devno; @@ -275,4 +275,4 @@ void vas_unregister_coproc_api(void) class_destroy(coproc_device.class); unregister_chrdev_region(coproc_device.devt, 1); } -EXPORT_SYMBOL_GPL(vas_unregister_coproc_api); +EXPORT_SYMBOL_GPL(vas_unregister_api_powernv); diff --git a/drivers/crypto/nx/nx-common-powernv.c b/drivers/crypto/nx/nx-common-powernv.c index 13c65deda8e9..88d728415bb2 100644 --- a/drivers/crypto/nx/nx-common-powernv.c +++ b/drivers/crypto/nx/nx-common-powernv.c @@ -1090,8 +1090,8 @@ static __init int nx_compress_powernv_init(void) * normal FIFO priority is assigned for userspace. * 842 compression is supported only in kernel. */ - ret = vas_register_coproc_api(THIS_MODULE, VAS_COP_TYPE_GZIP, - "nx-gzip"); + ret = vas_register_api_powernv(THIS_MODULE, VAS_COP_TYPE_GZIP, + "nx-gzip"); /* * GZIP is not supported in kernel right now. @@ -1127,7 +1127,7 @@ static void __exit nx_compress_powernv_exit(void) * use. So delete this API use for GZIP engine. */ if (!nx842_ct) - vas_unregister_coproc_api(); + vas_unregister_api_powernv(); crypto_unregister_alg(&nx842_powernv_alg); From patchwork Sun Apr 11 00:31:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195975 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7178C433B4 for ; Sun, 11 Apr 2021 00:31:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 66C5F610E5 for ; Sun, 11 Apr 2021 00:31:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234973AbhDKAbd (ORCPT ); Sat, 10 Apr 2021 20:31:33 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42252 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234548AbhDKAbd (ORCPT ); Sat, 10 Apr 2021 20:31:33 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B04XI8157681; Sat, 10 Apr 2021 20:31:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=B3pS7QUpxE7BrjNKIkJ8ZyLfzPv9EBhx+hdAfvEAlmg=; b=fww/NcTTu2/nQmSVsxCVmNo16LNkxywWtRmg+i773Ma0OHYQFZWpTW/vzvWKrozMTK7y n7YzjdvKD7rcWLZW/ebxFdNlf+qesrOh6CjKM1zzuNAe7zSfmW0iCRv1VeWL99DR0w+o u3V1TrK7StA0THRa70JMuoAjSDugilRWUIQhZaXj29xbrAuNRszYJ3HR9d3A3WDEHLM3 8/TQ++fLuhdzGFencz4dGk69V2K1hAs47XCq73Y6h+3cNtaXtnnSH0PPSSZaD2obd5vI tPT0fYf4oE6UaJGlavPrr/Wzh8raRqILZ8IQVgK0NhSufeVs/mjV7W1Xm+7plqgxWwu0 gQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 37u65nwxwa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:31:08 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0DkSq181443; Sat, 10 Apr 2021 20:31:08 -0400 Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0b-001b2d01.pphosted.com with ESMTP id 37u65nwxw1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:31:08 -0400 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0Rtcb017288; Sun, 11 Apr 2021 00:31:07 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma02wdc.us.ibm.com with ESMTP id 37u3n9549b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:31:07 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0V7Oq31588614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:31:07 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 082C8AC05B; Sun, 11 Apr 2021 00:31:07 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF7DFAC05E; Sun, 11 Apr 2021 00:31:05 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:31:05 +0000 (GMT) Message-ID: Subject: [PATCH 02/16] powerpc/vas: Make VAS API powerpc platform independent From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@us.ibm.com Date: Sat, 10 Apr 2021 17:31:04 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ollXoqM8eZvl6rg3BkTi2bxvLHXQFzNi X-Proofpoint-ORIG-GUID: QBrUL0V83zIzCtNePTamAX5z2fBQjqc0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 priorityscore=1501 phishscore=0 adultscore=0 impostorscore=0 clxscore=1015 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104100182 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Using the same /dev/crypto/nx-gzip interface for both powerNV and pseries. So this patcb moves VAS API to powerpc platform indepedent directory. The actual functionality is not changed in this patch. Signed-off-by: Haren Myneni --- arch/powerpc/Kconfig | 15 +++++ arch/powerpc/include/asm/vas.h | 22 ++++++- arch/powerpc/kernel/Makefile | 1 + .../{platforms/powernv => kernel}/vas-api.c | 64 ++++++++++-------- arch/powerpc/platforms/powernv/Kconfig | 14 ---- arch/powerpc/platforms/powernv/Makefile | 2 +- arch/powerpc/platforms/powernv/vas-window.c | 66 +++++++++++++++++++ 7 files changed, 140 insertions(+), 44 deletions(-) rename arch/powerpc/{platforms/powernv => kernel}/vas-api.c (83%) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 386ae12d8523..7aa1fbf7c1dc 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -478,6 +478,21 @@ config PPC_UV If unsure, say "N". +config PPC_VAS + bool "IBM Virtual Accelerator Switchboard (VAS)" + depends on PPC_POWERNV && PPC_64K_PAGES + default y + help + This enables support for IBM Virtual Accelerator Switchboard (VAS). + + VAS allows accelerators in co-processors like NX-GZIP and NX-842 + to be accessible to kernel subsystems and user processes. + VAS adapters are found in POWER9 and later based systems. + The user mode NX-GZIP support is added on P9 for powerNV and on + P10 for powerVM. + + If unsure, say "N". + config LD_HEAD_STUB_CATCH bool "Reserve 256 bytes to cope with linker stubs in HEAD text" if EXPERT depends on PPC64 diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h index 41f73fae7ab8..6bbade60d8f4 100644 --- a/arch/powerpc/include/asm/vas.h +++ b/arch/powerpc/include/asm/vas.h @@ -5,6 +5,8 @@ #ifndef _ASM_POWERPC_VAS_H #define _ASM_POWERPC_VAS_H +#include + struct vas_window; @@ -48,6 +50,16 @@ enum vas_cop_type { VAS_COP_TYPE_MAX, }; +/* + * User space window operations used for powernv and powerVM + */ +struct vas_user_win_ops { + struct vas_window * (*open_win)(struct vas_tx_win_open_attr *, + enum vas_cop_type); + u64 (*paste_addr)(void *); + int (*close_win)(void *); +}; + /* * Receive window attributes specified by the (in-kernel) owner of window. */ @@ -161,6 +173,9 @@ int vas_copy_crb(void *crb, int offset); * assumed to be true for NX windows. */ int vas_paste_crb(struct vas_window *win, int offset, bool re); +int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, + const char *name); +void vas_unregister_api_powernv(void); /* * Register / unregister coprocessor type to VAS API which will be exported @@ -170,8 +185,9 @@ int vas_paste_crb(struct vas_window *win, int offset, bool re); * Only NX GZIP coprocessor type is supported now, but this API can be * used for others in future. */ -int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, - const char *name); -void vas_unregister_api_powernv(void); +int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, + const char *name, + struct vas_user_win_ops *vops); +void vas_unregister_coproc_api(void); #endif /* __ASM_POWERPC_VAS_H */ diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index 6084fa499aa3..205d8f12bd36 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -118,6 +118,7 @@ obj-$(CONFIG_PPC_UDBG_16550) += legacy_serial.o udbg_16550.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_SWIOTLB) += dma-swiotlb.o obj-$(CONFIG_ARCH_HAS_DMA_SET_MASK) += dma-mask.o +obj-$(CONFIG_PPC_VAS) += vas-api.o pci64-$(CONFIG_PPC64) += pci_dn.o pci-hotplug.o isa-bridge.o obj-$(CONFIG_PCI) += pci_$(BITS).o $(pci64-y) \ diff --git a/arch/powerpc/platforms/powernv/vas-api.c b/arch/powerpc/kernel/vas-api.c similarity index 83% rename from arch/powerpc/platforms/powernv/vas-api.c rename to arch/powerpc/kernel/vas-api.c index 72d8ce39e56c..05d7b99acf41 100644 --- a/arch/powerpc/platforms/powernv/vas-api.c +++ b/arch/powerpc/kernel/vas-api.c @@ -4,15 +4,20 @@ * Copyright (C) 2019 Haren Myneni, IBM Corp */ +#include #include #include #include #include #include #include +#include +#include +#include +#include #include +#include #include -#include "vas.h" /* * The driver creates the device node that can be used as follows: @@ -42,6 +47,7 @@ static struct coproc_dev { dev_t devt; struct class *class; enum vas_cop_type cop_type; + struct vas_user_win_ops *vops; } coproc_device; struct coproc_instance { @@ -72,11 +78,10 @@ static int coproc_open(struct inode *inode, struct file *fp) static int coproc_ioc_tx_win_open(struct file *fp, unsigned long arg) { void __user *uptr = (void __user *)arg; - struct vas_tx_win_attr txattr = {}; struct vas_tx_win_open_attr uattr; struct coproc_instance *cp_inst; struct vas_window *txwin; - int rc, vasid; + int rc; cp_inst = fp->private_data; @@ -93,27 +98,20 @@ static int coproc_ioc_tx_win_open(struct file *fp, unsigned long arg) } if (uattr.version != 1) { - pr_err("Invalid version\n"); + pr_err("Invalid window open API version\n"); return -EINVAL; } - vasid = uattr.vas_id; - - vas_init_tx_win_attr(&txattr, cp_inst->coproc->cop_type); - - txattr.lpid = mfspr(SPRN_LPID); - txattr.pidr = mfspr(SPRN_PID); - txattr.user_win = true; - txattr.rsvd_txbuf_count = false; - txattr.pswid = false; - - pr_devel("Pid %d: Opening txwin, PIDR %ld\n", txattr.pidr, - mfspr(SPRN_PID)); + if (!cp_inst->coproc->vops && !cp_inst->coproc->vops->open_win) { + pr_err("VAS API is not registered\n"); + return -EACCES; + } - txwin = vas_tx_win_open(vasid, cp_inst->coproc->cop_type, &txattr); + txwin = cp_inst->coproc->vops->open_win(&uattr, + cp_inst->coproc->cop_type); if (IS_ERR(txwin)) { - pr_err("%s() vas_tx_win_open() failed, %ld\n", __func__, - PTR_ERR(txwin)); + pr_err("%s() VAS window open failed, %ld\n", __func__, + PTR_ERR(txwin)); return PTR_ERR(txwin); } @@ -125,9 +123,14 @@ static int coproc_ioc_tx_win_open(struct file *fp, unsigned long arg) static int coproc_release(struct inode *inode, struct file *fp) { struct coproc_instance *cp_inst = fp->private_data; + int rc = 0; if (cp_inst->txwin) { - vas_win_close(cp_inst->txwin); + if (cp_inst->coproc->vops && cp_inst->coproc->vops->close_win) { + rc = cp_inst->coproc->vops->close_win(cp_inst->txwin); + if (rc) + return rc; + } cp_inst->txwin = NULL; } @@ -168,7 +171,17 @@ static int coproc_mmap(struct file *fp, struct vm_area_struct *vma) return -EINVAL; } - vas_win_paste_addr(txwin, &paste_addr, NULL); + if (!cp_inst->coproc->vops && !cp_inst->coproc->vops->paste_addr) { + pr_err("%s(): VAS API is not registered\n", __func__); + return -EACCES; + } + + paste_addr = cp_inst->coproc->vops->paste_addr(txwin); + if (!paste_addr) { + pr_err("%s(): Window paste address failed\n", __func__); + return -EINVAL; + } + pfn = paste_addr >> PAGE_SHIFT; /* flags, page_prot from cxl_mmap(), except we want cachable */ @@ -207,8 +220,8 @@ static struct file_operations coproc_fops = { * Supporting only nx-gzip coprocessor type now, but this API code * extended to other coprocessor types later. */ -int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, - const char *name) +int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, + const char *name, struct vas_user_win_ops *vops) { int rc = -EINVAL; dev_t devno; @@ -230,6 +243,7 @@ int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, } coproc_device.class->devnode = coproc_devnode; coproc_device.cop_type = cop_type; + coproc_device.vops = vops; coproc_fops.owner = mod; cdev_init(&coproc_device.cdev, &coproc_fops); @@ -262,9 +276,8 @@ int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, unregister_chrdev_region(coproc_device.devt, 1); return rc; } -EXPORT_SYMBOL_GPL(vas_register_api_powernv); -void vas_unregister_api_powernv(void) +void vas_unregister_coproc_api(void) { dev_t devno; @@ -275,4 +288,3 @@ void vas_unregister_api_powernv(void) class_destroy(coproc_device.class); unregister_chrdev_region(coproc_device.devt, 1); } -EXPORT_SYMBOL_GPL(vas_unregister_api_powernv); diff --git a/arch/powerpc/platforms/powernv/Kconfig b/arch/powerpc/platforms/powernv/Kconfig index 619b093a0657..043eefbbdd28 100644 --- a/arch/powerpc/platforms/powernv/Kconfig +++ b/arch/powerpc/platforms/powernv/Kconfig @@ -33,20 +33,6 @@ config PPC_MEMTRACE Enabling this option allows for runtime allocation of memory (RAM) for hardware tracing. -config PPC_VAS - bool "IBM Virtual Accelerator Switchboard (VAS)" - depends on PPC_POWERNV && PPC_64K_PAGES - default y - help - This enables support for IBM Virtual Accelerator Switchboard (VAS). - - VAS allows accelerators in co-processors like NX-GZIP and NX-842 - to be accessible to kernel subsystems and user processes. - - VAS adapters are found in POWER9 based systems. - - If unsure, say N. - config SCOM_DEBUGFS bool "Expose SCOM controllers via debugfs" depends on DEBUG_FS diff --git a/arch/powerpc/platforms/powernv/Makefile b/arch/powerpc/platforms/powernv/Makefile index 2eb6ae150d1f..c747a1f1d25b 100644 --- a/arch/powerpc/platforms/powernv/Makefile +++ b/arch/powerpc/platforms/powernv/Makefile @@ -18,7 +18,7 @@ obj-$(CONFIG_MEMORY_FAILURE) += opal-memory-errors.o obj-$(CONFIG_OPAL_PRD) += opal-prd.o obj-$(CONFIG_PERF_EVENTS) += opal-imc.o obj-$(CONFIG_PPC_MEMTRACE) += memtrace.o -obj-$(CONFIG_PPC_VAS) += vas.o vas-window.o vas-debug.o vas-fault.o vas-api.o +obj-$(CONFIG_PPC_VAS) += vas.o vas-window.o vas-debug.o vas-fault.o obj-$(CONFIG_OCXL_BASE) += ocxl.o obj-$(CONFIG_SCOM_DEBUGFS) += opal-xscom.o obj-$(CONFIG_PPC_SECURE_BOOT) += opal-secvar.o diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c index 5f5fe63a3d1c..b973dd574b47 100644 --- a/arch/powerpc/platforms/powernv/vas-window.c +++ b/arch/powerpc/platforms/powernv/vas-window.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include "vas.h" #include "copy-paste.h" @@ -1441,3 +1443,67 @@ struct vas_window *vas_pswid_to_window(struct vas_instance *vinst, return window; } + +static struct vas_window *vas_user_win_open(struct vas_tx_win_open_attr *uattr, + enum vas_cop_type cop_type) +{ + struct vas_tx_win_attr txattr = {}; + + vas_init_tx_win_attr(&txattr, cop_type); + + txattr.lpid = mfspr(SPRN_LPID); + txattr.pidr = mfspr(SPRN_PID); + txattr.user_win = true; + txattr.rsvd_txbuf_count = false; + txattr.pswid = false; + + pr_devel("Pid %d: Opening txwin, PIDR %ld\n", txattr.pidr, + mfspr(SPRN_PID)); + + return vas_tx_win_open(uattr->vas_id, cop_type, &txattr); +} + +static u64 vas_user_win_paste_addr(void *addr) +{ + u64 paste_addr; + + vas_win_paste_addr((struct vas_window *)addr, &paste_addr, NULL); + + return paste_addr; +} + +static int vas_user_win_close(void *addr) +{ + struct vas_window *txwin = addr; + + vas_win_close(txwin); + + return 0; +} + +static struct vas_user_win_ops vops = { + .open_win = vas_user_win_open, + .paste_addr = vas_user_win_paste_addr, + .close_win = vas_user_win_close, +}; + +/* + * Supporting only nx-gzip coprocessor type now, but this API code + * extended to other coprocessor types later. + */ +int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, + const char *name) +{ + int rc; + + rc = vas_register_coproc_api(mod, cop_type, name, &vops); + + return rc; +} +EXPORT_SYMBOL_GPL(vas_register_api_powernv); + +void vas_unregister_api_powernv(void) +{ + vas_unregister_coproc_api(); +} +EXPORT_SYMBOL_GPL(vas_unregister_api_powernv); From patchwork Sun Apr 11 00:32:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195977 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3F51C433B4 for ; Sun, 11 Apr 2021 00:32:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88D9C61008 for ; Sun, 11 Apr 2021 00:32:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234680AbhDKAcf (ORCPT ); Sat, 10 Apr 2021 20:32:35 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:41688 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKAce (ORCPT ); Sat, 10 Apr 2021 20:32:34 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B045Io172660; Sat, 10 Apr 2021 20:32:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=UtgSHUNeSe3m3TtSnaEuGJ0/PAgJl16y00+VEWMRNMI=; b=L4N/SgV8G5HDLal/3OB7ncwVayKWyaeCulwiKjM2uHa51PRk2HC+vDfEUBh73Y+O6Ran VZ9+1/sH4ZN8qOin9VU7kHl+hV3srKRhqQQjoIrDaKFEfJEhP9ChW+HDU7dP/98V61Ut Tx+Z4evappSPVC9F+xFnR9HSqPy0AF1PiLt64D1wbg0jfsdhJXW1DSvppc3nZmHjdoaa BEAuQEKWKql3fQW2TUFWBz1tKtuMg6he2ROQNeHiqSaaAaS4+5+4jDgZdbupdJicHUzt nFesr6hqvuhUdb+mUFvDf6Mi4xmhjrGuGn9HqvC2cWAY024ADddhxP5f3ii/we/roHp7 Lg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u80qm30e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:32:11 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0RWw1040716; Sat, 10 Apr 2021 20:32:11 -0400 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u80qm309-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:32:11 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0S1Fn019978; Sun, 11 Apr 2021 00:32:10 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma04dal.us.ibm.com with ESMTP id 37u3n86de2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:32:10 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0W9M125166170 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:32:09 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 21AB9BE054; Sun, 11 Apr 2021 00:32:09 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AC6FCBE053; Sun, 11 Apr 2021 00:32:07 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:32:07 +0000 (GMT) Message-ID: <8d6df414f0a119175cff2c59125712b2f73e045b.camel@linux.ibm.com> Subject: [PATCH 03/16] powerpc/vas: Create take/drop task reference functions From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@us.ibm.com Date: Sat, 10 Apr 2021 17:32:05 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 5jC_zHR94ePyF5p1m6COdst6N9_erfgb X-Proofpoint-GUID: htqiHGpwe2l2PRV8a6xb33V7xOrGQHM2 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 malwarescore=0 impostorscore=0 mlxlogscore=780 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104100182 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Take task reference when each window opens and drops during close. This functionality is needed for powerNV and pseries. So this patch defines the existing code as functions in powerpc platform independent vas-api.c Signed-off-by: Haren Myneni --- arch/powerpc/include/asm/vas.h | 20 ++++++++ arch/powerpc/kernel/vas-api.c | 51 ++++++++++++++++++ arch/powerpc/platforms/powernv/vas-fault.c | 10 ++-- arch/powerpc/platforms/powernv/vas-window.c | 57 ++------------------- arch/powerpc/platforms/powernv/vas.h | 6 +-- 5 files changed, 83 insertions(+), 61 deletions(-) diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h index 6bbade60d8f4..2daaa1a2a9a9 100644 --- a/arch/powerpc/include/asm/vas.h +++ b/arch/powerpc/include/asm/vas.h @@ -5,6 +5,9 @@ #ifndef _ASM_POWERPC_VAS_H #define _ASM_POWERPC_VAS_H +#include +#include +#include #include @@ -60,6 +63,22 @@ struct vas_user_win_ops { int (*close_win)(void *); }; +struct vas_win_task { + struct pid *pid; /* Thread group ID of owner */ + struct pid *tgid; /* Linux process mm_struct */ + struct mm_struct *mm; /* Linux process mm_struct */ +}; + +static inline void vas_drop_reference_task(struct vas_win_task *task) +{ + /* Drop references to pid and mm */ + put_pid(task->pid); + if (task->mm) { + mm_context_remove_vas_window(task->mm); + mmdrop(task->mm); + } +} + /* * Receive window attributes specified by the (in-kernel) owner of window. */ @@ -190,4 +209,5 @@ int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, struct vas_user_win_ops *vops); void vas_unregister_coproc_api(void); +int vas_reference_task(struct vas_win_task *vtask); #endif /* __ASM_POWERPC_VAS_H */ diff --git a/arch/powerpc/kernel/vas-api.c b/arch/powerpc/kernel/vas-api.c index 05d7b99acf41..d98caa734154 100644 --- a/arch/powerpc/kernel/vas-api.c +++ b/arch/powerpc/kernel/vas-api.c @@ -60,6 +60,57 @@ static char *coproc_devnode(struct device *dev, umode_t *mode) return kasprintf(GFP_KERNEL, "crypto/%s", dev_name(dev)); } +/* + * Take reference to pid and mm + */ +int vas_reference_task(struct vas_win_task *vtask) +{ + /* + * Window opened by a child thread may not be closed when + * it exits. So take reference to its pid and release it + * when the window is free by parent thread. + * Acquire a reference to the task's pid to make sure + * pid will not be re-used - needed only for multithread + * applications. + */ + vtask->pid = get_task_pid(current, PIDTYPE_PID); + /* + * Acquire a reference to the task's mm. + */ + vtask->mm = get_task_mm(current); + if (!vtask->mm) { + put_pid(vtask->pid); + pr_err("VAS: pid(%d): mm_struct is not found\n", + current->pid); + return -EPERM; + } + + mmgrab(vtask->mm); + mmput(vtask->mm); + mm_context_add_vas_window(vtask->mm); + /* + * Process closes window during exit. In the case of + * multithread application, the child thread can open + * window and can exit without closing it. Expects parent + * thread to use and close the window. So do not need + * to take pid reference for parent thread. + */ + vtask->tgid = find_get_pid(task_tgid_vnr(current)); + /* + * Even a process that has no foreign real address mapping can + * use an unpaired COPY instruction (to no real effect). Issue + * CP_ABORT to clear any pending COPY and prevent a covert + * channel. + * + * __switch_to() will issue CP_ABORT on future context switches + * if process / thread has any open VAS window (Use + * current->mm->context.vas_windows). + */ + asm volatile(PPC_CP_ABORT); + + return 0; +} + static int coproc_open(struct inode *inode, struct file *fp) { struct coproc_instance *cp_inst; diff --git a/arch/powerpc/platforms/powernv/vas-fault.c b/arch/powerpc/platforms/powernv/vas-fault.c index 3d21fce254b7..a4835cb82c09 100644 --- a/arch/powerpc/platforms/powernv/vas-fault.c +++ b/arch/powerpc/platforms/powernv/vas-fault.c @@ -73,7 +73,7 @@ static void update_csb(struct vas_window *window, * NX user space windows can not be opened for task->mm=NULL * and faults will not be generated for kernel requests. */ - if (WARN_ON_ONCE(!window->mm || !window->user_win)) + if (WARN_ON_ONCE(!window->task.mm || !window->user_win)) return; csb_addr = (void __user *)be64_to_cpu(crb->csb_addr); @@ -92,7 +92,7 @@ static void update_csb(struct vas_window *window, csb.address = crb->stamp.nx.fault_storage_addr; csb.flags = 0; - pid = window->pid; + pid = window->task.pid; tsk = get_pid_task(pid, PIDTYPE_PID); /* * Process closes send window after all pending NX requests are @@ -111,7 +111,7 @@ static void update_csb(struct vas_window *window, * a window and exits without closing it. */ if (!tsk) { - pid = window->tgid; + pid = window->task.tgid; tsk = get_pid_task(pid, PIDTYPE_PID); /* * Parent thread (tgid) will be closing window when it @@ -127,7 +127,7 @@ static void update_csb(struct vas_window *window, return; } - kthread_use_mm(window->mm); + kthread_use_mm(window->task.mm); rc = copy_to_user(csb_addr, &csb, sizeof(csb)); /* * User space polls on csb.flags (first byte). So add barrier @@ -139,7 +139,7 @@ static void update_csb(struct vas_window *window, smp_mb(); rc = copy_to_user(csb_addr, &csb, sizeof(u8)); } - kthread_unuse_mm(window->mm); + kthread_unuse_mm(window->task.mm); put_task_struct(tsk); /* Success */ diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c index b973dd574b47..58e3d16c316f 100644 --- a/arch/powerpc/platforms/powernv/vas-window.c +++ b/arch/powerpc/platforms/powernv/vas-window.c @@ -1066,51 +1066,9 @@ struct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop, rc = -ENODEV; goto free_window; } - - /* - * Window opened by a child thread may not be closed when - * it exits. So take reference to its pid and release it - * when the window is free by parent thread. - * Acquire a reference to the task's pid to make sure - * pid will not be re-used - needed only for multithread - * applications. - */ - txwin->pid = get_task_pid(current, PIDTYPE_PID); - /* - * Acquire a reference to the task's mm. - */ - txwin->mm = get_task_mm(current); - - if (!txwin->mm) { - put_pid(txwin->pid); - pr_err("VAS: pid(%d): mm_struct is not found\n", - current->pid); - rc = -EPERM; + rc = vas_reference_task(&txwin->task); + if (rc) goto free_window; - } - - mmgrab(txwin->mm); - mmput(txwin->mm); - mm_context_add_vas_window(txwin->mm); - /* - * Process closes window during exit. In the case of - * multithread application, the child thread can open - * window and can exit without closing it. Expects parent - * thread to use and close the window. So do not need - * to take pid reference for parent thread. - */ - txwin->tgid = find_get_pid(task_tgid_vnr(current)); - /* - * Even a process that has no foreign real address mapping can - * use an unpaired COPY instruction (to no real effect). Issue - * CP_ABORT to clear any pending COPY and prevent a covert - * channel. - * - * __switch_to() will issue CP_ABORT on future context switches - * if process / thread has any open VAS window (Use - * current->mm->context.vas_windows). - */ - asm volatile(PPC_CP_ABORT); } set_vinst_win(vinst, txwin); @@ -1340,14 +1298,9 @@ int vas_win_close(struct vas_window *window) /* if send window, drop reference to matching receive window */ if (window->tx_win) { - if (window->user_win) { - /* Drop references to pid and mm */ - put_pid(window->pid); - if (window->mm) { - mm_context_remove_vas_window(window->mm); - mmdrop(window->mm); - } - } + if (window->user_win) + vas_drop_reference_task(&window->task); + put_rx_win(window->rxwin); } diff --git a/arch/powerpc/platforms/powernv/vas.h b/arch/powerpc/platforms/powernv/vas.h index c7db3190baca..f7aa2d04cd16 100644 --- a/arch/powerpc/platforms/powernv/vas.h +++ b/arch/powerpc/platforms/powernv/vas.h @@ -357,11 +357,9 @@ struct vas_window { bool user_win; /* True if user space window */ void *hvwc_map; /* HV window context */ void *uwc_map; /* OS/User window context */ - struct pid *pid; /* Linux process id of owner */ - struct pid *tgid; /* Thread group ID of owner */ - struct mm_struct *mm; /* Linux process mm_struct */ int wcreds_max; /* Window credits */ + struct vas_win_task task; char *dbgname; struct dentry *dbgdir; @@ -443,7 +441,7 @@ extern void vas_win_paste_addr(struct vas_window *window, u64 *addr, static inline int vas_window_pid(struct vas_window *window) { - return pid_vnr(window->pid); + return pid_vnr(window->task.pid); } static inline void vas_log_write(struct vas_window *win, char *name, From patchwork Sun Apr 11 00:33:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195979 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78E90C433B4 for ; Sun, 11 Apr 2021 00:33:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3EBDA610E5 for ; Sun, 11 Apr 2021 00:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234680AbhDKAdr (ORCPT ); Sat, 10 Apr 2021 20:33:47 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:27446 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKAdq (ORCPT ); Sat, 10 Apr 2021 20:33:46 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B03Xsw186724; Sat, 10 Apr 2021 20:33:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=p2N+4kpPtuWHVrFNu7CaSKJXWbClxDg5MDuTEFWU3d4=; b=QnADyfn2PgbkLld0vOQK94C+myIhzzHBwIkZZWV2+mFXNxUWCRURH3iSX+DggKwnKrHl jebz1oO7jCyZgW7JUrFImfQdj+x1G0sWdxOe8lnbVSldr8zTGkt5gc4da5agUxFTYdd7 kg70cyeIp8Ua64qTJGZUxrNo+8CPPO/GIXBSDpcICDTswMZrLt0u7hGVjQCkNC7Uks09 nYlnxgIQfDyxSkVIMu+ouppgTgrBeDtaYANJsiqOhu7WwOspjWD75Nr505p7VAbbidbn HbE6eZmIt/e91bV5px2+udUSOmDjwwcrlz3U5kcFwDcDmAst2b8fdnaxa3LcV31U1JdK IQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u7aqn0vn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:33:24 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0PK5b048617; Sat, 10 Apr 2021 20:33:24 -0400 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u7aqn0vj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:33:24 -0400 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0S0Bm026195; Sun, 11 Apr 2021 00:33:23 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma02dal.us.ibm.com with ESMTP id 37u3n8xc78-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:33:23 +0000 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0XLU711141432 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:33:21 GMT Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AEADC6A047; Sun, 11 Apr 2021 00:33:21 +0000 (GMT) Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 59A896A054; Sun, 11 Apr 2021 00:33:20 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:33:20 +0000 (GMT) Message-ID: <55224130b10375fc8fd0a467eae5a6098205e10a.camel@linux.ibm.com> Subject: [PATCH 04/16] powerpc/vas: Move update_csb/dump_crb to platform independent From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@linux.ibm.com Date: Sat, 10 Apr 2021 17:33:18 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: KxurP0Bdx3XP8zkSZuQMGg4cKnLTZ1yC X-Proofpoint-ORIG-GUID: dwoa7gYFh0R7dQ7zTVOgQsRyroXq_LDx X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 clxscore=1015 impostorscore=0 mlxscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104100182 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org NX issues an interrupt when sees fault on user space buffer. The kernel processes the fault by updating CSB. This functionality is same for both powerNV and pseries. So this patch moves these functions to vas-api.c and the actual functionality is not changed. Signed-off-by: Haren Myneni --- arch/powerpc/include/asm/vas.h | 3 + arch/powerpc/kernel/vas-api.c | 146 ++++++++++++++++++- arch/powerpc/platforms/powernv/vas-fault.c | 155 ++------------------- 3 files changed, 157 insertions(+), 147 deletions(-) diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h index 2daaa1a2a9a9..66bf8fb1a1be 100644 --- a/arch/powerpc/include/asm/vas.h +++ b/arch/powerpc/include/asm/vas.h @@ -210,4 +210,7 @@ int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, void vas_unregister_coproc_api(void); int vas_reference_task(struct vas_win_task *vtask); +void vas_update_csb(struct coprocessor_request_block *crb, + struct vas_win_task *vtask); +void vas_dump_crb(struct coprocessor_request_block *crb); #endif /* __ASM_POWERPC_VAS_H */ diff --git a/arch/powerpc/kernel/vas-api.c b/arch/powerpc/kernel/vas-api.c index d98caa734154..dc131b2e4acd 100644 --- a/arch/powerpc/kernel/vas-api.c +++ b/arch/powerpc/kernel/vas-api.c @@ -111,6 +111,150 @@ int vas_reference_task(struct vas_win_task *vtask) return 0; } +/* + * Update the CSB to indicate a translation error. + * + * User space will be polling on CSB after the request is issued. + * If NX can handle the request without any issues, it updates CSB. + * Whereas if NX encounters page fault, the kernel will handle the + * fault and update CSB with translation error. + * + * If we are unable to update the CSB means copy_to_user failed due to + * invalid csb_addr, send a signal to the process. + */ +void vas_update_csb(struct coprocessor_request_block *crb, + struct vas_win_task *vtask) +{ + struct coprocessor_status_block csb; + struct kernel_siginfo info; + struct task_struct *tsk; + void __user *csb_addr; + struct pid *pid; + int rc; + + /* + * NX user space windows can not be opened for task->mm=NULL + * and faults will not be generated for kernel requests. + */ + if (WARN_ON_ONCE(!vtask->mm)) + return; + + csb_addr = (void __user *)be64_to_cpu(crb->csb_addr); + + memset(&csb, 0, sizeof(csb)); + csb.cc = CSB_CC_FAULT_ADDRESS; + csb.ce = CSB_CE_TERMINATION; + csb.cs = 0; + csb.count = 0; + + /* + * NX operates and returns in BE format as defined CRB struct. + * So saves fault_storage_addr in BE as NX pastes in FIFO and + * expects user space to convert to CPU format. + */ + csb.address = crb->stamp.nx.fault_storage_addr; + csb.flags = 0; + + pid = vtask->pid; + tsk = get_pid_task(pid, PIDTYPE_PID); + /* + * Process closes send window after all pending NX requests are + * completed. In multi-thread applications, a child thread can + * open a window and can exit without closing it. May be some + * requests are pending or this window can be used by other + * threads later. We should handle faults if NX encounters + * pages faults on these requests. Update CSB with translation + * error and fault address. If csb_addr passed by user space is + * invalid, send SEGV signal to pid saved in window. If the + * child thread is not running, send the signal to tgid. + * Parent thread (tgid) will close this window upon its exit. + * + * pid and mm references are taken when window is opened by + * process (pid). So tgid is used only when child thread opens + * a window and exits without closing it. + */ + if (!tsk) { + pid = vtask->tgid; + tsk = get_pid_task(pid, PIDTYPE_PID); + /* + * Parent thread (tgid) will be closing window when it + * exits. So should not get here. + */ + if (WARN_ON_ONCE(!tsk)) + return; + } + + /* Return if the task is exiting. */ + if (tsk->flags & PF_EXITING) { + put_task_struct(tsk); + return; + } + + kthread_use_mm(vtask->mm); + rc = copy_to_user(csb_addr, &csb, sizeof(csb)); + /* + * User space polls on csb.flags (first byte). So add barrier + * then copy first byte with csb flags update. + */ + if (!rc) { + csb.flags = CSB_V; + /* Make sure update to csb.flags is visible now */ + smp_mb(); + rc = copy_to_user(csb_addr, &csb, sizeof(u8)); + } + kthread_unuse_mm(vtask->mm); + put_task_struct(tsk); + + /* Success */ + if (!rc) + return; + + + pr_debug("Invalid CSB address 0x%p signalling pid(%d)\n", + csb_addr, pid_vnr(pid)); + + clear_siginfo(&info); + info.si_signo = SIGSEGV; + info.si_errno = EFAULT; + info.si_code = SEGV_MAPERR; + info.si_addr = csb_addr; + /* + * process will be polling on csb.flags after request is sent to + * NX. So generally CSB update should not fail except when an + * application passes invalid csb_addr. So an error message will + * be displayed and leave it to user space whether to ignore or + * handle this signal. + */ + rcu_read_lock(); + rc = kill_pid_info(SIGSEGV, &info, pid); + rcu_read_unlock(); + + pr_devel("%s(): pid %d kill_proc_info() rc %d\n", __func__, + pid_vnr(pid), rc); +} + +void vas_dump_crb(struct coprocessor_request_block *crb) +{ + struct data_descriptor_entry *dde; + struct nx_fault_stamp *nx; + + dde = &crb->source; + pr_devel("SrcDDE: addr 0x%llx, len %d, count %d, idx %d, flags %d\n", + be64_to_cpu(dde->address), be32_to_cpu(dde->length), + dde->count, dde->index, dde->flags); + + dde = &crb->target; + pr_devel("TgtDDE: addr 0x%llx, len %d, count %d, idx %d, flags %d\n", + be64_to_cpu(dde->address), be32_to_cpu(dde->length), + dde->count, dde->index, dde->flags); + + nx = &crb->stamp.nx; + pr_devel("NX Stamp: PSWID 0x%x, FSA 0x%llx, flags 0x%x, FS 0x%x\n", + be32_to_cpu(nx->pswid), + be64_to_cpu(crb->stamp.nx.fault_storage_addr), + nx->flags, nx->fault_status); +} + static int coproc_open(struct inode *inode, struct file *fp) { struct coproc_instance *cp_inst; @@ -272,7 +416,7 @@ static struct file_operations coproc_fops = { * extended to other coprocessor types later. */ int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type, - const char *name, struct vas_user_win_ops *vops) + const char *name, struct vas_user_win_ops *vops) { int rc = -EINVAL; dev_t devno; diff --git a/arch/powerpc/platforms/powernv/vas-fault.c b/arch/powerpc/platforms/powernv/vas-fault.c index a4835cb82c09..2e898eac1bb2 100644 --- a/arch/powerpc/platforms/powernv/vas-fault.c +++ b/arch/powerpc/platforms/powernv/vas-fault.c @@ -26,150 +26,6 @@ */ #define VAS_FAULT_WIN_FIFO_SIZE (4 << 20) -static void dump_crb(struct coprocessor_request_block *crb) -{ - struct data_descriptor_entry *dde; - struct nx_fault_stamp *nx; - - dde = &crb->source; - pr_devel("SrcDDE: addr 0x%llx, len %d, count %d, idx %d, flags %d\n", - be64_to_cpu(dde->address), be32_to_cpu(dde->length), - dde->count, dde->index, dde->flags); - - dde = &crb->target; - pr_devel("TgtDDE: addr 0x%llx, len %d, count %d, idx %d, flags %d\n", - be64_to_cpu(dde->address), be32_to_cpu(dde->length), - dde->count, dde->index, dde->flags); - - nx = &crb->stamp.nx; - pr_devel("NX Stamp: PSWID 0x%x, FSA 0x%llx, flags 0x%x, FS 0x%x\n", - be32_to_cpu(nx->pswid), - be64_to_cpu(crb->stamp.nx.fault_storage_addr), - nx->flags, nx->fault_status); -} - -/* - * Update the CSB to indicate a translation error. - * - * User space will be polling on CSB after the request is issued. - * If NX can handle the request without any issues, it updates CSB. - * Whereas if NX encounters page fault, the kernel will handle the - * fault and update CSB with translation error. - * - * If we are unable to update the CSB means copy_to_user failed due to - * invalid csb_addr, send a signal to the process. - */ -static void update_csb(struct vas_window *window, - struct coprocessor_request_block *crb) -{ - struct coprocessor_status_block csb; - struct kernel_siginfo info; - struct task_struct *tsk; - void __user *csb_addr; - struct pid *pid; - int rc; - - /* - * NX user space windows can not be opened for task->mm=NULL - * and faults will not be generated for kernel requests. - */ - if (WARN_ON_ONCE(!window->task.mm || !window->user_win)) - return; - - csb_addr = (void __user *)be64_to_cpu(crb->csb_addr); - - memset(&csb, 0, sizeof(csb)); - csb.cc = CSB_CC_FAULT_ADDRESS; - csb.ce = CSB_CE_TERMINATION; - csb.cs = 0; - csb.count = 0; - - /* - * NX operates and returns in BE format as defined CRB struct. - * So saves fault_storage_addr in BE as NX pastes in FIFO and - * expects user space to convert to CPU format. - */ - csb.address = crb->stamp.nx.fault_storage_addr; - csb.flags = 0; - - pid = window->task.pid; - tsk = get_pid_task(pid, PIDTYPE_PID); - /* - * Process closes send window after all pending NX requests are - * completed. In multi-thread applications, a child thread can - * open a window and can exit without closing it. May be some - * requests are pending or this window can be used by other - * threads later. We should handle faults if NX encounters - * pages faults on these requests. Update CSB with translation - * error and fault address. If csb_addr passed by user space is - * invalid, send SEGV signal to pid saved in window. If the - * child thread is not running, send the signal to tgid. - * Parent thread (tgid) will close this window upon its exit. - * - * pid and mm references are taken when window is opened by - * process (pid). So tgid is used only when child thread opens - * a window and exits without closing it. - */ - if (!tsk) { - pid = window->task.tgid; - tsk = get_pid_task(pid, PIDTYPE_PID); - /* - * Parent thread (tgid) will be closing window when it - * exits. So should not get here. - */ - if (WARN_ON_ONCE(!tsk)) - return; - } - - /* Return if the task is exiting. */ - if (tsk->flags & PF_EXITING) { - put_task_struct(tsk); - return; - } - - kthread_use_mm(window->task.mm); - rc = copy_to_user(csb_addr, &csb, sizeof(csb)); - /* - * User space polls on csb.flags (first byte). So add barrier - * then copy first byte with csb flags update. - */ - if (!rc) { - csb.flags = CSB_V; - /* Make sure update to csb.flags is visible now */ - smp_mb(); - rc = copy_to_user(csb_addr, &csb, sizeof(u8)); - } - kthread_unuse_mm(window->task.mm); - put_task_struct(tsk); - - /* Success */ - if (!rc) - return; - - pr_debug("Invalid CSB address 0x%p signalling pid(%d)\n", - csb_addr, pid_vnr(pid)); - - clear_siginfo(&info); - info.si_signo = SIGSEGV; - info.si_errno = EFAULT; - info.si_code = SEGV_MAPERR; - info.si_addr = csb_addr; - - /* - * process will be polling on csb.flags after request is sent to - * NX. So generally CSB update should not fail except when an - * application passes invalid csb_addr. So an error message will - * be displayed and leave it to user space whether to ignore or - * handle this signal. - */ - rcu_read_lock(); - rc = kill_pid_info(SIGSEGV, &info, pid); - rcu_read_unlock(); - - pr_devel("%s(): pid %d kill_proc_info() rc %d\n", __func__, - pid_vnr(pid), rc); -} - static void dump_fifo(struct vas_instance *vinst, void *entry) { unsigned long *end = vinst->fault_fifo + vinst->fault_fifo_size; @@ -272,7 +128,7 @@ irqreturn_t vas_fault_thread_fn(int irq, void *data) vinst->vas_id, vinst->fault_fifo, fifo, vinst->fault_crbs); - dump_crb(crb); + vas_dump_crb(crb); window = vas_pswid_to_window(vinst, be32_to_cpu(crb->stamp.nx.pswid)); @@ -293,7 +149,14 @@ irqreturn_t vas_fault_thread_fn(int irq, void *data) WARN_ON_ONCE(1); } else { - update_csb(window, crb); + /* + * NX sees faults only with user space windows. + */ + if (window->user_win) + vas_update_csb(crb, &window->task); + else + WARN_ON_ONCE(!window->user_win); + /* * Return credit for send window after processing * fault CRB. From patchwork Sun Apr 11 00:34:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195981 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16AB5C433B4 for ; Sun, 11 Apr 2021 00:34:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7CF1610D1 for ; Sun, 11 Apr 2021 00:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234708AbhDKAej (ORCPT ); Sat, 10 Apr 2021 20:34:39 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:32764 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKAei (ORCPT ); Sat, 10 Apr 2021 20:34:38 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0Y5UF059571; Sat, 10 Apr 2021 20:34:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=mw6EMzbdpMpg25BHJTf5cjqRD7VjavNBwfG7Zi21oiQ=; b=hw2YgpwbRN7F29efNvN1OBMnlBk8C7IWYKEatun+dcYCNlGCjtdlKPtBxPFxAz+QpfRq Fldk2GQ5gb0uMXKAFLMsGCoj/PUcLBYlJ6q/WCm9SniSlBKlQwo59sUpcDE5dnlyO3P4 e08buR/SB4VK9k3e85B4AANX0KipADQ1cd/FFO/5Ape4C4OBPVfU7wA+3yCKv8Jb8StM BcdggLXCS8PiUEBkppnT+UTG04Tr4Rm/jtfThYiMsVu9GaG5XFWuONCriK8aY//8bog7 fxtB7z7l50DhvH/APnuowuqg2Xc6f08olGjGhfduwguvj7bRoi5KR6F4SbMVhW/BMhwj hg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u80qm3s0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:34:15 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0YFFN059841; Sat, 10 Apr 2021 20:34:15 -0400 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u80qm3rt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:34:15 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0RnDM002682; Sun, 11 Apr 2021 00:34:14 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma03wdc.us.ibm.com with ESMTP id 37uhcm1d9y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:34:14 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0YE1h33096118 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:34:14 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46490AE05F; Sun, 11 Apr 2021 00:34:14 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 253A9AE063; Sun, 11 Apr 2021 00:34:13 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:34:12 +0000 (GMT) Message-ID: <762c1bc902cb5b2c356830a5815c0914e1d5e185.camel@linux.ibm.com> Subject: [PATCH 05/16] powerpc/vas: Define and use common vas_window struct From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@linux.ibm.com Date: Sat, 10 Apr 2021 17:34:11 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: -jIyka_Hy_x1g6s46pV0C6DzeYqKdJjJ X-Proofpoint-GUID: 7igguruoG1tVeebw7DwQN1tBfyC2OZBb X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 malwarescore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Same vas_window struct is used on powerNV and pseries. So this patch changes in struct vas_window to support both platforms and also the corresponding modifications in powerNV vas code. On powerNV vas_window is used for both TX and RX windows, whereas only for TX windows on powerVM. So some elements are specific to these platforms. Signed-off-by: Haren Myneni --- arch/powerpc/include/asm/vas.h | 48 ++++++++ arch/powerpc/platforms/powernv/vas-debug.c | 12 +- arch/powerpc/platforms/powernv/vas-fault.c | 4 +- arch/powerpc/platforms/powernv/vas-trace.h | 6 +- arch/powerpc/platforms/powernv/vas-window.c | 129 +++++++++++--------- arch/powerpc/platforms/powernv/vas.h | 38 +----- 6 files changed, 135 insertions(+), 102 deletions(-) diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h index 66bf8fb1a1be..f928bf4c7e98 100644 --- a/arch/powerpc/include/asm/vas.h +++ b/arch/powerpc/include/asm/vas.h @@ -69,6 +69,54 @@ struct vas_win_task { struct mm_struct *mm; /* Linux process mm_struct */ }; +/* + * In-kernel state a VAS window. One per window. + * powerVM: Used only for Tx windows. + * powerNV: Used for both Tx and Rx windows. + */ +struct vas_window { + u32 winid; + u32 wcreds_max; /* Window credits */ + enum vas_cop_type cop; + struct vas_win_task task; + char *dbgname; + struct dentry *dbgdir; + union { + /* powerNV specific data */ + struct { + void *vinst; /* points to VAS instance */ + bool tx_win; /* True if send window */ + bool nx_win; /* True if NX window */ + bool user_win; /* True if user space window */ + void *hvwc_map; /* HV window context */ + void *uwc_map; /* OS/User window context */ + + /* Fields applicable only to send windows */ + void *paste_kaddr; + char *paste_addr_name; + struct vas_window *rxwin; + + atomic_t num_txwins; /* Only for receive windows */ + } pnv; + struct { + u64 win_addr; /* Physical paste address */ + u8 win_type; /* QoS or Default window */ + u8 status; + u32 complete_irq; /* Completion interrupt */ + u32 fault_irq; /* Fault interrupt */ + u64 domain[6]; /* Associativity domain Ids */ + /* this window is allocated */ + u64 util; + + /* List of windows opened which is used for LPM */ + struct list_head win_list; + u64 flags; + char *name; + int fault_virq; + } lpar; + }; +}; + static inline void vas_drop_reference_task(struct vas_win_task *task) { /* Drop references to pid and mm */ diff --git a/arch/powerpc/platforms/powernv/vas-debug.c b/arch/powerpc/platforms/powernv/vas-debug.c index 41fa90d2f4ab..80f735449ab8 100644 --- a/arch/powerpc/platforms/powernv/vas-debug.c +++ b/arch/powerpc/platforms/powernv/vas-debug.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "vas.h" static struct dentry *vas_debugfs; @@ -33,11 +34,11 @@ static int info_show(struct seq_file *s, void *private) mutex_lock(&vas_mutex); /* ensure window is not unmapped */ - if (!window->hvwc_map) + if (!window->pnv.hvwc_map) goto unlock; seq_printf(s, "Type: %s, %s\n", cop_to_str(window->cop), - window->tx_win ? "Send" : "Receive"); + window->pnv.tx_win ? "Send" : "Receive"); seq_printf(s, "Pid : %d\n", vas_window_pid(window)); unlock: @@ -60,7 +61,7 @@ static int hvwc_show(struct seq_file *s, void *private) mutex_lock(&vas_mutex); /* ensure window is not unmapped */ - if (!window->hvwc_map) + if (!window->pnv.hvwc_map) goto unlock; print_reg(s, window, VREG(LPID)); @@ -115,9 +116,10 @@ void vas_window_free_dbgdir(struct vas_window *window) void vas_window_init_dbgdir(struct vas_window *window) { + struct vas_instance *vinst = window->pnv.vinst; struct dentry *d; - if (!window->vinst->dbgdir) + if (!vinst->dbgdir) return; window->dbgname = kzalloc(16, GFP_KERNEL); @@ -126,7 +128,7 @@ void vas_window_init_dbgdir(struct vas_window *window) snprintf(window->dbgname, 16, "w%d", window->winid); - d = debugfs_create_dir(window->dbgname, window->vinst->dbgdir); + d = debugfs_create_dir(window->dbgname, vinst->dbgdir); window->dbgdir = d; debugfs_create_file("info", 0444, d, window, &info_fops); diff --git a/arch/powerpc/platforms/powernv/vas-fault.c b/arch/powerpc/platforms/powernv/vas-fault.c index 2e898eac1bb2..82acede2d892 100644 --- a/arch/powerpc/platforms/powernv/vas-fault.c +++ b/arch/powerpc/platforms/powernv/vas-fault.c @@ -152,10 +152,10 @@ irqreturn_t vas_fault_thread_fn(int irq, void *data) /* * NX sees faults only with user space windows. */ - if (window->user_win) + if (window->pnv.user_win) vas_update_csb(crb, &window->task); else - WARN_ON_ONCE(!window->user_win); + WARN_ON_ONCE(!window->pnv.user_win); /* * Return credit for send window after processing diff --git a/arch/powerpc/platforms/powernv/vas-trace.h b/arch/powerpc/platforms/powernv/vas-trace.h index a449b9f0c12e..843aae37c07a 100644 --- a/arch/powerpc/platforms/powernv/vas-trace.h +++ b/arch/powerpc/platforms/powernv/vas-trace.h @@ -95,9 +95,11 @@ TRACE_EVENT( vas_paste_crb, TP_fast_assign( __entry->pid = tsk->pid; - __entry->vasid = win->vinst->vas_id; + __entry->vasid = + ((struct vas_instance *)win->pnv.vinst)->vas_id; __entry->winid = win->winid; - __entry->paste_kaddr = (unsigned long)win->paste_kaddr + __entry->paste_kaddr = + (unsigned long)win->pnv.paste_kaddr; ), TP_printk("pid=%d, vasid=%d, winid=%d, paste_kaddr=0x%016lx\n", diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c index 58e3d16c316f..254be61c73ab 100644 --- a/arch/powerpc/platforms/powernv/vas-window.c +++ b/arch/powerpc/platforms/powernv/vas-window.c @@ -32,9 +32,10 @@ void vas_win_paste_addr(struct vas_window *window, u64 *addr, int *len) { int winid; u64 base, shift; + struct vas_instance *vinst = window->pnv.vinst; - base = window->vinst->paste_base_addr; - shift = window->vinst->paste_win_id_shift; + base = vinst->paste_base_addr; + shift = vinst->paste_win_id_shift; winid = window->winid; *addr = base + (winid << shift); @@ -47,9 +48,10 @@ void vas_win_paste_addr(struct vas_window *window, u64 *addr, int *len) static inline void get_hvwc_mmio_bar(struct vas_window *window, u64 *start, int *len) { + struct vas_instance *vinst = window->pnv.vinst; u64 pbaddr; - pbaddr = window->vinst->hvwc_bar_start; + pbaddr = vinst->hvwc_bar_start; *start = pbaddr + window->winid * VAS_HVWC_SIZE; *len = VAS_HVWC_SIZE; } @@ -57,9 +59,10 @@ static inline void get_hvwc_mmio_bar(struct vas_window *window, static inline void get_uwc_mmio_bar(struct vas_window *window, u64 *start, int *len) { + struct vas_instance *vinst = window->pnv.vinst; u64 pbaddr; - pbaddr = window->vinst->uwc_bar_start; + pbaddr = vinst->uwc_bar_start; *start = pbaddr + window->winid * VAS_UWC_SIZE; *len = VAS_UWC_SIZE; } @@ -75,13 +78,14 @@ static void *map_paste_region(struct vas_window *txwin) void *map; char *name; u64 start; + struct vas_instance *vinst = txwin->pnv.vinst; - name = kasprintf(GFP_KERNEL, "window-v%d-w%d", txwin->vinst->vas_id, + name = kasprintf(GFP_KERNEL, "window-v%d-w%d", vinst->vas_id, txwin->winid); if (!name) goto free_name; - txwin->paste_addr_name = name; + txwin->pnv.paste_addr_name = name; vas_win_paste_addr(txwin, &start, &len); if (!request_mem_region(start, len, name)) { @@ -139,12 +143,12 @@ static void unmap_paste_region(struct vas_window *window) int len; u64 busaddr_start; - if (window->paste_kaddr) { + if (window->pnv.paste_kaddr) { vas_win_paste_addr(window, &busaddr_start, &len); - unmap_region(window->paste_kaddr, busaddr_start, len); - window->paste_kaddr = NULL; - kfree(window->paste_addr_name); - window->paste_addr_name = NULL; + unmap_region(window->pnv.paste_kaddr, busaddr_start, len); + window->pnv.paste_kaddr = NULL; + kfree(window->pnv.paste_addr_name); + window->pnv.paste_addr_name = NULL; } } @@ -164,11 +168,11 @@ static void unmap_winctx_mmio_bars(struct vas_window *window) mutex_lock(&vas_mutex); - hvwc_map = window->hvwc_map; - window->hvwc_map = NULL; + hvwc_map = window->pnv.hvwc_map; + window->pnv.hvwc_map = NULL; - uwc_map = window->uwc_map; - window->uwc_map = NULL; + uwc_map = window->pnv.uwc_map; + window->pnv.uwc_map = NULL; mutex_unlock(&vas_mutex); @@ -194,12 +198,12 @@ static int map_winctx_mmio_bars(struct vas_window *window) u64 start; get_hvwc_mmio_bar(window, &start, &len); - window->hvwc_map = map_mmio_region("HVWCM_Window", start, len); + window->pnv.hvwc_map = map_mmio_region("HVWCM_Window", start, len); get_uwc_mmio_bar(window, &start, &len); - window->uwc_map = map_mmio_region("UWCM_Window", start, len); + window->pnv.uwc_map = map_mmio_region("UWCM_Window", start, len); - if (!window->hvwc_map || !window->uwc_map) { + if (!window->pnv.hvwc_map || !window->pnv.uwc_map) { unmap_winctx_mmio_bars(window); return -1; } @@ -524,7 +528,7 @@ static int vas_assign_window_id(struct ida *ida) static void vas_window_free(struct vas_window *window) { int winid = window->winid; - struct vas_instance *vinst = window->vinst; + struct vas_instance *vinst = window->pnv.vinst; unmap_winctx_mmio_bars(window); @@ -548,7 +552,7 @@ static struct vas_window *vas_window_alloc(struct vas_instance *vinst) if (!window) goto out_free; - window->vinst = vinst; + window->pnv.vinst = vinst; window->winid = winid; if (map_winctx_mmio_bars(window)) @@ -567,9 +571,9 @@ static struct vas_window *vas_window_alloc(struct vas_instance *vinst) static void put_rx_win(struct vas_window *rxwin) { /* Better not be a send window! */ - WARN_ON_ONCE(rxwin->tx_win); + WARN_ON_ONCE(rxwin->pnv.tx_win); - atomic_dec(&rxwin->num_txwins); + atomic_dec(&rxwin->pnv.num_txwins); } /* @@ -592,7 +596,7 @@ static struct vas_window *get_user_rxwin(struct vas_instance *vinst, u32 pswid) rxwin = vinst->windows[winid]; - if (!rxwin || rxwin->tx_win || rxwin->cop != VAS_COP_TYPE_FTW) + if (!rxwin || rxwin->pnv.tx_win || rxwin->cop != VAS_COP_TYPE_FTW) return ERR_PTR(-EINVAL); return rxwin; @@ -617,7 +621,7 @@ static struct vas_window *get_vinst_rxwin(struct vas_instance *vinst, rxwin = vinst->rxwin[cop] ?: ERR_PTR(-EINVAL); if (!IS_ERR(rxwin)) - atomic_inc(&rxwin->num_txwins); + atomic_inc(&rxwin->pnv.num_txwins); mutex_unlock(&vinst->mutex); @@ -650,7 +654,7 @@ static void set_vinst_win(struct vas_instance *vinst, * There should only be one receive window for a coprocessor type * unless its a user (FTW) window. */ - if (!window->user_win && !window->tx_win) { + if (!window->pnv.user_win && !window->pnv.tx_win) { WARN_ON_ONCE(vinst->rxwin[window->cop]); vinst->rxwin[window->cop] = window; } @@ -668,11 +672,11 @@ static void set_vinst_win(struct vas_instance *vinst, static void clear_vinst_win(struct vas_window *window) { int id = window->winid; - struct vas_instance *vinst = window->vinst; + struct vas_instance *vinst = window->pnv.vinst; mutex_lock(&vinst->mutex); - if (!window->user_win && !window->tx_win) { + if (!window->pnv.user_win && !window->pnv.tx_win) { WARN_ON_ONCE(!vinst->rxwin[window->cop]); vinst->rxwin[window->cop] = NULL; } @@ -687,6 +691,8 @@ static void init_winctx_for_rxwin(struct vas_window *rxwin, struct vas_rx_win_attr *rxattr, struct vas_winctx *winctx) { + struct vas_instance *vinst; + /* * We first zero (memset()) all fields and only set non-zero fields. * Following fields are 0/false but maybe deserve a comment: @@ -751,8 +757,9 @@ static void init_winctx_for_rxwin(struct vas_window *rxwin, winctx->min_scope = VAS_SCOPE_LOCAL; winctx->max_scope = VAS_SCOPE_VECTORED_GROUP; - if (rxwin->vinst->virq) - winctx->irq_port = rxwin->vinst->irq_port; + vinst = rxwin->pnv.vinst; + if (vinst->virq) + winctx->irq_port = vinst->irq_port; } static bool rx_win_args_valid(enum vas_cop_type cop, @@ -875,9 +882,9 @@ struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop, return rxwin; } - rxwin->tx_win = false; - rxwin->nx_win = rxattr->nx_win; - rxwin->user_win = rxattr->user_win; + rxwin->pnv.tx_win = false; + rxwin->pnv.nx_win = rxattr->nx_win; + rxwin->pnv.user_win = rxattr->user_win; rxwin->cop = cop; rxwin->wcreds_max = rxattr->wcreds_max; @@ -911,6 +918,8 @@ static void init_winctx_for_txwin(struct vas_window *txwin, struct vas_tx_win_attr *txattr, struct vas_winctx *winctx) { + struct vas_instance *vinst = txwin->pnv.vinst; + /* * We first zero all fields and only set non-zero ones. Following * are some fields set to 0/false for the stated reason: @@ -931,7 +940,7 @@ static void init_winctx_for_txwin(struct vas_window *txwin, winctx->wcreds_max = txwin->wcreds_max; winctx->user_win = txattr->user_win; - winctx->nx_win = txwin->rxwin->nx_win; + winctx->nx_win = txwin->pnv.rxwin->pnv.nx_win; winctx->pin_win = txattr->pin_win; winctx->rej_no_credit = txattr->rej_no_credit; winctx->rsvd_txbuf_enable = txattr->rsvd_txbuf_enable; @@ -948,23 +957,23 @@ static void init_winctx_for_txwin(struct vas_window *txwin, winctx->lpid = txattr->lpid; winctx->pidr = txattr->pidr; - winctx->rx_win_id = txwin->rxwin->winid; + winctx->rx_win_id = txwin->pnv.rxwin->winid; /* * IRQ and fault window setup is successful. Set fault window * for the send window so that ready to handle faults. */ - if (txwin->vinst->virq) - winctx->fault_win_id = txwin->vinst->fault_win->winid; + if (vinst->virq) + winctx->fault_win_id = vinst->fault_win->winid; winctx->dma_type = VAS_DMA_TYPE_INJECT; winctx->tc_mode = txattr->tc_mode; winctx->min_scope = VAS_SCOPE_LOCAL; winctx->max_scope = VAS_SCOPE_VECTORED_GROUP; - if (txwin->vinst->virq) - winctx->irq_port = txwin->vinst->irq_port; + if (vinst->virq) + winctx->irq_port = vinst->irq_port; winctx->pswid = txattr->pswid ? txattr->pswid : - encode_pswid(txwin->vinst->vas_id, txwin->winid); + encode_pswid(vinst->vas_id, txwin->winid); } static bool tx_win_args_valid(enum vas_cop_type cop, @@ -1032,10 +1041,10 @@ struct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop, } txwin->cop = cop; - txwin->tx_win = 1; - txwin->rxwin = rxwin; - txwin->nx_win = txwin->rxwin->nx_win; - txwin->user_win = attr->user_win; + txwin->pnv.tx_win = 1; + txwin->pnv.rxwin = rxwin; + txwin->pnv.nx_win = txwin->pnv.rxwin->pnv.nx_win; + txwin->pnv.user_win = attr->user_win; txwin->wcreds_max = attr->wcreds_max ?: VAS_WCREDS_DEFAULT; init_winctx_for_txwin(txwin, attr, &winctx); @@ -1050,10 +1059,10 @@ struct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop, * NOTE: If kernel ever resubmits a user CRB after handling a page * fault, we will need to map this into kernel as well. */ - if (!txwin->user_win) { - txwin->paste_kaddr = map_paste_region(txwin); - if (IS_ERR(txwin->paste_kaddr)) { - rc = PTR_ERR(txwin->paste_kaddr); + if (!txwin->pnv.user_win) { + txwin->pnv.paste_kaddr = map_paste_region(txwin); + if (IS_ERR(txwin->pnv.paste_kaddr)) { + rc = PTR_ERR(txwin->pnv.paste_kaddr); goto free_window; } } else { @@ -1105,9 +1114,9 @@ int vas_paste_crb(struct vas_window *txwin, int offset, bool re) * report-enable flag is set for NX windows. Ensure software * complies too. */ - WARN_ON_ONCE(txwin->nx_win && !re); + WARN_ON_ONCE(txwin->pnv.nx_win && !re); - addr = txwin->paste_kaddr; + addr = txwin->pnv.paste_kaddr; if (re) { /* * Set the REPORT_ENABLE bit (equivalent to writing @@ -1154,7 +1163,7 @@ static void poll_window_credits(struct vas_window *window) int count = 0; val = read_hvwc_reg(window, VREG(WINCTL)); - if (window->tx_win) + if (window->pnv.tx_win) mode = GET_FIELD(VAS_WINCTL_TX_WCRED_MODE, val); else mode = GET_FIELD(VAS_WINCTL_RX_WCRED_MODE, val); @@ -1162,7 +1171,7 @@ static void poll_window_credits(struct vas_window *window) if (!mode) return; retry: - if (window->tx_win) { + if (window->pnv.tx_win) { val = read_hvwc_reg(window, VREG(TX_WCRED)); creds = GET_FIELD(VAS_TX_WCRED, val); } else { @@ -1278,7 +1287,7 @@ int vas_win_close(struct vas_window *window) if (!window) return 0; - if (!window->tx_win && atomic_read(&window->num_txwins) != 0) { + if (!window->pnv.tx_win && atomic_read(&window->pnv.num_txwins) != 0) { pr_devel("Attempting to close an active Rx window!\n"); WARN_ON_ONCE(1); return -EBUSY; @@ -1297,11 +1306,11 @@ int vas_win_close(struct vas_window *window) poll_window_castout(window); /* if send window, drop reference to matching receive window */ - if (window->tx_win) { - if (window->user_win) + if (window->pnv.tx_win) { + if (window->pnv.user_win) vas_drop_reference_task(&window->task); - put_rx_win(window->rxwin); + put_rx_win(window->pnv.rxwin); } vas_window_free(window); @@ -1385,12 +1394,12 @@ struct vas_window *vas_pswid_to_window(struct vas_instance *vinst, * since their CRBs are ignored (not queued on FIFO or processed * by NX). */ - if (!window->tx_win || !window->user_win || !window->nx_win || - window->cop == VAS_COP_TYPE_FAULT || - window->cop == VAS_COP_TYPE_FTW) { + if (!window->pnv.tx_win || !window->pnv.user_win || + !window->pnv.nx_win || window->cop == VAS_COP_TYPE_FAULT || + window->cop == VAS_COP_TYPE_FTW) { pr_err("PSWID decode: id %d, tx %d, user %d, nx %d, cop %d\n", - winid, window->tx_win, window->user_win, - window->nx_win, window->cop); + winid, window->pnv.tx_win, window->pnv.user_win, + window->pnv.nx_win, window->cop); WARN_ON(1); } diff --git a/arch/powerpc/platforms/powernv/vas.h b/arch/powerpc/platforms/powernv/vas.h index f7aa2d04cd16..72ccb2f692cc 100644 --- a/arch/powerpc/platforms/powernv/vas.h +++ b/arch/powerpc/platforms/powernv/vas.h @@ -345,34 +345,6 @@ struct vas_instance { struct dentry *dbgdir; }; -/* - * In-kernel state a VAS window. One per window. - */ -struct vas_window { - /* Fields common to send and receive windows */ - struct vas_instance *vinst; - int winid; - bool tx_win; /* True if send window */ - bool nx_win; /* True if NX window */ - bool user_win; /* True if user space window */ - void *hvwc_map; /* HV window context */ - void *uwc_map; /* OS/User window context */ - int wcreds_max; /* Window credits */ - - struct vas_win_task task; - char *dbgname; - struct dentry *dbgdir; - - /* Fields applicable only to send windows */ - void *paste_kaddr; - char *paste_addr_name; - struct vas_window *rxwin; - - /* Feilds applicable only to receive windows */ - enum vas_cop_type cop; - atomic_t num_txwins; -}; - /* * Container for the hardware state of a window. One per-window. * @@ -449,8 +421,8 @@ static inline void vas_log_write(struct vas_window *win, char *name, { if (val) pr_debug("%swin #%d: %s reg %p, val 0x%016llx\n", - win->tx_win ? "Tx" : "Rx", win->winid, name, - regptr, val); + win->pnv.tx_win ? "Tx" : "Rx", win->winid, + name, regptr, val); } static inline void write_uwc_reg(struct vas_window *win, char *name, @@ -458,7 +430,7 @@ static inline void write_uwc_reg(struct vas_window *win, char *name, { void *regptr; - regptr = win->uwc_map + reg; + regptr = win->pnv.uwc_map + reg; vas_log_write(win, name, regptr, val); out_be64(regptr, val); @@ -469,7 +441,7 @@ static inline void write_hvwc_reg(struct vas_window *win, char *name, { void *regptr; - regptr = win->hvwc_map + reg; + regptr = win->pnv.hvwc_map + reg; vas_log_write(win, name, regptr, val); out_be64(regptr, val); @@ -478,7 +450,7 @@ static inline void write_hvwc_reg(struct vas_window *win, char *name, static inline u64 read_hvwc_reg(struct vas_window *win, char *name __maybe_unused, s32 reg) { - return in_be64(win->hvwc_map+reg); + return in_be64(win->pnv.hvwc_map + reg); } /* From patchwork Sun Apr 11 00:35:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195983 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2431C433B4 for ; Sun, 11 Apr 2021 00:35:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71BCA610D1 for ; Sun, 11 Apr 2021 00:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234680AbhDKAfl (ORCPT ); Sat, 10 Apr 2021 20:35:41 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38926 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKAfk (ORCPT ); Sat, 10 Apr 2021 20:35:40 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0WxrZ080318; Sat, 10 Apr 2021 20:35:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=olc+eomlGw3902fdR0WGyXodUkT7w/7aW0MiC+MUNFk=; b=P2vsBq9ZgX9ke0/xcfArkPJ4jXYFDsAQHNMOLKXAhrzTyVRHm8Lxc7W3hK/87coMpNoX 3dnAk32GjmD2bHiR0AOtQeD828X0ZYdAAsVAkLpcS2QjlirQ21JEbTUxai6Fluh8iKKq zXTCrHd/gC90glwK5Dk70kJqTlhO+tahSCtlaJhrQeIuMlHs5jO8yEPp97ijHvV9cahk usTO3EFyUs12qU5xu03yKLxV8bCQnO0L/o0sFGaPMuACDQ4p725mp3d9DSQwWvs/6Vq5 sm4Lvv104Cp3UbD81UF6f8i14wm32QC0eJnLc6VS4GlHQV7SKP3VAEL8by7eAj6ASOfv xA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u7vyv9ed-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:35:17 -0400 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0YkWh083795; Sat, 10 Apr 2021 20:35:17 -0400 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u7vyv9e8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:35:17 -0400 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0RWXw021395; Sun, 11 Apr 2021 00:35:16 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma01dal.us.ibm.com with ESMTP id 37u3n8pcyh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:35:16 +0000 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0ZEuY18547188 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:35:14 GMT Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BBB626A051; Sun, 11 Apr 2021 00:35:14 +0000 (GMT) Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5ACB06A047; Sun, 11 Apr 2021 00:35:13 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:35:13 +0000 (GMT) Message-ID: <65524fd88b91a30b0ba24b79d3866f71e4d349af.camel@linux.ibm.com> Subject: [PATCH 06/16] powerpc/pseries/vas: Define VAS/NXGZIP HCALLs and structs From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@linux.ibm.com Date: Sat, 10 Apr 2021 17:35:11 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: k8uKKo1YE1IYyaNIHNTFq8DRqWkqRwxn X-Proofpoint-GUID: XbLNxBhYi7inCD4cYxoQT1u5mxkG_3hw X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 bulkscore=0 clxscore=1015 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This patch adds HCALLs and other definitions. Also define structs that are used in VAS implementation on powerVM. Signed-off-by: Haren Myneni --- arch/powerpc/include/asm/hvcall.h | 7 ++ arch/powerpc/include/asm/vas.h | 28 ++++++++ arch/powerpc/platforms/pseries/vas.h | 96 ++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 arch/powerpc/platforms/pseries/vas.h diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h index ed6086d57b22..accbb7f6f272 100644 --- a/arch/powerpc/include/asm/hvcall.h +++ b/arch/powerpc/include/asm/hvcall.h @@ -294,6 +294,13 @@ #define H_RESIZE_HPT_COMMIT 0x370 #define H_REGISTER_PROC_TBL 0x37C #define H_SIGNAL_SYS_RESET 0x380 +#define H_ALLOCATE_VAS_WINDOW 0x388 +#define H_MODIFY_VAS_WINDOW 0x38C +#define H_DEALLOCATE_VAS_WINDOW 0x390 +#define H_QUERY_VAS_WINDOW 0x394 +#define H_QUERY_VAS_CAPABILITIES 0x398 +#define H_QUERY_NX_CAPABILITIES 0x39C +#define H_GET_NX_FAULT 0x3A0 #define H_INT_GET_SOURCE_INFO 0x3A8 #define H_INT_SET_SOURCE_CONFIG 0x3AC #define H_INT_GET_SOURCE_CONFIG 0x3B0 diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h index f928bf4c7e98..d15784506a54 100644 --- a/arch/powerpc/include/asm/vas.h +++ b/arch/powerpc/include/asm/vas.h @@ -179,6 +179,7 @@ struct vas_tx_win_attr { bool rx_win_ord_mode; }; +#ifdef CONFIG_PPC_POWERNV /* * Helper to map a chip id to VAS id. * For POWER9, this is a 1:1 mapping. In the future this maybe a 1:N @@ -243,6 +244,33 @@ int vas_paste_crb(struct vas_window *win, int offset, bool re); int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type, const char *name); void vas_unregister_api_powernv(void); +#endif + +#ifdef CONFIG_PPC_PSERIES + +/* VAS Capabilities */ +#define VAS_GZIP_QOS_FEAT 0x1 +#define VAS_GZIP_DEF_FEAT 0x2 +#define VAS_GZIP_QOS_FEAT_BIT (1UL << (63 - VAS_GZIP_QOS_FEAT)) /* Bit 1 */ +#define VAS_GZIP_DEF_FEAT_BIT (1UL << (63 - VAS_GZIP_DEF_FEAT)) /* Bit 2 */ + +/* NX Capabilities */ +#define VAS_NX_GZIP_FEAT 0x1 +#define VAS_NX_GZIP_FEAT_BIT (1UL << (63 - VAS_NX_GZIP_FEAT)) /* Bit 1 */ +#define VAS_DESCR_LEN 8 + +struct vas_all_capabs_be { + __be64 descriptor; + __be64 feat_type; +} __packed __aligned(0x1000); + +struct vas_all_capabs { + char name[VAS_DESCR_LEN + 1]; + u64 descriptor; + u64 feat_type; +}; + +#endif /* * Register / unregister coprocessor type to VAS API which will be exported diff --git a/arch/powerpc/platforms/pseries/vas.h b/arch/powerpc/platforms/pseries/vas.h new file mode 100644 index 000000000000..208682fffa57 --- /dev/null +++ b/arch/powerpc/platforms/pseries/vas.h @@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright 2020-21 IBM Corp. + */ + +#ifndef _VAS_H +#define _VAS_H +#include +#include +#include + +/* + * VAS window modify flags + */ +#define VAS_MOD_WIN_CLOSE (1UL << 63) +#define VAS_MOD_WIN_JOBS_KILL (1UL << (63 - 1)) +#define VAS_MOD_WIN_DR (1UL << (63 - 3)) +#define VAS_MOD_WIN_PR (1UL << (63 - 4)) +#define VAS_MOD_WIN_SF (1UL << (63 - 5)) +#define VAS_MOD_WIN_TA (1UL << (63 - 6)) +#define VAS_MOD_WIN_FLAGS (VAS_MOD_WIN_JOBS_KILL | VAS_MOD_WIN_DR | \ + VAS_MOD_WIN_PR | VAS_MOD_WIN_SF) + +#define VAS_WIN_ACTIVE 0x0 +#define VAS_WIN_CLOSED 0x1 +#define VAS_WIN_INACTIVE 0x2 /* Inactive due to HW failure */ +/* Process of being modified, deallocated, or quiesced */ +#define VAS_WIN_MOD_IN_PROCESS 0x3 + +#define VAS_COPY_PASTE_USER_MODE 0x00000001 +#define VAS_COP_OP_USER_MODE 0x00000010 + +/* + * Co-processor feature - GZIP QoS windows or GZIP default windows + */ +enum vas_cop_feat_type { + VAS_GZIP_QOS_FEAT_TYPE, + VAS_GZIP_DEF_FEAT_TYPE, + VAS_MAX_FEAT_TYPE, +}; + +struct vas_ct_capabs_be { + __be64 descriptor; + u8 win_type; /* Default or QoS type */ + u8 user_mode; + __be16 max_lpar_creds; + __be16 max_win_creds; + union { + __be16 reserved; + __be16 def_lpar_creds; /* Used for default capabilities */ + }; + __be16 target_lpar_creds; +} __packed __aligned(0x1000); + +struct vas_ct_capabs { + char name[VAS_DESCR_LEN + 1]; + u64 descriptor; + u8 win_type; /* Default or QoS type */ + u8 user_mode; /* User mode copy/paste or COP HCALL */ + u16 max_lpar_creds; /* Max credits available in LPAR */ + /* Max credits can be assigned per window */ + u16 max_win_creds; + union { + u16 reserved; /* Used for QoS credit type */ + u16 def_lpar_creds; /* Used for default credit type */ + }; + /* Total LPAR available credits. Can be different from max LPAR */ + /* credits due to DLPAR operation */ + atomic_t target_lpar_creds; + atomic_t used_lpar_creds; /* Used credits so far */ + u16 avail_lpar_creds; /* Remaining available credits */ +}; + +struct vas_capabs { + struct vas_ct_capabs capab; + struct list_head list; +}; + +struct vas_win_lpar_be { + __be16 version; + u8 win_type; + u8 status; + __be16 credits; /* No of credits assigned to this window */ + __be16 reserved; + __be32 pid; /* LPAR Process ID */ + __be32 tid; /* LPAR Thread ID */ + __be64 win_addr; + __be32 interrupt; /* Interrupt when NX request completes */ + __be32 fault; /* Interrupt when NX sees fault */ + /* Associativity Domain Identifiers as returned in */ + /* H_HOME_NODE_ASSOCIATIVITY */ + __be64 domain[6]; + __be64 win_util; /* Number of bytes processed */ +} __packed __aligned(0x1000); + +#endif /* _VAS_H */ From patchwork Sun Apr 11 00:35:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195985 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52D8BC433B4 for ; Sun, 11 Apr 2021 00:36:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26E96610D1 for ; Sun, 11 Apr 2021 00:36:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234751AbhDKAga (ORCPT ); Sat, 10 Apr 2021 20:36:30 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:10116 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234548AbhDKAg3 (ORCPT ); Sat, 10 Apr 2021 20:36:29 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0WYZA040206; Sat, 10 Apr 2021 20:36:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=xAabvqf+7v65N95vm6otfwdaGYBW7MTh6Z+fcF2lOwU=; b=RVpZnEPV3Xg17GX/FDUZ+QCcf88Zk+oGfn4yIiNIHwjbIBUDxQB2g2cLe2ZHHEuZ/9yI nySu9NAEmwllWaO5OGA3ZQs3le9UD8rn8EfQy09cE/JAxXizCDHk+V60oqfxqcYqdtwA GKabSWLO4oJp9Wj+wl8OMcSIVjEEOXr4ulAAm021OqMUDZ8zDTcffM7xy0u8wYPLh+Tr P9HkKAIuWW6fGUgEr/5+7FA2QX7lZC/1SvmbLKuUEuL7PlHqOUxxKhw/Ygn92crUdOMD i5FeQ3TVa0tDRRz+7Ou9jrOaFYoAjqycaiMRNPksWeniWJ6TfxIOtdj5Bpil7BhvpUod fw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 37u65nx0vu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:36:06 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0XcZ4041930; Sat, 10 Apr 2021 20:36:06 -0400 Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0b-001b2d01.pphosted.com with ESMTP id 37u65nx0vq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:36:06 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0S5Js003799; Sun, 11 Apr 2021 00:36:05 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma05wdc.us.ibm.com with ESMTP id 37u3n95403-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:36:05 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0a5j023396684 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:36:05 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3A544AE067; Sun, 11 Apr 2021 00:36:05 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 127FCAE05C; Sun, 11 Apr 2021 00:36:04 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:36:03 +0000 (GMT) Message-ID: <2489cf15fafb25fab3f608d6ecae72665738bd27.camel@linux.ibm.com> Subject: [PATCH 07/16] powerpc/vas: Define QoS credit flag to allocate window From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@us.ibm.com Date: Sat, 10 Apr 2021 17:35:54 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: O047JVj8iGEMCghYtav-qZwvoKY_ts75 X-Proofpoint-ORIG-GUID: 3bJgJnLaIjJNqwGQLoQ2COQ6vOJwefNB X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 priorityscore=1501 phishscore=0 adultscore=0 impostorscore=0 clxscore=1015 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org pHyp introduces two different type of credits: Default and Quality of service (QoS). The total number of default credits available on each LPAR depends on CPU resources configured. But these credits can be shared or over-committed across LPARs in shared mode which can result in paste command failure (RMA_busy). To avoid NX HW contention, phyp introduces QoS credit type which makes sure guaranteed access to NX resources. The system admins can assign QoS credits for each LPAR via HMC. Default credit type is used to allocate a VAS window by default as on powerVM implementation. But the process can pass VAS_WIN_QOS_CREDITS flag with VAS_TX_WIN_OPEN ioctl to open VAS QoS type window. Signed-off-by: Haren Myneni --- arch/powerpc/include/uapi/asm/vas-api.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/uapi/asm/vas-api.h b/arch/powerpc/include/uapi/asm/vas-api.h index ebd4b2424785..eb7c8694174f 100644 --- a/arch/powerpc/include/uapi/asm/vas-api.h +++ b/arch/powerpc/include/uapi/asm/vas-api.h @@ -13,11 +13,15 @@ #define VAS_MAGIC 'v' #define VAS_TX_WIN_OPEN _IOW(VAS_MAGIC, 0x20, struct vas_tx_win_open_attr) +/* Flags to VAS TX open window ioctl */ +/* To allocate a window with QoS credit, otherwise default credit is used */ +#define VAS_WIN_QOS_CREDITS 0x0000000000000001 + struct vas_tx_win_open_attr { __u32 version; __s16 vas_id; /* specific instance of vas or -1 for default */ __u16 reserved1; - __u64 flags; /* Future use */ + __u64 flags; __u64 reserved2[6]; }; From patchwork Sun Apr 11 00:36:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195987 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36EF7C433ED for ; Sun, 11 Apr 2021 00:37:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06B4561028 for ; Sun, 11 Apr 2021 00:37:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234680AbhDKAhV (ORCPT ); Sat, 10 Apr 2021 20:37:21 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:62152 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKAhV (ORCPT ); Sat, 10 Apr 2021 20:37:21 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0XYJ4073183; Sat, 10 Apr 2021 20:37:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=9ETTbJjrjvw9mMBYfehCAwyxedjykqeURiOMtjUAEwo=; b=sX7gwgPxu6NLHcX+W5RIVHbkW4tG+okKe5c4ILYlSIRlA/Q7To5HGexkzswe3dOZBM6n Uj9YGrEUSmMSPNLRZFdA+k93nFG1NVRSPtdanIKgP25dNE7RAWJCASCs4EbDaA3LLdkR H59vlUWeh0B9m2gD+TaiT2hIjo2Qj3wToaqcFmkloladGMwYDioqnQOijnfdi9KohkJp RrjuhATEb0Q9upse4yumfc2LxTEpZ6ZPYqPOKwHSxTMAHO3nrIQxhWOZwg4bzW0SbLRJ SUe6GfuCux5OtHDMOs9iJS6L3jnEXKGcN3GciuGIDeB7MFuzYNV7lg7Z5cC4ABQ40i44 Vw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u7aqn22e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:37:00 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0aOWM077881; Sat, 10 Apr 2021 20:36:59 -0400 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u7aqn229-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:36:59 -0400 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0RYv2021517; Sun, 11 Apr 2021 00:36:58 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma01dal.us.ibm.com with ESMTP id 37u3n8pdbr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:36:58 +0000 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0avnS26870090 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:36:57 GMT Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5A7506A04F; Sun, 11 Apr 2021 00:36:57 +0000 (GMT) Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F1D456A057; Sun, 11 Apr 2021 00:36:55 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:36:55 +0000 (GMT) Message-ID: <49bccf905ce2e70f35ef1f1ba99e16654d364139.camel@linux.ibm.com> Subject: [PATCH 08/16] powerpc/pseries/VAS: Implement allocate/modify/deallocate HCALLS From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@us.ibm.com Date: Sat, 10 Apr 2021 17:36:54 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 6_Kzw71GupgKzI2Z4MwkrpWarTL5kWza X-Proofpoint-ORIG-GUID: CiCPzORgWH2qEwOKlsTwsWu851_Xf858 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 clxscore=1015 impostorscore=0 mlxscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This patch adds the following HCALLs which are used to allocate, modify and deallocate VAS windows. H_ALLOCATE_VAS_WINDOW: Allocate VAS window H_DEALLOCATE_VAS_WINDOW: Close VAS window H_MODIFY_VAS_WINDOW: Setup window before using Also adds phyp call (H_QUERY_VAS_CAPABILITIES) to get all VAS capabilities that phyp provides. Signed-off-by: Haren Myneni --- arch/powerpc/platforms/pseries/vas.c | 217 +++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 arch/powerpc/platforms/pseries/vas.c diff --git a/arch/powerpc/platforms/pseries/vas.c b/arch/powerpc/platforms/pseries/vas.c new file mode 100644 index 000000000000..06960151477c --- /dev/null +++ b/arch/powerpc/platforms/pseries/vas.c @@ -0,0 +1,217 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright 2020-21 IBM Corp. + */ + +#define pr_fmt(fmt) "vas: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "vas.h" + +#define VAS_INVALID_WIN_ADDRESS 0xFFFFFFFFFFFFFFFFul +#define VAS_DEFAULT_DOMAIN_ID 0xFFFFFFFFFFFFFFFFul +/* Authority Mask Register (AMR) value is not supported in */ +/* linux implementation. So pass '0' to modify window HCALL */ +#define VAS_AMR_VALUE 0 +/* phyp allows one credit per window right now */ +#define DEF_WIN_CREDS 1 + +static int64_t hcall_return_busy_check(int64_t rc) +{ + /* Check if we are stalled for some time */ + if (H_IS_LONG_BUSY(rc)) { + msleep(get_longbusy_msecs(rc)); + rc = H_BUSY; + } else if (rc == H_BUSY) { + cond_resched(); + } + + return rc; +} + +/* + * Allocate VAS window HCALL + */ +static int plpar_vas_allocate_window(struct vas_window *win, u64 *domain, + u8 wintype, u16 credits) +{ + long retbuf[PLPAR_HCALL9_BUFSIZE] = {0}; + int64_t rc; + + do { + rc = plpar_hcall9(H_ALLOCATE_VAS_WINDOW, retbuf, wintype, + credits, domain[0], domain[1], domain[2], + domain[3], domain[4], domain[5]); + + rc = hcall_return_busy_check(rc); + } while (rc == H_BUSY); + + switch (rc) { + case H_SUCCESS: + win->winid = retbuf[0]; + win->lpar.win_addr = retbuf[1]; + win->lpar.complete_irq = retbuf[2]; + win->lpar.fault_irq = retbuf[3]; + if (win->lpar.win_addr == VAS_INVALID_WIN_ADDRESS) { + pr_err("HCALL(%x): COPY/PASTE is not supported\n", + H_ALLOCATE_VAS_WINDOW); + return -ENOTSUPP; + } + return 0; + case H_PARAMETER: + pr_err("HCALL(%x): Invalid window type (%u)\n", + H_ALLOCATE_VAS_WINDOW, wintype); + return -EINVAL; + case H_P2: + pr_err("HCALL(%x): Credits(%u) exceed maximum window credits\n", + H_ALLOCATE_VAS_WINDOW, credits); + return -EINVAL; + case H_COP_HW: + pr_err("HCALL(%x): User-mode COPY/PASTE is not supported\n", + H_ALLOCATE_VAS_WINDOW); + return -ENOTSUPP; + case H_RESOURCE: + pr_err("HCALL(%x): LPAR credit limit exceeds window limit\n", + H_ALLOCATE_VAS_WINDOW); + return -EPERM; + case H_CONSTRAINED: + pr_err("HCALL(%x): Credits (%u) are not available\n", + H_ALLOCATE_VAS_WINDOW, credits); + return -EPERM; + default: + pr_err("HCALL(%x): Unexpected error %lld\n", + H_ALLOCATE_VAS_WINDOW, rc); + return -EIO; + } +} + +/* + * Deallocate VAS window HCALL. + */ +static int plpar_vas_deallocate_window(u64 winid) +{ + int64_t rc; + + do { + rc = plpar_hcall_norets(H_DEALLOCATE_VAS_WINDOW, winid); + + rc = hcall_return_busy_check(rc); + } while (rc == H_BUSY); + + switch (rc) { + case H_SUCCESS: + return 0; + case H_PARAMETER: + pr_err("HCALL(%x): Invalid window ID %llu\n", + H_DEALLOCATE_VAS_WINDOW, winid); + return -EINVAL; + case H_STATE: + pr_err("HCALL(%x): Window(%llu): Invalid page table entries\n", + H_DEALLOCATE_VAS_WINDOW, winid); + return -EPERM; + default: + pr_err("HCALL(%x): Unexpected error %lld for window(%llu)\n", + H_DEALLOCATE_VAS_WINDOW, rc, winid); + return -EIO; + } +} + +/* + * Modify VAS window. + * After the window is opened with allocate window HCALL, configure it + * with flags and LPAR PID before using. + */ +static int plpar_vas_modify_window(struct vas_window *win) +{ + int64_t rc; + u32 lpid = mfspr(SPRN_PID); + + /* + * AMR value is not supported in Linux implementation + * phyp ignores it if 0 is passed. + */ + do { + rc = plpar_hcall_norets(H_MODIFY_VAS_WINDOW, win->winid, + lpid, 0, VAS_MOD_WIN_FLAGS, + VAS_AMR_VALUE); + + rc = hcall_return_busy_check(rc); + } while (rc == H_BUSY); + + switch (rc) { + case H_SUCCESS: + return 0; + case H_PARAMETER: + pr_err("HCALL(%x): Invalid window ID %u\n", + H_MODIFY_VAS_WINDOW, win->winid); + return -EINVAL; + case H_P2: + pr_err("HCALL(%x): Window(%d): Invalid LPAR Process ID %u\n", + H_MODIFY_VAS_WINDOW, lpid, win->winid); + return -EINVAL; + case H_P3: + /* LPAR thread ID is deprecated on P10 */ + pr_err("HCALL(%x): Invalid LPAR Thread ID for window(%u)\n", + H_MODIFY_VAS_WINDOW, win->winid); + return -EINVAL; + case H_STATE: + pr_err("HCALL(%x): Jobs in progress, Can't modify window(%u)\n", + H_MODIFY_VAS_WINDOW, win->winid); + return -EBUSY; + default: + pr_err("HCALL(%x): Unexpected error %lld for window(%u)\n", + H_MODIFY_VAS_WINDOW, rc, win->winid); + return -EIO; + } +} + +/* + * This HCALL is used to determine the capabilities that pHyp provides. + * @hcall: H_QUERY_VAS_CAPABILITIES or H_QUERY_NX_CAPABILITIES + * @query_type: If 0 is passed, phyp returns the overall capabilities + * which provides all feature(s) that are available. Then + * query phyp to get the corresponding capabilities for + * the specific feature. + * Example: H_QUERY_VAS_CAPABILITIES provides VAS GZIP QoS + * and VAS GZIP Default capabilities. + * H_QUERY_NX_CAPABILITIES provides NX GZIP + * capabilities. + * @result: Return buffer to save capabilities. + */ +int plpar_vas_query_capabilities(const u64 hcall, u8 query_type, + u64 result) +{ + int64_t rc; + + rc = plpar_hcall_norets(hcall, query_type, result); + + switch (rc) { + case H_SUCCESS: + return 0; + case H_PARAMETER: + pr_err("HCALL(%llx): Invalid query type %u\n", hcall, + query_type); + return -EINVAL; + case H_PRIVILEGE: + pr_err("HCALL(%llx): Invalid result buffer 0x%llx\n", + hcall, result); + return -EACCES; + default: + pr_err("HCALL(%llx): Unexpected error %lld\n", hcall, rc); + return -EIO; + } +} From patchwork Sun Apr 11 00:38:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195989 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80C5CC433ED for ; Sun, 11 Apr 2021 00:38:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52F6961074 for ; Sun, 11 Apr 2021 00:38:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234680AbhDKAic (ORCPT ); Sat, 10 Apr 2021 20:38:32 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54568 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKAib (ORCPT ); Sat, 10 Apr 2021 20:38:31 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0X0YH080397; Sat, 10 Apr 2021 20:38:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=aJ6vjjC786MTHJjzsddAsFQowBXH0hlUgF+uJXi8Epo=; b=Ew5oMcW2m2pVgLGctjZABCYpCxWTxC/EoJDGEdYYPKd2jz6QAlhzAc1AKk2K9BDmCfHR GiLGmqvf6Cvy4OE78VtTBQNbVaLSR08GYaHD9TLhthR5SQTJk5fRySryFUZE1ST/Jf8r vmKBom0nQXGivrm5wEs2MREKIsSKVi9odIxUClHn+Yvhcmu9t9fvEERIblI7rPo9Foec 3irdPgXhSbY7768MvIWEx7QankfeFCbO5d2urZZfNwVt0OOJ9/lOzdXvEGk1pjTeF5o/ Tp1zRAOLlWXTvx7UkHEZ2u3dVwI82fE9JIuCc1FfVAV13yUVxDQA51port2wlPxZCtUZ 4Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u7vyvafu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:38:09 -0400 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0XX7K081893; Sat, 10 Apr 2021 20:38:08 -0400 Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u7vyvafr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:38:08 -0400 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0Rxh6017306; Sun, 11 Apr 2021 00:38:08 GMT Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by ppma02wdc.us.ibm.com with ESMTP id 37u3n955gk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:38:08 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0c7Tr16843128 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:38:07 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DE62112064; Sun, 11 Apr 2021 00:38:07 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 70BC3112063; Sun, 11 Apr 2021 00:38:06 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:38:06 +0000 (GMT) Message-ID: <7782d98999a8753b023b133ee43387da392cfefb.camel@linux.ibm.com> Subject: [PATCH 09/16] powerpc/pseries/vas: Implement to get all capabilities From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@linux.ibm.com Date: Sat, 10 Apr 2021 17:38:04 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 4KlPZVl7LUd8pu9cE1tnpD5dCp6W5AIS X-Proofpoint-GUID: jsEtlXGv5UhZmdea5s4KLb0GNpH-bNPD X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 bulkscore=0 clxscore=1015 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org pHyp provides various VAS capabilities such as GZIP default and QoS capabilities which are used to determine total number of credits available in LPAR, maximum window credits, maximum LPAR credits, whether usermode copy/paste is supported, and etc. So first retrieve overall vas capabilities using H_QUERY_VAS_CAPABILITIES HCALL which tells the specific features that are available. Then retrieve the specific capabilities by using the feature type in H_QUERY_VAS_CAPABILITIES HCALL. pHyp supports only GZIP default and GZIP QoS capabilities right now. Signed-off-by: Haren Myneni --- arch/powerpc/platforms/pseries/vas.c | 130 +++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/arch/powerpc/platforms/pseries/vas.c b/arch/powerpc/platforms/pseries/vas.c index 06960151477c..35946fb02995 100644 --- a/arch/powerpc/platforms/pseries/vas.c +++ b/arch/powerpc/platforms/pseries/vas.c @@ -30,6 +30,13 @@ /* phyp allows one credit per window right now */ #define DEF_WIN_CREDS 1 +static struct vas_all_capabs capabs_all; +static int copypaste_feat; + +struct vas_capabs vcapabs[VAS_MAX_FEAT_TYPE]; + +DEFINE_MUTEX(vas_pseries_mutex); + static int64_t hcall_return_busy_check(int64_t rc) { /* Check if we are stalled for some time */ @@ -215,3 +222,126 @@ int plpar_vas_query_capabilities(const u64 hcall, u8 query_type, return -EIO; } } + +/* + * Get the specific capabilities based on the feature type. + * Right now supports GZIP default and GZIP QoS capabilities. + */ +static int get_vas_capabilities(u8 feat, enum vas_cop_feat_type type, + struct vas_ct_capabs_be *capab_be) +{ + struct vas_ct_capabs *capab; + struct vas_capabs *vcapab; + int rc = 0; + + vcapab = &vcapabs[type]; + memset(vcapab, 0, sizeof(*vcapab)); + INIT_LIST_HEAD(&vcapab->list); + + capab = &vcapab->capab; + + rc = plpar_vas_query_capabilities(H_QUERY_VAS_CAPABILITIES, feat, + (u64)virt_to_phys(capab_be)); + if (rc) + return rc; + + capab->user_mode = capab_be->user_mode; + if (!(capab->user_mode & VAS_COPY_PASTE_USER_MODE)) { + pr_err("User space COPY/PASTE is not supported\n"); + return -ENOTSUPP; + } + + snprintf(capab->name, VAS_DESCR_LEN + 1, "%.8s", + (char *)&capab_be->descriptor); + capab->descriptor = be64_to_cpu(capab_be->descriptor); + capab->win_type = capab_be->win_type; + if (capab->win_type >= VAS_MAX_FEAT_TYPE) { + pr_err("Unsupported window type %u\n", capab->win_type); + return -EINVAL; + } + capab->max_lpar_creds = be16_to_cpu(capab_be->max_lpar_creds); + capab->max_win_creds = be16_to_cpu(capab_be->max_win_creds); + atomic_set(&capab->target_lpar_creds, + be16_to_cpu(capab_be->target_lpar_creds)); + if (feat == VAS_GZIP_DEF_FEAT) { + capab->def_lpar_creds = be16_to_cpu(capab_be->def_lpar_creds); + + if (capab->max_win_creds < DEF_WIN_CREDS) { + pr_err("Window creds(%u) > max allowed window creds(%u)\n", + DEF_WIN_CREDS, capab->max_win_creds); + return -EINVAL; + } + } + + copypaste_feat = 1; + + return 0; +} + +static int __init pseries_vas_init(void) +{ + struct vas_ct_capabs_be *ct_capabs_be; + struct vas_all_capabs_be *capabs_be; + int rc; + + /* + * Linux supports user space COPY/PASTE only with Radix + */ + if (!radix_enabled()) { + pr_err("API is supported only with radix page tables\n"); + return -ENOTSUPP; + } + + capabs_be = kmalloc(sizeof(*capabs_be), GFP_KERNEL); + if (!capabs_be) + return -ENOMEM; + /* + * Get VAS overall capabilities by passing 0 to feature type. + */ + rc = plpar_vas_query_capabilities(H_QUERY_VAS_CAPABILITIES, 0, + (u64)virt_to_phys(capabs_be)); + if (rc) + goto out; + + snprintf(capabs_all.name, VAS_DESCR_LEN, "%.7s", + (char *)&capabs_be->descriptor); + capabs_all.descriptor = be64_to_cpu(capabs_be->descriptor); + capabs_all.feat_type = be64_to_cpu(capabs_be->feat_type); + + ct_capabs_be = kmalloc(sizeof(*ct_capabs_be), GFP_KERNEL); + if (!ct_capabs_be) { + rc = -ENOMEM; + goto out; + } + /* + * QOS capabilities available + */ + if (capabs_all.feat_type & VAS_GZIP_QOS_FEAT_BIT) { + rc = get_vas_capabilities(VAS_GZIP_QOS_FEAT, + VAS_GZIP_QOS_FEAT_TYPE, ct_capabs_be); + + if (rc) + goto out_ct; + } + /* + * Default capabilities available + */ + if (capabs_all.feat_type & VAS_GZIP_DEF_FEAT_BIT) { + rc = get_vas_capabilities(VAS_GZIP_DEF_FEAT, + VAS_GZIP_DEF_FEAT_TYPE, ct_capabs_be); + if (rc) + goto out_ct; + } + + if (!copypaste_feat) + pr_err("GZIP feature is not supported\n"); + + pr_info("GZIP feature is available\n"); + +out_ct: + kfree(ct_capabs_be); +out: + kfree(capabs_be); + return rc; +} +machine_device_initcall(pseries, pseries_vas_init); From patchwork Sun Apr 11 00:39:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195991 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 198E4C433B4 for ; Sun, 11 Apr 2021 00:39:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E01D661074 for ; Sun, 11 Apr 2021 00:39:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234680AbhDKAjm (ORCPT ); Sat, 10 Apr 2021 20:39:42 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:61266 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234548AbhDKAjl (ORCPT ); Sat, 10 Apr 2021 20:39:41 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0XO7x061484; Sat, 10 Apr 2021 20:39:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=EVjye/BBlFI2yu/VUn9jbJh5EK0czYfEgMLq/wGSBz8=; b=RT1tSaaKzBdYpRPQMlVBgr4Wr2Ghb0siwnH6RiiJzeu1Qh9XaLLk1q2mUlZah2Gzm4VK jo2l3FwivHprbxxNm7n1QK/LGN7Xmx3opcyDWN9rIy0YcG6lR48hlRa+DekpW50BeKVW viV4C4CExb/CfqffkRkwXx3U0tNRYbOKswZuRnS3VyrRIPpRh0m8vbbglE0nNq6Rxx3x R3vfj9ZUSzc8qCvNRT22Mi6oYYnHlHvuWlniNTBqstU2A/Hfrb/UnoISFlLnggyUKOT3 icie6tJEMJ0xJYQhHgdIcYe+mKxKvtUynhdIxtYxkSRpdPGmVe0irCblxEhTsE0nddzc xA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 37u4y7xwd6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:39:18 -0400 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0Xa1H061914; Sat, 10 Apr 2021 20:39:18 -0400 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0b-001b2d01.pphosted.com with ESMTP id 37u4y7xwd3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:39:18 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0RxpV019955; Sun, 11 Apr 2021 00:39:17 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma04dal.us.ibm.com with ESMTP id 37u3n86evr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:39:17 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0dFWd23789946 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:39:15 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1AF778066; Sun, 11 Apr 2021 00:39:15 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DE5678063; Sun, 11 Apr 2021 00:39:14 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:39:14 +0000 (GMT) Message-ID: <620bf714643eb18ba5a05e920881d36d9fc03d76.camel@linux.ibm.com> Subject: [PATCH 10/16] powerpc/pseries/vas: Integrate API with open/close windows From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@linux.ibm.com Date: Sat, 10 Apr 2021 17:39:12 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: k72o3XhRMTi5uLYC8ywqUWryt3NepiSV X-Proofpoint-ORIG-GUID: 4AQuDhtPNWdMP6Sx0-swCfMO7bEJHMH2 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 impostorscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 mlxscore=0 spamscore=0 suspectscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This patch adds VAS window allocatioa/close with the corresponding HCALLs. Also changes to integrate with the existing user space VAS API and provide register/unregister functions to NX pseries driver. The driver register function is used to create the user space interface (/dev/crypto/nx-gzip) and unregister to remove this entry. The user space process opens this device node and makes an ioctl to allocate VAS window. The close interface is used to deallocate window. Signed-off-by: Haren Myneni --- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/vas.h | 5 + arch/powerpc/platforms/pseries/Makefile | 1 + arch/powerpc/platforms/pseries/vas.c | 212 ++++++++++++++++++++++++ 4 files changed, 219 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 7aa1fbf7c1dc..10853ee02b84 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -480,7 +480,7 @@ config PPC_UV config PPC_VAS bool "IBM Virtual Accelerator Switchboard (VAS)" - depends on PPC_POWERNV && PPC_64K_PAGES + depends on (PPC_POWERNV || PPC_PSERIES) && PPC_64K_PAGES default y help This enables support for IBM Virtual Accelerator Switchboard (VAS). diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h index d15784506a54..aa1974aba27e 100644 --- a/arch/powerpc/include/asm/vas.h +++ b/arch/powerpc/include/asm/vas.h @@ -270,6 +270,11 @@ struct vas_all_capabs { u64 feat_type; }; +int plpar_vas_query_capabilities(const u64 hcall, u8 query_type, + u64 result); +int vas_register_api_pseries(struct module *mod, + enum vas_cop_type cop_type, const char *name); +void vas_unregister_api_pseries(void); #endif /* diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile index c8a2b0b05ac0..4cda0ef87be0 100644 --- a/arch/powerpc/platforms/pseries/Makefile +++ b/arch/powerpc/platforms/pseries/Makefile @@ -30,3 +30,4 @@ obj-$(CONFIG_PPC_SVM) += svm.o obj-$(CONFIG_FA_DUMP) += rtas-fadump.o obj-$(CONFIG_SUSPEND) += suspend.o +obj-$(CONFIG_PPC_VAS) += vas.o diff --git a/arch/powerpc/platforms/pseries/vas.c b/arch/powerpc/platforms/pseries/vas.c index 35946fb02995..0ade0d6d728f 100644 --- a/arch/powerpc/platforms/pseries/vas.c +++ b/arch/powerpc/platforms/pseries/vas.c @@ -222,6 +222,218 @@ int plpar_vas_query_capabilities(const u64 hcall, u8 query_type, return -EIO; } } +EXPORT_SYMBOL_GPL(plpar_vas_query_capabilities); + +/* + * Allocate window and setup IRQ mapping. + */ +static int allocate_setup_window(struct vas_window *txwin, + u64 *domain, u8 wintype) +{ + int rc; + + rc = plpar_vas_allocate_window(txwin, domain, wintype, DEF_WIN_CREDS); + if (rc) + return rc; + + txwin->wcreds_max = DEF_WIN_CREDS; + + return 0; +} + +static struct vas_window *vas_allocate_window(struct vas_tx_win_open_attr *uattr, + enum vas_cop_type cop_type) +{ + long domain[PLPAR_HCALL9_BUFSIZE] = {VAS_DEFAULT_DOMAIN_ID}; + struct vas_ct_capabs *ct_capab; + struct vas_capabs *capabs; + struct vas_window *txwin; + int rc; + + txwin = kzalloc(sizeof(*txwin), GFP_KERNEL); + if (!txwin) + return ERR_PTR(-ENOMEM); + + /* + * A VAS window can have many credits which means that many + * requests can be issued simultaneously. But phyp restricts + * one credit per window. + * phyp introduces 2 different types of credits: + * Default credit type (Uses normal priority FIFO): + * A limited number of credits are assigned to partitions + * based on processor entitlement. But these credits may be + * over-committed on a system depends on whether the CPUs + * are in shared or dedicated modes - that is, more requests + * may be issued across the system than NX can service at + * once which can result in paste command failure (RMA_busy). + * Then the process has to resend requests or fall-back to + * SW compression. + * Quality of Service (QoS) credit type (Uses high priority FIFO): + * To avoid NX HW contention, the system admins can assign + * QoS credits for each LPAR so that this partition is + * guaranteed access to NX resources. These credits are + * assigned to partitions via the HMC. + * Refer PAPR for more information. + * + * Allocate window with QoS credits if user requested. Otherwise + * default credits are used. + */ + if (uattr->flags & VAS_WIN_QOS_CREDITS) + capabs = &vcapabs[VAS_GZIP_QOS_FEAT_TYPE]; + else + capabs = &vcapabs[VAS_GZIP_DEF_FEAT_TYPE]; + + ct_capab = &capabs->capab; + + if (atomic_inc_return(&ct_capab->used_lpar_creds) > + atomic_read(&ct_capab->target_lpar_creds)) { + pr_err("Credits are not available to allocate window\n"); + rc = -EINVAL; + goto out; + } + + /* + * The user space is requesting to allocate a window on a VAS + * instance (or chip) where the process is executing. + * On powerVM, domain values are passed to pHyp to select chip / + * VAS instance. Useful if the process is affinity to NUMA node. + * pHyp selects VAS instance if VAS_DEFAULT_DOMAIN_ID (-1) is + * passed for domain values. + */ + if (uattr->vas_id == -1) { + /* + * To allocate VAS window, pass same domain values returned + * from this HCALL. + */ + rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, domain, + VPHN_FLAG_VCPU, smp_processor_id()); + if (rc != H_SUCCESS) { + pr_err("HCALL(%x): failed with ret(%d)\n", + H_HOME_NODE_ASSOCIATIVITY, rc); + goto out; + } + } + + /* + * Allocate / Deallocate window HCALLs and setup / free IRQs + * have to be protected with mutex. Otherwise, since IRQ is freed + * after deallocate HCALL, may see the case where window ID and + * fault interrupt could be reused before free IRQ (for the old + * window) in kernel. It can result in setup IRQ fail for the + * new window. + */ + mutex_lock(&vas_pseries_mutex); + rc = allocate_setup_window(txwin, (u64 *)&domain[0], + ct_capab->win_type); + mutex_unlock(&vas_pseries_mutex); + if (rc) + goto out; + + /* + * Modify window and it is ready to use. + */ + rc = plpar_vas_modify_window(txwin); + if (!rc) + rc = vas_reference_task(&txwin->task); + if (rc) + goto out_free; + + txwin->lpar.win_type = ct_capab->win_type; + mutex_lock(&vas_pseries_mutex); + list_add(&txwin->lpar.win_list, &capabs->list); + mutex_unlock(&vas_pseries_mutex); + + return txwin; + +out_free: + plpar_vas_deallocate_window(txwin->winid); +out: + atomic_dec(&ct_capab->used_lpar_creds); + kfree(txwin); + return ERR_PTR(rc); +} + +static u64 vas_paste_address(void *addr) +{ + struct vas_window *win = addr; + + return win->lpar.win_addr; +} + +static int deallocate_free_window(struct vas_window *win) +{ + int rc = 0; + + rc = plpar_vas_deallocate_window(win->winid); + if (!rc) + kfree(win->lpar.name); + + return rc; +} + +static int vas_deallocate_window(void *addr) +{ + struct vas_window *win = (struct vas_window *)addr; + struct vas_ct_capabs *capabs; + int rc = 0; + + if (!win) + return -EINVAL; + + /* Should not happen */ + if (win->lpar.win_type >= VAS_MAX_FEAT_TYPE) { + pr_err("Window (%u): Invalid window type %u\n", + win->winid, win->lpar.win_type); + return -EINVAL; + } + + capabs = &vcapabs[win->lpar.win_type].capab; + mutex_lock(&vas_pseries_mutex); + rc = deallocate_free_window(win); + if (rc) { + mutex_unlock(&vas_pseries_mutex); + return rc; + } + + list_del(&win->lpar.win_list); + atomic_dec(&capabs->used_lpar_creds); + mutex_unlock(&vas_pseries_mutex); + + vas_drop_reference_task(&win->task); + + kfree(win); + return 0; +} + +static struct vas_user_win_ops vops_pseries = { + .open_win = vas_allocate_window, /* Open and configure window */ + .paste_addr = vas_paste_address, /* To do copy/paste */ + .close_win = vas_deallocate_window, /* Close window */ +}; + +/* + * Supporting only nx-gzip coprocessor type now, but this API code + * extended to other coprocessor types later. + */ +int vas_register_api_pseries(struct module *mod, enum vas_cop_type cop_type, + const char *name) +{ + int rc; + + if (!copypaste_feat) + return -ENOTSUPP; + + rc = vas_register_coproc_api(mod, cop_type, name, &vops_pseries); + + return rc; +} +EXPORT_SYMBOL_GPL(vas_register_api_pseries); + +void vas_unregister_api_pseries(void) +{ + vas_unregister_coproc_api(); +} +EXPORT_SYMBOL_GPL(vas_unregister_api_pseries); /* * Get the specific capabilities based on the feature type. From patchwork Sun Apr 11 00:40:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195993 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 183FEC433B4 for ; Sun, 11 Apr 2021 00:40:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DCF35610E5 for ; Sun, 11 Apr 2021 00:40:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234757AbhDKAko (ORCPT ); Sat, 10 Apr 2021 20:40:44 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:52268 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKAko (ORCPT ); Sat, 10 Apr 2021 20:40:44 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0YLTl032960; Sat, 10 Apr 2021 20:40:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=w/j4sQ6u0E3NetS+ST1UrLgc/chewiQxhgJ00C45B8w=; b=ZcNBY2azjkPopNGcyc0/0ik0mc1XKbI5omREXhWXCNBWTOBOtwkebDpde9JiKAtE3QPL uJziU2NQlnAAtPcl7n5xqvc6xTum5cbYRbEWDtsJYWrRtkWlZ3DP4XRuBZqQcSnSO0kP pNYczfSHva7TCj98hEPLP0dvFejRrqZ10q1UknC3Sh7oEzgeOBrKVkO8V4qRCUga9rtn iYhNiMXmBqXqIHC41BiZvPiH11McZXEGAkXhteaxsZNipmsyEdfHencnzTNcswv5tWJ4 ncg8JdMp79pGTY5r1TNUfSGMu2ov8gPiPwNLMSgEKq68LcA8PNDPr0ZtrV2yyl1Ierck /A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37up2j8hnx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:40:23 -0400 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0c3XA042131; Sat, 10 Apr 2021 20:40:22 -0400 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 37up2j8hns-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:40:22 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0SwuP002031; Sun, 11 Apr 2021 00:40:21 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma03dal.us.ibm.com with ESMTP id 37u3n8ee29-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:40:21 +0000 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0eK4o19923374 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:40:20 GMT Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 421126A04F; Sun, 11 Apr 2021 00:40:20 +0000 (GMT) Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DAE846A047; Sun, 11 Apr 2021 00:40:18 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:40:18 +0000 (GMT) Message-ID: <0267158504d624f590416fa70434a3a09880ab3b.camel@linux.ibm.com> Subject: [PATCH 11/16] powerpc/pseries/vas: Setup IRQ and fault handling From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@linux.ibm.com Date: Sat, 10 Apr 2021 17:40:16 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: LGG948qlpBbUtL1EvGPj5KbgWda5QlcJ X-Proofpoint-ORIG-GUID: ryGZHKnVNY6a8NQFFnHIDS5qFz_SorD1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 malwarescore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org When NX sees a fault on the user space buffer, generates a fault interrupt and pHyp forwards that interrupt to OS. Then the kernel makes H_GET_NX_FAULT HCALL to retrieve the fault CRB information. This patch adds changes to setup IRQ per each window and handles fault by updating CSB. Signed-off-by: Haren Myneni --- arch/powerpc/platforms/pseries/vas.c | 111 ++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/platforms/pseries/vas.c b/arch/powerpc/platforms/pseries/vas.c index 0ade0d6d728f..2106eca0862a 100644 --- a/arch/powerpc/platforms/pseries/vas.c +++ b/arch/powerpc/platforms/pseries/vas.c @@ -224,6 +224,62 @@ int plpar_vas_query_capabilities(const u64 hcall, u8 query_type, } EXPORT_SYMBOL_GPL(plpar_vas_query_capabilities); +/* + * HCALL to get fault CRB from pHyp. + */ +static int plpar_get_nx_fault(u32 winid, u64 buffer) +{ + int64_t rc; + + rc = plpar_hcall_norets(H_GET_NX_FAULT, winid, buffer); + + switch (rc) { + case H_SUCCESS: + return 0; + case H_PARAMETER: + pr_err("HCALL(%x): Invalid window ID %u\n", H_GET_NX_FAULT, + winid); + return -EINVAL; + case H_STATE: + pr_err("HCALL(%x): No outstanding faults for window ID %u\n", + H_GET_NX_FAULT, winid); + return -EINVAL; + case H_PRIVILEGE: + pr_err("HCALL(%x): Window(%u): Invalid fault buffer 0x%llx\n", + H_GET_NX_FAULT, winid, buffer); + return -EACCES; + default: + pr_err("HCALL(%x): Unexpected error %lld for window(%u)\n", + H_GET_NX_FAULT, rc, winid); + return -EIO; + } +} + +/* + * Handle the fault interrupt. + * When the fault interrupt is received for each window, query pHyp to get + * the fault CRB on the specific fault. Then process the CRB by updating + * CSB or send signal if the user space CSB is invalid. + * Note: pHyp forwards an interrupt for each fault request. So one fault + * CRB to process for each H_GET_NX_FAULT HCALL. + */ +irqreturn_t pseries_vas_fault_thread_fn(int irq, void *data) +{ + struct vas_window *txwin = data; + struct coprocessor_request_block crb; + struct vas_win_task *tsk; + int rc; + + rc = plpar_get_nx_fault(txwin->winid, (u64)virt_to_phys(&crb)); + if (!rc) { + tsk = &txwin->task; + vas_dump_crb(&crb); + vas_update_csb(&crb, tsk); + } + + return IRQ_HANDLED; +} + /* * Allocate window and setup IRQ mapping. */ @@ -235,10 +291,51 @@ static int allocate_setup_window(struct vas_window *txwin, rc = plpar_vas_allocate_window(txwin, domain, wintype, DEF_WIN_CREDS); if (rc) return rc; + /* + * On powerVM, pHyp setup and forwards the fault interrupt per + * window. So the IRQ setup and fault handling will be done for + * each open window separately. + */ + txwin->lpar.fault_virq = irq_create_mapping(NULL, + txwin->lpar.fault_irq); + if (!txwin->lpar.fault_virq) { + pr_err("Failed irq mapping %d\n", txwin->lpar.fault_irq); + rc = -EINVAL; + goto out_win; + } + + txwin->lpar.name = kasprintf(GFP_KERNEL, "vas-win-%d", txwin->winid); + if (!txwin->lpar.name) { + rc = -ENOMEM; + goto out_irq; + } + + rc = request_threaded_irq(txwin->lpar.fault_virq, NULL, + pseries_vas_fault_thread_fn, IRQF_ONESHOT, + txwin->lpar.name, txwin); + if (rc) { + pr_err("VAS-Window[%d]: Request IRQ(%u) failed with %d\n", + txwin->winid, txwin->lpar.fault_virq, rc); + goto out_free; + } txwin->wcreds_max = DEF_WIN_CREDS; return 0; +out_free: + kfree(txwin->lpar.name); +out_irq: + irq_dispose_mapping(txwin->lpar.fault_virq); +out_win: + plpar_vas_deallocate_window(txwin->winid); + return rc; +} + +static inline void free_irq_setup(struct vas_window *txwin) +{ + free_irq(txwin->lpar.fault_virq, txwin); + irq_dispose_mapping(txwin->lpar.fault_virq); + kfree(txwin->lpar.name); } static struct vas_window *vas_allocate_window(struct vas_tx_win_open_attr *uattr, @@ -346,6 +443,11 @@ static struct vas_window *vas_allocate_window(struct vas_tx_win_open_attr *uattr return txwin; out_free: + /* + * Window is not operational. Free IRQ before closing + * window so that do not have to hold mutex. + */ + free_irq_setup(txwin); plpar_vas_deallocate_window(txwin->winid); out: atomic_dec(&ct_capab->used_lpar_creds); @@ -364,9 +466,16 @@ static int deallocate_free_window(struct vas_window *win) { int rc = 0; + /* + * Free IRQ after executing H_DEALLOCATE_VAS_WINDOW HCALL + * to close the window. pHyp waits for all requests including + * faults are processed before closing the window - Means all + * credits are returned. In the case of fault request, credit + * is returned after OS issues H_GET_NX_FAULT HCALL. + */ rc = plpar_vas_deallocate_window(win->winid); if (!rc) - kfree(win->lpar.name); + free_irq_setup(win); return rc; } From patchwork Sun Apr 11 00:41:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195995 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C7AFC433ED for ; Sun, 11 Apr 2021 00:41:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C202610E5 for ; Sun, 11 Apr 2021 00:41:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234751AbhDKAlk (ORCPT ); Sat, 10 Apr 2021 20:41:40 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:60758 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKAlk (ORCPT ); Sat, 10 Apr 2021 20:41:40 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0X0qx028680; Sat, 10 Apr 2021 20:41:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=uphXrxhepjoFoEF05pzkUGxznHJbTIybZp64/TppNYE=; b=lq39qKSjW+q6NrTLlVF/YxNPHqLrID3yGYwH/xOoJseDX4FTlAHqcf/odxKXWUnhp66+ 09bk0v+HbCIny5gWylun3HcHYuB4iLwcz/BqWyZcbjsZqYHqoOOPT0aK6JxmRM4l7Uuk qHxf0xrQqq58QY6Npffd/lF/HYtG1+4AopQsiXsL8oktcKlffhHu4RdgZsAjTx3bmhvQ BluDtv9Jz+P0xHIMUgfwfn6EwtQyfuShVkxKBc+rctxAe/FNFAYqeZ1JVNVRLDEQaQOb GfibcKdaoA6ZYiSP3NOTw44lJwLrn5RW2APWEQCbAR2Rqi4AiirCTKFvyUaOOnTBEZww ww== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u4wb7ayq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:41:19 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0bYXj039533; Sat, 10 Apr 2021 20:41:19 -0400 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u4wb7ayh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:41:18 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0Ruge019941; Sun, 11 Apr 2021 00:41:18 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma04dal.us.ibm.com with ESMTP id 37u3n86f6h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:41:17 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0fGtB29294864 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:41:16 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5F871C605B; Sun, 11 Apr 2021 00:41:16 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9890C6055; Sun, 11 Apr 2021 00:41:14 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:41:14 +0000 (GMT) Message-ID: Subject: [PATCH 12/16] powerpc/pseries/vas: sysfs interface to export capabilities From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@linux.ibm.com Date: Sat, 10 Apr 2021 17:41:12 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 7MqtyllT4FQb3r52gCCaTTpPJLBkJSQN X-Proofpoint-ORIG-GUID: GpxCxW368VJ2ACk8gNLsl5zAJ7XM8zHK X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 spamscore=0 adultscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org pHyp provides GZIP default and GZIP QoS capabilities which gives the total number of credits are available in LPAR. This patch creates sysfs entries and exports LPAR credits, the currently used and the available credits for each feature. /sys/kernel/vas/VasCaps/VDefGzip: (default GZIP capabilities) avail_lpar_creds /* Available credits to use */ target_lpar_creds /* Total credits available which can be /* changed with DLPAR operation */ used_lpar_creds /* Used credits */ /sys/kernel/vas/VasCaps/VQosGzip (QoS GZIP capabilities) avail_lpar_creds target_lpar_creds used_lpar_creds Signed-off-by: Haren Myneni --- arch/powerpc/platforms/pseries/Makefile | 2 +- arch/powerpc/platforms/pseries/vas-sysfs.c | 173 +++++++++++++++++++++ arch/powerpc/platforms/pseries/vas.c | 6 + arch/powerpc/platforms/pseries/vas.h | 2 + 4 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/platforms/pseries/vas-sysfs.c diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile index 4cda0ef87be0..e24093bebc0b 100644 --- a/arch/powerpc/platforms/pseries/Makefile +++ b/arch/powerpc/platforms/pseries/Makefile @@ -30,4 +30,4 @@ obj-$(CONFIG_PPC_SVM) += svm.o obj-$(CONFIG_FA_DUMP) += rtas-fadump.o obj-$(CONFIG_SUSPEND) += suspend.o -obj-$(CONFIG_PPC_VAS) += vas.o +obj-$(CONFIG_PPC_VAS) += vas.o vas-sysfs.o diff --git a/arch/powerpc/platforms/pseries/vas-sysfs.c b/arch/powerpc/platforms/pseries/vas-sysfs.c new file mode 100644 index 000000000000..bf12f38cb9f9 --- /dev/null +++ b/arch/powerpc/platforms/pseries/vas-sysfs.c @@ -0,0 +1,173 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright 2016-17 IBM Corp. + */ + +#define pr_fmt(fmt) "vas: " fmt + +#include +#include +#include +#include +#include + +#include "vas.h" + +#ifdef CONFIG_SYSFS +static struct kobject *pseries_vas_kobj; +static struct kobject *vas_capabs_kobj; + +struct vas_capabs_entry { + struct kobject kobj; + struct vas_ct_capabs *capabs; +}; + +#define to_capabs_entry(entry) container_of(entry, struct vas_capabs_entry, kobj) + +static ssize_t avail_lpar_creds_show(struct vas_ct_capabs *capabs, char *buf) +{ + int avail_creds = atomic_read(&capabs->target_lpar_creds) - + atomic_read(&capabs->used_lpar_creds); + return sprintf(buf, "%d\n", avail_creds); +} + +#define sysfs_capbs_entry_read(_name) \ +static ssize_t _name##_show(struct vas_ct_capabs *capabs, char *buf) \ +{ \ + return sprintf(buf, "%d\n", atomic_read(&capabs->_name)); \ +} + +struct vas_sysfs_entry { + struct attribute attr; + ssize_t (*show)(struct vas_ct_capabs *, char *); + ssize_t (*store)(struct vas_ct_capabs *, const char *, size_t); +}; + +#define VAS_ATTR_RO(_name) \ + sysfs_capbs_entry_read(_name); \ + static struct vas_sysfs_entry _name##_attribute = __ATTR(_name, \ + 0444, _name##_show, NULL); + +VAS_ATTR_RO(target_lpar_creds); +VAS_ATTR_RO(used_lpar_creds); + +static struct vas_sysfs_entry avail_lpar_creds_attribute = + __ATTR(avail_lpar_creds, 0644, avail_lpar_creds_show, NULL); + +static struct attribute *vas_capab_attrs[] = { + &target_lpar_creds_attribute.attr, + &used_lpar_creds_attribute.attr, + &avail_lpar_creds_attribute.attr, + NULL, +}; + +static ssize_t vas_type_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct vas_capabs_entry *centry; + struct vas_ct_capabs *capabs; + struct vas_sysfs_entry *entry; + + centry = to_capabs_entry(kobj); + capabs = centry->capabs; + entry = container_of(attr, struct vas_sysfs_entry, attr); + + if (!entry->show) + return -EIO; + + return entry->show(capabs, buf); +} + +static ssize_t vas_type_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) +{ + struct vas_capabs_entry *centry; + struct vas_ct_capabs *capabs; + struct vas_sysfs_entry *entry; + + centry = to_capabs_entry(kobj); + capabs = centry->capabs; + entry = container_of(attr, struct vas_sysfs_entry, attr); + if (!entry->store) + return -EIO; + + return entry->store(capabs, buf, count); +} + +static void vas_type_release(struct kobject *kobj) +{ + struct vas_capabs_entry *centry = to_capabs_entry(kobj); + kfree(centry); +} + +static const struct sysfs_ops vas_sysfs_ops = { + .show = vas_type_show, + .store = vas_type_store, +}; + +static struct kobj_type vas_attr_type = { + .release = vas_type_release, + .sysfs_ops = &vas_sysfs_ops, + .default_attrs = vas_capab_attrs, +}; + +/* + * Add feature specific capability dir entry. + * Ex: VDefGzip or VQosGzip + */ +int sysfs_add_vas_capabs(struct vas_ct_capabs *capabs) +{ + struct vas_capabs_entry *centry; + int ret = 0; + + centry = kzalloc(sizeof(*centry), GFP_KERNEL); + if (!centry) + return -ENOMEM; + + kobject_init(¢ry->kobj, &vas_attr_type); + centry->capabs = capabs; + + ret = kobject_add(¢ry->kobj, vas_capabs_kobj, "%s", + capabs->name); + + if (ret) { + pr_err("VAS: sysfs kobject add / event failed %d\n", ret); + kobject_put(¢ry->kobj); + } + + return ret; +} + +/* + * Add VAS and VasCaps (overall capabilities) dir entries. + */ +int __init sysfs_pseries_vas_init(struct vas_all_capabs *vas_caps) +{ + pseries_vas_kobj = kobject_create_and_add("vas", kernel_kobj); + if (!pseries_vas_kobj) { + pr_err("Failed to create VAS sysfs entry\n"); + return -ENOMEM; + } + + vas_capabs_kobj = kobject_create_and_add(vas_caps->name, + pseries_vas_kobj); + if (!vas_capabs_kobj) { + pr_err("Failed to create VAS capabilities kobject\n"); + kobject_put(pseries_vas_kobj); + return -ENOMEM; + } + + return 0; +} + +#else +int sysfs_add_vas_capabs(struct vas_ct_capabs *capabs) +{ + return 0; +} + +int __init sysfs_pseries_vas_init(struct vas_all_capabs *vas_caps) +{ + return 0; +} +#endif diff --git a/arch/powerpc/platforms/pseries/vas.c b/arch/powerpc/platforms/pseries/vas.c index 2106eca0862a..ac06fa09900c 100644 --- a/arch/powerpc/platforms/pseries/vas.c +++ b/arch/powerpc/platforms/pseries/vas.c @@ -594,6 +594,10 @@ static int get_vas_capabilities(u8 feat, enum vas_cop_feat_type type, } } + rc = sysfs_add_vas_capabs(capab); + if (rc) + return rc; + copypaste_feat = 1; return 0; @@ -629,6 +633,8 @@ static int __init pseries_vas_init(void) capabs_all.descriptor = be64_to_cpu(capabs_be->descriptor); capabs_all.feat_type = be64_to_cpu(capabs_be->feat_type); + sysfs_pseries_vas_init(&capabs_all); + ct_capabs_be = kmalloc(sizeof(*ct_capabs_be), GFP_KERNEL); if (!ct_capabs_be) { rc = -ENOMEM; diff --git a/arch/powerpc/platforms/pseries/vas.h b/arch/powerpc/platforms/pseries/vas.h index 208682fffa57..e64677f03f08 100644 --- a/arch/powerpc/platforms/pseries/vas.h +++ b/arch/powerpc/platforms/pseries/vas.h @@ -93,4 +93,6 @@ struct vas_win_lpar_be { __be64 win_util; /* Number of bytes processed */ } __packed __aligned(0x1000); +int sysfs_add_vas_capabs(struct vas_ct_capabs *capabs); +int __init sysfs_pseries_vas_init(struct vas_all_capabs *vas_caps); #endif /* _VAS_H */ From patchwork Sun Apr 11 00:41:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195997 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B4EBC433ED for ; Sun, 11 Apr 2021 00:42:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1062361074 for ; Sun, 11 Apr 2021 00:42:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234751AbhDKAm0 (ORCPT ); Sat, 10 Apr 2021 20:42:26 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:8332 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKAm0 (ORCPT ); Sat, 10 Apr 2021 20:42:26 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0X07I181709; Sat, 10 Apr 2021 20:42:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=8VDNbTf7G5vRHHu4gG6mXsNruwZ1y+Folrm8GfKCM/o=; b=Jv0w0/9DmhExqefP+OcUCjgHg5+UNFoIMj7atTYZdntvKmFuohB6ry6cyILyGkFT36Si g7mUg8RzRnhznLiJF4LYX0FoQlcBIOaQfzvih+B+zinB26wfDgoDa715CJaCVK3DoTNx nwwMbNILT5pGNoODFhpTIQYh8v3mjf+CkzMbUhrKFx7tB/ecpwnjohH2Qv4dapcQPQlf r5uFLOc1R/pSAzk06k5D+x0QZt11+leLNDNQ1tWrk/DEDZYQPOXGCaiZgBJNkql7ep/5 rSF+pVjBOeL1lyDjq3+Tqf/uX3taz0afHQIkHgauvp+V7q2p/wrHci6TG71kgKwwYpkl Qw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37ujq4u4k6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:42:05 -0400 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0Xhb8187095; Sat, 10 Apr 2021 20:42:05 -0400 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 37ujq4u4jt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:42:05 -0400 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0RoLb018069; Sun, 11 Apr 2021 00:42:04 GMT Received: from b03cxnp07027.gho.boulder.ibm.com (b03cxnp07027.gho.boulder.ibm.com [9.17.130.14]) by ppma04wdc.us.ibm.com with ESMTP id 37u3n9d5gs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:42:04 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0g21927525420 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:42:02 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 968557805E; Sun, 11 Apr 2021 00:42:02 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E7A278060; Sun, 11 Apr 2021 00:42:01 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:42:00 +0000 (GMT) Message-ID: Subject: [PATCH 13/16] crypto/nx: Rename nx-842-pseries file name to nx-common-pseries From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, linux@linux.ibm.com Date: Sat, 10 Apr 2021 17:41:58 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ro22S_to62A_tEQzWCVN4CT5dqk9WO1_ X-Proofpoint-GUID: U5S6pgpkSYmHEXbt9NG17fhYFPRxN0N- X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 suspectscore=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Rename nx-842-pseries.c to nx-common-pseries.c to add code for new GZIP compression type. The actual functionality is not changed in this patch. Signed-off-by: Haren Myneni --- drivers/crypto/nx/Makefile | 2 +- drivers/crypto/nx/{nx-842-pseries.c => nx-common-pseries.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename drivers/crypto/nx/{nx-842-pseries.c => nx-common-pseries.c} (100%) diff --git a/drivers/crypto/nx/Makefile b/drivers/crypto/nx/Makefile index bc89a20e5d9d..d00181a26dd6 100644 --- a/drivers/crypto/nx/Makefile +++ b/drivers/crypto/nx/Makefile @@ -14,5 +14,5 @@ nx-crypto-objs := nx.o \ obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_PSERIES) += nx-compress-pseries.o nx-compress.o obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_POWERNV) += nx-compress-powernv.o nx-compress.o nx-compress-objs := nx-842.o -nx-compress-pseries-objs := nx-842-pseries.o +nx-compress-pseries-objs := nx-common-pseries.o nx-compress-powernv-objs := nx-common-powernv.o diff --git a/drivers/crypto/nx/nx-842-pseries.c b/drivers/crypto/nx/nx-common-pseries.c similarity index 100% rename from drivers/crypto/nx/nx-842-pseries.c rename to drivers/crypto/nx/nx-common-pseries.c From patchwork Sun Apr 11 00:43:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12195999 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24E5FC433ED for ; Sun, 11 Apr 2021 00:43:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA55161074 for ; Sun, 11 Apr 2021 00:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234548AbhDKAny (ORCPT ); Sat, 10 Apr 2021 20:43:54 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:28398 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234751AbhDKAnx (ORCPT ); Sat, 10 Apr 2021 20:43:53 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0Wu3M080231; Sat, 10 Apr 2021 20:43:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=Gd0uGeDjCAGU9zUqoHWMiI2g/XddIbnnaqtWnmmTHEo=; b=gYDiltLxgQlFB6HkkbApy2OaG+fnTu804/NWRsl7hW9L81K6im+hRxiRFCfFIk0Pffw0 vYjC/nsODIRJ2N7qA6YehPk6H2ooXXWlRqMUc2nEdJbKDyd6q2HXnOkSTB5lNj+r6OUu c4JVUPCdgPe/QQZQBi+8xgu3WVfUYojs7qiGarMp1XPMHuvyRaj6pjQxUCszCYcm+AHk uTTO4tFwG+9NK4HKWerJQ9qmzedq+Do95VpgYm+phmc590KdeZEGellZOw3tgeXyuCN9 q37mfb1+9QIwsT3+ycZHbNH7w1vPq+eJ4nVT+U+2YBrq3+Ox2oXm/QVwh1Wd0Yjpk+Q4 Ew== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u7vyvc99-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:43:30 -0400 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0ZAx2084735; Sat, 10 Apr 2021 20:43:30 -0400 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u7vyvc95-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:43:30 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0STQL031585; Sun, 11 Apr 2021 00:43:30 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma01wdc.us.ibm.com with ESMTP id 37u3n8n5qd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:43:29 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0hScw25493906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:43:28 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BD43C6055; Sun, 11 Apr 2021 00:43:28 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3AA9BC605B; Sun, 11 Apr 2021 00:43:27 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:43:27 +0000 (GMT) Message-ID: <3b7f3ec660db031e84306e8d9c4917bc737a58d3.camel@linux.ibm.com> Subject: [PATCH 14/16] crypto/nx: Register and unregister VAS interface From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@linux.ibm.com Date: Sat, 10 Apr 2021 17:43:25 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 1Dw12ly6c1NSlDAe-M7Tf8CAT9icFqZM X-Proofpoint-GUID: z-G48494KOVBjcfzYMdSNn-vAPP6dL1y X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 bulkscore=0 clxscore=1015 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Changes to create /dev/crypto/nx-gzip interface with VAS register and to remove this interface with VAS unregister. Signed-off-by: Haren Myneni Reported-by: kernel test robot --- drivers/crypto/nx/nx-common-pseries.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/crypto/nx/nx-common-pseries.c b/drivers/crypto/nx/nx-common-pseries.c index cc8dd3072b8b..9a40fca8a9e6 100644 --- a/drivers/crypto/nx/nx-common-pseries.c +++ b/drivers/crypto/nx/nx-common-pseries.c @@ -9,6 +9,7 @@ */ #include +#include #include "nx-842.h" #include "nx_csbcpb.h" /* struct nx_csbcpb */ @@ -1101,6 +1102,12 @@ static int __init nx842_pseries_init(void) return ret; } + ret = vas_register_api_pseries(THIS_MODULE, VAS_COP_TYPE_GZIP, + "nx-gzip"); + + if (ret) + pr_err("NX-GZIP is not supported. Returned=%d\n", ret); + return 0; } @@ -1111,6 +1118,8 @@ static void __exit nx842_pseries_exit(void) struct nx842_devdata *old_devdata; unsigned long flags; + vas_unregister_api_pseries(); + crypto_unregister_alg(&nx842_pseries_alg); spin_lock_irqsave(&devdata_mutex, flags); From patchwork Sun Apr 11 00:44:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12196001 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF230C433B4 for ; Sun, 11 Apr 2021 00:44:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF07F610E5 for ; Sun, 11 Apr 2021 00:44:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234926AbhDKAog (ORCPT ); Sat, 10 Apr 2021 20:44:36 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39652 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234751AbhDKAof (ORCPT ); Sat, 10 Apr 2021 20:44:35 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0XiNP075040; Sat, 10 Apr 2021 20:44:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=pxeHkQP1kmn1yXzALIc5qkqciwnKnZqng2FUwOgZiXs=; b=CaO67Q6IM9Zq7XnbgDJjkR8/a19JkWMYLtLTiHFcjmm8mibQ/HtY7JOyBedDfColD6pY ksOfSXVB6Sw87UrFRnddE2G0EklaaqQNXZq2aXSfPXuxXSpz/Q9KU6rCudiU42DeeMxD wu7Ve5F8cbSA6txxc9Oc+In7Nfsbu88SZBUFsLSRjtPAwsudblJgRmP2qLl6adr9X+Fb Pj9Q1l68BLU7ff3EzSOIX6Al4raarM8u2oMAw5POpauGgPmmOKryE2ciWEruzveSfQg7 iMIn1io6mAb6lbxLny4F3obEhLNdwDUz8lRPGOBdCYtSpWlrj999ZKas3ZNCEl7cZEyU zA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u6b9p3ae-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:44:14 -0400 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0hYjM096849; Sat, 10 Apr 2021 20:44:14 -0400 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 37u6b9p3a5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:44:14 -0400 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0RmPP018044; Sun, 11 Apr 2021 00:44:13 GMT Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by ppma04wdc.us.ibm.com with ESMTP id 37u3n9d5ru-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:44:13 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0iC2A15204620 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:44:13 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E6D37AE05F; Sun, 11 Apr 2021 00:44:12 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E3E4EAE05C; Sun, 11 Apr 2021 00:44:11 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:44:11 +0000 (GMT) Message-ID: <27f6fef4852a3fdbb36c3a35a357a0082c581be5.camel@linux.ibm.com> Subject: [PATCH 15/16] crypto/nx: Get NX capabilities for GZIP coprocessor type From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@linux.ibm.com Date: Sat, 10 Apr 2021 17:44:10 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: VTB9xOkpTjFLMZ_Le3L4BtVqR0JfYe9h X-Proofpoint-GUID: 1w1b0fIZiSNcSEkOO3j3J635KZQNbsE2 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 mlxscore=0 adultscore=0 spamscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org phyp provides NX capabilities which gives recommended minimum compression / decompression length and maximum request buffer size in bytes. Changes to get NX overall capabilities which points to the specific features phyp supports. Then retrieve NXGZIP specific capabilities. Signed-off-by: Haren Myneni Reported-by: kernel test robot --- drivers/crypto/nx/nx-common-pseries.c | 83 +++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/drivers/crypto/nx/nx-common-pseries.c b/drivers/crypto/nx/nx-common-pseries.c index 9a40fca8a9e6..49224870d05e 100644 --- a/drivers/crypto/nx/nx-common-pseries.c +++ b/drivers/crypto/nx/nx-common-pseries.c @@ -9,6 +9,7 @@ */ #include +#include #include #include "nx-842.h" @@ -20,6 +21,24 @@ MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors"); MODULE_ALIAS_CRYPTO("842"); MODULE_ALIAS_CRYPTO("842-nx"); +struct nx_ct_capabs_be { + __be64 descriptor; + __be64 req_max_processed_len; /* Max bytes in one GZIP request */ + __be64 min_compress_len; /* Min compression size in bytes */ + __be64 min_decompress_len; /* Min decompression size in bytes */ +} __packed __aligned(0x1000); + +struct nx_ct_capabs { + char name[VAS_DESCR_LEN + 1]; + u64 descriptor; + u64 req_max_processed_len; /* Max bytes in one GZIP request */ + u64 min_compress_len; /* Min compression in bytes */ + u64 min_decompress_len; /* Min decompression in bytes */ +}; + +u64 capab_feat = 0; +struct nx_ct_capabs nx_ct_capab; + static struct nx842_constraints nx842_pseries_constraints = { .alignment = DDE_BUFFER_ALIGN, .multiple = DDE_BUFFER_LAST_MULT, @@ -1066,6 +1085,66 @@ static void nx842_remove(struct vio_dev *viodev) kfree(old_devdata); } +/* + * Get NX capabilities from pHyp. + * Only NXGZIP capabilities are available right now and these values + * are available through sysfs. + */ +static void __init nxct_get_capabilities(void) +{ + struct vas_all_capabs_be *capabs_be; + struct nx_ct_capabs_be *nxc_be; + int rc; + + capabs_be = kmalloc(sizeof(*capabs_be), GFP_KERNEL); + if (!capabs_be) + return; + /* + * Get NX overall capabilities with feature type=0 + */ + rc = plpar_vas_query_capabilities(H_QUERY_NX_CAPABILITIES, 0, + (u64)virt_to_phys(capabs_be)); + if (rc) + goto out; + + capab_feat = be64_to_cpu(capabs_be->feat_type); + /* + * NX-GZIP feature available + */ + if (capab_feat & VAS_NX_GZIP_FEAT_BIT) { + nxc_be = kmalloc(sizeof(*nxc_be), GFP_KERNEL); + if (!nxc_be) + goto out; + /* + * Get capabilities for NX-GZIP feature + */ + rc = plpar_vas_query_capabilities(H_QUERY_NX_CAPABILITIES, + VAS_NX_GZIP_FEAT, + (u64)virt_to_phys(nxc_be)); + } else { + pr_err("NX-GZIP feature is not available\n"); + rc = -EINVAL; + } + + if (!rc) { + snprintf(nx_ct_capab.name, VAS_DESCR_LEN + 1, "%.8s", + (char *)&nxc_be->descriptor); + nx_ct_capab.descriptor = be64_to_cpu(nxc_be->descriptor); + nx_ct_capab.req_max_processed_len = + be64_to_cpu(nxc_be->req_max_processed_len); + nx_ct_capab.min_compress_len = + be64_to_cpu(nxc_be->min_compress_len); + nx_ct_capab.min_decompress_len = + be64_to_cpu(nxc_be->min_decompress_len); + } else { + capab_feat = 0; + } + + kfree(nxc_be); +out: + kfree(capabs_be); +} + static const struct vio_device_id nx842_vio_driver_ids[] = { {"ibm,compression-v1", "ibm,compression"}, {"", ""}, @@ -1093,6 +1172,10 @@ static int __init nx842_pseries_init(void) return -ENOMEM; RCU_INIT_POINTER(devdata, new_devdata); + /* + * Get NX capabilities from pHyp which is used for NX-GZIP. + */ + nxct_get_capabilities(); ret = vio_register_driver(&nx842_vio_driver); if (ret) { From patchwork Sun Apr 11 00:45:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 12196003 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29C0BC433ED for ; Sun, 11 Apr 2021 00:45:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F088F61074 for ; Sun, 11 Apr 2021 00:45:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234751AbhDKAqC (ORCPT ); Sat, 10 Apr 2021 20:46:02 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:5844 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbhDKAqC (ORCPT ); Sat, 10 Apr 2021 20:46:02 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13B0Y4HJ032497; Sat, 10 Apr 2021 20:45:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=QtHIP9dLzxxRRuIHGRlAtB+wH86pg3rz8isJQCt4K5Q=; b=A32Qa+f6fSISPH/P+m1hQ+XPGSlnPiMw3ALzEVxaK+KHr8db4ItnXV1pezN0aW3LGffa TYGGtR08fG+SXDPSJxtIbExvTQSahGbOCbKk7bJvOXTTCE8+cOOEzzkh9p/Pwd62WT7o zrwS6U1DhBlu66cM3FLkykrjhhSv4J5E1GeplP79bQ/ZZ62iRK9prpRaW7wLYGqebHdY OJ5vmOc0NSf7C0JtPEfV86BqdKNQhKJKXR7O+iBsRNqh6gWu4NyQ4TIFL15u5Lwa8jvm AFgEkKuO19sjNVuhGL6eGB/FaPZMwpAc3j/pAg9K8ZRrx44xnDxi8Y1fnrnMCLsPMAK9 6Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37up2j8keq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:45:41 -0400 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13B0Z09O033945; Sat, 10 Apr 2021 20:45:40 -0400 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 37up2j8kef-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 10 Apr 2021 20:45:40 -0400 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13B0RX2E021504; Sun, 11 Apr 2021 00:45:39 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma01dal.us.ibm.com with ESMTP id 37u3n8peqm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 11 Apr 2021 00:45:39 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13B0jcox32899476 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 11 Apr 2021 00:45:38 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 270D1C6057; Sun, 11 Apr 2021 00:45:38 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D039EC6055; Sun, 11 Apr 2021 00:45:36 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Sun, 11 Apr 2021 00:45:36 +0000 (GMT) Message-ID: <4413800e55c1cace3aca3fa51951d6e9063b0557.camel@linux.ibm.com> Subject: [PATCH 16/16] crypto/nx: sysfs interface to export NX capabilities From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com, haren@linux.ibm.com Date: Sat, 10 Apr 2021 17:45:34 -0700 In-Reply-To: References: User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ThpkibqJT0RHCRmTgjTECuawM8Ti8FUH X-Proofpoint-ORIG-GUID: 3QvTU31jUylsQNiWxq0gow7GMvOB29CQ X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-10_07:2021-04-09,2021-04-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 malwarescore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104110000 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Changes to export the following NXGZIP capabilities through sysfs: /sys/devices/vio/ibm,compression-v1/NxGzCaps: min_compress_len /*Recommended minimum compress length in bytes*/ min_decompress_len /*Recommended minimum decompress length in bytes*/ req_max_processed_len /* Maximum number of bytes processed in one request */ Signed-off-by: Haren Myneni --- drivers/crypto/nx/nx-common-pseries.c | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/crypto/nx/nx-common-pseries.c b/drivers/crypto/nx/nx-common-pseries.c index 49224870d05e..cc258d2c6475 100644 --- a/drivers/crypto/nx/nx-common-pseries.c +++ b/drivers/crypto/nx/nx-common-pseries.c @@ -962,6 +962,36 @@ static struct attribute_group nx842_attribute_group = { .attrs = nx842_sysfs_entries, }; +#define nxct_capab_read(_name) \ +static ssize_t nxct_##_name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + return sprintf(buf, "%lld\n", nx_ct_capab._name); \ +} + +#define NXCT_ATTR_RO(_name) \ + nxct_capab_read(_name); \ + static struct device_attribute dev_attr_##_name = __ATTR(_name, \ + 0444, \ + nxct_##_name##_show, \ + NULL); + +NXCT_ATTR_RO(req_max_processed_len); +NXCT_ATTR_RO(min_compress_len); +NXCT_ATTR_RO(min_decompress_len); + +static struct attribute *nxct_capab_sysfs_entries[] = { + &dev_attr_req_max_processed_len.attr, + &dev_attr_min_compress_len.attr, + &dev_attr_min_decompress_len.attr, + NULL, +}; + +static struct attribute_group nxct_capab_attr_group = { + .name = nx_ct_capab.name, + .attrs = nxct_capab_sysfs_entries, +}; + static struct nx842_driver nx842_pseries_driver = { .name = KBUILD_MODNAME, .owner = THIS_MODULE, @@ -1051,6 +1081,16 @@ static int nx842_probe(struct vio_dev *viodev, goto error; } + if (capab_feat) { + if (sysfs_create_group(&viodev->dev.kobj, + &nxct_capab_attr_group)) { + dev_err(&viodev->dev, + "Could not create sysfs NX capability entries\n"); + ret = -1; + goto error; + } + } + return 0; error_unlock: @@ -1070,6 +1110,9 @@ static void nx842_remove(struct vio_dev *viodev) pr_info("Removing IBM Power 842 compression device\n"); sysfs_remove_group(&viodev->dev.kobj, &nx842_attribute_group); + if (capab_feat) + sysfs_remove_group(&viodev->dev.kobj, &nxct_capab_attr_group); + crypto_unregister_alg(&nx842_pseries_alg); spin_lock_irqsave(&devdata_mutex, flags);