From patchwork Wed Sep 11 20:41:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13801090 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BDD3BEE57CF for ; Wed, 11 Sep 2024 20:48:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To: From:Subject:Message-ID:References:Mime-Version:In-Reply-To:Date: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZSI8dsTyNYYmZluhAXeYyfAeB1n1NlxlB5JW+pr40RY=; b=Bx/bb9fubtZp8ty5NAAsuHr7af u/2/q7nazkUdiJBc2So3j/RStLid4ua7+sqI/PgsztiKofquIJC0IqKngdvZA9Nc/nZlJtUonSukL r6VJk8eIfy35hZHPbGv5RDchwOhWbpPT5hCYGFwNHH0j/y5iFHNMhgDyloCsxLVjonFu26S8HZPBS ZVJNykEE12syd4RUMewuc0bjpZv7rXuniuUS78DchEqybJ4EuPKbE4LIEYg6vVaz/orUFP6x/02PA 5YTz2oPnRwmEFfmhnvJjhvB3qsBvqBVoPNMs7Kiq18w35mHFKp5MwgZSdVBe9hRw/EFFRXjBg8gET TZEkO3Zg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUG5-0000000Az1u-1dYq; Wed, 11 Sep 2024 20:48:13 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUAY-0000000Awxn-1k7Y for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 20:42:32 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1fd9a0efe4eso4753885ad.0 for ; Wed, 11 Sep 2024 13:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726087349; x=1726692149; darn=lists.infradead.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=ZSI8dsTyNYYmZluhAXeYyfAeB1n1NlxlB5JW+pr40RY=; b=P5UrEw1BbgyBI92+F/30zhwQtRzK78LsAW/mwPicp971AQm9aPQkLwS2ZHIUa9SBaQ 4rGEJ4Jf4P4voOBPFTjNMlHXvQf5iojPAzDI+K2xJlmZMm/HiMXf/mN7XQNEp20YyXKz pGPuzFEJBA6FEqI6+mzF3/9AQ1hvEE5bsyiTM7FPMgPePbEPSSEtHEvc1T08qIvz2QX3 tA7cZb7d23o/csn0P0hpP6z5IEBkiGRJrYVKyqWICbNbQnwL75SrkZluG+oj8CQ4jQlx 9tTRJx3pvpml3R4VCJdXaFkg/xryzeByWqLS1g9xbH6Qq40eI+C7SZ4t4OhImrZeEsLN b40A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726087349; x=1726692149; 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=ZSI8dsTyNYYmZluhAXeYyfAeB1n1NlxlB5JW+pr40RY=; b=mrMQ0dgnmFdSSU/KLxvIMEc1TRRW3jGDpbY0vkEVWTKtBZoRMuA/BV9Z0vlZ1rnTHN YgJSvYRPR7sCdvHhi1znmr1N4W2esFAcJgHJdvAdMMP363c1w6Zkk4Fz7V3EN1rzbJRF FiTjR2oqYMV8lnSt5zq1aNpE9aikDK32clY4BITB8vZLuKU2fnV/FV/mT05U4ac/tLOv ZlKkwwmbap17DOAI2UtXYhwxQyWqDOAKzvNR4H/8nA+pLX2mOEflFACzfnlqb7dmsbIl OD0e27S2vDfx8FSc5wpBbISI+efHllbfsf6MiebtvzqVvT8qsGVnnBdyw6T/cQI6ndVJ z/Dw== X-Gm-Message-State: AOJu0YzFCY6TYdeqdU7Mxnh0/woswQZiPXsyMK4f6pM9OQeuSzIuZBns g0U+brPc1F+iMNSq/tdfVTcOn6hfaw1L31R2K+uye8QVm01NKRjAYyy8q49ymD6uimpQ3Fr2vod Cxw== X-Google-Smtp-Source: AGHT+IFVhcOXMpYuiCLKMEBjF0GLRF0droi6YIr05t4juUD0iWZSecyCNUnHqr+/fAL8PrR1+nheHNVoid8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:41d1:b0:206:99b3:52de with SMTP id d9443c01a7336-2076e47cc2dmr175945ad.10.1726087348954; Wed, 11 Sep 2024 13:42:28 -0700 (PDT) Date: Wed, 11 Sep 2024 13:41:49 -0700 In-Reply-To: <20240911204158.2034295-1-seanjc@google.com> Mime-Version: 1.0 References: <20240911204158.2034295-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911204158.2034295-5-seanjc@google.com> Subject: [PATCH v2 04/13] KVM: selftests: Assert that vcpu_{g,s}et_reg() won't truncate From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda 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, Sean Christopherson , James Houghton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_134230_531603_926F14E7 X-CRM114-Status: GOOD ( 11.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Assert that the the register being read/written by vcpu_{g,s}et_reg() is no larger than a uint64_t, i.e. that a selftest isn't unintentionally truncating the value being read/written. Ideally, the assert would be done at compile-time, but that would limit the checks to hardcoded accesses and/or require fancier compile-time assertion infrastructure to filter out dynamic usage. Signed-off-by: Sean Christopherson Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/include/kvm_util.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 429a7f003fe3..80230e49e35f 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -683,6 +683,8 @@ static inline uint64_t vcpu_get_reg(struct kvm_vcpu *vcpu, uint64_t id) uint64_t val; struct kvm_one_reg reg = { .id = id, .addr = (uint64_t)&val }; + TEST_ASSERT(KVM_REG_SIZE(id) <= sizeof(val), "Reg %lx too big", id); + vcpu_ioctl(vcpu, KVM_GET_ONE_REG, ®); return val; } @@ -690,6 +692,8 @@ static inline void vcpu_set_reg(struct kvm_vcpu *vcpu, uint64_t id, uint64_t val { struct kvm_one_reg reg = { .id = id, .addr = (uint64_t)&val }; + TEST_ASSERT(KVM_REG_SIZE(id) <= sizeof(val), "Reg %lx too big", id); + vcpu_ioctl(vcpu, KVM_SET_ONE_REG, ®); }