Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3803526rdh; Fri, 29 Sep 2023 02:52:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEuurBtQ0brCRuFuhBOL0J2LfTcfim73VA4tzhV4ZAdx++gtmOMYbEbUQbxPSVukIPFwjJU X-Received: by 2002:a05:6a20:3249:b0:161:afbc:c02f with SMTP id hm9-20020a056a20324900b00161afbcc02fmr3338158pzc.54.1695981126157; Fri, 29 Sep 2023 02:52:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695981126; cv=none; d=google.com; s=arc-20160816; b=cuVP0UEr4juGJmxrlXNq/GD+UW1tarBXrHlxWkd8IO+Iz02ylXEt7QUOupUVd3OObN s+gSgOhEgAZn+KNXxbfMEao5K1vGU67EyWXrIGfOzPpreaQgvu5/9d02N68OTTP/KgrI pihLHyY0IQUr+U/Mp8FocppWVWokuruQ1RIAvzBfej5IWfLhYUqSdR9GmH+ZIt1XF2OM BVK8lX6m8G6V5rIL0/hTizdaAUBjptmd0GoJWXxsp4b+PZTxIjSSxaYaDaAkuJAe60JC ZW4MHODvSZ+4sHRZtpuaKAFJ1y7HJ6P4cPfGhkXsDOFnpz7ceLrpS5ScTYWhmvc2grYF EcvQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=yJlZv5KfytnzZmRqZMI7mLTWvvegYQeNtr0CrdJHxrc=; fh=brbVgFrtCTEER0oOudG8SRWryx8saMIRm6YoJHqrKx4=; b=gt3KtB8MmPcZfkmV9dUIHnd32uT8UMkQj93MW3wBO6If8gmUoKiKUuS8ccksdN7Ep3 Lkx+BbotzjBYhgW9OZfaSWmFVs1fQyFCoM2RnjWAnI2WIKz/pAQw+UGRM5T0r4K/lUPy OwKVIN9SLT04DuiSuwTnulrv+XcyC25iQaaqkuQulcfQD+2NWpjBsQ4/lXBQPnTkpQmt ggdMiYfqxOuJ2n4l2NuX0LrADoFdgbnwQFNNWHSnRIPqceJndh6VQS1jUmTaWit1KO41 zXHmfy1Iuz+oDRA5yAJs/W6471UYMuE9TCx8cpUyjyqewSaDDQAgj+vvXDyhM0WmrdrF XZ/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Ez/Uh1km"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id m1-20020a656a01000000b0057749f3cbe1si23642066pgu.673.2023.09.29.02.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 02:52:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Ez/Uh1km"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 12A5A82C52C9; Thu, 28 Sep 2023 15:24:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232570AbjI1WXw (ORCPT + 99 others); Thu, 28 Sep 2023 18:23:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232544AbjI1WXu (ORCPT ); Thu, 28 Sep 2023 18:23:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27B34CC2 for ; Thu, 28 Sep 2023 15:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695939706; 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=yJlZv5KfytnzZmRqZMI7mLTWvvegYQeNtr0CrdJHxrc=; b=Ez/Uh1kmKg7MrjRNPCLulA36pOVjQ5gy+yOz1Jj2F1p7YDVNjgYUbnohzK5m8M6UMihyZI 5Nir5HLf1gp7t9/HQZBBB6HClzl4nxU3aSfeXGRqbjnDrAU/ebPMJyYLmqfB83zPhdfkUg YN8894ftLye1JsVY6MxPTN61qhGbvyI= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286--8_1FKbhMM2N7Rrox0Pp3Q-1; Thu, 28 Sep 2023 18:21:45 -0400 X-MC-Unique: -8_1FKbhMM2N7Rrox0Pp3Q-1 Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-790d3e93a25so1700384039f.0 for ; Thu, 28 Sep 2023 15:21:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695939704; x=1696544504; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yJlZv5KfytnzZmRqZMI7mLTWvvegYQeNtr0CrdJHxrc=; b=T2FQ5OGVeIuXrokmdU16YEy0vQLw097vmQt4RDm6A/GhH6Sq5a2lPcpS/1adVs1gUL LFbCZYB1tTVT60jGxHY3ou6QmozwFtfXoRC6bYYkF9ChQca93GWWq5PMlWisoYu36V4d twdYLTqZ4wC0uOQNaauMgwqeeODNA1flp4WexVr8nz/JzNKZAgYm+h5MYHEVdugFHyyx TLKxBw1379FNGCvRapvlTvecRABWA2YAGMkfJulgMuGqcvNFlUTgtARmqkUa1KeUEDfg OBxyehtpXdmfwbxuVruWuXPoUezPgNguOZgJdn1uaUA4H6PBaZz+kRrFvSyaEg4j3mnv EVYQ== X-Gm-Message-State: AOJu0YyuvFqy5CFA1kKsmNZ4/7ReJfOul90c4UHTsr35X+95Y5YBQ17o E3fYu/Rh45DkVLRMnTGnPFYz9ZH89/lpcjYa9QbGIW1IXYZmg4JB2KVpf3RHtUrSNVE4FQsRkDu HCxCk+A81E/YokWSNpT5mB1HK X-Received: by 2002:a5e:9e09:0:b0:795:8805:1378 with SMTP id i9-20020a5e9e09000000b0079588051378mr2451961ioq.9.1695939704283; Thu, 28 Sep 2023 15:21:44 -0700 (PDT) X-Received: by 2002:a5e:9e09:0:b0:795:8805:1378 with SMTP id i9-20020a5e9e09000000b0079588051378mr2451906ioq.9.1695939703976; Thu, 28 Sep 2023 15:21:43 -0700 (PDT) Received: from redhat.com ([38.15.60.12]) by smtp.gmail.com with ESMTPSA id t23-20020a02c497000000b0042b10d42c90sm4610172jam.113.2023.09.28.15.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 15:21:42 -0700 (PDT) Date: Thu, 28 Sep 2023 16:21:05 -0600 From: Alex Williamson To: Sean Christopherson Cc: Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Peter Zijlstra , Arnaldo Carvalho de Melo , Paolo Bonzini , Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Andy Lutomirski , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Anish Ghulati , Venkatesh Srinivas , Andrew Thornton Subject: Re: [PATCH 02/26] vfio: Move KVM get/put helpers to colocate it with other KVM related code Message-ID: <20230928162105.2e347cd5.alex.williamson@redhat.com> In-Reply-To: <20230916003118.2540661-3-seanjc@google.com> References: <20230916003118.2540661-1-seanjc@google.com> <20230916003118.2540661-3-seanjc@google.com> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 28 Sep 2023 15:24:07 -0700 (PDT) On Fri, 15 Sep 2023 17:30:54 -0700 Sean Christopherson wrote: > Move the definitions of vfio_device_get_kvm_safe() and vfio_device_put_kvm() > down in vfio_main.c to colocate them with other KVM-specific functions, > e.g. to allow wrapping them all with a single CONFIG_KVM check. > > Signed-off-by: Sean Christopherson > --- > drivers/vfio/vfio_main.c | 104 +++++++++++++++++++-------------------- > 1 file changed, 52 insertions(+), 52 deletions(-) Reviewed-by: Alex Williamson > diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c > index 80e39f7a6d8f..6368eed7b7b2 100644 > --- a/drivers/vfio/vfio_main.c > +++ b/drivers/vfio/vfio_main.c > @@ -381,58 +381,6 @@ void vfio_unregister_group_dev(struct vfio_device *device) > } > EXPORT_SYMBOL_GPL(vfio_unregister_group_dev); > > -#if IS_ENABLED(CONFIG_KVM) > -void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm) > -{ > - void (*pfn)(struct kvm *kvm); > - bool (*fn)(struct kvm *kvm); > - bool ret; > - > - lockdep_assert_held(&device->dev_set->lock); > - > - if (!kvm) > - return; > - > - pfn = symbol_get(kvm_put_kvm); > - if (WARN_ON(!pfn)) > - return; > - > - fn = symbol_get(kvm_get_kvm_safe); > - if (WARN_ON(!fn)) { > - symbol_put(kvm_put_kvm); > - return; > - } > - > - ret = fn(kvm); > - symbol_put(kvm_get_kvm_safe); > - if (!ret) { > - symbol_put(kvm_put_kvm); > - return; > - } > - > - device->put_kvm = pfn; > - device->kvm = kvm; > -} > - > -void vfio_device_put_kvm(struct vfio_device *device) > -{ > - lockdep_assert_held(&device->dev_set->lock); > - > - if (!device->kvm) > - return; > - > - if (WARN_ON(!device->put_kvm)) > - goto clear; > - > - device->put_kvm(device->kvm); > - device->put_kvm = NULL; > - symbol_put(kvm_put_kvm); > - > -clear: > - device->kvm = NULL; > -} > -#endif > - > /* true if the vfio_device has open_device() called but not close_device() */ > static bool vfio_assert_device_open(struct vfio_device *device) > { > @@ -1354,6 +1302,58 @@ bool vfio_file_enforced_coherent(struct file *file) > } > EXPORT_SYMBOL_GPL(vfio_file_enforced_coherent); > > +#if IS_ENABLED(CONFIG_KVM) > +void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm) > +{ > + void (*pfn)(struct kvm *kvm); > + bool (*fn)(struct kvm *kvm); > + bool ret; > + > + lockdep_assert_held(&device->dev_set->lock); > + > + if (!kvm) > + return; > + > + pfn = symbol_get(kvm_put_kvm); > + if (WARN_ON(!pfn)) > + return; > + > + fn = symbol_get(kvm_get_kvm_safe); > + if (WARN_ON(!fn)) { > + symbol_put(kvm_put_kvm); > + return; > + } > + > + ret = fn(kvm); > + symbol_put(kvm_get_kvm_safe); > + if (!ret) { > + symbol_put(kvm_put_kvm); > + return; > + } > + > + device->put_kvm = pfn; > + device->kvm = kvm; > +} > + > +void vfio_device_put_kvm(struct vfio_device *device) > +{ > + lockdep_assert_held(&device->dev_set->lock); > + > + if (!device->kvm) > + return; > + > + if (WARN_ON(!device->put_kvm)) > + goto clear; > + > + device->put_kvm(device->kvm); > + device->put_kvm = NULL; > + symbol_put(kvm_put_kvm); > + > +clear: > + device->kvm = NULL; > +} > +#endif > + > static void vfio_device_file_set_kvm(struct file *file, struct kvm *kvm) > { > struct vfio_device_file *df = file->private_data;