Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1131921imi; Fri, 22 Jul 2022 18:25:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vzTpCTcvXazhewMv+KNcS2t9offtTubR34HbQj4cDQTlJh4NPV6+gt4/D4MAqvcSrzDBk9 X-Received: by 2002:a17:906:5d16:b0:72f:248d:525a with SMTP id g22-20020a1709065d1600b0072f248d525amr1986656ejt.441.1658539508204; Fri, 22 Jul 2022 18:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658539508; cv=none; d=google.com; s=arc-20160816; b=vy8S5hNWuJJOjigRTlyCiNNyHN6k+drw/mKLmpsI2WDLIxLnoWoiM2I6CHSCO64eZb zDXv/lrw490ZU4DytXpFSn74//Yw4Dvedykt3zj8Ov45wNwYTtEMWEPAVPFDiqDbGIxR x3fcKNH3P17kRiUl7IOx5sIQc1p8mgodVcJ2fcKtLiWlPXVkFPVXMtDX8m93BXogE+vu x5K9esAW57YrbwNgNaqLWvTe6Lq5cICiXIi0CBDLxJckjUBYS+6NncNaJ9L8vF433Bq0 A86JWN/E+wljINYTv8Cv3id8nZHgc1qsl1S71422EpJh3KG+uUdYywnfZZXCcyW3papU t86w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :reply-to:dkim-signature; bh=/gYd/fZvacXV103c8Lv/rGV7oRgkLYVyY8qKay9SInY=; b=xEMVypG1smtQvD4p17NFjS+q72duFgPM78pUpoztD7RCcDohASO4tvPlz3cvpftDRy WrAnh0q/JHf9xL5RZguzKdaquhfjfeuRigsnqW6tjDVQDC4bflYlhDdzhoZR1RuhJ93n Mljc8IQ42lW/P2dtJMsQHUBUMhDMliefQ5NxyU+8Kafd/3eLZdYXdLB5XkoMzno5BSDb P2jtoBDFwY5tIRkYRoPMAK0J90nY3FEqWPNgeiBgQPPKqEnVyO6v/THIbWR44oorblIJ 3rgwnKZcn+panlyZWFDfB47WumdtF/XEDpoAcN8UH/RVYolQdR5qHP8rpUO2Ro3td7R7 Y8kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cV861rw7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g1-20020a056402424100b0043ba8911e25si8162065edb.242.2022.07.22.18.24.43; Fri, 22 Jul 2022 18:25:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cV861rw7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234766AbiGWBXd (ORCPT + 99 others); Fri, 22 Jul 2022 21:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbiGWBXb (ORCPT ); Fri, 22 Jul 2022 21:23:31 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C531675A3 for ; Fri, 22 Jul 2022 18:23:31 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id q75-20020a25d94e000000b00670834a0102so4843328ybg.8 for ; Fri, 22 Jul 2022 18:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:message-id:mime-version:subject:from:to:cc; bh=/gYd/fZvacXV103c8Lv/rGV7oRgkLYVyY8qKay9SInY=; b=cV861rw7TopdwNZfjzFLsWvW1zofCcUZDGXRFCfdk/hnh/KEKQARihawDtz0JOa5R5 +ChtrCDJJ7VytXjFDlIJ+My/SgqZYEw9LUXTHIg1pmDaXKAd0IGNocf/w5XUclYDrP5T pOUOvCSFrxYCD/vOnfzTJspdfHHho4BOrcxcWxm+INEfHiqiYCUNiL3DvcpuAeSw1H8j YzdhfxTqCT6fwvAvekTu5aAyWwxApEk6jyiKKAN6V4dii8hY6eygJlpQuY94Zqkphsym jxl4fs4F2/l40rmjHe98W1D9d+wKK20FFFLdL5WWx61V/3HGS3Ch99KtgzW8+qg2u/pw RCog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:message-id:mime-version:subject :from:to:cc; bh=/gYd/fZvacXV103c8Lv/rGV7oRgkLYVyY8qKay9SInY=; b=wqyvkUhEoJKRyViroX1nMVETPS71U6QYcP+FQoeHWExVpmckjRySFlYFooXaUD67m+ MDqGm93T1pwMgQsCvunAARNgE5VrUNWiDg8dpcKSc2pCldVWwm0OYxgHSPPF6nKamTAD WZ/u8IFYInoqMZtm7wTbyoG4Nct8Wsqex9aNz+aau0ceXenZoHSxPulDHf4BAb2o7Cmm llfuCxnEusOaRSEzKrw6PsYubRNSk0GLY6kUjDWrEivMAg0V3sbULmSFzWJUA6jDS2Gm 4lIuipnYiCt0S6fYWlhnODfI0Dddd8NvuoIUvxH/3CT3sOhbrH61TulZV/JtuD1vXTo1 YWtQ== X-Gm-Message-State: AJIora+XRPc8tupru13VxuKB5Ytk+wTIL9cKn9wVK9hSxGtiKg1nhzJD zWH3OP6T1GNQkUZgpJAW6m6V/Q/mejA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:190f:0:b0:31e:66e3:79e0 with SMTP id 15-20020a81190f000000b0031e66e379e0mr2128354ywz.331.1658539410510; Fri, 22 Jul 2022 18:23:30 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 23 Jul 2022 01:23:19 +0000 Message-Id: <20220723012325.1715714-1-seanjc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.1.359.gd136c6c3e2-goog Subject: [PATCH v2 0/6] KVM: x86: Apply NX mitigation more precisely From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , Mingwei Zhang , Ben Gardon Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Patch 6 from Mingwei is the end goal of the series. KVM incorrectly assumes that the NX huge page mitigation is the only scenario where KVM will create a non-leaf page instead of a huge page. Precisely track (via kvm_mmu_page) if a non-huge page is being forced and use that info to avoid unnecessarily forcing smaller page sizes in disallowed_hugepage_adjust(). v2: Rebase, tweak a changelog accordingly. v1: https://lore.kernel.org/all/20220409003847.819686-1-seanjc@google.com Mingwei Zhang (1): KVM: x86/mmu: explicitly check nx_hugepage in disallowed_hugepage_adjust() Sean Christopherson (5): KVM: x86/mmu: Tag disallowed NX huge pages even if they're not tracked KVM: x86/mmu: Properly account NX huge page workaround for nonpaging MMUs KVM: x86/mmu: Set disallowed_nx_huge_page in TDP MMU before setting SPTE KVM: x86/mmu: Track the number of TDP MMU pages, but not the actual pages KVM: x86/mmu: Add helper to convert SPTE value to its shadow page arch/x86/include/asm/kvm_host.h | 17 ++--- arch/x86/kvm/mmu/mmu.c | 107 ++++++++++++++++++++++---------- arch/x86/kvm/mmu/mmu_internal.h | 41 +++++++----- arch/x86/kvm/mmu/paging_tmpl.h | 6 +- arch/x86/kvm/mmu/spte.c | 11 ++++ arch/x86/kvm/mmu/spte.h | 17 +++++ arch/x86/kvm/mmu/tdp_mmu.c | 49 +++++++++------ arch/x86/kvm/mmu/tdp_mmu.h | 2 + 8 files changed, 167 insertions(+), 83 deletions(-) base-commit: 1a4d88a361af4f2e91861d632c6a1fe87a9665c2 -- 2.37.1.359.gd136c6c3e2-goog