From patchwork Wed Feb 28 02:41:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 207639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3099390dyb; Tue, 27 Feb 2024 18:45:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUy8Bnr3KyPgfWM15iNQld5ZsCgos2VzABEqEHtKN3Mmsa1FCxUHxMPzi7KA/eIaduOdJz9YYSCBAiQCYzO7blGO0AeUg== X-Google-Smtp-Source: AGHT+IEdIjDmacGS2YMpcHELxD6gHtHGslx7mcFaXa1f2ZJn4gQQ24+qXY6e37LEH519BRE8epQd X-Received: by 2002:a05:622a:1649:b0:42e:8a12:f8c6 with SMTP id y9-20020a05622a164900b0042e8a12f8c6mr7349242qtj.19.1709088347292; Tue, 27 Feb 2024 18:45:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709088347; cv=pass; d=google.com; s=arc-20160816; b=E8+LWyhTX5JhK5QvK2V6xnRRWuZxFDYz4oEkdCVDedirHfcAFcN1TT2ziV5RY5mPZi eylG2O8w0q6pEIwLdQ1yXeLRKsmeyhpfio9ibqe5rOP/ZDEvKWkB4V2fFUen2oqqReMb RgyolF8ZcZFoKbxSFrUFR0j7tawzFGcllxAcoA2yhl20n80iFhZoU5/r+8xYGRR4J+8g EekZuxbGX8NomQXodzSIv7au93e4AOZCTv3Yl0wP/dtv4nBMTgEoTp7tlkbjUzM8palw eV+x1/4plHFMIDxDS08IKtjx2i3w6p3V8h2A+n4d8QfkdQ3JCzUForK5RFvFcl9crLu1 5fKw== 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 :reply-to:dkim-signature; bh=f2pVTuxLJ1bF5JkBExEt38LFzKRRlG2j//10dt1o0l8=; fh=FOUVduz0+O0UMtizUduRdm1Gx2lC+Bxc6K99RbFKJa0=; b=d+KZnN3A8Pwa0G6m8qGsctTh5a4/A1tqPSPfO3khHXkXnf8Jd5nwrcv2MSvL7JT3VE LSI6DBMb31ByCtMZQa5dUyKcOz4pSLm8+W2hAQzGIBNEwZhVTL+93yEW2vlQKrgfQtpO YDzpMm9od1yMeZ8jAAY4x/nfNI9rGB5BThRrvV3vdIhKRwqisQq0xUqlEzspGO7YWljS HnWKRaeZr8PUg07B5X1j/gW6LH/cdooDILNvCqLhxZUOfKYj5fRBAifTFmfXGKBBjJ0J 1MH3p67qMpxEIfqXqXgdcY8QeZAtixk80OgmB5rRhZAsjBnCEtj6i/a6LzKT93btp/HK APHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="edga/too"; 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-84437-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84437-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n14-20020a05622a040e00b0042de973b9e9si9289335qtx.151.2024.02.27.18.45.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 18:45:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84437-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="edga/too"; 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-84437-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84437-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D65D91C20930 for ; Wed, 28 Feb 2024 02:45:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8784D22318; Wed, 28 Feb 2024 02:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="edga/too" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 ED68C2C1B6 for ; Wed, 28 Feb 2024 02:42:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709088133; cv=none; b=fBQNrF+omhWZwYV97uPKm9VOLDaU9wiiXJ8CCEHq1nwO12AjayMTGqjP+veWBZN8fICgJxIrnWPN9TZzyzFRX09vCYM1vDDxRH2uzl9lfFiQSMf1KrGO13dsHqqSjFpXRXhBX7ylbGRJrMpuVEo3Mb7yR8p1I3Z9vttzhTNSnQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709088133; c=relaxed/simple; bh=UGrkpK716aAHiw66iG1/DSWpe947kr0y+y0Afd7BmIg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R75X57zlT/wsPEnVSMh1PRUJppzIhq7B9Tke5tDOdLnUKhPz1zOmeKzkK9cM/wGp0wblnN+XEMd7QtgRB5azleBt7vvPihj0kmWsv0Vhx/ZA6yYmkUmCGzxAR4BuSpZxXKgzKI3QQIJDZPi4IAj+lgzIR6+UPF/MBbAzhUH5Q+k= 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=edga/too; arc=none smtp.client-ip=209.85.128.202 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-f202.google.com with SMTP id 00721157ae682-60810219282so61210967b3.0 for ; Tue, 27 Feb 2024 18:42:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709088131; x=1709692931; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=f2pVTuxLJ1bF5JkBExEt38LFzKRRlG2j//10dt1o0l8=; b=edga/tooo62Ub6On2m2O1NUOjTM2zXNHq6BsT4vn89Q2jP+XHb+ii9oxXDO7TKkLjc 13mriBUiCJxtVKEbtq/+zZwEjfoQ4FIyY3atcTIZNTtS8ZQ9+X2d4IQcTeAT2IUln9OW X78TUvtzeZRJasqIg8qZwN8OMCMjCb7najP9MHk2NyWJ6eABftNwdvGr3F89Rm0pdZBF p174c5aDsey9R2lbEcAcQWsii4f5iQk4bK/d3gBF8P18P6YhW4Yh3yxbpxm3hRklAzfD fvy9LitG5Ncnhldf7ThRBbCetaCHq54huVnsRuWzEjACNXFtbMI+zLBR8IQd4UEtEIwC +/Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709088131; x=1709692931; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f2pVTuxLJ1bF5JkBExEt38LFzKRRlG2j//10dt1o0l8=; b=vKWIwwPv4kMd+1E6Y7qbcyKO27O0+pZZbEBc8a1rK3vtwaNuZkZSiFy14LZ+BafkCB oB7xq2PuTDyk0kp59HK0CSd2392ngqgs+qqG+REPChxSDaVL3c7lZWgTjlxmuwXF/63e rYQdCpJOt30/R+mzOKpXo1I9QHuYXNa5gTSd88PsOWaj4ndGfVJb/hrXE4BOQY5W/7vu yiuKqsmRZqKNExJjIOwHokDTUr9bpjcHkFRi3Zi/PwisUrxWQJ0pQofJMUlSwE8IbMf/ 98bQIBn33FS0oZBuIP14pBXQNmHyzzfXMXERygyYxbwq+gsIR8jiMfz6wdDBKfFT1m7y lx/g== X-Forwarded-Encrypted: i=1; AJvYcCW9zAV3zPBV7nDhX9zzpbjPOLaBnMl0aEMRbS2L3twma7soBTfGEl6MFOG1GWm5mYMvskDX/AWX2WLhCkkZQOwzD56H7n4Z1+nop8zS X-Gm-Message-State: AOJu0Yz1Wyb79bcld2pGFIx5FhxhEI+LMHJ2ODx4+IGnS37pTMoXTlyd Tu5tMGFkTtkng6AndlyEJLtxoXYcPLaPKYDwol+MH3JWzw2BkXk+2D4mjzJrsBTTpDNve1Y7RDO uww== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:5714:0:b0:609:3bd3:31fd with SMTP id l20-20020a815714000000b006093bd331fdmr118940ywb.2.1709088131111; Tue, 27 Feb 2024 18:42:11 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 27 Feb 2024 18:41:42 -0800 In-Reply-To: <20240228024147.41573-1-seanjc@google.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> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240228024147.41573-12-seanjc@google.com> Subject: [PATCH 11/16] KVM: x86/mmu: Explicitly disallow private accesses to emulated MMIO From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yan Zhao , Isaku Yamahata , Michael Roth , Yu Zhang , Chao Peng , Fuad Tabba , David Matlack X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792109022850169018 X-GMAIL-MSGID: 1792109022850169018 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; + } + vcpu_cache_mmio_info(vcpu, gva, fault->gfn, access & shadow_mmio_access_mask);