From patchwork Sun Aug 20 20:44:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 715206 Delivered-To: patch@linaro.org Received: by 2002:a5d:484e:0:b0:317:ecd7:513f with SMTP id n14csp1531663wrs; Sun, 20 Aug 2023 13:44:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsvPNxoUN4LNxd2yl88veuusvG3fZ/S0jqYGtXhogArHmWdDaHHEyVZ8LgIiG5IPil2yP6 X-Received: by 2002:a0c:d989:0:b0:63c:ed11:7bf0 with SMTP id y9-20020a0cd989000000b0063ced117bf0mr5559236qvj.6.1692564299065; Sun, 20 Aug 2023 13:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692564299; cv=none; d=google.com; s=arc-20160816; b=JckIpMxheAE7SRO0eMrO+V+9G1YGct8bOCi0OWGdZ8FrbKaWkn45leuQ/FX4YK8dzg ttV5Fd1FXOL5kWbGS9qaUjsGQ+PhQs3XoXelD2da1bbK5dYc7eBKAQhkMG6YtKlRRxVa MTn94wvT4GUepFDp/7XPStJg2KD3KzhZjTvMqhb9i22ePGE2ou4AN3Qu/2Xc68zMjVno KItf5Q7UDHUb4FAJvb3fvOf2qcDuAZR0K57gtwWDbUgclNt5kMBZENZwTBZnQmnDMEE1 Sx2K/Ofl5L45YyE5y0h7bNNjZ45qEB7fbq4pD47VZ/q+wqUs1XkgyLwrZkA6PtcE3Vu0 MXqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Y+pbl/I8yc9+qiiBx4oS2dhGsqACGwpE/srodEThD5g=; fh=VLyDSxEFBkv0vhe3LU868VMhL5H8YsEeY0KW/Q5O5ZU=; b=HAOXrb2o/XBR3zRNq2hqziSElkZoi73+cXh5057We4zhrbb/OVfLft5c1EHD4xqSu/ hFBXP+9ajgQVCvCxQHoeWgg+ZRB283uePDk6mYOrPQQjfZsI0h3LQzWUa0Fmbwd9HkyI XOynEaeUwwo6qfIS6N5TiouuA4l8lakhYfDmatQWuuI9B0Vc3DHOuiOp2o3ZlC3Nis56 C7pNGw3isLi9D+dQk0NefoTc0vutDj/MISyjGTgFTfe4Ppc2XymjR2WKVNKEyKEF3sly hl7WXvrzkmIGSV9LwUjf834Zg1ut+5aSLzr2NBkMVJvH4IFcrRogCnP54m1bN1+VDZjZ JODA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="EZ/ByETh"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d9-20020a0cf0c9000000b0063cefebbd61si4047263qvl.106.2023.08.20.13.44.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Aug 2023 13:44:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="EZ/ByETh"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qXpHW-0004y7-Cx; Sun, 20 Aug 2023 16:44:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qXpHU-0004wo-0d for qemu-devel@nongnu.org; Sun, 20 Aug 2023 16:44:16 -0400 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qXpHR-0007kQ-Ef for qemu-devel@nongnu.org; Sun, 20 Aug 2023 16:44:15 -0400 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3a85b9c6ccdso216947b6e.0 for ; Sun, 20 Aug 2023 13:44:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692564252; x=1693169052; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y+pbl/I8yc9+qiiBx4oS2dhGsqACGwpE/srodEThD5g=; b=EZ/ByEThr2TXyaggw5E8gnyMRfZU7/PAzpvzHWpiTU4RWB62j4M96vPVyEILfEAOwt 25HUZSFGex1w06NTq4E5rObGyNdCel1IunzfvcpnUH9kM7FY/yAySFg6hXbewsgq9MrT duDUGxMVChEtMnIb3pJlr1z750/UlSoPr7CTgKO++YKPPB0FYkiL5JTYatfuJUnIL+QL xBs1XwdLtSkKzJd+LxIGSbR3+jUZGWShgO86SE56oqhOxlUvsBuLekZVaMnFnkUExRuX 5SA67ETOiO1fG3m0gtr7jJ+HHbpjqBu4s9lmgtJrAl1NgkAEiQ0hrAwPg7YePg8hRi+x wNBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692564252; x=1693169052; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y+pbl/I8yc9+qiiBx4oS2dhGsqACGwpE/srodEThD5g=; b=aq4Mzf8z3VaHij6qvRj1yGOp2tW5PgBt+PQYM4B3JpB/BWcntLqggkzRE15T4p4BTv yVvZmhqIaQoHL8p9VePbUzBbISlhC/3kCRsJ0OfCcDkFZT50voGjZbmjyDfqLTtHyU1H flZrMCYwZaGEg7DyJcscpcG0XFFLDyRXdxvW7lbh/p/OVwimvDwPo9DdNc3+XPAGNOeT hpp3Mknn7YEpX8TKCkO9CXRYAlisNxV1Atw0U8owU7r1Geu2+Hgy/v7FaG6h6demXZwI XzUNOOzxpYilTmPwMycVeD+sTu9y/gh0zm/RLNSadgFFSWaMvZzjw4sMDk/Q/RqdlRuO XtTQ== X-Gm-Message-State: AOJu0YxVt5xJ2IDqcvcbEqQHg1BZln6lllOibaT8VRt3Q2UCJ6j/nTEI opJN4dhDNFyftrmM1My9IlyaqctnynlXBKICDXs= X-Received: by 2002:a05:6808:1a0a:b0:3a7:4b9a:43c2 with SMTP id bk10-20020a0568081a0a00b003a74b9a43c2mr8484408oib.13.1692564251908; Sun, 20 Aug 2023 13:44:11 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:347d:4d37:bdd7:f5e5]) by smtp.gmail.com with ESMTPSA id c7-20020aa78c07000000b0064fde7ae1ffsm1430149pfd.38.2023.08.20.13.44.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 13:44:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, imp@bsdimp.com, kariem.taha2.7@gmail.com Subject: [PATCH 2/4] linux-user: Use WITH_MMAP_LOCK_GUARD in target_{shmat, shmdt} Date: Sun, 20 Aug 2023 13:44:06 -0700 Message-Id: <20230820204408.327348-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230820204408.327348-1-richard.henderson@linaro.org> References: <20230820204408.327348-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22e; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Move the CF_PARALLEL setting outside of the mmap lock. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 98 ++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 3aeacd1ecd..f45b2d307c 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -1017,9 +1017,8 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, { CPUState *cpu = env_cpu(cpu_env); abi_ulong raddr; - void *host_raddr; struct shmid_ds shm_info; - int i, ret; + int ret; abi_ulong shmlba; /* shmat pointers are always untagged */ @@ -1044,7 +1043,43 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, return -TARGET_EINVAL; } - mmap_lock(); + WITH_MMAP_LOCK_GUARD() { + void *host_raddr; + + if (shmaddr) { + host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); + } else { + abi_ulong mmap_start; + + /* In order to use the host shmat, we need to honor host SHMLBA. */ + mmap_start = mmap_find_vma(0, shm_info.shm_segsz, + MAX(SHMLBA, shmlba)); + + if (mmap_start == -1) { + return -TARGET_ENOMEM; + } + host_raddr = shmat(shmid, g2h_untagged(mmap_start), + shmflg | SHM_REMAP); + } + + if (host_raddr == (void *)-1) { + return get_errno(-1); + } + raddr = h2g(host_raddr); + + page_set_flags(raddr, raddr + shm_info.shm_segsz - 1, + PAGE_VALID | PAGE_RESET | PAGE_READ | + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); + + for (int i = 0; i < N_SHM_REGIONS; i++) { + if (!shm_regions[i].in_use) { + shm_regions[i].in_use = true; + shm_regions[i].start = raddr; + shm_regions[i].size = shm_info.shm_segsz; + break; + } + } + } /* * We're mapping shared memory, so ensure we generate code for parallel @@ -1057,65 +1092,24 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, tb_flush(cpu); } - if (shmaddr) { - host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); - } else { - abi_ulong mmap_start; - - /* In order to use the host shmat, we need to honor host SHMLBA. */ - mmap_start = mmap_find_vma(0, shm_info.shm_segsz, MAX(SHMLBA, shmlba)); - - if (mmap_start == -1) { - errno = ENOMEM; - host_raddr = (void *)-1; - } else { - host_raddr = shmat(shmid, g2h_untagged(mmap_start), - shmflg | SHM_REMAP); - } - } - - if (host_raddr == (void *)-1) { - mmap_unlock(); - return get_errno((intptr_t)host_raddr); - } - raddr = h2g((uintptr_t)host_raddr); - - page_set_flags(raddr, raddr + shm_info.shm_segsz - 1, - PAGE_VALID | PAGE_RESET | PAGE_READ | - (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); - - for (i = 0; i < N_SHM_REGIONS; i++) { - if (!shm_regions[i].in_use) { - shm_regions[i].in_use = true; - shm_regions[i].start = raddr; - shm_regions[i].size = shm_info.shm_segsz; - break; - } - } - - mmap_unlock(); return raddr; } abi_long target_shmdt(abi_ulong shmaddr) { - int i; abi_long rv; /* shmdt pointers are always untagged */ - mmap_lock(); - - for (i = 0; i < N_SHM_REGIONS; ++i) { - if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { - shm_regions[i].in_use = false; - page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); - break; + WITH_MMAP_LOCK_GUARD() { + for (int i = 0; i < N_SHM_REGIONS; ++i) { + if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { + shm_regions[i].in_use = false; + page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); + break; + } } + rv = get_errno(shmdt(g2h_untagged(shmaddr))); } - rv = get_errno(shmdt(g2h_untagged(shmaddr))); - - mmap_unlock(); - return rv; }