Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1045378pxj; Fri, 4 Jun 2021 04:55:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXnBYshMmxnh4Xa99kSbhGEjHTx74/e+Dnrxpb3yFhgOwV4sZbUzeYtPHoQXjV04tfWw5J X-Received: by 2002:a05:6402:157:: with SMTP id s23mr4403976edu.282.1622807715911; Fri, 04 Jun 2021 04:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622807715; cv=none; d=google.com; s=arc-20160816; b=Gc+dW+Y1QETRCIAzmUj+XiJsY8ND13kiVcYmTv8DL0INar1F988oCMfjjTBsFbzBks VcR6RL+zNxUSthCE+YOG5J9/XSTFQ9mDs6R1qHf4j0EoS9/DbbDRZ/CSa7jwOuZ+UolM MYTjZA589CteBuIQG4Jl85dyRQA22yEAGpKH7up92WzL082kDR7727JONY4SJSttdKUD HcnKl2bkIXV6FTtPFbJjaNYBzJvKpiceUN54zVC0SqcwC/gEqkvAqPp21EJ6cAWhGggr 9UvLHhFReLQ/a+3uCfFwSLZcrraWpcUClqs0KGIozK8D4NrxIW5+jL8vpDrT0jbR/TMs Ay0A== 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=pCf4oeyOgvfMeV1YwFq/bg8oonyECo4bihVszCWEV5I=; b=WHSQttIjONj0PVwIbV3P9nnqRZ0OzBGxAzjVenX1cbCmaJ2z2fHMC+gf6Yexv44UlX YQ4TJHTgijaZoWsxLVqECsnBGnsvTCtin19oDA/zSxRDOL+sJRVR43oc4SibxFXw+Osc IBvFG7HGNdrfcLbuWV8LGw+TJoiS2x1kgaD49IVyCkVqNawc9TWwJCGJYLvAYJkDXV9c PT2UpBYjWPM4BinDE7NPnerVHN7IXhrnjS7tM3qsmE7C5zvc2XgWQIz3aqE6eqFmW4DU QBTz6ue93BZufQrJZOobHVYByrgMuWJfwPocubUsB6rlj+zhfKwTUWXl4MReC7b0evSe 1ULw== 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 y8si4797708edc.269.2021.06.04.04.54.52; Fri, 04 Jun 2021 04:55:15 -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 S230030AbhFDLzD (ORCPT + 99 others); Fri, 4 Jun 2021 07:55:03 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:44473 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230207AbhFDLzD (ORCPT ); Fri, 4 Jun 2021 07:55:03 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id C06E51BF207; Fri, 4 Jun 2021 11:53:12 +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 v4 3/4] riscv: Introduce set_kernel_memory helper Date: Fri, 4 Jun 2021 13:49:49 +0200 Message-Id: <20210604114950.1446390-4-alex@ghiti.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210604114950.1446390-1-alex@ghiti.fr> References: <20210604114950.1446390-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 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