From patchwork Thu May 20 10:22:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: thermal-bot for Julien Panis X-Patchwork-Id: 444302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED264C43462 for ; Thu, 20 May 2021 10:24:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5F7E6135B for ; Thu, 20 May 2021 10:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235714AbhETKZ2 (ORCPT ); Thu, 20 May 2021 06:25:28 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:45948 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235967AbhETKXt (ORCPT ); Thu, 20 May 2021 06:23:49 -0400 Date: Thu, 20 May 2021 10:22:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1621506139; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZagrcgFZectxiy1/3uvyt0uDezedS074rlpmvxtY4DQ=; b=3xIo7UEBmxMtMQMX9TaUhsqixau3Gxed2cR9o93+FsABTxjKWV4D0fTQTHgZ9upt52Pw2w 7HmrLfYBh8AjHLrbYtG1ARiutxSyHqIfIdsaYyTah5eq5Ir7mgCubkuiGoTI23mC7Rr01G afFURpA1zi2PAIJli/YG9vzyvyqW0FV4cDOCUdkdKz7tJlyuw0HvVsQooNZBaU4ggYEGkA CTbUPnvkCad9rf1YOOkDkAP3qecdL5nO3YMmPDfCV+sv4TWyaYvo7J+9G/rvEAhT7y1Pol ewJWOYgj4I7lJ6B/oDFrfGAt/GVt5X7QRElDeCBrKWUPqIPfIxnAknEl8s3OfQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1621506139; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZagrcgFZectxiy1/3uvyt0uDezedS074rlpmvxtY4DQ=; b=StpVGhK6ppJzC7yhwHmDjzySzTZE3rh3j+Tw995QL7ZfjrJJ6jvjjwjmSLTUnZ690wTf1A q/ztyKV5FzuhmcDg== From: "tip-bot2 for Joerg Roedel" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/sev-es: Forward page-faults which happen during emulation Cc: Joerg Roedel , Borislav Petkov , stable@vger.kernel.org, #@tip-bot2.tec.linutronix.de, v5.10+@tip-bot2.tec.linutronix.de, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210519135251.30093-3-joro@8bytes.org> References: <20210519135251.30093-3-joro@8bytes.org> MIME-Version: 1.0 Message-ID: <162150613865.29796.2348311879608249315.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: c25bbdb564060adaad5c3a8a10765c13487ba6a3 Gitweb: https://git.kernel.org/tip/c25bbdb564060adaad5c3a8a10765c13487ba6a3 Author: Joerg Roedel AuthorDate: Wed, 19 May 2021 15:52:45 +02:00 Committer: Borislav Petkov CommitterDate: Wed, 19 May 2021 17:13:04 +02:00 x86/sev-es: Forward page-faults which happen during emulation When emulating guest instructions for MMIO or IOIO accesses, the #VC handler might get a page-fault and will not be able to complete. Forward the page-fault in this case to the correct handler instead of killing the machine. Fixes: 0786138c78e7 ("x86/sev-es: Add a Runtime #VC Exception Handler") Signed-off-by: Joerg Roedel Signed-off-by: Borislav Petkov Cc: stable@vger.kernel.org # v5.10+ Link: https://lkml.kernel.org/r/20210519135251.30093-3-joro@8bytes.org --- arch/x86/kernel/sev.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 82bced8..1f428f4 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1270,6 +1270,10 @@ static __always_inline void vc_forward_exception(struct es_em_ctxt *ctxt) case X86_TRAP_UD: exc_invalid_op(ctxt->regs); break; + case X86_TRAP_PF: + write_cr2(ctxt->fi.cr2); + exc_page_fault(ctxt->regs, error_code); + break; case X86_TRAP_AC: exc_alignment_check(ctxt->regs, error_code); break; From patchwork Wed May 19 13:52:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 444636 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27601C43616 for ; Wed, 19 May 2021 13:53:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0982E6139A for ; Wed, 19 May 2021 13:53:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353789AbhESNye (ORCPT ); Wed, 19 May 2021 09:54:34 -0400 Received: from 8bytes.org ([81.169.241.247]:40046 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353774AbhESNyd (ORCPT ); Wed, 19 May 2021 09:54:33 -0400 Received: from cap.home.8bytes.org (p549ad305.dip0.t-ipconnect.de [84.154.211.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id 14C4E3FF; Wed, 19 May 2021 15:53:09 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org, Hyunwook Baek Cc: Joerg Roedel , Joerg Roedel , stable@vger.kernel.org, hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , Arvind Sankar , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v2 2/8] x86/sev-es: Forward page-faults which happen during emulation Date: Wed, 19 May 2021 15:52:45 +0200 Message-Id: <20210519135251.30093-3-joro@8bytes.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210519135251.30093-1-joro@8bytes.org> References: <20210519135251.30093-1-joro@8bytes.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Joerg Roedel When emulating guest instructions for MMIO or IOIO accesses the #VC handler might get a page-fault and will not be able to complete. Forward the page-fault in this case to the correct handler instead of killing the machine. Fixes: 0786138c78e7 ("x86/sev-es: Add a Runtime #VC Exception Handler") Cc: stable@vger.kernel.org # v5.10+ Signed-off-by: Joerg Roedel --- arch/x86/kernel/sev.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 82bced88153b..1f428f401bed 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1270,6 +1270,10 @@ static __always_inline void vc_forward_exception(struct es_em_ctxt *ctxt) case X86_TRAP_UD: exc_invalid_op(ctxt->regs); break; + case X86_TRAP_PF: + write_cr2(ctxt->fi.cr2); + exc_page_fault(ctxt->regs, error_code); + break; case X86_TRAP_AC: exc_alignment_check(ctxt->regs, error_code); break;