Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1884936pxv; Fri, 2 Jul 2021 15:08:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9q3FeO4JWOnjrCBsElV6RxapFskVZkCo0Fu46jgr2eAS9fPt6m4nG74eTcZcz1T5V/cgN X-Received: by 2002:a17:906:9b86:: with SMTP id dd6mr1871962ejc.100.1625263691582; Fri, 02 Jul 2021 15:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263691; cv=none; d=google.com; s=arc-20160816; b=Oy60EP01HgebzEQpYCnu6SPK4uF9ptm/z54MKc0hX3SiGiP0Rrf6EJ4WaC7uAqzVG7 MA7tKaYUjW7NH8qyvBKMcQB8AB87sXfeidiHeCdvbfcLWCoKN94Nzt+P7NPz7itYyutg EPvQDrfexoLGL2BECCgh+VnGRxLQnMpDCD9KkgETBea9FB9Q5OsdiO35RWhQo1SCp4qA ahfuabfv8mFo/k5dDcsUDO0g9kGjSwGOZJ5PHG3mgBYRtbulAe7bQCTnpDFyV6Tt0SN3 qFUJB0VzqitAv5EgtisN/x3cNcNbyC36vAmX6QTC/AcJFUKlVi1qruWyoPM80abxNIVF Z9mw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=HCPVJzvjvmBCAceO5vju5hsvaK7th2QZVcLm7srByrs=; b=SmqF098zvZYGBW+/eWKsNsUZsebYZrD7Ka+34G8kkPeTXmfxZcR1iEyvUl08cXc55p 7CkdlrW56RXPCehRL3Z7ThG24J8qQJ3EZ8sxFYGkLZ+aJ9uRcO1UYMzaGmXXZApIUD5y zXRqaWPY0uidchiTKvNwR+TI7ARHyt7z35pj4PeR7O3VPQ7j/QAkmJ73KiO4FUr/OroD IdCcoO1mEB4hPDWghD2aZKwfCHI6EWUbDxY+pFA4dJ+G30+23m7/dkX8QZo8WDM3ducq 8MnG03X96UAxY3SPlY1NxfIzYHCc59pBDnwS4jzC4vmGsJIb+GHVGiOu2QLgaojrlh9Z p/IA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si148442edz.545.2021.07.02.15.07.48; Fri, 02 Jul 2021 15:08:11 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233814AbhGBWIh (ORCPT + 99 others); Fri, 2 Jul 2021 18:08:37 -0400 Received: from mga12.intel.com ([192.55.52.136]:50197 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233144AbhGBWH5 (ORCPT ); Fri, 2 Jul 2021 18:07:57 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="188472734" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="188472734" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:24 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814763" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:24 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson Subject: [RFC PATCH v2 28/69] KVM: Add per-VM flag to mark read-only memory as unsupported Date: Fri, 2 Jul 2021 15:04:34 -0700 Message-Id: <1eb584469b41775380ab0a5a5d31a64e344b1b95.1625186503.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isaku Yamahata Add a flag for TDX to flag RO memory as unsupported and propagate it to KVM_MEM_READONLY to allow reporting RO memory as unsupported on a per-VM basis. TDX1 doesn't expose permission bits to the VMM in the SEPT tables, i.e. doesn't support read-only private memory. Signed-off-by: Isaku Yamahata Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 4 +++- include/linux/kvm_host.h | 4 ++++ virt/kvm/kvm_main.c | 8 +++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index cd9407982366..87212d7563ae 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3897,7 +3897,6 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_ASYNC_PF_INT: case KVM_CAP_GET_TSC_KHZ: case KVM_CAP_KVMCLOCK_CTRL: - case KVM_CAP_READONLY_MEM: case KVM_CAP_HYPERV_TIME: case KVM_CAP_IOAPIC_POLARITY_IGNORED: case KVM_CAP_TSC_DEADLINE_TIMER: @@ -4009,6 +4008,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) if (static_call(kvm_x86_is_vm_type_supported)(KVM_X86_TDX_VM)) r |= BIT(KVM_X86_TDX_VM); break; + case KVM_CAP_READONLY_MEM: + r = kvm && kvm->readonly_mem_unsupported ? 0 : 1; + break; default: break; } diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index ddd4d0f68cdf..7ee7104b4b59 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -597,6 +597,10 @@ struct kvm { unsigned int max_halt_poll_ns; u32 dirty_ring_size; +#ifdef __KVM_HAVE_READONLY_MEM + bool readonly_mem_unsupported; +#endif + bool vm_bugged; }; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 52d40ea75749..63d0c2833913 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1258,12 +1258,14 @@ static void update_memslots(struct kvm_memslots *slots, } } -static int check_memory_region_flags(const struct kvm_userspace_memory_region *mem) +static int check_memory_region_flags(struct kvm *kvm, + const struct kvm_userspace_memory_region *mem) { u32 valid_flags = KVM_MEM_LOG_DIRTY_PAGES; #ifdef __KVM_HAVE_READONLY_MEM - valid_flags |= KVM_MEM_READONLY; + if (!kvm->readonly_mem_unsupported) + valid_flags |= KVM_MEM_READONLY; #endif if (mem->flags & ~valid_flags) @@ -1436,7 +1438,7 @@ int __kvm_set_memory_region(struct kvm *kvm, int as_id, id; int r; - r = check_memory_region_flags(mem); + r = check_memory_region_flags(kvm, mem); if (r) return r; -- 2.25.1