From patchwork Fri Aug 30 10:12:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1978875 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=z2gYdT0I; 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=dJPwSQf0; 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 4WwDVK3rh7z1ygJ for ; Fri, 30 Aug 2024 20:12:41 +1000 (AEST) 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=r1PcIXmw9JMOckgcPk+3lLeSjWeNuF6s6arSya22oA8=; b=z2gYdT0IAWNDpE 6L17RAbahrxYS+MMkn+mswq1cHKKDMtkLJC/FjXAzPwvQGH1OnA6qY1MeDYHc1456LUktxCaGDgc/ NNTt5U819WtKLTjC4jOLo7wddwZVwKsQQ+Tfa24mzj5P/4QoV75+gNuAMyjNCT1i1wyTjSyhL+Zqe lS0xLXv4tLwzRkBi/Ae5S6nTHeU4zkCLbQV3zOTSbvoteFA84Bl3bNY0WSdkCb8tJUpGjC66xdqfd 4xafDjDzAhywFb7VD9NJPxoj0h0MnPPQxJ4TV+WIwlb0ASPtRHq95VPceR/FU2gv+Doy5Fm2GU94b PFehbesjl8poUhjetQAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjycS-00000005k1o-12pu; Fri, 30 Aug 2024 10:12:40 +0000 Received: from out-182.mta1.migadu.com ([95.215.58.182]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjycM-00000005jvG-2ogK for kvm-riscv@lists.infradead.org; Fri, 30 Aug 2024 10:12:37 +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=1725012747; 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=wIgN50Nk075398eDAbRkYLwA2xDhb8GOYDf57SqqBH0=; b=dJPwSQf0Vp5OjfDDhbQJX3sDW8KebG5wzdae6eg7BhDdk/sMqleus0lqlwLsqjaQupo5YM 29aMYSYmjojuKUdFrwB5NSZbVFpF9Aq4OwRpYdNjcfSrkAiPv8mZFVpfOpxCRKGbfWbUN/ n6W0tE/DygYj7jrigOlRsHaa84KVzag= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: atishp@rivosinc.com, cade.richard@berkeley.edu, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 1/3] lib/cpumask: Fix and simplify a few functions Date: Fri, 30 Aug 2024 12:12:23 +0200 Message-ID: <20240830101221.2202707-6-andrew.jones@linux.dev> In-Reply-To: <20240830101221.2202707-5-andrew.jones@linux.dev> References: <20240830101221.2202707-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-20240830_031234_887571_CF8A940E X-CRM114-Status: GOOD ( 11.02 ) 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: Simplify cpumask_setall and cpumask_clear by just using memset. Also simplify cpumask_empty and cpumask_full. This is a fix for cpumask_empty as it would have reported non-empty for cpumasks that had [...] 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.182 listed in list.dnswl.org] 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.182 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.182 listed in sa-accredit.habeas.com] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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.182 listed in bl.score.senderscore.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 Simplify cpumask_setall and cpumask_clear by just using memset. Also simplify cpumask_empty and cpumask_full. This is a fix for cpumask_empty as it would have reported non-empty for cpumasks that had uninitialized junk following nr_cpus when nr_cpus < NR_CPUS. There aren't currently any users of cpumask_empty though so that bug has never appeared. cpumask_full was just convoluted and can now follow cpumask_empty's new pattern. I've already yelled at a mirror to scold the author of the original implementations! Signed-off-by: Andrew Jones --- lib/cpumask.h | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/lib/cpumask.h b/lib/cpumask.h index be1919234d8e..e1e92aacd1f1 100644 --- a/lib/cpumask.h +++ b/lib/cpumask.h @@ -6,8 +6,9 @@ */ #ifndef _CPUMASK_H_ #define _CPUMASK_H_ -#include #include +#include +#include #define CPUMASK_NR_LONGS ((NR_CPUS + BITS_PER_LONG - 1) / BITS_PER_LONG) @@ -49,46 +50,34 @@ static inline int cpumask_test_and_clear_cpu(int cpu, cpumask_t *mask) static inline void cpumask_setall(cpumask_t *mask) { - int i; - for (i = 0; i < nr_cpus; i += BITS_PER_LONG) - cpumask_bits(mask)[BIT_WORD(i)] = ~0UL; - i -= BITS_PER_LONG; - if ((nr_cpus - i) < BITS_PER_LONG) - cpumask_bits(mask)[BIT_WORD(i)] = BIT_MASK(nr_cpus - i) - 1; + memset(mask, 0xff, sizeof(*mask)); } static inline void cpumask_clear(cpumask_t *mask) { - int i; - for (i = 0; i < nr_cpus; i += BITS_PER_LONG) - cpumask_bits(mask)[BIT_WORD(i)] = 0UL; + memset(mask, 0, sizeof(*mask)); } static inline bool cpumask_empty(const cpumask_t *mask) { - int i; - for (i = 0; i < nr_cpus; i += BITS_PER_LONG) { - if (i < NR_CPUS) { /* silence crazy compiler warning */ - if (cpumask_bits(mask)[BIT_WORD(i)] != 0UL) - return false; - } - } - return true; + unsigned long lastmask = BIT_MASK(nr_cpus) - 1; + + for (int i = 0; i < BIT_WORD(nr_cpus); ++i) + if (cpumask_bits(mask)[i]) + return false; + + return !lastmask || !(cpumask_bits(mask)[BIT_WORD(nr_cpus)] & lastmask); } static inline bool cpumask_full(const cpumask_t *mask) { - int i; - for (i = 0; i < nr_cpus; i += BITS_PER_LONG) { - if (cpumask_bits(mask)[BIT_WORD(i)] != ~0UL) { - if ((nr_cpus - i) >= BITS_PER_LONG) - return false; - if (cpumask_bits(mask)[BIT_WORD(i)] - != BIT_MASK(nr_cpus - i) - 1) - return false; - } - } - return true; + unsigned long lastmask = BIT_MASK(nr_cpus) - 1; + + for (int i = 0; i < BIT_WORD(nr_cpus); ++i) + if (cpumask_bits(mask)[i] != ULONG_MAX) + return false; + + return !lastmask || (cpumask_bits(mask)[BIT_WORD(nr_cpus)] & lastmask) == lastmask; } static inline int cpumask_weight(const cpumask_t *mask) From patchwork Fri Aug 30 10:12:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1978873 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=JD8oTYv/; 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=uKbtkh45; 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 4WwDVG4kDWz1ydy for ; Fri, 30 Aug 2024 20:12:38 +1000 (AEST) 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=GLP+hJIJXyG6witgSrM9HRCo3Lljmu6KPoBeUFwMmvo=; b=JD8oTYv/qQRmZd 4qf0I8iiROZGv8+UDIMpteJ6KgbAU7FlEGHEsOH/jckVuB3airC7Xr4jPDQuTivpN7Mcg4nWuYrDk pA+qLVFgigt4h5aEOacgPyw/K80xD3z7odCdtVVQA2SxRhyN5fPjY04x5mswm6CyX7WA2p7BtOiL3 1eBUrrUWuSEc4lPqkA7zt4XG6REd08Cy+J+OanXhb7A4WpLgZ7e/3HCP6k0BtD5YI5ees2vfu59jf Cu9NXbl5H2EXrpEssNCrAo6esVHTFtduP0TGgjGJq5eGP9Eb6XwT/eCam+GySv2j9Xmsycvs8vF2v lM3Du28ZlZ1v/Eyg1NEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjycP-00000005k08-0rgq; Fri, 30 Aug 2024 10:12:37 +0000 Received: from out-171.mta1.migadu.com ([95.215.58.171]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjycL-00000005jvn-2D1N for kvm-riscv@lists.infradead.org; Fri, 30 Aug 2024 10:12:35 +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=1725012749; 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=acH8W84ZyAce4P3EP3Hx16y1Mjg34j7uh57mDyDs55E=; b=uKbtkh45mr5ph8AZ4VtrJIH0BtSj/D6JcA7ux/i3zC15o7x/+NwMN6WCGlak5SIQxr8bRc IMBbomULAF/pn1XO1Nbl9vM2KoCMZYVKOr4B07gTO8GNp3leB79bnM7mot6BV5uack9uw+ l51p5ZZOQYqBERj6bA+nhJqaF8hrLQM= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: atishp@rivosinc.com, cade.richard@berkeley.edu, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 2/3] lib/on-cpus: Introduce on_cpumask and on_cpumask_async Date: Fri, 30 Aug 2024 12:12:24 +0200 Message-ID: <20240830101221.2202707-7-andrew.jones@linux.dev> In-Reply-To: <20240830101221.2202707-5-andrew.jones@linux.dev> References: <20240830101221.2202707-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-20240830_031234_133915_C012AE08 X-CRM114-Status: UNSURE ( 9.65 ) X-CRM114-Notice: Please train this message. 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: Provide functions to launch tasks on a selection of cpus identified by a cpumask. Signed-off-by: Andrew Jones --- lib/on-cpus.c | 35 +++++++++++++++++++++++++++-------- lib/on-cpus.h | 3 +++ 2 files changed, 30 insertions(+), 8 deletions(-) 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.171 listed in list.dnswl.org] 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.171 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.171 listed in sa-accredit.habeas.com] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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.171 listed in bl.score.senderscore.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 Provide functions to launch tasks on a selection of cpus identified by a cpumask. Signed-off-by: Andrew Jones --- lib/on-cpus.c | 35 +++++++++++++++++++++++++++-------- lib/on-cpus.h | 3 +++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/on-cpus.c b/lib/on-cpus.c index aed70f7b27b2..892149338419 100644 --- a/lib/on-cpus.c +++ b/lib/on-cpus.c @@ -124,24 +124,32 @@ void on_cpu_async(int cpu, void (*func)(void *data), void *data) smp_send_event(); } -void on_cpu(int cpu, void (*func)(void *data), void *data) +void on_cpumask_async(const cpumask_t *mask, void (*func)(void *data), void *data) { - on_cpu_async(cpu, func, data); - cpu_wait(cpu); + int cpu, me = smp_processor_id(); + + for_each_cpu(cpu, mask) { + if (cpu == me) + continue; + on_cpu_async(cpu, func, data); + } + if (cpumask_test_cpu(me, mask)) + func(data); } -void on_cpus(void (*func)(void *data), void *data) +void on_cpumask(const cpumask_t *mask, void (*func)(void *data), void *data) { int cpu, me = smp_processor_id(); - for_each_present_cpu(cpu) { + for_each_cpu(cpu, mask) { if (cpu == me) continue; on_cpu_async(cpu, func, data); } - func(data); + if (cpumask_test_cpu(me, mask)) + func(data); - for_each_present_cpu(cpu) { + for_each_cpu(cpu, mask) { if (cpu == me) continue; cpumask_set_cpu(me, &on_cpu_info[cpu].waiters); @@ -149,6 +157,17 @@ void on_cpus(void (*func)(void *data), void *data) } while (cpumask_weight(&cpu_idle_mask) < nr_cpus - 1) smp_wait_for_event(); - for_each_present_cpu(cpu) + for_each_cpu(cpu, mask) cpumask_clear_cpu(me, &on_cpu_info[cpu].waiters); } + +void on_cpu(int cpu, void (*func)(void *data), void *data) +{ + on_cpu_async(cpu, func, data); + cpu_wait(cpu); +} + +void on_cpus(void (*func)(void *data), void *data) +{ + on_cpumask(&cpu_present_mask, func, data); +} diff --git a/lib/on-cpus.h b/lib/on-cpus.h index 41103b0245c7..4bc6236d6b58 100644 --- a/lib/on-cpus.h +++ b/lib/on-cpus.h @@ -2,6 +2,7 @@ #ifndef _ON_CPUS_H_ #define _ON_CPUS_H_ #include +#include extern bool cpu0_calls_idle; @@ -10,5 +11,7 @@ void do_idle(void); void on_cpu_async(int cpu, void (*func)(void *data), void *data); void on_cpu(int cpu, void (*func)(void *data), void *data); void on_cpus(void (*func)(void *data), void *data); +void on_cpumask_async(const cpumask_t *mask, void (*func)(void *data), void *data); +void on_cpumask(const cpumask_t *mask, void (*func)(void *data), void *data); #endif /* _ON_CPUS_H_ */ From patchwork Fri Aug 30 10:12:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1978876 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=gDANG+5W; 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=gbCvCGLP; 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 4WwDVL0ZTmz1ydy for ; Fri, 30 Aug 2024 20:12:41 +1000 (AEST) 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=Q3tpnavwITyYzejfSAl2BvSRDh95vn4lyX3NauDBv4o=; b=gDANG+5WB96Rfc 9YVMm3Jnf7Phul9jSFY0SCVUDodqv/5G7RN+mfWsIDoMHF74jHaJ7JVCPQtijXmUeZrnjC/Ipwlg0 RlDzINLTMZ0aLQ4vK55I4/4bNuVBkP9xjO08ErRqULvQIsfaqGjd7cFClz3tBGpnLg9DXgDyo+mgs qsy8xM5tnEZQCI7x3o3xKYHZwE4tR0W9K5Ybr41+eIOgAgtZCZLPoabvOkMzFkjhlM1Vmtg0yjS4V Cfr6cZCCZwtQK4I2efCrovJjDyrVwy1CN+RQicFUdmXDhhJltqwkc2GQKH3kbi7yKMlJiXnKECsWP YaUrZJC3WNCApZR+I2/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjycS-00000005k2I-2gQG; Fri, 30 Aug 2024 10:12:40 +0000 Received: from out-180.mta0.migadu.com ([91.218.175.180]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjycO-00000005jyE-0rvX for kvm-riscv@lists.infradead.org; Fri, 30 Aug 2024 10:12:38 +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=1725012753; 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=0xDy3dXhfhs76uE+qsYOO2EHperiy+X3slHufWL875k=; b=gbCvCGLPnTCv01Gr43cOKTR4LYwl0FpaQy5QFy28EG6+sklK2PK6r1wH8sMlOoAr0lq7Yq Vd9CjTCpq+ib0DyEedKHL3SwDj3PC3LWkYcQHn6laUoBEGkKgOu3T7Xe4iaA4X7R5A01sN ByIxlCuz3RjbwnEpzhWzJ0nTikmUqi0= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: atishp@rivosinc.com, cade.richard@berkeley.edu, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 3/3] riscv: Introduce SBI IPI convenience functions Date: Fri, 30 Aug 2024 12:12:25 +0200 Message-ID: <20240830101221.2202707-8-andrew.jones@linux.dev> In-Reply-To: <20240830101221.2202707-5-andrew.jones@linux.dev> References: <20240830101221.2202707-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-20240830_031236_953591_02C8959A X-CRM114-Status: UNSURE ( 9.69 ) 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: The SBI IPI function interface is a bit painful to use since it operates on hartids as opposed to cpuids and requires determining a mask base and a mask. Provide functions allowing IPIs to be sent to [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 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. [91.218.175.180 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.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. [91.218.175.180 listed in sa-accredit.habeas.com] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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. [91.218.175.180 listed in bl.score.senderscore.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 The SBI IPI function interface is a bit painful to use since it operates on hartids as opposed to cpuids and requires determining a mask base and a mask. Provide functions allowing IPIs to be sent to single cpus and to all cpus set in a cpumask in order to simplify things for unit tests. Signed-off-by: Andrew Jones --- lib/riscv/asm/sbi.h | 3 +++ lib/riscv/sbi.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index 4a35cf38da70..e032444dd760 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -13,6 +13,7 @@ #define SBI_ERR_ALREADY_STOPPED -8 #ifndef __ASSEMBLY__ +#include enum sbi_ext_id { SBI_EXT_BASE = 0x10, @@ -67,6 +68,8 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, void sbi_shutdown(void); struct sbiret sbi_hart_start(unsigned long hartid, unsigned long entry, unsigned long sp); struct sbiret sbi_send_ipi(unsigned long hart_mask, unsigned long hart_mask_base); +struct sbiret sbi_send_ipi_cpu(int cpu); +struct sbiret sbi_send_ipi_cpumask(const cpumask_t *mask); struct sbiret sbi_set_timer(unsigned long stime_value); long sbi_probe(int ext); diff --git a/lib/riscv/sbi.c b/lib/riscv/sbi.c index 07660e422cbb..ecc63acdebb7 100644 --- a/lib/riscv/sbi.c +++ b/lib/riscv/sbi.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-only #include +#include +#include #include +#include struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, @@ -44,6 +47,46 @@ struct sbiret sbi_send_ipi(unsigned long hart_mask, unsigned long hart_mask_base return sbi_ecall(SBI_EXT_IPI, SBI_EXT_IPI_SEND_IPI, hart_mask, hart_mask_base, 0, 0, 0, 0); } +struct sbiret sbi_send_ipi_cpu(int cpu) +{ + return sbi_send_ipi(1UL, cpus[cpu].hartid); +} + +struct sbiret sbi_send_ipi_cpumask(const cpumask_t *mask) +{ + struct sbiret ret; + cpumask_t tmp; + + if (cpumask_full(mask)) + return sbi_send_ipi(0, -1UL); + + cpumask_copy(&tmp, mask); + + while (!cpumask_empty(&tmp)) { + unsigned long base = ULONG_MAX; + unsigned long mask = 0; + int cpu; + + for_each_cpu(cpu, &tmp) { + if (base > cpus[cpu].hartid) + base = cpus[cpu].hartid; + } + + for_each_cpu(cpu, &tmp) { + if (cpus[cpu].hartid < base + BITS_PER_LONG) { + mask |= 1UL << (cpus[cpu].hartid - base); + cpumask_clear_cpu(cpu, &tmp); + } + } + + ret = sbi_send_ipi(mask, base); + if (ret.error) + break; + } + + return ret; +} + struct sbiret sbi_set_timer(unsigned long stime_value) { return sbi_ecall(SBI_EXT_TIME, SBI_EXT_TIME_SET_TIMER, stime_value, 0, 0, 0, 0, 0); From patchwork Fri Aug 30 11:01:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1978906 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=A0IWD+K2; 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=qOJOf9FH; 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 4WwFb070BRz1yfX for ; Fri, 30 Aug 2024 21:01:46 +1000 (AEST) 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=oamHtzmQGHPzuk6irjQHOl3Zo4wyET04eIdPSX9Uyig=; b=A0IWD+K2j5J9YG QBo6qAzS0R1VpcbZq0c1HHfcDEYeojxTAe7T/gCpwrGzBsNBEdg5kedQKp75tHpeEp6wGTEKbrw2c RKSOgs5PmD5jG+NsmCvcG7fVFyKvTX4Ivgznp0eTAMOATEAFsYiYA9qh7IB3eWXIcpoJAHqzxpopg Ie5jVnKYqb42Nzh4YEL9HkT0l9Q7rVinGFSA6ytWXT1RIWZu59d3q6CFXvUhPyC7P6ouCldGZdQcW /66WTPfzyeudbYFFG+oAXrLxOUcV1MCkNIP2p5w4vP0sRPyTH0jY3ePAMDOLcnkMYWCKtq1d2+nzC JeddXCojHTmJ4S30b5bQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjzNw-00000005wHD-40J1; Fri, 30 Aug 2024 11:01:44 +0000 Received: from out-176.mta1.migadu.com ([95.215.58.176]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjzNt-00000005wET-2CVP for kvm-riscv@lists.infradead.org; Fri, 30 Aug 2024 11:01:43 +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=1725015699; 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=N909z69GYkPeqBou+7oKeymfZidniJoL6acPvqa0aHg=; b=qOJOf9FHZ51yqmsKwBUFLrW9jQ6a/Qlimn0+rylZLssY5oqmaFSuXZw0Gw6ZvQtRdW5xq9 Ep1c/gALxnv/rM0zbfdWs2NS66eh+PD0g8mi5pVOvw/jClEAaKnPMFmHwrUH6P6Hijdy9K M2FJ1q4k1vTj2uo3RWaVA8SQ39oBW+8= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: atishp@rivosinc.com, cade.richard@berkeley.edu, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 4/3] riscv: Provide helpers for IPIs Date: Fri, 30 Aug 2024 13:01:36 +0200 Message-ID: <20240830110135.2232665-2-andrew.jones@linux.dev> In-Reply-To: <20240830101221.2202707-5-andrew.jones@linux.dev> References: <20240830101221.2202707-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-20240830_040141_789385_06956B69 X-CRM114-Status: UNSURE ( 7.36 ) X-CRM114-Notice: Please train this message. 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: Provide a few functions to enable/disable/acknowledge IPIs. Signed-off-by: Andrew Jones --- lib/riscv/asm/csr.h | 3 ++- lib/riscv/asm/processor.h | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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.176 listed in list.dnswl.org] 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.176 listed in bl.score.senderscore.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.176 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.176 listed in sa-accredit.habeas.com] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 Provide a few functions to enable/disable/acknowledge IPIs. Signed-off-by: Andrew Jones --- lib/riscv/asm/csr.h | 3 ++- lib/riscv/asm/processor.h | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/riscv/asm/csr.h b/lib/riscv/asm/csr.h index 24b333e02589..16f5ddd762de 100644 --- a/lib/riscv/asm/csr.h +++ b/lib/riscv/asm/csr.h @@ -51,7 +51,8 @@ #define IRQ_S_GEXT 12 #define IRQ_PMU_OVF 13 -#define IE_TIE (_AC(0x1, UL) << IRQ_S_TIMER) +#define IE_SSIE (_AC(1, UL) << IRQ_S_SOFT) +#define IE_TIE (_AC(1, UL) << IRQ_S_TIMER) #define IP_TIP IE_TIE diff --git a/lib/riscv/asm/processor.h b/lib/riscv/asm/processor.h index 4c9ad968460d..8989d8d686f9 100644 --- a/lib/riscv/asm/processor.h +++ b/lib/riscv/asm/processor.h @@ -32,6 +32,21 @@ static inline void local_irq_disable(void) csr_clear(CSR_SSTATUS, SR_SIE); } +static inline void local_ipi_enable(void) +{ + csr_set(CSR_SIE, IE_SSIE); +} + +static inline void local_ipi_disable(void) +{ + csr_clear(CSR_SIE, IE_SSIE); +} + +static inline void ipi_ack(void) +{ + csr_clear(CSR_SIP, IE_SSIE); +} + void install_exception_handler(unsigned long cause, void (*handler)(struct pt_regs *)); void install_irq_handler(unsigned long cause, void (*handler)(struct pt_regs *)); void do_handle_exception(struct pt_regs *regs);