From patchwork Wed Apr 19 22:23:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13217570 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AA48C6FD18 for ; Wed, 19 Apr 2023 22:27:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233317AbjDSW1X (ORCPT ); Wed, 19 Apr 2023 18:27:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233233AbjDSW1A (ORCPT ); Wed, 19 Apr 2023 18:27:00 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED256B478 for ; Wed, 19 Apr 2023 15:25:34 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-524b02cc166so67506a12.0 for ; Wed, 19 Apr 2023 15:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943044; x=1684535044; 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=LXsqDGUR1sIAzl083YrDdeF8Dcz5MG5TcoJ+FCFYQPE=; b=ohOEHO7BV/FHEqjDiY6pG/sbPPkvlHxUUXDxUV7dZqgZIIWVcpKe0qvs+coh7D9ZRh B9hkxCLFKh8o9nAC2rlRn7bMm1mBtWYtjnNK9pkEtJDD583cXnspj2Ze6kFtPx4sD05T M0i9ezLAErgLCl4r/YZAwl7ub1kBW72A2bCM2VN+GllxhNlhbw4174U5Fs0Rqs8lwuLx 6dFmv6DPhfk7Q0h+47Fu4cY06lgOcb8Yfc8WZoxCPJavUfQg727zdhXtl53U+ZG5ga3H Ua4k+o9Cp2yjV6jziSpH7zmCITKPG2JXN/AwelqUy5IqPzKZ18t594Y0qlAjZCJGwgwu OUiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943044; x=1684535044; 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=LXsqDGUR1sIAzl083YrDdeF8Dcz5MG5TcoJ+FCFYQPE=; b=YfF8uBaKMVwLgaI4EhqamUFtPbXFFhnNr/j7NpPuF26Mf51Yi4NBOES9tSvSgvP5yd cjMhyZYlQKq73WmDeaA8dXKHJ8lHm3H8oHXN6eEiWuiGcx/vqqCtii8nETSXdE3VaFQ8 kwNpc6bAAiz2pQHLLoeWFS5W0tmT/VqV21m65fHJnIu39AkSxUue67J/MPdDlzezbr9b I4YL4Yg8aakyOv5fw+KiiwjU8CZWGRYf2qWVe72cFZQ1V1CSHdnnvFb+EnSOvjbgYAIu Jzha7D7BIV3yFLDrhn0+qn0XXRO1k0GH4yRnAUSci2mlPdjA6N8fUuIsMBcWzid6sZeP Iq/A== X-Gm-Message-State: AAQBX9fT9p/gYkNFVxVZFYepvyQRBbOamKpWfN3ZcEqN3o54QBZs0rTB d/Gy4G0umWT9bTcE1b4AZxFthA== X-Google-Smtp-Source: AKy350ZHJJEltFWMtiEqeoirE/coBcaQIIAAD+T2dcklEUVhjT2GbyU5FBvkRUpdkDap1R/DwivJLA== X-Received: by 2002:a17:90a:be01:b0:247:1e30:5880 with SMTP id a1-20020a17090abe0100b002471e305880mr3727645pjs.38.1681943044256; Wed, 19 Apr 2023 15:24:04 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id e4-20020a170902744400b001a681fb3e77sm11867810plt.44.2023.04.19.15.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:24:04 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Rajnesh Kanwal , Uladzislau Rezki Subject: [RFC kvmtool 01/10] riscv: Add a CoVE VM type. Date: Wed, 19 Apr 2023 15:23:41 -0700 Message-Id: <20230419222350.3604274-2-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419222350.3604274-1-atishp@rivosinc.com> References: <20230419222350.3604274-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The KVM needs to distinguish if an user wants to create a CoVE VM instead of a traditional VM. Define a RISC-V specific CoVE VM type that can be passed as a VM type. Signed-off-by: Atish Patra --- include/linux/kvm.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/kvm.h b/include/linux/kvm.h index ba4c4b0..000d2b9 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -911,6 +911,8 @@ struct kvm_ppc_resize_hpt { #define KVM_VM_TYPE_ARM_IPA_SIZE_MASK 0xffULL #define KVM_VM_TYPE_ARM_IPA_SIZE(x) \ ((x) & KVM_VM_TYPE_ARM_IPA_SIZE_MASK) + +#define KVM_VM_TYPE_RISCV_COVE (1UL << 9) /* * ioctls for /dev/kvm fds: */ From patchwork Wed Apr 19 22:23:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13217577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34A78C77B7C for ; Wed, 19 Apr 2023 22:28:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233342AbjDSW2d (ORCPT ); Wed, 19 Apr 2023 18:28:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233626AbjDSW2J (ORCPT ); Wed, 19 Apr 2023 18:28:09 -0400 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64D96AD31 for ; Wed, 19 Apr 2023 15:26:37 -0700 (PDT) Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-51b0f9d7d70so287740a12.1 for ; Wed, 19 Apr 2023 15:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943046; x=1684535046; 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=nDYPek2GW62ZjpMwmsxfE9d0xDPaKHdBMm+cEZKc8s8=; b=gbm655ZKGYsSplRJThxaUIliJsDtxxCNHAd8Jsh9rquTj5wgjudHgZwJA550iZsQk9 VB0SQu2x2QDE7zie14SgvIe7dnOfITMaMnMjD/onrUT0al1gT1sDadgULueeivhnEmTD JNLdLb2hMXSDd97f9GLtgcoOoiKtiFWFueifxdMTSbyKE0Z6Gv5tcQoRd/Nk8sLhR8hd DGNAlG+7Czxou3KoS1S39Pu0wydKlsp73goQ0cZbb90x0/1svTeMdjxcJ4JUnBS4z1ue xceJZmumlSVFCncTt6FuOgv+xYSVDvprfYgxAUggRJ/YOlKDghslSrOk6KKM64ujkV1m 0exg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943046; x=1684535046; 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=nDYPek2GW62ZjpMwmsxfE9d0xDPaKHdBMm+cEZKc8s8=; b=gzd1Iad/u8JwSKY2eSeLw2BCj18rzkQZHbhv/cz+gBahNhQKVo1/Y5EY+RQMQrba9D CLnhvq2YVRVEm3DNjhO4BzZ9nt2lllH3pknjG9Hpw703laebYE56Ge3KIkLmqVKN2VqW Mal4lV50ax8+iGbwNkX/HrQyQcQyCJAU/vowwD4MXmDgXIhzVwtvtqtIZl8ruK4R/D1r IEY7W9A7pYUyXdVSOx3aJ4Ilfdc1IlDY2SUTMVIIp43KhbAAy6gRTA4Z/uPixkSK+5/I 5a9W/QBsj9sqXETjfFdi/XwX9Q1Re43oH+ksceRUk48O0YWy3S8a3KHialA062w67REP HGoQ== X-Gm-Message-State: AAQBX9eLz9hpI88HT0a8R+jau9nIAGFGmL44wi7/1CoZh8+MGDwS2Zqa 7yk1hdZV6oOYRYhMdplM3tN5X3B1XCHolVh5sZ4= X-Google-Smtp-Source: AKy350ZvU/B8LPyorDIQytWlfNOBgumMg9x+NGoZu6TjngTCY2lrTTdfxOrkdp5JkE0zcFgeJL83hQ== X-Received: by 2002:a17:903:120e:b0:1a6:c12d:9020 with SMTP id l14-20020a170903120e00b001a6c12d9020mr7842484plh.24.1681943046020; Wed, 19 Apr 2023 15:24:06 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id e4-20020a170902744400b001a681fb3e77sm11867810plt.44.2023.04.19.15.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:24:05 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Rajnesh Kanwal , Uladzislau Rezki Subject: [RFC kvmtool 02/10] riscv: Define a command line option for CoVE VM Date: Wed, 19 Apr 2023 15:23:42 -0700 Message-Id: <20230419222350.3604274-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419222350.3604274-1-atishp@rivosinc.com> References: <20230419222350.3604274-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The user should be able configure the VMM to instantiate a CoVE VM via a command line. Add the new option cove-vm. Signed-off-by: Atish Patra --- riscv/include/kvm/kvm-config-arch.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/riscv/include/kvm/kvm-config-arch.h b/riscv/include/kvm/kvm-config-arch.h index aed4fbf..01276ea 100644 --- a/riscv/include/kvm/kvm-config-arch.h +++ b/riscv/include/kvm/kvm-config-arch.h @@ -10,6 +10,7 @@ struct kvm_config_arch { u64 custom_mimpid; bool ext_disabled[KVM_RISCV_ISA_EXT_MAX]; bool sbi_ext_disabled[KVM_RISCV_SBI_EXT_MAX]; + bool cove_vm; }; #define OPT_ARCH_RUN(pfx, cfg) \ @@ -66,6 +67,7 @@ struct kvm_config_arch { "Disable SBI Experimental Extensions"), \ OPT_BOOLEAN('\0', "disable-sbi-vendor", \ &(cfg)->sbi_ext_disabled[KVM_RISCV_SBI_EXT_VENDOR], \ - "Disable SBI Vendor Extensions"), + "Disable SBI Vendor Extensions"), \ + OPT_BOOLEAN('\0', "cove-vm", &(cfg)->cove_vm, "CoVE VM"), #endif /* KVM__KVM_CONFIG_ARCH_H */ From patchwork Wed Apr 19 22:23:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13217575 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18F76C77B73 for ; Wed, 19 Apr 2023 22:28:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233765AbjDSW2Y (ORCPT ); Wed, 19 Apr 2023 18:28:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232503AbjDSW2B (ORCPT ); Wed, 19 Apr 2023 18:28:01 -0400 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E5E77A8B for ; Wed, 19 Apr 2023 15:26:25 -0700 (PDT) Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-5144a9c11c7so278317a12.2 for ; Wed, 19 Apr 2023 15:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943048; x=1684535048; 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=sx5yCGWct6pM6GpC/mvdByE459bnHS7kFRJEEmvmIAE=; b=3p9iTgdU1fM6SCFnmbdU2SRrkZIz70XAXwuZckkQOMwQBsxli9xyQOj3eelNgilUbh Ys8/7Ew5TPJfNpxVGDr0CtIGeK0FA4rEB+OIcbXgq5wyTLnVYPvSZ8aMalLarGl9SYQB 5RACL91+xtTKghPY756sehNtiuCKsCnVWuoe+lw1F03ENQxtWOfB9WS65O7GV37PILFO Dk35L2JW1UKZe1fvGcD1U01nAz5TPWWbGAHGpwD1ZT3uAJFTUyTj5jlwZGRm00f0H14O tl+5fi2Hb+F0OmZuIVTWcPUeShVBuC5Hht10Q7j0AV8S9TF+U8wIpbjtIc2XL8zQkszI EVlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943048; x=1684535048; 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=sx5yCGWct6pM6GpC/mvdByE459bnHS7kFRJEEmvmIAE=; b=LjysvHXg6JjJF7LbJ9nbRG4Np6IN9ljg2QNw5Cb8Be2AHYNGKfe8Wf05EHyKw4Kr7g p+uxDQyQ5Vgyr6AV4Ygu/70i4C8hGqu3EhqID31NyIN44RdRTmB7rEVy0SKEQ+ydcl+l 5r5iouygUxNHAxGszX8LeePQXMbz0JdLBPVMyRbYWeMsuQsm1aB4lKU6qXjRyGxM91Xr gbK+UWakFHqhUrNNyhu1h0tcc7NGXWzDBuawYxxoF4NQ5lrS9GsPSr265zDRwvOpPcPn Gf0JVd5jw0smtpoy+Ud0V3trKXErOofVAmqLHPMRDQg2eBqr0lnmiyP4YKFjNhD+PX1u c0zQ== X-Gm-Message-State: AAQBX9fXf9qK0cZuqxYPYDKsiCJF+fYY9XkXyFsf7LAeVNOZ4nRr1qLM nImwZ+xRKd8elYDdADVEvPBaoA== X-Google-Smtp-Source: AKy350YPzGRajmyQ2O5tL/h5sOqIMWA3WFpT3qCLbVNDZ6itlq+/cjeCHlrQkCoL9IBGQLSaGxxwuA== X-Received: by 2002:a17:903:2905:b0:19a:b869:f2f8 with SMTP id lh5-20020a170903290500b0019ab869f2f8mr5951568plb.21.1681943047880; Wed, 19 Apr 2023 15:24:07 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id e4-20020a170902744400b001a681fb3e77sm11867810plt.44.2023.04.19.15.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:24:07 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Rajnesh Kanwal , Uladzislau Rezki Subject: [RFC kvmtool 03/10] riscv: Define a measure region IOCTL Date: Wed, 19 Apr 2023 15:23:43 -0700 Message-Id: <20230419222350.3604274-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419222350.3604274-1-atishp@rivosinc.com> References: <20230419222350.3604274-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org CoVE VM images needs to be measured by the TSM. The VMM updates the host about these images via a new IOCTL. The host makes appropriate ecalls for TSM to perform the measurement. Signed-off-by: Atish Patra --- include/linux/kvm.h | 2 ++ riscv/include/asm/kvm.h | 6 ++++++ riscv/include/kvm/kvm-arch.h | 2 ++ riscv/kvm.c | 21 +++++++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/include/linux/kvm.h b/include/linux/kvm.h index 000d2b9..d4969a0 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -1547,6 +1547,8 @@ struct kvm_s390_ucas_mapping { #define KVM_PPC_SVM_OFF _IO(KVMIO, 0xb3) #define KVM_ARM_MTE_COPY_TAGS _IOR(KVMIO, 0xb4, struct kvm_arm_copy_mte_tags) +#define KVM_RISCV_COVE_MEASURE_REGION _IOR(KVMIO, 0xb5, struct kvm_riscv_cove_measure_region) + /* ioctl for vm fd */ #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device) diff --git a/riscv/include/asm/kvm.h b/riscv/include/asm/kvm.h index 1dce9a4..2bacc38 100644 --- a/riscv/include/asm/kvm.h +++ b/riscv/include/asm/kvm.h @@ -98,6 +98,12 @@ struct kvm_riscv_timer { __u64 state; }; +struct kvm_riscv_cove_measure_region { + unsigned long user_addr; + unsigned long gpa; + unsigned long size; +}; + /* * ISA extension IDs specific to KVM. This is not the same as the host ISA * extension IDs as that is internal to the host and should not be exposed diff --git a/riscv/include/kvm/kvm-arch.h b/riscv/include/kvm/kvm-arch.h index 9f2159f..08ac54a 100644 --- a/riscv/include/kvm/kvm-arch.h +++ b/riscv/include/kvm/kvm-arch.h @@ -120,4 +120,6 @@ void riscv__generate_irq_prop(void *fdt, u8 irq, enum irq_type irq_type); void riscv__irqchip_create(struct kvm *kvm); +void kvm_cove_measure_region(struct kvm *kvm, unsigned long uaddr, + unsigned long gpa, unsigned long rsize); #endif /* KVM__KVM_ARCH_H */ diff --git a/riscv/kvm.c b/riscv/kvm.c index a9ade1f..99b253e 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -13,6 +13,27 @@ struct kvm_ext kvm_req_ext[] = { { 0, 0 }, }; +void kvm_cove_measure_region(struct kvm *kvm, unsigned long uaddr, + unsigned long gpa, unsigned long rsize) +{ + int ret; + + if (!kvm->cfg.arch.cove_vm) + return; + + struct kvm_riscv_cove_measure_region mr = { + .user_addr = uaddr, + .gpa = gpa, + .size = rsize, + }; + + ret = ioctl(kvm->vm_fd, KVM_RISCV_COVE_MEASURE_REGION, &mr); + if (ret < 0) { + ret = -errno; + die("Setting measure region failed for CoVE VM\n"); + } +} + u64 kvm__arch_default_ram_address(void) { return RISCV_RAM; From patchwork Wed Apr 19 22:23:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13217587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FB3FC77B73 for ; Wed, 19 Apr 2023 22:33:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232677AbjDSWdh (ORCPT ); Wed, 19 Apr 2023 18:33:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232249AbjDSWdf (ORCPT ); Wed, 19 Apr 2023 18:33:35 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE24E7D93 for ; Wed, 19 Apr 2023 15:33:02 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id d75a77b69052e-3ef2452967fso409361cf.3 for ; Wed, 19 Apr 2023 15:33:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943501; x=1684535501; 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=DqxJzuQg4YHoKMLWmjQ5z9IqDd25T8M3gtHVASWlMsA=; b=1Q7hIA4aDMOrm+VJSSQt57+O1Yad3Su4z21MMQXubivfmUvT4TzZS+54yTctr3F4hs DA9MZGIEjjAZ08cwi+8U2hjt4/VzRBBslzVS9HvO64xrxWykMszd9sXEogl5xu1rKg3l 9PcM2bH3HKaZud0dLZZG48E+T0zM+Kh8989lnsTxZf/PaaiwB3/9kuDjHL2tMyekndJm ajvbHE4ZLHC78IsLi6KkG0MCIwYHqOUN0p/oks8/JC6LmVTyUsXeLSca2VO9vr92B6Ue sbO05MVjt/+MJSAyUwTIM0JMurWm566lkE4xMnL4ODDgVV1ctgjOAAZQifFPAla1LUcr bnzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943501; x=1684535501; 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=DqxJzuQg4YHoKMLWmjQ5z9IqDd25T8M3gtHVASWlMsA=; b=F+1PbTbnFrXnd8JonhvAUYl0HgYZLgjAJIUVWExAL9AsqdQQl3yJlgByuq0v+tMCR8 EH6Ns9TdH4kGAoaakKmx/bXO+uv7lsHI/597PB8ap6ttlkR4RQn4i0DHEZDatBpaqmGk wnJ6Q45deQaa71TA60uyk8shPqYvY9qlFISAEKFhnwsjeDvebrbqeBuQ0uFVaaRFh31X Kww1jX3uURO1Fy4Ge1G7LdUm/5wklfsJVf0xzgv9t+TMVUZ4yLw0BScx09V7BunGIFKl SqxTive5KV+lCuEILamDvl/JXoOd3FJxxdRe3pCltvg5MmDCQAZUXS0n1hll4Z9+/uXo eO2A== X-Gm-Message-State: AAQBX9feoX/Gwo2EV5zf64BKsDwb1gWAiMyvLdncSHbASiMGMLH6wO0l 5lhzq+7DItonMPe3cz/yR6yIrmFHCcglJDtY96c= X-Google-Smtp-Source: AKy350Y1oJzpFyEWrofUoiBPrqInLwUP0IdbCjWNBlR0+a+fpEuwpi5wATQkdQOE2P7s+B2OF642XA== X-Received: by 2002:a17:902:db08:b0:1a6:8405:f709 with SMTP id m8-20020a170902db0800b001a68405f709mr8145477plx.20.1681943049834; Wed, 19 Apr 2023 15:24:09 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id e4-20020a170902744400b001a681fb3e77sm11867810plt.44.2023.04.19.15.24.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:24:09 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Rajnesh Kanwal , Uladzislau Rezki Subject: [RFC kvmtool 04/10] riscv: Invoke measure region for VM images Date: Wed, 19 Apr 2023 15:23:44 -0700 Message-Id: <20230419222350.3604274-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419222350.3604274-1-atishp@rivosinc.com> References: <20230419222350.3604274-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The DT, initrd and kernel images needs to be measured before a CoVE VM can be started to validate its authenticity. Hookup the measure region API for these three components. Signed-off-by: Atish Patra --- riscv/fdt.c | 3 +++ riscv/kvm.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/riscv/fdt.c b/riscv/fdt.c index 61a28bb..07ec336 100644 --- a/riscv/fdt.c +++ b/riscv/fdt.c @@ -254,6 +254,9 @@ static int setup_fdt(struct kvm *kvm) if (kvm->cfg.arch.dump_dtb_filename) dump_fdt(kvm->cfg.arch.dump_dtb_filename, fdt_dest); + + kvm_cove_measure_region(kvm, (unsigned long)fdt_dest, + kvm->arch.dtb_guest_start, FDT_MAX_SIZE); return 0; } late_init(setup_fdt); diff --git a/riscv/kvm.c b/riscv/kvm.c index 99b253e..d59e8bc 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -148,6 +148,8 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, pr_debug("Loaded kernel to 0x%llx (%zd bytes)", kvm->arch.kern_guest_start, file_size); + kvm_cove_measure_region(kvm, (unsigned long)pos, kvm->arch.kern_guest_start, + file_size); /* Place FDT just after kernel at FDT_ALIGN address */ pos = kernel_end + FDT_ALIGN; guest_addr = ALIGN(host_to_guest_flat(kvm, pos), FDT_ALIGN); @@ -188,6 +190,8 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, pr_debug("Loaded initrd to 0x%llx (%llu bytes)", kvm->arch.initrd_guest_start, kvm->arch.initrd_size); + kvm_cove_measure_region(kvm, (unsigned long)pos, initrd_start, + file_size); } else { kvm->arch.initrd_size = 0; } From patchwork Wed Apr 19 22:23:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13217573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C400AC77B73 for ; Wed, 19 Apr 2023 22:27:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232240AbjDSW1n (ORCPT ); Wed, 19 Apr 2023 18:27:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231910AbjDSW1J (ORCPT ); Wed, 19 Apr 2023 18:27:09 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0C23D32D for ; Wed, 19 Apr 2023 15:25:46 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1a80d827179so4535915ad.3 for ; Wed, 19 Apr 2023 15:25:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943052; x=1684535052; 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=E81F/sZHqFlmC4PTTDxmyvFtDAnkdcxCBJVjUmPx/Qw=; b=h8qvhmk4lDaY4kQIaAqeKrnT156suhglOdhOFhlubu1kF8monJSVNUgUE+j1dG31u3 2u4SpVYqZ4tfegebKpsL38KKycJWXvEDDTgK8UNr6JRmWeQLZM10VY51+CKxQiNgddvl jVlFZj35wrKDUORGT0J+qOCCKpjlGHzbKe/sGfoeSgQinTk47q9jptfvuPOOM2rG+CYr zwGu3oFCrdRFjF7E7+wb2JbG1bH3s5tlAZXNHsT/M1j9N2DMFEV+pbXVFPMwgsNs8Fq+ +9F3bZPSaGt+4fI+77DT77iqb04ZT/uOhlexxfDhgZPl/024tDlCe5TFxeig37XFSsp8 WtKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943052; x=1684535052; 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=E81F/sZHqFlmC4PTTDxmyvFtDAnkdcxCBJVjUmPx/Qw=; b=PniBOBJowk0Qu9+oNqrZ6G0qg/u8Bz6Wddrt+SCmMi/xvkWuGBPU/46S/ewohO5i2W 7f77hHkFwt7uuu5OatGk7gtBZ0NTd+ejgw4WtXFGELtqDfnbv6nDu+dhrymCR2RULLD9 QaaZDq4rOtXQd2W0Xwbm5ozF1+c/ExwselimOPMcgf/1sfjOt5KZivYsWra2y7zpZJMg AOdDRB1d4MZOepOrD0ppzu2BUjrmQzX5PoFyWdavWdLDnychSTvJ/sedXxL7P2kAEXRB PV6lR35XbamjsjTeS4ch8oyK/t+GYJobmuVXh+f0jB1kFCb4v/jZ2gbmy2PcDGzP5nak 7NvQ== X-Gm-Message-State: AAQBX9dyiHFDpzqzXFGVQHYDynUAuoArscXiqT9x87Xka/h9nqPsL441 tHx6268TLy1ihkLxZdxWgy83lA== X-Google-Smtp-Source: AKy350ZDizFV7lhpli0WrCYYrT6iDsFp55kYpsDPb3wO0+TsDTvsM5wAJ/jQ030A1Tz0V9swMbp+9w== X-Received: by 2002:a17:902:da8a:b0:1a6:97fd:29e7 with SMTP id j10-20020a170902da8a00b001a697fd29e7mr8449012plx.27.1681943051998; Wed, 19 Apr 2023 15:24:11 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id e4-20020a170902744400b001a681fb3e77sm11867810plt.44.2023.04.19.15.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:24:11 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Rajnesh Kanwal , Uladzislau Rezki Subject: [RFC kvmtool 05/10] riscv: Do not create APLIC for TVMs Date: Wed, 19 Apr 2023 15:23:45 -0700 Message-Id: <20230419222350.3604274-6-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419222350.3604274-1-atishp@rivosinc.com> References: <20230419222350.3604274-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The CoVE VMs do not support wired interrupts. Thus no need of APLIC at this point. Signed-off-by: Atish Patra --- riscv/aia.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/riscv/aia.c b/riscv/aia.c index 8c85b3f..a3b8618 100644 --- a/riscv/aia.c +++ b/riscv/aia.c @@ -143,6 +143,11 @@ static int aia__init(struct kvm *kvm) .attr = KVM_DEV_RISCV_AIA_CTRL_INIT, }; + + /* CoVE VM only supports hardware with physical guest interrupt file */ + if (kvm->cfg.arch.cove_vm) + aia_mode = KVM_DEV_RISCV_AIA_MODE_HWACCEL; + /* Setup global device attribute variables */ aia_mode_attr.addr = (u64)(unsigned long)&aia_mode; aia_nr_ids_attr.addr = (u64)(unsigned long)&aia_nr_ids; @@ -160,10 +165,7 @@ static int aia__init(struct kvm *kvm) ret = ioctl(aia_fd, KVM_GET_DEVICE_ATTR, &aia_nr_ids_attr); if (ret) return ret; - aia_nr_sources = irq__get_nr_allocated_lines(); - ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_nr_sources_attr); - if (ret) - return ret; + aia_hart_bits = fls_long(kvm->nrcpus); ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_hart_bits_attr); if (ret) @@ -172,12 +174,21 @@ static int aia__init(struct kvm *kvm) /* Save number of HARTs for FDT generation */ aia_nr_harts = kvm->nrcpus; - /* Set AIA device addresses */ - aia_addr = AIA_APLIC_ADDR(aia_nr_harts); - aia_addr_attr.attr = KVM_DEV_RISCV_AIA_ADDR_APLIC; - ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_addr_attr); - if (ret) - return ret; + /* CoVE VMs do not support APLIC yet */ + if (!kvm->cfg.arch.cove_vm) { + aia_nr_sources = irq__get_nr_allocated_lines(); + ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_nr_sources_attr); + if (ret) + return ret; + + /* Set AIA device addresses */ + aia_addr = AIA_APLIC_ADDR(aia_nr_harts); + aia_addr_attr.attr = KVM_DEV_RISCV_AIA_ADDR_APLIC; + ret = ioctl(aia_fd, KVM_SET_DEVICE_ATTR, &aia_addr_attr); + if (ret) + return ret; + } + for (i = 0; i < kvm->nrcpus; i++) { aia_addr = AIA_IMSIC_ADDR(i); aia_addr_attr.attr = KVM_DEV_RISCV_AIA_ADDR_IMSIC(i); From patchwork Wed Apr 19 22:23:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13217572 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 559F4C6FD18 for ; Wed, 19 Apr 2023 22:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233350AbjDSW10 (ORCPT ); Wed, 19 Apr 2023 18:27:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233541AbjDSW1B (ORCPT ); Wed, 19 Apr 2023 18:27:01 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7089C158 for ; Wed, 19 Apr 2023 15:25:35 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1a9253d4551so4804085ad.0 for ; Wed, 19 Apr 2023 15:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943053; x=1684535053; 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=2k6fZhtBjuovD0xJN9/3Mss7sJpSj6M+Lhg1puIM9yQ=; b=frHFpOgJMj3IyT+0l6lF4ggQqLWSqJ+R5Lwl83JFjnZ1FgOj+RCeflj5OiteP2veXj hs8UabqlFhDeAfeVOqN8nsOlJjF/2yPcJvsYdreBOn4W0VsT07xnNPxxC9wRqCbEDrEI ZWpU6jo5/ivGxGl/5WlSrPuw4s+yWAlTdUEKKQGRxh6JkIhcKHr1ykdZxEako+r8BVLI Iia+UAGrprs58WkfVvjD7u2w/7WcLDjo2lLLRaRlMw3OivWlNDMPp50fyu9RdhML7Hv4 wHYTWA+nkcv0sFjdO1RQEsLbEgouvwKngVct5OCtGdc8SgVKzfHhIkTKi03d/OSMpN46 dypw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943053; x=1684535053; 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=2k6fZhtBjuovD0xJN9/3Mss7sJpSj6M+Lhg1puIM9yQ=; b=Z0i7tJjWh/NHjBLpHlr9FAAX6ZlFJSdbKzrHVYXNZAkwjMTQUTvQD3XCaJo/ZjUjm+ cfoOIcgSmqfFDPhxpibbxiER8tzXmRTaZ4V+DVE7FfbQgw9uj1iaV/uWcYHzoAkEs5yC ZsYp87XtVu7y4E17HC5vahb5+Bj8nvhfsSxCffK61YK/MzNCEcGMJdKKP7O5Bc92ZSDW QG8mXbUp+I0UTTr49EJgJVmTH83TDebC0TzCpqEbZnKdYRbzX3Gjv3O9dWu8AedxPA3n +KUhkNFwBItltzFSJhCxeHguGyjNRuqYfKD6d/inxRUmlgT5Ydg6fQWieoWqaV6crLjP 3LnA== X-Gm-Message-State: AAQBX9etDHpRHcDH0OnOFSP2BhSjUP3jiIrwnuXnrpSYy8KO0dB5k9Ua S1xXExevngbUdsuCyjJVdPZv1A== X-Google-Smtp-Source: AKy350a+wtlv0SH4nHUTs3X+REynERjZtWfA6CRUt3D8Ejpa/aSb6HljJIxaa3PlyPoDKWKx8hTZ+g== X-Received: by 2002:a17:903:8c6:b0:1a0:42d4:e38a with SMTP id lk6-20020a17090308c600b001a042d4e38amr7048884plb.11.1681943053760; Wed, 19 Apr 2023 15:24:13 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id e4-20020a170902744400b001a681fb3e77sm11867810plt.44.2023.04.19.15.24.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:24:13 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Rajnesh Kanwal , Uladzislau Rezki Subject: [RFC kvmtool 06/10] riscv: Change initrd alignment to a page size Date: Wed, 19 Apr 2023 15:23:46 -0700 Message-Id: <20230419222350.3604274-7-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419222350.3604274-1-atishp@rivosinc.com> References: <20230419222350.3604274-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Currently, the initrd image is aligned to 8. This is problematic for CoVE where the image is expected to be aligned at page granularity level. Thus, align it to 4k. This can be done only if user requested a TVM. However, initrd usually much bigger (in MBs at least). Thus, aligning to a page for everything should not matter much. Signed-off-by: Atish Patra --- riscv/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riscv/kvm.c b/riscv/kvm.c index d59e8bc..5f9b0d5 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -113,7 +113,7 @@ void kvm__arch_init(struct kvm *kvm) } #define FDT_ALIGN SZ_4M -#define INITRD_ALIGN 8 +#define INITRD_ALIGN SZ_4K bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline) { From patchwork Wed Apr 19 22:23:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13217576 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A7CCC77B73 for ; Wed, 19 Apr 2023 22:28:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232456AbjDSW23 (ORCPT ); Wed, 19 Apr 2023 18:28:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233693AbjDSW2C (ORCPT ); Wed, 19 Apr 2023 18:28:02 -0400 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD06B9EE3 for ; Wed, 19 Apr 2023 15:26:27 -0700 (PDT) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-63b8b19901fso453977b3a.3 for ; Wed, 19 Apr 2023 15:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943055; x=1684535055; 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=ZTLerH+RJ52lhodOQfma/DJulVaHZ1rN37E2HPQ1gqk=; b=a1bnzxGWwIOEAkq+19MIVfBP/ZCFCZqLmC1UeQSHZvEerwM1InrDlC+CNQjLasRYNY TG6B+BEbccXViq3GxUGM1S1bKt08GMbNh8cu2/7uvz8TADG5izCLZidY7kyXryOk8Cc+ amepc4YX9EhmwedHzdpQaI6iQRwH2jqt2DPucE98CEAfI6Pi8SQBLcJ1U0kFZji/jcS3 poVKHT9OeJbpVpJ3SjBehUYSR58tbT8ZMpTvtdSUCQHzPMMVlmcC1HTTyDhFywITeMq2 sEJhC6uIWIrcV3571Eqlwgn/Fm+q+fD6bbuTOkEai1g6rHX8oYaeAhJEcO5b4iPV/t6d oGlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943055; x=1684535055; 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=ZTLerH+RJ52lhodOQfma/DJulVaHZ1rN37E2HPQ1gqk=; b=D6qvoefyDQxeGHq17EUyWNEdRZLmoPH8L/KR1IG3O/oWOQdSG6IpVfMP2T5QLQtcBp ZhjELFrvRaPihk/plfx1KTo6IfOeE8CseS/I3CLD9s1T7tGZorscO7WkP6R3zR0sFGud N3vc7+9EY80c8Dghsuv3HSGYI+c483gFUSUNKplVtLgUtuG2ys7b5PeJcKBkvQYP2NUP R4CjroCdRUogJQKUpJHRTF4IgI3C6VL7Rb7d4XTAGf5ji0z+VZXmkgNlGCkmLKJRItxP iQOqcA4IV/7b7sivxAkwS06FCPUciPVOMBKNm8eMUGiAfRDFZzjdhJGkhS6dRo0Km4/j egkQ== X-Gm-Message-State: AAQBX9ffIBTnhv1z898JIeYyarxB2plndcbdxbpugFIPtLWQkwKS2xQj wH+sIueqY80E80rLPz1Tx4xPmw== X-Google-Smtp-Source: AKy350biCI2sFr3cWCmld5tDykr7Z5GZPcCxF2zAi1qUg8p1jfhx7EqRslonbApZT3U9aoxz+Y7avQ== X-Received: by 2002:a17:902:e5c7:b0:1a8:1436:c892 with SMTP id u7-20020a170902e5c700b001a81436c892mr5044406plf.14.1681943055547; Wed, 19 Apr 2023 15:24:15 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id e4-20020a170902744400b001a681fb3e77sm11867810plt.44.2023.04.19.15.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:24:15 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Rajnesh Kanwal , Uladzislau Rezki Subject: [RFC kvmtool 07/10] riscv: Define riscv specific vm_type function Date: Wed, 19 Apr 2023 15:23:47 -0700 Message-Id: <20230419222350.3604274-8-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419222350.3604274-1-atishp@rivosinc.com> References: <20230419222350.3604274-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org RISC-V supports CoVE VMs now. It needs to setup correct VM type if the user requests it. Signed-off-by: Atish Patra --- riscv/kvm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/riscv/kvm.c b/riscv/kvm.c index 5f9b0d5..e728790 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -39,6 +39,18 @@ u64 kvm__arch_default_ram_address(void) return RISCV_RAM; } +int kvm__get_vm_type(struct kvm *kvm) +{ + if (kvm->cfg.arch.cove_vm) { + if (__riscv_xlen == 64) + return KVM_VM_TYPE_RISCV_COVE; + else + die("CoVE VM is not supported in RV32\n"); + } else { + return KVM_VM_TYPE; + } +} + void kvm__arch_validate_cfg(struct kvm *kvm) { } From patchwork Wed Apr 19 22:23:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13217578 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43FEFC6FD18 for ; Wed, 19 Apr 2023 22:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233767AbjDSW2p (ORCPT ); Wed, 19 Apr 2023 18:28:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233768AbjDSW2Z (ORCPT ); Wed, 19 Apr 2023 18:28:25 -0400 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67265C147 for ; Wed, 19 Apr 2023 15:26:47 -0700 (PDT) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1a6ebc66ca4so4245155ad.3 for ; Wed, 19 Apr 2023 15:26:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943057; x=1684535057; 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=iv3jO/UplLaGK+gTx4v9j9xexh60oYjru3uhX3LfGtA=; b=KlF0beSBSA6VLstvFDlAYMs9lpg8gvRR8zucHEopsyriEw6o1h2sLsqbVwcFiW8cZ2 ykz4DGeTyhjIF7TUhCvkjoQIqDlNYfhLHbuIW6A6Nze2qZg8Mjs4XhacrR2YEsP5YvVC RlKM3D/qrtizTZ3hrz+4hH+4HBcHwt4wDVgzIrtDMMjRIhDdPS70B4ffIp/QcNwVpgLh l3tvN+FDLmm6WxBLSXFEB5UUmHWn5q2p7Y1BPq6qQBjKBoxl/p2sw2H5TvKzZwP4jWXj /BG7zkngU3fOCCHkdBXlJJfXlhrBn1uWDICB+9I2KRJvOa60PVK4lOGzawO9HJcdv8/2 2Ciw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943057; x=1684535057; 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=iv3jO/UplLaGK+gTx4v9j9xexh60oYjru3uhX3LfGtA=; b=WDNh+bYmXWg/DUytYskQqjbTGYkuq7XfJKCUTydogyB+akfZQOAZlGi6dSbAXkhijE ng9FFoe2Lg/LVIENnhqMzzWXetUbj274dU2nn6Cviu/4YBWz+C8Y/SO520Fi6ubHxuhG Jx5yvUmXa03s+U3glGUYY0Sl+NNqL1DFQxrO4qICenVnCDhU51h7XRPlPSIaj2wUcH2s sUqelvhHWYYQnIeExYCwMcYorOrTK9uziFhh12zokOYAdqb5e3hfaVwOqgcLCGchNEpV GRp/2YWS9Y3QaIu4x1+omEPS4YXDhKQO9KL9AIgXIa73dGulpL6fomRqm4WgCoxt+UGs O2Bw== X-Gm-Message-State: AAQBX9cYEqI0PGFyNyUzFsIp30w0ZIG0DdS2DUWloFzhj4cs6BLoYVEp mv0oZPrZGdxsNMwHGUdex8fVgw== X-Google-Smtp-Source: AKy350YmjLuFNHpdbGKVUxtLnNGDTOqZujizSNNxdVNVjL7P36ZiZ6Z6Phv1PaiPaoxLg0i7OBeTQw== X-Received: by 2002:a17:902:d505:b0:19d:778:ff5 with SMTP id b5-20020a170902d50500b0019d07780ff5mr7467330plg.15.1681943057246; Wed, 19 Apr 2023 15:24:17 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id e4-20020a170902744400b001a681fb3e77sm11867810plt.44.2023.04.19.15.24.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:24:17 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Rajnesh Kanwal , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Uladzislau Rezki Subject: [RFC kvmtool 08/10] riscv: virtio: Enforce VIRTIO_F_ACCESS_PLATFORM feature flag. Date: Wed, 19 Apr 2023 15:23:48 -0700 Message-Id: <20230419222350.3604274-9-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419222350.3604274-1-atishp@rivosinc.com> References: <20230419222350.3604274-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Rajnesh Kanwal VIRTIO_F_ACCESS_PLATFORM feature tells the guest that device will be using DMA for transfers. This forces the guest to use DMA API to allow the host to successfully access guest memory as needed. This is needed for CoVE VMs. Signed-off-by: Rajnesh Kanwal --- riscv/kvm.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/riscv/kvm.c b/riscv/kvm.c index e728790..aebb6bd 100644 --- a/riscv/kvm.c +++ b/riscv/kvm.c @@ -7,6 +7,7 @@ #include #include #include +#include struct kvm_ext kvm_req_ext[] = { { DEFINE_KVM_EXT(KVM_CAP_ONE_REG) }, @@ -224,5 +225,14 @@ int kvm__arch_setup_firmware(struct kvm *kvm) u64 kvm__arch_get_virtio_host_features(struct kvm *kvm) { - return 0; + u64 features = 0; + + /* CoVE VMs mandate VIRTIO_F_ACCESS_PLATFORM feature to force use of + * SWIOTLB bounce buffers through DMA API. Without this device probe + * will fail for CoVE VMs. + */ + if (kvm->cfg.arch.cove_vm) + features |= (1ULL << VIRTIO_F_ACCESS_PLATFORM); + + return features; } From patchwork Wed Apr 19 22:23:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13217574 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0931C6FD18 for ; Wed, 19 Apr 2023 22:27:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232644AbjDSW1q (ORCPT ); Wed, 19 Apr 2023 18:27:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233603AbjDSW1P (ORCPT ); Wed, 19 Apr 2023 18:27:15 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 571071025C for ; Wed, 19 Apr 2023 15:25:51 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-51f1b6e8179so197790a12.3 for ; Wed, 19 Apr 2023 15:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943059; x=1684535059; 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=92JmYNvjI4h3x1v84zDdO04a6NNcBv03E/psDBTJE8A=; b=nUPF7sXfdzfSW6QquvIfaq4GAfSYyZeAk0mT1xklq8pqmC8JoWNIvCjy+zgsODVUHq O1IjPJuK8sxnkfCXOFdrW+u9RpzMDpy7y7UdhAG0oCuYW3dH8GSGsOh9ODDRIxw2eaFz bkM34qwDSq7IzfX047RwYqZPP8OQknDg9R1karBknWrofSn/KUs6wUf/rHdpra1bOATf rzsEvtKv0XMZjsFArXphtLo3X7lGUkjGEGkW6yljl786vgCvygViLOvHooAc3u8hDTWy WbwJ4EH+yr+KTGNMLcFTkEfYKE8eHBN2A40w7EVpD08O7tCunWfP2Fwi90JATCfWffYG bUcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943059; x=1684535059; 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=92JmYNvjI4h3x1v84zDdO04a6NNcBv03E/psDBTJE8A=; b=II29LZx9+EU4tDkvf4QQ6goqhbKddBL5BQKjVXpcd+uIw5EwJci/kR5XDtyj5hAdeS LUSO7PRF6KUau8dT0QibTrkSpYyWy27/i0S1y1qJHMfSj1ge/hjObDP+chYl/6MQo+bS G0CijUZclvOU6W4wT7u3erjs9rD23kxbQ8l1gOpsIo9S4zW02t8F/fDFIBbpG1+xjeTn Ny5Es18swOqwUF7DItTS4T92+1gJDZdHjwWWujoW8QLvWyoLYyvNkyM43+ULdWuvLVFw 2EztrV3fWp4KTbkj9FBrhVuPCJmp+KNtKl2BtbdcSm2Y7WFrjDgbDc2PJ3L4clFKasW3 u9sw== X-Gm-Message-State: AAQBX9cFTyhaKOeSXmMED/ZWBzMNFtnDIj9ExVe9XDgWqOPa7cDo29Fz FPwSQlHp+SH1KvavEnEzZ3KloA== X-Google-Smtp-Source: AKy350Z85naSstLXZzvY5D57utZL9LkLhfRNOpeuO+9VtZ6rJWlxmJ/TTxgn/rQUXeeW25YB/WTEcw== X-Received: by 2002:a17:90a:cf81:b0:247:1f35:3314 with SMTP id i1-20020a17090acf8100b002471f353314mr3406729pju.48.1681943059019; Wed, 19 Apr 2023 15:24:19 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id e4-20020a170902744400b001a681fb3e77sm11867810plt.44.2023.04.19.15.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:24:18 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Rajnesh Kanwal , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Uladzislau Rezki Subject: [RFC kvmtool 09/10] riscv: Don't emit MMIO devices for CoVE VM. Date: Wed, 19 Apr 2023 15:23:49 -0700 Message-Id: <20230419222350.3604274-10-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419222350.3604274-1-atishp@rivosinc.com> References: <20230419222350.3604274-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Rajnesh Kanwal The CoVE VMs do not support MMIO devices yet. Do not emit MMIO device nodes for CoVE VMs. Signed-off-by: Rajnesh Kanwal --- riscv/fdt.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/riscv/fdt.c b/riscv/fdt.c index 07ec336..a7d32b3 100644 --- a/riscv/fdt.c +++ b/riscv/fdt.c @@ -210,22 +210,25 @@ static int setup_fdt(struct kvm *kvm) riscv_irqchip_phandle)); _FDT(fdt_property(fdt, "ranges", NULL, 0)); - /* Virtio MMIO devices */ - dev_hdr = device__first_dev(DEVICE_BUS_MMIO); - while (dev_hdr) { - generate_mmio_fdt_nodes = dev_hdr->data; - generate_mmio_fdt_nodes(fdt, dev_hdr, - riscv__generate_irq_prop); - dev_hdr = device__next_dev(dev_hdr); - } + /* CoVE VMs do not support MMIO devices yet */ + if (!kvm->cfg.arch.cove_vm) { + /* Virtio MMIO devices */ + dev_hdr = device__first_dev(DEVICE_BUS_MMIO); + while (dev_hdr) { + generate_mmio_fdt_nodes = dev_hdr->data; + generate_mmio_fdt_nodes(fdt, dev_hdr, + riscv__generate_irq_prop); + dev_hdr = device__next_dev(dev_hdr); + } - /* IOPORT devices */ - dev_hdr = device__first_dev(DEVICE_BUS_IOPORT); - while (dev_hdr) { - generate_mmio_fdt_nodes = dev_hdr->data; - generate_mmio_fdt_nodes(fdt, dev_hdr, - riscv__generate_irq_prop); - dev_hdr = device__next_dev(dev_hdr); + /* IOPORT devices */ + dev_hdr = device__first_dev(DEVICE_BUS_IOPORT); + while (dev_hdr) { + generate_mmio_fdt_nodes = dev_hdr->data; + generate_mmio_fdt_nodes(fdt, dev_hdr, + riscv__generate_irq_prop); + dev_hdr = device__next_dev(dev_hdr); + } } /* PCI host controller */ From patchwork Wed Apr 19 22:23:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13217571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82710C77B75 for ; Wed, 19 Apr 2023 22:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233734AbjDSW1Y (ORCPT ); Wed, 19 Apr 2023 18:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233272AbjDSW1B (ORCPT ); Wed, 19 Apr 2023 18:27:01 -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 22FC7C141 for ; Wed, 19 Apr 2023 15:25:35 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-63b70f0b320so492666b3a.1 for ; Wed, 19 Apr 2023 15:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943061; x=1684535061; 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=joeGaZNojBtAEH48oFyXyXsTdXyxZ+syATM0NtCwkJg=; b=Hy5Vjaj1GFlfqXFgFU4Wk7wYhL+AdW+GISShF7pbpQzBCAzoyX06mKj9riDONUvoTu KJygh5nscsoyPvItPChqrHSXQPxDp5bYRAnKsEvFqcmijRhCw38xeSwetTsF9AvkbUYf hVmE7FSAH4Q4wrzRD6pw23VK9AaSnKgovUSlZ9QXs++6xGQZcPVEtNzbYKNpDmb7ydxL pihm7AbjTblUz+nkMI32xYxKW27gseqDrV0RGKN4T43bczPSmCXLp3fRh/utmO9YHtoB Sey/VFplr9PE2lySTaLRpT3t0lbZnm/yfBcOsJhGI8vtN1zAVWuoZu9OzywwnPC3RL4n V1wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943061; x=1684535061; 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=joeGaZNojBtAEH48oFyXyXsTdXyxZ+syATM0NtCwkJg=; b=hLm9O8wfrozOKZBSrKoBvLYhq9tkCObdF8qX+TjtMTHrEtcmSP2bdDICN9/OLBmVf3 KCOeE0efq5KwsVn9UyIVycAl6R1UDKJsYL81Ml3aH6ecQsx4nyWZZswpE4tJyurkpp8W Qoh5X9/JnOl21wdu0GUkDQEyyqmLcUHDehTx/8dEHzgvyVnbzglLAQvkduMo5/3+9yGG TPIlmVFumJFTGwpfsu2Vl/IG7KunWXrysKXgXKSXlUyo+0ZOmZqPfQkgTV+UkuDG8G0O c3FUxSCgsevQxj5TKLYJL616rDoLDU17uZqKTHXgo3w1XB5uaKys1p7GB2GyxkhOwcji 5qFg== X-Gm-Message-State: AAQBX9cwKSht8pNIQI/XkYKOZ8mAzJthIY+4Gy2dce8BCxC587Tjeguu M3fSZvQK3GPSl+B/nrj9soZbdEAHcpoBZfrYJhk= X-Google-Smtp-Source: AKy350bpDV/yb/MMXonhLvjhCzwnd1ozKuOFojavKdcbbpka5zKY4L/5Rw/zrIiOtje9GuJuXPaRMw== X-Received: by 2002:a17:902:7891:b0:1a1:bf22:2b6e with SMTP id q17-20020a170902789100b001a1bf222b6emr6634040pll.43.1681943060762; Wed, 19 Apr 2023 15:24:20 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id e4-20020a170902744400b001a681fb3e77sm11867810plt.44.2023.04.19.15.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:24:20 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Rajnesh Kanwal , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paolo Bonzini , Uladzislau Rezki Subject: [RFC kvmtool 10/10] riscv: cove: Don't emit interrupt_map for pci devices in fdt. Date: Wed, 19 Apr 2023 15:23:50 -0700 Message-Id: <20230419222350.3604274-11-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419222350.3604274-1-atishp@rivosinc.com> References: <20230419222350.3604274-1-atishp@rivosinc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Rajnesh Kanwal CoVE VMs don't support pin based interrupts yet as APLIC isn't supported. Signed-off-by: Rajnesh Kanwal --- riscv/fdt.c | 2 +- riscv/include/kvm/kvm-arch.h | 2 +- riscv/pci.c | 83 +++++++++++++++++++----------------- 3 files changed, 46 insertions(+), 41 deletions(-) diff --git a/riscv/fdt.c b/riscv/fdt.c index a7d32b3..115ae17 100644 --- a/riscv/fdt.c +++ b/riscv/fdt.c @@ -232,7 +232,7 @@ static int setup_fdt(struct kvm *kvm) } /* PCI host controller */ - pci__generate_fdt_nodes(fdt); + pci__generate_fdt_nodes(fdt, kvm); _FDT(fdt_end_node(fdt)); diff --git a/riscv/include/kvm/kvm-arch.h b/riscv/include/kvm/kvm-arch.h index 08ac54a..9f6967f 100644 --- a/riscv/include/kvm/kvm-arch.h +++ b/riscv/include/kvm/kvm-arch.h @@ -104,7 +104,7 @@ void aia__create(struct kvm *kvm); void plic__create(struct kvm *kvm); -void pci__generate_fdt_nodes(void *fdt); +void pci__generate_fdt_nodes(void *fdt, struct kvm *kvm); int riscv__add_irqfd(struct kvm *kvm, unsigned int gsi, int trigger_fd, int resample_fd); diff --git a/riscv/pci.c b/riscv/pci.c index 9760ca3..31ea286 100644 --- a/riscv/pci.c +++ b/riscv/pci.c @@ -17,7 +17,7 @@ struct of_interrupt_map_entry { u32 irqchip_sense; } __attribute__((packed)); -void pci__generate_fdt_nodes(void *fdt) +void pci__generate_fdt_nodes(void *fdt, struct kvm *kvm) { struct device_header *dev_hdr; struct of_interrupt_map_entry irq_map[OF_PCI_IRQ_MAP_MAX]; @@ -67,51 +67,56 @@ void pci__generate_fdt_nodes(void *fdt) _FDT(fdt_property(fdt, "reg", &cfg_reg_prop, sizeof(cfg_reg_prop))); _FDT(fdt_property(fdt, "ranges", ranges, sizeof(ranges))); - /* Generate the interrupt map ... */ - dev_hdr = device__first_dev(DEVICE_BUS_PCI); - while (dev_hdr && nentries < ARRAY_SIZE(irq_map)) { - struct of_interrupt_map_entry *entry; - struct pci_device_header *pci_hdr = dev_hdr->data; - u8 dev_num = dev_hdr->dev_num; - u8 pin = pci_hdr->irq_pin; - u8 irq = pci_hdr->irq_line; + /* CoVE VMs do not support pin based interrupts yet as APLIC isn't + * supported. + */ + if (!kvm->cfg.arch.cove_vm) { + /* Generate the interrupt map ... */ + dev_hdr = device__first_dev(DEVICE_BUS_PCI); + while (dev_hdr && nentries < ARRAY_SIZE(irq_map)) { + struct of_interrupt_map_entry *entry; + struct pci_device_header *pci_hdr = dev_hdr->data; + u8 dev_num = dev_hdr->dev_num; + u8 pin = pci_hdr->irq_pin; + u8 irq = pci_hdr->irq_line; - entry = ((void *)irq_map) + (nsize * nentries); - *entry = (struct of_interrupt_map_entry) { - .pci_irq_mask = { - .pci_addr = { - .hi = cpu_to_fdt32(of_pci_b_ddddd(dev_num)), - .mid = 0, - .lo = 0, + entry = ((void *)irq_map) + (nsize * nentries); + *entry = (struct of_interrupt_map_entry) { + .pci_irq_mask = { + .pci_addr = { + .hi = cpu_to_fdt32(of_pci_b_ddddd(dev_num)), + .mid = 0, + .lo = 0, + }, + .pci_pin = cpu_to_fdt32(pin), }, - .pci_pin = cpu_to_fdt32(pin), - }, - .irqchip_phandle = cpu_to_fdt32(riscv_irqchip_phandle), - .irqchip_line = cpu_to_fdt32(irq), - }; + .irqchip_phandle = cpu_to_fdt32(riscv_irqchip_phandle), + .irqchip_line = cpu_to_fdt32(irq), + }; - if (riscv_irqchip_line_sensing) - entry->irqchip_sense = cpu_to_fdt32(IRQ_TYPE_LEVEL_HIGH); + if (riscv_irqchip_line_sensing) + entry->irqchip_sense = cpu_to_fdt32(IRQ_TYPE_LEVEL_HIGH); - nentries++; - dev_hdr = device__next_dev(dev_hdr); - } + nentries++; + dev_hdr = device__next_dev(dev_hdr); + } - _FDT(fdt_property(fdt, "interrupt-map", irq_map, nsize * nentries)); + _FDT(fdt_property(fdt, "interrupt-map", irq_map, nsize * nentries)); - /* ... and the corresponding mask. */ - if (nentries) { - struct of_pci_irq_mask irq_mask = { - .pci_addr = { - .hi = cpu_to_fdt32(of_pci_b_ddddd(-1)), - .mid = 0, - .lo = 0, - }, - .pci_pin = cpu_to_fdt32(7), - }; + /* ... and the corresponding mask. */ + if (nentries) { + struct of_pci_irq_mask irq_mask = { + .pci_addr = { + .hi = cpu_to_fdt32(of_pci_b_ddddd(-1)), + .mid = 0, + .lo = 0, + }, + .pci_pin = cpu_to_fdt32(7), + }; - _FDT(fdt_property(fdt, "interrupt-map-mask", &irq_mask, - sizeof(irq_mask))); + _FDT(fdt_property(fdt, "interrupt-map-mask", &irq_mask, + sizeof(irq_mask))); + } } /* Set MSI parent if available */