Message ID | 20240228024147.41573-10-seanjc@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-84435-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3099076dyb; Tue, 27 Feb 2024 18:44:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU/deNmlSQiD/RhsvyAxjAy3XLHcrrpyaNIoVMEXHMQb+8PBZPVq52H37Js2pZWtmQk7QfrnKUX7xdzVnf1bO3YzhyXvw== X-Google-Smtp-Source: AGHT+IG6tuR4syJCgZHgcQ/JcRYyxLpFbHzfQY2iz2NjhZ/zbpCqej0EaoMnp06aimvFnwd+dTmC X-Received: by 2002:a81:5751:0:b0:608:8f31:244f with SMTP id l78-20020a815751000000b006088f31244fmr3610507ywb.51.1709088291273; Tue, 27 Feb 2024 18:44:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709088291; cv=pass; d=google.com; s=arc-20160816; b=GJMTCJxz4EBvFANJC12e4ZPGVbTumsIo00t0AVqWptYoyDuUi7EfRCun74SksRkHuU mqX1USYYLb7l8Vh++vxtshHccKUuXozCsEeoT9kDFHEXobm4Rp0Zz2PcJjKdwPwSEesa XSTtxuvhr8+cL/MmEoMbRGWAXFqzZqEQYoRqIJnwgLNbDsfMYmAcqKHaWPqhBfduif7A BFqefWVUPeZA0ceYLYCo/7skH/vHhLtpVO/ylxXXWBue0uxwp6aW9bK2K47ZH2L/whxs u2zjrIWbzfJpi84Pu+KNQr8ObxdA5WysouUuNpbBr85Qmg/W9Yg5RRDyIPIR9YG2DcPq 5CsA== 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=DGgOzzQ1+jAk85gp0p6D7NJFf1xx8C5oqxWRvpff3B4=; fh=7jDWF/UM1LlrxPxvaHODlH28g+xHrel/EJFPMjk3mAw=; b=gga2T8FC6d3YSVem9c4BUhEqjeMZfYcaoW4D7/qQaw2wYnm1ngcp2xHHbmLeXc56op As43TJFgLCy4rtUwKtePdoqgmFlfnsE8fQG/16vfQpdoGFbnHm1ZnbD+ekpBIq4lcN+K 09iCVmYDSx9NoSyJ0RgHlPTkq44/2YbHYs9J12LHAFCoATj1xNOry5RdHSU+MKzNDkzE 378Ub7QCIXVqlcx57rLiLMlPD0Sj06UvhyXGGJcAdF2clMMgOctfOwMuOkazltg9aZcB HHHopj0WC/D+7O38gijKsD7LIVrHqz64MC2dsUxHIilDrRHU77YbD2XlZYGf4nNXQeTu R09w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jm6G4Zku; 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-84435-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84435-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 f18-20020ac84992000000b0042e74b6ff6dsi8180645qtq.80.2024.02.27.18.44.51 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 18:44:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84435-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=jm6G4Zku; 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-84435-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84435-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 156BE1C2643F for <ouuuleilei@gmail.com>; Wed, 28 Feb 2024 02:44:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5415C2C68C; Wed, 28 Feb 2024 02:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jm6G4Zku" Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 C26072561F for <linux-kernel@vger.kernel.org>; Wed, 28 Feb 2024 02:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709088129; cv=none; b=R/IxmF0gNPnDojD3uRspaxKqA8k1ArLGOwKfXsln+NU9YZ/Y27TsqrKwppQ5vb1AHUarsCLLFv3TauZ2NK/hyr3v6Nx204vYqafxc/wnHvz9hzfp6ujNZLegya2aZlcmsku/gN5BXaQw7ArnrtKklepIpvPlycGv8G+Ng+1JNfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709088129; c=relaxed/simple; bh=wTukbFZz6gTZ0AuLeXiBHYZaq0ngrSizsl1vey1TzwM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DUi8eSeRfjv2zPN3hF2iu3mq9zJ2XMwaoTWvFKNoo2LySr+Nr2+OQHlNqq6zBfwaaA3p5g4Dlf5Q01OvQRlx+RiUqb5W3ORAAusR3QIGXRRsXG4lwmvLlPOyK2Fu0n02pQnuS8AMknzR8jGQz032Qf+L1l7/50TwH6CWaoF6TWA= 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=jm6G4Zku; arc=none smtp.client-ip=209.85.214.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-pl1-f202.google.com with SMTP id d9443c01a7336-1dbe3ca6bb7so3200715ad.0 for <linux-kernel@vger.kernel.org>; Tue, 27 Feb 2024 18:42:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709088127; x=1709692927; 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=DGgOzzQ1+jAk85gp0p6D7NJFf1xx8C5oqxWRvpff3B4=; b=jm6G4ZkuHsVYDoi4cc6dCfEHacaybn5wOU3GFpqSoz0boWYz0rUoOTFsbvU5/zfXd0 9M0JoaglZ0aT73cxmH3uR3FSrgqkThm5lG9ERhNuwGS1OyKsU3ufBa6wS8ShddvU3jIn os66jQ53NyvLRaYb65w9sLeU5HLz9IQZ8tcD2aETaYgecfgPrGbQDpQskq5i7l9n51I0 lXOlR4uR89lBzOl9zitud+SKEiEVDVKjz9DbjmD7zlYvPXCbVV6wQWjCrCAYTe424T86 sRdpoqBHVziaSbFkTw3qA3txAHoHenWoDU68M1OggvH+elix3TCsIkxObKeRE0u2bzO6 Sucw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709088127; x=1709692927; 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=DGgOzzQ1+jAk85gp0p6D7NJFf1xx8C5oqxWRvpff3B4=; b=bnEzpXubC3oc1bpMWEpfBLDySXv99wwBRwI4awCbjSxDubgy5mCkibwapcGm9Eycxq rlxq2LLAlZJwpVxclShRbkVjbL0YRHJ4KLdWjsGmroe5unD6dMT44ILM6fJv+QrUsEDN Y2hxTcPMd5RHegvUUCB7dG33skmfFSHEANWoMmt8n7YwNNgaHtAG2dmjCuAWyBaDE0n1 33/jgj9tkc2XgDt/Euj52YsbBIBFBa4uRApFeMv67+X5b9xIscCsQ/77E2HLZBv45/rG FgvdPzYvTFjtSYl354+wORuOHHJ4lSFybV/BgFU92o4DjGECWIlDia2XN8C96P5nDhFo gZqQ== X-Forwarded-Encrypted: i=1; AJvYcCWykJMSxiy07cqUToHTeNv/mRyFld3TA3F44zbqCM3u85rgznniIhhjyEaNLw/7PdPcZz+NNURovAKpfQwlkAziZ4KePtNIEbzHP+yo X-Gm-Message-State: AOJu0YwRAYKf2mJlun9hJqtz+w1BW4JJkVy10EGhNjY3F8ox20H0+6QT hBWY28ttEok++TQh9j+2k1C9lwR2RL9Q7U4G68U72yLSlnheM9WNd+mEWpgq/gt7ZG3KNolNylp Z5Q== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:d114:b0:1dc:68a2:2cb6 with SMTP id w20-20020a170902d11400b001dc68a22cb6mr2554plw.6.1709088126987; Tue, 27 Feb 2024 18:42:06 -0800 (PST) Reply-To: Sean Christopherson <seanjc@google.com> Date: Tue, 27 Feb 2024 18:41:40 -0800 In-Reply-To: <20240228024147.41573-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> 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-10-seanjc@google.com> Subject: [PATCH 09/16] KVM: x86/mmu: Move private vs. shared check above slot validity checks From: Sean Christopherson <seanjc@google.com> To: Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com> Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yan Zhao <yan.y.zhao@intel.com>, Isaku Yamahata <isaku.yamahata@intel.com>, Michael Roth <michael.roth@amd.com>, Yu Zhang <yu.c.zhang@linux.intel.com>, Chao Peng <chao.p.peng@linux.intel.com>, Fuad Tabba <tabba@google.com>, David Matlack <dmatlack@google.com> Content-Type: text/plain; charset="UTF-8" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792108963953596366 X-GMAIL-MSGID: 1792108963953596366 |
Series |
KVM: x86/mmu: Page fault and MMIO cleanups
|
|
Commit Message
Sean Christopherson
Feb. 28, 2024, 2:41 a.m. UTC
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 <yu.c.zhang@linux.intel.com>
Cc: Chao Peng <chao.p.peng@linux.intel.com>
Cc: Fuad Tabba <tabba@google.com>
Cc: Michael Roth <michael.roth@amd.com>
Cc: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/mmu/mmu.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 9206cfa58feb..58c5ae8be66c 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4365,11 +4365,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); @@ -4410,6 +4405,16 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, fault->mmu_seq = vcpu->kvm->mmu_invalidate_seq; smp_rmb(); + /* + * Check for a private vs. shared mismatch *after* taking a snapshot of + * mmu_invalidate_seq, as changes to gfn attributes are guarded by the + * invalidation notifier. + */ + if (fault->is_private != kvm_mem_is_private(vcpu->kvm, fault->gfn)) { + kvm_mmu_prepare_memory_fault_exit(vcpu, fault); + return -EFAULT; + } + /* * Check for a relevant mmu_notifier invalidation event before getting * the pfn from the primary MMU, and before acquiring mmu_lock.