Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp94188pxj; Thu, 3 Jun 2021 01:33:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz//A7fpuW2M9NX6lnrRK+IHWQ6zBXA0irGVO36rY9JF3UQFKHxc+O+IF4HQ/8A2vsEbf06 X-Received: by 2002:a05:6402:111a:: with SMTP id u26mr41777203edv.260.1622709231140; Thu, 03 Jun 2021 01:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622709231; cv=none; d=google.com; s=arc-20160816; b=OJaHZskFQcHVc53mmP/tUsTlS6i3ZT8CgfSa61chL5lVtkCXXly7EJ6bGV4nZjiTai yW6gW5dlXphXvQFmJY9HSPekWMVvCLF+DjfyjSEtls0UcwvG3a0hB207EGqDHGN+QJmH mkjxubRF6pHMKNd/8MYEKEBrFrKBHVCtW8UpWbtszen/r2B7nMy2Fs1ic1IDIbUmv0gN 07wWHUQaPMU0B5e2XEuAQteX/Fd5uzVlfW8dajET6cKQrX4or1nyt1Za5Q8SLtQmbKem 6jsqzwpf0D21vGncb+CWZ+P9W639OpGxjUoWbt030TRrNhBFDCr4hXm2a0bbgp0/05b2 qSEQ== 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=krdQuJpjly7AuayWIqc+Qi3tUA3C/5hhsbOSl0sElEI=; b=m479TEetu7+p6VJ3MOuD2IpEp8W9+yO6O755xbqZG2rkn2ZdGUhTEaLrr11B0Gd1tf ttKWexe+A/2Q+b7QPjzLedpItH3TNr31/rYAtCMl8J54kw5wBQaKYj5ByeSzp9rhjIqv rh1MbX9t8WUck6fAYyWqPQhg0DTgvU87IJ1MN0aqVkPgPPm2Bz8DBMpfdeMULm7la6o8 poTePgkNrlPY8Cv7BQdn97GBw9WUUB+bsmPPZ07h8i47waTW4VXes/WvkfDcouIPE5yc vWAtig8IVAKxyhLk4i5XYJxRPV1xbEhMJOz64GLWPc6F7qbbpiYQ9iqT+eY03JdbQIed pKjA== 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 k9si1742112edx.45.2021.06.03.01.33.28; Thu, 03 Jun 2021 01:33: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 S229772AbhFCIby (ORCPT + 99 others); Thu, 3 Jun 2021 04:31:54 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:46863 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbhFCIby (ORCPT ); Thu, 3 Jun 2021 04:31:54 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 1FD3710000D; Thu, 3 Jun 2021 08:30:02 +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 v3 2/3] riscv: Introduce set_kernel_memory helper Date: Thu, 3 Jun 2021 10:27:48 +0200 Message-Id: <20210603082749.1256129-3-alex@ghiti.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603082749.1256129-1-alex@ghiti.fr> References: <20210603082749.1256129-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 --- 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 086f757e8ba3..7a411fed9e0e 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