Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1514660rwb; Wed, 26 Jul 2023 13:52:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlE/NTKkGoPlE7HFcwB5bMh4t5nO8+q1O03LwqsrxL3qASvAYL2Lj1ZMHOynr+KYzvfGFMXl X-Received: by 2002:a17:902:9882:b0:1b8:a720:f513 with SMTP id s2-20020a170902988200b001b8a720f513mr2424295plp.30.1690404727927; Wed, 26 Jul 2023 13:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690404727; cv=none; d=google.com; s=arc-20160816; b=0GMHSsAXWat0gmcVhP5XNuyXsP23jOJF9BA5E1n4aT4UP6H3XvU0pL55r3FxiB2sHP 0XpLHCNd2uD8EX+v/m6/wAu5pqtG6U3KxJJeY1wT0SPh6VQ7WbHIFWp5jwwqg1L6fjb0 T00pTVz5/dq57h/sB+MO0Xcf7wEokiLnhwrnK94udqxno+F1L54h7xqQsObfWBuao0N0 UypNAyJm+3mTKAz8KzsM34TEozYh3Scousd9qGUQzKRUUcb2col/fuboBDvuE8wliS19 znUkowkP2AuD90+H4GekSPjy9TSlKcRsoUswQct+Ua3ATpup5LZSlQ7zujWVxPEoc2jy c2qw== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=wk8YN2z9DygnTN7wIkQ/drKhQeRLfAOWaFSkpwIJ9VA=; fh=tka8fjfhHFzL15AUMsoY3DpID25kLtr7rZLwDH2qGkg=; b=Dyr4Ji3pgKy2E5cD9phK4vN+v6XdiSGMsg39hfpHfAqVHVBJdjs/BOLN+pSArODzQ2 vPhB4UU8n9ADWuuETnzM6D+sXem38CAqm5atvqBXYKe2lBmu4xYiBYcHIINlVQUJviBq qZYKnEel1Ki01d0gEfUrxDrjQhkwQ8SLfLy18g3w9Od2cQ5k4p/nf6Fp1BWQY7qc6wE1 zloID/nHlvI3OXhFwvShVOfUeWcVEaKS0izDZ1qOxKfhVNKpxD0ZxLhV72eq6M/xq+38 YDni6Nozy+UHL3Wx2Iklhu4RnadVIeCv/wKgNlVlotJPCZg6P0AdqRcnHfSVDUCYfMay CMHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=eM8gatpI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3-20020a17090332c300b001b89b63b877si14611059plr.446.2023.07.26.13.51.55; Wed, 26 Jul 2023 13:52:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=eM8gatpI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231238AbjGZUW2 (ORCPT + 99 others); Wed, 26 Jul 2023 16:22:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229595AbjGZUW0 (ORCPT ); Wed, 26 Jul 2023 16:22:26 -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 D609019AF for ; Wed, 26 Jul 2023 13:22:24 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d1c693a29a0so149892276.1 for ; Wed, 26 Jul 2023 13:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690402944; x=1691007744; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wk8YN2z9DygnTN7wIkQ/drKhQeRLfAOWaFSkpwIJ9VA=; b=eM8gatpIFAPsVcHsvCyPq5hyC8MsN3TVlS3mNniSEUN+A8XGjxiS8F6dC4aFmL513/ OKqKBd4JNqQZqMKS0xCiGe+t5AXNUTDm2VuHrYqk4zFosWdPFjPIB6URfw5vd93IMKdx lKXXLluLhbwl+YjfsuqRPKzKU2+mG/aerZ1RHkgGlaQ2XngSQ4QWGzUzw8Bk02VhX6BY iemdbo75Y0mm9KaGC6Z479jAT6buL5FMFb75fU2ROzDvErIFsnjLxci0m6st5PC1U67q 6FdRgc7HGPP7DF/FaK/f0cWfoJ+ZjAfbcmtP5i/qUasNowuJ11SfJCK8qdGxq6HB8Y5C RWCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690402944; x=1691007744; 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=wk8YN2z9DygnTN7wIkQ/drKhQeRLfAOWaFSkpwIJ9VA=; b=hB+fM9RcqUw0x7e5vj1xU1Pv0iHxKGnW6O5gDLrUTuTUrsGUq4vbLiZTIaCO1hzE73 mledHztCjIBcO0E0DclfXtHIhiH0sYtqG8hrQg66qmS5bO3QvLAO5fMPHpiDb3luwkwT /Cc7trdlq2DTTwLG8ImE7flPvC4Teg0U4ijE0NGjTbgRosykj9Nz2iDeod5oJt8zdGCt mYq0nD96DAbUNtjju5I8kF9Xb9QR8W3+wMD826f+NEIiKEKWijTmkJvpNH+IHU2Z5Rdo Cy1nTtTdL4FftrAOinXQ7/kYNDVJAlrtu27tKU0H0p4Uq46gnaqN/10wVUSGCHVeQM35 sbYg== X-Gm-Message-State: ABy/qLYAUQpGVVXJ3RgoqlhdIGKYGMwNDzSbji5PuNuWa+fR08U2zYSW Cmk2P7cjvIiSVuuM3zMi1lz8DqQRdDU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:cf48:0:b0:d06:1a77:7d2 with SMTP id f69-20020a25cf48000000b00d061a7707d2mr18632ybg.13.1690402944082; Wed, 26 Jul 2023 13:22:24 -0700 (PDT) Date: Wed, 26 Jul 2023 13:22:22 -0700 In-Reply-To: <711f74d6-fe15-6bd4-a9b9-c4f178d95bf3@redhat.com> Mime-Version: 1.0 References: <20230718234512.1690985-1-seanjc@google.com> <20230718234512.1690985-2-seanjc@google.com> <711f74d6-fe15-6bd4-a9b9-c4f178d95bf3@redhat.com> Message-ID: Subject: Re: [RFC PATCH v11 01/29] KVM: Wrap kvm_gfn_range.pte in a per-action union From: Sean Christopherson To: Paolo Bonzini Cc: Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" , 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-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Yu Zhang , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , Vlastimil Babka , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 19, 2023, Paolo Bonzini wrote: > On 7/19/23 01:44, Sean Christopherson wrote: > > + BUILD_BUG_ON(sizeof(gfn_range.arg) != sizeof(gfn_range.arg.raw)); > > + BUILD_BUG_ON(sizeof(range->arg) != sizeof(range->arg.raw)); > > I think these should be static assertions near the definition of the > structs. However another possibility is to remove 'raw' and just assign the > whole union. Duh, and use a named union. I think when I first proposed this I forgot that a single value would be passed between kvm_hva_range *and* kvm_gfn_range, and so created an anonymous union without thinking about the impliciations. A named union is _much_ cleaner. I'll post a complete version of the below snippet as a standalone non-RFC patch. diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 9d3ac7720da9..9125d0ab642d 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -256,11 +256,15 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu); #endif #ifdef KVM_ARCH_WANT_MMU_NOTIFIER +union kvm_mmu_notifier_arg { + pte_t pte; +}; + struct kvm_gfn_range { struct kvm_memory_slot *slot; gfn_t start; gfn_t end; - pte_t pte; + union kvm_mmu_notifier_arg arg; 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 dfbaafbe3a00..f84ef9399aee 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -526,7 +526,7 @@ typedef void (*on_unlock_fn_t)(struct kvm *kvm); struct kvm_hva_range { unsigned long start; unsigned long end; - pte_t pte; + union kvm_mmu_notifier_arg arg; hva_handler_t handler; on_lock_fn_t on_lock; on_unlock_fn_t on_unlock; @@ -547,6 +547,8 @@ static void kvm_null_fn(void) } #define IS_KVM_NULL_FN(fn) ((fn) == (void *)kvm_null_fn) +static const union kvm_mmu_notifier_arg KVM_NO_ARG; + /* Iterate over each memslot intersecting [start, last] (inclusive) range */ #define kvm_for_each_memslot_in_hva_range(node, slots, start, last) \ for (node = interval_tree_iter_first(&slots->hva_tree, start, last); \ @@ -591,7 +593,7 @@ static __always_inline int __kvm_handle_hva_range(struct kvm *kvm, * bother making these conditional (to avoid writes on * the second or later invocation of the handler). */ - gfn_range.pte = range->pte; + gfn_range.arg = range->arg; gfn_range.may_block = range->may_block; /*