Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1430470rdh; Mon, 25 Sep 2023 12:32:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHCoUGDwtLJEN3aVM+X4g1vPBPE+6EhYb/wHNg/y60+bEc92p1yqKmeghz/R+S0llA0slN X-Received: by 2002:a05:6870:a44f:b0:1c8:bbd0:2fc9 with SMTP id n15-20020a056870a44f00b001c8bbd02fc9mr10043745oal.49.1695670354505; Mon, 25 Sep 2023 12:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695670354; cv=none; d=google.com; s=arc-20160816; b=xNQyblmoiM5MhCbbmKAQ9/GJGbfexlmnhEhB3USbYQFRMTzdZbre2KsClyIMEFzjRc psJ+Suu808NJH71D1R+cmmZZE/bUM4rvsxCrHRoNNjUBPBJCC0cYr9C5lsgeSpDJCgMY yy6duqhGIHFA9wlUTDq5r7sFEDdi5dBngCz7l+a3xqu75I+jQmfbSO60W7WfQ7vnkGoa XVD14+zjRK9ENCMAMZ/w7lrmquRe0DQr39h+Jniuuph07m4PL0ei1x9AvmRvCProSqar r/wTxSV3QS50PyXFCb7QxzR8+ecgxKha97rTNBO6fqWjA2+gPG4y2R3XnZu0dYYBJphC aMJg== 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=4OSNJSuzGEyn2eFVxut8UHIn8mk8UoHB1vJTBDeWUjg=; fh=pj50qK/3dcjXkdoGQxvrxbjDtpgaYMSyUhw6gCdm3x4=; b=Shq1cAujVIUjwirDrpugINtzw2+8f7m+Iu/dHTRUc7yzD8mK+vKkKch6BhWezvGITZ jriCqFGf/qrk/0o9a4k0ozlw5PM33YgUw7/7pZvqVy/fKuj3og1GDFPrS8eGcTAGcn40 rKJnrEQN626LjQ4oTyBpu1TvtRfF96XyjDyVoJI15wPwKVLaXHA1f9TPYgGjGD0V3MuW 2uTYBAis/vq4yXlYoqijPf4aawb1PNYm0v7GAcybCL7Zk3hGwl+pqU+5Ve0NGdCFNwtp l85S6eldTcGuaMbYU4c42pzMPQ64NpS75u5lhYDgnk/H3gBHPZ3NCWPVuUYQ38ZVIKv+ hNEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vHOkqRox; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y184-20020a638ac1000000b00565660b78d3si10534833pgd.591.2023.09.25.12.32.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 12:32:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vHOkqRox; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id EBE718077987; Mon, 25 Sep 2023 10:37:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232948AbjIYRhz (ORCPT + 99 others); Mon, 25 Sep 2023 13:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233061AbjIYRhv (ORCPT ); Mon, 25 Sep 2023 13:37:51 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9BD410E for ; Mon, 25 Sep 2023 10:37:44 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d817775453dso9995357276.2 for ; Mon, 25 Sep 2023 10:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695663464; x=1696268264; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4OSNJSuzGEyn2eFVxut8UHIn8mk8UoHB1vJTBDeWUjg=; b=vHOkqRox53qWWq1w+Y3R/aBAcsqP2f0/LNwJwmzxBUBvbELxtAJ6WQLQ4COw481jWg 5XpcRTOL103TSrAzZNlnTMG1Cf+eOC0WZxF+FCAwmbRRdVNuLepHIOBdWyDB08n5YCSe jlJtH2FuqegQqHwVchEEPTST2X8ZE5G4nYrRSKwHxa5x5HM0vMXNJ87VZ0aQtzsS9kdv jAQqIus3+oLXkGka3TY1JEsJ79dwBXNI8OvA2hAUtIPbElxcF8AXME0DcJe+DbcurUGr L+0oTtRH3YdccuVR3DF+3bqDuzvatC7Ug4oeHYoRIb1aOoKvXGwV8mY7IhxF6UXG9hwd 1UMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695663464; x=1696268264; 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=4OSNJSuzGEyn2eFVxut8UHIn8mk8UoHB1vJTBDeWUjg=; b=qIy2XfMFSsAnG60cvIqMrnLqzJgKL2Bj5Q56RnS4wusBWDpEeX56Ns7LwY6TjnLv3N 5MeRRM3KgYU5HiMwkImRBoj7fIPBF/catklLb7RdyDBNEKhnqf4mtxXPiCupx1BtT8va +oFGR7GcboX0wOymTVyFK2xe07MLLt84UxR8+y/U63IOmCQyPXAS9XgoWNMdsCIsYdm0 POg63ERP554JD7Z6cY42qgvG+51VcRqrPd2xZp6ZHbJdgtmTyrl+mA0sSXwVaonOZLQC Se5mOuaRsNr/mATHfdhRzSNtfwTtmYWYAN4JH3Iv0CrqfTKfKdRqR/ccASfBrT9YgQYU rUmA== X-Gm-Message-State: AOJu0YxHrKM4RFhzCVQjwyj14w7icvzTXEbID0nAUmalz4TvaGG9BhYM sXuBO9fWEj/7N8oDdOQRfHjj+MPwOgg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:abac:0:b0:d81:fc08:29ea with SMTP id v41-20020a25abac000000b00d81fc0829eamr67094ybi.2.1695663463860; Mon, 25 Sep 2023 10:37:43 -0700 (PDT) Date: Mon, 25 Sep 2023 10:37:42 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230914015531.1419405-1-seanjc@google.com> <20230914015531.1419405-12-seanjc@google.com> Message-ID: Subject: Re: [RFC PATCH v12 11/33] KVM: Introduce per-page memory attributes From: Sean Christopherson To: Yan Zhao Cc: Paolo Bonzini , 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" , 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 , Anish Moorthy , Yu Zhang , Isaku Yamahata , Xu Yilun , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 10:37:56 -0700 (PDT) On Thu, Sep 21, 2023, Yan Zhao wrote: > On Wed, Sep 20, 2023 at 02:00:22PM -0700, Sean Christopherson wrote: > > On Fri, Sep 15, 2023, Yan Zhao wrote: > > > On Wed, Sep 13, 2023 at 06:55:09PM -0700, Sean Christopherson wrote: > > > > +/* Set @attributes for the gfn range [@start, @end). */ > > > > +static int kvm_vm_set_mem_attributes(struct kvm *kvm, gfn_t start, gfn_t end, > > > > + unsigned long attributes) > > > > +{ > > > > + struct kvm_mmu_notifier_range pre_set_range = { > > > > + .start = start, > > > > + .end = end, > > > > + .handler = kvm_arch_pre_set_memory_attributes, > > > > + .on_lock = kvm_mmu_invalidate_begin, > > > > + .flush_on_ret = true, > > > > + .may_block = true, > > > > + }; > > > > + struct kvm_mmu_notifier_range post_set_range = { > > > > + .start = start, > > > > + .end = end, > > > > + .arg.attributes = attributes, > > > > + .handler = kvm_arch_post_set_memory_attributes, > > > > + .on_lock = kvm_mmu_invalidate_end, > > > > + .may_block = true, > > > > + }; > > > > + unsigned long i; > > > > + void *entry; > > > > + int r = 0; > > > > + > > > > + entry = attributes ? xa_mk_value(attributes) : NULL; > > > Also here, do we need to get existing attributes of a GFN first ? > > > > No? @entry is the new value that will be set for all entries. This line doesn't > > touch the xarray in any way. Maybe I'm just not understanding your question. > Hmm, I thought this interface was to allow users to add/remove an attribute to a GFN > rather than overwrite all attributes of a GFN. Now I think I misunderstood the intention. > > But I wonder if there is a way for users to just add one attribute, as I don't find > ioctl like KVM_GET_MEMORY_ATTRIBUTES for users to get current attributes and then to > add/remove one based on that. e.g. maybe in future, KVM wants to add one attribute in > kernel without being told by userspace ? The plan is that memory attributes will be 100% userspace driven, i.e. that KVM will never add its own attributes. That's why there is (currently) no KVM_GET_MEMORY_ATTRIBUTES, the intended usage model is that userspace is fully responsible for managing attributes, and so should never need to query information that it already knows. If there's a compelling case for getting attributes then we could certainly add such an ioctl(), but I hope we never need to add a GET because that likely means we've made mistakes along the way. Giving userspace full control of attributes allows for a simpler uAPI, e.g. if userspace doesn't have full control, then setting or clearing bits requires a RMW operation, which means creating a more complex ioctl(). That's why its a straight SET operation and not an OR type operation.