Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2111954rdb; Tue, 20 Feb 2024 18:38:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUix8YfJ7CPp6nbYeKpiFH2xgLdt9+KsJNpkVb47zrcoHgwq1KVl+vcZ6kaobb08sQTKZecYw/PT397/02MbwAuf9VgmVO8k4Eh62PJPA== X-Google-Smtp-Source: AGHT+IEMtFgVy/prUL5iRuVA41mycbs3GAVTDNFbPsvSIp3g7jp5OPXNvzUD6t2U2MlGeNv4IeTq X-Received: by 2002:ac8:5f4c:0:b0:42c:7b12:70eb with SMTP id y12-20020ac85f4c000000b0042c7b1270ebmr20241062qta.3.1708483085611; Tue, 20 Feb 2024 18:38:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708483085; cv=pass; d=google.com; s=arc-20160816; b=uHFsFhgGUAxKigIwE7nS6thEeIJDfzkSELLvPYcw7FYcNuNwBBBAR6ReK41LQ5jCtr Aadax+c1OhXlYhoQ+9WKSvyMq9qY6ApQwuMGmQD5xuSlBvIlojVAOgu7NsztsgG5Fmcf rrO/SmefCQ6yIWea6erv3c3xpSaCBarR3Zb3qqf8sjxsCgi6ewdlC90oknBz+8RWIRix Off5RHfXLkLNWSvOpTaIX4n9jcSFdG8QEmBnMlOuHTXPNLdKy6xmGTegRiBnwiMaFQxL 2oDsG6fW+0LKAZTlhJhSF30ZBQQNm9oJ+XLQ9UON7Ucy4wEzs7Df0O0jkTQZsLulqpYQ 0EQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=GIMDrzpnacEme9gLjUpWeDhxio/wVIn1riqvLCd96I4=; fh=n4OnCdto9ks8g3/ozZ8KTfkEmd/DPhDnPmomDuJFCko=; b=yymKQ3ioGEsM5RGqnkeCfy1P0v32xOD+paSeLoi1ySEcVR7nUSxKRpyryN7GZzTQS6 3ZTsolx7vroVCitYN4x8W7A7xb2cx6RMX9cV6mRVakLTR9E5sd4BJ8GQRc53vUCoUqy6 E0463c7GVOeuNaatnfH04UyUVGGyMFrMXdo0xX4z2YzBR7bELBC0EMxjIEHY+QUIqSPw hoEo2Zks0V+tOfMks9lgtmqEO/xpUVcgFJfNnM5f3LvbprAE7a4uUtywrSjbW/kJWEmK pKRNB7zdUuuAQ/cjG4RfzIJNJj8EBfIACbl+CAvnse1tIy+674ZOv1nEvnLQTZdJAh72 UyEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GEDvp+FT; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-73961-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73961-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e9-20020ac86709000000b0042dfb6f53a2si8133462qtp.748.2024.02.20.18.38.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 18:38:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73961-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GEDvp+FT; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-73961-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73961-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2D2DA1C231C3 for ; Wed, 21 Feb 2024 02:38:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A09112837B; Wed, 21 Feb 2024 02:37:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GEDvp+FT" 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 E2A1D249E4 for ; Wed, 21 Feb 2024 02:37:44 +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=1708483067; cv=none; b=AK3KVKlN+jEhyOGj3wi6KP16qLJjGDR9XNJ4RaYppAqfuau1eO0ZYmte7WymgSAHx+Wpr5zdCV6zhJO9B6GXTFDqtqCyHxtU9lEnlDDH/G3WpN9j2/ju8xhAizHmPlkiNuC0E/ytOwSf+A7b5VJN0JXS/pf5m+8zukZlJs6abdk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708483067; c=relaxed/simple; bh=pPTKCdY9creDjcLWMyQf0xXSOqUquqJnbrHQ99XuHvA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GBrx/ehK6Mt8AGNyg8QcNkYGjwwrpwkNLNALOUDsjGsf3hUthGILDi+DqEvNKrOU/PXa7VGOtLhXVsJNDWQcLBuqYFUvFTlSiR2B2Eh9en6l3KLJOZKkURKy/3xk6L6f3sJVnwQz87MTXKqeHKH53TthWfDyWOLxkCi/QkbQAUY= 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=GEDvp+FT; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708483063; 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=GIMDrzpnacEme9gLjUpWeDhxio/wVIn1riqvLCd96I4=; b=GEDvp+FTwyWEWP4kLtTDZt/SPCNC1sE8BJgPEuZbX7lJ4XAtL+ZctcfAiiKvrUVbfqcI3i 9T28gOFhW6oL+JUwcsii6Qbkask0USbEogLlNpNglQ8ByRRl2n4hp4OlrQd0KudGQgfqDl JI38ibRHevfbwkYeEgPvd1+EklWBjzQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-102-Yf2dw5QQPkmYmsDRr--p_Q-1; Tue, 20 Feb 2024 21:37:35 -0500 X-MC-Unique: Yf2dw5QQPkmYmsDRr--p_Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 875453C40B56; Wed, 21 Feb 2024 02:37:34 +0000 (UTC) Received: from localhost (unknown [10.72.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AC77492BD7; Wed, 21 Feb 2024 02:37:32 +0000 (UTC) Date: Wed, 21 Feb 2024 10:37:29 +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-kernel@vger.kernel.org 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.10 On 02/20/24 at 02:36pm, Kirill A. Shutemov wrote: > On Tue, Feb 20, 2024 at 06:25:43PM +0800, Baoquan He wrote: > > > 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) > > ... > > } > > > > What about this fixup: Some nitpicks. > > diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c > index 3612e3167147..425ff6e192e6 100644 > --- a/arch/x86/mm/pat/set_memory.c > +++ b/arch/x86/mm/pat/set_memory.c > @@ -657,7 +657,8 @@ static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long star > > /* > * 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. > + * Return a pointer to the entry and the level of the mapping (or NULL if > + * the entry is none) and level of the entry. ^ this right parenthesis may need be moved to the end. ======= * Return a pointer to the entry and the level of the mapping (or NULL if * the entry is none and level of the entry). ======= > */ > pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, > unsigned int *level) > @@ -704,9 +705,8 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, > * 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 > - * or when the present bit is not set. Otherwise we would return a > - * pointer to a nonexisting mapping. > + * Note: the function returns p4d, pud and pmd either when the entry is marked ~~~ ^ s/and/or/ > + * large or when the present bit is not set. Otherwise it returns NULL. > */ > pte_t *lookup_address(unsigned long address, unsigned int *level) > { > -- > Kiryl Shutsemau / Kirill A. Shutemov >