public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicolin Chen <nicolinc@nvidia.com>
To: "Tian, Kevin" <kevin.tian@intel.com>
Cc: "jgg@nvidia.com" <jgg@nvidia.com>,
	"Liu, Yi L" <yi.l.liu@intel.com>,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iommufd/device: Enforce reserved IOVA also when attached to hwpt_nested
Date: Mon, 5 Aug 2024 20:55:40 -0700	[thread overview]
Message-ID: <ZrGevEpFCntQx6wV@Asurada-Nvidia> (raw)
In-Reply-To: <BN9PR11MB527682A9FBDDE82439A3F7E28CBF2@BN9PR11MB5276.namprd11.prod.outlook.com>

On Tue, Aug 06, 2024 at 02:59:53AM +0000, Tian, Kevin wrote:
> > From: Nicolin Chen <nicolinc@nvidia.com>
> > Sent: Tuesday, August 6, 2024 2:04 AM
> >
> > On Mon, Aug 05, 2024 at 07:40:45AM +0000, Tian, Kevin wrote:
> > > > From: Nicolin Chen <nicolinc@nvidia.com>
> > > > Sent: Friday, August 2, 2024 1:35 PM
> > > >
> > > >  static int
> > > > -iommufd_group_do_replace_paging(struct iommufd_group *igroup,
> > > > -                             struct iommufd_hwpt_paging *hwpt_paging)
> > > > +iommufd_group_do_replace_reserved_iova(struct iommufd_group
> > *igroup,
> > > > +                                    struct iommufd_hw_pagetable *hwpt)
> > > >  {
> > > > +     struct iommufd_hwpt_paging *hwpt_paging =
> > > > to_hwpt_paging(hwpt);
> > > >       struct iommufd_hw_pagetable *old_hwpt = igroup->hwpt;
> > > >       struct iommufd_device *cur;
> > > >       int rc;
> > > >
> > > >       lockdep_assert_held(&igroup->lock);
> > > >
> > > > -     if (!hwpt_is_paging(old_hwpt) ||
> > > > -         hwpt_paging->ioas != to_hwpt_paging(old_hwpt)->ioas) {
> > > > +     if (!hwpt_paging)
> > > > +             return 0;
> > > > +
> > > > +     if (iommufd_hw_pagetable_compare_ioas(old_hwpt, hwpt)) {
> > >
> > > hmm this change is broken. In this helper:
> > >
> > >         if (!old_hwpt_paging || !new_hwpt_paging)
> > >                 return false;
> > >         return old_hwpt_paging->ioas != new_hwpt_paging->ioas;
> > >
> > > Obviously the original code wants to enforce reserved regions if
> > > new_hwpt is paging && old_hwpt is not paging, but this change
> > > skips this scenario.
> >
> > Hmm..I think that is the intention of this patch?
> >
> > The original code does that because it didn't enforce reserved
> > region (to the parent paging hwpt) when attaching the group to
> > a nested one. Now, it does. So, we basically check whether the
> > associated ioas has changed or not. Right?
> >
> 
> that is too much tied to nested vs. paging type. In case a new
> type comes w/o parent/ioas in the future, above will be broken.
> 
> IMHO to_hwpt_paging() already resolves the problem about
> nested parent while the original code above appears to be
> more future proof (w/ the enhanced to_hwpt_paging()), i.e.
> adding reserved region to the new hwpt w/ ioas as long as
> old/new hwpts don't belong to a same ioas (including the case
> where old has no ioas), instead of adding reserved region
> only when both old/new have an ioas but different. 😊

Ah, I see your point. It failed to cover the case where one of
the hwpts returns NULL from to_hwpt_paging().

Will fix and respin.

Thanks
Nicolin

      reply	other threads:[~2024-08-06  3:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-02  5:34 [PATCH] iommufd/device: Enforce reserved IOVA also when attached to hwpt_nested Nicolin Chen
2024-08-05  7:40 ` Tian, Kevin
2024-08-05 18:03   ` Nicolin Chen
2024-08-06  2:59     ` Tian, Kevin
2024-08-06  3:55       ` Nicolin Chen [this message]

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=ZrGevEpFCntQx6wV@Asurada-Nvidia \
    --to=nicolinc@nvidia.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yi.l.liu@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox