All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@kernel.org>
To: Andy Lutomirski <luto@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Peter Anvin <hpa@zytor.com>,
	the arch/x86 maintainers <x86@kernel.org>,
	One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>,
	Borislav Petkov <bp@alien8.de>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Brian Gerst <brgerst@gmail.com>,
	Matthew Whitehead <tedheadster@gmail.com>,
	Henrique de Moraes Holschuh <hmh@hmh.eng.br>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: [PATCH v2 5/6] x86/xen: Add a Xen-specific sync_core() implementation
Date: Fri, 2 Dec 2016 19:03:43 +0100	[thread overview]
Message-ID: <20161202180343.gehqor7lgtmzwqq3@pd.tnic> (raw)
In-Reply-To: <CALCETrXCLLW9pd=h7dZ0u2oBSiRBJOBkxvEq2iz=Z8aTVtrZ=w@mail.gmail.com>

On Fri, Dec 02, 2016 at 09:38:38AM -0800, Andy Lutomirski wrote:
> apply_alternatives, unfortunately.  It's performance-critical because
> it's intensely stupid and does sync_core() for every single patch.
> Fixing that would be nice, too.

So I did experiment at the time to batch that sync_core() and interrupts
disabling in text_poke_early() but that amounted to almost nothing.
That's why I didn't bother chasing this further. I can try to dig out
that old thread...

/me goes and searches...

ah, here's something:

SNB:
* before:
[    0.011707] SMP alternatives: Starting apply_alternatives...
[    0.011784] SMP alternatives: done.
[    0.011806] Freeing SMP alternatives: 20k freed

* after:
[    0.011699] SMP alternatives: Starting apply_alternatives...
[    0.011721] SMP alternatives: done.
[    0.011743] Freeing SMP alternatives: 20k freed

-> 63 microseconds speedup


* kvm guest:
* before:
[    0.017005] SMP alternatives: Starting apply_alternatives...
[    0.019024] SMP alternatives: done.
[    0.020119] Freeing SMP alternatives: 20k freed

* after:
[    0.015008] SMP alternatives: Starting apply_alternatives...
[    0.016029] SMP alternatives: done.
[    0.017118] Freeing SMP alternatives: 20k freed

-> ~3 milliseconds speedup

---

I tried something simple like this:

