Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp692386pxx; Wed, 28 Oct 2020 14:40:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnO+gscu8YqzZIt4rLpbW7E5KAH0adodTUo5F06rSPy/DJ6PyF0DsIF0kj4VTe7uY21Dxu X-Received: by 2002:a05:6402:1c04:: with SMTP id ck4mr986839edb.274.1603921225116; Wed, 28 Oct 2020 14:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603921225; cv=none; d=google.com; s=arc-20160816; b=07VtveCx+PSu0zMdXIJigIrGTYksKS5gnCeRTQ9BHjYYh+bjhYA7L32GurXNXNFh22 027BH/wHnH6jCahiuTEmAy4NaMnFoRieb2TPtK9PxNIKvpYztQheraZGgFlJPyp8I4EO K6rr0LwvTXF+MF9kbkJh+ztqzYavt0VkkCuJF5pxv72W/uhY7XzBJJp0I2nRM/u9Itlk usamq9SyrRia1LytABV7OJ60CRqSlyB5FsqY1UOoQcwqQ7hteiD6knsha8FtL4dACmXO IMqaIINPcAtKvxxCctPaorHxoMTeSlKJbaKuxVXivT0/vwtEcOcTlS3YVoeqPP0jVQgR pj8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=QtLd4MZtASQ2zrGtGhpf+MoowsKrVZdCQedmVoJd9Rc=; b=q/CnCcGVQtb74kh0OwGy711tt89D9ssPXqqXDd7DfPAiKAceopGxsDR6zyoj1+MKIF GkkJvFsYwuEjKliKNBarGyHpooYRZPHrjroy/xeFLULTqIic419TzzjzGWVjpJq5rrFG wLMXSgW2AE6gtDrvubx1bMtJEdL79MSxn9fxLT0Uzdj/T+wV2va33gZzYagZYx9Ik7LD AqJmu9zsKHN6taJP9hRBUNkxrAIqqvmN30a3A4kmskT2tWfCTSeQfmYlpsyUUAUE88F5 2qegGlkx/0rm1cIDhQ7DcsTCBvQpIvFLPqThJRogC09CDN9Z4wVQADYeja6g8/cff9pA rF7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SueMScFf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b29si566305edn.354.2020.10.28.14.40.03; Wed, 28 Oct 2020 14:40:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SueMScFf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1832213AbgJ0WJX (ORCPT + 99 others); Tue, 27 Oct 2020 18:09:23 -0400 Received: from mail-il1-f195.google.com ([209.85.166.195]:45378 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2505872AbgJ0WJX (ORCPT ); Tue, 27 Oct 2020 18:09:23 -0400 Received: by mail-il1-f195.google.com with SMTP id g7so2909685ilr.12 for ; Tue, 27 Oct 2020 15:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QtLd4MZtASQ2zrGtGhpf+MoowsKrVZdCQedmVoJd9Rc=; b=SueMScFfjbh8XdzU6F54EIkMXs8/Wtn/eXnJRab8hMwLvr8ZYxl9q4sbIuHjn6xIZM gNu7A9DCdnVKmAFaRgH1p8pHuaDP8b31v2ISiN+iH4o/QAohO08LS6eP75LpqUKGbo5t 0QToa+81/KVB1jd4PH9AFE75XKUJ8pbo8pF/yez9VjMJTaehId5F9mPLuIu+vtA2Frxf UPJba55YPJ1EvpCJeA4JnQLXVUo45vtF24vQf0+at8Ha9ehe0+J0AQiwX729a8++U8wU cxKwN/occG1uD9K/uClYiEaKCKws1mpNXP4t1R4EivxxlkljqqOM7SvFykOTcSaX1+sJ XBKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QtLd4MZtASQ2zrGtGhpf+MoowsKrVZdCQedmVoJd9Rc=; b=NRlYZGlGJMS9+X7iV/SOTF8VuCaVZm5BkmWo4QrjxJt/sCoa07o/64zArcUilKEkda O/thC8fvshyURMIFaINk4z6mK07XLuB69b/Kf7+bSfuHSnskH9mlWeZOLfyAfFSy4l/c d+mw0pgbyZIqggYjOvdJx5n1xnCiEZ2K6z7tq4m95e7G7GnsEWeWzwv063SYgSJzGsPp kPZwqVOpAaDG6o+PG+9p+/B3mszEd1nLp9raSL1Ex9taaPQjwPAGLx7pvgOR8/fv5Lmi 04Vp1H+AlNzYVIRhzXD3fTYmhj2FGndtIJPtMiyDr9gojKnIbeo6v8iNb/M7KWMSjLgL zYqA== X-Gm-Message-State: AOAM5326SVZHid+YIT6TIKwQ4o4Pnl6B8Q/liFttygz8UZPiNNQHPJG5 /Fv3WSnUEZZNT4IG3byUSKRHxX2tUN5NN63Ztmp6dg== X-Received: by 2002:a92:d5c4:: with SMTP id d4mr3228850ilq.154.1603836561979; Tue, 27 Oct 2020 15:09:21 -0700 (PDT) MIME-Version: 1.0 References: <20201027214300.1342-1-sean.j.christopherson@intel.com> <20201027214300.1342-4-sean.j.christopherson@intel.com> In-Reply-To: <20201027214300.1342-4-sean.j.christopherson@intel.com> From: Ben Gardon Date: Tue, 27 Oct 2020 15:09:11 -0700 Message-ID: Subject: Re: [PATCH 3/3] KVM: x86/mmu: Use hugepage GFN mask to compute GFN offset mask To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 27, 2020 at 2:43 PM Sean Christopherson wrote: > > Use the logical NOT of KVM_HPAGE_GFN_MASK() to compute the GFN offset > mask instead of open coding the equivalent in a variety of locations. I don't see a "no functional change expected" note on this patch as was on the previous one, but I don't think this represents any functional change. > > Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon > --- > arch/x86/kvm/mmu/mmu.c | 2 +- > arch/x86/kvm/mmu/mmutrace.h | 2 +- > arch/x86/kvm/mmu/tdp_mmu.c | 2 +- > arch/x86/kvm/x86.c | 6 +++--- > 4 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 3bfc7ee44e51..9fb50c666ec5 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -2827,7 +2827,7 @@ int kvm_mmu_hugepage_adjust(struct kvm_vcpu *vcpu, gfn_t gfn, > * mmu_notifier_retry() was successful and mmu_lock is held, so > * the pmd can't be split from under us. > */ > - mask = KVM_PAGES_PER_HPAGE(level) - 1; > + mask = ~KVM_HPAGE_GFN_MASK(level); > VM_BUG_ON((gfn & mask) != (pfn & mask)); > *pfnp = pfn & ~mask; > > diff --git a/arch/x86/kvm/mmu/mmutrace.h b/arch/x86/kvm/mmu/mmutrace.h > index 213699b27b44..4432ca3c7e4e 100644 > --- a/arch/x86/kvm/mmu/mmutrace.h > +++ b/arch/x86/kvm/mmu/mmutrace.h > @@ -372,7 +372,7 @@ TRACE_EVENT( > > TP_fast_assign( > __entry->gfn = addr >> PAGE_SHIFT; > - __entry->pfn = pfn | (__entry->gfn & (KVM_PAGES_PER_HPAGE(level) - 1)); > + __entry->pfn = pfn | (__entry->gfn & ~KVM_HPAGE_GFN_MASK(level)); > __entry->level = level; > ), > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index 27e381c9da6c..681686608c0b 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -209,7 +209,7 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn, > > WARN_ON(level > PT64_ROOT_MAX_LEVEL); > WARN_ON(level < PG_LEVEL_4K); > - WARN_ON(gfn & (KVM_PAGES_PER_HPAGE(level) - 1)); > + WARN_ON(gfn & ~KVM_HPAGE_GFN_MASK(level)); > > /* > * If this warning were to trigger it would indicate that there was a > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 397f599b20e5..faf4c4ddde94 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -10451,16 +10451,16 @@ static int kvm_alloc_memslot_metadata(struct kvm_memory_slot *slot, > > slot->arch.lpage_info[i - 1] = linfo; > > - if (slot->base_gfn & (KVM_PAGES_PER_HPAGE(level) - 1)) > + if (slot->base_gfn & ~KVM_HPAGE_GFN_MASK(level)) > linfo[0].disallow_lpage = 1; > - if ((slot->base_gfn + npages) & (KVM_PAGES_PER_HPAGE(level) - 1)) > + if ((slot->base_gfn + npages) & ~KVM_HPAGE_GFN_MASK(level)) > linfo[lpages - 1].disallow_lpage = 1; > ugfn = slot->userspace_addr >> PAGE_SHIFT; > /* > * If the gfn and userspace address are not aligned wrt each > * other, disable large page support for this slot. > */ > - if ((slot->base_gfn ^ ugfn) & (KVM_PAGES_PER_HPAGE(level) - 1)) { > + if ((slot->base_gfn ^ ugfn) & ~KVM_HPAGE_GFN_MASK(level)) { > unsigned long j; > > for (j = 0; j < lpages; ++j) > -- > 2.28.0 >