All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: yi.l.liu@intel.com, yi.y.sun@linux.intel.com,
	qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [PATCH 2/3] intel-iommu: drop VTDBus
Date: Mon, 17 Jan 2022 09:27:03 +0800	[thread overview]
Message-ID: <YeTF58bY96CiFQsc@xz-m1.local> (raw)
In-Reply-To: <54f9372b-7a04-28db-5f27-0eafaf87d632@redhat.com>

On Fri, Jan 14, 2022 at 05:15:35PM +0800, Jason Wang wrote:
> 
> 在 2022/1/14 上午10:32, Jason Wang 写道:
> > > > dressSpace *as)
> > > >   /* GHashTable functions */
> > > >   static gboolean vtd_uint64_equal(gconstpointer v1, gconstpointer v2)
> > > >   {
> > > > -    return *((const uint64_t *)v1) == *((const uint64_t *)v2);
> > > > +    const struct vtd_as_key *key1 = v1;
> > > > +    const struct vtd_as_key *key2 = v2;
> > > > +
> > > > +    return (key1->bus == key2->bus) && (key1->devfn == key2->devfn);
> > > >   }
> > > >     static guint vtd_uint64_hash(gconstpointer v)
> > > >   {
> > > > -    return (guint)*(const uint64_t *)v;
> > > > +    const struct vtd_as_key *key = v;
> > > > +    guint value = (guint)(uintptr_t)key->bus;
> > > > +
> > > > +    return (guint)(value << 8 | key->devfn);
> > > Note that value is a pointer to PCIBus*.  Just want to check with
> > > you that it's
> > > intended to use this hash value (or maybe you wanted to use Source
> > > ID so it is
> > > bus number to use not the bus pointer)?
> > 
> > 
> > Right, SID should be used here.
> 
> 
> Sorry for taking too long for the context switching ...
> 
> The hash and shift based the bus pointer is intended since we use bus
> pointer as part of the key. The reason is still, during vtd_find_add_as(),
> SID is not correct since guest might not finish the initialization of the
> device and PCI bridge.

Ah, right.

However here value is left-shifted 8 bits so I'm not sure how it could
guarantee no collision - logically any addresses that match lower 56 bits will
hit with the same devfn by accident.

I don't think it'll matter in reality, but... wondering whether it's easier to
simply use g_direct_hash() (the glibc provided hash function when hash==NULL is
passed over, IOW we simply pass hash_func=NULL for g_hash_table_new) so we'll
hash with struct vtd_as_key* instead; IMHO that'll suffice too.

Thanks,

-- 
Peter Xu



  reply	other threads:[~2022-01-17  1:29 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05  4:19 [PATCH 0/3] PASID support for Intel IOMMU Jason Wang
2022-01-05  4:19 ` [PATCH] intel-iommu: correctly check passthrough during translation Jason Wang
2022-01-05  4:19 ` [PATCH 1/3] intel-iommu: don't warn guest errors when getting rid2pasid entry Jason Wang
2022-01-13  3:35   ` Peter Xu
2022-01-13  6:16     ` Jason Wang
2022-01-13  6:32       ` Peter Xu
2022-01-13  7:05     ` Michael S. Tsirkin
2022-01-14  3:02       ` Jason Wang
2022-01-13  7:06   ` Michael S. Tsirkin
2022-01-14  2:56     ` Jason Wang
2022-01-05  4:19 ` [PATCH 2/3] intel-iommu: drop VTDBus Jason Wang
2022-01-13  4:12   ` Peter Xu
2022-01-14  2:32     ` Jason Wang
2022-01-14  9:15       ` Jason Wang
2022-01-17  1:27         ` Peter Xu [this message]
2022-01-17  1:42           ` Peter Xu
2022-01-05  4:19 ` [PATCH 3/3] intel-iommu: PASID support Jason Wang
2022-01-13  5:06   ` Peter Xu
2022-01-13  7:16     ` Michael S. Tsirkin
2022-01-14  2:47     ` Jason Wang
2022-01-14  3:31       ` Peter Xu
2022-01-14  5:58         ` Jason Wang
2022-01-14  7:13           ` Peter Xu
2022-01-14  7:22             ` Jason Wang
2022-01-14  7:45               ` Peter Xu
2022-01-14  9:12                 ` Jason Wang
2022-01-14 12:58               ` Liu Yi L
2022-01-17  6:01                 ` Jason Wang

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=YeTF58bY96CiFQsc@xz-m1.local \
    --to=peterx@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yi.l.liu@intel.com \
    --cc=yi.y.sun@linux.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.