From patchwork Wed Nov 8 11:17:54 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: 162975 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp843576vqo; Wed, 8 Nov 2023 03:23:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJjNYjJNS/6IPbLyKKKOWQyhzBU+WfVwQ/VXz+LxR/hs/HH8N2XjC2B/NY3goOAroNf41Q X-Received: by 2002:a05:6871:7248:b0:1dc:704c:7c83 with SMTP id ml8-20020a056871724800b001dc704c7c83mr1793373oac.30.1699442609939; Wed, 08 Nov 2023 03:23:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699442609; cv=none; d=google.com; s=arc-20160816; b=jvX4Au/l6NgNC/K/eTnzLO7If1gqgKvelma1HEOVHJSufP4fP5Ed0d/dp59t2OHh45 jDDWRb4mr0uhSrBQz+yiY8upkwzciUGegGka8u1D/7C/YpVhB4iYiiMUDXUrcK0oVvTE lEBa3pqR0auXEyVqxxKAWrKfZ9/+dILie//x0FsGm/oiFBd8fBMZLMzkxsYdjaBPaBua gZrBXzs/n1BSoPNCQzvckSHNFDcMMp88DmqLVqx3Y/El2nc6pHRkjSFfqGykXH0dK+rz lzm36kbVUsSU6/jk/psS3k1sCE+PYH4YMdCs/wQi89W/+Fz5hgzoRDvKk/oH9vayZQx1 NfHg== 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=RgZghGDVPKK1y7/jRC8uX7Dc8zxHwsko9uAHRrK/b/E=; fh=Qdq7NqGm5JR9LpctBpXjoRI38Lb2mCk6xy26GEDp1Bg=; b=AkD6o3098WP514zBtOeUG6CTc8nsdb53oflxbhqb87fjiOb6jynxWOGOWjy7aY+y46 iyjZKX2wDKwoP81+tJj0lGbTNOEIjfjTsJPXWNfpN0u/h0QQrDki7ARY8esLwcqfZJ+8 +DXED0OYyJ/xuj7cCBg7dXwzc0jO9cgXovEEgaPd9kxm9NR6EpDX7zHOlkuONW+K+naW +S7vyLaq0xY43ApNMqDmlAugbSk0/W1npY3sxMITqTjeo6KCVeQK4h7zUkJl9hSf2hjv kTDbvRXsQlbiclzegNWvzz1vPtKJjaqk+7n3PDU4rK9sCWnoYhRAlxQcv2SPyqOsfvWD lU+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=KZxnAQq5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id g192-20020a636bc9000000b0057c2f61474asi1620850pgc.290.2023.11.08.03.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:23:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=KZxnAQq5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id E479183AC0C1; Wed, 8 Nov 2023 03:23:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344805AbjKHLXX (ORCPT + 32 others); Wed, 8 Nov 2023 06:23:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344818AbjKHLXA (ORCPT ); Wed, 8 Nov 2023 06:23:00 -0500 Received: from smtp-fw-52002.amazon.com (smtp-fw-52002.amazon.com [52.119.213.150]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D763D1FF6; Wed, 8 Nov 2023 03:22:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1699442578; x=1730978578; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RgZghGDVPKK1y7/jRC8uX7Dc8zxHwsko9uAHRrK/b/E=; b=KZxnAQq5x79fecGfeJTdJwy7Asc3OjoDvMstzCK0CsEroWHde6inNPoH bAU2j0GSTfcIUcHmqvV6Wua1ulzGl2alPEfcFhkNCqK5ql5IvNSb6LsP9 lasAo5p7cJN+MQIsFD4w09XMJeESBGC7AfQ4VSo0pakLEqgS+5nD3v4yh k=; X-IronPort-AV: E=Sophos;i="6.03,286,1694736000"; d="scan'208";a="593808027" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-d23e07e8.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-52002.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2023 11:22:57 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1d-m6i4x-d23e07e8.us-east-1.amazon.com (Postfix) with ESMTPS id 6925380801; Wed, 8 Nov 2023 11:22:52 +0000 (UTC) Received: from EX19MTAEUC002.ant.amazon.com [10.0.17.79:36451] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.43.105:2525] with esmtp (Farcaster) id 6ea11377-1737-4520-be2a-aa11258cc468; Wed, 8 Nov 2023 11:22:51 +0000 (UTC) X-Farcaster-Flow-ID: 6ea11377-1737-4520-be2a-aa11258cc468 Received: from EX19D004EUC001.ant.amazon.com (10.252.51.190) by EX19MTAEUC002.ant.amazon.com (10.252.51.181) 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:51 +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:46 +0000 From: Nicolas Saenz Julienne To: CC: , , , , , , , , , , , , , , , Nicolas Saenz Julienne Subject: [RFC 21/33] KVM: Pass memory attribute array as a MMU notifier argument Date: Wed, 8 Nov 2023 11:17:54 +0000 Message-ID: <20231108111806.92604-22-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 (snail.vger.email [0.0.0.0]); Wed, 08 Nov 2023 03:23:28 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781994734248139405 X-GMAIL-MSGID: 1781994734248139405 Pass the memory attribute array through struct kvm_mmu_notifier_arg and use it in kvm_arch_post_set_memory_attributes() instead of defaulting on kvm->mem_attr_array. Signed-off-by: Nicolas Saenz Julienne --- arch/x86/kvm/mmu/mmu.c | 8 ++++---- include/linux/kvm_host.h | 5 ++++- virt/kvm/kvm_main.c | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index c0fd3afd6be5..c2bec2be2ba9 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -7311,6 +7311,7 @@ static bool hugepage_has_attrs(struct xarray *mem_attr_array, bool kvm_arch_post_set_memory_attributes(struct kvm *kvm, struct kvm_gfn_range *range) { + struct xarray *mem_attr_array = range->arg.mem_attr_array; unsigned long attrs = range->arg.attributes; struct kvm_memory_slot *slot = range->slot; int level; @@ -7344,8 +7345,8 @@ bool kvm_arch_post_set_memory_attributes(struct kvm *kvm, * misaligned address regardless of memory attributes. */ if (gfn >= slot->base_gfn) { - if (hugepage_has_attrs(&kvm->mem_attr_array, - slot, gfn, level, attrs)) + if (hugepage_has_attrs(mem_attr_array, slot, + gfn, level, attrs)) hugepage_clear_mixed(slot, gfn, level); else hugepage_set_mixed(slot, gfn, level); @@ -7367,8 +7368,7 @@ bool kvm_arch_post_set_memory_attributes(struct kvm *kvm, */ if (gfn < range->end && (gfn + nr_pages) <= (slot->base_gfn + slot->npages)) { - if (hugepage_has_attrs(&kvm->mem_attr_array, slot, gfn, - level, attrs)) + if (hugepage_has_attrs(mem_attr_array, slot, gfn, level, attrs)) hugepage_clear_mixed(slot, gfn, level); else hugepage_set_mixed(slot, gfn, level); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 32cf05637647..652656444c45 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -256,7 +256,10 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu); #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER union kvm_mmu_notifier_arg { pte_t pte; - unsigned long attributes; + struct { + unsigned long attributes; + struct xarray *mem_attr_array; + }; }; struct kvm_gfn_range { diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 6bb23eaf7aa6..f20dafaedc72 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2569,6 +2569,7 @@ static int kvm_vm_set_mem_attributes(struct kvm *kvm, gfn_t start, gfn_t end, .start = start, .end = end, .arg.attributes = attributes, + .arg.mem_attr_array = &kvm->mem_attr_array, .handler = kvm_arch_post_set_memory_attributes, .on_lock = kvm_mmu_invalidate_end, .may_block = true,