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: 13784879 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (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 35CC518FC9F for ; Fri, 30 Aug 2024 10:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725012751; cv=none; b=MYLsb8e67e08Kg6B8a28cRtOGGp3sZZsIqwC9KvuofEaHJGLfMLbQ5CQeEYXPPAzx7h9a9Jl/ssfnv5Bv5G9N27Dfmix0nH9rFIooUAq1RHEPmxp9q0FD0JM6JsuXdUMdQcTtp9hkZhrJjLu/IaMzAGsOzV6im3ZYBLh8J7JGJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725012751; c=relaxed/simple; bh=7jPlGbTB7MxeJTqNMRDYok689EzX7DiIR1j2PXQvRuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FoY1C5Lb8bahvV4XZOdF5mB8l1V3tAP1ChnjNgWdPLpVwV29sJbKz00GJ+sg9YNo1P0rsWCfoVAhQ6hyKKLOIRlDWpX3x1msy1/OYOJcxtCVNSzT+MNBrGpu/CayHDvOXesg5rLzW+B+mcZTf0rKTmrMv1vz37ScOII0adcXhug= 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=dJPwSQf0; arc=none smtp.client-ip=95.215.58.179 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dJPwSQf0" 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: 13784880 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 2EE0918FC93 for ; Fri, 30 Aug 2024 10:12:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725012753; cv=none; b=qmPyYQlZJfgFlrX79cKHKJNnnwEE/W+7BIrjlFuMyM/w5i9jmrrY4cwUl4bC/8lOUjn4ji2V1QHP3TbU9tk1Gm5OgxM50RyJPU72Uj9rfvKD35g9HA6QafVrzUbmFQVxv3qHiduG9xesfA/6o2s4SIqr85UvFp/jaRmdBxzk+Z8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725012753; c=relaxed/simple; bh=EkVLgyI+PiNCuoF2l5eLwqCpwIwMnyXIvB+/6HuV4rY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HbxaoYiFAiRK86Wr9fWR+OHBb6m+2O4G4flT4vJiElJZZBfynAvrF1IWi9/gf2tUkF5Jy1rbQ7Oubk/oBYbmjmr06BScJXbKmso3Rr05BTkY/FIoUhe3SfcZ2k6yL7xpq2vRLCObaohj7pKJVts8w3tKomIW1CfUPNFpcVNPYA8= 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=uKbtkh45; arc=none smtp.client-ip=95.215.58.187 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="uKbtkh45" 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: 13784881 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (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 44BE418FC93 for ; Fri, 30 Aug 2024 10:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725012757; cv=none; b=jcJBVA4Q58vFzTKX51xQmLPlVeTefSG2d5TeiATJvsXx7HjVb0nGPslZD/ibvSVyrgvR43EJs4EPC9bsTRk7x0nZuP/cIFFBCyUrizA8EY5le9qNLR5x0Ljx3G5om7p5hNm+NB68C4Eavq4mIUGjnbMADrPem5lHNaOlFxngiQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725012757; c=relaxed/simple; bh=+g2CnwQZmAX+btJR7PuVwPL1cIW4Zd+8eq095bwLH/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sqD5bY7K+mR4L2O+GDipOOZdxTHdUqTYyAUK5ddG4eZwuiF4H3ENEru+OViOwF7Br+buIld5YlRWEOViq2sj4euWPbfMld1FYf7gadpVaUofnOnPCYo6x1l5/a6KriABVaZYBriooOyZE6RjUXnbL4Zeu73++pxyNObCI4A/eZc= 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=gbCvCGLP; arc=none smtp.client-ip=91.218.175.174 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="gbCvCGLP" 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: 13784924 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (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 6711D19992C for ; Fri, 30 Aug 2024 11:01:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725015703; cv=none; b=mYfDKW2I5m5XHfRgI8D/tKNG+wBgl/73rzMKC0fpJeOCol5twwn3OZUUhV6QlU/W9r2CitTvfRZEzzWRXs/K524txkF+N82dI+VWp9lgtuJ7TM6TqMVUwJoUiHthZSyaxdaJ9YbZZqXBvCxjI/zZZ9mEq9s887VvjiHozCanZXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725015703; c=relaxed/simple; bh=OU3ZD/tINDeCZzbqkPivzNhufEb02y3r9eN2e0aJmwU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s5fseCZeBhRE6LkGzEZ76sk9jWz9K4W52ZXo3LyD+bqERUsinLNaW15a9+UKjX2OSGuUhBW4xwf4nUBX9MnF2cHnjey+kbO9utmTh13rpCG1aFvdmBxHjWVrAXASfYNdcsySgbigZgu5MmAgFKldreKSBToHer2Kbotcw38jPEA= 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=qOJOf9FH; arc=none smtp.client-ip=95.215.58.176 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qOJOf9FH" 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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);