Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2168920rdb; Tue, 20 Feb 2024 21:46:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW9pwxneQ4kpNC7HwmQWQzORxB8RYIlFKhj6wQNJoWZv3+dkzWNlijB2p75j2cz2280FdEfLEmqKali0pCLjjfLSjKwK4SCKOzlAuBVMw== X-Google-Smtp-Source: AGHT+IEoBA0I+feuGdh9PnZ0wZVGaxMJGXZbEJ6cGz6Z3QokBE01M/ATJKWn7E7f+Ef7nfODABjX X-Received: by 2002:a05:6870:e247:b0:21f:397c:bf51 with SMTP id d7-20020a056870e24700b0021f397cbf51mr2439199oac.25.1708494360667; Tue, 20 Feb 2024 21:46:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708494360; cv=pass; d=google.com; s=arc-20160816; b=nhN1G2rAhPlzFL3kuC0dzbMc0Wlkf9L+bATyaltJ5FYaXTiEOqxpye204tdrEhy6Bw srEmk7KtXhyEDk1WPleFFXiCCVMkUdVbOEUEe0Lcaq1S7rlP6cj0FF+SEjr7xLk349qI 3l+ye9KqDF/EjhKsct5AG6stCBGYbOqJEyVq5HBsqVdE4d2+CcBMaf6SiKiaN+5C5qgm qH71AL7o1o4ED9923hrm8XUi+P7n50Oam70+q2IXmzg9fUbqRBbKiFmtEkB9p/nULnLt 7RphjEj3Vyyu4pTEc/8AGdpMlydveRi4Ml5RZBPy6adQpdvucJW9B06qKs6rRTN4DIop 6XJw== 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=OSxryl4GJz7jglvRnwO6HB5bazTdcs2fEdVdtMmeB8s=; fh=kCIhDCwfhVa+1moYcBlLNuY7yX/BfELZCoRk1wSf3jY=; b=aaTNW13wltCVorj1AXFvlF5nHgRA65YZwddHWTW+8Jxbl+OyxkVETeGLbyyM8jsVM1 LBgsUX5RN5o3Eq0ArNrhETrKCV61c68lYJPPbsvOsDmkatvWc3cB0Rz1W4XrrnnWOiIv Ma+FQPCd3G7xbK90agMOiDFC6GbpEmVP8bsbxHnf5l97ps8UWQ7duLmTRjbsH8x9BCDe dFIME5set6rbTlU3ZmPmyltv3m01BLYFf5ImK7xFrCB27DOnzfPkxJznpS3jnT0pgQ+s 3x703q6B3ys4/Hmsfp8eu5CwZJF+tBUwrBeC5JnCTRRz/PyqlQAsP0h/UNl7UBRMCB1N K4bw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=JOdXlq8W; 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-74104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74104-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m187-20020a6326c4000000b005dc97ac8afesi7600265pgm.37.2024.02.20.21.46.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 21:46:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=JOdXlq8W; 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-74104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74104-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3F169286190 for ; Wed, 21 Feb 2024 05:45:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5464B3C68C; Wed, 21 Feb 2024 05:43:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="JOdXlq8W" Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 DE9663A8E5 for ; Wed, 21 Feb 2024 05:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708494213; cv=none; b=d+Z4cmhnQhNpublbzzYzu0larUrgdDx1Mib9O0iLJk/I9PWPbOlI6H0pHBJNGR2Avm3GNCjf+vMeVPjvv5FteY+5QnuxwDZnsW64zta9npmz9E/FUqDAU/60dIZ+Tg/T4w+UgXz9fHJOmfafv60S44gt5etiaxtuPp3qtqupjy0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708494213; c=relaxed/simple; bh=i1Z17y1L2zZUqDCMRJDQXDFZa8iLbDZzznncMJH6hZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j6csHFl7jWTbDhq2ulvowNe5WvT97dqwLDH3NwDJB/DGm17RnLCxF7ZKaHXoYPkWkuPjK/uboNgPTlVpapS2pWQkPavODgzyeDUak/QU2WHUC1nIbKBUbj4HhDqMaLkl2zkGP9VHXKJRdjRdCiK/fbyRZD2J0x7VZaYuv6jBlwc= 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=JOdXlq8W; arc=none smtp.client-ip=91.218.175.180 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=1708494210; 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=OSxryl4GJz7jglvRnwO6HB5bazTdcs2fEdVdtMmeB8s=; b=JOdXlq8WUZfIK0n17nGijHUe5mPeuDqw2JyGKCciNDJMECFQT4kEAYdfH3vwhxjHvWm+Qb pb7a+3tuYFEeojv3/zOuWw6jNPAcD0AK+UZkb4eA8f0unN752nf2as6SvuFCUq9uK7Omv5 pcjH9bPZKe2pu2gtm7P8FjZrjXkjBb0= 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, Eric Auger , Oliver Upton Subject: [PATCH v4 06/10] KVM: arm64: vgic: Use atomics to count LPIs Date: Wed, 21 Feb 2024 05:42:49 +0000 Message-ID: <20240221054253.3848076-7-oliver.upton@linux.dev> In-Reply-To: <20240221054253.3848076-1-oliver.upton@linux.dev> References: <20240221054253.3848076-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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Switch to using atomics for LPI accounting, allowing vgic_irq references to be dropped in parallel. Signed-off-by: Oliver Upton --- arch/arm64/kvm/vgic/vgic-debug.c | 2 +- arch/arm64/kvm/vgic/vgic-its.c | 4 ++-- arch/arm64/kvm/vgic/vgic.c | 2 +- include/kvm/arm_vgic.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/vgic/vgic-debug.c b/arch/arm64/kvm/vgic/vgic-debug.c index 85606a531dc3..389025ce7749 100644 --- a/arch/arm64/kvm/vgic/vgic-debug.c +++ b/arch/arm64/kvm/vgic/vgic-debug.c @@ -149,7 +149,7 @@ static void print_dist_state(struct seq_file *s, struct vgic_dist *dist) seq_printf(s, "vgic_model:\t%s\n", v3 ? "GICv3" : "GICv2"); seq_printf(s, "nr_spis:\t%d\n", dist->nr_spis); if (v3) - seq_printf(s, "nr_lpis:\t%d\n", dist->lpi_list_count); + seq_printf(s, "nr_lpis:\t%d\n", atomic_read(&dist->lpi_count)); seq_printf(s, "enabled:\t%d\n", dist->enabled); seq_printf(s, "\n"); diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c index 3d0208162bcd..0be3c33676c3 100644 --- a/arch/arm64/kvm/vgic/vgic-its.c +++ b/arch/arm64/kvm/vgic/vgic-its.c @@ -96,7 +96,7 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid, goto out_unlock; } - dist->lpi_list_count++; + atomic_inc(&dist->lpi_count); out_unlock: raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags); @@ -346,7 +346,7 @@ int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr) * command). If coming from another path (such as enabling LPIs), * we must be careful not to overrun the array. */ - irq_count = READ_ONCE(dist->lpi_list_count); + irq_count = atomic_read(&dist->lpi_count); intids = kmalloc_array(irq_count, sizeof(intids[0]), GFP_KERNEL_ACCOUNT); if (!intids) return -ENOMEM; diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c index 6240faab0127..15dbd17b3a9e 100644 --- a/arch/arm64/kvm/vgic/vgic.c +++ b/arch/arm64/kvm/vgic/vgic.c @@ -123,7 +123,7 @@ void __vgic_put_lpi_locked(struct kvm *kvm, struct vgic_irq *irq) return; xa_erase(&dist->lpi_xa, irq->intid); - dist->lpi_list_count--; + atomic_dec(&dist->lpi_count); kfree(irq); } diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index aeff363e3ba6..71e9d719533b 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -273,10 +273,10 @@ struct vgic_dist { */ u64 propbaser; - /* Protects the lpi_list and the count value below. */ + /* Protects the lpi_list. */ raw_spinlock_t lpi_list_lock; struct xarray lpi_xa; - int lpi_list_count; + atomic_t lpi_count; /* LPI translation cache */ struct list_head lpi_translation_cache; -- 2.44.0.rc0.258.g7320e95886-goog