All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Deucher <alexdeucher@gmail.com>
To: "Lazar, Lijo" <Lijo.Lazar@amd.com>
Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"Koenig, Christian" <Christian.Koenig@amd.com>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
	"yangyingliang@huawei.com" <yangyingliang@huawei.com>,
	"Deucher, Alexander" <Alexander.Deucher@amd.com>,
	Xiongfeng Wang <wangxiongfeng2@huawei.com>,
	"Zhang, Hawking" <Hawking.Zhang@amd.com>
Subject: Re: [PATCH 1/2] drm/radeon: Fix PCI device refcount leak in radeon_atrm_get_bios()
Date: Tue, 22 Nov 2022 12:13:17 -0500	[thread overview]
Message-ID: <CADnq5_OscVZFbys1Y0Qmm6i0V+Ogk5BjgzUesw0Veo6WxY=7+A@mail.gmail.com> (raw)
In-Reply-To: <BYAPR12MB46142113C29D75B8E0251926970D9@BYAPR12MB4614.namprd12.prod.outlook.com>

On Tue, Nov 22, 2022 at 12:10 PM Lazar, Lijo <Lijo.Lazar@amd.com> wrote:
>
> [AMD Official Use Only - General]
>
> When only second GPU has valid ATRM handle -
> then it stays inside the loop and in the next call to pci_get_class(), it passes pdev reference to first GPU as the "from" param. That time it drops the reference count of "from" device.

ah, right, that was the part I missed.  Thanks.

Alex


