Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	vkuznets@redhat.com, mlevitsk@redhat.com,
	joao.m.martins@oracle.com, stable@vger.kernel.org,
	David Matlack <dmatlack@google.com>
Subject: Re: [PATCH v2] selftests: KVM: avoid failures due to reserved HyperTransport region
Date: Thu, 9 Dec 2021 21:47:59 +0000	[thread overview]
Message-ID: <YbJ5jyCyqZwZU3uH@google.com> (raw)
In-Reply-To: <20211209205256.301140-1-pbonzini@redhat.com>

On Thu, Dec 09, 2021, Paolo Bonzini wrote:
> +unsigned long vm_compute_max_gfn(struct kvm_vm *vm)
> +{
> +	const unsigned long num_ht_pages = 12 << 18; /* 12 GiB */
> +	unsigned long ht_gfn, max_gfn, max_pfn;
> +	uint32_t eax, ebx, ecx, edx;
> +
> +	max_gfn = (1ULL << (vm->pa_bits - vm->page_shift)) - 1;
> +
> +	/* Avoid reserved HyperTransport region on AMD processors.  */
> +	eax = ecx = 0;
> +	cpuid(&eax, &ebx, &ecx, &edx);
> +	if (ebx != X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx ||
> +	    ecx != X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx ||
> +	    edx != X86EMUL_CPUID_VENDOR_AuthenticAMD_edx)
> +		return max_gfn;
> +
> +	/* On parts with <40 physical address bits, the area is fully hidden */
> +	if (vm->pa_bits < 40)
> +		return max_gfn;
> +
> +	eax = 1;
> +	cpuid(&eax, &ebx, &ecx, &edx);
> +	if (x86_family(eax) < 0x17) {
> +		/* Before family 17h, the HyperTransport area is just below 1T.  */
> +		ht_gfn = (1 << 28) - num_ht_pages;
> +	} else {
> +		/*
> +		 * Otherwise it's at the top of the physical address
> +		 * space, possibly reduced due to SME by bits 11:6 of
> +		 * CPUID[0x8000001f].EBX.
> +		 */
> +		eax = 0x80000008;
> +		cpuid(&eax, &ebx, &ecx, &edx);

Should't this check 0x80000000.eax >= 0x80000008 first?  Or do we just accept
failure if family==0x17 and there's no 0x80000008?  One paranoid option would be
to use the pre-fam17 value, e.g.

        /* Before family 17h, the HyperTransport area is just below 1T. */
        ht_gfn = (1 << 28) - num_ht_pages;
        if (x86_family(eax) < 0x17)
                goto out;

        eax = 0x80000000;
        cpuid(&eax, &ebx, &ecx, &edx);
        max_ext_leaf = eax;

        /* Use the old, conservative value if MAXPHYADDR isn't enumerated. */
        if (max_ext_leaf < 0x80000008)
                goto out;

        /* comment */
        eax = 0x80000008;
        cpuid(&eax, &ebx, &ecx, &edx);
        max_pfn = (1ULL << ((eax & 255) - vm->page_shift)) - 1;
        if (max_ext_leaf >= 0x8000001f) {
                <adjust>
        }
        ht_gfn = max_pfn - num_ht_pages;
out:
        return min(max_gfn, ht_gfn - 1);

> +             max_pfn = (1ULL << ((eax & 255) - vm->page_shift)) - 1;

LOL, "& 255", you just couldn't resist, huh?  My version of Rami Code only goes
up to 15.  :-)

  reply	other threads:[~2021-12-09 21:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-09 20:52 [PATCH v2] selftests: KVM: avoid failures due to reserved HyperTransport region Paolo Bonzini
2021-12-09 21:47 ` Sean Christopherson [this message]
2021-12-09 22:21   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YbJ5jyCyqZwZU3uH@google.com \
    --to=seanjc@google.com \
    --cc=dmatlack@google.com \
    --cc=joao.m.martins@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=vkuznets@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox