Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1856892pxb; Sat, 14 Nov 2020 04:56:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzp28Q0p0H6Gy+wC+nwnArcmY1OyK+d0nqncdLahKkLWu1gbQEiL2buwCnIqUzIqhjEsQPc X-Received: by 2002:a17:906:d9dd:: with SMTP id qk29mr6675673ejb.487.1605358605823; Sat, 14 Nov 2020 04:56:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605358605; cv=none; d=google.com; s=arc-20160816; b=je5JTehVJw1GdkUDvpZV++cUnJXCfOV6+3Y1UFG0JINysUNbLy+GObepFSNgB65uFT tfL8TrCno6hgZlaHU82EMm87LmQrCNcQ7qJwQgeOypqgE2nAYMD9/fF24bMm8R26iplz LWsWJ6awMIpEwBvJxUrzj4SEzNVP0e8n9IGM3vUmmpiSeV+q+hgNuj8YY/KppXDmg3GY tyrrPJfr2JlJeqT3x9+aPpCsFEcoraVM1iuuHiO27G/IJlKFF0ICCMUIsCqbfQz8Zp4Z L8qcZmtoJT9PtXSHj5RGmtKrPP+6y959j8g5xIaTPJbhwncAsi/q/W9BFu/v/CcZgk5Q kI9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+GFf5HLFwaNORiZdhbLtPgFiP1jvubuOoIqJBQqz6Cw=; b=PkOZQCVAlIWCaIlPC/L2ecshxM4vce/hGlZuLeGmLu4PvFbxqyBLGjmBmO7ZqFOuAw i0qjWMM7kxi5bOYEPwgFrmjUD8+cUczBCKrWlXq2HyuMGr3zcfeOaObCu/gIr/LTu6Ic 7JPZ0AN6W2eouAJ1TupgHB73taXZ7fPJaok6cCNrI+TpUsnh38nGOxa0mwDxybYIltdf ORZS0FMKJV/tNsNH7AXyySncWe75jH/on9SB2AhTtqqjrGnN4+BFkQaWD6uKJq4e4KEa NmtiNf8x18Qsq+gtcWOJkWd4+fABC56b5AHJwh7LDEjJCYvejVCDXIv9CDGj8atLEpmj NcJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=lhwhQyYF; 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 d12si8545809edo.384.2020.11.14.04.56.22; Sat, 14 Nov 2020 04:56:45 -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=lhwhQyYF; 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 S1726826AbgKNMyB (ORCPT + 99 others); Sat, 14 Nov 2020 07:54:01 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39044 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726725AbgKNMx6 (ORCPT ); Sat, 14 Nov 2020 07:53:58 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AECWP8P084243; Sat, 14 Nov 2020 07:53:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=+GFf5HLFwaNORiZdhbLtPgFiP1jvubuOoIqJBQqz6Cw=; b=lhwhQyYFs5y6YOmilCIz02cFWnCV/2zrsd5RZgkp84qtvM9TG0Zr5z66S+SA8q+6zBxR 4SVQComWP0pK42UzLXOFnOgaOXYdr58PEdXHBXgLD8mp1OrCddESU+nImemWy9UetsgZ b88vWQVOHHsmPfRtSjJqowT0Y+xWGyu39hgiBvxDFIL0VyHxynlVwhT1yfbHF44EIxTJ 4VuHJpJPSJV+KrJP7ViwOVGL/VY0h+k4+fQMK6qiw7GciMMetkjWWp5b6pq+hAJGSwEW tKT+T/DRdULpHCUhwFmYVyfUqDzlJu59TV2mowEThfN0TbzX0X+S/bdhDObAIbR8q+mj RA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 34tdft1xf8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 14 Nov 2020 07:53:17 -0500 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0AECcv1J103682; Sat, 14 Nov 2020 07:53:17 -0500 Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0b-001b2d01.pphosted.com with ESMTP id 34tdft1xev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 14 Nov 2020 07:53:17 -0500 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0AECph6L009545; Sat, 14 Nov 2020 12:53:15 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06fra.de.ibm.com with ESMTP id 34t6gh85gn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 14 Nov 2020 12:53:15 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0AECrC7p60424516 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 14 Nov 2020 12:53:13 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD546A4040; Sat, 14 Nov 2020 12:53:12 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4F647A4051; Sat, 14 Nov 2020 12:53:12 +0000 (GMT) Received: from localhost (unknown [9.171.68.134]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Sat, 14 Nov 2020 12:53:12 +0000 (GMT) Date: Sat, 14 Nov 2020 13:53:10 +0100 From: Vasily Gorbik To: Josh Poimboeuf , Shile Zhang , Peter Zijlstra , Ingo Molnar Cc: Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Miroslav Benes , Alexandre Chartre , Julien Thierry , linux-kernel@vger.kernel.org Subject: [PATCH] scripts/sorttable: Fix ORC unwind table sorting on big endian Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Patchwork-Bot: notify X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-14_04:2020-11-13,2020-11-14 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 suspectscore=2 priorityscore=1501 spamscore=0 impostorscore=0 adultscore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011140079 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently when x86_64 kernel is cross compiled on big endian hardware ORC unwind table is not sorted correctly. Due to missing byte swaps and treating size as 4-byte value ORC sections sizes end up as 0 and the problem is silently ignored. Make ORC unwind table sorting endianness aware. Signed-off-by: Vasily Gorbik --- This goes on top of the patch series: http://lkml.kernel.org/r/cover.thread-1e2854.your-ad-here.call-01605220128-ext-6070@work.hours scripts/sorttable.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/sorttable.h b/scripts/sorttable.h index a2baa2fefb13..99f3fa1767d1 100644 --- a/scripts/sorttable.h +++ b/scripts/sorttable.h @@ -59,6 +59,8 @@ # define uint_t uint64_t # define _r r8 # define _w w8 +# define _r4 r +# define _w4 w #else # define extable_ent_size 8 # define compare_extable compare_extable_32 @@ -80,6 +82,8 @@ # define uint_t uint32_t # define _r r # define _w w +# define _r4 r +# define _w4 w #endif #if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED) @@ -98,7 +102,7 @@ pthread_t orc_sort_thread; static inline unsigned long orc_ip(const int *ip) { - return (unsigned long)ip + *ip; + return (unsigned long)ip + (int)_r4((uint32_t *)ip); } static int orc_sort_cmp(const void *_a, const void *_b) @@ -158,7 +162,7 @@ static void *sort_orctable(void *arg) /* initialize indices array, convert ip_table to absolute address */ for (i = 0; i < num_entries; i++) { idxs[i] = i; - tmp_orc_ip_table[i] = g_orc_ip_table[i] + i * sizeof(int); + tmp_orc_ip_table[i] = (int)_r4((uint32_t *)&g_orc_ip_table[i]) + i * sizeof(int); } memcpy(tmp_orc_table, g_orc_table, orc_size); @@ -169,7 +173,7 @@ static void *sort_orctable(void *arg) continue; /* convert back to relative address */ - g_orc_ip_table[i] = tmp_orc_ip_table[idxs[i]] - i * sizeof(int); + _w4(tmp_orc_ip_table[idxs[i]] - i * sizeof(int), (uint32_t *)&g_orc_ip_table[i]); g_orc_table[i] = tmp_orc_table[idxs[i]]; } @@ -256,14 +260,12 @@ static int do_sort(Elf_Ehdr *ehdr, #if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED) /* locate the ORC unwind tables */ if (!strcmp(secstrings + idx, ".orc_unwind_ip")) { - orc_ip_size = s->sh_size; - g_orc_ip_table = (int *)((void *)ehdr + - s->sh_offset); + orc_ip_size = _r(&s->sh_size); + g_orc_ip_table = (int *)((void *)ehdr + _r(&s->sh_offset)); } if (!strcmp(secstrings + idx, ".orc_unwind")) { - orc_size = s->sh_size; - g_orc_table = (struct orc_entry *)((void *)ehdr + - s->sh_offset); + orc_size = _r(&s->sh_size); + g_orc_table = (struct orc_entry *)((void *)ehdr + _r(&s->sh_offset)); } #endif } /* for loop */ -- 2.25.4