From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH 07/15] KVM: MTRR: improve kvm_mtrr_get_guest_memory_type Date: Wed, 03 Jun 2015 09:57:16 +0200 Message-ID: <556EB35C.6040601@redhat.com> References: <1432983566-15773-1-git-send-email-guangrong.xiao@linux.intel.com> <1432983566-15773-8-git-send-email-guangrong.xiao@linux.intel.com> <556C22FC.50505@redhat.com> <556E6270.2060701@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: gleb@kernel.org, mtosatti@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org To: Xiao Guangrong Return-path: In-Reply-To: <556E6270.2060701@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 03/06/2015 04:12, Xiao Guangrong wrote: >> >> Perhaps just use type = MIN(type, curr_type), which also happens to get >> WT vs. WB right? You can also add a >> >> BUILD_BUG_ON(MTRR_TYPE_WRTHROUGH > MTRR_TYPE_WRBACK); >> >> to ensure that the WT vs. WB precedence is correct. > > Only WT and WB are allowed to be overlapped here otherwise is > "undefined behavior". For example if the types are MTRR_TYPE_WRPROT > and MTRR_TYPE_WRTHROUGH, min() will get MTRR_TYPE_WRTHROUGH rather than > "undefined behavior". Choosing MTRR_TYPE_WRTHROUGH is one example of achieve undefined behavior. Picking one type arbitrarily is just a different kind of undefined behavior. Paolo