From patchwork Mon Jun 21 11:04:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 464502 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp2456308jao; Mon, 21 Jun 2021 04:07:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztjhAtGG5c/9hyZ96U6xhDefvt5QcbVTCJgvd4YK3BUonGIt+f5t7CxC+po4RtrWoWWwuY X-Received: by 2002:a1f:308a:: with SMTP id w132mr13652652vkw.7.1624273658736; Mon, 21 Jun 2021 04:07:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624273658; cv=none; d=google.com; s=arc-20160816; b=mETCjJuvvqqi45lkQ01XxOU5wJrvzhhX4Uq9bPZ3e2JWGH7wpYQ+7xip9+GyUFe7xB vk7XWGSWI8voHiHM5ypPbCWYba0dwrqNZAK0bIzHzsi32Dj7q4uvGGqe2W1eO+zToQv1 ZnYtPmvLbYAzeyMn54tMpm1niVGU46RDV0l6lGKUpRT9Y9MsaLFHfHR94EvOqT1KS7CW frA6FpdCHjixwF3F82e84ct7scSfotQTn+HUfe2SSFWNZezeriU2xns3Z9Sc9EzIXxXy Vz1V2iV2x6T4aTvr2v/igRoApym2/xDpWTwRBFpyg5wg3HP3z98B3pA4iWiAdSyjAVMD 1Y4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from; bh=GVJxooKk4xi6yX5o8wJUzuDsxGS/ScrNnjt1nvmf3O4=; b=BrhCl6Bf5+5eN44yQEniOeglZ19D33Qq503oyU4loDW8gtbb9UmK8UvbpEH2JYigof lRtHEc46txE1l3BpJIUidmR1yH5S+MAzz2PXuuxU6/5VpQW+jTy2kzio0rHCV4yTBRVF eyknmDXGeEd0BjNiWIICKEE0DnxwjY1zC9z8qEsRRwvHvOVFfy7uqGTb4+46eBuN9YOX yc9M8+Z0/OLwv7cTsSXpoAX/PKGZ1zVrTtTN2bJiW3+Fkfa97h/zODM02i/eoWwPSD1j KDpr/gZRAf4HJ5NB+gIRkGQJPAos357ayGv2Y3UpAYCyEkCC0+FzugaoHGKWH9KZPVfR l4eg== ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p3si2393737vsq.421.2021.06.21.04.07.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Jun 2021 04:07:38 -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; 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" Received: from localhost ([::1]:47094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lvHmE-00005p-4u for patch@linaro.org; Mon, 21 Jun 2021 07:07:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvHjY-0002o9-FE for qemu-devel@nongnu.org; Mon, 21 Jun 2021 07:04:53 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:53975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvHjV-0003uQ-Sc for qemu-devel@nongnu.org; Mon, 21 Jun 2021 07:04:51 -0400 Received: from quad ([82.142.1.74]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MIMOy-1m0jn82TFk-00EPFp; Mon, 21 Jun 2021 13:04:46 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 1/9] linux-user: Set CF_PARALLEL when mapping shared memory Date: Mon, 21 Jun 2021 13:04:37 +0200 Message-Id: <20210621110445.231771-2-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210621110445.231771-1-laurent@vivier.eu> References: <20210621110445.231771-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:UFy6xt4K53iFDMglBPtNG7ol1kK5/42StTASrSex5sojzRu7qj8 mG4rI7zJFwLktBXqHCK54Ru/9lw1ZKB1b1WtGnezZWExFG3v4lnw1PmlJn7yVToO0bZ+9Oo wN5d7jxzu/mdKrRlIFKrMdU7yrlBaIF2rnFEzN69xmBBq0w8tFGbGn7MQCbvso8riGXeoHg yHr60vSFjctrzZWkzvgyw== X-UI-Out-Filterresults: notjunk:1; V03:K0:uREM49oludY=:Jgjm4IxxxbKlgMKN/S2go0 azoiuC/5kE0npg7Ew+5M1m9mBNwtcWNwTjrz8V6uYE2NiI2ek9S8ItEg5/5uIbaLcmUu64B8L T3tPzURYVKjmAtSk8C3I1Ufe2J8aDyF288g0hhEeRqiIjPmz7FbGdsOU+AshFaT/HbSWH+NfE Jzyus/Ggh4kHGRcYgnEJey1PA5IgdDQC0/EdEiLtKljxLRLgGyR+yqlb6BcadrSckZx04V6Yz KEL41DqSLrIE/DE55wBJrwcggemmbVN+SDBhJtQFGGFOfUlGi1XUNsq4f3cY3ds27il8wkh6A C/AkaahK+sbXiHgQWBm2fKiPbHfEaiVTbgXrXbSNhquy3y39tGIgF52YnjBvoYW2occ+wJ4le 3JnLKzh0vpTMLG5VZfvFQe7XjvZYNgs2ivG7pMSCRJxLhjzT+akRts5aXViidgRm1aRRFir5m jUX2/w2oMUJcQHGyQcbOKuxkDCdBt4YyxAlshnx5ABuKav6ZrNm/WA5U/++XZ6n0XXCJKy7LD tzT2rQrHVWYd/6WUMrMHb0= Received-SPF: none client-ip=212.227.126.131; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signal the translator to use host atomic instructions for guest operations, insofar as it is possible. This is the best we can do to allow the guest to interact atomically with other processes. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/121 Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Message-Id: <20210612060828.695332-1-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/mmap.c | 14 ++++++++++++++ linux-user/syscall.c | 12 ++++++++++++ 2 files changed, 26 insertions(+) -- 2.31.1 diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 7e3b2450368a..0e103859fed8 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -451,6 +451,20 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } + /* + * If we're mapping shared memory, ensure we generate code for parallel + * execution and flush old translations. This will work up to the level + * supported by the host -- anything that requires EXCP_ATOMIC will not + * be atomic with respect to an external process. + */ + if (flags & MAP_SHARED) { + CPUState *cpu = thread_cpu; + if (!(cpu->tcg_cflags & CF_PARALLEL)) { + cpu->tcg_cflags |= CF_PARALLEL; + tb_flush(cpu); + } + } + real_start = start & qemu_host_page_mask; host_offset = offset & qemu_host_page_mask; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 974dd46c9a17..54037db8d66d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4603,6 +4603,7 @@ static inline abi_ulong target_shmlba(CPUArchState *cpu_env) static inline abi_ulong do_shmat(CPUArchState *cpu_env, int shmid, abi_ulong shmaddr, int shmflg) { + CPUState *cpu = env_cpu(cpu_env); abi_long raddr; void *host_raddr; struct shmid_ds shm_info; @@ -4633,6 +4634,17 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, mmap_lock(); + /* + * We're mapping shared memory, so ensure we generate code for parallel + * execution and flush old translations. This will work up to the level + * supported by the host -- anything that requires EXCP_ATOMIC will not + * be atomic with respect to an external process. + */ + if (!(cpu->tcg_cflags & CF_PARALLEL)) { + cpu->tcg_cflags |= CF_PARALLEL; + tb_flush(cpu); + } + if (shmaddr) host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); else {