Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1229200rwb; Thu, 1 Dec 2022 14:21:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf5xjef2UfnGEwye8/I6SQVUuf6M+r9yW8ZPplsMshdplR3iWeWOaavjguEevS1cXzNe+HC5 X-Received: by 2002:a17:902:a514:b0:189:97c3:6382 with SMTP id s20-20020a170902a51400b0018997c36382mr17834823plq.168.1669933294046; Thu, 01 Dec 2022 14:21:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669933294; cv=none; d=google.com; s=arc-20160816; b=jSGK7ODmnZ9VVvI83ggn0nr9qXWyxu0y4jvngA/S7IwEWb3YM8KD1vVznyuahy1ea1 LF+Dn4N79mt0UNh24pl6tbnwc23g8j8KwCFgtDjx4kz4/ssUyc0owm4dg7shTv7I5O0F OE+9KKTrz0zUdBijdZhRbBr0AuY86L8dpoQq78pqyeXB6/3pXPzw8suSzpWSGwT1bHsb Pwg0OS7muNOoCfjPNo9g1SBuswgf7q1QMv+A1a1EF9FoaiqvG+PhL8/kNO0Ri78Vz4oG fnUm0KETejQdQoYvjZ4Cllh5rVrUvKU0U4gPg0oJ3tix9/RCyMBQbDK8YbxDZX/LgBsB QKkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=QIafPhFD9IJ7Ly0CwNSGH3i2Rs4yyu6nN9+ipEhZh0A=; b=mLuHKr6ps3cRJTNfCLIvD70ajN56PW09Xyc0W9kSgKP9z9SYidoFoCwMUn5vYzFwmZ tZET2EYQ8o5ZKl62proBVWjNKmdn8v8ergBYFRWp8U17Afv+UZoV2gJRjBjeLlWl2z2n QfH2LjLlX9vw8CxpIXL4flVRNAAAuHSRE1WW3fUfYocM3Gzs2FDs0VKZU26HoCe80Wva EJa6gVdTsy1FKuZwWQl+DI6Eb4klPr6BTx+KNYVT8y36u0tWdF3bgfiEx2IKSoBBbqhF 4lbbptq/Oet0SxfQR4D92CC6sRGD8wazDtaJr7IH+5/5woum3Da01KAMrEft6lfivNKZ iBcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jjyByQFW; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n14-20020a63ee4e000000b0045a43a568casi5512897pgk.717.2022.12.01.14.21.23; Thu, 01 Dec 2022 14:21:34 -0800 (PST) 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=@linaro.org header.s=google header.b=jjyByQFW; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbiLAWAd (ORCPT + 81 others); Thu, 1 Dec 2022 17:00:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230420AbiLAWAU (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 9306EC3FFF for ; Thu, 1 Dec 2022 14:00:18 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id m7-20020a05600c090700b003cf8a105d9eso2800949wmp.5 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=WdLFf5ACG9j+uYjKa4TSK3DKaZjuvN/LBGzsChxVIl6bfI6MTrGXR5YqdphfugKjRZ zr1WrdgeKew5rc3F/lbSw6iyKtQCE85sMx5TkiJfJBR8RuguDCB6OqnI8mJbRf4b8m9l MnK0UlXAF+HFvkvRuvpttdnJ0uA1Ne1nBS8Kx60qHj78opcO2s1MOIxh6XpZscJMKUWb 9usDP6SunbVxTdvU3116RrPMTwoFVt8g6CQnqWwQr52VQXsneey/K3iUDpwebBVIRAOC +X81ANoretcZYIRK+9CGz+Fh6nNISowdjIzeRbIMKp51nDIaEfUZeoCGSICaT7LszCet Bxqw== X-Gm-Message-State: ANoB5pngB+O1FQhF02oV4qcmkTOmz1xYQmWKJ2fLoM+F8R7E/1MJTrCq h+u+d1ynNRs8PZ2AQ5Y9gsavxA== 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 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 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;