Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3421017iog; Mon, 27 Jun 2022 16:02:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uafC1+4Yiq3OGvTcpYt6eI777RyABVIV87ENp77tZhvBNbyuql3b1xNk9s0AyrM4+TFjkp X-Received: by 2002:a17:907:7b86:b0:726:ccd7:4ca4 with SMTP id ne6-20020a1709077b8600b00726ccd74ca4mr650132ejc.72.1656370926715; Mon, 27 Jun 2022 16:02:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656370926; cv=none; d=google.com; s=arc-20160816; b=Gx+iYZAtbvKP/7HBTRLutLF4BubxkPoX99XfvytXKXbgyWzUapcztSNYqGBc1rysU5 9ZWOau0GAFeZ79/YQOWVUD1X4l6kK0EGaML/a9OQPuCtoCCHSESl3GyJdwse1UrJVDF3 JNKuz+IAsbac8PM1syLEeepqWE5oudV05nvobMcffEqQxqawf52PoFd97vzEGRNfqgLy Kw23fjPGgGFCqT1Ln87cjBZYVCMhiY8Evikqq3fsL2oDErlG0xFIxqeEI5/Dy1r3yOlP 7PfxiPk+DCQ474dGD5LlOuqE8bkQtdsbt202HPNWbOVHc1BGOH26ISv0euD8A6qBDQPQ ofkg== 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 :dkim-signature; bh=NrXD3x8dDh+kWBYIbKibpMIuwNM/c93t27Z2WxjJDXA=; b=ycSivbsCm6ZIrCeRddkdVjgDuTFq8x8hkSSmT3qpw+GvISz7qQofpVWWlYjPeDVk3E SSCREzIw19HyVIXWQHsoZ8ScP1uZkhW+L/HRXBrakJK3nQc76ePq3/rZTtW0KXGbMVSV lF5MErmxl3eFDz3SzUADeLcyvPhXQqR/QDApoDhlO7t7h1dfLx8nJLOGJYVzKwFtxNxQ goBGL9NcxmcusmP40a7ws3h2X2d4l7GktqKp1gmKN4J9eoQp238Hslq2KW8f+XIa1UzV pelALZs5zHq3zjwjvHZ+Qr+zX/b3U80oVe8aIa0TNLCUyegtHaYsTmX2E47deDtokV44 mzqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l1kaVmXC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la3-20020a170906ad8300b00711ee53603esi13053222ejb.595.2022.06.27.16.01.41; Mon, 27 Jun 2022 16:02:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l1kaVmXC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242188AbiF0V7I (ORCPT + 99 others); Mon, 27 Jun 2022 17:59:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241497AbiF0Vz3 (ORCPT ); Mon, 27 Jun 2022 17:55:29 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB20D65B4; Mon, 27 Jun 2022 14:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366899; x=1687902899; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1Xl4GSkEm1UhNCYDSsYhWJHWueUQ4Wh6xbEP4MdBrPE=; b=l1kaVmXCUs9/9mCreOdioC0HSRUJ/FPgxgBlAH0HKtBNB2chQxdZM3Q6 liRimcYP8VnCzdsTIiPA3jpIWORCoUXeDNfCOxfkg5eNxrSCU4PVp2Oxj /bZ2yVPJ5GTeBvUgqLjmQcxk2Ka4Qv1lRXRKWFAUd23tfPuH3lB0fK0lc R+GgzAdTnVpWdgSKwcrQ2BtA7FeBZDSO9MyoN/u6/Qjq4VvL33Et1JIIj e1FMz2YhKSyvokVtRmbt6XoqkwJBQPhQP3V1rkTrvbDSfz71bhX7sApjX v/p0yIufGeqTQpH+YHS27Aa8qVwJcABSdVQBy7DtF8WI4zQX6oedoYpG9 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="281609571" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="281609571" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:54 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863591" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:54 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , Sean Christopherson , Xiaoyao Li Subject: [PATCH v7 048/102] KVM: x86/mmu: Disallow dirty logging for x86 TDX Date: Mon, 27 Jun 2022 14:53:40 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson TDX doesn't support dirty logging. Report dirty logging isn't supported so that device model, for example qemu, can properly handle it. Signed-off-by: Sean Christopherson Signed-off-by: Xiaoyao Li Signed-off-by: Isaku Yamahata Reviewed-by: Paolo Bonzini --- arch/x86/kvm/x86.c | 5 +++++ include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4309ef0ade21..dcd1f5e2ba05 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -13164,6 +13164,11 @@ int kvm_sev_es_string_io(struct kvm_vcpu *vcpu, unsigned int size, } EXPORT_SYMBOL_GPL(kvm_sev_es_string_io); +bool kvm_arch_dirty_log_supported(struct kvm *kvm) +{ + return kvm->arch.vm_type != KVM_X86_TDX_VM; +} + EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_entry); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_fast_mmio); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 79a4988fd51f..6fd8ec297236 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1452,6 +1452,7 @@ bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu); int kvm_arch_post_init_vm(struct kvm *kvm); void kvm_arch_pre_destroy_vm(struct kvm *kvm); int kvm_arch_create_vm_debugfs(struct kvm *kvm); +bool kvm_arch_dirty_log_supported(struct kvm *kvm); #ifndef __KVM_HAVE_ARCH_VM_ALLOC /* diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 7a5261eb7eb8..703c1d0c98da 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1467,9 +1467,18 @@ static void kvm_replace_memslot(struct kvm *kvm, } } -static int check_memory_region_flags(const struct kvm_userspace_memory_region *mem) +bool __weak kvm_arch_dirty_log_supported(struct kvm *kvm) { - u32 valid_flags = KVM_MEM_LOG_DIRTY_PAGES; + return true; +} + +static int check_memory_region_flags(struct kvm *kvm, + const struct kvm_userspace_memory_region *mem) +{ + u32 valid_flags = 0; + + if (kvm_arch_dirty_log_supported(kvm)) + valid_flags |= KVM_MEM_LOG_DIRTY_PAGES; #ifdef __KVM_HAVE_READONLY_MEM valid_flags |= KVM_MEM_READONLY; @@ -1871,7 +1880,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