Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3667632rdh; Mon, 27 Nov 2023 23:43:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkDF0JJh5KGd/4wL2Y6rV9VMkiCnKlumZsUAVcy7Uz5jEcTl2MLItS4Ya2zKA6gWDeQ9z8 X-Received: by 2002:a17:90b:1b01:b0:285:9d0d:89a with SMTP id nu1-20020a17090b1b0100b002859d0d089amr11373113pjb.13.1701157379875; Mon, 27 Nov 2023 23:42:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701157379; cv=none; d=google.com; s=arc-20160816; b=N6d236Xk1/krfaXBWCvPhcS8/8soyN1sJ4FRlpvySNU1aFgNfnHVcPkXJwhMIGtW03 U+ZUFzhM6vdJE34drHplwvFat5Ds5aZJNpdHrlzzdv+WRCce+1bddnFwmPpX92mQ2zDa K+2URlZemWlTC2jx/VUZHpk/+4JAOFjXAVu+O5a509rHhN5wuidZu4PuXZxZ+TNpACVE ISwagDJqrIYU0J0rcPQyN0YVY1PBJgdfW+nYa6fS2UC1uwhnXhyiOIqx9JmKqw9m/+0/ kw62eAP08dpviyjrz5gutJBSCLeXs8vz1a9LEkF0RWtHlygOeO4W1l0JCwZhnnPkvLOO sKtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=CEnBNNAbZDViVxp0lQwkboLBGvebtjQoRjp+wXTMCDw=; fh=0JE/s9melwQrHIwHj7I58Itp5rDesgOPWrDm6iWtl/s=; b=McX5IZsaRYdxworP/opiLvC+UAI5JKhDdywS/5cRAGrJOP3Jn+4P0Lc0VD/ybfl9xi 4GtrCMsv4sXPjrZGVkrKEZ8UYuM+Q1hbhVF3JsZ22qgBQiRREQHIGqK+WI0pACRxIZ69 7/Ti68LLVASyb4IQdEAwYJbthrnQj+ROAW+t6chRqQo9ESZmpbWPgUyy51bnJyI+Dw1C KGkgrEIBIg4+kweXPcT0YVrhWK/0qMX316tltd/r5eTVGFfVCnugP0NDF7CpKlU3mJJC P7qFHEGH/hTzkS//ItfQpwi4Yesl2J4Y3DzL3rRhaImnxPFVFEjKSYmvro65q9MjVegC UH1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="T0/1u7Df"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id nd11-20020a17090b4ccb00b00285c51ea0ccsi4764340pjb.17.2023.11.27.23.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 23:42:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="T0/1u7Df"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 1D56E81A73D4; Mon, 27 Nov 2023 23:42:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343870AbjK1Hml (ORCPT + 99 others); Tue, 28 Nov 2023 02:42:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230316AbjK1Hmj (ORCPT ); Tue, 28 Nov 2023 02:42:39 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90E271BB for ; Mon, 27 Nov 2023 23:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701157363; 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=CEnBNNAbZDViVxp0lQwkboLBGvebtjQoRjp+wXTMCDw=; b=T0/1u7DfvtfrKyVMXsGOcywzvoFBqZkE19XLDuCGuI5Iyfgz6KHAzAZK0/5NwmrWKnBOnL ufjkO01EF9Jfd29X4jxysBhH8mGCu4G6hLbzZfkYjuKAV6lUHvBdx4RKaDlEl1NKJGWP3U Cvagzd/Dn0rEJsa14ig8tnuZsT2M0pk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-_GpWeNiQOyCvgl3i1fdTbg-1; Tue, 28 Nov 2023 02:42:42 -0500 X-MC-Unique: _GpWeNiQOyCvgl3i1fdTbg-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40b296a4450so29413235e9.3 for ; Mon, 27 Nov 2023 23:42:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701157361; x=1701762161; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CEnBNNAbZDViVxp0lQwkboLBGvebtjQoRjp+wXTMCDw=; b=YcF7ExsR/bwnOyevT+vAc4ngPzzzx+6IRpPc7Cmi+nPIQ1FZ/6cqBph2UF46m7eAx1 vPbqfzw3UTPGhsKKbVJmViEsakfiyt5phRIpKYDnmIUcugYtycll+O3rTUWrw84rI1TP GsqWvW8TR1NMrUF4iywKwVFzQr7DXFMGqMn6H1RPDDlijdYmdUQhzn6sBN5F6TV/KDto 6wBlgW0nDKhg7d4Z3SPpgY4AfRcqx6lUBxJiUu6TkRLQ81suNXl3qzln2zGfWjUIbpMX H45i2ITagwKlhxzZRBtXw75cPwF2vMB+MCHjwluo8kovGs+afgsxh5q0XpBkz/KC/ILC 5efQ== X-Gm-Message-State: AOJu0YxL8ExVWUtiDTQYlWR+rNXSkDWBDCCruXwnUA1DHbjnXxdcL7lJ lZa5xzPFeCthJlNi1ROfJnS+nkgBwzxpXaHgen/jK/ysV4vby17A4QqGwv1VJWhFVQ4uKmcqiUd +LjDh+0nLTn45f3WKIrFzsvLf X-Received: by 2002:a05:600c:19d1:b0:40b:4268:f375 with SMTP id u17-20020a05600c19d100b0040b4268f375mr5201157wmq.36.1701157360944; Mon, 27 Nov 2023 23:42:40 -0800 (PST) X-Received: by 2002:a05:600c:19d1:b0:40b:4268:f375 with SMTP id u17-20020a05600c19d100b0040b4268f375mr5201138wmq.36.1701157360670; Mon, 27 Nov 2023 23:42:40 -0800 (PST) Received: from starship ([77.137.131.4]) by smtp.gmail.com with ESMTPSA id p34-20020a05600c1da200b00406408dc788sm17210463wms.44.2023.11.27.23.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 23:42:40 -0800 (PST) Message-ID: <78f8ff04c20c45525321247336e16d06063e57d0.camel@redhat.com> Subject: Re: [RFC 19/33] KVM: x86: Decouple kvm_range_has_memory_attributes() from struct kvm's mem_attr_array From: Maxim Levitsky To: Nicolas Saenz Julienne , kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, anelkz@amazon.com, graf@amazon.com, dwmw@amazon.co.uk, jgowans@amazon.com, corbert@lwn.net, kys@microsoft.com, haiyangz@microsoft.com, decui@microsoft.com, x86@kernel.org, linux-doc@vger.kernel.org Date: Tue, 28 Nov 2023 09:42:38 +0200 In-Reply-To: <20231108111806.92604-20-nsaenz@amazon.com> References: <20231108111806.92604-1-nsaenz@amazon.com> <20231108111806.92604-20-nsaenz@amazon.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 pete.vger.email 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 (pete.vger.email [0.0.0.0]); Mon, 27 Nov 2023 23:42:57 -0800 (PST) On Wed, 2023-11-08 at 11:17 +0000, Nicolas Saenz Julienne wrote: > Decouple kvm_range_has_memory_attributes() from struct kvm's > mem_attr_array to allow other memory attribute sources to use the > function. > > Signed-off-by: Nicolas Saenz Julienne > --- > arch/x86/kvm/mmu/mmu.c | 3 ++- > include/linux/kvm_host.h | 4 ++-- > virt/kvm/kvm_main.c | 9 +++++---- > 3 files changed, 9 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 96421234ca88..4ace2f8660b0 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -7297,7 +7297,8 @@ static bool hugepage_has_attrs(struct kvm *kvm, struct kvm_memory_slot *slot, > const unsigned long end = start + KVM_PAGES_PER_HPAGE(level); > > if (level == PG_LEVEL_2M) > - return kvm_range_has_memory_attributes(kvm, start, end, attrs); > + return kvm_range_has_memory_attributes(&kvm->mem_attr_array, > + start, end, attrs); > > for (gfn = start; gfn < end; gfn += KVM_PAGES_PER_HPAGE(level - 1)) { > if (hugepage_test_mixed(slot, gfn, level - 1) || > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 4242588e3dfb..32cf05637647 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -2391,8 +2391,8 @@ kvm_get_memory_attributes(struct xarray *mem_attr_array, gfn_t gfn) > return xa_to_value(xa_load(mem_attr_array, gfn)); > } > > -bool kvm_range_has_memory_attributes(struct kvm *kvm, gfn_t start, gfn_t end, > - unsigned long attrs); > +bool kvm_range_has_memory_attributes(struct xarray *mem_attr_array, gfn_t start, > + gfn_t end, unsigned long attrs); > bool kvm_arch_pre_set_memory_attributes(struct kvm *kvm, > struct kvm_gfn_range *range); > bool kvm_arch_post_set_memory_attributes(struct kvm *kvm, > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index fde004a0ac46..6bb23eaf7aa6 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -2440,10 +2440,10 @@ static int kvm_vm_ioctl_clear_dirty_log(struct kvm *kvm, > * Returns true if _all_ gfns in the range [@start, @end) have attributes > * matching @attrs. > */ > -bool kvm_range_has_memory_attributes(struct kvm *kvm, gfn_t start, gfn_t end, > - unsigned long attrs) > +bool kvm_range_has_memory_attributes(struct xarray *mem_attr_array, gfn_t start, > + gfn_t end, unsigned long attrs) > { > - XA_STATE(xas, &kvm->mem_attr_array, start); > + XA_STATE(xas, mem_attr_array, start); > unsigned long index; > bool has_attrs; > void *entry; > @@ -2582,7 +2582,8 @@ static int kvm_vm_set_mem_attributes(struct kvm *kvm, gfn_t start, gfn_t end, > mutex_lock(&kvm->slots_lock); > > /* Nothing to do if the entire range as the desired attributes. */ > - if (kvm_range_has_memory_attributes(kvm, start, end, attributes)) > + if (kvm_range_has_memory_attributes(&kvm->mem_attr_array, start, end, > + attributes)) > goto out_unlock; > > /* Same comments as for previous patch + how about 'kvm_gfn_range_has_memory_attributes' (I didn't review the memfd patch series and it shows :( ) Best regards, Maxim Levitsky