Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp205386lqi; Wed, 6 Mar 2024 14:44:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV1Z8gvu2dpN4lV0SH71xzPqDljVS2mb9hCtlgN7Z6qfima+3YBDWs7PIguljtz3gs9oDIAMz3sfjbX7hYcuBu0fdpcn2BKV/49rVATew== X-Google-Smtp-Source: AGHT+IGoCCDxzttvMGLf304S2QDemAPpo6NpC4KjMWNl7qxPZfOy1ptDXnyyywSVJpntgjQVP+6K X-Received: by 2002:aa7:d44b:0:b0:567:4694:159 with SMTP id q11-20020aa7d44b000000b0056746940159mr6717877edr.26.1709765050091; Wed, 06 Mar 2024 14:44:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709765050; cv=pass; d=google.com; s=arc-20160816; b=SU9vgdqpGQb9F1u4VCMVUfyuTxkWCvguhyGt5fsJ/xMvN75P2t6qYhJ9Hreytjeemu 7JmaygxXW71TEl4rWd6QPaf71uwJoKA7eCTo7eki3CT3IL0V9rzRiPLGC252b8aBmgNL W9RVW0G7hnyVfAZ1XMeWafIgsGzA2DsFt/BycModct5jGNcl36D/nIN868LFg4sI6/SU c4aLlXHZK4kz9+FL8xEe2NccHF1YN6uGraE/BjnLZl5ZXLjwyCinPx4IX59iHS5YTIzs tc5xbrax0euvB4W1gg1/71+rElShBmw1s/Ee7Ev/YqMIngqAWkLlunumKad/f4LmIAub jGWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=kYeF/kACf7fpncWg98H8xfi7RXLHudnXWCpEy+NEJ2g=; fh=8DIzSYPevO2zLq/kIhOOfcyatlxZeebaRHQc6bTh48U=; b=H4wlLnSRK2Abt1dePD1zP0AiePbABLmhivgL0Pz+xoCDQf10iSPzLi33cOqAWafZu/ TRSFeY9uC212NeJOyNXD44G/YsljbR8a4r9ECly3p713+Hd26fy5b7eGmuI53i9LpcML GYcDzXac0N7Pkt25cnDjyR7rE3isM3ISiKT/LBGgyRcsgPhyxJk8XhOabFGboRnNof5t kPGrA8OSZLytYw0b1tp1wYC1+oS6dvIfs8RPoM3s4C6hN0/pTj9CI8dEKBBqnEOwwJcu DuklNQfsoyrx8gsCVn6/sFN0zilfD4E1EGRDSbhqxM76d+lT6+TX7APz2EFUpVVvsG8B D+KA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=a0QuFOVj; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94671-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94671-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s9-20020a056402520900b00566c272382asi5756759edd.43.2024.03.06.14.44.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 14:44:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94671-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=a0QuFOVj; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94671-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94671-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D07891F22DBE for ; Wed, 6 Mar 2024 22:44:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DDBC81C29E; Wed, 6 Mar 2024 22:43:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="a0QuFOVj" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B4431FA4 for ; Wed, 6 Mar 2024 22:43:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709765037; cv=none; b=AXD7K6c6lrgf0Z7h7JIEdgtUXwzwDYzy2ObNvx9bLNCjhTj4fVZp2KvOkE5NDLbzDuLUHwwORTR/erng2w5hhbzZiNg58J9DLrpY+A2aeTX3r6PLejj+RKgAhChZs5Tr1M4FQWG1wR7nw4PXUR8IJvwTUYRcVJ2kdXFjK/0t2ZA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709765037; c=relaxed/simple; bh=/HhmgHY9Vyo2JQaInrFC98id0ADUFYLs567EtUvXnXw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=u+hzYfmeSqY9d25S6ihVoz5nzzqZMWUlCtZbQLQDqbpaC/HjiO82XGLEuiLR2/mDfU5Bal8Plf2HgYJH7m//hIui+43xVVjPjy6MkhUkxEsKTy4uRjOT8wvY0mvyNBA5vT/YaMNt4NNNIS/OSYCLwz/Ftf/Qs96ad5UO1lq0Okw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=a0QuFOVj; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-609f015e386so592557b3.3 for ; Wed, 06 Mar 2024 14:43:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709765034; x=1710369834; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kYeF/kACf7fpncWg98H8xfi7RXLHudnXWCpEy+NEJ2g=; b=a0QuFOVjcDcIIAy4T76L90YwKpTits+1HtAvGasuZR2unuVp75Egd+4kwtib2nLUaC VoB1fycOqjd6YrnpgzRr0HqQFSdW1lbbgbP1vOa6pvAukRTds96OJ+kWK85oZZ1sxPMR pgNgdpinDnYc6CO12RgccF9E9G6l8+afE3T31EYhnMhTBTt/sUsIOf3spAFZX/GOed6W y4hzlM1tjWEtrHxGmbe1NVXbj28A+2lnyHcQLPdRp46pDO9iAUldeNbSBkmYNlzHLpQY 1ERBp7nniX2VvEdOqSj70JMowNY55zxC92osIAaUO5UpKUD8U3rbpRIH87b+vspwn8u+ BfeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709765034; x=1710369834; h=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=kYeF/kACf7fpncWg98H8xfi7RXLHudnXWCpEy+NEJ2g=; b=uSOj2x7MMx3yjxKceMb6b/V6taZyHw4LwKSKd7+bncHKOKCEYPCGsQyZIKWKt9KHJA SpDgGglHIHBd5E81l3EjRMP/s4R7YjPJXh0oIQSUF+IAR9WTUtD/sPtR5Y+XXtoOqtUU MYLNkkwW4QJeHcPhxI9pW5gCJ58cBcLPGuJIxrtdGII0WVmr9/l4eutPwsmDsxPRagbM Z+HFD53oEv6jVL8BhJ9Pt+mYUXPQ84UZos/sh17n9+niTDAc3sVUem4129vt7Ahp+tmS /HoSUe+EpJmm+N7ZGLzEYgtPd1MPWROLrht+GdmyBYcQkW5pHBifnqE6vuPSwDyoof2p CSbQ== X-Forwarded-Encrypted: i=1; AJvYcCVvoA6E14mhudDGpzroCKJTduQF41flEkGVkKuAm60N5OroUgd2ul6iUFbFeBQWRdMVzJOWBfiE1SmIDie7xd+eX+bbVi4L0wnITEgI X-Gm-Message-State: AOJu0YyNfYVx0W0RwAw9OWMKeqVvJ0vmnxLrUXqkeWBn6fWlQG+AiBfu qOUGuithjkj/tp78w9DEfjMpIj0a+H3qicG+BzuTW99abOpwxrLh4MScbtiSmEYzv6/xum2tYj4 qMA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:110a:b0:dc7:49a9:6666 with SMTP id o10-20020a056902110a00b00dc749a96666mr4059310ybu.3.1709765034707; Wed, 06 Mar 2024 14:43:54 -0800 (PST) Date: Wed, 6 Mar 2024 14:43:53 -0800 In-Reply-To: <0a05d5ec-5352-4bab-96ae-2fa35235477c@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228024147.41573-1-seanjc@google.com> <20240228024147.41573-12-seanjc@google.com> <0a05d5ec-5352-4bab-96ae-2fa35235477c@intel.com> Message-ID: Subject: Re: [PATCH 11/16] KVM: x86/mmu: Explicitly disallow private accesses to emulated MMIO From: Sean Christopherson To: Kai Huang Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yan Zhao , Isaku Yamahata , Michael Roth , Yu Zhang , Chao Peng , Fuad Tabba , David Matlack Content-Type: text/plain; charset="us-ascii" On Thu, Mar 07, 2024, Kai Huang wrote: > > > On 28/02/2024 3:41 pm, Sean Christopherson wrote: > > Explicitly detect and disallow private accesses to emulated MMIO in > > kvm_handle_noslot_fault() instead of relying on kvm_faultin_pfn_private() > > to perform the check. This will allow the page fault path to go straight > > to kvm_handle_noslot_fault() without bouncing through __kvm_faultin_pfn(). > > > > Signed-off-by: Sean Christopherson > > --- > > arch/x86/kvm/mmu/mmu.c | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > index 5c8caab64ba2..ebdb3fcce3dc 100644 > > --- a/arch/x86/kvm/mmu/mmu.c > > +++ b/arch/x86/kvm/mmu/mmu.c > > @@ -3314,6 +3314,11 @@ static int kvm_handle_noslot_fault(struct kvm_vcpu *vcpu, > > { > > gva_t gva = fault->is_tdp ? 0 : fault->addr; > > + if (fault->is_private) { > > + kvm_mmu_prepare_memory_fault_exit(vcpu, fault); > > + return -EFAULT; > > + } > > + > > As mentioned in another reply in this series, unless I am mistaken, for TDX > guest the _first_ MMIO access would still cause EPT violation with MMIO GFN > being private. > > Returning to userspace cannot really help here because the MMIO mapping is > inside the guest. That's a guest bug. The guest *knows* it's a TDX VM, it *has* to know. Accessing emulated MMIO and thus taking a #VE before enabling paging is nonsensical. Either enable paging and setup MMIO regions as shared, or go straight to TDCALL. > > I am hoping I am missing something here?