From patchwork Thu Mar 25 04:37:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 408760 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp203344jai; Wed, 24 Mar 2021 21:38:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkWKB8s/rBCJOJkX/eEXqwTJYhuxc3w+7DmlYmA8U7T1UKmFHWEt5vChWNA2cxAQ+/bHX4 X-Received: by 2002:aa7:d385:: with SMTP id x5mr7009111edq.289.1616647127013; Wed, 24 Mar 2021 21:38:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616647127; cv=none; d=google.com; s=arc-20160816; b=LpiyH8c3uEQwNfxyA8gcrBFhOkIyJ6snnunBM+K0/Py1uMpkKQH3G+p3g6wTEGR3qP Dyik0Q/Wm1b501aEVzg0dMkLyzAxA7yCtSDf3sNdLkb55rrXr26FSupI28Sz+twnmF5P KfzuLUrY/ugHQph7+ux5RmplJ13qPQFH1PAos8fmLMJpQk/eLNdp2nFeeU44PckoTsPP ifdpBqQKsqjaCqS5UHq+hKK6U31ZS+fOp263Oros6x7Elc1puad9tViw5Z++JGLlJZEG pQejY9B7zgP/B4sjjrPP1deU4lGeynfVt1hf+QFRBgRlUNU1MEXVYCY5DPtHCE2/kS/8 W+GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:message-id:subject:to :from:date:dkim-signature; bh=ynwlZQzZxPHryJ7B0FoLClvmyrX6u0WGTzsz8USDiWs=; b=tnF2GRAjjwEDOm/BzAVO1MGci8D1h5E4RYS4MrQNBlQHcVllrrsgaBtyJa4p41cgYB +sgpjDAh1QoJSTmCHMePepT3ULunAj15br5e85zjzALLmpObEuoRwf9W48lRoJZk1v3C hbPJlDpwqbVpMtivIbp4wqqMMkHom8EgqDAVz8v23c8/Wly0vJygks0DLUN6YHfW67iL AZii6teVL7Z/qYVoM8bFegLVsKrb8eKXqlIrSyAEyOS9lJ9WsXudFBscjZ86PIXpvBaT IQM0AB4tTwaGF41vb0ZApn3FJm0WfTKmSk+hTTjH/YEt4PYLHJnAI+ZOLsyxrSMb7ORv a+dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=2gxNNAYe; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o7si3144719edr.131.2021.03.24.21.38.46; Wed, 24 Mar 2021 21:38:47 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=2gxNNAYe; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbhCYEiO (ORCPT + 12 others); Thu, 25 Mar 2021 00:38:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:44464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229801AbhCYEhp (ORCPT ); Thu, 25 Mar 2021 00:37:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ADC5961A1D; Thu, 25 Mar 2021 04:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1616647065; bh=XEN77bx4abFEwI/o3fAxImEJjxvZmzazWSGm5OVvdzA=; h=Date:From:To:Subject:In-Reply-To:From; b=2gxNNAYe1SDLo+L8sX/ug0+iCgXUmGoGndOcyhhK1QPy4cwX2Fv/eTKvPehs3LXtn V9tvxjS4Qiaz9mfCiCM1Klt5a+IKoP5jtdo9bqietLFVbswnoWHeGqxtxlmv0c8BhT 9KtHGcAzXnJ+nwNOLE/8IE70S1zXXpJF4eaH0138= Date: Wed, 24 Mar 2021 21:37:44 -0700 From: Andrew Morton To: akpm@linux-foundation.org, linux-mm@kvack.org, maskray@google.com, mm-commits@vger.kernel.org, nathan@kernel.org, ndesaulniers@google.com, oberpar@linux.ibm.com, psodagud@quicinc.com, stable@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 10/14] gcov: fix clang-11+ support Message-ID: <20210325043744.olufBBZcn%akpm@linux-foundation.org> In-Reply-To: <20210324213644.bf03a529aec4ef9580e17dbc@linux-foundation.org> User-Agent: s-nail v14.8.16 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Nick Desaulniers Subject: gcov: fix clang-11+ support LLVM changed the expected function signatures for llvm_gcda_start_file() and llvm_gcda_emit_function() in the clang-11 release. Users of clang-11 or newer may have noticed their kernels failing to boot due to a panic when enabling CONFIG_GCOV_KERNEL=y +CONFIG_GCOV_PROFILE_ALL=y. Fix up the function signatures so calling these functions doesn't panic the kernel. Link: https://reviews.llvm.org/rGcdd683b516d147925212724b09ec6fb792a40041 Link: https://reviews.llvm.org/rG13a633b438b6500ecad9e4f936ebadf3411d0f44 Link: https://lkml.kernel.org/r/20210312224132.3413602-2-ndesaulniers@google.com Signed-off-by: Nick Desaulniers Reported-by: Prasad Sodagudi Suggested-by: Nathan Chancellor Reviewed-by: Fangrui Song Tested-by: Nathan Chancellor Acked-by: Peter Oberparleiter Reviewed-by: Nathan Chancellor Cc: [5.4+] Signed-off-by: Andrew Morton --- kernel/gcov/clang.c | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) --- a/kernel/gcov/clang.c~gcov-fix-clang-11-support +++ a/kernel/gcov/clang.c @@ -75,7 +75,9 @@ struct gcov_fn_info { u32 num_counters; u64 *counters; +#if CONFIG_CLANG_VERSION < 110000 const char *function_name; +#endif }; static struct gcov_info *current_info; @@ -105,6 +107,7 @@ void llvm_gcov_init(llvm_gcov_callback w } EXPORT_SYMBOL(llvm_gcov_init); +#if CONFIG_CLANG_VERSION < 110000 void llvm_gcda_start_file(const char *orig_filename, const char version[4], u32 checksum) { @@ -113,7 +116,17 @@ void llvm_gcda_start_file(const char *or current_info->checksum = checksum; } EXPORT_SYMBOL(llvm_gcda_start_file); +#else +void llvm_gcda_start_file(const char *orig_filename, u32 version, u32 checksum) +{ + current_info->filename = orig_filename; + current_info->version = version; + current_info->checksum = checksum; +} +EXPORT_SYMBOL(llvm_gcda_start_file); +#endif +#if CONFIG_CLANG_VERSION < 110000 void llvm_gcda_emit_function(u32 ident, const char *function_name, u32 func_checksum, u8 use_extra_checksum, u32 cfg_checksum) { @@ -133,6 +146,24 @@ void llvm_gcda_emit_function(u32 ident, list_add_tail(&info->head, ¤t_info->functions); } EXPORT_SYMBOL(llvm_gcda_emit_function); +#else +void llvm_gcda_emit_function(u32 ident, u32 func_checksum, + u8 use_extra_checksum, u32 cfg_checksum) +{ + struct gcov_fn_info *info = kzalloc(sizeof(*info), GFP_KERNEL); + + if (!info) + return; + + INIT_LIST_HEAD(&info->head); + info->ident = ident; + info->checksum = func_checksum; + info->use_extra_checksum = use_extra_checksum; + info->cfg_checksum = cfg_checksum; + list_add_tail(&info->head, ¤t_info->functions); +} +EXPORT_SYMBOL(llvm_gcda_emit_function); +#endif void llvm_gcda_emit_arcs(u32 num_counters, u64 *counters) { @@ -295,6 +326,7 @@ void gcov_info_add(struct gcov_info *dst } } +#if CONFIG_CLANG_VERSION < 110000 static struct gcov_fn_info *gcov_fn_info_dup(struct gcov_fn_info *fn) { size_t cv_size; /* counter values size */ @@ -322,6 +354,28 @@ err_name: kfree(fn_dup); return NULL; } +#else +static struct gcov_fn_info *gcov_fn_info_dup(struct gcov_fn_info *fn) +{ + size_t cv_size; /* counter values size */ + struct gcov_fn_info *fn_dup = kmemdup(fn, sizeof(*fn), + GFP_KERNEL); + if (!fn_dup) + return NULL; + INIT_LIST_HEAD(&fn_dup->head); + + cv_size = fn->num_counters * sizeof(fn->counters[0]); + fn_dup->counters = vmalloc(cv_size); + if (!fn_dup->counters) { + kfree(fn_dup); + return NULL; + } + + memcpy(fn_dup->counters, fn->counters, cv_size); + + return fn_dup; +} +#endif /** * gcov_info_dup - duplicate profiling data set @@ -362,6 +416,7 @@ err: * gcov_info_free - release memory for profiling data set duplicate * @info: profiling data set duplicate to free */ +#if CONFIG_CLANG_VERSION < 110000 void gcov_info_free(struct gcov_info *info) { struct gcov_fn_info *fn, *tmp; @@ -375,6 +430,20 @@ void gcov_info_free(struct gcov_info *in kfree(info->filename); kfree(info); } +#else +void gcov_info_free(struct gcov_info *info) +{ + struct gcov_fn_info *fn, *tmp; + + list_for_each_entry_safe(fn, tmp, &info->functions, head) { + vfree(fn->counters); + list_del(&fn->head); + kfree(fn); + } + kfree(info->filename); + kfree(info); +} +#endif #define ITER_STRIDE PAGE_SIZE