Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1363535rdd; Wed, 10 Jan 2024 18:01:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IERS0kFaTxtD52+Dy7IvySOgOb8AO/eWlRQmNtfPXBK8Md7hlm9ZGQkm8722j5hCluS3Ny1 X-Received: by 2002:a17:902:dad1:b0:1d5:6600:3d96 with SMTP id q17-20020a170902dad100b001d566003d96mr68679plx.0.1704938519069; Wed, 10 Jan 2024 18:01:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704938519; cv=none; d=google.com; s=arc-20160816; b=e0n/JcqbMB8QVXGIeGrsgEYC0uUZNJ73itCvPWscFKFYXb9b/Hv9SfhZ+oi9/6+Mlx +ntj7tAYFO5PyeTl9wc46AgJjPLMGiBk4m3A4Z/j3rclHJ53+LZPBPZ/V1U2s22tRxpy u+PxIx6F+JP3qwYg/MN70os1ske6w4xtRk+D2x3lA1+0PP4XYFrZfVtsDJ0yfdRk4Qm6 8dahd80fkAj/MDMD2uazHfpXfXNwPyr8fgOYiDCf3v0Agib6LLzdtVX5/s9AqMphouPI xz/M6csTBMULNvjOUfstLdlNT9U/TKXkvw2jT7f5KTTBAW5teB/b83DF0mE9p9czVOzY Gz8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=l9/uUlAc1H6ges5WZZ0my7oKxRDSlYhBNEqPxH+MbT4=; fh=YsubNrZQ0gWuK57m7npwpfEBQGmQ6VfO6ArPkYLo2pk=; b=Wl7xEZlYcWqCOdF9txKJNBzyWeRQ+yc+0ENrT9ivkLcLMRb5khxYyGUlZbWiQwaaM9 LD1yAlkbILjTTCsBTDj75Gog//dUadRKG5EeYUXmrWv9FDW8eX3W2QkMZ1cogZRdfepe fboyI2Ls2AydnO6/91t0DDkFMLDsjzT1kJK63xcPOkcsTw954ttIpwXLf/bdlwZ6w1q1 AuU2ITLQzLcpHW50JKvAgkFWmce9LCHvnega6mpwj5LZv1sU/dC8590mm6RyWL0VpFVY KN+E84Ni+7V+gLUkTf564Jjzrr9cKv2dn+0XtNzChXARi6VUjvwKW+K6XbSJMD1ArdGF 78hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Lh6jSNZ6; spf=pass (google.com: domain of linux-kernel+bounces-22945-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22945-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j190-20020a6380c7000000b005cef24b3015si45182pgd.219.2024.01.10.18.01.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 18:01:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22945-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Lh6jSNZ6; spf=pass (google.com: domain of linux-kernel+bounces-22945-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22945-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 B03CF289E87 for ; Thu, 11 Jan 2024 02:01:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4973953A5; Thu, 11 Jan 2024 02:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Lh6jSNZ6" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1757A20F8 for ; Thu, 11 Jan 2024 02:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-db402e6f61dso6228135276.3 for ; Wed, 10 Jan 2024 18:00:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704938458; x=1705543258; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=l9/uUlAc1H6ges5WZZ0my7oKxRDSlYhBNEqPxH+MbT4=; b=Lh6jSNZ6lnn/YTXtA//qLIgGy6u0hLEtPrmRi5Pdkw5vn/FTbaSzmLXnYkxLsE2128 c0v/kjJso7bu1epNSy5w9FvTq98LzRZxnBtZmDkDXt4O+FG/bCycXVhVY2FBpTEkmqsW 5HSkpjkp3MphMjU1+zHcgujvsvldwir1V/YaFzYBqgPSWwrnUtt0+6yXFqJriQW6D8bD RzjRibYTT/p7+tG5Q+xBEy6Klu1clqcfCxRWZSGGjuxbP649zS7h7S5DtLhJe2oTmw/Y CUp2+HAglm1fYnMhIXAV5Xlqq75XUA4ApEW3j90EkddrIq2VljHYqDuKXLjzQIyPxDm9 p52A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704938458; x=1705543258; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=l9/uUlAc1H6ges5WZZ0my7oKxRDSlYhBNEqPxH+MbT4=; b=ptsHCFKv8GLW8Bg3E/q/8jvUBIcPIVmLIABEJwIaEqYtOq4AguDL8m3mum80xsDSj6 boRPsPuPU47DcK0CQ3otInNErZRUvU6j4iUjAn90IaL86+QVsfK5Ln5gDPkynJSerAIE 0CxFkrfOQZQ08n0tuVOMZWgFvHf8NbWgj1wFio4UDJuPfmUdcrN78rREhvbvwTcx9NLs 2KK5iCryMwCujgma8z9V8psAt9J8vGYLC61/LvK0+Q0Qg0klBPQtNoWrZ0/sxU9UeRei vRXoqelVX63zdL9sAxjBxMBcp/hVLhDgh8CEJTJEOIwVXze6seNuM3hQtGyGLGCbEu5K WSrw== X-Gm-Message-State: AOJu0YzTLkWTLH4JpeEOPSzNVMS6y2MGLdhw3jFyHwc34KA01P+AhGkX cz/wo0rQx5nQWyZPT4jwiibOE+F5CHIkIyEYCg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:9f02:0:b0:dbe:642c:2124 with SMTP id n2-20020a259f02000000b00dbe642c2124mr222202ybq.0.1704938458187; Wed, 10 Jan 2024 18:00:58 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 10 Jan 2024 18:00:43 -0800 In-Reply-To: <20240111020048.844847-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240111020048.844847-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog Message-ID: <20240111020048.844847-4-seanjc@google.com> Subject: [PATCH 3/8] KVM: x86/mmu: Allow passing '-1' for "all" as_id for TDP MMU iterators From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Pattara Teerapong Content-Type: text/plain; charset="UTF-8" Modify for_each_tdp_mmu_root() and __for_each_tdp_mmu_root_yield_safe() to accept -1 for _as_id to mean "process all memslot address spaces". That way code that wants to process both SMM and !SMM doesn't need to iterate over roots twice (and likely copy+paste code in the process). Deliberately don't cast _as_id to an "int", just in case not casting helps the compiler elide the "_as_id >=0" check when being passed an unsigned value, e.g. from a memslot. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 68920877370b..60fff2aad59e 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -149,11 +149,11 @@ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm, * If shared is set, this function is operating under the MMU lock in read * mode. */ -#define __for_each_tdp_mmu_root_yield_safe(_kvm, _root, _as_id, _only_valid)\ - for (_root = tdp_mmu_next_root(_kvm, NULL, _only_valid); \ - ({ lockdep_assert_held(&(_kvm)->mmu_lock); }), _root; \ - _root = tdp_mmu_next_root(_kvm, _root, _only_valid)) \ - if (kvm_mmu_page_as_id(_root) != _as_id) { \ +#define __for_each_tdp_mmu_root_yield_safe(_kvm, _root, _as_id, _only_valid) \ + for (_root = tdp_mmu_next_root(_kvm, NULL, _only_valid); \ + ({ lockdep_assert_held(&(_kvm)->mmu_lock); }), _root; \ + _root = tdp_mmu_next_root(_kvm, _root, _only_valid)) \ + if (_as_id >= 0 && kvm_mmu_page_as_id(_root) != _as_id) { \ } else #define for_each_valid_tdp_mmu_root_yield_safe(_kvm, _root, _as_id) \ @@ -171,10 +171,10 @@ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm, * Holding mmu_lock for write obviates the need for RCU protection as the list * is guaranteed to be stable. */ -#define for_each_tdp_mmu_root(_kvm, _root, _as_id) \ - list_for_each_entry(_root, &_kvm->arch.tdp_mmu_roots, link) \ - if (kvm_lockdep_assert_mmu_lock_held(_kvm, false) && \ - kvm_mmu_page_as_id(_root) != _as_id) { \ +#define for_each_tdp_mmu_root(_kvm, _root, _as_id) \ + list_for_each_entry(_root, &_kvm->arch.tdp_mmu_roots, link) \ + if (kvm_lockdep_assert_mmu_lock_held(_kvm, false) && \ + _as_id >= 0 && kvm_mmu_page_as_id(_root) != _as_id) { \ } else static struct kvm_mmu_page *tdp_mmu_alloc_sp(struct kvm_vcpu *vcpu) -- 2.43.0.275.g3460e3d667-goog