From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B68BDC4167B for ; Thu, 2 Nov 2023 14:41:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231201AbjKBOli (ORCPT ); Thu, 2 Nov 2023 10:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbjKBOlg (ORCPT ); Thu, 2 Nov 2023 10:41:36 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B33813A for ; Thu, 2 Nov 2023 07:41:33 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-da03ef6fc30so1219681276.0 for ; Thu, 02 Nov 2023 07:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698936092; x=1699540892; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=xhBeRDHIuw2MhHJCiZzpmIP+VopsidfcOzvL++iqJMc=; b=E8ebSa9c6or9LYXHIbFKFTAuADYgYjM9eje8EFyHBw87GFEdLwCKcJ8i1m5xxy81u1 CRy05fuVNYjnG8S/xFRYsuF7mdsaYzuwSiFkg18oH0iky8DUUq5R6Z5dgpjX36yCBdD1 nkH2lDdLXHQXXHluGOv3deTIP/fInRgWG+/X2dyS3jabjNSq6MktO6nIU4sQfTNhsyxv z492XWb4v+voUQCfH2CXS+uivzWYdEjTDaxFPf70Xxr9agZjx6YdIJBoSoxp3pEvfIPX H7ufQX/vWv5ohN8/0DPI+udxnJG8E7NBGxZT66sCftP7Xj/OOJeV6NJvDIDZ1UP05ULr 3TvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698936092; x=1699540892; h=content-transfer-encoding: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=xhBeRDHIuw2MhHJCiZzpmIP+VopsidfcOzvL++iqJMc=; b=v/mTIugMtVhNiZkt8ykH6Xy7asHbLH2a+JGutFW708xIWIv8EOsmlp07f4y0uYsnrN ekRpuXkpyoK43eLZONc7zq2ksO12rjvmkeYW4egNRoYk/r6scYsBAcsnH3NZjn/b+2OK DVf8844R0V/MWSNZTfUWxbIdEj7OsJz27goR52YTLJOxZkvj2KSCXEuzm0uODmvVnimw N+FNnanpVfwHXZ1cHlsAj86hnz382/QabtFdH5is42IR5HaGJXNaLUlUxN83bMFH7/Uj LM5ogFB56t28S7lFZDlKHypF7BwncdTzscXY7DDmgBPOeQJ/8rzLGCB2usJ6BO6h6tie X6lg== X-Gm-Message-State: AOJu0YxQ5ilwH4y/iYB7h0aAyiNVBCfoQLz01fAr/KPHAOVZ1uXDW/jQ spw9F+EjSOClnwOdMg/AfqfgMmKjNuI= X-Google-Smtp-Source: AGHT+IGookYXrYm1A+ma3WZO34BPnkwMLXQzWy+6HX4P/l5wwOteWAD0NK2vYdNE8zwnCUE9EMm+eRT161A= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:2fce:0:b0:d9a:f3dc:7d19 with SMTP id v197-20020a252fce000000b00d9af3dc7d19mr331431ybv.11.1698936092597; Thu, 02 Nov 2023 07:41:32 -0700 (PDT) Date: Thu, 2 Nov 2023 07:41:30 -0700 In-Reply-To: Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-13-seanjc@google.com> Message-ID: Subject: Re: [PATCH v13 12/35] KVM: Prepare for handling only shared mappings in mmu_notifier events From: Sean Christopherson To: Fuad Tabba Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Xu Yilun , Chao Peng , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , "=?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?=" , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 02, 2023, Fuad Tabba wrote: > Hi, >=20 > On Fri, Oct 27, 2023 at 7:22=E2=80=AFPM Sean Christopherson wrote: > > > > Add flags to "struct kvm_gfn_range" to let notifier events target only > > shared and only private mappings, and write up the existing mmu_notifie= r > > events to be shared-only (private memory is never associated with a > > userspace virtual address, i.e. can't be reached via mmu_notifiers). > > > > Add two flags so that KVM can handle the three possibilities (shared, > > private, and shared+private) without needing something like a tri-state > > enum. > > > > Link: https://lore.kernel.org/all/ZJX0hk+KpQP0KUyB@google.com > > Signed-off-by: Sean Christopherson > > --- > > include/linux/kvm_host.h | 2 ++ > > virt/kvm/kvm_main.c | 7 +++++++ > > 2 files changed, 9 insertions(+) > > > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > > index 96aa930536b1..89c1a991a3b8 100644 > > --- a/include/linux/kvm_host.h > > +++ b/include/linux/kvm_host.h > > @@ -263,6 +263,8 @@ struct kvm_gfn_range { > > gfn_t start; > > gfn_t end; > > union kvm_mmu_notifier_arg arg; > > + bool only_private; > > + bool only_shared; >=20 > If these flags aren't used in this patch series, should this patch be > moved to the other series? If *both* TDX and SNP need this patch, then I think it's probably worth app= lying it now to make their lives easier. But if only one needs the support, then= I completely agree this should be punted to whichever series needs it (this a= lso came up in v11, but we didn't force the issue). Mike, Isaku? > Also, if shared+private is a possibility, doesn't the prefix "only_" > confuse things a bit? I.e., what is shared+private, is it when both > are 0 or when both are 1? I assume it's the former (both are 0), but > it might be clearer. Heh, I was hoping that "only_private && only_shared" would be obviously non= sensical. The only alternative I can think would be to add an enum, e.g. enum { PROCESS_PRIVATE_AND_SHARED, PROCESS_ONLY_PRIVATE, PROCESS_ONLY_SHARED, }; because every other way of expressing the flags either results in more conf= usion or an unsafe default. I.e. I want zapping only private or only shared to r= equire the caller to explicitly set a non-zero value, which is how I ended up with "only_{private,shared}" as opposed to "process_{private,shared}".