Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2986222rwd; Fri, 19 May 2023 13:07:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Ua5A0D/NT1esCBCRMcjFhd6qRy9tSzQKDqgyaX7TsdBq/UUiF1BjKMNGwnxyxjDRr9IOr X-Received: by 2002:a05:6a20:3c91:b0:100:ed92:7d4d with SMTP id b17-20020a056a203c9100b00100ed927d4dmr3520336pzj.31.1684526823605; Fri, 19 May 2023 13:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684526823; cv=none; d=google.com; s=arc-20160816; b=deBCPQAvmXXSjgRKE0zf7nGEr4ClS48JC1TOFwVavlh6CnVffa3RFgy4Tp8+Dlwru3 b9F25cfiiSntrIpEFYuySEGFZyhJDoJSSACaP2f+qbFCPPblQb7ZfCh8KF7YP4kPGuyu f5bK0S2XxjvjhjEwwdtyLMB6URHzu/11+k9jKSEMQFLXohX1U6kKlztra7caMkbt+Ayh qqZZYx9IbV2LPr30jwtfGkmUI3Mwyr/CNO39M/RLQXaqUeraLJ9ziossxbA7wZrlnMWR EpevtAdJfuH6Vj359/llyEpcQOaDFNJKFC2berr9DQTuEHgCeSYK5ZnBpU/g8OFcQ9eL GcoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=pKqky4qtLhLMqwc+jYDJn6p8bYat7L/lp+nKxMPkRyY=; b=oA8Ojb0aN+ukg3Bs2k77Qh1ieNWWYWnKerMFRohdtUhvjs/6V3/xpJN34f3LdldICZ bYdrJBBRl4gLF1rn45UJBt+bOiJnjrm2JErHlcGNoCLwvBoDz7mt0n/q7bPS4JCvkZ84 iC9Xvt/6IjFEs0h9AI6KF6pRKAgARUORJt9xoOPYlMzVvuV+lv1mCNID3HqMdhpHHH/d ymt2m7jyY38fPX78AgPumCGnbLpt4QM7tTW4WbBISwr5Xjeu2RF3lF8PgVTuoLvMyt/h R7odMLYComm/ymXzApw6CW1K/L5HCO6QlhxYixXfhBTPOCp9EjqWcXOIS9fdwgSBJi2z 9nYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="Y4/nCNzr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 129-20020a630087000000b005346ce4f2absi130159pga.605.2023.05.19.13.06.51; Fri, 19 May 2023 13:07:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="Y4/nCNzr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229871AbjEST6Z (ORCPT + 99 others); Fri, 19 May 2023 15:58:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229828AbjEST6X (ORCPT ); Fri, 19 May 2023 15:58:23 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D43921712 for ; Fri, 19 May 2023 12:57:45 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561fc920e70so41677207b3.0 for ; Fri, 19 May 2023 12:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684526250; x=1687118250; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pKqky4qtLhLMqwc+jYDJn6p8bYat7L/lp+nKxMPkRyY=; b=Y4/nCNzrFtAXrTxhpgxnIohVGQ15GL4scvI0E/2mwJYj0GQbPVuXot7Jeu/0WvRvj2 9Uxos5w5dD8ChOUGochlppnIBC5WV72wtD3Z57q1qVzEB6BAU0zrp0Rj839OpxiYl1kv G7aILpvUERbXB4ndb2rR/5sC8oXuhx9NqV1vUAEDqYGF4xFHckOEfCC8e/Xg4DdMuR9l zQm9PUkP+OBFNpwTjL8yMr9HKgLvxTY4wkwyU4C1eKD22zw0o+8bYInRVaF8kFuyTWom 12s22nrLwFtLZKHZJekTC38ZFlIu/iG4U6Mf6VoeQ952/z/sfp8161qhLkUY71jT5lqI iHcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684526250; x=1687118250; 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=pKqky4qtLhLMqwc+jYDJn6p8bYat7L/lp+nKxMPkRyY=; b=d346nIMd4FT/Wqn1gYJ28qop5VaDByBfnv+3Q11TZLgrlUllYIhBU7hCsPwGBfZhBY hRk4HgVXuSM0J+4QD04Q65P8kqE9j+qv2FCez/cPQvthqr8gPsA5ZuVcvCF/iHW7BBKb +ZEEUld3M/CXcbfueNaNULf9v3Tr7+uRqAT46ZNukyjJuEgp9uyDWTPMiVW5Vq0eSJqp kiegU3kBfjV2lAzXwmQ3XR3PiX5i1MqKGcss0z+8dGAGVq9O1YcTU5eUFzQBzM0QuVHQ 0CEgEjdA4mdOkR3kayTwZlYKZl9jjVhPwYbGBW/IC/SLUks/CoYZ/WaorpCjtwWkShny A/UQ== X-Gm-Message-State: AC+VfDwOAvYtFEOGPC6AWL+w0djxfXL9OF+fDWTXO0+CPQ3lWD3TJq/y 303Orr+Lw4AZPSuqnxdhUugsSHtC+PQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:9f0a:0:b0:561:949f:227 with SMTP id s10-20020a819f0a000000b00561949f0227mr1854093ywn.1.1684526250423; Fri, 19 May 2023 12:57:30 -0700 (PDT) Date: Fri, 19 May 2023 12:57:28 -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" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 19, 2023, Nicolas Saenz Julienne wrote: > Hi Sean, > > On Fri May 19, 2023 at 6:23 PM UTC, Sean Christopherson wrote: > > 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 > > That's not what the current implementation does, when attributes is > equal 0 it clears the entries from the xarray: > > static int kvm_vm_ioctl_set_mem_attributes(struct kvm *kvm, > struct kvm_memory_attributes *attrs) > { > > entry = attrs->attributes ? xa_mk_value(attrs->attributes) : NULL; > [...] > for (i = start; i < end; i++) > if (xa_err(xa_store(&kvm->mem_attr_array, i, entry, > GFP_KERNEL_ACCOUNT))) > break; > } > > >From Documentation/core-api/xarray.rst: > > "There is no difference between an entry that has never > been stored to, one that has been erased and one that has most recently > had ``NULL`` stored to it." > > The way I understood the series, there needs to be a differentiation > between no attributes (regular page fault) and no-access. Ah, I see what you're saying. There are multiple ways to solve things without a "no access" flag while still maintaining an empty xarray for the default case. E.g. invert the flags to be DENY flags[*], have an internal-only "entry valid" flag, etc. [*] I vaguely recall suggesting a "deny" approach somewhere, but I may just be making things up to make it look like I thought deeply about this ;-)