From nobody Tue Feb 08 18:36:51 2022 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 7187F19AA6B9; Tue, 8 Feb 2022 18:36:52 +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 4JtWv775Mxz3q5D; Tue, 8 Feb 2022 18:36:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644345412; 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=BvDNu4AtqeSH2ZoJcAP1zx/A9K09kxVWlgOApV9uTas=; b=EM1gcX7jXRXVazyFR+8PqKBrwBv6tkeyA3y2cEPQl9ZAF8BFG0u/X8ncpkmFKt0X1UKTiu EjyyazNCjypQs01d/+cjgjSL1s78bHdQkv8Gow65pC3hiCCMv/cSQvSEQIT1sJlPcISJaz 5fBLcev1hL1Bc0vP6L6c94S4U9kol/Vpo+KfmJBqd+fqkIbIXRjs9JWL0dNoG6dAPmpiVE JDyFyLOoF6eJ+RtG2yl/TcRQ7riNSoaGiPz4PAFphIhCwm+GLm+Ebico9xIxH+nQj0Wchk 3CZ0YpdiYxQ/NRXpXpGuXhcNbQN8FK9N2RLLZl1lJzK96na8sSEbxwNFtuo7hw== 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 B13FD1E4CC; Tue, 8 Feb 2022 18:36:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 218Iaple089157; Tue, 8 Feb 2022 18:36:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 218IapOW089156; Tue, 8 Feb 2022 18:36:51 GMT (envelope-from git) Date: Tue, 8 Feb 2022 18:36:51 GMT Message-Id: <202202081836.218IapOW089156@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: c862d5f2a789 - main - riscv: Fix a race in pmap_pinit() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c862d5f2a789925efe70fc64247caa5148e98a54 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644345412; 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=BvDNu4AtqeSH2ZoJcAP1zx/A9K09kxVWlgOApV9uTas=; b=eSg00JiYyw4BlawYbbgHng1k90ntB6do0ra04wMZ0NDWLyHcPJdbfW5ePM2JaA5R7WHZ0s wuIsvCaUAIPsTzhkSNi1uVemht+qxOO881eCGdUplT9xwpkfpyhTEqBoWkC4jTdAl+3KEh gEdD/x/r/k2sDK1VeoS4+rBmc0knZdpZrggZsSCXf9wtMPhhjVaR4CkWfaH8ASFMEoTrwt 6QiAxAgnzUO9brcCSCO5sDdw8lpKyarmZ/a+Z2iEjgZDdYHEbTZacqP8Fy/QX8Ss+Qe39L bVqZU/m/ec+H9mWlLTCDwF6j1R9TD/nW7/gAYFQtu9b8Th+Y3IsGqjWsracNsw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644345412; a=rsa-sha256; cv=none; b=DwSSMMAJZ9p9CL5eo7aAMqGf4T5iYRzNa5/trBOR/6PTiVdpbyD/FQXDjHHJbqFdWdRvnf sLBydCa0XKFAYnec7UY3MAKxmyCNYBm2yi8exGt+ty+GEKp71z+3n/tCuMy7yoJDRv9MxW 4bnV1m9ImVabeDHxvBJqf0n+5SMPdTKSMOeiOhVXSIEOhIPQRXXkmUhnSbIMqVhiAHZb6J O4mUj9rgcfu+WIFwrlx1eCFWiPmBTPnFKcYdT8rVnqApBh3hRx/yBbzBqX1NaQJFItEqzC 84H8ZM0W3h/12GBgMT65iL9pgW6MXRuKGivvRxx38xT6il2EKPKrWrRaJgROQQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c862d5f2a789925efe70fc64247caa5148e98a54 commit c862d5f2a789925efe70fc64247caa5148e98a54 Author: Mark Johnston AuthorDate: 2022-02-08 18:15:54 +0000 Commit: Mark Johnston CommitDate: 2022-02-08 18:31:55 +0000 riscv: Fix a race in pmap_pinit() All pmaps share the top half of the address space. With 3-level page tables, the top-level kernel map entries are not static: they might change if the kernel map is extended (via pmap_growkernel()) or a 1GB mapping in the direct map is demoted (not implemented yet). Thus the riscv pmap maintains the allpmaps list to synchronize updates to top-level entries. When a pmap is created, it is inserted into this list after copying top-level entries from the kernel pmap. The copying is done without holding the allpmaps lock, and it is possible for pmap_pinit() to race with kernel map updates. In particular, if a thread is modifying L1 entries, and a concurrent pmap_pinit() copies the old version of the entries, it might not receive the update. Fix the problem by copying the kernel map entries after inserting the pmap into the list. This ensures that the nascent pmap always receives updates, though pmap_distribute_l1() may race with the page copy. Reviewed by: mhorne, jhb MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34158 --- sys/riscv/riscv/pmap.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index 1dc62418b165..0607b82c88e6 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -1231,14 +1231,12 @@ pmap_pinit(pmap_t pmap) CPU_ZERO(&pmap->pm_active); - /* Install kernel pagetables */ - memcpy(pmap->pm_l1, kernel_pmap->pm_l1, PAGE_SIZE); - - /* Add to the list of all user pmaps */ mtx_lock(&allpmaps_lock); LIST_INSERT_HEAD(&allpmaps, pmap, pm_list); mtx_unlock(&allpmaps_lock); + memcpy(pmap->pm_l1, kernel_pmap->pm_l1, PAGE_SIZE); + vm_radix_init(&pmap->pm_root); return (1);