---
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 1850592f4700..f4d5689ea503 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -253,10 +253,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
                                         struct alt_instr *end)
 {
        struct alt_instr *a;
+       unsigned long flags;
        u8 *instr, *replacement;
        u8 insnbuf[MAX_PATCH_LEN];

        DPRINTK("%s: alt table %p -> %p\n", __func__, start, end);
+
+       local_irq_save(flags);
        /*
         * The scan order should be from start to end. A later scanned
         * alternative code can overwrite a previous scanned alternative code.
@@ -284,8 +287,10 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
                add_nops(insnbuf + a->replacementlen,
                         a->instrlen - a->replacementlen);

-               text_poke_early(instr, insnbuf, a->instrlen);
+               memcpy(instr, insnbuf, a->instrlen);
        }
+       sync_core();
+       local_irq_restore(flags);
 }

 #ifdef CONFIG_SMP
---

I could try and redo the measurements again but I doubt it'll be any
different. Unless I haven't made a mistake somewhere...

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

  parent reply	other threads:[~2016-12-02 18:11 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-30 20:34 [PATCH 0/4] CPUID-less CPU fixes and improvements Andy Lutomirski
2016-11-30 20:34 ` [PATCH 1/4] x86/asm/32: Make sync_core() handle missing CPUID on all 32-bit kernels Andy Lutomirski
2016-11-30 20:34 ` [PATCH 2/4] Revert "x86/boot: Fail the boot if !M486 and CPUID is missing" Andy Lutomirski
2016-12-01  5:53   ` Peter Zijlstra
2016-12-01  9:02     ` Borislav Petkov
2016-12-01 10:07       ` Thomas Gleixner
2016-12-01 11:15         ` [PATCH] x86/CPU: Add X86_FEATURE_CPUID Borislav Petkov
2016-12-01 17:00           ` Andy Lutomirski
2016-12-02  0:33       ` [PATCH 2/4] Revert "x86/boot: Fail the boot if !M486 and CPUID is missing" Andy Lutomirski
2016-12-01 17:00     ` Andy Lutomirski
2016-11-30 20:34 ` [PATCH 3/4] x86/microcode/intel: Replace sync_core() with cpuid_eax(1) Andy Lutomirski
2016-12-01  9:11   ` Borislav Petkov
2016-11-30 20:34 ` [PATCH 4/4] x86/asm: Change sync_core() to use MOV to CR2 to serialize Andy Lutomirski
2016-12-01  9:22   ` Borislav Petkov
2016-12-01 17:08     ` Andy Lutomirski
2016-12-01 17:46       ` Andrew Cooper
2016-12-02  7:34     ` Ingo Molnar
2016-12-02  0:34 ` [PATCH v2 0/6] CPUID-less CPU/sync_core fixes and improvements Andy Lutomirski
2016-12-02  0:34   ` [PATCH v2 1/6] x86/asm/32: Make sync_core() handle missing CPUID on all 32-bit kernels Andy Lutomirski
2016-12-02  0:34   ` [PATCH v2 2/6] Revert "x86/boot: Fail the boot if !M486 and CPUID is missing" Andy Lutomirski
2016-12-02  0:34   ` [PATCH v2 3/6] x86/microcode/intel: Replace sync_core() with cpuid_eax(1) Andy Lutomirski
2016-12-02  0:35   ` [PATCH v2 4/6] x86/paravirt: Make sync_core() be a paravirt op Andy Lutomirski
2016-12-02  0:35   ` [PATCH v2 5/6] x86/xen: Add a Xen-specific sync_core() implementation Andy Lutomirski
2016-12-02 11:44     ` Andrew Cooper
2016-12-02 11:44     ` Andrew Cooper
2016-12-02 17:07       ` Andy Lutomirski
2016-12-02 17:07       ` Andy Lutomirski
2016-12-02 17:16         ` Andrew Cooper
2016-12-02 17:16         ` Andrew Cooper
2016-12-02 17:23           ` Andy Lutomirski
2016-12-02 17:26             ` Andrew Cooper
2016-12-02 17:26             ` Andrew Cooper
2016-12-02 17:23           ` Andy Lutomirski
2016-12-02 18:50       ` Boris Ostrovsky
2016-12-02 18:50       ` Boris Ostrovsky
2016-12-02 19:34         ` Andy Lutomirski
2016-12-02 19:34         ` Andy Lutomirski
2016-12-02 20:09       ` Boris Ostrovsky
2016-12-02 20:09         ` Boris Ostrovsky
2016-12-02 17:32     ` Linus Torvalds
2016-12-02 17:38       ` Andy Lutomirski
2016-12-02 17:53         ` Linus Torvalds
2016-12-02 18:03         ` Borislav Petkov [this message]
2016-12-02 18:27           ` Linus Torvalds
2016-12-02 18:50             ` Borislav Petkov
2016-12-02 19:03               ` Linus Torvalds
2016-12-02 19:20                 ` Borislav Petkov
2016-12-02 19:24                   ` Linus Torvalds
2016-12-02 19:28                     ` Borislav Petkov
2016-12-03 15:02                       ` [PATCH] x86/alternatives: Do not use sync_core() to serialize I$ Borislav Petkov
2016-12-03 17:05                         ` Andy Lutomirski
2016-12-20  7:58                         ` [tip:x86/urgent] " tip-bot for Borislav Petkov
2016-12-20  9:35                         ` tip-bot for Borislav Petkov
2016-12-02 19:30                     ` [PATCH v2 5/6] x86/xen: Add a Xen-specific sync_core() implementation Andy Lutomirski
2016-12-02 19:35                       ` Linus Torvalds
2016-12-02 20:41                         ` Andy Lutomirski
2016-12-02 21:10                           ` Linus Torvalds
2016-12-02 22:55                             ` Andy Lutomirski
2016-12-02 23:09                               ` Linus Torvalds
2016-12-02 19:23                 ` Andy Lutomirski
2016-12-02 19:30                   ` Borislav Petkov
2016-12-03 12:44         ` Borislav Petkov
2016-12-02  0:35   ` [PATCH v2 6/6] x86/asm: Change sync_core() to use MOV to CR2 to serialize Andy Lutomirski
2016-12-02  0:36 ` [PATCH 0/4] CPUID-less CPU fixes and improvements Andy Lutomirski
2016-12-02 10:17   ` Ingo Molnar

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=20161202180343.gehqor7lgtmzwqq3@pd.tnic \
    --to=bp@kernel.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=hmh@hmh.eng.br \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tedheadster@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.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.