Received: by 2002:ac8:5491:0:b0:40f:fb00:664b with SMTP id h17csp604350qtq; Thu, 10 Aug 2023 10:16:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpG3vvtmAf2HdEFx1DgPn5a4/epEkPgzevM6feIZaW4S0QAJnkp2ONFrs6rRb49lxEkq1p X-Received: by 2002:ac2:4305:0:b0:4fe:1ea7:63b4 with SMTP id l5-20020ac24305000000b004fe1ea763b4mr2296651lfh.57.1691687768018; Thu, 10 Aug 2023 10:16:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691687767; cv=none; d=google.com; s=arc-20160816; b=jwtIy4LpKasOJjvDDFmREAtxR8beEJPCars14N5TiGXJQ8guWLOUtAw1YQEikHbWgh JGJCgL8cIG3A8X2b/HCoRRPtcZ6FBCv2iZL84v/S16ERbevXh7WFyd6IwanMiJExfd3z qYSgpKnDmnkcx9wwznkPNroyRktFQTNM4/8nPXgmJZQ9J6ebDDiwrRcNDvA3T0AsWhMz jnoHbv7EU8rj+vZU1fbDciiZ3LH6B23U9A2HA1qxFa15JrRxM+LZGnLg1e+kQOk88EuJ 8W4Y7xlEyWvtpd7jx6fMunW+AOigDrcWa1arUrBisiEz/VwE2rzPT5GQjlg9Bw+f7/Q/ Bbyg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Oyq9KI3NurUC1G8S0DuY90VVqt2QiudPjei5bx+xe8I=; fh=TxLVtSsj0Yk+bstPG6ly04YaPbvjOFEmGNSQ8sZkNQc=; b=VRNH/ijxbjyzJfZG+0vukgn/4bfIssCIs35rRLK4+w9JTbBRgN5Bg7L6uqb99TWg9m 3U5DNf2y7SVQILTcimWZUd2gLL/EXPhASQfFG1thY0+qqErw8+Rxyez8w0kpngMyNjdc 7W1zYIgoL/gOCYwXxuPpJtJ/vWyO//8Y8ckNKBpSWaSdUKWGPYJXxXHj7tJ/JKyjSFSz HtVcCFX+HkTZgzSGfJVv9f0p7ugga5U7f+XJTUUZ4jnCEfbEw6XoadJOX686icRRE60o uvx6hu0/1eJrYkSAdubcdSMBCtX/KDt2LiU8Q1xQlO13U6vWVfeXqd2OOull5gNjJujv ET6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OzwLYJDB; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g15-20020aa7c58f000000b0052240dd74f4si1795419edq.616.2023.08.10.10.15.42; Thu, 10 Aug 2023 10:16:07 -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=OzwLYJDB; 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 S236741AbjHJQNK (ORCPT + 99 others); Thu, 10 Aug 2023 12:13:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236556AbjHJQNE (ORCPT ); Thu, 10 Aug 2023 12:13:04 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E7352703; Thu, 10 Aug 2023 09:04:45 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bbf8cb694aso9441665ad.3; Thu, 10 Aug 2023 09:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691683478; x=1692288278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Oyq9KI3NurUC1G8S0DuY90VVqt2QiudPjei5bx+xe8I=; b=OzwLYJDBajWtJkd2M3jwwzEWK28bhXxlwnwqBRIBLdtT4DVYXxRwl66np/1CXRDtM7 XOfC3IbH+t/NJNTBRfJMgMbo2FFxptaC717HHYel7YjhvxnB39xBE9K/aQoNdA2GmACM J5w7LFnEqVGJJJSqhEycc1sXyUFFps8+zGNZUMmqhO8Wi7wMB8E1kUUuhysD0RO79gFj vf8ah+BiwsCOcW28UWj5IQJM4iNWymQfqBOmZDtmKSeqs0ANsGfJsF5fpWpxkQ+Efboq gKULvGBR+8q4QDtX7cUVQuHNJRFof9C7TdWxyrO7cbKIXrH/jBKiLrcGq/YIXXcOx2ga Kw9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691683478; x=1692288278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Oyq9KI3NurUC1G8S0DuY90VVqt2QiudPjei5bx+xe8I=; b=UpLCvtMJx7ZIAZAGvDfp0SkgwGGdPFfkum3WRKc8fKsWIPeZAq5yGKj/mccp1Iy+Q5 Uiy7WQ5L2ZiIsKzGzYiRKDDzqmmyGzUhcIaH28ZnNd68LZOEEUfiCSdlJnSJGNMm2EHI rsq9LmXRlyNCvt+6cfsoNEzA9DFAcTdwi/E8WPP1oSfw7WK+Ql6S41ic5awz+J2biASo E5yjbsMq2nEH5LGafiQPsICB22qiLjAhUqvfJYEnSE7NO7zfzOdQYTdzbZ7PNl305jC4 QJEscB37pkUoAqsAGy680QcM2PHdUW5TVUX/Q2HZNldGRVYfQ5oWzV3AbI5uXsL6JIXx lQdQ== X-Gm-Message-State: AOJu0YyqhCdE43bXdbYxqhtRwKd7kqwrXaFpLaMMv3E6+DOIJsZ1yKkG vpMQ8nKoVyjoaNiezTpNA2w= X-Received: by 2002:a17:902:8688:b0:1b9:c205:a876 with SMTP id g8-20020a170902868800b001b9c205a876mr2395865plo.29.1691683478550; Thu, 10 Aug 2023 09:04:38 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:0:c620:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id r4-20020a1709028bc400b001b895a17429sm1948821plo.280.2023.08.10.09.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 09:04:35 -0700 (PDT) From: Tianyu Lan To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, daniel.lezcano@linaro.org, arnd@arndb.de, michael.h.kelley@microsoft.com Cc: Tianyu Lan , linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, vkuznets@redhat.com, Michael Kelley Subject: [PATCH V5 8/8] x86/hyperv: Add hyperv-specific handling for VMMCALL under SEV-ES Date: Thu, 10 Aug 2023 12:04:11 -0400 Message-Id: <20230810160412.820246-9-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230810160412.820246-1-ltykernel@gmail.com> References: <20230810160412.820246-1-ltykernel@gmail.com> 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_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 From: Tianyu Lan Add Hyperv-specific handling for faults caused by VMMCALL instructions. Reviewed-by: Michael Kelley Signed-off-by: Tianyu Lan --- arch/x86/kernel/cpu/mshyperv.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index c2ccb49b49c2..b7d73f3107c6 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -32,6 +32,7 @@ #include #include #include +#include /* Is Linux running as the root partition? */ bool hv_root_partition; @@ -574,6 +575,22 @@ static bool __init ms_hyperv_msi_ext_dest_id(void) return eax & HYPERV_VS_PROPERTIES_EAX_EXTENDED_IOAPIC_RTE; } +#ifdef CONFIG_AMD_MEM_ENCRYPT +static void hv_sev_es_hcall_prepare(struct ghcb *ghcb, struct pt_regs *regs) +{ + /* RAX and CPL are already in the GHCB */ + ghcb_set_rcx(ghcb, regs->cx); + ghcb_set_rdx(ghcb, regs->dx); + ghcb_set_r8(ghcb, regs->r8); +} + +static bool hv_sev_es_hcall_finish(struct ghcb *ghcb, struct pt_regs *regs) +{ + /* No checking of the return state needed */ + return true; +} +#endif + const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = { .name = "Microsoft Hyper-V", .detect = ms_hyperv_platform, @@ -581,4 +598,8 @@ const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = { .init.x2apic_available = ms_hyperv_x2apic_available, .init.msi_ext_dest_id = ms_hyperv_msi_ext_dest_id, .init.init_platform = ms_hyperv_init_platform, +#ifdef CONFIG_AMD_MEM_ENCRYPT + .runtime.sev_es_hcall_prepare = hv_sev_es_hcall_prepare, + .runtime.sev_es_hcall_finish = hv_sev_es_hcall_finish, +#endif }; -- 2.25.1