From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24DE83A5453 for ; Fri, 12 Jun 2026 06:59:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781247573; cv=none; b=qU5Sne7XcUq3DahtCFb56vB3RGietARHvUN4o1jou3eqTRvENyuqxFabCjIFd2u53ZMlayf4XFmqcw1i3fnxvp3szmpL41q6EK2qXiKyALKepqzTWoy0OBbCgs9Xj2zBfN0mnM3Egdy6UvnvA3sWYz2r2coJiKrznco5LhUJ1sg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781247573; c=relaxed/simple; bh=oUndi4kwUXoWg5lumryXFXpNAfQ0A0QlqigFUa6sS3w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mcPeUfQwHgADcaEyh2pjlCu1ODykqOwxuz49+gwvAsET2s/ED6FxGoJkHiuK2Z7L5SON2zzR1RJ/zoSciDFMa/9RFdktIh8nnKUvFyEGcFxHpOoJGpmIrsZPFLr76F4VctEXneWIh6bsg3d7E0Jhg2g7bvD63ByFfvXwyRt0+/o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tabba.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ENFfM0GS; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tabba.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ENFfM0GS" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-490b2f22ea2so5631225e9.1 for ; Thu, 11 Jun 2026 23:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781247571; x=1781852371; darn=vger.kernel.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=m6lByUAON2kwH/WVx8s6LHD92Bsz3VHXajDWnpZfQxc=; b=ENFfM0GSl7kD9BW/r87FMg03/Wr5Hfeugf48L0voh/CpfXIL67NfiHnAKA/nVPPy8b OzNd/E6lZP5J9tx+79NjT0WUZU32SPkQXjw1lz8Wua0HTY2e+BMRce3Il6A9uXcMxhPY U9IrtMn81kl0+P6xuJojcTnJFkI96g1idqjkbv+pmo+nThIlaOVyJWVftQSx1QrwdJ1u bJq2+lb9s7ICdl6nxVLOo6L/x0pXHRYMmSlUXWBGHat9iLq6UeUFhD0yenYXF/JFcXFX YN8OkhO1jbsoMcWI0e96VYTmAb3cNSMrtv+tjFqO1Ptvkr2fVfb+51U9TDEOzBxvNKMJ tOZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781247571; x=1781852371; 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=m6lByUAON2kwH/WVx8s6LHD92Bsz3VHXajDWnpZfQxc=; b=BBZnsT1zAxnBbaeUIG0e1LIIKrMq1Lk4vPpRd3qozvCOe1Tc/D9UIEvEuxbPtsFCtw yDFEBvlFJMM30nN+ycoZHyMqjVebJbsOT2d6r8CGstxv+4EfdmyR7bSB9lKF7LwapHeH 820HOZ1DEksWEzz1gBbTWVd+b/dR8esoxPaCodVCSLcszH4phgxPhJel0Kok9DqzBDwt Jy6Ji8RWFK77pY/tqVNxQpxR4n51kgy5drodELWj8Cw2CAeZv6tl2epUJFoynHi1dmUc QszeCcrRwo8Xj/+kW3ANws/NqKz0sbpyPocpz3CI9VyovIxqqJg1ShCRyJOJXMFXocFh WqHQ== X-Forwarded-Encrypted: i=1; AFNElJ9BuKfpup0xcrZLdI+FB3d4P+dK5cLDLWaC0LEGhqrLZ4w8T74W//uhErIQhVQegZg5/DCo8KdZxWcAAhQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0iRdBVXPJkMfT06+10MSKdUB1D/Y9/ge4H602789vwAGnDPfa iPU/cM40Vz9WqmVogtfOSIJuJkHHqmRBBuW0pYkY++HK7jreSd1xSXZ7syBAU3TmeLhOw/8Os1R OPw== X-Received: from wmoo1.prod.google.com ([2002:a05:600d:101:b0:490:b195:62b3]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:8012:b0:490:b9d3:a9ce with SMTP id 5b1f17b1804b1-490ec5047d3mr16382375e9.30.1781247570557; Thu, 11 Jun 2026 23:59:30 -0700 (PDT) Date: Fri, 12 Jun 2026 07:59:18 +0100 In-Reply-To: <20260612065925.755562-1-tabba@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260612065925.755562-1-tabba@google.com> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog Message-ID: <20260612065925.755562-5-tabba@google.com> Subject: [PATCH v1 04/11] KVM: arm64: Extract MPIDR computation into a shared header From: tabba@google.com To: Marc Zyngier , Oliver Upton Cc: Fuad Tabba , Will Deacon , Catalin Marinas , Quentin Perret , Vincent Donnefort , Sebastian Ene , Per Larsen , Suzuki K Poulose , Zenghui Yu , Joey Gouly , Steffen Eiden , Mark Rutland , Jonathan Cameron , Hyunwoo Kim , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Extract the vCPU MPIDR computation embedded in reset_mpidr() into a kvm_calculate_mpidr() inline in sys_regs.h, so it can be computed without duplicating the logic. A follow-up series reuses it to reset protected vCPUs at EL2. No functional change intended. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/sys_regs.c | 14 +------------- arch/arm64/kvm/sys_regs.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index fa5c93c7a135..869a4bac96d6 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -979,21 +979,9 @@ static u64 reset_actlr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) static u64 reset_mpidr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) { - u64 mpidr; + u64 mpidr = kvm_calculate_mpidr(vcpu); - /* - * Map the vcpu_id into the first three affinity level fields of - * the MPIDR. We limit the number of VCPUs in level 0 due to a - * limitation to 16 CPUs in that level in the ICC_SGIxR registers - * of the GICv3 to be able to address each CPU directly when - * sending IPIs. - */ - mpidr = (vcpu->vcpu_id & 0x0f) << MPIDR_LEVEL_SHIFT(0); - mpidr |= ((vcpu->vcpu_id >> 4) & 0xff) << MPIDR_LEVEL_SHIFT(1); - mpidr |= ((vcpu->vcpu_id >> 12) & 0xff) << MPIDR_LEVEL_SHIFT(2); - mpidr |= (1ULL << 31); vcpu_write_sys_reg(vcpu, mpidr, MPIDR_EL1); - return mpidr; } diff --git a/arch/arm64/kvm/sys_regs.h b/arch/arm64/kvm/sys_regs.h index 2a983664220c..bd56a45abbf9 100644 --- a/arch/arm64/kvm/sys_regs.h +++ b/arch/arm64/kvm/sys_regs.h @@ -222,6 +222,25 @@ find_reg(const struct sys_reg_params *params, const struct sys_reg_desc table[], return __inline_bsearch((void *)pval, table, num, sizeof(table[0]), match_sys_reg); } +static inline u64 kvm_calculate_mpidr(const struct kvm_vcpu *vcpu) +{ + u64 mpidr; + + /* + * Map the vcpu_id into the first three affinity level fields of + * the MPIDR. We limit the number of VCPUs in level 0 due to a + * limitation to 16 CPUs in that level in the ICC_SGIxR registers + * of the GICv3 to be able to address each CPU directly when + * sending IPIs. + */ + mpidr = (vcpu->vcpu_id & 0x0f) << MPIDR_LEVEL_SHIFT(0); + mpidr |= ((vcpu->vcpu_id >> 4) & 0xff) << MPIDR_LEVEL_SHIFT(1); + mpidr |= ((vcpu->vcpu_id >> 12) & 0xff) << MPIDR_LEVEL_SHIFT(2); + mpidr |= (1ULL << 31); + + return mpidr; +} + const struct sys_reg_desc *get_reg_by_id(u64 id, const struct sys_reg_desc table[], unsigned int num); -- 2.54.0.1136.gdb2ca164c4-goog