Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753217AbdHXQBb (ORCPT ); Thu, 24 Aug 2017 12:01:31 -0400 Received: from mga01.intel.com ([192.55.52.88]:53779 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751840AbdHXQB3 (ORCPT ); Thu, 24 Aug 2017 12:01:29 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,422,1498546800"; d="scan'208";a="122269877" Subject: Re: [PATCH v3 2/5] KVM: MMU: check guest CR3 reserved bits based on its physical address width. To: Paolo Bonzini , kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, xiaoguangrong@tencent.com, joro@8bytes.org References: <1503577676-12345-1-git-send-email-yu.c.zhang@linux.intel.com> <1503577676-12345-3-git-send-email-yu.c.zhang@linux.intel.com> <0bce2df3-79ac-599b-19fa-8ebeaff23623@redhat.com> <35e285e7-168a-25e6-1053-c005da18c103@redhat.com> From: Yu Zhang Message-ID: Date: Thu, 24 Aug 2017 23:38:23 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <35e285e7-168a-25e6-1053-c005da18c103@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 874 Lines: 31 On 8/24/2017 11:50 PM, Paolo Bonzini wrote: > On 24/08/2017 17:23, Yu Zhang wrote: >>>> static inline u64 rsvd_bits(int s, int e) >>>> { >>>> + if (e < s) >>>> + return 0; >>>> + >>>> return ((1ULL << (e - s + 1)) - 1) << s; >>>> } >>> e = s - 1 is already supported; why do you need e <= s - 2? >> Sorry? I do not quite understand. When will e = s - 1? > Is there any case where e < s? I can see that MAXPHYADDR=63 gives > rsvd_bits(63, 62), but that works. > > In practice, MAXPHYADDR will never be 59 even because the PKRU bits are > at bits 59..62. Thanks, Paolo. I see. I had made an assumption that MAXPHYADDR shall not exceed the physical one, which is 52 I believe. But I'm not sure there's any place to check this. Maybe we should make sure the vcpu->arch.maxphyaddr will not be greater than the value of the host? Yu > > Paolo >