Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp711260pxy; Wed, 21 Apr 2021 13:03:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQ/7uB5ONdc+dcd2T/TU+/arGiyt5+EciUunGa6NeKmppFjXSWi5fwTONyo3GAb4WndBYn X-Received: by 2002:a17:90b:368b:: with SMTP id mj11mr13012930pjb.217.1619035414912; Wed, 21 Apr 2021 13:03:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619035414; cv=none; d=google.com; s=arc-20160816; b=T98mEyMLWVE7iQMOoKdctHt8N7zsfUmmiWvWRy+L5TzmKgZPRnUQfL0Yyqw2iJPddN 4LN3bLX4rg8XksFIkg8eciZGUmFXL9cm/O+tJ1VURGWRSPjj/Xomx3lkcgpeniebMuS8 KUErSYq5zNZ6QTD+0N7ihia+cEY1KBcmTFaBsgHl+SDZSXxA024XODtBVYOCirxNnTBv 812dUtrjYHpH5sHqC0EUO1ZBlyZbwLMskz+3Q7tActO10asd+i96Rv4POAJFGKn8yKyb L9ZNy5iK40tg/V+Inqsxfp97f/Q1Yp4ymo0oAGY0LktbzYZ88+rNNjI5KVfIW35QgVX3 to2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SBgIJ5k6u6nv4fZ2GI4+dW/oLzowYqHhUYoMPcapY9s=; b=L80m5GyAZITQToPeDvDrODgvDGZ7gAyAy+2l1YUhahjOxkFiloqbJqRYB5Q85AVCNP o+e+2Pc8qnUhRbrlfSLtlvkY5s3P/Ckm1BteiUtsEV/NvQUF29KWVnO9W/2/SXdG6piN oSBP4rOID1YZLEsndn5FIh3aR7o2b9G4/RQ8O/1xem+XpNWO/97dXiC3rGZ4Tv8jbGiF qV56oTDRbID646C2UBKQCCEq6NnLZ/XYhXaPxfnKrjmv8j50oL3lZcL0sGZ86h/P0DL6 ybMXvaPRH+5vQnCygjr755F24Cn41brW7LmIDSzSgYsW3xjkY6XW8mUGQaoiQoks4o+Q fAKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=BLVNtvdX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 22si501119pfv.61.2021.04.21.13.03.22; Wed, 21 Apr 2021 13:03:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=BLVNtvdX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239993AbhDUOoj (ORCPT + 99 others); Wed, 21 Apr 2021 10:44:39 -0400 Received: from mail.skyhub.de ([5.9.137.197]:37764 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235292AbhDUOoi (ORCPT ); Wed, 21 Apr 2021 10:44:38 -0400 Received: from zn.tnic (p200300ec2f10df00c08862b6cef04697.dip0.t-ipconnect.de [IPv6:2003:ec:2f10:df00:c088:62b6:cef0:4697]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id EA3741EC0472; Wed, 21 Apr 2021 16:44:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1619016244; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=SBgIJ5k6u6nv4fZ2GI4+dW/oLzowYqHhUYoMPcapY9s=; b=BLVNtvdX3ijWdEoPAQPQynOC09UfEZ0/52og7XNIwqdP1Jj2iPmnpa+sdJ38rtLFrFT2O+ rEYWj9J1gNMFIysZENPGXgc7adE+dX6yh1nVTzl4CcMLVltPPO+E1q2VBn0fnd4umTGyGK rkPIF18ZNZ1/c/BMfBFyrfnsPulSEsc= Date: Wed, 21 Apr 2021 16:44:02 +0200 From: Borislav Petkov To: Ashish Kalra Cc: pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com, kexec@lists.infradead.org Subject: Re: [PATCH v13 12/12] x86/kvm: Add guest support for detecting and enabling SEV Live Migration feature. Message-ID: <20210421144402.GB5004@zn.tnic> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 15, 2021 at 04:01:16PM +0000, Ashish Kalra wrote: > From: Ashish Kalra > > The guest support for detecting and enabling SEV Live migration > feature uses the following logic : > > - kvm_init_plaform() invokes check_kvm_sev_migration() which > checks if its booted under the EFI > > - If not EFI, > > i) check for the KVM_FEATURE_CPUID Where do you do that? $ git grep KVM_FEATURE_CPUID $ Do you mean kvm_para_has_feature(KVM_FEATURE_SEV_LIVE_MIGRATION) per chance? > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > index 78bb0fae3982..94ef16d263a7 100644 > --- a/arch/x86/kernel/kvm.c > +++ b/arch/x86/kernel/kvm.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -429,6 +430,59 @@ static inline void __set_percpu_decrypted(void *ptr, unsigned long size) > early_set_memory_decrypted((unsigned long) ptr, size); > } > > +static int __init setup_kvm_sev_migration(void) kvm_init_sev_migration() or so. ... > @@ -48,6 +50,8 @@ EXPORT_SYMBOL_GPL(sev_enable_key); > > bool sev_enabled __section(".data"); > > +bool sev_live_migration_enabled __section(".data"); Pls add a function called something like: bool sev_feature_enabled(enum sev_feature) and gets SEV_FEATURE_LIVE_MIGRATION and then use it instead of adding yet another boolean which contains whether some aspect of SEV has been enabled or not. Then add a static enum sev_feature sev_features; in mem_encrypt.c and that function above will query that sev_features enum for set flags. Then, if you feel bored, you could convert sme_active, sev_active, sev_es_active, mem_encrypt_active and whetever else code needs to query any aspect of SEV being enabled or not, to that function. > +void __init check_kvm_sev_migration(void) > +{ > + if (sev_active() && > + kvm_para_has_feature(KVM_FEATURE_SEV_LIVE_MIGRATION)) { Save an indentation level: if (!sev_active() || !kvm_para_has_feature(KVM_FEATURE_SEV_LIVE_MIGRATION)) return; > + unsigned long nr_pages; > + int i; > + > + pr_info("KVM enable live migration\n"); That should be at the end of the function and say: pr_info("KVM live migration enabled.\n"); > + WRITE_ONCE(sev_live_migration_enabled, true); Why WRITE_ONCE? And that needs to go to the end of the function too. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette