All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Ross Lagerwall <ross.lagerwall@citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v2 3/3] livepatch-build-tools: account for section alignment when calculating function size
Date: Tue, 28 Nov 2023 10:21:52 +0100	[thread overview]
Message-ID: <20231128092152.35039-4-roger.pau@citrix.com> (raw)
In-Reply-To: <20231128092152.35039-1-roger.pau@citrix.com>

Forcing function section alignment at the compiler level ensures that enough
space is present in the text section so that at least a jump can be encoded in
the old function body to switch to the newly loaded code payload.

Modify create-diff-object to account for any section alignment when calculating
the size of the old function.

When used with a suitable -falign-function compiler parameter on the Xen
hypervisor build this ensures that all functions have enough space to
accommodate for any control flow instructions plus a jump.

Note that while the rounding could be applied to all (text) symbols, it's not
required, as the size is only relevant for functions that are live patched, and
hence only do the rounding when calculating the old (previous) function size.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v2:
 - New in this version.
---
 common.h             | 2 ++
 create-diff-object.c | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/common.h b/common.h
index 0d3e5f1dd3b5..5ff9ef6ca8e9 100644
--- a/common.h
+++ b/common.h
@@ -37,6 +37,8 @@ extern char *childobj;
 	list_add_tail(&(_new)->list, (_list)); \
 }
 
+#define ROUNDUP(x, a) (((x) + (a) - 1) & ~((a) - 1))
+
 enum loglevel {
 	DEBUG,
 	NORMAL
diff --git a/create-diff-object.c b/create-diff-object.c
index d0e14e3a62bb..fed360a9aa68 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -2015,6 +2015,11 @@ static void livepatch_create_patches_sections(struct kpatch_elf *kelf,
 					ERROR("lookup_global_symbol %s",
 					      sym->name);
 			}
+
+			/* Take into account section alignment for padding. */
+			result.size = ROUNDUP(result.size,
+					      sym->sec->sh.sh_addralign);
+
 			log_debug("lookup for %s @ 0x%016lx len %lu\n",
 			          sym->name, result.value, result.size);
 
-- 
2.43.0



  parent reply	other threads:[~2023-11-28  9:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28  9:21 [PATCH v2 0/3] livepatch-build-tools: fixes for non GNU tools and alignment Roger Pau Monne
2023-11-28  9:21 ` [PATCH v2 1/3] livepatch-build-tools: do not use readlink -m option Roger Pau Monne
2023-11-28  9:21 ` [PATCH v2 2/3] livepatch-build-tools: remove usage of gawk Roger Pau Monne
2023-11-28  9:21 ` Roger Pau Monne [this message]
2023-12-06 14:46 ` [PATCH v2 0/3] livepatch-build-tools: fixes for non GNU tools and alignment Ross Lagerwall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231128092152.35039-4-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=konrad.wilk@oracle.com \
    --cc=ross.lagerwall@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.