From patchwork Mon Sep 28 08:30:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 11803089 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26E2B618 for ; Mon, 28 Sep 2020 07:30:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07DB4221E8 for ; Mon, 28 Sep 2020 07:30:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UmOj2XUm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726665AbgI1Ha0 (ORCPT ); Mon, 28 Sep 2020 03:30:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726380AbgI1Ha0 (ORCPT ); Mon, 28 Sep 2020 03:30:26 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 217F6C0613CE; Mon, 28 Sep 2020 00:30:26 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id u24so119627pgi.1; Mon, 28 Sep 2020 00:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SRDOrcOXo2fctkY7+23XpqsPfrMaqBHYhZz060zwT4Q=; b=UmOj2XUm/RnyvxN42kx1ehBHGEBvFHIY/zknL6770zTKMNoUrydl4/Z/5ORQASPRl0 jvrZc+IPZRom//1jSEALkM7bGChyOpxeRouaw+BpUwmR2llvqmDSCSA7K60L0Jb9Kcsd Sy+P0p5yIsUAgdvNkXhLbhxEDNrMPKjjwmCbUq4OB5Kie5/MU2GkOlSFFA8K56GHI5Qy kWKB97zYkEp1wMWXuREglQnWlrWIcIoTLPVQ1OYTfWcfC/UOPOjstpm5KD4J2KX6JR5R uwYEkXwvUxC8vBxGfRLgVU5d+oKpV+rtC73Flcr/07L0YPanwHamHQaS7xEVUXKJXpBb 9QJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SRDOrcOXo2fctkY7+23XpqsPfrMaqBHYhZz060zwT4Q=; b=jSMmN0UlLRehZJ9WxZSO0svcC866iEth/q4XUuUqCE/Fy8MGRg1WjJh6rRNEG47l2r 9kXtfXzalV61Aata/wPQbcO50X78xWZaYcRwi19GsqtBbCm+d9aG5vQDf/jW70mtwX7J 46qIUXKBTIsZhkHPMNEE8+4R8KRn4rtbHVZTmIynzHTzlBMhPFns1gqVcUrQqXVgTtZt 4AUAERGEYih1G30sMBt5RCP1vj1LeJEB2bq+qOaZY3J2X1a9brVUu54a1oXNh3ysqCgQ H+nYCQx8tlB+idgqWYn52w+ZbCpVBpw+guoQ5MD21CT1zVaBmqgeIHAo+KTYasxskjEG PWgQ== X-Gm-Message-State: AOAM532R4xr1vrcpv2Ooqrz4tOdq2egIpRdliMS3dmtzfbCb18OrELOG ZV31DNilws6nPQFMEWsD7UsxnqezQxk= X-Google-Smtp-Source: ABdhPJxny9MXVCI132op9NYkIA8MXVFiisGYHhNHNTyyqp/XYfn+gM9mGiHpfaKbSxFqjd2bdXaOLA== X-Received: by 2002:aa7:904a:0:b029:142:2501:35d8 with SMTP id n10-20020aa7904a0000b0290142250135d8mr347011pfo.56.1601278225528; Mon, 28 Sep 2020 00:30:25 -0700 (PDT) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id k7sm194840pjs.9.2020.09.28.00.30.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Sep 2020 00:30:25 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Lai Jiangshan , Sean Christopherson , Yu Zhang , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [RFC PATCH 1/2] kvm/x86: intercept guest changes to X86_CR4_LA57 Date: Mon, 28 Sep 2020 16:30:46 +0800 Message-Id: <20200928083047.3349-1-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan When shadowpaping is enabled, guest should not be allowed to toggle X86_CR4_LA57. And X86_CR4_LA57 is a rarely changed bit, so we can just intercept all the attempts to toggle it no matter shadowpaping is in used or not. Fixes: fd8cb433734ee ("KVM: MMU: Expose the LA57 feature to VM.") Cc: Sean Christopherson Cc: Yu Zhang Cc: Paolo Bonzini Signed-off-by: Lai Jiangshan --- No test to toggle X86_CR4_LA57 in guest since I can't access to any CPU supports it. Maybe it is not a real problem. arch/x86/kvm/kvm_cache_regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h index cfe83d4ae625..ca0781b41df9 100644 --- a/arch/x86/kvm/kvm_cache_regs.h +++ b/arch/x86/kvm/kvm_cache_regs.h @@ -7,7 +7,7 @@ #define KVM_POSSIBLE_CR0_GUEST_BITS X86_CR0_TS #define KVM_POSSIBLE_CR4_GUEST_BITS \ (X86_CR4_PVI | X86_CR4_DE | X86_CR4_PCE | X86_CR4_OSFXSR \ - | X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_PGE | X86_CR4_TSD) + | X86_CR4_OSXMMEXCPT | X86_CR4_PGE | X86_CR4_TSD) #define BUILD_KVM_GPR_ACCESSORS(lname, uname) \ static __always_inline unsigned long kvm_##lname##_read(struct kvm_vcpu *vcpu)\ From patchwork Mon Sep 28 08:30:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 11803091 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D0A68618 for ; Mon, 28 Sep 2020 07:30:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1B8E2080C for ; Mon, 28 Sep 2020 07:30:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uU0aG6tZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726696AbgI1Hab (ORCPT ); Mon, 28 Sep 2020 03:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbgI1Ha3 (ORCPT ); Mon, 28 Sep 2020 03:30:29 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2240FC0613CE; Mon, 28 Sep 2020 00:30:29 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id s31so96919pga.7; Mon, 28 Sep 2020 00:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hlUXKNgJlmFS9LcdYBGGvIRXhDW1V51nJ7N32WE7Hns=; b=uU0aG6tZl03pavnDsfsz9AGoXD0qBwegzcxQsET0gXBcWMOCTOdlRafnaiW9DE08/r fnl1WYBR687CFhB8TuKZSk6ezmmMcxKOtGvQXubjVRo4vO2GrrCS6ATiXsJYNp8yPV7t fxXFouKmEW6q1HAhzoG43GF2oVwNrS1uS6n+wkvC3ugMLvMzRfZPVPMb24QaHsdjhWU8 OsIIPr0Q3TstSTX9roHFZAxLALq4/6aYeNd7CypYDkw0MAhsyD41TNJftiZenuhfIhK/ JA8AIvJYbhkP5KsB1TxAiItytzwBD5FVDg6eIKOD/8z8/ArEMn5/SOn3H1dbXEfgBYGx REmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hlUXKNgJlmFS9LcdYBGGvIRXhDW1V51nJ7N32WE7Hns=; b=phvK6wCNxUwpVZbyOxa4AtLma4b+0/ins9Fg6XrTBLpJlDwV26TnM0kFAqxRdxisfZ 41Sa4TzGtz3c97HRoH3dFYKV1qU+6Dz8HLsSsORaUXRNG/Z9R37qmXY5ZeTYH2RXFoWN 3UN3neI8gvCnGALsFg7cpYavhshzH83KAAycDzP18Z87l8Ox1vkc+RGrfYHCoBdh/FBw 29Bai+CoeP2HvmO1VtMGY8JHJrIPKhanqqlUyDbS3uTWd6qDhvh0hwsm/snK1084VNIu 0bQzskqIzj58Shoh4xHERFLqxP7L2ob0d2TYwi9eTB204YmQbvnY06BpY5j2RDbAIzfV kOqQ== X-Gm-Message-State: AOAM531gpW6JM9Oa6p/MeBm5VtFHDKxz+l1bzkemWkbKHrrlIfDfckr3 bgII1Y3GnZC77cljAKKaaj166y8t2vg= X-Google-Smtp-Source: ABdhPJxafmjcVScUQe1VHQdDZYlnHWwefJg3QusPt34Rq2D0SX7ZjiF/PO7sKgpDQ413pPEqyVXb8Q== X-Received: by 2002:a17:902:a501:b029:d2:8ce6:f589 with SMTP id s1-20020a170902a501b02900d28ce6f589mr397225plq.11.1601278228612; Mon, 28 Sep 2020 00:30:28 -0700 (PDT) Received: from localhost ([47.251.3.230]) by smtp.gmail.com with ESMTPSA id 22sm469920pfw.17.2020.09.28.00.30.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Sep 2020 00:30:28 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [RFC PATCH 2/2] kvm/x86: allow guest to toggle X86_CR4_FSGSBASE Date: Mon, 28 Sep 2020 16:30:47 +0800 Message-Id: <20200928083047.3349-2-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20200928083047.3349-1-jiangshanlai@gmail.com> References: <20200928083047.3349-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan There is no reason to force VM-Exit on toggling X86_CR4_FSGSBASE. Cc: Paolo Bonzini Signed-off-by: Lai Jiangshan --- arch/x86/kvm/kvm_cache_regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h index ca0781b41df9..a889563ad02d 100644 --- a/arch/x86/kvm/kvm_cache_regs.h +++ b/arch/x86/kvm/kvm_cache_regs.h @@ -7,7 +7,7 @@ #define KVM_POSSIBLE_CR0_GUEST_BITS X86_CR0_TS #define KVM_POSSIBLE_CR4_GUEST_BITS \ (X86_CR4_PVI | X86_CR4_DE | X86_CR4_PCE | X86_CR4_OSFXSR \ - | X86_CR4_OSXMMEXCPT | X86_CR4_PGE | X86_CR4_TSD) + | X86_CR4_OSXMMEXCPT | X86_CR4_PGE | X86_CR4_TSD | X86_CR4_FSGSBASE) #define BUILD_KVM_GPR_ACCESSORS(lname, uname) \ static __always_inline unsigned long kvm_##lname##_read(struct kvm_vcpu *vcpu)\