Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp650953iob; Wed, 18 May 2022 09:52:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzddWxsZ/8npyu/TDYwmbtmbmJ7qA/GV/aJY/Qnb4ykwoDO++9VLQxADHLDYFApD/mJ46yK X-Received: by 2002:a17:903:2303:b0:15e:a53e:322d with SMTP id d3-20020a170903230300b0015ea53e322dmr618841plh.36.1652892743364; Wed, 18 May 2022 09:52:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652892743; cv=none; d=google.com; s=arc-20160816; b=c5fd142HXifAN0ro+ULKJfQM+hzk8mbFRvMwW0uA8seVnjPlRodgyw3YXhJfsBGZ34 JSpMZpDaKkrdenbT/6V80Iw1HlHm59GOdz6sLwpZuDz9qoNVxrx9O1C5nMODjR/Z/Sbq GxrNSWFMYkOJXeBrs8w9nIvp3BScYebq3D2njaZqzxm/c8zfuzwDgxrR9y7ZWy7vTQXW IqsJ5n2z7LPqO7p0mDDeixhC1LN9WO0YCYRsbcMB+me9ZSrou/3pf7rQZciYDFB07aqY d091bRDWtoECKlfNXCb/Cx1wLfdaRgaYGf4KVAqAxVk0El2yX6zNbeWaygabVQqbS7S+ cM8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:user-agent:in-reply-to:references:cc:to:subject:from :date:dkim-signature; bh=E/KJiJDZWVaEZCn40lud7/8o1j+K/VJuslMugUXGBiM=; b=vC74DXadW9Puxi9X/8hkFqvq3EWQftmw/+VgeMnT0hl3h3LcEQwBPMRUpkNDpf9yZW FfW+tKuClZgmloirWr8GjkUscCRH+uQlnCc66ha1ZlsLr7/lw+fa3JnSPSA6IrM6583U 9fPITNflYD5KrPG/9OkK1PrSCb4ncktK0YuuDEJzokAXJVFftu0c+AP5IVksG9RARugk b3I1OlQytgei73Wc8HVBkPxfYjQWPXkEyDIP6p27iTyb1rtnYv2PkWQIa1J6PSkwZ7B/ YBv6WVUurGUxKNJwN6K/2QZq27EiQxcLDJtk3efLV5xU3Ko2qBrBTgz0f22CsqJTgVXq YX5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=D5zEioSJ; 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=ibm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y6-20020a62b506000000b00506bc45aaecsi3288129pfe.371.2022.05.18.09.52.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 09:52:23 -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=@ibm.com header.s=pp1 header.b=D5zEioSJ; 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=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1D6AE8B0A4; Wed, 18 May 2022 09:48:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240527AbiERQsj (ORCPT + 99 others); Wed, 18 May 2022 12:48:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240519AbiERQsf (ORCPT ); Wed, 18 May 2022 12:48:35 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE23D8AE7C for ; Wed, 18 May 2022 09:48:34 -0700 (PDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24IGfkUK011224; Wed, 18 May 2022 16:48:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : subject : to : cc : references : in-reply-to : message-id : content-type : content-transfer-encoding : mime-version; s=pp1; bh=E/KJiJDZWVaEZCn40lud7/8o1j+K/VJuslMugUXGBiM=; b=D5zEioSJUJ8vkCIdHAi4TDMrK4U4XhfCug2DAIR8zX2OuVMUWSkyZzjuHfI9rSIy4+kd eZW5F8gvD7juFBW6sa+H1otOJkWbEYfdbJjNMTmOTaHkeZYyvd2uTlie9W6LoCH9oibf WR3TAjr4ZPnezjeWet/7ZJAzZ7ExG57LcBJIZcN6KkbEZHbCRC0dTSuquzjlHgb0OUbv Q9vmO0p/8zwSyf0egtDUEON6stpzye+4ZEvtTeCoVcs3f7AfzC/RJNEAanP4oAjROO+Q xq28LrMILcO/84fKEJdjmkWUcQZCtIak3rX30jfzRelFaQLFMkO/ns9bGPLgPBKoDznm PQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g54hyg4ns-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 May 2022 16:48:21 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24IGgE5E012824; Wed, 18 May 2022 16:48:20 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g54hyg4mv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 May 2022 16:48:20 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24IGXlaw012021; Wed, 18 May 2022 16:48:18 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma01fra.de.ibm.com with ESMTP id 3g2428vvps-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 May 2022 16:48:18 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24IGmFSV48824774 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 May 2022 16:48:15 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B77D04C046; Wed, 18 May 2022 16:48:15 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4C1E74C044; Wed, 18 May 2022 16:48:15 +0000 (GMT) Received: from localhost (unknown [9.43.19.36]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 18 May 2022 16:48:15 +0000 (GMT) Date: Wed, 18 May 2022 22:18:13 +0530 From: "Naveen N. Rao" Subject: Re: [PATCH] kexec_file: Drop pr_err in weak implementations of arch_kexec_apply_relocations[_add] To: "Eric W. Biederman" , Michael Ellerman Cc: Baoquan He , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <20220425174128.11455-1-naveen.n.rao@linux.vnet.ibm.com> <1652782155.56t7mah8ib.naveen@linux.ibm.com> <8735h8b2f1.fsf@email.froward.int.ebiederm.org> <87v8u3o9tk.fsf@mpe.ellerman.id.au> <875ym2aoc7.fsf@email.froward.int.ebiederm.org> In-Reply-To: <875ym2aoc7.fsf@email.froward.int.ebiederm.org> User-Agent: astroid/4d6b06ad (https://github.com/astroidmail/astroid) Message-Id: <1652892300.1k6kqwc17y.naveen@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: XO4RXk88ZrBBP6VnIK7Xps7fUVZDizXw X-Proofpoint-GUID: x_NDsOGiwNsBgH-jBOd0QAcoHw3VvYLa Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-18_06,2022-05-17_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 spamscore=0 adultscore=0 clxscore=1015 phishscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205180099 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 Eric W. Biederman wrote: > Michael Ellerman writes: >=20 >> "Eric W. Biederman" writes: >>> Looking at this the pr_err is absolutely needed. If an unsupported case >>> winds up in the purgatory blob and the code can't handle it things >>> will fail silently much worse later. >> >> It won't fail later, it will fail the syscall. >> >> sys_kexec_file_load() >> kimage_file_alloc_init() >> kimage_file_prepare_segments() >> arch_kexec_kernel_image_load() >> kexec_image_load_default() >> image->fops->load() >> elf64_load() # powerpc >> bzImage64_load() # x86 >> kexec_load_purgatory() >> kexec_apply_relocations() >> >> Which does: >> >> if (relsec->sh_type =3D=3D SHT_RELA) >> ret =3D arch_kexec_apply_relocations_add(pi, section, >> relsec, symtab); >> else if (relsec->sh_type =3D=3D SHT_REL) >> ret =3D arch_kexec_apply_relocations(pi, section, >> relsec, symtab); >> if (ret) >> return ret; >> >> And that error is bubbled all the way back up. So as long as >> arch_kexec_apply_relocations() returns an error the syscall will fail >> back to userspace and there'll be an error message at that level. >> >> It's true that having nothing printed in dmesg makes it harder to work >> out why the syscall failed. But it's a kernel bug if there are unhandled >> relocations in the kernel-supplied purgatory code, so a user really has >> no way to do anything about the error even if it is printed. >=20 > Good point. I really hadn't noticed the error code in there when I > looked. >=20 > I still don't think changing the functionality of the code because of > a tool issue is the right solution. Ok. >=20 >=20 >>> "Naveen N. Rao" writes: >>> >>>> Baoquan He wrote: >>>>> On 04/25/22 at 11:11pm, Naveen N. Rao wrote: >>>>>> kexec_load_purgatory() can fail for many reasons - there is no need = to >>>>>> print an error when encountering unsupported relocations. >>>>>> This solves a build issue on powerpc with binutils v2.36 and newer [= 1]. >>>>>> Since commit d1bcae833b32f1 ("ELF: Don't generate unused section >>>>>> symbols") [2], binutils started dropping section symbols that it tho= ught >>>>> I am not familiar with binutils, while wondering if this exists in ot= her >>>>> ARCHes except of ppc. Arm64 doesn't have the ARCH override either, do= we >>>>> have problem with it? >>>> >>>> I'm not aware of this specific file causing a problem on other archite= ctures - >>>> perhaps the config options differ enough. There are however more repor= ts of >>>> similar issues affecting other architectures with the llvm integrated = assembler: >>>> https://github.com/ClangBuiltLinux/linux/issues/981 >>>> >>>>> >>>>>> were unused. This isn't an issue in general, but with kexec_file.c,= gcc >>>>>> is placing kexec_arch_apply_relocations[_add] into a separate >>>>>> .text.unlikely section and the section symbol ".text.unlikely" is be= ing >>>>>> dropped. Due to this, recordmcount is unable to find a non-weak symb= ol >>>>> But arch_kexec_apply_relocations_add is weak symbol on ppc. >>>> >>>> Yes. Note that it is just the section symbol that gets dropped. The se= ction is >>>> still present and will continue to hold the symbols for the functions >>>> themselves. >>> >>> So we have a case where binutils thinks it is doing something useful >>> and our kernel specific tool gets tripped up by it. >> >> It's not just binutils, the LLVM assembler has the same behavior. >> >>> Reading the recordmcount code it looks like it is finding any symbol >>> within a section but ignoring weak symbols. So I suspect the only >>> remaining symbol in the section is __weak and that confuses >>> recordmcount. >>> >>> Does removing the __weak annotation on those functions fix the build >>> error? If so we can restructure the kexec code to simply not use __weak >>> symbols. >>> >>> Otherwise the fix needs to be in recordmcount or binutils, and we should >>> loop whoever maintains recordmcount in to see what they can do. >> >> It seems that recordmcount is not really maintained anymore now that x86 >> uses objtool? >> >> There've been several threads about fixing recordmcount, but none of >> them seem to have lead to a solution. >=20 > That is unfortunate. >=20 >> These weak symbol vs recordmcount problems have been worked around going >> back as far as 2020: >> >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/com= mit/include/linux/elfcore.h?id=3D6e7b64b9dd6d96537d816ea07ec26b7dedd397b9 >=20 > I am more than happy to adopt the kind of solution that was adopted > there in elfcore.h and simply get rid of __weak symbols in the kexec > code. >=20 > Using __weak symbols is really not the common kernel way of doing > things. Using __weak symbols introduces a bit of magic in how the > kernel gets built that is unnecessary. >=20 > Can someone verify that deleting __weak is enough to get powerpc to > build? AKA: >=20 > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > index 8347fc158d2b..7f4ca8dbe26f 100644 > --- a/kernel/kexec_file.c > +++ b/kernel/kexec_file.c > @@ -117,7 +117,7 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage= *image, void *buf, > * > * Return: 0 on success, negative errno on error. > */ > -int __weak > +int > arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *se= ction, > const Elf_Shdr *relsec, const Elf_Shdr *= symtab) > { > @@ -134,7 +134,7 @@ arch_kexec_apply_relocations_add(struct purgatory_inf= o *pi, Elf_Shdr *section, > * > * Return: 0 on success, negative errno on error. > */ > -int __weak > +int > arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *sectio= n, > const Elf_Shdr *relsec, const Elf_Shdr *symt= ab) > { Yes, dropping the __weak attribute allows recordmcount to emit a=20 relocation using those symbols, so that resolves the problem. >=20 > If that change is verified to work a proper patch that keeps x86 and > s390 building that have actual implementations should not be too > difficult to write. Sure, I will post a patch for that. Thanks, Naveen