Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2224511ybh; Mon, 9 Mar 2020 01:24:49 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuvxU2C4ewo9dIlWtnHX9H1cadHl0+LXtTA1PD0GeWd8e2UfBg0nwAzARX4CqDy7sEXWwej X-Received: by 2002:aca:56c5:: with SMTP id k188mr10177260oib.165.1583742289247; Mon, 09 Mar 2020 01:24:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583742289; cv=none; d=google.com; s=arc-20160816; b=W67F3dNhkOfJ4MutNSTa9TYs0lH2QOfnJGa6v45iExh4Mqv7BbdVPkUrg2gDwNaiR3 EF5il0ynFHhkrTPo7kfxgm2WdayceEFo0TG6wdX+1pzPpQR3TRclzQy2L2GDi5o33cRY mFHkHWNEcDN9LeQAZ2XtctMWWDaCY9p+V8ABfUM4w3xhzkXxjBdYEW5H1HmtAZzQxs7J JSZcn0hUVW6Szjk+sUvaemHXcZyDgmWAwuG9Y+SkpR9Ph6jTlxNTW+VmGug59x4YH4GS N+axY6KVJD1FGnGFwl1u6uJ0sfYihuMaJ1eUUGdPhMMNEqrQyP1kWi0YHkTWJoxvAT6g 0cOg== 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=FB/FaS6maNFx1G9rifhLlVqm/rM7x/H1XFd6gLMSMDU=; b=ekH+3tRGzFzS/mxLNKuwLE1wsmXHh3yU18hJMIvIVifOjxfXiXM00JjiZkdDmlPEUD QUxSrRZiBro3V2QYVdDtjbDDie1pJ0/c+5r63BGlU8K7wS3F+168wNWWLB5AC18M+R5D 9WNwbgWP87gURDMVU0l/Gc+5LODHTk85FUj81ShlFL8hEuQYr+Ra57E1AkRVk1+vdmDE V4TOL3oC8cfDbT4Zwwa7z2KqQAS27GE7t2R8pi/EECfRG+pLDwtFqSr7Jn12Zql/Aixc xOuBNphlt5AHPQbdKfaK3TxurAQHOqFfpxfCSY8X1tCsyHA1oCq8KN+TirxDdry/ic+d Pcvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=YS4VWjcI; 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 n62si697381oig.196.2020.03.09.01.24.37; Mon, 09 Mar 2020 01:24:49 -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=YS4VWjcI; 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 S1726523AbgCIIWp (ORCPT + 99 others); Mon, 9 Mar 2020 04:22:45 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:54334 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726463AbgCIIWn (ORCPT ); Mon, 9 Mar 2020 04:22:43 -0400 Received: by mail-pj1-f68.google.com with SMTP id np16so4039832pjb.4 for ; Mon, 09 Mar 2020 01:22:42 -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=FB/FaS6maNFx1G9rifhLlVqm/rM7x/H1XFd6gLMSMDU=; b=YS4VWjcIzeXzEasAyfAvYoSY4xprd+s7Wos2ERuoNAlrVKG7Fx0HIv0sqNsBwuLcad YwyAQno4NvMm0cuwXi8xX4qbwAq24e9BHJULt7K4znUU1XTyqlpe4/Ku86KvfuBm5RCt JkXAfaFtDTKMpYAVjVpTcHdSaKRw6r17IZY8qKK3BkfD4ah5HbhY4k94YgkAPb42tUFk QHApoeA/VpcE5xNVrCm6RFlcxgAfGEurGZPdnxxhmmjqgAsptqKwrUCgUXJxVeTtp1gB ArQ3R3kgsumnWJy/3jts4vRoWOhf6l2rdrTcZSYOgn0gMGBTgB1qhIHnFh3N9tFad5dW H2xQ== 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=FB/FaS6maNFx1G9rifhLlVqm/rM7x/H1XFd6gLMSMDU=; b=mzoRePPHbP8oqQpUzPElg+6KL5m2jqSbZ62l4IAapI3r8zg8VKyrcF+aESPpPJAHCm 4cm05gvr1L+WpZ3X0ApOAXuAOLWxIwTuQeWfrsH+fmxgbrfcnHp7Yd3uvNsTjChsbCOK KpwaZ7BSH6ww4AkMj8p4+qd+Uqx+t/Ca1C99FqDiwpuRQ+Z2F0HSQCWWzd2k+dfD5152 ioNTbJ+8n+jFE4+VWTzNCC9KNLJf/kNafCQngKdjH4NqBqtUJp6K8dW5mYGUVXksqcLL XZOC/sWW3Do7XeyTI2GqYH9PN3W10IKRo/QTxdyqAQSf83RKiaJPpN3YcvjaaDqXUHcd AMlQ== X-Gm-Message-State: ANhLgQ0GkkxQHTQpdltxzqWGylykoJ8T8cb/Rw5iFYPTIDvjO1wK9RfZ 0WtyuXBpV790WDfDNt+E2od1GScvVIA= X-Received: by 2002:a17:902:7d8f:: with SMTP id a15mr14993550plm.107.1583742161781; Mon, 09 Mar 2020 01:22:41 -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 v5sm18364779pfn.64.2020.03.09.01.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 01:22:41 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH v2 2/9] riscv: add ARCH_HAS_SET_DIRECT_MAP support Date: Mon, 9 Mar 2020 16:22:22 +0800 Message-Id: <3875093ee6a6e980919009bb86b7193def05e2e8.1583741997.git.zong.li@sifive.com> X-Mailer: git-send-email 2.25.1 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 --- 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 76ed36543b3a..07bf1a7c0dd2 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -60,6 +60,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 936f08063566..a9783a878dca 100644 --- a/arch/riscv/include/asm/set_memory.h +++ b/arch/riscv/include/asm/set_memory.h @@ -14,4 +14,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_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.25.1