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: 13828691 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 B4535201109 for ; Wed, 9 Oct 2024 15:50:04 +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=1728489006; cv=none; b=t3PVyZiJfsjyS2YEMf8MLbUnaCyqOR5mh0C1wav2M/87qzkrGHilrdRMoCBtkw5M38kq1s0ISa5eIJ0qtZoI/LQICnotQTRopsDt7NZQwy5OpnjyGnJw5SGi11XmOxS1WqwqmpO4eQR9rggCzD7L8pqfUlZi1k3KDb4rvnsr07g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489006; c=relaxed/simple; bh=yMjqrBBrs5fD7ztP9Hd+ZjDB2ceAdIl8KOqv0sYfMVY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PxTz26s2GjTTDnsguPZKF7ySGAbqAxE42Q0Y8O/DNsSK2uTfEXYPO2qUXDebtlI0ZtYG3fY2Eogx4oNobc/q59P+bzTfJs4rYK76uJknw4+PnZJFtd/Omi54ZrFiJT8H4XCJ3Yl0qQmtQ64PVEzKXn18GMy3DL0CaaaZULmnr9g= 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=KdUXTV9p; 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="KdUXTV9p" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-71e1e989aa2so1030441b3a.3 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=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=x0cgmo92qPc8MR1y7gAJGg1sCyN/CNSLMfDMg1eW/5U=; b=KdUXTV9p3IjcpOSmHzQFFPIOx+QacZMhGzbwcxZB1x7gfMmdjM0rel2+OfkCYqAjb0 Q1jjQpw7rA/mxrn6z+c6xk8rgoDJsOvqdj0pDu+Ei1h05+0mZo4SPji+CbqbqqVgqgQz 1OtH3aCz+ICOzTChlVDlBSFhxPNz5vbMVDEQnUD9MnTfoUOTbXF7phJHcOSiCq6rjWFD cBRpG3p0aTW1D0EC2/zxOjJTGL0JTkykRX0yC3DU1TMx2w6hU5FYq43wp0+YzTae9Ms0 FHBURjiQ3gVtdEBUwk5gIiqucB5amQeNy1B2nSr92ghdV4lz3z4LiHkLfhDGHWXhsQPX EPXA== 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=I8SVP0XHKNDpBN/Cl3DUxoSQ4YMu8AimZu3rJatGfXOdWuvm4gw0BEudBWcK4C2PvV Vf4fUSqJDrjyjEAsCA/DNLuBi5NGUazzJqDJ2JtvNyZfpUP/Rnf0EFSvH0pVWZr6cpbh yHmeVoNRekiTqNpksbPdcNrJ2g5nEf+w88p8yxJL++nWLQjkMWDm6qJ4N7DyaQtwkKXF /6ocmQq0vgh4u4wb/GkX/NnAst714mPpy80Ua9XfpmbpdeqzsrKdZWG424Fn6plApwLH bx1sgeIAEVLGZ0T4idEmihysqMGo4ZF+9QkXLJgcJFIEBmnGZBEFCYBKWNcTqwAB2NQ6 V3ZA== X-Forwarded-Encrypted: i=1; AJvYcCVUrOz+CYmfM0BsZBG6GOx+BbpNcy16PfmQWifXCqoNMFexfnHWnegiUPPRljWe3mG6zV4=@vger.kernel.org X-Gm-Message-State: AOJu0YyXVppbdGvakUbjqF25xPEbtGhqNusf3KhXJY/YmbsGmg3hG83L TW2clGCzY4Jtizgvmw/FxkcwIfD1r8+Bw3FkWh/dIx1FEvNPcojEvAcHBtljQRNTEtNOsHyTHgH 8YQ== 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) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:43 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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, ®); }