Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6892F16423 for ; Tue, 27 Feb 2024 14:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709044886; cv=none; b=HYWpz9w3tVzhcvBglPv/RQtVzyCxkg5rvGb2ELc0GNGvC1OaOff1AP3OdeVMn9EdFQ2JyDfMzJpM2+KXOg5oqitF8B1LJ/9uvBgIWRhBE8GUMITejsiWLonRldMTDI68F3EjTlJ5jHrqEvpyj6eAY5kCBfHJotzxIxZ6Mq7NX9E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709044886; c=relaxed/simple; bh=MYsw92l+jB195Q/VNlcZ62mYs47pxQnaKyTW6lSbLic=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BW2S26hQx3bN89M+1vVBR7TWs/57kW0kE4emRskMAinQx8su++DxtHvRDKpaa1z4EAQyEhVfkMMHoZrrr/oYBXGfpBuM504KsGkUcPtvP79S6BvZIOrD8FZUwqdaxjT4JnEJzoz2PVpbQRIYgBlNXEJwswfWP4wc4fB3Sz3D4yo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 590BCC433C7; Tue, 27 Feb 2024 14:41:24 +0000 (UTC) Date: Tue, 27 Feb 2024 09:43:26 -0500 From: Steven Rostedt To: David Woodhouse Cc: kvm@vger.kernel.org, Sean Christopherson , Paul Durrant , Paolo Bonzini , Michal Luczaj , Paul Durrant , David Woodhouse , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: Re: [PATCH v2 7/8] KVM: x86/xen: avoid blocking in hardirq context in kvm_xen_set_evtchn_fast() Message-ID: <20240227094326.04fd2b09@gandalf.local.home> In-Reply-To: <20240227115648.3104-8-dwmw2@infradead.org> References: <20240227115648.3104-1-dwmw2@infradead.org> <20240227115648.3104-8-dwmw2@infradead.org> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 27 Feb 2024 11:49:21 +0000 David Woodhouse wrote: > diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c > index c16b6d394d55..d8b5326ecebc 100644 > --- a/arch/x86/kvm/xen.c > +++ b/arch/x86/kvm/xen.c > @@ -1736,9 +1736,23 @@ static int set_shinfo_evtchn_pending(struct kvm_vcpu *vcpu, u32 port) > unsigned long flags; > int rc = -EWOULDBLOCK; > > - read_lock_irqsave(&gpc->lock, flags); > + local_irq_save(flags); > + if (!read_trylock(&gpc->lock)) { Note, directly disabling interrupts in PREEMPT_RT is just as bad as doing so in non RT and the taking a mutex. Worse yet, in PREEMPT_RT read_unlock_irqrestore() isn't going to re-enable interrupts. Not really sure what the best solution is here. -- Steve > + /* > + * When PREEMPT_RT turns locks into mutexes, rwlocks are > + * turned into mutexes and most interrupts are threaded. > + * But timer events may be delivered in hardirq mode due > + * to using HRTIMER_MODE_ABS_HARD. So bail to the slow > + * path if the trylock fails in interrupt context. > + */ > + if (in_interrupt()) > + goto out; > + > + read_lock(&gpc->lock); > + } > + > if (!kvm_gpc_check(gpc, PAGE_SIZE)) > - goto out; > + goto out_unlock; > > if (IS_ENABLED(CONFIG_64BIT) && kvm->arch.xen.long_mode) { > struct shared_info *shinfo = gpc->khva;