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: 10936621 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 CBAFC92A for ; Thu, 9 May 2019 04:47:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA0C2288FA for ; Thu, 9 May 2019 04:47:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE66B28908; Thu, 9 May 2019 04:47:13 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E8B8288FA for ; Thu, 9 May 2019 04:47:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7386E6B0008; Thu, 9 May 2019 00:47:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6E7AD6B000A; Thu, 9 May 2019 00:47:12 -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 5B1146B000C; Thu, 9 May 2019 00:47:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 0E15D6B0008 for ; Thu, 9 May 2019 00:47:12 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id n23so565612edv.9 for ; Wed, 08 May 2019 21:47:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=smRSWtMfbzqp9e26+Uu8/I42k9wBiKKP23FnAZWrewY=; b=M9fm1amS8//SacWYsdoCM76ACwSYp/ce3IF9gUv0ynHx3RhVdZxgsbjDujVhDUiSye 0nCMcg1ycMdTDkhl2wuoJLNO0Am+30ijc6laOPLCh9PkvRQoXeWnC9FGNuHbnU90lQmQ nLu+BIT7MRoIHSJHX/bpvcksyMZ4VbBZ2w5WSjSZnmpMIbECD5QIDUGbmqfAR/QHNex/ lcaBZSZRdWOupFHkz4o05tunXJlHzJJ9NAlEtAdYxIykbOZgkntfw8hQxTNXnqk0TEpU /hDtHHrX8P+168l73ev862G+fec4/eQM79DKpXP83XMs2RLqzdBZzHSUKioYHu9qRCTq FqrA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of anshuman.khandual@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com X-Gm-Message-State: APjAAAVJV+nRwePRBDV/m4ApnFQbxtKx6RThmMxfPTPMVpVkOL4BgjHg 2U5qrCCqTiufRtGk5X3DMGgNjSHwwWNHh1FLY5k8D6/BpoEOoVbb82gkMn2NCT8jibvb9JD4ntD mfKMbiWTjdhJFG0oPL2njGeforvN2JSeZ9psDWOqKj+irQk8Jv2nnjPZ2WroUqIkZDQ== X-Received: by 2002:a17:907:104e:: with SMTP id oy14mr1434244ejb.253.1557377231572; Wed, 08 May 2019 21:47:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqx71cNrWAtbOne2mZzz1Q21Z8MTjS7xAY4H3zjoRj21wYU0OlQYigqTEuA23Q5kNYVEjxKu X-Received: by 2002:a17:907:104e:: with SMTP id oy14mr1434201ejb.253.1557377230486; Wed, 08 May 2019 21:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557377230; cv=none; d=google.com; s=arc-20160816; b=c1fQfeqaSKDRTaGZhEVxgRXKxwocQD4MEEoPbbfeyGQ5lSbag/GdHUXfM7lgWZCH9N PBSJItkxZd77ZcvbI82wSv1ZmybwCceyEERoCQa5VNo1L+icJG58z01CMHyQR3QWFHLj obqRkbCoAHoliqRH2nPFtmd1Xeda/Zy3tTrojpz5GzKE45r8p64LLDvP1v20kQeM+npL RUpPEokyuKylcpDiPUWj3qBd9Lh4zTNXWLr0HHEyYIo+yPc144ES/LatvHbCDEOOdXVW j0i6UItaKqAAuw1j/ZyJN0BwmKykBopNhoocTnGE4DmXYR02OpKLAFH8pRosqy0WbiQX pDRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=smRSWtMfbzqp9e26+Uu8/I42k9wBiKKP23FnAZWrewY=; b=Kz+y4bRroN048uUep/5r8BCS0OneHGWwDTJFYYPy243moL4+kRY8SOjUTsud2NOXI0 C7dH4/unMctisItaKXpBAfX5twehn5mIdTvi3TrSWyQ+mbvUIyi1Zm3c1NOKafa45O5F i6mP1ZWcRFwIduaAg+gY7o6NBchowHd1QsNqfOZoDdLKiM9whUNxXumw/ZYS4Txpig1m KdPOAcRl1YdO8L1Y7dXrnENMMkC7n0zKalfEGNvMgwGvTo+NITJ8b/nS+eeGtlqgdg+Z PaN1Mx0pVUhTL3iysff36I0wZfeMd0ZX31Zn59c+RZlkb743vWbRNiOvWxFY4oVxsc8A gQSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of anshuman.khandual@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id k57si690192edb.36.2019.05.08.21.47.10 for ; Wed, 08 May 2019 21:47:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of anshuman.khandual@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of anshuman.khandual@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com 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 Cc: Anshuman Khandual , Toshi Kani , Andrew Morton , Will Deacon , Chintan Pandya , Thomas Gleixner , Catalin Marinas 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-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: 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: 10936625 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 9827E76 for ; Thu, 9 May 2019 04:47:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 887A8288FA for ; Thu, 9 May 2019 04:47:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79C8828908; Thu, 9 May 2019 04:47:24 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F0C3288FA for ; Thu, 9 May 2019 04:47:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7ACF16B000A; Thu, 9 May 2019 00:47:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 75C536B000C; Thu, 9 May 2019 00:47:22 -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 64CDA6B000D; Thu, 9 May 2019 00:47:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 1813B6B000A for ; Thu, 9 May 2019 00:47:22 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id x16so553896edm.16 for ; Wed, 08 May 2019 21:47:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=DYixvt1jDbt1vu6MAn5rwFWxpCwVL0maYvtuuMFfkM4=; b=MEnUF+hLD6khBcNXJAHwx6vC1A/iKvuI0Pp/JqW7QwPAm3RUS4F8F3pH5EbbAs+MAb 8LjgXHeyc1FoDOFmWmVysN5UeWufQk01ZXqeTEZMZSC646DZf869lVEStgvIV5NOdBjw wbJ/+J3JSeReSWmozAMh80P2OMEC59FYyZ2b9HkqU7RtlipTJk5Wf0FRvELaURPQq9oT 4DvIFaspuyHof8tEZRZiDZzWXSOcL8SA1GYKSDk0rVQvBmzM0cpNG3oAdmM7LxAj3LUx my6eVGDI/h0c72+CN1dKWrUTY1cUeE/amfX6HjpyyC8J7kH/Nxz599RHCqkT14wDiVHk FGdA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of anshuman.khandual@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com X-Gm-Message-State: APjAAAUm8zOxgkElpzPrPn8Hzfamo+JXs2Lbuiz8Y/Xq94gO2o+0+P9O /S8EHC9Azy4ypc2oWPUOKnurFiqAfl9IISM4DC89+Pf+uh8uhrTzLOa8eT1olbAtgEdL7a2Kik0 1aojykY2JO/QuwXsNmMpMU/r7lNIIxXPaf9R5NhF2Z4UDaaHyyccA/OtoHhnGrss31g== X-Received: by 2002:a17:906:6aca:: with SMTP id q10mr1486124ejs.54.1557377241581; Wed, 08 May 2019 21:47:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxn5HdeFruxHtfU+wQPzWdX07jEz6taIAigHjEXy0OUD9R97YWBwwNvAeIvzCQLHElcgH3p X-Received: by 2002:a17:906:6aca:: with SMTP id q10mr1486081ejs.54.1557377240743; Wed, 08 May 2019 21:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557377240; cv=none; d=google.com; s=arc-20160816; b=PGfmJkUEOBhqZDkXzq6SlJGn2BsISB/dEDPElp6NftCQcMlBoSV5wzmxJRGVxqD4Y9 k0MF1WQcuHpaYR3NKx1PyJy57usaMqNx6xSu57YuJS9UIfJrsBNSTveIt6fGQusD+y2Y 1P5yLtLcHxoPpzNcawfozMXZGaORZJt2bpAXB/C8DX1LHJ7BCYxeWosXdAX/Yiul3CAy YoL0k6RBAT28b2q1KypdFuzhmbxzeLrD6n7QxLJP/w/lNDm8sRL8Nyl/7SIvN8kSd7i6 aereLV2iDshRNresxxJPDjZh/pC20iX38KS3uCrEShEuG1E0FE+BKS2GlpsazA5JcXDJ wypQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=DYixvt1jDbt1vu6MAn5rwFWxpCwVL0maYvtuuMFfkM4=; b=PPLStWfLhB8Tgm/eTkyIMUwCRUPkVRfe5pzjhsChjWMtpGxQAH6TZBZji87xgMhiFD 7Opn1nt1wOSOPz8C205Kro/NZla18tplOCCobIKiLk/+JqEZM5L5hubuCVoHfvU+oqFx p1h8GhAFxQgPsDEX7E7ESc/0GU6/8DsgcBdt2QsBS2qNvqnY5bsk09HQjB/B5sKRjldg QYoQT7I6Hu9qZ8tBg6oLRa8eTjqWWMibiKL85638blzQg4+rXTxcJWdGp04LRPrUn8Vy N0nx57XLUO5tDxETrZ3eQfKvVcgercCmg5G6LlMbRySuC2hgukTHe24kPXapPUem2oq8 hx3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of anshuman.khandual@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id g1si469352ejc.373.2019.05.08.21.47.20 for ; Wed, 08 May 2019 21:47:20 -0700 (PDT) Received-SPF: pass (google.com: domain of anshuman.khandual@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of anshuman.khandual@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com 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 Cc: Anshuman Khandual , Catalin Marinas , Will Deacon , Mark Rutland , James Morse , Robin Murphy 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-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: 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 {