Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6628595rwr; Tue, 25 Apr 2023 01:01:11 -0700 (PDT) X-Google-Smtp-Source: AKy350bvESQfOyHgJepeK98/jP07bGONamX7SP84TJ6rAP6KPTgyURd5ijxGJUNOia8Mc23zq5Bj X-Received: by 2002:a17:903:22c8:b0:1a6:c12d:9036 with SMTP id y8-20020a17090322c800b001a6c12d9036mr22285017plg.33.1682409671565; Tue, 25 Apr 2023 01:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682409671; cv=none; d=google.com; s=arc-20160816; b=FwkytTvNiwO97xNIhcd5/EK+nEMrVz9Tv0IVQ8iGhSmU9h/VGqTWe3VQuV/wNgArRw FckFTlcT9Ef7cPr6JL3gC3aJWzuX2R3E38woMXHbFMVmoB2oAcFNYyPBUpngyolS5C4i yLZJ/B1kKbo1thGYjxz890GnXw9VN1JwjUviOge1rriFMMt0zDUuj3qnmGBIdAn9+gCU AQl/XRmYfvO2wBsheOR/5Q9ygmsJRTL+lK34OOpAuZwXKWzcDa4ITW10HoMxlMAY9zDp 4fEAduP9J+IjE1vFwkZv4dxX/NP99M5YAcR/appDoOivLaI7yJVVwJMZdxwOV/l6vB6l wcPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=wJcVKVJA3HgnW7bSvVOddaHKG/ERA+dvV0Lub2llU+Q=; b=z7p0NBCozHqn/RN2yQllvxp7ihEP6WO/IWBy18ydXAWaXE4mV1BtVjTyw6+FkS8neS Wx7m4vNar5Xl1nKnzFVQ3WJCpmimJFAq3f0KMOrNXyeQmkxzwEGPIiWZ7Q28Ti+jjB0G TiYYh9RqYNb+F7VH+UGy7KrRVWZjo9RUXStAQBLzFK0lmX0McKc3+VXFSLyCc8Oy+ccM p82iw6/AOHr1xkmOJ29cNaYid2rzD7WLJE4K9noFyJLE/7xjwAX+eo52ja0kEwuOl5P3 Qjk818TPEDQRgr+Lcj/uLM+3RyfW3DWSgyObYhXnk/+SudiGdAj7CIdxMyC63bWpTBpW Jufw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=EOkcITT5; 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 q1-20020a170902dac100b001a92694cbd6si14242165plx.600.2023.04.25.01.00.53; Tue, 25 Apr 2023 01:01:11 -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=EOkcITT5; 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 S233417AbjDYIAX (ORCPT + 99 others); Tue, 25 Apr 2023 04:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233383AbjDYIAV (ORCPT ); Tue, 25 Apr 2023 04:00:21 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FBC32D52 for ; Tue, 25 Apr 2023 01:00:19 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4eed6ddcae1so23393598e87.0 for ; Tue, 25 Apr 2023 01:00:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1682409618; x=1685001618; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=wJcVKVJA3HgnW7bSvVOddaHKG/ERA+dvV0Lub2llU+Q=; b=EOkcITT5Rq6XWK3ejRIWqvQTkMe0ymO3UjoLJxHU/nMXd+kJfjuDnngRLl0056SRHm ThA9qKaCSDNobvcy6jnV68/ursuWUy1LRvfcOiMnvJd6umM5gBHUqjEii9P0KObi7KGh BAFvn/jnFZdpnznd05oLdmPYj0b3vIN6GQEhpBNTdSfL4z+ZwxB1QMA9d150A+77EI3i plazI1uNEF7MssMeARqn6HbaKObj7K0qUBZHDm45tsXJspZswccglcpyVh33k/az8cYf 7sxktCdB7+YpplssXVz1+FDrVlx5NHqwNlTaeiZQzIojqvTIoBPoyIpW8YSps41cN/xv Ujqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682409618; x=1685001618; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wJcVKVJA3HgnW7bSvVOddaHKG/ERA+dvV0Lub2llU+Q=; b=ZP8aq8DuFfQae9D+qG1skpzsiGmAEKTi7A8OKXEpaL1zRNXscNdVlBehHKWb9ikN29 lDSRtbzbk6FqhqbvyPcD6pmTsrdsNpMscgNe55Q/tjWmGFtZVi9xorju2wuGOSQjpc0H 1s3C/zUpo8tm8N+HlZOiA0C+LUTled9XmgKyTRLf2F2Ua11+uBwZrY0rrU4pznveXrZ/ tA2GhXWCirKk0819z3ImrtuS+xeuiohpE37bbwyAjpGrrkCafeazKTO49ooIlClEwpiZ +cQ9teUVG1lIrplz+2fMdKuYT31L8brOKmd4GSGjuBBs76CS4H0S9Sy3A1vW4PYxdSDU sW4g== X-Gm-Message-State: AAQBX9eq9gM0uMpNa7u/6FnxN1tonPc2Ya67k9bgP5a4LT+Rh3VDfduv 3ew5feY9eXPazMZTpxWhJCFZkGJVP/ikvTGMdjq/lQ== X-Received: by 2002:a2e:9b87:0:b0:2aa:4550:9169 with SMTP id z7-20020a2e9b87000000b002aa45509169mr3099317lji.20.1682409617717; Tue, 25 Apr 2023 01:00:17 -0700 (PDT) MIME-Version: 1.0 References: <20230419221716.3603068-1-atishp@rivosinc.com> <20230419221716.3603068-46-atishp@rivosinc.com> <69ba1760-a079-fd8f-b079-fcb01e3eedec@intel.com> <81c476f4-ef62-e4a6-0033-8a46a15379fd@intel.com> In-Reply-To: <81c476f4-ef62-e4a6-0033-8a46a15379fd@intel.com> From: Atish Kumar Patra Date: Tue, 25 Apr 2023 13:30:06 +0530 Message-ID: Subject: Re: [RFC 45/48] RISC-V: ioremap: Implement for arch specific ioremap hooks To: Dave Hansen Cc: linux-kernel@vger.kernel.org, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=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 On Mon, Apr 24, 2023 at 7:18=E2=80=AFPM Dave Hansen = wrote: > > On 4/21/23 12:24, Atish Kumar Patra wrote: > > On Fri, Apr 21, 2023 at 3:46=E2=80=AFAM Dave Hansen wrote:>> This callback appears to say to the host: > >> > >> Hey, I (the guest) am treating this guest physical area as MMI= O. > >> > >> But the host and guest have to agree _somewhere_ what the MMIO is used > >> for, not just that it is being used as MMIO. > > > > Yes. The TSM (TEE Security Manager) which is equivalent to TDX also > > needs to be aware of the MMIO regions so that it can forward the > > faults accordingly. Most of the MMIO is emulated in the host > > (userspace or kernel emulation if present). The host is outside the > > trust boundary of the guest. Thus, guest needs to make sure the host > > only emulates the designated MMIO region. Otherwise, it opens an > > attack surface from a malicious host. > How does this mechanism stop the host from emulating something outside > the designated region? > > On TDX, for instance, the guest page table have a shared/private bit. > Private pages get TDX protections to (among other things) keep the page > contents confidential from the host. Shared pages can be used for MMIO > and don't have those protections. > > If the host goes and tries to flip a page from private->shared, TDX > protections will kick in and prevent it. > > None of this requires the guest to tell the host where it expects MMIO > to be located. > > > All other confidential computing solutions also depend on guest > > initiated MMIO as well. AFAIK, the TDX & SEV relies on #VE like > > exceptions to invoke that while this patch is similar to what pkvm > > does. This approach lets the enlightened guest control which MMIO > > regions it wants the host to emulate. > > I'm not _quite_ sure what "guest initiated" means. But SEV and TDX > don't require an ioremap hook like this. So, even if they *are* "guest > initiated", the question still remains how they work without this patch, > or what they are missing without it. > Maybe I misunderstood your question earlier. Are you concerned about guests invoking any MMIO region specific calls in the ioremap path or passing that information to the host ? Earlier, I assumed the former but it seems you are also concerned about the latter as well. Sorry for the confusion in that case. The guest initiation is necessary while the host notification can be made optional. The "guest initiated" means the guest tells the TSM (equivalent of TDX module in RISC-V) the MMIO region details. The TSM keeps a track of this and any page faults that happen in that region are forwarded to the host by the TSM after the instruction decoding. Thus TSM can make sure that only ioremapped regions are considered MMIO regions. Otherwise, all memory outside the guest physical region will be considered as the MMIO region. In the current CoVE implementation, that MMIO region information is also passed to the host to provide additional flexibility. The host may choose to do additional sanity check and bail if the fault address does not belong to requested MMIO regions without going to the userspace. This is purely an optimization and may not be manda= tory. > > It can be a subset of the region's host provided the layout. The > > guest device filtering solution is based on this idea as well [1]. > > > > [1] https://lore.kernel.org/all/20210930010511.3387967-1-sathyanarayana= n.kuppuswamy@linux.intel.com/ > > I don't really see the connection. Even if that series was going > forward (I'm not sure it is) there is no ioremap hook there. There's > also no guest->host communication in that series. The guest doesn't > _tell_ the host where the MMIO is, it just declines to run code for > devices that it didn't expect to see. > This is a recent version of the above series from tdx github. This is a WIP as well and has not been posted to the mailing list. Thus, it may be going under revisions as well. As per my understanding the above ioremap changes for TDX mark the ioremapped pages as shared. The guest->host communication happen in the #VE exception handler where the guest converts this to a hypercall by invoking TDG.VP.VMCALL with an EPT violation set. The host would emulate an MMIO address if it gets an VMCALL with EPT violation. Please correct me if I am wrong. As I said above, the objective here is to notify the TSM where the MMIO is. Notifying the host is just an optimization that we choose to add. In fact, in this series the KVM code doesn't do anything with that information. The commit text probably can be improved to clarify that. > I'm still rather confused here.