From patchwork Thu Oct 31 12:39:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2004651 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=tDucOOvp; 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=v+g3pbxJ; 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 4XfPTQ5b6gz1xx7 for ; Fri, 1 Nov 2024 00:09:14 +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=3EKmjnp/drfYwJsjhJArOsap6le6zt5WleQyq/emrMM=; b=tDucOOvpZgAkdZ OjsvVMCc56B8qRvp5/6d25aUcup+zZrRa5OGPcnpG6qtc/7As1XdsGZSEjWS0pFdgCyZBG8NcLf4z /j2Ivl/9wuVpDUU1hvcEoM2m5itPZlWzgUEYo76WpLHhhqefLyM1EuvqyBnxkyY2/i9Ww1NpYkAp/ 4LQMQBocyhjGX3FQOm5xxBQnhXgCu8z0hJHVkZNt0ihO0q5MgWmN7Eu/810EhXrKI3ESSisWjqgmY Im4u7k5rSzFgBaV172PeJy6TxKnoJCp8Oqf9MyN07YFvhzNgLyP3be+JQpMCpRO/VqQoWWGRMX1eL nK8ZzpYIZG50XddnA2ag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t6UvJ-00000003dRF-1jAg; Thu, 31 Oct 2024 13:09:13 +0000 Received: from out-174.mta1.migadu.com ([2001:41d0:203:375::ae]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t6USy-00000003Yfj-2Jcr for kvm-riscv@lists.infradead.org; Thu, 31 Oct 2024 12:39:58 +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=1730378394; 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=TRNGizBmS3No09royYQAbT6P9mobmk6sdA5rSdYfEw8=; b=v+g3pbxJitJk62SxyplCt57DrusgyGpM1bvqDyQRLaklC9QaBKdHygl10drdXSH684vIp3 GhqLtspjbXJAhsVs6+Eg3dXOPrCelIw2fTKba838UV++/PfIoP17ybbv7COMfBwYCvs9bV EEXdPyhXFl4pek866OP5Bw/E5sjZu2s= 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 v2 1/3] lib/on-cpus: Correct and simplify synchronization Date: Thu, 31 Oct 2024 13:39:50 +0100 Message-ID: <20241031123948.320652-6-andrew.jones@linux.dev> In-Reply-To: <20241031123948.320652-5-andrew.jones@linux.dev> References: <20241031123948.320652-5-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-20241031_053956_774727_BE5ED17D X-CRM114-Status: GOOD ( 12.50 ) X-Spam-Score: -2.1 (--) 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: get/put_on_cpu_info() were providing per-cpu locking for the per-cpu on_cpu info, but it's difficult to reason that they're correct since they use test_and_set/clear rather than a typical lock. Just r [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 get/put_on_cpu_info() were providing per-cpu locking for the per-cpu on_cpu info, but it's difficult to reason that they're correct since they use test_and_set/clear rather than a typical lock. Just revert to a typical spinlock to simplify it. Also simplify the break case for on_cpu_async() - we don't care if func is NULL, we only care that the cpu is idle. And, finally, add a missing barrier to on_cpu_async(). Before commit 018550041b38 ("arm/arm64: Remove spinlocks from on_cpu_async") the spin_unlock() provided an implicit barrier at the correct location, but moving the release to the more logical location, below the setting of idle, lost it. Fixes: 018550041b38 ("arm/arm64: Remove spinlocks from on_cpu_async") Signed-off-by: Andrew Jones Reviewed-by: Eric Auger --- lib/on-cpus.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/lib/on-cpus.c b/lib/on-cpus.c index 892149338419..f6072117fa1b 100644 --- a/lib/on-cpus.c +++ b/lib/on-cpus.c @@ -9,6 +9,7 @@ #include #include #include +#include bool cpu0_calls_idle; @@ -18,18 +19,7 @@ struct on_cpu_info { cpumask_t waiters; }; static struct on_cpu_info on_cpu_info[NR_CPUS]; -static cpumask_t on_cpu_info_lock; - -static bool get_on_cpu_info(int cpu) -{ - return !cpumask_test_and_set_cpu(cpu, &on_cpu_info_lock); -} - -static void put_on_cpu_info(int cpu) -{ - int ret = cpumask_test_and_clear_cpu(cpu, &on_cpu_info_lock); - assert(ret); -} +static struct spinlock lock; static void __deadlock_check(int cpu, const cpumask_t *waiters, bool *found) { @@ -81,18 +71,14 @@ void do_idle(void) if (cpu == 0) cpu0_calls_idle = true; - set_cpu_idle(cpu, true); - smp_send_event(); - for (;;) { + set_cpu_idle(cpu, true); + smp_send_event(); + while (cpu_idle(cpu)) smp_wait_for_event(); smp_rmb(); on_cpu_info[cpu].func(on_cpu_info[cpu].data); - on_cpu_info[cpu].func = NULL; - smp_wmb(); - set_cpu_idle(cpu, true); - smp_send_event(); } } @@ -110,17 +96,17 @@ void on_cpu_async(int cpu, void (*func)(void *data), void *data) for (;;) { cpu_wait(cpu); - if (get_on_cpu_info(cpu)) { - if ((volatile void *)on_cpu_info[cpu].func == NULL) - break; - put_on_cpu_info(cpu); - } + spin_lock(&lock); + if (cpu_idle(cpu)) + break; + spin_unlock(&lock); } on_cpu_info[cpu].func = func; on_cpu_info[cpu].data = data; + smp_wmb(); set_cpu_idle(cpu, false); - put_on_cpu_info(cpu); + spin_unlock(&lock); smp_send_event(); } From patchwork Thu Oct 31 12:39:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2004650 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=XkE6FugD; 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=jXwB1F7L; 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 4XfPTR0hfRz1xxw for ; Fri, 1 Nov 2024 00:09:15 +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=r72bR/xA4Oh4N9xDhaqnnlEITGmV/CfqvI5geEVjo8s=; b=XkE6FugDgbJzQ6 SAxcqFkGTLwzLn9vX0f2MYZ/w2kApK37Gz6UWD8W8x0erz49NN0xXSuCGDwJcZUaUFi6Elt08Ib2X eNFAf7g2yvm/I02CDlnKrdMe/0E7rSdHt9IVFCGH8FMcX2+j+mZk9UBnHDVBrei4nh4qL+AsmI0e9 mM9OV7pKSUvSkwChgHTSTxbX/mKNNK4kGB5MCFDoQL9qLjMBWiw2aNnxy5x/5ABqtSwJhkozPzs7U a4VgYKqmP5J269nQRd75GP2HvVmajnkHMZU5fg3zFzHzNN6/Y2xjwb7VTWz1lZp2epK5lKTy8l112 6LA6crG7VE3mhAkqwGyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t6UvJ-00000003dRZ-3236; Thu, 31 Oct 2024 13:09:13 +0000 Received: from out-172.mta0.migadu.com ([2001:41d0:1004:224b::ac]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t6UT5-00000003YhL-2409 for kvm-riscv@lists.infradead.org; Thu, 31 Oct 2024 12:40:05 +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=1730378400; 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=6sdpDxlDP7qYJBIbsqSGSz+F9K7iMcqf9pogsQkjPxU=; b=jXwB1F7LrXVcvAi9BoxHOFzDAZ5xNofxLot+WMeczadZnh7CZROGqQsjqqn6q+J8lam8y1 QLhHPvO0OjN7f3uzGEAdpYTaHHiRd9dFGSMfhw6Vqk7fuhXckB7KCHdgOwn366rdG6EDvH L28O8jJgjXD9IWlkHCmbwi0zCGud+xg= 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 v2 2/3] lib/on-cpus: Add barrier after func call Date: Thu, 31 Oct 2024 13:39:51 +0100 Message-ID: <20241031123948.320652-7-andrew.jones@linux.dev> In-Reply-To: <20241031123948.320652-5-andrew.jones@linux.dev> References: <20241031123948.320652-5-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-20241031_054003_697919_E9F5AA79 X-CRM114-Status: UNSURE ( 9.08 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.1 (--) 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: It's reasonable for users of on_cpu() and on_cpumask() to assume they can read data that 'func' has written when the call completes. Ensure the caller doesn't observe a completion (target cpus are aga [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 It's reasonable for users of on_cpu() and on_cpumask() to assume they can read data that 'func' has written when the call completes. Ensure the caller doesn't observe a completion (target cpus are again idle) without also being able to observe any writes which were made by func(). Do so by adding barriers to implement the following target-cpu calling-cpu ---------- ----------- func() /* store something */ /* wait for target to be idle */ smp_wmb(); smp_rmb(); set_cpu_idle(smp_processor_id(), true); /* load what func() stored */ Signed-off-by: Andrew Jones Reviewed-by: Eric Auger --- lib/on-cpus.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/on-cpus.c b/lib/on-cpus.c index f6072117fa1b..356f284be61b 100644 --- a/lib/on-cpus.c +++ b/lib/on-cpus.c @@ -79,6 +79,7 @@ void do_idle(void) smp_wait_for_event(); smp_rmb(); on_cpu_info[cpu].func(on_cpu_info[cpu].data); + smp_wmb(); /* pairs with the smp_rmb() in on_cpu() and on_cpumask() */ } } @@ -145,12 +146,14 @@ void on_cpumask(const cpumask_t *mask, void (*func)(void *data), void *data) smp_wait_for_event(); for_each_cpu(cpu, mask) cpumask_clear_cpu(me, &on_cpu_info[cpu].waiters); + smp_rmb(); /* pairs with the smp_wmb() in do_idle() */ } void on_cpu(int cpu, void (*func)(void *data), void *data) { on_cpu_async(cpu, func, data); cpu_wait(cpu); + smp_rmb(); /* pairs with the smp_wmb() in do_idle() */ } void on_cpus(void (*func)(void *data), void *data) From patchwork Thu Oct 31 12:39:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2004648 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=0eIHJlDA; 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=QOYvY2te; 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 4XfPTR3HqYz1xxx for ; Fri, 1 Nov 2024 00:09:15 +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=5mgraQeTAopGBgQLA4AEOXpACijzfSf25iuk5b83RG0=; b=0eIHJlDA3ysi3r kapmr2L6b+NPVAj01IWGDmGBPMKPOa3fJLWGvzL8CRf1JQJY389lcAYLdXyndYNQ8QH9QwBM5DMCg 7n2vyB1tpJDqEhTbo7bstYh7Dn8C+NoyRpvHuXA6e2+5xWuXHrINAgl5GyDhtxgxNH1cln8mLbLSj e24UiqUzUrcxELrNfRKnHvGLu5Jo/h1/gRipL1LFy3bwpMMfcKYlLRm0JdMGrXPrZekFyT71D5Ngt pM9f7fC0W49zNmZgdPkbgWv9CMj6dmOnqjEriYHQ3PSXsa8PJ3tM3jcLSB+Up2dhBypMvcjgft36D Lpt+1d0GZaMx2I9gVwUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t6UvK-00000003dRk-0GEy; Thu, 31 Oct 2024 13:09:14 +0000 Received: from out-178.mta1.migadu.com ([95.215.58.178]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t6UT9-00000003Yhg-0zWs for kvm-riscv@lists.infradead.org; Thu, 31 Oct 2024 12:40:08 +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=1730378403; 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=hPzKqk+gmXmf2DgmdqtxmOjA4rFHvz5nJ0CLZ7ibfGU=; b=QOYvY2teA3lbxD5oJXtk2VS+8rcW5OtSF48WZpf0IwCLxps2ImseheTTJtbqb8Lmgz5frh fbClSfucZRA9Iq74THC3oycjnw2t+biFrGiZdBhJ+VaGLZaiLbKLPIX5QG+S3UdmIlIBZI pGyj3mRmqXO/el8HsEob8G/tUGj7ww8= 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 v2 3/3] lib/on-cpus: Fix on_cpumask Date: Thu, 31 Oct 2024 13:39:52 +0100 Message-ID: <20241031123948.320652-8-andrew.jones@linux.dev> In-Reply-To: <20241031123948.320652-5-andrew.jones@linux.dev> References: <20241031123948.320652-5-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-20241031_054007_445574_22974765 X-CRM114-Status: GOOD ( 11.45 ) 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.178 listed in list.dnswl.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.178 listed in sa-accredit.habeas.com] 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.178 listed in sa-trusted.bondedsender.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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.178 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 Reviewed-by: Eric Auger --- 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 356f284be61b..889b6bc8a186 100644 --- a/lib/on-cpus.c +++ b/lib/on-cpus.c @@ -127,24 +127,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); smp_rmb(); /* pairs with the smp_wmb() in do_idle() */ }