drm/amd/display: Exit idle optimizations before HDCP execution
Subsystems (4)
Sasha Levin
maintainerPATCH 1/11 drm/amd/display: Exit idle optimizations before HDCP execution
From: Nicholas Kazlauskas <[email protected]>
[ Upstream commit f30a3bea92bdab398531129d187629fb1d28f598 ]
[WHY]
PSP can access DCN registers during command submission and we need to ensure that DCN is not in PG before doing so.
[HOW]
Add a callback to DM to lock and notify DC for idle optimization exit. It can't be DC directly because of a potential race condition with the link protection thread and the rest of DM operation.
--- drivers/gpu/drm/amd/display/modules/hdcp/hdcp.c | 10 ++++++++++ drivers/gpu/drm/amd/display/modules/inc/mod_hdcp.h | 8 ++++++++ 2 files changed, 18 insertions(+)
drivers/gpu/drm/amd/display/modules/hdcp/hdcp.c +10 -0
@@ -88,6 +88,14 @@ static uint8_t is_cp_desired_hdcp2(struct mod_hdcp *hdcp) !hdcp->connection.is_hdcp2_revoked; } +static void exit_idle_optimizations (struct mod_hdcp *hdcp) +{ +struct mod_hdcp_dm *dm = &hdcp->config.dm; + +if (dm->funcs.exit_idle_optimizations) + dm->funcs.exit_idle_optimizations (dm->handle); +} +static enum mod_hdcp_status execution (struct mod_hdcp *hdcp,struct mod_hdcp_event_context *event_ctx,union mod_hdcp_transition_input *input)
@@ -543,6 +551,8 @@ enum mod_hdcp_status mod_hdcp_process_event(struct mod_hdcp *hdcp,memset (&event_ctx,0 ,sizeof (struct mod_hdcp_event_context )); event_ctx.event = event; +exit_idle_optimizations (hdcp); +/* execute and transition */ exec_status =execution (hdcp, &event_ctx, &hdcp->auth.trans_input); trans_status = transition(
drivers/gpu/drm/amd/display/modules/inc/mod_hdcp.h +8 -0
@@ -155,6 +155,13 @@ struct mod_hdcp_ddc { } funcs; }; +struct mod_hdcp_dm { +void *handle; +struct { +void (*exit_idle_optimizations)(void *handle); + } funcs; +}; +struct mod_hdcp_psp {void *handle;void *funcs;
@@ -271,6 +278,7 @@ struct mod_hdcp_display_query {struct mod_hdcp_config {struct mod_hdcp_psp psp;struct mod_hdcp_ddc ddc; +struct mod_hdcp_dm dm;uint8_t index; };
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 2/11 platform/x86: toshiba_acpi: Add quirk for buttons on Z830
From: Arvid Norlander <[email protected]>
[ Upstream commit 23f1d8b47d125dcd8c1ec62a91164e6bc5d691d0 ]
The Z830 has some buttons that will only work properly as "quickstart" buttons. To enable them in that mode, a value between 1 and 7 must be used for HCI_HOTKEY_EVENT. Windows uses 0x5 on this laptop so use that for maximum predictability and compatibility.
As there is not yet a known way of auto detection, this patch uses a DMI quirk table. A module parameter is exposed to allow setting this on other models for testing.
--- drivers/platform/x86/toshiba_acpi.c | 36 ++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-)
drivers/platform/x86/toshiba_acpi.c +33 -3
@@ -57,6 +57,11 @@ module_param(turn_on_panel_on_resume, int, 0644);MODULE_PARM_DESC (turn_on_panel_on_resume,"Call HCI_PANEL_POWER_ON on resume (-1 = auto, 0 = no, 1 = yes" ); +static int hci_hotkey_quickstart =-1 ; +module_param (hci_hotkey_quickstart, int,0644 ); +MODULE_PARM_DESC (hci_hotkey_quickstart, +"Call HCI_HOTKEY_EVENT with value 0x5 for quickstart button support (-1 = auto, 0 = no, 1 = yes" ); +#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"/* Scan code for Fn key on TOS1900 models */
@@ -136,6 +141,7 @@ MODULE_PARM_DESC(turn_on_panel_on_resume,#define HCI_ACCEL_MASK 0x7fff#define HCI_ACCEL_DIRECTION_MASK 0x8000#define HCI_HOTKEY_DISABLE 0x0b +#define HCI_HOTKEY_ENABLE_QUICKSTART 0x05#define HCI_HOTKEY_ENABLE 0x09#define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10#define HCI_LCD_BRIGHTNESS_BITS 3
@@ -2730,10 +2736,15 @@ static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)return -ENODEV ;/* +* Enable quickstart buttons if supported. +* * Enable the "Special Functions" mode only if they are * supported and if they are activated. */ -if (dev->kbd_function_keys_supported && dev->special_functions) +if (hci_hotkey_quickstart) + result =hci_write (dev,HCI_HOTKEY_EVENT , +HCI_HOTKEY_ENABLE_QUICKSTART ); +else if (dev->kbd_function_keys_supported && dev->special_functions) result =hci_write (dev,HCI_HOTKEY_EVENT ,HCI_HOTKEY_SPECIAL_FUNCTIONS );else
@@ -3259,7 +3270,14 @@ static const char *find_hci_method(acpi_handle handle)* works. toshiba_acpi_resume() uses HCI_PANEL_POWER_ON to avoid changing * the configured brightness level. */ -static const struct dmi_system_id turn_on_panel_on_resume_dmi_ids[] = { +#define QUIRK_TURN_ON_PANEL_ON_RESUME BIT(0) +/* +* Some Toshibas use "quickstart" keys. On these, HCI_HOTKEY_EVENT must use +* the value HCI_HOTKEY_ENABLE_QUICKSTART. +*/ +#define QUIRK_HCI_HOTKEY_QUICKSTART BIT(1) + +static const struct dmi_system_id toshiba_dmi_quirks[] = { {/* Toshiba Portégé R700 */ /* https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
@@ -3267,6 +3285,7 @@ static const struct dmi_system_id turn_on_panel_on_resume_dmi_ids[] = {DMI_MATCH (DMI_SYS_VENDOR ,"TOSHIBA" ), DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R700"), }, + .driver_data = (void *)QUIRK_TURN_ON_PANEL_ON_RESUME, }, {/* Toshiba Satellite/Portégé R830 */
@@ -3276,6 +3295,7 @@ static const struct dmi_system_id turn_on_panel_on_resume_dmi_ids[] = {DMI_MATCH (DMI_SYS_VENDOR ,"TOSHIBA" ), DMI_MATCH(DMI_PRODUCT_NAME, "R830"), }, + .driver_data = (void *)QUIRK_TURN_ON_PANEL_ON_RESUME, }, {/* Toshiba Satellite/Portégé Z830 */
@@ -3283,6 +3303,7 @@ static const struct dmi_system_id turn_on_panel_on_resume_dmi_ids[] = { DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), DMI_MATCH(DMI_PRODUCT_NAME, "Z830"), }, + .driver_data = (void *)(QUIRK_TURN_ON_PANEL_ON_RESUME | QUIRK_HCI_HOTKEY_QUICKSTART), }, };
@@ -3291,6 +3312,8 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)struct toshiba_acpi_dev *dev;const char *hci_method;u32 dummy; +const struct dmi_system_id *dmi_id; +long quirks =0 ;int ret =0 ;if (toshiba_acpi)
@@ -3443,8 +3466,15 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) }#endif + dmi_id =dmi_first_match (toshiba_dmi_quirks); +if (dmi_id) + quirks = (long )dmi_id->driver_data; +if (turn_on_panel_on_resume ==-1 ) - turn_on_panel_on_resume =dmi_check_system (turn_on_panel_on_resume_dmi_ids); + turn_on_panel_on_resume = !!(quirks &QUIRK_TURN_ON_PANEL_ON_RESUME ); + +if (hci_hotkey_quickstart ==-1 ) + hci_hotkey_quickstart = !!(quirks &QUIRK_HCI_HOTKEY_QUICKSTART );toshiba_wwan_available (dev);if (dev->wwan_supported)
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 3/11 ASoC: Intel: sof_sdw: add JD2 quirk for HP Omen 14
In reply to Sasha LevinFrom: Pierre-Louis Bossart <[email protected]>
[ Upstream commit 4fee07fbf47d2a5f1065d985459e5ce7bf7969f0 ]
The default JD1 does not seem to work, use JD2 instead.
--- sound/soc/intel/boards/sof_sdw.c | 9 +++++++++ 1 file changed, 9 insertions(+)
sound/soc/intel/boards/sof_sdw.c +9 -0
@@ -413,6 +413,15 @@ static const struct dmi_system_id sof_sdw_quirk_table[] = { SOF_BT_OFFLOAD_SSP(1) | SOF_SSP_BT_OFFLOAD_PRESENT), }, + { + .callback = sof_sdw_quirk_cb, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HP"), + DMI_MATCH(DMI_PRODUCT_NAME, "OMEN Transcend Gaming Laptop"), + }, + .driver_data = (void *)(RT711_JD2), + }, +/* LunarLake devices */ { .callback = sof_sdw_quirk_cb,
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 4/11 drm/lima: add mask irq callback to gp and pp
In reply to Sasha LevinFrom: Erico Nunes <[email protected]>
[ Upstream commit 49c13b4d2dd4a831225746e758893673f6ae961c ]
This is needed because we want to reset those devices in device-agnostic code such as lima_sched.
In particular, masking irqs will be useful before a hard reset to prevent race conditions.
--- drivers/gpu/drm/lima/lima_bcast.c | 12 ++++++++++++ drivers/gpu/drm/lima/lima_bcast.h | 3 +++ drivers/gpu/drm/lima/lima_gp.c | 8 ++++++++ drivers/gpu/drm/lima/lima_pp.c | 18 ++++++++++++++++++ drivers/gpu/drm/lima/lima_sched.h | 1 + 5 files changed, 42 insertions(+)
drivers/gpu/drm/lima/lima_bcast.c +12 -0
@@ -43,6 +43,18 @@ void lima_bcast_suspend(struct lima_ip *ip) } +int lima_bcast_mask_irq (struct lima_ip *ip) +{ +bcast_write (LIMA_BCAST_BROADCAST_MASK ,0 ); +bcast_write (LIMA_BCAST_INTERRUPT_MASK ,0 ); +return 0 ; +} + +int lima_bcast_reset (struct lima_ip *ip) +{ +return lima_bcast_hw_init (ip); +} +int lima_bcast_init (struct lima_ip *ip) {int i;
drivers/gpu/drm/lima/lima_bcast.h +3 -0
@@ -13,4 +13,7 @@ void lima_bcast_fini(struct lima_ip *ip);void lima_bcast_enable (struct lima_device *dev,int num_pp); +int lima_bcast_mask_irq (struct lima_ip *ip); +int lima_bcast_reset (struct lima_ip *ip); +#endif
drivers/gpu/drm/lima/lima_gp.c +8 -0
@@ -212,6 +212,13 @@ static void lima_gp_task_mmu_error(struct lima_sched_pipe *pipe)lima_sched_pipe_task_done (pipe); } +static void lima_gp_task_mask_irq (struct lima_sched_pipe *pipe) +{ +struct lima_ip *ip = pipe->processor[0 ]; + +gp_write (LIMA_GP_INT_MASK ,0 ); +} +static int lima_gp_task_recover (struct lima_sched_pipe *pipe) {struct lima_ip *ip = pipe->processor[0 ];
@@ -344,6 +351,7 @@ int lima_gp_pipe_init(struct lima_device *dev) pipe->task_error = lima_gp_task_error; pipe->task_mmu_error = lima_gp_task_mmu_error; pipe->task_recover = lima_gp_task_recover; + pipe->task_mask_irq = lima_gp_task_mask_irq;return 0 ; }
drivers/gpu/drm/lima/lima_pp.c +18 -0
@@ -408,6 +408,9 @@ static void lima_pp_task_error(struct lima_sched_pipe *pipe)lima_pp_hard_reset (ip); } + +if (pipe->bcast_processor) +lima_bcast_reset (pipe->bcast_processor); }static void lima_pp_task_mmu_error (struct lima_sched_pipe *pipe)
@@ -416,6 +419,20 @@ static void lima_pp_task_mmu_error(struct lima_sched_pipe *pipe)lima_sched_pipe_task_done (pipe); } +static void lima_pp_task_mask_irq (struct lima_sched_pipe *pipe) +{ +int i; + +for (i =0 ; i < pipe->num_processor; i++) { +struct lima_ip *ip = pipe->processor[i]; + +pp_write (LIMA_PP_INT_MASK ,0 ); + } + +if (pipe->bcast_processor) +lima_bcast_mask_irq (pipe->bcast_processor); +} +static struct kmem_cache *lima_pp_task_slab;static int lima_pp_task_slab_refcnt;
@@ -447,6 +464,7 @@ int lima_pp_pipe_init(struct lima_device *dev) pipe->task_fini = lima_pp_task_fini; pipe->task_error = lima_pp_task_error; pipe->task_mmu_error = lima_pp_task_mmu_error; + pipe->task_mask_irq = lima_pp_task_mask_irq;return 0 ; }
drivers/gpu/drm/lima/lima_sched.h +1 -0
@@ -80,6 +80,7 @@ struct lima_sched_pipe {void (*task_error)(struct lima_sched_pipe *pipe);void (*task_mmu_error)(struct lima_sched_pipe *pipe);int (*task_recover)(struct lima_sched_pipe *pipe); +void (*task_mask_irq)(struct lima_sched_pipe *pipe);struct work_struct recover_work; };
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 5/11 drm/lima: mask irqs in timeout path before hard reset
In reply to Sasha LevinFrom: Erico Nunes <[email protected]>
[ Upstream commit a421cc7a6a001b70415aa4f66024fa6178885a14 ]
There is a race condition in which a rendering job might take just long enough to trigger the drm sched job timeout handler but also still complete before the hard reset is done by the timeout handler. This runs into race conditions not expected by the timeout handler. In some very specific cases it currently may result in a refcount imbalance on lima_pm_idle, with a stack dump such as:
[10136.669170] WARNING: CPU: 0 PID: 0 at drivers/gpu/drm/lima/lima_devfreq.c:205 lima_devfreq_record_idle+0xa0/0xb0 ... [10136.669459] pc : lima_devfreq_record_idle+0xa0/0xb0 ... [10136.669628] Call trace: [10136.669634] lima_devfreq_record_idle+0xa0/0xb0 [10136.669646] lima_sched_pipe_task_done+0x5c/0xb0 [10136.669656] lima_gp_irq_handler+0xa8/0x120 [10136.669666] __handle_irq_event_percpu+0x48/0x160 [10136.669679] handle_irq_event+0x4c/0xc0
We can prevent that race condition entirely by masking the irqs at the beginning of the timeout handler, at which point we give up on waiting for that job entirely.
The irqs will be enabled again at the next hard reset which is already done as a recovery by the timeout handler.
--- drivers/gpu/drm/lima/lima_sched.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/lima/lima_sched.c +7 -0
@@ -402,6 +402,13 @@ static enum drm_gpu_sched_stat lima_sched_timedout_job(struct drm_sched_job *jobstruct lima_sched_task *task =to_lima_task (job);struct lima_device *ldev = pipe->ldev; +/* +* The task might still finish while this timeout handler runs. +* To prevent a race condition on its completion, mask all irqs +* on the running core until the next hard reset completes. +*/ + pipe->task_mask_irq (pipe); +if (!pipe->error)DRM_ERROR ("lima job timeout\n" );
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 6/11 ALSA: hda/realtek: Add quirks for Lenovo 13X
In reply to Sasha LevinFrom: Stefan Binding <[email protected]>
[ Upstream commit 25f46354dca912c84f1f79468fd636a94b8d287a ]
Add laptop using CS35L41 HDA.
This laptop does not have _DSD, so require entries in property configuration table for cs35l41_hda driver.
Message-ID: <[email protected]>
--- sound/pci/hda/patch_realtek.c | 2 ++ 1 file changed, 2 insertions(+)
sound/pci/hda/patch_realtek.c +2 -0
@@ -10076,6 +10076,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x17aa ,0x3852 ,"Lenovo Yoga 7 14ITL5" ,ALC287_FIXUP_YOGA7_14ITL_SPEAKERS ),SND_PCI_QUIRK (0x17aa ,0x3853 ,"Lenovo Yoga 7 15ITL5" ,ALC287_FIXUP_YOGA7_14ITL_SPEAKERS ),SND_PCI_QUIRK (0x17aa ,0x3855 ,"Legion 7 16ITHG6" ,ALC287_FIXUP_LEGION_16ITHG6 ), +SND_PCI_QUIRK (0x17aa ,0x3865 ,"Lenovo 13X" ,ALC287_FIXUP_CS35L41_I2C_2 ), +SND_PCI_QUIRK (0x17aa ,0x3866 ,"Lenovo 13X" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x17aa ,0x3869 ,"Lenovo Yoga7 14IAL7" ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN ),SND_PCI_QUIRK (0x17aa ,0x3902 ,"Lenovo E50-80" ,ALC269_FIXUP_DMIC_THINKPAD_ACPI ), SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC),
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 7/11 media: lgdt3306a: Add a check against null-pointer-def
In reply to Sasha LevinFrom: Zheyu Ma <[email protected]>
[ Upstream commit c1115ddbda9c930fba0fdd062e7a8873ebaf898d ]
The driver should check whether the client provides the platform_data.
The following log reveals it:
[ 29.610324] BUG: KASAN: null-ptr-deref in kmemdup+0x30/0x40 [ 29.610730] Read of size 40 at addr 0000000000000000 by task bash/414 [ 29.612820] Call Trace: [ 29.613030] <TASK> [ 29.613201] dump_stack_lvl+0x56/0x6f [ 29.613496] ? kmemdup+0x30/0x40 [ 29.613754] print_report.cold+0x494/0x6b7 [ 29.614082] ? kmemdup+0x30/0x40 [ 29.614340] kasan_report+0x8a/0x190 [ 29.614628] ? kmemdup+0x30/0x40 [ 29.614888] kasan_check_range+0x14d/0x1d0 [ 29.615213] memcpy+0x20/0x60 [ 29.615454] kmemdup+0x30/0x40 [ 29.615700] lgdt3306a_probe+0x52/0x310 [ 29.616339] i2c_device_probe+0x951/0xa90
--- drivers/media/dvb-frontends/lgdt3306a.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/media/dvb-frontends/lgdt3306a.c +5 -0
@@ -2177,6 +2177,11 @@ static int lgdt3306a_probe(struct i2c_client *client,struct dvb_frontend *fe;int ret; +if (!client->dev.platform_data) { +dev_err (&client->dev,"platform data is mandatory\n" ); +return -EINVAL ; + } + config =kmemdup (client->dev.platform_data,sizeof (struct lgdt3306a_config ),GFP_KERNEL );if (config ==NULL ) {
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 8/11 powerpc: make fadump resilient with memory add/remove events
In reply to Sasha LevinFrom: Sourabh Jain <[email protected]>
[ Upstream commit c6c5b14dac0d1bd0da8b4d1d3b77f18eb9085fcb ]
Due to changes in memory resources caused by either memory hotplug or online/offline events, the elfcorehdr, which describes the CPUs and memory of the crashed kernel to the kernel that collects the dump (known as second/fadump kernel), becomes outdated. Consequently, attempting dump collection with an outdated elfcorehdr can lead to failed or inaccurate dump collection.
Memory hotplug or online/offline events is referred as memory add/remove events in reset of the commit message.
The current solution to address the aforementioned issue is as follows:
Monitor memory add/remove events in userspace using udev rules, and re-register fadump whenever there are changes in memory resources. This leads to the creation of a new elfcorehdr with updated system memory information.
There are several notable issues associated with re-registering fadump for every memory add/remove events.
1. Bulk memory add/remove events with udev-based fadump re-registration can lead to race conditions and, more importantly, it creates a wide window during which fadump is inactive until all memory add/remove events are settled.
2. Re-registering fadump for every memory add/remove event is inefficient.
3. The memory for elfcorehdr is allocated based on the memblock regions available during early boot and remains fixed thereafter. However, if elfcorehdr is later recreated with additional memblock regions, its size will increase, potentially leading to memory corruption.
Address the aforementioned challenges by shifting the creation of elfcorehdr from the first kernel (also referred as the crashed kernel), where it was created and frequently recreated for every memory add/remove event, to the fadump kernel. As a result, the elfcorehdr only needs to be created once, thus eliminating the necessity to re-register fadump during memory add/remove events.
At present, the first kernel prepares fadump header and stores it in the fadump reserved area. The fadump header includes the start address of the elfcorehdr, crashing CPU details, and other relevant information. In the event of a crash in the first kernel, the second/fadump boots and accesses the fadump header prepared by the first kernel. It then performs the following steps in a platform-specific function [rtas|opal]_fadump_process:
1. Sanity check for fadump header
2. Update CPU notes in elfcorehdr
Along with the above, update the setup_fadump()/fadump.c to create elfcorehdr and set its address to the global variable elfcorehdr_addr for the vmcore module to process it in the second/fadump kernel.
Section below outlines the information required to create the elfcorehdr and the changes made to make it available to the fadump kernel if it's not already.
To create elfcorehdr, the following crashed kernel information is
required: CPU notes, vmcoreinfo, and memory ranges.
At present, the CPU notes are already prepared in the fadump kernel, so no changes are needed in that regard. The fadump kernel has access to all crashed kernel memory regions, including boot memory regions that are relocated by firmware to fadump reserved areas, so no changes for that either. However, it is necessary to add new members to the fadump header, i.e., the 'fadump_crash_info_header' structure, in order to pass the crashed kernel's vmcoreinfo address and its size to fadump kernel.
In addition to the vmcoreinfo address and size, there are a few other attributes also added to the fadump_crash_info_header structure.
1. version:
It stores the fadump header version, which is currently set to 1. This provides flexibility to update the fadump crash info header in the future without changing the magic number. For each change in the fadump header, the version will be increased. This will help the updated kernel determine how to handle kernel dumps from older kernels. The magic number remains relevant for checking fadump header corruption.
2. pt_regs_sz/cpu_mask_sz:
Store size of pt_regs and cpu_mask structure of first kernel. These attributes are used to prevent dump processing if the sizes of pt_regs or cpu_mask structure differ between the first and fadump kernels.
Note: if either first/crashed kernel or second/fadump kernel do not have the changes introduced here then kernel fail to collect the dump and prints relevant error message on the console.
--- arch/powerpc/include/asm/fadump-internal.h | 31 +- arch/powerpc/kernel/fadump.c | 361 +++++++++++-------- arch/powerpc/platforms/powernv/opal-fadump.c | 22 +- arch/powerpc/platforms/pseries/rtas-fadump.c | 34 +- 4 files changed, 242 insertions(+), 206 deletions(-)
arch/powerpc/include/asm/fadump-internal.h +29 -2
@@ -42,13 +42,38 @@ static inline u64 fadump_str_to_u64(const char *str)#define FADUMP_CPU_UNKNOWN (~((u32)0)) -#define FADUMP_CRASH_INFO_MAGIC fadump_str_to_u64("FADMPINF") +/* +* The introduction of new fields in the fadump crash info header has +* led to a change in the magic key from `FADMPINF` to `FADMPSIG` for +* identifying a kernel crash from an old kernel. +* +* To prevent the need for further changes to the magic number in the +* event of future modifications to the fadump crash info header, a +* version field has been introduced to track the fadump crash info +* header version. +* +* Consider a few points before adding new members to the fadump crash info +* header structure: +* +* - Append new members; avoid adding them in between. +* - Non-primitive members should have a size member as well. +* - For every change in the fadump header, increment the +* fadump header version. This helps the updated kernel decide how to +* handle kernel dumps from older kernels. +*/ +#define FADUMP_CRASH_INFO_MAGIC_OLD fadump_str_to_u64("FADMPINF") +#define FADUMP_CRASH_INFO_MAGIC fadump_str_to_u64("FADMPSIG") +#define FADUMP_HEADER_VERSION 1/* fadump crash info structure */ struct fadump_crash_info_header {u64 magic_number; -u64 elfcorehdr_addr; +u32 version;u32 crashing_cpu; +u64 vmcoreinfo_raddr; +u64 vmcoreinfo_size; +u32 pt_regs_sz; +u32 cpu_mask_sz;struct pt_regs regs;struct cpumask cpu_mask; };
@@ -94,6 +119,8 @@ struct fw_dump {u64 boot_mem_regs_cnt;unsigned long fadumphdr_addr; +u64 elfcorehdr_addr; +u64 elfcorehdr_size;unsigned long cpu_notes_buf_vaddr;unsigned long cpu_notes_buf_size;
arch/powerpc/kernel/fadump.c +205 -156
481 lines not on this page · raw message
arch/powerpc/platforms/powernv/opal-fadump.c +3 -19
@@ -513,8 +513,8 @@ opal_fadump_build_cpu_notes(struct fw_dump *fadump_conf,final_note (note_buf);pr_debug ("Updating elfcore header (%llx) with cpu notes\n" , - fdh->elfcorehdr_addr); -fadump_update_elfcore_header (__va (fdh->elfcorehdr_addr)); + fadump_conf->elfcorehdr_addr); +fadump_update_elfcore_header ((char *)fadump_conf->elfcorehdr_addr);return 0 ; }
@@ -526,12 +526,7 @@ static int __init opal_fadump_process(struct fw_dump *fadump_conf)if (!opal_fdm_active || !fadump_conf->fadumphdr_addr)return rc; -/* Validate the fadump crash info header */ fdh =__va (fadump_conf->fadumphdr_addr); -if (fdh->magic_number !=FADUMP_CRASH_INFO_MAGIC ) { -pr_err ("Crash info header is not valid.\n" ); -return rc; - }#ifdef CONFIG_OPAL_CORE /*
@@ -545,18 +540,7 @@ static int __init opal_fadump_process(struct fw_dump *fadump_conf) kernel_initiated = true;#endif - rc =opal_fadump_build_cpu_notes (fadump_conf, fdh); -if (rc) -return rc; - -/* -* We are done validating dump info and elfcore header is now ready -* to be exported. set elfcorehdr_addr so that vmcore module will -* export the elfcore header through '/proc/vmcore'. -*/ - elfcorehdr_addr = fdh->elfcorehdr_addr; - -return rc; +return opal_fadump_build_cpu_notes (fadump_conf, fdh); } static void opal_fadump_region_show(struct fw_dump *fadump_conf,
arch/powerpc/platforms/pseries/rtas-fadump.c +5 -29
@@ -375,11 +375,8 @@ static int __init rtas_fadump_build_cpu_notes(struct fw_dump *fadump_conf) }final_note (note_buf); -if (fdh) { -pr_debug ("Updating elfcore header (%llx) with cpu notes\n" , - fdh->elfcorehdr_addr); -fadump_update_elfcore_header (__va (fdh->elfcorehdr_addr)); - } +pr_debug ("Updating elfcore header (%llx) with cpu notes\n" , fadump_conf->elfcorehdr_addr); +fadump_update_elfcore_header ((char *)fadump_conf->elfcorehdr_addr);return 0 ; error_out:
@@ -389,14 +386,11 @@ static int __init rtas_fadump_build_cpu_notes(struct fw_dump *fadump_conf) }/* -* Validate and process the dump data stored by firmware before exporting -* it through '/proc/vmcore'. +* Validate and process the dump data stored by the firmware, and update +* the CPU notes of elfcorehdr. */ static int __init rtas_fadump_process (struct fw_dump *fadump_conf) { -struct fadump_crash_info_header *fdh; -int rc =0 ; -if (!fdm_active || !fadump_conf->fadumphdr_addr)return -EINVAL ;
@@ -415,25 +409,7 @@ static int __init rtas_fadump_process(struct fw_dump *fadump_conf)return -EINVAL ; } -/* Validate the fadump crash info header */ - fdh =__va (fadump_conf->fadumphdr_addr); -if (fdh->magic_number !=FADUMP_CRASH_INFO_MAGIC ) { -pr_err ("Crash info header is not valid.\n" ); -return -EINVAL ; - } - - rc =rtas_fadump_build_cpu_notes (fadump_conf); -if (rc) -return rc; - -/* -* We are done validating dump info and elfcore header is now ready -* to be exported. set elfcorehdr_addr so that vmcore module will -* export the elfcore header through '/proc/vmcore'. -*/ - elfcorehdr_addr = fdh->elfcorehdr_addr; - -return 0 ; +return rtas_fadump_build_cpu_notes (fadump_conf); } static void rtas_fadump_region_show(struct fw_dump *fadump_conf,
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 9/11 powerpc/pseries: Enforce hcall result buffer validity and size
In reply to Sasha LevinFrom: Nathan Lynch <[email protected]>
[ Upstream commit ff2e185cf73df480ec69675936c4ee75a445c3e4 ]
plpar_hcall(), plpar_hcall9(), and related functions expect callers to provide valid result buffers of certain minimum size. Currently this is communicated only through comments in the code and the compiler has no idea.
For example, if I write a bug like this:
long retbuf[PLPAR_HCALL_BUFSIZE]; // should be PLPAR_HCALL9_BUFSIZE plpar_hcall9(H_ALLOCATE_VAS_WINDOW, retbuf, ...);
This compiles with no diagnostics emitted, but likely results in stack corruption at runtime when plpar_hcall9() stores results past the end of the array. (To be clear this is a contrived example and I have not found a real instance yet.)
To make this class of error less likely, we can use explicitly-sized array parameters instead of pointers in the declarations for the hcall APIs. When compiled with -Warray-bounds[1], the code above now provokes a diagnostic like this:
error: array argument is too small;
is of size 32, callee requires at least 72 [-Werror,-Warray-bounds]
60 | plpar_hcall9(H_ALLOCATE_VAS_WINDOW, retbuf,
| ^ ~~~~~~[1] Enabled for LLVM builds but not GCC for now. See commit
0da6e5fd6c37 ("gcc: disable '-Warray-bounds' for gcc-13 too") and
related changes.--- arch/powerpc/include/asm/hvcall.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/hvcall.h +4 -4
@@ -493,7 +493,7 @@ long plpar_hcall_norets_notrace(unsigned long opcode, ...);* Used for all but the craziest of phyp interfaces (see plpar_hcall9) */ #define PLPAR_HCALL_BUFSIZE 4 -long plpar_hcall (unsigned long opcode,unsigned long *retbuf, ...); +long plpar_hcall (unsigned long opcode,unsigned long retbuf[static PLPAR_HCALL_BUFSIZE ], ...);/** * plpar_hcall_raw: - Make a hypervisor call without calculating hcall stats
@@ -507,7 +507,7 @@ long plpar_hcall(unsigned long opcode, unsigned long *retbuf, ...);* plpar_hcall, but plpar_hcall_raw works in real mode and does not * calculate hypervisor call statistics. */ -long plpar_hcall_raw (unsigned long opcode,unsigned long *retbuf, ...); +long plpar_hcall_raw (unsigned long opcode,unsigned long retbuf[static PLPAR_HCALL_BUFSIZE ], ...);/** * plpar_hcall9: - Make a pseries hypervisor call with up to 9 return arguments
@@ -518,8 +518,8 @@ long plpar_hcall_raw(unsigned long opcode, unsigned long *retbuf, ...);* PLPAR_HCALL9_BUFSIZE to size the return argument buffer. */ #define PLPAR_HCALL9_BUFSIZE 9 -long plpar_hcall9 (unsigned long opcode,unsigned long *retbuf, ...); -long plpar_hcall9_raw (unsigned long opcode,unsigned long *retbuf, ...); +long plpar_hcall9 (unsigned long opcode,unsigned long retbuf[static PLPAR_HCALL9_BUFSIZE ], ...); +long plpar_hcall9_raw (unsigned long opcode,unsigned long retbuf[static PLPAR_HCALL9_BUFSIZE ], ...);/* pseries hcall tracing */ extern struct static_key hcall_tracepoint_key;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 10/11 powerpc/io: Avoid clang null pointer arithmetic warnings
In reply to Sasha LevinFrom: Michael Ellerman <[email protected]>
[ Upstream commit 03c0f2c2b2220fc9cf8785cd7b61d3e71e24a366 ]
With -Wextra clang warns about pointer arithmetic using a null pointer. When building with CONFIG_PCI=n, that triggers a warning in the IO accessors, eg:
In file included from linux/arch/powerpc/include/asm/io.h:672:
linux/arch/powerpc/include/asm/io-defs.h:23:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
23 | DEF_PCI_AC_RET(inb, u8, (unsigned long port), (port), pio, port)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
linux/arch/powerpc/include/asm/io.h:591:53: note: expanded from macro '__do_inb'
591 | #define __do_inb(port) readb((PCI_IO_ADDR)_IO_BASE + port);
| ~~~~~~~~~~~~~~~~~~~~~ ^That is because when CONFIG_PCI=n, _IO_BASE is defined as 0.
Although _IO_BASE is defined as plain 0, the cast (PCI_IO_ADDR) converts it to void * before the addition with port happens.
Instead the addition can be done first, and then the cast. The resulting value will be the same, but avoids the warning, and also avoids void pointer arithmetic which is apparently non-standard.
--- arch/powerpc/include/asm/io.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
arch/powerpc/include/asm/io.h +12 -12
@@ -553,12 +553,12 @@ __do_out_asm(_rec_outl, "stwbrx")#define __do_inw (port) _rec_inw(port)#define __do_inl (port) _rec_inl(port)#else /* CONFIG_PPC32 */ -#define __do_outb (val, port) writeb(val,(PCI_IO_ADDR)_IO_BASE+port); -#define __do_outw (val, port) writew(val,(PCI_IO_ADDR)_IO_BASE+port); -#define __do_outl (val, port) writel(val,(PCI_IO_ADDR)_IO_BASE+port); -#define __do_inb (port) readb((PCI_IO_ADDR)_IO_BASE + port); -#define __do_inw (port) readw((PCI_IO_ADDR)_IO_BASE + port); -#define __do_inl (port) readl((PCI_IO_ADDR)_IO_BASE + port); +#define __do_outb (val, port) writeb(val,(PCI_IO_ADDR)(_IO_BASE+port)); +#define __do_outw (val, port) writew(val,(PCI_IO_ADDR)(_IO_BASE+port)); +#define __do_outl (val, port) writel(val,(PCI_IO_ADDR)(_IO_BASE+port)); +#define __do_inb (port) readb((PCI_IO_ADDR)(_IO_BASE + port)); +#define __do_inw (port) readw((PCI_IO_ADDR)(_IO_BASE + port)); +#define __do_inl (port) readl((PCI_IO_ADDR)(_IO_BASE + port));#endif /* !CONFIG_PPC32 */ #ifdef CONFIG_EEH
@@ -574,12 +574,12 @@ __do_out_asm(_rec_outl, "stwbrx")#define __do_writesw (a, b, n) _outsw(PCI_FIX_ADDR(a),(b),(n))#define __do_writesl (a, b, n) _outsl(PCI_FIX_ADDR(a),(b),(n)) -#define __do_insb (p, b, n) readsb((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) -#define __do_insw (p, b, n) readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) -#define __do_insl (p, b, n) readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) -#define __do_outsb (p, b, n) writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) -#define __do_outsw (p, b, n) writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) -#define __do_outsl (p, b, n) writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) +#define __do_insb (p, b, n) readsb((PCI_IO_ADDR)(_IO_BASE+(p)), (b), (n)) +#define __do_insw (p, b, n) readsw((PCI_IO_ADDR)(_IO_BASE+(p)), (b), (n)) +#define __do_insl (p, b, n) readsl((PCI_IO_ADDR)(_IO_BASE+(p)), (b), (n)) +#define __do_outsb (p, b, n) writesb((PCI_IO_ADDR)(_IO_BASE+(p)),(b),(n)) +#define __do_outsw (p, b, n) writesw((PCI_IO_ADDR)(_IO_BASE+(p)),(b),(n)) +#define __do_outsl (p, b, n) writesl((PCI_IO_ADDR)(_IO_BASE+(p)),(b),(n))#define __do_memset_io (addr, c, n) \ _memset_io(PCI_FIX_ADDR(addr), c, n)
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 11/11 platform/x86: p2sb: Don't init until unassigned resources have been assigned
In reply to Sasha LevinFrom: Ben Fradella <[email protected]>
[ Upstream commit 2c6370e6607663fc5fa0fd9ed58e2e01014898c7 ]
The P2SB could get an invalid BAR from the BIOS, and that won't be fixed up until pcibios_assign_resources(), which is an fs_initcall().
- Move p2sb_fs_init() to an fs_initcall_sync(). This is still early enough to avoid a race with any dependent drivers.
- Add a check for IORESOURCE_UNSET in p2sb_valid_resource() to catch unset BARs going forward.
- Return error values from p2sb_fs_init() so that the 'initcall_debug' cmdline arg provides useful data.
--- drivers/platform/x86/p2sb.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/platform/x86/p2sb.c +15 -14
@@ -56,12 +56,9 @@ static int p2sb_get_devfn(unsigned int *devfn)return 0 ; } -static bool p2sb_valid_resource (struct resource *res) +static bool p2sb_valid_resource (const struct resource *res) { -if (res->flags) -return true; - -return false; +return res->flags & ~IORESOURCE_UNSET ; }/* Copy resource from the first BAR of the device in question */
@@ -220,16 +217,20 @@ EXPORT_SYMBOL_GPL(p2sb_bar);static int __init p2sb_fs_init (void ) { -p2sb_cache_resources (); -return 0 ; +return p2sb_cache_resources (); }/* -* pci_rescan_remove_lock to avoid access to unhidden P2SB devices can -* not be locked in sysfs pci bus rescan path because of deadlock. To -* avoid the deadlock, access to P2SB devices with the lock at an early -* step in kernel initialization and cache required resources. This -* should happen after subsys_initcall which initializes PCI subsystem -* and before device_initcall which requires P2SB resources. +* pci_rescan_remove_lock() can not be locked in sysfs PCI bus rescan path +* because of deadlock. To avoid the deadlock, access P2SB devices with the lock +* at an early step in kernel initialization and cache required resources. +* +* We want to run as early as possible. If the P2SB was assigned a bad BAR, +* we'll need to wait on pcibios_assign_resources() to fix it. So, our list of +* initcall dependencies looks something like this: +* +* ... +* subsys_initcall (pci_subsys_init) +* fs_initcall (pcibios_assign_resources) */ -fs_initcall (p2sb_fs_init); +fs_initcall_sync (p2sb_fs_init);
Signature · 1 line
2.43.0