From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A8D161679 for ; Tue, 20 Feb 2024 10:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708424756; cv=none; b=Pp2UTaR1vR5luqdcyp5RKuKByOytHdMsC55NTqglDw1BoEonnSpmoWL+POWgTMC44ZBBE6CXMRD4abEMVn+BI2+gXP99EJWsrim0LRgscuQnagOc0wCA0GM1rKdg51wvMw7gGdhQcvnyFfxeM4HHO9p00TzUu1qaED29I/q4WuU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708424756; c=relaxed/simple; bh=wg6VDrurtGdejNdwTV9KCdi+jcJpnILodt2ZkcTdixE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JFQtpc4lMfV4jlKO1DzEMb2TuVPcyFZyScExvyX23Ldz0iyPyWd03CzWgkEYqoHE3cYEtQCMHWVM3J/Fi/Txd6A7++PDOjJggB/utTnKQrD9bf1SypQjZ+jUeuCNYYg84sxAgmZq53WCS11F0FQXFhQ3XYyrz4hiG205KUMucQM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JqetGDFX; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JqetGDFX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708424753; 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: in-reply-to:in-reply-to:references:references; bh=6CJmYxHjSreu7pvbpR786lmw2JKf71InmDGqh/N4n8g=; b=JqetGDFXNVBmfCMIoRkGUr563aecGqqDBLKgiB1VkvMWuLyIPI2AlrsvW4jK/eb0h608nh ANtKeOnbqUp32iULdBvkDCQQ7FGgYW5aIhXhrSL1yPJjNohzzcF2OezjlsoGQv3jOlnP9+ 50YmjpBkjycfGr5OOZYWpKNLGm+12g8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-168-IBasa97ZNHaPfAgAfWH0zw-1; Tue, 20 Feb 2024 05:25:48 -0500 X-MC-Unique: IBasa97ZNHaPfAgAfWH0zw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AC57585A589; Tue, 20 Feb 2024 10:25:47 +0000 (UTC) Received: from localhost (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9EDB91121306; Tue, 20 Feb 2024 10:25:46 +0000 (UTC) Date: Tue, 20 Feb 2024 18:25:43 +0800 From: Baoquan He To: "Kirill A. Shutemov" Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCHv7 07/16] x86/mm: Return correct level from lookup_address() if pte is none Message-ID: References: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> <20240212104448.2589568-8-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 On 02/19/24 at 03:52pm, Kirill A. Shutemov wrote: > On Mon, Feb 19, 2024 at 01:12:32PM +0800, Baoquan He wrote: > > On 02/12/24 at 12:44pm, Kirill A. Shutemov wrote: > > > lookup_address() only returns correct page table level for the entry if > > > the entry is not none. > > > > > > Make the helper to always return correct 'level'. It allows to implement > > > iterator over kernel page tables using lookup_address(). > > > > > > Add one more entry into enum pg_level to indicate size of VA covered by > > > one PGD entry in 5-level paging mode. > > > > > > Signed-off-by: Kirill A. Shutemov > > > Reviewed-by: Rick Edgecombe > > > --- > > > arch/x86/include/asm/pgtable_types.h | 1 + > > > arch/x86/mm/pat/set_memory.c | 8 ++++---- > > > 2 files changed, 5 insertions(+), 4 deletions(-) > > > > > > diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h > > > index 0b748ee16b3d..3f648ffdfbe5 100644 > > > --- a/arch/x86/include/asm/pgtable_types.h > > > +++ b/arch/x86/include/asm/pgtable_types.h > > > @@ -548,6 +548,7 @@ enum pg_level { > > > PG_LEVEL_2M, > > > PG_LEVEL_1G, > > > PG_LEVEL_512G, > > > + PG_LEVEL_256T, > > > PG_LEVEL_NUM > > > }; > > > > > > diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c > > > index f92da8c9a86d..3612e3167147 100644 > > > --- a/arch/x86/mm/pat/set_memory.c > > > +++ b/arch/x86/mm/pat/set_memory.c > > > @@ -666,32 +666,32 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, > > > > LGTM, > > > > Reviewed-by: Baoquan He > > > > By the way, we may need update the code comment above function > > lookup_address_in_pgd() and function lookup_address() since they don't > > reflect the latest behaviour of them. > > I am not sure what part of the comment you see doesn't reflect the > behaviour. From my PoV, changed code matches the comment closer that > original. Oh, I didn't make it clear. I mean update the code comment for lookup_address(), and add code comment for lookup_address_in_pgd() to mention the level thing. Maybe it's a chance to do that. ===1> * * Lookup the page table entry for a virtual address. Return a pointer * to the entry and the level of the mapping. * * Note: We return pud and pmd either when the entry is marked large ~~~~~~~~~~~ seems we return p4d too * or when the present bit is not set. Otherwise we would return a * pointer to a nonexisting mapping. ~~~~~~~~~~~~~~~ NULL? */ pte_t *lookup_address(unsigned long address, unsigned int *level) { return lookup_address_in_pgd(pgd_offset_k(address), address, level); } EXPORT_SYMBOL_GPL(lookup_address); === ===2> /* * Lookup the page table entry for a virtual address in a specific pgd. * Return a pointer to the entry and the level of the mapping. ~~ also could return NULL if it's none entry. And do we need to mention the level thing? */ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, unsigned int *level) ... }