<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/arch/x86/kernel/alternative.c, branch linux-5.13.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.13.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.13.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2021-06-03T14:33:09Z</updated>
<entry>
<title>x86/alternative: Optimize single-byte NOPs at an arbitrary position</title>
<updated>2021-06-03T14:33:09Z</updated>
<author>
<name>Borislav Petkov</name>
</author>
<published>2021-06-01T15:51:22Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2b31e8ed96b260ce2c22bd62ecbb9458399e3b62'/>
<id>urn:sha1:2b31e8ed96b260ce2c22bd62ecbb9458399e3b62</id>
<content type='text'>
Up until now the assumption was that an alternative patching site would
have some instructions at the beginning and trailing single-byte NOPs
(0x90) padding. Therefore, the patching machinery would go and optimize
those single-byte NOPs into longer ones.

However, this assumption is broken on 32-bit when code like
hv_do_hypercall() in hyperv_init() would use the ratpoline speculation
killer CALL_NOSPEC. The 32-bit version of that macro would align certain
insns to 16 bytes, leading to the compiler issuing a one or more
single-byte NOPs, depending on the holes it needs to fill for alignment.

That would lead to the warning in optimize_nops() to fire:

  ------------[ cut here ]------------
  Not a NOP at 0xc27fb598
   WARNING: CPU: 0 PID: 0 at arch/x86/kernel/alternative.c:211 optimize_nops.isra.13

due to that function verifying whether all of the following bytes really
are single-byte NOPs.

Therefore, carve out the NOP padding into a separate function and call
it for each NOP range beginning with a single-byte NOP.

Fixes: 23c1ad538f4f ("x86/alternatives: Optimize optimize_nops()")
Reported-by: Richard Narron &lt;richard@aaazen.com&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Acked-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt;
Link: https://bugzilla.kernel.org/show_bug.cgi?id=213301
Link: https://lkml.kernel.org/r/20210601212125.17145-1-bp@alien8.de
</content>
</entry>
<entry>
<title>Merge tag 'x86-mm-2021-04-29' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip</title>
<updated>2021-04-29T18:41:43Z</updated>
<author>
<name>Linus Torvalds</name>
</author>
<published>2021-04-29T18:41:43Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=635de956a7f5a6ffcb04f29d70630c64c717b56b'/>
<id>urn:sha1:635de956a7f5a6ffcb04f29d70630c64c717b56b</id>
<content type='text'>
Pull x86 tlb updates from Ingo Molnar:
 "The x86 MM changes in this cycle were:

   - Implement concurrent TLB flushes, which overlaps the local TLB
     flush with the remote TLB flush.

     In testing this improved sysbench performance measurably by a
     couple of percentage points, especially if TLB-heavy security
     mitigations are active.

   - Further micro-optimizations to improve the performance of TLB
     flushes"

* tag 'x86-mm-2021-04-29' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  smp: Micro-optimize smp_call_function_many_cond()
  smp: Inline on_each_cpu_cond() and on_each_cpu()
  x86/mm/tlb: Remove unnecessary uses of the inline keyword
  cpumask: Mark functions as pure
  x86/mm/tlb: Do not make is_lazy dirty for no reason
  x86/mm/tlb: Privatize cpu_tlbstate
  x86/mm/tlb: Flush remote and local TLBs concurrently
  x86/mm/tlb: Open-code on_each_cpu_cond_mask() for tlb_is_not_lazy()
  x86/mm/tlb: Unify flush_tlb_func_local() and flush_tlb_func_remote()
  smp: Run functions concurrently in smp_call_function_many_cond()
</content>
</entry>
<entry>
<title>x86/alternatives: Optimize optimize_nops()</title>
<updated>2021-04-02T10:41:17Z</updated>
<author>
<name>Peter Zijlstra</name>
</author>
<published>2021-03-26T15:12:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=23c1ad538f4f371bdb67d8a112314842d5db7e5a'/>
<id>urn:sha1:23c1ad538f4f371bdb67d8a112314842d5db7e5a</id>
<content type='text'>
Currently, optimize_nops() scans to see if the alternative starts with
NOPs. However, the emit pattern is:

  141:	\oldinstr
  142:	.skip (len-(142b-141b)), 0x90

That is, when 'oldinstr' is short, the tail is padded with NOPs. This case
never gets optimized.

Rewrite optimize_nops() to replace any trailing string of NOPs inside
the alternative to larger NOPs. Also run it irrespective of patching,
replacing NOPs in both the original and replaced code.

A direct consequence is that 'padlen' becomes superfluous, so remove it.

 [ bp:
   - Adjust commit message
   - remove a stale comment about needing to pad
   - add a comment in optimize_nops()
   - exit early if the NOP verif. loop catches a mismatch - function
     should not not add NOPs in that case
   - fix the "optimized NOPs" offsets output ]

Signed-off-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Signed-off-by: Ingo Molnar &lt;mingo@kernel.org&gt;
Link: https://lkml.kernel.org/r/20210326151259.442992235@infradead.org
</content>
</entry>
<entry>
<title>Merge branch 'x86/cpu' into WIP.x86/core, to merge the NOP changes &amp; resolve a semantic conflict</title>
<updated>2021-04-02T10:36:30Z</updated>
<author>
<name>Ingo Molnar</name>
</author>
<published>2021-04-02T10:34:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b1f480bc0686e65d5413c035bd13af2ea4888784'/>
<id>urn:sha1:b1f480bc0686e65d5413c035bd13af2ea4888784</id>
<content type='text'>
Conflict-merge this main commit in essence:

  a89dfde3dc3c: ("x86: Remove dynamic NOP selection")

With this upstream commit:

  b90829704780: ("bpf: Use NOP_ATOMIC5 instead of emit_nops(&amp;prog, 5) for BPF_TRAMP_F_CALL_ORIG")

Semantic merge conflict:

  arch/x86/net/bpf_jit_comp.c

  - memcpy(prog, ideal_nops[NOP_ATOMIC5], X86_PATCH_SIZE);
  + memcpy(prog, x86_nops[5], X86_PATCH_SIZE);

Signed-off-by: Ingo Molnar &lt;mingo@kernel.org&gt;
</content>
</entry>
<entry>
<title>Merge 'x86/alternatives'</title>
<updated>2021-03-31T16:04:19Z</updated>
<author>
<name>Borislav Petkov</name>
</author>
<published>2021-03-31T16:04:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f2ac256b9a8b7e79847efcd82bd10fd876369b9f'/>
<id>urn:sha1:f2ac256b9a8b7e79847efcd82bd10fd876369b9f</id>
<content type='text'>
Pick up dependent changes.

Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
</content>
</entry>
<entry>
<title>x86: Add insn_decode_kernel()</title>
<updated>2021-03-31T14:20:22Z</updated>
<author>
<name>Peter Zijlstra</name>
</author>
<published>2021-03-26T15:12:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=52fa82c21f64e900a72437269a5cc9e0034b424e'/>
<id>urn:sha1:52fa82c21f64e900a72437269a5cc9e0034b424e</id>
<content type='text'>
Add a helper to decode kernel instructions; there's no point in
endlessly repeating those last two arguments.

Signed-off-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Link: https://lkml.kernel.org/r/20210326151259.379242587@infradead.org
</content>
</entry>
<entry>
<title>x86: Remove dynamic NOP selection</title>
<updated>2021-03-15T15:24:59Z</updated>
<author>
<name>Peter Zijlstra</name>
</author>
<published>2021-03-12T11:32:54Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a89dfde3dc3c2dbf56910af75e2d8b11ec5308f6'/>
<id>urn:sha1:a89dfde3dc3c2dbf56910af75e2d8b11ec5308f6</id>
<content type='text'>
This ensures that a NOP is a NOP and not a random other instruction that
is also a NOP. It allows simplification of dynamic code patching that
wants to verify existing code before writing new instructions (ftrace,
jump_label, static_call, etc..).

Differentiating on NOPs is not a feature.

This pessimises 32bit (DONTCARE) and 32bit on 64bit CPUs (CARELESS).
32bit is not a performance target.

Everything x86_64 since AMD K10 (2007) and Intel IvyBridge (2012) is
fine with using NOPL (as opposed to prefix NOP). And per FEATURE_NOPL
being required for x86_64, all x86_64 CPUs can use NOPL. So stop
caring about NOPs, simplify things and get on with life.

[ The problem seems to be that some uarchs can only decode NOPL on a
single front-end port while others have severe decode penalties for
excessive prefixes. All modern uarchs can handle both, except Atom,
which has prefix penalties. ]

[ Also, much doubt you can actually measure any of this on normal
workloads. ]

After this, FEATURE_NOPL is unused except for required-features for
x86_64. FEATURE_K8 is only used for PTI.

 [ bp: Kernel build measurements showed ~0.3s slowdown on Sandybridge
   which is hardly a slowdown. Get rid of X86_FEATURE_K7, while at it. ]

Signed-off-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Acked-by: Alexei Starovoitov &lt;alexei.starovoitov@gmail.com&gt; # bpf
Acked-by: Linus Torvalds &lt;torvalds@linuxfoundation.org&gt;
Link: https://lkml.kernel.org/r/20210312115749.065275711@infradead.org
</content>
</entry>
<entry>
<title>x86/alternative: Use insn_decode()</title>
<updated>2021-03-15T10:25:38Z</updated>
<author>
<name>Borislav Petkov</name>
</author>
<published>2020-11-06T18:37:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=63c66cde7bbcc79aac14b25861c5b2495eede57b'/>
<id>urn:sha1:63c66cde7bbcc79aac14b25861c5b2495eede57b</id>
<content type='text'>
No functional changes, just simplification.

Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Link: https://lkml.kernel.org/r/20210304174237.31945-10-bp@alien8.de
</content>
</entry>
<entry>
<title>x86/paravirt: Have only one paravirt patch function</title>
<updated>2021-03-11T19:11:09Z</updated>
<author>
<name>Juergen Gross</name>
</author>
<published>2021-03-11T14:23:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=054ac8ad5ebe4a69e1f0e842483821ddbe560121'/>
<id>urn:sha1:054ac8ad5ebe4a69e1f0e842483821ddbe560121</id>
<content type='text'>
There is no need any longer to have different paravirt patch functions
for native and Xen. Eliminate native_patch() and rename
paravirt_patch_default() to paravirt_patch().

Signed-off-by: Juergen Gross &lt;jgross@suse.com&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Acked-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt;
Link: https://lkml.kernel.org/r/20210311142319.4723-15-jgross@suse.com
</content>
</entry>
<entry>
<title>x86/paravirt: Add new features for paravirt patching</title>
<updated>2021-03-11T18:51:49Z</updated>
<author>
<name>Juergen Gross</name>
</author>
<published>2021-03-11T14:23:13Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4e6292114c741221479046515b1aa8145cf1e3f6'/>
<id>urn:sha1:4e6292114c741221479046515b1aa8145cf1e3f6</id>
<content type='text'>
For being able to switch paravirt patching from special cased custom
code sequences to ALTERNATIVE handling some X86_FEATURE_* are needed
as new features. This enables to have the standard indirect pv call
as the default code and to patch that with the non-Xen custom code
sequence via ALTERNATIVE patching later.

Make sure paravirt patching is performed before alternatives patching.

Signed-off-by: Juergen Gross &lt;jgross@suse.com&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Acked-by: Peter Zijlstra (Intel) &lt;peterz@infradead.org&gt;
Link: https://lkml.kernel.org/r/20210311142319.4723-9-jgross@suse.com
</content>
</entry>
</feed>
