Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp173518lqo; Tue, 7 May 2024 16:38:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwFza+C6OTzv83B02jQ/zAn4FEqGj37raT8pbamlYlFpXAnt6oCE4UDMj3U0vAADRsYKLLERKAIG6bZr754yCQkC6vSiOkdn06+uoiwA== X-Google-Smtp-Source: AGHT+IH0qM/VcoMvXnvHYp0/eJH7u9bad/mXLmE2UTWkBaILRsIo8MWhthfixu8hcXuC9Ntk9QUF X-Received: by 2002:a17:902:e744:b0:1eb:7ba:a4bc with SMTP id d9443c01a7336-1eeb099ffb8mr13881175ad.51.1715125110471; Tue, 07 May 2024 16:38:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715125110; cv=pass; d=google.com; s=arc-20160816; b=APD7VIB9C1IWTjHBlfNWLacUYmUSJmNQrOBMw1hbz+f4m7ATgG/hNiVQPcJ75r3nCX Lmc+NEzABxBsbqMbkF1gexk2vx/Zkb9AB69ELwbvLiHf1uqk9DfeS5d7Umb6K87SXVeQ 4FlKwUqOk7xInGKhgCeeZSpKGq/8osgKhm3QjJVNqfEbHnmm41r3tVOPyJhFOxigvyzC sL5VaVuO3VXq1wNR6cxGeT4AeQ4Cad1JucAj0XlLy4Fomo5QiYhFBJtQ2vAaSKPWX7BB 1YEAuuPVt/AfymlEfxLijtCCIx+t2G1pFBKdIWCzOWOAOUKFL/09IfivdZaGGEuaGxl7 vvoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JNL0+BxEIQX0ijgd/JEiX4MoeV9f5zLqNxpN+on+bas=; fh=hY/SEVnsWR2C9ATpZ2J5omXiHOAAgZiJu1W4M5iCacY=; b=ttts32Wp+YyR/sjk04GuCzrSTm+XH8vz0UQPt8EuLuSHhjY0J0BQflRE9PKDNPKHrx gOTYKs4Jpz9nt+p5nnAftwMa3XcclqZSQ5qNQGIAxa1sk5mz8MHTnvd2SWei9OrdAIgY GDCD+WzCnWj3wnhLMMzZ2lX2oBEEfYn864NqPaQuCzT6sb47Kl26STir5hl+h0EzEu2a pH1pmBU8xQBdRqt4OaYsdk1APYFzkHreUgvUWBv860DwL6mVAtPpBajvbU7VYw9jJ/Zx NvlC0QRPPTab9K6ayTzV3UawDn0YJyRqAagWar3C9WgdmetentQz51TTEKQ+dX06GlUl GdPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qc+rKPV8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172410-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172410-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f17-20020a170902ce9100b001ec7c4261b9si9206223plg.179.2024.05.07.16.38.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 16:38:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172410-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qc+rKPV8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172410-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172410-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1CB7628332C for ; Tue, 7 May 2024 23:38:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB86114A4FB; Tue, 7 May 2024 23:11:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qc+rKPV8" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7BB7137746; Tue, 7 May 2024 23:11:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715123461; cv=none; b=eSYtUJIVW49A4mmc3zMv3RPlfH5nag1bB5puy8eOWgRu7gSDoJjw4DyY++80Wxnpql9q0XHKzCLovjDX4l9+KVM5+wrf6dc6aLIN8skaHyfrYTA2i0Obdosg9AWeRc8CKzhKLAyUR6rpgnylSdaGy+cklqxKq0+DOxOXj02o620= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715123461; c=relaxed/simple; bh=XdZxsoASaO5IpIo4VCvpiibSkBtatqEOIr6SGp02oOY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OEftpGk+lXuUwLF0S+yOTATUxHWr8M0BOMZ7ewmrEyI403Ax00Nz9xdRdzxyNYNio6KCYloe8IA6C1wBr2xwySRa8G9cQtP+I2+Q9hYG+7eaDzH5OLNxQw8JKazBP633o1jiR8XGvMU16U/8exIFSr5SCB1uOe6kJt/xbBZuNYU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qc+rKPV8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CCF7C3277B; Tue, 7 May 2024 23:10:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715123460; bh=XdZxsoASaO5IpIo4VCvpiibSkBtatqEOIr6SGp02oOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qc+rKPV8hknaPxiJQDUoNANTgJMCDq3AudkjQ553yJOMzeIpo/KjV7x5g04bwv2W1 S5ttBZkqLallG6yClosavBPf1ZaO/p9tFRe4/g5KmStLmJCmGApy4HAdDPaa5Pfqdz mAN50uMgO6WV+7EQil6lAo9R6SQdkE7sKpnPN2SZJwRNp+79+8vrJlviCvRP7ReesC N+akT5QRdPTagqSo9TIhDisDjhHrNKRzRkKw7ZkgmC7zdzs8Naw1xCLpgYJYRiJAL/ k/cgCpERk44slwoutnqR2Oo8M9B6J9xbZayI+sv2Ce5xGNgvFGonN/EkjNbh+l7D0T b7WNgtIDWa7gA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Oliver Upton , Marc Zyngier , Sasha Levin , pbonzini@redhat.com, shuah@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 15/43] KVM: selftests: Add test for uaccesses to non-existent vgic-v2 CPUIF Date: Tue, 7 May 2024 19:09:36 -0400 Message-ID: <20240507231033.393285-15-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240507231033.393285-1-sashal@kernel.org> References: <20240507231033.393285-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.30 Content-Transfer-Encoding: 8bit From: Oliver Upton [ Upstream commit 160933e330f4c5a13931d725a4d952a4b9aefa71 ] Assert that accesses to a non-existent vgic-v2 CPU interface consistently fail across the various KVM device attr ioctls. This also serves as a regression test for a bug wherein KVM hits a NULL dereference when the CPUID specified in the ioctl is invalid. Note that there is no need to print the observed errno, as TEST_ASSERT() will take care of it. Reviewed-by: Marc Zyngier Link: https://lore.kernel.org/r/20240424173959.3776798-3-oliver.upton@linux.dev Signed-off-by: Oliver Upton Signed-off-by: Sasha Levin --- .../testing/selftests/kvm/aarch64/vgic_init.c | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/testing/selftests/kvm/aarch64/vgic_init.c b/tools/testing/selftests/kvm/aarch64/vgic_init.c index eef816b80993f..ca917c71ff602 100644 --- a/tools/testing/selftests/kvm/aarch64/vgic_init.c +++ b/tools/testing/selftests/kvm/aarch64/vgic_init.c @@ -84,6 +84,18 @@ static struct vm_gic vm_gic_create_with_vcpus(uint32_t gic_dev_type, return v; } +static struct vm_gic vm_gic_create_barebones(uint32_t gic_dev_type) +{ + struct vm_gic v; + + v.gic_dev_type = gic_dev_type; + v.vm = vm_create_barebones(); + v.gic_fd = kvm_create_device(v.vm, gic_dev_type); + + return v; +} + + static void vm_gic_destroy(struct vm_gic *v) { close(v->gic_fd); @@ -357,6 +369,40 @@ static void test_vcpus_then_vgic(uint32_t gic_dev_type) vm_gic_destroy(&v); } +#define KVM_VGIC_V2_ATTR(offset, cpu) \ + (FIELD_PREP(KVM_DEV_ARM_VGIC_OFFSET_MASK, offset) | \ + FIELD_PREP(KVM_DEV_ARM_VGIC_CPUID_MASK, cpu)) + +#define GIC_CPU_CTRL 0x00 + +static void test_v2_uaccess_cpuif_no_vcpus(void) +{ + struct vm_gic v; + u64 val = 0; + int ret; + + v = vm_gic_create_barebones(KVM_DEV_TYPE_ARM_VGIC_V2); + subtest_dist_rdist(&v); + + ret = __kvm_has_device_attr(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CPU_REGS, + KVM_VGIC_V2_ATTR(GIC_CPU_CTRL, 0)); + TEST_ASSERT(ret && errno == EINVAL, + "accessed non-existent CPU interface, want errno: %i", + EINVAL); + ret = __kvm_device_attr_get(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CPU_REGS, + KVM_VGIC_V2_ATTR(GIC_CPU_CTRL, 0), &val); + TEST_ASSERT(ret && errno == EINVAL, + "accessed non-existent CPU interface, want errno: %i", + EINVAL); + ret = __kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CPU_REGS, + KVM_VGIC_V2_ATTR(GIC_CPU_CTRL, 0), &val); + TEST_ASSERT(ret && errno == EINVAL, + "accessed non-existent CPU interface, want errno: %i", + EINVAL); + + vm_gic_destroy(&v); +} + static void test_v3_new_redist_regions(void) { struct kvm_vcpu *vcpus[NR_VCPUS]; @@ -675,6 +721,9 @@ void run_tests(uint32_t gic_dev_type) test_vcpus_then_vgic(gic_dev_type); test_vgic_then_vcpus(gic_dev_type); + if (VGIC_DEV_IS_V2(gic_dev_type)) + test_v2_uaccess_cpuif_no_vcpus(); + if (VGIC_DEV_IS_V3(gic_dev_type)) { test_v3_new_redist_regions(); test_v3_typer_accesses(); -- 2.43.0