HID: intel-ish-hid: fix the length of MNG_SYNC_FW_CLOCK in doorbell
Subsystems (7)
Sasha Levin
maintainerPATCH 1/17 HID: intel-ish-hid: fix the length of MNG_SYNC_FW_CLOCK in doorbell
From: Zhang Lixu <[email protected]>
[ Upstream commit 4b54ae69197b9f416baa0fceadff7e89075f8454 ]
The timestamps in the Firmware log and HID sensor samples are incorrect. They show 1970-01-01 because the current IPC driver only uses the first 8 bytes of bootup time when synchronizing time with the firmware. The firmware converts the bootup time to UTC time, which results in the display of 1970-01-01.
In write_ipc_from_queue(), when sending the MNG_SYNC_FW_CLOCK message, the clock is updated according to the definition of ipc_time_update_msg. However, in _ish_sync_fw_clock(), the message length is specified as the size of uint64_t when building the doorbell. As a result, the firmware only receives the first 8 bytes of struct ipc_time_update_msg. This patch corrects the length in the doorbell to ensure the entire ipc_time_update_msg is sent, fixing the timestamp issue.
--- drivers/hid/intel-ish-hid/ipc/ipc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hid/intel-ish-hid/ipc/ipc.c +3 -3
@@ -577,14 +577,14 @@ static void fw_reset_work_fn(struct work_struct *unused)static void _ish_sync_fw_clock (struct ishtp_device *dev) {static unsigned long prev_sync; -uint64_t usec; +struct ipc_time_update_msg time = {};if (prev_sync &&time_before (jiffies, prev_sync +20 *HZ ))return ; prev_sync = jiffies; - usec =ktime_to_us (ktime_get_boottime ()); -ipc_send_mng_msg (dev,MNG_SYNC_FW_CLOCK , &usec,sizeof (uint64_t )); +/* The fields of time would be updated while sending message */ +ipc_send_mng_msg (dev,MNG_SYNC_FW_CLOCK , &time,sizeof (time)); }/**
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 2/17 HID: intel-ish-hid: Send clock sync message immediately after reset
From: Zhang Lixu <[email protected]>
[ Upstream commit 7e0d1cff12b895f44f4ddc8cf50311bc1f775201 ]
The ISH driver performs a clock sync with the firmware once at system startup and then every 20 seconds. If a firmware reset occurs right after a clock sync, the driver would wait 20 seconds before performing another clock sync with the firmware. This is particularly problematic with the introduction of the "load firmware from host" feature, where the driver performs a clock sync with the bootloader and then has to wait 20 seconds before syncing with the main firmware.
This patch clears prev_sync immediately upon receiving an IPC reset, so that the main firmware and driver will perform a clock sync immediately after completing the IPC handshake.
--- drivers/hid/intel-ish-hid/ipc/ipc.c | 9 ++++++--- drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/hid/intel-ish-hid/ipc/ipc.c +6 -3
@@ -517,6 +517,10 @@ static int ish_fw_reset_handler(struct ishtp_device *dev)/* ISH FW is dead */ if (!ish_is_input_ready (dev))return -EPIPE ; + +/* Send clock sync at once after reset */ + ishtp_dev->prev_sync =0 ; +/* * Set HOST2ISH.ILUP. Apparently we need this BEFORE sending * RESET_NOTIFY_ACK - FW will be checking for it
@@ -576,13 +580,12 @@ static void fw_reset_work_fn(struct work_struct *unused)*/ static void _ish_sync_fw_clock (struct ishtp_device *dev) { -static unsigned long prev_sync;struct ipc_time_update_msg time = {}; -if (prev_sync &&time_before (jiffies, prev_sync +20 *HZ )) +if (dev->prev_sync &&time_before (jiffies, dev->prev_sync +20 *HZ ))return ; - prev_sync = jiffies; + dev->prev_sync = jiffies;/* The fields of time would be updated while sending message */ ipc_send_mng_msg (dev,MNG_SYNC_FW_CLOCK , &time,sizeof (time)); }
drivers/hid/intel-ish-hid/ishtp/ishtp-dev.h +2 -0
@@ -212,6 +212,8 @@ struct ishtp_device {unsigned int ipc_tx_cnt;unsigned long long ipc_tx_bytes_cnt; +/* Time of the last clock sync */ +unsigned long prev_sync;const struct ishtp_hw_ops *ops;size_t mtu;uint32_t ishtp_msg_hdr;
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 3/17 HID: ignore non-functional sensor in HP 5MP Camera
In reply to Sasha LevinFrom: "Chia-Lin Kao (AceLan)" <[email protected]>
[ Upstream commit 363236d709e75610b628c2a4337ccbe42e454b6d ]
The HP 5MP Camera (USB ID 0408:5473) reports a HID sensor interface that is not actually implemented. Attempting to access this non-functional sensor via iio_info causes system hangs as runtime PM tries to wake up an unresponsive sensor.
[453] hid-sensor-hub 0003:0408:5473.0003: Report latency attributes: ffffffff:ffffffff
[453] hid-sensor-hub 0003:0408:5473.0003: common attributes: 5:1, 2:1, 3:1 ffffffff:ffffffff
Add this device to the HID ignore list since the sensor interface is non-functional by design and should not be exposed to userspace.
--- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-quirks.c | 1 + 2 files changed, 2 insertions(+)
drivers/hid/hid-ids.h +1 -0
@@ -1085,6 +1085,7 @@#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001 0x3001#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3003 0x3003#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008 0x3008 +#define USB_DEVICE_ID_QUANTA_HP_5MP_CAMERA_5473 0x5473#define I2C_VENDOR_ID_RAYDIUM 0x2386#define I2C_PRODUCT_ID_RAYDIUM_4B33 0x4b33
drivers/hid/hid-quirks.c +1 -0
@@ -891,6 +891,7 @@ static const struct hid_device_id hid_ignore_list[] = { { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) }, #endif { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) }, + { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_HP_5MP_CAMERA_5473) }, { } };
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 4/17 usb: phy: generic: Use proper helper for property detection
In reply to Sasha LevinFrom: Alexander Stein <[email protected]>
[ Upstream commit 309005e448c1f3e4b81e4416406991b7c3339c1d ]
Since commit c141ecc3cecd7 ("of: Warn when of_property_read_bool() is used on non-boolean properties") a warning is raised if this function is used for property detection. of_property_present() is the correct helper for this.
--- drivers/usb/phy/phy-generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/phy/phy-generic.c +1 -1
@@ -217,7 +217,7 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop)if (of_property_read_u32 (node,"clock-frequency" , &clk_rate)) clk_rate =0 ; - needs_clk =of_property_read_bool (node,"clocks" ); + needs_clk =of_property_present (node,"clocks" ); } nop->gpiod_reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_ASIS );
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 5/17 HID: topre: Fix n-key rollover on Realforce R3S TKL boards
In reply to Sasha LevinFrom: Daniel Brackenbury <[email protected]>
[ Upstream commit 9271af9d846c7e49c8709b58d5853cb73c00b193 ]
Newer model R3* Topre Realforce keyboards share an issue with their older R2 cousins where a report descriptor fixup is needed in order for n-key rollover to work correctly, otherwise only 6-key rollover is available. This patch adds some new hardware IDs for the R3S 87-key keyboard and makes amendments to the existing hid-topre driver in order to change the correct byte in the new model.
--- drivers/hid/Kconfig | 3 ++- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-topre.c | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-)
drivers/hid/Kconfig +2 -1
@@ -1151,7 +1151,8 @@ config HID_TOPRE tristate "Topre REALFORCE keyboards" depends on HID help - Say Y for N-key rollover support on Topre REALFORCE R2 108/87 key keyboards. + Say Y for N-key rollover support on Topre REALFORCE R2 108/87 key and + Topre REALFORCE R3S 87 key keyboards. config HID_THINGM tristate "ThingM blink(1) USB RGB LED"
drivers/hid/hid-ids.h +1 -0
@@ -1285,6 +1285,7 @@#define USB_VENDOR_ID_TOPRE 0x0853#define USB_DEVICE_ID_TOPRE_REALFORCE_R2_108 0x0148#define USB_DEVICE_ID_TOPRE_REALFORCE_R2_87 0x0146 +#define USB_DEVICE_ID_TOPRE_REALFORCE_R3S_87 0x0313#define USB_VENDOR_ID_TOPSEED 0x0766#define USB_DEVICE_ID_TOPSEED_CYBERLINK 0x0204
drivers/hid/hid-topre.c +7 -0
@@ -29,6 +29,11 @@ static __u8 *topre_report_fixup(struct hid_device *hdev, __u8 *rdesc,hid_info (hdev,"fixing up Topre REALFORCE keyboard report descriptor\n" ); rdesc[72 ] =0x02 ; + }else if (*rsize >=106 && rdesc[28 ] ==0x29 && rdesc[29 ] ==0xe7 && + rdesc[30 ] ==0x81 && rdesc[31 ] ==0x00 ) { +hid_info (hdev, +"fixing up Topre REALFORCE keyboard report descriptor\n" ); + rdesc[31 ] =0x02 ; }return rdesc; }
@@ -38,6 +43,8 @@ static const struct hid_device_id topre_id_table[] = { USB_DEVICE_ID_TOPRE_REALFORCE_R2_108) }, { HID_USB_DEVICE(USB_VENDOR_ID_TOPRE, USB_DEVICE_ID_TOPRE_REALFORCE_R2_87) }, + { HID_USB_DEVICE(USB_VENDOR_ID_TOPRE, + USB_DEVICE_ID_TOPRE_REALFORCE_R3S_87) }, { } }; MODULE_DEVICE_TABLE(hid, topre_id_table);
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 6/17 HID: hid-apple: Apple Magic Keyboard a3203 USB-C support
In reply to Sasha LevinFrom: Ievgen Vovk <[email protected]>
[ Upstream commit 2813e00dcd748cef47d2bffaa04071de93fddf00 ]
Add Apple Magic Keyboard 2024 model (with USB-C port) device ID (0320) to those recognized by the hid-apple driver. Keyboard is otherwise compatible with the existing implementation for its earlier 2021 model.
--- drivers/hid/hid-apple.c | 5 +++++ drivers/hid/hid-ids.h | 1 + 2 files changed, 6 insertions(+)
drivers/hid/hid-apple.c +5 -0
@@ -459,6 +459,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015) table = magic_keyboard_2015_fn_keys; else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 || + hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024 || hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 || hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021) table = apple2021_fn_keys;
@@ -1064,6 +1065,10 @@ static const struct hid_device_id apple_devices[] = { .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY }, { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021), .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024), + .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY }, + { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024), + .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021), .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY }, { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021),
drivers/hid/hid-ids.h +1 -0
@@ -184,6 +184,7 @@#define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242#define USB_DEVICE_ID_APPLE_IRCONTROL5 0x8243#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 0x029c +#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024 0x0320#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 0x029a#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021 0x029f#define USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT 0x8102
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 7/17 HID: apple: fix up the F6 key on the Omoton KB066 keyboard
In reply to Sasha LevinFrom: Alex Henrie <[email protected]>
[ Upstream commit 819083cb6eedcc8495cbf84845877bcc741b93b3 ]
The Omoton KB066 is an Apple A1255 keyboard clone (HID product code 05ac:022c). On both keyboards, the F6 key becomes Num Lock when the Fn key is held. But unlike its Apple exemplar, when the Omoton's F6 key is pressed without Fn, it sends the usage code 0xC0301 from the reserved section of the consumer page instead of the standard F6 usage code 0x7003F from the keyboard page. The nonstandard code is translated to KEY_UNKNOWN and becomes useless on Linux. The Omoton KB066 is a pretty popular keyboard, judging from its 29,058 reviews on Amazon at time of writing, so let's account for its quirk to make it more usable.
By the way, it would be nice if we could automatically set fnmode to 0 for Omoton keyboards because they handle the Fn key internally and the kernel's Fn key handling creates undesirable side effects such as making F1 and F2 always Brightness Up and Brightness Down in fnmode=1 (the default) or always F1 and F2 in fnmode=2. Unfortunately I don't think there's a way to identify Bluetooth keyboards more specifically than the HID product code which is obviously inaccurate. Users of Omoton keyboards will just have to set fnmode to 0 manually to get full Fn key functionality.
--- drivers/hid/hid-apple.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-apple.c +3 -0
@@ -531,6 +531,9 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, } } +if (usage->hid ==0xc0301 )/* Omoton KB066 quirk */ + code =KEY_F6 ; +if (usage->code != code) {input_event_with_scancode (input, usage->type, code, usage->hid, value);
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 8/17 objtool: Ignore dangling jump table entries
In reply to Sasha LevinFrom: Josh Poimboeuf <[email protected]>
[ Upstream commit 3724062ca2b1364f02cf44dbea1a552227844ad1 ]
Clang sometimes leaves dangling unused jump table entries which point to the end of the function. Ignore them.
--- tools/objtool/check.c | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/objtool/check.c +9 -0
@@ -2028,6 +2028,14 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn, reloc_addend(reloc) == pfunc->offset)break ; +/* +* Clang sometimes leaves dangling unused jump table entries +* which point to the end of the function. Ignore them. +*/ +if (reloc->sym->sec == pfunc->sec && +reloc_addend (reloc) == pfunc->offset + pfunc->len) + goto next; + dest_insn =find_insn (file, reloc->sym->sec,reloc_addend (reloc));if (!dest_insn)break ;
@@ -2045,6 +2053,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn, alt->insn = dest_insn; alt->next = insn->alts; insn->alts = alt; +next: prev_offset =reloc_offset (reloc); }
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 9/17 sched: Clarify wake_up_q()'s write to task->wake_q.next
In reply to Sasha LevinFrom: Jann Horn <[email protected]>
[ Upstream commit bcc6244e13b4d4903511a1ea84368abf925031c0 ]
Clarify that wake_up_q() does an atomic write to task->wake_q.next, after which a concurrent __wake_q_add() can immediately overwrite task->wake_q.next again.
--- kernel/sched/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/sched/core.c +3 -2
@@ -1019,9 +1019,10 @@ void wake_up_q(struct wake_q_head *head)struct task_struct *task; task = container_of(node, struct task_struct, wake_q); -/* Task can safely be re-inserted now: */ node = node->next; - task->wake_q.next =NULL ; +/* pairs with cmpxchg_relaxed() in __wake_q_add() */ +WRITE_ONCE (task->wake_q.next,NULL ); +/* Task can safely be re-inserted now. */ /* * wake_up_process() executes a full barrier, which pairs with
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 10/17 platform/x86: thinkpad_acpi: Fix invalid fan speed on ThinkPad X120e
In reply to Sasha LevinFrom: Sybil Isabel Dorsett <[email protected]>
[ Upstream commit 1046cac109225eda0973b898e053aeb3d6c10e1d ]
On ThinkPad X120e, fan speed is reported in ticks per revolution rather than RPM.
Recalculate the fan speed value reported for ThinkPad X120e to RPM based on a 22.5 kHz clock.
Based on the information on
https://www.thinkwiki.org/wiki/How_to_control_fan_speed,
the same problem is highly likely to be relevant to at least Edge11, but Edge11 is not addressed in this patch.
--- drivers/platform/x86/thinkpad_acpi.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +14 -2
@@ -7961,6 +7961,7 @@ static struct ibm_struct volume_driver_data = {#define FAN_NS_CTRL_STATUS BIT(2)/* Bit which determines control is enabled or not */ #define FAN_NS_CTRL BIT(4)/* Bit which determines control is by host or EC */ +#define FAN_CLOCK_TPM (22500*60)/* Ticks per minute for a 22.5 kHz clock */ enum {/* Fan control constants */ fan_status_offset =0x2f ,/* EC register 0x2f */
@@ -8014,6 +8015,7 @@ static int fan_watchdog_maxinterval;static bool fan_with_ns_addr;static bool ecfw_with_fan_dec_rpm; +static bool fan_speed_in_tpr;static struct mutex fan_mutex;
@@ -8195,8 +8197,11 @@ static int fan_get_speed(unsigned int *speed) !acpi_ec_read(fan_rpm_offset + 1, &hi)))return -EIO ; -if (likely (speed)) +if (likely (speed)) { *speed = (hi <<8 ) | lo; +if (fan_speed_in_tpr && *speed !=0 ) + *speed =FAN_CLOCK_TPM / *speed; + }break ;case TPACPI_FAN_RD_TPEC_NS :if (!acpi_ec_read (fan_rpm_status_ns, &lo))
@@ -8229,8 +8234,11 @@ static int fan2_get_speed(unsigned int *speed)if (rc)return -EIO ; -if (likely (speed)) +if (likely (speed)) { *speed = (hi <<8 ) | lo; +if (fan_speed_in_tpr && *speed !=0 ) + *speed =FAN_CLOCK_TPM / *speed; + }break ;case TPACPI_FAN_RD_TPEC_NS :
@@ -8758,6 +8766,7 @@ static const struct attribute_group fan_driver_attr_group = {#define TPACPI_FAN_NOFAN 0x0008/* no fan available */ #define TPACPI_FAN_NS 0x0010/* For EC with non-Standard register addresses */ #define TPACPI_FAN_DECRPM 0x0020/* For ECFW's with RPM in register as decimal */ +#define TPACPI_FAN_TPR 0x0040/* Fan speed is in Ticks Per Revolution */ static const struct tpacpi_quirk fan_quirk_table[]__initconst = {TPACPI_QEC_IBM ('1' ,'Y' ,TPACPI_FAN_Q1 ),
@@ -8780,6 +8789,7 @@ static const struct tpacpi_quirk fan_quirk_table[] __initconst = {TPACPI_Q_LNV3 ('N' ,'2' ,'U' ,TPACPI_FAN_NS ),/* X13 Yoga Gen 2*/ TPACPI_Q_LNV3 ('N' ,'1' ,'O' ,TPACPI_FAN_NOFAN ),/* X1 Tablet (2nd gen) */ TPACPI_Q_LNV3 ('R' ,'0' ,'Q' ,TPACPI_FAN_DECRPM ),/* L480 */ + TPACPI_Q_LNV('8', 'F', TPACPI_FAN_TPR), /* ThinkPad x120e */ };static int __init fan_init (struct ibm_init_struct *iibm)
@@ -8843,6 +8853,8 @@ static int __init fan_init(struct ibm_init_struct *iibm)if (quirks &TPACPI_FAN_Q1 )fan_quirk1_setup (); +if (quirks &TPACPI_FAN_TPR ) + fan_speed_in_tpr = true;/* Try and probe the 2nd fan */ tp_features.second_fan =1 ;/* needed for get_speed to work */ res =fan2_get_speed (&speed);
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 11/17 platform/x86: thinkpad_acpi: Support for V9 DYTC platform profiles
In reply to Sasha LevinFrom: Mark Pearson <[email protected]>
[ Upstream commit 9cff907cbf8c7fb5345918dbcc7b74a01656f34f ]
Newer Thinkpad AMD platforms are using V9 DYTC and this changes the profiles used for PSC mode. Add support for this update. Tested on P14s G5 AMD
--- drivers/platform/x86/thinkpad_acpi.c | 34 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +22 -12
@@ -10282,6 +10282,10 @@ static struct ibm_struct proxsensor_driver_data = {#define DYTC_MODE_PSC_BALANCE 5/* Default mode aka balanced */ #define DYTC_MODE_PSC_PERFORM 7/* High power mode aka performance */ +#define DYTC_MODE_PSCV9_LOWPOWER 1/* Low power mode */ +#define DYTC_MODE_PSCV9_BALANCE 3/* Default mode aka balanced */ +#define DYTC_MODE_PSCV9_PERFORM 4/* High power mode aka performance */ +#define DYTC_ERR_MASK 0xF/* Bits 0-3 in cmd result are the error result */ #define DYTC_ERR_SUCCESS 1/* CMD completed successful */
@@ -10302,6 +10306,10 @@ static int dytc_capabilities;static bool dytc_mmc_get_available;static int profile_force; +static int platform_psc_profile_lowpower =DYTC_MODE_PSC_LOWPOWER ; +static int platform_psc_profile_balanced =DYTC_MODE_PSC_BALANCE ; +static int platform_psc_profile_performance =DYTC_MODE_PSC_PERFORM ; +static int convert_dytc_to_profile (int funcmode,int dytcmode,enum platform_profile_option *profile) {
@@ -10323,19 +10331,15 @@ static int convert_dytc_to_profile(int funcmode, int dytcmode, }return 0 ;case DYTC_FUNCTION_PSC : -switch (dytcmode) { -case DYTC_MODE_PSC_LOWPOWER : +if (dytcmode == platform_psc_profile_lowpower) *profile =PLATFORM_PROFILE_LOW_POWER ; -break ; -case DYTC_MODE_PSC_BALANCE : +else if (dytcmode == platform_psc_profile_balanced) *profile =PLATFORM_PROFILE_BALANCED ; -break ; -case DYTC_MODE_PSC_PERFORM : +else if (dytcmode == platform_psc_profile_performance) *profile =PLATFORM_PROFILE_PERFORMANCE ; -break ; -default :/* Unknown mode */ +else return -EINVAL ; - } +return 0 ;case DYTC_FUNCTION_AMT :/* For now return balanced. It's the closest we have to 'auto' */
@@ -10356,19 +10360,19 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *peif (dytc_capabilities &BIT (DYTC_FC_MMC )) *perfmode =DYTC_MODE_MMC_LOWPOWER ;else if (dytc_capabilities &BIT (DYTC_FC_PSC )) - *perfmode =DYTC_MODE_PSC_LOWPOWER ; + *perfmode = platform_psc_profile_lowpower;break ;case PLATFORM_PROFILE_BALANCED :if (dytc_capabilities &BIT (DYTC_FC_MMC )) *perfmode =DYTC_MODE_MMC_BALANCE ;else if (dytc_capabilities &BIT (DYTC_FC_PSC )) - *perfmode =DYTC_MODE_PSC_BALANCE ; + *perfmode = platform_psc_profile_balanced;break ;case PLATFORM_PROFILE_PERFORMANCE :if (dytc_capabilities &BIT (DYTC_FC_MMC )) *perfmode =DYTC_MODE_MMC_PERFORM ;else if (dytc_capabilities &BIT (DYTC_FC_PSC )) - *perfmode =DYTC_MODE_PSC_PERFORM ; + *perfmode = platform_psc_profile_performance;break ;default :/* Unknown profile */ return -EOPNOTSUPP ;
@@ -10557,6 +10561,7 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)if (output &BIT (DYTC_QUERY_ENABLE_BIT )) dytc_version = (output >>DYTC_QUERY_REV_BIT ) &0xF ; +dbg_printk (TPACPI_DBG_INIT ,"DYTC version %d\n" , dytc_version);/* Check DYTC is enabled and supports mode setting */ if (dytc_version <5 )return -ENODEV ;
@@ -10595,6 +10600,11 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) } }else if (dytc_capabilities &BIT (DYTC_FC_PSC )) {/* PSC MODE */ pr_debug ("PSC is supported\n" ); +if (dytc_version >=9 ) {/* update profiles for DYTC 9 and up */ + platform_psc_profile_lowpower =DYTC_MODE_PSCV9_LOWPOWER ; + platform_psc_profile_balanced =DYTC_MODE_PSCV9_BALANCE ; + platform_psc_profile_performance =DYTC_MODE_PSCV9_PERFORM ; + } }else {dbg_printk (TPACPI_DBG_INIT ,"No DYTC support available\n" );return -ENODEV ;
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 12/17 s390/cio: Fix CHPID "configure" attribute caching
In reply to Sasha LevinFrom: Peter Oberparleiter <[email protected]>
[ Upstream commit 32ae4a2992529e2c7934e422035fad1d9b0f1fb5 ]
In some environments, the SCLP firmware interface used to query a CHPID's configured state is not supported. On these environments, rapidly reading the corresponding sysfs attribute produces inconsistent results:
$ cat /sys/devices/css0/chp0.00/configure cat: /sys/devices/css0/chp0.00/configure: Operation not supported $ cat /sys/devices/css0/chp0.00/configure 3
This occurs for example when Linux is run as a KVM guest. The inconsistency is a result of CIO using cached results for generating the value of the "configure" attribute while failing to handle the situation where no data was returned by SCLP.
Fix this by not updating the cache-expiration timestamp when SCLP returns no data. With the fix applied, the system response is consistent:
$ cat /sys/devices/css0/chp0.00/configure cat: /sys/devices/css0/chp0.00/configure: Operation not supported $ cat /sys/devices/css0/chp0.00/configure cat: /sys/devices/css0/chp0.00/configure: Operation not supported
--- drivers/s390/cio/chp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/s390/cio/chp.c +2 -1
@@ -661,7 +661,8 @@ static int info_update(void)if (time_after (jiffies, chp_info_expires)) {/* Data is too old, update. */ rc =sclp_chp_read_info (&chp_info); - chp_info_expires = jiffies +CHP_INFO_UPDATE_INTERVAL ; +if (!rc) + chp_info_expires = jiffies +CHP_INFO_UPDATE_INTERVAL ; }mutex_unlock (&info_lock);
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 13/17 thermal/cpufreq_cooling: Remove structure member documentation
In reply to Sasha LevinFrom: Daniel Lezcano <[email protected]>
[ Upstream commit a6768c4f92e152265590371975d44c071a5279c7 ]
The structure member documentation refers to a member which does not exist any more. Remove it.
--- drivers/thermal/cpufreq_cooling.c | 2 -- 1 file changed, 2 deletions(-)
drivers/thermal/cpufreq_cooling.c +0 -2
@@ -57,8 +57,6 @@ struct time_in_idle {* @max_level: maximum cooling level. One less than total number of valid * cpufreq frequencies. * @em: Reference on the Energy Model of the device -* @cdev: thermal_cooling_device pointer to keep track of the -* registered cooling device. * @policy: cpufreq policy. * @cooling_ops: cpufreq callbacks to thermal cooling device ops * @idle_time: idle time stats
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 14/17 um: virt-pci: don't use kmalloc()
In reply to Sasha LevinFrom: Johannes Berg <[email protected]>
[ Upstream commit 5b166b782d327f4b66190cc43afd3be36f2b3b7a ]
This code can be called deep in the IRQ handling, for example, and then cannot normally use kmalloc(). Have its own pre-allocated memory and use from there instead so this doesn't occur. Only in the (very rare) case of memcpy_toio() we'd still need to allocate memory.
--- arch/um/drivers/virt-pci.c | 198 +++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 96 deletions(-)
arch/um/drivers/virt-pci.c +102 -96
@@ -25,8 +25,10 @@#define MAX_IRQ_MSG_SIZE (sizeof(struct virtio_pcidev_msg) + sizeof(u32))#define NUM_IRQ_MSGS 10 -#define HANDLE_NO_FREE (ptr) ((void *)((unsigned long)(ptr) | 1)) -#define HANDLE_IS_NO_FREE (ptr) ((unsigned long)(ptr) & 1) +struct um_pci_message_buffer { +struct virtio_pcidev_msg hdr; +u8 data[8 ]; +};struct um_pci_device {struct virtio_device *vdev;
@@ -36,6 +38,11 @@ struct um_pci_device {struct virtqueue *cmd_vq, *irq_vq; +#define UM_PCI_WRITE_BUFS 20 +struct um_pci_message_buffer bufs[UM_PCI_WRITE_BUFS +1 ]; +void *extra_ptrs[UM_PCI_WRITE_BUFS +1 ]; +DECLARE_BITMAP (used_bufs,UM_PCI_WRITE_BUFS ); +#define UM_PCI_STAT_WAITING 0unsigned long status;
@@ -61,12 +68,40 @@ static unsigned long um_pci_msi_used[BITS_TO_LONGS(MAX_MSI_VECTORS)];static unsigned int um_pci_max_delay_us =40000 ;module_param_named (max_delay_us, um_pci_max_delay_us, uint,0644 ); -struct um_pci_message_buffer { -struct virtio_pcidev_msg hdr; -u8 data[8 ]; -}; +static int um_pci_get_buf (struct um_pci_device *dev,bool *posted) +{ +int i; + +for (i =0 ; i <UM_PCI_WRITE_BUFS ; i++) { +if (!test_and_set_bit (i, dev->used_bufs)) +return i; + } -static struct um_pci_message_buffer __percpu *um_pci_msg_bufs; + *posted = false; +return UM_PCI_WRITE_BUFS ; +} + +static void um_pci_free_buf (struct um_pci_device *dev,void *buf) +{ +int i; + +if (buf == &dev->bufs[UM_PCI_WRITE_BUFS ]) { +kfree (dev->extra_ptrs[UM_PCI_WRITE_BUFS ]); + dev->extra_ptrs[UM_PCI_WRITE_BUFS ] =NULL ; +return ; + } + +for (i =0 ; i <UM_PCI_WRITE_BUFS ; i++) { +if (buf == &dev->bufs[i]) { +kfree (dev->extra_ptrs[i]); + dev->extra_ptrs[i] =NULL ; +WARN_ON (!test_and_clear_bit (i, dev->used_bufs)); +return ; + } + } + +WARN_ON (1 ); +} static int um_pci_send_cmd(struct um_pci_device *dev, struct virtio_pcidev_msg *cmd,
@@ -82,7 +117,9 @@ static int um_pci_send_cmd(struct um_pci_device *dev, };struct um_pci_message_buffer *buf;int delay_count =0 ; +bool bounce_out;int ret, len; +int buf_idx;bool posted;if (WARN_ON (cmd_size <sizeof (*cmd) || cmd_size >sizeof (*buf)))
@@ -101,26 +138,28 @@ static int um_pci_send_cmd(struct um_pci_device *dev,break ; } - buf =get_cpu_var (um_pci_msg_bufs); -if (buf) -memcpy (buf, cmd, cmd_size); + bounce_out = !posted && cmd_size <=sizeof (*cmd) && + out && out_size <=sizeof (buf->data); -if (posted) { -u8 *ncmd =kmalloc (cmd_size + extra_size,GFP_ATOMIC ); - -if (ncmd) { -memcpy (ncmd, cmd, cmd_size); -if (extra) -memcpy (ncmd + cmd_size, extra, extra_size); - cmd = (void *)ncmd; - cmd_size += extra_size; - extra =NULL ; - extra_size =0 ; - }else { -/* try without allocating memory */ - posted = false; - cmd = (void *)buf; + buf_idx =um_pci_get_buf (dev, &posted); + buf = &dev->bufs[buf_idx]; +memcpy (buf, cmd, cmd_size); + +if (posted && extra && extra_size >sizeof (buf) - cmd_size) { + dev->extra_ptrs[buf_idx] =kmemdup (extra, extra_size, +GFP_ATOMIC ); + +if (!dev->extra_ptrs[buf_idx]) { +um_pci_free_buf (dev, buf); +return -ENOMEM ; } + extra = dev->extra_ptrs[buf_idx]; + }else if (extra && extra_size <=sizeof (buf) - cmd_size) { +memcpy ((u8 *)buf + cmd_size, extra, extra_size); + cmd_size += extra_size; + extra_size =0 ; + extra =NULL ; + cmd = (void *)buf; }else { cmd = (void *)buf; }
@@ -128,39 +167,40 @@ static int um_pci_send_cmd(struct um_pci_device *dev,sg_init_one (&out_sg, cmd, cmd_size);if (extra)sg_init_one (&extra_sg, extra, extra_size); -if (out) +/* allow stack for small buffers */ +if (bounce_out) +sg_init_one (&in_sg, buf->data, out_size); +else if (out)sg_init_one (&in_sg, out, out_size);/* add to internal virtio queue */ ret =virtqueue_add_sgs (dev->cmd_vq, sgs_list, extra ?2 :1 , out ?1 :0 , - posted ? cmd :HANDLE_NO_FREE (cmd), -GFP_ATOMIC ); + cmd,GFP_ATOMIC );if (ret) { -if (posted) -kfree (cmd); - goto out; +um_pci_free_buf (dev, buf); +return ret; }if (posted) {virtqueue_kick (dev->cmd_vq); - ret =0 ; - goto out; +return 0 ; }/* kick and poll for getting a response on the queue */ set_bit (UM_PCI_STAT_WAITING , &dev->status);virtqueue_kick (dev->cmd_vq); + ret =0 ;while (1 ) {void *completed =virtqueue_get_buf (dev->cmd_vq, &len); -if (completed ==HANDLE_NO_FREE (cmd)) +if (completed == buf)break ; -if (completed && !HANDLE_IS_NO_FREE (completed)) -kfree (completed); +if (completed) +um_pci_free_buf (dev, completed); if (WARN_ONCE(virtqueue_is_broken(dev->cmd_vq) || ++delay_count > um_pci_max_delay_us,
@@ -172,8 +212,11 @@ static int um_pci_send_cmd(struct um_pci_device *dev, }clear_bit (UM_PCI_STAT_WAITING , &dev->status); -out: -put_cpu_var (um_pci_msg_bufs); +if (bounce_out) +memcpy (out, buf->data, out_size); + +um_pci_free_buf (dev, buf); +return ret; }
@@ -187,20 +230,13 @@ static unsigned long um_pci_cfgspace_read(void *priv, unsigned int offset, .size = size, .addr = offset, }; -/* buf->data is maximum size - we may only use parts of it */ -struct um_pci_message_buffer *buf; -u8 *data; -unsigned long ret =ULONG_MAX ; -size_t bytes =sizeof (buf->data); +/* max 8, we might not use it all */ +u8 data[8 ];if (!dev)return ULONG_MAX ; - buf =get_cpu_var (um_pci_msg_bufs); - data = buf->data; - -if (buf) -memset (data,0xff , bytes); +memset (data,0xff ,sizeof (data));switch (size) {case 1 :
@@ -212,34 +248,26 @@ static unsigned long um_pci_cfgspace_read(void *priv, unsigned int offset,break ;default :WARN (1 ,"invalid config space read size %d\n" , size); - goto out; +return ULONG_MAX ; } -if (um_pci_send_cmd (dev, &hdr,sizeof (hdr),NULL ,0 , data, bytes)) - goto out; +if (um_pci_send_cmd (dev, &hdr,sizeof (hdr),NULL ,0 , data, size)) +return ULONG_MAX ;switch (size) {case 1 : - ret = data[0 ]; -break ; +return data[0 ];case 2 : - ret =le16_to_cpup ((void *)data); -break ; +return le16_to_cpup ((void *)data);case 4 : - ret =le32_to_cpup ((void *)data); -break ; +return le32_to_cpup ((void *)data);#ifdef CONFIG_64BIT case 8 : - ret =le64_to_cpup ((void *)data); -break ; +return le64_to_cpup ((void *)data);#endif default : -break ; +return ULONG_MAX ; } - -out: -put_cpu_var (um_pci_msg_bufs); -return ret; } static void um_pci_cfgspace_write(void *priv, unsigned int offset, int size,
@@ -312,13 +340,8 @@ static void um_pci_bar_copy_from(void *priv, void *buffer,static unsigned long um_pci_bar_read (void *priv,unsigned int offset,int size) { -/* buf->data is maximum size - we may only use parts of it */ -struct um_pci_message_buffer *buf; -u8 *data; -unsigned long ret =ULONG_MAX ; - - buf =get_cpu_var (um_pci_msg_bufs); - data = buf->data; +/* 8 is maximum size - we may only use parts of it */ +u8 data[8 ];switch (size) {case 1 :
@@ -330,33 +353,25 @@ static unsigned long um_pci_bar_read(void *priv, unsigned int offset,break ;default :WARN (1 ,"invalid config space read size %d\n" , size); - goto out; +return ULONG_MAX ; }um_pci_bar_copy_from (priv, data, offset, size);switch (size) {case 1 : - ret = data[0 ]; -break ; +return data[0 ];case 2 : - ret =le16_to_cpup ((void *)data); -break ; +return le16_to_cpup ((void *)data);case 4 : - ret =le32_to_cpup ((void *)data); -break ; +return le32_to_cpup ((void *)data);#ifdef CONFIG_64BIT case 8 : - ret =le64_to_cpup ((void *)data); -break ; +return le64_to_cpup ((void *)data);#endif default : -break ; +return ULONG_MAX ; } - -out: -put_cpu_var (um_pci_msg_bufs); -return ret; } static void um_pci_bar_copy_to(void *priv, unsigned int offset,
@@ -523,11 +538,8 @@ static void um_pci_cmd_vq_cb(struct virtqueue *vq)if (test_bit (UM_PCI_STAT_WAITING , &dev->status))return ; -while ((cmd =virtqueue_get_buf (vq, &len))) { -if (WARN_ON (HANDLE_IS_NO_FREE (cmd))) -continue ; -kfree (cmd); - } +while ((cmd =virtqueue_get_buf (vq, &len))) +um_pci_free_buf (dev, cmd); }static void um_pci_irq_vq_cb (struct virtqueue *vq)
@@ -1000,10 +1012,6 @@ static int __init um_pci_init(void) "No virtio device ID configured for PCI - no PCI support\n"))return 0 ; - um_pci_msg_bufs = alloc_percpu(struct um_pci_message_buffer); -if (!um_pci_msg_bufs) -return -ENOMEM ; - bridge =pci_alloc_host_bridge (0 );if (!bridge) { err = -ENOMEM ;
@@ -1065,7 +1073,6 @@ static int __init um_pci_init(void)pci_free_resource_list (&bridge->windows);pci_free_host_bridge (bridge); } -free_percpu (um_pci_msg_bufs);return err; }module_init (um_pci_init);
@@ -1077,6 +1084,5 @@ static void __exit um_pci_exit(void)irq_domain_remove (um_pci_inner_domain);pci_free_resource_list (&bridge->windows);pci_free_host_bridge (bridge); -free_percpu (um_pci_msg_bufs); }module_exit (um_pci_exit);
Signature · 1 line
2.39.5
Johannes Berg
maintainerRe: [PATCH AUTOSEL 6.6 14/17] um: virt-pci: don't use kmalloc()
Quoted 9 lines · Sasha Levin
From: Johannes Berg <[email protected]>
[ Upstream commit
5b166b782d327f4b66190cc43afd3be36f2b3b7a]This code can be called deep in the IRQ handling, for example, and then cannot normally use
kmalloc(). Have its own pre-allocated memory and use from there instead so this doesn't occur. Only in the (very rare) case ofmemcpy_toio()we'd still need to allocate memory.
I don't believe this patch, "um: convert irq_lock to raw spinlock" and "um: virtio_uml: use raw spinlock", are relevant to anything older than 6.12. I don't see how applying them would _hurt_, but I didn't have them before 6.12 and had no lockdep complaints about it; I believe some other internal IRQ rework caused the issues to pop up.
Never mind that we (Intel WiFi stuff) are probably the only ones ever running this virtio_uml/virt-pci with lockdep :)
johannes
Sasha Levin
maintainerRe: [PATCH AUTOSEL 6.6 14/17] um: virt-pci: don't use kmalloc()
Quoted 11 lines · Johannes Berg
Quoted 9 lines · Sasha Levin
From: Johannes Berg <[email protected]>
[ Upstream commit
5b166b782d327f4b66190cc43afd3be36f2b3b7a]This code can be called deep in the IRQ handling, for example, and then cannot normally use
kmalloc(). Have its own pre-allocated memory and use from there instead so this doesn't occur. Only in the (very rare) case ofmemcpy_toio()we'd still need to allocate memory.
Quoted 8 lines
I don't believe this patch, "um: convert
irq_lockto raw spinlock" and "um:virtio_uml: use raw spinlock", are relevant to anything older than 6.12. I don't see how applying them would _hurt_, but I didn't have them before 6.12 and had no lockdep complaints about it; I believe some other internal IRQ rework caused the issues to pop up.Never mind that we (Intel WiFi stuff) are probably the only ones ever running this virtio_uml/virt-pci with lockdep :)
I'll drop it, thanks!
Signature · 2 lines
Thanks, Sasha
Sasha Levin
maintainerPATCH 15/17 um: virtio_uml: use raw spinlock
In reply to Sasha LevinFrom: Johannes Berg <[email protected]>
[ Upstream commit daa1a05ba431540097ec925d4e01d53ef29a98f1 ]
This is needed because at least in time-travel the code can be called directly from the deep architecture and IRQ handling code.
--- arch/um/drivers/virtio_uml.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/um/drivers/virtio_uml.c +4 -4
@@ -52,7 +52,7 @@ struct virtio_uml_device {struct platform_device *pdev;struct virtio_uml_platform_data *pdata; -spinlock_t sock_lock; +raw_spinlock_t sock_lock;int sock, req_fd, irq;u64 features;u64 protocol_features;
@@ -247,7 +247,7 @@ static int vhost_user_send(struct virtio_uml_device *vu_dev,if (request_ack) msg->header.flags |=VHOST_USER_FLAG_NEED_REPLY ; -spin_lock_irqsave (&vu_dev->sock_lock, flags); +raw_spin_lock_irqsave (&vu_dev->sock_lock, flags); rc =full_sendmsg_fds (vu_dev->sock, msg, size, fds, num_fds);if (rc <0 ) goto out;
@@ -267,7 +267,7 @@ static int vhost_user_send(struct virtio_uml_device *vu_dev, } out: -spin_unlock_irqrestore (&vu_dev->sock_lock, flags); +raw_spin_unlock_irqrestore (&vu_dev->sock_lock, flags);return rc; }
@@ -1218,7 +1218,7 @@ static int virtio_uml_probe(struct platform_device *pdev) goto error_free; vu_dev->sock = rc; -spin_lock_init (&vu_dev->sock_lock); +raw_spin_lock_init (&vu_dev->sock_lock); rc =vhost_user_init (vu_dev);if (rc)
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 16/17 Xen/swiotlb: mark xen_swiotlb_fixup() __init
In reply to Sasha LevinFrom: Jan Beulich <[email protected]>
[ Upstream commit 75ad02318af2e4ae669e26a79f001bd5e1f97472 ]
It's sole user (pci_xen_swiotlb_init()) is __init, too.
Message-ID: <[email protected]>
--- drivers/xen/swiotlb-xen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/swiotlb-xen.c +1 -1
@@ -110,7 +110,7 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr) }#ifdef CONFIG_X86 -int xen_swiotlb_fixup (void *buf,unsigned long nslabs) +int __init xen_swiotlb_fixup (void *buf,unsigned long nslabs) {int rc;unsigned int order =get_order (IO_TLB_SEGSIZE <<IO_TLB_SHIFT );
Signature · 1 line
2.39.5
Sasha Levin
maintainerPATCH 17/17 Bluetooth: L2CAP: Fix slab-use-after-free Read in l2cap_send_cmd
In reply to Sasha LevinFrom: Luiz Augusto von Dentz <[email protected]>
[ Upstream commit b4f82f9ed43aefa79bec2504ae8c29be0c0f5d1d ]
After the hci sync command releases l2cap_conn, the hci receive data work queue references the released l2cap_conn when sending to the upper layer. Add hci dev lock to the hci receive data work queue to synchronize the two.
[1]
BUG: KASAN: slab-use-after-free in l2cap_send_cmd+0x187/0x8d0 net/bluetooth/l2cap_core.c:954 Read of size 8 at addr ffff8880271a4000 by task kworker/u9:2/5837 CPU: 0 UID: 0 PID: 5837 Comm: kworker/u9:2 Not tainted 6.13.0-rc5-syzkaller-00163-gab75170520d4 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 Workqueue: hci1 hci_rx_work Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0x169/0x550 mm/kasan/report.c:489 kasan_report+0x143/0x180 mm/kasan/report.c:602 l2cap_build_cmd net/bluetooth/l2cap_core.c:2964 [inline] l2cap_send_cmd+0x187/0x8d0 net/bluetooth/l2cap_core.c:954 l2cap_sig_send_rej net/bluetooth/l2cap_core.c:5502 [inline] l2cap_sig_channel net/bluetooth/l2cap_core.c:5538 [inline] l2cap_recv_frame+0x221f/0x10db0 net/bluetooth/l2cap_core.c:6817 hci_acldata_packet net/bluetooth/hci_core.c:3797 [inline] hci_rx_work+0x508/0xdb0 net/bluetooth/hci_core.c:4040 process_one_work kernel/workqueue.c:3229 [inline] process_scheduled_works+0xa66/0x1840 kernel/workqueue.c:3310 worker_thread+0x870/0xd30 kernel/workqueue.c:3391 kthread+0x2f0/0x390 kernel/kthread.c:389 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 </TASK> Allocated by task 5837: kasan_save_stack mm/kasan/common.c:47 [inline] kasan_save_track+0x3f/0x80 mm/kasan/common.c:68 poison_kmalloc_redzone mm/kasan/common.c:377 [inline] __kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:394 kasan_kmalloc include/linux/kasan.h:260 [inline] __kmalloc_cache_noprof+0x243/0x390 mm/slub.c:4329 kmalloc_noprof include/linux/slab.h:901 [inline] kzalloc_noprof include/linux/slab.h:1037 [inline] l2cap_conn_add+0xa9/0x8e0 net/bluetooth/l2cap_core.c:6860 l2cap_connect_cfm+0x115/0x1090 net/bluetooth/l2cap_core.c:7239 hci_connect_cfm include/net/bluetooth/hci_core.h:2057 [inline] hci_remote_features_evt+0x68e/0xac0 net/bluetooth/hci_event.c:3726 hci_event_func net/bluetooth/hci_event.c:7473 [inline] hci_event_packet+0xac2/0x1540 net/bluetooth/hci_event.c:7525 hci_rx_work+0x3f3/0xdb0 net/bluetooth/hci_core.c:4035 process_one_work kernel/workqueue.c:3229 [inline] process_scheduled_works+0xa66/0x1840 kernel/workqueue.c:3310 worker_thread+0x870/0xd30 kernel/workqueue.c:3391 kthread+0x2f0/0x390 kernel/kthread.c:389 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 Freed by task 54: kasan_save_stack mm/kasan/common.c:47 [inline] kasan_save_track+0x3f/0x80 mm/kasan/common.c:68 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:582 poison_slab_object mm/kasan/common.c:247 [inline] __kasan_slab_free+0x59/0x70 mm/kasan/common.c:264 kasan_slab_free include/linux/kasan.h:233 [inline] slab_free_hook mm/slub.c:2353 [inline] slab_free mm/slub.c:4613 [inline] kfree+0x196/0x430 mm/slub.c:4761 l2cap_connect_cfm+0xcc/0x1090 net/bluetooth/l2cap_core.c:7235 hci_connect_cfm include/net/bluetooth/hci_core.h:2057 [inline] hci_conn_failed+0x287/0x400 net/bluetooth/hci_conn.c:1266 hci_abort_conn_sync+0x56c/0x11f0 net/bluetooth/hci_sync.c:5603 hci_cmd_sync_work+0x22b/0x400 net/bluetooth/hci_sync.c:332 process_one_work kernel/workqueue.c:3229 [inline] process_scheduled_works+0xa66/0x1840 kernel/workqueue.c:3310 worker_thread+0x870/0xd30 kernel/workqueue.c:3391 kthread+0x2f0/0x390 kernel/kthread.c:389 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
--- net/bluetooth/l2cap_core.c | 39 +++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-)
net/bluetooth/l2cap_core.c +34 -5
@@ -948,6 +948,16 @@ static u8 l2cap_get_ident(struct l2cap_conn *conn)return id; } +static void l2cap_send_acl (struct l2cap_conn *conn,struct sk_buff *skb, +u8 flags) +{ +/* Check if the hcon still valid before attempting to send */ +if (hci_conn_valid (conn->hcon->hdev, conn->hcon)) +hci_send_acl (conn->hchan, skb, flags); +else +kfree_skb (skb); +} +static void l2cap_send_cmd (struct l2cap_conn *conn,u8 ident,u8 code,u16 len,void *data) {
@@ -970,7 +980,7 @@ static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len,bt_cb (skb)->force_active =BT_POWER_FORCE_ACTIVE_ON ; skb->priority =HCI_PRIO_MAX ; -hci_send_acl (conn->hchan, skb, flags); +l2cap_send_acl (conn, skb, flags); }static void l2cap_do_send (struct l2cap_chan *chan,struct sk_buff *skb)
@@ -1792,13 +1802,10 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)mutex_unlock (&conn->chan_lock); -hci_chan_del (conn->hchan); -if (conn->info_state &L2CAP_INFO_FEAT_MASK_REQ_SENT )cancel_delayed_work_sync (&conn->info_timer); hcon->l2cap_data =NULL ; - conn->hchan =NULL ;l2cap_conn_put (conn); }
@@ -1806,6 +1813,7 @@ static void l2cap_conn_free(struct kref *ref) { struct l2cap_conn *conn = container_of(ref, struct l2cap_conn, ref); +hci_chan_del (conn->hchan);hci_conn_put (conn->hcon);kfree (conn); }
@@ -7472,14 +7480,33 @@ static void l2cap_recv_reset(struct l2cap_conn *conn) conn->rx_len =0 ; } +static struct l2cap_conn *l2cap_conn_hold_unless_zero (struct l2cap_conn *c) +{ +BT_DBG ("conn %p orig refcnt %u" , c,kref_read (&c->ref)); + +if (!kref_get_unless_zero (&c->ref)) +return NULL ; + +return c; +} +void l2cap_recv_acldata (struct hci_conn *hcon,struct sk_buff *skb,u16 flags) { -struct l2cap_conn *conn = hcon->l2cap_data; +struct l2cap_conn *conn;int len; +/* Lock hdev to access l2cap_data to avoid race with l2cap_conn_del */ +hci_dev_lock (hcon->hdev); + + conn = hcon->l2cap_data; +if (!conn) conn =l2cap_conn_add (hcon); + conn =l2cap_conn_hold_unless_zero (conn); + +hci_dev_unlock (hcon->hdev); +if (!conn) goto drop;
@@ -7571,6 +7598,8 @@ void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)break ; } +l2cap_conn_put (conn); + drop:kfree_skb (skb); }
Signature · 1 line
2.39.5