From patchwork Thu Sep 8 13:25:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1675592 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UL96f5I7; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MNfyp35Qbz1yj1 for ; Thu, 8 Sep 2022 23:26:09 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MNfyn633kz3bvZ for ; Thu, 8 Sep 2022 23:26:09 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UL96f5I7; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42f; helo=mail-pf1-x42f.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UL96f5I7; dkim-atps=neutral Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MNfyc5pWNz303T for ; Thu, 8 Sep 2022 23:25:58 +1000 (AEST) Received: by mail-pf1-x42f.google.com with SMTP id e5so89174pfl.2 for ; Thu, 08 Sep 2022 06:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=log0diJjGxBlvSxf2yN5pbMKbshxXY0OSVP3MW4ICZg=; b=UL96f5I7AaCVCASEIkm5LW6I2hv/WJ93iwOtLyvlXeOBhmn543NSDEcb/2+SvKQPOl JxM6DTYv4e6T0BkWwVsgTTZcY2LPuv5Psnyu9cdEtzqdoSSRHUjZsh48O8ODr2wYpC8j PALES4WvinJvuf1AZw6jcZ4lrwV+DJx9/w5ns/vHN+eAmgZouASYP39xiV6P+oGIIxVh ncxcas+e6VWuZiHyl/SKNFfaSZoLfrTDzzW8FZdxLUwvm88P4K5wCQMsd6io/4sRk3tx WOl0kR1qkz5ClRHZGyZvlNENrmpHU6D9tz0pHnwiyUiyRNE19tEyvF2SxB+YzENm57eG rIgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=log0diJjGxBlvSxf2yN5pbMKbshxXY0OSVP3MW4ICZg=; b=ILiwr6IoiiWjIwpbb5mRUgIICGjhTCrhK+1RC5jhfEwf1NHg5xV+ua1KF69H7rNVgw RIEf44q9DdGedDKk589h6wUkWb5ym4kT3/bGQrfPsAXRalb/xIwwMNTOCsa2x66ZlH6p eR/s+1sdIMMfQbUfHVgQWoivw41WpbiCB7CH4KPGP6zuXnaY8liD96j2Yw3RvkKkOc8z NL9iuUl+X1dfdDwX3aMh9gAGeK7VbtjxxKFPo4lB4DZMAbnVDLnD0Rnv+YkpV8ZFUv8S u27pXtM2urYZZ/I5j0/DhePY167eQQOos79j9WFDBDupB+O6xLIuvVoersAuqz6+CIZZ eWUg== X-Gm-Message-State: ACgBeo34rZmhCUkMD38+5vOBYmeXhEn5ZIJTloNpct+KK+4e+yn26LIN eUvPmY66bkwt4VF3OP5mK64WqEoEWtzkBA== X-Google-Smtp-Source: AA6agR5+XapZByClH6vaW+GTvw17ZAA3ncF2TMd7zEiDBcQItXANW75VWyNmNovyYHXq5+tu2/a4Wg== X-Received: by 2002:a63:290:0:b0:41c:506f:7ae9 with SMTP id 138-20020a630290000000b0041c506f7ae9mr8001320pgc.373.1662643555765; Thu, 08 Sep 2022 06:25:55 -0700 (PDT) Received: from bobo.ibm.com ([193.114.109.49]) by smtp.gmail.com with ESMTPSA id z17-20020a170903019100b001768517f99esm12505504plg.244.2022.09.08.06.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 06:25:55 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 1/5] KVM: PPC: Book3S HV P9: Clear vcpu cpu fields before enabling host irqs Date: Thu, 8 Sep 2022 23:25:41 +1000 Message-Id: <20220908132545.4085849-1-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" On guest entry, vcpu->cpu and vcpu->arch.thread_cpu are set after disabling host irqs. On guest exit there is a window whre tick time accounting briefly enables irqs before these fields are cleared. Move them up to ensure they are cleared before host irqs are run. This is possibly not a problem, but is more symmetric and makes the fields less surprising. Signed-off-by: Nicholas Piggin --- arch/powerpc/kvm/book3s_hv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 57d0835e56fd..014575b31651 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -4615,6 +4615,9 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, set_irq_happened(trap); + vcpu->cpu = -1; + vcpu->arch.thread_cpu = -1; + context_tracking_guest_exit(); if (!vtime_accounting_enabled_this_cpu()) { local_irq_enable(); @@ -4630,9 +4633,6 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, } vtime_account_guest_exit(); - vcpu->cpu = -1; - vcpu->arch.thread_cpu = -1; - powerpc_local_irq_pmu_restore(flags); preempt_enable(); From patchwork Thu Sep 8 13:25:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1675594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=hnQAef5x; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MNfzS1CKrz1yj1 for ; Thu, 8 Sep 2022 23:26:44 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MNfzS0b7rz3bNj for ; Thu, 8 Sep 2022 23:26:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=hnQAef5x; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::102d; helo=mail-pj1-x102d.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=hnQAef5x; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MNfyc6G1sz30D0 for ; Thu, 8 Sep 2022 23:26:00 +1000 (AEST) Received: by mail-pj1-x102d.google.com with SMTP id pj10so7345843pjb.2 for ; Thu, 08 Sep 2022 06:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=b6R5QMvB2S/UrzCiGF2IsiVSCIsOB79N6a1hozlTLlk=; b=hnQAef5xTCRakQyJPwSW3KnWpdpHkLwsrx06fSZKw04MiOgKPSsWtfxCEJHX/1q3G6 W7Qbm3RBgLbstMJYJgUwbLhKZPo/HojBo18zkHgRGcTzEZlKtOF89rjVZbeUHBR3ILCW 7r7WyTAkRYAZu61x0wXR3Hk9ACjaVBG5o3Wbmcl4WMZvZVM3NWCfGofzLzF1GX00mT9E RAh0gVJt3gGQuAZ5hCASwtmD02b1va7Sn528b6t0OyNGaLLw/LBKTKpOjDKZlxaw6qO+ HlnnrP5Xh3aG7Ok3IbL01kn8RSJZfto4xzW6V7kQ6BfJxxjlq1vecmaeMqB1z17yGRmn aGBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=b6R5QMvB2S/UrzCiGF2IsiVSCIsOB79N6a1hozlTLlk=; b=3GHp2Fa3HCkrjtntB+P+JD+uDQiriallwCE5/5Jvcj6ZtFTfFT+VSOwKOTJV6LETmT YiiuI/LoRaxngAsRtFJMmQCqAgdhVR8p9yN79WQJgjgqfu3Rg1l3VLA2Y9fDfrYBR5Ds YCZJfHYexcNRh5PMO49RUHGp9nD8ixQjN8bFQ7Ede2AXL+Pk2S2uDzjdFSnlRb1sOB2p gv2d0jYIcvOp+ceJMDkeXflUM1ntnW22Hov8EaM71QGlp1HRNoVJxYbWPyx4F3IGwzkc DfsOT4kiBlY3+XWb/Y1qgkr+ek+pUB6AhVQOyr+MR2KiNG96agWRUKtdTHvxJAHRr9Lh n4bQ== X-Gm-Message-State: ACgBeo3bbMy6rOytj+H3Xctga/p/575jCEZqWeMeQVrZPjEByGfOVS9a MXemN2n72zL6uHTdld71hlgpJNN2EuFLAQ== X-Google-Smtp-Source: AA6agR5NUEKKZ4J8dkEe/3aeYaQc/UKDgV8Yf9JKScJ0Q5xPY2jXFQVzx6jym8WRhZTmVibyrN6zXA== X-Received: by 2002:a17:902:ec85:b0:175:55ce:f241 with SMTP id x5-20020a170902ec8500b0017555cef241mr8927578plg.89.1662643558174; Thu, 08 Sep 2022 06:25:58 -0700 (PDT) Received: from bobo.ibm.com ([193.114.109.49]) by smtp.gmail.com with ESMTPSA id z17-20020a170903019100b001768517f99esm12505504plg.244.2022.09.08.06.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 06:25:57 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 2/5] KVM: PPC: Book3S HV P9: Fix irq disabling in tick accounting Date: Thu, 8 Sep 2022 23:25:42 +1000 Message-Id: <20220908132545.4085849-2-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220908132545.4085849-1-npiggin@gmail.com> References: <20220908132545.4085849-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" kvmhv_run_single_vcpu() disables PMIs as well as Linux irqs, however the tick time accounting code enables and disables irqs and not PMIs within this region. By chance this might not actually cause a bug, but it is clearly an incorrect use of the APIs. Fixes: 2251fbe76395e ("KVM: PPC: Book3S HV P9: Improve mtmsrd scheduling by delaying MSR[EE] disable") Signed-off-by: Nicholas Piggin --- arch/powerpc/kvm/book3s_hv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 014575b31651..f62dfaaf6c39 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -4620,7 +4620,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, context_tracking_guest_exit(); if (!vtime_accounting_enabled_this_cpu()) { - local_irq_enable(); + powerpc_local_irq_pmu_restore(flags); /* * Service IRQs here before vtime_account_guest_exit() so any * ticks that occurred while running the guest are accounted to @@ -4629,7 +4629,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, * interrupts here, which has the problem that it accounts * interrupt processing overhead to the host. */ - local_irq_disable(); + powerpc_local_irq_pmu_save(flags); } vtime_account_guest_exit(); From patchwork Thu Sep 8 13:25:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1675595 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=i9DXLNAu; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MNg066tdlz1yj1 for ; Thu, 8 Sep 2022 23:27:18 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MNg066BgMz3c4x for ; Thu, 8 Sep 2022 23:27:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=i9DXLNAu; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::434; helo=mail-pf1-x434.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=i9DXLNAu; dkim-atps=neutral Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MNfyg4zmkz3bd3 for ; Thu, 8 Sep 2022 23:26:03 +1000 (AEST) Received: by mail-pf1-x434.google.com with SMTP id y136so12971985pfb.3 for ; Thu, 08 Sep 2022 06:26:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=hZuRvJiw5iye7TlBCTHMxBMXEhn2X/qZw/+1K30Lz6A=; b=i9DXLNAuXBXRuKC0m8kyzyHJWZEM7tbpI6RxTWvPgYqr5gz6q3GXkQjw0o9nhN9NUc LhAC+OnJkcW28oC/1oQk8deUZSSCzcOztnfonW71y//9CrvJV+iHpmAqZ57j9JP12kGH 1/z0pH30bmd8GQf8YsQyKL3ugKPQCLMiI9ZpVM9A4c7aXPAvQam3twCSy4eP4OEXt8jC dxCvKIMJ1IMHWjCZezVpCF5UtFpGbiC35F3L7WRb5luGDwpSnNID6P+outMdNhuuXKsk LERIMd4rzo0k7qjrvW+0PBF4LEv+eVa6nALKcsZa2n4a1o/oVyUltNtHTFYOCNIv62e+ c08A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=hZuRvJiw5iye7TlBCTHMxBMXEhn2X/qZw/+1K30Lz6A=; b=3gMt0YA1H3oVzzQfc6ZAEVAMyOs0KR8fo17HxJqYuzSqh7OtIiB6MzHaE5MRMKzGvz pOhA8kDnNCTow/mo2JigS1BXbbjTBU6USJ3hYYI9ZHFP+dIHZSAAG51WdGG/wxnytNEh RBZcpOJuxBn+Uy6mO7zk76r2xT6f2IqxEcf6Rtx1orYZvWsbGBHeq25EVCKdsOvdA7d+ NDvfkZbdSPfSN7WRbBZ4IJ0a0i6MPbkNFZz304MoJiI26o4fFlZbB7O1V0JNut4g58IE tClDI0No65M8K4uK2JRPMv4JL2ybFhILaQF65mspqcqkHCPo440MNcHmeo+Ucbq5bHP/ Gpxg== X-Gm-Message-State: ACgBeo3X4ho8WaNdWtUhZ4Bf0+aJZmlsH5QikUKzC/jIfbRQG3x2F5D8 Mu1w8M6rP+bVlYHDjUGNcntASMKqJG8bsQ== X-Google-Smtp-Source: AA6agR66vkU8jJVE9RzfXYZVet1kF/+I4i/oOEqp2i6cWYBd1/NNbn6sizbhz+iKvHJmVoHAYu4apA== X-Received: by 2002:a63:f313:0:b0:434:346b:d074 with SMTP id l19-20020a63f313000000b00434346bd074mr8112513pgh.298.1662643560838; Thu, 08 Sep 2022 06:26:00 -0700 (PDT) Received: from bobo.ibm.com ([193.114.109.49]) by smtp.gmail.com with ESMTPSA id z17-20020a170903019100b001768517f99esm12505504plg.244.2022.09.08.06.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 06:26:00 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 3/5] KVM: PPC: Book3S HV: Update guest state entry/exit accounting to new API Date: Thu, 8 Sep 2022 23:25:43 +1000 Message-Id: <20220908132545.4085849-3-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220908132545.4085849-1-npiggin@gmail.com> References: <20220908132545.4085849-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Update the guest state and timing entry/exit accounting to use the new API, which was introduced following issues found[1]. KVM HV does possibly call instrumented code inside the guest context, and it does call srcu inside the guest context which is fragile at best. Switch to the new API, moving the guest context inside the srcu_read_lock/unlock region. [1] https://lore.kernel.org/lkml/20220201132926.3301912-1-mark.rutland@arm.com/ Cc: Mark Rutland Signed-off-by: Nicholas Piggin --- Since RFC: - Drop unrelated changes. - Cut the amount of code churn to a minimum. arch/powerpc/kvm/book3s_hv.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index f62dfaaf6c39..771b8b0e0329 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -3840,23 +3840,17 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc) for (sub = 0; sub < core_info.n_subcores; ++sub) spin_unlock(&core_info.vc[sub]->lock); - guest_enter_irqoff(); + guest_timing_enter_irqoff(); srcu_idx = srcu_read_lock(&vc->kvm->srcu); + guest_state_enter_irqoff(); this_cpu_disable_ftrace(); - /* - * Interrupts will be enabled once we get into the guest, - * so tell lockdep that we're about to enable interrupts. - */ - trace_hardirqs_on(); - trap = __kvmppc_vcore_entry(); - trace_hardirqs_off(); - this_cpu_enable_ftrace(); + guest_state_exit_irqoff(); srcu_read_unlock(&vc->kvm->srcu, srcu_idx); @@ -3891,11 +3885,10 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc) kvmppc_set_host_core(pcpu); - context_tracking_guest_exit(); if (!vtime_accounting_enabled_this_cpu()) { local_irq_enable(); /* - * Service IRQs here before vtime_account_guest_exit() so any + * Service IRQs here before guest_timing_exit_irqoff() so any * ticks that occurred while running the guest are accounted to * the guest. If vtime accounting is enabled, accounting uses * TB rather than ticks, so it can be done without enabling @@ -3904,7 +3897,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc) */ local_irq_disable(); } - vtime_account_guest_exit(); + guest_timing_exit_irqoff(); local_irq_enable(); @@ -4595,21 +4588,18 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, trace_kvm_guest_enter(vcpu); - guest_enter_irqoff(); + guest_timing_enter_irqoff(); srcu_idx = srcu_read_lock(&kvm->srcu); + guest_state_enter_irqoff(); this_cpu_disable_ftrace(); - /* Tell lockdep that we're about to enable interrupts */ - trace_hardirqs_on(); - trap = kvmhv_p9_guest_entry(vcpu, time_limit, lpcr, &tb); vcpu->arch.trap = trap; - trace_hardirqs_off(); - this_cpu_enable_ftrace(); + guest_state_exit_irqoff(); srcu_read_unlock(&kvm->srcu, srcu_idx); @@ -4618,11 +4608,10 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, vcpu->cpu = -1; vcpu->arch.thread_cpu = -1; - context_tracking_guest_exit(); if (!vtime_accounting_enabled_this_cpu()) { powerpc_local_irq_pmu_restore(flags); /* - * Service IRQs here before vtime_account_guest_exit() so any + * Service IRQs here before guest_timing_exit_irqoff() so any * ticks that occurred while running the guest are accounted to * the guest. If vtime accounting is enabled, accounting uses * TB rather than ticks, so it can be done without enabling @@ -4631,7 +4620,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, */ powerpc_local_irq_pmu_save(flags); } - vtime_account_guest_exit(); + guest_timing_exit_irqoff(); powerpc_local_irq_pmu_restore(flags); From patchwork Thu Sep 8 13:25:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1675596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Kk6Aykgg; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MNg0n3dD5z1yj1 for ; Thu, 8 Sep 2022 23:27:53 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MNg0n33zMz3cjL for ; Thu, 8 Sep 2022 23:27:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Kk6Aykgg; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::533; helo=mail-pg1-x533.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Kk6Aykgg; dkim-atps=neutral Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MNfyk2L0Xz3br9 for ; Thu, 8 Sep 2022 23:26:05 +1000 (AEST) Received: by mail-pg1-x533.google.com with SMTP id r17so4312045pgr.7 for ; Thu, 08 Sep 2022 06:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Og0o94+N0+6YORMvQ8vPWX9HpFF+KjQSP+rVXPGi/mc=; b=Kk6AykggaSeabC8+I+dLgi5ZwO2iiIe8pm0AmmUc71YaW27Euk4QAJKjj1bmnuQAqr 3M3rSZNBPuCS+XdQ61MPlS4SsHFmF0iw10Cu7rC50ZkQFoGfiKJk3FtXkd7kVbmlzqM0 gDzH5aucBvI7Xh/52GF2U2KOMijmrbecJJetcCqvUfT8NJnPye9DP9XA3I153RUw4eFb d4yb+knkPz9GkNALdkOuKFJbjusTiVgrb1zUW8gi3xvj4SLOzTKyBaxgubRkzKoh4mRi jDlr5kaALtLUQ4W78JGo1giX0PcqmP1vslsxYQH7qj4ZJMFa0WjbznXOFaSr1kWun0xL pR+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Og0o94+N0+6YORMvQ8vPWX9HpFF+KjQSP+rVXPGi/mc=; b=TXWiQwu/m/z2DpTJGeIy9/eOanIEaj5NR9pa+aW2r1suHeZZ5b3pCFw3iZfRkdPiEI HpFQ5W9e9SplNs61FNCNmj/Km0yi2xMF9T9Rb607AfzFUDY8Jx3H1Pc/xcw0I+yYy5yQ msrz+bM/98/KoFxW4LWmkxcsejMVp650T9wR6HGfx09l4xGqdO+KwZ8kn9bWJ7u8wPv4 PiPrJldDaOxiutQLRviDW8w2q5U7Rtefs8IfHOb0ZzFw8Dqe6SS50iUEPdNruGoDuQAg WOllHJ4MmTASTFsnWytHQ8mZ7A+twPF0cLMjHI41Xah7A/7W4NT4KjyCrMrD5C+wOgCF 9Npg== X-Gm-Message-State: ACgBeo1vq+/iQ/p6Xw3f8PrGfkzHPQrgN6YTHHnugy8EQTNfAp6e50ha 0hgcCEb2opN9CMD2rAl9NrgRdjvCxuQ0Rw== X-Google-Smtp-Source: AA6agR7azezNYIL+Cnxk2/QKVzFeFnruvpFay4EztsH1TryHO1w1vA5gljzsVVUn6RvMyYyzJQr0kw== X-Received: by 2002:a63:1546:0:b0:42c:50dc:2115 with SMTP id 6-20020a631546000000b0042c50dc2115mr8003725pgv.613.1662643563322; Thu, 08 Sep 2022 06:26:03 -0700 (PDT) Received: from bobo.ibm.com ([193.114.109.49]) by smtp.gmail.com with ESMTPSA id z17-20020a170903019100b001768517f99esm12505504plg.244.2022.09.08.06.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 06:26:02 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 4/5] KVM: PPC: Book3S HV P9: Restore stolen time logging in dtl Date: Thu, 8 Sep 2022 23:25:44 +1000 Message-Id: <20220908132545.4085849-4-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220908132545.4085849-1-npiggin@gmail.com> References: <20220908132545.4085849-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Stolen time logging in dtl was removed from the P9 path, so guests had no stolen time accounting. Add it back in a simpler way that still avoids locks and per-core accounting code. Fixes: ecb6a7207f92 ("KVM: PPC: Book3S HV P9: Remove most of the vcore logic") Signed-off-by: Nicholas Piggin --- arch/powerpc/kvm/book3s_hv.c | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 771b8b0e0329..c3a4785b10d5 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -249,6 +249,7 @@ static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu) /* * We use the vcpu_load/put functions to measure stolen time. + * * Stolen time is counted as time when either the vcpu is able to * run as part of a virtual core, but the task running the vcore * is preempted or sleeping, or when the vcpu needs something done @@ -278,6 +279,12 @@ static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu) * lock. The stolen times are measured in units of timebase ticks. * (Note that the != TB_NIL checks below are purely defensive; * they should never fail.) + * + * The POWER9 path is simpler, one vcpu per virtual core so the + * former case does not exist. If a vcpu is preempted when it is + * BUSY_IN_HOST and not ceded or otherwise blocked, then accumulate + * the stolen cycles in busy_stolen. RUNNING is not a preemptible + * state in the P9 path. */ static void kvmppc_core_start_stolen(struct kvmppc_vcore *vc, u64 tb) @@ -311,8 +318,14 @@ static void kvmppc_core_vcpu_load_hv(struct kvm_vcpu *vcpu, int cpu) unsigned long flags; u64 now; - if (cpu_has_feature(CPU_FTR_ARCH_300)) + if (cpu_has_feature(CPU_FTR_ARCH_300)) { + if (vcpu->arch.busy_preempt != TB_NIL) { + WARN_ON_ONCE(vcpu->arch.state != KVMPPC_VCPU_BUSY_IN_HOST); + vc->stolen_tb += mftb() - vcpu->arch.busy_preempt; + vcpu->arch.busy_preempt = TB_NIL; + } return; + } now = mftb(); @@ -340,8 +353,21 @@ static void kvmppc_core_vcpu_put_hv(struct kvm_vcpu *vcpu) unsigned long flags; u64 now; - if (cpu_has_feature(CPU_FTR_ARCH_300)) + if (cpu_has_feature(CPU_FTR_ARCH_300)) { + /* + * In the P9 path, RUNNABLE is not preemptible + * (nor takes host interrupts) + */ + WARN_ON_ONCE(vcpu->arch.state == KVMPPC_VCPU_RUNNABLE); + /* + * Account stolen time when preempted while the vcpu task is + * running in the kernel (but not in qemu, which is INACTIVE). + */ + if (task_is_running(current) && + vcpu->arch.state == KVMPPC_VCPU_BUSY_IN_HOST) + vcpu->arch.busy_preempt = mftb(); return; + } now = mftb(); @@ -740,6 +766,18 @@ static void __kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu, vcpu->arch.dtl.dirty = true; } +static void kvmppc_create_dtl_entry_p9(struct kvm_vcpu *vcpu, + struct kvmppc_vcore *vc, + u64 now) +{ + unsigned long stolen; + + stolen = vc->stolen_tb - vcpu->arch.stolen_logged; + vcpu->arch.stolen_logged = vc->stolen_tb; + + __kvmppc_create_dtl_entry(vcpu, vc->pcpu, now, stolen); +} + static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu, struct kvmppc_vcore *vc) { @@ -4513,7 +4551,6 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, vc = vcpu->arch.vcore; vcpu->arch.ceded = 0; vcpu->arch.run_task = current; - vcpu->arch.state = KVMPPC_VCPU_RUNNABLE; vcpu->arch.last_inst = KVM_INST_FETCH_FAILED; /* See if the MMU is ready to go */ @@ -4540,6 +4577,8 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, /* flags save not required, but irq_pmu has no disable/enable API */ powerpc_local_irq_pmu_save(flags); + vcpu->arch.state = KVMPPC_VCPU_RUNNABLE; + if (signal_pending(current)) goto sigpend; if (need_resched() || !kvm->arch.mmu_ready) @@ -4584,7 +4623,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, tb = mftb(); - __kvmppc_create_dtl_entry(vcpu, pcpu, tb + vc->tb_offset, 0); + kvmppc_create_dtl_entry_p9(vcpu, vc, tb + vc->tb_offset); trace_kvm_guest_enter(vcpu); @@ -4607,6 +4646,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, vcpu->cpu = -1; vcpu->arch.thread_cpu = -1; + vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; if (!vtime_accounting_enabled_this_cpu()) { powerpc_local_irq_pmu_restore(flags); @@ -4683,6 +4723,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, out: vcpu->cpu = -1; vcpu->arch.thread_cpu = -1; + vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; powerpc_local_irq_pmu_restore(flags); preempt_enable(); goto done; From patchwork Thu Sep 8 13:25:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1675597 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=LIxLxmnZ; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MNg1b3hn1z1yj1 for ; Thu, 8 Sep 2022 23:28:35 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MNg1b3TPjz3dwP for ; Thu, 8 Sep 2022 23:28:35 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=LIxLxmnZ; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::534; helo=mail-pg1-x534.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=LIxLxmnZ; dkim-atps=neutral Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MNfym3GJ8z3bwr for ; Thu, 8 Sep 2022 23:26:08 +1000 (AEST) Received: by mail-pg1-x534.google.com with SMTP id t65so5813092pgt.2 for ; Thu, 08 Sep 2022 06:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=XG+9udUlOy7seLjhzDlhW7K+fh9Lq8hdqIdeUcTOgS4=; b=LIxLxmnZUyHitj4ZjiMk/Dsm2nU7orfV6csXhu6W1zT77YxpExgiRcQIGMy/GC7SaP BpfmMHtPSRWYbO8XLdyg8VyR/lBmCl0KIpcQy+yOM+k3l1EAM/FbSIpkjIw7vhDKS98r 8PJ5D+auFOVHd8FJOcVBoYG+nZiOshi3THM4S8rLM++pb9UkBfuUPkaiHDqCU0dHjivC LUQFPprWhjYAJ/JH2n4jx2lpP3IjyA3kNHL1exuB7460XE1uIFf8GPjTTBs46nHlG+Yy FwSus0PeMfVyUmt7ZBAY6ztJUuYkWt6vCENUEl8L7ksISKUSJ72NKUIeiAb5gt4Tc6V4 j+Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=XG+9udUlOy7seLjhzDlhW7K+fh9Lq8hdqIdeUcTOgS4=; b=kALdpw4PheiXAFgpVX4pUlqLDmmsrdD1kzWQBdd8Hec5+R9U6suJK0ioI1rmmy1d4D pMuHuiqH1BFRJQOW8hY+aiacbe/hq+gFfkRbR6qRNZQUgW0EFi072Geo9rneIraFHKst UmoqOW47jQ6N6TLB6HVHk3iJo38jZPMJ0HZ5cXBItkW9BwTKnQ5iCwnZQIMJNTukAhxL uDJ0dWRu12gg88yr7RtxhhkOE8WFXG0cBvn6xTLj+AHXgLMbYZVnGC2IwUGqd338uCEG j4pgQW4SCrRdm3aBEKizbgCiLLPK12BHiodhSHD7gUwCbK4+9oePSgn7Qb1RV5dOhamt 3EXw== X-Gm-Message-State: ACgBeo3qPMN2GoCAOw2nFuJf1optHHxOF4ETr7LEJozg/uT3SlIreQBc zVLHAHcxqfFqMRGAbglm8QI0OvCDL6wXDg== X-Google-Smtp-Source: AA6agR7JaOB00QPpUU6VtTSiI4DsEFrhk9ZXCwHE9kfVddz+5D6ZG3oW71vCJ/u9nIx3ERHIGXlvTA== X-Received: by 2002:a63:df14:0:b0:42b:484c:4273 with SMTP id u20-20020a63df14000000b0042b484c4273mr7730948pgg.186.1662643565963; Thu, 08 Sep 2022 06:26:05 -0700 (PDT) Received: from bobo.ibm.com ([193.114.109.49]) by smtp.gmail.com with ESMTPSA id z17-20020a170903019100b001768517f99esm12505504plg.244.2022.09.08.06.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 06:26:05 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 5/5] KVM: PPC: Book3S HV: Implement scheduling wait interval counters in the VPA Date: Thu, 8 Sep 2022 23:25:45 +1000 Message-Id: <20220908132545.4085849-5-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220908132545.4085849-1-npiggin@gmail.com> References: <20220908132545.4085849-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin , Fabiano Rosas Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" PAPR specifies accumulated virtual processor wait intervals that relate to partition scheduling interval times. Implement these counters in the same way as they are repoted by dtl. Reviewed-by: Fabiano Rosas Signed-off-by: Nicholas Piggin --- This requires patch "powerpc/pseries: Add wait interval counter definitions to struct lppaca" https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-September/247798.html When running a host with this patch and a guest with the corresponding pseries implementation, the guest shows 10% stolen time with vmstat in a 160 vCPU guest running busy work on all CPUs on a 144 CPU host. 144/160 = 90%. arch/powerpc/kvm/book3s_hv.c | 62 ++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index c3a4785b10d5..2aca86290f76 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -733,16 +733,15 @@ static u64 vcore_stolen_time(struct kvmppc_vcore *vc, u64 now) } static void __kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu, + struct lppaca *vpa, unsigned int pcpu, u64 now, unsigned long stolen) { struct dtl_entry *dt; - struct lppaca *vpa; dt = vcpu->arch.dtl_ptr; - vpa = vcpu->arch.vpa.pinned_addr; - if (!dt || !vpa) + if (!dt) return; dt->dispatch_reason = 7; @@ -763,29 +762,23 @@ static void __kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu, /* order writing *dt vs. writing vpa->dtl_idx */ smp_wmb(); vpa->dtl_idx = cpu_to_be64(++vcpu->arch.dtl_index); - vcpu->arch.dtl.dirty = true; -} - -static void kvmppc_create_dtl_entry_p9(struct kvm_vcpu *vcpu, - struct kvmppc_vcore *vc, - u64 now) -{ - unsigned long stolen; - stolen = vc->stolen_tb - vcpu->arch.stolen_logged; - vcpu->arch.stolen_logged = vc->stolen_tb; - - __kvmppc_create_dtl_entry(vcpu, vc->pcpu, now, stolen); + /* vcpu->arch.dtl.dirty is set by the caller */ } -static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu, - struct kvmppc_vcore *vc) +static void kvmppc_update_vpa_dispatch(struct kvm_vcpu *vcpu, + struct kvmppc_vcore *vc) { + struct lppaca *vpa; unsigned long stolen; unsigned long core_stolen; u64 now; unsigned long flags; + vpa = vcpu->arch.vpa.pinned_addr; + if (!vpa) + return; + now = mftb(); core_stolen = vcore_stolen_time(vc, now); @@ -796,7 +789,34 @@ static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu, vcpu->arch.busy_stolen = 0; spin_unlock_irqrestore(&vcpu->arch.tbacct_lock, flags); - __kvmppc_create_dtl_entry(vcpu, vc->pcpu, now + vc->tb_offset, stolen); + vpa->enqueue_dispatch_tb = cpu_to_be64(be64_to_cpu(vpa->enqueue_dispatch_tb) + stolen); + + __kvmppc_create_dtl_entry(vcpu, vpa, vc->pcpu, now + vc->tb_offset, stolen); + + vcpu->arch.vpa.dirty = true; +} + +static void kvmppc_update_vpa_dispatch_p9(struct kvm_vcpu *vcpu, + struct kvmppc_vcore *vc, + u64 now) +{ + struct lppaca *vpa; + unsigned long stolen; + unsigned long stolen_delta; + + vpa = vcpu->arch.vpa.pinned_addr; + if (!vpa) + return; + + stolen = vc->stolen_tb; + stolen_delta = stolen - vcpu->arch.stolen_logged; + vcpu->arch.stolen_logged = stolen; + + vpa->enqueue_dispatch_tb = cpu_to_be64(stolen); + + __kvmppc_create_dtl_entry(vcpu, vpa, vc->pcpu, now, stolen_delta); + + vcpu->arch.vpa.dirty = true; } /* See if there is a doorbell interrupt pending for a vcpu */ @@ -3838,7 +3858,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc) * kvmppc_core_prepare_to_enter. */ kvmppc_start_thread(vcpu, pvc); - kvmppc_create_dtl_entry(vcpu, pvc); + kvmppc_update_vpa_dispatch(vcpu, pvc); trace_kvm_guest_enter(vcpu); if (!vcpu->arch.ptid) thr0_done = true; @@ -4435,7 +4455,7 @@ static int kvmppc_run_vcpu(struct kvm_vcpu *vcpu) if ((vc->vcore_state == VCORE_PIGGYBACK || vc->vcore_state == VCORE_RUNNING) && !VCORE_IS_EXITING(vc)) { - kvmppc_create_dtl_entry(vcpu, vc); + kvmppc_update_vpa_dispatch(vcpu, vc); kvmppc_start_thread(vcpu, vc); trace_kvm_guest_enter(vcpu); } else if (vc->vcore_state == VCORE_SLEEPING) { @@ -4623,7 +4643,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, tb = mftb(); - kvmppc_create_dtl_entry_p9(vcpu, vc, tb + vc->tb_offset); + kvmppc_update_vpa_dispatch_p9(vcpu, vc, tb + vc->tb_offset); trace_kvm_guest_enter(vcpu);