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 9D0C5C4321E for ; Thu, 1 Dec 2022 22:01:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230126AbiLAWAc (ORCPT ); Thu, 1 Dec 2022 17:00:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230494AbiLAWAU (ORCPT ); Thu, 1 Dec 2022 17:00:20 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94A87C5E07 for ; Thu, 1 Dec 2022 14:00:18 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id p13-20020a05600c468d00b003cf8859ed1bso2822268wmo.1 for ; Thu, 01 Dec 2022 14:00:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=QIafPhFD9IJ7Ly0CwNSGH3i2Rs4yyu6nN9+ipEhZh0A=; b=jjyByQFW3CViXa2XSpO0S5OezirA8iriSGyNq1Emb3eAjXPvAcs8h/qhWZvQRHrkM7 E4yO5aU5oCECenX1ChS/eFoKmPv0xbsgDyU0kSVTl00jl03ZBLNhtOgaVKcwhuzhfB8T N7R+KHdaQ76bY3Z76ec67H1IKhJ28BX8clWmhefVQ98++dEoXnF5l49Qy+3a5Cak9CFt EIL7cmRV6y+1rtO82GUIbFuUYJjyYdwwYbZEtJNme41VeTXnC4oIE2dnPOWtcMsSXZFG q6jTLuz1FCKKC86LuPzjUTBAJLTqeyAPRmVpOXM4szcQvlKMGYRA5VkbQrYDVl2oy6Mj mCEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QIafPhFD9IJ7Ly0CwNSGH3i2Rs4yyu6nN9+ipEhZh0A=; b=tmK/Fc7AVR4oG5ZYxPU6+sW7RzshE0qYruv1RARzhJ/lNrbyQLUBxYnGEdTCI0Qu5P GREwZpGme7xEmH7dscXqmmkatNj8xlNsbppuTlAflgAVrTFfu6lNacBdTEnnjVVTLUUD 5wsDSDzlHagC7tfVWtUU+Z8HK+yWLORWH8d783WF3D23c/czyu0NFZ6lFp/oHu+7wfbK yDnVEPexhTvMtSdndnH42AD2UaZym5GKSBOw9Rg8j3U8xf58YHKkxo2ViTr+hk8u0+FH 5c9b7kEuGzgMQ3nwqKyE2pNDfHJ/gImPpkofTLbEJNAKfYHWkYFabNc0HGfUJj8MzVrB dERg== X-Gm-Message-State: ANoB5pk6xgT8an4eDgpMFBPv+t4cP2hyzbWbxG/5HBBXm+KN17LAm3ME wjgBl3ipF//fDlRkCOpA0mCatw== X-Google-Smtp-Source: AA0mqf6xx+vYTMkMQZD2sUVXTGHs5cp2mVsSPKIbRGdbGqnCPXkM+pX1knRmP86IOvF6J1/cipiL/g== X-Received: by 2002:a05:600c:3495:b0:3cf:ae53:918f with SMTP id a21-20020a05600c349500b003cfae53918fmr38954917wmq.131.1669932017038; Thu, 01 Dec 2022 14:00:17 -0800 (PST) Received: from [192.168.1.115] ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id k12-20020adfe8cc000000b00241b5af8697sm5556585wrn.85.2022.12.01.14.00.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Dec 2022 14:00:16 -0800 (PST) Message-ID: Date: Thu, 1 Dec 2022 23:00:13 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v2 21/50] KVM: MIPS: Hardcode callbacks to hardware virtualization extensions Content-Language: en-US To: Sean Christopherson , Paolo Bonzini , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Matthew Rosato , Eric Farman , Vitaly Kuznetsov , David Woodhouse , Paul Durrant Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Atish Patra , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-mips@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, Yuan Yao , Cornelia Huck , Isaku Yamahata , Fabiano Rosas , Michael Ellerman , Kai Huang , Chao Gao , Thomas Gleixner References: <20221130230934.1014142-1-seanjc@google.com> <20221130230934.1014142-22-seanjc@google.com> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= In-Reply-To: <20221130230934.1014142-22-seanjc@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On 1/12/22 00:09, Sean Christopherson wrote: > Now that KVM no longer supports trap-and-emulate (see commit 45c7e8af4a5e > "MIPS: Remove KVM_TE support"), hardcode the MIPS callbacks to the > virtualization callbacks. > > Harcoding the callbacks eliminates the technically-unnecessary check on > non-NULL kvm_mips_callbacks in kvm_arch_init(). MIPS has never supported > multiple in-tree modules, i.e. barring an out-of-tree module, where > copying and renaming kvm.ko counts as "out-of-tree", KVM could never > encounter a non-NULL set of callbacks during module init. > > The callback check is also subtly broken, as it is not thread safe, > i.e. if there were multiple modules, loading both concurrently would > create a race between checking and setting kvm_mips_callbacks. > > Given that out-of-tree shenanigans are not the kernel's responsibility, > hardcode the callbacks to simplify the code. > > Signed-off-by: Sean Christopherson > --- > arch/mips/include/asm/kvm_host.h | 2 +- > arch/mips/kvm/Makefile | 2 +- > arch/mips/kvm/callback.c | 14 -------------- > arch/mips/kvm/mips.c | 9 ++------- > arch/mips/kvm/vz.c | 7 ++++--- > 5 files changed, 8 insertions(+), 26 deletions(-) > delete mode 100644 arch/mips/kvm/callback.c > > diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h > index 28f0ba97db71..2803c9c21ef9 100644 > --- a/arch/mips/include/asm/kvm_host.h > +++ b/arch/mips/include/asm/kvm_host.h > @@ -758,7 +758,7 @@ struct kvm_mips_callbacks { > void (*vcpu_reenter)(struct kvm_vcpu *vcpu); > }; > extern struct kvm_mips_callbacks *kvm_mips_callbacks; IIUC we could even constify this pointer. Anyway, Reviewed-by: Philippe Mathieu-Daudé > diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c > index af29490d9740..f0a6c245d1ff 100644 > --- a/arch/mips/kvm/mips.c > +++ b/arch/mips/kvm/mips.c > @@ -1012,17 +1012,12 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) > > int kvm_arch_init(void *opaque) > { > - if (kvm_mips_callbacks) { > - kvm_err("kvm: module already exists\n"); > - return -EEXIST; > - } > - > - return kvm_mips_emulation_init(&kvm_mips_callbacks); > + return kvm_mips_emulation_init(); > } > > void kvm_arch_exit(void) > { > - kvm_mips_callbacks = NULL; > + > } > > int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, > diff --git a/arch/mips/kvm/vz.c b/arch/mips/kvm/vz.c > index c706f5890a05..dafab003ea0d 100644 > --- a/arch/mips/kvm/vz.c > +++ b/arch/mips/kvm/vz.c > @@ -3304,7 +3304,10 @@ static struct kvm_mips_callbacks kvm_vz_callbacks = { > .vcpu_reenter = kvm_vz_vcpu_reenter, > }; > > -int kvm_mips_emulation_init(struct kvm_mips_callbacks **install_callbacks) > +/* FIXME: Get rid of the callbacks now that trap-and-emulate is gone. */ > +struct kvm_mips_callbacks *kvm_mips_callbacks = &kvm_vz_callbacks;