Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp909266ybz; Wed, 22 Apr 2020 10:03:57 -0700 (PDT) X-Google-Smtp-Source: APiQypL/D8cCu2S4+nqUm7q4KONa7pBJSLMnOx6aL+FDKBIbh6Gb//neIgQ3cPoCZiU6zkX+cij1 X-Received: by 2002:aa7:c3cb:: with SMTP id l11mr23181677edr.129.1587575036921; Wed, 22 Apr 2020 10:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587575036; cv=none; d=google.com; s=arc-20160816; b=cFJHIsKc5DQ8+lPekCbOiA4ph8shBtVPKf4xF6ALaDKr7uECBYs3K+4O1PVE3wSiaK gVNI65cYE6Ghe0OKAQqKIoXgzsFiXJRHG3LNIgNqZzBnRnOnU4WP52iLe8DZwQTSHd9r pL5DUQpGiEpgdjlRf4V/ehY1NJNyDejeBSR2RF+/21Tyh82FkGBx7upqR1UrvXB8m6pu pWS+ZGb6S0n/O7S/KhnNqKv3e3Vp3cffS7niH8wlgaOiLeYD9pBQtBvqRhAwsvMuDR0O Ww3mcENgVLmNT/LJkcS9GgwYOILxqOCbzIg+i08elHVm7GEENbf5sNRrzkuaxqvhab4C 6vFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=QCOhu8y6jcDa7Xa/hP0pPsvNknCJHsRI68OSk0LUzHk=; b=rLpxNc0pVXE5D0AztU4scv/ItuT/U6GFGLn6JG676FPbzLzvjq66DpH+FzLJtkuTGe ONJDAFa/nwmP/Fsy/rp/4jit7hGGrqwvTnM8vdWDrWc2eE8JoMfOcQghI5bmdVu+H+E+ GazSaPY8enQhAI1JUikPjoho6IEuS5Wcjps8J2aTqF0XgZrI0gZGHqfkH/xJv4p2HedQ 3maZ102Xb9lh2nGRD9CabzHotavqffvCsC41fo6cGgE9i3QCcfUr6lv2qX71EbVep1O6 thGqJXZpLbNGkH6c8/x/EZyFyhM+3IKs5ch3v9Fh/ZxjzQT72TJbFhhdswbVvChgSZoi XJEw== ARC-Authentication-Results: i=1; mx.google.com; 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 dk9si3650495edb.403.2020.04.22.10.03.11; Wed, 22 Apr 2020 10:03:56 -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; 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 S1726760AbgDVRBU (ORCPT + 99 others); Wed, 22 Apr 2020 13:01:20 -0400 Received: from verein.lst.de ([213.95.11.211]:53665 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbgDVRBU (ORCPT ); Wed, 22 Apr 2020 13:01:20 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 485BF68C4E; Wed, 22 Apr 2020 19:01:16 +0200 (CEST) Date: Wed, 22 Apr 2020 19:01:16 +0200 From: Christoph Hellwig To: Qian Cai Cc: Christoph Hellwig , Borislav Petkov , "Peter Zijlstra (Intel)" , x86 , LKML , kasan-dev Subject: Re: AMD boot woe due to "x86/mm: Cleanup pgprot_4k_2_large() and pgprot_large_2_4k()" Message-ID: <20200422170116.GA28345@lst.de> References: <1ED37D02-125F-4919-861A-371981581D9E@lca.pw> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="LQksG6bCIzRHxTLp" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1ED37D02-125F-4919-861A-371981581D9E@lca.pw> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Wed, Apr 22, 2020 at 11:55:54AM -0400, Qian Cai wrote: > Reverted the linux-next commit and its dependency, > > a85573f7e741 ("x86/mm: Unexport __cachemode2pte_tbl”) > 9e294786c89a (“x86/mm: Cleanup pgprot_4k_2_large() and pgprot_large_2_4k()”) > > fixed crashes or hard reset on AMD machines during boot that have been flagged by > KASAN in different forms indicating some sort of memory corruption with this config, Interesting. Your config seems to boot fine in my VM until the point where the lack of virtio-blk support stops it from mounting the root file system. Looking at the patch I found one bug, although that should not affect your config (it should use the pgprotval_t type), and one difference that could affect code generation, although I prefer the new version (use of __pgprot vs a local variable + pgprot_val()). Two patches attached, can you try them? --LQksG6bCIzRHxTLp Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0001-x86-Use-pgprotval_t-in-protval_4k_2_large-and-pgprot.patch" From 71829ed28a4f3d616382e7a362d501eb9ea7dc13 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 22 Apr 2020 18:53:08 +0200 Subject: x86: Use pgprotval_t in protval_4k_2_large and pgprot_4k_2_large Use the proper type for "raw" page table values. Signed-off-by: Christoph Hellwig --- arch/x86/include/asm/pgtable_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 567abdbd64d3..7b6ddcf77d70 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -478,7 +478,7 @@ static inline pteval_t pte_flags(pte_t pte) unsigned long cachemode2protval(enum page_cache_mode pcm); -static inline unsigned long protval_4k_2_large(unsigned long val) +static inline pgprotval_t protval_4k_2_large(pgprotval_t val) { return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | ((val & _PAGE_PAT) << (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT)); @@ -487,7 +487,7 @@ static inline pgprot_t pgprot_4k_2_large(pgprot_t pgprot) { return __pgprot(protval_4k_2_large(pgprot_val(pgprot))); } -static inline unsigned long protval_large_2_4k(unsigned long val) +static inline pgprotval_t protval_large_2_4k(pgprotval_t val) { return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | ((val & _PAGE_PAT_LARGE) >> -- 2.26.1 --LQksG6bCIzRHxTLp Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0002-foo.patch" From e5a6c2e84accad3d528c5c90c74071d10079db9a Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 22 Apr 2020 18:54:45 +0200 Subject: foo --- arch/x86/include/asm/pgtable_types.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 7b6ddcf77d70..c6d4725269bb 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -485,7 +485,10 @@ static inline pgprotval_t protval_4k_2_large(pgprotval_t val) } static inline pgprot_t pgprot_4k_2_large(pgprot_t pgprot) { - return __pgprot(protval_4k_2_large(pgprot_val(pgprot))); + pgprot_t new; + + pgprot_val(new) = protval_4k_2_large(pgprot_val(pgprot)); + return new; } static inline pgprotval_t protval_large_2_4k(pgprotval_t val) { @@ -495,9 +498,11 @@ static inline pgprotval_t protval_large_2_4k(pgprotval_t val) } static inline pgprot_t pgprot_large_2_4k(pgprot_t pgprot) { - return __pgprot(protval_large_2_4k(pgprot_val(pgprot))); -} + pgprot_t new; + pgprot_val(new) = protval_large_2_4k(pgprot_val(pgprot)); + return new; +} typedef struct page *pgtable_t; -- 2.26.1 --LQksG6bCIzRHxTLp--