From patchwork Mon May 15 16:59:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 94230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp7080952vqo; Mon, 15 May 2023 10:30:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6s7DJGXbEyI+AlZyKiH0Hq6yobTLKkvtX7kZDoJk7qZUgho1DebLBj4QcchAY4rLFUdep4 X-Received: by 2002:a17:902:e5ce:b0:1ae:e2b:3ad8 with SMTP id u14-20020a170902e5ce00b001ae0e2b3ad8mr6496047plf.66.1684171824311; Mon, 15 May 2023 10:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684171824; cv=none; d=google.com; s=arc-20160816; b=lP3Xxo7NYukdvQCxDNxQkUlBz/X2kcf5Cm+zKB0uZxckN9iOrtoDskaHzOXD/lvMSO hyvAKawqvZ7Qdc13yMm0EiOUfE0jyemm6OQziBtN+gTwLdEK6wuszlML9c8cCGLWhAou abWfxIdo04tCHkERcJlHQEpMl0Sucm0ymK9dEAbskvj32oLP7eeFizoPfZmMbOtWstN8 7swuQTbW5yiLmK9yFzHCn5lj6vKuLzunX4Kr9B4zn/UIwwF6xGz4cWQ9m7GCMxvqB7H1 Vikffh8ue1qiPkba7FqhJ26l5q5bYJAkVS/ekN74p4TlSVbSKaZkmPvSRuPI61fQOMoy FZ6g== 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=fry12NLoScUn7gbAM5zwlql+LIRPvftdxXtygfKZOSU=; b=0gj7DafgdF13k+Ipfo83tWPuCcvaCQ+9huN6lI36mr0cU79rehwBOApsDmRClzGuNJ MzkBSI0DJy/5iC8QWHv0s+NyxdAUFRBY8YOml6SshRAuySk33tPsm4y2o+SFnkwzGBo0 cjvxUilzFigNPYHDeAKnuYVJWZcRuRJ4OjNSz7Sl47U5ojHwqSBFEF6PZ7L2mhEcQ1Hn sdSOY8HHk2HSbmcp3a1LofAh4U2hApTF687IVoaq8Lm2nIfbu9vcfnqYLHXCmCkp3Db+ FMSjOYL1inP099tEsmsiV5rvmbKDSEDI7DBz9dows49ln9UE+MRWKzcr1syZuS/NivjR 8ZnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=MPWw7UFB; 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 k23-20020a170902761700b001aaef930752si4164313pll.647.2023.05.15.10.30.06; Mon, 15 May 2023 10:30:24 -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=MPWw7UFB; 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 S243427AbjEORAX (ORCPT + 99 others); Mon, 15 May 2023 13:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243391AbjEOQ7t (ORCPT ); Mon, 15 May 2023 12:59:49 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 528817DAF; Mon, 15 May 2023 09:59:37 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5304913530fso6556033a12.0; Mon, 15 May 2023 09:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684169977; x=1686761977; 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=fry12NLoScUn7gbAM5zwlql+LIRPvftdxXtygfKZOSU=; b=MPWw7UFBWYvp7IesQxIo5ysOJktrGYmN1TyLJFXadxqrZlruiQQeYOfaD6NZKFi8Oq 3wGuOBsR5RhIsSFuGzLjnjU6hLY0jnMdT3FUtnxfbQM1S3POdaIZLhDcuNcWxcuR2R1Y 0IjbzRGTxnwyyW7rHc6fCYr+gYB2xbtBijAw+YUyf0vBZwBuJR80Vfgi0IIbSUzzQwx+ 6DC6ruv18XbvcFxW1kc+xxLrBsCc0d/rhx4U8TQ3CWMTeseQe0yOmPMkPDrEvymJdvLY ZhGPuDye4KBzHXDdk8pfoHDc39l1AexogeYofB9l7mSAXowILiOl3uZ507KJ++uRvTnK ZgIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684169977; x=1686761977; 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=fry12NLoScUn7gbAM5zwlql+LIRPvftdxXtygfKZOSU=; b=aAQZJc50DJOlzrwjqEeJA4lqo9/LETR5XLlBTXIiX8zj+XASqq8kdXfSgKgNQEsS+O 9Fbw28Z1Np9yKVHzTLVNN3C5Qu4LvB23R1paBFDZ//X/akMmcE4rgRzCmoordnrxuA7n TyFrBTCJYIXnFTDFwZYYzIqM4yEoLqcaatw2sGu1px4gSVaACRyhhI10yvzOmXPQh2Xx PIhhTrKYFuQyKvj06ubcKwKkW/y+Ul7Xp6DJfF4xFFXrUEtFB4jjOj3w8epbvjKKnjpI p77tM3g9Ub33jmu8nxZhp6y8YjhBN875+D1FEAKZrrbErTSDX+SFWp1W6BX6TR+dCOmn MvOg== X-Gm-Message-State: AC+VfDzQBGAZE9bz0qCP4eqw5u83n+XbIqJ8sp78/7Y9gw1srmPxgxrf dWrWkcf9EGVLSA+K2TbJzZE= X-Received: by 2002:a17:90a:94cc:b0:24e:edd:4d63 with SMTP id j12-20020a17090a94cc00b0024e0edd4d63mr33116444pjw.5.1684169976665; Mon, 15 May 2023 09:59:36 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:f:85bb:dfc8:391f:ff73]) by smtp.gmail.com with ESMTPSA id x13-20020a17090aa38d00b0024df6bbf5d8sm2151pjp.30.2023.05.15.09.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 09:59:36 -0700 (PDT) From: Tianyu Lan To: luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, jgross@suse.com, tiala@microsoft.com, kirill@shutemov.name, jiangshan.ljs@antgroup.com, peterz@infradead.org, ashish.kalra@amd.com, srutherford@google.com, akpm@linux-foundation.org, anshuman.khandual@arm.com, pawan.kumar.gupta@linux.intel.com, adrian.hunter@intel.com, daniel.sneddon@linux.intel.com, alexander.shishkin@linux.intel.com, sandipan.das@amd.com, ray.huang@amd.com, brijesh.singh@amd.com, michael.roth@amd.com, thomas.lendacky@amd.com, venu.busireddy@oracle.com, sterritt@google.com, tony.luck@intel.com, samitolvanen@google.com, fenghua.yu@intel.com Cc: pangupta@amd.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org Subject: [RFC PATCH V6 08/14] x86/hyperv: Use vmmcall to implement Hyper-V hypercall in sev-snp enlightened guest Date: Mon, 15 May 2023 12:59:10 -0400 Message-Id: <20230515165917.1306922-9-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230515165917.1306922-1-ltykernel@gmail.com> References: <20230515165917.1306922-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_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765982155011994973?= X-GMAIL-MSGID: =?utf-8?q?1765982155011994973?= 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 --- Change since RFC V2: * Fix indentation style --- arch/x86/include/asm/mshyperv.h | 44 ++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 97d117ec95c4..939373791249 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -61,16 +61,25 @@ static inline u64 hv_do_hypercall(u64 control, void *input, void *output) u64 hv_status; #ifdef CONFIG_X86_64 - if (!hv_hypercall_pg) - return U64_MAX; + if (hv_isolation_type_en_snp()) { + __asm__ __volatile__("mov %4, %%r8\n" + "vmmcall" + : "=a" (hv_status), ASM_CALL_CONSTRAINT, + "+c" (control), "+d" (input_address) + : "r" (output_address) + : "cc", "memory", "r8", "r9", "r10", "r11"); + } else { + if (!hv_hypercall_pg) + return U64_MAX; - __asm__ __volatile__("mov %4, %%r8\n" - CALL_NOSPEC - : "=a" (hv_status), ASM_CALL_CONSTRAINT, - "+c" (control), "+d" (input_address) - : "r" (output_address), - THUNK_TARGET(hv_hypercall_pg) - : "cc", "memory", "r8", "r9", "r10", "r11"); + __asm__ __volatile__("mov %4, %%r8\n" + CALL_NOSPEC + : "=a" (hv_status), ASM_CALL_CONSTRAINT, + "+c" (control), "+d" (input_address) + : "r" (output_address), + THUNK_TARGET(hv_hypercall_pg) + : "cc", "memory", "r8", "r9", "r10", "r11"); + } #else u32 input_address_hi = upper_32_bits(input_address); u32 input_address_lo = lower_32_bits(input_address); @@ -104,7 +113,13 @@ static inline u64 _hv_do_fast_hypercall8(u64 control, u64 input1) u64 hv_status; #ifdef CONFIG_X86_64 - { + if (hv_isolation_type_en_snp()) { + __asm__ __volatile__( + "vmmcall" + : "=a" (hv_status), ASM_CALL_CONSTRAINT, + "+c" (control), "+d" (input1) + :: "cc", "r8", "r9", "r10", "r11"); + } else { __asm__ __volatile__(CALL_NOSPEC : "=a" (hv_status), ASM_CALL_CONSTRAINT, "+c" (control), "+d" (input1) @@ -149,7 +164,14 @@ static inline u64 _hv_do_fast_hypercall16(u64 control, u64 input1, u64 input2) u64 hv_status; #ifdef CONFIG_X86_64 - { + if (hv_isolation_type_en_snp()) { + __asm__ __volatile__("mov %4, %%r8\n" + "vmmcall" + : "=a" (hv_status), ASM_CALL_CONSTRAINT, + "+c" (control), "+d" (input1) + : "r" (input2) + : "cc", "r8", "r9", "r10", "r11"); + } else { __asm__ __volatile__("mov %4, %%r8\n" CALL_NOSPEC : "=a" (hv_status), ASM_CALL_CONSTRAINT,