From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH 2/2] kvm-unit-tests: VMX: Test cases for nested EPT Date: Mon, 09 Sep 2013 16:26:58 +0200 Message-ID: <522DDAB2.9020900@redhat.com> References: <1378702644-23655-1-git-send-email-yzt356@gmail.com> <1378702644-23655-3-git-send-email-yzt356@gmail.com> <522DD3A7.5090100@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: kvm , Jan Kiszka , Gleb Natapov To: Arthur Chunqi Li Return-path: Received: from mx1.redhat.com ([209.132.183.28]:57614 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753445Ab3IIO0z (ORCPT ); Mon, 9 Sep 2013 10:26:55 -0400 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: Il 09/09/2013 16:11, Arthur Chunqi Li ha scritto: >>> >> +volatile u32 stage; >>> >> +volatile bool init_fail; >> > >> > Why volatile? > Because init_fail is only set but not used later in ept_init(), and if > I don't add volatile, compiler may optimize the setting to init_fail. > > This occasion firstly occurred when I write set_stage/get_stage. If > one variant is set in a function but not used later, the compiler > usually optimizes this setting as redundant assignment and remove it. No, the two are different. "stage" is written several times in the same function, with no code in the middle: stage++; *p = 1; stage++; To the compiler, the first store is dead. The compiler doesn't know that "*p = 1" traps to the hypervisor. But this is not the case for "init_fail". Paolo