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 16831C6FD1D for ; Thu, 30 Mar 2023 10:20:14 +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: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=ZaVojbrSV4fnoLys9HZ5ZeL8sc3MqD+fKGFh+8SOtT8=; b=SQ7KSGZR2VC/z5 Hjcve0Q639MJU+EfZbKSmjOqqXbcUYn1RoZdVDwxf5ZzG20PqI0N+KQgvLNBsH6puzAv2xtgmAdZ6 UDwEZ27m9xmVTFfMmBNlPAAitEfwEIVSLcXzJadZLohrIzDR3NBoIg8sWsR0L6QGjRwqgw/hm8fwv 7ogRK7kDSqrl0uoIn93jQkGlf2BIUXRgBrCDXDeycwrvZMOgH2sI2a0q+Wo8YkSeZ5Ug3WzRNE7bA YlqHxyVpSGhCAS1X0n0a37YpVSQ+eIXLiO7s3WXL23Oqa20bHujiS/xbUV4KDrqaQ8fUH33oiUbq+ fluz675nY170fTFfJr0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phpNM-003RgL-2s; Thu, 30 Mar 2023 10:19:24 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1phpNI-003Rf0-2F for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2023 10:19:22 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D3429B82586; Thu, 30 Mar 2023 10:19:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87350C433D2; Thu, 30 Mar 2023 10:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680171557; bh=CMp2kdl18Tf8LPjUAO8ppft0LA+7nCX3ctxuW1Ll+48=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qRG71vlHK4iDGxPKLo/GpAGBGIQY8BxqFNGQcT9cc0Cn6tk9Y/G3QSPt6si/7xoUD jq5MWjvgi4nLe7tbdTOYqIH4aT+LamdP6B19a9Uh30PW9xvhD5svbjGkwswur3Iq2J j12/6TZ7H+Gmh+TyZySrXJkj3VCkVv6bpArOsnjJp1WG+DAYzk7X4RAlOzai/S6J4b F5Kqw+NCahFPGJJEAQ8qT0+H5LyDStBhWuCXJuHRyDRv+i3YWGK6GslAODS2/PXnQx woSwb5gXNzsv5KVnJQ/hfnXXB7pVlASOjXPoWEBpOlZyaSWBr646ZhOMH+vBRctnMZ KTr/VDB0biraw== 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 1phpND-004KQm-Aq; Thu, 30 Mar 2023 11:19:15 +0100 Date: Thu, 30 Mar 2023 11:19:14 +0100 Message-ID: <86edp6wnh9.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Zenghui Yu , Ricardo Koller , Simon Veith , Reiji Watanabe , Colton Lewis , Joey Gouly , dwmw2@infradead.org Subject: Re: [PATCH v3 11/18] KVM: arm64: timers: Move the timer IRQs into arch_timer_vm_data In-Reply-To: References: <20230324144704.4193635-1-maz@kernel.org> <20230324144704.4193635-12-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/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: oliver.upton@linux.dev, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, ricarkol@google.com, sveith@amazon.de, reijiw@google.com, coltonlewis@google.com, joey.gouly@arm.com, dwmw2@infradead.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-20230330_031921_056521_5325BC2D X-CRM114-Status: GOOD ( 34.23 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 30 Mar 2023 08:02:13 +0100, Oliver Upton wrote: > > On Fri, Mar 24, 2023 at 02:46:57PM +0000, Marc Zyngier wrote: > > Having the timer IRQs duplicated into each vcpu isn't great, and > > becomes absolutely awful with NV. So let's move these into > > the per-VM arch_timer_vm_data structure. > > > > This simplifies a lot of code, but requires us to introduce a > > mutex so that we can reason about userspace trying to change > > an interrupt number while another vcpu is running, something > > that wasn't really well handled so far. > > > > Reviewed-by: Colton Lewis > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/include/asm/kvm_host.h | 2 + > > arch/arm64/kvm/arch_timer.c | 104 +++++++++++++++++------------- > > arch/arm64/kvm/arm.c | 2 + > > include/kvm/arm_arch_timer.h | 18 ++++-- > > 4 files changed, 78 insertions(+), 48 deletions(-) > > > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > > index 116233a390e9..1280154c9ef3 100644 > > --- a/arch/arm64/include/asm/kvm_host.h > > +++ b/arch/arm64/include/asm/kvm_host.h > > @@ -223,6 +223,8 @@ struct kvm_arch { > > #define KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED 5 > > /* VM counter offset */ > > #define KVM_ARCH_FLAG_VM_COUNTER_OFFSET 6 > > + /* Timer PPIs made immutable */ > > +#define KVM_ARCH_FLAG_TIMER_PPIS_IMMUTABLE 7 > > > > unsigned long flags; > > > > diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c > > index 7cd0b0947454..88a38d45d352 100644 > > --- a/arch/arm64/kvm/arch_timer.c > > +++ b/arch/arm64/kvm/arch_timer.c > > @@ -851,7 +851,6 @@ static void timer_context_init(struct kvm_vcpu *vcpu, int timerid) > > > > hrtimer_init(&ctxt->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); > > ctxt->hrtimer.function = kvm_hrtimer_expire; > > - timer_irq(ctxt) = default_ppi[timerid]; > > > > switch (timerid) { > > case TIMER_PTIMER: > > @@ -880,6 +879,13 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) > > timer->bg_timer.function = kvm_bg_timer_expire; > > } > > > > +void kvm_timer_init_vm(struct kvm *kvm) > > +{ > > + mutex_init(&kvm->arch.timer_data.lock); > > + for (int i = 0; i < NR_KVM_TIMERS; i++) > > + kvm->arch.timer_data.ppi[i] = default_ppi[i]; > > +} > > + > > void kvm_timer_cpu_up(void) > > { > > enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags); > > @@ -1292,44 +1298,52 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) > > > > static bool timer_irqs_are_valid(struct kvm_vcpu *vcpu) > > { > > - int vtimer_irq, ptimer_irq, ret; > > - unsigned long i; > > + u32 ppis = 0; > > > > - vtimer_irq = timer_irq(vcpu_vtimer(vcpu)); > > - ret = kvm_vgic_set_owner(vcpu, vtimer_irq, vcpu_vtimer(vcpu)); > > - if (ret) > > - return false; > > + mutex_lock(&vcpu->kvm->arch.timer_data.lock); > > > > - ptimer_irq = timer_irq(vcpu_ptimer(vcpu)); > > - ret = kvm_vgic_set_owner(vcpu, ptimer_irq, vcpu_ptimer(vcpu)); > > - if (ret) > > - return false; > > + for (int i = 0; i < NR_KVM_TIMERS; i++) { > > + struct arch_timer_context *ctx; > > + int irq; > > > > - kvm_for_each_vcpu(i, vcpu, vcpu->kvm) { > > - if (timer_irq(vcpu_vtimer(vcpu)) != vtimer_irq || > > - timer_irq(vcpu_ptimer(vcpu)) != ptimer_irq) > > - return false; > > + ctx = vcpu_get_timer(vcpu, i); > > + irq = timer_irq(ctx); > > + if (kvm_vgic_set_owner(vcpu, irq, ctx)) > > + break; > > + > > + /* > > + * We know by construction that we only have PPIs, so > > + * all values are less than 32. > > + */ > > + ppis |= BIT(irq); > > } > > > > - return true; > > + set_bit(KVM_ARCH_FLAG_TIMER_PPIS_IMMUTABLE, &vcpu->kvm->arch.flags); > > + > > + mutex_unlock(&vcpu->kvm->arch.timer_data.lock); > > + > > + return hweight32(ppis) == NR_KVM_TIMERS; > > Does it make sense to only set the IMMUTABLE flag if the timer IRQs are > indeed valid? I doubt userspace would do anything when it gets the > EINVAL, but it is possible userspace could make another attempt at > configuring the IRQs correctly. Yup, that's fair enough. I'll flip things around. Thanks! M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel