Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30287451rwd; Thu, 6 Jul 2023 03:51:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlFN8F/UYaqn8Wm8hN1Fped3AHvRR5z27ZUa2VFRnetG99MjQjUHJi2VdGdbzwgh3ErAiic4 X-Received: by 2002:a17:90a:6748:b0:263:5c6a:1956 with SMTP id c8-20020a17090a674800b002635c6a1956mr958949pjm.25.1688640698566; Thu, 06 Jul 2023 03:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688640698; cv=none; d=google.com; s=arc-20160816; b=iPETMjuVkFa33YSILw1ewDU7ScY1tum4tvJmM6k1+fv+8Vz+KdcdA3hIbAZzV7yVYT DdNkrxja6XKwH3fK7QsQIkA9Mqkq/IuGae1b084TLpLnyFUwFcmvB7/JegYNIrQSlVWn dh2Naca4AWKP0KSSc+BoW57qGvlzw+vzfX6VlTnmL3XnWJci6xq7oJXhtz8C3SyoPu/F A2nLkWlGKYi/Rvcl7MN+oonXp6c3mdudEbVFVx2+kQ7XTHgDcinZXwW6CTTQL1vLeDXk 3aQAT3+wcD8J17vREBPBgLkcLPBq1DrIxPO/xV+afWuPTN2eZvj2tcAzGvvWzNVJTNR3 e08Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=pWSRtLdme6FJ70IV4C93Q8VXnr5yFBXVr0WOwSgrr+g=; fh=0oytOtpLO7pJCUBpT9mUpydN5BXGbXVn6b+8gm8X9vs=; b=XyinQuOAF99k9bkziraH108FxQ/In7VAT22HbTLumgp3TEajTco1fQ+egwqGNf1kq8 1SFLEIjBGM7dfY7Qd31jn0jAFHGv2uHujdiVWUBTLzsfInc2+KKWUtee3AHWOf5L9tdD OVTNPlwKU3Ga8Ul9NX2kfXT1gE2ZWzHK6fBcVVkpiyviKxmupPnpDpoalwEZ/u/Yk33J cVKwPVxV0Z3GJy/jUZWAnX+7LMcX9d6aT5gedg5csRAf7rg5tI1g3AEaN3BFXRdk90yi wWrcMgDrSbkQk3WQL6j2zswVCDeskAdBM6Z6GQhbxSU0eNVnsVY5XagFxOn4NBluenzo mfSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=erTQvC8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r20-20020a6560d4000000b0054201a3f08dsi1170088pgv.592.2023.07.06.03.51.25; Thu, 06 Jul 2023 03:51:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=erTQvC8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230436AbjGFK3O (ORCPT + 99 others); Thu, 6 Jul 2023 06:29:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbjGFK3M (ORCPT ); Thu, 6 Jul 2023 06:29:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 748E2123 for ; Thu, 6 Jul 2023 03:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688639307; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pWSRtLdme6FJ70IV4C93Q8VXnr5yFBXVr0WOwSgrr+g=; b=erTQvC8h8rS8cXO9U5Nx9olT0qHZXZiqPST8Q/hMo/X3U+iwO/Bo66/qMb1O5lS6TbRb91 JRy0hjwMDI6Smowb8ogvtTEYudH8pdFWEu+jH8MHfmohRpWFZZvTrAY2+EM7Mysfb0H0ae BuQ5YvXYINOpnEf2nwNYuL4KkiNTHW8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-194-C_ZbWKdJPQad0nV88K3J4w-1; Thu, 06 Jul 2023 06:28:24 -0400 X-MC-Unique: C_ZbWKdJPQad0nV88K3J4w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07D42101A54E; Thu, 6 Jul 2023 10:28:24 +0000 (UTC) Received: from localhost (unknown [10.42.28.237]) by smtp.corp.redhat.com (Postfix) with ESMTP id C75BEF5CE3; Thu, 6 Jul 2023 10:28:23 +0000 (UTC) Date: Thu, 6 Jul 2023 11:28:23 +0100 From: "Richard W.M. Jones" To: Richard Henderson Cc: Peter Zijlstra , Arnd Bergmann , Naresh Kamboju , Anders Roxell , Daniel =?iso-8859-1?Q?D=EDaz?= , Benjamin Copeland , linux-kernel@vger.kernel.org, x86@kernel.org, Paolo Bonzini Subject: Re: qemu-x86_64 booting with 8.0.0 stil see int3: when running LTP tracing testing. Message-ID: <20230706102823.GO7636@redhat.com> References: <2d7595b1-b655-4425-85d3-423801bce644@app.fastmail.com> <20230621160655.GL2053369@hirez.programming.kicks-ass.net> <20230704074620.GA17440@redhat.com> <20230705162830.GC17440@redhat.com> <20230705215008.GD17440@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 06, 2023 at 07:30:50AM +0100, Richard Henderson wrote: > On 7/5/23 22:50, Richard W.M. Jones wrote: > >tb_invalidate_phys_range_fast() *is* called, and we end up calling > > tb_invalidate_phys_page_range__locked -> > > tb_phys_invalidate__locked -> > > do_tb_phys_invalidate > > > >Nevertheless the old TB (containing the call to the int3 helper) is > >still called after the code has been replaced with a NOP. > > > >Of course there are 4 MTTCG threads so maybe another thread is in the > >middle of executing the same TB when it gets invalidated. > > Yes. > > >tb_invalidate_phys_page_range__locked goes to some effort to check if > >the current TB is being invalidated and restart the TB, but as far as > >I can see the test can only work for the current core, and won't > >restart the TB on other cores. > > Yes. > > The assumption with any of these sorts of races is that it is "as > if" the other thread has already passed the location of the write > within that block. But by the time this thread has finished > do_tb_phys_invalidate, any other thread cannot execute the same > block *again*. > > There's a race here, and now that I think about it, there's been mail about it in the past: > > https://lore.kernel.org/qemu-devel/cebad06c-48f2-6dbd-6d7f-3a3cf5aebbe3@linaro.org/ > > We take care of the same race for user-only in translator_access, by > ensuring that each translated page is read-only *before* performing > the read for translation. But for system mode we grab the page > locks *after* the reads. Which means there's a race. > > The email above describes the race pretty clearly, with a new TB > being generated before the write is even complete. > > It'll be non-trivial fixing this, because not only do we need to > grab the lock earlier, there are ordering issues for a TB that spans > two pages, in that one must grab the two locks in the correct order > lest we deadlock. Yes I can see how this is hard to fix. Even if we just lock the page containing the first instruction (which we know) before doing translation, we still have a problem when entering tb_link_page() where we would need to only lock the second page, which might cause ordering issues. How about a new per-page lock, which would be grabbed by do_tb_phys_invalidate() and tb_gen_code(), just on the first instruction? It would mean, I think, that no page can be having TBs invalidated and generated at the same time. Or something like scanning the bytes as they are being translated, generate a secure-ish checksum, then recheck it after translation and discard the TB if the code changed. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW