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 588AAC77B7A for ; Fri, 19 May 2023 18:23:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbjESSXc (ORCPT ); Fri, 19 May 2023 14:23:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjESSX1 (ORCPT ); Fri, 19 May 2023 14:23:27 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E50BD132 for ; Fri, 19 May 2023 11:23:24 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-64d285fc7ecso1923043b3a.2 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=eC6eIcMKDAQGbTTyfRsYnUfAT0Fd0Yro5EXszQcxINMnP8Sry0tVHZteAImWNhKIIj +dr9Y+K92MegZK9YZxGnhK817NT+Avfi7qbVFGG/Q3Cszm+f3s4TEAzjQa4B56spXvjq h3Z04XUlwlp0QIghpdbnWjjJqgHzFwCn/bgCU0A4QIoF2UfVJ58NvCZyLxYjL0RtgUVg EFz5cDsf9rHQH7f/XsIPOfa2NeTVRZb5yyy8qwBYgp3cw3U/gCEqVPb350MEeNXnbiJ9 eBIX673qFgUzGn0kFNa827Vw2sKGyFCNivZqbsAEgfYPPdr27TnwvKQTePEMx9LY/rTX Geew== X-Gm-Message-State: AC+VfDzG4/fsdpG2b7ZzWHQ5Fr/+kq1jhsy4Uj1i4KwlZr0BIKZKEwtw KyLt5MasFO29Vdz6+ywfYyy1I04o3sM= 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: linux-kernel@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