From patchwork Thu May 2 15:42:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13651837 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 4C248C4345F for ; Thu, 2 May 2024 15:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=kkPlwXPeaeGwuaaKZPFYki8uOIQPzBymhdrfCUUpNoc=; b=coXb/qArQ2t1zh cO/rVRmT/i+IKyQwLyylZHIRVrxNLkoLxNlhNh5WLtPyQf6l9P5fLojjPQtJtRRjxR+qvy4KsjsKy VyEppXPvUMNny/fj6yA2YeqEKjd9c6umI5cnJLJioirybHCIq9oxzCOGYyCpML7s74At4yliQUq88 KIhYDEwaX3WEwqjWvc43ypSY/SSqswluVPNrqv4VyxttkXeIQfqGyd2j4VKrYoQ/hOj4KIa1NBqUu HaOUoPpaUBL430wG/qJZT1t+/4MS2703Wla2t35uDB0tNsSBxmyF0Axfsc4RGEzYa7+bAAolQ+RLX QH6tcoH8clcmJyr09X1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2YaJ-0000000DA6T-1wcw; Thu, 02 May 2024 15:42:59 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2YaH-0000000DA5P-0Es7 for linux-arm-kernel@lists.infradead.org; Thu, 02 May 2024 15:42:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 8154ECE174E; Thu, 2 May 2024 15:42:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59033C113CC; Thu, 2 May 2024 15:42:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714664573; bh=5eBUBmndAeMIzU7wiDmFwOIDIxcvQl+iymkpM5oAR3s=; h=From:To:Cc:Subject:Date:From; b=YAmkZP57/0kGevam+PC9104D2BNGobDFZ8Cfv56oz11o696OkPqCKQWRoQtfsOhWs DNaDPyAm2EpXpMyS+UqaoIkYFbLwmAW7CDXl/yksGZ67C1x1lINGrY4CL4P+GZmaBl p1js6etzAgeRI2ZRw78fjr314MpwEupgdmLpHPhvjaGMPXA8MruLPloXMWG6KLQ01w EoCjiMQbmT1a9dhp2VypHXRwbP++Kn00KbenuI9cJ9ybedVVrvkB6RfQh7h8l6mexj IvlbHfHiOWYNI8FyE/26huBJ05FGM/RXs1WDkLQXVKhm1EnBVWWUwUgdzmhXP0btQd e8YF+pivrtq9Q== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1s2YaB-00A2mi-3W; Thu, 02 May 2024 16:42:51 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: [PATCH] KVM: arm64: Convert kvm_mpidr_index() to bitmap_gather() Date: Thu, 2 May 2024 16:42:47 +0100 Message-Id: <20240502154247.3012042-1-maz@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240502_084257_375812_DA6844E1 X-CRM114-Status: GOOD ( 12.02 ) 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 Linux 6.9 has introduced new bitmap manipulation helpers, with bitmap_gather() being of special interest, as it does exactly what kvm_mpidr_index() is already doing. Make the latter a wrapper around the former. Signed-off-by: Marc Zyngier Reviewed-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 23a117cb3e50..fe94e96dced8 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -221,20 +221,10 @@ struct kvm_mpidr_data { static inline u16 kvm_mpidr_index(struct kvm_mpidr_data *data, u64 mpidr) { - unsigned long mask = data->mpidr_mask; - u64 aff = mpidr & MPIDR_HWID_BITMASK; - int nbits, bit, bit_idx = 0; - u16 index = 0; + unsigned long index = 0, mask = data->mpidr_mask; + unsigned long aff = mpidr & MPIDR_HWID_BITMASK; - /* - * If this looks like RISC-V's BEXT or x86's PEXT - * instructions, it isn't by accident. - */ - nbits = fls(mask); - for_each_set_bit(bit, &mask, nbits) { - index |= (aff & BIT(bit)) >> (bit - bit_idx); - bit_idx++; - } + bitmap_gather(&index, &aff, &mask, fls(mask)); return index; }