Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1699485rdb; Tue, 20 Feb 2024 04:37:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXy8JRCE3yX213ekyFLJRLuUPJEhTMA8JhFyRGhivKH9P0QoNSxOpcLR02GEJ0TjIBV82RJoqYZieq/o7CMQfarEEdY9fD5jIcYPXJx+w== X-Google-Smtp-Source: AGHT+IEOiWxknjK2WRaXbBFWt8YYrzpA8tTOMVpT2GLYaVoibcOByYnpuOiYmC1u87nmjZd0TrGu X-Received: by 2002:a17:906:5fd7:b0:a3e:4f8b:bcc5 with SMTP id k23-20020a1709065fd700b00a3e4f8bbcc5mr4947526ejv.34.1708432625641; Tue, 20 Feb 2024 04:37:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708432625; cv=pass; d=google.com; s=arc-20160816; b=JpBTzqsx7CbjMPtdli5ZGYaSiYivPRAxtJ92+3ko1j3NFW9oD7GhpCxeJG+ljnZg1b zQQUlEdZiWyYpNsJMoskIZGXZUrHxMHk2hB9NHBSEHAfrDLmBLeWfTM0BWAPsO6FBa04 oIz/P/JVIa0E+Ok3Uud3/1O8OHjWmzoS31iv+3a7M3sA7i/Wpnp4Gcq7tjMANm374Im3 UPtZgmWv0uV5qnyz00BmMG5ltPtSMrVlhRQ9SeB0BDMMYtcPkbkQ4aiXsXteSACWHCIO bQOzVOuB1CRjOg6t2U0uG9Zhg3MRgsiDxOpjVGOHajFa33oFmFV9OfgrOI0gigGHXZeo OWsQ== 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=K4oQYAjPCkfzrw7crGNA2SWjIDNH+IxD97W0ksH/DsI=; fh=b1CtWOVMAK8JQs6DB+SVg+AtEQpeOtyGwB1IJYlzURY=; b=sr3jjoYvyVPrKNkzX3Vn/xWHGiRuIJ3/YfxKnidvjuRU6s0eXtJWFr/Nd0W6ZL2kUn PrydB1R0/KR8pLyJORiISUHseW+c5iFYqSuRDdjcWHuQGb1HYKtri9AouGqPaPS0yA8k PcNZCMa8RHuhtwJyuBV0UBo9DCNktVEtlpWjOJtz6nYxAcyQ363JuZbU+GKkMqKw9xiR K9GISczMnQaUl7TxJvQQx7+MVOeD6X7CXHJPAK0j+YeEteHujXvSA1hcIlAlFjmRZvXt WEA/sH9mXVRiysU9woEq1WW8VTfm3EOjysWIC5FbtF13rsUlvmlzzwZMv23pUjIcQmnt gtIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=j+cvAyCi; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-73028-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73028-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f25-20020a170906085900b00a3ee69998d0si840560ejd.529.2024.02.20.04.37.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 04:37:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73028-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=j+cvAyCi; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-73028-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73028-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 666941F23EE8 for ; Tue, 20 Feb 2024 12:37:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5DDC692F5; Tue, 20 Feb 2024 12:36:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="j+cvAyCi" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 65A135B5CE for ; Tue, 20 Feb 2024 12:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708432616; cv=none; b=JhzPN6I8+Tj2RxrPOMZIKZIEOW5Moe0YFWWf6JiDsjSJ6xez8nXsdL3uHQE6O5n+DYZ/o1Onu/VAkSUuAiEvGUtkeVOpNIRUVM04d2tuoAYo7WXLq04/55hSdKhioZOhyZ5dciWta44Nfkug63o9DSaA8yEXjnXLRA87BuM0n3Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708432616; c=relaxed/simple; bh=iNBAnZuBMR9OpFb371kjh23uca3k0nUqZwIq/GwOHag=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jeVNYc2mvNAkq3iktLP2ZICd9ZZp5ka68YEqk0cF7CPsgQXDA0lpBmVyOguXIGZ+xDdmJ+IecC7dQuqhMOBBI/7XrhwwD0QCKyV3QU9zo/MOYCxM3eiZSwM3fxNqU+ldNCZRufN3FPuPHswYX2K4NGJZXWeEycOEl0OcqyjEqQ8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=j+cvAyCi; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708432615; x=1739968615; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=iNBAnZuBMR9OpFb371kjh23uca3k0nUqZwIq/GwOHag=; b=j+cvAyCiqxCy8DpmyDqx8X2VDyDElKFIRVQ/yEcOwYEBKUUIdqxofUdo nis0wAiLBLZOQTQzr9njWjXfGhPkHn9qfi+xqfKhUtj3CCKO6oHRmJag3 Yi0ZqiAnyD6qPYYzprpqFUGqZZeSxopaARlirK/yW+mGmj/aCoRQM6/2d O7LxRxprmbcvaekKvzN5HgUdhOosRVD3TEsL5dTqoTGA9Cdm49jDfjTSf Brus8vOFM1IMmRedHLU1yQ5W1agpFrr1iC5PZPnWXd6Lgx8jGfllC8bqW LTzC3yfACGlMQkWYU22tvVb32V74pJ9fVuNp85Nfk5mDI3ahN17sX/NbC w==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2395636" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="2395636" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 04:36:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="936448238" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="936448238" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 20 Feb 2024 04:36:49 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id D0CCE305; Tue, 20 Feb 2024 14:36:48 +0200 (EET) Date: Tue, 20 Feb 2024 14:36:48 +0200 From: "Kirill A. Shutemov" To: Baoquan He 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: 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: 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. */ 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 + * 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