Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2950595rdb; Fri, 22 Sep 2023 13:04:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjgO7Z6+T8E7og5sezeY7CzkS8bbyVwvkraBBO7AE65yMYh+cFX3T2L8l3iu+TIp3jRAGo X-Received: by 2002:a05:6a20:8417:b0:138:836c:5370 with SMTP id c23-20020a056a20841700b00138836c5370mr689809pzd.42.1695413040105; Fri, 22 Sep 2023 13:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695413040; cv=none; d=google.com; s=arc-20160816; b=eY3UlFqVnO4Ruj1CT16YnzkFeMPyk+0z43Pa0lXkMAxtYrSMzd1/mWFQ/85R4ziqhj fECc58IbaSAWzhehS3LI1Z5wlexNb4/V/KHdaNN9lC8QpyayTFjwRjXgoxrD7O3r1Yl8 Wjwz1CZXMdm2aKTHyn/EAomBoGWQK1WOqYwsgiLNVO3nFCpp1Sn76yHSL5HpVKN75zXs dfhJFCnKcD6HTwr0fxyYPSOSZRF9EoZUXnQ0YTtPlXptGJkMWi305WzlxMUsbzr4OdhH wYKY/U/FbrW8nBKxVswRqOQdaqoZRPaKQHqSG07BwSqpMrOLbFomGfKcvos9Hu22I+54 MPxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-filter; bh=pa2lqK8tLRFSFgOMzplmgHoF6LUPfwgF2UX/Kyn0MmE=; fh=VvAK5TwosYkw/BHQCQrIhU7/Qvknrtw1foo6x4jfPJ4=; b=JXPy27m045TGk6+bnQiymV5oVc9akyGp0JpsP/1qtpMKACQldpg0ZlZ7gGmCtaKHJP WWPhRwLpzYR1+f+qNPNdkl52LvvsqfVNIwpxlLJl8/FggD5Gi0nUcKjLrQHB9Br/WtZD c27aktNS0A59uZ4SSgatuxgNCCrC/iCwSUjaB+xphzxwqZGByAGr7mbGyiJMQsyHTh1T ztbBoTKUTWP8Q3coYrX8evJKiLJTBOf2JhNzFrGddq7da6WrdU1B5aympJInQTCqQloE UqOyGFYF3hW11dK7ABZUwqg8Xwf2nc930RnV7+TdrAnNOjP9Vx1gQFjH2K7lryz9D+Q/ DMog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=RaykwJUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id ca24-20020a056a00419800b0068fea05ecdasi4434168pfb.182.2023.09.22.13.03.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 13:04:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=RaykwJUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 6989881CCDBC; Fri, 22 Sep 2023 13:00:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230071AbjIVUAy (ORCPT + 99 others); Fri, 22 Sep 2023 16:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjIVUAx (ORCPT ); Fri, 22 Sep 2023 16:00:53 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8867C19B; Fri, 22 Sep 2023 13:00:47 -0700 (PDT) Received: from DESKTOP-4OLSCEK. (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id CB69F212C5CD; Fri, 22 Sep 2023 13:00:46 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CB69F212C5CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1695412846; bh=pa2lqK8tLRFSFgOMzplmgHoF6LUPfwgF2UX/Kyn0MmE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RaykwJUMG3etwttwdEEJpDTgXvbyop+iEVPs7w6rEMn6QcB6o9n2C0uFeU7OjAcSa 7BW2/CCVIeFhoYAahg+P5h9mZGPGfauaMJe/mZnIct0MTWMge9cB743lnAA0Pphv9y wc6ML3YUYP+oBYL1K/58sUZz9UPXAilh1Jvw3/ng= Date: Fri, 22 Sep 2023 13:00:42 -0700 From: Beau Belgrave To: =?iso-8859-1?Q?Cl=E9ment_L=E9ger?= Cc: Steven Rostedt , Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH] tracing/user_events: align uaddr on unsigned long alignment Message-ID: <20230922200042.GA1981-beaub@linux.microsoft.com> References: <20230914131102.179100-1-cleger@rivosinc.com> <20230914131700.0ba3ee80@gandalf.local.home> <20230914132956.569dad45@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 22 Sep 2023 13:00:56 -0700 (PDT) On Tue, Sep 19, 2023 at 02:59:12PM +0200, Cl?ment L?ger wrote: > > > On 14/09/2023 19:29, Steven Rostedt wrote: > > On Thu, 14 Sep 2023 13:17:00 -0400 > > Steven Rostedt wrote: > > > >> Now lets look at big endian layout: > >> > >> uaddr = 0xbeef0004 > >> enabler = 1; > >> > >> memory at 0xbeef0000: 00 00 00 00 00 00 00 02 > >> ^ > >> addr: 0xbeef0004 > >> > >> (enabler is set ) > >> > >> bitoffset = uaddr & (sizeof(unsigned long) - 1); bitoffset = 4 > >> bit_offset *= 8; bitoffset = 32 > >> uaddr &= ~(sizeof(unsigned long) - 1); uaddr = 0xbeef0000 > >> > >> ptr = kaddr + (uaddr & ~PAGE_MASK); > >> > >> clear_bit(1 + 32, ptr); > >> > >> memory at 0xbeef0000: 00 00 00 00 00 00 00 02 > >> ^ > >> bit 33 of 0xbeef0000 > >> > >> I don't think that's what you expected! > > > > I believe the above can be fixed with: > > > > bit_offset = uaddr & (sizeof(unsigned long) - 1); > > if (bit_offset) { > > #ifdef CONFIG_CPU_BIG_ENDIAN > > bit_offest = 0; > > #else > > bit_offset *= BITS_PER_BYTE; > > #endif > > uaddr &= ~(sizeof(unsigned long) - 1); > > } > > > > -- Steve > > > Actually, after looking more in depth at that, it seems like there are > actually 2 problems that can happen. > > First one is atomic access misalignment due to enable_size == 4 and > uaddr not being aligned on a (long) boundary on 64 bits architecture. > This can generate misaligned exceptions on various architectures. This > can be fixed in a more general way according to Masami snippet. > > Second one that I can see is on 64 bits, big endian architectures with > enable_size == 4. In that case, the bit provided by the userspace won't > be correctly set since this code kind of assume that the atomic are done > on 32bits value. Since the kernel assume long sized atomic operation, on > big endian 64 bits architecture, the updated bit will actually be in the > next 32 bits word. > > Can someone confirm my understanding ? > Actually, I take back some of what I said [1]. If a 32-bit on a 64-bit kernel comes in on BE, and is aligned, we do need to offset the bits as well (just verified on my ppc64 BE VM). You should be able to use that patch as a base though and add a flag to struct user_event_enabler when this case occurs. Then in the align_addr_bit() adjust the bits as well upon aligned cases. Thanks, -Beau 1. https://lore.kernel.org/linux-trace-kernel/20230922192231.GA1828-beaub@linux.microsoft.com/ > Cl?ment