Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp856150rwr; Thu, 27 Apr 2023 09:00:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4c5llEGyInMwzRt7IVYqnzr+uyKij2NgXF0Dq9vXBl2KVvG0FwMznZkD6y9gMI/evTdhfV X-Received: by 2002:a17:902:e5c7:b0:1a9:6467:aa78 with SMTP id u7-20020a170902e5c700b001a96467aa78mr2430573plf.4.1682611212712; Thu, 27 Apr 2023 09:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682611212; cv=none; d=google.com; s=arc-20160816; b=QF0w2cJz5+tCJwOzexaLAJrFI9qneayz6ZKxTjXVjTlsYBWONUFyjSyl7bch8OQfZS ci/vJrNZM7lzmDPd8wD6cbWJXbEfcPVps7lk2eqCtT5h6MIOq566cfNu6oiJmFgAax2p /E7B1wu/oYKDFrQjg41igtqYnKJNBTPtxTXNQ7si1tdDIrebdv4nGkv+fitLP5aRxqSH zAjoZvQVilqcVN2jJsCtE0nijF6cgN40r8J2zmnkvaCX/DTaG5f8dJ2Dzm1N005qolzm vuCnbrxMdlCwb/hn030ZBQ0iDwCb1XqnfNQSLoTYhoJSexctitcMxSah2px+ye21bxnm 2T/A== 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:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=/BGmFMzU05ZC8sZHkNJgBYDk4c+irOD6V9U91yPyg9g=; b=r2jyX8AxSlwhemkYRAe/54XSKQgxWkmIbTrO0WZWgRWBPpEu874dwdVlL+zvyHkU6Y zUmRUDoOBt6niixZL7pLA/cWrURp8HS4jg+MhOMWGLIzNV03vnf+egn44cKMEz6DrBtT y9mlzY87XVqIM3j6nFZ+LNeCiOh0Un5/KLQjdXWv9XcCo+VTrAqb+6WaWAcy3JQRatWU 1qSPouCDDk31sDmI7atfBKZpV5jqyVeFh7Bb7IYCbEvW5KfKK+sxnRy8pZgBvtT2MG5d 2EpYQk9d0bBnLi/cJbB++T8pXHxOhmxELkNJJ2q2Y4mQTop/veRbe6gQ6u4P1nynYtdr faDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=paDMNiJu; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf6-20020a17090b0b0600b0023a6f4e0510si21220822pjb.155.2023.04.27.08.59.57; Thu, 27 Apr 2023 09:00:12 -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=@google.com header.s=20221208 header.b=paDMNiJu; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244246AbjD0PvH (ORCPT + 99 others); Thu, 27 Apr 2023 11:51:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244175AbjD0PvG (ORCPT ); Thu, 27 Apr 2023 11:51:06 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B5733585 for ; Thu, 27 Apr 2023 08:51:05 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-64115e69e1eso4678622b3a.0 for ; Thu, 27 Apr 2023 08:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682610664; x=1685202664; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=/BGmFMzU05ZC8sZHkNJgBYDk4c+irOD6V9U91yPyg9g=; b=paDMNiJunl017JsePs93I3EW8GnrmF4BA+oHSO3Osw6zGVWtLuWrBcMRCJQeWgFPpW kqUV7h4lT1mAxFALgewPDuVLQjgbEqpxdCX3hOh+gIElgZScbMQiYnMhNWGl/jIaK/Qp 5RWEi7PZfm2t7ZCOuwGIUAJGkC6FfqWYpOuK/nb1SQpGdKFrPT8QBxKEk3pLf0nFKuA3 J4LicDbSLsEZh96t9a+zWsVMFTUzKLprFvHc6WQl9lR7Xh6WXEJER2ULFkzozmZ8AVaK 9Hkh7adpeQlYPe2BMdVEAqYrjm5syMMEk92wdM21XhCS8TDxDjy7ttTlvMnaFErqG1qg /rJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682610664; x=1685202664; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=/BGmFMzU05ZC8sZHkNJgBYDk4c+irOD6V9U91yPyg9g=; b=fTd6GHzII9iEXzf0JsVGupkC+36DjpLGhG3N76dRgns5hDSJyprVgoq3HzC7FYXBdq AeLWTz48uJK5zhhAjIitgYoqy9i9e2eXx91jx+B0Nf8LCh5lTlNwHB1cXFViOOytd/kD z1F+5tPJxiMEADmvD9Dpw+KsPjzSNJgjDbR/aj9srzK8OesXuXapy/CQtdrSvDtvJZes F5OGFbOJNE3cLJIKOKVLrFKO6KPIx0tcxePh0LMAioX0hW0uiYjW6lI2Y/qEMm85T30p Qs/dPqfy+RQRXtuoNGHUBNwIUwlXylnaPW01aYCimUZVnqtLmbYjD3cSQeaWs0JMBypq lpkw== X-Gm-Message-State: AC+VfDzYh6mOBavED9jRPXXI6ifSGVybSUrN+dKrplSNdvhuVChstbNe xSzc03Txj4EjYssorrREwtVjewax6yw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:203:0:b0:528:a60c:c06b with SMTP id 3-20020a630203000000b00528a60cc06bmr451235pgc.1.1682610664522; Thu, 27 Apr 2023 08:51:04 -0700 (PDT) Date: Thu, 27 Apr 2023 08:51:03 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230418190904.1111011-1-vannapurve@google.com> <20230419133841.00001ee8.zhi.wang.linux@gmail.com> Message-ID: Subject: Re: [PATCH v13 098/113] KVM: TDX: Handle TDX PV map_gpa hypercall From: Sean Christopherson To: Vishal Annapurve Cc: Zhi Wang , isaku.yamahata@intel.com, dmatlack@google.com, erdemaktas@google.com, isaku.yamahata@gmail.com, kai.huang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, sagis@google.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 On Wed, Apr 26, 2023, Vishal Annapurve wrote: > On Wed, Apr 19, 2023 at 3:38=E2=80=AFAM Zhi Wang wrote: > > > > On Tue, 18 Apr 2023 19:09:04 +0000 > > Vishal Annapurve wrote: > > > > > > +static int tdx_map_gpa(struct kvm_vcpu *vcpu) > > > > +{ > > > > + struct kvm *kvm =3D vcpu->kvm; > > > > + gpa_t gpa =3D tdvmcall_a0_read(vcpu); > > > > + gpa_t size =3D tdvmcall_a1_read(vcpu); > > > > + gpa_t end =3D gpa + size; > > > > + > > > > + if (!IS_ALIGNED(gpa, PAGE_SIZE) || !IS_ALIGNED(size, PAGE_SIZE)= || > > > > + end < gpa || > > > > + end > kvm_gfn_shared_mask(kvm) << (PAGE_SHIFT + 1) || > > > > + kvm_is_private_gpa(kvm, gpa) !=3D kvm_is_private_gpa(kvm, e= nd)) { > > > > + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_INVALID_OP= ERAND); > > > > + return 1; > > > > + } > > > > + > > > > + return tdx_vp_vmcall_to_user(vcpu); > > > > > > This will result into exits to userspace for MMIO regions as well. Do= es it make > > > sense to only exit to userspace for guest physical memory regions bac= ked by > > > memslots? No, KVM should exit always, e.g. userspace _could_ choose to create a priva= te memslot in response to the guest's request. > > I think this is necessary as when passing a PCI device to a TD, the gue= st > > needs to convert a MMIO region from private to shared, which is not bac= ked > > by memslots. This isn't entirely accurate. If you're talking about emulated MMIO, then = there is no memslot. But the "passing a PCI device" makes it sound like you're t= alking about device passthrough, in which case there is a memslot that points at a= n actual MMIO region in the host platform. In either case, conversions should be unnecessary as MMIO regions should no= t be enumerated to the guest as supporting encryption, i.e. the guest should kno= w from time zero that those regions are shared. If we end up with something like = Hyper-V's SVSM-based paravisor, then there might be private emulated MMIO, but such a= setup would also come with its own brand of enlightment in the guest. > KVM could internally handle conversion of regions not backed by No, KVM should never internally handle conversions, at least not in the ini= tial implementation. And if KVM ever does go down this route, it needs dedicate= d support in KVM's uAPI since userspace needs to be kept in the loop, i.e. ne= eds to opt-in and be notified of any conversions.