Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3172378pxp; Mon, 14 Mar 2022 12:29:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxV6aIoQ8wJjlIGHAc4vLfVt8G6qaAJyJDEauaM4aRQF4+TAPZShZHazeifwyrLoyoYQVJ X-Received: by 2002:a17:907:2d25:b0:6d7:c831:5714 with SMTP id gs37-20020a1709072d2500b006d7c8315714mr20043378ejc.137.1647286142855; Mon, 14 Mar 2022 12:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647286142; cv=none; d=google.com; s=arc-20160816; b=pciHg2Yi1p6iMbYzYh+8mYTR7nrBEpFyyXGR3yb3/sLpcPF1JPumrcFU6ZEinPlDwX +p5APy3w8yc/du2b7lQgKNGat6+H6cEiQcreQbZH5CwQREf8bLFgHiQ/jgqMkDAZ4iy3 QwnQfFN8m8Lj3+G7dLL+8DaN7GlGWlkXax9BMnoJoSVNoYmC9d+rga0vFNSjrNxe/k3Z G5aK4R3yeiBtOG9e+N2RahUYuumNjlqSPfxQy9td7MYUhKj6JCH5nD9mqbmG2/Jn1YaE LTIi4QCUZSS/a69jpzLMJ/LWEonYO9qAl2wsrSmIPujmCD5YZYTxtIe4oiXXpx4ynrFp gDsg== 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=uzGhcVtIlmKcCi6fCVbblOgP4Y/uwHLuvPaMz7hOcqw=; b=OkwkwonyRXUgbEX3ftEZfm5iu02FCx4MWBkCGk8us+0+nnBxwSF5x/MN/W2luCGsZY knaPMqL6WnQzr3cowAGhYb4ZUxDuCPHNfqBmpWUI0nRbUeoF58i3I3+brctRSSUwght9 cChyPH0nXUz9lLbNUWhusjTCzt2psKqJgqP6EmML3STxE19/6n5lQ7THppfb7IyEjEpY MQ9CS8+TjCR6sX/6Ld1uXd+qXC5N5k+RRuoJXGbfwu1GSO7hohWbS6JZcbQfUokfPl7g 4n7oFUNPyDySRhMNGe7C+Jg6xzu1D7gt12N2hp8hCfrCCydVITG+tZ4zKmr4X2r0UA7+ xXlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TIQPeqLD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp17-20020a170906c15100b006cfeb9ee051si10053613ejc.393.2022.03.14.12.28.36; Mon, 14 Mar 2022 12:29:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TIQPeqLD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S242060AbiCNM2w (ORCPT + 99 others); Mon, 14 Mar 2022 08:28:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243644AbiCNMVG (ORCPT ); Mon, 14 Mar 2022 08:21:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D13E354FB5; Mon, 14 Mar 2022 05:16:33 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 6766B60C77; Mon, 14 Mar 2022 12:16:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BE79C340E9; Mon, 14 Mar 2022 12:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647260192; bh=q6225OgmNK7kllOTZPGgFL9ixZv/nU3ERVzIB1tEN58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TIQPeqLDBZqh1IKZAK9dFGSyYgbxaIvTCIr/GITR48vixGd61wNdBi2eiRtR35xfZ +IpJFL/WsDJ0xfZjYum7j+3/EjNX1upD3g65xthIm9lc0S2mhnOGa3x6f4xSjFp+9Z UHCotToxd1MhHzftvnw6gjR3kocB6xsGOLXVRjzU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anton Romanov , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.16 065/121] kvm: x86: Disable KVM_HC_CLOCK_PAIRING if tsc is in always catchup mode Date: Mon, 14 Mar 2022 12:54:08 +0100 Message-Id: <20220314112745.939591232@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112744.120491875@linuxfoundation.org> References: <20220314112744.120491875@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=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Anton Romanov [ Upstream commit 3a55f729240a686aa8af00af436306c0cd532522 ] If vcpu has tsc_always_catchup set each request updates pvclock data. KVM_HC_CLOCK_PAIRING consumers such as ptp_kvm_x86 rely on tsc read on host's side and do hypercall inside pvclock_read_retry loop leading to infinite loop in such situation. v3: Removed warn Changed return code to KVM_EFAULT v2: Added warn Signed-off-by: Anton Romanov Message-Id: <20220216182653.506850-1-romanton@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/x86.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c6eb3e45e3d8..e8f495b9ae10 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8770,6 +8770,13 @@ static int kvm_pv_clock_pairing(struct kvm_vcpu *vcpu, gpa_t paddr, if (clock_type != KVM_CLOCK_PAIRING_WALLCLOCK) return -KVM_EOPNOTSUPP; + /* + * When tsc is in permanent catchup mode guests won't be able to use + * pvclock_read_retry loop to get consistent view of pvclock + */ + if (vcpu->arch.tsc_always_catchup) + return -KVM_EOPNOTSUPP; + if (!kvm_get_walltime_and_clockread(&ts, &cycle)) return -KVM_EOPNOTSUPP; -- 2.34.1