Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2143171lqo; Mon, 13 May 2024 09:00:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXc1Xt8QFpYn0yfeb5i/VSOZg5+6dU+Ha2k5LzV/KeO+D4LHq4WfOxhYm/FTdO6+GoLSm1DOPmqWKnS1V1PWpoq7DgWqaX9pA0+tQpoxA== X-Google-Smtp-Source: AGHT+IFkALbsG33M9VE1gm4vsblUQ1Gwei7Lr9d19ZvG+ZcP5BkHKdsxCf+uGGN50DQcs2sVm0G/ X-Received: by 2002:a05:6214:5f0c:b0:69b:5a87:21cc with SMTP id 6a1803df08f44-6a168146387mr130462846d6.13.1715616011112; Mon, 13 May 2024 09:00:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715616011; cv=pass; d=google.com; s=arc-20160816; b=nD34CMB+jJSswUrFlnQJOADK4x3ZtMb5tcWrgb6El6YKOu2MYb3iW60AibK+Vt3HW9 l6U0sGcLw1JTC0Zz77OuPp3i7xYpoxhtEzOgDJPA0UDwjqGLj/ktkqzHn2pE+rz4Xmml juk4rd0rCMSqmpnmy3iMG2okou5QEaEIN7ofMdDMXqFBS6/7Vi68aVjrII+94WhugOg+ y1pUENnx57S3F90C0JJ9kOMzc24cthRWc2yKqyFeOwfSybm0dgkzpPGaObMgWhJvcBWZ 5MM9OK0A9bzdPlqvs7P3MHnLRVUoPKrBMev6SG2jO5btW5yRa+A4oclEikd7Zw0roeuD ARTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=Hiz9d+UkfTnuOJsCCK1RJ7H42O2YvySBkboss9W12RQ=; fh=IrmzTZaGmUDWw+2+HUwS15Sh95pguzFIC/GVtfluTYY=; b=NVwSeNrqPXotKs5a0iSY+dbFXGVsV+5nFz0o1qNecItGzCNZCjgbsbRhpYcCxUoadw mwHkJdJTGIffQgXYSwcIry7+QlSnJ+SFEicVs27J6b4jnG9YJEpm4/cTZCTYz/DEzlvq nFZigyVf7isf0mfvHJqG8as2k4NVZOmpCsWyR+dwwyhYc8imKUdaysX+L27+fZGKjZmE r/KZjKFay3c5d0P5jIZpbCb0thVgGvYWAN7Yq6OOSJPbk8h7Qy2iQ2Rrte5WLb7rZD3H 6XftH013iUt3mM//92KgMZENbLMMHwzUHd3pD5ldnqr4AZLgciAjucXjKVB93ewfffW1 uAAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MxzXKmne; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-177795-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177795-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f2ed9fdsi98665206d6.472.2024.05.13.09.00.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 09:00:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177795-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MxzXKmne; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-177795-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177795-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C406E1C229A2 for ; Mon, 13 May 2024 16:00:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF15115532F; Mon, 13 May 2024 16:00:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MxzXKmne" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2598154423; Mon, 13 May 2024 16:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715616003; cv=none; b=fJzTlJQYpQssTehy1lT7xsM8yvQubxj/SVCgXz30VY0yrQ6prPr7vV4/C8G4XrtwgUD1+3Sq1jLeM9Grcf9QV9Dl7iv66E/nQ5xZG8729uVqeRPoCCRlkJj6h4TBQmM1iHeaUTdDDVnny/QK/Jbg9kA5KIFF96RPCR3SiGuvOtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715616003; c=relaxed/simple; bh=k2zBO/pJSJJXeGK42+0QmyGneLPTwY0zTIWbg5TCzdo=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=ao1COASCgMuLQ2rJuQZEXx89twU7V+2NcbMir1DBxJ3hxjuVspQOzvAZq4ionwKNz9Df1IbV8ON5WU/SJFQA5kQDBx1cKirC564yZJqlygo2LdPK3Yzr0XWr+yKRwhq3qtqSB4gmsGXQ5MIzHaSeHx9BscUmkQFUv3gIOKBWiBQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MxzXKmne; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FA2CC113CC; Mon, 13 May 2024 16:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715616002; bh=k2zBO/pJSJJXeGK42+0QmyGneLPTwY0zTIWbg5TCzdo=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=MxzXKmne4Q0q7RCI54pTOJidMsN+RsKt47FFBV47KtxcReD+agKNZ6QuIZwlpKDFJ r7yNAphTKeaym1EwZwOCBxaOgl5UEw6eU/Wqgt7Az4e/Cb6LQHLV8/zZwH+cr39xBd Zr/NVoF7f5wlVCSibtXWRnuXdQjfxA57MiNn3SE1Hfcot+QSY+2klBOWg35QQTVkgT vcXW86bdIXkeMIMJbvSlybzmJOVEz5qLXccq8tZYcsw1GyYNgEWonvAhs7vSqpAFqV MgdAUAzCSspNpFY3ExqbVGhDRCNGnDaf2xfHBtzPuLk9oRzZN03heKLaKSOCbqjciN WpY42C+27A/yw== From: Puranjay Mohan To: Naveen N Rao Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , Hari Bathini , bpf@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, paulmck@kernel.org Subject: Re: [PATCH bpf v3] powerpc/bpf: enforce full ordering for ATOMIC operations with BPF_FETCH In-Reply-To: References: <20240513100248.110535-1-puranjay@kernel.org> Date: Mon, 13 May 2024 15:59:59 +0000 Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Naveen N Rao writes: > On Mon, May 13, 2024 at 10:02:48AM GMT, Puranjay Mohan wrote: >> The Linux Kernel Memory Model [1][2] requires RMW operations that have a >> return value to be fully ordered. >> >> BPF atomic operations with BPF_FETCH (including BPF_XCHG and >> BPF_CMPXCHG) return a value back so they need to be JITed to fully >> ordered operations. POWERPC currently emits relaxed operations for >> these. >> >> We can show this by running the following litmus-test: >> >> PPC SB+atomic_add+fetch >> >> { >> 0:r0=x; (* dst reg assuming offset is 0 *) >> 0:r1=2; (* src reg *) >> 0:r2=1; >> 0:r4=y; (* P0 writes to this, P1 reads this *) >> 0:r5=z; (* P1 writes to this, P0 reads this *) >> 0:r6=0; >> >> 1:r2=1; >> 1:r4=y; >> 1:r5=z; >> } >> >> P0 | P1 ; >> stw r2, 0(r4) | stw r2,0(r5) ; >> | ; >> loop:lwarx r3, r6, r0 | ; >> mr r8, r3 | ; >> add r3, r3, r1 | sync ; >> stwcx. r3, r6, r0 | ; >> bne loop | ; >> mr r1, r8 | ; >> | ; >> lwa r7, 0(r5) | lwa r7,0(r4) ; >> >> ~exists(0:r7=0 /\ 1:r7=0) >> >> Witnesses >> Positive: 9 Negative: 3 >> Condition ~exists (0:r7=0 /\ 1:r7=0) >> Observation SB+atomic_add+fetch Sometimes 3 9 >> >> This test shows that the older store in P0 is reordered with a newer >> load to a different address. Although there is a RMW operation with >> fetch between them. Adding a sync before and after RMW fixes the issue: >> >> Witnesses >> Positive: 9 Negative: 0 >> Condition ~exists (0:r7=0 /\ 1:r7=0) >> Observation SB+atomic_add+fetch Never 0 9 >> >> [1] https://www.kernel.org/doc/Documentation/memory-barriers.txt >> [2] https://www.kernel.org/doc/Documentation/atomic_t.txt >> >> Fixes: 65112709115f ("powerpc/bpf/64: add support for BPF_ATOMIC bitwise operations") > > As I noted in v2, I think that is the wrong commit. This fixes the below Sorry for missing this. Would this need another version or your message below will make it work with the stable process? > four commits in mainline: > Fixes: aea7ef8a82c0 ("powerpc/bpf/32: add support for BPF_ATOMIC bitwise operations") > Fixes: 2d9206b22743 ("powerpc/bpf/32: Add instructions for atomic_[cmp]xchg") > Fixes: dbe6e2456fb0 ("powerpc/bpf/64: add support for atomic fetch operations") > Fixes: 1e82dfaa7819 ("powerpc/bpf/64: Add instructions for atomic_[cmp]xchg") > > Cc: stable@vger.kernel.org # v6.0+ Thanks, Puranjay