Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp148482pxv; Thu, 24 Jun 2021 05:03:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzc1uMqi5dalosSiK38f6cy9hDgm9iAhV3Xb8gFi6YoMfIWhDTvfMAOsqU+mhUWYPsmzUCI X-Received: by 2002:a17:907:c87:: with SMTP id gi7mr4912502ejc.452.1624536185378; Thu, 24 Jun 2021 05:03:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624536185; cv=none; d=google.com; s=arc-20160816; b=0dXaSXygUegpdK0oD8R86CRRfCHGwu79mVfw7wzMy4qI8SXNa0dAtq4gGCkZzJkBud mUchhym6tvDecbG9NdAgpexut9GfnXTIcBkRNOO233tHdZQxhATtTpvbFnlnvWCZEwVE HlrZYY56C3OLmncLYMxr3HM1NjOVYdTffbZb5XUa3Khob0OCsYRX6ozC03ru+FtH/FV4 W3Pb7s6tGVl490areItH0HH2W0+3dL5k8hUc9ez1EMg6GdKgNUIlSa3Xp61PiNGr6xE8 OrCZvn+7iy8aNrTU6PrMr5bxbbNLf9WHH2z3FPa+MX3AND9nzxToAkEgmee1/v9+pWxA nwmg== 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=PFrtGQaZ477mmkuELN8zYIp4wL+9dCzeMHmxwWBesac=; b=QGXkBVBITxTDIBYPRQ1Yu7owTzCCaRNGghLjdjWD2D4fR3VgOWBeY8akKo0Z+tgxCK vDWlV0inEt7UK6qCs+DxWbvHkJZ7Si4Xzy1GhtjwzB5b0Jq/um616Ixg4aBKvVqsBS0Q CQgMaT7H7VQgbc/4i/PWPs9LkP7cg4gOd1FzIPOyFDsp5mo86W0UBDGF+kdhEe9iJbUJ sVc5ZGEn9cdB2AZN+mvv8yQPxh/GmCq5AThA2hhtuC+RcbbdaUBIRYzHDEkgoE3F94WZ u2I1BPzsLLeoGDjoP5UNDezNGp7aI+5zMIfQ7HCw63muPx8FHAraOeQvfUDY55+IHS+5 MG2g== 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 v29si3052503eda.351.2021.06.24.05.02.42; Thu, 24 Jun 2021 05:03:05 -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 S230046AbhFXMEJ (ORCPT + 99 others); Thu, 24 Jun 2021 08:04:09 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:38367 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbhFXMEJ (ORCPT ); Thu, 24 Jun 2021 08:04:09 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 219A7E000F; Thu, 24 Jun 2021 12:01:45 +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 v8 1/2] riscv: Introduce set_kernel_memory helper Date: Thu, 24 Jun 2021 14:00:40 +0200 Message-Id: <20210624120041.2786419-2-alex@ghiti.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624120041.2786419-1-alex@ghiti.fr> References: <20210624120041.2786419-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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/riscv/include/asm/set_memory.h b/arch/riscv/include/asm/set_memory.h index 9d4d455726d4..96e317dcab13 100644 --- a/arch/riscv/include/asm/set_memory.h +++ b/arch/riscv/include/asm/set_memory.h @@ -17,6 +17,16 @@ 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); void protect_kernel_text_data(void); +static __always_inline 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); +} #else static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; } @@ -24,6 +34,12 @@ 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 *startp, char *endp, + int (*set_memory)(unsigned long start, + int num_pages)) +{ + return 0; +} #endif #if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX) -- 2.30.2