From patchwork Tue Apr 13 08:19: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: 420307 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 18387C433ED for ; Tue, 13 Apr 2021 08:19:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA94061242 for ; Tue, 13 Apr 2021 08:19:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242685AbhDMITj (ORCPT ); Tue, 13 Apr 2021 04:19:39 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:4610 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241675AbhDMITi (ORCPT ); Tue, 13 Apr 2021 04:19:38 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13D83BFV093066; Tue, 13 Apr 2021 04:19: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=BpUOCiXkn3Lnaz7oK7kSbg4xQWKMOF02ZZA9A0eflHg=; b=DzZo1OiUJvFD8me5v+6URGntUw8b3bGX/E65B5vXeLOskM7ZSQnY7jnYR2HeNQhMlYo4 yBXp3ZPCh6baTw6YtrvYK9CgXzySg4IymbqArGYV+sVNWGvqDIDFiIRdrmlFSe0KJovW CY5EICRTuJ0CATPCCoN7S5zQcsTKj4DYXKIguQS9bKpU5UTG6D2qkXMA1V6vZD7uCXh7 G+ThNhi1aqRxVt4UEXxV6ksXNcsbwFAIX0vGBaJZHUged0vTdGBDVuS3x7Txyh4B4Va8 mis1AUQnpTUX3U1LckCay/gy0XL/p0pm/cX+fmm169cJtSr6Y6zQQin5VrLTyVLir1Q4 wA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37vujkek95-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:19:11 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13D83GZY093630; Tue, 13 Apr 2021 04:19:10 -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 37vujkek8p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:19:10 -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 13D81VBE026454; Tue, 13 Apr 2021 08:19:09 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma02wdc.us.ibm.com with ESMTP id 37u3n9q2wh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 08:19:09 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13D8J7Dx9830688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Apr 2021 08:19:07 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D415112063; Tue, 13 Apr 2021 08:19:07 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2EEEA112061; Tue, 13 Apr 2021 08:19:06 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 13 Apr 2021 08:19:05 +0000 (GMT) Message-ID: <647a08951fe5934ccb0cf35982e53ae36bd337fc.camel@linux.ibm.com> Subject: [V2 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: Tue, 13 Apr 2021 01:19:04 -0700 In-Reply-To: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> References: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: TyBg4dNui07rTMAD6C8XwOLNI8r8vOgw X-Proofpoint-ORIG-GUID: KpTinkOZUU2w83cyiJF1Wcq_FGzZN8aW X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-13_03:2021-04-13,2021-04-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 suspectscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104130055 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 Tue Apr 13 08:20:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 420306 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 D1403C433ED for ; Tue, 13 Apr 2021 08:20:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F70B6128E for ; Tue, 13 Apr 2021 08:20:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229610AbhDMIVK (ORCPT ); Tue, 13 Apr 2021 04:21:10 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:23896 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbhDMIVK (ORCPT ); Tue, 13 Apr 2021 04:21:10 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13D83DNU093202; Tue, 13 Apr 2021 04:20:45 -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=p9IsE/R9eJqWFOdIjpQZN/fTrOhN6HHEdYWHW0iamIkMM0pHCbUSaqvSxrseNhjdHVu6 ARNLxa2PvT8U3pKNjNrniUqrX/hY198Bu0Kdem5NzO583F2fGIwXXdsDIWxbleA3Ax/l XQvGpbEML4fJfESXTl7CKxlvDvSh5p4c0p5AEJDCxjgykPbDKo0JmVkbHXAJ2ExyINJ8 TUSfm87u3t0sp9E6GZWm+oOpRjfrnh1O4da4jHEIG6GfPxhR3fa60vlNquXNG4f0hlsk lnM/E+c+nm4iLZFkJHKMhrOZGePqBnrKvOH1axGpKZxGA1eYF9Duqx6JhBXVk+k5TUfS Yg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37vujkemmk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:20:45 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13D83PRp094522; Tue, 13 Apr 2021 04:20:45 -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 37vujkemky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:20:44 -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 13D7wCYM008058; Tue, 13 Apr 2021 08:20:44 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma02dal.us.ibm.com with ESMTP id 37u3n9mu93-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 08:20:44 +0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13D8Kh6C8586172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Apr 2021 08:20:43 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5F563124054; Tue, 13 Apr 2021 08:20:43 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B4C5124053; Tue, 13 Apr 2021 08:20:42 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 13 Apr 2021 08:20:41 +0000 (GMT) Message-ID: <562018e2e0c87fb3d0d5377176c0d34577a0c575.camel@linux.ibm.com> Subject: [V2 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@linux.ibm.com Date: Tue, 13 Apr 2021 01:20:40 -0700 In-Reply-To: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> References: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: mQ8TDPSyMGQ9yAyAkRKRI1-OWB-Br8d9 X-Proofpoint-ORIG-GUID: PvbkZQEo8Po3SPCfffIKsWKRGvAZQVMC X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-13_03:2021-04-13,2021-04-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=780 adultscore=0 mlxscore=0 phishscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 suspectscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104130055 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 Tue Apr 13 08:23:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 420305 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 40852C433ED for ; Tue, 13 Apr 2021 08:23:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24C8E61369 for ; Tue, 13 Apr 2021 08:23:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229564AbhDMIXl (ORCPT ); Tue, 13 Apr 2021 04:23:41 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:41332 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229446AbhDMIXk (ORCPT ); Tue, 13 Apr 2021 04:23:40 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13D83GO0158185; Tue, 13 Apr 2021 04:23:14 -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=eh85GiiQ4SL+15bDknHMDy4e2W3gro5gDQ6UMlKQ6O9nkhhmJN0JRcu5NCd3DDQrZ8LN ytJQ/8CinBJD4ulE0hcOgBbpy0v6g8tgRSKJ1qyaKcdUJc3ynpOnQHs9l1GlyVA/LSlo B9XAPJ31c/vm19Becxm9/JL+KPbAzR+WWAoT8MXw7cf/kgWDMWfb8voMDGxmS8QmFVF6 ZQ01J2jUbjBrx/UeqSl6QLTmB5Fmu0FXo786omSeiAU+YOTyupkD0m2QyOLtb5lPoVS/ TcaRw0IjM1qlA0DpJGLxYc3dG4aeav9NnAwT4XbyUcxYoHY40oCLqM77tn+bUaqQc7Sz Eg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vtnt0f8v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:23:13 -0400 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13D84QGh165293; Tue, 13 Apr 2021 04:23:13 -0400 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vtnt0f8f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:23:13 -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 13D8LxrV009864; Tue, 13 Apr 2021 08:23:12 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma03wdc.us.ibm.com with ESMTP id 37uhcmkc8f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 08:23:12 +0000 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13D8NB8B25624980 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Apr 2021 08:23:11 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D042D136053; Tue, 13 Apr 2021 08:23:11 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7B6B713604F; Tue, 13 Apr 2021 08:23:10 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 13 Apr 2021 08:23:10 +0000 (GMT) Message-ID: <5407f08a02231fd7f4b879c33ee508d3bcd44588.camel@linux.ibm.com> Subject: [V2 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 Date: Tue, 13 Apr 2021 01:23:08 -0700 In-Reply-To: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> References: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: jvJLYsnuuKnZ0RlodPeu1qwEEdXBiC25 X-Proofpoint-ORIG-GUID: _6Me2CsxFmfa0UOnR7wqV_snQrp0NrVO X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-13_03:2021-04-13,2021-04-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 mlxscore=0 impostorscore=0 clxscore=1015 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104130055 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 Tue Apr 13 08:24: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: 420304 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 A0653C433ED for ; Tue, 13 Apr 2021 08:24:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87EFD613A9 for ; Tue, 13 Apr 2021 08:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229573AbhDMIYy (ORCPT ); Tue, 13 Apr 2021 04:24:54 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:63060 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229446AbhDMIYx (ORCPT ); Tue, 13 Apr 2021 04:24:53 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13D83Mjr063515; Tue, 13 Apr 2021 04:24: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=xAabvqf+7v65N95vm6otfwdaGYBW7MTh6Z+fcF2lOwU=; b=BVJYS8QU4MVM7/SX5YU5Z0J0bV2QbwIwa/vcF923w7NIx31UuY/0maQ4YgaZTEzD1cFc 4iCtGhbWD0bc3HizE+5pf1mG9EC3LMbNU0IVpow7HKKDrr7E/YgFNzdnzeskDfSOwgWd 5cJK0H9xZ7OUmymAv4OaiJr9u6QlyBF5Q+9oEowxZutzNOdCRtpyqM38AfBz55yeGGRI Rvj7MzTKzw1qtui75E6yDBKzSdSfyz1FnhwEhrR58kbsFFelDr8NjJk2WV1BkdqZUe8K oWe89R6EOR6p637tCWoCLAyfCHyyQwRNgJHsaJyaCThHZTNymbNxCmGIMShoJ/wIQfRs YA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vtvy84se-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:24:23 -0400 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13D84mpZ068829; Tue, 13 Apr 2021 04:24:23 -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 37vtvy84ry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:24:23 -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 13D8MFOx028362; Tue, 13 Apr 2021 08:24:22 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma05wdc.us.ibm.com with ESMTP id 37u3n9q301-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 08:24:22 +0000 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13D8OLRY21561820 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Apr 2021 08:24:22 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9575136051; Tue, 13 Apr 2021 08:24:21 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9EC4413604F; Tue, 13 Apr 2021 08:24:20 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 13 Apr 2021 08:24:20 +0000 (GMT) Message-ID: <6d38f5eeb1661f613bc020c4e71b3ea33e87afa1.camel@linux.ibm.com> Subject: [V2 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 Date: Tue, 13 Apr 2021 01:24:18 -0700 In-Reply-To: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> References: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: DQ0iIL8ez2RDtJ7WA6rB16noJqk-RoSf X-Proofpoint-GUID: BQxwn9ahUtXEm5gjLD20a33l4OebmkkW X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-13_03:2021-04-13,2021-04-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 impostorscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 clxscore=1015 adultscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104130055 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 Tue Apr 13 08:25:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 420303 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 99BAAC433ED for ; Tue, 13 Apr 2021 08:25:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E0F361369 for ; Tue, 13 Apr 2021 08:25:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229590AbhDMI0H (ORCPT ); Tue, 13 Apr 2021 04:26:07 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:50052 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229379AbhDMI0G (ORCPT ); Tue, 13 Apr 2021 04:26:06 -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 13D83Kuc125641; Tue, 13 Apr 2021 04:25:39 -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=Ce/oQH9Ac0OvAMjazStzjczTFNXb9fCiQASfaVHuwsBUrYuMs2JNp9QewaWs54Ta60bN poPBRfzMq5I5sQORT9SQiU7WB8XfcdibcQ7/UAY4fbf03MbPNS3he86ulWdjYNy7Voml i8pZsUVoQ4Fgb8zpe1UIVVcWhMBxK+MwsGD8RDEob/uts4xgNjIOvtki187OTR58AW/u XpcwmNGlYwEwSmBC2pPL0J7K6Bzlq7f6QGQk+EH3SffmCzkCqCuH+hjUYydnf14J+eFA OZwTJMQCOqjqtS49gAlr7j1AdudOZmsMxkN17ekey6NBdumcwGGBZv+M/C5eOz3RTeei PQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vk4ja1uy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:25:39 -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 13D84dtD130502; Tue, 13 Apr 2021 04:25:39 -0400 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vk4ja1un-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:25:38 -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 13D8Mxg2012907; Tue, 13 Apr 2021 08:25:38 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma03dal.us.ibm.com with ESMTP id 37u3n94vu2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 08:25:38 +0000 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13D8PbFZ62783818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Apr 2021 08:25:37 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ED80F136055; Tue, 13 Apr 2021 08:25:36 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B49D0136053; Tue, 13 Apr 2021 08:25:35 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 13 Apr 2021 08:25:35 +0000 (GMT) Message-ID: <942d6399b4f5eda9c8a3b7b277fd9f33be39c7f7.camel@linux.ibm.com> Subject: [V2 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 Date: Tue, 13 Apr 2021 01:25:33 -0700 In-Reply-To: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> References: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Lt6qhSuOe6Iri5zUxmo9qZ8xnaq5WIJ4 X-Proofpoint-GUID: NvW3s52ZkZJ0shoawpM72T6ToCXgj0By X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-13_03:2021-04-13,2021-04-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 clxscore=1015 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104130055 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 Tue Apr 13 08:26:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 420302 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 281CEC433B4 for ; Tue, 13 Apr 2021 08:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 086FE613A9 for ; Tue, 13 Apr 2021 08:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229866AbhDMI12 (ORCPT ); Tue, 13 Apr 2021 04:27:28 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:32042 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229791AbhDMI11 (ORCPT ); Tue, 13 Apr 2021 04:27:27 -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 13D83Xc2172381; Tue, 13 Apr 2021 04:27:01 -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=NSIQ6EK6jluITHWtA0hSJd4eNkihfsnAu+6NxTfqxJavb/4vNilsL6ZViSsSEkTTVtqF 9xdzwei3D24qROLTkGYsSnRcSBtsfz/az9y2Jbw2Gt7Ypw689Xg0SjtNlTQQmtw31cHt 7pleFUoaYJe1uFIkxV2KniAG/J0jF8uBlHHjRRgpkE3tf+XXtVwR6wAnjnvncO9bU09v pCGVhrg+ssiOVY6PAD9jNMIdiX0lfz1Fwbsj2b3H8kFJq2ZjriZbcV0HrUmZFTeeQypQ z4eeVWt5E8939OdlJze1DtFshAZUtMBgBjjsEsnuJ87Ikvn0QILUnwsV66gvYaFWpDwv nQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vkd62f1f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:27:01 -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 13D83mCk173286; Tue, 13 Apr 2021 04:27:00 -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 37vkd62f17-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:27:00 -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 13D8NUjd018537; Tue, 13 Apr 2021 08:27:00 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 37u3n9q4a3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 08:27:00 +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 13D8Qx1t26411332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Apr 2021 08:26:59 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9CE90AE062; Tue, 13 Apr 2021 08:26:59 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9CBD3AE05F; Tue, 13 Apr 2021 08:26:58 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 13 Apr 2021 08:26:58 +0000 (GMT) Message-ID: <0b77b2646964a6fdabeaf33f22eeaa2ac7c25b91.camel@linux.ibm.com> Subject: [V2 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 Date: Tue, 13 Apr 2021 01:26:56 -0700 In-Reply-To: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> References: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: FOaVWz4fq9jvKJhqoIUqt2omx-9I6QQn X-Proofpoint-ORIG-GUID: l9eZ0wFmxYUiqs04NoKVl4HqyrPXc_p6 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-13_03:2021-04-13,2021-04-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 phishscore=0 spamscore=0 impostorscore=0 adultscore=0 clxscore=1015 malwarescore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104130055 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 Tue Apr 13 08:28:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 420301 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 E07B7C433ED for ; Tue, 13 Apr 2021 08:29:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA52C613B2 for ; Tue, 13 Apr 2021 08:29:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbhDMI3Z (ORCPT ); Tue, 13 Apr 2021 04:29:25 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37348 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243002AbhDMI3W (ORCPT ); Tue, 13 Apr 2021 04:29:22 -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 13D83dc6191500; Tue, 13 Apr 2021 04:28:57 -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=Sb8XFGKVB72fwAjD6uHz3wm2Cu7ChkiWVFgCYdMuzJ7sG5MWln9duN1Pa9qbS4c3VgsS kBTy+hBYf1ZTo8RySV/TCsUf85SrVoX0Y0MPrrZWFo++sVHeTDsvpHB31jjXQNqr4XTA SkP87i4IqPOMx+4nYAc2b8NEKMAcc1iPfIHPetpjWxgSfihmWLExpVXNs0Ol8pHorWQv OzTbedy0hqurRnI5FPoN6A8orrRp2EFYIFFc9q73sXVGBLgHnJng6HFVQmVDLXPJpHjR VZOLzp7PHrujlk48ZBRU3GL9qjuWwkLRkgvIG9L6tl3dLHrtdx7+FrzJfRpLoweg2qBt qw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37w6wm9w2m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:28:57 -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 13D84T5S194184; Tue, 13 Apr 2021 04:28:56 -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 37w6wm9w28-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:28:56 -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 13D8S5LK016045; Tue, 13 Apr 2021 08:28:55 GMT Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by ppma04dal.us.ibm.com with ESMTP id 37u3n8vwsa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 08:28:55 +0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13D8StK925362758 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Apr 2021 08:28:55 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0112A124054; Tue, 13 Apr 2021 08:28:55 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F0CF8124053; Tue, 13 Apr 2021 08:28:53 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 13 Apr 2021 08:28:53 +0000 (GMT) Message-ID: Subject: [V2 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 Date: Tue, 13 Apr 2021 01:28:52 -0700 In-Reply-To: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> References: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: FcRfx4-rUbEjyiLFvMkcUwOVNsBEZMVi X-Proofpoint-GUID: mUDOIhBOgevtbutXRvFQu1d_ygE_4Yz4 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-13_03:2021-04-13,2021-04-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1015 phishscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104130055 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 Tue Apr 13 08:30:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 420300 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 1BC9AC433B4 for ; Tue, 13 Apr 2021 08:30:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB7CA613CA for ; Tue, 13 Apr 2021 08:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229995AbhDMIal (ORCPT ); Tue, 13 Apr 2021 04:30:41 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:13650 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229963AbhDMIaj (ORCPT ); Tue, 13 Apr 2021 04:30:39 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13D83GIR158150; Tue, 13 Apr 2021 04:30:12 -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=g2/+WCm/dUqpUSGdxAl8vSFvm3276P/MWwdP4hvx+9qQttFhTXOdwXARVC2lPPzZtSwm v4DGkefPs5FWoy9RAj4GFoV7ehwNjd84BUUlR8Tm5AoR7VB/zPjgFa7hWjCRMkkZ0dOt EvX5Yup4ZevYbYjPHziZxGz0SR1qyCvL3Ocpr2vYmzjfV3MtxC5jUBeL+SsirXiytwK1 cL5g2UPo31egRpMLFHNJzfs3pVn06HBBWSEWRUKEG3s3pNZKmvtekF86weRqGfkRc4Nn sU/OfY3knxMMsflxPtAePRJ+rCOXIUvLvQN98NcKkudGQgpreF8ecqBUdbYhHi5owcRL gQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vtnt0nn5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:30:11 -0400 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13D8N4sC034347; Tue, 13 Apr 2021 04:30:11 -0400 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vtnt0nmj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:30:11 -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 13D8S3Bm021314; Tue, 13 Apr 2021 08:30:10 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma04wdc.us.ibm.com with ESMTP id 37u3n9y4kn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 08:30:10 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13D8UAvV32309620 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Apr 2021 08:30:10 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EB16CAC05B; Tue, 13 Apr 2021 08:30:09 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2687DAC060; Tue, 13 Apr 2021 08:30:09 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 13 Apr 2021 08:30:09 +0000 (GMT) Message-ID: <1bb10e6566b6984448489f93b89686c0bb1fbe7f.camel@linux.ibm.com> Subject: [V2 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 Date: Tue, 13 Apr 2021 01:30:07 -0700 In-Reply-To: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> References: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: IlFbmZQbgY6yoe2DirnUgsaknPzmyqEq X-Proofpoint-ORIG-GUID: hGEISsj94auK1NWnhbqUz0LWBOQCevz5 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-13_03:2021-04-13,2021-04-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 mlxscore=0 impostorscore=0 clxscore=1015 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104130055 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 --- 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) {