All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>, Wei Liu <wl@xen.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Ross Lagerwall <ross.lagerwall@citrix.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v2 1/5] x86/livepatch: set function alignment to ensure minimal function size
Date: Fri, 1 Dec 2023 11:21:23 +0100	[thread overview]
Message-ID: <ZWmzo68abRmRtfwN@macbook> (raw)
In-Reply-To: <0d9bc0cd-3719-4961-ae7d-3e27508000a2@suse.com>

On Fri, Dec 01, 2023 at 10:41:45AM +0100, Jan Beulich wrote:
> On 01.12.2023 09:50, Roger Pau Monné wrote:
> > On Fri, Dec 01, 2023 at 07:53:29AM +0100, Jan Beulich wrote:
> >> On 30.11.2023 18:37, Roger Pau Monné wrote:
> >>> On Thu, Nov 30, 2023 at 05:55:07PM +0100, Jan Beulich wrote:
> >>>> On 28.11.2023 11:03, Roger Pau Monne wrote:
> >>>>> The minimal function size requirements for livepatch are either 5 bytes (for
> >>>>> jmp) or 9 bytes (for endbr + jmp).  Ensure that functions are always at least
> >>>>> that size by requesting the compiled to align the functions to 8 or 16 bytes,
> >>>>> depending on whether Xen is build with IBT support.
> >>>>
> >>>> How is alignment going to enforce minimum function size? If a function is
> >>>> last in a section, there may not be any padding added (ahead of linking at
> >>>> least). The trailing padding also isn't part of the function.
> >>>
> >>> If each function lives in it's own section (by using
> >>> -ffunction-sections), and each section is aligned, then I think we can
> >>> guarantee that there will always be enough padding space?
> >>>
> >>> Even the last function/section on the .text block would still be
> >>> aligned, and as long as the function alignment <= SECTION_ALIGN
> >>> there will be enough padding left.  I should add some build time
> >>> assert that CONFIG_CC_FUNCTION_ALIGNMENT <= SECTION_ALIGN.
> >>
> >> I'm not sure of there being a requirement for a section to be padded to
> >> its alignment. If the following section has smaller alignment, it could
> >> be made start earlier. Of course our linker scripts might guarantee
> >> this ...
> > 
> > I do think so, given our linker script arrangements for the .text
> > section:
> > 
> > DECL_SECTION(.text) {
> >     [...]
> > } PHDR(text) = 0x9090
> > 
> > . = ALIGN(SECTION_ALIGN);
> > 
> > The end of the text section is aligned to SECTION_ALIGN, so as long as
> > SECTION_ALIGN >= CONFIG_CC_FUNCTION_ALIGNMENT the alignment should
> > guarantee a minimal function size.
> > 
> > Do you think it would be clearer if I add the following paragraph:
> > 
> > "Given the Xen linker script arrangement of the .text section, we can
> > ensure that when all functions are aligned to the given boundary the
> > function size will always be a multiple of such alignment, even for
> > the last function in .text, as the linker script aligns the end of the
> > section to SECTION_ALIGN."
> 
> I think this would be useful to have there. Beyond that, assembly code
> also needs considering btw.

Assembly will get dealt with once we start to also have separate
sections for each assembly function.  We cannot patch assembly code at
the moment anyway, due to lack of debug symbols.

Thanks, Roger.


  reply	other threads:[~2023-12-01 10:21 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28 10:03 [PATCH v2 0/5] xen/x86: add testing for self modifying code and livepatch Roger Pau Monne
2023-11-28 10:03 ` [PATCH v2 1/5] x86/livepatch: set function alignment to ensure minimal function size Roger Pau Monne
2023-11-30 16:55   ` Jan Beulich
2023-11-30 17:37     ` Roger Pau Monné
2023-12-01  6:53       ` Jan Beulich
2023-12-01  8:50         ` Roger Pau Monné
2023-12-01  9:41           ` Jan Beulich
2023-12-01 10:21             ` Roger Pau Monné [this message]
2023-12-01 10:59               ` Jan Beulich
2023-12-01 11:31                 ` Roger Pau Monné
2023-12-01 12:59                   ` Jan Beulich
2023-12-05 13:42   ` Andrew Cooper
2023-12-05 15:01     ` Roger Pau Monné
2023-12-05 15:14       ` Jan Beulich
2023-12-05 15:36         ` Roger Pau Monné
2023-12-05 15:45           ` Jan Beulich
2023-11-28 10:03 ` [PATCH v2 2/5] automation/alpine: add elfutils-dev Roger Pau Monne
2023-11-30  2:56   ` Stefano Stabellini
2023-11-28 10:03 ` [PATCH v2 3/5] xen/x86: introduce self modifying code test Roger Pau Monne
2023-11-30  2:58   ` Stefano Stabellini
2023-12-01 11:52     ` Roger Pau Monné
2023-11-30 17:02   ` Jan Beulich
2023-12-01 12:08     ` Roger Pau Monné
2023-12-02  2:36       ` Stefano Stabellini
2023-11-28 10:03 ` [PATCH v2 4/5] x86/livepatch: introduce a basic live patch test to gitlab CI Roger Pau Monne
2023-12-05 11:49   ` Jan Beulich
2023-12-05 13:08     ` Roger Pau Monné
2023-12-05 13:23       ` Jan Beulich
2023-11-28 10:03 ` [PATCH v2 5/5] automation: add x86-64 livepatching test Roger Pau Monne
2023-11-30  3:03   ` Stefano Stabellini
2023-12-13 10:55     ` Roger Pau Monné
2023-12-14  2:08       ` Stefano Stabellini

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=ZWmzo68abRmRtfwN@macbook \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=konrad.wilk@oracle.com \
    --cc=ross.lagerwall@citrix.com \
    --cc=wl@xen.org \
    --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.