From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01594C48BCF for ; Sat, 12 Jun 2021 10:32:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6EE0D610A7 for ; Sat, 12 Jun 2021 10:32:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6EE0D610A7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:34768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ls0vy-0002vS-1M for qemu-devel@archiver.kernel.org; Sat, 12 Jun 2021 06:32:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ls0te-0001vx-Ps for qemu-devel@nongnu.org; Sat, 12 Jun 2021 06:29:46 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:38993) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ls0tb-00073S-Ui for qemu-devel@nongnu.org; Sat, 12 Jun 2021 06:29:46 -0400 Received: from [192.168.100.1] ([82.142.6.178]) by mrelayeu.kundenserver.de (mreue011 [213.165.67.103]) with ESMTPSA (Nemesis) id 1MUY9w-1ljJkR1sZM-00QRkr; Sat, 12 Jun 2021 12:29:39 +0200 Subject: Re: [PATCH] linux-user: Set CF_PARALLEL when mapping shared memory To: Richard Henderson , qemu-devel@nongnu.org References: <20210612060828.695332-1-richard.henderson@linaro.org> From: Laurent Vivier Message-ID: Date: Sat, 12 Jun 2021 12:29:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210612060828.695332-1-richard.henderson@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:UbM7qY/9X6HgSBUXigpx2ihcmUSsAiNoZQ1XPxwZOrEfepJJBvh CreppHBNZhKj03ibKTnnehg5B3wCe3lK9Z95XDAeaROk+TSTRTgP5K4SkvkrwLCDP5zzmix fVeRZ5nmNQTM69DGn/YKdp+qS2zku+yjYSDlbBhKPd8R2BdCqyZ7GR05gNyxLhFjnjoG9As IdNN15jyGVmJBDG4qGCmw== X-UI-Out-Filterresults: notjunk:1;V03:K0:nYq2iIF1yXc=:5XVEuCW/4by/raaE/Vlivu 5hRUfXhlRYHk2CTEpddIJhQiGp08SfP4EED5wXuvgiJrVYPqJdNxhbpfwN6SE5xhsgESYWhnc u+7U9kejG95xVfkawDD4vwWQTAmBDgaW+9G3IVvXfNVvWlCIWOpu7fCV/Dc3hQC8hyqFZDGzz lCWUpHblx4LFYgZRRpzQWgRGCVqif7GV8yosOzcXP988+3nwxNpT5XfKUs71GJBVqpKKgokO1 wEClcW199lJjSzXYsWP+Kwvli/bFHhvtvgRhdx0GApcER1JMenSeInrB/+OaVo1Zv6V0ry6po avYPLkxJkth+KbpRT9kICQ5NCLsJ+B/EQjm/HaIdp4gYqZpL1DSfJcA6rK5tFfYOUW0MpKpCu bXlXd3vHb6sydmLWuaU5snzkX2L+hE+5MJoxVNawkHe+wGV61ygRkn5jGtqj0UnPfR/H+1u8u V3udUTwYQwBQdd9VkjCRWZctSRhLaIp2L8DwjVWzezUdXoWXnjv+YaYo+a8/kaEBKQKMU3sAF O6czdRjrrRu9iDXzEReWMM= 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, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Le 12/06/2021 à 08:08, Richard Henderson a écrit : > 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 > --- > linux-user/mmap.c | 14 ++++++++++++++ > linux-user/syscall.c | 12 ++++++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/linux-user/mmap.c b/linux-user/mmap.c > index 7e3b245036..0e103859fe 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 974dd46c9a..54037db8d6 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 { > Applied to my linux-user-for-6.1 branch. Thanks, Laurent