From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 9E579C33CA2 for ; Thu, 9 Jan 2020 14:54:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6DCF820721 for ; Thu, 9 Jan 2020 14:54:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6DCF820721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 06FC48E001E; Thu, 9 Jan 2020 09:54:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F3A208E0017; Thu, 9 Jan 2020 09:54:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDAF58E001E; Thu, 9 Jan 2020 09:54:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id C4E718E0017 for ; Thu, 9 Jan 2020 09:54:49 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 87D08181AC9C6 for ; Thu, 9 Jan 2020 14:54:49 +0000 (UTC) X-FDA: 76358392698.24.bee41_643ea4b9bd44e X-HE-Tag: bee41_643ea4b9bd44e X-Filterd-Recvd-Size: 7447 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Thu, 9 Jan 2020 14:54:48 +0000 (UTC) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 009EqG3t171725 for ; Thu, 9 Jan 2020 09:54:48 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2xdvtax8qf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 09 Jan 2020 09:54:47 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 9 Jan 2020 14:54:45 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 9 Jan 2020 14:54:38 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 009EsaDt56557640 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 9 Jan 2020 14:54:36 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B693BA4055; Thu, 9 Jan 2020 14:54:36 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 99DAAA404D; Thu, 9 Jan 2020 14:54:35 +0000 (GMT) Received: from bali.tlslab.ibm.com (unknown [9.101.4.17]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 9 Jan 2020 14:54:35 +0000 (GMT) Subject: Re: [PATCH v2 09/27] ocxl: Free detached contexts in ocxl_context_detach_all() To: "Alastair D'Silva" , alastair@d-silva.org Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , Dan Williams , Vishal Verma , Dave Jiang , Keith Busch , Ira Weiny , Andrew Morton , Mauro Carvalho Chehab , "David S. Miller" , Rob Herring , Anton Blanchard , Krzysztof Kozlowski , Mahesh Salgaonkar , Madhavan Srinivasan , =?UTF-8?Q?C=c3=a9dric_Le_Goater?= , Anju T Sudhakar , Hari Bathini , Thomas Gleixner , Greg Kurz , Nicholas Piggin , Masahiro Yamada , Alexey Kardashevskiy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-nvdimm@lists.01.org, linux-mm@kvack.org References: <20191203034655.51561-1-alastair@au1.ibm.com> <20191203034655.51561-10-alastair@au1.ibm.com> From: Frederic Barrat Date: Thu, 9 Jan 2020 15:54:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191203034655.51561-10-alastair@au1.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 20010914-0012-0000-0000-0000037BF30D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20010914-0013-0000-0000-000021B814C0 Message-Id: <4c9da9a0-55f4-6cf4-53b8-e8a69744bf98@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-01-09_02:2020-01-09,2020-01-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=2 adultscore=0 priorityscore=1501 mlxlogscore=999 clxscore=1015 phishscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1910280000 definitions=main-2001090130 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Le 03/12/2019 =C3=A0 04:46, Alastair D'Silva a =C3=A9crit=C2=A0: > From: Alastair D'Silva >=20 > ocxl_context_detach_all() is called from ocxl_function_close(), so > there is no reason to leave the contexts allocated, as the caller > can do nothing useful with them at that point. >=20 > This also has the side-effect of freeing any allocated IRQs > within the context. >=20 > Signed-off-by: Alastair D'Silva > --- I think this is wrong and probably unneeded. In ocxl (and I would assume=20 most drivers), we separate pretty clearly what is setup by the driver=20 framework when a device is probed, and what is allocated by the users=20 (userland or scm). Contexts are allocated by the users. So they should=20 be freed by them only. That separation is also why we have some=20 reference counting on the afu and function structs, to make sure the=20 core data remains valid for as long as required. Though it's a bit asking for troubles, it can be seen when unbinding a=20 function from the driver through sysfs. That will end up calling=20 ocxl_function_close() and therefore ocxl_context_detach_all(). However=20 it's possible for a user process to still have a file descriptor opened.=20 The context is detached and marked as CLOSED, so any interaction with it=20 from the user will fail, but it should still be allocated so that it is=20 valid if the user process makes a system call to the driver. The context=20 will be freed when the file descriptor is closed. I don't think this is needed for scm either, since you've now added the=20 context detach and free call in free_scm() I would just drop this patch. Fred > drivers/misc/ocxl/context.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/misc/ocxl/context.c b/drivers/misc/ocxl/context.c > index 994563a078eb..6cb36ef96e09 100644 > --- a/drivers/misc/ocxl/context.c > +++ b/drivers/misc/ocxl/context.c > @@ -259,10 +259,11 @@ void ocxl_context_detach_all(struct ocxl_afu *afu= ) > { > struct ocxl_context *ctx; > int tmp; > + int rc; > =20 > mutex_lock(&afu->contexts_lock); > idr_for_each_entry(&afu->contexts_idr, ctx, tmp) { > - ocxl_context_detach(ctx); > + rc =3D ocxl_context_detach(ctx); > /* > * We are force detaching - remove any active mmio > * mappings so userspace cannot interfere with the > @@ -274,6 +275,9 @@ void ocxl_context_detach_all(struct ocxl_afu *afu) > if (ctx->mapping) > unmap_mapping_range(ctx->mapping, 0, 0, 1); > mutex_unlock(&ctx->mapping_lock); > + > + if (rc !=3D -EBUSY) > + ocxl_context_free(ctx); > } > mutex_unlock(&afu->contexts_lock); > } >=20