io_uring/cancel: re-grab ctx mutex after finishing wait
Subsystems (5)
Sasha Levin
maintainerPATCH 1/10 io_uring/cancel: re-grab ctx mutex after finishing wait
From: Jens Axboe <[email protected]>
[ Upstream commit 23fffb2f09ce1145cbd751801d45ba74acaa6542 ]
If we have a signal pending during cancelations, it'll cause the task_work run to return an error. Since we didn't run task_work, the current task is left in TASK_INTERRUPTIBLE state when we need to re-grab the ctx mutex, and the kernel will rightfully complain about that.
Move the lock grabbing for the error cases outside the loop to avoid that issue.
--- io_uring/cancel.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
io_uring/cancel.c +4 -5
@@ -288,24 +288,23 @@ int io_sync_cancel(struct io_ring_ctx *ctx, void __user *arg) ret =__io_sync_cancel (current->io_uring, &cd, sc.fd); +mutex_unlock (&ctx->uring_lock);if (ret != -EALREADY )break ; -mutex_unlock (&ctx->uring_lock); ret =io_run_task_work_sig (ctx); -if (ret <0 ) { -mutex_lock (&ctx->uring_lock); +if (ret <0 )break ; - } ret =schedule_hrtimeout (&timeout,HRTIMER_MODE_ABS ); -mutex_lock (&ctx->uring_lock);if (!ret) { ret = -ETIME ;break ; } +mutex_lock (&ctx->uring_lock); }while (1 );finish_wait (&ctx->cq_wait, &wait); +mutex_lock (&ctx->uring_lock);if (ret == -ENOENT || ret >0 ) ret =0 ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 2/10 nvme: fix multipath crash caused by flush request when blktrace is enabled
From: Yanjun Zhang <[email protected]>
[ Upstream commit 3659fb5ac29a5e6102bebe494ac789fd47fb78f4 ]
The flush request initialized by blk_kick_flush has NULL bio, and it may be dealt with nvme_end_req during io completion. When blktrace is enabled, nvme_trace_bio_complete with multipath activated trying to access NULL pointer bio from flush request results in the following crash:
[ 2517.831677] BUG: kernel NULL pointer dereference, address: 000000000000001a [ 2517.835213] #PF: supervisor read access in kernel mode [ 2517.838724] #PF: error_code(0x0000) - not-present page [ 2517.842222] PGD 7b2d51067 P4D 0 [ 2517.845684] Oops: 0000 [#1] SMP NOPTI [ 2517.849125] CPU: 2 PID: 732 Comm: kworker/2:1H Kdump: loaded Tainted: G S 5.15.67-0.cl9.x86_64 #1 [ 2517.852723] Hardware name: XFUSION 2288H V6/BC13MBSBC, BIOS 1.13 07/27/2022 [ 2517.856358] Workqueue: nvme_tcp_wq nvme_tcp_io_work [nvme_tcp] [ 2517.859993] RIP: 0010:blk_add_trace_bio_complete+0x6/0x30 [ 2517.863628] Code: 1f 44 00 00 48 8b 46 08 31 c9 ba 04 00 10 00 48 8b 80 50 03 00 00 48 8b 78 50 e9 e5 fe ff ff 0f 1f 44 00 00 41 54 49 89 f4 55 <0f> b6 7a 1a 48 89 d5 e8 3e 1c 2b 00 48 89 ee 4c 89 e7 5d 89 c1 ba [ 2517.871269] RSP: 0018:ff7f6a008d9dbcd0 EFLAGS: 00010286 [ 2517.875081] RAX: ff3d5b4be00b1d50 RBX: 0000000002040002 RCX: ff3d5b0a270f2000 [ 2517.878966] RDX: 0000000000000000 RSI: ff3d5b0b021fb9f8 RDI: 0000000000000000 [ 2517.882849] RBP: ff3d5b0b96a6fa00 R08: 0000000000000001 R09: 0000000000000000 [ 2517.886718] R10: 000000000000000c R11: 000000000000000c R12: ff3d5b0b021fb9f8 [ 2517.890575] R13: 0000000002000000 R14: ff3d5b0b021fb1b0 R15: 0000000000000018 [ 2517.894434] FS: 0000000000000000(0000) GS:ff3d5b42bfc80000(0000) knlGS:0000000000000000 [ 2517.898299] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 2517.902157] CR2: 000000000000001a CR3: 00000004f023e005 CR4: 0000000000771ee0 [ 2517.906053] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 2517.909930] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 2517.913761] PKRU: 55555554 [ 2517.917558] Call Trace: [ 2517.921294] <TASK> [ 2517.924982] nvme_complete_rq+0x1c3/0x1e0 [nvme_core] [ 2517.928715] nvme_tcp_recv_pdu+0x4d7/0x540 [nvme_tcp] [ 2517.932442] nvme_tcp_recv_skb+0x4f/0x240 [nvme_tcp] [ 2517.936137] ? nvme_tcp_recv_pdu+0x540/0x540 [nvme_tcp] [ 2517.939830] tcp_read_sock+0x9c/0x260 [ 2517.943486] nvme_tcp_try_recv+0x65/0xa0 [nvme_tcp] [ 2517.947173] nvme_tcp_io_work+0x64/0x90 [nvme_tcp] [ 2517.950834] process_one_work+0x1e8/0x390 [ 2517.954473] worker_thread+0x53/0x3c0 [ 2517.958069] ? process_one_work+0x390/0x390 [ 2517.961655] kthread+0x10c/0x130 [ 2517.965211] ? set_kthread_struct+0x40/0x40 [ 2517.968760] ret_from_fork+0x1f/0x30 [ 2517.972285] </TASK>
To avoid this situation, add a NULL check for req->bio before calling trace_block_bio_complete.
--- drivers/nvme/host/nvme.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/nvme.h +1 -1
@@ -888,7 +888,7 @@ static inline void nvme_trace_bio_complete(struct request *req) {struct nvme_ns *ns = req->q->queuedata; -if (req->cmd_flags &REQ_NVME_MPATH ) +if ((req->cmd_flags &REQ_NVME_MPATH ) && req->bio)trace_block_bio_complete (ns->head->disk->queue, req->bio); }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 3/10 ACPI: video: Allow GPU drivers to report no panels
In reply to Sasha LevinFrom: Mario Limonciello <[email protected]>
[ Upstream commit 00a734104af7d878f1252d49eff9298785c6cbdc ]
The current logic for the ACPI backlight detection will create a backlight device if no native or vendor drivers have created 8 seconds after the system has booted if the ACPI tables included backlight control methods.
If the GPU drivers have loaded, they may be able to report whether any LCD panels were found. Allow using this information to factor in whether to enable the fallback logic for making an acpi_video0 backlight device.
--- drivers/acpi/acpi_video.c | 11 +++++++++++ include/acpi/video.h | 2 ++ 2 files changed, 13 insertions(+)
drivers/acpi/acpi_video.c +11 -0
@@ -2178,6 +2178,17 @@ static bool should_check_lcd_flag(void)return false; } +/* +* At least one graphics driver has reported that no LCD is connected +* via the native interface. cancel the registration for fallback acpi_video0. +* If another driver still deems this necessary, it can explicitly register it. +*/ +void acpi_video_report_nolcd (void ) +{ +cancel_delayed_work (&video_bus_register_backlight_work); +} +EXPORT_SYMBOL (acpi_video_report_nolcd); +int acpi_video_register (void ) {int ret =0 ;
include/acpi/video.h +2 -0
@@ -53,6 +53,7 @@ enum acpi_backlight_type { };#if IS_ENABLED (CONFIG_ACPI_VIDEO ) +extern void acpi_video_report_nolcd (void );extern int acpi_video_register (void );extern void acpi_video_unregister (void );extern void acpi_video_register_backlight (void );
@@ -69,6 +70,7 @@ extern int acpi_video_get_levels(struct acpi_device *device,struct acpi_video_device_brightness **dev_br, int *pmax_level);#else +static inline void acpi_video_report_nolcd (void ) {return ; };static inline int acpi_video_register (void ) {return -ENODEV ; }static inline void acpi_video_unregister (void ) {return ; }static inline void acpi_video_register_backlight (void ) {return ; }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 4/10 drm/amd/display: Report to ACPI video if no panels were found
In reply to Sasha LevinFrom: Mario Limonciello <[email protected]>
[ Upstream commit c573e240609ff781a0246c0c8c8351abd0475287 ]
On desktop APUs amdgpu doesn't create a native backlight device as no eDP panels are found. However if the BIOS has reported backlight control methods in the ACPI tables then an acpi_video0 backlight device will be made 8 seconds after boot.
This has manifested in a power slider on a number of desktop APUs ranging from Ryzen 5000 through Ryzen 7000 on various motherboard manufacturers. To avoid this, report to the acpi video detection that the system does not have any panel connected in the native driver.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -0
@@ -4371,6 +4371,10 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)amdgpu_set_panel_orientation (&aconnector->base); } +/* If we didn't find a panel, notify the acpi video detection */ +if (dm->adev->flags &AMD_IS_APU && dm->num_of_edps ==0 ) +acpi_video_report_nolcd (); +/* Software is initialized. Now we can register interrupt handlers. */ switch (adev->asic_type) {#if defined(CONFIG_DRM_AMD_DC_SI )
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 5/10 ACPI: video: Don't enable fallback path for creating ACPI backlight by default
In reply to Sasha LevinFrom: Mario Limonciello <[email protected]>
[ Upstream commit 5aa9d943e9b6bf6e6023645cbe7ce7d5ed84baf4 ]
The ACPI video detection code has a module parameter register_backlight_delay which is currently configured to 8 seconds. This means that if after 8 seconds of booting no native driver has created a backlight device then the code will attempt to make an ACPI video backlight device.
This was intended as a safety mechanism with the backlight overhaul that occurred in kernel 6.1, but as it doesn't appear necesssary set it to be disabled by default.
--- drivers/acpi/acpi_video.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/acpi/acpi_video.c +1 -5
@@ -70,11 +70,7 @@ module_param(device_id_scheme, bool, 0444);static int only_lcd =-1 ;module_param (only_lcd, int,0444 ); -/* -* Display probing is known to take up to 5 seconds, so delay the fallback -* backlight registration by 5 seconds + 3 seconds for some extra margin. -*/ -static int register_backlight_delay =8 ; +static int register_backlight_delay;module_param (register_backlight_delay, int,0444 );MODULE_PARM_DESC (register_backlight_delay, "Delay in seconds before doing fallback (non GPU driver triggered) "
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 6/10 ACPI: resource: do IRQ override on XMG Core 15
In reply to Sasha LevinFrom: Erik Schumacher <[email protected]>
[ Upstream commit 7592b79ba4a91350b38469e05238308bcfe1019b ]
The Schenker XMG CORE 15 (M22) is Ryzen-6 based and needs IRQ overriding for the keyboard to work. Adding an entry for this laptop to the override_table makes the internal keyboard functional again.
--- drivers/acpi/resource.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/acpi/resource.c +12 -0
@@ -446,6 +446,17 @@ static const struct dmi_system_id lenovo_82ra[] = { { } }; +static const struct dmi_system_id schenker_gm_rg[] = { + { + .ident ="XMG CORE 15 (M22)" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"SchenkerTechnologiesGmbH" ), +DMI_MATCH (DMI_BOARD_NAME ,"GMxRGxx" ), + }, + }, + { } +}; +struct irq_override_cmp {const struct dmi_system_id *system;unsigned char irq;
@@ -460,6 +471,7 @@ static const struct irq_override_cmp override_table[] = { { asus_laptop, 1, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW, 0, false }, { lenovo_82ra, 6, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW, 0, true }, { lenovo_82ra, 10, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW, 0, true }, + { schenker_gm_rg, 1, ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_LOW, 1, true }, }; static bool acpi_dev_irq_override(u32 gsi, u8 triggering, u8 polarity,
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 7/10 io_uring: check for valid register opcode earlier
In reply to Sasha LevinFrom: Jens Axboe <[email protected]>
[ Upstream commit 343190841a1f22b96996d9f8cfab902a4d1bfd0e ]
We only check the register opcode value inside the restricted ring section, move it into the main io_uring_register() function instead and check it up front.
--- io_uring/io_uring.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
io_uring/io_uring.c +3 -2
@@ -3897,8 +3897,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,return -EEXIST ;if (ctx->restricted) { -if (opcode >=IORING_REGISTER_LAST ) -return -EINVAL ; opcode =array_index_nospec (opcode,IORING_REGISTER_LAST );if (!test_bit (opcode, ctx->restrictions.register_op))return -EACCES ;
@@ -4054,6 +4052,9 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,long ret = -EBADF ;struct fd f; +if (opcode >=IORING_REGISTER_LAST ) +return -EINVAL ; + f =fdget (fd);if (!f.file)return -EBADF ;
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 8/10 kunit: alloc_string_stream_fragment error handling bug fix
In reply to Sasha LevinFrom: "YoungJun.park" <[email protected]>
[ Upstream commit 93ef83050e597634d2c7dc838a28caf5137b9404 ]
When it fails to allocate fragment, it does not free and return error. And check the pointer inappropriately.
Fixed merge conflicts with
commit 618887768bb7 ("kunit: update NULL vs IS_ERR() tests") Shuah Khan <[email protected]>
--- lib/kunit/string-stream.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/kunit/string-stream.c +3 -1
@@ -23,8 +23,10 @@ static struct string_stream_fragment *alloc_string_stream_fragment(return ERR_PTR (-ENOMEM ); frag->fragment =kunit_kmalloc (test, len, gfp); -if (!frag->fragment) +if (!frag->fragment) { +kunit_kfree (test, frag);return ERR_PTR (-ENOMEM ); + }return frag; }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 9/10 nvmet: use NVME_CMD_EFFECTS_CSUPP instead of open coding it
In reply to Sasha LevinFrom: Christoph Hellwig <[email protected]>
[ Upstream commit 61f37154c599cf9f2f84dcbd9be842f8645a7099 ]
Use NVME_CMD_EFFECTS_CSUPP instead of open coding it and assign a single value to multiple array entries instead of repeated assignments.
--- drivers/nvme/target/admin-cmd.c | 35 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-)
drivers/nvme/target/admin-cmd.c +19 -16
@@ -164,26 +164,29 @@ static void nvmet_execute_get_log_page_smart(struct nvmet_req *req)static void nvmet_get_cmd_effects_nvm (struct nvme_effects_log *log) { - log->acs[nvme_admin_get_log_page] =cpu_to_le32 (1 <<0 ); - log->acs[nvme_admin_identify] =cpu_to_le32 (1 <<0 ); - log->acs[nvme_admin_abort_cmd] =cpu_to_le32 (1 <<0 ); - log->acs[nvme_admin_set_features] =cpu_to_le32 (1 <<0 ); - log->acs[nvme_admin_get_features] =cpu_to_le32 (1 <<0 ); - log->acs[nvme_admin_async_event] =cpu_to_le32 (1 <<0 ); - log->acs[nvme_admin_keep_alive] =cpu_to_le32 (1 <<0 ); - - log->iocs[nvme_cmd_read] =cpu_to_le32 (1 <<0 ); - log->iocs[nvme_cmd_write] =cpu_to_le32 (1 <<0 ); - log->iocs[nvme_cmd_flush] =cpu_to_le32 (1 <<0 ); - log->iocs[nvme_cmd_dsm] =cpu_to_le32 (1 <<0 ); - log->iocs[nvme_cmd_write_zeroes] =cpu_to_le32 (1 <<0 ); + log->acs[nvme_admin_get_log_page] = + log->acs[nvme_admin_identify] = + log->acs[nvme_admin_abort_cmd] = + log->acs[nvme_admin_set_features] = + log->acs[nvme_admin_get_features] = + log->acs[nvme_admin_async_event] = + log->acs[nvme_admin_keep_alive] = +cpu_to_le32 (NVME_CMD_EFFECTS_CSUPP ); + + log->iocs[nvme_cmd_read] = + log->iocs[nvme_cmd_write] = + log->iocs[nvme_cmd_flush] = + log->iocs[nvme_cmd_dsm] = + log->iocs[nvme_cmd_write_zeroes] = +cpu_to_le32 (NVME_CMD_EFFECTS_CSUPP ); }static void nvmet_get_cmd_effects_zns (struct nvme_effects_log *log) { - log->iocs[nvme_cmd_zone_append] =cpu_to_le32 (1 <<0 ); - log->iocs[nvme_cmd_zone_mgmt_send] =cpu_to_le32 (1 <<0 ); - log->iocs[nvme_cmd_zone_mgmt_recv] =cpu_to_le32 (1 <<0 ); + log->iocs[nvme_cmd_zone_append] = + log->iocs[nvme_cmd_zone_mgmt_send] = + log->iocs[nvme_cmd_zone_mgmt_recv] = +cpu_to_le32 (NVME_CMD_EFFECTS_CSUPP ); }static void nvmet_execute_get_log_cmd_effects_ns (struct nvmet_req *req)
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 10/10 nvme: also return I/O command effects from nvme_command_effects
In reply to Sasha LevinFrom: Christoph Hellwig <[email protected]>
[ Upstream commit 831ed60c2aca2d7c517b2da22897a90224a97d27 ]
To be able to use the Commands Supported and Effects Log for allowing unprivileged passtrough, it needs to be corretly reported for I/O commands as well. Return the I/O command effects from nvme_command_effects, and also add a default list of effects for the NVM command set. For other command sets, the Commands Supported and Effects log is required to be present already.
--- drivers/nvme/host/core.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +26 -6
@@ -1069,6 +1069,18 @@ static u32 nvme_known_admin_effects(u8 opcode)return 0 ; } +static u32 nvme_known_nvm_effects (u8 opcode) +{ +switch (opcode) { +case nvme_cmd_write: +case nvme_cmd_write_zeroes: +case nvme_cmd_write_uncor: +return NVME_CMD_EFFECTS_LBCC ; +default : +return 0 ; + } +} +u32 nvme_command_effects (struct nvme_ctrl *ctrl,struct nvme_ns *ns,u8 opcode) {u32 effects =0 ;
@@ -1076,16 +1088,24 @@ u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode)if (ns) {if (ns->head->effects) effects =le32_to_cpu (ns->head->effects->iocs[opcode]); +if (ns->head->ids.csi ==NVME_CAP_CSS_NVM ) + effects |=nvme_known_nvm_effects (opcode);if (effects & ~(NVME_CMD_EFFECTS_CSUPP |NVME_CMD_EFFECTS_LBCC ))dev_warn_once (ctrl->device, -"IO command:%02x has unhandled effects:%08x\n" , +"IO command:%02x has unusual effects:%08x\n" , opcode, effects); -return 0 ; - } -if (ctrl->effects) - effects =le32_to_cpu (ctrl->effects->acs[opcode]); - effects |=nvme_known_admin_effects (opcode); +/* +* NVME_CMD_EFFECTS_CSE_MASK causes a freeze all I/O queues, +* which would deadlock when done on an I/O command. Note that +* We already warn about an unusual effect above. +*/ + effects &= ~NVME_CMD_EFFECTS_CSE_MASK ; + }else { +if (ctrl->effects) + effects =le32_to_cpu (ctrl->effects->acs[opcode]); + effects |=nvme_known_admin_effects (opcode); + }return effects; }
Signature · 1 line
2.35.1