Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5658665pxv; Wed, 7 Jul 2021 08:49:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGmPVA0O5hZa0/tlHSE5eifbUyb55u9kucgEwy/p6gXN9Nni0iHUSKtwn7yHg+F6r/c3zQ X-Received: by 2002:a17:907:d24:: with SMTP id gn36mr24674373ejc.269.1625672948292; Wed, 07 Jul 2021 08:49:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625672948; cv=none; d=google.com; s=arc-20160816; b=mVFvR7TLnpdDz5w13It4MJBivoihzN/GDD12OqDXTB9ZrtJURY/jaxvKpR8bqBp2G9 9dXD0B+F7MM07VxfiTEC5QRXCJV25UiRJV79WNnj8GUcXiJepKgoJvFlSclfQ6QfPMUA 2e+dMtNQvCUMzOoHw4KYF0WccX7HqUBY8VZpB+I0z+mbN9l4nOhI6gBKck6SR3zXy745 WYOUD6YXpuSuUCCmHpdF0YCAZicHetbE/uty+T9ww82NDlR81vY0IVRlMNuZJ2/vpeFE eEiwvmZk8mCxiNoxABQ2dz/79A14DiuZRnNIdW5ZFczyM0UQjgKRptv8YYrmLLmAz/Pg 1EkQ== 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=XnnD+WKjmMaIcoxzXQeIqu3OOT9S8jIhhegPGmtXPps=; b=Zxyg6qpMSXaBGtfyzqUp2rCkkINVi7KIKEiKvJvxdmdlovBm++AC4uPc6J3PY8ssQZ leTtOUihjml4qOGbvwWWt3xs3m8/jVIqCtmsPq5IMM0r4S838U1adt7xaXZmdKohhvDi S7BskfFeAi1u9K0Fhcw6yzQeyxHTbKcfytr5m0d68ZwpkhH5oydMfr4eVFHMq2+cCMLd GzXfTDDr3SBfu7JQA9dBzNSHj4ceEdtCfPNv86sT88DgiqyCkctLn013+rHhaIIDxwqQ udhOvKjGuyVecnQF2EvacCAqXqR6fv1Pgqk6OuoomgONyYfKFkjEwlY0wPZ1k4JUnzv8 ZrEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=agixlmBy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s7si17163040ejd.294.2021.07.07.08.48.43; Wed, 07 Jul 2021 08:49:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=agixlmBy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232351AbhGGPtz (ORCPT + 99 others); Wed, 7 Jul 2021 11:49:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232364AbhGGPtg (ORCPT ); Wed, 7 Jul 2021 11:49:36 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE4B2C061762; Wed, 7 Jul 2021 08:46:55 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id a6so1280571plh.11; Wed, 07 Jul 2021 08:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XnnD+WKjmMaIcoxzXQeIqu3OOT9S8jIhhegPGmtXPps=; b=agixlmBytfRil/fkf4OgDDmdZCvfuSwnj5sy2vnE2pYjSr4fq49TUp4T0f/DBWL+R7 dtp0xUVHFyRDbO2ZZHZG47mGHjJiVyYQesO2NN0JFKBXh2xwgv0l85XvXqUywSG8Fvr0 1Ul+fpcelmkcjAQw+bszpcRSz+GI7SFKNDQMiNrze7nfUoRflIMbr8UPrWEDWdIiLHWT 977bhPck25q/c2/QSy5qX/caMDzXJuO73RHyL0IAREsmggF+7GypT2XtMaRNeZvwgssJ Jb9R+KHghWzumV11pGybgCdu9V73FPISKwDj6Kc2id9ZDjTW1viAcgETkpNHjkay/0uH yUMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XnnD+WKjmMaIcoxzXQeIqu3OOT9S8jIhhegPGmtXPps=; b=Eza1oWmLZOTuvqTzcqhRzeNtagn1La9cqgdMEUrb2oo4+CimMFkblozMYyg3hotbZA dZRPotgHUnUUezclkfHNaODcqvyNxZd7LLObp3IBGpOK4dLDyoUJpogRKQGhqdT1P4eu 9I9ATjCMErp8ZHipUlkz27dy3Ya019cf82deRhnoVtZyM5+673T/dLc9nLoxrmpj8mrc ckQt2szjPOW1MbGrAMsK81MPTwjlHngGY+njjkiDd2ZDH/+LgNWMT3AzLdCnVffsdSUm e/eqbsg6vsfCZUpTIJdD50YBm5nzZWNQ3UcpWjCT7wSbUr7IIimkCCFPwVBIosq0hyCh rcLw== X-Gm-Message-State: AOAM530ff1jFykwFycIrPZHmw4xTE/8hgYNYFQpJui5+42pZBlePRgKz JO07EXdkZ+NkO64DTIZ1jQM= X-Received: by 2002:a17:902:ed82:b029:ef:48c8:128e with SMTP id e2-20020a170902ed82b02900ef48c8128emr21831521plj.72.1625672815405; Wed, 07 Jul 2021 08:46:55 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:38:6b47:cf3e:bbf2:d229]) by smtp.gmail.com with ESMTPSA id q18sm23093560pgj.8.2021.07.07.08.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 08:46:55 -0700 (PDT) From: Tianyu Lan To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, joro@8bytes.org, will@kernel.org, davem@davemloft.net, kuba@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, kirill.shutemov@linux.intel.com, akpm@linux-foundation.org, rppt@kernel.org, Tianyu.Lan@microsoft.com, thomas.lendacky@amd.com, ardb@kernel.org, robh@kernel.org, nramas@linux.microsoft.com, pgonda@google.com, martin.b.radev@gmail.com, david@redhat.com, krish.sadhukhan@oracle.com, saravanand@fb.com, xen-devel@lists.xenproject.org, keescook@chromium.org, rientjes@google.com, hannes@cmpxchg.org, michael.h.kelley@microsoft.com Cc: iommu@lists.linux-foundation.org, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, netdev@vger.kernel.org, vkuznets@redhat.com, brijesh.singh@amd.com, anparri@microsoft.com Subject: [Resend RFC PATCH V4 06/13] HV: Add ghcb hvcall support for SNP VM Date: Wed, 7 Jul 2021 11:46:20 -0400 Message-Id: <20210707154629.3977369-7-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210707154629.3977369-1-ltykernel@gmail.com> References: <20210707154629.3977369-1-ltykernel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tianyu Lan Hyper-V provides ghcb hvcall to handle VMBus HVCALL_SIGNAL_EVENT and HVCALL_POST_MESSAGE msg in SNP Isolation VM. Add such support. Signed-off-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 42 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + drivers/hv/connection.c | 6 ++++- drivers/hv/hv.c | 8 ++++++- include/asm-generic/mshyperv.h | 29 +++++++++++++++++++++++ 5 files changed, 84 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index c7b54631ca0d..8a6f4e9e3d6c 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -15,6 +15,48 @@ #include #include +u64 hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_size) +{ + union hv_ghcb *hv_ghcb; + void **ghcb_base; + unsigned long flags; + + if (!ms_hyperv.ghcb_base) + return -EFAULT; + + WARN_ON(in_nmi()); + + local_irq_save(flags); + ghcb_base = (void **)this_cpu_ptr(ms_hyperv.ghcb_base); + hv_ghcb = (union hv_ghcb *)*ghcb_base; + if (!hv_ghcb) { + local_irq_restore(flags); + return -EFAULT; + } + + memset(hv_ghcb, 0x00, HV_HYP_PAGE_SIZE); + hv_ghcb->ghcb.protocol_version = 1; + hv_ghcb->ghcb.ghcb_usage = 1; + + hv_ghcb->hypercall.outputgpa = (u64)output; + hv_ghcb->hypercall.hypercallinput.asuint64 = 0; + hv_ghcb->hypercall.hypercallinput.callcode = control; + + if (input_size) + memcpy(hv_ghcb->hypercall.hypercalldata, input, input_size); + + VMGEXIT(); + + hv_ghcb->ghcb.ghcb_usage = 0xffffffff; + memset(hv_ghcb->ghcb.save.valid_bitmap, 0, + sizeof(hv_ghcb->ghcb.save.valid_bitmap)); + + local_irq_restore(flags); + + return hv_ghcb->hypercall.hypercalloutput.callstatus; +} +EXPORT_SYMBOL_GPL(hv_ghcb_hypercall); + void hv_ghcb_msr_write(u64 msr, u64 value) { union hv_ghcb *hv_ghcb; diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index f9cc3753040a..fe03e3e833ac 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -258,6 +258,7 @@ void hv_sint_rdmsrl_ghcb(u64 msr, u64 *value); void hv_signal_eom_ghcb(void); void hv_ghcb_msr_write(u64 msr, u64 value); void hv_ghcb_msr_read(u64 msr, u64 *value); +u64 hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_size); #define hv_get_synint_state_ghcb(int_num, val) \ hv_sint_rdmsrl_ghcb(HV_X64_MSR_SINT0 + int_num, val) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 311cd005b3be..186fd4c8acd4 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -445,6 +445,10 @@ void vmbus_set_event(struct vmbus_channel *channel) ++channel->sig_events; - hv_do_fast_hypercall8(HVCALL_SIGNAL_EVENT, channel->sig_event); + if (hv_isolation_type_snp()) + hv_ghcb_hypercall(HVCALL_SIGNAL_EVENT, &channel->sig_event, + NULL, sizeof(u64)); + else + hv_do_fast_hypercall8(HVCALL_SIGNAL_EVENT, channel->sig_event); } EXPORT_SYMBOL_GPL(vmbus_set_event); diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 59f7173c4d9f..e5c9fc467893 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -98,7 +98,13 @@ int hv_post_message(union hv_connection_id connection_id, aligned_msg->payload_size = payload_size; memcpy((void *)aligned_msg->payload, payload, payload_size); - status = hv_do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL); + if (hv_isolation_type_snp()) + status = hv_ghcb_hypercall(HVCALL_POST_MESSAGE, + (void *)aligned_msg, NULL, + sizeof(struct hv_input_post_message)); + else + status = hv_do_hypercall(HVCALL_POST_MESSAGE, + aligned_msg, NULL); /* Preemption must remain disabled until after the hypercall * so some other thread can't get scheduled onto this cpu and diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index e6d6886faed1..8f6f283fb5b5 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -30,6 +30,35 @@ union hv_ghcb { struct ghcb ghcb; + struct { + u64 hypercalldata[509]; + u64 outputgpa; + union { + union { + struct { + u32 callcode : 16; + u32 isfast : 1; + u32 reserved1 : 14; + u32 isnested : 1; + u32 countofelements : 12; + u32 reserved2 : 4; + u32 repstartindex : 12; + u32 reserved3 : 4; + }; + u64 asuint64; + } hypercallinput; + union { + struct { + u16 callstatus; + u16 reserved1; + u32 elementsprocessed : 12; + u32 reserved2 : 20; + }; + u64 asunit64; + } hypercalloutput; + }; + u64 reserved2; + } hypercall; } __packed __aligned(PAGE_SIZE); struct ms_hyperv_info { -- 2.25.1