Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1221857pxu; Wed, 6 Jan 2021 16:22:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQ5KMs/ERV3bQaarg/BZ4bgFT7KQ6e1VvyZTs5kic8+lPJEmuu7mIUuQtCpUpXCwUF+u9o X-Received: by 2002:a17:906:52c1:: with SMTP id w1mr4738599ejn.214.1609978962122; Wed, 06 Jan 2021 16:22:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609978962; cv=none; d=google.com; s=arc-20160816; b=K9fTQynAvc4fSYSGN38sb0Et/UwRvh500kVhV7YI1ZIGaXiRqCST95lhgTFq/SDM70 JToKne06QrzhQUHyjy7kUk6YZ/mxBqspmeDOEPmq+aXCqBYjAQfkru/H3+6WmwnGCu/R hzsVQNjpR88wtaY9JlrI9qot3ragXB2uG3Bio02kwM6XXi2DR4Yd0xSxxzcOJ8kkYoQh eHfM/Z9rBOA5weuvm9LJ0QqSI3QXoJ31/yYaRBvaEkAYVrmAGQ5UeA+muimQrPGSukmK V6m6F3R7E0b33niPdW/Hco9zL4Ztd0NzFN5v9jthavu6ZsLxSe3CbHZikkUsy8/d5u45 8QFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=dDiuE/L+TEOVkofWeADZyQOWx+prBVUG+hG/zE7qjqw=; b=VUeLrV/VJPp3yw2LO4z/yPsn3tEe0lUJ+W4GSsUmMW0XGAo8LFNLNBsEwtcB0tVykY 3oQmtYfOiCU+F5M+LESIOvQPLMjNY/eNIUQYQem3A6re9+1Pw1qUtDMOaCyVUcQmd/VI b3hfjqcm6T0QZ/ZXM1qA047H5QTDYIakrA7xP0qdxZO7deN5828xK3cFwwNJR+jOY2tJ 0RTpm852/4tPf3wLTFlE2GulGYCbvNPFM068JV8AzIBixut2Rt+v9e8EN/wF+dOh0ZjH T9vIBtqKX+qkACTvHXW1fmvUts3f3Qbc0Zoj2vNoLzvXYhb9lyHdI+P25ZM28LJuWhlZ SDWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VkjczQkD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg13si1748614ejc.352.2021.01.06.16.22.18; Wed, 06 Jan 2021 16:22:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VkjczQkD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727704AbhAGAUW (ORCPT + 99 others); Wed, 6 Jan 2021 19:20:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727464AbhAGAUV (ORCPT ); Wed, 6 Jan 2021 19:20:21 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81F75C061372 for ; Wed, 6 Jan 2021 16:19:41 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id t16so2711619pfh.22 for ; Wed, 06 Jan 2021 16:19:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=dDiuE/L+TEOVkofWeADZyQOWx+prBVUG+hG/zE7qjqw=; b=VkjczQkDv6uSysLxiEUHoxuQ+DbKhDcWrtgG8nIXiIk9txn9MKBRgvUvoRfyoTVdn6 F+V3rRcP5bSzLl0Zu2tc03tpgWRRfCP4476e7Wx8ki01QtG8Xw8UXuqfuOhiZu0eN0ZC l/uisVbTdVRibbAkrN0eGjVTnXuoFxvf1hrzN5daVrnwrtoP4/J1J9JohxHNaT7tC9Ow uG2mCdoqC/rM8zsbXCyc6qyz2PlYSiuysFaaeyb0/w7ZOc2rOCCg3I06N6+aQQbIP+uj 7pz7Q9VyJCQkD9MoX/bKjNxU+fJmeL8vziSQGhhuxkVn+XmeRjM/p31kv+pKd4Ygxk5A +iRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=dDiuE/L+TEOVkofWeADZyQOWx+prBVUG+hG/zE7qjqw=; b=EtH9ykKTKieVru/7KmXaRTw/UD1LGQ6lpx54krWqYZjYhd/wWq77PGX5/68E9y3WVf F3GSivVeCo2d2VeuA5StSPtGnt0oIReBuSJ1gtmx9mqyr6Wcmvw+tX+WWrT4dDzD6Rhi uG2JRqy30e4sbzYpCloqB1kO2mLtjS/6lrMtF8UC7IiAJ0v8l3nnQhWdQR+MuTVwMoQq McztzWh+Z8Zm0GrSD+QKyAQvvsBzUEENP/QV5e6aerYXbi7tr60yGK/NvQuaO6yxUS4b QTr/nViaXZnm0ByHG5My4HV4druwWqqEjYT/MGLPvOjgIF9DY8MwKiWlq/5ZSi1zvQcI af9A== X-Gm-Message-State: AOAM533bczsmDYxiOGgW1W9o2Vzq81fHu5MSkQIemMaIQswfvskrgC5U bEP3MImAoR/KUnbGH+bikrU1B3KDDoQRXmQLLBWBB94BI7OYsroJByie8PrTAusqWW9Dxh2UUEg DPoLQa+YfVK0M3XPByIsn8/51wPmOkkl9MWgs3Q4OedkqJS3D0bUxwuBw6BhmxI9EK6tmEt6D Sender: "bgardon via sendgmr" X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:f693:9fff:fef4:a293]) (user=bgardon job=sendgmr) by 2002:a17:90b:14d3:: with SMTP id jz19mr6654541pjb.196.1609978780963; Wed, 06 Jan 2021 16:19:40 -0800 (PST) Date: Wed, 6 Jan 2021 16:19:35 -0800 In-Reply-To: <20210107001935.3732070-1-bgardon@google.com> Message-Id: <20210107001935.3732070-2-bgardon@google.com> Mime-Version: 1.0 References: <20210107001935.3732070-1-bgardon@google.com> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [PATCH v3 2/2] KVM: x86/mmu: Clarify TDP MMU page list invariants From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Peter Shier , "Maciej S . Szmigiero" , Leo Hou , Ben Gardon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The tdp_mmu_roots and tdp_mmu_pages in struct kvm_arch should only contain pages with tdp_mmu_page set to true. tdp_mmu_pages should not contain any pages with a non-zero root_count and tdp_mmu_roots should only contain pages with a positive root_count, unless a thread holds the MMU lock and is in the process of modifying the list. Various functions expect these invariants to be maintained, but they are not explictily documented. Add to the comments on both fields to document the above invariants. Signed-off-by: Ben Gardon --- arch/x86/include/asm/kvm_host.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 39707e72b062..2389735a29f3 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1010,9 +1010,21 @@ struct kvm_arch { */ bool tdp_mmu_enabled; - /* List of struct tdp_mmu_pages being used as roots */ + /* + * List of struct tdp_mmu_pages being used as roots. + * All struct kvm_mmu_pages in the list should have + * tdp_mmu_page set. + * All struct kvm_mmu_pages in the list should have a positive + * root_count except when a thread holds the MMU lock and is removing + * an entry from the list. + */ struct list_head tdp_mmu_roots; - /* List of struct tdp_mmu_pages not being used as roots */ + + /* + * List of struct tdp_mmu_pages not being used as roots. + * All struct kvm_mmu_pages in the list should have + * tdp_mmu_page set and a root_count of 0. + */ struct list_head tdp_mmu_pages; }; -- 2.29.2.729.g45daf8777d-goog