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 7DC08C77B7A for ; Fri, 19 May 2023 19:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbjEST6Y (ORCPT ); Fri, 19 May 2023 15:58:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbjEST6X (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 4B01410D7 for ; Fri, 19 May 2023 12:57:46 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561ceb5b584so66641397b3.3 for ; Fri, 19 May 2023 12:57:46 -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=P+K+hH1hD3526mCbC2s+/C4RDjCT5n1KNwV3QMwEbWV6KpUPZI8x4XGADcjqjhct6M LGuD55OwzKuRTY9aaO/JMyLIoAn10jcbk+HJ0VgaUZP9zq8WMzCeUjcOojkGxsFhu1CF +BdFdiDJ96cmmxXThHkszADzUbkgTQ3TRB0bMz65ulWxUvdHob6geuNvJ6qMM/IW+tkg LFm0EMrwoDiq+mHBELTIJujDvB/JV+VHXkuhRerYKsSSRPqZYCBaRgfrsvBtujfz+gwm 4w55fZI8eq4Yx0VfJjlmJZqqo3TI8zowb8q+hcZLPTrXBX54kyPq3Y5nIGpiTJhN4Ti0 OsjA== X-Gm-Message-State: AC+VfDyfnJrxN/KTDT1VGuFs0bzZJmDEgBl/UYASFHO3A2X+k04uyOcM ycW4IxJfYqzE++2u3x+JRC03K0Le3OU= X-Google-Smtp-Source: ACHHUZ6FEiPmU5v43LWifQRBpo81052L49sw5QgxYInZToAzWsR8mGtYDH7+PppQKkPgp34+c6aLJuvLWhk= 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" Precedence: bulk List-ID: X-Mailing-List: linux-api@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 ;-)