Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1663059rdf; Sun, 5 Nov 2023 08:38:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmsL7kQbxOu+NvO/cHkMQtpDs3FEoId04ElpYr3sDbXMOCf1GyyF3cJ4PV1ib8nR4mHfY6 X-Received: by 2002:a05:6870:9723:b0:1e9:b0fa:de4c with SMTP id n35-20020a056870972300b001e9b0fade4cmr27585407oaq.33.1699202314750; Sun, 05 Nov 2023 08:38:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699202314; cv=none; d=google.com; s=arc-20160816; b=ouDh0N5JiMWKKJc19Q70j1iSOeLYO9Pgh+2IfRijm/5TXn3Bfu7BINpSwX53YX9FJ4 atXMTX+L1ATB9SCngSReW/6TU3/qOVcCy0rhZ312O+829HahqNF6IHyvvtuuVdYAlMbk /Ng+BLmVn/7FLF6gMyw04RY1N6yyGZjUgFuPMqorHGo+67SPfV05MC1PJXykzkJvZXA4 JujrVzbD8wTWv95bHwU66n9INB5HL4yiu/yNTF+R5kf8/FShAi1wMOGkVPBvmVWevGku wGIHoxOVUXHCckU5C06CnWL8M2VE6UiTcZ7GvkSaDXy8/y2KDUpwFTKmCcQIHE/+QY++ 26YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JI038vGa+9l4j36u3/UOgkDOr4COidrQJinDT6XHM/0=; fh=HrMuB0qA2qw4RqBwyiyN+RBlGw+Ob1hcALwHW/PphXs=; b=JjmILAqeJXrBeMoax5RtUzz3qvy+MsMHP1mKcUGlYAUr0RP+Mv1Mr7txBKyYbKjPFD 8xWf/AB7L2wN2uEV22n/E2S35Ql9HiUk05jW/cttvpZbYYnML2/F8uB8pggyaJYHz+MX UUUamn53nWCv3wVpGh1/YSrPXYtw7zHzbf2XfHev6qkhklqZ7LVubnAKriXQ2Yfs8haa uLtrRLyplqHmCCPZXxmnHQ+DkH4PfyKcvJCYSFTQyS5P2UFMsx/ehRuo+UtKQvl98sX5 TNsWor0WGmesaJBfxENmM3ciE+5oZC/BqWHINTjcxPeHnIdc5SHVSkylESwkbp55elak +uWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K5S88On0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id h11-20020a63120b000000b005aca8ed90c3si6061389pgl.271.2023.11.05.08.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 08:38:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K5S88On0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C13548054ED8; Sun, 5 Nov 2023 08:38:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230374AbjKEQiC (ORCPT + 99 others); Sun, 5 Nov 2023 11:38:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230490AbjKEQh1 (ORCPT ); Sun, 5 Nov 2023 11:37:27 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD00930C4 for ; Sun, 5 Nov 2023 08:35:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699202122; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JI038vGa+9l4j36u3/UOgkDOr4COidrQJinDT6XHM/0=; b=K5S88On0oHV0S9YMAUsKZ9e6q9JoSJc5u1LciseRe/OLTiY7cCMfg1nzAHi8+rHPPczZUq Smd1sTx52CMr0wPBSL/utgQL99W1bf/tYJYcKTI9wbxM5GFeZRpyX+djlDw/ifuXz4+piX EG5DktbYoDyBwNTModE3VJx+IJOn5RI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-299-4FlDTlVyN5-dKH0IlJkdsg-1; Sun, 05 Nov 2023 11:35:19 -0500 X-MC-Unique: 4FlDTlVyN5-dKH0IlJkdsg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DD3E7101A52D; Sun, 5 Nov 2023 16:35:17 +0000 (UTC) Received: from avogadro.redhat.com (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2596C2166B26; Sun, 5 Nov 2023 16:35:11 +0000 (UTC) From: Paolo Bonzini To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Sean Christopherson , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton Cc: 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 , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A. Shutemov" Subject: [PATCH 35/34] KVM: Prepare for handling only shared mappings in mmu_notifier events Date: Sun, 5 Nov 2023 17:30:38 +0100 Message-ID: <20231105163040.14904-36-pbonzini@redhat.com> In-Reply-To: <20231105163040.14904-1-pbonzini@redhat.com> References: <20231105163040.14904-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Spam-Status: No, score=-1.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 05 Nov 2023 08:38:32 -0800 (PST) From: Sean Christopherson Add flags to "struct kvm_gfn_range" to let notifier events target only shared and only private mappings, and write up the existing mmu_notifier 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 Message-Id: <20231027182217.3615211-13-seanjc@google.com> Signed-off-by: Paolo Bonzini --- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 3ebc6912c54a..4d5d139b0bde 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -264,6 +264,8 @@ struct kvm_gfn_range { gfn_t start; gfn_t end; union kvm_mmu_notifier_arg arg; + bool only_private; + bool only_shared; bool may_block; }; bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 8758cb799e18..9170a61ea99f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -635,6 +635,13 @@ static __always_inline kvm_mn_ret_t __kvm_handle_hva_range(struct kvm *kvm, * the second or later invocation of the handler). */ gfn_range.arg = range->arg; + + /* + * HVA-based notifications provide a userspace address, + * and as such are only relevant for shared mappings. + */ + gfn_range.only_private = false; + gfn_range.only_shared = true; gfn_range.may_block = range->may_block; /* @@ -2493,6 +2500,16 @@ static __always_inline void kvm_handle_gfn_range(struct kvm *kvm, gfn_range.arg = range->arg; gfn_range.may_block = range->may_block; + /* + * If/when KVM supports more attributes beyond private .vs shared, this + * _could_ set only_{private,shared} appropriately if the entire target + * range already has the desired private vs. shared state (it's unclear + * if that is a net win). For now, KVM reaches this point if and only + * if the private flag is being toggled, i.e. all mappings are in play. + */ + gfn_range.only_private = false; + gfn_range.only_shared = false; + for (i = 0; i < kvm_arch_nr_memslot_as_ids(kvm); i++) { slots = __kvm_memslots(kvm, i); -- 2.39.1