From patchwork Mon May 1 08:57:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 88996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2563033vqo; Mon, 1 May 2023 02:00:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6S7XAWZbjc7RbJy8Vtwg/7mBsACx6GU2y83LXtFpLKXYvYyzs2QMsj1npQI8SeycvsbPXx X-Received: by 2002:a05:6a20:244b:b0:f6:442f:37c9 with SMTP id t11-20020a056a20244b00b000f6442f37c9mr16729260pzc.39.1682931605155; Mon, 01 May 2023 02:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682931605; cv=none; d=google.com; s=arc-20160816; b=XPw85RsCCZ81Vw6N5j63qiq7MPUghqMqm4Oo2LEw6P7xzS4kiTVccxPpVgJFnfpq7g O7m5dygLkmo6q9XiBIb0q98u4USPzi0H4Xss8Adkj6RlVZZKB4sCPcK5QmcHy9sIncpM yoXzdAfhCQgYi3rrI5MFg/ezYI5a4dW8tGKbTa52lJKJJOqm+/SwhJ0U9mOFr2vBASzw htmUPwa7oWWbhYQurGAMaqoBDkb3lVAzgLNB4K/fqxI+YqnlNhLIXSRNjcQ874q7nkfm yGvzpxJSsvv3mdKqgrWKTMWCXWmEg4CHCTl7RIPd3Aep1e7bXvzsAagrqpdlDIW4aqaL GSqg== 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=v9rBUX8zxYLON2WeixMYcynqQit4QqOsD7fiqT8bXlg=; b=FUmOj4vu7g7kwi9bdEXJPor30/MyNfW7LODCQwwF5EKirHP9pvUQcBHmofLcjGmZrK e1c4MEbn4A2mDsqbmVWUwBqMgqCH5MzdvjW4rUIazje2juNWp1yy8diIYeQYJK8K9S7g /BDYodlF9Y5iVY6yOPOK5nqZnFH++x6A7JOIphokh2feGZRzeUwiBMmlOq7ThoctFxmR rj+xuzsFwgUfSC+GsJvA7XU7XJqqWxG0MvuPTKkDGyYQYo/woPIFuJwUi8AlegJJeo0/ f4HHwdVCA1bVq9zWkXRQMaVFnNFOLYbAlPmdWuRxr8ygIbqHzlYq11zcR7kQ1WvzJoVy 3Dlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ozIKeWZG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q188-20020a632ac5000000b00528808c5f63si13723572pgq.169.2023.05.01.01.59.52; Mon, 01 May 2023 02:00:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ozIKeWZG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232402AbjEAI56 (ORCPT + 99 others); Mon, 1 May 2023 04:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232330AbjEAI5k (ORCPT ); Mon, 1 May 2023 04:57:40 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD02C10E7; Mon, 1 May 2023 01:57:38 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1aaef97652fso6860855ad.0; Mon, 01 May 2023 01:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682931458; x=1685523458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v9rBUX8zxYLON2WeixMYcynqQit4QqOsD7fiqT8bXlg=; b=ozIKeWZGvO83qG/cO/jf8e1+md4Qe61e7BWRvVR0LTuFi7buO0Fcf+2hPdnr2F/BMo GW5YSzUDtx5XEJfQIYgOqSRHQbZ/RBZEHR2pVmpOoz4GjvaqgkJcwFBqJxy08OoO3Bic tdHcV4Sy/lyzse6vbOHhgsE8qxwmQqW5+BaHlBG3C7EdnzL4Dv/tyJjgQN6a9OuYKNVO MCWO1nJo9qgFdJrLmOId9XwLXOcPEi5CLNQ7De6LavPg7EIzwtiph2AmG13Ky0LylGNk eUMGhnFeaxt1N8yN+1yDiaFipBvisaTZwRexB05/+8L/cLvQis8EFH0siEIG5V4QYznW OLLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682931458; x=1685523458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v9rBUX8zxYLON2WeixMYcynqQit4QqOsD7fiqT8bXlg=; b=I2wOnIBDvhHP6A9BUkoAv1ek7a7Bm13o1BTXtYf3Ejj61fCJNenw2EhoVhnEses8kr vfv6RC8MprDlEHwhS3TOky+REa+i7PtZDPL7Ad0YEJgKl8AiZKGSyVD3w7F7m2MxFBKV sI0DEEINzpq4BnFqvP5bgPuq5f/7qtBXxmyAYxl2u76LTfmi9nxVR38WeuJyW0pw9f4T 0OHH+qfMz7aYDc/8YVtpff0MtseMoq/Iz64150FS/6q2jHtTE9cqc0rbD+wX0cPPwRzC +K1hLmQgn1qDZ1wBEuxNaTuYU6m4M+V0o3Xuywa8bUXsD1u2Y9t3WrgexBIIct0wfiYB wFsQ== X-Gm-Message-State: AC+VfDzlSOCFRIAqkVXlzvnJ7541ZM5BX1UUZq7fU//p4JCyUI38O7gS QviInTRJa5EYLatENCgBmd4= X-Received: by 2002:a17:902:ec8a:b0:1a2:afdd:8476 with SMTP id x10-20020a170902ec8a00b001a2afdd8476mr16497385plg.2.1682931458294; Mon, 01 May 2023 01:57:38 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:b:e11b:15ea:ad44:bde7]) by smtp.gmail.com with ESMTPSA id t13-20020a1709028c8d00b001a4fe00a8d4sm17407070plo.90.2023.05.01.01.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 01:57:37 -0700 (PDT) From: Tianyu Lan To: luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, jgross@suse.com, tiala@microsoft.com, kirill@shutemov.name, jiangshan.ljs@antgroup.com, peterz@infradead.org, ashish.kalra@amd.com, srutherford@google.com, akpm@linux-foundation.org, anshuman.khandual@arm.com, pawan.kumar.gupta@linux.intel.com, adrian.hunter@intel.com, daniel.sneddon@linux.intel.com, alexander.shishkin@linux.intel.com, sandipan.das@amd.com, ray.huang@amd.com, brijesh.singh@amd.com, michael.roth@amd.com, thomas.lendacky@amd.com, venu.busireddy@oracle.com, sterritt@google.com, tony.luck@intel.com, samitolvanen@google.com, fenghua.yu@intel.com Cc: pangupta@amd.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org Subject: [RFC PATCH V5 06/15] hv: vmbus: decrypt VMBus pages for sev-snp enlightened guest Date: Mon, 1 May 2023 04:57:16 -0400 Message-Id: <20230501085726.544209-7-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230501085726.544209-1-ltykernel@gmail.com> References: <20230501085726.544209-1-ltykernel@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764681690790497140?= X-GMAIL-MSGID: =?utf-8?q?1764681690790497140?= From: Tianyu Lan VMBus post msg, synic event and message pages are shared with hypervisor and so decrypt these pages in the sev-snp guest. Signed-off-by: Tianyu Lan --- Change sicne RFC V4: * Fix encrypt and free page order. Change since RFC V3: * Set encrypt page back in the hv_synic_free() Change since RFC V2: * Fix error in the error code path and encrypt pages correctly when decryption failure happens. --- drivers/hv/hv.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index de6708dbe0df..e0943db51acd 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "hyperv_vmbus.h" /* The one and only */ @@ -78,7 +79,7 @@ int hv_post_message(union hv_connection_id connection_id, int hv_synic_alloc(void) { - int cpu; + int cpu, ret; struct hv_per_cpu_context *hv_cpu; /* @@ -123,9 +124,33 @@ int hv_synic_alloc(void) goto err; } } + + if (hv_isolation_type_en_snp()) { + ret = set_memory_decrypted((unsigned long) + hv_cpu->synic_message_page, 1); + if (ret) + goto err; + + ret = set_memory_decrypted((unsigned long) + hv_cpu->synic_event_page, 1); + if (ret) + goto err_decrypt_event_page; + + memset(hv_cpu->synic_message_page, 0, PAGE_SIZE); + memset(hv_cpu->synic_event_page, 0, PAGE_SIZE); + } } return 0; + +err_decrypt_msg_page: + set_memory_encrypted((unsigned long) + hv_cpu->synic_event_page, 1); + +err_decrypt_event_page: + set_memory_encrypted((unsigned long) + hv_cpu->synic_message_page, 1); + err: /* * Any memory allocations that succeeded will be freed when @@ -143,8 +168,18 @@ void hv_synic_free(void) struct hv_per_cpu_context *hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu); - free_page((unsigned long)hv_cpu->synic_event_page); - free_page((unsigned long)hv_cpu->synic_message_page); + if (hv_isolation_type_en_snp()) { + if (!set_memory_encrypted((unsigned long) + hv_cpu->synic_message_page, 1)) + free_page((unsigned long)hv_cpu->synic_event_page); + + if (!set_memory_encrypted((unsigned long) + hv_cpu->synic_event_page, 1)) + free_page((unsigned long)hv_cpu->synic_message_page); + } else { + free_page((unsigned long)hv_cpu->synic_event_page); + free_page((unsigned long)hv_cpu->synic_message_page); + } } kfree(hv_context.hv_numa_map);