From mboxrd@z Thu Jan 1 00:00:00 1970 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 DFDDBEED618 for ; Thu, 12 Sep 2024 16:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: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:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CHc8H+AgFlKGz9oROxRBwufdfanAh7CzUD+9HRa3+GA=; b=YXxdFaIzSYT2z6dlZFjmAgEdJ9 e9vZACe4E7ubuvBZMaHkrZZ/m5BslGBZYkMxNgaDo8jWKHDwXkiJUifD/w3qdv0fFTMC1LNXHIWmm m3PoKquDLdL5yVkh/7SZDv13Q47rN1ULLHJTIQ4flIVLXc3CVVJCMBE1uIYJk4KfsdRL8Mg5fnb7P N1ou3Elb8aLFm4QwiRWnxJy6+GwBeGJ+aJ4mYDAHApEHlcsFy2kwgAYx+9CzrxduprwpzBXnPKjky gJOM4cclE64+YKFbvgT6weu3dUeYm5/OB/5EYmVkAMVKyIplaGHMOQ6WbW14XwEgHHLes8jPloRHm rEFdqdhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1somWs-0000000DgHL-2vVd; Thu, 12 Sep 2024 16:18:46 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1somVo-0000000DgB9-15Ae for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 16:17:41 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e1ab008280aso2097110276.0 for ; Thu, 12 Sep 2024 09:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726157858; x=1726762658; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CHc8H+AgFlKGz9oROxRBwufdfanAh7CzUD+9HRa3+GA=; b=uq33ZtgMtdGAvJWfftdEpk1qFrmZx3KrPAHQ6mm7hm1TlilU90A2dcYaPboMDJwxPH i6f+uYwNnPjrBqK9PvyXEUroCDmuKkTaeDbsUzmu9E16SntRxWNpaSpvT+fnbN9EnjT+ dpHBRh4lrMSVn1jAqqz+dCxVypOFhQV03cYv0aTZwn3bDNt/HzM8aTbDjN8GScSOhPHn uepcwSNzA/4HhLL1ws2qwBqQUs5EqbI+qIunhQ+zJ5hmE1DDwh8H5EdP1+6WmduyAmFs XW8yYV1f6LIqogExyNF9qG0OSnYQZZVfpsuSG6vzVoZrLHz6Wcomr92CH+f1YUdI/Tde pmBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726157858; x=1726762658; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CHc8H+AgFlKGz9oROxRBwufdfanAh7CzUD+9HRa3+GA=; b=wvRqE6nOgSw79+bkfSOuclXTSeXTzSa69pphv3gc87KJKnIF2JbE3v+UTB6mqYsnaX R8xbbqwebaHigby71pUKjDU7VagKr8yLhbd7gzFpPPyS00566Jy3zCW0JEF+xcanulJ+ b2HcyQOP8df+gxSWg1j4EyQQiCuynXlIoiF4zGgy/P9fOH+RldKefqQUec6yjP4iaNiV Ps4Gs/MRmc0k0j5HKLK/QQQSXYu5fMAA1SfvJbkFlveb3IllHbVlW4N03nunSAREAWY4 iiCkr9bpYEwTQ38W8UQ/Du+KKPtqb7b8FUWHj9T8zZ8HqHZqF+d4ndCMku6mj0y0HJZn I2/w== X-Forwarded-Encrypted: i=1; AJvYcCXG2ASgN+reDlwAEZB95VTnWYrE7moHYteenSmF6lmVdWnaYw5dwYOiJx8OR/GXUFOdySu76n4wnAgmVjCzdQ8B@lists.infradead.org X-Gm-Message-State: AOJu0Ywl33SRLNFplUHkJ1fYHRuekOLod+ixJIRBJxTtrn/Y9Y2u/Hl4 WJvaxe59XSIVOxQupKUP/ycYqrm43wUcHRC9ALmF6l/3S1tN4igSUugcFlXg8SSgZ16VUrhct20 cnA== X-Google-Smtp-Source: AGHT+IEJVscKJvuinHeLuj6Vk0WsuDDxtUgSvi9YqWgJNhdyRuKGPX9aioKoGnIVhZDgsM2BQvZ5JjUQZqU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:86c4:0:b0:e11:5e94:17dc with SMTP id 3f1490d57ef6-e1d9dbd0464mr4681276.5.1726157858129; Thu, 12 Sep 2024 09:17:38 -0700 (PDT) Date: Thu, 12 Sep 2024 09:17:36 -0700 In-Reply-To: <20240912-75f992936cd9878d0e507498@orel> Mime-Version: 1.0 References: <20240911204158.2034295-1-seanjc@google.com> <20240911204158.2034295-5-seanjc@google.com> <20240912-75f992936cd9878d0e507498@orel> Message-ID: Subject: Re: [PATCH v2 04/13] KVM: selftests: Assert that vcpu_{g,s}et_reg() won't truncate From: Sean Christopherson To: Andrew Jones Cc: Marc Zyngier , Oliver Upton , Anup Patel , Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , 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, James Houghton Content-Type: text/plain; charset="us-ascii" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240912_091740_322362_30AA2422 X-CRM114-Status: GOOD ( 20.75 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 12, 2024, Andrew Jones wrote: > On Wed, Sep 11, 2024 at 01:41:49PM GMT, Sean Christopherson wrote: > > 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 > > --- > > 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, ®); > > } > > > > -- > > 2.46.0.598.g6f2099f65c-goog > > > > Reviewed-by: Andrew Jones > > Shouldn't patches 3 and 4 come before patch 2 in this series? Ideally, yes, but for this patch, it gets weird because the output param of vcpu_reg_get() isn't actually restricted to a 64-bit value prior to patch 2. E.g. if this patch were merged without that rework, then the assert would be confusing and arguably flat out wrong. As for the hack-a-fix, I deliberately ordered it after patch 2 so that it would be easier for others to (try to) reproduce the bug. I have no objection to swapping 2 and 3 in the next version.