Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp917362rwr; Wed, 19 Apr 2023 15:25:49 -0700 (PDT) X-Google-Smtp-Source: AKy350ahKc9ovgH83NINCcF1OjTt69xpZe4gllWAbOy7boB2PafrB4tQjBGfgu2y6z0RIL4YgVMz X-Received: by 2002:a05:6a20:3c90:b0:d6:7b9b:f89 with SMTP id b16-20020a056a203c9000b000d67b9b0f89mr213810pzj.4.1681943149544; Wed, 19 Apr 2023 15:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681943149; cv=none; d=google.com; s=arc-20160816; b=JPmFAytF8e6lx8cKiQ694yPsWPJGU9CikOqXw83RGk5ygCoiLTGPwTsk9lEqVREaq1 2TANZNF8/L8YQJzMdwUBYdZMM+C8IXtC14pF3ru9jgARKabR2i6iVlDvtQZTRH/ccWk4 OIBfnmHTPJgfI0A43AKyF7/zeVYy6MC1jWF7sPx/SptuTUxX7PM+wRRyQK533kBYFDek bZaAO5rbopulJRBmMtmiIZp4642bvtJZ1X1leEOqQ9Fc7TT7Wisdq3IeExzO+YU/B4z4 c6ZYf0Rniig9kENhiU6+uoZyWHu7bNUVCw16XKjfNsAGrmxt+pDcTvicomQF3cuF5sVo wAPQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LnnJUnDn5Gg0VxA4G2224aJuFesVpwMyXWuJ35Yh1EA=; b=uwrQiHC7S/cboN4JNnGOu4nik+NxEvvoZDiKKBwSnUjSSXICLsTjt7M5SDFg8wvIK2 H2KP14//h/ZOG8RacMZvaE7D+QrOs0557fLv32kQpN7rvEj8dLimeFUyNzufcj2i8YiQ bjmc93sufd1scTmwRGuJc552N6e/xx9rNy2PMqK3BaOmDrd698Og9MzV6D3NpHZuWh6o MJ57Vb8pZ3tTAv5UzijMBvJhPjjYP8vRX8Gu/M2hyIyHdd6o6D7R+/jjsNumfJ0ctnti F1r5xOhQhkJFFn88xq/aMMWm08ZqNrauzDIlPeM+ASYPsNjCYibiINLrf3zBLCmr9ZDh qt1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=qN2qG27G; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a654145000000b00503059b8b2fsi3431534pgp.220.2023.04.19.15.25.34; Wed, 19 Apr 2023 15:25:49 -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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=qN2qG27G; 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 S233665AbjDSWWj (ORCPT + 99 others); Wed, 19 Apr 2023 18:22:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233086AbjDSWWD (ORCPT ); Wed, 19 Apr 2023 18:22:03 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BED62526F for ; Wed, 19 Apr 2023 15:20:28 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2496863c2c7so216520a91.1 for ; Wed, 19 Apr 2023 15:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681942738; x=1684534738; 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=LnnJUnDn5Gg0VxA4G2224aJuFesVpwMyXWuJ35Yh1EA=; b=qN2qG27GHv+d9gUwWztkTi8p+g3aaC2rFXOZGwLc8eAMBqzRu7eT8kWoOJLWLTW0Eo Z5lYOlCFWymONdQ75UX7d1w0T/hT7irv6Jb4eLBvu7abb5vVm52aXVMSJ1GMw0Dbzqsr +1z7/IHpZr9TOWWv65z2G7cezkDsdmOF3T3T+GedPiWIaC/Kuy6PLSFoobdSxJzll2MD g1noklYQNjPoDJtmIYCLWo0ww78Wd6QJJJ0qNcx7/a9E59ARcqxtApq0JG/1pIkk/aOb ezm4wy13mbTPlO+a9FFwfpQuhkNR1dmeg9ddTlU2Pq0Tpw9j5c0vXUUJGHEIdY9VbyGW 1hlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681942738; x=1684534738; 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=LnnJUnDn5Gg0VxA4G2224aJuFesVpwMyXWuJ35Yh1EA=; b=Yif53SI9EPikdd5txQBf+tulAcclLEC570Y0moqZeA2PNSEej6jYxihTg4hfEbDbsW QKhkbfzfpF85uO/X0ybIuo4CczrIBDiFo/QezZo3ju06sDsPSTdZo1VAjYdgp15cgZUq dhL2PzBopLK+YcwTsVYUIWFProq0qh3yFtjypnInJknrPIT9v/uuqMbPDxSuaVebHBTZ qYIGKOcPszx04XBQG9MnLKGWh7bWShz1ZCDhvKSbguGVaHQsKrJE+NuqW1xE5XWPcRFQ sG7/8jtGjOhowh96iddWaza2Qt5a+5Wu9tWNsva/A/2aj2R8Y89GHivHqlUfGcmQAHoU XNzQ== X-Gm-Message-State: AAQBX9c74oaqHDqRTk7XJ8D6uObCqajRJAXVADcKj0RUZXDSaZDv8uLD hKoGGQork+MekHNiBH4LTpOan0WzffV4ZeIfFxM= X-Received: by 2002:a17:90b:38c6:b0:237:c209:5b14 with SMTP id nn6-20020a17090b38c600b00237c2095b14mr3820467pjb.22.1681942738315; Wed, 19 Apr 2023 15:18:58 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id jn11-20020a170903050b00b00196807b5189sm11619190plb.292.2023.04.19.15.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:18:58 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Rajnesh Kanwal , Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Christoph Hellwig , Conor Dooley , Greg Kroah-Hartman , Guo Ren , Heiko Stuebner , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Mayuresh Chitale , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Uladzislau Rezki Subject: [RFC 40/48] RISC-V: COVE: Add COVH invalidate, validate, promote, demote and remove APIs. Date: Wed, 19 Apr 2023 15:17:08 -0700 Message-Id: <20230419221716.3603068-41-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419221716.3603068-1-atishp@rivosinc.com> References: <20230419221716.3603068-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Rajnesh Kanwal SBI_EXT_COVH_TVM_INVALIDATE_PAGES: Invalidates the pages in the specified range of guest physical address space. The host can now work upon the range without TVM's interaction. Any access from TVM to the range will result in a page-fault which will be reported to the host. SBI_EXT_COVH_TVM_VALIDATE_PAGES: Marks the invalidated pages in the specified range of guest physical address space as present and TVM can now access the pages. SBI_EXT_COVH_TVM_PROMOTE_PAGES: Promotes a set of contiguous mappings to the requested page size. This is mainly to support huge-pages. SBI_EXT_COVH_TVM_DEMOTE_PAGES: Demotes a huge page mapping to a set of contiguous mappings at the target size. SBI_EXT_COVH_TVM_REMOVE_PAGES: Removes mappings from a TVM. The range to be unmapped must already have been invalidated and fenced, and must lie within a removable region of guest physical address space. Signed-off-by: Atish Patra Signed-off-by: Rajnesh Kanwal --- arch/riscv/include/asm/kvm_cove_sbi.h | 16 +++++++ arch/riscv/include/asm/sbi.h | 5 +++ arch/riscv/kvm/cove_sbi.c | 65 +++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/arch/riscv/include/asm/kvm_cove_sbi.h b/arch/riscv/include/asm/kvm_cove_sbi.h index 0759f70..b554a8d 100644 --- a/arch/riscv/include/asm/kvm_cove_sbi.h +++ b/arch/riscv/include/asm/kvm_cove_sbi.h @@ -59,6 +59,22 @@ int sbi_covh_create_tvm_vcpu(unsigned long tvmid, unsigned long tvm_vcpuid, int sbi_covh_run_tvm_vcpu(unsigned long tvmid, unsigned long tvm_vcpuid); +int sbi_covh_tvm_invalidate_pages(unsigned long tvmid, + unsigned long tvm_base_page_addr, + unsigned long len); +int sbi_covh_tvm_validate_pages(unsigned long tvmid, + unsigned long tvm_base_page_addr, + unsigned long len); +int sbi_covh_tvm_promote_page(unsigned long tvmid, + unsigned long tvm_base_page_addr, + enum sbi_cove_page_type ptype); +int sbi_covh_tvm_demote_page(unsigned long tvmid, + unsigned long tvm_base_page_addr, + enum sbi_cove_page_type ptype); +int sbi_covh_tvm_remove_pages(unsigned long tvmid, + unsigned long tvm_base_page_addr, + unsigned long len); + /* Functions related to CoVE Interrupt Management(COVI) Extension */ int sbi_covi_tvm_aia_init(unsigned long tvm_gid, struct sbi_cove_tvm_aia_params *tvm_aia_params); int sbi_covi_set_vcpu_imsic_addr(unsigned long tvm_gid, unsigned long vcpu_id, diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index e02ee75..03b0cc8 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -369,6 +369,11 @@ enum sbi_ext_covh_fid { SBI_EXT_COVH_TVM_CREATE_VCPU, SBI_EXT_COVH_TVM_VCPU_RUN, SBI_EXT_COVH_TVM_INITIATE_FENCE, + SBI_EXT_COVH_TVM_INVALIDATE_PAGES, + SBI_EXT_COVH_TVM_VALIDATE_PAGES, + SBI_EXT_COVH_TVM_PROMOTE_PAGE, + SBI_EXT_COVH_TVM_DEMOTE_PAGE, + SBI_EXT_COVH_TVM_REMOVE_PAGES, }; enum sbi_ext_covi_fid { diff --git a/arch/riscv/kvm/cove_sbi.c b/arch/riscv/kvm/cove_sbi.c index a8901ac..01dc260 100644 --- a/arch/riscv/kvm/cove_sbi.c +++ b/arch/riscv/kvm/cove_sbi.c @@ -405,3 +405,68 @@ int sbi_covh_run_tvm_vcpu(unsigned long tvmid, unsigned long vcpuid) return 0; } + +int sbi_covh_tvm_invalidate_pages(unsigned long tvmid, + unsigned long tvm_base_page_addr, + unsigned long len) +{ + struct sbiret ret = sbi_ecall(SBI_EXT_COVH, + SBI_EXT_COVH_TVM_INVALIDATE_PAGES, tvmid, + tvm_base_page_addr, len, 0, 0, 0); + if (ret.error) + return sbi_err_map_linux_errno(ret.error); + + return 0; +} + +int sbi_covh_tvm_validate_pages(unsigned long tvmid, + unsigned long tvm_base_page_addr, + unsigned long len) +{ + struct sbiret ret = sbi_ecall(SBI_EXT_COVH, + SBI_EXT_COVH_TVM_VALIDATE_PAGES, tvmid, + tvm_base_page_addr, len, 0, 0, 0); + if (ret.error) + return sbi_err_map_linux_errno(ret.error); + + return 0; +} + +int sbi_covh_tvm_promote_page(unsigned long tvmid, + unsigned long tvm_base_page_addr, + enum sbi_cove_page_type ptype) +{ + struct sbiret ret = sbi_ecall(SBI_EXT_COVH, + SBI_EXT_COVH_TVM_PROMOTE_PAGE, tvmid, + tvm_base_page_addr, ptype, 0, 0, 0); + if (ret.error) + return sbi_err_map_linux_errno(ret.error); + + return 0; +} + +int sbi_covh_tvm_demote_page(unsigned long tvmid, + unsigned long tvm_base_page_addr, + enum sbi_cove_page_type ptype) +{ + struct sbiret ret = sbi_ecall(SBI_EXT_COVH, + SBI_EXT_COVH_TVM_DEMOTE_PAGE, tvmid, + tvm_base_page_addr, ptype, 0, 0, 0); + if (ret.error) + return sbi_err_map_linux_errno(ret.error); + + return 0; +} + +int sbi_covh_tvm_remove_pages(unsigned long tvmid, + unsigned long tvm_base_page_addr, + unsigned long len) +{ + struct sbiret ret = sbi_ecall(SBI_EXT_COVH, + SBI_EXT_COVH_TVM_REMOVE_PAGES, tvmid, + tvm_base_page_addr, len, 0, 0, 0); + if (ret.error) + return sbi_err_map_linux_errno(ret.error); + + return 0; +} -- 2.25.1