Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5186026rdb; Sat, 16 Sep 2023 06:31:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGn96KK1eLZNKzalHc4JN2sR2pqgpchItUp41CNcNgnf5ZvKlnUYnI96En7m4+LQNo4Wlqk X-Received: by 2002:a05:6a20:dd9a:b0:14c:512c:c138 with SMTP id kw26-20020a056a20dd9a00b0014c512cc138mr3993094pzb.60.1694871063585; Sat, 16 Sep 2023 06:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694871063; cv=none; d=google.com; s=arc-20160816; b=l4jNehsohSU5yeDZGUsF/by8iB4kjRyz6RK/twv+hZDl43JVrEThj98jUqG7nGErM/ ljoUcGzNuSwJcKLSeECT96B92mFBJ4LZOZ86uZoq/1U8/1tUrf2rRYTxZSNmbjgeGoA5 sbr0K0db8iHNzOjqLvqKdSkOrPxqgwaWmIL5/cbX78LY63ULq04e7T6b9TpN42yOhSLj rYIC6ttX0AEqrxYQadjNRq5McdDDEHUiiZcyFhEOssPvReV3QY0MMjldsMFqKPCwJ2KZ y3tVOjSvZvI46LiqiUOoGZp3+L07O7qvF3hnRKYEAp1cP2020qkf3v9gRHKN06RFVaIg veIw== 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:reply-to:dkim-signature; bh=NdOAPx70WjWtTXOKtIxgwEtN+XJRELer/ruyZoFwPzQ=; fh=kXSkXFacTVTlVHq0XnHvR0iN61knZqi7sPJIGv3JAWo=; b=W8c4nYAKwvqPbVSm2r41UVkUbmrEchJafcito7w3rfq7lMAy8YMnnJPV2BUZPdlaUp zxKzlneLVvLC8KwRN5MMSDzJq0hZ9FGbwQi+qGZnJ4jGcgMJQp/IZ9FIlSg3howuEfBz /IWjL8NJNrf3pCgRsafMoBdvtrQDATn7vpzKkRxRhE+i32a/+VcQlnZV37dvzdWSCK16 4BQJBKf7GLnls2BifWN4ufuf+RShJQ8B0m4snd7jDv1yUJQKnii53h77SK6n0LYkrLGX ARzf4oAxuUF4iW0O6RnP5YcdVyxH2sKSzLGlNAqtvZ3YibEw5mA1KExoCdnTZKQ2IZ6k MdUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RlXJm+mZ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id o25-20020a635a19000000b00565e87d8707si4831496pgb.496.2023.09.16.06.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 06:31:03 -0700 (PDT) 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=@google.com header.s=20230601 header.b=RlXJm+mZ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0C6C282A54D2; Fri, 15 Sep 2023 17:33:00 -0700 (PDT) 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 S238664AbjIPAc1 (ORCPT + 99 others); Fri, 15 Sep 2023 20:32:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238610AbjIPAcK (ORCPT ); Fri, 15 Sep 2023 20:32:10 -0400 Received: from mail-oi1-x249.google.com (mail-oi1-x249.google.com [IPv6:2607:f8b0:4864:20::249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58673CCF for ; Fri, 15 Sep 2023 17:31:25 -0700 (PDT) Received: by mail-oi1-x249.google.com with SMTP id 5614622812f47-3a741f4790fso4367788b6e.0 for ; Fri, 15 Sep 2023 17:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694824284; x=1695429084; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=NdOAPx70WjWtTXOKtIxgwEtN+XJRELer/ruyZoFwPzQ=; b=RlXJm+mZvrxm3TdH7rqHIPrlVvTo4KquPvK8UVq3NN5veuJB/mi9ryJHvFeKMAtnPp hPxgp34Yh6rJ5lm+4syv8SCZe+7xA7Fv6c1FljwvDQiy3j2D5SfDPLC4LvU4LK+f0Hnd XzPGLz6ybxyOrNbEJSaoUgSEsV9nduzwqd8vi1CA4uDfumU39XR/gEIesx64Hi95yPKN 7OdYcCV1Sv/tEKMWY6ex/Wwd6o1RSVZW3lb5oOgf0+xs2BvFq4c43x+2pmamAn+AbBR8 aeZDJ4jC0Gn6tEare6UsiV0E76tCnR9I5p3lITfJ2MvZSPAoe7bUb/PsN2uzYgSF4MPp Dh+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694824284; x=1695429084; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NdOAPx70WjWtTXOKtIxgwEtN+XJRELer/ruyZoFwPzQ=; b=oUWcABihkIPJx6NQTqExryseSAebpCR07kKZ05YG8e8Zv7eol0wPdGIcTs1D22bhYl O8vJri8ekmWQTD+Na6uUwNDeEWMMCPbcmqo35c+fxu6MlzT4C7JgvDL1/H4lwtAot6vN xetlnE9UUTXSMvIX+MRIfn9F5XXpvt7+VPSpyQhePM+V/SBFd9y+sxLhWkxxJwiQo+46 DS7Y/vJcXJLoPRi/ZngPitBMHF2oeuZ7Um8B4fi8Uc2hnsa1JaYRrUgzk+qvHcFIk60D Y+bMrUkL75YgPD1OOYRcqZoamrDVNP0CbTrp10bY+BbibHBnjtgCIZ+hhKh2ehgSKdy3 rhlA== X-Gm-Message-State: AOJu0YxVTatkdeTjhPg4mUm2qAMXzYqIIqDs8s2aqK8RJtH7e2tBEyuX SPTdNFp0GScmGCHKnCeZ1bI4E0pgua0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6870:b7ad:b0:1d6:4da3:ae2d with SMTP id ed45-20020a056870b7ad00b001d64da3ae2dmr1068876oab.7.1694824284654; Fri, 15 Sep 2023 17:31:24 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 15 Sep 2023 17:30:54 -0700 In-Reply-To: <20230916003118.2540661-1-seanjc@google.com> Mime-Version: 1.0 References: <20230916003118.2540661-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230916003118.2540661-3-seanjc@google.com> Subject: [PATCH 02/26] vfio: Move KVM get/put helpers to colocate it with other KVM related code From: Sean Christopherson To: 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 , Sean Christopherson , Paolo Bonzini , Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Alex Williamson , Andy Lutomirski Cc: 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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]); Fri, 15 Sep 2023 17:33:00 -0700 (PDT) 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(-) 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; -- 2.42.0.459.ge4e396fd5e-goog