i2c: rcar: faster irq code to minimize HW race condition
Subsystems (15)
Sasha Levin
maintainerPATCH 1/33 i2c: rcar: faster irq code to minimize HW race condition
From: Wolfram Sang <[email protected]>
[ Upstream commit c7b514ec979e23a08c411f3d8ed39c7922751422 ]
To avoid the HW race condition on R-Car Gen2 and earlier, we need to write to ICMCR as soon as possible in the interrupt handler. We can improve this by writing a static value instead of masking out bits.
--- drivers/i2c/busses/i2c-rcar.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-rcar.c +4 -7
@@ -89,7 +89,6 @@#define RCAR_BUS_PHASE_START (MDBS | MIE | ESG)#define RCAR_BUS_PHASE_DATA (MDBS | MIE) -#define RCAR_BUS_MASK_DATA (~(ESG | FSB) & 0xFF)#define RCAR_BUS_PHASE_STOP (MDBS | MIE | FSB)#define RCAR_IRQ_SEND (MNR | MAL | MST | MAT | MDE)
@@ -616,7 +615,7 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv)/* * This driver has a lock-free design because there are IP cores (at least * R-Car Gen2) which have an inherent race condition in their hardware design. -* There, we need to clear RCAR_BUS_MASK_DATA bits as soon as possible after +* There, we need to switch to RCAR_BUS_PHASE_DATA as soon as possible after * the interrupt was generated, otherwise an unwanted repeated message gets * generated. It turned out that taking a spinlock at the beginning of the ISR * was already causing repeated messages. Thus, this driver was converted to
@@ -625,13 +624,11 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv)static irqreturn_t rcar_i2c_irq (int irq,void *ptr) {struct rcar_i2c_priv *priv = ptr; -u32 msr, val; +u32 msr;/* Clear START or STOP immediately, except for REPSTART after read */ -if (likely (!(priv->flags &ID_P_REP_AFTER_RD ))) { - val =rcar_i2c_read (priv,ICMCR ); -rcar_i2c_write (priv,ICMCR , val &RCAR_BUS_MASK_DATA ); - } +if (likely (!(priv->flags &ID_P_REP_AFTER_RD ))) +rcar_i2c_write (priv,ICMCR ,RCAR_BUS_PHASE_DATA ); msr =rcar_i2c_read (priv,ICMSR );
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 2/33 i2c: rcar: optimize cacheline to minimize HW race condition
From: Wolfram Sang <[email protected]>
[ Upstream commit 25c2e0fb5fefb8d7847214cf114d94c7aad8e9ce ]
'flags' and 'io' are needed first, so they should be at the beginning of the private struct.
--- drivers/i2c/busses/i2c-rcar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-rcar.c +1 -1
@@ -116,6 +116,7 @@ enum rcar_i2c_type { };struct rcar_i2c_priv { +u32 flags;void __iomem *io;struct i2c_adapter adap;struct i2c_msg *msg;
@@ -126,7 +127,6 @@ struct rcar_i2c_priv {int pos;u32 icccr; -u32 flags;u8 recovery_icmcr;/* protected by adapter lock */ enum rcar_i2c_type devtype;struct i2c_client *slave;
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 3/33 udf: fix silent AED tagLocation corruption
In reply to Sasha LevinFrom: "Steven J. Magnani" <[email protected]>
[ Upstream commit 63c9e47a1642fc817654a1bc18a6ec4bbcc0f056 ]
When extending a file, udf_do_extend_file() may enter following empty indirect extent. At the end of udf_do_extend_file() we revert prev_epos to point to the last written extent. However if we end up not adding any further extent in udf_do_extend_file(), the reverting points prev_epos into the header area of the AED and following updates of the extents (in udf_update_extents()) will corrupt the header.
Make sure that we do not follow indirect extent if we are not going to add any more extents so that returning back to the last written extent works correctly.
--- fs/udf/inode.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/udf/inode.c +6 -3
@@ -547,11 +547,14 @@ static int udf_do_extend_file(struct inode *inode,udf_write_aext (inode, last_pos, &last_ext->extLocation, last_ext->extLength,1 ); +/* -* We've rewritten the last extent but there may be empty -* indirect extent after it - enter it. +* We've rewritten the last extent. If we are going to add +* more extents, we may need to enter possible following +* empty indirect extent. */ -udf_next_aext (inode, last_pos, &tmploc, &tmplen,0 ); +if (new_block_bytes || prealloc_len) +udf_next_aext (inode, last_pos, &tmploc, &tmplen,0 ); }/* Managed to do everything necessary? */
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 4/33 mmc: mxs-mmc: Fix a resource leak in an error handling path in 'mxs_mmc_probe()'
In reply to Sasha LevinFrom: Christophe JAILLET <[email protected]>
[ Upstream commit 0bb7e560f821c7770973a94e346654c4bdccd42c ]
If 'mmc_of_parse()' fails, we must undo the previous 'dma_request_chan()' call.
--- drivers/mmc/host/mxs-mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/mxs-mmc.c +1 -1
@@ -644,7 +644,7 @@ static int mxs_mmc_probe(struct platform_device *pdev) ret =mmc_of_parse (mmc);if (ret) - goto out_clk_disable; + goto out_free_dma; mmc->ocr_avail =MMC_VDD_32_33 |MMC_VDD_33_34 ;
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 5/33 mmc: sdhci-of-dwcmshc: set SDHCI_QUIRK2_PRESET_VALUE_BROKEN
In reply to Sasha LevinFrom: Jisheng Zhang <[email protected]>
[ Upstream commit 5f7dfda4f2cec580c135fd81d96a05006651c128 ]
The SDHCI_PRESET_FOR_* registers are not set(all read as zeros), so set the quirk.
--- drivers/mmc/host/sdhci-of-dwcmshc.c | 1 + 1 file changed, 1 insertion(+)
drivers/mmc/host/sdhci-of-dwcmshc.c +1 -0
@@ -58,6 +58,7 @@ static const struct sdhci_ops sdhci_dwcmshc_ops = {static const struct sdhci_pltfm_data sdhci_dwcmshc_pdata = { .ops = &sdhci_dwcmshc_ops, .quirks =SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN , + .quirks2 =SDHCI_QUIRK2_PRESET_VALUE_BROKEN , };static int dwcmshc_probe (struct platform_device *pdev)
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 6/33 mmc: mediatek: fix race condition between msdc_request_timeout and irq
In reply to Sasha LevinFrom: Chaotian Jing <[email protected]>
[ Upstream commit 0354ca6edd464a2cf332f390581977b8699ed081 ]
when get request SW timeout, if CMD/DAT xfer done irq coming right now, then there is race between the msdc_request_timeout work and irq handler, and the host->cmd and host->data may set to NULL in irq handler. also, current flow ensure that only one path can go to msdc_request_done(), so no need check the return value of cancel_delayed_work().
--- drivers/mmc/host/mtk-sd.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/mmc/host/mtk-sd.c +10 -8
@@ -1020,13 +1020,13 @@ static void msdc_track_cmd_data(struct msdc_host *host,static void msdc_request_done (struct msdc_host *host,struct mmc_request *mrq) {unsigned long flags; -bool ret; - ret =cancel_delayed_work (&host->req_timeout); -if (!ret) { -/* delay work already running */ -return ; - } +/* +* No need check the return value of cancel_delayed_work, as only ONE +* path will go here! +*/ +cancel_delayed_work (&host->req_timeout); +spin_lock_irqsave (&host->lock, flags); host->mrq =NULL ;spin_unlock_irqrestore (&host->lock, flags);
@@ -1046,7 +1046,7 @@ static bool msdc_cmd_done(struct msdc_host *host, int events,bool done = false;bool sbc_error;unsigned long flags; -u32 *rsp = cmd->resp; +u32 *rsp; if (mrq->sbc && cmd == mrq->cmd && (events & (MSDC_INT_ACMDRDY | MSDC_INT_ACMDCRCERR
@@ -1067,6 +1067,7 @@ static bool msdc_cmd_done(struct msdc_host *host, int events,if (done)return true; + rsp = cmd->resp;sdr_clr_bits (host->base +MSDC_INTEN , cmd_ints_mask);
@@ -1254,7 +1255,7 @@ static void msdc_data_xfer_next(struct msdc_host *host,static bool msdc_data_xfer_done (struct msdc_host *host,u32 events,struct mmc_request *mrq,struct mmc_data *data) { -struct mmc_command *stop = data->stop; +struct mmc_command *stop;unsigned long flags;bool done; unsigned int check_data = events &
@@ -1270,6 +1271,7 @@ static bool msdc_data_xfer_done(struct msdc_host *host, u32 events,if (done)return true; + stop = data->stop;if (check_data || (stop && stop->error)) { dev_dbg(host->dev, "DMA status: 0x%8X\n",
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 7/33 Platform: OLPC: Fix probe error handling
In reply to Sasha LevinFrom: Lubomir Rintel <[email protected]>
[ Upstream commit cec551ea0d41c679ed11d758e1a386e20285b29d ]
Reset ec_priv if probe ends unsuccessfully.
--- drivers/platform/olpc/olpc-ec.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/platform/olpc/olpc-ec.c +8 -7
@@ -426,11 +426,8 @@ static int olpc_ec_probe(struct platform_device *pdev)/* get the EC revision */ err =olpc_ec_cmd (EC_FIRMWARE_REV ,NULL ,0 , &ec->version,1 ); -if (err) { - ec_priv =NULL ; -kfree (ec); -return err; - } +if (err) + goto error; config.dev = pdev->dev.parent; config.driver_data = ec;
@@ -440,12 +437,16 @@ static int olpc_ec_probe(struct platform_device *pdev)if (IS_ERR (ec->dcon_rdev)) {dev_err (&pdev->dev,"failed to register DCON regulator\n" ); err =PTR_ERR (ec->dcon_rdev); -kfree (ec); -return err; + goto error; } ec->dbgfs_dir =olpc_ec_setup_debugfs (); +return 0 ; + +error: + ec_priv =NULL ; +kfree (ec);return err; }
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 8/33 powerpc/pci: Add ppc_md.discover_phbs()
In reply to Sasha LevinFrom: Oliver O'Halloran <[email protected]>
[ Upstream commit 5537fcb319d016ce387f818dd774179bc03217f5 ]
On many powerpc platforms the discovery and initalisation of pci_controllers (PHBs) happens inside of setup_arch(). This is very early in boot (pre-initcalls) and means that we're initialising the PHB long before many basic kernel services (slab allocator, debugfs, a real ioremap) are available.
On PowerNV this causes an additional problem since we map the PHB registers with ioremap(). As of commit d538aadc2718 ("powerpc/ioremap: warn on early use of ioremap()") a warning is printed because we're using the "incorrect" API to setup and MMIO mapping in searly boot. The kernel does provide early_ioremap(), but that is not intended to create long-lived MMIO mappings and a seperate warning is printed by generic code if early_ioremap() mappings are "leaked."
This is all fixable with dumb hacks like using early_ioremap() to setup the initial mapping then replacing it with a real ioremap later on in boot, but it does raise the question: Why the hell are we setting up the PHB's this early in boot?
The old and wise claim it's due to "hysterical rasins." Aside from amused grapes there doesn't appear to be any real reason to maintain the current behaviour. Already most of the newer embedded platforms perform PHB discovery in an arch_initcall and between the end of setup_arch() and the start of initcalls none of the generic kernel code does anything PCI related. On powerpc scanning PHBs occurs in a subsys_initcall so it should be possible to move the PHB discovery to a core, postcore or arch initcall.
This patch adds the ppc_md.discover_phbs hook and a core_initcall stub that calls it. The core_initcalls are the earliest to be called so this will any possibly issues with dependency between initcalls. This isn't just an academic issue either since on pseries and PowerNV EEH init occurs in an arch_initcall and depends on the pci_controllers being available, similarly the creation of pci_dns occurs at core_initcall_sync (i.e. between core and postcore initcalls). These problems need to be addressed seperately.
--- arch/powerpc/include/asm/machdep.h | 3 +++ arch/powerpc/kernel/pci-common.c | 10 ++++++++++ 2 files changed, 13 insertions(+)
arch/powerpc/include/asm/machdep.h +3 -0
@@ -59,6 +59,9 @@ struct machdep_calls {int (*pcibios_root_bridge_prepare)(struct pci_host_bridge *bridge); +/* finds all the pci_controllers present at boot */ +void (*discover_phbs)(void ); +/* To setup PHBs when using automatic OF platform driver for PCI */ int (*pci_setup_phb)(struct pci_controller *host);
arch/powerpc/kernel/pci-common.c +10 -0
@@ -1669,3 +1669,13 @@ static void fixup_hide_host_resource_fsl(struct pci_dev *dev) }DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_MOTOROLA ,PCI_ANY_ID , fixup_hide_host_resource_fsl);DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_FREESCALE ,PCI_ANY_ID , fixup_hide_host_resource_fsl); + + +static int __init discover_phbs (void ) +{ +if (ppc_md.discover_phbs) + ppc_md.discover_phbs (); + +return 0 ; +} +core_initcall (discover_phbs);
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 9/33 HID: i2c-hid: Add I2C_HID_QUIRK_NO_IRQ_AFTER_RESET for ITE8568 EC on Voyo Winpad A15
In reply to Sasha LevinFrom: Hans de Goede <[email protected]>
[ Upstream commit fc6a31b00739356809dd566e16f2c4325a63285d ]
The ITE8568 EC on the Voyo Winpad A15 presents itself as an I2C-HID attached keyboard and mouse (which seems to never send any events).
This needs the I2C_HID_QUIRK_NO_IRQ_AFTER_RESET quirk, otherwise we get the following errors:
[ 3688.770850] i2c_hid i2c-ITE8568:00: failed to reset device. [ 3694.915865] i2c_hid i2c-ITE8568:00: failed to reset device. [ 3701.059717] i2c_hid i2c-ITE8568:00: failed to reset device. [ 3707.205944] i2c_hid i2c-ITE8568:00: failed to reset device. [ 3708.227940] i2c_hid i2c-ITE8568:00: can't add hid device: -61 [ 3708.236518] i2c_hid: probe of i2c-ITE8568:00 failed with error -61
Which leads to a significant boot delay.
--- drivers/hid/hid-ids.h | 2 ++ drivers/hid/i2c-hid/i2c-hid-core.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/hid/hid-ids.h +2 -0
@@ -640,6 +640,8 @@#define USB_DEVICE_ID_INNEX_GENESIS_ATARI 0x4745#define USB_VENDOR_ID_ITE 0x048d +#define I2C_VENDOR_ID_ITE 0x103c +#define I2C_DEVICE_ID_ITE_VOYO_WINPAD_A15 0x184f#define USB_DEVICE_ID_ITE_LENOVO_YOGA 0x8386#define USB_DEVICE_ID_ITE_LENOVO_YOGA2 0x8350#define I2C_DEVICE_ID_ITE_LENOVO_LEGION_Y720 0x837a
drivers/hid/i2c-hid/i2c-hid-core.c +2 -0
@@ -173,6 +173,8 @@ static const struct i2c_hid_quirks { I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV }, {I2C_VENDOR_ID_HANTICK ,I2C_PRODUCT_ID_HANTICK_5288 , I2C_HID_QUIRK_NO_IRQ_AFTER_RESET }, + { I2C_VENDOR_ID_ITE, I2C_DEVICE_ID_ITE_VOYO_WINPAD_A15, + I2C_HID_QUIRK_NO_IRQ_AFTER_RESET }, { I2C_VENDOR_ID_RAYDIUM, I2C_PRODUCT_ID_RAYDIUM_3118, I2C_HID_QUIRK_NO_IRQ_AFTER_RESET }, { USB_VENDOR_ID_ELAN, HID_ANY_ID,
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 10/33 spi: stm32: make spurious and overrun interrupts visible
In reply to Sasha LevinFrom: Alain Volmat <[email protected]>
[ Upstream commit c64e7efe46b7de21937ef4b3594d9b1fc74f07df ]
We do not expect to receive spurious interrupts so rise a warning if it happens.
RX overrun is an error condition that signals a corrupted RX stream both in dma and in irq modes. Report the error and abort the transfer in either cases.
--- drivers/spi/spi-stm32.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/spi/spi-stm32.c +4 -11
@@ -924,8 +924,8 @@ static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id) mask |=STM32H7_SPI_SR_RXP ;if (!(sr & mask)) { -dev_dbg (spi->dev,"spurious IT (sr=0x%08x, ier=0x%08x)\n" , - sr, ier); +dev_warn (spi->dev,"spurious IT (sr=0x%08x, ier=0x%08x)\n" , + sr, ier);spin_unlock_irqrestore (&spi->lock, flags);return IRQ_NONE ; }
@@ -952,15 +952,8 @@ static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id) }if (sr &STM32H7_SPI_SR_OVR ) { -dev_warn (spi->dev,"Overrun: received value discarded\n" ); -if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len >0 ))) -stm32h7_spi_read_rxfifo (spi, false); -/* -* If overrun is detected while using DMA, it means that -* something went wrong, so stop the current transfer -*/ -if (spi->cur_usedma) - end = true; +dev_err (spi->dev,"Overrun: RX data lost\n" ); + end = true; }if (sr &STM32H7_SPI_SR_EOT ) {
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 11/33 powerpc: improve handling of unrecoverable system reset
In reply to Sasha LevinFrom: Nicholas Piggin <[email protected]>
[ Upstream commit 11cb0a25f71818ca7ab4856548ecfd83c169aa4d ]
If an unrecoverable system reset hits in process context, the system does not have to panic. Similar to machine check, call nmi_exit() before die().
--- arch/powerpc/kernel/traps.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/kernel/traps.c +4 -1
@@ -513,8 +513,11 @@ out:die ("Unrecoverable nested System Reset" , regs,SIGABRT );#endif /* Must die if the interrupt is not recoverable */ -if (!(regs->msr &MSR_RI )) +if (!(regs->msr &MSR_RI )) { +/* For the reason explained in die_mce, nmi_exit before die */ +nmi_exit ();die ("Unrecoverable System Reset" , regs,SIGABRT ); + }if (saved_hsrrs) {mtspr (SPRN_HSRR0 , hsrr0);
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 12/33 powerpc/perf: Record counter overflow always if SAMPLE_IP is unset
In reply to Sasha LevinFrom: Athira Rajeev <[email protected]>
[ Upstream commit d137845c973147a22622cc76c7b0bc16f6206323 ]
While sampling for marked events, currently we record the sample only if the SIAR valid bit of Sampled Instruction Event Register (SIER) is set. SIAR_VALID bit is used for fetching the instruction address from Sampled Instruction Address Register(SIAR). But there are some usecases, where the user is interested only in the PMU stats at each counter overflow and the exact IP of the overflow event is not required. Dropping SIAR invalid samples will fail to record some of the counter overflows in such cases.
Example of such usecase is dumping the PMU stats (event counts) after some regular amount of instructions/events from the userspace (ex: via ptrace). Here counter overflow is indicated to userspace via signal handler, and captured by monitoring and enabling I/O signaling on the event file descriptor. In these cases, we expect to get sample/overflow indication after each specified sample_period.
Perf event attribute will not have PERF_SAMPLE_IP set in the sample_type if exact IP of the overflow event is not requested. So while profiling if SAMPLE_IP is not set, just record the counter overflow irrespective of SIAR_VALID check.
--- arch/powerpc/perf/core-book3s.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
arch/powerpc/perf/core-book3s.c +15 -4
@@ -2077,7 +2077,17 @@ static void record_and_restart(struct perf_event *event, unsigned long val, left += period;if (left <=0 ) left = period; - record =siar_valid (regs); + +/* +* If address is not requested in the sample via +* PERF_SAMPLE_IP, just record that sample irrespective +* of SIAR valid check. +*/ +if (event->attr.sample_type &PERF_SAMPLE_IP ) + record =siar_valid (regs); +else + record =1 ; + event->hw.last_period = event->hw.sample_period; }if (left <0x80000000LL )
@@ -2095,9 +2105,10 @@ static void record_and_restart(struct perf_event *event, unsigned long val,* MMCR2. Check attr.exclude_kernel and address to drop the sample in * these cases. */ -if (event->attr.exclude_kernel && record) -if (is_kernel_addr (mfspr (SPRN_SIAR ))) - record =0 ; +if (event->attr.exclude_kernel && + (event->attr.sample_type &PERF_SAMPLE_IP ) && +is_kernel_addr (mfspr (SPRN_SIAR ))) + record =0 ;/* * Finally record data if requested.
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 13/33 HID: logitech-dj: add support for the new lightspeed connection iteration
In reply to Sasha LevinFrom: Filipe Laíns <[email protected]>
[ Upstream commit fab3a95654eea01d6b0204995be8b7492a00d001 ]
This new connection type is the new iteration of the Lightspeed connection and will probably be used in some of the newer gaming devices. It is currently use in the G Pro X Superlight.
This patch should be backported to older versions, as currently the driver will panic when seing the unsupported connection. This isn't an issue when using the receiver that came with the device, as Logitech has been using different PIDs when they change the connection type, but is an issue when using a generic receiver (well, generic Lightspeed receiver), which is the case of the one in the Powerplay mat. Currently, the only generic Ligthspeed receiver we support, and the only one that exists AFAIK, is ther Powerplay.
As it stands, the driver will panic when seeing a G Pro X Superlight connected to the Powerplay receiver and won't send any input events to userspace! The kernel will warn about this so the issue should be easy to identify, but it is still very worrying how hard it will fail :(
[915977.398471] logitech-djreceiver 0003:046D:C53A.0107: unusable device of type UNKNOWN (0x0f) connected on slot 1
--- drivers/hid/hid-logitech-dj.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/hid/hid-logitech-dj.c +6 -1
@@ -994,7 +994,12 @@ static void logi_hidpp_recv_queue_notif(struct hid_device *hdev, workitem.reports_supported |=STD_KEYBOARD ;break ;case 0x0d : - device_type ="eQUAD Lightspeed 1_1" ; + device_type ="eQUAD Lightspeed 1.1" ; +logi_hidpp_dev_conn_notif_equad (hdev, hidpp_report, &workitem); + workitem.reports_supported |=STD_KEYBOARD ; +break ; +case 0x0f : + device_type ="eQUAD Lightspeed 1.2" ;logi_hidpp_dev_conn_notif_equad (hdev, hidpp_report, &workitem); workitem.reports_supported |=STD_KEYBOARD ;break ;
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 14/33 powerpc/64: Fix stack trace not displaying final frame
In reply to Sasha LevinFrom: Michael Ellerman <[email protected]>
[ Upstream commit e3de1e291fa58a1ab0f471a4b458eff2514e4b5f ]
In commit bf13718bc57a ("powerpc: show registers when unwinding interrupt frames") we changed our stack dumping logic to show the full registers whenever we find an interrupt frame on the stack.
However we didn't notice that on 64-bit this doesn't show the final frame, ie. the interrupt that brought us in from userspace, whereas on 32-bit it does.
That is due to confusion about the size of that last frame. The code in show_stack() calls validate_sp(), passing it STACK_INT_FRAME_SIZE to check the sp is at least that far below the top of the stack.
However on 64-bit that size is too large for the final frame, because it includes the red zone, but we don't allocate a red zone for the first frame.
So add a new define that encodes the correct size for 32-bit and 64-bit, and use it in show_stack().
This results in the full trace being shown on 64-bit, eg:
sysrq: Trigger a crash
Kernel panic - not syncing: sysrq triggered crash CPU: 0 PID: 83 Comm: sh Not tainted 5.11.0-rc2-gcc-8.2.0-00188-g571abcb96b10-dirty #649 Call Trace: [c00000000a1c3ac0] [c000000000897b70] dump_stack+0xc4/0x114 (unreliable) [c00000000a1c3b00] [c00000000014334c] panic+0x178/0x41c [c00000000a1c3ba0] [c00000000094e600] sysrq_handle_crash+0x40/0x50 [c00000000a1c3c00] [c00000000094ef98] __handle_sysrq+0xd8/0x210 [c00000000a1c3ca0] [c00000000094f820] write_sysrq_trigger+0x100/0x188 [c00000000a1c3ce0] [c0000000005559dc] proc_reg_write+0x10c/0x1b0 [c00000000a1c3d10] [c000000000479950] vfs_write+0xf0/0x360 [c00000000a1c3d60] [c000000000479d9c] ksys_write+0x7c/0x140 [c00000000a1c3db0] [c00000000002bf5c] system_call_exception+0x19c/0x2c0 [c00000000a1c3e10] [c00000000000d35c] system_call_common+0xec/0x278 --- interrupt: c00 at 0x7fff9fbab428 NIP: 00007fff9fbab428 LR: 000000001000b724 CTR: 0000000000000000 REGS: c00000000a1c3e80 TRAP: 0c00 Not tainted (5.11.0-rc2-gcc-8.2.0-00188-g571abcb96b10-dirty) MSR: 900000000280f033 <SF,HV,VEC,VSX,EE,PR,FP,ME,IR,DR,RI,LE> CR: 22002884 XER: 00000000 IRQMASK: 0 GPR00: 0000000000000004 00007fffc3cb8960 00007fff9fc59900 0000000000000001 GPR04: 000000002a4b32d0 0000000000000002 0000000000000063 0000000000000063 GPR08: 000000002a4b32d0 0000000000000000 0000000000000000 0000000000000000 GPR12: 0000000000000000 00007fff9fcca9a0 0000000000000000 0000000000000000 GPR16: 0000000000000000 0000000000000000 0000000000000000 00000000100b8fd0 GPR20: 000000002a4b3485 00000000100b8f90 0000000000000000 0000000000000000 GPR24: 000000002a4b0440 00000000100e77b8 0000000000000020 000000002a4b32d0 GPR28: 0000000000000001 0000000000000002 000000002a4b32d0 0000000000000001 NIP [00007fff9fbab428] 0x7fff9fbab428 LR [000000001000b724] 0x1000b724 --- interrupt: c00
--- arch/powerpc/include/asm/ptrace.h | 3 +++ arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/process.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/ptrace.h +3 -0
@@ -62,6 +62,9 @@ struct pt_regs };#endif + +#define STACK_FRAME_WITH_PT_REGS (STACK_FRAME_OVERHEAD + sizeof(struct pt_regs)) +#ifdef __powerpc64__/*
arch/powerpc/kernel/asm-offsets.c +1 -1
@@ -285,7 +285,7 @@ int main(void)/* Interrupt register frame */ DEFINE (INT_FRAME_SIZE ,STACK_INT_FRAME_SIZE ); -DEFINE (SWITCH_FRAME_SIZE ,STACK_FRAME_OVERHEAD +sizeof (struct pt_regs )); +DEFINE (SWITCH_FRAME_SIZE ,STACK_FRAME_WITH_PT_REGS );STACK_PT_REGS_OFFSET (GPR0 , gpr[0 ]);STACK_PT_REGS_OFFSET (GPR1 , gpr[1 ]);STACK_PT_REGS_OFFSET (GPR2 , gpr[2 ]);
arch/powerpc/kernel/process.c +1 -1
@@ -2081,7 +2081,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)* See if this is an exception frame. * We look for the "regshere" marker in the current frame. */ -if (validate_sp (sp, tsk,STACK_INT_FRAME_SIZE ) +if (validate_sp (sp, tsk,STACK_FRAME_WITH_PT_REGS ) && stack[STACK_FRAME_MARKER ] ==STACK_FRAME_REGS_MARKER ) {struct pt_regs *regs = (struct pt_regs *) (sp +STACK_FRAME_OVERHEAD );
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 15/33 iommu/amd: Fix performance counter initialization
In reply to Sasha LevinFrom: Suravee Suthikulpanit <[email protected]>
[ Upstream commit 6778ff5b21bd8e78c8bd547fd66437cf2657fd9b ]
Certain AMD platforms enable power gating feature for IOMMU PMC, which prevents the IOMMU driver from updating the counter while trying to validate the PMC functionality in the init_iommu_perf_ctr(). This results in disabling PMC support and the following error message:
"AMD-Vi: Unable to read/write to IOMMU perf counter"
To workaround this issue, disable power gating temporarily by programming the counter source to non-zero value while validating the counter, and restore the prior state afterward.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=201753
--- drivers/iommu/amd_iommu_init.c | 45 +++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-)
drivers/iommu/amd_iommu_init.c +34 -11
@@ -12,6 +12,7 @@#include <linux/acpi.h> #include <linux/list.h> #include <linux/bitmap.h> +#include <linux/delay.h> #include <linux/slab.h> #include <linux/syscore_ops.h> #include <linux/interrupt.h>
@@ -253,6 +254,8 @@ static enum iommu_init_state init_state = IOMMU_START_STATE;static int amd_iommu_enable_interrupts (void );static int __init iommu_go_to_state (enum iommu_init_state state);static void init_device_table_dma (void ); +static int iommu_pc_get_set_reg (struct amd_iommu *iommu,u8 bank,u8 cntr, +u8 fxn,u64 *value,bool is_write);static bool amd_iommu_pre_enabled = true;
@@ -1672,13 +1675,11 @@ static int __init init_iommu_all(struct acpi_table_header *table)return 0 ; } -static int iommu_pc_get_set_reg (struct amd_iommu *iommu,u8 bank,u8 cntr, -u8 fxn,u64 *value,bool is_write); - -static void init_iommu_perf_ctr (struct amd_iommu *iommu) +static void __init init_iommu_perf_ctr (struct amd_iommu *iommu) { +int retry;struct pci_dev *pdev = iommu->dev; -u64 val =0xabcd , val2 =0 , save_reg =0 ; +u64 val =0xabcd , val2 =0 , save_reg, save_src;if (!iommu_feature (iommu,FEATURE_PC ))return ;
@@ -1686,17 +1687,39 @@ static void init_iommu_perf_ctr(struct amd_iommu *iommu) amd_iommu_pc_present = true;/* save the value to restore, if writable */ -if (iommu_pc_get_set_reg (iommu,0 ,0 ,0 , &save_reg, false)) +if (iommu_pc_get_set_reg (iommu,0 ,0 ,0 , &save_reg, false) || +iommu_pc_get_set_reg (iommu,0 ,0 ,8 , &save_src, false)) goto pc_false; -/* Check if the performance counters can be written to */ -if ((iommu_pc_get_set_reg (iommu,0 ,0 ,0 , &val, true)) || - (iommu_pc_get_set_reg (iommu,0 ,0 ,0 , &val2, false)) || - (val != val2)) +/* +* Disable power gating by programing the performance counter +* source to 20 (i.e. counts the reads and writes from/to IOMMU +* Reserved Register [MMIO Offset 1FF8h] that are ignored.), +* which never get incremented during this init phase. +* (Note: The event is also deprecated.) +*/ + val =20 ; +if (iommu_pc_get_set_reg (iommu,0 ,0 ,8 , &val, true)) goto pc_false; +/* Check if the performance counters can be written to */ + val =0xabcd ; +for (retry =5 ; retry; retry--) { +if (iommu_pc_get_set_reg (iommu,0 ,0 ,0 , &val, true) || +iommu_pc_get_set_reg (iommu,0 ,0 ,0 , &val2, false) || + val2) +break ; + +/* Wait about 20 msec for power gating to disable and retry. */ +msleep (20 ); + } +/* restore */ -if (iommu_pc_get_set_reg (iommu,0 ,0 ,0 , &save_reg, true)) +if (iommu_pc_get_set_reg (iommu,0 ,0 ,0 , &save_reg, true) || +iommu_pc_get_set_reg (iommu,0 ,0 ,8 , &save_src, true)) + goto pc_false; + +if (val != val2) goto pc_false;pci_info (pdev,"IOMMU performance counters supported\n" );
Signature · 6 lines
2.30.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Sasha Levin
maintainerPATCH 16/33 sparc32: Limit memblock allocation to low memory
In reply to Sasha LevinFrom: Andreas Larsson <[email protected]>
[ Upstream commit bda166930c37604ffa93f2425426af6921ec575a ]
Commit cca079ef8ac29a7c02192d2bad2ffe4c0c5ffdd0 changed sparc32 to use memblocks instead of bootmem, but also made high memory available via memblock allocation which does not work together with e.g. phys_to_virt and can lead to kernel panic.
This changes back to only low memory being allocatable in the early stages, now using memblock allocation.
--- arch/sparc/mm/init_32.c | 3 +++ 1 file changed, 3 insertions(+)
arch/sparc/mm/init_32.c +3 -0
@@ -197,6 +197,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail) size =memblock_phys_mem_size () -memblock_reserved_size (); *pages_avail = (size >>PAGE_SHIFT ) - high_pages; +/* Only allow low memory to be allocated via memblock allocation */ +memblock_set_current_limit (max_low_pfn <<PAGE_SHIFT ); +return max_pfn; }
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 17/33 sparc64: Use arch_validate_flags() to validate ADI flag
In reply to Sasha LevinFrom: Khalid Aziz <[email protected]>
[ Upstream commit 147d8622f2a26ef34beacc60e1ed8b66c2fa457f ]
When userspace calls mprotect() to enable ADI on an address range, do_mprotect_pkey() calls arch_validate_prot() to validate new protection flags. arch_validate_prot() for sparc looks at the first VMA associated with address range to verify if ADI can indeed be enabled on this address range. This has two issues - (1) Address range might cover multiple VMAs while arch_validate_prot() looks at only the first VMA, (2) arch_validate_prot() peeks at VMA without holding mmap lock which can result in race condition.
arch_validate_flags() from commit c462ac288f2c ("mm: Introduce arch_validate_flags()") allows for VMA flags to be validated for all VMAs that cover the address range given by user while holding mmap lock. This patch updates sparc code to move the VMA check from arch_validate_prot() to arch_validate_flags() to fix above two issues.
--- arch/sparc/include/asm/mman.h | 54 +++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 25 deletions(-)
arch/sparc/include/asm/mman.h +29 -25
@@ -57,35 +57,39 @@ static inline int sparc_validate_prot(unsigned long prot, unsigned long addr) {if (prot & ~(PROT_READ |PROT_WRITE |PROT_EXEC |PROT_SEM |PROT_ADI ))return 0 ; -if (prot &PROT_ADI ) { -if (!adi_capable ()) -return 0 ; +return 1 ; +} -if (addr) { -struct vm_area_struct *vma; +#define arch_validate_flags (vm_flags) arch_validate_flags(vm_flags) +/* arch_validate_flags() - Ensure combination of flags is valid for a +* VMA. +*/ +static inline bool arch_validate_flags (unsigned long vm_flags) +{ +/* If ADI is being enabled on this VMA, check for ADI +* capability on the platform and ensure VMA is suitable +* for ADI +*/ +if (vm_flags &VM_SPARC_ADI ) { +if (!adi_capable ()) +return false; - vma =find_vma (current->mm, addr); -if (vma) { -/* ADI can not be enabled on PFN -* mapped pages -*/ -if (vma->vm_flags & (VM_PFNMAP |VM_MIXEDMAP )) -return 0 ; +/* ADI can not be enabled on PFN mapped pages */ +if (vm_flags & (VM_PFNMAP |VM_MIXEDMAP )) +return false; -/* Mergeable pages can become unmergeable -* if ADI is enabled on them even if they -* have identical data on them. This can be -* because ADI enabled pages with identical -* data may still not have identical ADI -* tags on them. Disallow ADI on mergeable -* pages. -*/ -if (vma->vm_flags &VM_MERGEABLE ) -return 0 ; - } - } +/* Mergeable pages can become unmergeable +* if ADI is enabled on them even if they +* have identical data on them. This can be +* because ADI enabled pages with identical +* data may still not have identical ADI +* tags on them. Disallow ADI on mergeable +* pages. +*/ +if (vm_flags &VM_MERGEABLE ) +return false; } -return 1 ; +return true; }#endif /* CONFIG_SPARC64 */
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 18/33 ACPICA: Fix race in generic_serial_bus (I2C) and GPIO op_region parameter handling
In reply to Sasha LevinFrom: Hans de Goede <[email protected]>
[ Upstream commit c27f3d011b08540e68233cf56274fdc34bebb9b5 ]
ACPICA commit c9e0116952363b0fa815143dca7e9a2eb4fefa61
The handling of the generic_serial_bus (I2C) and GPIO op_regions in acpi_ev_address_space_dispatch() passes a number of extra parameters to the address-space handler through the address-space Context pointer (instead of using more function parameters).
The Context is shared between threads, so if multiple threads try to call the handler for the same address-space at the same time, then a second thread could change the parameters of a first thread while the handler is running for the first thread.
An example of this race hitting is the Lenovo Yoga Tablet2 1015L, where there are both attrib_bytes accesses and attrib_byte accesses to the same address-space. The attrib_bytes access stores the number of bytes to transfer in Context->access_length. Where as for the attrib_byte access the number of bytes to transfer is always 1 and field_obj->Field.access_length is unused (so 0). Both types of accesses racing from different threads leads to the following problem:
1. Thread a. starts an attrib_bytes access, stores a non 0 value
from field_obj->Field.access_length in Context->access_length
2. Thread b. starts an attrib_byte access, stores 0 in
Context->access_length
3. Thread a. calls i2c_acpi_space_handler() (under Linux). Which sees that the access-type is ACPI_GSB_ACCESS_ATTRIB_MULTIBYTE and calls acpi_gsb_i2c_read_bytes(..., Context->access_length)
4. At this point Context->access_length is 0 (set by thread b.)
rather then the field_obj->Field.access_length value from thread a. This 0 length reads leads to the following errors being logged:
i2c i2c-0: adapter quirk: no zero length (addr 0x0078, size 0, read) i2c i2c-0: i2c read 0 bytes from client@0x78 starting at reg 0x0 failed, error: -95
Note this is just an example of the problems which this race can cause.
There are likely many more (sporadic) problems caused by this race.
This commit adds a new context_mutex to struct acpi_object_addr_handler and makes acpi_ev_address_space_dispatch() take that mutex when using the shared Context to pass extra parameters to an address-space handler, fixing this race.
Note the new mutex must be taken *after* exiting the interpreter, therefor the existing acpi_ex_exit_interpreter() call is moved to above the code which stores the extra parameters in the Context.
--- drivers/acpi/acpica/acobject.h | 1 + drivers/acpi/acpica/evhandler.c | 7 ++++ drivers/acpi/acpica/evregion.c | 64 ++++++++++++++++++++++++--------- drivers/acpi/acpica/evxfregn.c | 2 ++ 4 files changed, 57 insertions(+), 17 deletions(-)
drivers/acpi/acpica/acobject.h +1 -0
@@ -283,6 +283,7 @@ struct acpi_object_addr_handler {acpi_adr_space_handler handler;struct acpi_namespace_node *node;/* Parent device */ void *context; +acpi_mutex context_mutex;acpi_adr_space_setup setup;union acpi_operand_object *region_list;/* Regions using this handler */ union acpi_operand_object *next;
drivers/acpi/acpica/evhandler.c +7 -0
@@ -489,6 +489,13 @@ acpi_ev_install_space_handler(struct acpi_namespace_node *node,/* Init handler obj */ + status = +acpi_os_create_mutex (&handler_obj->address_space.context_mutex); +if (ACPI_FAILURE (status)) { +acpi_ut_remove_reference (handler_obj); + goto unlock_and_exit; + } + handler_obj->address_space.space_id = (u8 )space_id; handler_obj->address_space.handler_flags = flags; handler_obj->address_space.region_list =NULL ;
drivers/acpi/acpica/evregion.c +47 -17
117 lines not on this page · raw message
drivers/acpi/acpica/evxfregn.c +2 -0
@@ -201,6 +201,8 @@ acpi_remove_address_space_handler(acpi_handle device,/* Now we can delete the handler object */ +acpi_os_release_mutex (handler_obj->address_space. + context_mutex);acpi_ut_remove_reference (handler_obj); goto unlock_and_exit; }
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 19/33 Input: applespi - don't wait for responses to commands indefinitely.
In reply to Sasha LevinFrom: Ronald Tschalär <[email protected]>
[ Upstream commit 0ce1ac23149c6da939a5926c098c270c58c317a0 ]
The response to a command may never arrive or it may be corrupted (and hence dropped) for some reason. While exceedingly rare, when it did happen it blocked all further commands. One way to fix this was to do a suspend/resume. However, recovering automatically seems like a nicer option. Hence this puts a time limit (1 sec) on how long we're willing to wait for a response, after which we assume it got lost.
--- drivers/input/keyboard/applespi.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/input/keyboard/applespi.c +15 -6
@@ -48,6 +48,7 @@#include <linux/efi.h> #include <linux/input.h> #include <linux/input/mt.h> +#include <linux/ktime.h> #include <linux/leds.h> #include <linux/module.h> #include <linux/spinlock.h>
@@ -400,7 +401,7 @@ struct applespi_data {unsigned int cmd_msg_cntr;/* lock to protect the above parameters and flags below */ spinlock_t cmd_msg_lock; -bool cmd_msg_queued; +ktime_t cmd_msg_queued;enum applespi_evt_type cmd_evt_type;struct led_classdev backlight_info;
@@ -716,7 +717,7 @@ static void applespi_msg_complete(struct applespi_data *applespi,wake_up_all (&applespi->drain_complete);if (is_write_msg) { - applespi->cmd_msg_queued = false; + applespi->cmd_msg_queued =0 ;applespi_send_cmd_msg (applespi); }
@@ -758,8 +759,16 @@ static int applespi_send_cmd_msg(struct applespi_data *applespi)return 0 ;/* check whether send is in progress */ -if (applespi->cmd_msg_queued) -return 0 ; +if (applespi->cmd_msg_queued) { +if (ktime_ms_delta (ktime_get (), applespi->cmd_msg_queued) <1000 ) +return 0 ; + +dev_warn (&applespi->spi->dev,"Command %d timed out\n" , + applespi->cmd_evt_type); + + applespi->cmd_msg_queued =0 ; + applespi->write_active = false; + }/* set up packet */ memset (packet,0 ,APPLESPI_PACKET_SIZE );
@@ -856,7 +865,7 @@ static int applespi_send_cmd_msg(struct applespi_data *applespi)return sts; } - applespi->cmd_msg_queued = true; + applespi->cmd_msg_queued =ktime_get_coarse (); applespi->write_active = true;return 0 ;
@@ -1908,7 +1917,7 @@ static int __maybe_unused applespi_resume(struct device *dev) applespi->drain = false; applespi->have_cl_led_on = false; applespi->have_bl_level =0 ; - applespi->cmd_msg_queued = false; + applespi->cmd_msg_queued =0 ; applespi->read_active = false; applespi->write_active = false;
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 20/33 x86, build: use objtool mcount
In reply to Sasha LevinFrom: Sami Tolvanen <[email protected]>
[ Upstream commit 6dafca97803309c3cb5148d449bfa711e41ddef2 ]
Select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION is selected to use objtool to generate __mcount_loc sections for dynamic ftrace with Clang and gcc <5 (later versions of gcc use -mrecord-mcount).
--- arch/x86/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/x86/Kconfig +1 -0
@@ -154,6 +154,7 @@ config X86 select HAVE_CONTEXT_TRACKING if X86_64 select HAVE_COPY_THREAD_TLS select HAVE_C_RECORDMCOUNT + select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACE
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 21/33 PCI: xgene-msi: Fix race in installing chained irq handler
In reply to Sasha LevinFrom: Martin Kaiser <[email protected]>
[ Upstream commit a93c00e5f975f23592895b7e83f35de2d36b7633 ]
Fix a race where a pending interrupt could be received and the handler called before the handler's data has been setup, by converting to irq_set_chained_handler_and_data().
See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained IRQ handler").
Based on the mail discussion, it seems ok to drop the error handling.
--- drivers/pci/controller/pci-xgene-msi.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/pci/controller/pci-xgene-msi.c +3 -7
@@ -384,13 +384,9 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu)if (!msi_group->gic_irq)continue ; -irq_set_chained_handler (msi_group->gic_irq, - xgene_msi_isr); - err =irq_set_handler_data (msi_group->gic_irq, msi_group); -if (err) { -pr_err ("failed to register GIC IRQ handler\n" ); -return -EINVAL ; - } +irq_set_chained_handler_and_data (msi_group->gic_irq, + xgene_msi_isr, msi_group); +/* * Statically allocate MSI GIC IRQs to each CPU core. * With 8-core X-Gene v1, 2 MSI GIC IRQs are allocated
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 22/33 misc: eeprom_93xx46: Add quirk to support Microchip 93LC46B eeprom
In reply to Sasha LevinFrom: Aswath Govindraju <[email protected]>
[ Upstream commit f6f1f8e6e3eea25f539105d48166e91f0ab46dd1 ]
A dummy zero bit is sent preceding the data during a read transfer by the Microchip 93LC46B eeprom (section 2.7 of[1]). This results in right shift of data during a read. In order to ignore this bit a quirk can be added to send an extra zero bit after the read address.
Add a quirk to ignore the zero bit sent before data by adding a zero bit after the read address.
[1] - https://www.mouser.com/datasheet/2/268/20001749K-277859.pdf
--- drivers/misc/eeprom/eeprom_93xx46.c | 15 +++++++++++++++ include/linux/eeprom_93xx46.h | 2 ++ 2 files changed, 17 insertions(+)
drivers/misc/eeprom/eeprom_93xx46.c +15 -0
@@ -35,6 +35,10 @@ static const struct eeprom_93xx46_devtype_data atmel_at93c46d_data = { EEPROM_93XX46_QUIRK_INSTRUCTION_LENGTH, }; +static const struct eeprom_93xx46_devtype_data microchip_93lc46b_data = { + .quirks =EEPROM_93XX46_QUIRK_EXTRA_READ_CYCLE , +}; +struct eeprom_93xx46_dev {struct spi_device *spi;struct eeprom_93xx46_platform_data *pdata;
@@ -55,6 +59,11 @@ static inline bool has_quirk_instruction_length(struct eeprom_93xx46_dev *edev)return edev->pdata->quirks &EEPROM_93XX46_QUIRK_INSTRUCTION_LENGTH ; } +static inline bool has_quirk_extra_read_cycle (struct eeprom_93xx46_dev *edev) +{ +return edev->pdata->quirks &EEPROM_93XX46_QUIRK_EXTRA_READ_CYCLE ; +} +static int eeprom_93xx46_read (void *priv,unsigned int off,void *val,size_t count) {
@@ -96,6 +105,11 @@ static int eeprom_93xx46_read(void *priv, unsigned int off,dev_dbg (&edev->spi->dev,"read cmd 0x%x, %d Hz\n" , cmd_addr, edev->spi->max_speed_hz); +if (has_quirk_extra_read_cycle (edev)) { + cmd_addr <<=1 ; + bits +=1 ; + } +spi_message_init (&m); t[0 ].tx_buf = (char *)&cmd_addr;
@@ -363,6 +377,7 @@ static void select_deassert(void *context)static const struct of_device_id eeprom_93xx46_of_table[] = { { .compatible ="eeprom-93xx46" , }, { .compatible ="atmel,at93c46d" , .data = &atmel_at93c46d_data, }, + { .compatible ="microchip,93lc46b" , .data = µchip_93lc46b_data, }, {} };MODULE_DEVICE_TABLE (of, eeprom_93xx46_of_table);
include/linux/eeprom_93xx46.h +2 -0
@@ -16,6 +16,8 @@ struct eeprom_93xx46_platform_data {#define EEPROM_93XX46_QUIRK_SINGLE_WORD_READ (1 << 0)/* Instructions such as EWEN are (addrlen + 2) in length. */ #define EEPROM_93XX46_QUIRK_INSTRUCTION_LENGTH (1 << 1) +/* Add extra cycle after address during a read */ +#define EEPROM_93XX46_QUIRK_EXTRA_READ_CYCLE BIT(2)/* * optional hooks to control additional logic
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 23/33 PCI: mediatek: Add missing of_node_put() to fix reference leak
In reply to Sasha LevinFrom: Krzysztof Wilczyński <[email protected]>
[ Upstream commit 42814c438aac79746d310f413a27d5b0b959c5de ]
The for_each_available_child_of_node helper internally makes use of the of_get_next_available_child() which performs an of_node_get() on each iteration when searching for next available child node.
Should an available child node be found, then it would return a device node pointer with reference count incremented, thus early return from the middle of the loop requires an explicit of_node_put() to prevent reference count leak.
To stop the reference leak, explicitly call of_node_put() before returning after an error occurred.
--- drivers/pci/controller/pcie-mediatek.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/pci/controller/pcie-mediatek.c +5 -2
@@ -1063,14 +1063,14 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie) err =of_pci_get_devfn (child);if (err <0 ) {dev_err (dev,"failed to parse devfn: %d\n" , err); -return err; + goto error_put_node; } slot =PCI_SLOT (err); err =mtk_pcie_parse_port (pcie, child, slot);if (err) -return err; + goto error_put_node; } err =mtk_pcie_subsys_powerup (pcie);
@@ -1086,6 +1086,9 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)mtk_pcie_subsys_powerdown (pcie);return 0 ; +error_put_node: +of_node_put (child); +return err; }static int mtk_pcie_probe (struct platform_device *pdev)
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 24/33 drm/msm/a5xx: Remove overwriting A5XX_PC_DBG_ECO_CNTL register
In reply to Sasha LevinFrom: AngeloGioacchino Del Regno <[email protected]>
[ Upstream commit 8f03c30cb814213e36032084a01f49a9e604a3e3 ]
The PC_DBG_ECO_CNTL register on the Adreno A5xx family gets programmed to some different values on a per-model basis. At least, this is what we intend to do here;
Unfortunately, though, this register is being overwritten with a static magic number, right after applying the GPU-specific configuration (including the GPU-specific quirks) and that is effectively nullifying the efforts.
Let's remove the redundant and wrong write to the PC_DBG_ECO_CNTL register in order to retain the wanted configuration for the target GPU.
--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 2 -- 1 file changed, 2 deletions(-)
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +0 -2
@@ -581,8 +581,6 @@ static int a5xx_hw_init(struct msm_gpu *gpu)if (adreno_gpu->info->quirks &ADRENO_QUIRK_TWO_PASS_USE_WFI )gpu_rmw (gpu,REG_A5XX_PC_DBG_ECO_CNTL ,0 , (1 <<8 )); -gpu_write (gpu,REG_A5XX_PC_DBG_ECO_CNTL ,0xc0200100 ); -/* Enable USE_RETENTION_FLOPS */ gpu_write (gpu,REG_A5XX_CP_CHICKEN_DBG ,0x02000000 );
Signature · 6 lines
2.30.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Sasha Levin
maintainerPATCH 25/33 kbuild: clamp SUBLEVEL to 255
In reply to Sasha Levin[ Upstream commit 9b82f13e7ef316cdc0a8858f1349f4defce3f9e0 ]
Right now if SUBLEVEL becomes larger than 255 it will overflow into the territory of PATCHLEVEL, causing havoc in userspace that tests for specific kernel version.
While userspace code tests for MAJOR and PATCHLEVEL, it doesn't test SUBLEVEL at any point as ABI changes don't happen in the context of stable tree.
Thus, to avoid overflows, simply clamp SUBLEVEL to it's maximum value in the context of LINUX_VERSION_CODE. This does not affect "make kernelversion" and such.
--- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
Makefile +9 -3
@@ -1175,9 +1175,15 @@ define filechk_utsrelease.h endef define filechk_version.h - echo \#define LINUX_VERSION_CODE $(shell \ - expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ - echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' + if [ $(SUBLEVEL) -gt 255 ]; then \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 255); \ + else \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ + fi; \ + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ + ((c) > 255 ? 255 : (c)))' endef $(version_h): FORCE
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 26/33 PCI: Fix pci_register_io_range() memory leak
In reply to Sasha LevinFrom: Geert Uytterhoeven <[email protected]>
[ Upstream commit f6bda644fa3a7070621c3bf12cd657f69a42f170 ]
Kmemleak reports:
unreferenced object 0xc328de40 (size 64):
comm "kworker/1:1", pid 21, jiffies 4294938212 (age 1484.670s)
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 e0 d8 fc eb 00 00 00 00 ................
00 00 10 fe 00 00 00 00 00 00 00 00 00 00 00 00 ................backtrace:
[<ad758d10>] pci_register_io_range+0x3c/0x80
[<2c7f139e>] of_pci_range_to_resource+0x48/0xc0
[<f079ecc8>] devm_of_pci_get_host_bridge_resources.constprop.0+0x2ac/0x3ac
[<e999753b>] devm_of_pci_bridge_init+0x60/0x1b8
[<a895b229>] devm_pci_alloc_host_bridge+0x54/0x64
[<e451ddb0>] rcar_pcie_probe+0x2c/0x644In case a PCI host driver's probe is deferred, the same I/O range may be allocated again, and be ignored, causing a memory leak.
Fix this by (a) letting logic_pio_register_range() return -EEXIST if the passed range already exists, so pci_register_io_range() will free it, and by (b) making pci_register_io_range() not consider -EEXIST an error condition.
--- drivers/pci/pci.c | 4 ++++ lib/logic_pio.c | 3 +++ 2 files changed, 7 insertions(+)
drivers/pci/pci.c +4 -0
@@ -3896,6 +3896,10 @@ int pci_register_io_range(struct fwnode_handle *fwnode, phys_addr_t addr, ret =logic_pio_register_range (range);if (ret)kfree (range); + +/* Ignore duplicates due to deferred probing */ +if (ret == -EEXIST ) + ret =0 ;#endif return ret;
lib/logic_pio.c +3 -0
@@ -27,6 +27,8 @@ static DEFINE_MUTEX(io_range_mutex);* @new_range: pointer to the IO range to be registered. * * Returns 0 on success, the error code in case of failure. +* If the range already exists, -EEXIST will be returned, which should be +* considered a success. * * Register a new IO range node in the IO range list. */
@@ -49,6 +51,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)list_for_each_entry (range, &io_range_list, list) {if (range->fwnode == new_range->fwnode) {/* range already there */ + ret = -EEXIST ; goto end_register; } if (range->flags == LOGIC_PIO_CPU_MMIO &&
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 27/33 i40e: Fix memory leak in i40e_probe
In reply to Sasha LevinFrom: Keita Suzuki <[email protected]>
[ Upstream commit 58cab46c622d6324e47bd1c533693c94498e4172 ]
Struct i40e_veb is allocated in function i40e_setup_pf_switch, and stored to an array field veb inside struct i40e_pf. However when i40e_setup_misc_vector fails, this memory leaks.
Fix this by calling exit and teardown functions.
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/intel/i40e/i40e_main.c +2 -0
@@ -15164,6 +15164,8 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (err) {dev_info (&pdev->dev,"setup of misc vector failed: %d\n" , err); +i40e_cloud_filter_exit (pf); +i40e_fdir_teardown (pf); goto err_vsis; } }
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 28/33 s390/smp: __smp_rescan_cpus() - move cpumask away from stack
In reply to Sasha LevinFrom: Heiko Carstens <[email protected]>
[ Upstream commit 62c8dca9e194326802b43c60763f856d782b225c ]
Avoid a potentially large stack frame and overflow by making "cpumask_t avail" a static variable. There is no concurrent access due to the existing locking.
--- arch/s390/kernel/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kernel/smp.c +1 -1
@@ -765,7 +765,7 @@ static int smp_add_core(struct sclp_core_entry *core, cpumask_t *avail,static int __smp_rescan_cpus (struct sclp_core_info *info,bool early) {struct sclp_core_entry *core; -cpumask_t avail; +static cpumask_t avail;bool configured;u16 core_id;int nr, i;
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 29/33 sysctl.c: fix underflow value setting risk in vm_table
In reply to Sasha LevinFrom: Lin Feng <[email protected]>
[ Upstream commit 3b3376f222e3ab58367d9dd405cafd09d5e37b7c ]
Apart from subsystem specific .proc_handler handler, all ctl_tables with extra1 and extra2 members set should use proc_dointvec_minmax instead of proc_dointvec, or the limit set in extra* never work and potentially echo underflow values(negative numbers) is likely make system unstable.
Especially vfs_cache_pressure and zone_reclaim_mode, -1 is apparently not a valid value, but we can set to them. And then kernel may crash.
# echo -1 > /proc/sys/vm/vfs_cache_pressure
--- kernel/sysctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/sysctl.c +4 -4
@@ -1563,7 +1563,7 @@ static struct ctl_table vm_table[] = { .data = &block_dump, .maxlen = sizeof(block_dump), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, }, {
@@ -1571,7 +1571,7 @@ static struct ctl_table vm_table[] = { .data = &sysctl_vfs_cache_pressure, .maxlen = sizeof(sysctl_vfs_cache_pressure), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, }, #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
@@ -1581,7 +1581,7 @@ static struct ctl_table vm_table[] = { .data = &sysctl_legacy_va_layout, .maxlen = sizeof(sysctl_legacy_va_layout), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, },#endif
@@ -1591,7 +1591,7 @@ static struct ctl_table vm_table[] = { .data = &node_reclaim_mode, .maxlen = sizeof(node_reclaim_mode), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, }, {
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 30/33 scsi: libiscsi: Fix iscsi_prep_scsi_cmd_pdu() error handling
In reply to Sasha LevinFrom: Mike Christie <[email protected]>
[ Upstream commit d28d48c699779973ab9a3bd0e5acfa112bd4fdef ]
If iscsi_prep_scsi_cmd_pdu() fails we try to add it back to the cmdqueue, but we leave it partially setup. We don't have functions that can undo the pdu and init task setup. We only have cleanup_task which can clean up both parts. So this has us just fail the cmd and go through the standard cleanup routine and then have the SCSI midlayer retry it like is done when it fails in the queuecommand path.
--- drivers/scsi/libiscsi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/scsi/libiscsi.c +3 -8
@@ -1532,14 +1532,9 @@ check_mgmt: } rc =iscsi_prep_scsi_cmd_pdu (conn->task);if (rc) { -if (rc == -ENOMEM || rc == -EACCES ) { -spin_lock_bh (&conn->taskqueuelock); -list_add_tail (&conn->task->running, - &conn->cmdqueue); - conn->task =NULL ; -spin_unlock_bh (&conn->taskqueuelock); - goto done; - }else +if (rc == -ENOMEM || rc == -EACCES ) +fail_scsi_task (conn->task,DID_IMM_RETRY ); +else fail_scsi_task (conn->task,DID_ABORT );spin_lock_bh (&conn->taskqueuelock);continue ;
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 31/33 nbd: handle device refs for DESTROY_ON_DISCONNECT properly
In reply to Sasha LevinFrom: Josef Bacik <[email protected]>
[ Upstream commit c9a2f90f4d6b9d42b9912f7aaf68e8d748acfffd ]
There exists a race where we can be attempting to create a new nbd configuration while a previous configuration is going down, both configured with DESTROY_ON_DISCONNECT. Normally devices all have a reference of 1, as they won't be cleaned up until the module is torn down. However with DESTROY_ON_DISCONNECT we'll make sure that there is only 1 reference (generally) on the device for the config itself, and then once the config is dropped, the device is torn down.
The race that exists looks like this
TASK1 TASK2nbd_genl_connect()
idr_find()
refcount_inc_not_zero(nbd)
* count is 2 here ^^
nbd_config_put()
nbd_put(nbd) (count is 1)
setup new config
check DESTROY_ON_DISCONNECT
put_dev = true
if (put_dev) nbd_put(nbd)
* free'd here ^^
In nbd_genl_connect() we assume that the nbd ref count will be 2, however clearly that won't be true if the nbd device had been setup as DESTROY_ON_DISCONNECT with its prior configuration. Fix this by getting rid of the runtime flag to check if we need to mess with the nbd device refcount, and use the device NBD_DESTROY_ON_DISCONNECT flag to check if we need to adjust the ref counts. This was reported by syzkaller with the following kasan dump
BUG: KASAN: use-after-free in instrument_atomic_read include/linux/instrumented.h:71 [inline]
BUG: KASAN: use-after-free in atomic_read include/asm-generic/atomic-instrumented.h:27 [inline]
BUG: KASAN: use-after-free in refcount_dec_not_one+0x71/0x1e0 lib/refcount.c:76
Read of size 4 at addr ffff888143bf71a0 by task systemd-udevd/8451
CPU: 0 PID: 8451 Comm: systemd-udevd Not tainted 5.11.0-rc7-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:79 [inline]
dump_stack+0x107/0x163 lib/dump_stack.c:120
print_address_description.constprop.0.cold+0x5b/0x2f8 mm/kasan/report.c:230
__kasan_report mm/kasan/report.c:396 [inline]
kasan_report.cold+0x79/0xd5 mm/kasan/report.c:413
check_memory_region_inline mm/kasan/generic.c:179 [inline]
check_memory_region+0x13d/0x180 mm/kasan/generic.c:185
instrument_atomic_read include/linux/instrumented.h:71 [inline]
atomic_read include/asm-generic/atomic-instrumented.h:27 [inline]
refcount_dec_not_one+0x71/0x1e0 lib/refcount.c:76
refcount_dec_and_mutex_lock+0x19/0x140 lib/refcount.c:115
nbd_put drivers/block/nbd.c:248 [inline]
nbd_release+0x116/0x190 drivers/block/nbd.c:1508
__blkdev_put+0x548/0x800 fs/block_dev.c:1579
blkdev_put+0x92/0x570 fs/block_dev.c:1632
blkdev_close+0x8c/0xb0 fs/block_dev.c:1640
__fput+0x283/0x920 fs/file_table.c:280
task_work_run+0xdd/0x190 kernel/task_work.c:140
tracehook_notify_resume include/linux/tracehook.h:189 [inline]
exit_to_user_mode_loop kernel/entry/common.c:174 [inline]
exit_to_user_mode_prepare+0x249/0x250 kernel/entry/common.c:201
__syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7fc1e92b5270
Code: 73 01 c3 48 8b 0d 38 7d 20 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 83 3d 59 c1 20 00 00 75 10 b8 03 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 ee fb ff ff 48 89 04 24
RSP: 002b:00007ffe8beb2d18 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000007 RCX: 00007fc1e92b5270
RDX: 000000000aba9500 RSI: 0000000000000000 RDI: 0000000000000007
RBP: 00007fc1ea16f710 R08: 000000000000004a R09: 0000000000000008
R10: 0000562f8cb0b2a8 R11: 0000000000000246 R12: 0000000000000000
R13: 0000562f8cb0afd0 R14: 0000000000000003 R15: 000000000000000e
Allocated by task 1:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
kasan_set_track mm/kasan/common.c:46 [inline]
set_alloc_info mm/kasan/common.c:401 [inline]
____kasan_kmalloc.constprop.0+0x82/0xa0 mm/kasan/common.c:429
kmalloc include/linux/slab.h:552 [inline]
kzalloc include/linux/slab.h:682 [inline]
nbd_dev_add+0x44/0x8e0 drivers/block/nbd.c:1673
nbd_init+0x250/0x271 drivers/block/nbd.c:2394
do_one_initcall+0x103/0x650 init/main.c:1223
do_initcall_level init/main.c:1296 [inline]
do_initcalls init/main.c:1312 [inline]
do_basic_setup init/main.c:1332 [inline]
kernel_init_freeable+0x605/0x689 init/main.c:1533
kernel_init+0xd/0x1b8 init/main.c:1421
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296
Freed by task 8451:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
kasan_set_track+0x1c/0x30 mm/kasan/common.c:46
kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:356
____kasan_slab_free+0xe1/0x110 mm/kasan/common.c:362
kasan_slab_free include/linux/kasan.h:192 [inline]
slab_free_hook mm/slub.c:1547 [inline]
slab_free_freelist_hook+0x5d/0x150 mm/slub.c:1580
slab_free mm/slub.c:3143 [inline]
kfree+0xdb/0x3b0 mm/slub.c:4139
nbd_dev_remove drivers/block/nbd.c:243 [inline]
nbd_put.part.0+0x180/0x1d0 drivers/block/nbd.c:251
nbd_put drivers/block/nbd.c:295 [inline]
nbd_config_put+0x6dd/0x8c0 drivers/block/nbd.c:1242
nbd_release+0x103/0x190 drivers/block/nbd.c:1507
__blkdev_put+0x548/0x800 fs/block_dev.c:1579
blkdev_put+0x92/0x570 fs/block_dev.c:1632
blkdev_close+0x8c/0xb0 fs/block_dev.c:1640
__fput+0x283/0x920 fs/file_table.c:280
task_work_run+0xdd/0x190 kernel/task_work.c:140
tracehook_notify_resume include/linux/tracehook.h:189 [inline]
exit_to_user_mode_loop kernel/entry/common.c:174 [inline]
exit_to_user_mode_prepare+0x249/0x250 kernel/entry/common.c:201
__syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x44/0xa9
The buggy address belongs to the object at ffff888143bf7000
which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 416 bytes inside of
1024-byte region [ffff888143bf7000, ffff888143bf7400)
The buggy address belongs to the page:
page:000000005238f4ce refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x143bf0
head:000000005238f4ce order:3 compound_mapcount:0 compound_pincount:0
flags: 0x57ff00000010200(slab|head)
raw: 057ff00000010200 ffffea00004b1400 0000000300000003 ffff888010c41140
raw: 0000000000000000 0000000000100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff888143bf7080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888143bf7100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888143bf7180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888143bf7200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb--- drivers/block/nbd.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
drivers/block/nbd.c +19 -13
@@ -78,8 +78,7 @@ struct link_dead_args {#define NBD_RT_HAS_PID_FILE 3#define NBD_RT_HAS_CONFIG_REF 4#define NBD_RT_BOUND 5 -#define NBD_RT_DESTROY_ON_DISCONNECT 6 -#define NBD_RT_DISCONNECT_ON_CLOSE 7 +#define NBD_RT_DISCONNECT_ON_CLOSE 6#define NBD_DESTROY_ON_DISCONNECT 0#define NBD_DISCONNECT_REQUESTED 1
@@ -1940,12 +1939,21 @@ again:if (info->attrs[NBD_ATTR_CLIENT_FLAGS ]) {u64 flags =nla_get_u64 (info->attrs[NBD_ATTR_CLIENT_FLAGS ]);if (flags &NBD_CFLAG_DESTROY_ON_DISCONNECT ) { -set_bit (NBD_RT_DESTROY_ON_DISCONNECT , - &config->runtime_flags); -set_bit (NBD_DESTROY_ON_DISCONNECT , &nbd->flags); - put_dev = true; +/* +* We have 1 ref to keep the device around, and then 1 +* ref for our current operation here, which will be +* inherited by the config. If we already have +* DESTROY_ON_DISCONNECT set then we know we don't have +* that extra ref already held so we don't need the +* put_dev. +*/ +if (!test_and_set_bit (NBD_DESTROY_ON_DISCONNECT , + &nbd->flags)) + put_dev = true; }else { -clear_bit (NBD_DESTROY_ON_DISCONNECT , &nbd->flags); +if (test_and_clear_bit (NBD_DESTROY_ON_DISCONNECT , + &nbd->flags)) +refcount_inc (&nbd->refs); }if (flags &NBD_CFLAG_DISCONNECT_ON_CLOSE ) { set_bit(NBD_RT_DISCONNECT_ON_CLOSE,
@@ -2116,15 +2124,13 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)if (info->attrs[NBD_ATTR_CLIENT_FLAGS ]) {u64 flags =nla_get_u64 (info->attrs[NBD_ATTR_CLIENT_FLAGS ]);if (flags &NBD_CFLAG_DESTROY_ON_DISCONNECT ) { -if (!test_and_set_bit (NBD_RT_DESTROY_ON_DISCONNECT , - &config->runtime_flags)) +if (!test_and_set_bit (NBD_DESTROY_ON_DISCONNECT , + &nbd->flags)) put_dev = true; -set_bit (NBD_DESTROY_ON_DISCONNECT , &nbd->flags); }else { -if (test_and_clear_bit (NBD_RT_DESTROY_ON_DISCONNECT , - &config->runtime_flags)) +if (test_and_clear_bit (NBD_DESTROY_ON_DISCONNECT , + &nbd->flags))refcount_inc (&nbd->refs); -clear_bit (NBD_DESTROY_ON_DISCONNECT , &nbd->flags); }if (flags &NBD_CFLAG_DISCONNECT_ON_CLOSE ) {
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 32/33 scsi: target: core: Add cmd length set before cmd complete
In reply to Sasha LevinFrom: Aleksandr Miloserdov <[email protected]>
[ Upstream commit 1c73e0c5e54d5f7d77f422a10b03ebe61eaed5ad ]
TCM doesn't properly handle underflow case for service actions. One way to prevent it is to always complete command with target_complete_cmd_with_length(), however it requires access to data_sg, which is not always available.
This change introduces target_set_cmd_data_length() function which allows to set command data length before completing it.
--- drivers/target/target_core_transport.c | 15 +++++++++++---- include/target/target_core_backend.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-)
drivers/target/target_core_transport.c +11 -4
@@ -873,11 +873,9 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) }EXPORT_SYMBOL (target_complete_cmd); -void target_complete_cmd_with_length (struct se_cmd *cmd,u8 scsi_status,int length) +void target_set_cmd_data_length (struct se_cmd *cmd,int length) { -if ((scsi_status ==SAM_STAT_GOOD || - cmd->se_cmd_flags &SCF_TREAT_READ_AS_NORMAL ) && - length < cmd->data_length) { +if (length < cmd->data_length) {if (cmd->se_cmd_flags &SCF_UNDERFLOW_BIT ) { cmd->residual_count += cmd->data_length - length; }else {
@@ -887,6 +885,15 @@ void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int len cmd->data_length = length; } +} +EXPORT_SYMBOL (target_set_cmd_data_length); + +void target_complete_cmd_with_length (struct se_cmd *cmd,u8 scsi_status,int length) +{ +if (scsi_status ==SAM_STAT_GOOD || + cmd->se_cmd_flags &SCF_TREAT_READ_AS_NORMAL ) { +target_set_cmd_data_length (cmd, length); + }target_complete_cmd (cmd, scsi_status); }
include/target/target_core_backend.h +1 -0
@@ -69,6 +69,7 @@ int transport_backend_register(const struct target_backend_ops *);void target_backend_unregister (const struct target_backend_ops *);void target_complete_cmd (struct se_cmd *,u8 ); +void target_set_cmd_data_length (struct se_cmd *,int );void target_complete_cmd_with_length (struct se_cmd *,u8 ,int );void transport_copy_sense_to_cmd (struct se_cmd *,unsigned char *);
Signature · 1 line
2.30.1
Sasha Levin
maintainerPATCH 33/33 scsi: target: core: Prevent underflow for service actions
In reply to Sasha LevinFrom: Aleksandr Miloserdov <[email protected]>
[ Upstream commit 14d24e2cc77411301e906a8cf41884739de192de ]
TCM buffer length doesn't necessarily equal 8 + ADDITIONAL LENGTH which might be considered an underflow in case of Data-In size being greater than 8 + ADDITIONAL LENGTH. So truncate buffer length to prevent underflow.
--- drivers/target/target_core_pr.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/target/target_core_pr.c +11 -4
@@ -3731,6 +3731,7 @@ core_scsi3_pri_read_keys(struct se_cmd *cmd)spin_unlock (&dev->t10_pr.registration_lock);put_unaligned_be32 (add_len, &buf[4 ]); +target_set_cmd_data_length (cmd,8 + add_len);transport_kunmap_data_sg (cmd);
@@ -3749,7 +3750,7 @@ core_scsi3_pri_read_reservation(struct se_cmd *cmd)struct t10_pr_registration *pr_reg;unsigned char *buf;u64 pr_res_key; -u32 add_len =16 ;/* Hardcoded to 16 when a reservation is held. */ +u32 add_len =0 ;if (cmd->data_length <8 ) { pr_err("PRIN SA READ_RESERVATIONS SCSI Data Length: %u"
@@ -3767,8 +3768,9 @@ core_scsi3_pri_read_reservation(struct se_cmd *cmd) pr_reg = dev->dev_pr_res_holder;if (pr_reg) {/* -* Set the hardcoded Additional Length +* Set the Additional Length to 16 when a reservation is held */ + add_len =16 ;put_unaligned_be32 (add_len, &buf[4 ]);if (cmd->data_length <22 )
@@ -3804,6 +3806,8 @@ core_scsi3_pri_read_reservation(struct se_cmd *cmd) (pr_reg->pr_res_type &0x0f ); } +target_set_cmd_data_length (cmd,8 + add_len); + err:spin_unlock (&dev->dev_reservation_lock);transport_kunmap_data_sg (cmd);
@@ -3822,7 +3826,7 @@ core_scsi3_pri_report_capabilities(struct se_cmd *cmd)struct se_device *dev = cmd->se_dev;struct t10_reservation *pr_tmpl = &dev->t10_pr;unsigned char *buf; -u16 add_len =8 ;/* Hardcoded to 8. */ +u16 len =8 ;/* Hardcoded to 8. */ if (cmd->data_length <6 ) { pr_err("PRIN SA REPORT_CAPABILITIES SCSI Data Length:"
@@ -3834,7 +3838,7 @@ core_scsi3_pri_report_capabilities(struct se_cmd *cmd)if (!buf)return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ; -put_unaligned_be16 (add_len, &buf[0 ]); +put_unaligned_be16 (len, &buf[0 ]); buf[2 ] |=0x10 ;/* CRH: Compatible Reservation Hanlding bit. */ buf[2 ] |=0x08 ;/* SIP_C: Specify Initiator Ports Capable bit */ buf[2 ] |=0x04 ;/* ATP_C: All Target Ports Capable bit */
@@ -3863,6 +3867,8 @@ core_scsi3_pri_report_capabilities(struct se_cmd *cmd) buf[4 ] |=0x02 ;/* PR_TYPE_WRITE_EXCLUSIVE */ buf[5 ] |=0x01 ;/* PR_TYPE_EXCLUSIVE_ACCESS_ALLREG */ +target_set_cmd_data_length (cmd, len); +transport_kunmap_data_sg (cmd);return 0 ;
@@ -4023,6 +4029,7 @@ core_scsi3_pri_read_full_status(struct se_cmd *cmd)* Set ADDITIONAL_LENGTH */ put_unaligned_be32 (add_len, &buf[4 ]); +target_set_cmd_data_length (cmd,8 + add_len);transport_kunmap_data_sg (cmd);
Signature · 1 line
2.30.1