Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4295413yba; Wed, 17 Apr 2019 08:34:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqx46y/D0PGOOG2thrU5e7jVUsVnvp6cTCHVKUDBjVdOSmtBTxJKliHlOuqbF3tY7PrvRxtt X-Received: by 2002:a17:902:7885:: with SMTP id q5mr90992502pll.12.1555515274200; Wed, 17 Apr 2019 08:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555515274; cv=none; d=google.com; s=arc-20160816; b=s17SpUsSIF2/kwT4kbNsDraKBJEUmaMuYsmrPySBIGBC7g/TiEi0Wn9LIBYZY17FBG 1AueD8IofrxuFZ1DldVR05elHgf2tRk1/f176wfXWJCPzqszAwqAUemYceOt+bFBW9cn za1S85iPfSuvrbbwEFNS9SftTuGabnREmOuvoGpxkPMUIS2l4537l9cvToBPRpaoBg8J w4LbTNB8WtQAjQu3pl1eUI++FBwB04m3NUZIaW8nrjlcsyleywf5L33tVdD2nJuq3nEG Voz2ZieXtEqtbhLcWOObIhg+W4Mxj+MSsJpdMa2Czlvf9LIWFBWOhj6+WarLAx8hdFuL 1p2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject; bh=ZWNYUiomf7p/FsXrB0l7pFcXSd/EFZkDrwp1YsuLfUk=; b=sefpkuhZjgNdGgnex12TVfIwFeeU78k7sMSG109kbObcwf1GEHIXofBlJMzAitRfiV 99oT7XbUSHvdQxPvwYTvfJXA7j7auV5WB9p1EsmjoQDBoGL31qOc+9q6uN+0rs7fsMhZ /vlZlqJh2xO4QsYHZhBvStluna8UcY3Ij8x94EpNZzL102xc86ftOKX+X/5ONbwgmw+6 VlNTGhfp9YMKAxFiL+1qLInqN7VYjmB8AXdESzCXujX9uZ1ZUcwXm9c3mMy0zkw/qDvU QwQ+35MEM2E8c6JHc4vuyI+5etQAMEy7+bXMLnOVVi+oBU5TTolyKVseWrfuYHp3HH2W Nv7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si39778538pfd.105.2019.04.17.08.34.19; Wed, 17 Apr 2019 08:34:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732670AbfDQPd1 (ORCPT + 99 others); Wed, 17 Apr 2019 11:33:27 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:35984 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729940AbfDQPd0 (ORCPT ); Wed, 17 Apr 2019 11:33:26 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3HFW6pQ056568 for ; Wed, 17 Apr 2019 11:33:24 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 2rx4qne84w-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 17 Apr 2019 11:33:23 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 17 Apr 2019 16:33:22 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 17 Apr 2019 16:33:18 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x3HFXHWs52166758 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2019 15:33:17 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0408D4204D; Wed, 17 Apr 2019 15:33:17 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 971F342042; Wed, 17 Apr 2019 15:33:16 +0000 (GMT) Received: from [9.145.35.200] (unknown [9.145.35.200]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 17 Apr 2019 15:33:16 +0000 (GMT) Subject: Re: [PATCH v4 4/7] ocxl: Allow external drivers to use OpenCAPI contexts To: "Alastair D'Silva" , alastair@d-silva.org Cc: Greg Kurz , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <20190327053137.15173-1-alastair@au1.ibm.com> <20190327053137.15173-5-alastair@au1.ibm.com> From: Frederic Barrat Date: Wed, 17 Apr 2019 17:33:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190327053137.15173-5-alastair@au1.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19041715-0028-0000-0000-00000361E7E7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19041715-0029-0000-0000-0000242124D0 Message-Id: <88e125bf-d499-f31f-628a-f611a84b5509@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-17_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904170104 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 27/03/2019 à 06:31, Alastair D'Silva a écrit : > From: Alastair D'Silva > > Most OpenCAPI operations require a valid context, so > exposing these functions to external drivers is necessary. > > Signed-off-by: Alastair D'Silva > Reviewed-by: Greg Kurz > --- There's a small memory leak in here on context alloc, if we can't get a pasid from the IDR. But that's not new to this patch, I just saw it because the code was moved around. And since that's the only thing I've seen in the full series and it's super long to review, I'll address it with a later patch. So: Acked-by: Frederic Barrat > drivers/misc/ocxl/context.c | 22 ++++++++++------- > drivers/misc/ocxl/file.c | 8 ++----- > drivers/misc/ocxl/ocxl_internal.h | 6 ----- > include/misc/ocxl.h | 39 +++++++++++++++++++++++++++++++ > 4 files changed, 55 insertions(+), 20 deletions(-) > > diff --git a/drivers/misc/ocxl/context.c b/drivers/misc/ocxl/context.c > index c73a859d2224..b60e674ac019 100644 > --- a/drivers/misc/ocxl/context.c > +++ b/drivers/misc/ocxl/context.c > @@ -4,15 +4,17 @@ > #include "trace.h" > #include "ocxl_internal.h" > > -struct ocxl_context *ocxl_context_alloc(void) > -{ > - return kzalloc(sizeof(struct ocxl_context), GFP_KERNEL); > -} > - > -int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu, > +int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu, > struct address_space *mapping) > { > int pasid; > + struct ocxl_context *ctx; > + > + *context = kzalloc(sizeof(struct ocxl_context), GFP_KERNEL); > + if (!*context) > + return -ENOMEM; > + > + ctx = *context; > > ctx->afu = afu; > mutex_lock(&afu->contexts_lock); > @@ -43,6 +45,7 @@ int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu, > ocxl_afu_get(afu); > return 0; > } > +EXPORT_SYMBOL_GPL(ocxl_context_alloc); > > /* > * Callback for when a translation fault triggers an error > @@ -63,7 +66,7 @@ static void xsl_fault_error(void *data, u64 addr, u64 dsisr) > wake_up_all(&ctx->events_wq); > } > > -int ocxl_context_attach(struct ocxl_context *ctx, u64 amr) > +int ocxl_context_attach(struct ocxl_context *ctx, u64 amr, struct mm_struct *mm) > { > int rc; > > @@ -75,7 +78,7 @@ int ocxl_context_attach(struct ocxl_context *ctx, u64 amr) > } > > rc = ocxl_link_add_pe(ctx->afu->fn->link, ctx->pasid, > - current->mm->context.id, ctx->tidr, amr, current->mm, > + mm->context.id, ctx->tidr, amr, mm, > xsl_fault_error, ctx); > if (rc) > goto out; > @@ -85,6 +88,7 @@ int ocxl_context_attach(struct ocxl_context *ctx, u64 amr) > mutex_unlock(&ctx->status_mutex); > return rc; > } > +EXPORT_SYMBOL_GPL(ocxl_context_attach); > > static vm_fault_t map_afu_irq(struct vm_area_struct *vma, unsigned long address, > u64 offset, struct ocxl_context *ctx) > @@ -243,6 +247,7 @@ int ocxl_context_detach(struct ocxl_context *ctx) > } > return 0; > } > +EXPORT_SYMBOL_GPL(ocxl_context_detach); > > void ocxl_context_detach_all(struct ocxl_afu *afu) > { > @@ -280,3 +285,4 @@ void ocxl_context_free(struct ocxl_context *ctx) > ocxl_afu_put(ctx->afu); > kfree(ctx); > } > +EXPORT_SYMBOL_GPL(ocxl_context_free); > diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c > index 7a38ea5af9db..8225892a5d77 100644 > --- a/drivers/misc/ocxl/file.c > +++ b/drivers/misc/ocxl/file.c > @@ -61,11 +61,7 @@ static int afu_open(struct inode *inode, struct file *file) > if (!info) > return -ENODEV; > > - ctx = ocxl_context_alloc(); > - if (!ctx) > - return -ENOMEM; > - > - rc = ocxl_context_init(ctx, info->afu, inode->i_mapping); > + rc = ocxl_context_alloc(&ctx, info->afu, inode->i_mapping); > if (rc) > return rc; > > @@ -90,7 +86,7 @@ static long afu_ioctl_attach(struct ocxl_context *ctx, > return -EINVAL; > > amr = arg.amr & mfspr(SPRN_UAMOR); > - rc = ocxl_context_attach(ctx, amr); > + rc = ocxl_context_attach(ctx, amr, current->mm); > return rc; > } > > diff --git a/drivers/misc/ocxl/ocxl_internal.h b/drivers/misc/ocxl/ocxl_internal.h > index 53b6c64a1bf0..de6c16237742 100644 > --- a/drivers/misc/ocxl/ocxl_internal.h > +++ b/drivers/misc/ocxl/ocxl_internal.h > @@ -130,15 +130,9 @@ int ocxl_config_check_afu_index(struct pci_dev *dev, > */ > int ocxl_link_update_pe(void *link_handle, int pasid, __u16 tid); > > -struct ocxl_context *ocxl_context_alloc(void); > -int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu, > - struct address_space *mapping); > -int ocxl_context_attach(struct ocxl_context *ctx, u64 amr); > int ocxl_context_mmap(struct ocxl_context *ctx, > struct vm_area_struct *vma); > -int ocxl_context_detach(struct ocxl_context *ctx); > void ocxl_context_detach_all(struct ocxl_afu *afu); > -void ocxl_context_free(struct ocxl_context *ctx); > > int ocxl_sysfs_register_afu(struct ocxl_file_info *info); > void ocxl_sysfs_unregister_afu(struct ocxl_file_info *info); > diff --git a/include/misc/ocxl.h b/include/misc/ocxl.h > index 8bafd748e380..e4704632eac5 100644 > --- a/include/misc/ocxl.h > +++ b/include/misc/ocxl.h > @@ -48,6 +48,7 @@ struct ocxl_fn_config { > // These are opaque outside the ocxl driver > struct ocxl_afu; > struct ocxl_fn; > +struct ocxl_context; > > // Device detection & initialisation > > @@ -116,6 +117,44 @@ const struct ocxl_fn_config *ocxl_function_config(struct ocxl_fn *fn); > */ > void ocxl_function_close(struct ocxl_fn *fn); > > +// Context allocation > + > +/** > + * Allocate an OpenCAPI context > + * > + * @context: The OpenCAPI context to allocate, must be freed with ocxl_context_free > + * @afu: The AFU the context belongs to > + * @mapping: The mapping to unmap when the context is closed (may be NULL) > + */ > +int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu, > + struct address_space *mapping); > + > +/** > + * Free an OpenCAPI context > + * > + * @ctx: The OpenCAPI context to free > + */ > +void ocxl_context_free(struct ocxl_context *ctx); > + > +/** > + * Grant access to an MM to an OpenCAPI context > + * @ctx: The OpenCAPI context to attach > + * @amr: The value of the AMR register to restrict access > + * @mm: The mm to attach to the context > + * > + * Returns 0 on success, negative on failure > + */ > +int ocxl_context_attach(struct ocxl_context *ctx, u64 amr, > + struct mm_struct *mm); > + > +/** > + * Detach an MM from an OpenCAPI context > + * @ctx: The OpenCAPI context to attach > + * > + * Returns 0 on success, negative on failure > + */ > +int ocxl_context_detach(struct ocxl_context *ctx); > + > // AFU Metadata > > /** >