Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1866428lql; Wed, 13 Mar 2024 10:11:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWXeMikCqTWpNBLTHYq6SNgGBQ9dQfIVeKHB85mzmf9S/YkAwVjBUbxV5OylRBu7QWlFODW7NlPYrDamgTPHraRDlj9pgv5gcfygdfFiA== X-Google-Smtp-Source: AGHT+IFPpiQgE8J53f90pdDyjX80vqWaRiHMVVKG3xsXmp29DmVEmmclTzQZQmyHj/igJ8fZ/tS/ X-Received: by 2002:a05:620a:20da:b0:788:2e1e:772c with SMTP id f26-20020a05620a20da00b007882e1e772cmr463787qka.45.1710349894241; Wed, 13 Mar 2024 10:11:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710349894; cv=pass; d=google.com; s=arc-20160816; b=Q1QPy6X8z2WT38WI8cWzhzQFU4UpAo/LwLiiWwTUMvesMFT2avZiBunl0lNq+ukqzX xlnGU4WSnShbKMowLCk09g0656DecjDUCbaP4TisqIW4gOcJ1UQiRuW3k/lRUITFn8W2 woFcz9wBUiXTEJzr3p857p2lXmTg3UB0Qxy3SO1/2ByxQyftLeBSXmPOVISR4kAyho0B Z/5h83Fj7uIAkjNENmu1ZWINzqlQ4MjxykyKa6f0UGcAtotbaaH5QYgE/j6tqEV+CXbr /sC9+wrOZRa/o9BeAHjzDfrNV/ib05xgTDIMqHiaEVXh5Dhi6v5NaGSd/z6R/Ct5HrEB 6b/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=V+jNmWvzahT3NuL2zjSNRiKSBbuQIytQabp1xzzKtgo=; fh=g78TLxI1T+wFKAETjXXzHdA8/G9qVVj36bZ/kcTL53g=; b=vyCauS2neyRYBLDGHDWi8HjCCzuXUPwCVDJ6+eQTumjfKYVmLftFFK8INRqY6qEQoe thlWJRPYhIPrO91FfND4DpHy3mlFaj/R6+BkdMtS+cNGGzOeqvcNxa2snGdKmeyXIyha P9HCwvCnOdKzLODQJowQPOU8HvLP7sKwqayUimu+kpC5q8rtcY9/9g1q91dq1wDx42RU wB4cpSJo7K5yQNlpBqrm8PpS7WA3RjFs3VizcySXSsx2aI51s7vASkHjp+A0dD+bHi9j 5fqP0SZhnVHGALW5BBUPiWUvdWey8P4RDSbuLzahPCG5TXL2tQkIbA0mlFEUg8Rm3qkR JG0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PgEImyVj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101899-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101899-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x4-20020a05620a0ec400b0078822c48779si9960657qkm.451.2024.03.13.10.11.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:11:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101899-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PgEImyVj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101899-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101899-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4F6E21C21DFD for ; Wed, 13 Mar 2024 17:11:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7EFB780636; Wed, 13 Mar 2024 16:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PgEImyVj" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 808DB80607; Wed, 13 Mar 2024 16:40:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348035; cv=none; b=eSiAk2Kx/6CxWhaRIlwAoLGs28oTRNL3n2tNdwBi9Pev4MIFDgxgIfozfMipkF1r1oJ8ljszx09REME8PGVx4B/Ru3s74IaKFVa76x9narOSh0ayJLsN2RzCH2bQglFZLZL2isgOFqt8BZHl2ajuEYn7f5M8BZdePiU0VrZIxZ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348035; c=relaxed/simple; bh=JVPLM3Xa8ry312Rq6zPFIsn1EaGQK1w1EkpB+/6XKOk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K3hpxJmK283Sf7ybpuxZeEeYDcqRtnKR2XXXf/4b4JEW4AWMbkW+z0JXr+YuvcqWQooub2cwUGml5k6IXjUHnYPEpELJf646XwUwBJNeA9bouhygzYeiKopSwspR5H2iuvbyQvvKAYhQgnc8eYN8p50ymta18eSiHkLR+1ZKAXU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PgEImyVj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 782ACC433A6; Wed, 13 Mar 2024 16:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348035; bh=JVPLM3Xa8ry312Rq6zPFIsn1EaGQK1w1EkpB+/6XKOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PgEImyVjg3doCYGweEellpsRkTZhbR0lYZCV0UiV5nqVA4ruD6bGxTjMqvYZcgKkZ wwdJSCfKm49WVRrw7vU90dyBk3UWhdbXXlWjH6vRjwfNNbO+ja3ZgJo1F7CCE75QEo Sv7Lf2kTW/mEGVzuzuXzgEcld9+12WS8+KrwOkdVilx4b2/IAGA8OqM+5uDxoWKSfP fynx1iHjdPMYOYvFRgaqkMUAdUM75uIiPE6gU2EZbu7jK0WlvoU+tAF1QUdUzHrVN6 7ocHe7A0dRXRfLcn2fYXpViIWEoTt5YvmPlBrlD/KtkqLOtpzuCAABqOuIPuhifUJJ ve9WBj3eWDItg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nico Boehr , David Hildenbrand , Claudio Imbrenda , Janosch Frank , Sasha Levin Subject: [PATCH 6.1 31/71] KVM: s390: add stat counter for shadow gmap events Date: Wed, 13 Mar 2024 12:39:17 -0400 Message-ID: <20240313163957.615276-32-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313163957.615276-1-sashal@kernel.org> References: <20240313163957.615276-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.1.82-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-6.1.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 6.1.82-rc1 X-KernelTest-Deadline: 2024-03-15T16:39+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Nico Boehr [ Upstream commit c3235e2dd6956448a562d6b1112205eeebc8ab43 ] The shadow gmap tracks memory of nested guests (guest-3). In certain scenarios, the shadow gmap needs to be rebuilt, which is a costly operation since it involves a SIE exit into guest-1 for every entry in the respective shadow level. Add kvm stat counters when new shadow structures are created at various levels. Also add a counter gmap_shadow_create when a completely fresh shadow gmap is created as well as a counter gmap_shadow_reuse when an existing gmap is being reused. Note that when several levels are shadowed at once, counters on all affected levels will be increased. Also note that not all page table levels need to be present and a ASCE can directly point to e.g. a segment table. In this case, a new segment table will always be equivalent to a new shadow gmap and hence will be counted as gmap_shadow_create and not as gmap_shadow_segment. Signed-off-by: Nico Boehr Reviewed-by: David Hildenbrand Reviewed-by: Claudio Imbrenda Reviewed-by: Janosch Frank Signed-off-by: Janosch Frank Link: https://lore.kernel.org/r/20231009093304.2555344-2-nrb@linux.ibm.com Message-Id: <20231009093304.2555344-2-nrb@linux.ibm.com> Stable-dep-of: fe752331d4b3 ("KVM: s390: vsie: fix race during shadow creation") Signed-off-by: Sasha Levin --- arch/s390/include/asm/kvm_host.h | 7 +++++++ arch/s390/kvm/gaccess.c | 7 +++++++ arch/s390/kvm/kvm-s390.c | 9 ++++++++- arch/s390/kvm/vsie.c | 5 ++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h index b1e98a9ed152b..09abf000359f8 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h @@ -777,6 +777,13 @@ struct kvm_vm_stat { u64 inject_service_signal; u64 inject_virtio; u64 aen_forward; + u64 gmap_shadow_create; + u64 gmap_shadow_reuse; + u64 gmap_shadow_r1_entry; + u64 gmap_shadow_r2_entry; + u64 gmap_shadow_r3_entry; + u64 gmap_shadow_sg_entry; + u64 gmap_shadow_pg_entry; }; struct kvm_arch_memory_slot { diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c index 0243b6e38d364..3beceff5f1c09 100644 --- a/arch/s390/kvm/gaccess.c +++ b/arch/s390/kvm/gaccess.c @@ -1273,6 +1273,7 @@ static int kvm_s390_shadow_tables(struct gmap *sg, unsigned long saddr, unsigned long *pgt, int *dat_protection, int *fake) { + struct kvm *kvm; struct gmap *parent; union asce asce; union vaddress vaddr; @@ -1281,6 +1282,7 @@ static int kvm_s390_shadow_tables(struct gmap *sg, unsigned long saddr, *fake = 0; *dat_protection = 0; + kvm = sg->private; parent = sg->parent; vaddr.addr = saddr; asce.val = sg->orig_asce; @@ -1341,6 +1343,7 @@ static int kvm_s390_shadow_tables(struct gmap *sg, unsigned long saddr, rc = gmap_shadow_r2t(sg, saddr, rfte.val, *fake); if (rc) return rc; + kvm->stat.gmap_shadow_r1_entry++; } fallthrough; case ASCE_TYPE_REGION2: { @@ -1369,6 +1372,7 @@ static int kvm_s390_shadow_tables(struct gmap *sg, unsigned long saddr, rc = gmap_shadow_r3t(sg, saddr, rste.val, *fake); if (rc) return rc; + kvm->stat.gmap_shadow_r2_entry++; } fallthrough; case ASCE_TYPE_REGION3: { @@ -1406,6 +1410,7 @@ static int kvm_s390_shadow_tables(struct gmap *sg, unsigned long saddr, rc = gmap_shadow_sgt(sg, saddr, rtte.val, *fake); if (rc) return rc; + kvm->stat.gmap_shadow_r3_entry++; } fallthrough; case ASCE_TYPE_SEGMENT: { @@ -1439,6 +1444,7 @@ static int kvm_s390_shadow_tables(struct gmap *sg, unsigned long saddr, rc = gmap_shadow_pgt(sg, saddr, ste.val, *fake); if (rc) return rc; + kvm->stat.gmap_shadow_sg_entry++; } } /* Return the parent address of the page table */ @@ -1509,6 +1515,7 @@ int kvm_s390_shadow_fault(struct kvm_vcpu *vcpu, struct gmap *sg, pte.p |= dat_protection; if (!rc) rc = gmap_shadow_page(sg, saddr, __pte(pte.val)); + vcpu->kvm->stat.gmap_shadow_pg_entry++; ipte_unlock(vcpu->kvm); mmap_read_unlock(sg->mm); return rc; diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index f604946ab2c85..348d49268a7ec 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -66,7 +66,14 @@ const struct _kvm_stats_desc kvm_vm_stats_desc[] = { STATS_DESC_COUNTER(VM, inject_pfault_done), STATS_DESC_COUNTER(VM, inject_service_signal), STATS_DESC_COUNTER(VM, inject_virtio), - STATS_DESC_COUNTER(VM, aen_forward) + STATS_DESC_COUNTER(VM, aen_forward), + STATS_DESC_COUNTER(VM, gmap_shadow_reuse), + STATS_DESC_COUNTER(VM, gmap_shadow_create), + STATS_DESC_COUNTER(VM, gmap_shadow_r1_entry), + STATS_DESC_COUNTER(VM, gmap_shadow_r2_entry), + STATS_DESC_COUNTER(VM, gmap_shadow_r3_entry), + STATS_DESC_COUNTER(VM, gmap_shadow_sg_entry), + STATS_DESC_COUNTER(VM, gmap_shadow_pg_entry), }; const struct kvm_stats_header kvm_vm_stats_header = { diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c index 740f8b56e63f9..b2dbf08a961e5 100644 --- a/arch/s390/kvm/vsie.c +++ b/arch/s390/kvm/vsie.c @@ -1206,8 +1206,10 @@ static int acquire_gmap_shadow(struct kvm_vcpu *vcpu, * we're holding has been unshadowed. If the gmap is still valid, * we can safely reuse it. */ - if (vsie_page->gmap && gmap_shadow_valid(vsie_page->gmap, asce, edat)) + if (vsie_page->gmap && gmap_shadow_valid(vsie_page->gmap, asce, edat)) { + vcpu->kvm->stat.gmap_shadow_reuse++; return 0; + } /* release the old shadow - if any, and mark the prefix as unmapped */ release_gmap_shadow(vsie_page); @@ -1215,6 +1217,7 @@ static int acquire_gmap_shadow(struct kvm_vcpu *vcpu, if (IS_ERR(gmap)) return PTR_ERR(gmap); gmap->private = vcpu->kvm; + vcpu->kvm->stat.gmap_shadow_create++; WRITE_ONCE(vsie_page->gmap, gmap); return 0; } -- 2.43.0