Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp199977pxj; Thu, 3 Jun 2021 04:40:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqLMsZgZxUucOxRHTaDGUFQ/c03HR3gfIghvpd0SeT5Q7hpLmL3N2a/ObqPjF/lVApdjTz X-Received: by 2002:aa7:d6cc:: with SMTP id x12mr19807910edr.55.1622720437367; Thu, 03 Jun 2021 04:40:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622720437; cv=none; d=google.com; s=arc-20160816; b=BalU/BKwCiMTCGSiNL8Hn1t9T5wceYa2QTQl3zTQ8nHQduor2PHHuAI+D6j53Jyuq4 W2U8lEcxI/4K8LkDGit8R2arCDpczdryC9Bc/ItqIRTM26EWdqlunWWzRC9E0aTFihtH U2KOMMDvgsLySlK1hkQFY54suvM9HTvlHFWD7fHZAiQOAMuF0SC20AQjkirnCEeY2cSE 2gf8lB5eCD2Xdl+hdR7G/Wv7MNcIL9GrR6PqpJ6rJxFh4DhX8eXb+KUW29LDgo1I7z8e hNBXbfmg7QHj5Jv2fQwnHS2nUCJGlifW2TliwHtTqyA69i8XIdLNEwm6eRHNXftrxqwl 3GWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=hUWQYY6cwXoInPRfC/THU59jRaVeDOI2+m6C3p5kdkg=; b=kWuzCNbSQwZZEeDn4J2SDOpWYLoPnNCpXkjqozWeGO1/BwqnRriZ+sNAabipejajV2 VSHRYlnIO0dUq9rmUTldHq71LFF7IpkYJZkTF9ZdG5nA690RDboMJ5k4xYr8dN7wUV6x E6d5q3zw5/rd8k8GQVYXW4ZDSk1yqc5Nkiat9uyUrvzcCIxqPkUuaf7se27WCO6w/hWg VQ4ta68knAM8gFwCfHCJodBmQNohJ+XrBWiV3f6G2vl9g6J6Ux5+zWLNIGo+DsuXDSss TTdx5w+2EAI3NrTlZO1g1EcLdlymE6DbDEfcp/uUwA9iusFIKdCFTM8KqRSU1Jj4+2fY ariw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b="2POa4/Dx"; 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 g21si2217730ejb.437.2021.06.03.04.40.15; Thu, 03 Jun 2021 04:40:37 -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; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b="2POa4/Dx"; 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 S229876AbhFCLin (ORCPT + 99 others); Thu, 3 Jun 2021 07:38:43 -0400 Received: from mail-wr1-f48.google.com ([209.85.221.48]:33318 "EHLO mail-wr1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbhFCLin (ORCPT ); Thu, 3 Jun 2021 07:38:43 -0400 Received: by mail-wr1-f48.google.com with SMTP id a20so5543657wrc.0 for ; Thu, 03 Jun 2021 04:36:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hUWQYY6cwXoInPRfC/THU59jRaVeDOI2+m6C3p5kdkg=; b=2POa4/DxL3JRww/m2F5CWyfeZDJIbslwiPuE4VWvkdtk0v8fJgU1idUSWF09zSdpqi mfwRoAXiRBkv20g32UdgxUkb4qcetzXTquQ8NNgFNiJ3rAkXvcH6/zZQwTXMNrEzeqZT U4Kwg5Za/uNzxxBdM3YExgc3L+pw9b6Pdff0cZN6hoNxJCAq+nq/UrHgBBooW0OJUl6d N1qIh3w0wFmBIRnlQNtR+W5kiSUb/Af1wZxa1gaAeTg/SLrqidOB8vkIrxg8u8iAC9E6 ikNQoeiEaIBi+iVyUg1vJqXQnX6vPxVRJI6WaNABewvgqrctE0clhGEdUtbSbIyk4sPE aXRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hUWQYY6cwXoInPRfC/THU59jRaVeDOI2+m6C3p5kdkg=; b=Fl39BfXuMFkxC1qq8N03KSfI2y/7H/JYdq7uQRHAwdFXZ9A29qa8wTz4dlALARdZrw 7/a1efDPmL+IL7VIdn+9uyrSBcKa0QoLDGGoa4cOJIT9YemIZB5nop8u2kiNFfPaQfoX MtdM+P0m4p1tHZIjoz2sAzFI0tM/LGpyuGcSXihnmYLmWPLKS+l+Lackyk/z1BO7q3cT Yjtb1uFW3bcrqy9xJdMaJg0VtuTnmZXjiwr8JTzcQO/7K/DtqNW9NZw7xaH9N+fLicHc 5yqtYZ4AR04xNeZX6ubHkC2HM2+lvPkR0gKWdoquxAiZlVWl+67tNyRthKhPFYPq+RgT Tqpg== X-Gm-Message-State: AOAM531gEt8F9Fg9dez2w37pgV6gz1denigz8XKv7hRIkPeqYrUOQqP/ 7FhHwGj/1JljSk+GW1uBwO75DdGb3h7ivF2tQGindg== X-Received: by 2002:a5d:540b:: with SMTP id g11mr11167932wrv.390.1622720157797; Thu, 03 Jun 2021 04:35:57 -0700 (PDT) MIME-Version: 1.0 References: <20210603082749.1256129-1-alex@ghiti.fr> <20210603082749.1256129-3-alex@ghiti.fr> In-Reply-To: <20210603082749.1256129-3-alex@ghiti.fr> From: Anup Patel Date: Thu, 3 Jun 2021 17:05:46 +0530 Message-ID: Subject: Re: [PATCH v3 2/3] riscv: Introduce set_kernel_memory helper To: Alexandre Ghiti Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Christoph Hellwig , Zong Li , linux-riscv , "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 3, 2021 at 2:00 PM Alexandre Ghiti wrote: > > 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 Looks good to me. Reviewed-by: Anup Patel Regards, Anup > --- > 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 >