Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4464816ioa; Wed, 27 Apr 2022 04:35:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpkLX2NozKXGH+Il0plLscK6Kpna9jnZ9HqSqAmBc+Jzwx9hSgbyOq8cz2PFAJNc+MIXIS X-Received: by 2002:a63:6ac6:0:b0:3c1:4744:1abf with SMTP id f189-20020a636ac6000000b003c147441abfmr2499726pgc.588.1651059314452; Wed, 27 Apr 2022 04:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651059314; cv=none; d=google.com; s=arc-20160816; b=oB7U/nz3qHRT9moqANXDSXl4OER8U6yaqBETQN42/ToPvjtE3b8RKq5TiuesN38IdC x7CVRU65WfmWouLmOYcVbc8wizUrIVshNngJA955d0FHKJ4hEDzug56jrWAIhaiZEsR2 spL5CA+OizjAcKlmw+dF1ZBj72HWYIIfWdvSEofZRoyo2Wm724iYkK4lnjN5QtnE1vyJ zR+yiD9BG6cG5hM+pVfj1liPGbx53bddvWH/a/ADr94IGWSp+SGXWKLU1ivUGbyvOGME IHSPE3jpbpU9cGiTma+/rFEVmRy6PZudiaxsHFKfoAuyL1Gt/vgOWYVC0tqVF3sHNDmJ Os7w== 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=b6++sd/tm/GB2xgwFZ3wS4VisyKHT2Q8zwmuBKBeK1I=; b=gSiMP2/EEgOrqDutjBsogYrmXhWw+uxFkv4pt0nSBW2LM1r/iqp7tVL1xYCHYhkVZ2 IRyh9tn4gnAZ/8wQ4BHTC2UCyWxdUplT5kLaQ4QXvKG5e8k3hT5NQxIfzlVkhHWrAhQG mdx/yFCTiw8Lqt7Na+kBogIWgHBh8Cu44V08as7O8npIDgKq+KdhwzPKFu5/O3HVkhaI eaHRHjBvWlTxFdMU1buONiq1cmEzF17qEfrQ+xDqmOEVuZLnApyYlJH1yqZ812ZAJV4D IIyF2/rv8jPym5kC8PY6vJ43beCMruiAW7dprhPT1ceu4TyyFNsHSDmVhbYSoBGPcAlO KZNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wALMeqXu; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i190-20020a6387c7000000b003993a5ee24bsi1092413pge.693.2022.04.27.04.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:35:14 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wALMeqXu; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 63647496526; Wed, 27 Apr 2022 03:24:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237572AbiDZJiB (ORCPT + 99 others); Tue, 26 Apr 2022 05:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346280AbiDZJH3 (ORCPT ); Tue, 26 Apr 2022 05:07:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01F9ACA0D7; Tue, 26 Apr 2022 01:48:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B14F5B81D0A; Tue, 26 Apr 2022 08:48:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDB37C385A0; Tue, 26 Apr 2022 08:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962912; bh=dTrkoAicnKNbR8OoKD9QRqhGbzc5PwsgGK9Ouyr9B7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wALMeqXus2Z04YUG1AhB9X/AGLzp18hM5tVNhD8GYAyJlqEGHStxb0xfR8uEPbdpc P53UcnmQPhyclO2+xYXhgtrTCfXd3bRQnTuqI8WNcAkjM4HtJDN1M8MPShwBoGiteB Sy0kED6HcevFT/bKP/Rod8oXiaT2wI9Qh7wkKVv4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Maxim Levitsky , Paolo Bonzini Subject: [PATCH 5.17 129/146] KVM: x86: Dont re-acquire SRCU lock in complete_emulated_io() Date: Tue, 26 Apr 2022 10:22:04 +0200 Message-Id: <20220426081753.688082335@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081750.051179617@linuxfoundation.org> References: <20220426081750.051179617@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE 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 From: Sean Christopherson commit 2d08935682ac5f6bfb70f7e6844ec27d4a245fa4 upstream. Don't re-acquire SRCU in complete_emulated_io() now that KVM acquires the lock in kvm_arch_vcpu_ioctl_run(). More importantly, don't overwrite vcpu->srcu_idx. If the index acquired by complete_emulated_io() differs from the one acquired by kvm_arch_vcpu_ioctl_run(), KVM will effectively leak a lock and hang if/when synchronize_srcu() is invoked for the relevant grace period. Fixes: 8d25b7beca7e ("KVM: x86: pull kvm->srcu read-side to kvm_arch_vcpu_ioctl_run") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky Message-Id: <20220415004343.2203171-2-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10296,12 +10296,7 @@ static int vcpu_run(struct kvm_vcpu *vcp static inline int complete_emulated_io(struct kvm_vcpu *vcpu) { - int r; - - vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); - r = kvm_emulate_instruction(vcpu, EMULTYPE_NO_DECODE); - srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); - return r; + return kvm_emulate_instruction(vcpu, EMULTYPE_NO_DECODE); } static int complete_emulated_pio(struct kvm_vcpu *vcpu)