From patchwork Thu Apr 20 08:47:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Mikhalitsyn X-Patchwork-Id: 13218150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62FCFC77B72 for ; Thu, 20 Apr 2023 08:48:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234578AbjDTIsL (ORCPT ); Thu, 20 Apr 2023 04:48:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234554AbjDTIrr (ORCPT ); Thu, 20 Apr 2023 04:47:47 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C762525A for ; Thu, 20 Apr 2023 01:47:39 -0700 (PDT) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id A13124131F for ; Thu, 20 Apr 2023 08:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1681980457; bh=RdaT2Pf0VFYL4LUkKTTIwRSg1FtfHR7MN47zcz2wKyA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=M6X/IL+6C0IANJOtuZiH/AkpBzXPe6+yAYR8X76F5aXjpBjwe5dAQElbLxK8RqCfb cp/DrNaM/O9cudEqraiOh+vNee0jH6mV1B5uigBiNV9zVNG7l8onGbey7B5maUGrhT 5ZvZo9flkWVG0/Nv1G0QtyQzbuW9+aVv8ZhSQkxzHW2ITlrCgkzkhZtd3Six8DvfGT ImuN4eRN0UuqdwX+oqKKUkWH58pC4UBz/TkXYLIs5FW86QK48CvU7cUy/Y3BgiFVT5 0XfHDXKgAAPVyEHnKB+KyZQ94cNtP60WeHmwZAcbSxtJtaR3lCTP03elKfqH7JTUkA ypJh4JiMpDBLA== Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-505149e1a4eso2021301a12.1 for ; Thu, 20 Apr 2023 01:47:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681980457; x=1684572457; 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=RdaT2Pf0VFYL4LUkKTTIwRSg1FtfHR7MN47zcz2wKyA=; b=FGtVyHvqEsBAW1Nawi+sua4rsmVHajXBigjy9aftqFMhEEuHF4S7Fg7qTDuUDtPiKH HhQg2d5N24B8YdNU7mxOxRFDtkYULKU1B67CEZzOVqNY3/5oathRkXT8E8fpLHleB15D kQv/mAF2n0tVXSapoR2Ld5ZY1IDndthk8bIuv5q0ONTZVsMJlIAJ/zC4igITzJmcvDyo tVT+GpjITL0s8tDvRjVwBxQN4Vl1unn+qemlqjgfUpvKGBq4GxCIjpvqFCIEpI+ePxBC 6B+IuNMac8/PyhNANxCNbDZVxXxtnEjwYdiLjYzAWdIe8CBweUqgXBHzMxavB6GwoPL9 fmtw== X-Gm-Message-State: AAQBX9fRWbh6/WznM9gQei//3DI31BFFxbkeVZiMV8EPt5/KZ9DxvhQv QSM+UDdkSSyRbmInuC4e6WgfmhqCtwTynXjOSUVO4hHxSrI6qw5CEugivZdAlGASpZM8deWLkmi +Q24vkljHTwzIq86HxnZvyZy2o9MGJQ== X-Received: by 2002:a05:6402:12c2:b0:506:a44c:e213 with SMTP id k2-20020a05640212c200b00506a44ce213mr594663edx.20.1681980457111; Thu, 20 Apr 2023 01:47:37 -0700 (PDT) X-Google-Smtp-Source: AKy350b5BYuHyFkiztfhJggGt3MxEYfSJc8HG66vflrM6qKXJUleuivEjOAyu1+2XykBik1RY7QhZw== X-Received: by 2002:a05:6402:12c2:b0:506:a44c:e213 with SMTP id k2-20020a05640212c200b00506a44ce213mr594650edx.20.1681980456869; Thu, 20 Apr 2023 01:47:36 -0700 (PDT) Received: from amikhalitsyn.. (ip5f5bd076.dynamic.kabel-deutschland.de. [95.91.208.118]) by smtp.gmail.com with ESMTPSA id k26-20020aa7c39a000000b005068053b53dsm500964edq.73.2023.04.20.01.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 01:47:36 -0700 (PDT) From: Alexander Mikhalitsyn To: pbonzini@redhat.com Cc: Alexander Mikhalitsyn , Sean Christopherson , =?utf-8?q?St=C3=A9phane_Graber?= , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH RESEND 1/2] KVM: SVM: free sev_*asid_bitmap init if SEV init fails Date: Thu, 20 Apr 2023 10:47:16 +0200 Message-Id: <20230420084717.111024-2-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420084717.111024-1-aleksandr.mikhalitsyn@canonical.com> References: <20230420084717.111024-1-aleksandr.mikhalitsyn@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If misc_cg_set_capacity() fails for some reason then we have a memleak for sev_reclaim_asid_bitmap/sev_asid_bitmap. It's not a case right now, because misc_cg_set_capacity() just can't fail and check inside it is always successful. But let's fix that for code consistency. Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Stéphane Graber Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Alexander Mikhalitsyn --- arch/x86/kvm/svm/sev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index c25aeb550cd9..a42536a0681a 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2213,8 +2213,13 @@ void __init sev_hardware_setup(void) } sev_asid_count = max_sev_asid - min_sev_asid + 1; - if (misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count)) + if (misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count)) { + bitmap_free(sev_reclaim_asid_bitmap); + sev_reclaim_asid_bitmap = NULL; + bitmap_free(sev_asid_bitmap); + sev_asid_bitmap = NULL; goto out; + } pr_info("SEV supported: %u ASIDs\n", sev_asid_count); sev_supported = true; From patchwork Thu Apr 20 08:47:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Mikhalitsyn X-Patchwork-Id: 13218152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8FC6C77B73 for ; Thu, 20 Apr 2023 08:48:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234536AbjDTIsf (ORCPT ); Thu, 20 Apr 2023 04:48:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234534AbjDTIrz (ORCPT ); Thu, 20 Apr 2023 04:47:55 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3CAC5599 for ; Thu, 20 Apr 2023 01:47:43 -0700 (PDT) Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 4AF6241B37 for ; Thu, 20 Apr 2023 08:47:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1681980462; bh=QUa3auAj4u9NqRTBT9WVcUeMs8DEO6WQSLZjTthBB3A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=nmCdT5ZHmnT7A7DA4OX4xBVkbWKNP2NQn2RXdz88XT988P8SQbeThehfIufYBWzw+ IeB7pea2xl5lr45vg347i0rlq+IxMunly7GWSqfmjNaU/6JGy5u2XrRRmiGkjQGmfL QHRJBeR/CYjQRFGcqDECnEcxth0/noZbFwSHWWtCf8iZg7zWjD6GEq/b4yAQ2mPv3P huGdkmBzfxaMUoKsoamvrekEGg0ed6q/jjPhI7HjSFh0KIgRsYZeNZExtW+bBQUx2f QYGh4kBba18/GTBercMJEB2Gnnl0tam1DGCqvGSVKNUVQfRLFerz+hrMVKKqNzGGyC xP7L9KpJbrxNw== Received: by mail-ed1-f70.google.com with SMTP id h8-20020a50cdc8000000b00506a09c4a49so1211835edj.9 for ; Thu, 20 Apr 2023 01:47:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681980459; x=1684572459; 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=QUa3auAj4u9NqRTBT9WVcUeMs8DEO6WQSLZjTthBB3A=; b=OhAtBAF7TpUTfbipMHAUv4M/llvHFoxzAW88CS6dLfa2X5pM4ATQmAoswAcXGhvHpY pb70xn4m/JB2bfjXIgnzMbsuVjdUFKVyS2VUeL/TPonwYQ3F6w8KnixmxnMqHrgqRkHK 9GifIZ67UdNPLk5X6A9HSTRPvTLQFe6JbWW0mQBQvSvftxBwpgFO/QJJdahoUQgRho6A /wGmkqOg20KauWVhjzqps+lTVkxXpsDX6gh7p8yTv6gfSvPRTUgZP7q1jPRGdudBO6Xd Q/TkP4+IsGFzeZkhe3ax940TC+ROhe4QoAl39AaumedlZcjbFM+3J92Rq1zlrZ1PAYuV +vsQ== X-Gm-Message-State: AAQBX9fKT9x28HM158Tm3MeAQcfPYOh1OM4TQr/YcQWGYeLhfu4F6CN5 hjxkMkcOPVQMuT7hql8XyIgMFN7OHcF+mXOsms5ThaMcflTV0X11iYZxHLeXi2vfRO8IThBj8e0 diLQaAlcjOHAmh2okeE+Z/ozSbNnYgw== X-Received: by 2002:a17:906:3512:b0:94f:12c0:4c8f with SMTP id r18-20020a170906351200b0094f12c04c8fmr820690eja.50.1681980459546; Thu, 20 Apr 2023 01:47:39 -0700 (PDT) X-Google-Smtp-Source: AKy350ZzV+Zu8+SSa+Fm3TdTM/basx1ZOevVs7KCOHxWHbqRAxUygjWfAeKhy8CpvyHsuSUMo+P3vg== X-Received: by 2002:a17:906:3512:b0:94f:12c0:4c8f with SMTP id r18-20020a170906351200b0094f12c04c8fmr820671eja.50.1681980459275; Thu, 20 Apr 2023 01:47:39 -0700 (PDT) Received: from amikhalitsyn.. (ip5f5bd076.dynamic.kabel-deutschland.de. [95.91.208.118]) by smtp.gmail.com with ESMTPSA id k26-20020aa7c39a000000b005068053b53dsm500964edq.73.2023.04.20.01.47.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 01:47:38 -0700 (PDT) From: Alexander Mikhalitsyn To: pbonzini@redhat.com Cc: Alexander Mikhalitsyn , Sean Christopherson , =?utf-8?q?St=C3=A9phane_Graber?= , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH RESEND 2/2] KVM: SVM: add some info prints to SEV init Date: Thu, 20 Apr 2023 10:47:17 +0200 Message-Id: <20230420084717.111024-3-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420084717.111024-1-aleksandr.mikhalitsyn@canonical.com> References: <20230420084717.111024-1-aleksandr.mikhalitsyn@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's add a few pr_info's to sev_hardware_setup to make SEV/SEV-ES enabling a little bit handier for users. Right now it's too hard to guess why SEV/SEV-ES are failing to enable. There are a few reasons. SEV: - NPT is disabled (module parameter) - CPU lacks some features (sev, decodeassists) - Maximum SEV ASID is 0 SEV-ES: - mmio_caching is disabled (module parameter) - CPU lacks sev_es feature - Minimum SEV ASID value is 1 (can be adjusted in BIOS/UEFI) Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Stéphane Graber Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Alexander Mikhalitsyn --- arch/x86/kvm/svm/sev.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index a42536a0681a..14cbb8f14c6b 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2168,17 +2168,24 @@ void __init sev_hardware_setup(void) bool sev_es_supported = false; bool sev_supported = false; - if (!sev_enabled || !npt_enabled) + if (!sev_enabled) goto out; + if (!npt_enabled) { + pr_info("Failed to enable AMD SEV as it requires Nested Paging to be enabled\n"); + goto out; + } + /* * SEV must obviously be supported in hardware. Sanity check that the * CPU supports decode assists, which is mandatory for SEV guests to * support instruction emulation. */ if (!boot_cpu_has(X86_FEATURE_SEV) || - WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_DECODEASSISTS))) + WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_DECODEASSISTS))) { + pr_info("Failed to enable AMD SEV as it requires decodeassists and sev CPU features\n"); goto out; + } /* Retrieve SEV CPUID information */ cpuid(0x8000001f, &eax, &ebx, &ecx, &edx); @@ -2188,8 +2195,10 @@ void __init sev_hardware_setup(void) /* Maximum number of encrypted guests supported simultaneously */ max_sev_asid = ecx; - if (!max_sev_asid) + if (!max_sev_asid) { + pr_info("Failed to enable SEV as the maximum SEV ASID value is 0.\n"); goto out; + } /* Minimum ASID value that should be used for SEV guest */ min_sev_asid = edx; @@ -2234,16 +2243,22 @@ void __init sev_hardware_setup(void) * instead relies on #NPF(RSVD) being reflected into the guest as #VC * (the guest can then do a #VMGEXIT to request MMIO emulation). */ - if (!enable_mmio_caching) + if (!enable_mmio_caching) { + pr_info("Failed to enable SEV-ES as it requires MMIO caching to be enabled\n"); goto out; + } /* Does the CPU support SEV-ES? */ - if (!boot_cpu_has(X86_FEATURE_SEV_ES)) + if (!boot_cpu_has(X86_FEATURE_SEV_ES)) { + pr_info("Failed to enable SEV-ES as it requires sev_es CPU feature\n"); goto out; + } /* Has the system been allocated ASIDs for SEV-ES? */ - if (min_sev_asid == 1) + if (min_sev_asid == 1) { + pr_info("Failed to enable SEV-ES as the minimum SEV ASID value is 1.\n"); goto out; + } sev_es_asid_count = min_sev_asid - 1; if (misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count))