Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4111934rwi; Mon, 17 Oct 2022 01:23:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6+qYEjB/qIc3hbxIlhmySKEvjF5f9Ew4qeghLrj75DaoMofm7XJG+pS+mvmugzKV1ExAXU X-Received: by 2002:a17:902:a416:b0:178:a030:5f94 with SMTP id p22-20020a170902a41600b00178a0305f94mr10828328plq.162.1665994993071; Mon, 17 Oct 2022 01:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665994993; cv=none; d=google.com; s=arc-20160816; b=sZ5b1s7M8oZI3vFHTna/GxTNyu0RLOmtX229FSetz0CILqjXB+E21rksgqR/QhIUh8 qg3t/q+25p1ZNRKwM2xs1ILqnGYc7Yqh/1v7ii4GUt+PtbNODC0hZT5/2WIobFHr01yQ HIrRDnTKfiRABEvFIRVaISe2jyy84SeJxAhb+9TWZMuQcUMkK686hi6LJkxlzQ1xL8Zt yOZryIktUvgWhi2bfYhi64e056Z/7efK/Lhtjjn+ChniNxb2UtxGxsmm79M+CTLN0qh+ 6BdHvnPwgHVSTryYgiEOKeWO3Ysb0Xo0FC6dfdNzWg8tJ5GFwaAKjNPbbn+LJlnMYyyt eS6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=XXRYRsJRPJjLzKK7puJ7pxqclC9eIM+qPkhyGBJL1K8=; b=Z5CXZsdkVG1hsKRHKOlMEgwPs82ihRwbwv9rCgtiUl9ak8/lyiRfcTopiOelNZSLfR wirU6aQNj2fvcWX6dtNndMcbNWWCYM7g8I5r/uqUg+vUjaXcso8XR/nkyimMuCuAAkPG U9iqA9+/QBDKS6UOjcu3FPby0JGwYEKnZm2Fqjq5GFUEgeoJ2Mpb7Y4cVjO5xQXIReW/ Q6u5kacQAQ10Kx682yqnvV55JY/vTIvyJ8Ph2mOSzzoYTKXY3s4JSLHte5y18P4Nsf2H nNgddHpK7/qD/+//6j8mraAlUUmadBZHG0e6S0Gz0K0Ti/6oNJQOZ6X7Dr45C+4VGI1D 7U4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=v7ACNPAW; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x14-20020a63170e000000b004393f62586csi12317744pgl.238.2022.10.17.01.22.57; Mon, 17 Oct 2022 01:23:12 -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=@xen0n.name header.s=mail header.b=v7ACNPAW; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230120AbiJQIFv (ORCPT + 99 others); Mon, 17 Oct 2022 04:05:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbiJQIFs (ORCPT ); Mon, 17 Oct 2022 04:05:48 -0400 Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C933D6587 for ; Mon, 17 Oct 2022 01:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1665993944; bh=rbLjBNdrdjtEGr4opnMLT4SrOV8FV9W/7+iLBbcBYx8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=v7ACNPAWfsoEbl/PxgLTT89p4Znwh8KyR4/t3PAS8AsS4O5/nSOyeXqYYIIYeVsrR YxIvyN08wEHNlt1rztxeW8CwzUklJdyMlx/UEYBH4LlPMnsPyxONBstMHmf8wSst3q hROZIxb2rc+fwjHnRk2z/tHxFiF5GZzL0KxaCRbY= Received: from [100.100.57.122] (unknown [220.248.53.61]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 281BD600B5; Mon, 17 Oct 2022 16:05:44 +0800 (CST) Message-ID: <52ada3c4-f4f2-dc27-5899-d29e5952189d@xen0n.name> Date: Mon, 17 Oct 2022 16:05:43 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:107.0) Gecko/20100101 Thunderbird/107.0a1 Subject: Re: [PATCH] LoongArch: Add unaligned access support Content-Language: en-US To: Arnd Bergmann , Huacai Chen Cc: Huacai Chen , loongarch@lists.linux.dev, Xuefeng Li , Tiezhu Yang , guoren , Jiaxun Yang , linux-kernel@vger.kernel.org References: <20221016133418.2122777-1-chenhuacai@loongson.cn> <506fe4e5-a203-48e6-84a6-f70133be15dd@app.fastmail.com> From: WANG Xuerui In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS 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 Hi, Just my 2c... On 2022/10/17 15:38, Arnd Bergmann wrote: > On Mon, Oct 17, 2022, at 9:31 AM, Huacai Chen wrote: >> Hi, Arnd, >> >> On Mon, Oct 17, 2022 at 3:12 PM Arnd Bergmann wrote: >>> >>> On Sun, Oct 16, 2022, at 3:34 PM, Huacai Chen wrote: >>>> Loongson-2 series (Loongson-2K500, Loongson-2K1000) don't support >>>> unaligned access in hardware, while Loongson-3 series (Loongson-3A5000, >>>> Loongson-3C5000) are configurable whether support unaligned access in >>>> hardware. This patch add unaligned access emulation for those LoongArch >>>> processors without hardware support. >>>> >>>> Signed-off-by: Huacai Chen >>> >>> What does the Loongarch ELF ABI say about this? On most architectures, >>> C compilers are not allowed to produce unaligned accesses for standard >>> compliant source code, the only way you'd get this is when casting >>> a an unaligned (e.g. char*) pointer to another type with higher alignment >>> requirement. >> Some unaligned accesses are observed from the kernel network stack, it >> seems related to whether the packet aligns to IP header or MAC header. > > This is usually a bug in the device driver. It's a fairly common bug > since the network driver has to ensure the alignment is correct, but > it's usually fixable, and fixing it results in better performance on > machines that support unaligned access as well. > > Which driver did you observe this with? I agree with Arnd that it's probably better to fix the drivers. Having the debug feature would help, but in the end it's still the drivers that should get the fix. For example I have previously fixed one such unaligned access in iwlwifi when I was tinkering with a Loongson 3A4000, it was pretty easy to spot with the right perf tools. > >> And, gcc has a -mstrict-align parameter, if without this, there are >> unaligned instructions. > > Does this default to strict or non-strict mode? Usually gcc does not > allow to turn this off on architectures that have no hardware support > for unaligned access. The LoongArch gcc behavior is tunable via the "-m[no-]strict-align" command-line flag, and I believe gcc defaults to producing the "non-strict" code, most likely because the most popular LoongArch model (the 3A5000) supports efficient unaligned accesses. Also there's always the possibility that code compiled for and tested on e.g. 3A5000 will get run on the less capable models, so it's arguably desirable to not let those just fail. Yes it's vendors' responsibility to actually test their code/solution and observe the failure early, but things happen and I'm actually not sure if not doing the emulation will benefit the users at this point... > >>>> +/* sysctl hooks */ >>>> +int unaligned_enabled __read_mostly = 1; /* Enabled by default */ >>>> +int no_unaligned_warning __read_mostly = 1; /* Only 1 warning by default */ >>> >>> The comment says 'sysctl', the implementation has a debugfs interface. >> Originally "enabled", "warning" and "counters" are all debugfs >> interfaces, then you told me to use sysctl. Now in this version >> "enabled" and "warning" are converted to sysctl, but there are no >> existing "counters" sysctl. > > I don't see the sysctl interface in the patch, what am I missing? FYI they are chosen by the Kconfig options and live in kernel/sysctl.c. And I believe the debugfs interface (the counters) is inspired by the original mips code. Pretty niche use case but can be handy at times... -- WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/