Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4985678pxu; Tue, 13 Oct 2020 11:45:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtzbDkdjNeOiG1YOY9jRFoVGNlnFg+wYZJapKGKbG+uqkcOfXETxxshCtYDMDWl5TwMu0R X-Received: by 2002:a50:c38e:: with SMTP id h14mr1062555edf.174.1602614752009; Tue, 13 Oct 2020 11:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602614752; cv=none; d=google.com; s=arc-20160816; b=G5554Ett2Ac0QaO0PnM4p0bxL+TUSkXi1iYnPIIy0gyspaHOAhYiVe+sfSCtH2xKJa sKqrKfD1K4XXkM9/pr27W1+s8UcGBVHVm9WohsbiwSoMtHUBxXsCy3WQlbKtg2IonfWC ecGK0srXnBHobE5SzQ+7R67rhhKmEavb4PW/JnYJxa/rIVKZ0lLwe32TGFEqaI6IgKsb dADHMQ1IVsEWcGj1bxSOWrYDypIuKARzaqhYE10mDfCszfRKYTw34+zPY7WaHtwcMKW+ r4TiWfDcqt3fEgunlUoTgBngU98H7LgJC3axteXglaUIPawxYkBWt6aVkRLU/ue5nGMZ 27rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Xfu/ebxb/UYFOqqMbLllxczv7MOxN3Wzob0VED+pAio=; b=SFYwGg2hLFpDDOkRvbjM4pKZizetJXQYHwjB5Sstyv8xcxBSSqpGYZO1ijGMd/8hJI C78PX6HNzSoL1LXQlII9cdDEmm5JEUiZYlMr2a0BeBn+3T9tbwjKJi61+yf7211YA6pE 54537A/t8hZsjmsLxPKm0+sxwncNM2EXPHav6G5gjBfDy+3sRQEb+VlgtYmO88xGSw3Z 28pew13Mi1WgPWZHcQRD3x/jnPKdxvbotLryQtKqwHkH9u3OteSuQixHKorj4usiQibL S/VgwPIGKdPT+dPGcYRBGBkTgXnb6s2dO+vn23tPi5XY8R0CdVe/D2u44E4wJumqFku9 OJEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ol0BDvd3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v27si424333ejq.250.2020.10.13.11.45.29; Tue, 13 Oct 2020 11:45:51 -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=@infradead.org header.s=casper.20170209 header.b=ol0BDvd3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727287AbgJMQfM (ORCPT + 99 others); Tue, 13 Oct 2020 12:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbgJMQfM (ORCPT ); Tue, 13 Oct 2020 12:35:12 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D55D4C0613D0 for ; Tue, 13 Oct 2020 09:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Xfu/ebxb/UYFOqqMbLllxczv7MOxN3Wzob0VED+pAio=; b=ol0BDvd3j4XzUMB99fNnsM+D1G n9jFecDUIF0qzgjbGPuuSQG6Wt1gfZU8wP1bkuxaVavH9h3QObC5YLkwd8HqA5M7TLi9gBRO4jU5z ZNlICrQqF2RFJgBGM0pYGsGqpGwgx65c5y2HM9Oh/uhMkssBu6Kmjatp9/ZBKViWgAtMCXiI2jAfK Uq7MEv3poSFC3WAlNJXMrw6QdGEhooaPgelwjS0cNMRzObqTTz6aU+NbQQvm7QFnhkqzkut0sdOIx 8XmewLrtpiQI3LHwTaliIfoefZ5QPR0ZUnX6ZZRL40qGhhqOck3s1PdHKjo4D3FoqTnRMmgoAtVdR dmApB3HQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSNGG-0005Hv-IT; Tue, 13 Oct 2020 16:34:52 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 93E14304B90; Tue, 13 Oct 2020 18:34:49 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5A07E203CD911; Tue, 13 Oct 2020 18:34:49 +0200 (CEST) Date: Tue, 13 Oct 2020 18:34:49 +0200 From: Peter Zijlstra To: "Liang, Kan" Cc: Will Deacon , Michael Ellerman , mingo@redhat.com, acme@kernel.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, eranian@google.com, ak@linux.intel.com, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, benh@kernel.crashing.org, paulus@samba.org, David Miller Subject: Re: [PATCH V9 1/4] perf/core: Add PERF_SAMPLE_DATA_PAGE_SIZE Message-ID: <20201013163449.GR2651@hirez.programming.kicks-ass.net> References: <20201001135749.2804-1-kan.liang@linux.intel.com> <20201001135749.2804-2-kan.liang@linux.intel.com> <20201009090927.GQ2611@hirez.programming.kicks-ass.net> <877drz1qbc.fsf@mpe.ellerman.id.au> <20201012084829.GA1151@willie-the-truck> <20201013154615.GE2594@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201013154615.GE2594@hirez.programming.kicks-ass.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 13, 2020 at 05:46:15PM +0200, Peter Zijlstra wrote: > Nah, that generic function, should work for 90% of all archs, it's just > a few oddballs that need something else. > > Also, if we add that hugetlb exception, we'll even get the usermap for > those oddballs right. > > I'll take this version after the merge window, I'll add __weak for the > oddballs and also add the hugetlb userspace thing on top. Like so.. --- Subject: perf,mm: Handle non-page-table-aligned hugetlbfs From: Peter Zijlstra Date: Fri, 9 Oct 2020 11:09:27 +0200 A limited nunmber of architectures support hugetlbfs sizes that do not align with the page-tables (ARM64, Power, Sparc64). Add support for this to the generic perf_get_page_size() implementation, and also allow an architecture to override this implementation. This latter is only needed when it uses non-page-table aligned huge pages in its kernel map. Signed-off-by: Peter Zijlstra (Intel) --- kernel/events/core.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6996,10 +6996,18 @@ static u64 perf_virt_to_phys(u64 virt) #ifdef CONFIG_MMU /* - * Return the MMU page size of a given virtual address + * Return the MMU page size of a given virtual address. + * + * This generic implementation handles page-table aligned huge pages, as well + * as non-page-table aligned hugetlbfs compound pages. + * + * If an architecture supports and uses non-page-table aligned pages in their + * kernel mapping it will need to provide it's own implementation of this + * function. */ -static u64 __perf_get_page_size(struct mm_struct *mm, unsigned long addr) +__weak u64 arch_perf_get_page_size(struct mm_struct *mm, unsigned long addr) { + struct page *page; pgd_t *pgd; p4d_t *p4d; pud_t *pud; @@ -7021,15 +7029,27 @@ static u64 __perf_get_page_size(struct m if (!pud_present(*pud)) return 0; - if (pud_leaf(*pud)) + if (pud_leaf(*pud)) { +#ifdef pud_page + page = pud_page(*pud); + if (PageHuge(page)) + return page_size(compound_head(page)); +#endif return 1ULL << PUD_SHIFT; + } pmd = pmd_offset(pud, addr); if (!pmd_present(*pmd)) return 0; - if (pmd_leaf(*pmd)) + if (pmd_leaf(*pmd)) { +#ifdef pmd_page + page = pmd_page(*pmd); + if (PageHuge(page)) + return page_size(compound_head(page)); +#endif return 1ULL << PMD_SHIFT; + } pte = pte_offset_map(pmd, addr); if (!pte_present(*pte)) { @@ -7037,13 +7057,20 @@ static u64 __perf_get_page_size(struct m return 0; } + page = pte_page(*pte); + if (PageHuge(page)) { + u64 size = page_size(compound_head(page)); + pte_unmap(pte); + return size; + } + pte_unmap(pte); return PAGE_SIZE; } #else -static u64 __perf_get_page_size(struct mm_struct *mm, unsigned long addr) +static u64 arch_perf_get_page_size(struct mm_struct *mm, unsigned long addr) { return 0; } @@ -7074,7 +7101,7 @@ static u64 perf_get_page_size(unsigned l mm = &init_mm; } - size = __perf_get_page_size(mm, addr); + size = arch_perf_get_page_size(mm, addr); local_irq_restore(flags);