Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3200790imc; Wed, 13 Mar 2019 11:21:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwK+MQPScIIkmGQgMQCUDL6f2EbnuQ2zqR9CvenUAyZzY4rH2Fv4uJEDLUwsP5XzRKFHPJj X-Received: by 2002:a17:902:5ac9:: with SMTP id g9mr47532258plm.205.1552501319444; Wed, 13 Mar 2019 11:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552501319; cv=none; d=google.com; s=arc-20160816; b=UQgo2LBASaryCZE2xa632VCuQwOSHaf+U/PldoZmIUJV2bA3TfFYM4rf0hz02739c+ 95oL0g5N4eBWSr+rWx2P4q+bLq0PZMGz89USnBupCT8Lcz4jprLx/UXfm7ZbsDLH6ajV IjHKeSvD0XQ7t8gUtQ38oNNzl3sHH/Ay1Nyqhw1vpVppcM1IiS4lEj0OvKevq7RoSDEv ZhoB891MUzInCWN/WOs9hMrmiJiJ6SZAO5wFYFD5F9eGkycGGpgRZcVbgUOtTKmUZ4Ow nD6LJ8eodZZvH0i4kwYISCZTNM79k+5BKR5gt2imaBCUanJBI30cbIonI4fJ1s8ItEHa pVtg== 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=ldIUQXvu9x3N4ZzfMDyV00auiN+HGhiMZfTvvrwVI3E=; b=PTsiFn2Pit/6Z1jaQBRfWyRMPejzmMQ+s/XpelPCfrAxtUU5Qbh21qeAASBYyCz2C5 vYcb6eixxLAVjv7jJJHeOwjENBOa8QHSoTJS8buDx/OSxLZDBaIeCrdBhMeCrO1XwuLK mYUMLXW+xz0Wk5xcd6EZoI2wBYCxLwogj4JQu7MZpdR5uTs6Mo4Ji8HSps47y8xv8r06 C4q2Yyv6cXLeSfdMiM7V/lE56iHUnhq9HpCmaNsScMIY69ydFRseuBjt5pIYhIhjo8KY jt83elVxRwpnV/WcgT3UkqVQ+eXBgFgiRGfb3PMfjLOkAfuJiJbQLrmsUP7O4xfHSSEU tuPQ== 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 j7si11832160plb.349.2019.03.13.11.21.42; Wed, 13 Mar 2019 11:21:59 -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 S1726746AbfCMSVD (ORCPT + 99 others); Wed, 13 Mar 2019 14:21:03 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:35694 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726411AbfCMSVC (ORCPT ); Wed, 13 Mar 2019 14:21:02 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2DICqcc064189 for ; Wed, 13 Mar 2019 14:21:01 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2r749agakt-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 13 Mar 2019 14:20:59 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 13 Mar 2019 18:20:49 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 13 Mar 2019 18:20:46 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x2DIKj8131916208 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Mar 2019 18:20:45 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B69FA405C; Wed, 13 Mar 2019 18:20:45 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA844A4054; Wed, 13 Mar 2019 18:20:44 +0000 (GMT) Received: from [9.145.182.34] (unknown [9.145.182.34]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 13 Mar 2019 18:20:44 +0000 (GMT) Subject: Re: [PATCH 2/7] ocxl: Allow external drivers to use OpenCAPI contexts To: "Alastair D'Silva" Cc: "Alastair D'Silva" , Greg Kurz , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <20190313041524.14644-1-alastair@au1.ibm.com> <20190313041524.14644-3-alastair@au1.ibm.com> From: Frederic Barrat Date: Wed, 13 Mar 2019 19:20:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190313041524.14644-3-alastair@au1.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19031318-4275-0000-0000-0000031A9469 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19031318-4276-0000-0000-00003829041D Message-Id: <35bec389-2b70-96cb-c5f5-443bf902c9cd@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-13_11:,, 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=644 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903130126 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 13/03/2019 à 05:15, 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 > --- Patch could also be moved later in the series (same reason as before), but: Acked-by: Frederic Barrat > drivers/misc/ocxl/context.c | 9 +++++-- > drivers/misc/ocxl/file.c | 2 +- > drivers/misc/ocxl/ocxl_internal.h | 6 ----- > include/misc/ocxl.h | 44 +++++++++++++++++++++++++++++++ > 4 files changed, 52 insertions(+), 9 deletions(-) > > diff --git a/drivers/misc/ocxl/context.c b/drivers/misc/ocxl/context.c > index 3498a0199bde..1534b56f1db1 100644 > --- a/drivers/misc/ocxl/context.c > +++ b/drivers/misc/ocxl/context.c > @@ -8,6 +8,7 @@ struct ocxl_context *ocxl_context_alloc(void) > { > return kzalloc(sizeof(struct ocxl_context), GFP_KERNEL); > } > +EXPORT_SYMBOL_GPL(ocxl_context_alloc); > > int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu, > struct address_space *mapping) > @@ -43,6 +44,7 @@ int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu, > ocxl_afu_get(afu); > return 0; > } > +EXPORT_SYMBOL_GPL(ocxl_context_init); > > /* > * Callback for when a translation fault triggers an error > @@ -63,7 +65,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 +77,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 +87,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 +246,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 +284,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 16eb8a60d5c7..865b3d176431 100644 > --- a/drivers/misc/ocxl/file.c > +++ b/drivers/misc/ocxl/file.c > @@ -100,7 +100,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 06fd98c989c8..779d15ef60b5 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_add_afu(struct ocxl_afu *afu); > void ocxl_sysfs_remove_afu(struct ocxl_afu *afu); > diff --git a/include/misc/ocxl.h b/include/misc/ocxl.h > index 3b320c39f0af..ebbfe83cd5a6 100644 > --- a/include/misc/ocxl.h > +++ b/include/misc/ocxl.h > @@ -51,6 +51,7 @@ struct ocxl_fn_config { > > // These are opaque outside the ocxl driver > struct ocxl_afu; > +struct ocxl_context; > > enum ocxl_endian { > OCXL_BIG_ENDIAN = 0, /**< AFU data is big-endian */ > @@ -58,6 +59,49 @@ enum ocxl_endian { > OCXL_HOST_ENDIAN = 2, /**< AFU data is the same endianness as the host */ > }; > > +/** > + * Allocate space for a new OpenCAPI context > + * > + * Returns NULL on failure > + */ > +struct ocxl_context *ocxl_context_alloc(void); > + > +/** > + * Initialize an OpenCAPI context > + * > + * @ctx: The OpenCAPI context to initialize > + * @afu: The AFU the context belongs to > + * @mapping: The mapping to unmap when the context is closed (may be NULL) > + */ > +int ocxl_context_init(struct ocxl_context *ctx, 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); > + > /** > * Read a 32 bit value from global MMIO > * >