From patchwork Tue Feb 13 09:32:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 200285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp423651dyb; Tue, 13 Feb 2024 01:34:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkp2BSk7Js6982un7hOKg1yTvfaIGTDr/yT7EJa73bYXD7C1SrbQsetuONt/Y8iQvu/Yyv X-Received: by 2002:a05:6402:797:b0:561:e4aa:ef2c with SMTP id d23-20020a056402079700b00561e4aaef2cmr1665019edy.32.1707816873212; Tue, 13 Feb 2024 01:34:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707816873; cv=pass; d=google.com; s=arc-20160816; b=oEAtdGnNeYdi/4SaEA3t4kN+ESVFbpNvIC8Zagsw9cyKlgGWPt45db5rZlmeHrN0i0 l+vGKTUsRNpT7FmwtcPDXVrvEEoBOx1MssSwzzws7PW5p3FEmmA89/kwsQ+6lsh1aHui X6GobHG3c2bKXm9A8oPA3E2UVfivLvaQMWEOGnX0s8eaQm08+yxzUoJ3vQhCIpR6QoWC pGkDz3WwWwPCCQdO5/2rgv9eqal0Te5NPNLAVZvu/ZKO0Lta+iIqU1d1XlnZLaXsgh23 stW46RyaFE1tocfhLEX5O/GgrrsvrJ5j2iI7+2SY9W2zRV222poAbCi1nPX5MsT6IBk7 mtxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fnPoXibpf2eubnu4qas8Q67UZMLIaNGzfiD65c36g0Y=; fh=9qsDl80Ah6hGGVcyRYMeGASCZsA3ANHxoWkqy6EnK2Y=; b=RihQppPU3diM1GK9smivUSlMHK+J09TAqC6firxG1/yLTjddxhfrc5Pz8UNMD07/ad kBwIDtyoChSzIHbOgA/bkEG1V8aJ1JS2GCXwWUiEWnofJPhwSytZk9BHjJRbz4biR5DN PY2p3p89nvgE0H0D+u1SrwV6aMF4jk16/QGiqrPoQlQViHtu00fuBuufOxa2tqElWo1h xJAL9fv8JPOL//vsG1iTAqnyc4GXKx2V4FCdivxcwoEqsigIOymoL4K9+uda6TdShwNq cwRqF8h5MgRru0SYJi0EUS9IEuF4AFIO9V6f3kIa22KU68iZ6/1yBYgc8O0oa1LRrfgL dORQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vaKssv7Z; 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-63207-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63207-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCVmCL9ptBFF6DUNfE5F4BtjIlSiK/5kGXN4cDzFWhW60ENPLe1UiDxJFQ/tWXbj4xPSbJa7EDjrqQo46pyru2pBYij9Bg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m22-20020aa7d356000000b00560027fbed5si3648528edr.619.2024.02.13.01.34.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:34:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63207-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vaKssv7Z; 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-63207-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63207-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id D12451F2523E for ; Tue, 13 Feb 2024 09:34:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B845286AD; Tue, 13 Feb 2024 09:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="vaKssv7Z" Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) (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 C72F422334 for ; Tue, 13 Feb 2024 09:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707816800; cv=none; b=usveOC/Cr/uy0PS9/Ldjyl89FJgbtVSMfOENv5rNzIWdK1q7zpNUeeVEjXKvxCUcZRsNcjxkmQh1Yb+DYmGhilJJT2i/uAdESqIOo+uIjnLhWDSB4XE1Y1j+oTLyRqTjGZiYuZD+TyvZmdOvY0npEuUfo1UYi7oz2ndVIZQIar8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707816800; c=relaxed/simple; bh=H7EPwNAHhjpAAN+1sCd20hc3wyAtZ3lgAHFoSyw3Q5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dd9PE2ExHZAiAui1Cx+h8fgqqKHoCqlS6mwlm68ATJu9n01/elOhXUe5WSTo1MQmF7wk4LnSrvtR1ztvgURNhQs5ANZP3iQ0hpGlUaQv+V1YuK19FmeMRRapxvRVTzOtlmQVIspz/T26NMHui4FdxoXxfXuwNEs5X4sQidLx1MA= 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=vaKssv7Z; arc=none smtp.client-ip=95.215.58.175 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 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707816796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fnPoXibpf2eubnu4qas8Q67UZMLIaNGzfiD65c36g0Y=; b=vaKssv7ZX0b92LyxSE2pWJosQl7s9miduOitoV/mhpSghGsXb9f3a1INqHUg7rWIm7QU0+ pAWzKGNYijFdtUoxI/hac1dBCqgGANwd3LvAv72hBapQ435bqhAwQNAB+mpCNs1wRmuezW y3dxjGfE0Qf/iJWDD1ynrlLkHHYxdrs= From: Oliver Upton To: kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , linux-kernel@vger.kernel.org, Oliver Upton Subject: [PATCH v2 02/23] KVM: arm64: vgic: Store LPIs in an xarray Date: Tue, 13 Feb 2024 09:32:39 +0000 Message-ID: <20240213093250.3960069-3-oliver.upton@linux.dev> In-Reply-To: <20240213093250.3960069-1-oliver.upton@linux.dev> References: <20240213093250.3960069-1-oliver.upton@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790775785901624392 X-GMAIL-MSGID: 1790775785901624392 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 --- arch/arm64/kvm/vgic/vgic-init.c | 3 +++ arch/arm64/kvm/vgic/vgic-its.c | 16 ++++++++++++++++ arch/arm64/kvm/vgic/vgic.c | 1 + include/kvm/arm_vgic.h | 2 ++ 4 files changed, 22 insertions(+) diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c index e949e1d0fd9f..411719053107 100644 --- a/arch/arm64/kvm/vgic/vgic-init.c +++ b/arch/arm64/kvm/vgic/vgic-init.c @@ -56,6 +56,7 @@ void kvm_vgic_early_init(struct kvm *kvm) INIT_LIST_HEAD(&dist->lpi_list_head); INIT_LIST_HEAD(&dist->lpi_translation_cache); raw_spin_lock_init(&dist->lpi_list_lock); + xa_init_flags(&dist->lpi_xa, XA_FLAGS_LOCK_IRQ); } /* CREATION */ @@ -366,6 +367,8 @@ static void kvm_vgic_dist_destroy(struct kvm *kvm) if (vgic_supports_direct_msis(kvm)) vgic_v4_teardown(kvm); + + xa_destroy(&dist->lpi_xa); } static void __kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu) diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c index 59179268ac2d..0265cd1f2d6e 100644 --- a/arch/arm64/kvm/vgic/vgic-its.c +++ b/arch/arm64/kvm/vgic/vgic-its.c @@ -53,6 +53,12 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid, if (!irq) return ERR_PTR(-ENOMEM); + ret = xa_reserve_irq(&dist->lpi_xa, intid, GFP_KERNEL_ACCOUNT); + if (ret) { + kfree(irq); + return ERR_PTR(ret); + } + INIT_LIST_HEAD(&irq->lpi_list); INIT_LIST_HEAD(&irq->ap_list); raw_spin_lock_init(&irq->irq_lock); @@ -87,10 +93,20 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid, goto out_unlock; } + ret = xa_err(xa_store(&dist->lpi_xa, intid, irq, 0)); + if (ret) { + xa_release(&dist->lpi_xa, intid); + kfree(irq); + goto out_unlock; + } + list_add_tail(&irq->lpi_list, &dist->lpi_list_head); dist->lpi_list_count++; out_unlock: + if (ret) + return ERR_PTR(ret); + raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags); /* 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); dist->lpi_list_count--; kfree(irq); diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 8cc38e836f54..795b35656b54 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -275,6 +276,7 @@ struct vgic_dist { /* Protects the lpi_list and the count value below. */ raw_spinlock_t lpi_list_lock; + struct xarray lpi_xa; struct list_head lpi_list_head; int lpi_list_count;