Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1884428rdb; Tue, 20 Feb 2024 09:43:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUITRNoS5kCSKEFsNqc+NkLMOK3X/liiLuEeC2OI7MVlJ2JVKqVF0glCCEW1QAJvRKOD0bJADul20Al2KxZ7G3Mg9yU7E12ms0pdfNo5A== X-Google-Smtp-Source: AGHT+IHeg7gHqK0vWhC1QxvoYXV36AVHlW4SuS5B1e7ZIchjRjTYQHLI0POVuU1S2LRGGwf/nVqK X-Received: by 2002:a05:6214:4a8a:b0:68f:8927:ac6c with SMTP id pi10-20020a0562144a8a00b0068f8927ac6cmr7766420qvb.20.1708451000324; Tue, 20 Feb 2024 09:43:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708451000; cv=pass; d=google.com; s=arc-20160816; b=iHOBywmpnHRAr81RJMEO6axw3z7rZ9MPqF/CyhGYOC9pBVWHRcsZ8cm/LEW2VeQ9gT hNo0m3Ym7URXtz/UP9Kp+BMc1upiuqrOBCYxXylHVV6+G9YYLlWU4zHJtf5I6FYQJ+DL PBbDYh9r36SDIsqnmy2BxdX+7Vl39zWpy9bfIZw7KoLxKA3m9MtbSvmRquEwKSky02Qj 01gf70inOJpAhdDcaiR/sTZgqg3pW8D7KAd5zVzqU6Et+rciYeZA4zfV/vppXH5outBH g/eSx0neAktaQCY84+mnCqZsszl7pqdu7WqV1rV0BQ872co3u1YcgTJjcN9mFgfiPYr1 cCsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=1WiD5PloTx6/1dWd7HZEu/9GcCBJE7Z8BOQ03vbreAk=; fh=CLKARMnA0MKy/ZMCtmCKuqmOAbfFkXxrGkrh63ojSE4=; b=mS5uJJBkDf6ITqei3ali9TW3kiIT+B+5z7fVPyCYqcl9zTvNgEf3XnTOVNjOpN5tTA nRcwxldHJrtt/v/GRZpFj3pAwz29IJmqa5GbCU4ME/Z/h0PVyONY7ejbV9S2bQGf+Q4s A6zdHkup1hpklKYwqMJeJkyIpNi5+fnflwHpcQQd/7TNQh6rL9T9YAnkvI6EBuFmzXgm xHTMkSMuAcot9QvGJ+zJ7WWcB1HIl7Bc8oe/+Uyffb45sS7oOsz8ae/p15OvZzj8lrax oLeko3sINMcAfvvKl/BVENPg2Awj81RPQudqLOC3N1aTxI28MKkNi90diHVqLNugEYNa pEKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZzUDS+Qz; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-73462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73462-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kl29-20020a056214519d00b0068cd964819asi8838991qvb.392.2024.02.20.09.43.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:43:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZzUDS+Qz; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-73462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73462-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 188B71C221EA for ; Tue, 20 Feb 2024 17:43:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D55427763C; Tue, 20 Feb 2024 17:43:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ZzUDS+Qz" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (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 7BE6477620 for ; Tue, 20 Feb 2024 17:43:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708450992; cv=none; b=MtWF1Ajs1WY7I2etllzA2ZXsrk3uz2rg2AmiOSngq9AC33I+WxZWqzvelrbdjVzDdOoR6MVTW5iFtZPtqEbKkh1VKJP3EhfgtYtL6LjbQNbdAn+iqQVqPzvrLRgDqQ0UzAuviK9Y7e+kuk6hF7kAJbXF+bfrTakVkoDtEvoRKls= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708450992; c=relaxed/simple; bh=dQqVq1NvhO9fM/qzHMx4aJ4MaWXu0/sZ8110Nw6gfMM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UZ0p/iyp3kUbI7sLUxlEj3jCZ1Ou84dl0pqb3NQ2RyS4idawXgtTHh6cqNDDNS1WxntcSOwhdyWAegJch96J/vJ3aL+Wi/s0UDpvO8yvK6JM6YPZ/aAZvAB2rGD56IcwAzOf3qqVJa7MimG9uo7MqmqPTzvBMthRjAxPneDBjZI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ZzUDS+Qz; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Tue, 20 Feb 2024 17:43:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708450987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1WiD5PloTx6/1dWd7HZEu/9GcCBJE7Z8BOQ03vbreAk=; b=ZzUDS+QzCOyCwwlPADraq8THbsI8iPSn4f3zF1MBFS9PBQsNomJoiBKAlrWjj69VKcLkTM 91HY5/klQ7YU9/pmjMBehu617QUXTAWkQ5mpPDKkuE45lCqZf1NgnCTFVY4E0AoChJEue4 VSdQKOK3e6VrmkEq2WC4uTLkvSKcYUo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Marc Zyngier Cc: Zenghui Yu , kvmarm@lists.linux.dev, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Zenghui Yu , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 01/10] KVM: arm64: vgic: Store LPIs in an xarray Message-ID: References: <20240216184153.2714504-1-oliver.upton@linux.dev> <20240216184153.2714504-2-oliver.upton@linux.dev> <86wmqz2gm5.wl-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86wmqz2gm5.wl-maz@kernel.org> X-Migadu-Flow: FLOW_OUT On Tue, Feb 20, 2024 at 05:24:50PM +0000, Marc Zyngier wrote: > On Tue, 20 Feb 2024 16:30:24 +0000, > Zenghui Yu wrote: > > > > On 2024/2/17 02:41, Oliver Upton wrote: > > > Using a linked-list for LPIs is less than ideal as it of course requires > > > iterative searches to find a particular entry. An xarray is a better > > > data structure for this use case, as it provides faster searches and can > > > still handle a potentially sparse range of INTID allocations. > > > > > > Start by storing LPIs in an xarray, punting usage of the xarray to a > > > subsequent change. > > > > > > Signed-off-by: Oliver Upton > > > > [..] > > > > > diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c > > > index db2a95762b1b..c126014f8395 100644 > > > --- a/arch/arm64/kvm/vgic/vgic.c > > > +++ b/arch/arm64/kvm/vgic/vgic.c > > > @@ -131,6 +131,7 @@ void __vgic_put_lpi_locked(struct kvm *kvm, struct vgic_irq *irq) > > > return; > > > list_del(&irq->lpi_list); > > > + xa_erase(&dist->lpi_xa, irq->intid); > > > > We can get here *after* grabbing the vgic_cpu->ap_list_lock (e.g., > > vgic_flush_pending_lpis()/vgic_put_irq()). And as according to vGIC's > > "Locking order", we should disable interrupts before taking the xa_lock > > in xa_erase() and we would otherwise see bad things like deadlock.. > > > > It's not a problem before patch #10, where we drop the lpi_list_lock and > > start taking the xa_lock with interrupts enabled. Consider switching to > > use xa_erase_irq() instead? > > But does it actually work? xa_erase_irq() uses spin_lock_irq(), > followed by spin_unlock_irq(). So if we were already in interrupt > context, we would end-up reenabling interrupts. At least, this should > be the irqsave version. This is what I was planning to do, although I may kick it out to patch 10 to avoid churn. > The question is whether we manipulate LPIs (in the get/put sense) on > the back of an interrupt handler (like we do for the timer). It isn't > obvious to me that it is the case, but I haven't spent much time > staring at this code recently. I think we can get into here both from contexts w/ interrupts disabled or enabled. irqfd_wakeup() expects to be called w/ interrupts disabled. All the more reason to use irqsave() / irqrestore() flavors of all of this, and a reminder to go check all callsites that implicitly take the xa_lock. -- Thanks, Oliver