Message ID | 20230523032947.60041-1-likexu@tencent.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1870540vqo; Mon, 22 May 2023 20:39:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7UWAFwO8FrAjpLxzQ0qBnhUG6Lv/a9ghcpFQVPjqNOgpt3g8DUZZqJRBFenmecm1cXJN7x X-Received: by 2002:a05:6a20:42a3:b0:10a:ee1b:fdc4 with SMTP id o35-20020a056a2042a300b0010aee1bfdc4mr9117381pzj.47.1684813169778; Mon, 22 May 2023 20:39:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684813169; cv=none; d=google.com; s=arc-20160816; b=AobnnzUiCcgMFgSUJPpPJAa3HeFPGuIbohgfh9/U9d6IwTI7kqDnL4gTx6TDRz1ftp FtBRJiyg/5aoNU+MFhW91yYvbGVDEI8BkBn1eBk8l7VQFUVcmUUTtHx1kWq+CSwymisD +ShuflBD8a834vTNGzNpWtHPJbEc65aXmwt7Um6A/OgB1jVLWK9SwgnE8JZHGJoTGWl0 yUkAs9+4LE7s91zeow0TtEWwsEFwvuPOyllv9GLIPueEq9sO0ag18vBcPy7v4I/GDyBC SwZHSXyRStQNRYSGO+DuSFTZejIbS/p1csvShF5PQrMiJDhdvQNm8Ybzk6fVq89WLaRH R9lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=DKMb9AmQA76fDeMluH7dncBirmnwfpNZXYIh/ojYCFg=; b=m8nXHEtkeGVWHKeWPL1kdOQ1B5WrOoZiKboP3V5XEaeh+kO8JXk27GgvFRRe3HomRr 4AimNh3t8eXOvONRbFo53WrCivsyPacrYiMuNp+zJIl5PWrLMYzE5ogDBSvpFfsNZdvD 5FnPLcci19Yd7bX8W6fBCsoAY6/G2QXu2PSe/zieKKoDUG/ECU+7jvoO9LUUK1NwpcRP /j9jxQZwBZoEYKioYpUm0/Ekx2th5gFnTwjJHCP2gEtW1zg0ePQupHncMOhEKH2DnLjs 7mX8cj93oo5ILx0CsLEHH9wUckWmCv7KJmD5LefczeV98SzQl03pEvqCEJalz0bMPsIw 6Beg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=IeNddv1r; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 72-20020a63004b000000b00528a9f56705si4054433pga.602.2023.05.22.20.39.13; Mon, 22 May 2023 20:39:29 -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=@gmail.com header.s=20221208 header.b=IeNddv1r; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232288AbjEWDaJ (ORCPT <rfc822;ahmedalshaiji.dev@gmail.com> + 99 others); Mon, 22 May 2023 23:30:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbjEWDaG (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 22 May 2023 23:30:06 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A693791; Mon, 22 May 2023 20:30:04 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1ae3f6e5d70so62813315ad.1; Mon, 22 May 2023 20:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684812604; x=1687404604; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DKMb9AmQA76fDeMluH7dncBirmnwfpNZXYIh/ojYCFg=; b=IeNddv1ru8ZPgNG+l/M77WwANktvCP9rB0pZ6K6ryPHZtCx/aJq0uXUtPXitYcQbAh WKWWlHySoYSH7AGsTkQNIasmrmAriZ1BZDfC2PvtJASPSMyIek8+B7gTl7hQZrMOZNmi xFRv1he1Q6IxNkRoaUH91avfG4itToDtwLdsOyBtVspydsS4ePi/txHckvgaW1oF6Pgz iaEIbwOhnGSO8Wm572DPkMd6wMoDe74wlPjOSJ1vzuMgUYSclmVKo01iQAtBOaQcI8eO D8mB7gH07/f3dIrfPNSqXrTEJIYPCoG49KMJ/FUxZa2W5JqHH/Hv2D9oaG+cZsiRpUap C2Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684812604; x=1687404604; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DKMb9AmQA76fDeMluH7dncBirmnwfpNZXYIh/ojYCFg=; b=DWgmj/Xo/1TQFnHp6Cflq1NTuDSJkMMlh15U6C7f/FZoLtQkUDydFgxvneXfL6nlnO bBAPis1n2sMLBZ02NfgJW8gImP5VzgLfSqGX+fy4YZUAMjpheMEUEo0vDwonT0nsTdwl 00EjtbfEsR+0m1x0CpMjJnJGXdCTgB1qS0W+BemgcDl6lY35hlPX0Q+i2Ou9yEt0MHiV VFDL5MOM5CHgJsxd4qQ0CGrhGnaMNN+zFHYaOqbRsDCl0P32Ax5/dG8+tH6bb7EkiFMN p5PWWldU9ShBpjxJvcrXEmvAAdqo1AXwnsQYtU0J/jCWX/9JyNAgea+twHz0xCsdk7kl Y2PA== X-Gm-Message-State: AC+VfDwj2PY0yehMH5U+FEs83ofn0NDbTvM5IBXK/OHr3syznqWqGlKn o+fvHxUsnlXfFoGWBjHprGA= X-Received: by 2002:a17:902:c791:b0:1af:ccc2:70dd with SMTP id w17-20020a170902c79100b001afccc270ddmr794319pla.28.1684812603978; Mon, 22 May 2023 20:30:03 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.32]) by smtp.gmail.com with ESMTPSA id iw10-20020a170903044a00b001ac2f98e953sm5527194plb.216.2023.05.22.20.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 20:30:03 -0700 (PDT) From: Like Xu <like.xu.linux@gmail.com> X-Google-Original-From: Like Xu <likexu@tencent.com> To: Sean Christopherson <seanjc@google.com> Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] KVM: x86/mmu: Assert on @mmu in the __kvm_mmu_invalidate_addr() Date: Tue, 23 May 2023 11:29:47 +0800 Message-Id: <20230523032947.60041-1-likexu@tencent.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766654654300226868?= X-GMAIL-MSGID: =?utf-8?q?1766654654300226868?= |
Series |
[v2] KVM: x86/mmu: Assert on @mmu in the __kvm_mmu_invalidate_addr()
|
|
Commit Message
Like Xu
May 23, 2023, 3:29 a.m. UTC
From: Like Xu <likexu@tencent.com> Add assertion to track that "mmu == vcpu->arch.mmu" is always true in the context of __kvm_mmu_invalidate_addr(). for_each_shadow_entry_using_root() and kvm_sync_spte() operate on vcpu->arch.mmu, but the only reason that doesn't cause explosions is because handle_invept() frees roots instead of doing a manual invalidation. As of now, there are no major roadblocks to switching INVEPT emulation over to use kvm_mmu_invalidate_addr(). Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Like Xu <likexu@tencent.com> --- V1 -> V2 Changelog: - Better to assert on @mmu instead of deleting it. (Sean) V1: https://lore.kernel.org/kvm/20230519081711.72906-1-likexu@tencent.com/ arch/x86/kvm/mmu/mmu.c | 8 ++++++++ 1 file changed, 8 insertions(+) base-commit: f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6
Comments
On Tue, 23 May 2023 11:29:47 +0800, Like Xu wrote: > Add assertion to track that "mmu == vcpu->arch.mmu" is always true in the > context of __kvm_mmu_invalidate_addr(). for_each_shadow_entry_using_root() > and kvm_sync_spte() operate on vcpu->arch.mmu, but the only reason that > doesn't cause explosions is because handle_invept() frees roots instead of > doing a manual invalidation. As of now, there are no major roadblocks > to switching INVEPT emulation over to use kvm_mmu_invalidate_addr(). > > [...] Applied to kvm-x86 mmu, thanks! [1/1] KVM: x86/mmu: Assert on @mmu in the __kvm_mmu_invalidate_addr() https://github.com/kvm-x86/linux/commit/762b33eb90c9 -- https://github.com/kvm-x86/linux/tree/next https://github.com/kvm-x86/linux/tree/fixes
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index c8961f45e3b1..258f12235874 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5797,6 +5797,14 @@ static void __kvm_mmu_invalidate_addr(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu vcpu_clear_mmio_info(vcpu, addr); + /* + * Walking and synchronizing SPTEs both assume they are operating in + * the context of the current MMU, and would need to be reworked if + * this is ever used to sync the guest_mmu, e.g. to emulate INVEPT. + */ + if (WARN_ON_ONCE(mmu != vcpu->arch.mmu)) + return; + if (!VALID_PAGE(root_hpa)) return;