Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp131474lqb; Tue, 28 May 2024 10:44:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWry0VUHpKLHyShoU+z6vBhj+KXZISJhChiAFuYVV5QcC5oXwaxefqmX2xbcMHZYJ/YREcGRgX59o6LwpRCtW3ZFiDX3xMf6EpXRyVrUA== X-Google-Smtp-Source: AGHT+IHo5zBvnVK6JZgksa17qg64zHMIyRNE0PmxWgUOMgE66xhp43DKskKaTfCMTLFOtw3gYcii X-Received: by 2002:a25:874d:0:b0:df7:c087:57a1 with SMTP id 3f1490d57ef6-df7c0876661mr3873401276.51.1716918249674; Tue, 28 May 2024 10:44:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716918249; cv=pass; d=google.com; s=arc-20160816; b=LsntYsIlwRi49guJr3DegR5Pr6/0I/lAqQz2Y8NZvGUnkhwrdDZpmKd0nSzZh1RQn8 5BJZtleppl1hDTcKX+sGVZN5NmShnjodqRjSMUJ6PZ5YMeWh/l0GoKoPGbUf93bD6U5p KCy8k/g8UjIRnY6BiOoRrpjVjXjhylXAu2Uo0TrMN5F8el8NAzgHPCH4NempeRHSBmh/ sLoLHP1VgAXVCdn76DYW3Zla2AiJPtqK0mRRwUTjnjffofm4bkfLXv9gB9rEs1bstia3 Um9jhvfPAvEjfHGm+HxDCJBN/xuOViGdH8khrbB8sz+48k9sG6wBwlDMkP1IUD/aH+vg i4YA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=BgC1mBmX/uzbi9oKpLMQ8UHWTdsyAuGhZK7pefKFgjk=; fh=wU0E25eLhx4sSZ0Xyvjk4DMR4tLaxDvRv/HwkaBHhQg=; b=r6eTBth24OCLngTczKeBwOAuazb4r5ADDVDG6N4iVPtV40FYHwPSkwszDYBPGdLk5n 5M7vp0nfrXcPLfnIh0TI9iuNVmLwLL+hzvkfg8nkUHuIOfRNAo9NvjSTwafsNGJs+LF8 qZGJzcMyG3ecbsq7cha77utcaqgm8iLyw0iBBZkGbKHd0g104dxOeZPTulvLwFadi7g0 6kwWjftiLK6dUqEGJy1XiJ88e6ZeNyRtMHs5KvwfjZEFHoBQwEgvnBgg42lcesBRuTvX uFDUjAPHTsYFlys6Ezva+0JKO6lOB7ntwUwn4OSgTg5ejV7QrtWwlMMsd2/jfV9bNxW3 egNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FfR5vCDG; 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-192822-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192822-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794abd4d69asi1185180485a.575.2024.05.28.10.44.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 10:44:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192822-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FfR5vCDG; 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-192822-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192822-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 527A61C22ED2 for ; Tue, 28 May 2024 17:44:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0379229415; Tue, 28 May 2024 17:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FfR5vCDG" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 679B0224FD for ; Tue, 28 May 2024 17:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716918219; cv=none; b=B22tSWXexUcv0CVskU7MZxJwMBDserUgBlOW9O/Y74OpYIfe5jia6C+8xXEhy0OPNq2GzEBvfuQMDHtelUg4u2neMmZnS7yXh4WWidELkEB79fAZdpQrkvS091WwZNqC9tZ8Hhe68/ccvRsBzWIowPstq6K3ZiFW+CnT5ZP6TRk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716918219; c=relaxed/simple; bh=5ss+AAnDNgpFoZHquQjyHRTVRnwByHqRQ9kN4FAyIBk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=fW+1Y5fEgjof5nAt/apNDm8BqqWJCR2wB4XHr06ZwVQ7/Vhp+/xj4Bl2Uk2Y1L0CcXk6mb1sZ/gCtIwRlz6mJ5iu3et4Ev/EM/T6AkCzb3B+LwpcHhYxDdWRLCl3afli3iCH5rwvz1bGtSloipMngHf0eI8PLzSduI6a+ydGvSs= 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=FfR5vCDG; arc=none smtp.client-ip=170.10.129.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=1716918216; 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=BgC1mBmX/uzbi9oKpLMQ8UHWTdsyAuGhZK7pefKFgjk=; b=FfR5vCDG3B1md5I5fTu+1bj4IoLEXuNxPJeVkYy7uplU/tz9JMxLi7oGG++wb+4uxZGSRj EfACyPY5tsHV+tST+DCNfAny8n8NY1kxecApaEVEOjozkP2Kl4spySAQz9LkjawQMf2tQd DDzjBMa+MDH6u97pzaRBf6Y4hcmE7rk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-aG2KsOEgN42ywBQI0uOQZA-1; Tue, 28 May 2024 13:43:34 -0400 X-MC-Unique: aG2KsOEgN42ywBQI0uOQZA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-42110ebbd0fso7901045e9.1 for ; Tue, 28 May 2024 10:43:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716918214; x=1717523014; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BgC1mBmX/uzbi9oKpLMQ8UHWTdsyAuGhZK7pefKFgjk=; b=GK1/DCG6QB3gYqv3LMGORa47xHbnaKH4G4OZpHqPODUJiiPZY3C1c6ceXyxwTKfjhB zNTn4Cn9s/6QTPYSlwvsYxv2+ec8BvMqC9pg6BSNAWYv40qW3CWS6eXS+v5+miDO0q8c KitmPX6kKfuL2VqYA8gnLB122+MjTQ4lAOV4XUGxk69kbZs1L5tNJ/++qpFD4F9ais0y qJGxyguYp1yTpULgtCyMRDFC12cPx0yfhJXxFCuwBYXJv2/Mm3Z9KnrFkRtfCFRNq5uT 1hD88Vu/cfga7wveR2iH9woaD+Amiu0RG1SU4Bz4dGZ8lS3rUx54G4c3nOu7l3k6twOY sAYQ== X-Forwarded-Encrypted: i=1; AJvYcCVXw7/OwZFTalVa2Wj14mrdbWfLAmMzxCStbieNYnblSKLuAh/f1siaVI5blyuuGR04BCgx3npBbTuQKvpO2x1hGwc6ZEJ+dTnhtWEl X-Gm-Message-State: AOJu0YxyrlReeLhME9NIe4a8Eg8hthJi2jlz2lCjDkMXIGrMpu5BJ4yK mda6I7ro57YrXYx4VIGO2y8BUaD2b6GjSpUC9Z5wZXj9cKybNkxmq23YzYYYSaZtHNHQtBWjQ8E 2DBsng1edgxeMt1E1M6MaMnd9vdzTvj9a1C3E5aUn6jUmecxWDgNmdQOBxbQUdfgf7GFk6lYJX8 DNCO02vqf/mU7Vyg8VXwq7rynRjYHJPDC2M8Mm X-Received: by 2002:a5d:5692:0:b0:34c:9a24:7a40 with SMTP id ffacd0b85a97d-3552fe19565mr8133822f8f.56.1716918213759; Tue, 28 May 2024 10:43:33 -0700 (PDT) X-Received: by 2002:a5d:5692:0:b0:34c:9a24:7a40 with SMTP id ffacd0b85a97d-3552fe19565mr8133794f8f.56.1716918213277; Tue, 28 May 2024 10:43:33 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <1d247b658f3e9b14cefcfcf7bca01a652d0845a0.camel@intel.com> <588d801796415df61136ce457156d9ff3f2a2661.camel@intel.com> <021e8ee11c87bfac90e886e78795d825ddab32ee.camel@intel.com> <20240516194209.GL168153@ls.amr.corp.intel.com> <55c24448fdf42d383d45601ff6c0b07f44f61787.camel@intel.com> <20240517090348.GN168153@ls.amr.corp.intel.com> <20240517191630.GC412700@ls.amr.corp.intel.com> <20240520233227.GA29916@ls.amr.corp.intel.com> In-Reply-To: <20240520233227.GA29916@ls.amr.corp.intel.com> From: Paolo Bonzini Date: Tue, 28 May 2024 19:43:20 +0200 Message-ID: Subject: Re: [PATCH 10/16] KVM: x86/tdp_mmu: Support TDX private mapping for TDP MMU To: Isaku Yamahata Cc: "Edgecombe, Rick P" , "kvm@vger.kernel.org" , "seanjc@google.com" , "Huang, Kai" , "sagis@google.com" , "isaku.yamahata@linux.intel.com" , "Aktas, Erdem" , "Zhao, Yan Y" , "isaku.yamahata@gmail.com" , "dmatlack@google.com" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, May 21, 2024 at 1:32=E2=80=AFAM Isaku Yamahata wrote: > +static void vt_adjust_max_pa(void) > +{ > + u64 tme_activate; > + > + mmu_max_gfn =3D __kvm_mmu_max_gfn(); > + rdmsrl(MSR_IA32_TME_ACTIVATE, tme_activate); > + if (!(tme_activate & TME_ACTIVATE_LOCKED) || > + !(tme_activate & TME_ACTIVATE_ENABLED)) > + return; > + > + mmu_max_gfn -=3D (gfn_t)TDX_RESERVED_KEYID_BITS(tme_activate); This would be be >>=3D, not "-=3D". But I think this should not look at TME MSRs directly, instead it can use boot_cpu_data.x86_phys_bits. You can use it instead of shadow_phys_bits in __kvm_mmu_max_gfn() and then VMX does not need any adjustment. That said, this is not a bugfix, it's just an optimization. Paolo > + } > > out: > /* kfree() accepts NULL. */ > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 7f89405c8bc4..c519bb9c9559 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -12693,6 +12693,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned lo= ng type) > if (ret) > goto out; > > + kvm->arch.mmu_max_gfn =3D __kvm_mmu_max_gfn(); > kvm_mmu_init_vm(kvm); > > ret =3D static_call(kvm_x86_vm_init)(kvm); > @@ -13030,7 +13031,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kv= m, > return -EINVAL; > > if (change =3D=3D KVM_MR_CREATE || change =3D=3D KVM_MR_MOVE) { > - if ((new->base_gfn + new->npages - 1) > kvm_mmu_max_gfn()= ) > + if ((new->base_gfn + new->npages - 1) > kvm_mmu_max_gfn(k= vm)) > return -EINVAL; > > #if 0 > > -- > Isaku Yamahata >