From: "Ertman, David M" <david.m.ertman@intel.com>
To: ivecera <ivecera@redhat.com>, mschmidt <mschmidt@redhat.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
poros <poros@redhat.com>,
"Brandeburg, Jesse" <jesse.brandeburg@intel.com>,
"Nguyen, Anthony L" <anthony.l.nguyen@intel.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
"Saleem, Shiraz" <shiraz.saleem@intel.com>,
"moderated list:INTEL ETHERNET DRIVERS"
<intel-wired-lan@lists.osuosl.org>,
open list <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH net] ice: Fix race during aux device (un)plugging
Date: Fri, 15 Apr 2022 17:53:44 +0000 [thread overview]
Message-ID: <MW5PR11MB5811D6D5245206C5A37B803DDDEE9@MW5PR11MB5811.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20220415174932.6c85d5ab@ceranb>
> -----Original Message-----
> From: Ivan Vecera <ivecera@redhat.com>
> Sent: Friday, April 15, 2022 8:50 AM
> To: mschmidt <mschmidt@redhat.com>
> Cc: netdev@vger.kernel.org; poros <poros@redhat.com>; Brandeburg,
> Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; David S. Miller <davem@davemloft.net>;
> Jakub Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>;
> Saleem, Shiraz <shiraz.saleem@intel.com>; Ertman, David M
> <david.m.ertman@intel.com>; moderated list:INTEL ETHERNET DRIVERS
> <intel-wired-lan@lists.osuosl.org>; open list <linux-kernel@vger.kernel.org>
> Subject: Re: [PATCH net] ice: Fix race during aux device (un)plugging
>
> On Fri, 15 Apr 2022 13:12:03 +0200
> Michal Schmidt <mschmidt@redhat.com> wrote:
>
> > On Thu, Apr 14, 2022 at 6:39 PM Ivan Vecera <ivecera@redhat.com> wrote:
> >
> > > Function ice_plug_aux_dev() assigns pf->adev field too early prior
> > > aux device initialization and on other side ice_unplug_aux_dev()
> > > starts aux device deinit and at the end assigns NULL to pf->adev.
> > > This is wrong and can causes a crash when ice_send_event_to_aux()
> > > call occurs during these operations because that function depends
> > > on non-NULL value of pf->adev and does not assume that aux device
> > > is half-initialized or half-destroyed.
> > >
> > > Modify affected functions so pf->adev field is set after aux device
> > > init and prior aux device destroy.
> > >
> > [...]
> >
> > > @@ -320,12 +319,14 @@ int ice_plug_aux_dev(struct ice_pf *pf)
> > > */
> > > void ice_unplug_aux_dev(struct ice_pf *pf)
> > > {
> > > - if (!pf->adev)
> > > + struct auxiliary_device *adev = pf->adev;
> > > +
> > > + if (!adev)
> > > return;
> > >
> > > - auxiliary_device_delete(pf->adev);
> > > - auxiliary_device_uninit(pf->adev);
> > > pf->adev = NULL;
> > > + auxiliary_device_delete(adev);
> > > + auxiliary_device_uninit(adev);
> > > }
> > >
> >
> > Hi Ivan,
> > What prevents ice_unplug_aux_dev() from running immediately after
> > ice_send_event_to_aux() gets past its "if (!pf->adev)" test ?
> > Michal
>
> ice_send_event_to_aux() takes aux device lock. ice_unplug_aux_dev()
> calls auxiliary_device_delete() that calls device_del(). device_del()
> takes device_lock() prior kill_device(). So if ice_send_event_to_aux()
> is in progress then device_del() waits for its completion.
>
> Thanks,
> Ivan
Thanks for the patch Ivan!
Reviewed-by: Dave Ertman <david.m.ertman@intel.com>
WARNING: multiple messages have this Message-ID (diff)
From: Ertman, David M <david.m.ertman@intel.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [PATCH net] ice: Fix race during aux device (un)plugging
Date: Fri, 15 Apr 2022 17:53:44 +0000 [thread overview]
Message-ID: <MW5PR11MB5811D6D5245206C5A37B803DDDEE9@MW5PR11MB5811.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20220415174932.6c85d5ab@ceranb>
> -----Original Message-----
> From: Ivan Vecera <ivecera@redhat.com>
> Sent: Friday, April 15, 2022 8:50 AM
> To: mschmidt <mschmidt@redhat.com>
> Cc: netdev at vger.kernel.org; poros <poros@redhat.com>; Brandeburg,
> Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; David S. Miller <davem@davemloft.net>;
> Jakub Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>;
> Saleem, Shiraz <shiraz.saleem@intel.com>; Ertman, David M
> <david.m.ertman@intel.com>; moderated list:INTEL ETHERNET DRIVERS
> <intel-wired-lan@lists.osuosl.org>; open list <linux-kernel@vger.kernel.org>
> Subject: Re: [PATCH net] ice: Fix race during aux device (un)plugging
>
> On Fri, 15 Apr 2022 13:12:03 +0200
> Michal Schmidt <mschmidt@redhat.com> wrote:
>
> > On Thu, Apr 14, 2022 at 6:39 PM Ivan Vecera <ivecera@redhat.com> wrote:
> >
> > > Function ice_plug_aux_dev() assigns pf->adev field too early prior
> > > aux device initialization and on other side ice_unplug_aux_dev()
> > > starts aux device deinit and at the end assigns NULL to pf->adev.
> > > This is wrong and can causes a crash when ice_send_event_to_aux()
> > > call occurs during these operations because that function depends
> > > on non-NULL value of pf->adev and does not assume that aux device
> > > is half-initialized or half-destroyed.
> > >
> > > Modify affected functions so pf->adev field is set after aux device
> > > init and prior aux device destroy.
> > >
> > [...]
> >
> > > @@ -320,12 +319,14 @@ int ice_plug_aux_dev(struct ice_pf *pf)
> > > */
> > > void ice_unplug_aux_dev(struct ice_pf *pf)
> > > {
> > > - if (!pf->adev)
> > > + struct auxiliary_device *adev = pf->adev;
> > > +
> > > + if (!adev)
> > > return;
> > >
> > > - auxiliary_device_delete(pf->adev);
> > > - auxiliary_device_uninit(pf->adev);
> > > pf->adev = NULL;
> > > + auxiliary_device_delete(adev);
> > > + auxiliary_device_uninit(adev);
> > > }
> > >
> >
> > Hi Ivan,
> > What prevents ice_unplug_aux_dev() from running immediately after
> > ice_send_event_to_aux() gets past its "if (!pf->adev)" test ?
> > Michal
>
> ice_send_event_to_aux() takes aux device lock. ice_unplug_aux_dev()
> calls auxiliary_device_delete() that calls device_del(). device_del()
> takes device_lock() prior kill_device(). So if ice_send_event_to_aux()
> is in progress then device_del() waits for its completion.
>
> Thanks,
> Ivan
Thanks for the patch Ivan!
Reviewed-by: Dave Ertman <david.m.ertman@intel.com>
next prev parent reply other threads:[~2022-04-15 17:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-14 16:39 [PATCH net] ice: Fix race during aux device (un)plugging Ivan Vecera
2022-04-14 16:39 ` [Intel-wired-lan] " Ivan Vecera
2022-04-15 11:12 ` Michal Schmidt
2022-04-15 15:49 ` Ivan Vecera
2022-04-15 15:49 ` [Intel-wired-lan] " Ivan Vecera
2022-04-15 17:53 ` Ertman, David M [this message]
2022-04-15 17:53 ` Ertman, David M
2022-04-20 6:36 ` Leon Romanovsky
2022-04-20 6:36 ` [Intel-wired-lan] " Leon Romanovsky
2022-04-20 13:59 ` Ivan Vecera
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=MW5PR11MB5811D6D5245206C5A37B803DDDEE9@MW5PR11MB5811.namprd11.prod.outlook.com \
--to=david.m.ertman@intel.com \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=ivecera@redhat.com \
--cc=jesse.brandeburg@intel.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mschmidt@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=poros@redhat.com \
--cc=shiraz.saleem@intel.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.