From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Xu Subject: Re: [PATCH kvm-unit-tests 01/17] x86: intel-iommu: add vt-d init test Date: Tue, 8 Nov 2016 10:24:18 -0500 Message-ID: <20161108152418.GD2793@pxdev.xzpeter.org> References: <1477468040-21034-1-git-send-email-peterx@redhat.com> <1477468040-21034-2-git-send-email-peterx@redhat.com> <20161108105234.GG10472@agordeev.lab.eng.brq.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: kvm@vger.kernel.org, drjones@redhat.com, rkrcmar@redhat.com, jan.kiszka@web.de, pbonzini@redhat.com To: Alexander Gordeev Return-path: Received: from mx1.redhat.com ([209.132.183.28]:37500 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752174AbcKHPYV (ORCPT ); Tue, 8 Nov 2016 10:24:21 -0500 Content-Disposition: inline In-Reply-To: <20161108105234.GG10472@agordeev.lab.eng.brq.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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