From nobody Tue Mar 01 15:17:51 2022 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 1DCAE19E8854; Tue, 1 Mar 2022 15:17: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 4K7LTq702xz3kGQ; Tue, 1 Mar 2022 15:17:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646147872; 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=ch77LeAp7HYaOZwPRoSGZG1l+zqHX9fYRs74UTFkSHI=; b=w4DdiYStgk0b5zqe1YAkFhPxZEcdW9MCoyFzUuQs3dAdHdHmCfzax+hAs5Gmtcj/G2tsuo vtOBpvz1RmML0MawfwvUYu3WHSMemdXvObqpBAwweYkc3MpuLOgVRDLl2ah11YtoTUE8Uj 9jkx+cyLcoN0//6IlDdlkBk0TUQ9GTLWuN59d07FRyd/1bA9uUvlzHJvl1twSIWaP9LV3Q uWrxZvh5VISSMEXjD/ji5avhNrPO7HjlIFosFPRMOS6ASZJJl4rxj6W757aiHcTHLUC6Q1 YmwJ73TVoamqqKUmfoUY/8KU5RVyallJh8j1NoiV+768t1LP8uy3aQXR6boPFA== 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 D131F11CB8; Tue, 1 Mar 2022 15:17: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 221FHpZ5092637; Tue, 1 Mar 2022 15:17:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 221FHpPO092636; Tue, 1 Mar 2022 15:17:51 GMT (envelope-from git) Date: Tue, 1 Mar 2022 15:17:51 GMT Message-Id: <202203011517.221FHpPO092636@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 15a163794539 - stable/13 - riscv: Fix a race in pmap_pinit() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 15a16379453983788fdcb030006b59ff4807f61f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646147872; 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=ch77LeAp7HYaOZwPRoSGZG1l+zqHX9fYRs74UTFkSHI=; b=CE4k5dxmcK/mD16caKAt4TbJPFcShfAYMAKd6qslr3uv7Bwi84DLUIrWRs4Q1QXXiGrdol 0QUCNmLZ+CZX3gbeyn+qi2gnRQVYfy7U68gGouwvIJ/h+rmzZgOXrs8j48HbZcdga6Hm8Y FjJNy90b/A8OtThOT9xxW+1i9s7IVMaesO7obIzRRv6i+7KrSJfUhF5Eh6Y7h4/p2vQ0Gq B1KB/NjLxJXcBdR+n5SLtQpIhYyPh9tfMW7gY0NB2Xy0+PoHe7exEvJn6can1dREp7P292 jqz9u8rhXJbkCietrnVAxMIwgP25sQ5jxlM8sE6gt9XPs9v3IBA9vAuLYJOSyA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646147872; a=rsa-sha256; cv=none; b=B+1+sMi6toCybW0N+n+W5O+7YxyZ0yk9UhACQASHEYJmhOrxe5bs3ZnCEBe5q/YPwYj0HG rOZGFjwmhFpKxgUpCYTuWRpAtpcO7lJtpJx8qOV+uk7cudbKONBm/04MI8LCzHCPTZwgyQ F/I8T5eEkUi5kuILQhcs4SBLjzBpZetQQQhnqyFPkIo1ELDKLl3sdpUTVVLFBX/d2X8tM3 iFENDRXiv5AmKYpMMbS4w9jbe9gylROI0SUtKPoPAGehBGPr+nUpKq5Gj/GwR6E6757n25 VuQtXtdpsNFKsbtZQkBE1jtEG8Xm3FX3ruyKzbhGh97r6qIM/QBe5TpsSnOHeQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=15a16379453983788fdcb030006b59ff4807f61f commit 15a16379453983788fdcb030006b59ff4807f61f Author: Mark Johnston AuthorDate: 2022-02-08 18:15:54 +0000 Commit: Mark Johnston CommitDate: 2022-03-01 15:17:33 +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 Sponsored by: The FreeBSD Foundation (cherry picked from commit c862d5f2a789925efe70fc64247caa5148e98a54) --- 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 589628d0e350..97f96ebdf99e 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);