Re: [PATCH kvm-unit-tests 01/17] x86: intel-iommu: add vt-d init test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 08, 2016 at 11:52:35AM +0100, Alexander Gordeev wrote:
> On Wed, Oct 26, 2016 at 03:47:04PM +0800, Peter Xu wrote:
> > +static inline void vtd_writel(unsigned int reg, uint32_t value)
> > +{
> > +	*(uint32_t *)(Q35_HOST_BRIDGE_IOMMU_ADDR + reg) = value;
> > +}
> > +
> > +static inline void vtd_writeq(unsigned int reg, uint64_t value)
> > +{
> > +	*(uint64_t *)(Q35_HOST_BRIDGE_IOMMU_ADDR + reg) = value;
> > +}
> > +
> > +static inline uint32_t vtd_readl(unsigned int reg)
> > +{
> > +	return *(uint32_t *)(Q35_HOST_BRIDGE_IOMMU_ADDR + reg);
> > +}
> > +
> > +static inline uint64_t vtd_readq(unsigned int reg)
> > +{
> > +	return *(uint64_t *)(Q35_HOST_BRIDGE_IOMMU_ADDR + reg);
> > +}
> 
> Is it safe to use memory dereference here?
> By contrast, Linux seems uses read*()/write*() accessors.

Looks like Linux is using memory barrior and volatile keywords to do
the protection (build_mmio_read() for x86). I think at least I can add
volatile here for each read/write to make it safer. Do you think
that'll suffice here? E.g.:

  static inline uint64_t vtd_readq(unsigned int reg)
  {
      return *(volatile uint64_t *)(Q35_HOST_BRIDGE_IOMMU_ADDR + reg);
  }

Thanks,

-- peterx
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux