From nobody Sat Feb 17 21:32:27 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Tchpg6Lnmz59kwK; Sat, 17 Feb 2024 21:32:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Tchpg5wLJz4g87; Sat, 17 Feb 2024 21:32:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZSoQnVjL/BAr8yrsCAXq2dIE1XQpI6mE2el1n6avOlY=; b=Atotfb6nVm6ro2cFUP7sNZF6TomC3SVEpeiTlFnExadRKr1FLA9pgyRst72j4ulIOXb1Xf I50weBSH0Vvng9zMipQ4SHtKyJmqo6cgm81yAcP8kxlhSSTsuYuzn17eBAg4zalZtkFzmd UjPMGt4Szy6TTwIZDPoh70VS1ITAFdU8QHUzKfmD9t7lZNK4F3bwc8mJ2A9ZTPFVVw0jez aX2bD8QcPxG+t99BWFpJsDdiDBc8CV0wSGODw0a0ytKoIs6wWuMn+3KrBNTC2GGLioQCqw dfBhZxx7bRrZ+gVC4N0z3EBrW5kBm0TVnmG4UQ8vvSpYr5SRpVw0+m/XFmVjdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZSoQnVjL/BAr8yrsCAXq2dIE1XQpI6mE2el1n6avOlY=; b=m3jWZpLJMvQ5xoZUNLYOKpViAgZDSH3uME6jOxZ6zIqmAq5zZhZxntIaH2UPNp9119fW3d wLIQjLH42HfRrsR8iHUNfsMxh4hk0sDF5E9AWNcDI/+PKpiA9uT6a+PD8UAykREliw0gm0 vT6G7QwpyNjefS8qPsbaVTgPDNjT0Qf8omMRLIk2QnLSPaG/kRKp1rT2B3tjX6c5XROrk5 H6LS2/0kcyLtSPzq+GRNkDIjNZfttYLQJQvkKL+rHIOmUczNet7rjsTL7W1J6Y64jyu5uv eoRpeMIpiOh0sUdemKRCzPPetde4rtS9+qX9PbSWMCR2SbAFJdLTtPgyrktvJQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708205547; a=rsa-sha256; cv=none; b=NYvUyv3sDOYDnr5y83U1DO8SdGDhXRbPdAqcERNQQpJxPV56SZu2remAFGDZ0N5rvA1FXx HdsTGFdqgf0KKc8u8JEQaIFxhdGbLhgasPW2RSiTJzXxwF9m6Dkwpw7aS5uKdt/3ryWGlq nb76R39FWDPyB1RW8+4VAqJZgoexcoYX6crd1XBIEW5nB4rKsEt6lctDcT8JFPfoIFYLLE VeNI5bLwckjYcUZqzWmJZLT9V+71iBdtxSSy5aO6mO2gBSMd25fyghTJbFV0PNVbCMyH9I BtV8Sxx2+4mGsiiP/LdWHDia1KAZcXJhbcPna7eLZ1TkkSKZhIoB//+LDuiD0w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Tchpg4z2jzPM8; Sat, 17 Feb 2024 21:32:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41HLWREs019443; Sat, 17 Feb 2024 21:32:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41HLWRsS019440; Sat, 17 Feb 2024 21:32:27 GMT (envelope-from git) Date: Sat, 17 Feb 2024 21:32:27 GMT Message-Id: <202402172132.41HLWRsS019440@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: bb01efa6f87a - stable/14 - linuxkpi: Fix uses of `pmap_change_attr()` List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: bb01efa6f87a8588f0190fe778f2376736c93acc Auto-Submitted: auto-generated The branch stable/14 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=bb01efa6f87a8588f0190fe778f2376736c93acc commit bb01efa6f87a8588f0190fe778f2376736c93acc Author: Jean-Sébastien Pédron AuthorDate: 2023-08-16 20:32:42 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-02-17 20:58:34 +0000 linuxkpi: Fix uses of `pmap_change_attr()` [Why] This function takes an offset and a length as argument, not a physical address and a number of pages. This misuse caused the `set_memory_*()` and `arch_io_reserve_memtype_wc()` functions to return EINVAL. Another problem was the fact that they returned errors as a positive integer, whereas Linux uses negative integers. [How] Physical addresses and number of pages are converted to offset+length in the `set_memory_*()` functions. `arch_io_reserve_memtype_wc()` now calls `pmap_change_attr()` directly instead of using `set_memory_wc()`. Reviewed by: manu Approved by: manu Differential Revision: https://reviews.freebsd.org/D42053 (cherry picked from commit 1e99b2ee90956f275c3668e92a408400f2dada1c) --- .../linuxkpi/common/include/asm/set_memory.h | 24 +++++++++++++++++++--- sys/compat/linuxkpi/common/include/linux/io.h | 15 ++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/asm/set_memory.h b/sys/compat/linuxkpi/common/include/asm/set_memory.h index ae50148f0314..69f659001c60 100644 --- a/sys/compat/linuxkpi/common/include/asm/set_memory.h +++ b/sys/compat/linuxkpi/common/include/asm/set_memory.h @@ -34,14 +34,26 @@ static inline int set_memory_uc(unsigned long addr, int numpages) { - return (pmap_change_attr(addr, numpages, VM_MEMATTR_UNCACHEABLE)); + vm_offset_t va; + vm_size_t len; + + va = PHYS_TO_DMAP(addr); + len = numpages << PAGE_SHIFT; + + return (-pmap_change_attr(va, len, VM_MEMATTR_UNCACHEABLE)); } static inline int set_memory_wc(unsigned long addr, int numpages) { #ifdef VM_MEMATTR_WRITE_COMBINING - return (pmap_change_attr(addr, numpages, VM_MEMATTR_WRITE_COMBINING)); + vm_offset_t va; + vm_size_t len; + + va = PHYS_TO_DMAP(addr); + len = numpages << PAGE_SHIFT; + + return (-pmap_change_attr(va, len, VM_MEMATTR_WRITE_COMBINING)); #else return (set_memory_uc(addr, numpages)); #endif @@ -50,7 +62,13 @@ set_memory_wc(unsigned long addr, int numpages) static inline int set_memory_wb(unsigned long addr, int numpages) { - return (pmap_change_attr(addr, numpages, VM_MEMATTR_WRITE_BACK)); + vm_offset_t va; + vm_size_t len; + + va = PHYS_TO_DMAP(addr); + len = numpages << PAGE_SHIFT; + + return (-pmap_change_attr(va, len, VM_MEMATTR_WRITE_BACK)); } static inline int diff --git a/sys/compat/linuxkpi/common/include/linux/io.h b/sys/compat/linuxkpi/common/include/linux/io.h index ee46d354a5ae..2345967898e6 100644 --- a/sys/compat/linuxkpi/common/include/linux/io.h +++ b/sys/compat/linuxkpi/common/include/linux/io.h @@ -532,14 +532,25 @@ void lkpi_arch_phys_wc_del(int); static inline int arch_io_reserve_memtype_wc(resource_size_t start, resource_size_t size) { + vm_offset_t va; - return (set_memory_wc(start, size >> PAGE_SHIFT)); + va = PHYS_TO_DMAP(start); + +#ifdef VM_MEMATTR_WRITE_COMBINING + return (-pmap_change_attr(va, size, VM_MEMATTR_WRITE_COMBINING)); +#else + return (-pmap_change_attr(va, size, VM_MEMATTR_UNCACHEABLE)); +#endif } static inline void arch_io_free_memtype_wc(resource_size_t start, resource_size_t size) { - set_memory_wb(start, size >> PAGE_SHIFT); + vm_offset_t va; + + va = PHYS_TO_DMAP(start); + + pmap_change_attr(va, size, VM_MEMATTR_WRITE_BACK); } #endif