From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FE0DC433E0 for ; Wed, 27 May 2020 08:39:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 20E232073B for ; Wed, 27 May 2020 08:39:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="G6qMI0JX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 20E232073B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 900C9800BA; Wed, 27 May 2020 04:39:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B15880010; Wed, 27 May 2020 04:39:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C7B2800BA; Wed, 27 May 2020 04:39:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id 637DB80010 for ; Wed, 27 May 2020 04:39:41 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1FFB75010 for ; Wed, 27 May 2020 08:39:41 +0000 (UTC) X-FDA: 76861850562.13.tray59_5909cdf26d50 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id EB98718140B67 for ; Wed, 27 May 2020 08:39:40 +0000 (UTC) X-HE-Tag: tray59_5909cdf26d50 X-Filterd-Recvd-Size: 6154 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 May 2020 08:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590568779; 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: in-reply-to:in-reply-to:references:references; bh=5CtVNmzXXKb/GJnyK3cmtp2ErHYUKsptEP9TQUHQbxw=; b=G6qMI0JXsaEA95oPVcjzNX79Go3SDGiFDpal7vxbO2y4h8ho3U/KFii69k6zYtjqj9VLdg HnXc3RqgI2/u9p6fwj8gdtrYyxrK1ybmE9SZvFudCMKjaRVksrvo8A3SEl6mMIHNvDeU4H NoEqqriNzM/HOfwc43jpJ0sAAofe5E8= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-1Dy99h82PFGk1Du07j_Z5w-1; Wed, 27 May 2020 04:39:37 -0400 X-MC-Unique: 1Dy99h82PFGk1Du07j_Z5w-1 Received: by mail-ej1-f70.google.com with SMTP id ci7so6446378ejb.2 for ; Wed, 27 May 2020 01:39:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=5CtVNmzXXKb/GJnyK3cmtp2ErHYUKsptEP9TQUHQbxw=; b=rBw7wCOZeabXvRkvtK+WSIsOFONDzXhbBPIOV2rb6LW7UsR4MtIdoocFBwjWtKr+sf /3TazcVpGCb/qolXkAKXh1A5l+KdClZsSvuGC30fp3i7H9n+ltC3vhRjzYoYTBROOa8D Av5PLA8TJFVpN3P/3dSmhz+Ec0qcB1WH0kcObrEEkhwRbfCyscKrTehmjFOlPlJ9hp7E 8/nlmXn133Ev+RGokGNU/lbas9KeXzY1QzhNuSDDpF+RLU+UqiEVu0k+tfrGHIcIQd6f Nx0Dc6DMVeE6ZwfKyM211m1TVg6UxatDl5ayCag81xrezXFSeLLu5zFNm43gM7jIizx6 CWAw== X-Gm-Message-State: AOAM531tv2uq8Doi3KQAtoFJ60IG6qTYm6ZBd9eIrfHU2+reQMSik94v i8oSnXzlaTnPw5CsLxAHAVtS/YGtNACZIJp7e44Rvr7vcvzmMZhV780U2Fu+jEw0WluasAJ+Mhx eKT0h2ULuRoI= X-Received: by 2002:a17:906:3b9a:: with SMTP id u26mr4827614ejf.456.1590568776171; Wed, 27 May 2020 01:39:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwp2aIsA3XEwQ6IIPY4EvLkOvUOmXFr3P4IIB2DE6c8rBlbscdO/yOITd5hElHhUs1XcB7/yQ== X-Received: by 2002:a17:906:3b9a:: with SMTP id u26mr4827580ejf.456.1590568775832; Wed, 27 May 2020 01:39:35 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id s19sm2124076eja.91.2020.05.27.01.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 01:39:34 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson , "Kirill A. Shutemov" Cc: David Rientjes , Andrea Arcangeli , Kees Cook , Will Drewry , "Edgecombe\, Rick P" , "Kleen\, Andi" , x86@kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Paolo Bonzini , Wanpeng Li , Jim Mattson , Joerg Roedel Subject: Re: [RFC 02/16] x86/kvm: Introduce KVM memory protection feature In-Reply-To: <20200527050350.GK31696@linux.intel.com> References: <20200522125214.31348-1-kirill.shutemov@linux.intel.com> <20200522125214.31348-3-kirill.shutemov@linux.intel.com> <87d06s83is.fsf@vitty.brq.redhat.com> <20200525151525.qmfvzxbl7sq46cdq@box> <20200527050350.GK31696@linux.intel.com> Date: Wed, 27 May 2020 10:39:33 +0200 Message-ID: <87eer56abe.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Rspamd-Queue-Id: EB98718140B67 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Sean Christopherson writes: > On Mon, May 25, 2020 at 06:15:25PM +0300, Kirill A. Shutemov wrote: >> On Mon, May 25, 2020 at 04:58:51PM +0200, Vitaly Kuznetsov wrote: >> > > @@ -727,6 +734,15 @@ static void __init kvm_init_platform(void) >> > > { >> > > kvmclock_init(); >> > > x86_platform.apic_post_init = kvm_apic_init; >> > > + >> > > + if (kvm_para_has_feature(KVM_FEATURE_MEM_PROTECTED)) { >> > > + if (kvm_hypercall0(KVM_HC_ENABLE_MEM_PROTECTED)) { >> > > + pr_err("Failed to enable KVM memory protection\n"); >> > > + return; >> > > + } >> > > + >> > > + mem_protected = true; >> > > + } >> > > } >> > >> > Personally, I'd prefer to do this via setting a bit in a KVM-specific >> > MSR instead. The benefit is that the guest doesn't need to remember if >> > it enabled the feature or not, it can always read the config msr. May >> > come handy for e.g. kexec/kdump. >> >> I think we would need to remember it anyway. Accessing MSR is somewhat >> expensive. But, okay, I can rework it MSR if needed. > > I think Vitaly is talking about the case where the kernel can't easily get > at its cached state, e.g. after booting into a new kernel. The kernel would > still have an X86_FEATURE bit or whatever, providing a virtual MSR would be > purely for rare slow paths. > > That being said, a hypercall plus CPUID bit might be better, e.g. that'd > allow the guest to query the state without risking a #GP. We have rdmsr_safe() for that! :-) MSR (and hypercall to that matter) should have an associated CPUID feature bit of course. Yes, hypercall + CPUID would do but normally we treat CPUID data as static and in this case we'll make it a dynamically flipping bit. Especially if we introduce 'KVM_HC_DISABLE_MEM_PROTECTED' later. > >> Note, that we can avoid the enabling algother, if we modify BIOS to deal >> with private/shared memory. Currently BIOS get system crash if we enable >> the feature from time zero. > > Which would mesh better with a CPUID feature bit. > And maybe even help us to resolve 'reboot' problem. -- Vitaly