5.10.20-rc1 review
Subsystems (11)
Greg Kroah-Hartman
maintainerPATCH 614/663 mei: me: add adler lake point LP DID
In reply to Greg Kroah-HartmanFrom: Alexander Usyskin <[email protected]>
commit 930c922a987a02936000f15ea62988b7a39c27f5 upstream.
Add Adler Lake LP device id.
--- drivers/misc/mei/hw-me-regs.h | 1 + drivers/misc/mei/pci-me.c | 1 + 2 files changed, 2 insertions(+)
drivers/misc/mei/hw-me-regs.h +1 -0
@@ -104,6 +104,7 @@#define MEI_DEV_ID_EBG 0x1BE0/* Emmitsburg WS */ #define MEI_DEV_ID_ADP_S 0x7AE8/* Alder Lake Point S */ +#define MEI_DEV_ID_ADP_LP 0x7A60/* Alder Lake Point LP */ /* * MEI HW Section
drivers/misc/mei/pci-me.c +1 -0
@@ -110,6 +110,7 @@ static const struct pci_device_id mei_me {MEI_PCI_DEVICE(MEI_DEV_ID_EBG, MEI_ME_PCH15_SPS_CFG)}, {MEI_PCI_DEVICE(MEI_DEV_ID_ADP_S, MEI_ME_PCH15_CFG)}, + {MEI_PCI_DEVICE(MEI_DEV_ID_ADP_LP, MEI_ME_PCH15_CFG)},/* required last entry */ {0, }
Greg Kroah-Hartman
maintainerPATCH 615/663 gpio: pcf857x: Fix missing first interrupt
In reply to Greg Kroah-HartmanFrom: Maxim Kiselev <[email protected]>
commit a8002a35935aaefcd6a42ad3289f62bab947f2ca upstream.
If no n_latch value will be provided at driver probe then all pins will be used as an input:
gpio->out = ~n_latch;
In that case initial state for all pins is "one":
gpio->status = gpio->out;
So if pcf857x IRQ happens with change pin value from "zero" to "one" then we miss it, because of "one" from IRQ and "one" from initial state leaves corresponding pin unchanged:
change = (gpio->status ^ status) & gpio->irq_enabled;
The right solution will be to read actual state at driver probe.
--- drivers/gpio/gpio-pcf857x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-pcf857x.c +1 -1
@@ -332,7 +332,7 @@ static int pcf857x_probe(struct i2c_clie* reset state. Otherwise it flags pins to be driven low. */ gpio->out = ~n_latch; - gpio->status = gpio->out; + gpio->status = gpio->read (gpio->client);/* Enable irqchip if we have an interrupt */ if (client->irq) {
Greg Kroah-Hartman
maintainerPATCH 616/663 mfd: gateworks-gsc: Fix interrupt type
In reply to Greg Kroah-HartmanFrom: Tim Harvey <[email protected]>
commit 8d9bf3c3e1451fc8de7b590040a868ade26d6b22 upstream.
The Gateworks System Controller has an active-low interrupt. Fix the interrupt request type.
--- drivers/mfd/gateworks-gsc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/gateworks-gsc.c +1 -1
@@ -234,7 +234,7 @@ static int gsc_probe(struct i2c_client * ret =devm_regmap_add_irq_chip (dev, gsc->regmap, client->irq,IRQF_ONESHOT |IRQF_SHARED | -IRQF_TRIGGER_FALLING ,0 , +IRQF_TRIGGER_LOW ,0 , &gsc_irq_chip, &irq_data);if (ret)return ret;
Greg Kroah-Hartman
maintainerPATCH 617/663 printk: fix deadlock when kernel panic
In reply to Greg Kroah-HartmanFrom: Muchun Song <[email protected]>
commit 8a8109f303e25a27f92c1d8edd67d7cbbc60a4eb upstream.
printk_safe_flush_on_panic() caused the following deadlock on our server:
CPU0: CPU1:
panic rcu_dump_cpu_stacks
kdump_nmi_shootdown_cpus nmi_trigger_cpumask_backtrace
register_nmi_handler(crash_nmi_callback) printk_safe_flush
__printk_safe_flush
raw_spin_lock_irqsave(&read_lock)
// send NMI to other processors
apic_send_IPI_allbutself(NMI_VECTOR)
// NMI interrupt, dead loop
crash_nmi_callback
printk_safe_flush_on_panic
printk_safe_flush
__printk_safe_flush
// deadlock
raw_spin_lock_irqsave(&read_lock)DEADLOCK: read_lock is taken on CPU1 and will never get released.
It happens when panic() stops a CPU by NMI while it has been in the middle of printk_safe_flush().
Handle the lock the same way as logbuf_lock. The printk_safe buffers are flushed only when both locks can be safely taken. It can avoid the deadlock _in this particular case_ at expense of losing contents of printk_safe buffers.
Note: It would actually be safe to re-init the locks when all CPUs were
stopped by NMI. But it would require passing this information from arch-specific code. It is not worth the complexity. Especially because logbuf_lock and printk_safe buffers have been obsoleted by the lockless ring buffer.
--- kernel/printk/printk_safe.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
kernel/printk/printk_safe.c +12 -4
@@ -45,6 +45,8 @@ struct printk_safe_seq_buf { static DEFINE_PER_CPU(struct printk_safe_seq_buf, safe_print_seq); static DEFINE_PER_CPU(int, printk_context); +static DEFINE_RAW_SPINLOCK (safe_read_lock); +#ifdef CONFIG_PRINTK_NMI static DEFINE_PER_CPU(struct printk_safe_seq_buf, nmi_print_seq);#endif
@@ -180,8 +182,6 @@ static void report_message_lost(struct p*/ static void __printk_safe_flush (struct irq_work *work) { -static raw_spinlock_t read_lock = -__RAW_SPIN_LOCK_INITIALIZER (read_lock);struct printk_safe_seq_buf *s = container_of(work, struct printk_safe_seq_buf, work);unsigned long flags;
@@ -195,7 +195,7 @@ static void __printk_safe_flush(struct i* different CPUs. This is especially important when printing * a backtrace. */ -raw_spin_lock_irqsave (&read_lock, flags); +raw_spin_lock_irqsave (&safe_read_lock, flags); i =0 ; more:
@@ -232,7 +232,7 @@ more: out:report_message_lost (s); -raw_spin_unlock_irqrestore (&read_lock, flags); +raw_spin_unlock_irqrestore (&safe_read_lock, flags); }/**
@@ -278,6 +278,14 @@ void printk_safe_flush_on_panic(void)raw_spin_lock_init (&logbuf_lock); } +if (raw_spin_is_locked (&safe_read_lock)) { +if (num_online_cpus () >1 ) +return ; + +debug_locks_off (); +raw_spin_lock_init (&safe_read_lock); + } +printk_safe_flush (); }
Greg Kroah-Hartman
maintainerPATCH 618/663 exfat: fix shift-out-of-bounds in exfat_fill_super()
In reply to Greg Kroah-HartmanFrom: Namjae Jeon <[email protected]>
commit 78c276f5495aa53a8beebb627e5bf6a54f0af34f upstream.
syzbot reported a warning which could cause shift-out-of-bounds issue.
Call Trace: __dump_stack lib/dump_stack.c:79 [inline] dump_stack+0x183/0x22e lib/dump_stack.c:120 ubsan_epilogue lib/ubsan.c:148 [inline] __ubsan_handle_shift_out_of_bounds+0x432/0x4d0 lib/ubsan.c:395 exfat_read_boot_sector fs/exfat/super.c:471 [inline] __exfat_fill_super fs/exfat/super.c:556 [inline] exfat_fill_super+0x2acb/0x2d00 fs/exfat/super.c:624 get_tree_bdev+0x406/0x630 fs/super.c:1291 vfs_get_tree+0x86/0x270 fs/super.c:1496 do_new_mount fs/namespace.c:2881 [inline] path_mount+0x1937/0x2c50 fs/namespace.c:3211 do_mount fs/namespace.c:3224 [inline] __do_sys_mount fs/namespace.c:3432 [inline] __se_sys_mount+0x2f9/0x3b0 fs/namespace.c:3409 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x44/0xa9
exfat specification describe sect_per_clus_bits field of boot sector could be at most 25 - sect_size_bits and at least 0. And sect_size_bits can also affect this calculation, It also needs validation. This patch add validation for sect_per_clus_bits and sect_size_bits field of boot sector.
--- fs/exfat/exfat_raw.h | 4 ++++ fs/exfat/super.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-)
fs/exfat/exfat_raw.h +4 -0
@@ -77,6 +77,10 @@#define EXFAT_FILE_NAME_LEN 15 +#define EXFAT_MIN_SECT_SIZE_BITS 9 +#define EXFAT_MAX_SECT_SIZE_BITS 12 +#define EXFAT_MAX_SECT_PER_CLUS_BITS (x) (25 - (x)->sect_size_bits) +/* EXFAT: Main and Backup Boot Sector (512 bytes) */ struct boot_sector {__u8 jmp_boot[BOOTSEC_JUMP_BOOT_LEN ];
fs/exfat/super.c +26 -5
@@ -381,8 +381,7 @@ static int exfat_calibrate_blocksize(str {struct exfat_sb_info *sbi =EXFAT_SB (sb); -if (!is_power_of_2 (logical_sect) || - logical_sect <512 || logical_sect >4096 ) { +if (!is_power_of_2 (logical_sect)) {exfat_err (sb,"bogus logical sector size %u" , logical_sect);return -EIO ; }
@@ -451,6 +450,25 @@ static int exfat_read_boot_sector(structreturn -EINVAL ; } +/* +* sect_size_bits could be at least 9 and at most 12. +*/ +if (p_boot->sect_size_bits <EXFAT_MIN_SECT_SIZE_BITS || + p_boot->sect_size_bits >EXFAT_MAX_SECT_SIZE_BITS ) { +exfat_err (sb,"bogus sector size bits : %u\n" , + p_boot->sect_size_bits); +return -EINVAL ; + } + +/* +* sect_per_clus_bits could be at least 0 and at most 25 - sect_size_bits. +*/ +if (p_boot->sect_per_clus_bits >EXFAT_MAX_SECT_PER_CLUS_BITS (p_boot)) { +exfat_err (sb,"bogus sectors bits per cluster : %u\n" , + p_boot->sect_per_clus_bits); +return -EINVAL ; + } + sbi->sect_per_clus =1 << p_boot->sect_per_clus_bits; sbi->sect_per_clus_bits = p_boot->sect_per_clus_bits; sbi->cluster_size_bits = p_boot->sect_per_clus_bits +
@@ -477,16 +495,19 @@ static int exfat_read_boot_sector(struct sbi->used_clusters =EXFAT_CLUSTERS_UNTRACKED ;/* check consistencies */ -if (sbi->num_FAT_sectors << p_boot->sect_size_bits < - sbi->num_clusters *4 ) { +if ((u64 )sbi->num_FAT_sectors << p_boot->sect_size_bits < + (u64 )sbi->num_clusters *4 ) {exfat_err (sb,"bogus fat length" );return -EINVAL ; } +if (sbi->data_start_sector < - sbi->FAT1_start_sector + sbi->num_FAT_sectors * p_boot->num_fats) { + (u64 )sbi->FAT1_start_sector + + (u64 )sbi->num_FAT_sectors * p_boot->num_fats) {exfat_err (sb,"bogus data start sector" );return -EINVAL ; } +if (sbi->vol_flags &VOLUME_DIRTY )exfat_warn (sb,"Volume was not properly unmounted. Some data may be corrupt. Please run fsck." );if (sbi->vol_flags &MEDIA_FAILURE )
Greg Kroah-Hartman
maintainerPATCH 619/663 zonefs: Fix file size of zones in full condition
In reply to Greg Kroah-HartmanFrom: Shin'ichiro Kawasaki <[email protected]>
commit 059c01039c0185dbee7ed080f1f2bd22cb1e4dab upstream.
Per ZBC/ZAC/ZNS specifications, write pointers may not have valid values when zones are in full condition. However, when zonefs mounts a zoned block device, zonefs refers write pointers to set file size even when the zones are in full condition. This results in wrong file size. To fix this, refer maximum file size in place of write pointers for zones in full condition.
--- fs/zonefs/super.c | 3 +++ 1 file changed, 3 insertions(+)
fs/zonefs/super.c +3 -0
@@ -250,6 +250,9 @@ static loff_t zonefs_check_zone_conditio } inode->i_mode &= ~0222 ;return i_size_read (inode); +case BLK_ZONE_COND_FULL : +/* The write pointer of full zones is invalid. */ +return zi->i_max_size;default :if (zi->i_ztype ==ZONEFS_ZTYPE_CNV )return zi->i_max_size;
Greg Kroah-Hartman
maintainerPATCH 620/663 kcmp: Support selection of SYS_kcmp without CHECKPOINT_RESTORE
In reply to Greg Kroah-HartmanFrom: Chris Wilson <[email protected]>
commit bfe3911a91047557eb0e620f95a370aee6a248c7 upstream.
Userspace has discovered the functionality offered by SYS_kcmp and has started to depend upon it. In particular, Mesa uses SYS_kcmp for os_same_file_description() in order to identify when two fd (e.g. device or dmabuf) point to the same struct file. Since they depend on it for core functionality, lift SYS_kcmp out of the non-default CONFIG_CHECKPOINT_RESTORE into the selectable syscall category.
Rasmus Villemoes also pointed out that systemd uses SYS_kcmp to deduplicate the per-service file descriptor store.
Note that some distributions such as Ubuntu are already enabling CHECKPOINT_RESTORE in their configs and so, by extension, SYS_kcmp.
--- drivers/gpu/drm/Kconfig | 3 +++ fs/eventpoll.c | 4 ++-- include/linux/eventpoll.h | 2 +- init/Kconfig | 11 +++++++++++ kernel/Makefile | 2 +- tools/testing/selftests/seccomp/seccomp_bpf.c | 2 +- 6 files changed, 19 insertions(+), 5 deletions(-)
drivers/gpu/drm/Kconfig +3 -0
@@ -15,6 +15,9 @@ menuconfig DRM select I2C_ALGOBIT select DMA_SHARED_BUFFER select SYNC_FILE +# gallium uses SYS_kcmp for os_same_file_description() to de-duplicate +# device and dmabuf fd. Let's make sure that is available for our userspace. + select KCMP help Kernel-level support for the Direct Rendering Infrastructure (DRI) introduced in XFree86 4.0. If you say Y here, you need to select
fs/eventpoll.c +2 -2
@@ -1062,7 +1062,7 @@ static struct epitem *ep_find(struct evereturn epir; } -#ifdef CONFIG_CHECKPOINT_RESTORE +#ifdef CONFIG_KCMP static struct epitem *ep_find_tfd (struct eventpoll *ep,int tfd,unsigned long toff) {struct rb_node *rbp;
@@ -1104,7 +1104,7 @@ struct file *get_epoll_tfile_raw_ptr(str return file_raw; } -#endif /* CONFIG_CHECKPOINT_RESTORE */ +#endif /* CONFIG_KCMP */ /** * Adds a new entry to the tail of the list in a lockless way, i.e.
include/linux/eventpoll.h +1 -1
@@ -18,7 +18,7 @@ struct file;#ifdef CONFIG_EPOLL -#ifdef CONFIG_CHECKPOINT_RESTORE +#ifdef CONFIG_KCMP struct file *get_epoll_tfile_raw_ptr (struct file *file,int tfd,unsigned long toff);#endif
init/Kconfig +11 -0
@@ -1194,6 +1194,7 @@ endif # NAMESPACES config CHECKPOINT_RESTORE bool "Checkpoint/restore support" select PROC_CHILDREN + select KCMP default n help Enables additional kernel features in a sake of checkpoint/restore.
@@ -1737,6 +1738,16 @@ config ARCH_HAS_MEMBARRIER_CALLBACKS config ARCH_HAS_MEMBARRIER_SYNC_CORE bool +config KCMP + bool "Enable kcmp() system call" if EXPERT + help + Enable the kernel resource comparison system call. It provides + user-space with the ability to compare two processes to see if they + share a common resource, such as a file descriptor or even virtual + memory space. + + If unsure, say N. + config RSEQ bool "Enable rseq() system call" if EXPERT default y
kernel/Makefile +1 -1
@@ -48,7 +48,7 @@ obj-y += livepatch/ obj-y += dma/ obj-y += entry/ -obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o +obj-$(CONFIG_KCMP) += kcmp.o obj-$(CONFIG_FREEZER) += freezer.o obj-$(CONFIG_PROFILING) += profile.o obj-$(CONFIG_STACKTRACE) += stacktrace.o
tools/testing/selftests/seccomp/seccomp_bpf.c +1 -1
@@ -315,7 +315,7 @@ TEST(kcmp) ret =__filecmp (getpid (),getpid (),1 ,1 );EXPECT_EQ (ret,0 );if (ret !=0 && errno ==ENOSYS ) -SKIP (return,"Kernel does not support kcmp() (missing CONFIG_CHECKPOINT_RESTORE?)" ); +SKIP (return,"Kernel does not support kcmp() (missing CONFIG_KCMP?)" ); }TEST (mode_strict_support)
Greg Kroah-Hartman
maintainerPATCH 621/663 thermal: cpufreq_cooling: freq_qos_update_request() returns < 0 on error
In reply to Greg Kroah-HartmanFrom: Viresh Kumar <[email protected]>
commit a51afb13311cd85b2f638c691b2734622277d8f5 upstream.
freq_qos_update_request() returns 1 if the effective constraint value has changed, 0 if the effective constraint value has not changed, or a negative error code on failures.
The frequency constraints for CPUs can be set by different parts of the kernel. If the maximum frequency constraint set by other parts of the kernel are set at a lower value than the one corresponding to cooling state 0, then we will never be able to cool down the system as freq_qos_update_request() will keep on returning 0 and we will skip updating cpufreq_state and thermal pressure.
Fix that by doing the updates even in the case where freq_qos_update_request() returns 0, as we have effectively set the constraint to a new value even if the consolidated value of the actual constraint is unchanged because of external factors.
--- drivers/thermal/cpufreq_cooling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/cpufreq_cooling.c +1 -1
@@ -441,7 +441,7 @@ static int cpufreq_set_cur_state(struct frequency =get_state_freq (cpufreq_cdev, state); ret =freq_qos_update_request (&cpufreq_cdev->qos_req, frequency); -if (ret >0 ) { +if (ret >=0 ) { cpufreq_cdev->cpufreq_state = state; cpus = cpufreq_cdev->policy->cpus; max_capacity =arch_scale_cpu_capacity (cpumask_first (cpus));
Greg Kroah-Hartman
maintainerPATCH 622/663 cpufreq: qcom-hw: drop devm_xxx() calls from init/exit hooks
In reply to Greg Kroah-HartmanFrom: Shawn Guo <[email protected]>
commit 67fc209b527d023db4d087c68e44e9790aa089ef upstream.
Commit f17b3e44320b ("cpufreq: qcom-hw: Use devm_platform_ioremap_resource() to simplify code") introduces a regression on platforms using the driver, by failing to initialise a policy, when one is created post hotplug.
When all the CPUs of a policy are hoptplugged out, the call to .exit() and later to devm_iounmap() does not release the memory region that was requested during devm_platform_ioremap_resource(). Therefore, a subsequent call to .init() will result in the following error, which will prevent a new policy to be initialised:
[ 3395.915416] CPU4: shutdown [ 3395.938185] psci: CPU4 killed (polled 0 ms) [ 3399.071424] CPU5: shutdown [ 3399.094316] psci: CPU5 killed (polled 0 ms) [ 3402.139358] CPU6: shutdown [ 3402.161705] psci: CPU6 killed (polled 0 ms) [ 3404.742939] CPU7: shutdown [ 3404.765592] psci: CPU7 killed (polled 0 ms) [ 3411.492274] Detected VIPT I-cache on CPU4 [ 3411.492337] GICv3: CPU4: found redistributor 400 region 0:0x0000000017ae0000 [ 3411.492448] CPU4: Booted secondary processor 0x0000000400 [0x516f802d] [ 3411.503654] qcom-cpufreq-hw 17d43000.cpufreq: can't request region for resource [mem 0x17d45800-0x17d46bff]
With that being said, the original code was tricky and skipping memory region request intentionally to hide this issue. The true cause is that those devm_xxx() device managed functions shouldn't be used for cpufreq init/exit hooks, because &pdev->dev is alive across the hooks and will not trigger auto resource free-up. Let's drop the use of device managed functions and manually allocate/free resources, so that the issue can be fixed properly.
--- drivers/cpufreq/qcom-cpufreq-hw.c | 40 ++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-)
drivers/cpufreq/qcom-cpufreq-hw.c +32 -8
@@ -32,6 +32,7 @@ struct qcom_cpufreq_soc_data {struct qcom_cpufreq_data {void __iomem *base; +struct resource *res;const struct qcom_cpufreq_soc_data *soc_data; };
@@ -280,6 +281,7 @@ static int qcom_cpufreq_hw_cpu_init(strustruct of_phandle_args args;struct device_node *cpu_np;struct device *cpu_dev; +struct resource *res;void __iomem *base;struct qcom_cpufreq_data *data;int ret, index;
@@ -303,18 +305,33 @@ static int qcom_cpufreq_hw_cpu_init(stru index = args.args[0 ]; - base =devm_platform_ioremap_resource (pdev, index); -if (IS_ERR (base)) -return PTR_ERR (base); + res =platform_get_resource (pdev,IORESOURCE_MEM , index); +if (!res) { +dev_err (dev,"failed to get mem resource %d\n" , index); +return -ENODEV ; + } + +if (!request_mem_region (res->start,resource_size (res), res->name)) { +dev_err (dev,"failed to request resource %pR\n" , res); +return -EBUSY ; + } - data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); + base =ioremap (res->start,resource_size (res)); +if (IS_ERR (base)) { +dev_err (dev,"failed to map resource %pR\n" , res); + ret =PTR_ERR (base); + goto release_region; + } + + data =kzalloc (sizeof (*data),GFP_KERNEL );if (!data) { ret = -ENOMEM ; - goto error; + goto unmap_base; } data->soc_data =of_device_get_match_data (&pdev->dev); data->base = base; + data->res = res;/* HW should be in enabled state to proceed */ if (!(readl_relaxed (base + data->soc_data->reg_enable) &0x1 )) {
@@ -349,7 +366,11 @@ static int qcom_cpufreq_hw_cpu_init(strureturn 0 ; error: -devm_iounmap (dev, base); +kfree (data); +unmap_base: +iounmap (data->base); +release_region: +release_mem_region (res->start,resource_size (res));return ret; }
@@ -357,12 +378,15 @@ static int qcom_cpufreq_hw_cpu_exit(stru {struct device *cpu_dev =get_cpu_device (policy->cpu);struct qcom_cpufreq_data *data = policy->driver_data; -struct platform_device *pdev =cpufreq_get_driver_data (); +struct resource *res = data->res; +void __iomem *base = data->base;dev_pm_opp_remove_all_dynamic (cpu_dev);dev_pm_opp_of_cpumask_remove_table (policy->related_cpus);kfree (policy->freq_table); -devm_iounmap (&pdev->dev, data->base); +kfree (data); +iounmap (base); +release_mem_region (res->start,resource_size (res));return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 623/663 cpufreq: intel_pstate: Change intel_pstate_get_hwp_max() argument
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
commit a45ee4d4e13b0e35a8ec7ea0bf9267243d57b302 upstream.
All of the callers of intel_pstate_get_hwp_max() access the struct cpudata object that corresponds to the given CPU already and the function itself needs to access that object (in order to update hwp_cap_cached), so modify the code to pass a struct cpudata pointer to it instead of the CPU number.
--- drivers/cpufreq/intel_pstate.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/cpufreq/intel_pstate.c +8 -8
@@ -829,13 +829,13 @@ static struct freq_attr *hwp_cpufreq_att NULL, }; -static void intel_pstate_get_hwp_max (unsigned int cpu,int *phy_max, +static void intel_pstate_get_hwp_max (struct cpudata *cpu,int *phy_max,int *current_max) {u64 cap; -rdmsrl_on_cpu (cpu,MSR_HWP_CAPABILITIES , &cap); -WRITE_ONCE (all_cpu_data[cpu]->hwp_cap_cached, cap); +rdmsrl_on_cpu (cpu->cpu,MSR_HWP_CAPABILITIES , &cap); +WRITE_ONCE (cpu->hwp_cap_cached, cap);if (global.no_turbo || global.turbo_disabled) *current_max =HWP_GUARANTEED_PERF (cap);else
@@ -1223,7 +1223,7 @@ static void update_qos_request(enum freqcontinue ;if (hwp_active) -intel_pstate_get_hwp_max (i, &turbo_max, &max_state); +intel_pstate_get_hwp_max (cpu, &turbo_max, &max_state);else turbo_max = cpu->pstate.turbo_pstate;
@@ -1733,7 +1733,7 @@ static void intel_pstate_get_cpu_pstatesif (hwp_active && !hwp_mode_bdw) {unsigned int phy_max, current_max; -intel_pstate_get_hwp_max (cpu->cpu, &phy_max, ¤t_max); +intel_pstate_get_hwp_max (cpu, &phy_max, ¤t_max); cpu->pstate.turbo_freq = phy_max * cpu->pstate.scaling; cpu->pstate.turbo_pstate = phy_max; }else {
@@ -2217,7 +2217,7 @@ static void intel_pstate_update_perf_lim* rather than pure ratios. */ if (hwp_active) { -intel_pstate_get_hwp_max (cpu->cpu, &turbo_max, &max_state); +intel_pstate_get_hwp_max (cpu, &turbo_max, &max_state); }else { max_state = global.no_turbo || global.turbo_disabled ? cpu->pstate.max_pstate : cpu->pstate.turbo_pstate;
@@ -2332,7 +2332,7 @@ static void intel_pstate_verify_cpu_poliif (hwp_active) {int max_state, turbo_max; -intel_pstate_get_hwp_max (cpu->cpu, &turbo_max, &max_state); +intel_pstate_get_hwp_max (cpu, &turbo_max, &max_state); max_freq = max_state * cpu->pstate.scaling; }else { max_freq =intel_pstate_get_max_freq (cpu);
@@ -2675,7 +2675,7 @@ static int intel_cpufreq_cpu_init(structif (hwp_active) {u64 value; -intel_pstate_get_hwp_max (policy->cpu, &turbo_max, &max_state); +intel_pstate_get_hwp_max (cpu, &turbo_max, &max_state); policy->transition_delay_us =INTEL_CPUFREQ_TRANSITION_DELAY_HWP ;rdmsrl_on_cpu (cpu->cpu,MSR_HWP_REQUEST , &value);WRITE_ONCE (cpu->hwp_req_cached, value);
Greg Kroah-Hartman
maintainerPATCH 624/663 cpufreq: intel_pstate: Get per-CPU max freq via MSR_HWP_CAPABILITIES if available
In reply to Greg Kroah-HartmanFrom: Chen Yu <[email protected]>
commit 6f67e060083a84a4cc364eab6ae40c717165fb0c upstream.
Currently, when turbo is disabled (either by BIOS or by the user), the intel_pstate driver reads the max non-turbo frequency from the package-wide MSR_PLATFORM_INFO(0xce) register.
However, on asymmetric platforms it is possible in theory that small and big core with HWP enabled might have different max non-turbo CPU frequency, because MSR_HWP_CAPABILITIES is per-CPU scope according to Intel Software Developer Manual.
The turbo max freq is already per-CPU in current code, so make similar change to the max non-turbo frequency as well.
--- drivers/cpufreq/intel_pstate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cpufreq/intel_pstate.c +3 -2
@@ -1724,11 +1724,9 @@ static void intel_pstate_max_within_limistatic void intel_pstate_get_cpu_pstates (struct cpudata *cpu) { cpu->pstate.min_pstate = pstate_funcs.get_min (); - cpu->pstate.max_pstate = pstate_funcs.get_max (); cpu->pstate.max_pstate_physical = pstate_funcs.get_max_physical (); cpu->pstate.turbo_pstate = pstate_funcs.get_turbo (); cpu->pstate.scaling = pstate_funcs.get_scaling (); - cpu->pstate.max_freq = cpu->pstate.max_pstate * cpu->pstate.scaling;if (hwp_active && !hwp_mode_bdw) {unsigned int phy_max, current_max;
@@ -1736,9 +1734,12 @@ static void intel_pstate_get_cpu_pstatesintel_pstate_get_hwp_max (cpu, &phy_max, ¤t_max); cpu->pstate.turbo_freq = phy_max * cpu->pstate.scaling; cpu->pstate.turbo_pstate = phy_max; + cpu->pstate.max_pstate =HWP_GUARANTEED_PERF (READ_ONCE (cpu->hwp_cap_cached)); }else { cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * cpu->pstate.scaling; + cpu->pstate.max_pstate = pstate_funcs.get_max (); } + cpu->pstate.max_freq = cpu->pstate.max_pstate * cpu->pstate.scaling;if (pstate_funcs.get_aperf_mperf_shift) cpu->aperf_mperf_shift = pstate_funcs.get_aperf_mperf_shift ();
Greg Kroah-Hartman
maintainerPATCH 625/663 proc: dont allow async path resolution of /proc/thread-self components
In reply to Greg Kroah-HartmanFrom: Jens Axboe <[email protected]>
commit 0d4370cfe36b7f1719123b621a4ec4d9c7a25f89 upstream.
If this is attempted by an io-wq kthread, then return -EOPNOTSUPP as we don't currently support that. Once we can get task_pid_ptr() doing the right thing, then this can go away again.
Use PF_IO_WORKER for this to speciically target the io_uring workers. Modify the /proc/self/ check to use PF_IO_WORKER as well.
--- fs/proc/self.c | 2 +- fs/proc/thread_self.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-)
fs/proc/self.c +1 -1
@@ -20,7 +20,7 @@ static const char *proc_self_get_link(st* Not currently supported. Once we can inherit all of struct pid, * we can allow this. */ -if (current->flags &PF_KTHREAD ) +if (current->flags &PF_IO_WORKER )return ERR_PTR (-EOPNOTSUPP );if (!tgid)
fs/proc/thread_self.c +7 -0
@@ -17,6 +17,13 @@ static const char *proc_thread_self_get_pid_t pid =task_pid_nr_ns (current, ns);char *name; +/* +* Not currently supported. Once we can inherit all of struct pid, +* we can allow this. +*/ +if (current->flags &PF_IO_WORKER ) +return ERR_PTR (-EOPNOTSUPP ); +if (!pid)return ERR_PTR (-ENOENT ); name =kmalloc (10 +6 +10 +1 , dentry ?GFP_KERNEL :GFP_ATOMIC );
Greg Kroah-Hartman
maintainerPATCH 626/663 s390/vtime: fix inline assembly clobber list
In reply to Greg Kroah-HartmanFrom: Heiko Carstens <[email protected]>
commit b29c5093820d333eef22f58cd04ec0d089059c39 upstream.
The stck/stckf instruction used within the inline assembly within do_account_vtime() changes the condition code. This is not reflected with the clobber list, and therefore might result in incorrect code generation.
It seems unlikely that the compiler could generate incorrect code considering the surrounding C code, but it must still be fixed.
--- arch/s390/kernel/vtime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kernel/vtime.c +2 -1
@@ -136,7 +136,8 @@ static int do_account_vtime(struct task_" stck %1" /* Store current tod clock value */ #endif : "=Q" (S390_lowcore.last_update_timer), - "=Q" (S390_lowcore.last_update_clock)); +"=Q" (S390_lowcore.last_update_clock) + : : "cc"); clock = S390_lowcore.last_update_clock - clock; timer -= S390_lowcore.last_update_timer;
Greg Kroah-Hartman
maintainerPATCH 627/663 virtio/s390: implement virtio-ccw revision 2 correctly
In reply to Greg Kroah-HartmanFrom: Cornelia Huck <[email protected]>
commit 182f709c5cff683e6732d04c78e328de0532284f upstream.
CCW_CMD_READ_STATUS was introduced with revision 2 of virtio-ccw, and drivers should only rely on it being implemented when they negotiated at least that revision with the device.
However, virtio_ccw_get_status() issued READ_STATUS for any device operating at least at revision 1. If the device accepts READ_STATUS regardless of the negotiated revision (which some implementations like QEMU do, even though the spec currently does not allow it), everything works as intended. While a device rejecting the command should also be handled gracefully, we will not be able to see any changes the device makes to the status, such as setting NEEDS_RESET or setting the status to zero after a completed reset.
We negotiated the revision to at most 1, as we never bumped the maximum revision; let's do that now and properly send READ_STATUS only if we are operating at least at revision 2.
--- drivers/s390/virtio/virtio_ccw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/s390/virtio/virtio_ccw.c +2 -2
@@ -117,7 +117,7 @@ struct virtio_rev_info { };/* the highest virtio-ccw revision we support */ -#define VIRTIO_CCW_REV_MAX 1 +#define VIRTIO_CCW_REV_MAX 2struct virtio_ccw_vq_info {struct virtqueue *vq;
@@ -952,7 +952,7 @@ static u8 virtio_ccw_get_status(struct vu8 old_status = vcdev->dma_area->status;struct ccw1 *ccw; -if (vcdev->revision <1 ) +if (vcdev->revision <2 )return vcdev->dma_area->status; ccw =ccw_device_dma_zalloc (vcdev->cdev,sizeof (*ccw));
Greg Kroah-Hartman
maintainerPATCH 628/663 um: mm: check more comprehensively for stub changes
In reply to Greg Kroah-HartmanFrom: Johannes Berg <[email protected]>
commit 47da29763ec9a153b9b685bff9db659e4e09e494 upstream.
If userspace tries to change the stub, we need to kill it, because otherwise it can escape the virtual machine. In a few cases the stub checks weren't good, e.g. if userspace just tries to
mmap(0x100000 - 0x1000, 0x3000, ...)
it could succeed to get a new private/anonymous mapping replacing the stubs. Fix this by checking everywhere, and checking for _overlap_, not just direct changes.
--- arch/um/kernel/tlb.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
arch/um/kernel/tlb.c +11 -1
@@ -125,6 +125,9 @@ static int add_mmap(unsigned long virt,struct host_vm_op *last;int fd =-1 , ret =0 ; +if (virt + len >STUB_START && virt <STUB_END ) +return -EINVAL ; +if (hvc->userspace) fd =phys_mapping (phys, &offset);else
@@ -162,7 +165,7 @@ static int add_munmap(unsigned long addrstruct host_vm_op *last;int ret =0 ; -if ((addr >=STUB_START ) && (addr <STUB_END )) +if (addr + len >STUB_START && addr <STUB_END )return -EINVAL ;if (hvc->index !=0 ) {
@@ -192,6 +195,9 @@ static int add_mprotect(unsigned long adstruct host_vm_op *last;int ret =0 ; +if (addr + len >STUB_START && addr <STUB_END ) +return -EINVAL ; +if (hvc->index !=0 ) { last = &hvc->ops[hvc->index -1 ]; if ((last->type == MPROTECT) &&
@@ -472,6 +478,10 @@ void flush_tlb_page(struct vm_area_strucstruct mm_id *mm_id; address &=PAGE_MASK ; + +if (address >=STUB_START && address <STUB_END ) + goto kill; + pgd =pgd_offset (mm, address);if (!pgd_present (*pgd)) goto kill;
Greg Kroah-Hartman
maintainerPATCH 629/663 um: defer killing userspace on page table update failures
In reply to Greg Kroah-HartmanFrom: Johannes Berg <[email protected]>
commit a7d48886cacf8b426e0079bca9639d2657cf2d38 upstream.
In some cases we can get to fix_range_common() with mmap_sem held, and in others we get there without it being held. For example, we get there with it held from sys_mprotect(), and without it held from fork_handler().
Avoid any issues in this and simply defer killing the task until it runs the next time. Do it on the mm so that another task that shares the same mm can't continue running afterwards.
--- arch/um/include/shared/skas/mm_id.h | 1 + arch/um/kernel/tlb.c | 7 +++---- arch/um/os-Linux/skas/process.c | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-)
arch/um/include/shared/skas/mm_id.h +1 -0
@@ -12,6 +12,7 @@ struct mm_id { int pid; } u;unsigned long stack; +int kill; };#endif
arch/um/kernel/tlb.c +3 -4
@@ -352,12 +352,11 @@ void fix_range_common(struct mm_struct */* This is not an else because ret is modified above */ if (ret) { +struct mm_id *mm_idp = ¤t->mm->context.id; +printk (KERN_ERR "fix_range_common: failed, killing current " "process: %d\n" ,task_tgid_vnr (current)); -/* We are under mmap_lock, release it such that current can terminate */ -mmap_write_unlock (current->mm); -force_sig (SIGKILL ); -do_signal (¤t->thread.regs); + mm_idp->kill =1 ; } }
arch/um/os-Linux/skas/process.c +4 -0
@@ -249,6 +249,7 @@ static int userspace_tramp(void *stack) }int userspace_pid[NR_CPUS ]; +int kill_userspace_mm[NR_CPUS ];/** * start_userspace() - prepare a new userspace process
@@ -342,6 +343,8 @@ void userspace(struct uml_pt_regs *regs,interrupt_end ();while (1 ) { +if (kill_userspace_mm[0 ]) +fatal_sigsegv ();/* * This can legitimately fail if the process loads a
@@ -650,4 +653,5 @@ void reboot_skas(void)void __switch_mm (struct mm_id *mm_idp) { userspace_pid[0 ] = mm_idp->u.pid; + kill_userspace_mm[0 ] = mm_idp->kill; }
Greg Kroah-Hartman
maintainerPATCH 630/663 irqchip/loongson-pch-msi: Use bitmap_zalloc() to allocate bitmap
In reply to Greg Kroah-HartmanFrom: Huacai Chen <[email protected]>
commit c1f664d2400e73d5ca0fcd067fa5847d2c789c11 upstream.
Currently we use bitmap_alloc() to allocate msi bitmap which should be initialized with zero. This is obviously wrong but it works because msi can fallback to legacy interrupt mode. So use bitmap_zalloc() instead.
--- drivers/irqchip/irq-loongson-pch-msi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-loongson-pch-msi.c +1 -1
@@ -225,7 +225,7 @@ static int pch_msi_init(struct device_no goto err_priv; } - priv->msi_map =bitmap_alloc (priv->num_irqs,GFP_KERNEL ); + priv->msi_map =bitmap_zalloc (priv->num_irqs,GFP_KERNEL );if (!priv->msi_map) { ret = -ENOMEM ; goto err_priv;
Greg Kroah-Hartman
maintainerPATCH 631/663 f2fs: fix out-of-repair __setattr_copy()
In reply to Greg Kroah-HartmanFrom: Chao Yu <[email protected]>
commit 2562515f0ad7342bde6456602c491b64c63fe950 upstream.
__setattr_copy() was copied from setattr_copy() in fs/attr.c, there is two missing patches doesn't cover this inner function, fix it.
Commit 7fa294c8991c ("userns: Allow chown and setgid preservation") Commit 23adbe12ef7d ("fs,userns: Change inode_capable to capable_wrt_inode_uidgid")
--- fs/f2fs/file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/f2fs/file.c +2 -1
@@ -851,7 +851,8 @@ static void __setattr_copy(struct inodeif (ia_valid &ATTR_MODE ) {umode_t mode = attr->ia_mode; -if (!in_group_p (inode->i_gid) && !capable (CAP_FSETID )) +if (!in_group_p (inode->i_gid) && + !capable_wrt_inode_uidgid (inode,CAP_FSETID )) mode &= ~S_ISGID ;set_acl_inode (inode, mode); }
Greg Kroah-Hartman
maintainerPATCH 632/663 f2fs: enforce the immutable flag on open files
In reply to Greg Kroah-HartmanFrom: Chao Yu <[email protected]>
commit e0fcd01510ad025c9bbce704c5c2579294056141 upstream.
This patch ports commit 02b016ca7f99 ("ext4: enforce the immutable flag on open files") to f2fs.
According to the chattr man page, "a file with the 'i' attribute cannot be modified..." Historically, this was only enforced when the file was opened, per the rest of the description, "... and the file can not be opened in write mode".
There is general agreement that we should standardize all file systems to prevent modifications even for files that were opened at the time the immutable flag is set. Eventually, a change to enforce this at the VFS layer should be landing in mainline.
--- fs/f2fs/file.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fs/f2fs/file.c +17 -0
@@ -59,6 +59,9 @@ static vm_fault_t f2fs_vm_page_mkwrite(sbool need_alloc = true;int err =0 ; +if (unlikely (IS_IMMUTABLE (inode))) +return VM_FAULT_SIGBUS ; +if (unlikely (f2fs_cp_error (sbi))) { err = -EIO ; goto err;
@@ -869,6 +872,14 @@ int f2fs_setattr(struct dentry *dentry,if (unlikely (f2fs_cp_error (F2FS_I_SB (inode))))return -EIO ; +if (unlikely (IS_IMMUTABLE (inode))) +return -EPERM ; + +if (unlikely (IS_APPEND (inode) && + (attr->ia_valid & (ATTR_MODE |ATTR_UID | +ATTR_GID |ATTR_TIMES_SET )))) +return -EPERM ; +if ((attr->ia_valid &ATTR_SIZE ) && !f2fs_is_compress_backend_ready (inode))return -EOPNOTSUPP ;
@@ -4084,6 +4095,11 @@ static ssize_t f2fs_file_write_iter(struinode_lock (inode); } +if (unlikely (IS_IMMUTABLE (inode))) { + ret = -EPERM ; + goto unlock; + } + ret =generic_write_checks (iocb, from);if (ret >0 ) {bool preallocated = false;
@@ -4148,6 +4164,7 @@ write:if (ret >0 )f2fs_update_iostat (F2FS_I_SB (inode),APP_WRITE_IO , ret); } +unlock:inode_unlock (inode); out: trace_f2fs_file_write_iter(inode, iocb->ki_pos,
Greg Kroah-Hartman
maintainerPATCH 633/663 f2fs: flush data when enabling checkpoint back
In reply to Greg Kroah-HartmanFrom: Jaegeuk Kim <[email protected]>
commit b0ff4fe746fd028eef920ddc8c7b0361c1ede6ec upstream.
During checkpoint=disable period, f2fs bypasses all the synchronous IOs such as sync and fsync. So, when enabling it back, we must flush all of them in order to keep the data persistent. Otherwise, suddern power-cut right after enabling checkpoint will cause data loss.
--- fs/f2fs/super.c | 3 +++ 1 file changed, 3 insertions(+)
fs/f2fs/super.c +3 -0
@@ -1764,6 +1764,9 @@ restore_flag:static void f2fs_enable_checkpoint (struct f2fs_sb_info *sbi) { +/* we should flush all the data to keep data consistency */ +sync_inodes_sb (sbi->sb); +down_write (&sbi->gc_lock);f2fs_dirty_to_prefree (sbi);
Greg Kroah-Hartman
maintainerPATCH 634/663 sparc32: fix a user-triggerable oops in clear_user()
In reply to Greg Kroah-HartmanFrom: Al Viro <[email protected]>
commit 7780918b36489f0b2f9a3749d7be00c2ceaec513 upstream.
Back in 2.1.29 the clear_user() guts (__bzero()) had been merged with memset(). Unfortunately, while all exception handlers had been copied, one of the exception table entries got lost. As the result, clear_user() starting at 128*n bytes before the end of page and spanning between 8 and 127 bytes into the next page would oops when the second page is unmapped. It's trivial to reproduce - all it takes is
main()
{
int fd = open("/dev/zero", O_RDONLY);
char *p = mmap(NULL, 16384, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANON, -1, 0);
munmap(p + 8192, 8192);
read(fd, p + 8192 - 128, 192);
}which had been oopsing since March 1997. Says something about the quality of test coverage... ;-/ And while today sparc32 port is nearly dead, back in '97 it had been very much alive; in fact, sparc64 had only been in mainline for 3 months by that point...
--- arch/sparc/lib/memset.S | 1 + 1 file changed, 1 insertion(+)
arch/sparc/lib/memset.S +1 -0
@@ -142,6 +142,7 @@ __bzero: ZERO_LAST_BLOCKS(%o0, 0x48, %g2) ZERO_LAST_BLOCKS(%o0, 0x08, %g2) 13: + EXT(12b, 13b, 21f) be 8f andcc %o1, 4, %g0
Greg Kroah-Hartman
maintainerPATCH 635/663 spi: fsl: invert spisel_boot signal on MPC8309
In reply to Greg Kroah-HartmanFrom: Rasmus Villemoes <[email protected]>
commit 9d2aa6dbf87af89c13cac2d1b4cccad83fb14a7e upstream.
Commit 7a2da5d7960a ("spi: fsl: Fix driver breakage when SPI_CS_HIGH is not set in spi->mode") broke our MPC8309 board by effectively inverting the boolean value passed to fsl_spi_cs_control. The SPISEL_BOOT signal is used as chipselect, but it's not a gpio, so we cannot rely on gpiolib handling the polarity.
Adapt to the new world order by inverting the logic here. This does assume that the slave sitting at the SPISEL_BOOT is active low, but should that ever turn out not to be the case, one can create a stub gpiochip driver controlling a single gpio (or rather, a single "spo", special-purpose output).
--- drivers/spi/spi-fsl-spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-fsl-spi.c +1 -1
@@ -695,7 +695,7 @@ static void fsl_spi_cs_control(struct spif (WARN_ON_ONCE (!pinfo->immr_spi_cs))return ; -iowrite32be (on ?SPI_BOOT_SEL_BIT :0 , pinfo->immr_spi_cs); +iowrite32be (on ?0 :SPI_BOOT_SEL_BIT , pinfo->immr_spi_cs); } }
Greg Kroah-Hartman
maintainerPATCH 636/663 spi: spi-synquacer: fix set_cs handling
In reply to Greg Kroah-HartmanFrom: Masahisa Kojima <[email protected]>
commit 1c9f1750f0305bf605ff22686fc0ac89c06deb28 upstream.
When the slave chip select is deasserted, DMSTOP bit must be set.
--- drivers/spi/spi-synquacer.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/spi/spi-synquacer.c +4 -0
@@ -490,6 +490,10 @@ static void synquacer_spi_set_cs(struct val &= ~(SYNQUACER_HSSPI_DMPSEL_CS_MASK <<SYNQUACER_HSSPI_DMPSEL_CS_SHIFT ); val |= spi->chip_select <<SYNQUACER_HSSPI_DMPSEL_CS_SHIFT ; + +if (!enable) + val |=SYNQUACER_HSSPI_DMSTOP_STOP ; +writel (val, sspi->regs +SYNQUACER_HSSPI_REG_DMSTART ); }
Greg Kroah-Hartman
maintainerPATCH 637/663 gfs2: fix glock confusion in function signal_our_withdraw
In reply to Greg Kroah-HartmanFrom: Bob Peterson <[email protected]>
commit f5f02fde9f52b2d769c1c2ddfd3d9c4a1fe739a7 upstream.
If go_free is defined, function signal_our_withdraw is supposed to synchronize on the GLF_FREEING flag of the inode glock, but it accidentally does that on the live glock. Fix that and disambiguate the glock variables.
--- fs/gfs2/util.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
fs/gfs2/util.c +9 -7
@@ -93,9 +93,10 @@ out_unlock:static void signal_our_withdraw (struct gfs2_sbd *sdp) { -struct gfs2_glock *gl = sdp->sd_live_gh.gh_gl; +struct gfs2_glock *live_gl = sdp->sd_live_gh.gh_gl;struct inode *inode = sdp->sd_jdesc->jd_inode;struct gfs2_inode *ip =GFS2_I (inode); +struct gfs2_glock *i_gl = ip->i_gl;u64 no_formal_ino = ip->i_no_formal_ino;int ret =0 ;int tries;
@@ -141,7 +142,8 @@ static void signal_our_withdraw(struct gatomic_set (&sdp->sd_freeze_state,SFS_FROZEN );thaw_super (sdp->sd_vfs); }else { -wait_on_bit (&gl->gl_flags,GLF_DEMOTE ,TASK_UNINTERRUPTIBLE ); +wait_on_bit (&i_gl->gl_flags,GLF_DEMOTE , +TASK_UNINTERRUPTIBLE ); }/*
@@ -161,15 +163,15 @@ static void signal_our_withdraw(struct g* on other nodes to be successful, otherwise we remain the owner of * the glock as far as dlm is concerned. */ -if (gl->gl_ops->go_free) { -set_bit (GLF_FREEING , &gl->gl_flags); -wait_on_bit (&gl->gl_flags,GLF_FREEING ,TASK_UNINTERRUPTIBLE ); +if (i_gl->gl_ops->go_free) { +set_bit (GLF_FREEING , &i_gl->gl_flags); +wait_on_bit (&i_gl->gl_flags,GLF_FREEING ,TASK_UNINTERRUPTIBLE ); }/* * Dequeue the "live" glock, but keep a reference so it's never freed. */ -gfs2_glock_hold (gl); +gfs2_glock_hold (live_gl);gfs2_glock_dq_wait (&sdp->sd_live_gh);/* * We enqueue the "live" glock in EX so that all other nodes
@@ -208,7 +210,7 @@ static void signal_our_withdraw(struct ggfs2_glock_nq (&sdp->sd_live_gh); } -gfs2_glock_queue_put (gl);/* drop the extra reference we acquired */ +gfs2_glock_queue_put (live_gl);/* drop extra reference we acquired */ clear_bit (SDF_WITHDRAW_RECOVERY , &sdp->sd_flags);/*
Greg Kroah-Hartman
maintainerPATCH 638/663 gfs2: Dont skip dlm unlock if glock has an lvb
In reply to Greg Kroah-HartmanFrom: Bob Peterson <[email protected]>
commit 78178ca844f0eb88f21f31c7fde969384be4c901 upstream.
Patch fb6791d100d1 was designed to allow gfs2 to unmount quicker by skipping the step where it tells dlm to unlock glocks in EX with lvbs. This was done because when gfs2 unmounts a file system, it destroys the dlm lockspace shortly after it destroys the glocks so it doesn't need to unlock them all: the unlock is implied when the lockspace is destroyed by dlm.
However, that patch introduced a use-after-free in dlm: as part of its normal dlm_recoverd process, it can call ls_recovery to recover dead locks. In so doing, it can call recover_rsbs which calls recover_lvb for any mastered rsbs. Func recover_lvb runs through the list of lkbs queued to the given rsb (if the glock is cached but unlocked, it will still be queued to the lkb, but in NL--Unlocked--mode) and if it has an lvb, copies it to the rsb, thus trying to preserve the lkb. However, when gfs2 skips the dlm unlock step, it frees the glock and its lvb, which means dlm's function recover_lvb references the now freed lvb pointer, copying the freed lvb memory to the rsb.
This patch changes the check in gdlm_put_lock so that it calls dlm_unlock for all glocks that contain an lvb pointer.
--- fs/gfs2/lock_dlm.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
fs/gfs2/lock_dlm.c +2 -6
@@ -284,7 +284,6 @@ static void gdlm_put_lock(struct gfs2_gl {struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;struct lm_lockstruct *ls = &sdp->sd_lockstruct; -int lvb_needs_unlock =0 ;int error;if (gl->gl_lksb.sb_lkid ==0 ) {
@@ -297,13 +296,10 @@ static void gdlm_put_lock(struct gfs2_glgfs2_sbstats_inc (gl,GFS2_LKS_DCOUNT );gfs2_update_request_times (gl); -/* don't want to skip dlm_unlock writing the lvb when lock is ex */ - -if (gl->gl_lksb.sb_lvbptr && (gl->gl_state ==LM_ST_EXCLUSIVE )) - lvb_needs_unlock =1 ; +/* don't want to skip dlm_unlock writing the lvb when lock has one */ if (test_bit (SDF_SKIP_DLM_UNLOCK , &sdp->sd_flags) && - !lvb_needs_unlock) { + !gl->gl_lksb.sb_lvbptr) {gfs2_glock_free (gl);return ; }
Greg Kroah-Hartman
maintainerPATCH 639/663 gfs2: Lock imbalance on error path in gfs2_recover_one
In reply to Greg Kroah-HartmanFrom: Andreas Gruenbacher <[email protected]>
commit 834ec3e1ee65029029225a86c12337a6cd385af7 upstream.
In gfs2_recover_one, fix a sd_log_flush_lock imbalance when a recovery pass fails.
--- fs/gfs2/recovery.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/gfs2/recovery.c +3 -1
@@ -514,8 +514,10 @@ void gfs2_recover_func(struct work_struc error =foreach_descriptor (jd, head.lh_tail, head.lh_blkno, pass);lops_after_scan (jd, error, pass); -if (error) +if (error) { +up_read (&sdp->sd_log_flush_lock); goto fail_gunlock_thaw; + } }recover_local_statfs (jd, &head);
Greg Kroah-Hartman
maintainerPATCH 640/663 gfs2: Recursive gfs2_quota_hold in gfs2_iomap_end
In reply to Greg Kroah-HartmanFrom: Andreas Gruenbacher <[email protected]>
commit 7009fa9cd9a5262944b30eb7efb1f0561d074b68 upstream.
When starting an iomap write, gfs2_quota_lock_check -> gfs2_quota_lock -> gfs2_quota_hold is called from gfs2_iomap_begin. At the end of the write, before unlocking the quotas, punch_hole -> gfs2_quota_hold can be called again in gfs2_iomap_end, which is incorrect and leads to a failed assertion. Instead, move the call to gfs2_quota_unlock before the call to punch_hole to fix that.
--- fs/gfs2/bmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/gfs2/bmap.c +3 -3
@@ -1230,6 +1230,9 @@ static int gfs2_iomap_end(struct inode *gfs2_inplace_release (ip); +if (ip->i_qadata && ip->i_qadata->qa_qd_num) +gfs2_quota_unlock (ip); +if (length != written && (iomap->flags &IOMAP_F_NEW )) {/* Deallocate blocks that were just allocated. */ loff_t blockmask =i_blocksize (inode) -1 ;
@@ -1242,9 +1245,6 @@ static int gfs2_iomap_end(struct inode * } } -if (ip->i_qadata && ip->i_qadata->qa_qd_num) -gfs2_quota_unlock (ip); -if (unlikely (!written)) goto out_unlock;
Greg Kroah-Hartman
maintainerPATCH 641/663 dm: fix deadlock when swapping to encrypted device
In reply to Greg Kroah-HartmanFrom: Mikulas Patocka <[email protected]>
commit a666e5c05e7c4aaabb2c5d58117b0946803d03d2 upstream.
The system would deadlock when swapping to a dm-crypt device. The reason is that for each incoming write bio, dm-crypt allocates memory that holds encrypted data. These excessive allocations exhaust all the memory and the result is either deadlock or OOM trigger.
This patch limits the number of in-flight swap bios, so that the memory consumed by dm-crypt is limited. The limit is enforced if the target set the "limit_swap_bios" variable and if the bio has REQ_SWAP set.
Non-swap bios are not affected becuase taking the semaphore would cause performance degradation.
This is similar to request-based drivers - they will also block when the number of requests is over the limit.
--- drivers/md/dm-core.h | 4 ++ drivers/md/dm-crypt.c | 1 drivers/md/dm.c | 60 ++++++++++++++++++++++++++++++++++++++++++ include/linux/device-mapper.h | 5 +++ 4 files changed, 70 insertions(+)
drivers/md/dm-core.h +4 -0
@@ -109,6 +109,10 @@ struct mapped_device {struct block_device *bdev; +int swap_bios; +struct semaphore swap_bios_semaphore; +struct mutex swap_bios_lock; +struct dm_stats stats;/* for blk-mq request-based DM support */
drivers/md/dm-crypt.c +1 -0
@@ -3324,6 +3324,7 @@ static int crypt_ctr(struct dm_target *twake_up_process (cc->write_thread); ti->num_flush_bios =1 ; + ti->limit_swap_bios = true;return 0 ;
drivers/md/dm.c +60 -0
118 lines not on this page · raw message
include/linux/device-mapper.h +5 -0
@@ -325,6 +325,11 @@ struct dm_target {* whether or not its underlying devices have support. */ bool discards_supported:1; + +/* +* Set if we need to limit the number of in-flight bios when swapping. +*/ + bool limit_swap_bios:1; };void *dm_per_bio_data (struct bio *bio,size_t data_size);
Greg Kroah-Hartman
maintainerPATCH 642/663 dm table: fix iterate_devices based device capability checks
In reply to Greg Kroah-HartmanFrom: Jeffle Xu <[email protected]>
commit a4c8dd9c2d0987cf542a2a0c42684c9c6d78a04e upstream.
According to the definition of dm_iterate_devices_fn:
* This function must iterate through each section of device used by the
* target until it encounters a non-zero return code, which it then returns.
* Returns zero if no callout returned non-zero.
For some target type (e.g. dm-stripe), one call of iterate_devices() may iterate multiple underlying devices internally, in which case a non-zero return code returned by iterate_devices_callout_fn will stop the iteration in advance. No iterate_devices_callout_fn should return non-zero unless device iteration should stop.
Rename dm_table_requires_stable_pages() to dm_table_any_dev_attr() and elevate it for reuse to stop iterating (and return non-zero) on the first device that causes iterate_devices_callout_fn to return non-zero. Use dm_table_any_dev_attr() to properly iterate through devices.
Rename device_is_nonrot() to device_is_rotational() and invert logic accordingly to fix improper disposition.
--- drivers/md/dm-table.c | 97 ++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 46 deletions(-)
drivers/md/dm-table.c +51 -46
@@ -1302,6 +1302,46 @@ struct dm_target *dm_table_find_target(sreturn &t->targets[(KEYS_PER_NODE * n) + k]; } +/* +* type->iterate_devices() should be called when the sanity check needs to +* iterate and check all underlying data devices. iterate_devices() will +* iterate all underlying data devices until it encounters a non-zero return +* code, returned by whether the input iterate_devices_callout_fn, or +* iterate_devices() itself internally. +* +* For some target type (e.g. dm-stripe), one call of iterate_devices() may +* iterate multiple underlying devices internally, in which case a non-zero +* return code returned by iterate_devices_callout_fn will stop the iteration +* in advance. +* +* Cases requiring _any_ underlying device supporting some kind of attribute, +* should use the iteration structure like dm_table_any_dev_attr(), or call +* it directly. @func should handle semantics of positive examples, e.g. +* capable of something. +* +* Cases requiring _all_ underlying devices supporting some kind of attribute, +* should use the iteration structure like dm_table_supports_nowait() or +* dm_table_supports_discards(). Or introduce dm_table_all_devs_attr() that +* uses an @anti_func that handle semantics of counter examples, e.g. not +* capable of something. So: return !dm_table_any_dev_attr(t, anti_func); +*/ +static bool dm_table_any_dev_attr (struct dm_table *t, +iterate_devices_callout_fn func) +{ +struct dm_target *ti; +unsigned int i; + +for (i =0 ; i <dm_table_get_num_targets (t); i++) { + ti =dm_table_get_target (t, i); + +if (ti->type->iterate_devices && + ti->type->iterate_devices (ti, func,NULL )) +return true; + } + +return false; +} +static int count_device (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data) {
@@ -1602,12 +1642,12 @@ static int dm_table_supports_dax_write_creturn false; } -static int device_is_nonrot (struct dm_target *ti,struct dm_dev *dev, -sector_t start,sector_t len,void *data) +static int device_is_rotational (struct dm_target *ti,struct dm_dev *dev, +sector_t start,sector_t len,void *data) {struct request_queue *q =bdev_get_queue (dev->bdev); -return q &&blk_queue_nonrot (q); +return q && !blk_queue_nonrot (q); } static int device_is_not_random(struct dm_target *ti, struct dm_dev *dev,
@@ -1618,23 +1658,6 @@ static int device_is_not_random(struct dreturn q && !blk_queue_add_random (q); } -static bool dm_table_all_devices_attribute (struct dm_table *t, -iterate_devices_callout_fn func) -{ -struct dm_target *ti; -unsigned i; - -for (i =0 ; i <dm_table_get_num_targets (t); i++) { - ti =dm_table_get_target (t, i); - -if (!ti->type->iterate_devices || - !ti->type->iterate_devices (ti, func,NULL )) -return false; - } - -return true; -} -static int device_not_write_same_capable (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data) {
@@ -1786,27 +1809,6 @@ static int device_requires_stable_pages(return q &&blk_queue_stable_writes (q); } -/* -* If any underlying device requires stable pages, a table must require -* them as well. Only targets that support iterate_devices are considered: -* don't want error, zero, etc to require stable pages. -*/ -static bool dm_table_requires_stable_pages (struct dm_table *t) -{ -struct dm_target *ti; -unsigned i; - -for (i =0 ; i <dm_table_get_num_targets (t); i++) { - ti =dm_table_get_target (t, i); - -if (ti->type->iterate_devices && - ti->type->iterate_devices (ti, device_requires_stable_pages,NULL )) -return true; - } - -return false; -} -void dm_table_set_restrictions (struct dm_table *t,struct request_queue *q,struct queue_limits *limits) {
@@ -1856,10 +1858,10 @@ void dm_table_set_restrictions(struct dmdax_write_cache (t->md->dax_dev, true);/* Ensure that all underlying devices are non-rotational. */ -if (dm_table_all_devices_attribute (t, device_is_nonrot)) -blk_queue_flag_set (QUEUE_FLAG_NONROT , q); -else +if (dm_table_any_dev_attr (t, device_is_rotational))blk_queue_flag_clear (QUEUE_FLAG_NONROT , q); +else +blk_queue_flag_set (QUEUE_FLAG_NONROT , q);if (!dm_table_supports_write_same (t)) q->limits.max_write_same_sectors =0 ;
@@ -1871,8 +1873,11 @@ void dm_table_set_restrictions(struct dm/* * Some devices don't use blk_integrity but still want stable pages * because they do their own checksumming. +* If any underlying device requires stable pages, a table must require +* them as well. Only targets that support iterate_devices are considered: +* don't want error, zero, etc to require stable pages. */ -if (dm_table_requires_stable_pages (t)) +if (dm_table_any_dev_attr (t, device_requires_stable_pages))blk_queue_flag_set (QUEUE_FLAG_STABLE_WRITES , q);else blk_queue_flag_clear (QUEUE_FLAG_STABLE_WRITES , q);
@@ -1883,7 +1888,7 @@ void dm_table_set_restrictions(struct dm* Clear QUEUE_FLAG_ADD_RANDOM if any underlying device does not * have it set. */ -if (blk_queue_add_random (q) &&dm_table_all_devices_attribute (t, device_is_not_random)) +if (blk_queue_add_random (q) &&dm_table_any_dev_attr (t, device_is_not_random))blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , q);/*
Greg Kroah-Hartman
maintainerPATCH 643/663 dm table: fix DAX iterate_devices based device capability checks
In reply to Greg Kroah-HartmanFrom: Jeffle Xu <[email protected]>
commit 5b0fab508992c2e120971da658ce80027acbc405 upstream.
Fix dm_table_supports_dax() and invert logic of both iterate_devices_callout_fn so that all devices' DAX capabilities are properly checked.
--- drivers/md/dm-table.c | 37 ++++++++++--------------------------- drivers/md/dm.c | 2 +- drivers/md/dm.h | 2 +- 3 files changed, 12 insertions(+), 29 deletions(-)
drivers/md/dm-table.c +10 -27
@@ -827,24 +827,24 @@ void dm_table_set_type(struct dm_table *EXPORT_SYMBOL_GPL (dm_table_set_type);/* validate the dax capability of the target device span */ -int device_supports_dax (struct dm_target *ti,struct dm_dev *dev, +int device_not_dax_capable (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data) {int blocksize = *(int *) data, id;bool rc; id =dax_read_lock (); - rc =dax_supported (dev->dax_dev, dev->bdev, blocksize, start, len); + rc = !dax_supported (dev->dax_dev, dev->bdev, blocksize, start, len);dax_read_unlock (id);return rc; }/* Check devices support synchronous DAX */ -static int device_dax_synchronous (struct dm_target *ti,struct dm_dev *dev, -sector_t start,sector_t len,void *data) +static int device_not_dax_synchronous_capable (struct dm_target *ti,struct dm_dev *dev, +sector_t start,sector_t len,void *data) { -return dev->dax_dev &&dax_synchronous (dev->dax_dev); +return !dev->dax_dev || !dax_synchronous (dev->dax_dev); } bool dm_table_supports_dax(struct dm_table *t,
@@ -861,7 +861,7 @@ bool dm_table_supports_dax(struct dm_tabreturn false;if (!ti->type->iterate_devices || - !ti->type->iterate_devices (ti, iterate_fn, blocksize)) + ti->type->iterate_devices (ti, iterate_fn, blocksize))return false; }
@@ -932,7 +932,7 @@ static int dm_table_determine_type(struc verify_bio_based:/* We must use this table as bio-based */ t->type =DM_TYPE_BIO_BASED ; -if (dm_table_supports_dax (t, device_supports_dax, &page_size) || +if (dm_table_supports_dax (t, device_not_dax_capable, &page_size) || (list_empty (devices) && live_md_type ==DM_TYPE_DAX_BIO_BASED )) { t->type =DM_TYPE_DAX_BIO_BASED ; }
@@ -1625,23 +1625,6 @@ static int device_dax_write_cache_enablereturn false; } -static int dm_table_supports_dax_write_cache (struct dm_table *t) -{ -struct dm_target *ti; -unsigned i; - -for (i =0 ; i <dm_table_get_num_targets (t); i++) { - ti =dm_table_get_target (t, i); - -if (ti->type->iterate_devices && - ti->type->iterate_devices (ti, - device_dax_write_cache_enabled,NULL )) -return true; - } - -return false; -} -static int device_is_rotational (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data) {
@@ -1846,15 +1829,15 @@ void dm_table_set_restrictions(struct dm }blk_queue_write_cache (q, wc, fua); -if (dm_table_supports_dax (t, device_supports_dax, &page_size)) { +if (dm_table_supports_dax (t, device_not_dax_capable, &page_size)) {blk_queue_flag_set (QUEUE_FLAG_DAX , q); -if (dm_table_supports_dax (t, device_dax_synchronous,NULL )) +if (dm_table_supports_dax (t, device_not_dax_synchronous_capable,NULL ))set_dax_synchronous (t->md->dax_dev); }else blk_queue_flag_clear (QUEUE_FLAG_DAX , q); -if (dm_table_supports_dax_write_cache (t)) +if (dm_table_any_dev_attr (t, device_dax_write_cache_enabled))dax_write_cache (t->md->dax_dev, true);/* Ensure that all underlying devices are non-rotational. */
drivers/md/dm.c +1 -1
@@ -1145,7 +1145,7 @@ static bool dm_dax_supported(struct dax_if (!map) goto out; - ret =dm_table_supports_dax (map, device_supports_dax, &blocksize); + ret =dm_table_supports_dax (map, device_not_dax_capable, &blocksize); out:dm_put_live_table (md, srcu_idx);
drivers/md/dm.h +1 -1
@@ -73,7 +73,7 @@ void dm_table_free_md_mempools(struct dmstruct dm_md_mempools *dm_table_get_md_mempools (struct dm_table *t);bool dm_table_supports_dax (struct dm_table *t,iterate_devices_callout_fn fn,int *blocksize); -int device_supports_dax (struct dm_target *ti,struct dm_dev *dev, +int device_not_dax_capable (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data);void dm_lock_md_type (struct mapped_device *md);
Greg Kroah-Hartman
maintainerPATCH 644/663 dm table: fix zoned iterate_devices based device capability checks
In reply to Greg Kroah-HartmanFrom: Jeffle Xu <[email protected]>
commit 24f6b6036c9eec21191646930ad42808e6180510 upstream.
Fix dm_table_supports_zoned_model() and invert logic of both iterate_devices_callout_fn so that all devices' zoned capabilities are properly checked.
Add one more parameter to dm_table_any_dev_attr(), which is actually used as the @data parameter of iterate_devices_callout_fn, so that dm_table_matches_zone_sectors() can be replaced by dm_table_any_dev_attr().
--- drivers/md/dm-table.c | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-)
drivers/md/dm-table.c +16 -32
@@ -1323,10 +1323,10 @@ struct dm_target *dm_table_find_target(s* should use the iteration structure like dm_table_supports_nowait() or * dm_table_supports_discards(). Or introduce dm_table_all_devs_attr() that * uses an @anti_func that handle semantics of counter examples, e.g. not -* capable of something. So: return !dm_table_any_dev_attr(t, anti_func); +* capable of something. So: return !dm_table_any_dev_attr(t, anti_func, data); */ static bool dm_table_any_dev_attr (struct dm_table *t, -iterate_devices_callout_fn func) +iterate_devices_callout_fn func,void *data) {struct dm_target *ti;unsigned int i;
@@ -1335,7 +1335,7 @@ static bool dm_table_any_dev_attr(struct ti =dm_table_get_target (t, i);if (ti->type->iterate_devices && - ti->type->iterate_devices (ti, func,NULL )) + ti->type->iterate_devices (ti, func, data))return true; }
@@ -1378,13 +1378,13 @@ bool dm_table_has_no_data_devices(structreturn true; } -static int device_is_zoned_model (struct dm_target *ti,struct dm_dev *dev, -sector_t start,sector_t len,void *data) +static int device_not_zoned_model (struct dm_target *ti,struct dm_dev *dev, +sector_t start,sector_t len,void *data) {struct request_queue *q =bdev_get_queue (dev->bdev);enum blk_zoned_model *zoned_model = data; -return q &&blk_queue_zoned_model (q) == *zoned_model; +return !q ||blk_queue_zoned_model (q) != *zoned_model; } static bool dm_table_supports_zoned_model(struct dm_table *t,
@@ -1401,37 +1401,20 @@ static bool dm_table_supports_zoned_modereturn false;if (!ti->type->iterate_devices || - !ti->type->iterate_devices (ti, device_is_zoned_model, &zoned_model)) + ti->type->iterate_devices (ti, device_not_zoned_model, &zoned_model))return false; }return true; } -static int device_matches_zone_sectors (struct dm_target *ti,struct dm_dev *dev, -sector_t start,sector_t len,void *data) +static int device_not_matches_zone_sectors (struct dm_target *ti,struct dm_dev *dev, +sector_t start,sector_t len,void *data) {struct request_queue *q =bdev_get_queue (dev->bdev);unsigned int *zone_sectors = data; -return q &&blk_queue_zone_sectors (q) == *zone_sectors; -} - -static bool dm_table_matches_zone_sectors (struct dm_table *t, -unsigned int zone_sectors) -{ -struct dm_target *ti; -unsigned i; - -for (i =0 ; i <dm_table_get_num_targets (t); i++) { - ti =dm_table_get_target (t, i); - -if (!ti->type->iterate_devices || - !ti->type->iterate_devices (ti, device_matches_zone_sectors, &zone_sectors)) -return false; - } - -return true; +return !q ||blk_queue_zone_sectors (q) != *zone_sectors; } static int validate_hardware_zoned_model(struct dm_table *table,
@@ -1451,7 +1434,7 @@ static int validate_hardware_zoned_modelif (!zone_sectors || !is_power_of_2 (zone_sectors))return -EINVAL ; -if (!dm_table_matches_zone_sectors (table, zone_sectors)) { +if (dm_table_any_dev_attr (table, device_not_matches_zone_sectors, &zone_sectors)) {DMERR ("%s: zone sectors is not consistent across all devices" ,dm_device_name (table->md));return -EINVAL ;
@@ -1837,11 +1820,11 @@ void dm_table_set_restrictions(struct dmelse blk_queue_flag_clear (QUEUE_FLAG_DAX , q); -if (dm_table_any_dev_attr (t, device_dax_write_cache_enabled)) +if (dm_table_any_dev_attr (t, device_dax_write_cache_enabled,NULL ))dax_write_cache (t->md->dax_dev, true);/* Ensure that all underlying devices are non-rotational. */ -if (dm_table_any_dev_attr (t, device_is_rotational)) +if (dm_table_any_dev_attr (t, device_is_rotational,NULL ))blk_queue_flag_clear (QUEUE_FLAG_NONROT , q);else blk_queue_flag_set (QUEUE_FLAG_NONROT , q);
@@ -1860,7 +1843,7 @@ void dm_table_set_restrictions(struct dm* them as well. Only targets that support iterate_devices are considered: * don't want error, zero, etc to require stable pages. */ -if (dm_table_any_dev_attr (t, device_requires_stable_pages)) +if (dm_table_any_dev_attr (t, device_requires_stable_pages,NULL ))blk_queue_flag_set (QUEUE_FLAG_STABLE_WRITES , q);else blk_queue_flag_clear (QUEUE_FLAG_STABLE_WRITES , q);
@@ -1871,7 +1854,8 @@ void dm_table_set_restrictions(struct dm* Clear QUEUE_FLAG_ADD_RANDOM if any underlying device does not * have it set. */ -if (blk_queue_add_random (q) &&dm_table_any_dev_attr (t, device_is_not_random)) +if (blk_queue_add_random (q) && +dm_table_any_dev_attr (t, device_is_not_random,NULL ))blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , q);/*
Greg Kroah-Hartman
maintainerPATCH 645/663 dm writecache: fix performance degradation in ssd mode
In reply to Greg Kroah-HartmanFrom: Mikulas Patocka <[email protected]>
commit cb728484a7710c202f02b96aa0962ce9b07aa5c2 upstream.
Fix a thinko in ssd_commit_superblock. region.count is in sectors, not bytes. This bug doesn't corrupt data, but it causes performance degradation.
--- drivers/md/dm-writecache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-writecache.c +1 -1
@@ -523,7 +523,7 @@ static void ssd_commit_superblock(struct region.bdev = wc->ssd_dev->bdev; region.sector =0 ; - region.count =PAGE_SIZE ; + region.count =PAGE_SIZE >>SECTOR_SHIFT ;if (unlikely (region.sector + region.count > wc->metadata_sectors)) region.count = wc->metadata_sectors - region.sector;
Greg Kroah-Hartman
maintainerPATCH 646/663 dm writecache: return the exact table values that were set
In reply to Greg Kroah-HartmanFrom: Mikulas Patocka <[email protected]>
commit 054bee16163df023e2589db09fd27d81f7ad9e72 upstream.
LVM doesn't like it when the target returns different values from what was set in the constructor. Fix dm-writecache so that the returned table values are exactly the same as requested values.
--- drivers/md/dm-writecache.c | 54 +++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 24 deletions(-)
drivers/md/dm-writecache.c +30 -24
@@ -159,14 +159,22 @@ struct dm_writecache { bool overwrote_committed:1; bool memory_vmapped:1; + bool start_sector_set:1; bool high_wm_percent_set:1; bool low_wm_percent_set:1; bool max_writeback_jobs_set:1; bool autocommit_blocks_set:1; bool autocommit_time_set:1; + bool max_age_set:1; bool writeback_fua_set:1; bool flush_on_suspend:1; bool cleaner:1; + bool cleaner_set:1; + +unsigned high_wm_percent_value; +unsigned low_wm_percent_value; +unsigned autocommit_time_value; +unsigned max_age_value;unsigned writeback_all;struct workqueue_struct *writeback_wq;
@@ -2205,6 +2213,7 @@ static int writecache_ctr(struct dm_targif (sscanf (string,"%llu%c" , &start_sector, &dummy) !=1 ) goto invalid_optional; wc->start_sector = start_sector; + wc->start_sector_set = true;if (wc->start_sector != start_sector || wc->start_sector >= wc->memory_map_size >>SECTOR_SHIFT ) goto invalid_optional;
@@ -2214,6 +2223,7 @@ static int writecache_ctr(struct dm_targ goto invalid_optional;if (high_wm_percent <0 || high_wm_percent >100 ) goto invalid_optional; + wc->high_wm_percent_value = high_wm_percent; wc->high_wm_percent_set = true; }else if (!strcasecmp (string,"low_watermark" ) && opt_params >=1 ) { string =dm_shift_arg (&as), opt_params--;
@@ -2221,6 +2231,7 @@ static int writecache_ctr(struct dm_targ goto invalid_optional;if (low_wm_percent <0 || low_wm_percent >100 ) goto invalid_optional; + wc->low_wm_percent_value = low_wm_percent; wc->low_wm_percent_set = true; }else if (!strcasecmp (string,"writeback_jobs" ) && opt_params >=1 ) { string =dm_shift_arg (&as), opt_params--;
@@ -2240,6 +2251,7 @@ static int writecache_ctr(struct dm_targif (autocommit_msecs >3600000 ) goto invalid_optional; wc->autocommit_jiffies =msecs_to_jiffies (autocommit_msecs); + wc->autocommit_time_value = autocommit_msecs; wc->autocommit_time_set = true; }else if (!strcasecmp (string,"max_age" ) && opt_params >=1 ) {unsigned max_age_msecs;
@@ -2249,7 +2261,10 @@ static int writecache_ctr(struct dm_targif (max_age_msecs >86400000 ) goto invalid_optional; wc->max_age =msecs_to_jiffies (max_age_msecs); + wc->max_age_set = true; + wc->max_age_value = max_age_msecs; }else if (!strcasecmp (string,"cleaner" )) { + wc->cleaner_set = true; wc->cleaner = true; }else if (!strcasecmp (string,"fua" )) {if (WC_MODE_PMEM (wc)) {
@@ -2455,7 +2470,6 @@ static void writecache_status(struct dm_struct dm_writecache *wc = ti->private;unsigned extra_args;unsigned sz =0 ; -uint64_t x;switch (type) {case STATUSTYPE_INFO :
@@ -2467,11 +2481,11 @@ static void writecache_status(struct dm_DMEMIT ("%c %s %s %u " ,WC_MODE_PMEM (wc) ?'p' :'s' , wc->dev->name, wc->ssd_dev->name, wc->block_size); extra_args =0 ; -if (wc->start_sector) +if (wc->start_sector_set) extra_args +=2 ; -if (wc->high_wm_percent_set && !wc->cleaner) +if (wc->high_wm_percent_set) extra_args +=2 ; -if (wc->low_wm_percent_set && !wc->cleaner) +if (wc->low_wm_percent_set) extra_args +=2 ;if (wc->max_writeback_jobs_set) extra_args +=2 ;
@@ -2479,37 +2493,29 @@ static void writecache_status(struct dm_ extra_args +=2 ;if (wc->autocommit_time_set) extra_args +=2 ; -if (wc->max_age !=MAX_AGE_UNSPECIFIED ) +if (wc->max_age_set) extra_args +=2 ; -if (wc->cleaner) +if (wc->cleaner_set) extra_args++;if (wc->writeback_fua_set) extra_args++;DMEMIT ("%u" , extra_args); -if (wc->start_sector) +if (wc->start_sector_set)DMEMIT (" start_sector %llu" , (unsigned long long )wc->start_sector); -if (wc->high_wm_percent_set && !wc->cleaner) { - x = (uint64_t )wc->freelist_high_watermark *100 ; - x += wc->n_blocks /2 ; -do_div (x, (size_t )wc->n_blocks); -DMEMIT (" high_watermark %u" ,100 - (unsigned )x); - } -if (wc->low_wm_percent_set && !wc->cleaner) { - x = (uint64_t )wc->freelist_low_watermark *100 ; - x += wc->n_blocks /2 ; -do_div (x, (size_t )wc->n_blocks); -DMEMIT (" low_watermark %u" ,100 - (unsigned )x); - } +if (wc->high_wm_percent_set) +DMEMIT (" high_watermark %u" , wc->high_wm_percent_value); +if (wc->low_wm_percent_set) +DMEMIT (" low_watermark %u" , wc->low_wm_percent_value);if (wc->max_writeback_jobs_set)DMEMIT (" writeback_jobs %u" , wc->max_writeback_jobs);if (wc->autocommit_blocks_set)DMEMIT (" autocommit_blocks %u" , wc->autocommit_blocks);if (wc->autocommit_time_set) -DMEMIT (" autocommit_time %u" ,jiffies_to_msecs (wc->autocommit_jiffies)); -if (wc->max_age !=MAX_AGE_UNSPECIFIED ) -DMEMIT (" max_age %u" ,jiffies_to_msecs (wc->max_age)); -if (wc->cleaner) +DMEMIT (" autocommit_time %u" , wc->autocommit_time_value); +if (wc->max_age_set) +DMEMIT (" max_age %u" , wc->max_age_value); +if (wc->cleaner_set)DMEMIT (" cleaner" );if (wc->writeback_fua_set)DMEMIT (" %sfua" , wc->writeback_fua ?"" :"no" );
@@ -2519,7 +2525,7 @@ static void writecache_status(struct dm_static struct target_type writecache_target = { .name ="writecache" , - .version = {1 ,3 ,0 }, + .version = {1 ,4 ,0 }, .module =THIS_MODULE , .ctr = writecache_ctr, .dtr = writecache_dtr,
Greg Kroah-Hartman
maintainerPATCH 647/663 dm writecache: fix writing beyond end of underlying device when shrinking
In reply to Greg Kroah-HartmanFrom: Mikulas Patocka <[email protected]>
commit 4134455f2aafdfeab50cabb4cccb35e916034b93 upstream.
Do not attempt to write any data beyond the end of the underlying data device while shrinking it.
The DM writecache device must be suspended when the underlying data device is shrunk.
--- drivers/md/dm-writecache.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/md/dm-writecache.c +18 -0
@@ -148,6 +148,7 @@ struct dm_writecache {size_t metadata_sectors;size_t n_blocks;uint64_t seq_count; +sector_t data_device_sectors;void *block_start;struct wc_entry *entries;unsigned block_size;
@@ -977,6 +978,8 @@ static void writecache_resume(struct dm_wc_lock (wc); + wc->data_device_sectors =i_size_read (wc->dev->bdev->bd_inode) >>SECTOR_SHIFT ; +if (WC_MODE_PMEM (wc)) {persistent_memory_invalidate_cache (wc->memory_map, wc->memory_map_size); }else {
@@ -1646,6 +1649,10 @@ static bool wc_add_block(struct writebacvoid *address =memory_data (wc, e);persistent_memory_flush_cache (address, block_size); + +if (unlikely (bio_end_sector (&wb->bio) >= wc->data_device_sectors)) +return true; +return bio_add_page (&wb->bio,persistent_memory_page (address), block_size,persistent_memory_page_offset (address)) !=0 ; }
@@ -1717,6 +1724,9 @@ static void __writecache_writeback_pmem(if (writecache_has_error (wc)) { bio->bi_status =BLK_STS_IOERR ;bio_endio (bio); + }else if (unlikely (!bio_sectors (bio))) { + bio->bi_status =BLK_STS_OK ; +bio_endio (bio); }else {submit_bio (bio); }
@@ -1760,6 +1770,14 @@ static void __writecache_writeback_ssd(s e = f; } +if (unlikely (to.sector + to.count > wc->data_device_sectors)) { +if (to.sector >= wc->data_device_sectors) { +writecache_copy_endio (0 ,0 , c); +continue ; + } + from.count = to.count = wc->data_device_sectors - to.sector; + } +dm_kcopyd_copy (wc->dm_kcopyd, &from,1 , &to,0 , writecache_copy_endio, c);__writeback_throttle (wc, wbl);
Greg Kroah-Hartman
maintainerPATCH 648/663 dm era: Recover committed writeset after crash
In reply to Greg Kroah-HartmanFrom: Nikos Tsironis <[email protected]>
commit de89afc1e40fdfa5f8b666e5d07c43d21a1d3be0 upstream.
Following a system crash, dm-era fails to recover the committed writeset for the current era, leading to lost writes. That is, we lose the information about what blocks were written during the affected era.
dm-era assumes that the writeset of the current era is archived when the device is suspended. So, when resuming the device, it just moves on to the next era, ignoring the committed writeset.
This assumption holds when the device is properly shut down. But, when the system crashes, the code that suspends the target never runs, so the writeset for the current era is not archived.
There are three issues that cause the committed writeset to get lost:
1. dm-era doesn't load the committed writeset when opening the metadata
2. The code that resizes the metadata wipes the information about the committed writeset (assuming it was loaded at step 1)
3. era_preresume() starts a new era, without taking into account that the current era might not have been archived, due to a system crash.
To fix this:
1. Load the committed writeset when opening the metadata
2. Fix the code that resizes the metadata to make sure it doesn't wipe the loaded writeset
3. Fix era_preresume() to check for a loaded writeset and archive it, before starting a new era.
--- drivers/md/dm-era-target.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/md/dm-era-target.c +9 -8
@@ -71,8 +71,6 @@ static size_t bitset_size(unsigned nr_bi*/ static int writeset_alloc (struct writeset *ws,dm_block_t nr_blocks) { - ws->md.nr_bits = nr_blocks; - ws->md.root =INVALID_WRITESET_ROOT ; ws->bits =vzalloc (bitset_size (nr_blocks));if (!ws->bits) {DMERR ("%s: couldn't allocate in memory bitset" , __func__);
@@ -85,12 +83,14 @@ static int writeset_alloc(struct writese/* * Wipes the in-core bitset, and creates a new on disk bitset. */ -static int writeset_init (struct dm_disk_bitset *info,struct writeset *ws) +static int writeset_init (struct dm_disk_bitset *info,struct writeset *ws, +dm_block_t nr_blocks) {int r; -memset (ws->bits,0 ,bitset_size (ws->md.nr_bits)); +memset (ws->bits,0 ,bitset_size (nr_blocks)); + ws->md.nr_bits = nr_blocks; r =setup_on_disk_bitset (info, ws->md.nr_bits, &ws->md.root);if (r) {DMERR ("%s: setup_on_disk_bitset failed" , __func__);
@@ -579,6 +579,7 @@ static int open_metadata(struct era_meta md->nr_blocks =le32_to_cpu (disk->nr_blocks); md->current_era =le32_to_cpu (disk->current_era); +ws_unpack (&disk->current_writeset, &md->current_writeset->md); md->writeset_tree_root =le64_to_cpu (disk->writeset_tree_root); md->era_array_root =le64_to_cpu (disk->era_array_root); md->metadata_snap =le64_to_cpu (disk->metadata_snap);
@@ -870,7 +871,6 @@ static int metadata_era_archive(struct e }ws_pack (&md->current_writeset->md, &value); - md->current_writeset->md.root =INVALID_WRITESET_ROOT ; keys[0 ] = md->current_era;__dm_bless_for_disk (&value);
@@ -882,6 +882,7 @@ static int metadata_era_archive(struct ereturn r; } + md->current_writeset->md.root =INVALID_WRITESET_ROOT ; md->archived_writesets = true;return 0 ;
@@ -898,7 +899,7 @@ static int metadata_new_era(struct era_mint r;struct writeset *new_writeset =next_writeset (md); - r =writeset_init (&md->bitset_info, new_writeset); + r =writeset_init (&md->bitset_info, new_writeset, md->nr_blocks);if (r) {DMERR ("%s: writeset_init failed" , __func__);return r;
@@ -951,7 +952,7 @@ static int metadata_commit(struct era_meint r;struct dm_block *sblock; -if (md->current_writeset->md.root !=SUPERBLOCK_LOCATION ) { +if (md->current_writeset->md.root !=INVALID_WRITESET_ROOT ) { r =dm_bitset_flush (&md->bitset_info, md->current_writeset->md.root, &md->current_writeset->md.root);if (r) {
@@ -1565,7 +1566,7 @@ static int era_preresume(struct dm_targestart_worker (era); - r =in_worker0 (era, metadata_new_era); + r =in_worker0 (era, metadata_era_rollover);if (r) {DMERR ("%s: metadata_era_rollover failed" , __func__);return r;
Greg Kroah-Hartman
maintainerPATCH 649/663 dm era: Update in-core bitset after committing the metadata
In reply to Greg Kroah-HartmanFrom: Nikos Tsironis <[email protected]>
commit 2099b145d77c1d53f5711f029c37cc537897cee6 upstream.
In case of a system crash, dm-era might fail to mark blocks as written in its metadata, although the corresponding writes to these blocks were passed down to the origin device and completed successfully.
Consider the following sequence of events:
1. We write to a block that has not been yet written in the current era
2. era_map() checks the in-core bitmap for the current era and sees that the block is not marked as written.
3. The write is deferred for submission after the metadata have been updated and committed.
4. The worker thread processes the deferred write (process_deferred_bios()) and marks the block as written in the in-core bitmap, **before** committing the metadata.
5. The worker thread starts committing the metadata.
6. We do more writes that map to the same block as the write of step (1)
7. era_map() checks the in-core bitmap and sees that the block is marked as written, **although the metadata have not been committed yet**.
8. These writes are passed down to the origin device immediately and the device reports them as completed.
9. The system crashes, e.g., power failure, before the commit from step
(5) finishes.
When the system recovers and we query the dm-era target for the list of written blocks it doesn't report the aforementioned block as written, although the writes of step (6) completed successfully.
The issue is that era_map() decides whether to defer or not a write based on non committed information. The root cause of the bug is that we update the in-core bitmap, **before** committing the metadata.
Fix this by updating the in-core bitmap **after** successfully committing the metadata.
--- drivers/md/dm-era-target.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/md/dm-era-target.c +19 -6
@@ -134,7 +134,7 @@ static int writeset_test_and_set(struct {int r; -if (!test_and_set_bit (block, ws->bits)) { +if (!test_bit (block, ws->bits)) { r =dm_bitset_set_bit (info, ws->md.root, block, &ws->md.root);if (r) {/* FIXME: fail mode */
@@ -1226,8 +1226,10 @@ static void process_deferred_bios(structint r;struct bio_list deferred_bios, marked_bios;struct bio *bio; +struct blk_plug plug;bool commit_needed = false;bool failed = false; +struct writeset *ws = era->md->current_writeset;bio_list_init (&deferred_bios);bio_list_init (&marked_bios);
@@ -1237,9 +1239,11 @@ static void process_deferred_bios(structbio_list_init (&era->deferred_bios);spin_unlock (&era->deferred_lock); +if (bio_list_empty (&deferred_bios)) +return ; +while ((bio =bio_list_pop (&deferred_bios))) { - r =writeset_test_and_set (&era->md->bitset_info, - era->md->current_writeset, + r =writeset_test_and_set (&era->md->bitset_info, ws,get_block (era, bio));if (r <0 ) {/*
@@ -1247,7 +1251,6 @@ static void process_deferred_bios(struct* FIXME: finish. */ failed = true; - }else if (r ==0 ) commit_needed = true;
@@ -1263,9 +1266,19 @@ static void process_deferred_bios(structif (failed)while ((bio =bio_list_pop (&marked_bios)))bio_io_error (bio); -else -while ((bio =bio_list_pop (&marked_bios))) +else { +blk_start_plug (&plug); +while ((bio =bio_list_pop (&marked_bios))) { +/* +* Only update the in-core writeset if the on-disk one +* was updated too. +*/ +if (commit_needed) +set_bit (get_block (era, bio), ws->bits);submit_bio_noacct (bio); + } +blk_finish_plug (&plug); + } }static void process_rpc_calls (struct era *era)
Greg Kroah-Hartman
maintainerPATCH 650/663 dm era: Verify the data block size hasnt changed
In reply to Greg Kroah-HartmanFrom: Nikos Tsironis <[email protected]>
commit c8e846ff93d5eaa5384f6f325a1687ac5921aade upstream.
dm-era doesn't support changing the data block size of existing devices, so check explicitly that the requested block size for a new target matches the one stored in the metadata.
--- drivers/md/dm-era-target.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/md/dm-era-target.c +9 -1
@@ -564,6 +564,15 @@ static int open_metadata(struct era_meta } disk =dm_block_data (sblock); + +/* Verify the data block size hasn't changed */ +if (le32_to_cpu (disk->data_block_size) != md->block_size) { +DMERR ("changing the data block size (from %u to %llu) is not supported" , +le32_to_cpu (disk->data_block_size), md->block_size); + r = -EINVAL ; + goto bad; + } + r = dm_tm_open_with_sm(md->bm, SUPERBLOCK_LOCATION, disk->metadata_space_map_root, sizeof(disk->metadata_space_map_root),
@@ -575,7 +584,6 @@ static int open_metadata(struct era_metasetup_infos (md); - md->block_size =le32_to_cpu (disk->data_block_size); md->nr_blocks =le32_to_cpu (disk->nr_blocks); md->current_era =le32_to_cpu (disk->current_era);
Greg Kroah-Hartman
maintainerPATCH 651/663 dm era: Fix bitset memory leaks
In reply to Greg Kroah-HartmanFrom: Nikos Tsironis <[email protected]>
commit 904e6b266619c2da5c58b5dce14ae30629e39645 upstream.
Deallocate the memory allocated for the in-core bitsets when destroying the target and in error paths.
--- drivers/md/dm-era-target.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/md/dm-era-target.c +6 -0
@@ -47,6 +47,7 @@ struct writeset {static void writeset_free (struct writeset *ws) {vfree (ws->bits); + ws->bits =NULL ; } static int setup_on_disk_bitset(struct dm_disk_bitset *info,
@@ -811,6 +812,8 @@ static struct era_metadata *metadata_opestatic void metadata_close (struct era_metadata *md) { +writeset_free (&md->writesets[0 ]); +writeset_free (&md->writesets[1 ]);destroy_persistent_data_objects (md);kfree (md); }
@@ -848,6 +851,7 @@ static int metadata_resize(struct era_me r =writeset_alloc (&md->writesets[1 ], *new_size);if (r) {DMERR ("%s: writeset_alloc failed for writeset 1" , __func__); +writeset_free (&md->writesets[0 ]);return r; }
@@ -858,6 +862,8 @@ static int metadata_resize(struct era_me &value, &md->era_array_root);if (r) {DMERR ("%s: dm_array_resize failed" , __func__); +writeset_free (&md->writesets[0 ]); +writeset_free (&md->writesets[1 ]);return r; }
Greg Kroah-Hartman
maintainerPATCH 652/663 dm era: Use correct value size in equality function of writeset tree
In reply to Greg Kroah-HartmanFrom: Nikos Tsironis <[email protected]>
commit 64f2d15afe7b336aafebdcd14cc835ecf856df4b upstream.
Fix the writeset tree equality test function to use the right value size when comparing two btree values.
--- drivers/md/dm-era-target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-era-target.c +1 -1
@@ -389,7 +389,7 @@ static void ws_dec(void *context, conststatic int ws_eq (void *context,const void *value1,const void *value2) { -return !memcmp (value1, value2,sizeof (struct writeset_metadata )); +return !memcmp (value1, value2,sizeof (struct writeset_disk )); }/*----------------------------------------------------------------*/
Greg Kroah-Hartman
maintainerPATCH 653/663 dm era: Reinitialize bitset cache before digesting a new writeset
In reply to Greg Kroah-HartmanFrom: Nikos Tsironis <[email protected]>
commit 2524933307fd0036d5c32357c693c021ab09a0b0 upstream.
In case of devices with at most 64 blocks, the digestion of consecutive eras uses the writeset of the first era as the writeset of all eras to digest, leading to lost writes. That is, we lose the information about what blocks were written during the affected eras.
The digestion code uses a dm_disk_bitset object to access the archived writesets. This structure includes a one word (64-bit) cache to reduce the number of array lookups.
This structure is initialized only once, in metadata_digest_start(), when we kick off digestion.
But, when we insert a new writeset into the writeset tree, before the digestion of the previous writeset is done, or equivalently when there are multiple writesets in the writeset tree to digest, then all these writesets are digested using the same cache and the cache is not re-initialized when moving from one writeset to the next.
For devices with more than 64 blocks, i.e., the size of the cache, the cache is indirectly invalidated when we move to a next set of blocks, so we avoid the bug.
But for devices with at most 64 blocks we end up using the same cached data for digesting all archived writesets, i.e., the cache is loaded when digesting the first writeset and it never gets reloaded, until the digestion is done.
As a result, the writeset of the first era to digest is used as the writeset of all the following archived eras, leading to lost writes.
Fix this by reinitializing the dm_disk_bitset structure, and thus invalidating the cache, every time the digestion code starts digesting a new writeset.
--- drivers/md/dm-era-target.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/md/dm-era-target.c +6 -6
@@ -756,6 +756,12 @@ static int metadata_digest_lookup_writesws_unpack (&disk, &d->writeset); d->value =cpu_to_le32 (key); +/* +* We initialise another bitset info to avoid any caching side effects +* with the previous one. +*/ +dm_disk_bitset_init (md->tm, &d->info); + d->nr_bits =min (d->writeset.nr_bits, md->nr_blocks); d->current_bit =0 ; d->step = metadata_digest_transcribe_writeset;
@@ -769,12 +775,6 @@ static int metadata_digest_start(structreturn 0 ;memset (d,0 ,sizeof (*d)); - -/* -* We initialise another bitset info to avoid any caching side -* effects with the previous one. -*/ -dm_disk_bitset_init (md->tm, &d->info); d->step = metadata_digest_lookup_writeset;return 0 ;
Greg Kroah-Hartman
maintainerPATCH 654/663 dm era: only resize metadata in preresume
In reply to Greg Kroah-HartmanFrom: Nikos Tsironis <[email protected]>
commit cca2c6aebe86f68103a8615074b3578e854b5016 upstream.
Metadata resize shouldn't happen in the ctr. The ctr loads a temporary (inactive) table that will only become active upon resume. That is why resize should always be done in terms of resume. Otherwise a load (ctr) whose inactive table never becomes active will incorrectly resize the metadata.
Also, perform the resize directly in preresume, instead of using the worker to do it.
The worker might run other metadata operations, e.g., it could start digestion, before resizing the metadata. These operations will end up using the old size.
This could lead to errors, like:
device-mapper: era: metadata_digest_transcribe_writeset: dm_array_set_value failed
device-mapper: era: process_old_eras: digest step failed, stopping digestion
The reason of the above error is that the worker started the digestion of the archived writeset using the old, larger size.
As a result, metadata_digest_transcribe_writeset tried to write beyond the end of the era array.
--- drivers/md/dm-era-target.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/md/dm-era-target.c +10 -11
@@ -1501,15 +1501,6 @@ static int era_ctr(struct dm_target *ti, } era->md = md; - era->nr_blocks =calc_nr_blocks (era); - - r =metadata_resize (era->md, &era->nr_blocks); -if (r) { - ti->error ="couldn't resize metadata" ; -era_destroy (era); -return -ENOMEM ; - } - era->wq =alloc_ordered_workqueue ("dm-" DM_MSG_PREFIX ,WQ_MEM_RECLAIM );if (!era->wq) { ti->error ="could not create workqueue for metadata object" ;
@@ -1584,9 +1575,17 @@ static int era_preresume(struct dm_targedm_block_t new_size =calc_nr_blocks (era);if (era->nr_blocks != new_size) { - r =in_worker1 (era, metadata_resize, &new_size); -if (r) + r =metadata_resize (era->md, &new_size); +if (r) { +DMERR ("%s: metadata_resize failed" , __func__); +return r; + } + + r =metadata_commit (era->md); +if (r) { +DMERR ("%s: metadata_commit failed" , __func__);return r; + } era->nr_blocks = new_size; }
Greg Kroah-Hartman
maintainerPATCH 655/663 drm/i915: Reject 446-480MHz HDMI clock on GLK
In reply to Greg Kroah-HartmanFrom: Ville Syrjälä <[email protected]>
commit 7a6c6243b44a439bda4bf099032be35ebcf53406 upstream.
The BXT/GLK DPLL can't generate certain frequencies. We already reject the 233-240MHz range on both. But on GLK the DPLL max frequency was bumped from 300MHz to 594MHz, so now we get to also worry about the 446-480MHz range (double the original problem range). Reject any frequency within the higher problematic range as well.
--- drivers/gpu/drm/i915/display/intel_hdmi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/display/intel_hdmi.c +5 -1
@@ -2216,7 +2216,11 @@ hdmi_port_clock_valid(struct intel_hdmi has_hdmi_sink))return MODE_CLOCK_HIGH ; -/* BXT DPLL can't generate 223-240 MHz */ +/* GLK DPLL can't generate 446-480 MHz */ +if (IS_GEMINILAKE (dev_priv) && clock >446666 && clock <480000 ) +return MODE_CLOCK_RANGE ; + +/* BXT/GLK DPLL can't generate 223-240 MHz */ if (IS_GEN9_LP (dev_priv) && clock >223333 && clock <240000 )return MODE_CLOCK_RANGE ;
Greg Kroah-Hartman
maintainerPATCH 656/663 kgdb: fix to kill breakpoints on initmem after boot
In reply to Greg Kroah-HartmanFrom: Sumit Garg <[email protected]>
commit d54ce6158e354f5358a547b96299ecd7f3725393 upstream.
Currently breakpoints in kernel .init.text section are not handled correctly while allowing to remove them even after corresponding pages have been freed.
Fix it via killing .init.text section breakpoints just prior to initmem pages being freed.
Doug: "HW breakpoints aren't handled by this patch but it's probably not such a big deal".
--- include/linux/kgdb.h | 2 ++ init/main.c | 1 + kernel/debug/debug_core.c | 11 +++++++++++ 3 files changed, 14 insertions(+)
include/linux/kgdb.h +2 -0
@@ -360,9 +360,11 @@ extern atomic_t kgdb_active;extern bool dbg_is_early;extern void __init dbg_late_init (void );extern void kgdb_panic (const char *msg); +extern void kgdb_free_init_mem (void );#else /* ! CONFIG_KGDB */ #define in_dbg_master () (0)#define dbg_late_init ()static inline void kgdb_panic (const char *msg) {} +static inline void kgdb_free_init_mem (void ) { }#endif /* ! CONFIG_KGDB */ #endif /* _KGDB_H_ */
init/main.c +1 -0
@@ -1417,6 +1417,7 @@ static int __ref kernel_init(void *unuseasync_synchronize_full ();kprobe_free_init_mem ();ftrace_free_init_mem (); +kgdb_free_init_mem ();free_initmem ();mark_readonly ();
kernel/debug/debug_core.c +11 -0
@@ -456,6 +456,17 @@ setundefined:return 0 ; } +void kgdb_free_init_mem (void ) +{ +int i; + +/* Clear init memory breakpoints. */ +for (i =0 ; i <KGDB_MAX_BREAKPOINTS ; i++) { +if (init_section_contains ((void *)kgdb_break[i].bpt_addr,0 )) + kgdb_break[i].state =BP_UNDEFINED ; + } +} +#ifdef CONFIG_KGDB_KDB void kdb_dump_stack_on_cpu (int cpu) {
Greg Kroah-Hartman
maintainerPATCH 657/663 ipv6: silence compilation warning for non-IPV6 builds
In reply to Greg Kroah-HartmanFrom: Leon Romanovsky <[email protected]>
commit 1faba27f11c8da244e793546a1b35a9b1da8208e upstream.
The W=1 compilation of allmodconfig generates the following warning:
net/ipv6/icmp.c:448:6: warning: no previous prototype for 'icmp6_send' [-Wmissing-prototypes]
448 | void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
| ^~~~~~~~~~
Fix it by providing function declaration for builds with ipv6 as a module.
--- include/linux/icmpv6.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/icmpv6.h +1 -1
@@ -16,9 +16,9 @@ static inline struct icmp6hdr *icmp6_hdrtypedef void ip6_icmp_send_t (struct sk_buff *skb,u8 type,u8 code,__u32 info,const struct in6_addr *force_saddr); -#if IS_BUILTIN (CONFIG_IPV6 )void icmp6_send (struct sk_buff *skb,u8 type,u8 code,__u32 info,const struct in6_addr *force_saddr); +#if IS_BUILTIN (CONFIG_IPV6 )static inline void icmpv6_send (struct sk_buff *skb,u8 type,u8 code,__u32 info) {icmp6_send (skb, type, code, info,NULL );
Greg Kroah-Hartman
maintainerPATCH 658/663 net: icmp: pass zeroed opts from icmp{,v6}_ndo_send before sending
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
commit ee576c47db60432c37e54b1e2b43a8ca6d3a8dca upstream.
The icmp{,v6}_send functions make all sorts of use of skb->cb, casting it with IPCB or IP6CB, assuming the skb to have come directly from the inet layer. But when the packet comes from the ndo layer, especially when forwarded, there's no telling what might be in skb->cb at that point. As a result, the icmp sending code risks reading bogus memory contents, which can result in nasty stack overflows such as this one reported by a user:
panic+0x108/0x2ea
__stack_chk_fail+0x14/0x20
__icmp_send+0x5bd/0x5c0
icmp_ndo_send+0x148/0x160In icmp_send, skb->cb is cast with IPCB and an ip_options struct is read from it. The optlen parameter there is of particular note, as it can induce writes beyond bounds. There are quite a few ways that can happen in __ip_options_echo. For example:
// sptr/skb are attacker-controlled skb bytes
sptr = skb_network_header(skb);
// dptr/dopt points to stack memory allocated by __icmp_send
dptr = dopt->__data;
// sopt is the corrupt skb->cb in question
if (sopt->rr) {
optlen = sptr[sopt->rr+1]; // corrupt skb->cb + skb->data
soffset = sptr[sopt->rr+2]; // corrupt skb->cb + skb->data
// this now writes potentially attacker-controlled data, over
// flowing the stack:
memcpy(dptr, sptr+sopt->rr, optlen);
}In the icmpv6_send case, the story is similar, but not as dire, as only IP6CB(skb)->iif and IP6CB(skb)->dsthao are used. The dsthao case is worse than the iif case, but it is passed to ipv6_find_tlv, which does a bit of bounds checking on the value.
This is easy to simulate by doing a memset(skb->cb, 0x41, sizeof(skb->cb)); before calling icmp{,v6}_ndo_send, and it's only by good fortune and the rarity of icmp sending from that context that we've avoided reports like this until now. For example, in KASAN:
BUG: KASAN: stack-out-of-bounds in __ip_options_echo+0xa0e/0x12b0
Write of size 38 at addr ffff888006f1f80e by task ping/89
CPU: 2 PID: 89 Comm: ping Not tainted 5.10.0-rc7-debug+ #5
Call Trace:
dump_stack+0x9a/0xcc
print_address_description.constprop.0+0x1a/0x160
__kasan_report.cold+0x20/0x38
kasan_report+0x32/0x40
check_memory_region+0x145/0x1a0
memcpy+0x39/0x60
__ip_options_echo+0xa0e/0x12b0
__icmp_send+0x744/0x1700Actually, out of the 4 drivers that do this, only gtp zeroed the cb for the v4 case, while the rest did not. So this commit actually removes the gtp-specific zeroing, while putting the code where it belongs in the shared infrastructure of icmp{,v6}_ndo_send.
This commit fixes the issue by passing an empty IPCB or IP6CB along to the functions that actually do the work. For the icmp_send, this was already trivial, thanks to __icmp_send providing the plumbing function. For icmpv6_send, this required a tiny bit of refactoring to make it behave like the v4 case, after which it was straight forward.
--- drivers/net/gtp.c | 1 - include/linux/icmpv6.h | 26 ++++++++++++++++++++------ include/linux/ipv6.h | 1 - include/net/icmp.h | 6 +++++- net/ipv4/icmp.c | 5 +++-- net/ipv6/icmp.c | 18 +++++++++--------- net/ipv6/ip6_icmp.c | 12 +++++++----- 7 files changed, 44 insertions(+), 25 deletions(-)
drivers/net/gtp.c +0 -1
@@ -539,7 +539,6 @@ static int gtp_build_skb_ip4(struct sk_bif (!skb_is_gso (skb) && (iph->frag_off &htons (IP_DF )) && mtu <ntohs (iph->tot_len)) {netdev_dbg (dev,"packet too big, fragmentation needed\n" ); -memset (IPCB (skb),0 ,sizeof (*IPCB (skb)));icmp_ndo_send (skb,ICMP_DEST_UNREACH ,ICMP_FRAG_NEEDED ,htonl (mtu)); goto err_rt;
include/linux/icmpv6.h +20 -6
@@ -3,6 +3,7 @@#define _LINUX_ICMPV6_H#include <linux/skbuff.h> +#include <linux/ipv6.h> #include <uapi/linux/icmpv6.h> static inline struct icmp6hdr *icmp6_hdr (const struct sk_buff *skb)
@@ -15,13 +16,16 @@ static inline struct icmp6hdr *icmp6_hdr #if IS_ENABLED(CONFIG_IPV6) typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info, - const struct in6_addr *force_saddr); + const struct in6_addr *force_saddr, + const struct inet6_skb_parm *parm); void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, - const struct in6_addr *force_saddr); + const struct in6_addr *force_saddr, + const struct inet6_skb_parm *parm); #if IS_BUILTIN(CONFIG_IPV6) -static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info) +static inline void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, + const struct inet6_skb_parm *parm) { - icmp6_send(skb, type, code, info, NULL); + icmp6_send(skb, type, code, info, NULL, parm); } static inline int inet6_register_icmp_sender(ip6_icmp_send_t *fn) {
@@ -34,18 +38,28 @@ static inline int inet6_unregister_icmp_return 0 ; }#else -extern void icmpv6_send (struct sk_buff *skb,u8 type,u8 code,__u32 info); +extern void __icmpv6_send (struct sk_buff *skb,u8 type,u8 code,__u32 info, +const struct inet6_skb_parm *parm);extern int inet6_register_icmp_sender (ip6_icmp_send_t *fn);extern int inet6_unregister_icmp_sender (ip6_icmp_send_t *fn);#endif +static inline void icmpv6_send (struct sk_buff *skb,u8 type,u8 code,__u32 info) +{ +__icmpv6_send (skb, type, code, info,IP6CB (skb)); +} +int ip6_err_gen_icmpv6_unreach (struct sk_buff *skb,int nhs,int type,unsigned int data_len);#if IS_ENABLED (CONFIG_NF_NAT )void icmpv6_ndo_send (struct sk_buff *skb_in,u8 type,u8 code,__u32 info);#else -#define icmpv6_ndo_send icmpv6_send +static inline void icmpv6_ndo_send (struct sk_buff *skb_in,u8 type,u8 code,__u32 info) +{ +struct inet6_skb_parm parm = {0 }; +__icmpv6_send (skb_in, type, code, info, &parm); +}#endif #else
include/linux/ipv6.h +0 -1
@@ -84,7 +84,6 @@ struct ipv6_params {__s32 autoconf; };extern struct ipv6_params ipv6_defaults; -#include <linux/icmpv6.h> #include <linux/tcp.h> #include <linux/udp.h>
include/net/icmp.h +5 -1
@@ -46,7 +46,11 @@ static inline void icmp_send(struct sk_b#if IS_ENABLED (CONFIG_NF_NAT )void icmp_ndo_send (struct sk_buff *skb_in,int type,int code,__be32 info);#else -#define icmp_ndo_send icmp_send +static inline void icmp_ndo_send (struct sk_buff *skb_in,int type,int code,__be32 info) +{ +struct ip_options opts = {0 }; +__icmp_send (skb_in, type, code, info, &opts); +}#endif int icmp_rcv (struct sk_buff *skb);
net/ipv4/icmp.c +3 -2
@@ -775,13 +775,14 @@ EXPORT_SYMBOL(__icmp_send);void icmp_ndo_send (struct sk_buff *skb_in,int type,int code,__be32 info) {struct sk_buff *cloned_skb =NULL ; +struct ip_options opts = {0 };enum ip_conntrack_info ctinfo;struct nf_conn *ct;__be32 orig_ip; ct =nf_ct_get (skb_in, &ctinfo);if (!ct || !(ct->status &IPS_SRC_NAT )) { -icmp_send (skb_in, type, code, info); +__icmp_send (skb_in, type, code, info, &opts);return ; }
@@ -796,7 +797,7 @@ void icmp_ndo_send(struct sk_buff *skb_i orig_ip =ip_hdr (skb_in)->saddr;ip_hdr (skb_in)->saddr = ct->tuplehash[0 ].tuple.src.u3.ip; -icmp_send (skb_in, type, code, info); +__icmp_send (skb_in, type, code, info, &opts);ip_hdr (skb_in)->saddr = orig_ip; out:consume_skb (cloned_skb);
net/ipv6/icmp.c +9 -9
@@ -331,10 +331,9 @@ static int icmpv6_getfrag(void *from, ch }#if IS_ENABLED (CONFIG_IPV6_MIP6 ) -static void mip6_addr_swap (struct sk_buff *skb) +static void mip6_addr_swap (struct sk_buff *skb,const struct inet6_skb_parm *opt) {struct ipv6hdr *iph =ipv6_hdr (skb); -struct inet6_skb_parm *opt =IP6CB (skb);struct ipv6_destopt_hao *hao;struct in6_addr tmp;int off;
@@ -351,7 +350,7 @@ static void mip6_addr_swap(struct sk_buf } }#else -static inline void mip6_addr_swap (struct sk_buff *skb) {} +static inline void mip6_addr_swap (struct sk_buff *skb,const struct inet6_skb_parm *opt) {}#endif static struct dst_entry *icmpv6_route_lookup(struct net *net,
@@ -446,7 +445,8 @@ static int icmp6_iif(const struct sk_buf* Send an ICMP message in response to a packet in error */ void icmp6_send (struct sk_buff *skb,u8 type,u8 code,__u32 info, -const struct in6_addr *force_saddr) +const struct in6_addr *force_saddr, +const struct inet6_skb_parm *parm) {struct inet6_dev *idev =NULL ;struct ipv6hdr *hdr =ipv6_hdr (skb);
@@ -542,7 +542,7 @@ void icmp6_send(struct sk_buff *skb, u8if (!(skb->dev->flags &IFF_LOOPBACK ) && !icmpv6_global_allow (net, type)) goto out_bh_enable; -mip6_addr_swap (skb); +mip6_addr_swap (skb, parm); sk =icmpv6_xmit_lock (net);if (!sk)
@@ -559,7 +559,7 @@ void icmp6_send(struct sk_buff *skb, u8/* select a more meaningful saddr from input if */ struct net_device *in_netdev; - in_netdev =dev_get_by_index (net,IP6CB (skb)->iif); + in_netdev =dev_get_by_index (net, parm->iif);if (in_netdev) { ipv6_dev_get_saddr(net, in_netdev, &fl6.daddr, inet6_sk(sk)->srcprefs,
@@ -640,7 +640,7 @@ EXPORT_SYMBOL(icmp6_send);*/ void icmpv6_param_prob (struct sk_buff *skb,u8 code,int pos) { -icmp6_send (skb,ICMPV6_PARAMPROB , code, pos,NULL ); +icmp6_send (skb,ICMPV6_PARAMPROB , code, pos,NULL ,IP6CB (skb));kfree_skb (skb); }
@@ -697,10 +697,10 @@ int ip6_err_gen_icmpv6_unreach(struct sk }if (type ==ICMP_TIME_EXCEEDED )icmp6_send (skb2,ICMPV6_TIME_EXCEED ,ICMPV6_EXC_HOPLIMIT , - info, &temp_saddr); + info, &temp_saddr,IP6CB (skb2));else icmp6_send (skb2,ICMPV6_DEST_UNREACH ,ICMPV6_ADDR_UNREACH , - info, &temp_saddr); + info, &temp_saddr,IP6CB (skb2));if (rt)ip6_rt_put (rt);
net/ipv6/ip6_icmp.c +7 -5
@@ -33,23 +33,25 @@ int inet6_unregister_icmp_sender(ip6_icm }EXPORT_SYMBOL (inet6_unregister_icmp_sender); -void icmpv6_send (struct sk_buff *skb,u8 type,u8 code,__u32 info) +void __icmpv6_send (struct sk_buff *skb,u8 type,u8 code,__u32 info, +const struct inet6_skb_parm *parm) {ip6_icmp_send_t *send;rcu_read_lock (); send =rcu_dereference (ip6_icmp_send);if (send) -send (skb, type, code, info,NULL ); +send (skb, type, code, info,NULL , parm);rcu_read_unlock (); } -EXPORT_SYMBOL (icmpv6_send); +EXPORT_SYMBOL (__icmpv6_send);#endif #if IS_ENABLED (CONFIG_NF_NAT )#include <net/netfilter/nf_conntrack.h> void icmpv6_ndo_send (struct sk_buff *skb_in,u8 type,u8 code,__u32 info) { +struct inet6_skb_parm parm = {0 };struct sk_buff *cloned_skb =NULL ;enum ip_conntrack_info ctinfo;struct in6_addr orig_ip;
@@ -57,7 +59,7 @@ void icmpv6_ndo_send(struct sk_buff *skb ct =nf_ct_get (skb_in, &ctinfo);if (!ct || !(ct->status &IPS_SRC_NAT )) { -icmpv6_send (skb_in, type, code, info); +__icmpv6_send (skb_in, type, code, info, &parm);return ; }
@@ -72,7 +74,7 @@ void icmpv6_ndo_send(struct sk_buff *skb orig_ip =ipv6_hdr (skb_in)->saddr;ipv6_hdr (skb_in)->saddr = ct->tuplehash[0 ].tuple.src.u3.in6; -icmpv6_send (skb_in, type, code, info); +__icmpv6_send (skb_in, type, code, info, &parm);ipv6_hdr (skb_in)->saddr = orig_ip; out:consume_skb (cloned_skb);
Greg Kroah-Hartman
maintainerPATCH 659/663 wireguard: selftests: test multiple parallel streams
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
commit d5a49aa6c3e264a93a7d08485d66e346be0969dd upstream.
In order to test ndo_start_xmit being called in parallel, explicitly add separate tests, which should all run on different cores. This should help tease out bugs associated with queueing up packets from different cores in parallel. Currently, it hasn't found those types of bugs, but given future planned work, this is a useful regression to avoid.
--- tools/testing/selftests/wireguard/netns.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
tools/testing/selftests/wireguard/netns.sh +14 -1
@@ -39,7 +39,7 @@ ip0() { pretty 0 "ip $*"; ip -n $netns0 ip1() { pretty 1 "ip $*"; ip -n $netns1 "$@"; } ip2() { pretty 2 "ip $*"; ip -n $netns2 "$@"; } sleep() { read -t "$1" -N 1 || true; } -waitiperf() { pretty "${1//*-}" "wait for iperf:5201 pid $2"; while [[ $(ss -N "$1" -tlpH 'sport = 5201') != *\"iperf3\",pid=$2,fd=* ]]; do sleep 0.1; done; } +waitiperf() { pretty "${1//*-}" "wait for iperf:${3:-5201} pid $2"; while [[ $(ss -N "$1" -tlpH "sport = ${3:-5201}") != *\"iperf3\",pid=$2,fd=* ]]; do sleep 0.1; done; } waitncatudp() { pretty "${1//*-}" "wait for udp:1111 pid $2"; while [[ $(ss -N "$1" -ulpH 'sport = 1111') != *\"ncat\",pid=$2,fd=* ]]; do sleep 0.1; done; } waitiface() { pretty "${1//*-}" "wait for $2 to come up"; ip netns exec "$1" bash -c "while [[ \$(< \"/sys/class/net/$2/operstate\") != up ]]; do read -t .1 -N 0 || true; done;"; }
@@ -141,6 +141,19 @@ tests() { n2 iperf3 -s -1 -B fd00::2 & waitiperf $netns2 $! n1 iperf3 -Z -t 3 -b 0 -u -c fd00::2 + + # TCP over IPv4, in parallel + for max in 4 5 50; do + local pids=( ) + for ((i=0; i < max; ++i)) do + n2 iperf3 -p $(( 5200 + i )) -s -1 -B 192.168.241.2 & + pids+=( $! ); waitiperf $netns2 $! $(( 5200 + i )) + done + for ((i=0; i < max; ++i)) do + n1 iperf3 -Z -t 3 -p $(( 5200 + i )) -c 192.168.241.2 & + done + wait "${pids[@]}" + done } [[ $(ip1 link show dev wg0) =~ mtu\ ([0-9]+) ]] && orig_mtu="${BASH_REMATCH[1]}"
Greg Kroah-Hartman
maintainerPATCH 660/663 wireguard: queueing: get rid of per-peer ring buffers
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
commit 8b5553ace83cced775eefd0f3f18b5c6214ccf7a upstream.
Having two ring buffers per-peer means that every peer results in two massive ring allocations. On an 8-core x86_64 machine, this commit reduces the per-peer allocation from 18,688 bytes to 1,856 bytes, which is an 90% reduction. Ninety percent! With some single-machine deployments approaching 500,000 peers, we're talking about a reduction from 7 gigs of memory down to 700 megs of memory.
In order to get rid of these per-peer allocations, this commit switches to using a list-based queueing approach. Currently GSO fragments are chained together using the skb->next pointer (the skb_list_* singly linked list approach), so we form the per-peer queue around the unused skb->prev pointer (which sort of makes sense because the links are pointing backwards). Use of skb_queue_* is not possible here, because that is based on doubly linked lists and spinlocks. Multiple cores can write into the queue at any given time, because its writes occur in the start_xmit path or in the udp_recv path. But reads happen in a single workqueue item per-peer, amounting to a multi-producer, single-consumer paradigm.
The MPSC queue is implemented locklessly and never blocks. However, it is not linearizable (though it is serializable), with a very tight and unlikely race on writes, which, when hit (some tiny fraction of the 0.15% of partial adds on a fully loaded 16-core x86_64 system), causes the queue reader to terminate early. However, because every packet sent queues up the same workqueue item after it is fully added, the worker resumes again, and stopping early isn't actually a problem, since at that point the packet wouldn't have yet been added to the encryption queue. These properties allow us to avoid disabling interrupts or spinning. The design is based on Dmitry Vyukov's algorithm [1].
Performance-wise, ordinarily list-based queues aren't preferable to ringbuffers, because of cache misses when following pointers around. However, we *already* have to follow the adjacent pointers when working through fragments, so there shouldn't actually be any change there. A potential downside is that dequeueing is a bit more complicated, but the ptr_ring structure used prior had a spinlock when dequeueing, so all and all the difference appears to be a wash.
Actually, from profiling, the biggest performance hit, by far, of this commit winds up being atomic_add_unless(count, 1, max) and atomic_ dec(count), which account for the majority of CPU time, according to perf. In that sense, the previous ring buffer was superior in that it could check if it was full by head==tail, which the list-based approach cannot do.
But all and all, this enables us to get massive memory savings, allowing WireGuard to scale for real world deployments, without taking much of a performance hit.
[1] http://www.1024cores.net/home/lock-free-algorithms/queues/intrusive-mpsc-node-based-queue
--- drivers/net/wireguard/device.c | 12 ++--- drivers/net/wireguard/device.h | 15 +++--- drivers/net/wireguard/peer.c | 28 ++++-------- drivers/net/wireguard/peer.h | 4 - drivers/net/wireguard/queueing.c | 86 +++++++++++++++++++++++++++++++-------- drivers/net/wireguard/queueing.h | 45 ++++++++++++++------ drivers/net/wireguard/receive.c | 16 ++----- drivers/net/wireguard/send.c | 31 ++++---------- 8 files changed, 144 insertions(+), 93 deletions(-)
drivers/net/wireguard/device.c +6 -6
@@ -235,8 +235,8 @@ static void wg_destruct(struct net_devicdestroy_workqueue (wg->handshake_receive_wq);destroy_workqueue (wg->handshake_send_wq);destroy_workqueue (wg->packet_crypt_wq); -wg_packet_queue_free (&wg->decrypt_queue, true); -wg_packet_queue_free (&wg->encrypt_queue, true); +wg_packet_queue_free (&wg->decrypt_queue); +wg_packet_queue_free (&wg->encrypt_queue);rcu_barrier ();/* Wait for all the peers to be actually freed. */ wg_ratelimiter_uninit ();memzero_explicit (&wg->static_identity,sizeof (wg->static_identity));
@@ -338,12 +338,12 @@ static int wg_newlink(struct net *src_ne goto err_destroy_handshake_send; ret =wg_packet_queue_init (&wg->encrypt_queue, wg_packet_encrypt_worker, - true,MAX_QUEUED_PACKETS ); +MAX_QUEUED_PACKETS );if (ret <0 ) goto err_destroy_packet_crypt; ret =wg_packet_queue_init (&wg->decrypt_queue, wg_packet_decrypt_worker, - true,MAX_QUEUED_PACKETS ); +MAX_QUEUED_PACKETS );if (ret <0 ) goto err_free_encrypt_queue;
@@ -368,9 +368,9 @@ static int wg_newlink(struct net *src_ne err_uninit_ratelimiter:wg_ratelimiter_uninit (); err_free_decrypt_queue: -wg_packet_queue_free (&wg->decrypt_queue, true); +wg_packet_queue_free (&wg->decrypt_queue); err_free_encrypt_queue: -wg_packet_queue_free (&wg->encrypt_queue, true); +wg_packet_queue_free (&wg->encrypt_queue); err_destroy_packet_crypt:destroy_workqueue (wg->packet_crypt_wq); err_destroy_handshake_send:
drivers/net/wireguard/device.h +8 -7
@@ -27,13 +27,14 @@ struct multicore_worker {struct crypt_queue {struct ptr_ring ring; -union { -struct { -struct multicore_worker __percpu *worker; -int last_cpu; - }; -struct work_struct work; - }; +struct multicore_worker __percpu *worker; +int last_cpu; +}; + +struct prev_queue { +struct sk_buff *head, *tail, *peeked; +struct {struct sk_buff *next, *prev; } empty;// Match first 2 members of struct sk_buff. +atomic_t count; };struct wg_device {
drivers/net/wireguard/peer.c +9 -19
@@ -32,27 +32,22 @@ struct wg_peer *wg_peer_create(struct wg peer =kzalloc (sizeof (*peer),GFP_KERNEL );if (unlikely (!peer))return ERR_PTR (ret); - peer->device = wg; +if (dst_cache_init (&peer->endpoint_cache,GFP_KERNEL )) + goto err; + peer->device = wg;wg_noise_handshake_init (&peer->handshake, &wg->static_identity, public_key, preshared_key, peer); -if (dst_cache_init (&peer->endpoint_cache,GFP_KERNEL )) - goto err_1; -if (wg_packet_queue_init (&peer->tx_queue, wg_packet_tx_worker, false, -MAX_QUEUED_PACKETS )) - goto err_2; -if (wg_packet_queue_init (&peer->rx_queue,NULL , false, -MAX_QUEUED_PACKETS )) - goto err_3; - peer->internal_id =atomic64_inc_return (&peer_counter); peer->serial_work_cpu = nr_cpumask_bits;wg_cookie_init (&peer->latest_cookie);wg_timers_init (peer);wg_cookie_checker_precompute_peer_keys (peer);spin_lock_init (&peer->keypairs.keypair_update_lock); -INIT_WORK (&peer->transmit_handshake_work, - wg_packet_handshake_send_worker); +INIT_WORK (&peer->transmit_handshake_work, wg_packet_handshake_send_worker); +INIT_WORK (&peer->transmit_packet_work, wg_packet_tx_worker); +wg_prev_queue_init (&peer->tx_queue); +wg_prev_queue_init (&peer->rx_queue);rwlock_init (&peer->endpoint_lock);kref_init (&peer->refcount);skb_queue_head_init (&peer->staged_packet_queue);
@@ -68,11 +63,7 @@ struct wg_peer *wg_peer_create(struct wgpr_debug ("%s: Peer %llu created\n" , wg->dev->name, peer->internal_id);return peer; -err_3: -wg_packet_queue_free (&peer->tx_queue, false); -err_2: -dst_cache_destroy (&peer->endpoint_cache); -err_1: +err:kfree (peer);return ERR_PTR (ret); }
@@ -197,8 +188,7 @@ static void rcu_release(struct rcu_head struct wg_peer *peer = container_of(rcu, struct wg_peer, rcu);dst_cache_destroy (&peer->endpoint_cache); -wg_packet_queue_free (&peer->rx_queue, false); -wg_packet_queue_free (&peer->tx_queue, false); +WARN_ON (wg_prev_queue_peek (&peer->tx_queue) ||wg_prev_queue_peek (&peer->rx_queue));/* The final zeroing takes care of clearing any remaining handshake key * material and other potentially sensitive information.
drivers/net/wireguard/peer.h +2 -2
@@ -36,7 +36,7 @@ struct endpoint {struct wg_peer {struct wg_device *device; -struct crypt_queue tx_queue, rx_queue; +struct prev_queue tx_queue, rx_queue;struct sk_buff_head staged_packet_queue;int serial_work_cpu;struct noise_keypairs keypairs;
@@ -45,7 +45,7 @@ struct wg_peer {rwlock_t endpoint_lock;struct noise_handshake handshake;atomic64_t last_sent_handshake; -struct work_struct transmit_handshake_work, clear_peer_work; +struct work_struct transmit_handshake_work, clear_peer_work, transmit_packet_work;struct cookie latest_cookie;struct hlist_node pubkey_hash;u64 rx_bytes, tx_bytes;
drivers/net/wireguard/queueing.c +69 -17
109 lines not on this page · raw message
drivers/net/wireguard/queueing.h +33 -12
84 lines not on this page · raw message
drivers/net/wireguard/receive.c +6 -10
@@ -444,7 +444,6 @@ packet_processed:int wg_packet_rx_poll (struct napi_struct *napi,int budget) { struct wg_peer *peer = container_of(napi, struct wg_peer, napi); -struct crypt_queue *queue = &peer->rx_queue;struct noise_keypair *keypair;struct endpoint endpoint;enum packet_state state;
@@ -455,11 +454,10 @@ int wg_packet_rx_poll(struct napi_structif (unlikely (budget <=0 ))return 0 ; -while ((skb =__ptr_ring_peek (&queue->ring)) !=NULL && +while ((skb =wg_prev_queue_peek (&peer->rx_queue)) !=NULL && (state =atomic_read_acquire (&PACKET_CB (skb)->state)) !=PACKET_STATE_UNCRYPTED ) { -__ptr_ring_discard_one (&queue->ring); - peer =PACKET_PEER (skb); +wg_prev_queue_drop_peeked (&peer->rx_queue); keypair =PACKET_CB (skb)->keypair; free = true;
@@ -508,7 +506,7 @@ void wg_packet_decrypt_worker(struct worenum packet_state state =likely (decrypt_packet (skb,PACKET_CB (skb)->keypair)) ?PACKET_STATE_CRYPTED :PACKET_STATE_DEAD ; -wg_queue_enqueue_per_peer_napi (skb, state); +wg_queue_enqueue_per_peer_rx (skb, state);if (need_resched ())cond_resched (); }
@@ -531,12 +529,10 @@ static void wg_packet_consume_data(strucif (unlikely (READ_ONCE (peer->is_dead))) goto err; - ret =wg_queue_enqueue_per_device_and_peer (&wg->decrypt_queue, - &peer->rx_queue, skb, - wg->packet_crypt_wq, - &wg->decrypt_queue.last_cpu); + ret =wg_queue_enqueue_per_device_and_peer (&wg->decrypt_queue, &peer->rx_queue, skb, + wg->packet_crypt_wq, &wg->decrypt_queue.last_cpu);if (unlikely (ret == -EPIPE )) -wg_queue_enqueue_per_peer_napi (skb,PACKET_STATE_DEAD ); +wg_queue_enqueue_per_peer_rx (skb,PACKET_STATE_DEAD );if (likely (!ret || ret == -EPIPE )) {rcu_read_unlock_bh ();return ;
drivers/net/wireguard/send.c +11 -20
@@ -239,8 +239,7 @@ void wg_packet_send_keepalive(struct wg_wg_packet_send_staged_packets (peer); } -static void wg_packet_create_data_done (struct sk_buff *first, -struct wg_peer *peer) +static void wg_packet_create_data_done (struct wg_peer *peer,struct sk_buff *first) {struct sk_buff *skb, *next;bool is_keepalive, data_sent = false;
@@ -262,22 +261,19 @@ static void wg_packet_create_data_done(svoid wg_packet_tx_worker (struct work_struct *work) { - struct crypt_queue *queue = container_of(work, struct crypt_queue, - work); + struct wg_peer *peer = container_of(work, struct wg_peer, transmit_packet_work);struct noise_keypair *keypair;enum packet_state state;struct sk_buff *first; -struct wg_peer *peer; -while ((first =__ptr_ring_peek (&queue->ring)) !=NULL && +while ((first =wg_prev_queue_peek (&peer->tx_queue)) !=NULL && (state =atomic_read_acquire (&PACKET_CB (first)->state)) !=PACKET_STATE_UNCRYPTED ) { -__ptr_ring_discard_one (&queue->ring); - peer =PACKET_PEER (first); +wg_prev_queue_drop_peeked (&peer->tx_queue); keypair =PACKET_CB (first)->keypair;if (likely (state ==PACKET_STATE_CRYPTED )) -wg_packet_create_data_done (first, peer); +wg_packet_create_data_done (peer, first);else kfree_skb_list (first);
@@ -306,16 +302,14 @@ void wg_packet_encrypt_worker(struct worbreak ; } } -wg_queue_enqueue_per_peer (&PACKET_PEER (first)->tx_queue, first, - state); +wg_queue_enqueue_per_peer_tx (first, state);if (need_resched ())cond_resched (); } } -static void wg_packet_create_data (struct sk_buff *first) +static void wg_packet_create_data (struct wg_peer *peer,struct sk_buff *first) { -struct wg_peer *peer =PACKET_PEER (first);struct wg_device *wg = peer->device;int ret = -EINVAL ;
@@ -323,13 +317,10 @@ static void wg_packet_create_data(structif (unlikely (READ_ONCE (peer->is_dead))) goto err; - ret =wg_queue_enqueue_per_device_and_peer (&wg->encrypt_queue, - &peer->tx_queue, first, - wg->packet_crypt_wq, - &wg->encrypt_queue.last_cpu); + ret =wg_queue_enqueue_per_device_and_peer (&wg->encrypt_queue, &peer->tx_queue, first, + wg->packet_crypt_wq, &wg->encrypt_queue.last_cpu);if (unlikely (ret == -EPIPE )) -wg_queue_enqueue_per_peer (&peer->tx_queue, first, -PACKET_STATE_DEAD ); +wg_queue_enqueue_per_peer_tx (first,PACKET_STATE_DEAD ); err:rcu_read_unlock_bh ();if (likely (!ret || ret == -EPIPE ))
@@ -393,7 +384,7 @@ void wg_packet_send_staged_packets(struc packets.prev->next =NULL ;wg_peer_get (keypair->entry.peer);PACKET_CB (packets.next)->keypair = keypair; -wg_packet_create_data (packets.next); +wg_packet_create_data (peer, packets.next);return ; out_invalid:
Greg Kroah-Hartman
maintainerPATCH 661/663 net: sched: fix police ext initialization
In reply to Greg Kroah-HartmanFrom: Vlad Buslov <[email protected]>
commit 396d7f23adf9e8c436dd81a69488b5b6a865acf8 upstream.
When police action is created by cls API tcf_exts_validate() first conditional that calls tcf_action_init_1() directly, the action idr is not updated according to latest changes in action API that require caller to commit newly created action to idr with tcf_idr_insert_many(). This results such action not being accessible through act API and causes crash reported by syzbot:
==================================================================
BUG: KASAN: null-ptr-deref in instrument_atomic_read include/linux/instrumented.h:71 [inline] BUG: KASAN: null-ptr-deref in atomic_read include/asm-generic/atomic-instrumented.h:27 [inline] BUG: KASAN: null-ptr-deref in __tcf_idr_release net/sched/act_api.c:178 [inline] BUG: KASAN: null-ptr-deref in tcf_idrinfo_destroy+0x129/0x1d0 net/sched/act_api.c:598 Read of size 4 at addr 0000000000000010 by task kworker/u4:5/204 CPU: 0 PID: 204 Comm: kworker/u4:5 Not tainted 5.11.0-rc7-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: netns cleanup_net Call Trace: __dump_stack lib/dump_stack.c:79 [inline] dump_stack+0x107/0x163 lib/dump_stack.c:120 __kasan_report mm/kasan/report.c:400 [inline] kasan_report.cold+0x5f/0xd5 mm/kasan/report.c:413 check_memory_region_inline mm/kasan/generic.c:179 [inline] check_memory_region+0x13d/0x180 mm/kasan/generic.c:185 instrument_atomic_read include/linux/instrumented.h:71 [inline] atomic_read include/asm-generic/atomic-instrumented.h:27 [inline] __tcf_idr_release net/sched/act_api.c:178 [inline] tcf_idrinfo_destroy+0x129/0x1d0 net/sched/act_api.c:598 tc_action_net_exit include/net/act_api.h:151 [inline] police_exit_net+0x168/0x360 net/sched/act_police.c:390 ops_exit_list+0x10d/0x160 net/core/net_namespace.c:190 cleanup_net+0x4ea/0xb10 net/core/net_namespace.c:604 process_one_work+0x98d/0x15f0 kernel/workqueue.c:2275 worker_thread+0x64c/0x1120 kernel/workqueue.c:2421 kthread+0x3b1/0x4a0 kernel/kthread.c:292 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296 ================================================================== Kernel panic - not syncing: panic_on_warn set ... CPU: 0 PID: 204 Comm: kworker/u4:5 Tainted: G B 5.11.0-rc7-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: netns cleanup_net Call Trace: __dump_stack lib/dump_stack.c:79 [inline] dump_stack+0x107/0x163 lib/dump_stack.c:120 panic+0x306/0x73d kernel/panic.c:231 end_report+0x58/0x5e mm/kasan/report.c:100 __kasan_report mm/kasan/report.c:403 [inline] kasan_report.cold+0x67/0xd5 mm/kasan/report.c:413 check_memory_region_inline mm/kasan/generic.c:179 [inline] check_memory_region+0x13d/0x180 mm/kasan/generic.c:185 instrument_atomic_read include/linux/instrumented.h:71 [inline] atomic_read include/asm-generic/atomic-instrumented.h:27 [inline] __tcf_idr_release net/sched/act_api.c:178 [inline] tcf_idrinfo_destroy+0x129/0x1d0 net/sched/act_api.c:598 tc_action_net_exit include/net/act_api.h:151 [inline] police_exit_net+0x168/0x360 net/sched/act_police.c:390 ops_exit_list+0x10d/0x160 net/core/net_namespace.c:190 cleanup_net+0x4ea/0xb10 net/core/net_namespace.c:604 process_one_work+0x98d/0x15f0 kernel/workqueue.c:2275 worker_thread+0x64c/0x1120 kernel/workqueue.c:2421 kthread+0x3b1/0x4a0 kernel/kthread.c:292 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296
Kernel Offset: disabled
Fix the issue by calling tcf_idr_insert_many() after successful action initialization.
--- include/net/act_api.h | 1 + net/sched/act_api.c | 2 +- net/sched/cls_api.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-)
include/net/act_api.h +1 -0
@@ -166,6 +166,7 @@ int tcf_idr_create_from_flags(struct tc_ struct nlattr *est, struct tc_action **a, const struct tc_action_ops *ops, int bind, u32 flags); +void tcf_idr_insert_many (struct tc_action *actions[]);void tcf_idr_cleanup (struct tc_action_net *tn,u32 index);int tcf_idr_check_alloc (struct tc_action_net *tn,u32 *index,struct tc_action **a,int bind);
net/sched/act_api.c +1 -1
@@ -888,7 +888,7 @@ static const struct nla_policy tcf_actio [TCA_ACT_HW_STATS] = NLA_POLICY_BITFIELD32(TCA_ACT_HW_STATS_ANY), }; -static void tcf_idr_insert_many (struct tc_action *actions[]) +void tcf_idr_insert_many (struct tc_action *actions[]) {int i;
net/sched/cls_api.c +1 -0
@@ -3065,6 +3065,7 @@ int tcf_exts_validate(struct net *net, s act->type = exts->type =TCA_OLD_COMPAT ; exts->actions[0 ] = act; exts->nr_actions =1 ; +tcf_idr_insert_many (exts->actions); }else if (exts->action && tb[exts->action]) {int err;
Greg Kroah-Hartman
maintainerPATCH 662/663 net: qrtr: Fix memory leak in qrtr_tun_open
In reply to Greg Kroah-HartmanFrom: Takeshi Misawa <[email protected]>
commit fc0494ead6398609c49afa37bc949b61c5c16b91 upstream.
If qrtr_endpoint_register() failed, tun is leaked. Fix this, by freeing tun in error path.
syzbot report:
BUG: memory leak
unreferenced object 0xffff88811848d680 (size 64):
comm "syz-executor684", pid 10171, jiffies 4294951561 (age 26.070s)
hex dump (first 32 bytes):
80 dd 0a 84 ff ff ff ff 00 00 00 00 00 00 00 00 ................
90 d6 48 18 81 88 ff ff 90 d6 48 18 81 88 ff ff ..H.......H.....
backtrace:
[<0000000018992a50>] kmalloc include/linux/slab.h:552 [inline]
[<0000000018992a50>] kzalloc include/linux/slab.h:682 [inline]
[<0000000018992a50>] qrtr_tun_open+0x22/0x90 net/qrtr/tun.c:35
[<0000000003a453ef>] misc_open+0x19c/0x1e0 drivers/char/misc.c:141
[<00000000dec38ac8>] chrdev_open+0x10d/0x340 fs/char_dev.c:414
[<0000000079094996>] do_dentry_open+0x1e6/0x620 fs/open.c:817
[<000000004096d290>] do_open fs/namei.c:3252 [inline]
[<000000004096d290>] path_openat+0x74a/0x1b00 fs/namei.c:3369
[<00000000b8e64241>] do_filp_open+0xa0/0x190 fs/namei.c:3396
[<00000000a3299422>] do_sys_openat2+0xed/0x230 fs/open.c:1172
[<000000002c1bdcef>] do_sys_open fs/open.c:1188 [inline]
[<000000002c1bdcef>] __do_sys_openat fs/open.c:1204 [inline]
[<000000002c1bdcef>] __se_sys_openat fs/open.c:1199 [inline]
[<000000002c1bdcef>] __x64_sys_openat+0x7f/0xe0 fs/open.c:1199
[<00000000f3a5728f>] do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
[<000000004b38b7ec>] entry_SYSCALL_64_after_hwframe+0x44/0xa9--- net/qrtr/tun.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
net/qrtr/tun.c +11 -1
@@ -31,6 +31,7 @@ static int qrtr_tun_send(struct qrtr_endstatic int qrtr_tun_open (struct inode *inode,struct file *filp) {struct qrtr_tun *tun; +int ret; tun =kzalloc (sizeof (*tun),GFP_KERNEL );if (!tun)
@@ -43,7 +44,16 @@ static int qrtr_tun_open(struct inode *i filp->private_data = tun; -return qrtr_endpoint_register (&tun->ep,QRTR_EP_NID_AUTO ); + ret =qrtr_endpoint_register (&tun->ep,QRTR_EP_NID_AUTO ); +if (ret) + goto out; + +return 0 ; + +out: + filp->private_data =NULL ; +kfree (tun); +return ret; }static ssize_t qrtr_tun_read_iter (struct kiocb *iocb,struct iov_iter *to)
Greg Kroah-Hartman
maintainerPATCH 663/663 net_sched: fix RTNL deadlock again caused by request_module()
In reply to Greg Kroah-HartmanFrom: Cong Wang <[email protected]>
commit d349f997686887906b1183b5be96933c5452362a upstream.
tcf_action_init_1() loads tc action modules automatically with request_module() after parsing the tc action names, and it drops RTNL lock and re-holds it before and after request_module(). This causes a lot of troubles, as discovered by syzbot, because we can be in the middle of batch initializations when we create an array of tc actions.
One of the problem is deadlock:
CPU 0 CPU 1rtnl_lock();
for (...) {
tcf_action_init_1();
-> rtnl_unlock();
-> request_module();
rtnl_lock();
for (...) {
tcf_action_init_1();
-> tcf_idr_check_alloc();
// Insert one action into idr,
// but it is not committed until
// tcf_idr_insert_many(), then drop
// the RTNL lock in the _next_
// iteration
-> rtnl_unlock();
-> rtnl_lock();
-> a_o->init();
-> tcf_idr_check_alloc();
// Now waiting for the same index
// to be committed
-> request_module();
-> rtnl_lock()
// Now waiting for RTNL lock
}
rtnl_unlock();
}rtnl_unlock();
This is not easy to solve, we can move the request_module() before this loop and pre-load all the modules we need for this netlink message and then do the rest initializations. So the loop breaks down to two now:
for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
struct tc_action_ops *a_o;
a_o = tc_action_load_ops(name, tb[i]...);
ops[i - 1] = a_o;
}
for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
act = tcf_action_init_1(ops[i - 1]...);
}Although this looks serious, it only has been reported by syzbot, so it seems hard to trigger this by humans. And given the size of this patch, I'd suggest to make it to net-next and not to backport to stable.
This patch has been tested by syzbot and tested with tdc.py by me.
--- include/net/act_api.h | 5 +- net/sched/act_api.c | 104 +++++++++++++++++++++++++++++++------------------- net/sched/cls_api.c | 11 ++++- 3 files changed, 79 insertions(+), 41 deletions(-)
include/net/act_api.h +4 -1
@@ -187,10 +187,13 @@ int tcf_action_init(struct net *net, str struct nlattr *est, char *name, int ovr, int bind, struct tc_action *actions[], size_t *attr_size, bool rtnl_held, struct netlink_ext_ack *extack); +struct tc_action_ops *tc_action_load_ops (char *name,struct nlattr *nla, +bool rtnl_held, +struct netlink_ext_ack *extack);struct tc_action *tcf_action_init_1 (struct net *net,struct tcf_proto *tp,struct nlattr *nla,struct nlattr *est,char *name,int ovr,int bind, -bool rtnl_held, +struct tc_action_ops *ops,bool rtnl_held,struct netlink_ext_ack *extack);int tcf_action_dump (struct sk_buff *skb,struct tc_action *actions[],int bind,int ref,bool terse);
net/sched/act_api.c +66 -38
176 lines not on this page · raw message
net/sched/cls_api.c +9 -2
@@ -3055,12 +3055,19 @@ int tcf_exts_validate(struct net *net, ssize_t attr_size =0 ;if (exts->police && tb[exts->police]) { +struct tc_action_ops *a_o; + + a_o =tc_action_load_ops ("police" , tb[exts->police], rtnl_held, extack); +if (IS_ERR (a_o)) +return PTR_ERR (a_o); act =tcf_action_init_1 (net, tp, tb[exts->police], rate_tlv,"police" , ovr, -TCA_ACT_BIND , rtnl_held, +TCA_ACT_BIND , a_o, rtnl_held, extack); -if (IS_ERR (act)) +if (IS_ERR (act)) { +module_put (a_o->owner);return PTR_ERR (act); + } act->type = exts->type =TCA_OLD_COMPAT ; exts->actions[0 ] = act;
Re: [PATCH 5.10 663/663] net_sched: fix RTNL deadlock again caused by request_module()
Hi!
Quoted 3 lines
Although this looks serious, it only has been reported by syzbot, so it seems hard to trigger this by humans. And given the size of this patch, I'd suggest to make it to net-next and not to backport to stable.
I'd also preffer this not to be in stable. Long patch in series of 600, with few days to review it all, and patch was not really in mainline for long enough.
Best regards,
Pavel
Signature · 1 line
http://www.livejournal.com/~pavelmachek