Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp18894lqo; Tue, 7 May 2024 10:48:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVd5cAOQO2SD/VyyKzW23pOykz85v0WbKqBqmP7u9gJLqQkJu9sn8UrvZkC6Rj8A30cy5U8fW6qlx2xn7R5sG3U+j+8cEmmH37uUiyXjA== X-Google-Smtp-Source: AGHT+IEjhDIAmwXdFOXoyyHXh2b6NhVPCpsd5B7F2ukFqbi8ViW4IBo0nOhWgIGmQM6uc6HNCmyR X-Received: by 2002:a05:6358:904b:b0:18a:68c9:d7b8 with SMTP id e5c5f4694b2df-192d2c2c92amr51910255d.8.1715104116835; Tue, 07 May 2024 10:48:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715104116; cv=pass; d=google.com; s=arc-20160816; b=ksCz+wdMnwjFpWeQsN9PXZkC4NxMkpO2lEKEsLTNgGw5tnHcEFqZbvggl1o/NxD88c QfbGQ8Ws161nn++J0LR65TMm5ZMGFGi5Od/XxTOqVCufhgR0zybPIgtsqQIkMr5wRnXI CPF4/AH0TR37vgbXfzr1efBPTyyNc0xk0aKzy5O6neT7wXULrQ/b7AS2ZcF5TFerOmL5 pjD6yDrQjop8cCHiC2Wh4wTaIhjtoLX+CdubV9ESp+KGXdM9GyPS0aN5DvAq6R5FL4w1 uzYL/MtqJytWLtQLOE7u3G+cu0+ndIRorVCW/SFp6bDXTlHxnqjI3vaSQPCa/DRDyxDk uPxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=U7NSWv2sngdGccyzHhW9zKoCfPe+XKegdqJlyPFodbI=; fh=6AbHzZCnQAica21MLfZwkQsWtkbN+Y8EC5TPXEoEKag=; b=YbBo8z0YXQeZ7PaE5dGW7am5fwWBm5Y/uIMq/1L6oBi9pYoUI/dLtP+c+tzmL6Pyjx vq6H60JoB9+ruZlcZ7N0aeDfdwjBBQxvpVIJzk986b7yu63a4qd7DpKhgXTp5esv+DAH B9q2gv+I+XF2BY6XVFNB67SliW3W4C7ROM/mP96PdWhFODsk1bQBwGR3qYsI7JYNiSFQ rLl62paVRgDZNPtrcFzqk7AzzOImTzELJCiWEyhTiUrPoJ8YQws6wgXcnNPl/oLRiMEj XDM2qDzj4gYlD0QJ8h8cUUpfpVlwe0GtwaAt2MjYxEjW/YbSCflgps41okkZYbXyXgAI Q3Jw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E16icK21; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-171928-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171928-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n2-20020a63f802000000b005e49cd906d6si9400183pgh.97.2024.05.07.10.48.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 10:48:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171928-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E16icK21; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-171928-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171928-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DAC8A2858FC for ; Tue, 7 May 2024 17:48:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 285FB16C873; Tue, 7 May 2024 17:48:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="E16icK21" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73ECA168AF5 for ; Tue, 7 May 2024 17:48:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715104104; cv=none; b=RY/pBeE77T89O/rdkfpoC4uuT3TPXkQGLYggxVxqT3pFmfgQw9tzjkbtvBDoWqj+m0Pl7BThc0UTc2i4/fmBAfW8bBNCbB1VM2cpp0MbCGbOwFDS+AE+Vzu4gb4Y45MFCZqnR+k3lb68knHETzA5ymEbe1A+ttrnTyw28uo3CR4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715104104; c=relaxed/simple; bh=G4sKnEbJdMGDqqOOZcGjKlz86s6SEc8Aai9Vaa1zX6Y=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=P2Ix3WVqriC1OnUBBX1h4CaktK3PiatjzFfNRfrrZXVCrzhxzj8d/34Q9fqNRm7BGXPq1y7S9pQ/mZ6nV5gK3G/9dIokRyFrdmhP835N98x2icKD3i/ll3TKopf9dAbCB3bmTmgsFZ6O7KwcZCon4OgOmijcKzfv2jkBlL1SKBE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=E16icK21; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715104101; 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:autocrypt:autocrypt; bh=U7NSWv2sngdGccyzHhW9zKoCfPe+XKegdqJlyPFodbI=; b=E16icK2184rGoPWH2bEBWPXJZtGGn9IuSbomFmgWyhqqa1ruGKqhGhtqOmdBud9HvxmNF8 k+VmqjaN1GCvbVHjRurw9a5R6X8ORqMflupozOg9FWcquJGX2GuADfbdyV2D6n3le9qlAy 7cR7RWsjIaPqUqnhqUs2tSPvXoMUcDw= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-308-PoGURnTGMFCdzMgdngfTjw-1; Tue, 07 May 2024 13:48:19 -0400 X-MC-Unique: PoGURnTGMFCdzMgdngfTjw-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-56c1ac93679so2820194a12.2 for ; Tue, 07 May 2024 10:48:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715104098; x=1715708898; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U7NSWv2sngdGccyzHhW9zKoCfPe+XKegdqJlyPFodbI=; b=p1vSUUo0+KOW667q/kUZDH7M21NlgLF1yGBmOzpsWUugtcSIERZSLqfU4D52svmhRP +NNboOI3voE0kU79a3iA7EgfPSiAMoxEzsrU+nM0k1unwCFp772Gb3oK4foHXky/lq+f RuNlj1z38q+hNEHj+0szR8LnVI6N50ZWnSQESK4gzi/WFm68cZX+/XwK1Cb8Rzplb8/v dx1A2OsmD9hipND+1SwzI86jejT6YYD5/ibRW0UUmk4+cV1kLzbKWTQOpepDrSGzQOcG P0F1MFXfgK4YJ1v+Fj+b0nHPjKSaYIjXSbh7Rhx0eT6uMI4p5YNpE1C6qzJdJ8qDsntM +FJQ== X-Forwarded-Encrypted: i=1; AJvYcCVxiuRDGEQMUBBfzeiRBb5oBzo1XrWfTOirByG77Po5I9ot//DGl/ZzSgGtaZqCrsrRjnuABnwyciEQJaDhKjAGbHjTPma2Ns21O8Ok X-Gm-Message-State: AOJu0Yz5NPW1cIiKuLVXk2uMENiPBVFQ7QGVBVaBq8QrMBDEu2RCPtDY NPh29qIM5NaxnBezz1CoBiwg/XJqQVERZg0yksGL/7Wag/+6VzTqD9joW+Up/erp4BuZR7ZvAd8 WesuikRstEplNoE1sMl4arfbAjDORlfNI37gNhcWa5JaGvhRLAHHyp/9u3jaPQw== X-Received: by 2002:a50:8ac8:0:b0:572:9d8a:20f4 with SMTP id 4fb4d7f45d1cf-5731da81922mr272396a12.32.1715104098655; Tue, 07 May 2024 10:48:18 -0700 (PDT) X-Received: by 2002:a50:8ac8:0:b0:572:9d8a:20f4 with SMTP id 4fb4d7f45d1cf-5731da81922mr272359a12.32.1715104098236; Tue, 07 May 2024 10:48:18 -0700 (PDT) Received: from [192.168.10.81] ([151.95.155.52]) by smtp.googlemail.com with ESMTPSA id b14-20020a0564021f0e00b00572cebc5f32sm5776641edb.65.2024.05.07.10.48.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 May 2024 10:48:17 -0700 (PDT) Message-ID: <044e8953-56f0-405e-9b50-7dde4ca8986b@redhat.com> Date: Tue, 7 May 2024 19:48:15 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v15 02/20] KVM: x86: Add hook for determining max NPT mapping level To: Michael Roth , kvm@vger.kernel.org Cc: linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, seanjc@google.com, vkuznets@redhat.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, bp@alien8.de, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, jarkko@kernel.org, ashish.kalra@amd.com, nikunj.dadhania@amd.com, pankaj.gupta@amd.com, liam.merwick@oracle.com References: <20240501085210.2213060-1-michael.roth@amd.com> <20240501085210.2213060-3-michael.roth@amd.com> From: Paolo Bonzini Content-Language: en-US Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 Cx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g0 JBrdmNZSQDz0iKmSrx8xkoXYfA3bgtFN8WJH2xgFL28XnqY4M6dLhJwV3z08tPSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: <20240501085210.2213060-3-michael.roth@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/1/24 10:51, Michael Roth wrote: > In the case of SEV-SNP, whether or not a 2MB page can be mapped via a > 2MB mapping in the guest's nested page table depends on whether or not > any subpages within the range have already been initialized as private > in the RMP table. The existing mixed-attribute tracking in KVM is > insufficient here, for instance: > > - gmem allocates 2MB page > - guest issues PVALIDATE on 2MB page > - guest later converts a subpage to shared > - SNP host code issues PSMASH to split 2MB RMP mapping to 4K > - KVM MMU splits NPT mapping to 4K > - guest later converts that shared page back to private > > At this point there are no mixed attributes, and KVM would normally > allow for 2MB NPT mappings again, but this is actually not allowed > because the RMP table mappings are 4K and cannot be promoted on the > hypervisor side, so the NPT mappings must still be limited to 4K to > match this. > > Add a hook to determine the max NPT mapping size in situations like > this. > > Suggested-by: Sean Christopherson > Signed-off-by: Michael Roth > --- > arch/x86/include/asm/kvm-x86-ops.h | 1 + > arch/x86/include/asm/kvm_host.h | 1 + > arch/x86/kvm/mmu/mmu.c | 18 ++++++++++++++++-- > 3 files changed, 18 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h > index c81990937ab4..566d19b02483 100644 > --- a/arch/x86/include/asm/kvm-x86-ops.h > +++ b/arch/x86/include/asm/kvm-x86-ops.h > @@ -140,6 +140,7 @@ KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons); > KVM_X86_OP_OPTIONAL(get_untagged_addr) > KVM_X86_OP_OPTIONAL(alloc_apic_backing_page) > KVM_X86_OP_OPTIONAL_RET0(gmem_prepare) > +KVM_X86_OP_OPTIONAL_RET0(private_max_mapping_level) > KVM_X86_OP_OPTIONAL(gmem_invalidate) > > #undef KVM_X86_OP > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index c6c5018376be..87265b73906a 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1816,6 +1816,7 @@ struct kvm_x86_ops { > void *(*alloc_apic_backing_page)(struct kvm_vcpu *vcpu); > int (*gmem_prepare)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order); > void (*gmem_invalidate)(kvm_pfn_t start, kvm_pfn_t end); > + int (*private_max_mapping_level)(struct kvm *kvm, kvm_pfn_t pfn); > }; > > struct kvm_x86_nested_ops { > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 510eb1117012..0d556da052f6 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -4271,6 +4271,20 @@ static inline u8 kvm_max_level_for_order(int order) > return PG_LEVEL_4K; > } > > +static u8 kvm_max_private_mapping_level(struct kvm *kvm, kvm_pfn_t pfn, > + u8 max_level, int gmem_order) > +{ > + if (max_level == PG_LEVEL_4K) > + return PG_LEVEL_4K; > + > + max_level = min(kvm_max_level_for_order(gmem_order), max_level); > + if (max_level == PG_LEVEL_4K) > + return PG_LEVEL_4K; > + > + return min(max_level, > + static_call(kvm_x86_private_max_mapping_level)(kvm, pfn)); > +} Since you're returning 0 both as a default and, later in the series, for non-SNP guests, you need to treat 0 as "don't care": diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index de35dee25bf6..62ad38b2a8c9 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4274,6 +4274,8 @@ static inline u8 kvm_max_level_for_order(int order) static u8 kvm_max_private_mapping_level(struct kvm *kvm, kvm_pfn_t pfn, u8 max_level, int gmem_order) { + u8 req_max_level; + if (max_level == PG_LEVEL_4K) return PG_LEVEL_4K; @@ -4281,8 +4283,11 @@ static u8 kvm_max_private_mapping_level(struct kvm *kvm, kvm_pfn_t pfn, if (max_level == PG_LEVEL_4K) return PG_LEVEL_4K; - return min(max_level, - static_call(kvm_x86_private_max_mapping_level)(kvm, pfn)); + req_max_level = static_call(kvm_x86_private_max_mapping_level)(kvm, pfn); + if (req_max_level) + max_level = min(max_level, req_max_level); + + return req_max_level; } static int kvm_faultin_pfn_private(struct kvm_vcpu *vcpu, Not beautiful but it does the job I guess. Paolo