Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp580128pxj; Thu, 17 Jun 2021 09:06:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5m8YCftI1oENwJ469V1ygZYWUkJL2sNZjAdDm/g6rgic1A/uIcFG6EBvA9vi2tq6DVGFx X-Received: by 2002:a17:906:74a:: with SMTP id z10mr4346979ejb.107.1623946011493; Thu, 17 Jun 2021 09:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623946011; cv=none; d=google.com; s=arc-20160816; b=t2b7SXoVEyzWYIrqfDDu5YrQlAGIDdASCDE+0pS09qxO2VPw+wdwA/ltkEmTZkMabb N0S2u4Rc9nJ/j7BB2KZrBN9RjZPkKM1zR2rEhrg77DhU+P1Q3MmOx4HTZJ69Rmt4QCEr MfU5fSZsnBJS9Qqb2Z4TAQUJkPoxhpZMtbx6dUfueurXyrceU+BkWsguJYc3qYL+NBqf FgMZGX2k/v7pevxQOTytQY16JY0gXwgnIx1K5GJxXBZ20Wk67WBjU3/J/iZmfQqy9jcM kc79ITypWx2Yz19NcBGHUK0r1ZdmStBCFBQTmMUfQa9nhjxAF3W5NI6MqaI+LuKioC64 YAaw== 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=swl7+5zz4N9Qku4Q5HlcPnnOp5FpRnILGKffsZOHXF79b7beMnvPcv3j1FVk2LpmxT k17EH5ASOhy/EfvkTsoAAa0nvZwiI59K+0OtvlYCiZL74OKgwCxjl3pRs9Dk5H+kyaQd 5Oh4pIMxqylXvB+5ElaWKAyKLM90il2pzaHc5OyMMyg9TgBgyMt+sbfNmR0n2udF7q06 qUTaqRZOwbpLf0jn+Uo3GVQyhZcmLad0vPKpYFrlF2wsaBnh1RsFt/wdnX7BMoDgrIVl AxyeOiXNpmL6Vh92Vr4cbKX6tmhWiB1u785mG6qOJ/wEZyNbVf6eVJIN83Ti3qB1hBPz YQGQ== 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 c18si6001361ejc.732.2021.06.17.09.06.27; Thu, 17 Jun 2021 09:06:51 -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 S232198AbhFQNVU (ORCPT + 99 others); Thu, 17 Jun 2021 09:21:20 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:56417 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbhFQNVR (ORCPT ); Thu, 17 Jun 2021 09:21:17 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 2C19D60003; Thu, 17 Jun 2021 13:18:56 +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 v6 1/2] riscv: Introduce set_kernel_memory helper Date: Thu, 17 Jun 2021 15:17:33 +0200 Message-Id: <20210617131734.1923932-2-alex@ghiti.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210617131734.1923932-1-alex@ghiti.fr> References: <20210617131734.1923932-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