>
> Thanks,
> Lijo
> ________________________________
> From: Alex Deucher <alexdeucher@gmail.com>
> Sent: Tuesday, November 22, 2022 9:55:33 PM
> To: Lazar, Lijo <Lijo.Lazar@amd.com>
> Cc: Xiongfeng Wang <wangxiongfeng2@huawei.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; Pan, Xinhui <Xinhui.Pan@amd.com>; airlied@gmail.com <airlied@gmail.com>; daniel@ffwll.ch <daniel@ffwll.ch>; Zhang, Hawking <Hawking.Zhang@amd.com>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; yangyingliang@huawei.com <yangyingliang@huawei.com>
> Subject: Re: [PATCH 1/2] drm/radeon: Fix PCI device refcount leak in radeon_atrm_get_bios()
>
> On Tue, Nov 22, 2022 at 9:59 AM Lazar, Lijo <lijo.lazar@amd.com> wrote:
> >
> >
> >
> > On 11/22/2022 8:19 PM, Alex Deucher wrote:
> > > On Tue, Nov 22, 2022 at 6:12 AM Xiongfeng Wang
> > > <wangxiongfeng2@huawei.com> wrote:
> > >>
> > >> As comment of pci_get_class() says, it returns a pci_device with its
> > >> refcount increased and decreased the refcount for the input parameter
> > >> @from if it is not NULL.
> > >>
> > >> If we break the loop in radeon_atrm_get_bios() with 'pdev' not NULL, we
> > >> need to call pci_dev_put() to decrease the refcount. Add the missing
> > >> pci_dev_put() to avoid refcount leak.
> > >
> > > For both patches, I think pci_dev_put() needs to go into the loops.
> > > There are 2 or more GPUs on the systems where this is relevant.
> > >
> >
> > As per the logic, the loop breaks when it finds a valid ATRM handle. So
> > dev_put is required only for that device.
>
> Sure, but what if the handle is on the second DISPLAY_VGA or
> DISPLAY_OTHER class PCI device on the system?  We've already called
> pci_get_class() for the first PCI device that matched.
>
> Alex
>
> >
> > When inside the loop this happens -  "decreased the refcount for the
> > input parameter @from if it is not NULL"
> >
> > Thanks,
> > Lijo
> >
> > > Alex
> > >
> > >>
> > >> Fixes: d8ade3526b2a ("drm/radeon: handle non-VGA class pci devices with ATRM")
> > >> Fixes: c61e2775873f ("drm/radeon: split ATRM support out from the ATPX handler (v3)")
> > >> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> > >> ---
> > >>   drivers/gpu/drm/radeon/radeon_bios.c | 1 +
> > >>   1 file changed, 1 insertion(+)
> > >>
> > >> diff --git a/drivers/gpu/drm/radeon/radeon_bios.c b/drivers/gpu/drm/radeon/radeon_bios.c
> > >> index 33121655d50b..2df6ce3e32cb 100644
> > >> --- a/drivers/gpu/drm/radeon/radeon_bios.c
> > >> +++ b/drivers/gpu/drm/radeon/radeon_bios.c
> > >> @@ -227,6 +227,7 @@ static bool radeon_atrm_get_bios(struct radeon_device *rdev)
> > >>
> > >>          if (!found)
> > >>                  return false;
> > >> +       pci_dev_put(pdev);
> > >>
> > >>          rdev->bios = kmalloc(size, GFP_KERNEL);
> > >>          if (!rdev->bios) {
> > >> --
> > >> 2.20.1
> > >>

WARNING: multiple messages have this Message-ID (diff)
From: Alex Deucher <alexdeucher@gmail.com>
To: "Lazar, Lijo" <Lijo.Lazar@amd.com>
Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"Koenig, Christian" <Christian.Koenig@amd.com>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
	"daniel@ffwll.ch" <daniel@ffwll.ch>,
	"yangyingliang@huawei.com" <yangyingliang@huawei.com>,
	"Deucher, Alexander" <Alexander.Deucher@amd.com>,
	"airlied@gmail.com" <airlied@gmail.com>,
	Xiongfeng Wang <wangxiongfeng2@huawei.com>,
	"Zhang, Hawking" <Hawking.Zhang@amd.com>
Subject: Re: [PATCH 1/2] drm/radeon: Fix PCI device refcount leak in radeon_atrm_get_bios()
Date: Tue, 22 Nov 2022 12:13:17 -0500	[thread overview]
Message-ID: <CADnq5_OscVZFbys1Y0Qmm6i0V+Ogk5BjgzUesw0Veo6WxY=7+A@mail.gmail.com> (raw)
In-Reply-To: <BYAPR12MB46142113C29D75B8E0251926970D9@BYAPR12MB4614.namprd12.prod.outlook.com>

On Tue, Nov 22, 2022 at 12:10 PM Lazar, Lijo <Lijo.Lazar@amd.com> wrote:
>
> [AMD Official Use Only - General]
>
> When only second GPU has valid ATRM handle -
> then it stays inside the loop and in the next call to pci_get_class(), it passes pdev reference to first GPU as the "from" param. That time it drops the reference count of "from" device.

ah, right, that was the part I missed.  Thanks.

Alex


>
> Thanks,
> Lijo
> ________________________________
> From: Alex Deucher <alexdeucher@gmail.com>
> Sent: Tuesday, November 22, 2022 9:55:33 PM
> To: Lazar, Lijo <Lijo.Lazar@amd.com>
> Cc: Xiongfeng Wang <wangxiongfeng2@huawei.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; Pan, Xinhui <Xinhui.Pan@amd.com>; airlied@gmail.com <airlied@gmail.com>; daniel@ffwll.ch <daniel@ffwll.ch>; Zhang, Hawking <Hawking.Zhang@amd.com>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; yangyingliang@huawei.com <yangyingliang@huawei.com>
> Subject: Re: [PATCH 1/2] drm/radeon: Fix PCI device refcount leak in radeon_atrm_get_bios()
>
> On Tue, Nov 22, 2022 at 9:59 AM Lazar, Lijo <lijo.lazar@amd.com> wrote:
> >
> >
> >
> > On 11/22/2022 8:19 PM, Alex Deucher wrote:
> > > On Tue, Nov 22, 2022 at 6:12 AM Xiongfeng Wang
> > > <wangxiongfeng2@huawei.com> wrote:
> > >>
> > >> As comment of pci_get_class() says, it returns a pci_device with its
> > >> refcount increased and decreased the refcount for the input parameter
> > >> @from if it is not NULL.
> > >>
> > >> If we break the loop in radeon_atrm_get_bios() with 'pdev' not NULL, we
> > >> need to call pci_dev_put() to decrease the refcount. Add the missing
> > >> pci_dev_put() to avoid refcount leak.
> > >
> > > For both patches, I think pci_dev_put() needs to go into the loops.
> > > There are 2 or more GPUs on the systems where this is relevant.
> > >
> >
> > As per the logic, the loop breaks when it finds a valid ATRM handle. So
> > dev_put is required only for that device.
>
> Sure, but what if the handle is on the second DISPLAY_VGA or
> DISPLAY_OTHER class PCI device on the system?  We've already called
> pci_get_class() for the first PCI device that matched.
>
> Alex
>
> >
> > When inside the loop this happens -  "decreased the refcount for the
> > input parameter @from if it is not NULL"
> >
> > Thanks,
> > Lijo
> >
> > > Alex
> > >
> > >>
> > >> Fixes: d8ade3526b2a ("drm/radeon: handle non-VGA class pci devices with ATRM")
> > >> Fixes: c61e2775873f ("drm/radeon: split ATRM support out from the ATPX handler (v3)")
> > >> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> > >> ---
> > >>   drivers/gpu/drm/radeon/radeon_bios.c | 1 +
> > >>   1 file changed, 1 insertion(+)
> > >>
> > >> diff --git a/drivers/gpu/drm/radeon/radeon_bios.c b/drivers/gpu/drm/radeon/radeon_bios.c
> > >> index 33121655d50b..2df6ce3e32cb 100644
> > >> --- a/drivers/gpu/drm/radeon/radeon_bios.c
> > >> +++ b/drivers/gpu/drm/radeon/radeon_bios.c
> > >> @@ -227,6 +227,7 @@ static bool radeon_atrm_get_bios(struct radeon_device *rdev)
> > >>
> > >>          if (!found)
> > >>                  return false;
> > >> +       pci_dev_put(pdev);
> > >>
> > >>          rdev->bios = kmalloc(size, GFP_KERNEL);
> > >>          if (!rdev->bios) {
> > >> --
> > >> 2.20.1
> > >>

  reply	other threads:[~2022-11-22 17:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22 11:30 [PATCH 0/2] drm: Fix PCI device refcount leak Xiongfeng Wang
2022-11-22 11:30 ` [PATCH 1/2] drm/radeon: Fix PCI device refcount leak in radeon_atrm_get_bios() Xiongfeng Wang
2022-11-22 14:49   ` Alex Deucher
2022-11-22 14:49     ` Alex Deucher
2022-11-22 14:59     ` Lazar, Lijo
2022-11-22 14:59       ` Lazar, Lijo
2022-11-22 16:25       ` Alex Deucher
2022-11-22 16:25         ` Alex Deucher
2022-11-22 17:10         ` Lazar, Lijo
2022-11-22 17:10           ` Lazar, Lijo
2022-11-22 17:13           ` Alex Deucher [this message]
2022-11-22 17:13             ` Alex Deucher
2022-11-22 11:30 ` [PATCH 2/2] drm/amdgpu: Fix PCI device refcount leak in amdgpu_atrm_get_bios() Xiongfeng Wang
2022-11-25 18:37   ` Alex Deucher
2022-11-25 18:37     ` Alex Deucher

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='CADnq5_OscVZFbys1Y0Qmm6i0V+Ogk5BjgzUesw0Veo6WxY=7+A@mail.gmail.com' \
    --to=alexdeucher@gmail.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Hawking.Zhang@amd.com \
    --cc=Lijo.Lazar@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=wangxiongfeng2@huawei.com \
    --cc=yangyingliang@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.