From patchwork Wed Apr 19 22:17:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 85632 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp713624vqo; Wed, 19 Apr 2023 15:53:36 -0700 (PDT) X-Google-Smtp-Source: AKy350YEVZiSHLpdNhvbmX2v0cOwBz23a2Vffy9+XL59DVhfpikti5vx1a4x02LYZgFLgaiIdsjA X-Received: by 2002:a05:6a21:6d86:b0:f0:2c96:1c6c with SMTP id wl6-20020a056a216d8600b000f02c961c6cmr114855pzb.25.1681944816063; Wed, 19 Apr 2023 15:53:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681944816; cv=none; d=google.com; s=arc-20160816; b=YPXAcGo1ZOK4zPPf32+nLB6o9ypuk7WPKishfa6QqEeAaC7B1bLvqKMC+R5RjSB9ul qly+qurl1tFWtp5P49OsvT62uTHVTqHbEYbBGpM/k3VHQfknQZkcpl/piyyo2PopPg9K SixfEBnEXOPP5RJPjJ/CnZxzBHwEAmQoOUG8S03mNpEMx+G2h/bI5gW4WQQ7uwhMxaMW hbkrKfsVQcl7cO454ck6gXZw6vOb4JBv4trpT1cr6jXatd62TEABzAfq66UlaRPExX4S 0E5CJhoN+g7NX7ZAhrI+aUaROT6X0jaweZz9Fi9M6iUAf3yvBGpZ2dzN5a3kYFyHBDbO FLag== 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=ecSGlantlLzvA0G9VPQY9TXgG8EZEn7xksLEzRIVmIY=; b=mvkeqCca42N1OtR4MUbUWnmswMkWoHk4tqv0j4zQcBbbHXIPlU2y7gPgM5APbWJZI5 C016aVq1d2hQdKU1tk3MQPkVtCZsupnZ70DlSMaGw9wN5mZrYDYJ4RRjbJcGiT5l4IJd JXZsC6hsA8iifLcFvGAUQ+K4UsWmvI1BoJh8eHpc4aLXJNs59GV6wMxgCD7m0oG46lg0 YFCoYperhUraucK4si5iby7YsJkJpvLJdvK5RKYSCFE4dxAWchgIN2Jm6pmeaUSK5iIl zRYEGkMeMuLW4/CFN38ULfWS+NAHbShtsO3HUZtkKkAKgDerfUl3g7tp2wFdf3KwyFC7 fOfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=nVCe2AAf; 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 22-20020a630216000000b0051423ad5cdfsi17452056pgc.621.2023.04.19.15.53.23; Wed, 19 Apr 2023 15:53:36 -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=nVCe2AAf; 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 S232363AbjDSWd7 (ORCPT + 99 others); Wed, 19 Apr 2023 18:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233127AbjDSWdy (ORCPT ); Wed, 19 Apr 2023 18:33:54 -0400 Received: from mail-ua1-x92c.google.com (mail-ua1-x92c.google.com [IPv6:2607:f8b0:4864:20::92c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FF4F6A42 for ; Wed, 19 Apr 2023 15:33:28 -0700 (PDT) Received: by mail-ua1-x92c.google.com with SMTP id a1e0cc1a2514c-77858d8dcb5so169222241.1 for ; Wed, 19 Apr 2023 15:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943532; x=1684535532; 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=ecSGlantlLzvA0G9VPQY9TXgG8EZEn7xksLEzRIVmIY=; b=nVCe2AAfzZXe6JIhHVsKNh6KA28/pjNf8Z3SAz1dBHAaxZ39iY1Ye6QRA12TkcozeF EDBvrNGkvB8B7Dy7KbVh/GZGxwAafszOX3YUqMjp95og7XPvVSTe46oDhJhagCjU5jaW 1NsLWRK5F/OBW/nu3ywg+pcJs2MM07FLtUjKOKusVQM5CiqYbtFyMOIYDrkYMjr9D3U5 PD7AWIVs4EiYNc3WLM7OwqfjNbCv6LcKM/rNgRSh9VjaxWvmfa2GlemZLcwmonamBnhF 9+jt1Fl/8FqhCxKcAX4PtIm/MWATiKOM81gk+CCgl9h9jp05N1Vrdia9WPK/wBHpXNTK Ypiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943532; x=1684535532; 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=ecSGlantlLzvA0G9VPQY9TXgG8EZEn7xksLEzRIVmIY=; b=ODi/Yxq+QOfv/PsmwHP3sUzJ9YQI4nK/LADS4Fj5jXKVpkqqXyRAat2YfLgrtMqjYF OD8u2m5l5JNmM3z9vZ5khSCkWqYEOicowcrfs47wqOAhtKsldeCT04t5In0RZQ3LEQmI kKhMez8M9Zu9qQrYHQO/teQZKMK4dESgnqfErBr8QEf37M2iZHLnA4ujhHKh8NOruP1f 5HBHsaOTENx7Z+EpFIkz7K2TX9o1ONZL4mGcYGqdaQmGUjub39p9rL2UYu4RaLRyr/f0 Hq9rIkoGIcEPVPsMdbGIbD6cnBtEbojgA9fvlGvaXPLnuW9NzTqMH5+MTvyUPLsBdmej jSig== X-Gm-Message-State: AAQBX9fBxXtZEOMtYqVE80cYZibtsFk2xVE/duFX2WzJ9ZCikSn1TslL TcQ0gkUMYh59qVHCBCH+YaNOYuXySfuCsQY+b8g= X-Received: by 2002:a17:903:22c7:b0:1a6:3737:750c with SMTP id y7-20020a17090322c700b001a63737750cmr4095049plg.21.1681942751934; Wed, 19 Apr 2023 15:19:11 -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.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:19:11 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Rajnesh Kanwal , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , 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 46/48] riscv/virtio: Have CoVE guests enforce restricted virtio memory access. Date: Wed, 19 Apr 2023 15:17:14 -0700 Message-Id: <20230419221716.3603068-47-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763646967418946203?= X-GMAIL-MSGID: =?utf-8?q?1763646967418946203?= From: Rajnesh Kanwal CoVE guest requires that virtio devices use the DMA API to allow the hypervisor to successfully access guest memory as needed. The VIRTIO_F_VERSION_1 and VIRTIO_F_ACCESS_PLATFORM features tell virtio to use the DMA API. Force to check for these features to fail the device probe if these features have not been set when running as an TEE guest. Signed-off-by: Rajnesh Kanwal --- arch/riscv/mm/mem_encrypt.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/riscv/mm/mem_encrypt.c b/arch/riscv/mm/mem_encrypt.c index 8207a5c..8523c50 100644 --- a/arch/riscv/mm/mem_encrypt.c +++ b/arch/riscv/mm/mem_encrypt.c @@ -10,6 +10,7 @@ #include #include #include +#include #include /* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */ @@ -54,4 +55,7 @@ void __init mem_encrypt_init(void) /* Call into SWIOTLB to update the SWIOTLB DMA buffers */ swiotlb_update_mem_attributes(); + + /* Set restricted memory access for virtio. */ + virtio_set_mem_acc_cb(virtio_require_restricted_mem_acc); }