Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2541687pxt; Mon, 9 Aug 2021 03:07:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCEfenR4jZzrQhGjhAvXZ8j+e5GaTPuM2+L4NFDYi54h2F8De14sKEQVPbEXw8V7CS5IPF X-Received: by 2002:a50:8fe1:: with SMTP id y88mr28548946edy.101.1628503664743; Mon, 09 Aug 2021 03:07:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628503664; cv=none; d=google.com; s=arc-20160816; b=iAU35H2rI8fEfVZaD87ingrt88ce7z0xVsw0fl2SYtBzIvBF2r/BlmTzsKV0frmhk8 NlEVuklaPG+Zkneegvcq7Vx2baij8DO9yy8Dl5CtrXLMSxnN9aiewK6V9ILMAySumtxC KnazK9PcbNIqhSQ6VZ7Gnr/LeeMqk1O8e2DfqQjmExQ+K9gWLMznCFhhK3zstpIWQyXj PlNaj7lAOVQjZHkLIglaJ2yzVw1xIBbPF8h5+Jwn0hLiBQ4hXzx27+R06kI74NDi9C0b OI9s/tmFWvuoJu0FPcDSqJjJfIB/9Ynmgwy1jyPDTDcRc27g9G+ct4RLu1SwJnt6kmFC hNkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=sNLQyoKHz3doB3VgHoSYiw/2Wi9gt/WD6yUBM0vzV9U=; b=xRcQlGexjOD+BWObIdu5vcCySNNjLNfXxCVs4yIAbj23VxGLY/XEnhVh9pR2n/FSIy Uq5hsEVRVuBI+Xrm6OQ5ZncReREl5aLkidS2o25PgSeeZXMJxM0EClkl85SN3RoLKC0m 2hHQ76chcK2e4QTFVdHjIM+FevFHKF54EVRq75akcsygFxlJgn8Gii8gzJ86zxNSePL/ yBf3LXUPFpKWb1rMWwTPhN7Hrq/qKIXjlVKtMfWkR5VjiW6uB7vJFLmv14kC1Ze5TpqK a5yLP/mHTmFr2nhnOJNQGIIqGFwRYYGOYFdcyCE1UmIUctkDgPXS4CPsCgShcTehDbyH 5c1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VNnMWS2L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j14si16528984edq.89.2021.08.09.03.07.18; Mon, 09 Aug 2021 03:07:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VNnMWS2L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233618AbhHIHqJ (ORCPT + 99 others); Mon, 9 Aug 2021 03:46:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20171 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233575AbhHIHpz (ORCPT ); Mon, 9 Aug 2021 03:45:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628495135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sNLQyoKHz3doB3VgHoSYiw/2Wi9gt/WD6yUBM0vzV9U=; b=VNnMWS2LtZVDxEc26SFpnM2pJHwnVJlX1Vh/l6NcSRvsFuah8KlwzNlg4EYD7sFLI0xyAX yxbTxd9os+zvqQtj+TAuQXO6ABOQWCcSKbYbrq19zVfqdGW4ZB84vSAPFpEZQ2FriGhWJg xkWkhMbCgEyVE4h/qbAtRp6qImXr5dM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-591-z6TTFUY7OwO2e0ffebZ4jA-1; Mon, 09 Aug 2021 03:45:32 -0400 X-MC-Unique: z6TTFUY7OwO2e0ffebZ4jA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 887631853028; Mon, 9 Aug 2021 07:45:30 +0000 (UTC) Received: from starship (unknown [10.35.206.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC1BD60CC9; Mon, 9 Aug 2021 07:45:28 +0000 (UTC) Message-ID: <33d01b8bb31541be7911f95581cdf608c6c79bf6.camel@redhat.com> Subject: Re: [PATCH] selftests: KVM: avoid failures due to reserved HyperTransport region From: Maxim Levitsky To: Joao Martins , Paolo Bonzini Cc: stable@vger.kernel.org, David Matlack , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Date: Mon, 09 Aug 2021 10:45:27 +0300 In-Reply-To: <4b530fb6-81cc-be36-aa68-92ec01c65775@oracle.com> References: <20210805105423.412878-1-pbonzini@redhat.com> <4b530fb6-81cc-be36-aa68-92ec01c65775@oracle.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2021-08-06 at 11:57 +0100, Joao Martins wrote: > > On 8/5/21 11:54 AM, Paolo Bonzini wrote: > > Accessing guest physical addresses at 0xFFFD_0000_0000 and above causes > > a failure on AMD processors because those addresses are reserved by > > HyperTransport (this is not documented). > > Oh, but it's actually documented in the AMD IOMMU manual [0] (and AMD IOMMU in linux do > mark it as a reserved IOVA region i.e. HT_RANGE_START..HT_RANGE_END). And it's usually > marked as a reserved type in E820. At least on the machines I've seen. > > See manual section '2.1.2 IOMMU Logical Topology': > > "Special address controls in Table 3 are interpreted against untranslated guest physical > addressess (GPA) that lack a PASID TLP prefix." > > Base Address Top Address Use > > FD_0000_0000h FD_F7FF_FFFFh Reserved interrupt address space > FD_F800_0000h FD_F8FF_FFFFh Interrupt/EOI IntCtl > FD_F900_0000h FD_F90F_FFFFh Legacy PIC IACK > FD_F910_0000h FD_F91F_FFFFh System Management > FD_F920_0000h FD_FAFF_FFFFh Reserved Page Tables > FD_FB00_0000h FD_FBFF_FFFFh Address Translation > FD_FC00_0000h FD_FDFF_FFFFh I/O Space > FD_FE00_0000h FD_FFFF_FFFFh Configuration > FE_0000_0000h FE_1FFF_FFFFh Extended Configuration/Device Messages > FE_2000_0000h FF_FFFF_FFFFh Reserved > > It covers the range starting that address you fixed up ... up to 1Tb, fwiw. > > You mark it ~1010G as max gfn so shouldn't be a problem. > > [0] https://www.amd.com/system/files/TechDocs/48882_IOMMU.pdf > > > Avoid selftests failures > > by reserving those guest physical addresses. > > > > Fixes: ef4c9f4f6546 ("KVM: selftests: Fix 32-bit truncation of vm_get_max_gfn()") > > Cc: stable@vger.kernel.org > > Cc: David Matlack > > Reported-by: Maxim Levitsky > > Signed-off-by: Paolo Bonzini > > --- > > tools/testing/selftests/kvm/lib/kvm_util.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > > index 10a8ed691c66..d995cc9836ee 100644 > > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > > @@ -309,6 +309,12 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm) > > /* Limit physical addresses to PA-bits. */ > > vm->max_gfn = ((1ULL << vm->pa_bits) >> vm->page_shift) - 1; > > > > +#ifdef __x86_64__ > > + /* Avoid reserved HyperTransport region on AMD processors. */ > > + if (vm->pa_bits == 48) > > + vm->max_gfn = 0xfffcfffff; > > +#endif > > + > > Not sure if it's worth the trouble having a macro with the same name as AMD iommu like: > > #define HT_RANGE_START (0xfd00000000ULL) > #define MAX_GFN (HT_RANGE_START - 1ULL) > > #ifdef __x86_64__ > /* Avoid reserved HyperTransport region on AMD processors. */ > if (vm->pa_bits == 48) > vm->max_gfn = MAX_GFN; > #endif I guess now that we know that it is documented, it is worth it, to remove '== 48' check and add check for an AMD cpu, and add reference to this manual. I am mentioning the 48 bit check because I have seen that AMD just recently posted 5 level NPT support, so I guess CPUs which > 48 bit max physical address are also probably on horison. And long term solution for this I guess is to add these areas to a blacklist and avoid them. Best regards, Maxim Levitsky > > It's a detail, but *perhaps* would help people grepping around it. > > Also, not sure if checking against AMD cpuid vendor is worth, considering this is > a limitation only on AMD. > > > > /* Allocate and setup memory for guest. */ > > vm->vpages_mapped = sparsebit_alloc(); > > if (phy_pages != 0) > >