From patchwork Fri Jul 12 15:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13731886 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 C05351741D0 for ; Fri, 12 Jul 2024 15:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720797222; cv=none; b=rWQQF6QDb21n4tSk1XEk/Mk/xuB8bbRRHiW1eLCWbeWit67B6YwHnBj/b2c58pFH0+rdDwxRW8P045SNaFaYkEXQvXUGeqilernY6M0SYMiqaJUFWnawvI78HaQVhxfyhYQRFmNu6u8ySSumP4ENKnPUD52vlkUfmRZhk2DoQgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720797222; c=relaxed/simple; bh=FMK1JNQzZMC+LLZ+NnGfOW2CO/G1iLTvC9MBzV8N/ss=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=q07cmBcvCNK5DZK9TV5Q8b4UE9LNCjShw6e21uhBt0j3FOQGs0eU99l3NPCjzS41y4Z5IbVrFuTdB3lrN4VGCX7VPBlJ/iWv3BGy7fRbBcr8R2A/r7l2hAX+tFOLUJ977d78sRaH4xFxBKebe3pGUUorY7YoWOhLLvJRqTTaMlY= 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=hkHU+PvO; arc=none smtp.client-ip=209.85.219.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hkHU+PvO" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e03623b24ddso4051631276.1 for ; Fri, 12 Jul 2024 08:13:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720797220; x=1721402020; 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=uNeBBWCFWkfC6m3nRC4ikAjguGNDe/LUsyASgE65KAs=; b=hkHU+PvOezwwEOba4ULpklfsCbN9d+iWkYw9EYM2zfI6lSoxVdZqBU0r5Plo1tuzsP YNoWUy2nQTGq/M34PjUj5lnvbRvJov8bz1kIoNksFmUkYRMqGjaPPNQNW9r+Bz5cOvwx yY9Sz4xklNaijMBDzta3bVBk8EYxtrN6pgRkKv4Fo3zo7qEOHHMG4u8McwfTpQtML33K eCu/ZM4WxWDYizhH4d8NAUaMGLXoZGkDRfobXbBHc2wAZlwDZrPLKHJIy8bD1OW8iwNb mQ6P5DOQQfj5oE8/0xzm82WWCDAMYK99WUDqDL1FB4WcsjH5eRjgsB1UoZfOiA9pltf1 EaLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720797220; x=1721402020; 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=uNeBBWCFWkfC6m3nRC4ikAjguGNDe/LUsyASgE65KAs=; b=oLszM6xFrtf9RC4hdhvhfI7XpxOzQHQ2tC5p9VDqEc/VCktcfE9mWA3GtiIX6tsNaB JVeSsloyr8p8Sex3q1yK8xYvUBIF2F05PLxUThYSwRbN6Ppfon+oFjZrsR1oWgeQICL/ OWte82w4+7aevSDf2wS+bCdpZ6/uF1aWoQDGo3OGHz0k8Z8RXLCq4Gi0xWZbqNDBxU+G Sy8YD8tComjDMu78edSNuHUBDNGgKyIZw8R9yaOl/d/qjyDEw/a4uAV1GBAgr/LgmDVS irWfIfFVPL/tF6BvbfRSgYloRUMqfbCkeywEmpbcpqSimBe0bg91k83cXssoz2SdbIS4 58EA== X-Gm-Message-State: AOJu0Yy4pVJnamqSsOS9dTcBbOQVk4W3tE4izhJq7KKd2mL0qZDikxEi R82+YP8vrLad2Ib83j8TohQAmAenbxtwc7tMLjoXIcQki+cYVrnaZh/eUaJv5CL4wNOTyeWOdNC afg== X-Google-Smtp-Source: AGHT+IFb18rrVSrijY3yb9YIXcErdEDiSDk80QlE2yIt+GQ0EP5KOyZY2pb43G390lTTX4jv/Y2p7iSY+m0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:114b:b0:e05:74ca:70ce with SMTP id 3f1490d57ef6-e0574ca77fbmr435165276.4.1720797219866; Fri, 12 Jul 2024 08:13:39 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 12 Jul 2024 08:13:34 -0700 In-Reply-To: <20240712151335.1242633-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240712151335.1242633-1-seanjc@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240712151335.1242633-2-seanjc@google.com> Subject: [PATCH 1/2] KVM: x86/mmu: Bug the VM if KVM tries to split a !hugepage SPTE From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack Bug the VM instead of simply warning if KVM tries to split a SPTE that is non-present or not-huge. KVM is guaranteed to end up in a broken state as the callers fully expect a valid SPTE, e.g. the shadow MMU will add an rmap entry, and all MMUs will account the expected small page. Returning '0' is also technically wrong now that SHADOW_NONPRESENT_VALUE exists, i.e. would cause KVM to create a potential #VE SPTE. While it would be possible to have the callers gracefully handle failure, doing so would provide no practical value as the scenario really should be impossible, while the error handling would add a non-trivial amount of noise. Fixes: a3fe5dbda0a4 ("KVM: x86/mmu: Split huge pages mapped by the TDP MMU when dirty logging is enabled") Cc: David Matlack Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/spte.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index c8fe13217ff7..bc55e3b26045 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -296,11 +296,7 @@ u64 make_huge_page_split_spte(struct kvm *kvm, u64 huge_spte, union kvm_mmu_page { u64 child_spte; - if (WARN_ON_ONCE(!is_shadow_present_pte(huge_spte))) - return 0; - - if (WARN_ON_ONCE(!is_large_pte(huge_spte))) - return 0; + KVM_BUG_ON(!is_shadow_present_pte(huge_spte) || !is_large_pte(huge_spte), kvm); child_spte = huge_spte; From patchwork Fri Jul 12 15:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13731887 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 8D3221741FA for ; Fri, 12 Jul 2024 15:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720797223; cv=none; b=fg6ySMxQsBESNO1HXJSAOGX6ymkZojjaWUA7StmaJ+EjDZJRejR1KufT2DxT1VEhiNFYoEGQgDJ0zpdf4xEOMmIkI0LvhQIAnUZUzak7eoXEjegEMidzBmF5587eJb32z8uotaM+T/ZgpwOAQl63xUh0MG+MJqHdwWok4WgrlPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720797223; c=relaxed/simple; bh=BUzUp5RWHqaySVY5+BeOJD2jf/JigFe4Y+aXQC4Sk6g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=M+ZvFKryl4pIlnCSiS1YWy++RET0J7ospyi15IAjmBX+HneorNfmBafgYdhRvFBhAOJc5+RjIqtuGcFWH935yytclyqb7uPPfgpkrUwdN3y0TUt12bD6YtOsnesXEDWVd7oY78FC8uO8Qm5aTT2/n8KjjB2aEzTSHCiFC64i2to= 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=VAaIEFTp; arc=none smtp.client-ip=209.85.215.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VAaIEFTp" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-78006198b43so1589086a12.0 for ; Fri, 12 Jul 2024 08:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720797222; x=1721402022; 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=xhil9fMKdOmNNY/hw6eHjeaj/nT3knlY7TdVcvRm4IE=; b=VAaIEFTp18j1yt0awEGjyi3hVxwnrmekeh8nwZ33E41yTegnnGTu5Is9jw3CT3TkEy hhiZSqog1H4YvrNTFi95rXfxmkgPOvMS+urUpMd4/DUOFh6NGMORvO2ZpBlsdkdc7hDQ xsdAzng7vU5ON1R1APCiraC2kcf2JKc/vF/0NO+UwIGtnRMEghjy7s06zD81J84qva9F 6+8SSl93aa2TIMQR4Lic9S69I/uP+upeyTWmVfPHc0iGNATNdd/yys5PyfoOoNAMHp2n 2y1lIDd8ILA8OGh9HaSEBibPmL176bHlG4Q4waBr8YZsHsXB4HmjjBO1wjZaF+kBA+C4 0JvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720797222; x=1721402022; 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=xhil9fMKdOmNNY/hw6eHjeaj/nT3knlY7TdVcvRm4IE=; b=P0UR9q1NBXtklkeU5PmpU2N5P+R0FDIDpbREgavMhcR2aalMlxsEzFELj9IHmsyT/O dopbc/pwK+UVrnjjoWx4MQT0FxaB6wZyFTK9mXDK3u7yG6g68b6zhYcHfgtKBO7Cv1pe TVWIgSrR7Ne45s0XRnfdr8w9DrGJq3+m3MNuOv0udQ08RP9qx7r7WMyoN+vXrVkVc4XV vJDv1edW9acU09hRUJvaiZ2Fnh/QEWPoRsBgkg+5AV2Fw+inIgFD40mWj+Gr9NAlTVL2 9QHLiYSXoZLDSpOFOgD1naDg8Rdu5+C2iV6WWBQYJPoGV0vZEuG/GK5fTIGnV6qXKviU Fg1g== X-Gm-Message-State: AOJu0YxHmqslJ5BkhWlRXxpjfnikgPEdDl/fzYLJPwxUCKHUlz8IlGcV FMRDbWwn8iTC1V+Wsw3aAius7frf1st7ywAouOYsAN42DrhJmjcXXRSUzBcjbFweFKv9IaOa22W omQ== X-Google-Smtp-Source: AGHT+IHuT8K9rOPRCiT1msZ0/9yu35XkKU/imCLWZDOybsPwvXfpkO4uEj7EHjAiqcRPow2eblVNuQyIq1c= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:3759:0:b0:6e7:95d3:b35c with SMTP id 41be03b00d2f7-77db673944fmr23291a12.5.1720797221803; Fri, 12 Jul 2024 08:13:41 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 12 Jul 2024 08:13:35 -0700 In-Reply-To: <20240712151335.1242633-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240712151335.1242633-1-seanjc@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240712151335.1242633-3-seanjc@google.com> Subject: [PATCH 2/2] KVM: x86/mmu: Clean up make_huge_page_split_spte() definition and intro From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack Tweak the definition of make_huge_page_split_spte() to eliminate an unnecessarily long line, and opportunistically initialize child_spte to make it more obvious that the child is directly derived from the huge parent. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/spte.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index bc55e3b26045..10390eecd85d 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -291,15 +291,13 @@ static u64 make_spte_executable(u64 spte) * This is used during huge page splitting to build the SPTEs that make up the * new page table. */ -u64 make_huge_page_split_spte(struct kvm *kvm, u64 huge_spte, union kvm_mmu_page_role role, - int index) +u64 make_huge_page_split_spte(struct kvm *kvm, u64 huge_spte, + union kvm_mmu_page_role role, int index) { - u64 child_spte; + u64 child_spte = huge_spte; KVM_BUG_ON(!is_shadow_present_pte(huge_spte) || !is_large_pte(huge_spte), kvm); - child_spte = huge_spte; - /* * The child_spte already has the base address of the huge page being * split. So we just have to OR in the offset to the page at the next