From patchwork Wed Nov 8 11:17:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 162978 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp844197vqo; Wed, 8 Nov 2023 03:24:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IELvvSI795NOzwMVbSliPYSFQQysskftLw/Iicm16EMZ4j+36M3j+s+TuPmPTKG0XHKNBDD X-Received: by 2002:a05:6a00:a1a:b0:6c3:75e1:9dcd with SMTP id p26-20020a056a000a1a00b006c375e19dcdmr1458162pfh.18.1699442683223; Wed, 08 Nov 2023 03:24:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699442683; cv=none; d=google.com; s=arc-20160816; b=KE2lBd7jpo6/gQYdpi4zsZHp7sVxAF7jqiIxDpuvLIdV/qsDFH1vfCKz1Xj2L8szBl pW3liMjyb1vh9kJZO4RTfwhHdlPTUMopQPR3nnPcx3MQ1YGu7LwR2WTQk5auOCcHz1Tp NM44fFznnVhCOoZz8zaa92dSsqUGXnEk4v2NCdH/AOuvgY5GevWY3f4fYZrZj3xG3ZpX Lz4zgb57L8gz+f1jtxSVD0VMI9bRrKlboqqX0xTjXr2mOkSD91WuLc/X+dQmeklvcPCq BntfvkBa25V916b0GU4GqCoCuEspmpraSeoL2pWMVjp3T3PoeUQo2dZi4ZF7XmluXcW2 8NHQ== 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=c+LzbRrbsSUyvlGgFH27jCwf7iTA/jQxajqqAaH5CaQ=; fh=Qdq7NqGm5JR9LpctBpXjoRI38Lb2mCk6xy26GEDp1Bg=; b=lWrEtIPWi7A0N5YZK0yIUIaW+aVGzh+vqRjHnuzCjkpAmZNevLz/uiR76i7cvy8msq CJZR9wm3xNy8MvgA5cPmSfSXUhvkzdw9KoLAtqr45dva6foYd6Ic60iqNobPGmVUh6aK PR/5ifqPh5PgdYiJVBseY44JAvvpOs/H5iVdjBweqWkL4w/i3O8+P9c2S5LhLzyr8HJ5 rGaCDLMJa9ahY/J8JxLbAenS0yfxgLn4EQrtV5C2gOLwsVh0zdC/PfQvOC/BYi2jbT+9 mUAHtzsTcsc5v0Ab4dmLUvu4ESCemqEbofNbnl3vE5IfesexcTttubuzcaRsimkORpah lq5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=fx21Mtjt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s10-20020a056a00194a00b006b8e367ed42si13511486pfk.54.2023.11.08.03.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:24:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=fx21Mtjt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7CAE1826BBBE; Wed, 8 Nov 2023 03:24:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344476AbjKHLXe (ORCPT + 32 others); Wed, 8 Nov 2023 06:23:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344709AbjKHLXQ (ORCPT ); Wed, 8 Nov 2023 06:23:16 -0500 Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AA8A1FE7; Wed, 8 Nov 2023 03:23:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1699442589; x=1730978589; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c+LzbRrbsSUyvlGgFH27jCwf7iTA/jQxajqqAaH5CaQ=; b=fx21MtjtuEYg4WSnWWtyzoP5MoH0tXFLtnQBIffZJ8BwJx9rNFKxkXqY uCthuyHuyYHVocvqF1+i2tQPqXX346ecbzUbofxrbUEfzzZbprlZ32WPv wFZgRWZ1XrOOheF9kYWirku2+mWbD1Gdht/jFGPjEwKkU+/mL2UUSZ3Mq c=; X-IronPort-AV: E=Sophos;i="6.03,286,1694736000"; d="scan'208";a="164959605" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-pdx-2b-m6i4x-cadc3fbd.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2023 11:23:07 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2b-m6i4x-cadc3fbd.us-west-2.amazon.com (Postfix) with ESMTPS id 1A2F0A12E2; Wed, 8 Nov 2023 11:23:02 +0000 (UTC) Received: from EX19MTAEUA002.ant.amazon.com [10.0.17.79:48574] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.32.187:2525] with esmtp (Farcaster) id 78327385-25a6-4125-94a0-25fd575b12d8; Wed, 8 Nov 2023 11:23:01 +0000 (UTC) X-Farcaster-Flow-ID: 78327385-25a6-4125-94a0-25fd575b12d8 Received: from EX19D004EUC001.ant.amazon.com (10.252.51.190) by EX19MTAEUA002.ant.amazon.com (10.252.50.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Wed, 8 Nov 2023 11:23:01 +0000 Received: from dev-dsk-nsaenz-1b-189b39ae.eu-west-1.amazon.com (10.13.235.138) by EX19D004EUC001.ant.amazon.com (10.252.51.190) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Wed, 8 Nov 2023 11:22:56 +0000 From: Nicolas Saenz Julienne To: CC: , , , , , , , , , , , , , , , Nicolas Saenz Julienne Subject: [RFC 23/33] KVM: Expose memory attribute helper functions unanimously Date: Wed, 8 Nov 2023 11:17:56 +0000 Message-ID: <20231108111806.92604-24-nsaenz@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231108111806.92604-1-nsaenz@amazon.com> References: <20231108111806.92604-1-nsaenz@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.13.235.138] X-ClientProxiedBy: EX19D033UWC001.ant.amazon.com (10.13.139.218) To EX19D004EUC001.ant.amazon.com (10.252.51.190) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 08 Nov 2023 03:24:39 -0800 (PST) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781994811070482358 X-GMAIL-MSGID: 1781994811070482358 Expose memory attribute helper functions even when CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES is disabled. Other KVM features, like Hyper-V VSM, make use of memory attributes but don't rely on the KVM ioctl. Signed-off-by: Nicolas Saenz Julienne --- arch/x86/kvm/mmu/mmu.c | 2 +- include/linux/kvm_host.h | 2 +- virt/kvm/kvm_main.c | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index c2bec2be2ba9..a76028aa8fb3 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -7250,7 +7250,6 @@ void kvm_mmu_pre_destroy_vm(struct kvm *kvm) kthread_stop(kvm->arch.nx_huge_page_recovery_thread); } -#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES bool kvm_arch_pre_set_memory_attributes(struct kvm *kvm, struct kvm_gfn_range *range) { @@ -7377,6 +7376,7 @@ bool kvm_arch_post_set_memory_attributes(struct kvm *kvm, return false; } +#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES void kvm_mmu_init_memslot_memory_attributes(struct kvm *kvm, struct kvm_memory_slot *slot) { diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index ad104794037f..45e3e261755d 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2387,7 +2387,6 @@ static inline void kvm_prepare_memory_fault_exit(struct kvm_vcpu *vcpu, vcpu->run->memory_fault.flags |= KVM_MEMORY_EXIT_FLAG_PRIVATE; } -#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES static inline unsigned long kvm_get_memory_attributes(struct xarray *mem_attr_array, gfn_t gfn) { @@ -2404,6 +2403,7 @@ bool kvm_arch_pre_set_memory_attributes(struct kvm *kvm, bool kvm_arch_post_set_memory_attributes(struct kvm *kvm, struct kvm_gfn_range *range); +#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES static inline bool kvm_mem_is_private(struct kvm *kvm, gfn_t gfn) { return IS_ENABLED(CONFIG_KVM_PRIVATE_MEM) && diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 74c4c42b2126..b3f4b200f438 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2435,7 +2435,6 @@ static int kvm_vm_ioctl_clear_dirty_log(struct kvm *kvm, } #endif /* CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT */ -#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES /* * Returns true if _all_ gfns in the range [@start, @end) have attributes * matching @attrs. @@ -2472,14 +2471,6 @@ bool kvm_range_has_memory_attributes(struct xarray *mem_attr_array, gfn_t start, return has_attrs; } -static u64 kvm_supported_mem_attributes(struct kvm *kvm) -{ - if (!kvm || kvm_arch_has_private_mem(kvm)) - return KVM_MEMORY_ATTRIBUTE_PRIVATE; - - return 0; -} - static __always_inline void kvm_handle_gfn_range(struct kvm *kvm, struct kvm_mmu_notifier_range *range) { @@ -2644,6 +2635,15 @@ int kvm_ioctl_set_mem_attributes(struct kvm *kvm, struct xarray *mem_attr_array, attrs->attributes); } +#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES +static u64 kvm_supported_mem_attributes(struct kvm *kvm) +{ + if (!kvm || kvm_arch_has_private_mem(kvm)) + return KVM_MEMORY_ATTRIBUTE_PRIVATE; + + return 0; +} + static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm, struct kvm_memory_attributes *attrs) {