From patchwork Mon May 4 14:58:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Chartre X-Patchwork-Id: 11526459 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63D7215AB for ; Mon, 4 May 2020 14:59:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2FFC8206D7 for ; Mon, 4 May 2020 14:59:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NYaPu6pU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2FFC8206D7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6095D8E002D; Mon, 4 May 2020 10:59:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5DFD58E0024; Mon, 4 May 2020 10:59:58 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F6CB8E002D; Mon, 4 May 2020 10:59:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0077.hostedemail.com [216.40.44.77]) by kanga.kvack.org (Postfix) with ESMTP id 37F7C8E0024 for ; Mon, 4 May 2020 10:59:58 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EBAF5180AD80F for ; Mon, 4 May 2020 14:59:57 +0000 (UTC) X-FDA: 76779346434.11.frame17_39d84dbdc0331 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,alexandre.chartre@oracle.com,,RULES_HIT:30054:30064,0,RBL:156.151.31.86:@oracle.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: frame17_39d84dbdc0331 X-Filterd-Recvd-Size: 5872 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 May 2020 14:59:57 +0000 (UTC) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 044ElbDo116519; Mon, 4 May 2020 14:59:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=ItAga/RAZZLJV2kYsxGyvAeBJnzaxmTXCE/C0Q2axKc=; b=NYaPu6pUwjVJ3gCuMmIeR4QjgnjJAa1EfrSnTxbil4a2AIEQnfp5a3IaEV4En82n/9yJ QKzIqppk1aCLias8xSIi3Hdf/5k6pH4iWeimowFwt0UtX25QaaQT/EMTM4/wBSVJBQpG T9+L70neL+NhewAs4vErWbCyeqzWqQniZWEeXy6rwJY8oXFgLs/cOg6ku6dPIzv21I4+ jNK2CnZJe5oI6nUgtW4FUZLA87Eu0ZlmOvrmHOsPv1TFt6KsiiqkCnrMiiSmaXbQhVWz clS6E1vVtFMO4hetYxBiUvXFOP/1e1ptoJxt8B8uUaARL0+MuP9uvDF86QPWIgaD3GwU zg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 30s09qyfqf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 04 May 2020 14:59:47 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 044EkelF094657; Mon, 4 May 2020 14:59:46 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 30sjdqq654-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 04 May 2020 14:59:46 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 044Exi5M022173; Mon, 4 May 2020 14:59:44 GMT Received: from linux-1.home.com (/10.175.9.166) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 04 May 2020 07:59:44 -0700 From: Alexandre Chartre To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, konrad.wilk@oracle.com, jan.setjeeilers@oracle.com, liran.alon@oracle.com, junaids@google.com, graf@amazon.de, rppt@linux.vnet.ibm.com, kuzuno@gmail.com, mgross@linux.intel.com, alexandre.chartre@oracle.com Subject: [RFC v4][PATCH part-2 03/13] mm/dpt: Add decorated page-table entry offset functions Date: Mon, 4 May 2020 16:58:00 +0200 Message-Id: <20200504145810.11882-4-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200504145810.11882-1-alexandre.chartre@oracle.com> References: <20200504145810.11882-1-alexandre.chartre@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9610 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 mlxscore=0 bulkscore=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005040123 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9610 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 clxscore=1015 suspectscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005040123 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add wrappers around the p4d/pud/pmd/pte offset kernel functions which ensure that page-table pointers are in the specified decorated page-table. Signed-off-by: Alexandre Chartre --- arch/x86/mm/dpt.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/arch/x86/mm/dpt.c b/arch/x86/mm/dpt.c index 6df2d4fde8ec..44aad99bc3dc 100644 --- a/arch/x86/mm/dpt.c +++ b/arch/x86/mm/dpt.c @@ -82,6 +82,72 @@ static bool dpt_valid_offset(struct dpt *dpt, void *offset) return valid; } +/* + * dpt_pXX_offset() functions are equivalent to kernel pXX_offset() + * functions but, in addition, they ensure that page table pointers + * are in the specified decorated page table. Otherwise an error is + * returned. + */ + +static pte_t *dpt_pte_offset(struct dpt *dpt, + pmd_t *pmd, unsigned long addr) +{ + pte_t *pte; + + pte = pte_offset_map(pmd, addr); + if (!dpt_valid_offset(dpt, pte)) { + pr_err("DPT %p: PTE %px not found\n", dpt, pte); + return ERR_PTR(-EINVAL); + } + + return pte; +} + +static pmd_t *dpt_pmd_offset(struct dpt *dpt, + pud_t *pud, unsigned long addr) +{ + pmd_t *pmd; + + pmd = pmd_offset(pud, addr); + if (!dpt_valid_offset(dpt, pmd)) { + pr_err("DPT %p: PMD %px not found\n", dpt, pmd); + return ERR_PTR(-EINVAL); + } + + return pmd; +} + +static pud_t *dpt_pud_offset(struct dpt *dpt, + p4d_t *p4d, unsigned long addr) +{ + pud_t *pud; + + pud = pud_offset(p4d, addr); + if (!dpt_valid_offset(dpt, pud)) { + pr_err("DPT %p: PUD %px not found\n", dpt, pud); + return ERR_PTR(-EINVAL); + } + + return pud; +} + +static p4d_t *dpt_p4d_offset(struct dpt *dpt, + pgd_t *pgd, unsigned long addr) +{ + p4d_t *p4d; + + p4d = p4d_offset(pgd, addr); + /* + * p4d is the same has pgd if we don't have a 5-level page table. + */ + if ((p4d != (p4d_t *)pgd) && !dpt_valid_offset(dpt, p4d)) { + pr_err("DPT %p: P4D %px not found\n", dpt, p4d); + return ERR_PTR(-EINVAL); + } + + return p4d; +} + /* * dpt_create - allocate a page-table and create a corresponding * decorated page-table. The page-table is allocated and aligned