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=-7.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 33CFCC433E0 for ; Sun, 31 Jan 2021 23:02:45 +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 908E764E09 for ; Sun, 31 Jan 2021 23:02:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 908E764E09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6Ljv-0005f1-G4 for qemu-devel@archiver.kernel.org; Sun, 31 Jan 2021 18:02:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6Lit-0005Cw-TZ for qemu-devel@nongnu.org; Sun, 31 Jan 2021 18:01:39 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:34960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l6Lir-0002It-7j for qemu-devel@nongnu.org; Sun, 31 Jan 2021 18:01:39 -0500 Received: by mail-pl1-x629.google.com with SMTP id g3so8953273plp.2 for ; Sun, 31 Jan 2021 15:01:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=zD1Hq5ytfdhxRrB45gBVm3J7jB2oS2KNPSSHD/U9XlE=; b=W+3/wes7RkFRH9wO/jDftNL5dSWy5xsTbqG1FmnxDi7u1IN6HT6QIj/eh1joTHDmLS orhqPNOlZA3t0W1mUzwVwvUb/yTOsFIr6ilXHmXPvned79hrYuA1XCxRkFyPVXQxNsgM lIlP5Unoa5oz/OqlqqnNuvzDVf2N72a7PmSc6Pst28QGzeEcK6uuhb8nGlJUv1nTDdul MirY8MIShUij/d75JaZn/FyKf+TuGXJuvxqMVtNxXBfmZMRcVCcmpftb6P+uDTiWfSwF F/h27f5IR8OS/YxjkZrnepWqLL/n+JQomXSoPe8e+2Lq/W4IzzJMvTQGRe7Yo/gpIylp NiuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zD1Hq5ytfdhxRrB45gBVm3J7jB2oS2KNPSSHD/U9XlE=; b=ZHg7ismDufTIx+u3Ff5l5BQyB63s7nu6N8ksjWEIxSE4HqcCHMI5QkH8RwwodVr795 +5mB3JqrvqAKmrxRpEBYpW1L8UxIVzyB2HBBuLXA8ux7W4f3KG9dulab1wynBOQM+IoD 2EuY3gGR61CI8A/i3pmjOxQ0KVLO7iLh5Q8iGgHVKW5SoD+VXLFXyd3+5BaTDVn6TOIP pmEqJczbSlFStfbBL4wiW8RVqIsLi9SzJd21R12NNft+vrhv0f+UFVMzkF+TGfImsZDs Hg1L6CZUP3OTmPa/aUztBew1BeRBXQ1uPGmEQxE65eR6qn8iQT+kf50iCv9ADI0tgDY6 lBMQ== X-Gm-Message-State: AOAM533+ti1p1MhCm+qpe8xtISKihmeRr5sZRFBhAgkryiBLThKiESbg rLPD8gN27si83vtQrFphlzy7vw== X-Google-Smtp-Source: ABdhPJxs3BdhacNLzOMGvIUoUT81vaZD3rRDkWrjtsLyDLbLbAQKrL+fPZzyxZW/kvp20Nuh9iFQ0Q== X-Received: by 2002:a17:90b:3805:: with SMTP id mq5mr14506299pjb.93.1612134094649; Sun, 31 Jan 2021 15:01:34 -0800 (PST) Received: from [192.168.3.43] (cpe-66-27-222-29.hawaii.res.rr.com. [66.27.222.29]) by smtp.gmail.com with ESMTPSA id 130sm15761771pfb.92.2021.01.31.15.01.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 31 Jan 2021 15:01:33 -0800 (PST) Subject: Re: [QUESTION] tcg: Is concurrent storing and code translation of the same code page considered as racing in MTTCG? To: Liren Wei , "qemu-devel@nongnu.org" References: <60169742.1c69fb81.90ae8.cdc6SMTPIN_ADDED_BROKEN@mx.google.com> From: Richard Henderson Message-ID: Date: Sun, 31 Jan 2021 13:01:29 -1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <60169742.1c69fb81.90ae8.cdc6SMTPIN_ADDED_BROKEN@mx.google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 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, NICE_REPLY_A=-0.079, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?Q?Alex_Benn=c3=a9e?= , Peter Maydell Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 1/31/21 1:38 AM, Liren Wei wrote: > However, similar to the situation described in: > https://lists.nongnu.org/archive/html/qemu-devel/2018-02/msg02529.html > > When we have 2 vCPUs with one of them writing to the code page while > the other just translated some code within that same page, the following > situation might happen: > >    vCPU thread 1 - writing      vCPU thread 2 - translating >    -----------------------      ----------------------- >    TLB check -> slow path >      notdirty_write() >        set dirty flag >      write to RAM >                                 tb_gen_code() >                                   tb_page_add() >                                     tlb_protect_code() > >    TLB check -> fast path >                                       set TLB_NOTDIRTY >      write to RAM > executing unmodified code for this time >                                 and maybe also for the next time, never >                                 re-translate modified TBs. > > > My question is: >   Should the situation described above be considered as a bug or, >   an intended behavior for QEMU (, so it's the programmer's fault >   for not flushing the icache after modifying shared code page)? Yes, this is a bug, because we are trying to support e.g. x86 which does not require an icache flush. I think the page lock, the TLB_NOTDIRTY setting, and a possible sync on the setting, needs to happen before the bytes are read during translation. Otherwise we don't catch the case above, nor do we catch CPU1 CPU2 ------------------ -------------------------- TLB check -> fast tb_gen_code() -> all of it write to ram Also because of x86 (and other architectures in which a single instruction can span a page boundary), I think this lock+set+sync sequence needs to happen on demand in something called from the function set defined in include/exec/translator.h That also means that any target/cpu/ which has not been converted to use that interface remains broken, and should be converted or deprecated. Are you planning to work on this? r~