From patchwork Thu Nov 14 16:18:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875409 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F015713AD39 for ; Thu, 14 Nov 2024 16:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601131; cv=none; b=tPEA4zMho/YbtyNwsUBRLTnZjhn9Tpzj2yfmH9Dq0uW4vayEjqaKgMf1Rl6PjpR2riNbWG4RsL8kAmlfR9yOEbdpBltg/yJSl9VBRMlb3C1UTmN8Lb3LD/cCJHidUF/LaDCBtJ9tBdoqAkL8++GMMQ9+c0/BUAU5taSby5kIoeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601131; c=relaxed/simple; bh=g+8C+bxaMal2sistKMy08AprWRr5v1lTzqnhoi4uxEc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qLmLlwgjvJZUrbL0sOhLgGylggVnnTCm4U1NNBMPEl6q7H6B6fSIkF2pH5ZjGcOvbirjUCz3xKrWALrT1kNU9hre20ntg4CZ85wRr1SG9mh+NmiEcwbLZ1jgtMfkJ6m8Bz20hITUqNQsC+yr0VtDHYHoknjCKRUUvsr1KO/sRAw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=ZwYZ1I1g; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="ZwYZ1I1g" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-432d86a3085so7716455e9.2 for ; Thu, 14 Nov 2024 08:18:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601128; x=1732205928; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D3ezq2WAE13GAqwSlX07T0LyNCWtPpuH6EoHFe0wCHg=; b=ZwYZ1I1gmsoZ3IIftmTQcKn4wpbAPoyKZs+CuAflG6frSJUbq5+jIATD/QqusKv58I LlY+g8jnnG4tTEs9vXXj5Mypr14WX9hRQUBVkuj+DpbaeES7fZ1hCKkEbDbLM4f3BsWQ X/kIRDf6TuzZ8ZPxjgMzLFPig3HqB49kch4p8d1YhlMzGaAyHDVXs6ZXSAf2p2YR5xsC 2p28pjym0AXwwuWFYmANkp3hoMkGEfuKoHKg46wB+p1OPxXrILTupUN9W4HMyvHBeH+2 bs8rVVHFuixDMZFmI58YyLqdB2mTXH5m2whnSOI4QUPjlm6M5pqS4JUZWVLucFYk28+B h6yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601128; x=1732205928; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D3ezq2WAE13GAqwSlX07T0LyNCWtPpuH6EoHFe0wCHg=; b=DnQ+csFMalc1/WdIgJnCLc1Ows+g06kZp0z9UboG6itmIkdFePgH/Yv1R3Mdp6nnus zGCM5jsjfY3z3Z4BSdrGRADR5QDWTKXkMwi1nbOKAHbpNcuRD1qhS0iADQSsPolr7kpA ewUpD1NBS6aDL6HmQjwUl00eSs5ms9z7nfTah3xsDAO7d8RlMfzUeYUbexTHJoK6bbsr MW+otDmF9MURhcw5+sRnDkx++ic/O4IdtmENJp1pIbcSZH+Iuq3zb7xfkVePyCsvxzfA wP7x93RoQOPhLvsZZ9OJv8/IgFvN0xKK2fczE2BEc3oi4H57rUgzKjNJfTUB1V1rBHtu 4Nqg== X-Forwarded-Encrypted: i=1; AJvYcCXuYQRLLdSML8H6HaZ1wdWKzXQdDJeGnJvEnBNXl/vYfzpVui49bInmiqvd+L4vUT39xx4=@vger.kernel.org X-Gm-Message-State: AOJu0YyCbeVjiB2Boclef5iB2udSBaP0rnPmWNcch3zVwPCDkP2BgD1V i9969YyVx9X6C0G/PsCdaBWxTUNyqWiVzDJZ5A7xqGBFM4skjcdahh1x+paZh+8= X-Google-Smtp-Source: AGHT+IGL/aKw/LZ1JTJ7uKMa5kImPbRP3wDn7MPyUSWssqMaT5McjPD8vLFqR2fLEptCKYdvhP3z0A== X-Received: by 2002:a05:600c:1d1c:b0:426:6308:e2f0 with SMTP id 5b1f17b1804b1-432da7cbcefmr23145865e9.26.1731601128138; Thu, 14 Nov 2024 08:18:48 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432da2800absm28573255e9.25.2024.11.14.08.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:18:47 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 01/15] irqchip/riscv-imsic: Use hierarchy to reach irq_set_affinity Date: Thu, 14 Nov 2024 17:18:46 +0100 Message-ID: <20241114161845.502027-18-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In order to support IRQ domains which reside between the leaf domains and IMSIC, put the IMSIC implementation of irq_set_affinity into its chip. Signed-off-by: Andrew Jones --- drivers/irqchip/irq-riscv-imsic-platform.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/irq-riscv-imsic-platform.c index c708780e8760..5d7c30ad8855 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -96,9 +96,8 @@ static int imsic_irq_set_affinity(struct irq_data *d, const struct cpumask *mask bool force) { struct imsic_vector *old_vec, *new_vec; - struct irq_data *pd = d->parent_data; - old_vec = irq_data_get_irq_chip_data(pd); + old_vec = irq_data_get_irq_chip_data(d); if (WARN_ON(!old_vec)) return -ENOENT; @@ -116,13 +115,13 @@ static int imsic_irq_set_affinity(struct irq_data *d, const struct cpumask *mask return -ENOSPC; /* Point device to the new vector */ - imsic_msi_update_msg(d, new_vec); + imsic_msi_update_msg(irq_get_irq_data(d->irq), new_vec); /* Update irq descriptors with the new vector */ - pd->chip_data = new_vec; + d->chip_data = new_vec; - /* Update effective affinity of parent irq data */ - irq_data_update_effective_affinity(pd, cpumask_of(new_vec->cpu)); + /* Update effective affinity */ + irq_data_update_effective_affinity(d, cpumask_of(new_vec->cpu)); /* Move state of the old vector to the new vector */ imsic_vector_move(old_vec, new_vec); @@ -135,6 +134,9 @@ static struct irq_chip imsic_irq_base_chip = { .name = "IMSIC", .irq_mask = imsic_irq_mask, .irq_unmask = imsic_irq_unmask, +#ifdef CONFIG_SMP + .irq_set_affinity = imsic_irq_set_affinity, +#endif .irq_retrigger = imsic_irq_retrigger, .irq_compose_msi_msg = imsic_irq_compose_msg, .flags = IRQCHIP_SKIP_SET_WAKE | @@ -245,7 +247,7 @@ static bool imsic_init_dev_msi_info(struct device *dev, if (WARN_ON_ONCE(domain != real_parent)) return false; #ifdef CONFIG_SMP - info->chip->irq_set_affinity = imsic_irq_set_affinity; + info->chip->irq_set_affinity = irq_chip_set_affinity_parent; #endif break; default: From patchwork Thu Nov 14 16:18:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875413 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D8BF1779AE for ; Thu, 14 Nov 2024 16:18:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601133; cv=none; b=mZEhnhHA8ZPmqCv8TV3B90eBUFKCQDHqKa6vw4r7ZAcjW0wF4VPfkj8KP2KaMOFQrxGtdKIPUfoFAVUOpKoAbKCVzGJbpnDBToo1zajQ6hT/UoMZp7OTD3KQuehpUHNCFrtmlw55dbUjlrLo6Vm43iniy6NFdvbF/mwlWTjvl/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601133; c=relaxed/simple; bh=Fk34GaC/hTLP6m0UNDLPdCaDiAz8BRxxGQykrmrUHjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AMZ78XKMUIr1Ijxsa+sSHj8a+H7OezIN3Q4PLJ3R6eH729uadV4YsoWgfqsQ+BTS3KaTwCCZZcF2bZ+QzCa1GTE5PiMt2qjrHbTCPxXjdXCd+cX6LQU8IRoZ+LqHRREV3LKk5VNdQNYGxG1liYstp6IWXUEQjD/u50MeSTO0xWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=ogM8fqbT; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="ogM8fqbT" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-382171e1a83so624280f8f.0 for ; Thu, 14 Nov 2024 08:18:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601130; x=1732205930; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4sV1q1LQk/q83S2J2BpeMk7gg4mJdAxo4Zufy5rZGAM=; b=ogM8fqbTMAIib6JisGUriwtAYFoUI7SYWbE3JembUiuwTAlOYGTbKCv9+bMne15a6b Cq1oobXNizib4H6EWAW/T0xdJ5C1OZwcPiz2KbCsg2ffSTuiuGxmQlNit04Xh4xs1LAc +mY0odhwcUY10Kn1g5xVufbYeh1v/xJtqOYZmRPzDBpbt6rSAcSUs/LeCb6bYMPs7RBf U6IOX6fkuMtZP7aXowbQgcecnKgzCmTaBUvf774WEbvp1tclst5/adllD2dy0X+lkaRS EMTxIapOfYuLWJI2769LDEiO+X5O5yGd5XuKVFrV0Mfv18BGSas63C7khn+BcjIazU8P NdSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601130; x=1732205930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4sV1q1LQk/q83S2J2BpeMk7gg4mJdAxo4Zufy5rZGAM=; b=jkp6GsHmkMouMYftx41qnLy1UTih1stWCzUUgk7E8j/naNOKUYBdUNObXnMvxmIo7O 510G4YzYTAoEXEC7UB1O3f/tAqcaugy3cVhKGJd9C+UIMTmWsQsST+sAmqSdpPWbrnsH /WZemTS46AIP/LrA2rbJzJ+y/emX/mvPuTEpcjptl/cmnNpBr42Z+88sU6vGAVF3Rq9s lt/s/KjmlsWe1a+fOiz7tYi7vDUJMwSUyGUICwR4IwTelFP8PdqY5E6Bw3xQtFOrCcFd Gwy5fkvA+aB9S5auHR0BpH7XZfm9zuP/zsYNPoJuZu7POjsLFJARG3sJRrLuWHRA1Vzc gG5Q== X-Forwarded-Encrypted: i=1; AJvYcCXazpce9ACQTj6AcWjKVuIGRy9nTQQgmoefa15t3RwpJ2Twk0IzF+W+K/5Qf0yNze95NvE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5JF4/sAjkh8m5ozrkyDac6qBpUwRsZiNhaNaZhNZJXvVLmtlt RmTaAr3+MOjeyv2uRthT97nnJCW3Kb3G6sSDB9IMWyl62in24rOFAJ4FHZo8OG0= X-Google-Smtp-Source: AGHT+IG+PIdlvaNPVTcrNev34iOeURvR6kwzzOllPVjWxdCbuE/GqDAX+WoRpo6pTqFd8njujj53Ow== X-Received: by 2002:a05:6000:2a10:b0:382:2084:19b3 with SMTP id ffacd0b85a97d-38220844ac9mr1324585f8f.22.1731601129621; Thu, 14 Nov 2024 08:18:49 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432da265c45sm28633555e9.11.2024.11.14.08.18.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:18:49 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 02/15] genirq/msi: Provide DOMAIN_BUS_MSI_REMAP Date: Thu, 14 Nov 2024 17:18:47 +0100 Message-ID: <20241114161845.502027-19-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Provide a domain bus token for the upcoming support for the RISC-V IOMMU interrupt remapping domain, which needs to be distinguished from NEXUS domains. The new token name is generic, as the only information that needs to be conveyed is that the IRQ domain will remap MSIs, i.e. there's nothing RISC-V specific to convey. Signed-off-by: Andrew Jones --- include/linux/irqdomain_defs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/irqdomain_defs.h b/include/linux/irqdomain_defs.h index 36653e2ee1c9..676eca8147ae 100644 --- a/include/linux/irqdomain_defs.h +++ b/include/linux/irqdomain_defs.h @@ -27,6 +27,7 @@ enum irq_domain_bus_token { DOMAIN_BUS_AMDVI, DOMAIN_BUS_DEVICE_MSI, DOMAIN_BUS_WIRED_TO_MSI, + DOMAIN_BUS_MSI_REMAP, }; #endif /* _LINUX_IRQDOMAIN_DEFS_H */ From patchwork Thu Nov 14 16:18:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875415 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18B7A185B6D for ; Thu, 14 Nov 2024 16:18:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601134; cv=none; b=rM0Dplagbz1l8zrsv5jsqKxIVCOT8I/dQSENkaBPxESpn4rz1PlHHUREZ60ptSdmyCAnL/HGWhZNjBQeT64RQq8tqf12jSVt+bnxLDfOPPYNz+AIXfgrxnBUA/08+kxcSDkhWAmGjzjcFIGAJ1bmJzADEHdwvziFVAzicoZM9IA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601134; c=relaxed/simple; bh=NzQJBoC/AMGjdcz5fUxYJHaJ2T5WgutxrlJ2H2gtLTs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CPCPvBvIN0G0afEH1qNCQV1jfmPHlNBzKaKlJKrYHnD6qXgOtDg+ljwi5FhCXpOLH4LcqIyEtstAehIb/nhtIUdkPVGe4BPhmLtWS9y31sfs9y3ihtqQ6kCv1Xx7f9aChqZHYvaKKk9kE+/xkOAaWvQYw/vuakQLXB/Qnit5qUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=h5B7kqKt; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="h5B7kqKt" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-53b34ed38easo822049e87.0 for ; Thu, 14 Nov 2024 08:18:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601131; x=1732205931; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EgkdpOYsLIOn0iKAKl5fgt6eXL8Mzl+XIucJ8fWc9TA=; b=h5B7kqKtNlz0keBSJ6L9z3uNVroLZMvCO7rHbNBSELLix0MPQeWidHSSHgtozh1Qxw rQPbbka2ZCerR68GE6loC6UUBnuJgjWC2dipbRo1u+d/+IbwTKwgPmK0C5patPP99VO7 Jrx2i/dCcEN1+Lx9ZJyT+zXgmHNCmGIkdvqLS5U6PvnrW6/IVPYrPNhPMzSjMsaV1jHB lpfIsgIl/7trYNUNxGhyFshmWivhzB7PQl7jvxvzp1JJPBrOd1VbOORPLl3Bi1X0ENjm EujcdBFGfqLe9w3q1AO508CZz3eVRaW7WMhf3RtuTPUodQMDt0Rk3kQ/DQ+DseJVBTN5 RdFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601131; x=1732205931; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EgkdpOYsLIOn0iKAKl5fgt6eXL8Mzl+XIucJ8fWc9TA=; b=fnYgFwKHfQB6jEK5SjMtESWbqJAftiRK6snm8aDcgZsCVudwhr1saZL1M6Z5fvTkkA O3QNl/+P9Z/2YYJC5GSTbCyYexdiZgZFxuoYcOJ0g9dhVTWXTUpa1x/VEtpevCmhWPb1 BmN54MIg92DKmZrDSjAJo3mep5sb6yU/uCjEctu+8CQnlmiXwxewFN7gFmoZw+w65R50 Eni+3grRF9ayAZ0UYFwBX7DQkQLkRYEVT28JRdYOjU3dgGyh5jfvK1bwQpxl4wHzll/s W//rwQ7+dpL+LNu4FuYT1C0cPiZiHBnru3uSXFWZUuOJnPV87qii2/wFgX+WOR962STp xE6Q== X-Forwarded-Encrypted: i=1; AJvYcCVMA3EjBzVEXKDKHTcqw6AMLUriZGPbNazU3imI78vpk5uABdtIvR31X9eyOA9KuYS/AJw=@vger.kernel.org X-Gm-Message-State: AOJu0YyyYCYYoputNqItdHzn/nm9VGfFWI2EfgK9TyfgKvjXWmwx3uuX wYtV1u2cCgjzQ1xd1DbL8nau1UmIJ/lJ1p2xkYchfTRQlEowZWT6xn1o+mfNjYE= X-Google-Smtp-Source: AGHT+IFd0CnkIMN5l0Pz4D+G0QBgRZi3KYTDXcb5xA9gQJqvW8wTertCqu9+xj4IWnW1G55hIkNGVw== X-Received: by 2002:a05:6512:3ca5:b0:539:f607:1d2b with SMTP id 2adb3069b0e04-53d862b45e5mr14144215e87.7.1731601131046; Thu, 14 Nov 2024 08:18:51 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dac1f409sm24906005e9.37.2024.11.14.08.18.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:18:50 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 03/15] irqchip/riscv-imsic: Add support for DOMAIN_BUS_MSI_REMAP Date: Thu, 14 Nov 2024 17:18:48 +0100 Message-ID: <20241114161845.502027-20-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Unlike a child of an MSI NEXUS domain, a child of an MSI_REMAP domain will not invoke init_dev_msi_info() with 'domain' equal to 'msi_parent_domain'. This is because the MSI_REMAP domain implements init_dev_msi_info() with msi_parent_init_dev_msi_info(), which makes 'domain' point to the NEXUS (IMSIC) domain, while keeping 'msi_parent_domain' pointing to itself. The rest of the IMSIC init_dev_msi_info() implementation works for MSI_REMAP domains, though, so there's nothing to do to add support except accept the token. Signed-off-by: Andrew Jones --- drivers/irqchip/irq-riscv-imsic-platform.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/irq-riscv-imsic-platform.c index 5d7c30ad8855..6a7d7fefda6a 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -246,6 +246,8 @@ static bool imsic_init_dev_msi_info(struct device *dev, case DOMAIN_BUS_NEXUS: if (WARN_ON_ONCE(domain != real_parent)) return false; + fallthrough; + case DOMAIN_BUS_MSI_REMAP: #ifdef CONFIG_SMP info->chip->irq_set_affinity = irq_chip_set_affinity_parent; #endif From patchwork Thu Nov 14 16:18:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875417 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22D4118A930 for ; Thu, 14 Nov 2024 16:18:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601136; cv=none; b=QuqFvvayr+7iaTYuqbMgS5oOaOnKbixwATDf3K1MYc611X1jRD3c1gW5uo0FPBkIix8ftCAKHY8UGAdflURBJ7OTtTXnUMwughoMaxvulaKgjq3S5EXZGDYfVOgkB8Q7j7Ka3otk7boTd2/j2LxiIkvIdMaVcgEUBdskhsY3ljo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601136; c=relaxed/simple; bh=0mPWdQkW2KKBDaAhQDqapvf02Htw+fq40OqWkKngxqU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CsJNGTvVXyufk4bJbcBZVM+E7UbLMArkJSC/StRDTCG/kR/GKAoa2tCHqDmAOTeoaiDDNc/KbKoX+4OT0et6K/ELysBWFgMP9LH/10jBy20nCuK13Zm4dhrzr5IcXVgxbcLrd9FrUHWvber7koFBZI1FsJ4soHtpiGDvutPD2Ro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=oHbOPHBU; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="oHbOPHBU" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-431695fa98bso6928255e9.3 for ; Thu, 14 Nov 2024 08:18:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601132; x=1732205932; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o3RScEb/zQMeNBIY0PtZD1/ZjJQ2IegD9nNkwkqM6gc=; b=oHbOPHBUelHfY0VEbF0nTmwmxbT5sLJwpWWYtzvmb48Fx+muiDlYOrzYqK+2RW7F5c gCRJK3btEmsj1XrAz7nO9vE+d1I+Taeglw3B3cErFh7V6pMpzrF0QwMgJ92XZmUtIEcQ Yue6uT096Iyc58nVKpJ+Jpoe22VG1VokY0zMrcNia0AcLC8hv0CNOEwmgp+nBt+ZrMC9 z1msiUAqTSxt62HmbtiQ3rVAtDIBtAr2dJYL0tUUoaDGLKRcwHovCSZ9WagjA7zAR3bS 61pPNa8NoyHD3IyJYH1h/gmUUpGuJHaLOjxED+467qRemMjtl8cCjCnOSuRFqOPQu27K hfcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601132; x=1732205932; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o3RScEb/zQMeNBIY0PtZD1/ZjJQ2IegD9nNkwkqM6gc=; b=RX4FYz2LKz+X7Kc36zOGs7l4/sWXcyF+myzLxZCtD59SOxA0gpbQ9saJrzTpX7nSyQ DgwW4jfMRrINxSj2HtO/mNQBwvQaL/hosQb4ip522cNo40dp4TeVdYfCYOL8yHtyDWfe Y1gAAXYPsxk5gkGAT0+QxOjismWPLrYggVkYmdXfVeRUqy+6QKlwiGXb0jWhcgasCLbH aN00IxoIOBFe79/ZnuH8llLHl5T/gPd2GBlEt65ahX2tejLAmS3dvPBs0DMf5saefE+Y Ywf1NMfp2RTuXDewF8/NTfIb8lI7eIts4OexXBOdmW0yOi0yu/dh7qD0GmtXHkZJCeh1 4QsQ== X-Forwarded-Encrypted: i=1; AJvYcCUuurdNqSgncXGb7wDo3EF80ya69myulZzDuQdm3flfikRxnvkeSIp2U/t72XfTrVeZTeU=@vger.kernel.org X-Gm-Message-State: AOJu0YxSAdh7+SndGV00X2SGeaSokc/UmafQgb9ZWqQBovYpcdr9pKkl c0dxOH7IzAddkqa0Sh2dWOYXe9/e1aNb7CuKpXvRG6lDT+PcYuKWJMghCYrP0NQ= X-Google-Smtp-Source: AGHT+IETarykQuvm6+z3/CASGfAXpcrdoszeWN3rsEIL+bc92gQplNjgpnYXoIwCDFze+tOTvORF1Q== X-Received: by 2002:a05:600c:3c8f:b0:431:4e25:fe42 with SMTP id 5b1f17b1804b1-432b751e28fmr192523985e9.32.1731601132365; Thu, 14 Nov 2024 08:18:52 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab72184sm24967935e9.2.2024.11.14.08.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:18:51 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 04/15] iommu/riscv: report iommu capabilities Date: Thu, 14 Nov 2024 17:18:49 +0100 Message-ID: <20241114161845.502027-21-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Tomasz Jeznach Report RISC-V IOMMU capabilities required by VFIO subsystem to enable PCIe device assignment. Signed-off-by: Tomasz Jeznach Signed-off-by: Andrew Jones --- drivers/iommu/riscv/iommu.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 8a05def774bd..3fe4ceba8dd3 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -1462,6 +1462,17 @@ static struct iommu_group *riscv_iommu_device_group(struct device *dev) return generic_device_group(dev); } +static bool riscv_iommu_capable(struct device *dev, enum iommu_cap cap) +{ + switch (cap) { + case IOMMU_CAP_CACHE_COHERENCY: + case IOMMU_CAP_DEFERRED_FLUSH: + return true; + default: + return false; + } +} + static int riscv_iommu_of_xlate(struct device *dev, const struct of_phandle_args *args) { return iommu_fwspec_add_ids(dev, args->args, 1); @@ -1526,6 +1537,7 @@ static void riscv_iommu_release_device(struct device *dev) static const struct iommu_ops riscv_iommu_ops = { .pgsize_bitmap = SZ_4K, .of_xlate = riscv_iommu_of_xlate, + .capable = riscv_iommu_capable, .identity_domain = &riscv_iommu_identity_domain, .blocked_domain = &riscv_iommu_blocking_domain, .release_domain = &riscv_iommu_blocking_domain, From patchwork Thu Nov 14 16:18: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: 13875419 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C487418C326 for ; Thu, 14 Nov 2024 16:18:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601137; cv=none; b=clOVWIIBksvYvkkErncL0yN2fRAGSXZGOkLhYNVYPJJqPtVseZoB+PYdGVX1kdFhlWcGYNIjW2lDJzM9Gm6bEzhMwC6An05/S38cKd6hxcF/q32EWoZp1MGo+f55KlFp+TdVmkQHniVrd+luk7DrHZZ5mLhD3+g7jdHZ+GlfhKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601137; c=relaxed/simple; bh=Eb4pr4WluxpATHyk/B5wEDuQM3N608Zzf1YYtlCp/dw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WQwkYnjmy+KfbgSxZKj8ewDOjnMtu0v6Nx8S2yxmi6nDQ8boCUZIDYgO01B6xp0BYj33lSt4MoECfhdgnc9ujQSBvofvzbPx0NRLKGmqanzaQhjD6soxVQFw6fiSUMkXCpGGpWApBLL+uoRjtE+VIKk+LbiX1GHw9fn8NsEWG4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=FN9smk4z; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="FN9smk4z" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-539f84907caso848309e87.3 for ; Thu, 14 Nov 2024 08:18:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601134; x=1732205934; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ro7v641M+HDwWifuZZcr9Q07sHhkgURxU5TLhKMU2Mo=; b=FN9smk4zEni5TTrZlNz/bPZesL1r0schg0VCtLsT1Ss0GKqYVMWxVIGZ9GDk/0oW6z +3pubecEYYIEauGVHH6c0p0d90Ri0lpSqstQ2dCTPAiKDRzRW1vLw5KijY1Ax8SP2XBQ qLp7rvt5OZhY8wpXRKOlNYGXMBdPoWokQ15lTpPt18RSbSXQeTGUMXtm9pu1ED+NNEqD EeNtDVRFBHnSs3AZbePAugFxVaYKqk+hePSCqG1ov1PwuqNcQuIl0UyflcLvf3GVzDT3 LbP68PDi9bEpbDLcbfipe5GipoIt2cIVM9memB2NPIJHhHrtGWwcsrsKTytqqhCr5iQB ccHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601134; x=1732205934; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ro7v641M+HDwWifuZZcr9Q07sHhkgURxU5TLhKMU2Mo=; b=aVY5xTu7Jiw3U8Z23Uhqy2BwjUOhwuiWLLJ+q4+ZhVt4nG/kJlwRN6xnEY7WA4H550 GscP3leo2TFkxDvIbuLUJvALIAx195iNPD83i7i6CA0DqtHjZleH/QptON6TKJIrFBP4 Q87V6zW9fyIk6o0pIq5697bSVYqhaTjhW4xJCztrgMnt/N7/1cuqS0GUnMISMjpEpDQp qqeht+YrL0vEzDgYlktG1F5d5Y1mDeHESdax1e05V6mw0W5HIuph+3/6STRz8kKsXKkS 3jCCxQ+H29zzGJMepuKFG8HNmqVHe7Y+aOU7B8dBpfFx1eDStPSICjqUySf+pVV+O5Tq OHHw== X-Forwarded-Encrypted: i=1; AJvYcCVkiIcCKKsAzLqKhkZGKsX9Z2A50R7WDgZAIV1aRv05QVAHWaNJ/HOlgTN5wgM+jEogMhY=@vger.kernel.org X-Gm-Message-State: AOJu0YxvkJgzK4VGAQYspqPpUeu7KgwGVgSERYfHmMF4RoUTbFUcMjKQ I+PGvpktNCsQHgyUAeHu7FwMn3LFMDHBDcfEooJxHhpwTYh5kFUioy70LyqhIHk= X-Google-Smtp-Source: AGHT+IErvh7GZ5g5xv9y/mHNwbC72YxK/U2el7s2R5QBHLBxBaMXMwoD7jtczGtgvCVqx0SU+SjOAw== X-Received: by 2002:a05:6512:baa:b0:53d:a34d:9faa with SMTP id 2adb3069b0e04-53da34da11emr2749757e87.45.1731601133876; Thu, 14 Nov 2024 08:18:53 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432da265e16sm28762605e9.12.2024.11.14.08.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:18:53 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 05/15] iommu/riscv: use data structure instead of individual values Date: Thu, 14 Nov 2024 17:18:50 +0100 Message-ID: <20241114161845.502027-22-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zong Li The parameter will be increased when we need to set up more bit fields in the device context. Use a data structure to wrap them up. Signed-off-by: Zong Li Signed-off-by: Andrew Jones --- drivers/iommu/riscv/iommu.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 3fe4ceba8dd3..9d7945dc3c24 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -1001,7 +1001,7 @@ static void riscv_iommu_iotlb_inval(struct riscv_iommu_domain *domain, * interim translation faults. */ static void riscv_iommu_iodir_update(struct riscv_iommu_device *iommu, - struct device *dev, u64 fsc, u64 ta) + struct device *dev, struct riscv_iommu_dc *new_dc) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct riscv_iommu_dc *dc; @@ -1035,10 +1035,10 @@ static void riscv_iommu_iodir_update(struct riscv_iommu_device *iommu, for (i = 0; i < fwspec->num_ids; i++) { dc = riscv_iommu_get_dc(iommu, fwspec->ids[i]); tc = READ_ONCE(dc->tc); - tc |= ta & RISCV_IOMMU_DC_TC_V; + tc |= new_dc->ta & RISCV_IOMMU_DC_TC_V; - WRITE_ONCE(dc->fsc, fsc); - WRITE_ONCE(dc->ta, ta & RISCV_IOMMU_PC_TA_PSCID); + WRITE_ONCE(dc->fsc, new_dc->fsc); + WRITE_ONCE(dc->ta, new_dc->ta & RISCV_IOMMU_PC_TA_PSCID); /* Update device context, write TC.V as the last step. */ dma_wmb(); WRITE_ONCE(dc->tc, tc); @@ -1315,20 +1315,20 @@ static int riscv_iommu_attach_paging_domain(struct iommu_domain *iommu_domain, struct riscv_iommu_domain *domain = iommu_domain_to_riscv(iommu_domain); struct riscv_iommu_device *iommu = dev_to_iommu(dev); struct riscv_iommu_info *info = dev_iommu_priv_get(dev); - u64 fsc, ta; + struct riscv_iommu_dc dc = {0}; if (!riscv_iommu_pt_supported(iommu, domain->pgd_mode)) return -ENODEV; - fsc = FIELD_PREP(RISCV_IOMMU_PC_FSC_MODE, domain->pgd_mode) | - FIELD_PREP(RISCV_IOMMU_PC_FSC_PPN, virt_to_pfn(domain->pgd_root)); - ta = FIELD_PREP(RISCV_IOMMU_PC_TA_PSCID, domain->pscid) | - RISCV_IOMMU_PC_TA_V; + dc.fsc = FIELD_PREP(RISCV_IOMMU_PC_FSC_MODE, domain->pgd_mode) | + FIELD_PREP(RISCV_IOMMU_PC_FSC_PPN, virt_to_pfn(domain->pgd_root)); + dc.ta = FIELD_PREP(RISCV_IOMMU_PC_TA_PSCID, domain->pscid) | + RISCV_IOMMU_PC_TA_V; if (riscv_iommu_bond_link(domain, dev)) return -ENOMEM; - riscv_iommu_iodir_update(iommu, dev, fsc, ta); + riscv_iommu_iodir_update(iommu, dev, &dc); riscv_iommu_bond_unlink(info->domain, dev); info->domain = domain; @@ -1419,9 +1419,12 @@ static int riscv_iommu_attach_blocking_domain(struct iommu_domain *iommu_domain, { struct riscv_iommu_device *iommu = dev_to_iommu(dev); struct riscv_iommu_info *info = dev_iommu_priv_get(dev); + struct riscv_iommu_dc dc = {0}; + + dc.fsc = RISCV_IOMMU_FSC_BARE; /* Make device context invalid, translation requests will fault w/ #258 */ - riscv_iommu_iodir_update(iommu, dev, RISCV_IOMMU_FSC_BARE, 0); + riscv_iommu_iodir_update(iommu, dev, &dc); riscv_iommu_bond_unlink(info->domain, dev); info->domain = NULL; @@ -1440,8 +1443,12 @@ static int riscv_iommu_attach_identity_domain(struct iommu_domain *iommu_domain, { struct riscv_iommu_device *iommu = dev_to_iommu(dev); struct riscv_iommu_info *info = dev_iommu_priv_get(dev); + struct riscv_iommu_dc dc = {0}; + + dc.fsc = RISCV_IOMMU_FSC_BARE; + dc.ta = RISCV_IOMMU_PC_TA_V; - riscv_iommu_iodir_update(iommu, dev, RISCV_IOMMU_FSC_BARE, RISCV_IOMMU_PC_TA_V); + riscv_iommu_iodir_update(iommu, dev, &dc); riscv_iommu_bond_unlink(info->domain, dev); info->domain = NULL; From patchwork Thu Nov 14 16:18: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: 13875421 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B78F18CC02 for ; Thu, 14 Nov 2024 16:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601138; cv=none; b=PxrAy801PMrTtANSIHrZgDYZ4cXuHfaK8mVjGWzAny/ZjilQdUOj+zoQNPzD46E8JIaMii7VzQV5vQov5Cmh12jMTbcfgcYkUWCikKE3RPvs3r2kxGjLrfDer+2lq8oVsB9LCXePXTS39+2ND/R/2IkoiaNbDcHJt54My37eqkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601138; c=relaxed/simple; bh=mSKDSl3GLSiOekZPsY51mXQ0nJSnVkEWku0uYPCWFJs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=stXE6GQQZKsklgXyojQ1ZGtzrgEVACNq0W/fdgFwrSbICjWKeoztx7GK+xrt0mO6fza2rsKgaHgc/KCdD9Ck6Jaw9X9W7urwyzbMXVzOjMFODQWFPrsEAJ5jsqV+neIOZT1Qym+zG5gCORYvaV4TuTfT8OnXVHg4n67trjjZLow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=cX1cxQMB; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="cX1cxQMB" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-431695fa98bso6928705e9.3 for ; Thu, 14 Nov 2024 08:18:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601135; x=1732205935; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yp1usq1fK4gxtiGD08iHEFdZ4WeofRrQEoktS1P9VL0=; b=cX1cxQMBXTX7F9Pk1bIKY5KFFO+cqFpldRJ0lomT6vn9gErKBKfgcwR37xmzgzv4Ac ft9msctJoHzZ5ZwBTJyCQMGfTVJl392hQV2DlkNW8ZYNNJ+sPSTDfWSd0MvOZBAthhIf r614Az7ZO4s4f/5kcswtsFhEWcZ3bLKaVGu2YUC/6eWZJk4y5D8IMrr2/Isg4KrJvObz CMIcQgCnbb2Oriws2LLjcqiuFLlWEaLn/OzvcN7fvoMT/BLkYEKRLd++eiZBnAqM4/u8 bBummUMtP2lIeR8rjhE4srp+WPd+7oGnW31Mg0CkuZ9UuE8XUtbdv+Zjx5FxiN4wpv+K OphQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601135; x=1732205935; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yp1usq1fK4gxtiGD08iHEFdZ4WeofRrQEoktS1P9VL0=; b=xJwTj/nukJ4uFOLda6ITJcxQJPV8HvbOuOthu/AwJnhdMvSDqFjpe8K2nNk4qO/RIA kuG7XmzvGc7SWKRI+AJrp1mikTL1lVgcDOA3viGf8MjfkmsPs0VtlkejKF8ZLBJZyRhF ogG0GMbRstZwyCqDWtHLrubYzYnu9vL5mgWnRR7dMcuXBvlqSoLRDvayxf7KfjUwmU8b tIWCSKBMe7OqCTtGBXLbjvp4yxWPTbCoHhqlgpC2OQeUnt8iJ7xg6Gn4luFnl1ih+lKH sK7el465eU+l++ft1E/sqItzOaZcH+BmHpeHEFSFC/cONuR0HSKXt884JLpj1t/thzb6 X6PQ== X-Forwarded-Encrypted: i=1; AJvYcCX5yxyjjsj60mBtPcnXBxZKyrLh8GxEKndUwrjnZQl7AhgiTo9YSKVsct+0YQLkx5pTy4s=@vger.kernel.org X-Gm-Message-State: AOJu0YyjS9Oro5x/OKLBO7tKCK1YWn+rriZaNYD3E24zumFSOgLOszfw j9cFC13ccRqsDRUTUDD1fwL4yaZ7zGoSkB/A7KwBG0lY5e+LZ7IFC4w4Efg+0tM= X-Google-Smtp-Source: AGHT+IFyYvgOotPy1xBLjJZdRQpK5gbKBNQ63i5f7cylok3AbHGEDqsRn2z3h347XR748S8k1vlXxg== X-Received: by 2002:a05:600c:3ca4:b0:42c:a6da:a149 with SMTP id 5b1f17b1804b1-432b751839dmr220940445e9.25.1731601135291; Thu, 14 Nov 2024 08:18:55 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432da27fc8esm29713515e9.21.2024.11.14.08.18.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:18:54 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 06/15] iommu/riscv: support GSCID and GVMA invalidation command Date: Thu, 14 Nov 2024 17:18:51 +0100 Message-ID: <20241114161845.502027-23-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zong Li This patch adds a ID Allocator for GSCID and a wrap for setting up GSCID in IOTLB invalidation command. Set up iohgatp to enable second stage table and flush stage-2 table if the GSCID is set. The GSCID of domain should be freed when release domain. GSCID will be allocated for parent domain in nested IOMMU process. Signed-off-by: Zong Li Signed-off-by: Andrew Jones --- drivers/iommu/riscv/iommu-bits.h | 7 +++++++ drivers/iommu/riscv/iommu.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/riscv/iommu-bits.h b/drivers/iommu/riscv/iommu-bits.h index 98daf0e1a306..d72b982cf9bf 100644 --- a/drivers/iommu/riscv/iommu-bits.h +++ b/drivers/iommu/riscv/iommu-bits.h @@ -715,6 +715,13 @@ static inline void riscv_iommu_cmd_inval_vma(struct riscv_iommu_command *cmd) cmd->dword1 = 0; } +static inline void riscv_iommu_cmd_inval_gvma(struct riscv_iommu_command *cmd) +{ + cmd->dword0 = FIELD_PREP(RISCV_IOMMU_CMD_OPCODE, RISCV_IOMMU_CMD_IOTINVAL_OPCODE) | + FIELD_PREP(RISCV_IOMMU_CMD_FUNC, RISCV_IOMMU_CMD_IOTINVAL_FUNC_GVMA); + cmd->dword1 = 0; +} + static inline void riscv_iommu_cmd_inval_set_addr(struct riscv_iommu_command *cmd, u64 addr) { diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 9d7945dc3c24..ef38a1bb3eca 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -45,6 +45,10 @@ static DEFINE_IDA(riscv_iommu_pscids); #define RISCV_IOMMU_MAX_PSCID (BIT(20) - 1) +/* IOMMU GSCID allocation namespace. */ +static DEFINE_IDA(riscv_iommu_gscids); +#define RISCV_IOMMU_MAX_GSCID (BIT(16) - 1) + /* Device resource-managed allocations */ struct riscv_iommu_devres { void *addr; @@ -801,6 +805,7 @@ struct riscv_iommu_domain { struct list_head bonds; spinlock_t lock; /* protect bonds list updates. */ int pscid; + int gscid; bool amo_enabled; int numa_node; unsigned int pgd_mode; @@ -954,15 +959,20 @@ static void riscv_iommu_iotlb_inval(struct riscv_iommu_domain *domain, /* * IOTLB invalidation request can be safely omitted if already sent - * to the IOMMU for the same PSCID, and with domain->bonds list + * to the IOMMU for the same PSCID/GSCID, and with domain->bonds list * arranged based on the device's IOMMU, it's sufficient to check * last device the invalidation was sent to. */ if (iommu == prev) continue; - riscv_iommu_cmd_inval_vma(&cmd); - riscv_iommu_cmd_inval_set_pscid(&cmd, domain->pscid); + if (domain->gscid) { + riscv_iommu_cmd_inval_gvma(&cmd); + riscv_iommu_cmd_inval_set_gscid(&cmd, domain->gscid); + } else { + riscv_iommu_cmd_inval_vma(&cmd); + riscv_iommu_cmd_inval_set_pscid(&cmd, domain->pscid); + } if (len && len < RISCV_IOMMU_IOTLB_INVAL_LIMIT) { for (iova = start; iova < end; iova += PAGE_SIZE) { riscv_iommu_cmd_inval_set_addr(&cmd, iova); @@ -1039,6 +1049,7 @@ static void riscv_iommu_iodir_update(struct riscv_iommu_device *iommu, WRITE_ONCE(dc->fsc, new_dc->fsc); WRITE_ONCE(dc->ta, new_dc->ta & RISCV_IOMMU_PC_TA_PSCID); + WRITE_ONCE(dc->iohgatp, new_dc->iohgatp); /* Update device context, write TC.V as the last step. */ dma_wmb(); WRITE_ONCE(dc->tc, tc); @@ -1287,8 +1298,10 @@ static void riscv_iommu_free_paging_domain(struct iommu_domain *iommu_domain) WARN_ON(!list_empty(&domain->bonds)); - if ((int)domain->pscid > 0) + if (domain->pscid > 0) ida_free(&riscv_iommu_pscids, domain->pscid); + if (domain->gscid > 0) + ida_free(&riscv_iommu_gscids, domain->gscid); riscv_iommu_pte_free(domain, _io_pte_entry(pfn, _PAGE_TABLE), NULL); kfree(domain); @@ -1320,8 +1333,15 @@ static int riscv_iommu_attach_paging_domain(struct iommu_domain *iommu_domain, if (!riscv_iommu_pt_supported(iommu, domain->pgd_mode)) return -ENODEV; - dc.fsc = FIELD_PREP(RISCV_IOMMU_PC_FSC_MODE, domain->pgd_mode) | - FIELD_PREP(RISCV_IOMMU_PC_FSC_PPN, virt_to_pfn(domain->pgd_root)); + if (domain->gscid) { + dc.iohgatp = FIELD_PREP(RISCV_IOMMU_DC_IOHGATP_MODE, domain->pgd_mode) | + FIELD_PREP(RISCV_IOMMU_DC_IOHGATP_GSCID, domain->gscid) | + FIELD_PREP(RISCV_IOMMU_DC_IOHGATP_PPN, virt_to_pfn(domain->pgd_root)); + } else { + dc.fsc = FIELD_PREP(RISCV_IOMMU_PC_FSC_MODE, domain->pgd_mode) | + FIELD_PREP(RISCV_IOMMU_PC_FSC_PPN, virt_to_pfn(domain->pgd_root)); + } + dc.ta = FIELD_PREP(RISCV_IOMMU_PC_TA_PSCID, domain->pscid) | RISCV_IOMMU_PC_TA_V; From patchwork Thu Nov 14 16:18: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: 13875423 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4500E19047E for ; Thu, 14 Nov 2024 16:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601143; cv=none; b=UdJyiY13aPiUHVJQ4puMIoa58EYN1RlvP/hhuo9V8MXaKlrQ5WAXiCjwAJDtiZTkvYOJFpP+eGTlVMO2A4KHeZuWGA0L2BYB5Eu2Ae5UHJ4awRFXyQLnAGnL+7UtjVtkItUE/Cj4pF1FGQmVU8TWTtrQgfv1bhkDhgQhSpAqZEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601143; c=relaxed/simple; bh=+5wAhC0R7frfuir1SgBtFwo6bPSVn4yPznFFFiLyIwk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GwXDQvFsKhJKZbrkz0rpkkeHFF/EWnPT9f9QORgtoYkoB1yoBkK+GJ3OSy1EXu6E9ICuk+bYEX95q9LNhJDOrGJaH0fT7Dq0VOY9UBUOpvxbyBifHmr3hFF6GlHVfpgyNSfWgnPv1bj1f5AFa4b8/7UzBrLT3TMID4JjWmPyrd8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=QGJgIDhb; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="QGJgIDhb" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-43161e7bb25so7032725e9.2 for ; Thu, 14 Nov 2024 08:19:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601140; x=1732205940; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L/DCjdoH/ZMLdfMdshfw9p7vCmVOtJEZSwKkAynWgoM=; b=QGJgIDhbAkAAY/B6opqYckVlEyHcaYHjA1IWoeuwxDzBmgfIy4AZwaBs88eMOUOCjb TIa2tQ1mmSC9k0v7j1TKlaj6x86b/c5BFThQ652X1esxVA2Oc5IBh/gWRAinK+eA3a/r NF6qCTDpc/BSJxekqWQxrlUGtUqPULXzmt5reU0x41aJsO5DSgSPcv3fqqZmtt8H9U60 0lyF5sl0hfPUYiqchrbuLNmUSmYWLsoiKr2ysrtUU/hxNIxGQn0ik/tbSgISn57OnqCR RNiMAifwqZrL1oypd0Co9P6z0XBBhpEvlGUaGGojT+zY19hbeqP88gixi4J0dPr0lJIS 9KuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601140; x=1732205940; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L/DCjdoH/ZMLdfMdshfw9p7vCmVOtJEZSwKkAynWgoM=; b=n/jK2PFGZ1J/AkJ4dWKu6IQFSlHddUlbdJO92nQF6baCBLDOt4SIaFXR8OsqKMy51f hYEYLK2eMqSkjc3Z3VXPPH0vsYVv3LxH19iJ3Kw8W1Kv8yEvzFfGq0D5EJA36z+e+Qlg FPqZQdqYeYu5zvUm0XUp9wf7bR85bHgriLa+eObXfCd49ZnHYzK4zN2k/eDaBbzS+Qi2 R4e6KU1QiIBb6WCqsaDpbVcKv52g/ZX0CRPzJvxBF9xtEvegKp0JxO4nYQyCWoTjhhcP LIjTdseplVJ4dvouh6SOXOcP8iyZk7GEHXt5oixiLayjjhy9bjQy94f3qIPpE6UYh7nc J1Fw== X-Forwarded-Encrypted: i=1; AJvYcCXZQySmep6hjNriuTrP8vQunWfA1scIURUVqVxFsd+tBeAhptwATaaSrWnBp6CZpOr7WjA=@vger.kernel.org X-Gm-Message-State: AOJu0YyzmqGm3UOZ+Q7b7WfCzNXmOSS8yDRxCDFJIdYGWAQu80sImS9u +UlW6wbk4LHgsi3xccL/9hJBaHLCPXEzI2r835U5zcj1yjhu6GeOX5SSqXgxEkS1/Y9blJvnrdy lrOI= X-Google-Smtp-Source: AGHT+IFaQ4hpn9NQyC7cNnSLRB13MgnD04TaYJf6YLnF9bvsb+UpgbykQ8H4jk6OiPjoZJw0SQKo9A== X-Received: by 2002:a05:600c:5247:b0:42c:b63e:fe91 with SMTP id 5b1f17b1804b1-432cd474820mr91410355e9.24.1731601139559; Thu, 14 Nov 2024 08:18:59 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dac1f94asm25135835e9.39.2024.11.14.08.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:18:59 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 07/15] iommu/riscv: Move definitions to iommu.h Date: Thu, 14 Nov 2024 17:18:52 +0100 Message-ID: <20241114161845.502027-24-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In order to add the interrupt remapping support in a separate file, share definitions through the header, as well as making some functions public. Signed-off-by: Andrew Jones --- drivers/iommu/riscv/iommu-bits.h | 4 ++ drivers/iommu/riscv/iommu.c | 71 ++++---------------------------- drivers/iommu/riscv/iommu.h | 54 ++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 62 deletions(-) diff --git a/drivers/iommu/riscv/iommu-bits.h b/drivers/iommu/riscv/iommu-bits.h index d72b982cf9bf..d3d98dbed709 100644 --- a/drivers/iommu/riscv/iommu-bits.h +++ b/drivers/iommu/riscv/iommu-bits.h @@ -36,6 +36,10 @@ #define RISCV_IOMMU_ATP_PPN_FIELD GENMASK_ULL(43, 0) #define RISCV_IOMMU_ATP_MODE_FIELD GENMASK_ULL(63, 60) +/* RISC-V IOMMU PPN <> PHYS address conversions, PHYS <=> PPN[53:10] */ +#define riscv_iommu_phys_to_ppn(pa) (((pa) >> 2) & (((1ULL << 44) - 1) << 10)) +#define riscv_iommu_ppn_to_phys(pn) (((pn) << 2) & (((1ULL << 44) - 1) << 12)) + /* 5.3 IOMMU Capabilities (64bits) */ #define RISCV_IOMMU_REG_CAPABILITIES 0x0000 #define RISCV_IOMMU_CAPABILITIES_VERSION GENMASK_ULL(7, 0) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index ef38a1bb3eca..6e8ea3d22ff5 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -24,23 +24,10 @@ #include "iommu-bits.h" #include "iommu.h" -/* Timeouts in [us] */ -#define RISCV_IOMMU_QCSR_TIMEOUT 150000 -#define RISCV_IOMMU_QUEUE_TIMEOUT 150000 -#define RISCV_IOMMU_DDTP_TIMEOUT 10000000 -#define RISCV_IOMMU_IOTINVAL_TIMEOUT 90000000 - /* Number of entries per CMD/FLT queue, should be <= INT_MAX */ #define RISCV_IOMMU_DEF_CQ_COUNT 8192 #define RISCV_IOMMU_DEF_FQ_COUNT 4096 -/* RISC-V IOMMU PPN <> PHYS address conversions, PHYS <=> PPN[53:10] */ -#define phys_to_ppn(pa) (((pa) >> 2) & (((1ULL << 44) - 1) << 10)) -#define ppn_to_phys(pn) (((pn) << 2) & (((1ULL << 44) - 1) << 12)) - -#define dev_to_iommu(dev) \ - iommu_get_iommu_dev(dev, struct riscv_iommu_device, iommu) - /* IOMMU PSCID allocation namespace. */ static DEFINE_IDA(riscv_iommu_pscids); #define RISCV_IOMMU_MAX_PSCID (BIT(20) - 1) @@ -177,7 +164,7 @@ static int riscv_iommu_queue_alloc(struct riscv_iommu_device *iommu, if (!queue->base) return -ENOMEM; - qb = phys_to_ppn(queue->phys) | + qb = riscv_iommu_phys_to_ppn(queue->phys) | FIELD_PREP(RISCV_IOMMU_QUEUE_LOG2SZ_FIELD, logsz); /* Update base register and read back to verify hw accepted our write */ @@ -480,15 +467,15 @@ static irqreturn_t riscv_iommu_cmdq_process(int irq, void *data) } /* Send command to the IOMMU command queue */ -static void riscv_iommu_cmd_send(struct riscv_iommu_device *iommu, - struct riscv_iommu_command *cmd) +void riscv_iommu_cmd_send(struct riscv_iommu_device *iommu, + struct riscv_iommu_command *cmd) { riscv_iommu_queue_send(&iommu->cmdq, cmd, sizeof(*cmd)); } /* Send IOFENCE.C command and wait for all scheduled commands to complete. */ -static void riscv_iommu_cmd_sync(struct riscv_iommu_device *iommu, - unsigned int timeout_us) +void riscv_iommu_cmd_sync(struct riscv_iommu_device *iommu, + unsigned int timeout_us) { struct riscv_iommu_command cmd; unsigned int prod; @@ -614,7 +601,7 @@ static struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iomm do { ddt = READ_ONCE(*(unsigned long *)ddtp); if (ddt & RISCV_IOMMU_DDTE_V) { - ddtp = __va(ppn_to_phys(ddt)); + ddtp = __va(riscv_iommu_ppn_to_phys(ddt)); break; } @@ -622,7 +609,7 @@ static struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iomm if (!ptr) return NULL; - new = phys_to_ppn(__pa(ptr)) | RISCV_IOMMU_DDTE_V; + new = riscv_iommu_phys_to_ppn(__pa(ptr)) | RISCV_IOMMU_DDTE_V; old = cmpxchg_relaxed((unsigned long *)ddtp, ddt, new); if (old == ddt) { @@ -687,7 +674,7 @@ static int riscv_iommu_iodir_alloc(struct riscv_iommu_device *iommu) if (ddtp & RISCV_IOMMU_DDTP_BUSY) return -EBUSY; - iommu->ddt_phys = ppn_to_phys(ddtp); + iommu->ddt_phys = riscv_iommu_ppn_to_phys(ddtp); if (iommu->ddt_phys) iommu->ddt_root = devm_ioremap(iommu->dev, iommu->ddt_phys, PAGE_SIZE); @@ -734,7 +721,7 @@ static int riscv_iommu_iodir_set_mode(struct riscv_iommu_device *iommu, do { rq_ddtp = FIELD_PREP(RISCV_IOMMU_DDTP_IOMMU_MODE, rq_mode); if (rq_mode > RISCV_IOMMU_DDTP_IOMMU_MODE_BARE) - rq_ddtp |= phys_to_ppn(iommu->ddt_phys); + rq_ddtp |= riscv_iommu_phys_to_ppn(iommu->ddt_phys); riscv_iommu_writeq(iommu, RISCV_IOMMU_REG_DDTP, rq_ddtp); ddtp = riscv_iommu_read_ddtp(iommu); @@ -799,49 +786,9 @@ static int riscv_iommu_iodir_set_mode(struct riscv_iommu_device *iommu, return 0; } -/* This struct contains protection domain specific IOMMU driver data. */ -struct riscv_iommu_domain { - struct iommu_domain domain; - struct list_head bonds; - spinlock_t lock; /* protect bonds list updates. */ - int pscid; - int gscid; - bool amo_enabled; - int numa_node; - unsigned int pgd_mode; - unsigned long *pgd_root; -}; - #define iommu_domain_to_riscv(iommu_domain) \ container_of(iommu_domain, struct riscv_iommu_domain, domain) -/* Private IOMMU data for managed devices, dev_iommu_priv_* */ -struct riscv_iommu_info { - struct riscv_iommu_domain *domain; -}; - -/* - * Linkage between an iommu_domain and attached devices. - * - * Protection domain requiring IOATC and DevATC translation cache invalidations, - * should be linked to attached devices using a riscv_iommu_bond structure. - * Devices should be linked to the domain before first use and unlinked after - * the translations from the referenced protection domain can no longer be used. - * Blocking and identity domains are not tracked here, as the IOMMU hardware - * does not cache negative and/or identity (BARE mode) translations, and DevATC - * is disabled for those protection domains. - * - * The device pointer and IOMMU data remain stable in the bond struct after - * _probe_device() where it's attached to the managed IOMMU, up to the - * completion of the _release_device() call. The release of the bond structure - * is synchronized with the device release. - */ -struct riscv_iommu_bond { - struct list_head list; - struct rcu_head rcu; - struct device *dev; -}; - static int riscv_iommu_bond_link(struct riscv_iommu_domain *domain, struct device *dev) { diff --git a/drivers/iommu/riscv/iommu.h b/drivers/iommu/riscv/iommu.h index b1c4664542b4..dd538b19fbb7 100644 --- a/drivers/iommu/riscv/iommu.h +++ b/drivers/iommu/riscv/iommu.h @@ -17,8 +17,35 @@ #include "iommu-bits.h" +/* Timeouts in [us] */ +#define RISCV_IOMMU_QCSR_TIMEOUT 150000 +#define RISCV_IOMMU_QUEUE_TIMEOUT 150000 +#define RISCV_IOMMU_DDTP_TIMEOUT 10000000 +#define RISCV_IOMMU_IOTINVAL_TIMEOUT 90000000 + +/* This struct contains protection domain specific IOMMU driver data. */ +struct riscv_iommu_domain { + struct iommu_domain domain; + struct list_head bonds; + spinlock_t lock; /* protect bonds list updates. */ + int pscid; + int gscid; + int amo_enabled; + int numa_node; + unsigned int pgd_mode; + unsigned long *pgd_root; +}; + +/* Private IOMMU data for managed devices, dev_iommu_priv_* */ +struct riscv_iommu_info { + struct riscv_iommu_domain *domain; +}; + struct riscv_iommu_device; +#define dev_to_iommu(dev) \ + iommu_get_iommu_dev(dev, struct riscv_iommu_device, iommu) + struct riscv_iommu_queue { atomic_t prod; /* unbounded producer allocation index */ atomic_t head; /* unbounded shadow ring buffer consumer index */ @@ -62,9 +89,36 @@ struct riscv_iommu_device { u64 *ddt_root; }; +/* + * Linkage between an iommu_domain and attached devices. + * + * Protection domain requiring IOATC and DevATC translation cache invalidations, + * should be linked to attached devices using a riscv_iommu_bond structure. + * Devices should be linked to the domain before first use and unlinked after + * the translations from the referenced protection domain can no longer be used. + * Blocking and identity domains are not tracked here, as the IOMMU hardware + * does not cache negative and/or identity (BARE mode) translations, and DevATC + * is disabled for those protection domains. + * + * The device pointer and IOMMU data remain stable in the bond struct after + * _probe_device() where it's attached to the managed IOMMU, up to the + * completion of the _release_device() call. The release of the bond structure + * is synchronized with the device release. + */ +struct riscv_iommu_bond { + struct list_head list; + struct rcu_head rcu; + struct device *dev; +}; + int riscv_iommu_init(struct riscv_iommu_device *iommu); void riscv_iommu_remove(struct riscv_iommu_device *iommu); +void riscv_iommu_cmd_send(struct riscv_iommu_device *iommu, + struct riscv_iommu_command *cmd); +void riscv_iommu_cmd_sync(struct riscv_iommu_device *iommu, + unsigned int timeout_us); + #define riscv_iommu_readl(iommu, addr) \ readl_relaxed((iommu)->reg + (addr)) From patchwork Thu Nov 14 16:18:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875425 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3F3C1991C1 for ; Thu, 14 Nov 2024 16:19:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601146; cv=none; b=O6TtADiBlExxq0Nw16NPy6l0OWQ4RspSApEgMgPmuOq8G7rXvtax/KcoiJ3ecHRaQ9+LvB8XlrXh1enXrzXPuDyzirTusz9KVWAeupKg5IJwgnd15Q3YrQV2C+pQqt0OOLpvnlrI9sNK0zsaEzYtN9zL00+1HSyTmVL3kzc6mXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601146; c=relaxed/simple; bh=g5McopJz9YgSe9KWmaVd8HxaSlP+V5h/dFeTAq0VhNk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BxYufpsAkretBqGjhZtshPAPurNM5IB2kVI/OV3PFNZfPn906cyT4gYsOzhmsvqbuf5rcLRyKjDnpkXVBQJ1NdNaIaglavIXUOap1Gr9uGGC7lA6Suhqo1NrI5Te2LbnsuK+0K4zL933VRHy3GOM1b5KsWXfg4qWJGSVqpkko/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=D/2QTte+; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="D/2QTte+" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-37d63a79bb6so590657f8f.0 for ; Thu, 14 Nov 2024 08:19:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601141; x=1732205941; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VmyPhlw9y/X/fnXH6ufVz2Fv/AglekMjgv19lGdZt0M=; b=D/2QTte+5ekBEh8AIzxqlQOzVWMBoeqvBjYxUc8By+CDZlpa4Z3qQa92oY3tg2Q1/4 xHV1LEk8oJ7GmcVbad6+DhAnJETkiye/jQFK7QjM7MnlkwtjzlPve0YGCG1xxhGDsX7d H+8E1Fjj05QfIFPgstBQVDzSlxaTphFqGRZcjFf3F7SMV+xZ3+gP1uu1su+SBuE8AhSK uS6vozhxfNIcMk6FoNEE5+CGu0W0qq0p9JVqaFAzpgq9W4g5uW4G/3jx59LxU8RPzw19 B3iSISeGoyQYIKZziFwGKukJBqL9Xtn4b78UO3liXLoJNFM0euTrbfJEuBemFtN/GEF0 g2+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601141; x=1732205941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VmyPhlw9y/X/fnXH6ufVz2Fv/AglekMjgv19lGdZt0M=; b=qmuneqomq6cAGBeAQPIyMxIIq9LVu/eHnTcsoHQRz4oJMP2AmYxmtpZRGy/Cp5btUJ tvKc243ZIFCEIZF5gm8bYS8ePYueEa3IIgvDzDl6bOzAWnN0Z07/1OIbYIiaJrmG7Mzt 5TmCyaamkpODGT90007rSlI7QwUatYC8NrIb8xZRlppmy0PFerZvLn5bU7qnkeXBuTUt IKx6/7AO+VomRlkRgWdTRDiPXIGYh6OBawJCYdN0W/1R0hsfnjBGZu2Ni7vtJSFCF0Fq FbfXduoUzRPAmhufp6OQHAoVVouDGpaAhrUGrkgfzuw6q9uqPcIEBkxaczS6SnzkMqND 2W2Q== X-Forwarded-Encrypted: i=1; AJvYcCXMy/IRsgSkgUGSiEfRqaxlsRr482pX2jO70SnzLF34MB5WjxvUGiJORsaoltornweUzaI=@vger.kernel.org X-Gm-Message-State: AOJu0YzdoHyH68EqqNu11V7y2hXnLpg0c6QtvwtTih0s9fofdo2NbOWk N6+CmOew5zAqRA8sjefWqQx8bTPexNHUWSTkqtjYc2E4OsN7BVjMeNFXNsIOpgY= X-Google-Smtp-Source: AGHT+IEurYWNfkgEG6OVCqRhsfT6EytEjQqOu8Vk3V55flsbBNhf08vSjr2U+chyzyCkXFZDditk7A== X-Received: by 2002:a05:6000:2aa:b0:37d:4ef1:1820 with SMTP id ffacd0b85a97d-3820df88797mr5457081f8f.40.1731601141065; Thu, 14 Nov 2024 08:19:01 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3821ada2da2sm1862201f8f.15.2024.11.14.08.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:19:00 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 08/15] iommu/riscv: Add IRQ domain for interrupt remapping Date: Thu, 14 Nov 2024 17:18:53 +0100 Message-ID: <20241114161845.502027-25-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is just a skeleton. Until irq_set_vcpu_affinity() is implemented the IRQ domain doesn't serve any purpose. Signed-off-by: Andrew Jones --- drivers/iommu/riscv/Makefile | 2 +- drivers/iommu/riscv/iommu-ir.c | 209 +++++++++++++++++++++++++++++++++ drivers/iommu/riscv/iommu.c | 43 ++++++- drivers/iommu/riscv/iommu.h | 21 ++++ 4 files changed, 270 insertions(+), 5 deletions(-) create mode 100644 drivers/iommu/riscv/iommu-ir.c diff --git a/drivers/iommu/riscv/Makefile b/drivers/iommu/riscv/Makefile index f54c9ed17d41..8420dd1776cb 100644 --- a/drivers/iommu/riscv/Makefile +++ b/drivers/iommu/riscv/Makefile @@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_RISCV_IOMMU) += iommu.o iommu-platform.o +obj-$(CONFIG_RISCV_IOMMU) += iommu.o iommu-ir.o iommu-platform.o obj-$(CONFIG_RISCV_IOMMU_PCI) += iommu-pci.o diff --git a/drivers/iommu/riscv/iommu-ir.c b/drivers/iommu/riscv/iommu-ir.c new file mode 100644 index 000000000000..c177e064b205 --- /dev/null +++ b/drivers/iommu/riscv/iommu-ir.c @@ -0,0 +1,209 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * IOMMU Interrupt Remapping + * + * Copyright © 2024 Ventana Micro Systems Inc. + */ +#include +#include + +#include "../iommu-pages.h" +#include "iommu.h" + +static size_t riscv_iommu_ir_get_msipte_idx(struct riscv_iommu_domain *domain, + phys_addr_t msi_pa) +{ + phys_addr_t addr = msi_pa >> 12; + size_t idx; + + if (domain->group_index_bits) { + phys_addr_t group_mask = BIT(domain->group_index_bits) - 1; + phys_addr_t group_shift = domain->group_index_shift - 12; + phys_addr_t group = (addr >> group_shift) & group_mask; + phys_addr_t mask = domain->msiptp.msi_addr_mask & ~(group_mask << group_shift); + + idx = addr & mask; + idx |= group << fls64(mask); + } else { + idx = addr & domain->msiptp.msi_addr_mask; + } + + return idx; +} + +static struct riscv_iommu_msipte *riscv_iommu_ir_get_msipte(struct riscv_iommu_domain *domain, + phys_addr_t msi_pa) +{ + size_t idx; + + if (((msi_pa >> 12) & ~domain->msiptp.msi_addr_mask) != domain->msiptp.msi_addr_pattern) + return NULL; + + idx = riscv_iommu_ir_get_msipte_idx(domain, msi_pa); + return &domain->msi_root[idx]; +} + +static size_t riscv_iommu_ir_nr_msiptes(struct riscv_iommu_domain *domain) +{ + phys_addr_t base = domain->msiptp.msi_addr_pattern << 12; + phys_addr_t max_addr = base | (domain->msiptp.msi_addr_mask << 12); + size_t max_idx = riscv_iommu_ir_get_msipte_idx(domain, max_addr); + + return max_idx + 1; +} + +static struct irq_chip riscv_iommu_irq_chip = { + .name = "IOMMU-IR", + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, +}; + +static int riscv_iommu_irq_domain_alloc_irqs(struct irq_domain *irqdomain, + unsigned int irq_base, unsigned int nr_irqs, + void *arg) +{ + struct irq_data *data; + int i, ret; + + ret = irq_domain_alloc_irqs_parent(irqdomain, irq_base, nr_irqs, arg); + if (ret) + return ret; + + for (i = 0; i < nr_irqs; i++) { + data = irq_domain_get_irq_data(irqdomain, irq_base + i); + data->chip = &riscv_iommu_irq_chip; + } + + return 0; +} + +static const struct irq_domain_ops riscv_iommu_irq_domain_ops = { + .alloc = riscv_iommu_irq_domain_alloc_irqs, + .free = irq_domain_free_irqs_parent, +}; + +static const struct msi_parent_ops riscv_iommu_msi_parent_ops = { + .prefix = "IR-", + .supported_flags = MSI_GENERIC_FLAGS_MASK | + MSI_FLAG_PCI_MSIX, + .required_flags = MSI_FLAG_USE_DEF_DOM_OPS | + MSI_FLAG_USE_DEF_CHIP_OPS, + .init_dev_msi_info = msi_parent_init_dev_msi_info, +}; + +int riscv_iommu_irq_domain_create(struct riscv_iommu_domain *domain, + struct device *dev) +{ + struct riscv_iommu_device *iommu = dev_to_iommu(dev); + struct fwnode_handle *fn; + char *fwname; + + if (domain->irqdomain) { + dev_set_msi_domain(dev, domain->irqdomain); + return 0; + } + + if (!(iommu->caps & RISCV_IOMMU_CAPABILITIES_MSI_FLAT)) { + dev_warn(iommu->dev, "Cannot enable interrupt remapping\n"); + return 0; + } + + spin_lock_init(&domain->msi_lock); + /* + * TODO: The hypervisor should be in control of this size. For now + * we just allocate enough space for 512 VCPUs. + */ + domain->msi_order = 1; + domain->msi_root = iommu_alloc_pages_node(domain->numa_node, + GFP_KERNEL_ACCOUNT, domain->msi_order); + if (!domain->msi_root) + return -ENOMEM; + + fwname = kasprintf(GFP_KERNEL, "IOMMU-IR-%s", dev_name(dev)); + if (!fwname) { + iommu_free_pages(domain->msi_root, domain->msi_order); + return -ENOMEM; + } + + fn = irq_domain_alloc_named_fwnode(fwname); + kfree(fwname); + if (!fn) { + dev_err(iommu->dev, "Couldn't allocate fwnode\n"); + iommu_free_pages(domain->msi_root, domain->msi_order); + return -ENOMEM; + } + + domain->irqdomain = irq_domain_create_hierarchy(dev_get_msi_domain(dev), + 0, 0, fn, + &riscv_iommu_irq_domain_ops, + domain); + if (!domain->irqdomain) { + dev_err(iommu->dev, "Failed to create IOMMU irq domain\n"); + iommu_free_pages(domain->msi_root, domain->msi_order); + irq_domain_free_fwnode(fn); + return -ENOMEM; + } + + domain->irqdomain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT | + IRQ_DOMAIN_FLAG_ISOLATED_MSI; + domain->irqdomain->msi_parent_ops = &riscv_iommu_msi_parent_ops; + irq_domain_update_bus_token(domain->irqdomain, DOMAIN_BUS_MSI_REMAP); + dev_set_msi_domain(dev, domain->irqdomain); + + return 0; +} + +void riscv_iommu_ir_get_resv_regions(struct device *dev, struct list_head *head) +{ + struct riscv_iommu_info *info = dev_iommu_priv_get(dev); + struct riscv_iommu_domain *domain = info->domain; + struct iommu_resv_region *reg; + phys_addr_t base, addr; + size_t nr_pages, i; + + if (!domain || !domain->msiptp.msiptp) + return; + + base = domain->msiptp.msi_addr_pattern << 12; + + if (domain->group_index_bits) { + phys_addr_t group_mask = BIT(domain->group_index_bits) - 1; + phys_addr_t group_shift = domain->group_index_shift - 12; + phys_addr_t mask = domain->msiptp.msi_addr_mask & ~(group_mask << group_shift); + + nr_pages = mask + 1; + } else { + nr_pages = domain->msiptp.msi_addr_mask + 1; + } + + for (i = 0; i < BIT(domain->group_index_bits); i++) { + addr = base | (i << domain->group_index_shift); + reg = iommu_alloc_resv_region(addr, nr_pages * 4096, + 0, IOMMU_RESV_MSI, GFP_KERNEL); + if (reg) + list_add_tail(®->list, head); + } +} + +void riscv_iommu_irq_domain_remove(struct riscv_iommu_domain *domain) +{ + struct fwnode_handle *fn; + + if (!domain->irqdomain) + return; + + iommu_free_pages(domain->msi_root, domain->msi_order); + + fn = domain->irqdomain->fwnode; + irq_domain_remove(domain->irqdomain); + irq_domain_free_fwnode(fn); +} + +void riscv_iommu_irq_domain_unlink(struct riscv_iommu_domain *domain, + struct device *dev) +{ + if (!domain || !domain->irqdomain) + return; + + dev_set_msi_domain(dev, domain->irqdomain->parent); +} diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 6e8ea3d22ff5..c4a47b21c58f 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -943,7 +943,8 @@ static void riscv_iommu_iotlb_inval(struct riscv_iommu_domain *domain, rcu_read_unlock(); } -#define RISCV_IOMMU_FSC_BARE 0 +#define RISCV_IOMMU_FSC_BARE 0 +#define RISCV_IOMMU_IOHGATP_BARE 0 /* * Update IODIR for the device. @@ -1245,6 +1246,8 @@ static void riscv_iommu_free_paging_domain(struct iommu_domain *iommu_domain) WARN_ON(!list_empty(&domain->bonds)); + riscv_iommu_irq_domain_remove(domain); + if (domain->pscid > 0) ida_free(&riscv_iommu_pscids, domain->pscid); if (domain->gscid > 0) @@ -1276,10 +1279,30 @@ static int riscv_iommu_attach_paging_domain(struct iommu_domain *iommu_domain, struct riscv_iommu_device *iommu = dev_to_iommu(dev); struct riscv_iommu_info *info = dev_iommu_priv_get(dev); struct riscv_iommu_dc dc = {0}; + int ret; if (!riscv_iommu_pt_supported(iommu, domain->pgd_mode)) return -ENODEV; + if (riscv_iommu_bond_link(domain, dev)) + return -ENOMEM; + + if (iommu_domain->type == IOMMU_DOMAIN_UNMANAGED) { + domain->gscid = ida_alloc_range(&riscv_iommu_gscids, 1, + RISCV_IOMMU_MAX_GSCID, GFP_KERNEL); + if (domain->gscid < 0) { + riscv_iommu_bond_unlink(domain, dev); + return -ENOMEM; + } + + ret = riscv_iommu_irq_domain_create(domain, dev); + if (ret) { + riscv_iommu_bond_unlink(domain, dev); + ida_free(&riscv_iommu_gscids, domain->gscid); + return ret; + } + } + if (domain->gscid) { dc.iohgatp = FIELD_PREP(RISCV_IOMMU_DC_IOHGATP_MODE, domain->pgd_mode) | FIELD_PREP(RISCV_IOMMU_DC_IOHGATP_GSCID, domain->gscid) | @@ -1292,10 +1315,9 @@ static int riscv_iommu_attach_paging_domain(struct iommu_domain *iommu_domain, dc.ta = FIELD_PREP(RISCV_IOMMU_PC_TA_PSCID, domain->pscid) | RISCV_IOMMU_PC_TA_V; - if (riscv_iommu_bond_link(domain, dev)) - return -ENOMEM; - riscv_iommu_iodir_update(iommu, dev, &dc); + + riscv_iommu_irq_domain_unlink(info->domain, dev); riscv_iommu_bond_unlink(info->domain, dev); info->domain = domain; @@ -1389,9 +1411,12 @@ static int riscv_iommu_attach_blocking_domain(struct iommu_domain *iommu_domain, struct riscv_iommu_dc dc = {0}; dc.fsc = RISCV_IOMMU_FSC_BARE; + dc.iohgatp = RISCV_IOMMU_IOHGATP_BARE; /* Make device context invalid, translation requests will fault w/ #258 */ riscv_iommu_iodir_update(iommu, dev, &dc); + + riscv_iommu_irq_domain_unlink(info->domain, dev); riscv_iommu_bond_unlink(info->domain, dev); info->domain = NULL; @@ -1413,15 +1438,24 @@ static int riscv_iommu_attach_identity_domain(struct iommu_domain *iommu_domain, struct riscv_iommu_dc dc = {0}; dc.fsc = RISCV_IOMMU_FSC_BARE; + dc.iohgatp = RISCV_IOMMU_IOHGATP_BARE; dc.ta = RISCV_IOMMU_PC_TA_V; riscv_iommu_iodir_update(iommu, dev, &dc); + + riscv_iommu_irq_domain_unlink(info->domain, dev); riscv_iommu_bond_unlink(info->domain, dev); info->domain = NULL; return 0; } +static void riscv_iommu_get_resv_regions(struct device *dev, + struct list_head *head) +{ + riscv_iommu_ir_get_resv_regions(dev, head); +} + static struct iommu_domain riscv_iommu_identity_domain = { .type = IOMMU_DOMAIN_IDENTITY, .ops = &(const struct iommu_domain_ops) { @@ -1516,6 +1550,7 @@ static const struct iommu_ops riscv_iommu_ops = { .blocked_domain = &riscv_iommu_blocking_domain, .release_domain = &riscv_iommu_blocking_domain, .domain_alloc_paging = riscv_iommu_alloc_paging_domain, + .get_resv_regions = riscv_iommu_get_resv_regions, .device_group = riscv_iommu_device_group, .probe_device = riscv_iommu_probe_device, .release_device = riscv_iommu_release_device, diff --git a/drivers/iommu/riscv/iommu.h b/drivers/iommu/riscv/iommu.h index dd538b19fbb7..6ce71095781c 100644 --- a/drivers/iommu/riscv/iommu.h +++ b/drivers/iommu/riscv/iommu.h @@ -23,6 +23,12 @@ #define RISCV_IOMMU_DDTP_TIMEOUT 10000000 #define RISCV_IOMMU_IOTINVAL_TIMEOUT 90000000 +struct riscv_iommu_msiptp_state { + u64 msiptp; + u64 msi_addr_mask; + u64 msi_addr_pattern; +}; + /* This struct contains protection domain specific IOMMU driver data. */ struct riscv_iommu_domain { struct iommu_domain domain; @@ -34,6 +40,13 @@ struct riscv_iommu_domain { int numa_node; unsigned int pgd_mode; unsigned long *pgd_root; + u32 group_index_bits; + u32 group_index_shift; + int msi_order; + struct riscv_iommu_msipte *msi_root; + spinlock_t msi_lock; + struct riscv_iommu_msiptp_state msiptp; + struct irq_domain *irqdomain; }; /* Private IOMMU data for managed devices, dev_iommu_priv_* */ @@ -119,6 +132,14 @@ void riscv_iommu_cmd_send(struct riscv_iommu_device *iommu, void riscv_iommu_cmd_sync(struct riscv_iommu_device *iommu, unsigned int timeout_us); +int riscv_iommu_irq_domain_create(struct riscv_iommu_domain *domain, + struct device *dev); +void riscv_iommu_irq_domain_remove(struct riscv_iommu_domain *domain); +void riscv_iommu_irq_domain_unlink(struct riscv_iommu_domain *domain, + struct device *dev); +void riscv_iommu_ir_get_resv_regions(struct device *dev, + struct list_head *head); + #define riscv_iommu_readl(iommu, addr) \ readl_relaxed((iommu)->reg + (addr)) From patchwork Thu Nov 14 16:18:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875427 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 001A819CCF9 for ; Thu, 14 Nov 2024 16:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601146; cv=none; b=YcMY1EW6omAD8mYimZKp0PATJZy+9uhdB4sy1wemsiRrOpbyV0VtP7H31anmIsit0GsEHtppdwBoIK0txJcp+P4dt4P9Imac/QBMGUoTByfgfEO1RZyyxmOgG0O4bsF/Rxv621zBgfLYYl2HtxTorkEZAFEE+A/LRjUgh4Xbt/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601146; c=relaxed/simple; bh=zG8rAEuB5eoKnSaZdksATDcRCj9Xf9/S0fQz+A0rat0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c+cSpy/24AqbeR6r33o/qNi/N8wgQ7oyM8DoQ+cmpIU3Buw6mvN3pTGhGHk/fLjsFD3zdTX7vNxSAb3yENJcvZNxvakd30dyCSlOjTsYMP/Mw7R1K/2Phh/lffkJgybI4KP2L7yvq0e6R1JojaHIFIRhi6EmbvwDjYPEWgTePGg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=K04vfsoH; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="K04vfsoH" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4314b316495so7193755e9.2 for ; Thu, 14 Nov 2024 08:19:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601143; x=1732205943; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ylj9cSUnN7lZBYMxGOa796BuugfVNbbIfct9OAjDsOY=; b=K04vfsoHPQ8sPeJn6OLhB5+OzhmlWfrdBFhPGKUrNINOuOXu7fCIATXEeIeCvnOEeg ybzd4rUCMGjVI6vyH18f5fd+tj8MT3QzxXD6mYG8Dukd3Tkd9kr6WuvHibe/cElDo84M 0XQ47hsTA8SgFAWvcegXtscWvB64wR6bblP3U40lR+deWbXLx5c7KoG9dKxm8l2LndGz /lKctDSgyMzk7cKrQGXCfasEn1ANX8BdXepDysl8yQbGzlOzrexRXNHDv+x5L7BXKg6f YNwRxI0Lo8dRbPahvtSCpd1SO/EXlyJUZL/ZC0nr1X0AO8ZuLMsqechg5oc3rCAlY06J 6wAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601143; x=1732205943; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ylj9cSUnN7lZBYMxGOa796BuugfVNbbIfct9OAjDsOY=; b=aB2mweQi9zMKvWmOsjGAUy8WOQ3aq2tC71kl78oilR5u4G4UTv9Lh9N/ITblKah3Ik wZbwF6MeaONPKc78WTL0G/YXSwvBPjwQ7WDwRjLFVFrRE32EgKsg8DRkP9KZwnAJgEuS Uj1v3mD3F45gaq05peT4e/6KbiZ/HH1ORpQhA7hHKvJ9F8gyQJYM0epFooIVeMbe8yi1 djwX7HhTTAQQR8A8W8k+otAO9N83fb9hjEavPmNz9VVCqzf7UYJxHEYR3agLMi3VQ4+7 IQfDOJbti9gVAulBXcG8rqgDUJUFtn9QQ5c8yHyPnIUJko1gpbh1fCuKsi/L/zgX/Itw NJKg== X-Forwarded-Encrypted: i=1; AJvYcCWhpY0PwRmvM/CXOr5WCxrlasUi3hx9ZVqkiCMan3BQOcZf6R4YX28oNnJFR/q9ewj2CcI=@vger.kernel.org X-Gm-Message-State: AOJu0YzfiKXCOGqJeerg0JuOLCQGtBLX/iOrmGBzTw+vqzZL7hnalf88 8dQ8Rkd6yzRsJnwWcAasFg1fwV1lzDD5LiqycBVxXlWmEzg84y+wo2i0rSYvmP4= X-Google-Smtp-Source: AGHT+IGWufmtM+epbPX600D1VFEI9w8hjUWbvA+ZtsTOBkgX8kbCaXoJN+2t/PgDnUc4rlU+m8h9BA== X-Received: by 2002:a05:600c:3114:b0:42c:bd4d:e8ba with SMTP id 5b1f17b1804b1-432d4aae479mr69854575e9.8.1731601143362; Thu, 14 Nov 2024 08:19:03 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432da265ca8sm28719625e9.14.2024.11.14.08.19.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:19:02 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 09/15] RISC-V: KVM: Enable KVM_VFIO interfaces on RISC-V arch Date: Thu, 14 Nov 2024 17:18:54 +0100 Message-ID: <20241114161845.502027-26-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Tomasz Jeznach Enable KVM/VFIO support on RISC-V architecture. Signed-off-by: Tomasz Jeznach Signed-off-by: Andrew Jones --- arch/riscv/kvm/Kconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig index 0c3cbb0915ff..333d95da8ebe 100644 --- a/arch/riscv/kvm/Kconfig +++ b/arch/riscv/kvm/Kconfig @@ -29,10 +29,12 @@ config KVM select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_HARDWARE_ENABLING select KVM_MMIO + select KVM_VFIO select KVM_XFER_TO_GUEST_WORK select KVM_GENERIC_MMU_NOTIFIER select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS + select SRCU help Support hosting virtualized guest machines. From patchwork Thu Nov 14 16:18:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875429 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DF0419E982 for ; Thu, 14 Nov 2024 16:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601148; cv=none; b=UYkBko5P9FUSwLZBMOO2YOxJWvc7ZZjduSc+bdZEyEhBWZ+wjRbpGKEoYbmBdb6TKZ6ERuUqDPFRvVWYJGX3BzRGvCHjK+P3SzlbmVYLWss/Tj/9oruEC2+Vb/OQ3LXP71P2ILdOdkhpCF3h3F16DOPzllM4m3LlbbVV1HD+PFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601148; c=relaxed/simple; bh=UESyK8Uc8qhnyUFE7sWCeUfzwrVwuw9Qm2LYqZNp+fo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tk4cCE6KJKBvvCk3jrjNXccEERZF6NAtTMMRWyvUpy7FsciZpHg6YsLvbRmufeb//+5marDcssx8KcyfNPGIfNIJBwaiein21BdlJFmkNH7bRnf9IZqwJbVIMdiN3cOfuLvaCRuEp+2VfVddTf2GV3aW8e5KA2Mz/GU/xorPTV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=DZIjfuan; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="DZIjfuan" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-37d50fad249so606911f8f.1 for ; Thu, 14 Nov 2024 08:19:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601145; x=1732205945; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JmyAZwFmuLjn3p39hRK9ePQAJ1PSqwbQ6F/1nOHrEzM=; b=DZIjfuancE62FVd5pElzCWaDhWZzUbPRjpUcOwPOqX3NUfD2KqxBkWC0qie5IovXOt +oSnJDvYreXF7KKEaNIKY6qECF6rsme87Xqvq39u1k51nyLwODtS8Zjz1n+w+Oo0vXb4 sWNV5sR7+f/HaCTksTzicGELUlkwxAD0yPsc9NHCpXYV5Jq4FSatznfSLaBhjYp+hwFR T/CJETXvKVjCwFikKNY9OyDOEtW5f9q978eTDWeIMMY4cTfKZ/1v+fdJ/1UAJQgf4HBn A+qRrBVNrYfLUJYRoYITLqP7Ijj5FzTLZvX0xzniGCSckHjSY/TObd/moVJL999r8QpQ a8Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601145; x=1732205945; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JmyAZwFmuLjn3p39hRK9ePQAJ1PSqwbQ6F/1nOHrEzM=; b=vCq1NsqJcikmfCZleIZEPCwTDT+8zQOHQLsL7d7HB8TneO/qoN19LMeuPsuNrNK0pg swNFBbRLOrcjJT83wwB8uhU0FwFGZ3RkXuyUtjTVNIf5eqT86RuN+LFC8ZmGD/ddbq+g bfbTywAzt+lt4jFZxJTl2gd5bjIWvaTbz5zZupOo9Ma8YQwV6ovFvojb44SUKkCVPOk+ Sa+L4FedKoEYOI8sAK1YmXc0Htw2rPQFL2iuerbtfvDKYvWS6wEy4o3liiec4pachzaY mGyozYMpUezX89nxEqVtql6TTFYabazs5lXld4kxJWa0b80lfToK5inoM2GjfzlStKSp +mGQ== X-Forwarded-Encrypted: i=1; AJvYcCXdF6W3ICoZqwW8w8Y7/hzVg9RRLV+qdV1CGT/o8Bwr37x9+EgIX3Og5QZd2f9xN8J18r8=@vger.kernel.org X-Gm-Message-State: AOJu0YxBQZSo9QglNqbLxQSbByrVsfeExXzvv6lcEqrdRpdbuEvXPxxO iOEz4ZBMIteQ8doMFCn3EcgD0mATm+pwKXsDcdDVf8mskXNjkIgxodK/We8hHEs= X-Google-Smtp-Source: AGHT+IEn3qlHsw/D0PT2IEwLbgj1uEV7tnlyKBH8z2H1adqlOAImJaC/GmimW4BKxNwCPjE/Y1igiA== X-Received: by 2002:a05:6000:210e:b0:382:424:94fe with SMTP id ffacd0b85a97d-382042495edmr11613726f8f.36.1731601144686; Thu, 14 Nov 2024 08:19:04 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3821ae161d8sm1901964f8f.78.2024.11.14.08.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:19:04 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 10/15] RISC-V: KVM: Add irqbypass skeleton Date: Thu, 14 Nov 2024 17:18:55 +0100 Message-ID: <20241114161845.502027-27-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add all the functions needed to wire up irqbypass support. kvm_arch_update_irqfd_routing() is left unimplemented, so return false from kvm_arch_has_irq_bypass(). Signed-off-by: Andrew Jones --- arch/riscv/include/asm/kvm_host.h | 3 ++ arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/aia_imsic.c | 6 ++++ arch/riscv/kvm/vm.c | 60 +++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 35eab6e0f4ae..fef7422939f6 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -114,6 +114,9 @@ struct kvm_arch { /* AIA Guest/VM context */ struct kvm_aia aia; + +#define __KVM_HAVE_ARCH_ASSIGNED_DEVICE + atomic_t assigned_device_count; }; struct kvm_cpu_trap { diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig index 333d95da8ebe..9a4feb1e671d 100644 --- a/arch/riscv/kvm/Kconfig +++ b/arch/riscv/kvm/Kconfig @@ -21,6 +21,7 @@ config KVM tristate "Kernel-based Virtual Machine (KVM) support (EXPERIMENTAL)" depends on RISCV_SBI && MMU select HAVE_KVM_IRQCHIP + select HAVE_KVM_IRQ_BYPASS select HAVE_KVM_IRQ_ROUTING select HAVE_KVM_MSI select HAVE_KVM_VCPU_ASYNC_IOCTL diff --git a/arch/riscv/kvm/aia_imsic.c b/arch/riscv/kvm/aia_imsic.c index a8085cd8215e..64b1f3713dd5 100644 --- a/arch/riscv/kvm/aia_imsic.c +++ b/arch/riscv/kvm/aia_imsic.c @@ -727,6 +727,12 @@ void kvm_riscv_vcpu_aia_imsic_release(struct kvm_vcpu *vcpu) kvm_riscv_aia_free_hgei(old_vsfile_cpu, old_vsfile_hgei); } +int kvm_arch_update_irqfd_routing(struct kvm *kvm, unsigned int host_irq, + uint32_t guest_irq, bool set) +{ + return -ENXIO; +} + int kvm_riscv_vcpu_aia_imsic_update(struct kvm_vcpu *vcpu) { unsigned long flags; diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c index 7396b8654f45..9c5837518c1a 100644 --- a/arch/riscv/kvm/vm.c +++ b/arch/riscv/kvm/vm.c @@ -11,6 +11,9 @@ #include #include #include +#include + +#include const struct _kvm_stats_desc kvm_vm_stats_desc[] = { KVM_GENERIC_VM_STATS() @@ -55,6 +58,63 @@ void kvm_arch_destroy_vm(struct kvm *kvm) kvm_riscv_aia_destroy_vm(kvm); } +void kvm_arch_start_assignment(struct kvm *kvm) +{ + atomic_inc(&kvm->arch.assigned_device_count); +} +EXPORT_SYMBOL_GPL(kvm_arch_start_assignment); + +void kvm_arch_end_assignment(struct kvm *kvm) +{ + atomic_dec(&kvm->arch.assigned_device_count); +} +EXPORT_SYMBOL_GPL(kvm_arch_end_assignment); + +bool noinstr kvm_arch_has_assigned_device(struct kvm *kvm) +{ + return arch_atomic_read(&kvm->arch.assigned_device_count); +} +EXPORT_SYMBOL_GPL(kvm_arch_has_assigned_device); + +bool kvm_arch_has_irq_bypass(void) +{ + return false; +} + +int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons, + struct irq_bypass_producer *prod) +{ + struct kvm_kernel_irqfd *irqfd = + container_of(cons, struct kvm_kernel_irqfd, consumer); + int ret; + + irqfd->producer = prod; + kvm_arch_start_assignment(irqfd->kvm); + ret = kvm_arch_update_irqfd_routing(irqfd->kvm, prod->irq, irqfd->gsi, true); + if (ret) + kvm_arch_end_assignment(irqfd->kvm); + + return ret; +} + +void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons, + struct irq_bypass_producer *prod) +{ + struct kvm_kernel_irqfd *irqfd = + container_of(cons, struct kvm_kernel_irqfd, consumer); + int ret; + + WARN_ON(irqfd->producer != prod); + irqfd->producer = NULL; + + ret = kvm_arch_update_irqfd_routing(irqfd->kvm, prod->irq, irqfd->gsi, false); + if (ret) + pr_info("irq bypass consumer (token %p) unregistration fails: %d\n", + irqfd->consumer.token, ret); + + kvm_arch_end_assignment(irqfd->kvm); +} + int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irql, bool line_status) { From patchwork Thu Nov 14 16:18:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875431 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F64F1A76D0 for ; Thu, 14 Nov 2024 16:19:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601149; cv=none; b=gz75W8/wjX9qKAISEIVjsD1AvBkULttIv1fXoZ/tRA/dKhjfZY/3zURszP+RK8r7qE0IUpIhRKVMJVOOwzTHyVml9BbgbsmFg79NS1n10ulL3ILSY8cQZoypcsJ9IJBT6rs0pn0ce1A+cM6rSuI2eZvnC+BcPk6TMrE0mRuGXVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601149; c=relaxed/simple; bh=mWR/+tZ7zPAyQgPDW6T1+Yz2Dl/T8S6Wjb1XP+iFats=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=InrgkbMeVnERMR8LHNZbZDQZOSCYbKZCPLFMXX4pJNUAVV8XLOrAlZCGJuQxpPOQok372Cxu9t+g6UGTyXXyWrVgAeBudb215ie91KQzqCZVNjSm+fdFtj/KS1CDoxcYmkR36Xp42ats5wCKxNkF8mey99yIH5LY4mSZflVYeaM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=V4MChWXo; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="V4MChWXo" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-53d8c08cfc4so685035e87.3 for ; Thu, 14 Nov 2024 08:19:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601146; x=1732205946; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ftdmF/h5yhFV9hvEqaih+NCLoaifWjggdlhRka1xblk=; b=V4MChWXoTH/de5eiio/PWHY2gS252zyJrZmd26MMgFImZ9oZJrrTHQj55XbjCshc7I UT2lu83aGx9xiccEqDAz0dG7xqcjol/pjMNVXLDXE+inOdtF+1TVShli5emzmLOGpbIz PYiG3/5SfMZl4TIwlk8qdvCfZsYThRRcujHfj4M35XuZF8x/8GgqqUfngihVmg7wS5Qu efP+atBdKIP883PIWsRI3iPJmW3OL7Oq+dqP443wcKSVh3MhZnZFqLGAlDEEU4F3kgcq K6iCmIN6Aj1cipwnHWwIeXrMppxQjgvxnVN9iyiZ3y6tR72Btv+HQt4pFvYy2Xlx+dCm xoSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601146; x=1732205946; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ftdmF/h5yhFV9hvEqaih+NCLoaifWjggdlhRka1xblk=; b=YbDNFnO1K5629i/EFQm7CTkdmoCPG46iOCqG9IiFb55EjttIct9pLE57SdUi5IAGNx 1aFStfx/VymZ0anX/OTunwcuxWuYsTMB8JbYPhCG0K4cNsdYuPq/l/3XOLTca7lz+yub xDSQCtb/v+0Hk/bPmp3/LwY6G/n0YxoFICGdZEAqFvtw0zXhDsqpUIBDhecZK/bOuf+P TX+LogyPDMYeSGM4SshItmF4z8Ua20jK9EUgex7+aEEfTqF3yxMUiz+s4qA1ukuJgZ3q zGKvwVmEwzCrzm1X66gp8WTvjIKO6e75RWbVA3NpI3WPa28cAkP/JxoKHv4Nr9Y7iSQL H7sw== X-Forwarded-Encrypted: i=1; AJvYcCUjAgVe9cFAS6Nub4LzRvyHH3d4eIQimPEdIIK2SyhMey57ul540ZF0U2DiFTttCDUJ/VI=@vger.kernel.org X-Gm-Message-State: AOJu0YzwBOH2bZW83AJE0KtjdZLqUI68KSNO3MpBgW+0DDrqfL4CJJIz Alc7g4+Y9lEB+N/aqPkIgIqW2ZLN/2WhGWVmstH5LRIlMoBzHT5qdT6otGy8Hhg= X-Google-Smtp-Source: AGHT+IEJJHbd90NQ7GNwzK7jz3We2gQcoeU/8zkdAd9xuaV8q/ybA/J9tvQBrrlFpg45NfoyESG9lg== X-Received: by 2002:a05:6512:39c2:b0:53d:a99e:b768 with SMTP id 2adb3069b0e04-53da99ebce0mr590942e87.25.1731601146055; Thu, 14 Nov 2024 08:19:06 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab76dafsm25510275e9.10.2024.11.14.08.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:19:05 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 11/15] RISC-V: Define irqbypass vcpu_info Date: Thu, 14 Nov 2024 17:18:56 +0100 Message-ID: <20241114161845.502027-28-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The vcpu_info parameter to irq_set_vcpu_affinity() effectively defines an arch specific IOMMU <=> hypervisor protocol. Provide a definition for the RISCV IOMMU. Signed-off-by: Andrew Jones --- arch/riscv/include/asm/irq.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h index 7b038f3b7cb0..8588667cbb5f 100644 --- a/arch/riscv/include/asm/irq.h +++ b/arch/riscv/include/asm/irq.h @@ -23,6 +23,15 @@ void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void)); struct fwnode_handle *riscv_get_intc_hwnode(void); +struct riscv_iommu_vcpu_info { + u64 msi_addr_pattern; + u64 msi_addr_mask; + u32 group_index_bits; + u32 group_index_shift; + u64 gpa; + u64 hpa; +}; + #ifdef CONFIG_ACPI enum riscv_irqchip_type { From patchwork Thu Nov 14 16:18:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875433 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C99E1AAE1D for ; Thu, 14 Nov 2024 16:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601151; cv=none; b=IW7TwR64+AnlhB9Wof26mAFUYaXLgeUqE6CRyv2EKfFHeXMqxv/Pr41ygSMzuWvLwwd1gLimOa5Si/jHaS8umi98kqfINi0TZ7EJ3HTkOkrNHSZ7Ioz9oZgt7Cvvbi02ZjWwRgydYHzbAQYAqtnfBNwFnXs3TPk/CMVEO0poOCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601151; c=relaxed/simple; bh=TFtkar47iRvavG7LpOfAS59Gk/J7yKNnx1BiLzNhwhw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z1jOi1WMBidhz4W1WTPEDPfj+YhRwn5lyQku6f5vHP3+2clW38vqF46hC2dLi4PVRD+tc791aIj4shGPbEnWGiw/OyXjDJ/ST/vIOICsMQDV2DmbfYGGnRi4gaVBESn42sTE6vFXH0qe9G6ysHMo30BNjafqiQddCaCA+1wjXYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=A4X/nqPm; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="A4X/nqPm" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-37d6a2aa748so499811f8f.1 for ; Thu, 14 Nov 2024 08:19:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601147; x=1732205947; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+uTuyHOKGUnE3VHWBJ7LYW/wszuVbaF5PQNKaXjnEr8=; b=A4X/nqPms2mqzeEN8bCdMwJ7VrdUuhdRMDBevZ1teUFRb15Zz6gUVroQep235Cgp0l d/c9yEx2lyl2PTPlaDqIo4vl0HrNY1IoPD7iWGYkyYHKBRM8F51lp7/DRWFl0aGl8KmD wK3zoKKsQKplorDb2XRnwv8cpUwyd0i4Y1uu3rsYptB87LulN5mENL3Vlll26vpRSRdG p4Onza33DjBnAs2xsQEKsTj7HLXUwBk9jjUslyaurnj1i3sPb8+yBKq5hH1Fo1EU8/4r 153gXU46g/2Mf3s9QNQV4GXhbO82XpOIrBfIdL8q7lzZFhN7AxzQ5hQD1sErngJ/hITG CZKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601147; x=1732205947; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+uTuyHOKGUnE3VHWBJ7LYW/wszuVbaF5PQNKaXjnEr8=; b=CvdYIs5rOB150IysuQ8hyAq1otKKCjag//M9wTP4G7Zkfy3KjstfU3bv4QVh+RJ1Y2 pt6gMFsbC74DuIVHs3H97Ax4J0YbTQKNVeHK7iRna2E1I8ngHVkTg6qHdLyehJX6Cpo5 Upxz20JEwxH4uV6GPT3iJktS8oyhPafXz4isfzs07UA24nhnQE6xA+iOJrNRGY+hvl8N kdKQRlXQhuybm64eBLm6bM8nyaiXXrSpNvO8phuPi8ZxpxwCtdfc873uzxa2Y+xaYsb7 7gJr4yKMEtEzpc7dwRMtXZe/+dgbEobRFnxNNyCrGrM4JhoXFwMGa0Mn2ZLQsKh83s11 kigA== X-Forwarded-Encrypted: i=1; AJvYcCWs9FjhopjHjhMB4ouKfmunTlP7lU9FhT8vu1wJbZi1VpzPSz8yOPHpoYnG3ScJiQw2Auw=@vger.kernel.org X-Gm-Message-State: AOJu0YxDcXHBaIe/x61njnwjR5vo6yCfTbzNM6mW0Vy7TlpcATYLs8UG LblK2wDMeFXDnSSIDWM5Htwla4r3Uvp197GADDEKY+d/Cg4PvvkrFSTq2F2l2ig= X-Google-Smtp-Source: AGHT+IF+dux3jioiQujAjXbkRVUUE8HYuaL/Pb+N/XvgW2ONJ3mvlvI5/3yMLnI7JF+vXby3PurS7Q== X-Received: by 2002:a05:6000:156b:b0:37d:498a:a233 with SMTP id ffacd0b85a97d-382185391demr2252298f8f.43.1731601147550; Thu, 14 Nov 2024 08:19:07 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3821ada4076sm1858965f8f.16.2024.11.14.08.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:19:07 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 12/15] iommu/riscv: Add guest file irqbypass support Date: Thu, 14 Nov 2024 17:18:57 +0100 Message-ID: <20241114161845.502027-29-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Implement irq_set_vcpu_affinity() in the RISCV IOMMU driver. irq_set_vcpu_affinity() is the channel from a hypervisor to the IOMMU needed to ensure that assigned devices which direct MSIs to guest IMSIC addresses will have those MSI writes redirected to their corresponding guest interrupt files. Signed-off-by: Andrew Jones --- drivers/iommu/riscv/iommu-ir.c | 151 +++++++++++++++++++++++++++++++++ drivers/iommu/riscv/iommu.c | 4 +- drivers/iommu/riscv/iommu.h | 3 + 3 files changed, 156 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/riscv/iommu-ir.c b/drivers/iommu/riscv/iommu-ir.c index c177e064b205..958270450ec1 100644 --- a/drivers/iommu/riscv/iommu-ir.c +++ b/drivers/iommu/riscv/iommu-ir.c @@ -7,6 +7,8 @@ #include #include +#include + #include "../iommu-pages.h" #include "iommu.h" @@ -52,10 +54,159 @@ static size_t riscv_iommu_ir_nr_msiptes(struct riscv_iommu_domain *domain) return max_idx + 1; } +static void riscv_iommu_ir_msitbl_inval(struct riscv_iommu_domain *domain, + struct riscv_iommu_msipte *pte) +{ + struct riscv_iommu_bond *bond; + struct riscv_iommu_device *iommu, *prev; + struct riscv_iommu_command cmd; + u64 addr; + + addr = pfn_to_phys(FIELD_GET(RISCV_IOMMU_MSIPTE_PPN, pte->pte)); + riscv_iommu_cmd_inval_gvma(&cmd); + riscv_iommu_cmd_inval_set_addr(&cmd, addr); + + /* Like riscv_iommu_iotlb_inval(), synchronize with riscv_iommu_bond_link() */ + smp_mb(); + + rcu_read_lock(); + + prev = NULL; + list_for_each_entry_rcu(bond, &domain->bonds, list) { + iommu = dev_to_iommu(bond->dev); + + if (iommu == prev) + continue; + + riscv_iommu_cmd_send(iommu, &cmd); + riscv_iommu_cmd_sync(iommu, RISCV_IOMMU_IOTINVAL_TIMEOUT); + prev = iommu; + } + + rcu_read_unlock(); +} + +static void riscv_iommu_ir_msitbl_update(struct riscv_iommu_domain *domain, + struct riscv_iommu_msiptp_state *msiptp) +{ + struct riscv_iommu_bond *bond; + struct riscv_iommu_device *iommu, *prev; + struct riscv_iommu_command cmd; + struct iommu_fwspec *fwspec; + struct riscv_iommu_dc *dc; + int i; + + /* Like riscv_iommu_ir_msitbl_inval(), synchronize with riscv_iommu_bond_link() */ + smp_mb(); + rcu_read_lock(); + + prev = NULL; + list_for_each_entry_rcu(bond, &domain->bonds, list) { + iommu = dev_to_iommu(bond->dev); + fwspec = dev_iommu_fwspec_get(bond->dev); + + for (i = 0; i < fwspec->num_ids; i++) { + dc = riscv_iommu_get_dc(iommu, fwspec->ids[i]); + WRITE_ONCE(dc->msiptp, msiptp->msiptp); + WRITE_ONCE(dc->msi_addr_mask, msiptp->msi_addr_mask); + WRITE_ONCE(dc->msi_addr_pattern, msiptp->msi_addr_pattern); + } + + dma_wmb(); + + if (iommu == prev) + continue; + + riscv_iommu_cmd_inval_gvma(&cmd); + riscv_iommu_cmd_send(iommu, &cmd); + riscv_iommu_cmd_sync(iommu, RISCV_IOMMU_IOTINVAL_TIMEOUT); + prev = iommu; + } + + rcu_read_unlock(); +} + +static int riscv_iommu_ir_msitbl_init(struct riscv_iommu_domain *domain, + struct riscv_iommu_vcpu_info *vcpu_info) +{ + domain->msiptp.msi_addr_pattern = vcpu_info->msi_addr_pattern; + domain->msiptp.msi_addr_mask = vcpu_info->msi_addr_mask; + domain->group_index_bits = vcpu_info->group_index_bits; + domain->group_index_shift = vcpu_info->group_index_shift; + + if (riscv_iommu_ir_nr_msiptes(domain) * sizeof(*domain->msi_root) > PAGE_SIZE * 2) + return -ENOMEM; + + domain->msiptp.msiptp = virt_to_pfn(domain->msi_root) | + FIELD_PREP(RISCV_IOMMU_DC_MSIPTP_MODE, + RISCV_IOMMU_DC_MSIPTP_MODE_FLAT); + + riscv_iommu_ir_msitbl_update(domain, &domain->msiptp); + + return 0; +} + +static int riscv_iommu_irq_set_vcpu_affinity(struct irq_data *data, void *info) +{ + struct riscv_iommu_vcpu_info *vcpu_info = info; + struct riscv_iommu_domain *domain = data->domain->host_data; + struct riscv_iommu_msipte *pte; + int ret = -EINVAL; + u64 pteval; + + if (WARN_ON(domain->domain.type != IOMMU_DOMAIN_UNMANAGED)) + return ret; + + spin_lock(&domain->msi_lock); + + if (!domain->msiptp.msiptp) { + if (WARN_ON(!vcpu_info)) + goto out_unlock; + + ret = riscv_iommu_ir_msitbl_init(domain, vcpu_info); + if (ret) + goto out_unlock; + } else if (!vcpu_info) { + /* + * Nothing to do here since we don't track host_irq <=> msipte mappings + * nor reference count the ptes. If we did do that tracking then we would + * decrement the reference count of the pte for the host_irq and possibly + * clear its valid bit if it was the last one mapped. + */ + ret = 0; + goto out_unlock; + } else if (WARN_ON(vcpu_info->msi_addr_pattern != domain->msiptp.msi_addr_pattern || + vcpu_info->msi_addr_mask != domain->msiptp.msi_addr_mask || + vcpu_info->group_index_bits != domain->group_index_bits || + vcpu_info->group_index_shift != domain->group_index_shift)) { + goto out_unlock; + } + + pte = riscv_iommu_ir_get_msipte(domain, vcpu_info->gpa); + if (!pte) + goto out_unlock; + + pteval = FIELD_PREP(RISCV_IOMMU_MSIPTE_M, 3) | + riscv_iommu_phys_to_ppn(vcpu_info->hpa) | + FIELD_PREP(RISCV_IOMMU_MSIPTE_V, 1); + + if (pte->pte != pteval) { + pte->pte = pteval; + riscv_iommu_ir_msitbl_inval(domain, pte); + } + + ret = 0; + +out_unlock: + spin_unlock(&domain->msi_lock); + return ret; +} + static struct irq_chip riscv_iommu_irq_chip = { .name = "IOMMU-IR", .irq_mask = irq_chip_mask_parent, .irq_unmask = irq_chip_unmask_parent, + .irq_set_vcpu_affinity = riscv_iommu_irq_set_vcpu_affinity, }; static int riscv_iommu_irq_domain_alloc_irqs(struct irq_domain *irqdomain, diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index c4a47b21c58f..46ac228ba7ac 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -544,8 +544,8 @@ static irqreturn_t riscv_iommu_fltq_process(int irq, void *data) } /* Lookup and initialize device context info structure. */ -static struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iommu, - unsigned int devid) +struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iommu, + unsigned int devid) { const bool base_format = !(iommu->caps & RISCV_IOMMU_CAPABILITIES_MSI_FLAT); unsigned int depth; diff --git a/drivers/iommu/riscv/iommu.h b/drivers/iommu/riscv/iommu.h index 6ce71095781c..2ca76edf48f5 100644 --- a/drivers/iommu/riscv/iommu.h +++ b/drivers/iommu/riscv/iommu.h @@ -127,6 +127,9 @@ struct riscv_iommu_bond { int riscv_iommu_init(struct riscv_iommu_device *iommu); void riscv_iommu_remove(struct riscv_iommu_device *iommu); +struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iommu, + unsigned int devid); + void riscv_iommu_cmd_send(struct riscv_iommu_device *iommu, struct riscv_iommu_command *cmd); void riscv_iommu_cmd_sync(struct riscv_iommu_device *iommu, From patchwork Thu Nov 14 16:18:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875434 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BC3C1ABEA5 for ; Thu, 14 Nov 2024 16:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601153; cv=none; b=I1FHPgEuNhpbKOWq8Yqrvubt/6OribeOeiHoPyONwanY6d73hMzZLRXhZmzYfUohv+Y/tDJfCQkci/QanUuYpLX707raOl6uqAhamKF1Gu34VRvQMAFYzNTfLXtLyUtxHznDrMABFZgZMGUudGPur30v/vq4g9Ictp0ew/uMC2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601153; c=relaxed/simple; bh=u/8uTbD/TLPDkTbsVh/aqh2UnYJ2kwaG/0urCXnRHYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oRrgz1MIROxws9YmEmu3v4NNLkTqGTpt8bPFq0iiOOM1wi4Rw+5SRrFXurHdLyQTSh1VKFtCbxpMCxpWoGQxYDneNG7FvALuywB5UE+DD0lRXDT4akS73PaYKDDOwxrf1mQUNfa4guGo4ehWvV5nGGsBx2mQOSHySBvoFnX0INs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=SC7VkfU8; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="SC7VkfU8" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-431481433bdso7140915e9.3 for ; Thu, 14 Nov 2024 08:19:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601149; x=1732205949; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pFFBRicSLcryUXTcW4czNg2bW4hUi+sNV0Va2EAONJ0=; b=SC7VkfU8iCwbc2eSLPG+OBq+8zDTAbBnyQFRomHLnoBBL8w5k/cunsMQcnUg8y4i1B YQk2Cv/U3Oz+LSb2FqutN2bPvz/0jDC9oMA+s+VGrBjq+0fkqx/cd7mle9RylTbXPjCf Om8zoFn8V8o7zApeEkK11GrI45GNxJM+Xrw02JuJeIu/J2Ce9EZahrKRKDE/9rvm8CAg Aa0yQm5LNVPom/5ZSC5vX1IHp51INaBrhBCGGuOX6rWz+cMGptD4MIG2rPSj1lfI+ULX NKm9PflpQJMQCI+PhnvQ9SfUQYXKQdOcmrKZ7yxzZ10RcFovtR9zJf+dWn+bc9Ua3ECJ EtrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601149; x=1732205949; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pFFBRicSLcryUXTcW4czNg2bW4hUi+sNV0Va2EAONJ0=; b=ZVDnAwylqJeI4mcoPYPHTsct+HeKkVy7T40puh0g/5FHrvw+YyHTi/4iXKry4tu3w6 56g/Eyw8KNnOsmnX08hS5DZl/8wwnY9/IOCNSQq4y3rA0062cXcQduNAGuMsH7wOQUbS Sc6an6dQZ6EakQ9UKsxvqoR01M8D/8mN0TNqVbzEe0+l0mCkGK/wv86PmZfe2QBZm6xq E0ANNxW/9EyI9V/qzUH2FpHEOxLqzj3b+2YmHPN2qdhAsx9egVq5FUFPWTZpHFhoVD// 6ocW0IJIVZy0ZTJTt7ruGmzrc6y+0OOKIVAFgc5sHuRs/8sDMwgdG6CQLKOjTEF+ezem sISA== X-Forwarded-Encrypted: i=1; AJvYcCUuoSVxwg2f9qp0tZmbTYllkUxpf2S9GY4QrAe/V6T1zYGk6HDshA5L5S2NztI4vbJtqxY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxx1CUDstwtnOmQU8x72v97hEC5hLuOBEuSAMHW+4Y/B5TzVITL 3gl1oSPXJa/r4CVMo64CDpfNxEXQtEWTTFcQ7fRxZSq/JgZCmPbVhWaHJs8xM7U= X-Google-Smtp-Source: AGHT+IFGPNdzokCF0Smmz2HXrxBVONdHjbl61VaRzcWcWTFU5SBB8vXJqki1qLp7dZUHNDK1wlI75g== X-Received: by 2002:a05:600c:a48:b0:431:5f1c:8359 with SMTP id 5b1f17b1804b1-432d4ab9134mr73117815e9.15.1731601149016; Thu, 14 Nov 2024 08:19:09 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432da28b76fsm29185835e9.28.2024.11.14.08.19.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:19:08 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 13/15] RISC-V: KVM: Add guest file irqbypass support Date: Thu, 14 Nov 2024 17:18:58 +0100 Message-ID: <20241114161845.502027-30-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Implement kvm_arch_update_irqfd_routing() which makes irq_set_vcpu_affinity() calls whenever the assigned device updates its target addresses and whenever the hypervisor has migrated a VCPU to another CPU (which requires changing the guest interrupt file). Signed-off-by: Andrew Jones --- arch/riscv/kvm/aia_imsic.c | 132 ++++++++++++++++++++++++++++++++++++- arch/riscv/kvm/vm.c | 2 +- 2 files changed, 130 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kvm/aia_imsic.c b/arch/riscv/kvm/aia_imsic.c index 64b1f3713dd5..6a7c23e25f79 100644 --- a/arch/riscv/kvm/aia_imsic.c +++ b/arch/riscv/kvm/aia_imsic.c @@ -11,11 +11,13 @@ #include #include #include +#include #include #include #include #include #include +#include #define IMSIC_MAX_EIX (IMSIC_MAX_ID / BITS_PER_TYPE(u64)) @@ -676,6 +678,14 @@ static void imsic_swfile_update(struct kvm_vcpu *vcpu, imsic_swfile_extirq_update(vcpu); } +static u64 kvm_riscv_aia_msi_addr_mask(struct kvm_aia *aia) +{ + u64 group_mask = BIT(aia->nr_group_bits) - 1; + + return (group_mask << (aia->nr_group_shift - IMSIC_MMIO_PAGE_SHIFT)) | + (BIT(aia->nr_hart_bits + aia->nr_guest_bits) - 1); +} + void kvm_riscv_vcpu_aia_imsic_release(struct kvm_vcpu *vcpu) { unsigned long flags; @@ -730,7 +740,120 @@ void kvm_riscv_vcpu_aia_imsic_release(struct kvm_vcpu *vcpu) int kvm_arch_update_irqfd_routing(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, bool set) { - return -ENXIO; + struct irq_data *irqdata = irq_get_irq_data(host_irq); + struct kvm_irq_routing_table *irq_rt; + struct kvm_vcpu *vcpu; + unsigned long tmp, flags; + int idx, ret = -ENXIO; + + if (!set) + return irq_set_vcpu_affinity(host_irq, NULL); + + idx = srcu_read_lock(&kvm->irq_srcu); + irq_rt = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu); + if (guest_irq >= irq_rt->nr_rt_entries || + hlist_empty(&irq_rt->map[guest_irq])) { + pr_warn_once("no route for guest_irq %u/%u (broken user space?)\n", + guest_irq, irq_rt->nr_rt_entries); + goto out; + } + + kvm_for_each_vcpu(tmp, vcpu, kvm) { + struct imsic *imsic = vcpu->arch.aia_context.imsic_state; + gpa_t ippn = vcpu->arch.aia_context.imsic_addr >> IMSIC_MMIO_PAGE_SHIFT; + struct kvm_aia *aia = &kvm->arch.aia; + struct kvm_kernel_irq_routing_entry *e; + + hlist_for_each_entry(e, &irq_rt->map[guest_irq], link) { + struct msi_msg msg[2] = { + { + .address_hi = e->msi.address_hi, + .address_lo = e->msi.address_lo, + .data = e->msi.data, + }, + }; + struct riscv_iommu_vcpu_info vcpu_info = { + .msi_addr_mask = kvm_riscv_aia_msi_addr_mask(aia), + .group_index_bits = aia->nr_group_bits, + .group_index_shift = aia->nr_group_shift, + }; + gpa_t target, tppn; + + if (e->type != KVM_IRQ_ROUTING_MSI) + continue; + + target = ((gpa_t)e->msi.address_hi << 32) | e->msi.address_lo; + tppn = target >> IMSIC_MMIO_PAGE_SHIFT; + + WARN_ON(target & (IMSIC_MMIO_PAGE_SZ - 1)); + + if (ippn != tppn) + continue; + + vcpu_info.msi_addr_pattern = tppn & ~vcpu_info.msi_addr_mask; + vcpu_info.gpa = target; + + read_lock_irqsave(&imsic->vsfile_lock, flags); + + if (WARN_ON_ONCE(imsic->vsfile_cpu < 0)) { + read_unlock_irqrestore(&imsic->vsfile_lock, flags); + goto out; + } + + vcpu_info.hpa = imsic->vsfile_pa; + + ret = irq_set_vcpu_affinity(host_irq, &vcpu_info); + if (ret) { + read_unlock_irqrestore(&imsic->vsfile_lock, flags); + goto out; + } + + irq_data_get_irq_chip(irqdata)->irq_write_msi_msg(irqdata, msg); + + read_unlock_irqrestore(&imsic->vsfile_lock, flags); + } + } + + ret = 0; +out: + srcu_read_unlock(&kvm->irq_srcu, idx); + return ret; +} + +static int kvm_riscv_vcpu_irq_update(struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + struct imsic *imsic = vcpu->arch.aia_context.imsic_state; + struct kvm_aia *aia = &kvm->arch.aia; + u64 mask = kvm_riscv_aia_msi_addr_mask(aia); + u64 target = vcpu->arch.aia_context.imsic_addr; + struct riscv_iommu_vcpu_info vcpu_info = { + .msi_addr_pattern = (target >> IMSIC_MMIO_PAGE_SHIFT) & ~mask, + .msi_addr_mask = mask, + .group_index_bits = aia->nr_group_bits, + .group_index_shift = aia->nr_group_shift, + .gpa = target, + .hpa = imsic->vsfile_pa, + }; + struct kvm_kernel_irqfd *irqfd; + int host_irq, ret; + + spin_lock_irq(&kvm->irqfds.lock); + + list_for_each_entry(irqfd, &kvm->irqfds.items, list) { + if (!irqfd->producer) + continue; + host_irq = irqfd->producer->irq; + ret = irq_set_vcpu_affinity(host_irq, &vcpu_info); + if (ret) { + spin_unlock_irq(&kvm->irqfds.lock); + return ret; + } + } + + spin_unlock_irq(&kvm->irqfds.lock); + + return 0; } int kvm_riscv_vcpu_aia_imsic_update(struct kvm_vcpu *vcpu) @@ -797,14 +920,17 @@ int kvm_riscv_vcpu_aia_imsic_update(struct kvm_vcpu *vcpu) if (ret) goto fail_free_vsfile_hgei; - /* TODO: Update the IOMMU mapping ??? */ - /* Update new IMSIC VS-file details in IMSIC context */ write_lock_irqsave(&imsic->vsfile_lock, flags); + imsic->vsfile_hgei = new_vsfile_hgei; imsic->vsfile_cpu = vcpu->cpu; imsic->vsfile_va = new_vsfile_va; imsic->vsfile_pa = new_vsfile_pa; + + /* Update the IOMMU mapping */ + kvm_riscv_vcpu_irq_update(vcpu); + write_unlock_irqrestore(&imsic->vsfile_lock, flags); /* diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c index 9c5837518c1a..5f697d9a37da 100644 --- a/arch/riscv/kvm/vm.c +++ b/arch/riscv/kvm/vm.c @@ -78,7 +78,7 @@ EXPORT_SYMBOL_GPL(kvm_arch_has_assigned_device); bool kvm_arch_has_irq_bypass(void) { - return false; + return true; } int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons, From patchwork Thu Nov 14 16:18:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875435 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12F5D1AC88A for ; Thu, 14 Nov 2024 16:19:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601153; cv=none; b=AJ8OTxrjHhhjlpEO9KLndV5YH+NZOF01BpCtx6HRWN5/Ga0CKFT/V5L+B6e1xa24eAhLfV3vTP0FbBxu68/o9SU0JXlcg3T+h4aOH4P8WZgUP6NZi9R6NONVChSAfVZXfGP9MhWC05KkwEc+yZqC1oJu5NmJR8RPwBZKY8c1jBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601153; c=relaxed/simple; bh=ES0TvAxz9/x2ptiDnzIz0eP+Ou6/i+zYJHVn+dCYtjM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rOmOlweThrFJy6Tv+FcTlzpZ6b6Hpn5yHGtuWlTEgT46SKBYJaIVysVDWsAIUZ3j4wsx08gL4VJy/JjHoXLRCj5xbMthIWxdiAEWBEtygI36jI57OoR5lqv104hw+9Ue2k97IGm6hwitHxbT779RLjLWW8DJGeDbG938BWD0a3k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=LQsagkWD; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="LQsagkWD" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4315e62afe0so7662455e9.1 for ; Thu, 14 Nov 2024 08:19:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601150; x=1732205950; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BmqNGe/T2iE9PlV9lB2/3K3MC1TQA7fI1NussKF1DE0=; b=LQsagkWDpQ09Orr95W2tYqbVr5m6ZwXuTCLazfrX6HiwLKpF0BBxavxZURIXdq/Wrs O/XIT6O+69q5zC8NXSVTiBpJ5lVkg/cT4qJm1wn9VRjDaa/1tN5blgJXCaH8fLWePHeE kta4aTjJqZNrE2H9Qsopq8q3PXcG3RvjVh2iBWi12Em5vOdykiEEIlNefwuuStFqwSv5 D51jsaIiXgD3vKMuKI51T0lGlHsAxA8gdX/zXkgY2RIwj2XhmUdHSfw/WyvDS7YivgYH 5vd9SiRpfyjJAyhf7/xwtIPW4FnmuVgIPu/uKlNnFPnIBPSpZ88wAHOpZZyjNTcHeA+N wqjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601150; x=1732205950; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BmqNGe/T2iE9PlV9lB2/3K3MC1TQA7fI1NussKF1DE0=; b=TW6JMo2mudZIEaVQoKmRbov0iqLwhcllrUdzNOGwrQOThR5oW9rQBVkhidrSBC1Dax WQBVrmjQaR2ahRq05YwP9aDlEdtoYfQ/repnY4Ky+j1kdDIoBXQvWNTGBXY+XtPWnQeN 8UW8ScTxGYjyx5XUQonmgrlnrUYMWeo8Q+PtGzbx4rfYNPlGo9G4SGe2fOy6XSO3c+ls RojmQECNEBVWOoznHGxxwSdsNWlCCi/4NKQhzPEBh20GXmw0q0xNXSZvrXbDwXSz52GS H6GD36keJ4dQFgsx1Gx01Ay/QzjwT4ZpZLiSsx4VqmaMhLgcySHAcZyUUiKRWq+mbndy uubA== X-Forwarded-Encrypted: i=1; AJvYcCXJ4w1pcYNN0hZBJ2Y7ItoTXLO/yfRGRinmUkBXAI+zw0JFEA/uTB5Rm7KJnG3pZd6i1f4=@vger.kernel.org X-Gm-Message-State: AOJu0Yya9F0Fg9v/Lme7XNFLUbgbqEKAedZfN4WRxUY4+cysSj15vt9/ yzkrM+kT5MHK8enH+8gMpXsCF5tQtVZUEj4ttUninYiVfn6EkbBV4CKpF8x2JHU= X-Google-Smtp-Source: AGHT+IGMbtDDWmvKWsj/Ybdc9TgUB55aFH3ajhr0ZnMlCbsRayCj2n5LaLaeoDlbaJzuEn6VOd9B/g== X-Received: by 2002:a05:600c:8715:b0:431:93d8:e1a1 with SMTP id 5b1f17b1804b1-432b751bcc2mr209410385e9.27.1731601150428; Thu, 14 Nov 2024 08:19:10 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3821adbe779sm1834550f8f.60.2024.11.14.08.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:19:09 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 14/15] vfio: enable IOMMU_TYPE1 for RISC-V Date: Thu, 14 Nov 2024 17:18:59 +0100 Message-ID: <20241114161845.502027-31-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Tomasz Jeznach Enable VFIO support on RISC-V architecture. Signed-off-by: Tomasz Jeznach Signed-off-by: Andrew Jones --- drivers/vfio/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vfio/Kconfig b/drivers/vfio/Kconfig index ceae52fd7586..ad62205b4e45 100644 --- a/drivers/vfio/Kconfig +++ b/drivers/vfio/Kconfig @@ -39,7 +39,7 @@ config VFIO_GROUP config VFIO_CONTAINER bool "Support for the VFIO container /dev/vfio/vfio" - select VFIO_IOMMU_TYPE1 if MMU && (X86 || S390 || ARM || ARM64) + select VFIO_IOMMU_TYPE1 if MMU && (X86 || S390 || ARM || ARM64 || RISCV) depends on VFIO_GROUP default y help From patchwork Thu Nov 14 16:19:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13875436 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E986F1ADFEA for ; Thu, 14 Nov 2024 16:19:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601155; cv=none; b=Yyjt0T5ZUEtF31NdhOuIscVzDrxCXX26saKhTgrpc5epUV5jxN7Z6bhA662CFQ3uXczxdukaxVfXZEcZOma9xmcHrcl140FpHDn8GHjrNyisP9qSozTQ1yeZrWgFEpomGDXxaQG580BBP5dJfJUdHcY/3YE+dQ4ODZ0C41wAakQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731601155; c=relaxed/simple; bh=nPnauxX7TiBvZUSelznoj4ZrHIzLIbMVHtA1EyH4RVI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bJm/ImB1izp2K2Bc5qBZVWAfB/pnBkNwYSG82aDSZUV81v1FBBFOQOTP6dHIs2nBTMXcAsfa46PVZVDIRrIQ4B0Dfz8+AnhsHsEY3eu1jhRwJslXlfXuSPKUTFVNg1AqFd1lOaV6tIk4QlAKlP8lsVUDFYqUxZzlQ8EtxoTD9gs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=i/dm21c6; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="i/dm21c6" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4315e9e9642so7301125e9.0 for ; Thu, 14 Nov 2024 08:19:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1731601152; x=1732205952; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bLyjPEUjYy3GGHllbim/73zpVvmemz3R8H3vfZF+LqU=; b=i/dm21c6mHbPUh0kR2V+NaD9L4LdKkTk3mInd+TPeSVk7MDkqijGAwQrIB9Z+T1zJc xmfoA+ATnVC7IRs/FxWba3DRi/SGb+YLPbfDLxhAE3ccENfNOQA6fpzeA3CQlyJ0aOs5 wboMSAFzZrIVvtHiYsvDar7j2RDk3qRxZpbmhPlnAeR34oS3U4jkMHMyJ1v/vKx7+j4P TLnqGL7KqozomSlKbuk8pOW6oKctTDeAza+O5PP0S3VJGnXumADG8H0T2sL/WT+XER1s Nff69oehon4dCrZ+XEi+GZ64a4nRuKatR39W/gcl3wV4YEiMqM3CdzpuKxGxpa9UT0Dg RbVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731601152; x=1732205952; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bLyjPEUjYy3GGHllbim/73zpVvmemz3R8H3vfZF+LqU=; b=fXtztU9sutkK3q4r/RrHGzbHcOQhsn895YxpV4fiHsuTzU2TPz9banr3gCfJeOelUB jbMOilxvHYVUuo/ekXIQRzMLCIDMq54HkU3FIZaMhA1nz0P398NukYHqltbIQ0rzo0W1 B1MDhnrNL6/cQSZ+go97mB+7pZuQBo/3UbWaOj989lTqDYk2SMU9+/ujBRpN+qDm0HCM KJQHrgDuFHgZ960IbHlCQzsw/joHYVFSbx2TJdv4o5kwQxy/DG8oBshPOD8/b0Jy7m69 eZj8psbvdaWdug7vfpo81YJ/7UvmniLIguYAzmIglWCm88DKT9ICSj2KH2D3SUnq7OmM p4MA== X-Forwarded-Encrypted: i=1; AJvYcCXhtcj/a7nEjdY3P/+8XSy9MfOBo4kQx0cRFKNZFpgeNm4hevpugyGzpuH9NqEhlgkQ9y4=@vger.kernel.org X-Gm-Message-State: AOJu0YzWEOrPaJOXMqvqRCt9zGFDCRw/ls9sbF8Dlr5bwj4M0ljQzMp1 H34gMxTpezvf5VdtkDOIx2kuYJ/NGlhg+bPjmsgcVx9AZDsD+JZF6GVi+HnH+jo= X-Google-Smtp-Source: AGHT+IHKQidNVhwcm1UkvoSFM0iFKvguMA4Koj+yRoQBZD+zU91sO767fbB1E85gsh6vbgzv0SLQ3g== X-Received: by 2002:a05:600c:c08:b0:42c:bd27:4c12 with SMTP id 5b1f17b1804b1-432d4aae6b7mr76573235e9.10.1731601152220; Thu, 14 Nov 2024 08:19:12 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432da298a41sm29066525e9.38.2024.11.14.08.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 08:19:11 -0800 (PST) From: Andrew Jones To: iommu@lists.linux.dev, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: tjeznach@rivosinc.com, zong.li@sifive.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, anup@brainfault.org, atishp@atishpatra.org, tglx@linutronix.de, alex.williamson@redhat.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Subject: [RFC PATCH 15/15] RISC-V: defconfig: Add VFIO modules Date: Thu, 14 Nov 2024 17:19:00 +0100 Message-ID: <20241114161845.502027-32-ajones@ventanamicro.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241114161845.502027-17-ajones@ventanamicro.com> References: <20241114161845.502027-17-ajones@ventanamicro.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the VFIO modules to the defconfig to complement KVM now that there is IOMMU support. Signed-off-by: Andrew Jones --- arch/riscv/configs/defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig index b4a37345703e..10fc9d84a28c 100644 --- a/arch/riscv/configs/defconfig +++ b/arch/riscv/configs/defconfig @@ -242,6 +242,8 @@ CONFIG_RTC_DRV_SUN6I=y CONFIG_DMADEVICES=y CONFIG_DMA_SUN6I=m CONFIG_DW_AXI_DMAC=y +CONFIG_VFIO=m +CONFIG_VFIO_PCI=m CONFIG_VIRTIO_PCI=y CONFIG_VIRTIO_BALLOON=y CONFIG_VIRTIO_INPUT=y