LSM: general protection fault in legacy_parse_param
Subsystems (19)
Sasha Levin
maintainerPATCH 8/35 block: throttle split bio in case of iops limit
In reply to Sasha LevinFrom: Ming Lei <[email protected]>
[ Upstream commit 9f5ede3c01f9951b0ae7d68b28762ad51d9bacc8 ]
Commit 111be8839817 ("block-throttle: avoid double charge") marks bio as BIO_THROTTLED unconditionally if __blk_throtl_bio() is called on this bio, then this bio won't be called into __blk_throtl_bio() any more. This way is to avoid double charge in case of bio splitting. It is reasonable for read/write throughput limit, but not reasonable for IOPS limit because block layer provides io accounting against split bio.
Chunguang Xu has already observed this issue and fixed it in commit 4f1e9630afe6 ("blk-throtl: optimize IOPS throttle for large IO scenarios"). However, that patch only covers bio splitting in __blk_queue_split(), and we have other kind of bio splitting, such as bio_split() & submit_bio_noacct() and other ways.
This patch tries to fix the issue in one generic way by always charging the bio for iops limit in blk_throtl_bio(). This way is reasonable:
re-submission & fast-cloned bio is charged if it is submitted to same disk/queue, and BIO_THROTTLED will be cleared if bio->bi_bdev is changed.
This new approach can get much more smooth/stable iops limit compared with commit 4f1e9630afe6 ("blk-throtl: optimize IOPS throttle for large IO scenarios") since that commit can't throttle current split bios actually.
Also this way won't cause new double bio iops charge in blk_throtl_dispatch_work_fn() in which blk_throtl_bio() won't be called any more.
--- block/blk-merge.c | 2 -- block/blk-throttle.c | 10 +++++++--- block/blk-throttle.h | 2 -- 3 files changed, 7 insertions(+), 7 deletions(-)
block/blk-merge.c +0 -2
@@ -366,8 +366,6 @@ void __blk_queue_split(struct request_queue *q, struct bio **bio,trace_block_split (split, (*bio)->bi_iter.bi_sector);submit_bio_noacct (*bio); *bio = split; - -blk_throtl_charge_bio_split (*bio); } }
block/blk-throttle.c +7 -3
@@ -807,7 +807,8 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio,unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;unsigned int bio_size =throtl_bio_data_size (bio); -if (bps_limit ==U64_MAX ) { +/* no need to throttle if this bio's bytes have been accounted */ +if (bps_limit ==U64_MAX ||bio_flagged (bio,BIO_THROTTLED )) {if (wait) *wait =0 ;return true;
@@ -919,9 +920,12 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)unsigned int bio_size =throtl_bio_data_size (bio);/* Charge the bio to the group */ - tg->bytes_disp[rw] += bio_size; +if (!bio_flagged (bio,BIO_THROTTLED )) { + tg->bytes_disp[rw] += bio_size; + tg->last_bytes_disp[rw] += bio_size; + } + tg->io_disp[rw]++; - tg->last_bytes_disp[rw] += bio_size; tg->last_io_disp[rw]++;/*
block/blk-throttle.h +0 -2
@@ -170,8 +170,6 @@ static inline bool blk_throtl_bio(struct bio *bio) {struct throtl_grp *tg =blkg_to_tg (bio->bi_blkg); -if (bio_flagged (bio,BIO_THROTTLED )) -return false;if (!tg->has_rules[bio_data_dir (bio)])return false;
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 13/35 block, bfq: don't move oom_bfqq
In reply to Sasha LevinFrom: Yu Kuai <[email protected]>
[ Upstream commit 8410f70977734f21b8ed45c37e925d311dfda2e7 ]
Our test report a UAF:
[ 2073.019181] ================================================================== [ 2073.019188] BUG: KASAN: use-after-free in __bfq_put_async_bfqq+0xa0/0x168 [ 2073.019191] Write of size 8 at addr ffff8000ccf64128 by task rmmod/72584 [ 2073.019192] [ 2073.019196] CPU: 0 PID: 72584 Comm: rmmod Kdump: loaded Not tainted 4.19.90-yk #5 [ 2073.019198] Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 [ 2073.019200] Call trace: [ 2073.019203] dump_backtrace+0x0/0x310 [ 2073.019206] show_stack+0x28/0x38 [ 2073.019210] dump_stack+0xec/0x15c [ 2073.019216] print_address_description+0x68/0x2d0 [ 2073.019220] kasan_report+0x238/0x2f0 [ 2073.019224] __asan_store8+0x88/0xb0 [ 2073.019229] __bfq_put_async_bfqq+0xa0/0x168 [ 2073.019233] bfq_put_async_queues+0xbc/0x208 [ 2073.019236] bfq_pd_offline+0x178/0x238 [ 2073.019240] blkcg_deactivate_policy+0x1f0/0x420 [ 2073.019244] bfq_exit_queue+0x128/0x178 [ 2073.019249] blk_mq_exit_sched+0x12c/0x160 [ 2073.019252] elevator_exit+0xc8/0xd0 [ 2073.019256] blk_exit_queue+0x50/0x88 [ 2073.019259] blk_cleanup_queue+0x228/0x3d8 [ 2073.019267] null_del_dev+0xfc/0x1e0 [null_blk] [ 2073.019274] null_exit+0x90/0x114 [null_blk] [ 2073.019278] __arm64_sys_delete_module+0x358/0x5a0 [ 2073.019282] el0_svc_common+0xc8/0x320 [ 2073.019287] el0_svc_handler+0xf8/0x160 [ 2073.019290] el0_svc+0x10/0x218 [ 2073.019291] [ 2073.019294] Allocated by task 14163: [ 2073.019301] kasan_kmalloc+0xe0/0x190 [ 2073.019305] kmem_cache_alloc_node_trace+0x1cc/0x418 [ 2073.019308] bfq_pd_alloc+0x54/0x118 [ 2073.019313] blkcg_activate_policy+0x250/0x460 [ 2073.019317] bfq_create_group_hierarchy+0x38/0x110 [ 2073.019321] bfq_init_queue+0x6d0/0x948 [ 2073.019325] blk_mq_init_sched+0x1d8/0x390 [ 2073.019330] elevator_switch_mq+0x88/0x170 [ 2073.019334] elevator_switch+0x140/0x270 [ 2073.019338] elv_iosched_store+0x1a4/0x2a0 [ 2073.019342] queue_attr_store+0x90/0xe0 [ 2073.019348] sysfs_kf_write+0xa8/0xe8 [ 2073.019351] kernfs_fop_write+0x1f8/0x378 [ 2073.019359] __vfs_write+0xe0/0x360 [ 2073.019363] vfs_write+0xf0/0x270 [ 2073.019367] ksys_write+0xdc/0x1b8 [ 2073.019371] __arm64_sys_write+0x50/0x60 [ 2073.019375] el0_svc_common+0xc8/0x320 [ 2073.019380] el0_svc_handler+0xf8/0x160 [ 2073.019383] el0_svc+0x10/0x218 [ 2073.019385] [ 2073.019387] Freed by task 72584: [ 2073.019391] __kasan_slab_free+0x120/0x228 [ 2073.019394] kasan_slab_free+0x10/0x18 [ 2073.019397] kfree+0x94/0x368 [ 2073.019400] bfqg_put+0x64/0xb0 [ 2073.019404] bfqg_and_blkg_put+0x90/0xb0 [ 2073.019408] bfq_put_queue+0x220/0x228 [ 2073.019413] __bfq_put_async_bfqq+0x98/0x168 [ 2073.019416] bfq_put_async_queues+0xbc/0x208 [ 2073.019420] bfq_pd_offline+0x178/0x238 [ 2073.019424] blkcg_deactivate_policy+0x1f0/0x420 [ 2073.019429] bfq_exit_queue+0x128/0x178 [ 2073.019433] blk_mq_exit_sched+0x12c/0x160 [ 2073.019437] elevator_exit+0xc8/0xd0 [ 2073.019440] blk_exit_queue+0x50/0x88 [ 2073.019443] blk_cleanup_queue+0x228/0x3d8 [ 2073.019451] null_del_dev+0xfc/0x1e0 [null_blk] [ 2073.019459] null_exit+0x90/0x114 [null_blk] [ 2073.019462] __arm64_sys_delete_module+0x358/0x5a0 [ 2073.019467] el0_svc_common+0xc8/0x320 [ 2073.019471] el0_svc_handler+0xf8/0x160 [ 2073.019474] el0_svc+0x10/0x218 [ 2073.019475] [ 2073.019479] The buggy address belongs to the object at ffff8000ccf63f00 which belongs to the cache kmalloc-1024 of size 1024 [ 2073.019484] The buggy address is located 552 bytes inside of 1024-byte region [ffff8000ccf63f00, ffff8000ccf64300) [ 2073.019486] The buggy address belongs to the page: [ 2073.019492] page:ffff7e000333d800 count:1 mapcount:0 mapping:ffff8000c0003a00 index:0x0 compound_mapcount: 0 [ 2073.020123] flags: 0x7ffff0000008100(slab|head) [ 2073.020403] raw: 07ffff0000008100 ffff7e0003334c08 ffff7e00001f5a08 ffff8000c0003a00 [ 2073.020409] raw: 0000000000000000 00000000001c001c 00000001ffffffff 0000000000000000 [ 2073.020411] page dumped because: kasan: bad access detected [ 2073.020412] [ 2073.020414] Memory state around the buggy address: [ 2073.020420] ffff8000ccf64000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 2073.020424] ffff8000ccf64080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 2073.020428] >ffff8000ccf64100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 2073.020430] ^ [ 2073.020434] ffff8000ccf64180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 2073.020438] ffff8000ccf64200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 2073.020439] ==================================================================
The same problem exist in mainline as well.
This is because oom_bfqq is moved to a non-root group, thus root_group is freed earlier.
Thus fix the problem by don't move oom_bfqq.
--- block/bfq-cgroup.c | 6 ++++++ 1 file changed, 6 insertions(+)
block/bfq-cgroup.c +6 -0
@@ -646,6 +646,12 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq, {struct bfq_entity *entity = &bfqq->entity; +/* +* oom_bfqq is not allowed to move, oom_bfqq will hold ref to root_group +* until elevator exit. +*/ +if (bfqq == &bfqd->oom_bfqq) +return ;/* * Get extra reference to prevent bfqq from being freed in * next possible expire or deactivate.
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 16/35 arm64: module: remove (NOLOAD) from linker script
In reply to Sasha LevinFrom: Fangrui Song <[email protected]>
[ Upstream commit 4013e26670c590944abdab56c4fa797527b74325 ]
On ELF, (NOLOAD) sets the section type to SHT_NOBITS[1]. It is conceptually inappropriate for .plt and .text.* sections which are always SHT_PROGBITS.
In GNU ld, if PLT entries are needed, .plt will be SHT_PROGBITS anyway and (NOLOAD) will be essentially ignored. In ld.lld, since
https://reviews.llvm.org/D118840 ("[ELF] Support (TYPE=<value>) to customize the output section type"), ld.lld will report a section type mismatch error. Just remove (NOLOAD) to fix the error.
[1] https://lld.llvm.org/ELF/linker_script.html As of today, "The section should be marked as not loadable" on
https://sourceware.org/binutils/docs/ld/Output-Section-Type.html is outdated for ELF.
--- arch/arm64/include/asm/module.lds.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/include/asm/module.lds.h +3 -3
@@ -1,8 +1,8 @@ SECTIONS { #ifdef CONFIG_ARM64_MODULE_PLTS - .plt 0 (NOLOAD) : { BYTE(0) } - .init.plt 0 (NOLOAD) : { BYTE(0) } - .text.ftrace_trampoline 0 (NOLOAD) : { BYTE(0) } + .plt 0 : { BYTE(0) } + .init.plt 0 : { BYTE(0) } + .text.ftrace_trampoline 0 : { BYTE(0) } #endif #ifdef CONFIG_KASAN_SW_TAGS
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 22/35 fs/binfmt_elf: Fix AT_PHDR for unusual ELF files
In reply to Sasha LevinFrom: Akira Kawata <[email protected]>
[ Upstream commit 0da1d5002745cdc721bc018b582a8a9704d56c42 ]
As pointed out in the discussion of buglink, we cannot calculate AT_PHDR as the sum of load_addr and exec->e_phoff.
: The AT_PHDR of ELF auxiliary vectors should point to the memory address : of program header. But binfmt_elf.c calculates this address as follows:
:
: NEW_AUX_ENT(AT_PHDR, load_addr + exec->e_phoff);
:
: which is wrong since e_phoff is the file offset of program header and : load_addr is the memory base address from PT_LOAD entry.
:
: The ld.so uses AT_PHDR as the memory address of program header. In normal : case, since the e_phoff is usually 64 and in the first PT_LOAD region, it : is the correct program header address.
:
: But if the address of program header isn't equal to the first PT_LOAD : address + e_phoff (e.g. Put the program header in other non-consecutive : PT_LOAD region), ld.so will try to read program header from wrong address : then crash or use incorrect program header.
This is because exec->e_phoff
is the offset of PHDRs in the file and the address of PHDRs in the memory may differ from it. This patch fixes the bug by calculating the address of program headers from PT_LOADs directly.
--- fs/binfmt_elf.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
fs/binfmt_elf.c +18 -6
@@ -170,8 +170,8 @@ static int padzero(unsigned long elf_bss)static int create_elf_tables (struct linux_binprm *bprm,const struct elfhdr *exec, -unsigned long load_addr,unsigned long interp_load_addr, -unsigned long e_entry) +unsigned long interp_load_addr, +unsigned long e_entry,unsigned long phdr_addr) {struct mm_struct *mm = current->mm;unsigned long p = bprm->p;
@@ -257,7 +257,7 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec,NEW_AUX_ENT (AT_HWCAP ,ELF_HWCAP );NEW_AUX_ENT (AT_PAGESZ ,ELF_EXEC_PAGESIZE );NEW_AUX_ENT (AT_CLKTCK ,CLOCKS_PER_SEC ); -NEW_AUX_ENT (AT_PHDR , load_addr + exec->e_phoff); +NEW_AUX_ENT (AT_PHDR , phdr_addr);NEW_AUX_ENT (AT_PHENT ,sizeof (struct elf_phdr ));NEW_AUX_ENT (AT_PHNUM , exec->e_phnum);NEW_AUX_ENT (AT_BASE , interp_load_addr);
@@ -823,7 +823,7 @@ static int parse_elf_properties(struct file *f, const struct elf_phdr *phdr,static int load_elf_binary (struct linux_binprm *bprm) {struct file *interpreter =NULL ;/* to shut gcc up */ -unsigned long load_addr =0 , load_bias =0 ; +unsigned long load_addr, load_bias =0 , phdr_addr =0 ;int load_addr_set =0 ;unsigned long error;struct elf_phdr *elf_ppnt, *elf_phdata, *interp_elf_phdata =NULL ;
@@ -1180,6 +1180,17 @@ static int load_elf_binary(struct linux_binprm *bprm) reloc_func_desc = load_bias; } } + +/* +* Figure out which segment in the file contains the Program +* Header table, and map to the associated memory address. +*/ +if (elf_ppnt->p_offset <= elf_ex->e_phoff && + elf_ex->e_phoff < elf_ppnt->p_offset + elf_ppnt->p_filesz) { + phdr_addr = elf_ex->e_phoff - elf_ppnt->p_offset + + elf_ppnt->p_vaddr; + } + k = elf_ppnt->p_vaddr;if ((elf_ppnt->p_flags &PF_X ) && k < start_code) start_code = k;
@@ -1215,6 +1226,7 @@ static int load_elf_binary(struct linux_binprm *bprm) } e_entry = elf_ex->e_entry + load_bias; + phdr_addr += load_bias; elf_bss += load_bias; elf_brk += load_bias; start_code += load_bias;
@@ -1278,8 +1290,8 @@ static int load_elf_binary(struct linux_binprm *bprm) goto out;#endif /* ARCH_HAS_SETUP_ADDITIONAL_PAGES */ - retval =create_elf_tables (bprm, elf_ex, - load_addr, interp_load_addr, e_entry); + retval =create_elf_tables (bprm, elf_ex, interp_load_addr, + e_entry, phdr_addr);if (retval <0 ) goto out;
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 6/35 pinctrl: npcm: Fix broken references to chip->parent_device
In reply to Sasha LevinFrom: Marc Zyngier <[email protected]>
[ Upstream commit f7e53e2255808ca3abcc8f38d18ad0823425e771 ]
The npcm driver has a bunch of references to the irq_chip parent_device field, but never sets it.
Fix it by fishing that reference from somewhere else, but it is obvious that these debug statements were never used. Also remove an unused field in a local data structure.
--- drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c | 25 +++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c +12 -13
@@ -78,7 +78,6 @@ struct npcm7xx_gpio {struct gpio_chip gc;int irqbase;int irq; -void *priv;struct irq_chip irq_chip;u32 pinctrl_id;int (*direction_input)(struct gpio_chip *chip,unsigned offset);
@@ -226,7 +225,7 @@ static void npcmgpio_irq_handler(struct irq_desc *desc)chained_irq_enter (chip, desc); sts =ioread32 (bank->base +NPCM7XX_GP_N_EVST ); en =ioread32 (bank->base +NPCM7XX_GP_N_EVEN ); -dev_dbg (chip->parent_device,"==> got irq sts %.8x %.8x\n" , sts, +dev_dbg (bank->gc.parent,"==> got irq sts %.8x %.8x\n" , sts, en); sts &= en;
@@ -241,33 +240,33 @@ static int npcmgpio_set_irq_type(struct irq_data *d, unsigned int type)gpiochip_get_data (irq_data_get_irq_chip_data (d));unsigned int gpio =BIT (d->hwirq); -dev_dbg (d->chip->parent_device,"setirqtype: %u.%u = %u\n" , gpio, +dev_dbg (bank->gc.parent,"setirqtype: %u.%u = %u\n" , gpio, d->irq, type);switch (type) {case IRQ_TYPE_EDGE_RISING : -dev_dbg (d->chip->parent_device,"edge.rising\n" ); +dev_dbg (bank->gc.parent,"edge.rising\n" );npcm_gpio_clr (&bank->gc, bank->base +NPCM7XX_GP_N_EVBE , gpio);npcm_gpio_clr (&bank->gc, bank->base +NPCM7XX_GP_N_POL , gpio);break ;case IRQ_TYPE_EDGE_FALLING : -dev_dbg (d->chip->parent_device,"edge.falling\n" ); +dev_dbg (bank->gc.parent,"edge.falling\n" );npcm_gpio_clr (&bank->gc, bank->base +NPCM7XX_GP_N_EVBE , gpio);npcm_gpio_set (&bank->gc, bank->base +NPCM7XX_GP_N_POL , gpio);break ;case IRQ_TYPE_EDGE_BOTH : -dev_dbg (d->chip->parent_device,"edge.both\n" ); +dev_dbg (bank->gc.parent,"edge.both\n" );npcm_gpio_set (&bank->gc, bank->base +NPCM7XX_GP_N_EVBE , gpio);break ;case IRQ_TYPE_LEVEL_LOW : -dev_dbg (d->chip->parent_device,"level.low\n" ); +dev_dbg (bank->gc.parent,"level.low\n" );npcm_gpio_set (&bank->gc, bank->base +NPCM7XX_GP_N_POL , gpio);break ;case IRQ_TYPE_LEVEL_HIGH : -dev_dbg (d->chip->parent_device,"level.high\n" ); +dev_dbg (bank->gc.parent,"level.high\n" );npcm_gpio_clr (&bank->gc, bank->base +NPCM7XX_GP_N_POL , gpio);break ;default : -dev_dbg (d->chip->parent_device,"invalid irq type\n" ); +dev_dbg (bank->gc.parent,"invalid irq type\n" );return -EINVAL ; }
@@ -289,7 +288,7 @@ static void npcmgpio_irq_ack(struct irq_data *d)gpiochip_get_data (irq_data_get_irq_chip_data (d));unsigned int gpio = d->hwirq; -dev_dbg (d->chip->parent_device,"irq_ack: %u.%u\n" , gpio, d->irq); +dev_dbg (bank->gc.parent,"irq_ack: %u.%u\n" , gpio, d->irq);iowrite32 (BIT (gpio), bank->base +NPCM7XX_GP_N_EVST ); }
@@ -301,7 +300,7 @@ static void npcmgpio_irq_mask(struct irq_data *d)unsigned int gpio = d->hwirq;/* Clear events */ -dev_dbg (d->chip->parent_device,"irq_mask: %u.%u\n" , gpio, d->irq); +dev_dbg (bank->gc.parent,"irq_mask: %u.%u\n" , gpio, d->irq);iowrite32 (BIT (gpio), bank->base +NPCM7XX_GP_N_EVENC ); }
@@ -313,7 +312,7 @@ static void npcmgpio_irq_unmask(struct irq_data *d)unsigned int gpio = d->hwirq;/* Enable events */ -dev_dbg (d->chip->parent_device,"irq_unmask: %u.%u\n" , gpio, d->irq); +dev_dbg (bank->gc.parent,"irq_unmask: %u.%u\n" , gpio, d->irq);iowrite32 (BIT (gpio), bank->base +NPCM7XX_GP_N_EVENS ); }
@@ -323,7 +322,7 @@ static unsigned int npcmgpio_irq_startup(struct irq_data *d)unsigned int gpio = d->hwirq;/* active-high, input, clear interrupt, enable interrupt */ -dev_dbg (d->chip->parent_device,"startup: %u.%u\n" , gpio, d->irq); +dev_dbg (gc->parent,"startup: %u.%u\n" , gpio, d->irq);npcmgpio_direction_input (gc, gpio);npcmgpio_irq_ack (d);npcmgpio_irq_unmask (d);
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 32/35 nvme-tcp: lockdep: annotate in-kernel sockets
In reply to Sasha LevinFrom: Chris Leech <[email protected]>
[ Upstream commit 841aee4d75f18fdfb53935080b03de0c65e9b92c ]
Put NVMe/TCP sockets in their own class to avoid some lockdep warnings. Sockets created by nvme-tcp are not exposed to user-space, and will not trigger certain code paths that the general socket API exposes.
Lockdep complains about a circular dependency between the socket and filesystem locks, because setsockopt can trigger a page fault with a socket lock held, but nvme-tcp sends requests on the socket while file system locks are held.
======================================================
WARNING: possible circular locking dependency detected 5.15.0-rc3 #1 Not tainted
------------------------------------------------------
fio/1496 is trying to acquire lock:
(sk_lock-AF_INET){+.+.}-{0:0}, at: tcp_sendpage+0x23/0x80
but task is already holding lock:
(&xfs_dir_ilock_class/5){+.+.}-{3:3}, at: xfs_ilock+0xcf/0x290 [xfs]
which lock already depends on the new lock.
other info that might help us debug this:
chain exists of:
sk_lock-AF_INET --> sb_internal --> &xfs_dir_ilock_class/5
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&xfs_dir_ilock_class/5);
lock(sb_internal);
lock(&xfs_dir_ilock_class/5); lock(sk_lock-AF_INET);
*** DEADLOCK ***
6 locks held by fio/1496:
#0: (sb_writers#13){.+.+}-{0:0}, at: path_openat+0x9fc/0xa20
#1: (&inode->i_sb->s_type->i_mutex_dir_key){++++}-{3:3}, at: path_openat+0x296/0xa20 #2: (sb_internal){.+.+}-{0:0}, at: xfs_trans_alloc_icreate+0x41/0xd0 [xfs] #3: (&xfs_dir_ilock_class/5){+.+.}-{3:3}, at: xfs_ilock+0xcf/0x290 [xfs] #4: (hctx->srcu){....}-{0:0}, at: hctx_lock+0x51/0xd0
#5: (&queue->send_mutex){+.+.}-{3:3}, at: nvme_tcp_queue_rq+0x33e/0x380 [nvme_tcp]
This annotation lets lockdep analyze nvme-tcp controlled sockets independently of what the user-space sockets API does.
--- drivers/nvme/host/tcp.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
drivers/nvme/host/tcp.c +40 -0
@@ -30,6 +30,44 @@ static int so_priority;module_param (so_priority, int,0644 );MODULE_PARM_DESC (so_priority,"nvme tcp socket optimize priority" ); +#ifdef CONFIG_DEBUG_LOCK_ALLOC +/* lockdep can detect a circular dependency of the form +* sk_lock -> mmap_lock (page fault) -> fs locks -> sk_lock +* because dependencies are tracked for both nvme-tcp and user contexts. Using +* a separate class prevents lockdep from conflating nvme-tcp socket use with +* user-space socket API use. +*/ +static struct lock_class_key nvme_tcp_sk_key[2 ]; +static struct lock_class_key nvme_tcp_slock_key[2 ]; + +static void nvme_tcp_reclassify_socket (struct socket *sock) +{ +struct sock *sk = sock->sk; + +if (WARN_ON_ONCE (!sock_allow_reclassification (sk))) +return ; + +switch (sk->sk_family) { +case AF_INET : +sock_lock_init_class_and_name (sk,"slock-AF_INET-NVME" , + &nvme_tcp_slock_key[0 ], +"sk_lock-AF_INET-NVME" , + &nvme_tcp_sk_key[0 ]); +break ; +case AF_INET6 : +sock_lock_init_class_and_name (sk,"slock-AF_INET6-NVME" , + &nvme_tcp_slock_key[1 ], +"sk_lock-AF_INET6-NVME" , + &nvme_tcp_sk_key[1 ]); +break ; +default : +WARN_ON_ONCE (1 ); + } +} +#else +static void nvme_tcp_reclassify_socket (struct socket *sock) { } +#endif +enum nvme_tcp_send_state {NVME_TCP_SEND_CMD_PDU =0 ,NVME_TCP_SEND_H2C_PDU ,
@@ -1469,6 +1507,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, goto err_destroy_mutex; } +nvme_tcp_reclassify_socket (queue->sock); +/* Single syn retry */ tcp_sock_set_syncnt (queue->sock->sk,1 );
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 1/35 LSM: general protection fault in legacy_parse_param
From: Casey Schaufler <[email protected]>
[ Upstream commit ecff30575b5ad0eda149aadad247b7f75411fd47 ]
The usual LSM hook "bail on fail" scheme doesn't work for cases where a security module may return an error code indicating that it does not recognize an input. In this particular case Smack sees a mount option that it recognizes, and returns 0. A call to a BPF hook follows, which returns -ENOPARAM, which confuses the caller because Smack has processed its data.
The SELinux hook incorrectly returns 1 on success. There was a time when this was correct, however the current expectation is that it return 0 on success. This is repaired.
--- security/security.c | 17 +++++++++++++++-- security/selinux/hooks.c | 5 ++--- 2 files changed, 17 insertions(+), 5 deletions(-)
security/security.c +15 -2
@@ -884,9 +884,22 @@ int security_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc)return call_int_hook (fs_context_dup,0 , fc, src_fc); } -int security_fs_context_parse_param (struct fs_context *fc,struct fs_parameter *param) +int security_fs_context_parse_param (struct fs_context *fc, +struct fs_parameter *param) { -return call_int_hook (fs_context_parse_param, -ENOPARAM , fc, param); +struct security_hook_list *hp; +int trc; +int rc = -ENOPARAM ; + +hlist_for_each_entry (hp, &security_hook_heads.fs_context_parse_param, + list) { + trc = hp->hook.fs_context_parse_param (fc, param); +if (trc ==0 ) + rc =0 ; +else if (trc != -ENOPARAM ) +return trc; + } +return rc; }int security_sb_alloc (struct super_block *sb)
security/selinux/hooks.c +2 -3
@@ -2909,10 +2909,9 @@ static int selinux_fs_context_parse_param(struct fs_context *fc,return opt; rc =selinux_add_opt (opt, param->string, &fc->security); -if (!rc) { +if (!rc) param->string =NULL ; - rc =1 ; - } +return rc; }
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 14/35 selinux: use correct type for context length
From: Christian Göttsche <[email protected]>
[ Upstream commit b97df7c098c531010e445da88d02b7bf7bf59ef6 ]
security_sid_to_context() expects a pointer to an u32 as the address where to store the length of the computed context.
Reported by sparse:
security/selinux/xfrm.c:359:39: warning: incorrect type in arg 4
(different signedness)
security/selinux/xfrm.c:359:39: expected unsigned int
[usertype] *scontext_len
security/selinux/xfrm.c:359:39: got int *
--- security/selinux/xfrm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/selinux/xfrm.c +1 -1
@@ -347,7 +347,7 @@ int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x,int rc;struct xfrm_sec_ctx *ctx;char *ctx_str =NULL ; -int str_len; +u32 str_len;if (!polsec)return 0 ;
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 17/35 selinux: allow FIOCLEX and FIONCLEX with policy capability
In reply to Sasha LevinFrom: Richard Haines <[email protected]>
[ Upstream commit 65881e1db4e948614d9eb195b8e1197339822949 ]
These ioctls are equivalent to fcntl(fd, F_SETFD, flags), which SELinux always allows too. Furthermore, a failed FIOCLEX could result in a file descriptor being leaked to a process that should not have access to it.
As this patch removes access controls, a policy capability needs to be enabled in policy to always allow these ioctls.
--- security/selinux/hooks.c | 6 ++++++ security/selinux/include/policycap.h | 1 + security/selinux/include/policycap_names.h | 3 ++- security/selinux/include/security.h | 7 +++++++ 4 files changed, 16 insertions(+), 1 deletion(-)
security/selinux/hooks.c +6 -0
@@ -3793,6 +3793,12 @@ static int selinux_file_ioctl(struct file *file, unsigned int cmd, CAP_OPT_NONE, true);break ; +case FIOCLEX : +case FIONCLEX : +if (!selinux_policycap_ioctl_skip_cloexec ()) + error =ioctl_has_perm (cred, file,FILE__IOCTL , (u16 ) cmd); +break ; +/* default case assumes that the command will go * to the file's ioctl() function. */
security/selinux/include/policycap.h +1 -0
@@ -11,6 +11,7 @@ enum {POLICYDB_CAPABILITY_CGROUPSECLABEL ,POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION ,POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS , +POLICYDB_CAPABILITY_IOCTL_SKIP_CLOEXEC , __POLICYDB_CAPABILITY_MAX };#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)
security/selinux/include/policycap_names.h +2 -1
@@ -12,7 +12,8 @@ const char *selinux_policycap_names[__POLICYDB_CAPABILITY_MAX] = {"always_check_network" ,"cgroup_seclabel" ,"nnp_nosuid_transition" , -"genfs_seclabel_symlinks" +"genfs_seclabel_symlinks" , +"ioctl_skip_cloexec" };#endif /* _SELINUX_POLICYCAP_NAMES_H_ */
security/selinux/include/security.h +7 -0
@@ -219,6 +219,13 @@ static inline bool selinux_policycap_genfs_seclabel_symlinks(void)return READ_ONCE (state->policycap[POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS ]); } +static inline bool selinux_policycap_ioctl_skip_cloexec (void ) +{ +struct selinux_state *state = &selinux_state; + +return READ_ONCE (state->policycap[POLICYDB_CAPABILITY_IOCTL_SKIP_CLOEXEC ]); +} +struct selinux_policy_convert_data ;struct selinux_load_state {
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 28/35 ACPI/APEI: Limit printable size of BERT table data
In reply to Sasha LevinFrom: Darren Hart <[email protected]>
[ Upstream commit 3f8dec116210ca649163574ed5f8df1e3b837d07 ]
Platforms with large BERT table data can trigger soft lockup errors while attempting to print the entire BERT table data to the console at boot:
watchdog: BUG: soft lockup - CPU#160 stuck for 23s! [swapper/0:1]
Observed on Ampere Altra systems with a single BERT record of ~250KB.
The original bert driver appears to have assumed relatively small table data. Since it is impractical to reassemble large table data from interwoven console messages, and the table data is available in
/sys/firmware/acpi/tables/data/BERT
limit the size for tables printed to the console to 1024 (for no reason other than it seemed like a good place to kick off the discussion, would appreciate feedback from existing users in terms of what size would maintain their current usage model).
Alternatively, we could make printing a CONFIG option, use the bert_disable boot arg (or something similar), or use a debug log level. However, all those solutions require extra steps or change the existing behavior for small table data. Limiting the size preserves existing behavior on existing platforms with small table data, and eliminates the soft lockups for platforms with large table data, while still making it available.
--- drivers/acpi/apei/bert.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/apei/bert.c +6 -2
@@ -29,6 +29,7 @@#undef pr_fmt#define pr_fmt (fmt) "BERT: " fmt +#define ACPI_BERT_PRINT_MAX_LEN 1024static int bert_disable;
@@ -58,8 +59,11 @@ static void __init bert_print_all(struct acpi_bert_region *region, }pr_info_once ("Error records from previous boot:\n" ); - - cper_estatus_print(KERN_INFO HW_ERR, estatus); +if (region_len <ACPI_BERT_PRINT_MAX_LEN ) + cper_estatus_print(KERN_INFO HW_ERR, estatus); +else +pr_info_once ("Max print length exceeded, table data is available at:\n" +"/sys/firmware/acpi/tables/data/BERT" );/* * Because the boot error source is "one-time polled" type,
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 10/35 block/bfq_wf2q: correct weight to ioprio
In reply to Sasha LevinFrom: Yahu Gao <[email protected]>
[ Upstream commit bcd2be763252f3a4d5fc4d6008d4d96c601ee74b ]
The return value is ioprio * BFQ_WEIGHT_CONVERSION_COEFF or 0. What we want is ioprio or 0.
Correct this by changing the calculation.
--- block/bfq-wf2q.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/bfq-wf2q.c +1 -1
@@ -519,7 +519,7 @@ unsigned short bfq_ioprio_to_weight(int ioprio)static unsigned short bfq_weight_to_ioprio (int weight) {return max_t (int,0 , -IOPRIO_NR_LEVELS *BFQ_WEIGHT_CONVERSION_COEFF - weight); +IOPRIO_NR_LEVELS - weight /BFQ_WEIGHT_CONVERSION_COEFF ); }static void bfq_get_entity (struct bfq_entity *entity)
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 25/35 ACPICA: Avoid walking the ACPI Namespace if it is not there
In reply to Sasha LevinFrom: "Rafael J. Wysocki" <[email protected]>
[ Upstream commit 0c9992315e738e7d6e927ef36839a466b080dba6 ]
ACPICA commit b1c3656ef4950098e530be68d4b589584f06cddc
Prevent acpi_ns_walk_namespace() from crashing when called with start_node equal to ACPI_ROOT_OBJECT if the Namespace has not been instantiated yet and acpi_gbl_root_node is NULL.
For instance, this can happen if the kernel is run with "acpi=off" in the command line.
--- drivers/acpi/acpica/nswalk.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/acpi/acpica/nswalk.c +3 -0
@@ -169,6 +169,9 @@ acpi_ns_walk_namespace(acpi_object_type type,if (start_node ==ACPI_ROOT_OBJECT ) { start_node = acpi_gbl_root_node; +if (!start_node) { +return_ACPI_STATUS (AE_NO_NAMESPACE ); + } }/* Null child means "get first node" */
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 30/35 parisc: Fix non-access data TLB cache flush faults
In reply to Sasha LevinFrom: John David Anglin <[email protected]>
[ Upstream commit f839e5f1cef36ce268950c387129b1bfefdaebc9 ]
When a page is not present, we get non-access data TLB faults from the fdc and fic instructions in flush_user_dcache_range_asm and flush_user_icache_range_asm. When these occur, the cache line is not invalidated and potentially we get memory corruption. The problem was hidden by the nullification of the flush instructions.
These faults also affect performance. With pa8800/pa8900 processors, there will be 32 faults per 4 KB page since the cache line is 128 bytes. There will be more faults with earlier processors.
The problem is fixed by using flush_cache_pages(). It does the flush using a tmp alias mapping.
The flush_cache_pages() call in flush_cache_range() flushed too large a range.
V2: Remove unnecessary preempt_disable() and preempt_enable() calls.
--- arch/parisc/kernel/cache.c | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-)
arch/parisc/kernel/cache.c +1 -27
@@ -558,15 +558,6 @@ static void flush_cache_pages(struct vm_area_struct *vma, struct mm_struct *mm, } } -static void flush_user_cache_tlb (struct vm_area_struct *vma, -unsigned long start,unsigned long end) -{ -flush_user_dcache_range_asm (start, end); -if (vma->vm_flags &VM_EXEC ) -flush_user_icache_range_asm (start, end); -flush_tlb_range (vma, start, end); -} -void flush_cache_mm (struct mm_struct *mm) {struct vm_area_struct *vma;
@@ -581,17 +572,8 @@ void flush_cache_mm(struct mm_struct *mm)return ; } -preempt_disable (); -if (mm->context ==mfsp (3 )) { -for (vma = mm->mmap; vma; vma = vma->vm_next) -flush_user_cache_tlb (vma, vma->vm_start, vma->vm_end); -preempt_enable (); -return ; - } -for (vma = mm->mmap; vma; vma = vma->vm_next)flush_cache_pages (vma, mm, vma->vm_start, vma->vm_end); -preempt_enable (); } void flush_cache_range(struct vm_area_struct *vma,
@@ -605,15 +587,7 @@ void flush_cache_range(struct vm_area_struct *vma,return ; } -preempt_disable (); -if (vma->vm_mm->context ==mfsp (3 )) { -flush_user_cache_tlb (vma, start, end); -preempt_enable (); -return ; - } - -flush_cache_pages (vma, vma->vm_mm, vma->vm_start, vma->vm_end); -preempt_enable (); +flush_cache_pages (vma, vma->vm_mm, start, end); }void
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 31/35 parisc: Fix handling off probe non-access faults
In reply to Sasha LevinFrom: John David Anglin <[email protected]>
[ Upstream commit e00b0a2ab8ec019c344e53bfc76e31c18bb587b7 ]
Currently, the parisc kernel does not fully support non-access TLB fault handling for probe instructions. In the fast path, we set the target register to zero if it is not a shadowed register. The slow path is not implemented, so we call do_page_fault. The architecture indicates that non-access faults should not cause a page fault from disk.
This change adds to code to provide non-access fault support for probe instructions. It also modifies the handling of faults on userspace so that if the address lies in a valid VMA and the access type matches that for the VMA, the probe target register is set to one. Otherwise, the target register is set to zero.
This was done to make probe instructions more useful for userspace. Probe instructions are not very useful if they set the target register to zero whenever a page is not present in memory. Nominally, the purpose of the probe instruction is determine whether read or write access to a given address is allowed.
This fixes a problem in function pointer comparison noticed in the glibc testsuite (stdio-common/tst-vfprintf-user-type). The same problem is likely in glibc (_dl_lookup_address).
V2 adds flush and lpa instruction support to handle_nadtlb_fault.
--- arch/parisc/include/asm/traps.h | 1 + arch/parisc/kernel/traps.c | 2 + arch/parisc/mm/fault.c | 89 +++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+)
arch/parisc/include/asm/traps.h +1 -0
@@ -18,6 +18,7 @@ unsigned long parisc_acctyp(unsigned long code, unsigned int inst);const char *trap_name (unsigned long code);void do_page_fault (struct pt_regs *regs,unsigned long code,unsigned long address); +int handle_nadtlb_fault (struct pt_regs *regs);#endif #endif
arch/parisc/kernel/traps.c +2 -0
@@ -662,6 +662,8 @@ void notrace handle_interruption(int code, struct pt_regs *regs)by hand. Technically we need to emulate: fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw */ +if (code ==17 &&handle_nadtlb_fault (regs)) +return ; fault_address = regs->ior; fault_space = regs->isr;break ;
arch/parisc/mm/fault.c +89 -0
92 lines not on this page · raw message
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 27/35 Revert "Revert "block, bfq: honor already-setup queue merges""
In reply to Sasha LevinFrom: Paolo Valente <[email protected]>
[ Upstream commit 15729ff8143f8135b03988a100a19e66d7cb7ecd ]
A crash [1] happened to be triggered in conjunction with commit 2d52c58b9c9b ("block, bfq: honor already-setup queue merges"). The latter was then reverted by commit ebc69e897e17 ("Revert "block, bfq:
honor already-setup queue merges""). Yet, the reverted commit was not the one introducing the bug. In fact, it actually triggered a UAF introduced by a different commit, and now fixed by commit d29bd41428cf ("block, bfq: reset last_bfqq_created on group change").
So, there is no point in keeping commit 2d52c58b9c9b ("block, bfq:
honor already-setup queue merges") out. This commit restores it.
[1] https://bugzilla.kernel.org/show_bug.cgi?id=214503
--- block/bfq-iosched.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
block/bfq-iosched.c +13 -3
@@ -2662,6 +2662,15 @@ bfq_setup_merge(struct bfq_queue *bfqq, struct bfq_queue *new_bfqq)* are likely to increase the throughput. */ bfqq->new_bfqq = new_bfqq; +/* +* The above assignment schedules the following redirections: +* each time some I/O for bfqq arrives, the process that +* generated that I/O is disassociated from bfqq and +* associated with new_bfqq. Here we increases new_bfqq->ref +* in advance, adding the number of processes that are +* expected to be associated with new_bfqq as they happen to +* issue I/O. +*/ new_bfqq->ref += process_refs;return new_bfqq; }
@@ -2724,6 +2733,10 @@ bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq, {struct bfq_queue *in_service_bfqq, *new_bfqq; +/* if a merge has already been setup, then proceed with that first */ +if (bfqq->new_bfqq) +return bfqq->new_bfqq; +/* * Check delayed stable merge for rotational or non-queueing * devs. For this branch to be executed, bfqq must not be
@@ -2825,9 +2838,6 @@ bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq,if (bfq_too_late_for_merging (bfqq))return NULL ; -if (bfqq->new_bfqq) -return bfqq->new_bfqq; -if (!io_struct ||unlikely (bfqq == &bfqd->oom_bfqq))return NULL ;
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 9/35 memstick/mspro_block: fix handling of read-only devices
In reply to Sasha LevinFrom: Christoph Hellwig <[email protected]>
[ Upstream commit 6dab421bfe06a59bf8f212a72e34673e8acf2018 ]
Use set_disk_ro to propagate the read-only state to the block layer instead of checking for it in ->open and leaking a reference in case of a read-only device.
--- drivers/memstick/core/mspro_block.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/memstick/core/mspro_block.c +4 -6
@@ -186,13 +186,8 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)mutex_lock (&mspro_block_disk_lock); -if (msb && msb->card) { +if (msb && msb->card) msb->usage_count++; -if ((mode &FMODE_WRITE ) && msb->read_only) - rc = -EROFS ; -else - rc =0 ; - }mutex_unlock (&mspro_block_disk_lock);
@@ -1239,6 +1234,9 @@ static int mspro_block_init_disk(struct memstick_dev *card)set_capacity (msb->disk, capacity);dev_dbg (&card->dev,"capacity set %ld\n" , capacity); +if (msb->read_only) +set_disk_ro (msb->disk, true); + rc =device_add_disk (&card->dev, msb->disk,NULL );if (rc) goto out_cleanup_disk;
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 12/35 crypto: hisilicon/sec - not need to enable sm4 extra mode at HW V3
In reply to Sasha LevinFrom: Kai Ye <[email protected]>
[ Upstream commit f8a2652826444d13181061840b96a5d975d5b6c6 ]
It is not need to enable sm4 extra mode in at HW V3. Here is fix it.
--- drivers/crypto/hisilicon/sec2/sec_main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/crypto/hisilicon/sec2/sec_main.c +5 -3
@@ -443,9 +443,11 @@ static int sec_engine_init(struct hisi_qm *qm)writel (SEC_SAA_ENABLE , qm->io_base +SEC_SAA_EN_REG ); -/* Enable sm4 extra mode, as ctr/ecb */ -writel_relaxed (SEC_BD_ERR_CHK_EN0 , - qm->io_base +SEC_BD_ERR_CHK_EN_REG0 ); +/* HW V2 enable sm4 extra mode, as ctr/ecb */ +if (qm->ver <QM_HW_V3 ) +writel_relaxed (SEC_BD_ERR_CHK_EN0 , + qm->io_base +SEC_BD_ERR_CHK_EN_REG0 ); +/* Enable sm4 xts mode multiple iv */ writel_relaxed (SEC_BD_ERR_CHK_EN1 , qm->io_base +SEC_BD_ERR_CHK_EN_REG1 );
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 33/35 spi: tegra20: Use of_device_get_match_data()
In reply to Sasha LevinFrom: Minghao Chi <[email protected]>
[ Upstream commit c9839acfcbe20ce43d363c2a9d0772472d9921c0 ]
Use of_device_get_match_data() to simplify the code.
--- drivers/spi/spi-tegra20-slink.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/spi/spi-tegra20-slink.c +1 -7
@@ -1003,14 +1003,8 @@ static int tegra_slink_probe(struct platform_device *pdev)struct resource *r;int ret, spi_irq;const struct tegra_slink_chip_data *cdata =NULL ; -const struct of_device_id *match; - match =of_match_device (tegra_slink_of_match, &pdev->dev); -if (!match) { -dev_err (&pdev->dev,"Error: No device match found\n" ); -return -ENODEV ; - } - cdata = match->data; + cdata =of_device_get_match_data (&pdev->dev); master =spi_alloc_master (&pdev->dev,sizeof (*tspi));if (!master) {
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 7/35 rcu: Mark writes to the rcu_segcblist structure's ->flags field
In reply to Sasha LevinFrom: "Paul E. McKenney" <[email protected]>
[ Upstream commit c09929031018913b5783872a8b8cdddef4a543c7 ]
KCSAN reports data races between the rcu_segcblist_clear_flags() and rcu_segcblist_set_flags() functions, though misreporting the latter as a call to rcu_segcblist_is_enabled() from call_rcu(). This commit converts the updates of this field to WRITE_ONCE(), relying on the resulting unmarked reads to continue to detect buggy concurrent writes to this field.
--- kernel/rcu/rcu_segcblist.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/rcu/rcu_segcblist.h +2 -2
@@ -56,13 +56,13 @@ static inline long rcu_segcblist_n_cbs(struct rcu_segcblist *rsclp)static inline void rcu_segcblist_set_flags (struct rcu_segcblist *rsclp,int flags) { - rsclp->flags |= flags; +WRITE_ONCE (rsclp->flags, rsclp->flags | flags); }static inline void rcu_segcblist_clear_flags (struct rcu_segcblist *rsclp,int flags) { - rsclp->flags &= ~flags; +WRITE_ONCE (rsclp->flags, rsclp->flags & ~flags); } static inline bool rcu_segcblist_test_flags(struct rcu_segcblist *rsclp,
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 29/35 PM: core: keep irq flags in device_pm_check_callbacks()
In reply to Sasha LevinFrom: Dmitry Baryshkov <[email protected]>
[ Upstream commit 524bb1da785a7ae43dd413cd392b5071c6c367f8 ]
The function device_pm_check_callbacks() can be called under the spin lock (in the reported case it happens from genpd_add_device() -> dev_pm_domain_set(), when the genpd uses spinlocks rather than mutexes.
However this function uncoditionally uses spin_lock_irq() / spin_unlock_irq(), thus not preserving the CPU flags. Use the irqsave/irqrestore instead.
The backtrace for the reference:
[ 2.752010] ------------[ cut here ]------------ [ 2.756769] raw_local_irq_restore() called with IRQs enabled [ 2.762596] WARNING: CPU: 4 PID: 1 at kernel/locking/irqflag-debug.c:10 warn_bogus_irq_restore+0x34/0x50 [ 2.772338] Modules linked in: [ 2.775487] CPU: 4 PID: 1 Comm: swapper/0 Tainted: G S 5.17.0-rc6-00384-ge330d0d82eff-dirty #684 [ 2.781384] Freeing initrd memory: 46024K [ 2.785839] pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 2.785841] pc : warn_bogus_irq_restore+0x34/0x50 [ 2.785844] lr : warn_bogus_irq_restore+0x34/0x50 [ 2.785846] sp : ffff80000805b7d0 [ 2.785847] x29: ffff80000805b7d0 x28: 0000000000000000 x27: 0000000000000002 [ 2.785850] x26: ffffd40e80930b18 x25: ffff7ee2329192b8 x24: ffff7edfc9f60800 [ 2.785853] x23: ffffd40e80930b18 x22: ffffd40e80930d30 x21: ffff7edfc0dffa00 [ 2.785856] x20: ffff7edfc09e3768 x19: 0000000000000000 x18: ffffffffffffffff [ 2.845775] x17: 6572206f74206465 x16: 6c696166203a3030 x15: ffff80008805b4f7 [ 2.853108] x14: 0000000000000000 x13: ffffd40e809550b0 x12: 00000000000003d8 [ 2.860441] x11: 0000000000000148 x10: ffffd40e809550b0 x9 : ffffd40e809550b0 [ 2.867774] x8 : 00000000ffffefff x7 : ffffd40e809ad0b0 x6 : ffffd40e809ad0b0 [ 2.875107] x5 : 000000000000bff4 x4 : 0000000000000000 x3 : 0000000000000000 [ 2.882440] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff7edfc03a8000 [ 2.889774] Call trace: [ 2.892290] warn_bogus_irq_restore+0x34/0x50 [ 2.896770] _raw_spin_unlock_irqrestore+0x94/0xa0 [ 2.901690] genpd_unlock_spin+0x20/0x30 [ 2.905724] genpd_add_device+0x100/0x2d0 [ 2.909850] __genpd_dev_pm_attach+0xa8/0x23c [ 2.914329] genpd_dev_pm_attach_by_id+0xc4/0x190 [ 2.919167] genpd_dev_pm_attach_by_name+0x3c/0xd0 [ 2.924086] dev_pm_domain_attach_by_name+0x24/0x30 [ 2.929102] psci_dt_attach_cpu+0x24/0x90 [ 2.933230] psci_cpuidle_probe+0x2d4/0x46c [ 2.937534] platform_probe+0x68/0xe0 [ 2.941304] really_probe.part.0+0x9c/0x2fc [ 2.945605] __driver_probe_device+0x98/0x144 [ 2.950085] driver_probe_device+0x44/0x15c [ 2.954385] __device_attach_driver+0xb8/0x120 [ 2.958950] bus_for_each_drv+0x78/0xd0 [ 2.962896] __device_attach+0xd8/0x180 [ 2.966843] device_initial_probe+0x14/0x20 [ 2.971144] bus_probe_device+0x9c/0xa4 [ 2.975092] device_add+0x380/0x88c [ 2.978679] platform_device_add+0x114/0x234 [ 2.983067] platform_device_register_full+0x100/0x190 [ 2.988344] psci_idle_init+0x6c/0xb0 [ 2.992113] do_one_initcall+0x74/0x3a0 [ 2.996060] kernel_init_freeable+0x2fc/0x384 [ 3.000543] kernel_init+0x28/0x130 [ 3.004132] ret_from_fork+0x10/0x20 [ 3.007817] irq event stamp: 319826 [ 3.011404] hardirqs last enabled at (319825): [<ffffd40e7eda0268>] __up_console_sem+0x78/0x84 [ 3.020332] hardirqs last disabled at (319826): [<ffffd40e7fd6d9d8>] el1_dbg+0x24/0x8c [ 3.028458] softirqs last enabled at (318312): [<ffffd40e7ec90410>] _stext+0x410/0x588 [ 3.036678] softirqs last disabled at (318299): [<ffffd40e7ed1bf68>] __irq_exit_rcu+0x158/0x174 [ 3.045607] ---[ end trace 0000000000000000 ]---
--- drivers/base/power/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/base/power/main.c +4 -2
@@ -2018,7 +2018,9 @@ static bool pm_ops_is_empty(const struct dev_pm_ops *ops)void device_pm_check_callbacks (struct device *dev) { -spin_lock_irq (&dev->power.lock); +unsigned long flags; + +spin_lock_irqsave (&dev->power.lock, flags); dev->power.no_pm_callbacks = (!dev->bus || (pm_ops_is_empty (dev->bus->pm) && !dev->bus->suspend && !dev->bus->resume)) &&
@@ -2027,7 +2029,7 @@ void device_pm_check_callbacks(struct device *dev) (!dev->pm_domain ||pm_ops_is_empty (&dev->pm_domain->ops)) && (!dev->driver || (pm_ops_is_empty (dev->driver->pm) && !dev->driver->suspend && !dev->driver->resume)); -spin_unlock_irq (&dev->power.lock); +spin_unlock_irqrestore (&dev->power.lock, flags); }bool dev_pm_skip_suspend (struct device *dev)
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 15/35 powercap/dtpm_cpu: Reset per_cpu variable in the release function
In reply to Sasha LevinFrom: Daniel Lezcano <[email protected]>
[ Upstream commit 0aea2e4ec2a2bfa2d7e8820e37ba5b5ce04f20a5 ]
The release function does not reset the per cpu variable when it is called. That will prevent creation again as the variable will be already from the previous creation.
Fix it by resetting them.
--- drivers/powercap/dtpm_cpu.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/powercap/dtpm_cpu.c +7 -0
@@ -150,10 +150,17 @@ static int update_pd_power_uw(struct dtpm *dtpm)static void pd_release (struct dtpm *dtpm) {struct dtpm_cpu *dtpm_cpu =to_dtpm_cpu (dtpm); +struct cpufreq_policy *policy;if (freq_qos_request_active (&dtpm_cpu->qos_req))freq_qos_remove_request (&dtpm_cpu->qos_req); + policy =cpufreq_cpu_get (dtpm_cpu->cpu); +if (policy) { +for_each_cpu (dtpm_cpu->cpu, policy->related_cpus) +per_cpu (dtpm_per_cpu, dtpm_cpu->cpu) =NULL ; + } +kfree (dtpm_cpu); }
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 3/35 crypto: hisilicon/qm - cleanup warning in qm_vf_read_qos
In reply to Sasha LevinFrom: Kai Ye <[email protected]>
[ Upstream commit 05b3bade290d6c940701f97f3233c07cfe27205d ]
The kernel test rebot report this warning: Uninitialized variable: ret. The code flow may return value of ret directly. This value is an uninitialized variable, here is fix it.
--- drivers/crypto/hisilicon/qm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/hisilicon/qm.c +1 -1
@@ -4145,7 +4145,7 @@ static void qm_vf_get_qos(struct hisi_qm *qm, u32 fun_num)static int qm_vf_read_qos (struct hisi_qm *qm) {int cnt =0 ; -int ret; +int ret = -EINVAL ;/* reset mailbox qos val */ qm->mb_qos =0 ;
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 18/35 loop: use sysfs_emit() in the sysfs xxx show()
In reply to Sasha LevinFrom: Chaitanya Kulkarni <[email protected]>
[ Upstream commit b27824d31f09ea7b4a6ba2c1b18bd328df3e8bed ]
sprintf does not know the PAGE_SIZE maximum of the temporary buffer used for outputting sysfs content and it's possible to overrun the PAGE_SIZE buffer length.
Use a generic sysfs_emit function that knows the size of the temporary buffer and ensures that no overrun is done for offset attribute in loop_attr_[offset|sizelimit|autoclear|partscan|dio]_show() callbacks.
--- drivers/block/loop.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/block/loop.c +5 -5
@@ -681,33 +681,33 @@ static ssize_t loop_attr_backing_file_show(struct loop_device *lo, char *buf)static ssize_t loop_attr_offset_show (struct loop_device *lo,char *buf) { -return sprintf (buf,"%llu\n" , (unsigned long long )lo->lo_offset); +return sysfs_emit (buf,"%llu\n" , (unsigned long long )lo->lo_offset); }static ssize_t loop_attr_sizelimit_show (struct loop_device *lo,char *buf) { -return sprintf (buf,"%llu\n" , (unsigned long long )lo->lo_sizelimit); +return sysfs_emit (buf,"%llu\n" , (unsigned long long )lo->lo_sizelimit); }static ssize_t loop_attr_autoclear_show (struct loop_device *lo,char *buf) {int autoclear = (lo->lo_flags &LO_FLAGS_AUTOCLEAR ); -return sprintf (buf,"%s\n" , autoclear ?"1" :"0" ); +return sysfs_emit (buf,"%s\n" , autoclear ?"1" :"0" ); }static ssize_t loop_attr_partscan_show (struct loop_device *lo,char *buf) {int partscan = (lo->lo_flags &LO_FLAGS_PARTSCAN ); -return sprintf (buf,"%s\n" , partscan ?"1" :"0" ); +return sysfs_emit (buf,"%s\n" , partscan ?"1" :"0" ); }static ssize_t loop_attr_dio_show (struct loop_device *lo,char *buf) {int dio = (lo->lo_flags &LO_FLAGS_DIRECT_IO ); -return sprintf (buf,"%s\n" , dio ?"1" :"0" ); +return sysfs_emit (buf,"%s\n" , dio ?"1" :"0" ); }LOOP_ATTR_RO (backing_file);
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 5/35 rcu: Kill rnp->ofl_seq and use only rcu_state.ofl_lock for exclusion
In reply to Sasha LevinFrom: David Woodhouse <[email protected]>
[ Upstream commit 82980b1622d97017053c6792382469d7dc26a486 ]
If we allow architectures to bring APs online in parallel, then we end up requiring rcu_cpu_starting() to be reentrant. But currently, the manipulation of rnp->ofl_seq is not thread-safe.
However, rnp->ofl_seq is also fairly much pointless anyway since both rcu_cpu_starting() and rcu_report_dead() hold rcu_state.ofl_lock for fairly much the whole time that rnp->ofl_seq is set to an odd number to indicate that an operation is in progress.
So drop rnp->ofl_seq completely, and use only rcu_state.ofl_lock.
This has a couple of minor complexities: lockdep will complain when we take rcu_state.ofl_lock, and currently accepts the 'excuse' of having an odd value in rnp->ofl_seq. So switch it to an arch_spinlock_t to avoid that false positive complaint. Since we're killing rnp->ofl_seq of course that 'excuse' has to be changed too, so make it check for arch_spin_is_locked(rcu_state.ofl_lock).
There's no arch_spin_lock_irqsave() so we have to manually save and restore local interrupts around the locking.
At Paul's request based on Neeraj's analysis, make rcu_gp_init not just wait but *exclude* any CPU online/offline activity, which was fairly much true already by virtue of it holding rcu_state.ofl_lock.
--- kernel/rcu/tree.c | 71 ++++++++++++++++++++++++----------------------- kernel/rcu/tree.h | 4 +-- 2 files changed, 37 insertions(+), 38 deletions(-)
kernel/rcu/tree.c +36 -35
@@ -91,7 +91,7 @@ static struct rcu_state rcu_state = { .abbr = RCU_ABBR, .exp_mutex = __MUTEX_INITIALIZER(rcu_state.exp_mutex), .exp_wake_mutex = __MUTEX_INITIALIZER(rcu_state.exp_wake_mutex), - .ofl_lock = __RAW_SPIN_LOCK_UNLOCKED(rcu_state.ofl_lock), + .ofl_lock = __ARCH_SPIN_LOCK_UNLOCKED, };/* Dump rcu_node combining tree at boot to verify correct setup. */
@@ -1168,7 +1168,15 @@ bool rcu_lockdep_current_cpu_online(void)preempt_disable_notrace (); rdp =this_cpu_ptr (&rcu_data); rnp = rdp->mynode; -if (rdp->grpmask &rcu_rnp_online_cpus (rnp) ||READ_ONCE (rnp->ofl_seq) &0x1 ) +/* +* Strictly, we care here about the case where the current CPU is +* in rcu_cpu_starting() and thus has an excuse for rdp->grpmask +* not being up to date. So arch_spin_is_locked() might have a +* false positive if it's held by some *other* CPU, but that's +* OK because that just means a false *negative* on the warning. +*/ +if (rdp->grpmask &rcu_rnp_online_cpus (rnp) || +arch_spin_is_locked (&rcu_state.ofl_lock)) ret = true;preempt_enable_notrace ();return ret;
@@ -1732,7 +1740,6 @@ static void rcu_strict_gp_boundary(void *unused)*/ static noinline_for_stack bool rcu_gp_init(void) { -unsigned long firstseq;unsigned long flags;unsigned long oldmask;unsigned long mask;
@@ -1775,22 +1782,17 @@ static noinline_for_stack bool rcu_gp_init(void)* of RCU's Requirements documentation. */ WRITE_ONCE (rcu_state.gp_state,RCU_GP_ONOFF ); +/* Exclude CPU hotplug operations. */ rcu_for_each_leaf_node (rnp) { -// Wait for CPU-hotplug operations that might have -// started before this grace period did. -smp_mb ();// Pair with barriers used when updating ->ofl_seq to odd values. - firstseq =READ_ONCE (rnp->ofl_seq); -if (firstseq &0x1 ) -while (firstseq ==READ_ONCE (rnp->ofl_seq)) -schedule_timeout_idle (1 );// Can't wake unless RCU is watching. -smp_mb ();// Pair with barriers used when updating ->ofl_seq to even values. -raw_spin_lock (&rcu_state.ofl_lock); -raw_spin_lock_irq_rcu_node (rnp); +local_irq_save (flags); +arch_spin_lock (&rcu_state.ofl_lock); +raw_spin_lock_rcu_node (rnp);if (rnp->qsmaskinit == rnp->qsmaskinitnext && !rnp->wait_blkd_tasks) {/* Nothing to do on this leaf rcu_node structure. */ -raw_spin_unlock_irq_rcu_node (rnp); -raw_spin_unlock (&rcu_state.ofl_lock); +raw_spin_unlock_rcu_node (rnp); +arch_spin_unlock (&rcu_state.ofl_lock); +local_irq_restore (flags);continue ; }
@@ -1825,8 +1827,9 @@ static noinline_for_stack bool rcu_gp_init(void)rcu_cleanup_dead_rnp (rnp); } -raw_spin_unlock_irq_rcu_node (rnp); -raw_spin_unlock (&rcu_state.ofl_lock); +raw_spin_unlock_rcu_node (rnp); +arch_spin_unlock (&rcu_state.ofl_lock); +local_irq_restore (flags); }rcu_gp_slow (gp_preinit_delay);/* Races with CPU hotplug. */
@@ -4247,11 +4250,10 @@ void rcu_cpu_starting(unsigned int cpu) rnp = rdp->mynode; mask = rdp->grpmask; -WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); -WARN_ON_ONCE (!(rnp->ofl_seq &0x1 )); +local_irq_save (flags); +arch_spin_lock (&rcu_state.ofl_lock);rcu_dynticks_eqs_online (); -smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -raw_spin_lock_irqsave_rcu_node (rnp, flags); +raw_spin_lock_rcu_node (rnp);WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext | mask); newcpu = !(rnp->expmaskinitnext & mask); rnp->expmaskinitnext |= mask;
@@ -4264,15 +4266,18 @@ void rcu_cpu_starting(unsigned int cpu)/* An incoming CPU should never be blocking a grace period. */ if (WARN_ON_ONCE (rnp->qsmask & mask)) {/* RCU waiting on incoming CPU? */ +/* rcu_report_qs_rnp() *really* wants some flags to restore */ +unsigned long flags2; + +local_irq_save (flags2);rcu_disable_urgency_upon_qs (rdp);/* Report QS -after- changing ->qsmaskinitnext! */ -rcu_report_qs_rnp (mask, rnp, rnp->gp_seq, flags); +rcu_report_qs_rnp (mask, rnp, rnp->gp_seq, flags2); }else { -raw_spin_unlock_irqrestore_rcu_node (rnp, flags); +raw_spin_unlock_rcu_node (rnp); } -smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); -WARN_ON_ONCE (rnp->ofl_seq &0x1 ); +arch_spin_unlock (&rcu_state.ofl_lock); +local_irq_restore (flags);smp_mb ();/* Ensure RCU read-side usage follows above initialization. */ }
@@ -4286,7 +4291,7 @@ void rcu_cpu_starting(unsigned int cpu)*/ void rcu_report_dead (unsigned int cpu) { -unsigned long flags; +unsigned long flags, seq_flags;unsigned long mask;struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);struct rcu_node *rnp = rdp->mynode;/* Outgoing CPU's rdp & rnp. */
@@ -4300,10 +4305,8 @@ void rcu_report_dead(unsigned int cpu)/* Remove outgoing CPU from mask in the leaf rcu_node structure. */ mask = rdp->grpmask; -WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); -WARN_ON_ONCE (!(rnp->ofl_seq &0x1 )); -smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -raw_spin_lock (&rcu_state.ofl_lock); +local_irq_save (seq_flags); +arch_spin_lock (&rcu_state.ofl_lock);raw_spin_lock_irqsave_rcu_node (rnp, flags);/* Enforce GP memory-order guarantee. */ rdp->rcu_ofl_gp_seq =READ_ONCE (rcu_state.gp_seq); rdp->rcu_ofl_gp_flags =READ_ONCE (rcu_state.gp_flags);
@@ -4314,10 +4317,8 @@ void rcu_report_dead(unsigned int cpu) }WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext & ~mask);raw_spin_unlock_irqrestore_rcu_node (rnp, flags); -raw_spin_unlock (&rcu_state.ofl_lock); -smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); -WARN_ON_ONCE (rnp->ofl_seq &0x1 ); +arch_spin_unlock (&rcu_state.ofl_lock); +local_irq_restore (seq_flags); rdp->cpu_started = false; }
kernel/rcu/tree.h +1 -3
@@ -56,8 +56,6 @@ struct rcu_node {/* Initialized from ->qsmaskinitnext at the */ /* beginning of each grace period. */ unsigned long qsmaskinitnext; -unsigned long ofl_seq;/* CPU-hotplug operation sequence count. */ -/* Online CPUs for next grace period. */ unsigned long expmask;/* CPUs or groups that need to check in */ /* to allow the current expedited GP */ /* to complete. */
@@ -358,7 +356,7 @@ struct rcu_state {const char *name;/* Name of structure. */ char abbr;/* Abbreviated name. */ -raw_spinlock_t ofl_lock____cacheline_internodealigned_in_smp ; +arch_spinlock_t ofl_lock____cacheline_internodealigned_in_smp ;/* Synchronize offline with */ /* GP pre-initialization. */ };
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 11/35 crypto: xts - Add softdep on ecb
In reply to Sasha LevinFrom: Herbert Xu <[email protected]>
[ Upstream commit dfe085d8dcd0bb1fe20cc2327e81c8064cead441 ]
The xts module needs ecb to be present as it's meant to work on top of ecb. This patch adds a softdep so ecb can be included automatically into the initramfs.
--- crypto/xts.c | 1 + 1 file changed, 1 insertion(+)
crypto/xts.c +1 -0
@@ -466,3 +466,4 @@ MODULE_LICENSE("GPL");MODULE_DESCRIPTION ("XTS block cipher mode" );MODULE_ALIAS_CRYPTO ("xts" );MODULE_IMPORT_NS (CRYPTO_INTERNAL ); +MODULE_SOFTDEP ("pre: ecb" );
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 19/35 Fix incorrect type in assignment of ipv6 port for audit
In reply to Sasha LevinFrom: Casey Schaufler <[email protected]>
[ Upstream commit a5cd1ab7ab679d252a6d2f483eee7d45ebf2040c ]
Remove inappropriate use of ntohs() and assign the port value directly.
--- security/smack/smack_lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/smack/smack_lsm.c +1 -1
@@ -2511,7 +2511,7 @@ static int smk_ipv6_check(struct smack_known *subject,#ifdef CONFIG_AUDIT smk_ad_init_net (&ad, __func__,LSM_AUDIT_DATA_NET , &net); ad.a.u.net->family =PF_INET6 ; - ad.a.u.net->dport =ntohs (address->sin6_port); + ad.a.u.net->dport = address->sin6_port;if (act ==SMK_RECEIVING ) ad.a.u.net->v6info.saddr = address->sin6_addr;else
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 20/35 irqchip/qcom-pdc: Fix broken locking
In reply to Sasha LevinFrom: Marc Zyngier <[email protected]>
[ Upstream commit a6aca2f460e203781dc41391913cc5b54f4bc0ce ]
pdc_enable_intr() serves as a primitive to qcom_pdc_gic_{en,dis}able, and has a raw spinlock for mutual exclusion, which is uses with interruptible primitives.
This means that this critical section can itself be interrupted. Should the interrupt also be a PDC interrupt, and the endpoint driver perform an irq_disable() on that interrupt, we end-up in a deadlock.
Fix this by using the irqsave/irqrestore variants of the locking primitives.
--- drivers/irqchip/qcom-pdc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/irqchip/qcom-pdc.c +3 -2
@@ -56,17 +56,18 @@ static u32 pdc_reg_read(int reg, u32 i)static void pdc_enable_intr (struct irq_data *d,bool on) {int pin_out = d->hwirq; +unsigned long flags;u32 index, mask;u32 enable; index = pin_out /32 ; mask = pin_out %32 ; -raw_spin_lock (&pdc_lock); +raw_spin_lock_irqsave (&pdc_lock, flags); enable =pdc_reg_read (IRQ_ENABLE_BANK , index); enable = on ?ENABLE_INTR (enable, mask) :CLEAR_INTR (enable, mask);pdc_reg_write (IRQ_ENABLE_BANK , index, enable); -raw_spin_unlock (&pdc_lock); +raw_spin_unlock_irqrestore (&pdc_lock, flags); }static void qcom_pdc_gic_disable (struct irq_data *d)
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 24/35 bfq: fix use-after-free in bfq_dispatch_request
In reply to Sasha LevinFrom: Zhang Wensheng <[email protected]>
[ Upstream commit ab552fcb17cc9e4afe0e4ac4df95fc7b30e8490a ]
KASAN reports a use-after-free report when doing normal scsi-mq test
[69832.239032] ================================================================== [69832.241810] BUG: KASAN: use-after-free in bfq_dispatch_request+0x1045/0x44b0 [69832.243267] Read of size 8 at addr ffff88802622ba88 by task kworker/3:1H/155 [69832.244656] [69832.245007] CPU: 3 PID: 155 Comm: kworker/3:1H Not tainted 5.10.0-10295-g576c6382529e #8 [69832.246626] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014 [69832.249069] Workqueue: kblockd blk_mq_run_work_fn [69832.250022] Call Trace: [69832.250541] dump_stack+0x9b/0xce [69832.251232] ? bfq_dispatch_request+0x1045/0x44b0 [69832.252243] print_address_description.constprop.6+0x3e/0x60 [69832.253381] ? __cpuidle_text_end+0x5/0x5 [69832.254211] ? vprintk_func+0x6b/0x120 [69832.254994] ? bfq_dispatch_request+0x1045/0x44b0 [69832.255952] ? bfq_dispatch_request+0x1045/0x44b0 [69832.256914] kasan_report.cold.9+0x22/0x3a [69832.257753] ? bfq_dispatch_request+0x1045/0x44b0 [69832.258755] check_memory_region+0x1c1/0x1e0 [69832.260248] bfq_dispatch_request+0x1045/0x44b0 [69832.261181] ? bfq_bfqq_expire+0x2440/0x2440 [69832.262032] ? blk_mq_delay_run_hw_queues+0xf9/0x170 [69832.263022] __blk_mq_do_dispatch_sched+0x52f/0x830 [69832.264011] ? blk_mq_sched_request_inserted+0x100/0x100 [69832.265101] __blk_mq_sched_dispatch_requests+0x398/0x4f0 [69832.266206] ? blk_mq_do_dispatch_ctx+0x570/0x570 [69832.267147] ? __switch_to+0x5f4/0xee0 [69832.267898] blk_mq_sched_dispatch_requests+0xdf/0x140 [69832.268946] __blk_mq_run_hw_queue+0xc0/0x270 [69832.269840] blk_mq_run_work_fn+0x51/0x60 [69832.278170] process_one_work+0x6d4/0xfe0 [69832.278984] worker_thread+0x91/0xc80 [69832.279726] ? __kthread_parkme+0xb0/0x110 [69832.280554] ? process_one_work+0xfe0/0xfe0 [69832.281414] kthread+0x32d/0x3f0 [69832.282082] ? kthread_park+0x170/0x170 [69832.282849] ret_from_fork+0x1f/0x30 [69832.283573] [69832.283886] Allocated by task 7725: [69832.284599] kasan_save_stack+0x19/0x40 [69832.285385] __kasan_kmalloc.constprop.2+0xc1/0xd0 [69832.286350] kmem_cache_alloc_node+0x13f/0x460 [69832.287237] bfq_get_queue+0x3d4/0x1140 [69832.287993] bfq_get_bfqq_handle_split+0x103/0x510 [69832.289015] bfq_init_rq+0x337/0x2d50 [69832.289749] bfq_insert_requests+0x304/0x4e10 [69832.290634] blk_mq_sched_insert_requests+0x13e/0x390 [69832.291629] blk_mq_flush_plug_list+0x4b4/0x760 [69832.292538] blk_flush_plug_list+0x2c5/0x480 [69832.293392] io_schedule_prepare+0xb2/0xd0 [69832.294209] io_schedule_timeout+0x13/0x80 [69832.295014] wait_for_common_io.constprop.1+0x13c/0x270 [69832.296137] submit_bio_wait+0x103/0x1a0 [69832.296932] blkdev_issue_discard+0xe6/0x160 [69832.297794] blk_ioctl_discard+0x219/0x290 [69832.298614] blkdev_common_ioctl+0x50a/0x1750 [69832.304715] blkdev_ioctl+0x470/0x600 [69832.305474] block_ioctl+0xde/0x120 [69832.306232] vfs_ioctl+0x6c/0xc0 [69832.306877] __se_sys_ioctl+0x90/0xa0 [69832.307629] do_syscall_64+0x2d/0x40 [69832.308362] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [69832.309382] [69832.309701] Freed by task 155: [69832.310328] kasan_save_stack+0x19/0x40 [69832.311121] kasan_set_track+0x1c/0x30 [69832.311868] kasan_set_free_info+0x1b/0x30 [69832.312699] __kasan_slab_free+0x111/0x160 [69832.313524] kmem_cache_free+0x94/0x460 [69832.314367] bfq_put_queue+0x582/0x940 [69832.315112] __bfq_bfqd_reset_in_service+0x166/0x1d0 [69832.317275] bfq_bfqq_expire+0xb27/0x2440 [69832.318084] bfq_dispatch_request+0x697/0x44b0 [69832.318991] __blk_mq_do_dispatch_sched+0x52f/0x830 [69832.319984] __blk_mq_sched_dispatch_requests+0x398/0x4f0 [69832.321087] blk_mq_sched_dispatch_requests+0xdf/0x140 [69832.322225] __blk_mq_run_hw_queue+0xc0/0x270 [69832.323114] blk_mq_run_work_fn+0x51/0x60 [69832.323942] process_one_work+0x6d4/0xfe0 [69832.324772] worker_thread+0x91/0xc80 [69832.325518] kthread+0x32d/0x3f0 [69832.326205] ret_from_fork+0x1f/0x30 [69832.326932] [69832.338297] The buggy address belongs to the object at ffff88802622b968 [69832.338297] which belongs to the cache bfq_queue of size 512 [69832.340766] The buggy address is located 288 bytes inside of [69832.340766] 512-byte region [ffff88802622b968, ffff88802622bb68) [69832.343091] The buggy address belongs to the page: [69832.344097] page:ffffea0000988a00 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88802622a528 pfn:0x26228 [69832.346214] head:ffffea0000988a00 order:2 compound_mapcount:0 compound_pincount:0 [69832.347719] flags: 0x1fffff80010200(slab|head) [69832.348625] raw: 001fffff80010200 ffffea0000dbac08 ffff888017a57650 ffff8880179fe840 [69832.354972] raw: ffff88802622a528 0000000000120008 00000001ffffffff 0000000000000000 [69832.356547] page dumped because: kasan: bad access detected [69832.357652] [69832.357970] Memory state around the buggy address: [69832.358926] ffff88802622b980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [69832.360358] ffff88802622ba00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [69832.361810] >ffff88802622ba80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [69832.363273] ^ [69832.363975] ffff88802622bb00: fb fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc [69832.375960] ffff88802622bb80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [69832.377405] ==================================================================
In bfq_dispatch_requestfunction, it may have function call:
bfq_dispatch_request
__bfq_dispatch_request
bfq_select_queue
bfq_bfqq_expire
__bfq_bfqd_reset_in_service
bfq_put_queue
kmem_cache_free
In this function call, in_serv_queue has beed expired and meet the conditions to free. In the function bfq_dispatch_request, the address of in_serv_queue pointing to has been released. For getting the value of idle_timer_disabled, it will get flags value from the address which in_serv_queue pointing to, then the problem of use-after-free happens;
Fix the problem by check in_serv_queue == bfqd->in_service_queue, to get the value of idle_timer_disabled if in_serve_queue is equel to bfqd->in_service_queue. If the space of in_serv_queue pointing has been released, this judge will aviod use-after-free problem. And if in_serv_queue may be expired or finished, the idle_timer_disabled will be false which would not give effects to bfq_update_dispatch_stats.
--- block/bfq-iosched.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
block/bfq-iosched.c +8 -7
@@ -5061,7 +5061,7 @@ static struct request *bfq_dispatch_request(struct blk_mq_hw_ctx *hctx)struct bfq_data *bfqd = hctx->queue->elevator->elevator_data;struct request *rq;struct bfq_queue *in_serv_queue; -bool waiting_rq, idle_timer_disabled; +bool waiting_rq, idle_timer_disabled = false;spin_lock_irq (&bfqd->lock);
@@ -5069,14 +5069,15 @@ static struct request *bfq_dispatch_request(struct blk_mq_hw_ctx *hctx) waiting_rq = in_serv_queue &&bfq_bfqq_wait_request (in_serv_queue); rq =__bfq_dispatch_request (hctx); - - idle_timer_disabled = - waiting_rq && !bfq_bfqq_wait_request (in_serv_queue); +if (in_serv_queue == bfqd->in_service_queue) { + idle_timer_disabled = + waiting_rq && !bfq_bfqq_wait_request (in_serv_queue); + }spin_unlock_irq (&bfqd->lock); - -bfq_update_dispatch_stats (hctx->queue, rq, in_serv_queue, - idle_timer_disabled); +bfq_update_dispatch_stats (hctx->queue, rq, + idle_timer_disabled ? in_serv_queue :NULL , + idle_timer_disabled);return rq; }
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 4/35 gcc-plugins/stackleak: Exactly match strings instead of prefixes
In reply to Sasha LevinFrom: Kees Cook <[email protected]>
[ Upstream commit 27e9faf415dbf94af19b9c827842435edbc1fbbc ]
Since STRING_CST may not be NUL terminated, strncmp() was used for check for equality. However, this may lead to mismatches for longer section names where the start matches the tested-for string. Test for exact equality by checking for the presences of NUL termination.
--- scripts/gcc-plugins/stackleak_plugin.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
scripts/gcc-plugins/stackleak_plugin.c +21 -4
@@ -429,6 +429,23 @@ static unsigned int stackleak_cleanup_execute(void)return 0 ; } +/* +* STRING_CST may or may not be NUL terminated: +* https://gcc.gnu.org/onlinedocs/gccint/Constant-expressions.html +*/ +static inline bool string_equal (tree node,const char *string,int length) +{ +if (TREE_STRING_LENGTH (node) < length) +return false; +if (TREE_STRING_LENGTH (node) > length +1 ) +return false; +if (TREE_STRING_LENGTH (node) == length +1 && +TREE_STRING_POINTER (node)[length] !='\0' ) +return false; +return !memcmp (TREE_STRING_POINTER (node), string, length); +} +#define STRING_EQUAL (node, str) string_equal(node, str, strlen(str)) +static bool stackleak_gate (void ) {tree section;
@@ -438,13 +455,13 @@ static bool stackleak_gate(void)if (section &&TREE_VALUE (section)) { section =TREE_VALUE (TREE_VALUE (section)); -if (!strncmp (TREE_STRING_POINTER (section),".init.text" ,10 )) +if (STRING_EQUAL (section,".init.text" ))return false; -if (!strncmp (TREE_STRING_POINTER (section),".devinit.text" ,13 )) +if (STRING_EQUAL (section,".devinit.text" ))return false; -if (!strncmp (TREE_STRING_POINTER (section),".cpuinit.text" ,13 )) +if (STRING_EQUAL (section,".cpuinit.text" ))return false; -if (!strncmp (TREE_STRING_POINTER (section),".meminit.text" ,13 )) +if (STRING_EQUAL (section,".meminit.text" ))return false; }
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 2/35 regulator: rpi-panel: Handle I2C errors/timing to the Atmel
In reply to Sasha LevinFrom: Dave Stevenson <[email protected]>
[ Upstream commit 5665eee7a3800430e7dc3ef6f25722476b603186 ]
The Atmel is doing some things in the I2C ISR, during which period it will not respond to further commands. This is particularly true of the POWERON command.
Increase delays appropriately, and retry should I2C errors be reported.
--- .../regulator/rpi-panel-attiny-regulator.c | 56 +++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-)
drivers/regulator/rpi-panel-attiny-regulator.c +46 -10
@@ -37,11 +37,24 @@ static const struct regmap_config attiny_regmap_config = {static int attiny_lcd_power_enable (struct regulator_dev *rdev) {unsigned int data; +int ret, i;regmap_write (rdev->regmap,REG_POWERON ,1 ); +msleep (80 ); +/* Wait for nPWRDWN to go low to indicate poweron is done. */ -regmap_read_poll_timeout (rdev->regmap,REG_PORTB , data, - data &BIT (0 ),10 ,1000000 ); +for (i =0 ; i <20 ; i++) { + ret =regmap_read (rdev->regmap,REG_PORTB , &data); +if (!ret) { +if (data &BIT (0 )) +break ; + } +usleep_range (10000 ,12000 ); + } +usleep_range (10000 ,12000 ); + +if (ret) +pr_err ("%s: regmap_read_poll_timeout failed %d\n" , __func__, ret);/* Default to the same orientation as the closed source * firmware used for the panel. Runtime rotation
@@ -57,23 +70,34 @@ static int attiny_lcd_power_disable(struct regulator_dev *rdev) {regmap_write (rdev->regmap,REG_PWM ,0 );regmap_write (rdev->regmap,REG_POWERON ,0 ); -udelay (1 ); +msleep (30 );return 0 ; }static int attiny_lcd_power_is_enabled (struct regulator_dev *rdev) {unsigned int data; -int ret; +int ret, i; - ret =regmap_read (rdev->regmap,REG_POWERON , &data); +for (i =0 ; i <10 ; i++) { + ret =regmap_read (rdev->regmap,REG_POWERON , &data); +if (!ret) +break ; +usleep_range (10000 ,12000 ); + }if (ret <0 )return ret;if (!(data &BIT (0 )))return 0 ; - ret =regmap_read (rdev->regmap,REG_PORTB , &data); +for (i =0 ; i <10 ; i++) { + ret =regmap_read (rdev->regmap,REG_PORTB , &data); +if (!ret) +break ; +usleep_range (10000 ,12000 ); + } +if (ret <0 )return ret;
@@ -103,20 +127,32 @@ static int attiny_update_status(struct backlight_device *bl) {struct regmap *regmap =bl_get_data (bl);int brightness = bl->props.brightness; +int ret, i;if (bl->props.power !=FB_BLANK_UNBLANK || bl->props.fb_blank !=FB_BLANK_UNBLANK ) brightness =0 ; -return regmap_write (regmap,REG_PWM , brightness); +for (i =0 ; i <10 ; i++) { + ret =regmap_write (regmap,REG_PWM , brightness); +if (!ret) +break ; + } + +return ret; }static int attiny_get_brightness (struct backlight_device *bl) {struct regmap *regmap =bl_get_data (bl); -int ret, brightness; +int ret, brightness, i; + +for (i =0 ; i <10 ; i++) { + ret =regmap_read (regmap,REG_PWM , &brightness); +if (!ret) +break ; + } - ret =regmap_read (regmap,REG_PWM , &brightness);if (ret)return ret;
@@ -166,7 +202,7 @@ static int attiny_i2c_probe(struct i2c_client *i2c, }regmap_write (regmap,REG_POWERON ,0 ); -mdelay (1 ); +msleep (30 ); config.dev = &i2c->dev; config.regmap = regmap;
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 21/35 irqchip/nvic: Release nvic_base upon failure
In reply to Sasha LevinFrom: "Souptick Joarder (HPE)" <[email protected]>
[ Upstream commit e414c25e3399b2b3d7337dc47abccab5c71b7c8f ]
smatch warning was reported as below ->
smatch warnings:drivers/irqchip/irq-nvic.c:131 nvic_of_init()
warn: 'nvic_base' not released on lines: 97.
Release nvic_base upon failure.
--- drivers/irqchip/irq-nvic.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/irqchip/irq-nvic.c +2 -0
@@ -107,6 +107,7 @@ static int __init nvic_of_init(struct device_node *node,if (!nvic_irq_domain) {pr_warn ("Failed to allocate irq domain\n" ); +iounmap (nvic_base);return -ENOMEM ; }
@@ -116,6 +117,7 @@ static int __init nvic_of_init(struct device_node *node,if (ret) {pr_warn ("Failed to allocate irq chips\n" );irq_domain_remove (nvic_irq_domain); +iounmap (nvic_base);return ret; }
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 23/35 signal, x86: Delay calling signals in atomic on RT enabled kernels
In reply to Sasha LevinFrom: Oleg Nesterov <[email protected]>
[ Upstream commit bf9ad37dc8a30cce22ae95d6c2ca6abf8731d305 ]
On x86_64 we must disable preemption before we enable interrupts for stack faults, int3 and debugging, because the current task is using a per CPU debug stack defined by the IST. If we schedule out, another task can come in and use the same stack and cause the stack to be corrupted and crash the kernel on return.
When CONFIG_PREEMPT_RT is enabled, spinlock_t locks become sleeping, and one of these is the spin lock used in signal handling.
Some of the debug code (int3) causes do_trap() to send a signal. This function calls a spinlock_t lock that has been converted to a sleeping lock. If this happens, the above issues with the corrupted stack is possible.
Instead of calling the signal right away, for PREEMPT_RT and x86, the signal information is stored on the stacks task_struct and TIF_NOTIFY_RESUME is set. Then on exit of the trap, the signal resume code will send the signal when preemption is enabled.
[ rostedt: Switched from #ifdef CONFIG_PREEMPT_RT to
ARCH_RT_DELAYS_SIGNAL_SEND and added comments to the code. ]
[bigeasy: Add on 32bit as per Yang Shi, minor rewording. ] [ tglx: Use a config option ]
--- arch/x86/Kconfig | 1 + include/linux/sched.h | 3 +++ kernel/Kconfig.preempt | 12 +++++++++++- kernel/entry/common.c | 14 ++++++++++++++ kernel/signal.c | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-)
arch/x86/Kconfig +1 -0
@@ -119,6 +119,7 @@ config X86 select ARCH_WANTS_NO_INSTR select ARCH_WANT_HUGE_PMD_SHARE select ARCH_WANT_LD_ORPHAN_WARN + select ARCH_WANTS_RT_DELAYED_SIGNALS select ARCH_WANTS_THP_SWAP if X86_64 select ARCH_HAS_PARANOID_L1D_FLUSH select BUILDTIME_TABLE_SORT
include/linux/sched.h +3 -0
@@ -1082,6 +1082,9 @@ struct task_struct {/* Restored if set_restore_sigmask() was used: */ sigset_t saved_sigmask;struct sigpending pending; +#ifdef CONFIG_RT_DELAYED_SIGNALS +struct kernel_siginfo forced_info; +#endif unsigned long sas_ss_sp;size_t sas_ss_size;unsigned int sas_ss_flags;
kernel/Kconfig.preempt +11 -1
@@ -132,4 +132,14 @@ config SCHED_CORE which is the likely usage by Linux distributions, there should be no measurable impact on performance. - +config ARCH_WANTS_RT_DELAYED_SIGNALS + bool + help + This option is selected by architectures where raising signals + can happen in atomic contexts on PREEMPT_RT enabled kernels. This + option delays raising the signal until the return to user space + loop where it is also delivered. X86 requires this to deliver + signals from trap handlers which run on IST stacks. + +config RT_DELAYED_SIGNALS + def_bool PREEMPT_RT && ARCH_WANTS_RT_DELAYED_SIGNALS
kernel/entry/common.c +14 -0
@@ -148,6 +148,18 @@ static void handle_signal_work(struct pt_regs *regs, unsigned long ti_work)arch_do_signal_or_restart (regs, ti_work & _TIF_SIGPENDING); } +#ifdef CONFIG_RT_DELAYED_SIGNALS +static inline void raise_delayed_signal (void ) +{ +if (unlikely (current->forced_info.si_signo)) { +force_sig_info (¤t->forced_info); + current->forced_info.si_signo =0 ; + } +} +#else +static inline void raise_delayed_signal (void ) { } +#endif +static unsigned long exit_to_user_mode_loop (struct pt_regs *regs,unsigned long ti_work) {
@@ -162,6 +174,8 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs,if (ti_work & _TIF_NEED_RESCHED)schedule (); +raise_delayed_signal (); +if (ti_work & _TIF_UPROBE)uprobe_notify_resume (regs);
kernel/signal.c +40 -0
@@ -1304,6 +1304,43 @@ enum sig_handler { HANDLER_EXIT, /* Only visible as the process exit code */ }; +/* +* On some archictectures, PREEMPT_RT has to delay sending a signal from a +* trap since it cannot enable preemption, and the signal code's +* spin_locks turn into mutexes. Instead, it must set TIF_NOTIFY_RESUME +* which will send the signal on exit of the trap. +*/ +#ifdef CONFIG_RT_DELAYED_SIGNALS +static inline bool force_sig_delayed (struct kernel_siginfo *info, +struct task_struct *t) +{ +if (!in_atomic ()) +return false; + +if (WARN_ON_ONCE (t->forced_info.si_signo)) +return true; + +if (is_si_special (info)) { +WARN_ON_ONCE (info !=SEND_SIG_PRIV ); + t->forced_info.si_signo = info->si_signo; + t->forced_info.si_errno =0 ; + t->forced_info.si_code =SI_KERNEL ; + t->forced_info.si_pid =0 ; + t->forced_info.si_uid =0 ; + }else { + t->forced_info = *info; + } +set_tsk_thread_flag (t,TIF_NOTIFY_RESUME ); +return true; +} +#else +static inline bool force_sig_delayed (struct kernel_siginfo *info, +struct task_struct *t) +{ +return false; +} +#endif +/* * Force a signal that the process can't ignore: if necessary * we unblock the signal and change any SIG_IGN to SIG_DFL.
@@ -1324,6 +1361,9 @@ force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t,struct k_sigaction *action;int sig = info->si_signo; +if (force_sig_delayed (info, t)) +return 0 ; +spin_lock_irqsave (&t->sighand->siglock, flags); action = &t->sighand->action[sig-1 ]; ignored = action->sa.sa_handler ==SIG_IGN ;
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 34/35 Revert "ACPI: Pass the same capabilities to the _OSC regardless of the query flag"
In reply to Sasha LevinFrom: "Rafael J. Wysocki" <[email protected]>
[ Upstream commit 2ca8e6285250c07a2e5a22ecbfd59b5a4ef73484 ]
Revert commit 159d8c274fd9 ("ACPI: Pass the same capabilities to the _OSC regardless of the query flag") which caused legitimate usage scenarios (when the platform firmware does not want the OS to control certain platform features controlled by the system bus scope _OSC) to break and was misguided by some misleading language in the _OSC definition in the ACPI specification (in particular, Section 6.2.11.1.3 "Sequence of _OSC Calls" that contradicts other perts of the _OSC definition).
--- drivers/acpi/bus.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/acpi/bus.c +19 -8
@@ -332,21 +332,32 @@ static void acpi_bus_osc_negotiate_platform_control(void)if (ACPI_FAILURE (acpi_run_osc (handle, &context)))return ; -kfree (context.ret.pointer); + capbuf_ret = context.ret.pointer; +if (context.ret.length <=OSC_SUPPORT_DWORD ) { +kfree (context.ret.pointer); +return ; + } -/* Now run _OSC again with query flag clear */ +/* +* Now run _OSC again with query flag clear and with the caps +* supported by both the OS and the platform. +*/ capbuf[OSC_QUERY_DWORD ] =0 ; + capbuf[OSC_SUPPORT_DWORD ] = capbuf_ret[OSC_SUPPORT_DWORD ]; +kfree (context.ret.pointer);if (ACPI_FAILURE (acpi_run_osc (handle, &context)))return ; capbuf_ret = context.ret.pointer; - osc_sb_apei_support_acked = - capbuf_ret[OSC_SUPPORT_DWORD ] &OSC_SB_APEI_SUPPORT ; - osc_pc_lpi_support_confirmed = - capbuf_ret[OSC_SUPPORT_DWORD ] &OSC_SB_PCLPI_SUPPORT ; - osc_sb_native_usb4_support_confirmed = - capbuf_ret[OSC_SUPPORT_DWORD ] &OSC_SB_NATIVE_USB4_SUPPORT ; +if (context.ret.length >OSC_SUPPORT_DWORD ) { + osc_sb_apei_support_acked = + capbuf_ret[OSC_SUPPORT_DWORD ] &OSC_SB_APEI_SUPPORT ; + osc_pc_lpi_support_confirmed = + capbuf_ret[OSC_SUPPORT_DWORD ] &OSC_SB_PCLPI_SUPPORT ; + osc_sb_native_usb4_support_confirmed = + capbuf_ret[OSC_SUPPORT_DWORD ] &OSC_SB_NATIVE_USB4_SUPPORT ; + }kfree (context.ret.pointer); }
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 26/35 lib/raid6/test/Makefile: Use $(pound) instead of \# for Make 4.3
In reply to Sasha LevinFrom: Paul Menzel <[email protected]>
[ Upstream commit 633174a7046ec3b4572bec24ef98e6ee89bce14b ]
Buidling raid6test on Ubuntu 21.10 (ppc64le) with GNU Make 4.3 shows the errors below:
$ cd lib/raid6/test/
$ make
<stdin>:1:1: error: stray ‘\’ in program
<stdin>:1:2: error: stray ‘#’ in program
<stdin>:1:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ \
before ‘<’ token[...]
The errors come from the HAS_ALTIVEC test, which fails, and the POWER optimized versions are not built. That’s also reason nobody noticed on the other architectures.
GNU Make 4.3 does not remove the backslash anymore. From the 4.3 release announcment:
Quoted 11 lines
* WARNING: Backward-incompatibility!
Number signs (#) appearing inside a macro reference or function invocation no longer introduce comments and should not be escaped with backslashes:
thus a call such as:foo := $(shell echo '#') is legal. Previously the number sign needed to be escaped, for example: foo := $(shell echo '\#') Now this latter will resolve to "\#". If you want to write makefiles portable to both versions, assign the number sign to a variable: H := \# foo := $(shell echo '$H')
Quoted 2 lines
This was claimed to be fixed in 3.81, but wasn't, for some reason. To detect this change search for 'nocomment' in the .FEATURES variable.
So, do the same as commit 9564a8cf422d ("Kbuild: fix # escaping in .cmd files for future Make") and commit 929bef467771 ("bpf: Use $(pound) instead of \# in Makefiles") and define and use a $(pound) variable.
Reference for the change in make:
https://git.savannah.gnu.org/cgit/make.git/commit/?id=c6966b323811c37acedff05b57
--- lib/raid6/test/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/raid6/test/Makefile +3 -1
@@ -4,6 +4,8 @@ # from userspace. # +pound := \# + CC = gcc OPTFLAGS = -O2 # Adjust as desired CFLAGS = -I.. -I ../../../include -g $(OPTFLAGS)
@@ -42,7 +44,7 @@ else ifeq ($(HAS_NEON),yes) OBJS += neon.o neon1.o neon2.o neon4.o neon8.o recov_neon.o recov_neon_inner.o CFLAGS += -DCONFIG_KERNEL_MODE_NEON=1 else - HAS_ALTIVEC := $(shell printf '\#include <altivec.h>\nvector int a;\n' |\ + HAS_ALTIVEC := $(shell printf '$(pound)include <altivec.h>\nvector int a;\n' |\ gcc -c -x c - >/dev/null && rm ./-.o && echo yes) ifeq ($(HAS_ALTIVEC),yes) CFLAGS += -I../../../arch/powerpc/include
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 35/35 spi: fsi: Implement a timeout for polling status
In reply to Sasha LevinFrom: Eddie James <[email protected]>
[ Upstream commit 89b35e3f28514087d3f1e28e8f5634fbfd07c554 ]
The data transfer routines must poll the status register to determine when more data can be shifted in or out. If the hardware gets into a bad state, these polling loops may never exit. Prevent this by returning an error if a timeout is exceeded.
--- drivers/spi/spi-fsi.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/spi/spi-fsi.c +10 -0
@@ -25,6 +25,7 @@#define SPI_FSI_BASE 0x70000#define SPI_FSI_INIT_TIMEOUT_MS 1000 +#define SPI_FSI_STATUS_TIMEOUT_MS 100#define SPI_FSI_MAX_RX_SIZE 8#define SPI_FSI_MAX_TX_SIZE 40
@@ -299,6 +300,7 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx, struct spi_transfer *transfer) {int rc =0 ; +unsigned long end;u64 status =0ULL ;if (transfer->tx_buf) {
@@ -315,10 +317,14 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,if (rc)return rc; + end = jiffies +msecs_to_jiffies (SPI_FSI_STATUS_TIMEOUT_MS );do { rc =fsi_spi_status (ctx, &status,"TX" );if (rc)return rc; + +if (time_after (jiffies, end)) +return -ETIMEDOUT ; }while (status &SPI_FSI_STATUS_TDR_FULL ); sent += nb;
@@ -329,10 +335,14 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,u8 *rx = transfer->rx_buf;while (transfer->len > recv) { + end = jiffies +msecs_to_jiffies (SPI_FSI_STATUS_TIMEOUT_MS );do { rc =fsi_spi_status (ctx, &status,"RX" );if (rc)return rc; + +if (time_after (jiffies, end)) +return -ETIMEDOUT ; }while (!(status &SPI_FSI_STATUS_RDR_FULL )); rc =fsi_spi_read_reg (ctx,SPI_FSI_DATA_RX , &in);
Signature · 1 line
2.34.1