From patchwork Wed Oct 23 13:17:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2001053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=WTKHe6QS; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=d8JTL1cG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XYV2p6GRgz1xx1 for ; Thu, 24 Oct 2024 00:17:37 +1100 (AEDT) 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: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gDlgW2xssPgNtqY7w3NoJqwlh+KVfzUh9uOKPGAQeA0=; b=WTKHe6QS6yQmM4 8QRtnyAd4KDcxHOUN/z81Q74vPUQM9UbfjPiMQmRFDLwsKy0EudlJ72f1r/tICdXJRuUttLvzQu3z zuudRo/Mb8d9JDKHwIY509do58ObozodMhi9l9WgSB7wboVmxYAn2xOSnypQyaoMk9jDuq0MKTH61 9443j/Pll4pTnChpjPbpf/zihy09o7YtapoVcaBSVRrpgCZd8Woxgh5f0dW4fvJecGJqywtgHu7rb AwDoYUBmGEusBKT//NvVQ7j4RtZR5OxDNMa6aid1i2RP3pFHgyE3SzfrDGAwuqujIvtv3FcVkcGim rFASvrN5sbiVUh8w0cwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3bF2-0000000EVOm-0hvk; Wed, 23 Oct 2024 13:17:36 +0000 Received: from out-185.mta1.migadu.com ([95.215.58.185]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3bEx-0000000EVNA-3oIa for kvm-riscv@lists.infradead.org; Wed, 23 Oct 2024 13:17:33 +0000 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=1729689448; 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=l02EqjoVbZcAjRJYCFnsAiDgQGfpjHtDxV/1hFAAx5k=; b=d8JTL1cGcamsFcXSsTnfwg0zmJhp07O0P+V48OrBInRouEh7PN8TXnTn1jKjXUAEePy9ey oVTKD6TlRbW83tlRrrnXgecnzCz93rvxwxxT8pqvlU5p8FpnTZ7eZlv22XoE015fsq5aTt +4u9hi9mnMnfPByUZPCu4ZlpXNfvBNg= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, kvmarm@lists.linux.dev Cc: atishp@rivosinc.com, jamestiotio@gmail.com, alexandru.elisei@arm.com, eric.auger@redhat.com Subject: [kvm-unit-tests PATCH 2/2] lib/on-cpus: Fix on_cpumask Date: Wed, 23 Oct 2024 15:17:21 +0200 Message-ID: <20241023131718.117452-6-andrew.jones@linux.dev> In-Reply-To: <20241023131718.117452-4-andrew.jones@linux.dev> References: <20241023131718.117452-4-andrew.jones@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241023_061732_377268_8536FB2C X-CRM114-Status: GOOD ( 10.96 ) X-Spam-Score: -2.8 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: on_cpumask should wait until the cpus in the mask, not including the calling cpu, are idle. Checking the weight against nr_cpus minus 1 only works when the mask is the same as the present mask. Fixes: d012cfd5d309 ("lib/on-cpus: Introduce on_cpumask and on_cpumask_async") Signed-off-by: Andrew Jones --- lib/cpumask.h | 14 ++++++++++++++ lib/on-cpus.c | 17 ++++++++--- [...] Content analysis details: (-2.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [95.215.58.185 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [95.215.58.185 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [95.215.58.185 listed in sa-accredit.habeas.com] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [95.215.58.185 listed in bl.score.senderscore.com] X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org on_cpumask should wait until the cpus in the mask, not including the calling cpu, are idle. Checking the weight against nr_cpus minus 1 only works when the mask is the same as the present mask. Fixes: d012cfd5d309 ("lib/on-cpus: Introduce on_cpumask and on_cpumask_async") Signed-off-by: Andrew Jones --- lib/cpumask.h | 14 ++++++++++++++ lib/on-cpus.c | 17 ++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/cpumask.h b/lib/cpumask.h index e1e92aacd1f1..37d360786573 100644 --- a/lib/cpumask.h +++ b/lib/cpumask.h @@ -58,6 +58,20 @@ static inline void cpumask_clear(cpumask_t *mask) memset(mask, 0, sizeof(*mask)); } +/* true if src1 is a subset of src2 */ +static inline bool cpumask_subset(const struct cpumask *src1, const struct cpumask *src2) +{ + unsigned long lastmask = BIT_MASK(nr_cpus) - 1; + int i; + + for (i = 0; i < BIT_WORD(nr_cpus); ++i) { + if (cpumask_bits(src1)[i] & ~cpumask_bits(src2)[i]) + return false; + } + + return !lastmask || !((cpumask_bits(src1)[i] & ~cpumask_bits(src2)[i]) & lastmask); +} + static inline bool cpumask_empty(const cpumask_t *mask) { unsigned long lastmask = BIT_MASK(nr_cpus) - 1; diff --git a/lib/on-cpus.c b/lib/on-cpus.c index f6072117fa1b..7ce58be0e7e9 100644 --- a/lib/on-cpus.c +++ b/lib/on-cpus.c @@ -126,24 +126,23 @@ void on_cpumask_async(const cpumask_t *mask, void (*func)(void *data), void *dat void on_cpumask(const cpumask_t *mask, void (*func)(void *data), void *data) { int cpu, me = smp_processor_id(); + cpumask_t tmp; - for_each_cpu(cpu, mask) { - if (cpu == me) - continue; + cpumask_copy(&tmp, mask); + cpumask_clear_cpu(me, &tmp); + + for_each_cpu(cpu, &tmp) on_cpu_async(cpu, func, data); - } if (cpumask_test_cpu(me, mask)) func(data); - for_each_cpu(cpu, mask) { - if (cpu == me) - continue; + for_each_cpu(cpu, &tmp) { cpumask_set_cpu(me, &on_cpu_info[cpu].waiters); deadlock_check(me, cpu); } - while (cpumask_weight(&cpu_idle_mask) < nr_cpus - 1) + while (!cpumask_subset(&tmp, &cpu_idle_mask)) smp_wait_for_event(); - for_each_cpu(cpu, mask) + for_each_cpu(cpu, &tmp) cpumask_clear_cpu(me, &on_cpu_info[cpu].waiters); }