6.18.64-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 482/686 lib/crypto: mips: Disable Octeon SHA code on little-endian kernels
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit dd2a4edb26e1c78823c50ba10c42f2d3de2e5ec4 upstream.
Kernels built for the MIPS64-based Cavium Octeon SoCs are normally big-endian, but little-endian builds are also supported. Currently, the SHA-1, SHA-256, and SHA-512 code using the Octeon crypto co-processor is enabled in both builds.
This code is untestable without the hardware. However, based on the code itself, it is implausible that it computes hash values correctly in little-endian builds. Such builds write many incorrect values to COP2:
- SHA-1 and SHA-256: The 64-bit integer that contains the last two 32-bit message words of each block is written to COP2 entirely byte-reflected, due to missing endianness conversion in octeon_sha1_start() and octeon_sha256_start() to compensate for using native 64-bit loads from the message bytes. This differs from all the earlier message words which are written correctly.
Furthermore, the state is written to COP2 with each 32-bit word byte-reflected within each 64-bit integer, due to incorrect use of 64-bit endianness conversion in write_octeon_64bit_hash_dword() when the state is kept in memory in native-endian 32-bit words.
- SHA-512: All the 64-bit message words are written to COP2 byte-reflected, due to missing endianness conversion in write_octeon_64bit_block_sha512() and octeon_sha512_start(). The SHA-512 state words seem to be written correctly.
Big-endian kernels aren't affected by these bugs. These bugs also aren't new; this code has been broken on little-endian ever since it and Octeon little-endian support were first added in v4.1.
Commit d2a948d2db68 ("MIPS: Octeon: Make octeon-md5 driver endian-agnostic") made the MD5 code work on little-endian kernels by adding 64-bit endianness conversions to the COP2 macros used by MD5 (some of which are shared by SHA-1 and SHA-256, despite those algorithms keeping the state words in native-endian instead of MD5's little-endian, causing some of the strange behavior described above). However, SHA-1, SHA-256, and SHA-512 were never fixed to work on little-endian kernels.
Therefore, disable the Octeon SHA-1, SHA-256, and SHA-512 code in little-endian kernels. This causes the generic code that actually computes hash values correctly to be used instead.
--- lib/crypto/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/crypto/Kconfig +3 -3
@@ -142,7 +142,7 @@ config CRYPTO_LIB_SHA1_ARCH depends on CRYPTO_LIB_SHA1 && !UML default y if ARM default y if ARM64 && KERNEL_MODE_NEON - default y if MIPS && CPU_CAVIUM_OCTEON + default y if MIPS && CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN default y if PPC default y if S390 default y if SPARC64
@@ -160,7 +160,7 @@ config CRYPTO_LIB_SHA256_ARCH depends on CRYPTO_LIB_SHA256 && !UML default y if ARM && !CPU_V7M default y if ARM64 - default y if MIPS && CPU_CAVIUM_OCTEON + default y if MIPS && CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN default y if PPC && SPE default y if RISCV && 64BIT && TOOLCHAIN_HAS_VECTOR_CRYPTO && \ RISCV_EFFICIENT_VECTOR_UNALIGNED_ACCESS
@@ -180,7 +180,7 @@ config CRYPTO_LIB_SHA512_ARCH depends on CRYPTO_LIB_SHA512 && !UML default y if ARM && !CPU_V7M default y if ARM64 - default y if MIPS && CPU_CAVIUM_OCTEON + default y if MIPS && CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN default y if RISCV && 64BIT && TOOLCHAIN_HAS_VECTOR_CRYPTO && \ RISCV_EFFICIENT_VECTOR_UNALIGNED_ACCESS default y if S390
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 483/686 kho: do not reserve scratch memory in the kdump kernel
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxi Saparov <[email protected]>
[ Upstream commit 48be325089e15077411785d0c41ddb9071a61081 ]
If a kernel with CONFIG_KEXEC_HANDOVER_ENABLE_DEFAULT=y (or kho=on) does not receive a handover FDT, it reserves KHO scratch memory in kho_reserve_scratch().
The kdump kernel always takes this path. Since commit a6715d7ec472 ("kho: skip KHO for crash kernel"), the kernel does not add KHO metadata to the crash kimage. As a result, the kdump kernel never receives a handover FDT and always reserves scratch memory.
The kdump kernel boots in the small crashkernel= memory reservation. On our x86 hosts, the kernel and initramfs make approximately 176 MB of early reservations. The scratch areas then use approximately 650 MB more of the crashkernel memory. When a large early allocation fails, the kdump kernel panics:
bio: can't create integrity buf pool
A kdump kernel has nothing to hand over: its only task is to dump the memory of the old kernel and reboot. Fix is to disable KHO at the top of kho_memory_init() so that the kdump kernel does not reserve scratch memory.
--- kernel/kexec_handover.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/kexec_handover.c +7 -0
@@ -10,6 +10,7 @@#include <linux/cleanup.h> #include <linux/cma.h> +#include <linux/crash_dump.h> #include <linux/count_zeros.h> #include <linux/kexec.h> #include <linux/kexec_handover.h>
@@ -1325,6 +1326,12 @@ void __init kho_memory_init(void) {struct folio *folio; +if (is_kdump_kernel ()) { + kho_enable = false; +pr_info ("disabled in the kdump kernel\n" ); +return ; + } +if (kho_in.scratch_phys) { kho_scratch =phys_to_virt (kho_in.scratch_phys);kho_release_scratch ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 484/686 mtd: spi-nor: macronix: Restore fallback parameters for MX25L12805D
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cheng Ming Lin <[email protected]>
[ Upstream commit 01739ccea21b69818dc071096a249e6f84a6b13d ]
In a previous effort to drop flash_info fields and rely on SFDP, the static size and no_sfdp_flags were removed from the MX25L12805D entry (JEDEC ID 0xc22018).
At that time, the legacy MX25L12805D was already EOL and unavailable for physical testing. Verification was inadvertently performed using the newer MX25L12833F, which shares the same JEDEC ID but supports SFDP. As a result, the probe succeeded during testing, leading to the mistaken removal of the fallback parameters.
Since the actual MX25L12805D lacks SFDP support entirely, it strictly requires these static parameters.
Restore .size = SZ_16M and .no_sfdp_flags = SECT_4K to this entry to fix the probe failure for the legacy part.
--- drivers/mtd/spi-nor/macronix.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mtd/spi-nor/macronix.c +2 -0
@@ -132,7 +132,9 @@ static const struct flash_info macronix_nor_parts[] = { }, {/* MX25L12805D */ .id = SNOR_ID(0xc2, 0x20, 0x18), + .size = SZ_16M, .flags = SPI_NOR_HAS_LOCK | SPI_NOR_4BIT_BP, + .no_sfdp_flags = SECT_4K, }, {/* MX25L25635E, MX25L25645G */ .id = SNOR_ID(0xc2, 0x20, 0x19),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 485/686 media: i2c: imx219: Propagate errors from control range updates
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tarang Raval <[email protected]>
[ Upstream commit dff10c7044e8777bd14bba99444ff8a69d9bb2fe ]
Propagate return values from __v4l2_ctrl_modify_range() and __v4l2_ctrl_s_ctrl() in imx219_set_ctrl() and imx219_set_pad_format(). This ensures proper error handling instead of ignoring possible failures. Also return the result of imx219_set_pad_format() from imx219_init_state().
Stable-dep-of: 47576c541e9b ("media: imx219: The horizontal blanking step is 8")
--- drivers/media/i2c/imx219.c | 61 +++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 21 deletions(-)
drivers/media/i2c/imx219.c +40 -21
@@ -463,10 +463,14 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) exposure_max = format->height + ctrl->val -4 ; exposure_def = (exposure_max <IMX219_EXPOSURE_DEFAULT ) ? exposure_max :IMX219_EXPOSURE_DEFAULT ; -__v4l2_ctrl_modify_range (imx219->exposure, - imx219->exposure->minimum, - exposure_max, imx219->exposure->step, - exposure_def); + ret =__v4l2_ctrl_modify_range (imx219->exposure, + imx219->exposure->minimum, + exposure_max, + imx219->exposure->step, + exposure_def); +if (ret) +return ret; + }/*
@@ -858,6 +862,7 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,struct v4l2_rect *crop;u8 bin_h, bin_v, binning;u32 prev_line_len; +int ret; format =v4l2_subdev_state_get_format (state,0 ); prev_line_len = format->width + imx219->hblank->val;
@@ -893,19 +898,28 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,int pixel_rate;/* Update limits and set FPS to default */ -__v4l2_ctrl_modify_range (imx219->vblank,IMX219_VBLANK_MIN , -IMX219_FLL_MAX - mode->height,1 , + ret =__v4l2_ctrl_modify_range (imx219->vblank,IMX219_VBLANK_MIN , +IMX219_FLL_MAX - mode->height,1 , + mode->fll_def - mode->height); +if (ret) +return ret; + + ret =__v4l2_ctrl_s_ctrl (imx219->vblank, mode->fll_def - mode->height); -__v4l2_ctrl_s_ctrl (imx219->vblank, - mode->fll_def - mode->height); +if (ret) +return ret; +/* Update max exposure while meeting expected vblanking */ exposure_max = mode->fll_def -4 ; exposure_def = (exposure_max <IMX219_EXPOSURE_DEFAULT ) ? exposure_max :IMX219_EXPOSURE_DEFAULT ; -__v4l2_ctrl_modify_range (imx219->exposure, - imx219->exposure->minimum, - exposure_max, imx219->exposure->step, - exposure_def); + ret =__v4l2_ctrl_modify_range (imx219->exposure, + imx219->exposure->minimum, + exposure_max, + imx219->exposure->step, + exposure_def); +if (ret) +return ret;/* * With analog binning the default minimum line length of 3448
@@ -916,9 +930,12 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,imx219_get_binning (state, &bin_h, &bin_v); llp_min = (bin_h & bin_v) ==IMX219_BINNING_X2_ANALOG ?IMX219_BINNED_LLP_MIN :IMX219_LLP_MIN ; -__v4l2_ctrl_modify_range (imx219->hblank, llp_min - mode->width, -IMX219_LLP_MAX - mode->width,1 , - llp_min - mode->width); + ret =__v4l2_ctrl_modify_range (imx219->hblank, + llp_min - mode->width, +IMX219_LLP_MAX - mode->width,1 , + llp_min - mode->width); +if (ret) +return ret;/* * Retain PPL setting from previous mode so that the * line time does not change on a mode change.
@@ -927,13 +944,17 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,* mode width subtracted. */ hblank = prev_line_len - mode->width; -__v4l2_ctrl_s_ctrl (imx219->hblank, hblank); + ret =__v4l2_ctrl_s_ctrl (imx219->hblank, hblank); +if (ret) +return ret;/* Scale the pixel rate based on the mode specific factor */ pixel_rate =imx219_get_pixel_rate (imx219) *imx219_get_rate_factor (state); -__v4l2_ctrl_modify_range (imx219->pixel_rate, pixel_rate, - pixel_rate,1 , pixel_rate); + ret =__v4l2_ctrl_modify_range (imx219->pixel_rate, pixel_rate, + pixel_rate,1 , pixel_rate); +if (ret) +return ret; }return 0 ;
@@ -982,9 +1003,7 @@ static int imx219_init_state(struct v4l2_subdev *sd, }, }; -imx219_set_pad_format (sd, state, &fmt); - -return 0 ; +return imx219_set_pad_format (sd, state, &fmt); }static const struct v4l2_subdev_video_ops imx219_video_ops = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 486/686 media: imx219: The horizontal blanking step is 8
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sakari Ailus <[email protected]>
[ Upstream commit 47576c541e9b473841742bd0686d4940f5c93564 ]
The step for the LINE_LENGTH_A register on imx219 is 8. Take this into account in creating and modifying the horizontal blanking control. The minimum line length in pixels as well as the horizontal blanking values are already divisible by 8.
--- drivers/media/i2c/imx219.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/media/i2c/imx219.c +5 -2
@@ -77,6 +77,7 @@#define IMX219_LLP_MIN 0x0d78#define IMX219_BINNED_LLP_MIN 0x0de8#define IMX219_LLP_MAX 0x7ff0 +#define IMX219_LLP_STEP 8#define IMX219_REG_X_ADD_STA_A CCI_REG16(0x0164)#define IMX219_REG_X_ADD_END_A CCI_REG16(0x0166)
@@ -587,7 +588,8 @@ static int imx219_init_controls(struct imx219 *imx219) imx219->hblank =v4l2_ctrl_new_std (ctrl_hdlr, &imx219_ctrl_ops,V4L2_CID_HBLANK ,IMX219_LLP_MIN - mode->width, -IMX219_LLP_MAX - mode->width,1 , +IMX219_LLP_MAX - mode->width, +IMX219_LLP_STEP ,IMX219_LLP_MIN - mode->width); exposure_max = mode->fll_def -4 ; exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ?
@@ -932,7 +934,8 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd, IMX219_BINNED_LLP_MIN :IMX219_LLP_MIN ; ret =__v4l2_ctrl_modify_range (imx219->hblank, llp_min - mode->width, -IMX219_LLP_MAX - mode->width,1 , +IMX219_LLP_MAX - mode->width, +IMX219_LLP_STEP , llp_min - mode->width);if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 487/686 soc: qcom: pmic_glink: Fix device access from worker during suspend
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit 7d0767c5cd878707fd6711023731549c83563840 ]
For historical reasons, the GLINK smem interrupt is registered with IRRQF_NO_SUSPEND flag set, which is the underlying problem here, since the incoming messages can be delivered during late suspend and early resume.
In this specific case, the pmic_glink_altmode_worker() currently gets scheduled on the system_wq which can be scheduled to run while devices are still suspended. This proves to be a problem when a Type-C retimer, switch or mux that is controlled over a bus like I2C, because the I2C controller is suspended.
This has been proven to be the case on the X Elite boards where such retimers (ParadeTech PS8830) are used in order to handle Type-C orientation and altmode configuration. The following warning is thrown:
[ 35.134876] i2c i2c-4: Transfer while suspended [ 35.143865] WARNING: CPU: 0 PID: 99 at drivers/i2c/i2c-core.h:56 __i2c_transfer+0xb4/0x57c [i2c_core] [ 35.352879] Workqueue: events pmic_glink_altmode_worker [pmic_glink_altmode] [ 35.360179] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 35.455242] Call trace: [ 35.457826] __i2c_transfer+0xb4/0x57c [i2c_core] (P) [ 35.463086] i2c_transfer+0x98/0xf0 [i2c_core] [ 35.467713] i2c_transfer_buffer_flags+0x54/0x88 [i2c_core] [ 35.473502] regmap_i2c_write+0x20/0x48 [regmap_i2c] [ 35.478659] _regmap_raw_write_impl+0x780/0x944 [ 35.483401] _regmap_bus_raw_write+0x60/0x7c [ 35.487848] _regmap_write+0x134/0x184 [ 35.491773] regmap_write+0x54/0x78 [ 35.495418] ps883x_set+0x58/0xec [ps883x] [ 35.499688] ps883x_sw_set+0x60/0x84 [ps883x] [ 35.504223] typec_switch_set+0x48/0x74 [typec] [ 35.508952] pmic_glink_altmode_worker+0x44/0x1fc [pmic_glink_altmode] [ 35.515712] process_scheduled_works+0x1a0/0x2d0 [ 35.520525] worker_thread+0x2a8/0x3c8 [ 35.524449] kthread+0xfc/0x184 [ 35.527749] ret_from_fork+0x10/0x20
The proper solution here should be to not deliver these kind of messages during system suspend at all, or at least make it configurable per glink client. But simply dropping the IRQF_NO_SUSPEND flag entirely will break other clients. The final shape of the rework of the pmic glink driver in order to fulfill both the filtering of the messages that need to be able to wake-up the system and the queueing of these messages until the system has properly resumed is still being discussed and it is planned as a future effort.
Meanwhile, the stop-gap fix here is to schedule the pmic glink altmode worker on the system_freezable_wq instead of the system_wq. This will result in the altmode worker not being scheduled to run until the devices are resumed first, which will give the controllers like I2C a chance to resume before the transfer is requested.
--- drivers/soc/qcom/pmic_glink_altmode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/qcom/pmic_glink_altmode.c +2 -2
@@ -303,7 +303,7 @@ static void pmic_glink_altmode_sc8180xp_notify(struct pmic_glink_altmode *altmod alt_port->mode = mode; alt_port->hpd_state = hpd_state; alt_port->hpd_irq = hpd_irq; -schedule_work (&alt_port->work); +queue_work (system_freezable_wq, &alt_port->work); }#define SC8280XP_DPAM_MASK 0x3f
@@ -346,7 +346,7 @@ static void pmic_glink_altmode_sc8280xp_notify(struct pmic_glink_altmode *altmod alt_port->mode = mode; alt_port->hpd_state = hpd_state; alt_port->hpd_irq = hpd_irq; -schedule_work (&alt_port->work); +queue_work (system_freezable_wq, &alt_port->work); }static void pmic_glink_altmode_callback (const void *data,size_t len,void *priv)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 488/686 PCI: endpoint: pci-epf-vntb: Manage virtual NTB and PCI bus lifetime
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 5cdbd6d3a3a147fa9975e35f2602cbec9a72a932 ]
The virtual PCI driver registers an ntb_dev but has no remove callback. Unbinding the endpoint function can therefore free BARs while the NTB device and its client still use them. It also leaves the virtual PCI devices and root bus allocated.
Allocate an ntb_dev for each virtual PCI probe and unregister it from the matching remove callback. Start command processing only after registration. Publish the device for doorbell IRQs at the same point. During remove, stop the command work and drain IRQ handlers before unregistering the device.
Retain the root bus returned by pci_scan_bus() so it can be removed on unbind. Unregister the virtual PCI driver before releasing endpoint resources. Stop and remove the root bus under the PCI rescan/remove lock, then release its host bridge.
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 69 +++++++++++++++---- 1 file changed, 55 insertions(+), 14 deletions(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +55 -14
@@ -118,7 +118,7 @@ struct epf_ntb_ctrl { } __packed;struct epf_ntb { -struct ntb_dev ntb; +struct ntb_dev *ntb;struct pci_epf *epf;struct config_group group;
@@ -144,10 +144,15 @@ struct epf_ntb {void __iomem *vpci_mw_addr[MAX_MW ];struct delayed_work cmd_handler; +struct pci_bus *vpci_bus; };#define to_epf_ntb (epf_group) container_of((epf_group), struct epf_ntb, group) -#define ntb_ndev (__ntb) container_of(__ntb, struct epf_ntb, ntb) + +static struct epf_ntb *ntb_ndev (struct ntb_dev *ntb) +{ +return ntb->pdev->sysdata; +}static struct pci_epf_header epf_ntb_header = { .vendorid =PCI_ANY_ID ,
@@ -173,7 +178,7 @@ static int epf_ntb_link_up(struct epf_ntb *ntb, bool link_up)else ntb->reg->link_status &= ~LINK_STATUS_UP ; -ntb_link_event (&ntb->ntb); +ntb_link_event (ntb->ntb);return 0 ; }
@@ -261,7 +266,7 @@ static void epf_ntb_cmd_handler(struct work_struct *work)for (i =1 ; i < ntb->db_count; i++) {if (ntb->epf_db[i]) { ntb->db |=1 << (i -1 ); -ntb_db_event (&ntb->ntb, i); +ntb_db_event (ntb->ntb, i); ntb->epf_db[i] =0 ; } }
@@ -796,7 +801,6 @@ static int epf_ntb_epc_init(struct epf_ntb *ntb) }INIT_DELAYED_WORK (&ntb->cmd_handler, epf_ntb_cmd_handler); -queue_work (kpcintb_workqueue, &ntb->cmd_handler.work);return 0 ;
@@ -1100,6 +1104,7 @@ static int vpci_scan_bus(void *sysdata)pr_err ("create pci bus failed\n" );return -EINVAL ; } + ndev->vpci_bus = vpci_bus;pci_bus_add_devices (vpci_bus);
@@ -1144,7 +1149,7 @@ static int vntb_epf_mw_set_trans(struct ntb_dev *ndev, int pidx, int idx,int ret;struct device *dev; - dev = &ntb->ntb.dev; + dev = &ndev->dev; barno = ntb->epf_ntb_bar[BAR_MW1 + idx]; epf_bar = &ntb->epf->bar[barno]; epf_bar->phys_addr = addr;
@@ -1244,7 +1249,7 @@ static int vntb_epf_peer_db_set(struct ntb_dev *ndev, u64 db_bits) ret =pci_epc_raise_irq (ntb->epf->epc, func_no, vfunc_no,PCI_IRQ_MSI , interrupt_num +1 );if (ret) -dev_err (&ntb->ntb.dev,"Failed to raise IRQ\n" ); +dev_err (&ntb->epf->dev,"Failed to raise IRQ\n" );return ret; }
@@ -1327,13 +1332,18 @@ static const struct ntb_dev_ops vntb_epf_ops = {static int pci_vntb_probe (struct pci_dev *pdev,const struct pci_device_id *id) { -int ret;struct epf_ntb *ndev = (struct epf_ntb *)pdev->sysdata;struct device *dev = &pdev->dev; +struct ntb_dev *ntb; +int ret; - ndev->ntb.pdev = pdev; - ndev->ntb.topo =NTB_TOPO_NONE ; - ndev->ntb.ops = &vntb_epf_ops; + ntb =devm_kzalloc (dev,sizeof (*ntb),GFP_KERNEL ); +if (!ntb) +return -ENOMEM ; + + ntb->pdev = pdev; + ntb->topo =NTB_TOPO_NONE ; + ntb->ops = &vntb_epf_ops; ret =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (32 ));if (ret) {
@@ -1341,16 +1351,33 @@ static int pci_vntb_probe(struct pci_dev *pdev, const struct pci_device_id *id)return ret; } - ret =ntb_register_device (&ndev->ntb); + ret =ntb_register_device (ntb);if (ret) {dev_err (dev,"Failed to register NTB device\n" );return ret; } +/* Publish after ntb_register_device() succeeds */ +smp_store_release (&ndev->ntb, ntb); +queue_delayed_work (kpcintb_workqueue, &ndev->cmd_handler,0 ); +dev_dbg (dev,"PCI Virtual NTB driver loaded\n" );return 0 ; } +static void pci_vntb_remove (struct pci_dev *pdev) +{ +struct epf_ntb *ndev = pdev->sysdata; +struct ntb_dev *ntb; + +/* Stop the work reader */ +cancel_delayed_work_sync (&ndev->cmd_handler); + + ntb =xchg (&ndev->ntb,NULL ); + +ntb_unregister_device (ntb); +} +static struct pci_device_id pci_vntb_table[] = { {PCI_DEVICE (0xffff ,0xffff ),
@@ -1362,6 +1389,7 @@ static struct pci_driver vntb_pci_driver = { .name = "pci-vntb", .id_table = pci_vntb_table, .probe = pci_vntb_probe, + .remove = pci_vntb_remove, };/* ============ PCIe EPF Driver Bind ====================*/
@@ -1442,12 +1470,25 @@ static int epf_ntb_bind(struct pci_epf *epf)*/ static void epf_ntb_unbind (struct pci_epf *epf) { +struct pci_host_bridge *bridge;struct epf_ntb *ntb =epf_get_drvdata (epf); +pci_unregister_driver (&vntb_pci_driver); + +if (ntb->vpci_bus) { + bridge =to_pci_host_bridge (ntb->vpci_bus->bridge); + +pci_lock_rescan_remove (); +pci_stop_root_bus (ntb->vpci_bus); +pci_remove_root_bus (ntb->vpci_bus); + ntb->vpci_bus =NULL ; +pci_unlock_rescan_remove (); + +pci_free_host_bridge (bridge); + } +epf_ntb_epc_cleanup (ntb);epf_ntb_config_spad_bar_free (ntb); - -pci_unregister_driver (&vntb_pci_driver); }// EPF driver probe
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 489/686 platform: int3472: discrete: Support multiple HIDs per GPIO map entry
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tarang Raval <[email protected]>
[ Upstream commit edd0dd59aca038b7f32cf893170928d4a3b2297e ]
Each int3472_gpio_map entry currently maps exactly one ACPI HID to a GPIO quirk. As more sensors needing the same quirk are identified, this means adding a full duplicate table entry per HID, differing only in the HID string, which does not scale.
Change int3472_gpio_map::hid to a NULL-terminated hids array so a single entry can match any number of ACPI HIDs, letting new HIDs be added to the relevant array instead of duplicating quirk entries.
Keep the consolidated vana mapping for SONY471A and TBE20A0, which were not previously listed, so the subsequent handshake-delay fix applies unchanged. Perform the HID scan in the existing GPIO mapping routine instead of introducing a separate matching helper.
Stable-dep-of: 844982d3b993 ("platform/x86: int3472: Increase handshake GPIO delay to 200 ms")
--- drivers/platform/x86/intel/int3472/discrete.c | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +39 -6
@@ -123,10 +123,31 @@ skl_int3472_gpiod_get_from_temp_lookup(struct int3472_discrete_device *int3472,return desc; } +/* +* Other vana-supply users (e.g. ST, Toshiba, Sony sensors) can be added to +* this array instead of adding new quirk table entries. +*/ +static const char *const power_enable_hids_vana[] = { +"SONY471A" ,/* imx471 on Lenovo X9-14 and X9-15 */ +"TBE20A0" ,/* imx471 on Lenovo X1 Carbon G14 */ +NULL +}; + +static const char *const power_enable_hids_vdd[] = { +"INT33F0" ,/* mt9m114 */ +NULL +}; + +static const char *const power_enable_hids_enable[] = { +"INT347E" ,/* ov7251 */ +NULL +}; +/** * struct int3472_gpio_map - Map GPIOs to whatever is expected by the * sensor driver (as in DT bindings) -* @hid: The ACPI HID of the device without the instance number e.g. INT347E +* @hids: NULL-terminated array of ACPI HIDs of the devices without the +* instance number e.g. INT347E * @type_from: The GPIO type from ACPI ?SDT * @type_to: The assigned GPIO type, typically same as @type_from * @enable_time_us: Enable time in usec for GPIOs mapped to regulators
@@ -135,7 +156,7 @@ skl_int3472_gpiod_get_from_temp_lookup(struct int3472_discrete_device *int3472,* GPIO_ACTIVE_HIGH otherwise */ struct int3472_gpio_map { -const char *hid; +const char *const *hids;u8 type_from;u8 type_to;bool polarity_low;
@@ -145,25 +166,32 @@ struct int3472_gpio_map {static const struct int3472_gpio_map int3472_gpio_map[] = { {/* mt9m114 designs declare a powerdown pin which controls the regulators */ - .hid ="INT33F0" , + .hids = power_enable_hids_vdd, .type_from =INT3472_GPIO_TYPE_POWERDOWN , .type_to =INT3472_GPIO_TYPE_POWER_ENABLE , .con_id ="vdd" , .enable_time_us =GPIO_REGULATOR_ENABLE_TIME , }, {/* ov7251 driver / DT-bindings expect "enable" as con_id for reset */ - .hid ="INT347E" , + .hids = power_enable_hids_enable, .type_from =INT3472_GPIO_TYPE_RESET , .type_to =INT3472_GPIO_TYPE_RESET , .con_id ="enable" , }, {/* ov08x40's handshake pin needs a 45 ms delay on some HP laptops */ - .hid ="OVTI08F4" , + .hids = (const char *const []) {"OVTI08F4" ,NULL }, .type_from =INT3472_GPIO_TYPE_HANDSHAKE , .type_to =INT3472_GPIO_TYPE_HANDSHAKE , .con_id ="dvdd" , .enable_time_us =45 *USEC_PER_MSEC , }, + {/* Sensors which expect "vana" as con_id for power enable */ + .hids = power_enable_hids_vana, + .type_from =INT3472_GPIO_TYPE_POWER_ENABLE , + .type_to =INT3472_GPIO_TYPE_POWER_ENABLE , + .con_id ="vana" , + .enable_time_us =GPIO_REGULATOR_ENABLE_TIME , + }, }; static void int3472_get_con_id_and_polarity(struct int3472_discrete_device *int3472, u8 *type,
@@ -171,6 +199,7 @@ static void int3472_get_con_id_and_polarity(struct int3472_discrete_device *int3 unsigned int *enable_time_us) {struct acpi_device *adev = int3472->sensor; +const char *const *hids;unsigned int i;for (i =0 ; i <ARRAY_SIZE (int3472_gpio_map); i++) {
@@ -182,7 +211,11 @@ static void int3472_get_con_id_and_polarity(struct int3472_discrete_device *int3if (*type != int3472_gpio_map[i].type_from)continue ; -if (!acpi_dev_hid_uid_match (adev, int3472_gpio_map[i].hid,NULL )) +for (hids = int3472_gpio_map[i].hids; *hids; hids++) { +if (acpi_dev_hid_uid_match (adev, *hids,NULL )) +break ; + } +if (!*hids)continue ; dev_dbg(int3472->dev, "mapping type 0x%02x pin to 0x%02x %s\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 490/686 platform/x86: int3472: Increase handshake GPIO delay to 200 ms
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
[ Upstream commit 844982d3b99340c21dd2125f44e1ad04ace6a38e ]
There have been several reports of the sensor not properly powering on, on laptops where an INT3472 handshake GPIO is used. Both with ov08x40 and hi556 sensors.
Testing has shown that a delay of 200 ms is necessary in some cases. The handshake GPIO is typically used to signal an extra bridge or other IC with that IC running the full sensor power sequence based on the handshake signal and also possible controlling I2C pass-through.
It seems that in some cases that extra IC takes up to 200 ms to before the sensor is fully powered up and ready for I2C communication.
With the default handshake signal delay increased to 200 ms the quirk to increase it to 45 ms for the ov08x40 is no longer necessary and is actually undesirable since some ov08x40 setups also need the longer delay, drop it.
--- drivers/platform/x86/intel/int3472/discrete.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +3 -9
@@ -15,6 +15,7 @@#include <linux/platform_data/x86/int3472.h> #include <linux/platform_device.h> #include <linux/string_choices.h> +#include <linux/time64.h> #include <linux/uuid.h> /*
@@ -178,13 +179,6 @@ static const struct int3472_gpio_map int3472_gpio_map[] = { .type_to = INT3472_GPIO_TYPE_RESET, .con_id = "enable", }, - {/* ov08x40's handshake pin needs a 45 ms delay on some HP laptops */ - .hids = (const char * const[]) { "OVTI08F4", NULL }, - .type_from = INT3472_GPIO_TYPE_HANDSHAKE, - .type_to = INT3472_GPIO_TYPE_HANDSHAKE, - .con_id = "dvdd", - .enable_time_us = 45 * USEC_PER_MSEC, - }, {/* Sensors which expect "vana" as con_id for power enable */ .hids = power_enable_hids_vana, .type_from = INT3472_GPIO_TYPE_POWER_ENABLE,
@@ -259,8 +253,8 @@ static void int3472_get_con_id_and_polarity(struct int3472_discrete_device *int3case INT3472_GPIO_TYPE_HANDSHAKE : *con_id ="dvdd" ; *gpio_flags =GPIO_ACTIVE_HIGH ; -/* Setups using a handshake pin need 25 ms enable delay */ - *enable_time_us =25 *USEC_PER_MSEC ; +/* Powering up the sensor through the handshake pin takes up to 200 ms */ + *enable_time_us =200 *USEC_PER_MSEC ;break ;default : *con_id ="unknown" ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 491/686 KVM: guest_memfd: Split bind() into prepare()+commit() phases
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 83411f32b8ad96c6b05b1511d1a588daab44bd25 ]
Split binding a memslot to a guest_memfd instance into prepare() and commit() phases so that KVM can separate preparing the memslot from binding the memslot to the gmem instance, i.e. from committing the memslot. This will allow waiting to commit the memslot+gmem binding until the memslot is fully prepared, which is necessary as the memslot becomes reachable when the binding is created.
As a bonus, drop the unwind-on-failure from the commit phase (other than nullifying the bindings), as the only reason bind() did the full unwind is because it technically didn't own the memslot, i.e. "needed" to leave memslot in the same state it started in.
No functional change intended (the unwinding down on bind() failure was effectively dead code since KVM simply deletes the memslot on failure, i.e. there was nothing that could actually observe the unwind).
--- virt/kvm/guest_memfd.c | 67 ++++++++++++++++++++++++------------------ virt/kvm/kvm_main.c | 18 +++++++++++- virt/kvm/kvm_mm.h | 18 ++++++++---- 3 files changed, 69 insertions(+), 34 deletions(-)
virt/kvm/guest_memfd.c +39 -28
@@ -563,15 +563,14 @@ int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args)return __kvm_gmem_create (kvm, size, flags); } -int kvm_gmem_bind (struct kvm *kvm,struct kvm_memory_slot *slot, -unsigned int fd,u64 offset) +int kvm_gmem_prepare_memory_region (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned int fd,u64 offset) {u64 size = slot->npages <<PAGE_SHIFT ; -unsigned long start, end;struct kvm_gmem *gmem;struct inode *inode;struct file *file; -int r = -EINVAL ; +BUILD_BUG_ON (sizeof (gpa_t) !=sizeof (offset));BUILD_BUG_ON (sizeof (gfn_t) !=sizeof (slot->gmem.pgoff));
@@ -595,43 +594,55 @@ int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot,if (!PAGE_ALIGNED (offset) || offset + size >i_size_read (inode)) goto err; -filemap_invalidate_lock (inode->i_mapping); - - start = offset >>PAGE_SHIFT ; - end = start + slot->npages; - -if (!xa_empty (&gmem->bindings) && -xa_find (&gmem->bindings, &start, end -1 ,XA_PRESENT )) { -filemap_invalidate_unlock (inode->i_mapping); - goto err; - } -/* * memslots of flag KVM_MEM_GUEST_MEMFD are immutable to change, so * kvm_gmem_bind() must occur on a new memslot. Because the memslot * is not visible yet, kvm_gmem_get_pfn() is guaranteed to see the file. */ WRITE_ONCE (slot->gmem.file, file); - slot->gmem.pgoff = start; + slot->gmem.pgoff = offset >>PAGE_SHIFT ;if (kvm_gmem_supports_mmap (inode)) slot->flags |=KVM_MEMSLOT_GMEM_ONLY ; - r =xa_err (xa_store_range (&gmem->bindings, start, end -1 , slot,GFP_KERNEL )); -if (r) { -xa_store_range (&gmem->bindings, start, end -1 ,NULL ,GFP_KERNEL ); - slot->gmem.file =NULL ; - slot->gmem.pgoff =0 ; - slot->flags &= ~KVM_MEMSLOT_GMEM_ONLY ; - } -filemap_invalidate_unlock (inode->i_mapping); -/* -* Drop the reference to the file, even on success. The file pins KVM, -* not the other way 'round. Active bindings are invalidated if the -* file is closed before memslots are destroyed. +* Gift the caller a reference to the file. The reference will be +* dropped after bindings are established, or if installing the new +* memslot ultimately fails. */ +return 0 ; + err:fput (file); +return -EINVAL ; +} + +int kvm_gmem_commit_memory_region (struct kvm *kvm,struct kvm_memory_slot *slot) +{ +struct kvm_gmem *gmem = slot->gmem.file->private_data; +struct inode *inode =file_inode (slot->gmem.file); +unsigned long start, end; +int r; + +if (WARN_ON_ONCE (slot->gmem.file->f_op != &kvm_gmem_fops)) +return -EIO ; + +filemap_invalidate_lock (inode->i_mapping); + + start = slot->gmem.pgoff; + end = start + slot->npages; + +if (!xa_empty (&gmem->bindings) && +xa_find (&gmem->bindings, &start, end -1 ,XA_PRESENT )) { +filemap_invalidate_unlock (inode->i_mapping); +return -EEXIST ; + } + + r =xa_err (xa_store_range (&gmem->bindings, start, end -1 , slot,GFP_KERNEL )); +if (r) +xa_store_range (&gmem->bindings, start, end -1 ,NULL ,GFP_KERNEL ); + +filemap_invalidate_unlock (inode->i_mapping); +return r; }
virt/kvm/kvm_main.c +17 -1
@@ -2128,7 +2128,23 @@ static int kvm_set_memory_region(struct kvm *kvm, new->flags = mem->flags; new->userspace_addr = mem->userspace_addr;if (change ==KVM_MR_CREATE && (mem->flags &KVM_MEM_GUEST_MEMFD )) { - r =kvm_gmem_bind (kvm, new, mem->guest_memfd, mem->guest_memfd_offset); + r =kvm_gmem_prepare_memory_region (kvm, new, mem->guest_memfd, + mem->guest_memfd_offset); +if (r) + goto out; + + r =kvm_gmem_commit_memory_region (kvm, new); + +/* +* Drop the reference to the file, even on success. The file +* pins KVM, not the other way 'round. Active bindings are +* invalidated if the file is closed before memslots are +* destroyed. +*/ +#ifdef CONFIG_KVM_GUEST_MEMFD +fput (new->gmem.file); +#endif +if (r) goto out; }
virt/kvm/kvm_mm.h +13 -5
@@ -73,8 +73,9 @@ static inline void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm,#ifdef CONFIG_KVM_GUEST_MEMFD void kvm_gmem_init (struct module *module);int kvm_gmem_create (struct kvm *kvm,struct kvm_create_guest_memfd *args); -int kvm_gmem_bind (struct kvm *kvm,struct kvm_memory_slot *slot, -unsigned int fd,u64 offset); +int kvm_gmem_prepare_memory_region (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned int fd,u64 offset); +int kvm_gmem_commit_memory_region (struct kvm *kvm,struct kvm_memory_slot *slot);void kvm_gmem_unbind (struct kvm_memory_slot *slot);#else static inline void kvm_gmem_init (struct module *module)
@@ -82,9 +83,16 @@ static inline void kvm_gmem_init(struct module *module) } -static inline int kvm_gmem_bind (struct kvm *kvm, -struct kvm_memory_slot *slot, -unsigned int fd,u64 offset) +static inline int kvm_gmem_prepare_memory_region (struct kvm *kvm, +struct kvm_memory_slot *slot, +unsigned int fd,u64 offset) +{ +WARN_ON_ONCE (1 ); +return -EIO ; +} + +static inline int kvm_gmem_commit_memory_region (struct kvm *kvm, +struct kvm_memory_slot *slot) {WARN_ON_ONCE (1 );return -EIO ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 492/686 iio: light: isl29028: remove isl29028_set_pm_runtime_busy() helper
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sang-Heon Jeon <[email protected]>
[ Upstream commit 7f61f41a3f5e8f9aa6c264833504995c89712cfc ]
isl29028_set_pm_runtime_busy() just calls pm_runtime_resume_and_get() or pm_runtime_put_autosuspend() depending on its bool argument. Call them directly and remove the helper.
No functional change.
Stable-dep-of: 0e30d15b1564 ("iio: light: isl29028: fix runtime PM reference leak on error paths")
--- drivers/iio/light/isl29028.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
drivers/iio/light/isl29028.c +5 -15
@@ -333,16 +333,6 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data)return isl29028_read_als_ir (chip, ir_data); } -static int isl29028_set_pm_runtime_busy (struct isl29028_chip *chip,bool on) -{ -struct device *dev =regmap_get_device (chip->regmap); - -if (on) -return pm_runtime_resume_and_get (dev); - -return pm_runtime_put_autosuspend (dev); -} -/* Channel IO */ static int isl29028_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
@@ -352,7 +342,7 @@ static int isl29028_write_raw(struct iio_dev *indio_dev,struct device *dev =regmap_get_device (chip->regmap);int ret; - ret =isl29028_set_pm_runtime_busy (chip, true); + ret =pm_runtime_resume_and_get (dev);if (ret <0 )return ret;
@@ -405,7 +395,7 @@ static int isl29028_write_raw(struct iio_dev *indio_dev,if (ret <0 )return ret; - ret =isl29028_set_pm_runtime_busy (chip, false); + ret =pm_runtime_put_autosuspend (dev);if (ret <0 )return ret;
@@ -420,7 +410,7 @@ static int isl29028_read_raw(struct iio_dev *indio_dev,struct device *dev =regmap_get_device (chip->regmap);int ret, pm_ret; - ret =isl29028_set_pm_runtime_busy (chip, true); + ret =pm_runtime_resume_and_get (dev);if (ret <0 )return ret;
@@ -476,10 +466,10 @@ static int isl29028_read_raw(struct iio_dev *indio_dev,/** * Preserve the ret variable if the call to -* isl29028_set_pm_runtime_busy() is successful so the reading +* pm_runtime_put_autosuspend() is successful so the reading * (if applicable) is returned to user space. */ - pm_ret =isl29028_set_pm_runtime_busy (chip, false); + pm_ret =pm_runtime_put_autosuspend (dev);if (pm_ret <0 )return pm_ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 493/686 iio: light: isl29028: fix runtime PM reference leak on error paths
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fabio Cesari <[email protected]>
[ Upstream commit 0e30d15b15647df786e60022650613e16dd70645 ]
isl29028_read_raw() and isl29028_write_raw() take a runtime PM reference with pm_runtime_resume_and_get() but return directly on their error paths without dropping it. The usage count never balances again and the device stops entering autosuspend for good. In isl29028_read_raw() this needs a regmap access to fail; in isl29028_write_raw() one rejected sysfs write is enough, for example
echo 200 > in_proximity_sampling_frequency
which is outside the [1:100] range and returns -EINVAL with the reference still held.
Take the reference with PM_RUNTIME_ACQUIRE_AUTOSUSPEND() instead, so it is released on every return path.
This also stops the return value of pm_runtime_put_autosuspend() from reaching userspace. That value only says whether the device could be suspended right away, so -EAGAIN or -EPERM turns a successful access into a failure, and with CONFIG_PM=n the stub returns -ENOSYS on every access.
--- drivers/iio/light/isl29028.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-)
drivers/iio/light/isl29028.c +8 -25
@@ -342,8 +342,9 @@ static int isl29028_write_raw(struct iio_dev *indio_dev,struct device *dev =regmap_get_device (chip->regmap);int ret; - ret =pm_runtime_resume_and_get (dev); -if (ret <0 ) +PM_RUNTIME_ACQUIRE_AUTOSUSPEND (dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm); +if (ret)return ret;mutex_lock (&chip->lock);
@@ -392,14 +393,7 @@ static int isl29028_write_raw(struct iio_dev *indio_dev,mutex_unlock (&chip->lock); -if (ret <0 ) -return ret; - - ret =pm_runtime_put_autosuspend (dev); -if (ret <0 ) -return ret; - -return 0 ; +return ret; } static int isl29028_read_raw(struct iio_dev *indio_dev,
@@ -408,10 +402,11 @@ static int isl29028_read_raw(struct iio_dev *indio_dev, {struct isl29028_chip *chip =iio_priv (indio_dev);struct device *dev =regmap_get_device (chip->regmap); -int ret, pm_ret; +int ret; - ret =pm_runtime_resume_and_get (dev); -if (ret <0 ) +PM_RUNTIME_ACQUIRE_AUTOSUSPEND (dev, pm); + ret =PM_RUNTIME_ACQUIRE_ERR (&pm); +if (ret)return ret;mutex_lock (&chip->lock);
@@ -461,18 +456,6 @@ static int isl29028_read_raw(struct iio_dev *indio_dev,mutex_unlock (&chip->lock); -if (ret <0 ) -return ret; - -/** -* Preserve the ret variable if the call to -* pm_runtime_put_autosuspend() is successful so the reading -* (if applicable) is returned to user space. -*/ - pm_ret =pm_runtime_put_autosuspend (dev); -if (pm_ret <0 ) -return pm_ret; -return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 494/686 KVM: arm64: Use kvm_s2_fault_vma_info in gmem_abort()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit 80b0b86dc5e4344e62a2fd3ee43d0ef816fe9122 ]
gmem_abort() maps at s2fd->fault_ipa, which HPFAR_EL2 holds at 4K granularity whatever the page size. The generic page-table code aligns it, but pkvm_pgtable_stage2_map() looks up existing mappings over [addr, addr + size), so on a pKVM host with pages larger than 4K a guest_memfd-backed guest that faults past the first 4K of a page can find its neighbour's mapping, get -EAGAIN and take the same fault forever.
The memory fault exit reports s2fd->fault_ipa too, which for a nested guest's fault is the nested IPA rather than the canonical one kvm_gmem_get_pfn() failed on.
Take the addresses from kvm_s2_fault_vma_info instead, as user_mem_abort() does, and report the canonical gfn in the memory fault exit. kvm_s2_fault_get_vma_info() itself isn't called: a guest_memfd memslot's userspace_addr doesn't need to be backed by a VMA.
--- arch/arm64/kvm/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/kvm/mmu.c +3 -1
@@ -1536,6 +1536,8 @@ static int gmem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (ret)return ret; + fault_ipa =ALIGN_DOWN (fault_ipa,PAGE_SIZE ); +if (nested) gfn =kvm_s2_trans_output (nested) >>PAGE_SHIFT ;else
@@ -1552,7 +1554,7 @@ static int gmem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, ret =kvm_gmem_get_pfn (kvm, memslot, gfn, &pfn, &page,NULL );if (ret) { -kvm_prepare_memory_fault_exit (vcpu, fault_ipa,PAGE_SIZE , +kvm_prepare_memory_fault_exit (vcpu,gfn_to_gpa (gfn),PAGE_SIZE , write_fault, exec_fault, false);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 495/686 KVM: arm64: ptdump: Check the page tables arent freed when accessing
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei-Lin Chang <[email protected]>
[ Upstream commit 7d7199bdf77a3a6ed74d0037133f435a7febe97c ]
An open debugfs file keeps the KVM structure alive, but does not prevent mmu notifier release from freeing the stage-2 page tables when the VMM’s address space is torn down. Therefore page tables belonging to the mmus could have been freed when a thread opens or reads the ptdump files. Take the mmu_lock and check mmu->pgt is still alive before accessing the page tables.
Also for the ipa_range file and stage2_levels file, switch from keeping the pointer to the page tables to keeping the pointer to the mmu.
--- arch/arm64/kvm/ptdump.c | 50 +++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 14 deletions(-)
arch/arm64/kvm/ptdump.c +36 -14
@@ -97,22 +97,35 @@ static struct kvm_ptdump_guest_state *kvm_ptdump_parser_create(struct kvm *kvm) {struct kvm_ptdump_guest_state *st;struct kvm_s2_mmu *mmu = &kvm->arch.mmu; -struct kvm_pgtable *pgtable = mmu->pgt; +s8 start_level; +u32 ia_bits;int ret; +/* +* We only need the pgt start level and IPA size to initialize the ptdump, +* get them while holding the mmu_lock. It's fine if the pgt gets freed +* afterwards, we'll check again when doing the actual dump. +*/ + scoped_guard(read_lock, &kvm->mmu_lock) { +if (!mmu->pgt) +return ERR_PTR (-ENOENT ); + start_level = mmu->pgt->start_level; + ia_bits = mmu->pgt->ia_bits; + } + st =kzalloc (sizeof (struct kvm_ptdump_guest_state ),GFP_KERNEL_ACCOUNT );if (!st)return ERR_PTR (-ENOMEM ); - ret =kvm_ptdump_build_levels (&st->level[0 ], pgtable->start_level); + ret =kvm_ptdump_build_levels (&st->level[0 ], start_level);if (ret) {kfree (st);return ERR_PTR (ret); } st->ipa_marker[0 ].name ="Guest IPA" ; - st->ipa_marker[1 ].start_address =BIT (pgtable->ia_bits); - st->range[0 ].end =BIT (pgtable->ia_bits); + st->ipa_marker[1 ].start_address =BIT (ia_bits); + st->range[0 ].end =BIT (ia_bits); st->kvm = kvm; st->parser_state = (struct ptdump_pg_state ) {
@@ -141,9 +154,11 @@ static int kvm_ptdump_guest_show(struct seq_file *m, void *unused) parser_state->seq = m; -write_lock (&kvm->mmu_lock); +guard (write_lock)(&kvm->mmu_lock); +if (!mmu->pgt) +return 0 ; + ret =kvm_pgtable_walk (mmu->pgt,0 ,BIT (mmu->pgt->ia_bits), &walker); -write_unlock (&kvm->mmu_lock);return ret; }
@@ -193,17 +208,27 @@ static const struct file_operations kvm_ptdump_guest_fops = {static int kvm_pgtable_range_show (struct seq_file *m,void *unused) { -struct kvm_pgtable *pgtable = m->private; +struct kvm_s2_mmu *mmu = m->private; +struct kvm *kvm =kvm_s2_mmu_to_kvm (mmu); + +guard (read_lock)(&kvm->mmu_lock); + +if (mmu->pgt) +seq_printf (m,"%2u\n" , mmu->pgt->ia_bits); -seq_printf (m,"%2u\n" , pgtable->ia_bits);return 0 ; }static int kvm_pgtable_levels_show (struct seq_file *m,void *unused) { -struct kvm_pgtable *pgtable = m->private; +struct kvm_s2_mmu *mmu = m->private; +struct kvm *kvm =kvm_s2_mmu_to_kvm (mmu); + +guard (read_lock)(&kvm->mmu_lock); + +if (mmu->pgt) +seq_printf (m,"%1d\n" ,KVM_PGTABLE_MAX_LEVELS - mmu->pgt->start_level); -seq_printf (m,"%1d\n" ,KVM_PGTABLE_MAX_LEVELS - pgtable->start_level);return 0 ; }
@@ -211,15 +236,12 @@ static int kvm_pgtable_debugfs_open(struct inode *m, struct file *file, int (*show)(struct seq_file *, void *)) {struct kvm *kvm = m->i_private; -struct kvm_pgtable *pgtable;int ret;if (!kvm_get_kvm_safe (kvm))return -ENOENT ; - pgtable = kvm->arch.mmu.pgt; - - ret =single_open (file, show, pgtable); + ret =single_open (file, show, &kvm->arch.mmu);if (ret <0 )kvm_put_kvm (kvm);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 496/686 media: microchip-isc: store the unshifted PFE_CFG0 BPS value
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 14cbe597504a04c5c49342d0566438e2b438a948 ]
pfe_cfg0_bps held a pre-shifted BPS value (ISC_PFE_CFG0_BPS_EIGHT was 0x4 << 28) ORed straight into the register. The other format selectors like cfa_baycfg store the bare field value and position it at the write, so this one was inconsistent.
Store the bare BPS value and apply it with FIELD_PREP() at the PFE_CFG0 write, and fix the pfe_cfg0_bps comment to match. No functional change.
Stable-dep-of: bb96c78c5f87 ("media: microchip-isc: fix SBGGR10 Bayer pattern")
--- drivers/media/platform/microchip/microchip-isc-base.c | 4 +++- drivers/media/platform/microchip/microchip-isc-regs.h | 10 +++++----- drivers/media/platform/microchip/microchip-isc.h | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-)
drivers/media/platform/microchip/microchip-isc-base.c +3 -1
@@ -8,6 +8,7 @@* Author: Eugen Hristev <[email protected]> * */ +#include <linux/bitfield.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/math64.h>
@@ -291,7 +292,8 @@ static int isc_configure(struct isc_device *isc)struct isc_subdev_entity *subdev = isc->current_subdev;int ret; - pfe_cfg0 = isc->config.sd_format->pfe_cfg0_bps; + pfe_cfg0 =FIELD_PREP (ISC_PFE_CFG0_BPS_MASK , + isc->config.sd_format->pfe_cfg0_bps); pipeline = isc->config.bits_pipeline; dcfg = isc->config.dcfg_imode | isc->dcfg;
drivers/media/platform/microchip/microchip-isc-regs.h +5 -5
@@ -31,11 +31,11 @@#define ISC_PFE_CFG0_MODE_PROGRESSIVE (0x0 << 4)#define ISC_PFE_CFG0_MODE_MASK GENMASK(6, 4) -#define ISC_PFE_CFG0_BPS_EIGHT (0x4 << 28) -#define ISC_PFG_CFG0_BPS_NINE (0x3 << 28) -#define ISC_PFG_CFG0_BPS_TEN (0x2 << 28) -#define ISC_PFG_CFG0_BPS_ELEVEN (0x1 << 28) -#define ISC_PFG_CFG0_BPS_TWELVE (0x0 << 28) +#define ISC_PFE_CFG0_BPS_EIGHT 0x4 +#define ISC_PFG_CFG0_BPS_NINE 0x3 +#define ISC_PFG_CFG0_BPS_TEN 0x2 +#define ISC_PFG_CFG0_BPS_ELEVEN 0x1 +#define ISC_PFG_CFG0_BPS_TWELVE 0x0#define ISC_PFE_CFG0_BPS_MASK GENMASK(30, 28)#define ISC_PFE_CFG0_COLEN BIT(12)
drivers/media/platform/microchip/microchip-isc.h +3 -1
@@ -62,7 +62,9 @@ struct isc_subdev_entity {* @mbus_code: V4L2 media bus format code. * @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer. this is either BGBG, RGRG, etc. -* @pfe_cfg0_bps: Number of hardware data lines connected to the ISC +* @pfe_cfg0_bps: ISC_PFE_CFG0 BPS field value (e.g. ISC_PFE_CFG0_BPS_EIGHT), +written into PFE_CFG0 with FIELD_PREP(ISC_PFE_CFG0_BPS_MASK) +at configure time. * @raw: If the format is raw bayer. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 497/686 media: microchip-isc: fix ISC_PFG_CFG0_BPS macro name typo
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit 96defd0723fc893db6ccf5f4968323db4af0b0aa ]
The BPS field macros for ISC_PFE_CFG0 were spelled ISC_PFG_CFG0_BPS_* (NINE, TEN, ELEVEN, TWELVE). The register is PFE, not PFG. Rename them to ISC_PFE_CFG0_BPS_* to match the register and the EIGHT and MASK macros. No functional change.
Stable-dep-of: bb96c78c5f87 ("media: microchip-isc: fix SBGGR10 Bayer pattern")
--- .../platform/microchip/microchip-isc-regs.h | 8 ++++---- .../platform/microchip/microchip-sama5d2-isc.c | 18 +++++++++--------- .../platform/microchip/microchip-sama7g5-isc.c | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-)
drivers/media/platform/microchip/microchip-isc-regs.h +4 -4
@@ -32,10 +32,10 @@#define ISC_PFE_CFG0_MODE_MASK GENMASK(6, 4)#define ISC_PFE_CFG0_BPS_EIGHT 0x4 -#define ISC_PFG_CFG0_BPS_NINE 0x3 -#define ISC_PFG_CFG0_BPS_TEN 0x2 -#define ISC_PFG_CFG0_BPS_ELEVEN 0x1 -#define ISC_PFG_CFG0_BPS_TWELVE 0x0 +#define ISC_PFE_CFG0_BPS_NINE 0x3 +#define ISC_PFE_CFG0_BPS_TEN 0x2 +#define ISC_PFE_CFG0_BPS_ELEVEN 0x1 +#define ISC_PFE_CFG0_BPS_TWELVE 0x0#define ISC_PFE_CFG0_BPS_MASK GENMASK(30, 28)#define ISC_PFE_CFG0_COLEN BIT(12)
drivers/media/platform/microchip/microchip-sama5d2-isc.c +9 -9
@@ -147,49 +147,49 @@ static struct isc_format sama5d2_formats_list[] = { { .fourcc = V4L2_PIX_FMT_SBGGR10, .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, .mbus_code = MEDIA_BUS_FMT_SGBRG10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_GBGB, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, .mbus_code = MEDIA_BUS_FMT_SGRBG10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_GRGR, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, .mbus_code = MEDIA_BUS_FMT_SRGGB10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, { .fourcc = V4L2_PIX_FMT_SBGGR12, .mbus_code = MEDIA_BUS_FMT_SBGGR12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_BGBG, }, { .fourcc = V4L2_PIX_FMT_SGBRG12, .mbus_code = MEDIA_BUS_FMT_SGBRG12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_GBGB, }, { .fourcc = V4L2_PIX_FMT_SGRBG12, .mbus_code = MEDIA_BUS_FMT_SGRBG12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_GRGR, }, { .fourcc = V4L2_PIX_FMT_SRGGB12, .mbus_code = MEDIA_BUS_FMT_SRGGB12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, {
@@ -210,7 +210,7 @@ static struct isc_format sama5d2_formats_list[] = { { .fourcc = V4L2_PIX_FMT_Y10, .mbus_code = MEDIA_BUS_FMT_Y10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, }, };
drivers/media/platform/microchip/microchip-sama7g5-isc.c +9 -9
@@ -156,49 +156,49 @@ static struct isc_format sama7g5_formats_list[] = { { .fourcc = V4L2_PIX_FMT_SBGGR10, .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, { .fourcc = V4L2_PIX_FMT_SGBRG10, .mbus_code = MEDIA_BUS_FMT_SGBRG10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_GBGB, }, { .fourcc = V4L2_PIX_FMT_SGRBG10, .mbus_code = MEDIA_BUS_FMT_SGRBG10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_GRGR, }, { .fourcc = V4L2_PIX_FMT_SRGGB10, .mbus_code = MEDIA_BUS_FMT_SRGGB10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, { .fourcc = V4L2_PIX_FMT_SBGGR12, .mbus_code = MEDIA_BUS_FMT_SBGGR12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_BGBG, }, { .fourcc = V4L2_PIX_FMT_SGBRG12, .mbus_code = MEDIA_BUS_FMT_SGBRG12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_GBGB, }, { .fourcc = V4L2_PIX_FMT_SGRBG12, .mbus_code = MEDIA_BUS_FMT_SGRBG12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_GRGR, }, { .fourcc = V4L2_PIX_FMT_SRGGB12, .mbus_code = MEDIA_BUS_FMT_SRGGB12_1X12, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TWELVE, .cfa_baycfg = ISC_BAY_CFG_RGRG, }, {
@@ -224,7 +224,7 @@ static struct isc_format sama7g5_formats_list[] = { { .fourcc = V4L2_PIX_FMT_Y10, .mbus_code = MEDIA_BUS_FMT_Y10_1X10, - .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN, + .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, }, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 498/686 media: microchip-isc: fix SBGGR10 Bayer pattern
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Balakrishnan Sambath <[email protected]>
[ Upstream commit bb96c78c5f87072913f8825faebe64bf711a503c ]
SBGGR10 was mapped to ISC_BAY_CFG_RGRG instead of ISC_BAY_CFG_BGBG, causing red/blue channel swap.
--- drivers/media/platform/microchip/microchip-sama5d2-isc.c | 2 +- drivers/media/platform/microchip/microchip-sama7g5-isc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/microchip/microchip-sama5d2-isc.c +1 -1
@@ -148,7 +148,7 @@ static struct isc_format sama5d2_formats_list[] = { .fourcc = V4L2_PIX_FMT_SBGGR10, .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, - .cfa_baycfg = ISC_BAY_CFG_RGRG, + .cfa_baycfg = ISC_BAY_CFG_BGBG, }, { .fourcc = V4L2_PIX_FMT_SGBRG10,
drivers/media/platform/microchip/microchip-sama7g5-isc.c +1 -1
@@ -157,7 +157,7 @@ static struct isc_format sama7g5_formats_list[] = { .fourcc = V4L2_PIX_FMT_SBGGR10, .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_TEN, - .cfa_baycfg = ISC_BAY_CFG_RGRG, + .cfa_baycfg = ISC_BAY_CFG_BGBG, }, { .fourcc = V4L2_PIX_FMT_SGBRG10,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 499/686 media: i2c: imx219: Replace exposure magic value with named constant
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tarang Raval <[email protected]>
[ Upstream commit 9a9ba098e7ba6b89efaddeabf0716a84a0f54c99 ]
Introduce IMX219_EXPOSURE_OFFSET (4) and use it instead of the literal '4' when computing the maximum coarse exposure. The IMX219 datasheet specifies the maximum storage time as frame_length_lines - 4. (Ref: Datasheet section 5-7-1)
Also fix one indentation issue for consistency.
Stable-dep-of: 57043aef0a04 ("media: imx219: Account for rate_factor in control steps")
--- drivers/media/i2c/imx219.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/media/i2c/imx219.c +7 -6
@@ -68,6 +68,7 @@#define IMX219_EXPOSURE_STEP 1#define IMX219_EXPOSURE_DEFAULT 0x640#define IMX219_EXPOSURE_MAX 65535 +#define IMX219_EXPOSURE_OFFSET 4/* V_TIMING internal */ #define IMX219_REG_FRM_LENGTH_A CCI_REG16(0x0160)
@@ -461,9 +462,9 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)int exposure_max, exposure_def;/* Update max exposure while meeting expected vblanking */ - exposure_max = format->height + ctrl->val -4 ; + exposure_max = format->height + ctrl->val -IMX219_EXPOSURE_OFFSET ; exposure_def = (exposure_max <IMX219_EXPOSURE_DEFAULT ) ? - exposure_max :IMX219_EXPOSURE_DEFAULT ; + exposure_max :IMX219_EXPOSURE_DEFAULT ; ret = __v4l2_ctrl_modify_range(imx219->exposure, imx219->exposure->minimum, exposure_max,
@@ -591,9 +592,9 @@ static int imx219_init_controls(struct imx219 *imx219)IMX219_LLP_MAX - mode->width,IMX219_LLP_STEP , IMX219_LLP_MIN - mode->width); - exposure_max = mode->fll_def -4 ; + exposure_max = mode->fll_def -IMX219_EXPOSURE_OFFSET ; exposure_def = (exposure_max <IMX219_EXPOSURE_DEFAULT ) ? - exposure_max :IMX219_EXPOSURE_DEFAULT ; + exposure_max :IMX219_EXPOSURE_DEFAULT ; imx219->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, V4L2_CID_EXPOSURE, IMX219_EXPOSURE_MIN, exposure_max,
@@ -912,9 +913,9 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,return ret;/* Update max exposure while meeting expected vblanking */ - exposure_max = mode->fll_def -4 ; + exposure_max = mode->fll_def -IMX219_EXPOSURE_OFFSET ; exposure_def = (exposure_max <IMX219_EXPOSURE_DEFAULT ) ? - exposure_max :IMX219_EXPOSURE_DEFAULT ; + exposure_max :IMX219_EXPOSURE_DEFAULT ; ret = __v4l2_ctrl_modify_range(imx219->exposure, imx219->exposure->minimum, exposure_max,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 500/686 media: imx219: Account rate_factor in setting upper exposure limit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sakari Ailus <[email protected]>
[ Upstream commit db111b66f2db7f3f79d9359f4a9762e832d6fde9 ]
The rate_factor multiplier is used to multiply a few values in the sensor's timing configuration and the exposure time is one of them. This also needs to be taken into account in exposure time margin: multiply it by rate_factor so that sensor's exposure time margin is respected.
Stable-dep-of: 57043aef0a04 ("media: imx219: Account for rate_factor in control steps")
--- drivers/media/i2c/imx219.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/media/i2c/imx219.c +5 -2
@@ -462,7 +462,8 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)int exposure_max, exposure_def;/* Update max exposure while meeting expected vblanking */ - exposure_max = format->height + ctrl->val -IMX219_EXPOSURE_OFFSET ; + exposure_max = format->height + ctrl->val - +IMX219_EXPOSURE_OFFSET * rate_factor; exposure_def = (exposure_max <IMX219_EXPOSURE_DEFAULT ) ? exposure_max :IMX219_EXPOSURE_DEFAULT ; ret = __v4l2_ctrl_modify_range(imx219->exposure,
@@ -895,6 +896,7 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd, crop->top = (IMX219_NATIVE_HEIGHT - crop->height) /2 ;if (fmt->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { +int rate_factor =imx219_get_rate_factor (state);int exposure_max;int exposure_def;int hblank, llp_min;
@@ -913,7 +915,8 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,return ret;/* Update max exposure while meeting expected vblanking */ - exposure_max = mode->fll_def -IMX219_EXPOSURE_OFFSET ; + exposure_max = mode->fll_def - +IMX219_EXPOSURE_OFFSET * rate_factor; exposure_def = (exposure_max <IMX219_EXPOSURE_DEFAULT ) ? exposure_max :IMX219_EXPOSURE_DEFAULT ; ret = __v4l2_ctrl_modify_range(imx219->exposure,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 501/686 media: imx219: Account for rate_factor in control steps
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sakari Ailus <[email protected]>
[ Upstream commit 57043aef0a04bd96d97881422590e71c1e4c45b1 ]
The controls that are divided by the rate_factor before writing them to the registers have the step of the value of the rate_factor. Take this into account when the control's range is modified. The controls are created in a configuration where rate_factor is always 1, hence there's no need to change the code adding new controls.
--- drivers/media/i2c/imx219.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/media/i2c/imx219.c +7 -9
@@ -326,13 +326,13 @@ static const struct imx219_mode supported_modes[] = {/* 2x2 binned 60fps mode */ .width = 1640, .height = 1232, - .fll_def = 1707, + .fll_def = 1706, }, {/* 640x480 60fps mode */ .width = 640, .height = 480, - .fll_def = 1707, + .fll_def = 1706, }, };
@@ -469,8 +469,7 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) ret =__v4l2_ctrl_modify_range (imx219->exposure, imx219->exposure->minimum, exposure_max, - imx219->exposure->step, - exposure_def); + rate_factor, exposure_def);if (ret)return ret;
@@ -904,7 +903,8 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,/* Update limits and set FPS to default */ ret =__v4l2_ctrl_modify_range (imx219->vblank,IMX219_VBLANK_MIN , -IMX219_FLL_MAX - mode->height,1 , +IMX219_FLL_MAX - mode->height, + rate_factor, mode->fll_def - mode->height);if (ret)return ret;
@@ -922,8 +922,7 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd, ret =__v4l2_ctrl_modify_range (imx219->exposure, imx219->exposure->minimum, exposure_max, - imx219->exposure->step, - exposure_def); + rate_factor, exposure_def);if (ret)return ret;
@@ -956,8 +955,7 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,return ret;/* Scale the pixel rate based on the mode specific factor */ - pixel_rate =imx219_get_pixel_rate (imx219) * -imx219_get_rate_factor (state); + pixel_rate =imx219_get_pixel_rate (imx219) * rate_factor; ret =__v4l2_ctrl_modify_range (imx219->pixel_rate, pixel_rate, pixel_rate,1 , pixel_rate);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 502/686 media: iris: Fix iova allocation from restrict region
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vishnu Reddy <[email protected]>
[ Upstream commit 200473c198b201c308dfb916fb3233074d9407fa ]
The VPU issues DMA through several SMMU streams, and the hardware does not give every stream the same addressable range. The non-pixel stream cannot address the low 600MB of IOVA space, while the pixel stream can address the full range:
+-----------------------------------------------------------+
| non-pixel stream addressable range (600 MB - 3.5 GB) |
| 0x25800000 - 0xe0000000 |
+-----------------------------------------------------------+
| pixel stream addressable range (0 - 3.5 GB) |
| 0x00000000 - 0xe0000000 |
+-----------------------------------------------------------+A single "iommus" property on the video-codec node puts every stream in one IOMMU domain sharing one IOVA space, so nothing stops a non-pixel buffer from landing below 600MB. Once an allocation lands below that boundary the hardware faults, which shows up as unhandled SMMU page faults and spontaneous reboots.
https://gitlab.freedesktop.org/drm/msm/-/work_items/100
Fix this by reserving the 0-600MB range, below the boundary the non-pixel stream cannot address, using dma_iova_try_alloc() so the IOMMU-DMA core never hands that range out to a real DMA mapping. This reserves only IOVA space, it does not allocate any physical memory.
Since sub-nodes for non-pixel, pixel, and secure streams do not exist yet and only a single device is available, the restriction is applied to both non-pixel and pixel stream IDs.
--- drivers/media/platform/qcom/iris/iris_core.h | 6 ++ drivers/media/platform/qcom/iris/iris_probe.c | 62 ++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/iris/iris_core.h +6 -0
@@ -7,6 +7,7 @@#define __IRIS_CORE_H__#include <linux/types.h> +#include <linux/dma-mapping.h> #include <linux/pm_domain.h> #include <media/v4l2-device.h>
@@ -25,6 +26,9 @@ struct icc_info {#define IRIS_FW_VERSION_LENGTH 128#define IFACEQ_CORE_PKT_SIZE (1024 * 4) +#define IRIS_NP_RESERVE_IOVA_START 0x0 +#define IRIS_NP_RESERVE_IOVA_SIZE 0x25800000 +enum domain_type {ENCODER =BIT (0 ),DECODER =BIT (1 ),
@@ -73,6 +77,7 @@ enum domain_type {* @instances: a list_head of all instances * @inst_fw_caps_dec: an array of supported instance capabilities by decoder * @inst_fw_caps_enc: an array of supported instance capabilities by encoder +* @iova_state: a pointer to an array of dma_iova_state entries reserved for restricted IOVA region */ struct iris_core {
@@ -117,6 +122,7 @@ struct iris_core {/* encoder and decoder have overlapping caps, so two different arrays are required */ struct platform_inst_fw_cap inst_fw_caps_dec[INST_FW_CAP_MAX ];struct platform_inst_fw_cap inst_fw_caps_enc[INST_FW_CAP_MAX ]; +struct dma_iova_state *iova_state; };int iris_core_init (struct iris_core *core);
drivers/media/platform/qcom/iris/iris_probe.c +61 -1
89 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 503/686 iio: adc: ad7192: Revert "properly check spi_get_device_match_data()"
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 0309e66abea141f3ec339b064b8f8b8003d2a634 ]
This reverts commit b7f99fa1b64af2f696b13cec581cb4cd7d3982b8.
The added code is currently a dead code. Moreover, the driver is not designed to have any defaults effectively making driver data a mandatory information to work with. Taking all together, revert unneeded change.
Discussion at #1 concluded in agreeing a new policy on this for IIO.
Stable-dep-of: 7f7a119a370e ("iio: adc: ad7192: reject devices without match data")
--- drivers/iio/adc/ad7192.c | 3 --- 1 file changed, 3 deletions(-)
drivers/iio/adc/ad7192.c +0 -3
@@ -1402,9 +1402,6 @@ static int ad7192_probe(struct spi_device *spi) st->int_vref_mv = ret == -ENODEV ? avdd_mv : ret /MILLI ; st->chip_info =spi_get_device_match_data (spi); -if (!st->chip_info) -return -ENODEV ; - indio_dev->name = st->chip_info->name; indio_dev->modes =INDIO_DIRECT_MODE ; indio_dev->info = st->chip_info->info;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 504/686 iio: adc: ad7192: reject devices without match data
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 7f7a119a370ecf6c8d4ab9e9ee0a8cdd77afedd3 ]
SPI driver_override allows a device to bind to this driver without matching either the OF or SPI device ID table. In that case, spi_get_device_match_data() returns NULL.
ad7192_probe() immediately dereferences the returned chip information to initialize the IIO device, causing a NULL pointer dereference.
Commit 572a00852635 ("iio: dac: ad5686: missing NULL check on match data") fixed the same driver_override issue in another SPI driver. Reject devices without match data before using the chip information.
--- drivers/iio/adc/ad7192.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iio/adc/ad7192.c +3 -0
@@ -1402,6 +1402,9 @@ static int ad7192_probe(struct spi_device *spi) st->int_vref_mv = ret == -ENODEV ? avdd_mv : ret /MILLI ; st->chip_info =spi_get_device_match_data (spi); +if (!st->chip_info) +return -ENODATA ; + indio_dev->name = st->chip_info->name; indio_dev->modes =INDIO_DIRECT_MODE ; indio_dev->info = st->chip_info->info;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 505/686 ALSA: core: Clean up file_operations definitions
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 307835a6eb50e548e58ee604bf91909d4faa4203 ]
Align file_operations initializers with tabs to match the standard kernel coding style and improve readability.
Stable-dep-of: 1bbc033983b7 ("ALSA: timer: Handle userspace-driven timer ioctls from 32-bit tasks")
--- sound/core/compress_offload.c | 18 +++++++------- sound/core/control.c | 19 +++++++-------- sound/core/hwdep.c | 23 +++++++++--------- sound/core/init.c | 23 +++++++++--------- sound/core/jack.c | 38 ++++++++++++++--------------- sound/core/oss/mixer_oss.c | 13 +++++----- sound/core/oss/pcm_oss.c | 21 ++++++++-------- sound/core/pcm_native.c | 44 +++++++++++++++++----------------- sound/core/rawmidi.c | 16 ++++++------- sound/core/seq/oss/seq_oss.c | 21 ++++++++-------- sound/core/seq/seq_clientmgr.c | 19 +++++++-------- sound/core/sound.c | 9 ++++--- sound/core/timer.c | 25 ++++++++++--------- 13 files changed, 140 insertions(+), 149 deletions(-)
sound/core/compress_offload.c +9 -9
@@ -1399,17 +1399,17 @@ static long snd_compr_ioctl_compat(struct file *file, unsigned int cmd,#endif static const struct file_operations snd_compr_file_ops = { - .owner =THIS_MODULE , - .open = snd_compr_open, - .release = snd_compr_free, - .write = snd_compr_write, - .read = snd_compr_read, - .unlocked_ioctl = snd_compr_ioctl, + .owner =THIS_MODULE , + .open = snd_compr_open, + .release = snd_compr_free, + .write = snd_compr_write, + .read = snd_compr_read, + .unlocked_ioctl = snd_compr_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = snd_compr_ioctl_compat, + .compat_ioctl = snd_compr_ioctl_compat, #endif - .mmap = snd_compr_mmap, - .poll = snd_compr_poll, + .mmap = snd_compr_mmap, + .poll = snd_compr_poll, };static int snd_compress_dev_register (struct snd_device *device)
sound/core/control.c +9 -10
@@ -2269,16 +2269,15 @@ EXPORT_SYMBOL_GPL(snd_ctl_disconnect_layer);* INIT PART */ -static const struct file_operations snd_ctl_f_ops = -{ - .owner =THIS_MODULE , - .read = snd_ctl_read, - .open = snd_ctl_open, - .release = snd_ctl_release, - .poll = snd_ctl_poll, - .unlocked_ioctl = snd_ctl_ioctl, - .compat_ioctl = snd_ctl_ioctl_compat, - .fasync = snd_ctl_fasync, +static const struct file_operations snd_ctl_f_ops = { + .owner =THIS_MODULE , + .read = snd_ctl_read, + .open = snd_ctl_open, + .release = snd_ctl_release, + .poll = snd_ctl_poll, + .unlocked_ioctl = snd_ctl_ioctl, + .compat_ioctl = snd_ctl_ioctl_compat, + .fasync = snd_ctl_fasync, };/* call lops under rwsems; called from snd_ctl_dev_*() below() */
sound/core/hwdep.c +11 -12
@@ -324,18 +324,17 @@ static int snd_hwdep_control_ioctl(struct snd_card *card,*/ -static const struct file_operations snd_hwdep_f_ops = -{ - .owner =THIS_MODULE , - .llseek = snd_hwdep_llseek, - .read = snd_hwdep_read, - .write = snd_hwdep_write, - .open = snd_hwdep_open, - .release = snd_hwdep_release, - .poll = snd_hwdep_poll, - .unlocked_ioctl = snd_hwdep_ioctl, - .compat_ioctl = snd_hwdep_ioctl_compat, - .mmap = snd_hwdep_mmap, +static const struct file_operations snd_hwdep_f_ops = { + .owner =THIS_MODULE , + .llseek = snd_hwdep_llseek, + .read = snd_hwdep_read, + .write = snd_hwdep_write, + .open = snd_hwdep_open, + .release = snd_hwdep_release, + .poll = snd_hwdep_poll, + .unlocked_ioctl = snd_hwdep_ioctl, + .compat_ioctl = snd_hwdep_ioctl_compat, + .mmap = snd_hwdep_mmap, };static void snd_hwdep_free (struct snd_hwdep *hwdep)
sound/core/init.c +11 -12
@@ -461,20 +461,19 @@ static int snd_disconnect_fasync(int fd, struct file *file, int on)return -ENODEV ; } -static const struct file_operations snd_shutdown_f_ops = -{ - .owner =THIS_MODULE , - .llseek = snd_disconnect_llseek, - .read = snd_disconnect_read, - .write = snd_disconnect_write, - .release = snd_disconnect_release, - .poll = snd_disconnect_poll, - .unlocked_ioctl = snd_disconnect_ioctl, +static const struct file_operations snd_shutdown_f_ops = { + .owner =THIS_MODULE , + .llseek = snd_disconnect_llseek, + .read = snd_disconnect_read, + .write = snd_disconnect_write, + .release = snd_disconnect_release, + .poll = snd_disconnect_poll, + .unlocked_ioctl = snd_disconnect_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = snd_disconnect_ioctl, + .compat_ioctl = snd_disconnect_ioctl, #endif - .mmap = snd_disconnect_mmap, - .fasync = snd_disconnect_fasync + .mmap = snd_disconnect_mmap, + .fasync = snd_disconnect_fasync };/**
sound/core/jack.c +19 -19
@@ -306,41 +306,41 @@ static ssize_t jack_type_read(struct file *file, }static const struct file_operations jack_type_fops = { - .open = simple_open, - .read = jack_type_read, - .llseek = default_llseek, + .open = simple_open, + .read = jack_type_read, + .llseek = default_llseek, };#endif static const struct file_operations sw_inject_enable_fops = { - .open = simple_open, - .read = sw_inject_enable_read, - .write = sw_inject_enable_write, - .llseek = default_llseek, + .open = simple_open, + .read = sw_inject_enable_read, + .write = sw_inject_enable_write, + .llseek = default_llseek, };static const struct file_operations jackin_inject_fops = { - .open = simple_open, - .write = jackin_inject_write, - .llseek = default_llseek, + .open = simple_open, + .write = jackin_inject_write, + .llseek = default_llseek, };static const struct file_operations jack_kctl_id_fops = { - .open = simple_open, - .read = jack_kctl_id_read, - .llseek = default_llseek, + .open = simple_open, + .read = jack_kctl_id_read, + .llseek = default_llseek, };static const struct file_operations jack_kctl_mask_bits_fops = { - .open = simple_open, - .read = jack_kctl_mask_bits_read, - .llseek = default_llseek, + .open = simple_open, + .read = jack_kctl_mask_bits_read, + .llseek = default_llseek, };static const struct file_operations jack_kctl_status_fops = { - .open = simple_open, - .read = jack_kctl_status_read, - .llseek = default_llseek, + .open = simple_open, + .read = jack_kctl_status_read, + .llseek = default_llseek, }; static int snd_jack_debugfs_add_inject_node(struct snd_jack *jack,
sound/core/oss/mixer_oss.c +6 -7
@@ -407,13 +407,12 @@ static long snd_mixer_oss_ioctl_compat(struct file *file, unsigned int cmd,* REGISTRATION PART */ -static const struct file_operations snd_mixer_oss_f_ops = -{ - .owner =THIS_MODULE , - .open = snd_mixer_oss_open, - .release = snd_mixer_oss_release, - .unlocked_ioctl = snd_mixer_oss_ioctl, - .compat_ioctl = snd_mixer_oss_ioctl_compat, +static const struct file_operations snd_mixer_oss_f_ops = { + .owner =THIS_MODULE , + .open = snd_mixer_oss_open, + .release = snd_mixer_oss_release, + .unlocked_ioctl = snd_mixer_oss_ioctl, + .compat_ioctl = snd_mixer_oss_ioctl_compat, };/*
sound/core/oss/pcm_oss.c +10 -11
@@ -3120,17 +3120,16 @@ static inline void snd_pcm_oss_proc_done(struct snd_pcm *pcm)* ENTRY functions */ -static const struct file_operations snd_pcm_oss_f_reg = -{ - .owner =THIS_MODULE , - .read = snd_pcm_oss_read, - .write = snd_pcm_oss_write, - .open = snd_pcm_oss_open, - .release = snd_pcm_oss_release, - .poll = snd_pcm_oss_poll, - .unlocked_ioctl = snd_pcm_oss_ioctl, - .compat_ioctl = snd_pcm_oss_ioctl_compat, - .mmap = snd_pcm_oss_mmap, +static const struct file_operations snd_pcm_oss_f_reg = { + .owner =THIS_MODULE , + .read = snd_pcm_oss_read, + .write = snd_pcm_oss_write, + .open = snd_pcm_oss_open, + .release = snd_pcm_oss_release, + .poll = snd_pcm_oss_poll, + .unlocked_ioctl = snd_pcm_oss_ioctl, + .compat_ioctl = snd_pcm_oss_ioctl_compat, + .mmap = snd_pcm_oss_mmap, };static void register_oss_dsp (struct snd_pcm *pcm,int index)
sound/core/pcm_native.c +22 -22
51 lines not on this page · raw message
sound/core/rawmidi.c +8 -8
@@ -1784,14 +1784,14 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,*/ static const struct file_operations snd_rawmidi_f_ops = { - .owner =THIS_MODULE , - .read = snd_rawmidi_read, - .write = snd_rawmidi_write, - .open = snd_rawmidi_open, - .release = snd_rawmidi_release, - .poll = snd_rawmidi_poll, - .unlocked_ioctl = snd_rawmidi_ioctl, - .compat_ioctl = snd_rawmidi_ioctl_compat, + .owner =THIS_MODULE , + .read = snd_rawmidi_read, + .write = snd_rawmidi_write, + .open = snd_rawmidi_open, + .release = snd_rawmidi_release, + .poll = snd_rawmidi_poll, + .unlocked_ioctl = snd_rawmidi_ioctl, + .compat_ioctl = snd_rawmidi_ioctl_compat, }; static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
sound/core/seq/oss/seq_oss.c +10 -11
@@ -206,17 +206,16 @@ odev_poll(struct file *file, poll_table * wait)* registration of sequencer minor device */ -static const struct file_operations seq_oss_f_ops = -{ - .owner =THIS_MODULE , - .read = odev_read, - .write = odev_write, - .open = odev_open, - .release = odev_release, - .poll = odev_poll, - .unlocked_ioctl = odev_ioctl, - .compat_ioctl = odev_ioctl_compat, - .llseek = noop_llseek, +static const struct file_operations seq_oss_f_ops = { + .owner =THIS_MODULE , + .read = odev_read, + .write = odev_write, + .open = odev_open, + .release = odev_release, + .poll = odev_poll, + .unlocked_ioctl = odev_ioctl, + .compat_ioctl = odev_ioctl_compat, + .llseek = noop_llseek, }; static int __init
sound/core/seq/seq_clientmgr.c +9 -10
@@ -2661,16 +2661,15 @@ void snd_seq_info_clients_read(struct snd_info_entry *entry,* REGISTRATION PART */ -static const struct file_operations snd_seq_f_ops = -{ - .owner =THIS_MODULE , - .read = snd_seq_read, - .write = snd_seq_write, - .open = snd_seq_open, - .release = snd_seq_release, - .poll = snd_seq_poll, - .unlocked_ioctl = snd_seq_ioctl, - .compat_ioctl = snd_seq_ioctl_compat, +static const struct file_operations snd_seq_f_ops = { + .owner =THIS_MODULE , + .read = snd_seq_read, + .write = snd_seq_write, + .open = snd_seq_open, + .release = snd_seq_release, + .poll = snd_seq_poll, + .unlocked_ioctl = snd_seq_ioctl, + .compat_ioctl = snd_seq_ioctl_compat, };static struct device *seq_dev;
sound/core/sound.c +4 -5
@@ -167,11 +167,10 @@ static int snd_open(struct inode *inode, struct file *file)return err; } -static const struct file_operations snd_fops = -{ - .owner =THIS_MODULE , - .open = snd_open, - .llseek = noop_llseek, +static const struct file_operations snd_fops = { + .owner =THIS_MODULE , + .open = snd_open, + .llseek = noop_llseek, };#ifdef CONFIG_SND_DYNAMIC_MINORS
sound/core/timer.c +12 -13
@@ -2101,9 +2101,9 @@ static long snd_utimer_ioctl(struct file *file, unsigned int ioctl, unsigned lon }static const struct file_operations snd_utimer_fops = { - .llseek = noop_llseek, - .release = snd_utimer_release, - .unlocked_ioctl = snd_utimer_ioctl, + .llseek = noop_llseek, + .release = snd_utimer_release, + .unlocked_ioctl = snd_utimer_ioctl, };static int snd_utimer_start (struct snd_timer *t)
@@ -2455,16 +2455,15 @@ static __poll_t snd_timer_user_poll(struct file *file, poll_table * wait)#define snd_timer_user_ioctl_compat NULL#endif -static const struct file_operations snd_timer_f_ops = -{ - .owner =THIS_MODULE , - .read = snd_timer_user_read, - .open = snd_timer_user_open, - .release = snd_timer_user_release, - .poll = snd_timer_user_poll, - .unlocked_ioctl = snd_timer_user_ioctl, - .compat_ioctl = snd_timer_user_ioctl_compat, - .fasync = snd_timer_user_fasync, +static const struct file_operations snd_timer_f_ops = { + .owner =THIS_MODULE , + .read = snd_timer_user_read, + .open = snd_timer_user_open, + .release = snd_timer_user_release, + .poll = snd_timer_user_poll, + .unlocked_ioctl = snd_timer_user_ioctl, + .compat_ioctl = snd_timer_user_ioctl_compat, + .fasync = snd_timer_user_fasync, };/* unregister the system timer */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 506/686 ALSA: timer: Handle userspace-driven timer ioctls from 32-bit tasks
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danish Khateeb <[email protected]>
[ Upstream commit 1bbc033983b76f41d51d4a48838bf94c5e6b6f50 ]
32-bit tasks on a 64-bit kernel can't use userspace-driven timers. The compat handler for /dev/snd/timer doesn't list SNDRV_TIMER_IOCTL_CREATE, so creating a timer fails with -ENOTTY. The file returned for a timer has no .compat_ioctl either, so SNDRV_TIMER_IOCTL_TRIGGER fails with -ENOTTY too.
struct snd_timer_uinfo has the same layout for 32-bit and 64-bit tasks, and SNDRV_TIMER_IOCTL_TRIGGER takes no argument, so both commands can be passed through unchanged.
The utimer selftest doesn't catch this when built with -m32: it takes -ENOTTY from SNDRV_TIMER_IOCTL_CREATE to mean CONFIG_SND_UTIMER=n and skips.
--- sound/core/timer.c | 1 + sound/core/timer_compat.c | 1 + 2 files changed, 2 insertions(+)
sound/core/timer.c +1 -0
@@ -2104,6 +2104,7 @@ static const struct file_operations snd_utimer_fops = { .llseek = noop_llseek, .release = snd_utimer_release, .unlocked_ioctl = snd_utimer_ioctl, + .compat_ioctl = snd_utimer_ioctl, };static int snd_utimer_start (struct snd_timer *t)
sound/core/timer_compat.c +1 -0
@@ -98,6 +98,7 @@ static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd,case SNDRV_TIMER_IOCTL_PAUSE :case SNDRV_TIMER_IOCTL_PAUSE_OLD :case SNDRV_TIMER_IOCTL_NEXT_DEVICE : +case SNDRV_TIMER_IOCTL_CREATE :return __snd_timer_user_ioctl (file, cmd, (unsigned long )argp, true);case SNDRV_TIMER_IOCTL_GPARAMS32 :return snd_timer_user_gparams_compat (file, argp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 507/686 ALSA: usb-audio: keep MIDI input running for Roland TD-11
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Hobson <[email protected]>
[ Upstream commit 2e4c9ab2574eeaa7b893c7d35b4a9f60fd681ddd ]
The TD-11 hands MIDI handling off to the host once connected via USB. If no MIDI input port is opened on the host, the device itself becomes unusable as a standalone instrument until its input is serviced, independent of anything happening on the computer.
Add a per-device keep_input_running flag, set for the TD-11 in snd_usbmidi_detect_roland(), and check it alongside the existing opened[1] check in snd_usbmidi_input_start()/snd_usbmidi_input_stop() so that input is started at device creation and never stopped for these devices, regardless of whether a client has the input port open.
Stable-dep-of: 19b42c1fff7f ("ALSA: usb-audio: Protect Roland control activation")
--- sound/usb/midi.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
sound/usb/midi.c +11 -2
@@ -113,6 +113,7 @@ struct snd_usb_midi {unsigned int opened[2 ];unsigned char disconnected;unsigned char input_running; +unsigned char keep_input_running;struct snd_kcontrol *roland_load_ctl; };
@@ -1168,7 +1169,7 @@ static int substream_open(struct snd_rawmidi_substream *substream, int dir,snd_usbmidi_input_start (&umidi->list); }else { umidi->opened[dir]--; -if (!umidi->opened[1 ]) +if (!umidi->opened[1 ] && !umidi->keep_input_running)snd_usbmidi_input_stop (&umidi->list);if (!umidi->opened[0 ] && !umidi->opened[1 ]) {if (umidi->roland_load_ctl) {
@@ -2258,6 +2259,10 @@ static int snd_usbmidi_detect_roland(struct snd_usb_midi *umidi,struct usb_host_interface *hostif;u8 *cs_desc; +/* TD-11 becomes unusable if input isn't serviced continuously */ +if (umidi->usb_id ==USB_ID (0x0582 ,0x0151 )) + umidi->keep_input_running =1 ; + intf = umidi->iface;if (!intf)return -ENOENT ;
@@ -2465,7 +2470,7 @@ void snd_usbmidi_input_start(struct list_head *p)int i; umidi = list_entry(p, struct snd_usb_midi, list); -if (umidi->input_running || !umidi->opened[1 ]) +if (umidi->input_running || (!umidi->opened[1 ] && !umidi->keep_input_running))return ;for (i =0 ; i <MIDI_MAX_ENDPOINTS ; ++i)snd_usbmidi_input_start_ep (umidi, umidi->endpoints[i].in);
@@ -2640,6 +2645,10 @@ int __snd_usbmidi_create(struct snd_card *card,if (err <0 ) goto exit; +/* start input for devices that need continuous servicing */ +if (umidi->keep_input_running) +snd_usbmidi_input_start (&umidi->list); +usb_autopm_get_interface_no_resume (umidi->iface);list_add_tail (&umidi->list, midi_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 508/686 ALSA: usb-audio: Protect Roland control activation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 19b42c1fff7f220a6346c614d79ce1bda6d95b40 ]
The USB MIDI driver changes the Roland MIDI Input Mode control's access flags directly from the rawmidi open and close paths. These changes are not protected by the ALSA control core and the corresponding notifications can race with control access.
Use snd_ctl_activate_id() so that the control core updates the access flags and sends the notification under its lock. Release the USB MIDI mutex before calling it because the control write path holds controls_rwsem while roland_load_put() takes the USB MIDI mutex.
Keep the state transition and alternate-setting change under the USB MIDI mutex; rawmidi's open mutex serializes the enclosing open and close paths.
--- sound/usb/midi.c | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-)
sound/usb/midi.c +27 -26
@@ -1146,41 +1146,42 @@ static int substream_open(struct snd_rawmidi_substream *substream, int dir, int open) {struct snd_usb_midi *umidi = substream->rmidi->private_data; -struct snd_kcontrol *ctl; +struct snd_ctl_elem_id ctl_id; +bool activate_ctl = false; +bool active;guard (rwsem_read)(&umidi->disc_rwsem);if (umidi->disconnected)return open ? -ENODEV :0 ; -guard (mutex)(&umidi->mutex); -if (open) { -if (!umidi->opened[0 ] && !umidi->opened[1 ]) { -if (umidi->roland_load_ctl) { - ctl = umidi->roland_load_ctl; - ctl->vd[0 ].access |= -SNDRV_CTL_ELEM_ACCESS_INACTIVE ; -snd_ctl_notify (umidi->card, -SNDRV_CTL_EVENT_MASK_INFO , &ctl->id); -update_roland_altsetting (umidi); + scoped_guard(mutex, &umidi->mutex) { +if (open) { +if (!umidi->opened[0 ] && !umidi->opened[1 ]) { +if (umidi->roland_load_ctl) { + ctl_id = umidi->roland_load_ctl->id; + activate_ctl = true; + active = false; +update_roland_altsetting (umidi); + } } - } - umidi->opened[dir]++; -if (umidi->opened[1 ]) -snd_usbmidi_input_start (&umidi->list); - }else { - umidi->opened[dir]--; -if (!umidi->opened[1 ] && !umidi->keep_input_running) -snd_usbmidi_input_stop (&umidi->list); -if (!umidi->opened[0 ] && !umidi->opened[1 ]) { -if (umidi->roland_load_ctl) { - ctl = umidi->roland_load_ctl; - ctl->vd[0 ].access &= - ~SNDRV_CTL_ELEM_ACCESS_INACTIVE ; -snd_ctl_notify (umidi->card, -SNDRV_CTL_EVENT_MASK_INFO , &ctl->id); + umidi->opened[dir]++; +if (umidi->opened[1 ]) +snd_usbmidi_input_start (&umidi->list); + }else { + umidi->opened[dir]--; +if (!umidi->opened[1 ] && !umidi->keep_input_running) +snd_usbmidi_input_stop (&umidi->list); +if (!umidi->opened[0 ] && !umidi->opened[1 ]) { +if (umidi->roland_load_ctl) { + ctl_id = umidi->roland_load_ctl->id; + activate_ctl = true; + active = true; + } } } } +if (activate_ctl) +snd_ctl_activate_id (umidi->card, &ctl_id, active);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 509/686 hwmon: (tmp102) Fix jiffies wraparound in conversion-ready check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tom Verdonck <[email protected]>
[ Upstream commit 56c1d32323e773b8b927316f8beeae9238576335 ]
tmp102 records a one-shot deadline in ->ready_time at probe (and resume) and, on every temperature read, refuses the read with -EAGAIN while time_before(jiffies, ready_time) is true, in order to skip the first ~35 ms conversion.
->ready_time is an unsigned long compared with time_before(), whose signed difference is only meaningful while the two values are within LONG_MAX jiffies of each other. Because ->ready_time is set once and never refreshed, jiffies keeps advancing away from it, and after 2^31 jiffies the difference flips sign. On a 32-bit HZ=100 kernel that happens ~248.5 days after boot: time_before() then permanently reports "not ready" and the driver returns -EAGAIN on every read, without ever touching the sensor, until the next reboot.
Store the deadline as a 64-bit jiffies value and compare it with get_jiffies_64()/time_before64(), which does not wrap in any practical uptime.
--- drivers/hwmon/tmp102.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hwmon/tmp102.c +4 -4
@@ -56,7 +56,7 @@ struct tmp102 {const char *label;struct regmap *regmap;u16 config_orig; -unsigned long ready_time; +u64 ready_time; };/* convert left adjusted 13-bit TMP102 register value to milliCelsius */
@@ -91,7 +91,7 @@ static int tmp102_read(struct device *dev, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input:/* Is it too early to return a conversion ? */ -if (time_before (jiffies, tmp102->ready_time)) { +if (time_before64 (get_jiffies_64 (), tmp102->ready_time)) {dev_dbg (dev,"%s: Conversion not ready yet..\n" , __func__);return -EAGAIN ; }
@@ -270,7 +270,7 @@ static int tmp102_probe(struct i2c_client *client)* Mark that we are not ready with data until the first * conversion is complete */ - tmp102->ready_time = jiffies +msecs_to_jiffies (CONVERSION_TIME_MS ); + tmp102->ready_time =get_jiffies_64 () +msecs_to_jiffies (CONVERSION_TIME_MS ); hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, tmp102,
@@ -303,7 +303,7 @@ static int tmp102_resume(struct device *dev) err =regmap_update_bits (tmp102->regmap,TMP102_CONF_REG ,TMP102_CONF_SD ,0 ); - tmp102->ready_time = jiffies +msecs_to_jiffies (CONVERSION_TIME_MS ); + tmp102->ready_time =get_jiffies_64 () +msecs_to_jiffies (CONVERSION_TIME_MS );return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 510/686 gfs2: reject invalid inode sizes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiaming Zhang <[email protected]>
[ Upstream commit 33ed0a0567e0abe66ea65e89dad2e35082890fbe ]
A corrupted GFS2 image can store a dinode size that is larger than what VFS i_size can represent. gfs2_dinode_in() reads the on-disk di_size as a u64 and writes it directly into inode->i_size. If the value is larger than S64_MAX, the incore i_size becomes negative. That negative value can bypass the existing stuffed inode size check:
inode->i_size > gfs2_max_stuffed_size(ip)
Later, gfs2_quotad may try to sync the quota file and unstuff the quota inode. gfs2_unstuffer_folio() reads the negative i_size into an unsigned length and passes it to memcpy(), turning it into a huge copy size and triggering a out-of-bound issue.
Reject dinodes whose size exceeds sb->s_maxbytes before storing the value in inode->i_size. Also make the stuffed inode check use the raw on-disk size while it is still unsigned.
--- fs/gfs2/glops.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/gfs2/glops.c +8 -2
@@ -392,6 +392,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)umode_t mode =be32_to_cpu (str->di_mode);struct inode *inode = &ip->i_inode;bool is_new = inode->i_state &I_NEW ; +u64 size;if (unlikely (ip->i_no_addr !=be64_to_cpu (str->di_num.no_addr))) {gfs2_consist_inode (ip);
@@ -417,7 +418,12 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)i_uid_write (inode,be32_to_cpu (str->di_uid));i_gid_write (inode,be32_to_cpu (str->di_gid));set_nlink (inode,be32_to_cpu (str->di_nlink)); -i_size_write (inode,be64_to_cpu (str->di_size)); + size =be64_to_cpu (str->di_size); +if (unlikely (size > inode->i_sb->s_maxbytes)) { +gfs2_consist_inode (ip); +return -EIO ; + } +i_size_write (inode, size);gfs2_set_inode_blocks (inode,be64_to_cpu (str->di_blocks)); atime.tv_sec =be64_to_cpu (str->di_atime); atime.tv_nsec =be32_to_cpu (str->di_atime_nsec);
@@ -456,7 +462,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) ip->i_depth = (u8 )depth; ip->i_entries =be32_to_cpu (str->di_entries); -if (gfs2_is_stuffed (ip) && inode->i_size >gfs2_max_stuffed_size (ip)) { +if (gfs2_is_stuffed (ip) && size >gfs2_max_stuffed_size (ip)) {gfs2_consist_inode (ip);return -EIO ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 511/686 media: i2c: og01a1b: Switch from .s_stream to .enable_streams/.disable_streams
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Zapolskiy <[email protected]>
[ Upstream commit 3a594bb454ba1ecb005f753007fa1bb5c5e68bae ]
The change allows to simplify the driver code, in particular the explicit locking scheme for stream on/off or format update serialization can be dropped in favour to the one provided by the V4L2 core internals.
Stable-dep-of: a26c5ac46191 ("media: i2c: og01a1b: power off sensor on remove")
--- drivers/media/i2c/og01a1b.c | 90 ++++++++++++++----------------------- 1 file changed, 34 insertions(+), 56 deletions(-)
drivers/media/i2c/og01a1b.c +34 -56
@@ -442,9 +442,6 @@ struct og01a1b {/* Current mode */ const struct og01a1b_mode *cur_mode; - -/* To serialize asynchronus callbacks */ -struct mutex mutex; };static u64 to_pixel_rate (u32 f_index)
@@ -616,7 +613,6 @@ static int og01a1b_init_controls(struct og01a1b *og01a1b)if (ret)return ret; - ctrl_hdlr->lock = &og01a1b->mutex; og01a1b->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &og01a1b_ctrl_ops, V4L2_CID_LINK_FREQ,
@@ -686,74 +682,66 @@ static void og01a1b_update_pad_format(const struct og01a1b_mode *mode, fmt->field =V4L2_FIELD_NONE ; } -static int og01a1b_start_streaming (struct og01a1b *og01a1b) +static int og01a1b_enable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) { +struct og01a1b *og01a1b =to_og01a1b (sd); +unsigned int link_freq_index = og01a1b->cur_mode->link_freq_index;const struct og01a1b_reg_list *reg_list; -int link_freq_index, ret; +int ret; - link_freq_index = og01a1b->cur_mode->link_freq_index; - reg_list = &link_freq_configs[link_freq_index].reg_list; + ret =pm_runtime_resume_and_get (og01a1b->dev); +if (ret) +return ret; + reg_list = &link_freq_configs[link_freq_index].reg_list; ret =og01a1b_write_reg_list (og01a1b, reg_list);if (ret) { -dev_err (og01a1b->dev,"failed to set plls" ); -return ret; +dev_err (og01a1b->dev,"failed to set plls: %d\n" , ret); + goto error; } reg_list = &og01a1b->cur_mode->reg_list; ret =og01a1b_write_reg_list (og01a1b, reg_list);if (ret) { -dev_err (og01a1b->dev,"failed to set mode" ); -return ret; +dev_err (og01a1b->dev,"failed to set mode: %d\n" , ret); + goto error; } ret =__v4l2_ctrl_handler_setup (og01a1b->sd.ctrl_handler);if (ret) -return ret; + goto error; ret =og01a1b_write_reg (og01a1b,OG01A1B_REG_MODE_SELECT ,OG01A1B_REG_VALUE_08BIT ,OG01A1B_MODE_STREAMING );if (ret) { -dev_err (og01a1b->dev,"failed to set stream" ); -return ret; +dev_err (og01a1b->dev,"failed to start streaming: %d\n" , ret); + goto error; }return 0 ; -} -static void og01a1b_stop_streaming (struct og01a1b *og01a1b) -{ -if (og01a1b_write_reg (og01a1b,OG01A1B_REG_MODE_SELECT , -OG01A1B_REG_VALUE_08BIT ,OG01A1B_MODE_STANDBY )) -dev_err (og01a1b->dev,"failed to set stream" ); +error: +pm_runtime_put_autosuspend (og01a1b->dev); + +return ret; } -static int og01a1b_set_stream (struct v4l2_subdev *sd,int enable) +static int og01a1b_disable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) {struct og01a1b *og01a1b =to_og01a1b (sd); -int ret =0 ; - -mutex_lock (&og01a1b->mutex); -if (enable) { - ret =pm_runtime_resume_and_get (og01a1b->dev); -if (ret) { -mutex_unlock (&og01a1b->mutex); -return ret; - } +int ret; - ret =og01a1b_start_streaming (og01a1b); -if (ret) { - enable =0 ; -og01a1b_stop_streaming (og01a1b); -pm_runtime_put (og01a1b->dev); - } - }else { -og01a1b_stop_streaming (og01a1b); -pm_runtime_put (og01a1b->dev); - } + ret =og01a1b_write_reg (og01a1b,OG01A1B_REG_MODE_SELECT , +OG01A1B_REG_VALUE_08BIT ,OG01A1B_MODE_STANDBY ); +if (ret) +dev_err (og01a1b->dev,"failed to stop streaming: %d\n" , ret); -mutex_unlock (&og01a1b->mutex); +pm_runtime_put_autosuspend (og01a1b->dev);return ret; }
@@ -771,7 +759,6 @@ static int og01a1b_set_format(struct v4l2_subdev *sd, height, fmt->format.width, fmt->format.height); -mutex_lock (&og01a1b->mutex);og01a1b_update_pad_format (mode, &fmt->format);if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { *v4l2_subdev_state_get_format (sd_state, fmt->pad) = fmt->format;
@@ -794,8 +781,6 @@ static int og01a1b_set_format(struct v4l2_subdev *sd, h_blank); } -mutex_unlock (&og01a1b->mutex); -return 0 ; }
@@ -805,15 +790,12 @@ static int og01a1b_get_format(struct v4l2_subdev *sd, {struct og01a1b *og01a1b =to_og01a1b (sd); -mutex_lock (&og01a1b->mutex);if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) fmt->format = *v4l2_subdev_state_get_format (sd_state, fmt->pad);else og01a1b_update_pad_format (og01a1b->cur_mode, &fmt->format); -mutex_unlock (&og01a1b->mutex); -return 0 ; }
@@ -849,18 +831,14 @@ static int og01a1b_enum_frame_size(struct v4l2_subdev *sd,static int og01a1b_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) { -struct og01a1b *og01a1b =to_og01a1b (sd); - -mutex_lock (&og01a1b->mutex);og01a1b_update_pad_format (&supported_modes[0 ],v4l2_subdev_state_get_format (fh->state,0 )); -mutex_unlock (&og01a1b->mutex);return 0 ; }static const struct v4l2_subdev_video_ops og01a1b_video_ops = { - .s_stream = og01a1b_set_stream, + .s_stream = v4l2_subdev_s_stream_helper, };static const struct v4l2_subdev_pad_ops og01a1b_pad_ops = {
@@ -868,6 +846,8 @@ static const struct v4l2_subdev_pad_ops og01a1b_pad_ops = { .get_fmt = og01a1b_get_format, .enum_mbus_code = og01a1b_enum_mbus_code, .enum_frame_size = og01a1b_enum_frame_size, + .enable_streams = og01a1b_enable_streams, + .disable_streams = og01a1b_disable_streams, };static const struct v4l2_subdev_ops og01a1b_subdev_ops = {
@@ -1046,7 +1026,6 @@ static void og01a1b_remove(struct i2c_client *client)media_entity_cleanup (&sd->entity);v4l2_ctrl_handler_free (sd->ctrl_handler);pm_runtime_disable (og01a1b->dev); -mutex_destroy (&og01a1b->mutex); }static int og01a1b_probe (struct i2c_client *client)
@@ -1135,7 +1114,6 @@ static int og01a1b_probe(struct i2c_client *client) goto power_off; } -mutex_init (&og01a1b->mutex); og01a1b->cur_mode = &supported_modes[0 ]; ret =og01a1b_init_controls (og01a1b);if (ret) {
@@ -1143,6 +1121,7 @@ static int og01a1b_probe(struct i2c_client *client) goto probe_error_v4l2_ctrl_handler_free; } + og01a1b->sd.state_lock = og01a1b->ctrl_handler.lock; og01a1b->sd.internal_ops = &og01a1b_internal_ops; og01a1b->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; og01a1b->sd.entity.ops = &og01a1b_subdev_entity_ops;
@@ -1183,7 +1162,6 @@ static int og01a1b_probe(struct i2c_client *client) probe_error_v4l2_ctrl_handler_free:v4l2_ctrl_handler_free (og01a1b->sd.ctrl_handler); -mutex_destroy (&og01a1b->mutex); power_off:og01a1b_power_off (og01a1b->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 512/686 media: i2c: og01a1b: power off sensor on remove
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit a26c5ac46191ae34b3413f7a45d6241f63e15d42 ]
og01a1b_probe() powers the sensor on explicitly before identifying and initializing it. After a successful probe, runtime PM is enabled and pm_runtime_idle() is used to allow the runtime suspend callback to power the sensor off.
The probe error path explicitly calls og01a1b_power_off(), but the normal remove path only disables runtime PM. pm_runtime_disable() does not guarantee that an active device is runtime suspended, so the sensor can remain powered when the driver is removed. This also leaves the xvclk enable performed by og01a1b_power_on() unbalanced.
After disabling runtime PM, check whether the device is already suspended. If it is still active, power the sensor off explicitly and update the runtime PM state accordingly. Avoid powering it off again when runtime suspend has already done so.
This issue was found by manual code inspection.
--- drivers/media/i2c/og01a1b.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/media/i2c/og01a1b.c +5 -0
@@ -1026,6 +1026,11 @@ static void og01a1b_remove(struct i2c_client *client)media_entity_cleanup (&sd->entity);v4l2_ctrl_handler_free (sd->ctrl_handler);pm_runtime_disable (og01a1b->dev); + +if (!pm_runtime_status_suspended (og01a1b->dev)) { +og01a1b_power_off (og01a1b->dev); +pm_runtime_set_suspended (og01a1b->dev); + } }static int og01a1b_probe (struct i2c_client *client)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 513/686 f2fs: fix to avoid folio->mapping dereference in is_{meta, node}_folio()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit b5a71253c5c7e1139eab2f3e1e13e0bf2cbcaac7 ]
Otherwise, it may cause NULL pointer dereference in race condition:
Thread A Thread B
- f2fs_setattr
- f2fs_truncate
- f2fs_truncate_blocks
- f2fs_do_truncate_blocks
- f2fs_truncate_inode_blocks
- truncate_dnode
- truncate_node
- invalidate_mapping_pages
- folio->mapping = NULL
- folio_lock
- is_node_folio
- F2FS_F_SB(folio): dereference on folio->mapping
--- fs/f2fs/checkpoint.c | 4 ++-- fs/f2fs/data.c | 5 +++-- fs/f2fs/f2fs.h | 8 ++++---- fs/f2fs/gc.c | 2 +- fs/f2fs/node.c | 16 ++++++++-------- 5 files changed, 18 insertions(+), 17 deletions(-)
fs/f2fs/checkpoint.c +2 -2
@@ -93,7 +93,7 @@ static struct folio *__get_meta_folio(struct f2fs_sb_info *sbi, pgoff_t index,f2fs_update_iostat (sbi,NULL ,FS_META_READ_IO ,F2FS_BLKSIZE );folio_lock (folio); -if (unlikely (!is_meta_folio (folio))) { +if (unlikely (!is_meta_folio (sbi, folio))) {f2fs_folio_put (folio, true); goto repeat; }
@@ -439,7 +439,7 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,folio_lock (folio); -if (unlikely (!is_meta_folio (folio))) { +if (unlikely (!is_meta_folio (sbi, folio))) { continue_unlock:folio_unlock (folio);continue ;
fs/f2fs/data.c +3 -2
@@ -153,7 +153,8 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)dec_page_count (F2FS_F_SB (folio),__read_io_type (folio));if (bio->bi_status ==BLK_STS_OK && -F2FS_F_SB (folio)->node_inode &&is_node_folio (folio) && +F2FS_F_SB (folio)->node_inode && +is_node_folio (F2FS_F_SB (folio), folio) &&f2fs_sanity_check_node_footer (F2FS_F_SB (folio), folio, folio->index,NODE_TYPE_REGULAR , true)) bio->bi_status =BLK_STS_IOERR ;
@@ -359,7 +360,7 @@ static void f2fs_write_end_io(struct bio *bio) STOP_CP_REASON_WRITE_FAIL); } -if (is_node_folio (folio)) { +if (is_node_folio (sbi, folio)) {f2fs_sanity_check_node_footer (sbi, folio, folio->index,NODE_TYPE_REGULAR , true);f2fs_bug_on (sbi, folio->index !=nid_of_node (folio));
fs/f2fs/f2fs.h +4 -4
@@ -2222,14 +2222,14 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)return sbi->node_inode->i_mapping; } -static inline bool is_meta_folio (struct folio *folio) +static inline bool is_meta_folio (struct f2fs_sb_info *sbi,struct folio *folio) { -return folio->mapping ==META_MAPPING (F2FS_F_SB (folio)); +return folio->mapping ==META_MAPPING (sbi); } -static inline bool is_node_folio (struct folio *folio) +static inline bool is_node_folio (struct f2fs_sb_info *sbi,struct folio *folio) { -return folio->mapping ==NODE_MAPPING (F2FS_F_SB (folio)); +return folio->mapping ==NODE_MAPPING (sbi); }static inline bool is_sbi_flag_set (struct f2fs_sb_info *sbi,unsigned int type)
fs/f2fs/gc.c +1 -1
@@ -1418,7 +1418,7 @@ static int move_data_block(struct inode *inode, block_t bidx, F2FS_BLKSIZE);folio_lock (mfolio); -if (unlikely (!is_meta_folio (mfolio) || +if (unlikely (!is_meta_folio (fio.sbi, mfolio) || !folio_test_uptodate (mfolio))) { err = -EIO ;f2fs_folio_put (mfolio, true);
fs/f2fs/node.c +8 -8
@@ -327,7 +327,7 @@ static unsigned int __gang_lookup_nat_set(struct f2fs_nm_info *nm_i,bool f2fs_in_warm_node_list (struct f2fs_sb_info *sbi,struct folio *folio) { -return is_node_folio (folio) &&IS_DNODE (folio) &&is_cold_node (folio); +return is_node_folio (sbi, folio) &&IS_DNODE (folio) &&is_cold_node (folio); }void f2fs_init_fsync_node_info (struct f2fs_sb_info *sbi)
@@ -1266,7 +1266,7 @@ int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from) goto fail;if (offset[1 ] ==0 &&get_nid (folio, offset[0 ], true)) {folio_lock (folio); -BUG_ON (!is_node_folio (folio)); +BUG_ON (!is_node_folio (sbi, folio));set_nid (folio, offset[0 ],0 , true);folio_unlock (folio); }
@@ -1579,7 +1579,7 @@ static struct folio *__get_node_folio(struct f2fs_sb_info *sbi, pgoff_t nid,folio_lock (folio); -if (unlikely (!is_node_folio (folio))) { +if (unlikely (!is_node_folio (sbi, folio))) {f2fs_folio_put (folio, true); goto repeat; }
@@ -1698,7 +1698,7 @@ static struct folio *last_fsync_dnode(struct f2fs_sb_info *sbi, nid_t ino)folio_lock (folio); -if (unlikely (!is_node_folio (folio))) { +if (unlikely (!is_node_folio (sbi, folio))) { continue_unlock:folio_unlock (folio);continue ;
@@ -1930,7 +1930,7 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,folio_lock (folio); -if (unlikely (!is_node_folio (folio))) { +if (unlikely (!is_node_folio (sbi, folio))) { continue_unlock:folio_unlock (folio);continue ;
@@ -1988,7 +1988,7 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,f2fs_debug (sbi,"Retry to write fsync mark: ino=%u, idx=%lx" , ino, last_folio->index);folio_lock (last_folio); -if (unlikely (!is_node_folio (last_folio))) { +if (unlikely (!is_node_folio (sbi, last_folio))) {f2fs_folio_put (last_folio, true); ret = -EAGAIN ; goto out;
@@ -2066,7 +2066,7 @@ void f2fs_flush_inline_data(struct f2fs_sb_info *sbi)folio_lock (folio); -if (unlikely (!is_node_folio (folio))) +if (unlikely (!is_node_folio (sbi, folio))) goto unlock;if (!folio_test_dirty (folio)) goto unlock;
@@ -2138,7 +2138,7 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,else if (!folio_trylock (folio))continue ; -if (unlikely (!is_node_folio (folio))) { +if (unlikely (!is_node_folio (sbi, folio))) { continue_unlock:folio_unlock (folio);continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 514/686 m68k: Fix task info flags handling for 68000
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Palmer <[email protected]>
[ Upstream commit 2c6805145e1605cef39459f78979f7edee251b41 ]
The logic for deciding what to do after a syscall should be checking if any of the lower byte bits are set and then checking if the reschedule bit is set.
Currently we are loading the top word, checking if any bits are set (which never seems to be true) and thus jumping over loading the whole long and checking if the reschedule bit is set.
We get the thread info in two places so split that logic out in a macro and then fix the code so that it loads the byte of the flags we need to check, checks if anything is set and then checks if the reschedule bit in particular is set.
Stable-dep-of: 48859f8018d9 ("m68k: Fix seccomp filtering on ColdFire and 68000")
--- arch/m68k/68000/entry.S | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
arch/m68k/68000/entry.S +13 -8
@@ -18,6 +18,13 @@ .text +/* get thread_info pointer into a2 */ + .macro getthreadinfo + movel %sp,%d1 + andl #-THREAD_SIZE,%d1 + movel %d1,%a2 + .endm + .globl system_call .globl resume .globl ret_from_exception
@@ -70,9 +77,8 @@ ENTRY(system_call) movel %sp@(PT_OFF_ORIG_D0),%d0 - movel %sp,%d1 /* get thread_info pointer */ - andl #-THREAD_SIZE,%d1 - movel %d1,%a2 + /* Doing a trace ? */ + getthreadinfo btst #(TIF_SYSCALL_TRACE%8),%a2@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) jne do_trace cmpl #NR_syscalls,%d0
@@ -96,16 +102,15 @@ Luser_return: /* heavy interrupt load*/ andw #ALLOWINT,%sr - movel %sp,%d1 /* get thread_info pointer */ - andl #-THREAD_SIZE,%d1 - movel %d1,%a2 + getthreadinfo 1: - move %a2@(TINFO_FLAGS),%d1 /* thread_info->flags */ + /* check if any of the flags are set */ + moveb %a2@(TINFO_FLAGS + 3),%d1 /* thread_info->flags (low 8 bits) */ jne Lwork_to_do RESTORE_ALL Lwork_to_do: - movel %a2@(TINFO_FLAGS),%d1 /* thread_info->flags */ + /* check if reschedule needs to be called */ btst #TIF_NEED_RESCHED,%d1 jne reschedule
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 515/686 m68k: Fix seccomp filtering on ColdFire and 68000
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christopher Lusk <[email protected]>
[ Upstream commit 48859f8018d93bd93ef35f7430fdf5b97f2f9715 ]
m68k selects HAVE_ARCH_SECCOMP_FILTER for all configurations, but the ColdFire and 68000 syscall entry paths only branch to syscall_trace_enter() for TIF_SYSCALL_TRACE. TIF_SECCOMP alone falls through to syscall dispatch, leaving installed filters ineffective.
Test the combined TIF_SYSCALL_TRACE and TIF_SECCOMP mask in both paths and route either flag through the existing slow path. Leave the classic MMU syscall entry implementation unchanged.
Validated the combined test under QEMU mcf5208evb (ColdFire): filters denying getpid, openat, unlinkat, and reboot each returned -EPERM. A classic-MMU control (q800) denied the filtered getpid syscall both before and after this change. The 68000 path shares the same source-level omission and receives the identical masked test but was not separately emulated. Compile-tested W=1 with CONFIG_SECCOMP_FILTER=y on both m5208evb_defconfig and a custom no-MMU UCSIMM configuration; the latter built arch/m68k/68000/entry.o and vmlinux.
--- arch/m68k/68000/entry.S | 3 ++- arch/m68k/coldfire/entry.S | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
arch/m68k/68000/entry.S +2 -1
@@ -79,7 +79,8 @@ ENTRY(system_call) /* Doing a trace ? */ getthreadinfo - btst #(TIF_SYSCALL_TRACE%8),%a2@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) + moveb %a2@(TINFO_FLAGS+2),%d1 + andl #((_TIF_SYSCALL_TRACE + _TIF_SECCOMP) >> 8),%d1 jne do_trace cmpl #NR_syscalls,%d0 jcc badsys
arch/m68k/coldfire/entry.S +2 -1
@@ -72,7 +72,8 @@ ENTRY(system_call) movel %d2,%a0 movel %a0@,%a1 /* save top of frame */ movel %sp,%a1@(TASK_THREAD+THREAD_ESP0) - btst #(TIF_SYSCALL_TRACE%8),%a0@(TINFO_FLAGS+(31-TIF_SYSCALL_TRACE)/8) + moveb %a0@(TINFO_FLAGS+2),%d2 + andl #((_TIF_SYSCALL_TRACE + _TIF_SECCOMP) >> 8),%d2 bnes 1f movel %d3,%a0
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 516/686 powerpc/pseries/iommu: Add TCEs for 16GB pages when RAM is pre-mapped
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gaurav Batra <[email protected]>
[ Upstream commit 0b8b0c17a8998709ecb2852d56442ea981102941 ]
In powerPC, if Dynamic DMA Window is big enough, RAM is pre-mapped. To determine the size of RAM, a PAPR+ property "ibm,lrdr-capacity" is used. This OF property dictates what is the max size of RAM an LPAR can have, including DR added memory.
In PowerPC, 16GB pages can be allocated at machine level and then assigned to LPARs. These 16GB pages are added to LPAR memory at the time of boot. The address range for these 16GB pages is above MAX RAM an LPAR can have (ibm,lrdr-capacity). In the current implementation, these 16GB pages are being excluded from pre-mapped TCEs. A driver can have DMA buffers allocated from 16GB pages. This results in platform to raise an EEH when DMA is attempted on buffers in 16GB memory range.
commit 6aa989ab2bd0 ("powerpc/pseries/iommu: memory notifier incorrectly adds TCEs for pmemory")
Prior to the above patch, memblock_end_of_DRAM() was being used to determine the MAX memory of an LPAR. This included 16GB pages as well. The issue with using memblock_end_of_DRAM() is that when pmemory is converted to RAM via daxctl command, the DDW engine will incorrectly try to add TCEs for pmemory as well.
Below is the address distribution of RAM, 16GB pages and pmemory for an LPAR with max memory of 256GB, memory allocated 64GB, 2 16GB pages and assigned pmemory of 8GB.
RANGE SIZE STATE REMOVABLE BLOCK
0x0000000000000000-0x0000000fffffffff 64G online yes 0-255 0x0000004000000000-0x00000047ffffffff 32G online yes 1024-1151
cat /sys/bus/nd/devices/region0/resource0x40100000000
cat /sys/bus/nd/devices/region0/size
8589934592
The approach to fix this problem is to revert back the code changes introduced by the above patch and to stash away the MAX memory of an LPAR, including 16GB pages, at the LPAR boot time. This value is then used whenever TCEs are needed to be pre-mapped - enable_DDW() or, iommu_mem_notifier()
--- arch/powerpc/platforms/pseries/iommu.c | 67 +++++++++++++++++--------- 1 file changed, 45 insertions(+), 22 deletions(-)
arch/powerpc/platforms/pseries/iommu.c +45 -22
@@ -69,6 +69,8 @@ static struct iommu_table *iommu_pseries_alloc_table(int node)return tbl; } +static phys_addr_t pseries_ddw_max_ram__ro_after_init ; +#ifdef CONFIG_IOMMU_API static struct iommu_table_group_ops spapr_tce_table_group_ops;#endif
@@ -1284,15 +1286,19 @@ struct failed_ddw_pdn {static LIST_HEAD (failed_ddw_pdn_list); -static phys_addr_t ddw_memory_hotplug_max (void ) +static phys_addr_t __init ddw_memory_hotplug_max (void ) { -resource_size_t max_addr; +resource_size_t max_addr =memory_hotplug_max (); +struct device_node *memory; -#if defined(CONFIG_NUMA ) && defined(CONFIG_MEMORY_HOTPLUG ) - max_addr =hot_add_drconf_memory_max (); -#else - max_addr =memblock_end_of_DRAM (); -#endif +for_each_node_by_type (memory,"memory" ) { +struct resource res; + +if (of_address_to_resource (memory,0 , &res)) +continue ; + + max_addr =max_t (resource_size_t, max_addr, res.end +1 ); + }return max_addr; }
@@ -1447,7 +1453,7 @@ static struct property *ddw_property_create(const char *propname, u32 liobn, u64static bool enable_ddw (struct pci_dev *dev,struct device_node *pdn,u64 dma_mask) {int len =0 , ret; -int max_ram_len =order_base_2 (ddw_memory_hotplug_max ()); +int max_ram_len =order_base_2 (pseries_ddw_max_ram);struct ddw_query_response query;struct ddw_create_response create;int page_shift;
@@ -1617,12 +1623,12 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn, u64 dma_masif (default_win_removed && pmem_present && !direct_mapping) {/* DDW is big enough to be split */ if ((1ULL << ddw_sz) >= -MIN_DDW_VPMEM_DMA_WINDOW + (1ULL << max_ram_len)) { +MIN_DDW_VPMEM_DMA_WINDOW + pseries_ddw_max_ram) { direct_mapping = true;/* offset of the Dynamic part of DDW */ - dynamic_offset =1ULL << max_ram_len; + dynamic_offset = pseries_ddw_max_ram; }/* DDW will at least have dynamic allocation */
@@ -1669,7 +1675,7 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn, u64 dma_masif (direct_mapping) {/* DDW maps the whole partition, so enable direct DMA mapping */ - ret =walk_system_ram_range (0 ,ddw_memory_hotplug_max () >>PAGE_SHIFT , + ret =walk_system_ram_range (0 , pseries_ddw_max_ram >>PAGE_SHIFT , win64->value, tce_setrange_multi_pSeriesLP_walk);if (ret) { dev_info(&dev->dev, "failed to map DMA window for %pOF: %d\n",
@@ -1774,8 +1780,7 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn, u64 dma_mas* to directly map both RAM and vPMEM, then we need to set DMA limit. */ if (pmem_present && direct_mapping && len !=MAX_PHYSMEM_BITS ) - dev->dev.bus_dma_limit = dev->dev.archdata.dma_offset + - (1ULL << max_ram_len); + dev->dev.bus_dma_limit = dev->dev.archdata.dma_offset + pseries_ddw_max_ram;dev_info (&dev->dev,"lsa_required: %x, lsa_enabled: %x, direct mapping: %x\n" , limited_addr_req, limited_addr_enabled, direct_mapping);
@@ -2422,23 +2427,35 @@ static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action, {struct dma_win *window;struct memory_notify *arg = data; +unsigned long limit = arg->nr_pages; +unsigned long max_ram_pages = pseries_ddw_max_ram >>PAGE_SHIFT ;int ret =0 ;/* This notifier can get called when onlining persistent memory as well. * TCEs are not pre-mapped for persistent memory. Persistent memory will -* always be above ddw_memory_hotplug_max() +* always be above pseries_ddw_max_ram */ +if (arg->start_pfn >= max_ram_pages) +return NOTIFY_OK ; + +/* RAM is being DLPAR'ed. The range should never exceed max ram. +* Just in case, clamp the range and throw a warning. +*/ +if (arg->start_pfn + limit > max_ram_pages) { + limit = max_ram_pages - arg->start_pfn; +WARN_ONCE (1 ,"Limiting Page Range %lx - %lx to Max Mem Pages: %lx\n" , + arg->start_pfn, arg->start_pfn + arg->nr_pages, + max_ram_pages); + }switch (action) {case MEM_GOING_ONLINE :spin_lock (&dma_win_list_lock);list_for_each_entry (window, &dma_win_list, list) { -if (window->direct && (arg->start_pfn <<PAGE_SHIFT ) < -ddw_memory_hotplug_max ()) { +if (window->direct) { ret |=tce_setrange_multi_pSeriesLP (arg->start_pfn, - arg->nr_pages, window->prop); + limit, window->prop); } -/* XXX log error */ }spin_unlock (&dma_win_list_lock);break ;
@@ -2446,12 +2463,10 @@ static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action,case MEM_OFFLINE :spin_lock (&dma_win_list_lock);list_for_each_entry (window, &dma_win_list, list) { -if (window->direct && (arg->start_pfn <<PAGE_SHIFT ) < -ddw_memory_hotplug_max ()) { +if (window->direct) { ret |=tce_clearrange_multi_pSeriesLP (arg->start_pfn, - arg->nr_pages, window->prop); + limit, window->prop); } -/* XXX log error */ }spin_unlock (&dma_win_list_lock);break ;
@@ -2535,6 +2550,14 @@ void __init iommu_init_early_pSeries(void)register_memory_notifier (&iommu_mem_nb);set_pci_dma_ops (&dma_iommu_ops); + +/* During init determine the max memory an LPAR can have and set it. This +* will be used for pre-mapping RAM in DDW. memblock_end_of_DRAM() can +* change during the running of LPAR - daxctl can add pmemory as +* "system-ram". This memory range should not be pre-mapped in DDW since +* the address of pmemory can be much higher than the DDW size. +*/ + pseries_ddw_max_ram =ddw_memory_hotplug_max (); }static int __init disable_multitce (char *str)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 517/686 f2fs: fix to check continuousness in f2fs_sync_meta_pages() correctly
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit 1383cff4ccf3c8833c6255edffa29eb67c6419bb ]
In f2fs_sync_meta_pages(), whenever i becomes zero inside while loop, below check may be skipped, it failed to check the continuousness:
if (nr_to_write != LONG_MAX && i != 0 &&
folio->index != prev +
folio_nr_pages(fbatch.folios[i-1])) {--- fs/f2fs/checkpoint.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/f2fs/checkpoint.c +4 -5
@@ -411,7 +411,7 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, long nr_to_write, enum iostat_type io_type) { struct address_space *mapping = META_MAPPING(sbi); -pgoff_t index =0 , prev =ULONG_MAX ; +pgoff_t index =0 , next =ULONG_MAX ;struct folio_batch fbatch;long nwritten =0 ;int nr_folios;
@@ -430,9 +430,8 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,for (i =0 ; i < nr_folios; i++) {struct folio *folio = fbatch.folios[i]; -if (nr_to_write !=LONG_MAX && i !=0 && - folio->index != prev + -folio_nr_pages (fbatch.folios[i-1 ])) { +if (nr_to_write !=LONG_MAX && next !=ULONG_MAX && + folio->index != next) {folio_batch_release (&fbatch); goto stop; }
@@ -460,7 +459,7 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,break ; } nwritten +=folio_nr_pages (folio); - prev = folio->index; + next = folio->index +folio_nr_pages (folio);if (unlikely (nwritten >= nr_to_write))break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 518/686 iio: light: Remove redundant dev_err()/dev_err_probe()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pan Chuang <[email protected]>
[ Upstream commit 9cf89c342bc2508b79b4ab8823df90da8f77f1f1 ]
Since commit55b48e23f5c4 ("genirq/devres: Add error handling in devm_request_*_irq()"), devm_request_irq() and devm_request_threaded_irq() automatically log detailed error messages on failure. Remove the now-redundant driver-specific dev_err() and dev_err_probe() calls.
Standardize error check on if (ret) rather than if (ret < 0).
Stable-dep-of: 8a9bcd587d7d ("iio: light: ltr501: Power down chip if request irq fails")
--- drivers/iio/light/adux1020.c | 4 +--- drivers/iio/light/apds9160.c | 7 ++----- drivers/iio/light/apds9300.c | 4 +--- drivers/iio/light/apds9306.c | 3 +-- drivers/iio/light/apds9960.c | 4 +--- drivers/iio/light/bh1745.c | 3 +-- drivers/iio/light/cm3605.c | 4 +--- drivers/iio/light/gp2ap002.c | 4 +--- drivers/iio/light/ltr390.c | 3 +-- drivers/iio/light/ltr501.c | 5 +---- drivers/iio/light/opt4060.c | 2 +- drivers/iio/light/rpr0521.c | 5 +---- drivers/iio/light/si1145.c | 4 +--- drivers/iio/light/st_uvis25_core.c | 5 +---- drivers/iio/light/stk3310.c | 5 +---- drivers/iio/light/tsl2563.c | 2 +- drivers/iio/light/tsl2772.c | 5 +---- drivers/iio/light/veml6030.c | 4 +--- drivers/iio/light/vl6180.c | 2 +- 19 files changed, 20 insertions(+), 55 deletions(-)
drivers/iio/light/adux1020.c +1 -3
@@ -808,10 +808,8 @@ static int adux1020_probe(struct i2c_client *client)NULL , adux1020_interrupt_handler,IRQF_TRIGGER_HIGH |IRQF_ONESHOT , ADUX1020_DRV_NAME, indio_dev); -if (ret) { -dev_err (&client->dev,"irq request error %d\n" , -ret); +if (ret)return ret; - } }return devm_iio_device_register (&client->dev, indio_dev);
drivers/iio/light/apds9160.c +2 -5
@@ -1545,11 +1545,8 @@ static int apds9160_probe(struct i2c_client *client) apds9160_irq_handler,IRQF_ONESHOT ,"apds9160_event" , indio_dev); -if (ret) { -return dev_err_probe (dev, ret, -"request irq (%d) failed\n" , - client->irq); - } +if (ret) +return ret; }else { indio_dev->info = &apds9160_info_no_events; indio_dev->channels = apds9160_channels_without_events;
drivers/iio/light/apds9300.c +1 -3
@@ -432,10 +432,8 @@ static int apds9300_probe(struct i2c_client *client)NULL , apds9300_interrupt_handler,IRQF_TRIGGER_FALLING |IRQF_ONESHOT , "apds9300_event", indio_dev); -if (ret) { -dev_err (&client->dev,"irq request error %d\n" , -ret); +if (ret) goto err; - } } ret =iio_device_register (indio_dev);
drivers/iio/light/apds9306.c +1 -2
@@ -1286,8 +1286,7 @@ static int apds9306_probe(struct i2c_client *client) apds9306_irq_handler,IRQF_ONESHOT , "apds9306_event", indio_dev);if (ret) -return dev_err_probe (dev, ret, -"failed to assign interrupt.\n" ); +return ret; }else { indio_dev->info = &apds9306_info_no_events; indio_dev->channels = apds9306_channels_without_events;
drivers/iio/light/apds9960.c +1 -3
@@ -1098,10 +1098,8 @@ static int apds9960_probe(struct i2c_client *client)IRQF_TRIGGER_FALLING |IRQF_ONESHOT ,"apds9960_event" , indio_dev); -if (ret) { -dev_err (&client->dev,"request irq (%d) failed\n" , client->irq); +if (ret) goto error_power_down; - } ret =iio_device_register (indio_dev);if (ret)
drivers/iio/light/bh1745.c +1 -2
@@ -784,8 +784,7 @@ static int bh1745_setup_triggered_buffer(struct iio_dev *indio_dev,IRQF_ONESHOT , "bh1745_interrupt", indio_dev);if (ret) -return dev_err_probe (dev, ret, -"Request for IRQ failed\n" ); +return ret; }return 0 ;
drivers/iio/light/cm3605.c +1 -3
@@ -233,10 +233,8 @@ static int cm3605_probe(struct platform_device *pdev) ret =devm_request_threaded_irq (dev, irq, cm3605_prox_irq,NULL ,0 ,"cm3605" , indio_dev); -if (ret) { -dev_err (dev,"unable to request IRQ\n" ); +if (ret) goto out_disable_aset; - }/* Just name the trigger the same as the driver */ led_trigger_register_simple ("cm3605" , &cm3605->led);
drivers/iio/light/gp2ap002.c +1 -3
@@ -580,10 +580,8 @@ static int gp2ap002_probe(struct i2c_client *client) ret =devm_request_threaded_irq (dev, client->irq,NULL , gp2ap002_prox_irq,IRQF_ONESHOT ,"gp2ap002" , indio_dev); -if (ret) { -dev_err (dev,"unable to request IRQ\n" ); +if (ret) goto out_put_pm; - } gp2ap002->irq = client->irq;/*
drivers/iio/light/ltr390.c +1 -2
@@ -838,8 +838,7 @@ static int ltr390_probe(struct i2c_client *client)"ltr390_thresh_event" , indio_dev);if (ret) -return dev_err_probe (dev, ret, -"request irq (%d) failed\n" , client->irq); +return ret; } ret =ltr390_pm_init (data);
drivers/iio/light/ltr501.c +1 -4
@@ -1538,11 +1538,8 @@ static int ltr501_probe(struct i2c_client *client)IRQF_ONESHOT ,"ltr501_thresh_event" , indio_dev); -if (ret) { -dev_err (&client->dev,"request irq (%d) failed\n" , - client->irq); +if (ret)return ret; - } }else { indio_dev->info = data->chip_info->info_no_irq; }
drivers/iio/light/opt4060.c +1 -1
@@ -1223,7 +1223,7 @@ static int opt4060_setup_trigger(struct opt4060_chip *chip, struct iio_dev *idevIRQF_TRIGGER_FALLING |IRQF_ONESHOT , name, idev);if (ret) -return dev_err_probe (chip->dev, ret,"Could not request IRQ\n" ); +return ret;init_completion (&chip->completion);
drivers/iio/light/rpr0521.c +1 -4
@@ -988,11 +988,8 @@ static int rpr0521_probe(struct i2c_client *client) rpr0521_drdy_irq_handler, rpr0521_drdy_irq_thread,IRQF_TRIGGER_FALLING |IRQF_ONESHOT , "rpr0521_event", indio_dev); -if (ret <0 ) { -dev_err (&client->dev,"request irq %d for trigger0 failed\n" , - client->irq); +if (ret) goto err_pm_disable; - } ret =devm_iio_trigger_register (indio_dev->dev.parent, data->drdy_trigger0);
drivers/iio/light/si1145.c +1 -3
@@ -1251,10 +1251,8 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)IRQF_TRIGGER_FALLING |IRQF_NO_THREAD ,"si1145_irq" , trig); -if (ret <0 ) { -dev_err (&client->dev,"irq request failed\n" ); +if (ret)return ret; - } ret =devm_iio_trigger_register (&client->dev, trig);if (ret)
drivers/iio/light/st_uvis25_core.c +1 -4
@@ -196,11 +196,8 @@ static int st_uvis25_allocate_trigger(struct iio_dev *iio_dev) st_uvis25_trigger_handler_thread, irq_type |IRQF_ONESHOT , iio_dev->name, hw); -if (err) { -dev_err (dev,"failed to request trigger irq %d\n" , - hw->irq); +if (err)return err; - } hw->trig =devm_iio_trigger_alloc (dev,"%s-trigger" , iio_dev->name);
drivers/iio/light/stk3310.c +1 -4
@@ -661,11 +661,8 @@ static int stk3310_probe(struct i2c_client *client)IRQF_TRIGGER_FALLING |IRQF_ONESHOT , "stk3310_event", indio_dev); -if (ret <0 ) { -dev_err (&client->dev,"request irq %d failed\n" , - client->irq); +if (ret) goto err_standby; - } } ret =iio_device_register (indio_dev);
drivers/iio/light/tsl2563.c +1 -1
@@ -755,7 +755,7 @@ static int tsl2563_probe(struct i2c_client *client)"tsl2563_event" , indio_dev);if (err) -return dev_err_probe (dev, err,"irq request error\n" ); +return err; } err =tsl2563_configure (chip);
drivers/iio/light/tsl2772.c +1 -4
@@ -1837,11 +1837,8 @@ static int tsl2772_probe(struct i2c_client *clientp)IRQF_ONESHOT ,"TSL2772_event" , indio_dev); -if (ret) { -dev_err (&clientp->dev, -"%s: irq request failed\n" , __func__); +if (ret)return ret; - } }else { indio_dev->channels = chip->chip_info->channel_without_events; }
drivers/iio/light/veml6030.c +1 -3
@@ -925,9 +925,7 @@ static int veml6030_set_info(struct iio_dev *indio_dev)IRQF_TRIGGER_LOW |IRQF_ONESHOT , indio_dev->name, indio_dev);if (ret <0 ) -return dev_err_probe (&client->dev, ret, -"irq %d request failed\n" , - client->irq); +return ret; indio_dev->info = &veml6030_info; }else {
drivers/iio/light/vl6180.c +1 -1
@@ -722,7 +722,7 @@ static int vl6180_probe(struct i2c_client *client)IRQF_ONESHOT , indio_dev->name, indio_dev);if (ret) -return dev_err_probe (&client->dev, ret,"devm_request_irq error\n" ); +return ret;init_completion (&data->completion);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 519/686 iio: light: ltr501: Power down chip if request irq fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Esben Haabendal <[email protected]>
[ Upstream commit 8a9bcd587d7d768e6c8e9fff88bb89645e412731 ]
In case devm_request_threaded_irq() failed, we were leaving the chip powered instead of powering it down again. Power down the chip switching ALS and PS modes to standby.
--- drivers/iio/light/ltr501.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/ltr501.c +1 -1
@@ -1539,7 +1539,7 @@ static int ltr501_probe(struct i2c_client *client)"ltr501_thresh_event" , indio_dev);if (ret) -return ret; + goto powerdown_on_error; }else { indio_dev->info = data->chip_info->info_no_irq; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 520/686 media: redrat3: Error path leaves device in transmitting state
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit 8024d5e84531d828535365718278f1cf0ce67db0 ]
In the allocation failure error path, the transmitting boolean is not cleared. If this error path is followed the transmitter cannot be used again until the device is replugged or the module reloaded.
Fix the error path by moving the assignment statement.
Remove the check for the transmitting state in transmit, since rc-core ensures there is never a reentrant call to the driver transmit function; the transmit function is always called with dev->lock held.
The transmitting boolean is only used for interpretting firmware errors.
--- drivers/media/rc/redrat3.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/media/rc/redrat3.c +3 -8
@@ -773,17 +773,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,u8 curlencheck =0 ;unsigned i, sendbuf_len; -if (rr3->transmitting) { -dev_warn (dev,"%s: transmitter already in use\n" , __func__); -return -EAGAIN ; - } -if (count >RR3_MAX_SIG_SIZE -RR3_TX_TRAILER_LEN )return -EINVAL ; -/* rr3 will disable rc detector on transmit */ - rr3->transmitting = true; - sample_lens =kcalloc (RR3_DRIVER_MAXLENS ,sizeof (*sample_lens),GFP_KERNEL );
@@ -796,6 +788,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, goto out; } +/* rr3 will disable rc detector on transmit */ + rr3->transmitting = true; +for (i =0 ; i < count; i++) { cur_sample_len =redrat3_us_to_len (txbuf[i]);if (cur_sample_len >0xffff ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 521/686 media: i2c: ov5647: fix power cleanup on remove
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 6e81cfc38548109021ab761b94ecdd01f8753154 ]
ov5647_remove() disables runtime PM without powering off the sensor if it is still runtime active. pm_runtime_disable() does not invoke the runtime suspend callback, so the sensor can remain powered on.
If the device is not already runtime suspended, call ov5647_power_off() and mark the runtime PM state as suspended.
This issue was found by manual code inspection.
--- drivers/media/i2c/ov5647.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/ov5647.c +4 -0
@@ -1480,6 +1480,10 @@ static void ov5647_remove(struct i2c_client *client)v4l2_ctrl_handler_free (&sensor->ctrls);v4l2_device_unregister_subdev (sd);pm_runtime_disable (&client->dev); +if (!pm_runtime_status_suspended (&client->dev)) { +ov5647_power_off (&client->dev); +pm_runtime_set_suspended (&client->dev); + }mutex_destroy (&sensor->lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 522/686 KVM: guest_memfd: Establish memslot<=>guest_memfd bindings *after* memslot is ready
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 3fe5d2944e5ac3fc5073344b0982c73703332e18 ]
Wait to bind a memslot to a guest_memfd instance until *after* the memslot is fully prepared, as creating the binding in guest_memfd will effectively expose the memslot to readers. As pointed out by Sashiko, binding the memslot before it's ready to be exposed to the rest of the world can break various memslot assumption and rules. E.g. x86 could observe a NULL rmap pointer if a PUNCH_HOLE hit the guest_memfd after the binding was created, but before KVM made it through kvm_prepare_memory_region().
--- virt/kvm/kvm_main.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
virt/kvm/kvm_main.c +19 -17
@@ -1955,6 +1955,15 @@ static int kvm_set_memslot(struct kvm *kvm,if (r) goto err; +if (change ==KVM_MR_CREATE && (new->flags &KVM_MEM_GUEST_MEMFD )) { + r =kvm_gmem_commit_memory_region (kvm, new); +if (r) { +kvm_arch_free_memslot (kvm, new); +kvm_destroy_dirty_bitmap (new); + goto err; + } + } +/* * For DELETE and MOVE, the working slot is now active as the INVALID * version of the old slot. MOVE is particularly special as it reuses
@@ -2132,32 +2141,25 @@ static int kvm_set_memory_region(struct kvm *kvm, mem->guest_memfd_offset);if (r) goto out; + } - r =kvm_gmem_commit_memory_region (kvm, new); + r =kvm_set_memslot (kvm, old, new, change); -/* -* Drop the reference to the file, even on success. The file -* pins KVM, not the other way 'round. Active bindings are -* invalidated if the file is closed before memslots are -* destroyed. -*/ +/* +* Drop the reference to the gmem file, even on success. The file pins +* KVM, not the other way 'round. Active bindings are invalidated if +* the file is closed before memslots are destroyed. +*/ #ifdef CONFIG_KVM_GUEST_MEMFD -fput (new->gmem.file); +if (change ==KVM_MR_CREATE && (mem->flags &KVM_MEM_GUEST_MEMFD )) +fput (new->gmem.file);#endif -if (r) - goto out; - } - - r =kvm_set_memslot (kvm, old, new, change);if (r) - goto out_unbind; + goto out;return 0 ; -out_unbind: -if (change ==KVM_MR_CREATE && (mem->flags &KVM_MEM_GUEST_MEMFD )) -kvm_gmem_unbind (new); out:kfree (new);return r;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 523/686 ublk: keep a canceled FETCH round canceling until the server is gone
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Lei <[email protected]>
[ Upstream commit 4c454b5b2634d982caf797fbe477770c3edfc983 ]
A cancel completes a fetched io command and sets io->cmd to NULL, but the io still counts as ready. Only ubq->canceling stops ublk_queue_rq() from using the NULL io->cmd. Two paths clear that flag too early:
partial FETCH round recovery, two queues
------------------- --------------------
task A: FETCH tags 0-2 q0 ready: q0->canceling = false
task A exits: q0 task exits:
start_cancel(): mark queues start_cancel(): ub->canceling
tags 0-2: io->cmd = NULL is still set -> q0 not marked
task B: FETCH tag 3 q0: io->cmd = NULL
queue ready: canceling = false q1 ready
START_DEV END_USER_RECOVERY
read -> ublk_queue_cmd(NULL) read on q0 -> ublk_queue_cmd(NULL)A FETCH round runs from the open of /dev/ublkcN until ublk_reset_ch_dev() resets the queues. A canceled command can't be fetched again in the same round. So the ready check only needs one
fact: did this round see a cancel? ub->canceling already records it:ublk_start_cancel() sets it under cancel_mutex before any command is taken. It is only cleared too early, when all queues are ready.
Fix:
- clear ub->canceling only in ublk_reset_ch_dev()
- when a queue gets ready, clear ubq->canceling only if ub->canceling is not set, and check it under cancel_mutex
The check and the marking are ordered by cancel_mutex:
check first: queue cleared -> start_cancel() marks it again
-> command taken
cancel first: check sees ub->canceling -> queue stays canceling
While ub->canceling is set, no queue clears its flag. So the "all queues marked" shortcut in ublk_start_cancel() is correct again.
UBLK_F_BATCH_IO follows the same rule. It does not dispatch through io->cmd, so it never hit the oops, but a round which lost a fetch command is treated the same way: it has to start over.
--- drivers/block/ublk_drv.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-)
drivers/block/ublk_drv.c +24 -7
@@ -233,6 +233,11 @@ struct ublk_device {u32 nr_io_ready;bool unprivileged_daemons;struct mutex cancel_mutex; +/* +* A cancel started in this FETCH round. Set by ublk_set_canceling(), +* cleared only by ublk_reset_ch_dev() when a new round starts. While +* it is set, no queue clears its ->canceling. +*/ bool canceling;pid_t ublksrv_tgid;struct delayed_work exit_work;
@@ -1637,6 +1642,11 @@ static void ublk_reset_ch_dev(struct ublk_device *ub)for (i =0 ; i < ub->dev_info.nr_hw_queues; i++)ublk_queue_reinit (ub,ublk_get_queue (ub, i)); +/* a new FETCH round starts, the queues stay canceling until ready */ +mutex_lock (&ub->cancel_mutex); + ub->canceling = false; +mutex_unlock (&ub->cancel_mutex); +/* set to NULL, otherwise new tasks cannot mmap io_cmd_buf */ ub->mm =NULL ; ub->nr_io_ready =0 ;
@@ -2152,8 +2162,15 @@ static void ublk_reset_io_flags(struct ublk_device *ub)for (i =0 ; i < ub->dev_info.nr_hw_queues; i++)ublk_get_queue (ub, i)->fail_io = false; +/* +* A cancel in this FETCH round took a command which still counts as +* ready, so the queues have to stay canceling. ub->canceling is set +* under cancel_mutex before any command is taken: either we see it +* here, or the cancel marks these queues again later. +*/ mutex_lock (&ub->cancel_mutex); -ublk_set_canceling (ub, false); +if (!ub->canceling) +ublk_set_canceling (ub, false);mutex_unlock (&ub->cancel_mutex); }
@@ -2173,9 +2190,8 @@ static void ublk_mark_io_ready(struct ublk_device *ub, struct ublk_queue *ubq, ub->nr_io_ready++;if (ublk_dev_ready (ub)) {/* -* now we are ready for handling ublk io request, clear -* device-level canceling flag and wake ublk_dev_ready() -* waiters +* Reset queue flags unless this round saw a cancel, and +* wake ublk_dev_ready() waiters. */ ublk_reset_io_flags (ub);wake_up_var (&ub->nr_io_ready);
@@ -2996,9 +3012,10 @@ static bool ublk_validate_user_pid(struct ublk_device *ub, pid_t ublksrv_pid)/* * Wait until all queues have fetched their I/O commands, and return with -* ub->mutex held and readiness guaranteed: then every queue's ->canceling -* is cleared. Ready may regress between wakeup and mutex_lock() (daemon -* death), so re-check it under the mutex and wait again. +* ub->mutex held and readiness guaranteed. The queues stay canceling if +* this round saw a cancel, see ublk_reset_io_flags(). Ready may regress +* between wakeup and mutex_lock() (daemon death), so re-check it under +* the mutex and wait again. */ static int ublk_wait_dev_ready_and_lock (struct ublk_device *ub) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 524/686 misc: fastrpc: Rename phys to dma_addr for clarity
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumari Pallavi <[email protected]>
[ Upstream commit 428b2f2b60c37f69e0723a225135da1f352d2602 ]
The fields buf->phys and map->phys currently store DMA addresses returned by dma_map_*() APIs, not physical addresses. This naming is misleading and may lead to incorrect assumptions about the address type and its translation.
Rename these fields from phys to dma_addr to improve code clarity and align with kernel conventions for dma_addr_t usage.
Stable-dep-of: 09fa66ec1b48 ("misc: fastrpc: fix double-free in fastrpc_map_attach() error path")
--- drivers/misc/fastrpc.c | 77 ++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 36 deletions(-)
drivers/misc/fastrpc.c +41 -36
@@ -106,7 +106,7 @@#define miscdev_to_fdevice (d) container_of(d, struct fastrpc_device, miscdev)struct fastrpc_phy_page { -u64 addr;/* physical address */ +dma_addr_t addr;/* dma address */ u64 size;/* size of contiguous region */ };
@@ -171,7 +171,7 @@ struct fastrpc_msg {u64 ctx;/* invoke caller context */ u32 handle;/* handle to invoke */ u32 sc;/* scalars structure describing the data */ -u64 addr;/* physical address */ +dma_addr_t addr;/* dma address */ u64 size;/* size of contiguous region */ };
@@ -194,7 +194,7 @@ struct fastrpc_buf {struct dma_buf *dmabuf;struct device *dev;void *virt; -u64 phys; +dma_addr_t dma_addr;u64 size;/* Lock for dma buf attachments */ struct mutex lock;
@@ -217,7 +217,7 @@ struct fastrpc_map {struct dma_buf *buf;struct sg_table *table;struct dma_buf_attachment *attach; -u64 phys; +dma_addr_t dma_addr;u64 size;void *va;u64 len;
@@ -322,11 +322,12 @@ static void fastrpc_free_map(struct kref *ref) perm.vmid =QCOM_SCM_VMID_HLOS ; perm.perm =QCOM_SCM_PERM_RWX ; - err =qcom_scm_assign_mem (map->phys, map->len, + err =qcom_scm_assign_mem (map->dma_addr, map->len, &src_perms, &perm,1 );if (err) { -dev_err (map->fl->sctx->dev,"Failed to assign memory phys 0x%llx size 0x%llx err %d\n" , - map->phys, map->len, err); +dev_err (map->fl->sctx->dev, +"Failed to assign memory dma_addr %pad size 0x%llx err %d\n" , + &map->dma_addr, map->len, err);return ; } }
@@ -397,7 +398,7 @@ static int fastrpc_map_lookup(struct fastrpc_user *fl, int fd,static void fastrpc_buf_free (struct fastrpc_buf *buf) {dma_free_coherent (buf->dev, buf->size, buf->virt, -FASTRPC_PHYS (buf->phys)); +FASTRPC_PHYS (buf->dma_addr));kfree (buf); }
@@ -416,12 +417,12 @@ static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, buf->fl = fl; buf->virt =NULL ; - buf->phys =0 ; + buf->dma_addr =0 ; buf->size = size; buf->dev = dev; buf->raddr =0 ; - buf->virt =dma_alloc_coherent (dev, buf->size, (dma_addr_t *)&buf->phys, + buf->virt =dma_alloc_coherent (dev, buf->size, &buf->dma_addr,GFP_KERNEL );if (!buf->virt) {mutex_destroy (&buf->lock);
@@ -447,7 +448,7 @@ static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, buf = *obuf;if (fl->sctx && fl->sctx->sid) - buf->phys += ((u64 )fl->sctx->sid <<32 ); + buf->dma_addr += ((u64 )fl->sctx->sid <<32 );return 0 ; }
@@ -740,7 +741,7 @@ static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf,return -ENOMEM ; ret =dma_get_sgtable (buffer->dev, &a->sgt, buffer->virt, -FASTRPC_PHYS (buffer->phys), buffer->size); +FASTRPC_PHYS (buffer->dma_addr), buffer->size);if (ret <0 ) {dev_err (buffer->dev,"failed to get scatterlist from DMA API\n" );kfree (a);
@@ -789,7 +790,7 @@ static int fastrpc_mmap(struct dma_buf *dmabuf,dma_resv_assert_held (dmabuf->resv);return dma_mmap_coherent (buf->dev, vma, buf->virt, -FASTRPC_PHYS (buf->phys), size); +FASTRPC_PHYS (buf->dma_addr), size); }static const struct dma_buf_ops fastrpc_dma_buf_ops = {
@@ -841,10 +842,10 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd, map->table = table;if (attr &FASTRPC_ATTR_SECUREMAP ) { - map->phys =sg_phys (map->table->sgl); + map->dma_addr =sg_phys (map->table->sgl); }else { - map->phys =sg_dma_address (map->table->sgl); - map->phys += ((u64 )fl->sctx->sid <<32 ); + map->dma_addr =sg_dma_address (map->table->sgl); + map->dma_addr += ((u64 )fl->sctx->sid <<32 ); }for_each_sg (map->table->sgl, sgl, map->table->nents, sgl_index)
@@ -871,10 +872,11 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd, dst_perms[1 ].vmid = fl->cctx->vmperms[0 ].vmid; dst_perms[1 ].perm =QCOM_SCM_PERM_RWX ; map->attr = attr; - err =qcom_scm_assign_mem (map->phys, (u64 )map->len, &src_perms, dst_perms,2 ); + err =qcom_scm_assign_mem (map->dma_addr, (u64 )map->len, &src_perms, dst_perms,2 );if (err) { -dev_err (sess->dev,"Failed to assign memory with phys 0x%llx size 0x%llx err %d\n" , - map->phys, map->len, err); +dev_err (sess->dev, +"Failed to assign memory with dma_addr %pad size 0x%llx err %d\n" , + &map->dma_addr, map->len, err); goto map_err; } }
@@ -1056,7 +1058,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)struct vm_area_struct *vma =NULL ; rpra[i].buf.pv = (u64 ) ctx->args[i].ptr; - pages[i].addr = ctx->maps[i]->phys; + pages[i].addr = ctx->maps[i]->dma_addr;mmap_read_lock (current->mm); vma =vma_lookup (current->mm, ctx->args[i].ptr);
@@ -1083,7 +1085,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) goto bail; rpra[i].buf.pv = args - ctx->olaps[oix].offset; - pages[i].addr = ctx->buf->phys - + pages[i].addr = ctx->buf->dma_addr - ctx->olaps[oix].offset + (pkt_size - rlen); pages[i].addr = pages[i].addr &PAGE_MASK ;
@@ -1115,7 +1117,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) list[i].num = ctx->args[i].length ?1 :0 ; list[i].pgidx = i;if (ctx->maps[i]) { - pages[i].addr = ctx->maps[i]->phys; + pages[i].addr = ctx->maps[i]->dma_addr; pages[i].size = ctx->maps[i]->size; } rpra[i].dma.fd = ctx->args[i].fd;
@@ -1197,7 +1199,7 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx, msg->ctx = ctx->ctxid | fl->pd; msg->handle = handle; msg->sc = ctx->sc; - msg->addr = ctx->buf ? ctx->buf->phys :0 ; + msg->addr = ctx->buf ? ctx->buf->dma_addr :0 ; msg->size =roundup (ctx->msg_sz,PAGE_SIZE );fastrpc_context_get (ctx);
@@ -1357,13 +1359,15 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,if (fl->cctx->vmcount) {u64 src_perms =BIT (QCOM_SCM_VMID_HLOS ); - err =qcom_scm_assign_mem (fl->cctx->remote_heap->phys, + err =qcom_scm_assign_mem (fl->cctx->remote_heap->dma_addr, (u64 )fl->cctx->remote_heap->size, &src_perms, fl->cctx->vmperms, fl->cctx->vmcount);if (err) { -dev_err (fl->sctx->dev,"Failed to assign memory with phys 0x%llx size 0x%llx err %d\n" , - fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); +dev_err (fl->sctx->dev, +"Failed to assign memory with dma_addr %pad size 0x%llx err %d\n" , + &fl->cctx->remote_heap->dma_addr, + fl->cctx->remote_heap->size, err); goto err_map; } scm_done = true;
@@ -1381,7 +1385,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, args[1 ].length = inbuf.namelen; args[1 ].fd =-1 ; - pages[0 ].addr = fl->cctx->remote_heap->phys; + pages[0 ].addr = fl->cctx->remote_heap->dma_addr; pages[0 ].size = fl->cctx->remote_heap->size; args[2 ].ptr = (u64 )(uintptr_t ) pages;
@@ -1410,12 +1414,12 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, dst_perms.vmid =QCOM_SCM_VMID_HLOS ; dst_perms.perm =QCOM_SCM_PERM_RWX ; - err =qcom_scm_assign_mem (fl->cctx->remote_heap->phys, + err =qcom_scm_assign_mem (fl->cctx->remote_heap->dma_addr, (u64 )fl->cctx->remote_heap->size, &src_perms, &dst_perms,1 );if (err) -dev_err (fl->sctx->dev,"Failed to assign memory phys 0x%llx size 0x%llx err %d\n" , - fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); +dev_err (fl->sctx->dev,"Failed to assign memory dma_addr %pad size 0x%llx err %d\n" , + &fl->cctx->remote_heap->dma_addr, fl->cctx->remote_heap->size, err); } err_map:fastrpc_buf_free (fl->cctx->remote_heap);
@@ -1505,7 +1509,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, args[2 ].length = inbuf.filelen; args[2 ].fd = init.filefd; - pages[0 ].addr = imem->phys; + pages[0 ].addr = imem->dma_addr; pages[0 ].size = imem->size; args[3 ].ptr = (u64 )(uintptr_t ) pages;
@@ -1945,7 +1949,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp) args[0 ].ptr = (u64) (uintptr_t) &req_msg; args[0 ].length =sizeof (req_msg); - pages.addr = buf->phys; + pages.addr = buf->dma_addr; pages.size = buf->size; args[1 ].ptr = (u64) (uintptr_t) &pages;
@@ -1973,11 +1977,12 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)if (req.flags ==ADSP_MMAP_REMOTE_HEAP_ADDR && fl->cctx->vmcount) {u64 src_perms =BIT (QCOM_SCM_VMID_HLOS ); - err =qcom_scm_assign_mem (buf->phys, (u64 )buf->size, + err =qcom_scm_assign_mem (buf->dma_addr, (u64 )buf->size, &src_perms, fl->cctx->vmperms, fl->cctx->vmcount);if (err) { -dev_err (fl->sctx->dev,"Failed to assign memory phys 0x%llx size 0x%llx err %d" , - buf->phys, buf->size, err); +dev_err (fl->sctx->dev, +"Failed to assign memory dma_addr %pad size 0x%llx err %d" , + &buf->dma_addr, buf->size, err); goto err_assign; } }
@@ -2091,7 +2096,7 @@ static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp) args[0 ].ptr = (u64) (uintptr_t) &req_msg; args[0 ].length =sizeof (req_msg); - pages.addr = map->phys; + pages.addr = map->dma_addr; pages.size = map->len; args[1 ].ptr = (u64) (uintptr_t) &pages;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 525/686 misc: fastrpc: fix double-free in fastrpc_map_attach() error path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifei Gao <[email protected]>
[ Upstream commit 09fa66ec1b4896ab841da085ca58b6433f28f07f ]
map->table is assigned right after dma_buf_map_attachment_unlocked() succeeds. The two failure checks that follow, the len > map->size test and, where subsystem VMIDs are configured, a failed qcom_scm_assign_mem(), jump to map_err with map->table already set.
map_err manually calls dma_buf_detach() and dma_buf_put() and then falls through to fastrpc_map_put(). Since that change the error path tail is fastrpc_map_put() -> fastrpc_free_map(), and fastrpc_free_map() already unmaps, detaches and puts the dma-buf whenever map->table is set. The two operations therefore run twice: the second dma_buf_put() drops an extra reference on map->buf, and dma_buf_unmap_attachment_unlocked() dereferences the map->attach already freed by the manual dma_buf_detach(). kref_init() sets the refcount to 1 with no intervening get, so the final fastrpc_map_put() frees the map synchronously and the redundant cleanup is deterministic.
The len > map->size branch is reachable by an unprivileged process via FASTRPC_IOCTL_MEM_MAP with an fd whose dma-buf is smaller than the requested length, before any DSP invocation.
Route both map->table-is-set failure branches to get_err instead of map_err, so fastrpc_free_map() is the single owner of the unmap/detach/put sequence. map_err is retained for the dma_buf_map_attachment_unlocked() failure, which is reached with map->table still NULL and an attachment that fastrpc_free_map() will not clean up, so its dma_buf_detach()/dma_buf_put() must still run manually.
--- drivers/misc/fastrpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/fastrpc.c +2 -2
@@ -854,7 +854,7 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd,dev_dbg (sess->dev,"Bad size passed len 0x%llx map size 0x%llx\n" , len, map->size); err = -EINVAL ; - goto map_err; + goto get_err; } map->va =sg_virt (map->table->sgl); map->len = len;
@@ -877,7 +877,7 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd,dev_err (sess->dev,"Failed to assign memory with dma_addr %pad size 0x%llx err %d\n" , &map->dma_addr, map->len, err); - goto map_err; + goto get_err; } }spin_lock (&fl->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 526/686 cxl/port: Cleanup handling of the nr_dports 0 -> 1 transition
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Williams <[email protected]>
[ Upstream commit 47fec713d97fb6b823026f723435b58af541bd8d ]
There are multiple setup actions that can occur for a switch port after it is known that it has at least one active downstream link. That work is currently split between __devm_cxl_add_dport(), the add_dport() helper, and cxl_port_add_dport() where decoder setup occurs.
Clean this up by moving all @dport object setup responsibilities into add_dport() and all port effects into cxl_port_add_dport().
add_dport() handles taking a reference on @dport->dport_dev, and cxl_port_add_dport() grows the awareness to setup the port component registers. This removes an awkward open-coded xa_erase() from the middle of __devm_cxl_add_dport() and instead tasks cxl_port_add_dport() with calling the common @dport destruction path if anything goes wrong.
After this @port->nr_dports is always the count of @dports in the @port->dports xarray, and cxl_dport_remove() is symmetric with add_dport(). With ->nr_dports now reliably tracking the number of dports the use of ida_is_empty() can be dropped. Recall that the ida is only cleared on "release" of decoder objects, and release can be arbitrarily delayed past unregistration.
Lastly port->component_reg_phys is no longer reset to CXL_RESOURCE_NONE post setup, no reason is seen to carry that forward.
Stable-dep-of: 019560d23450 ("cxl/port: Clear cached dport pointers when a dport is removed")
--- drivers/cxl/core/port.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
drivers/cxl/core/port.c +15 -16
@@ -1073,11 +1073,15 @@ static int add_dport(struct cxl_port *port, struct cxl_dport *dport)return -EBUSY ; } +/* Arrange for dport_dev to be valid through remove_dport() */ + struct device *dev __free(put_device) = get_device(dport->dport_dev); + rc =xa_insert (&port->dports, (unsigned long )dport->dport_dev, dport,GFP_KERNEL );if (rc)return rc; +retain_and_null_ptr (dev); port->nr_dports++;return 0 ; }
@@ -1106,6 +1110,7 @@ static void cxl_dport_remove(void *data)struct cxl_dport *dport = data;struct cxl_port *port = dport->port; + port->nr_dports--;xa_erase (&port->dports, (unsigned long ) dport->dport_dev);put_device (dport->dport_dev); }
@@ -1188,21 +1193,6 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,if (rc)return ERR_PTR (rc); -/* -* Setup port register if this is the first dport showed up. Having -* a dport also means that there is at least 1 active link. -*/ -if (port->nr_dports ==1 && - port->component_reg_phys !=CXL_RESOURCE_NONE ) { - rc =cxl_port_setup_regs (port, port->component_reg_phys); -if (rc) { -xa_erase (&port->dports, (unsigned long )dport->dport_dev); -return ERR_PTR (rc); - } - port->component_reg_phys =CXL_RESOURCE_NONE ; - } - -get_device (dport_dev); rc =devm_add_action_or_reset (host, cxl_dport_remove, dport);if (rc)return ERR_PTR (rc);
@@ -1629,7 +1619,16 @@ static struct cxl_dport *cxl_port_add_dport(struct cxl_port *port,cxl_switch_parse_cdat (new_dport); -if (ida_is_empty (&port->decoder_ida)) { +if (port->nr_dports ==1 ) { +/* +* Some host bridges are known to not have component regsisters +* available until a root port has trained CXL. Perform that +* setup now. +*/ + rc =cxl_port_setup_regs (port, port->component_reg_phys); +if (rc) +return ERR_PTR (rc); + rc =devm_cxl_switch_port_decoders_setup (port);if (rc)return ERR_PTR (rc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 527/686 cxl/port: Clear cached dport pointers when a dport is removed
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 019560d23450a320f4060ff235563a5277ea8033 ]
Switch decoders cache dport pointers in cxlsd->target[], and nothing clears them when a dport is freed. Readers then dereference freed memory.
KASAN caught it under a cxl_test load/unload loop with concurrent sysfs reads (abbreviated).
Clear the matching slots from cxl_dport_remove(), walking the port's decoders the way cxl_port_update_decoder_targets() does on the add side. Scan all nr_targets slots, the target[] allocation size, and clear every hit.
--- drivers/cxl/core/port.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/cxl/core/port.c +29 -0
@@ -1105,11 +1105,40 @@ static void cond_cxl_root_unlock(struct cxl_port *port)device_unlock (&port->dev); } +static int clear_decoder_target (struct device *dev,void *data) +{ +struct cxl_dport *dport = data; +struct cxl_switch_decoder *cxlsd; + +if (!is_switch_decoder (dev)) +return 0 ; + + cxlsd =to_cxl_switch_decoder (dev); +guard (rwsem_write)(&cxl_rwsem.region); + +/* +* A dport can occupy more than one position of an interleave, so +* scan the whole target list rather than stopping at the first hit. +*/ +for (int i =0 ; i < cxlsd->nr_targets; i++) { +if (cxlsd->target[i] != dport) +continue ; + cxlsd->target[i] =NULL ; +dev_dbg (dev,"dport%d removed from target list, index %d\n" , + dport->port_id, i); + } + +return 0 ; +} +static void cxl_dport_remove (void *data) {struct cxl_dport *dport = data;struct cxl_port *port = dport->port; +/* counterpart of cxl_port_update_decoder_targets() */ +device_for_each_child (&port->dev, dport, clear_decoder_target); + port->nr_dports--;xa_erase (&port->dports, (unsigned long ) dport->dport_dev);put_device (dport->dport_dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 528/686 KVM: arm64: Pin the host vCPU before adjusting its PC under pKVM
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit a2bb5f5c67a95ac97fcd6859dab51be421cf26fe ]
Under pKVM, a page the host shares with EL2 is mapped at EL2 only while it's pinned, and the host vCPU is pinned at its first KVM_RUN. KVM_SET_VCPU_EVENTS with ext_dabt_pending reaches __kvm_adjust_pc() at EL2 before that, and dereferencing the unmapped host vCPU panics the hypervisor. Any process holding /dev/kvm on a pKVM host can trigger it.
Pin the host vCPU around the adjustment when no hyp vCPU is loaded for it. A loaded hyp vCPU implies it's pinned. A pin fails only for memory the host isn't sharing, and the request is then dropped like any other bad host pointer.
--- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/hyp-main.c +27 -1
@@ -385,8 +385,34 @@ static void handle___pkvm_host_mkyoung_guest(struct kvm_cpu_context *host_ctxt)static void handle___kvm_adjust_pc (struct kvm_cpu_context *host_ctxt) { DECLARE_REG(struct kvm_vcpu *, vcpu, host_ctxt, 1); +struct pkvm_hyp_vcpu *hyp_vcpu; +struct kvm_vcpu *host_vcpu; + + host_vcpu =kern_hyp_va (vcpu); +if (unlikely (is_protected_kvm_enabled ())) { + hyp_vcpu =pkvm_get_loaded_hyp_vcpu (); + +if (!hyp_vcpu || hyp_vcpu->host_vcpu != host_vcpu) + host_vcpu =NULL ; + } + +if (host_vcpu) { +__kvm_adjust_pc (host_vcpu); +return ; + } + +/* +* With no hyp vCPU loaded for it, the host vCPU may be unpinned, +* and so unmapped at EL2: its first run pins it. A pin fails only +* for memory the host isn't sharing, a bad pointer, so the request +* is dropped. +*/ + host_vcpu =kern_hyp_va (vcpu); +if (hyp_pin_shared_mem (host_vcpu, host_vcpu +1 )) +return ; -__kvm_adjust_pc (kern_hyp_va (vcpu)); +__kvm_adjust_pc (host_vcpu); +hyp_unpin_shared_mem (host_vcpu, host_vcpu +1 ); }static void handle___kvm_flush_vm_context (struct kvm_cpu_context *host_ctxt)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 529/686 sctp: hold shkey across socket migration
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Lee <[email protected]>
[ Upstream commit ad1320865b1826ffa2e81e37c49535751e81335c ]
sctp_sock_migrate() transfers queued DATA skbs from the old socket to the new one. skb_orphan() invokes sctp_wfree() during that transfer and drops the skb-owned shared-key reference.
If userspace has removed that key from the association, this can be the final reference. The following sctp_set_owner_w() then dereferences the freed chunk->shkey while trying to take the new owner reference.
Take a temporary shared-key reference before orphaning the skb and release it after the new owner has taken its reference. This preserves the selected authentication key throughout the ownership transfer.
Bug found and triaged by OpenAI Security Research and validated by Trail of Bits.
Stable-dep-of: 52ffeaa358d1 ("sctp: re-point retained control chunks on association migration")
--- net/sctp/socket.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
net/sctp/socket.c +11 -1
@@ -148,9 +148,19 @@ static inline void sctp_set_owner_w(struct sctp_chunk *chunk)static void sctp_clear_owner_w (struct sctp_chunk *chunk) { +/* Keep the shkey alive until the new owner takes its reference. */ +if (chunk->shkey) +sctp_auth_shkey_hold (chunk->shkey);skb_orphan (chunk->skb); } +static void sctp_set_owner_w_migrate (struct sctp_chunk *chunk) +{ +sctp_set_owner_w (chunk); +if (chunk->shkey) +sctp_auth_shkey_release (chunk->shkey); +} +#define traverse_and_process () \ do { \ msg = chunk->msg; \
@@ -9669,7 +9679,7 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,lock_sock_nested (newsk,SINGLE_DEPTH_NESTING );sctp_for_each_tx_datachunk (assoc, true, sctp_clear_owner_w);sctp_assoc_migrate (assoc, newsk); -sctp_for_each_tx_datachunk (assoc, false, sctp_set_owner_w); +sctp_for_each_tx_datachunk (assoc, false, sctp_set_owner_w_migrate);/* If the association on the newsk is already closed before accept() * is called, set RCV_SHUTDOWN flag.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 530/686 sctp: re-point retained control chunks on association migration
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jun Yang <[email protected]>
[ Upstream commit 52ffeaa358d1f3d91aa87a26ad90d77769cff74b ]
sctp_sock_migrate() transfers DATA chunk ownership but leaves retained control chunks pointing at the old socket. A later retransmission can therefore access the socket after it has been freed.
Extend the migration walk to cover retained control chunks and use sctp_control_set_owner_w() to assign their new owner. Reuse the DATA ownership check so each chunk is processed once per pass, even when it is reachable through multiple lists or retained pointers.
Preserve a control chunk's existing authentication key across migration so its final release can still generate SCTP_AUTH_FREE_KEY when needed.
--- include/net/sctp/sm.h | 1 + net/sctp/sm_make_chunk.c | 5 ++-- net/sctp/socket.c | 53 ++++++++++++++++++++++++++++++---------- 3 files changed, 44 insertions(+), 15 deletions(-)
include/net/sctp/sm.h +1 -0
@@ -252,6 +252,7 @@ struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc, struct sctp_fwdtsn_skip *skiplist);struct sctp_chunk *sctp_make_auth (const struct sctp_association *asoc,__u16 key_id); +void sctp_control_set_owner_w (struct sctp_chunk *chunk);struct sctp_chunk *sctp_make_strreset_req (const struct sctp_association *asoc,__u16 stream_num,__be16 *stream_list,bool out,bool in);
net/sctp/sm_make_chunk.c +3 -2
@@ -94,7 +94,7 @@ static void sctp_control_release_owner(struct sk_buff *skb) } } -static void sctp_control_set_owner_w (struct sctp_chunk *chunk) +void sctp_control_set_owner_w (struct sctp_chunk *chunk) {struct sctp_association *asoc = chunk->asoc;struct sk_buff *skb = chunk->skb;
@@ -107,7 +107,8 @@ static void sctp_control_set_owner_w(struct sctp_chunk *chunk)* For now don't do anything for now. */ if (chunk->auth) { - chunk->shkey = asoc->shkey; +if (!chunk->shkey) + chunk->shkey = asoc->shkey;sctp_auth_shkey_hold (chunk->shkey); } skb->sk = asoc ? asoc->base.sk :NULL ;
net/sctp/socket.c +40 -13
81 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 531/686 bnxt_en: Refactor some basic ring setup and adjustment logic
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Chan <[email protected]>
[ Upstream commit ceee35e5674aa84cf9e504c2a9dae4587511556c ]
Refactor out the basic code that trims the default rings, sets up and adjusts XDP TX rings and CP rings. There is no change in behavior. This is to prepare for the next bug fix patch.
Stable-dep-of: 78731b46967e ("bnxt_en: don't leave an XDP program installed when the open fails")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 53 +++++++++++++------ drivers/net/ethernet/broadcom/bnxt/bnxt.h | 1 + .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 5 +- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 5 +- 4 files changed, 41 insertions(+), 23 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +37 -16
@@ -13000,6 +13000,21 @@ static int bnxt_tx_nr_rings_per_tc(struct bnxt *bp)return bp->num_tc ? bp->tx_nr_rings / bp->num_tc : bp->tx_nr_rings; } +static void bnxt_set_xdp_tx_rings (struct bnxt *bp) +{ + bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc; + bp->tx_nr_rings += bp->tx_nr_rings_xdp; +} + +static void bnxt_adj_tx_rings (struct bnxt *bp) +{ +/* Make adjustments if reserved TX rings are less than requested */ + bp->tx_nr_rings -= bp->tx_nr_rings_xdp; + bp->tx_nr_rings_per_tc =bnxt_tx_nr_rings_per_tc (bp); +if (bp->tx_nr_rings_xdp) +bnxt_set_xdp_tx_rings (bp); +} +static int __bnxt_open_nic (struct bnxt *bp,bool irq_re_init,bool link_re_init) {int rc =0 ;
@@ -13017,13 +13032,7 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)if (rc)return rc; -/* Make adjustments if reserved TX rings are less than requested */ - bp->tx_nr_rings -= bp->tx_nr_rings_xdp; - bp->tx_nr_rings_per_tc =bnxt_tx_nr_rings_per_tc (bp); -if (bp->tx_nr_rings_xdp) { - bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc; - bp->tx_nr_rings += bp->tx_nr_rings_xdp; - } +bnxt_adj_tx_rings (bp); rc =bnxt_alloc_mem (bp, irq_re_init);if (rc) {netdev_err (bp->dev,"bnxt_alloc_mem err: %x\n" , rc);
@@ -15515,11 +15524,19 @@ static int bnxt_change_mtu(struct net_device *dev, int new_mtu)return 0 ; } +void bnxt_set_cp_rings (struct bnxt *bp,bool sh) +{ +int tx_cp =bnxt_num_tx_to_cp (bp, bp->tx_nr_rings); + + bp->cp_nr_rings = sh ?max_t (int, tx_cp, bp->rx_nr_rings) : + tx_cp + bp->rx_nr_rings; +} +int bnxt_setup_mq_tc (struct net_device *dev,u8 tc) {struct bnxt *bp =netdev_priv (dev);bool sh = false; -int rc, tx_cp; +int rc;if (tc > bp->max_tc) { netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
@@ -15552,9 +15569,7 @@ int bnxt_setup_mq_tc(struct net_device *dev, u8 tc) bp->num_tc =0 ; } bp->tx_nr_rings += bp->tx_nr_rings_xdp; - tx_cp =bnxt_num_tx_to_cp (bp, bp->tx_nr_rings); - bp->cp_nr_rings = sh ?max_t (int, tx_cp, bp->rx_nr_rings) : - tx_cp + bp->rx_nr_rings; +bnxt_set_cp_rings (bp, sh);if (netif_running (bp->dev))return bnxt_open_nic (bp, true, false);
@@ -16616,6 +16631,15 @@ static void bnxt_trim_dflt_sh_rings(struct bnxt *bp) bp->tx_nr_rings =bnxt_tx_nr_rings (bp); } +static void bnxt_adj_dflt_rings (struct bnxt *bp,bool sh) +{ +if (sh) +bnxt_trim_dflt_sh_rings (bp); +else + bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings; + bp->tx_nr_rings =bnxt_tx_nr_rings (bp); +} +static int bnxt_set_dflt_rings (struct bnxt *bp,bool sh) {int dflt_rings, max_rx_rings, max_tx_rings, rc;
@@ -16641,11 +16665,8 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)return rc; bp->rx_nr_rings =min_t (int, dflt_rings, max_rx_rings); bp->tx_nr_rings_per_tc =min_t (int, dflt_rings, max_tx_rings); -if (sh) -bnxt_trim_dflt_sh_rings (bp); -else - bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings; - bp->tx_nr_rings =bnxt_tx_nr_rings (bp); + +bnxt_adj_dflt_rings (bp, sh); avail_msix =bnxt_get_max_func_irqs (bp) - bp->cp_nr_rings;if (avail_msix >=BNXT_MIN_ROCE_CP_RINGS ) {
drivers/net/ethernet/broadcom/bnxt/bnxt.h +1 -0
@@ -2987,6 +2987,7 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, int tx_xdp);int bnxt_fw_init_one (struct bnxt *bp);bool bnxt_hwrm_reset_permitted (struct bnxt *bp); +void bnxt_set_cp_rings (struct bnxt *bp,bool sh);int bnxt_setup_mq_tc (struct net_device *dev,u8 tc);struct bnxt_ntuple_filter *bnxt_lookup_ntp_filter_from_idx (struct bnxt *bp,struct bnxt_ntuple_filter *fltr,u32 idx);
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +1 -4
@@ -940,7 +940,6 @@ static int bnxt_set_channels(struct net_device *dev,bool sh = false;int tx_xdp =0 ;int rc =0 ; -int tx_cp;if (channel->other_count)return -EINVAL ;
@@ -1008,9 +1007,7 @@ static int bnxt_set_channels(struct net_device *dev,if (tcs >1 ) bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp; - tx_cp =bnxt_num_tx_to_cp (bp, bp->tx_nr_rings); - bp->cp_nr_rings = sh ?max_t (int, tx_cp, bp->rx_nr_rings) : - tx_cp + bp->rx_nr_rings; +bnxt_set_cp_rings (bp, sh);/* After changing number of rx channels, update NTUPLE feature. */ netdev_update_features (dev);
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +2 -3
@@ -384,7 +384,7 @@ int bnxt_xdp_xmit(struct net_device *dev, int num_frames,static int bnxt_xdp_set (struct bnxt *bp,struct bpf_prog *prog) {struct net_device *dev = bp->dev; -int tx_xdp =0 , tx_cp, rc, tc; +int tx_xdp =0 , rc, tc;struct bpf_prog *old;netdev_assert_locked (dev);
@@ -431,8 +431,7 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog) } bp->tx_nr_rings_xdp = tx_xdp; bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc + tx_xdp; - tx_cp =bnxt_num_tx_to_cp (bp, bp->tx_nr_rings); - bp->cp_nr_rings =max_t (int, tx_cp, bp->rx_nr_rings); +bnxt_set_cp_rings (bp, true);bnxt_set_tpa_flags (bp);bnxt_set_ring_params (bp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 532/686 bnxt_en: dont leave an XDP program installed when the open fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vaibhav Nagare <[email protected]>
[ Upstream commit 78731b46967e3e7102b5cd5062bef185f3404b5c ]
bnxt_xdp_set() stores the new program and drops the reference on the old one before reopening the NIC. If bnxt_open_nic() then fails, ndo_bpf() returns an error with the new program still in bp->xdp_prog. The caller treats the error as "nothing was installed" and drops its own reference, so bp->xdp_prog is left pointing at a freed program and the next XDP update dereferences it:
BUG: unable to handle page fault for address: ff78ecc80ddd1038 RIP: 0010:__bpf_prog_put+0x5/0x80 Call Trace: bnxt_xdp_set+0xad/0x1b0 [bnxt_en] dev_xdp_propagate+0x36/0xa0 bond_xdp_set+0xeb/0x2d0 [bonding] dev_xdp_install+0x1b1/0x350 bpf_xdp_link_update+0xc5/0x1b0 link_update+0x104/0x1e0 __sys_bpf+0x662/0xcf0
Seen on a 6.12 based kernel after bnxt_alloc_mem() failed an order-4 allocation on a fragmented host:
bnxt_en 0000:a0:00.1 ens4f1np1: nic open fail (rc: fffffff4)
bond1: (slave ens4f1np1): Error -12 calling ndo_bpf
Bonding is not required to hit this; a plain XDP attach on a bnxt interface takes the same path.
Restore the previous program when an attach or a replace fails, and recompute the page-mode and XDP TX ring configuration from it. The configuration matters because bnxt_init_one_rx_ring() only assigns rxr->xdp_prog in page mode, and __bnxt_set_rx_skb_mode() derives dev->max_mtu from the installed program. Release the old program only once the change has been committed.
A detach is not undone. dev_xdp_detach_link() clears the core's record of the program even when the driver returns an error, so putting the program back would leave the driver running a program the core has already dropped. If the reopen fails during a detach, bnxt_xdp_set() therefore returns 0 with the device closed; bnxt_open_nic() has already logged the failure.
Found in a crash dump; the change was not tested on hardware.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +33 -16
@@ -381,11 +381,31 @@ int bnxt_xdp_xmit(struct net_device *dev, int num_frames,return nxmit; } +static void bnxt_xdp_apply_cfg (struct bnxt *bp,int tx_xdp) +{ +struct net_device *dev = bp->dev; +int tc = bp->num_tc ? :1 ; + +if (bp->xdp_prog) { +bnxt_set_rx_skb_mode (bp, true); +xdp_features_set_redirect_target_locked (dev, true); + }else { +xdp_features_clear_redirect_target_locked (dev); +bnxt_set_rx_skb_mode (bp, false); + } + bp->tx_nr_rings_xdp = tx_xdp; + bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc + tx_xdp; +bnxt_set_cp_rings (bp, true); +bnxt_set_tpa_flags (bp); +bnxt_set_ring_params (bp); +} +static int bnxt_xdp_set (struct bnxt *bp,struct bpf_prog *prog) {struct net_device *dev = bp->dev;int tx_xdp =0 , rc, tc;struct bpf_prog *old; +int old_tx_xdp;netdev_assert_locked (dev);
@@ -418,25 +438,22 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)if (netif_running (dev))bnxt_close_nic (bp, true, false); + old_tx_xdp = bp->tx_nr_rings_xdp; old =xchg (&bp->xdp_prog, prog); -if (old) -bpf_prog_put (old); - -if (prog) { -bnxt_set_rx_skb_mode (bp, true); -xdp_features_set_redirect_target_locked (dev, true); - }else { -xdp_features_clear_redirect_target_locked (dev); -bnxt_set_rx_skb_mode (bp, false); +bnxt_xdp_apply_cfg (bp, tx_xdp); + +if (netif_running (dev)) { + rc =bnxt_open_nic (bp, true, false); +/* a detach cannot be undone, only an attach */ +if (rc && prog) { +WRITE_ONCE (bp->xdp_prog, old); +bnxt_xdp_apply_cfg (bp, old_tx_xdp); +return rc; + } } - bp->tx_nr_rings_xdp = tx_xdp; - bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc + tx_xdp; -bnxt_set_cp_rings (bp, true); -bnxt_set_tpa_flags (bp); -bnxt_set_ring_params (bp); -if (netif_running (dev)) -return bnxt_open_nic (bp, true, false); +if (old) +bpf_prog_put (old);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 533/686 fs/ntfs3: validate the EA value length in ntfs_read_ea()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuejie Shi <[email protected]>
[ Upstream commit 351817226fbf0031c4c63d1f5d7f15c3172312eb ]
ntfs_read_ea() checks the $EA list for consistency, but it only recomputes the packed size of an entry when the entry's own size field is zero:
for (off = 0; off < size; off += ea_size) {
const struct EA_FULL *ef = Add2Ptr(ea_p, off);
u32 bytes = size - off;
...
if (ef->size) {
ea_size = le32_to_cpu(ef->size);
if (ea_size > bytes)
goto out1;
continue; /* <- elength never checked */
}
...
ea_size = ALIGN(struct_size(ef, name,
1 + ef->name_len +
le16_to_cpu(ef->elength)),
4);
if (ea_size > bytes)
goto out1;
}ef->size is non-zero for every entry except the last one, and it is what ntfs3 itself writes (ntfs_set_ea() stores exactly that aligned packed size), so in practice elength is not validated at all. find_ea() then uses unpacked_ea_size(), which also prefers ea->size when it is set, so it agrees and hands the entry back.
ntfs_get_ea() copies elength bytes with no further bound of its own:
len = le16_to_cpu(ea->elength);
...
if (len > size) { /* size is the *caller's* buffer */
err = -ERANGE;
...
}
memcpy(buffer, ea->name + ea->name_len + 1, len);so a caller that supplies a large enough buffer receives up to 64 KiB of whatever follows the small $EA allocation -- straight to userspace via getxattr(2).
Compute the packed size unconditionally and require it to fit in the entry. Hoist the "bytes < offsetof(struct EA_FULL, name)" test above the ef->size branch as well: name_len and elength were being read there without it, which is itself a small over-read of the kmalloc'd buffer when fewer than 8 bytes are left. The old "bytes < sizeof(ef->size)" test is subsumed by it.
# mkntfs image; create /mnt/ntfs/poc with user.ntfs6 set, then rewrite
# that EA_FULL's elength from 0xf to 0xff00 on the raw device
mount -t ntfs3 -o ro /dev/vda /mnt/ntfs
getxattr("/mnt/ntfs/poc", "user.ntfs6", buf, 128 * 1024);BUG: KASAN: slab-out-of-bounds in ntfs_get_ea+0x294/0x3e0 Read of size 65280 at addr ffff0000cca53acf by task xattr_probe/142 __asan_memcpy+0x3c/0xa0 ntfs_get_ea+0x294/0x3e0 ntfs_getxattr+0x284/0x318 __vfs_getxattr+0x104/0x160 vfs_getxattr+0x1b4/0x1e0 do_getxattr+0xcc/0x230 path_getxattrat+0x184/0x270 __arm64_sys_getxattr+0x64/0x80 Allocated by task 142: __kmalloc_noprof+0x294/0x668 ntfs_read_ea+0x1e4/0x420 ntfs_get_ea+0x2c8/0x3e0 The buggy address belongs to the object at ffff0000cca53a80 which belongs to the cache kmalloc-96 of size 96
The object being over-read is the one ntfs_read_ea() just allocated, and it is 96 bytes.
Entries written by ntfs3 and by Windows set size to the aligned packed size, so the new test does not reject anything a working filesystem produces.
--- fs/ntfs3/xattr.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
fs/ntfs3/xattr.c +14 -11
@@ -146,29 +146,32 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea,for (off =0 ; off < size; off += ea_size) {const struct EA_FULL *ef =Add2Ptr (ea_p, off);u32 bytes = size - off; -size_t need; - -/* Check if we can use field ea->size. */ -if (bytes <sizeof (ef->size)) - goto out1; +u32 packed_size;/* Check if we can use fields ef->name_len and ef->elength. */ if (bytes < offsetof(struct EA_FULL , name)) goto out1; -/* Size needed to hold this record's name and value. */ - need =struct_size (ef, name, -1 + ef->name_len +le16_to_cpu (ef->elength)); +/* +* The name and the value have to fit in the entry whether or +* not ef->size is set, because ntfs_get_ea() copies elength +* bytes out of this buffer and checks them only against the +* caller supplied buffer size. +*/ + packed_size = +ALIGN (struct_size (ef, name, +1 + ef->name_len + +le16_to_cpu (ef->elength)), +4 );if (ef->size) { ea_size =le32_to_cpu (ef->size); -/* ef->size must fit the list and cover the record. */ -if (ea_size > bytes || ea_size < need) +if (ea_size > bytes || packed_size > ea_size) goto out1;continue ; } - ea_size =ALIGN (need,4 ); + ea_size = packed_size;if (ea_size > bytes) goto out1; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 534/686 mm/hugetlb: unmap the page where the other VMA maps it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit ae99c503eb362b42cd5d24d80bc6cba669acc4c2 ]
If the owner of a MAP_PRIVATE hugetlb mapping fails to allocate a page for CoW, unmap_ref_private() unmaps the old page from all other private VMAs that have no reservation of their own. It finds them by the offset in the file, but then zaps each of them at the address of the faulting VMA. Nothing says that another VMA maps the offset at that address: a child can have moved its copy of the VMA with mremap(), and a second mapping of the file is wherever mmap() has put it.
So __unmap_hugepage_range() walks the page tables of the other mm at an address outside of iter_vma, where i_mmap_rwsem of this file protects nothing and where anything can be mapped, and the page stays mapped where it really is.
All of the following was seen on v7.3-rc6+ (g6c377d19d4a5) in KVM guests, as a user without any privilege. It takes a pool of 2 MiB pages with no free page that is not reserved, so that the allocation fails: the user can take or reserve what is free itself.
- The child moves its VMA away. The page is never unmapped, the mapcount stays 2, and the owner goes round retry_avoidcopy in hugetlb_wp() until the child is gone or a page becomes free. SIGKILL to the owner does not end it. 5 of 5 runs.
- The owner's mm has a second private mapping of the offset, made with MAP_NORESERVE. The owner zaps its own entry and reads zeroes where its data was. 5 of 5 runs.
- The child moves its VMA away and maps a 1 GiB hugetlb page at the old address, so this one takes a pool with a 1 GiB page as well. huge_pte_offset() for the 2 MiB size steps through the PUD leaf, so the "PMD table" is the 1 GiB page itself and its "page table lock" is folio->private of that page, which holds 2. Kernels with lock debugging oops in __unmap_hugepage_range(), 7 of 7 runs. Others spin on that word for ever with preemption disabled, 5 of 5 runs:
watchdog: BUG: soft lockup - CPU#0 stuck for 26s! [u_det3:130]
RIP: 0010:queued_spin_lock_slowpath+0x8a/0x290
RAX: 0000000000000002 RBX: ffffea0001000028
Call Trace:
__unmap_hugepage_range+0x154/0x6d0
unmap_hugepage_range+0xc1/0x140
hugetlb_wp+0x55c/0x700
hugetlb_fault+0x5f3/0x8f0RCU stalls follow, and killing all tasks of the user changes nothing. Four such owners, whose children share a single 1 GiB page, took down the whole guest with its four CPUs, 2 of 2 runs: one reported soft lockups on all four, the other gave no sign of life any more.
i_mmap_rwsem stays write locked. With a MAP_PRIVATE mapping of a hugetlbfs file that belongs to another user, and that the attacker can only read, the next mmap() of that file by its owner sleeps uninterruptibly in __mmap_region(), 4 of 4 runs.
Compute the address from the offset for each VMA. The tree walk returns only VMAs that cover pgoff, and vm_start, vm_end and vm_pgoff of a hugetlb VMA are aligned to the huge page size, as pgoff is, so the whole range lies inside iter_vma. Its page tables can not go away there, since the VMA is unlinked from the file under i_mmap_rwsem first.
With the right address the page is unmapped from all VMAs but the owner's, so the retry in hugetlb_wp() finds a mapcount of 1 and reuses the page.
A child that has moved its copy of the VMA now loses the page, and gets SIGBUS when it faults on a missing page of that VMA. That is what the comment above the function has always promised to those who do not own the reservation, and what already happens to a child that has left the VMA in place.
The address has been wrong from the start, and the second case needs only mmap() and fork(). mremap() of hugetlb VMAs, which the other cases use, came with commit 550a7d60bd5e ("mm, hugepages: add mremap() support for hugepage backed vma") in v5.16.
Original fix generated by an LLM and sent in private by Josef.
--- mm/hugetlb.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
mm/hugetlb.c +13 -4
@@ -6155,6 +6155,8 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,struct address_space *mapping;pgoff_t pgoff; +VM_WARN_ON_ONCE (!folio_test_anon (folio)); +/* * vm_pgoff is in PAGE_SIZE units, hence the different calculation * from page cache lookup which is in HPAGE_SIZE units.
@@ -6190,10 +6192,17 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,* could insert a zeroed page instead of the data existing * from the time of fork. This would look like data corruption */ -if (!is_vma_resv_set (iter_vma,HPAGE_RESV_OWNER )) -unmap_hugepage_range (iter_vma, address, - address +huge_page_size (h), - folio,0 ); +if (is_vma_resv_set (iter_vma,HPAGE_RESV_OWNER )) +continue ; + +/* +* The address in other VMAs can differ. Even though our old +* folio is anon, we always operate on the underlying hugetlb +* file. +*/ + address =vma_address (iter_vma, pgoff,1 ); +unmap_hugepage_range (iter_vma, address, + address +huge_page_size (h), folio,0 ); }i_mmap_unlock_write (mapping); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 535/686 mm/userfaultfd: only allocate anon_vma in CoW mappings
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 514c9247db305922591d806ec65d3c3fe420538d ]
find_vma_and_prepare_anon() can end up allocating an anon_vma in VMAs that are not CoW mappings, which is wrong.
If we have a MAP_SHARED R/O file mapped, we lack VM_SHARED (but do have VM_MAYSHARE) and lack VM_MAYWRITE.
While uffd later rejects such mappings (uffd registration requires VM_MAYWRITE, see comment in validate_dst_vma) find_vma_and_prepare_anon() still wrongly allocates an anon vma before it validates the vma.
This in turn later confuses copy_page_range()->vma_needs_copy() such that we end up calling copy_hugetlb_page_range() with ranges that actually do not contain *any* per-pagetable information that would require copying, which is the basis for PMD-table sharing in the first place.
copy_hugetlb_page_range() should not have to worry about shared PMD tables at all: it doesn't make any sense to copy page tables that are shared, as they can be fully recreated later. Ending up in the function with shareable page tables is the real issue.
If a destination PMD table is shared in copy_hugetlb_page_range(), it might get concurrently unshared as we are not holding relevant locks, resulting in us using a page table that is no longer mapped and possibly freed after calling:
dst_pte = huge_pte_alloc(dst, dst_vma, addr, sz);
To fix it, do not allocate an anon_vma in non-CoW mappings and add a safety guard to copy_hugetlb_page_range(), making sure that we never end up messing with shared PMD tables in there.
Before commit 867a43a34ff8a ("userfaultfd: use per-vma locks in userfaultfd operations") we would always validate the VMA before allocating an anon_vma, and consequently never wrongly allocate an anon_vma.
As uffd_lock_vma() is part of the same lookup machinery and also contains a misleading VM_SHARED check, change that one as well directly for consistency.
A follow-up cleanup will stop taking the hugetlb_vma_lock_read(src_vma) lock in copy_hugetlb_page_range() entirely. Further, the usage of VM_SHARED in userfaultfd code should be cleaned up later to focus on CoW vs. non-CoW mappings.
--- mm/hugetlb.c | 24 ++++++++++++------------ mm/userfaultfd.c | 5 ++--- 2 files changed, 14 insertions(+), 15 deletions(-)
mm/hugetlb.c +12 -12
@@ -5629,10 +5629,11 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,raw_write_seqcount_begin (&src->write_protect_seq); }else {/* -* For shared mappings the vma lock must be held before -* calling hugetlb_walk() in the src vma. Otherwise, the -* returned ptep could go away if part of a shared pmd and -* another thread calls huge_pmd_unshare. +* Shared mappings only need copying when we could have +* information stored in page tables (e.g., userfaultfd PTE +* bits or markers), which is incompatible with PMD sharing. +* Still take the hugetlb VMA lock for now to satisfy +* hugetlb_walk()'s locking requirements. */ hugetlb_vma_lock_read (src_vma); }
@@ -5640,6 +5641,13 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, last_addr_mask =hugetlb_mask_last_page (h);for (addr = src_vma->vm_start; addr < src_vma->vm_end; addr += sz) {spinlock_t *src_ptl, *dst_ptl; + +if (WARN_ON_ONCE (want_pmd_share (src_vma, addr) || +want_pmd_share (dst_vma, addr))) { + ret = -EINVAL ; +break ; + } + src_pte =hugetlb_walk (src_vma, addr, sz);if (!src_pte) { addr |= last_addr_mask;
@@ -5651,14 +5659,6 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,break ; } -#ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING -/* If the pagetables are shared, there is nothing to do */ -if (ptdesc_pmd_is_shared (virt_to_ptdesc (dst_pte))) { - addr |= last_addr_mask; -continue ; - } -#endif - dst_ptl =huge_pte_lock (h, dst, dst_pte); src_ptl =huge_pte_lockptr (h, src, src_pte);spin_lock_nested (src_ptl,SINGLE_DEPTH_NESTING );
mm/userfaultfd.c +2 -3
@@ -48,8 +48,7 @@ struct vm_area_struct *find_vma_and_prepare_anon(struct mm_struct *mm, vma =vma_lookup (mm, addr);if (!vma) vma =ERR_PTR (-ENOENT ); -else if (!(vma->vm_flags &VM_SHARED ) && -unlikely (anon_vma_prepare (vma))) +else if (is_cow_mapping (vma->vm_flags) &&unlikely (anon_vma_prepare (vma))) vma =ERR_PTR (-ENOMEM );return vma;
@@ -77,7 +76,7 @@ static struct vm_area_struct *uffd_lock_vma(struct mm_struct *mm,* We know we're going to need to use anon_vma, so check * that early. */ -if (!(vma->vm_flags &VM_SHARED ) &&unlikely (!vma->anon_vma)) +if (is_cow_mapping (vma->vm_flags) &&unlikely (!vma->anon_vma))vma_end_read (vma);else return vma;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 536/686 ceph: fix longname buffer overflow in ceph_fname_to_usr()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangshan Yi <[email protected]>
[ Upstream commit 71975d6e0db17646102488cf54480fda9de0f7a7 ]
Snapshot longname reconstruction formats "_<name>_<inode>" via snprintf() and memcpy()s the result into oname->name. Checking the length against NAME_MAX only protects the LOOKUPNAME/export callers, whose buffer is allocated with fscrypt_fname_alloc_buffer(NAME_MAX). The readdir path points oname->name straight at the altname in the MDS reply, whose capacity is altname_len; the reconstructed name can exceed that while still fitting under NAME_MAX, overflowing the in-place destination.
Save the actual oname->len before the decryption overwrites it, and fail with -ENAMETOOLONG when the reconstructed name would not fit.
--- fs/ceph/crypto.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ceph/crypto.c +8 -0
@@ -370,6 +370,7 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname,struct fscrypt_str iname;char *name = fname->name;int name_len = fname->name_len; +int dst_len;int ret;if (WARN_ON_ONCE (tname &&is_vmalloc_addr (tname->name)))
@@ -445,6 +446,9 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname, iname.len = fname->ctext_len; } +/* oname->len is overwritten by the decryption below */ + dst_len = oname->len; + _oname.name =unlikely (is_vmalloc_addr (oname->name)) ? tname->name : oname->name; _oname.len = oname->len;
@@ -462,6 +466,10 @@ int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname, name_len =snprintf (tmp_buf,sizeof (tmp_buf),"_%.*s_%ld" , oname->len, oname->name, dir->i_ino); +if (name_len > dst_len) { + ret = -ENAMETOOLONG ; + goto out; + }memcpy (oname->name, tmp_buf, name_len); oname->len = name_len; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 537/686 mm/page_vma_mapped: continue past nonmatching huge PMDs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
[ Upstream commit 1a2993227e8a27fc4cdea305bbdae82d290bc885 ]
A PTE-mapped large folio can straddle PMD boundaries after an unaligned mremap(). If the first part is discarded and replaced with an unrelated huge PMD, page_vma_mapped_walk() stops instead of looking for the rest of the folio in subsequent PMDs.
This also affects migration entries. A walk that stops at an unrelated huge PMD can leave migration PTEs behind when migration or an anonymous folio split restores the mappings. Those entries do not hold mapping references and can outlive the source folio.
This issue can lead to memory corruption and I have a reproducer for it.
Skip the current PMD rather than ending the walk on a flag or PFN mismatch. Do the same if the PMD became nonpresent before the locked recheck. Release the PMD lock, clear the per-PMD state and advance with step_forward(), so the existing range limit controls termination. This covers present, migration and device-private huge PMDs while preserving the matching-PMD and split-to-PTE paths.
--- mm/page_vma_mapped.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
mm/page_vma_mapped.c +16 -6
@@ -260,18 +260,18 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)if (!thp_migration_supported () || !(pvmw->flags &PVMW_MIGRATION )) -return not_found (pvmw); + goto next_pmd; entry =pmd_to_swp_entry (pmde);if (!is_migration_entry (entry) || !check_pmd (swp_offset_pfn (entry), pvmw)) -return not_found (pvmw); + goto next_pmd;return true; }if (likely (pmd_trans_huge (pmde))) {if (pvmw->flags &PVMW_MIGRATION ) -return not_found (pvmw); + goto next_pmd;if (!check_pmd (pmd_pfn (pmde), pvmw)) -return not_found (pvmw); + goto next_pmd;return true; }/* THP pmd was split under us: handle on pte level */
@@ -291,8 +291,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)spin_unlock (ptl); } -step_forward (pvmw,PMD_SIZE ); -continue ; + goto next_pmd; }if (!map_pte (pvmw, &pmde, &ptl)) {if (!pvmw->pte)
@@ -331,6 +330,17 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) pvmw->ptl = ptl; } goto this_pte; +next_pmd: +/* +* A large folio can be PTE-mapped across PMDs, so a +* nonmatching PMD does not end the walk. +*/ +if (pvmw->ptl) { +spin_unlock (pvmw->ptl); + pvmw->ptl =NULL ; + } + pvmw->pmd =NULL ; +step_forward (pvmw,PMD_SIZE ); }while (pvmw->address < end);return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 538/686 mm/shmem: honour F_SEAL_EXEC when an ACL is set
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 0237c47ca17005ea41b510c6116f0257dbf84eab ]
The owner of a memfd sealed with F_SEAL_EXEC can still change its execute bits by setting a POSIX access ACL. With CONFIG_TMPFS_POSIX_ACL, this lets an unprivileged owner make a non-executable memfd executable, bypassing vm.memfd_noexec=2.
simple_set_acl() updates i_mode directly, bypassing the seal check in shmem_setattr(). Add shmem_set_acl() to check the resulting mode. Share the F_SEAL_EXEC check with shmem_setattr() using memfd_check_seals_mode() in include/linux/memfd.h.
Fix generated by an LLM and sent by Chris Mason in private.
--- include/linux/memfd.h | 9 +++++++++ mm/shmem.c | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-)
include/linux/memfd.h +9 -0
@@ -2,8 +2,17 @@#ifndef __LINUX_MEMFD_H#define __LINUX_MEMFD_H +#include <linux/fcntl.h> #include <linux/file.h> +static inline int memfd_check_seals_mode (unsigned int seals,umode_t old_mode, +umode_t new_mode) +{ +if ((seals &F_SEAL_EXEC ) && ((old_mode ^ new_mode) &0111 )) +return -EPERM ; +return 0 ; +} +#ifdef CONFIG_MEMFD_CREATE extern long memfd_fcntl (struct file *file,unsigned int cmd,unsigned int arg);struct folio *memfd_alloc_folio (struct file *memfd,pgoff_t idx);
mm/shmem.c +30 -5
@@ -76,6 +76,7 @@ static struct vfsmount *shm_mnt __ro_after_init;#include <linux/magic.h> #include <linux/syscalls.h> #include <linux/fcntl.h> +#include <linux/memfd.h> #include <uapi/linux/memfd.h> #include <linux/rmap.h> #include <linux/uuid.h>
@@ -1321,10 +1322,11 @@ static int shmem_setattr(struct mnt_idmap *idmap,if (error)return error; -if ((info->seals &F_SEAL_EXEC ) && (attr->ia_valid &ATTR_MODE )) { -if ((inode->i_mode ^ attr->ia_mode) &0111 ) { -return -EPERM ; - } +if (attr->ia_valid &ATTR_MODE ) { + error =memfd_check_seals_mode (info->seals, inode->i_mode, + attr->ia_mode); +if (error) +return error; }if (S_ISREG (inode->i_mode) && (attr->ia_valid &ATTR_SIZE )) {
@@ -5295,12 +5297,35 @@ static const struct file_operations shmem_file_operations = {#endif }; +#ifdef CONFIG_TMPFS_POSIX_ACL +static int shmem_set_acl (struct mnt_idmap *idmap,struct dentry *dentry, +struct posix_acl *acl,int type) +{ +struct inode *inode =d_inode (dentry); +umode_t mode = inode->i_mode; +int error; + +if (type ==ACL_TYPE_ACCESS ) { + error =posix_acl_equiv_mode (acl, &mode); +if (error <0 ) +return error; + error =memfd_check_seals_mode (SHMEM_I (inode)->seals, + inode->i_mode, mode); +if (error) +return error; + } +return simple_set_acl (idmap, dentry, acl, type); +} +#else +#define shmem_set_acl simple_set_acl +#endif +static const struct inode_operations shmem_inode_operations = { .getattr = shmem_getattr, .setattr = shmem_setattr, #ifdef CONFIG_TMPFS_XATTR .listxattr = shmem_listxattr, - .set_acl = simple_set_acl, + .set_acl = shmem_set_acl, .fileattr_get = shmem_fileattr_get, .fileattr_set = shmem_fileattr_set, #endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 539/686 spi: cadence-xspi: Replace ACPI specifics by agnostic APIs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 6f9e4740e8591176eb90bb1dae95bbbb5c7d789e ]
Replace ACPI specific calls to get device property with the agnostic one. The code looses the direct dependency to the ACPI APIs and get cleaner. This doesn't change functionality.
While at it, drop now unneeded acpi.h.
Stable-dep-of: ea9854a169e9 ("spi: cadence-xspi: reject SDMA transfers larger than the requested length")
--- drivers/spi/spi-cadence-xspi.c | 36 +++++++++++----------------------- 1 file changed, 11 insertions(+), 25 deletions(-)
drivers/spi/spi-cadence-xspi.c +11 -25
@@ -2,7 +2,6 @@// Cadence XSPI flash controller driver // Copyright (C) 2020-21 Cadence -#include <linux/acpi.h> #include <linux/completion.h> #include <linux/delay.h> #include <linux/err.h>
@@ -21,6 +20,7 @@#include <linux/limits.h> #include <linux/log2.h> #include <linux/bitrev.h> +#include <linux/util_macros.h> #define CDNS_XSPI_MAGIC_NUM_VALUE 0x6522#define CDNS_XSPI_MAX_BANKS 8
@@ -775,19 +775,15 @@ static int marvell_xspi_mem_op_execute(struct spi_mem *mem,return ret; } -#ifdef CONFIG_ACPI static bool cdns_xspi_supports_op (struct spi_mem *mem,const struct spi_mem_op *op) {struct spi_device *spi = mem->spi; -const union acpi_object *obj; -struct acpi_device *adev; +struct device *dev = &spi->dev; +u32 value; - adev =ACPI_COMPANION (&spi->dev); - -if (!acpi_dev_get_property (adev,"spi-tx-bus-width" ,ACPI_TYPE_INTEGER , - &obj)) { -switch (obj->integer.value) { +if (!device_property_read_u32 (dev,"spi-tx-bus-width" , &value)) { +switch (value) {case 1 :break ;case 2 :
@@ -800,16 +796,13 @@ static bool cdns_xspi_supports_op(struct spi_mem *mem, spi->mode |=SPI_TX_OCTAL ;break ;default : -dev_warn (&spi->dev, -"spi-tx-bus-width %lld not supported\n" , - obj->integer.value); +dev_warn (dev,"spi-tx-bus-width %u not supported\n" , value);break ; } } -if (!acpi_dev_get_property (adev,"spi-rx-bus-width" ,ACPI_TYPE_INTEGER , - &obj)) { -switch (obj->integer.value) { +if (!device_property_read_u32 (dev,"spi-rx-bus-width" , &value)) { +switch (value) {case 1 :break ;case 2 :
@@ -822,9 +815,7 @@ static bool cdns_xspi_supports_op(struct spi_mem *mem, spi->mode |=SPI_RX_OCTAL ;break ;default : -dev_warn (&spi->dev, -"spi-rx-bus-width %lld not supported\n" , - obj->integer.value); +dev_warn (dev,"spi-rx-bus-width %u not supported\n" , value);break ; } }
@@ -834,7 +825,6 @@ static bool cdns_xspi_supports_op(struct spi_mem *mem,return true; } -#endif static int cdns_xspi_adjust_mem_op_size (struct spi_mem *mem,struct spi_mem_op *op) {
@@ -847,17 +837,13 @@ static int cdns_xspi_adjust_mem_op_size(struct spi_mem *mem, struct spi_mem_op * }static const struct spi_controller_mem_ops cadence_xspi_mem_ops = { -#ifdef CONFIG_ACPI - .supports_op = cdns_xspi_supports_op, -#endif + .supports_op =PTR_IF (IS_ENABLED (CONFIG_ACPI ), cdns_xspi_supports_op), .exec_op = cdns_xspi_mem_op_execute, .adjust_op_size = cdns_xspi_adjust_mem_op_size, };static const struct spi_controller_mem_ops marvell_xspi_mem_ops = { -#ifdef CONFIG_ACPI - .supports_op = cdns_xspi_supports_op, -#endif + .supports_op =PTR_IF (IS_ENABLED (CONFIG_ACPI ), cdns_xspi_supports_op), .exec_op = marvell_xspi_mem_op_execute, .adjust_op_size = cdns_xspi_adjust_mem_op_size, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 540/686 spi: cadence-xspi: Use FIELD_MODIFY()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Zhang <[email protected]>
[ Upstream commit 6fa473f4c5dcc20db9799f90da48b977730e05f1 ]
Use FIELD_MODIFY() to remove open-coded bit manipulation. No functional change intended.
Stable-dep-of: ea9854a169e9 ("spi: cadence-xspi: reject SDMA transfers larger than the requested length")
--- drivers/spi/spi-cadence-xspi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/spi-cadence-xspi.c +1 -2
@@ -453,8 +453,7 @@ static bool cdns_mrvl_xspi_setup_clock(struct cdns_xspi_dev *cdns_xspi,writel (clk_reg, cdns_xspi->auxbase +MRVL_XSPI_CLK_CTRL_AUX_REG ); clk_reg =FIELD_PREP (MRVL_XSPI_CLK_DIV , i); - clk_reg &= ~MRVL_XSPI_CLK_DIV ; - clk_reg |=FIELD_PREP (MRVL_XSPI_CLK_DIV , i); +FIELD_MODIFY (MRVL_XSPI_CLK_DIV , &clk_reg, i); clk_reg |=MRVL_XSPI_CLK_ENABLE ; clk_reg |=MRVL_XSPI_IRQ_ENABLE ; update_clk = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 541/686 spi: cadence-xspi: group marvell support code together
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jisheng Zhang <[email protected]>
[ Upstream commit 94d031d26168560e951f8c88cbfb7aa53a57092a ]
We will remove the 64BIT dependency from cadence-xspi for non marvell platform soon. No functionality change.
Stable-dep-of: ea9854a169e9 ("spi: cadence-xspi: reject SDMA transfers larger than the requested length")
--- drivers/spi/spi-cadence-xspi.c | 455 ++++++++++++++++----------------- 1 file changed, 227 insertions(+), 228 deletions(-)
drivers/spi/spi-cadence-xspi.c +227 -228
@@ -316,39 +316,10 @@ struct cdns_xspi_driver_data {u32 rfile_phy_dll_slave_ctrl; }; -static struct cdns_xspi_driver_data marvell_driver_data = { - .mrvl_hw_overlay = true, - .dll_phy_ctrl =MARVELL_REGS_DLL_PHY_CTRL , - .ctb_rfile_phy_ctrl =MARVELL_CTB_RFILE_PHY_CTRL , - .rfile_phy_tsel =MARVELL_RFILE_PHY_TSEL , - .rfile_phy_dq_timing =MARVELL_RFILE_PHY_DQ_TIMING , - .rfile_phy_dqs_timing =MARVELL_RFILE_PHY_DQS_TIMING , - .rfile_phy_gate_lpbk_ctrl =MARVELL_RFILE_PHY_GATE_LPBK_CTRL , - .rfile_phy_dll_master_ctrl =MARVELL_RFILE_PHY_DLL_MASTER_CTRL , - .rfile_phy_dll_slave_ctrl =MARVELL_RFILE_PHY_DLL_SLAVE_CTRL , -}; -static struct cdns_xspi_driver_data cdns_driver_data = { .mrvl_hw_overlay = false, }; -static const int cdns_mrvl_xspi_clk_div_list[] = { -4 ,//0x0 = Divide by 4. SPI clock is 200 MHz. -6 ,//0x1 = Divide by 6. SPI clock is 133.33 MHz. -8 ,//0x2 = Divide by 8. SPI clock is 100 MHz. -10 ,//0x3 = Divide by 10. SPI clock is 80 MHz. -12 ,//0x4 = Divide by 12. SPI clock is 66.666 MHz. -16 ,//0x5 = Divide by 16. SPI clock is 50 MHz. -18 ,//0x6 = Divide by 18. SPI clock is 44.44 MHz. -20 ,//0x7 = Divide by 20. SPI clock is 40 MHz. -24 ,//0x8 = Divide by 24. SPI clock is 33.33 MHz. -32 ,//0x9 = Divide by 32. SPI clock is 25 MHz. -40 ,//0xA = Divide by 40. SPI clock is 20 MHz. -50 ,//0xB = Divide by 50. SPI clock is 16 MHz. -64 ,//0xC = Divide by 64. SPI clock is 12.5 MHz. -128 //0xD = Divide by 128. SPI clock is 6.25 MHz. -}; -struct cdns_xspi_dev {struct platform_device *pdev;struct device *dev;
@@ -380,92 +351,6 @@ struct cdns_xspi_dev {int current_xfer_qword; }; -static void cdns_xspi_reset_dll (struct cdns_xspi_dev *cdns_xspi) -{ -u32 dll_cntrl =readl (cdns_xspi->iobase + -CDNS_XSPI_RF_MINICTRL_REGS_DLL_PHY_CTRL ); - -/* Reset DLL */ - dll_cntrl |=CDNS_XSPI_DLL_RST_N ; -writel (dll_cntrl, cdns_xspi->iobase + -CDNS_XSPI_RF_MINICTRL_REGS_DLL_PHY_CTRL ); -} - -static bool cdns_xspi_is_dll_locked (struct cdns_xspi_dev *cdns_xspi) -{ -u32 dll_lock; - -return !readl_relaxed_poll_timeout (cdns_xspi->iobase + -CDNS_XSPI_INTR_STATUS_REG , - dll_lock, ((dll_lock &CDNS_XSPI_DLL_LOCK ) ==1 ),10 ,10000 ); -} - -/* Static configuration of PHY */ -static bool cdns_xspi_configure_phy (struct cdns_xspi_dev *cdns_xspi) -{ -writel (cdns_xspi->driver_data->dll_phy_ctrl, - cdns_xspi->iobase +CDNS_XSPI_RF_MINICTRL_REGS_DLL_PHY_CTRL ); -writel (cdns_xspi->driver_data->ctb_rfile_phy_ctrl, - cdns_xspi->auxbase +CDNS_XSPI_PHY_CTB_RFILE_PHY_CTRL ); -writel (cdns_xspi->driver_data->rfile_phy_tsel, - cdns_xspi->auxbase +CDNS_XSPI_PHY_CTB_RFILE_PHY_TSEL ); -writel (cdns_xspi->driver_data->rfile_phy_dq_timing, - cdns_xspi->auxbase +CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DQ_TIMING ); -writel (cdns_xspi->driver_data->rfile_phy_dqs_timing, - cdns_xspi->auxbase +CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DQS_TIMING ); -writel (cdns_xspi->driver_data->rfile_phy_gate_lpbk_ctrl, - cdns_xspi->auxbase +CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_GATE_LPBK_CTRL ); -writel (cdns_xspi->driver_data->rfile_phy_dll_master_ctrl, - cdns_xspi->auxbase +CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DLL_MASTER_CTRL ); -writel (cdns_xspi->driver_data->rfile_phy_dll_slave_ctrl, - cdns_xspi->auxbase +CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DLL_SLAVE_CTRL ); - -cdns_xspi_reset_dll (cdns_xspi); - -return cdns_xspi_is_dll_locked (cdns_xspi); -} - -static bool cdns_mrvl_xspi_setup_clock (struct cdns_xspi_dev *cdns_xspi, -int requested_clk) -{ -int i =0 ; -int clk_val; -u32 clk_reg; -bool update_clk = false; - -while (i < (ARRAY_SIZE (cdns_mrvl_xspi_clk_div_list) -1 )) { - clk_val =MRVL_XSPI_CLOCK_DIVIDED ( - cdns_mrvl_xspi_clk_div_list[i]); -if (clk_val <= requested_clk) -break ; - i++; - } - -dev_dbg (cdns_xspi->dev,"Found clk div: %d, clk val: %d\n" , - cdns_mrvl_xspi_clk_div_list[i], -MRVL_XSPI_CLOCK_DIVIDED ( - cdns_mrvl_xspi_clk_div_list[i])); - - clk_reg =readl (cdns_xspi->auxbase +MRVL_XSPI_CLK_CTRL_AUX_REG ); - -if (FIELD_GET (MRVL_XSPI_CLK_DIV , clk_reg) != i) { - clk_reg &= ~MRVL_XSPI_CLK_ENABLE ; -writel (clk_reg, - cdns_xspi->auxbase +MRVL_XSPI_CLK_CTRL_AUX_REG ); - clk_reg =FIELD_PREP (MRVL_XSPI_CLK_DIV , i); -FIELD_MODIFY (MRVL_XSPI_CLK_DIV , &clk_reg, i); - clk_reg |=MRVL_XSPI_CLK_ENABLE ; - clk_reg |=MRVL_XSPI_IRQ_ENABLE ; - update_clk = true; - } - -if (update_clk) -writel (clk_reg, - cdns_xspi->auxbase +MRVL_XSPI_CLK_CTRL_AUX_REG ); - -return update_clk; -} -static int cdns_xspi_wait_for_controller_idle (struct cdns_xspi_dev *cdns_xspi) {u32 ctrl_stat;
@@ -538,23 +423,6 @@ static void cdns_xspi_set_interrupts(struct cdns_xspi_dev *cdns_xspi,writel (intr_enable, cdns_xspi->iobase +CDNS_XSPI_INTR_ENABLE_REG ); } -static void marvell_xspi_set_interrupts (struct cdns_xspi_dev *cdns_xspi, -bool enabled) -{ -u32 intr_enable; -u32 irq_status; - - irq_status =readl (cdns_xspi->iobase +CDNS_XSPI_INTR_STATUS_REG ); -writel (irq_status, cdns_xspi->iobase +CDNS_XSPI_INTR_STATUS_REG ); - - intr_enable =readl (cdns_xspi->iobase +CDNS_XSPI_INTR_ENABLE_REG ); -if (enabled) - intr_enable |=CDNS_XSPI_INTR_MASK ; -else - intr_enable &= ~CDNS_XSPI_INTR_MASK ; -writel (intr_enable, cdns_xspi->iobase +CDNS_XSPI_INTR_ENABLE_REG ); -} -static int cdns_xspi_controller_init (struct cdns_xspi_dev *cdns_xspi) {u32 ctrl_ver;
@@ -599,78 +467,6 @@ static void cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) } } -static void m_ioreadq (void __iomem *addr,void *buf,int len) -{ -if (IS_ALIGNED ((long )buf,8 ) && len >=8 ) { -u64 full_ops = len /8 ; -u64 *buffer = buf; - - len -= full_ops *8 ; - buf += full_ops *8 ; - -do { -u64 b =readq (addr); - *buffer++ = b; - }while (--full_ops); - } - - -while (len) { -u64 tmp_buf; - - tmp_buf =readq (addr); -memcpy (buf, &tmp_buf,min (len,8 )); - len = len >8 ? len -8 :0 ; - buf +=8 ; - } -} - -static void m_iowriteq (void __iomem *addr,const void *buf,int len) -{ -if (IS_ALIGNED ((long )buf,8 ) && len >=8 ) { -u64 full_ops = len /8 ; -const u64 *buffer = buf; - - len -= full_ops *8 ; - buf += full_ops *8 ; - -do { -writeq (*buffer++, addr); - }while (--full_ops); - } - -while (len) { -u64 tmp_buf; - -memcpy (&tmp_buf, buf,min (len,8 )); -writeq (tmp_buf, addr); - len = len >8 ? len -8 :0 ; - buf +=8 ; - } -} - -static void marvell_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) -{ -u32 sdma_size, sdma_trd_info; -u8 sdma_dir; - - sdma_size =readl (cdns_xspi->iobase +CDNS_XSPI_SDMA_SIZE_REG ); - sdma_trd_info =readl (cdns_xspi->iobase +CDNS_XSPI_SDMA_TRD_INFO_REG ); - sdma_dir =FIELD_GET (CDNS_XSPI_SDMA_DIR , sdma_trd_info); - -switch (sdma_dir) { -case CDNS_XSPI_SDMA_DIR_READ : -m_ioreadq (cdns_xspi->sdmabase, - cdns_xspi->in_buffer, sdma_size); -break ; - -case CDNS_XSPI_SDMA_DIR_WRITE : -m_iowriteq (cdns_xspi->sdmabase, - cdns_xspi->out_buffer, sdma_size); -break ; - } -} -static int cdns_xspi_send_stig_command (struct cdns_xspi_dev *cdns_xspi,const struct spi_mem_op *op,bool data_phase)
@@ -760,20 +556,6 @@ static int cdns_xspi_mem_op_execute(struct spi_mem *mem,return ret; } -static int marvell_xspi_mem_op_execute (struct spi_mem *mem, -const struct spi_mem_op *op) -{ -struct cdns_xspi_dev *cdns_xspi = -spi_controller_get_devdata (mem->spi->controller); -int ret =0 ; - -cdns_mrvl_xspi_setup_clock (cdns_xspi, mem->spi->max_speed_hz); - - ret =cdns_xspi_mem_op (cdns_xspi, mem, op); - -return ret; -} -static bool cdns_xspi_supports_op (struct spi_mem *mem,const struct spi_mem_op *op) {
@@ -841,12 +623,6 @@ static const struct spi_controller_mem_ops cadence_xspi_mem_ops = { .adjust_op_size = cdns_xspi_adjust_mem_op_size, }; -static const struct spi_controller_mem_ops marvell_xspi_mem_ops = { - .supports_op =PTR_IF (IS_ENABLED (CONFIG_ACPI ), cdns_xspi_supports_op), - .exec_op = marvell_xspi_mem_op_execute, - .adjust_op_size = cdns_xspi_adjust_mem_op_size, -}; -static irqreturn_t cdns_xspi_irq_handler (int this_irq,void *dev) {struct cdns_xspi_dev *cdns_xspi = dev;
@@ -928,6 +704,230 @@ static void cdns_xspi_print_phy_config(struct cdns_xspi_dev *cdns_xspi) readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_DLL_SLAVE_CTRL)); } +static struct cdns_xspi_driver_data marvell_driver_data = { + .mrvl_hw_overlay = true, + .dll_phy_ctrl =MARVELL_REGS_DLL_PHY_CTRL , + .ctb_rfile_phy_ctrl =MARVELL_CTB_RFILE_PHY_CTRL , + .rfile_phy_tsel =MARVELL_RFILE_PHY_TSEL , + .rfile_phy_dq_timing =MARVELL_RFILE_PHY_DQ_TIMING , + .rfile_phy_dqs_timing =MARVELL_RFILE_PHY_DQS_TIMING , + .rfile_phy_gate_lpbk_ctrl =MARVELL_RFILE_PHY_GATE_LPBK_CTRL , + .rfile_phy_dll_master_ctrl =MARVELL_RFILE_PHY_DLL_MASTER_CTRL , + .rfile_phy_dll_slave_ctrl =MARVELL_RFILE_PHY_DLL_SLAVE_CTRL , +}; + +static const int cdns_mrvl_xspi_clk_div_list[] = { +4 ,//0x0 = Divide by 4. SPI clock is 200 MHz. +6 ,//0x1 = Divide by 6. SPI clock is 133.33 MHz. +8 ,//0x2 = Divide by 8. SPI clock is 100 MHz. +10 ,//0x3 = Divide by 10. SPI clock is 80 MHz. +12 ,//0x4 = Divide by 12. SPI clock is 66.666 MHz. +16 ,//0x5 = Divide by 16. SPI clock is 50 MHz. +18 ,//0x6 = Divide by 18. SPI clock is 44.44 MHz. +20 ,//0x7 = Divide by 20. SPI clock is 40 MHz. +24 ,//0x8 = Divide by 24. SPI clock is 33.33 MHz. +32 ,//0x9 = Divide by 32. SPI clock is 25 MHz. +40 ,//0xA = Divide by 40. SPI clock is 20 MHz. +50 ,//0xB = Divide by 50. SPI clock is 16 MHz. +64 ,//0xC = Divide by 64. SPI clock is 12.5 MHz. +128 //0xD = Divide by 128. SPI clock is 6.25 MHz. +}; + +static void cdns_xspi_reset_dll (struct cdns_xspi_dev *cdns_xspi) +{ +u32 dll_cntrl =readl (cdns_xspi->iobase + +CDNS_XSPI_RF_MINICTRL_REGS_DLL_PHY_CTRL ); + +/* Reset DLL */ + dll_cntrl |=CDNS_XSPI_DLL_RST_N ; +writel (dll_cntrl, cdns_xspi->iobase + +CDNS_XSPI_RF_MINICTRL_REGS_DLL_PHY_CTRL ); +} + +static bool cdns_xspi_is_dll_locked (struct cdns_xspi_dev *cdns_xspi) +{ +u32 dll_lock; + +return !readl_relaxed_poll_timeout (cdns_xspi->iobase + +CDNS_XSPI_INTR_STATUS_REG , + dll_lock, ((dll_lock &CDNS_XSPI_DLL_LOCK ) ==1 ),10 ,10000 ); +} + +/* Static configuration of PHY */ +static bool cdns_xspi_configure_phy (struct cdns_xspi_dev *cdns_xspi) +{ +writel (cdns_xspi->driver_data->dll_phy_ctrl, + cdns_xspi->iobase +CDNS_XSPI_RF_MINICTRL_REGS_DLL_PHY_CTRL ); +writel (cdns_xspi->driver_data->ctb_rfile_phy_ctrl, + cdns_xspi->auxbase +CDNS_XSPI_PHY_CTB_RFILE_PHY_CTRL ); +writel (cdns_xspi->driver_data->rfile_phy_tsel, + cdns_xspi->auxbase +CDNS_XSPI_PHY_CTB_RFILE_PHY_TSEL ); +writel (cdns_xspi->driver_data->rfile_phy_dq_timing, + cdns_xspi->auxbase +CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DQ_TIMING ); +writel (cdns_xspi->driver_data->rfile_phy_dqs_timing, + cdns_xspi->auxbase +CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DQS_TIMING ); +writel (cdns_xspi->driver_data->rfile_phy_gate_lpbk_ctrl, + cdns_xspi->auxbase +CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_GATE_LPBK_CTRL ); +writel (cdns_xspi->driver_data->rfile_phy_dll_master_ctrl, + cdns_xspi->auxbase +CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DLL_MASTER_CTRL ); +writel (cdns_xspi->driver_data->rfile_phy_dll_slave_ctrl, + cdns_xspi->auxbase +CDNS_XSPI_PHY_DATASLICE_RFILE_PHY_DLL_SLAVE_CTRL ); + +cdns_xspi_reset_dll (cdns_xspi); + +return cdns_xspi_is_dll_locked (cdns_xspi); +} + +static bool cdns_mrvl_xspi_setup_clock (struct cdns_xspi_dev *cdns_xspi, +int requested_clk) +{ +int i =0 ; +int clk_val; +u32 clk_reg; +bool update_clk = false; + +while (i < (ARRAY_SIZE (cdns_mrvl_xspi_clk_div_list) -1 )) { + clk_val =MRVL_XSPI_CLOCK_DIVIDED ( + cdns_mrvl_xspi_clk_div_list[i]); +if (clk_val <= requested_clk) +break ; + i++; + } + +dev_dbg (cdns_xspi->dev,"Found clk div: %d, clk val: %d\n" , + cdns_mrvl_xspi_clk_div_list[i], +MRVL_XSPI_CLOCK_DIVIDED ( + cdns_mrvl_xspi_clk_div_list[i])); + + clk_reg =readl (cdns_xspi->auxbase +MRVL_XSPI_CLK_CTRL_AUX_REG ); + +if (FIELD_GET (MRVL_XSPI_CLK_DIV , clk_reg) != i) { + clk_reg &= ~MRVL_XSPI_CLK_ENABLE ; +writel (clk_reg, + cdns_xspi->auxbase +MRVL_XSPI_CLK_CTRL_AUX_REG ); + clk_reg =FIELD_PREP (MRVL_XSPI_CLK_DIV , i); +FIELD_MODIFY (MRVL_XSPI_CLK_DIV , &clk_reg, i); + clk_reg |=MRVL_XSPI_CLK_ENABLE ; + clk_reg |=MRVL_XSPI_IRQ_ENABLE ; + update_clk = true; + } + +if (update_clk) +writel (clk_reg, + cdns_xspi->auxbase +MRVL_XSPI_CLK_CTRL_AUX_REG ); + +return update_clk; +} + +static void marvell_xspi_set_interrupts (struct cdns_xspi_dev *cdns_xspi, +bool enabled) +{ +u32 intr_enable; +u32 irq_status; + + irq_status =readl (cdns_xspi->iobase +CDNS_XSPI_INTR_STATUS_REG ); +writel (irq_status, cdns_xspi->iobase +CDNS_XSPI_INTR_STATUS_REG ); + + intr_enable =readl (cdns_xspi->iobase +CDNS_XSPI_INTR_ENABLE_REG ); +if (enabled) + intr_enable |=CDNS_XSPI_INTR_MASK ; +else + intr_enable &= ~CDNS_XSPI_INTR_MASK ; +writel (intr_enable, cdns_xspi->iobase +CDNS_XSPI_INTR_ENABLE_REG ); +} + +static int marvell_xspi_mem_op_execute (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +struct cdns_xspi_dev *cdns_xspi = +spi_controller_get_devdata (mem->spi->controller); +int ret =0 ; + +cdns_mrvl_xspi_setup_clock (cdns_xspi, mem->spi->max_speed_hz); + + ret =cdns_xspi_mem_op (cdns_xspi, mem, op); + +return ret; +} + +static void m_ioreadq (void __iomem *addr,void *buf,int len) +{ +if (IS_ALIGNED ((long )buf,8 ) && len >=8 ) { +u64 full_ops = len /8 ; +u64 *buffer = buf; + + len -= full_ops *8 ; + buf += full_ops *8 ; + +do { +u64 b =readq (addr); + *buffer++ = b; + }while (--full_ops); + } + + +while (len) { +u64 tmp_buf; + + tmp_buf =readq (addr); +memcpy (buf, &tmp_buf,min (len,8 )); + len = len >8 ? len -8 :0 ; + buf +=8 ; + } +} + +static void m_iowriteq (void __iomem *addr,const void *buf,int len) +{ +if (IS_ALIGNED ((long )buf,8 ) && len >=8 ) { +u64 full_ops = len /8 ; +const u64 *buffer = buf; + + len -= full_ops *8 ; + buf += full_ops *8 ; + +do { +writeq (*buffer++, addr); + }while (--full_ops); + } + +while (len) { +u64 tmp_buf; + +memcpy (&tmp_buf, buf,min (len,8 )); +writeq (tmp_buf, addr); + len = len >8 ? len -8 :0 ; + buf +=8 ; + } +} + +static void marvell_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) +{ +u32 sdma_size, sdma_trd_info; +u8 sdma_dir; + + sdma_size =readl (cdns_xspi->iobase +CDNS_XSPI_SDMA_SIZE_REG ); + sdma_trd_info =readl (cdns_xspi->iobase +CDNS_XSPI_SDMA_TRD_INFO_REG ); + sdma_dir =FIELD_GET (CDNS_XSPI_SDMA_DIR , sdma_trd_info); + +switch (sdma_dir) { +case CDNS_XSPI_SDMA_DIR_READ : +m_ioreadq (cdns_xspi->sdmabase, + cdns_xspi->in_buffer, sdma_size); +break ; + +case CDNS_XSPI_SDMA_DIR_WRITE : +m_iowriteq (cdns_xspi->sdmabase, + cdns_xspi->out_buffer, sdma_size); +break ; + } +} + +static const struct spi_controller_mem_ops marvell_xspi_mem_ops = { + .supports_op =PTR_IF (IS_ENABLED (CONFIG_ACPI ), cdns_xspi_supports_op), + .exec_op = marvell_xspi_mem_op_execute, + .adjust_op_size = cdns_xspi_adjust_mem_op_size, +}; +static int cdns_xspi_prepare_generic (int cs,const void *dout,int len,int glue,u32 *cmd_regs) {u8 *data = (u8 *)dout;
@@ -1155,15 +1155,14 @@ static int cdns_xspi_probe(struct platform_device *pdev)return -ENODEV ; } + host->mem_ops = &cadence_xspi_mem_ops; + cdns_xspi->sdma_handler = &cdns_xspi_sdma_handle; + cdns_xspi->set_interrupts_handler = &cdns_xspi_set_interrupts;if (cdns_xspi->driver_data->mrvl_hw_overlay) { host->mem_ops = &marvell_xspi_mem_ops; host->transfer_one_message = cdns_xspi_transfer_one_message_b0; cdns_xspi->sdma_handler = &marvell_xspi_sdma_handle; cdns_xspi->set_interrupts_handler = &marvell_xspi_set_interrupts; - }else { - host->mem_ops = &cadence_xspi_mem_ops; - cdns_xspi->sdma_handler = &cdns_xspi_sdma_handle; - cdns_xspi->set_interrupts_handler = &cdns_xspi_set_interrupts; } host->dev.of_node = pdev->dev.of_node; host->bus_num =-1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 542/686 spi: cadence-xspi: reject SDMA transfers larger than the requested length
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weibin Liu <[email protected]>
[ Upstream commit ea9854a169e9c1437df8829bea21c2f2e80b137c ]
The XSPI controller reports the size of the slave-DMA transaction through SDMA_SIZE_REG. Both SDMA handlers take this register at face value and copy the reported number of bytes between the SDMA FIFO and the transfer buffers, without checking it against the length of the transfer that was actually requested.
While cdns_xspi_adjust_mem_op_size() clamps the size of the operations issued by the SPI core, the device can still report a bigger SDMA size than what was programmed, which makes the handlers read from or write to memory beyond the end of the transfer buffers.
Track the number of bytes requested for the current data phase in a new sdma_xfer_len field, set by cdns_xspi_send_stig_command() and by the Marvell b0 transfer path, and reject any SDMA size that exceeds it.
--- drivers/spi/spi-cadence-xspi.c | 36 +++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-)
drivers/spi/spi-cadence-xspi.c +31 -5
@@ -332,6 +332,7 @@ struct cdns_xspi_dev {int irq;int cur_cs;unsigned int sdmasize; +unsigned int sdma_xfer_len;struct completion cmd_complete;struct completion auto_cmd_complete;
@@ -344,7 +345,7 @@ struct cdns_xspi_dev {u8 hw_num_banks;const struct cdns_xspi_driver_data *driver_data; -void (*sdma_handler)(struct cdns_xspi_dev *cdns_xspi); +int (*sdma_handler)(struct cdns_xspi_dev *cdns_xspi);void (*set_interrupts_handler)(struct cdns_xspi_dev *cdns_xspi,bool enabled);bool xfer_in_progress;
@@ -445,7 +446,7 @@ static int cdns_xspi_controller_init(struct cdns_xspi_dev *cdns_xspi)return 0 ; } -static void cdns_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) +static int cdns_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) {u32 sdma_size, sdma_trd_info;u8 sdma_dir;
@@ -454,6 +455,13 @@ static void cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) sdma_trd_info =readl (cdns_xspi->iobase +CDNS_XSPI_SDMA_TRD_INFO_REG ); sdma_dir =FIELD_GET (CDNS_XSPI_SDMA_DIR , sdma_trd_info); +if (sdma_size > cdns_xspi->sdma_xfer_len) { +dev_err (cdns_xspi->dev, +"SDMA size %u exceeds the requested length %u\n" , + sdma_size, cdns_xspi->sdma_xfer_len); +return -EINVAL ; + } +switch (sdma_dir) {case CDNS_XSPI_SDMA_DIR_READ : ioread8_rep(cdns_xspi->sdmabase,
@@ -465,6 +473,8 @@ static void cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) cdns_xspi->out_buffer, sdma_size);break ; } + +return 0 ; } static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi,
@@ -510,6 +520,7 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, cdns_xspi->in_buffer = op->data.buf.in; cdns_xspi->out_buffer = op->data.buf.out; + cdns_xspi->sdma_xfer_len = op->data.nbytes;cdns_xspi_trigger_command (cdns_xspi, cmd_regs);
@@ -518,7 +529,11 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, cdns_xspi->set_interrupts_handler (cdns_xspi, false);return -EIO ; } - cdns_xspi->sdma_handler (cdns_xspi); + ret = cdns_xspi->sdma_handler (cdns_xspi); +if (ret) { + cdns_xspi->set_interrupts_handler (cdns_xspi, false); +return ret; + } }wait_for_completion (&cdns_xspi->cmd_complete);
@@ -900,7 +915,7 @@ static void m_iowriteq(void __iomem *addr, const void *buf, int len) } } -static void marvell_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) +static int marvell_xspi_sdma_handle (struct cdns_xspi_dev *cdns_xspi) {u32 sdma_size, sdma_trd_info;u8 sdma_dir;
@@ -909,6 +924,13 @@ static void marvell_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) sdma_trd_info =readl (cdns_xspi->iobase +CDNS_XSPI_SDMA_TRD_INFO_REG ); sdma_dir =FIELD_GET (CDNS_XSPI_SDMA_DIR , sdma_trd_info); +if (sdma_size > cdns_xspi->sdma_xfer_len) { +dev_err (cdns_xspi->dev, +"SDMA size %u exceeds the requested length %u\n" , + sdma_size, cdns_xspi->sdma_xfer_len); +return -EINVAL ; + } +switch (sdma_dir) {case CDNS_XSPI_SDMA_DIR_READ : m_ioreadq(cdns_xspi->sdmabase,
@@ -920,6 +942,8 @@ static void marvell_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) cdns_xspi->out_buffer, sdma_size);break ; } + +return 0 ; }static const struct spi_controller_mem_ops marvell_xspi_mem_ops = {
@@ -1084,9 +1108,11 @@ static int cdns_xspi_transfer_one_message_b0(struct spi_controller *controller,cdns_xspi_prepare_transfer (cs,1 , current_transfer_len -1 , cmd_regs);cdns_xspi_trigger_command (cdns_xspi, cmd_regs); + cdns_xspi->sdma_xfer_len = current_transfer_len -1 ;if (!cdns_xspi_is_sdma_ready (cdns_xspi, true))return -EIO ; - cdns_xspi->sdma_handler (cdns_xspi); +if (cdns_xspi->sdma_handler (cdns_xspi)) +return -EIO ;if (!cdns_xspi_is_stig_ready (cdns_xspi, true))return -EIO ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 543/686 mm: memory: fix truncation removing mapped folios
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baolin Wang <[email protected]>
[ Upstream commit 243cf1f67b365668389832463fc31cbb9fec47af ]
Ayush reported an issue that shmem/tmpfs folios are still mapped when truncating them on production:
"
BUG: Bad page cache in process ... pfn:... page dumped because: still mapped when deleted
"
I reproduced the issue with Ayush's reproducer [1] with the latest mm-unstable branch, and I got the following crash info. From the dump message, we can see that truncate_inode_folio() is really trying to remove mapped folios, which is incorrect.
"
[ 189.171977] page: refcount:3 mapcount:1 mapping:00000000fe168ee1 index:0x3880 pfn:0x191647 [ 189.171995] memcg:ffff0000cc073d40 [ 189.171997] aops:shmem_aops ino:3c01 dentry name(?):"memfd:runsc-memory" [ 189.172006] flags: 0x17fffef0002022d(locked|referenced|uptodate|lru| workingset|swapbacked|node=0|zone=2|lastcpupid=0x3ffff) ....... [ 189.172017] page dumped because: VM_BUG_ON_FOLIO(folio_mapped(folio)) [ 189.172026] ------------[ cut here ]------------ [ 189.172027] kernel BUG at mm/filemap.c:155! [ 189.172057] Internal error: Oops - BUG: 00000000f2000800 [#1] SMP ....... [ 189.177721] CPU: 3 UID: 0 PID: 5521 Comm: repro Kdump: loaded Tainted: 7.3.0-rc4+ #277 PREEMPT(lazy) ....... [ 189.183986] Call trace: [ 189.184124] filemap_unaccount_folio+0xf0/0x1e8 (P) [ 189.184391] __filemap_remove_folio+0x34/0x160 [ 189.184633] filemap_remove_folio+0x4c/0xb0 [ 189.184859] truncate_inode_folio+0x34/0x58 [ 189.185087] shmem_undo_range+0x220/0x658 [ 189.185308] shmem_fallocate+0x2f0/0x470 [ 189.185527] vfs_fallocate+0x128/0x328 ...... [ 189.187078] el0t_64_sync+0x184/0x188
"
After analysis, I believe the race exists between truncation and MADV_DONTNEED, and shmem's ->map_pages() merely makes the issue easier to reproduce. Since MADV_DONTNEED synchronously releases the pagetable page before calling tlb_flush_rmaps(), this could cause another thread's truncation to skip zap_pte_range() (due to pmd is none) but still observe the folio's mapcount as non-zero. A possible race scenario is as follows:
CPU 0 CPU 1shmem_fallocate madvise_dontneed_single_vma
unmap_mapping_range .......
......
(filemap_map_pages() remap folios)
zap_pte_range
truncate_inode_folio zap_empty_pte_table(pmd clear)
unmap_mapping_folio
......
zap_pmd_range (saw pmd none, skip)
filemap_remove_folio
BUG_ON(folio_mapped)
tlb_flush_rmaps(remove rmaps)
To fix this issue, we should move the pmd clear operation (via zap_empty_pte_table()) to after tlb_flush_rmaps() and use sync_with_folio_pmd_zap() to sync with concurrent zapping, so that when we find a pmd_none() while unmapping a folio without holding the PTL, the folio's mappings are guaranteed to have been removed via tlb_flush_rmaps().
Meanwhile move the second pmd_none() check to where it belongs: if splitting zapped the PMD.
--- mm/memory.c | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-)
mm/memory.c +31 -21
@@ -1877,6 +1877,15 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, } }while (pte += nr, addr +=PAGE_SIZE * nr, addr != end); +add_mm_rss_vec (mm, rss); +arch_leave_lazy_mmu_mode (); + +/* Do the actual TLB flush before dropping ptl */ +if (force_flush) { +tlb_flush_mmu_tlbonly (tlb); +tlb_flush_rmaps (tlb, vma); + } +/* * Fast path: try to hold the pmd lock and unmap the PTE page. *
@@ -1884,18 +1893,12 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,* to hold the pmd lock failed, then we need to recheck all pte entries * to ensure they are still none, thereby preventing the pte entries * from being repopulated by another thread. +* +* Clear the PMD after the rmaps for the table have been removed, in case +* an incorrect mapcount is observed after unmapping the folio. */ if (can_reclaim_pt && direct_reclaim && addr == end) direct_reclaim =try_get_and_clear_pmd (mm, pmd, &pmdval); - -add_mm_rss_vec (mm, rss); -arch_leave_lazy_mmu_mode (); - -/* Do the actual TLB flush before dropping ptl */ -if (force_flush) { -tlb_flush_mmu_tlbonly (tlb); -tlb_flush_rmaps (tlb, vma); - }pte_unmap_unlock (start_pte, ptl);/*
@@ -1942,19 +1945,26 @@ static inline unsigned long zap_pmd_range(struct mmu_gather *tlb, addr = next;continue ; } +/* We already synchronized with concurrent zapping. */ +if (pmd_none (*pmd)) { + addr = next; +continue ; + }/* fall through */ - }else if (details && details->single_folio && -folio_test_pmd_mappable (details->single_folio) && - next - addr ==HPAGE_PMD_SIZE &&pmd_none (*pmd)) { -spinlock_t *ptl =pmd_lock (tlb->mm, pmd); -/* -* Take and drop THP pmd lock so that we cannot return -* prematurely, while zap_huge_pmd() has cleared *pmd, -* but not yet decremented compound_mapcount(). -*/ -spin_unlock (ptl); - } -if (pmd_none (*pmd)) { + }else if (pmd_none (*pmd)) { +if (details && details->single_folio) { +spinlock_t *ptl =pmd_lock (tlb->mm, pmd); + +/* +* zap_huge_pmd() may have cleared the PMD but not +* yet updated the folio mapcount, and +* try_get_and_clear_pmd() clears the PMD only after +* the rmaps for the table have been removed, but +* nothing orders the pmd_none() read against later +* mapcount reads without this synchronization. +*/ +spin_unlock (ptl); + } addr = next;continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 544/686 ipmr: prevent info-leak in pmr_cache_report()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 4f34002e2e37639133693c13a2a9977fab86880d ]
Yiming Qian reported:
<quote>
ipmr_cache_report() allocates a report skb with alloc_skb(128, GFP_ATOMIC) and appends a struct igmphdr using skb_put(). In the non-IGMPMSG_WHOLEPKT` path it initializes only:
- igmp->type
- igmp->code
but does not initialize:
- igmp->csum
- igmp->group
Later, igmpmsg_netlink_event() copies the bytes after sizeof(struct igmpmsg) into the IPMRA_CREPORT_PKT netlink attribute and emits RTM_NEWCACHEREPORT on RTNLGRP_IPV4_MROUTE_R.
As a result, 6 bytes of stale heap data from the skb head are disclosed to userspace.
</quote>
Let's use skb_put_zero() instead of skb_put() to fix this bug.
Stable-dep-of: 94a6736bb5ab ("ipmr: only copy pktinfo to cache reports")
--- net/ipv4/ipmr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv4/ipmr.c +4 -3
@@ -1112,11 +1112,12 @@ static int ipmr_cache_report(const struct mr_table *mrt, msg->im_vif_hi = vifi >>8 ;ipv4_pktinfo_prepare (mroute_sk, pkt, false);memcpy (skb->cb, pkt->cb,sizeof (skb->cb)); -/* Add our header */ - igmp =skb_put (skb,sizeof (struct igmphdr )); +/* Add our header. +* Note that code, csum and group fields are cleared. +*/ + igmp =skb_put_zero (skb,sizeof (struct igmphdr )); igmp->type = assert; msg->im_msgtype = assert; - igmp->code =0 ;ip_hdr (skb)->tot_len =htons (skb->len);/* Fix the length */ skb->transport_header = skb->network_header; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 545/686 ipmr: only copy pktinfo to cache reports
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 94a6736bb5abe6b2ef38490d0cab19c1c6a7c71f ]
ipmr_cache_report() prepares IP_PKTINFO on the original skb. The ipv4_pktinfo_prepare() helper updates skb->cb and clears the pktinfo fields when packet info is disabled. Since the skb can continue through the data path, preserve and restore its original control block around the helper.
The original implementation copies the entire control block to the report skb. For synthetic RTM_GETROUTE packets, NETLINK_CB data is interpreted as IPCB by the raw IPv4 receive path. With IP_RECVOPTS or IP_RETOPTS enabled, corrupted option offsets cause out-of-bounds reads or a stack buffer overflow. WHOLEPKT and WRVIFWHOLE reports also inherit stale IP option offsets when their header is prepended.
Clear the report skb control block. Only prepare and copy pktinfo when the input skb has an IPv4 header. Synthetic route-query skbs use NETLINK_CB, not IPCB, so leave their report control block zeroed. Restore pkt->cb after preparing pktinfo for regular IPv4 packets.
--- net/ipv4/ipmr.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/ipv4/ipmr.c +10 -2
@@ -1055,6 +1055,7 @@ static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt,static int ipmr_cache_report (const struct mr_table *mrt,struct sk_buff *pkt,vifi_t vifi,int assert) { +unsigned char pkt_cb[sizeof (pkt->cb)];const int ihl =ip_hdrlen (pkt);struct sock *mroute_sk;struct igmphdr *igmp;
@@ -1110,8 +1111,6 @@ static int ipmr_cache_report(const struct mr_table *mrt, msg = (struct igmpmsg *)skb_network_header (skb); msg->im_vif = vifi; msg->im_vif_hi = vifi >>8 ; -ipv4_pktinfo_prepare (mroute_sk, pkt, false); -memcpy (skb->cb, pkt->cb,sizeof (skb->cb));/* Add our header. * Note that code, csum and group fields are cleared. */
@@ -1122,6 +1121,15 @@ static int ipmr_cache_report(const struct mr_table *mrt, skb->transport_header = skb->network_header; } +memset (skb->cb,0 ,sizeof (skb->cb)); +/* Route queries from ipmr_get_route() carry NETLINK_CB, not IPCB. */ +if (ip_hdr (pkt)->version) { +memcpy (pkt_cb, pkt->cb,sizeof (pkt_cb)); +ipv4_pktinfo_prepare (mroute_sk, pkt, false); + *PKTINFO_SKB_CB (skb) = *PKTINFO_SKB_CB (pkt); +memcpy (pkt->cb, pkt_cb,sizeof (pkt_cb)); + } +igmpmsg_netlink_event (mrt, skb);/* Deliver to mrouted */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 546/686 nvme-tcp: skip TLS control records while waiting for the ICResp
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Belanger <[email protected]>
commit 12c20e2903563acfb949342967adb900310a24d4 upstream.
A peer may send a NewSessionTicket as soon as the handshake completes, ahead of the ICResp. nvme_tcp_init_connection() fails the connection on any record that is not application data, so such a target cannot be reached at all. An OpenSSL-based target does this by default.
RFC 9846 section 4.7.1 requires a client that does not support session resumption to ignore a NewSessionTicket. Discard such a record and read again, up to a fixed number of records. Report an alert, and fail the connection for any other record type.
The record type is now checked before the length. A control record shorter than the ICResp was reported as -ECONNRESET, which hid the real cause.
--- drivers/nvme/host/tcp.c | 162 ++++++++++++++++++++++++++++++++++------ 1 file changed, 140 insertions(+), 22 deletions(-)
drivers/nvme/host/tcp.c +140 -22
@@ -53,6 +53,12 @@ MODULE_PARM_DESC(tls_handshake_timeout, "nvme TLS handshake timeout in seconds (default 10)");#endif +/* read a TLS control record in chunks of this size */ +#define NVME_TCP_TLS_REC_CHUNK 256 + +/* TLS records read while waiting for the ICResp, the ICResp included */ +#define NVME_TCP_ICRESP_MAX_RECORDS 8 +static atomic_t nvme_tcp_cpu_queues[NR_CPUS ];#ifdef CONFIG_DEBUG_LOCK_ALLOC
@@ -1535,12 +1541,143 @@ static void nvme_tcp_free_queue(struct nvme_ctrl *nctrl, int qid)mutex_destroy (&queue->pf_cache_lock); } +static int nvme_tcp_recv_tls_alert (struct nvme_tcp_queue *queue, +struct msghdr *msg,int len) +{ +struct sock *sk = queue->sock->sk; +u8 level, description; + +if (len <2 ) { +dev_err (queue->ctrl->ctrl.device, +"queue %d: truncated TLS alert\n" , +nvme_tcp_queue_id (queue)); +return -ENOTCONN ; + } + +/* tls_alert_recv() reads through the iterator */ +iov_iter_revert (&msg->msg_iter, len); +tls_alert_recv (sk, msg, &level, &description); + +if (level ==TLS_ALERT_LEVEL_FATAL ) { +dev_err (queue->ctrl->ctrl.device, +"queue %d: fatal TLS alert %u\n" , +nvme_tcp_queue_id (queue), description); +return -ENOTCONN ; + } + +/* a peer shutting down normally is not worth a warning */ +if (description ==TLS_ALERT_DESC_CLOSE_NOTIFY ) +dev_dbg (queue->ctrl->ctrl.device, +"queue %d: TLS close_notify\n" , +nvme_tcp_queue_id (queue)); +else +dev_warn (queue->ctrl->ctrl.device, +"queue %d: TLS alert %u\n" , +nvme_tcp_queue_id (queue), description); + +return 0 ; +} + +/* +* Discard a TLS record that arrived in place of the ICResp. A peer may send +* a NewSessionTicket as soon as the handshake completes. +* +* Returns 0 when the record was discarded and the ICResp can be read, or a +* negative errno if the connection cannot continue. +*/ +static int nvme_tcp_skip_tls_record (struct nvme_tcp_queue *queue, +struct msghdr *msg,u8 ctype,int len) +{ +u8 buf[NVME_TCP_TLS_REC_CHUNK ]; +int ret; + +switch (ctype) { +case TLS_RECORD_TYPE_HANDSHAKE : +break ; +case TLS_RECORD_TYPE_ALERT : + ret =nvme_tcp_recv_tls_alert (queue, msg, len); +return ret ? : -ENOTCONN ; +default : +pr_err ("queue %d: unhandled TLS record %u\n" , +nvme_tcp_queue_id (queue), ctype); +return -ENOTCONN ; + } + +/* the ICResp is in a later record, drain this one first */ +while (!(msg->msg_flags &MSG_EOR )) { +struct kvec iov = { + .iov_base = buf, + .iov_len =sizeof (buf), + }; +char cbuf[CMSG_LEN (sizeof (char ))] = {}; +/* kTLS fails a control record read without a cmsg buffer */ +struct msghdr drain = { + .msg_control = cbuf, + .msg_controllen =sizeof (cbuf), + }; + + ret =kernel_recvmsg (queue->sock, &drain, &iov,1 ,sizeof (buf), +0 ); +if (ret <=0 ) { +pr_warn ("queue %d: failed to drain TLS record: %d\n" , +nvme_tcp_queue_id (queue), ret); +return ret ? : -ECONNRESET ; + } + msg->msg_flags = drain.msg_flags; + } + +return 0 ; +} + +/* +* Receive the ICResp. Over TLS, skip the records that a peer may send +* ahead of it. +* +* Returns the length received, or a negative errno. +*/ +static int nvme_tcp_recv_icresp (struct nvme_tcp_queue *queue, +struct nvme_tcp_icresp_pdu *icresp) +{ +char cbuf[CMSG_LEN (sizeof (char ))]; +struct msghdr msg; +struct kvec iov; +u8 ctype; +int i, ret; + +for (i =0 ; i <NVME_TCP_ICRESP_MAX_RECORDS ; i++) { +memset (&msg,0 ,sizeof (msg)); +memset (cbuf,0 ,sizeof (cbuf)); + iov.iov_base = icresp; + iov.iov_len =sizeof (*icresp); +if (nvme_tcp_queue_tls (queue)) { + msg.msg_control = cbuf; + msg.msg_controllen =sizeof (cbuf); + } + msg.msg_flags =MSG_WAITALL ; + ret =kernel_recvmsg (queue->sock, &msg, &iov,1 , + iov.iov_len, msg.msg_flags); +if (ret <=0 || !nvme_tcp_queue_tls (queue)) +return ret; + + ctype =tls_get_record_type (queue->sock->sk, + (struct cmsghdr *)cbuf); +if (ctype ==TLS_RECORD_TYPE_DATA ) +return ret; + + ret =nvme_tcp_skip_tls_record (queue, &msg, ctype, ret); +if (ret <0 ) +return ret; + } + +pr_err ("queue %d: too many TLS records before the ICResp\n" , +nvme_tcp_queue_id (queue)); +return -EPROTO ; +} +static int nvme_tcp_init_connection (struct nvme_tcp_queue *queue) {struct nvme_tcp_icreq_pdu *icreq;struct nvme_tcp_icresp_pdu *icresp; -char cbuf[CMSG_LEN (sizeof (char ))] = {}; -u8 ctype;struct msghdr msg = {};struct kvec iov;bool ctrl_hdgst, ctrl_ddgst;
@@ -1578,16 +1715,7 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue) goto free_icresp; } -memset (&msg,0 ,sizeof (msg)); - iov.iov_base = icresp; - iov.iov_len =sizeof (*icresp); -if (nvme_tcp_queue_tls (queue)) { - msg.msg_control = cbuf; - msg.msg_controllen =sizeof (cbuf); - } - msg.msg_flags =MSG_WAITALL ; - ret =kernel_recvmsg (queue->sock, &msg, &iov,1 , - iov.iov_len, msg.msg_flags); + ret =nvme_tcp_recv_icresp (queue, icresp);if (ret >=0 && ret <sizeof (*icresp)) ret = -ECONNRESET ;if (ret <0 ) {
@@ -1595,16 +1723,6 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue) nvme_tcp_queue_id(queue), ret); goto free_icresp; } - ret = -ENOTCONN ; -if (nvme_tcp_queue_tls (queue)) { - ctype =tls_get_record_type (queue->sock->sk, - (struct cmsghdr *)cbuf); -if (ctype !=TLS_RECORD_TYPE_DATA ) { -pr_err ("queue %d: unhandled TLS record %d\n" , -nvme_tcp_queue_id (queue), ctype); - goto free_icresp; - } - } ret = -EINVAL ;if (icresp->hdr.type != nvme_tcp_icresp) { pr_err("queue %d: bad type returned %d\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 547/686 wifi: rtw88: usb: route bmc frames via the high queue only for DTIM delivery
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mehmet Fide <[email protected]>
[ Upstream commit c710c7c2e0380d7c0eeb33b686262edcaef7cb07 ]
In AP mode every broadcast and multicast data frame is routed to TX_DESC_QSEL_HIGH, the after-DTIM queue, whether or not anybody is asleep. The firmware drains that queue at beacon pace, a dozen or so frames per second measured on RTL8822BU, while one associated client's mDNS/SSDP chatter alone exceeds that. The excess accumulates inside the chip until the shared TX page pool is exhausted (measured: 14 of 1803 pages left). From that point every host-sourced frame queues behind the backlog: authentication responses reach the air seconds after the client has given up, so no station can associate anymore, and the beacon reserved-page download fails the BCN_VALID poll ("error beacon valid") because it needs pages from the same pool. The AP keeps beaconing, so the failure looks like a silent RX stall and only a reboot recovers.
mac80211 already decides when after-DTIM delivery is needed: it sets IEEE80211_TX_CTL_SEND_AFTER_DTIM on bmc frames only while at least one station is actually dozing. Honor that instead of routing
unconditionally: flagged frames keep going through the high queue with the MORE_DATA and HGQMD handling introduced by commit 076f786a0ae1 ("wifi: rtw88: Fix AP mode incorrect DTIM behavior"), everything else leaves at line rate through the AC queues. This partially reverts the usb.c hunk of that commit, whose unconditional routing is what lets the backlog build up.
On a bench AP (USB2, 20 MHz, WPA2, hostapd, a Windows client driven through disconnect/reconnect cycles): reconnects fail 0/5 on RTL8822BU and 0/3 on RTL8821CU before this change, and pass 10/10 and 5/5 with it, with the page pool staying healthy and no beacon errors logged.
--- drivers/net/wireless/realtek/rtw88/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw88/usb.c +3 -1
@@ -560,6 +560,7 @@ static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)static u8 rtw_usb_tx_queue_mapping_to_qsel (struct sk_buff *skb) {struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb);__le16 fc = hdr->frame_control;u8 qsel;
@@ -567,7 +568,8 @@ static u8 rtw_usb_tx_queue_mapping_to_qsel(struct sk_buff *skb) qsel =TX_DESC_QSEL_MGMT ; else if (is_broadcast_ether_addr(hdr->addr1) || is_multicast_ether_addr(hdr->addr1)) - qsel =TX_DESC_QSEL_HIGH ; + qsel = (info->flags &IEEE80211_TX_CTL_SEND_AFTER_DTIM ) ? +TX_DESC_QSEL_HIGH : skb->priority; else if (skb_get_queue_mapping(skb) <= IEEE80211_AC_BK) qsel = skb->priority; else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 548/686 wifi: rtw88: usb: bound what the driver feeds the after-DTIM queue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mehmet Fide <[email protected]>
[ Upstream commit 04cc8c59a3d79ef7ec2341f1c7aef1d40a0ce7df ]
Frames routed to the high queue are transmitted right after DTIM beacons only, inside the ATIM window, while they wait in the shared TX page pool. The driver puts no limit on how many it hands over, so as long as one station dozes, any sustained broadcast or multicast traffic outruns the drain and empties the pool: measured on an RTL8822BU AP with a single client in power save and ~40 frames/s of mDNS chatter, the free page count at 0x240 goes from 1803 to 16 in about 100 seconds and stays there for as long as the traffic lasts. From that point every other transmit queues behind the backlog, authentication responses arrive too late for anyone to join, and the reserved page download fails ("error beacon valid"). The AP keeps beaconing and only a reboot recovers.
Feed the high queue through a small budget that refills below the measured drain rate (about 3 frames per DTIM, ~15/s at dtim_period 2 on the default 2 TU ATIM window); whatever exceeds the budget leaves on its access category queue right away. The high queue backlog is now bounded by the burst size under any load, so the page pool cannot run dry, at the price that a dozing station may miss part of a broadcast storm.
--- drivers/net/wireless/realtek/rtw88/usb.c | 41 ++++++++++++++++++++++-- drivers/net/wireless/realtek/rtw88/usb.h | 5 +++ 2 files changed, 43 insertions(+), 3 deletions(-)
drivers/net/wireless/realtek/rtw88/usb.c +38 -3
@@ -557,7 +557,37 @@ static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)return rtw_usb_write_data (rtwdev, &pkt_info, buf); } -static u8 rtw_usb_tx_queue_mapping_to_qsel (struct sk_buff *skb) +#define RTW_USB_HIQ_REFILL_INTERVAL (HZ / 10)/* one unit of budget per 100 ms */ +#define RTW_USB_HIQ_BUDGET_MAX 16 + +static bool rtw_usb_hiq_take_budget (struct rtw_usb *rtwusb) +{ +unsigned long flags, elapsed, add; +bool ok; + +spin_lock_irqsave (&rtwusb->hiq_lock, flags); + + elapsed = jiffies - rtwusb->hiq_refill; + add = elapsed /RTW_USB_HIQ_REFILL_INTERVAL ; +if (add) { + rtwusb->hiq_budget = min_t(unsigned long, rtwusb->hiq_budget + add, +RTW_USB_HIQ_BUDGET_MAX ); + +/* keep the unfinished part of the interval for the next unit */ + rtwusb->hiq_refill = jiffies - elapsed %RTW_USB_HIQ_REFILL_INTERVAL ; + } + + ok = rtwusb->hiq_budget >0 ; +if (ok) + rtwusb->hiq_budget--; + +spin_unlock_irqrestore (&rtwusb->hiq_lock, flags); + +return ok; +} + +static u8 rtw_usb_tx_queue_mapping_to_qsel (struct rtw_usb *rtwusb, +struct sk_buff *skb) {struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb);
@@ -568,7 +598,8 @@ static u8 rtw_usb_tx_queue_mapping_to_qsel(struct sk_buff *skb) qsel =TX_DESC_QSEL_MGMT ; else if (is_broadcast_ether_addr(hdr->addr1) || is_multicast_ether_addr(hdr->addr1)) - qsel = (info->flags &IEEE80211_TX_CTL_SEND_AFTER_DTIM ) ? + qsel = (info->flags &IEEE80211_TX_CTL_SEND_AFTER_DTIM ) && +rtw_usb_hiq_take_budget (rtwusb) ?TX_DESC_QSEL_HIGH : skb->priority; else if (skb_get_queue_mapping(skb) <= IEEE80211_AC_BK) qsel = skb->priority;
@@ -588,7 +619,7 @@ static int rtw_usb_tx_write(struct rtw_dev *rtwdev,u8 *pkt_desc;int ep; - pkt_info->qsel =rtw_usb_tx_queue_mapping_to_qsel (skb); + pkt_info->qsel =rtw_usb_tx_queue_mapping_to_qsel (rtwusb, skb); pkt_desc =skb_push (skb, chip->tx_pkt_desc_sz);memset (pkt_desc,0 , chip->tx_pkt_desc_sz); ep =qsel_to_ep (rtwusb, pkt_info->qsel);
@@ -1025,6 +1056,10 @@ static int rtw_usb_init_tx(struct rtw_dev *rtwdev)struct rtw_usb *rtwusb =rtw_get_usb_priv (rtwdev);int i; +spin_lock_init (&rtwusb->hiq_lock); + rtwusb->hiq_budget =RTW_USB_HIQ_BUDGET_MAX ; + rtwusb->hiq_refill = jiffies; + rtwusb->txwq =create_singlethread_workqueue ("rtw88_usb: tx wq" );if (!rtwusb->txwq) {rtw_err (rtwdev,"failed to create TX work queue\n" );
drivers/net/wireless/realtek/rtw88/usb.h +5 -0
@@ -75,6 +75,11 @@ struct rtw_usb {u8 out_ep[RTW_USB_EP_MAX ];int qsel_to_ep[TX_DESC_QSEL_MAX ]; +/* protects hiq_budget and hiq_refill */ +spinlock_t hiq_lock; +u32 hiq_budget; +unsigned long hiq_refill; +struct workqueue_struct *txwq, *rxwq;struct sk_buff_head tx_queue[RTW_USB_EP_MAX ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 549/686 wifi: rtw88: usb: only let the frames a dozing station needs use the after-DTIM queue
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mehmet Fide <[email protected]>
[ Upstream commit 185971f1b4eb4ea9059d76cf1a18f992eef998c1 ]
With the budget in place the high queue can no longer take the chip down, but ordinary chatter still competes with the frames a sleeping station actually needs. mac80211 marks every broadcast and multicast frame with IEEE80211_TX_CTL_SEND_AFTER_DTIM while a station dozes, mDNS and SSDP included, so under normal traffic the budget is spent on frames nobody waits for.
Do what the vendor driver does with its default "allow special" high queue filter: admit only ARP, EAPOL and DHCP to the after-DTIM path, the frames a station coming out of power save has to see; everything else goes out on its access category queue at line rate. The frames are classified the way rtw89_core_tx_btc_spec_pkt_notify() does it, from skb->protocol and the network and transport header offsets that mac80211 keeps from the netdev path; EAPOL is the control port flag. Frames the AP relays between its own stations arrive as ETH_P_802_3 and are not inspected, they leave on the access category queue.
With the filter in place the page pool stays at 1803 through the same 180 second storm, a DHCP flood still takes the after-DTIM path (and is then held by the budget), and join/ping cycling without power save is unchanged (10/10).
--- drivers/net/wireless/realtek/rtw88/usb.c | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw88/usb.c +25 -2
@@ -2,9 +2,11 @@/* Copyright(c) 2018-2019 Realtek Corporation */ +#include <linux/ip.h> #include <linux/module.h> -#include <linux/usb.h> #include <linux/mutex.h> +#include <linux/udp.h> +#include <linux/usb.h> #include "main.h" #include "debug.h" #include "mac.h"
@@ -557,6 +559,27 @@ static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)return rtw_usb_write_data (rtwdev, &pkt_info, buf); } +static bool rtw_usb_bmc_needs_dtim (struct sk_buff *skb) +{ +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb); +struct udphdr *udphdr; + +if (info->control.flags &IEEE80211_TX_CTRL_PORT_CTRL_PROTO ) +return true; + +if (skb->protocol ==htons (ETH_P_ARP )) +return true; + +if (skb->protocol ==htons (ETH_P_IP ) && +ip_hdr (skb)->protocol ==IPPROTO_UDP ) { + udphdr =udp_hdr (skb); + +return udphdr->dest ==htons (67 ) || udphdr->dest ==htons (68 ); + } + +return false; +} +#define RTW_USB_HIQ_REFILL_INTERVAL (HZ / 10)/* one unit of budget per 100 ms */ #define RTW_USB_HIQ_BUDGET_MAX 16
@@ -599,7 +622,7 @@ static u8 rtw_usb_tx_queue_mapping_to_qsel(struct rtw_usb *rtwusb,else if (is_broadcast_ether_addr (hdr->addr1) ||is_multicast_ether_addr (hdr->addr1)) qsel = (info->flags &IEEE80211_TX_CTL_SEND_AFTER_DTIM ) && -rtw_usb_hiq_take_budget (rtwusb) ? +rtw_usb_bmc_needs_dtim (skb) &&rtw_usb_hiq_take_budget (rtwusb) ?TX_DESC_QSEL_HIGH : skb->priority;else if (skb_get_queue_mapping (skb) <=IEEE80211_AC_BK ) qsel = skb->priority;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 550/686 wifi: rtw88: widen the ATIM window while an AP interface is up
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mehmet Fide <[email protected]>
[ Upstream commit cf8b516f67652f550e040951b88a2040b375afcf ]
The frames held for dozing stations go out right after the DTIM beacon and only for the duration of the ATIM window. The chips come up with a 2 TU window (the two that program it set 0x2 at init), which drains about three frames per DTIM; the vendor driver sets 0xa or 0xc in AP mode instead. With the 2 TU window the measured page pool exhaustion takes ~100 s of ordinary multicast chatter; at 0x4 the same storm already drains, so 0xa leaves comfortable headroom.
Program 0xa when an AP interface starts and put the default back when it stops, since most chips never initialize the register themselves. The bound and the filter of the previous patches still apply: the window adds drain capacity, the budget protects the pool when that is not enough, the filter keeps chatter off the beacon-paced path.
--- drivers/net/wireless/realtek/rtw88/mac80211.c | 2 ++ drivers/net/wireless/realtek/rtw88/reg.h | 2 ++ 2 files changed, 4 insertions(+)
drivers/net/wireless/realtek/rtw88/mac80211.c +2 -0
@@ -468,6 +468,7 @@ static int rtw_ops_start_ap(struct ieee80211_hw *hw,mutex_lock (&rtwdev->mutex);rtw_write32_set (rtwdev,REG_TCR ,BIT_TCR_UPDATE_HGQMD ); +rtw_write16 (rtwdev,REG_ATIMWND ,ATIMWND_AP ); rtwdev->ap_active = true;rtw_store_op_chan (rtwdev, true); chip->ops->phy_calibration (rtwdev);
@@ -484,6 +485,7 @@ static void rtw_ops_stop_ap(struct ieee80211_hw *hw,mutex_lock (&rtwdev->mutex);rtw_write32_clr (rtwdev,REG_TCR ,BIT_TCR_UPDATE_HGQMD ); +rtw_write16 (rtwdev,REG_ATIMWND ,ATIMWND_DEFAULT ); rtwdev->ap_active = false;if (!rtw_core_check_sta_active (rtwdev))rtw_clear_op_chan (rtwdev);
drivers/net/wireless/realtek/rtw88/reg.h +2 -0
@@ -483,6 +483,8 @@#define REG_DRVERLYINT 0x0558#define REG_BCNDMATIM 0x0559#define REG_ATIMWND 0x055A +#define ATIMWND_DEFAULT 0x2 +#define ATIMWND_AP 0xa#define REG_USTIME_TSF 0x055C#define REG_BCN_MAX_ERR 0x055D#define REG_RXTSF_OFFSET_CCK 0x055E
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 551/686 ovl: fail the mount if the casefold flag has changed
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit c782fc8ada811569811c0fdea5c3412511be95d0 ]
An unprivileged user in a user namespace can repeatedly trigger a kernel warning with their own overlay mounts. They do so by changing the casefold flag of the topmost layer's empty root, the top directory of that layer, after the layers are set and before the mount is created.
The casefold flag of a directory makes name lookups in that directory case-insensitive. All layers of an overlay must agree on casefolding.
ovl_mount_dir_check() reads the casefold flag of a layer root when fsconfig() sets that layer, and saves the result in ofs->casefold. The mount is created later, by another fsconfig() call with FSCONFIG_CMD_CREATE.
The casefold flag of an empty directory can be changed.
The casefold flag of the overlay root must match ofs->casefold. ovl_get_root() copies the flag from the topmost layer root, as it is when the mount is created. On a mismatch, ovl_get_root() only does a WARN_ON(), and the mount continues. The check is not a WARN_ON_ONCE(), so each such mount warns again.
An unprivileged user needs CONFIG_UNICODE, and a tmpfs mounted with the casefold option in their namespace.
Reproduced by changing the casefold flag of the empty upper directory after the layers were set and before FSCONFIG_CMD_CREATE, with tmpfs and ext4 layers, and as uid 1000 in a user namespace.
Fix this by replacing the WARN_ON() with a check that fails the mount with -EINVAL.
[backport: In 6.18, ovl_fill_super() handles credential restoration and filesystem cleanup. Drop the unpublished root dentry and go to out_err, skipping out_free_oe because the root inode already owns oe.]
--- fs/overlayfs/super.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
fs/overlayfs/super.c +11 -1
@@ -1370,7 +1370,6 @@ static struct dentry *ovl_get_root(struct super_block *sb,ovl_dentry_set_flag (OVL_E_CONNECTED , root);ovl_set_upperdata (d_inode (root));ovl_inode_init (d_inode (root), &oip, ino, fsid); -WARN_ON (!!IS_CASEFOLDED (d_inode (root)) != ofs->casefold);ovl_dentry_init_flags (root, upperdentry, oe,DCACHE_OP_WEAK_REVALIDATE );/* root keeps a reference of upperdentry */ dget (upperdentry);
@@ -1576,6 +1575,17 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc)if (!root_dentry) goto out_free_oe; +/* +* The casefold flag of an empty layer root may have changed since the +* mount options were parsed. The root inode owns oe by now. +*/ +if (!!IS_CASEFOLDED (d_inode (root_dentry)) != ofs->casefold) { +pr_err ("casefold flag of the root directory has changed\n" ); +dput (root_dentry); + err = -EINVAL ; + goto out_err; + } + sb->s_root = root_dentry;ovl_revert_creds (old_cred);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 552/686 udf: validate the device specification EA before using it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunpeng Tian <[email protected]>
[ Upstream commit 9a2390959685ac35a58c80c8016120849a2babf6 ]
udf_get_extendedattr() bounds an extended attribute only against struct genericFormat, which is 12 bytes. A type-12 device specification is struct deviceSpec, which is 24 bytes plus a flexible impUse array. Thus a corrupted filesystem can contain extended attribute that is accepted by udf_get_extendedattr() but udf_write_inode() or udf_read_inode() may access beyond the end of provided buffer.
Provide a udf_device_spec_valid() check to validate correctness of extended attribute that is a deviceSpec. While here, check the result of udf_add_extendedattr() before dereferencing it as it can return NULL in case of error.
[JK: Removed duplicated validity checks]
--- fs/udf/inode.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-)
fs/udf/inode.c +37 -5
@@ -1346,6 +1346,26 @@ int udf_setsize(struct inode *inode, loff_t newsize)return err; } +/* +* Verify validity of struct deviceSpec on disk. udf_get_extendedattr() has +* already verified the generic header and made sure attribute fits in the +* inode so we just have to make sure attribute space is large enough for +* deviceSpec struct and required impUse information. +*/ +static bool udf_device_spec_valid (struct deviceSpec *dsea) +{ +u32 attr_length, imp_use_length; + + attr_length =le32_to_cpu (dsea->attrLength); + imp_use_length =le32_to_cpu (dsea->impUseLength); +if (attr_length <sizeof (struct deviceSpec ) || + imp_use_length <sizeof (struct regid ) || + imp_use_length > attr_length -sizeof (struct deviceSpec )) +return false; + +return true; +} +/* * Maximum length of linked list formed by ICB hierarchy. The chosen number is * arbitrary - just that we hopefully don't limit any real use of rewritten
@@ -1664,13 +1684,12 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode)if (S_ISCHR (inode->i_mode) ||S_ISBLK (inode->i_mode)) {struct deviceSpec *dsea = (struct deviceSpec *)udf_get_extendedattr (inode,12 ,1 ); -if (dsea) { -init_special_inode (inode, inode->i_mode, + +if (!dsea || !udf_device_spec_valid (dsea)) + goto out; +init_special_inode (inode, inode->i_mode,MKDEV (le32_to_cpu (dsea->majorDeviceIdent),le32_to_cpu (dsea->minorDeviceIdent))); -/* Developer ID ??? */ - }else - goto out; } ret =0 ; out:
@@ -1818,6 +1837,10 @@ static int udf_update_inode(struct inode *inode, int do_sync)udf_add_extendedattr (inode,sizeof (struct deviceSpec ) +sizeof (struct regid ),12 ,0x3 ); +if (!dsea) { + err = -ENOSPC ; + goto out_unlock; + } dsea->attrType =cpu_to_le32 (12 ); dsea->attrSubtype =1 ; dsea->attrLength = cpu_to_le32(
@@ -1825,6 +1848,10 @@ static int udf_update_inode(struct inode *inode, int do_sync) sizeof(struct regid)); dsea->impUseLength =cpu_to_le32 (sizeof (struct regid )); } +if (!udf_device_spec_valid (dsea)) { + err = -EFSCORRUPTED ; + goto out_unlock; + } eid = (struct regid *)dsea->impUse;memset (eid,0 ,sizeof (*eid));strcpy (eid->ident,UDF_ID_DEVELOPER );
@@ -1966,6 +1993,11 @@ static int udf_update_inode(struct inode *inode, int do_sync)brelse (bh);return err; + +out_unlock: +unlock_buffer (bh); +brelse (bh); +return err; } struct inode *__udf_iget(struct super_block *sb, struct kernel_lb_addr *ino,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 553/686 hwmon: (tmp108) Fix jiffies wraparound in conversion-ready check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tom Verdonck <[email protected]>
[ Upstream commit 6b8b1d1d7bc7e579b53fc7c3293b787d68de702a ]
tmp108 records a one-shot deadline in ->ready_time at probe (and resume) and, on every temperature read, refuses the read with -EAGAIN while time_before(jiffies, ready_time) is true, in order to skip the initial conversion.
->ready_time is an unsigned long compared with time_before(), whose signed difference is only meaningful while the two values are within LONG_MAX jiffies of each other. Because ->ready_time is set once and never refreshed, jiffies keeps advancing away from it, and after 2^31 jiffies the difference flips sign. On a 32-bit HZ=100 kernel that happens ~248.5 days after boot: time_before() then permanently reports "not ready" and the driver returns -EAGAIN on every read, without ever touching the sensor, until the next reboot. The continuous-mode path, which sets ->ready_time to jiffies with no added conversion delay, wraps the same way.
Store the deadline as a 64-bit jiffies value and compare it with get_jiffies_64()/time_before64(), which does not wrap in any practical uptime.
--- drivers/hwmon/tmp108.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hwmon/tmp108.c +4 -4
@@ -74,7 +74,7 @@struct tmp108 {struct regmap *regmap;u16 orig_config; -unsigned long ready_time; +u64 ready_time; };/* convert 12-bit TMP108 register value to milliCelsius */
@@ -125,7 +125,7 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input:/* Is it too early to return a conversion ? */ -if (time_before (jiffies, tmp108->ready_time)) { +if (time_before64 (get_jiffies_64 (), tmp108->ready_time)) {dev_dbg (dev,"%s: Conversion not ready yet..\n" , __func__);return -EAGAIN ;
@@ -362,7 +362,7 @@ static int tmp108_common_probe(struct device *dev, struct regmap *regmap, char *return err; } - tmp108->ready_time = jiffies; + tmp108->ready_time =get_jiffies_64 ();if ((tmp108->orig_config &TMP108_CONF_MODE_MASK ) ==TMP108_MODE_SHUTDOWN ) tmp108->ready_time +=
@@ -413,7 +413,7 @@ static int tmp108_resume(struct device *dev) err =regmap_update_bits (tmp108->regmap,TMP108_REG_CONF ,TMP108_CONF_MODE_MASK ,TMP108_MODE_CONTINUOUS ); - tmp108->ready_time = jiffies + + tmp108->ready_time =get_jiffies_64 () +msecs_to_jiffies (TMP108_CONVERSION_TIME_MS );return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 554/686 dmaengine: qcom: bam_dma: Defer IRQ trigger type to device tree
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vishnu Santhosh <[email protected]>
[ Upstream commit 3cee6f79553202d7d3954555560ac38d719344b8 ]
The driver hardcodes IRQF_TRIGGER_HIGH when registering the BAM interrupt, which overrides the trigger type specified in the device tree. On Qualcomm Shikra SoC, the A2 BAM signals an edge interrupt to the apps processor; registering it as level-high causes the interrupt to not fire, resulting in missed DMA completions.
Use IRQF_TRIGGER_NONE instead, which causes the kernel to use the trigger type already configured by platform_get_irq() when it parsed the device tree interrupts property. This makes the driver platform-agnostic.
Stable-dep-of: 82eed160cfa7 ("dmaengine: qcom: bam_dma: free interrupt before the clock in error path")
--- drivers/dma/qcom/bam_dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/qcom/bam_dma.c +1 -1
@@ -1323,7 +1323,7 @@ static int bam_dma_probe(struct platform_device *pdev)bam_channel_init (bdev, &bdev->channels[i], i); ret =devm_request_irq (bdev->dev, bdev->irq, bam_dma_irq, -IRQF_TRIGGER_HIGH ,"bam_dma" , bdev); +IRQF_TRIGGER_NONE ,"bam_dma" , bdev);if (ret) goto err_bam_channel_exit;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 555/686 dmaengine: qcom: bam_dma: free interrupt before the clock in error path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 82eed160cfa7a296ae4eb5acb8dd8f493323eea7 ]
The BAM interrupt is requested with a devres helper and so on error it's freed after probe() returns. We disable the clock before freeing or masking it so it may still fire and we may end up reading BAM registers with clock disabled.
Stop using devres for interrupts as we free it in remove() manually anyway. Add an appropriate label and free the interrupt before disabling the clock in error path and in remove().
--- drivers/dma/qcom/bam_dma.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/dma/qcom/bam_dma.c +6 -4
@@ -1322,8 +1322,8 @@ static int bam_dma_probe(struct platform_device *pdev)for (i =0 ; i < bdev->num_channels; i++)bam_channel_init (bdev, &bdev->channels[i], i); - ret =devm_request_irq (bdev->dev, bdev->irq, bam_dma_irq, -IRQF_TRIGGER_NONE ,"bam_dma" , bdev); + ret =request_irq (bdev->irq, bam_dma_irq,IRQF_TRIGGER_NONE , +"bam_dma" , bdev);if (ret) goto err_bam_channel_exit;
@@ -1356,7 +1356,7 @@ static int bam_dma_probe(struct platform_device *pdev) ret =dma_async_device_register (&bdev->common);if (ret) {dev_err (bdev->dev,"failed to register dma async device\n" ); - goto err_bam_channel_exit; + goto err_free_irq; } ret = of_dma_controller_register(pdev->dev.of_node, bam_dma_xlate,
@@ -1375,6 +1375,8 @@ static int bam_dma_probe(struct platform_device *pdev) err_unregister_dma:dma_async_device_unregister (&bdev->common); +err_free_irq: +free_irq (bdev->irq, bdev); err_bam_channel_exit:for (i =0 ; i < bdev->num_channels; i++)tasklet_kill (&bdev->channels[i].vc.task);
@@ -1400,7 +1402,7 @@ static void bam_dma_remove(struct platform_device *pdev)/* mask all interrupts for this execution environment */ writel_relaxed (0 ,bam_addr (bdev,0 ,BAM_IRQ_SRCS_MSK_EE )); -devm_free_irq (bdev->dev, bdev->irq, bdev); +free_irq (bdev->irq, bdev);for (i =0 ; i < bdev->num_channels; i++) {bam_dma_terminate_all (&bdev->channels[i].vc.chan);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 556/686 ASoC: stm: stm32_i2s: Drop redundant error messages
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit a6cdfb6230944082e7be64f9166eed64656b1162 ]
Both devm_request_irq() and snd_dmaengine_pcm_register() already log failures internally. Drop the redundant error messages and return the original errors directly.
Stable-dep-of: 1b207c85551f ("ASoC: stm: stm32_i2s: request IRQ after regmap initialization")
--- sound/soc/stm/stm32_i2s.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
sound/soc/stm/stm32_i2s.c +2 -4
@@ -1245,10 +1245,8 @@ static int stm32_i2s_parse_dt(struct platform_device *pdev, ret =devm_request_irq (&pdev->dev, irq, stm32_i2s_isr,0 ,dev_name (&pdev->dev), i2s); -if (ret) { -dev_err (&pdev->dev,"irq request returned %d\n" , ret); +if (ret)return ret; - }/* Reset */ rst =devm_reset_control_get_optional_exclusive (&pdev->dev,NULL );
@@ -1302,7 +1300,7 @@ static int stm32_i2s_probe(struct platform_device *pdev) ret =snd_dmaengine_pcm_register (&pdev->dev, &stm32_i2s_pcm_config,0 );if (ret) -return dev_err_probe (&pdev->dev, ret,"PCM DMA register error\n" ); +return ret; ret =snd_soc_register_component (&pdev->dev, &stm32_i2s_component, i2s->dai_drv,1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 557/686 ASoC: stm: stm32_i2s: request IRQ after regmap initialization
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 1b207c85551fd74854d632116849295b2305245f ]
The ISR accesses the managed regmap, but probe requests the IRQ before creating it. An early interrupt can reach an uninitialized regmap. Reverse-order cleanup can free the regmap while the IRQ remains active.
Request the IRQ after regmap initialization so probe unwind and removal free and synchronize it before releasing the regmap.
The teardown ordering issue was found by static analysis.
--- sound/soc/stm/stm32_i2s.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
sound/soc/stm/stm32_i2s.c +11 -12
@@ -1192,7 +1192,7 @@ static int stm32_i2s_parse_dt(struct platform_device *pdev,struct device_node *np = pdev->dev.of_node;struct reset_control *rst;struct resource *res; -int irq, ret; +int ret;if (!np)return -ENODEV ;
@@ -1238,16 +1238,6 @@ static int stm32_i2s_parse_dt(struct platform_device *pdev,return ret; } -/* Get irqs */ - irq =platform_get_irq (pdev,0 ); -if (irq <0 ) -return irq; - - ret =devm_request_irq (&pdev->dev, irq, stm32_i2s_isr,0 , -dev_name (&pdev->dev), i2s); -if (ret) -return ret; -/* Reset */ rst =devm_reset_control_get_optional_exclusive (&pdev->dev,NULL );if (IS_ERR (rst))
@@ -1272,7 +1262,7 @@ static int stm32_i2s_probe(struct platform_device *pdev) {struct stm32_i2s_data *i2s;u32 val; -int ret; +int irq, ret; i2s =devm_kzalloc (&pdev->dev,sizeof (*i2s),GFP_KERNEL );if (!i2s)
@@ -1298,6 +1288,15 @@ static int stm32_i2s_probe(struct platform_device *pdev)return dev_err_probe (&pdev->dev,PTR_ERR (i2s->regmap),"Regmap init error\n" ); + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + ret =devm_request_irq (&pdev->dev, irq, stm32_i2s_isr,0 , +dev_name (&pdev->dev), i2s); +if (ret) +return ret; + ret =snd_dmaengine_pcm_register (&pdev->dev, &stm32_i2s_pcm_config,0 );if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 558/686 iio: dac: mcp4821: reject devices without match data
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 6ac1faf4de61dcf27ffe8f2c25d96fe5f4b2886d ]
A device bound through driver_override need not match an entry in the driver tables. In that case spi_get_device_match_data() returns NULL, but mcp4821_probe() dereferences the result while configuring the IIO device.
Reject devices without match data before using the chip information.
--- drivers/iio/dac/mcp4821.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iio/dac/mcp4821.c +5 -2
@@ -172,9 +172,13 @@ static const struct iio_info mcp4821_info = {static int mcp4821_probe (struct spi_device *spi) { +const struct mcp4821_chip_info *info;struct iio_dev *indio_dev;struct mcp4821_state *state; -const struct mcp4821_chip_info *info; + + info =spi_get_device_match_data (spi); +if (!info) +return -ENODATA ; indio_dev =devm_iio_device_alloc (&spi->dev,sizeof (*state));if (indio_dev ==NULL )
@@ -183,7 +187,6 @@ static int mcp4821_probe(struct spi_device *spi) state =iio_priv (indio_dev); state->spi = spi; - info =spi_get_device_match_data (spi); indio_dev->name = info->name; indio_dev->info = &mcp4821_info; indio_dev->modes =INDIO_DIRECT_MODE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 559/686 ALSA: hda/realtek: Add codec SSID quirk for Lenovo Yoga Pro 9 16IMH9
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rámon van Raaij <[email protected]>
[ Upstream commit 56722cfbb78d7eb41756cd78dc5192d08bd14f3d ]
The Yoga Pro 9 16IMH9 (codec SSID 17aa:38d6) shares PCI audio device subsystem ID 17aa:3811 with the Legion S7 15IMH05. The existing SND_PCI_QUIRK entry for the Legion routes both machines to ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS, which does not bind the TAS2781 smart amplifiers, resulting in near-silent built-in speakers.
Add an HDA_CODEC_QUIRK entry immediately before the conflicting PCI quirk that matches the Yoga Pro 9's unique codec SSID and routes it to ALC287_FIXUP_TAS2781_I2C. Codec quirks are evaluated after PCI quirks and take precedence, leaving the Legion S7 15IMH05 entry unaffected.
This follows the same pattern used to disambiguate PCI SSID 17aa:3847 (shared between Yoga Pro 7 14IMH9 and Legion 7 16ACHG6), where a HDA_CODEC_QUIRK for codec SSID 17aa:38cf resolves the conflict.
Stable-dep-of: 1c36207da794 ("ALSA: hda/realtek: Fix silent speakers on Lenovo Legion S7 15IMH05")
--- sound/hda/codecs/realtek/alc269.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/hda/codecs/realtek/alc269.c +4 -0
@@ -7544,6 +7544,10 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x17aa ,0x3801 ,"Lenovo Yoga9 14IAP7" ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN ),HDA_CODEC_QUIRK (0x17aa ,0x3802 ,"DuetITL 2021" ,ALC287_FIXUP_YOGA7_14ITL_SPEAKERS ),SND_PCI_QUIRK (0x17aa ,0x3802 ,"Lenovo Yoga Pro 9 14IRP8" ,ALC287_FIXUP_TAS2781_I2C ), +/* Yoga Pro 9 16IMH9 shares PCI SSID 17aa:3811 with Legion S7 15IMH05; +* use codec SSID to distinguish them +*/ +HDA_CODEC_QUIRK (0x17aa ,0x38d6 ,"Lenovo Yoga Pro 9 16IMH9" ,ALC287_FIXUP_TAS2781_I2C ),SND_PCI_QUIRK (0x17aa ,0x3811 ,"Legion S7 15IMH05" ,ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS ),SND_PCI_QUIRK (0x17aa ,0x3813 ,"Legion 7i 15IMHG05" ,ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS ), SND_PCI_QUIRK(0x17aa, 0x3818, "Lenovo C940 / Yoga Duet 7", ALC298_FIXUP_LENOVO_C940_DUET7),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 560/686 ALSA: hda/realtek: Fix Legion 7 16ITHG6 speaker amp binding
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Bonello <[email protected]>
[ Upstream commit dd074f04e04648d89d9d10ae9846cd057c97b385 ]
The Lenovo Legion 7 16ITHG6 uses codec SSID 17aa:3855, but its PCI SSID is 17aa:3811. The latter is now also used by the Legion S7 15IMH05 quirk, which is matched before codec SSID fallback and incorrectly routes Legion 7 16ITHG6 machines to ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS.
That fixup does not bind the CLSA0101 CS35L41 companion amplifiers, making the built-in speakers silent even though playback appears to be active.
Add a codec SSID quirk for 17aa:3855 before the conflicting PCI SSID quirk so that the Legion 7 16ITHG6 uses ALC287_FIXUP_LEGION_16ITHG6. This restores CS35L41 firmware loading and binds both speaker amplifiers.
Stable-dep-of: 1c36207da794 ("ALSA: hda/realtek: Fix silent speakers on Lenovo Legion S7 15IMH05")
--- sound/hda/codecs/realtek/alc269.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
sound/hda/codecs/realtek/alc269.c +3 -2
@@ -7544,10 +7544,11 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x17aa ,0x3801 ,"Lenovo Yoga9 14IAP7" ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN ),HDA_CODEC_QUIRK (0x17aa ,0x3802 ,"DuetITL 2021" ,ALC287_FIXUP_YOGA7_14ITL_SPEAKERS ),SND_PCI_QUIRK (0x17aa ,0x3802 ,"Lenovo Yoga Pro 9 14IRP8" ,ALC287_FIXUP_TAS2781_I2C ), -/* Yoga Pro 9 16IMH9 shares PCI SSID 17aa:3811 with Legion S7 15IMH05; -* use codec SSID to distinguish them +/* Yoga Pro 9 16IMH9 and Legion 7 16ITHG6 share PCI SSID 17aa:3811 +* with Legion S7 15IMH05; use codec SSID to distinguish them */ HDA_CODEC_QUIRK (0x17aa ,0x38d6 ,"Lenovo Yoga Pro 9 16IMH9" ,ALC287_FIXUP_TAS2781_I2C ), +HDA_CODEC_QUIRK (0x17aa ,0x3855 ,"Legion 7 16ITHG6" ,ALC287_FIXUP_LEGION_16ITHG6 ),SND_PCI_QUIRK (0x17aa ,0x3811 ,"Legion S7 15IMH05" ,ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS ),SND_PCI_QUIRK (0x17aa ,0x3813 ,"Legion 7i 15IMHG05" ,ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS ), SND_PCI_QUIRK(0x17aa, 0x3818, "Lenovo C940 / Yoga Duet 7", ALC298_FIXUP_LENOVO_C940_DUET7),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 561/686 ALSA: hda/realtek: Fix silent speakers on Lenovo Legion S7 15IMH05
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matej Sochan <[email protected]>
[ Upstream commit 1c36207da79455402d981125fa09716991364e66 ]
The speakers on the Legion S7 15IMH05 (PCI SSID 17aa:3811, ALC287) stay silent after a cold boot with the current quirk, which applies ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS. They only start working after a suspend/resume cycle.
The amplifier setup is sent through COEF 0x24/0x26 on NID 0x20. On this machine the first pass of that sequence appears to only wake the amplifiers. Sending the identical sequence a second time makes both speakers work, provided the second write comes a few milliseconds after the first: back-to-back writes leave the speakers silent, a 7 ms gap makes only the right speaker work, and 8 ms or more is reliable. A dump of all COEF registers of NID 0x20 taken before and after the second write shows no difference.
Add a dedicated fixup that writes the sequence, waits 20 ms to keep a margin over the measured minimum, and writes it again on every codec init. It chains to the same AUTOMUTE fixup as before. To share the sequence, move the verbs of ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS into a named array; this has no functional change for the other users of that fixup.
--- sound/hda/codecs/realtek/alc269.c | 92 +++++++++++++++++++------------ 1 file changed, 56 insertions(+), 36 deletions(-)
sound/hda/codecs/realtek/alc269.c +56 -36
@@ -3937,6 +3937,7 @@ enum {ALC236_FIXUP_HP_LIMIT_INT_MIC_BOOST ,ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS ,ALC287_FIXUP_LEGION_15IMHG05_AUTOMUTE , +ALC287_FIXUP_LEGION_S7_15IMH05_AMP ,ALC287_FIXUP_YOGA7_14ITL_SPEAKERS ,ALC298_FIXUP_LENOVO_C940_DUET7 , ALC287_FIXUP_LENOVO_YOGA_BOOK_9I,
@@ -4058,6 +4059,53 @@ static void alc700_fixup_intel_hades_canyon(struct hda_codec *codec,alc_update_coef_idx (codec,0x1b ,0x0400 ,0x0400 ); } +static const struct hda_verb legion_amp_verbs[] = { +/* left speaker */ + {0x20 ,AC_VERB_SET_COEF_INDEX ,0x24 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x41 }, + {0x20 ,AC_VERB_SET_COEF_INDEX ,0x26 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0xc }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x1a }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0xb020 }, + {0x20 ,AC_VERB_SET_COEF_INDEX ,0x26 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x2 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0xb020 }, + +/* right speaker */ + {0x20 ,AC_VERB_SET_COEF_INDEX ,0x24 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x42 }, + {0x20 ,AC_VERB_SET_COEF_INDEX ,0x26 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0xc }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x2a }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0xb020 }, + {0x20 ,AC_VERB_SET_COEF_INDEX ,0x26 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x2 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, + {0x20 ,AC_VERB_SET_PROC_COEF ,0xb020 }, + {} +}; + +static void alc287_fixup_legion_s7_amp (struct hda_codec *codec, +const struct hda_fixup *fix,int action) +{ +if (action !=HDA_FIXUP_ACT_INIT ) +return ; + +snd_hda_sequence_write (codec, legion_amp_verbs); +/* +* The amplifiers accept the setup only a few ms after the first +* write (8 ms is the measured minimum on the test machine), so +* keep a margin. +*/ +msleep (20 ); +snd_hda_sequence_write (codec, legion_amp_verbs); +} +static const struct hda_fixup alc269_fixups[] = { [ALC233_FIXUP_WUJIE_SPEAKERS ] = { .type =HDA_FIXUP_PINS ,
@@ -6054,41 +6102,13 @@ static const struct hda_fixup alc269_fixups[] = { }, [ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS] = { .type = HDA_FIXUP_VERBS, -//.v.verbs = legion_15imhg05_coefs, - .v.verbs = (const struct hda_verb []) { -// set left speaker Legion 7i. - {0x20 ,AC_VERB_SET_COEF_INDEX ,0x24 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x41 }, - - {0x20 ,AC_VERB_SET_COEF_INDEX ,0x26 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0xc }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x1a }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0xb020 }, - - {0x20 ,AC_VERB_SET_COEF_INDEX ,0x26 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x2 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0xb020 }, - -// set right speaker Legion 7i. - {0x20 ,AC_VERB_SET_COEF_INDEX ,0x24 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x42 }, - - {0x20 ,AC_VERB_SET_COEF_INDEX ,0x26 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0xc }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x2a }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0xb020 }, - - {0x20 ,AC_VERB_SET_COEF_INDEX ,0x26 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x2 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0x0 }, - {0x20 ,AC_VERB_SET_PROC_COEF ,0xb020 }, - {} - }, + .v.verbs = legion_amp_verbs, + .chained = true, + .chain_id = ALC287_FIXUP_LEGION_15IMHG05_AUTOMUTE, + }, + [ALC287_FIXUP_LEGION_S7_15IMH05_AMP] = { + .type = HDA_FIXUP_FUNC, + .v.func = alc287_fixup_legion_s7_amp, .chained = true, .chain_id = ALC287_FIXUP_LEGION_15IMHG05_AUTOMUTE, },
@@ -7549,7 +7569,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {*/ HDA_CODEC_QUIRK (0x17aa ,0x38d6 ,"Lenovo Yoga Pro 9 16IMH9" ,ALC287_FIXUP_TAS2781_I2C ),HDA_CODEC_QUIRK (0x17aa ,0x3855 ,"Legion 7 16ITHG6" ,ALC287_FIXUP_LEGION_16ITHG6 ), -SND_PCI_QUIRK (0x17aa ,0x3811 ,"Legion S7 15IMH05" ,ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS ), +SND_PCI_QUIRK (0x17aa ,0x3811 ,"Legion S7 15IMH05" ,ALC287_FIXUP_LEGION_S7_15IMH05_AMP ),SND_PCI_QUIRK (0x17aa ,0x3813 ,"Legion 7i 15IMHG05" ,ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS ),SND_PCI_QUIRK (0x17aa ,0x3818 ,"Lenovo C940 / Yoga Duet 7" ,ALC298_FIXUP_LENOVO_C940_DUET7 ), SND_PCI_QUIRK(0x17aa, 0x3819, "Lenovo 13s Gen2 ITL", ALC287_FIXUP_13S_GEN2_SPEAKERS),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 562/686 spi: atmel-quadspi: add controller init callback
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robert Marko <[email protected]>
[ Upstream commit cbbd5a945e85e7835ac5792d855d85c20e40d1e3 ]
Allow controller variants to provide a custom initialization callback through their capability data.
This prepares the driver for variants which require a different hardware initialization sequence without adding SoC checks to the common path.
Stable-dep-of: 717e45f97246 ("spi: atmel-quadspi: balance runtime PM and pclk across system sleep")
--- drivers/spi/atmel-quadspi.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/spi/atmel-quadspi.c +9 -0
@@ -256,8 +256,11 @@ static const struct atmel_qspi_pcal pcal[ATMEL_QSPI_PCAL_ARRAY_SIZE] = { {200000000, 7}, }; +struct atmel_qspi; + struct atmel_qspi_caps { u32 max_speed_hz; + int (*init)(struct atmel_qspi *aq); bool has_qspick; bool has_gclk; bool has_ricr;
@@ -1156,6 +1159,9 @@ static int atmel_qspi_sama7g5_setup(struct spi_device *spi)/* The controller can communicate with a single peripheral device (target). */ aq->target_max_speed_hz = spi->max_speed_hz; +if (aq->caps->init) +return aq->caps->init (aq); +return atmel_qspi_sama7g5_init (aq); }
@@ -1571,6 +1577,9 @@ static int __maybe_unused atmel_qspi_resume(struct device *dev)return ret; } +if (aq->caps->init) +return aq->caps->init (aq); +if (aq->caps->has_gclk)return atmel_qspi_sama7g5_init (aq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 563/686 spi: atmel-quadspi: use init callback for gclk variants
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robert Marko <[email protected]>
[ Upstream commit b881f1d8d1dfbc4480776d3b16f80261a5a68cbc ]
Assign the existing SAMA7G5 initialization routine to every generic clock variant and dispatch initialization exclusively through the capability callback.
This keeps hardware capabilities separate from initialization selection and lets variants override the sequence explicitly.
Stable-dep-of: 717e45f97246 ("spi: atmel-quadspi: balance runtime PM and pclk across system sleep")
--- drivers/spi/atmel-quadspi.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/spi/atmel-quadspi.c +7 -8
@@ -1159,10 +1159,7 @@ static int atmel_qspi_sama7g5_setup(struct spi_device *spi)/* The controller can communicate with a single peripheral device (target). */ aq->target_max_speed_hz = spi->max_speed_hz; -if (aq->caps->init) -return aq->caps->init (aq); - -return atmel_qspi_sama7g5_init (aq); +return aq->caps->init (aq); }static int atmel_qspi_setup (struct spi_device *spi)
@@ -1577,11 +1574,8 @@ static int __maybe_unused atmel_qspi_resume(struct device *dev)return ret; } -if (aq->caps->init) -return aq->caps->init (aq); -if (aq->caps->has_gclk) -return atmel_qspi_sama7g5_init (aq); +return aq->caps->init (aq); ret =pm_runtime_force_resume (dev);if (ret <0 )
@@ -1639,6 +1633,7 @@ static const struct atmel_qspi_caps atmel_sam9x60_qspi_caps = {static const struct atmel_qspi_caps atmel_sam9x7_ospi_caps = { .max_speed_hz =SAM9X7_QSPI_MAX_SPEED_HZ , + .init = atmel_qspi_sama7g5_init, .has_gclk = true, .octal = true, .has_dma = true,
@@ -1649,6 +1644,7 @@ static const struct atmel_qspi_caps atmel_sam9x7_ospi_caps = {static const struct atmel_qspi_caps atmel_sama7d65_ospi_caps = { .max_speed_hz =SAMA7G5_QSPI0_MAX_SPEED_HZ , + .init = atmel_qspi_sama7g5_init, .has_gclk = true, .octal = true, .has_dma = true,
@@ -1659,6 +1655,7 @@ static const struct atmel_qspi_caps atmel_sama7d65_ospi_caps = {static const struct atmel_qspi_caps atmel_sama7d65_qspi_caps = { .max_speed_hz =SAMA7G5_QSPI1_SDR_MAX_SPEED_HZ , + .init = atmel_qspi_sama7g5_init, .has_gclk = true, .has_dma = true, .has_2xgclk = true,
@@ -1667,6 +1664,7 @@ static const struct atmel_qspi_caps atmel_sama7d65_qspi_caps = {static const struct atmel_qspi_caps atmel_sama7g5_ospi_caps = { .max_speed_hz =SAMA7G5_QSPI0_MAX_SPEED_HZ , + .init = atmel_qspi_sama7g5_init, .has_gclk = true, .octal = true, .has_dma = true,
@@ -1676,6 +1674,7 @@ static const struct atmel_qspi_caps atmel_sama7g5_ospi_caps = {static const struct atmel_qspi_caps atmel_sama7g5_qspi_caps = { .max_speed_hz =SAMA7G5_QSPI1_SDR_MAX_SPEED_HZ , + .init = atmel_qspi_sama7g5_init, .has_gclk = true, .has_dma = true, .has_dllon = true,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 564/686 spi: atmel-quadspi: balance runtime PM and pclk across system sleep
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 717e45f97246d1070cdf86ccd7a0fb872b45933a ]
On the controllers with a generic clock (SAMA7G5, SAMA7D65, SAM9X7 and LAN969x), atmel_qspi_suspend() takes a runtime PM reference and returns without dropping it or suspending the device. It disables the peripheral clock directly. atmel_qspi_resume() only prepares the peripheral clock and then reinitializes the controller with that clock still off.
On a SAM9X75 Curiosity board, the tested standby and mem resumes failed:
atmel_qspi f0014000.spi: PM: failed to resume: error -110 spi-nor spi0.0: resume() failed
Reading the flash afterwards returned no data. The runtime usage count grew by one with each cycle, and the second suspend disabled the peripheral clock again:
WARNING: drivers/clk/clk.c:1257 at clk_core_disable+0x6c/0xcc qspi_clk already disabled
Use the same runtime PM sequence as the other variants. Suspend disables the controller and forces a runtime suspend. Resume forces a runtime resume, which enables the peripheral clock, before it runs the init callback, and drops the reference afterwards. With this change the tested resumes succeed on the board in both modes, the controller returns to runtime suspend, and the flash reads back.
--- drivers/spi/atmel-quadspi.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/spi/atmel-quadspi.c +13 -11
@@ -1543,12 +1543,14 @@ static int __maybe_unused atmel_qspi_suspend(struct device *dev)if (aq->caps->has_gclk) { ret =atmel_qspi_sama7g5_suspend (aq); -clk_disable_unprepare (aq->pclk); -return ret; +if (ret) { +pm_runtime_put_autosuspend (dev); +return ret; + } + }else { +atmel_qspi_write (QSPI_CR_QSPIDIS , aq,QSPI_CR ); } -atmel_qspi_write (QSPI_CR_QSPIDIS , aq,QSPI_CR ); -pm_runtime_mark_last_busy (dev);pm_runtime_force_suspend (dev);
@@ -1574,20 +1576,20 @@ static int __maybe_unused atmel_qspi_resume(struct device *dev)return ret; } -if (aq->caps->has_gclk) -return aq->caps->init (aq); - ret =pm_runtime_force_resume (dev);if (ret <0 )return ret; -atmel_qspi_init (aq); - -atmel_qspi_write (aq->scr, aq,QSPI_SCR ); +if (aq->caps->has_gclk) { + ret = aq->caps->init (aq); + }else { +atmel_qspi_init (aq); +atmel_qspi_write (aq->scr, aq,QSPI_SCR ); + }pm_runtime_put_autosuspend (dev); -return 0 ; +return ret; }static int __maybe_unused atmel_qspi_runtime_suspend (struct device *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 565/686 vfio/pci: Restore 8-byte ioeventfd support
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li RongQing <[email protected]>
[ Upstream commit b30b52c2fb82e6d38ee2845a4d85e8254b44f3d8 ]
Commit b44a06bd28f2 ("vfio/pci: Remove #ifdef iowrite64 and #ifdef ioread64") inadvertently converted a conditional 8-byte rejection into an unconditional one.
Originally, 'count == 8' was rejected only if iowrite64 was undefined (#ifndef iowrite64). When iowrite64 became globally available via generic fallbacks, this rejection became dead code, allowing 8-byte ioeventfds. However, b44a06bd28f2 removed the #ifndef wrappers but left the nested 'if (count == 8) return -EINVAL;' intact, breaking all 8-byte registrations.
Drop the unconditional check to restore 8-byte ioeventfd support, matching the original intent.
--- drivers/vfio/pci/vfio_pci_rdwr.c | 3 --- 1 file changed, 3 deletions(-)
drivers/vfio/pci/vfio_pci_rdwr.c +0 -3
@@ -449,9 +449,6 @@ int vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset, pos >= vdev->msix_offset + vdev->msix_size))return -EINVAL ; -if (count ==8 ) -return -EINVAL ; - ret =vfio_pci_core_setup_barmap (vdev, bar);if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 566/686 ata: libata: Add an argument to ata_eh_reset()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 4b3c2ca268b0a66093793466e02d8566d642f19c ]
Pass the ATA port pointer as first argument to ata_eh_reset(). No functionality has been changed. This patch prepares for enabling lock context analysis. Without this patch, lockdep_assert_held() statements would have to be added before each ata_eh_reset() call because the compiler doesn't know that ap->link.p == ap. See also ata_link_init().
Stable-dep-of: 96fdeb7e3fd8 ("ata: sata_inic162x: remove dangerous broken driver")
--- drivers/ata/libata-eh.c | 6 +++--- drivers/ata/libata-pmp.c | 2 +- drivers/ata/libata.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/ata/libata-eh.c +3 -3
@@ -2812,10 +2812,9 @@ static bool ata_eh_followup_srst_needed(struct ata_link *link, int rc)return false; } -int ata_eh_reset (struct ata_link *link,int classify, +int ata_eh_reset (struct ata_port *ap,struct ata_link *link,int classify,struct ata_reset_operations *reset_ops) { -struct ata_port *ap = link->ap;struct ata_link *slave = ap->slave_link;struct ata_eh_context *ehc = &link->eh_context;struct ata_eh_context *sehc = slave ? &slave->eh_context :NULL ;
@@ -3863,7 +3862,8 @@ int ata_eh_recover(struct ata_port *ap, struct ata_reset_operations *reset_ops,if (!(ehc->i.action &ATA_EH_RESET ))continue ; - rc =ata_eh_reset (link,ata_link_nr_vacant (link), reset_ops); + rc =ata_eh_reset (ap, link,ata_link_nr_vacant (link), + reset_ops);if (rc) {ata_link_err (link,"reset failed, giving up\n" ); goto out;
drivers/ata/libata-pmp.c +1 -1
@@ -796,7 +796,7 @@ static int sata_pmp_eh_recover_pmp(struct ata_port *ap,struct ata_link *tlink;/* reset */ - rc =ata_eh_reset (link,0 , reset_ops); + rc =ata_eh_reset (ap, link,0 , reset_ops);if (rc) {ata_link_err (link,"failed to reset PMP, giving up\n" ); goto fail;
drivers/ata/libata.h +2 -2
@@ -192,8 +192,8 @@ extern void ata_eh_done(struct ata_link *link, struct ata_device *dev,extern void ata_eh_autopsy (struct ata_port *ap);const char *ata_get_cmd_name (u8 command);extern void ata_eh_report (struct ata_port *ap); -extern int ata_eh_reset (struct ata_link *link,int classify, -struct ata_reset_operations *reset_ops); +extern int ata_eh_reset (struct ata_port *ap,struct ata_link *link, +int classify,struct ata_reset_operations *reset_ops);extern int ata_eh_recover (struct ata_port *ap,struct ata_reset_operations *reset_ops,struct ata_link **r_failed_disk);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 567/686 ata: sata_inic162x: remove dangerous broken driver
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ethan Nelson-Moore <[email protected]>
[ Upstream commit 96fdeb7e3fd8d937f8351ed90824c9d904e590a1 ]
The sata_inic162x driver was labeled as "very experimental" in commit bb9696192826 ("libata: make it clear that sata_inic162x is experimental") due to data corruption issues, but not marked as broken. Since then, no changes have been made to it that could fix these issues. Since the driver was not marked as broken, and the message about potential data corruption is only visible in the code and dmesg, it is possible that someone could enable the driver without realizing its potential for data corruption. Remove the driver to protect users' data.
--- drivers/ata/Kconfig | 7 - drivers/ata/Makefile | 1 - drivers/ata/sata_inic162x.c | 902 ------------------------------------ 3 files changed, 910 deletions(-) delete mode 100644 drivers/ata/sata_inic162x.c
drivers/ata/Kconfig +0 -7
@@ -329,13 +329,6 @@ config SATA_AHCI_SEATTLE If unsure, say N -config SATA_INIC162X - tristate "Initio 162x SATA support (Very Experimental)" - depends on PCI - select SATA_HOST - help - This option enables support for Initio 162x Serial ATA. - config SATA_ACARD_AHCI tristate "ACard AHCI variant (ATP 8620)" depends on PCI
drivers/ata/Makefile +0 -1
@@ -9,7 +9,6 @@ obj-$(CONFIG_SATA_AHCI_SEATTLE) += ahci_seattle.o libahci.o libahci_platform.o obj-$(CONFIG_SATA_AHCI_PLATFORM) += ahci_platform.o libahci.o libahci_platform.o obj-$(CONFIG_SATA_FSL) += sata_fsl.o obj-$(CONFIG_SATA_GEMINI) += sata_gemini.o -obj-$(CONFIG_SATA_INIC162X) += sata_inic162x.o obj-$(CONFIG_SATA_SIL24) += sata_sil24.o obj-$(CONFIG_SATA_DWC) += sata_dwc_460ex.o obj-$(CONFIG_SATA_HIGHBANK) += sata_highbank.o libahci.o
drivers/ata/sata_inic162x.c deleted +0 -902
902 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 568/686 f2fs: zone: fix to avoid bio split on sequential zone
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit b9b036bd1e2cfbc189d5811d62d8711e216c40b3 ]
In the block layer, bio_split_to_limits() splits a bio if it exceeds any underlying queue limits:
1. queue_max_sectors: Splits bios larger than the transfer limit. This limit is set by the device driver/DMA controller (max_hw_sectors) and device-mapper targets. When flushing dirty pages (governed by VFS writeback_chunk_size() and f2fs nr_pages_to_skip()), f2fs merges contiguous pages into bios up to 512KB (1024 sectors) or more without checking queue_max_sectors, which will be split if the device or DM target enforces a smaller limit.
2. queue_max_segments: Splits bios exceeding scatter-gather segment limits. f2fs allocates bios with up to 256 pages, exceeding the 128-segment limit of DM targets (dm-default-key/dm-crypt) if pages are discontiguous.
3. chunk_sectors: Splits bios crossing chunk/zone boundaries. In f2fs, section_size strictly matches zone_size, and block allocation never spans across section boundaries, so bios never cross chunk_sectors.
Crucially, when bio_split_to_limits() splits a bio, bio_submit_split() submits the tail half via submit_bio_noacct() before returning the head half to the caller. On a sequential zoned device, this causes the tail bio to arrive at the zone write plug before the head:
dm-3: zone 7: prepare_bio wp mismatch: bio sector 30720 offset 2048 != wp_offset 248, len 248
The write plug rejects the out-of-order tail with BLK_STS_IOERR, causing f2fs_stop_checkpoint() and remounting the filesystem read-only:
2026-09-30T22:09:23.725678+08:00 localhost kernel: CPU: 9 UID: 0 PID: 243 Comm: kworker/9:1H Not tainted 6.12.81-gb3ef518fb26d #5 2026-09-30T22:09:23.725750+08:00 localhost kernel: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1 04/01/2014 2026-09-30T22:09:23.725753+08:00 localhost kernel: Workqueue: dm-3_zwplugs blk_zone_wplug_bio_work 2026-09-30T22:09:23.725756+08:00 localhost kernel: Call Trace: 2026-09-30T22:09:23.725758+08:00 localhost kernel: <TASK> 2026-09-30T22:09:23.725758+08:00 localhost kernel: dump_stack_lvl+0x4d/0x70 2026-09-30T22:09:23.725759+08:00 localhost kernel: f2fs_stop_checkpoint+0x1df/0x5d0 2026-09-30T22:09:23.725759+08:00 localhost kernel: ? blk_zone_wplug_bio_work+0x4eb/0x740 2026-09-30T22:09:23.725760+08:00 localhost kernel: f2fs_cache_write_end_io+0x545/0x6e0 2026-09-30T22:09:23.725761+08:00 localhost kernel: blk_zone_wplug_bio_work+0x4eb/0x740 2026-09-30T22:09:23.725762+08:00 localhost kernel: process_one_work+0x5c6/0xde0 2026-09-30T22:09:23.725764+08:00 localhost kernel: ? assign_work+0x124/0x4e0 2026-09-30T22:09:23.725765+08:00 localhost kernel: worker_thread+0x403/0xb70 2026-09-30T22:09:23.725765+08:00 localhost kernel: ? __kthread_parkme+0x82/0x140 2026-09-30T22:09:23.725766+08:00 localhost kernel: ? __pfx_worker_thread+0x10/0x10 2026-09-30T22:09:23.725766+08:00 localhost kernel: kthread+0x235/0x2e0 2026-09-30T22:09:23.725767+08:00 localhost kernel: ? recalc_sigpending+0x128/0x1d0 2026-09-30T22:09:23.725767+08:00 localhost kernel: ? __pfx_kthread+0x10/0x10 2026-09-30T22:09:23.725769+08:00 localhost kernel: ret_from_fork+0x2f/0x70 2026-09-30T22:09:23.725769+08:00 localhost kernel: ? __pfx_kthread+0x10/0x10 2026-09-30T22:09:23.725770+08:00 localhost kernel: ret_from_fork_asm+0x1a/0x30 2026-09-30T22:09:23.725771+08:00 localhost kernel: </TASK> 2026-09-30T22:09:23.725771+08:00 localhost kernel: F2FS-fs (dm-0): Stopped filesystem due to reason: 3
To prevent write bios destined for sequential zones from being split:
1. In __bio_alloc(), bound npages to bdev_max_segments(bdev) for writes to sequential zone areas.
2. In page_is_mergeable(), check queue_max_segments() and queue_max_sectors() for sequential zone areas, so f2fs will not merge beyond the queue limits.
--- fs/f2fs/data.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
fs/f2fs/data.c +17 -1
@@ -475,6 +475,10 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)struct bio *bio; bdev =f2fs_target_device (sbi, fio->new_blkaddr, §or); +/* avoid reversed IO if bio is split due to exceeding max_segments */ +if (npages >1 && !is_read_io (fio->op) && +f2fs_is_sequential_zone_area (sbi, fio->new_blkaddr)) + npages =min_t (int, npages,bdev_max_segments (bdev)); bio =bio_alloc_bioset (bdev, npages, fio->op | fio->op_flags |f2fs_io_flags (fio),GFP_NOIO , &f2fs_bioset);
@@ -744,7 +748,19 @@ static bool page_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,return false;if (last_blkaddr +1 != cur_blkaddr)return false; -return bio->bi_bdev ==f2fs_target_device (sbi, cur_blkaddr,NULL ); +if (bio->bi_bdev !=f2fs_target_device (sbi, cur_blkaddr,NULL )) +return false; +/* avoid reversed IO if bio is split due to exceeding max_segments/sectors */ +if (f2fs_is_sequential_zone_area (sbi, cur_blkaddr)) { +struct request_queue *q =bdev_get_queue (bio->bi_bdev); + +if (bio->bi_vcnt >=queue_max_segments (q)) +return false; +if (bio_sectors (bio) + (F2FS_BLKSIZE >>SECTOR_SHIFT ) > +queue_max_sectors (q)) +return false; + } +return true; } static bool io_type_is_mergeable(struct f2fs_bio_info *io,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 569/686 cgroup: Expose some cgroup helpers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <[email protected]>
[ Upstream commit 5b30afc20b3fea29b9beb83c6415c4ff06f774aa ]
Expose the following through cgroup.h:
- cgroup_on_dfl()
- cgroup_is_dead()
- cgroup_for_each_live_child()
- cgroup_for_each_live_descendant_pre()
- cgroup_for_each_live_descendant_post()
Until now, these didn't need to be exposed because controllers only cared about the css hierarchy. The planned sched_ext hierarchical scheduler support will be based on the default cgroup hierarchy, which is in line with the existing BPF cgroup support, and thus needs these exposed.
Stable-dep-of: 15da1e4978dd ("mm/mglru: fix ineffective memory protection for non-kswapd reclaim")
--- include/linux/cgroup.h | 65 ++++++++++++++++++++++++++++++++- kernel/cgroup/cgroup-internal.h | 6 --- kernel/cgroup/cgroup.c | 55 ---------------------------- 3 files changed, 63 insertions(+), 63 deletions(-)
include/linux/cgroup.h +63 -2
@@ -42,6 +42,14 @@ struct kernel_clone_args;#ifdef CONFIG_CGROUPS +/* +* To avoid confusing the compiler (and generating warnings) with code +* that attempts to access what would be a 0-element array (i.e. sized +* to a potentially empty array when CGROUP_SUBSYS_COUNT == 0), this +* constant expression can be added. +*/ +#define CGROUP_HAS_SUBSYS_CONFIG (CGROUP_SUBSYS_COUNT > 0) +enum css_task_iter_flags {CSS_TASK_ITER_PROCS = (1U <<0 ),/* walk only threadgroup leaders */ CSS_TASK_ITER_THREADED = (1U << 1), /* walk all threaded css_sets in the domain */
@@ -76,6 +84,7 @@ enum cgroup_lifetime_events {extern struct file_system_type cgroup_fs_type;extern struct cgroup_root cgrp_dfl_root;extern struct css_set init_css_set; +extern struct mutex cgroup_mutex;extern spinlock_t css_set_lock;extern struct blocking_notifier_head cgroup_lifetime_notifier;
@@ -103,6 +112,8 @@ extern struct blocking_notifier_head cgroup_lifetime_notifier;#define cgroup_subsys_on_dfl (ss) \ static_branch_likely(&ss ## _on_dfl_key) +bool cgroup_on_dfl (const struct cgroup *cgrp); +bool css_has_online_children (struct cgroup_subsys_state *css);struct cgroup_subsys_state *css_from_id (int id,struct cgroup_subsys *ss); struct cgroup_subsys_state *cgroup_e_css(struct cgroup *cgroup,
@@ -273,6 +284,32 @@ void css_task_iter_end(struct css_task_iter *it);for ((pos) =css_next_descendant_post (NULL , (css)); (pos); \ (pos) =css_next_descendant_post ((pos), (css))) +/* iterate over child cgrps, lock should be held throughout iteration */ +#define cgroup_for_each_live_child (child, cgrp) \ + list_for_each_entry((child), &(cgrp)->self.children, self.sibling) \ + if (({ lockdep_assert_held(&cgroup_mutex); \ + cgroup_is_dead(child); })) \ + ; \ + else + +/* walk live descendants in pre order */ +#define cgroup_for_each_live_descendant_pre (dsct, d_css, cgrp) \ + css_for_each_descendant_pre((d_css), cgroup_css((cgrp), NULL)) \ + if (({ lockdep_assert_held(&cgroup_mutex); \ + (dsct) = (d_css)->cgroup; \ + cgroup_is_dead(dsct); })) \ + ; \ + else + +/* walk live descendants in postorder */ +#define cgroup_for_each_live_descendant_post (dsct, d_css, cgrp) \ + css_for_each_descendant_post((d_css), cgroup_css((cgrp), NULL)) \ + if (({ lockdep_assert_held(&cgroup_mutex); \ + (dsct) = (d_css)->cgroup; \ + cgroup_is_dead(dsct); })) \ + ; \ + else +/** * cgroup_taskset_for_each - iterate cgroup_taskset * @task: the loop cursor
@@ -335,6 +372,27 @@ static inline u64 cgroup_id(const struct cgroup *cgrp)return cgrp->kn->id; } +/** +* cgroup_css - obtain a cgroup's css for the specified subsystem +* @cgrp: the cgroup of interest +* @ss: the subsystem of interest (%NULL returns @cgrp->self) +* +* Return @cgrp's css (cgroup_subsys_state) associated with @ss. This +* function must be called either under cgroup_mutex or rcu_read_lock() and +* the caller is responsible for pinning the returned css if it wants to +* keep accessing it outside the said locks. This function may return +* %NULL if @cgrp doesn't have @subsys_id enabled. +*/ +static inline struct cgroup_subsys_state *cgroup_css (struct cgroup *cgrp, +struct cgroup_subsys *ss) +{ +if (CGROUP_HAS_SUBSYS_CONFIG && ss) +return rcu_dereference_check (cgrp->subsys[ss->id], +lockdep_is_held (&cgroup_mutex)); +else +return &cgrp->self; +} +/** * css_is_dying - test whether the specified css is dying * @css: target css
@@ -371,6 +429,11 @@ static inline bool css_is_self(struct cgroup_subsys_state *css)return false; } +static inline bool cgroup_is_dead (const struct cgroup *cgrp) +{ +return !(cgrp->self.flags &CSS_ONLINE ); +} +static inline void cgroup_get (struct cgroup *cgrp) {css_get (&cgrp->self);
@@ -386,8 +449,6 @@ static inline void cgroup_put(struct cgroup *cgrp)css_put (&cgrp->self); } -extern struct mutex cgroup_mutex; -static inline void cgroup_lock (void ) {mutex_lock (&cgroup_mutex);
kernel/cgroup/cgroup-internal.h +0 -6
@@ -184,11 +184,6 @@ extern bool cgrp_dfl_visible;for ((ssid) =0 ; (ssid) <CGROUP_SUBSYS_COUNT && \ (((ss) = cgroup_subsys[ssid]) || true); (ssid)++) -static inline bool cgroup_is_dead(const struct cgroup *cgrp) -{ -return !(cgrp->self.flags &CSS_ONLINE ); -} - static inline bool notify_on_release(const struct cgroup *cgrp) {return test_bit (CGRP_NOTIFY_ON_RELEASE , &cgrp->flags);
@@ -222,7 +217,6 @@ static inline void get_css_set(struct css_set *cset) }bool cgroup_ssid_enabled (int ssid); -bool cgroup_on_dfl (const struct cgroup *cgrp);struct cgroup_root *cgroup_root_from_kf (struct kernfs_root *kf_root); struct cgroup *task_cgroup_from_root(struct task_struct *task,
kernel/cgroup/cgroup.c +0 -55
73 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 570/686 mm/mglru: fix ineffective memory protection for non-kswapd reclaim
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ridong Chen <[email protected]>
[ Upstream commit 15da1e4978dd4ea8f5faa6e15ee967ba4ad9a30a ]
For MGLRU, memory.min/low is not honored during global proactive reclaim (writing to the root memory.reclaim) and global direct reclaim, because these paths shrink memcgs using stale protection (emin/elow). It can be reproduced as follows:
# echo 7 > /sys/kernel/mm/lru_gen/enabled # cd /sys/fs/cgroup # mkdir -p a/b # echo 100M > a/memory.min # echo +memory > a/cgroup.subtree_control # echo 100M > a/b/memory.min # echo $$ > a/b/cgroup.procs # dd if=/dev/zero of=/tmp/testfile bs=1M count=200 # cat a/b/memory.current 222650368 # echo 500M > memory.reclaim -bash: echo: write error: Resource temporarily unavailable # cat a/b/memory.current 6070272
memory.min is 100M, yet reclaim drops a/b down to 6M, breaking the protection. The traditional LRU path is not affected because shrink_node() calls mem_cgroup_calculate_protection() for each memcg it visits during a top-down tree walk.
Commit 30d77b7eef01 ("mm/mglru: fix ineffective protection calculation") moved the protection computation into lru_gen_age_node(), which only runs for kswapd. Non-kswapd global reclaim reaches shrink_one() through lru_gen_shrink_node() -> shrink_many() without any protection computation, so emin/elow are whatever a previous kswapd run left behind - or zero if kswapd never ran on this node. Relying on a prior kswapd pass is not correct either: a memcg's emin/elow are derived from its ancestors' memory.min/low settings and from children_min_usage, both of which change over time, so emin/elow go stale even after kswapd has run and must be recomputed at the point of reclaim.
Introduce mem_cgroup_calculate_protection_path() which computes emin/elow along the root-to-target path only, by iterating through the cgroup ancestors array top-down. This avoids the full tree traversal that would be needed with mem_cgroup_calculate_protection(), limiting the cost to O(depth) per memcg - typically 3-5 levels.
Call it from shrink_one() for the non-kswapd path so that each memcg about to be shrunk has correct protection values.
--- include/linux/memcontrol.h | 10 +++++++++ mm/memcontrol.c | 45 ++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 8 ++++++- 3 files changed, 62 insertions(+), 1 deletion(-)
include/linux/memcontrol.h +10 -0
@@ -1869,6 +1869,16 @@ static inline void mem_cgroup_node_filter_allowed(struct mem_cgroup *memcg, }#endif /* CONFIG_MEMCG */ +#if defined(CONFIG_MEMCG ) && defined(CONFIG_LRU_GEN ) +void mem_cgroup_calculate_protection_path (struct mem_cgroup *root, +struct mem_cgroup *memcg); +#else +static inline void mem_cgroup_calculate_protection_path (struct mem_cgroup *root, +struct mem_cgroup *memcg) +{ +} +#endif +#if defined(CONFIG_MEMCG ) && defined(CONFIG_ZSWAP )bool obj_cgroup_may_zswap (struct obj_cgroup *objcg);void obj_cgroup_charge_zswap (struct obj_cgroup *objcg,size_t size);
mm/memcontrol.c +45 -0
51 lines not on this page · raw message
mm/vmscan.c +7 -1
@@ -4927,7 +4927,13 @@ static int shrink_one(struct lruvec *lruvec, struct scan_control *sc)struct mem_cgroup *memcg =lruvec_memcg (lruvec);struct pglist_data *pgdat =lruvec_pgdat (lruvec); -/* lru_gen_age_node() called mem_cgroup_calculate_protection() */ +/* +* For kswapd, mem_cgroup_calculate_protection() has already +* been called during the top-down cgroup traversal. +*/ +if (!current_is_kswapd ()) +mem_cgroup_calculate_protection_path (NULL , memcg); +if (mem_cgroup_below_min (NULL , memcg))return MEMCG_LRU_YOUNG ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 571/686 f2fs: return -EIO for a lost inode block after cp_error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daeho Jeong <[email protected]>
[ Upstream commit 53b12b63304b34a3850a901c4de3cc6ad08e0aee ]
After cp_error, dirty node caches are dropped without being written. If such an inode was never written, its NAT entry is still NEW_ADDR, and reading its inode block returns -ENOENT.
f2fs_get_dnode_of_data() passes that -ENOENT up, and callers take it as a hole. Since the inode block is missing, the next offset can only advance one block, so fiemap walks block by block up to maxbytes, about 2^30 blocks, while holding the inode lock. It took hours in a power-off recovery test after shutdown and blocked unlink and umount on the file.
Return -EIO instead of -ENOENT when the inode block itself is missing after cp_error or shutdown. A missing direct or indirect node is still reported as -ENOENT.
--- fs/f2fs/node.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
fs/f2fs/node.c +14 -2
@@ -811,8 +811,20 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode)if (!dn->inode_folio) { nfolio[0 ] =f2fs_get_inode_folio (sbi, nids[0 ]); -if (IS_ERR (nfolio[0 ])) -return PTR_ERR (nfolio[0 ]); +if (IS_ERR (nfolio[0 ])) { + err =PTR_ERR (nfolio[0 ]); +/* +* cp_error drops dirty node caches, so the inode block +* of an inode that was never written reads as NEW_ADDR +* and returns -ENOENT. It is not a hole; the inode is +* gone. Callers treat -ENOENT as a hole and keep +* looking block by block (e.g. fiemap up to maxbytes). +*/ +if (err == -ENOENT && (f2fs_cp_error (sbi) || +is_sbi_flag_set (sbi,SBI_IS_SHUTDOWN ))) + err = -EIO ; +return err; + } }else { nfolio[0 ] = dn->inode_folio; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 572/686 drm/amd/pm:restate all customized OD features on every table upload for smu 13.0.0/smu 14.0.2
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kenneth Feng <[email protected]>
[ Upstream commit 44d0d3031e47973ed65fd327669d5e2eaaf6c565 ]
PMFW interprets OverDriveTable.FeatureCtrlMask as the complete set of overdrive features that are currently overridden, not as a delta describing the operation at hand. On import it resets every feature whose bit is clear back to its default value - for the VF curve that means zeroing VoltageOffsetPerZoneBoundary[] outright.
The driver assumed the opposite. smu_v14_0_2_od_edit_dpm_table() clears the mask after a successful commit, so a subsequent above-default power1_cap write goes through smu_v14_0_2_set_ppt_limit() and uploads a table carrying only PP_OD_FEATURE_PPT_BIT. PMFW then drops the user's voltage offset and reverts to the stock V/F curve, while the driver's cached user table still reports the offset through pp_od_clk_voltage.
--- drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 2 + .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 35 +++++++---------- .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 32 +++++++--------- .../drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c | 38 +++++++++++-------- 4 files changed, 52 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +2 -0
@@ -370,6 +370,8 @@ struct smu_table_context {void *boot_overdrive_table;void *user_overdrive_table; +uint32_t user_od_feature_mask; +uint32_t gpu_metrics_table_size;void *gpu_metrics_table; };
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +14 -21
@@ -1643,7 +1643,6 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu,struct amdgpu_device *adev = smu->adev;uint32_t offset_of_voltageoffset;int32_t minimum, maximum; -uint32_t feature_ctrlmask;int i, ret =0 ;switch (type) {
@@ -1965,21 +1964,16 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu,if (ret)return ret; }else { - feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;memcpy (od_table, table_context->boot_overdrive_table,sizeof (OverDriveTableExternal_t)); - od_table->OverDriveTable.FeatureCtrlMask = feature_ctrlmask; + od_table->OverDriveTable.FeatureCtrlMask =0 ; + table_context->user_od_feature_mask =0 ; } fallthrough;case PP_OD_COMMIT_DPM_TABLE : -/* -* The member below instructs PMFW the settings focused in -* this single operation. -* `uint32_t FeatureCtrlMask;` -* It does not contain actual informations about user's custom -* settings. Thus we do not cache it. -*/ + table_context->user_od_feature_mask = + od_table->OverDriveTable.FeatureCtrlMask; offset_of_voltageoffset = offsetof(OverDriveTable_t , VoltageOffsetPerZoneBoundary); if (memcmp((u8 *)od_table + offset_of_voltageoffset, table_context->user_overdrive_table + offset_of_voltageoffset,
@@ -1992,7 +1986,6 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu,return ret; } - od_table->OverDriveTable.FeatureCtrlMask =0 ;memcpy (table_context->user_overdrive_table + offset_of_voltageoffset, (u8 *)od_table + offset_of_voltageoffset,sizeof (OverDriveTableExternal_t) - offset_of_voltageoffset);
@@ -2271,6 +2264,7 @@ static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu) boot_od_table, sizeof(OverDriveTableExternal_t)); smu->user_dpm_profile.user_od = false; + smu->smu_table.user_od_feature_mask =0 ; }else if (smu->user_dpm_profile.user_od) { memcpy(&user_od_table_bak, user_od_table,
@@ -2320,12 +2314,8 @@ static int smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)OverDriveTableExternal_t *od_table = table_context->overdrive_table;OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;int res; - - user_od_table->OverDriveTable.FeatureCtrlMask =BIT (PP_OD_FEATURE_GFXCLK_BIT ) | -BIT (PP_OD_FEATURE_UCLK_BIT ) | -BIT (PP_OD_FEATURE_GFX_VF_CURVE_BIT ) | -BIT (PP_OD_FEATURE_FAN_CURVE_BIT ) | -BIT (PP_OD_FEATURE_ZERO_FAN_BIT ); + user_od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; res =smu_v13_0_0_upload_overdrive_table (smu, user_od_table); user_od_table->OverDriveTable.FeatureCtrlMask =0 ;if (res ==0 )
@@ -3130,8 +3120,10 @@ static int smu_v13_0_0_set_power_limit(struct smu_context *smu,if (limit <= msg_limit) {if (smu->current_power_limit > msg_limit) { od_table->OverDriveTable.Ppt =0 ; - od_table->OverDriveTable.FeatureCtrlMask |=1U <<PP_OD_FEATURE_PPT_BIT ; - + table_context->user_od_feature_mask &= + ~(1U <<PP_OD_FEATURE_PPT_BIT ); + od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; ret =smu_v13_0_0_upload_overdrive_table (smu, od_table);if (ret) {dev_err (smu->adev->dev,"Failed to upload overdrive table!\n" );
@@ -3145,8 +3137,9 @@ static int smu_v13_0_0_set_power_limit(struct smu_context *smu,return ret; od_table->OverDriveTable.Ppt = (limit *100 ) / msg_limit -100 ; - od_table->OverDriveTable.FeatureCtrlMask |=1U <<PP_OD_FEATURE_PPT_BIT ; - + table_context->user_od_feature_mask |=1U <<PP_OD_FEATURE_PPT_BIT ; + od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; ret =smu_v13_0_0_upload_overdrive_table (smu, od_table);if (ret) {dev_err (smu->adev->dev,"Failed to upload overdrive table!\n" );
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +14 -18
@@ -1631,7 +1631,6 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu,struct amdgpu_device *adev = smu->adev;uint32_t offset_of_voltageoffset;int32_t minimum, maximum; -uint32_t feature_ctrlmask;int i, ret =0 ;switch (type) {
@@ -1953,22 +1952,17 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu,if (ret)return ret; }else { - feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;memcpy (od_table, table_context->boot_overdrive_table,sizeof (OverDriveTableExternal_t)); - od_table->OverDriveTable.FeatureCtrlMask = feature_ctrlmask; + od_table->OverDriveTable.FeatureCtrlMask =0 ; + table_context->user_od_feature_mask =0 ; } fallthrough;case PP_OD_COMMIT_DPM_TABLE : -/* -* The member below instructs PMFW the settings focused in -* this single operation. -* `uint32_t FeatureCtrlMask;` -* It does not contain actual informations about user's custom -* settings. Thus we do not cache it. -*/ + table_context->user_od_feature_mask = + od_table->OverDriveTable.FeatureCtrlMask; offset_of_voltageoffset = offsetof(OverDriveTable_t , VoltageOffsetPerZoneBoundary); if (memcmp((u8 *)od_table + offset_of_voltageoffset, table_context->user_overdrive_table + offset_of_voltageoffset,
@@ -1981,7 +1975,6 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu,return ret; } - od_table->OverDriveTable.FeatureCtrlMask =0 ;memcpy (table_context->user_overdrive_table + offset_of_voltageoffset, (u8 *)od_table + offset_of_voltageoffset,sizeof (OverDriveTableExternal_t) - offset_of_voltageoffset);
@@ -2254,6 +2247,7 @@ static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu) boot_od_table, sizeof(OverDriveTableExternal_t)); smu->user_dpm_profile.user_od = false; + smu->smu_table.user_od_feature_mask =0 ; }else if (smu->user_dpm_profile.user_od) { memcpy(&user_od_table_bak, user_od_table,
@@ -2304,11 +2298,8 @@ static int smu_v13_0_7_restore_user_od_settings(struct smu_context *smu)OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;int res; - user_od_table->OverDriveTable.FeatureCtrlMask =BIT (PP_OD_FEATURE_GFXCLK_BIT ) | -BIT (PP_OD_FEATURE_UCLK_BIT ) | -BIT (PP_OD_FEATURE_GFX_VF_CURVE_BIT ) | -BIT (PP_OD_FEATURE_FAN_CURVE_BIT ) | -BIT (PP_OD_FEATURE_ZERO_FAN_BIT ); + user_od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; res =smu_v13_0_7_upload_overdrive_table (smu, user_od_table); user_od_table->OverDriveTable.FeatureCtrlMask =0 ;if (res ==0 )
@@ -2726,7 +2717,10 @@ static int smu_v13_0_7_set_power_limit(struct smu_context *smu,if (limit <= msg_limit) {if (smu->current_power_limit > msg_limit) { od_table->OverDriveTable.Ppt =0 ; - od_table->OverDriveTable.FeatureCtrlMask |=1U <<PP_OD_FEATURE_PPT_BIT ; + table_context->user_od_feature_mask &= + ~(1U <<PP_OD_FEATURE_PPT_BIT ); + od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; ret =smu_v13_0_7_upload_overdrive_table (smu, od_table);if (ret) {
@@ -2741,7 +2735,9 @@ static int smu_v13_0_7_set_power_limit(struct smu_context *smu,return ret; od_table->OverDriveTable.Ppt = (limit *100 ) / msg_limit -100 ; - od_table->OverDriveTable.FeatureCtrlMask |=1U <<PP_OD_FEATURE_PPT_BIT ; + table_context->user_od_feature_mask |=1U <<PP_OD_FEATURE_PPT_BIT ; + od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; ret =smu_v13_0_7_upload_overdrive_table (smu, od_table);if (ret) {
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c +22 -16
@@ -2391,6 +2391,7 @@ static int smu_v14_0_2_set_default_od_settings(struct smu_context *smu) boot_od_table, sizeof(OverDriveTableExternal_t)); smu->user_dpm_profile.user_od = false; + smu->smu_table.user_od_feature_mask =0 ; }else if (smu->user_dpm_profile.user_od) { memcpy(&user_od_table_bak, user_od_table,
@@ -2439,11 +2440,8 @@ static int smu_v14_0_2_restore_user_od_settings(struct smu_context *smu)OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;int res; - user_od_table->OverDriveTable.FeatureCtrlMask =BIT (PP_OD_FEATURE_GFXCLK_BIT ) | -BIT (PP_OD_FEATURE_UCLK_BIT ) | -BIT (PP_OD_FEATURE_GFX_VF_CURVE_BIT ) | -BIT (PP_OD_FEATURE_FAN_CURVE_BIT ) | -BIT (PP_OD_FEATURE_ZERO_FAN_BIT ); + user_od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; res =smu_v14_0_2_upload_overdrive_table (smu, user_od_table); user_od_table->OverDriveTable.FeatureCtrlMask =0 ;if (res ==0 )
@@ -2528,7 +2526,6 @@ static int smu_v14_0_2_od_edit_dpm_table(struct smu_context *smu,struct amdgpu_device *adev = smu->adev;uint32_t offset_of_voltageoffset;int32_t minimum, maximum; -uint32_t feature_ctrlmask;int i, ret =0 ;switch (type) {
@@ -2817,21 +2814,26 @@ static int smu_v14_0_2_od_edit_dpm_table(struct smu_context *smu,if (ret)return ret; }else { - feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;memcpy (od_table, table_context->boot_overdrive_table,sizeof (OverDriveTableExternal_t)); - od_table->OverDriveTable.FeatureCtrlMask = feature_ctrlmask; + od_table->OverDriveTable.FeatureCtrlMask =0 ; + table_context->user_od_feature_mask =0 ; } fallthrough;case PP_OD_COMMIT_DPM_TABLE :/* -* The member below instructs PMFW the settings focused in -* this single operation. -* `uint32_t FeatureCtrlMask;` -* It does not contain actual informations about user's custom -* settings. Thus we do not cache it. +* PMFW interprets FeatureCtrlMask as the complete set of OD +* features that are currently overridden, not as a delta +* describing this single operation. Any feature whose bit is +* clear gets reset to its default on import. od_table's mask +* has accumulated every feature the user touched since the +* last full restore, so record it and keep restating it on +* subsequent uploads. */ + table_context->user_od_feature_mask = + od_table->OverDriveTable.FeatureCtrlMask; + offset_of_voltageoffset = offsetof(OverDriveTable_t , VoltageOffsetPerZoneBoundary); if (memcmp((u8 *)od_table + offset_of_voltageoffset, table_context->user_overdrive_table + offset_of_voltageoffset,
@@ -2844,7 +2846,6 @@ static int smu_v14_0_2_od_edit_dpm_table(struct smu_context *smu,return ret; } - od_table->OverDriveTable.FeatureCtrlMask =0 ;memcpy (table_context->user_overdrive_table + offset_of_voltageoffset, (u8 *)od_table + offset_of_voltageoffset,sizeof (OverDriveTableExternal_t) - offset_of_voltageoffset);
@@ -2882,7 +2883,10 @@ static int smu_v14_0_2_set_power_limit(struct smu_context *smu,if (limit <= msg_limit) {if (smu->current_power_limit > msg_limit) { od_table->OverDriveTable.Ppt =0 ; - od_table->OverDriveTable.FeatureCtrlMask |=1U <<PP_OD_FEATURE_PPT_BIT ; + table_context->user_od_feature_mask &= + ~(1U <<PP_OD_FEATURE_PPT_BIT ); + od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; ret =smu_v14_0_2_upload_overdrive_table (smu, od_table);if (ret) {
@@ -2897,7 +2901,9 @@ static int smu_v14_0_2_set_power_limit(struct smu_context *smu,return ret; od_table->OverDriveTable.Ppt = (limit *100 ) / msg_limit -100 ; - od_table->OverDriveTable.FeatureCtrlMask |=1U <<PP_OD_FEATURE_PPT_BIT ; + table_context->user_od_feature_mask |=1U <<PP_OD_FEATURE_PPT_BIT ; + od_table->OverDriveTable.FeatureCtrlMask = + table_context->user_od_feature_mask; ret =smu_v14_0_2_upload_overdrive_table (smu, od_table);if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 573/686 mfd: twl-core: Use i2c_check_functionality as boolean value
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 7ee4fa2674e51a0d100b9240cd8a50355141362f ]
i2c_check_functionality() returns a boolean status rather than an error code - directly use it as a boolean value.
Stable-dep-of: 3c5c55d979dd ("mfd: twl-core: Unregister the auxiliary platform device on unbind")
--- drivers/mfd/twl-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/twl-core.c +1 -1
@@ -754,7 +754,7 @@ twl_probe(struct i2c_client *client)return status; } -if (i2c_check_functionality (client->adapter,I2C_FUNC_I2C ) ==0 ) { +if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C )) {dev_dbg (&client->dev,"can't talk I2C?\n" ); status = -EIO ; goto free;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 574/686 mfd: twl-core: Unregister the auxiliary platform device on unbind
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 3c5c55d979ddcb0765ce531bc7ba173c87c8712a ]
twl_probe() registers a standalone platform device named "twl", but keeps its pointer only in a local variable. Probe errors unregister the device, while successful probe leaves no way for twl_remove() to release it. The platform device therefore remains registered after the I2C driver unbinds.
Register a managed action on the I2C device immediately after adding the platform device. This unregisters it on probe failure and driver unbind, and also handles failure to register the action itself. Remove the manual error-path unregister to avoid releasing the device twice.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/mfd/twl-core.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/mfd/twl-core.c +15 -8
@@ -719,6 +719,11 @@ static const struct mfd_cell twl6032_cells[] = { { .name = "twl6032-clk" }, }; +static void twl_unregister_device (void *data) +{ +platform_device_unregister (data); +} +/* NOTE: This driver only handles a single twl4030/tps659x0 chip */ static int twl_probe (struct i2c_client *client)
@@ -754,17 +759,22 @@ twl_probe(struct i2c_client *client)return status; } + status =devm_add_action_or_reset (&client->dev, twl_unregister_device, + pdev); +if (status) +return status; +if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C )) {dev_dbg (&client->dev,"can't talk I2C?\n" ); status = -EIO ; - goto free; + goto out; } twl_priv =devm_kzalloc (&client->dev,sizeof (struct twl_private ),GFP_KERNEL );if (!twl_priv) { status = -ENOMEM ; - goto free; + goto out; }if ((id->driver_data) &TWL6030_CLASS ) {
@@ -784,7 +794,7 @@ twl_probe(struct i2c_client *client) GFP_KERNEL);if (!twl_priv->twl_modules) { status = -ENOMEM ; - goto free; + goto out; }for (i =0 ; i < num_slaves; i++) {
@@ -880,7 +890,7 @@ twl_probe(struct i2c_client *client) status =devm_mfd_add_devices (&client->dev,PLATFORM_DEVID_NONE , cells, num_cells,NULL ,0 ,NULL );if (status <0 ) - goto free; + goto out;if (of_device_is_system_power_controller (node)) {if (!pm_power_off)
@@ -896,10 +906,7 @@ twl_probe(struct i2c_client *client) fail:if (status <0 )twl_remove (client); -free: -if (status <0 ) -platform_device_unregister (pdev); - +out:return status; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 575/686 ALSA: hda: cs35l41: Use auto-cleanup for put_device()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit c437a83cc69645edab8e0bfc450a3b706abe759e ]
A temporary refcount management of a struct device can be done gracefully with __clean(put_device) for avoiding potential leaks.
No functional change but just a code cleanup.
Stable-dep-of: 8d70e364e866 ("ALSA: hda: cs35l41: Fix ACPI device reference leak on probe failure")
--- sound/hda/codecs/side-codecs/cs35l41_hda.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
sound/hda/codecs/side-codecs/cs35l41_hda.c +3 -7
@@ -1929,7 +1929,6 @@ int cs35l41_hda_parse_acpi(struct cs35l41_hda *cs35l41, struct device *physdev,static int cs35l41_hda_read_acpi (struct cs35l41_hda *cs35l41,const char *hid,int id) {struct acpi_device *adev; -struct device *physdev;struct spi_device *spi;const char *sub;int ret;
@@ -1941,7 +1940,8 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i } cs35l41->dacpi = adev; - physdev =get_device (acpi_get_first_physical_node (adev)); + struct device *physdev __free(put_device) = +get_device (acpi_get_first_physical_node (adev));if (!physdev) {acpi_dev_put (adev);return -ENODEV ;
@@ -1959,13 +1959,9 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i } ret =cs35l41_hda_parse_acpi (cs35l41, physdev, id); -if (ret) { -put_device (physdev); +if (ret)return ret; - } out: -put_device (physdev); - cs35l41->bypass_fw = false;if (cs35l41->control_bus ==SPI ) { spi =to_spi_device (cs35l41->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 576/686 ALSA: hda: cs35l41: Fix ACPI device reference leak on probe failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ma Ke <[email protected]>
[ Upstream commit 8d70e364e866bdfca81eee24d0688fac9472cfb9 ]
cs35l41_hda_probe() takes an acpi_device through cs35l41_hda_read_acpi() and stores it in cs35l41->dacpi. Only the failures that happen later reach the err: label, which is where that reference and cs35l41->acpi_subsystem_id are released, so the early return taken when cs35l41_hda_read_acpi() fails leaves both behind.
Keep the ownership in the caller instead of dropping the reference inside cs35l41_hda_read_acpi(). That removes the need to work out whether a given failure path has already released it, and with it the double put that cs35l41_hda_parse_acpi() would otherwise cause when it fails after having released the device itself.
cs35l41_hda_parse_acpi() and the !physdev path no longer put the reference, and the early failure enters the existing err: cleanup tail through a new err_acpi label.
The label sits between the reset of the codec and the gpio cleanup, so an early failure also releases the reset and chip-select descriptors that cs35l41_hda_parse_acpi() may already have taken, while still skipping cs35l41_safe_reset() on a codec that was never brought up.
cs35l41->dacpi comes from devm_kzalloc() and is only assigned once the ACPI device has been found, so the put is a no-op when the lookup itself failed.
Found by code review.
--- sound/hda/codecs/side-codecs/cs35l41_hda.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
sound/hda/codecs/side-codecs/cs35l41_hda.c +6 -6
@@ -1921,7 +1921,6 @@ int cs35l41_hda_parse_acpi(struct cs35l41_hda *cs35l41, struct device *physdev, hw_cfg->valid = false; hw_cfg->gpio1.valid = false; hw_cfg->gpio2.valid = false; -acpi_dev_put (cs35l41->dacpi);return ret; }
@@ -1942,10 +1941,8 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i cs35l41->dacpi = adev; struct device *physdev __free(put_device) =get_device (acpi_get_first_physical_node (adev)); -if (!physdev) { -acpi_dev_put (adev); +if (!physdev)return -ENODEV ; - } sub =acpi_get_subsystem_id (ACPI_HANDLE (physdev));if (IS_ERR (sub))
@@ -2000,8 +1997,10 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int idev_set_drvdata (dev, cs35l41); ret =cs35l41_hda_read_acpi (cs35l41, device_name, id); -if (ret) -return dev_err_probe (cs35l41->dev, ret,"Platform not supported\n" ); +if (ret) { +dev_err_probe (cs35l41->dev, ret,"Platform not supported\n" ); + goto err_acpi; + }if (IS_ERR (cs35l41->reset_gpio)) { ret =PTR_ERR (cs35l41->reset_gpio);
@@ -2088,6 +2087,7 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i err:if (cs35l41_safe_reset (cs35l41->regmap, cs35l41->hw_cfg.bst_type))gpiod_set_value_cansleep (cs35l41->reset_gpio,0 ); +err_acpi:gpiod_put (cs35l41->reset_gpio);gpiod_put (cs35l41->cs_gpio);acpi_dev_put (cs35l41->dacpi);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 577/686 platform/x86: asus-wmi: Serialize WMI method evaluations with a mutex
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Scardovi <[email protected]>
[ Upstream commit b9428edaf4109e86a97254228d831767d0acc1f8 ]
Concurrent evaluations of ASUS WMI management methods (from ACPI notify, HID, userspace daemons, and debugfs) enter the BIOS ACPI/SMM interface simultaneously, triggering re-entrant SMIs or EC mailbox buffer corruption.
Fix this at the root by introducing a centralized evaluation helper (asus_wmi_evaluate_method_locked()) protected by a global mutex (asus_wmi_eval_lock) using guard(mutex). Route all evaluations of ASUS_WMI_MGMT_GUID (method3, method5, method_buf, and show_call) through this helper.
A static mutex is required because asus_wmi_evaluate_method() is an exported symbol used by external modules (such as hid-asus and asus-armoury) that lack access to struct asus_wmi drvdata, and the underlying ASUS ACPI/EC management method is a single physical platform resource.
The mutex is non-recursive: nested ACPI/WMI notify handlers must not call back into evaluate on the same task (defer via workqueue, as asus_rfkill_notify already does).
The sysfs-versus-notify race predates the later export of asus_wmi_evaluate_method(), so Fixes points at the original shared evaluate helper rather than that export.
--- drivers/platform/x86/asus-wmi.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
drivers/platform/x86/asus-wmi.c +21 -9
@@ -15,6 +15,7 @@#include <linux/acpi.h> #include <linux/backlight.h> +#include <linux/cleanup.h> #include <linux/debugfs.h> #include <linux/delay.h> #include <linux/dmi.h>
@@ -27,6 +28,7 @@#include <linux/leds.h> #include <linux/minmax.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/pci.h> #include <linux/pci_hotplug.h> #include <linux/platform_data/x86/asus-wmi.h>
@@ -341,6 +343,20 @@ static enum asus_ally_mcu_hack use_ally_mcu_hack = ASUS_WMI_ALLY_MCU_HACK_INIT;/* WMI ************************************************************************/ +/* +* Concurrent evaluations of ASUS WMI methods can re-enter firmware +* SMI/EC mailbox handling and corrupt the mailbox. +*/ +static DEFINE_MUTEX (asus_wmi_eval_lock); + +static acpi_status asus_wmi_evaluate_method_locked (u32 method_id, +struct acpi_buffer *input, +struct acpi_buffer *output) +{ +guard (mutex)(&asus_wmi_eval_lock); +return wmi_evaluate_method (ASUS_WMI_MGMT_GUID ,0 , method_id, input, output); +} +static int asus_wmi_evaluate_method3 (u32 method_id,u32 arg0,u32 arg1,u32 arg2,u32 *retval) {
@@ -355,8 +371,7 @@ static int asus_wmi_evaluate_method3(u32 method_id,union acpi_object *obj;u32 tmp =0 ; - status =wmi_evaluate_method (ASUS_WMI_MGMT_GUID ,0 , method_id, - &input, &output); + status =asus_wmi_evaluate_method_locked (method_id, &input, &output);pr_debug ("%s called (0x%08x) with args: 0x%08x, 0x%08x, 0x%08x\n" , __func__, method_id, arg0, arg1, arg2);
@@ -407,8 +422,7 @@ static int asus_wmi_evaluate_method5(u32 method_id,union acpi_object *obj;u32 tmp =0 ; - status =wmi_evaluate_method (ASUS_WMI_MGMT_GUID ,0 , method_id, - &input, &output); + status =asus_wmi_evaluate_method_locked (method_id, &input, &output);pr_debug ("%s called (0x%08x) with args: 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x\n" , __func__, method_id, arg0, arg1, arg2, arg3, arg4);
@@ -455,8 +469,7 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,union acpi_object *obj;int err =0 ; - status =wmi_evaluate_method (ASUS_WMI_MGMT_GUID ,0 , method_id, - &input, &output); + status =asus_wmi_evaluate_method_locked (method_id, &input, &output);pr_debug ("%s called (0x%08x) with args: 0x%08x, 0x%08x\n" , __func__, method_id, arg0, arg1);
@@ -4656,9 +4669,8 @@ static int show_call(struct seq_file *m, void *data)union acpi_object *obj;acpi_status status; - status =wmi_evaluate_method (ASUS_WMI_MGMT_GUID , -0 , asus->debug.method_id, - &input, &output); + status =asus_wmi_evaluate_method_locked (asus->debug.method_id, + &input, &output);if (ACPI_FAILURE (status))return -EIO ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 578/686 KVM: arm64: nv: Move L2->L1 switch on interrupt early
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit 21d3b33234ebbb675c2a2a0fa7b12d2d83953d7a ]
NV request generation to switch from L2 to L1 on interrupt is buried into the vgic flush code, while we should be able to deliver requests as early as possible.
Similarly, MI generation happens *after* the need for a request has been evaluated, which means we potentially delay the maintenance interrupt by a full exit/entry cycle.
Move these two things to happen much earlier in the entry code, and make sure the MI generation and PMU interrupt serve as input to the request switching back from L2 to L1.
--- arch/arm64/kvm/arm.c | 4 ++-- arch/arm64/kvm/nested.c | 10 ++++++++++ arch/arm64/kvm/vgic/vgic.c | 11 ++--------- 3 files changed, 14 insertions(+), 11 deletions(-)
arch/arm64/kvm/arm.c +2 -2
@@ -1225,11 +1225,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)*/ preempt_disable (); -kvm_nested_flush_hwstate (vcpu); -if (kvm_vcpu_has_pmu (vcpu))kvm_pmu_flush_hwstate (vcpu); +kvm_nested_flush_hwstate (vcpu); +local_irq_disable ();/*
arch/arm64/kvm/nested.c +10 -0
@@ -16,6 +16,7 @@#include <asm/sysreg.h> #include "sys_regs.h" +#include "vgic/vgic.h" struct vncr_tlb {/* The guest's VNCR_EL2 */
@@ -1879,6 +1880,9 @@ void check_nested_vcpu_requests(struct kvm_vcpu *vcpu)* * What follows is some slop to (1) react to exception routing / masking and (2) * preserve the pending SError state across translation regimes. +* +* Also generate the maintenance interrupt state, and finally check that if +* we need to take an interrupt targetting the guest hypervisor. */ void kvm_nested_flush_hwstate (struct kvm_vcpu *vcpu) {
@@ -1887,6 +1891,12 @@ void kvm_nested_flush_hwstate(struct kvm_vcpu *vcpu)if (unlikely (vcpu_test_and_clear_flag (vcpu,NESTED_SERROR_PENDING )))kvm_inject_serror_esr (vcpu,vcpu_get_vsesr (vcpu)); + +if (!vgic_state_is_nested (vcpu)) +vgic_v3_nested_update_mi (vcpu); + +if (vgic_state_is_nested (vcpu) &&kvm_vgic_vcpu_pending_irq (vcpu)) +kvm_make_request (KVM_REQ_GUEST_HYP_IRQ_PENDING , vcpu); }void kvm_nested_sync_hwstate (struct kvm_vcpu *vcpu)
arch/arm64/kvm/vgic/vgic.c +2 -9
@@ -969,7 +969,7 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu)* * We do that by placing a request to ourselves which will * abort the entry procedure and inject the exception at the -* beginning of the run loop. +* beginning of the run loop (see kvm_nested_flush_hwstate()). * * - Otherwise, do exactly *NOTHING*. The guest state is * already loaded, and we can carry on with running it.
@@ -977,15 +977,8 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu)* If we have NV, but are not in a nested state, compute the * maintenance interrupt state, as it may fire. */ -if (vgic_state_is_nested (vcpu)) { -if (kvm_vgic_vcpu_pending_irq (vcpu)) -kvm_make_request (KVM_REQ_GUEST_HYP_IRQ_PENDING , vcpu); - +if (vgic_state_is_nested (vcpu))return ; - } - -if (vcpu_has_nv (vcpu)) -vgic_v3_nested_update_mi (vcpu);/* * If there are no virtual interrupts active or pending for this
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 579/686 media: rockchip: rga: use clk_bulk api
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Püschel <[email protected]>
[ Upstream commit a2a4f69fd2e333bacd17d1788eb5211cb6f373cc ]
Use the clk_bulk API to avoid code duplication for each of the three clocks.
Stable-dep-of: a875c43dd95e ("media: rockchip: rga: quiesce IRQ before releasing m2m state")
--- drivers/media/platform/rockchip/rga/rga.c | 65 +++-------------------- drivers/media/platform/rockchip/rga/rga.h | 6 +-- 2 files changed, 11 insertions(+), 60 deletions(-)
drivers/media/platform/rockchip/rga/rga.c +8 -57
@@ -702,48 +702,10 @@ static const struct video_device rga_videodev = { .device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING, }; -static int rga_enable_clocks (struct rockchip_rga *rga) -{ -int ret; - - ret =clk_prepare_enable (rga->sclk); -if (ret) { -dev_err (rga->dev,"Cannot enable rga sclk: %d\n" , ret); -return ret; - } - - ret =clk_prepare_enable (rga->aclk); -if (ret) { -dev_err (rga->dev,"Cannot enable rga aclk: %d\n" , ret); - goto err_disable_sclk; - } - - ret =clk_prepare_enable (rga->hclk); -if (ret) { -dev_err (rga->dev,"Cannot enable rga hclk: %d\n" , ret); - goto err_disable_aclk; - } - -return 0 ; - -err_disable_aclk: -clk_disable_unprepare (rga->aclk); -err_disable_sclk: -clk_disable_unprepare (rga->sclk); - -return ret; -} - -static void rga_disable_clocks (struct rockchip_rga *rga) -{ -clk_disable_unprepare (rga->sclk); -clk_disable_unprepare (rga->hclk); -clk_disable_unprepare (rga->aclk); -} -static int rga_parse_dt (struct rockchip_rga *rga) {struct reset_control *core_rst, *axi_rst, *ahb_rst; +int ret; core_rst =devm_reset_control_get (rga->dev,"core" );if (IS_ERR (core_rst)) {
@@ -775,23 +737,12 @@ static int rga_parse_dt(struct rockchip_rga *rga)udelay (1 );reset_control_deassert (ahb_rst); - rga->sclk =devm_clk_get (rga->dev,"sclk" ); -if (IS_ERR (rga->sclk)) { -dev_err (rga->dev,"failed to get sclk clock\n" ); -return PTR_ERR (rga->sclk); - } - - rga->aclk =devm_clk_get (rga->dev,"aclk" ); -if (IS_ERR (rga->aclk)) { -dev_err (rga->dev,"failed to get aclk clock\n" ); -return PTR_ERR (rga->aclk); - } - - rga->hclk =devm_clk_get (rga->dev,"hclk" ); -if (IS_ERR (rga->hclk)) { -dev_err (rga->dev,"failed to get hclk clock\n" ); -return PTR_ERR (rga->hclk); + ret =devm_clk_bulk_get_all (rga->dev, &rga->clks); +if (ret <0 ) { +dev_err (rga->dev,"failed to get clocks\n" ); +return ret; } + rga->num_clks = ret;return 0 ; }
@@ -939,7 +890,7 @@ static int __maybe_unused rga_runtime_suspend(struct device *dev) {struct rockchip_rga *rga =dev_get_drvdata (dev); -rga_disable_clocks (rga); +clk_bulk_disable_unprepare (rga->num_clks, rga->clks);return 0 ; }
@@ -948,7 +899,7 @@ static int __maybe_unused rga_runtime_resume(struct device *dev) {struct rockchip_rga *rga =dev_get_drvdata (dev); -return rga_enable_clocks (rga); +return clk_bulk_prepare_enable (rga->num_clks, rga->clks); }static const struct dev_pm_ops rga_pm = {
drivers/media/platform/rockchip/rga/rga.h +3 -3
@@ -6,6 +6,7 @@#ifndef __RGA_H__#define __RGA_H__ +#include <linux/clk.h> #include <linux/platform_device.h> #include <media/videobuf2-v4l2.h> #include <media/v4l2-ctrls.h>
@@ -81,9 +82,8 @@ struct rockchip_rga {struct device *dev;struct regmap *grf;void __iomem *regs; -struct clk *sclk; -struct clk *aclk; -struct clk *hclk; +struct clk_bulk_data *clks; +int num_clks;struct rockchip_rga_version version;/* vfd lock */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 580/686 media: rockchip: rga: quiesce IRQ before releasing m2m state
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit a875c43dd95ee4f9c4e3e5ae1cb8362cc6d7817d ]
rga_remove() releases the m2m state before the IRQ is freed. The IRQ is devm-managed and is only released once rga_remove() returns, so rga_isr() can still run while the m2m device state is being torn down.
Store the IRQ number in struct rockchip_rga, unregister the video device first, and free the IRQ before releasing the m2m state so the handler cannot run against the freed state.
--- drivers/media/platform/rockchip/rga/rga.c | 4 +++- drivers/media/platform/rockchip/rga/rga.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/rockchip/rga/rga.c +3 -1
@@ -782,6 +782,7 @@ static int rga_probe(struct platform_device *pdev) ret = irq; goto err_put_clk; } + rga->irq = irq; ret =devm_request_irq (rga->dev, irq, rga_isr,0 ,dev_name (rga->dev), rga);
@@ -879,8 +880,9 @@ static void rga_remove(struct platform_device *pdev)v4l2_info (&rga->v4l2_dev,"Removing\n" ); -v4l2_m2m_release (rga->m2m_dev);video_unregister_device (rga->vfd); +devm_free_irq (rga->dev, rga->irq, rga); +v4l2_m2m_release (rga->m2m_dev);v4l2_device_unregister (&rga->v4l2_dev);pm_runtime_disable (rga->dev);
drivers/media/platform/rockchip/rga/rga.h +1 -0
@@ -82,6 +82,7 @@ struct rockchip_rga {struct device *dev;struct regmap *grf;void __iomem *regs; +int irq;struct clk_bulk_data *clks;int num_clks;struct rockchip_rga_version version;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 581/686 filemap: Add folio_next_pos()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wilcox (Oracle) <[email protected]>
[ Upstream commit 4511fd86db6f8f94f8aff01044f5c69aa38f81f4 ]
Replace the open-coded implementation in ocfs2 (which loses the top 32 bits on 32-bit architectures) with a helper in pagemap.h.
Stable-dep-of: 329750292e9d ("xfarray: don't crash when sorting if array element crosses a folio")
--- fs/ocfs2/alloc.c | 2 +- include/linux/pagemap.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
fs/ocfs2/alloc.c +1 -1
@@ -6891,7 +6891,7 @@ static void ocfs2_zero_cluster_folios(struct inode *inode, loff_t start,ocfs2_map_and_dirty_folio (inode, handle, from, to, folio,1 , &phys); - start =folio_next_index (folio) <<PAGE_SHIFT ; + start =folio_next_pos (folio); } out:if (folios)
include/linux/pagemap.h +11 -0
@@ -941,6 +941,17 @@ static inline pgoff_t folio_next_index(const struct folio *folio)return folio->index +folio_nr_pages (folio); } +/** +* folio_next_pos - Get the file position of the next folio. +* @folio: The current folio. +* +* Return: The position of the folio which follows this folio in the file. +*/ +static inline loff_t folio_next_pos (const struct folio *folio) +{ +return (loff_t )folio_next_index (folio) <<PAGE_SHIFT ; +} +/** * folio_file_page - The page for a particular index. * @folio: The folio which contains this index.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 582/686 xfs: Use folio_next_pos()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wilcox (Oracle) <[email protected]>
[ Upstream commit ac0a11113de3f0007283d20f5a38615ea4c6e9fd ]
This is one instruction more efficient than open-coding folio_pos() + folio_size(). It's the equivalent of (x + y) << z rather than x << z + y << z.
Stable-dep-of: 329750292e9d ("xfarray: don't crash when sorting if array element crosses a folio")
--- fs/xfs/scrub/xfarray.c | 2 +- fs/xfs/xfs_aops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/xfs/scrub/xfarray.c +1 -1
@@ -833,7 +833,7 @@ xfarray_sort_scan( si->first_folio_idx =xfarray_idx (si->array,folio_pos (si->folio) + si->array->obj_size -1 ); - next_pos =folio_pos (si->folio) +folio_size (si->folio); + next_pos =folio_next_pos (si->folio); si->last_folio_idx =xfarray_idx (si->array, next_pos -1 );if (xfarray_pos (si->array, si->last_folio_idx +1 ) > next_pos) si->last_folio_idx--;
fs/xfs/xfs_aops.c +1 -1
@@ -271,7 +271,7 @@ xfs_discard_folio(* folio itself and not the start offset that is passed in. */ xfs_bmap_punch_delalloc_range (ip,XFS_DATA_FORK , pos, -folio_pos (folio) +folio_size (folio),NULL ); +folio_next_pos (folio),NULL ); }/*
Signature · 1 line
2.53.0