Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp71897pxb; Tue, 5 Oct 2021 23:39:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHKQpQGOAtpGjrDizd17YaRKfjE2X4RTxAfTXZBExxeAWTC3hedjxIrg4vpqEAoBBykNLS X-Received: by 2002:a05:6a00:1ac6:b0:44c:9e9:9e98 with SMTP id f6-20020a056a001ac600b0044c09e99e98mr31172798pfv.69.1633502399450; Tue, 05 Oct 2021 23:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633502399; cv=none; d=google.com; s=arc-20160816; b=GgTj+PyP1YPnWsNvazidC0gAq+JTnDcJMa8Ivnbmx/F5S9l5/lqt8amxzZx1vKe525 c6bam3lbKf2D2lm46Ompd0FHa7PUU3flWUrCfFGYIkjwOkGKkeHkFaM00T2SN2CZ6qNk rsUPCJArLjXPHWhQHALT+JJ5Vs1sq9JLLDs+3jzySt2vAFT5/YzNP0e6KTvwdzCE+Gmk TuQPCE0DPRA0H8IvAuvxJ7P2Gosdg+DzfWdIAyCVu33qVrwz/eTnfTrQKbVAUEVr6kFY xCnG09roNpxa84a0M3AjA7Ig4sXTVFWf2DqAwj1C8BavsigcX/y/Pk9dXEawdGuYrZPc pIYQ== 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=XBEgOEIOcem5paCQuIdhsRwNpRP9LBEy4PyqxTKlwF8=; b=BkGS5htPrtF34kBOtfEQLenN5yWMXkEmokednWP1k8FsH18UQ4MY6xZj/PLB1GzJJj bjsThGTUjUx1kqA7w3Z2hHhwAGVwsq4p0rr3zPuvvw5t/RrMfbIbDtERqT45wLeLA703 W68pcUC527tSxUkQd/QogIO97HSlBm8DqvTeOs76S44p3C/vyOcab/yTHr6KjQtlLONy zhDfYwcnTurAXBsGBp12+LqIbyRs6PYkCWwrNnaq33XLcj+ITbbssNu5zGce7bN0cj0x WBzjxN2cIS38D4A8cQSXx3Ldmap0JV9Cz+5cK2pJmX5Bui9Njxez1pFUZ01B+DGX1Pnj dbDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qL5aZaEX; 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 ng10si7039383pjb.110.2021.10.05.23.39.46; Tue, 05 Oct 2021 23:39:59 -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=qL5aZaEX; 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 S237436AbhJFGjk (ORCPT + 99 others); Wed, 6 Oct 2021 02:39:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237580AbhJFGjM (ORCPT ); Wed, 6 Oct 2021 02:39:12 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D9AC061783; Tue, 5 Oct 2021 23:37:07 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id j15so1028956plh.7; Tue, 05 Oct 2021 23:37:07 -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=XBEgOEIOcem5paCQuIdhsRwNpRP9LBEy4PyqxTKlwF8=; b=qL5aZaEXuiv/jKgBQDTg5x2+FH9lYARPm2Rakf2kkkEc38CqF0yW3nH5zjd4jI8865 AvVwvr4ifpcmCazIMOfXzGZyaGxWkGa0yucksQ51DnmHLHtFM4a7lZokqFsBRxT5zHpC 86k2IGghJPMWKm2zdrHT0R4vh/506NQ7R9ptXUPC/I5DRs04vmOWYz2v0z5Ibt3XbRY9 pwLu8iOrAvhUFSOA/w1WWyfrdfitEYI17dWirjR5hgLcki+pL1MN3zIAASOiCsuS3eUa Qmff+cRWToej7AJkjw5y7QdGExGrVOAO/TbpPllCoMR3CDv28r4pHw2WBB5RazQyOc49 1PmA== 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=XBEgOEIOcem5paCQuIdhsRwNpRP9LBEy4PyqxTKlwF8=; b=jPsxJj33uJ9+/GNSLDuKTH6uQPEI6tCQKAngVxNgMePaj5mLuBhpsVRM0C80q2RjtO sVj2EOtJKEuoqNS4uvw+QTTGr7NdI8aOfrW4G5t79tEBAdDfvO/0VSTojvCusR6BX/FH zFcWihLIfEc74yVA6/LBXmF08VIZMkw5AOi3e8rpMo9/F53YxPHgwm/vllRrXrxlM4kz k8DGjpqhggrygNPVf67r793HLo4pWN+e6gtESUlEJ8IPhAescOOhGu58T6rl4Bj5eXch 82UhKvAFKhlNgWTJ+eUNW4B/RYX2yg1X54+VifE1nifYNHOrBd63rcaV6mL85iPK5XPn Kc3w== X-Gm-Message-State: AOAM530MJdUV01dZNUlYdh3bhqSRgZlTYDyK8uhQgX67ppFCPiF3qkO+ m7ASXAhG5SrInZ7Bak0bWUU= X-Received: by 2002:a17:90a:e453:: with SMTP id jp19mr8933711pjb.11.1633502226830; Tue, 05 Oct 2021 23:37:06 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:357b:c418:cfef:30b1]) by smtp.gmail.com with ESMTPSA id l185sm19886413pfd.29.2021.10.05.23.37.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 23:37:06 -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, davem@davemloft.net, kuba@kernel.org, gregkh@linuxfoundation.org, arnd@arndb.de, jroedel@suse.de, 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, tj@kernel.org, aneesh.kumar@linux.ibm.com, saravanand@fb.com, hannes@cmpxchg.org, rientjes@google.com, michael.h.kelley@microsoft.com Cc: linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, vkuznets@redhat.com, konrad.wilk@oracle.com, hch@lst.de, robin.murphy@arm.com, joro@8bytes.org, parri.andrea@gmail.com, dave.hansen@intel.com Subject: [PATCH V7 8/9] Drivers: hv: vmbus: Add SNP support for VMbus channel initiate message Date: Wed, 6 Oct 2021 02:36:48 -0400 Message-Id: <20211006063651.1124737-9-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211006063651.1124737-1-ltykernel@gmail.com> References: <20211006063651.1124737-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 v6: * Add comment about calling memunmap() in the non-snp IVM. Change since v5: * change vmbus_connection.monitor_pages_pa type from unsigned long to phys_addr_t * Plus vmbus_connection.monitor_pages_pa with ms_hyperv. shared_gpa_boundary only in the IVM with AMD SEV. 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 | 95 ++++++++++++++++++++++++++++++++++++--- drivers/hv/hyperv_vmbus.h | 2 + 2 files changed, 91 insertions(+), 6 deletions(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 8820ae68f20f..a3d8be8d6cfb 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()) { + 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_pa[0] += + ms_hyperv.shared_gpa_boundary; + vmbus_connection.monitor_pages_pa[1] += + ms_hyperv.shared_gpa_boundary; + + 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,31 @@ 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() checks input address is ioremap address or not + * inside. It doesn't unmap any thing in the non-SNP CVM and + * so not check CVM type here. + */ + 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..d0a5232a1c3e 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]; + phys_addr_t monitor_pages_pa[2]; struct list_head chn_msg_list; spinlock_t channelmsg_lock; -- 2.25.1