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 8BBDDEEB580 for ; Thu, 12 Sep 2024 09:42:35 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From: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=aiemgFzmdlVArSRtl/VBHqqgaU54TtFT6LBWQAz3Kr8=; b=kTX5Cy1MrbCxA6LkVHPLQg/SW9 ZBtORUdIE9051fqeFHtd8D9Ua1YuiL/jRJIlV8VbwGndWnCYSzEGDoqSQI0e9CbQryalB6aISQ84Q lcDZgZX/KzyAtTLZPUaegtrU7DRsqlwjrsY3cXAeC/c+aG504rdrphGP1sZ2W49TCd7UQYBHB3Er0 cBkwKPXy8d60rFV9XF5EGB8w0gxq+YTaLQN8t7Z5SdP0ruGKmmEtPGml/SNB7PdprluWygz+3xCSD hVhF6648pIGlRlIPw+VVvrkNHkw2jrG71Mugn9MO+cPuBNT/va6fp7qzYWAHXZfWU28+eKwBPN/kH JQhuSrPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sogLG-0000000Ca4v-1rxd; Thu, 12 Sep 2024 09:42:22 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sogKB-0000000CZrz-1X7Q for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 09:41:16 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-5365a9574b6so1099409e87.1 for ; Thu, 12 Sep 2024 02:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1726134073; x=1726738873; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=aiemgFzmdlVArSRtl/VBHqqgaU54TtFT6LBWQAz3Kr8=; b=pK6KvfYiQb0v5diNbb859rnS+ngFFX1+60sOfxqo881JgPXtQ8Suwho/iJyJ3e3Qc2 iZp9CAFS5J4fs5TC2kW6oxQiuYOi3W3O46qCu2BO+v8uK5zcLAexe4ucHHvpPSMC02fo 8jmXnyiXz+VksYvhZLo1eAM/QS6q/7TDpB+h6TfaEEB+jjImcVqh60XhXMAhmATXNaBs sAYltLcgE3fC0io8f6ZElhSqkBHhVA7rowowwJ8hD5ae/3POEJ+vqLF/DXmt+0pNTUWZ RtWjUq0Im7SigVwpUuE/HjRfBlkzH8lACkeicJhXheBXMziFVIFzAI3nMUJBBuIXFKHB maJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726134073; x=1726738873; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=aiemgFzmdlVArSRtl/VBHqqgaU54TtFT6LBWQAz3Kr8=; b=vorENt0PRGsH7mp7fct4GFe3p3S9RblcAObQsLVHvhPnW07bF8oWnVR7UuCFjatpOi WausEz2yQbb/NcXquYeJ9qpr6Xo2ryok/zBktp65fCkcqiSbpISmO4Y/uBXwkVoOfbaw 9ejIw0WcLqzAG1aQeS1Ef7M0bGCQ87OwQDUGPDXTC0KMCe653QfnU3GfL7dVKBzs87CI 6JYeJ25Py5LKz9dgefK0PaW1APQb8PnIzd3grfCAQv6ghjrUfT2GEMdj7dyFerqTllUH EL4tRlWqf3eweQapwM6as6nvLl8qHhP3Db5FFZmZsKL249IEpuJaSpG3PMx1s5vc9AW/ 2pxQ== X-Forwarded-Encrypted: i=1; AJvYcCU86noBhAQZUsNi4Cr5WDSAKTPKSpfmX2tD3oSrscDppAXjOFTfxD8dOkRsQZtXtCh9rZS+COXam9vi324KZ0tY@lists.infradead.org X-Gm-Message-State: AOJu0Yw5ViMwk+FF6iXVwRNJr8hrB8sTxB/FtDtgVQAf6b66gBqFPnF0 ejVMZQQwqIwk26YRjC0QTAMlq+RmGeBQLhdhNk0biAA3JM2XEPxSwpiEceYqff0= X-Google-Smtp-Source: AGHT+IE8hrIDE8jMWqmlxIeW/6mf22/C3WP/B4LyK9EfIJcAxDLa0UZEL1XXRZvbqP4WfQWiTVCnKg== X-Received: by 2002:a05:6512:31d3:b0:536:5509:8857 with SMTP id 2adb3069b0e04-53678fb7196mr1697881e87.21.1726134072038; Thu, 12 Sep 2024 02:41:12 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72757sm721848266b.103.2024.09.12.02.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 02:41:11 -0700 (PDT) Date: Thu, 12 Sep 2024 11:41:10 +0200 From: Andrew Jones To: Sean Christopherson 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 Subject: Re: [PATCH v2 04/13] KVM: selftests: Assert that vcpu_{g,s}et_reg() won't truncate Message-ID: <20240912-75f992936cd9878d0e507498@orel> References: <20240911204158.2034295-1-seanjc@google.com> <20240911204158.2034295-5-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240911204158.2034295-5-seanjc@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240912_024115_433814_4F6A281E X-CRM114-Status: GOOD ( 17.93 ) 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 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? Thanks, drew