Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2716298rdb; Mon, 5 Feb 2024 15:50:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfCWRXSqxFnHxwJNMjnoKWxJj2LnwB9s91qb+Rfsb9YuCTMLrKhWQq0JczF7denKa5MfwW X-Received: by 2002:a17:907:7897:b0:a38:1589:a7cd with SMTP id ku23-20020a170907789700b00a381589a7cdmr298153ejc.30.1707177020527; Mon, 05 Feb 2024 15:50:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707177020; cv=pass; d=google.com; s=arc-20160816; b=QStVQh8T2Jq4mTI0afTx1RxxWOhBr+2UVKr0Khx/12riJPiId1rwQfJc81az4qAAL7 iuTN6s5v6Psf0xGzF0z6/BsHlzYTQSFEscDmcodiC23XbeD+FI5vkk52Wse/CndHlYoJ 45yvmn7XXXODk+AZmoaf4LZeTkveZuueHs4f7mHMdMx145xDnjo3NlmCSLsStRMcy91q GvBp8JvWKcG1osoGXlel3JKTZnJn0KV3ZMktp0ntKtlRXVUnxwtsfgaIkGIw2BBMnt2v GlVhM0udWj+T+6tOh6Xtp9Mxd8StopMe49WqmrSQwLlKZJ5fxIw/uWjbGynK/1MJl5Up IVtQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=CLaCt86KE4z7cIgRB82YaYKlIDPGoF1DhNw2e1I2B8M=; fh=K2qWajKEN8qj9XOp3/zUkYLrA4mBcC1fozdKXEtH7EM=; b=WG6nlxm2rpWpfwJFVvlpZE2aG5a4wWiA9Khe5wklAip059ETwhQ/QGvlvmsspxsGjT Ca3JWXrX/T24fpYwVSo9VfCbUL28QsZF7VqaUy9FzHqv4qqpdt+9Omo8UYjBJJ2brgsL nFwS6iN9YM8WGzkpgHLaKYbcCAhs5u07d6yYA/dHR59yjFyxwBgzvL8Fsut4Fe7BYTv+ QJc7Orx7tr00xz49FndvcbJZZm/pXeHWNabHOq++6N05A0NQ0MLXo1OaN0m/m7mXOOI7 14RLSW1ahDCuIaDyGmRw1iwZIaJ9LDWnxvZp0HHsUDBiRzUFbW4/FHC1ejU11AP9/Xv1 xmcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Xfo7zHy4; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-54104-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54104-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCVifw0Lyym1AcQnWqbVWmGzh4OcBt6ftLaIL/8DcAKSpldQ5ndkTFxNBwIypKyQ2cjqMOUQTvFg/TFBSMTcQLXU9VsA7oUjJmbM084+Lw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lf20-20020a170906ae5400b00a3777178f8fsi374269ejb.630.2024.02.05.15.50.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 15:50:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54104-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=@gmail.com header.s=20230601 header.b=Xfo7zHy4; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-54104-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54104-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 40DED1F23BAC for ; Mon, 5 Feb 2024 23:50:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57E7D4F603; Mon, 5 Feb 2024 23:50:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xfo7zHy4" Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 DA8B64F5E4; Mon, 5 Feb 2024 23:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707177008; cv=none; b=ZBRkmciJWHbHUTSxnZ4HvqYUsc73B2zQh1idDjyTN8fgHk8FNlXFd63vnoHHi2bIKwey4cUKEFDLgVUo2c4S4RKe26J1ZElgvIzGB0UWRLMCIT/oNUCWbRpRkyfzjWOWK5TLV2++h6621v2TxGgpQw5aXGa2IleXsGlKMSxuQYY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707177008; c=relaxed/simple; bh=eMP+pBzXjOisnrJFlhbgFG68K3/hBnqXW+IrLBhZ78k=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=uaBc8YDj5+F45jb9I9xKF56UoPKKQSYTNEuFmr0l8xMNCUWNDrniWRR2WPQYOaGqFy3CCU33wZaLHeDezTW8cikkHQFJF9NOZJxvx56CMdLVphBz/AVHRqaaFovjkoAdodgNi/x8BQeDdSPcu7y7expJoh7uQsSrtSodFFXKwJQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Xfo7zHy4; arc=none smtp.client-ip=209.85.208.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2d09faadba5so27570711fa.1; Mon, 05 Feb 2024 15:50:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707177005; x=1707781805; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CLaCt86KE4z7cIgRB82YaYKlIDPGoF1DhNw2e1I2B8M=; b=Xfo7zHy4QNPRqvIQPzIzSZW7Vlr/zp2/WqQibZpgYzXebE5wMsF2OIyrKirBsyLk3+ yv4VI4V0GgRevNlv1xNiLHkNqkjkIdz4iLotXPu2INRUy/l1nKV6y3s7tsDLpSIiDu3I hrNq5il9AFQwRXw0P4iJYIDeAPQruKtpP3GDSequBpaRn5LmmpMfcj2eDMmR/dnNCmWT f6mfnF8WgACGCBdZB53Hb2esBkBBpfMPNh7Xxoa86tnDZhL1NVJqs7+cc6fiifoVyJjZ pNFM3ZKrK3Ejig4P2c3ZvLvNABJ49VYjW4De4cX7ygmqfdrrZYfws2rmLLqlDJsR77fA ygmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707177005; x=1707781805; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CLaCt86KE4z7cIgRB82YaYKlIDPGoF1DhNw2e1I2B8M=; b=JdI0YlnlScyAxNsfxgkkrJl4duYfQ+vxgA1UYFCKqV/KTOlm9NJvYO1ZQRJIyeDTwT A9PjWYOZn1nIAy25/p8lUjJNqHVv17LgJbYyRwYn0wfj5UzeHHgJx50zi5ih0u3lH6bB LCZ6YvLqC7JdLPG2nb4DPBEQ/6YUtEvD4Pq1f5Bu80kzFUXd80Nb3RtsCF0YNDj59cAN Z7V5ymIHDtJk1FL2H3c1+sggAwDCfX4B5o2gBpl0mvANFx6EAkbz/bBRZ+RnzUjV9Ew4 r0gEM2yQzHJ3tdzX0qAGEnybUoJUmUyYdsscL8IHK2WO6cP8jugr+6RXIv9+BZRGkjhh W8ag== X-Gm-Message-State: AOJu0Yxfx/7LSb1G0civGrg5vxltlPZlllNdS7Bt56El75kx+9X7fMaS h1pM8lJegjYp6eexIq5xbuADtZfKfSPgIG6815xrGY3ZCfswXCTs2fItg+1Uj/4QT9ZcE+Kzdjg 3L3PBXOXrZ/nQtewu3aGsMt8sHVlvWXftwhU= X-Received: by 2002:a2e:7d0d:0:b0:2d0:b291:d017 with SMTP id y13-20020a2e7d0d000000b002d0b291d017mr699202ljc.15.1707177004526; Mon, 05 Feb 2024 15:50:04 -0800 (PST) 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> In-Reply-To: From: Andrei Vagin Date: Mon, 5 Feb 2024 15:49:53 -0800 Message-ID: Subject: Re: [PATCH] kvm/x86: add capability to disable the write-track mechanism To: Sean Christopherson Cc: Andrei Vagin , Paolo Bonzini , linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, Zhenyu Wang , Zhi Wang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 5, 2024 at 10:41=E2=80=AFAM Sean Christopherson wrote: > > 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 thi= s > > driver. > > > > Enabling the write-track mechanism adds a two-byte overhead per page ac= ross > > all memory slots. It isn't significant for regular VMs. However in gVis= or, > > where the entire process virtual address space is mapped into the VM, e= ven > > 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 enabl= ed > > 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 deadlo= ck, 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 th= rough > 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. I think it is a good idea, I don't know why I didn't consider it. Thanks. I will prepare a new patch. Thanks, Andrei