From patchwork Thu May 9 04:46:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 10936623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1CB0292A for ; Thu, 9 May 2019 04:47:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C23A288FA for ; Thu, 9 May 2019 04:47:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00D6728A12; Thu, 9 May 2019 04:47:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D35C9288FA for ; Thu, 9 May 2019 04:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=mfpkRrcq0VANAnN0yzQde3wvBTIzw1CH5kaKepiuGf4=; b=oepzxbMS/pXeuPzoZmViBd0/hS qMGZLNBNSb2Hgf0xS677A8m5XZnLujouRpkFJVcvDskGpXR9IhRdDYTl4zb36FJen9umlay5R27FU T3pYLo+7nJYQwcOsG7r6Ffn2ncN53wfY79A3WoaMfmwG16ArD0AiNGsj/tFuZ4H02/7fdxIOxA4f2 3B+mLwfFq4z8vcpc+jBX4A3ZOziklNhpidUWBDJPQUruF0z0VZolg/ucMoYePCySuGyTaJXcfEhLl XJFgFn52G8HuwAjRoy7l0Jpuq06OnHnT9Fc4+aj9WYTJJF4IyCwl4NzQtVI9wpGTMwzaoY7RFzHjM 5oUItoIw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hOaxe-000550-KT; Thu, 09 May 2019 04:47:14 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hOaxZ-00051N-MX for linux-arm-kernel@lists.infradead.org; Thu, 09 May 2019 04:47:11 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7F7BE374; Wed, 8 May 2019 21:47:09 -0700 (PDT) Received: from p8cg001049571a15.arm.com (unknown [10.163.1.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3F0C93F575; Wed, 8 May 2019 21:47:03 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V3 1/2] mm/ioremap: Check virtual address alignment while creating huge mappings Date: Thu, 9 May 2019 10:16:16 +0530 Message-Id: <1557377177-20695-2-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557377177-20695-1-git-send-email-anshuman.khandual@arm.com> References: <1557377177-20695-1-git-send-email-anshuman.khandual@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190508_214709_854533_3848BC1D X-CRM114-Status: GOOD ( 11.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Toshi Kani , Anshuman Khandual , Catalin Marinas , Will Deacon , Chintan Pandya , Andrew Morton , Thomas Gleixner MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Virtual address alignment is essential in ensuring correct clearing for all intermediate level pgtable entries and freeing associated pgtable pages. An unaligned address can end up randomly freeing pgtable page that potentially still contains valid mappings. Hence also check it's alignment along with existing phys_addr check. Signed-off-by: Anshuman Khandual Cc: Toshi Kani Cc: Andrew Morton Cc: Will Deacon Cc: Chintan Pandya Cc: Thomas Gleixner Cc: Catalin Marinas --- lib/ioremap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ioremap.c b/lib/ioremap.c index 063213685563..8b5c8dda857d 100644 --- a/lib/ioremap.c +++ b/lib/ioremap.c @@ -86,6 +86,9 @@ static int ioremap_try_huge_pmd(pmd_t *pmd, unsigned long addr, if ((end - addr) != PMD_SIZE) return 0; + if (!IS_ALIGNED(addr, PMD_SIZE)) + return 0; + if (!IS_ALIGNED(phys_addr, PMD_SIZE)) return 0; @@ -126,6 +129,9 @@ static int ioremap_try_huge_pud(pud_t *pud, unsigned long addr, if ((end - addr) != PUD_SIZE) return 0; + if (!IS_ALIGNED(addr, PUD_SIZE)) + return 0; + if (!IS_ALIGNED(phys_addr, PUD_SIZE)) return 0; From patchwork Thu May 9 04:46:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 10936627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6865776 for ; Thu, 9 May 2019 04:47:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56AA4288FA for ; Thu, 9 May 2019 04:47:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4ABE828908; Thu, 9 May 2019 04:47:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ED47C288FA for ; Thu, 9 May 2019 04:47:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=NIIOXE3cS8DHmNFTePywEIWPfMD6IWjA6sdzzw0UDow=; b=eymF1WhJ0yr+wU4WtbT1JKC2KK yXYcod9HRc6KYiQl8rIlMbb6xb+nRS+Y6AoPBHxtBCOnmS+lJ24+GCrWN7fUgZiOTRdKBswv9GfUn VZKkj0xz2x67B+wzYHwGml8zoCnr55jxBBwiPzN95dwAT9gC22fbue44VSpIfCU43VJhP1XRHd6mY paqPLKWe9/6tDV4iTTOs8vb5npsRuqJAxErc3mmzjmAoqbwwVMWPcbXgZrOgCeOD0YkBqDjVCviRT zd/wIjOSqvOqFFtHmwgiOjet8O/yVuXnRZIXzYLLS/iTo3TUjCwEub75q9sqAJBV8fM6EJ832rxwN wSvfFTuQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hOaxs-0005M4-Jf; Thu, 09 May 2019 04:47:28 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hOaxl-0005DS-1M for linux-arm-kernel@lists.infradead.org; Thu, 09 May 2019 04:47:24 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C10A9374; Wed, 8 May 2019 21:47:19 -0700 (PDT) Received: from p8cg001049571a15.arm.com (unknown [10.163.1.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 07BC43F575; Wed, 8 May 2019 21:47:14 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V3 2/2] arm64/mm: Change offset base address in [pud|pmd]_free_[pmd|pte]_page() Date: Thu, 9 May 2019 10:16:17 +0530 Message-Id: <1557377177-20695-3-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557377177-20695-1-git-send-email-anshuman.khandual@arm.com> References: <1557377177-20695-1-git-send-email-anshuman.khandual@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190508_214721_416333_C835EC77 X-CRM114-Status: GOOD ( 12.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Anshuman Khandual , Catalin Marinas , Will Deacon , James Morse , Robin Murphy MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Pgtable page address can be fetched with [pmd|pte]_offset_[kernel] if input address is PMD_SIZE or PTE_SIZE aligned. Input address is now guaranteed to be aligned, hence fetched pgtable page address is always correct. But using 0UL as offset base address has been a standard practice across platforms. It also makes more sense as it isolates pgtable page address computation from input virtual address alignment. This does not change functionality. Signed-off-by: Anshuman Khandual Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: James Morse Cc: Robin Murphy --- arch/arm64/mm/mmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index e97f018ff740..71bcb783aace 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1005,7 +1005,7 @@ int pmd_free_pte_page(pmd_t *pmdp, unsigned long addr) return 1; } - table = pte_offset_kernel(pmdp, addr); + table = pte_offset_kernel(pmdp, 0UL); pmd_clear(pmdp); __flush_tlb_kernel_pgtable(addr); pte_free_kernel(NULL, table); @@ -1026,8 +1026,8 @@ int pud_free_pmd_page(pud_t *pudp, unsigned long addr) return 1; } - table = pmd_offset(pudp, addr); - pmdp = table; + table = pmd_offset(pudp, 0UL); + pmdp = pmd_offset(pudp, addr); next = addr; end = addr + PUD_SIZE; do {