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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E491C7EE2A for ; Fri, 19 May 2023 18:23:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229695AbjESSX3 (ORCPT ); Fri, 19 May 2023 14:23:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjESSX0 (ORCPT ); Fri, 19 May 2023 14:23:26 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E96DE1A1 for ; Fri, 19 May 2023 11:23:24 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-64d1c53cad8so2538423b3a.3 for ; Fri, 19 May 2023 11:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684520604; x=1687112604; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DLB02Z/Vwsol/Ye6PM6jgDdfosuGHdGXe49pn4jVFGs=; b=ITz9fDEYRz6uJ1+nRWO7vsSi14em+HdSJidcWgxJ4Wt6DeOJu7xDarNLoGHPPmOBJm 513df8JS3NzUdZBK5GSwxSAE1obesd28XWXoOz2iBbvdy2ADgD8Q7q4etCMKIPinEZf9 82KenOrwjvv/KK8vs+qKxwowe4qePsP8+TuW1ty9rOYtzfzi/ynfD476K7Sa4jcxQ34p HkwfUr8RcwOMfxti367AckaqXDd3aDIN65dnmKhBIIZmfTcWPib/CZQFAhBLIgn2eTM2 VcgA71nqkKuEZwM79FEKmyy8iW+KFC3fLH2DABkTHNX+7IlmO+RnTTQJhuLLoZh1rgpR H95A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684520604; x=1687112604; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DLB02Z/Vwsol/Ye6PM6jgDdfosuGHdGXe49pn4jVFGs=; b=YbJTQnCE85ocFb8iL3fWfsLnR1MUj35jVCXInAGAK2QGw5xMbL//6LOZwJHUwz9LbT MfEH1LwWZfC2REUgXWPEbuh+10vbUdbJe242QQJrEZg+1xzZxRLt59G7LlH9+Zcaa0AO +7jE4iXYyKpYpCtLV0PxlJMUphLOmqUByvA9qprc4Z/jwti+0ikkVEjKstyi4o5Ta1BB dHpR9ZMT+M6jwfUzlzCAu1KTtb+fWI1OjMGn5BbNv1LheIliANvLh/rnw9PnF8F9L9+C h4LIhGCv/IqoXYe3kWMikUC9au9AKJKQTCvqOsF5LCN4Cm3cdNdNJuR3WUh35ybmuwUl jU9g== X-Gm-Message-State: AC+VfDwh2/YatslzhupD4mYEX6mBBPm/DLFeXHWc3WMNwjihDmCT2tdo W2XTXcBZ4ccFAOaoBNK1wzcDhJRLsuM= X-Google-Smtp-Source: ACHHUZ419BZyva9XfjdHZezzlVRJTJng9P1rwHIVB2iZ3Kvn5yX6WZYPLwlGGRjyBM2xKvPRPQpWmzT2ch0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:aa7:88c4:0:b0:643:4595:64c7 with SMTP id k4-20020aa788c4000000b00643459564c7mr1352262pff.4.1684520604384; Fri, 19 May 2023 11:23:24 -0700 (PDT) Date: Fri, 19 May 2023 11:23:23 -0700 In-Reply-To: Mime-Version: 1.0 References: <20221202061347.1070246-1-chao.p.peng@linux.intel.com> <20221202061347.1070246-3-chao.p.peng@linux.intel.com> Message-ID: Subject: Re: [PATCH v10 2/9] KVM: Introduce per-page memory attributes From: Sean Christopherson To: Nicolas Saenz Julienne Cc: Chao Peng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, graf@amazon.com, Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Arnd Bergmann , Naoya Horiguchi , Miaohe Lin , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , tabba@google.com, Michael Roth , mhocko@suse.com, wei.w.wang@intel.com, anelkz@amazon.de Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Fri, May 19, 2023, Nicolas Saenz Julienne wrote: > Hi, > > On Fri Dec 2, 2022 at 6:13 AM UTC, Chao Peng wrote: > > [...] > > +The user sets the per-page memory attributes to a guest memory range indicated > > +by address/size, and in return KVM adjusts address and size to reflect the > > +actual pages of the memory range have been successfully set to the attributes. > > +If the call returns 0, "address" is updated to the last successful address + 1 > > +and "size" is updated to the remaining address size that has not been set > > +successfully. The user should check the return value as well as the size to > > +decide if the operation succeeded for the whole range or not. The user may want > > +to retry the operation with the returned address/size if the previous range was > > +partially successful. > > + > > +Both address and size should be page aligned and the supported attributes can be > > +retrieved with KVM_GET_SUPPORTED_MEMORY_ATTRIBUTES. > > + > > +The "flags" field may be used for future extensions and should be set to 0s. > > We have been looking into adding support for the Hyper-V VSM extensions > which Windows uses to implement Credential Guard. This interface seems > like a good fit for one of its underlying features. I just wanted to > share a bit about it, and see if we can expand it to fit this use-case. > Note that this was already briefly discussed between Sean and Alex some > time ago[1]. > > VSM introduces isolated guest execution contexts called Virtual Trust > Levels (VTL) [2]. Each VTL has its own memory access protections, > virtual processors states, interrupt controllers and overlay pages. VTLs > are hierarchical and might enforce memory protections on less privileged > VTLs. Memory protections are enforced on a per-GPA granularity. > > The list of possible protections is: > - No access -- This needs a new memory attribute, I think. No, if KVM provides three bits for READ, WRITE, and EXECUTE, then userspace can get all the possible combinations. E.g. this is RWX=000b > - Read-only, no execute RWX=100b (using my completely arbitrary ordering of RWX bits :-) ) > - Read-only, execute RWX=101b > - Read/write, no execute RWX=110b > - Read/write, execute RWX=111b > We implemented this in the past by using a separate address space per > VTL and updating memory regions on protection changes. But having to > update the memory slot layout for every permission change scales poorly, > especially as we have to perform 100.000s of these operations at boot > (see [1] for a little more context). > > I believe the biggest barrier for us to use memory attributes is not > having the ability to target specific address spaces, or to the very > least having some mechanism to maintain multiple independent layers of > attributes. Can you elaborate on "specific address spaces"? In KVM, that usually means SMM, but the VTL comment above makes me think you're talking about something entirely different. E.g. can you provide a brief summary of the requirements/expectations? > Also sorry for not posting our VSM patches. They are not ready for > upstream review yet, but we're working on it. > > Nicolas > > [1] https://patchwork.kernel.org/comment/25054908/ > [2] See Chapter 15 of Microsoft's 'Hypervisor Top Level Functional Specification': > https://raw.githubusercontent.com/MicrosoftDocs/Virtualization-Documentation/main/tlfs/Hypervisor%20Top%20Level%20Functional%20Specification%20v6.0b.pdf