All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Chen <Wei.Chen@arm.com>
To: Stefano Stabellini <sstabellini@kernel.org>
Cc: Kaly Xin <Kaly.Xin@arm.com>, Julien Grall <Julien.Grall@arm.com>,
	nd <nd@arm.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>,
	Steve Capper <Steve.Capper@arm.com>
Subject: Re: [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings
Date: Thu, 6 Jul 2017 02:45:12 +0000	[thread overview]
Message-ID: <DB3PR08MB0107E4903E4DD9C68B9ACC359ED50@DB3PR08MB0107.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1707051109460.2919@sstabellini-ThinkPad-X260>



> -----Original Message-----
> From: Stefano Stabellini [mailto:sstabellini@kernel.org]
> Sent: 2017年7月6日 2:15
> To: Wei Chen <Wei.Chen@arm.com>
> Cc: Julien Grall <Julien.Grall@arm.com>; Stefano Stabellini
> <sstabellini@kernel.org>; Kaly Xin <Kaly.Xin@arm.com>; nd <nd@arm.com>; Steve
> Capper <Steve.Capper@arm.com>; xen-devel@lists.xen.org
> Subject: Re: [Xen-devel] [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU
> bindings
> 
> On Wed, 5 Jul 2017, Wei Chen wrote:
> > > >> > +static int arm_smmu_of_xlate(struct device *dev, struct
> of_phandle_args
> > > >> *args)
> > > >> > +{
> > > >> > +   struct arm_smmu_device *smmu;
> > > >> > +   u32 mask = 0, fwid = 0;
> > > >> > +
> > > >> > +   smmu = find_smmu(dt_to_dev(args->np));
> > > >> > +   if (!smmu) {
> > > >> > +           dev_err(dev, "Could not find smmu device!\n");
> > > >> > +           return -ENODEV;
> > > >> > +   }
> > > >> > +
> > > >> > +   if (args->args_count > 0)
> > > >> > +           fwid |= (u16)args->args[0];
> > > >> > +
> > > >> > +   if (args->args_count > 1)
> > > >> > +           fwid |= (u16)args->args[1] << SMR_MASK_SHIFT;
> > > >> > +   else if (!of_property_read_u32(args->np, "stream-match-mask",
> &mask))
> > > >> > +           fwid |= (u16)mask << SMR_MASK_SHIFT;
> > > >> > +   dev_dbg(dev, "%s fwid:%08x mask:%08x args_count:%d\n",
> > > >> > +                      args->np->full_name, fwid,
> > > >> > +                      mask, args->args_count);
> > > >>
> > > >> I don't understand why fwid is declared as u32 but used as a u16 below.
> > > >> Shouldn't it be declared as u16 in the first place?
> > > >>
> > > >
> > > > Oh, it's my mistake. In Linux, the fwid will be passed to
> > > > iommu_fwspec_add_ids,
> > > > it requires u32 parameter. But after I ported this code to Xen, we
> passed
> > > > the fwid to arm_smmu_add_generic_master_id, a u16 parameter is enough
> > > u16 is not enough. If you look at the code you ported:
> > >
> > > if (args->args_count > 0)
> > >    fwid |= (u16)args->args[0];
> > >
> > > if (!of_property_read_u32(args->np, "stream-match-mask", &mask)
> > >    fwid |= mask << SMR_MASK_SHIFT;
> > >
> > > SMR_MASK_SHIFT is 16, so the top 16-bit will be set to the mask. With
> > > your u16 cast you loose those bits and therefore will not support
> > > properly SMMU when the property "stream-match-mask" has been set.
> > >
> >
> > Yes, that's the reason why we use u32. Thanks for your reminder,
> > Although the master->cfg.streamids is using u16, we'd better to keep
> > U32 here and add a warning message to notice whom set "stream-match-mask"
> 
> Even if you are using a u32 for fwid, you are still losing all the top
> 16 bits in the operations above because of the (u16) casts. This code
> looks wrong.

I think it's better to change the
arm_smmu_add_generic_master_id(..., u16 fwid)
to
arm_smmu_add_generic_master_id(..., u32 fwid). And keep the fwid in arm_smmu_of_xlate
to u32 to guarantee the data integrity from device tree. Let arm_smmu_add_generic_master_id
to determine whether to drop top 16-bits or not.



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2017-07-06  2:45 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-30  3:15 [PATCH 0/7] Generic IOMMU bindings support for Xen platform devices Wei Chen
2017-06-30  3:15 ` [PATCH 1/7] xen/arm: SMMU: Implement the add_device callback in SMMU Wei Chen
2017-07-03 21:58   ` Stefano Stabellini
2017-07-04  5:37     ` Wei Chen
2017-07-05 17:57       ` Stefano Stabellini
2017-07-06  2:16         ` Wei Chen
2017-07-04 15:40   ` Julien Grall
2017-07-05  7:06     ` Wei Chen
2017-06-30  3:15 ` [PATCH 2/7] xen/arm: SMMU: Introduce a helper to add DT device to SMMU Wei Chen
2017-07-03 22:02   ` Stefano Stabellini
2017-07-04  5:45     ` Wei Chen
2017-07-05 18:02       ` Stefano Stabellini
2017-07-06  2:20         ` Wei Chen
2017-06-30  3:15 ` [PATCH 3/7] xen/arm: Prepare SMMU resources for protected devices Wei Chen
2017-07-03 22:05   ` Stefano Stabellini
2017-06-30  3:15 ` [PATCH 4/7] xen/arm: SMMU: Detect types of device tree binding Wei Chen
2017-07-03 22:30   ` Stefano Stabellini
2017-07-04  6:20     ` Wei Chen
2017-07-05 18:08       ` Stefano Stabellini
2017-07-06  2:25         ` Wei Chen
2017-06-30  3:15 ` [PATCH 5/7] xen/arm: SMMU: Keep registering legacy master in SMMU probe Wei Chen
2017-07-03 22:32   ` Stefano Stabellini
2017-06-30  3:15 ` [PATCH 6/7] xen/arm: SMMU: Support generic IOMMU bindings Wei Chen
2017-07-03 22:59   ` Stefano Stabellini
2017-07-04  6:27     ` Wei Chen
2017-07-04  7:26       ` Julien Grall
2017-07-05  7:04         ` Wei Chen
2017-07-05 13:07           ` Julien Grall
2017-07-06  2:11             ` Wei Chen
2017-07-05 18:15           ` Stefano Stabellini
2017-07-06  2:45             ` Wei Chen [this message]
2017-06-30  3:15 ` [PATCH 7/7] xen: Fix a typo in error message of iommu_do_dt_domctl Wei Chen
2017-07-03 21:53   ` Stefano Stabellini

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=DB3PR08MB0107E4903E4DD9C68B9ACC359ED50@DB3PR08MB0107.eurprd08.prod.outlook.com \
    --to=wei.chen@arm.com \
    --cc=Julien.Grall@arm.com \
    --cc=Kaly.Xin@arm.com \
    --cc=Steve.Capper@arm.com \
    --cc=nd@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xen.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 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.