Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5204034ybp; Mon, 14 Oct 2019 17:34:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKMvnO6LP1U83IOCgmu997wZEj/2bRtAWOB/AEUeCCxlP5gAL0Wr3Yizs1TQv408IqWYmg X-Received: by 2002:a17:906:3946:: with SMTP id g6mr31300555eje.49.1571099671627; Mon, 14 Oct 2019 17:34:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571099671; cv=none; d=google.com; s=arc-20160816; b=fGl3b8FILUN4fSVNB2z10R4zP0zR1u1RXAgEKa1vLn065tYzjokUKaQXPlVOeq3WiK lWBZD+zRXB4AwBFg0FhJm8hnj3CupzxOdv8e+fCwRVxOlOpEkKRWmXJnq8+UbYaE7vaU 9jRQrllry616bD2NfmE8T/iA+gp6mSLLYu3kmSNPJPXbw7niMnbLe85yUwJONdVpVeS1 erSaDDu8rh3X6YEMttQpkLxMXgXcOi5IfQdCZQ0gKiEy3D2oKNvd9CgP7Gi4d/+b9Ltg AsvcqycZLOrZycamu3ulsC3MzQARUL5upwViCySW9PayAmWRnYD16ackvCjaDBUmqrVO l61g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=LvNlasHHPKccXox7dKQ61wjVRqsBAIykBowufugafNw=; b=tyVTSmSYQyDXQVHebBtJN4zFDo9hZjBHMAHKFrcxdhxaD+yJBCabYGY4lMXTsI3fgd J9eYyeRyzAOkZfogXYxHDROUnYEMw/MCy/Bx66rOVBbqixPLBduQtHEYeaj1l/FEQTuW vx0HVwZ/t6QV/72megPq7wVzbTHIqSLMiUc9XquN3ptQr3itCxT8VkGs45ZHuf0Ytosl odkwQhWsJI1dyMUV4Kfdf4+WeZnArSilJkbGmdPEVaOkutjFHBh0WTKFs/iAyX9mFIgw BtXhWZmzz1GeLtbh6DH/PvQhXkQNMFRv4Z1UAydQLbOHRDYS5/FGGANDcW73jxIaEOJC ro7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=JHYeinNb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m55si14258450edc.17.2019.10.14.17.34.07; Mon, 14 Oct 2019 17:34:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=JHYeinNb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733276AbfJNUi6 (ORCPT + 99 others); Mon, 14 Oct 2019 16:38:58 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:45826 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733194AbfJNUi6 (ORCPT ); Mon, 14 Oct 2019 16:38:58 -0400 Received: by mail-lf1-f66.google.com with SMTP id r134so12724964lff.12 for ; Mon, 14 Oct 2019 13:38:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LvNlasHHPKccXox7dKQ61wjVRqsBAIykBowufugafNw=; b=JHYeinNbUhDU9JOT1icXjbCc6D8tAAxdTuxxBxHbP7n5BxrRPMJN6jHCkGxuqtQsmo F38havP+GnWryvYUJVgEpDkK/4ERk+FjYdhOiRWDlYL15HUvXuaNMXnyFom5PU8TxlkT jhgnijOPh4hbegqJqlkHK+WVNTGc3Zb0SylD4= 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=LvNlasHHPKccXox7dKQ61wjVRqsBAIykBowufugafNw=; b=aVXEdkbyMmS4oZwhW2RR1Pr3HDsRsKfcJYqH5v1jhKBecprZpliFuXgRv/NINEoU6j K9wEnglDbjw6KQlAc47o7THNax/u/Oi+OGwwcEMWFd2QIaj5jr2yj7+QMFojj/ESwVZm 26IvItrgnmAUZd+UTX/qC6zsnHgXYPLhFk5dFNdqS8ChNPp98q+y4Nv8F8ZduGW5fjuk v+PiKzQYHzdV4QposuwoBj96gEOdSf0HSSQ0nUOkNQXoIwxk8csLuemVLGwHoGda9A0S tbNq0VcRhUiD45wAVToI9KhTAIzXkvW/yegZY08GxqMido6w7p/sbwgt/zrLSijCYg+0 aOfg== X-Gm-Message-State: APjAAAW3D4DaneYl+1vtOgpWPOfbThF0/SuTZdCU/WsUV9gcTAuvo8bt ymUrcRtsYSaDOuQC06KJGUfxUxjC3fY= X-Received: by 2002:ac2:4a81:: with SMTP id l1mr16845922lfp.67.1571085535246; Mon, 14 Oct 2019 13:38:55 -0700 (PDT) Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com. [209.85.208.177]) by smtp.gmail.com with ESMTPSA id l3sm4392433lfc.31.2019.10.14.13.38.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Oct 2019 13:38:51 -0700 (PDT) Received: by mail-lj1-f177.google.com with SMTP id y23so17899954lje.9 for ; Mon, 14 Oct 2019 13:38:51 -0700 (PDT) X-Received: by 2002:a2e:8315:: with SMTP id a21mr10388327ljh.133.1571085530949; Mon, 14 Oct 2019 13:38:50 -0700 (PDT) MIME-Version: 1.0 References: <20191011121951.nxna6hruuskvdxod@box> <20191011223818.7238-1-vgupta@synopsys.com> <8bfd023b-5c00-8355-fd0f-3b4377951e6c@gmail.com> In-Reply-To: <8bfd023b-5c00-8355-fd0f-3b4377951e6c@gmail.com> From: Linus Torvalds Date: Mon, 14 Oct 2019 13:38:34 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC] asm-generic/tlb: stub out pmd_free_tlb() if __PAGETABLE_PMD_FOLDED To: Vineet Gupta Cc: linux-arch , Arnd Bergmann , Peter Zijlstra , "Aneesh Kumar K . V" , Linux Kernel Mailing List , Nick Piggin , Linux-MM , Andrew Morton , linux-snps-arc@lists.infradead.org, Will Deacon , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 14, 2019 at 12:08 PM Vineet Gupta wrote: > > > And yes, pmd_clear_bad() should just go away. We have > > > > static inline int pmd_none_or_clear_bad(pmd_t *pmd) > > { > > if (pmd_none(*pmd)) > > return 1; > > if (unlikely(pmd_bad(*pmd))) { > > pmd_clear_bad(pmd); > > return 1; > > } > > return 0; > > } That was a particularly bad example. The pmd always exists, even in a 2-level setup. It's the pgd/p4d/pud that end up containing a lower level, but pmd_none() is never one of the fixed "doesn't exist" cases. > > Exactly what part isn't working for you? > > I haven't tested that patch but I suspect even if it was broken, it would not > necessarily show right away with a trivial test. > > Anyhow my worry/confusions starts at free_pgd_range() where > pgd_none_or_clear_bad(pgd) is no-op given pgd_none()/pgd_bad() are stubs for nopmd > case. Right. If you have a two-level setup, then p[g4u]d_none_or_clear_bad() should end up being no-ops. Buit then: > And the validation of pgd entry actually happens in pmd_none_or_clear_bad(pmd) > since there pmd actually ends up referencing pgd entry. Hence the ensuing > pmd_clear_bad() doesn't seem like if it could be stubbed out. Yes, you're correct, I was just "off by one" in my levels. Yeah, the folding is damn confusing. And it doesn't help that I think some of the code talks about the lower level being folded into the higher level for historical reasons, so we have those PMD_FOLDED macros etc, which are really about pud() just going away because pmd is folded inside the pud. So when the pud level is compiled away, we talk about the pmd level being folded into it, and then we get confusion (like mine above) where you end up being off by one level, because depending on how it's being talked about, you talk about one or the other. And it shows in the header files too. We have "pgtable-nopmd.h", which then defines the page table accessors not for the pmd level, but for the pud level. Which is why I then spout nonsense like the above about pmd_none() - because I was thinking of the nopmd case, but that makes the p*u*d_none() be always 0, not p*m*d_none(). So we have this whole "off-by-one" error in our naming and thus our thinking, and it's really easy to just get really confused about it. We should probably get rid of the whole "PMD_FOLDED" logic, and instead talk about "no PUD level". It actually shows in our types too. We do this: typedef struct { pud_t pud; } pmd_t; #define PTRS_PER_PMD 1 because some of the code thinks of the pmd as containing the pud. But it would probably be better to do it the other way around, and just consistently think of it as "pud level doesn't exist, the pud level just contains a pmd" instead. So we have these really odd "somethimes we think of pmd as part of a pud entry" vs "sometimes we think of pud as just containing a single pmd". And I think that latter model is the better mental model, but then we should have typedef struct { pmd_t pud; } pud_t; #define PTRS_PER_PUD 1 instead, and we'd get static inline pmd_t * pmd_offset(pud_t * pud, unsigned long address) { return &pud->pmd; } and that would make more sense, wouldn't it? But trying to fix our odd "we seem to think about it wrong" model would likely be too painful to be realistic., It would involve renaming nop4d.h -> nopgd.h nopud.h -> nop4d.h nopmd.h -> nopud.h and turning those types around (so we'd have those typedef struct { p4d_t p4d; } pgd_t; typedef struct { pud_t pud; | p4d_t; typedef struct { pmd_t pmd; } pud_t; for no-pgd/no-p4d/no-pud respectively. So then a 2-level machine would only define the pmd and pte levels, and be done with it, because the upper levels would be defined in terms of those. But that's not what we do, and we mix up levels in odd and confusing ways. And now I've said pgd/pud/p4d/pmd so many times that I've confused myself and think I'm wrong again, and I think that historically - originally - we always had a pgd, and then the pmd didn't exist because it was folded into it. That makes sense from a x86 naming standpoint. Then x86 _did_ get a pmd, and then we added more levels in between, and other architectures did things differently. So I think the confusion is historical, and is because we've switched between thinking that the the lower level that doesn't exist, but is embedded in the upper level, and slowly converted to "it's the upper level that doesn't exist, and just contains the lower level" The point stands: it's confusing, and we should probably pick one model, and the model we pick should likely be "this level doesn't exist, and just wraps the lower level", so it *should* be "no pgd"/"no p4d"/"no pud". Linus