From nobody Tue Oct 03 20:16:02 2023 X-Original-To: dev-commits-src-main@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 4S0Tbk3nCYz4vwlV; Tue, 3 Oct 2023 20:16:02 +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 4S0Tbk38Dhz4g8F; Tue, 3 Oct 2023 20:16:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696364162; 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=o6WLgNRRaBWg4Rpi4a+cUgOebs/rBhw0Sr8knnJAGsU=; b=hBMmv0Ym8/igKDRN60gS9AgYzhnqroPCPJOF83hzlqB/Pp6f/W/FOGyh5Et+j6vXst7vDr 26RbfN6ADzcrNKjAuh/Bk/0z05DOhPVr2ENanp4AErJ4+p5l4AD7nMPHb1/JKlN5bi0tNw ncmODTH3BFmfi/EsNVm1Q2qzB0MwQaemJUr8NgQ0G9t141lxWHCsDRrqUlDN9RjtVCmQdO UfSvVbietASh23bb5bJMizkDd7ldnIGoYOt26G19ESdrNIyzn5NiaUQBQdhoW77wOZvrOe MrfB9gWUl4aN3NE/NxkQ5xvOSitS7xsakgtUs5qJ1BvkYiTpDvMvQc8vmQe/5A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696364162; a=rsa-sha256; cv=none; b=MHbL1Wg4/dwbzC0P6SFoPDKNW/sftYD9TlAimYnJzZEyTlP1Gb5EuexfTU82z6sp+1yZKK U97UUPbS9L51praG7UBzg8Bi7T/Y4fHUIYo1s2Zcq6BxBdIzw99dHeupUU3htES3Yu2YCs 0wuhKzlNueTah//BpDwktcW3C+H357UaV4HEySi8T0AzNLkoi+T8copOtLaZHstoSruY3h PnbpgHr+/yGShltVJWvwdYEgkb1XF4G65kIEDIdUcaZ19kgC8LMl/R1ag12rIWjWLFpXVQ pyN2wMOny7+H15EFxGPQ7p4fWAxZEHUoMhfRcWFTLVFspDsvCPFXp7R43T0R1w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696364162; 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=o6WLgNRRaBWg4Rpi4a+cUgOebs/rBhw0Sr8knnJAGsU=; b=o+rVoV+Vi+bEt/1/EgjK2vj3Bp8mKcPgjEzB9AwsrQEq8pCZFU3TuyFhShsvBKewpQz6tC bfSVWyLyyOD9d4VxjBaTgv8QavGxa2s/j+DREpyHK73yA/B5WYuoYstw0mWlQ7nVqf5c9v fTzKA7keKrevaS0Fa7c1kr4bFamceUjjJpUgtFaOSvpDdTJhPyp7pfRd6o5PePxKe1DfBb 4d+ICqY9MpmybiUpv3GaG3gEz7RZzFCOJctoJ6rtYbCCcSBsZqcK9d7tPEfUawFvOMLfXv GivyuFb65i08Wh8pBb0+uMpw+vdz4VxdyzlF94BW4KMk7eLUw453sCuLJTsr1Q== 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 4S0Tbk26Hzz17rK; Tue, 3 Oct 2023 20:16:02 +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 393KG2D3069664; Tue, 3 Oct 2023 20:16:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 393KG2WR069661; Tue, 3 Oct 2023 20:16:02 GMT (envelope-from git) Date: Tue, 3 Oct 2023 20:16:02 GMT Message-Id: <202310032016.393KG2WR069661@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Jean-S=C3=A9bastien?= =?utf-8?Q?P=C3=A9dron?= Subject: git: 1e99b2ee9095 - main - linuxkpi: Fix uses of `pmap_change_attr()` List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1e99b2ee90956f275c3668e92a408400f2dada1c Auto-Submitted: auto-generated The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=1e99b2ee90956f275c3668e92a408400f2dada1c commit 1e99b2ee90956f275c3668e92a408400f2dada1c Author: Jean-Sébastien Pédron AuthorDate: 2023-08-16 20:32:42 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2023-10-03 20:13:52 +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 --- .../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