From patchwork Fri Feb 9 22:28:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 199152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1177347dyd; Fri, 9 Feb 2024 14:57:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVmOwlGOznP5cmfvx465UQzlqYCJctGN5AppuA8iRgdsZVepbevZ9lph4pKMvfhTqJscD8FmhFlG2PBS+kVb2ZbpG4NKw== X-Google-Smtp-Source: AGHT+IG4sHAaz9v423yZ1ApKuz/X7nA73jZFAOr5oGD8bOzg5MVLR5fFAK+pTApLA7rTJL+8PG1f X-Received: by 2002:a17:903:40d2:b0:1d9:1359:75ec with SMTP id t18-20020a17090340d200b001d9135975ecmr811303pld.30.1707519463832; Fri, 09 Feb 2024 14:57:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707519463; cv=pass; d=google.com; s=arc-20160816; b=XjSGK+6fk6TBG0XpRGx/+d/ZNd2O6/LpV/MrQbdlHI9ln3bmB3CpWk9FjNfENPbIHd I+gxnClJ42bIeJHlTNcWpGdLfhRe0hZiImalXruOqDKDWp/vSsTkeiiLEOdjt+hMUiXQ tXGxBJwIXX5HEpmtAVsUbM5I4Vs1sm4nGIQTxuOgoh81SnwA0L0HAxxeFyfDRAWuPqdH fmne9hkTmSFiqFwzddVLouz46DdA2nlceuym14xp/hxKJq+TMakYXU1fH2WKxqpd+afg MsBcpulLdE7XDohMVHBy0NrwZ00UTboJUy0qwpsgo/iptqDNme7V61kKHKbMK1+6tMoM CNuQ== 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=7bcloJ+2HwTb1M9xznBR1nyxmyl4elTRFFxAIRR6UOg=; fh=pqBDEyoFxSNczJ+E7a33VCv8i7M20g2pNUZi29bXL6Y=; b=KsrkofVrvXedbhIOvef6sNspW2f8xeXfMg2XbfbSZoFZV8DUff5DawjJXcnEjSov9c drC0iyrqyqfRDD3xoHC3kW/8rdoAP7W89Y5LRDKE/LgzclS+LVERyRsGztfxrpTVp15N U1qAQnggJJERQdvykaD3ESYM97EgSklgSJN0e7UPQ6LbRs5NdqWt538tSVukSTWAr7rY pq+WLpRCXhREDvBxzLJ89E27MzO8Y9TdyFZV7tJE6o+sFvo0OAediL6+rkg/x6sd19J5 zaERSqnduRQC9aatiASiVdt0m2A8i8PKlmVp3cR7TGdKqaZadZGmeXh3N9GMVCKD2Ced iWUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PSiNohpa; 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-60106-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60106-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCVNjWjgQij+VT507DEYKR1JJObKC4s+5Mipxe5XXn5+05D7FmFf0BnFMRXe5BjVu6n19p5fk7TW4AOWEIxsN9e0cFq4Zw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h12-20020a170902680c00b001d791ce5b52si2314284plk.209.2024.02.09.14.57.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 14:57:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60106-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PSiNohpa; 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-60106-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60106-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 9FEF4B29158 for ; Fri, 9 Feb 2024 22:30:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE88339AC5; Fri, 9 Feb 2024 22:29:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PSiNohpa" 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 82965381B6 for ; Fri, 9 Feb 2024 22:29:05 +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=1707517747; cv=none; b=MEwVgRxetiwCi8h1jj3C2juGMmNBR7B7gS1l9TUHIEX45Rg4TOwolonjoAL4u8fXOTiBSbfVtL3B7HEc3dWMOSDfSmZzQv6u6TYSyDhiCFqtKmwPAo+tgGW40ewsKRkMksSkFVNVI/kXCrh5z/lVUUykfni5PVtxG9YV8d9XQkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517747; c=relaxed/simple; bh=I+1ReO9gJD+nyzCjrY4TEB+E2DVWxf90KoNj+96Bxgs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DgQZ7X67bNiXyfrKfYU5eKi1j5eox7sYE2gjSqXD/eWOnyRYOpJgJhO5PqyrB7m63BJFpVnDxzl0DxJsdSUyyK7HjW1pkvDMTIOqn/95jXccTDfzwSGB/iy9LGsQ9mxhsJjp1QHZ6eBweuiwGV4WYDIjBbVkE4z3agwwZ0Qf1B8= 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=PSiNohpa; 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-5ecfd153ccfso29550587b3.2 for ; Fri, 09 Feb 2024 14:29:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707517744; x=1708122544; 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=7bcloJ+2HwTb1M9xznBR1nyxmyl4elTRFFxAIRR6UOg=; b=PSiNohpayclniZ5o4jJNQhNEQ6poxFoV0Ma84p/699pC92QSuRExaK3Je5jW8clhur CUQmpVQQ2tkaUHZaZUbOVBFDmQjjsSdXQHLIFT7xE+pmxb9rI97qDfJwKhpW8lDfB+bj Ge7w/sIi2OgjQ2MRSRNK74RtXQHcwVrEjicKTrQeAu7g2Vgv03IYSJANbSfDCur/r59P v8yI5CxzuKmNWnoITfxKCEFmFqIdc+VbZ2/eOYeCvwg2B0LWz9/PIkwxnrONZICIq2at lZx6kp5cr+UCiCBLW78nK96kVaW7eSMIP3MJ0jZno0AX1tI5qWjtzGJKMvmIKgm6Ajx1 elew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707517744; x=1708122544; 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=7bcloJ+2HwTb1M9xznBR1nyxmyl4elTRFFxAIRR6UOg=; b=cXgCenltgiP0a617yf9Y2uX0/2ivBModGrjkpkQ29edCKm8nk/61jnIsa1ZJPKccaD JGsFOJ9f0OdPV5SLpmQFYvwfnWhRiETO+/wBIH3qP++GDwjjFd34IHKCwcRqZ72g6QCN Cnz7muAfqSyTh6pgLY2Ykr9daNdW/3nxLIo3+hf5AWq7acKsgx8oVuG04O33DpNGGpAF /S00Vsb9D7yIFwc8v5JG2wL9HfXgyLS/Dhlj64T5X4AdoKo7NDA4LEToVwRH4P5VJnpN 5lSHRj8pvEBBBRZCEYWzT8UWq2KaWZaUGWtge0+zGZBfPwwR++paAQPVqRqMPlLX8IA2 ENYg== X-Forwarded-Encrypted: i=1; AJvYcCXmaeI2bylaKTCMW8CSaCa2Dm2WGqLP5S6rTN0uyVHlxn/nP/cB7VE8ZZ7+LVhm8OvXb72Ks/SzzF8Hu1TynczxIK8NkDZWuWAxSh3U X-Gm-Message-State: AOJu0YzYE/Cs7ertCsPsnRY0h6OPxLnBcZlBww2A9BjFG0fuPPPhxKHs jiceWh0McpCkz6/MrYfQ/jyyEkNwnT4c9IMUoTUqv5I34+aiVVxDyjSHkwOn1leQNNh6oTuechK 0BQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1083:b0:dc6:f78d:435a with SMTP id v3-20020a056902108300b00dc6f78d435amr109630ybu.11.1707517744631; Fri, 09 Feb 2024 14:29:04 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 9 Feb 2024 14:28:56 -0800 In-Reply-To: <20240209222858.396696-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: <20240209222858.396696-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240209222858.396696-3-seanjc@google.com> Subject: [PATCH v4 2/4] KVM: x86/mmu: Move private vs. shared check above slot validity checks From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yan Zhao , Friedrich Weber , Kai Huang , Yuan Yao , Xu Yilun , Yu Zhang , Chao Peng , Fuad Tabba , Michael Roth , Isaku Yamahata , David Matlack X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790463929412791432 X-GMAIL-MSGID: 1790463929412791432 Prioritize private vs. shared gfn attribute checks above slot validity checks to ensure a consistent userspace ABI. E.g. as is, KVM will exit to userspace if there is no memslot, but emulate accesses to the APIC access page even if the attributes mismatch. Fixes: 8dd2eee9d526 ("KVM: x86/mmu: Handle page fault for private memory") Cc: Yu Zhang Cc: Chao Peng Cc: Fuad Tabba Cc: Michael Roth Cc: Isaku Yamahata Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 166cef0c3ff4..50bfaa53f3f2 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4360,11 +4360,6 @@ static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault return RET_PF_EMULATE; } - if (fault->is_private != kvm_mem_is_private(vcpu->kvm, fault->gfn)) { - kvm_mmu_prepare_memory_fault_exit(vcpu, fault); - return -EFAULT; - } - if (fault->is_private) return kvm_faultin_pfn_private(vcpu, fault); @@ -4403,6 +4398,11 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, struct kvm_memory_slot *slot = fault->slot; int ret; + if (fault->is_private != kvm_mem_is_private(vcpu->kvm, fault->gfn)) { + kvm_mmu_prepare_memory_fault_exit(vcpu, fault); + return -EFAULT; + } + fault->mmu_seq = vcpu->kvm->mmu_invalidate_seq; smp_rmb(); From patchwork Fri Feb 9 22:28:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 199153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1177453dyd; Fri, 9 Feb 2024 14:58:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCjX5HuwcqK860mKghsyNoz6OsOROmUCgRqWPxkskSQva7Zsposcb1a/S5fiUVZQYhJB7C X-Received: by 2002:a62:e218:0:b0:6e0:465e:cdd5 with SMTP id a24-20020a62e218000000b006e0465ecdd5mr682693pfi.23.1707519481679; Fri, 09 Feb 2024 14:58:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707519481; cv=pass; d=google.com; s=arc-20160816; b=kThTtSHtAH/BBnJi1jz33t5Ows1m7B4N+fJ2w7hedGAJQl3lf1mn5JY1LbWgAnYow3 /QlYbwxAs39TG+MSFe87kGf9wLn/gD9I5zyNo06kGUKeWXrSrSU8Yw9vpoD7sPXpw12H AHWlKoqfhc7h9DeANF9Y56MQl1TBr85+TbSUuss4VMVsN6a4OdTiaR41MOMVRKDn4kTJ ukITtIJReAyYB6/cCLOQl7/HLeKgVcDbIJ1f0+ZKs5Z2tzkZUV6imcHsFAjVzrUFaS9L bNj6viKmSY3ZkiP6l7Zvudw71qEggK3hD4xq1RrvH86E054bRZ/byOSpNHQWZnLfUSdU 0q/A== 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=a9w16DkYUKNtIq1BB7P1j7ef4bijSTE+8L2OPdx5r88=; fh=cAEHPHOW4vVhXpFPaJg0iWN6sE7S/CV0Zj0t2tGwbFk=; b=gKoXVQbFijitrneyjkIW5dsNhz7RVgmH+k0pE1Ue7OSz+r9kW4EEPr9LzzEhwGAP+k Wu/6320NvyVhp0+Jt3+8jU1a0PA4V/IbcQEpT1ffuEyUKeKxwG+Y8KcDLOGwxV3z1+bV AILjfGYIGDQaiDJm7HKDeKDgsQX/RqUrpeAx5xkgLR9Fy/tHrDzj2tTe2rTWt5RIsR38 Yn0Wy+lizt6NJ/qUnhq4IYtOaFxUjzhzH9HYI86TUbx/ejomWG7W9xmQbDoQvK7sxv9s WtBJAoU3yvIZ3XZA2fYYZ0ZdOsI3iS0pxYTQcguW7rcCfxoyLjGrSLgEepyoRdzP+n+O G0Ig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4rSD36P0; 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-60107-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60107-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCV75o6j21GtpdpoV8IiZzUrQHn89j4v5HDwByG0eyeiRo6mSCHBVFAwlOfxMrhhJmG5uL0YYkKhbyYjFoY5pOH4lternQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ck4-20020a056a02090400b005d8e352afefsi2635571pgb.695.2024.02.09.14.58.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 14:58:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60107-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4rSD36P0; 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-60107-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60107-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 52883B21BD4 for ; Fri, 9 Feb 2024 22:31:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2579839FD6; Fri, 9 Feb 2024 22:29:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4rSD36P0" 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 724F538DFB for ; Fri, 9 Feb 2024 22:29:07 +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=1707517749; cv=none; b=Rz+R5B4+UIIHd1+Ezs7A+T0Un0g/Q1d/9CKzoTMIrG/vMawWcrI2jCjQGZZ6osUMeUDDUN8JQCyf6gU0gklTV+ILVM8BGkLAFnkJVRcCuHcT2u7BCQV+jrvLKqeAjSRTfAjNR2hvQf/Vo9wzhwayInuQh0gXDSzN3Rl/WJ7bsRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517749; c=relaxed/simple; bh=MzdZYOJ8bcmLxbBzxayTEgk/rh3FciY0A5qDjUGjyCw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ntacnGQiG1ekRnE3tf3O3EuNeIe2Xth6isdswpLtDLHWcAxWvc+sbv0PQlDvC/6Ok0ODH5faNl1GfUVptgiB5/IpjwhRW5hUOXYTJUketMjSgZHSPWV4HAzhC/p4KmsZXqYFgoUby2Xz57srYGvkWujcDTqYZD/oIo1kjfS0++Q= 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=4rSD36P0; 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-604acd1d164so28997387b3.3 for ; Fri, 09 Feb 2024 14:29:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707517746; x=1708122546; 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=a9w16DkYUKNtIq1BB7P1j7ef4bijSTE+8L2OPdx5r88=; b=4rSD36P0XAQFuAK/Nms2+vP/iKlh4jKw3co2K416l19tvRWVQfYeGHrwdHSTAhdK+V vGF9bF9x4tJqT2Fs/aqmNcVD0wXXTcDxm7laxOjZP7vNf3K/+EY/1JkAS/hEG8k2RgLa JHCZ9zLtIv7REH4uXprpSVNI0BoLlo6WxA/tQ7XEqSbQBBC7cyPybdbbWUkck9TiZv44 h8Fz5VxXWXB4n9XVi+0mnMNelaXL/z2HNk60TcvyrGScblw4s2uLylza8BBd93AKCTQE 4W/livcJRfn51On7TIWf2oyfMuCVPC6MIL7oUlONZAuCYCp+UsGJ3+qwPSTJ7NV+LLVy abhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707517746; x=1708122546; 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=a9w16DkYUKNtIq1BB7P1j7ef4bijSTE+8L2OPdx5r88=; b=R0oI4DM42f+Tud2U6PN9HDLDDxtDJEdHHaM4jQiARG36DyNesWRS2jBKWYGWMsSaNn tHaSb0L18aO2UZcnMCvM/nMFYmKWrVPW0OQs+Wqw9sRbY1LRNAwjJgQRFvOKOx5YNGNF sZ/V37EtwhUqI+3XuvjunL3uQ7hT8J5N2BbpXnGo0mCrUpCnZXEkGA1XW+mWqtH/ToEX g4m8VDWLoGD84Y6FimR/AL5Hl/ZLM4+2CK9j1iOChYJbhlXF7Trw1vn4nG9TTeR+NzWf KRQlqpRzBCrLCANsHyZP1O0O6elsaimnVj9U01ylZ8Axd2BtUJUixUdvuiiVN6395ZWP +NoQ== X-Gm-Message-State: AOJu0YwOq+Hs+XripXVp7mlsG3YO7O+lskk98T+OaekYcH5LoxDca9X0 MrBvuK0KwztRotj2XdyhDQD2AYdyz2la6nmIZNycfE5/YWJoP8t2eqJLYdjl1WBKYI/E/TCBiio bzw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:ec9:b0:604:648:6dc0 with SMTP id cs9-20020a05690c0ec900b0060406486dc0mr161009ywb.10.1707517746491; Fri, 09 Feb 2024 14:29:06 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 9 Feb 2024 14:28:57 -0800 In-Reply-To: <20240209222858.396696-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: <20240209222858.396696-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240209222858.396696-4-seanjc@google.com> Subject: [PATCH v4 3/4] KVM: x86/mmu: Move slot checks from __kvm_faultin_pfn() to kvm_faultin_pfn() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yan Zhao , Friedrich Weber , Kai Huang , Yuan Yao , Xu Yilun , Yu Zhang , Chao Peng , Fuad Tabba , Michael Roth , Isaku Yamahata , David Matlack X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790463948162937373 X-GMAIL-MSGID: 1790463948162937373 Move the checks related to the validity of an access to a memslot from the inner __kvm_faultin_pfn() to its sole caller, kvm_faultin_pfn(). This allows emulating accesses to the APIC access page, which don't need to resolve a pfn, even if there is a relevant in-progress mmu_notifier invalidation. Ditto for accesses to KVM internal memslots from L2, which KVM also treats as emulated MMIO. More importantly, this will allow for future cleanup by having the "no memslot" case bail from kvm_faultin_pfn() very early on. Signed-off-by: Sean Christopherson Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 62 ++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 50bfaa53f3f2..505fc7eef533 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4333,33 +4333,6 @@ static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault struct kvm_memory_slot *slot = fault->slot; bool async; - /* - * Retry the page fault if the gfn hit a memslot that is being deleted - * or moved. This ensures any existing SPTEs for the old memslot will - * be zapped before KVM inserts a new MMIO SPTE for the gfn. - */ - if (slot && (slot->flags & KVM_MEMSLOT_INVALID)) - return RET_PF_RETRY; - - if (!kvm_is_visible_memslot(slot)) { - /* Don't expose private memslots to L2. */ - if (is_guest_mode(vcpu)) { - fault->slot = NULL; - fault->pfn = KVM_PFN_NOSLOT; - fault->map_writable = false; - return RET_PF_CONTINUE; - } - /* - * If the APIC access page exists but is disabled, go directly - * to emulation without caching the MMIO access or creating a - * MMIO SPTE. That way the cache doesn't need to be purged - * when the AVIC is re-enabled. - */ - if (slot && slot->id == APIC_ACCESS_PAGE_PRIVATE_MEMSLOT && - !kvm_apicv_activated(vcpu->kvm)) - return RET_PF_EMULATE; - } - if (fault->is_private) return kvm_faultin_pfn_private(vcpu, fault); @@ -4406,6 +4379,37 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, fault->mmu_seq = vcpu->kvm->mmu_invalidate_seq; smp_rmb(); + if (!slot) + goto faultin_pfn; + + /* + * Retry the page fault if the gfn hit a memslot that is being deleted + * or moved. This ensures any existing SPTEs for the old memslot will + * be zapped before KVM inserts a new MMIO SPTE for the gfn. + */ + if (slot->flags & KVM_MEMSLOT_INVALID) + return RET_PF_RETRY; + + if (!kvm_is_visible_memslot(slot)) { + /* Don't expose KVM's internal memslots to L2. */ + if (is_guest_mode(vcpu)) { + fault->slot = NULL; + fault->pfn = KVM_PFN_NOSLOT; + fault->map_writable = false; + return RET_PF_CONTINUE; + } + + /* + * If the APIC access page exists but is disabled, go directly + * to emulation without caching the MMIO access or creating a + * MMIO SPTE. That way the cache doesn't need to be purged + * when the AVIC is re-enabled. + */ + if (slot->id == APIC_ACCESS_PAGE_PRIVATE_MEMSLOT && + !kvm_apicv_activated(vcpu->kvm)) + return RET_PF_EMULATE; + } + /* * Check for a relevant mmu_notifier invalidation event before getting * the pfn from the primary MMU, and before acquiring mmu_lock. @@ -4427,10 +4431,10 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, * *guaranteed* to need to retry, i.e. waiting until mmu_lock is held * to detect retry guarantees the worst case latency for the vCPU. */ - if (!slot && - mmu_invalidate_retry_gfn_unsafe(vcpu->kvm, fault->mmu_seq, fault->gfn)) + if (mmu_invalidate_retry_gfn_unsafe(vcpu->kvm, fault->mmu_seq, fault->gfn)) return RET_PF_RETRY; +faultin_pfn: ret = __kvm_faultin_pfn(vcpu, fault); if (ret != RET_PF_CONTINUE) return ret; From patchwork Fri Feb 9 22:28:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 199144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1167420dyd; Fri, 9 Feb 2024 14:31:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3A5OmD94NOcU80Kq0GJLwbPDYipK5RVBm5fxLAfnXCRpiprJ/6Z80FOJ96dpu7bLra+z3 X-Received: by 2002:a17:902:8216:b0:1d8:cc30:bb18 with SMTP id x22-20020a170902821600b001d8cc30bb18mr600880pln.52.1707517878686; Fri, 09 Feb 2024 14:31:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707517878; cv=pass; d=google.com; s=arc-20160816; b=XCoEWdMN565eMf9n9ZpOCXXIdS0idapgqQzXrEIqGQJHpWDzUTpIyeWBIhmmgV8HUq cC/7VO8QrpwTRbHi0DrykNrMm+wxCeiZJTmaliV2cHSgWkZykpD9EWvfEL8twHXJoN42 lR7dTp9LMMiuYjqqGmHtvZGxr5VY0ZrQbotCau3NfOvE0msLX1WqmlPQerk7dUeaCHRG U33GhtyJ2hR8vvB0S76VhBNEQhsCSIauMzI3eY0C8NePgnmZKfVXsjhIOwnQPO+EuaSJ 0RgjkXDUneFDFOsk1WdT+aKJnXt/4uBmSFa5W96w2AFHymQ+jabeB+riHpwWPf/IMv6G HcKg== 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=kAg+9jSv1tP63SQt0oBxMImkHQpyEVjvNJmbkD/YeDg=; fh=fJ9qqjhQYsr+rFWwF3R/APwIrPculis9+2UyQVOWa4E=; b=Iurb4d3eM6mg+X9ki9ZmMpKBKUOhG2OQW9TJ7KYl/Aqg1PVqpS+OXEN7F0ZwGch36b Hr0omkE93GvLExjug9kCRC5Xt4ss9fyi7xpTQbw1L5I6g/DNMxTXEUQlCRvOwBZXsSCk fe2UckFkHa5JCjWTalUmNaLWgZDu9PPbdr4ccvtfJxPKxpa89NQj1yTnQMeyBeyxv3kK L6IUIM3N31zagcd4ZTWzRY5RjYCrMYUGRicGpLv5nx0sFMVnOKYjR5bH4oFcuK3yKQfr y8s1nLhPAG0thVeOuCXRSqOgjI4t+bJPrw3+bx450PQWpqJd3oEL5WuqP0xVyCvnarcQ zI4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="HiTvF/wM"; 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-60108-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60108-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCWKcsIi28cMAg7pys8an0agkGNyCmYWiqDqW1hC1NsS8q5975XwfmXhZgoufCmnWp8yaSMMDc3xnvcOOJKmx86+AZERWQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b21-20020a170902ed1500b001d8d08bd124si2241763pld.644.2024.02.09.14.31.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 14:31:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60108-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="HiTvF/wM"; 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-60108-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60108-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 49339285A40 for ; Fri, 9 Feb 2024 22:31:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 327E93A1AC; Fri, 9 Feb 2024 22:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HiTvF/wM" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 7AA763987A for ; Fri, 9 Feb 2024 22:29:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517751; cv=none; b=pkS7/SQOdJ5Zm5YlTh65NlsSmDBsMi5tPWgIrz6KpGSthA+fHdM1/5vOm+9axTBq0V2gNWpi5myS9xRQ5SG0BvdtsSoyW05ylSretp8TrhYsbFIKEjbCLAF1Z7Kl0gdaXBvgkl4pPDX4MMR/gbTJ5illvuNspnnNLYENZCEooXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517751; c=relaxed/simple; bh=+BzY1mPGL9nhkNO3V2zfL1PyIK23e4DvUb11rip84d4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LKgEpOEPTt94E9C62WgFGjaaEzH/R2ZIXUdrHwmaJdZXeIMPrttCFuEXdGq4+saX+V3D5V/djHDn7EC/U5gYzfUktwAar1t8d5aOBLKDQc+UJVHBIw8RkDORNcGZa70nXdI+SuE7jhf6Nou5rDjv56z/4K5+uwWWNWiEbWlL+fU= 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=HiTvF/wM; arc=none smtp.client-ip=209.85.219.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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbf618042daso2365477276.0 for ; Fri, 09 Feb 2024 14:29:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707517748; x=1708122548; 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=kAg+9jSv1tP63SQt0oBxMImkHQpyEVjvNJmbkD/YeDg=; b=HiTvF/wMJ7P5PXvGFeh5182hDQYnTMPqu2XnC/kbD2H2h+fKT0vWquTL7mMH+Hv7Uy d3nTW7ykXxCEd6dVYvm1DFF66h8CUFbM+UIIEQCnXwlzb2+lmT1l6MSCx7dDufCbWL5t IPMuAMQpeh5hfiMbCSYqK2DEEMnbb0cVrlvX9p88pMNAQhuYNH+bcVuzDsw5Tl2BbG7Z VhwA3g2labHdtmAn/IqpYPKjPzKf4KhBaW2IswfRxXhP0v3tp6oRU+5/fgEdQxG+c6b9 lb2xoNE4lQmwSp+esObWSP7p8xMkdQr+NJM4s0iTVv8NO80bWYKM+n+19N4QzP8ZLoA7 eitA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707517748; x=1708122548; 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=kAg+9jSv1tP63SQt0oBxMImkHQpyEVjvNJmbkD/YeDg=; b=Kon5UhINC8yzUIkbRuJTcoe1h/yTrEcZjoCcJ0JDCk1LyhtATKJRNILK+pgniNhbaU 4ZKbClEtn1la6JbQjF0NB4j+J5IGnOS31ETObIG+NU7LmC5JPxPPESypUjPKt3qGcS2A zNgnB4x5/6npIX9msAaVFo+yTc1AwNiQxjtfyWh6/DVkhKuhwCloVkixU6cbWhLx1th7 Usu23oQJdR2czO8YwGVF8FJg/LYULEb4RabxtiSR+Ie9WrWiQlKs/ox9Qg87UfFVCwH/ CICo1Hvs4uqd3jZJBxAgTAhUxlCBtinYA8ydoAinjACfk40n4uHhhEJV1pKmAdhdWX8m 03Gw== X-Gm-Message-State: AOJu0Yzh/j1VbqAJxeorIVrX20gtW5UgbUgwilXWdxOaFWQMbiJ5NuQb /YrqltbwAyA8iYvUa64YsKbisK7T19N2iAskTKrUxq0ADTapApbJmiEHdiZdug0cmFVTa0y9gSg vSA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1b8a:b0:dc6:4bf5:5a74 with SMTP id ei10-20020a0569021b8a00b00dc64bf55a74mr20696ybb.11.1707517748503; Fri, 09 Feb 2024 14:29:08 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 9 Feb 2024 14:28:58 -0800 In-Reply-To: <20240209222858.396696-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: <20240209222858.396696-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240209222858.396696-5-seanjc@google.com> Subject: [PATCH v4 4/4] KVM: x86/mmu: Handle no-slot faults at the beginning of kvm_faultin_pfn() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yan Zhao , Friedrich Weber , Kai Huang , Yuan Yao , Xu Yilun , Yu Zhang , Chao Peng , Fuad Tabba , Michael Roth , Isaku Yamahata , David Matlack X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790462266934163436 X-GMAIL-MSGID: 1790462266934163436 Handle the "no memslot" case at the beginning of kvm_faultin_pfn(), just after the private versus shared check, so that there's no need to repeatedly query whether or not a slot exists. This also makes it more obvious that, except for private vs. shared attributes, the process of faulting in a pfn simply doesn't apply to gfns without a slot. Cc: David Matlack Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 33 ++++++++++++++++++--------------- arch/x86/kvm/mmu/mmu_internal.h | 5 ++++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 505fc7eef533..7a2874756b3f 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3278,6 +3278,14 @@ static int direct_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) return ret; } +static void kvm_mmu_prepare_memory_fault_exit(struct kvm_vcpu *vcpu, + struct kvm_page_fault *fault) +{ + kvm_prepare_memory_fault_exit(vcpu, fault->gfn << PAGE_SHIFT, + PAGE_SIZE, fault->write, fault->exec, + fault->is_private); +} + static void kvm_send_hwpoison_signal(struct kvm_memory_slot *slot, gfn_t gfn) { unsigned long hva = gfn_to_hva_memslot(slot, gfn); @@ -3314,9 +3322,16 @@ 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); + fault->pfn = KVM_PFN_NOSLOT; + /* * If MMIO caching is disabled, emulate immediately without * touching the shadow page tables as attempting to install an @@ -4296,14 +4311,6 @@ static inline u8 kvm_max_level_for_order(int order) return PG_LEVEL_4K; } -static void kvm_mmu_prepare_memory_fault_exit(struct kvm_vcpu *vcpu, - struct kvm_page_fault *fault) -{ - kvm_prepare_memory_fault_exit(vcpu, fault->gfn << PAGE_SHIFT, - PAGE_SIZE, fault->write, fault->exec, - fault->is_private); -} - static int kvm_faultin_pfn_private(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) { @@ -4376,12 +4383,12 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, return -EFAULT; } + if (unlikely(!slot)) + return kvm_handle_noslot_fault(vcpu, fault, access); + fault->mmu_seq = vcpu->kvm->mmu_invalidate_seq; smp_rmb(); - if (!slot) - goto faultin_pfn; - /* * Retry the page fault if the gfn hit a memslot that is being deleted * or moved. This ensures any existing SPTEs for the old memslot will @@ -4434,7 +4441,6 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, if (mmu_invalidate_retry_gfn_unsafe(vcpu->kvm, fault->mmu_seq, fault->gfn)) return RET_PF_RETRY; -faultin_pfn: ret = __kvm_faultin_pfn(vcpu, fault); if (ret != RET_PF_CONTINUE) return ret; @@ -4442,9 +4448,6 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, if (unlikely(is_error_pfn(fault->pfn))) return kvm_handle_error_pfn(vcpu, fault); - if (unlikely(!slot)) - return kvm_handle_noslot_fault(vcpu, fault, access); - /* * Check again for a relevant mmu_notifier invalidation event purely to * avoid contending mmu_lock. Most invalidations will be detected by diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index 0669a8a668ca..bd7d07e6c697 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -235,7 +235,10 @@ struct kvm_page_fault { /* The memslot containing gfn. May be NULL. */ struct kvm_memory_slot *slot; - /* Outputs of kvm_faultin_pfn. */ + /* + * Outputs of kvm_faultin_pfn, guaranteed to be valid if and only if + * slot is non-NULL. + */ unsigned long mmu_seq; kvm_pfn_t pfn; hva_t hva;