From patchwork Wed Oct 9 15:49:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828715 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 8197ACEE329 for ; Wed, 9 Oct 2024 16:00:46 +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=x0cgmo92qPc8MR1y7gAJGg1sCyN/CNSLMfDMg1eW/5U=; b=mvN3B6LvbvkBWYFZdXNzIj3387 BxX//SnjLCsDmTHt+elbAmCVm3cvvRLqyYOUTECMKOcvpy+bCOXTDVOWnwzz0SFTvBJr3ufej8Iwg 9rg92bHFETaBAaQz8hWHQiDq9Ox7P8vpYSYgikDu8QN4L1PFRSxc123nXxctyVTR4dP/J2U6bz77v vB9Cb/iB6lVaMpPr3FmaxemO4uef/WDQuXJf/OnkEQNp5uQuoH4EcwIQEcGjef/ruG6cGUhm1VVoP lsyCRJ/FhRcQ11pGcXPKQBkIrTWCxLgPDCyb+sszBWqgVtTmDiHqyD0eUm3I6kws+l1sqBPBIYHd6 HI1jDwxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syZ71-00000009qLx-38mv; Wed, 09 Oct 2024 16:00:31 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syYww-00000009o4Y-0J8h for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 15:50:09 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-71e1ed58e9bso1071907b3a.0 for ; Wed, 09 Oct 2024 08:50:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489004; x=1729093804; 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=x0cgmo92qPc8MR1y7gAJGg1sCyN/CNSLMfDMg1eW/5U=; b=v+PyAs7xiXW4JO4mkqRxca5B0uiPlhu7vlTcAcClWxQSiwpRYSNrqd2aMjIceW6lyE BSEhb33/syvmGwMTEj21gasth9MqjcxaWw1k2p+ILICHT3bjkQYDWv1K8aMEWKOY0WJk qZBRoYFfJ/TnX2h1+slwVUJVh/pma1Ve3oInfATojFO68zYRmcRFdQvbUyC156ZsROpZ 8gYvmQlmjikDmsALjECund8ccEIFi7QEL3noF8/t86Z22f7wXdu6OKdXDPodr6JmQzPO qV+ND6wRejh0cwSuKNcMfmm26Ez6KcpfTXk+FiZZSljPT/FAsjvSSqoL765HJgvOTDN/ tJNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489004; x=1729093804; 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=x0cgmo92qPc8MR1y7gAJGg1sCyN/CNSLMfDMg1eW/5U=; b=QUoTHh4gBCNlpZDEkOhxFRMemJSpY/8n+ROI9yW3WdiqJjqYrmz6GVfiCnveS8M0IT BGR9fn1pDaAvNJqsqyNoBOMeJPBHj2lGRPhwLcTVtzw2qGWBJA2qQyfWuHoWUxh7FjkE aI239PPB9DNNAPrpRDAlDoQXAj6QsZd0Ex/nUdz5FOVK1gel3WP/IeojeMYW81r6903X x0QulROPuIDMEoanFwBjlqbLl+vAMvDgIriVJJOx5aBiHHJSqKK3QaxmCYorE4/PlN70 vvROoYRxNzfSJpZKStaY0dU2+L+b8mUeiNxNBG1kY9UzXnHV8tPD0uU8KlnYziEIU5RT DT/A== X-Gm-Message-State: AOJu0YxPRoYsSCc2ns0mYlSz/1SwaGDt7kw5DzDgA9Dw2opHMclXDGA2 j8wQU7Ov3QoJCqWOLW+XpH3CFjZSBGcwzA7PpigFvHh9lWJdXSpNtWl0f10bzPr36m8v3ukq84j euw== X-Google-Smtp-Source: AGHT+IERUBPfneULnJ59z0o0A04D0VCwsGKXUdX4SfWVGxtKdYKWNTs8AEtFgRMkbcfSQG42khoM/WAQWlQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:6a00:4fcf:b0:71d:fb06:e79b with SMTP id d2e1a72fcca58-71e1daa9410mr6141b3a.0.1728489003716; Wed, 09 Oct 2024 08:50:03 -0700 (PDT) Date: Wed, 9 Oct 2024 08:49:43 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Mime-Version: 1.0 References: <20241009154953.1073471-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241009154953.1073471-5-seanjc@google.com> Subject: [PATCH v3 04/14] KVM: selftests: Assert that vcpu_{g,s}et_reg() won't truncate From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , 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 , Andrew Jones , James Houghton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_085006_178727_D9F5EDC6 X-CRM114-Status: GOOD ( 10.68 ) 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 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. Reviewed-by: Andrew Jones Signed-off-by: Sean Christopherson --- 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 287a3ec06df4..4c4e5a847f67 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -707,6 +707,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; } @@ -714,6 +716,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, ®); }