From patchwork Mon Apr 3 17:43:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 78662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2476332vqo; Mon, 3 Apr 2023 10:46:25 -0700 (PDT) X-Google-Smtp-Source: AKy350Zb5NO8QXqZlVpwrRV2Lg26lsW2U3fVJdIts2/lREG+srgJdar3LdKrxxHMgMX5bAXt7/io X-Received: by 2002:aa7:cad9:0:b0:502:4875:721 with SMTP id l25-20020aa7cad9000000b0050248750721mr60604edt.15.1680543984932; Mon, 03 Apr 2023 10:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680543984; cv=none; d=google.com; s=arc-20160816; b=A/8SgQjYD3EmaiXzMcvNrkPeHMfSW8vx/sf3XvgR1tGbaKsPl/tXoqE4Plp5IwJpy3 KJfUTj03hpZyk5zOYeGFkSTrTltQyoJ7AdkX+BdJmn6n9uOcoYo7cVcoSxl01v9L6LZU Rj1bp+tDBRz7TfsQTEu3siAK1o2ugwj2Zk0w0VFJJMhMJHZzFMv9V3UkzCDy4Y9sn7oy pV7I7+03kfEj0nfpGbKc238MPYdJkUdmeBAMzPXegwGhZzuRdKjZdg6mYQyHjoPQMiij w9+Kh7huxkyLsNPj4CmzWhf1Js0Z/xd43W5ag3HaTfhphTB5mDysKjRR79izOwoXJfIh 6VcA== 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=IOp+J/MlPfipkIt8hJ1o3RldVOHyWVonLkOqsh7nnxE=; b=Ca5InyHZ04atYfJ0NtmCrOPWJ3hxzZbN7rvWQdAwPj5qmqCeQsDU1T39nm6PYoVMi2 Lv4axx8OaTRV0YD/meTLarcXddwjhkIjlmJ+uc7e2IeySw35Tdxv/mM4n7zWblwvElJf JQqzspDt9op4XOfclxzkGjrQFV9FZrWfVMJ1vol1ll/D59QYUycSVQFl/sDh2U+EsWvJ ylvyxwnz5opxKT/7ZwIyNZUN3nHNhJfjzW0DtddRDpdqRrEvz5i6/msJLClS/S5ZAY54 q95+f8czn9r9SiDbwa1ts6YKValt/C1YoJzCRmYwhQmN6n3hrfCJLn8OWDTzdJdGXS2i +JTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cNHdFhG1; 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 e15-20020a50ec8f000000b00500748a37b9si6956138edr.249.2023.04.03.10.46.00; Mon, 03 Apr 2023 10:46:24 -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=20210112 header.b=cNHdFhG1; 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 S232446AbjDCRoj (ORCPT + 99 others); Mon, 3 Apr 2023 13:44:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232109AbjDCRoT (ORCPT ); Mon, 3 Apr 2023 13:44:19 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA0642D74; Mon, 3 Apr 2023 10:44:18 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id j13so27980318pjd.1; Mon, 03 Apr 2023 10:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680543858; 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=IOp+J/MlPfipkIt8hJ1o3RldVOHyWVonLkOqsh7nnxE=; b=cNHdFhG1ku6DUDGidsm1yJOL/aAIk1oglkPnxeY7og8ZgkiM+b3Pv24z5fzscyI+os qzhTSEuFFXMfpi09zy7sPw8B6SXXsLMWC3+SHcg0WImPp+0Sz3TbPyySkpGliNacOBRX /PL69a5eFxhM+r2UHZGd7le+Mvs76NrUJxg0yXEbRpru7AFS3LV45Bc6S0KHvn2Rmko8 dMHFTU9IDosPlLpsldPWD0M0bHltEFRmpnaGECmcRFlB/nq78Du61dNx0ERORHQKsufp NSbGnU0V3q10kfriRRm8zOL8hjiJMQ3H6pn7c5VdClkRM3CApaxFZLKxOOKovWXwHvr7 +lLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680543858; 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=IOp+J/MlPfipkIt8hJ1o3RldVOHyWVonLkOqsh7nnxE=; b=yYoCWEFGzBP1fsQtlclz0KCkA5OHe0amxTK42FYOWOOg8t+Xqfbf7dZ9Srj6mONd6v YXzV+WPMQE/zmyR6jBo6zPA2Sfwx6PtAGwd1nqbbwP+bUubF88e5FJJbOrCY8J1OsVJy CGewKSFeqgjzrZPxpFuXAyWH1/8qvtrjVsI5BA+3GEsCQPzuo9qid5NcY6vLbtKKwaQF FH7utvCP1GO/xjPD9hPbZQHyTKw0UIG5WtIRmrVM4IDpMKvBjlMaUskIDZcia6LnYbsN Cj5vNDSpdQ00dhjqbNQDRvaxVnK0BXMVHgRsSfYLUKYM9kQAFm5ZH+17Wk35qyWfiYdV eoBA== X-Gm-Message-State: AAQBX9cur3AZJ5SkuTQ9QjR++KaJiiGsxpNKzT1twNljQjmj/XGQJIec C04XcIf5BMp35L0QOuBMNFY= X-Received: by 2002:a17:90b:1e43:b0:23f:8752:98be with SMTP id pi3-20020a17090b1e4300b0023f875298bemr43385277pjb.4.1680543858196; Mon, 03 Apr 2023 10:44:18 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:2:8635:6e96:35c1:c560]) by smtp.gmail.com with ESMTPSA id jj21-20020a170903049500b001a19196af48sm6883803plb.64.2023.04.03.10.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 10:44:17 -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 V4 06/17] x86/hyperv: decrypt VMBus pages for sev-snp enlightened guest Date: Mon, 3 Apr 2023 13:43:54 -0400 Message-Id: <20230403174406.4180472-7-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230403174406.4180472-1-ltykernel@gmail.com> References: <20230403174406.4180472-1-ltykernel@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1762178089322069999?= X-GMAIL-MSGID: =?utf-8?q?1762178089322069999?= 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 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 | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 008234894d28..e09cea8f2f04 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 */ @@ -117,7 +118,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; /* @@ -168,9 +169,39 @@ int hv_synic_alloc(void) pr_err("Unable to allocate post msg page\n"); 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; + + ret = set_memory_decrypted((unsigned long) + hv_cpu->post_msg_page, 1); + if (ret) + goto err_decrypt_msg_page; + + memset(hv_cpu->synic_message_page, 0, PAGE_SIZE); + memset(hv_cpu->synic_event_page, 0, PAGE_SIZE); + memset(hv_cpu->post_msg_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 @@ -191,6 +222,15 @@ void hv_synic_free(void) free_page((unsigned long)hv_cpu->synic_event_page); free_page((unsigned long)hv_cpu->synic_message_page); free_page((unsigned long)hv_cpu->post_msg_page); + + if (hv_isolation_type_en_snp()) { + set_memory_encrypted((unsigned long) + hv_cpu->synic_message_page, 1); + set_memory_encrypted((unsigned long) + hv_cpu->synic_event_page, 1); + set_memory_encrypted((unsigned long) + hv_cpu->post_msg_page, 1); + } } kfree(hv_context.hv_numa_map);