From patchwork Mon Oct 20 10:24:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jungseung Lee X-Patchwork-Id: 5104091 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 038949F65C for ; Mon, 20 Oct 2014 10:27:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 16B7D20166 for ; Mon, 20 Oct 2014 10:27:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0095C200E9 for ; Mon, 20 Oct 2014 10:27:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XgA9M-0000ss-98; Mon, 20 Oct 2014 10:25:16 +0000 Received: from mail-pd0-x244.google.com ([2607:f8b0:400e:c02::244]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XgA9G-0008Aa-PW for linux-arm-kernel@lists.infradead.org; Mon, 20 Oct 2014 10:25:11 +0000 Received: by mail-pd0-f196.google.com with SMTP id ft15so2027723pdb.7 for ; Mon, 20 Oct 2014 03:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=s6RpuORd6sXdDXqlUo5UydX1f5XBQ7X1ET5J1dhvQ9g=; b=rM/QegSAWfJD1aLBBKmAyAM12rXxlOZKe060ziTdnD8ETxuvNwxxJsTFqVa0k6LQQT IkLwVPnS58gIGZPuM1r3ADLLkZk9w1PJqiHxAqm4Kwz7IoA/8e+fkWumt8PNewEnVza3 GqNxRCj1/t/AvET6nlZgxyCHmDgKa/rnTSyqm7gXVnMoqF1aVJF4k754FPvUaEuNUYTN kH6BYxEoMqzl25yOet/KOvLN1ZWj8biRiEnsHP8wVo/cfp5lx0KxM+i0dsaOHKb4l9zO wBV/LqwGAUbc64FoGAmF8fgYrf8lN3nZ5qSjhfYM5PMAcCoC6EhNyqvv15zYLYhXdlDa MMqA== X-Received: by 10.66.193.193 with SMTP id hq1mr26443230pac.20.1413800689898; Mon, 20 Oct 2014 03:24:49 -0700 (PDT) Received: from localhost.localdomain ([165.132.120.48]) by mx.google.com with ESMTPSA id ps7sm8737371pbb.73.2014.10.20.03.24.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Oct 2014 03:24:49 -0700 (PDT) From: Jungseung Lee To: Russell King , Laura Abbott , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org Subject: [PATCH] ARM: mm: Refine set_memory_* functions Date: Mon, 20 Oct 2014 19:24:38 +0900 Message-Id: <1413800678-6794-1-git-send-email-js07.lee@gmail.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141020_032510_864888_4176C160 X-CRM114-Status: GOOD ( 13.63 ) X-Spam-Score: -0.8 (/) Cc: Jungseung Lee X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP set_memory_* functions have same implementation without memory attribute. This is a change to reduce code size and enhance the readability Signed-off-by: Jungseung Lee --- arch/arm/mm/mmu.c | 70 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index 9f98cec..34a64b3 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -364,33 +364,59 @@ static int pte_set_##_name(pte_t *ptep, pgtable_t token, unsigned long addr, \ return 0; \ } \ -#define SET_MEMORY_FN(_name, callback) \ -int set_memory_##_name(unsigned long addr, int numpages) \ -{ \ - unsigned long start = addr; \ - unsigned long size = PAGE_SIZE*numpages; \ - unsigned end = start + size; \ -\ - if (start < MODULES_VADDR || start >= MODULES_END) \ - return -EINVAL;\ -\ - if (end < MODULES_VADDR || end >= MODULES_END) \ - return -EINVAL; \ -\ - apply_to_page_range(&init_mm, start, size, callback, NULL); \ - flush_tlb_kernel_range(start, end); \ - return 0;\ -} - PTE_SET_FN(ro, pte_wrprotect) PTE_SET_FN(rw, pte_mkwrite) PTE_SET_FN(x, pte_mkexec) PTE_SET_FN(nx, pte_mknexec) -SET_MEMORY_FN(ro, pte_set_ro) -SET_MEMORY_FN(rw, pte_set_rw) -SET_MEMORY_FN(x, pte_set_x) -SET_MEMORY_FN(nx, pte_set_nx) +static int set_memory_attr(unsigned long addr, pte_fn_t fn, int numpages) +{ + unsigned long start = addr; + unsigned long size = PAGE_SIZE*numpages; + unsigned end = start + size; + + if (start < MODULES_VADDR || start >= MODULES_END) + return -EINVAL; + + if (end < MODULES_VADDR || end >= MODULES_END) + return -EINVAL; + + apply_to_page_range(&init_mm, start, size, fn, NULL); + flush_tlb_kernel_range(start, end); + return 0; +} + +int set_memory_ro(unsigned long addr, int numpages) +{ + int ret; + + ret = set_memory_attr(addr, pte_set_ro, numpages); + return ret; +} + +int set_memory_rw(unsigned long addr, int numpages) +{ + int ret; + + ret = set_memory_attr(addr, pte_set_rw, numpages); + return ret; +} + +int set_memory_x(unsigned long addr, int numpages) +{ + int ret; + + ret = set_memory_attr(addr, pte_set_x, numpages); + return ret; +} + +int set_memory_nx(unsigned long addr, int numpages) +{ + int ret; + + ret = set_memory_attr(addr, pte_set_nx, numpages); + return ret; +} /* * Adjust the PMD section entries according to the CPU in use.