Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3028218pxb; Mon, 18 Oct 2021 06:55:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGrRjS/U7BDfVQMSZ5itT8wSTcWXtWDWHjdfl/0/tPIEcC6hFEe2n9It93oPRCF2D5YAcf X-Received: by 2002:a17:90b:1806:: with SMTP id lw6mr33324322pjb.222.1634565307288; Mon, 18 Oct 2021 06:55:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634565307; cv=none; d=google.com; s=arc-20160816; b=SZ/LjrEnfhABMgRTKYcaZ8EmIE7sGDLhsk/msY1LbtLuu6u+ogItJNArX49GdJ3i52 kc1mxYXlO80Ac9oxlInj7c66IPCrG5D8kkvb1HBXzOWwWJqcUD8UE3vjNHJOTVbQLo6o A2XY5IHo/Qdq48FZB40rqO2B71vl9gMXgIHvMLah4AIOG2RNadU2nNehS58OKUpni1JF QHrXl2qQM60/fA5zAVE6vrXgTAMmBMH8dJ3pcYbI6YqFOF3xW4r+HGssaJJhAGefQQf4 ymLfQNCqFjxbCr/xxiO7w6QjecsEmYvUgUNtzrWiWAeMBFe1IfoOqPb0DWlknMq5cCqN qPGw== 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=QxIFQlIH1MaCcHtJdkMR1a1dl9Ru9wNLsO7EjNWfThs=; b=z90VOhPORahNwezRsmcoOLTYCSuXSPJBJtBMubhcGjfsmuqNOQv56aTj5CmzNueO3U 24SJ3DY47B98fe+2xKU78+Pn38zCCR1xNG9H8dvmhY0D9xGPN38w2l2U34o998MF6Odx gWWiy4gjZzTEBGAW4KWJrwQX77rjyF8IHwr+5oh9f+OutH5y2dccmrqcKQ1pAddz/n/l /oDkwjmGGh8M+Fh1XrRmZkZfq6rFf7K3gPXkM+XgqERMNxRb1TS/PmM/f64wY4HEgHTD /KNKhiri3Lp1eJfX+2jsUslqYXqO17C9btPPbktb8eQoO6yd6sRrFs1BbHasF+wSLHOq up4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u48kO6zZ; 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 hf24si19207850pjb.7.2021.10.18.06.54.52; Mon, 18 Oct 2021 06:55:07 -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=u48kO6zZ; 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 S232200AbhJRN4E (ORCPT + 99 others); Mon, 18 Oct 2021 09:56:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:58198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234472AbhJRNx4 (ORCPT ); Mon, 18 Oct 2021 09:53:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 422FB619F5; Mon, 18 Oct 2021 13:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564366; bh=jX8oLkjFFqTvA6DxKsaB1LJrVxL87LonVxv4sXsVfWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u48kO6zZdQoAoyD54fFG/vus+3y3SByfC6/bdAGuEtWUSyLaeIhBOafzEvfdwC0kx gwsnejHKR8QKxhPQfHcnyiiWuWrrTPfgXWr5nltFcUFN6jBgig2B4jckTHBNMOqfG7 51WNu9xsnEx8xdeg4Hx1QrRHaXT2ccFyCxYmeIEQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman Subject: [PATCH 5.14 061/151] KVM: PPC: Book3S HV: Make idle_kvm_start_guest() return 0 if it went to guest Date: Mon, 18 Oct 2021 15:24:00 +0200 Message-Id: <20211018132342.680787028@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132340.682786018@linuxfoundation.org> References: <20211018132340.682786018@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: Michael Ellerman commit cdeb5d7d890e14f3b70e8087e745c4a6a7d9f337 upstream. We call idle_kvm_start_guest() from power7_offline() if the thread has been requested to enter KVM. We pass it the SRR1 value that was returned from power7_idle_insn() which tells us what sort of wakeup we're processing. Depending on the SRR1 value we pass in, the KVM code might enter the guest, or it might return to us to do some host action if the wakeup requires it. If idle_kvm_start_guest() is able to handle the wakeup, and enter the guest it is supposed to indicate that by returning a zero SRR1 value to us. That was the behaviour prior to commit 10d91611f426 ("powerpc/64s: Reimplement book3s idle code in C"), however in that commit the handling of SRR1 was reworked, and the zeroing behaviour was lost. Returning from idle_kvm_start_guest() without zeroing the SRR1 value can confuse the host offline code, causing the guest to crash and other weirdness. Fixes: 10d91611f426 ("powerpc/64s: Reimplement book3s idle code in C") Cc: stable@vger.kernel.org # v5.2+ Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20211015133929.832061-2-mpe@ellerman.id.au Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S +++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S @@ -264,6 +264,7 @@ _GLOBAL(idle_kvm_start_guest) stdu r1, -SWITCH_FRAME_SIZE(r4) // Switch to new frame on emergency stack mr r1, r4 + std r3, 32(r1) // Save SRR1 wakeup value SAVE_NVGPRS(r1) /* @@ -315,6 +316,10 @@ kvm_unsplit_wakeup: kvm_secondary_got_guest: + // About to go to guest, clear saved SRR1 + li r0, 0 + std r0, 32(r1) + /* Set HSTATE_DSCR(r13) to something sensible */ ld r6, PACA_DSCR_DEFAULT(r13) std r6, HSTATE_DSCR(r13) @@ -394,8 +399,8 @@ kvm_no_guest: mfspr r4, SPRN_LPCR rlwimi r4, r3, 0, LPCR_PECE0 | LPCR_PECE1 mtspr SPRN_LPCR, r4 - /* set up r3 for return */ - mfspr r3,SPRN_SRR1 + // Return SRR1 wakeup value, or 0 if we went into the guest + ld r3, 32(r1) REST_NVGPRS(r1) ld r1, 0(r1) // Switch back to caller stack ld r0, 16(r1) // Reload LR