diff mbox

[v3,15/18] bug/x86/arm: Align bug_frames sections.

Message ID 1473626125-13683-16-git-send-email-konrad.wilk@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Konrad Rzeszutek Wilk Sept. 11, 2016, 8:35 p.m. UTC
Most of the WARN_ON or BUG_ON sections are properly aligned on
x86. However on ARM and on x86 assembler the macros don't include
any aligment information - hence they end up being the default
byte granularity.

On ARM32 it is paramount that the aligment is word-size (4)
otherwise if one tries to use (uint32_t*) access (such
as livepatch ELF relocations) we get a Data Abort.

Enforcing bug_frames to have the proper aligment across all
architectures and in both C and x86 makes them all the same.

Furthermore on x86 the bloat-o-meter detects that with this
change:

[konrad@char xen]$ ~/linux/scripts/bloat-o-meter xen-syms xen-syms.align4
add/remove: 0/0 grow/shrink: 3/14 up/down: 115/-1497 (-1382)
function                                     old     new   delta
mod_l1_entry                                1490    1587     +97
p2m_switch_domain_altp2m_by_id               520     533     +13
p2m_switch_vcpu_altp2m_by_id                 453     458      +5
machine_kexec                                263     261      -2
hvm_do_IRQ_dpci                              244     242      -2
sh_page_fault__guest_4                      8252    8192     -60
sh_audit_gw                                 1529    1462     -67
validate_gl3e                                337     264     -73
validate_gl4e                                449     375     -74
p2m_altp2m_lazy_copy                         730     652     -78
set_typed_p2m_entry                         1346    1259     -87
virt_to_xen_l2e                              491     365    -126
sh_x86_emulate_write__guest_4                443     288    -155
p2m_mem_access_check                        1733    1576    -157
sh_x86_emulate_cmpxchg__guest_4              512     349    -163
__get_gfn_type_access                        709     542    -167
map_pages_to_xen                            4430    4144    -286
Total: Before=1974033, After=1972651, chg -0.07%

We end up making the binary file a bit smaller.

On ARM32:
add/remove: 1/0 grow/shrink: 0/1 up/down: 384/-288 (96)
function                                     old     new   delta
gnttab_unpopulate_status_frames                -     384    +384
do_grant_table_op                          10808   10520    -288

And ARM64:
add/remove: 1/2 grow/shrink: 0/1 up/down: 4164/-4236 (-72)
function                                     old     new   delta
gnttab_map_grant_ref                           -    4164   +4164
do_grant_table_op                           9892    9836     -56
grant_map_exists                             300       -    -300
__gnttab_map_grant_ref                      3880       -   -3880

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
Cc: Julien Grall <julien.grall@arm.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>

v3: First submission. Replaces the "livepatch/elf: Adjust section aligment to word"
    patch.
---
 xen/include/asm-arm/bug.h | 1 +
 xen/include/asm-x86/bug.h | 1 +
 2 files changed, 2 insertions(+)

Comments

Jan Beulich Sept. 13, 2016, 9:21 a.m. UTC | #1
>>> On 11.09.16 at 22:35, <konrad.wilk@oracle.com> wrote:
> Furthermore on x86 the bloat-o-meter detects that with this
> change:
> 
> [konrad@char xen]$ ~/linux/scripts/bloat-o-meter xen-syms xen-syms.align4
> add/remove: 0/0 grow/shrink: 3/14 up/down: 115/-1497 (-1382)
> function                                     old     new   delta
> mod_l1_entry                                1490    1587     +97
> p2m_switch_domain_altp2m_by_id               520     533     +13
> p2m_switch_vcpu_altp2m_by_id                 453     458      +5
> machine_kexec                                263     261      -2
> hvm_do_IRQ_dpci                              244     242      -2
> sh_page_fault__guest_4                      8252    8192     -60
> sh_audit_gw                                 1529    1462     -67
> validate_gl3e                                337     264     -73
> validate_gl4e                                449     375     -74
> p2m_altp2m_lazy_copy                         730     652     -78
> set_typed_p2m_entry                         1346    1259     -87
> virt_to_xen_l2e                              491     365    -126
> sh_x86_emulate_write__guest_4                443     288    -155
> p2m_mem_access_check                        1733    1576    -157
> sh_x86_emulate_cmpxchg__guest_4              512     349    -163
> __get_gfn_type_access                        709     542    -167
> map_pages_to_xen                            4430    4144    -286
> Total: Before=1974033, After=1972651, chg -0.07%
> 
> We end up making the binary file a bit smaller.

I'm fine with the change, but I'm having a very hard time buying the
above: The change you do is to code used only in assembly files _and_
is not affecting .text (and I assume the sizes above are .text ones),
yet all the functions listed above live in C ones. I can't help thinking
that there must be something else going on, or that we had an actual
problem before this.

