public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: "Lazar, Lijo" <lijo.lazar@amd.com>,
	Alex Deucher <alexander.deucher@amd.com>,
	linux-kernel@vger.kernel.org
Cc: Javier Martinez Canillas <javierm@redhat.com>,
	Carlos Soriano Sanchez <csoriano@redhat.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	christian.koenig@amd.com, "Pan, Xinhui" <Xinhui.Pan@amd.com>
Subject: Re: [PATCH v6 05/45] drm/amd: Add a new helper for loading/validating microcode
Date: Wed, 4 Jan 2023 23:37:35 -0600	[thread overview]
Message-ID: <1cc650c7-3bdb-6571-ee79-3bcd7affafc5@amd.com> (raw)
In-Reply-To: <d227e106-1766-c51e-397d-209c1f880a65@amd.com>

On 1/4/23 23:29, Lazar, Lijo wrote:
> 
> 
> On 1/5/2023 10:53 AM, Mario Limonciello wrote:
>> On 1/4/23 23:07, Lazar, Lijo wrote:
>>>
>>>
>>> On 1/5/2023 9:12 AM, Mario Limonciello wrote:
>>>> All microcode runs a basic validation after it's been loaded. Each
>>>> IP block as part of init will run both.
>>>>
>>>> Introduce a wrapper for request_firmware and amdgpu_ucode_validate.
>>>> This wrapper will also remap any error codes from request_firmware
>>>> to -ENODEV.  This is so that early_init will fail if firmware couldn't
>>>> be loaded instead of the IP block being disabled.
>>>>
>>>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>>>> ---
>>>> v5->v6:
>>>>   * Fix argument to be ** not *
>>>> ---
>>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 36 
>>>> +++++++++++++++++++++++
>>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h |  3 ++
>>>>   2 files changed, 39 insertions(+)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c 
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c
>>>> index eafcddce58d3..8ebfec12da87 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c
>>>> @@ -1312,3 +1312,39 @@ void amdgpu_ucode_ip_version_decode(struct 
>>>> amdgpu_device *adev, int block_type,
>>>>       snprintf(ucode_prefix, len, "%s_%d_%d_%d", ip_name, maj, min, 
>>>> rev);
>>>>   }
>>>> +
>>>> +/*
>>>> + * amdgpu_ucode_request - Fetch and validate amdgpu microcode
>>>> + *
>>>> + * @adev: amdgpu device
>>>> + * @fw: pointer to load firmware to
>>>> + * @fw_name: firmware to load
>>>> + *
>>>> + * This is a helper that will use request_firmware and 
>>>> amdgpu_ucode_validate
>>>> + * to load and run basic validation on firmware. If the load fails, 
>>>> remap
>>>> + * the error code to -ENODEV, so that early_init functions will 
>>>> fail to load.
>>>> + */
>>>> +int amdgpu_ucode_request(struct amdgpu_device *adev, const struct 
>>>> firmware **fw,
>>>> +             const char *fw_name)
>>>> +{
>>>> +    int err = request_firmware(fw, fw_name, adev->dev);
>>>> +
>>>> +    if (err)
>>>> +        return -ENODEV;
>>>> +    err = amdgpu_ucode_validate(*fw);
>>>> +    if (err)
>>>> +        dev_dbg(adev->dev, "\"%s\" failed to validate\n", fw_name);
>>>> +
>>>
>>> Missed this earlier. If validate fails, shouldn't this undo the 
>>> request operation by calling release?
>>
>> Actually that was original design, but there is one place in the 
>> codebase that expects that ucode validation can fail, and so leave the 
>> evaluate of error code and cleanup outside of helper.
>>
> 
> I see. Does request_firmware assure that fw pointer be always NULL if it 
> fails? Or should that be done here if request_ fails? In subsequent 
> patches, I see clients calling release without checking what caused the 
> failure.

Yes, according to docs 
(https://docs.kernel.org/next/driver-api/firmware/request_firmware.html#request-firmware-api-expected-driver-use)

> 
> Thanks,
> Lijo
> 
>>>
>>> Thanks,
>>> Lijo
>>>
>>>> +    return err;
>>>> +}
>>>> +
>>>> +/*
>>>> + * amdgpu_ucode_release - Release firmware microcode
>>>> + *
>>>> + * @fw: pointer to firmware to release
>>>> + */
>>>> +void amdgpu_ucode_release(const struct firmware **fw)
>>>> +{
>>>> +    release_firmware(*fw);
>>>> +    *fw = NULL;
>>>> +}
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h 
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h
>>>> index 552e06929229..848579d4988b 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h
>>>> @@ -544,6 +544,9 @@ void amdgpu_ucode_print_sdma_hdr(const struct 
>>>> common_firmware_header *hdr);
>>>>   void amdgpu_ucode_print_psp_hdr(const struct 
>>>> common_firmware_header *hdr);
>>>>   void amdgpu_ucode_print_gpu_info_hdr(const struct 
>>>> common_firmware_header *hdr);
>>>>   int amdgpu_ucode_validate(const struct firmware *fw);
>>>> +int amdgpu_ucode_request(struct amdgpu_device *adev, const struct 
>>>> firmware **fw,
>>>> +             const char *fw_name);
>>>> +void amdgpu_ucode_release(const struct firmware **fw);
>>>>   bool amdgpu_ucode_hdr_version(union amdgpu_firmware_header *hdr,
>>>>                   uint16_t hdr_major, uint16_t hdr_minor);
>>


  reply	other threads:[~2023-01-05  5:38 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-05  3:42 [PATCH v6 00/45] Recover from failure to probe GPU Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 01/45] drm/amd: Delay removal of the firmware framebuffer Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 02/45] drm/amd: Add a legacy mapping to "amdgpu_ucode_ip_version_decode" Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 03/45] drm/amd: Convert SMUv11 microcode to use `amdgpu_ucode_ip_version_decode` Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 04/45] drm/amd: Convert SMUv13 " Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 05/45] drm/amd: Add a new helper for loading/validating microcode Mario Limonciello
2023-01-05  5:07   ` Lazar, Lijo
2023-01-05  5:23     ` Mario Limonciello
2023-01-05  5:29       ` Lazar, Lijo
2023-01-05  5:37         ` Mario Limonciello [this message]
2023-01-05  3:42 ` [PATCH v6 06/45] drm/amd: Use `amdgpu_ucode_request` helper for SDMA Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 07/45] drm/amd: Convert SDMA to use `amdgpu_ucode_ip_version_decode` Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 08/45] drm/amd: Make SDMA firmware load failures less noisy Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 09/45] drm/amd: Use `amdgpu_ucode_*` helpers for VCN Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 10/45] drm/amd: Load VCN microcode during early_init Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 11/45] drm/amd: Load MES " Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 12/45] drm/amd: Use `amdgpu_ucode_*` helpers for MES Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 13/45] drm/amd: Remove superfluous assignment for `adev->mes.adev` Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 14/45] drm/amd: Use `amdgpu_ucode_*` helpers for GFX9 Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 15/45] drm/amd: Load GFX9 microcode during early_init Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 16/45] drm/amd: Use `amdgpu_ucode_*` helpers for GFX10 Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 17/45] drm/amd: Load GFX10 microcode during early_init Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 18/45] drm/amd: Use `amdgpu_ucode_*` helpers for GFX11 Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 19/45] drm/amd: Load GFX11 microcode during early_init Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 20/45] drm/amd: Parse both v1 and v2 TA microcode headers using same function Mario Limonciello
2023-01-05 13:22   ` Lazar, Lijo
2023-01-05 16:04     ` Limonciello, Mario
2023-01-05  3:42 ` [PATCH v6 21/45] drm/amd: Avoid BUG() for case of SRIOV missing IP version Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 22/45] drm/amd: Load PSP microcode during early_init Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 23/45] drm/amd: Use `amdgpu_ucode_*` helpers for PSP Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 24/45] drm/amd/display: Load DMUB microcode during early_init Mario Limonciello
2023-01-05  3:42 ` [PATCH v6 25/45] drm/amd: Use `amdgpu_ucode_release` helper for DMUB Mario Limonciello
2023-01-05 17:17   ` Harry Wentland
2023-01-05  3:43 ` [PATCH v6 26/45] drm/amd: Use `amdgpu_ucode_*` helpers for SMU Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 27/45] drm/amd: Load SMU microcode during early_init Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 28/45] drm/amd: Optimize SRIOV switch/case for PSP microcode load Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 29/45] drm/amd: Use `amdgpu_ucode_*` helpers for GFX6 Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 30/45] drm/amd: Use `amdgpu_ucode_*` helpers for GFX7 Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 31/45] drm/amd: Use `amdgpu_ucode_*` helpers for GFX8 Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 32/45] drm/amd: Use `amdgpu_ucode_*` helpers for GMC6 Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 33/45] drm/amd: Use `amdgpu_ucode_*` helpers for GMC7 Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 34/45] drm/amd: Use `amdgpu_ucode_*` helpers for GMC8 Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 35/45] drm/amd: Use `amdgpu_ucode_*` helpers for SDMA2.4 Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 36/45] drm/amd: Use `amdgpu_ucode_*` helpers for SDMA3.0 Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 37/45] drm/amd: Use `amdgpu_ucode_*` helpers for SDMA on CIK Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 38/45] drm/amd: Use `amdgpu_ucode_*` helpers for UVD Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 39/45] drm/amd: Use `amdgpu_ucode_*` helpers for VCE Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 40/45] drm/amd: Use `amdgpu_ucode_*` helpers for CGS Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 41/45] drm/amd: Use `amdgpu_ucode_*` helpers for GPU info bin Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 42/45] drm/amd: Use `amdgpu_ucode_*` helpers for DMCU Mario Limonciello
2023-01-05 17:18   ` Harry Wentland
2023-01-05  3:43 ` [PATCH v6 43/45] drm/amd: Use `amdgpu_ucode_release` helper for powerplay Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 44/45] drm/amd: Use `amdgpu_ucode_release` helper for si Mario Limonciello
2023-01-05  3:43 ` [PATCH v6 45/45] drm/amd: make amdgpu_ucode_validate static Mario Limonciello

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1cc650c7-3bdb-6571-ee79-3bcd7affafc5@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=csoriano@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=javierm@redhat.com \
    --cc=lijo.lazar@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox