From patchwork Mon May 22 16:12:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13250798 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 539A9C7EE23 for ; Mon, 22 May 2023 16:13:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232888AbjEVQNZ (ORCPT ); Mon, 22 May 2023 12:13:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231410AbjEVQNX (ORCPT ); Mon, 22 May 2023 12:13:23 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 044A5DB for ; Mon, 22 May 2023 09:13:22 -0700 (PDT) Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.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-0.canonical.com (Postfix) with ESMTPS id 577F83F4EE for ; Mon, 22 May 2023 16:13:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1684772000; bh=4rb90djqBbs5XuYtW3R9I7+5RrdmbXXkWM9Wptt0JPo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=kGbV8pY6g9wUtSipAX/32hBadyjG1AiedXvrjmwkF3oO7/uSu9R4x+mffgGu0Ui+7 r4iZZnCECP/IBrKFNAu9oPnDH0oZvaHTGxImB9tWQilrZ3IniZ7Bh0xyGXAZYz2DFi 0vTguQO80p9zoRpd+wQdEt1OG/nGEucPQ+B7PvnUNkMPoMYQUSgkBJJuRnEczwxeCY AxG4b2XI88C0L9xdLUziA3HWQ7eQioj9OOnw0gHxKCA2Zbb5oluBBRODkhoNPXoXGR L0GZUrexZSCDyDZkG4C3xwJrrZWzUBvuxhA7Du+lwmf3P4q2mAoOm4Q+b7tLtaklsP SJ8abN8cAAi6A== Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-94a348facbbso790579166b.1 for ; Mon, 22 May 2023 09:13:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684771998; x=1687363998; 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=4rb90djqBbs5XuYtW3R9I7+5RrdmbXXkWM9Wptt0JPo=; b=jxKjH2jobqPYNLPIX2cB9RL1KjJEFQdY5IQ6QmpxHkBx0dAOldXhcZK1iVNoKrfZ+s /8vnBQB+kpqi8LQGm3CO2wLvh8H64CKScgQBwzbjCjwQFI/C3pEB3vNcno41OkCikSdl Si2rhmO4KspKcCU2HIsxw3nXOCqaRCX8q7M1u3/fgwOxy4urbRP+dJo1r/ThHNkoE3RH e3YU8ncX/zDjnqdl5KHl3CxTJ75dwOBiHtASUK2WNOgZGXqX62wKkoiVamzngql6/B/+ 9AHCK9/8FEf1BBh1j9+HVY7fst1o/wu2X/92c0UblLfzzaEu4YbK/tQMxI0cwAV2ibPs kNRA== X-Gm-Message-State: AC+VfDzODbJB5LiGEqWcSj1DFPb6LOqSi45lt9fopyGjaNu4HebSi7H+ A88bY/wv/2jo406t3y5B7VyBwgC411ADni4kh8H/p5TME+a7636rQzY2QXOoAlWQLgYbzUaf6Ex 3hAXZYVQYbHDpmzRYdxRmLmysTI7+rg== X-Received: by 2002:a17:907:e8c:b0:965:ff38:2fbb with SMTP id ho12-20020a1709070e8c00b00965ff382fbbmr11057650ejc.1.1684771998136; Mon, 22 May 2023 09:13:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6sFu9ZDMMoJ+qT7dryKzCzvkxh7vw6VbgF+1fgPmovvfOkC6jSGHbWPbUIqDC9vc4/EtEUfg== X-Received: by 2002:a17:907:e8c:b0:965:ff38:2fbb with SMTP id ho12-20020a1709070e8c00b00965ff382fbbmr11057638ejc.1.1684771997945; Mon, 22 May 2023 09:13:17 -0700 (PDT) Received: from amikhalitsyn.local (dslb-088-074-206-207.088.074.pools.vodafone-ip.de. [88.74.206.207]) by smtp.gmail.com with ESMTPSA id a7-20020a17090682c700b009658475919csm3225039ejy.188.2023.05.22.09.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 09:13:17 -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 v2 1/2] KVM: SVM: free sev_*asid_bitmap init if SEV init fails Date: Mon, 22 May 2023 18:12:47 +0200 Message-Id: <20230522161249.800829-2-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230522161249.800829-1-aleksandr.mikhalitsyn@canonical.com> References: <20230522161249.800829-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 Reported-by: Alexander Mikhalitsyn Signed-off-by: Sean Christopherson --- 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 69ae5e1b3120..cc832a8d1bca 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2216,8 +2216,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 Mon May 22 16:12:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 13250800 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 5F6BCC77B75 for ; Mon, 22 May 2023 16:13:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232913AbjEVQNd (ORCPT ); Mon, 22 May 2023 12:13:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233040AbjEVQN1 (ORCPT ); Mon, 22 May 2023 12:13:27 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B45EBB6 for ; Mon, 22 May 2023 09:13:26 -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-0.canonical.com (Postfix) with ESMTPS id 370723F526 for ; Mon, 22 May 2023 16:13:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1684772002; bh=yEoXhOv9392G4YyVtPika8TuddyFutw1yuUvDKTMDXc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=WZAkvBik5wa79VE7Idp3tQYhg14zHkrgDhu8rA7vqtlzOqq7BafNhexk8b7htU0y0 UGa33jGd71X8MU9gMPxeLZHFMvW+zmuD6dIywbRVLy8fDGbDPXaN9aFN068NvxwbL0 1KYLEmd/XLkVZ0PSvo2ujaH6KUjiE1TpH+WMZ+Bwscx6D6QMWYM3KtOE+Z8/29yoId iqWu0Tg5ZVf7pXdE3uffJSUZDwK2/UqXR/ksDyELn6XwIvB7YL8kF32CySw9kO2Zoa gEw/Y4kKBoMSEo2MAtc7R8OLWx06DTG5s8Ybj4J6wNzEQsNeAXvzUbl8BdDHoLYPUi Dttr1R5xFH2Fg== Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-510d8e4416cso6659725a12.3 for ; Mon, 22 May 2023 09:13:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684772001; x=1687364001; 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=yEoXhOv9392G4YyVtPika8TuddyFutw1yuUvDKTMDXc=; b=kFbh3Kru5FvjB+Rffg9YzAa2aZDw2+1WXmBQXv7AdjuiRZ4B5wfhQwORSMDDpSrSix Oj9jQWbj3sUvmyLva/+XpSxyMpO+JAW45CBZsg6ysqlBkfrpoyml1OMoulofLaXigq1m IwmR5nIeUpTEO7eUezuE8hOPgKEnSKvdWWOWB9EQwaQUXtvvgJuSKB1CXLzK8bTmwvYB X39AEjuCHpzUBUcs3VXw+SfYU/wetUE63lr4kJEJICVXXpAJY+qQWnnhadDesL7q/+1s 0GyWSDoseNgBaKkeOdLlNqO7Cq3QzeQWyGFPnvfLutAkKeAoWrEl/fSDIlDmKjuC90pr AKAA== X-Gm-Message-State: AC+VfDxoao6JwVB2U+nhOnDMmeW/0m+tFPZs7rvgwbSO5M9o3miHisPx Xqk91FNlJYiPFTXbKsQt58Fy0kG9bYDzOSPoPq8TNTbpM68hifI9jZ9/FJrX8W8PtIdlAl5AdCt fN9L7y809uEwjCLZR2w9rNit8mfzV7Q== X-Received: by 2002:a17:906:58c7:b0:96b:e93:3a9f with SMTP id e7-20020a17090658c700b0096b0e933a9fmr11141498ejs.20.1684772001414; Mon, 22 May 2023 09:13:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6dUWTXh+XjI7wSktkwgjubPt+RAL8UbOeWuwZfD0kG6B2OVu9hYOQ/teuL04KXyyfGDkSquQ== X-Received: by 2002:a17:906:58c7:b0:96b:e93:3a9f with SMTP id e7-20020a17090658c700b0096b0e933a9fmr11141482ejs.20.1684772001173; Mon, 22 May 2023 09:13:21 -0700 (PDT) Received: from amikhalitsyn.local (dslb-088-074-206-207.088.074.pools.vodafone-ip.de. [88.74.206.207]) by smtp.gmail.com with ESMTPSA id a7-20020a17090682c700b009658475919csm3225039ejy.188.2023.05.22.09.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 09:13:20 -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 v2 2/2] KVM: SVM: enhance info printk's in SEV init Date: Mon, 22 May 2023 18:12:48 +0200 Message-Id: <20230522161249.800829-3-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230522161249.800829-1-aleksandr.mikhalitsyn@canonical.com> References: <20230522161249.800829-1-aleksandr.mikhalitsyn@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's print available ASID ranges for SEV/SEV-ES guests. This information can be useful for system administrator to debug if SEV/SEV-ES fails 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 Suggested-by: Sean Christopherson Signed-off-by: Alexander Mikhalitsyn --- v2: - print only the ASID ranges according to Sean's suggestion --- arch/x86/kvm/svm/sev.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index cc832a8d1bca..fff63d1f2a34 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2224,7 +2224,6 @@ void __init sev_hardware_setup(void) goto out; } - pr_info("SEV supported: %u ASIDs\n", sev_asid_count); sev_supported = true; /* SEV-ES support requested? */ @@ -2252,10 +2251,16 @@ void __init sev_hardware_setup(void) if (misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count)) goto out; - pr_info("SEV-ES supported: %u ASIDs\n", sev_es_asid_count); sev_es_supported = true; out: + if (boot_cpu_has(X86_FEATURE_SEV)) + pr_info("SEV %s (ASIDs %u - %u)\n", + sev_supported ? "enabled" : "disabled", min_sev_asid, max_sev_asid); + if (boot_cpu_has(X86_FEATURE_SEV_ES)) + pr_info("SEV-ES %s (ASIDs %u - %u)\n", + sev_es_supported ? "enabled" : "disabled", 1, min_sev_asid - 1); + sev_enabled = sev_supported; sev_es_enabled = sev_es_supported; #endif