Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1140592ybe; Wed, 4 Sep 2019 13:18:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzy7DGXQfK+CJyhUt3ki3DYNOG1Z69OEaemSyVgE9M9B1GkkAg3V9AzSdUcdvGebcrx0JOK X-Received: by 2002:a63:6c02:: with SMTP id h2mr38388861pgc.61.1567628336337; Wed, 04 Sep 2019 13:18:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567628336; cv=none; d=google.com; s=arc-20160816; b=NlaIWEgiNbe4N1nSlIwZE/6nn5D4P9Qc6Qtbbw2X10E1Yqeu4UxB2GAdJrGS+32wJw yfMCt2o03Ghi+dx3aLUZBcfoPGfc/hwvreX2oaMqTQpHH5rOda1fBJBteKe1xgu/zvtN vBUvJg4h1eXBtXFnLX1adaadw9852DN1VfucVSHgkjithg3BI3EHig9CcNBpLyyIycrx f3rcYU1yNOcL8yt4ueVqHSIV+hd5eHhRgjd7skAXt0Bn8yrAOi4vQ/aBN0/AZenpATLb fvm3SuqjQLrijUVll928us8Aq86DRprVi5mmaoeVzadDsqMrIl6m5HEfZbF6Hk8gQSEW SW7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:subject:cc:to:from:date; bh=CA/vHwR1EQdxlKk6IWcy+Wl20mQ5ouvko/YuE+irwQs=; b=QR7elaso+LXGcWIkkcOIgopSspJ8dxHjPByWsN0id3vYV9eSNGj704zK/EXs6v83T/ sjwnrXG8/0yiXN3omDgyQJW15eJUwGutwAINZN0IVFxb+KwUfrWIoNbARZ7/FJqko5k5 FBjYsAKLQmlhhPCoqAbRwgdFFMAkTKAKbh2tFeFP8wStlKszAh9te45uC83g/AQSrKXA cmbeeo3lgXt0IK2/1022veR0S4Kd9Az8KUXGk/Q2EVjKIGWEhdYi4HZMQYzzQ7cmIhWP BTqBOuLygjWvBEktdNly3I6eMpCAff3lLkiPMjD6lPzpoYL7hJPEXpt3anwLGURo6VC+ k3GQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bf3si6089308plb.37.2019.09.04.13.18.40; Wed, 04 Sep 2019 13:18:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729973AbfIDUQh (ORCPT + 99 others); Wed, 4 Sep 2019 16:16:37 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:29636 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727722AbfIDUQe (ORCPT ); Wed, 4 Sep 2019 16:16:34 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x84KBr51004287 for ; Wed, 4 Sep 2019 16:16:33 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2utky98ew7-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 04 Sep 2019 16:16:33 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Sep 2019 21:16:30 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 4 Sep 2019 21:16:21 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x84KGKlh51314888 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Sep 2019 20:16:20 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7DEAAAE045; Wed, 4 Sep 2019 20:16:20 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 50121AE04D; Wed, 4 Sep 2019 20:16:19 +0000 (GMT) Received: from thinkpad (unknown [9.152.96.45]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 4 Sep 2019 20:16:19 +0000 (GMT) Date: Wed, 4 Sep 2019 22:16:18 +0200 From: Gerald Schaefer To: Anshuman Khandual Cc: linux-mm@kvack.org, Andrew Morton , Vlastimil Babka , Greg Kroah-Hartman , Thomas Gleixner , Mike Rapoport , Jason Gunthorpe , Dan Williams , Peter Zijlstra , Michal Hocko , Mark Rutland , Mark Brown , Steven Price , Ard Biesheuvel , Masahiro Yamada , Kees Cook , Tetsuo Handa , Matthew Wilcox , Sri Krishna chowdary , Dave Hansen , Russell King - ARM Linux , Michael Ellerman , Paul Mackerras , Martin Schwidefsky , Heiko Carstens , "David S. Miller" , Vineet Gupta , James Hogan , Paul Burton , Ralf Baechle , linux-snps-arc@lists.infradead.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] mm/pgtable/debug: Add test validating architecture page table helpers In-Reply-To: <1567497706-8649-2-git-send-email-anshuman.khandual@arm.com> References: <1567497706-8649-1-git-send-email-anshuman.khandual@arm.com> <1567497706-8649-2-git-send-email-anshuman.khandual@arm.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 19090420-0020-0000-0000-00000367C323 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19090420-0021-0000-0000-000021BD3453 Message-Id: <20190904221618.1b624a98@thinkpad> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-09-04_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909040202 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 3 Sep 2019 13:31:46 +0530 Anshuman Khandual wrote: > This adds a test module which will validate architecture page table helpers > and accessors regarding compliance with generic MM semantics expectations. > This will help various architectures in validating changes to the existing > page table helpers or addition of new ones. > > Test page table and memory pages creating it's entries at various level are > all allocated from system memory with required alignments. If memory pages > with required size and alignment could not be allocated, then all depending > individual tests are skipped. This looks very useful, thanks. Of course, s390 is quite special and does not work nicely with this patch (yet), mostly because of our dynamic page table levels/folding. Still need to figure out what can be fixed in the arch code and what would need to be changed in the test module. See below for some generic comments/questions. At least one real bug in the s390 code was already revealed by this, which is very nice. In pmd/pud_bad(), we also check large pmds/puds for sanity, instead of reporting them as bad, which is apparently not how it is expected. [...] > +/* > + * Basic operations > + * > + * mkold(entry) = An old and not a young entry > + * mkyoung(entry) = A young and not an old entry > + * mkdirty(entry) = A dirty and not a clean entry > + * mkclean(entry) = A clean and not a dirty entry > + * mkwrite(entry) = A write and not a write protected entry > + * wrprotect(entry) = A write protected and not a write entry > + * pxx_bad(entry) = A mapped and non-table entry > + * pxx_same(entry1, entry2) = Both entries hold the exact same value > + */ > +#define VADDR_TEST (PGDIR_SIZE + PUD_SIZE + PMD_SIZE + PAGE_SIZE) Why is P4D_SIZE missing in the VADDR_TEST calculation? [...] > + > +#if !defined(__PAGETABLE_PMD_FOLDED) && !defined(__ARCH_HAS_4LEVEL_HACK) > +static void pud_clear_tests(pud_t *pudp) > +{ > + memset(pudp, RANDOM_NZVALUE, sizeof(pud_t)); > + pud_clear(pudp); > + WARN_ON(!pud_none(READ_ONCE(*pudp))); > +} For pgd/p4d/pud_clear(), we only clear if the page table level is present and not folded. The memset() here overwrites the table type bits, so pud_clear() will not clear anything on s390 and the pud_none() check will fail. Would it be possible to OR a (larger) random value into the table, so that the lower 12 bits would be preserved? > + > +static void pud_populate_tests(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp) > +{ > + /* > + * This entry points to next level page table page. > + * Hence this must not qualify as pud_bad(). > + */ > + pmd_clear(pmdp); > + pud_clear(pudp); > + pud_populate(mm, pudp, pmdp); > + WARN_ON(pud_bad(READ_ONCE(*pudp))); > +} This will populate the pud with a pmd pointer that does not point to the beginning of the pmd table, but to the second entry (because of how VADDR_TEST is constructed). This will result in failing pud_bad() check on s390. Not sure why/how it works on other archs, but would it be possible to align pmdp down to the beginning of the pmd table (and similar for the other pxd_populate_tests)? [...] > + > + p4d_free(mm, saved_p4dp); > + pud_free(mm, saved_pudp); > + pmd_free(mm, saved_pmdp); > + pte_free(mm, (pgtable_t) virt_to_page(saved_ptep)); pgtable_t is arch-specific, and on s390 it is not a struct page pointer, but a pte pointer. So this will go wrong, also on all other archs (if any) where pgtable_t is not struct page. Would it be possible to use pte_free_kernel() instead, and just pass saved_ptep directly? Regards, Gerald