From nobody Wed Oct 8 00:42:30 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D8D0F2E3B0F; Thu, 3 Jul 2025 13:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751551085; cv=none; b=uQtd3ECXzudfMh/ofwbymdXd8yhXnPGnfzHHq2glFCxRD6VbXFBwWc0b9I7kiviQ2Mqx6apOag4Z6UqvSn832ImzXR+2X9yEemSIA4o/QV7qa8JjGnitCvC/YHnZlNtctXzSp+LzFp9lHPgf1UVl7DT/P5k17/hpcXhJOq7UC2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751551085; c=relaxed/simple; bh=cqKWaRaRxWF6y8mCDtNPMHZhHWKzACmDdS7NSuDGNlM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eCRzTK8U0AP7yAB1fVW45uEoaef4biwQ6jGvRRwQ1wEoIUiUiQu1jSqC5yDINHvKCdJ78ilEn24N7Ime6zORW0z4Ze73L7HFo8+Y+GqpyhlxpeVyAWNHAjMo7pdyJjSqlP/KnLgbT2Vzksw+56lkuOpL0vzc2qs9lb4qADl+L5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 24F081655; Thu, 3 Jul 2025 06:57:49 -0700 (PDT) Received: from e134344.cambridge.arm.com (e134344.arm.com [10.1.196.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D8D7B3F63F; Thu, 3 Jul 2025 06:58:00 -0700 (PDT) From: Ben Horgan To: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, yury.norov@gmail.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org Cc: james.morse@arm.com, Ben Horgan , stable@vger.kernel.org Subject: [PATCH 1/2] KVM: arm64: Fix enforcement of upper bound on MDCR_EL2.HPMN Date: Thu, 3 Jul 2025 14:57:28 +0100 Message-ID: <20250703135729.1807517-2-ben.horgan@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250703135729.1807517-1-ben.horgan@arm.com> References: <20250703135729.1807517-1-ben.horgan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously, u64_replace_bits() was used to no effect as the return value was ignored. Convert to u64p_replace_bits() so the value is updated in place. Signed-off-by: Ben Horgan Fixes: efff9dd2fee7 ("KVM: arm64: Handle out-of-bound write to MDCR_EL2.HPM= N") Cc: Marc Zyngier Cc: stable@vger.kernel.org Reviewed-by: Zenghui Yu --- arch/arm64/kvm/sys_regs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 76c2f0da821f..c20bd6f21e60 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -2624,7 +2624,7 @@ static bool access_mdcr(struct kvm_vcpu *vcpu, */ if (hpmn > vcpu->kvm->arch.nr_pmu_counters) { hpmn =3D vcpu->kvm->arch.nr_pmu_counters; - u64_replace_bits(val, hpmn, MDCR_EL2_HPMN); + u64p_replace_bits(&val, hpmn, MDCR_EL2_HPMN); } =20 __vcpu_assign_sys_reg(vcpu, MDCR_EL2, val); --=20 2.43.0 From nobody Wed Oct 8 00:42:30 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 113012E7649 for ; Thu, 3 Jul 2025 13:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751551090; cv=none; b=gj90ixnytDhORHHOcoWCqsSUh5IOtoxYw8RbQnHcDbecx1zqLL7Z+w9CY/c8iUZAgP6jvd1sHObZgrq3VNYkcstF7tL132hhd8vOfQe6mh2sDzkMDghCbmoU8ctWq+Hq0Vihj/jmkZdNQ6EJAX67W11f9qforqZwFTf/xY36IvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751551090; c=relaxed/simple; bh=eeopCVKDz3gHN66p6tv950nt1239hOeN8CC37RsxxVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sdGSlG8t1ZzZM9FtUa4atYbPQ9gUcUvrREmeR+XI7zlE+Dg741012oBiNE2Dn2S7RRm/84jwgwcGaoePkCNnT4oaRNO6unLwNpkJIg8BiCTGliX5CAtnKkkLzDPGQkX0IwCW11QBfgbscBneAiCkkqnkBVhCXjkCe/fTeffXWAs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 539CD1596; Thu, 3 Jul 2025 06:57:54 -0700 (PDT) Received: from e134344.cambridge.arm.com (e134344.arm.com [10.1.196.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 32AF13F63F; Thu, 3 Jul 2025 06:58:06 -0700 (PDT) From: Ben Horgan To: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, yury.norov@gmail.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org Cc: james.morse@arm.com, Ben Horgan Subject: [PATCH 2/2] bitfield: Ensure the return value of type##_replace_bits() is checked Date: Thu, 3 Jul 2025 14:57:29 +0100 Message-ID: <20250703135729.1807517-3-ben.horgan@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250703135729.1807517-1-ben.horgan@arm.com> References: <20250703135729.1807517-1-ben.horgan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As type##_replace_bits() has no side effects it is only useful if its return value is checked. Add __must_check to enforce this usage. To have the bits replaced in-place typep##_replace_bits() can be used instead. Signed-off-by: Ben Horgan --- include/linux/bitfield.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 6d9a53db54b6..39333b80d22b 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -195,8 +195,8 @@ static __always_inline __##type type##_encode_bits(base= v, base field) \ __field_overflow(); \ return to((v & field_mask(field)) * field_multiplier(field)); \ } \ -static __always_inline __##type type##_replace_bits(__##type old, \ - base val, base field) \ +static __always_inline __##type __must_check type##_replace_bits(__##type = old, \ + base val, base field) \ { \ return (old & ~to(field)) | type##_encode_bits(val, field); \ } \ --=20 2.43.0