Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp357799pxb; Wed, 6 Oct 2021 06:32:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy2fi2kg9bWAcS0mLi2WixszvyofI5dnu7Hsm8UimUjhMZRSzsgGYoEii1ggFLeWdi23uQ X-Received: by 2002:a05:600c:1992:: with SMTP id t18mr4285213wmq.48.1633527168565; Wed, 06 Oct 2021 06:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633527168; cv=none; d=google.com; s=arc-20160816; b=TB+RAKMzAV7q2EA25XyZmcwV+rxpU0aQqKYIy7ByC7yjj6tSsNUBOktJg7Ys1n1xyy f6N8b2+Lt4aBoMqRqXGq0mSTmcu+KjI8PBkVZJxw4OsOUZEs+vbAzT3/B3AqQY2lLjqK Po8/gxIHsHJnYACXrO2KKnQvUEJT92t95KQXSAhApA+b6H1R5S2DTpzkwx4FIbxe+oQT ySDgeaZZeJbC2qUdCXpEqD2Y2wzsHXOrX2s/cRRnAj5IJA3htGOZ+zKxg4oqqfjftvh/ GsBZqRVmF9QbM0iecm3cMCM0MnSXnvR4Xcg3y7Prh/u/CgxmfJ1HaVwegWWyJpiJxdG8 ApLw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7VbzgC5SAC2E508VBQ795CMnWa8U1GYCBuWrv3AiUHQ=; b=FkqRCeMNhE8jKM11khseUatAvbCGoHfXd4xnDPAYMDqM+NvZjIVof1Iz0/66gjyINK WNYT8zLjV8XCIyKqL+q4fcqBO3gDuUnKYRKULsc/lAwtv9p24oxw0FJOCUUd2Vv8A7Fa yS9tSEwXuzQ38LjLSxUPpW04OHKO7MQczL1JzM99wP2jiHX71HPa60e79ZQ3oHD4AwjZ 0Iru4zVW+n2YGWm69UXnVe8ovuF2b0kwaaZAnEj5lefu3b1EKg4byoVFZ/NOOOKpo7KT +4NWCsKH2DTzlK5ZC3grhgux5BcCGgCVRqCZsuCXIcjM0k8PFQyunO8vpZIhr0C42hsH u6Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z279v6kG; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si29708855edm.232.2021.10.06.06.32.20; Wed, 06 Oct 2021 06:32:48 -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=@kernel.org header.s=k20201202 header.b=Z279v6kG; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238912AbhJFNcZ (ORCPT + 99 others); Wed, 6 Oct 2021 09:32:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:48804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238668AbhJFNcS (ORCPT ); Wed, 6 Oct 2021 09:32:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EE5C66115A; Wed, 6 Oct 2021 13:30:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633527026; bh=WrArq5TDbHCcIBLOTgr1Em1sBBFfw26b3uB3ADisu30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z279v6kGkQU8MSHS2EUfhAOr78s9rZodOH/lQet7DLODpTiY0SdNjytOIt+AopO0R eCSHeA8sGwNR7uW+2OSThAeQ2Tr0YP3ZdSypiYz+AROc8H+vlpafphzKZy5S+fdtkk nVjyQHFXmXNOIcklnMGTwOdJsQ7OthHErji0RhMMDwCfS3Z+IBhvGiMb3uaijZ9KRF 5vzj6mn8ONabGH1SRaPnnpWvg6trNJE6rRgabfR6GaxBP2Kg0KXRwSHWPHRmY9Bkd8 SMnevOiifP8YWdM2tcnZWqG8/irO2lqe9tTruZ6sToQ4n8/Nhp7LuFgDocr/zCy4wG CSJbXH6se29Hw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sergey Senozhatsky , Paolo Bonzini , Sasha Levin , kvm@vger.kernel.org Subject: [PATCH MANUALSEL 5.14 3/9] KVM: do not shrink halt_poll_ns below grow_start Date: Wed, 6 Oct 2021 09:30:15 -0400 Message-Id: <20211006133021.271905-3-sashal@kernel.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211006133021.271905-1-sashal@kernel.org> References: <20211006133021.271905-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergey Senozhatsky [ Upstream commit ae232ea460888dc5a8b37e840c553b02521fbf18 ] grow_halt_poll_ns() ignores values between 0 and halt_poll_ns_grow_start (10000 by default). However, when we shrink halt_poll_ns we may fall way below halt_poll_ns_grow_start and endup with halt_poll_ns values that don't make a lot of sense: like 1 or 9, or 19. VCPU1 trace (halt_poll_ns_shrink equals 2): VCPU1 grow 10000 VCPU1 shrink 5000 VCPU1 shrink 2500 VCPU1 shrink 1250 VCPU1 shrink 625 VCPU1 shrink 312 VCPU1 shrink 156 VCPU1 shrink 78 VCPU1 shrink 39 VCPU1 shrink 19 VCPU1 shrink 9 VCPU1 shrink 4 Mirror what grow_halt_poll_ns() does and set halt_poll_ns to 0 as soon as new shrink-ed halt_poll_ns value falls below halt_poll_ns_grow_start. Signed-off-by: Sergey Senozhatsky Signed-off-by: Paolo Bonzini Message-Id: <20210902031100.252080-1-senozhatsky@chromium.org> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- virt/kvm/kvm_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index b50dbe269f4b..1a11dcb670a3 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3053,15 +3053,19 @@ static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) static void shrink_halt_poll_ns(struct kvm_vcpu *vcpu) { - unsigned int old, val, shrink; + unsigned int old, val, shrink, grow_start; old = val = vcpu->halt_poll_ns; shrink = READ_ONCE(halt_poll_ns_shrink); + grow_start = READ_ONCE(halt_poll_ns_grow_start); if (shrink == 0) val = 0; else val /= shrink; + if (val < grow_start) + val = 0; + vcpu->halt_poll_ns = val; trace_kvm_halt_poll_ns_shrink(vcpu->vcpu_id, val, old); } -- 2.33.0