Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp224274rwo; Fri, 21 Jul 2023 10:51:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlGB2WFEP/tLdXbBRWL3wva6EJVnqIFzm4j3RN0TX0CotsdD08Kbu0YOL2HHL6E2pxH/geFX X-Received: by 2002:a05:6358:9190:b0:134:d806:69df with SMTP id j16-20020a056358919000b00134d80669dfmr486539rwa.18.1689961871535; Fri, 21 Jul 2023 10:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689961871; cv=none; d=google.com; s=arc-20160816; b=XY2J0V5xNRNzGBHX20AMCwNWHjIsgkTeBALqOQcL3qr8IiTizhzIQKzQIbrA0NRcq8 tQuutAsi1sCbhZvybpdwR/qlz7+gFU8rB9Q4dIRKLVb/aRQgHxHLI5O6Jw870Y1Xk46U oG6mBklH1KvoNGnl06YSuhCbSJQnN7cDPR8C/1+rPEL+01Mzzpp+OC5/VPMHw17iWaMr HRBKI8sGdGyVt5Mz3kixnAnlJS0SFtxV+YWkvQDcQy87S65YnZoxWWtKDNIZranf6aa9 /Vxz4SYnOUJWf6UlKHNAwXaQrKj5THk87zpza9PWglwuu8oZokCkqYfcE7yVrS0lgVi2 iheA== 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=0EsEuc6ZrLkBpjfXrbTj3wl8CGw2RCGPAyUMK4WwkjA=; fh=tka8fjfhHFzL15AUMsoY3DpID25kLtr7rZLwDH2qGkg=; b=gBNrxJhcV36G+z1QuSAvmFE8gBqJBi9A9wctyobDPnEdobRS9aqmaC2yL1Q8x+X8FH n2Sx2MiEI4Y2BPd4x+1lbQG5J4Pu+EjhYQqKFfqY3Tfvu58KhX/JevTIvH8rJcgZTTgG 6CZijHmvjWF+V3Vsn9/kc73rtJGEpRbrFIvHoiyWSdZQegm5bkzi5VLCp3aKQhyQb+ll hJrh18mjSITfFUN1vDtKzrdfBCftk51SjvcyDZhbY586hTRW24mcTd7WBEgmKdktVj9g ZM8VpfEicybl/xQvpBo3UmwFMoNDWuJqY9HGAl9u194NWFHM2o2ecPXK4QgKMKq5DQDh r64Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=DoHzE6IB; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a63ae47000000b0056345699503si3328444pgp.2.2023.07.21.10.50.58; Fri, 21 Jul 2023 10:51:11 -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=@google.com header.s=20221208 header.b=DoHzE6IB; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230194AbjGURlV (ORCPT + 99 others); Fri, 21 Jul 2023 13:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbjGURlT (ORCPT ); Fri, 21 Jul 2023 13:41:19 -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 D2F5430DD for ; Fri, 21 Jul 2023 10:41:16 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-cf4cb742715so2061951276.2 for ; Fri, 21 Jul 2023 10:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689961276; x=1690566076; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0EsEuc6ZrLkBpjfXrbTj3wl8CGw2RCGPAyUMK4WwkjA=; b=DoHzE6IB/gTaLmkueM9yb30EUG6tzOb2A5AXrz9PQw1Ifq3ks790NG9A8kHnulrV92 RNCrZzNkmPOc83fANNDf5nXf1wPVFL2y5FNAhz+fPjDVllxc5Oizeq9OoCoSO3jrCWPO Fdo3zuU1ITNzecPSKDNY0XL2xmTCfJibF/rCjlkemXFUh+Sr371B5TqkScdP+lHN0Bsv l8bJ71cW4eJgHOkXZEVFnapIkfHWHqvRivBGgXBk81wx3rhHxJzYdjltDTwHbRDPypPU FqCvfBjArc5TGgWA7G3s9Jm2aOIc06rnT78obfljmzEALSkpFg35cZZdMznfZTRdtzpx x88Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689961276; x=1690566076; 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=0EsEuc6ZrLkBpjfXrbTj3wl8CGw2RCGPAyUMK4WwkjA=; b=A1ctc5xkkM1d8o3dxrQcs38YIJrjfytkjr1l9qC0jaMpzys/C0G/BONw9kG+/506tt P2zHtMSI8i7x1Qp0i4U5KbYaE3FyGO3UKB5XV8Ajduo3HkSBlD15FfvGZ6I0P9QRPZ43 3d1Z+ehx3PWT7hNvf7qzQR1TrmQvckx0fqkNVaBKpsoRmfWiMEl3Xyk9Vob9dsUiOvQS Sde5YocTW+uVqZaesa+fXPIgJPKk0XQDnlr0gpTQgSeIXclzOQwba9Wloxra4v0Fh3Cv zCnHPu7pZy+cKMOPcln8hxVRnOv0QOzNr7bbgrwTOeglz5ZDP0orX/op7rs6K+I+AJDo QMvA== X-Gm-Message-State: ABy/qLbqNp37fwW39MpMiZHHMKRKHZA7Yvxb1TjhnJpi/7j47B78BK06 g8m53OW3+Ta2g/k7RH0FYDwS0fn87vw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:4f41:0:b0:cb6:6c22:d0f8 with SMTP id d62-20020a254f41000000b00cb66c22d0f8mr17638ybb.4.1689961276130; Fri, 21 Jul 2023 10:41:16 -0700 (PDT) Date: Fri, 21 Jul 2023 10:41:14 -0700 In-Reply-To: <6118063e-5c91-acc4-129f-3bacc19f25ce@redhat.com> Mime-Version: 1.0 References: <20230718234512.1690985-1-seanjc@google.com> <20230718234512.1690985-10-seanjc@google.com> <6118063e-5c91-acc4-129f-3bacc19f25ce@redhat.com> Message-ID: Subject: Re: [RFC PATCH v11 09/29] KVM: x86: Disallow hugepages when memory attributes are mixed From: Sean Christopherson To: Paolo Bonzini Cc: 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 , Yu Zhang , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , Vlastimil Babka , 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,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 Fri, Jul 21, 2023, Paolo Bonzini wrote: > On 7/19/23 01:44, Sean Christopherson wrote: > > +static bool range_has_attrs(struct kvm *kvm, gfn_t start, gfn_t end, > > + unsigned long attrs) > > +{ > > + XA_STATE(xas, &kvm->mem_attr_array, start); > > + unsigned long index; > > + bool has_attrs; > > + void *entry; > > + > > + rcu_read_lock(); > > + > > + if (!attrs) { > > + has_attrs = !xas_find(&xas, end); > > + goto out; > > + } > > + > > + has_attrs = true; > > + for (index = start; index < end; index++) { > > + do { > > + entry = xas_next(&xas); > > + } while (xas_retry(&xas, entry)); > > + > > + if (xas.xa_index != index || xa_to_value(entry) != attrs) { > > + has_attrs = false; > > + break; > > + } > > + } > > + > > +out: > > + rcu_read_unlock(); > > + return has_attrs; > > +} > > + > > Can you move this function to virt/kvm/kvm_main.c? Ah, yeah, that's a good idea.