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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A536EB64DC for ; Fri, 21 Jul 2023 10:57:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A05802801B3; Fri, 21 Jul 2023 06:57:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98E412801A0; Fri, 21 Jul 2023 06:57:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E12B2801B3; Fri, 21 Jul 2023 06:57:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6A1E42801A0 for ; Fri, 21 Jul 2023 06:57:16 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 34C1C140225 for ; Fri, 21 Jul 2023 10:57:16 +0000 (UTC) X-FDA: 81035317272.24.222764E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id DDF4540014 for ; Fri, 21 Jul 2023 10:57:13 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CfDUw4n5; spf=pass (imf04.hostedemail.com: domain of pbonzini@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=pbonzini@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689937034; h=from:from:sender: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:dkim-signature; bh=JCcb9xtScqAyMOStlm7ewhQnyFA6r02pOvdu3ozJ8ms=; b=cj0l3IUkotlVpL9cqHnTQBuxhv3erbZiDApc7GVrlJRQWjKFOoYP8i74qBQEXQFNNkXzJ2 0eou+a7cIKFz4G1mFfGC/kyfDrV9P4itB/P+uKR7UW712YpeWu286YYUo8Vm4J5ikVYmq/ dGHOVfyT1YAeOn7gVldBN1boiW9p8Cg= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CfDUw4n5; spf=pass (imf04.hostedemail.com: domain of pbonzini@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=pbonzini@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937034; a=rsa-sha256; cv=none; b=JtrOUPqtTY1qUZf3hSR4dpYzxOqfvdloXtEpyJuMaHIRTbQpn/kcJIoQ6qNEINE4iwiBtI ionOA62ePOKbwEnI+ZRXRkybFC+dp5KlM2l/i56lDkoe/gfG8aNh2TkvgIM/+lTfrKZmwN xqmSgbHSS5GiWvQvnnSnvqlgCVpbAMg= 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-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-573-VGq9Rbd-Mw6maYMf3w4usg-1; Fri, 21 Jul 2023 06:57:11 -0400 X-MC-Unique: VGq9Rbd-Mw6maYMf3w4usg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-993c24f3246so217368466b.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=alAohUtT3Xpjm4dIiD2/GFaclF/ttEFRwN0i4kN2G6p4NVmNz+mZqPMfd3JbBmZUMv k31DMt71NgKdgOz8y4mEEwtsxmZzfhXjqtOxNgfr9NorFMXhiyvP0QGI7QFwP4ucgt9l 8XIesuqyBAa+f+dJuqrvnebw2LSA1bhPCsJdXnpPJNk7dySoVMfBE/LMH0CXKDx8OsOd RTV4rqI+cHTd48nuxhh5tCXRmdFotM5rXRh/gB1SQ8Imby8WxJfF2lJ8UHVgqxKeazHn jULgVITowP6P6Q0+QH/oMY5wcOGrS417GJ2XnkcjDf0kSkWta6EfUI4DvNfFSdgOH1fe phlw== X-Gm-Message-State: ABy/qLZDdnzLqpYMO1+IRKZR5N9+U9u9UoxmSAt3tJaDBXXpey5LWeiB iVgs1snCvtPyE4J3yVjpEUtIwYDfuFpDg5soEFV3RKB2alfBBL3NbKTPoVhchS2czL3u7nRYT7L isoGt6KC2Gus= X-Received: by 2002:a17:907:d8a:b0:991:d414:d889 with SMTP id go10-20020a1709070d8a00b00991d414d889mr8230241ejc.15.1689937030831; Fri, 21 Jul 2023 03:57:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlHG8R7IreJRTfdc0Wq/Yo7PIzOhZZy/jcnGLgxDY0N1OVv0CFUqys6sH346KYqEVj6MNTbrkQ== 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 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> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: DDF4540014 X-Rspam-User: X-Stat-Signature: iu75wujkyayfcb4eop7akp8qo5stkuad X-Rspamd-Server: rspam01 X-HE-Tag: 1689937033-127529 X-HE-Meta: U2FsdGVkX1/NCxCXCoLN8v+KjEKAUvisJKDauZF0B36kRruNJ8JJwMroaY6YDbKf8aCWTx0tvv7ABKcwzXhFcGDj/3FgRZRWaCyhvPQLxsIZs1H+f0/Y9KEsLnryIyzr9mDoI85IyWXc0Pwt28qZd0pPuJfQdLV+mcftjiyz69iGlhE8oRLBTUab76rgjpbCzlbpG35mLsMkOZSgpOpM7D/1om83vrTwm9W8mxKmR3ED9m4FdYAOvXAPtq9/2RJsFjeZ8dTPX+v48gFN2A5dtX2PzBK4mot3d1SHg3IWPJis7o9MReUko7AE5icR5NCAA3aLOO6d8Y2BXnGXzx5k6gswAsD5fBhhruYuO7eyM7iZFwdGYhxOnEvcI9eIjHVFSCjXQr3rLuf+r7eTNzkHOE70F9x1kV4HEWacb4QJ9hCyow5N+D1z5br8bTOMdaO6elGPWiOjjGl1qgClYo5ZfffxsmvtACJRGWeTMG5Uo4HR/f7uqa56zOYm0DSm0oQxxQyWrBMO31GHU4YgM45aECP0sRA2QTS4kRpXVIMTrmszTwZtMZvfRaWV74VINJEp7pVX8YvdKgm7DncJURZoEKrRB9rI1hN9O1Utlks7iCkviZ1DdTuMdeGIeKRadeaADGqQUzStwd4ULP9uf3LKhtiMP42OSp5Rw8Sb0pwtCMFpXd82jPWW11j38fXAQAEb8tfsFD3HYqiBH7PR7zZmVfhieUnYSpZjQXJWk+5r1KjCV8cH9qGYdy/7WSxZ2/R0fQBvkbMKnOmqnXsiYwoajJCoicP5PjUhAQzPAQVHJPXbKl4lUy4un00WIHXtHk1NMPIkvxQCaiki3f1GHZwiPGIHUdmcN/GgbTSo/Tqq/GXijZabKgaLw9u1V97hNLH5P7Nze9HoqqR+h6aRzHYtKOxb/xsg/cHszKdNorji28NR+ve3/4RaNYgQTuYJgSo4/yPfwVSUgGmRaMR3rzs VHxiOWz6 +mVSz+NOHhNFQEPmOu0s+ZrchnJCc6bHV22q4mfRxRMqHQM6mInnVJ5nB+JOXrICcGecWv1KeQ9h9x/1dA44XPIVZvxdUYqYmD5UXz6Wv157piSqJqdBkYSAEx57MLATrwEOZGG5R6JXcdtO0r5pexKUoDLn2l4gc7Bvlf9KEyEhKEA9bZ37YR2epKWDKR1LoLC6Jw1s0fr05ieStCBcySIe6cfczBmAI2CZypPbgHuyR/huSxeiy+bd99tBlmMByNIjiShGcEtYY7kchlQjZiEiGFtE2wfmFtUxyKsFgRpbJq7P4yveJvYdMIKnaaGSUT8kFrmR74rskbrien1TEYHG5EbkOOaj3qRFmOL5mZI+aH5+nOB8VaB90PqQU0HhSoflKJKSShh9pL5uaQS2plHNV0m6DBHEURXQ4qdXWpXYjcDRXJU9hmV2o+JM2vk9Paxmw/OyS0MTWOvAlak6LrzrVIia1Dx4TyHnuaiKLsHY781eL96bWqTGP6RRx0Cl9e2JWB8/nzrWIAoK1qUlEQGY7bUwNANK4wuuLLBABlSdyYEk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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