From patchwork Wed May 25 16:57:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 12861445 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36A22C433F5 for ; Wed, 25 May 2022 16:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=joW0Dwpyyr0teYmgA48iTfVQgF9xQ7oq4cAGnfsUcBc=; b=MKjLaT/h1WVaeK C2C+Elh3xc2iHBtRw75y3Hx9LY4ZWrLREDlN8lBU8ThE2cGXrxd5yB/D4p1IX+IGv+10KDJ7QPTwc HlmZjlH1gU+3lk7DFdf1ILc8a6NCnPla9zHTwZyQ30eLTcd88K6zkx3CXu02w48tYYknvTHdPhoIm XPxRFi6R26G57tzCxGxEGRtkU8gDb+HxLJiyVueyZTVFC5s8fEoLXdqzEUopmXM2nJ6ppiej9yA1c 9mKikj9402h8Zc4G/67ZaneuceGJK1fxlJn7vLzu5qSAHqaPUmM6z7JbDzuwy5PeWACyMr/qUmt+v otMa3iiF2R1cSrLsWNEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntuJv-00BuGS-Os; Wed, 25 May 2022 16:57:15 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntuJk-00BuEO-Rw for linux-arm-kernel@lists.infradead.org; Wed, 25 May 2022 16:57:06 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D2F0A14BF; Wed, 25 May 2022 09:57:03 -0700 (PDT) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9F5F23F93E; Wed, 25 May 2022 09:57:02 -0700 (PDT) From: Alexandru Elisei To: will@kernel.org, julien.thierry.kdev@gmail.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, andre.przywara@arm.com Subject: [PATCH kvmtool 1/2] arm64: Honor --vcpu-affinity for aarch32 guests Date: Wed, 25 May 2022 17:57:03 +0100 Message-Id: <20220525165704.186754-2-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220525165704.186754-1-alexandru.elisei@arm.com> References: <20220525165704.186754-1-alexandru.elisei@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220525_095704_985539_3A511FE5 X-CRM114-Status: GOOD ( 15.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Commit 4639b72f61a3 ("arm64: Add --vcpu-affinity command line argument") introduced the --vcpu-affinity command line argument to pin the VCPUs to a given list of physical CPUs. Unfortunately, the affinity is set only for an arm64 guest, leading to the following error when running a 32-bit guest on a system with two or more PMUs: KVM exit reason: 9 ("KVM_EXIT_FAIL_ENTRY") Registers: PC: 0x8000c608 PSTATE: 0x200000d3 SP_EL1: 0x0 LR: 0x0 *pc: 0x8000c608: 25 3f a0 e1 83 61 a0 e1 0x8000c610: 83 31 98 e7 04 10 82 e1 0x8000c618: 07 2c 81 e3 28 10 1b e5 0x8000c620: 03 20 82 e3 03 00 a0 e1 *lr: Warning: unable to translate guest address 0x0 to host 0x00000000: 0x00000008: 0x00000010: 0x00000018: # KVM compatibility warning. virtio-net device was not detected. While you have requested a virtio-net device, the guest kernel did not initialize it. Please make sure that the guest kernel was compiled with CONFIG_VIRTIO_NET=y enabled in .config. # KVM session ended normally. Make the error go away by setting the affinity of the VCPUs for both 32-bit and 64-bit guests. Fixes: 4639b72f61a3 ("arm64: Add --vcpu-affinity command line argument") Signed-off-by: Alexandru Elisei --- arm/aarch64/kvm-cpu.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index 4ac0fafae06b..c8be10b3ca94 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -88,16 +88,7 @@ static void reset_vcpu_aarch64(struct kvm_cpu *vcpu) { struct kvm *kvm = vcpu->kvm; struct kvm_one_reg reg; - cpu_set_t *affinity; u64 data; - int ret; - - affinity = kvm->arch.vcpu_affinity_cpuset; - if (affinity) { - ret = sched_setaffinity(0, sizeof(cpu_set_t), affinity); - if (ret == -1) - die_perror("sched_setaffinity"); - } reg.addr = (u64)&data; @@ -179,7 +170,18 @@ int kvm_cpu__configure_features(struct kvm_cpu *vcpu) void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu) { - if (vcpu->kvm->cfg.arch.aarch32_guest) + struct kvm *kvm = vcpu->kvm; + cpu_set_t *affinity; + int ret; + + affinity = kvm->arch.vcpu_affinity_cpuset; + if (affinity) { + ret = sched_setaffinity(0, sizeof(cpu_set_t), affinity); + if (ret == -1) + die_perror("sched_setaffinity"); + } + + if (kvm->cfg.arch.aarch32_guest) return reset_vcpu_aarch32(vcpu); else return reset_vcpu_aarch64(vcpu);