From patchwork Thu Jun 15 07:33:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp460916vqr; Thu, 15 Jun 2023 00:53:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Dj2XYdYIew/tenHB8pHWyvtT8qXSw/Q4KDRAF5/dMo2+xNFta2jyAkWA2wsRs1RONpSM1 X-Received: by 2002:a17:907:3f83:b0:94f:704d:a486 with SMTP id hr3-20020a1709073f8300b0094f704da486mr17727468ejc.32.1686815636408; Thu, 15 Jun 2023 00:53:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686815636; cv=none; d=google.com; s=arc-20160816; b=0YkOuoQSARw7bMt66LWzW4ZlCN6ETaAtHq9ZTtYS8UsMQxRF0czVZV+4+5OYC3fZkY dR77nTvmX+04gIq/uJeIe4W6mK20H8nov6jiPf2wMwAxi8kd28B4ENqUQ2vrmMdPjK8D v5/RDDEEfEUnlaEimC+o+aCaVxG4/WVE98LE6mqIH36sl5PhqpD9lhUjHh8L5rJ92n5Z 8YErwVsi66jttiYil4qpTRhOUbGVpZHOL3ZL3pQSb3DpBzemmR6ag+Jhbu2e4jbZZWVc x0Vo2aa9utf2ne1aarQ4dFG5SSv2a147jaD4Ljr362IccLHezJckzR+/OFQaguvhPCAm 6Glg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=uSVZgRG5YqM/eFQOFzsv+7qQx2kR6U7K/exhbfh3iHo=; b=Q2c+ZdKA7sDkGiWgmTE7qJ/WoAk+7+n0MSJyhOxImB3aNFQufyuBzMiKm+DJM3qODn 15MV11krj2lE/ZZUoYpPACrXAfiZqYTaYd2Yc9xBHrw2OdjRnB3DstiXOBmSSSc5udka wevHNJLmPzR6D+A1aDJXVT5iO9953Pmfv+HbHEzWw1hkLZUxblENxMuEsxLm58iwAztU P3+ut77zznqwx6D4b/JLRfUCRgY5DEJrD9NWl0MxUEtpn+h/31ybSIyGEor+bXBZLI/g U839oVqgpVhNmrubQlmVacasMCAzG8tktpCtiFFh75v6SlVcT/lOKH0w1jNCWxrPWvdC uqtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=ZU5NKMa7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a1709064a0400b00977ecf4ef8bsi9171300eju.54.2023.06.15.00.53.32; Thu, 15 Jun 2023 00:53:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=ZU5NKMa7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244940AbjFOHf3 (ORCPT + 99 others); Thu, 15 Jun 2023 03:35:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244993AbjFOHem (ORCPT ); Thu, 15 Jun 2023 03:34:42 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C0072949 for ; Thu, 15 Jun 2023 00:34:03 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-66615629689so1886386b3a.2 for ; Thu, 15 Jun 2023 00:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1686814443; x=1689406443; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uSVZgRG5YqM/eFQOFzsv+7qQx2kR6U7K/exhbfh3iHo=; b=ZU5NKMa7G4ct8b3MBmjVWKrm9NhEKEL5tmHTacR2un8854Mv7M7pqhvPirLhVQlLKD yQJrWHCAeRXcVIuM2TcU0o7A0ieXOuLIj9mPpX0XJAvWzt397TT8XVjBsBEjPQmCjUHi G6wwzmRmXhg8W1M7ODggv7uVUuVaMsRhPBVt+shONlAZyFq4rVmMix++00q5mtjr/wK2 rrsXFvjGIQZE5quFdViRsx8SRkNIb+eSdgUXVFzVNdJCEMBKlmIk39JaFHbnNrob+DWs TFLKaYjlcY2JbZxX3Ipx9OGlOT9J2DwPNPx4qP3MiX8qUURz0qzLsH3ZwbpHr1OFD3Gx 2eVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686814443; x=1689406443; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uSVZgRG5YqM/eFQOFzsv+7qQx2kR6U7K/exhbfh3iHo=; b=du+lR/MRK4BvnX2q018T2xbYkU8yhNchWNDolknOcmgWuojxpz3zMSY6iDj0ECdfdK M6aN6mFliatLs3wHTNH33OTajRYnTX8LIp4gZGErHdfaXFkz9rNtHrFuWUvDvYg7Trv+ IvNmRfPMDmYDOYP/t8zqqLF5AIbN/7DQYsKU/BYl7T0Vj9+QY+VmgUCui7D2ni+r6SVX MJGxBOgacqS6JY33d3TYH5nsBuAUMILhF8DLIuCnRqEeJgxEB1IcUWemWfwQFI1cBh28 qr7sAy2DHvwftH3FE+6ZZZVGSKdAl2GrFD3eefjkPM4puqALgSSkQN/MldGdz6iNYYVS XeQQ== X-Gm-Message-State: AC+VfDxulsMUncjwjH47l1z4720q2NGwib4tP5N9cBz3Hvotf9DVH3Ws 3Nh7OZqumzWUZVfK/U2m8DwO1Q== X-Received: by 2002:a05:6a21:329a:b0:10b:cdb1:3563 with SMTP id yt26-20020a056a21329a00b0010bcdb13563mr4810645pzb.46.1686814442720; Thu, 15 Jun 2023 00:34:02 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([106.51.83.242]) by smtp.gmail.com with ESMTPSA id ji1-20020a170903324100b001b016313b1dsm8049855plb.86.2023.06.15.00.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 00:34:02 -0700 (PDT) From: Anup Patel To: Paolo Bonzini , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Andrew Jones , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH v3 00/10] RISC-V KVM in-kernel AIA irqchip Date: Thu, 15 Jun 2023 13:03:43 +0530 Message-Id: <20230615073353.85435-1-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768754392452195091?= X-GMAIL-MSGID: =?utf-8?q?1768754392452195091?= This series adds in-kernel AIA irqchip to KVM RISC-V which trap-n-emulate IMSIC and APLIC MSI-mode for Guest. The APLIC MSI-mode trap-n-emulate is optional so KVM user space can emulate APLIC entirely in user space. The use of IMSIC HW guest files to accelerate IMSIC virtualization will be done as separate series since this depends on AIA irqchip drivers to be upstreamed. This series has no dependency on the AIA irqchip drivers. There is also a KVM AIA irq-bypass (or device MSI virtualization) series under development which depends on this series and upcoming IOMMU driver series. These patches (or this series) can also be found in the riscv_kvm_aia_irqchip_v3 branch at: https://github.com/avpatel/linux.git Changes since v2: - Added KVM_CAP_IRQCHIP in PATCH5 - Fix check for KVM_DEV_RISCV_AIA_CONFIG_IDS write in PATCH6 - Fix APLIC_IRQ_STATE_ENPEND usage in PATCH7 Changes since v1: - Rebased on Linux-6.4-rc6 - Addressed Atish's comment in PATCH6 - Added comments in arch/riscv/include/uapi/asm/kvm.h about APLIC and IMSIC device attribute type Anup Patel (10): RISC-V: KVM: Implement guest external interrupt line management RISC-V: KVM: Add IMSIC related defines RISC-V: KVM: Add APLIC related defines RISC-V: KVM: Set kvm_riscv_aia_nr_hgei to zero RISC-V: KVM: Skeletal in-kernel AIA irqchip support RISC-V: KVM: Implement device interface for AIA irqchip RISC-V: KVM: Add in-kernel emulation of AIA APLIC RISC-V: KVM: Expose APLIC registers as attributes of AIA irqchip RISC-V: KVM: Add in-kernel virtualization of AIA IMSIC RISC-V: KVM: Expose IMSIC registers as attributes of AIA irqchip arch/riscv/include/asm/kvm_aia.h | 107 ++- arch/riscv/include/asm/kvm_aia_aplic.h | 58 ++ arch/riscv/include/asm/kvm_aia_imsic.h | 38 + arch/riscv/include/asm/kvm_host.h | 4 + arch/riscv/include/uapi/asm/kvm.h | 72 ++ arch/riscv/kvm/Kconfig | 4 + arch/riscv/kvm/Makefile | 3 + arch/riscv/kvm/aia.c | 274 +++++- arch/riscv/kvm/aia_aplic.c | 619 ++++++++++++++ arch/riscv/kvm/aia_device.c | 673 +++++++++++++++ arch/riscv/kvm/aia_imsic.c | 1083 ++++++++++++++++++++++++ arch/riscv/kvm/main.c | 3 +- arch/riscv/kvm/vcpu.c | 2 + arch/riscv/kvm/vm.c | 118 +++ include/uapi/linux/kvm.h | 2 + 15 files changed, 3027 insertions(+), 33 deletions(-) create mode 100644 arch/riscv/include/asm/kvm_aia_aplic.h create mode 100644 arch/riscv/include/asm/kvm_aia_imsic.h create mode 100644 arch/riscv/kvm/aia_aplic.c create mode 100644 arch/riscv/kvm/aia_device.c create mode 100644 arch/riscv/kvm/aia_imsic.c