Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp688357pxb; Tue, 14 Sep 2021 06:41:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSwgZR9mLtraOtfytX1uBGgNDPa2jSiTlH0otIsIWnQ23y3UIImeaNnc7Djmxb9sGX3X0H X-Received: by 2002:a6b:e012:: with SMTP id z18mr13514422iog.26.1631626895216; Tue, 14 Sep 2021 06:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631626895; cv=none; d=google.com; s=arc-20160816; b=RLmeLYyMqFHgMpAP4VKDPzjv8tSWd60K0SPqDi9GroUYZOGd2LQ6KpyZZyY7LV7Lpb 7W4icT+yKB3INGxpUikR1JY6wlAvqg9OjYd7lUXMeJicpol4f40VB5vBuJAUSgkuvtL0 fUitN9Y6fa4V2VFhP01ZBhbv3wT0Z9MMu0nWD5JtPpPRCPRG8S0DX7U7+4ob3B0+4wG5 Uzoa1uVH72UJnaFSea9oCN9rul6VmvY8/7vyA8uQV2uzm0Baq03ktleelFiHkBlfARda 2+l9XvQYlOdSSONR3v/3W38gbroamFoTnERasPAPVv+ilWpbsktTkziaurSLMGQrnB5d RXHA== 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=04R/nF7ZQn0L4lmwG9K7NZhI1RIoqJtAembHuZpzcoE=; b=Ij1rQyJXM5NyyVAP9HHvKq/ziZ9zXXnPoEyA1no1MGtQAXXsSo4vUy9zqeG7YnENbW f+SW0XwJk5Nwo6TUAjhVnz9iFZDeDVlmRJB1cQBSnmT4k+ba+qfNe24hETi3J1QZ77WI +1299YU3lIYmuDqHv1tKxtk+t+1iZ6UywbnGRDAjM2UYIfzNJJEBns85yx3gixcQr7wS 8KghOTc7GqUgn7cuy/qSo6Kycz2HnWUHQWs/prWQyvSaSn8weFEIpg0+arUWBqN/5pM5 3adWgZwsp8zJQhb6bHQ/QCkOv78eZvSe10CFad/3zJcbjTjxh9n9YSQz1Ak5IstGiWZy /cGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cXWjfh70; 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 m21si12099716jaj.19.2021.09.14.06.41.23; Tue, 14 Sep 2021 06:41:35 -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=20210112 header.b=cXWjfh70; 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 S233680AbhINNlS (ORCPT + 99 others); Tue, 14 Sep 2021 09:41:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233499AbhINNk7 (ORCPT ); Tue, 14 Sep 2021 09:40:59 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3480C0613DF; Tue, 14 Sep 2021 06:39:42 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id u18so12802540pgf.0; Tue, 14 Sep 2021 06:39:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=04R/nF7ZQn0L4lmwG9K7NZhI1RIoqJtAembHuZpzcoE=; b=cXWjfh70bA6/tTG3cRi7I0j1g+p2Lm3CJSGXyCEtns1z4ew1JMJSouaTXxuUkcmAAF pD2ztmNCM/EaSPUeDDaq6UxsWFBxK9H35yFnlW25xXgoMBjP2i0pScCK83QZEclf8ecy N9PLUvbIXVRHq4/y1x9TK184cTltER/wXcMXRfCw3qyn5rb59Xp4R9JHz9uej2V7BUzJ 4nbgXuO4P+lxZbUEZEs/1u05P/Zm7T9ezY8W5GtsXzTaY96NJ/PhksjnQl9x9HnadNWx cTQCObr34jF7frx/WSelSqFMtM9MhrWIvfcA85EYhYphGuBONqJDe9RZDWb/6vKzX5CK TR2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=04R/nF7ZQn0L4lmwG9K7NZhI1RIoqJtAembHuZpzcoE=; b=ghDTcxGgfxFExzQPxvGqHXKbCHJTWIE5olgpfebXElJaC79n5TVdqLGYStjPmV6fCP g4kpbkh9KmDNvkzZsp8gCZR/mDYUHEM/9onazhuAjJbouJVG2Qp7hW/1rbITgeBYbd6p Nu0q5UY4khf2ZDmy+QFEcfWwbu6HArwlsuChnoH4QdNjYXdbWCWbLO7mhzdmKQkXr0sI VSPnifsp3YdVID+fCgcsMCsPBQy7al7Gb6QyKqr0nGHsdl+Egj7J5j72ODEsA1smpDmb 04k7aMCfaauT4YoTy5/rRvvjmMGlXyKXgnMLBpODJ0C7x6xvS1Vbr5l2nkEUxaW6fmTV ckTg== X-Gm-Message-State: AOAM532oNFdvpE2lsRy6jXo7WYaPFZS0oWMlglaLoERWZmXM2bwsIYaw MxJ8LvCYyEZG1i3gaXh4ILo= X-Received: by 2002:a63:7112:: with SMTP id m18mr15630957pgc.93.1631626782143; Tue, 14 Sep 2021 06:39:42 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:7:6ea2:a529:4af3:5057]) by smtp.gmail.com with ESMTPSA id v13sm10461234pfm.16.2021.09.14.06.39.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:39:41 -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, gregkh@linuxfoundation.org, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, brijesh.singh@amd.com, Tianyu.Lan@microsoft.com, thomas.lendacky@amd.com, pgonda@google.com, akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, rppt@kernel.org, sfr@canb.auug.org.au, aneesh.kumar@linux.ibm.com, saravanand@fb.com, krish.sadhukhan@oracle.com, xen-devel@lists.xenproject.org, tj@kernel.org, rientjes@google.com, 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, parri.andrea@gmail.com, dave.hansen@intel.com Subject: [PATCH V5 07/12] Drivers: hv: vmbus: Add SNP support for VMbus channel initiate message Date: Tue, 14 Sep 2021 09:39:08 -0400 Message-Id: <20210914133916.1440931-8-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210914133916.1440931-1-ltykernel@gmail.com> References: <20210914133916.1440931-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 The monitor pages in the CHANNELMSG_INITIATE_CONTACT msg are shared with host in Isolation VM and so it's necessary to use hvcall to set them visible to host. In Isolation VM with AMD SEV SNP, the access address should be in the extra space which is above shared gpa boundary. So remap these pages into the extra address(pa + shared_gpa_boundary). Introduce monitor_pages_original[] in the struct vmbus_connection to store monitor page virtual address returned by hv_alloc_hyperv_ zeroed_page() and free monitor page via monitor_pages_original in the vmbus_disconnect(). The monitor_pages[] is to used to access monitor page and it is initialized to be equal with monitor_pages_ original. The monitor_pages[] will be overridden in the isolation VM with va of extra address. Introduce monitor_pages_pa[] to store monitor pages' physical address and use it to populate pa in the initiate msg. Signed-off-by: Tianyu Lan --- Change since v4: * Introduce monitor_pages_pa[] to store monitor pages' physical address and use it to populate pa in the initiate msg. * Move code of mapping moniter pages in extra address into vmbus_connect(). Change since v3: * Rename monitor_pages_va with monitor_pages_original * free monitor page via monitor_pages_original and monitor_pages is used to access monitor page. Change since v1: * Not remap monitor pages in the non-SNP isolation VM. --- drivers/hv/connection.c | 90 ++++++++++++++++++++++++++++++++++++--- drivers/hv/hyperv_vmbus.h | 2 + 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 8820ae68f20f..edd8f7dd169f 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include "hyperv_vmbus.h" @@ -102,8 +104,9 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) vmbus_connection.msg_conn_id = VMBUS_MESSAGE_CONNECTION_ID; } - msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]); - msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]); + msg->monitor_page1 = vmbus_connection.monitor_pages_pa[0]; + msg->monitor_page2 = vmbus_connection.monitor_pages_pa[1]; + msg->target_vcpu = hv_cpu_number_to_vp_number(VMBUS_CONNECT_CPU); /* @@ -216,6 +219,65 @@ int vmbus_connect(void) goto cleanup; } + vmbus_connection.monitor_pages_original[0] + = vmbus_connection.monitor_pages[0]; + vmbus_connection.monitor_pages_original[1] + = vmbus_connection.monitor_pages[1]; + vmbus_connection.monitor_pages_pa[0] + = virt_to_phys(vmbus_connection.monitor_pages[0]); + vmbus_connection.monitor_pages_pa[1] + = virt_to_phys(vmbus_connection.monitor_pages[1]); + + if (hv_is_isolation_supported()) { + vmbus_connection.monitor_pages_pa[0] += + ms_hyperv.shared_gpa_boundary; + vmbus_connection.monitor_pages_pa[1] += + ms_hyperv.shared_gpa_boundary; + + ret = set_memory_decrypted((unsigned long) + vmbus_connection.monitor_pages[0], + 1); + ret |= set_memory_decrypted((unsigned long) + vmbus_connection.monitor_pages[1], + 1); + if (ret) + goto cleanup; + + /* + * Isolation VM with AMD SNP needs to access monitor page via + * address space above shared gpa boundary. + */ + if (hv_isolation_type_snp()) { + vmbus_connection.monitor_pages[0] + = memremap(vmbus_connection.monitor_pages_pa[0], + HV_HYP_PAGE_SIZE, + MEMREMAP_WB); + if (!vmbus_connection.monitor_pages[0]) { + ret = -ENOMEM; + goto cleanup; + } + + vmbus_connection.monitor_pages[1] + = memremap(vmbus_connection.monitor_pages_pa[1], + HV_HYP_PAGE_SIZE, + MEMREMAP_WB); + if (!vmbus_connection.monitor_pages[1]) { + ret = -ENOMEM; + goto cleanup; + } + } + + /* + * Set memory host visibility hvcall smears memory + * and so zero monitor pages here. + */ + memset(vmbus_connection.monitor_pages[0], 0x00, + HV_HYP_PAGE_SIZE); + memset(vmbus_connection.monitor_pages[1], 0x00, + HV_HYP_PAGE_SIZE); + + } + msginfo = kzalloc(sizeof(*msginfo) + sizeof(struct vmbus_channel_initiate_contact), GFP_KERNEL); @@ -303,10 +365,26 @@ void vmbus_disconnect(void) vmbus_connection.int_page = NULL; } - hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[0]); - hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[1]); - vmbus_connection.monitor_pages[0] = NULL; - vmbus_connection.monitor_pages[1] = NULL; + if (hv_is_isolation_supported()) { + memunmap(vmbus_connection.monitor_pages[0]); + memunmap(vmbus_connection.monitor_pages[1]); + + set_memory_encrypted((unsigned long) + vmbus_connection.monitor_pages_original[0], + 1); + set_memory_encrypted((unsigned long) + vmbus_connection.monitor_pages_original[1], + 1); + } + + hv_free_hyperv_page((unsigned long) + vmbus_connection.monitor_pages_original[0]); + hv_free_hyperv_page((unsigned long) + vmbus_connection.monitor_pages_original[1]); + vmbus_connection.monitor_pages_original[0] = + vmbus_connection.monitor_pages[0] = NULL; + vmbus_connection.monitor_pages_original[1] = + vmbus_connection.monitor_pages[1] = NULL; } /* diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 42f3d9d123a1..560cba916d1d 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -240,6 +240,8 @@ struct vmbus_connection { * is child->parent notification */ struct hv_monitor_page *monitor_pages[2]; + void *monitor_pages_original[2]; + unsigned long monitor_pages_pa[2]; struct list_head chn_msg_list; spinlock_t channelmsg_lock; -- 2.25.1