From nobody Mon Feb 9 20:13:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1712774563; cv=none; d=zohomail.com; s=zohoarc; b=ne6T1Il0bkUFRlm9GyVU2ozkUm5HNeOttAAcPd0VaYvcpY32RU7yD6IwPK+lS5EmYN6h3/xGUrQCw6TIzo5Y7X3NKTZ6g7/m5evEdBitPfzK7HjhAcGJVU/xT3MJW5lhZkrxpeiDiOvgJUlOmVcxpIT2U5zSwC1TVoc5xQ+FnNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712774563; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ukDAjmcMpf650PdUhUxZlNvZY089aJWuIQPAP0FBqkA=; b=JRm6qBP+8J1DoSFUOYhgexgsZnYFGFtfYssul6W5I0SSuTc66kT8sB7bOlzN6QeCodh14rnAYnfr08usOxVLnzs1bsf6c6eVAASc3BeYlN6PsQrYInyy3tBs4rDffuzCUtu/wMId1erJEHkE9h34BfxzdIlwC6DjBAb2PSpRvWo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1712774563160497.32144524479406; Wed, 10 Apr 2024 11:42:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.703547.1099225 (Exim 4.92) (envelope-from ) id 1ructu-0002lb-T9; Wed, 10 Apr 2024 18:42:26 +0000 Received: by outflank-mailman (output) from mailman id 703547.1099225; Wed, 10 Apr 2024 18:42:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ructu-0002kv-O0; Wed, 10 Apr 2024 18:42:26 +0000 Received: by outflank-mailman (input) for mailman id 703547; Wed, 10 Apr 2024 18:42:25 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ructt-0002iK-Ph for xen-devel@lists.xenproject.org; Wed, 10 Apr 2024 18:42:25 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 122a496e-f76a-11ee-94a3-07e782e9044d; Wed, 10 Apr 2024 20:42:23 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-516d0c004b1so8389024e87.2 for ; Wed, 10 Apr 2024 11:42:23 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id gv18-20020a170906f11200b00a4e1a9e1ab4sm7228404ejb.157.2024.04.10.11.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 11:42:22 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 122a496e-f76a-11ee-94a3-07e782e9044d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1712774543; x=1713379343; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ukDAjmcMpf650PdUhUxZlNvZY089aJWuIQPAP0FBqkA=; b=s7kUJhfHxwmHk+Y5ecvys////TIrzyO14lA7bpavZp2T8PC/CGRv/cxOPjGioXxA8r OyehLb5mOmOnbRuAEo5DRMHxH5lU8HG3bEyP0AdUq9XztO/AHxD9mWLEArnUBy12jhff Tgn5DA69Pur/epPiKcBPVNdPM0j2nO1+wf10k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712774543; x=1713379343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ukDAjmcMpf650PdUhUxZlNvZY089aJWuIQPAP0FBqkA=; b=ASXQ7UBSXKELtbp82gTEGtxnjU7ttRz0DXBjmXlXDjHbcX+sjAn3rV7apv4kqx8fx4 NDsjyMDU0iXByW4/EhYBU44pRoWxT9cF5A20Zb0JyVQ9sUC2Ac5SBtXjUq7jNuYUzU0m mFEgYMoj0cJbp5sTBjHOe48JBn0bUylogk+x8XAxzujvpU+kY/abOed+W3jLK98ytCQB +9+k9BlETpwJx33eCX4gRpnZeqQN55FQX+Y+wNa9D7GnoBmn3YGK/xFITV/N3ghcSeEr LGRQXwUJZOfQ0A50e3HNBGM7frAim8Elljdld5R/A1dMBzBDPMSRWuoxKKSoytcsVug8 QD/w== X-Gm-Message-State: AOJu0Yyo9IOgS0VhgsAuj6pia+sM+MxjD2obRMeNcfgJLebYtGMumYMX 5M4UFkd0ZAFZyQUZizpgeCHrzT9oehbrRWqi2zs+gcCiHaU7QC6sTCrWyFg81IzpCi1vesHtwv1 H7Lg= X-Google-Smtp-Source: AGHT+IGDaH/9QknP6CAoXXWRXtTwYi3Gfw6NQpu6oJ7f3XDm1pyEE9CcWbhZL6WN8tVegXQD46jt7g== X-Received: by 2002:ac2:5df9:0:b0:516:afb5:6a71 with SMTP id z25-20020ac25df9000000b00516afb56a71mr2372510lfq.67.1712774542977; Wed, 10 Apr 2024 11:42:22 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Ross Lagerwall , Jan Beulich , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio , Konrad Rzeszutek Wilk Subject: [PATCH v2 2/4] xen/virtual-region: Rework how bugframe linkage works Date: Wed, 10 Apr 2024 19:42:15 +0100 Message-Id: <20240410184217.1482366-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240410184217.1482366-1-andrew.cooper3@citrix.com> References: <20240410184217.1482366-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1712774565037100001 The start/stop1/etc linkage scheme predates struct virtual_region, and as setup_virtual_regions() shows, it's awkward to express in the new scheme. Change the linker to provide explicit start/stop symbols for each bugframe type, and change virtual_region to have a stop pointer rather than a count. This marginly simplifies both do_bug_frame()s and prepare_payload(), but it massively simplifies setup_virtual_regions() by allowing the compiler to initialise the .frame[] array at build time. virtual_region.c is the only user of the linker symbols, and this is unlike= ly to change given the purpose of struct virtual_region, so move their externs out of bug.h No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Ross Lagerwall Reviewed-by: Jan Beulich Acked-by: Michal Orzel --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko CC: Shawn Anastasio CC: Konrad Rzeszutek Wilk CC: Ross Lagerwall --- xen/arch/arm/traps.c | 5 ++-- xen/common/bug.c | 5 ++-- xen/common/livepatch.c | 7 +++-- xen/common/virtual_region.c | 45 ++++++++++++++------------------ xen/include/xen/bug.h | 6 ----- xen/include/xen/virtual_region.h | 3 +-- xen/include/xen/xen.lds.h | 8 +++++- 7 files changed, 35 insertions(+), 44 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 9cffe7f79005..a8039087c805 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1226,10 +1226,9 @@ int do_bug_frame(const struct cpu_user_regs *regs, v= addr_t pc) for ( id =3D 0; id < BUGFRAME_NR; id++ ) { const struct bug_frame *b; - unsigned int i; =20 - for ( i =3D 0, b =3D region->frame[id].bugs; - i < region->frame[id].n_bugs; b++, i++ ) + for ( b =3D region->frame[id].start; + b < region->frame[id].stop; b++ ) { if ( ((vaddr_t)bug_loc(b)) =3D=3D pc ) { diff --git a/xen/common/bug.c b/xen/common/bug.c index c43e7c439735..b7c5d8fd4d4a 100644 --- a/xen/common/bug.c +++ b/xen/common/bug.c @@ -25,10 +25,9 @@ int do_bug_frame(const struct cpu_user_regs *regs, unsig= ned long pc) for ( id =3D 0; id < BUGFRAME_NR; id++ ) { const struct bug_frame *b; - size_t i; =20 - for ( i =3D 0, b =3D region->frame[id].bugs; - i < region->frame[id].n_bugs; b++, i++ ) + for ( b =3D region->frame[id].start; + b < region->frame[id].stop; b++ ) { if ( bug_loc(b) =3D=3D pc ) { diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index cabfb6391117..351a3e0b9a60 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -804,12 +804,11 @@ static int prepare_payload(struct payload *payload, if ( !sec ) continue; =20 - if ( !section_ok(elf, sec, sizeof(*region->frame[i].bugs)) ) + if ( !section_ok(elf, sec, sizeof(*region->frame[i].start)) ) return -EINVAL; =20 - region->frame[i].bugs =3D sec->load_addr; - region->frame[i].n_bugs =3D sec->sec->sh_size / - sizeof(*region->frame[i].bugs); + region->frame[i].start =3D sec->load_addr; + region->frame[i].stop =3D sec->load_addr + sec->sec->sh_size; } =20 sec =3D livepatch_elf_sec_by_name(elf, ".altinstructions"); diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c index 142f21e18153..7d8bdeb61282 100644 --- a/xen/common/virtual_region.c +++ b/xen/common/virtual_region.c @@ -9,12 +9,25 @@ #include #include =20 +extern const struct bug_frame + __start_bug_frames_0[], __stop_bug_frames_0[], + __start_bug_frames_1[], __stop_bug_frames_1[], + __start_bug_frames_2[], __stop_bug_frames_2[], + __start_bug_frames_3[], __stop_bug_frames_3[]; + static struct virtual_region core =3D { .list =3D LIST_HEAD_INIT(core.list), .text_start =3D _stext, .text_end =3D _etext, .rodata_start =3D _srodata, .rodata_end =3D _erodata, + + .frame =3D { + { __start_bug_frames_0, __stop_bug_frames_0 }, + { __start_bug_frames_1, __stop_bug_frames_1 }, + { __start_bug_frames_2, __stop_bug_frames_2 }, + { __start_bug_frames_3, __stop_bug_frames_3 }, + }, }; =20 /* Becomes irrelevant when __init sections are cleared. */ @@ -22,6 +35,13 @@ static struct virtual_region core_init __initdata =3D { .list =3D LIST_HEAD_INIT(core_init.list), .text_start =3D _sinittext, .text_end =3D _einittext, + + .frame =3D { + { __start_bug_frames_0, __stop_bug_frames_0 }, + { __start_bug_frames_1, __stop_bug_frames_1 }, + { __start_bug_frames_2, __stop_bug_frames_2 }, + { __start_bug_frames_3, __stop_bug_frames_3 }, + }, }; =20 /* @@ -133,31 +153,6 @@ void __init unregister_init_virtual_region(void) void __init setup_virtual_regions(const struct exception_table_entry *star= t, const struct exception_table_entry *end) { - size_t sz; - unsigned int i; - static const struct bug_frame *const __initconstrel bug_frames[] =3D { - __start_bug_frames, - __stop_bug_frames_0, - __stop_bug_frames_1, - __stop_bug_frames_2, - __stop_bug_frames_3, - NULL - }; - - for ( i =3D 1; bug_frames[i]; i++ ) - { - const struct bug_frame *s; - - s =3D bug_frames[i - 1]; - sz =3D bug_frames[i] - s; - - core.frame[i - 1].n_bugs =3D sz; - core.frame[i - 1].bugs =3D s; - - core_init.frame[i - 1].n_bugs =3D sz; - core_init.frame[i - 1].bugs =3D s; - } - core_init.ex =3D core.ex =3D start; core_init.ex_end =3D core.ex_end =3D end; =20 diff --git a/xen/include/xen/bug.h b/xen/include/xen/bug.h index 77fe1e1ba840..99814c4bef36 100644 --- a/xen/include/xen/bug.h +++ b/xen/include/xen/bug.h @@ -155,12 +155,6 @@ int do_bug_frame(const struct cpu_user_regs *regs, uns= igned long pc); =20 #endif /* CONFIG_GENERIC_BUG_FRAME */ =20 -extern const struct bug_frame __start_bug_frames[], - __stop_bug_frames_0[], - __stop_bug_frames_1[], - __stop_bug_frames_2[], - __stop_bug_frames_3[]; - #endif /* !__ASSEMBLY__ */ =20 #endif /* __XEN_BUG_H__ */ diff --git a/xen/include/xen/virtual_region.h b/xen/include/xen/virtual_reg= ion.h index dcdc95ba494c..c8a90e3ef26d 100644 --- a/xen/include/xen/virtual_region.h +++ b/xen/include/xen/virtual_region.h @@ -29,8 +29,7 @@ struct virtual_region symbols_lookup_t *symbols_lookup; =20 struct { - const struct bug_frame *bugs; /* The pointer to array of bug frame= s. */ - size_t n_bugs; /* The number of them. */ + const struct bug_frame *start, *stop; /* Pointers to array of bug = frames. */ } frame[BUGFRAME_NR]; =20 const struct exception_table_entry *ex; diff --git a/xen/include/xen/xen.lds.h b/xen/include/xen/xen.lds.h index 7ab7aa567872..a17810bb286f 100644 --- a/xen/include/xen/xen.lds.h +++ b/xen/include/xen/xen.lds.h @@ -115,13 +115,19 @@ /* List of constructs other than *_SECTIONS in alphabetical order. */ =20 #define BUGFRAMES \ - __start_bug_frames =3D .; \ + __start_bug_frames_0 =3D .; \ *(.bug_frames.0) \ __stop_bug_frames_0 =3D .; \ + \ + __start_bug_frames_1 =3D .; \ *(.bug_frames.1) \ __stop_bug_frames_1 =3D .; \ + \ + __start_bug_frames_2 =3D .; \ *(.bug_frames.2) \ __stop_bug_frames_2 =3D .; \ + \ + __start_bug_frames_3 =3D .; \ *(.bug_frames.3) \ __stop_bug_frames_3 =3D .; =20 --=20 2.30.2