> --- a/xen/include/asm-x86/bug.h
> +++ b/xen/include/asm-x86/bug.h
> @@ -98,6 +98,7 @@ extern const struct bug_frame __start_bug_frames[],
>      .popsection
>  
>      .pushsection .bug_frames.\type, "a", @progbits
> +        .p2align 2
>          .L\@bf:
>          .long (.L\@ud - .L\@bf) + \
>                 ((\line >> BUG_LINE_LO_WIDTH) << BUG_DISP_WIDTH)

This ought to be accompanied by removing the enforcing of alignment
in xen.lds.S.

Jan
Konrad Rzeszutek Wilk Sept. 13, 2016, 7:26 p.m. UTC | #2
On Tue, Sep 13, 2016 at 03:21:04AM -0600, Jan Beulich wrote:
> >>> On 11.09.16 at 22:35, <konrad.wilk@oracle.com> wrote:
> > Furthermore on x86 the bloat-o-meter detects that with this
> > change:
> > 
> > [konrad@char xen]$ ~/linux/scripts/bloat-o-meter xen-syms xen-syms.align4
> > add/remove: 0/0 grow/shrink: 3/14 up/down: 115/-1497 (-1382)
> > function                                     old     new   delta
> > mod_l1_entry                                1490    1587     +97
> > p2m_switch_domain_altp2m_by_id               520     533     +13
> > p2m_switch_vcpu_altp2m_by_id                 453     458      +5
> > machine_kexec                                263     261      -2
> > hvm_do_IRQ_dpci                              244     242      -2
> > sh_page_fault__guest_4                      8252    8192     -60
> > sh_audit_gw                                 1529    1462     -67
> > validate_gl3e                                337     264     -73
> > validate_gl4e                                449     375     -74
> > p2m_altp2m_lazy_copy                         730     652     -78
> > set_typed_p2m_entry                         1346    1259     -87
> > virt_to_xen_l2e                              491     365    -126
> > sh_x86_emulate_write__guest_4                443     288    -155
> > p2m_mem_access_check                        1733    1576    -157
> > sh_x86_emulate_cmpxchg__guest_4              512     349    -163
> > __get_gfn_type_access                        709     542    -167
> > map_pages_to_xen                            4430    4144    -286
> > Total: Before=1974033, After=1972651, chg -0.07%
> > 
> > We end up making the binary file a bit smaller.
> 
> I'm fine with the change, but I'm having a very hard time buying the
> above: The change you do is to code used only in assembly files _and_

That is indeed fishy. I re-ran the test and got:

 ~/linux/scripts/bloat-o-meter /tmp/xen-syms.orig /tmp/xen-syms.p2malign 
add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0)
function                                     old     new   delta

which is more inline with what we expect.

> is not affecting .text (and I assume the sizes above are .text ones),
> yet all the functions listed above live in C ones. I can't help thinking
> that there must be something else going on, or that we had an actual
> problem before this.

I am not sure what I managed to screw up.
> 
> > --- a/xen/include/asm-x86/bug.h
> > +++ b/xen/include/asm-x86/bug.h
> > @@ -98,6 +98,7 @@ extern const struct bug_frame __start_bug_frames[],
> >      .popsection
> >  
> >      .pushsection .bug_frames.\type, "a", @progbits
> > +        .p2align 2
> >          .L\@bf:
> >          .long (.L\@ud - .L\@bf) + \
> >                 ((\line >> BUG_LINE_LO_WIDTH) << BUG_DISP_WIDTH)
> 
> This ought to be accompanied by removing the enforcing of alignment
> in xen.lds.S.

/me nods. Done!
> 
> Jan
>
diff mbox

Patch

diff --git a/xen/include/asm-arm/bug.h b/xen/include/asm-arm/bug.h
index 68353e1..773d63e 100644
--- a/xen/include/asm-arm/bug.h
+++ b/xen/include/asm-arm/bug.h
@@ -52,6 +52,7 @@  struct bug_frame {
          ".popsection\n"                                                    \
          ".pushsection .bug_frames." __stringify(type) ", \"a\", %progbits\n"\
          "4:\n"                                                             \
+         ".align 4\n"                                                       \
          ".long (1b - 4b)\n"                                                \
          ".long (2b - 4b)\n"                                                \
          ".long (3b - 4b)\n"                                                \
diff --git a/xen/include/asm-x86/bug.h b/xen/include/asm-x86/bug.h
index c5d2d4c..9bb4a19 100644
--- a/xen/include/asm-x86/bug.h
+++ b/xen/include/asm-x86/bug.h
@@ -98,6 +98,7 @@  extern const struct bug_frame __start_bug_frames[],
     .popsection
 
     .pushsection .bug_frames.\type, "a", @progbits
+        .p2align 2
         .L\@bf:
         .long (.L\@ud - .L\@bf) + \
                ((\line >> BUG_LINE_LO_WIDTH) << BUG_DISP_WIDTH)