Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1653897pxp; Thu, 17 Mar 2022 13:42:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+OrgGiJ8/v4mrwwNhKOwBC4IvhqXrruIr+H5Q50lBpcylwTXA+nsDUnLICcLIdM3c/lzO X-Received: by 2002:a17:902:be14:b0:14f:ce67:d0a1 with SMTP id r20-20020a170902be1400b0014fce67d0a1mr6500897pls.29.1647549734279; Thu, 17 Mar 2022 13:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647549734; cv=none; d=google.com; s=arc-20160816; b=oh3KgPWNU8o9gdUp+qAp0blbyUmL6XPR/evUIx15T4Kv4eSUB+WXHoJGdcdpEPkBzx pOjAn0EhzJMWLpj/GYwpPrKK0rFrQ40YHyMzXzMGGELO8oxnDhYDmKy5LhxB8ANO5mQ9 dl+0fAAdFbF/QX1g5OcJ3dn2fT0fBIkUGAxQGBZd6VwTv7Yyq14oNue2zdk9p2vyYj5N BlEUUnTCKFRa1Y89PNAQMOcAjJx4NVtilNODghFPGV6JCKKlU9HZuHKxmnmJ58kC5Leh E5Ig3Ok+b3Noxb4M7nXhZTxyhTR7YYJtI6n6vVwnkNSUE00IXnaikQQhcRAxi70ZrJqR 2fNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=nQqbWtH5pfKnl7ntBQnMna6KGgKeLVbC9temYzdbrVk=; b=ZbBRgPXi2twzNyaP7rdZqK1YR0c1vL4mHu++b1ISk/gp6pyPlf5k4NJs7qI8mSYs44 mYAWD92prnFU9e/uI4MKnY1jZ1hgbNVn4MJFoLaKa3FA6MflilTQsuoS42EOq6Sc42lf prb9mNQb1kKhCOUZuoU6gBYvJggTs4IlFbCWs/L1MhHAnWD3yCESVtfWZc1uIX4OXqFC y69LRsguE1Judrjtu7ys2hoAa8LrgX9ptgNBprEpOrwbDInrCeX0DVfArgpXinIZaA7e KhR2zZGZKiAxRD1QoSHlnhB/1fQUmbtKbWb62z6nejy1VRrgDfkGNkhjQXZBbTuhnHGN B79g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jmPQuC0g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c5-20020a17090ad90500b001c69320a57esi1862330pjv.26.2022.03.17.13.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 13:42:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jmPQuC0g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 537542EBFBD; Thu, 17 Mar 2022 13:10:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235655AbiCQPO2 (ORCPT + 99 others); Thu, 17 Mar 2022 11:14:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbiCQPO1 (ORCPT ); Thu, 17 Mar 2022 11:14:27 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1431A1EC6D for ; Thu, 17 Mar 2022 08:13:11 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id r7so3296133wmq.2 for ; Thu, 17 Mar 2022 08:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=nQqbWtH5pfKnl7ntBQnMna6KGgKeLVbC9temYzdbrVk=; b=jmPQuC0gcd7cVIo3rSP/TX3nT+TeQj+v9JPsb3+HNkEXYNGVZawetow5Z2hnZIlwz1 enueRIfh+3xPAy+wyBjmg6HTmAnGRTS3UNFVvjEzNOFZlbbcZIWJYIMWNfrAAiV18x1u B04ZhhSUezK2Y6L6opNRDOzvXt3b8Zrp+G/nVdxhrldjtCvUcdT43gXRxBKtJSR6Fe2i 0GcLQmp/1a55cGSKTLClpOwxBvyHtdXqe31s0Zpm0GmUCGQejjSJnsXl49RplKJN086R l0NlPTW8n9kOxKEUG5tBfu09d3hlUdyDsWjb/QEQPNEZVY+TBbECzQplDjsvwgPZ2Zam APNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=nQqbWtH5pfKnl7ntBQnMna6KGgKeLVbC9temYzdbrVk=; b=ZcS2raHSSPCir01HdrxC2mP5V9hsWCJTUUVogoW4X2qufcgDgy4wRiAzLdUGqABNmc 7lgjXu0UUKB2laD1tXCSkBYEnvd94oZdheZ/9DddTA6WCO6eDyo+jZPUYa8gKQST91nj KLzDO+HZSyZ4EtB6qcnLFB/rBsYzTfA0+5p2jPo6wniC9rvwUffQCbCjy9MVVnP1/QpV cm/VVTh3Apl98WTwITfMhz/322EIh5aUcqQtnQXD5OQsLADHewPxocBT7GaKwjU0VDbC JjmzzUuIC7F1mqdGSa4e8agMxpCDZwCFtX5V9raOoUwvP77ZFbel5XgcLTfNwrgzTrWL 1Fbw== X-Gm-Message-State: AOAM530hwD1W1l7Brppo/94mwpU94Al9A3XKpd0ydGlvAIvouTsT1Nyu 1jiFRyz0Tl9/2VlwHGImtwjyXA== X-Received: by 2002:a05:600c:27d0:b0:38c:6c01:9668 with SMTP id l16-20020a05600c27d000b0038c6c019668mr8492847wmb.59.1647529989621; Thu, 17 Mar 2022 08:13:09 -0700 (PDT) Received: from google.com (cpc155339-bagu17-2-0-cust87.1-3.cable.virginm.net. [86.27.177.88]) by smtp.gmail.com with ESMTPSA id f7-20020a0560001a8700b00203c23e55e0sm4405777wry.78.2022.03.17.08.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 08:13:09 -0700 (PDT) Date: Thu, 17 Mar 2022 15:13:07 +0000 From: Lee Jones To: Felix Kuehling Cc: David Airlie , "Pan, Xinhui" , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, Alex Deucher , Christian =?iso-8859-1?Q?K=F6nig?= Subject: Re: [PATCH 1/1] drm/amdkfd: Protect the Client whilst it is being operated on Message-ID: References: <20220317131610.554347-1-lee.jones@linaro.org> <8702f8a5-62a1-c07e-c7b7-e9378be069b6@amd.com> <1f003356-3cf9-7237-501e-950d0aa124d1@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1f003356-3cf9-7237-501e-950d0aa124d1@amd.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 17 Mar 2022, Felix Kuehling wrote: > > Am 2022-03-17 um 11:00 schrieb Lee Jones: > > Good afternoon Felix, > > > > Thanks for your review. > > > > > Am 2022-03-17 um 09:16 schrieb Lee Jones: > > > > Presently the Client can be freed whilst still in use. > > > > > > > > Use the already provided lock to prevent this. > > > > > > > > Cc: Felix Kuehling > > > > Cc: Alex Deucher > > > > Cc: "Christian König" > > > > Cc: "Pan, Xinhui" > > > > Cc: David Airlie > > > > Cc: Daniel Vetter > > > > Cc: amd-gfx@lists.freedesktop.org > > > > Cc: dri-devel@lists.freedesktop.org > > > > Signed-off-by: Lee Jones > > > > --- > > > > drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 6 ++++++ > > > > 1 file changed, 6 insertions(+) > > > > > > > > diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c > > > > index e4beebb1c80a2..3b9ac1e87231f 100644 > > > > --- a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c > > > > +++ b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c > > > > @@ -145,8 +145,11 @@ static int kfd_smi_ev_release(struct inode *inode, struct file *filep) > > > > spin_unlock(&dev->smi_lock); > > > > synchronize_rcu(); > > > > + > > > > + spin_lock(&client->lock); > > > > kfifo_free(&client->fifo); > > > > kfree(client); > > > > + spin_unlock(&client->lock); > > > The spin_unlock is after the spinlock data structure has been freed. > > Good point. > > > > If we go forward with this approach the unlock should perhaps be moved > > to just before the kfree(). > > > > > There > > > should be no concurrent users here, since we are freeing the data structure. > > > If there still are concurrent users at this point, they will crash anyway. > > > So the locking is unnecessary. > > The users may well crash, as does the kernel unfortunately. > We only get to kfd_smi_ev_release when the file descriptor is closed. User > mode has no way to use the client any more at this point. This function also > removes the client from the dev->smi_cllients list. So no more events will > be added to the client. Therefore it is safe to free the client. > > If any of the above were not true, it would not be safe to kfree(client). > > But if it is safe to kfree(client), then there is no need for the locking. I'm not keen to go into too much detail until it's been patched. However, there is a way to free the client while it is still in use. Remember we are multi-threaded. -- Lee Jones [李琼斯] Principal Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog