5.15.103-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 126/145 ext4: add ext4_sb_block_valid() refactored out of ext4_inode_block_valid()
In reply to Greg Kroah-HartmanFrom: Ritesh Harjani <[email protected]>
commit 6bc6c2bdf1baca6522b8d9ba976257d722423085 upstream.
This API will be needed at places where we don't have an inode for e.g. while freeing blocks in ext4_group_add_blocks()
--- fs/ext4/block_validity.c | 26 +++++++++++++++++--------- fs/ext4/ext4.h | 3 +++ 2 files changed, 20 insertions(+), 9 deletions(-)
fs/ext4/block_validity.c +17 -9
@@ -292,15 +292,10 @@ void ext4_release_system_zone(struct supcall_rcu (&system_blks->rcu, ext4_destroy_system_zone); } -/* -* Returns 1 if the passed-in block region (start_blk, -* start_blk+count) is valid; 0 if some part of the block region -* overlaps with some other filesystem metadata blocks. -*/ -int ext4_inode_block_valid (struct inode *inode,ext4_fsblk_t start_blk, -unsigned int count) +int ext4_sb_block_valid (struct super_block *sb,struct inode *inode, +ext4_fsblk_t start_blk,unsigned int count) { -struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb); +struct ext4_sb_info *sbi =EXT4_SB (sb);struct ext4_system_blocks *system_blks;struct ext4_system_zone *entry;struct rb_node *n;
@@ -329,7 +324,9 @@ int ext4_inode_block_valid(struct inodeelse if (start_blk >= (entry->start_blk + entry->count)) n = n->rb_right;else { - ret = (entry->ino == inode->i_ino); + ret =0 ; +if (inode) + ret = (entry->ino == inode->i_ino);break ; } }
@@ -338,6 +335,17 @@ out_rcu:return ret; } +/* +* Returns 1 if the passed-in block region (start_blk, +* start_blk+count) is valid; 0 if some part of the block region +* overlaps with some other filesystem metadata blocks. +*/ +int ext4_inode_block_valid (struct inode *inode,ext4_fsblk_t start_blk, +unsigned int count) +{ +return ext4_sb_block_valid (inode->i_sb, inode, start_blk, count); +} +int ext4_check_blockref (const char *function,unsigned int line,struct inode *inode,__le32 *p,unsigned int max) {
fs/ext4/ext4.h +3 -0
@@ -3698,6 +3698,9 @@ extern int ext4_inode_block_valid(struct unsigned int count);extern int ext4_check_blockref (const char *,unsigned int ,struct inode *,__le32 *,unsigned int ); +extern int ext4_sb_block_valid (struct super_block *sb,struct inode *inode, +ext4_fsblk_t start_blk,unsigned int count); +/* extents.c */ struct ext4_ext_path ;
Greg Kroah-Hartman
maintainerPATCH 127/145 ext4: add strict range checks while freeing blocks
In reply to Greg Kroah-HartmanFrom: Ritesh Harjani <[email protected]>
commit a00b482b82fb098956a5bed22bd7873e56f152f1 upstream.
Currently ext4_mb_clear_bb() & ext4_group_add_blocks() only checks whether the given block ranges (which is to be freed) belongs to any FS metadata blocks or not, of the block's respective block group. But to detect any FS error early, it is better to add more strict checkings in those functions which checks whether the given blocks belongs to any critical FS metadata or not within system-zone.
--- fs/ext4/mballoc.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
fs/ext4/mballoc.c +3 -13
@@ -5946,13 +5946,7 @@ do_more: goto error_return; } -if (in_range (ext4_block_bitmap (sb, gdp), block, count) || -in_range (ext4_inode_bitmap (sb, gdp), block, count) || -in_range (block,ext4_inode_table (sb, gdp), - sbi->s_itb_per_group) || -in_range (block + count -1 ,ext4_inode_table (sb, gdp), - sbi->s_itb_per_group)) { - +if (!ext4_inode_block_valid (inode, block, count)) {ext4_error (sb,"Freeing blocks in system zone - " "Block = %llu, count = %lu" , block, count);/* err = 0. ext4_std_error should be a no op */
@@ -6023,7 +6017,7 @@ do_more: NULL);if (err && err != -EOPNOTSUPP )ext4_msg (sb,KERN_WARNING ,"discard request in" -" group:%d block:%d count:%lu failed" +" group:%u block:%d count:%lu failed" " with %d" , block_group, bit, count, err); }else
@@ -6236,11 +6230,7 @@ int ext4_group_add_blocks(handle_t *hand goto error_return; } -if (in_range (ext4_block_bitmap (sb, desc), block, count) || -in_range (ext4_inode_bitmap (sb, desc), block, count) || -in_range (block,ext4_inode_table (sb, desc), sbi->s_itb_per_group) || -in_range (block + count -1 ,ext4_inode_table (sb, desc), - sbi->s_itb_per_group)) { +if (!ext4_sb_block_valid (sb,NULL , block, count)) {ext4_error (sb,"Adding blocks in system zones - " "Block = %llu, count = %lu" , block, count);
Greg Kroah-Hartman
maintainerPATCH 128/145 ext4: block range must be validated before use in ext4_mb_clear_bb()
In reply to Greg Kroah-HartmanFrom: Lukas Czerner <[email protected]>
commit 1e1c2b86ef86a8477fd9b9a4f48a6bfe235606f6 upstream.
Block range to free is validated in ext4_free_blocks() using ext4_inode_block_valid() and then it's passed to ext4_mb_clear_bb(). However in some situations on bigalloc file system the range might be adjusted after the validation in ext4_free_blocks() which can lead to troubles on corrupted file systems such as one found by syzkaller that resulted in the following BUG
kernel BUG at fs/ext4/ext4.h:3319!
PREEMPT SMP NOPTI
CPU: 28 PID: 4243 Comm: repro Kdump: loaded Not tainted 5.19.0-rc6+ #1 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1.fc35 04/01/2014 RIP: 0010:ext4_free_blocks+0x95e/0xa90 Call Trace: <TASK> ? lock_timer_base+0x61/0x80 ? __es_remove_extent+0x5a/0x760 ? __mod_timer+0x256/0x380 ? ext4_ind_truncate_ensure_credits+0x90/0x220 ext4_clear_blocks+0x107/0x1b0 ext4_free_data+0x15b/0x170 ext4_ind_truncate+0x214/0x2c0 ? _raw_spin_unlock+0x15/0x30 ? ext4_discard_preallocations+0x15a/0x410 ? ext4_journal_check_start+0xe/0x90 ? __ext4_journal_start_sb+0x2f/0x110 ext4_truncate+0x1b5/0x460 ? __ext4_journal_start_sb+0x2f/0x110 ext4_evict_inode+0x2b4/0x6f0 evict+0xd0/0x1d0 ext4_enable_quotas+0x11f/0x1f0 ext4_orphan_cleanup+0x3de/0x430 ? proc_create_seq_private+0x43/0x50 ext4_fill_super+0x295f/0x3ae0 ? snprintf+0x39/0x40 ? sget_fc+0x19c/0x330 ? ext4_reconfigure+0x850/0x850 get_tree_bdev+0x16d/0x260 vfs_get_tree+0x25/0xb0 path_mount+0x431/0xa70 __x64_sys_mount+0xe2/0x120 do_syscall_64+0x5b/0x80 ? do_user_addr_fault+0x1e2/0x670 ? exc_page_fault+0x70/0x170 entry_SYSCALL_64_after_hwframe+0x46/0xb0 RIP: 0033:0x7fdf4e512ace
Fix it by making sure that the block range is properly validated before used every time it changes in ext4_free_blocks() or ext4_mb_clear_bb().
--- fs/ext4/mballoc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
fs/ext4/mballoc.c +20 -1
@@ -5916,6 +5916,15 @@ static void ext4_mb_clear_bb(handle_t *h sbi =EXT4_SB (sb); +if (!(flags &EXT4_FREE_BLOCKS_VALIDATED ) && + !ext4_inode_block_valid (inode, block, count)) { +ext4_error (sb,"Freeing blocks in system zone - " +"Block = %llu, count = %lu" , block, count); +/* err = 0. ext4_std_error should be a no op */ + goto error_return; + } + flags |=EXT4_FREE_BLOCKS_VALIDATED ; + do_more: overflow =0 ;ext4_get_group_no_and_offset (sb, block, &block_group, &bit);
@@ -5932,6 +5941,8 @@ do_more: overflow =EXT4_C2B (sbi, bit) + count -EXT4_BLOCKS_PER_GROUP (sb); count -= overflow; +/* The range changed so it's no longer validated */ + flags &= ~EXT4_FREE_BLOCKS_VALIDATED ; } count_clusters =EXT4_NUM_B2C (sbi, count); bitmap_bh =ext4_read_block_bitmap (sb, block_group);
@@ -5946,7 +5957,8 @@ do_more: goto error_return; } -if (!ext4_inode_block_valid (inode, block, count)) { +if (!(flags &EXT4_FREE_BLOCKS_VALIDATED ) && + !ext4_inode_block_valid (inode, block, count)) {ext4_error (sb,"Freeing blocks in system zone - " "Block = %llu, count = %lu" , block, count);/* err = 0. ext4_std_error should be a no op */
@@ -6069,6 +6081,8 @@ do_more: block += count; count = overflow;put_bh (bitmap_bh); +/* The range changed so it's no longer validated */ + flags &= ~EXT4_FREE_BLOCKS_VALIDATED ; goto do_more; } error_return:
@@ -6115,6 +6129,7 @@ void ext4_free_blocks(handle_t *handle, "block = %llu, count = %lu", block, count);return ; } + flags |=EXT4_FREE_BLOCKS_VALIDATED ;ext4_debug ("freeing block %llu\n" , block);trace_ext4_free_blocks (inode, block, count, flags);
@@ -6146,6 +6161,8 @@ void ext4_free_blocks(handle_t *handle, block -= overflow; count += overflow; } +/* The range changed so it's no longer validated */ + flags &= ~EXT4_FREE_BLOCKS_VALIDATED ; } overflow =EXT4_LBLK_COFF (sbi, count);if (overflow) {
@@ -6156,6 +6173,8 @@ void ext4_free_blocks(handle_t *handle,return ; }else count += sbi->s_cluster_ratio - overflow; +/* The range changed so it's no longer validated */ + flags &= ~EXT4_FREE_BLOCKS_VALIDATED ; }if (!bh && (flags &EXT4_FREE_BLOCKS_FORGET )) {
Greg Kroah-Hartman
maintainerPATCH 129/145 arch: fix broken BuildID for arm64 and riscv
In reply to Greg Kroah-HartmanFrom: Masahiro Yamada <[email protected]>
commit 99cb0d917ffa1ab628bb67364ca9b162c07699b1 upstream.
Dennis Gilmore reports that the BuildID is missing in the arm64 vmlinux since commit 994b7ac1697b ("arm64: remove special treatment for the link order of head.o").
The issue is that the type of .notes section, which contains the BuildID, changed from NOTES to PROGBITS.
Ard Biesheuvel figured out that whichever object gets linked first gets to decide the type of a section. The PROGBITS type is the result of the compiler emitting .note.GNU-stack as PROGBITS rather than NOTE.
While Ard provided a fix for arm64, I want to fix this globally because the same issue is happening on riscv since commit 2348e6bf4421 ("riscv:
remove special treatment for the link order of head.o"). This problem will happen in general for other architectures if they start to drop unneeded entries from scripts/head-object-list.txt.
Discard .note.GNU-stack in include/asm-generic/vmlinux.lds.h.
Though the above "Fixes:" commits are not in this kernel, the conditions which lead to a missing Build ID in arm64 vmlinux are similar.
Evidence points to these conditions:
1. ld version > 2.36 (exact binutils commit documented in a494398bde27)
2. first object which gets linked (head.o) has a PROGBITS .note.GNU-stack segment
These conditions can be observed when:
- 5.15.60+ OR 5.10.136+ OR 5.4.210+
- AND ld version > 2.36
- AND arch=arm64
- AND CONFIG_MODVERSIONS=y
There are notable differences in the vmlinux elf files produced before(bad) and after(good) applying this series.
Good: p_type:PT_NOTE segment exists.
Bad: p_type:PT_NOTE segment is missing.
Good: sh_name_str:.notes section has sh_type:SHT_NOTE
Bad: sh_name_str:.notes section has sh_type:SHT_PROGBITS
readelf -n (as of v2.40) searches for Build Id
by processing only the very first note in sh_type:SHT_NOTE sections.
This was previously bisected to the stable backport of 0d362be5b142.
Follow-up experiments were discussed here: https://lore.kernel.org/all/[email protected]/
which strongly hints at condition 2.
--- include/asm-generic/vmlinux.lds.h | 5 +++++ 1 file changed, 5 insertions(+)
include/asm-generic/vmlinux.lds.h +5 -0
@@ -903,7 +903,12 @@#define PRINTK_INDEX #endif +/* +* Discard .note.GNU-stack, which is emitted as PROGBITS by the compiler. +* Otherwise, the type of .notes section would become PROGBITS instead of NOTES. +*/ #define NOTES \ + /DISCARD/ : { *(.note.GNU-stack) } \ .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \ __start_notes = .; \ KEEP(*(.note.*)) \
Greg Kroah-Hartman
maintainerPATCH 130/145 powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT
In reply to Greg Kroah-HartmanFrom: Michael Ellerman <[email protected]>
commit 4b9880dbf3bdba3a7c56445137c3d0e30aaa0a40 upstream.
The powerpc linker script explicitly includes .exit.text, because otherwise the link fails due to references from __bug_table and __ex_table. The code is freed (discarded) at runtime along with .init.text and data.
That has worked in the past despite powerpc not defining RUNTIME_DISCARD_EXIT because DISCARDS appears late in the powerpc linker script (line 410), and the explicit inclusion of .exit.text earlier (line 280) supersedes the discard.
However commit 99cb0d917ffa ("arch: fix broken BuildID for arm64 and riscv") introduced an earlier use of DISCARD as part of the RO_DATA macro (line 136). With binutils < 2.36 that causes the DISCARD directives later in the script to be applied earlier [1], causing .exit.text to actually be discarded at link time, leading to build errors:
'.exit.text' referenced in section '__bug_table' of crypto/algboss.o: defined in discarded section '.exit.text' of crypto/algboss.o
'.exit.text' referenced in section '__ex_table' of drivers/nvdimm/core.o: defined in discarded section '.exit.text' of drivers/nvdimm/core.o
Fix it by defining RUNTIME_DISCARD_EXIT, which causes the generic DISCARDS macro to not include .exit.text at all.
1: https://lore.kernel.org/lkml/[email protected]/
--- arch/powerpc/kernel/vmlinux.lds.S | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/kernel/vmlinux.lds.S +1 -0
@@ -8,6 +8,7 @@ #define BSS_FIRST_SECTIONS *(.bss.prominit) #define EMITS_PT_NOTE #define RO_EXCEPTION_TABLE_ALIGN 0 +#define RUNTIME_DISCARD_EXIT #define SOFT_MASK_TABLE(align) \ . = ALIGN(align); \
Greg Kroah-Hartman
maintainerPATCH 131/145 powerpc/vmlinux.lds: Dont discard .rela* for relocatable builds
In reply to Greg Kroah-HartmanFrom: Michael Ellerman <[email protected]>
commit 07b050f9290ee012a407a0f64151db902a1520f5 upstream.
Relocatable kernels must not discard relocations, they need to be processed at runtime. As such they are included for CONFIG_RELOCATABLE builds in the powerpc linker script (line 340).
However they are also unconditionally discarded later in the script (line 414). Previously that worked because the earlier inclusion superseded the discard.
However commit 99cb0d917ffa ("arch: fix broken BuildID for arm64 and riscv") introduced an earlier use of DISCARD as part of the RO_DATA macro (line 137). With binutils < 2.36 that causes the DISCARD directives later in the script to be applied earlier, causing .rela* to actually be discarded at link time, leading to build warnings and a kernel that doesn't boot:
ld: warning: discarding dynamic section .rela.init.rodata
Fix it by conditionally discarding .rela* only when CONFIG_RELOCATABLE is disabled.
--- arch/powerpc/kernel/vmlinux.lds.S | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/kernel/vmlinux.lds.S +4 -1
@@ -408,9 +408,12 @@ SECTIONS DISCARDS /DISCARD/ : { *(*.EMB.apuinfo) - *(.glink .iplt .plt .rela* .comment) + *(.glink .iplt .plt .comment) *(.gnu.version*) *(.gnu.attributes) *(.eh_frame) +#ifndef CONFIG_RELOCATABLE + *(.rela*) +#endif } }
Greg Kroah-Hartman
maintainerPATCH 132/145 s390: define RUNTIME_DISCARD_EXIT to fix link error with GNU ld < 2.36
In reply to Greg Kroah-HartmanFrom: Masahiro Yamada <[email protected]>
commit a494398bde273143c2352dd373cad8211f7d94b2 upstream.
Nathan Chancellor reports that the s390 vmlinux fails to link with GNU ld < 2.36 since commit 99cb0d917ffa ("arch: fix broken BuildID for arm64 and riscv").
It happens for defconfig, or more specifically for CONFIG_EXPOLINE=y.
$ s390x-linux-gnu-ld --version | head -n1 GNU ld (GNU Binutils for Debian) 2.35.2 $ make -s ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- allnoconfig $ ./scripts/config -e CONFIG_EXPOLINE $ make -s ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- olddefconfig $ make -s ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- `.exit.text' referenced in section `.s390_return_reg' of drivers/base/dd.o: defined in discarded section `.exit.text' of drivers/base/dd.o make[1]: *** [scripts/Makefile.vmlinux:34: vmlinux] Error 1 make: *** [Makefile:1252: vmlinux] Error 2
arch/s390/kernel/vmlinux.lds.S wants to keep EXIT_TEXT:
.exit.text : {
EXIT_TEXT
}But, at the same time, EXIT_TEXT is thrown away by DISCARD because s390 does not define RUNTIME_DISCARD_EXIT.
I still do not understand why the latter wins after 99cb0d917ffa, but defining RUNTIME_DISCARD_EXIT seems correct because the comment line in arch/s390/kernel/vmlinux.lds.S says:
/*
* .exit.text is discarded at runtime, not link time,
* to deal with references from __bug_table */
Nathan also found that binutils commit 21401fc7bf67 ("Duplicate output sections in scripts") cured this issue, so we cannot reproduce it with binutils 2.36+, but it is better to not rely on it.
--- arch/s390/kernel/vmlinux.lds.S | 2 ++ 1 file changed, 2 insertions(+)
arch/s390/kernel/vmlinux.lds.S +2 -0
@@ -17,6 +17,8 @@ /* Handle ro_after_init data on our own. */ #define RO_AFTER_INIT_DATA +#define RUNTIME_DISCARD_EXIT + #define EMITS_PT_NOTE #include <asm-generic/vmlinux.lds.h>
Greg Kroah-Hartman
maintainerPATCH 133/145 sh: define RUNTIME_DISCARD_EXIT
In reply to Greg Kroah-HartmanFrom: Tom Saeger <[email protected]>
commit c1c551bebf928889e7a8fef7415b44f9a64975f4 upstream.
sh vmlinux fails to link with GNU ld < 2.40 (likely < 2.36) since commit 99cb0d917ffa ("arch: fix broken BuildID for arm64 and riscv").
This is similar to fixes for powerpc and s390:
commit 4b9880dbf3bd ("powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT"). commit a494398bde27 ("s390: define RUNTIME_DISCARD_EXIT to fix link error with GNU ld < 2.36").
$ sh4-linux-gnu-ld --version | head -n1 GNU ld (GNU Binutils for Debian) 2.35.2
$ make ARCH=sh CROSS_COMPILE=sh4-linux-gnu- microdev_defconfig $ make ARCH=sh CROSS_COMPILE=sh4-linux-gnu-
.exit.text' referenced in section __bug_table' of crypto/algboss.o:
defined in discarded section .exit.text' of crypto/algboss.o .exit.text' referenced in section __bug_table' of drivers/char/hw_random/core.o: defined in discarded section .exit.text' of drivers/char/hw_random/core.o
make[2]: *** [scripts/Makefile.vmlinux:34: vmlinux] Error 1 make[1]: *** [Makefile:1252: vmlinux] Error 2
arch/sh/kernel/vmlinux.lds.S keeps EXIT_TEXT:
/*
* .exit.text is discarded at runtime, not link time, to deal with
* references from __bug_table
*/
.exit.text : AT(ADDR(.exit.text)) { EXIT_TEXT }However, EXIT_TEXT is thrown away by DISCARD(include/asm-generic/vmlinux.lds.h) because sh does not define RUNTIME_DISCARD_EXIT.
GNU ld 2.40 does not have this issue and builds fine.
This corresponds with Masahiro's comments in a494398bde27:
"Nathan [Chancellor] also found that binutils
commit 21401fc7bf67 ("Duplicate output sections in scripts") cured this issue, so we cannot reproduce it with binutils 2.36+, but it is better to not rely on it."
--- arch/sh/kernel/vmlinux.lds.S | 1 + 1 file changed, 1 insertion(+)
arch/sh/kernel/vmlinux.lds.S +1 -0
@@ -4,6 +4,7 @@ * Written by Niibe Yutaka and Paul Mundt */ OUTPUT_ARCH(sh) +#define RUNTIME_DISCARD_EXIT #include <asm/thread_info.h> #include <asm/cache.h> #include <asm/vmlinux.lds.h>
Greg Kroah-Hartman
maintainerPATCH 134/145 tools build: Add feature test for init_disassemble_info API changes
In reply to Greg Kroah-HartmanFrom: Andres Freund <[email protected]>
commit cfd59ca91467056bb2c36907b2fa67b8e1af9952 upstream.
binutils changed the signature of init_disassemble_info(), which now causes compilation failures for tools/{perf,bpf}, e.g. on debian unstable.
Relevant binutils commit:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07
This commit adds a feature test to detect the new signature. Subsequent commits will use it to fix the build failures.
--- tools/build/Makefile.feature | 1 + tools/build/feature/Makefile | 4 ++++ tools/build/feature/test-all.c | 4 ++++ tools/build/feature/test-disassembler-init-styled.c | 13 +++++++++++++ 4 files changed, 22 insertions(+) create mode 100644 tools/build/feature/test-disassembler-init-styled.c
tools/build/Makefile.feature +1 -0
@@ -69,6 +69,7 @@ FEATURE_TESTS_BASIC := libaio \ libzstd \ disassembler-four-args \ + disassembler-init-styled \ file-handle # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
tools/build/feature/Makefile +4 -0
@@ -18,6 +18,7 @@ FILES= test-libbfd.bin \ test-libbfd-buildid.bin \ test-disassembler-four-args.bin \ + test-disassembler-init-styled.bin \ test-reallocarray.bin \ test-libbfd-liberty.bin \ test-libbfd-liberty-z.bin \
@@ -239,6 +240,9 @@ $(OUTPUT)test-libbfd-buildid.bin: $(OUTPUT)test-disassembler-four-args.bin: $(BUILD) -DPACKAGE='"perf"' -lbfd -lopcodes +$(OUTPUT)test-disassembler-init-styled.bin: + $(BUILD) -DPACKAGE='"perf"' -lbfd -lopcodes + $(OUTPUT)test-reallocarray.bin: $(BUILD)
tools/build/feature/test-all.c +4 -0
@@ -166,6 +166,10 @@# include "test-disassembler-four-args.c" #undef main +#define main main_test_disassembler_init_styled +# include "test-disassembler-init-styled.c" +#undef main +#define main main_test_libzstd# include "test-libzstd.c" #undef main
tools/build/feature/test-disassembler-init-styled.c new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <stdio.h> +#include <dis-asm.h> + +int main (void ) +{ +struct disassemble_info info; + +init_disassemble_info (&info, stdout, +NULL ,NULL ); + +return 0 ; +}
Greg Kroah-Hartman
maintainerPATCH 135/145 tools include: add dis-asm-compat.h to handle version differences
In reply to Greg Kroah-HartmanFrom: Andres Freund <[email protected]>
commit a45b3d6926231c3d024ea0de4f7bd967f83709ee upstream.
binutils changed the signature of init_disassemble_info(), which now causes compilation failures for tools/{perf,bpf}, e.g. on debian unstable.
Relevant binutils commit:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07
This commit introduces a wrapper for init_disassemble_info(), to avoid spreading #ifdef DISASM_INIT_STYLED to a bunch of places. Subsequent commits will use it to fix the build failures.
It likely is worth adding a wrapper for disassember(), to avoid the already existing DISASM_FOUR_ARGS_SIGNATURE ifdefery.
--- tools/include/tools/dis-asm-compat.h | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tools/include/tools/dis-asm-compat.h
tools/include/tools/dis-asm-compat.h new file +55 -0
@@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause */ +#ifndef _TOOLS_DIS_ASM_COMPAT_H +#define _TOOLS_DIS_ASM_COMPAT_H + +#include <stdio.h> +#include <dis-asm.h> + +/* define types for older binutils version, to centralize ifdef'ery a bit */ +#ifndef DISASM_INIT_STYLED +enum disassembler_style {DISASSEMBLER_STYLE_NOT_EMPTY }; +typedef int (*fprintf_styled_ftype ) (void *,enum disassembler_style ,const char *, ...); +#endif + +/* +* Trivial fprintf wrapper to be used as the fprintf_styled_func argument to +* init_disassemble_info_compat() when normal fprintf suffices. +*/ +static inline int fprintf_styled (void *out, +enum disassembler_style style, +const char *fmt, ...) +{ +va_list args; +int r; + + (void )style; + +va_start (args, fmt); + r =vfprintf (out, fmt, args); +va_end (args); + +return r; +} + +/* +* Wrapper for init_disassemble_info() that hides version +* differences. Depending on binutils version and architecture either +* fprintf_func or fprintf_styled_func will be called. +*/ +static inline void init_disassemble_info_compat (struct disassemble_info *info, +void *stream, +fprintf_ftype unstyled_func, +fprintf_styled_ftype styled_func) +{ +#ifdef DISASM_INIT_STYLED +init_disassemble_info (info, stream, + unstyled_func, + styled_func); +#else + (void )styled_func; +init_disassemble_info (info, stream, + unstyled_func); +#endif +} + +#endif /* _TOOLS_DIS_ASM_COMPAT_H */
Greg Kroah-Hartman
maintainerPATCH 136/145 tools perf: Fix compilation error with new binutils
In reply to Greg Kroah-HartmanFrom: Andres Freund <[email protected]>
commit 83aa0120487e8bc3f231e72c460add783f71f17c upstream.
binutils changed the signature of init_disassemble_info(), which now causes compilation failures for tools/perf/util/annotate.c, e.g. on debian unstable.
Relevant binutils commit:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07
Wire up the feature test and switch to init_disassemble_info_compat(), which were introduced in prior commits, fixing the compilation failure.
I verified that perf can still disassemble bpf programs by using bpftrace under load, recording a perf trace, and then annotating the bpf "function" with and without the changes. With old binutils there's no change in output before/after this patch. When comparing the output from old binutils (2.35) to new bintuils with the patch (upstream snapshot) there are a few output differences, but they are unrelated to this patch. An example hunk is:
1.15 : 55:mov %rbp,%rdx
0.00 : 58:add $0xfffffffffffffff8,%rdx
0.00 : 5c:xor %ecx,%ecx
- 1.03 : 5e:callq 0xffffffffe12aca3c
+ 1.03 : 5e:call 0xffffffffe12aca3c
0.00 : 63:xor %eax,%eax
- 2.18 : 65:leaveq
- 2.82 : 66:retq
+ 2.18 : 65:leave
+ 2.82 : 66:ret--- tools/perf/Makefile.config | 8 ++++++++ tools/perf/util/annotate.c | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
tools/perf/Makefile.config +8 -0
@@ -296,6 +296,7 @@ FEATURE_CHECK_LDFLAGS-libpython := $(PYT FEATURE_CHECK_LDFLAGS-libaio = -lrt FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl +FEATURE_CHECK_LDFLAGS-disassembler-init-styled = -lbfd -lopcodes -ldl CORE_CFLAGS += -fno-omit-frame-pointer CORE_CFLAGS += -ggdb3
@@ -872,13 +873,16 @@ ifndef NO_LIBBFD ifeq ($(feature-libbfd-liberty), 1) EXTLIBS += -lbfd -lopcodes -liberty FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl + FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -ldl else ifeq ($(feature-libbfd-liberty-z), 1) EXTLIBS += -lbfd -lopcodes -liberty -lz FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl + FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -lz -ldl endif endif $(call feature_check,disassembler-four-args) + $(call feature_check,disassembler-init-styled) endif ifeq ($(feature-libbfd-buildid), 1)
@@ -992,6 +996,10 @@ ifeq ($(feature-disassembler-four-args), CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE endif +ifeq ($(feature-disassembler-init-styled), 1) + CFLAGS += -DDISASM_INIT_STYLED +endif + ifeq (${IS_64_BIT}, 1) ifndef NO_PERF_READ_VDSO32 $(call feature_check,compile-32)
tools/perf/util/annotate.c +4 -3
@@ -1694,6 +1694,7 @@ fallback:#include <bpf/btf.h> #include <bpf/libbpf.h> #include <linux/btf.h> +#include <tools/dis-asm-compat.h> static int symbol__disassemble_bpf (struct symbol *sym,struct annotate_args *args)
@@ -1736,9 +1737,9 @@ static int symbol__disassemble_bpf(struc ret = errno; goto out; } -init_disassemble_info (&info, s, - (fprintf_ftype ) fprintf); - +init_disassemble_info_compat (&info, s, + (fprintf_ftype ) fprintf, + fprintf_styled); info.arch =bfd_get_arch (bfdf); info.mach =bfd_get_mach (bfdf);
Greg Kroah-Hartman
maintainerPATCH 137/145 tools bpf_jit_disasm: Fix compilation error with new binutils
In reply to Greg Kroah-HartmanFrom: Andres Freund <[email protected]>
commit 96ed066054abf11c7d3e106e3011a51f3f1227a3 upstream.
binutils changed the signature of init_disassemble_info(), which now causes compilation to fail for tools/bpf/bpf_jit_disasm.c, e.g. on debian unstable.
Relevant binutils commit:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07
Wire up the feature test and switch to init_disassemble_info_compat(), which were introduced in prior commits, fixing the compilation failure.
I verified that bpf_jit_disasm can still disassemble bpf programs, both with the old and new dis-asm.h API. With old binutils there's no change in output before/after this patch. When comparing the output from old binutils (2.35) to new bintuils with the patch (upstream snapshot) there are a few output differences, but they are unrelated to this patch. An example hunk is:
f4: mov %r14,%rsi
f7: mov %r15,%rdx
fa: mov $0x2a,%ecx
- ff: callq 0xffffffffea8c4988
+ ff: call 0xffffffffea8c4988
104: test %rax,%rax
107: jge 0x0000000000000110
109: xor %eax,%eax
- 10b: jmpq 0x0000000000000073
+ 10b: jmp 0x0000000000000073
110: cmp $0x16,%raxHowever, I had to use an older kernel to generate the bpf_jit_enabled = 2 output, as that has been broken since 5.18 / 1022a5498f6f745c ("bpf,x86_64: Use bpf_jit_binary_pack_alloc").
https://lore.kernel.org/[email protected]
--- tools/bpf/Makefile | 5 ++++- tools/bpf/bpf_jit_disasm.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
tools/bpf/Makefile +4 -1
@@ -34,7 +34,7 @@ else endif FEATURE_USER = .bpf -FEATURE_TESTS = libbfd disassembler-four-args +FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled FEATURE_DISPLAY = libbfd disassembler-four-args check_feat := 1
@@ -56,6 +56,9 @@ endif ifeq ($(feature-disassembler-four-args), 1) CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE endif +ifeq ($(feature-disassembler-init-styled), 1) +CFLAGS += -DDISASM_INIT_STYLED +endif $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y $(QUIET_BISON)$(YACC) -o $@ -d $<
tools/bpf/bpf_jit_disasm.c +4 -1
@@ -28,6 +28,7 @@#include <sys/types.h> #include <sys/stat.h> #include <limits.h> +#include <tools/dis-asm-compat.h> #define CMD_ACTION_SIZE_BUFFER 10#define CMD_ACTION_READ_ALL 3
@@ -64,7 +65,9 @@ static void get_asm_insns(uint8_t *imageassert (bfdf);assert (bfd_check_format (bfdf, bfd_object)); -init_disassemble_info (&info, stdout, (fprintf_ftype ) fprintf); +init_disassemble_info_compat (&info, stdout, + (fprintf_ftype ) fprintf, + fprintf_styled); info.arch =bfd_get_arch (bfdf); info.mach =bfd_get_mach (bfdf); info.buffer = image;
Greg Kroah-Hartman
maintainerPATCH 138/145 tools bpftool: Fix compilation error with new binutils
In reply to Greg Kroah-HartmanFrom: Andres Freund <[email protected]>
commit 600b7b26c07a070d0153daa76b3806c1e52c9e00 upstream.
binutils changed the signature of init_disassemble_info(), which now causes compilation to fail for tools/bpf/bpftool/jit_disasm.c, e.g. on debian unstable.
Relevant binutils commit:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07
Wire up the feature test and switch to init_disassemble_info_compat(), which were introduced in prior commits, fixing the compilation failure.
I verified that bpftool can still disassemble bpf programs, both with an old and new dis-asm.h API. There are no output changes for plain and json formats. When comparing the output from old binutils (2.35) to new bintuils with the patch (upstream snapshot) there are a few output differences, but they are unrelated to this patch. An example hunk is:
2f: pop %r14
31: pop %r13
33: pop %rbx
- 34: leaveq
- 35: retq
+ 34: leave
+ 35: ret--- tools/bpf/bpftool/Makefile | 5 +++- tools/bpf/bpftool/jit_disasm.c | 42 +++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 9 deletions(-)
tools/bpf/bpftool/Makefile +4 -1
@@ -76,7 +76,7 @@ INSTALL ?= install RM ?= rm -f FEATURE_USER = .bpftool -FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib libcap \ +FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled reallocarray zlib libcap \ clang-bpf-co-re FEATURE_DISPLAY = libbfd disassembler-four-args zlib libcap \ clang-bpf-co-re
@@ -111,6 +111,9 @@ ifeq ($(feature-libcap), 1) CFLAGS += -DUSE_LIBCAP LIBS += -lcap endif +ifeq ($(feature-disassembler-init-styled), 1) + CFLAGS += -DDISASM_INIT_STYLED +endif include $(wildcard $(OUTPUT)*.d)
tools/bpf/bpftool/jit_disasm.c +34 -8
72 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 139/145 KVM: fix memoryleak in kvm_init()
In reply to Greg Kroah-HartmanFrom: Miaohe Lin <[email protected]>
commit 5a2a961be2ad6a16eb388a80442443b353c11d16 upstream.
When alloc_cpumask_var_node() fails for a certain cpu, there might be some allocated cpumasks for percpu cpu_kick_mask. We should free these cpumasks or memoryleak will occur.
--- virt/kvm/kvm_main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
virt/kvm/kvm_main.c +2 -3
@@ -5649,7 +5649,7 @@ int kvm_init(void *opaque, unsigned vcpu r =kvm_async_pf_init ();if (r) - goto out_free_5; + goto out_free_4; kvm_chardev_ops.owner = module; kvm_vm_fops.owner = module;
@@ -5682,10 +5682,9 @@ err_register:kvm_vfio_ops_exit (); err_vfio:kvm_async_pf_deinit (); -out_free_5: +out_free_4:for_each_possible_cpu (cpu)free_cpumask_var (per_cpu (cpu_kick_mask, cpu)); -out_free_4:kmem_cache_destroy (kvm_vcpu_cache); out_free_3:unregister_reboot_notifier (&kvm_reboot_notifier);
Greg Kroah-Hartman
maintainerPATCH 140/145 xfs: remove xfs_setattr_time() declaration
In reply to Greg Kroah-HartmanFrom: Gaosheng Cui <[email protected]>
commit b0463b9dd7030a766133ad2f1571f97f204d7bdf upstream.
xfs_setattr_time() has been removed since
commit e014f37db1a2 ("xfs: use setattr_copy to set vfs inode attributes"), so remove it.
--- fs/xfs/xfs_iops.h | 1 - 1 file changed, 1 deletion(-)
fs/xfs/xfs_iops.h +0 -1
@@ -13,7 +13,6 @@ extern const struct file_operations xfs_extern ssize_t xfs_vn_listxattr (struct dentry *,char *data,size_t size); -extern void xfs_setattr_time (struct xfs_inode *ip,struct iattr *iattr);int xfs_vn_setattr_size (struct user_namespace *mnt_userns,struct dentry *dentry,struct iattr *vap);
Greg Kroah-Hartman
maintainerPATCH 141/145 UML: define RUNTIME_DISCARD_EXIT
In reply to Greg Kroah-HartmanFrom: Masahiro Yamada <[email protected]>
commit b99ddbe8336ee680257c8ab479f75051eaa49dcf upstream.
With CONFIG_VIRTIO_UML=y, GNU ld < 2.36 fails to link UML vmlinux (w/wo CONFIG_LD_SCRIPT_STATIC).
.exit.text' referenced in section .uml.exitcall.exit' of arch/um/drivers/virtio_uml.o: defined in discarded section `.exit.text' of arch/um/drivers/virtio_uml.o
collect2: error: ld returned 1 exit status
This fix is similar to the following commits:
- 4b9880dbf3bd ("powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT")
- a494398bde27 ("s390: define RUNTIME_DISCARD_EXIT to fix link error with GNU ld < 2.36")
- c1c551bebf92 ("sh: define RUNTIME_DISCARD_EXIT")
--- arch/um/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/um/kernel/vmlinux.lds.S +1 -1
@@ -1,4 +1,4 @@ - +#define RUNTIME_DISCARD_EXIT KERNEL_STACK_SIZE = 4096 * (1 << CONFIG_KERNEL_STACK_ORDER); #ifdef CONFIG_LD_SCRIPT_STATIC
Greg Kroah-Hartman
maintainerPATCH 142/145 fs: hold writers when changing mounts idmapping
In reply to Greg Kroah-HartmanFrom: Christian Brauner <[email protected]>
commit e1bbcd277a53e08d619ffeec56c5c9287f2bf42f upstream.
Hold writers when changing a mount's idmapping to make it more robust.
The vfs layer takes care to retrieve the idmapping of a mount once ensuring that the idmapping used for vfs permission checking is identical to the idmapping passed down to the filesystem.
For ioctl codepaths the filesystem itself is responsible for taking the idmapping into account if they need to. While all filesystems with FS_ALLOW_IDMAP raised take the same precautions as the vfs we should enforce it explicitly by making sure there are no active writers on the relevant mount while changing the idmapping.
This is similar to turning a mount ro with the difference that in contrast to turning a mount ro changing the idmapping can only ever be done once while a mount can transition between ro and rw as much as it wants.
This is a minor user-visible change. But it is extremely unlikely to matter. The caller must've created a detached mount via OPEN_TREE_CLONE and then handed that O_PATH fd to another process or thread which then must've gotten a writable fd for that mount and started creating files in there while the caller is still changing mount properties. While not impossible it will be an extremely rare corner-case and should in general be considered a bug in the application. Consider making a mount MOUNT_ATTR_NOEXEC or MOUNT_ATTR_NODEV while allowing someone else to perform lookups or exec'ing in parallel by handing them a copy of the OPEN_TREE_CLONE fd or another fd beneath that mount.
--- fs/namespace.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
fs/namespace.c +20 -9
@@ -3968,6 +3968,23 @@ static int can_idmap_mount(const structreturn 0 ; } +/** +* mnt_allow_writers() - check whether the attribute change allows writers +* @kattr: the new mount attributes +* @mnt: the mount to which @kattr will be applied +* +* Check whether thew new mount attributes in @kattr allow concurrent writers. +* +* Return: true if writers need to be held, false if not +*/ +static inline bool mnt_allow_writers (const struct mount_kattr *kattr, +const struct mount *mnt) +{ +return (!(kattr->attr_set &MNT_READONLY ) || + (mnt->mnt.mnt_flags &MNT_READONLY )) && + !kattr->mnt_userns; +} +static struct mount *mount_setattr_prepare (struct mount_kattr *kattr,struct mount *mnt,int *err) {
@@ -3998,8 +4015,7 @@ static struct mount *mount_setattr_prepa last = m; -if ((kattr->attr_set &MNT_READONLY ) && - !(m->mnt.mnt_flags &MNT_READONLY )) { +if (!mnt_allow_writers (kattr, m)) { *err =mnt_hold_writers (m);if (*err) goto out;
@@ -4050,13 +4066,8 @@ static void mount_setattr_commit(structWRITE_ONCE (m->mnt.mnt_flags, flags); } -/* -* We either set MNT_READONLY above so make it visible -* before ~MNT_WRITE_HOLD or we failed to recursively -* apply mount options. -*/ -if ((kattr->attr_set &MNT_READONLY ) && - (m->mnt.mnt_flags &MNT_WRITE_HOLD )) +/* If we had to hold writers unblock them. */ +if (m->mnt.mnt_flags &MNT_WRITE_HOLD )mnt_unhold_writers (m);if (!err && kattr->propagation)
Greg Kroah-Hartman
maintainerPATCH 143/145 KVM: nVMX: Dont use Enlightened MSR Bitmap for L3
In reply to Greg Kroah-HartmanFrom: Vitaly Kuznetsov <[email protected]>
commit 250552b925ce400c17d166422fde9bb215958481 upstream.
When KVM runs as a nested hypervisor on top of Hyper-V it uses Enlightened VMCS and enables Enlightened MSR Bitmap feature for its L1s and L2s (which are actually L2s and L3s from Hyper-V's perspective). When MSR bitmap is updated, KVM has to reset HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP from clean fields to make Hyper-V aware of the change. For KVM's L1s, this is done in vmx_disable_intercept_for_msr()/vmx_enable_intercept_for_msr(). MSR bitmap for L2 is build in nested_vmx_prepare_msr_bitmap() by blending MSR bitmap for L1 and L1's idea of MSR bitmap for L2. KVM, however, doesn't check if the resulting bitmap is different and never cleans HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP in eVMCS02. This is incorrect and may result in Hyper-V missing the update.
The issue could've been solved by calling evmcs_touch_msr_bitmap() for eVMCS02 from nested_vmx_prepare_msr_bitmap() unconditionally but doing so would not give any performance benefits (compared to not using Enlightened MSR Bitmap at all). 3-level nesting is also not a very common setup nowadays.
Don't enable 'Enlightened MSR Bitmap' feature for KVM's L2s (real L3s) for now.
Message-Id: <[email protected]>
--- arch/x86/kvm/vmx/vmx.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
arch/x86/kvm/vmx/vmx.c +13 -9
@@ -2739,15 +2739,6 @@ int alloc_loaded_vmcs(struct loaded_vmcsif (!loaded_vmcs->msr_bitmap) goto out_vmcs;memset (loaded_vmcs->msr_bitmap,0xff ,PAGE_SIZE ); - -if (IS_ENABLED (CONFIG_HYPERV ) && -static_branch_unlikely (&enable_evmcs) && - (ms_hyperv.nested_features &HV_X64_NESTED_MSR_BITMAP )) { -struct hv_enlightened_vmcs *evmcs = - (struct hv_enlightened_vmcs *)loaded_vmcs->vmcs; - - evmcs->hv_enlightenments_control.msr_bitmap =1 ; - } }memset (&loaded_vmcs->host_state,0 ,sizeof (struct vmcs_host_state ));
@@ -6969,6 +6960,19 @@ static int vmx_create_vcpu(struct kvm_vcif (err <0 ) goto free_pml; +/* +* Use Hyper-V 'Enlightened MSR Bitmap' feature when KVM runs as a +* nested (L1) hypervisor and Hyper-V in L0 supports it. Enable the +* feature only for vmcs01, KVM currently isn't equipped to realize any +* performance benefits from enabling it for vmcs02. +*/ +if (IS_ENABLED (CONFIG_HYPERV ) &&static_branch_unlikely (&enable_evmcs) && + (ms_hyperv.nested_features &HV_X64_NESTED_MSR_BITMAP )) { +struct hv_enlightened_vmcs *evmcs = (void *)vmx->vmcs01.vmcs; + + evmcs->hv_enlightenments_control.msr_bitmap =1 ; + } +/* The MSR bitmap starts with all ones */ bitmap_fill (vmx->shadow_msr_intercept.read,MAX_POSSIBLE_PASSTHROUGH_MSRS );bitmap_fill (vmx->shadow_msr_intercept.write,MAX_POSSIBLE_PASSTHROUGH_MSRS );
Greg Kroah-Hartman
maintainerPATCH 144/145 KVM: VMX: Introduce vmx_msr_bitmap_l01_changed() helper
In reply to Greg Kroah-HartmanFrom: Vitaly Kuznetsov <[email protected]>
commit b84155c38076b36d625043a06a2f1c90bde62903 upstream.
In preparation to enabling 'Enlightened MSR Bitmap' feature for Hyper-V guests move MSR bitmap update tracking to a dedicated helper.
Note: vmx_msr_bitmap_l01_changed() is called when MSR bitmap might be updated. KVM doesn't check if the bit we're trying to set is already set (or the bit it's trying to clear is already cleared). Such situations should not be common and a few false positives should not be a problem.
No functional change intended.
Message-Id: <[email protected]>
--- arch/x86/kvm/vmx/vmx.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
arch/x86/kvm/vmx/vmx.c +13 -4
@@ -3772,6 +3772,17 @@ void free_vpid(int vpid)spin_unlock (&vmx_vpid_lock); } +static void vmx_msr_bitmap_l01_changed (struct vcpu_vmx *vmx) +{ +/* +* When KVM is a nested hypervisor on top of Hyper-V and uses +* 'Enlightened MSR Bitmap' feature L0 needs to know that MSR +* bitmap has changed. +*/ +if (static_branch_unlikely (&enable_evmcs)) +evmcs_touch_msr_bitmap (); +} +void vmx_disable_intercept_for_msr (struct kvm_vcpu *vcpu,u32 msr,int type) {struct vcpu_vmx *vmx =to_vmx (vcpu);
@@ -3780,8 +3791,7 @@ void vmx_disable_intercept_for_msr(strucif (!cpu_has_vmx_msr_bitmap ())return ; -if (static_branch_unlikely (&enable_evmcs)) -evmcs_touch_msr_bitmap (); +vmx_msr_bitmap_l01_changed (vmx);/* * Mark the desired intercept state in shadow bitmap, this is needed
@@ -3825,8 +3835,7 @@ void vmx_enable_intercept_for_msr(structif (!cpu_has_vmx_msr_bitmap ())return ; -if (static_branch_unlikely (&enable_evmcs)) -evmcs_touch_msr_bitmap (); +vmx_msr_bitmap_l01_changed (vmx);/* * Mark the desired intercept state in shadow bitmap, this is needed
Greg Kroah-Hartman
maintainerPATCH 145/145 KVM: VMX: Fix crash due to uninitialized current_vmcs
In reply to Greg Kroah-HartmanFrom: Alexandru Matei <[email protected]>
commit 93827a0a36396f2fd6368a54a020f420c8916e9b upstream.
KVM enables 'Enlightened VMCS' and 'Enlightened MSR Bitmap' when running as a nested hypervisor on top of Hyper-V. When MSR bitmap is updated, evmcs_touch_msr_bitmap function uses current_vmcs per-cpu variable to mark that the msr bitmap was changed.
vmx_vcpu_create() modifies the msr bitmap via vmx_disable_intercept_for_msr -> vmx_msr_bitmap_l01_changed which in the end calls this function. The function checks for current_vmcs if it is null but the check is insufficient because current_vmcs is not initialized. Because of this, the code might incorrectly write to the structure pointed by current_vmcs value left by another task. Preemption is not disabled, the current task can be preempted and moved to another CPU while current_vmcs is accessed multiple times from evmcs_touch_msr_bitmap() which leads to crash.
The manipulation of MSR bitmaps by callers happens only for vmcs01 so the solution is to use vmx->vmcs01.vmcs instead of current_vmcs.
BUG: kernel NULL pointer dereference, address: 0000000000000338 PGD 4e1775067 P4D 0 Oops: 0002 [#1] PREEMPT SMP NOPTI ... RIP: 0010:vmx_msr_bitmap_l01_changed+0x39/0x50 [kvm_intel] ... Call Trace: vmx_disable_intercept_for_msr+0x36/0x260 [kvm_intel] vmx_vcpu_create+0xe6/0x540 [kvm_intel] kvm_arch_vcpu_create+0x1d1/0x2e0 [kvm] kvm_vm_ioctl_create_vcpu+0x178/0x430 [kvm] kvm_vm_ioctl+0x53f/0x790 [kvm] __x64_sys_ioctl+0x8a/0xc0 do_syscall_64+0x5c/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd
[manual backport: evmcs.h got renamed to hyperv.h in a later version, modified in evmcs.h instead]
--- arch/x86/kvm/vmx/evmcs.h | 11 ----------- arch/x86/kvm/vmx/vmx.c | 9 +++++++-- 2 files changed, 7 insertions(+), 13 deletions(-)
arch/x86/kvm/vmx/evmcs.h +0 -11
@@ -162,16 +162,6 @@ static inline u16 evmcs_read16(unsignedreturn *(u16 *)((char *)current_evmcs + offset); } -static inline void evmcs_touch_msr_bitmap (void ) -{ -if (unlikely (!current_evmcs)) -return ; - -if (current_evmcs->hv_enlightenments_control.msr_bitmap) - current_evmcs->hv_clean_fields &= - ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP ; -} -static inline void evmcs_load (u64 phys_addr) { struct hv_vp_assist_page *vp_ap =
@@ -192,7 +182,6 @@ static inline u64 evmcs_read64(unsignedstatic inline u32 evmcs_read32 (unsigned long field) {return 0 ; }static inline u16 evmcs_read16 (unsigned long field) {return 0 ; }static inline void evmcs_load (u64 phys_addr) {} -static inline void evmcs_touch_msr_bitmap (void ) {}#endif /* IS_ENABLED(CONFIG_HYPERV) */ #define EVMPTR_INVALID (-1ULL)
arch/x86/kvm/vmx/vmx.c +7 -2
@@ -3779,8 +3779,13 @@ static void vmx_msr_bitmap_l01_changed(s* 'Enlightened MSR Bitmap' feature L0 needs to know that MSR * bitmap has changed. */ -if (static_branch_unlikely (&enable_evmcs)) -evmcs_touch_msr_bitmap (); +if (IS_ENABLED (CONFIG_HYPERV ) &&static_branch_unlikely (&enable_evmcs)) { +struct hv_enlightened_vmcs *evmcs = (void *)vmx->vmcs01.vmcs; + +if (evmcs->hv_enlightenments_control.msr_bitmap) + evmcs->hv_clean_fields &= + ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP ; + } }void vmx_disable_intercept_for_msr (struct kvm_vcpu *vcpu,u32 msr,int type)
Hello Greg,
Quoted 10 lines
From: Greg Kroah-Hartman <[email protected]>
Sent: 15 March 2023 12:11This is the start of the stable review cycle for the 5.15.103 release. There are 145 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 17 Mar 2023 11:57:10 +0000. Anything received after that time might be too late.
CIP configurations built and booted with Linux 5.15.103-rc1 (158686d9d0fd):
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/pipelines/807195776
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/commits/linux-5.15.y
Kind regards, Chris
Hello!
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.15.103 release. There are 145 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 17 Mar 2023 11:57:10 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.103-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.15.y
and the diffstat can be found below.thanks,
greg k-h
We're seeing PowerPC build failures like the following (GCC-8, GCC-12, Clang-16):
-----8<-----
In file included from /builds/linux/drivers/usb/host/ehci-hcd.c:1298:
/builds/linux/drivers/usb/host/ehci-ppc-of.c:122:13: error: use of undeclared identifier 'NO_IRQ'
if (irq == NO_IRQ) {
^1 error generated.
----->8-----
Then, Perf fails on Arm and i386 with GCC-12:
-----8<-----
In function 'parse_events_term__num',
inlined from 'parse_events_multi_pmu_add' at util/parse-events.c:1687:9:util/parse-events.c:3100:64: error: array subscript 'YYLTYPE[0]' is partly outside array bounds of 'char[4]' [-Werror=array-bounds]
3100 | .err_term = loc_term ? loc_term->first_column : 0,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
util/parse-events.c: In function 'parse_events_multi_pmu_add':util/parse-events.c:1678:39: note: object 'config' of size 4
1678 | char *config;
| ^~~~~~
cc1: all warnings being treated as errors ----->8-----
Greetings!
Daniel Díaz
[email protected]
Greg Kroah-Hartman
maintainerQuoted 23 lines · Daniel Díaz
Hello!
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.15.103 release. There are 145 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 17 Mar 2023 11:57:10 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.103-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.15.y
and the diffstat can be found below.thanks,
greg k-h
We're seeing PowerPC build failures like the following (GCC-8, GCC-12, Clang-16):
Quoted 7 lines
-----8<-----
In file included from /builds/linux/drivers/usb/host/ehci-hcd.c:1298:
/builds/linux/drivers/usb/host/ehci-ppc-of.c:122:13: error: use of undeclared identifier 'NO_IRQ'if (irq == NO_IRQ) { ^1 error generated.
----->8-----
Will be fixed in -rc2
Quoted 8 lines
Then, Perf fails on Arm and i386 with GCC-12:
-----8<-----
In function 'parse_events_term__num',
inlined from 'parse_events_multi_pmu_add' atutil/parse-events.c:1687:9:util/parse-events.c:3100:64: error: array subscript 'YYLTYPE[0]' is partly outside array bounds of 'char[4]' [-Werror=array-bounds]
3100 | .err_term =loc_term?loc_term->first_column: 0,
Quoted 7 lines
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
util/parse-events.c: In function 'parse_events_multi_pmu_add':util/parse-events.c:1678:39: note: object 'config' of size 4
1678 | char *config;
| ^~~~~~
cc1: all warnings being treated as errors ----->8-----
This is odd as this file isn't modified, but other build fixes for perf for 5.15 were made. Let's see if this still happens in -rc2 and if so, if you could bisect to track down the offending commit that would be great.
thanks,
greg k-h
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.15.103 release. There are 145 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 17 Mar 2023 11:57:10 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.103-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.15.y
and the diffstat can be found below.thanks,
greg k-h
On ARCH_BRCMSTB using 32-bit and 64-bit ARM kernels, build tested on BMIPS_GENERIC:
Signature · 1 line
Florian
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.15.103 release. There are 145 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 17 Mar 2023 11:57:10 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 9 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.103-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.15.y
and the diffstat can be found below.thanks,
greg k-h
Compiled and booted on my test system. No dmesg regressions.
thanks,
-- Shuah
Quoted 5 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.15.103 release. There are 145 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Successfully cross-compiled for arm64 (bcm2711_defconfig, GCC 10.2.0) and powerpc (ps3_defconfig, GCC 12.2.0).
Signature · 1 line
An old man doll... just what I always wanted! - Clara