From nobody Fri Oct 24 09:35:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518804800903150.96462418989665; Fri, 16 Feb 2018 10:13:20 -0800 (PST) Received: from localhost ([::1]:46729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emkVS-0004yU-Ph for importer@patchew.org; Fri, 16 Feb 2018 13:13:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emkUS-0004ZV-6B for qemu-devel@nongnu.org; Fri, 16 Feb 2018 13:12:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emkUP-0003JR-26 for qemu-devel@nongnu.org; Fri, 16 Feb 2018 13:12:08 -0500 Received: from 1.mo4.mail-out.ovh.net ([178.33.248.196]:33898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1emkUO-0003IX-QB for qemu-devel@nongnu.org; Fri, 16 Feb 2018 13:12:04 -0500 Received: from player798.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo4.mail-out.ovh.net (Postfix) with ESMTP id EFC6714F8F5 for ; Fri, 16 Feb 2018 19:12:02 +0100 (CET) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player798.ha.ovh.net (Postfix) with ESMTPA id DF14E540095; Fri, 16 Feb 2018 19:11:56 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 16 Feb 2018 19:11:50 +0100 Message-ID: <151880471076.4588.45148319107456140.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 2229844766492694801 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrfeeggdduudduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.33.248.196 Subject: [Qemu-devel] [PATCH] kvm: add stubs for kvm_vcpu_id_is_valid() and kvm_arch_vcpu_id() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Paolo Bonzini , Eduardo Habkost , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 These two functions are essentially called by code that is only compiled when CONFIG_KVM=3Dy, with the notable exception of the two users in the sPAPR code: $ git grep -E -l 'kvm_arch_vcpu_id|kvm_vcpu_id_is_valid' accel/kvm/kvm-all.c hw/intc/openpic_kvm.c hw/intc/xics_kvm.c hw/ppc/spapr.c include/sysemu/kvm.h target/arm/kvm.c target/i386/kvm.c target/mips/kvm.c target/ppc/kvm.c target/s390x/kvm.c In hw/ppc/spapr.c: if (kvm_enabled()) { return kvm_arch_vcpu_id(cs); } else { return cs->cpu_index; } and if (kvm_enabled() && !kvm_vcpu_id_is_valid(cpu->vcpu_id)) { ... } This code happens to compile without CONFIG_KVM=3Dy simply because kvm_enabled() expands to (0) and the compiler optimizes the dead code away. Unless this was done on purpose to indicate no stubs are required, and we'd rather break the build if calling these from KVM agnostic code, it seems better practice to have stubs. It doesn't really make sense to call these when kvm_enabled() is false, since they were introduced to allow the architecture to control VCPU ids passed to the KVM_CREATE_VCPU ioctl. This being said, I see no reason for not giving the stub a friendly default behaviour: - VCPU id is cpu_index - a VCPU id is always valid Signed-off-by: Greg Kurz --- accel/stubs/kvm-stub.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index c964af3e1c97..d3e7d39ff9a9 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -160,4 +160,14 @@ bool kvm_arm_supports_user_irq(void) { return false; } + +bool kvm_vcpu_id_is_valid(int vcpu_id) +{ + return true; +} + +unsigned long kvm_arch_vcpu_id(CPUState *cpu) +{ + return cpu->cpu_index; +} #endif