Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp111987pxb; Thu, 27 Jan 2022 16:29:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwziZKhjbG+g4A5JkYBo2tfztMZuLCH/dWq+EMB7Jdjh+O6JeMHQ1YeUqhiaqMUnqyjAWaT X-Received: by 2002:a17:906:58c6:: with SMTP id e6mr4902285ejs.514.1643329773854; Thu, 27 Jan 2022 16:29:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643329773; cv=none; d=google.com; s=arc-20160816; b=QabdItegoii+W5A2VibcbYqpLqzmxGXeQBcw7Tq0EHdgaCAHOnDbY0vsavRVOYEMpr xrWYbMPOp1z2lR13t6nzTIZB3+qk3UXny9/7p7EDd9n0zP5WqQtKJxHRokU7x+N6o9x6 w5pXYY350hKpNjRyAjnnQtIK2DIOfvt8EFFToN65xsRPeneKEb/Cuhiayz66eaVh2eO8 hHMzeJvB6n/l20vbCyKrGeeP+iVFgZMbA05w1/n5b17nLN/Q5RUPxdA3Wj1S5HZE5tkp HFxSEXfg/z+uPDCkt8CfkUW+l5FpRj9OB2OSDVZnDpy68OsiLxo8Qg2V21waYKZOYkFM JkKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=XeEMBEwWWG+dHaYo1yluoFv6fP/RuA+zAGBEUfwky5w=; b=k2yy52BAMPLjVqMAsIbSnl+MbJdzlk8EOhg3iAu9Aqdi5nq05Sgfla8/esh0s4HNTv 5XTZhZ3Z9/yeZenoBXN5oVYkZ4zFiS1enXGFc99IWht/+UyxdEI8sXF52adFQ3+UDW7g JJF3BivsIgQBdABanx1eX0muL9bkHT0ZGTERPZQ6UOGWxyYkCEbUvMFRhdE/zAfSEAYl hXP4z9lL3QPJ+MU1BV8nXCtAvvSyBRiQ6j/d4sXm+fmM0VbCkJQ0qVdGV/2dw4kaK4fC 8nYrxOGL02namSJ71SxavzaVskDcUqR+TaIGsTcMMmyuY7FUXPnuRZovHUQJA5UkeslG iBmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=pQIYfGL9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 7si1890617ejh.105.2022.01.27.16.29.09; Thu, 27 Jan 2022 16:29:33 -0800 (PST) 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; dkim=pass header.i=@ibm.com header.s=pp1 header.b=pQIYfGL9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241593AbiA0NRF (ORCPT + 99 others); Thu, 27 Jan 2022 08:17:05 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42204 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241585AbiA0NRE (ORCPT ); Thu, 27 Jan 2022 08:17:04 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20RDDSrU027765; Thu, 27 Jan 2022 13:16:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : references : date : in-reply-to : message-id : mime-version : content-type; s=pp1; bh=XeEMBEwWWG+dHaYo1yluoFv6fP/RuA+zAGBEUfwky5w=; b=pQIYfGL9is9OvvLkJuKSaZ5N96qrrmnAtSSbEvgitpPiPN15jIPMTwMY601MRnoEze4Z i9AOm9SKTu+yR6krbp4ErhzGOhIeus4uX/CNLQ9MWRZSUl9a135UfFeIfrf7xm9u4mfC y71IEH/neWzn4c0Gw+K5yDvTNtW549t1n99xqO8N2qEq5cpdnNVvuJwWKPzLv1LR+HQP tIDOS2SCz9VteNKwfk5qAX07w4icnObvoB5TfS4ktiXm7R3XalQtCiTYWkNANfjs0HUR /Hg+7b/Xb56zgfwCXUdZayru562ka5cqzL6HsdKTG10U8VqgLBWcfbXWapjhd4o+bPs+ tw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dupsuqqbx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Jan 2022 13:16:38 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 20RDGb16008275; Thu, 27 Jan 2022 13:16:38 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dupsuqqb2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Jan 2022 13:16:37 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 20RDCRVC001264; Thu, 27 Jan 2022 13:16:35 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06fra.de.ibm.com with ESMTP id 3dr96jx7ka-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Jan 2022 13:16:35 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 20RDGWaZ21496254 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Jan 2022 13:16:32 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 268F84C052; Thu, 27 Jan 2022 13:16:32 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CD5AD4C040; Thu, 27 Jan 2022 13:16:31 +0000 (GMT) Received: from tuxmaker.linux.ibm.com (unknown [9.152.85.9]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 27 Jan 2022 13:16:31 +0000 (GMT) From: Sven Schnelle To: Mark Rutland Cc: Steven Rostedt , Yinan Liu , linuxppc-dev@lists.ozlabs.org, Sachin Sant , linux-kernel@vger.kernel.org, ardb@kernel.org, keescook@chromium.org, hca@linux.ibm.com Subject: Re: [powerpc] ftrace warning kernel/trace/ftrace.c:2068 with code-patching selftests References: <944D10DA-8200-4BA9-8D0A-3BED9AA99F82@linux.ibm.com> <20220124114548.30241947@gandalf.local.home> <0fa0daec-881a-314b-e28b-3828e80bbd90@linux.alibaba.com> <20220127074601.41a3773d@rorschach.local.home> Date: Thu, 27 Jan 2022 14:16:31 +0100 In-Reply-To: (Mark Rutland's message of "Thu, 27 Jan 2022 13:08:46 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 1HlEL2zE9lD4mxEQU6kQxS4U-kPK0-JT X-Proofpoint-ORIG-GUID: l8jXR6C3cwAQe74SA6titpwuHpkUaO0p X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-27_03,2022-01-27_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 spamscore=0 bulkscore=0 adultscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1015 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201270079 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Mark Rutland writes: > On Thu, Jan 27, 2022 at 07:46:01AM -0500, Steven Rostedt wrote: >> On Thu, 27 Jan 2022 12:27:04 +0000 >> Mark Rutland wrote: >> >> > Ah, so those non-ELF relocations for the mcount_loc table just mean "apply the >> > KASLR offset here", which is equivalent for all entries. >> > >> > That makes sense, thanks! >> >> And this is why we were having such a hard time understanding each other ;-) > > ;) > > With that in mind, I think that we understand that the build-time sort works > for: > > * arch/x86, becuase the non-ELF relocations for mcount_loc happen to be > equivalent. > > * arch/arm, because there's no dynamic relocaiton and the mcount_loc entries > have been finalized prior to sorting. > > ... but doesn't work for anyone else (including arm64) because the ELF > relocations are not equivalent, and need special care that is not yet > implemented. For s390 my idea is to just skip the addresses between __start_mcount_loc and __stop_mcount_loc, because for these addresses we know that they are 64 bits wide, so we just need to add the KASLR offset. I'm thinking about something like this: diff --git a/arch/s390/boot/compressed/decompressor.h b/arch/s390/boot/compressed/decompressor.h index f75cc31a77dd..015d7e2e94ef 100644 --- a/arch/s390/boot/compressed/decompressor.h +++ b/arch/s390/boot/compressed/decompressor.h @@ -25,6 +25,8 @@ struct vmlinux_info { unsigned long rela_dyn_start; unsigned long rela_dyn_end; unsigned long amode31_size; + unsigned long start_mcount_loc; + unsigned long stop_mcount_loc; }; /* Symbols defined by linker scripts */ diff --git a/arch/s390/boot/startup.c b/arch/s390/boot/startup.c index 1aa11a8f57dd..7bb0d88db5c6 100644 --- a/arch/s390/boot/startup.c +++ b/arch/s390/boot/startup.c @@ -88,6 +88,11 @@ static void handle_relocs(unsigned long offset) dynsym = (Elf64_Sym *) vmlinux.dynsym_start; for (rela = rela_start; rela < rela_end; rela++) { loc = rela->r_offset + offset; + if ((loc >= vmlinux.start_mcount_loc) && + (loc < vmlinux.stop_mcount_loc)) { + (*(unsigned long *)loc) += offset; + continue; + } val = rela->r_addend; r_sym = ELF64_R_SYM(rela->r_info); if (r_sym) { @@ -232,6 +237,8 @@ static void offset_vmlinux_info(unsigned long offset) vmlinux.rela_dyn_start += offset; vmlinux.rela_dyn_end += offset; vmlinux.dynsym_start += offset; + vmlinux.start_mcount_loc += offset; + vmlinux.stop_mcount_loc += offset; } static unsigned long reserve_amode31(unsigned long safe_addr) diff --git a/arch/s390/kernel/vmlinux.lds.S b/arch/s390/kernel/vmlinux.lds.S index 42c43521878f..51c773405608 100644 --- a/arch/s390/kernel/vmlinux.lds.S +++ b/arch/s390/kernel/vmlinux.lds.S @@ -213,6 +213,8 @@ SECTIONS QUAD(__rela_dyn_start) /* rela_dyn_start */ QUAD(__rela_dyn_end) /* rela_dyn_end */ QUAD(_eamode31 - _samode31) /* amode31_size */ + QUAD(__start_mcount_loc) + QUAD(__stop_mcount_loc) } :NONE /* Debugging sections. */ Not sure whether that would also work on power, and also not sure whether i missed something thinking about that. Maybe it doesn't even work. ;-)