From patchwork Mon Jul 1 06:40:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11025101 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 66D84138B for ; Mon, 1 Jul 2019 06:40:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68BF427F92 for ; Mon, 1 Jul 2019 06:40:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BA032832D; Mon, 1 Jul 2019 06:40:57 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 DF3E127F92 for ; Mon, 1 Jul 2019 06:40:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA4CF8E000E; Mon, 1 Jul 2019 02:40:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A55FF8E0002; Mon, 1 Jul 2019 02:40:55 -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 9446C8E000E; Mon, 1 Jul 2019 02:40:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f206.google.com (mail-pg1-f206.google.com [209.85.215.206]) by kanga.kvack.org (Postfix) with ESMTP id 5E6598E0002 for ; Mon, 1 Jul 2019 02:40:55 -0400 (EDT) Received: by mail-pg1-f206.google.com with SMTP id f18so478080pgb.10 for ; Sun, 30 Jun 2019 23:40:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=pKOh82x9P2FXMy8MB5i8VNrUUku24zVBdhYruM45v1s=; b=M2Nm7sMpSedNWAiuuUql2OU/WPdnb9r6FFkuEN3i8bQ8LFmvp1WnpqvW+mUihORxjc LdcCuNFpY5t2atOcrgcwZaHRKMxYQJuQX7n6415Hs5MsoL7lliwgWikLQ6SZtqsLOg3W RmRuQOeLMHAZbDAMmgp3EyqGm7Zpez6lK49yls/fxQL5bzXiI0kpvCg/zGnnllVy3Z/w 9Vw1YhrmuAimcl8UeGYmp29Z6mqjBaS24Wo5XcAsrg14MdbF6mOpFpLCoA8Drr5rIGJE WXxrIx3A2eFwYjtXGfoFY/8FAR/UFqbqGVTzG41/YU52AoazEX0nnRlCGr80BaU5kqeY rLcw== X-Gm-Message-State: APjAAAVEzGilXeVLhaPc1MNzyr50TtZKm4TgXAI62yLGCeVEz3QqhawN ZYh49GelaZkR9XbrZlvApfQsWfeG/YgPI7rp7B9lL2GJY4Cg0s8HrnmbvJo3Q74Gmu6pkWqY57e m/jbk3oFBVXf9brgYu3PF/6a9r0qvIBrfD9kFvxOv53N/tKzEaGh6diDgjgp0ST/LaQ== X-Received: by 2002:a17:90a:214e:: with SMTP id a72mr30072358pje.0.1561963255082; Sun, 30 Jun 2019 23:40:55 -0700 (PDT) X-Received: by 2002:a17:90a:214e:: with SMTP id a72mr30072299pje.0.1561963254335; Sun, 30 Jun 2019 23:40:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561963254; cv=none; d=google.com; s=arc-20160816; b=x30ACrXpJSQchLfL1nUB4g8P0mf4psOSqoCzcw1PRpxFNLyXGw31B1BxjRR3HXIk3k HO7g58ob7UFqsmZP25hp+l6Inn056kEZcqnXg2zP/ca1RY1TTunVKDZe5LtwTIJ7d9Y7 4lETCrsPH6/6DJ77t4UkNNbeAjWbY64UbypYWQ1hKdgjsROvrgLWakJESW5rZ2u64bXi wLfXlgKz3dsHB6mBV6IDV+xpP985Q5EiAf0RfWtzjUTUd5qgKADBS7cKyT7HS4sLsrP3 pjALwWEgnf5kIDiTdC/xlz1HNnVgyxyyaMmPYlkZM3rykhXcTwbo2JMiDITdCUSqczLs nJ6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=pKOh82x9P2FXMy8MB5i8VNrUUku24zVBdhYruM45v1s=; b=DXyRhMhOP1b4EtP1ALWOMzelkL1E/U6xuIcDD4KuWM2xlpQdLibISCZErxjopBpyNx mTvKxtb/Wx23W5tbHq8qqQ5wFM3BdzH2pZSy8Zjau7QgBFt1FqprlkbNScrXN7xRjLA4 xfSBwMJD69BJ9dMtJn/Xkqk62Gpby0dRlLay1qRvySH+pmOIhdwXYK4857tqoFQ5BO8o bo94miFFPQREl99wvcxNYl31But7/hk12o1tW7cnfwUnTetXKe8VlNGUygVVNs7jZYSR lAlP5BLJH4ihGSn9aYaU4JE9b+w0o0X2PKM5duzJaABsPFWa/fuBDXWvyMze5cUmjeQz st9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Yv7ONmA4; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d2sor11558924pju.0.2019.06.30.23.40.54 for (Google Transport Security); Sun, 30 Jun 2019 23:40:54 -0700 (PDT) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Yv7ONmA4; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pKOh82x9P2FXMy8MB5i8VNrUUku24zVBdhYruM45v1s=; b=Yv7ONmA4HXrBg5Z7fqXzGOQbgQwuhlK4G2llLAPL9hd//uUhAJCdLP1gC4MiqhQmS1 PV4CZ1/6GPjUs6tQxXSl9GVwIuOpYlj0kPjLUd5KNaZDhIEToxG1Sa+JbI0gqbWYCnK1 nlIT45EuZA6x+yj65DFrpUmE+ukUb3brmWRiJ0sEST0egchnVhKD3wf61QoTZodMZhmy k4LLY0TR+zKUetQRGdhUpKeJcCk0KpXMV/eM/4aPeAhRmDX3A00d0snpwA3wONNLJH4u fRpP7dt48AfYD+D5tlNpsUuYik0uEhm3cuSW3WNaRLnnooak0yNkr7b21OrBtbTM1gge bOuA== X-Google-Smtp-Source: APXvYqyuG0y2ZSl0o0Y8HuBhNNVpR47p1znHr/GTjxdAJLwOfhhJ0EB9nOQKOhPc/GH1Qv7SUWLDfA== X-Received: by 2002:a17:90a:eb08:: with SMTP id j8mr14461754pjz.72.1561963253877; Sun, 30 Jun 2019 23:40:53 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id x128sm24238285pfd.17.2019.06.30.23.40.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 30 Jun 2019 23:40:53 -0700 (PDT) From: Nicholas Piggin To: "linux-mm @ kvack . org" Cc: Nicholas Piggin , "linux-arm-kernel @ lists . infradead . org" , "linuxppc-dev @ lists . ozlabs . org" , Andrew Morton , Anshuman Khandual , Christophe Leroy , Ard Biesheuvel , Mark Rutland , Catalin Marinas , Will Deacon , Steven Price Subject: [PATCH v2 1/3] arm64: mm: Add p?d_large() definitions Date: Mon, 1 Jul 2019 16:40:24 +1000 Message-Id: <20190701064026.970-2-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190701064026.970-1-npiggin@gmail.com> References: <20190701064026.970-1-npiggin@gmail.com> MIME-Version: 1.0 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 walk_page_range() is going to be allowed to walk page tables other than those of user space. For this it needs to know when it has reached a 'leaf' entry in the page tables. This information will be provided by the p?d_large() functions/macros. For arm64, we already have p?d_sect() macros which we can reuse for p?d_large(). pud_sect() is defined as a dummy function when CONFIG_PGTABLE_LEVELS < 3 or CONFIG_ARM64_64K_PAGES is defined. However when the kernel is configured this way then architecturally it isn't allowed to have a large page that this level, and any code using these page walking macros is implicitly relying on the page size/number of levels being the same as the kernel. So it is safe to reuse this for p?d_large() as it is an architectural restriction. Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Steven Price Acked-by: Catalin Marinas --- arch/arm64/include/asm/pgtable.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index fca26759081a..0e973201bc16 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -417,6 +417,7 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, PMD_TYPE_TABLE) #define pmd_sect(pmd) ((pmd_val(pmd) & PMD_TYPE_MASK) == \ PMD_TYPE_SECT) +#define pmd_large(pmd) pmd_sect(pmd) #if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3 #define pud_sect(pud) (0) @@ -499,6 +500,7 @@ static inline void pte_unmap(pte_t *pte) { } #define pud_none(pud) (!pud_val(pud)) #define pud_bad(pud) (!(pud_val(pud) & PUD_TABLE_BIT)) #define pud_present(pud) pte_present(pud_pte(pud)) +#define pud_large(pud) pud_sect(pud) #define pud_valid(pud) pte_valid(pud_pte(pud)) static inline void set_pud(pud_t *pudp, pud_t pud) From patchwork Mon Jul 1 06:40:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11025103 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 AB544746 for ; Mon, 1 Jul 2019 06:41:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF974284DA for ; Mon, 1 Jul 2019 06:41:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EDA4284B3; Mon, 1 Jul 2019 06:41:01 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 23A1B284B3 for ; Mon, 1 Jul 2019 06:41:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C79CF8E000F; Mon, 1 Jul 2019 02:40:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C29678E0002; Mon, 1 Jul 2019 02:40:59 -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 B190A8E000F; Mon, 1 Jul 2019 02:40:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f207.google.com (mail-pl1-f207.google.com [209.85.214.207]) by kanga.kvack.org (Postfix) with ESMTP id 7F7B48E0002 for ; Mon, 1 Jul 2019 02:40:59 -0400 (EDT) Received: by mail-pl1-f207.google.com with SMTP id n1so6774766plk.11 for ; Sun, 30 Jun 2019 23:40:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=6Zlw/hCGICkGVg8omOyX/d2u3HngLNHtlfTr8g+whbg=; b=OA8pueYhxVi9BPeoJlt/kPWW/XZoYn0FdcPyuUhIp0hcpbQFKgcmFvuh8IHRdRhXaM a0gO/FtoSMWRuYMmCmLfwVZ9pxgvi1uTi6a0W/84K9YuvyYztXVDHmO+DKgC56NW7rBm pHvyxufxFO1fsclyyAXw8qVuJ9/xGzMh+9rJDqtNSWIpvEOJC6WDRdECu5pguNFeipTf FKFdfzuOUIs7aYcUlTgGX34byRGa/ExQYDj5v72H8CxeqVB4SNdMmDrp57uCGLwUraB2 H/gyRf008SuHfXa9KASOR0M/1h9v6YsGnWoISTn8jkgKgTtBwXFz0hNA93mCHrXk8Lk1 O2Jg== X-Gm-Message-State: APjAAAUjkHOFBFFszurXeEKk640L6MIF20dBJP4DoUbsLPAGHxbX7aiX SlQL44s8Mcac17KLM76jvgpsKb41QGS97r5/0fw/TEDSUKXLMZxjygYZt6wyQEpuhcXfl+ucuzg 4dMMkvhEnIYMS5d4xf/DqQ4reY9CLKJazbfZHpwqfsnT9pbNYz7zI9w4FUaSGvL09mg== X-Received: by 2002:a63:24c1:: with SMTP id k184mr23641527pgk.120.1561963259121; Sun, 30 Jun 2019 23:40:59 -0700 (PDT) X-Received: by 2002:a63:24c1:: with SMTP id k184mr23641456pgk.120.1561963257966; Sun, 30 Jun 2019 23:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561963257; cv=none; d=google.com; s=arc-20160816; b=PNlWD0rZ3UHzJKsq6Yvha1ZaC6wQq9YymGPRl3sQKOQxUUR+Nxb8lxSb76HmW4yqai f9ZgjFWIb+ir8XCkeNUP5SZhvORGjCJWJeejrBN7Z43H7xtW+xSw7jGpCmPTcsUfeqEN UqGkt/iRevyQBUR5yYeaRjAgztKzQ3Aaho/6oy2n7Td1znlIgqejbLZF0KCjWom/wc6N /2zQ3fg7NcgFJ3XJpNVfKrQErGTQpCiqe87/9NYymULa89+KTbJ23qVZ22pf5o2bvQoG 0O0iklrz1GqUZip9FemTaEjwMCi5jE0Z1oAUz4JhFICKxfL/SQ6y9qIC+Pm90tRe2XcE f83Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=6Zlw/hCGICkGVg8omOyX/d2u3HngLNHtlfTr8g+whbg=; b=0HGKgxbpum37fer0g0+7nvA6xzTlsAkljWb4ApLcFv3FPB6nQwK3fHECkLjLF7H0wr 5ZJbWk59B+AjNozZ/1rayhzkrwSc7gAfK4Um4Fl5PEsNQWn7QxVtDshbGuPJSaL0QXyV 5gKp+Z151LIKWdHNIR80hijLcINMFsHryM2aD4KsPPoHVNHNTV/0yrDIEpemLEpzOkoX 0jWC51FhdvRm/u/jmlbpOeJqNO3oZECd3QaKhV94EsffU51nHhrSxLESONoInI1m8+kT 74nnvFo8v7uY2BlOIn0nn2Qv+4t2WN5aXy2utVZrtBAUUEIPlEKRzKCDTsgKWAMLz7fj Slcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ouq5FzdI; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i96sor11376065pje.17.2019.06.30.23.40.57 for (Google Transport Security); Sun, 30 Jun 2019 23:40:57 -0700 (PDT) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ouq5FzdI; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Zlw/hCGICkGVg8omOyX/d2u3HngLNHtlfTr8g+whbg=; b=ouq5FzdIf9rNySj7b3zWVPcAwWspCJDbKnSjFCLmfjwBeC3LJPB34aIN0+a7wQ8McC p1Txuhs4kMtY+16Cqhhps3AA30X2hrE5mj6QueTPMfgLdP9ZAL77JuJMAafKBj8Wct8b QjxaYZ1kTJ5UE+4AUmDCQjs7UUTxxBoXRQu5Wj84zOrGTJ8ez4CMlZFv3/c0+r5SCFqa UrMNuge9PYhXovbwW/X9u2mXxujZnpVUsInRSBgusFGBG9eoHqQ+JcLGdPYGoL91mbVG Yu1phLwtKP+clAkHJhLFNUWD84oz9qvm0JbedtUx+FFMqCYLfFmH0zttRDXk8AY+NjND E4nA== X-Google-Smtp-Source: APXvYqx98EZ/1NGwoXYug6FXGMmAdVT2/AyL1LfX+2sBRIhK5AVZczoBxviaDZiO/22AP1OmmeXKEg== X-Received: by 2002:a17:90a:ac11:: with SMTP id o17mr29589490pjq.134.1561963257515; Sun, 30 Jun 2019 23:40:57 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id x128sm24238285pfd.17.2019.06.30.23.40.54 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 30 Jun 2019 23:40:57 -0700 (PDT) From: Nicholas Piggin To: "linux-mm @ kvack . org" Cc: Nicholas Piggin , "linux-arm-kernel @ lists . infradead . org" , "linuxppc-dev @ lists . ozlabs . org" , Andrew Morton , Anshuman Khandual , Christophe Leroy , Ard Biesheuvel , Mark Rutland Subject: [PATCH v2 2/3] powerpc/64s: Add p?d_large definitions Date: Mon, 1 Jul 2019 16:40:25 +1000 Message-Id: <20190701064026.970-3-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190701064026.970-1-npiggin@gmail.com> References: <20190701064026.970-1-npiggin@gmail.com> MIME-Version: 1.0 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 The subsequent patch to fix vmalloc_to_page with huge vmap requires HUGE_VMAP archs to provide p?d_large definitions for the non-pgd page table levels they support. Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Nicholas Piggin --- arch/powerpc/include/asm/book3s/64/pgtable.h | 24 ++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index ccf00a8b98c6..c19c8396a1bd 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -915,6 +915,11 @@ static inline int pud_present(pud_t pud) return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PRESENT)); } +static inline int pud_large(pud_t pud) +{ + return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE)); +} + extern struct page *pud_page(pud_t pud); extern struct page *pmd_page(pmd_t pmd); static inline pte_t pud_pte(pud_t pud) @@ -958,6 +963,11 @@ static inline int pgd_present(pgd_t pgd) return !!(pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT)); } +static inline int pgd_large(pgd_t pgd) +{ + return !!(pgd_raw(pgd) & cpu_to_be64(_PAGE_PTE)); +} + static inline pte_t pgd_pte(pgd_t pgd) { return __pte_raw(pgd_raw(pgd)); @@ -1083,6 +1093,11 @@ static inline pte_t *pmdp_ptep(pmd_t *pmd) #define pmd_mk_savedwrite(pmd) pte_pmd(pte_mk_savedwrite(pmd_pte(pmd))) #define pmd_clear_savedwrite(pmd) pte_pmd(pte_clear_savedwrite(pmd_pte(pmd))) +static inline int pmd_large(pmd_t pmd) +{ + return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)); +} + #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY #define pmd_soft_dirty(pmd) pte_soft_dirty(pmd_pte(pmd)) #define pmd_mksoft_dirty(pmd) pte_pmd(pte_mksoft_dirty(pmd_pte(pmd))) @@ -1151,15 +1166,6 @@ pmd_hugepage_update(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, return hash__pmd_hugepage_update(mm, addr, pmdp, clr, set); } -/* - * returns true for pmd migration entries, THP, devmap, hugetlb - * But compile time dependent on THP config - */ -static inline int pmd_large(pmd_t pmd) -{ - return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE)); -} - static inline pmd_t pmd_mknotpresent(pmd_t pmd) { return __pmd(pmd_val(pmd) & ~_PAGE_PRESENT); From patchwork Mon Jul 1 06:40:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11025107 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 2711C1580 for ; Mon, 1 Jul 2019 06:41:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B798284B3 for ; Mon, 1 Jul 2019 06:41:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F96E284E9; Mon, 1 Jul 2019 06:41:05 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 7D0CA284B3 for ; Mon, 1 Jul 2019 06:41:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9C608E0010; Mon, 1 Jul 2019 02:41:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E4EE98E0002; Mon, 1 Jul 2019 02:41:02 -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 D153D8E0010; Mon, 1 Jul 2019 02:41:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f206.google.com (mail-pg1-f206.google.com [209.85.215.206]) by kanga.kvack.org (Postfix) with ESMTP id 8F6FB8E0002 for ; Mon, 1 Jul 2019 02:41:02 -0400 (EDT) Received: by mail-pg1-f206.google.com with SMTP id x19so7070303pgx.1 for ; Sun, 30 Jun 2019 23:41:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=smDmHv6fTQfEC2Xw13QJ3CuxW2VIYrqrjOiGuS7E8nY=; b=I6WZLtY862c4oGqrxBqts+uR1BwtB/z77T09FRrHJ5c75657zV5h56dcTQZi6udOUU wl7sQAOt0bvd6qvdZTEewDn1YS7b/UAu7Mpy9tLdkiGPwy7eB3SOzV6alnzL8EUCMsfY tTVfvXpeGMHsgUJ8JEcNCxb3Zk9yQw08PW4bD3BhmsZnKSyHdg5baoz/x+iRD5JMNdSv A3X1FfwsmC2Hf2ebYVTnuc5p2oLQJ3eCxE1gVmj20HNGcKLRjSnaDMV5IkU1ZznceoJg mgoZ/cKSrWdKFi91PZq3h6qZpc69kiKbNLfkoRSup3uTcPk7+jyXm73Enf2kAQE9siFf 5XLg== X-Gm-Message-State: APjAAAWh93Gy1g7l3CKKK/iWXtqIBI9ZVl+y5VlnWC1nQUYdE1qBG0O7 OerkIK4jt8GVdofHTP8mBQv4Qa2VRtTnouqV9U0EuXS5zOpMxEkpyjmG37SU6QnBCwb5YyE+yTV jvxxyloU/b6Xp0pMYqUExPLQTdMrkw7/CqKtpaiGX/t8UQa9yY56XCrFD/DVH8bC9OQ== X-Received: by 2002:a17:90a:2ec1:: with SMTP id h1mr29257371pjs.101.1561963262265; Sun, 30 Jun 2019 23:41:02 -0700 (PDT) X-Received: by 2002:a17:90a:2ec1:: with SMTP id h1mr29257309pjs.101.1561963261513; Sun, 30 Jun 2019 23:41:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561963261; cv=none; d=google.com; s=arc-20160816; b=jPx4P4qt3bHgmxdQ4Syldg9TATpTVYpAH55UF6fWNklBa4VTnly1+heUwvn0GzHyGy JdMz3dzAfS42+i9X0kiZjZXKY9J/3eBjKeHChdCwgbcRlVpZzTeBL0mrd4zVwaekILxb fnsbRdbmnfCWaI9mRhm3QyO4sng8m/R4jxkP3aEAI/BOA0RCTPgGh2rBjG9tocPJcDnf TN+Sj+0d3664el+G9l9KcB4/96TEN2vMhDtZl0cnlSE8M5DcFLTl0sYAcmZEBfwVlIor O1CScKpuakRZ62dmFR0tRC/kv/K/raCRzBCxeO9VqoAioshbCfwp2cYEQyZIHEzoovKt hozw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=smDmHv6fTQfEC2Xw13QJ3CuxW2VIYrqrjOiGuS7E8nY=; b=acR0YbaPzbJ5Zjs3i5UZHGRXHaw+PDhZft+pkt34g6+VCeDnZXD38J1MGOH0PXM6o3 BS81k84QF1FAh8BmBHqUBU0b+thwpuJs/llmMz9zRHdLcDpUXmsFpeWEBb0fzzNxonSm W7urispfZgx3h4ufNaL5ighG450NY6WoHlE7qtTfvfiUFvOtbQra1Xl7px+OB6kZFlTJ VBEplPwT/RL3GkKG0yMcdqdIP8X2LFdfjpUkWjC0cveE9qUPTOJj3iWJNw5YxpNE+GhU 0rFuAmb/9VYsQ4FZVosG/4GyLi+/287bUZE/HuWNw+G1Yc1TZw9Rt7KtW3tMpx7BSEEP 1Xtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bizikAVg; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 3sor11203805plo.62.2019.06.30.23.41.01 for (Google Transport Security); Sun, 30 Jun 2019 23:41:01 -0700 (PDT) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bizikAVg; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=smDmHv6fTQfEC2Xw13QJ3CuxW2VIYrqrjOiGuS7E8nY=; b=bizikAVg98c+yn3J0ciWcHUsmX+eyH5Ec+Sx1ENDwBE32Rx/0lg8b1PCfc37WCUEDP jvLHutEpkCjCeKIF+3OCxCQD2xwfD1eqZv22X/0xYJQ2gfkR6T5h9U/i3UGWyxnopCfA Lc9xD+81BMSV0KJwxT6Zl8kgkeypStm0C7tCePD/8Phv4vhKKMSzIoSCKbqq4aQcXAk2 zSivyt8fYuQ9m/IJ5Iloms2K0emcTQysfKlLQHpo7SvscAXV2YkufHhBN7FSL1dpYBzJ hW4BMvvO1kSJHQ22hVPW5au0hnygWqK2g/+kZgrcqWqf4S6z9Rb8Swfe1cQTUPSpss9b XiSA== X-Google-Smtp-Source: APXvYqxC3bQxXqpIe85UilgRlX3q9ASs816UdqitUsnjCUP/RYiNALnXskGWa2IYqd1xwqXJJ9Kx/Q== X-Received: by 2002:a17:902:d887:: with SMTP id b7mr27095942plz.28.1561963261105; Sun, 30 Jun 2019 23:41:01 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id x128sm24238285pfd.17.2019.06.30.23.40.57 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 30 Jun 2019 23:41:00 -0700 (PDT) From: Nicholas Piggin To: "linux-mm @ kvack . org" Cc: Nicholas Piggin , "linux-arm-kernel @ lists . infradead . org" , "linuxppc-dev @ lists . ozlabs . org" , Andrew Morton , Anshuman Khandual , Christophe Leroy , Ard Biesheuvel , Mark Rutland Subject: [PATCH v2 3/3] mm/vmalloc: fix vmalloc_to_page for huge vmap mappings Date: Mon, 1 Jul 2019 16:40:26 +1000 Message-Id: <20190701064026.970-4-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190701064026.970-1-npiggin@gmail.com> References: <20190701064026.970-1-npiggin@gmail.com> MIME-Version: 1.0 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 vmalloc_to_page returns NULL for addresses mapped by larger pages[*]. Whether or not a vmap is huge depends on the architecture details, alignments, boot options, etc., which the caller can not be expected to know. Therefore HUGE_VMAP is a regression for vmalloc_to_page. This change teaches vmalloc_to_page about larger pages, and returns the struct page that corresponds to the offset within the large page. This makes the API agnostic to mapping implementation details. [*] As explained by commit 029c54b095995 ("mm/vmalloc.c: huge-vmap: fail gracefully on unexpected huge vmap mappings") Signed-off-by: Nicholas Piggin Reviewed-by: Anshuman Khandual --- include/asm-generic/4level-fixup.h | 1 + include/asm-generic/5level-fixup.h | 1 + mm/vmalloc.c | 37 +++++++++++++++++++----------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h index e3667c9a33a5..3cc65a4dd093 100644 --- a/include/asm-generic/4level-fixup.h +++ b/include/asm-generic/4level-fixup.h @@ -20,6 +20,7 @@ #define pud_none(pud) 0 #define pud_bad(pud) 0 #define pud_present(pud) 1 +#define pud_large(pud) 0 #define pud_ERROR(pud) do { } while (0) #define pud_clear(pud) pgd_clear(pud) #define pud_val(pud) pgd_val(pud) diff --git a/include/asm-generic/5level-fixup.h b/include/asm-generic/5level-fixup.h index bb6cb347018c..c4377db09a4f 100644 --- a/include/asm-generic/5level-fixup.h +++ b/include/asm-generic/5level-fixup.h @@ -22,6 +22,7 @@ #define p4d_none(p4d) 0 #define p4d_bad(p4d) 0 #define p4d_present(p4d) 1 +#define p4d_large(p4d) 0 #define p4d_ERROR(p4d) do { } while (0) #define p4d_clear(p4d) pgd_clear(p4d) #define p4d_val(p4d) pgd_val(p4d) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 0f76cca32a1c..09a283866368 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -284,25 +285,35 @@ struct page *vmalloc_to_page(const void *vmalloc_addr) if (pgd_none(*pgd)) return NULL; + p4d = p4d_offset(pgd, addr); if (p4d_none(*p4d)) return NULL; - pud = pud_offset(p4d, addr); +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + if (p4d_large(*p4d)) + return p4d_page(*p4d) + ((addr & ~P4D_MASK) >> PAGE_SHIFT); +#endif + if (WARN_ON_ONCE(p4d_bad(*p4d))) + return NULL; - /* - * Don't dereference bad PUD or PMD (below) entries. This will also - * identify huge mappings, which we may encounter on architectures - * that define CONFIG_HAVE_ARCH_HUGE_VMAP=y. Such regions will be - * identified as vmalloc addresses by is_vmalloc_addr(), but are - * not [unambiguously] associated with a struct page, so there is - * no correct value to return for them. - */ - WARN_ON_ONCE(pud_bad(*pud)); - if (pud_none(*pud) || pud_bad(*pud)) + pud = pud_offset(p4d, addr); + if (pud_none(*pud)) + return NULL; +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + if (pud_large(*pud)) + return pud_page(*pud) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); +#endif + if (WARN_ON_ONCE(pud_bad(*pud))) return NULL; + pmd = pmd_offset(pud, addr); - WARN_ON_ONCE(pmd_bad(*pmd)); - if (pmd_none(*pmd) || pmd_bad(*pmd)) + if (pmd_none(*pmd)) + return NULL; +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + if (pmd_large(*pmd)) + return pmd_page(*pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); +#endif + if (WARN_ON_ONCE(pmd_bad(*pmd))) return NULL; ptep = pte_offset_map(pmd, addr);