From patchwork Fri Dec 20 01:38:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13915994 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2525A125B9 for ; Fri, 20 Dec 2024 01:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658752; cv=none; b=QaWFOF4Yw8pLU3w1bqvts32ZX/KkvepnaK45M4yByzw6gEHIQyB5bW+eZLU7oDYoev8ai2D2B6pWANPW8Wd0wLbc6eh+sLiLqUIPXiYt3VFYvmUtcQmwsthhlPp2wJuhiEvA9x9NoLtQrIOyBSc2mYFacjoRBmpuM+1klHO+D2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658752; c=relaxed/simple; bh=vUAkr3IX2LE4GH/mlPkbcxzVyqeoUOtvVrlhcSINMSY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dQ3osmzosFrz4jDvaFDVuYQnVL9FXj+WBb9CNvmbB/Z6CgMqJ+V2Vq3LVgqJ+/qSIFEZM7IzsYPuk1qRtFLT8SYnZt78EqLecwf9nmB1F5Q2jN4F19CWQW90JQsp8D+ZNNJxJ56zrJP+xvO+0AE/01aRA45PRDW/5FZjMb3AKuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Cg9ARUip; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Cg9ARUip" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7eaac1e95ffso910717a12.2 for ; Thu, 19 Dec 2024 17:39:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734658750; x=1735263550; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=OYKvlAfMuP2ktBfEDhDytfcvSdR/S4IqDZKQdTsYjuw=; b=Cg9ARUipzj+8HUO5coEyze9E5jPY0yiPMCRfSBVxS71MrLP8NEMYVYkiIy+Ufm1/hM TIzx3/DFVt+IFZ446W0z9lnHIGWpDqjmtY5TuenifpJOAMQoqztmfk61MV6wBSuXYWsN Ru56Gk6HOo+FHKP8I4qiOx8Mvx0PovvW/GKRAS/JYvgEMV3g+koLHzLCCgbLHpNQaFab MP+JqOBEchaCE9KBn/ddVBGK5z7iscaAmbavLRrOu+RPSJ4mg48m/OVKMK2scDlQT+gy CLsHGOMXBy2Rcb5MUJyD4QJfxRd3ZPiWOdFdrJEzrGYduFAJJdkWCHgkGeYCgOkQfOi5 O+uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734658750; x=1735263550; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OYKvlAfMuP2ktBfEDhDytfcvSdR/S4IqDZKQdTsYjuw=; b=VUQGFB6iNyuG+vJCQdgIvJ4xNQ1etU4Z4a28RAvcC9Mbqx7x03XMSlnlKwDzMU7ZNB aia2rrl9BS2hdhS4QkFdLyRZK8EUEBVyLFy2RSVeJpRys5MP1jTsl1KOWLcVAmAjNkk3 1li9muXt3tXNZvh7kkteZV1yaGbh/W3H1jp3u5xCG2ErVC90HuIqaQtYX2Q3ZGX1BIis WyE061sCay8Z7xT3n9x/Nxd9BBsNTwsMyv98V3KIr/igyYaROJrADd/9t3juu3XekgZh vtoXCIZGRwCFV5h3BEesmHZDYz05d9hl0UG4LKBx/iHS7q+Z+C0sY351bltiVWMpUZ9H LOBw== X-Forwarded-Encrypted: i=1; AJvYcCUw/mQ68bauPWTPAPP+MkdL13QH1ghBNqyqm4FWbRKXUBrOcPCDyu+Vic1vhQCyxrzQTtw=@vger.kernel.org X-Gm-Message-State: AOJu0Yw518zZs2jXsf8chFaMsED6G5XtN+jfbLDTY0+evDuwpe33/RAW nWyrkZb7TNBhYXok7FDEH7x5jBzkmBuBfpHLqZvXDfbRrRnyhuREM216N5p2lhYECb/vMpnAlJe RUQ== X-Google-Smtp-Source: AGHT+IGntiLPaNNzeAfuu6/TEmKwPAvoTiJFX2SO6583j9CN5As5xvpXTmf/fSQgTUKQrOus8R97PMQPQe4= X-Received: from pfbch14.prod.google.com ([2002:a05:6a00:288e:b0:727:3a40:52cd]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3a85:b0:1e1:c8f5:19ee with SMTP id adf61e73a8af0-1e5e04945e8mr2117339637.25.1734658750347; Thu, 19 Dec 2024 17:39:10 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 19 Dec 2024 17:38:59 -0800 In-Reply-To: <20241220013906.3518334-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220013906.3518334-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220013906.3518334-2-seanjc@google.com> Subject: [PATCH 1/8] KVM: selftests: Fix mostly theoretical leak of VM's binary stats FD From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org When allocating and freeing a VM's cached binary stats info, check for a NULL descriptor, not a '0' file descriptor, as '0' is a legal FD. E.g. in the unlikely scenario the kernel installs the stats FD at entry '0', selftests would reallocate on the next __vm_get_stat() and/or fail to free the stats in kvm_vm_free(). Fixes: 83f6e109f562 ("KVM: selftests: Cache binary stats metadata for duration of test") Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/kvm_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 33fefeb3ca44..91d295ef5d02 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -749,7 +749,7 @@ void kvm_vm_free(struct kvm_vm *vmp) return; /* Free cached stats metadata and close FD */ - if (vmp->stats_fd) { + if (vmp->stats_desc) { free(vmp->stats_desc); close(vmp->stats_fd); } @@ -2218,7 +2218,7 @@ void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, size_t size_desc; int i; - if (!vm->stats_fd) { + if (!vm->stats_desc) { vm->stats_fd = vm_get_stats_fd(vm); read_stats_header(vm->stats_fd, &vm->stats_header); vm->stats_desc = read_stats_descriptors(vm->stats_fd, From patchwork Fri Dec 20 01:39:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13915995 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83DAB1CD1F for ; Fri, 20 Dec 2024 01:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658754; cv=none; b=IVt4oUHk0EZJTx7kyWl9B0kRBKo75Q36UWdwYszkgLJ+BSmKqpA0sUkXkBmiKNH/FI93Ro+9DBVaLGIbqf54mCOnap320PFOnRp7M7ctdihXHF/x9uDTuCXVPlH8NZek40B5hS7or3sLJQCUOUgVkfytytsH4KCGl4Nt8pISIeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658754; c=relaxed/simple; bh=x+G/SKe65zYqmcjfUDWiwO99pE05MNdhz6X9PomzPYg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jPynmLQSpecoNVLLj8MSQZWXB8OXuZrY+Lj2wJIGhm4hEMDD+SSodGa0fxph4z3vg0U0+g9+jjJdWnK68eesrVcBGwbQ+NNOcdFQ5F/g5LLsXYLHBb4ibjG4ZSNz7y4JIzAoZXPI2Bt+cv0KNIps4ds4+HqWNgrt/oGC3Hs0qJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Gy1sOYJ/; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Gy1sOYJ/" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-21655569152so12654775ad.2 for ; Thu, 19 Dec 2024 17:39:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734658752; x=1735263552; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=VJst1sRt7o765YHKTsyCLHu+qBA9pewJkWtnndgMLN0=; b=Gy1sOYJ/9dNZiwp6AIpFu5aEI/7NnphKHg0vq0utlmoJw0iAG+yjGkYoeZ7HfFfSAA ZZBox9PpDLPhsQPOBoSiD7+ujZaWvJOK4MC8E9+Re8czgvInh4QrmQW7e/034Q1MrPna 0HSVUhFnWoWERjNYXIzAJS2Ouv0oDkpqTkZNzYJyUFpwjQWbVFSyX+lBgThwAi/zYUt9 jCjuSyJWzyQCf49Jw7tLuy8DOvsru5t7LdI02U6mwHDaXnIV1NesprwWMXIW0ccKu6S1 0cdOmOHqydF8XjdQJWsfxr3IgqB0BlfmFXW4JvYTdAvF5AfixJ+IVJNZWgXZMqF04KtP n3jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734658752; x=1735263552; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VJst1sRt7o765YHKTsyCLHu+qBA9pewJkWtnndgMLN0=; b=xL+K+Lto0JYrQBtAjC6QuP/aCvXsbLwAOQfutvQUDoHy6fkIOV0pmrauTvoFywZpW9 398A5T9xVRTHyFHUG8JzUIX38/qXYNy73S3vzY4W9Tna9aPg4lG0Xf+u5Km6QB66rorW vqwCP4mTaUS5aOGtwhBWj3FaPt3aC9HgJuzUArLkoKTycxIBD8S1l3GMl+UjMCpfK03Y xffWa41BKe4sTP5Q7SrDiv6/a6lhK9NT1rah98IqGW9V2wlcBaB3fc8E0opPsAxghLqz yxWno8k9xTBcXn9mppBz4H/ZFa8kQwUVSaWR10OZytltmAgV019lrr5Fw73FrGm4fGHD tLvQ== X-Forwarded-Encrypted: i=1; AJvYcCXaL1luosVv6/THiBf/i/J38wIygrLKQi4RrRa9Qknk7auNsMkq73ZU3V/1tQYFUhQemW0=@vger.kernel.org X-Gm-Message-State: AOJu0YxrSLGerdeRpjSjSZGvFzIdhFnF4PT8IpYWelV+TXAWI2rmxy4k 3cQ0QIquZVezSNFt7XP/2q11o04TSifNfG+KkZID5syORybdBO5llZiARDrBBWcFsHy8Jw/uFF2 phA== X-Google-Smtp-Source: AGHT+IGsWQbkvzY4Nq8NW+TxgBWjNbfzrSia5xRKbrBdsJJ8VjsmNkZOW2nxKqNkxRXVufnLriMmB7/RPeQ= X-Received: from plbkw12.prod.google.com ([2002:a17:902:f90c:b0:216:3e9d:6bc4]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:c406:b0:215:854c:a71a with SMTP id d9443c01a7336-219e6ebb68dmr11030635ad.34.1734658751894; Thu, 19 Dec 2024 17:39:11 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 19 Dec 2024 17:39:00 -0800 In-Reply-To: <20241220013906.3518334-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220013906.3518334-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220013906.3518334-3-seanjc@google.com> Subject: [PATCH 2/8] KVM: selftests: Close VM's binary stats FD when releasing VM From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Close/free a VM's binary stats cache when the VM is released, not when the VM is fully freed. When a VM is re-created, e.g. for state save/restore tests, the stats FD and descriptor points at the old, defunct VM. The FD is still valid, in that the underlying stats file won't be freed until the FD is closed, but reading stats will always pull information from the old VM. Note, this is a benign bug in the current code base as none of the tests that recreate VMs use binary stats. Fixes: 83f6e109f562 ("KVM: selftests: Cache binary stats metadata for duration of test") Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/kvm_util.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 91d295ef5d02..9138801ecb60 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -709,6 +709,15 @@ void kvm_vm_release(struct kvm_vm *vmp) ret = close(vmp->kvm_fd); TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("close()", ret)); + + /* Free cached stats metadata and close FD */ + if (vmp->stats_desc) { + free(vmp->stats_desc); + vmp->stats_desc = NULL; + + ret = close(vmp->stats_fd); + TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("close()", ret)); + } } static void __vm_mem_region_delete(struct kvm_vm *vm, @@ -748,12 +757,6 @@ void kvm_vm_free(struct kvm_vm *vmp) if (vmp == NULL) return; - /* Free cached stats metadata and close FD */ - if (vmp->stats_desc) { - free(vmp->stats_desc); - close(vmp->stats_fd); - } - /* Free userspace_mem_regions. */ hash_for_each_safe(vmp->regions.slot_hash, ctr, node, region, slot_node) __vm_mem_region_delete(vmp, region); From patchwork Fri Dec 20 01:39:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13915996 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F60039FF3 for ; Fri, 20 Dec 2024 01:39:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658755; cv=none; b=HL/QKRgs6JQSNFHluyJDiey0C05hAlRDHz08XdoV0BqB7PZyD7CMrSIYSdMZbXhZ2IyYVC7wECTZ3XMOrYeXBUq+J47ZpJ1pfUrP3gwsc1nXfTzBRv/6cD8sLEwSPSvTSQerWRf7wSEetpgR+20ukWaH1ZtKcj2D1vNDSfK0HL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658755; c=relaxed/simple; bh=ngrqdUdgvu+/gBHMswn/cnVSO5lL2tVEodHB9BBNKEM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Qggdfu4g5G4v7bjRfICz2paLpwosNsLbPhwtKYoWRyDPy+L6tCpJ3dwkKf1GRcbXVRAMfu5leeYe2dt+6IpsTn1Yb/ckRRmSfs3nfTj6kfZYgxx3aNg6FBPO7IdYCKnqiXFFyBsu8zAhWqZlOly3tgdyESxyEMnBeIDKgxUDdLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=J3fCUG0+; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="J3fCUG0+" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-725cf25d47bso1339404b3a.2 for ; Thu, 19 Dec 2024 17:39:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734658754; x=1735263554; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=C0bgCVLlKE2bsIas/97mE7OWeLqD3b90q0/zRCnz1gQ=; b=J3fCUG0+qjA9k190tJaAswaik3zjNOL4+2Sw7CgMQ9H061WzAk0dozVjK7kw2GWCDI UuO91ZW+4mu6WqaiSHbV88h/suLD3ewC05NMdSMhoxma1MMc/FDcEtKBswMC7JiS6o+5 E9ODXmmjk41SSRbO2Kejy475eirN2GcjPwLS6eTYphaQyjmfKDNf0N4J/gXgUeEuZ7oL YOwqDValvINzFs7E9F9XUG97JBZyW1WNVu1q9OjIlkTvqN0BZiZ2POWqEOhmW2JPGU+6 eepQvVpdIEz+VL+pcIzUVYdZlczml3pdY9Upoe2Qo/xWCqQpyMO/sUFrNZU90sLGrV0S gv+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734658754; x=1735263554; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=C0bgCVLlKE2bsIas/97mE7OWeLqD3b90q0/zRCnz1gQ=; b=Hb4JTmqR7TLL7AjI75qW2NVFmRIjVWIVOU7JPBL0wqyofy6kJwQdXJUefqp3BkqfBv c43hbsVuO28cpb5ZpuM+9aI4ofSKTHAj3N8HpRyhrytrqMEzuDzoVvxvdf8UERhlrroq /Wadpfh2TvSsjNNoPfphR3brM/96RM57YoQ8ZDeXX+JS1MYbEaw5A7Sl9Q5CfgdgRzpd B5jq6tOLhKIsvCS+SISBAPF3N9eqaxAKoyG2bx4pFJU+XI+iiSL3JcD2WBNflV5B61PG AoHM15YUb2HP840QniAlD1qPhrpMlK1CKxzeK0nUUyURfEMLpr7ZJ7nHEsq2/mmMwsgz 0XGA== X-Forwarded-Encrypted: i=1; AJvYcCXxlXm8nv471+8A+m2M+bEFv9k7dUf9aAJL0qvMj9aDYyt+qKtHCTpM/7EwSypgg9ZaTrk=@vger.kernel.org X-Gm-Message-State: AOJu0YzX4c9LxYNhWuhUPy+4ULhNwpFOS7tZ27BapQqpUdh0isyDYeyh VqGwaQyo+WP7qo+VZccErxdAUqeVu2i9lhdqIxGuGebturfW/JLJLGCEQqku9gKrH5LLk3BTS4k 7Hw== X-Google-Smtp-Source: AGHT+IEnCf3mHfBvLfwshZ15Q9EpX1HZcjdF08kZ2lrJwSlTx89Hx0AQSr2Fy6V/QWuDYbh+JhZtgEK5cgY= X-Received: from pfbbd38.prod.google.com ([2002:a05:6a00:27a6:b0:725:ccfc:fd85]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1942:b0:725:cfa3:bc6b with SMTP id d2e1a72fcca58-72abde404b0mr1283201b3a.3.1734658753719; Thu, 19 Dec 2024 17:39:13 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 19 Dec 2024 17:39:01 -0800 In-Reply-To: <20241220013906.3518334-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220013906.3518334-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220013906.3518334-4-seanjc@google.com> Subject: [PATCH 3/8] KVM: selftests: Assert that __vm_get_stat() actually finds a stat From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Fail the test if it attempts to read a stat that doesn't exist, e.g. due to a typo, or because the test tried to get a stat for the wrong scope. As is, there's no indiciation of failure and @data is left untouched, e.g. holds '0' or random stack data in most cases. Fixes: 8448ec5993be ("KVM: selftests: Add NX huge pages test") Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/kvm_util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 9138801ecb60..21b5a6261106 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -2238,9 +2238,10 @@ void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, read_stat_data(vm->stats_fd, &vm->stats_header, desc, data, max_elements); - - break; + return; } + + TEST_FAIL("Unabled to find stat '%s'", stat_name); } __weak void kvm_arch_vm_post_create(struct kvm_vm *vm) From patchwork Fri Dec 20 01:39:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13915997 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A0797346F for ; Fri, 20 Dec 2024 01:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658757; cv=none; b=NQBPNcNHgdWENvLzEKkT3cC+A4CN1HTa0nvKuAU1IWcV0yghb2/rMK5kGwaFtyTkdBnNOudHAeImj6ynptOUja2WTt6Z5xNcvBLe1i8QQnGuMcRlzhoX+ebdfywofkgQAjvPltKZ4szKczBkjSj+uxhqwfXGspyn8orROj1d4GE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658757; c=relaxed/simple; bh=cdYoQmC1gHgaq22PDsiZGCRoGD7RLzRK9PeAtDWgW1s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Jb4kEYNeRV8mGXmz0CNoEF0LcIyiIRDMc2C74PmaHkVK5H2f7uPj/NlB6JRV0dmVY4iRDHbcdLC4cEGtxI4jJV3o/5bOvBNZi/DrBO6lEOlPJWZe4UfeMlLU1erGT7HWKrNC7bsqaTAUEV19gfYnvKZyPeRVumATkcC/xRK4OBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Xrb47Avc; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Xrb47Avc" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7f712829f05so883691a12.0 for ; Thu, 19 Dec 2024 17:39:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734658755; x=1735263555; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=FOB7JN0OSt2j8FiVppNC5qzgljC2YrzarOO3DmltLC8=; b=Xrb47AvcWGXho1oJMLU7+rUDiTU4pz0Zlc4qK/+wdhWg3mQoU+RUexLsNYkOdS/+Jr 92anryNYkKe199xlAT8gOgVkdSfZ3LxW5cAijWTIVD+TfLNUjKwFIW4hFieMphNHd1Pg J3iSGT4t3dQcMO+PNl6P/JnYO0YKaUpC6CAn7tcRF/OdrLWEk1QItf1P3qFtXFsf4bri VM0lcYrBzXaLgIrEYu4ce4H2uKX4XLDM9vXTFMXsY3hmR7T+Wo7VbTNLlNO2rrZNHvtI eyPMCRoeS/Mng/KSq3mAeZE77+ROaV7jb+2XoKQAXMXAawC2Oa+U8YlREnxynhq/6x61 HkVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734658755; x=1735263555; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FOB7JN0OSt2j8FiVppNC5qzgljC2YrzarOO3DmltLC8=; b=U5yZqnFV0t0RRIe/jvxeY9TL7j8WQoepqx3A+jgEKsPmTHOEIgCdsSSP2kVrjOR8ap GXAGU32nmLIkoAQbLJ36npFXLq5a+gh/7t/0VvxovMBU4FazBgEuoasSqZO0OjtRjzmQ ERN+gbkMS7uwhoTUfvsDQz2spTub8LQE4/fmM0l2/bGuvRTRE8xj44OUCciGWvC5ZBBD FmhOq3q/UZhpfDS5SfehgEMh5wykZi1iePVZAtUrHDbJa+XMNihdhLa5p/oIe0P3YS/p wzOCN28oFO5Q4VX4j4E3ldRYq5wygWO2ODZyI/qHQ4Ub9mui34fTLKh8Cfky0P5tKbKq LUTw== X-Forwarded-Encrypted: i=1; AJvYcCXOdSPHCab6wuIVnWDSTq9ZBmvlq+PQVzJrTPhRy6ULR2zo8DZK0YcXq9LYi8p4n7WvrGQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzHY7CnDcuT8h1K8LpoAEuIunIfZfv+ak5nxmZGUdWBzPWrknCh 0IRAla8im3PG/ixQeLJNqqXlAJi8TDsTpqt0Fh2idE/6K4H1hLuZ15MHTtc1/6bTgmkOEDuuM/a 4ig== X-Google-Smtp-Source: AGHT+IGgztxRUxTUpaMUvL86uRz7hYZyu/zAmCoVzo4yvg4Q5SlFHbLBFYN3ktm59BGI0bTCiW14R+y2ITQ= X-Received: from pfbkt9.prod.google.com ([2002:a05:6a00:4ba9:b0:72a:bc54:8507]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:33a6:b0:1e5:c43f:f36d with SMTP id adf61e73a8af0-1e5e046189cmr1878060637.18.1734658755535; Thu, 19 Dec 2024 17:39:15 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 19 Dec 2024 17:39:02 -0800 In-Reply-To: <20241220013906.3518334-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220013906.3518334-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220013906.3518334-5-seanjc@google.com> Subject: [PATCH 4/8] KVM: selftests: Macrofy vm_get_stat() to auto-generate stat name string From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Turn vm_get_stat() into a macro that generates a string for the stat name, as opposed to taking a string. This will allow hardening stat usage in the future to generate errors on unknown stats at compile time. No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/kvm_util.h | 14 +++++++------- .../kvm/x86/dirty_log_page_splitting_test.c | 6 +++--- .../testing/selftests/kvm/x86/nx_huge_pages_test.c | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 4c4e5a847f67..044c2231431e 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -534,13 +534,13 @@ void read_stat_data(int stats_fd, struct kvm_stats_header *header, void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, size_t max_elements); -static inline uint64_t vm_get_stat(struct kvm_vm *vm, const char *stat_name) -{ - uint64_t data; - - __vm_get_stat(vm, stat_name, &data, 1); - return data; -} +#define vm_get_stat(vm, stat) \ +({ \ + uint64_t data; \ + \ + __vm_get_stat(vm, #stat, &data, 1); \ + data; \ +}) void vm_create_irqchip(struct kvm_vm *vm); diff --git a/tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c b/tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c index 2929c067c207..b0d2b04a7ff2 100644 --- a/tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c +++ b/tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c @@ -41,9 +41,9 @@ struct kvm_page_stats { static void get_page_stats(struct kvm_vm *vm, struct kvm_page_stats *stats, const char *stage) { - stats->pages_4k = vm_get_stat(vm, "pages_4k"); - stats->pages_2m = vm_get_stat(vm, "pages_2m"); - stats->pages_1g = vm_get_stat(vm, "pages_1g"); + stats->pages_4k = vm_get_stat(vm, pages_4k); + stats->pages_2m = vm_get_stat(vm, pages_2m); + stats->pages_1g = vm_get_stat(vm, pages_1g); stats->hugepages = stats->pages_2m + stats->pages_1g; pr_debug("\nPage stats after %s: 4K: %ld 2M: %ld 1G: %ld huge: %ld\n", diff --git a/tools/testing/selftests/kvm/x86/nx_huge_pages_test.c b/tools/testing/selftests/kvm/x86/nx_huge_pages_test.c index e7efb2b35f8b..c0d84827f736 100644 --- a/tools/testing/selftests/kvm/x86/nx_huge_pages_test.c +++ b/tools/testing/selftests/kvm/x86/nx_huge_pages_test.c @@ -73,7 +73,7 @@ static void check_2m_page_count(struct kvm_vm *vm, int expected_pages_2m) { int actual_pages_2m; - actual_pages_2m = vm_get_stat(vm, "pages_2m"); + actual_pages_2m = vm_get_stat(vm, pages_2m); TEST_ASSERT(actual_pages_2m == expected_pages_2m, "Unexpected 2m page count. Expected %d, got %d", @@ -84,7 +84,7 @@ static void check_split_count(struct kvm_vm *vm, int expected_splits) { int actual_splits; - actual_splits = vm_get_stat(vm, "nx_lpage_splits"); + actual_splits = vm_get_stat(vm, nx_lpage_splits); TEST_ASSERT(actual_splits == expected_splits, "Unexpected NX huge page split count. Expected %d, got %d", From patchwork Fri Dec 20 01:39:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13915998 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A6FD157A48 for ; Fri, 20 Dec 2024 01:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658760; cv=none; b=WjDZLiSkiKCCv0az2xMVGO7Gd4RdMR/O+6V2Fajbh+ugkPB+cdmJ3+7z3Yy6BqDozqGFIh+mioKIaQSfiG2XtY/hmtHBVQZ1h/a6w2keeSzjucO6nx8FBm/50M/uafpW5BE8K8EEsJwLt7qTnVNgVesLfoOKurHU44Xg4zbQ8Mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658760; c=relaxed/simple; bh=eeF/zKkticJHl5FU2ydo7jdEXM5cm9h9vTJoDSn8JMo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=On9vv87OGJdmClewz0uJ17HlchyjVXU4zla/VTnRcFYYv4WSvlyj7SuvNVxM6fCwafJT5qIwBDrgN0ocW8+wm5vcY5RpryxmtRoFQ8w3jnVEBSHex3nLGGUg50BBgQUjtrcqLUcBIT2H/dGWOy7F6G9Rdl/ZZvd77JJmPLFRO8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Rv9gcxLG; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Rv9gcxLG" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-72907f58023so1663559b3a.3 for ; Thu, 19 Dec 2024 17:39:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734658757; x=1735263557; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=lQGXs4fRzhUjC9h6471rkcBzWgIFKg5z0MpBCPWHmMU=; b=Rv9gcxLGjoh1H6qINvmeWbMrOsPPYUnz9QHnoTc8YJBDEHXZ8yw3INwCMWG5gPMKLF qH4/ClaEAGx7fMkxmQOZdkUezeVW1x+lpCVEutgt5zb3yzJWMsi5cIDXK0MuefwLEhNV O7rldiQIcB+NZDKgW1sGjfy9FWaZPMjkKy1zesMLYL6kfJs1atpoS+VdTLEIVk6ZgMbO GIDRYoC9mAZbTpyoI4+Rs+9gnPPGwSS/CefwJD3hp0jTKmGGbqmO278l9mv6dWWN3Ad3 EGSWxTSydM3abhVXoK1tESznXf2b4iinwqMhdfNVPW7GUiGATAAKvcOmWofbdHu4yKKf osKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734658757; x=1735263557; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lQGXs4fRzhUjC9h6471rkcBzWgIFKg5z0MpBCPWHmMU=; b=bBGCOv06kAGc7UcTmw0avdTM9c9jxBzEulfTC0pn1aEZfdd/0aCjeImUN45bU8xMu8 78llMVWOipZR0pjgDidWJcJ1y2z165PtS4Pxkf7VJBXXpyYuv74/Fi0DF3KbtPJIK8Yx eYvpPYuBIBa/ocnqyWebNAEnKElisC43Yfmdef/Or+2gUokBRWgUz+7S/F1qhdnF3V3t r4H4xYrnW4iJJR3mmR64hgtnJXsHx7en2hQTPffsuNvAfKZhX8jz7JyhX6tXWpMrZxa8 WH8Etm0q/TA0dpmSuYgNZ3Ewr5NoTH1EQ+ofMO1rCVW7TzoxS74KHvAR0Op4TruiFGPA ixqw== X-Forwarded-Encrypted: i=1; AJvYcCXpaaTi9qxBe/WCxj0M2YL1oJpXz7CvHK5tVWt7IAQBrr4D4JtHZdY1R7J+UASE0B1VLKE=@vger.kernel.org X-Gm-Message-State: AOJu0YwHK3/P1RoZNcXzfrbdEvue2UfoSnOBm23U/uZFq+svkIPqHSwx WPscnKH5itQRePjM0K87llfvIgAcX4aghZ28rYIpuAB0oZScCGaoHz6CPUKYSzAtXdpSvCPR7Hr nkw== X-Google-Smtp-Source: AGHT+IGUByijU78nvHemXzOEaAQQDSmObXI7NYnb4v2toowk5S9287aNHUtx84WY5rqumwN+j1k67ZUHOWo= X-Received: from pfd7.prod.google.com ([2002:a05:6a00:a807:b0:727:2d74:d385]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2d1f:b0:1e1:b1e4:e750 with SMTP id adf61e73a8af0-1e5e04717a2mr2014875637.18.1734658757426; Thu, 19 Dec 2024 17:39:17 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 19 Dec 2024 17:39:03 -0800 In-Reply-To: <20241220013906.3518334-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220013906.3518334-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220013906.3518334-6-seanjc@google.com> Subject: [PATCH 5/8] KVM: selftests: Add struct and helpers to wrap binary stats cache From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Add a struct and helpers to manage the binary stats cache, which is currently used only for VM-scoped stats. This will allow expanding the selftests infrastructure to provide support for vCPU-scoped binary stats, which, except for the ioctl to get the stats FD are identical to VM-scoped stats. Defer converting __vm_get_stat() to a scope-agnostic helper to a future patch, as getting the stats FD from KVM needs to be moved elsewhere before it can be made completely scope-agnostic. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/kvm_util.h | 11 +++-- tools/testing/selftests/kvm/lib/kvm_util.c | 47 +++++++++++-------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 044c2231431e..9a64bab42f89 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -46,6 +46,12 @@ struct userspace_mem_region { struct hlist_node slot_node; }; +struct kvm_binary_stats { + int fd; + struct kvm_stats_header header; + struct kvm_stats_desc *desc; +}; + struct kvm_vcpu { struct list_head list; uint32_t id; @@ -99,10 +105,7 @@ struct kvm_vm { struct kvm_vm_arch arch; - /* Cache of information for binary stats interface */ - int stats_fd; - struct kvm_stats_header stats_header; - struct kvm_stats_desc *stats_desc; + struct kvm_binary_stats stats; /* * KVM region slots. These are the default memslots used by page diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 21b5a6261106..c88f5e7871f7 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -657,6 +657,20 @@ userspace_mem_region_find(struct kvm_vm *vm, uint64_t start, uint64_t end) return NULL; } +static void kvm_stats_release(struct kvm_binary_stats *stats) +{ + int ret; + + if (!stats->desc) + return; + + free(stats->desc); + stats->desc = NULL; + + ret = close(stats->fd); + TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("close()", ret)); +} + __weak void vcpu_arch_free(struct kvm_vcpu *vcpu) { @@ -711,13 +725,7 @@ void kvm_vm_release(struct kvm_vm *vmp) TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("close()", ret)); /* Free cached stats metadata and close FD */ - if (vmp->stats_desc) { - free(vmp->stats_desc); - vmp->stats_desc = NULL; - - ret = close(vmp->stats_fd); - TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("close()", ret)); - } + kvm_stats_release(&vmp->stats); } static void __vm_mem_region_delete(struct kvm_vm *vm, @@ -2214,34 +2222,33 @@ void read_stat_data(int stats_fd, struct kvm_stats_header *header, * * Read the data values of a specified stat from the binary stats interface. */ -void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, +void __vm_get_stat(struct kvm_vm *vm, const char *name, uint64_t *data, size_t max_elements) { + struct kvm_binary_stats *stats = &vm->stats; struct kvm_stats_desc *desc; size_t size_desc; int i; - if (!vm->stats_desc) { - vm->stats_fd = vm_get_stats_fd(vm); - read_stats_header(vm->stats_fd, &vm->stats_header); - vm->stats_desc = read_stats_descriptors(vm->stats_fd, - &vm->stats_header); + if (!stats->desc) { + stats->fd = vm_get_stats_fd(vm); + read_stats_header(stats->fd, &stats->header); + stats->desc = read_stats_descriptors(stats->fd, &stats->header); } - size_desc = get_stats_descriptor_size(&vm->stats_header); + size_desc = get_stats_descriptor_size(&stats->header); - for (i = 0; i < vm->stats_header.num_desc; ++i) { - desc = (void *)vm->stats_desc + (i * size_desc); + for (i = 0; i < stats->header.num_desc; ++i) { + desc = (void *)stats->desc + (i * size_desc); - if (strcmp(desc->name, stat_name)) + if (strcmp(desc->name, name)) continue; - read_stat_data(vm->stats_fd, &vm->stats_header, desc, - data, max_elements); + read_stat_data(stats->fd, &stats->header, desc, data, max_elements); return; } - TEST_FAIL("Unabled to find stat '%s'", stat_name); + TEST_FAIL("Unabled to find stat '%s'", name); } __weak void kvm_arch_vm_post_create(struct kvm_vm *vm) From patchwork Fri Dec 20 01:39:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13915999 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D03EB17BEBF for ; Fri, 20 Dec 2024 01:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658762; cv=none; b=Nw6KbtKiePVTRtKTDj89ltJC70ybyarhAvQT8k6gs2+nL72txoGhyssS9tEw0tIj1UIqZ2CaXIBYY6p5DE2QWyGhtw3RL3RrUjKLiPKzoSLZxm9REa4cIIpWUpVOyUj3kIYtNZvil4jfulNnG6FwW9nVs7n6OfGjr4QdWpWwVZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658762; c=relaxed/simple; bh=9wCSd3rSLA4oI57Um3yrK2ezfr59o98xEdgio1tOA1k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QCobldvoJLns7WZNFz3my9RI9hsaiuGDn2peHp3TgCk9BXLFNxU3cbUtX1eDtfUsdU+idInC6GaHHoYWr9dguQ1qbBGi/9Ckxs9eQ6snL3dc5CwSQFUhGKa6SKVNvuikd53drdlpFXOrD8jSy6lUmCsQIG4a6Er6EwOb4sk2p4c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=erNjRo9o; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="erNjRo9o" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-726047a4bd1so2076179b3a.3 for ; Thu, 19 Dec 2024 17:39:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734658759; x=1735263559; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=9d0sb2aXj7DAHSi3NyOXr17347erebt+0rHoY2hViJM=; b=erNjRo9o5pMkDoGgzTfCqC3ihalDYxXLpQQu7fK50HkzRzUy6HV8VejFh8pZD+R/o3 O+LZQa5rHCxMQkwIJolmjFqyBusck02/RccF329IvONeNV2/FIxjMe+M5F+Hv2z9kIgz Ejh31getAyQ7CFIF80pkcWhxpa7xidrAMOqsH9l4muf3dwtQZGq0FxT0klsodL8JV3Oc +FNd8VhqZiDLoovRMsDN1WtwyXlQXLd3LOVQ2okjE4d87Z8wCJrO7NIZPMmiEvtBfSmi O3pxfJ0RYt2miyMNbAOgvP1ZTeq07MvnX6Xu361af83an/prpLCSIF3Q+1jRj029nkKi YlZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734658759; x=1735263559; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9d0sb2aXj7DAHSi3NyOXr17347erebt+0rHoY2hViJM=; b=objCpuAoBM80kurTf0AK+74CBWX9TOr2PXSFnane7ONsuQXhMcO+R3+tKjzc3hZUf6 JJpPmdruAqEyja8ic+/XRZnoLdM5ouR3VKgo6zaQ01ilnPq+jn1tW6Yr0Q/lKTBjfWeM EnTPYt9EclPHczNvyWGqwR/lH46qinef2Cj+V6XiT7uel1+0Y1yKPqrof4rFg1fcINfu 40teYiCAK6WDcfJRJcejH50hlgu9oRO/BH3YB97JW221eisUWbXnoGYBVbcdG/7BibBX WcZXv9kGIzo4WcgYtvK+13Q+a30NFl8M2WjKwW1KuZhf/cmsDqQIxxXhxzai2mMGLIdx U4SQ== X-Forwarded-Encrypted: i=1; AJvYcCX0HYRRjLnvUK1TgReQtlf0lsrNwf9G2tbWDw3yp8XTybEZz3oo+n7/seF5xeEDDyhAOAc=@vger.kernel.org X-Gm-Message-State: AOJu0YzvFvwS2cb7mMwOJ6/OergjmjwN9WPnIR5etQ+BR8dKvyTYAQKy T4w/Pl/JI8vcDSd2JLQ1avbkxfuwZVS65n/WGP+41C20/N8l33GNieZohy/ADpNPaMEi2gvwRtE QDQ== X-Google-Smtp-Source: AGHT+IFCVSOEBNw3Lv/7iuAoV97N3pDi0VWzw4l+AQLpoLja8FzKhTyc8mSa5fPmEkzN6L6pcIM/EKjTQ3o= X-Received: from pfbby5.prod.google.com ([2002:a05:6a00:4005:b0:725:e39e:1055]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3cc2:b0:71e:4cff:2654 with SMTP id d2e1a72fcca58-72abdd6eb8cmr1219933b3a.6.1734658759224; Thu, 19 Dec 2024 17:39:19 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 19 Dec 2024 17:39:04 -0800 In-Reply-To: <20241220013906.3518334-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220013906.3518334-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220013906.3518334-7-seanjc@google.com> Subject: [PATCH 6/8] KVM: selftests: Get VM's binary stats FD when opening VM From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Get and cache a VM's binary stats FD when the VM is opened, as opposed to waiting until the stats are first used. Opening the stats FD outside of __vm_get_stat() will allow converting it to a scope-agnostic helper. Note, this doesn't interfere with kvm_binary_stats_test's testcase that verifies a stats FD can be used after its own VM's FD is closed, as the cached FD is also closed during kvm_vm_free(). Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/kvm_util.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index c88f5e7871f7..16ee03e76d66 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -196,6 +196,11 @@ static void vm_open(struct kvm_vm *vm) vm->fd = __kvm_ioctl(vm->kvm_fd, KVM_CREATE_VM, (void *)vm->type); TEST_ASSERT(vm->fd >= 0, KVM_IOCTL_ERROR(KVM_CREATE_VM, vm->fd)); + + if (kvm_has_cap(KVM_CAP_BINARY_STATS_FD)) + vm->stats.fd = vm_get_stats_fd(vm); + else + vm->stats.fd = -1; } const char *vm_guest_mode_string(uint32_t i) @@ -661,14 +666,17 @@ static void kvm_stats_release(struct kvm_binary_stats *stats) { int ret; - if (!stats->desc) + if (stats->fd < 0) return; - free(stats->desc); - stats->desc = NULL; + if (stats->desc) { + free(stats->desc); + stats->desc = NULL; + } ret = close(stats->fd); TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("close()", ret)); + stats->fd = -1; } __weak void vcpu_arch_free(struct kvm_vcpu *vcpu) @@ -2231,7 +2239,6 @@ void __vm_get_stat(struct kvm_vm *vm, const char *name, uint64_t *data, int i; if (!stats->desc) { - stats->fd = vm_get_stats_fd(vm); read_stats_header(stats->fd, &stats->header); stats->desc = read_stats_descriptors(stats->fd, &stats->header); } From patchwork Fri Dec 20 01:39:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13916000 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8ABF9186E54 for ; Fri, 20 Dec 2024 01:39:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658763; cv=none; b=itQUNy52dmXVor2KbN2xJbS0I1s8fBgOelxJC895BDPRvC7LFIW/TQiuhS9aAAvzd4tkKHbK2pHM5y4rtrZkSxskrsNiJBrQudK63eMFze10K4OP8+dycc0knlHOQ9WTq4uFMFJkrsi3c6INaDZk9xnMeBnnwFqnseF3HnPa2Rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658763; c=relaxed/simple; bh=B+RJp0TYVNSYdkENveDWwDdnsH059YtVcZm9zws4alI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KFllteyVk8tqZpOYPsuFTNaZ1SHx3KCHTE1q0AzdHEZFpQhywDCuokN+t7kyOmWoKRJZuEEd46XmxNRePAC5xuIuLHp/t+RAd+7zcWQI35Hegi5d+ugLOA8vtzIWbg5vOMtuUS3xk7DM/gBDYGrBf1mcmfVM6dyacqLp7/dpBuo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Al7Oj66y; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Al7Oj66y" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef9da03117so1749213a91.1 for ; Thu, 19 Dec 2024 17:39:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734658761; x=1735263561; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=dH5y8/UE39Fu2msLM/JJYa9i5LZG9N1ZOJAUvzMfFnk=; b=Al7Oj66ydz8dPcNCKh4q0gXlV+MOOD7aAQQss8of06t7hMxi8z628f6gqgD31Gt4e3 xFGXY1rp5/2MnBm+nuwk2tU+sP6i9nFCt1dOV1CfDpy20vbNF6//WJIoCiYmNjHgy5lG 4m1hr2EgYoec88H0VzD5XRBtf400nA7y9esYkYd/WnJic/x1UUD5enbSaSxknGgBF/8x 143vgHGBG7Ylv4jDXWJbVYq+JHXTcPvbNdG8Ezk6JOQWy6pqPUfLAjkp4U5ORG5cyPtl HhkI0P/zruV+JrU//Cg18PW9Zn7V9gYubXSdcHWf6RJyo+jRu/RxiQIMcaOBrOc2D7TX ThxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734658761; x=1735263561; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dH5y8/UE39Fu2msLM/JJYa9i5LZG9N1ZOJAUvzMfFnk=; b=G7wEr0xEcL/HIsukZAodefAkukNTN17F8CTflfO92JG0vAlGaIzThliyoEXAk3FECW G0FLTKSHf8IIr3v80+m/OcsPGhojEY05R0VLRZhMTcApG1XsU5737oJuy7H2Q5NMC72B OGUMzwxnXHsgFnALJq7wis/KqRMO2S+OcspZCINYQ0uCS73TtajcybdKaDKqHHfZgoCl 8AM9VJF2afITCONgFeL/Ifvck4IoeugwlKOqeaK9Je6o6N4g8o4/9n/cYBIcgfmJm0eD OTxZkJp49zlwccuZc1AyMQs7j5MTyiv79EUylXfVrGwYz9ezGjKNYIG44LSjyHMOJmKU XGqA== X-Forwarded-Encrypted: i=1; AJvYcCUSh9FouBtl0VxHzlgLzPP2B94ELQA/Xq/q0Jubvy6syNTBRo7SN4aLa5cF5lt9JNRdLO0=@vger.kernel.org X-Gm-Message-State: AOJu0YxmyC2HYQlY4o+n9wwmFV/u/5MI94jRYMjFP92XYoB0HduU+4iT N1h+z/57vKH6TIn+4HchZdM38S2gkIAmtBoiowfO490E7Qz41ndd0uu4HbWBDYRj3aVjFV6q0My +3w== X-Google-Smtp-Source: AGHT+IEWDX/fMBQN37LNDm8pwZAbb4nPz2A12lsLKXmgW0NfsvdhBH23GcxtGNe29UPGQ7kGMBybcOA6PXg= X-Received: from pjbqn15.prod.google.com ([2002:a17:90b:3d4f:b0:2ef:8612:dd6b]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:e18b:b0:2ee:9902:18b4 with SMTP id 98e67ed59e1d1-2f452ee838bmr1687135a91.27.1734658760980; Thu, 19 Dec 2024 17:39:20 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 19 Dec 2024 17:39:05 -0800 In-Reply-To: <20241220013906.3518334-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220013906.3518334-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220013906.3518334-8-seanjc@google.com> Subject: [PATCH 7/8] KVM: selftests: Add infrastructure for getting vCPU binary stats From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Now that the binary stats cache infrastructure is largely scope agnostic, add support for vCPU-scoped stats. Like VM stats, open and cache the stats FD when the vCPU is created so that it's guaranteed to be valid when vcpu_get_stats() is invoked. To sanity check that the infrastructure actually works, and to get a bit of bonus coverage, add an assert in x86's xapic_ipi_test to verify that the number of HLTs executed by the test matches the number of HLT exits observed by KVM. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/kvm_util.h | 20 +++++++++------ tools/testing/selftests/kvm/lib/kvm_util.c | 25 +++++++------------ .../selftests/kvm/x86/xapic_ipi_test.c | 2 ++ 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 9a64bab42f89..e0d23873158e 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -61,6 +61,7 @@ struct kvm_vcpu { #ifdef __x86_64__ struct kvm_cpuid2 *cpuid; #endif + struct kvm_binary_stats stats; struct kvm_dirty_gfn *dirty_gfns; uint32_t fetch_index; uint32_t dirty_gfns_count; @@ -534,17 +535,20 @@ void read_stat_data(int stats_fd, struct kvm_stats_header *header, struct kvm_stats_desc *desc, uint64_t *data, size_t max_elements); -void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, - size_t max_elements); +void kvm_get_stat(struct kvm_binary_stats *stats, const char *name, + uint64_t *data, size_t max_elements); -#define vm_get_stat(vm, stat) \ -({ \ - uint64_t data; \ - \ - __vm_get_stat(vm, #stat, &data, 1); \ - data; \ +#define __get_stat(stats, stat) \ +({ \ + uint64_t data; \ + \ + kvm_get_stat(stats, #stat, &data, 1); \ + data; \ }) +#define vm_get_stat(vm, stat) __get_stat(&(vm)->stats, stat) +#define vcpu_get_stat(vcpu, stat) __get_stat(&(vcpu)->stats, stat) + void vm_create_irqchip(struct kvm_vm *vm); static inline int __vm_create_guest_memfd(struct kvm_vm *vm, uint64_t size, diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 16ee03e76d66..99fe8bcd2346 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -712,6 +712,8 @@ static void vm_vcpu_rm(struct kvm_vm *vm, struct kvm_vcpu *vcpu) ret = close(vcpu->fd); TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("close()", ret)); + kvm_stats_release(&vcpu->stats); + list_del(&vcpu->list); vcpu_arch_free(vcpu); @@ -1305,6 +1307,11 @@ struct kvm_vcpu *__vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id) TEST_ASSERT(vcpu->run != MAP_FAILED, __KVM_SYSCALL_ERROR("mmap()", (int)(unsigned long)MAP_FAILED)); + if (kvm_has_cap(KVM_CAP_BINARY_STATS_FD)) + vcpu->stats.fd = vcpu_get_stats_fd(vcpu); + else + vcpu->stats.fd = -1; + /* Add to linked-list of VCPUs. */ list_add(&vcpu->list, &vm->vcpus); @@ -2217,23 +2224,9 @@ void read_stat_data(int stats_fd, struct kvm_stats_header *header, desc->name, size, ret); } -/* - * Read the data of the named stat - * - * Input Args: - * vm - the VM for which the stat should be read - * stat_name - the name of the stat to read - * max_elements - the maximum number of 8-byte values to read into data - * - * Output Args: - * data - the buffer into which stat data should be read - * - * Read the data values of a specified stat from the binary stats interface. - */ -void __vm_get_stat(struct kvm_vm *vm, const char *name, uint64_t *data, - size_t max_elements) +void kvm_get_stat(struct kvm_binary_stats *stats, const char *name, + uint64_t *data, size_t max_elements) { - struct kvm_binary_stats *stats = &vm->stats; struct kvm_stats_desc *desc; size_t size_desc; int i; diff --git a/tools/testing/selftests/kvm/x86/xapic_ipi_test.c b/tools/testing/selftests/kvm/x86/xapic_ipi_test.c index a76078a08ff8..574a944763b7 100644 --- a/tools/testing/selftests/kvm/x86/xapic_ipi_test.c +++ b/tools/testing/selftests/kvm/x86/xapic_ipi_test.c @@ -465,6 +465,8 @@ int main(int argc, char *argv[]) cancel_join_vcpu_thread(threads[0], params[0].vcpu); cancel_join_vcpu_thread(threads[1], params[1].vcpu); + TEST_ASSERT_EQ(data->hlt_count, vcpu_get_stat(params[0].vcpu, halt_exits)); + fprintf(stderr, "Test successful after running for %d seconds.\n" "Sending vCPU sent %lu IPIs to halting vCPU\n" From patchwork Fri Dec 20 01:39:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13916001 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70FD319DF47 for ; Fri, 20 Dec 2024 01:39:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658765; cv=none; b=OKZtuUDla5IT2YNbYDLgYxqSaSmxqUCk0QW9+owXtuEyT9kZ8/vHH9ILVuMrHDe/6g1eJvmVqqy6kTXgku8t1QaCphHWUDoHDhw93ok23RSA8psUr58/1mQdfGm6PoxUPp5SFVSW7N3yJQcyEtsyeJSYIrqynCsRR663MHYvHxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658765; c=relaxed/simple; bh=nqQDxG063aqcSsWGMdpx+mWnh2VxAOb7f/HB5PC3v8Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ohMZ985iVjscAXWYf401rrYmwphJSFx7EwTVKIhqZ7lrJ4X7uyCxJAr8t/vbe+lT1jEj4iosNeiDlI6GvvWr7dYwn3W5GG+M5SNVzJCHLY8znK8ftfkn+PmFNnbqSijDi4L64Fn4UtEPoD4F6tlRCjOwC9Ua1v6oOhKKvCaBzrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bjZ/xlqw; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bjZ/xlqw" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-72aa68f306fso1227638b3a.0 for ; Thu, 19 Dec 2024 17:39:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734658763; x=1735263563; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:from:to:cc:subject:date :message-id:reply-to; bh=Dg8fmjMM2o4ZdUzcCM3IsD7JuuynFC9AcsVyNRsKeBU=; b=bjZ/xlqwRmoxBE/vxJFgUGhcEVlDo+va4m2bMBPe7GlHf08EYB8FSiICdAVe2VKHXT 9LLBYmwdDoJoOe2rPHXHDzkowrhk58oTjJYlPZqV+DqHxPjREXa7pLmG/9OtA9IxOHRQ WtTr0BcBOx+y6jNDjSoLfhE23nPbLMMT52FB7E4Ng6xwqDVrvVGNn2WytV5jOlR7Lv8v bXrDEOpl7TL6plsRh7q2ullbM7XOinXycZNTM44pGhuxC7ovNW5wLeYka6i2kYlG/ti0 IXbCO49QIZGS5cucbUAknPk3Aire8+Qg1knqUXuQKn2iHsVkLfMjftuTh3IsPIVKf0IB 1+Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734658763; x=1735263563; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Dg8fmjMM2o4ZdUzcCM3IsD7JuuynFC9AcsVyNRsKeBU=; b=aQcPyyflUFtXWbIwA4HuieIXGSRk02aVHVTuwcPqOrrmw239swfzGh/A98Yk+OGk/p ryCEXmfWy8LGkIXFylk1oH53k0I1IX87BOoo35s8lY168klqU2BorL3wCV6LyzpkSKis AynkNUUzkajwyjiSTLNZUK0JTTAZRudNLDNSxhZ0cLlnA1s46uSMAnKBUdKlAea+Cd2e 60OwLkDrfJ07+JG4D5JO8/z7+r0B7S2x3s2Sx4BhERuN1kauTBuY+H3ixK5WZDdDEAe3 VN2aRfuPlWaKzG63usC8TTtfbmuSm+Ri/nxcKOGu9QxK4syoHJe8LYoeaBT+SsBVbzmD Gegw== X-Forwarded-Encrypted: i=1; AJvYcCXRwZ/xM1cgLdeMNRYgC3pXeq8KOUHRmdL1bG5780Od8wGjNLKOc6jFSQ/uGK0tzXQg+b0=@vger.kernel.org X-Gm-Message-State: AOJu0YzZjleLCcwYj0TMp7Tv/Be/W0aFAbaxTNuqNeqwVlNOODT9MsdV fxo3ZAkuSQ7PwMlq8rJ01nccBGwCfH4YPVfOz7zI9LrF5nQqXCRtoI/xSasr6Cu8uoMeA6Rw7CD jPg== X-Google-Smtp-Source: AGHT+IE6EA1Soh2HbsBhs8mA4Cxp5/kcHpg0QYYkszskXT1G6lUfvmxNE+q8q9njljny5qS/JMm3vKiIjQ4= X-Received: from pgbbw29.prod.google.com ([2002:a05:6a02:49d:b0:801:d768:c174]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6300:6681:b0:1e0:c6c0:1e1f with SMTP id adf61e73a8af0-1e5e07f8a98mr2122068637.36.1734658762701; Thu, 19 Dec 2024 17:39:22 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 19 Dec 2024 17:39:06 -0800 In-Reply-To: <20241220013906.3518334-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220013906.3518334-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220013906.3518334-9-seanjc@google.com> Subject: [PATCH 8/8] KVM: selftests: Add compile-time assertions to guard against stats typos From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Add compile-time assertions to the main binary stats accessor to verify the stat is a known KVM stat of the appropriate scope, and "add" all known stats for all architectures. To build the set of known stats, define enums for each stat, with a completely arbitrary magic value to specify the scope of the stat. With the assert in place, misuse of stat (or usage of a new stat) generates error like so: In file included from include/x86/kvm_util_arch.h:8, from include/kvm_util.h:23, from x86/dirty_log_page_splitting_test.c:16: x86/dirty_log_page_splitting_test.c: In function ‘get_page_stats’: include/kvm_util.h:563:42: error: ‘VM_STAT_pages_4m’ undeclared (first use in this function); did you mean ‘VM_STAT_pages_2m’? 563 | #define vm_get_stat(vm, stat) __get_stat(VM, &(vm)->stats, stat) | ^~ ... x86/dirty_log_page_splitting_test.c:45:27: note: in expansion of macro ‘vm_get_stat’ 45 | stats->pages_2m = vm_get_stat(vm, pages_4m); | ^~~~~~~~~~~ Using pre-defined lists of stats doesn't completely eliminate human error, e.g. it's obviously possible to make a typo when adding a state. And while there is also a non-zero cost to maintaining the set of stats, adding stats in KVM is relatively uncommon, and removing stats is extremely rare. On the flip side, providing a list of known stats should make it easier to use stats in test, at which point detecting goofs at compile-time will also be more valuable. Signed-off-by: Sean Christopherson --- .../kvm/include/arm64/kvm_util_arch.h | 12 ++ .../testing/selftests/kvm/include/kvm_util.h | 24 +++- .../selftests/kvm/include/kvm_util_types.h | 6 + .../kvm/include/riscv/kvm_util_arch.h | 14 +++ .../kvm/include/s390/kvm_util_arch.h | 113 ++++++++++++++++++ .../selftests/kvm/include/x86/kvm_util_arch.h | 52 ++++++++ 6 files changed, 218 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h b/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h index e43a57d99b56..12097262f585 100644 --- a/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h +++ b/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h @@ -2,6 +2,18 @@ #ifndef SELFTEST_KVM_UTIL_ARCH_H #define SELFTEST_KVM_UTIL_ARCH_H +#include "kvm_util_types.h" + struct kvm_vm_arch {}; +enum kvm_arm64_stats { + VCPU_STAT(hvc_exit_stat), + VCPU_STAT(wfe_exit_stat), + VCPU_STAT(wfi_exit_stat), + VCPU_STAT(mmio_exit_user), + VCPU_STAT(mmio_exit_kernel), + VCPU_STAT(signal_exits), + VCPU_STAT(exits), +}; + #endif // SELFTEST_KVM_UTIL_ARCH_H diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index e0d23873158e..f4f0e27cea27 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -535,19 +535,37 @@ void read_stat_data(int stats_fd, struct kvm_stats_header *header, struct kvm_stats_desc *desc, uint64_t *data, size_t max_elements); +enum kvm_common_stats { + VM_STAT(remote_tlb_flush), + VM_STAT(remote_tlb_flush_requests), + + VCPU_STAT(halt_successfull_poll), + VCPU_STAT(halt_attempted_poll), + VCPU_STAT(halt_poll_invalid), + VCPU_STAT(halt_wakeup), + VCPU_STAT(halt_poll_success_ns), + VCPU_STAT(halt_poll_fail_ns), + VCPU_STAT(halt_wait_ns), + VCPU_STAT(halt_poll_success_hist), + VCPU_STAT(halt_poll_fail_hist), + VCPU_STAT(halt_wait_hist), + VCPU_STAT(blocking), +}; + void kvm_get_stat(struct kvm_binary_stats *stats, const char *name, uint64_t *data, size_t max_elements); -#define __get_stat(stats, stat) \ +#define __get_stat(type, stats, stat) \ ({ \ uint64_t data; \ \ + kvm_static_assert(type##_STAT_##stat == type##_STAT_MAGIC_NUMBER); \ kvm_get_stat(stats, #stat, &data, 1); \ data; \ }) -#define vm_get_stat(vm, stat) __get_stat(&(vm)->stats, stat) -#define vcpu_get_stat(vcpu, stat) __get_stat(&(vcpu)->stats, stat) +#define vm_get_stat(vm, stat) __get_stat(VM, &(vm)->stats, stat) +#define vcpu_get_stat(vcpu, stat) __get_stat(VCPU, &(vcpu)->stats, stat) void vm_create_irqchip(struct kvm_vm *vm); diff --git a/tools/testing/selftests/kvm/include/kvm_util_types.h b/tools/testing/selftests/kvm/include/kvm_util_types.h index ec787b97cf18..20e6717a0d24 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_types.h +++ b/tools/testing/selftests/kvm/include/kvm_util_types.h @@ -17,4 +17,10 @@ typedef uint64_t vm_paddr_t; /* Virtual Machine (Guest) physical address */ typedef uint64_t vm_vaddr_t; /* Virtual Machine (Guest) virtual address */ +#define VM_STAT_MAGIC_NUMBER 1 +#define VM_STAT(stat) VM_STAT_##stat = VM_STAT_MAGIC_NUMBER + +#define VCPU_STAT_MAGIC_NUMBER 2 +#define VCPU_STAT(stat) VCPU_STAT_##stat = VCPU_STAT_MAGIC_NUMBER + #endif /* SELFTEST_KVM_UTIL_TYPES_H */ diff --git a/tools/testing/selftests/kvm/include/riscv/kvm_util_arch.h b/tools/testing/selftests/kvm/include/riscv/kvm_util_arch.h index e43a57d99b56..ea53d6aeb693 100644 --- a/tools/testing/selftests/kvm/include/riscv/kvm_util_arch.h +++ b/tools/testing/selftests/kvm/include/riscv/kvm_util_arch.h @@ -2,6 +2,20 @@ #ifndef SELFTEST_KVM_UTIL_ARCH_H #define SELFTEST_KVM_UTIL_ARCH_H +#include "kvm_util_types.h" + struct kvm_vm_arch {}; +enum kvm_riscv_stats { + VCPU_STAT(ecall_exit_stat), + VCPU_STAT(wfi_exit_stat), + VCPU_STAT(wrs_exit_stat), + VCPU_STAT(mmio_exit_user), + VCPU_STAT(mmio_exit_kernel), + VCPU_STAT(csr_exit_user), + VCPU_STAT(csr_exit_kernel), + VCPU_STAT(signal_exits), + VCPU_STAT(exits), +}; + #endif // SELFTEST_KVM_UTIL_ARCH_H diff --git a/tools/testing/selftests/kvm/include/s390/kvm_util_arch.h b/tools/testing/selftests/kvm/include/s390/kvm_util_arch.h index e43a57d99b56..64d4de333e09 100644 --- a/tools/testing/selftests/kvm/include/s390/kvm_util_arch.h +++ b/tools/testing/selftests/kvm/include/s390/kvm_util_arch.h @@ -2,6 +2,119 @@ #ifndef SELFTEST_KVM_UTIL_ARCH_H #define SELFTEST_KVM_UTIL_ARCH_H +#include "kvm_util_types.h" + struct kvm_vm_arch {}; +enum kvm_s390_stats { + VM_STAT(inject_io), + VM_STAT(inject_float_mchk), + VM_STAT(inject_pfault_done), + VM_STAT(inject_service_signal), + VM_STAT(inject_virtio), + VM_STAT(aen_forward), + VM_STAT(gmap_shadow_reuse), + VM_STAT(gmap_shadow_create), + VM_STAT(gmap_shadow_r1_entry), + VM_STAT(gmap_shadow_r2_entry), + VM_STAT(gmap_shadow_r3_entry), + VM_STAT(gmap_shadow_sg_entry), + VM_STAT(gmap_shadow_pg_entry), + + VCPU_STAT(exit_userspace), + VCPU_STAT(exit_null), + VCPU_STAT(exit_external_request), + VCPU_STAT(exit_io_request), + VCPU_STAT(exit_external_interrupt), + VCPU_STAT(exit_stop_request), + VCPU_STAT(exit_validity), + VCPU_STAT(exit_instruction), + VCPU_STAT(exit_pei), + VCPU_STAT(halt_no_poll_steal), + VCPU_STAT(instruction_lctl), + VCPU_STAT(instruction_lctlg), + VCPU_STAT(instruction_stctl), + VCPU_STAT(instruction_stctg), + VCPU_STAT(exit_program_interruption), + VCPU_STAT(exit_instr_and_program), + VCPU_STAT(exit_operation_exception), + VCPU_STAT(deliver_ckc), + VCPU_STAT(deliver_cputm), + VCPU_STAT(deliver_external_call), + VCPU_STAT(deliver_emergency_signal), + VCPU_STAT(deliver_service_signal), + VCPU_STAT(deliver_virtio), + VCPU_STAT(deliver_stop_signal), + VCPU_STAT(deliver_prefix_signal), + VCPU_STAT(deliver_restart_signal), + VCPU_STAT(deliver_program), + VCPU_STAT(deliver_io), + VCPU_STAT(deliver_machine_check), + VCPU_STAT(exit_wait_state), + VCPU_STAT(inject_ckc), + VCPU_STAT(inject_cputm), + VCPU_STAT(inject_external_call), + VCPU_STAT(inject_emergency_signal), + VCPU_STAT(inject_mchk), + VCPU_STAT(inject_pfault_init), + VCPU_STAT(inject_program), + VCPU_STAT(inject_restart), + VCPU_STAT(inject_set_prefix), + VCPU_STAT(inject_stop_signal), + VCPU_STAT(instruction_epsw), + VCPU_STAT(instruction_gs), + VCPU_STAT(instruction_io_other), + VCPU_STAT(instruction_lpsw), + VCPU_STAT(instruction_lpswe), + VCPU_STAT(instruction_lpswey), + VCPU_STAT(instruction_pfmf), + VCPU_STAT(instruction_ptff), + VCPU_STAT(instruction_sck), + VCPU_STAT(instruction_sckpf), + VCPU_STAT(instruction_stidp), + VCPU_STAT(instruction_spx), + VCPU_STAT(instruction_stpx), + VCPU_STAT(instruction_stap), + VCPU_STAT(instruction_iske), + VCPU_STAT(instruction_ri), + VCPU_STAT(instruction_rrbe), + VCPU_STAT(instruction_sske), + VCPU_STAT(instruction_ipte_interlock), + VCPU_STAT(instruction_stsi), + VCPU_STAT(instruction_stfl), + VCPU_STAT(instruction_tb), + VCPU_STAT(instruction_tpi), + VCPU_STAT(instruction_tprot), + VCPU_STAT(instruction_tsch), + VCPU_STAT(instruction_sie), + VCPU_STAT(instruction_essa), + VCPU_STAT(instruction_sthyi), + VCPU_STAT(instruction_sigp_sense), + VCPU_STAT(instruction_sigp_sense_running), + VCPU_STAT(instruction_sigp_external_call), + VCPU_STAT(instruction_sigp_emergency), + VCPU_STAT(instruction_sigp_cond_emergency), + VCPU_STAT(instruction_sigp_start), + VCPU_STAT(instruction_sigp_stop), + VCPU_STAT(instruction_sigp_stop_store_status), + VCPU_STAT(instruction_sigp_store_status), + VCPU_STAT(instruction_sigp_store_adtl_status), + VCPU_STAT(instruction_sigp_arch), + VCPU_STAT(instruction_sigp_prefix), + VCPU_STAT(instruction_sigp_restart), + VCPU_STAT(instruction_sigp_init_cpu_reset), + VCPU_STAT(instruction_sigp_cpu_reset), + VCPU_STAT(instruction_sigp_unknown), + VCPU_STAT(instruction_diagnose_10), + VCPU_STAT(instruction_diagnose_44), + VCPU_STAT(instruction_diagnose_9c), + VCPU_STAT(diag_9c_ignored), + VCPU_STAT(diag_9c_forward), + VCPU_STAT(instruction_diagnose_258), + VCPU_STAT(instruction_diagnose_308), + VCPU_STAT(instruction_diagnose_500), + VCPU_STAT(instruction_diagnose_other), + VCPU_STAT(pfault_sync), +}; + #endif // SELFTEST_KVM_UTIL_ARCH_H diff --git a/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h b/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h index 972bb1c4ab4c..f9c4aedddbd0 100644 --- a/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h +++ b/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h @@ -48,4 +48,56 @@ do { \ } \ } while (0) +enum kvm_x86_stats { + VM_STAT(mmu_shadow_zapped), + VM_STAT(mmu_pte_write), + VM_STAT(mmu_pde_zapped), + VM_STAT(mmu_flooded), + VM_STAT(mmu_recycled), + VM_STAT(mmu_cache_miss), + VM_STAT(mmu_unsync), + VM_STAT(pages_4k), + VM_STAT(pages_2m), + VM_STAT(pages_1g), + VM_STAT(pages), + VM_STAT(nx_lpage_splits), + VM_STAT(max_mmu_page_hash_collisions), + VM_STAT(max_mmu_rmap_size), + + VCPU_STAT(pf_taken), + VCPU_STAT(pf_fixed), + VCPU_STAT(pf_emulate), + VCPU_STAT(pf_spurious), + VCPU_STAT(pf_fast), + VCPU_STAT(pf_mmio_spte_created), + VCPU_STAT(pf_guest), + VCPU_STAT(tlb_flush), + VCPU_STAT(invlpg), + VCPU_STAT(exits), + VCPU_STAT(io_exits), + VCPU_STAT(mmio_exits), + VCPU_STAT(signal_exits), + VCPU_STAT(irq_window_exits), + VCPU_STAT(nmi_window_exits), + VCPU_STAT(l1d_flush), + VCPU_STAT(halt_exits), + VCPU_STAT(request_irq_exits), + VCPU_STAT(irq_exits), + VCPU_STAT(host_state_reload), + VCPU_STAT(fpu_reload), + VCPU_STAT(insn_emulation), + VCPU_STAT(insn_emulation_fail), + VCPU_STAT(hypercalls), + VCPU_STAT(irq_injections), + VCPU_STAT(nmi_injections), + VCPU_STAT(req_event), + VCPU_STAT(nested_run), + VCPU_STAT(directed_yield_attempted), + VCPU_STAT(directed_yield_successful), + VCPU_STAT(preemption_reported), + VCPU_STAT(preemption_other), + VCPU_STAT(guest_mode), + VCPU_STAT(notify_window_exits), +}; + #endif // SELFTEST_KVM_UTIL_ARCH_H