From patchwork Fri Jul 12 17:00:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Jackman X-Patchwork-Id: 13732005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5D90C2BD09 for ; Fri, 12 Jul 2024 17:02:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AB1B6B00B9; Fri, 12 Jul 2024 13:02:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20D1E6B00BB; Fri, 12 Jul 2024 13:02:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F044F6B00BA; Fri, 12 Jul 2024 13:02:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CE98C6B00B8 for ; Fri, 12 Jul 2024 13:02:02 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4DF2FC0AC1 for ; Fri, 12 Jul 2024 17:02:01 +0000 (UTC) X-FDA: 82331718042.27.55176CE Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf11.hostedemail.com (Postfix) with ESMTP id 52D494003C for ; Fri, 12 Jul 2024 17:01:59 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IN6Fv3uM; spf=pass (imf11.hostedemail.com: domain of 3hWGRZggKCMgxoqy0o1pu22uzs.q20zw18B-00y9oqy.25u@flex--jackmanb.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3hWGRZggKCMgxoqy0o1pu22uzs.q20zw18B-00y9oqy.25u@flex--jackmanb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720803703; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LtvK59wkpmv96YBPTwdu+UmQnFP5VkAZYiTxY4Mh4uQ=; b=wanuE70s7BEATPSm5z3M68713Rg06w0HdvhZWVC/mqj3ZtyUFqtPrsnTXYN8UgUvl17AIj vLUimMUpCSLytlfBHnFxRn+AV5jD4okizD3oT9857auT2POrMAkmEc3VD7InCy9Qpy+kOt /+qn5W7EA3uzkYp+WPPK1qtUrEhNpQo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IN6Fv3uM; spf=pass (imf11.hostedemail.com: domain of 3hWGRZggKCMgxoqy0o1pu22uzs.q20zw18B-00y9oqy.25u@flex--jackmanb.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3hWGRZggKCMgxoqy0o1pu22uzs.q20zw18B-00y9oqy.25u@flex--jackmanb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720803703; a=rsa-sha256; cv=none; b=xSSgyuoQPay7VpheRrujCZFpMzZ5l4NhB/u6ikJtpfJukTCvi9dw/Fye3BP9/19H15Y/0f 2LlTkbZx3j4I+VLH8AAhA7IZ/crbq3u9XYFBijwC1CX/YifglfWRwClTOty1CHUzf7Al7T ulOMiKozDu2WDAdxh7uHJ7SYh92kldc= Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-367960f4673so1771696f8f.1 for ; Fri, 12 Jul 2024 10:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720803718; x=1721408518; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LtvK59wkpmv96YBPTwdu+UmQnFP5VkAZYiTxY4Mh4uQ=; b=IN6Fv3uMAS72pBSelDk0+TBW/1wiDu0DSgM80YQsO17b5kbaEqxMbHaQ6+o8fdWkmE JC4XZJ0Zb2OZqA88AzfvHWHauqLg2jYD1qZeXNUbUPGgC1EKgSZvFzw2FfCAy9+kj88U YdJj5vagCUA7/vTGzYKI6Nk60kpgknoqKjTOtnzNUhms2GXAM11z/9pxdu8nont454Dm 6bqSKFqsFAG8aRE+kKB2Ly43Zc1mpnxg9zO9gZEU4lLGxnP/+6DFNFubWXtDad4AA5a3 XndddP5Up3FWNJxCgWz3pdG+otzASADZbUwR/C4hqz7j9Z67lkBgugI1Bji/CaAInGEW 79oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720803718; x=1721408518; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LtvK59wkpmv96YBPTwdu+UmQnFP5VkAZYiTxY4Mh4uQ=; b=ATRBLBonPQW9LY1iK4wc9RfAvBiZG9QDhnP7AnN1f2/EYmmn5N5qf7JlZLbyyfIbJH 2fVwHulCK1gjgqDwsvnkVgeTTLDx3O6TZxiDXYqeYg7A7cQpMrF0NReBTrRXAkvO2akp hTvalj9jQTmYXQ01lR5eKD1XSKzLruNV4E6HfvOB7dGlWmrd5K4hCvYdngOqo/UV1wM+ +sBqgbICcufeTOYbygmS9qi/g8w51Gx7TZTlOcsGNhgY3UuUWxGtcBt9omPLTxeXRP/5 JTE7IEQ/owfFKxB99ZcZuvieXFm6PWLZKZ7MMIaILe6TKBBlpIb7Q9VGIs1UJYlXDyR3 U2+g== X-Forwarded-Encrypted: i=1; AJvYcCWrkrfPwKdueSyuG2uibnl/+/+joeSCD6nS7vfWRmqv/wr2qWzwNZwS9601TzPyvrXGoV6OXTUZU5UxnCw8VBlDjps= X-Gm-Message-State: AOJu0YzqRI9kPjcfuzNjOv3zJEFFtW/pHRB7m50oNny/haN22p5h8S5g cmohIOtINY3NGd6cpHRNxT3nWy/BRfHYctcAOKfNVwEEjfrCa2Sd71erMWJBouiJrwxjRgTRfXT 9K6IYNRbi+Q== X-Google-Smtp-Source: AGHT+IFpeHjscoHoV+i7b46AZT6D1f9aKe2Nj5oFbdtPCtyqFA2ot3+sTCgSvjfbQ/uIAyhmtnXZfQlaZ6B1Pg== X-Received: from beeg.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:11db]) (user=jackmanb job=sendgmr) by 2002:a05:6000:2ae:b0:366:df3f:6f98 with SMTP id ffacd0b85a97d-367ff696f10mr6916f8f.1.1720803717468; Fri, 12 Jul 2024 10:01:57 -0700 (PDT) Date: Fri, 12 Jul 2024 17:00:40 +0000 In-Reply-To: <20240712-asi-rfc-24-v1-0-144b319a40d8@google.com> Mime-Version: 1.0 References: <20240712-asi-rfc-24-v1-0-144b319a40d8@google.com> X-Mailer: b4 0.14-dev Message-ID: <20240712-asi-rfc-24-v1-22-144b319a40d8@google.com> Subject: [PATCH 22/26] KVM: x86: asi: Stabilize CR3 when potentially accessing with ASI From: Brendan Jackman To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Sean Christopherson , Paolo Bonzini , Alexandre Chartre , Liran Alon , Jan Setje-Eilers , Catalin Marinas , Will Deacon , Mark Rutland , Andrew Morton , Mel Gorman , Lorenzo Stoakes , David Hildenbrand , Vlastimil Babka , Michal Hocko , Khalid Aziz , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Valentin Schneider , Paul Turner , Reiji Watanabe , Junaid Shahid , Ofir Weisse , Yosry Ahmed , Patrick Bellasi , KP Singh , Alexandra Sandulescu , Matteo Rizzo , Jann Horn Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, Brendan Jackman X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 52D494003C X-Stat-Signature: 4c59easnqs98keitu5bmkopjwppnbcfp X-HE-Tag: 1720803719-284027 X-HE-Meta: U2FsdGVkX1/iTF/PztUZ53ajh4hPbOjMSxA2A1t/4pdrM2Ed/RbEL+5Pe1Y6a9c0kn3Ss+qu1fEMMgrqJot3FFxbo5iNRw2TCFUnzUsSGS6HBF+0WYkFRrpDmPAHpk3kqwEDrtAZlixA2vjtpom8rDCS2LOhE7ndj4zNTyZhwEL6dhLxrVQILRJk7iog70P5w4F4I2DhH7VDSgHDGzTbKaNz5YWVj6CRYfNil9I3OFfOIxtk5YYuhwABMhy2cl/TkTfbp9TKOZdzHD7tt9t8WCVYSlyGwq/Htzbbrc0d5syInNgzl9zFEJ1FteNefKS7PKGOrhcCPhdUjq12ZjXRlgg6euYHM8/7pI2EiXl3BHfY9iDB1DFuwx1JJim5Fal5M0Dcw2mYFNUOZ6q83GHMNftgf+Onq9NC5ohCecAAbA3AVV7VbhYc57rZ6IxqDRDE09TFrYObJQ7OrQWqcpcJHhCL6lqmEXNsL6UZLyTf4HGjIBgBpfc3Q/JQxfwCqxrjYYMY8QCs/vvDOu6WJ9JCX+/cGrP6kCo5I9DX1eCcbP9eIi+OFN+nrfp5Q6bOro1oN9dBYA0H86uGRl1LI/1QACYZWUjUDfkPpAxGWV0sLDDRT8LpYkq/M6edu8iKo1NKkCEELy7SOjoZ00CorICIjOq5jcDnGWGhLZOFQVlgut4+Yp9/O5RJIwj4vcHAMbUFAkcwPDN2uKy9Je9b/Ck1E1Do2zrZhhUYOeLn2Jg4oAGoEgNnr2KOIaFO5ZKuKZ2dCtMw8kfAMRvvIBGQe6VkH1n33nY88BTjH4PqPElvL4dFKJUZXzQDLQFoOe8RDrky7FOINfZgmEFuh8FW4ur+Wdx2OLyAdEUz6fVFk4BNsOODE33YtH7ZqQ3CRW28Yi5NBXt4B2qYxJcpxGzYcNGB9ANPg+3zqawFK6bZSFTJTOOIKffliomQm15d/nC167GyoiveW3sOxuUVTaiziGL mZHNt1ap CzLdZ36caufFyOQ8HLxsLVoMxZiKK6qR4sBRHvemwImgy3RhUM+plyX2aU87/y0rn4FRa4x0mpfAo6OtNqqPAaod7nZbMGGvVw1MeEaG4kFGyVYgjgb3fWJV1juBRTYiGjrGFfzKb/rRhkal37JY0/GP6jtFMCMewh5VNzpMrQ0GQYgYfk0n+Obwp1g/qJM7KLm0z8fJwPiOPdN6dcnN2fXtymF/hXudjr7P3TzJRk4PeEY1E4QLreKftpRg4vXILwFMVUB1K65w3LuOp5k5U16q8vgyKVxOHXvXEvgo30Wem4IlJQk3f1MtDHseLufFEOHL7hvV3Vpem5+fhGYiYbwWZF5XzjEEFMRNwfPJczt9R7gntqoVRGZtb5wtFfSuDDewhHdBbXyvaJYRzJUaf5lqMWPbE/Rwoj4wgbiIv88Ri3hskck8kg7oj13LzDsEOQwopttJ+Gw7WHDD+ENjVVnIQ6htudB8r57QCTuCWy4FBEpni3pRjnUt3AAWqBRqUWC/IA25yz1G5vCkozvjRyN69cjtdaZBO5IwV X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: nested_vmx_check_vmentry_hw() does a VM Enter as a "dry run" to check the VMCS. It's important that we VM Exit back into the correct CR3 in order to avoid going out of sync with ASI state. Under ASI, CR3 is unstable even when interrupts are disabled, except a) during the ASI critical section and b) when the address space is unrestricted. We can take advantage of case b) here to make sure the VM Enter is safe. Signed-off-by: Brendan Jackman --- arch/x86/kvm/vmx/nested.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index d05ddf751491..ffca468f8197 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3147,6 +3147,14 @@ static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu) */ vmcs_writel(GUEST_RFLAGS, 0); + /* + * Stabilize CR3 to ensure the VM Exit returns to the correct address + * space. This is costly; at the expense of complexity it could be + * optimized away by instead doing an asi_enter() to create an ASI + * critical section, in the case that we are currently restricted. + */ + asi_exit(); + cr3 = __get_current_cr3_fast(); if (unlikely(cr3 != vmx->loaded_vmcs->host_state.cr3)) { vmcs_writel(HOST_CR3, cr3);