Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp217984rdb; Thu, 30 Nov 2023 03:02:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7Ys+XaDXnQBPnFWGbDZD8Tb9Arbb3QxfLgLINV7oSkXO9/sai5KmnB6NVqCqVbHgHHuph X-Received: by 2002:a05:6a20:1586:b0:17a:e981:7fe4 with SMTP id h6-20020a056a20158600b0017ae9817fe4mr36182162pzj.16.1701342162864; Thu, 30 Nov 2023 03:02:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701342162; cv=none; d=google.com; s=arc-20160816; b=O+707od5BZ7otA24zWInA2sFshCeuN0+m+hRFJ9oD94l8C9c4eXDziidP46FaYBvhZ Nl/VoOK5rHj47S8SEH0RTIU16tlyhzNK9swf3K9K3nf/0nu3KOFh6AR92TbydIUpiNZ9 +LdzREIxPek4LA6VR/sdjmTSqRQp+0XeQiXnQgfo09ndnfPzuf2mCiCUWQNDagOPvp3F KVA+j2c5rEj8Da/Vc+7isTaGGDTH0gg6GgRSwt8FrJmGqRxNLT0Ftdx2KCcge7xH4abF LD9mmCnHCpnYTKvkOqAg3/URcwE5e2uroEt6YefrE96CSq0X+3tkrXT7hj5qKi2jUDSj vy0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=gs6NL1JWCwPtc/Ynqu3SKEbqWqsJEPHoMd4M4nLVY50=; fh=mOqrdtzLxfRdhx+JUcCLIFZwj5ZpRA4B+MTwRGfrWMA=; b=EwHiAVy0tACct6HC9/enh0v+tem+3b/9kZyP7K8lRH1cyOLCv5aBevcj/JETvR7AcM PhXqjrsA7YDxa8ysSRdM74DdjiYA/3lnUUBy/AdxNr0oEFtKy17zfXP5weRO5RxsmOjj eVLy/y9uDuRofeyb4a+AQ8RRd6IodcrBzmCVAwxB7pGuNkO2xzitpHi9wP6ZP6H7dVys wyPfDeAYVeJ76K4aYt4/apkJ7wN6FyhfnmQSbVtlCA6PsgCIx63NYASwvMg2YTXhyjXT 0UtyuuILyJ+y/wQv9Vw9M83EwCD0hnpo+my8wOQ0UBxePaBI/BRU/ZWPk7x2LVsx4brC 3Tog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jStqfFGd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id g3-20020a63f403000000b005c2791fedb1si1042832pgi.874.2023.11.30.03.02.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 03:02:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jStqfFGd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id ED7E08025163; Thu, 30 Nov 2023 03:02:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235157AbjK3LCZ (ORCPT + 99 others); Thu, 30 Nov 2023 06:02:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231847AbjK3LCY (ORCPT ); Thu, 30 Nov 2023 06:02:24 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1051E10E5; Thu, 30 Nov 2023 03:02:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701342151; x=1732878151; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=c7oz0UEaAq0Ujr9AK7uExxzrAyiLZa8EboDA/OApfNE=; b=jStqfFGdclGLXaGE5aSnQKB6PFyxGjqPPTeIF0oBPTp0qnwDIb5nfL6T OPnh0myMfGXft6JndKG/L2fYGPqvLnZGh5F3qdvprBlfQz7omHVycpv4O yIzwG92DxKjZ93qFiJrACOIAbBVG75DJ4ePxEpuf3D/AaNe5zb7uOuBDf XzriP1SUzcR9Y6vLVUvhZ7qXkmFIROMHrErFeRtBaFdFyQ1LneMejgJxx 3hPK3BIVNIXihJY9eRCRs3WRgBPl2WBVOlCJwDexQKBi0RyC+EaQX260q 1LLr/fhjWgD8snNCGFHS0VmuHQxg8OA4cpA8E3rYHAdpZtLdI4GdrGClv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="392172392" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="392172392" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 03:02:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="745596790" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="745596790" Received: from bergler-mobl.ger.corp.intel.com ([10.249.33.30]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 03:02:27 -0800 Date: Thu, 30 Nov 2023 13:02:24 +0200 (EET) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: "David E. Box" cc: LKML , platform-driver-x86@vger.kernel.org, rajvi.jingar@linux.intel.com Subject: Re: [PATCH V6 01/20] platform/x86/intel/vsec: Fix xa_alloc memory leak In-Reply-To: <20231129222132.2331261-2-david.e.box@linux.intel.com> Message-ID: <5c21230-1176-4168-f31f-a0c1f1713ca8@linux.intel.com> References: <20231129222132.2331261-1-david.e.box@linux.intel.com> <20231129222132.2331261-2-david.e.box@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-2128018015-1701342149=:1808" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 30 Nov 2023 03:02:40 -0800 (PST) This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-2128018015-1701342149=:1808 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8BIT On Wed, 29 Nov 2023, David E. Box wrote: > Commit 936874b77dd0 ("platform/x86/intel/vsec: Add PCI error recovery > support to Intel PMT") added an xarray to track the list of vsec devices to > be recovered after a PCI error. But it did not provide cleanup for the list > leading to a memory leak that was caught by kmemleak. Do xa_alloc() before > devm_add_action_or_reset() so that the list may be cleaned up with > xa_erase() in the release function. > > Fixes: 936874b77dd0 ("platform/x86/intel/vsec: Add PCI error recovery support to Intel PMT") > Signed-off-by: David E. Box > --- > > V6 - Move xa_alloc() before ida_alloc() to reduce mutex use during error > recovery. > - Fix return value after id_alloc() fail > - Add Fixes tag > - Add more detail to changelog > > V5 - New patch > > drivers/platform/x86/intel/vsec.c | 24 ++++++++++++++---------- > drivers/platform/x86/intel/vsec.h | 1 + > 2 files changed, 15 insertions(+), 10 deletions(-) > > diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c > index c1f9e4471b28..2d568466b4e2 100644 > --- a/drivers/platform/x86/intel/vsec.c > +++ b/drivers/platform/x86/intel/vsec.c > @@ -120,6 +120,8 @@ static void intel_vsec_dev_release(struct device *dev) > { > struct intel_vsec_device *intel_vsec_dev = dev_to_ivdev(dev); > > + xa_erase(&auxdev_array, intel_vsec_dev->id); > + > mutex_lock(&vsec_ida_lock); > ida_free(intel_vsec_dev->ida, intel_vsec_dev->auxdev.id); > mutex_unlock(&vsec_ida_lock); > @@ -135,19 +137,27 @@ int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent, > struct auxiliary_device *auxdev = &intel_vsec_dev->auxdev; > int ret, id; > > - mutex_lock(&vsec_ida_lock); > - ret = ida_alloc(intel_vsec_dev->ida, GFP_KERNEL); > - mutex_unlock(&vsec_ida_lock); > + ret = xa_alloc(&auxdev_array, &intel_vsec_dev->id, intel_vsec_dev, > + PMT_XA_LIMIT, GFP_KERNEL); > if (ret < 0) { > kfree(intel_vsec_dev->resource); > kfree(intel_vsec_dev); > return ret; > } > > + mutex_lock(&vsec_ida_lock); > + id = ida_alloc(intel_vsec_dev->ida, GFP_KERNEL); > + mutex_unlock(&vsec_ida_lock); > + if (id < 0) { > + kfree(intel_vsec_dev->resource); > + kfree(intel_vsec_dev); > + return id; Thanks, this looks much better this way around but it is missing xa_alloc() rollback now that the order is reversed. Once that is fixed, Reviewed-by: Ilpo J?rvinen -- i. --8323329-2128018015-1701342149=:1808--