Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2614252pxb; Sun, 28 Feb 2021 07:12:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwreC99sDFtXfeY4M/BRdF80GPoI5j9SfQ5u6vEXPkwc1tzQ9iQwfIQzwv7LWIPboxFB19I X-Received: by 2002:a05:6402:1383:: with SMTP id b3mr12022742edv.131.1614525128029; Sun, 28 Feb 2021 07:12:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614525128; cv=none; d=google.com; s=arc-20160816; b=sUe70Wl4bHlruF51OLlNskecZ3FDbWwSonotJxjI6tvKGFaVEG9iXtJ4FIX8mprjKm 3gPR25do+ykVSmo6EBy7whFIWLP6pTozqCuwOhSKNQQBUeFEDoscCNWcvhpy4j649dG5 5QPrEOs3WdMNzgr2P8QR5v/uSeySdcfnQmdeyYF/H55PSGLUex1JK5ET4pY1qASxFhT6 27TvZjdUKnyXP9im33V8OuDw1Vtdv3TJIw537Cs0MLWUqG8acJX5gxWOb6I8HSmO4y+9 OIKbf24xwxqe59ugezX09+LCtixGg48eWRop6SEiCg6LNLs4o2KDCyfLfPfS5YGJpCoC NTBA== 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=g6yJapEvr1+vG3IMl2CfJqTEdM4tLFKyeRGeN+T/RzY=; b=QdTJQUhOlf+EfjWTbY/+Ox6lNO62k7a3zgL+ee83gimt+CDN0fgA1iqTYznbGpWqH1 cXhMcvLswK9znqJ5bWord0I33zD9lE/zYW3aeYgUEDs8zsj2IVrkcfNnXcT5i5nbui0+ WkMj4QEIYv3g3Czira6+64STdyhFaMhLyMOegJByKmijxAebMdIcH2LA0U8BQ7MelZYo 6z1EIYonfk4APYmV8xWCcgzhxI6JM5zLG/a/kII1l7y/kLPPtWsZaQIifPWiGg0pEClX kl7AL8R8Cch9+zHtspidPOJ1uM1rzHBHgINb196U4Bwljk0CPbVe0tTBaRyD4P5pDz3K OUKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bz1S3s+A; 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 s21si9421767ejq.101.2021.02.28.07.11.44; Sun, 28 Feb 2021 07:12:08 -0800 (PST) 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=bz1S3s+A; 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 S231220AbhB1PHh (ORCPT + 99 others); Sun, 28 Feb 2021 10:07:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbhB1PFg (ORCPT ); Sun, 28 Feb 2021 10:05:36 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DA57C06178B; Sun, 28 Feb 2021 07:04:16 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id d2so9672591pjs.4; Sun, 28 Feb 2021 07:04:16 -0800 (PST) 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=g6yJapEvr1+vG3IMl2CfJqTEdM4tLFKyeRGeN+T/RzY=; b=bz1S3s+Ak9sKtmuMg8kVV18+TzMmfiDTl8M6+4SqBUHFkcsCyQU8p8rbalZeqA4wrM 9pF0g14dfGNUghhDIrC8th5AzL2p97nlPt1JGezu2WvlcfAigAtKdw+aEbh6tmc/5rVs YDynqA00v8RQdbYAtT8uXLRPmwmsyPkmCb7bmWDC9onMslp67BXwfvzmM0QXsbuR2r6E UzJczTQN6a8ZD5xJQmcAND8p1l+NUPF8GoFPSTVQ3umk/I1GzLKCTCtRuxgp04KSXuH6 YEFskFv/NbEZ6nHjuAIJxzahgJ7nCGLCm7TCxDDnumF0C1+GV9OUWPfXU0BdSYDpkzak d5OA== 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=g6yJapEvr1+vG3IMl2CfJqTEdM4tLFKyeRGeN+T/RzY=; b=YnhERpjiuZusqqS76DW6nqyXI8g/H5+TxGrWL7zOYoe/BVca+l07k8HK0u1BRO6hlG gDKB0CbW2h45nzRoIS3zNcEb7bsXirE9h91HUxbEXo/nMKKIAVu3vZsDQ7SaeEIYp+PZ Ms6I84ra/Z5/ZE5Y5xYKQlTnbWrmZ/XHg7RsnJzxzGkNUQ9DTFl4dk9hunpJkSt/9iqE M6QA8MhED70S+X124GJwAfuCG0Yy2mTVgkruzy6g5BsStgZQiSOEjqPO1W3m4fqHMARN zHK6a0drpRBL5JEdKXkkXyKaTyGsnji1Ivvzp2znyHE1CMtkElJtFDXqfJ9DfNtfVlMr Ga2Q== X-Gm-Message-State: AOAM530r5oFoXg+fYvcjJ/oWWweo5pidG8u5oekyTeGWWADR7K0BRMTR gGkkPtjF2npJCg9ygnVRjuU= X-Received: by 2002:a17:902:694c:b029:e2:daa3:ca4a with SMTP id k12-20020a170902694cb02900e2daa3ca4amr11516866plt.80.1614524655876; Sun, 28 Feb 2021 07:04:15 -0800 (PST) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:0:561f:afde:af07:8820]) by smtp.gmail.com with ESMTPSA id 142sm8391331pfz.196.2021.02.28.07.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 07:04:15 -0800 (PST) From: Tianyu Lan To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com Cc: Tianyu Lan , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, vkuznets@redhat.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, sunilmut@microsoft.com Subject: [RFC PATCH 5/12] HV: Add ghcb hvcall support for SNP VM Date: Sun, 28 Feb 2021 10:03:08 -0500 Message-Id: <20210228150315.2552437-6-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210228150315.2552437-1-ltykernel@gmail.com> References: <20210228150315.2552437-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 | 69 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + drivers/hv/connection.c | 6 ++- drivers/hv/hv.c | 8 +++- 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 4332bf7aaf9b..feaabcd151f5 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -14,8 +14,77 @@ 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); +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; + + 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 f624d72b99d3..c8f66d269e5b 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -274,6 +274,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 c83612cddb99..79bca653dce9 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -442,6 +442,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 28e28ccc2081..6c64a7fd1ebd 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -60,7 +60,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 -- 2.25.1