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 A32B0C02187 for ; Thu, 16 Jan 2025 15:11:34 +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:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Subject:Cc:To:From: Message-ID:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zWMvMluQUPZ+9ElDul1fOD8Cr99Y9VpWtLpDJgMStSI=; b=cEGanIyE4qU9bwUxsjXScjFfdl /Y19fNo3Xnwy/S6ntJv4hcvlovUsHKP73GrgQDR8Rdcw/eoTe2oWFY13etPvbwkqVDvaJl24Vpkn8 g9SHqABjG/+IiVN+V/VLiNYfp+Gh6KuRSAizkxgNOhpuwqJ+iV8+o5RnBu4kUA/g/1e+EgeFB1ao4 izAbwhiECyUi/dspEu/+vejKqyOpJi8GwMvkgW/8619rJRBM6t0PoQ45DzugkdnjgxGdH9lWCl8T1 +D/Cw6BbOPJQyA2u8wbmNIhX2bjg9I3k/LPzqz4k3RXjabsUSl7WtNGek4132cyhHduFwUvTKtp1y 4CD0woSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYRWh-0000000FIMc-31ST; Thu, 16 Jan 2025 15:11:19 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tYRVR-0000000FI9f-3JMt for linux-arm-kernel@lists.infradead.org; Thu, 16 Jan 2025 15:10:03 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 946955C5CE8; Thu, 16 Jan 2025 15:09:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05D6BC4CED6; Thu, 16 Jan 2025 15:10:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737040201; bh=L3LKFN888pCcYtXfi2qM4Z727c0oTzkfgjaKEUCtMv4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Cu9mO6noCnsX6IAbFrKrerNkGnSmMXPBnJ1iZVTY1jaco0pl3ntQIwUNnZnh6uPuG znTOS1tt+8zyN3gm144ex4xcCs4dfeI6pyd9nL2OkTvAGyhCQzu1++QY+Xg2t4e07a +ToB1XKf1jo6si4+XiJXFxPAi1kW3n2GWnVpFxlUmSN6eVO+AZAht0mvGZp3DjWeuu /UzkFCzFIVyLR1rfAI8EBNOFQu/7MJzc/FVuspekd5DufguCxOSu/qhbyOH9a1q20a QU3mB/0CcCwo1LYZ5eqDiEG3MznPGbqkc2f0+FtolDRrBBYAsOOUrqwAcyj6xm9uux I9E2DU8IUFnAg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tYRVO-00Cpqo-JN; Thu, 16 Jan 2025 15:09:58 +0000 Date: Thu, 16 Jan 2025 15:09:57 +0000 Message-ID: <861px2x0ai.wl-maz@kernel.org> From: Marc Zyngier To: Uros Bizjak Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon Subject: Re: [PATCH 1/3] KVM: arm64: timers: Fix percpu address space issues in kvm_timer_hyp_init() In-Reply-To: References: <20241213145809.2918-1-ubizjak@gmail.com> <86bjxfsdw0.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: ubizjak@gmail.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org 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-20250116_071001_921082_C247EF1F X-CRM114-Status: GOOD ( 33.73 ) 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 Thu, 16 Jan 2025 14:25:09 +0000, Uros Bizjak wrote: >=20 > On Fri, Dec 13, 2024 at 6:15=E2=80=AFPM Marc Zyngier wro= te: > > > > On Fri, 13 Dec 2024 14:57:52 +0000, > > Uros Bizjak wrote: > > > > > > Cast return value from kvm_get_running_vcpus() in the __percpu > > > address space to the generic address space via uintptr_t [1] > > > to fix a couple of: > > > > > > arch_timer.c:1395:66: warning: incorrect type in argument 2 (differen= t address spaces) > > > arch_timer.c:1395:66: expected void *vcpu_info > > > arch_timer.c:1395:66: got struct kvm_vcpu *[noderef] __percpu * > > > > > > sparse warnings. > > > > > > There were no changes in the resulting object files. > > > > > > [1] https://sparse.docs.kernel.org/en/latest/annotations.html#address= -space-name > > > > > > Signed-off-by: Uros Bizjak > > > Cc: Marc Zyngier > > > Cc: Oliver Upton > > > Cc: Joey Gouly > > > Cc: Suzuki K Poulose > > > Cc: Zenghui Yu > > > Cc: Catalin Marinas > > > Cc: Will Deacon > > > --- > > > arch/arm64/kvm/arch_timer.c | 4 ++-- > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c > > > index 1215df590418..a13bb9e8dc19 100644 > > > --- a/arch/arm64/kvm/arch_timer.c > > > +++ b/arch/arm64/kvm/arch_timer.c > > > @@ -1392,7 +1392,7 @@ int __init kvm_timer_hyp_init(bool has_gic) > > > > > > if (has_gic) { > > > err =3D irq_set_vcpu_affinity(host_vtimer_irq, > > > - kvm_get_running_vcpus()); > > > + (void *)(uintptr_t)kvm_get_= running_vcpus()); > > > if (err) { > > > kvm_err("kvm_arch_timer: error setting vcpu aff= inity\n"); > > > goto out_free_vtimer_irq; > > > @@ -1416,7 +1416,7 @@ int __init kvm_timer_hyp_init(bool has_gic) > > > > > > if (has_gic) { > > > err =3D irq_set_vcpu_affinity(host_ptimer_irq, > > > - kvm_get_running_vcp= us()); > > > + (void *)(uintptr_t)= kvm_get_running_vcpus()); > > > if (err) { > > > kvm_err("kvm_arch_timer: error setting = vcpu affinity\n"); > > > goto out_free_ptimer_irq; > > > > I think the fix is worse than the current code, because there is no > > real semantics behind the pointer being passed to > > irq_set_vcpu_affinity(). All that is required is that it is a non-NULL > > pointer. >=20 > If this is the case, we can just remove dependence on the pointer in > the called function. No, we can't. >=20 > Something like in the attached patch. [...] > diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c > index 1215df590418..10c293c2d2f5 100644 > --- a/arch/arm64/kvm/arch_timer.c > +++ b/arch/arm64/kvm/arch_timer.c > @@ -1238,12 +1238,10 @@ void kvm_arm_timer_write_sysreg(struct kvm_vcpu *= vcpu, > } > } > =20 > -static int timer_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu) > +static int timer_irq_set_vcpu_affinity(struct irq_data *d, > + void __always_unused *vcpu) > { > - if (vcpu) > - irqd_set_forwarded_to_vcpu(d); > - else > - irqd_clr_forwarded_to_vcpu(d); > + irqd_set_forwarded_to_vcpu(d); > =20 > return 0; > } > @@ -1391,8 +1389,7 @@ int __init kvm_timer_hyp_init(bool has_gic) > } > =20 > if (has_gic) { > - err =3D irq_set_vcpu_affinity(host_vtimer_irq, > - kvm_get_running_vcpus()); > + err =3D irq_set_vcpu_affinity(host_vtimer_irq, NULL); > if (err) { > kvm_err("kvm_arch_timer: error setting vcpu affinity\n"); > goto out_free_vtimer_irq; > @@ -1415,8 +1412,7 @@ int __init kvm_timer_hyp_init(bool has_gic) > } > =20 > if (has_gic) { > - err =3D irq_set_vcpu_affinity(host_ptimer_irq, > - kvm_get_running_vcpus()); > + err =3D irq_set_vcpu_affinity(host_ptimer_irq, NULL); And now you breaking everything by ignoring the semantics of irq_set_vcpu_affinity(), which uses a NULL pointer to *stop* the forwarding. Congratulations, KVM doesn't work anymore, except on systems such as the Apple stuff (which are the only systems requiring the timer_irq_set_vcpu_affinity() hack). Just look at what the irqchips are implementing to convince yourself. M. --=20 Without deviation from the norm, progress is not possible.