5.10.137-rc1 review
Subsystems (9)
Greg Kroah-Hartman
maintainerPATCH 467/545 intel_th: pci: Add Meteor Lake-P support
In reply to Greg Kroah-HartmanFrom: Alexander Shishkin <[email protected]>
[ Upstream commit 802a9a0b1d91274ef10d9fe429b4cc1e8c200aef ]
Add support for the Trace Hub in Meteor Lake-P.
--- drivers/hwtracing/intel_th/pci.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/hwtracing/intel_th/pci.c +5 -0
@@ -284,6 +284,11 @@ static const struct pci_device_id intel_th_pci_id_table[] = { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x54a6), .driver_data = (kernel_ulong_t)&intel_th_2x, }, + { +/* Meteor Lake-P */ +PCI_DEVICE (PCI_VENDOR_ID_INTEL ,0x7e24 ), + .driver_data = (kernel_ulong_t)&intel_th_2x, + }, {/* Alder Lake CPU */ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x466f),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 468/545 intel_th: pci: Add Raptor Lake-S PCH support
In reply to Greg Kroah-HartmanFrom: Alexander Shishkin <[email protected]>
[ Upstream commit 23e2de5826e2fc4dd43e08bab3a2ea1a5338b063 ]
Add support for the Trace Hub in Raptor Lake-S PCH.
--- drivers/hwtracing/intel_th/pci.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/hwtracing/intel_th/pci.c +5 -0
@@ -289,6 +289,11 @@ static const struct pci_device_id intel_th_pci_id_table[] = { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x7e24), .driver_data = (kernel_ulong_t)&intel_th_2x, }, + { +/* Raptor Lake-S */ +PCI_DEVICE (PCI_VENDOR_ID_INTEL ,0x7a26 ), + .driver_data = (kernel_ulong_t)&intel_th_2x, + }, {/* Alder Lake CPU */ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x466f),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 469/545 intel_th: pci: Add Raptor Lake-S CPU support
In reply to Greg Kroah-HartmanFrom: Alexander Shishkin <[email protected]>
[ Upstream commit ff46a601afc5a66a81c3945b83d0a2caeb88e8bc ]
Add support for the Trace Hub in Raptor Lake-S CPU.
--- drivers/hwtracing/intel_th/pci.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/hwtracing/intel_th/pci.c +5 -0
@@ -294,6 +294,11 @@ static const struct pci_device_id intel_th_pci_id_table[] = { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x7a26), .driver_data = (kernel_ulong_t)&intel_th_2x, }, + { +/* Raptor Lake-S CPU */ +PCI_DEVICE (PCI_VENDOR_ID_INTEL ,0xa76f ), + .driver_data = (kernel_ulong_t)&intel_th_2x, + }, {/* Alder Lake CPU */ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x466f),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 470/545 KVM: set_msr_mce: Permit guests to ignore single-bit ECC errors
In reply to Greg Kroah-HartmanFrom: Lev Kujawski <[email protected]>
[ Upstream commit 0471a7bd1bca2a47a5f378f2222c5cf39ce94152 ]
Certain guest operating systems (e.g., UNIXWARE) clear bit 0 of MC1_CTL to ignore single-bit ECC data errors. Single-bit ECC data errors are always correctable and thus are safe to ignore because they are informational in nature rather than signaling a loss of data integrity.
Prior to this patch, these guests would crash upon writing MC1_CTL, with resultant error messages like the following:
error: kvm run failed Operation not permitted
EAX=fffffffe EBX=fffffffe ECX=00000404 EDX=ffffffff ESI=ffffffff EDI=00000001 EBP=fffdaba4 ESP=fffdab20 EIP=c01333a5 EFL=00000246 [---Z-P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0108 00000000 ffffffff 00c09300 DPL=0 DS [-WA]
CS =0100 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0108 00000000 ffffffff 00c09300 DPL=0 DS [-WA]
DS =0108 00000000 ffffffff 00c09300 DPL=0 DS [-WA]
FS =0000 00000000 ffffffff 00c00000
GS =0000 00000000 ffffffff 00c00000
LDT=0118 c1026390 00000047 00008200 DPL=0 LDT
TR =0110 ffff5af0 00000067 00008b00 DPL=0 TSS32-busy
GDT= ffff5020 000002cf
IDT= ffff52f0 000007ff
CR0=8001003b CR2=00000000 CR3=0100a000 CR4=00000230 DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000 DR6=ffff0ff0 DR7=00000400
EFER=0000000000000000
Code=08 89 01 89 51 04 c3 8b 4c 24 08 8b 01 8b 51 04 8b 4c 24 04 <0f> 30 c3 f7 05 a4 6d ff ff 10 00 00 00 74 03 0f 31 c3 33 c0 33 d2 c3 8d 74 26 00 0f 31 c3
Message-Id: <[email protected]>
--- arch/x86/kvm/x86.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +5 -2
@@ -2862,10 +2862,13 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, struct msr_data *msr_info)/* only 0 or all 1s can be written to IA32_MCi_CTL * some Linux kernels though clear bit 10 in bank 4 to * workaround a BIOS/GART TBL issue on AMD K8s, ignore -* this to avoid an uncatched #GP in the guest +* this to avoid an uncatched #GP in the guest. +* +* UNIXWARE clears bit 0 of MC1_CTL to ignore +* correctable, single-bit ECC data errors. */ if ((offset &0x3 ) ==0 && - data !=0 && (data | (1 <<10 )) != ~(u64 )0 ) + data !=0 && (data | (1 <<10 ) |1 ) != ~(u64 )0 )return -1 ;/* MCi_STATUS */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 471/545 KVM: x86: Signal #GP, not -EPERM, on bad WRMSR(MCi_CTL/STATUS)
In reply to Greg Kroah-HartmanFrom: Sean Christopherson <[email protected]>
[ Upstream commit 2368048bf5c2ec4b604ac3431564071e89a0bc71 ]
Return '1', not '-1', when handling an illegal WRMSR to a MCi_CTL or MCi_STATUS MSR. The behavior of "all zeros' or "all ones" for CTL MSRs is architectural, as is the "only zeros" behavior for STATUS MSRs. I.e. the intent is to inject a #GP, not exit to userspace due to an unhandled emulation case. Returning '-1' gets interpreted as -EPERM up the stack and effecitvely kills the guest.
--- arch/x86/kvm/x86.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +2 -2
@@ -2869,13 +2869,13 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, struct msr_data *msr_info)*/ if ((offset &0x3 ) ==0 && data !=0 && (data | (1 <<10 ) |1 ) != ~(u64 )0 ) -return -1 ; +return 1 ;/* MCi_STATUS */ if (!msr_info->host_initiated && (offset &0x3 ) ==1 && data !=0 ) {if (!can_set_mci_status (vcpu)) -return -1 ; +return 1 ; } vcpu->arch.mce_banks[offset] = data;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 472/545 iommu/vt-d: avoid invalid memory access via node_online(NUMA_NO_NODE)
In reply to Greg Kroah-HartmanFrom: Alexander Lobakin <[email protected]>
[ Upstream commit b0b0b77ea611e3088e9523e60860f4f41b62b235 ]
KASAN reports:
[ 4.668325][ T0] BUG: KASAN: wild-memory-access in dmar_parse_one_rhsa (arch/x86/include/asm/bitops.h:214 arch/x86/include/asm/bitops.h:226 include/asm-generic/bitops/instrumented-non-atomic.h:142 include/linux/nodemask.h:415 drivers/iommu/intel/dmar.c:497) [ 4.676149][ T0] Read of size 8 at addr 1fffffff85115558 by task swapper/0/0 [ 4.683454][ T0] [ 4.685638][ T0] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.19.0-rc3-00004-g0e862838f290 #1 [ 4.694331][ T0] Hardware name: Supermicro SYS-5018D-FN4T/X10SDV-8C-TLN4F, BIOS 1.1 03/02/2016 [ 4.703196][ T0] Call Trace: [ 4.706334][ T0] <TASK> [ 4.709133][ T0] ? dmar_parse_one_rhsa (arch/x86/include/asm/bitops.h:214 arch/x86/include/asm/bitops.h:226 include/asm-generic/bitops/instrumented-non-atomic.h:142 include/linux/nodemask.h:415 drivers/iommu/intel/dmar.c:497)
after converting the type of the first argument (@nr, bit number) of arch_test_bit() from long to unsigned long[0].
Under certain conditions (for example, when ACPI NUMA is disabled via command line), pxm_to_node() can return %NUMA_NO_NODE (-1). It is valid 'magic' number of NUMA node, but not valid bit number to use in bitops.node_online() eventually descends to test_bit() without checking for the input, assuming it's on caller side (which might be good for perf-critical tasks). There, -1 becomes %ULONG_MAX which leads to an insane array index when calculating bit position in memory.
For now, add an explicit check for @node being not %NUMA_NO_NODE before calling test_bit(). The actual logics didn't change here at all.
[0] https://github.com/norov/linux/commit/0e862838f290147ea9c16db852d8d494b552d38d
--- drivers/iommu/intel/dmar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/dmar.c +1 -1
@@ -497,7 +497,7 @@ static int dmar_parse_one_rhsa(struct acpi_dmar_header *header, void *arg)if (drhd->reg_base_addr == rhsa->base_address) {int node =pxm_to_node (rhsa->proximity_domain); -if (!node_online (node)) +if (node !=NUMA_NO_NODE && !node_online (node)) node =NUMA_NO_NODE ; drhd->iommu->node = node;return 0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 473/545 PCI/AER: Write AER Capability only when we control it
In reply to Greg Kroah-HartmanFrom: Sean V Kelley <[email protected]>
[ Upstream commit 50cc18fcd3053fb46a09db5a39e6516e9560f765 ]
If an OS has not been granted AER control via _OSC, it should not make changes to PCI_ERR_ROOT_COMMAND and PCI_ERR_ROOT_STATUS related registers. Per section 4.5.1 of the System Firmware Intermediary (SFI) _OSC and DPC Updates ECN [1], this bit also covers these aspects of the PCI Express Advanced Error Reporting. Based on the above and earlier discussion [2], make the following changes:
Add a check for the native case (i.e., AER control via _OSC)
Note that the previous "clear, reset, enable" order suggests that the reset might cause errors that we should ignore. After this commit, those errors (if any) will remain logged in the PCI_ERR_ROOT_STATUS register.
[1] System Firmware Intermediary (SFI) _OSC and DPC Updates ECN, Feb 24, 2020, affecting PCI Firmware Specification, Rev. 3.2
https://members.pcisig.com/wg/PCI-SIG/document/14076
[2] https://lore.kernel.org/linux-pci/20201020162820.GA370938@bjorn-Precision-5520/
--- drivers/pci/pcie/aer.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
drivers/pci/pcie/aer.c +16 -13
@@ -1366,23 +1366,26 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev)u32 reg32;int rc; - -/* Disable Root's interrupt in response to error messages */ -pci_read_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , ®32); - reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK ; -pci_write_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , reg32); +if (pcie_aer_is_native (dev)) { +/* Disable Root's interrupt in response to error messages */ +pci_read_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , ®32); + reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK ; +pci_write_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , reg32); + } rc =pci_bus_error_reset (dev); -pci_info (dev,"Root Port link has been reset\n" ); +pci_info (dev,"Root Port link has been reset (%d)\n" , rc); -/* Clear Root Error Status */ -pci_read_config_dword (dev, aer +PCI_ERR_ROOT_STATUS , ®32); -pci_write_config_dword (dev, aer +PCI_ERR_ROOT_STATUS , reg32); +if (pcie_aer_is_native (dev)) { +/* Clear Root Error Status */ +pci_read_config_dword (dev, aer +PCI_ERR_ROOT_STATUS , ®32); +pci_write_config_dword (dev, aer +PCI_ERR_ROOT_STATUS , reg32); -/* Enable Root Port's interrupt in response to error messages */ -pci_read_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , ®32); - reg32 |=ROOT_PORT_INTR_ON_MESG_MASK ; -pci_write_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , reg32); +/* Enable Root Port's interrupt in response to error messages */ +pci_read_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , ®32); + reg32 |=ROOT_PORT_INTR_ON_MESG_MASK ; +pci_write_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , reg32); + }return rc ?PCI_ERS_RESULT_DISCONNECT :PCI_ERS_RESULT_RECOVERED ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 474/545 PCI/ERR: Bind RCEC devices to the Root Port driver
In reply to Greg Kroah-HartmanFrom: Qiuxu Zhuo <[email protected]>
[ Upstream commit c9d659b60770db94b898f94947192a94bbf95c5c ]
If a Root Complex Integrated Endpoint (RCiEP) is implemented, it may signal errors through a Root Complex Event Collector (RCEC). Each RCiEP must be associated with no more than one RCEC.
For an RCEC (which is technically not a Bridge), error messages "received" from associated RCiEPs must be enabled for "transmission" in order to cause a System Error via the Root Control register or (when the Advanced Error Reporting Capability is present) reporting via the Root Error Command register and logging in the Root Error Status register and Error Source Identification register.
Given the commonality with Root Ports and the need to also support AER and PME services for RCECs, extend the Root Port driver to support RCEC devices by adding the RCEC Class ID to the driver structure.
--- drivers/pci/pcie/portdrv_pci.c | 5 ++++- include/linux/pci_ids.h | 1 + include/uapi/linux/pci_regs.h | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-)
drivers/pci/pcie/portdrv_pci.c +4 -1
@@ -106,7 +106,8 @@ static int pcie_portdrv_probe(struct pciif (!pci_is_pcie (dev) || ((pci_pcie_type (dev) !=PCI_EXP_TYPE_ROOT_PORT ) && (pci_pcie_type (dev) !=PCI_EXP_TYPE_UPSTREAM ) && - (pci_pcie_type (dev) !=PCI_EXP_TYPE_DOWNSTREAM ))) + (pci_pcie_type (dev) !=PCI_EXP_TYPE_DOWNSTREAM ) && + (pci_pcie_type (dev) !=PCI_EXP_TYPE_RC_EC )))return -ENODEV ; status =pcie_port_device_register (dev);
@@ -195,6 +196,8 @@ static const struct pci_device_id port_p { PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0) },/* subtractive decode PCI-to-PCI bridge, class type is 060401h */ { PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x01), ~0) }, +/* handle any Root Complex Event Collector */ + { PCI_DEVICE_CLASS(((PCI_CLASS_SYSTEM_RCEC << 8) | 0x00), ~0) }, { }, };
include/linux/pci_ids.h +1 -0
@@ -83,6 +83,7 @@#define PCI_CLASS_SYSTEM_RTC 0x0803#define PCI_CLASS_SYSTEM_PCI_HOTPLUG 0x0804#define PCI_CLASS_SYSTEM_SDHCI 0x0805 +#define PCI_CLASS_SYSTEM_RCEC 0x0807#define PCI_CLASS_SYSTEM_OTHER 0x0880#define PCI_BASE_CLASS_INPUT 0x09
include/uapi/linux/pci_regs.h +7 -0
@@ -837,6 +837,13 @@#define PCI_PWR_CAP_BUDGET (x) ((x) & 1)/* Included in system budget */ #define PCI_EXT_CAP_PWR_SIZEOF 16 +/* Root Complex Event Collector Endpoint Association */ +#define PCI_RCEC_RCIEP_BITMAP 4/* Associated Bitmap for RCiEPs */ +#define PCI_RCEC_BUSN 8/* RCEC Associated Bus Numbers */ +#define PCI_RCEC_BUSN_REG_VER 0x02/* Least version with BUSN present */ +#define PCI_RCEC_BUSN_NEXT (x) (((x) >> 8) & 0xff) +#define PCI_RCEC_BUSN_LAST (x) (((x) >> 16) & 0xff) +/* Vendor-Specific (VSEC, PCI_EXT_CAP_ID_VNDR) */ #define PCI_VNDR_HEADER 4/* Vendor-Specific Header */ #define PCI_VNDR_HEADER_ID (x) ((x) & 0xffff)
Greg Kroah-Hartman
maintainerPATCH 475/545 PCI/ERR: Rename reset_link() to reset_subordinates()
In reply to Greg Kroah-HartmanFrom: Sean V Kelley <[email protected]>
[ Upstream commit 8f1bbfbc3596d401b60d1562b27ec28c2724f60d ]
reset_link() appears to be misnamed. The point is to reset any devices below a given bridge, so rename it to reset_subordinates() to make it clear that we are passing a bridge with the intent to reset the devices below it.
--- drivers/pci/pci.h | 4 ++-- drivers/pci/pcie/err.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/pci/pci.h +2 -2
@@ -559,8 +559,8 @@ static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev)/* PCI error reporting and recovery */ pci_ers_result_t pcie_do_recovery (struct pci_dev *dev, -pci_channel_state_t state, -pci_ers_result_t (*reset_link)(struct pci_dev *pdev)); +pci_channel_state_t state, +pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev));bool pcie_wait_for_link (struct pci_dev *pdev,bool active);#ifdef CONFIG_PCIEASPM
drivers/pci/pcie/err.c +4 -4
@@ -147,8 +147,8 @@ static int report_resume(struct pci_dev *dev, void *data) }pci_ers_result_t pcie_do_recovery (struct pci_dev *dev, -pci_channel_state_t state, -pci_ers_result_t (*reset_link)(struct pci_dev *pdev)) +pci_channel_state_t state, +pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev)) {pci_ers_result_t status =PCI_ERS_RESULT_CAN_RECOVER ;struct pci_bus *bus;
@@ -165,9 +165,9 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,pci_dbg (dev,"broadcast error_detected message\n" );if (state == pci_channel_io_frozen) {pci_walk_bus (bus, report_frozen_detected, &status); - status =reset_link (dev); + status =reset_subordinates (dev);if (status !=PCI_ERS_RESULT_RECOVERED ) { -pci_warn (dev,"link reset failed\n" ); +pci_warn (dev,"subordinate device reset failed\n" ); goto failed; } }else {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 476/545 PCI/ERR: Simplify by using pci_upstream_bridge()
In reply to Greg Kroah-HartmanFrom: Sean V Kelley <[email protected]>
[ Upstream commit 5d69dcc9f839bd2d5cac7a098712f52149e1673f ]
Use pci_upstream_bridge() in place of dev->bus->self. No functional change intended.
--- drivers/pci/pcie/err.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pcie/err.c +1 -1
@@ -159,7 +159,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,*/ if (!(pci_pcie_type (dev) ==PCI_EXP_TYPE_ROOT_PORT ||pci_pcie_type (dev) ==PCI_EXP_TYPE_DOWNSTREAM )) - dev = dev->bus->self; + dev =pci_upstream_bridge (dev); bus = dev->subordinate;pci_dbg (dev,"broadcast error_detected message\n" );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 477/545 PCI/ERR: Simplify by computing pci_pcie_type() once
In reply to Greg Kroah-HartmanFrom: Sean V Kelley <[email protected]>
[ Upstream commit 480ef7cb9fcebda7b28cbed4f6cdcf0a02f4a6ca ]
Instead of calling pci_pcie_type(dev) twice, call it once and save the result. No functional change intended.
--- drivers/pci/pcie/aer.c | 5 +++-- drivers/pci/pcie/err.c | 5 +++-- drivers/pci/pcie/portdrv_pci.c | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-)
drivers/pci/pcie/aer.c +3 -2
@@ -1039,6 +1039,7 @@ EXPORT_SYMBOL_GPL(aer_recover_queue);*/ int aer_get_device_error_info (struct pci_dev *dev,struct aer_err_info *info) { +int type =pci_pcie_type (dev);int aer = dev->aer_cap;int temp;
@@ -1057,8 +1058,8 @@ int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info) &info->mask);if (!(info->status & ~info->mask))return 0 ; - }else if (pci_pcie_type (dev) ==PCI_EXP_TYPE_ROOT_PORT || -pci_pcie_type (dev) ==PCI_EXP_TYPE_DOWNSTREAM || + }else if (type ==PCI_EXP_TYPE_ROOT_PORT || + type ==PCI_EXP_TYPE_DOWNSTREAM || info->severity ==AER_NONFATAL ) {/* Link is still healthy for IO reads */
drivers/pci/pcie/err.c +3 -2
@@ -150,6 +150,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,pci_channel_state_t state, pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev)) { + int type = pci_pcie_type(dev);pci_ers_result_t status =PCI_ERS_RESULT_CAN_RECOVER ;struct pci_bus *bus;
@@ -157,8 +158,8 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,* Error recovery runs on all subordinates of the first downstream port. * If the downstream port detected the error, it is cleared at the end. */ -if (!(pci_pcie_type (dev) ==PCI_EXP_TYPE_ROOT_PORT || -pci_pcie_type (dev) ==PCI_EXP_TYPE_DOWNSTREAM )) +if (!(type ==PCI_EXP_TYPE_ROOT_PORT || + type ==PCI_EXP_TYPE_DOWNSTREAM )) dev =pci_upstream_bridge (dev); bus = dev->subordinate;
drivers/pci/pcie/portdrv_pci.c +5 -4
@@ -101,13 +101,14 @@ static const struct dev_pm_ops pcie_portdrv_pm_ops = {static int pcie_portdrv_probe (struct pci_dev *dev,const struct pci_device_id *id) { +int type =pci_pcie_type (dev);int status;if (!pci_is_pcie (dev) || - ((pci_pcie_type (dev) !=PCI_EXP_TYPE_ROOT_PORT ) && - (pci_pcie_type (dev) !=PCI_EXP_TYPE_UPSTREAM ) && - (pci_pcie_type (dev) !=PCI_EXP_TYPE_DOWNSTREAM ) && - (pci_pcie_type (dev) !=PCI_EXP_TYPE_RC_EC ))) + ((type !=PCI_EXP_TYPE_ROOT_PORT ) && + (type !=PCI_EXP_TYPE_UPSTREAM ) && + (type !=PCI_EXP_TYPE_DOWNSTREAM ) && + (type !=PCI_EXP_TYPE_RC_EC )))return -ENODEV ; status =pcie_port_device_register (dev);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 478/545 PCI/ERR: Use "bridge" for clarity in pcie_do_recovery()
In reply to Greg Kroah-HartmanFrom: Sean V Kelley <[email protected]>
[ Upstream commit 0791721d800790e6e533bd8467df67f0dc4f2fec ]
pcie_do_recovery() may be called with "dev" being either a bridge (Root Port or Switch Downstream Port) or an Endpoint. The bulk of the function deals with the bridge, so if we start with an Endpoint, we reset "dev" to be the bridge leading to it.
For clarity, replace "dev" in the body of the function with "bridge". No functional change intended.
--- drivers/pci/pcie/err.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-)
drivers/pci/pcie/err.c +20 -17
@@ -151,24 +151,27 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev)) {int type =pci_pcie_type (dev); -pci_ers_result_t status =PCI_ERS_RESULT_CAN_RECOVER ; +struct pci_dev *bridge;struct pci_bus *bus; +pci_ers_result_t status =PCI_ERS_RESULT_CAN_RECOVER ;/* -* Error recovery runs on all subordinates of the first downstream port. -* If the downstream port detected the error, it is cleared at the end. +* Error recovery runs on all subordinates of the bridge. If the +* bridge detected the error, it is cleared at the end. */ if (!(type ==PCI_EXP_TYPE_ROOT_PORT || type ==PCI_EXP_TYPE_DOWNSTREAM )) - dev =pci_upstream_bridge (dev); - bus = dev->subordinate; + bridge =pci_upstream_bridge (dev); +else + bridge = dev; -pci_dbg (dev,"broadcast error_detected message\n" ); + bus = bridge->subordinate; +pci_dbg (bridge,"broadcast error_detected message\n" );if (state == pci_channel_io_frozen) {pci_walk_bus (bus, report_frozen_detected, &status); - status =reset_subordinates (dev); + status =reset_subordinates (bridge);if (status !=PCI_ERS_RESULT_RECOVERED ) { -pci_warn (dev,"subordinate device reset failed\n" ); +pci_warn (bridge,"subordinate device reset failed\n" ); goto failed; } }else {
@@ -177,7 +180,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,if (status ==PCI_ERS_RESULT_CAN_RECOVER ) { status =PCI_ERS_RESULT_RECOVERED ; -pci_dbg (dev,"broadcast mmio_enabled message\n" ); +pci_dbg (bridge,"broadcast mmio_enabled message\n" );pci_walk_bus (bus, report_mmio_enabled, &status); }
@@ -188,27 +191,27 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,* drivers' slot_reset callbacks? */ status =PCI_ERS_RESULT_RECOVERED ; -pci_dbg (dev,"broadcast slot_reset message\n" ); +pci_dbg (bridge,"broadcast slot_reset message\n" );pci_walk_bus (bus, report_slot_reset, &status); }if (status !=PCI_ERS_RESULT_RECOVERED ) goto failed; -pci_dbg (dev,"broadcast resume message\n" ); +pci_dbg (bridge,"broadcast resume message\n" );pci_walk_bus (bus, report_resume, &status); -if (pcie_aer_is_native (dev)) -pcie_clear_device_status (dev); -pci_aer_clear_nonfatal_status (dev); -pci_info (dev,"device recovery successful\n" ); +if (pcie_aer_is_native (bridge)) +pcie_clear_device_status (bridge); +pci_aer_clear_nonfatal_status (bridge); +pci_info (bridge,"device recovery successful\n" );return status; failed: -pci_uevent_ers (dev,PCI_ERS_RESULT_DISCONNECT ); +pci_uevent_ers (bridge,PCI_ERS_RESULT_DISCONNECT );/* TODO: Should kernel panic here? */ -pci_info (dev,"device recovery failed\n" ); +pci_info (bridge,"device recovery failed\n" );return status; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 479/545 PCI/ERR: Avoid negated conditional for clarity
In reply to Greg Kroah-HartmanFrom: Sean V Kelley <[email protected]>
[ Upstream commit 3d7d8fc78f4b504819882278fcfe10784eb985fa ]
Reverse the sense of the Root Port/Downstream Port conditional for clarity. No functional change intended.
--- drivers/pci/pcie/err.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pci/pcie/err.c +4 -4
@@ -159,11 +159,11 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,* Error recovery runs on all subordinates of the bridge. If the * bridge detected the error, it is cleared at the end. */ -if (!(type ==PCI_EXP_TYPE_ROOT_PORT || - type ==PCI_EXP_TYPE_DOWNSTREAM )) - bridge =pci_upstream_bridge (dev); -else +if (type ==PCI_EXP_TYPE_ROOT_PORT || + type ==PCI_EXP_TYPE_DOWNSTREAM ) bridge = dev; +else + bridge =pci_upstream_bridge (dev); bus = bridge->subordinate;pci_dbg (bridge,"broadcast error_detected message\n" );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 480/545 PCI/ERR: Add pci_walk_bridge() to pcie_do_recovery()
In reply to Greg Kroah-HartmanFrom: Sean V Kelley <[email protected]>
[ Upstream commit 05e9ae19ab83881a0f33025bd1288e41e552a34b ]
Consolidate subordinate bus checks with pci_walk_bus() into pci_walk_bridge() for walking below potentially AER affected bridges.
--- drivers/pci/pcie/err.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)
drivers/pci/pcie/err.c +23 -7
@@ -146,13 +146,30 @@ static int report_resume(struct pci_dev *dev, void *data)return 0 ; } +/** +* pci_walk_bridge - walk bridges potentially AER affected +* @bridge: bridge which may be a Port +* @cb: callback to be called for each device found +* @userdata: arbitrary pointer to be passed to callback +* +* If the device provided is a bridge, walk the subordinate bus, including +* any bridged devices on buses under this bus. Call the provided callback +* on each device found. +*/ +static void pci_walk_bridge (struct pci_dev *bridge, +int (*cb)(struct pci_dev *,void *), +void *userdata) +{ +if (bridge->subordinate) +pci_walk_bus (bridge->subordinate, cb, userdata); +} +pci_ers_result_t pcie_do_recovery (struct pci_dev *dev,pci_channel_state_t state,pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev)) {int type =pci_pcie_type (dev);struct pci_dev *bridge; -struct pci_bus *bus;pci_ers_result_t status =PCI_ERS_RESULT_CAN_RECOVER ;/*
@@ -165,23 +182,22 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,else bridge =pci_upstream_bridge (dev); - bus = bridge->subordinate;pci_dbg (bridge,"broadcast error_detected message\n" );if (state == pci_channel_io_frozen) { -pci_walk_bus (bus, report_frozen_detected, &status); +pci_walk_bridge (bridge, report_frozen_detected, &status); status =reset_subordinates (bridge);if (status !=PCI_ERS_RESULT_RECOVERED ) {pci_warn (bridge,"subordinate device reset failed\n" ); goto failed; } }else { -pci_walk_bus (bus, report_normal_detected, &status); +pci_walk_bridge (bridge, report_normal_detected, &status); }if (status ==PCI_ERS_RESULT_CAN_RECOVER ) { status =PCI_ERS_RESULT_RECOVERED ;pci_dbg (bridge,"broadcast mmio_enabled message\n" ); -pci_walk_bus (bus, report_mmio_enabled, &status); +pci_walk_bridge (bridge, report_mmio_enabled, &status); }if (status ==PCI_ERS_RESULT_NEED_RESET ) {
@@ -192,14 +208,14 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,*/ status =PCI_ERS_RESULT_RECOVERED ;pci_dbg (bridge,"broadcast slot_reset message\n" ); -pci_walk_bus (bus, report_slot_reset, &status); +pci_walk_bridge (bridge, report_slot_reset, &status); }if (status !=PCI_ERS_RESULT_RECOVERED ) goto failed;pci_dbg (bridge,"broadcast resume message\n" ); -pci_walk_bus (bus, report_resume, &status); +pci_walk_bridge (bridge, report_resume, &status);if (pcie_aer_is_native (bridge))pcie_clear_device_status (bridge);
Signature · 1 line
2.35.1
Dominique Martinet
Tested-by Hedi Berriche Acked-by Sean V Kelley Acked-by Hedi Berriche on v1 480/545Re: [PATCH 5.10 480/545] PCI/ERR: Add pci_walk_bridge() to pcie_do_recovery()
Greg Kroah-Hartman wrote on Fri, Aug 19, 2022 at 05:44:10PM +0200:
Quoted 25 lines
From: Sean V Kelley <[email protected]>
[ Upstream commit
05e9ae19ab83881a0f33025bd1288e41e552a34b]Consolidate subordinate bus checks with
pci_walk_bus()intopci_walk_bridge()for walking below potentially AER affected bridges.Signed-off-by Sean V Kelley <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- drivers/pci/pcie/err.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)drivers/pci/pcie/err.c +0
-0@@ -165,23 +182,22 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,else bridge =pci_upstream_bridge (dev);
drivers/pci/pcie/err.c pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, · line 192
Quoted 10 lines
drivers/pci/pcie/err.c +1
-2- bus = bridge->subordinate;pci_dbg (bridge,"broadcast error_detected message\n" );if (state == pci_channel_io_frozen) { -pci_walk_bus (bus, report_frozen_detected, &status); +pci_walk_bridge (bridge, report_frozen_detected, &status); status =reset_subordinates (bridge);if (status !=PCI_ERS_RESULT_RECOVERED ) {pci_warn (bridge,"subordinate device reset failed\n" ); goto failed; }
A local conflict merging this made me notice a later commit:
-----
commit 387c72cdd7fb6bef650fb078d0f6ae9682abf631
Author: Keith Busch <[email protected]> Date: Mon Jan 4 15:02:58 2021 -0800
PCI/ERR: Retain status from error notification
Overwriting the frozen detected status with the result of the link reset loses the NEED_RESET result that drivers are depending on for error handling to report the .slot_reset() callback. Retain this status so that subsequent error handling has the correct flow.
drivers/pci/pcie/err.c +1 -2
@@ -198,8 +198,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,pci_dbg (bridge,"broadcast error_detected message\n" );if (state == pci_channel_io_frozen) {pci_walk_bridge (bridge, report_frozen_detected, &status); - status =reset_subordinates (bridge); -if (status !=PCI_ERS_RESULT_RECOVERED ) { +if (reset_subordinates (bridge) !=PCI_ERS_RESULT_RECOVERED ) {pci_warn (bridge,"subordinate device reset failed\n" ); goto failed; }
-----
Since this (commit I reply to) has been picked up, I think it'd make sense to also include this (commit I just listed) in a later 5.10 tag. It cherry-picks without error but would you like me to resend? (I have added in Cc all involved people to this mail)
Digging through the mails the patch came with seem to imply approval for stable merges; but it didn't make sense until pci_walk_bridge() had been added just now. Now it's here we probably want both:
https://lore.kernel.org/all/[email protected]/
(I noticed because the NXP kernel we are provided includes a different "fix" for what I believe to be the same issue, previously discussed here:
https://lore.kernel.org/linux-pci/12115.1588207324@famine/
I haven't actually encountered any of the problems discribed, so this is purely theorical for me; it just looks a bit weird.)
Thanks,
--
Dominique
Re: [PATCH 5.10 480/545] PCI/ERR: Add pci_walk_bridge() to pcie_do_recovery()
Quoted 85 lines · Dominique Martinet
Greg Kroah-Hartman wrote on Fri, Aug 19, 2022 at 05:44:10PM +0200:
Quoted 25 lines
From: Sean V Kelley <[email protected]>
[ Upstream commit
05e9ae19ab83881a0f33025bd1288e41e552a34b]Consolidate subordinate bus checks with
pci_walk_bus()intopci_walk_bridge()for walking below potentially AER affected bridges.Signed-off-by Sean V Kelley <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- drivers/pci/pcie/err.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)drivers/pci/pcie/err.c +0
-0@@ -165,23 +182,22 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,else bridge =pci_upstream_bridge (dev);drivers/pci/pcie/err.c pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, · line 192
Quoted 10 lines
drivers/pci/pcie/err.c +1
-2- bus = bridge->subordinate;pci_dbg (bridge,"broadcast error_detected message\n" );if (state == pci_channel_io_frozen) { -pci_walk_bus (bus, report_frozen_detected, &status); +pci_walk_bridge (bridge, report_frozen_detected, &status); status =reset_subordinates (bridge);if (status !=PCI_ERS_RESULT_RECOVERED ) {pci_warn (bridge,"subordinate device reset failed\n" ); goto failed; }A local conflict merging this made me notice a later commit:
-----
commit387c72cdd7fb6bef650fb078d0f6ae9682abf631Author: Keith Busch <[email protected]> Date: Mon Jan 4 15:02:58 2021 -0800PCI/ERR: Retain status from error notification
Overwriting the frozen detected status with the result of the link reset loses the
NEED_RESETresult that drivers are depending on for error handling to report the .slot_reset() callback. Retain this status so that subsequent error handling has the correct flow.Reported-by Hinko Kocevar <[email protected]>Tested-by Hedi Berriche <[email protected]>Signed-off-by Keith Busch <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>Acked-by Sean V Kelley <[email protected]>Acked-by Hedi Berriche <[email protected]>drivers/pci/pcie/err.c +1
-3@@ -198,8 +198,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,pci_dbg (bridge,"broadcast error_detected message\n" );if (state == pci_channel_io_frozen) {pci_walk_bridge (bridge, report_frozen_detected, &status); - status =reset_subordinates (bridge); -if (status !=PCI_ERS_RESULT_RECOVERED ) { +if (reset_subordinates (bridge) !=PCI_ERS_RESULT_RECOVERED ) {pci_warn (bridge,"subordinate device reset failed\n" ); goto failed; } -----Since this (commit I reply to) has been picked up, I think it'd make sense to also include this (commit I just listed) in a later 5.10 tag. It cherry-picks without error but would you like me to resend? (I have added in Cc all involved people to this mail)
Digging through the mails the patch came with seem to imply approval for stable merges; but it didn't make sense until
pci_walk_bridge()had been added just now. Now it's here we probably want both:
https://lore.kernel.org/all/[email protected]/
Quoted 6 lines
(I noticed because the NXP kernel we are provided includes a different "fix" for what I believe to be the same issue, previously discussed here:
https://lore.kernel.org/linux-pci/12115.1588207324@famine/I haven't actually encountered any of the problems discribed, so this is purely theorical for me; it just looks a bit weird.)
I've queued up the commit you referenced above now, thanks!
greg k-h
Greg Kroah-Hartman
maintainerPATCH 481/545 PCI/ERR: Recover from RCEC AER errors
In reply to Greg Kroah-HartmanFrom: Sean V Kelley <[email protected]>
[ Upstream commit a175102b0a82fc57853a9e611c42d1d6172e5180 ]
A Root Complex Event Collector (RCEC) collects and signals AER errors that were detected by Root Complex Integrated Endpoints (RCiEPs), but it may also signal errors it detects itself. This is analogous to errors detected and signaled by a Root Port.
Update the AER service driver to claim RCECs in addition to Root Ports. Add support for handling RCEC-detected AER errors. This does not include handling RCiEP-detected errors that are signaled by the RCEC.
Note that we expect these errors only from the native AER and APEI paths, not from DPC or EDR.
--- drivers/pci/pcie/aer.c | 58 +++++++++++++++++++++++++++++------------- drivers/pci/pcie/err.c | 19 +++++++++++--- 2 files changed, 56 insertions(+), 21 deletions(-)
drivers/pci/pcie/aer.c +41 -17
@@ -305,7 +305,8 @@ int pci_aer_raw_clear_status(struct pci_dev *dev)return -EIO ; port_type =pci_pcie_type (dev); -if (port_type ==PCI_EXP_TYPE_ROOT_PORT ) { +if (port_type ==PCI_EXP_TYPE_ROOT_PORT || + port_type ==PCI_EXP_TYPE_RC_EC ) {pci_read_config_dword (dev, aer +PCI_ERR_ROOT_STATUS , &status);pci_write_config_dword (dev, aer +PCI_ERR_ROOT_STATUS , status); }
@@ -600,7 +601,8 @@ static umode_t aer_stats_attrs_are_visible(struct kobject *kobj,if ((a == &dev_attr_aer_rootport_total_err_cor.attr || a == &dev_attr_aer_rootport_total_err_fatal.attr || a == &dev_attr_aer_rootport_total_err_nonfatal.attr) && -pci_pcie_type (pdev) !=PCI_EXP_TYPE_ROOT_PORT ) + ((pci_pcie_type (pdev) !=PCI_EXP_TYPE_ROOT_PORT ) && + (pci_pcie_type (pdev) !=PCI_EXP_TYPE_RC_EC )))return 0 ;return a->mode;
@@ -1211,6 +1213,7 @@ static int set_device_error_reporting(struct pci_dev *dev, void *data)int type =pci_pcie_type (dev);if ((type ==PCI_EXP_TYPE_ROOT_PORT ) || + (type ==PCI_EXP_TYPE_RC_EC ) || (type ==PCI_EXP_TYPE_UPSTREAM ) || (type ==PCI_EXP_TYPE_DOWNSTREAM )) {if (enable)
@@ -1335,6 +1338,11 @@ static int aer_probe(struct pcie_device *dev)struct device *device = &dev->device;struct pci_dev *port = dev->port; +/* Limit to Root Ports or Root Complex Event Collectors */ +if ((pci_pcie_type (port) !=PCI_EXP_TYPE_RC_EC ) && + (pci_pcie_type (port) !=PCI_EXP_TYPE_ROOT_PORT )) +return -ENODEV ; + rpc =devm_kzalloc (device,sizeof (struct aer_rpc ),GFP_KERNEL );if (!rpc)return -ENOMEM ;
@@ -1356,36 +1364,52 @@ static int aer_probe(struct pcie_device *dev) }/** -* aer_root_reset - reset link on Root Port -* @dev: pointer to Root Port's pci_dev data structure +* aer_root_reset - reset Root Port hierarchy or RCEC +* @dev: pointer to Root Port or RCEC * -* Invoked by Port Bus driver when performing link reset at Root Port. +* Invoked by Port Bus driver when performing reset. */ static pci_ers_result_t aer_root_reset (struct pci_dev *dev) { -int aer = dev->aer_cap; +int type =pci_pcie_type (dev); +struct pci_dev *root; +int aer; +struct pci_host_bridge *host =pci_find_host_bridge (dev->bus);u32 reg32;int rc; -if (pcie_aer_is_native (dev)) { + root = dev;/* device with Root Error registers */ + aer = root->aer_cap; + +if ((host->native_aer || pcie_ports_native) && aer) {/* Disable Root's interrupt in response to error messages */ -pci_read_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , ®32); +pci_read_config_dword (root, aer +PCI_ERR_ROOT_COMMAND , ®32); reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK ; -pci_write_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , reg32); +pci_write_config_dword (root, aer +PCI_ERR_ROOT_COMMAND , reg32); } - rc =pci_bus_error_reset (dev); -pci_info (dev,"Root Port link has been reset (%d)\n" , rc); +if (type ==PCI_EXP_TYPE_RC_EC ) { +if (pcie_has_flr (dev)) { + rc =pcie_flr (dev); +pci_info (dev,"has been reset (%d)\n" , rc); + }else { +pci_info (dev,"not reset (no FLR support)\n" ); + rc = -ENOTTY ; + } + }else { + rc =pci_bus_error_reset (dev); +pci_info (dev,"Root Port link has been reset (%d)\n" , rc); + } -if (pcie_aer_is_native (dev)) { +if ((host->native_aer || pcie_ports_native) && aer) {/* Clear Root Error Status */ -pci_read_config_dword (dev, aer +PCI_ERR_ROOT_STATUS , ®32); -pci_write_config_dword (dev, aer +PCI_ERR_ROOT_STATUS , reg32); +pci_read_config_dword (root, aer +PCI_ERR_ROOT_STATUS , ®32); +pci_write_config_dword (root, aer +PCI_ERR_ROOT_STATUS , reg32);/* Enable Root Port's interrupt in response to error messages */ -pci_read_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , ®32); +pci_read_config_dword (root, aer +PCI_ERR_ROOT_COMMAND , ®32); reg32 |=ROOT_PORT_INTR_ON_MESG_MASK ; -pci_write_config_dword (dev, aer +PCI_ERR_ROOT_COMMAND , reg32); +pci_write_config_dword (root, aer +PCI_ERR_ROOT_COMMAND , reg32); }return rc ?PCI_ERS_RESULT_DISCONNECT :PCI_ERS_RESULT_RECOVERED ;
@@ -1393,7 +1417,7 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev)static struct pcie_port_service_driver aerdriver = { .name ="aer" , - .port_type =PCI_EXP_TYPE_ROOT_PORT , + .port_type =PCIE_ANY_PORT , .service =PCIE_PORT_SERVICE_AER , .probe = aer_probe,
drivers/pci/pcie/err.c +15 -4
@@ -148,13 +148,16 @@ static int report_resume(struct pci_dev *dev, void *data)/** * pci_walk_bridge - walk bridges potentially AER affected -* @bridge: bridge which may be a Port +* @bridge: bridge which may be a Port or an RCEC * @cb: callback to be called for each device found * @userdata: arbitrary pointer to be passed to callback * * If the device provided is a bridge, walk the subordinate bus, including * any bridged devices on buses under this bus. Call the provided callback * on each device found. +* +* If the device provided has no subordinate bus, e.g., an RCEC, call the +* callback on the device itself. */ static void pci_walk_bridge(struct pci_dev *bridge, int (*cb)(struct pci_dev *, void *),
@@ -162,6 +165,8 @@ static void pci_walk_bridge(struct pci_dev *bridge, {if (bridge->subordinate)pci_walk_bus (bridge->subordinate, cb, userdata); +else +cb (bridge, userdata); } pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
@@ -173,11 +178,17 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,pci_ers_result_t status =PCI_ERS_RESULT_CAN_RECOVER ;/* -* Error recovery runs on all subordinates of the bridge. If the -* bridge detected the error, it is cleared at the end. +* If the error was detected by a Root Port, Downstream Port, or +* RCEC, recovery runs on the device itself. For Ports, that also +* includes any subordinate devices. +* +* If it was detected by another device (Endpoint, etc), recovery +* runs on the device and anything else under the same Port, i.e., +* everything under "bridge". */ if (type ==PCI_EXP_TYPE_ROOT_PORT || - type ==PCI_EXP_TYPE_DOWNSTREAM ) + type ==PCI_EXP_TYPE_DOWNSTREAM || + type ==PCI_EXP_TYPE_RC_EC ) bridge = dev;else bridge =pci_upstream_bridge (dev);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 482/545 PCI/AER: Iterate over error counters instead of error strings
In reply to Greg Kroah-HartmanFrom: Mohamed Khalfella <[email protected]>
[ Upstream commit 5e6ae050955b566484f3cc6a66e3925eae87a0ed ]
Previously we iterated over AER stat *names*, e.g., aer_correctable_error_string[32], but the actual stat *counters* may not be that large, e.g., pdev->aer_stats->dev_cor_errs[16], which means that we printed junk in the sysfs stats files.
Iterate over the stat counter arrays instead of the names to avoid this junk.
Also, added a build time check to make sure all
counters have entries in strings array.
--- drivers/pci/pcie/aer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/pci/pcie/aer.c +6 -1
@@ -538,7 +538,7 @@ static const char *aer_agent_string[] = {struct pci_dev *pdev =to_pci_dev (dev); \u64 *stats = pdev->aer_stats->stats_array; \ \ -for (i =0 ; i <ARRAY_SIZE (strings_array); i++) { \ +for (i =0 ; i <ARRAY_SIZE (pdev->aer_stats->stats_array); i++) {\if (strings_array[i]) \ str +=sprintf (str,"%s %llu\n" , \ strings_array[i], stats[i]); \
@@ -1338,6 +1338,11 @@ static int aer_probe(struct pcie_device *dev)struct device *device = &dev->device;struct pci_dev *port = dev->port; +BUILD_BUG_ON (ARRAY_SIZE (aer_correctable_error_string) < +AER_MAX_TYPEOF_COR_ERRS ); +BUILD_BUG_ON (ARRAY_SIZE (aer_uncorrectable_error_string) < +AER_MAX_TYPEOF_UNCOR_ERRS ); +/* Limit to Root Ports or Root Complex Event Collectors */ if ((pci_pcie_type (port) !=PCI_EXP_TYPE_RC_EC ) && (pci_pcie_type (port) !=PCI_EXP_TYPE_ROOT_PORT ))
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 483/545 serial: 8250: Dissociate 4MHz Titan ports from Oxford ports
In reply to Greg Kroah-HartmanFrom: Maciej W. Rozycki <[email protected]>
[ Upstream commit f771a34b141124a68265f91acae34cdb08aeb9e0 ]
Oxford Semiconductor PCIe (Tornado) serial port devices have their baud base set incorrectly, however their `pciserial_board' entries have been reused for Titan serial port devices. Define own entries for the latter devices then, carrying over the settings, so that Oxford entries can be fixed.
--- drivers/tty/serial/8250/8250_pci.c | 44 ++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-)
drivers/tty/serial/8250/8250_pci.c +38 -6
@@ -2983,6 +2983,10 @@ enum pci_board_num_t { pbn_sunix_pci_4s, pbn_sunix_pci_8s, pbn_sunix_pci_16s, + pbn_titan_1_4000000, + pbn_titan_2_4000000, + pbn_titan_4_4000000, + pbn_titan_8_4000000, pbn_moxa8250_2p, pbn_moxa8250_4p, pbn_moxa8250_8p,
@@ -3770,6 +3774,34 @@ static struct pciserial_board pci_boards[] = { .base_baud = 921600, .uart_offset = 0x8, }, + [pbn_titan_1_4000000] = { + .flags = FL_BASE0, + .num_ports = 1, + .base_baud = 4000000, + .uart_offset = 0x200, + .first_offset = 0x1000, + }, + [pbn_titan_2_4000000] = { + .flags = FL_BASE0, + .num_ports = 2, + .base_baud = 4000000, + .uart_offset = 0x200, + .first_offset = 0x1000, + }, + [pbn_titan_4_4000000] = { + .flags = FL_BASE0, + .num_ports = 4, + .base_baud = 4000000, + .uart_offset = 0x200, + .first_offset = 0x1000, + }, + [pbn_titan_8_4000000] = { + .flags = FL_BASE0, + .num_ports = 8, + .base_baud = 4000000, + .uart_offset = 0x200, + .first_offset = 0x1000, + }, [pbn_moxa8250_2p] = { .flags = FL_BASE1, .num_ports = 2,
@@ -4721,22 +4753,22 @@ static const struct pci_device_id serial_pci_tbl[] = { pbn_b0_4_921600 }, {PCI_VENDOR_ID_TITAN ,PCI_DEVICE_ID_TITAN_100E ,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_titan_1_4000000 }, { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200E,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_2_4000000 }, + pbn_titan_2_4000000 }, { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400E,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_4_4000000 }, + pbn_titan_4_4000000 }, { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800E,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_8_4000000 }, + pbn_titan_8_4000000 }, { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200EI,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_2_4000000 }, + pbn_titan_2_4000000 }, { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200EISI,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_2_4000000 }, + pbn_titan_2_4000000 }, { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200V3,PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , pbn_b0_bt_2_921600 },
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 484/545 serial: 8250: Correct the clock for OxSemi PCIe devices
In reply to Greg Kroah-HartmanFrom: Maciej W. Rozycki <[email protected]>
[ Upstream commit 6cbe45d8ac9316ceedd0749759bd54caf03f7012 ]
Oxford Semiconductor PCIe (Tornado) serial port devices are driven by a fixed 62.5MHz clock input derived from the 100MHz PCI Express clock.
In the enhanced (650) mode, which we select in `autoconfig_has_efr' by setting the ECB bit in the EFR register, and in the absence of clock reconfiguration, which we currently don't do, the clock rate is divided only by the oversampling rate of 16 as it is supplied to the baud rate generator, yielding the baud base of 3906250. This comes from the reset values of the TCR and MCR[7] registers which are both zero[1][2][3][4], choosing the oversampling rate of 16 and the normal (divide by 1) baud rate generator prescaler respectively. This is the rate that is divided by the value held in the divisor latch to determine the baud rate used.
Replace the incorrect baud base of 4000000 with the right value of 3906250 then.
[1] "OXPCIe200 PCI Express Multi-Port Bridge", Oxford Semiconductor,
Inc., DS-0045, 10 Nov 2008, Section "Reset Configuration", p. 72
[2] "OXPCIe952 PCI Express Bridge to Dual Serial & Parallel Port", Oxford Semiconductor, Inc., DS-0046, Mar 06 08, Section "Reset Configuration", p. 27
[3] "OXPCIe954 PCI Express Bridge to Quad Serial Port", Oxford Semiconductor, Inc., DS-0047, Feb 08, Section "Reset Configuration", p. 28
[4] "OXPCIe958 PCI Express Bridge to Octal Serial Port", Oxford Semiconductor, Inc., DS-0048, Feb 08, Section "Reset Configuration", p. 28
--- drivers/tty/serial/8250/8250_pci.c | 128 ++++++++++++++--------------- 1 file changed, 64 insertions(+), 64 deletions(-)
drivers/tty/serial/8250/8250_pci.c +64 -64
@@ -2862,7 +2862,7 @@ enum pci_board_num_t { pbn_b0_2_1843200, pbn_b0_4_1843200, - pbn_b0_1_4000000, + pbn_b0_1_3906250, pbn_b0_bt_1_115200, pbn_b0_bt_2_115200,
@@ -2942,10 +2942,10 @@ enum pci_board_num_t { pbn_plx_romulus, pbn_endrun_2_3906250, pbn_oxsemi, - pbn_oxsemi_1_4000000, - pbn_oxsemi_2_4000000, - pbn_oxsemi_4_4000000, - pbn_oxsemi_8_4000000, + pbn_oxsemi_1_3906250, + pbn_oxsemi_2_3906250, + pbn_oxsemi_4_3906250, + pbn_oxsemi_8_3906250, pbn_intel_i960, pbn_sgi_ioc3, pbn_computone_4,
@@ -3092,10 +3092,10 @@ static struct pciserial_board pci_boards[] = { .uart_offset = 8, }, - [pbn_b0_1_4000000] = { + [pbn_b0_1_3906250] = { .flags = FL_BASE0, .num_ports = 1, - .base_baud = 4000000, + .base_baud = 3906250, .uart_offset = 8, },
@@ -3490,31 +3490,31 @@ static struct pciserial_board pci_boards[] = { .base_baud = 115200, .uart_offset = 8, }, - [pbn_oxsemi_1_4000000] = { + [pbn_oxsemi_1_3906250] = { .flags = FL_BASE0, .num_ports = 1, - .base_baud = 4000000, + .base_baud = 3906250, .uart_offset = 0x200, .first_offset = 0x1000, }, - [pbn_oxsemi_2_4000000] = { + [pbn_oxsemi_2_3906250] = { .flags = FL_BASE0, .num_ports = 2, - .base_baud = 4000000, + .base_baud = 3906250, .uart_offset = 0x200, .first_offset = 0x1000, }, - [pbn_oxsemi_4_4000000] = { + [pbn_oxsemi_4_3906250] = { .flags = FL_BASE0, .num_ports = 4, - .base_baud = 4000000, + .base_baud = 3906250, .uart_offset = 0x200, .first_offset = 0x1000, }, - [pbn_oxsemi_8_4000000] = { + [pbn_oxsemi_8_3906250] = { .flags = FL_BASE0, .num_ports = 8, - .base_baud = 4000000, + .base_baud = 3906250, .uart_offset = 0x200, .first_offset = 0x1000, },
@@ -4528,158 +4528,158 @@ static const struct pci_device_id serial_pci_tbl[] = {*/ {PCI_VENDOR_ID_OXSEMI ,0xc101 ,/* OXPCIe952 1 Legacy UART */ PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_b0_1_4000000 }, + pbn_b0_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc105, /* OXPCIe952 1 Legacy UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_b0_1_4000000 }, + pbn_b0_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc11b, /* OXPCIe952 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc11f, /* OXPCIe952 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc120, /* OXPCIe952 1 Legacy UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_b0_1_4000000 }, + pbn_b0_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc124, /* OXPCIe952 1 Legacy UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_b0_1_4000000 }, + pbn_b0_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc138, /* OXPCIe952 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc13d, /* OXPCIe952 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc140, /* OXPCIe952 1 Legacy UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_b0_1_4000000 }, + pbn_b0_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc141, /* OXPCIe952 1 Legacy UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_b0_1_4000000 }, + pbn_b0_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc144, /* OXPCIe952 1 Legacy UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_b0_1_4000000 }, + pbn_b0_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc145, /* OXPCIe952 1 Legacy UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_b0_1_4000000 }, + pbn_b0_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc158, /* OXPCIe952 2 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_2_4000000 }, + pbn_oxsemi_2_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc15d, /* OXPCIe952 2 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_2_4000000 }, + pbn_oxsemi_2_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc208, /* OXPCIe954 4 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_4_4000000 }, + pbn_oxsemi_4_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc20d, /* OXPCIe954 4 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_4_4000000 }, + pbn_oxsemi_4_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc308, /* OXPCIe958 8 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_8_4000000 }, + pbn_oxsemi_8_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc30d, /* OXPCIe958 8 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_8_4000000 }, + pbn_oxsemi_8_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc40b, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc40f, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc41b, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc41f, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc42b, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc42f, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc43b, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc43f, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc44b, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc44f, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc45b, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc45f, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc46b, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc46f, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc47b, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc47f, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc48b, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc48f, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc49b, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc49f, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc4ab, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc4af, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc4bb, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc4bf, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc4cb, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_OXSEMI, 0xc4cf, /* OXPCIe200 1 Native UART */PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 },/* * Mainpine Inc. IQ Express "Rev3" utilizing OxSemi Tornado */ { PCI_VENDOR_ID_MAINPINE, 0x4000, /* IQ Express 1 Port V.34 Super-G3 Fax */PCI_VENDOR_ID_MAINPINE ,0x4001 ,0 ,0 , - pbn_oxsemi_1_4000000 }, + pbn_oxsemi_1_3906250 }, { PCI_VENDOR_ID_MAINPINE, 0x4000, /* IQ Express 2 Port V.34 Super-G3 Fax */PCI_VENDOR_ID_MAINPINE ,0x4002 ,0 ,0 , - pbn_oxsemi_2_4000000 }, + pbn_oxsemi_2_3906250 }, { PCI_VENDOR_ID_MAINPINE, 0x4000, /* IQ Express 4 Port V.34 Super-G3 Fax */PCI_VENDOR_ID_MAINPINE ,0x4004 ,0 ,0 , - pbn_oxsemi_4_4000000 }, + pbn_oxsemi_4_3906250 }, { PCI_VENDOR_ID_MAINPINE, 0x4000, /* IQ Express 8 Port V.34 Super-G3 Fax */PCI_VENDOR_ID_MAINPINE ,0x4008 ,0 ,0 , - pbn_oxsemi_8_4000000 }, + pbn_oxsemi_8_3906250 },/* * Digi/IBM PCIe 2-port Async EIA-232 Adapter utilizing OxSemi Tornado */ { PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_2_OX_IBM,PCI_SUBVENDOR_ID_IBM ,PCI_ANY_ID ,0 ,0 , - pbn_oxsemi_2_4000000 }, + pbn_oxsemi_2_3906250 },/* * SBS Technologies, Inc. P-Octal and PMC-OCTPRO cards,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 485/545 serial: 8250_pci: Refactor the loop in pci_ite887x_init()
In reply to Greg Kroah-HartmanFrom: Andy Shevchenko <[email protected]>
[ Upstream commit 35b4f17231923e2f64521bdf7a2793ce2c3c74a6 ]
The loop can be refactored by using ARRAY_SIZE() instead of NULL terminator. This reduces code base and makes it easier to read and understand.
--- drivers/tty/serial/8250/8250_pci.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/tty/serial/8250/8250_pci.c +4 -8
@@ -897,18 +897,16 @@ static int pci_netmos_init(struct pci_dev *dev)/* enable IO_Space bit */ #define ITE_887x_POSIO_ENABLE (1 << 31) +/* inta_addr are the configuration addresses of the ITE */ +static const short inta_addr[] = {0x2a0 ,0x2c0 ,0x220 ,0x240 ,0x1e0 ,0x200 ,0x280 };static int pci_ite887x_init (struct pci_dev *dev) { -/* inta_addr are the configuration addresses of the ITE */ -static const short inta_addr[] = {0x2a0 ,0x2c0 ,0x220 ,0x240 ,0x1e0 , -0x200 ,0x280 ,0 };int ret, i, type;struct resource *iobase =NULL ;u32 miscr, uartbar, ioport;/* search for the base-ioport */ - i =0 ; -while (inta_addr[i] && iobase ==NULL ) { +for (i =0 ; i <ARRAY_SIZE (inta_addr); i++) { iobase =request_region (inta_addr[i], ITE_887x_IOSIZE,"ite887x" );if (iobase !=NULL ) {
@@ -925,12 +923,10 @@ static int pci_ite887x_init(struct pci_dev *dev)break ; }release_region (iobase->start, ITE_887x_IOSIZE); - iobase =NULL ; } - i++; } -if (!inta_addr[i]) { +if (i ==ARRAY_SIZE (inta_addr)) {dev_err (&dev->dev,"ite887x: could not find iobase\n" );return -ENODEV ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 486/545 serial: 8250_pci: Replace dev_*() by pci_*() macros
In reply to Greg Kroah-HartmanFrom: Andy Shevchenko <[email protected]>
[ Upstream commit 1177384179416c7136e1348f07609e0da1ae6b91 ]
PCI subsystem provides convenient shortcut macros for message printing. Use those macros instead of dev_*().
--- drivers/tty/serial/8250/8250_pci.c | 52 +++++++++++++----------------- 1 file changed, 22 insertions(+), 30 deletions(-)
drivers/tty/serial/8250/8250_pci.c +22 -30
@@ -75,13 +75,12 @@ static int pci_default_setup(struct serial_private*,static void moan_device (const char *str,struct pci_dev *dev) { -dev_err (&dev->dev, -"%s: %s\n" +pci_err (dev,"%s\n" "Please send the output of lspci -vv, this\n" "message (0x%04x,0x%04x,0x%04x,0x%04x), the\n" "manufacturer and name of serial board or\n" "modem board to <[email protected]>.\n" , -pci_name (dev), str, dev->vendor, dev->device, + str, dev->vendor, dev->device, dev->subsystem_vendor, dev->subsystem_device); }
@@ -238,7 +237,7 @@ static int pci_inteli960ni_init(struct pci_dev *dev)/* is firmware started? */ pci_read_config_dword (dev,0x44 , &oldval);if (oldval ==0x00001000L ) {/* RESET value */ -dev_dbg (&dev->dev,"Local i960 firmware missing\n" ); +pci_dbg (dev,"Local i960 firmware missing\n" );return -ENODEV ; }return 0 ;
@@ -588,9 +587,8 @@ static int pci_timedia_probe(struct pci_dev *dev)* (0,2,3,5,6: serial only -- 7,8,9: serial + parallel) */ if ((dev->subsystem_device &0x00f0 ) >=0x70 ) { -dev_info (&dev->dev, -"ignoring Timedia subdevice %04x for parport_serial\n" , - dev->subsystem_device); +pci_info (dev,"ignoring Timedia subdevice %04x for parport_serial\n" , + dev->subsystem_device);return -ENODEV ; }
@@ -827,8 +825,7 @@ static int pci_netmos_9900_numports(struct pci_dev *dev)if (sub_serports >0 )return sub_serports; -dev_err (&dev->dev, -"NetMos/Mostech serial driver ignoring port on ambiguous config.\n" ); +pci_err (dev,"NetMos/Mostech serial driver ignoring port on ambiguous config.\n" );return 0 ; }
@@ -927,7 +924,7 @@ static int pci_ite887x_init(struct pci_dev *dev) }if (i ==ARRAY_SIZE (inta_addr)) { -dev_err (&dev->dev,"ite887x: could not find iobase\n" ); +pci_err (dev,"could not find iobase\n" );return -ENODEV ; }
@@ -1022,9 +1019,7 @@ static int pci_endrun_init(struct pci_dev *dev)/* EndRun device */ if (deviceID ==0x07000200 ) { number_uarts =ioread8 (p +4 ); -dev_dbg (&dev->dev, -"%d ports detected on EndRun PCI Express device\n" , - number_uarts); +pci_dbg (dev,"%d ports detected on EndRun PCI Express device\n" , number_uarts); }pci_iounmap (dev, p);return number_uarts;
@@ -1054,9 +1049,7 @@ static int pci_oxsemi_tornado_init(struct pci_dev *dev)/* Tornado device */ if (deviceID ==0x07000200 ) { number_uarts =ioread8 (p +4 ); -dev_dbg (&dev->dev, -"%d ports detected on Oxford PCI Express device\n" , - number_uarts); +pci_dbg (dev,"%d ports detected on Oxford PCI Express device\n" , number_uarts); }pci_iounmap (dev, p);return number_uarts;
@@ -1116,15 +1109,15 @@ static struct quatech_feature quatech_cards[] = { { 0, } }; -static int pci_quatech_amcc (u16 devid) +static int pci_quatech_amcc (struct pci_dev *dev) {struct quatech_feature *qf = &quatech_cards[0 ];while (qf->devid) { -if (qf->devid == devid) +if (qf->devid == dev->device)return qf->amcc; qf++; } -pr_err ("quatech: unknown port type '0x%04X'.\n" , devid); +pci_err (dev,"unknown port type '0x%04X'.\n" , dev->device);return 0 ; };
@@ -1287,7 +1280,7 @@ static int pci_quatech_rs422(struct uart_8250_port *port)static int pci_quatech_init (struct pci_dev *dev) { -if (pci_quatech_amcc (dev->device)) { +if (pci_quatech_amcc (dev)) {unsigned long base =pci_resource_start (dev,0 );if (base) {u32 tmp;
@@ -1311,7 +1304,7 @@ static int pci_quatech_setup(struct serial_private *priv, port->port.uartclk =pci_quatech_clock (port);/* For now just warn about RS422 */ if (pci_quatech_rs422 (port)) -pr_warn ("quatech: software control of RS422 features not currently supported.\n" ); +pci_warn (priv->dev,"software control of RS422 features not currently supported.\n" );return pci_default_setup (priv, board, port, idx); }
@@ -1525,7 +1518,7 @@ static int pci_fintek_setup(struct serial_private *priv,/* Get the io address from configuration space */ pci_read_config_word (pdev, config_base +4 , &iobase); -dev_dbg (&pdev->dev,"%s: idx=%d iobase=0x%x" , __func__, idx, iobase); +pci_dbg (pdev,"idx=%d iobase=0x%x" , idx, iobase); port->port.iotype =UPIO_PORT ; port->port.iobase = iobase;
@@ -1689,7 +1682,7 @@ static int skip_tx_en_setup(struct serial_private *priv, struct uart_8250_port *port, int idx) { port->port.quirks |=UPQ_NO_TXEN_TEST ; -dev_dbg (&priv->dev->dev, +pci_dbg (priv->dev,"serial8250: skipping TxEn test for device [%04x:%04x] subsystem [%04x:%04x]\n" , priv->dev->vendor, priv->dev->device, priv->dev->subsystem_vendor, priv->dev->subsystem_device);
@@ -4007,12 +4000,12 @@ pciserial_init_ports(struct pci_dev *dev, const struct pciserial_board *board) uart.port.irq =0 ; }else {if (pci_match_id (pci_use_msi, dev)) { -dev_dbg (&dev->dev,"Using MSI(-X) interrupts\n" ); +pci_dbg (dev,"Using MSI(-X) interrupts\n" );pci_set_master (dev); uart.port.flags &= ~UPF_SHARE_IRQ ; rc =pci_alloc_irq_vectors (dev,1 ,1 ,PCI_IRQ_ALL_TYPES ); }else { -dev_dbg (&dev->dev,"Using legacy interrupts\n" ); +pci_dbg (dev,"Using legacy interrupts\n" ); rc =pci_alloc_irq_vectors (dev,1 ,1 ,PCI_IRQ_LEGACY ); }if (rc <0 ) {
@@ -4030,12 +4023,12 @@ pciserial_init_ports(struct pci_dev *dev, const struct pciserial_board *board)if (quirk->setup (priv, board, &uart, i))break ; -dev_dbg (&dev->dev,"Setup PCI port: port %lx, irq %d, type %d\n" , +pci_dbg (dev,"Setup PCI port: port %lx, irq %d, type %d\n" , uart.port.iobase, uart.port.irq, uart.port.iotype); priv->line[i] =serial8250_register_8250_port (&uart);if (priv->line[i] <0 ) { -dev_err (&dev->dev, +pci_err (dev,"Couldn't register serial port %lx, irq %d, type %d, error %d\n" , uart.port.iobase, uart.port.irq, uart.port.iotype, priv->line[i]);
@@ -4131,8 +4124,7 @@ pciserial_init_one(struct pci_dev *dev, const struct pci_device_id *ent) }if (ent->driver_data >=ARRAY_SIZE (pci_boards)) { -dev_err (&dev->dev,"invalid driver_data: %ld\n" , - ent->driver_data); +pci_err (dev,"invalid driver_data: %ld\n" , ent->driver_data);return -EINVAL ; }
@@ -4215,7 +4207,7 @@ static int pciserial_resume_one(struct device *dev) err =pci_enable_device (pdev);/* FIXME: We cannot simply error out here */ if (err) -dev_err (dev,"Unable to re-enable ports, trying to continue.\n" ); +pci_err (pdev,"Unable to re-enable ports, trying to continue.\n" );pciserial_resume_ports (priv); }return 0 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 487/545 serial: 8250: Fold EndRun device support into OxSemi Tornado code
In reply to Greg Kroah-HartmanFrom: Maciej W. Rozycki <[email protected]>
[ Upstream commit 1f32c65bad24b9787d3e52843de375430e3df822 ]
The EndRun PTP/1588 dual serial port device is based on the Oxford Semiconductor OXPCIe952 UART device with the PCI vendor:device ID set for EndRun Technologies and uses the same sequence to determine the number of ports available. Despite that we have duplicate code specific to the EndRun device.
Remove redundant code then and factor out OxSemi Tornado device detection.
--- drivers/tty/serial/8250/8250_pci.c | 76 ++++++++++-------------------- 1 file changed, 25 insertions(+), 51 deletions(-)
drivers/tty/serial/8250/8250_pci.c +25 -51
@@ -994,41 +994,29 @@ static void pci_ite887x_exit(struct pci_dev *dev) }/* -* EndRun Technologies. -* Determine the number of ports available on the device. +* Oxford Semiconductor Inc. +* Check if an OxSemi device is part of the Tornado range of devices. */ #define PCI_VENDOR_ID_ENDRUN 0x7401#define PCI_DEVICE_ID_ENDRUN_1588 0xe100 -static int pci_endrun_init (struct pci_dev *dev) +static bool pci_oxsemi_tornado_p (struct pci_dev *dev) { -u8 __iomem *p; -unsigned long deviceID; -unsigned int number_uarts =0 ; +/* OxSemi Tornado devices are all 0xCxxx */ +if (dev->vendor ==PCI_VENDOR_ID_OXSEMI && + (dev->device &0xf000 ) !=0xc000 ) +return false; -/* EndRun device is all 0xexxx */ +/* EndRun devices are all 0xExxx */ if (dev->vendor ==PCI_VENDOR_ID_ENDRUN && - (dev->device &0xf000 ) !=0xe000 ) -return 0 ; - - p =pci_iomap (dev,0 ,5 ); -if (p ==NULL ) -return -ENOMEM ; + (dev->device &0xf000 ) !=0xe000 ) +return false; - deviceID =ioread32 (p); -/* EndRun device */ -if (deviceID ==0x07000200 ) { - number_uarts =ioread8 (p +4 ); -pci_dbg (dev,"%d ports detected on EndRun PCI Express device\n" , number_uarts); - } -pci_iounmap (dev, p); -return number_uarts; +return true; }/* -* Oxford Semiconductor Inc. -* Check that device is part of the Tornado range of devices, then determine -* the number of ports available on the device. +* Determine the number of ports available on a Tornado device. */ static int pci_oxsemi_tornado_init (struct pci_dev *dev) {
@@ -1036,9 +1024,7 @@ static int pci_oxsemi_tornado_init(struct pci_dev *dev)unsigned long deviceID;unsigned int number_uarts =0 ; -/* OxSemi Tornado devices are all 0xCxxx */ -if (dev->vendor ==PCI_VENDOR_ID_OXSEMI && - (dev->device &0xF000 ) !=0xC000 ) +if (!pci_oxsemi_tornado_p (dev))return 0 ; p =pci_iomap (dev,0 ,5 );
@@ -1049,7 +1035,10 @@ static int pci_oxsemi_tornado_init(struct pci_dev *dev)/* Tornado device */ if (deviceID ==0x07000200 ) { number_uarts =ioread8 (p +4 ); -pci_dbg (dev,"%d ports detected on Oxford PCI Express device\n" , number_uarts); +pci_dbg (dev,"%d ports detected on %s PCI Express device\n" , + number_uarts, + dev->vendor ==PCI_VENDOR_ID_ENDRUN ? +"EndRun" :"Oxford" ); }pci_iounmap (dev, p);return number_uarts;
@@ -2506,7 +2495,7 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = { .device = PCI_ANY_ID, .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, - .init = pci_endrun_init, + .init = pci_oxsemi_tornado_init, .setup = pci_default_setup, },/*
@@ -2929,7 +2918,6 @@ enum pci_board_num_t { pbn_panacom2, pbn_panacom4, pbn_plx_romulus, - pbn_endrun_2_3906250, pbn_oxsemi, pbn_oxsemi_1_3906250, pbn_oxsemi_2_3906250,
@@ -3455,20 +3443,6 @@ static struct pciserial_board pci_boards[] = { .first_offset = 0x03, }, -/* -* EndRun Technologies -* Uses the size of PCI Base region 0 to -* signal now many ports are available -* 2 port 952 Uart support -*/ - [pbn_endrun_2_3906250] = { - .flags = FL_BASE0, - .num_ports = 2, - .base_baud = 3906250, - .uart_offset = 0x200, - .first_offset = 0x1000, - }, -/* * This board uses the size of PCI Base region 0 to * signal now many ports are available
@@ -4400,13 +4374,6 @@ static const struct pci_device_id serial_pci_tbl[] = { {PCI_VENDOR_ID_PLX ,PCI_DEVICE_ID_PLX_ROMULUS ,0x10b5 ,0x106a ,0 ,0 , pbn_plx_romulus }, -/* -* EndRun Technologies. PCI express device range. -* EndRun PTP/1588 has 2 Native UARTs. -*/ - { PCI_VENDOR_ID_ENDRUN, PCI_DEVICE_ID_ENDRUN_1588, -PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , - pbn_endrun_2_3906250 },/* * Quatech cards. These actually have configurable clocks but for * now we just use the default.
@@ -4668,6 +4635,13 @@ static const struct pci_device_id serial_pci_tbl[] = { {PCI_VENDOR_ID_DIGI ,PCIE_DEVICE_ID_NEO_2_OX_IBM ,PCI_SUBVENDOR_ID_IBM ,PCI_ANY_ID ,0 ,0 , pbn_oxsemi_2_3906250 }, +/* +* EndRun Technologies. PCI express device range. +* EndRun PTP/1588 has 2 Native UARTs utilizing OxSemi 952. +*/ + { PCI_VENDOR_ID_ENDRUN, PCI_DEVICE_ID_ENDRUN_1588, +PCI_ANY_ID ,PCI_ANY_ID ,0 ,0 , + pbn_oxsemi_2_3906250 },/* * SBS Technologies, Inc. P-Octal and PMC-OCTPRO cards,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 488/545 dm writecache: set a default MAX_WRITEBACK_JOBS
In reply to Greg Kroah-HartmanFrom: Mikulas Patocka <[email protected]>
[ Upstream commit ca7dc242e358e46d963b32f9d9dd829785a9e957 ]
dm-writecache has the capability to limit the number of writeback jobs in progress. However, this feature was off by default. As such there were some out-of-memory crashes observed when lowering the low watermark while the cache is full.
This commit enables writeback limit by default. It is set to 256MiB or 1/16 of total system memory, whichever is smaller.
--- drivers/md/dm-writecache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-writecache.c +1 -1
@@ -20,7 +20,7 @@#define HIGH_WATERMARK 50#define LOW_WATERMARK 45 -#define MAX_WRITEBACK_JOBS 0 +#define MAX_WRITEBACK_JOBS min(0x10000000 / PAGE_SIZE, totalram_pages() / 16)#define ENDIO_LATENCY 16#define WRITEBACK_LATENCY 64#define AUTOCOMMIT_BLOCKS_SSD 65536
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 489/545 kexec, KEYS, s390: Make use of built-in and secondary keyring for signature verification
In reply to Greg Kroah-HartmanFrom: Michal Suchanek <[email protected]>
[ Upstream commit 0828c4a39be57768b8788e8cbd0d84683ea757e5 ]
commit e23a8020ce4e ("s390/kexec_file: Signature verification prototype") adds support for KEXEC_SIG verification with keys from platform keyring but the built-in keys and secondary keyring are not used.
Add support for the built-in keys and secondary keyring as x86 does.
--- arch/s390/kernel/machine_kexec_file.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
arch/s390/kernel/machine_kexec_file.c +13 -5
@@ -29,6 +29,7 @@ int s390_verify_sig(const char *kernel, unsigned long kernel_len)const unsigned long marker_len =sizeof (MODULE_SIG_STRING ) -1 ;struct module_signature *ms;unsigned long sig_len; +int ret;/* Skip signature verification when not secure IPLed. */ if (!ipl_secure_flag)
@@ -63,11 +64,18 @@ int s390_verify_sig(const char *kernel, unsigned long kernel_len) return -EBADMSG; } -return verify_pkcs7_signature (kernel, kernel_len, - kernel + kernel_len, sig_len, -VERIFY_USE_PLATFORM_KEYRING , -VERIFYING_MODULE_SIGNATURE , -NULL ,NULL ); + ret =verify_pkcs7_signature (kernel, kernel_len, + kernel + kernel_len, sig_len, +VERIFY_USE_SECONDARY_KEYRING , +VERIFYING_MODULE_SIGNATURE , +NULL ,NULL ); +if (ret == -ENOKEY &&IS_ENABLED (CONFIG_INTEGRITY_PLATFORM_KEYRING )) + ret =verify_pkcs7_signature (kernel, kernel_len, + kernel + kernel_len, sig_len, +VERIFY_USE_PLATFORM_KEYRING , +VERIFYING_MODULE_SIGNATURE , +NULL ,NULL ); +return ret; }#endif /* CONFIG_KEXEC_SIG */
Signature · 9 lines
2.35.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Greg Kroah-Hartman
maintainerPATCH 490/545 dm thin: fix use-after-free crash in dm_sm_register_threshold_callback
In reply to Greg Kroah-HartmanFrom: Luo Meng <[email protected]>
[ Upstream commit 3534e5a5ed2997ca1b00f44a0378a075bd05e8a3 ]
Fault inject on pool metadata device reports:
BUG: KASAN: use-after-free in dm_pool_register_metadata_threshold+0x40/0x80 Read of size 8 at addr ffff8881b9d50068 by task dmsetup/950 CPU: 7 PID: 950 Comm: dmsetup Tainted: G W 5.19.0-rc6 #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-1.fc33 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x34/0x44 print_address_description.constprop.0.cold+0xeb/0x3f4 kasan_report.cold+0xe6/0x147 dm_pool_register_metadata_threshold+0x40/0x80 pool_ctr+0xa0a/0x1150 dm_table_add_target+0x2c8/0x640 table_load+0x1fd/0x430 ctl_ioctl+0x2c4/0x5a0 dm_ctl_ioctl+0xa/0x10 __x64_sys_ioctl+0xb3/0xd0 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x46/0xb0
This can be easily reproduced using:
echo offline > /sys/block/sda/device/state
dd if=/dev/zero of=/dev/mapper/thin bs=4k count=10
dmsetup load pool --table "0 20971520 thin-pool /dev/sda /dev/sdb 128 0 0"
If a metadata commit fails, the transaction will be aborted and the metadata space maps will be destroyed. If a DM table reload then happens for this failed thin-pool, a use-after-free will occur in dm_sm_register_threshold_callback (called from dm_pool_register_metadata_threshold).
Fix this by in dm_pool_register_metadata_threshold() by returning the -EINVAL error if the thin-pool is in fail mode. Also fail pool_ctr() with a new error message: "Error registering metadata threshold".
--- drivers/md/dm-thin-metadata.c | 7 +++++-- drivers/md/dm-thin.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/md/dm-thin-metadata.c +5 -2
@@ -2058,10 +2058,13 @@ int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,dm_sm_threshold_fn fn, void *context) { - int r; + int r = -EINVAL;pmd_write_lock_in_core (pmd); - r =dm_sm_register_threshold_callback (pmd->metadata_sm, threshold, fn, context); +if (!pmd->fail_io) { + r =dm_sm_register_threshold_callback (pmd->metadata_sm, + threshold, fn, context); + }pmd_write_unlock (pmd);return r;
drivers/md/dm-thin.c +3 -1
@@ -3401,8 +3401,10 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)calc_metadata_threshold (pt), metadata_low_callback, pool); -if (r) +if (r) { + ti->error ="Error registering metadata threshold" ; goto out_flags_changed; + }dm_pool_register_pre_commit_callback (pool->pmd, metadata_pre_commit_callback, pool);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 491/545 timekeeping: contribute wall clock to rng on time change
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
[ Upstream commit b8ac29b40183a6038919768b5d189c9bd91ce9b4 ]
The rng's random_init() function contributes the real time to the rng at boot time, so that events can at least start in relation to something particular in the real world. But this clock might not yet be set that point in boot, so nothing is contributed. In addition, the relation between minor clock changes from, say, NTP, and the cycle counter is potentially useful entropic data.
This commit addresses this by mixing in a time stamp on calls to settimeofday and adjtimex. No entropy is credited in doing so, so it doesn't make initialization faster, but it is still useful input to have.
--- kernel/time/timekeeping.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/time/timekeeping.c +6 -1
@@ -23,6 +23,7 @@#include <linux/pvclock_gtod.h> #include <linux/compiler.h> #include <linux/audit.h> +#include <linux/random.h> #include "tick-internal.h" #include "ntp_internal.h"
@@ -1330,8 +1331,10 @@ int do_settimeofday64(const struct timespec64 *ts)/* signal hrtimers about time change */ clock_was_set (); -if (!ret) +if (!ret) {audit_tk_injoffset (ts_delta); +add_device_randomness (ts,sizeof (*ts)); + }return ret; }
@@ -2410,6 +2413,7 @@ int do_adjtimex(struct __kernel_timex *txc) ret =timekeeping_validate_timex (txc);if (ret)return ret; +add_device_randomness (txc,sizeof (*txc));if (txc->modes &ADJ_SETOFFSET ) {struct timespec64 delta;
@@ -2427,6 +2431,7 @@ int do_adjtimex(struct __kernel_timex *txc)audit_ntp_init (&ad);ktime_get_real_ts64 (&ts); +add_device_randomness (&ts,sizeof (ts));raw_spin_lock_irqsave (&timekeeper_lock, flags);write_seqcount_begin (&tk_core.seq);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 492/545 um: Allow PM with suspend-to-idle
In reply to Greg Kroah-HartmanFrom: Johannes Berg <[email protected]>
[ Upstream commit 92dcd3d31843fbe1a95d880dc912e1f6beac6632 ]
In order to be able to experiment with suspend in UML, add the minimal work to be able to suspend (s2idle) an instance of UML, and be able to wake it back up from that state with the USR1 signal sent to the main UML process.
--- arch/um/Kconfig | 5 +++++ arch/um/include/shared/kern_util.h | 2 ++ arch/um/include/shared/os.h | 1 + arch/um/kernel/um_arch.c | 25 +++++++++++++++++++++++++ arch/um/os-Linux/signal.c | 14 +++++++++++++- 5 files changed, 46 insertions(+), 1 deletion(-)
arch/um/Kconfig +5 -0
@@ -192,3 +192,8 @@ config UML_TIME_TRAVEL_SUPPORT endmenu source "arch/um/drivers/Kconfig" + +config ARCH_SUSPEND_POSSIBLE + def_bool y + +source "kernel/power/Kconfig"
arch/um/include/shared/kern_util.h +2 -0
@@ -39,6 +39,8 @@ extern int is_syscall(unsigned long addr);extern void timer_handler (int sig,struct siginfo *unused_si,struct uml_pt_regs *regs); +extern void uml_pm_wake (void ); +extern int start_uml (void );extern void paging_init (void );
arch/um/include/shared/os.h +1 -0
@@ -241,6 +241,7 @@ extern int set_signals(int enable);extern int set_signals_trace (int enable);extern int os_is_signal_stack (void );extern void deliver_alarm (void ); +extern void register_pm_wake_signal (void );/* util.c */ extern void stack_protections (unsigned long address);
arch/um/kernel/um_arch.c +25 -0
@@ -13,6 +13,7 @@#include <linux/sched.h> #include <linux/sched/task.h> #include <linux/kmsg_dump.h> +#include <linux/suspend.h> #include <asm/processor.h> #include <asm/sections.h>
@@ -385,3 +386,27 @@ void *text_poke(void *addr, const void *opcode, size_t len)void text_poke_sync (void ) { } + +#ifdef CONFIG_PM_SLEEP +void uml_pm_wake (void ) +{ +pm_system_wakeup (); +} + +static int init_pm_wake_signal (void ) +{ +/* +* In external time-travel mode we can't use signals to wake up +* since that would mess with the scheduling. We'll have to do +* some additional work to support wakeup on virtio devices or +* similar, perhaps implementing a fake RTC controller that can +* trigger wakeup (and request the appropriate scheduling from +* the external scheduler when going to suspend.) +*/ +if (time_travel_mode !=TT_MODE_EXTERNAL ) +register_pm_wake_signal (); +return 0 ; +} + +late_initcall (init_pm_wake_signal); +#endif
arch/um/os-Linux/signal.c +13 -1
@@ -136,6 +136,16 @@ void set_sigstack(void *sig_stack, int size)panic ("enabling signal stack failed, errno = %d\n" , errno); } +static void sigusr1_handler (int sig,struct siginfo *unused_si,mcontext_t *mc) +{ +uml_pm_wake (); +} + +void register_pm_wake_signal (void ) +{ +set_handler (SIGUSR1 ); +} +static void (*handlers[_NSIG])(int sig,struct siginfo *si,mcontext_t *mc) = { [SIGSEGV ] = sig_handler, [SIGBUS ] = sig_handler,
@@ -145,7 +155,9 @@ static void (*handlers[_NSIG])(int sig, struct siginfo *si, mcontext_t *mc) = { [SIGIO] = sig_handler, [SIGWINCH] = sig_handler, - [SIGALRM] = timer_alarm_handler + [SIGALRM] = timer_alarm_handler, + + [SIGUSR1] = sigusr1_handler, };static void hard_handler (int sig,siginfo_t *si,void *p)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 493/545 um: seed rng using host OS rng
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
[ Upstream commit 0b9ba6135d7f18b82f3d8bebb55ded725ba88e0e ]
UML generally does not provide access to special CPU instructions like RDRAND, and execution tends to be rather deterministic, with no real hardware interrupts, making good randomness really very hard, if not all together impossible. Not only is this a security eyebrow raiser, but it's also quite annoying when trying to do various pieces of UML-based automation that takes a long time to boot, if ever.
Fix this by trivially calling getrandom() in the host and using that seed as "bootloader randomness", which initializes the rng immediately at UML boot.
The old behavior can be restored the same way as on any other arch, by way of CONFIG_TRUST_BOOTLOADER_RANDOMNESS=n or random.trust_bootloader=0. So seen from that perspective, this just makes UML act like other archs, which is positive in its own right.
Additionally, wire up arch_get_random_{int,long}() in the same way, so that reseeds can also make use of the host RNG, controllable by CONFIG_TRUST_CPU_RANDOMNESS and random.trust_cpu, per usual.
--- arch/um/include/asm/archrandom.h | 30 ++++++++++++++++++++++++++++++ arch/um/include/shared/os.h | 7 +++++++ arch/um/kernel/um_arch.c | 8 ++++++++ arch/um/os-Linux/util.c | 6 ++++++ 4 files changed, 51 insertions(+) create mode 100644 arch/um/include/asm/archrandom.h
arch/um/include/asm/archrandom.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_UM_ARCHRANDOM_H__ +#define __ASM_UM_ARCHRANDOM_H__ + +#include <linux/types.h> + +/* This is from <os.h>, but better not to #include that in a global header here. */ +ssize_t os_getrandom (void *buf,size_t len,unsigned int flags); + +static inline bool __must_check arch_get_random_long (unsigned long *v) +{ +return os_getrandom (v,sizeof (*v),0 ) ==sizeof (*v); +} + +static inline bool __must_check arch_get_random_int (unsigned int *v) +{ +return os_getrandom (v,sizeof (*v),0 ) ==sizeof (*v); +} + +static inline bool __must_check arch_get_random_seed_long (unsigned long *v) +{ +return false; +} + +static inline bool __must_check arch_get_random_seed_int (unsigned int *v) +{ +return false; +} + +#endif
arch/um/include/shared/os.h +7 -0
@@ -12,6 +12,12 @@#include <irq_user.h> #include <longjmp.h> #include <mm_id.h> +/* This is to get size_t */ +#ifndef __UM_HOST__ +#include <linux/types.h> +#else +#include <sys/types.h> +#endif #define CATCH_EINTR (expr) while ((errno = 0, ((expr) < 0)) && (errno == EINTR))
@@ -248,6 +254,7 @@ extern void stack_protections(unsigned long address);extern int raw (int fd);extern void setup_machinename (char *machine_out);extern void setup_hostinfo (char *buf,int len); +extern ssize_t os_getrandom (void *buf,size_t len,unsigned int flags);extern void os_dump_core (void ) __attribute__ ((noreturn));extern void um_early_printk (const char *s,unsigned int n);extern void os_fix_helper_signals (void );
arch/um/kernel/um_arch.c +8 -0
@@ -14,6 +14,7 @@#include <linux/sched/task.h> #include <linux/kmsg_dump.h> #include <linux/suspend.h> +#include <linux/random.h> #include <asm/processor.h> #include <asm/sections.h>
@@ -342,6 +343,8 @@ int __init __weak read_initrd(void)void __init setup_arch (char **cmdline_p) { +u8 rng_seed[32 ]; +stack_protections ((unsigned long ) &init_thread_info);setup_physmem (uml_physmem, uml_reserved, physmem_size, highmem);mem_total_pages (physmem_size, iomem_size, highmem);
@@ -351,6 +354,11 @@ void __init setup_arch(char **cmdline_p)strlcpy (boot_command_line, command_line,COMMAND_LINE_SIZE ); *cmdline_p = command_line;setup_hostinfo (host_info,sizeof host_info); + +if (os_getrandom (rng_seed,sizeof (rng_seed),0 ) ==sizeof (rng_seed)) { +add_bootloader_randomness (rng_seed,sizeof (rng_seed)); +memzero_explicit (rng_seed,sizeof (rng_seed)); + } }void __init check_bugs (void )
arch/um/os-Linux/util.c +6 -0
@@ -13,6 +13,7 @@#include <sys/wait.h> #include <sys/mman.h> #include <sys/utsname.h> +#include <sys/random.h> #include <init.h> #include <os.h>
@@ -95,6 +96,11 @@ static inline void __attribute__ ((noreturn)) uml_abort(void)exit (127 ); } +ssize_t os_getrandom (void *buf,size_t len,unsigned int flags) +{ +return getrandom (buf, len, flags); +} +/* * UML helper threads must not handle SIGWINCH/INT/TERM */
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 494/545 btrfs: reject log replay if there is unsupported RO compat flag
In reply to Greg Kroah-HartmanFrom: Qu Wenruo <[email protected]>
[ Upstream commit dc4d31684974d140250f3ee612c3f0cab13b3146 ]
[BUG]
If we have a btrfs image with dirty log, along with an unsupported RO compatible flag:
log_root 30474240
...compat_flags 0x0compat_ro_flags 0x40000003
( FREE_SPACE_TREE | FREE_SPACE_TREE_VALID | unknown flag: 0x40000000 )
Then even if we can only mount it RO, we will still cause metadata update for log replay:
BTRFS info (device dm-1): flagging fs with big metadata feature BTRFS info (device dm-1): using free space tree
BTRFS info (device dm-1): has skinny extents
BTRFS info (device dm-1): start tree-log replay
This is definitely against RO compact flag requirement.
[CAUSE]
RO compact flag only forces us to do RO mount, but we will still do log replay for plain RO mount.
Thus this will result us to do log replay and update metadata.
This can be very problematic for new RO compat flag, for example older kernel can not understand v2 cache, and if we allow metadata update on RO mount and invalidate/corrupt v2 cache.
[FIX]
Just reject the mount unless rescue=nologreplay is provided:
BTRFS error (device dm-1): cannot replay dirty log with unsupport optional features (0x40000000), try rescue=nologreplay instead
We don't want to set rescue=nologreply directly, as this would make the end user to read the old data, and cause confusion.
Since the such case is really rare, we're mostly fine to just reject the mount with an error message, which also includes the proper workaround.
--- fs/btrfs/disk-io.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
fs/btrfs/disk-io.c +14 -0
@@ -3104,6 +3104,20 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device err = -EINVAL ; goto fail_alloc; } +/* +* We have unsupported RO compat features, although RO mounted, we +* should not cause any metadata write, including log replay. +* Or we could screw up whatever the new feature requires. +*/ +if (unlikely (features &&btrfs_super_log_root (disk_super) && + !btrfs_test_opt (fs_info,NOLOGREPLAY ))) { +btrfs_err (fs_info, +"cannot replay dirty log with unsupported compat_ro features (0x%llx), try rescue=nologreplay" , + features); + err = -EINVAL ; + goto fail_alloc; + } + ret =btrfs_init_workqueues (fs_info, fs_devices);if (ret) {
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 495/545 btrfs: reset block group chunk force if we have to wait
In reply to Greg Kroah-HartmanFrom: Josef Bacik <[email protected]>
[ Upstream commit 1314ca78b2c35d3e7d0f097268a2ee6dc0d369ef ]
If you try to force a chunk allocation, but you race with another chunk allocation, you will end up waiting on the chunk allocation that just occurred and then allocate another chunk. If you have many threads all doing this at once you can way over-allocate chunks.
Fix this by resetting force to NO_FORCE, that way if we think we need to allocate we can, otherwise we don't force another chunk allocation if one is already happening.
--- fs/btrfs/block-group.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/block-group.c +1 -0
@@ -3126,6 +3126,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,* attempt. */ wait_for_alloc = true; + force =CHUNK_ALLOC_NO_FORCE ;spin_unlock (&space_info->lock);mutex_lock (&fs_info->chunk_mutex);mutex_unlock (&fs_info->chunk_mutex);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 496/545 ACPI: CPPC: Do not prevent CPPC from working in the future
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit 4f4179fcf420873002035cf1941d844c9e0e7cb3 ]
There is a problem with the current revision checks in is_cppc_supported() that they essentially prevent the CPPC support from working if a new _CPC package format revision being a proper superset of the v3 and only causing _CPC to return a package with more entries (while retaining the types and meaning of the entries defined by the v3) is introduced in the future and used by the platform firmware.
In that case, as long as the number of entries in the _CPC return package is at least CPPC_V3_NUM_ENT, it should be perfectly fine to use the v3 support code and disregard the additional package entries added by the new package format revision.
For this reason, drop is_cppc_supported() altogether, put the revision checks directly into acpi_cppc_processor_probe() so they are easier to follow and rework them to take the case mentioned above into account.
--- drivers/acpi/cppc_acpi.c | 54 ++++++++++++++++++---------------------- include/acpi/cppc_acpi.h | 2 +- 2 files changed, 25 insertions(+), 31 deletions(-)
drivers/acpi/cppc_acpi.c +24 -30
@@ -607,33 +607,6 @@ static int pcc_data_alloc(int pcc_ss_id)return 0 ; } -/* Check if CPPC revision + num_ent combination is supported */ -static bool is_cppc_supported (int revision,int num_ent) -{ -int expected_num_ent; - -switch (revision) { -case CPPC_V2_REV : - expected_num_ent =CPPC_V2_NUM_ENT ; -break ; -case CPPC_V3_REV : - expected_num_ent =CPPC_V3_NUM_ENT ; -break ; -default : -pr_debug ("Firmware exports unsupported CPPC revision: %d\n" , - revision); -return false; - } - -if (expected_num_ent != num_ent) { -pr_debug ("Firmware exports %d entries. Expected: %d for CPPC rev:%d\n" , - num_ent, expected_num_ent, revision); -return false; - } - -return true; -} -/* * An example CPC table looks like the following. *
@@ -729,7 +702,6 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) cpc_obj->type); goto out_free; } - cpc_ptr->num_entries = num_ent;/* Second entry should be revision. */ cpc_obj = &out_obj->package.elements[1 ];
@@ -740,10 +712,32 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) cpc_obj->type); goto out_free; } - cpc_ptr->version = cpc_rev; -if (!is_cppc_supported (cpc_rev, num_ent)) +if (cpc_rev <CPPC_V2_REV ) { +pr_debug ("Unsupported _CPC Revision (%d) for CPU:%d\n" , cpc_rev, + pr->id); goto out_free; + } + +/* +* Disregard _CPC if the number of entries in the return pachage is not +* as expected, but support future revisions being proper supersets of +* the v3 and only causing more entries to be returned by _CPC. +*/ +if ((cpc_rev ==CPPC_V2_REV && num_ent !=CPPC_V2_NUM_ENT ) || + (cpc_rev ==CPPC_V3_REV && num_ent !=CPPC_V3_NUM_ENT ) || + (cpc_rev >CPPC_V3_REV && num_ent <=CPPC_V3_NUM_ENT )) { +pr_debug ("Unexpected number of _CPC return package entries (%d) for CPU:%d\n" , + num_ent, pr->id); + goto out_free; + } +if (cpc_rev >CPPC_V3_REV ) { + num_ent =CPPC_V3_NUM_ENT ; + cpc_rev =CPPC_V3_REV ; + } + + cpc_ptr->num_entries = num_ent; + cpc_ptr->version = cpc_rev;/* Iterate through remaining entries in _CPC */ for (i =2 ; i < num_ent; i++) {
include/acpi/cppc_acpi.h +1 -1
@@ -16,7 +16,7 @@#include <acpi/pcc.h> #include <acpi/processor.h> -/* Support CPPCv2 and CPPCv3 */ +/* CPPCv2 and CPPCv3 support */ #define CPPC_V2_REV 2#define CPPC_V3_REV 3#define CPPC_V2_NUM_ENT 21
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 497/545 KVM: PPC: Book3S HV: Remove virt mode checks from real mode handlers
In reply to Greg Kroah-HartmanFrom: Nicholas Piggin <[email protected]>
[ Upstream commit dcbac73a5b374873bd6dfd8a0ee5d0b7fc844420 ]
Now that the P7/8 path no longer supports radix, real-mode handlers do not need to deal with being called in virt mode.
This change effectively reverts commit acde25726bc6 ("KVM: PPC: Book3S
HV: Add radix checks in real-mode hypercall handlers").
It removes a few more real-mode tests in rm hcall handlers, which allows the indirect ops for the xive module to be removed from the built-in xics rm handlers.
kvmppc_h_random is renamed to kvmppc_rm_h_random to be a bit more descriptive and consistent with other rm handlers.
--- arch/powerpc/include/asm/kvm_ppc.h | 10 +-- arch/powerpc/kvm/book3s.c | 11 +-- arch/powerpc/kvm/book3s_64_vio_hv.c | 12 ---- arch/powerpc/kvm/book3s_hv_builtin.c | 91 ++++++------------------- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 2 +- arch/powerpc/kvm/book3s_xive.c | 18 ----- arch/powerpc/kvm/book3s_xive.h | 7 -- arch/powerpc/kvm/book3s_xive_native.c | 10 --- 8 files changed, 23 insertions(+), 138 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +1 -9
@@ -654,8 +654,6 @@ extern int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server, u32 *priority);extern int kvmppc_xive_int_on (struct kvm *kvm,u32 irq);extern int kvmppc_xive_int_off (struct kvm *kvm,u32 irq); -extern void kvmppc_xive_init_module (void ); -extern void kvmppc_xive_exit_module (void );extern int kvmppc_xive_connect_vcpu (struct kvm_device *dev,struct kvm_vcpu *vcpu,u32 cpu);
@@ -679,8 +677,6 @@ static inline int kvmppc_xive_enabled(struct kvm_vcpu *vcpu)extern int kvmppc_xive_native_connect_vcpu (struct kvm_device *dev,struct kvm_vcpu *vcpu,u32 cpu);extern void kvmppc_xive_native_cleanup_vcpu (struct kvm_vcpu *vcpu); -extern void kvmppc_xive_native_init_module (void ); -extern void kvmppc_xive_native_exit_module (void );extern int kvmppc_xive_native_get_vp (struct kvm_vcpu *vcpu,union kvmppc_one_reg *val); extern int kvmppc_xive_native_set_vp(struct kvm_vcpu *vcpu,
@@ -694,8 +690,6 @@ static inline int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server, u32 *priority) { return -1; }static inline int kvmppc_xive_int_on (struct kvm *kvm,u32 irq) {return -1 ; }static inline int kvmppc_xive_int_off (struct kvm *kvm,u32 irq) {return -1 ; } -static inline void kvmppc_xive_init_module (void ) { } -static inline void kvmppc_xive_exit_module (void ) { }static inline int kvmppc_xive_connect_vcpu (struct kvm_device *dev,struct kvm_vcpu *vcpu,u32 cpu) {return -EBUSY ; }
@@ -716,8 +710,6 @@ static inline int kvmppc_xive_enabled(struct kvm_vcpu *vcpu)static inline int kvmppc_xive_native_connect_vcpu (struct kvm_device *dev,struct kvm_vcpu *vcpu,u32 cpu) {return -EBUSY ; }static inline void kvmppc_xive_native_cleanup_vcpu (struct kvm_vcpu *vcpu) { } -static inline void kvmppc_xive_native_init_module (void ) { } -static inline void kvmppc_xive_native_exit_module (void ) { }static inline int kvmppc_xive_native_get_vp (struct kvm_vcpu *vcpu,union kvmppc_one_reg *val) {return 0 ; }
@@ -753,7 +745,7 @@ long kvmppc_rm_h_stuff_tce(struct kvm_vcpu *vcpu, unsigned long tce_value, unsigned long npages);long int kvmppc_rm_h_confer (struct kvm_vcpu *vcpu,int target,unsigned int yield_count); -long kvmppc_h_random (struct kvm_vcpu *vcpu); +long kvmppc_rm_h_random (struct kvm_vcpu *vcpu);void kvmhv_commence_exit (int trap);void kvmppc_realmode_machine_check (struct kvm_vcpu *vcpu);void kvmppc_subcore_enter_guest (void );
arch/powerpc/kvm/book3s.c +1 -10
@@ -1046,13 +1046,10 @@ static int kvmppc_book3s_init(void)#ifdef CONFIG_KVM_XICS #ifdef CONFIG_KVM_XIVE if (xics_on_xive ()) { -kvmppc_xive_init_module ();kvm_register_device_ops (&kvm_xive_ops,KVM_DEV_TYPE_XICS ); -if (kvmppc_xive_native_supported ()) { -kvmppc_xive_native_init_module (); +if (kvmppc_xive_native_supported ())kvm_register_device_ops (&kvm_xive_native_ops,KVM_DEV_TYPE_XIVE ); - } } else#endif kvm_register_device_ops (&kvm_xics_ops,KVM_DEV_TYPE_XICS );
@@ -1062,12 +1059,6 @@ static int kvmppc_book3s_init(void)static void kvmppc_book3s_exit (void ) { -#ifdef CONFIG_KVM_XICS -if (xics_on_xive ()) { -kvmppc_xive_exit_module (); -kvmppc_xive_native_exit_module (); - } -#endif #ifdef CONFIG_KVM_BOOK3S_32_HANDLER kvmppc_book3s_exit_pr ();#endif
arch/powerpc/kvm/book3s_64_vio_hv.c +0 -12
@@ -404,10 +404,6 @@ long kvmppc_rm_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,/* udbg_printf("H_PUT_TCE(): liobn=0x%lx ioba=0x%lx, tce=0x%lx\n", */ /* liobn, ioba, tce); */ -/* For radix, we might be in virtual mode, so punt */ -if (kvm_is_radix (vcpu->kvm)) -return H_TOO_HARD ; - stt =kvmppc_find_table (vcpu->kvm, liobn);if (!stt)return H_TOO_HARD ;
@@ -500,10 +496,6 @@ long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu,bool prereg = false;struct kvmppc_spapr_tce_iommu_table *stit; -/* For radix, we might be in virtual mode, so punt */ -if (kvm_is_radix (vcpu->kvm)) -return H_TOO_HARD ; -/* * used to check for invalidations in progress */
@@ -609,10 +601,6 @@ long kvmppc_rm_h_stuff_tce(struct kvm_vcpu *vcpu,long i, ret;struct kvmppc_spapr_tce_iommu_table *stit; -/* For radix, we might be in virtual mode, so punt */ -if (kvm_is_radix (vcpu->kvm)) -return H_TOO_HARD ; - stt =kvmppc_find_table (vcpu->kvm, liobn);if (!stt)return H_TOO_HARD ;
arch/powerpc/kvm/book3s_hv_builtin.c +20 -71
144 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +1 -1
@@ -2535,7 +2535,7 @@ hcall_real_table: #else .long 0 /* 0x2fc - H_XIRR_X*/ #endif - .long DOTSYM(kvmppc_h_random) - hcall_real_table + .long DOTSYM(kvmppc_rm_h_random) - hcall_real_table .globl hcall_real_table_end hcall_real_table_end:
arch/powerpc/kvm/book3s_xive.c +0 -18
@@ -2245,21 +2245,3 @@ struct kvm_device_ops kvm_xive_ops = { .get_attr = xive_get_attr, .has_attr = xive_has_attr, }; - -void kvmppc_xive_init_module (void ) -{ - __xive_vm_h_xirr = xive_vm_h_xirr; - __xive_vm_h_ipoll = xive_vm_h_ipoll; - __xive_vm_h_ipi = xive_vm_h_ipi; - __xive_vm_h_cppr = xive_vm_h_cppr; - __xive_vm_h_eoi = xive_vm_h_eoi; -} - -void kvmppc_xive_exit_module (void ) -{ - __xive_vm_h_xirr =NULL ; - __xive_vm_h_ipoll =NULL ; - __xive_vm_h_ipi =NULL ; - __xive_vm_h_cppr =NULL ; - __xive_vm_h_eoi =NULL ; -}
arch/powerpc/kvm/book3s_xive.h +0 -7
@@ -278,13 +278,6 @@ extern int xive_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server,extern int xive_rm_h_cppr (struct kvm_vcpu *vcpu,unsigned long cppr);extern int xive_rm_h_eoi (struct kvm_vcpu *vcpu,unsigned long xirr); -extern unsigned long (*__xive_vm_h_xirr)(struct kvm_vcpu *vcpu); -extern unsigned long (*__xive_vm_h_ipoll)(struct kvm_vcpu *vcpu,unsigned long server); -extern int (*__xive_vm_h_ipi)(struct kvm_vcpu *vcpu,unsigned long server, -unsigned long mfrr); -extern int (*__xive_vm_h_cppr)(struct kvm_vcpu *vcpu,unsigned long cppr); -extern int (*__xive_vm_h_eoi)(struct kvm_vcpu *vcpu,unsigned long xirr); -/* * Common Xive routines for XICS-over-XIVE and XIVE native */
arch/powerpc/kvm/book3s_xive_native.c +0 -10
@@ -1271,13 +1271,3 @@ struct kvm_device_ops kvm_xive_native_ops = { .has_attr = kvmppc_xive_native_has_attr, .mmap = kvmppc_xive_native_mmap, }; - -void kvmppc_xive_native_init_module (void ) -{ - ; -} - -void kvmppc_xive_native_exit_module (void ) -{ - ; -}
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 498/545 powerpc/powernv/kvm: Use darn for H_RANDOM on Power9
In reply to Greg Kroah-HartmanFrom: Jason A. Donenfeld <[email protected]>
[ Upstream commit 7ef3d06f1bc4a5e62273726f3dc2bd258ae1c71f ]
The existing logic in KVM to support guests calling H_RANDOM only works on Power8, because it looks for an RNG in the device tree, but on Power9 we just use darn.
In addition the existing code needs to work in real mode, so we have the special cased powernv_get_random_real_mode() to deal with that.
Instead just have KVM call ppc_md.get_random_seed(), and do the real mode check inside of there, that way we use whatever RNG is available, including darn on Power9.
--- arch/powerpc/include/asm/archrandom.h | 5 ---- arch/powerpc/kvm/book3s_hv_builtin.c | 7 +++--- arch/powerpc/platforms/powernv/rng.c | 36 ++++++--------------------- 3 files changed, 12 insertions(+), 36 deletions(-)
arch/powerpc/include/asm/archrandom.h +0 -5
@@ -38,12 +38,7 @@ static inline bool __must_check arch_get_random_seed_int(unsigned int *v)#endif /* CONFIG_ARCH_RANDOM */ #ifdef CONFIG_PPC_POWERNV -int powernv_hwrng_present (void );int powernv_get_random_long (unsigned long *v); -int powernv_get_random_real_mode (unsigned long *v); -#else -static inline int powernv_hwrng_present (void ) {return 0 ; } -static inline int powernv_get_random_real_mode (unsigned long *v) {return 0 ; }#endif #endif /* _ASM_POWERPC_ARCHRANDOM_H */
arch/powerpc/kvm/book3s_hv_builtin.c +4 -3
@@ -19,7 +19,7 @@#include <asm/cputable.h> #include <asm/kvm_ppc.h> #include <asm/kvm_book3s.h> -#include <asm/archrandom.h> +#include <asm/machdep.h> #include <asm/xics.h> #include <asm/xive.h> #include <asm/dbell.h>
@@ -176,13 +176,14 @@ EXPORT_SYMBOL_GPL(kvmppc_hcall_impl_hv_realmode);int kvmppc_hwrng_present (void ) { -return powernv_hwrng_present (); +return ppc_md.get_random_seed !=NULL ; }EXPORT_SYMBOL_GPL (kvmppc_hwrng_present);long kvmppc_rm_h_random (struct kvm_vcpu *vcpu) { -if (powernv_get_random_real_mode (&vcpu->arch.regs.gpr[4 ])) +if (ppc_md.get_random_seed && + ppc_md.get_random_seed (&vcpu->arch.regs.gpr[4 ]))return H_SUCCESS ;return H_HARDWARE ;
arch/powerpc/platforms/powernv/rng.c +8 -28
@@ -29,15 +29,6 @@ struct powernv_rng { static DEFINE_PER_CPU(struct powernv_rng *, powernv_rng); -int powernv_hwrng_present (void ) -{ -struct powernv_rng *rng; - - rng =get_cpu_var (powernv_rng); -put_cpu_var (rng); -return rng !=NULL ; -} -static unsigned long rng_whiten (struct powernv_rng *rng,unsigned long val) {unsigned long parity;
@@ -58,19 +49,6 @@ static unsigned long rng_whiten(struct powernv_rng *rng, unsigned long val)return val; } -int powernv_get_random_real_mode (unsigned long *v) -{ -struct powernv_rng *rng; - - rng =raw_cpu_read (powernv_rng); -if (!rng) -return 0 ; - - *v =rng_whiten (rng,__raw_rm_readq (rng->regs_real)); - -return 1 ; -} -static int powernv_get_random_darn (unsigned long *v) {unsigned long val;
@@ -107,12 +85,14 @@ int powernv_get_random_long(unsigned long *v) {struct powernv_rng *rng; - rng =get_cpu_var (powernv_rng); - - *v =rng_whiten (rng,in_be64 (rng->regs)); - -put_cpu_var (rng); - +if (mfmsr () &MSR_DR ) { + rng =get_cpu_var (powernv_rng); + *v =rng_whiten (rng,in_be64 (rng->regs)); +put_cpu_var (rng); + }else { + rng =raw_cpu_read (powernv_rng); + *v =rng_whiten (rng,__raw_rm_readq (rng->regs_real)); + }return 1 ; }EXPORT_SYMBOL_GPL (powernv_get_random_long);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 499/545 KVM: VMX: Drop guest CPUID check for VMXE in vmx_set_cr4()
In reply to Greg Kroah-HartmanFrom: Sean Christopherson <[email protected]>
[ Upstream commit d3a9e4146a6f79f19430bca3f2a4d6ebaaffe36b ]
Drop vmx_set_cr4()'s somewhat hidden guest_cpuid_has() check on VMXE now that common x86 handles the check by incorporating VMXE into the CR4 reserved bits, i.e. in cr4_guest_rsvd_bits. This fixes a bug where KVM incorrectly rejects KVM_SET_SREGS with CR4.VMXE=1 if it's executed before KVM_SET_CPUID{,2}.
Message-Id: <[email protected]>
--- arch/x86/kvm/vmx/vmx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx/vmx.c +3 -2
@@ -3217,9 +3217,10 @@ int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)* must first be able to turn on cr4.VMXE (see handle_vmon()). * So basically the check on whether to allow nested VMX * is here. We operate under the default treatment of SMM, -* so VMX cannot be enabled under SMM. +* so VMX cannot be enabled under SMM. Note, guest CPUID is +* intentionally ignored, it's handled by cr4_guest_rsvd_bits. */ -if (!nested_vmx_allowed (vcpu) ||is_smm (vcpu)) +if (!nested ||is_smm (vcpu))return 1 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 500/545 KVM: VMX: Drop explicit nested check from vmx_set_cr4()
In reply to Greg Kroah-HartmanFrom: Sean Christopherson <[email protected]>
[ Upstream commit a447e38a7fadb2e554c3942dda183e55cccd5df0 ]
Drop vmx_set_cr4()'s explicit check on the 'nested' module param now that common x86 handles the check by incorporating VMXE into the CR4 reserved bits, via kvm_cpu_caps. X86_FEATURE_VMX is set in kvm_cpu_caps (by vmx_set_cpu_caps()), if and only if 'nested' is true.
No functional change intended.
Message-Id: <[email protected]>
--- arch/x86/kvm/vmx/vmx.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
arch/x86/kvm/vmx/vmx.c +7 -12
@@ -3211,18 +3211,13 @@ int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) } } -if (cr4 &X86_CR4_VMXE ) { -/* -* To use VMXON (and later other VMX instructions), a guest -* must first be able to turn on cr4.VMXE (see handle_vmon()). -* So basically the check on whether to allow nested VMX -* is here. We operate under the default treatment of SMM, -* so VMX cannot be enabled under SMM. Note, guest CPUID is -* intentionally ignored, it's handled by cr4_guest_rsvd_bits. -*/ -if (!nested ||is_smm (vcpu)) -return 1 ; - } +/* +* We operate under the default treatment of SMM, so VMX cannot be +* enabled under SMM. Note, whether or not VMXE is allowed at all is +* handled by kvm_valid_cr4(). +*/ +if ((cr4 &X86_CR4_VMXE ) &&is_smm (vcpu)) +return 1 ;if (vmx->nested.vmxon && !nested_cr4_valid (vcpu, cr4))return 1 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 501/545 KVM: SVM: Drop VMXE check from svm_set_cr4()
In reply to Greg Kroah-HartmanFrom: Sean Christopherson <[email protected]>
[ Upstream commit 311a06593b9a3944a63ed176b95cb8d857f7c83b ]
Drop svm_set_cr4()'s explicit check CR4.VMXE now that common x86 handles the check by incorporating VMXE into the CR4 reserved bits, via kvm_cpu_caps. SVM obviously does not set X86_FEATURE_VMX.
No functional change intended.
Message-Id: <[email protected]>
--- arch/x86/kvm/svm/svm.c | 3 --- 1 file changed, 3 deletions(-)
arch/x86/kvm/svm/svm.c +0 -3
@@ -1697,9 +1697,6 @@ int svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)unsigned long host_cr4_mce =cr4_read_shadow () &X86_CR4_MCE ;unsigned long old_cr4 =to_svm (vcpu)->vmcb->save.cr4; -if (cr4 &X86_CR4_VMXE ) -return 1 ; -if (npt_enabled && ((old_cr4 ^ cr4) &X86_CR4_PGE ))svm_flush_tlb (vcpu);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 502/545 KVM: x86: Move vendor CR4 validity check to dedicated kvm_x86_ops hook
In reply to Greg Kroah-HartmanFrom: Sean Christopherson <[email protected]>
[ Upstream commit c2fe3cd4604ac87c587db05d41843d667dc43815 ]
Split out VMX's checks on CR4.VMXE to a dedicated hook, .is_valid_cr4(), and invoke the new hook from kvm_valid_cr4(). This fixes an issue where KVM_SET_SREGS would return success while failing to actually set CR4.
Fixing the issue by explicitly checking kvm_x86_ops.set_cr4()'s return in __set_sregs() is not a viable option as KVM has already stuffed a variety of vCPU state.
Note, kvm_valid_cr4() and is_valid_cr4() have different return types and inverted semantics. This will be remedied in a future patch.
Message-Id: <[email protected]>
--- arch/x86/include/asm/kvm_host.h | 3 ++- arch/x86/kvm/svm/svm.c | 9 +++++++-- arch/x86/kvm/svm/svm.h | 2 +- arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/vmx.c | 31 ++++++++++++++++++------------- arch/x86/kvm/vmx/vmx.h | 2 +- arch/x86/kvm/x86.c | 6 ++++-- 7 files changed, 34 insertions(+), 21 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -1
@@ -1117,7 +1117,8 @@ struct kvm_x86_ops { struct kvm_segment *var, int seg);void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu,int *db,int *l);void (*set_cr0)(struct kvm_vcpu *vcpu,unsigned long cr0); -int (*set_cr4)(struct kvm_vcpu *vcpu,unsigned long cr4); +bool (*is_valid_cr4)(struct kvm_vcpu *vcpu,unsigned long cr0); +void (*set_cr4)(struct kvm_vcpu *vcpu,unsigned long cr4);int (*set_efer)(struct kvm_vcpu *vcpu,u64 efer);void (*get_idt)(struct kvm_vcpu *vcpu,struct desc_ptr *dt);void (*set_idt)(struct kvm_vcpu *vcpu,struct desc_ptr *dt);
arch/x86/kvm/svm/svm.c +7 -2
@@ -1692,7 +1692,12 @@ void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)update_cr0_intercept (svm); } -int svm_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4) +static bool svm_is_valid_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4) +{ +return true; +} + +void svm_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4) {unsigned long host_cr4_mce =cr4_read_shadow () &X86_CR4_MCE ;unsigned long old_cr4 =to_svm (vcpu)->vmcb->save.cr4;
@@ -1706,7 +1711,6 @@ int svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) cr4 |= host_cr4_mce;to_svm (vcpu)->vmcb->save.cr4 = cr4;vmcb_mark_dirty (to_svm (vcpu)->vmcb,VMCB_CR ); -return 0 ; } static void svm_set_segment(struct kvm_vcpu *vcpu,
@@ -4238,6 +4242,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .get_cpl = svm_get_cpl, .get_cs_db_l_bits = kvm_get_cs_db_l_bits, .set_cr0 = svm_set_cr0, + .is_valid_cr4 = svm_is_valid_cr4, .set_cr4 = svm_set_cr4, .set_efer = svm_set_efer, .get_idt = svm_get_idt,
arch/x86/kvm/svm/svm.h +1 -1
@@ -355,7 +355,7 @@ void svm_vcpu_free_msrpm(u32 *msrpm);int svm_set_efer (struct kvm_vcpu *vcpu,u64 efer);void svm_set_cr0 (struct kvm_vcpu *vcpu,unsigned long cr0); -int svm_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4); +void svm_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4);void svm_flush_tlb (struct kvm_vcpu *vcpu);void disable_nmi_singlestep (struct vcpu_svm *svm);bool svm_smi_blocked (struct kvm_vcpu *vcpu);
arch/x86/kvm/vmx/nested.c +1 -1
@@ -4879,7 +4879,7 @@ static int handle_vmon(struct kvm_vcpu *vcpu)/* * The Intel VMX Instruction Reference lists a bunch of bits that are * prerequisite to running VMXON, most notably cr4.VMXE must be set to -* 1 (see vmx_set_cr4() for when we allow the guest to set this). +* 1 (see vmx_is_valid_cr4() for when we allow the guest to set this). * Otherwise, we should fail with #UD. But most faulting conditions * have already been checked by hardware, prior to the VM-exit for * VMXON. We do test guest cr4.VMXE because processor CR4 always has
arch/x86/kvm/vmx/vmx.c +18 -13
@@ -3183,7 +3183,23 @@ static void vmx_load_mmu_pgd(struct kvm_vcpu *vcpu, unsigned long pgd,vmcs_writel (GUEST_CR3 , guest_cr3); } -int vmx_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4) +static bool vmx_is_valid_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4) +{ +/* +* We operate under the default treatment of SMM, so VMX cannot be +* enabled under SMM. Note, whether or not VMXE is allowed at all is +* handled by kvm_valid_cr4(). +*/ +if ((cr4 &X86_CR4_VMXE ) &&is_smm (vcpu)) +return false; + +if (to_vmx (vcpu)->nested.vmxon && !nested_cr4_valid (vcpu, cr4)) +return false; + +return true; +} + +void vmx_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4) {struct vcpu_vmx *vmx =to_vmx (vcpu);/*
@@ -3211,17 +3227,6 @@ int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) } } -/* -* We operate under the default treatment of SMM, so VMX cannot be -* enabled under SMM. Note, whether or not VMXE is allowed at all is -* handled by kvm_valid_cr4(). -*/ -if ((cr4 &X86_CR4_VMXE ) &&is_smm (vcpu)) -return 1 ; - -if (vmx->nested.vmxon && !nested_cr4_valid (vcpu, cr4)) -return 1 ; - vcpu->arch.cr4 = cr4;kvm_register_mark_available (vcpu,VCPU_EXREG_CR4 );
@@ -3252,7 +3257,6 @@ int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)vmcs_writel (CR4_READ_SHADOW , cr4);vmcs_writel (GUEST_CR4 , hw_cr4); -return 0 ; }void vmx_get_segment (struct kvm_vcpu *vcpu,struct kvm_segment *var,int seg)
@@ -7748,6 +7752,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .get_cpl = vmx_get_cpl, .get_cs_db_l_bits = vmx_get_cs_db_l_bits, .set_cr0 = vmx_set_cr0, + .is_valid_cr4 = vmx_is_valid_cr4, .set_cr4 = vmx_set_cr4, .set_efer = vmx_set_efer, .get_idt = vmx_get_idt,
arch/x86/kvm/vmx/vmx.h +1 -1
@@ -347,7 +347,7 @@ u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu);void vmx_set_interrupt_shadow (struct kvm_vcpu *vcpu,int mask);int vmx_set_efer (struct kvm_vcpu *vcpu,u64 efer);void vmx_set_cr0 (struct kvm_vcpu *vcpu,unsigned long cr0); -int vmx_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4); +void vmx_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4);void set_cr4_guest_host_mask (struct vcpu_vmx *vmx);void ept_save_pdptrs (struct kvm_vcpu *vcpu);void vmx_get_segment (struct kvm_vcpu *vcpu,struct kvm_segment *var,int seg);
arch/x86/kvm/x86.c +4 -2
@@ -986,6 +986,9 @@ int kvm_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)if (cr4 & vcpu->arch.cr4_guest_rsvd_bits)return -EINVAL ; +if (!kvm_x86_ops.is_valid_cr4 (vcpu, cr4)) +return -EINVAL ; +return 0 ; }EXPORT_SYMBOL_GPL (kvm_valid_cr4);
@@ -1020,8 +1023,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)return 1 ; } -if (kvm_x86_ops.set_cr4 (vcpu, cr4)) -return 1 ; + kvm_x86_ops.set_cr4 (vcpu, cr4);if (((cr4 ^ old_cr4) & mmu_role_bits) || (!(cr4 &X86_CR4_PCIDE ) && (old_cr4 &X86_CR4_PCIDE )))
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 503/545 KVM: nVMX: Inject #UD if VMXON is attempted with incompatible CR0/CR4
In reply to Greg Kroah-HartmanFrom: Sean Christopherson <[email protected]>
[ Upstream commit c7d855c2aff2d511fd60ee2e356134c4fb394799 ]
Inject a #UD if L1 attempts VMXON with a CR0 or CR4 that is disallowed per the associated nested VMX MSRs' fixed0/1 settings. KVM cannot rely on hardware to perform the checks, even for the few checks that have higher priority than VM-Exit, as (a) KVM may have forced CR0/CR4 bits in hardware while running the guest, (b) there may incompatible CR0/CR4 bits that have lower priority than VM-Exit, e.g. CR0.NE, and (c) userspace may have further restricted the allowed CR0/CR4 values by manipulating the guest's nested VMX MSRs.
Note, despite a very strong desire to throw shade at Jim, commit 70f3aac964ae ("kvm: nVMX: Remove superfluous VMX instruction fault checks") is not to blame for the buggy behavior (though the comment...). That commit only removed the CR0.PE, EFLAGS.VM, and COMPATIBILITY mode checks (though it did erroneously drop the CPL check, but that has already been remedied). KVM may force CR0.PE=1, but will do so only when also forcing EFLAGS.VM=1 to emulate Real Mode, i.e. hardware will still #UD.
Message-Id: <[email protected]>
--- arch/x86/kvm/vmx/nested.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
arch/x86/kvm/vmx/nested.c +14 -9
@@ -4877,20 +4877,25 @@ static int handle_vmon(struct kvm_vcpu *vcpu) | FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX;/* -* The Intel VMX Instruction Reference lists a bunch of bits that are -* prerequisite to running VMXON, most notably cr4.VMXE must be set to -* 1 (see vmx_is_valid_cr4() for when we allow the guest to set this). -* Otherwise, we should fail with #UD. But most faulting conditions -* have already been checked by hardware, prior to the VM-exit for -* VMXON. We do test guest cr4.VMXE because processor CR4 always has -* that bit set to 1 in non-root mode. +* Note, KVM cannot rely on hardware to perform the CR0/CR4 #UD checks +* that have higher priority than VM-Exit (see Intel SDM's pseudocode +* for VMXON), as KVM must load valid CR0/CR4 values into hardware while +* running the guest, i.e. KVM needs to check the _guest_ values. +* +* Rely on hardware for the other two pre-VM-Exit checks, !VM86 and +* !COMPATIBILITY modes. KVM may run the guest in VM86 to emulate Real +* Mode, but KVM will never take the guest out of those modes. */ -if (!kvm_read_cr4_bits (vcpu,X86_CR4_VMXE )) { +if (!nested_host_cr0_valid (vcpu,kvm_read_cr0 (vcpu)) || + !nested_host_cr4_valid (vcpu,kvm_read_cr4 (vcpu))) {kvm_queue_exception (vcpu,UD_VECTOR );return 1 ; } -/* CPL=0 must be checked manually. */ +/* +* CPL=0 and all other checks that are lower priority than VM-Exit must +* be checked manually. +*/ if (vmx_get_cpl (vcpu)) {kvm_inject_gp (vcpu,0 );return 1 ;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 504/545 KVM: x86/pmu: preserve IA32_PERF_CAPABILITIES across CPUID refresh
In reply to Greg Kroah-HartmanFrom: Paolo Bonzini <[email protected]>
[ Upstream commit a755753903a40d982f6dd23d65eb96b248a2577a ]
Once MSR_IA32_PERF_CAPABILITIES is changed via vmx_set_msr(), the value should not be changed by cpuid(). To ensure that the new value is kept, the default initialization path is moved to intel_pmu_init(). The effective value of the MSR will be 0 if PDCM is clear, however.
--- arch/x86/kvm/vmx/pmu_intel.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
arch/x86/kvm/vmx/pmu_intel.c +10 -6
@@ -153,12 +153,17 @@ static struct kvm_pmc *intel_rdpmc_ecx_to_pmc(struct kvm_vcpu *vcpu,return &counters[array_index_nospec (idx, num_counters)]; } -static inline bool fw_writes_is_enabled (struct kvm_vcpu *vcpu) +static inline u64 vcpu_get_perf_capabilities (struct kvm_vcpu *vcpu) {if (!guest_cpuid_has (vcpu,X86_FEATURE_PDCM )) -return false; +return 0 ; -return vcpu->arch.perf_capabilities &PMU_CAP_FW_WRITES ; +return vcpu->arch.perf_capabilities; +} + +static inline bool fw_writes_is_enabled (struct kvm_vcpu *vcpu) +{ +return (vcpu_get_perf_capabilities (vcpu) &PMU_CAP_FW_WRITES ) !=0 ; }static inline struct kvm_pmc *get_fw_gp_pmc (struct kvm_pmu *pmu,u32 msr)
@@ -328,7 +333,6 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) pmu->counter_bitmask[KVM_PMC_FIXED ] =0 ; pmu->version =0 ; pmu->reserved_bits =0xffffffff00200000ull ; - vcpu->arch.perf_capabilities =0 ; entry =kvm_find_cpuid_entry (vcpu,0xa ,0 );if (!entry)
@@ -341,8 +345,6 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)return ;perf_get_x86_pmu_capability (&x86_pmu); -if (guest_cpuid_has (vcpu,X86_FEATURE_PDCM )) - vcpu->arch.perf_capabilities =vmx_get_perf_capabilities (); pmu->nr_arch_gp_counters =min_t (int, eax.split.num_counters, x86_pmu.num_counters_gp);
@@ -406,6 +408,8 @@ static void intel_pmu_init(struct kvm_vcpu *vcpu) pmu->fixed_counters[i].idx = i +INTEL_PMC_IDX_FIXED ; pmu->fixed_counters[i].current_config =0 ; } + + vcpu->arch.perf_capabilities =vmx_get_perf_capabilities (); }static void intel_pmu_reset (struct kvm_vcpu *vcpu)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 505/545 KVM: x86/pmu: Use binary search to check filtered events
In reply to Greg Kroah-HartmanFrom: Jim Mattson <[email protected]>
[ Upstream commit 7ff775aca48adc854436b92c060e5eebfffb6a4a ]
The PMU event filter may contain up to 300 events. Replace the linear search in reprogram_gp_counter() with a binary search.
Message-Id: <[email protected]>
--- arch/x86/kvm/pmu.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
arch/x86/kvm/pmu.c +19 -11
@@ -13,6 +13,8 @@#include <linux/types.h> #include <linux/kvm_host.h> #include <linux/perf_event.h> +#include <linux/bsearch.h> +#include <linux/sort.h> #include <asm/perf_event.h> #include "x86.h" #include "cpuid.h"
@@ -168,13 +170,17 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc)return true; } +static int cmp_u64 (const void *a,const void *b) +{ +return *(__u64 *)a - *(__u64 *)b; +} +void reprogram_gp_counter (struct kvm_pmc *pmc,u64 eventsel) {u64 config;u32 type =PERF_TYPE_RAW ;struct kvm *kvm = pmc->vcpu->kvm;struct kvm_pmu_event_filter *filter; -int i;bool allow_event = true;if (eventsel &ARCH_PERFMON_EVENTSEL_PIN_CONTROL )
@@ -189,16 +195,13 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel) filter =srcu_dereference (kvm->arch.pmu_event_filter, &kvm->srcu);if (filter) { -for (i =0 ; i < filter->nevents; i++) -if (filter->events[i] == - (eventsel &AMD64_RAW_EVENT_MASK_NB )) -break ; -if (filter->action ==KVM_PMU_EVENT_ALLOW && - i == filter->nevents) - allow_event = false; -if (filter->action ==KVM_PMU_EVENT_DENY && - i < filter->nevents) - allow_event = false; +__u64 key = eventsel &AMD64_RAW_EVENT_MASK_NB ; + +if (bsearch (&key, filter->events, filter->nevents, +sizeof (__u64), cmp_u64)) + allow_event = filter->action ==KVM_PMU_EVENT_ALLOW ; +else + allow_event = filter->action ==KVM_PMU_EVENT_DENY ; }if (!allow_event)return ;
@@ -507,6 +510,11 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp)/* Ensure nevents can't be changed between the user copies. */ *filter = tmp; +/* +* Sort the in-kernel list so that we can search it with bsearch. +*/ +sort (&filter->events, filter->nevents,sizeof (__u64), cmp_u64,NULL ); +mutex_lock (&kvm->lock); filter =rcu_replace_pointer (kvm->arch.pmu_event_filter, filter,mutex_is_locked (&kvm->lock));
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 506/545 KVM: x86/pmu: Use different raw event masks for AMD and Intel
In reply to Greg Kroah-HartmanFrom: Jim Mattson <[email protected]>
[ Upstream commit 95b065bf5c431c06c68056a03a5853b660640ecc ]
The third nybble of AMD's event select overlaps with Intel's IN_TX and IN_TXCP bits. Therefore, we can't use AMD64_RAW_EVENT_MASK on Intel platforms that support TSX.
Declare a raw_event_mask in the kvm_pmu structure, initialize it in the vendor-specific pmu_refresh() functions, and use that mask for PERF_TYPE_RAW configurations in reprogram_gp_counter().
Message-Id: <[email protected]>
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/pmu.c | 3 ++- arch/x86/kvm/svm/pmu.c | 1 + arch/x86/kvm/vmx/pmu_intel.c | 1 + 4 files changed, 5 insertions(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -439,6 +439,7 @@ struct kvm_pmu {u64 global_ctrl_mask;u64 global_ovf_ctrl_mask;u64 reserved_bits; +u64 raw_event_mask;u8 version;struct kvm_pmc gp_counters[INTEL_PMC_MAX_GENERIC ];struct kvm_pmc fixed_counters[INTEL_PMC_MAX_FIXED ];
arch/x86/kvm/pmu.c +2 -1
@@ -181,6 +181,7 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)u32 type =PERF_TYPE_RAW ;struct kvm *kvm = pmc->vcpu->kvm;struct kvm_pmu_event_filter *filter; +struct kvm_pmu *pmu =vcpu_to_pmu (pmc->vcpu);bool allow_event = true;if (eventsel &ARCH_PERFMON_EVENTSEL_PIN_CONTROL )
@@ -217,7 +218,7 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel) }if (type ==PERF_TYPE_RAW ) - config = eventsel &AMD64_RAW_EVENT_MASK ; + config = eventsel & pmu->raw_event_mask;if (pmc->current_config == eventsel &&pmc_resume_counter (pmc))return ;
arch/x86/kvm/svm/pmu.c +1 -0
@@ -295,6 +295,7 @@ static void amd_pmu_refresh(struct kvm_vcpu *vcpu) pmu->counter_bitmask[KVM_PMC_GP ] = ((u64 )1 <<48 ) -1 ; pmu->reserved_bits =0xfffffff000280000ull ; + pmu->raw_event_mask =AMD64_RAW_EVENT_MASK ; pmu->version =1 ;/* not applicable to AMD; but clean them to prevent any fall out */ pmu->counter_bitmask[KVM_PMC_FIXED ] =0 ;
arch/x86/kvm/vmx/pmu_intel.c +1 -0
@@ -333,6 +333,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) pmu->counter_bitmask[KVM_PMC_FIXED ] =0 ; pmu->version =0 ; pmu->reserved_bits =0xffffffff00200000ull ; + pmu->raw_event_mask =X86_RAW_EVENT_MASK ; entry =kvm_find_cpuid_entry (vcpu,0xa ,0 );if (!entry)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 507/545 KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter
In reply to Greg Kroah-HartmanFrom: Like Xu <[email protected]>
[ Upstream commit 2c985527dd8d283e786ad7a67e532ef7f6f00fac ]
The mask value of fixed counter control register should be dynamic adjusted with the number of fixed counters. This patch introduces a variable that includes the reserved bits of fixed counter control registers. This is a generic code refactoring.
Message-Id: <[email protected]>
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/pmu_intel.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -432,6 +432,7 @@ struct kvm_pmu {unsigned nr_arch_fixed_counters;unsigned available_event_types;u64 fixed_ctr_ctrl; +u64 fixed_ctr_ctrl_mask;u64 global_ctrl;u64 global_status;u64 global_ovf_ctrl;
arch/x86/kvm/vmx/pmu_intel.c +5 -1
@@ -259,7 +259,7 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)case MSR_CORE_PERF_FIXED_CTR_CTRL :if (pmu->fixed_ctr_ctrl == data)return 0 ; -if (!(data &0xfffffffffffff444ull )) { +if (!(data & pmu->fixed_ctr_ctrl_mask)) {reprogram_fixed_counters (pmu, data);return 0 ; }
@@ -326,6 +326,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)struct kvm_cpuid_entry2 *entry;union cpuid10_eax eax;union cpuid10_edx edx; +int i; pmu->nr_arch_gp_counters =0 ; pmu->nr_arch_fixed_counters =0 ;
@@ -334,6 +335,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) pmu->version =0 ; pmu->reserved_bits =0xffffffff00200000ull ; pmu->raw_event_mask =X86_RAW_EVENT_MASK ; + pmu->fixed_ctr_ctrl_mask = ~0ull ; entry =kvm_find_cpuid_entry (vcpu,0xa ,0 );if (!entry)
@@ -367,6 +369,8 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) ((u64 )1 << edx.split.bit_width_fixed) -1 ; } +for (i =0 ; i < pmu->nr_arch_fixed_counters; i++) + pmu->fixed_ctr_ctrl_mask &= ~(0xbull << (i *4 )); pmu->global_ctrl = ((1ull << pmu->nr_arch_gp_counters) -1 ) | (((1ull << pmu->nr_arch_fixed_counters) -1 ) <<INTEL_PMC_IDX_FIXED ); pmu->global_ctrl_mask = ~pmu->global_ctrl;
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 508/545 KVM: VMX: Mark all PERF_GLOBAL_(OVF)_CTRL bits reserved if theres no vPMU
In reply to Greg Kroah-HartmanFrom: Sean Christopherson <[email protected]>
[ Upstream commit 93255bf92939d948bc86d81c6bb70bb0fecc5db1 ]
Mark all MSR_CORE_PERF_GLOBAL_CTRL and MSR_CORE_PERF_GLOBAL_OVF_CTRL bits as reserved if there is no guest vPMU. The nVMX VM-Entry consistency checks do not check for a valid vPMU prior to consuming the masks via kvm_valid_perf_global_ctrl(), i.e. may incorrectly allow a non-zero mask to be loaded via VM-Enter or VM-Exit (well, attempted to be loaded, the actual MSR load will be rejected by intel_is_valid_msr()).
Message-Id: <[email protected]>
--- arch/x86/kvm/vmx/pmu_intel.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kvm/vmx/pmu_intel.c +2 -0
@@ -335,6 +335,8 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) pmu->version =0 ; pmu->reserved_bits =0xffffffff00200000ull ; pmu->raw_event_mask =X86_RAW_EVENT_MASK ; + pmu->global_ctrl_mask = ~0ull ; + pmu->global_ovf_ctrl_mask = ~0ull ; pmu->fixed_ctr_ctrl_mask = ~0ull ; entry =kvm_find_cpuid_entry (vcpu,0xa ,0 );
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 509/545 KVM: x86/pmu: Ignore pmu->global_ctrl check if vPMU doesnt support global_ctrl
In reply to Greg Kroah-HartmanFrom: Like Xu <[email protected]>
[ Upstream commit 98defd2e17803263f49548fea930cfc974d505aa ]
MSR_CORE_PERF_GLOBAL_CTRL is introduced as part of Architecture PMU V2, as indicated by Intel SDM 19.2.2 and the intel_is_valid_msr() function.
So in the absence of global_ctrl support, all PMCs are enabled as AMD does.
Message-Id: <[email protected]>
--- arch/x86/kvm/vmx/pmu_intel.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kvm/vmx/pmu_intel.c +3 -0
@@ -104,6 +104,9 @@ static bool intel_pmc_is_enabled(struct kvm_pmc *pmc) {struct kvm_pmu *pmu =pmc_to_pmu (pmc); +if (pmu->version <2 ) +return true; +return test_bit (pmc->idx, (unsigned long *)&pmu->global_ctrl); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 510/545 xen-blkback: fix persistent grants negotiation
In reply to Greg Kroah-HartmanFrom: SeongJae Park <[email protected]>
commit fc9be616bb8f3ed9cf560308f86904f5c06be205 upstream.
Persistent grants feature can be used only when both backend and the frontend supports the feature. The feature was always supported by 'blkback', but commit aac8a70db24b ("xen-blkback: add a parameter for disabling of persistent grants") has introduced a parameter for disabling it runtime.
To avoid the parameter be updated while being used by 'blkback', the commit caches the parameter into 'vbd->feature_gnt_persistent' in 'xen_vbd_create()', and then check if the guest also supports the feature and finally updates the field in 'connect_ring()'.
However, 'connect_ring()' could be called before 'xen_vbd_create()', so later execution of 'xen_vbd_create()' can wrongly overwrite 'true' to 'vbd->feature_gnt_persistent'. As a result, 'blkback' could try to use 'persistent grants' feature even if the guest doesn't support the feature.
This commit fixes the issue by moving the parameter value caching to 'xen_blkif_alloc()', which allocates the 'blkif'. Because the struct embeds 'vbd' object, which will be used by 'connect_ring()' later, this should be called before 'connect_ring()' and therefore this should be the right and safe place to do the caching.
--- drivers/block/xen-blkback/xenbus.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/block/xen-blkback/xenbus.c +7 -8
@@ -157,6 +157,11 @@ static int xen_blkif_alloc_rings(structreturn 0 ; } +/* Enable the persistent grants feature. */ +static bool feature_persistent = true; +module_param (feature_persistent, bool,0644 ); +MODULE_PARM_DESC (feature_persistent,"Enables the persistent grants feature" ); +static struct xen_blkif *xen_blkif_alloc (domid_t domid) {struct xen_blkif *blkif;
@@ -181,6 +186,8 @@ static struct xen_blkif *xen_blkif_alloc__module_get (THIS_MODULE );INIT_WORK (&blkif->free_work, xen_blkif_deferred_free); + blkif->vbd.feature_gnt_persistent = feature_persistent; +return blkif; }
@@ -472,12 +479,6 @@ static void xen_vbd_free(struct xen_vbd vbd->bdev =NULL ; } -/* Enable the persistent grants feature. */ -static bool feature_persistent = true; -module_param (feature_persistent, bool,0644 ); -MODULE_PARM_DESC (feature_persistent, -"Enables the persistent grants feature" ); -static int xen_vbd_create (struct xen_blkif *blkif,blkif_vdev_t handle,unsigned major,unsigned minor,int readonly,int cdrom)
@@ -523,8 +524,6 @@ static int xen_vbd_create(struct xen_blkif (q &&blk_queue_secure_erase (q)) vbd->discard_secure = true; - vbd->feature_gnt_persistent = feature_persistent; -pr_debug ("Successful creation of handle=%04x (dom=%u)\n" , handle, blkif->domid);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 511/545 xen-blkback: Apply feature_persistent parameter when connect
In reply to Greg Kroah-HartmanFrom: Maximilian Heyne <[email protected]>
commit e94c6101e151b019b8babc518ac2a6ada644a5a1 upstream.
In some use cases[1], the backend is created while the frontend doesn't support the persistent grants feature, but later the frontend can be changed to support the feature and reconnect. In the past, 'blkback' enabled the persistent grants feature since it unconditionally checked if frontend supports the persistent grants feature for every connect ('connect_ring()') and decided whether it should use persistent grans or not.
However, commit aac8a70db24b ("xen-blkback: add a parameter for disabling of persistent grants") has mistakenly changed the behavior. It made the frontend feature support check to not be repeated once it shown the 'feature_persistent' as 'false', or the frontend doesn't support persistent grants.
This commit changes the behavior of the parameter to make effect for every connect, so that the previous workflow can work again as expected.
--- Documentation/ABI/testing/sysfs-driver-xen-blkback | 2 +- drivers/block/xen-blkback/xenbus.c | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-)
Documentation/ABI/testing/sysfs-driver-xen-blkback +1 -1
@@ -42,5 +42,5 @@ KernelVersion: 5.10 Contact: SeongJae Park <[email protected]> Description: Whether to enable the persistent grants feature or not. Note - that this option only takes effect on newly created backends. + that this option only takes effect on newly connected backends. The default is Y (enable).
drivers/block/xen-blkback/xenbus.c +3 -6
@@ -186,8 +186,6 @@ static struct xen_blkif *xen_blkif_alloc__module_get (THIS_MODULE );INIT_WORK (&blkif->free_work, xen_blkif_deferred_free); - blkif->vbd.feature_gnt_persistent = feature_persistent; -return blkif; }
@@ -1090,10 +1088,9 @@ static int connect_ring(struct backend_ixenbus_dev_fatal (dev, err,"unknown fe protocol %s" , protocol);return -ENOSYS ; } -if (blkif->vbd.feature_gnt_persistent) - blkif->vbd.feature_gnt_persistent = -xenbus_read_unsigned (dev->otherend, -"feature-persistent" ,0 ); + + blkif->vbd.feature_gnt_persistent = feature_persistent && +xenbus_read_unsigned (dev->otherend,"feature-persistent" ,0 ); blkif->vbd.overflow_max_grants =0 ;
Greg Kroah-Hartman
maintainerPATCH 512/545 xen-blkfront: Apply feature_persistent parameter when connect
In reply to Greg Kroah-HartmanFrom: SeongJae Park <[email protected]>
commit 402c43ea6b34a1b371ffeed9adf907402569eaf5 upstream.
In some use cases[1], the backend is created while the frontend doesn't support the persistent grants feature, but later the frontend can be changed to support the feature and reconnect. In the past, 'blkback' enabled the persistent grants feature since it unconditionally checked if frontend supports the persistent grants feature for every connect ('connect_ring()') and decided whether it should use persistent grans or not.
However, commit aac8a70db24b ("xen-blkback: add a parameter for disabling of persistent grants") has mistakenly changed the behavior. It made the frontend feature support check to not be repeated once it shown the 'feature_persistent' as 'false', or the frontend doesn't support persistent grants.
Similar behavioral change has made on 'blkfront' by commit 74a852479c68 ("xen-blkfront: add a parameter for disabling of persistent grants"). This commit changes the behavior of the parameter to make effect for every connect, so that the previous behavior of 'blkfront' can be restored.
--- Documentation/ABI/testing/sysfs-driver-xen-blkfront | 2 +- drivers/block/xen-blkfront.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-driver-xen-blkfront +1 -1
@@ -15,5 +15,5 @@ KernelVersion: 5.10 Contact: SeongJae Park <[email protected]> Description: Whether to enable the persistent grants feature or not. Note - that this option only takes effect on newly created frontends. + that this option only takes effect on newly connected frontends. The default is Y (enable).
drivers/block/xen-blkfront.c +1 -3
@@ -2088,8 +2088,6 @@ static int blkfront_probe(struct xenbus_ info->vdevice = vdevice; info->connected =BLKIF_STATE_DISCONNECTED ; - info->feature_persistent = feature_persistent; -/* Front end dir is a number, which is used as the id. */ info->handle =simple_strtoul (strrchr (dev->nodename,'/' )+1 ,NULL ,0 );dev_set_drvdata (&dev->dev, info);
@@ -2393,7 +2391,7 @@ static void blkfront_gather_backend_featif (xenbus_read_unsigned (info->xbdev->otherend,"feature-discard" ,0 ))blkfront_setup_discard (info); -if (info->feature_persistent) +if (feature_persistent) info->feature_persistent = !!xenbus_read_unsigned (info->xbdev->otherend,"feature-persistent" ,0 );
Greg Kroah-Hartman
maintainerPATCH 513/545 KEYS: asymmetric: enforce SM2 signature use pkey algo
In reply to Greg Kroah-HartmanFrom: Tianjia Zhang <[email protected]>
commit 0815291a8fd66cdcf7db1445d4d99b0d16065829 upstream.
The signature verification of SM2 needs to add the Za value and recalculate sig->digest, which requires the detection of the pkey_algo in public_key_verify_signature(). As Eric Biggers said, the pkey_algo field in sig is attacker-controlled and should be use pkey->pkey_algo instead of sig->pkey_algo, and secondly, if sig->pkey_algo is NULL, it will also cause signature verification failure.
The software_key_determine_akcipher() already forces the algorithms are matched, so the SM3 algorithm is enforced in the SM2 signature, although this has been checked, we still avoid using any algorithm information in the signature as input.
--- crypto/asymmetric_keys/public_key.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
crypto/asymmetric_keys/public_key.c +5 -2
@@ -260,6 +260,10 @@ static int cert_sig_digest_update(constBUG_ON (!sig->data); +/* SM2 signatures always use the SM3 hash algorithm */ +if (!sig->hash_algo ||strcmp (sig->hash_algo,"sm3" ) !=0 ) +return -EINVAL ; + ret =sm2_compute_z_digest (tfm_pkey,SM2_DEFAULT_USERID ,SM2_DEFAULT_USERID_LEN , dgst);if (ret)
@@ -356,8 +360,7 @@ int public_key_verify_signature(const stif (ret) goto error_free_key; -if (sig->pkey_algo &&strcmp (sig->pkey_algo,"sm2" ) ==0 && - sig->data_size) { +if (strcmp (pkey->pkey_algo,"sm2" ) ==0 && sig->data_size) { ret =cert_sig_digest_update (sig, tfm);if (ret) goto error_free_key;
Greg Kroah-Hartman
maintainerPATCH 514/545 tpm: eventlog: Fix section mismatch for DEBUG_SECTION_MISMATCH
In reply to Greg Kroah-HartmanFrom: Huacai Chen <[email protected]>
commit bed4593645366ad7362a3aa7bc0d100d8d8236a8 upstream.
If DEBUG_SECTION_MISMATCH enabled, __calc_tpm2_event_size() will not be inlined, this cause section mismatch like this:
WARNING: modpost: vmlinux.o(.text.unlikely+0xe30c): Section mismatch in reference from the variable L0 to the function .init.text:early_ioremap() The function L0() references
the function __init early_memremap().
This is often because L0 lacks a __init
annotation or the annotation of early_ioremap is wrong.
Fix it by using __always_inline instead of inline for the called-once function __calc_tpm2_event_size().
--- include/linux/tpm_eventlog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/tpm_eventlog.h +1 -1
@@ -157,7 +157,7 @@ struct tcg_algorithm_info {* Return: size of the event on success, 0 on failure */ -static inline int __calc_tpm2_event_size (struct tcg_pcr_event2_head *event, +static __always_inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,struct tcg_pcr_event *event_header,bool do_mapping) {
Re: [PATCH 5.10 514/545] tpm: eventlog: Fix section mismatch for DEBUG_SECTION_MISMATCH
Quoted 31 lines · Greg Kroah-Hartman
From: Huacai Chen <[email protected]>
commit
bed4593645366ad7362a3aa7bc0d100d8d8236a8upstream.If
DEBUG_SECTION_MISMATCHenabled,__calc_tpm2_event_size()will not be inlined, this cause section mismatch like this:WARNING: modpost:
vmlinux.o(.text.unlikely+0xe30c): Section mismatch in reference from the variable L0 to the function .init.text:early_ioremap() The functionL0()references
the function__initearly_memremap().
This is often because L0 lacks a__init
annotation or the annotation ofearly_ioremapis wrong.Fix it by using
__always_inlineinstead of inline for the called-once function__calc_tpm2_event_size().Fixes 44038bc514a2 ("tpm: Abstract crypto agile event size calculations")Cc [email protected] # v5.3Reported-by WANG Xuerui <[email protected]>Signed-off-by Huacai Chen <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- include/linux/tpm_eventlog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/tpm_eventlog.h struct tcg_algorithm_info { · line 163
Quoted 8 lines
include/linux/tpm_eventlog.h +1
-1@@ -157,7 +157,7 @@ struct tcg_algorithm_info {* Return: size of the event on success, 0 on failure */ -static inline int __calc_tpm2_event_size (struct tcg_pcr_event2_head *event, +static __always_inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,struct tcg_pcr_event *event_header,bool do_mapping) {
Thank you. I'll pick this.
BR, Jarkko
Jarkko Sakkinen
maintainerRe: [PATCH 5.10 514/545] tpm: eventlog: Fix section mismatch for DEBUG_SECTION_MISMATCH
Quoted 43 lines · Jarkko Sakkinen
Quoted 31 lines · Greg Kroah-Hartman
From: Huacai Chen <[email protected]>
commit
bed4593645366ad7362a3aa7bc0d100d8d8236a8upstream.If
DEBUG_SECTION_MISMATCHenabled,__calc_tpm2_event_size()will not be inlined, this cause section mismatch like this:WARNING: modpost:
vmlinux.o(.text.unlikely+0xe30c): Section mismatch in reference from the variable L0 to the function .init.text:early_ioremap() The functionL0()references
the function__initearly_memremap().
This is often because L0 lacks a__init
annotation or the annotation ofearly_ioremapis wrong.Fix it by using
__always_inlineinstead of inline for the called-once function__calc_tpm2_event_size().Fixes 44038bc514a2 ("tpm: Abstract crypto agile event size calculations")Cc [email protected] # v5.3Reported-by WANG Xuerui <[email protected]>Signed-off-by Huacai Chen <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- include/linux/tpm_eventlog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/tpm_eventlog.h struct tcg_algorithm_info { · line 163
Quoted 8 lines
include/linux/tpm_eventlog.h +1
-1@@ -157,7 +157,7 @@ struct tcg_algorithm_info {* Return: size of the event on success, 0 on failure */ -static inline int __calc_tpm2_event_size (struct tcg_pcr_event2_head *event, +static __always_inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,struct tcg_pcr_event *event_header,bool do_mapping) {Thank you. I'll pick this.
Quoted 3 lines
Reviewed-by Jarkko Sakkinen <[email protected]>BR, Jarkko
Uh oh, sorry too many emails in one sit.
BR, Jarkko
Greg Kroah-Hartman
maintainerPATCH 515/545 tracing: Use a struct alignof to determine trace event field alignment
In reply to Greg Kroah-HartmanFrom: Steven Rostedt (Google) <[email protected]>
commit 4c3d2f9388d36eb28640a220a6f908328442d873 upstream.
alignof() gives an alignment of types as they would be as standalone variables. But alignment in structures might be different, and when building the fields of events, the alignment must be the actual alignment otherwise the field offsets may not match what they actually are.
This caused trace-cmd to crash, as libtraceevent did not check if the field offset was bigger than the event. The write_msr and read_msr events on 32 bit had their fields incorrect, because it had a u64 field between two ints. alignof(u64) would give 8, but the u64 field was at a 4 byte alignment.
Define a macro as:
ALIGN_STRUCTFIELD(type) ((int)(offsetof(struct {char a; type b;}, b)))
which gives the actual alignment of types in a structure.
--- include/trace/trace_events.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
include/trace/trace_events.h +5 -3
@@ -400,16 +400,18 @@ static struct trace_event_functions trac#include TRACE_INCLUDE (TRACE_INCLUDE_FILE ) +#define ALIGN_STRUCTFIELD (type) ((int)(offsetof(struct {char a; type b;}, b))) +#undef __field_ext#define __field_ext (_type, _item, _filter_type) { \ .type = #_type, .name = #_item, \ - .size = sizeof(_type), .align = __alignof__(_type), \ + .size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type), \ .is_signed = is_signed_type(_type), .filter_type = _filter_type },#undef __field_struct_ext#define __field_struct_ext (_type, _item, _filter_type) { \ .type = #_type, .name = #_item, \ - .size = sizeof(_type), .align = __alignof__(_type), \ + .size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type), \ 0, .filter_type = _filter_type },#undef __field
@@ -421,7 +423,7 @@ static struct trace_event_functions trac#undef __array#define __array (_type, _item, _len) { \ .type = #_type"["__stringify(_len)"]", .name = #_item, \ - .size = sizeof(_type[_len]), .align = __alignof__(_type), \ + .size = sizeof(_type[_len]), .align = ALIGN_STRUCTFIELD(_type), \ .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },#undef __dynamic_array
Greg Kroah-Hartman
maintainerPATCH 516/545 ext4: check if directory block is within i_size
In reply to Greg Kroah-HartmanFrom: Lukas Czerner <[email protected]>
commit 65f8ea4cd57dbd46ea13b41dc8bac03176b04233 upstream.
Currently ext4 directory handling code implicitly assumes that the directory blocks are always within the i_size. In fact ext4_append() will attempt to allocate next directory block based solely on i_size and the i_size is then appropriately increased after a successful allocation.
However, for this to work it requires i_size to be correct. If, for any reason, the directory inode i_size is corrupted in a way that the directory tree refers to a valid directory block past i_size, we could end up corrupting parts of the directory tree structure by overwriting already used directory blocks when modifying the directory.
Fix it by catching the corruption early in __ext4_read_dirblock().
Addresses Red-Hat-Bugzilla: #2070205
CVE: CVE-2022-1184
--- fs/ext4/namei.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/ext4/namei.c +7 -0
@@ -109,6 +109,13 @@ static struct buffer_head *__ext4_read_dstruct ext4_dir_entry *dirent;int is_dx_block =0 ; +if (block >= inode->i_size) { +ext4_error_inode (inode, func, line, block, +"Attempting to read directory block (%u) that is past i_size (%llu)" , + block, inode->i_size); +return ERR_PTR (-EFSCORRUPTED ); + } +if (ext4_simulate_fail (inode->i_sb,EXT4_SIM_DIRBLOCK_EIO )) bh =ERR_PTR (-EIO );else
Greg Kroah-Hartman
maintainerPATCH 517/545 ext4: add EXT4_INODE_HAS_XATTR_SPACE macro in xattr.h
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 179b14152dcb6a24c3415200603aebca70ff13af upstream.
When adding an xattr to an inode, we must ensure that the inode_size is not less than EXT4_GOOD_OLD_INODE_SIZE + extra_isize + pad. Otherwise, the end position may be greater than the start position, resulting in UAF.
--- fs/ext4/xattr.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
fs/ext4/xattr.h +13 -0
@@ -95,6 +95,19 @@ struct ext4_xattr_entry {#define EXT4_ZERO_XATTR_VALUE ((void *)-1) +/* +* If we want to add an xattr to the inode, we should make sure that +* i_extra_isize is not 0 and that the inode size is not less than +* EXT4_GOOD_OLD_INODE_SIZE + extra_isize + pad. +* EXT4_GOOD_OLD_INODE_SIZE extra_isize header entry pad data +* |--------------------------|------------|------|---------|---|-------| +*/ +#define EXT4_INODE_HAS_XATTR_SPACE (inode) \ + ((EXT4_I(inode)->i_extra_isize != 0) && \ + (EXT4_GOOD_OLD_INODE_SIZE + EXT4_I(inode)->i_extra_isize + \ + sizeof(struct ext4_xattr_ibody_header) + EXT4_XATTR_PAD <= \ + EXT4_INODE_SIZE((inode)->i_sb))) +struct ext4_xattr_info {const char *name;const void *value;
Greg Kroah-Hartman
maintainerPATCH 518/545 ext4: fix warning in ext4_iomap_begin as race between bmap and write
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
commit 51ae846cff568c8c29921b1b28eb2dfbcd4ac12d upstream.
We got issue as follows:
------------[ cut here ]------------ WARNING: CPU: 3 PID: 9310 at fs/ext4/inode.c:3441 ext4_iomap_begin+0x182/0x5d0 RIP: 0010:ext4_iomap_begin+0x182/0x5d0 RSP: 0018:ffff88812460fa08 EFLAGS: 00010293 RAX: ffff88811f168000 RBX: 0000000000000000 RCX: ffffffff97793c12 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000003 RBP: ffff88812c669160 R08: ffff88811f168000 R09: ffffed10258cd20f R10: ffff88812c669077 R11: ffffed10258cd20e R12: 0000000000000001 R13: 00000000000000a4 R14: 000000000000000c R15: ffff88812c6691ee FS: 00007fd0d6ff3740(0000) GS:ffff8883af180000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fd0d6dda290 CR3: 0000000104a62000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: iomap_apply+0x119/0x570 iomap_bmap+0x124/0x150 ext4_bmap+0x14f/0x250 bmap+0x55/0x80 do_vfs_ioctl+0x952/0xbd0 __x64_sys_ioctl+0xc6/0x170 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xa9
Above issue may happen as follows:
bmap write
bmap
ext4_bmap
iomap_bmap
ext4_iomap_begin
ext4_file_write_iter
ext4_buffered_write_iter
generic_perform_write
ext4_da_write_begin
ext4_da_write_inline_data_begin
ext4_prepare_inline_data
ext4_create_inline_data
ext4_set_inode_flag(inode,
EXT4_INODE_INLINE_DATA);
if (WARN_ON_ONCE(ext4_has_inline_data(inode))) ->trigger bug_onTo solved above issue hold inode lock in ext4_bamp.
--- fs/ext4/inode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
fs/ext4/inode.c +9 -3
@@ -3219,13 +3219,15 @@ static sector_t ext4_bmap(struct address {struct inode *inode = mapping->host;journal_t *journal; +sector_t ret =0 ;int err; +inode_lock_shared (inode);/* * We can get here for an inline file via the FIBMAP ioctl */ if (ext4_has_inline_data (inode)) -return 0 ; + goto out;if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY ) &&test_opt (inode->i_sb,DELALLOC )) {
@@ -3264,10 +3266,14 @@ static sector_t ext4_bmap(struct addressjbd2_journal_unlock_updates (journal);if (err) -return 0 ; + goto out; } -return iomap_bmap (mapping, block, &ext4_iomap_ops); + ret =iomap_bmap (mapping, block, &ext4_iomap_ops); + +out: +inode_unlock_shared (inode); +return ret; }static int ext4_readpage (struct file *file,struct page *page)
Greg Kroah-Hartman
maintainerPATCH 519/545 ext4: make sure ext4_append() always allocates new block
In reply to Greg Kroah-HartmanFrom: Lukas Czerner <[email protected]>
commit b8a04fe77ef1360fbf73c80fddbdfeaa9407ed1b upstream.
ext4_append() must always allocate a new block, otherwise we run the risk of overwriting existing directory block corrupting the directory tree in the process resulting in all manner of problems later on.
Add a sanity check to see if the logical block is already allocated and error out if it is.
--- fs/ext4/namei.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/ext4/namei.c +16 -0
@@ -54,6 +54,7 @@ static struct buffer_head *ext4_append(hstruct inode *inode, ext4_lblk_t *block) { + struct ext4_map_blocks map;struct buffer_head *bh;int err;
@@ -63,6 +64,21 @@ static struct buffer_head *ext4_append(hreturn ERR_PTR (-ENOSPC ); *block = inode->i_size >> inode->i_sb->s_blocksize_bits; + map.m_lblk = *block; + map.m_len =1 ; + +/* +* We're appending new directory block. Make sure the block is not +* allocated yet, otherwise we will end up corrupting the +* directory. +*/ + err =ext4_map_blocks (NULL , inode, &map,0 ); +if (err <0 ) +return ERR_PTR (err); +if (err) { +EXT4_ERROR_INODE (inode,"Logical block already allocated" ); +return ERR_PTR (-EFSCORRUPTED ); + } bh =ext4_bread (handle, inode, *block,EXT4_GET_BLOCKS_CREATE );if (IS_ERR (bh))
Greg Kroah-Hartman
maintainerPATCH 520/545 ext4: fix use-after-free in ext4_xattr_set_entry
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit 67d7d8ad99beccd9fe92d585b87f1760dc9018e3 upstream.
Hulk Robot reported a issue:
==================================================================
BUG: KASAN: use-after-free in ext4_xattr_set_entry+0x18ab/0x3500 Write of size 4105 at addr ffff8881675ef5f4 by task syz-executor.0/7092 CPU: 1 PID: 7092 Comm: syz-executor.0 Not tainted 4.19.90-dirty #17 Call Trace: [...] memcpy+0x34/0x50 mm/kasan/kasan.c:303 ext4_xattr_set_entry+0x18ab/0x3500 fs/ext4/xattr.c:1747 ext4_xattr_ibody_inline_set+0x86/0x2a0 fs/ext4/xattr.c:2205 ext4_xattr_set_handle+0x940/0x1300 fs/ext4/xattr.c:2386 ext4_xattr_set+0x1da/0x300 fs/ext4/xattr.c:2498 __vfs_setxattr+0x112/0x170 fs/xattr.c:149 __vfs_setxattr_noperm+0x11b/0x2a0 fs/xattr.c:180 __vfs_setxattr_locked+0x17b/0x250 fs/xattr.c:238 vfs_setxattr+0xed/0x270 fs/xattr.c:255 setxattr+0x235/0x330 fs/xattr.c:520 path_setxattr+0x176/0x190 fs/xattr.c:539 __do_sys_lsetxattr fs/xattr.c:561 [inline] __se_sys_lsetxattr fs/xattr.c:557 [inline] __x64_sys_lsetxattr+0xc2/0x160 fs/xattr.c:557 do_syscall_64+0xdf/0x530 arch/x86/entry/common.c:298 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x459fe9 RSP: 002b:00007fa5e54b4c08 EFLAGS: 00000246 ORIG_RAX: 00000000000000bd RAX: ffffffffffffffda RBX: 000000000051bf60 RCX: 0000000000459fe9 RDX: 00000000200003c0 RSI: 0000000020000180 RDI: 0000000020000140 RBP: 000000000051bf60 R08: 0000000000000001 R09: 0000000000000000 R10: 0000000000001009 R11: 0000000000000246 R12: 0000000000000000 R13: 00007ffc73c93fc0 R14: 000000000051bf60 R15: 00007fa5e54b4d80
[...]
==================================================================
Above issue may happen as follows:
-------------------------------------ext4_xattr_set
ext4_xattr_set_handle
ext4_xattr_ibody_find
>> s->end < s->base
>> no EXT4_STATE_XATTR
>> xattr_check_inode is not executed
ext4_xattr_ibody_set
ext4_xattr_set_entry
>> size_t min_offs = s->end - s->base
>> UAF in memcpy
we can easily reproduce this problem with the following commands:
mkfs.ext4 -F /dev/sda
mount -o debug_want_extra_isize=128 /dev/sda /mnt
touch /mnt/file
setfattr -n user.cat -v seq -s z 4096|tr -d '[:digit:]' /mnt/file
In ext4_xattr_ibody_find, we have the following assignment logic:
header = IHDR(inode, raw_inode)
= raw_inode + EXT4_GOOD_OLD_INODE_SIZE + i_extra_isize
is->s.base = IFIRST(header)
= header + sizeof(struct ext4_xattr_ibody_header)
is->s.end = raw_inode + s_inode_size
In ext4_xattr_set_entry
min_offs = s->end - s->base
= s_inode_size - EXT4_GOOD_OLD_INODE_SIZE - i_extra_isize -
sizeof(struct ext4_xattr_ibody_header)
last = s->first
free = min_offs - ((void *)last - s->base) - sizeof(__u32)
= s_inode_size - EXT4_GOOD_OLD_INODE_SIZE - i_extra_isize -
sizeof(struct ext4_xattr_ibody_header) - sizeof(__u32)
In the calculation formula, all values except s_inode_size and i_extra_size are fixed values. When i_extra_size is the maximum value s_inode_size - EXT4_GOOD_OLD_INODE_SIZE, min_offs is -4 and free is -8. The value overflows. As a result, the preceding issue is triggered when memcpy is executed.
Therefore, when finding xattr or setting xattr, check whether there is space for storing xattr in the inode to resolve this issue.
--- fs/ext4/xattr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ext4/xattr.c +4 -2
@@ -2167,8 +2167,9 @@ int ext4_xattr_ibody_find(struct inode *struct ext4_inode *raw_inode;int error; -if (EXT4_I (inode)->i_extra_isize ==0 ) +if (!EXT4_INODE_HAS_XATTR_SPACE (inode))return 0 ; + raw_inode =ext4_raw_inode (&is->iloc); header =IHDR (inode, raw_inode); is->s.base = is->s.first =IFIRST (header);
@@ -2196,8 +2197,9 @@ int ext4_xattr_ibody_inline_set(handle_tstruct ext4_xattr_search *s = &is->s;int error; -if (EXT4_I (inode)->i_extra_isize ==0 ) +if (!EXT4_INODE_HAS_XATTR_SPACE (inode))return -ENOSPC ; + error =ext4_xattr_set_entry (i, s, handle, inode, false/* is_block */ );if (error)return error;
Greg Kroah-Hartman
maintainerPATCH 521/545 ext4: update s_overhead_clusters in the superblock during an on-line resize
In reply to Greg Kroah-HartmanFrom: Theodore Ts'o <[email protected]>
commit de394a86658ffe4e89e5328fd4993abfe41b7435 upstream.
When doing an online resize, the on-disk superblock on-disk wasn't updated. This means that when the file system is unmounted and remounted, and the on-disk overhead value is non-zero, this would result in the results of statfs(2) to be incorrect.
This was partially fixed by Commits 10b01ee92df5 ("ext4: fix overhead calculation to account for the reserved gdt blocks"), 85d825dbf489 ("ext4: force overhead calculation if the s_overhead_cluster makes no sense"), and eb7054212eac ("ext4: update the cached overhead value in the superblock").
However, since it was too expensive to forcibly recalculate the overhead for bigalloc file systems at every mount, this didn't fix the problem for bigalloc file systems. This commit should address the problem when resizing file systems with the bigalloc feature enabled.
--- fs/ext4/resize.c | 1 + 1 file changed, 1 insertion(+)
fs/ext4/resize.c +1 -0
@@ -1461,6 +1461,7 @@ static void ext4_update_super(struct sup* Update the fs overhead information */ ext4_calculate_overhead (sb); + es->s_overhead_clusters =cpu_to_le32 (sbi->s_overhead);if (test_opt (sb,DEBUG )) printk(KERN_DEBUG "EXT4-fs: added group %u:"
Greg Kroah-Hartman
maintainerPATCH 522/545 ext4: fix extent status tree race in writeback error recovery path
In reply to Greg Kroah-HartmanFrom: Eric Whitney <[email protected]>
commit 7f0d8e1d607c1a4fa9a27362a108921d82230874 upstream.
A race can occur in the unlikely event ext4 is unable to allocate a physical cluster for a delayed allocation in a bigalloc file system during writeback. Failure to allocate a cluster forces error recovery that includes a call to mpage_release_unused_pages(). That function removes any corresponding delayed allocated blocks from the extent status tree. If a new delayed write is in progress on the same cluster simultaneously, resulting in the addition of an new extent containing one or more blocks in that cluster to the extent status tree, delayed block accounting can be thrown off if that delayed write then encounters a similar cluster allocation failure during future writeback.
Write lock the i_data_sem in mpage_release_unused_pages() to fix this problem. Ext4's block/cluster accounting code for bigalloc relies on i_data_sem for mutual exclusion, as is found in the delayed write path, and the locking in mpage_release_unused_pages() is missing.
--- fs/ext4/inode.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/ext4/inode.c +7 -0
@@ -1577,7 +1577,14 @@ static void mpage_release_unused_pages(sext4_lblk_t start, last; start = index << (PAGE_SHIFT - inode->i_blkbits); last = end << (PAGE_SHIFT - inode->i_blkbits); + +/* +* avoid racing with extent status tree scans made by +* ext4_insert_delayed_block() +*/ +down_write (&EXT4_I (inode)->i_data_sem);ext4_es_remove_extent (inode, start, last - start +1 ); +up_write (&EXT4_I (inode)->i_data_sem); }pagevec_init (&pvec);
Greg Kroah-Hartman
maintainerPATCH 523/545 ext4: correct max_inline_xattr_value_size computing
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit c9fd167d57133c5b748d16913c4eabc55e531c73 upstream.
If the ext4 inode does not have xattr space, 0 is returned in the get_max_inline_xattr_value_size function. Otherwise, the function returns a negative value when the inode does not contain EXT4_STATE_XATTR.
--- fs/ext4/inline.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ext4/inline.c +3 -0
@@ -34,6 +34,9 @@ static int get_max_inline_xattr_value_sistruct ext4_inode *raw_inode;int free, min_offs; +if (!EXT4_INODE_HAS_XATTR_SPACE (inode)) +return 0 ; + min_offs =EXT4_SB (inode->i_sb)->s_inode_size -EXT4_GOOD_OLD_INODE_SIZE - EXT4_I(inode)->i_extra_isize -
Greg Kroah-Hartman
maintainerPATCH 524/545 ext4: correct the misjudgment in ext4_iget_extra_inode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
commit fd7e672ea98b95b9d4c9dae316639f03c16a749d upstream.
Use the EXT4_INODE_HAS_XATTR_SPACE macro to more accurately determine whether the inode have xattr space.
--- fs/ext4/inode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/inode.c +1 -2
@@ -4613,8 +4613,7 @@ static inline int ext4_iget_extra_inode(__le32 *magic = (void *)raw_inode +EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize; -if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize +sizeof (__le32) <= -EXT4_INODE_SIZE (inode->i_sb) && +if (EXT4_INODE_HAS_XATTR_SPACE (inode) && *magic ==cpu_to_le32 (EXT4_XATTR_MAGIC )) {ext4_set_inode_state (inode,EXT4_STATE_XATTR );return ext4_find_inline_data_nolock (inode);
Greg Kroah-Hartman
maintainerPATCH 525/545 dm raid: fix address sanitizer warning in raid_resume
In reply to Greg Kroah-HartmanFrom: Mikulas Patocka <[email protected]>
commit 7dad24db59d2d2803576f2e3645728866a056dab upstream.
There is a KASAN warning in raid_resume when running the lvm test lvconvert-raid.sh. The reason for the warning is that mddev->raid_disks is greater than rs->raid_disks, so the loop touches one entry beyond the allocated length.
--- drivers/md/dm-raid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-raid.c +1 -1
@@ -3794,7 +3794,7 @@ static void attempt_restore_of_faulty_dememset (cleared_failed_devices,0 ,sizeof (cleared_failed_devices)); -for (i =0 ; i < mddev->raid_disks; i++) { +for (i =0 ; i < rs->raid_disks; i++) { r = &rs->dev[i].rdev;/* HM FIXME: enhance journal device recovery processing */ if (test_bit (Journal, &r->flags))
Greg Kroah-Hartman
maintainerPATCH 526/545 dm raid: fix address sanitizer warning in raid_status
In reply to Greg Kroah-HartmanFrom: Mikulas Patocka <[email protected]>
commit 1fbeea217d8f297fe0e0956a1516d14ba97d0396 upstream.
There is this warning when using a kernel with the address sanitizer and running this testsuite:
https://gitlab.com/cki-project/kernel-tests/-/tree/main/storage/swraid/scsi_raid
==================================================================
BUG: KASAN: slab-out-of-bounds in raid_status+0x1747/0x2820 [dm_raid] Read of size 4 at addr ffff888079d2c7e8 by task lvcreate/13319 CPU: 0 PID: 13319 Comm: lvcreate Not tainted 5.18.0-0.rc3.<snip> #1 Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 Call Trace: <TASK> dump_stack_lvl+0x6a/0x9c print_address_description.constprop.0+0x1f/0x1e0 print_report.cold+0x55/0x244 kasan_report+0xc9/0x100 raid_status+0x1747/0x2820 [dm_raid] dm_ima_measure_on_table_load+0x4b8/0xca0 [dm_mod] table_load+0x35c/0x630 [dm_mod] ctl_ioctl+0x411/0x630 [dm_mod] dm_ctl_ioctl+0xa/0x10 [dm_mod] __x64_sys_ioctl+0x12a/0x1a0 do_syscall_64+0x5b/0x80
The warning is caused by reading conf->max_nr_stripes in raid_status. The code in raid_status reads mddev->private, casts it to struct r5conf and reads the entry max_nr_stripes.
However, if we have different raid type than 4/5/6, mddev->private doesn't point to struct r5conf; it may point to struct r0conf, struct r1conf, struct r10conf or struct mpconf. If we cast a pointer to one of these structs to struct r5conf, we will be reading invalid memory and KASAN warns about it.
Fix this bug by reading struct r5conf only if raid type is 4, 5 or 6.
--- drivers/md/dm-raid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-raid.c +1 -1
@@ -3514,7 +3514,7 @@ static void raid_status(struct dm_target {struct raid_set *rs = ti->private;struct mddev *mddev = &rs->md; -struct r5conf *conf = mddev->private; +struct r5conf *conf =rs_is_raid456 (rs) ? mddev->private :NULL ;int i, max_nr_stripes = conf ? conf->max_nr_stripes :0 ;unsigned long recovery;unsigned int raid_param_cnt =1 ;/* at least 1 for chunksize */
Greg Kroah-Hartman
maintainerPATCH 527/545 net_sched: cls_route: remove from list when handle is 0
In reply to Greg Kroah-HartmanFrom: Thadeu Lima de Souza Cascardo <[email protected]>
commit 9ad36309e2719a884f946678e0296be10f0bb4c1 upstream.
When a route filter is replaced and the old filter has a 0 handle, the old one won't be removed from the hashtable, while it will still be freed.
The test was there since before commit 1109c00547fc ("net: sched: RCU cls_route"), when a new filter was not allocated when there was an old one. The old filter was reused and the reinserting would only be necessary if an old filter was replaced. That was still wrong for the same case where the old handle was 0.
Remove the old filter from the list independently from its handle value.
This fixes CVE-2022-2588, also reported as ZDI-CAN-17440.
--- net/sched/cls_route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/cls_route.c +1 -1
@@ -526,7 +526,7 @@ static int route4_change(struct net *netrcu_assign_pointer (f->next, f1);rcu_assign_pointer (*fp, f); -if (fold && fold->handle && f->handle != fold->handle) { +if (fold) { th =to_hash (fold->handle); h =from_hash (fold->handle >>16 ); b =rtnl_dereference (head->table[th]);
Greg Kroah-Hartman
maintainerPATCH 528/545 KVM: Add infrastructure and macro to mark VM as bugged
In reply to Greg Kroah-HartmanFrom: Sean Christopherson <[email protected]>
commit 0b8f11737cffc1a406d1134b58687abc29d76b52 upstream
Message-Id: <3a0998645c328bf0895f1290e61821b70f048549.1625186503.git.isaku.yamahata@intel.com>
--- include/linux/kvm_host.h | 28 +++++++++++++++++++++++++++- virt/kvm/kvm_main.c | 10 +++++----- 2 files changed, 32 insertions(+), 6 deletions(-)
include/linux/kvm_host.h +27 -1
@@ -146,6 +146,7 @@ static inline bool is_error_page(struct#define KVM_REQ_MMU_RELOAD (1 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)#define KVM_REQ_PENDING_TIMER 2#define KVM_REQ_UNHALT 3 +#define KVM_REQ_VM_BUGGED (4 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)#define KVM_REQUEST_ARCH_BASE 8#define KVM_ARCH_REQ_FLAGS (nr, flags) ({ \
@@ -505,6 +506,7 @@ struct kvm {struct srcu_struct irq_srcu;pid_t userspace_pid;unsigned int max_halt_poll_ns; +bool vm_bugged; };#define kvm_err (fmt, ...) \
@@ -533,6 +535,31 @@ struct kvm {#define vcpu_err (vcpu, fmt, ...) \ kvm_err("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__) +bool kvm_make_all_cpus_request (struct kvm *kvm,unsigned int req); +static inline void kvm_vm_bugged (struct kvm *kvm) +{ + kvm->vm_bugged = true; +kvm_make_all_cpus_request (kvm,KVM_REQ_VM_BUGGED ); +} + +#define KVM_BUG(cond, kvm, fmt...) \ +({ \ + int __ret = (cond); \ + \ + if (WARN_ONCE(__ret && !(kvm)->vm_bugged, fmt)) \ + kvm_vm_bugged(kvm); \ + unlikely(__ret); \ +}) + +#define KVM_BUG_ON (cond, kvm) \ +({ \ + int __ret = (cond); \ + \ + if (WARN_ON_ONCE(__ret && !(kvm)->vm_bugged)) \ + kvm_vm_bugged(kvm); \ + unlikely(__ret); \ +}) +static inline bool kvm_dirty_log_manual_protect_and_init_set (struct kvm *kvm) {return !!(kvm->manual_dirty_log_protect &KVM_DIRTY_LOG_INITIALLY_SET );
@@ -850,7 +877,6 @@ void *kvm_mmu_memory_cache_alloc(structbool kvm_make_vcpus_request_mask (struct kvm *kvm,unsigned int req,struct kvm_vcpu *except,unsigned long *vcpu_bitmap,cpumask_var_t tmp); -bool kvm_make_all_cpus_request (struct kvm *kvm,unsigned int req);bool kvm_make_all_cpus_request_except (struct kvm *kvm,unsigned int req,struct kvm_vcpu *except); bool kvm_make_cpus_request_mask(struct kvm *kvm, unsigned int req,
virt/kvm/kvm_main.c +5 -5
@@ -3264,7 +3264,7 @@ static long kvm_vcpu_ioctl(struct file *struct kvm_fpu *fpu =NULL ;struct kvm_sregs *kvm_sregs =NULL ; -if (vcpu->kvm->mm != current->mm) +if (vcpu->kvm->mm != current->mm || vcpu->kvm->vm_bugged)return -EIO ;if (unlikely (_IOC_TYPE (ioctl) !=KVMIO ))
@@ -3470,7 +3470,7 @@ static long kvm_vcpu_compat_ioctl(structvoid __user *argp =compat_ptr (arg);int r; -if (vcpu->kvm->mm != current->mm) +if (vcpu->kvm->mm != current->mm || vcpu->kvm->vm_bugged)return -EIO ;switch (ioctl) {
@@ -3536,7 +3536,7 @@ static long kvm_device_ioctl(struct file {struct kvm_device *dev = filp->private_data; -if (dev->kvm->mm != current->mm) +if (dev->kvm->mm != current->mm || dev->kvm->vm_bugged)return -EIO ;switch (ioctl) {
@@ -3755,7 +3755,7 @@ static long kvm_vm_ioctl(struct file *fivoid __user *argp = (void __user *)arg;int r; -if (kvm->mm != current->mm) +if (kvm->mm != current->mm || kvm->vm_bugged)return -EIO ;switch (ioctl) {case KVM_CREATE_VCPU :
@@ -3960,7 +3960,7 @@ static long kvm_vm_compat_ioctl(struct fstruct kvm *kvm = filp->private_data;int r; -if (kvm->mm != current->mm) +if (kvm->mm != current->mm || kvm->vm_bugged)return -EIO ;switch (ioctl) {#ifdef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT
Greg Kroah-Hartman
maintainerPATCH 529/545 KVM: x86: Check lapic_in_kernel() before attempting to set a SynIC irq
In reply to Greg Kroah-HartmanFrom: Vitaly Kuznetsov <[email protected]>
commit 7ec37d1cbe17d8189d9562178d8b29167fe1c31a upstream
When KVM_CAP_HYPERV_SYNIC{,2} is activated, KVM already checks for irqchip_in_kernel() so normally SynIC irqs should never be set. It is, however, possible for a misbehaving VMM to write to SYNIC/STIMER MSRs causing erroneous behavior.
The immediate issue being fixed is that kvm_irq_delivery_to_apic() (kvm_irq_delivery_to_apic_fast()) crashes when called with 'irq.shorthand = APIC_DEST_SELF' and 'src == NULL'.
Message-Id: <[email protected]>
--- arch/x86/kvm/hyperv.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kvm/hyperv.c +3 -0
@@ -428,6 +428,9 @@ static int synic_set_irq(struct kvm_vcpustruct kvm_lapic_irq irq;int ret, vector; +if (KVM_BUG_ON (!lapic_in_kernel (vcpu), vcpu->kvm)) +return -EINVAL ; +if (sint >=ARRAY_SIZE (synic->sint))return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 530/545 KVM: x86: Avoid theoretical NULL pointer dereference in kvm_irq_delivery_to_apic_fast()
In reply to Greg Kroah-HartmanFrom: Vitaly Kuznetsov <[email protected]>
commit 00b5f37189d24ac3ed46cb7f11742094778c46ce upstream
When kvm_irq_delivery_to_apic_fast() is called with APIC_DEST_SELF shorthand, 'src' must not be NULL. Crash the VM with KVM_BUG_ON() instead of crashing the host.
Message-Id: <[email protected]>
--- arch/x86/kvm/lapic.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/kvm/lapic.c +4 -0
@@ -991,6 +991,10 @@ bool kvm_irq_delivery_to_apic_fast(struc *r =-1 ;if (irq->shorthand ==APIC_DEST_SELF ) { +if (KVM_BUG_ON (!src, kvm)) { + *r =0 ; +return true; + } *r =kvm_apic_set_irq (src->vcpu, irq, dest_map);return true; }
Greg Kroah-Hartman
maintainerPATCH 531/545 mac80211: fix a memory leak where sta_info is not freed
In reply to Greg Kroah-HartmanFrom: Ahmed Zaki <[email protected]>
commit 8f9dcc29566626f683843ccac6113a12208315ca upstream.
The following is from a system that went OOM due to a memory leak:
wlan0: Allocated STA 74:83:c2:64:0b:87
wlan0: Allocated STA 74:83:c2:64:0b:87
wlan0: IBSS finish 74:83:c2:64:0b:87 (---from ieee80211_ibss_add_sta)
wlan0: Adding new IBSS station 74:83:c2:64:0b:87
wlan0: moving STA 74:83:c2:64:0b:87 to state 2
wlan0: moving STA 74:83:c2:64:0b:87 to state 3
wlan0: Inserted STA 74:83:c2:64:0b:87
wlan0: IBSS finish 74:83:c2:64:0b:87 (---from ieee80211_ibss_work)
wlan0: Adding new IBSS station 74:83:c2:64:0b:87
wlan0: moving STA 74:83:c2:64:0b:87 to state 2
wlan0: moving STA 74:83:c2:64:0b:87 to state 3
.
.
wlan0: expiring inactive not authorized STA 74:83:c2:64:0b:87
wlan0: moving STA 74:83:c2:64:0b:87 to state 2
wlan0: moving STA 74:83:c2:64:0b:87 to state 1
wlan0: Removed STA 74:83:c2:64:0b:87
wlan0: Destroyed STA 74:83:c2:64:0b:87
The ieee80211_ibss_finish_sta() is called twice on the same STA from 2 different locations. On the second attempt, the allocated STA is not destroyed creating a kernel memory leak.
This is happening because sta_info_insert_finish() does not call sta_info_free() the second time when the STA already exists (returns -EEXIST). Note that the caller sta_info_insert_rcu() assumes STA is destroyed upon errors.
Same fix is applied to -ENOMEM.
--- net/mac80211/sta_info.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/mac80211/sta_info.c +3 -3
@@ -645,13 +645,13 @@ static int sta_info_insert_finish(struct/* check if STA exists already */ if (sta_info_get_bss (sdata, sta->sta.addr)) { err = -EEXIST ; - goto out_err; + goto out_cleanup; } sinfo =kzalloc (sizeof (struct station_info ),GFP_KERNEL );if (!sinfo) { err = -ENOMEM ; - goto out_err; + goto out_cleanup; } local->num_sta++;
@@ -707,8 +707,8 @@ static int sta_info_insert_finish(struct out_drop_sta: local->num_sta--;synchronize_net (); + out_cleanup:cleanup_single_sta (sta); - out_err:mutex_unlock (&local->sta_mtx);kfree (sinfo);rcu_read_lock ();
Greg Kroah-Hartman
maintainerPATCH 532/545 tcp: fix over estimation in sk_forced_mem_schedule()
In reply to Greg Kroah-HartmanFrom: Eric Dumazet <[email protected]>
commit c4ee118561a0f74442439b7b5b486db1ac1ddfeb upstream.
sk_forced_mem_schedule() has a bug similar to ones fixed in commit 7c80b038d23e ("net: fix sk_wmem_schedule() and sk_rmem_schedule() errors")
While this bug has little chance to trigger in old kernels, we need to fix it before the following patch.
--- net/ipv4/tcp_output.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv4/tcp_output.c +4 -3
@@ -3372,11 +3372,12 @@ void tcp_xmit_retransmit_queue(struct so*/ void sk_forced_mem_schedule (struct sock *sk,int size) { -int amt; +int delta, amt; -if (size <= sk->sk_forward_alloc) + delta = size - sk->sk_forward_alloc; +if (delta <=0 )return ; - amt =sk_mem_pages (size); + amt =sk_mem_pages (delta); sk->sk_forward_alloc += amt *SK_MEM_QUANTUM ;sk_memory_allocated_add (sk, amt);
Greg Kroah-Hartman
maintainerPATCH 533/545 Revert "mwifiex: fix sleep in atomic context bugs caused by dev_coredumpv"
In reply to Greg Kroah-HartmanFrom: Greg Kroah-Hartman <[email protected]>
commit 5f8954e099b8ae96e7de1bb95950e00c85bedd40 upstream.
This reverts commit a52ed4866d2b90dd5e4ae9dabd453f3ed8fa3cbc as it causes build problems in linux-next. It needs to be reintroduced in a way that can allow the api to evolve and not require a "flag day" to catch all users.
--- drivers/net/wireless/marvell/mwifiex/init.c | 9 ++++----- drivers/net/wireless/marvell/mwifiex/main.h | 3 +-- drivers/net/wireless/marvell/mwifiex/sta_event.c | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-)
drivers/net/wireless/marvell/mwifiex/init.c +4 -5
@@ -63,10 +63,9 @@ static void wakeup_timer_fn(struct timer adapter->if_ops.card_reset (adapter); } -static void fw_dump_work (struct work_struct *work) +static void fw_dump_timer_fn (struct timer_list *t) { -struct mwifiex_adapter *adapter = - container_of(work, struct mwifiex_adapter, devdump_work.work); +struct mwifiex_adapter *adapter =from_timer (adapter, t, devdump_timer);mwifiex_upload_device_dump (adapter); }
@@ -322,7 +321,7 @@ static void mwifiex_init_adapter(struct adapter->active_scan_triggered = false;timer_setup (&adapter->wakeup_timer, wakeup_timer_fn,0 ); adapter->devdump_len =0 ; -INIT_DELAYED_WORK (&adapter->devdump_work, fw_dump_work); +timer_setup (&adapter->devdump_timer, fw_dump_timer_fn,0 ); }/*
@@ -401,7 +400,7 @@ static void mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter) {del_timer (&adapter->wakeup_timer); -cancel_delayed_work_sync (&adapter->devdump_work); +del_timer_sync (&adapter->devdump_timer);mwifiex_cancel_all_pending_cmd (adapter);wake_up_interruptible (&adapter->cmd_wait_q.wait);wake_up_interruptible (&adapter->hs_activate_wait_q);
drivers/net/wireless/marvell/mwifiex/main.h +1 -2
@@ -49,7 +49,6 @@#include <linux/pm_runtime.h> #include <linux/slab.h> #include <linux/of_irq.h> -#include <linux/workqueue.h> #include "decl.h" #include "ioctl.h"
@@ -1054,7 +1053,7 @@ struct mwifiex_adapter {/* Device dump data/length */ void *devdump_data;int devdump_len; -struct delayed_work devdump_work; +struct timer_list devdump_timer;bool ignore_btcoex_events; };
drivers/net/wireless/marvell/mwifiex/sta_event.c +3 -3
@@ -622,8 +622,8 @@ mwifiex_fw_dump_info_event(struct mwifie* transmission event get lost, in this cornel case, * user would still get partial of the dump. */ -schedule_delayed_work (&adapter->devdump_work, -msecs_to_jiffies (MWIFIEX_TIMER_10S )); +mod_timer (&adapter->devdump_timer, + jiffies +msecs_to_jiffies (MWIFIEX_TIMER_10S )); }/* Overflow check */
@@ -642,7 +642,7 @@ mwifiex_fw_dump_info_event(struct mwifiereturn ; upload_dump: -cancel_delayed_work_sync (&adapter->devdump_work); +del_timer_sync (&adapter->devdump_timer);mwifiex_upload_device_dump (adapter); }
Greg Kroah-Hartman
maintainerPATCH 534/545 drm/bridge: tc358767: Fix (e)DP bridge endpoint parsing in dedicated function
In reply to Greg Kroah-HartmanFrom: Marek Vasut <[email protected]>
commit 9030a9e571b3ba250d3d450a98310e3c74ecaff4 upstream.
Per toshiba,tc358767.yaml DT binding document, port@2 the output (e)DP port is optional. In case this port is not described in DT, the bridge driver operates in DPI-to-DP mode. The drm_of_find_panel_or_bridge() call in tc_probe_edp_bridge_endpoint() returns -ENODEV in case port@2 is not present in DT and this specific return value is incorrectly propagated outside of tc_probe_edp_bridge_endpoint() function. All other error values must be propagated and are propagated correctly.
Return 0 in case the port@2 is missing instead, that reinstates the original behavior before the commit this patch fixes.
--- drivers/gpu/drm/bridge/tc358767.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/tc358767.c +1 -1
@@ -1559,7 +1559,7 @@ static int tc_probe_edp_bridge_endpoint( tc->bridge.type = DRM_MODE_CONNECTOR_DisplayPort; } -return ret; +return 0 ; }static void tc_clk_disable (void *data)
Greg Kroah-Hartman
maintainerPATCH 535/545 drm/vc4: change vc4_dma_range_matches from a global to static
In reply to Greg Kroah-HartmanFrom: Tom Rix <[email protected]>
commit 63569d90863ff26c8b10c8971d1271c17a45224b upstream.
sparse reportsdrivers/gpu/drm/vc4/vc4_drv.c:270:27: warning: symbol 'vc4_dma_range_matches' was not declared. Should it be static?
vc4_dma_range_matches is only used in vc4_drv.c, so it's storage class specifier should be static.
--- drivers/gpu/drm/vc4/vc4_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_drv.c +1 -1
@@ -246,7 +246,7 @@ static void vc4_match_add_drivers(struct } } -const struct of_device_id vc4_dma_range_matches[] = { +static const struct of_device_id vc4_dma_range_matches[] = { { .compatible ="brcm,bcm2711-hvs" }, { .compatible ="brcm,bcm2835-hvs" }, { .compatible ="brcm,bcm2835-v3d" },
Greg Kroah-Hartman
maintainerPATCH 536/545 Revert "net: usb: ax88179_178a needs FLAG_SEND_ZLP"
In reply to Greg Kroah-HartmanFrom: Jose Alonso <[email protected]>
commit 6fd2c17fb6e02a8c0ab51df1cfec82ce96b8e83d upstream.
This reverts commit 36a15e1cb134c0395261ba1940762703f778438c.
The usage of FLAG_SEND_ZLP causes problems to other firmware/hardware versions that have no issues.
The FLAG_SEND_ZLP is not safe to use in this context. See:
https://patchwork.ozlabs.org/project/netdev/patch/1270599787.8900.8.camel@Linuxdev4-laptop/#118378
The original problem needs another way to solve.
--- drivers/net/usb/ax88179_178a.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/net/usb/ax88179_178a.c +10 -10
@@ -1796,7 +1796,7 @@ static const struct driver_info ax88179_ .link_reset = ax88179_link_reset, .reset = ax88179_reset, .stop = ax88179_stop, - .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, + .flags = FLAG_ETHER | FLAG_FRAMING_AX, .rx_fixup = ax88179_rx_fixup, .tx_fixup = ax88179_tx_fixup, };
@@ -1809,7 +1809,7 @@ static const struct driver_info ax88178a .link_reset = ax88179_link_reset, .reset = ax88179_reset, .stop = ax88179_stop, - .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, + .flags = FLAG_ETHER | FLAG_FRAMING_AX, .rx_fixup = ax88179_rx_fixup, .tx_fixup = ax88179_tx_fixup, };
@@ -1822,7 +1822,7 @@ static const struct driver_info cypress_ .link_reset = ax88179_link_reset, .reset = ax88179_reset, .stop = ax88179_stop, - .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, + .flags = FLAG_ETHER | FLAG_FRAMING_AX, .rx_fixup = ax88179_rx_fixup, .tx_fixup = ax88179_tx_fixup, };
@@ -1835,7 +1835,7 @@ static const struct driver_info dlink_du .link_reset = ax88179_link_reset, .reset = ax88179_reset, .stop = ax88179_stop, - .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, + .flags = FLAG_ETHER | FLAG_FRAMING_AX, .rx_fixup = ax88179_rx_fixup, .tx_fixup = ax88179_tx_fixup, };
@@ -1848,7 +1848,7 @@ static const struct driver_info sitecom_ .link_reset = ax88179_link_reset, .reset = ax88179_reset, .stop = ax88179_stop, - .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, + .flags = FLAG_ETHER | FLAG_FRAMING_AX, .rx_fixup = ax88179_rx_fixup, .tx_fixup = ax88179_tx_fixup, };
@@ -1861,7 +1861,7 @@ static const struct driver_info samsung_ .link_reset = ax88179_link_reset, .reset = ax88179_reset, .stop = ax88179_stop, - .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, + .flags = FLAG_ETHER | FLAG_FRAMING_AX, .rx_fixup = ax88179_rx_fixup, .tx_fixup = ax88179_tx_fixup, };
@@ -1874,7 +1874,7 @@ static const struct driver_info lenovo_i .link_reset = ax88179_link_reset, .reset = ax88179_reset, .stop = ax88179_stop, - .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, + .flags = FLAG_ETHER | FLAG_FRAMING_AX, .rx_fixup = ax88179_rx_fixup, .tx_fixup = ax88179_tx_fixup, };
@@ -1887,7 +1887,7 @@ static const struct driver_info belkin_i .link_reset = ax88179_link_reset, .reset = ax88179_reset, .stop = ax88179_stop, - .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, + .flags = FLAG_ETHER | FLAG_FRAMING_AX, .rx_fixup = ax88179_rx_fixup, .tx_fixup = ax88179_tx_fixup, };
@@ -1900,7 +1900,7 @@ static const struct driver_info toshiba_ .link_reset = ax88179_link_reset, .reset = ax88179_reset, .stop = ax88179_stop, - .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, + .flags = FLAG_ETHER | FLAG_FRAMING_AX, .rx_fixup = ax88179_rx_fixup, .tx_fixup = ax88179_tx_fixup, };
@@ -1913,7 +1913,7 @@ static const struct driver_info mct_info .link_reset = ax88179_link_reset, .reset = ax88179_reset, .stop = ax88179_stop, - .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, + .flags = FLAG_ETHER | FLAG_FRAMING_AX, .rx_fixup = ax88179_rx_fixup, .tx_fixup = ax88179_tx_fixup, };
Greg Kroah-Hartman
maintainerPATCH 537/545 Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression
In reply to Greg Kroah-HartmanFrom: Luiz Augusto von Dentz <[email protected]>
commit 332f1795ca202489c665a75e62e18ff6284de077 upstream.
The patch d0be8347c623: "Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put" from Jul 21, 2022, leads to the following Smatch static checker warning:
net/bluetooth/l2cap_core.c:1977 l2cap_global_chan_by_psm()
error: we previously assumed 'c' could be null (see line 1996)
--- net/bluetooth/l2cap_core.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
net/bluetooth/l2cap_core.c +6 -7
@@ -1966,11 +1966,11 @@ static struct l2cap_chan *l2cap_global_c bdaddr_t *dst, u8 link_type) { -struct l2cap_chan *c, *c1 =NULL ; +struct l2cap_chan *c, *tmp, *c1 =NULL ;read_lock (&chan_list_lock); -list_for_each_entry (c, &chan_list, global_l) { +list_for_each_entry_safe (c, tmp, &chan_list, global_l) {if (state && c->state != state)continue ;
@@ -1989,11 +1989,10 @@ static struct l2cap_chan *l2cap_global_c dst_match = !bacmp (&c->dst, dst);if (src_match && dst_match) { c =l2cap_chan_hold_unless_zero (c); -if (!c) -continue ; - -read_unlock (&chan_list_lock); -return c; +if (c) { +read_unlock (&chan_list_lock); +return c; + } }/* Closest match */
Greg Kroah-Hartman
maintainerPATCH 538/545 mtd: rawnand: arasan: Prevent an unsupported configuration
In reply to Greg Kroah-HartmanFrom: Miquel Raynal <[email protected]>
commit fc9e18f9e987ad46722dad53adab1c12148c213c upstream.
Under the following conditions:
* after rounding up by 4 the number of bytes to transfer (this is related to the controller's internal constraints),
* if this (rounded) amount of data is situated beyond the end of the device,
* and only in NV-DDR mode,
the Arasan NAND controller timeouts.
This currently can happen in a particular helper used when picking software ECC algorithms. Let's prevent this situation by refusing to use the NV-DDR interface with software engines.
--- drivers/mtd/nand/raw/arasan-nand-controller.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/mtd/nand/raw/arasan-nand-controller.c +15 -0
@@ -891,6 +891,21 @@ static int anfc_setup_interface(struct n nvddr =nand_get_nvddr_timings (conf);if (IS_ERR (nvddr))return PTR_ERR (nvddr); + +/* +* The controller only supports data payload requests which are +* a multiple of 4. In practice, most data accesses are 4-byte +* aligned and this is not an issue. However, rounding up will +* simply be refused by the controller if we reached the end of +* the device *and* we are using the NV-DDR interface(!). In +* this situation, unaligned data requests ending at the device +* boundary will confuse the controller and cannot be performed. +* +* This is something that happens in nand_read_subpage() when +* selecting software ECC support and must be avoided. +*/ +if (chip->ecc.engine_type ==NAND_ECC_ENGINE_TYPE_SOFT ) +return -ENOTSUPP ; }else { sdr =nand_get_sdr_timings (conf);if (IS_ERR (sdr))
Greg Kroah-Hartman
maintainerPATCH 539/545 kvm: x86/pmu: Fix the compare function used by the pmu event filter
In reply to Greg Kroah-HartmanFrom: Aaron Lewis <[email protected]>
commit 4ac19ead0dfbabd8e0bfc731f507cfb0b95d6c99 upstream.
When returning from the compare function the u64 is truncated to an int. This results in a loss of the high nybble[1] in the event select and its sign if that nybble is in use. Switch from using a result that can end up being truncated to a result that can only be: 1, 0, -1.
[1] bits 35:32 in the event select register and bits 11:8 in the event select.
Message-Id: <[email protected]>
--- arch/x86/kvm/pmu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kvm/pmu.c +5 -2
@@ -170,9 +170,12 @@ static bool pmc_resume_counter(struct kvreturn true; } -static int cmp_u64 (const void *a,const void *b) +static int cmp_u64 (const void *pa,const void *pb) { -return *(__u64 *)a - *(__u64 *)b; +u64 a = *(u64 *)pa; +u64 b = *(u64 *)pb; + +return (a > b) - (a < b); }void reprogram_gp_counter (struct kvm_pmc *pmc,u64 eventsel)
Greg Kroah-Hartman
maintainerPATCH 540/545 tee: add overflow check in register_shm_helper()
In reply to Greg Kroah-HartmanFrom: Jens Wiklander <[email protected]>
commit 573ae4f13f630d6660008f1974c0a8a29c30e18a upstream.
With special lengths supplied by user space, register_shm_helper() has an integer overflow when calculating the number of pages covered by a supplied user space memory region.
This causes internal_get_user_pages_fast() a helper function of pin_user_pages_fast() to do a NULL pointer dereference:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 Modules linked in: CPU: 1 PID: 173 Comm: optee_example_a Not tainted 5.19.0 #11 Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015 pc : internal_get_user_pages_fast+0x474/0xa80 Call trace: internal_get_user_pages_fast+0x474/0xa80 pin_user_pages_fast+0x24/0x4c register_shm_helper+0x194/0x330 tee_shm_register_user_buf+0x78/0x120 tee_ioctl+0xd0/0x11a0 __arm64_sys_ioctl+0xa8/0xec invoke_syscall+0x48/0x114
Fix this by adding an an explicit call to access_ok() in tee_shm_register_user_buf() to catch an invalid user space address early.
--- drivers/tee/tee_shm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/tee/tee_shm.c +3 -0
@@ -222,6 +222,9 @@ struct tee_shm *tee_shm_register(struct goto err; } +if (!access_ok ((void __user *)addr, length)) +return ERR_PTR (-EFAULT ); +mutex_lock (&teedev->mutex); shm->id =idr_alloc (&teedev->idr, shm,1 ,0 ,GFP_KERNEL );mutex_unlock (&teedev->mutex);
Re: [PATCH 5.10 540/545] tee: add overflow check in register_shm_helper()
Hi!
Quoted 10 lines
From: Jens Wiklander <[email protected]>
commit
573ae4f13f630d6660008f1974c0a8a29c30e18aupstream.With special lengths supplied by user space,
register_shm_helper()has an integer overflow when calculating the number of pages covered by a supplied user space memory region.This causes
internal_get_user_pages_fast()a helper function ofpin_user_pages_fast()to do a NULL pointer dereference:
Maybe this needs fixing, but this fix adds a memory leak or two. Note the goto err, that needs to be done.
Best regards,
Pavel
Review struct tee_shm *tee_shm_register(struct · line 230
Quoted 12 lines
+++
b/drivers/tee/tee_shm.c(quoted diff) +3
-0@@ -222,6 +222,9 @@ struct tee_shm *tee_shm_register(struct goto err; } + if (!access_ok((void __user *)addr, length)) + return ERR_PTR(-EFAULT); + mutex_lock(&teedev->mutex); shm->id = idr_alloc(&teedev->idr, shm, 1, 0, GFP_KERNEL); mutex_unlock(&teedev->mutex);
drivers/tee/tee_shm.c +4 -2
@@ -222,8 +222,10 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, goto err; } -if (!access_ok ((void __user *)addr, length)) -return ERR_PTR (-EFAULT ); +if (!access_ok ((void __user *)addr, length)) { + ret =ERR_PTR (-EFAULT ); + goto err; + }mutex_lock (&teedev->mutex); shm->id =idr_alloc (&teedev->idr, shm,1 ,0 ,GFP_KERNEL );
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Re: [PATCH 5.10 540/545] tee: add overflow check in register_shm_helper()
Hi,
Quoted 11 lines · Pavel Machek
Hi!
Quoted 8 lines
From: Jens Wiklander <[email protected]>
commit
573ae4f13f630d6660008f1974c0a8a29c30e18aupstream.With special lengths supplied by user space,
register_shm_helper()has an integer overflow when calculating the number of pages covered by a supplied user space memory region.
Quoted 5 lines
Quoted 2 lines
This causes
internal_get_user_pages_fast()a helper function ofpin_user_pages_fast()to do a NULL pointer dereference:Maybe this needs fixing, but this fix adds a memory leak or two. Note the goto err, that needs to be done.
Thanks for bringing this up. I believe the best option is to take the backport I just did for 5.4, it should apply cleanly on the 5.10 stable kernel too.
Greg, can you cherry-pick the 5.4 backport patch, or would you rather have an explicit backport for this stable kernel?
Cheers,
Jens
Quoted 41 lines
Best regards,
PavelSigned-off-by Pavel Machek <[email protected]>Quoted 12 lines
+++
b/drivers/tee/tee_shm.cdrivers/tee/tee_shm.c +3
-0@@ -222,6 +222,9 @@ struct tee_shm *tee_shm_register(struct goto err; } +if (!access_ok ((void __user *)addr, length)) +return ERR_PTR (-EFAULT ); +mutex_lock (&teedev->mutex); shm->id =idr_alloc (&teedev->idr, shm,1 ,0 ,GFP_KERNEL );mutex_unlock (&teedev->mutex);drivers/tee/tee_shm.c +4
-3@@ -222,8 +222,10 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, goto err; } -if (!access_ok ((void __user *)addr, length)) -return ERR_PTR (-EFAULT ); +if (!access_ok ((void __user *)addr, length)) { + ret =ERR_PTR (-EFAULT ); + goto err; + }mutex_lock (&teedev->mutex); shm->id =idr_alloc (&teedev->idr, shm,1 ,0 ,GFP_KERNEL ); --DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Re: [PATCH 5.10 540/545] tee: add overflow check in register_shm_helper()
Quoted 21 lines · Jens Wiklander
Hi,
Quoted 11 lines · Pavel Machek
Hi!
Quoted 8 lines
From: Jens Wiklander <[email protected]>
commit
573ae4f13f630d6660008f1974c0a8a29c30e18aupstream.With special lengths supplied by user space,
register_shm_helper()has an integer overflow when calculating the number of pages covered by a supplied user space memory region.Quoted 5 lines
Quoted 2 lines
This causes
internal_get_user_pages_fast()a helper function ofpin_user_pages_fast()to do a NULL pointer dereference:Maybe this needs fixing, but this fix adds a memory leak or two. Note the goto err, that needs to be done.
Quoted 6 lines
Thanks for bringing this up. I believe the best option is to take the backport I just did for 5.4, it should apply cleanly on the 5.10 stable kernel too.
Greg, can you cherry-pick the 5.4 backport patch, or would you rather have an explicit backport for this stable kernel?
I'm sorry, I'm confused by all the backports. I haven't posted the 5.4 yet, I've only just tested it. I'll tag that backport patch for 5.10 stable too.
Thanks,
Jens
Quoted 45 lines
Cheers,
JensQuoted 41 lines
Best regards,
PavelSigned-off-by Pavel Machek <[email protected]>Quoted 12 lines
+++
b/drivers/tee/tee_shm.cdrivers/tee/tee_shm.c +3
-0@@ -222,6 +222,9 @@ struct tee_shm *tee_shm_register(struct goto err; } +if (!access_ok ((void __user *)addr, length)) +return ERR_PTR (-EFAULT ); +mutex_lock (&teedev->mutex); shm->id =idr_alloc (&teedev->idr, shm,1 ,0 ,GFP_KERNEL );mutex_unlock (&teedev->mutex);drivers/tee/tee_shm.c +4
-3@@ -222,8 +222,10 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, goto err; } -if (!access_ok ((void __user *)addr, length)) -return ERR_PTR (-EFAULT ); +if (!access_ok ((void __user *)addr, length)) { + ret =ERR_PTR (-EFAULT ); + goto err; + }mutex_lock (&teedev->mutex); shm->id =idr_alloc (&teedev->idr, shm,1 ,0 ,GFP_KERNEL ); --DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Greg Kroah-Hartman
maintainerPATCH 541/545 net/9p: Initialize the iounit field during fid creation
In reply to Greg Kroah-HartmanFrom: Tyler Hicks <[email protected]>
commit aa7aeee169480e98cf41d83c01290a37e569be6d upstream.
Ensure that the fid's iounit field is set to zero when a new fid is created. Certain 9P operations, such as OPEN and CREATE, allow the server to reply with an iounit size which the client code assigns to the p9_fid struct shortly after the fid is created by p9_fid_create(). On the other hand, an XATTRWALK operation doesn't allow for the server to specify an iounit value. The iounit field of the newly allocated p9_fid struct remained uninitialized in that case. Depending on allocation patterns, the iounit value could have been something reasonable that was carried over from previously freed fids or, in the worst case, could have been arbitrary values from non-fid related usages of the memory location.
The bug was detected in the Windows Subsystem for Linux 2 (WSL2) kernel after the uninitialized iounit field resulted in the typical sequence of two getxattr(2) syscalls, one to get the size of an xattr and another after allocating a sufficiently sized buffer to fit the xattr value, to hit an unexpected ERANGE error in the second call to getxattr(2). An uninitialized iounit field would sometimes force rsize to be smaller than the xattr value size in p9_client_read_once() and the 9P server in WSL refused to chunk up the READ on the attr_fid and, instead, returned ERANGE to the client. The virtfs server in QEMU seems happy to chunk up the READ and this problem goes undetected there.
[tyhicks: Adjusted context due to:
- Lack of fid refcounting introduced in v5.11 commit 6636b6dcc3db ("9p:
add refcount to p9_fid struct")
- Difference in how buffer sizes are specified v5.16 commit 6e195b0f7c8e ("9p: fix a bunch of checkpatch warnings")]
--- net/9p/client.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
net/9p/client.c +1 -4
@@ -893,16 +893,13 @@ static struct p9_fid *p9_fid_create(strustruct p9_fid *fid;p9_debug (P9_DEBUG_FID ,"clnt %p\n" , clnt); - fid =kmalloc (sizeof (struct p9_fid ),GFP_KERNEL ); + fid =kzalloc (sizeof (struct p9_fid ),GFP_KERNEL );if (!fid)return NULL ; -memset (&fid->qid,0 ,sizeof (struct p9_qid )); fid->mode =-1 ; fid->uid =current_fsuid (); fid->clnt = clnt; - fid->rdir =NULL ; - fid->fid =0 ;idr_preload (GFP_KERNEL );spin_lock_irq (&clnt->lock);
Greg Kroah-Hartman
maintainerPATCH 542/545 net_sched: cls_route: disallow handle of 0
In reply to Greg Kroah-HartmanFrom: Jamal Hadi Salim <[email protected]>
commit 02799571714dc5dd6948824b9d080b44a295f695 upstream.
Follows up on:
https://lore.kernel.org/all/[email protected]/
handle of 0 implies from/to of universe realm which is not very sensible.
Lets see what this patch will do:
$sudo tc qdisc add dev $DEV root handle 1:0 prio
//lets manufacture a way to insert handle of 0
$sudo tc filter add dev $DEV parent 1:0 protocol ip prio 100 \
route to 0 from 0 classid 1:10 action ok
//gets rejected...
Error: handle of 0 is not valid.
We have an error talking to the kernel, -1
//lets create a legit entry..
sudo tc filter add dev $DEV parent 1:0 protocol ip prio 100 route from 10 \
classid 1:10 action ok
//what did the kernel insert?
$sudo tc filter ls dev $DEV parent 1:0
filter protocol ip pref 100 route chain 0
filter protocol ip pref 100 route chain 0 fh 0x000a8000 flowid 1:10 from 10
action order 1: gact action pass
random type none pass val 0
index 1 ref 1 bind 1
//Lets try to replace that legit entry with a handle of 0
$ sudo tc filter replace dev $DEV parent 1:0 protocol ip prio 100 \ handle 0x000a8000 route to 0 from 0 classid 1:10 action drop
Error: Replacing with handle of 0 is invalid.
We have an error talking to the kernel, -1
And last, lets run Cascardo's POC:
$ ./poc 0 0 -22 -22 -22
--- net/sched/cls_route.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/sched/cls_route.c +10 -0
@@ -424,6 +424,11 @@ static int route4_set_parms(struct net *return -EINVAL ; } +if (!nhandle) { +NL_SET_ERR_MSG (extack,"Replacing with handle of 0 is invalid" ); +return -EINVAL ; + } + h1 =to_hash (nhandle); b =rtnl_dereference (head->table[h1]);if (!b) {
@@ -477,6 +482,11 @@ static int route4_change(struct net *netint err;bool new = true; +if (!handle) { +NL_SET_ERR_MSG (extack,"Creating with handle of 0 is invalid" ); +return -EINVAL ; + } +if (opt ==NULL )return handle ? -EINVAL :0 ;
Greg Kroah-Hartman
maintainerPATCH 543/545 sched/fair: Fix fault in reweight_entity
In reply to Greg Kroah-HartmanFrom: Tadeusz Struk <[email protected]>
commit 13765de8148f71fa795e0a6607de37c49ea5915a upstream.
Syzbot found a GPF in reweight_entity. This has been bisected to commit 4ef0c5c6b5ba ("kernel/sched: Fix sched_fork() access an invalid sched_task_group")
There is a race between sched_post_fork() and setpriority(PRIO_PGRP) within a thread group that causes a null-ptr-deref in reweight_entity() in CFS. The scenario is that the main process spawns number of new threads, which then call setpriority(PRIO_PGRP, 0, -20), wait, and exit. For each of the new threads the copy_process() gets invoked, which adds the new task_struct and calls sched_post_fork() for it.
In the above scenario there is a possibility that setpriority(PRIO_PGRP) and set_one_prio() will be called for a thread in the group that is just being created by copy_process(), and for which the sched_post_fork() has not been executed yet. This will trigger a null pointer dereference in reweight_entity(), as it will try to access the run queue pointer, which hasn't been set.
Before the mentioned change the cfs_rq pointer for the task has been set in sched_fork(), which is called much earlier in copy_process(), before the new task is added to the thread_group. Now it is done in the sched_post_fork(), which is called after that. To fix the issue the remove the update_load param from the update_load param() function and call reweight_task() only if the task flag doesn't have the TASK_NEW flag set.
--- kernel/sched/core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
kernel/sched/core.c +6 -5
@@ -844,8 +844,9 @@ int tg_nop(struct task_group *tg, void * }#endif -static void set_load_weight (struct task_struct *p,bool update_load) +static void set_load_weight (struct task_struct *p) { +bool update_load = !(READ_ONCE (p->state) &TASK_NEW );int prio = p->static_prio -MAX_RT_PRIO ;struct load_weight *load = &p->se.load;
@@ -3266,7 +3267,7 @@ int sched_fork(unsigned long clone_flags p->static_prio =NICE_TO_PRIO (0 ); p->prio = p->normal_prio = p->static_prio; -set_load_weight (p, false); +set_load_weight (p);/* * We don't need the reset flag anymore after the fork. It has
@@ -5015,7 +5016,7 @@ void set_user_nice(struct task_struct *pput_prev_task (rq, p); p->static_prio =NICE_TO_PRIO (nice); -set_load_weight (p, true); +set_load_weight (p); old_prio = p->prio; p->prio =effective_prio (p);
@@ -5188,7 +5189,7 @@ static void __setscheduler_params(struct*/ p->rt_priority = attr->sched_priority; p->normal_prio =normal_prio (p); -set_load_weight (p, true); +set_load_weight (p); }/*
@@ -7200,7 +7201,7 @@ void __init sched_init(void)atomic_set (&rq->nr_iowait,0 ); } -set_load_weight (&init_task, false); +set_load_weight (&init_task);/* * The boot idle thread does lazy MMU switching as well:
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.137 release. There are 545 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sun, 21 Aug 2022 15:36:59 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 9 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.137-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
Compiled and booted on my test system. No dmesg regressions.
thanks,
-- Shuah
Quoted 10 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.137 release. There are 545 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sun, 21 Aug 2022 15:36:59 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.137-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
Results from Linaro's test farm.
Following regression found on powerpc.
Quoted 2 lines
Nicholas Piggin <[email protected]>
KVM: PPC: Book3S HV: Remove virt mode checks from real mode handlers
The powerpc defconfig build failed on stable-rc 5.10 with gcc and clang.
In file included from arch/powerpc/kvm/book3s_xive.c:53:arch/powerpc/kvm/book3s_xive.c:42:15: error: 'xive_vm_h_ipi' defined but not used [-Werror=unused-function]
42 | #define X_PFX xive_vm_
| ^~~~~~~~
arch/powerpc/kvm/book3s_xive_template.c:8:20: note: in definition of
macro 'XGLUE'
8 | #define XGLUE(a,b) a##b
| ^arch/powerpc/kvm/book3s_xive_template.c:606:14: note: in expansion of macro 'GLUE'
606 | X_STATIC int GLUE(X_PFX,h_ipi)(struct kvm_vcpu *vcpu, unsigned
long server,
| ^~~~
arch/powerpc/kvm/book3s_xive_template.c:606:19: note: in expansion of macro 'X_PFX'
606 | X_STATIC int GLUE(X_PFX,h_ipi)(struct kvm_vcpu *vcpu, unsigned
long server,
| ^~~~~arch/powerpc/kvm/book3s_xive.c:42:15: error: 'xive_vm_h_eoi' defined but not used [-Werror=unused-function]
42 | #define X_PFX xive_vm_
| ^~~~~~~~
arch/powerpc/kvm/book3s_xive_template.c:8:20: note: in definition of
macro 'XGLUE'
8 | #define XGLUE(a,b) a##b
| ^arch/powerpc/kvm/book3s_xive_template.c:501:14: note: in expansion of macro 'GLUE'
501 | X_STATIC int GLUE(X_PFX,h_eoi)(struct kvm_vcpu *vcpu, unsigned
long xirr)
| ^~~~
arch/powerpc/kvm/book3s_xive_template.c:501:19: note: in expansion of macro 'X_PFX'
501 | X_STATIC int GLUE(X_PFX,h_eoi)(struct kvm_vcpu *vcpu, unsigned
long xirr)
| ^~~~~arch/powerpc/kvm/book3s_xive.c:42:15: error: 'xive_vm_h_cppr' defined but not used [-Werror=unused-function]
42 | #define X_PFX xive_vm_
| ^~~~~~~~
arch/powerpc/kvm/book3s_xive_template.c:8:20: note: in definition of
macro 'XGLUE'
8 | #define XGLUE(a,b) a##b
| ^arch/powerpc/kvm/book3s_xive_template.c:442:14: note: in expansion of macro 'GLUE'
442 | X_STATIC int GLUE(X_PFX,h_cppr)(struct kvm_vcpu *vcpu,
unsigned long cppr)
| ^~~~
arch/powerpc/kvm/book3s_xive_template.c:442:19: note: in expansion of macro 'X_PFX'
442 | X_STATIC int GLUE(X_PFX,h_cppr)(struct kvm_vcpu *vcpu,
unsigned long cppr)
| ^~~~~arch/powerpc/kvm/book3s_xive.c:42:15: error: 'xive_vm_h_ipoll' defined but not used [-Werror=unused-function]
42 | #define X_PFX xive_vm_
| ^~~~~~~~
arch/powerpc/kvm/book3s_xive_template.c:8:20: note: in definition of
macro 'XGLUE'
8 | #define XGLUE(a,b) a##b
| ^arch/powerpc/kvm/book3s_xive_template.c:323:24: note: in expansion of macro 'GLUE'
323 | X_STATIC unsigned long GLUE(X_PFX,h_ipoll)(struct kvm_vcpu
*vcpu, unsigned long server)
| ^~~~arch/powerpc/kvm/book3s_xive_template.c:323:29: note: in expansion of macro 'X_PFX'
323 | X_STATIC unsigned long GLUE(X_PFX,h_ipoll)(struct kvm_vcpu
*vcpu, unsigned long server)
| ^~~~~arch/powerpc/kvm/book3s_xive.c:42:15: error: 'xive_vm_h_xirr' defined but not used [-Werror=unused-function]
42 | #define X_PFX xive_vm_
| ^~~~~~~~
arch/powerpc/kvm/book3s_xive_template.c:8:20: note: in definition of
macro 'XGLUE'
8 | #define XGLUE(a,b) a##b
| ^arch/powerpc/kvm/book3s_xive_template.c:272:24: note: in expansion of macro 'GLUE'
272 | X_STATIC unsigned long GLUE(X_PFX,h_xirr)(struct kvm_vcpu *vcpu)
| ^~~~arch/powerpc/kvm/book3s_xive_template.c:272:29: note: in expansion of macro 'X_PFX'
272 | X_STATIC unsigned long GLUE(X_PFX,h_xirr)(struct kvm_vcpu *vcpu)
| ^~~~~
cc1: all warnings being treated as errors
## Build
* kernel: 5.10.137-rc1
* git: https://gitlab.com/Linaro/lkft/mirrors/stable/linux-stable-rc
* git branch: linux-5.10.y
* git commit: 623e70e98313ed8ce5eb6da1ec87e1471d4e6af6
* git describe: v5.10.136-546-g623e70e98313
* test details:
https://qa-reports.linaro.org/lkft/linux-stable-rc-linux-5.10.y/build/v5.10.136-546-g623e70e98313
## Test Regressions (compared to v5.10.136)
* powerpc, build
- clang-13-defconfig
- clang-14-defconfig
- clang-nightly-defconfig
- gcc-10-defconfig
- gcc-11-defconfig
- gcc-8-defconfig
- gcc-9-defconfig
## No metric Regressions (compared to v5.10.136)
## No test Fixes (compared to v5.10.136)
## No metric Fixes (compared to v5.10.136)
## Test result summary
total: 125787, pass: 110926, fail: 582, skip: 13467, xfail: 812
## Build Summary
* arc: 10 total, 10 passed, 0 failed
* arm: 309 total, 309 passed, 0 failed
* arm64: 71 total, 69 passed, 2 failed
* i386: 60 total, 58 passed, 2 failed
* mips: 45 total, 45 passed, 0 failed
* parisc: 12 total, 12 passed, 0 failed
* powerpc: 51 total, 44 passed, 7 failed
* riscv: 27 total, 27 passed, 0 failed
* s390: 21 total, 21 passed, 0 failed
* sh: 24 total, 24 passed, 0 failed
* sparc: 12 total, 12 passed, 0 failed
* x86_64: 64 total, 62 passed, 2 failed
## Test suites summary
* fwts
* igt-gpu-tools
* kunit
* kvm-unit-tests
* libgpiod
* libhugetlbfs
* log-parser-boot
* log-parser-test
* ltp-cap_bounds
* ltp-commands
* ltp-containers
* ltp-controllers
* ltp-cpuhotplug
* ltp-crypto
* ltp-cve
* ltp-dio
* ltp-fcntl-locktests
* ltp-filecaps
* ltp-fs
* ltp-fs_bind
* ltp-fs_perms_simple
* ltp-fsx
* ltp-hugetlb
* ltp-io
* ltp-ipc
* ltp-math
* ltp-mm
* ltp-nptl
* ltp-open-posix-tests
* ltp-pty
* ltp-sched
* ltp-securebits
* ltp-smoke
* ltp-syscalls
* ltp-tracing
* network-basic-tests
* packetdrill
* rcutorture
* ssuite
* v4l2-compliance
* vdso
--
Linaro LKFT
https://lkft.linaro.org
Greg Kroah-Hartman
maintainerQuoted 120 lines · Naresh Kamboju
Quoted 10 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.137 release. There are 545 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sun, 21 Aug 2022 15:36:59 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.137-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
Results from Linaro's test farm.
Following regression found on powerpc.Quoted 2 lines
Nicholas Piggin <[email protected]>
KVM: PPC: Book3S HV: Remove virt mode checks from real mode handlersThe powerpc defconfig build failed on stable-rc 5.10 with gcc and clang.
In file included from
arch/powerpc/kvm/book3s_xive.c:53:arch/powerpc/kvm/book3s_xive.c:42:15: error: 'xive_vm_h_ipi' defined but not used [-Werror=unused-function]
42 | #defineX_PFXxive_vm_| ^~~~~~~~ arch/powerpc/kvm/book3s_xive_template.c:8:20: note: in definition of macro 'XGLUE' 8 | #define XGLUE(a,b) a##b | ^
arch/powerpc/kvm/book3s_xive_template.c:606:14: note: in expansion of macro 'GLUE'
606 |X_STATICint GLUE(X_PFX,h_ipi)(structkvm_vcpu*vcpu, unsigned
long server,| ^~~~
arch/powerpc/kvm/book3s_xive_template.c:606:19: note: in expansion of macro 'X_PFX'
606 |X_STATICint GLUE(X_PFX,h_ipi)(structkvm_vcpu*vcpu, unsigned
long server,
| ^~~~~arch/powerpc/kvm/book3s_xive.c:42:15: error: 'xive_vm_h_eoi' defined but not used [-Werror=unused-function]
42 | #defineX_PFXxive_vm_| ^~~~~~~~ arch/powerpc/kvm/book3s_xive_template.c:8:20: note: in definition of macro 'XGLUE' 8 | #define XGLUE(a,b) a##b | ^
arch/powerpc/kvm/book3s_xive_template.c:501:14: note: in expansion of macro 'GLUE'
501 |X_STATICint GLUE(X_PFX,h_eoi)(structkvm_vcpu*vcpu, unsigned
long xirr)| ^~~~
arch/powerpc/kvm/book3s_xive_template.c:501:19: note: in expansion of macro 'X_PFX'
501 |X_STATICint GLUE(X_PFX,h_eoi)(structkvm_vcpu*vcpu, unsigned
long xirr)
| ^~~~~arch/powerpc/kvm/book3s_xive.c:42:15: error: 'xive_vm_h_cppr' defined but not used [-Werror=unused-function]
42 | #defineX_PFXxive_vm_| ^~~~~~~~ arch/powerpc/kvm/book3s_xive_template.c:8:20: note: in definition of macro 'XGLUE' 8 | #define XGLUE(a,b) a##b | ^
arch/powerpc/kvm/book3s_xive_template.c:442:14: note: in expansion of macro 'GLUE'
442 |X_STATICint GLUE(X_PFX,h_cppr)(structkvm_vcpu*vcpu,
unsigned long cppr)| ^~~~
arch/powerpc/kvm/book3s_xive_template.c:442:19: note: in expansion of macro 'X_PFX'
442 |X_STATICint GLUE(X_PFX,h_cppr)(structkvm_vcpu*vcpu,
unsigned long cppr)
| ^~~~~arch/powerpc/kvm/book3s_xive.c:42:15: error: 'xive_vm_h_ipoll' defined but not used [-Werror=unused-function]
42 | #defineX_PFXxive_vm_| ^~~~~~~~ arch/powerpc/kvm/book3s_xive_template.c:8:20: note: in definition of macro 'XGLUE' 8 | #define XGLUE(a,b) a##b | ^
arch/powerpc/kvm/book3s_xive_template.c:323:24: note: in expansion of macro 'GLUE'
323 |X_STATICunsigned long GLUE(X_PFX,h_ipoll)(structkvm_vcpu
*vcpu, unsigned long server)
| ^~~~arch/powerpc/kvm/book3s_xive_template.c:323:29: note: in expansion of macro 'X_PFX'
323 |X_STATICunsigned long GLUE(X_PFX,h_ipoll)(structkvm_vcpu
*vcpu, unsigned long server)
| ^~~~~arch/powerpc/kvm/book3s_xive.c:42:15: error: 'xive_vm_h_xirr' defined but not used [-Werror=unused-function]
42 | #defineX_PFXxive_vm_| ^~~~~~~~ arch/powerpc/kvm/book3s_xive_template.c:8:20: note: in definition of macro 'XGLUE' 8 | #define XGLUE(a,b) a##b | ^
arch/powerpc/kvm/book3s_xive_template.c:272:24: note: in expansion of macro 'GLUE'
272 |X_STATICunsigned long GLUE(X_PFX,h_xirr)(structkvm_vcpu*vcpu)
| ^~~~arch/powerpc/kvm/book3s_xive_template.c:272:29: note: in expansion of macro 'X_PFX'
272 |X_STATICunsigned long GLUE(X_PFX,h_xirr)(structkvm_vcpu*vcpu)
| ^~~~~
cc1: all warnings being treated as errors
Quoted 2 lines
Thanks, I've dropped 2 powerpc kvm patches now that look to have caused this and will push out a -rc2 with that hopefully fixed up.
greg k-h
Quoted 7 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.137 release. There are 545 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sun, 21 Aug 2022 15:36:59 +0000. Anything received after that time might be too late.
Hi Greg,
5.10.137-rc1 tested.
Run tested on:
- Intel Skylake x86_64 (nuc6 i5-6260U)
In addition - build tested for:
- Allwinner A64
- Allwinner H3
- Allwinner H5
- Allwinner H6
- Rockchip RK3288
- Rockchip RK3328
- Rockchip RK3399pro
--
Rudi
Hi Greg,
Quoted 7 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.137 release. There are 545 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sun, 21 Aug 2022 15:36:59 +0000. Anything received after that time might be too late.
Build test (gcc version 11.3.1 20220819):
mips: 63 configs -> no failure
arm: 104 configs -> no failure
arm64: 3 configs -> no failurex86_64: 4 configs -> no failure
alpha allmodconfig -> no failure
powerpc allmodconfig -> no failure
riscv allmodconfig -> no failure
s390 allmodconfig -> no failure
xtensa allmodconfig -> no failure
Boot test:x86_64: Booted on my test laptop. No regression.x86_64: Booted on qemu. No regression. [1]
[1]. https://openqa.qa.codethink.co.uk/tests/1661
--
Regards
Sudip
Hi!
Quoted 4 lines
This is the start of the stable review cycle for the 5.10.137 release. There are 545 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
CIP testing did not find any problems here:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/tree/linux-5.10.y
Best regards,
Pavel
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Quoted 8 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.137 release. There are 545 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sun, 21 Aug 2022 15:36:59 +0000. Anything received after that time might be too late.
Build results:
total: 163 pass: 161 fail: 2
Failed builds:
powerpc:defconfig
um:defconfig
Qemu test results:
total: 474 pass: 451 fail: 23 Failed tests: <various ppc64>
Problems have ben reported already, so I assume I don't have to go into details.
Guenter
Greg Kroah-Hartman
maintainerPATCH 544/545 btrfs: only write the sectors in the vertical stripe which has data stripes
In reply to Greg Kroah-HartmanFrom: Qu Wenruo <[email protected]>
commit bd8f7e627703ca5707833d623efcd43f104c7b3f upstream.
If we have only 8K partial write at the beginning of a full RAID56 stripe, we will write the following contents:
0 8K 32K 64K
Disk 1 (data): |XX| | |
Disk 2 (data): | | | Disk 3 (parity): |XXXXXXXXXXXXXXX|XXXXXXXXXXXXXXX|
|X| means the sector will be written back to disk.
Note that, although we won't write any sectors from disk 2, but we will write the full 64KiB of parity to disk.
This behavior is fine for now, but not for the future (especially for RAID56J, as we waste quite some space to journal the unused parity stripes).
So here we will also utilize the btrfs_raid_bio::dbitmap, anytime we queue a higher level bio into an rbio, we will update rbio::dbitmap to indicate which vertical stripes we need to writeback.
And at finish_rmw(), we also check dbitmap to see if we need to write any sector in the vertical stripe.
So after the patch, above example will only lead to the following writeback pattern:
0 8K 32K 64K
Disk 1 (data): |XX| | |
Disk 2 (data): | | | Disk 3 (parity): |XX| | |
--- fs/btrfs/raid56.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-)
fs/btrfs/raid56.c +51 -4
@@ -332,6 +332,9 @@ static void merge_rbio(struct btrfs_raid {bio_list_merge (&dest->bio_list, &victim->bio_list); dest->bio_list_bytes += victim->bio_list_bytes; +/* Also inherit the bitmaps from @victim. */ +bitmap_or (dest->dbitmap, victim->dbitmap, dest->dbitmap, + dest->stripe_npages); dest->generic_bio_cnt += victim->generic_bio_cnt;bio_list_init (&victim->bio_list); }
@@ -874,6 +877,12 @@ static void rbio_orig_end_io(struct btrfif (rbio->generic_bio_cnt)btrfs_bio_counter_sub (rbio->fs_info, rbio->generic_bio_cnt); +/* +* Clear the data bitmap, as the rbio may be cached for later usage. +* do this before before unlock_stripe() so there will be no new bio +* for this bio. +*/ +bitmap_clear (rbio->dbitmap,0 , rbio->stripe_npages);/* * At this moment, rbio->bio_list is empty, however since rbio does not
@@ -1207,6 +1216,9 @@ static noinline void finish_rmw(struct belse BUG (); +/* We should have at least one data sector. */ +ASSERT (bitmap_weight (rbio->dbitmap, rbio->stripe_npages)); +/* at this point we either have a full stripe, * or we've read the full stripe from the drive. * recalculate the parity and write the new results.
@@ -1280,6 +1292,11 @@ static noinline void finish_rmw(struct bfor (stripe =0 ; stripe < rbio->real_stripes; stripe++) {for (pagenr =0 ; pagenr < rbio->stripe_npages; pagenr++) {struct page *page; + +/* This vertical stripe has no data, skip it. */ +if (!test_bit (pagenr, rbio->dbitmap)) +continue ; +if (stripe < rbio->nr_data) { page =page_in_rbio (rbio, stripe, pagenr,1 );if (!page)
@@ -1304,6 +1321,11 @@ static noinline void finish_rmw(struct bfor (pagenr =0 ; pagenr < rbio->stripe_npages; pagenr++) {struct page *page; + +/* This vertical stripe has no data, skip it. */ +if (!test_bit (pagenr, rbio->dbitmap)) +continue ; +if (stripe < rbio->nr_data) { page =page_in_rbio (rbio, stripe, pagenr,1 );if (!page)
@@ -1729,6 +1751,33 @@ static void btrfs_raid_unplug(struct blkrun_plug (plug); } +/* Add the original bio into rbio->bio_list, and update rbio::dbitmap. */ +static void rbio_add_bio (struct btrfs_raid_bio *rbio,struct bio *orig_bio) +{ +const struct btrfs_fs_info *fs_info = rbio->fs_info; +const u64 orig_logical = orig_bio->bi_iter.bi_sector <<SECTOR_SHIFT ; +const u64 full_stripe_start = rbio->bbio->raid_map[0 ]; +const u32 orig_len = orig_bio->bi_iter.bi_size; +const u32 sectorsize = fs_info->sectorsize; +u64 cur_logical; + +ASSERT (orig_logical >= full_stripe_start && + orig_logical + orig_len <= full_stripe_start + + rbio->nr_data * rbio->stripe_len); + +bio_list_add (&rbio->bio_list, orig_bio); + rbio->bio_list_bytes += orig_bio->bi_iter.bi_size; + +/* Update the dbitmap. */ +for (cur_logical = orig_logical; cur_logical < orig_logical + orig_len; + cur_logical += sectorsize) { +int bit = ((u32)(cur_logical - full_stripe_start) >> +PAGE_SHIFT ) % rbio->stripe_npages; + +set_bit (bit, rbio->dbitmap); + } +} +/* * our main entry point for writes from the rest of the FS. */
@@ -1745,9 +1794,8 @@ int raid56_parity_write(struct btrfs_fs_btrfs_put_bbio (bbio);return PTR_ERR (rbio); } -bio_list_add (&rbio->bio_list, bio); - rbio->bio_list_bytes = bio->bi_iter.bi_size; rbio->operation =BTRFS_RBIO_WRITE ; +rbio_add_bio (rbio, bio);btrfs_bio_counter_inc_noblocked (fs_info); rbio->generic_bio_cnt =1 ;
@@ -2144,8 +2192,7 @@ int raid56_parity_recover(struct btrfs_f } rbio->operation =BTRFS_RBIO_READ_REBUILD ; -bio_list_add (&rbio->bio_list, bio); - rbio->bio_list_bytes = bio->bi_iter.bi_size; +rbio_add_bio (rbio, bio); rbio->faila =find_logical_bio_stripe (rbio, bio);if (rbio->faila ==-1 ) {
Greg Kroah-Hartman
maintainerPATCH 545/545 btrfs: raid56: dont trust any cached sector in __raid56_parity_recover()
In reply to Greg Kroah-HartmanFrom: Qu Wenruo <[email protected]>
commit f6065f8edeb25f4a9dfe0b446030ad995a84a088 upstream.
[BUG]
There is a small workload which will always fail with recent kernel:
(A simplified version from btrfs/125 test case)
mkfs.btrfs -f -m raid5 -d raid5 -b 1G $dev1 $dev2 $dev3 mount $dev1 $mnt xfs_io -f -c "pwrite -S 0xee 0 1M" $mnt/file1 sync umount $mnt btrfs dev scan -u $dev3 mount -o degraded $dev1 $mnt xfs_io -f -c "pwrite -S 0xff 0 128M" $mnt/file2 umount $mnt btrfs dev scan mount $dev1 $mnt btrfs balance start --full-balance $mnt umount $mnt
The failure is always failed to read some tree blocks:
BTRFS info (device dm-4): relocating block group 217710592 flags data|raid5 BTRFS error (device dm-4): parent transid verify failed on 38993920 wanted 9 found 7 BTRFS error (device dm-4): parent transid verify failed on 38993920 wanted 9 found 7
...
[CAUSE]
With the recently added debug output, we can see all RAID56 operations related to full stripe 38928384:
56.1183: raid56_read_partial: full_stripe=38928384 devid=2 type=DATA1 offset=0 opf=0x0 physical=9502720 len=65536 56.1185: raid56_read_partial: full_stripe=38928384 devid=3 type=DATA2 offset=16384 opf=0x0 physical=9519104 len=16384 56.1185: raid56_read_partial: full_stripe=38928384 devid=3 type=DATA2 offset=49152 opf=0x0 physical=9551872 len=16384 56.1187: raid56_write_stripe: full_stripe=38928384 devid=3 type=DATA2 offset=0 opf=0x1 physical=9502720 len=16384 56.1188: raid56_write_stripe: full_stripe=38928384 devid=3 type=DATA2 offset=32768 opf=0x1 physical=9535488 len=16384 56.1188: raid56_write_stripe: full_stripe=38928384 devid=1 type=PQ1 offset=0 opf=0x1 physical=30474240 len=16384 56.1189: raid56_write_stripe: full_stripe=38928384 devid=1 type=PQ1 offset=32768 opf=0x1 physical=30507008 len=16384 56.1218: raid56_write_stripe: full_stripe=38928384 devid=3 type=DATA2 offset=49152 opf=0x1 physical=9551872 len=16384 56.1219: raid56_write_stripe: full_stripe=38928384 devid=1 type=PQ1 offset=49152 opf=0x1 physical=30523392 len=16384 56.2721: raid56_parity_recover: full stripe=38928384 eb=39010304 mirror=2
56.2723: raid56_parity_recover: full stripe=38928384 eb=39010304 mirror=2
56.2724: raid56_parity_recover: full stripe=38928384 eb=39010304 mirror=2
Before we enter raid56_parity_recover(), we have triggered some metadata write for the full stripe 38928384, this leads to us to read all the sectors from disk.
Furthermore, btrfs raid56 write will cache its calculated P/Q sectors to avoid unnecessary read.
This means, for that full stripe, after any partial write, we will have stale data, along with P/Q calculated using that stale data.
Thankfully due to patch "btrfs: only write the sectors in the vertical stripe which has data stripes" we haven't submitted all the corrupted P/Q to disk.
When we really need to recover certain range, aka in raid56_parity_recover(), we will use the cached rbio, along with its cached sectors (the full stripe is all cached).
This explains why we have no event raid56_scrub_read_recover() triggered.
Since we have the cached P/Q which is calculated using the stale data, the recovered one will just be stale.
In our particular test case, it will always return the same incorrect metadata, thus causing the same error message "parent transid verify failed on 39010304 wanted 9 found 7" again and again.
[BTRFS DESTRUCTIVE RMW PROBLEM]
Test case btrfs/125 (and above workload) always has its trouble with the destructive read-modify-write (RMW) cycle:
0 32K 64K Data1: | Good | Good | Data2: | Bad | Bad | Parity: | Good | Good |
In above case, if we trigger any write into Data1, we will use the bad data in Data2 to re-generate parity, killing the only chance to recovery Data2, thus Data2 is lost forever.
This destructive RMW cycle is not specific to btrfs RAID56, but there are some btrfs specific behaviors making the case even worse:
- Btrfs will cache sectors for unrelated vertical stripes.
In above example, if we're only writing into 0~32K range, btrfs will still read data range (32K ~ 64K) of Data1, and (64K~128K) of Data2. This behavior is to cache sectors for later update.
Incidentally commit d4e28d9b5f04 ("btrfs: raid56: make steal_rbio() subpage compatible") has a bug which makes RAID56 to never trust the cached sectors, thus slightly improve the situation for recovery.
Unfortunately, follow up fix "btrfs: update stripe_sectors::uptodate in steal_rbio" will revert the behavior back to the old one.
- Btrfs raid56 partial write will update all P/Q sectors and cache them
This means, even if data at (64K ~ 96K) of Data2 is free space, and only (96K ~ 128K) of Data2 is really stale data.
And we write into that (96K ~ 128K), we will update all the parity sectors for the full stripe.
This unnecessary behavior will completely kill the chance of recovery.
Thankfully, an unrelated optimization "btrfs: only write the sectors in the vertical stripe which has data stripes" will prevent submitting the write bio for untouched vertical sectors.
That optimization will keep the on-disk P/Q untouched for a chance for later recovery.
[FIX]
Although we have no good way to completely fix the destructive RMW (unless we go full scrub for each partial write), we can still limit the damage.
With patch "btrfs: only write the sectors in the vertical stripe which has data stripes" now we won't really submit the P/Q of unrelated vertical stripes, so the on-disk P/Q should still be fine.
Now we really need to do is just drop all the cached sectors when doing recovery.
By this, we have a chance to read the original P/Q from disk, and have a chance to recover the stale data, while still keep the cache to speed up regular write path.
In fact, just dropping all the cache for recovery path is good enough to allow the test case btrfs/125 along with the small script to pass reliably.
The lack of metadata write after the degraded mount, and forced metadata COW is saving us this time.
So this patch will fix the behavior by not trust any cache in __raid56_parity_recover(), to solve the problem while still keep the cache useful.
But please note that this test pass DOES NOT mean we have solved the destructive RMW problem, we just do better damage control a little better.
Related patches:
- btrfs: only write the sectors in the vertical stripe
- d4e28d9b5f04 ("btrfs: raid56: make steal_rbio() subpage compatible")
- btrfs: update stripe_sectors::uptodate in steal_rbio
--- fs/btrfs/raid56.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
fs/btrfs/raid56.c +6 -13
@@ -2094,9 +2094,12 @@ static int __raid56_parity_recover(strucatomic_set (&rbio->error,0 );/* -* read everything that hasn't failed. Thanks to the -* stripe cache, it is possible that some or all of these -* pages are going to be uptodate. +* Read everything that hasn't failed. However this time we will +* not trust any cached sector. +* As we may read out some stale data but higher layer is not reading +* that stale part. +* +* So here we always re-read everything in recovery path. */ for (stripe =0 ; stripe < rbio->real_stripes; stripe++) {if (rbio->faila == stripe || rbio->failb == stripe) {
@@ -2105,16 +2108,6 @@ static int __raid56_parity_recover(struc }for (pagenr =0 ; pagenr < rbio->stripe_npages; pagenr++) { -struct page *p; - -/* -* the rmw code may have already read this -* page in -*/ - p =rbio_stripe_page (rbio, stripe, pagenr); -if (PageUptodate (p)) -continue ; - ret =rbio_add_io_page (rbio, &bio_list,rbio_stripe_page (rbio, stripe, pagenr), stripe, pagenr, rbio->stripe_len);