From patchwork Wed May 15 02:35: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: 10944191 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 593D692A for ; Wed, 15 May 2019 02:36:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AF372896F for ; Wed, 15 May 2019 02:36:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1517E28998; Wed, 15 May 2019 02:36:11 +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 E42222896F for ; Wed, 15 May 2019 02:36:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F6926B0005; Tue, 14 May 2019 22:36:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3A41E6B0006; Tue, 14 May 2019 22:36:08 -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 294396B0007; Tue, 14 May 2019 22:36:08 -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 CD3966B0005 for ; Tue, 14 May 2019 22:36:07 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id t58so1473274edb.22 for ; Tue, 14 May 2019 19:36:07 -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=k+4pG7s5PhgweA8Ds6zH7Qo1tN5HR4wog5SSw+qvavA=; b=MADDsGN1KrOIpOWcBgfkl50xpP9o6aX2yKf3Do3sSdXmuZV+vUL+Ur5QxMPeyyJbah RkRrgl0/8BhsdVpRCl//FxEAazstk3+7n1NOC1ypupuaXsZijNAqojTsJ8sOxMcHIl65 kDGxfyYi5onyot6qUosStKTUKlA14hNMmHW0VpUVquGhTO+T81FXR9xhDlCJJ8ZNBSAX cCm2Ya82T/VUgrL1nNmjNxbwq0oWi+qWHgNrOZHhzrxe37OF/jgkYjpxotf9BY7jCPJy 2x2FGgDOan+0YAxhZs/ja04PwkEQg03qGzpPHUijeKJWzCQhnFlbYvsBPV2BHkfOI3vC JadQ== 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: APjAAAV67nXpk1qFws/TBYNnEX640YzJ8FpjxtTmNLtHVgQZdo+A9nmw 1OfdUUhE1hZyb5ipR2gwFjdqZWJutCcrgihg9qhRer2nWtCubfXDelNI04La9J9YZkkz5lbKStN 3jRzm53FBpAj0kq+gRFurv3P3/p1KRDT5LDaxJtO4dVeuRQVrjWw0Eqdd6LruVnetBg== X-Received: by 2002:aa7:c919:: with SMTP id b25mr40249214edt.274.1557887767360; Tue, 14 May 2019 19:36:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvyfnq35P1mgO+favCa+VZx8jwcFUP2VM7SqHDS4iIJ7Rd4H7iBKmjzDxgo1dxHIUpNT9n X-Received: by 2002:aa7:c919:: with SMTP id b25mr40249133edt.274.1557887766346; Tue, 14 May 2019 19:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557887766; cv=none; d=google.com; s=arc-20160816; b=gezeJN5s/g6JY2aNgbsA2Y4JO9SDpA0FgvB6f3w2SdR5YVKt7vc8rGR3E9rrK/eYCp naWW+1y44sTt7zvq6E+dyx2C6/WeVez6t4KRKxHkChcS7DWUOIdsTOMBFg+Av+EXwMjW c8RnQ4qNhmFZTaIWKhgd8rzD5ETA/l3Ed5tTuLcLEc0PraxWYbWQrUtlLWC4/YglpWLB 16Djm7d0GXC0GaC4vX+E4CZee900e5HNR6thp5w2dnUOjoaF/MdG4+eC1HmNoif4dE5y 5HIRldfG9nmFYBKXkA8C6S1uYeYfj68MVv2K8T9e3AEfDpYn0uHC2PNrwe7h3lCgRsnQ 4snA== 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=k+4pG7s5PhgweA8Ds6zH7Qo1tN5HR4wog5SSw+qvavA=; b=y87lmI9GUocpMUnNFMsXJuU8HyqcuQR3FvEs5iWcNIn/k4Vm2LjqWqcAa9COqWv2UL NC0F0l6ZT0Wv8gTjAWKUzi2z8JmOVr/ubUEOncjBAz6ztQoSvgsNpGSt8vbS/aYJxQBE KH5CCAK57M4Xe9soY1B1Wt5n0YXfMiPslzuCjxKdppS21IvJ0O1xauj0TNVLTIGQh9ka iA/KB/DqEnLVKLbKh1LqddZFP/zXZMOYQHxfW+nAtL+FWy2T+f9QO3Up4eq6whInU8hc 7D/jhMnHIhh0wGzTuKDB8rKsnj0i8eYLPVXjTs59CVtDfGjCBcCNqHxHdqdJ4ty1SYcV eOxQ== 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 p18si421306ejq.220.2019.05.14.19.36.06 for ; Tue, 14 May 2019 19:36:06 -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 4A0CF341; Tue, 14 May 2019 19:36:05 -0700 (PDT) Received: from p8cg001049571a15.arm.com (unknown [10.163.1.137]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7A45C3F703; Tue, 14 May 2019 19:35:58 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Cc: Anshuman Khandual , Toshi Kani , Andrew Morton , Will Deacon , Chintan Pandya , Thomas Gleixner , Catalin Marinas Subject: [PATCH V4] mm/ioremap: Check virtual address alignment while creating huge mappings Date: Wed, 15 May 2019 08:05:16 +0530 Message-Id: <1557887716-17918-1-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: 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 Reviewed-by: Toshi Kani Reviewed-by: Catalin Marinas --- Changes in V4: - Added similar check for ioremap_try_huge_p4d() as per Toshi Kani lib/ioremap.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/ioremap.c b/lib/ioremap.c index 063213685563..a95161d9c883 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; @@ -166,6 +172,9 @@ static int ioremap_try_huge_p4d(p4d_t *p4d, unsigned long addr, if ((end - addr) != P4D_SIZE) return 0; + if (!IS_ALIGNED(addr, P4D_SIZE)) + return 0; + if (!IS_ALIGNED(phys_addr, P4D_SIZE)) return 0;