From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Nico Boehr <nrb@linux.ibm.com>,
David Hildenbrand <david@redhat.com>,
Claudio Imbrenda <imbrenda@linux.ibm.com>,
Janosch Frank <frankja@linux.ibm.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.1 31/71] KVM: s390: add stat counter for shadow gmap events
Date: Wed, 13 Mar 2024 12:39:17 -0400 [thread overview]
Message-ID: <20240313163957.615276-32-sashal@kernel.org> (raw)
In-Reply-To: <20240313163957.615276-1-sashal@kernel.org>
From: Nico Boehr <nrb@linux.ibm.com>
[ 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 <nrb@linux.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
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 <sashal@kernel.org>
---
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
next prev parent reply other threads:[~2024-03-13 16:40 UTC|newest]
Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-13 16:38 [PATCH 6.1 00/71] 6.1.82-rc1 review Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 01/71] ceph: switch to corrected encoding of max_xattr_size in mdsmap Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 02/71] net: lan78xx: fix runtime PM count underflow on link stop Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 03/71] ixgbe: {dis, en}able irqs in ixgbe_txrx_ring_{dis, en}able Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 04/71] i40e: disable NAPI right after disabling irqs when handling xsk_pool Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 05/71] ice: reorder disabling IRQ and NAPI in ice_qp_dis Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 06/71] tracing/net_sched: Fix tracepoints that save qdisc_dev() as a string Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 07/71] geneve: make sure to pull inner header in geneve_rx() Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 08/71] net: sparx5: Fix use after free inside sparx5_del_mact_entry Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 09/71] ice: virtchnl: stop pretending to support RSS over AQ or registers Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 10/71] net: ice: Fix potential NULL pointer dereference in ice_bridge_setlink() Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 11/71] igc: avoid returning frame twice in XDP_REDIRECT Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 12/71] net/ipv6: avoid possible UAF in ip6_route_mpath_notify() Sasha Levin
2024-03-13 16:38 ` [PATCH 6.1 13/71] cpumap: Zero-initialise xdp_rxq_info struct before running XDP program Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 14/71] net: dsa: microchip: fix register write order in ksz8_ind_write8() Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 15/71] net/rds: fix WARNING in rds_conn_connect_if_down Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 16/71] netfilter: nft_ct: fix l3num expectations with inet pseudo family Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 17/71] netfilter: nf_conntrack_h323: Add protection for bmp length out of range Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 18/71] erofs: apply proper VMA alignment for memory mapped files on THP Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 19/71] netrom: Fix a data-race around sysctl_netrom_default_path_quality Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 20/71] netrom: Fix a data-race around sysctl_netrom_obsolescence_count_initialiser Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 21/71] netrom: Fix data-races around sysctl_netrom_network_ttl_initialiser Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 22/71] netrom: Fix a data-race around sysctl_netrom_transport_timeout Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 23/71] netrom: Fix a data-race around sysctl_netrom_transport_maximum_tries Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 24/71] netrom: Fix a data-race around sysctl_netrom_transport_acknowledge_delay Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 25/71] netrom: Fix a data-race around sysctl_netrom_transport_busy_delay Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 26/71] netrom: Fix a data-race around sysctl_netrom_transport_requested_window_size Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 27/71] netrom: Fix a data-race around sysctl_netrom_transport_no_activity_timeout Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 28/71] netrom: Fix a data-race around sysctl_netrom_routing_control Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 29/71] netrom: Fix a data-race around sysctl_netrom_link_fails_count Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 30/71] netrom: Fix data-races around sysctl_net_busy_read Sasha Levin
2024-03-13 16:39 ` Sasha Levin [this message]
2024-03-13 16:39 ` [PATCH 6.1 32/71] KVM: s390: vsie: fix race during shadow creation Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 33/71] ASoC: codecs: wcd938x: fix headphones volume controls Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 34/71] drm/amd/display: Fix uninitialized variable usage in core_link_ 'read_dpcd() & write_dpcd()' functions Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 35/71] nfp: flower: add goto_chain_index for ct entry Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 36/71] nfp: flower: add hardware offload check for post " Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 37/71] readahead: avoid multiple marked readahead pages Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 38/71] selftests/mm: switch to bash from sh Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 39/71] selftests: mm: fix map_hugetlb failure on 64K page size systems Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 40/71] xhci: process isoc TD properly when there was a transaction error mid TD Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 41/71] xhci: handle isoc Babble and Buffer Overrun events properly Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 42/71] drm/amdgpu: Reset IH OVERFLOW_CLEAR bit Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 43/71] x86/mmio: Disable KVM mitigation when X86_FEATURE_CLEAR_CPU_BUF is set Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 44/71] Documentation/hw-vuln: Add documentation for RFDS Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 45/71] x86/rfds: Mitigate Register File Data Sampling (RFDS) Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 46/71] KVM/x86: Export RFDS_NO and RFDS_CLEAR to guests Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 47/71] selftests: mptcp: decrease BW in simult flows Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 48/71] blk-iocost: disable writeback throttling Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 49/71] elevator: remove redundant code in elv_unregister_queue() Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 50/71] blk-wbt: remove unnecessary check in wbt_enable_default() Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 51/71] elevator: add new field flags in struct elevator_queue Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 52/71] blk-wbt: don't enable throttling if default elevator is bfq Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 53/71] blk-wbt: pass a gendisk to wbt_{enable,disable}_default Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 54/71] blk-wbt: pass a gendisk to wbt_init Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 55/71] blk-rq-qos: move rq_qos_add and rq_qos_del out of line Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 56/71] blk-rq-qos: make rq_qos_add and rq_qos_del more useful Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 57/71] blk-rq-qos: constify rq_qos_ops Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 58/71] blk-rq-qos: store a gendisk instead of request_queue in struct rq_qos Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 59/71] blk-wbt: Fix detection of dirty-throttled tasks Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 60/71] drm/amd/display: Wrong colorimetry workaround Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 61/71] drm/amd/display: Fix MST Null Ptr for RV Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 62/71] getrusage: add the "signal_struct *sig" local variable Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 63/71] getrusage: move thread_group_cputime_adjusted() outside of lock_task_sighand() Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 64/71] getrusage: use __for_each_thread() Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 65/71] getrusage: use sig->stats_lock rather than lock_task_sighand() Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 66/71] fs/proc: do_task_stat: use __for_each_thread() Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 67/71] fs/proc: do_task_stat: use sig->stats_lock to gather the threads/children stats Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 68/71] exit: wait_task_zombie: kill the no longer necessary spin_lock_irq(siglock) Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 69/71] blk-wbt: fix that wbt can't be disabled by default Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 70/71] blk-iocost: Pass gendisk to ioc_refresh_params Sasha Levin
2024-03-13 16:39 ` [PATCH 6.1 71/71] Linux 6.1.82-rc1 Sasha Levin
2024-03-13 20:04 ` [PATCH 6.1 00/71] 6.1.82-rc1 review Pavel Machek
2024-03-13 20:13 ` Mateusz Jończyk
2024-03-13 21:27 ` Mateusz Jończyk
2024-03-14 21:12 ` Mateusz Jończyk
2024-03-14 22:04 ` Jens Axboe
2024-03-14 22:35 ` Sasha Levin
2024-03-14 22:40 ` Jens Axboe
2024-03-15 12:14 ` Sasha Levin
2024-03-15 14:42 ` Sasha Levin
2024-03-15 14:49 ` Jens Axboe
2024-03-15 19:31 ` Ron Economos
2024-03-14 14:43 ` Naresh Kamboju
2024-03-14 20:45 ` Florian Fainelli
2024-03-15 10:37 ` Shreeya Patel
2024-03-15 15:34 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240313163957.615276-32-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=david@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nrb@linux.ibm.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox