From patchwork Fri Aug 4 15:22:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 131250 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp382445vqb; Fri, 4 Aug 2023 09:34:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWqLgQOgd9UwVBtwo6TEflJBSLJTbdotadx3PTpK1oHxjLEXQWE9Z1BIsncR/bnTZifHqk X-Received: by 2002:a17:907:7889:b0:99b:4668:865f with SMTP id ku9-20020a170907788900b0099b4668865fmr2342226ejc.10.1691166875831; Fri, 04 Aug 2023 09:34:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691166875; cv=none; d=google.com; s=arc-20160816; b=UNPZPmJ0NldVVO/tww80lt8c5G2UmAzftibIuiguwpif5bCFN3HT4uYOygY8vufNAO T2Nhk9dXV8ruzBOocNblYcuJerFO1QQhamiguOA6miSuzS9W5qbcJrB4u07iezKk0b2O wXh2C5GAr0tEGZxerVhA9arKdYsNGnqO9cSIvyNICXCcax5N/LvwqGuUzz7v9RI0yl6/ YG1g3QgUpX9gDIDmilDVSuff8W7NgZtcwx3EJBWP+rJcTddt5/VlBGEfJr2f9kQqEgRq Z8lLgH/a1mOTrfxG9vI+wQUkUYeJVmvOqpzsDz6OpTI1ji6k+Afu7UgQNQhgFZx7PIll VAKg== 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=lGDTbc8t+NaU1OP3xKzemfdpSc0H/y8ZWu0f/3/zAAY=; fh=0q4Ral/ZvWHifErBr5uVVFNUVQsTG1/TVmQRaCWii40=; b=riSFUfK8r097p6k30XlRprxxDhtqOqJ4YtwQgDc8KcCNqzQtCydOWDFa57YO1+/eQP 7vmwvwH6gLUFg7ALY+hko2OVswCLFgFY4MVZtole6AFEk6L9h42DgZw2pseWbVDEATKb Lyuo8kpT6/c+r1GK5djPsBQ7InCNrVO15QkmQMdSq01RuKvyM55s4my8UdOs6q1AIjxo 8S8vfDHn4QwDpA/zPTtFe+hRKavAcaKWGGFOqqOPyD1d5gbIl36CiXTCHD+v5gma4bhz 1L24qHpSxdZ3RECWmi/bQp4Kocty3xW7QNAZgB3SnpDI6rGMc0mR7d164anMv0RHvprG LUVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=WRy+WGkn; 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 gw1-20020a170906f14100b0099233cac125si1785979ejb.915.2023.08.04.09.33.53; Fri, 04 Aug 2023 09:34:35 -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=WRy+WGkn; 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 S232083AbjHDPX1 (ORCPT + 99 others); Fri, 4 Aug 2023 11:23:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232035AbjHDPXI (ORCPT ); Fri, 4 Aug 2023 11:23:08 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5956A49F0; Fri, 4 Aug 2023 08:23:07 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1b8ad8383faso19426985ad.0; Fri, 04 Aug 2023 08:23:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691162587; x=1691767387; 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=lGDTbc8t+NaU1OP3xKzemfdpSc0H/y8ZWu0f/3/zAAY=; b=WRy+WGkntymcLuEpT2lKn8XoQ/VswdVwHbhd3QD6XVOnnA7L6KrOK+9dePe1RJSBjD dLdGdHZTZfGW2KQ6cj+X9DUFfmb7AzkTzKoyfCnw+AtdIfslz0DDk5CuEE8sUVJR2MgZ I5l3D1KzymrYnTjXwbEIi6Si0NyPB+B0mWcFtxu+XoGIeBfBpE3W4n0/dm3VGAPqo+64 TUlGk32uiwzTd7u6TqhyRYvXeOTzs8sNFWagUMD30o7s0ZKMZ8yh+yaTvKwbVqBqRKLD Hca0c2qTf1wE4RdiX2bBmjYBEDIPvKala/RxbhwB0ZADxXlXCKhY5EjiIGcbcT9yr9vQ LLEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691162587; x=1691767387; 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=lGDTbc8t+NaU1OP3xKzemfdpSc0H/y8ZWu0f/3/zAAY=; b=MFpgYLlbQ9JLVUstpOWZ0ye3S1gvv9KhILn3P2/sAwFzsmLosTZXKpf9hYsJC47VnY ai69fGy3RbYg7SKuNEyrE6kUmeoH2PNlLs48njWp7AiVVHHiGXB0+3NzZX3dWPAVYOB6 OQCUC2bXPuIUQzY3TW0thusWsR8oYE5ImAxvT1KuJ9vs6FRkUG7aSz8oXPiIKs+Llkh5 Js5JZGbOIWFdvytGNEXuMGOXcco9taAqz8/oDEhZD2W31C8tMRs5TsVuJPpJssFkbkgd t3S2vqD/KGb4gGoZw+Y6QR82I36pgHdZv1TNX3gykZWPY2x0U7LH7iEb3QOxB0WdztxV k8SQ== X-Gm-Message-State: AOJu0Yy8dTnnV1vzgAu86IXFAEnJJrQNMHtz/nJJvhbDMOuPIhgoEZBp uP3yPBSNfUSXesu4OtYbF7A= X-Received: by 2002:a17:902:74c3:b0:1bc:203f:3b3c with SMTP id f3-20020a17090274c300b001bc203f3b3cmr2106299plt.24.1691162586772; Fri, 04 Aug 2023 08:23:06 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:f:a0bf:7946:90be:721b]) by smtp.gmail.com with ESMTPSA id s21-20020a170902989500b001aaf2e8b1eesm1891325plp.248.2023.08.04.08.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 08:23:06 -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 Subject: [PATCH V4 5/9] x86/hyperv: Use vmmcall to implement Hyper-V hypercall in sev-snp enlightened guest Date: Fri, 4 Aug 2023 11:22:49 -0400 Message-Id: <20230804152254.686317-6-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230804152254.686317-1-ltykernel@gmail.com> References: <20230804152254.686317-1-ltykernel@gmail.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773316998271495768 X-GMAIL-MSGID: 1773316998271495768 From: Tianyu Lan In sev-snp enlightened guest, Hyper-V hypercall needs to use vmmcall to trigger vmexit and notify hypervisor to handle hypercall request. Signed-off-by: Tianyu Lan --- arch/x86/include/asm/mshyperv.h | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 2fa38e9f6207..025eda129d99 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -64,12 +64,12 @@ static inline u64 hv_do_hypercall(u64 control, void *input, void *output) if (!hv_hypercall_pg) return U64_MAX; - __asm__ __volatile__("mov %4, %%r8\n" - CALL_NOSPEC + __asm__ __volatile__("mov %[output], %%r8\n" + ALTERNATIVE("vmmcall", CALL_NOSPEC, X86_FEATURE_SEV_ES) : "=a" (hv_status), ASM_CALL_CONSTRAINT, - "+c" (control), "+d" (input_address) - : "r" (output_address), - THUNK_TARGET(hv_hypercall_pg) + "+c" (control), "+d" (input_address) + : [output] "r" (output_address), + THUNK_TARGET(hv_hypercall_pg) : "cc", "memory", "r8", "r9", "r10", "r11"); #else u32 input_address_hi = upper_32_bits(input_address); @@ -105,7 +105,8 @@ static inline u64 _hv_do_fast_hypercall8(u64 control, u64 input1) #ifdef CONFIG_X86_64 { - __asm__ __volatile__(CALL_NOSPEC + __asm__ __volatile__("mov %[thunk_target], %%r8\n" + ALTERNATIVE("vmmcall", CALL_NOSPEC, X86_FEATURE_SEV_ES) : "=a" (hv_status), ASM_CALL_CONSTRAINT, "+c" (control), "+d" (input1) : THUNK_TARGET(hv_hypercall_pg) @@ -150,13 +151,13 @@ static inline u64 _hv_do_fast_hypercall16(u64 control, u64 input1, u64 input2) #ifdef CONFIG_X86_64 { - __asm__ __volatile__("mov %4, %%r8\n" - CALL_NOSPEC - : "=a" (hv_status), ASM_CALL_CONSTRAINT, - "+c" (control), "+d" (input1) - : "r" (input2), - THUNK_TARGET(hv_hypercall_pg) - : "cc", "r8", "r9", "r10", "r11"); + __asm__ __volatile__("mov %[output], %%r8\n" + ALTERNATIVE("vmmcall", CALL_NOSPEC, X86_FEATURE_SEV_ES) + : "=a" (hv_status), ASM_CALL_CONSTRAINT, + "+c" (control), "+d" (input1) + : [output] "r" (input2), + THUNK_TARGET(hv_hypercall_pg) + : "cc", "r8", "r9", "r10", "r11"); } #else {