From nobody Fri Dec 19 19:00:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50F1FC07E9D for ; Mon, 26 Sep 2022 11:07:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237372AbiIZLHO (ORCPT ); Mon, 26 Sep 2022 07:07:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237285AbiIZLGF (ORCPT ); Mon, 26 Sep 2022 07:06:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C27E25FAE6; Mon, 26 Sep 2022 03:34:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8FC8560B60; Mon, 26 Sep 2022 10:34:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3173C433C1; Mon, 26 Sep 2022 10:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188442; bh=bEG1wB8DvJkxliAXC/3pG7EJWLwc643+H5xuX8YcoXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e90pzbqZT0r5DJKuJlBCwIEQ1za+zRz/TSe3B516/PAhTh9Sf8lWnUl4rMKFjYFa2 sIpV+eBoXu8pV1/Kg+GOiitimqZREvjQhx32KCnFPOAPjYdOcg6pZ+s6U9vJfxuF/V dcbch/t/x4OaZGn8x6NuDgbgoO8WUbIRT9ITlP5I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Victor Skvortsov , Alex Deucher , Sasha Levin Subject: [PATCH 5.15 001/148] drm/amdgpu: Separate vf2pf work item init from virt data exchange Date: Mon, 26 Sep 2022 12:10:35 +0200 Message-Id: <20220926100756.125894060@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100756.074519146@linuxfoundation.org> References: <20220926100756.074519146@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Victor Skvortsov [ Upstream commit 892deb48269c65376f3eeb5b4c032ff2c2979bd7 ] We want to be able to call virt data exchange conditionally after gmc sw init to reserve bad pages as early as possible. Since this is a conditional call, we will need to call it again unconditionally later in the init sequence. Refactor the data exchange function so it can be called multiple times without re-initializing the work item. v2: Cleaned up the code. Kept the original call to init_exchange_data() inside early init to initialize the work item, afterwards call exchange_data() when needed. Signed-off-by: Victor Skvortsov Reviewed By: Shaoyun.liu Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 36 ++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h | 1 + 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/a= md/amdgpu/amdgpu_device.c index d1af709cc7dc..f443b4630f9d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -2390,6 +2390,10 @@ static int amdgpu_device_ip_init(struct amdgpu_devic= e *adev) =20 /* need to do gmc hw init early so we can allocate gpu mem */ if (adev->ip_blocks[i].version->type =3D=3D AMD_IP_BLOCK_TYPE_GMC) { + /* Try to reserve bad pages early */ + if (amdgpu_sriov_vf(adev)) + amdgpu_virt_exchange_data(adev); + r =3D amdgpu_device_vram_scratch_init(adev); if (r) { DRM_ERROR("amdgpu_vram_scratch_init failed %d\n", r); @@ -2421,7 +2425,7 @@ static int amdgpu_device_ip_init(struct amdgpu_device= *adev) } =20 if (amdgpu_sriov_vf(adev)) - amdgpu_virt_init_data_exchange(adev); + amdgpu_virt_exchange_data(adev); =20 r =3D amdgpu_ib_pool_init(adev); if (r) { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd= /amdgpu/amdgpu_virt.c index 16787c675f35..cce03aad5f0e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c @@ -614,17 +614,35 @@ void amdgpu_virt_fini_data_exchange(struct amdgpu_dev= ice *adev) =20 void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev) { - uint64_t bp_block_offset =3D 0; - uint32_t bp_block_size =3D 0; - struct amd_sriov_msg_pf2vf_info *pf2vf_v2 =3D NULL; - adev->virt.fw_reserve.p_pf2vf =3D NULL; adev->virt.fw_reserve.p_vf2pf =3D NULL; adev->virt.vf2pf_update_interval_ms =3D 0; =20 - if (adev->mman.fw_vram_usage_va !=3D NULL) { + if (adev->bios !=3D NULL) { adev->virt.vf2pf_update_interval_ms =3D 2000; =20 + adev->virt.fw_reserve.p_pf2vf =3D + (struct amd_sriov_msg_pf2vf_info_header *) + (adev->bios + (AMD_SRIOV_MSG_PF2VF_OFFSET_KB << 10)); + + amdgpu_virt_read_pf2vf_data(adev); + } + + if (adev->virt.vf2pf_update_interval_ms !=3D 0) { + INIT_DELAYED_WORK(&adev->virt.vf2pf_work, amdgpu_virt_update_vf2pf_work_= item); + schedule_delayed_work(&(adev->virt.vf2pf_work), msecs_to_jiffies(adev->v= irt.vf2pf_update_interval_ms)); + } +} + + +void amdgpu_virt_exchange_data(struct amdgpu_device *adev) +{ + uint64_t bp_block_offset =3D 0; + uint32_t bp_block_size =3D 0; + struct amd_sriov_msg_pf2vf_info *pf2vf_v2 =3D NULL; + + if (adev->mman.fw_vram_usage_va !=3D NULL) { + adev->virt.fw_reserve.p_pf2vf =3D (struct amd_sriov_msg_pf2vf_info_header *) (adev->mman.fw_vram_usage_va + (AMD_SRIOV_MSG_PF2VF_OFFSET_KB << 10)); @@ -655,16 +673,10 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_dev= ice *adev) (adev->bios + (AMD_SRIOV_MSG_PF2VF_OFFSET_KB << 10)); =20 amdgpu_virt_read_pf2vf_data(adev); - - return; - } - - if (adev->virt.vf2pf_update_interval_ms !=3D 0) { - INIT_DELAYED_WORK(&adev->virt.vf2pf_work, amdgpu_virt_update_vf2pf_work_= item); - schedule_delayed_work(&(adev->virt.vf2pf_work), adev->virt.vf2pf_update_= interval_ms); } } =20 + void amdgpu_detect_virtualization(struct amdgpu_device *adev) { uint32_t reg; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h b/drivers/gpu/drm/amd= /amdgpu/amdgpu_virt.h index 8d4c20bb71c5..9adfb8d63280 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h @@ -308,6 +308,7 @@ int amdgpu_virt_alloc_mm_table(struct amdgpu_device *ad= ev); void amdgpu_virt_free_mm_table(struct amdgpu_device *adev); void amdgpu_virt_release_ras_err_handler_data(struct amdgpu_device *adev); void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev); +void amdgpu_virt_exchange_data(struct amdgpu_device *adev); void amdgpu_virt_fini_data_exchange(struct amdgpu_device *adev); void amdgpu_detect_virtualization(struct amdgpu_device *adev); =20 --=20 2.35.1