Received: by 2002:ab2:1c04:0:b0:1f7:53ba:1ebe with SMTP id f4csp101612lqg; Fri, 26 Apr 2024 09:50:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVmbLtx1Jv9w5w1VTDwIY52J3HsmiM9+U1ngBbq//pQnUasMNWgK813+PmTfcCw2IU0BvzKgWZtmdSXb+NOmAHgBTKp+gfwaMFDaSYMg== X-Google-Smtp-Source: AGHT+IF5BKg1eSsO2QOnR5VTxfGhR4Iq2xM91dPbGtbHa9c5Bmyn2LB5hPQJL9xZAg8LnXqssz2q X-Received: by 2002:a05:6a20:9190:b0:1ae:3812:945e with SMTP id v16-20020a056a20919000b001ae3812945emr3923539pzd.62.1714150207129; Fri, 26 Apr 2024 09:50:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714150207; cv=pass; d=google.com; s=arc-20160816; b=op2OgYcwGpYttDeRsR+sboN396pKLvAm+1+8C83tVei8pDyNyI3F1EHzeD1HTfKVyH cL7Tg9NIPRDUNWfhEktMxXCUX+kHnyo7kjq9v8sk5h1O3q9b+yr1oPB3/z3/RMv1pzRt V8OHjNppxHbl+6SW5BOwe32PohdWre8bWOVeLjMXfrZpBRQb/EUMhZGdDsFvzYpDbUA9 dtSpxxIjmP25rG1vhajoxwuyTxH+OLkBDHc+PT3Y+z5Isl1x+7n7CYYFbQi8NLnrvpIE N9lUUZ1KUPwrRZ2V93MgjfcqSo+Vzo9olEqCYGOQm/ds4Il/28eaMg0TVXBwf/liUsTC ljPw== ARC-Message-Signature: i=2; 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 :dkim-signature; bh=4ewX/DowDnqHcwiaRF/iXxVQlOHg+443y/+RR0GCm0w=; fh=VR8sDG6nQExPOZUpZb73KDp1I5BFUzZK5W04RQzVnhM=; b=D21GH+B4zKrMckt0sTRGZv+7IoCdHMPXZw2F6E1ppN57TzzcZlgPbqhT/nGb4JPVSS KvmM48uWMddYhcBxYbEWodRcn7PqAc1YPVGp284Ul1Y4QwyzTKo4prwFDt5xkZmxWf/Y BDfT8LrBMBaHPM3edR07RWXb9PPFSJ+lBFWl+haABGLrPK7b5uXiqT1GX7COWu1kwjmd KsbW96zQaQyWZpEHCsJelD6i5hIUheBbrxioJEX23359Txpyp1xIeE1oVup8gKsKE7OE XIxyI1D4LbY849vzcpiSe5KYV5pDQNO4AhYtgzcXnqvAGkpLjsVihtLOLQGmZnNNdqhl m3DQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UL62sLzf; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-160400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160400-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c185-20020a6335c2000000b005f7feb2a619si13187505pga.612.2024.04.26.09.50.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 09:50:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160400-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=@google.com header.s=20230601 header.b=UL62sLzf; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-160400-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160400-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 BB6A42822E2 for ; Fri, 26 Apr 2024 16:50:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A8B9158D92; Fri, 26 Apr 2024 16:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UL62sLzf" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 2932A148FF6 for ; Fri, 26 Apr 2024 16:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714150197; cv=none; b=EA+IzO9gVy5EeQEQCW/ex8xFj79b+jNNm96SIn3FVDmHVAu8sE39pwqv87Bkw4gJ4Ra9HJQhN3hejEBW7F0Tv9afvcaVxnp+qQJ7k1+ojWJnYh4cBlEwJPneHSLQQA/+Atj/cURO2HELGnk/8r0EXN+t5bGVufj3vy/BLdGhxXQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714150197; c=relaxed/simple; bh=dAIh0mYrFaN2fm+UCmMxFACIbmH36yeNdbSzckFjm1c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WeD5AFscNxluoo8XAA3lUpa4N1XnVJDhlUeyBMNjGnF3OI4UHgZ34osgdcp6DkX7Ak0LwXH18MZGJl/2XBsF2J9ohfH/Dqfp93i7VXJ3csGwkHZ9wxPwG9kXtw0/lcqT1M/RtMmyxNuoEuBx3B6M+qgj9koepuTod4BePABXDqE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UL62sLzf; arc=none smtp.client-ip=209.85.128.202 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-yw1-f202.google.com with SMTP id 00721157ae682-61b75ef0453so45018647b3.3 for ; Fri, 26 Apr 2024 09:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714150195; x=1714754995; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4ewX/DowDnqHcwiaRF/iXxVQlOHg+443y/+RR0GCm0w=; b=UL62sLzfBcQm3mdNRySbmOaGEkFhscXij4Yz4mV73nsZN1Syw75WkBPF9mTPot+s4R OZk7rQLuiHzojKIxe5iibiE9MKGfb1JQtcEvnZRx5lvtq6xohGzfM2FtRAAwYfT65thM +R1OPa2S4AWDo1GH2egMGpEvM4wzLBKEM4/kdRMrxgtfLn/0B43SksWWFUZ91gdJIP46 8efeJovSrJOGpQkqMMen/aoq+DJSqxJm+ww+yConRK/CHpCw/X7QWiDh3Ox8PYff21WM w7WH35KfqNv8K0xK/AgXi/Su/x8opg5HHHlcrhOWn3YsnlJ6ZWsbZyUeu4ZR1Po9VKHG WIXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714150195; x=1714754995; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4ewX/DowDnqHcwiaRF/iXxVQlOHg+443y/+RR0GCm0w=; b=dvesBugaX9zrP5ekZ8Dviq0s/iFzU1tytlt1lfJj6+EvwCZ8CsX8tF/Ozu39kf4H4/ h5lGlZdTqyddA6vr2qID1FZOwW7AlnjpMU0I3PNzCALTb6Q8vlZrtv6DUtEhTL+HbX5W TiviQNXTzUZw60wZDqGDDJ3nj38CQ3b/d4lxalIyFcpxT407ZDfur1f3dqP3G2jYrAYi fUys0s0ZMiaYpev0AmgfrlroL4GYqXA4mi4h4Zr/BE8sO3tYDm+Fp6CwlnH6G72w5BBj fx7rvDLDhaj7rMuxS4MADhMmQYmg+zV7qG/IDwUIZtFw4VIuTg1bH7eXci+tbHlr6PE8 8DMQ== X-Forwarded-Encrypted: i=1; AJvYcCV28YMQuTwk58k6CDoX3p1W613//Xj+g4yXlIzHEGaESOrorjEdUAkap1DxAdFdrAG3LLKM2Eo6BNt6+ATsIpNPmioSFCf/x9AToIFz X-Gm-Message-State: AOJu0YyHm1weh1iWIZtsfFOUf4Kem+QAArJGuKS/+6LUwMgN6eI1vVp8 SQuvbMs3aM4M+wQgF4QsWtpvFKI/N45Skeo7fa0h9636Wx6r3XA2BZD5n8CqVV92CgpNiUyDgv9 brw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:8488:0:b0:615:19db:8ee0 with SMTP id u130-20020a818488000000b0061519db8ee0mr664141ywf.1.1714150195245; Fri, 26 Apr 2024 09:49:55 -0700 (PDT) Date: Fri, 26 Apr 2024 09:49:53 -0700 In-Reply-To: <21d284d23a7565beb9a0d032c97cc2a2d4e3988a.camel@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <2daf03ae-6b5a-44ae-806e-76d09fb5273b@linux.intel.com> <20240313171428.GK935089@ls.amr.corp.intel.com> <52bc2c174c06f94a44e3b8b455c0830be9965cdf.camel@intel.com> <1d1da229d4bd56acabafd2087a5fabca9f48c6fc.camel@intel.com> <20240319215015.GA1994522@ls.amr.corp.intel.com> <970c8891af05d0cb3ccb6eab2d67a7def3d45f74.camel@intel.com> <21d284d23a7565beb9a0d032c97cc2a2d4e3988a.camel@intel.com> Message-ID: Subject: Re: [PATCH v19 011/130] KVM: Add new members to struct kvm_gfn_range to operate on From: Sean Christopherson To: Rick P Edgecombe Cc: Tina Zhang , "linux-kernel@vger.kernel.org" , Hang Yuan , Kai Huang , "binbin.wu@linux.intel.com" , "sagis@google.com" , Bo Chen , "isaku.yamahata@linux.intel.com" , "tabba@google.com" , Erdem Aktas , "isaku.yamahata@gmail.com" , "kvm@vger.kernel.org" , Isaku Yamahata , "pbonzini@redhat.com" Content-Type: text/plain; charset="us-ascii" On Fri, Apr 26, 2024, Rick P Edgecombe wrote: > On Fri, 2024-04-26 at 08:28 -0700, Sean Christopherson wrote: > > If the choice is between an enum and exclude_*, I would strongly prefer the > > enum. Using exclude_* results in inverted polarity for the code that > > triggers invalidations. > > Right, the awkwardness lands in that code. > > The processing code looks nice though: > https://lore.kernel.org/kvm/5210e6e6e2eb73b04cb7039084015612479ae2fe.camel@intel.com/ Heh, where's your bitmask abuse spirit? It's a little evil (and by "evil" I mean awesome), but the need to process different roots is another good argument for an enum+bitmask. enum tdp_mmu_root_types { KVM_SHARED_ROOTS = KVM_PROCESS_SHARED, KVM_PRIVATE_ROOTS = KVM_PROCESS_PRIVATE, KVM_VALID_ROOTS = BIT(2), KVM_ANY_VALID_ROOT = KVM_SHARED_ROOT | KVM_PRIVATE_ROOT | KVM_VALID_ROOT, KVM_ANY_ROOT = KVM_SHARED_ROOT | KVM_PRIVATE_ROOT, } static_assert(!(KVM_SHARED_ROOTS & KVM_VALID_ROOTS)); static_assert(!(KVM_PRIVATE_ROOTS & KVM_VALID_ROOTS)); static_assert(KVM_PRIVATE_ROOTS == (KVM_SHARED_ROOTS << 1)); /* * Returns the next root after @prev_root (or the first root if @prev_root is * NULL). A reference to the returned root is acquired, and the reference to * @prev_root is released (the caller obviously must hold a reference to * @prev_root if it's non-NULL). * * Returns NULL if the end of tdp_mmu_roots was reached. */ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm, struct kvm_mmu_page *prev_root, enum tdp_mmu_root_types types) { bool only_valid = types & KVM_VALID_ROOTS; struct kvm_mmu_page *next_root; /* * While the roots themselves are RCU-protected, fields such as * role.invalid are protected by mmu_lock. */ lockdep_assert_held(&kvm->mmu_lock); rcu_read_lock(); if (prev_root) next_root = list_next_or_null_rcu(&kvm->arch.tdp_mmu_roots, &prev_root->link, typeof(*prev_root), link); else next_root = list_first_or_null_rcu(&kvm->arch.tdp_mmu_roots, typeof(*next_root), link); while (next_root) { if ((!only_valid || !next_root->role.invalid) && (types & (KVM_SHARED_ROOTS << is_private_sp(root))) && kvm_tdp_mmu_get_root(next_root)) break; next_root = list_next_or_null_rcu(&kvm->arch.tdp_mmu_roots, &next_root->link, typeof(*next_root), link); } rcu_read_unlock(); if (prev_root) kvm_tdp_mmu_put_root(kvm, prev_root); return next_root; } #define __for_each_tdp_mmu_root_yield_safe(_kvm, _root, _as_id, _types) \ for (_root = tdp_mmu_next_root(_kvm, NULL, _types); \ ({ lockdep_assert_held(&(_kvm)->mmu_lock); }), _root; \ _root = tdp_mmu_next_root(_kvm, _root, _types)) \ 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) \ __for_each_tdp_mmu_root_yield_safe(_kvm, _root, _as_id, KVM_ANY_VALID_ROOT) #define for_each_tdp_mmu_root_yield_safe(_kvm, _root) \ for (_root = tdp_mmu_next_root(_kvm, NULL, KVM_ANY_ROOT); \ ({ lockdep_assert_held(&(_kvm)->mmu_lock); }), _root; \ _root = tdp_mmu_next_root(_kvm, _root, KVM_ANY_ROOT))