From patchwork Mon May 15 16:59:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 94240 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp7082928vqo; Mon, 15 May 2023 10:33:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4bqbtwiESMGXpgGE5NIh4JN37ZlCQDvnVUI+3GuLrp/gvTAvrzz8yOfISQMNXBVSQSx62B X-Received: by 2002:a17:902:e888:b0:1ad:d500:19d3 with SMTP id w8-20020a170902e88800b001add50019d3mr18011734plg.23.1684172012761; Mon, 15 May 2023 10:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684172012; cv=none; d=google.com; s=arc-20160816; b=KLRxeblDtuAQ4NFmfDAEU7GC0MNnC3UBvpp8yxpoZnCQAO/aWWPffY4ncgl6rs/Z9J P/yypn7FLkEW4748vYfCtetrP6aWQwhZjtz94Cuc5roWj+ad/kTlIRVIQLWOUR2UwKoz YNNr7IqQ8JckVlDpy+E8+jT2obi/UDkqRF0q+CizbDKNgziY9RUZxyVt9yz++12mHZz4 GSbBkEuNocGOJFObb9bw5jX7i63MdTKugJQbNwEKJE5Gp5EZDrFUgk2D8KD8Wbkk5Xyh DQa+3rTVE6Blzzx2FAnhAuxDv4NTEGGFzIdamfHCFdamYpEEpKw5SBXsYOh7+fdh9l59 S2nQ== 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=6zQXnge0b5ZqyPL5Rd5uANtDut+QBzK0iKFoX0pFkxQ=; b=FgWT1cEZporOFHZxPL6d76NKEktp46dtwQrF3oxfIXLrMm0AdrljMHm3H2/1QxShFe Fk41rrfFsCQm0+tr1+wQx/BLFseZLNPhXN6HMP02FHxZ0g/dkmjOGCXphygT5asPS0zc U5xqY5sEek5v6VCX3DCScbrXcbQGV1XdzgTKW50MIuRll7V50YDFpi+XyuyYdwGNMqMi OYQQAK6NfnNMo2bg4DF0y8+b4q2c/RdWURAtup5dTAhLYX4ACD1kFqzVUV1OMowH4KHX UAZUdpl4dN7urs8y0eE29gNSBpt5w0vdjALX4L+EUg676Av4t7z4vfBM1RRBKaUSzMO8 drwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=BvU+b2eS; 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 ix18-20020a170902f81200b001a6b9ab7025si16073585plb.359.2023.05.15.10.33.18; Mon, 15 May 2023 10:33:32 -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=BvU+b2eS; 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 S243387AbjEORAZ (ORCPT + 99 others); Mon, 15 May 2023 13:00:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243419AbjEOQ7w (ORCPT ); Mon, 15 May 2023 12:59:52 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECD0A7EEA; Mon, 15 May 2023 09:59:40 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-24e01ba9e03so8921038a91.1; Mon, 15 May 2023 09:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684169980; x=1686761980; 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=6zQXnge0b5ZqyPL5Rd5uANtDut+QBzK0iKFoX0pFkxQ=; b=BvU+b2eSYafA1CZTNC996wjbIPyvv1JH75praEmQOdo9/xKZDc9oZ/t4Rp2Lc/ZYF6 ir/dYi8ZeZgOtkG+k9ct1MCVTw7eHFUParr+xk87Cntnv1XY/978lHlR2sQN/rRNQgz6 4hA9Bt/5l0BT9Kq+Q29ui+v/3Ril4eZ6u9RqKb6lbmcM587rs9MQ4XOCqOyiHnxoH2IN 1FfBen7YgCx8lobJKl4Gf9Ek/cNN6z6U2UswRbm71IrEx95MfPo5QF98+M10wbbHv++P zPZay86Z8Ce7g6e8SGZ6smJSqPLehsNMzv4jkrXVUqbpzR3kjFqgEp83+/FXj8Q3BYKk wTgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684169980; x=1686761980; 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=6zQXnge0b5ZqyPL5Rd5uANtDut+QBzK0iKFoX0pFkxQ=; b=ePbo/n/qJlwO1ejG2DZXwJGJdb/azBz/oZ2hLXUIk84Me835TLZ6lIbpeF8EspeBiB /QWZ2d8NgQl+USgG1JmTy3tly7qwG9l7bg09IaARo4E65KTtjrKsgBWIPQeYbhQCbDl5 AFe0GheVU1fsI16BY3jZVboDIC3zSoCuJXCNdTi1aVdbeexFgyuAiu9iBrZC14Wfe+8R 9NcJ2/bZqUHS2zKf/wfPKEH3p2G+SNmwfA4ytK7Gvku++SxAsW9HkPldOd7bHzucbb/l 0TtVnGIz2Kg79f1lZ2dpSzhXvxBW0a4tP5KWFj/4z/isLWJARIckJrk09CpqNrMgX3PI WkEQ== X-Gm-Message-State: AC+VfDzxm3WYSr9S62V3EctHTTUl3W13S095GqqLizLfP3jEKjTLa5Y5 +s/AxIn7jXMndNsc4Z2KIu8= X-Received: by 2002:a17:90a:de91:b0:24b:2f85:13eb with SMTP id n17-20020a17090ade9100b0024b2f8513ebmr33622082pjv.30.1684169980288; Mon, 15 May 2023 09:59:40 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:f:85bb:dfc8:391f:ff73]) by smtp.gmail.com with ESMTPSA id x13-20020a17090aa38d00b0024df6bbf5d8sm2151pjp.30.2023.05.15.09.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 09:59:39 -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 V6 10/14] hv: vmbus: Mask VMBus pages unencrypted for sev-snp enlightened guest Date: Mon, 15 May 2023 12:59:12 -0400 Message-Id: <20230515165917.1306922-11-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230515165917.1306922-1-ltykernel@gmail.com> References: <20230515165917.1306922-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?1765982352627139391?= X-GMAIL-MSGID: =?utf-8?q?1765982352627139391?= From: Tianyu Lan VMBus post msg, synic event and message pages is necessary to shared with hypervisor and so mask these pages unencrypted 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 | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index de6708dbe0df..d29bbf0c7108 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,29 @@ 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_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 +164,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);