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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 605E7C54E58 for ; Fri, 15 Mar 2024 11:25:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r+zweWCKYOA2GSGthG+qcrR29DpKWxi+JaM/9aPB3Uw=; b=XvLWTO2kpmUtOi puCTQ29eb162K4MF1a8dsfeRT8EiqhJXPpBzPlbUit+H8pYyUK50PmZRjJqdVMB59P7n+BGKP+PYk qeyeWUpdbjQOUXKZnnwzXziO0RmvjmWiZKNyCy9cSvM4LLP20jsBo2sUDaS/bMsO5Av4xrpPUZxIf U7u96ZM88KxIMCOX805DeOc1tjOsKiXyyrUTDhWN6L9LIWFkSydWzMOD7MvPCckQeo7HTqPAI3yW5 1V5LFaOLMgj/1qLKqZfy1k4j/I00c75zHWu8moNZEja9XT4ZbUwrtfXnS5sFcc0BoyX0J5CkLc6xd 5VO1CMAF734Yki/kyEsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl5gA-000000001Mz-1tMd; Fri, 15 Mar 2024 11:24:50 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rl5g8-000000001Ly-0UCS for linux-arm-kernel@lists.infradead.org; Fri, 15 Mar 2024 11:24:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710501886; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E5BzWgrmdgiGxq+PlZflG+BHDXAH3VOatC+yV3V4Mnk=; b=LqE8+0FnLPIGae3x7zI0v1EJ5WswsvKPs2OGxi806Lqlja5I/TrEOdP5rXS+ZDGSFqeXRD XM/Bc3vhXSwEDLjnfv6aDH1epGTCt3zkQcl5w2Ay3d3to982743x8KuRlLTHy//BSbQ8U/ 7glDbPOhGBkEq4Ri8hA6DbIpr0HEuTs= Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-660-cDdtjsRRPpK5yGwmtRq7yg-1; Fri, 15 Mar 2024 07:24:45 -0400 X-MC-Unique: cDdtjsRRPpK5yGwmtRq7yg-1 Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-6e6a1625e4bso2266689b3a.1 for ; Fri, 15 Mar 2024 04:24:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710501884; x=1711106684; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E5BzWgrmdgiGxq+PlZflG+BHDXAH3VOatC+yV3V4Mnk=; b=tivSp3iLlNVqO7T9wJt7pvyvXrNgx0175YCh4VNnjT1Bkj5ES07DEA5h7Q5aR/noB1 1eAb2xBg3GlVt9V/QnpZGNtA8bJi53XMuUCk3lc65BHgnct9CBurMvC4lH7VPlYTPTQb SF1SPCDF+FTw4ag7T2Fe7pmPMy9jgFrCd0CtOueycL0DyKnPPb2bzUUfm5oAKDg004IV IjLrKfnkrGNASvu7QjR8QD1f7spp9GlDl7yi+nyiPPt5mQw85qoXFjwif4HE/KnsO8qO w/ur/rvn55FxL6YGrD30isd136rV7rdWLZodBLoHqWxM8N+4mnC+xZ5bXeg+R6lYxYJ/ 2vvw== X-Forwarded-Encrypted: i=1; AJvYcCXFnBmzPgti6su59N5SsDHqjjeyadGBtEGHGgiH8rxP6HQzZfZ3p7kyPbf/ku/kszUxN6LEvmFJzNLW9m6zoBGijhip3dGgKGkEy4CxKvChfe939s4= X-Gm-Message-State: AOJu0YwSERyrz/ZnaoZMdqt6kBdjpuKkHFMr478Amv/mq9aSmiICvail 6YBBCyopktm7WsVWwOtIaIbCHSZFlhs/NGiH412DTygjRRqqhwXVrIaqfiQ9uYblM9c6k+GDiq1 3c/VoR8s+0k5J8PXWwGLLvOaOM7Ry5Tq/RIINv2ZbxyKZzrQlHs7rw4+k+utkI44/iVzQXHT8 X-Received: by 2002:a05:6a00:b96:b0:6e3:b1b3:139f with SMTP id g22-20020a056a000b9600b006e3b1b3139fmr3397434pfj.17.1710501883979; Fri, 15 Mar 2024 04:24:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFv6UByGgC+juEfECmFf0FkqYVVrr5jER7l/udV8Oy/Bm8qarOlLsSpAREhnDHVoTzcBzZzsg== X-Received: by 2002:a05:6a00:b96:b0:6e3:b1b3:139f with SMTP id g22-20020a056a000b9600b006e3b1b3139fmr3397425pfj.17.1710501883695; Fri, 15 Mar 2024 04:24:43 -0700 (PDT) Received: from [192.168.68.51] ([43.252.115.31]) by smtp.gmail.com with ESMTPSA id kt2-20020a056a004ba200b006e6233563cesm3131483pfb.218.2024.03.15.04.24.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 Mar 2024 04:24:43 -0700 (PDT) Message-ID: <66e12633-b2d6-4b9a-9103-bb79770fcafa@redhat.com> Date: Fri, 15 Mar 2024 21:24:36 +1000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] virtio_ring: Fix the stale index in available ring To: "Michael S. Tsirkin" Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, yihyu@redhat.com, shan.gavin@gmail.com, Will Deacon , Catalin Marinas , linux-arm-kernel@lists.infradead.org, mochs@nvidia.com References: <20240314074923.426688-1-gshan@redhat.com> <20240314040443-mutt-send-email-mst@kernel.org> <9b148de7-b687-4d10-b177-5608b8dc7046@redhat.com> <20240314074216-mutt-send-email-mst@kernel.org> <23dc6d00-6a57-4ddf-8611-f3c6f6a8e43c@redhat.com> <20240314085630-mutt-send-email-mst@kernel.org> <63002c24-8117-458f-84c7-fa4f7acd8cc6@redhat.com> <20240315065318-mutt-send-email-mst@kernel.org> From: Gavin Shan In-Reply-To: <20240315065318-mutt-send-email-mst@kernel.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240315_042448_275701_D10DC16B X-CRM114-Status: GOOD ( 18.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 3/15/24 21:05, Michael S. Tsirkin wrote: > On Fri, Mar 15, 2024 at 08:45:10PM +1000, Gavin Shan wrote: >>>> Yes, I guess smp_wmb() ('dmb') is buggy on NVidia's grace-hopper platform. I tried >> to reproduce it with my own driver where one thread writes to the shared buffer >> and another thread reads from the buffer. I don't hit the out-of-order issue so >> far. > > Make sure the 2 areas you are accessing are in different cache lines. > Yes, I already put those 2 areas to separate cache lines. > >> My driver may be not correct somewhere and I will update if I can reproduce >> the issue with my driver in the future. > > Then maybe your change is just making virtio slower and masks the bug > that is actually elsewhere? > > You don't really need a driver. Here's a simple test: without barriers > assertion will fail. With barriers it will not. > (Warning: didn't bother testing too much, could be buggy. > > --- > > #include > #include > #include > #include > > #define FIRST values[0] > #define SECOND values[64] > > volatile int values[100] = {}; > > void* writer_thread(void* arg) { > while (1) { > FIRST++; > // NEED smp_wmb here __asm__ volatile("dmb ishst" : : : "memory"); > SECOND++; > } > } > > void* reader_thread(void* arg) { > while (1) { > int first = FIRST; > // NEED smp_rmb here __asm__ volatile("dmb ishld" : : : "memory"); > int second = SECOND; > assert(first - second == 1 || first - second == 0); > } > } > > int main() { > pthread_t writer, reader; > > pthread_create(&writer, NULL, writer_thread, NULL); > pthread_create(&reader, NULL, reader_thread, NULL); > > pthread_join(writer, NULL); > pthread_join(reader, NULL); > > return 0; > } > Had a quick test on NVidia's grace-hopper and Ampere's CPUs. I hit the assert on both of them. After replacing 'dmb' with 'dsb', I can hit assert on both of them too. I need to look at the code closely. [root@virt-mtcollins-02 test]# ./a a: a.c:26: reader_thread: Assertion `first - second == 1 || first - second == 0' failed. Aborted (core dumped) [root@nvidia-grace-hopper-05 test]# ./a a: a.c:26: reader_thread: Assertion `first - second == 1 || first - second == 0' failed. Aborted (core dumped) Thanks, Gavin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel