Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1878303pxb; Mon, 13 Sep 2021 07:24:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPZncQo5Vu3u6F//zP2v2G1MBIZN7ecL3+Q5P28JlIATapaxIjt5f1oF+n4zkb8tKrhBY6 X-Received: by 2002:a17:906:b2d3:: with SMTP id cf19mr7080578ejb.298.1631543073110; Mon, 13 Sep 2021 07:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631543073; cv=none; d=google.com; s=arc-20160816; b=sZWxNuZY2BJ+FKot/9s3PsL+0N+P9PUHTKDK4i/VlvEcDo1d16FXn9C9wCOAofujbo szu72TgzLi+ONMtXa/qPMRi0JfkDMlu8yiF7COjDKNOb9k40vihQQ3deHMo0FWktFH6f RzkO3cvmy/QCvh9vyKgWeE7QpTA7XVD3lzmTFjZ+LS1ln00MfNX9DsJr3aOUezfvWqSz EJ9RADb0OKk5bkqVKZE0SLrdPKQMiw9b0Ks++C1fEAYm/dP+wjyCfQH9r7CIRLbZbQxl XRt9RTmGWVYA3L97jkHtTZLbK5S0ypkh/hhHSgpl8xnyl+cQmAEMA0sMV/ZuWGXGExXn fm8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8ZeW6P04W0L3bJgdKEYBs8PItSkNSjPDfgQoPGRgCEc=; b=t4Gyf/sjdwPNEE4AUDaw4pn3G9qDuMrnaOPwygoO6nXIfBNwHkmnprekqG0vNYqX25 Q37boUhCsY8sTGTPW6WKBKCFBQ+QyMnuoj/QPODfKlRGdoDGfIu6aDJdn/RoqBkhpbbG RKiGx9EJN5fsE7CHaP/y5+s7qdm9p8fH13qlhYYbb0vAwtBE0q7S8Uwm2V+W0varR0SI DQYeum6/p8fu1Pypy1SkFIO/TVNkueYyzGzVpSCfR++AzCEg6Zp7KTgOOvcc2Sdet0i+ FgllpRAlSv+vFP+k8FoRSSFilESy9tZ9xDaA50OimFmIuPzrtXWrih3ydqRR8TXtbmSI /UEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CGKiidDk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w20si7378723ejv.231.2021.09.13.07.24.07; Mon, 13 Sep 2021 07:24:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CGKiidDk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345626AbhIMOT4 (ORCPT + 99 others); Mon, 13 Sep 2021 10:19:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:37124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242459AbhIMOPM (ORCPT ); Mon, 13 Sep 2021 10:15:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8E78461AFA; Mon, 13 Sep 2021 13:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540652; bh=V9Z12daDq69BGaXOIG3sTgmjZulZoOY41ZxurHdYqm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CGKiidDkIXcXExP8ymAWoJwd4/u72YSAlQs2dNVPXRbFIVp3MD8qJJQHIh0wau3Gb 52HV3L1l3r7C1VkWmrwC6oKeY4Sg0o0fHDon6LSQmCxLkLU06+5fWt2gA/cauZnWmc fnIsTCELmvnQE9w9UzzrqXvF6x2MkVhk537xT79Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Halil Pasic , =?UTF-8?q?Christian=20Borntr=C3=A4ger?= , Claudio Imbrenda Subject: [PATCH 5.13 281/300] KVM: s390: index kvm->arch.idle_mask by vcpu_idx Date: Mon, 13 Sep 2021 15:15:42 +0200 Message-Id: <20210913131118.837826474@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Halil Pasic commit a3e03bc1368c1bc16e19b001fc96dc7430573cc8 upstream. While in practice vcpu->vcpu_idx == vcpu->vcp_id is often true, it may not always be, and we must not rely on this. Reason is that KVM decides the vcpu_idx, userspace decides the vcpu_id, thus the two might not match. Currently kvm->arch.idle_mask is indexed by vcpu_id, which implies that code like for_each_set_bit(vcpu_id, kvm->arch.idle_mask, online_vcpus) { vcpu = kvm_get_vcpu(kvm, vcpu_id); do_stuff(vcpu); } is not legit. Reason is that kvm_get_vcpu expects an vcpu_idx, not an vcpu_id. The trouble is, we do actually use kvm->arch.idle_mask like this. To fix this problem we have two options. Either use kvm_get_vcpu_by_id(vcpu_id), which would loop to find the right vcpu_id, or switch to indexing via vcpu_idx. The latter is preferable for obvious reasons. Let us make switch from indexing kvm->arch.idle_mask by vcpu_id to indexing it by vcpu_idx. To keep gisa_int.kicked_mask indexed by the same index as idle_mask lets make the same change for it as well. Fixes: 1ee0bc559dc3 ("KVM: s390: get rid of local_int array") Signed-off-by: Halil Pasic Reviewed-by: Christian Bornträger Reviewed-by: Claudio Imbrenda Cc: # 3.15+ Link: https://lore.kernel.org/r/20210827125429.1912577-1-pasic@linux.ibm.com Signed-off-by: Christian Borntraeger Signed-off-by: Greg Kroah-Hartman --- arch/s390/include/asm/kvm_host.h | 1 + arch/s390/kvm/interrupt.c | 12 ++++++------ arch/s390/kvm/kvm-s390.c | 2 +- arch/s390/kvm/kvm-s390.h | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h @@ -962,6 +962,7 @@ struct kvm_arch{ atomic64_t cmma_dirty_pages; /* subset of available cpu features enabled by user space */ DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS); + /* indexed by vcpu_idx */ DECLARE_BITMAP(idle_mask, KVM_MAX_VCPUS); struct kvm_s390_gisa_interrupt gisa_int; struct kvm_s390_pv pv; --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -419,13 +419,13 @@ static unsigned long deliverable_irqs(st static void __set_cpu_idle(struct kvm_vcpu *vcpu) { kvm_s390_set_cpuflags(vcpu, CPUSTAT_WAIT); - set_bit(vcpu->vcpu_id, vcpu->kvm->arch.idle_mask); + set_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.idle_mask); } static void __unset_cpu_idle(struct kvm_vcpu *vcpu) { kvm_s390_clear_cpuflags(vcpu, CPUSTAT_WAIT); - clear_bit(vcpu->vcpu_id, vcpu->kvm->arch.idle_mask); + clear_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.idle_mask); } static void __reset_intercept_indicators(struct kvm_vcpu *vcpu) @@ -3050,18 +3050,18 @@ int kvm_s390_get_irq_state(struct kvm_vc static void __airqs_kick_single_vcpu(struct kvm *kvm, u8 deliverable_mask) { - int vcpu_id, online_vcpus = atomic_read(&kvm->online_vcpus); + int vcpu_idx, online_vcpus = atomic_read(&kvm->online_vcpus); struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int; struct kvm_vcpu *vcpu; - for_each_set_bit(vcpu_id, kvm->arch.idle_mask, online_vcpus) { - vcpu = kvm_get_vcpu(kvm, vcpu_id); + for_each_set_bit(vcpu_idx, kvm->arch.idle_mask, online_vcpus) { + vcpu = kvm_get_vcpu(kvm, vcpu_idx); if (psw_ioint_disabled(vcpu)) continue; deliverable_mask &= (u8)(vcpu->arch.sie_block->gcr[6] >> 24); if (deliverable_mask) { /* lately kicked but not yet running */ - if (test_and_set_bit(vcpu_id, gi->kicked_mask)) + if (test_and_set_bit(vcpu_idx, gi->kicked_mask)) return; kvm_s390_vcpu_wakeup(vcpu); return; --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -4020,7 +4020,7 @@ static int vcpu_pre_run(struct kvm_vcpu kvm_s390_patch_guest_per_regs(vcpu); } - clear_bit(vcpu->vcpu_id, vcpu->kvm->arch.gisa_int.kicked_mask); + clear_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.gisa_int.kicked_mask); vcpu->arch.sie_block->icptcode = 0; cpuflags = atomic_read(&vcpu->arch.sie_block->cpuflags); --- a/arch/s390/kvm/kvm-s390.h +++ b/arch/s390/kvm/kvm-s390.h @@ -79,7 +79,7 @@ static inline int is_vcpu_stopped(struct static inline int is_vcpu_idle(struct kvm_vcpu *vcpu) { - return test_bit(vcpu->vcpu_id, vcpu->kvm->arch.idle_mask); + return test_bit(kvm_vcpu_get_idx(vcpu), vcpu->kvm->arch.idle_mask); } static inline int kvm_is_ucontrol(struct kvm *kvm)