Received: by 2002:ab2:68c1:0:b0:1fd:9a81:d0e4 with SMTP id e1csp574208lqp; Sun, 9 Jun 2024 09:07:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWRI+CgaK3VefIlKnxuhKjuyfxb9jYsV054sPf2r00O2rEOtRCzYeeBlSGeRoN2sb0gXDXTPdttundwWu7ejSK9K7LQKbsDT3jT/mBR4g== X-Google-Smtp-Source: AGHT+IEZpkfnQVgbyvb0JGMDYDqNzwPGT82zihCxkroCsHtSeH3MnCEJKwWM8CFoxfSYm9N3lpgi X-Received: by 2002:a05:6a21:3294:b0:1af:86da:3f7 with SMTP id adf61e73a8af0-1b2f969ed9bmr7487812637.4.1717949247953; Sun, 09 Jun 2024 09:07:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717949247; cv=pass; d=google.com; s=arc-20160816; b=Xu2Y4T7tBOeSDIDMuq2LoZFHz+K0PAgzTIWYH1QyODLuFBT6Ss8n6q5YbAkS8z1neC yuEpBVtOP0995fmM+Hkj0Q00GUEs5puNG2pTa6ogvm5IM0wipqtFafPZC3xWPOvYPk2K +K3MpfwfemyN/Vf0TIlGfUwmTehnV1cbsWZ3srH1gO005KgWBIik/BDI7fSEsgqN2KAg XOFUaJiIKlnvzUgd2CnJr/9znCPG6gszEclHN0kztgXRYBCG22PRgLYTrQJ1Mbn4DWVX 28GkR58FfnYyr2Dnk6J9jt5kB2zaUtjQ+Sd3efsSe7qpKBDkZ0rr47csQ0/HdPgxsRYX ktvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=KQwnm28YLoi/23yqXhNNFcKbD35vEjDl1rOMbl5bsvk=; fh=DkokhLYBLxU2e/zOSp1y+HaxJqPy9ivhmq9EMpyeY/A=; b=YwK+cySKss6IcNb/K6J76bapskvTcsaZOKf+nzFeX1xppHyZj+iMK5lTa+BaIY0A9s 2UwNaqbxFBkeShfHkp2bMuuxdC+QsuqPz/YAbj5h7KcF90RMJVFl7FI5R0W/I0cyMb1+ e9feU+mRpl7LYc2GjfI1pTQ0T3Wxozw7C+fgNwfnmV4u3oUaSqt4xFi6sv0POo/e6hyR IKO9bi/R5Ryz8vsSMFPVFvVpZgmxF+IFV9ESx8o7PtdIQjOJt1gsbqH/W+UqgVfe+EgE 2PflLelS9bWvIc+RI44ToarClT/zr7doy250IStfYahBdjtb4En0geKs2RokdrX9U47F 5eGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=LpPRGVnQ; arc=pass (i=1 spf=pass spfdomain=amazon.es dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-207415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207415-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6eab5e174dcsi1460450a12.728.2024.06.09.09.07.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 09:07:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=LpPRGVnQ; arc=pass (i=1 spf=pass spfdomain=amazon.es dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-207415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207415-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 49B6628224E for ; Sun, 9 Jun 2024 15:57:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E05147F60; Sun, 9 Jun 2024 15:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="LpPRGVnQ" Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) (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 5D4FC46441; Sun, 9 Jun 2024 15:57:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717948651; cv=none; b=NBs2D2hNs6ppF17y4WzwTtIZ6Gr5DHGJlilK6Gcx/n4FQ4BChacN0rvxZEXG07P9HlZ0ma+s7HsoSrGxyq3H5MXysjKn421NPgp1z69MXLeELLryhxRF8KJ2EfwvF/4AwNHNOPLKxieGs8MoOmO4QRxUhl7KmIT5pLBchXqTX+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717948651; c=relaxed/simple; bh=+Tv5yHEFjqh1Rpgd3wuBbZaDYV3FvrXaVRj6ufcU9Qk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AU60hHQWwN56PeTovA3IWZZLrcSNT+BLYm6JCAGKtLPXJex1ZUUmI79h1T2VEoDECSnEe71PIbtpJCxxoHY/Y16kSWSHl9uDdFEp+Uv8O37zNICJHELHe3KqjLx5HhFkfz0UlT+8zCzHB/3gewoXLkq0e+oRX+UFQJzGBdWejCA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.es; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=LpPRGVnQ; arc=none smtp.client-ip=99.78.197.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.es DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1717948650; x=1749484650; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KQwnm28YLoi/23yqXhNNFcKbD35vEjDl1rOMbl5bsvk=; b=LpPRGVnQf5PyIoUwweMi1F3GKECPH3BVKc/ouZsCNg5Rdv+PcSa4ZBbR kCvzxCTf2HvVSImJjGS2hjCeXfmlubzE6ILQkV8QpurnvF1uO7/jdjnFa UmkM0OkK4LpDWrJWiomo6H++0JtWr4NW9lKiyNsLXxd9WS9hwE1pZ0Qkp g=; X-IronPort-AV: E=Sophos;i="6.08,225,1712620800"; d="scan'208";a="302170451" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2024 15:57:28 +0000 Received: from EX19MTAEUB002.ant.amazon.com [10.0.17.79:16374] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.31.105:2525] with esmtp (Farcaster) id aaf56908-2e02-4c60-8d3f-48c034269da9; Sun, 9 Jun 2024 15:57:27 +0000 (UTC) X-Farcaster-Flow-ID: aaf56908-2e02-4c60-8d3f-48c034269da9 Received: from EX19D004EUC001.ant.amazon.com (10.252.51.190) by EX19MTAEUB002.ant.amazon.com (10.252.51.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Sun, 9 Jun 2024 15:57:27 +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.1258.34; Sun, 9 Jun 2024 15:57:21 +0000 From: Nicolas Saenz Julienne To: , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH 13/18] KVM: x86/mmu: Avoid warning when installing non-private memory attributes Date: Sun, 9 Jun 2024 15:49:42 +0000 Message-ID: <20240609154945.55332-14-nsaenz@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240609154945.55332-1-nsaenz@amazon.com> References: <20240609154945.55332-1-nsaenz@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D041UWB001.ant.amazon.com (10.13.139.132) To EX19D004EUC001.ant.amazon.com (10.252.51.190) In preparation to introducing RWX memory attributes, make sure user-space is attempting to install a memory attribute with KVM_MEMORY_ATTRIBUTE_PRIVATE before throwing a warning on systems with no private memory support. Signed-off-by: Nicolas Saenz Julienne --- arch/x86/kvm/mmu/mmu.c | 8 ++++++-- virt/kvm/kvm_main.c | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index b0c210b96419f..d56c04fbdc66b 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -7359,6 +7359,9 @@ void kvm_mmu_pre_destroy_vm(struct kvm *kvm) bool kvm_arch_pre_set_memory_attributes(struct kvm *kvm, struct kvm_gfn_range *range) { + unsigned long attrs = range->arg.attributes; + bool priv_attr = attrs & KVM_MEMORY_ATTRIBUTE_PRIVATE; + /* * Zap SPTEs even if the slot can't be mapped PRIVATE. KVM x86 only * supports KVM_MEMORY_ATTRIBUTE_PRIVATE, and so it *seems* like KVM @@ -7370,7 +7373,7 @@ bool kvm_arch_pre_set_memory_attributes(struct kvm *kvm, * Zapping SPTEs in this case ensures KVM will reassess whether or not * a hugepage can be used for affected ranges. */ - if (WARN_ON_ONCE(!kvm_arch_has_private_mem(kvm))) + if (WARN_ON_ONCE(priv_attr && !kvm_arch_has_private_mem(kvm))) return false; return kvm_unmap_gfn_range(kvm, range); @@ -7415,6 +7418,7 @@ bool kvm_arch_post_set_memory_attributes(struct kvm *kvm, struct kvm_gfn_range *range) { unsigned long attrs = range->arg.attributes; + bool priv_attr = attrs & KVM_MEMORY_ATTRIBUTE_PRIVATE; struct kvm_memory_slot *slot = range->slot; int level; @@ -7427,7 +7431,7 @@ bool kvm_arch_post_set_memory_attributes(struct kvm *kvm, * a range that has PRIVATE GFNs, and conversely converting a range to * SHARED may now allow hugepages. */ - if (WARN_ON_ONCE(!kvm_arch_has_private_mem(kvm))) + if (WARN_ON_ONCE(priv_attr && !kvm_arch_has_private_mem(kvm))) return false; /* diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 14841acb8b959..63c4b6739edee 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2506,6 +2506,7 @@ static int kvm_vm_set_mem_attributes(struct kvm *kvm, gfn_t start, gfn_t end, struct kvm_mmu_notifier_range pre_set_range = { .start = start, .end = end, + .arg.attributes = attributes, .handler = kvm_pre_set_memory_attributes, .on_lock = kvm_mmu_invalidate_begin, .flush_on_ret = true, -- 2.40.1