Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4894206pxv; Tue, 6 Jul 2021 11:44:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwENNU3AE9jx2WQDyNr/iaEdaMJ4zKGgnobpbzrmQFFgC6MgMplb6yc7GZjgseddB/JGBM3 X-Received: by 2002:a02:c00c:: with SMTP id y12mr17928711jai.99.1625597056563; Tue, 06 Jul 2021 11:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625597056; cv=none; d=google.com; s=arc-20160816; b=ZotyvHF253t2h68MbMmA+W2gxTlorv/M65m7hmrWUjmK20Plk52nuu1IxXoJCqvwMt jhw70H2ggywTJShBBkuNEi1fn7atEae8y2aEtrthUUn0GHCcvoC+68lhCyQrd478S6eh c3uaNS2TeHBqaWBI819hxo2H1DcpgrGNlgr9nQnst2xiUYZNKMlhoIfQBX3Kigt3oshj Hlm4QwGXiGtZUU2V4bYwiFfaLclskYWHYsVItHjhDmbXW719VWq03ILk2BZZKRACRJgO /BvlKMRSi9pGk9fIG9IvGpPhT1DgTD23+OOnAD7wgtVxnXmGZAGZ531hGsG8loiQ2+pP kRLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=707rQIpNsT+DR6bNaY9y99LVGrMoJ+TWhxJreVrtNoE=; b=yUyQPh7aY29ps2e2xoNrwaGoXrIza2zMtrSX5/r+2O9h2m8uGyNMeXSprIeQqbxYEa zXCEt0ox7qNe3Phs+MjEe4PLizdHDe1BEkgMZEyVICw7hSRjuWfV+gusFlvWxTgKncd5 zn8pGvuLNx1laVtZoC2L/FwQCpNL194azJo8B10/zfGcfMNqqs/HIF6pjLYNCsqIAMkg 2Rj12ZnZIRTLuH3uGvswxM7FtlGvwiO3su9VgmuLXsMy5zW+/vyeTuXLPmTY59Ex0XXZ df+DGG/EvGVOCGNwWMbOHxDJG+aQp5C/7pnKgmFI2ooE8pHpj+3hx+NefIPjnZ0fV58q 3ncQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j12si18794309jar.85.2021.07.06.11.44.04; Tue, 06 Jul 2021 11:44:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231521AbhGFSqN (ORCPT + 99 others); Tue, 6 Jul 2021 14:46:13 -0400 Received: from mga07.intel.com ([134.134.136.100]:59003 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbhGFSqM (ORCPT ); Tue, 6 Jul 2021 14:46:12 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10037"; a="273020027" X-IronPort-AV: E=Sophos;i="5.83,329,1616482800"; d="scan'208";a="273020027" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2021 11:43:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,329,1616482800"; d="scan'208";a="627769895" Received: from linux.intel.com ([10.54.29.200]) by orsmga005.jf.intel.com with ESMTP; 06 Jul 2021 11:43:32 -0700 Received: from [10.209.95.225] (kliang2-MOBL.ccr.corp.intel.com [10.209.95.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by linux.intel.com (Postfix) with ESMTPS id 27F055808AE; Tue, 6 Jul 2021 11:43:32 -0700 (PDT) Subject: Re: [PATCH] perf/x86/intel/uncore: Fix IIO cleanup mapping procedure for SNR/ICX To: Alexander Antonov , peterz@infradead.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: ak@linux.intel.com, alexey.v.bayduraev@linux.intel.com References: <20210706090723.41850-1-alexander.antonov@linux.intel.com> <3d634baf-8abe-480d-61ed-ade1945324ee@linux.intel.com> <0292c242-dc53-253d-da87-710b001aa3e7@linux.intel.com> From: "Liang, Kan" Message-ID: <99baf5a8-3d20-d9ff-95ee-b31d4a2c59bb@linux.intel.com> Date: Tue, 6 Jul 2021 14:43:30 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <0292c242-dc53-253d-da87-710b001aa3e7@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/6/2021 12:17 PM, Alexander Antonov wrote: > > On 7/6/2021 5:12 PM, Liang, Kan wrote: >> >> >> On 7/6/2021 5:07 AM, alexander.antonov@linux.intel.com wrote: >>> From: Alexander Antonov >>> >>> Cleanup mapping procedure for IIO PMU is needed to free memory which was >>> allocated for topology data and for attributes in IIO mapping >>> attribute_group. >>> Current implementation of this procedure for Snowridge and Icelake >>> Server >>> platforms doesn't free allocated memory that can be a reason for memory >>> leak issue. >>> Fix the issue with IIO cleanup mapping procedure for these platforms >>> to release allocated memory. >>> >>> Fixes: 10337e95e04c ("perf/x86/intel/uncore: Enable I/O stacks to IIO >>> PMON mapping on ICX") >>> >>> Signed-off-by: Alexander Antonov >> >> The patch looks good to me. >> >> Reviewed-by: Kan Liang >> >> >> With this fix, there will be several similar codes repeat, e.g., >> XXX_iio_set_mapping() and XXX_iio_cleanup_mapping(), for SKX, ICX, and >> SNR for now. >> I guess there will be more for the future platforms. Have you >> considered to add a macro or something to reduce the code repetition? >> >> Thanks, >> Kan > > That's a good idea. > I suggest to do it together with enabling of mapping on future > platforms. What do you think? > It's OK for me. Thanks. Kan > >> >>> --- >>>   arch/x86/events/intel/uncore_snbep.c | 40 +++++++++++++++++++--------- >>>   1 file changed, 28 insertions(+), 12 deletions(-) >>> >>> diff --git a/arch/x86/events/intel/uncore_snbep.c >>> b/arch/x86/events/intel/uncore_snbep.c >>> index bb6eb1e5569c..54cdbb96e628 100644 >>> --- a/arch/x86/events/intel/uncore_snbep.c >>> +++ b/arch/x86/events/intel/uncore_snbep.c >>> @@ -3836,26 +3836,32 @@ pmu_iio_set_mapping(struct intel_uncore_type >>> *type, struct attribute_group *ag) >>>       return ret; >>>   } >>>   -static int skx_iio_set_mapping(struct intel_uncore_type *type) >>> -{ >>> -    return pmu_iio_set_mapping(type, &skx_iio_mapping_group); >>> -} >>> - >>> -static void skx_iio_cleanup_mapping(struct intel_uncore_type *type) >>> +static void >>> +pmu_iio_cleanup_mapping(struct intel_uncore_type *type, struct >>> attribute_group *ag) >>>   { >>> -    struct attribute **attr = skx_iio_mapping_group.attrs; >>> +    struct attribute **attr = ag->attrs; >>>         if (!attr) >>>           return; >>>         for (; *attr; attr++) >>>           kfree((*attr)->name); >>> -    kfree(attr_to_ext_attr(*skx_iio_mapping_group.attrs)); >>> -    kfree(skx_iio_mapping_group.attrs); >>> -    skx_iio_mapping_group.attrs = NULL; >>> +    kfree(attr_to_ext_attr(*ag->attrs)); >>> +    kfree(ag->attrs); >>> +    ag->attrs = NULL; >>>       kfree(type->topology); >>>   } >>>   +static int skx_iio_set_mapping(struct intel_uncore_type *type) >>> +{ >>> +    return pmu_iio_set_mapping(type, &skx_iio_mapping_group); >>> +} >>> + >>> +static void skx_iio_cleanup_mapping(struct intel_uncore_type *type) >>> +{ >>> +    pmu_iio_cleanup_mapping(type, &skx_iio_mapping_group); >>> +} >>> + >>>   static struct intel_uncore_type skx_uncore_iio = { >>>       .name            = "iio", >>>       .num_counters        = 4, >>> @@ -4499,6 +4505,11 @@ static int snr_iio_set_mapping(struct >>> intel_uncore_type *type) >>>       return pmu_iio_set_mapping(type, &snr_iio_mapping_group); >>>   } >>>   +static void snr_iio_cleanup_mapping(struct intel_uncore_type *type) >>> +{ >>> +    pmu_iio_cleanup_mapping(type, &snr_iio_mapping_group); >>> +} >>> + >>>   static struct intel_uncore_type snr_uncore_iio = { >>>       .name            = "iio", >>>       .num_counters        = 4, >>> @@ -4515,7 +4526,7 @@ static struct intel_uncore_type snr_uncore_iio = { >>>       .attr_update        = snr_iio_attr_update, >>>       .get_topology        = snr_iio_get_topology, >>>       .set_mapping        = snr_iio_set_mapping, >>> -    .cleanup_mapping    = skx_iio_cleanup_mapping, >>> +    .cleanup_mapping    = snr_iio_cleanup_mapping, >>>   }; >>>     static struct intel_uncore_type snr_uncore_irp = { >>> @@ -5090,6 +5101,11 @@ static int icx_iio_set_mapping(struct >>> intel_uncore_type *type) >>>       return pmu_iio_set_mapping(type, &icx_iio_mapping_group); >>>   } >>>   +static void icx_iio_cleanup_mapping(struct intel_uncore_type *type) >>> +{ >>> +    pmu_iio_cleanup_mapping(type, &icx_iio_mapping_group); >>> +} >>> + >>>   static struct intel_uncore_type icx_uncore_iio = { >>>       .name            = "iio", >>>       .num_counters        = 4, >>> @@ -5107,7 +5123,7 @@ static struct intel_uncore_type icx_uncore_iio = { >>>       .attr_update        = icx_iio_attr_update, >>>       .get_topology        = icx_iio_get_topology, >>>       .set_mapping        = icx_iio_set_mapping, >>> -    .cleanup_mapping    = skx_iio_cleanup_mapping, >>> +    .cleanup_mapping    = icx_iio_cleanup_mapping, >>>   }; >>>     static struct intel_uncore_type icx_uncore_irp = { >>> >>> base-commit: 3dbdb38e286903ec220aaf1fb29a8d94297da246 >>>