From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYfAn-0001ng-Le for qemu-devel@nongnu.org; Thu, 19 Mar 2015 14:28:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYfAk-0002t2-FW for qemu-devel@nongnu.org; Thu, 19 Mar 2015 14:28:01 -0400 Received: from mail-qg0-f49.google.com ([209.85.192.49]:35994) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYfAk-0002sr-C7 for qemu-devel@nongnu.org; Thu, 19 Mar 2015 14:27:58 -0400 Received: by qgf3 with SMTP id 3so72850891qgf.3 for ; Thu, 19 Mar 2015 11:27:57 -0700 (PDT) Date: Thu, 19 Mar 2015 14:27:55 -0400 From: Kevin O'Connor Message-ID: <20150319182755.GA890@morn.localdomain> References: <1426515305-17766-1-git-send-email-somlo@cmu.edu> <1426515305-17766-7-git-send-email-somlo@cmu.edu> <5508202E.7020700@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5508202E.7020700@redhat.com> Subject: Re: [Qemu-devel] [PATCH 6/6] qga: RFC: guest-side retrieval of fw_cfg file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laszlo Ersek Cc: matt.fleming@intel.com, mdroth@linux.vnet.ibm.com, rjones@redhat.com, jordan.l.justen@intel.com, "Gabriel L. Somlo" , gleb@cloudius-systems.com, qemu-devel@nongnu.org, gsomlo@gmail.com, kraxel@redhat.com, pbonzini@redhat.com On Tue, Mar 17, 2015 at 01:38:06PM +0100, Laszlo Ersek wrote: > On 03/16/15 15:15, Gabriel L. Somlo wrote: > > 1. I can't for the life of me figure out how to stop gcc -O2 > > from assuming the if() test below is ALWAYS FALSE, and thus > > optimizing it out completely. For now I've forced -O0 on > > the entire function, but for some reason fw_cfg_read(&fcfile, ...) > > does not appear to count as potentially modifying fcfile... [...] > > +static void > > +fw_cfg_read(void *buf, int len) > > +{ > > + insb(PORT_FW_CFG_DATA, buf, len); > > +} [...] > I think fw_cfg_read() is inlined under -O2, and the insb() from that > function is somehow confusing gcc. > > From "/usr/include/sys/io.h", on my RHEL-7.1 laptop: > > static __inline void > insb (unsigned short int __port, void *__addr, unsigned long int __count) > { > __asm__ __volatile__ ("cld ; rep ; insb":"=D" (__addr), "=c" (__count) > :"d" (__port), "0" (__addr), "1" (__count)); > } My read of this is that gcc knows it must emit the instruction, and it knows that __addr and __count can change. But, it doesn't know that the memory at *__addr can change. I'd see if a barrier() fixes it. See the section on "clobber" at: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html In particular: You can use a trick to avoid this if the size of the memory being accessed is known at compile time. For example, if accessing ten bytes of a string, use a memory input like: {"m"( ({ struct { char x[10]; } *p = (void *)ptr ; *p; }) )}. -Kevin