Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4454462ybb; Tue, 7 Apr 2020 07:50:03 -0700 (PDT) X-Google-Smtp-Source: APiQypIIXpkjTrbnfSsz0pp7bepThD4pTE/oAcmKwaaZW6P8s20f03x0G/cbje3jYftMWKe18yZL X-Received: by 2002:a9d:6315:: with SMTP id q21mr1942429otk.16.1586271003549; Tue, 07 Apr 2020 07:50:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586271003; cv=none; d=google.com; s=arc-20160816; b=ysVuCinFOTAarlpnsy8kJEMA39U8qEh1g/msMUCLRvg2zXYhp0snk18mqE4fWpDoXp Y2c/l6gBnfYU4ka6M7aW2mN391bOxTcNrCTOQmc/B0vZ8bBaG6VmwxSoxNsJvduURmz7 pVK5KAbBI03w/VF+t8icNnh404C1FVOmwDnUsf0jLCWY4RL+vu7zwkV8Kw2FHGJAWhcD 0m9sW7ODrArgf00oxO9tApNVxABeq6TFR+QKoCHHBgA0l5cYbgOhZS7c5vBtJ7fDmoMR b14zvrcthBmef+JIpS0uK7kzIOty4OcHNHkIGQLCJZ9bAWgPPQF71Xa/00ehBGU0uq3A zHhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1qkEQ73ghM61/BXRvlDJEs7SEg6hkPYIpkfLFdxJqkM=; b=KLMg6aG5QAhnQT4bizxaN91dogbwKHOfz8wLuE6bDxVy8srDevmQntR4DehF+kGdPY RDHjD32ZX1KFPmV0M96VjVtUdByFevFJ7InXs89NjjCcVHukcvw9FUWhHrhyLsroedx2 ctAx+lmaDuZDyoatoNjDwBOoR++L2xuF/Ek7DUDz+vuIlqrh4tXOp+MKAuFIDS1HD5RA FZjJB/g0Jb1/+sxNfr0CZfoaEbWJ+zQhTJW3QJ8yADJl2TIRCiE+llbZpg5R8qjcnJvp KT1x5RAIpb5DB4Z5//neIxlaJIT8O9EYHr8hQ3h5vZ4L/W5oUOU6RUNGrZQMcLA87kYJ 9qHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Z95WsXja; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x73si1286190ooa.13.2020.04.07.07.49.50; Tue, 07 Apr 2020 07:50:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Z95WsXja; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728917AbgDGOri (ORCPT + 99 others); Tue, 7 Apr 2020 10:47:38 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36571 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729275AbgDGOrJ (ORCPT ); Tue, 7 Apr 2020 10:47:09 -0400 Received: by mail-pl1-f196.google.com with SMTP id g2so1334939plo.3 for ; Tue, 07 Apr 2020 07:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1qkEQ73ghM61/BXRvlDJEs7SEg6hkPYIpkfLFdxJqkM=; b=Z95WsXjaZ4R1OiZAjtFWozqj9735nUzepdNDu+Rm+ykKmZ1QhMW1WXzh4mh+TxtIUE 3up1bhUw0eoHYPS2z8u6Mz4s5j4A2KaKT+b3o5aWzvtjB2dNihRQ+qXe8mFuGaUjOb7e PHR/jKA1Ybc0M0HAbqxdcQ4Id/syAJDH5PBKE8wm9I8phudmq4vsXT6ifv3WXy0nXAIB AH2lCtDzZ8wqQyWQ5t3ZAaLK/NdSJoIrbi78EcorwBkK9t45hMs/R6/CQqwUJ3hI8RZL W9QEv1DPVnBiArLheGHAnGn1vDRriUf+GqOdmk4bKQW2fK7NCvaaEyPjormnBQMmeELy Pchg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1qkEQ73ghM61/BXRvlDJEs7SEg6hkPYIpkfLFdxJqkM=; b=ZHGF7sw/pAZ/SGM/OU2FMTPRKe3UCLSUjBE9yfSBOypBd395cGistjeY0aS0nGVna5 WtAFeXkDRh0Gwfa4CNNt9NKi/gWqLB3gntpXf5XWC6QRyj7MevCRtL5BsveunWoT/LWy qHOUXr2nJ/SEk3hiVoPrlMFGDVgFH1yj2bczcSZuaGc+L1xqtzOdKT1TT8xQ4326FgOn QBSTQnrmHsfuoYVKW7lsT6ub6vmLYY+8hcQ2zVB9HBjq4PUTh06Y35FYugz96p26JnYY KyvXE1Co18vE1EzvdL9zgzrRScvkd2Lc03BdUPu8/nVe52qc2kLU8NZTDu/MzSSXozdD I3hA== X-Gm-Message-State: AGi0PuZ5TyyRaxGMNRpMDgDL6sR0kzt2ENkextHTCJOSMzWH/k7mla7o RwocN9k1T3bD6AVugT/efR6JqQ== X-Received: by 2002:a17:902:8609:: with SMTP id f9mr2675736plo.203.1586270828988; Tue, 07 Apr 2020 07:47:08 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id y15sm14190093pfc.206.2020.04.07.07.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:47:08 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, mhiramat@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li , Palmer Dabbelt Subject: [PATCH v4 5/9] riscv: add ARCH_HAS_SET_DIRECT_MAP support Date: Tue, 7 Apr 2020 22:46:50 +0800 Message-Id: <1b9ab6009c1d70451e21a35ed7fea47c139bc65f.1586265122.git.zong.li@sifive.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add set_direct_map_*() functions for setting the direct map alias for the page to its default permissions and to an invalid state that cannot be cached in a TLB. (See d253ca0c ("x86/mm/cpa: Add set_direct_map_*() functions")) Add a similar implementation for RISC-V. Signed-off-by: Zong Li Reviewed-by: Palmer Dabbelt --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/set_memory.h | 3 +++ arch/riscv/mm/pageattr.c | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 9044e0dd95ea..a94d0f064d9c 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -59,6 +59,7 @@ config RISCV select HAVE_EBPF_JIT if 64BIT select EDAC_SUPPORT select ARCH_HAS_GIGANTIC_PAGE + select ARCH_HAS_SET_DIRECT_MAP select ARCH_HAS_SET_MEMORY select ARCH_WANT_HUGE_PMD_SHARE if 64BIT select SPARSEMEM_STATIC if 32BIT diff --git a/arch/riscv/include/asm/set_memory.h b/arch/riscv/include/asm/set_memory.h index 79a810f0f38b..620d81c372d9 100644 --- a/arch/riscv/include/asm/set_memory.h +++ b/arch/riscv/include/asm/set_memory.h @@ -21,4 +21,7 @@ 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; } #endif +int set_direct_map_invalid_noflush(struct page *page); +int set_direct_map_default_noflush(struct page *page); + #endif /* _ASM_RISCV_SET_MEMORY_H */ diff --git a/arch/riscv/mm/pageattr.c b/arch/riscv/mm/pageattr.c index fcd59ef2835b..7be6cd67e2ef 100644 --- a/arch/riscv/mm/pageattr.c +++ b/arch/riscv/mm/pageattr.c @@ -148,3 +148,27 @@ int set_memory_nx(unsigned long addr, int numpages) { return __set_memory(addr, numpages, __pgprot(0), __pgprot(_PAGE_EXEC)); } + +int set_direct_map_invalid_noflush(struct page *page) +{ + unsigned long start = (unsigned long)page_address(page); + unsigned long end = start + PAGE_SIZE; + struct pageattr_masks masks = { + .set_mask = __pgprot(0), + .clear_mask = __pgprot(_PAGE_PRESENT) + }; + + return walk_page_range(&init_mm, start, end, &pageattr_ops, &masks); +} + +int set_direct_map_default_noflush(struct page *page) +{ + unsigned long start = (unsigned long)page_address(page); + unsigned long end = start + PAGE_SIZE; + struct pageattr_masks masks = { + .set_mask = PAGE_KERNEL, + .clear_mask = __pgprot(0) + }; + + return walk_page_range(&init_mm, start, end, &pageattr_ops, &masks); +} -- 2.26.0