Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10750376rwp; Fri, 21 Jul 2023 04:32:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlEcS0UaFzrFCaajrXg8q2ccpRgQSLSgKHYyJRPrRMiBfJdysVRm8MJiHIimJ+ARc2m4Xhig X-Received: by 2002:a05:6a20:4c92:b0:12c:e3c8:8c7 with SMTP id fq18-20020a056a204c9200b0012ce3c808c7mr1297444pzb.41.1689939177646; Fri, 21 Jul 2023 04:32:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689939177; cv=none; d=google.com; s=arc-20160816; b=Xnoy8Xv5ivbRamffrFv/UH61SKTRZ9aO0iRCzl/HDkWpAv18Cngkqo3iIZ2tEDWMFJ Pun+p0kndmvCIJUSsYe2MMfIoEb6j1GGI7puGGJSB8IqAKn8brXNIouJHzoI6MxmThOz lYV9hSNAueKf4V6Lx1UIMflH+mmOxNr03TnVKzMtJKM490jPJR1O84VdWe07o8/3F5Z1 zPs+FKtXCu9hgHBSME0b/qddOcw5xwNNy3Po5uSxrlWor+6EB88uW/luOIOlOueMFsQ7 s95fZRpKuDwgPfIqR+RAxnuiNoXrw4+mk1lzFms2kucmN13yIcmYbVX3rI2NgsGXXRAU 9ieQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=JCcb9xtScqAyMOStlm7ewhQnyFA6r02pOvdu3ozJ8ms=; fh=Ha0fK0q/QRDhu63ZqG+O6WFFibL7W0Vai9siCdqdoHU=; b=0/5rbMK9yBBiaFBT76tPBbtbcnXKz5KW/YKof74bJKiSaWQeWN5MnVojNVMwevrXJX IUyRKnh8ep5ZqbbJzTnc7jOUk4qbuyaj1CssNK01X+3t4KPzELdYm8ZHehzQhXKXxYv+ ZgPt3ODkP3lx76S4U2vGQLH5rAkR2PfuFWuRaQBYdPe5kjZZBUO2kXvPLoa6tjDNNVn3 SIHaDOA8BPdCLjFwI71ixEm15qI2+zejDjRnSmj+uQtN8e4uRZpddVS7SHf1OHSRwhfb tgGwL8CoJ0cRZIihwQMFx04fgmWWqqEUXIIUpX7xDwUnhDpqZ1kYMA5Hov1/vqJQnxAR G9Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CfDUw4n5; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a62790b000000b0067a4b6093a8si2842310pfc.29.2023.07.21.04.32.44; Fri, 21 Jul 2023 04:32:57 -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=@redhat.com header.s=mimecast20190719 header.b=CfDUw4n5; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230373AbjGUK6B (ORCPT + 99 others); Fri, 21 Jul 2023 06:58:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231172AbjGUK57 (ORCPT ); Fri, 21 Jul 2023 06:57:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1712171A for ; Fri, 21 Jul 2023 03:57:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689937033; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JCcb9xtScqAyMOStlm7ewhQnyFA6r02pOvdu3ozJ8ms=; b=CfDUw4n5j9Ub8zU/uGCccEihQ3s/RFlSzrHXicFgigg9iXRpcJsjAkzayq/qzqV7eXWNbF TgYL2U0/RTkrjVJjgxihUYvvc8ehJ/QT0O8zUK7bCf7VwiS31imZHJUAZyB/kGNlg1HGkq JyrMHOhm3ERua6VGu9U+jHpmsjE6Utg= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-149-AWmXckHRPs6d0bKhiSzxEQ-1; Fri, 21 Jul 2023 06:57:11 -0400 X-MC-Unique: AWmXckHRPs6d0bKhiSzxEQ-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-98df34aa83aso336629966b.1 for ; Fri, 21 Jul 2023 03:57:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689937031; x=1690541831; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JCcb9xtScqAyMOStlm7ewhQnyFA6r02pOvdu3ozJ8ms=; b=OkplTwV/IMuuOunuhW47nH951WO44F6SMLj1xqL256XhT55UTl7oMmD+SRHkDWJCtE lCh6XyLAY4/MTkIwrMIcxEqoqs0RCsmhEjYicfBNlwtJDruOYjFqsYR9nDJl9O692WV6 qPMdvAYjxUGbJDWW+lVJsMxnnw+wY5B8sDs80xSngY00fzNLyuRqK2dfYQFms6cdqM1y saYr6ZUXm4K0Asl0U3LADJNFucz/nKPbsvfQJCCcYka/fKARxaRdVUUUjJ++aewIcBk8 nnPjUEelH31u+NZC53L9FAZGPkgO2Caxa9OCicW0w1eAD1N78A4+kgcb5dDcvSlfLHHx uoEg== X-Gm-Message-State: ABy/qLaISofupEwXqJLbmMDCXnubKV6AbhbnqAVcE0H7f6Ou8X1+dxJT 0Mhrn28NExoJJB0wGlecJvfHCJZigJuA6TQRgghlrvv8YxhdV31sfzgM0VJ2Qf4dzzohzc8H6N4 eZZPnM+WtJs57pRJSezmeBNWG X-Received: by 2002:a17:907:d8a:b0:991:d414:d889 with SMTP id go10-20020a1709070d8a00b00991d414d889mr8230224ejc.15.1689937030824; Fri, 21 Jul 2023 03:57:10 -0700 (PDT) X-Received: by 2002:a17:907:d8a:b0:991:d414:d889 with SMTP id go10-20020a1709070d8a00b00991d414d889mr8230204ejc.15.1689937030548; Fri, 21 Jul 2023 03:57:10 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:9af8:e5f5:7516:fa89? ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.googlemail.com with ESMTPSA id f21-20020a170906049500b0099364d9f0e9sm2025435eja.102.2023.07.21.03.57.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Jul 2023 03:57:09 -0700 (PDT) Message-ID: <0c033063-5d20-4522-87e2-80ad3cca3602@redhat.com> Date: Fri, 21 Jul 2023 12:57:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [RFC PATCH v11 08/29] KVM: Introduce per-page memory attributes Content-Language: en-US To: Sean Christopherson , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Yu Zhang , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , Vlastimil Babka , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" References: <20230718234512.1690985-1-seanjc@google.com> <20230718234512.1690985-9-seanjc@google.com> From: Paolo Bonzini In-Reply-To: <20230718234512.1690985-9-seanjc@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 7/19/23 01:44, Sean Christopherson wrote: > From: Chao Peng > > In confidential computing usages, whether a page is private or shared is > necessary information for KVM to perform operations like page fault > handling, page zapping etc. There are other potential use cases for > per-page memory attributes, e.g. to make memory read-only (or no-exec, > or exec-only, etc.) without having to modify memslots. > > Introduce two ioctls (advertised by KVM_CAP_MEMORY_ATTRIBUTES) to allow > userspace to operate on the per-page memory attributes. > - KVM_SET_MEMORY_ATTRIBUTES to set the per-page memory attributes to > a guest memory range. > - KVM_GET_SUPPORTED_MEMORY_ATTRIBUTES to return the KVM supported > memory attributes. > > Use an xarray to store the per-page attributes internally, with a naive, > not fully optimized implementation, i.e. prioritize correctness over > performance for the initial implementation. > > Because setting memory attributes is roughly analogous to mprotect() on > memory that is mapped into the guest, zap existing mappings prior to > updating the memory attributes. Opportunistically provide an arch hook > for the post-set path (needed to complete invalidation anyways) in > anticipation of x86 needing the hook to update metadata related to > determining whether or not a given gfn can be backed with various sizes > of hugepages. > > It's possible that future usages may not require an invalidation, e.g. > if KVM ends up supporting RWX protections and userspace grants _more_ > protections, but again opt for simplicity and punt optimizations to > if/when they are needed. > > Suggested-by: Sean Christopherson > Link: https://lore.kernel.org/all/Y2WB48kD0J4VGynX@google.com > Cc: Fuad Tabba > Signed-off-by: Chao Peng > Co-developed-by: Sean Christopherson > Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini