Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4784620pxj; Tue, 22 Jun 2021 08:00:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqwHORtFXWHzE7Ep/WXmU/OIkV+Mw0wxSS2APoVX4B4YVLOk3D2Bf5sdY1E8QaGCBci1WH X-Received: by 2002:a02:4b46:: with SMTP id q67mr4370177jaa.84.1624374055102; Tue, 22 Jun 2021 08:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624374055; cv=none; d=google.com; s=arc-20160816; b=BLrIUC1LuFy5v374YZ/DO8QYaw91gtofvQydeTUYzcyV8FfXUM761hjf4e8ioXXwRN 37GI++dR8jKUCc07PpuS0q+aTZulXkM/w5jSPCjukeF4gbcyei4rjo7bFpYtKSlPKxU8 E095SS2DeTFDC0GZgm7r5jy4uTbMDmWZH61LbZzOT5g9UJ5SarPz5X9MLIorPOikBwVT vNrjc48D3Dg8yKtAR0PE/Rgy3JNs3StEd1A4/PE//LBVp5KDeozYHW8rJD8rBvymkqPk FEIRI4yNNcYr2Xe5+/PmDWmbNf2Z3z5hrp0itO9rww82KT/Z6Ib8WkCTZPavnepe0xo3 US1g== 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:subject:cc:to:from:date :dkim-signature; bh=aR8G01IJ+UceVFDgRJW6BYPthEX2HmXBeaQ0eDZtDvc=; b=YERJnKX8pambgz4oTrs0DXGn684kRByK1ptOSYmnZZvhWP+1RbS3NWGfY0OmLi20Ba o2qij/lOKFeZTOMriR5b79ayN4Dqx739Kv2B5etnEd9uaFVX6ZMMbslpdIXH6LJ4JjLV rCUuGDcbrMKlfdzjhkqttUkgpAeOLw3khfF3QJnNfAu/jgWyvIt1Xh2qAENeqq8H0aD7 VE+vTF63CYRvmehxyTpEF14Ul75B4jXeRWttxu+lM/t3anKMt6LK+RqiZ76SfH4kbXil Nau+aaEqwYPyrR1uNcILCQhmK9Dm2B7Ns9Q5svuHz88+SSTMvIzTU7X+kf4FRSNGs/pM uMMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mail.ustc.edu.cn header.s=dkim header.b="rN9/qI/+"; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mail.ustc.edu.cn Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i17si14631961ilk.46.2021.06.22.08.00.41; Tue, 22 Jun 2021 08:00:55 -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=@mail.ustc.edu.cn header.s=dkim header.b="rN9/qI/+"; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mail.ustc.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232101AbhFVPCF (ORCPT + 99 others); Tue, 22 Jun 2021 11:02:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232087AbhFVPB7 (ORCPT ); Tue, 22 Jun 2021 11:01:59 -0400 Received: from ustc.edu.cn (email6.ustc.edu.cn [IPv6:2001:da8:d800::8]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2103BC061760 for ; Tue, 22 Jun 2021 07:59:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ustc.edu.cn; s=dkim; h=Received:Date:From:To:Cc:Subject: Message-ID:In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=aR8G01IJ+UceVFDgRJW6BYPthEX2HmXBea Q0eDZtDvc=; b=rN9/qI/+KZUTwcPnMglDwR/DmH325OzAcRRpUGkBv94ONCmds6 6g2xr9YsPWvYuurbncwEpXiKTKACK+TnKPMBNCA0Ok2hGSDkI6FR0a9222czloFq l3LGBjEqQPdQ9N2gdyCsZ5AKE+woSn8YaXAJ6arwFC3vIiszvc3M+frqY= Received: from xhacker (unknown [101.86.20.15]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygCHjoql+tFgLsMbAQ--.20215S2; Tue, 22 Jun 2021 22:58:45 +0800 (CST) Date: Tue, 22 Jun 2021 22:53:04 +0800 From: Jisheng Zhang To: Alexandre Ghiti Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Christoph Hellwig , Zong Li , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 1/2] riscv: Introduce set_kernel_memory helper Message-ID: <20210622225304.53d94c0b@xhacker> In-Reply-To: <20210622082134.2404162-2-alex@ghiti.fr> References: <20210622082134.2404162-1-alex@ghiti.fr> <20210622082134.2404162-2-alex@ghiti.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-CM-TRANSID: LkAmygCHjoql+tFgLsMbAQ--.20215S2 X-Coremail-Antispam: 1UD129KBjvJXoWxJw17uFy3ZrWDXry3Zw4DXFb_yoW5XFy5pF 48Jw4DCrWagF9rGFWI9ryq9w1xJwn5Gw1jyrW3A34DuF47XrWUCw15tw1DJr1kGFyqgF4q kay5C34Duanxt3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkqb7Iv0xC_tr1lb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I 8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8Jw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l 42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJV WUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAK I48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r 4UMIIF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF 0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8489tUUUUU== X-CM-SenderInfo: xmv2xttqjtqzxdloh3xvwfhvlgxou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alex, On Tue, 22 Jun 2021 10:21:33 +0200 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 > 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, If __always_inline, can it be moved to set_memory.h? Thanks > + 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;