Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2578338rdb; Mon, 5 Feb 2024 10:41:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGg5BuQAeKjEto6dv6Zy+uLQ1yCdQKvYUU1aule8jjBHZlniilrBsZX9fJfM6JTh1HpRu/T X-Received: by 2002:a17:906:2b10:b0:a37:e72a:a24c with SMTP id a16-20020a1709062b1000b00a37e72aa24cmr206611ejg.50.1707158467428; Mon, 05 Feb 2024 10:41:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707158467; cv=pass; d=google.com; s=arc-20160816; b=rfsspisbwNErOdoByRQ/uYGfDWaZxDCpI/BQa7ud9QAGNRXUAce6KwDC9iMyCA4mW4 9axTMMb4mRs8szyx52eOfvGmo5Nyfa5wa+ymzMuVgXfR1YTCDLBGAvpyLj5Oc/u6q/EG BShiu984Usy7d8ipadLhN0Ys0uBK/EHa8KRdKWNBOHkl3JVGbs3VgZC+xJKVb7dvtrMM X8rttCGhPlGeh4bQQg6h4QRHzru7p8wJUVjmAnD52BMUWs2toeDKxZjbMYgxT5cF+5m4 vjJgw2u6fBTJr8S578tlb+eoJZ7d9p/bVZt30NG0RQJ9h4rKBDbaxCweS5YnsX9PdAYq PxyQ== 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=55LWoOSB/WgS8nNcVu6xiIo2AyT6nK2cpDVJl/BcjxQ=; fh=yYioHk+e9c/y8caYwRk715m7dZm32YJiYhYoDPYcPj8=; b=SOg/cHUn/ukANE+IbogOYYnVKWY/ryQdTWNWqTveQAuO0qT/VwE0rYIsQpgIqwILNK npjztP/ZZpO9ElOz0ayGo4SQH1XCys7h30IVVpoZJqtIZObZiFFGO2keoJ83lhqexqX+ L1ShviNId5tuVXhv/TNUn3XoPryL1s30qwAqp8jc3gQ2eZ1CU8sYBvZN07UNZ4Jn+qtP OrFxIwZzceFIMLldzRNlEBcUH4jHXjIgIUm0ZuTryc7nXbFKDTUS/e2wv6vuzdN+iF4b MUJdPvetHsLv8hVc0WslI9oGAA1fYFWYgyUmPI0R2EzWVmPc4J/JlrUb2sS9+GKntNgO cvkw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=x2EhI2Y0; 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-53243-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53243-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCV8nYQMyBt5Wzj/4ODOKFTkPmAKzloFrdp2lUbXtTrxXsggtqdrCO7R0m1TnGddqkjVu7e4oJMw7x8KpJer/V288fIM+1lRdMDxEYYRcg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gh3-20020a170906e08300b00a379065e8besi106332ejb.338.2024.02.05.10.41.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:41:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53243-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=x2EhI2Y0; 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-53243-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53243-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2F7651F23352 for ; Mon, 5 Feb 2024 18:41:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7191481CB; Mon, 5 Feb 2024 18:40:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="x2EhI2Y0" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 A8AA345953 for ; Mon, 5 Feb 2024 18:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707158455; cv=none; b=cpayAkqceuw1+wuzon48ZykVsLRAcXmjoZqGZU30yCxJzjz/OPrMAS0wBA3fPIDHP+vrTvg32b/TJ4fAXYwhB+ecvfOFDknRfti1j5Ye3AG2SnQvRB608dHc/KJW2SzrByhKUybd4QXBfkQSQsPYxcn0en7KPK5Jz7oRKqMzWgw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707158455; c=relaxed/simple; bh=5KzOV2uFBphcx2s5QvJ6Q/kFoGTmnuoVCQbC2QKOQGc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=D/ImOrXtJi6hQ9tP8xKViynWpwD+ov3OXkeMPmU+VKofAJvdUdrJl18+ZVdUnY30ilQ1sIDfS4aTB3V5Wr8FAL6O2CUeH1EIhV0vzweyeyHaRjvPHUs/QjBTQVnf3wq0JSrT7DRGfbAqa81dqZXx4XZ9cpBbftZQuveiUnrW6qo= 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=x2EhI2Y0; arc=none smtp.client-ip=209.85.219.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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b269686aso95276276.1 for ; Mon, 05 Feb 2024 10:40:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707158452; x=1707763252; 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=55LWoOSB/WgS8nNcVu6xiIo2AyT6nK2cpDVJl/BcjxQ=; b=x2EhI2Y0w0IVZyCXec8Fon02Ano/Sl5QgF/z8gFkScthDXtwWwq/iVj5102mEftGov ebT9tL09F5EhEVJN4WgKivaGg+7BSuj4IGwR4d+2+enjs8vdKA3Hmgqaa6xCVypk0KEw JmTifuQEJfQDhgpPTS/h46FevXCGypeLJCqMoJlA/WsEyS1/5uukzBXcZ73HK4FdftF+ s39rY19B/8HgHcJPldFm4dh/fZ1OxPPZFm5B7MSRTGJHwne2FiZkrAfHiT2VCv9VPTL9 QbGV9m9GCVwJENquAswUCXW+SE7q1cdHfVP2tzxXjJJhwdybEitQoTD7QJQIZ1oPJbfH 7+Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707158452; x=1707763252; 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=55LWoOSB/WgS8nNcVu6xiIo2AyT6nK2cpDVJl/BcjxQ=; b=S81J3aEmmDnCv/X/Q3IlMN0PQOm/XuVd4WYLRkElRUTDg+UWsnuFKN710dIBNn8n13 U1z5/k6BpoY6/7qe6nuOG+h89e1aeHCmQpyoX7aGySANOQLuxLMKSifP6ak2o3jAswHD o/fHJtITfcLh/tBMxDz7nc/PWv3BzNq1ymyE2Sq+iAEnOSHNed8mfRUxWwqgm/50nodv Anie91A0mkun4oNhvDYEiQIlNPQZCLH9Uh0JGrx2bQcDJGJyYvBMzBf99lp7/OKeByZi eU4ab6WwqV88C7PdGsn/DbaZiOeMCbvyCGFTInDHr9tPqDQZjRGdv069Xq971a5DF4j+ 2+Og== X-Gm-Message-State: AOJu0YzVwjbaMPWKYBxCbCmQVquEKw66brEXu6RmiOhnpZ67KCSeYW2w peFyTk26KihdR9UymXsOJ34C+0TQcTGDdOELoaWP+JYbMHTPj0o6usEqOHBssTjN+R1G40CC+XY wRg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:2186:b0:dc6:ece2:634c with SMTP id dl6-20020a056902218600b00dc6ece2634cmr6729ybb.11.1707158452741; Mon, 05 Feb 2024 10:40:52 -0800 (PST) Date: Mon, 5 Feb 2024 10:40:51 -0800 In-Reply-To: <20240205173124.366901-1-avagin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240205173124.366901-1-avagin@google.com> Message-ID: Subject: Re: [PATCH] kvm/x86: add capability to disable the write-track mechanism From: Sean Christopherson To: Andrei Vagin Cc: Paolo Bonzini , linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, Zhenyu Wang , Zhi Wang Content-Type: text/plain; charset="us-ascii" On Mon, Feb 05, 2024, Andrei Vagin wrote: > The write-track is used externally only by the gpu/drm/i915 driver. > Currently, it is always enabled, if a kernel has been compiled with this > driver. > > Enabling the write-track mechanism adds a two-byte overhead per page across > all memory slots. It isn't significant for regular VMs. However in gVisor, > where the entire process virtual address space is mapped into the VM, even > with a 39-bit address space, the overhead amounts to 256MB. > > This change introduces the new KVM_CAP_PAGE_WRITE_TRACKING capability, > allowing users to enable/disable the write-track mechanism. It is enabled > by default for backward compatibility. I would much prefer to allocate the write-tracking metadata on-demand in kvm_page_track_register_notifier(), i.e. do the same as mmu_first_shadow_root_alloc(), except for just gfn_write_track. The only potential hiccup would be if taking slots_arch_lock would deadlock, but it should be impossible for slots_arch_lock to be taken in any other path that involves VFIO and/or KVMGT *and* can be coincident. Except for kvm_arch_destroy_vm() (which deletes KVM's internal memslots), slots_arch_lock is taken only through KVM ioctls(), and the caller of kvm_page_track_register_notifier() *must* hold a reference to the VM. That way there's no need for new uAPI and no need for userspace changes.