Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp563545pxj; Thu, 17 Jun 2021 08:47:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnawvzNskfTSOzbhgKXsrPPI9EOS8I+IJAwsSYHhCr/KNZtjw+WTC1ojg8qJBfg8/KuT3e X-Received: by 2002:a05:6402:2790:: with SMTP id b16mr7429182ede.115.1623944840108; Thu, 17 Jun 2021 08:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623944840; cv=none; d=google.com; s=arc-20160816; b=NPXa+sG8bvtaI1xYjSLwCUusJwWwf1RPEYn5EylEF9poqCHSe3g5H/QpswgoGgNwwC gNLO6i9kI29Pkcj5foy0n1hhQrA1tawv7pmt8ITX2MQSGYKdKoJllEwr2ayFErTba0Z8 40gkZE5a/74b5vj9+61sEPrQ28DGp4iGQu31ffe8JFHQypZ5p2TJ1JuXc1kHiehn/Uo9 OheXTfavdH3M7xPcreO/8gTJb3e7uOmGFS8sryFCTJ0hcK34bbypKSxia4ZbTd7Qtp0J tb3Ce72habsoV+G8/OBQlrFxks+n+iLJP24qf0UuJV+3+6R2yrpSf9MAWx4fbNKWFcy8 MCGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=upgAM9I0u4ZqGcpVfIt0FiIhnSpJiHZ7JzxuNSECXGs=; b=j/ln8I5Q1+KLEjGEWDFtGMMKpaYlnCl2hIT3j5aTowmrEEG4vI1Z1csIELTcbD4d0H KTLm1MVOI8f0yj7Zp0WxR+lnGfORd9XuUiltgJtIMb4MVKc9MH4XQjkxHtTZ3oEOwoBk QStVqq0nP3Loi8F/ISatkBxaa3aDhL+W+vz0MuQxp4XiVgIacSnfaxXNE4nyKY/TZReF tJ3Lkd33Cxxh57ky9qChIU/Xc8jo+xAQUws06UtSy5Uuef3MidCagmXrB3lwEN/xny9Y 9uuabCexy4aVDT7pBa68c3QsSd5e0l9VLt1Ki/U47C/0D3dS8UAIrGzB5erWXwKwMino 7GtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ci10si5867721ejc.752.2021.06.17.08.46.52; Thu, 17 Jun 2021 08:47:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232666AbhFQMEn (ORCPT + 99 others); Thu, 17 Jun 2021 08:04:43 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:46297 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232647AbhFQMEm (ORCPT ); Thu, 17 Jun 2021 08:04:42 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 4AA69100017; Thu, 17 Jun 2021 12:02:29 +0000 (UTC) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Christoph Hellwig , Zong Li , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH v5 1/2] riscv: Introduce set_kernel_memory helper Date: Thu, 17 Jun 2021 14:01:23 +0200 Message-Id: <20210617120124.1752541-2-alex@ghiti.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617120124.1752541-1-alex@ghiti.fr> References: <20210617120124.1752541-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This helper should be used for setting permissions to the kernel mapping as it takes pointers as arguments and then avoids explicit cast to unsigned long needed for the set_memory_* API. Suggested-by: Christoph Hellwig Signed-off-by: Alexandre Ghiti Reviewed-by: Anup Patel --- arch/riscv/include/asm/set_memory.h | 5 +++++ arch/riscv/mm/pageattr.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/arch/riscv/include/asm/set_memory.h b/arch/riscv/include/asm/set_memory.h index 9d4d455726d4..59f242abe969 100644 --- a/arch/riscv/include/asm/set_memory.h +++ b/arch/riscv/include/asm/set_memory.h @@ -16,6 +16,7 @@ int set_memory_rw(unsigned long addr, int numpages); int set_memory_x(unsigned long addr, int numpages); int set_memory_nx(unsigned long addr, int numpages); int set_memory_rw_nx(unsigned long addr, int numpages); +int set_kernel_memory(char *start, char *end, int (*set_memory)(unsigned long, int)); void protect_kernel_text_data(void); #else static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } @@ -24,6 +25,10 @@ static inline int set_memory_x(unsigned long addr, int numpages) { return 0; } static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; } static inline void protect_kernel_text_data(void) {} static inline int set_memory_rw_nx(unsigned long addr, int numpages) { return 0; } +static inline int set_kernel_memory(char *start, char *end, int (*set_memory)(unsigned long, int)) +{ + return 0; +} #endif #if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX) diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c index 5e49e4b4a4cc..c47ac6a432ac 100644 --- a/arch/riscv/mm/pageattr.c +++ b/arch/riscv/mm/pageattr.c @@ -156,6 +156,16 @@ int set_memory_nx(unsigned long addr, int numpages) return __set_memory(addr, numpages, __pgprot(0), __pgprot(_PAGE_EXEC)); } +int set_kernel_memory(char *startp, char *endp, + int (*set_memory)(unsigned long start, int num_pages)) +{ + unsigned long start = (unsigned long)startp; + unsigned long end = (unsigned long)endp; + int num_pages = PAGE_ALIGN(end - start) >> PAGE_SHIFT; + + return set_memory(start, num_pages); +} + int set_direct_map_invalid_noflush(struct page *page) { int ret; -- 2.30.2