Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4498548pxj; Tue, 22 Jun 2021 01:24:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGBinr50iDDUGLfRkW/04h2xcritniTwpMd+AAQaHYOYRaShuKIsXoJxGp9rMp1XUnPFzQ X-Received: by 2002:a02:956a:: with SMTP id y97mr2759956jah.58.1624350272044; Tue, 22 Jun 2021 01:24:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624350272; cv=none; d=google.com; s=arc-20160816; b=oMsyG5EVrHc2i+xpIqUcbeJwr7XYl4x4xVByz/vVvI4ey4eyn4a2tvtKWBMDegQ7jO be4ozgSJS00zbXljLogjh5cLKaPQYPSiUh/0pWI45+tjvpdUov00uhk34TsOqmH8UeDb LX8mvfXYJbwcZ/TB+m1EaWrzTSdZ+eUKbhRA2uc5MlVjwfMoW1uBX3za0dorpiP3QbrZ Zk7QFuChFsJANN/Fk34LG2kiUvEAXwJ32zhdMHALccwknxsLtcO1yw5qZUgjLJiNrAmY 1VdUFLL3Ax2iNfYM2rLs5ItrqBkI/PDEKP39wQN3BH7BKVW+XRHVxqeHAU89G/6unwJl 3ZMw== 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=+llnUDBhFGnaBn4k6FSs0Anz5HfEIIxKCAW5K0jUvDs=; b=qH8tjPBjcQ16GMZQouFi8/sOnHy9rK1AyQKqgV7CH55EgXCzCitibXYz7LV17brQp+ UV0M+layWiUXUt+5DuVc8Vzo5uj4Ns/M9EODotnUDgbtF57zpqhorFyhvIdyEBT0hIKE W8azOQLqvC0Z1uXoCUf2Q4FHt8RuM9p5jztizLMSIKcfhjoWWUJe2fpWCDCPuz5OjrQe HBmdBfEPtCII3uwK3axiGbl4ja8bmH3ViJtlk1T7WsVRt6x83xbjz0ExeokJ8+7BELZQ csl41PaNCmSM1LhaRJt0Wagof2VHdH8Qqo86a3IESIVDQ1S1jOZtKXcHyDuJlKu0Pj4D f02w== 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 u6si15505215ilq.55.2021.06.22.01.24.18; Tue, 22 Jun 2021 01:24:32 -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 S230438AbhFVIZC (ORCPT + 99 others); Tue, 22 Jun 2021 04:25:02 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:58893 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbhFVIY6 (ORCPT ); Tue, 22 Jun 2021 04:24:58 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay12.mail.gandi.net (Postfix) with ESMTPSA id E2888200009; Tue, 22 Jun 2021 08:22:38 +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 v7 1/2] riscv: Introduce set_kernel_memory helper Date: Tue, 22 Jun 2021 10:21:33 +0200 Message-Id: <20210622082134.2404162-2-alex@ghiti.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210622082134.2404162-1-alex@ghiti.fr> References: <20210622082134.2404162-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 | 8 ++++++++ arch/riscv/mm/pageattr.c | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/arch/riscv/include/asm/set_memory.h b/arch/riscv/include/asm/set_memory.h index 9d4d455726d4..4f9fc54d1806 100644 --- a/arch/riscv/include/asm/set_memory.h +++ b/arch/riscv/include/asm/set_memory.h @@ -16,6 +16,8 @@ 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 start, int num_pages)); void protect_kernel_text_data(void); #else static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } @@ -24,6 +26,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 *start, char *end, + int (*set_memory)(unsigned long start, + int num_pages)) +{ + 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..11d0b0f4c65d 100644 --- a/arch/riscv/mm/pageattr.c +++ b/arch/riscv/mm/pageattr.c @@ -156,6 +156,17 @@ int set_memory_nx(unsigned long addr, int numpages) return __set_memory(addr, numpages, __pgprot(0), __pgprot(_PAGE_EXEC)); } +__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); +} + int set_direct_map_invalid_noflush(struct page *page) { int ret; -- 2.30.2