Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5309551pxv; Wed, 28 Jul 2021 07:55:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNNVCHuJBATFmHTGaW+rLFWJdON0jmBJu8Qwbh1GU7EEK3Vhf39Snvbji014q/88HKukDh X-Received: by 2002:a05:6402:b2a:: with SMTP id bo10mr217568edb.215.1627484146397; Wed, 28 Jul 2021 07:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627484146; cv=none; d=google.com; s=arc-20160816; b=i1bXHyxj7XLTwWM/PF6rgxZOPGMQmNtCV6CwIcLe/HJ6qbwxAinZuhgRFpuoGiKqV3 0LFQeqG5jEP8nlg4qyNneLHWuARE8gQzDdMtIoyElQApPKUmOPonnuV3t/fZF8L5hjKF F8FGgYU3JpmSGsnBl4JW9PfSC8rDAxWeuuIZZ/Stk/eJZYmGSAq/8qKlssN3ygmO8Y/v xGzLQ+LXmfaJ3g+9pJwc3YommQ0VULob38pmA9U7gjoX988YSdSa6YiA0UPhE0ef20hr TaPnnWnA5tF/h+T4FDiPRYZspYuxe5ZtoCpFJWMMJ3G/G2t2T/Bc6JEWqHYE04CEABcX ZhDA== 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=+XJfA3AqCHkXuREWq5JYX1SJ1GS8dmwfVs7cs/uDyzo=; b=QKgYRZNAejsZiLCSp9ejW76iF0Gmpxj8ysTdYUmoIFrjxmqsc32uxNxJhAg4q+ymE2 DePVXQT0LDZhq1j+JxUUA+j/HsJqa5K/sWFOReOyDvpVtqZaR0ANsnqeZZ61kdM9skia oKidhc/hkdGzXG0g5uB70eXVJO6DdDuHo0rslakG7iY8RKRt+V99Bx4DPzxmKuG5zXWR 5QK029rmGAc/UGhTD8GDSKU1CSgA50HWVhV2PgTDKOTGWOZxtTh5w/tticp3ZQSDFlCH +6uVn/xTJgfFeh10ZgHWtGFfUlYFvZunM3AMIg2YHaCXkwhfnLYRDA7DxMzcGBnGlryQ M9Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JTfxH2MI; 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 hr12si30520ejc.464.2021.07.28.07.55.21; Wed, 28 Jul 2021 07:55:46 -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=JTfxH2MI; 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 S235521AbhG1Ox2 (ORCPT + 99 others); Wed, 28 Jul 2021 10:53:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236711AbhG1OxS (ORCPT ); Wed, 28 Jul 2021 10:53:18 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E021C061757; Wed, 28 Jul 2021 07:53:17 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id z3so1675465plg.8; Wed, 28 Jul 2021 07:53:17 -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=+XJfA3AqCHkXuREWq5JYX1SJ1GS8dmwfVs7cs/uDyzo=; b=JTfxH2MI6lr3vhghm+bYn1lDtWC6S40YgGpd2n5ZBE0WXJ57nPRp/vMeCnq6SmO90h UPiRb39uM4iMAgW0slMgb6ATsLC4Z0lW9pf+AZc7pl5WJGMDawbbzgXKBt1Z+GuOXtly 9TYhzeKXWg55tjzDSrNqnVlbyUVgZ1VhgspLUJ3MDp7VmLIaFpFkVzlACYJoXgx4h9W9 y5VivpznJ4FNs2S4rqNSmRUG+RlcTHOQjC6dLg1qrzPm0TcGvPf/VqvCVComHCJhCA2P 7AXzP0K57z4DE458hjOtv6x4NMiUz3iK84iyApsE6NxjF0AupgOoBJTCCu7r53H4pSie WfpA== 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=+XJfA3AqCHkXuREWq5JYX1SJ1GS8dmwfVs7cs/uDyzo=; b=k84UzRKtHJWuypJ3r4D8vqla2lnKLsy1UVW7CFD/cziM68EK1ADWojea3SK91C5eIp 2hwjV7KqhjdGHkS9zOlndhCiubZUZpnjdthM/1aF2gVGXt3y6rrif5M/FlozV868ejD8 ET5uPFaewBRLYGccObYIRbEHQI7o+yx3TrKyeBQ9u9axLh0+9E7WtMwdlwmVo+chYBcX 7+9nIa4NBo3YcR5d/FsK19ehL09mtyjfpD3C8qK4R2TljfNExPUp5VKYO061ADBJrOGL 41iiCfYtTHLORliTL7REiM4Ybycp3NPaFmIAvo4pj5k30FvG9MHXnxNC7kt+XGV6k3fZ NB2g== X-Gm-Message-State: AOAM531TRGRmQi94+tY77ANaywep4RxkYcigurGz+KdF7t+YzEuJpdh1 v+w6Xie5RXxawfhqkDCMKjA= X-Received: by 2002:a65:654c:: with SMTP id a12mr224730pgw.118.1627483996980; Wed, 28 Jul 2021 07:53:16 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:0:3823:141e:6d51:f0ad]) by smtp.gmail.com with ESMTPSA id n134sm277558pfd.89.2021.07.28.07.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 07:53:16 -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, thomas.lendacky@amd.com, brijesh.singh@amd.com, ardb@kernel.org, Tianyu.Lan@microsoft.com, rientjes@google.com, martin.b.radev@gmail.com, akpm@linux-foundation.org, rppt@kernel.org, kirill.shutemov@linux.intel.com, aneesh.kumar@linux.ibm.com, krish.sadhukhan@oracle.com, saravanand@fb.com, xen-devel@lists.xenproject.org, pgonda@google.com, david@redhat.com, keescook@chromium.org, hannes@cmpxchg.org, sfr@canb.auug.org.au, 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, anparri@microsoft.com Subject: [PATCH 04/13] HV: Mark vmbus ring buffer visible to host in Isolation VM Date: Wed, 28 Jul 2021 10:52:19 -0400 Message-Id: <20210728145232.285861-5-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210728145232.285861-1-ltykernel@gmail.com> References: <20210728145232.285861-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 Mark vmbus ring buffer visible with set_memory_decrypted() when establish gpadl handle. Signed-off-by: Tianyu Lan --- drivers/hv/channel.c | 38 ++++++++++++++++++++++++++++++++++++-- include/linux/hyperv.h | 10 ++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index f3761c73b074..01048bb07082 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -465,7 +466,7 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, struct list_head *curr; u32 next_gpadl_handle; unsigned long flags; - int ret = 0; + int ret = 0, index; next_gpadl_handle = (atomic_inc_return(&vmbus_connection.next_gpadl_handle) - 1); @@ -474,6 +475,13 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, if (ret) return ret; + ret = set_memory_decrypted((unsigned long)kbuffer, + HVPFN_UP(size)); + if (ret) { + pr_warn("Failed to set host visibility.\n"); + return ret; + } + init_completion(&msginfo->waitevent); msginfo->waiting_channel = channel; @@ -539,6 +547,15 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, /* At this point, we received the gpadl created msg */ *gpadl_handle = gpadlmsg->gpadl; + if (type == HV_GPADL_BUFFER) + index = 0; + else + index = channel->gpadl_range[1].gpadlhandle ? 2 : 1; + + channel->gpadl_range[index].size = size; + channel->gpadl_range[index].buffer = kbuffer; + channel->gpadl_range[index].gpadlhandle = *gpadl_handle; + cleanup: spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_del(&msginfo->msglistentry); @@ -549,6 +566,11 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, } kfree(msginfo); + + if (ret) + set_memory_encrypted((unsigned long)kbuffer, + HVPFN_UP(size)); + return ret; } @@ -811,7 +833,7 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) struct vmbus_channel_gpadl_teardown *msg; struct vmbus_channel_msginfo *info; unsigned long flags; - int ret; + int ret, i; info = kzalloc(sizeof(*info) + sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL); @@ -859,6 +881,18 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); kfree(info); + + /* Find gpadl buffer virtual address and size. */ + for (i = 0; i < VMBUS_GPADL_RANGE_COUNT; i++) + if (channel->gpadl_range[i].gpadlhandle == gpadl_handle) + break; + + if (set_memory_encrypted((unsigned long)channel->gpadl_range[i].buffer, + HVPFN_UP(channel->gpadl_range[i].size))) + pr_warn("Fail to set mem host visibility.\n"); + + channel->gpadl_range[i].gpadlhandle = 0; + return ret; } EXPORT_SYMBOL_GPL(vmbus_teardown_gpadl); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 2e859d2f9609..06eccaba10c5 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -809,6 +809,14 @@ struct vmbus_device { #define VMBUS_DEFAULT_MAX_PKT_SIZE 4096 +struct vmbus_gpadl_range { + u32 gpadlhandle; + u32 size; + void *buffer; +}; + +#define VMBUS_GPADL_RANGE_COUNT 3 + struct vmbus_channel { struct list_head listentry; @@ -829,6 +837,8 @@ struct vmbus_channel { struct completion rescind_event; u32 ringbuffer_gpadlhandle; + /* GPADL_RING and Send/Receive GPADL_BUFFER. */ + struct vmbus_gpadl_range gpadl_range[VMBUS_GPADL_RANGE_COUNT]; /* Allocated memory for ring buffer */ struct page *ringbuffer_page; -- 2.25.1