Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp932929lqc; Fri, 8 Mar 2024 17:10:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUmXNQIfTRsW3edU3phI2pmytZiN0xVMZfaBY09ulYlpA6BPKDOhe611X0hBO+2qepFlMBKar3bgLUfcawxfkn2FAOwStipO5nEs0pUig== X-Google-Smtp-Source: AGHT+IEnn5YjUHpvbm7tRULEBJdWE4hgFQ8qT+YPxl3XcMbwE4r9A+e2Hmw/P6gvLWkQ1DrF1ovA X-Received: by 2002:a05:6a00:1784:b0:6e6:265d:e787 with SMTP id s4-20020a056a00178400b006e6265de787mr806808pfg.25.1709946605950; Fri, 08 Mar 2024 17:10:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709946605; cv=pass; d=google.com; s=arc-20160816; b=RrQbVqijr45znyTHLynxsQVYNWeyVwj1sd+U2O9/MeHCkf75ULQKYKjAUp1Wyv0abY EHmureHvRs3nRXgrgjKtlzbOII2WT+1Ou/YXOEqEjcS8haL3zsPBs4j4FY6DOPc/fEFC ES4sO5XDAvKQT9Ml5oZgWXTZHkkZo7IVaL1ykJx6oQqC+IlIppBwrUvQ92WpgV6pkM7W yBm6lpQvC7tflS0aI2FP4kQFRmNkOeMM3rMkEXZSjs5Dvyjyq5SZOJuvsUd1kqsvcq/R u9AVEywsQnztOhqhDkzjxIGxyiC84dAtJs7PdxuJYJY7pTq4rcb8X6tDfAvI7mj49Eas oCRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:reply-to:dkim-signature; bh=/DWrZ/Y6O9dtVdJ6fn791rDIK6aHa8oXbKQewTP1zRw=; fh=WYa8ZyBPSBtJbV0Wm/ACt9HbUXj8ehV6/I3aGEkXiag=; b=VjQuhrtn3lmoYa4Kc6JVsfB4nLmf08WWvTyVILkADyjuTT+edhWvf9syDFQrnQJMbE /7CZhCKQKYt9RiWWrxwqUunGTeLSYbMozIu2OOmjYfWo+wcNehHT5AAITlhjIxkJNvhX vsy1jxbh/v4abNJgOIuwTuDIErIcML/bzgXitXkYiobAaW05VO+wH9x/SHqapkh/Hd7E WXWN5RJaGxnwmw7KzRvL+ajevAP0Gn/txrGVDGaS3uHxVOvlriE3Ibn1WXPqEZHVgWhQ 9jbfMDvXhLS7Tb1giLaSjLJB6nzgBBsMaQU/YiNAIvfEumoTbQjY8kHcx6yGl0S0jnZj HSgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qwJhfx5Z; 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-97718-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97718-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id fd11-20020a056a002e8b00b006e63eb52befsi642068pfb.92.2024.03.08.17.10.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 17:10:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97718-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qwJhfx5Z; 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-97718-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97718-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D199EB21BC2 for ; Sat, 9 Mar 2024 01:09:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7050C185B; Sat, 9 Mar 2024 01:09:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qwJhfx5Z" Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 28BB5A29 for ; Sat, 9 Mar 2024 01:09:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709946576; cv=none; b=cqw9paI2Rt59fuGm4oCwv9k6CNZaeJp8zohsOe18qaWzCGSMP7gxgkX6nk434gJAU6E5veEFPeDeUTIN90PNohNOS3N94cytICxE6+FqDAQ8J21pbYFiqkm1h96jhWicDhS6fQYwC3WhDZA1l5l5VRsHjVuIovoJWV1WpHWBlFE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709946576; c=relaxed/simple; bh=o/dHrg4W/2Qu7LhXHcnBR4PyxF3Ttwy46Ocol2kgU+w=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=ZmARX1M1MamcKVUtTNvVuInvM4tKdhG7N9npzvXGRm/G+gsEJrMITWFgR9YnGdo4YR6vSEbG4Z3BSD4yRIkIGOoKtiSrQhKgReg45JqHEjynJDT/vmzKVL4qozdk4A4HtA6EjMXmnE14nbbjeRA5V4V6ywNXys8etLuY0pGULdY= 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=qwJhfx5Z; arc=none smtp.client-ip=209.85.215.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-pg1-f202.google.com with SMTP id 41be03b00d2f7-5d8bdadc79cso1096039a12.2 for ; Fri, 08 Mar 2024 17:09:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709946574; x=1710551374; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=/DWrZ/Y6O9dtVdJ6fn791rDIK6aHa8oXbKQewTP1zRw=; b=qwJhfx5ZH2VDMhdp6veR4n8SnPSYw+A10yfBjPkKl8gnpu+uXtrxox1G+WcT2fJgCy HFeAg3GjlQS8uy+d/gF+tYLm8FPHlmYk+opRK5tRtHOV6XhuIJS6fMTJksw2pep1Kt0d 7xa0wWuBq6Oux0DeaJHlc2j2QV2aLFgJGOAmlhLE3MEiKsfQecLy5xhQGr8kkPDQFapE Svo0rncoqbW5rzkLpPJEjenaiaZNT2bxuOySOK9CCvClJB1aI5QqccfENNpgcbLGgcuv iCXFVcSl9yDcL56Ak0SbXw7MQV3t4r93F63QIfHq7WqUvSYzOOwRQ6eRg02PnN3/quRv Tiew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709946574; x=1710551374; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/DWrZ/Y6O9dtVdJ6fn791rDIK6aHa8oXbKQewTP1zRw=; b=UsVzbQzjyVgV1eWTPaFK8VwI5u/SedqWWsgseM13l/EvpAGGAMqMbyonEAO5Ninhoo KIYWVyWgoFkQro5npAjjbsuxtOGLMfYjapQpsTZfiA4obvWDZ02X9hNJ/1MvGwjrI8XZ A8GG+Rha859xTjuie06Tu5m7rf5IzzP9XlBQC/bliHiKhQSLMQUojQo5D7QtR4DuIfVe eEwFlY7mi4V7tV6r0SeRVNHuhz/f4Lv5MA2/Ppco/IfuMju7jVHXH0qkuyQXTMEWyNAW gOaOaJRKYMWTsEs419ALvV45Y/7UV9Ux2HUCaqx2izW/hMqBYoDEoxtRlY5ETOS7VhMk R5Jg== X-Forwarded-Encrypted: i=1; AJvYcCWGqaGfM/PDmOV2s4h9NGZvM4z8E2gIHlHnnLkgPXoV5IB1c4ZBBHNOJtpkw5RXWF49163BGUNeD6ipCwpPDuPTRiJnoNAZwE48KKDg X-Gm-Message-State: AOJu0YzPjk/yR13EOX4oRVW2ZG70H/ve40rq63vxu4gHMjgSIGl3cpwk u3eVV5u1BZcwxZm0IGc7cK9mFIm3M15Nma/4ZejGdBLD+GLv4MM+tUXzXNecc51/4r8TkwJi25r Ung== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:5347:0:b0:5d5:e46f:d39c with SMTP id t7-20020a635347000000b005d5e46fd39cmr1463pgl.12.1709946574438; Fri, 08 Mar 2024 17:09:34 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 8 Mar 2024 17:09:24 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240309010929.1403984-1-seanjc@google.com> Subject: [PATCH 0/5] KVM: VMX: Drop MTRR virtualization, honor guest PAT From: Sean Christopherson To: Paolo Bonzini , Sean Christopherson , Lai Jiangshan , "Paul E. McKenney" , Josh Triplett Cc: kvm@vger.kernel.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org, Kevin Tian , Yan Zhao , Yiwei Zhang Content-Type: text/plain; charset="UTF-8" First, rip out KVM's support for virtualizing guest MTRRs on VMX. The code is costly to main, a drag on guest boot performance, imperfect, and not required for functional correctness with modern guest kernels. Many details in patch 1's changelog. With MTRR virtualization gone, always honor guest PAT on Intel CPUs that support self-snoop, as such CPUs are guaranteed to maintain coherency even if the guest is aliasing memtypes, e.g. if the host is using WB but the guest is using WC. Honoring guest PAT is desirable for use cases where the guest must use WC when accessing memory that is DMA'd from a non-coherent device that does NOT bounce through VFIO, e.g. for mediated virtual GPUs. The SRCU patch adds an API that is effectively documentation for the memory barrier in srcu_read_lock(). Intel CPUs with self-snoop require a memory barrier after VM-Exit to ensure coherency, and KVM always does a srcu_read_lock() before reading guest memory after VM-Exit. Relying on SRCU to provide the barrier allows KVM to avoid emitting a redundant barrier of its own. This series needs a _lot_ more testing; I arguably should have tagged it RFC, but I'm feeling lucky. Sean Christopherson (3): KVM: x86: Remove VMX support for virtualizing guest MTRR memtypes KVM: VMX: Drop support for forcing UC memory when guest CR0.CD=1 KVM: VMX: Always honor guest PAT on CPUs that support self-snoop Yan Zhao (2): srcu: Add an API for a memory barrier after SRCU read lock KVM: x86: Ensure a full memory barrier is emitted in the VM-Exit path Documentation/virt/kvm/api.rst | 6 +- Documentation/virt/kvm/x86/errata.rst | 18 + arch/x86/include/asm/kvm_host.h | 15 +- arch/x86/kvm/mmu.h | 7 +- arch/x86/kvm/mmu/mmu.c | 35 +- arch/x86/kvm/mtrr.c | 644 ++------------------------ arch/x86/kvm/vmx/vmx.c | 40 +- arch/x86/kvm/x86.c | 24 +- arch/x86/kvm/x86.h | 4 - include/linux/srcu.h | 14 + 10 files changed, 105 insertions(+), 702 deletions(-) base-commit: 964d0c614c7f71917305a5afdca9178fe8231434 -- 2.44.0.278.ge034bb2e1d-goog